| 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=(e,t,s)=>globalThis.addEventListener(e,t,s),h=e=>{try{globalThis.dispatchEvent(e)}catch(e){}},f=globalThis.CustomEvent,p=globalThis.document,b=globalThis.Document,y=globalThis.JSON;let E;E=window._singleFile_fontFaces?window._singleFile_fontFaces:window._singleFile_fontFaces=new Map,p instanceof b&&(g("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,E.set(y.stringify(s),t)})),g("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,E.delete(y.stringify(s))})),g("single-file-clear-fonts",(()=>E=new Map)));const T="[\\x20\\t\\r\\n\\f]",w=new RegExp("\\\\([\\da-f]{1,6}"+T+"?|("+T+")|.)","ig");const I="single-file-request-get-adopted-stylesheets",v="single-file-unregister-request-get-adopted-stylesheets",A="single-file-response-get-adopted-stylesheets",S="data-single-file-removed-content",_="data-single-file-hidden-content",R="data-single-file-kept-content",M="data-single-file-hidden-frame",F="data-single-file-preserved-space-element",N="data-single-file-shadow-root-element",C="data-single-file-image",P="data-single-file-poster",q="data-single-file-video",x="data-single-file-canvas",k="data-single-file-movable-style",L="data-single-file-input-value",D="data-single-file-lazy-loaded-src",U="data-single-file-stylesheet",V="data-single-file-disabled-noscript",O="data-single-file-async-script",W="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",H=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],z=/^'(.*?)'$/,B=/^"(.*?)"$/,j={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},Y="single-file-ui-element",G="data:,",Z=globalThis.JSON;function J(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)).forEach((s=>{let r,a,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=oe(e,s),s instanceof e.HTMLElement&&o.removeHiddenElements&&(a=(i||s.closest("html > head"))&&H.includes(s.tagName.toUpperCase())||s.closest("details"),a||(r=i||ee(s,l),r&&(s.setAttribute(_,""),n.markedElements.push(s)))),!r)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(F,""),n.markedElements.push(s))}o.removeUnusedFonts&&(K(l,o,n.usedFonts),K(oe(e,s,":first-letter"),o,n.usedFonts),K(oe(e,s,":before"),o,n.usedFonts),K(oe(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(x,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==a){const t={currentSrc:i?G:o.loadDeferredImages&&s.getAttribute(D)||s.currentSrc};if(n.images.push(t),s.setAttribute(C,n.images.length-1),n.markedElements.push(s),s.removeAttribute(D),r=r||oe(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||oe(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=se("padding-left",s),r=se("padding-right",s),a=se("padding-top",s),l=se("padding-bottom",s),g?(d=se("border-left-width",s),c=se("border-right-width",s),u=se("border-top-width",s),m=se("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=oe(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(q,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(P,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==a&&i&&o.removeHiddenElements&&(s.setAttribute(M,""),n.markedElements.push(s));"INPUT"==a&&("password"!=s.type&&(s.setAttribute(L,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(L,s.checked),n.markedElements.push(s)));"TEXTAREA"==a&&(s.setAttribute(L,s.value),n.markedElements.push(s));"SELECT"==a&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(L,""),n.markedElements.push(e))}));"SCRIPT"==a&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(O,""),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)&&X(s);if(d&&!s.classList.contains(Y)){const i={};s.setAttribute(N,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(i);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)i.adoptedStyleSheets=$(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>i.adoptedStyleSheets=e.detail.adoptedStyleSheets;s.addEventListener(A,e),s.dispatchEvent(new CustomEvent(I,{bubbles:!0})),s.removeEventListener(A,e)}}catch(e){}J(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 CustomEvent(v,{bubbles:!0}))}catch(e){}}J(e,t,s,o,n,r),!o.autoSaveExternalSave&&o.removeHiddenElements&&i&&(a||""==s.getAttribute(R)?s.parentElement&&(s.parentElement.setAttribute(R,""),n.markedElements.push(s.parentElement)):r&&(s.setAttribute(S,""),n.markedElements.push(s)))}))}return n}function $(e){return Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n")))}function K(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=Q(n),!t.loadedFonts||t.loadedFonts.find((e=>Q(e.family)==n&&e.style==o))){const t=(i=e.getPropertyValue("font-weight"),j[i.toLowerCase().trim()]||i),r=e.getPropertyValue("font-variant")||"normal",a=[n,t,o,r];s.set(Z.stringify(a),[n,t,o,r])}var i}))}}function X(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 Q(e=""){return function(e){e=e.match(z)?e.replace(z,"$1"):e.replace(B,"$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 ee(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 te(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(),i&&i.cssRules.length==s.sheet.cssRules.length||(s.setAttribute(U,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}catch(e){}})),t}}function se(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function oe(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const ne={LAZY_SRC_ATTRIBUTE_NAME:D,SINGLE_FILE_UI_ELEMENT_CLASS:Y},ie=10,re="attributes",ae=globalThis.browser,le=globalThis.document,de=globalThis.MutationObserver,ce=(e,t,s)=>globalThis.addEventListener(e,t,s),ue=(e,t,s)=>globalThis.removeEventListener(e,t,s),me=new Map;let ge;async function he(e){if(le.documentElement){me.clear();const s=le.body&&le.body.scrollHeight||le.documentElement.scrollHeight,n=le.body&&le.body.scrollWidth||le.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 ge=0,new Promise((async s=>{let n;const r=new Set,l=new de((async t=>{if((t=t.filter((e=>e.type==re))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(ne.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(ne.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await pe(l,e,y),r.size||await fe(l,e,y))}}));async function c(t){await ye("idleTimeout",(async()=>{n?ge<ie&&(ge++,Te("idleTimeout"),await c(Math.max(500,t/2))):(Te("loadTimeout"),Te("maxTimeout"),be(l,e,y))}),t,e.loadDeferredImagesNativeTimeout)}function g(e){const t=e.target;t.removeAttribute(ne.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",g)}async function p(t){n=!0,await pe(l,e,y),await fe(l,e,y),t.detail&&r.add(t.detail)}async function b(t){await pe(l,e,y),await fe(l,e,y),r.delete(t.detail),r.size||await fe(l,e,y)}function y(e){l.disconnect(),ue(u,p),ue(m,b),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await pe(l,e,y),l.observe(le,{subtree:!0,childList:!0,attributes:!0}),ce(u,p),ce(m,b),function(e){e.loadDeferredImagesBlockCookies&&h(new f(i)),e.loadDeferredImagesBlockStorage&&h(new f(d)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(a)),e.loadDeferredImagesKeepZoomLevel?h(new f(o)):h(new f(t))}(e)}))}(e)}}}async function fe(e,t,s){await ye("loadTimeout",(()=>be(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function pe(e,t,s){await ye("maxTimeout",(async()=>{await Te("loadTimeout"),await be(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function be(e,t,o){await Te("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&h(new f(r)),e.loadDeferredImagesBlockStorage&&h(new f(c)),e.loadDeferredImagesDispatchScrollEvent&&h(new f(l)),e.loadDeferredImagesKeepZoomLevel?h(new f(n)):h(new f(s))}(t),await ye("endTimeout",(async()=>{await Te("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function ye(e,t,s,o){if(ae&&ae.runtime&&ae.runtime.sendMessage&&!o){if(!me.get(e)||!me.get(e).pending){const o={callback:t,pending:!0};me.set(e,o);try{await ae.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Ee(e,t,s)}o.pending=!1}}else Ee(e,t,s)}function Ee(e,t,s){const o=me.get(e);o&&globalThis.clearTimeout(o),me.set(e,t),globalThis.setTimeout(t,s)}async function Te(e){if(ae&&ae.runtime&&ae.runtime.sendMessage)try{await ae.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){we(e)}else we(e)}function we(e){const t=me.get(e);me.delete(e),t&&globalThis.clearTimeout(t)}ae&&ae.runtime&&ae.runtime.onMessage&&ae.runtime.onMessage.addListener&&ae.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=me.get(e.type);if(t){me.delete(e.type);try{t.callback()}catch(t){we(e.type)}}}}));const Ie={ON_BEFORE_CAPTURE_EVENT_NAME:"single-file-on-before-capture",ON_AFTER_CAPTURE_EVENT_NAME:"single-file-on-after-capture",WIN_ID_ATTRIBUTE_NAME:"data-single-file-win-id",preProcessDoc:function(e,t,s){e.querySelectorAll("noscript:not(["+V+"])").forEach((e=>{e.setAttribute(V,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(W).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+W+", html > body > "+W);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("data-single-file-invalid-element",""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=J(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=oe(t,e);s&&ee(e,s)&&(e.setAttribute(k,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(E.values()),stylesheets:te(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:$(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("["+V+"]").forEach((e=>{e.textContent=e.getAttribute(V),e.removeAttribute(V)})),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=[S,M,_,F,C,P,q,x,L,N,U,O];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(S),e.removeAttribute(_),e.removeAttribute(R),e.removeAttribute(M),e.removeAttribute(F),e.removeAttribute(C),e.removeAttribute(P),e.removeAttribute(q),e.removeAttribute(x),e.removeAttribute(L),e.removeAttribute(N),e.removeAttribute(U),e.removeAttribute(O),e.removeAttribute(k)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))},getShadowRoot:X},ve="__frameTree__::",Ae='iframe, frame, object[type="text/html"][data]',Se="*",_e="singlefile.frameTree.initRequest",Re="singlefile.frameTree.ackInitRequest",Me="singlefile.frameTree.cleanupRequest",Fe="singlefile.frameTree.initResponse",Ne="*",Ce=5e3,Pe=".",qe=globalThis.window==globalThis.top,xe=globalThis.browser,ke=globalThis.top,Le=globalThis.MessageChannel,De=globalThis.document,Ue=globalThis.JSON;let Ve,Oe=globalThis.sessions;var We,He,ze;function Be(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function je(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,qe||(Ve=globalThis.frameId=e.windowId),Ze(De,e.options,Ve,t),qe||(e.options.userScriptEnabled&&s&&await s(Ie.ON_BEFORE_CAPTURE_EVENT_NAME),Xe({frames:[et(De,globalThis,Ve,e.options,e.scrolling)],sessionId:t,requestedFrameId:De.documentElement.dataset.requestedFrameId&&Ve}),e.options.userScriptEnabled&&s&&await s(Ie.ON_AFTER_CAPTURE_EVENT_NAME),delete De.documentElement.dataset.requestedFrameId)}function Ye(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;Ke(tt(De),e.windowId,t)}}function Ge(e){e.frames.forEach((t=>Je("responseTimeouts",e.sessionId,t.windowId)));const t=Oe.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(Pe).length-e.windowId.split(Pe).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function Ze(e,t,s,o){const n=tt(e);!function(e,t,s,o,n){const i=[];let r;Oe.get(n)?r=Oe.get(n).requestTimeouts:(r={},Oe.set(n,{requestTimeouts:r}));t.forEach(((e,t)=>{const s=o+Pe+t;e.setAttribute(Ie.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),Xe({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+Pe+t;try{Qe(e.contentWindow,{method:_e,windowId:i,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}r[i]=globalThis.setTimeout((()=>Xe({frames:[{windowId:i,processed:!0}],sessionId:n})),Ce)})),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+Pe+t;let a;try{a=e.contentDocument}catch(e){}if(a)try{const t=e.contentWindow;t.stop(),Je("requestTimeouts",n,r),Ze(a,s,r,n),i.push(et(a,t,r,s,e.scrolling))}catch(e){i.push({windowId:r,processed:!0})}})),Xe({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function Je(e,t,s){const o=Oe.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function $e(e,t){const s=Oe.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>Xe({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function Ke(e,t,s){e.forEach(((e,o)=>{const n=t+Pe+o;e.removeAttribute(Ie.WIN_ID_ATTRIBUTE_NAME);try{Qe(e.contentWindow,{method:Me,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+Pe+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{Ke(tt(i),n,s)}catch(e){}}))}function Xe(e){e.method=Fe;try{ke.singlefile.processors.frameTree.initResponse(e)}catch(t){Qe(ke,e,!0)}}function Qe(e,t,s){if(e==ke&&xe&&xe.runtime&&xe.runtime.sendMessage)xe.runtime.sendMessage(t);else if(s){const s=new Le;e.postMessage(ve+Ue.stringify({method:t.method,sessionId:t.sessionId}),Ne,[s.port2]),s.port1.postMessage(t)}else e.postMessage(ve+Ue.stringify(t),Ne)}function et(e,t,s,o,n){const i=Ie.preProcessDoc(e,t,o),r=Ie.serialize(e);Ie.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 tt(e){let t=Array.from(e.querySelectorAll(Ae));return e.querySelectorAll(Se).forEach((e=>{const s=Ie.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Ae)))})),t}Oe||(Oe=globalThis.sessions=new Map),qe&&(Ve="0",xe&&xe.runtime&&xe.runtime.onMessage&&xe.runtime.onMessage.addListener&&xe.runtime.onMessage.addListener((e=>e.method==Fe?(Ge(e),Promise.resolve({})):e.method==Re?(Je("requestTimeouts",e.sessionId,e.windowId),$e(e.sessionId,e.windowId),Promise.resolve({})):void 0))),We="message",He=async e=>{if("string"==typeof e.data&&e.data.startsWith(ve)){e.preventDefault(),e.stopPropagation();const t=Ue.parse(e.data.substring(ve.length));t.method==_e?(e.source&&Qe(e.source,{method:Re,windowId:t.windowId,sessionId:t.sessionId}),qe||(globalThis.stop(),t.options.loadDeferredImages&&he(t.options),await je(t))):t.method==Re?(Je("requestTimeouts",t.sessionId,t.windowId),$e(t.sessionId,t.windowId)):t.method==Me?Ye(t):t.method==Fe&&Oe.get(t.sessionId)&&(e.ports[0].onmessage=e=>Ge(e.data))}},ze=!0,globalThis.addEventListener(We,He,ze),e.TIMEOUT_INIT_REQUEST_MESSAGE=Ce,e.cleanup=function(e){Oe.delete(e),Ye({windowId:Ve,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=Be();return e=Ue.parse(Ue.stringify(e)),new Promise((s=>{Oe.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),je({windowId:Ve,sessionId:t,options:e})}))},e.getSync=function(e){const t=Be();e=Ue.parse(Ue.stringify(e)),Oe.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis._singleFile_waitForUserScript;delete globalThis._singleFile_cleaningUp,qe||(Ve=globalThis.frameId=e.windowId);Ze(De,e.options,Ve,t),qe||(e.options.userScriptEnabled&&s&&s(Ie.ON_BEFORE_CAPTURE_EVENT_NAME),Xe({frames:[et(De,globalThis,Ve,e.options,e.scrolling)],sessionId:t,requestedFrameId:De.documentElement.dataset.requestedFrameId&&Ve}),e.options.userScriptEnabled&&s&&s(Ie.ON_AFTER_CAPTURE_EVENT_NAME),delete De.documentElement.dataset.requestedFrameId)}({windowId:Ve,sessionId:t,options:e});const s=Oe.get(t).frames;return s.sessionId=t,s},e.initResponse=Ge,Object.defineProperty(e,"__esModule",{value:!0})}));
|