/* eslint-disable no-self-assign */ /* eslint-disable no-undef */ // @ts-nocheck /* eslint-disable no-unused-vars */ // ==UserScript== // @name TryGetAllPage // @namespace http://tampermonkey.net/ // @version 2026.6.17.1 // @description try to take over the world! // @author You // @include * // @require https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js // @grant GM_download // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_registerMenuCommand // @require https://scriptcat.org/lib/5415/2026.06.10.01/IframeManager.js?sha384-ugGvg/lqdGGbm9DDcbYtxMoZqHU2cck8s/cVCxplzRwdkkJgvz4gRgCWbRh3Bj8g // ==/UserScript== GM_registerMenuCommand('在当前网址和子网址运行', () => { scriptControler.add(window.location.href) window.location.reload() }); GM_registerMenuCommand('移除当前网址运行了', () => { scriptControler.remove(window.location.href) window.location.reload() }); $(function(){ if(!scriptControler.contains(window.location.href)){return;} const IM = new MyIM(); const TA = new TryGetAllPage(); class Enumerable{ constructor(){ this.TA = TA; } GetPage(){ TA.GetHrefs(); return this; } async forEach(callback){ while(true){ const href = TA.Pop(); if(href){ const rs = await callback(href); if(rs=== false) break; } else break; } } get length(){ return TA.hrefs.size; } toArray(){ return [...TA.hrefs]; } } const EM = new Enumerable(); IM.GetPage = ()=> { TA.GetHrefs(); return [...TA.hrefs]; }; }) class ScriptControler{ constructor(){ if(GM_getValue('TryGetAllPage')){ this.list = new Set(GM_getValue('TryGetAllPage').split(' ')) }else this.list = new Set(); } add(url){ this.list.add(new URL(url).origin); GM_setValue('TryGetAllPage',[...this.list].join(' ')) } contains(url){ try{ return this.list.has(new URL(url).origin); }catch{console.error(url)} } remove(url){ url = new URL(url).origin; this.list.delete(url); GM_setValue('TryGetAllPage',[...this.list].join(' ')) } } const scriptControler = new ScriptControler(); class Mutex { constructor() { this._locked = false; this._queue = []; } lock() { return new Promise(resolve => { if (!this._locked) { this._locked = true; resolve(); } else { this._queue.push(resolve); } }); } unlock() { if (this._queue.length) { const next = this._queue.shift(); next(); } else { this._locked = false; } } } const mutex = new Mutex(); async function MutexG(callback) { await mutex.lock(); await callback(); mutex.unlock(); } class TryGetAllPage{ constructor(arg) { this.hrefs = new Set(); } GetHrefs(){ const _this = this; const atag = $('a[href]').filter((index,a)=>{ const isNum = /^ ?\d+ ?$/.test($(a).text())|| $(a).text().match(/上一页|下一页/g); const isNotSelf = a.href != window.location.href || window.location.href.indexOf(a.href)<0; return isNum && isNotSelf; }); atag.each(function(){ _this.hrefs.add(this.href); }) //console.log(this.hrefs); } Pop(){ if(this.hrefs.size==0) return null; const [first] = this.hrefs; this.hrefs.delete(first);console.log(first); return first; } Add(href){ this.hrefs.add(href); } } class MyIM{ constructor(){ const _this = this; this.srcs = new Set(); this.hrefs = []; this.IM = new IframeManagerSimple(window.location.href); $('body').append(` `) $('.iframe-manager').off('click', '.item .retry'); $('.iframe-manager').on('click','.item .retry',function(event){ const iframe = $(event.target).nextAll("iframe"); if(event.target.classList.contains('fontRed')){ if(iframe.length==1) iframe[0].src = iframe[0].src; event.target.classList.remove('fontRed'); }else{ event.target.classList.add('fontRed'); if(iframe.length!=1) return; if(iframe[0].contentDocument.readyState != "complete") iframe[0].contentWindow.stop(); else _this.IM.OnLoaded(iframe[0],{gettingPage : true}); } }) let actionCount = 0; this.IM.IframeAction = function(url,args){console.log(`iframe action : ${url}`) if(args.gettingPage){ let hrefs = _this.GetPage(); return {srcs : _this.GetSrcs() , url : url , getedSrcs : true , hrefs:hrefs} }else if(args.showImg){ // await _this.Download(url); } } this.IM.GetInfoFromIframe = function(args){ if(args.getedSrcs && args.srcs){ $('.iframe-manager .container button.tool.bu1').css('--action',`"${++actionCount}"`); args.srcs.forEach(i=>_this.srcs.add(i)); $('button.tool.bu5').text(`img (${_this.srcs.size})`) } if(args.hrefs){ _this.AddHrefs(args.hrefs); } } let closeHS = new Set(); this.IM.Close = async function(url){ if(closeHS.has(url)) throw(url); else closeHS.add(url); this.private.count--; this.box.RemoveIframe(url); await MutexG(()=>_this.pageCount--);console.log(`page count ${_this.pageCount}`); } //修复原基类的bug--------------------------------------------------------------------- this.IM._ParentPageLinstener = function(){ const __this = this; const onFromIframe = function(data){ if(!data.ActionDone) return; if(data.info) __this.GetInfoFromIframe(info); if(__this.autoClose) __this.Close(data.ActionDone); } this.Post.onFromIframe = onFromIframe; } this.AddBU(); this.state = "click img download"; this.dcount = 0; this.pageCount = 0; this.maxPage = 2; this.stop = true; } AddBU(){ const _this = this; $(".iframe-manager .container").append(`