@filteringdev/namulink 19.8.0 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NamuLink.user.js +3 -2
- package/dist/dom-await.d.ts +1 -0
- package/dist/dom-await.js +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +50 -451
- package/dist/ocr-client.d.ts +15 -0
- package/dist/ocr-client.js +281 -0
- package/dist/ocr-types.d.ts +32 -0
- package/dist/ocr-types.js +1 -0
- package/dist/ocr-worker.d.ts +1 -0
- package/dist/ocr-worker.js +442 -0
- package/dist/vuejsawait.d.ts +7 -0
- package/dist/vuejsawait.js +67 -0
- package/package.json +5 -5
package/dist/NamuLink.user.js
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
// @downloadURL https://cdn.jsdelivr.net/npm/@filteringdev/namulink@latest/dist/NamuLink.user.js
|
|
9
9
|
// @license MPL-2.0
|
|
10
10
|
//
|
|
11
|
-
// @version
|
|
11
|
+
// @version 20.0.0
|
|
12
12
|
// @author PiQuark6046 and contributors
|
|
13
13
|
//
|
|
14
14
|
// @grant unsafeWindow
|
|
15
|
+
// @grant GM.xmlHttpRequest
|
|
15
16
|
// @run-at document-start
|
|
16
17
|
//
|
|
17
18
|
// @description NamuLink blocks the PowerLink advertisement on NamuWiki.
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
// ==/UserScript==
|
|
22
23
|
|
|
23
24
|
|
|
24
|
-
(()=>{var Z=typeof unsafeWindow<"u"?unsafeWindow:window;function T(c,d="NamuLink"){let x=c.Function.prototype.call,f=c.Reflect.apply,E=c.Object.defineProperty,v=c.Proxy,s=c.Object.getOwnPropertyDescriptor,m=[[/function *\( *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *\) *{ *return *[A-Za-z.-9]+/,/, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *\) *{ *return *[A-Za-z.-9]+ *\( *[0-9a-fx *+-]+ *, *[A-Za-z.-9]+ *, *[A-Za-z.-9]+ *, *[0-9a-fx *+-]+/,/return *[A-Za-z.-9]+ *\( *[0-9a-fx *+-]+ *, *[A-Za-z.-9]+ *, *[A-Za-z.-9]+ *, *[0-9a-fx *+-]+ *,[A-Za-z.-9]+ *, *[A-Za-z.-9]+ * *\) *; *}/],[/function *[A-Za-z0-9]+ *\( *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *\) *{ *return *[A-Za-z.-9]+/,/, *[A-Za-z0-9]+ *, *[A-Za-z0-9]+ *\) *{ *return *[A-Za-z.-9]+ *\( *[0-9a-fx *+-]+ *, *[A-Za-z.-9]+ *, *[A-Za-z.-9]+ *, *[0-9a-fx *+-]+/,/return *[A-Za-z.-9]+ *\( *[0-9a-fx *+-]+ *, *[A-Za-z.-9]+ *, *[A-Za-z.-9]+ *, *[0-9a-fx *+-]+ *,[A-Za-z.-9]+ *, *[A-Za-z.-9]+ * *\) *; *}/]];function O(e){if(typeof e!="object"||e===null||typeof f(s,c.Object,[e,"_"])?.get=="function")return null;let t=new Set,n=e._;for(;typeof n=="object"&&n!==null&&!t.has(n);){t.add(n);let o=n.vnode;if(typeof o=="object"&&o!==null){let r=o.el;if(r instanceof HTMLElement)return r}n=n.parent}return null}function w(e){if(typeof e!="object"||e===null||typeof f(s,c.Object,[e,"_"])?.get=="function")return null;let t=new Set,n=e._;for(;typeof n=="object"&&n!==null&&!t.has(n);){t.add(n);let o=n.render;if(typeof o=="function")return o;n=n.parent}return null}function P(e){if(typeof e!="object"||e===null||typeof f(s,c.Object,[e,"_"])?.get=="function")return null;let t=new Set,n=e._;for(;typeof n=="object"&&n!==null&&!t.has(n);){t.add(n);let o=n.parent;if(typeof o=="object"&&o!==null){let i=o.vnode;if(typeof i=="object"&&i!==null){let l=i.el;if(l instanceof HTMLElement)return l}}let r=n.vnode;if(typeof r=="object"&&r!==null){let i=r.el;if(i instanceof HTMLElement)return i}n=o}return null}let b=.35,S=.75,y=.04;function u(e){return Number.parseFloat(e)||0}let h=null,g=!1;c.Function.prototype.call=new Proxy(x,{apply(e,t,n){if(g)return f(e,t,n);g=!0;let o=String(t);if(o.length<500&&m.filter(r=>r.filter(i=>i.test(o)).length===r.length).length===1){let r=P(n[6]);if(r!==null&&[...r.querySelectorAll("*")].filter(i=>{if(!(i instanceof HTMLElement))return!1;let l=i.getClientRects()[0]?.height??0,a=Math.max(u(getComputedStyle(i).getPropertyValue("padding-bottom")),u(getComputedStyle(i).getPropertyValue("margin-bottom")));return l>0&&a>=l*(b-y)&&a<=l*(S+y)}).length>=1)return console.debug(`[${d}]: Function.prototype.call called for PowerLink Skeleton:`,t),h=r,c.document.dispatchEvent(new CustomEvent("PL2PlaceHolder")),c.document.dispatchEvent(new CustomEvent("PL2PlaceHolderMobile")),g=!1,f(e,()=>{},[]);console.debug(`[${d}]: Matched Function.prototype.call called, but not for PowerLink Skeleton:`,t)}return g=!1,f(e,t,n)}}),c.Object.defineProperty=new Proxy(E,{apply(e,t,n){let o=w(n[0]),r=P(n[0]),i=String(o??"");if(o!==null&&r!==null&&i.length<500&&m.filter(l=>l.filter(a=>a.test(i)).length===l.length).length===1&&[...r.querySelectorAll("*")].filter(l=>{if(!(l instanceof HTMLElement))return!1;let a=l.getClientRects()[0]?.height??0,p=Math.max(u(getComputedStyle(l).getPropertyValue("padding-bottom")),u(getComputedStyle(l).getPropertyValue("margin-bottom")));return a>0&&p>=a*(b-y)&&p<=a*(S+y)}).length>=1){console.debug(`[${d}]: Restoring renderer.call for detected PowerLink skeleton:`,n[0]),o.call=Function.prototype.call;return}return f(e,t,n)}});let V=[[/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/,/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/],[/\( *\) *=> *{ *var _0x[a-z0-9]+ *= *_0x[a-z0-9]+ *; *if *\( *this\[ *_0x[a-z0-9]+ *\( *0x[0-9a-f]+ *\) *\] *\) *return *clearTimeout/,/\( *0x[0-9a-f]+ *\) *\] *\) *, *void *\( *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *= *void *\([x0-9a-f*+-]+ *\) *\) *; *this\[_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *\(\) *;/]];c.setTimeout=new Proxy(c.setTimeout,{apply(e,t,n){let o=String(n[0]);return V.filter(r=>r.filter(i=>i.test(o)).length>=1).length===1?(console.debug(`[${d}]: setTimeout called for PowerLink Skeleton:`,n[0]),f(e,t,[()=>{},0])):f(e,t,n)}});function z(e,t){if(typeof e!="object"||e===null)return 1;if(typeof f(s,c.Object,[e,"_"])?.get=="function")return null;let n=new Set,o=e._;for(;typeof o=="object"&&o!==null;){if(n.has(o))return 2;n.add(o);let r=o;if(typeof r.render=="function")return r.render=t,0;o=r.parent}return 3}function C(e){if(typeof e!="object"||e===null||typeof f(s,c.Object,[e,"_"])?.get=="function")return null;let t=new Set,n=e._;for(;typeof n=="object"&&n!==null&&!t.has(n);){t.add(n);let o=n,r=o.render;if(typeof r=="function")return r;let i=o.vnode;if(typeof i=="object"&&i!==null){let l=i.type;if(typeof l=="object"&&l!==null){let a=l.render;if(typeof a=="function")return a}}n=o.parent}return null}function H(e,t){if(typeof e!="object"||e===null)return 1;if(typeof f(s,c.Object,[e,"_"])?.get=="function")return null;let n=new Set,o=e._;for(;typeof o=="object"&&o!==null;){if(n.has(o))return 2;n.add(o);let r=o,i=r.vnode;if(typeof i=="object"&&i!==null){let l=i.type;if(typeof l=="object"&&l!==null&&typeof l.render=="function")return l.render=t,0}o=r.parent}return 3}function L(e){return[{Key:"Includes",String:"//ader.naver.com/"},{Key:"Includes",String:"//ader.naver.com/"},{Key:"StartWith",String:"!/jump/"}].some(n=>{switch(n.Key){case"StartWith":return e.startsWith(n.String);case"Includes":return e.includes(n.String);case"EndsWith":return e.endsWith(n.String)}})}function M(e){let t=String(e);return L(t)}function R(e,t=new WeakSet){if(t.has(e))return!1;t.add(e);for(let n of Object.keys(e)){let o=e[n],r=s(e,n);if(typeof o=="object"&&o!==null&&typeof r?.get!="function"){if(R(o,t))return!0}else if(typeof o=="string"&&L(o))return!0}return!1}function k(e,t){if(e===null||t===null)return e===t;if(Array.isArray(e))return Array.isArray(t)?e.length===0?!0:t.every(n=>k(e[0],n)):!1;if(typeof e=="object"){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;let n=Object.values(e),o=Object.values(t),r=new Array(o.length).fill(!1);for(let i of n){let l=!1;for(let a=0;a<o.length;a++)if(!r[a]&&k(i,o[a])){r[a]=!0,l=!0;break}if(!l)return!1}return!0}return typeof e==typeof t}let j=new Set;c.Proxy=new Proxy(v,{construct(e,t){let n=w(t[0]),o=C(t[0]),r=P(t[0]),i=String(n??"");if(n!==null&&r!==null&&i.length<500&&m.filter(l=>l.filter(a=>a.test(i)).length===l.length).length===1&&[...r.querySelectorAll("*")].filter(l=>{if(!(l instanceof HTMLElement))return!1;let a=l.getClientRects()[0]?.height??0,p=Math.max(u(getComputedStyle(l).getPropertyValue("padding-bottom")),u(getComputedStyle(l).getPropertyValue("margin-bottom")));return a>0&&p>=a*(b-y)&&p<=a*(S+y)}).length>=1)console.debug(`[${d}]: Prevented declaring render function in Vue.js 3 for detected PowerLink skeleton:`,t[0],r),j.add(n),z(t[0],()=>null),c.document.dispatchEvent(new CustomEvent("PL2PlaceHolderProxy"));else if(o!==null&&j.has(o))return console.debug(`[${d}]: Prevented declaring render function in Vue.js 3 in SPA moving for detected PowerLink skeleton:`,t[0]),H(t[0],()=>null),c.document.dispatchEvent(new CustomEvent("PL2PlaceHolderProxy")),Reflect.construct(e,t);if(typeof t[1].set=="function"){let l=t[1].set;t[1].set=function(...a){if(M(a[2])){console.debug(`[${d}]: Proxy set called for PowerLink Skeleton:`,a);return}if(R(a[0])&&k({Dummy:[],PowerLinkTracking:[{Url:"",UrlObj:{Url:""}}],LayoutFormat:"",NumberKey:[0,0,0],PowerLinkText:[{Url:"",Title:"",No:0}]},a[0])){console.debug(`[${d}]: Proxy set called for PowerLink Skeleton (target check):`,a),c.document.dispatchEvent(new CustomEvent("PL2PlaceHolderProxy"));return}return f(l,this,a)}}return Reflect.construct(e,t)}}),c.document.addEventListener("PL2AdvertContainer",()=>{setTimeout(()=>{let e=new Set([h]);e=new Set([...e,...[...e].flatMap(t=>[...t.querySelectorAll("*")])]),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-bottom-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-left-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-right-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-top-width"))>=.5)),e=new Set([...e].filter(t=>[...t.querySelectorAll("*")].some(n=>{if(!(n instanceof HTMLElement))return!1;let o=n.getClientRects()[0]?.height??0,r=u(getComputedStyle(n).getPropertyValue("margin-bottom"));return o===0?!1:r>=o*.65&&r<=o*1.25}))),console.debug(`[${d}]: Removing PowerLink Skeleton Containers (PL2AdvertContainer):`,e),e.forEach(t=>{t.setAttribute("style","display: none !important;")})},2500)}),c.document.addEventListener("PL2PlaceHolderMobile",()=>{setTimeout(()=>{let e=new Set([...c.document.querySelectorAll("div[class] div[class] div[class] ~ div[class]")]);e=new Set([...e].filter(t=>t instanceof HTMLElement)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("margin-bottom"))>15||u(getComputedStyle(t).getPropertyValue("padding-top"))>20)),e=new Set([...e].filter(t=>t instanceof HTMLElement&&t.innerText.trim().length===0)),e=new Set([...e].filter(t=>[...t.querySelectorAll("*")].some(n=>n instanceof HTMLElement&&u(getComputedStyle(n).getPropertyValue("padding-top"))>=5&&u(getComputedStyle(n).getPropertyValue("padding-bottom"))>=5&&u(getComputedStyle(n).getPropertyValue("padding-left"))>=5&&u(getComputedStyle(n).getPropertyValue("padding-right"))>=5))),console.debug(`[${d}]: Removing PowerLink Skeleton Containers (PL2PlaceHolderMobile):`,e),e.forEach(t=>{t.setAttribute("style","display: none !important;")})},2500)}),c.document.addEventListener("PL2PlaceHolder",()=>{setTimeout(()=>{let e=new Set([...c.document.querySelectorAll("div[class] div[class] div[class] ~ div[class]")]);e=new Set([...e].filter(t=>t instanceof HTMLElement)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("padding-top"))>10||u(getComputedStyle(t).getPropertyValue("margin-top"))>10)),e=new Set([...e,...[...e].flatMap(t=>[...t.querySelectorAll("*:not(button)")])]),e=new Set([...e].filter(t=>t instanceof HTMLElement&&t.innerText.trim().length===0)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-bottom-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-left-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-right-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("border-top-width"))>=.5)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("transition-duration"))>=.01)),console.debug(`[${d}]: Removing PowerLink Skeleton Containers (PL2PlaceHolder):`,e),e.forEach(t=>{t.setAttribute("style","display: none !important;")})},2500)}),c.document.addEventListener("PL2PlaceHolderProxy",()=>{setTimeout(()=>{let e=new Set([...c.document.querySelectorAll("div[class] div[class] div[class] ~ div[class]")]);e=new Set([...e].filter(t=>t instanceof HTMLElement)),e=new Set([...e].filter(t=>u(getComputedStyle(t).getPropertyValue("padding-top"))>=5&&u(getComputedStyle(t).getPropertyValue("padding-bottom"))>=5&&u(getComputedStyle(t).getPropertyValue("padding-left"))>=5&&u(getComputedStyle(t).getPropertyValue("padding-right"))>=5&&u(getComputedStyle(t).getPropertyValue("border-top-width"))>=.35&&u(getComputedStyle(t).getPropertyValue("border-bottom-width"))>=.35&&u(getComputedStyle(t).getPropertyValue("border-left-width"))>=.35&&u(getComputedStyle(t).getPropertyValue("border-right-width"))>=.35&&t.getClientRects()[0]?.height<=20&&t.getClientRects()[0]?.height>0)),e=new Set([...e].filter(t=>t instanceof HTMLElement&&t.innerText.trim().length===0)),console.debug(`[${d}]: Removing PowerLink Skeleton Containers (PL2PlaceHolderProxy):`,e),e.forEach(t=>{t.setAttribute("style","display: none !important;")})},2500)})}T(Z);})();
|
|
25
|
+
(()=>{function f(e,r={}){let n=r.QuietMs??120,t=r.EventName??"vue:settled",o=r.ChangeEventName??"vue:dom-changed";if(!(e instanceof HTMLElement))throw new TypeError("TargetEl must be an HTMLElement");let l=-1,s=0,i=!1,a=performance.now(),c=g=>{e.dispatchEvent(new CustomEvent(o,{detail:{Seq:s,At:a,MutationCount:g.length,Mutations:g}}))},d=()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{i||e.dispatchEvent(new CustomEvent(t,{detail:{Seq:s,QuietMs:n,SettledAt:performance.now(),ElapsedSinceLastMutation:performance.now()-a,Target:e}}))})})},m=()=>{clearTimeout(l),l=setTimeout(d,n)},u=new MutationObserver(g=>{s+=1,a=performance.now(),c(g),m()});return u.observe(e,{subtree:!0,childList:!0,attributes:!0,characterData:!0}),m(),{Disconnect(){i=!0,clearTimeout(l),u.disconnect(),e.dispatchEvent(new CustomEvent("vue:observer-disconnected",{detail:{Target:e}}))}}}function p(e,r=document.documentElement){return new Promise(n=>{let t=r.querySelector(e);if(t&&t instanceof HTMLElement){n(t);return}let o=new MutationObserver(()=>{let l=r.querySelector(e);l&&l instanceof HTMLElement&&(o.disconnect(),n(l))});o.observe(r,{subtree:!0,childList:!0,attributes:!0})})}function C(e){let r=e.trim();if(!r||r==="none")return null;let n=r.match(/^url\((.*)\)$/i);if(!n)return null;let t=n[1].trim();return(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1)),t}function h(e,r){let n=r;for(;n;){let t=e.getComputedStyle(n).backgroundColor;if(t&&t!=="transparent"&&t!=="rgba(0, 0, 0, 0)")return t;n=n.parentElement}return"rgb(255, 255, 255)"}function y(e,r,n){let t=new Set;function o(s){s&&(s==="transparent"||s==="rgba(0, 0, 0, 0)"||t.add(s))}o(n);let l=e.getComputedStyle(r);if(o(l.backgroundColor),o(l.color),o(e.getComputedStyle(e.document.documentElement).backgroundColor),e.document.body){let s=e.getComputedStyle(e.document.body);o(s.backgroundColor),o(s.color)}return o("rgb(255, 255, 255)"),o("rgb(0, 0, 0)"),[...t]}function M(e,r){if(r instanceof e.HTMLImageElement)return r.currentSrc||r.src||""||null;let n=e.getComputedStyle(r).backgroundImage;return C(n)}function S(e,r){let n=0,t=new Map;r.addEventListener("message",i=>{let a=i.data;if(!a||!("RequestId"in a))return;let c=t.get(a.RequestId);if(c){if(t.delete(a.RequestId),a.Kind==="detect-result"){c.Resolve(a.Result);return}c.Reject(new Error(a.Error))}});function o(i){let a=`ocr-${Date.now()}-${n++}`,c={Kind:"detect",RequestId:a,...i};return new Promise((d,m)=>{t.set(a,{Resolve:d,Reject:m}),r.postMessage(c)})}async function l(i,a){let c=M(e,i);if(!c)return null;let d=await b(e,i,c),m=h(e,i),u=y(e,i,m);return o({ImageData:d,BackgroundCandidates:u,FontCandidates:a?.FontCandidates,ScoreThreshold:a?.ScoreThreshold})}async function s(i){let a=await b(e,i.HostElement,i.SourceUrl),c=h(e,i.HostElement),d=y(e,i.HostElement,c);return o({ImageData:a,BackgroundCandidates:d,FontCandidates:i.FontCandidates,ScoreThreshold:i.ScoreThreshold})}return{DetectFromElement:l,DetectFromSource:s,Terminate(){for(let i of t.values())i.Reject(new Error("OCR worker terminated"));t.clear(),r.terminate()}}}function w(e){return/^data:image\/svg\+xml(?:[;,]|$)/i.test(e)}function L(e,r){let n=e.atob(r),t=new Uint8Array(n.length);for(let o=0;o<n.length;o++)t[o]=n.charCodeAt(o);return new TextDecoder().decode(t)}function R(e,r){let n=r.indexOf(",");if(n<0)throw new Error("Invalid SVG data URL");let t=r.slice(0,n).toLowerCase(),o=r.slice(n+1);return t.includes(";base64")?L(e,o):decodeURIComponent(o)}function T(e,r,n,t){let l=new e.DOMParser().parseFromString(r,"image/svg+xml");if(l.querySelector("parsererror"))throw new Error("Failed to parse SVG markup");let s=l.documentElement;if(!s||s.nodeName.toLowerCase()!=="svg")throw new Error("SVG root element not found");return s.getAttribute("xmlns")||s.setAttribute("xmlns","http://www.w3.org/2000/svg"),s.getAttribute("width")||s.setAttribute("width",String(n)),s.getAttribute("height")||s.setAttribute("height",String(t)),new e.XMLSerializer().serializeToString(l)}function D(e){return e.complete&&e.naturalWidth>0?Promise.resolve():new Promise((r,n)=>{function t(){e.removeEventListener("load",o),e.removeEventListener("error",l)}function o(){t(),r()}function l(){t(),n(new Error("Failed to load SVG image"))}e.addEventListener("load",o),e.addEventListener("error",l)})}async function x(e,r){let n=new e.Image;n.decoding="async",n.src=r;try{if(await n.decode(),n.naturalWidth>0)return n}catch{}return await D(n),n}function v(e){return typeof e=="string"&&/^image\/svg\+xml(?:\s*;|$)/i.test(e)}function P(e,r){let n=r.getBoundingClientRect(),t=Math.max(1,e.devicePixelRatio||1);return{Width:Math.max(1,Math.round((n.width||r.clientWidth||96)*t)),Height:Math.max(1,Math.round((n.height||r.clientHeight||32)*t))}}async function E(e,r,n){let{Width:t,Height:o}=P(e,r),l=T(e,n,t,o),s=e.URL.createObjectURL(new e.Blob([l],{type:"image/svg+xml"}));try{let i=await x(e,s),a=e.document.createElement("canvas");a.width=t,a.height=o;let c=a.getContext("2d",{willReadFrequently:!0});if(!c)throw new Error("2D context unavailable");return c.clearRect(0,0,t,o),c.drawImage(i,0,0,t,o),c.getImageData(0,0,t,o)}finally{e.URL.revokeObjectURL(s)}}async function k(e,r){let n=await e.createImageBitmap(r);try{let t=e.document.createElement("canvas");t.width=n.width,t.height=n.height;let o=t.getContext("2d",{willReadFrequently:!0});if(!o)throw new Error("2D context unavailable");return o.drawImage(n,0,0),o.getImageData(0,0,t.width,t.height)}finally{n.close()}}async function b(e,r,n){if(w(n)){let o=R(e,n);return await E(e,r,o)}let t=await new Promise((o,l)=>{GM.xmlHttpRequest({url:n,method:"GET",responseType:"blob",onload:s=>{if(s.status<200||s.status>=300){l(new Error(`Failed to fetch image: ${s.status} ${s.statusText}`));return}let i=s.response;if(!(i instanceof Blob)){l(new Error("Failed to fetch image: invalid blob response"));return}let a=s.responseHeaders.match(/^content-type:\s*(.+)$/im),c=a?a[1].trim():null;o({BlobData:i,ContentTypeHeader:c})},onerror:l,ontimeout:l})});if(v(t.BlobData.type)||v(t.ContentTypeHeader)){let o=await t.BlobData.text();return await E(e,r,o)}return await k(e,t.BlobData)}var I=typeof unsafeWindow<"u"?unsafeWindow:window;async function H(e,r="NamuLink"){let n=e.Reflect.apply,t=[[/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/,/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/],[/\( *\) *=> *{ *var _0x[a-z0-9]+ *= *_0x[a-z0-9]+ *; *if *\( *this\[ *_0x[a-z0-9]+ *\( *0x[0-9a-f]+ *\) *\] *\) *return *clearTimeout/,/\( *0x[0-9a-f]+ *\) *\] *\) *, *void *\( *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *= *void *\([x0-9a-f*+-]+ *\) *\) *; *this\[_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *\(\) *;/]];e.setTimeout=new Proxy(e.setTimeout,{apply(i,a,c){let d=String(c[0]);return t.filter(m=>m.filter(u=>u.test(d)).length>=1).length===1?(console.debug(`[${r}]: setTimeout called for PowerLink Skeleton:`,c[0]),n(i,a,[()=>{},0])):n(i,a,c)}});let o=await p("#app",e.document);f(o,{QuietMs:250,EventName:"vue:settled",ChangeEventName:"vue:change"});let l=S(e,new Worker(URL.createObjectURL(new Blob(['(()=>{var b=["\\uD30C\\uC6CC\\uB9C1\\uD06C","\\uAD11\\uACE0","\\uAD11\\uACE0\\uB4F1\\uB85D"],k=["Pretendard JP, sans-serif","Pretendard, sans-serif","system-ui, sans-serif","Apple SD Gothic Neo, sans-serif","Nanum Gothic, sans-serif","Noto Sans KR, sans-serif","Arial, sans-serif"],H=new Map;function T(t,n){return new OffscreenCanvas(Math.max(1,Math.floor(t)),Math.max(1,Math.floor(n)))}function C(t){let n=t.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("2D context unavailable");return n}function Y(t){let n=C(t),{width:a,height:e}=t,r=n.getImageData(0,0,a,e).data,o=new Uint8ClampedArray(a*e);for(let i=0,s=0;i<r.length;i+=4,s++){let l=r[i],h=r[i+1],g=r[i+2];o[s]=Math.round(.299*l+.587*h+.114*g)}return{Width:a,Height:e,Data:o}}function A(t){let n=new Uint32Array(256);for(let l=0;l<t.Data.length;l++)n[t.Data[l]]++;let a=t.Data.length,e=0;for(let l=0;l<256;l++)e+=l*n[l];let r=0,o=0,i=-1,s=127;for(let l=0;l<256;l++){if(o+=n[l],o===0)continue;let h=a-o;if(h===0)break;r+=l*n[l];let g=r/o,d=(e-r)/h,c=o*h*(g-d)*(g-d);c>i&&(i=c,s=l)}return s}function M(t){let n=A(t),a=0,e=0;for(let i=0;i<t.Data.length;i++)t.Data[i]<n?a++:e++;let r=a<e,o=new Uint8Array(t.Width*t.Height);for(let i=0;i<t.Data.length;i++){let s=r?t.Data[i]<n:t.Data[i]>n;o[i]=s?1:0}return{Width:t.Width,Height:t.Height,Data:o}}function O(t){let n=new Uint8Array(t.Width*t.Height);for(let a=1;a<t.Height-1;a++)for(let e=1;e<t.Width-1;e++){let r=1;for(let o=-1;o<=1&&r;o++)for(let i=-1;i<=1;i++)if(t.Data[(a+o)*t.Width+(e+i)]===0){r=0;break}n[a*t.Width+e]=r}return{Width:t.Width,Height:t.Height,Data:n}}function w(t){let n=new Uint8Array(t.Width*t.Height);for(let a=1;a<t.Height-1;a++)for(let e=1;e<t.Width-1;e++){let r=0;for(let o=-1;o<=1&&!r;o++)for(let i=-1;i<=1;i++)if(t.Data[(a+o)*t.Width+(e+i)]===1){r=1;break}n[a*t.Width+e]=r}return{Width:t.Width,Height:t.Height,Data:n}}function N(t){return w(O(w(t)))}function v(t,n=20){let a=new Uint8Array(t.Width*t.Height),e=[],r=new Int32Array(t.Width*t.Height),o=new Int32Array(t.Width*t.Height);for(let i=0;i<t.Height;i++)for(let s=0;s<t.Width;s++){let l=i*t.Width+s;if(a[l]||t.Data[l]===0)continue;let h=0,g=0;r[g]=s,o[g]=i,g++,a[l]=1;let d=s,c=i,u=s,f=i,X=0;for(;h<g;){let m=r[h],D=o[h];h++,X++,m<d&&(d=m),D<c&&(c=D),m>u&&(u=m),D>f&&(f=D);for(let I=-1;I<=1;I++)for(let y=-1;y<=1;y++){if(y===0&&I===0)continue;let W=m+y,B=D+I;if(W<0||B<0||W>=t.Width||B>=t.Height)continue;let x=B*t.Width+W;a[x]||t.Data[x]===0||(a[x]=1,r[g]=W,o[g]=B,g++)}}X>=n&&e.push({X:d,Y:c,Width:u-d+1,Height:f-c+1})}return e}function U(t,n=8,a=4){let e=[...t],r=!0;function o(i,s){let l=i.X+i.Width,h=i.Y+i.Height,g=s.X+s.Width,d=s.Y+s.Height;return!(l+n<s.X||g+n<i.X||h+a<s.Y||d+a<i.Y)}for(;r;){r=!1;t:for(let i=0;i<e.length;i++)for(let s=i+1;s<e.length;s++){if(!o(e[i],e[s]))continue;let l=e[i],h=e[s];e[i]={X:Math.min(l.X,h.X),Y:Math.min(l.Y,h.Y),Width:Math.max(l.X+l.Width,h.X+h.Width)-Math.min(l.X,h.X),Height:Math.max(l.Y+l.Height,h.Y+h.Height)-Math.min(l.Y,h.Y)},e.splice(s,1),r=!0;break t}}return e}function R(t,n){let a=new Uint8Array(n.Width*n.Height);for(let e=0;e<n.Height;e++)for(let r=0;r<n.Width;r++)a[e*n.Width+r]=t.Data[(n.Y+e)*t.Width+(n.X+r)];return{Width:n.Width,Height:n.Height,Data:a}}function E(t){let n=t.Width,a=t.Height,e=-1,r=-1;for(let o=0;o<t.Height;o++)for(let i=0;i<t.Width;i++)t.Data[o*t.Width+i]!==0&&(i<n&&(n=i),o<a&&(a=o),i>e&&(e=i),o>r&&(r=o));return e<n||r<a?{Width:1,Height:1,Data:new Uint8Array([0])}:R(t,{X:n,Y:a,Width:e-n+1,Height:r-a+1})}function P(t,n,a){let e=new Uint8Array(n*a);for(let r=0;r<a;r++)for(let o=0;o<n;o++){let i=Math.min(t.Width-1,Math.floor(o/n*t.Width)),s=Math.min(t.Height-1,Math.floor(r/a*t.Height));e[r*n+o]=t.Data[s*t.Width+i]}return{Width:n,Height:a,Data:e}}function p(t,n=64){let a=E(t),e=Math.max(a.Width,a.Height),r=new Uint8Array(e*e),o=Math.floor((e-a.Width)/2),i=Math.floor((e-a.Height)/2);for(let s=0;s<a.Height;s++)for(let l=0;l<a.Width;l++)r[(s+i)*e+(l+o)]=a.Data[s*a.Width+l];return P({Width:e,Height:e,Data:r},n,n)}function F(t,n){if(t.Width!==n.Width||t.Height!==n.Height)throw new Error("Image size mismatch");let a=0;for(let e=0;e<t.Data.length;e++)t.Data[e]!==n.Data[e]&&a++;return a/t.Data.length}function K(t,n){let a=`${t}__${n}`,e=H.get(a);if(e)return e;let r=256,o=96,i=T(r,o),s=C(i);s.fillStyle="white",s.fillRect(0,0,r,o);let l=Math.floor(o*.72);for(;l>8;){s.clearRect(0,0,r,o),s.fillStyle="white",s.fillRect(0,0,r,o),s.fillStyle="black",s.textAlign="center",s.textBaseline="middle",s.font=`700 ${l}px ${n}`;let g=s.measureText(t),d=g.width,c=(g.actualBoundingBoxAscent||l*.8)+(g.actualBoundingBoxDescent||l*.2);if(d<=r*.9&&c<=o*.9){s.fillText(t,r/2,o/2);let u=Y(i),f=p(M(u));return H.set(a,f),f}l--}s.font=`700 12px ${n}`,s.fillStyle="black",s.textAlign="center",s.textBaseline="middle",s.fillText(t,r/2,o/2);let h=p(M(Y(i)));return H.set(a,h),h}function V(t,n,a){let e=p(t),r=Number.POSITIVE_INFINITY;for(let o of a){let i=K(n,o),s=F(e,i);s<r&&(r=s)}return r}function z(t){let n=v(t,16);return U(n,10,6).filter(e=>{if(e.Width<8||e.Height<8)return!1;let r=e.Width/e.Height;return r>.5&&r<12})}async function $(t){let a=q(t.ImageData)?t.BackgroundCandidates:t.BackgroundCandidates.slice(0,1),e=t.FontCandidates??k,r=t.ScoreThreshold??.32,o=null;for(let i of a){let s=_(t.ImageData,i),l=G(s),h=N(M(l)),g=z(h);if(g.length!==0)for(let d of g){let c=R(h,d);for(let u of b){let f=V(c,u,e);(!o||f<o.Score)&&(o={Label:u,Score:f,Box:d})}}}return!o||o.Score>r?null:o}function G(t){let{width:n,height:a,data:e}=t,r=new Uint8ClampedArray(n*a);for(let o=0,i=0;o<e.length;o+=4,i++){let s=e[o],l=e[o+1],h=e[o+2];r[i]=Math.round(.299*s+.587*l+.114*h)}return{Width:n,Height:a,Data:r}}function q(t){let n=t.data;for(let a=3;a<n.length;a+=4)if(n[a]<255)return!0;return!1}function _(t,n){let a=T(t.width,t.height),e=C(a);return e.fillStyle=n,e.fillRect(0,0,t.width,t.height),e.putImageData(t,0,0),e.getImageData(0,0,t.width,t.height)}self.addEventListener("message",t=>{(async()=>{let n=t.data;if(!(!n||n.Kind!=="detect"))try{let a=await $(n),e={Kind:"detect-result",RequestId:n.RequestId,Result:a};self.postMessage(e)}catch(a){let e=a instanceof Error?a.message:String(a),r={Kind:"detect-error",RequestId:n.RequestId,Error:e};self.postMessage(r)}})()});})();\n'],{type:"application/javascript"}))));o.addEventListener("vue:settled",async()=>{let i=[...document.querySelectorAll("#app div[class] div[class] ~ div[class]")].filter(a=>a instanceof HTMLElement);i=i.filter(a=>parseFloat(getComputedStyle(a).getPropertyValue("padding-top"))>=20||parseFloat(getComputedStyle(a).getPropertyValue("margin-top"))>=20),i=i.filter(a=>[...a.querySelectorAll("*")].filter(c=>parseFloat(getComputedStyle(c).getPropertyValue("padding-top"))>=5&&parseFloat(getComputedStyle(c).getPropertyValue("border-bottom-width"))>=.1).length===1),i=await(async()=>{let a=[];for(let c of i){let d=[...c.querySelectorAll("*")].filter(u=>u instanceof HTMLElement).filter(u=>u instanceof HTMLImageElement||getComputedStyle(u).backgroundImage!=="none"),m=0;for(let u of d)if(await l.DetectFromElement(u,{ScoreThreshold:.32})!==null&&(m+=1),m>=1){a.push(c);break}}return a})(),i.forEach(a=>i.push(...new Set([...a.querySelectorAll("*")].filter(c=>c instanceof HTMLElement)))),i=[...new Set(i)],i=i.filter(a=>parseFloat(getComputedStyle(a).getPropertyValue("padding-left"))>=5&&parseFloat(getComputedStyle(a).getPropertyValue("border-right-width"))>=.1),console.debug(`[${r}] Detected ${i.length} potential ad elements.`,i),i.forEach(a=>{a.style.setProperty("display","none","important")})}),["https://fonts.googleapis.com/css2?family=Nanum Gothic&display=swap"].forEach(i=>{let a=e.document.createElement("link");a.rel="stylesheet",a.href=i,e.document.head.appendChild(a)})}H(I);})();
|
|
25
26
|
/*!
|
|
26
27
|
* @license MPL-2.0
|
|
27
28
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function WaitForElement(Selector: string, Root?: HTMLElement | Document): Promise<HTMLElement>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function WaitForElement(Selector, Root = document.documentElement) {
|
|
2
|
+
return new Promise((Resolve) => {
|
|
3
|
+
const Found = Root.querySelector(Selector);
|
|
4
|
+
if (Found && Found instanceof HTMLElement) {
|
|
5
|
+
Resolve(Found);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const Observer = new MutationObserver(() => {
|
|
9
|
+
const El = Root.querySelector(Selector);
|
|
10
|
+
if (El && El instanceof HTMLElement) {
|
|
11
|
+
Observer.disconnect();
|
|
12
|
+
Resolve(El);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Observer.observe(Root, {
|
|
16
|
+
subtree: true,
|
|
17
|
+
childList: true,
|
|
18
|
+
attributes: true
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* Contributors:
|
|
8
8
|
* - See Git history at https://github.com/FilteringDev/NamuLink for detailed authorship information.
|
|
9
9
|
*/
|
|
10
|
-
export declare function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptName?: string): void
|
|
10
|
+
export declare function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptName?: string): Promise<void>;
|