single-file-cli 1.1.29 → 1.1.31
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefileBootstrap={})}(this,(function(e){"use strict";const t="single-file-load-deferred-images-start",s="single-file-load-deferred-images-end",o="single-file-load-deferred-images-keep-zoom-level-start",n="single-file-load-deferred-images-keep-zoom-level-end",a="single-file-block-cookies-start",i="single-file-block-cookies-end",r="single-file-dispatch-scroll-event-start",l="single-file-dispatch-scroll-event-end",d="single-file-block-storage-start",c="single-file-block-storage-end",m="single-file-load-image",u="single-file-image-loaded",g="_singleFile_fontFaces",p=(e,t,s)=>globalThis.addEventListener(e,t,s),h=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},f=globalThis.CustomEvent,T=globalThis.document,E=globalThis.Document,b=globalThis.JSON;let y;y=window[g]?window[g]:window[g]=new Map,T instanceof E&&(p("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.set(b.stringify(s),t)})),p("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.delete(b.stringify(s))})),p("single-file-clear-fonts",(()=>y=new Map)));const I="[\\x20\\t\\r\\n\\f]",w=new RegExp("\\\\([\\da-f]{1,6}"+I+"?|("+I+")|.)","ig");const A="single-file-",S="_singleFile_waitForUserScript",v="__frameTree__::",R=A+"on-before-capture",N=A+"on-after-capture",P=A+"request-get-adopted-stylesheets",_=A+"response-get-adopted-stylesheets",M=A+"unregister-request-get-adopted-stylesheets",C=A+"user-script-init",O="data-"+A+"removed-content",L="data-"+A+"hidden-content",D="data-"+A+"kept-content",x="data-"+A+"hidden-frame",F="data-"+A+"preserved-space-element",U="data-"+A+"shadow-root-element",q="data-"+A+"win-id",k="data-"+A+"image",H="data-"+A+"poster",V="data-"+A+"video",B="data-"+A+"canvas",W="data-"+A+"movable-style",z="data-"+A+"input-value",Y="data-"+A+"lazy-loaded-src",j="data-"+A+"stylesheet",G="data-"+A+"disabled-noscript",K="data-"+A+"invalid-element",X="data-"+A+"async-script",Z="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",J=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],$=/^'(.*?)'$/,Q=/^"(.*?)"$/,ee={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},te="single-file-ui-element",se="data:,",oe=(e,t,s)=>globalThis.addEventListener(e,t,s),ne=globalThis.JSON,ae=globalThis.CustomEvent;function ie(e,t,s){e.querySelectorAll("noscript:not(["+G+"])").forEach((e=>{e.setAttribute(G,e.textContent),e.textContent=""})),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach((e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")}))}(e),e.head&&e.head.querySelectorAll(Z).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+Z+", html > body > "+Z);t.length&&(Array.from(e.childNodes).forEach((e=>e.remove())),t.forEach((t=>e.appendChild(t))))}));const o=new Map;let n;return t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach((t=>{const s=e.createElement("template");s.setAttribute(K,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=re(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=fe(t,e);s&&ue(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(y.values()),stylesheets:pe(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:e.referrer,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:le(e.adoptedStyleSheets)}}function re(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},a){if(s.childNodes){Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement)).forEach((s=>{let i,r,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=fe(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(r=(a||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),r||(i=a||ue(s,l),i&&(s.setAttribute(L,""),n.markedElements.push(s)))),!i)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(F,""),n.markedElements.push(s))}o.removeUnusedFonts&&(de(l,o,n.usedFonts),de(fe(e,s,":first-letter"),o,n.usedFonts),de(fe(e,s,":before"),o,n.usedFonts),de(fe(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,a,i){const r=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==r)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:i.getPropertyValue("background-color")}),s.setAttribute(B,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==r){const t={currentSrc:a?se:o.loadDeferredImages&&s.getAttribute(Y)||s.currentSrc};if(n.images.push(t),s.setAttribute(k,n.images.length-1),n.markedElements.push(s),s.removeAttribute(Y),i=i||fe(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const a=null==t.getAttribute("style");if(s=s||fe(e,t)){let e,i,r,l,d,c,m,u,g=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),g=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=he("padding-left",s),i=he("padding-right",s),r=he("padding-top",s),l=he("padding-bottom",s),g?(d=he("border-left-width",s),c=he("border-right-width",s),m=he("border-top-width",s),u=he("border-bottom-width",s)):d=c=m=u=0,o=Math.max(0,t.clientWidth-e-i-d-c),n=Math.max(0,t.clientHeight-r-l-m-u),a&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,i);const o=i.getPropertyValue("box-shadow"),n=i.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=i.getPropertyValue("background-color"),t.objectFit=i.getPropertyValue("object-fit"),t.boxSizing=i.getPropertyValue("box-sizing"),t.objectPosition=i.getPropertyValue("object-position"))}}if("VIDEO"==r){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=fe(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(V,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(H,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==r&&a&&o.removeHiddenElements&&(s.setAttribute(x,""),n.markedElements.push(s));"INPUT"==r&&("password"!=s.type&&(s.setAttribute(z,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(z,s.checked),n.markedElements.push(s)));"TEXTAREA"==r&&(s.setAttribute(z,s.value),n.markedElements.push(s));"SELECT"==r&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(z,""),n.markedElements.push(e))}));"SCRIPT"==r&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(X,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,i,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&ce(s);if(d&&!s.classList.contains(te)){const a={};s.setAttribute(U,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(a);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)a.adoptedStyleSheets=le(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>a.adoptedStyleSheets=e.detail.adoptedStyleSheets;s.addEventListener(_,e),s.dispatchEvent(new ae(P,{bubbles:!0})),s.removeEventListener(_,e)}}catch(e){}re(e,t,d,o,n,i),a.content=d.innerHTML,a.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&s.dispatchEvent(new ae(M,{bubbles:!0}))}catch(e){}}re(e,t,s,o,n,i),!o.autoSaveExternalSave&&o.removeHiddenElements&&a&&(r||""==s.getAttribute(D)?s.parentElement&&(s.parentElement.setAttribute(D,""),n.markedElements.push(s.parentElement)):i&&(s.setAttribute(O,""),n.markedElements.push(s)))}))}return n}function le(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function de(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=me(n),!t.loadedFonts||t.loadedFonts.find((e=>me(e.family)==n&&e.style==o))){const t=(a=e.getPropertyValue("font-weight"),ee[a.toLowerCase().trim()]||a),i=e.getPropertyValue("font-variant")||"normal",r=[n,t,o,i];s.set(ne.stringify(r),[n,t,o,i])}var a}))}}function ce(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function me(e=""){return function(e){e=e.match($)?e.replace($,"$1"):e.replace(Q,"$1");return e.trim()}((t=e.trim(),t.replace(w,((e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)})))).toLowerCase();var t}function ue(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),a=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==a)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function ge(e,t,s){if(e.querySelectorAll("["+G+"]").forEach((e=>{e.textContent=e.getAttribute(G),e.removeAttribute(G)})),e.querySelectorAll("meta[disabled-http-equiv]").forEach((e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")})),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach((e=>e.removeAttribute("hidden"))),!t){const s=[O,x,L,F,k,H,V,B,z,U,j,X];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(O),e.removeAttribute(L),e.removeAttribute(D),e.removeAttribute(x),e.removeAttribute(F),e.removeAttribute(k),e.removeAttribute(H),e.removeAttribute(V),e.removeAttribute(B),e.removeAttribute(z),e.removeAttribute(U),e.removeAttribute(j),e.removeAttribute(X),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))}function pe(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const a=n.sheet;n.remove();const i=Array.from(a.cssRules).map((e=>e.cssText)).join("\n"),r=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");a&&i==r||(s.setAttribute(j,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function he(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function fe(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const Te={LAZY_SRC_ATTRIBUTE_NAME:Y,SINGLE_FILE_UI_ELEMENT_CLASS:te},Ee=10,be="attributes",ye=globalThis.browser,Ie=globalThis.document,we=globalThis.MutationObserver,Ae=(e,t,s)=>globalThis.addEventListener(e,t,s),Se=(e,t,s)=>globalThis.removeEventListener(e,t,s),ve=new Map;let Re;async function Ne(e){if(Ie.documentElement){ve.clear();const s=Ie.body?Math.max(Ie.body.scrollHeight,Ie.documentElement.scrollHeight):Ie.documentElement.scrollHeight,n=Ie.body?Math.max(Ie.body.scrollWidth,Ie.documentElement.scrollWidth):Ie.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const i=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY<i||globalThis.scrollX<l)return function(e){return Re=0,new Promise((async s=>{let n;const i=new Set,l=new we((async t=>{if((t=t.filter((e=>e.type==be))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(Te.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",g)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(Te.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await _e(l,e,E),i.size||await Pe(l,e,E))}}));async function c(t){await Ce("idleTimeout",(async()=>{n?Re<Ee&&(Re++,Le("idleTimeout"),await c(Math.max(500,t/2))):(Le("loadTimeout"),Le("maxTimeout"),Me(l,e,E))}),t,e.loadDeferredImagesNativeTimeout)}function g(e){const t=e.target;t.removeAttribute(Te.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",g)}async function p(t){n=!0,await _e(l,e,E),await Pe(l,e,E),t.detail&&i.add(t.detail)}async function T(t){await _e(l,e,E),await Pe(l,e,E),i.delete(t.detail),i.size||await Pe(l,e,E)}function E(e){l.disconnect(),Se(m,p),Se(u,T),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await _e(l,e,E),l.observe(Ie,{subtree:!0,childList:!0,attributes:!0}),Ae(m,p),Ae(u,T),function(e){e.loadDeferredImagesBlockCookies&&h(new f(a)),e.loadDeferredImagesBlockStorage&&h(new f(d)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(r)),e.loadDeferredImagesKeepZoomLevel?h(new f(o)):h(new f(t))}(e)}))}(e)}}}async function Pe(e,t,s){await Ce("loadTimeout",(()=>Me(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function _e(e,t,s){await Ce("maxTimeout",(async()=>{await Le("loadTimeout"),await Me(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Me(e,t,o){await Le("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&h(new f(i)),e.loadDeferredImagesBlockStorage&&h(new f(c)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(l)),e.loadDeferredImagesKeepZoomLevel?h(new f(n)):h(new f(s))}(t),await Ce("endTimeout",(async()=>{await Le("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Ce(e,t,s,o){if(ye&&ye.runtime&&ye.runtime.sendMessage&&!o){if(!ve.get(e)||!ve.get(e).pending){const o={callback:t,pending:!0};ve.set(e,o);try{await ye.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Oe(e,t,s)}o.pending=!1}}else Oe(e,t,s)}function Oe(e,t,s){const o=ve.get(e);o&&globalThis.clearTimeout(o),ve.set(e,t),globalThis.setTimeout(t,s)}async function Le(e){if(ye&&ye.runtime&&ye.runtime.sendMessage)try{await ye.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){De(e)}else De(e)}function De(e){const t=ve.get(e);ve.delete(e),t&&globalThis.clearTimeout(t)}ye&&ye.runtime&&ye.runtime.onMessage&&ye.runtime.onMessage.addListener&&ye.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=ve.get(e.type);if(t){ve.delete(e.type);try{t.callback()}catch(t){De(e.type)}}}}));const xe={ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,WIN_ID_ATTRIBUTE_NAME:q,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:S,preProcessDoc:ie,serialize:function(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML},postProcessDoc:ge,getShadowRoot:ce},Fe='iframe, frame, object[type="text/html"][data]',Ue="*",qe="singlefile.frameTree.initRequest",ke="singlefile.frameTree.ackInitRequest",He="singlefile.frameTree.cleanupRequest",Ve="singlefile.frameTree.initResponse",Be="*",We=5e3,ze=".",Ye=globalThis.window==globalThis.top,je=globalThis.browser,Ge=globalThis.top,Ke=globalThis.MessageChannel,Xe=globalThis.document,Ze=globalThis.JSON;let Je,$e=globalThis.sessions;var Qe,et,tt;function st(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function ot(e){const t=e.sessionId,s=globalThis[xe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ye||(Je=globalThis.frameId=e.windowId),it(Xe,e.options,Je,t),Ye||(e.options.userScriptEnabled&&s&&await s(xe.ON_BEFORE_CAPTURE_EVENT_NAME),ct({frames:[ut(Xe,globalThis,Je,e.options,e.scrolling)],sessionId:t,requestedFrameId:Xe.documentElement.dataset.requestedFrameId&&Je}),e.options.userScriptEnabled&&s&&await s(xe.ON_AFTER_CAPTURE_EVENT_NAME),delete Xe.documentElement.dataset.requestedFrameId)}function nt(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;dt(gt(Xe),e.windowId,t)}}function at(e){e.frames.forEach((t=>rt("responseTimeouts",e.sessionId,t.windowId)));const t=$e.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach((e=>{let s=t.frames.find((t=>e.windowId==t.windowId));s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(ze).length-e.windowId.split(ze).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function it(e,t,s,o){const n=gt(e);!function(e,t,s,o,n){const a=[];let i;$e.get(n)?i=$e.get(n).requestTimeouts:(i={},$e.set(n,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=o+ze+t;e.setAttribute(xe.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),ct({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const a=o+ze+t;try{mt(e.contentWindow,{method:qe,windowId:a,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}i[a]=globalThis.setTimeout((()=>ct({frames:[{windowId:a,processed:!0}],sessionId:n})),We)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const a=[];t.forEach(((e,t)=>{const i=o+ze+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),rt("requestTimeouts",n,i),it(r,s,i,n),a.push(ut(r,t,i,s,e.scrolling))}catch(e){a.push({windowId:i,processed:!0})}})),ct({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function rt(e,t,s){const o=$e.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function lt(e,t){const s=$e.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>ct({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function dt(e,t,s){e.forEach(((e,o)=>{const n=t+ze+o;e.removeAttribute(xe.WIN_ID_ATTRIBUTE_NAME);try{mt(e.contentWindow,{method:He,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+ze+o;let a;try{a=e.contentDocument}catch(e){}if(a)try{dt(gt(a),n,s)}catch(e){}}))}function ct(e){e.method=Ve;try{Ge.singlefile.processors.frameTree.initResponse(e)}catch(t){mt(Ge,e,!0)}}function mt(e,t,s){if(e==Ge&&je&&je.runtime&&je.runtime.sendMessage)je.runtime.sendMessage(t);else if(s){const s=new Ke;e.postMessage(v+Ze.stringify({method:t.method,sessionId:t.sessionId}),Be,[s.port2]),s.port1.postMessage(t)}else e.postMessage(v+Ze.stringify(t),Be)}function ut(e,t,s,o,n){const a=xe.preProcessDoc(e,t,o),i=xe.serialize(e);xe.postProcessDoc(e,a.markedElements,a.invalidElements);return{windowId:s,content:i,baseURI:e.baseURI.split("#")[0],url:e.location.href,title:e.title,canvases:a.canvases,fonts:a.fonts,stylesheets:a.stylesheets,images:a.images,posters:a.posters,videos:a.videos,usedFonts:a.usedFonts,shadowRoots:a.shadowRoots,scrollPosition:a.scrollPosition,scrolling:n,adoptedStyleSheets:a.adoptedStyleSheets,processed:!0}}function gt(e){let t=Array.from(e.querySelectorAll(Fe));return e.querySelectorAll(Ue).forEach((e=>{const s=xe.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Fe)))})),t}$e||($e=globalThis.sessions=new Map),Ye&&(Je="0",je&&je.runtime&&je.runtime.onMessage&&je.runtime.onMessage.addListener&&je.runtime.onMessage.addListener((e=>e.method==Ve?(at(e),Promise.resolve({})):e.method==ke?(rt("requestTimeouts",e.sessionId,e.windowId),lt(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Qe="message",et=async e=>{if("string"==typeof e.data&&e.data.startsWith(v)){e.preventDefault(),e.stopPropagation();const t=Ze.parse(e.data.substring(v.length));t.method==qe?(e.source&&mt(e.source,{method:ke,windowId:t.windowId,sessionId:t.sessionId}),Ye||(globalThis.stop(),t.options.loadDeferredImages&&Ne(t.options),await ot(t))):t.method==ke?(rt("requestTimeouts",t.sessionId,t.windowId),lt(t.sessionId,t.windowId)):t.method==He?nt(t):t.method==Ve&&$e.get(t.sessionId)&&(e.ports[0].onmessage=e=>at(e.data))}},tt=!0,globalThis.addEventListener(Qe,et,tt);var pt=Object.freeze({__proto__:null,getAsync:function(e){const t=st();return e=Ze.parse(Ze.stringify(e)),new Promise((s=>{$e.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),ot({windowId:Je,sessionId:t,options:e})}))},getSync:function(e){const t=st();e=Ze.parse(Ze.stringify(e)),$e.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[xe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ye||(Je=globalThis.frameId=e.windowId);it(Xe,e.options,Je,t),Ye||(e.options.userScriptEnabled&&s&&s(xe.ON_BEFORE_CAPTURE_EVENT_NAME),ct({frames:[ut(Xe,globalThis,Je,e.options,e.scrolling)],sessionId:t,requestedFrameId:Xe.documentElement.dataset.requestedFrameId&&Je}),e.options.userScriptEnabled&&s&&s(xe.ON_AFTER_CAPTURE_EVENT_NAME),delete Xe.documentElement.dataset.requestedFrameId)}({windowId:Je,sessionId:t,options:e});const s=$e.get(t).frames;return s.sessionId=t,s},cleanup:function(e){$e.delete(e),nt({windowId:Je,sessionId:e,options:{sessionId:e}})},initResponse:at,TIMEOUT_INIT_REQUEST_MESSAGE:We});const ht=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"],ft=1,Tt=3,Et=8,bt=[{tagName:"HEAD",accept:e=>!e.childNodes.length||e.childNodes[0].nodeType==ft},{tagName:"BODY",accept:e=>!e.childNodes.length}],yt=[{tagName:"HTML",accept:e=>!e||e.nodeType!=Et},{tagName:"HEAD",accept:e=>!e||e.nodeType!=Et&&(e.nodeType!=Tt||!At(e.textContent))},{tagName:"BODY",accept:e=>!e||e.nodeType!=Et},{tagName:"LI",accept:(e,t)=>!e&&t.parentElement&&("UL"==St(t.parentElement)||"OL"==St(t.parentElement))||e&&["LI"].includes(St(e))},{tagName:"DT",accept:e=>!e||["DT","DD"].includes(St(e))},{tagName:"P",accept:e=>e&&["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"].includes(St(e))},{tagName:"DD",accept:e=>!e||["DT","DD"].includes(St(e))},{tagName:"RT",accept:e=>!e||["RT","RP"].includes(St(e))},{tagName:"RP",accept:e=>!e||["RT","RP"].includes(St(e))},{tagName:"OPTGROUP",accept:e=>!e||["OPTGROUP"].includes(St(e))},{tagName:"OPTION",accept:e=>!e||["OPTION","OPTGROUP"].includes(St(e))},{tagName:"COLGROUP",accept:e=>!e||e.nodeType!=Et&&(e.nodeType!=Tt||!At(e.textContent))},{tagName:"CAPTION",accept:e=>!e||e.nodeType!=Et&&(e.nodeType!=Tt||!At(e.textContent))},{tagName:"THEAD",accept:e=>!e||["TBODY","TFOOT"].includes(St(e))},{tagName:"TBODY",accept:e=>!e||["TBODY","TFOOT"].includes(St(e))},{tagName:"TFOOT",accept:e=>!e},{tagName:"TR",accept:e=>!e||["TR"].includes(St(e))},{tagName:"TD",accept:e=>!e||["TD","TH"].includes(St(e))},{tagName:"TH",accept:e=>!e||["TD","TH"].includes(St(e))}],It=["STYLE","SCRIPT","XMP","IFRAME","NOEMBED","NOFRAMES","PLAINTEXT","NOSCRIPT"];function wt(e,t,s){return e.nodeType==Tt?function(e){const t=e.parentNode;let s;t&&t.nodeType==ft&&(s=St(t));return!s||It.includes(s)?"SCRIPT"==s||"STYLE"==s?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&").replace(/\u00a0/g," ").replace(/</g,"<").replace(/>/g,">")}(e):e.nodeType==Et?"\x3c!--"+e.textContent+"--\x3e":e.nodeType==ft?function(e,t,s){const o=St(e),n=t&&bt.find((t=>o==St(t)&&t.accept(e)));let a="";n&&!e.attributes.length||(a="<"+o.toLowerCase(),Array.from(e.attributes).forEach((s=>a+=function(e,t,s){const o=e.name;let n="";if(!o.match(/["'>/=]/)){let a,i=e.value;s&&"class"==o&&(i=Array.from(t.classList).map((e=>e.trim())).join(" ")),i=i.replace(/&/g,"&").replace(/\u00a0/g," "),i.includes('"')&&(i.includes("'")||!s?i=i.replace(/"/g,"""):a=!0);const r=!s||i.match(/[ \t\n\f\r'"`=<>]/);n+=" ",e.namespace?"http://www.w3.org/XML/1998/namespace"==e.namespaceURI?n+="xml:"+o:"http://www.w3.org/2000/xmlns/"==e.namespaceURI?("xmlns"!==o&&(n+="xmlns:"),n+=o):"http://www.w3.org/1999/xlink"==e.namespaceURI?n+="xlink:"+o:n+=o:n+=o,""!=i&&(n+="=",r&&(n+=a?"'":'"'),n+=i,r&&(n+=a?"'":'"'))}return n}(s,e,t))),a+=">");"TEMPLATE"!=o||e.childNodes.length?Array.from(e.childNodes).forEach((e=>a+=wt(e,t,s||"svg"==o))):a+=e.innerHTML;const i=t&&yt.find((t=>o==St(t)&&t.accept(e.nextSibling,e)));(s||!i&&!ht.includes(o))&&(a+="</"+o.toLowerCase()+">");return a}(e,t,s):void 0}function At(e){return Boolean(e.match(/^[ \t\n\f\r]/))}function St(e){return e.tagName&&e.tagName.toUpperCase()}const vt={frameTree:pt},Rt={COMMENT_HEADER:"Page saved with SingleFile",COMMENT_HEADER_LEGACY:"Archive processed by SingleFile",ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,preProcessDoc:ie,postProcessDoc:ge,serialize:(e,t)=>function(e,t){const s=e.doctype;let o="";return s&&(o="<!DOCTYPE "+s.nodeName,s.publicId?(o+=' PUBLIC "'+s.publicId+'"',s.systemId&&(o+=' "'+s.systemId+'"')):s.systemId&&(o+=' SYSTEM "'+s.systemId+'"'),s.internalSubset&&(o+=" ["+s.internalSubset+"]"),o+="> "),o+wt(e.documentElement,t)}(e,t),getShadowRoot:ce};oe(C,(()=>globalThis[S]=async e=>{const t=new ae(e+"-request",{cancelable:!0}),s=new Promise((t=>oe(e+"-response",t)));(e=>{try{globalThis.dispatchEvent(e)}catch(e){}})(t),t.defaultPrevented&&await s})),e.helper=Rt,e.processors=vt,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefileBootstrap={})}(this,(function(e){"use strict";const t="single-file-load-deferred-images-start",s="single-file-load-deferred-images-end",o="single-file-load-deferred-images-keep-zoom-level-start",n="single-file-load-deferred-images-keep-zoom-level-end",a="single-file-block-cookies-start",i="single-file-block-cookies-end",r="single-file-dispatch-scroll-event-start",l="single-file-dispatch-scroll-event-end",d="single-file-block-storage-start",c="single-file-block-storage-end",m="single-file-load-image",u="single-file-image-loaded",g="_singleFile_fontFaces",p=(e,t,s)=>globalThis.addEventListener(e,t,s),h=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},f=globalThis.CustomEvent,T=globalThis.document,E=globalThis.Document,b=globalThis.JSON;let y;y=window[g]?window[g]:window[g]=new Map,T instanceof E&&(p("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.set(b.stringify(s),t)})),p("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.delete(b.stringify(s))})),p("single-file-clear-fonts",(()=>y=new Map)));const I="[\\x20\\t\\r\\n\\f]",w=new RegExp("\\\\([\\da-f]{1,6}"+I+"?|("+I+")|.)","ig");const A="single-file-",S="_singleFile_waitForUserScript",v="__frameTree__::",R=A+"on-before-capture",N=A+"on-after-capture",P=A+"request-get-adopted-stylesheets",_=A+"response-get-adopted-stylesheets",C=A+"unregister-request-get-adopted-stylesheets",M=A+"user-script-init",O="data-"+A+"removed-content",L="data-"+A+"hidden-content",D="data-"+A+"kept-content",x="data-"+A+"hidden-frame",F="data-"+A+"preserved-space-element",U="data-"+A+"shadow-root-element",q="data-"+A+"win-id",k="data-"+A+"image",H="data-"+A+"poster",V="data-"+A+"video",B="data-"+A+"canvas",W="data-"+A+"movable-style",z="data-"+A+"input-value",Y="data-"+A+"lazy-loaded-src",j="data-"+A+"stylesheet",G="data-"+A+"disabled-noscript",K="data-"+A+"invalid-element",X="data-"+A+"async-script",Z="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",J=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],$=/^'(.*?)'$/,Q=/^"(.*?)"$/,ee={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},te="single-file-ui-element",se="single-file-infobar",oe="data:,",ne=(e,t,s)=>globalThis.addEventListener(e,t,s),ae=globalThis.JSON,ie=globalThis.CustomEvent;function re(e,t,s){e.querySelectorAll("noscript:not(["+G+"])").forEach((e=>{e.setAttribute(G,e.textContent),e.textContent=""})),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach((e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")}))}(e),e.head&&e.head.querySelectorAll(Z).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+Z+", html > body > "+Z);t.length&&(Array.from(e.childNodes).forEach((e=>e.remove())),t.forEach((t=>e.appendChild(t))))}));const o=new Map;let n;return t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach((t=>{const s=e.createElement("template");s.setAttribute(K,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=le(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=Te(t,e);s&&ge(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(y.values()),stylesheets:he(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:e.referrer,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:de(e.adoptedStyleSheets)}}function le(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},a){if(s.childNodes){Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement)).forEach((s=>{let i,r,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=Te(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(r=(a||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),r||(i=a||ge(s,l),i&&(s.setAttribute(L,""),n.markedElements.push(s)))),!i)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(F,""),n.markedElements.push(s))}o.removeUnusedFonts&&(ce(l,o,n.usedFonts),ce(Te(e,s,":first-letter"),o,n.usedFonts),ce(Te(e,s,":before"),o,n.usedFonts),ce(Te(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,a,i){const r=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==r)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:i.getPropertyValue("background-color")}),s.setAttribute(B,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==r){const t={currentSrc:a?oe:o.loadDeferredImages&&s.getAttribute(Y)||s.currentSrc};if(n.images.push(t),s.setAttribute(k,n.images.length-1),n.markedElements.push(s),s.removeAttribute(Y),i=i||Te(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const a=null==t.getAttribute("style");if(s=s||Te(e,t)){let e,i,r,l,d,c,m,u,g=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),g=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=fe("padding-left",s),i=fe("padding-right",s),r=fe("padding-top",s),l=fe("padding-bottom",s),g?(d=fe("border-left-width",s),c=fe("border-right-width",s),m=fe("border-top-width",s),u=fe("border-bottom-width",s)):d=c=m=u=0,o=Math.max(0,t.clientWidth-e-i-d-c),n=Math.max(0,t.clientHeight-r-l-m-u),a&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,i);const o=i.getPropertyValue("box-shadow"),n=i.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=i.getPropertyValue("background-color"),t.objectFit=i.getPropertyValue("object-fit"),t.boxSizing=i.getPropertyValue("box-sizing"),t.objectPosition=i.getPropertyValue("object-position"))}}if("VIDEO"==r){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=Te(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(V,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(H,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==r&&a&&o.removeHiddenElements&&(s.setAttribute(x,""),n.markedElements.push(s));"INPUT"==r&&("password"!=s.type&&(s.setAttribute(z,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(z,s.checked),n.markedElements.push(s)));"TEXTAREA"==r&&(s.setAttribute(z,s.value),n.markedElements.push(s));"SELECT"==r&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(z,""),n.markedElements.push(e))}));"SCRIPT"==r&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(X,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,i,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&me(s);if(d&&!s.classList.contains(te)&&s.tagName.toLowerCase()!=se){const a={};s.setAttribute(U,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(a);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)a.adoptedStyleSheets=de(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>a.adoptedStyleSheets=e.detail.adoptedStyleSheets;s.addEventListener(_,e),s.dispatchEvent(new ie(P,{bubbles:!0})),s.removeEventListener(_,e)}}catch(e){}le(e,t,d,o,n,i),a.content=d.innerHTML,a.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&s.dispatchEvent(new ie(C,{bubbles:!0}))}catch(e){}}le(e,t,s,o,n,i),!o.autoSaveExternalSave&&o.removeHiddenElements&&a&&(r||""==s.getAttribute(D)?s.parentElement&&(s.parentElement.setAttribute(D,""),n.markedElements.push(s.parentElement)):i&&(s.setAttribute(O,""),n.markedElements.push(s)))}))}return n}function de(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function ce(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=ue(n),!t.loadedFonts||t.loadedFonts.find((e=>ue(e.family)==n&&e.style==o))){const t=(a=e.getPropertyValue("font-weight"),ee[a.toLowerCase().trim()]||a),i=e.getPropertyValue("font-variant")||"normal",r=[n,t,o,i];s.set(ae.stringify(r),[n,t,o,i])}var a}))}}function me(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function ue(e=""){return function(e){e=e.match($)?e.replace($,"$1"):e.replace(Q,"$1");return e.trim()}((t=e.trim(),t.replace(w,((e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)})))).toLowerCase();var t}function ge(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),a=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==a)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function pe(e,t,s){if(e.querySelectorAll("["+G+"]").forEach((e=>{e.textContent=e.getAttribute(G),e.removeAttribute(G)})),e.querySelectorAll("meta[disabled-http-equiv]").forEach((e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")})),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach((e=>e.removeAttribute("hidden"))),!t){const s=[O,x,L,F,k,H,V,B,z,U,j,X];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(O),e.removeAttribute(L),e.removeAttribute(D),e.removeAttribute(x),e.removeAttribute(F),e.removeAttribute(k),e.removeAttribute(H),e.removeAttribute(V),e.removeAttribute(B),e.removeAttribute(z),e.removeAttribute(U),e.removeAttribute(j),e.removeAttribute(X),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))}function he(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const a=n.sheet;n.remove();const i=Array.from(a.cssRules).map((e=>e.cssText)).join("\n"),r=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");a&&i==r||(s.setAttribute(j,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function fe(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function Te(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const Ee={LAZY_SRC_ATTRIBUTE_NAME:Y,SINGLE_FILE_UI_ELEMENT_CLASS:te},be=10,ye="attributes",Ie=globalThis.browser,we=globalThis.document,Ae=globalThis.MutationObserver,Se=(e,t,s)=>globalThis.addEventListener(e,t,s),ve=(e,t,s)=>globalThis.removeEventListener(e,t,s),Re=new Map;let Ne;async function Pe(e){if(we.documentElement){Re.clear();const s=we.body?Math.max(we.body.scrollHeight,we.documentElement.scrollHeight):we.documentElement.scrollHeight,n=we.body?Math.max(we.body.scrollWidth,we.documentElement.scrollWidth):we.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const i=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY<i||globalThis.scrollX<l)return function(e){return Ne=0,new Promise((async s=>{let n;const i=new Set,l=new Ae((async t=>{if((t=t.filter((e=>e.type==ye))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(Ee.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",g)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(Ee.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Ce(l,e,E),i.size||await _e(l,e,E))}}));async function c(t){await Oe("idleTimeout",(async()=>{n?Ne<be&&(Ne++,De("idleTimeout"),await c(Math.max(500,t/2))):(De("loadTimeout"),De("maxTimeout"),Me(l,e,E))}),t,e.loadDeferredImagesNativeTimeout)}function g(e){const t=e.target;t.removeAttribute(Ee.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",g)}async function p(t){n=!0,await Ce(l,e,E),await _e(l,e,E),t.detail&&i.add(t.detail)}async function T(t){await Ce(l,e,E),await _e(l,e,E),i.delete(t.detail),i.size||await _e(l,e,E)}function E(e){l.disconnect(),ve(m,p),ve(u,T),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await Ce(l,e,E),l.observe(we,{subtree:!0,childList:!0,attributes:!0}),Se(m,p),Se(u,T),function(e){e.loadDeferredImagesBlockCookies&&h(new f(a)),e.loadDeferredImagesBlockStorage&&h(new f(d)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(r)),e.loadDeferredImagesKeepZoomLevel?h(new f(o)):h(new f(t))}(e)}))}(e)}}}async function _e(e,t,s){await Oe("loadTimeout",(()=>Me(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Ce(e,t,s){await Oe("maxTimeout",(async()=>{await De("loadTimeout"),await Me(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Me(e,t,o){await De("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&h(new f(i)),e.loadDeferredImagesBlockStorage&&h(new f(c)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(l)),e.loadDeferredImagesKeepZoomLevel?h(new f(n)):h(new f(s))}(t),await Oe("endTimeout",(async()=>{await De("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Oe(e,t,s,o){if(Ie&&Ie.runtime&&Ie.runtime.sendMessage&&!o){if(!Re.get(e)||!Re.get(e).pending){const o={callback:t,pending:!0};Re.set(e,o);try{await Ie.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Le(e,t,s)}o.pending=!1}}else Le(e,t,s)}function Le(e,t,s){const o=Re.get(e);o&&globalThis.clearTimeout(o),Re.set(e,t),globalThis.setTimeout(t,s)}async function De(e){if(Ie&&Ie.runtime&&Ie.runtime.sendMessage)try{await Ie.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){xe(e)}else xe(e)}function xe(e){const t=Re.get(e);Re.delete(e),t&&globalThis.clearTimeout(t)}Ie&&Ie.runtime&&Ie.runtime.onMessage&&Ie.runtime.onMessage.addListener&&Ie.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=Re.get(e.type);if(t){Re.delete(e.type);try{t.callback()}catch(t){xe(e.type)}}}}));const Fe={ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,WIN_ID_ATTRIBUTE_NAME:q,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:S,preProcessDoc:re,serialize:function(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML},postProcessDoc:pe,getShadowRoot:me},Ue='iframe, frame, object[type="text/html"][data]',qe="*",ke="singlefile.frameTree.initRequest",He="singlefile.frameTree.ackInitRequest",Ve="singlefile.frameTree.cleanupRequest",Be="singlefile.frameTree.initResponse",We="*",ze=5e3,Ye=".",je=globalThis.window==globalThis.top,Ge=globalThis.browser,Ke=globalThis.top,Xe=globalThis.MessageChannel,Ze=globalThis.document,Je=globalThis.JSON;let $e,Qe=globalThis.sessions;var et,tt,st;function ot(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function nt(e){const t=e.sessionId,s=globalThis[Fe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,je||($e=globalThis.frameId=e.windowId),rt(Ze,e.options,$e,t),je||(e.options.userScriptEnabled&&s&&await s(Fe.ON_BEFORE_CAPTURE_EVENT_NAME),mt({frames:[gt(Ze,globalThis,$e,e.options,e.scrolling)],sessionId:t,requestedFrameId:Ze.documentElement.dataset.requestedFrameId&&$e}),e.options.userScriptEnabled&&s&&await s(Fe.ON_AFTER_CAPTURE_EVENT_NAME),delete Ze.documentElement.dataset.requestedFrameId)}function at(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;ct(pt(Ze),e.windowId,t)}}function it(e){e.frames.forEach((t=>lt("responseTimeouts",e.sessionId,t.windowId)));const t=Qe.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach((e=>{let s=t.frames.find((t=>e.windowId==t.windowId));s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(Ye).length-e.windowId.split(Ye).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function rt(e,t,s,o){const n=pt(e);!function(e,t,s,o,n){const a=[];let i;Qe.get(n)?i=Qe.get(n).requestTimeouts:(i={},Qe.set(n,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=o+Ye+t;e.setAttribute(Fe.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),mt({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const a=o+Ye+t;try{ut(e.contentWindow,{method:ke,windowId:a,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}i[a]=globalThis.setTimeout((()=>mt({frames:[{windowId:a,processed:!0}],sessionId:n})),ze)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const a=[];t.forEach(((e,t)=>{const i=o+Ye+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),lt("requestTimeouts",n,i),rt(r,s,i,n),a.push(gt(r,t,i,s,e.scrolling))}catch(e){a.push({windowId:i,processed:!0})}})),mt({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function lt(e,t,s){const o=Qe.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function dt(e,t){const s=Qe.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>mt({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function ct(e,t,s){e.forEach(((e,o)=>{const n=t+Ye+o;e.removeAttribute(Fe.WIN_ID_ATTRIBUTE_NAME);try{ut(e.contentWindow,{method:Ve,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+Ye+o;let a;try{a=e.contentDocument}catch(e){}if(a)try{ct(pt(a),n,s)}catch(e){}}))}function mt(e){e.method=Be;try{Ke.singlefile.processors.frameTree.initResponse(e)}catch(t){ut(Ke,e,!0)}}function ut(e,t,s){if(e==Ke&&Ge&&Ge.runtime&&Ge.runtime.sendMessage)Ge.runtime.sendMessage(t);else if(s){const s=new Xe;e.postMessage(v+Je.stringify({method:t.method,sessionId:t.sessionId}),We,[s.port2]),s.port1.postMessage(t)}else e.postMessage(v+Je.stringify(t),We)}function gt(e,t,s,o,n){const a=Fe.preProcessDoc(e,t,o),i=Fe.serialize(e);Fe.postProcessDoc(e,a.markedElements,a.invalidElements);return{windowId:s,content:i,baseURI:e.baseURI.split("#")[0],url:e.location.href,title:e.title,canvases:a.canvases,fonts:a.fonts,stylesheets:a.stylesheets,images:a.images,posters:a.posters,videos:a.videos,usedFonts:a.usedFonts,shadowRoots:a.shadowRoots,scrollPosition:a.scrollPosition,scrolling:n,adoptedStyleSheets:a.adoptedStyleSheets,processed:!0}}function pt(e){let t=Array.from(e.querySelectorAll(Ue));return e.querySelectorAll(qe).forEach((e=>{const s=Fe.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Ue)))})),t}Qe||(Qe=globalThis.sessions=new Map),je&&($e="0",Ge&&Ge.runtime&&Ge.runtime.onMessage&&Ge.runtime.onMessage.addListener&&Ge.runtime.onMessage.addListener((e=>e.method==Be?(it(e),Promise.resolve({})):e.method==He?(lt("requestTimeouts",e.sessionId,e.windowId),dt(e.sessionId,e.windowId),Promise.resolve({})):void 0))),et="message",tt=async e=>{if("string"==typeof e.data&&e.data.startsWith(v)){e.preventDefault(),e.stopPropagation();const t=Je.parse(e.data.substring(v.length));t.method==ke?(e.source&&ut(e.source,{method:He,windowId:t.windowId,sessionId:t.sessionId}),je||(globalThis.stop(),t.options.loadDeferredImages&&Pe(t.options),await nt(t))):t.method==He?(lt("requestTimeouts",t.sessionId,t.windowId),dt(t.sessionId,t.windowId)):t.method==Ve?at(t):t.method==Be&&Qe.get(t.sessionId)&&(e.ports[0].onmessage=e=>it(e.data))}},st=!0,globalThis.addEventListener(et,tt,st);var ht=Object.freeze({__proto__:null,getAsync:function(e){const t=ot();return e=Je.parse(Je.stringify(e)),new Promise((s=>{Qe.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),nt({windowId:$e,sessionId:t,options:e})}))},getSync:function(e){const t=ot();e=Je.parse(Je.stringify(e)),Qe.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Fe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,je||($e=globalThis.frameId=e.windowId);rt(Ze,e.options,$e,t),je||(e.options.userScriptEnabled&&s&&s(Fe.ON_BEFORE_CAPTURE_EVENT_NAME),mt({frames:[gt(Ze,globalThis,$e,e.options,e.scrolling)],sessionId:t,requestedFrameId:Ze.documentElement.dataset.requestedFrameId&&$e}),e.options.userScriptEnabled&&s&&s(Fe.ON_AFTER_CAPTURE_EVENT_NAME),delete Ze.documentElement.dataset.requestedFrameId)}({windowId:$e,sessionId:t,options:e});const s=Qe.get(t).frames;return s.sessionId=t,s},cleanup:function(e){Qe.delete(e),at({windowId:$e,sessionId:e,options:{sessionId:e}})},initResponse:it,TIMEOUT_INIT_REQUEST_MESSAGE:ze});const ft=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"],Tt=1,Et=3,bt=8,yt=[{tagName:"HEAD",accept:e=>!e.childNodes.length||e.childNodes[0].nodeType==Tt},{tagName:"BODY",accept:e=>!e.childNodes.length}],It=[{tagName:"HTML",accept:e=>!e||e.nodeType!=bt},{tagName:"HEAD",accept:e=>!e||e.nodeType!=bt&&(e.nodeType!=Et||!St(e.textContent))},{tagName:"BODY",accept:e=>!e||e.nodeType!=bt},{tagName:"LI",accept:(e,t)=>!e&&t.parentElement&&("UL"==vt(t.parentElement)||"OL"==vt(t.parentElement))||e&&["LI"].includes(vt(e))},{tagName:"DT",accept:e=>!e||["DT","DD"].includes(vt(e))},{tagName:"P",accept:e=>e&&["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"].includes(vt(e))},{tagName:"DD",accept:e=>!e||["DT","DD"].includes(vt(e))},{tagName:"RT",accept:e=>!e||["RT","RP"].includes(vt(e))},{tagName:"RP",accept:e=>!e||["RT","RP"].includes(vt(e))},{tagName:"OPTGROUP",accept:e=>!e||["OPTGROUP"].includes(vt(e))},{tagName:"OPTION",accept:e=>!e||["OPTION","OPTGROUP"].includes(vt(e))},{tagName:"COLGROUP",accept:e=>!e||e.nodeType!=bt&&(e.nodeType!=Et||!St(e.textContent))},{tagName:"CAPTION",accept:e=>!e||e.nodeType!=bt&&(e.nodeType!=Et||!St(e.textContent))},{tagName:"THEAD",accept:e=>!e||["TBODY","TFOOT"].includes(vt(e))},{tagName:"TBODY",accept:e=>!e||["TBODY","TFOOT"].includes(vt(e))},{tagName:"TFOOT",accept:e=>!e},{tagName:"TR",accept:e=>!e||["TR"].includes(vt(e))},{tagName:"TD",accept:e=>!e||["TD","TH"].includes(vt(e))},{tagName:"TH",accept:e=>!e||["TD","TH"].includes(vt(e))}],wt=["STYLE","SCRIPT","XMP","IFRAME","NOEMBED","NOFRAMES","PLAINTEXT","NOSCRIPT"];function At(e,t,s){return e.nodeType==Et?function(e){const t=e.parentNode;let s;t&&t.nodeType==Tt&&(s=vt(t));return!s||wt.includes(s)?"SCRIPT"==s||"STYLE"==s?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&").replace(/\u00a0/g," ").replace(/</g,"<").replace(/>/g,">")}(e):e.nodeType==bt?"\x3c!--"+e.textContent+"--\x3e":e.nodeType==Tt?function(e,t,s){const o=vt(e),n=t&&yt.find((t=>o==vt(t)&&t.accept(e)));let a="";n&&!e.attributes.length||(a="<"+o.toLowerCase(),Array.from(e.attributes).forEach((s=>a+=function(e,t,s){const o=e.name;let n="";if(!o.match(/["'>/=]/)){let a,i=e.value;s&&"class"==o&&(i=Array.from(t.classList).map((e=>e.trim())).join(" ")),i=i.replace(/&/g,"&").replace(/\u00a0/g," "),i.includes('"')&&(i.includes("'")||!s?i=i.replace(/"/g,"""):a=!0);const r=!s||i.match(/[ \t\n\f\r'"`=<>]/);n+=" ",e.namespace?"http://www.w3.org/XML/1998/namespace"==e.namespaceURI?n+="xml:"+o:"http://www.w3.org/2000/xmlns/"==e.namespaceURI?("xmlns"!==o&&(n+="xmlns:"),n+=o):"http://www.w3.org/1999/xlink"==e.namespaceURI?n+="xlink:"+o:n+=o:n+=o,""!=i&&(n+="=",r&&(n+=a?"'":'"'),n+=i,r&&(n+=a?"'":'"'))}return n}(s,e,t))),a+=">");"TEMPLATE"!=o||e.childNodes.length?Array.from(e.childNodes).forEach((e=>a+=At(e,t,s||"svg"==o))):a+=e.innerHTML;const i=t&&It.find((t=>o==vt(t)&&t.accept(e.nextSibling,e)));(s||!i&&!ft.includes(o))&&(a+="</"+o.toLowerCase()+">");return a}(e,t,s):void 0}function St(e){return Boolean(e.match(/^[ \t\n\f\r]/))}function vt(e){return e.tagName&&e.tagName.toUpperCase()}const Rt={frameTree:ht},Nt={COMMENT_HEADER:"Page saved with SingleFile",COMMENT_HEADER_LEGACY:"Archive processed by SingleFile",ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,preProcessDoc:re,postProcessDoc:pe,serialize:(e,t)=>function(e,t){const s=e.doctype;let o="";return s&&(o="<!DOCTYPE "+s.nodeName,s.publicId?(o+=' PUBLIC "'+s.publicId+'"',s.systemId&&(o+=' "'+s.systemId+'"')):s.systemId&&(o+=' SYSTEM "'+s.systemId+'"'),s.internalSubset&&(o+=" ["+s.internalSubset+"]"),o+="> "),o+At(e.documentElement,t)}(e,t),getShadowRoot:me};ne(M,(()=>globalThis[S]=async e=>{const t=new ie(e+"-request",{cancelable:!0}),s=new Promise((t=>ne(e+"-response",t)));(e=>{try{globalThis.dispatchEvent(e)}catch(e){}})(t),t.defaultPrevented&&await s})),e.helper=Nt,e.processors=Rt,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefile={})}(this,(function(e){"use strict";const t="single-file-load-deferred-images-start",s="single-file-load-deferred-images-end",o="single-file-load-deferred-images-keep-zoom-level-start",n="single-file-load-deferred-images-keep-zoom-level-end",i="single-file-block-cookies-start",r="single-file-block-cookies-end",a="single-file-dispatch-scroll-event-start",l="single-file-dispatch-scroll-event-end",d="single-file-block-storage-start",c="single-file-block-storage-end",u="single-file-load-image",m="single-file-image-loaded",g="_singleFile_fontFaces",h=(e,t,s)=>globalThis.addEventListener(e,t,s),f=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},p=globalThis.CustomEvent,b=globalThis.document,E=globalThis.Document,y=globalThis.JSON;let T;T=window[g]?window[g]:window[g]=new Map,b instanceof E&&(h("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,T.set(y.stringify(s),t)})),h("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,T.delete(y.stringify(s))})),h("single-file-clear-fonts",(()=>T=new Map)));const w="[\\x20\\t\\r\\n\\f]",I=new RegExp("\\\\([\\da-f]{1,6}"+w+"?|("+w+")|.)","ig");const A="single-file-",v="__frameTree__::",S=A+"on-before-capture",R=A+"on-after-capture",_=A+"request-get-adopted-stylesheets",M=A+"response-get-adopted-stylesheets",P=A+"unregister-request-get-adopted-stylesheets",N="data-"+A+"removed-content",C="data-"+A+"hidden-content",F="data-"+A+"kept-content",x="data-"+A+"hidden-frame",q="data-"+A+"preserved-space-element",L="data-"+A+"shadow-root-element",k="data-"+A+"win-id",U="data-"+A+"image",D="data-"+A+"poster",O="data-"+A+"video",V="data-"+A+"canvas",W="data-"+A+"movable-style",H="data-"+A+"input-value",z="data-"+A+"lazy-loaded-src",B="data-"+A+"stylesheet",j="data-"+A+"disabled-noscript",Y="data-"+A+"invalid-element",G="data-"+A+"async-script",Z="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",J=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],$=/^'(.*?)'$/,K=/^"(.*?)"$/,X={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},Q="single-file-ui-element",ee="data:,",te=globalThis.JSON,se=globalThis.CustomEvent;function oe(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},i){if(s.childNodes){Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement)).forEach((s=>{let r,a,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=ue(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(a=(i||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),a||(r=i||le(s,l),r&&(s.setAttribute(C,""),n.markedElements.push(s)))),!r)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(q,""),n.markedElements.push(s))}o.removeUnusedFonts&&(ie(l,o,n.usedFonts),ie(ue(e,s,":first-letter"),o,n.usedFonts),ie(ue(e,s,":before"),o,n.usedFonts),ie(ue(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,i,r){const a=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==a)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:r.getPropertyValue("background-color")}),s.setAttribute(V,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==a){const t={currentSrc:i?ee:o.loadDeferredImages&&s.getAttribute(z)||s.currentSrc};if(n.images.push(t),s.setAttribute(U,n.images.length-1),n.markedElements.push(s),s.removeAttribute(z),r=r||ue(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const i=null==t.getAttribute("style");if(s=s||ue(e,t)){let e,r,a,l,d,c,u,m,g=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),g=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=ce("padding-left",s),r=ce("padding-right",s),a=ce("padding-top",s),l=ce("padding-bottom",s),g?(d=ce("border-left-width",s),c=ce("border-right-width",s),u=ce("border-top-width",s),m=ce("border-bottom-width",s)):d=c=u=m=0,o=Math.max(0,t.clientWidth-e-r-d-c),n=Math.max(0,t.clientHeight-a-l-u-m),i&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,r);const o=r.getPropertyValue("box-shadow"),n=r.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=r.getPropertyValue("background-color"),t.objectFit=r.getPropertyValue("object-fit"),t.boxSizing=r.getPropertyValue("box-sizing"),t.objectPosition=r.getPropertyValue("object-position"))}}if("VIDEO"==a){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=ue(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(O,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(D,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==a&&i&&o.removeHiddenElements&&(s.setAttribute(x,""),n.markedElements.push(s));"INPUT"==a&&("password"!=s.type&&(s.setAttribute(H,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(H,s.checked),n.markedElements.push(s)));"TEXTAREA"==a&&(s.setAttribute(H,s.value),n.markedElements.push(s));"SELECT"==a&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(H,""),n.markedElements.push(e))}));"SCRIPT"==a&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(G,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,r,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&re(s);if(d&&!s.classList.contains(Q)){const i={};s.setAttribute(L,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(i);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)i.adoptedStyleSheets=ne(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>i.adoptedStyleSheets=e.detail.adoptedStyleSheets;s.addEventListener(M,e),s.dispatchEvent(new se(_,{bubbles:!0})),s.removeEventListener(M,e)}}catch(e){}oe(e,t,d,o,n,r),i.content=d.innerHTML,i.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&s.dispatchEvent(new se(P,{bubbles:!0}))}catch(e){}}oe(e,t,s,o,n,r),!o.autoSaveExternalSave&&o.removeHiddenElements&&i&&(a||""==s.getAttribute(F)?s.parentElement&&(s.parentElement.setAttribute(F,""),n.markedElements.push(s.parentElement)):r&&(s.setAttribute(N,""),n.markedElements.push(s)))}))}return n}function ne(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function ie(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=ae(n),!t.loadedFonts||t.loadedFonts.find((e=>ae(e.family)==n&&e.style==o))){const t=(i=e.getPropertyValue("font-weight"),X[i.toLowerCase().trim()]||i),r=e.getPropertyValue("font-variant")||"normal",a=[n,t,o,r];s.set(te.stringify(a),[n,t,o,r])}var i}))}}function re(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function ae(e=""){return function(e){e=e.match($)?e.replace($,"$1"):e.replace(K,"$1");return e.trim()}((t=e.trim(),t.replace(I,((e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)})))).toLowerCase();var t}function le(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),i=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==i)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function de(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const i=n.sheet;n.remove();const r=Array.from(i.cssRules).map((e=>e.cssText)).join("\n"),a=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");i&&r==a||(s.setAttribute(B,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function ce(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function ue(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const me={LAZY_SRC_ATTRIBUTE_NAME:z,SINGLE_FILE_UI_ELEMENT_CLASS:Q},ge=10,he="attributes",fe=globalThis.browser,pe=globalThis.document,be=globalThis.MutationObserver,Ee=(e,t,s)=>globalThis.addEventListener(e,t,s),ye=(e,t,s)=>globalThis.removeEventListener(e,t,s),Te=new Map;let we;async function Ie(e){if(pe.documentElement){Te.clear();const s=pe.body?Math.max(pe.body.scrollHeight,pe.documentElement.scrollHeight):pe.documentElement.scrollHeight,n=pe.body?Math.max(pe.body.scrollWidth,pe.documentElement.scrollWidth):pe.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const r=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY<r||globalThis.scrollX<l)return function(e){return we=0,new Promise((async s=>{let n;const r=new Set,l=new be((async t=>{if((t=t.filter((e=>e.type==he))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(me.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",g)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(me.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await ve(l,e,E),r.size||await Ae(l,e,E))}}));async function c(t){await Re("idleTimeout",(async()=>{n?we<ge&&(we++,Me("idleTimeout"),await c(Math.max(500,t/2))):(Me("loadTimeout"),Me("maxTimeout"),Se(l,e,E))}),t,e.loadDeferredImagesNativeTimeout)}function g(e){const t=e.target;t.removeAttribute(me.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",g)}async function h(t){n=!0,await ve(l,e,E),await Ae(l,e,E),t.detail&&r.add(t.detail)}async function b(t){await ve(l,e,E),await Ae(l,e,E),r.delete(t.detail),r.size||await Ae(l,e,E)}function E(e){l.disconnect(),ye(u,h),ye(m,b),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await ve(l,e,E),l.observe(pe,{subtree:!0,childList:!0,attributes:!0}),Ee(u,h),Ee(m,b),function(e){e.loadDeferredImagesBlockCookies&&f(new p(i)),e.loadDeferredImagesBlockStorage&&f(new p(d)),e.loadDeferredImagesDispatchScrollEvent&&f(new p(a)),e.loadDeferredImagesKeepZoomLevel?f(new p(o)):f(new p(t))}(e)}))}(e)}}}async function Ae(e,t,s){await Re("loadTimeout",(()=>Se(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function ve(e,t,s){await Re("maxTimeout",(async()=>{await Me("loadTimeout"),await Se(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Se(e,t,o){await Me("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&f(new p(r)),e.loadDeferredImagesBlockStorage&&f(new p(c)),e.loadDeferredImagesDispatchScrollEvent&&f(new p(l)),e.loadDeferredImagesKeepZoomLevel?f(new p(n)):f(new p(s))}(t),await Re("endTimeout",(async()=>{await Me("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Re(e,t,s,o){if(fe&&fe.runtime&&fe.runtime.sendMessage&&!o){if(!Te.get(e)||!Te.get(e).pending){const o={callback:t,pending:!0};Te.set(e,o);try{await fe.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){_e(e,t,s)}o.pending=!1}}else _e(e,t,s)}function _e(e,t,s){const o=Te.get(e);o&&globalThis.clearTimeout(o),Te.set(e,t),globalThis.setTimeout(t,s)}async function Me(e){if(fe&&fe.runtime&&fe.runtime.sendMessage)try{await fe.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){Pe(e)}else Pe(e)}function Pe(e){const t=Te.get(e);Te.delete(e),t&&globalThis.clearTimeout(t)}fe&&fe.runtime&&fe.runtime.onMessage&&fe.runtime.onMessage.addListener&&fe.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=Te.get(e.type);if(t){Te.delete(e.type);try{t.callback()}catch(t){Pe(e.type)}}}}));const Ne={ON_BEFORE_CAPTURE_EVENT_NAME:S,ON_AFTER_CAPTURE_EVENT_NAME:R,WIN_ID_ATTRIBUTE_NAME:k,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:"_singleFile_waitForUserScript",preProcessDoc:function(e,t,s){e.querySelectorAll("noscript:not(["+j+"])").forEach((e=>{e.setAttribute(j,e.textContent),e.textContent=""})),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach((e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")}))}(e),e.head&&e.head.querySelectorAll(Z).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+Z+", html > body > "+Z);t.length&&(Array.from(e.childNodes).forEach((e=>e.remove())),t.forEach((t=>e.appendChild(t))))}));const o=new Map;let n;return t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach((t=>{const s=e.createElement("template");s.setAttribute(Y,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=oe(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=ue(t,e);s&&le(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(T.values()),stylesheets:de(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:e.referrer,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:ne(e.adoptedStyleSheets)}},serialize:function(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML},postProcessDoc:function(e,t,s){if(e.querySelectorAll("["+j+"]").forEach((e=>{e.textContent=e.getAttribute(j),e.removeAttribute(j)})),e.querySelectorAll("meta[disabled-http-equiv]").forEach((e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")})),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach((e=>e.removeAttribute("hidden"))),!t){const s=[N,x,C,q,U,D,O,V,H,L,B,G];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(N),e.removeAttribute(C),e.removeAttribute(F),e.removeAttribute(x),e.removeAttribute(q),e.removeAttribute(U),e.removeAttribute(D),e.removeAttribute(O),e.removeAttribute(V),e.removeAttribute(H),e.removeAttribute(L),e.removeAttribute(B),e.removeAttribute(G),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))},getShadowRoot:re},Ce='iframe, frame, object[type="text/html"][data]',Fe="*",xe="singlefile.frameTree.initRequest",qe="singlefile.frameTree.ackInitRequest",Le="singlefile.frameTree.cleanupRequest",ke="singlefile.frameTree.initResponse",Ue="*",De=5e3,Oe=".",Ve=globalThis.window==globalThis.top,We=globalThis.browser,He=globalThis.top,ze=globalThis.MessageChannel,Be=globalThis.document,je=globalThis.JSON;let Ye,Ge=globalThis.sessions;var Ze,Je,$e;function Ke(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function Xe(e){const t=e.sessionId,s=globalThis[Ne.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ve||(Ye=globalThis.frameId=e.windowId),tt(Be,e.options,Ye,t),Ve||(e.options.userScriptEnabled&&s&&await s(Ne.ON_BEFORE_CAPTURE_EVENT_NAME),it({frames:[at(Be,globalThis,Ye,e.options,e.scrolling)],sessionId:t,requestedFrameId:Be.documentElement.dataset.requestedFrameId&&Ye}),e.options.userScriptEnabled&&s&&await s(Ne.ON_AFTER_CAPTURE_EVENT_NAME),delete Be.documentElement.dataset.requestedFrameId)}function Qe(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;nt(lt(Be),e.windowId,t)}}function et(e){e.frames.forEach((t=>st("responseTimeouts",e.sessionId,t.windowId)));const t=Ge.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach((e=>{let s=t.frames.find((t=>e.windowId==t.windowId));s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(Oe).length-e.windowId.split(Oe).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function tt(e,t,s,o){const n=lt(e);!function(e,t,s,o,n){const i=[];let r;Ge.get(n)?r=Ge.get(n).requestTimeouts:(r={},Ge.set(n,{requestTimeouts:r}));t.forEach(((e,t)=>{const s=o+Oe+t;e.setAttribute(Ne.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),it({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+Oe+t;try{rt(e.contentWindow,{method:xe,windowId:i,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}r[i]=globalThis.setTimeout((()=>it({frames:[{windowId:i,processed:!0}],sessionId:n})),De)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const i=[];t.forEach(((e,t)=>{const r=o+Oe+t;let a;try{a=e.contentDocument}catch(e){}if(a)try{const t=e.contentWindow;t.stop(),st("requestTimeouts",n,r),tt(a,s,r,n),i.push(at(a,t,r,s,e.scrolling))}catch(e){i.push({windowId:r,processed:!0})}})),it({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function st(e,t,s){const o=Ge.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function ot(e,t){const s=Ge.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>it({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function nt(e,t,s){e.forEach(((e,o)=>{const n=t+Oe+o;e.removeAttribute(Ne.WIN_ID_ATTRIBUTE_NAME);try{rt(e.contentWindow,{method:Le,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+Oe+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{nt(lt(i),n,s)}catch(e){}}))}function it(e){e.method=ke;try{He.singlefile.processors.frameTree.initResponse(e)}catch(t){rt(He,e,!0)}}function rt(e,t,s){if(e==He&&We&&We.runtime&&We.runtime.sendMessage)We.runtime.sendMessage(t);else if(s){const s=new ze;e.postMessage(v+je.stringify({method:t.method,sessionId:t.sessionId}),Ue,[s.port2]),s.port1.postMessage(t)}else e.postMessage(v+je.stringify(t),Ue)}function at(e,t,s,o,n){const i=Ne.preProcessDoc(e,t,o),r=Ne.serialize(e);Ne.postProcessDoc(e,i.markedElements,i.invalidElements);return{windowId:s,content:r,baseURI:e.baseURI.split("#")[0],url:e.location.href,title:e.title,canvases:i.canvases,fonts:i.fonts,stylesheets:i.stylesheets,images:i.images,posters:i.posters,videos:i.videos,usedFonts:i.usedFonts,shadowRoots:i.shadowRoots,scrollPosition:i.scrollPosition,scrolling:n,adoptedStyleSheets:i.adoptedStyleSheets,processed:!0}}function lt(e){let t=Array.from(e.querySelectorAll(Ce));return e.querySelectorAll(Fe).forEach((e=>{const s=Ne.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Ce)))})),t}Ge||(Ge=globalThis.sessions=new Map),Ve&&(Ye="0",We&&We.runtime&&We.runtime.onMessage&&We.runtime.onMessage.addListener&&We.runtime.onMessage.addListener((e=>e.method==ke?(et(e),Promise.resolve({})):e.method==qe?(st("requestTimeouts",e.sessionId,e.windowId),ot(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Ze="message",Je=async e=>{if("string"==typeof e.data&&e.data.startsWith(v)){e.preventDefault(),e.stopPropagation();const t=je.parse(e.data.substring(v.length));t.method==xe?(e.source&&rt(e.source,{method:qe,windowId:t.windowId,sessionId:t.sessionId}),Ve||(globalThis.stop(),t.options.loadDeferredImages&&Ie(t.options),await Xe(t))):t.method==qe?(st("requestTimeouts",t.sessionId,t.windowId),ot(t.sessionId,t.windowId)):t.method==Le?Qe(t):t.method==ke&&Ge.get(t.sessionId)&&(e.ports[0].onmessage=e=>et(e.data))}},$e=!0,globalThis.addEventListener(Ze,Je,$e),e.TIMEOUT_INIT_REQUEST_MESSAGE=De,e.cleanup=function(e){Ge.delete(e),Qe({windowId:Ye,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=Ke();return e=je.parse(je.stringify(e)),new Promise((s=>{Ge.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),Xe({windowId:Ye,sessionId:t,options:e})}))},e.getSync=function(e){const t=Ke();e=je.parse(je.stringify(e)),Ge.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Ne.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ve||(Ye=globalThis.frameId=e.windowId);tt(Be,e.options,Ye,t),Ve||(e.options.userScriptEnabled&&s&&s(Ne.ON_BEFORE_CAPTURE_EVENT_NAME),it({frames:[at(Be,globalThis,Ye,e.options,e.scrolling)],sessionId:t,requestedFrameId:Be.documentElement.dataset.requestedFrameId&&Ye}),e.options.userScriptEnabled&&s&&s(Ne.ON_AFTER_CAPTURE_EVENT_NAME),delete Be.documentElement.dataset.requestedFrameId)}({windowId:Ye,sessionId:t,options:e});const s=Ge.get(t).frames;return s.sessionId=t,s},e.initResponse=et,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefile={})}(this,(function(e){"use strict";const t="single-file-load-deferred-images-start",s="single-file-load-deferred-images-end",o="single-file-load-deferred-images-keep-zoom-level-start",n="single-file-load-deferred-images-keep-zoom-level-end",i="single-file-block-cookies-start",r="single-file-block-cookies-end",a="single-file-dispatch-scroll-event-start",l="single-file-dispatch-scroll-event-end",d="single-file-block-storage-start",c="single-file-block-storage-end",m="single-file-load-image",u="single-file-image-loaded",g="_singleFile_fontFaces",h=(e,t,s)=>globalThis.addEventListener(e,t,s),f=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},p=globalThis.CustomEvent,b=globalThis.document,E=globalThis.Document,y=globalThis.JSON;let T;T=window[g]?window[g]:window[g]=new Map,b instanceof E&&(h("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,T.set(y.stringify(s),t)})),h("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,T.delete(y.stringify(s))})),h("single-file-clear-fonts",(()=>T=new Map)));const w="[\\x20\\t\\r\\n\\f]",I=new RegExp("\\\\([\\da-f]{1,6}"+w+"?|("+w+")|.)","ig");const A="single-file-",v="__frameTree__::",S=A+"on-before-capture",R=A+"on-after-capture",_=A+"request-get-adopted-stylesheets",M=A+"response-get-adopted-stylesheets",P=A+"unregister-request-get-adopted-stylesheets",N="data-"+A+"removed-content",C="data-"+A+"hidden-content",F="data-"+A+"kept-content",x="data-"+A+"hidden-frame",q="data-"+A+"preserved-space-element",L="data-"+A+"shadow-root-element",k="data-"+A+"win-id",U="data-"+A+"image",D="data-"+A+"poster",O="data-"+A+"video",V="data-"+A+"canvas",W="data-"+A+"movable-style",H="data-"+A+"input-value",z="data-"+A+"lazy-loaded-src",B="data-"+A+"stylesheet",j="data-"+A+"disabled-noscript",Y="data-"+A+"invalid-element",G="data-"+A+"async-script",Z="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",J=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],$=/^'(.*?)'$/,K=/^"(.*?)"$/,X={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},Q="single-file-ui-element",ee="single-file-infobar",te="data:,",se=globalThis.JSON,oe=globalThis.CustomEvent;function ne(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},i){if(s.childNodes){Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement)).forEach((s=>{let r,a,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=ue(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(a=(i||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),a||(r=i||de(s,l),r&&(s.setAttribute(C,""),n.markedElements.push(s)))),!r)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(q,""),n.markedElements.push(s))}o.removeUnusedFonts&&(re(l,o,n.usedFonts),re(ue(e,s,":first-letter"),o,n.usedFonts),re(ue(e,s,":before"),o,n.usedFonts),re(ue(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,i,r){const a=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==a)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:r.getPropertyValue("background-color")}),s.setAttribute(V,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==a){const t={currentSrc:i?te:o.loadDeferredImages&&s.getAttribute(z)||s.currentSrc};if(n.images.push(t),s.setAttribute(U,n.images.length-1),n.markedElements.push(s),s.removeAttribute(z),r=r||ue(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const i=null==t.getAttribute("style");if(s=s||ue(e,t)){let e,r,a,l,d,c,m,u,g=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),g=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=me("padding-left",s),r=me("padding-right",s),a=me("padding-top",s),l=me("padding-bottom",s),g?(d=me("border-left-width",s),c=me("border-right-width",s),m=me("border-top-width",s),u=me("border-bottom-width",s)):d=c=m=u=0,o=Math.max(0,t.clientWidth-e-r-d-c),n=Math.max(0,t.clientHeight-a-l-m-u),i&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,r);const o=r.getPropertyValue("box-shadow"),n=r.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=r.getPropertyValue("background-color"),t.objectFit=r.getPropertyValue("object-fit"),t.boxSizing=r.getPropertyValue("box-sizing"),t.objectPosition=r.getPropertyValue("object-position"))}}if("VIDEO"==a){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=ue(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(O,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(D,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==a&&i&&o.removeHiddenElements&&(s.setAttribute(x,""),n.markedElements.push(s));"INPUT"==a&&("password"!=s.type&&(s.setAttribute(H,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(H,s.checked),n.markedElements.push(s)));"TEXTAREA"==a&&(s.setAttribute(H,s.value),n.markedElements.push(s));"SELECT"==a&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(H,""),n.markedElements.push(e))}));"SCRIPT"==a&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(G,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,r,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&ae(s);if(d&&!s.classList.contains(Q)&&s.tagName.toLowerCase()!=ee){const i={};s.setAttribute(L,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(i);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)i.adoptedStyleSheets=ie(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>i.adoptedStyleSheets=e.detail.adoptedStyleSheets;s.addEventListener(M,e),s.dispatchEvent(new oe(_,{bubbles:!0})),s.removeEventListener(M,e)}}catch(e){}ne(e,t,d,o,n,r),i.content=d.innerHTML,i.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&s.dispatchEvent(new oe(P,{bubbles:!0}))}catch(e){}}ne(e,t,s,o,n,r),!o.autoSaveExternalSave&&o.removeHiddenElements&&i&&(a||""==s.getAttribute(F)?s.parentElement&&(s.parentElement.setAttribute(F,""),n.markedElements.push(s.parentElement)):r&&(s.setAttribute(N,""),n.markedElements.push(s)))}))}return n}function ie(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function re(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=le(n),!t.loadedFonts||t.loadedFonts.find((e=>le(e.family)==n&&e.style==o))){const t=(i=e.getPropertyValue("font-weight"),X[i.toLowerCase().trim()]||i),r=e.getPropertyValue("font-variant")||"normal",a=[n,t,o,r];s.set(se.stringify(a),[n,t,o,r])}var i}))}}function ae(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function le(e=""){return function(e){e=e.match($)?e.replace($,"$1"):e.replace(K,"$1");return e.trim()}((t=e.trim(),t.replace(I,((e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)})))).toLowerCase();var t}function de(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),i=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==i)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function ce(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const i=n.sheet;n.remove();const r=Array.from(i.cssRules).map((e=>e.cssText)).join("\n"),a=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");i&&r==a||(s.setAttribute(B,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function me(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function ue(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const ge={LAZY_SRC_ATTRIBUTE_NAME:z,SINGLE_FILE_UI_ELEMENT_CLASS:Q},he=10,fe="attributes",pe=globalThis.browser,be=globalThis.document,Ee=globalThis.MutationObserver,ye=(e,t,s)=>globalThis.addEventListener(e,t,s),Te=(e,t,s)=>globalThis.removeEventListener(e,t,s),we=new Map;let Ie;async function Ae(e){if(be.documentElement){we.clear();const s=be.body?Math.max(be.body.scrollHeight,be.documentElement.scrollHeight):be.documentElement.scrollHeight,n=be.body?Math.max(be.body.scrollWidth,be.documentElement.scrollWidth):be.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const r=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY<r||globalThis.scrollX<l)return function(e){return Ie=0,new Promise((async s=>{let n;const r=new Set,l=new Ee((async t=>{if((t=t.filter((e=>e.type==fe))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(ge.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",g)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(ge.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Se(l,e,E),r.size||await ve(l,e,E))}}));async function c(t){await _e("idleTimeout",(async()=>{n?Ie<he&&(Ie++,Pe("idleTimeout"),await c(Math.max(500,t/2))):(Pe("loadTimeout"),Pe("maxTimeout"),Re(l,e,E))}),t,e.loadDeferredImagesNativeTimeout)}function g(e){const t=e.target;t.removeAttribute(ge.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",g)}async function h(t){n=!0,await Se(l,e,E),await ve(l,e,E),t.detail&&r.add(t.detail)}async function b(t){await Se(l,e,E),await ve(l,e,E),r.delete(t.detail),r.size||await ve(l,e,E)}function E(e){l.disconnect(),Te(m,h),Te(u,b),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await Se(l,e,E),l.observe(be,{subtree:!0,childList:!0,attributes:!0}),ye(m,h),ye(u,b),function(e){e.loadDeferredImagesBlockCookies&&f(new p(i)),e.loadDeferredImagesBlockStorage&&f(new p(d)),e.loadDeferredImagesDispatchScrollEvent&&f(new p(a)),e.loadDeferredImagesKeepZoomLevel?f(new p(o)):f(new p(t))}(e)}))}(e)}}}async function ve(e,t,s){await _e("loadTimeout",(()=>Re(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Se(e,t,s){await _e("maxTimeout",(async()=>{await Pe("loadTimeout"),await Re(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Re(e,t,o){await Pe("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&f(new p(r)),e.loadDeferredImagesBlockStorage&&f(new p(c)),e.loadDeferredImagesDispatchScrollEvent&&f(new p(l)),e.loadDeferredImagesKeepZoomLevel?f(new p(n)):f(new p(s))}(t),await _e("endTimeout",(async()=>{await Pe("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function _e(e,t,s,o){if(pe&&pe.runtime&&pe.runtime.sendMessage&&!o){if(!we.get(e)||!we.get(e).pending){const o={callback:t,pending:!0};we.set(e,o);try{await pe.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Me(e,t,s)}o.pending=!1}}else Me(e,t,s)}function Me(e,t,s){const o=we.get(e);o&&globalThis.clearTimeout(o),we.set(e,t),globalThis.setTimeout(t,s)}async function Pe(e){if(pe&&pe.runtime&&pe.runtime.sendMessage)try{await pe.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){Ne(e)}else Ne(e)}function Ne(e){const t=we.get(e);we.delete(e),t&&globalThis.clearTimeout(t)}pe&&pe.runtime&&pe.runtime.onMessage&&pe.runtime.onMessage.addListener&&pe.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=we.get(e.type);if(t){we.delete(e.type);try{t.callback()}catch(t){Ne(e.type)}}}}));const Ce={ON_BEFORE_CAPTURE_EVENT_NAME:S,ON_AFTER_CAPTURE_EVENT_NAME:R,WIN_ID_ATTRIBUTE_NAME:k,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:"_singleFile_waitForUserScript",preProcessDoc:function(e,t,s){e.querySelectorAll("noscript:not(["+j+"])").forEach((e=>{e.setAttribute(j,e.textContent),e.textContent=""})),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach((e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")}))}(e),e.head&&e.head.querySelectorAll(Z).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+Z+", html > body > "+Z);t.length&&(Array.from(e.childNodes).forEach((e=>e.remove())),t.forEach((t=>e.appendChild(t))))}));const o=new Map;let n;return t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach((t=>{const s=e.createElement("template");s.setAttribute(Y,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=ne(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=ue(t,e);s&&de(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(T.values()),stylesheets:ce(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:e.referrer,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:ie(e.adoptedStyleSheets)}},serialize:function(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML},postProcessDoc:function(e,t,s){if(e.querySelectorAll("["+j+"]").forEach((e=>{e.textContent=e.getAttribute(j),e.removeAttribute(j)})),e.querySelectorAll("meta[disabled-http-equiv]").forEach((e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")})),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach((e=>e.removeAttribute("hidden"))),!t){const s=[N,x,C,q,U,D,O,V,H,L,B,G];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(N),e.removeAttribute(C),e.removeAttribute(F),e.removeAttribute(x),e.removeAttribute(q),e.removeAttribute(U),e.removeAttribute(D),e.removeAttribute(O),e.removeAttribute(V),e.removeAttribute(H),e.removeAttribute(L),e.removeAttribute(B),e.removeAttribute(G),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))},getShadowRoot:ae},Fe='iframe, frame, object[type="text/html"][data]',xe="*",qe="singlefile.frameTree.initRequest",Le="singlefile.frameTree.ackInitRequest",ke="singlefile.frameTree.cleanupRequest",Ue="singlefile.frameTree.initResponse",De="*",Oe=5e3,Ve=".",We=globalThis.window==globalThis.top,He=globalThis.browser,ze=globalThis.top,Be=globalThis.MessageChannel,je=globalThis.document,Ye=globalThis.JSON;let Ge,Ze=globalThis.sessions;var Je,$e,Ke;function Xe(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function Qe(e){const t=e.sessionId,s=globalThis[Ce.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,We||(Ge=globalThis.frameId=e.windowId),st(je,e.options,Ge,t),We||(e.options.userScriptEnabled&&s&&await s(Ce.ON_BEFORE_CAPTURE_EVENT_NAME),rt({frames:[lt(je,globalThis,Ge,e.options,e.scrolling)],sessionId:t,requestedFrameId:je.documentElement.dataset.requestedFrameId&&Ge}),e.options.userScriptEnabled&&s&&await s(Ce.ON_AFTER_CAPTURE_EVENT_NAME),delete je.documentElement.dataset.requestedFrameId)}function et(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;it(dt(je),e.windowId,t)}}function tt(e){e.frames.forEach((t=>ot("responseTimeouts",e.sessionId,t.windowId)));const t=Ze.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach((e=>{let s=t.frames.find((t=>e.windowId==t.windowId));s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(Ve).length-e.windowId.split(Ve).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function st(e,t,s,o){const n=dt(e);!function(e,t,s,o,n){const i=[];let r;Ze.get(n)?r=Ze.get(n).requestTimeouts:(r={},Ze.set(n,{requestTimeouts:r}));t.forEach(((e,t)=>{const s=o+Ve+t;e.setAttribute(Ce.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),rt({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+Ve+t;try{at(e.contentWindow,{method:qe,windowId:i,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}r[i]=globalThis.setTimeout((()=>rt({frames:[{windowId:i,processed:!0}],sessionId:n})),Oe)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const i=[];t.forEach(((e,t)=>{const r=o+Ve+t;let a;try{a=e.contentDocument}catch(e){}if(a)try{const t=e.contentWindow;t.stop(),ot("requestTimeouts",n,r),st(a,s,r,n),i.push(lt(a,t,r,s,e.scrolling))}catch(e){i.push({windowId:r,processed:!0})}})),rt({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function ot(e,t,s){const o=Ze.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function nt(e,t){const s=Ze.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>rt({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function it(e,t,s){e.forEach(((e,o)=>{const n=t+Ve+o;e.removeAttribute(Ce.WIN_ID_ATTRIBUTE_NAME);try{at(e.contentWindow,{method:ke,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+Ve+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{it(dt(i),n,s)}catch(e){}}))}function rt(e){e.method=Ue;try{ze.singlefile.processors.frameTree.initResponse(e)}catch(t){at(ze,e,!0)}}function at(e,t,s){if(e==ze&&He&&He.runtime&&He.runtime.sendMessage)He.runtime.sendMessage(t);else if(s){const s=new Be;e.postMessage(v+Ye.stringify({method:t.method,sessionId:t.sessionId}),De,[s.port2]),s.port1.postMessage(t)}else e.postMessage(v+Ye.stringify(t),De)}function lt(e,t,s,o,n){const i=Ce.preProcessDoc(e,t,o),r=Ce.serialize(e);Ce.postProcessDoc(e,i.markedElements,i.invalidElements);return{windowId:s,content:r,baseURI:e.baseURI.split("#")[0],url:e.location.href,title:e.title,canvases:i.canvases,fonts:i.fonts,stylesheets:i.stylesheets,images:i.images,posters:i.posters,videos:i.videos,usedFonts:i.usedFonts,shadowRoots:i.shadowRoots,scrollPosition:i.scrollPosition,scrolling:n,adoptedStyleSheets:i.adoptedStyleSheets,processed:!0}}function dt(e){let t=Array.from(e.querySelectorAll(Fe));return e.querySelectorAll(xe).forEach((e=>{const s=Ce.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Fe)))})),t}Ze||(Ze=globalThis.sessions=new Map),We&&(Ge="0",He&&He.runtime&&He.runtime.onMessage&&He.runtime.onMessage.addListener&&He.runtime.onMessage.addListener((e=>e.method==Ue?(tt(e),Promise.resolve({})):e.method==Le?(ot("requestTimeouts",e.sessionId,e.windowId),nt(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Je="message",$e=async e=>{if("string"==typeof e.data&&e.data.startsWith(v)){e.preventDefault(),e.stopPropagation();const t=Ye.parse(e.data.substring(v.length));t.method==qe?(e.source&&at(e.source,{method:Le,windowId:t.windowId,sessionId:t.sessionId}),We||(globalThis.stop(),t.options.loadDeferredImages&&Ae(t.options),await Qe(t))):t.method==Le?(ot("requestTimeouts",t.sessionId,t.windowId),nt(t.sessionId,t.windowId)):t.method==ke?et(t):t.method==Ue&&Ze.get(t.sessionId)&&(e.ports[0].onmessage=e=>tt(e.data))}},Ke=!0,globalThis.addEventListener(Je,$e,Ke),e.TIMEOUT_INIT_REQUEST_MESSAGE=Oe,e.cleanup=function(e){Ze.delete(e),et({windowId:Ge,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=Xe();return e=Ye.parse(Ye.stringify(e)),new Promise((s=>{Ze.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),Qe({windowId:Ge,sessionId:t,options:e})}))},e.getSync=function(e){const t=Xe();e=Ye.parse(Ye.stringify(e)),Ze.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Ce.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,We||(Ge=globalThis.frameId=e.windowId);st(je,e.options,Ge,t),We||(e.options.userScriptEnabled&&s&&s(Ce.ON_BEFORE_CAPTURE_EVENT_NAME),rt({frames:[lt(je,globalThis,Ge,e.options,e.scrolling)],sessionId:t,requestedFrameId:je.documentElement.dataset.requestedFrameId&&Ge}),e.options.userScriptEnabled&&s&&s(Ce.ON_AFTER_CAPTURE_EVENT_NAME),delete je.documentElement.dataset.requestedFrameId)}({windowId:Ge,sessionId:t,options:e});const s=Ze.get(t).frames;return s.sessionId=t,s},e.initResponse=tt,Object.defineProperty(e,"__esModule",{value:!0})}));
|