trackkun-dom 2.34.3 → 2.35.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/stripper.js +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trackkun-dom",
3
3
  "author": "endyquang",
4
- "version": "2.34.3",
4
+ "version": "2.35.0",
5
5
  "license": "UNLICENSED",
6
6
  "description": "MP DOM parser & configurations",
7
7
  "main": "index.js",
package/stripper.js CHANGED
@@ -1 +1 @@
1
- (function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h.$mpStripper={}))})(this,(function(h){"use strict";function d(t,e){if(typeof t.checkVisibility=="function")return t.checkVisibility({opacityProperty:!0,visibilityProperty:!1,contentVisibilityAuto:!1});const n=window.getComputedStyle(t);if(n.display==="none"||n.opacity&&parseFloat(n.opacity)<.1)return!1;if(!e)return!0;const r=t.parentElement;return!r||r===e?!0:d(r,e)}function K({sel:t,heading:e,paraSel:n,useObfFont:r}){const o=["H1","H2","H3","H4","H5","H6","P","BLOCKQUOTE","PRE","CODE"],i=["BR","HR"],a=["BUTTON","FIGURE","IMG","SCRIPT","SELECT","INPUT","FORM","IFRAME","NAV","FOOTER","ASIDE","TABLE"],s=J(t),Ft=Z(s),Ut=r?tt(s):void 0,G=kt(s);if(!G)return;return{el:G,isRTL:Ft,fontFamily:Ut};function kt(f){let l=0,m=!1,c=0,p=0,R=!1;const w=z(f,o.includes(f.tagName)||!!n&&f.matches(n))?.node;if(!w)return;if(e){const u=document.createElement("h1");u.innerText=e,w.prepend(u)}return Bt(w),$t(w),w;function z(u,b){if(R)return;if(u.nodeType===Node.TEXT_NODE)return b&&u.textContent?.trim()?{node:u.cloneNode()}:void 0;if(u.nodeType!==Node.ELEMENT_NODE)return;const y=u.tagName;if(a.includes(y)||y==="A"&&(m||!b))return;if(i.includes(y))return b?{node:document.createElement(y),isEmpty:!0}:{aborted:!0};if(u.getAttribute("aria-hidden")==="true"||!d(u)||window.getComputedStyle(u).position==="fixed")return;const X=!!n&&u.matches(n),Y=X||o.includes(y),xt=b||Y,H=[];if(Array.from(u.childNodes).forEach(N=>{if(R)return;const D=z(N,xt);if(D?.aborted)return;const Q=D?.node;if(Q){if(p=D?.isEmpty?p+1:0,p>2)return;H.push(Q),m?c=0:++l>30&&(m=!0)}else m&&++c>30&&(R=!0)}),!H.length)return Y?{node:document.createElement("p"),isEmpty:!0}:void 0;const L=document.createElement(X?"p":y==="BODY"?"div":y==="a"?"span":y),M=u.getAttribute("dir");return M&&M!=="auto"&&L.setAttribute("dir",M),H.forEach(N=>L.appendChild(N)),{node:L}}}function $t(f){P(f,l=>{if(l===f)return;const m=l.tagName;if(i.includes(m)||o.includes(m))return;const c=l.parentElement;if(c?.childNodes.length===1){Array.from(l.childNodes).forEach(p=>{c.appendChild(p)}),c.removeChild(l);return}l.childNodes.length===1&&l.replaceWith(l.childNodes[0])})}function Bt(f){let l=!1;const m=[];T(f,c=>o.includes(c.tagName)?[]:Array.from(c.children),c=>{const p=c.textContent.trim();if(!p)return!0;if(l)return!1;if(l=!I(c),m.includes(p))return!0;if(l)return!1;m.push(p)}),T(f,c=>o.includes(c.tagName)?[]:Array.from(c.children).reverse(),c=>!c.textContent.trim()||I(c))}}function I(t){const e=t.nodeName;return e.length===2&&e.startsWith("H")}function J(t){const e=(t??"main,article").split(",").filter(Boolean);for(const r of e){const o=document.querySelector(r);if(o)return o}const n=document.querySelector("p:has(+ p), h1, h2");if(n){let r=n;for(;r!==document.body;)r=r.parentElement;return r}return document.body}function Z(t,e){if(t.getAttribute("dir")==="rtl")return!0;const n=t.querySelector("p")||t.querySelector("div:not(:empty)")||t;return n.getAttribute("dir")==="rtl"?!0:window.getComputedStyle(n).direction==="rtl"}function tt(t,e){const n=t.querySelector("p")||t.querySelector("div:not(:empty)")||t;return window.getComputedStyle(n).fontFamily}function P(t,e){Array.from(t.children).forEach(n=>{P(n,e)}),e(t)}function T(t,e,n){const r=e(t);let o=!1;for(let i=0;i<r.length;i++){const a=r[i],s=T(a,e,n);if(s!==void 0){if(!s)return!1;et(a)}else o=!0}if(!o)return n(t)}function et(t){t.parentNode?.removeChild(t)}var nt=(t=>(t[t.reading=1]="reading",t[t.paused=2]="paused",t[t.plan=3]="plan",t[t.completed=4]="completed",t[t.dropped=5]="dropped",t[t.deleted=6]="deleted",t))(nt||{}),rt=(t=>(t[t.ok=1]="ok",t[t.hidden=2]="hidden",t[t.deleted=3]="deleted",t))(rt||{}),ot=(t=>(t[t.aggregator=0]="aggregator",t[t.scanlator=1]="scanlator",t))(ot||{}),it=(t=>(t.id="id",t.name="name",t.slug="slug",t))(it||{}),at=(t=>(t.blank="about:blank",t.title="meta.title",t.reader="meta.reader",t))(at||{}),q=(t=>(t[t.manga=1]="manga",t[t.novel=2]="novel",t[t.anime=3]="anime",t))(q||{}),ct=(t=>(t[t.pending=0]="pending",t[t.completed=1]="completed",t[t.offline=2]="offline",t[t.incompat=3]="incompat",t))(ct||{});function O(t,e){let n=[e??document.documentElement];const r=t.split("->");for(let o=0;o<r.length;o++){const i=r[o];n=n.map(a=>Array.from((a.shadowRoot??a).querySelectorAll(i))).flat()}return n}function A(t=0){return new Promise(e=>setTimeout(e,t))}async function v(t,e,n){const r=await n(()=>{t=0});if(r!==void 0)return r;if(!(t<=0))return await new Promise(o=>{setTimeout(async()=>{const i=await v(t-1,e,n);o(i)},e)})}async function st(t,e,n=0){const r=e.root??document.documentElement,o=e.timeoutMs;return v(o/50,50,()=>{const i=e.all===!0?Array.from(r.querySelectorAll(t)):r.querySelector(t)??void 0;return(e.all?!i?.length:!i)?void 0:i})}function lt(t,e){return t>=280&&e>=50||t>=160&&e>=280}function g(t){const e=t.getBoundingClientRect();return lt(e.width,e.height)}async function ut(t,e){const n=await dt(t,e);return W(n?.parentElement??t)}async function dt(t,e){if(e?.imgDivs)return await st(e.imgDivs,{timeoutMs:15e3});const n=Array.from(t.querySelectorAll(e?.imgs?.split("|")[0]??"img:not(nav img, header img, footer img, aside img),canvas"));if(n.length)return n.find(r=>d(r,t)&&(g(r)||r instanceof HTMLImageElement&&(!r.width||!r.height)))}function W(t){return t===document.documentElement||t.scrollHeight-t.clientHeight>=10&&window.getComputedStyle(t).overflow!=="visible"?t:W(t.parentElement)}function mt(t,e){if(t instanceof HTMLOptionElement){const n=t.parentElement instanceof HTMLOptGroupElement?t.parentElement.parentElement:t.parentElement;if(!n||!(n instanceof HTMLSelectElement))return;const r=t.getAttribute("value")||"";if(n.value===r)return;n.value=r,n.dispatchEvent(new Event("change"));return}t instanceof HTMLAnchorElement&&e?.preventDefault!==!1&&t.addEventListener("click",n=>n.preventDefault(),{once:!0}),t.click(),t.dispatchEvent(new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,pointerType:"mouse",button:0})),t.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window,button:0}))}function F(t,e){const n=document;if(t.startsWith("//")){const r=document.evaluate(t,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return r instanceof HTMLElement?r:void 0}return n.querySelector(t)??void 0}async function ft(t){const e=await pt(t),n=t?.content;return n?await v(e?30:10,100,()=>{for(const r of n.split(",")){const o=document.querySelector(r);if(o)return o}})??document.body:document.body}async function pt(t){const{lstrip:e,lstripBtn:n}=t||{};if(!e||!n||F(e))return!1;const r=n.split(";");for(const o of r)if(!await yt(o.trim()))return!1;return!0}async function yt(t){const e=await v(50,30,()=>F(t));return e?(mt(e),await A(),!0):!1}function ht(t){return S(t)}async function S(t,e=0,n=0){const r=await ft(t);gt(r);const o=await ut(r,t);await vt(o,{stepMs:100,durationMs:1e4});const i=t?.imgDivs?wt(r,t.imgDivs):k(r),a=i===void 0;if(a&&n===50){if(!t?.imgDivs&&$(r))return r;throw new Error("EMPTY")}return i!==!1?(await A(500),await S(t,0,a?n+1:0),r):e>=1?r:await S(t,e+1)}function gt(t){const e=Array.from(t.querySelectorAll('img[loading="lazy"]'));for(const n of e)n.setAttribute("loading","eager");U(t,"data-src"),U(t,"data-url")}function U(t,e){const n=Array.from(t.querySelectorAll(`img[${e}]`));for(const r of n){const o=r.getAttribute(e)?.split(" ")[0];o&&r.src!==o&&(r.src=o)}}function wt(t,e){const n=O(e,t);if(n.length)return n.some(r=>$(r)?!1:k(r)!==!1)}function k(t){const e=Array.from(t.querySelectorAll("img"));let n=!1;for(const r of e){if(!d(r,t))continue;const o=g(r);if(n=n||o,!r.complete&&(o||!r.width||!r.height))return!0}return n?!1:void 0}function $(t){return Array.from(t.querySelectorAll("canvas")).some(e=>d(e,t)&&g(e))}async function vt(t,{stepMs:e,durationMs:n}){await Et(t,n,e)}async function Et(t,e,n){t.style.setProperty("scroll-behavior","auto");let r=e;for(;r>0&&t.scrollTop+t.clientHeight+200<t.scrollHeight;){const o=t.scrollHeight-t.scrollTop-t.clientHeight;t.scrollTop+=o/(r/n),r-=n,await A(n)}}function B(){const t=document.createElement("template");t.innerHTML="<iframe></iframe>";const e=t.content.querySelector("iframe");if(e){e?.style.setProperty("style","none"),document.body.appendChild(e);const n=e?.contentWindow?.HTMLCanvasElement?.prototype?.toDataURL;if(document.body.removeChild(e),n)return n}return HTMLCanvasElement.prototype.toDataURL}function x(t,e){const n=document.createElement("canvas"),r=n.getContext("2d"),o=t.naturalWidth,i=t.naturalHeight;n.width=o,n.height=i,r.drawImage(t,0,0,o,i);const a=e??HTMLCanvasElement.prototype.toDataURL,s=a.call(n,"image/webp");return s!=="data:,"?s:a.call(n,"image/jpeg")}async function bt(t,e){return t instanceof HTMLCanvasElement?e.call(t,"image/jpeg",1):!t.src.startsWith("blob:")||await Tt(t)?t.src:await x(t,e)}function Tt(t){return new Promise(e=>{const n=new Image;n.onload=()=>e(!0),n.onerror=()=>e(!1),n.src=t.src})}async function At(t,e){const n=e?.imgDivs,r=n?await St(t,n):await Ct(t,e),o=B();return await Promise.all(r.map(async i=>({src:await bt(i,o),el:i})))}async function St(t,e){const n=O(e,t),r=[];for(const o of n){const i=Array.from(o.querySelectorAll("img:not(nav img, header img, footer img, aside img),canvas"));for(const a of i)if(d(a,t)&&g(a)){r.push(a);break}}return r}function Ct(t,e){const n=[],r={};return t.querySelectorAll(e?.imgs?.split("|")[0]??"img:not(nav img, header img, footer img, aside img),canvas").forEach(async o=>{if(!(!d(o,t)||!g(o))){if(o instanceof HTMLImageElement){const i=r[o.src];if(i!==void 0&&i!==-1){n.splice(i,1);return}r[o.src]=n.length}n.push(o)}}),n}var Rt=Object.defineProperty,Ht=(t,e,n)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,C=(t,e,n)=>Ht(t,typeof e!="symbol"?e+"":e,n);function Lt(t,{isWeb:e}){const n=new Mt({isWeb:e});return Promise.all(t.map(r=>n.resolve(r)))}class Mt{constructor(e){C(this,"isAndroid"),C(this,"isWeb"),C(this,"canvasToDataURL"),this.isWeb=!!e?.isWeb,this.isAndroid=!this.isWeb&&navigator.userAgent.toLowerCase().includes("android"),this.canvasToDataURL=this.isWeb?B():void 0}async resolve({src:e,el:n}){let r,o;const i=e.startsWith("data:");if(this.isAndroid){const a=e.startsWith("blob:");!a&&!i&&(o=await E(e,n)),r=a?await Dt(e):e}else this.isWeb?i?r=e:(o=await E(e,n,!0),r=x(o,this.canvasToDataURL)):i?(r=await Nt(e),o=await E(r)):(r=e,o=await E(e,n));return{src:r,el:o}}}function E(t,e,n){if(e&&e instanceof HTMLImageElement&&!n)return Array.from(e.attributes).forEach(o=>{o.name!=="src"&&e.removeAttribute(o.name)}),e;const r=(o=1)=>new Promise((i,a)=>{const s=document.createElement("img");n&&(s.crossOrigin="anonymous"),s.onload=()=>i(s),s.onerror=()=>{o<2?r(o+1).then(i).catch(a):a(new Error("RESOLVE_IMG_ERR"))},s.src=t});return r()}async function Nt(t){const e=await(await fetch(t)).blob();return URL.createObjectURL(e)}async function Dt(t){const e=await fetch(t);return await It(await e.blob())}function It(t){return new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(r.result),r.onerror=n,r.readAsDataURL(t)})}async function Pt({spec:t,raw:e}){if(e.contentType===q.novel){const n=V({spec:t,raw:e});Wt({title:e.title.name,el:n})}else{const n=await _({spec:t,raw:e});Ot({title:e.title.name,images:n})}return{...e,prev:void 0,imgs:void 0,title:{...e.title,chapters:[]}}}async function _({spec:t,raw:e,isWeb:n}){const r=e.imgs?.length?e.imgs.map(o=>({src:o})):await qt(t.reader);if(!r.length)throw new Error("Empty");return await Lt(r,{isWeb:n})}function V({spec:t,raw:e}){const n=K({sel:t.reader?.content,heading:e.name,paraSel:t.reader?.para,useObfFont:!!t.reader?.obfFont});if(!n)throw new Error("Empty");const{el:r,isRTL:o,fontFamily:i}=n;return o&&r.setAttribute("dir","rtl"),i&&r.setAttribute("data-font-family",i),r.setAttribute("id","novel"),r}async function qt(t){const e=await ht(t);return await At(e,t)}function Ot({title:t,images:e}){j(t);const n=document.createElement("div");n.style.setProperty("display","none");const r=document.createElement("code");r.innerText=e.map(({src:o})=>o).join(" "),n.appendChild(r),document.body.appendChild(n),e.forEach(({el:o})=>o&&document.body.appendChild(o))}function Wt({title:t,el:e,obfFontSel:n}){const r=n?document.querySelector(n)?.cloneNode(!0):void 0,o=r?.parentElement===document.head;j(t),r&&(o?document.head:document.body).appendChild(r),document.body.appendChild(e)}function j(t){document.open(),document.close(),document.documentElement.style.setProperty("background","black"),document.title=t;const e=document.createElement("meta");e.setAttribute("name","viewport"),e.setAttribute("content","width=device-width, initial-scale=1, user-scalable=0"),document.head.appendChild(e)}h.loadImages=_,h.loadNovelHtml=V,h.strip=Pt}));
1
+ (function(C,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(C=typeof globalThis<"u"?globalThis:C||self,A(C.$mpStripper={}))})(this,(function(C){"use strict";function A(t,e){if(typeof t.checkVisibility=="function")return t.checkVisibility({opacityProperty:!0,visibilityProperty:!1,contentVisibilityAuto:!1});const n=window.getComputedStyle(t);if(n.display==="none"||n.opacity&&parseFloat(n.opacity)<.1)return!1;if(!e)return!0;const r=t.parentElement;return!r||r===e?!0:A(r,e)}function lt({sel:t,heading:e,paraSel:n,useObfFont:r}){const o=["H1","H2","H3","H4","H5","H6","P","BLOCKQUOTE","PRE","CODE"],a=["BR","HR"],c=["BUTTON","FIGURE","IMG","SCRIPT","SELECT","INPUT","FORM","IFRAME","NAV","FOOTER","ASIDE","TABLE"],u=ut(t),y=dt(u),T=r?ft(u):void 0,b=v(u);if(!b)return;return{el:b,isRTL:y,fontFamily:T};function v(l){let i=0,s=!1,d=0,p=0,w=!1;const f=E(l,o.includes(l.tagName)||!!n&&l.matches(n))?.node;if(!f)return;if(e){const g=document.createElement("h1");g.innerText=e,f.prepend(g)}return h(f),m(f),f;function E(g,M){if(w)return;if(g.nodeType===Node.TEXT_NODE)return M&&g.textContent?.trim()?{node:g.cloneNode()}:void 0;if(g.nodeType!==Node.ELEMENT_NODE)return;const S=g.tagName;if(c.includes(S)||S==="A"&&(s||!M))return;if(a.includes(S))return M?{node:document.createElement(S),isEmpty:!0}:{aborted:!0};if(g.getAttribute("aria-hidden")==="true"||!A(g)||window.getComputedStyle(g).position==="fixed")return;const at=!!n&&g.matches(n),ct=at||o.includes(S),oe=M||ct,W=[];if(Array.from(g.childNodes).forEach($=>{if(w)return;const k=E($,oe);if(k?.aborted)return;const st=k?.node;if(st){if(p=k?.isEmpty?p+1:0,p>2)return;W.push(st),s?d=0:++i>30&&(s=!0)}else s&&++d>30&&(w=!0)}),!W.length)return ct?{node:document.createElement("p"),isEmpty:!0}:void 0;const q=document.createElement(at?"p":S==="BODY"?"div":S==="a"?"span":S),F=g.getAttribute("dir");return F&&F!=="auto"&&q.setAttribute("dir",F),W.forEach($=>q.appendChild($)),{node:q}}}function m(l){U(l,i=>{if(i===l)return;const s=i.tagName;if(a.includes(s)||o.includes(s))return;const d=i.parentElement;if(d?.childNodes.length===1){Array.from(i.childNodes).forEach(p=>{d.appendChild(p)}),d.removeChild(i);return}i.childNodes.length===1&&i.replaceWith(i.childNodes[0])})}function h(l){let i=!1;const s=[];P(l,d=>o.includes(d.tagName)?[]:Array.from(d.children),d=>{const p=d.textContent.trim();if(!p)return!0;if(i)return!1;if(i=!_(d),s.includes(p))return!0;if(i)return!1;s.push(p)}),P(l,d=>o.includes(d.tagName)?[]:Array.from(d.children).reverse(),d=>!d.textContent.trim()||_(d))}}function _(t){const e=t.nodeName;return e.length===2&&e.startsWith("H")}function ut(t){const e=(t??"main,article").split(",").filter(Boolean);for(const r of e){const o=document.querySelector(r);if(o)return o}const n=document.querySelector("p:has(+ p), h1, h2");if(n){let r=n;for(;r!==document.body;)r=r.parentElement;return r}return document.body}function dt(t,e){if(t.getAttribute("dir")==="rtl")return!0;const n=t.querySelector("p")||t.querySelector("div:not(:empty)")||t;return n.getAttribute("dir")==="rtl"?!0:window.getComputedStyle(n).direction==="rtl"}function ft(t,e){const n=t.querySelector("p")||t.querySelector("div:not(:empty)")||t;return window.getComputedStyle(n).fontFamily}function U(t,e){Array.from(t.children).forEach(n=>{U(n,e)}),e(t)}function P(t,e,n){const r=e(t);let o=!1;for(let a=0;a<r.length;a++){const c=r[a],u=P(c,e,n);if(u!==void 0){if(!u)return!1;mt(c)}else o=!0}if(!o)return n(t)}function mt(t){t.parentNode?.removeChild(t)}function pt(t){if(t)try{return JSON.parse(t)}catch{return}}const wt={text:V,attr:Et,"attr-contain":At,value:Tt,row:St,"bg-image":Ct,json:Rt},ht={pattern:Lt,remove:Dt,atob:xt,json:z};function G(t,e){if(t)return gt(t,e,bt)}function gt(t,e,n){if(!t)return;const r=t.split("||").map(o=>o.trim()).filter(Boolean);for(const o of r){const a=yt(o);if(!a)continue;const c=n(document.documentElement,a);if(c)return c}}function yt(t){const[e,n,...r]=t.split("|");if(!n)return;const o=n?.startsWith("[")&&n.endsWith("]")?n.substring(1,n.length-1).split(","):[n];return{selector:e||void 0,extractors:o.map(j),transformers:r.map(j)}}function j(t){const e=t.indexOf(":"),n=e!==-1;return{fn:n?t.substring(0,e):t,param:n?t.substring(e+1):""}}function bt(t,e){if(!e.selector)return Y(t,e);const n=It(e.selector);for(const r of n){const o=Array.from(t.querySelectorAll(r));for(const a of o){const c=Y(a,e);if(c)return c}}}function Y(t,e){for(const n of e.extractors){const r=wt[n.fn],o=r(t,n.param);if(o)return vt(o,e.transformers)}}function vt(t,e){let n=t;for(const r of e){if(!n)return;const o=ht[r.fn];o&&(n=o(n,r.param)?.trim())}return n}function V(t){return Array.from(t.childNodes).filter(e=>e.nodeType===3).map(e=>R(e.textContent)).filter(Boolean).join(" ").trim()||R(t.textContent)}function Et(t,e){return R(t.getAttribute(e))}function At(t,e){let n=t.getAttribute(e);if(!n){const r=t.getAttributeNames().find(o=>o.includes(e));r&&(n=t.getAttribute(r))}return R(n)}function Tt(t){return t.value}function St(t,e){if(!e)return;const n=R(t.textContent)?.toLowerCase(),r=e.toLowerCase();if(!(n!==r&&n!==`${r}:`))return R(t.nextElementSibling?.textContent??t.nextSibling?.textContent)}function Ct(t){const e=getComputedStyle(t).backgroundImage;if(!(!e||!e.startsWith("url(")))return e.slice(5,-2)||void 0}function Rt(t,e){const n=V(t);if(n)return z(n,e)}function z(t,e){const n=J(pt(t),e),r=typeof n;if(r==="string")return R(n)||t;if(r==="number"||r==="boolean")return n+""}function J(t,e){if(!t||!e)return;const n=e.indexOf("."),r=n!==-1,o=r?e.substring(0,n):e,a=r?e.substring(n+1):void 0;try{const c=t[o];return a?J(c,a):c}catch{return}}function R(t){if(t)return t?.replace(/(\n|\t)/g," ").trim()||void 0}function Lt(t,e){if(e)try{return t.replace(new RegExp(e,"i"),"$1")}catch{}return t}function Dt(t,e){if(e)try{return t.replaceAll(new RegExp(e,"gi"),"")}catch{}return t}function xt(t){try{return window.atob(t)}catch{return t}}function It(t){const e=[];let n="",r=!1;for(let a=0;a<t.length;a++){const c=t[a];if(c==="["?r=!0:c==="]"&&(r=!1),c===","&&!r){const u=n.trim();u.length>0&&e.push(u),n=""}else n+=c}const o=n.trim();return o.length>0&&e.push(o),e}var Mt=(t=>(t[t.reading=1]="reading",t[t.paused=2]="paused",t[t.plan=3]="plan",t[t.completed=4]="completed",t[t.dropped=5]="dropped",t[t.deleted=6]="deleted",t))(Mt||{}),Pt=(t=>(t[t.ok=1]="ok",t[t.hidden=2]="hidden",t[t.deleted=3]="deleted",t))(Pt||{}),Ht=(t=>(t[t.aggregator=0]="aggregator",t[t.scanlator=1]="scanlator",t))(Ht||{}),Ot=(t=>(t.id="id",t.name="name",t.slug="slug",t))(Ot||{}),Nt=(t=>(t.blank="about:blank",t.title="meta.title",t.reader="meta.reader",t))(Nt||{}),X=(t=>(t[t.manga=1]="manga",t[t.novel=2]="novel",t[t.anime=3]="anime",t))(X||{}),Bt=(t=>(t[t.pending=0]="pending",t[t.completed=1]="completed",t[t.offline=2]="offline",t[t.incompat=3]="incompat",t))(Bt||{});function Wt(){const t=document.createElement("template");t.innerHTML="<iframe></iframe>";const e=t.content.querySelector("iframe");if(e){e?.style.setProperty("style","none"),document.body.appendChild(e);const n=e?.contentWindow?.HTMLCanvasElement?.prototype?.toDataURL;if(document.body.removeChild(e),n)return n}return HTMLCanvasElement.prototype.toDataURL}async function L(t,e,n){const r=await n(()=>{t=0});if(r!==void 0)return r;if(!(t<=0))return await new Promise(o=>{setTimeout(async()=>{const a=await L(t-1,e,n);o(a)},e)})}var qt=Object.defineProperty,Ft=(t,e,n)=>e in t?qt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,x=(t,e,n)=>Ft(t,typeof e!="symbol"?e+"":e,n);class H{constructor(e){x(this,"isAndroid"),x(this,"isWeb"),x(this,"isBlobDownloadable"),x(this,"canvasToDataURL"),this.isWeb=!!e?.isWeb,this.isAndroid=!this.isWeb&&navigator.userAgent.toLowerCase().includes("android"),this.canvasToDataURL=Wt()}async downloadImageEl(e){if(e instanceof HTMLCanvasElement){const r=await L(150,50,async()=>{const o=this.canvasToDataURL.call(e,"image/jpeg",1);return o.length<1e3?void 0:o});if(!r)throw new Error("IMG_LOAD_ERR");return await this.downloadSrc(r)}if(!e.src.startsWith("blob:")||await this.checkIsBlobImgDownloadable(e))return await this.downloadSrc(e.src);if(e.complete){if(!e.naturalWidth)throw new Error("IMG_LOAD_ERR");return await this.downloadSrc(e.src)}const n=await new Promise(r=>{let o,a=!1;const c=T=>{a||(a=!0,r(T),clearTimeout(o),e.removeEventListener("load",u),e.removeEventListener("error",y))},u=()=>c(e.src),y=()=>c();o=setTimeout(()=>r(void 0),45e3),e.addEventListener("load",u,{once:!0}),e.addEventListener("error",y,{once:!0}),e.complete&&c(e.naturalWidth?e.src:void 0)});if(!n)throw new Error("IMG_LOAD_ERR");return await this.downloadSrc(n)}async downloadSrc(e){let n;const r=e.startsWith("data:");if(this.isAndroid){const o=e.startsWith("blob:");!o&&!r&&(n=await I(e)),e=o?await kt(e):e}else if(this.isWeb){if(!r){const o=await I(e,!0);e=Ut(o,this.canvasToDataURL)}}else r?(e=await $t(e),n=await I(e)):n=await I(e);return{src:e,el:n}}async checkIsBlobImgDownloadable(e){return this.isBlobDownloadable??(this.isBlobDownloadable=await new Promise(n=>{const r=new Image;r.onload=()=>n(!0),r.onerror=()=>n(!1),r.src=e.src})),this.isBlobDownloadable}}function I(t,e){const n=(r=1)=>new Promise((o,a)=>{const c=document.createElement("img");e&&(c.crossOrigin="anonymous"),c.onload=()=>o(c),c.onerror=()=>{r<2?n(r+1).then(o).catch(a):a(new Error("IMG_LOAD_ERR"))},c.src=t});return n()}async function $t(t){const e=await(await fetch(t)).blob();return URL.createObjectURL(e)}async function kt(t){const e=await fetch(t);return await _t(await e.blob())}function _t(t){return new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(r.result),r.onerror=n,r.readAsDataURL(t)})}function Ut(t,e){const n=document.createElement("canvas"),r=n.getContext("2d"),o=t.naturalWidth,a=t.naturalHeight;n.width=o,n.height=a,r.drawImage(t,0,0,o,a);const c=e??HTMLCanvasElement.prototype.toDataURL,u=c.call(n,"image/webp");return u!=="data:,"?u:c.call(n,"image/jpeg")}function D(t=0){return new Promise(e=>setTimeout(e,t))}async function Gt(t,e,n=0){const r=e.root??document.documentElement,o=e.timeoutMs;return L(o/50,50,()=>{const a=e.all===!0?Array.from(r.querySelectorAll(t)):r.querySelector(t)??void 0;return(e.all?!a?.length:!a)?void 0:a})}function jt(t,e){return t>=280&&e>=50||t>=160&&e>=280}function O(t){const e=t.getBoundingClientRect();return jt(e.width,e.height)}async function Q(t,e){const n=await Yt(t,e);return K(n?.parentElement??t)}async function Yt(t,e){if(e?.imgDivs)return await Gt(e.imgDivs,{timeoutMs:15e3});const n=Array.from(t.querySelectorAll(e?.imgs?.split("|")[0]??"img:not(nav img, header img, footer img, aside img),canvas"));if(n.length)return n.find(r=>A(r,t)&&(O(r)||r instanceof HTMLImageElement&&(!r.width||!r.height)))}function K(t){return t===document.documentElement||t.scrollHeight-t.clientHeight>=10&&window.getComputedStyle(t).overflow!=="visible"?t:K(t.parentElement)}function Z(t,e){if(t instanceof HTMLOptionElement){const n=t.parentElement instanceof HTMLOptGroupElement?t.parentElement.parentElement:t.parentElement;if(!n||!(n instanceof HTMLSelectElement))return;const r=t.getAttribute("value")||"";if(n.value===r)return;n.value=r,n.dispatchEvent(new Event("change"));return}t instanceof HTMLAnchorElement&&e?.preventDefault!==!1&&t.addEventListener("click",n=>n.preventDefault(),{once:!0}),t.click(),t.dispatchEvent(new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,pointerType:"mouse",button:0})),t.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window,button:0}))}function N(t,e){const n=e??document;if(t.startsWith("//")){const r=document.evaluate(t,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return r instanceof HTMLElement?r:void 0}return n.querySelector(t)??void 0}async function tt(t){const e=await Vt(t),n=t?.content;return n?await L(e?30:10,100,()=>{for(const r of n.split(",")){const o=document.querySelector(r);if(o)return o}})??document.body:document.body}async function Vt(t){const{lstrip:e,lstripBtn:n}=t||{};if(!e||!n||N(e))return!1;const r=n.split(";");for(const o of r)if(!await zt(o.trim()))return!1;return!0}async function zt(t){const e=await L(50,30,()=>N(t));return e?(Z(e),await D(),!0):!1}const et="img:not(nav img, header img, footer img, aside img),canvas:not(nav canvas, header canvas, footer canvas, aside canvas)";async function Jt(t,e){let n=await tt(t),r=await Q(n,t);await m(2500),await m(2500),await m(5e3),await h();const{clientHeight:o}=r,a=new H(e),c=new Map,u=t?.imgDivs;if(u){let l=await L(50,50,()=>n.querySelector(u)??void 0);if(l){let i=0;for(;l;){const s=l,d=await b(s,30);if(!d)throw new Error("IMG_LOAD_ERR");c.set(s,d.downloaded),await h();const p=Array.from(n.querySelectorAll(u)),w=p.indexOf(l);i=w===-1?i+1:w+1,l=p[i]}return Array.from(c.values())}}return await y(),Array.from(c.values());async function y(l){try{l??(l=await T(Array.from(c.keys()).slice(-1)[0]))}catch(s){if(c.size>0)return;throw s}const i=await B({downloader:a,getPoint:async()=>{await v(l);const s=l.getBoundingClientRect().bottom+30;return{x:r.clientWidth/2,fromY:s,to:s+70}},isExclude:s=>s===l,maxFailedAttempts:3});i&&c.set(i.el,i.downloaded),await y(i?.el)}async function T(l){const i=await L(50,50,async()=>{await h();const d=Array.from(n.querySelectorAll(et));let p=!l;for(const w of d){if(!p){p=w===l;continue}if(A(w)&&O(w))return w}}),s=i?await b(i,5):void 0;if(!s)throw new Error("EMPTY");return c.set(s.el,s.downloaded),s.el}function b(l,i){return B({downloader:a,getPoint:async()=>{await v(l);const s=l.getBoundingClientRect();return{x:r.clientWidth/2,fromY:(Math.min(s.bottom,r.clientHeight)-Math.max(0,s.top))/2}},maxFailedAttempts:i})}async function v(l){const i=200-(o-l.getBoundingClientRect().bottom);i!=0&&(r.scrollTop+=i),await D(10)}async function m(l){await h(),await Qt(r,{stepMs:50,maxDurationMs:l}),r.scrollTop=0,await D(50)}async function h(){!n.isConnected&&(n=await tt(),Xt(n)),r.isConnected||(r=await Q(n),r.style.setProperty("scroll-behavior","auto"))}}function B({downloader:t,getPoint:e,isExclude:n,maxFailedAttempts:r}){return new Promise((o,a)=>{const c=new Map;let u=!1,y=0,T=0,b=0;const v=(i,s)=>{u||(u=!0,s?a(s):o(i))},m=(i,s)=>{u||!c.has(i)||(c.set(i,!0),s&&v({el:i,downloaded:s}))},h=i=>{c.has(i)&&c.set(i,!1)},l=async()=>{let i=[];const s=await e(),d=s.toY??s.fromY;for(let f=s.fromY;f<=d&&(i=Array.from(document.elementsFromPoint(s.x,f)).filter(E=>(E instanceof HTMLImageElement||E instanceof HTMLCanvasElement)&&!n?.(E)&&E.matches(et)&&A(E)&&O(E)),!i.length);f+=20);c.keys().filter(f=>!i.includes(f)).forEach(f=>{c.delete(f)});const p=i.filter(f=>!c.has(f));p.length&&(y=0,b=0),p.forEach(f=>{c.set(f,void 0),t.downloadImageEl(f).then(E=>m(f,E)).catch(()=>h(f))});const w=Array.from(c.values());if(!w.length&&++y>r||w.every(f=>f===!0)&&++T>r)return v(void 0);if(w.every(f=>f===!1)&&++b>r)return v(void 0,new Error("IMG_LOAD_ERR"));await D(1e3),!u&&l()};l()})}function Xt(t){const e=Array.from(t.querySelectorAll('img[loading="lazy"]'));for(const n of e)n.setAttribute("loading","eager");nt(t,"data-src"),nt(t,"data-url")}function nt(t,e){const n=Array.from(t.querySelectorAll(`img[${e}]`));for(const r of n){const o=r.getAttribute(e)?.split(" ")[0];o&&r.src!==o&&(r.src=o)}}async function Qt(t,{stepMs:e,maxDurationMs:n}){t.style.setProperty("scroll-behavior","auto");let r=n;for(;r>0&&t.scrollTop+t.clientHeight+200<t.scrollHeight;){const o=t.scrollHeight-t.scrollTop-t.clientHeight;t.scrollTop+=o/(r/e),r-=e,await D(e)}}async function Kt(t,e,n){const r=new H(n);let o=b(),a=0;return await u(1),await u(2),await u(0),await c();async function c(m=[],h=0){if(await u(h),h!==a)return m;v(),o.scrollIntoView({block:"center",behavior:"instant"}),await D(50);const l=await B({downloader:r,maxFailedAttempts:30,getPoint:async()=>{const i=o.getBoundingClientRect(),{innerWidth:s,innerHeight:d}=window;return{x:s/2,fromY:(Math.min(d,i.bottom)-Math.max(0,i.top))/2}}});if(!l)throw new Error("IMG_LOAD_ERR");return await c([...m,l.downloaded],a+1)}async function u(m){if(m===a)return;const h=T(m);if(h&&(await y(h,m),a===m))return;const{prevBtn:l,nextBtn:i}=t;if(!l||!i)return;const s=m-a>0,d=s?i:l,p=document.querySelector(d);if(!p)return;const w=a+(s?1:-1);await y(p,w),a===w&&await u(m)}async function y(m,h){for(let l=0;l<20;l++){Z(m);for(let i=0;i<6;i++){await D(50);const s=Zt(t.current);if(s&&(a=s-1,a===h))return}}}function T(m,h){const{pageBtn:l}=t;if(l)return N(l.replaceAll("{page}",`${m+1}`),document.body)}function b(){return e?document.querySelector(e)??document.body:document.body}function v(){o=o.isConnected?o:b()}}function Zt(t,e){return te(G(t,e))}function te(t){if(t)return parseInt(t.replace(/\D*/,""))||void 0}async function ee({spec:t,raw:e}){if(e.contentType===X.novel){const n=ot({spec:t,raw:e});re({title:e.title.name,el:n})}else{const n=await rt({spec:t,raw:e});ne({title:e.title.name,images:n})}return{...e,prev:void 0,imgs:void 0,title:{...e.title,chapters:[]}}}function rt({spec:t,raw:e,isWeb:n}){if(e.imgs?.length){const o=new H({isWeb:n});return Promise.all(e.imgs.map(a=>o.downloadSrc(a)))}const r=t?.reader?.paging;return r&&G(r.total)?Kt(r,t.reader?.content,{isWeb:n}):Jt(t.reader,{isWeb:n})}function ot({spec:t,raw:e}){const n=lt({sel:t.reader?.content,heading:e.name,paraSel:t.reader?.para,useObfFont:!!t.reader?.obfFont});if(!n)throw new Error("Empty");const{el:r,isRTL:o,fontFamily:a}=n;return o&&r.setAttribute("dir","rtl"),a&&r.setAttribute("data-font-family",a),r.setAttribute("id","novel"),r}function ne({title:t,images:e}){it(t);const n=document.createElement("div");n.style.setProperty("display","none");const r=document.createElement("code");r.innerText=e.map(({src:o})=>o).join(" "),n.appendChild(r),document.body.appendChild(n),e.forEach(({el:o})=>o&&document.body.appendChild(o))}function re({title:t,el:e,obfFontSel:n}){const r=n?document.querySelector(n)?.cloneNode(!0):void 0,o=r?.parentElement===document.head;it(t),r&&(o?document.head:document.body).appendChild(r),document.body.appendChild(e)}function it(t){document.open(),document.close(),document.documentElement.style.setProperty("background","black"),document.title=t;const e=document.createElement("meta");e.setAttribute("name","viewport"),e.setAttribute("content","width=device-width, initial-scale=1, user-scalable=0"),document.head.appendChild(e)}C.loadImages=rt,C.loadNovelHtml=ot,C.strip=ee}));