From 808ee1cc022c531aa2e8cfecbb76bd4fde9c104d Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Fri, 17 May 2024 07:11:00 +0000 Subject: [PATCH 1/5] feat: mock Win.String.prototype.indexOf for navigation --- sources/src/index.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/sources/src/index.ts b/sources/src/index.ts index 9e2a2a8..cddc55d 100644 --- a/sources/src/index.ts +++ b/sources/src/index.ts @@ -12,21 +12,15 @@ const NamuWikiUnloadedAdEvent = new Event('namuwikiunloadedadvert') const NamuWikiLoadedAdEvent = new Event('namuwikiloadedadvert') const NagivationEvent = new Event('namuwikinavigation') -const SubString = ['substring', 'substr'] -for (const SubStringFunction of SubString) { - Win.String.prototype[SubStringFunction] = new Proxy(Win.String.prototype[SubStringFunction], { - apply(Target, ThisArg, Args) { - if (typeof ThisArg === 'string' && /^[a-zA-Z0-9_]+--?[a-zA-Z0-9_]+(-[a-zA-Z0-9_]+-[a-zA-Z0-9_]+){0,}$/.test(ThisArg)) { - console.debug(`[NamuLink:index]: String.prototype.${SubStringFunction}:`, ThisArg) - Win.dispatchEvent(NamuWikiUnloadedAdEvent) - } - if (typeof ThisArg === 'string' && ThisArg === 'headAttrs') { - Win.dispatchEvent(NamuWikiUnloadedAdEvent) - } - return Reflect.apply(Target, ThisArg, Args) +Win.String.prototype.indexOf = new Proxy(Win.String.prototype.indexOf, { + apply(Target, ThisArg, Args) { + const Result = Reflect.apply(Target, ThisArg, Args) + if (typeof Args[0] === 'string' && Args[0] === 'key') { + Win.dispatchEvent(NamuWikiUnloadedAdEvent) } - }) -} + return Result + } +}) Win.TextDecoder.prototype.decode = new Proxy(Win.TextDecoder.prototype.decode, { apply(Target, ThisArg, Args) { From de9444f8880143a954c4ed3c52b897bcb9969046 Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Fri, 17 May 2024 07:11:23 +0000 Subject: [PATCH 2/5] chore: update version --- package.json | 2 +- sources/banner.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fbd8c55..457f02f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "namulink", - "version": "3.15.2", + "version": "3.16.0", "description": "", "type": "module", "scripts": { diff --git a/sources/banner.txt b/sources/banner.txt index 4b36d12..9d44508 100644 --- a/sources/banner.txt +++ b/sources/banner.txt @@ -8,7 +8,7 @@ // @downloadURL https://cdn.jsdelivr.net/gh/List-KR/NamuLink@latest/NamuLink.user.js // @license MIT // -// @version 3.15.2 +// @version 3.16.0 // @author PiQuark6046 and contributors // // @match https://namu.wiki/* From 883163967ebf55d55e940166bef7a0b9a008ede8 Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Fri, 17 May 2024 07:11:36 +0000 Subject: [PATCH 3/5] build userscript --- NamuLink.user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NamuLink.user.js b/NamuLink.user.js index e1752cf..5403cd9 100644 --- a/NamuLink.user.js +++ b/NamuLink.user.js @@ -8,7 +8,7 @@ // @downloadURL https://cdn.jsdelivr.net/gh/List-KR/NamuLink@latest/NamuLink.user.js // @license MIT // -// @version 3.15.2 +// @version 3.16.0 // @author PiQuark6046 and contributors // // @match https://namu.wiki/* @@ -21,4 +21,4 @@ // @inject-into page // ==/UserScript== // Used libraries: -(()=>{var E=class{value;next;constructor(e){this.value=e}},m=class{#e;#t;#n;constructor(){this.clear()}enqueue(e){let r=new E(e);this.#e?(this.#t.next=r,this.#t=r):(this.#e=r,this.#t=r),this.#n++}dequeue(){let e=this.#e;if(e)return this.#e=this.#e.next,this.#n--,e.value}clear(){this.#e=void 0,this.#t=void 0,this.#n=0}get size(){return this.#n}*[Symbol.iterator](){let e=this.#e;for(;e;)yield e.value,e=e.next}};var v={bind(n,e,r){return n.bind(r)}};function f(n){if(!((Number.isInteger(n)||n===Number.POSITIVE_INFINITY)&&n>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");let e=new m,r=0,t=()=>{r--,e.size>0&&e.dequeue()()},l=async(u,s,d)=>{r++;let y=(async()=>u(...d))();s(y);try{await y}catch{}t()},a=(u,s,d)=>{e.enqueue(v.bind(l.bind(void 0,u,s,d))),(async()=>(await Promise.resolve(),r0&&e.dequeue()()))()},i=(u,...s)=>new Promise(d=>{a(u,d,s)});return Object.defineProperties(i,{activeCount:{get:()=>r},pendingCount:{get:()=>e.size},clearQueue:{value(){e.clear()}}}),i}function T(n){if(!Number.isInteger(n.Count))throw new Error("MultithreadArrayOptions.Count should be an integer");if(n.Count<=0)throw new Error("MultithreadArrayOptions.Count should be greater than 0")}function h(n,e){T(e);let r=new Array(Math.ceil(n.length/e.Count));for(var t=0;tn.length?n.length:(t+1)*e.Count);return r}var o=typeof unsafeWindow<"u"?unsafeWindow:window,p=new Event("namuwikiunloadedadvert"),H=new Event("namuwikiloadedadvert"),M=new Event("namuwikinavigation"),w=["substring","substr"];for(let n of w)o.String.prototype[n]=new Proxy(o.String.prototype[n],{apply(e,r,t){return typeof r=="string"&&/^[a-zA-Z0-9_]+--?[a-zA-Z0-9_]+(-[a-zA-Z0-9_]+-[a-zA-Z0-9_]+){0,}$/.test(r)&&(console.debug(`[NamuLink:index]: String.prototype.${n}:`,r),o.dispatchEvent(p)),typeof r=="string"&&r==="headAttrs"&&o.dispatchEvent(p),Reflect.apply(e,r,t)}});o.TextDecoder.prototype.decode=new Proxy(o.TextDecoder.prototype.decode,{apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof t=="string"&&/^\[+.{0,10}#.{10,50}\/\/\/.{0,20}==/.test(t)?(console.debug("[NamuLink:index]: TextDecoder.prototype.decode",t),o.dispatchEvent(p),""):t}});var S=["setTimeout","setInterval"];for(let n of S)o[n]=new Proxy(o[n],{apply(e,r,t){if(typeof t[0]=="function"&&typeof t[1]=="number"&&(/return {0,}new {0,}Promise.+\.apply {0,}\(.+function.+next.+throw.+void/.test(t[0].toString())||/if {0,}\(('|")[a-zA-Z0-9_]+('|") {0,}===? {0,}.+return.+else/.test(t[0].toString()))){console.debug(`[NamuLink:index]: ${n}:`,t),o.dispatchEvent(p);return}return Reflect.apply(e,r,t)}});o.Array.prototype.join=new Proxy(o.Array.prototype.join,{apply(n,e,r){let t=Reflect.apply(n,e,r);return t.startsWith('noscript[data-n-head="]')&&o.dispatchEvent(M),t}});var c=[],L=n=>{c.push(...n),n.forEach(e=>{e.remove()})},b=()=>{console.debug("[NamuLink:index]: ShowElements:",c),c=c.filter(n=>n.parentElement!==null),c.forEach(n=>{n.style.removeProperty("display")}),c=[]},x=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>t.innerText.length<25),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).filter(i=>getComputedStyle(i).getPropertyValue("animation-iteration-count")==="infinite").length>=6)),e=e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement);return a.some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=10)&&a.every(i=>Number(getComputedStyle(i).getPropertyValue("margin-left").replace(/px$/,""))<=10)}),r.push(...e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(s=>s instanceof HTMLElement),u=Array.from(t.parentElement?.querySelectorAll("*")??[]).filter(s=>s instanceof HTMLElement);return a.every(s=>!s.innerText.includes("alt='external/"))&&u.filter(s=>s.nextElementSibling===t&&!(s instanceof HTMLHeadingElement)).length>0})),r},g=async()=>{let n=[];n.push(...Array.from(o.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(o.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of h(n,{Count:2}))t.push(r(()=>x(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)},C=null;o.EventTarget.prototype.addEventListener=new Proxy(o.EventTarget.prototype.addEventListener,{apply(n,e,r){return typeof r[1]=="function"&&r[0]==="click"&&e instanceof HTMLElement&&/('|")X('|")\) {0,}&&/.test(r[1].toString())&&/('|")Y('|")\) {0,}&&/.test(r[1].toString())&&/^.+\..+$/.test(e.innerText.replaceAll(/[^a-zA-Z0-9\uAC00-\uD7A3./]+/gu,""))&&(C=e,o.dispatchEvent(H)),Reflect.apply(n,e,r)}});var A=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>t.contains(C))),r},q=async()=>{let n=[];n.push(...Array.from(o.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(o.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of h(n,{Count:2}))t.push(r(()=>A(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)};o.addEventListener("namuwikiloadedadvert",q);o.addEventListener("namuwikiunloadedadvert",g);o.addEventListener("namuwikifristvisit",g);o.addEventListener("namuwikinavigation",b);})(); +(()=>{var p=class{value;next;constructor(e){this.value=e}},m=class{#e;#t;#n;constructor(){this.clear()}enqueue(e){let r=new p(e);this.#e?(this.#t.next=r,this.#t=r):(this.#e=r,this.#t=r),this.#n++}dequeue(){let e=this.#e;if(e)return this.#e=this.#e.next,this.#n--,e.value}clear(){this.#e=void 0,this.#t=void 0,this.#n=0}get size(){return this.#n}*[Symbol.iterator](){let e=this.#e;for(;e;)yield e.value,e=e.next}};var v={bind(n,e,r){return n.bind(r)}};function f(n){if(!((Number.isInteger(n)||n===Number.POSITIVE_INFINITY)&&n>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");let e=new m,r=0,t=()=>{r--,e.size>0&&e.dequeue()()},l=async(u,s,d)=>{r++;let y=(async()=>u(...d))();s(y);try{await y}catch{}t()},a=(u,s,d)=>{e.enqueue(v.bind(l.bind(void 0,u,s,d))),(async()=>(await Promise.resolve(),r0&&e.dequeue()()))()},i=(u,...s)=>new Promise(d=>{a(u,d,s)});return Object.defineProperties(i,{activeCount:{get:()=>r},pendingCount:{get:()=>e.size},clearQueue:{value(){e.clear()}}}),i}function C(n){if(!Number.isInteger(n.Count))throw new Error("MultithreadArrayOptions.Count should be an integer");if(n.Count<=0)throw new Error("MultithreadArrayOptions.Count should be greater than 0")}function E(n,e){C(e);let r=new Array(Math.ceil(n.length/e.Count));for(var t=0;tn.length?n.length:(t+1)*e.Count);return r}var o=typeof unsafeWindow<"u"?unsafeWindow:window,h=new Event("namuwikiunloadedadvert"),H=new Event("namuwikiloadedadvert"),M=new Event("namuwikinavigation");o.String.prototype.indexOf=new Proxy(o.String.prototype.indexOf,{apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof r[0]=="string"&&r[0]==="key"&&o.dispatchEvent(h),t}});o.TextDecoder.prototype.decode=new Proxy(o.TextDecoder.prototype.decode,{apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof t=="string"&&/^\[+.{0,10}#.{10,50}\/\/\/.{0,20}==/.test(t)?(console.debug("[NamuLink:index]: TextDecoder.prototype.decode",t),o.dispatchEvent(h),""):t}});var w=["setTimeout","setInterval"];for(let n of w)o[n]=new Proxy(o[n],{apply(e,r,t){if(typeof t[0]=="function"&&typeof t[1]=="number"&&(/return {0,}new {0,}Promise.+\.apply {0,}\(.+function.+next.+throw.+void/.test(t[0].toString())||/if {0,}\(('|")[a-zA-Z0-9_]+('|") {0,}===? {0,}.+return.+else/.test(t[0].toString()))){console.debug(`[NamuLink:index]: ${n}:`,t),o.dispatchEvent(h);return}return Reflect.apply(e,r,t)}});o.Array.prototype.join=new Proxy(o.Array.prototype.join,{apply(n,e,r){let t=Reflect.apply(n,e,r);return t.startsWith('noscript[data-n-head="]')&&o.dispatchEvent(M),t}});var c=[],L=n=>{c.push(...n),n.forEach(e=>{e.remove()})},S=()=>{console.debug("[NamuLink:index]: ShowElements:",c),c=c.filter(n=>n.parentElement!==null),c.forEach(n=>{n.style.removeProperty("display")}),c=[]},x=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>t.innerText.length<25),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).filter(i=>getComputedStyle(i).getPropertyValue("animation-iteration-count")==="infinite").length>=6)),e=e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement);return a.some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=10)&&a.every(i=>Number(getComputedStyle(i).getPropertyValue("margin-left").replace(/px$/,""))<=10)}),r.push(...e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(s=>s instanceof HTMLElement),u=Array.from(t.parentElement?.querySelectorAll("*")??[]).filter(s=>s instanceof HTMLElement);return a.every(s=>!s.innerText.includes("alt='external/"))&&u.filter(s=>s.nextElementSibling===t&&!(s instanceof HTMLHeadingElement)).length>0})),r},g=async()=>{let n=[];n.push(...Array.from(o.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(o.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of E(n,{Count:2}))t.push(r(()=>x(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)},T=null;o.EventTarget.prototype.addEventListener=new Proxy(o.EventTarget.prototype.addEventListener,{apply(n,e,r){return typeof r[1]=="function"&&r[0]==="click"&&e instanceof HTMLElement&&/('|")X('|")\) {0,}&&/.test(r[1].toString())&&/('|")Y('|")\) {0,}&&/.test(r[1].toString())&&/^.+\..+$/.test(e.innerText.replaceAll(/[^a-zA-Z0-9\uAC00-\uD7A3./]+/gu,""))&&(T=e,o.dispatchEvent(H)),Reflect.apply(n,e,r)}});var A=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>t.contains(T))),r},b=async()=>{let n=[];n.push(...Array.from(o.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(o.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of E(n,{Count:2}))t.push(r(()=>A(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)};o.addEventListener("namuwikiloadedadvert",b);o.addEventListener("namuwikiunloadedadvert",g);o.addEventListener("namuwikifristvisit",g);o.addEventListener("namuwikinavigation",S);})(); From c92b0b03527356a2c0858df70aec2009e11eb3e5 Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Fri, 17 May 2024 10:39:03 +0000 Subject: [PATCH 4/5] perf: clean up --- sources/src/index.ts | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/sources/src/index.ts b/sources/src/index.ts index cddc55d..2c09430 100644 --- a/sources/src/index.ts +++ b/sources/src/index.ts @@ -10,7 +10,6 @@ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window const NamuWikiUnloadedAdEvent = new Event('namuwikiunloadedadvert') const NamuWikiLoadedAdEvent = new Event('namuwikiloadedadvert') -const NagivationEvent = new Event('namuwikinavigation') Win.String.prototype.indexOf = new Proxy(Win.String.prototype.indexOf, { apply(Target, ThisArg, Args) { @@ -22,46 +21,6 @@ Win.String.prototype.indexOf = new Proxy(Win.String.prototype.indexOf, { } }) -Win.TextDecoder.prototype.decode = new Proxy(Win.TextDecoder.prototype.decode, { - apply(Target, ThisArg, Args) { - const Result = Reflect.apply(Target, ThisArg, Args) - if (typeof Result === 'string' && /^\[+.{0,10}#.{10,50}\/\/\/.{0,20}==/.test(Result)) { - console.debug('[NamuLink:index]: TextDecoder.prototype.decode', Result) - Win.dispatchEvent(NamuWikiUnloadedAdEvent) - return '' - } - return Result - } -}) - -const Timer = ['setTimeout', 'setInterval'] -for (const TimerFunction of Timer) { - Win[TimerFunction] = new Proxy(Win[TimerFunction], { - apply(Target, ThisArg, Args) { - if (typeof Args[0] === 'function' && typeof Args[1] === 'number' - // eslint-disable-next-line @typescript-eslint/ban-types - && (/return {0,}new {0,}Promise.+\.apply {0,}\(.+function.+next.+throw.+void/.test((Args[0] as Function).toString()) - // eslint-disable-next-line @typescript-eslint/ban-types - || /if {0,}\(('|")[a-zA-Z0-9_]+('|") {0,}===? {0,}.+return.+else/.test((Args[0] as Function).toString()))) { - console.debug(`[NamuLink:index]: ${TimerFunction}:`, Args) - Win.dispatchEvent(NamuWikiUnloadedAdEvent) - return - } - return Reflect.apply(Target, ThisArg, Args) - } - }) -} - -Win.Array.prototype.join = new Proxy(Win.Array.prototype.join, { - apply(Target, ThisArg, Args) { - const Result = Reflect.apply(Target, ThisArg, Args) - if ((Result as string).startsWith('noscript[data-n-head="]')) { - Win.dispatchEvent(NagivationEvent) - } - return Result - } -}) - var HiddenElements: HTMLElement[] = [] const HideElements = (TargetElements: HTMLElement[]) => { From a1ec7f3553c30872cd2cb0d513580f47b06654c8 Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Fri, 17 May 2024 10:39:13 +0000 Subject: [PATCH 5/5] build userscript --- NamuLink.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NamuLink.user.js b/NamuLink.user.js index 5403cd9..b33484a 100644 --- a/NamuLink.user.js +++ b/NamuLink.user.js @@ -21,4 +21,4 @@ // @inject-into page // ==/UserScript== // Used libraries: -(()=>{var p=class{value;next;constructor(e){this.value=e}},m=class{#e;#t;#n;constructor(){this.clear()}enqueue(e){let r=new p(e);this.#e?(this.#t.next=r,this.#t=r):(this.#e=r,this.#t=r),this.#n++}dequeue(){let e=this.#e;if(e)return this.#e=this.#e.next,this.#n--,e.value}clear(){this.#e=void 0,this.#t=void 0,this.#n=0}get size(){return this.#n}*[Symbol.iterator](){let e=this.#e;for(;e;)yield e.value,e=e.next}};var v={bind(n,e,r){return n.bind(r)}};function f(n){if(!((Number.isInteger(n)||n===Number.POSITIVE_INFINITY)&&n>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");let e=new m,r=0,t=()=>{r--,e.size>0&&e.dequeue()()},l=async(u,s,d)=>{r++;let y=(async()=>u(...d))();s(y);try{await y}catch{}t()},a=(u,s,d)=>{e.enqueue(v.bind(l.bind(void 0,u,s,d))),(async()=>(await Promise.resolve(),r0&&e.dequeue()()))()},i=(u,...s)=>new Promise(d=>{a(u,d,s)});return Object.defineProperties(i,{activeCount:{get:()=>r},pendingCount:{get:()=>e.size},clearQueue:{value(){e.clear()}}}),i}function C(n){if(!Number.isInteger(n.Count))throw new Error("MultithreadArrayOptions.Count should be an integer");if(n.Count<=0)throw new Error("MultithreadArrayOptions.Count should be greater than 0")}function E(n,e){C(e);let r=new Array(Math.ceil(n.length/e.Count));for(var t=0;tn.length?n.length:(t+1)*e.Count);return r}var o=typeof unsafeWindow<"u"?unsafeWindow:window,h=new Event("namuwikiunloadedadvert"),H=new Event("namuwikiloadedadvert"),M=new Event("namuwikinavigation");o.String.prototype.indexOf=new Proxy(o.String.prototype.indexOf,{apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof r[0]=="string"&&r[0]==="key"&&o.dispatchEvent(h),t}});o.TextDecoder.prototype.decode=new Proxy(o.TextDecoder.prototype.decode,{apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof t=="string"&&/^\[+.{0,10}#.{10,50}\/\/\/.{0,20}==/.test(t)?(console.debug("[NamuLink:index]: TextDecoder.prototype.decode",t),o.dispatchEvent(h),""):t}});var w=["setTimeout","setInterval"];for(let n of w)o[n]=new Proxy(o[n],{apply(e,r,t){if(typeof t[0]=="function"&&typeof t[1]=="number"&&(/return {0,}new {0,}Promise.+\.apply {0,}\(.+function.+next.+throw.+void/.test(t[0].toString())||/if {0,}\(('|")[a-zA-Z0-9_]+('|") {0,}===? {0,}.+return.+else/.test(t[0].toString()))){console.debug(`[NamuLink:index]: ${n}:`,t),o.dispatchEvent(h);return}return Reflect.apply(e,r,t)}});o.Array.prototype.join=new Proxy(o.Array.prototype.join,{apply(n,e,r){let t=Reflect.apply(n,e,r);return t.startsWith('noscript[data-n-head="]')&&o.dispatchEvent(M),t}});var c=[],L=n=>{c.push(...n),n.forEach(e=>{e.remove()})},S=()=>{console.debug("[NamuLink:index]: ShowElements:",c),c=c.filter(n=>n.parentElement!==null),c.forEach(n=>{n.style.removeProperty("display")}),c=[]},x=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>t.innerText.length<25),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).filter(i=>getComputedStyle(i).getPropertyValue("animation-iteration-count")==="infinite").length>=6)),e=e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement);return a.some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=10)&&a.every(i=>Number(getComputedStyle(i).getPropertyValue("margin-left").replace(/px$/,""))<=10)}),r.push(...e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(s=>s instanceof HTMLElement),u=Array.from(t.parentElement?.querySelectorAll("*")??[]).filter(s=>s instanceof HTMLElement);return a.every(s=>!s.innerText.includes("alt='external/"))&&u.filter(s=>s.nextElementSibling===t&&!(s instanceof HTMLHeadingElement)).length>0})),r},g=async()=>{let n=[];n.push(...Array.from(o.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(o.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of E(n,{Count:2}))t.push(r(()=>x(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)},T=null;o.EventTarget.prototype.addEventListener=new Proxy(o.EventTarget.prototype.addEventListener,{apply(n,e,r){return typeof r[1]=="function"&&r[0]==="click"&&e instanceof HTMLElement&&/('|")X('|")\) {0,}&&/.test(r[1].toString())&&/('|")Y('|")\) {0,}&&/.test(r[1].toString())&&/^.+\..+$/.test(e.innerText.replaceAll(/[^a-zA-Z0-9\uAC00-\uD7A3./]+/gu,""))&&(T=e,o.dispatchEvent(H)),Reflect.apply(n,e,r)}});var A=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>t.contains(T))),r},b=async()=>{let n=[];n.push(...Array.from(o.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(o.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of E(n,{Count:2}))t.push(r(()=>A(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)};o.addEventListener("namuwikiloadedadvert",b);o.addEventListener("namuwikiunloadedadvert",g);o.addEventListener("namuwikifristvisit",g);o.addEventListener("namuwikinavigation",S);})(); +(()=>{var E=class{value;next;constructor(e){this.value=e}},d=class{#e;#t;#n;constructor(){this.clear()}enqueue(e){let r=new E(e);this.#e?(this.#t.next=r,this.#t=r):(this.#e=r,this.#t=r),this.#n++}dequeue(){let e=this.#e;if(e)return this.#e=this.#e.next,this.#n--,e.value}clear(){this.#e=void 0,this.#t=void 0,this.#n=0}get size(){return this.#n}*[Symbol.iterator](){let e=this.#e;for(;e;)yield e.value,e=e.next}};var y={bind(n,e,r){return n.bind(r)}};function f(n){if(!((Number.isInteger(n)||n===Number.POSITIVE_INFINITY)&&n>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");let e=new d,r=0,t=()=>{r--,e.size>0&&e.dequeue()()},l=async(u,o,c)=>{r++;let p=(async()=>u(...c))();o(p);try{await p}catch{}t()},a=(u,o,c)=>{e.enqueue(y.bind(l.bind(void 0,u,o,c))),(async()=>(await Promise.resolve(),r0&&e.dequeue()()))()},i=(u,...o)=>new Promise(c=>{a(u,c,o)});return Object.defineProperties(i,{activeCount:{get:()=>r},pendingCount:{get:()=>e.size},clearQueue:{value(){e.clear()}}}),i}function C(n){if(!Number.isInteger(n.Count))throw new Error("MultithreadArrayOptions.Count should be an integer");if(n.Count<=0)throw new Error("MultithreadArrayOptions.Count should be greater than 0")}function h(n,e){C(e);let r=new Array(Math.ceil(n.length/e.Count));for(var t=0;tn.length?n.length:(t+1)*e.Count);return r}var s=typeof unsafeWindow<"u"?unsafeWindow:window,H=new Event("namuwikiunloadedadvert"),T=new Event("namuwikiloadedadvert");s.String.prototype.indexOf=new Proxy(s.String.prototype.indexOf,{apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof r[0]=="string"&&r[0]==="key"&&s.dispatchEvent(H),t}});var m=[],v=n=>{m.push(...n),n.forEach(e=>{e.remove()})},M=()=>{console.debug("[NamuLink:index]: ShowElements:",m),m=m.filter(n=>n.parentElement!==null),m.forEach(n=>{n.style.removeProperty("display")}),m=[]},w=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>t.innerText.length<25),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).filter(i=>getComputedStyle(i).getPropertyValue("animation-iteration-count")==="infinite").length>=6)),e=e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement);return a.some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=10)&&a.every(i=>Number(getComputedStyle(i).getPropertyValue("margin-left").replace(/px$/,""))<=10)}),r.push(...e.filter(t=>{let a=Array.from(t.querySelectorAll("*")).filter(o=>o instanceof HTMLElement),u=Array.from(t.parentElement?.querySelectorAll("*")??[]).filter(o=>o instanceof HTMLElement);return a.every(o=>!o.innerText.includes("alt='external/"))&&u.filter(o=>o.nextElementSibling===t&&!(o instanceof HTMLHeadingElement)).length>0})),r},L=async()=>{let n=[];n.push(...Array.from(s.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(s.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of h(n,{Count:2}))t.push(r(()=>w(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),v(e)},g=null;s.EventTarget.prototype.addEventListener=new Proxy(s.EventTarget.prototype.addEventListener,{apply(n,e,r){return typeof r[1]=="function"&&r[0]==="click"&&e instanceof HTMLElement&&/('|")X('|")\) {0,}&&/.test(r[1].toString())&&/('|")Y('|")\) {0,}&&/.test(r[1].toString())&&/^.+\..+$/.test(e.innerText.replaceAll(/[^a-zA-Z0-9\uAC00-\uD7A3./]+/gu,""))&&(g=e,s.dispatchEvent(T)),Reflect.apply(n,e,r)}});var S=n=>{var e=n.filter(t=>t instanceof HTMLElement);let r=[];return e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement).some(i=>Number(getComputedStyle(i).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(a=>a instanceof HTMLIFrameElement).length===0),e=e.filter(t=>t.querySelectorAll('span[id^="fn-"] + a[href^="#rfn-"]').length===0),e=e.filter(t=>!Array.from(t.parentElement.querySelectorAll("span")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),e=e.filter(t=>!Array.from(t.querySelectorAll("*")).some(l=>l.innerHTML.includes("\uC2E4\uC2DC\uAC04 \uAC80\uC0C9\uC5B4"))),r.push(...e.filter(t=>t.contains(g))),r},A=async()=>{let n=[];n.push(...Array.from(s.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(s.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=f((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let l of h(n,{Count:2}))t.push(r(()=>S(l)));e=await Promise.all(t).then(l=>l.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),v(e)};s.addEventListener("namuwikiloadedadvert",A);s.addEventListener("namuwikiunloadedadvert",L);s.addEventListener("namuwikifristvisit",L);s.addEventListener("namuwikinavigation",M);})();