// ==UserScript== // @name 动漫花园自动生成磁力链合集 // @namespace http://mooninsky.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://www.dongmanhuayuan.com/* // @grant GM_setClipboard // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @require https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js // @downloadURL none // ==/UserScript== // 翻页selector var plistkey = GM_getValue("listkey", ".uk-pagination:first a:not(:contains('页'))"); // 条目selector var itemkey= GM_getValue("itemkey", ".uk-grid .down_txt a"); // 磁力链selector var magkey= GM_getValue("magkey", "#magnet_one:first"); // 选择细则 var matchReg = GM_getValue("regkey", "简体"); var linklist = []; var maglist = []; // Fetch magnet link (iterate) function getMag(llst, func){ if(llst.length==0){ console.log("Finish all sub pages"); func(); return 0; } else { var clink = llst.pop(); $.get(clink, function(data){ var curcontent = $(data); var curlink = curcontent.find(magkey) maglist.push(curlink[0].defaultValue); return getMag(llst, func); }); } } // Fetch each page's list function fetchLinks(plst, func){ if(plst.length==0){ console.log("Returned from Parser"); func(); return 0; } else { var clink = plst.pop(); $.get(clink,function(data){ var curcontent = $(data); var curlinks = curcontent.find(itemkey) //console.log(curlinks); // Item Print $.each(curlinks, function (i,v){ // Check if match the need // var regex=/.*/; // eval("regex="+matchReg); let regex = new RegExp(matchReg); if( regex.test($(v).attr('title'))){ linklist.push(v); console.log($(v).attr('title')); }; }) return fetchLinks(plst , func); }); } } // the guts of this userscript function main() { // Style GM_addStyle("button { width:100px;height:30px;cursor:pointer; background:#183693; color:white; border-radius:3px; position:fixed; right:10px; }"); GM_addStyle("button:hover {background:#2846a3;}"); GM_addStyle("button#trigger { top:5px; }"); GM_addStyle("button#trigger.ongoing { background:darkgrey;color:#dddddd;cursor:default; }"); GM_addStyle("button#toggle{ top:35px;background:#3866a3; }"); GM_addStyle(".config-input { margin-top:5px;width:100%;text-align:center; }"); GM_addStyle(".config-input input { width:90%; text-align:center; }"); GM_addStyle("#config-panel .button { width:45px;height:20px;font-size:0.8em;cursor:pointer; background:#1e87f0; color:white; border-radius:3px;margin-top:20px;margin-bottom:20px; float:right;margin-right:5px; }"); // Insert the button $('body').append(""); $('body').append(""); $('body').append("
"); $('#config-panel').append("