☰

Get_Dcard_Sex_Resource

取得Dcard所有評論裡需要密碼的影片、圖片連結

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Get_Dcard_Sex_Resource
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  取得Dcard所有評論裡需要密碼的影片、圖片連結
// @author       You
// @include    https://www.dcard.tw/f/sex*
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
//@run-at  document-end
//@require https://code.jquery.com/jquery-3.3.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';


    //waitForKeyElements ("[class^=RegulationModal_container]", RemoveValidateAgeDiv);
    waitForKeyElements ("[class^=PostPage_content]", Main);

})();


function RemoveValidateAgeDiv(){
    console.log("remove dev");
  $("[class^=RegulationModal_container]").closest('[class^=Modal_modal]').remove();
    $('html, body').css('overflowY', 'auto');
}

//程式主要進入點
function Main(){
     var postId = GetPostIdbyUrl();
    var sexResourceUrls = FindResourceInMainContent(postId);
    sexResourceUrls = sexResourceUrls.concat(FindResourceInComment());
    console.log("All match urls:"+sexResourceUrls.join(','));

}

function GetPostIdbyUrl(){
    var url = window.location.href;
    var postId = 0;
    //取得文章編號
    var MatchPostId = /https:\/\/www\.dcard\.tw\/f\/(\w+)\/p\/(\d+).*/g;
    var Match = MatchPostId.exec(url);
    if(Match)
        postId = Match[2];
    return postId;
}

function FindResourceInComment(postId){
         var sexResourceUrls = [];

    //取得所有評論
    $.getJSON('https://www.dcard.tw/_api/posts/'+postId+'/comments', function(comments) {
        comments.forEach(function(comment, index) {

            if(comment.anonymous && comment.gender == "F"){
                var content = comment.content;
               console.log(comment.content);
                sexResourceUrls = sexResourceUrls.concat(MatchUrlInContent(content));
            }

        });//end of data foreach
    });//end of getJSON

    return sexResourceUrls;
}

function FindResourceInMainContent(){
    var content = $("[class^=Post_content]").html();
    return MatchUrlInContent(content);
}

function MatchUrlInContent(content){
    var Urls = [];
    var MatchVimeo = /https:\/\/player\.vimeo\.com\/video\/\d+/gm;
    var matches;
    console.log(content);
    while (matches = MatchVimeo.exec(content)) {
        console.log(matches);
        Urls.push(matches[1]);
    }

    var MatchPpt = /https:\/\/ppt\.cc\/\w+/gm;
    while (matches = MatchPpt.exec(content)) {
        console.log(matches);
        Urls.push(matches[1]);
    }

    return Urls;
}