From 29eb4abc513d873b2327d61578443d56fc8065f3 Mon Sep 17 00:00:00 2001 From: PiQuark6046 Date: Wed, 1 May 2024 05:18:50 +0000 Subject: [PATCH] feat: update new version of espejo (#72) * feat: update new version of espejo * chore: update version * build userscript --- NamuLink.user.js | 4 ++-- package.json | 2 +- sources/banner.txt | 2 +- sources/src/index.ts | 28 +++++++++++++++++----------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/NamuLink.user.js b/NamuLink.user.js index 4f5eaa6..eaba448 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.7.1 +// @version 3.8.0 // @author PiQuark6046 and contributors // // @match https://namu.wiki/* @@ -21,4 +21,4 @@ // @inject-into page // ==/UserScript== // Used libraries: -(()=>{var f=class{value;next;constructor(e){this.value=e}},d=class{#e;#t;#n;constructor(){this.clear()}enqueue(e){let r=new f(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 p={bind(n,e,r){return n.bind(r)}};function h(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()()},o=async(u,i,m)=>{r++;let E=(async()=>u(...m))();i(E);try{await E}catch{}t()},s=(u,i,m)=>{e.enqueue(p.bind(o.bind(void 0,u,i,m))),(async()=>(await Promise.resolve(),r0&&e.dequeue()()))()},l=(u,...i)=>new Promise(m=>{s(u,m,i)});return Object.defineProperties(l,{activeCount:{get:()=>r},pendingCount:{get:()=>e.size},clearQueue:{value(){e.clear()}}}),l}function g(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 y(n,e){g(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 a=typeof unsafeWindow<"u"?unsafeWindow:window,w=new Event("namuwikinavigationwithadvert"),C=new Event("namuwikinavigation");a.Function.prototype.apply=new Proxy(a.Function.prototype.apply,{apply(n,e,r){let t=typeof e=="function"&&e.toString().includes("fromCharCode")&&r[0]===null&&r[1]instanceof Uint16Array;if(t&&new TextDecoder().decode(r[1]).replaceAll("\0","").includes("adcr?x="))throw console.debug("[NamuLink:index]: Function.prototype.apply:",e,r),a.dispatchEvent(w),new Error;return t&&new TextDecoder().decode(r[1]).replaceAll("\0","").startsWith("wiki/i")&&a.dispatchEvent(C),Reflect.apply(n,e,r)}});var c=[],L=n=>{c.push(...n),n.forEach(e=>{e.style.setProperty("display","none","important")})},M=()=>{console.debug("[NamuLink:index]: ShowElements:",c),c=c.filter(n=>n.parentElement!==null),c.forEach(n=>{n.style.removeProperty("display")}),c=[]},H=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(l=>l instanceof HTMLElement).some(l=>Number(getComputedStyle(l).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(s=>s 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.querySelectorAll('a[rel="noopener"][target="_blank"][class] > span ~ span')).some(o=>o.innerHTML.includes("\uB098\uBB34\uB274\uC2A4"))),r.push(...e.filter(t=>Array.from(t.querySelectorAll("*")).filter(l=>l instanceof HTMLElement).filter(l=>getComputedStyle(l).getPropertyValue("animation-iteration-count")==="infinite").length>=6)),e=e.filter(t=>{let s=Array.from(t.querySelectorAll("*")).filter(l=>l instanceof HTMLElement);return s.some(l=>Number(getComputedStyle(l).getPropertyValue("margin-bottom").replace(/px$/,""))>=10)&&s.every(l=>Number(getComputedStyle(l).getPropertyValue("margin-left").replace(/px$/,""))<=10)}),r.push(...e.filter(t=>{let s=Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement),u=Array.from(t.parentElement?.querySelectorAll("*")??[]).filter(i=>i instanceof HTMLElement);return s.every(i=>!i.innerText.includes("alt='external/"))&&u.filter(i=>i.nextElementSibling===t&&!(i instanceof HTMLHeadingElement)).length>0})),r},v=async()=>{let n=[];n.push(...Array.from(a.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(a.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=h((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let o of y(n,{Count:2}))t.push(r(()=>H(o)));e=await Promise.all(t).then(o=>o.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)};a.addEventListener("namuwikinavigationwithadvert",v);a.addEventListener("namuwikifristvisit",v);a.addEventListener("namuwikinavigation",M);})(); +(()=>{var f=class{value;next;constructor(e){this.value=e}},d=class{#e;#t;#n;constructor(){this.clear()}enqueue(e){let r=new f(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 p={bind(n,e,r){return n.bind(r)}};function h(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()()},s=async(u,i,m)=>{r++;let E=(async()=>u(...m))();i(E);try{await E}catch{}t()},o=(u,i,m)=>{e.enqueue(p.bind(s.bind(void 0,u,i,m))),(async()=>(await Promise.resolve(),r0&&e.dequeue()()))()},l=(u,...i)=>new Promise(m=>{o(u,m,i)});return Object.defineProperties(l,{activeCount:{get:()=>r},pendingCount:{get:()=>e.size},clearQueue:{value(){e.clear()}}}),l}function v(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 y(n,e){v(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 a=typeof unsafeWindow<"u"?unsafeWindow:window,C=new Event("namuwikinavigationwithadvert"),w=new Event("namuwikinavigation");a.fetch=new Proxy(a.fetch,{async apply(n,e,r){let t=Reflect.apply(n,e,r);return typeof r[0]=="string"&&/^\/i\/[a-zA-Z0-9_-]{200,}/.test(r[0])&&r[1].method==="GET"&&(await(await t.then(o=>o.clone())).arrayBuffer()).byteLength>1e3&&a.dispatchEvent(C),t}});a.Array.prototype.join=new Proxy(a.Array.prototype.join,{apply(n,e,r){let t=Reflect.apply(n,e,r);return t.startsWith('noscript[data-n-head="]')&&a.dispatchEvent(w),t}});var c=[],L=n=>{c.push(...n),n.forEach(e=>{e.style.setProperty("display","none","important")})},M=()=>{console.debug("[NamuLink:index]: ShowElements:",c),c=c.filter(n=>n.parentElement!==null),c.forEach(n=>{n.style.removeProperty("display")}),c=[]},T=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(l=>l instanceof HTMLElement).some(l=>Number(getComputedStyle(l).getPropertyValue("margin-bottom").replace(/px$/,""))>=4)),e=e.filter(t=>Array.from(t.querySelectorAll("*")).filter(o=>o 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.querySelectorAll('a[rel="noopener"][target="_blank"][class] > span ~ span')).some(s=>s.innerHTML.includes("\uB098\uBB34\uB274\uC2A4"))),r.push(...e.filter(t=>Array.from(t.querySelectorAll("*")).filter(l=>l instanceof HTMLElement).filter(l=>getComputedStyle(l).getPropertyValue("animation-iteration-count")==="infinite").length>=6)),e=e.filter(t=>{let o=Array.from(t.querySelectorAll("*")).filter(l=>l instanceof HTMLElement);return o.some(l=>Number(getComputedStyle(l).getPropertyValue("margin-bottom").replace(/px$/,""))>=10)&&o.every(l=>Number(getComputedStyle(l).getPropertyValue("margin-left").replace(/px$/,""))<=10)}),r.push(...e.filter(t=>{let o=Array.from(t.querySelectorAll("*")).filter(i=>i instanceof HTMLElement),u=Array.from(t.parentElement?.querySelectorAll("*")??[]).filter(i=>i instanceof HTMLElement);return o.every(i=>!i.innerText.includes("alt='external/"))&&u.filter(i=>i.nextElementSibling===t&&!(i instanceof HTMLHeadingElement)).length>0})),r},g=async()=>{let n=[];n.push(...Array.from(a.document.querySelectorAll('div[class] div[class*=" "]:has(span ~ ul li) ~ div div[class] > div[class] div[class] ~ div[class]'))),n.push(...Array.from(a.document.querySelectorAll('div:not([class*=" "]) div[class] div[class*=" "]')));let e=[],r=h((navigator.hardwareConcurrency??4)<4?4:navigator.hardwareConcurrency),t=[];for(let s of y(n,{Count:2}))t.push(r(()=>T(s)));e=await Promise.all(t).then(s=>s.flat()),console.debug("[NamuLink:index]: HideLeftoverElement:",e),L(e)};a.addEventListener("namuwikinavigationwithadvert",g);a.addEventListener("namuwikifristvisit",g);a.addEventListener("namuwikinavigation",M);})(); diff --git a/package.json b/package.json index d1ecf09..4660282 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "namulink", - "version": "3.7.1", + "version": "3.8.0", "description": "", "type": "module", "scripts": { diff --git a/sources/banner.txt b/sources/banner.txt index 7480463..c37bc8f 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.7.1 +// @version 3.8.0 // @author PiQuark6046 and contributors // // @match https://namu.wiki/* diff --git a/sources/src/index.ts b/sources/src/index.ts index fb6f367..9e79602 100644 --- a/sources/src/index.ts +++ b/sources/src/index.ts @@ -11,20 +11,26 @@ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window const NagivationAdvertEvent = new Event('namuwikinavigationwithadvert') const NagivationEvent = new Event('namuwikinavigation') -Win.Function.prototype.apply = new Proxy(Win.Function.prototype.apply, { - apply(Target, ThisArg, Args) { - // eslint-disable-next-line @typescript-eslint/ban-types - const IsUint16Array = typeof ThisArg === 'function' && (ThisArg as Function).toString().includes('fromCharCode') - && Args[0] === null && Args[1] instanceof Uint16Array - if (IsUint16Array && new TextDecoder().decode(Args[1]).replaceAll('\x00', '').includes('adcr?x=')) { - console.debug('[NamuLink:index]: Function.prototype.apply:', ThisArg, Args) - Win.dispatchEvent(NagivationAdvertEvent) - throw new Error() +Win.fetch = new Proxy(Win.fetch, { + async apply(Target, ThisArg, Args) { + const Result = Reflect.apply(Target, ThisArg, Args) + if (typeof Args[0] === 'string' && /^\/i\/[a-zA-Z0-9_-]{200,}/.test(Args[0]) && (Args[1] as RequestInit).method === 'GET') { + const ResultCloned = await (Result as Promise).then(Response => Response.clone()) + if ((await ResultCloned.arrayBuffer()).byteLength > 1000) { + Win.dispatchEvent(NagivationAdvertEvent) + } } - if (IsUint16Array && new TextDecoder().decode(Args[1]).replaceAll('\x00', '').startsWith('wiki/i')) { + return Result + } +}) + +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 Reflect.apply(Target, ThisArg, Args) + return Result } })