@filteringdev/namulink 20.0.0 → 20.0.1
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 +2 -2
- package/dist/index.js +11 -4
- package/package.json +1 -1
package/dist/NamuLink.user.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
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 20.0.
|
|
11
|
+
// @version 20.0.1
|
|
12
12
|
// @author PiQuark6046 and contributors
|
|
13
13
|
//
|
|
14
14
|
// @grant unsafeWindow
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// ==/UserScript==
|
|
23
23
|
|
|
24
24
|
|
|
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
|
+
(()=>{function p(e,r={}){let n=r.QuietMs??120,t=r.EventName??"vue:settled",a=r.ChangeEventName??"vue:dom-changed";if(!(e instanceof HTMLElement))throw new TypeError("TargetEl must be an HTMLElement");let l=-1,s=0,o=!1,i=performance.now(),u=g=>{e.dispatchEvent(new CustomEvent(a,{detail:{Seq:s,At:i,MutationCount:g.length,Mutations:g}}))},c=()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{o||e.dispatchEvent(new CustomEvent(t,{detail:{Seq:s,QuietMs:n,SettledAt:performance.now(),ElapsedSinceLastMutation:performance.now()-i,Target:e}}))})})},d=()=>{clearTimeout(l),l=setTimeout(c,n)},m=new MutationObserver(g=>{s+=1,i=performance.now(),u(g),d()});return m.observe(e,{subtree:!0,childList:!0,attributes:!0,characterData:!0}),d(),{Disconnect(){o=!0,clearTimeout(l),m.disconnect(),e.dispatchEvent(new CustomEvent("vue:observer-disconnected",{detail:{Target:e}}))}}}function h(e,r=document.documentElement){return new Promise(n=>{let t=r.querySelector(e);if(t&&t instanceof HTMLElement){n(t);return}let a=new MutationObserver(()=>{let l=r.querySelector(e);l&&l instanceof HTMLElement&&(a.disconnect(),n(l))});a.observe(r,{subtree:!0,childList:!0,attributes:!0})})}function M(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 y(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 v(e,r,n){let t=new Set;function a(s){s&&(s==="transparent"||s==="rgba(0, 0, 0, 0)"||t.add(s))}a(n);let l=e.getComputedStyle(r);if(a(l.backgroundColor),a(l.color),a(e.getComputedStyle(e.document.documentElement).backgroundColor),e.document.body){let s=e.getComputedStyle(e.document.body);a(s.backgroundColor),a(s.color)}return a("rgb(255, 255, 255)"),a("rgb(0, 0, 0)"),[...t]}function w(e,r){if(r instanceof e.HTMLImageElement)return r.currentSrc||r.src||""||null;let n=e.getComputedStyle(r).backgroundImage;return M(n)}function C(e,r){let n=0,t=new Map;r.addEventListener("message",o=>{let i=o.data;if(!i||!("RequestId"in i))return;let u=t.get(i.RequestId);if(u){if(t.delete(i.RequestId),i.Kind==="detect-result"){u.Resolve(i.Result);return}u.Reject(new Error(i.Error))}});function a(o){let i=`ocr-${Date.now()}-${n++}`,u={Kind:"detect",RequestId:i,...o};return new Promise((c,d)=>{t.set(i,{Resolve:c,Reject:d}),r.postMessage(u)})}async function l(o,i){let u=w(e,o);if(!u)return null;let c=await S(e,o,u),d=y(e,o),m=v(e,o,d);return a({ImageData:c,BackgroundCandidates:m,FontCandidates:i?.FontCandidates,ScoreThreshold:i?.ScoreThreshold})}async function s(o){let i=await S(e,o.HostElement,o.SourceUrl),u=y(e,o.HostElement),c=v(e,o.HostElement,u);return a({ImageData:i,BackgroundCandidates:c,FontCandidates:o.FontCandidates,ScoreThreshold:o.ScoreThreshold})}return{DetectFromElement:l,DetectFromSource:s,Terminate(){for(let o of t.values())o.Reject(new Error("OCR worker terminated"));t.clear(),r.terminate()}}}function T(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 a=0;a<n.length;a++)t[a]=n.charCodeAt(a);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(),a=r.slice(n+1);return t.includes(";base64")?L(e,a):decodeURIComponent(a)}function x(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",a),e.removeEventListener("error",l)}function a(){t(),r()}function l(){t(),n(new Error("Failed to load SVG image"))}e.addEventListener("load",a),e.addEventListener("error",l)})}async function P(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 E(e){return typeof e=="string"&&/^image\/svg\+xml(?:\s*;|$)/i.test(e)}function k(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 b(e,r,n){let{Width:t,Height:a}=k(e,r),l=x(e,n,t,a),s=e.URL.createObjectURL(new e.Blob([l],{type:"image/svg+xml"}));try{let o=await P(e,s),i=e.document.createElement("canvas");i.width=t,i.height=a;let u=i.getContext("2d",{willReadFrequently:!0});if(!u)throw new Error("2D context unavailable");return u.clearRect(0,0,t,a),u.drawImage(o,0,0,t,a),u.getImageData(0,0,t,a)}finally{e.URL.revokeObjectURL(s)}}async function F(e,r){let n=await e.createImageBitmap(r);try{let t=e.document.createElement("canvas");t.width=n.width,t.height=n.height;let a=t.getContext("2d",{willReadFrequently:!0});if(!a)throw new Error("2D context unavailable");return a.drawImage(n,0,0),a.getImageData(0,0,t.width,t.height)}finally{n.close()}}async function S(e,r,n){if(T(n)){let a=R(e,n);return await b(e,r,a)}let t=await new Promise((a,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 o=s.response;if(!(o instanceof Blob)){l(new Error("Failed to fetch image: invalid blob response"));return}let i=s.responseHeaders.match(/^content-type:\s*(.+)$/im),u=i?i[1].trim():null;a({BlobData:o,ContentTypeHeader:u})},onerror:l,ontimeout:l})});if(E(t.BlobData.type)||E(t.ContentTypeHeader)){let a=await t.BlobData.text();return await b(e,r,a)}return await F(e,t.BlobData)}var H=typeof unsafeWindow<"u"?unsafeWindow:window;async function I(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(o,i,u){let c=String(u[0]);return t.filter(d=>d.filter(m=>m.test(c)).length>=1).length===1?(console.debug(`[${r}]: setTimeout called for PowerLink Skeleton:`,u[0]),n(o,i,[()=>{},0])):n(o,i,u)}});let a=await h("#app",e.document);p(a,{QuietMs:250,EventName:"vue:settled",ChangeEventName:"vue:change"});let l=C(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"}))));a.addEventListener("vue:settled",async()=>{let o=[...document.querySelectorAll("#app div[class] div[class] ~ div[class]")].filter(c=>c instanceof HTMLElement);o=o.filter(c=>parseFloat(getComputedStyle(c).getPropertyValue("padding-top"))>=20||parseFloat(getComputedStyle(c).getPropertyValue("margin-top"))>=20||parseFloat(getComputedStyle(c).getPropertyValue("margin-bottom"))>=12.5),o=o.filter(c=>[...c.querySelectorAll("*")].filter(d=>parseFloat(getComputedStyle(d).getPropertyValue("padding-top"))>=5&&parseFloat(getComputedStyle(d).getPropertyValue("border-bottom-width"))>=.1).length===1),o=await(async()=>{let c=[];for(let d of o){let m=[...d.querySelectorAll("*")].filter(f=>f instanceof HTMLElement).filter(f=>f instanceof HTMLImageElement||getComputedStyle(f).backgroundImage!=="none"),g=0;for(let f of m)if(await l.DetectFromElement(f,{ScoreThreshold:.32})!==null&&(g+=1),g>=1){c.push(d);break}}return c})(),o.forEach(c=>o.push(...new Set([...c.querySelectorAll("*")].filter(d=>d instanceof HTMLElement)))),o=[...new Set(o)];let i=o.filter(c=>parseFloat(getComputedStyle(c).getPropertyValue("padding-left"))>=5&&parseFloat(getComputedStyle(c).getPropertyValue("border-right-width"))>=.1);console.debug(`[${r}] vue:settled RealTargeted`,i),i.forEach(c=>{c.style.setProperty("display","none","important")});let u=o.filter(c=>c instanceof HTMLElement&&c.innerText.trim().length===0);console.debug(`[${r}] vue:settled FrameTargeted`,u),u.forEach(c=>{c.style.setProperty("display","none","important")})}),["https://fonts.googleapis.com/css2?family=Nanum Gothic&display=swap"].forEach(o=>{let i=e.document.createElement("link");i.rel="stylesheet",i.href=o,e.document.head.appendChild(i)})}I(H);})();
|
|
26
26
|
/*!
|
|
27
27
|
* @license MPL-2.0
|
|
28
28
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,9 @@ export async function RunNamuLinkUserscript(BrowserWindow, UserscriptName = 'Nam
|
|
|
39
39
|
const OCRInstance = CreateOcrWorkerClient(BrowserWindow, new Worker(URL.createObjectURL(new Blob([__OCR_WORKER_CODE__], { type: 'application/javascript' }))));
|
|
40
40
|
ArticleHTMLElement.addEventListener('vue:settled', async () => {
|
|
41
41
|
let Targeted = [...document.querySelectorAll('#app div[class] div[class] ~ div[class]')].filter(Ele => Ele instanceof HTMLElement);
|
|
42
|
-
Targeted = Targeted.filter(Ele => parseFloat(getComputedStyle(Ele).getPropertyValue('padding-top')) >= 20 ||
|
|
42
|
+
Targeted = Targeted.filter(Ele => parseFloat(getComputedStyle(Ele).getPropertyValue('padding-top')) >= 20 ||
|
|
43
|
+
parseFloat(getComputedStyle(Ele).getPropertyValue('margin-top')) >= 20 ||
|
|
44
|
+
parseFloat(getComputedStyle(Ele).getPropertyValue('margin-bottom')) >= 12.5);
|
|
43
45
|
Targeted = Targeted.filter(Ele => [...Ele.querySelectorAll('*')].filter(Child => parseFloat(getComputedStyle(Child).getPropertyValue('padding-top')) >= 5 && parseFloat(getComputedStyle(Child).getPropertyValue('border-bottom-width')) >= 0.1).length === 1);
|
|
44
46
|
Targeted = await (async () => {
|
|
45
47
|
const NextTargeted = [];
|
|
@@ -66,9 +68,14 @@ export async function RunNamuLinkUserscript(BrowserWindow, UserscriptName = 'Nam
|
|
|
66
68
|
})();
|
|
67
69
|
Targeted.forEach(Ele => Targeted.push(...new Set([...Ele.querySelectorAll('*')].filter(Child => Child instanceof HTMLElement))));
|
|
68
70
|
Targeted = [...new Set(Targeted)];
|
|
69
|
-
|
|
70
|
-
console.debug(`[${UserscriptName}]
|
|
71
|
-
|
|
71
|
+
let RealTargeted = Targeted.filter(Ele => parseFloat(getComputedStyle(Ele).getPropertyValue('padding-left')) >= 5 && parseFloat(getComputedStyle(Ele).getPropertyValue('border-right-width')) >= 0.1);
|
|
72
|
+
console.debug(`[${UserscriptName}] vue:settled RealTargeted`, RealTargeted);
|
|
73
|
+
RealTargeted.forEach(Ele => {
|
|
74
|
+
Ele.style.setProperty('display', 'none', 'important');
|
|
75
|
+
});
|
|
76
|
+
let FrameTargeted = Targeted.filter(Ele => Ele instanceof HTMLElement && Ele.innerText.trim().length === 0);
|
|
77
|
+
console.debug(`[${UserscriptName}] vue:settled FrameTargeted`, FrameTargeted);
|
|
78
|
+
FrameTargeted.forEach(Ele => {
|
|
72
79
|
Ele.style.setProperty('display', 'none', 'important');
|
|
73
80
|
});
|
|
74
81
|
});
|