| 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,T=globalThis.JSON;let y;y=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,y.set(T.stringify(s),t)})),h("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,y.delete(T.stringify(s))})),h("single-file-clear-fonts",(()=>y=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=["SCRIPT","NOSCRIPT","META","LINK","TEMPLATE"],$=/^'(.*?)'$/,X=/^"(.*?)"$/,Q={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},ee="single-file-ui-element",te="single-file-infobar",se="data:,",oe=globalThis.JSON,ne=globalThis.CustomEvent;function ie(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=ge(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||ce(s,l),r&&!K.includes(s.tagName.toUpperCase())&&(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&&(ae(l,o,n.usedFonts),ae(ge(e,s,":first-letter"),o,n.usedFonts),ae(ge(e,s,":before"),o,n.usedFonts),ae(ge(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?se: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||ge(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||ge(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=ue("padding-left",s),r=ue("padding-right",s),a=ue("padding-top",s),l=ue("padding-bottom",s),g?(d=ue("border-left-width",s),c=ue("border-right-width",s),m=ue("border-top-width",s),u=ue("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=ge(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)&&le(s);if(d&&!s.classList.contains(ee)&&s.tagName.toLowerCase()!=te){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=re(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>i.adoptedStyleSheets=e.detail.adoptedStyleSheets;s.addEventListener(M,e),s.dispatchEvent(new ne(_,{bubbles:!0})),s.removeEventListener(M,e)}}catch(e){}ie(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 ne(P,{bubbles:!0}))}catch(e){}}ie(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 re(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function ae(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=de(n),!t.loadedFonts||t.loadedFonts.find((e=>de(e.family)==n&&e.style==o))){const t=(i=e.getPropertyValue("font-weight"),Q[i.toLowerCase().trim()]||i),r=e.getPropertyValue("font-variant")||"normal",a=[n,t,o,r];s.set(oe.stringify(a),[n,t,o,r])}var i}))}}function le(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 de(e=""){return function(e){e=e.match($)?e.replace($,"$1"):e.replace(X,"$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 ce(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 me(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 ue(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function ge(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const he={LAZY_SRC_ATTRIBUTE_NAME:z,SINGLE_FILE_UI_ELEMENT_CLASS:ee},fe=10,pe="attributes",be=globalThis.browser,Ee=globalThis.document,Te=globalThis.MutationObserver,ye=(e,t,s)=>globalThis.addEventListener(e,t,s),we=(e,t,s)=>globalThis.removeEventListener(e,t,s),Ie=new Map;let Ae;async function ve(e){if(Ee.documentElement){Ie.clear();const s=Ee.body?Math.max(Ee.body.scrollHeight,Ee.documentElement.scrollHeight):Ee.documentElement.scrollHeight,n=Ee.body?Math.max(Ee.body.scrollWidth,Ee.documentElement.scrollWidth):Ee.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 Ae=0,new Promise((async s=>{let n;const r=new Set,l=new Te((async t=>{if((t=t.filter((e=>e.type==pe))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(he.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(he.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Re(l,e,E),r.size||await Se(l,e,E))}}));async function c(t){await Me("idleTimeout",(async()=>{n?Ae<fe&&(Ae++,Ne("idleTimeout"),await c(Math.max(500,t/2))):(Ne("loadTimeout"),Ne("maxTimeout"),_e(l,e,E))}),t,e.loadDeferredImagesNativeTimeout)}function g(e){const t=e.target;t.removeAttribute(he.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",g)}async function h(t){n=!0,await Re(l,e,E),await Se(l,e,E),t.detail&&r.add(t.detail)}async function b(t){await Re(l,e,E),await Se(l,e,E),r.delete(t.detail),r.size||await Se(l,e,E)}function E(e){l.disconnect(),we(m,h),we(u,b),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await Re(l,e,E),l.observe(Ee,{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 Se(e,t,s){await Me("loadTimeout",(()=>_e(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Re(e,t,s){await Me("maxTimeout",(async()=>{await Ne("loadTimeout"),await _e(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function _e(e,t,o){await Ne("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 Me("endTimeout",(async()=>{await Ne("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Me(e,t,s,o){if(be&&be.runtime&&be.runtime.sendMessage&&!o){if(!Ie.get(e)||!Ie.get(e).pending){const o={callback:t,pending:!0};Ie.set(e,o);try{await be.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Pe(e,t,s)}o.pending=!1}}else Pe(e,t,s)}function Pe(e,t,s){const o=Ie.get(e);o&&globalThis.clearTimeout(o),Ie.set(e,t),globalThis.setTimeout(t,s)}async function Ne(e){if(be&&be.runtime&&be.runtime.sendMessage)try{await be.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){Ce(e)}else Ce(e)}function Ce(e){const t=Ie.get(e);Ie.delete(e),t&&globalThis.clearTimeout(t)}be&&be.runtime&&be.runtime.onMessage&&be.runtime.onMessage.addListener&&be.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=Ie.get(e.type);if(t){Ie.delete(e.type);try{t.callback()}catch(t){Ce(e.type)}}}}));const Fe={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=ie(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=ge(t,e);s&&ce(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:me(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:re(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:le},xe='iframe, frame, object[type="text/html"][data]',qe="*",Le="singlefile.frameTree.initRequest",ke="singlefile.frameTree.ackInitRequest",Ue="singlefile.frameTree.cleanupRequest",De="singlefile.frameTree.initResponse",Oe="*",Ve=5e3,We=".",He=globalThis.window==globalThis.top,ze=globalThis.browser,Be=globalThis.top,je=globalThis.MessageChannel,Ye=globalThis.document,Ge=globalThis.JSON;let Ze,Je=globalThis.sessions;var Ke,$e,Xe;function Qe(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function et(e){const t=e.sessionId,s=globalThis[Fe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,He||(Ze=globalThis.frameId=e.windowId),ot(Ye,e.options,Ze,t),He||(e.options.userScriptEnabled&&s&&await s(Fe.ON_BEFORE_CAPTURE_EVENT_NAME),at({frames:[dt(Ye,globalThis,Ze,e.options,e.scrolling)],sessionId:t,requestedFrameId:Ye.documentElement.dataset.requestedFrameId&&Ze}),e.options.userScriptEnabled&&s&&await s(Fe.ON_AFTER_CAPTURE_EVENT_NAME),delete Ye.documentElement.dataset.requestedFrameId)}function tt(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;rt(ct(Ye),e.windowId,t)}}function st(e){e.frames.forEach((t=>nt("responseTimeouts",e.sessionId,t.windowId)));const t=Je.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(We).length-e.windowId.split(We).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function ot(e,t,s,o){const n=ct(e);!function(e,t,s,o,n){const i=[];let r;Je.get(n)?r=Je.get(n).requestTimeouts:(r={},Je.set(n,{requestTimeouts:r}));t.forEach(((e,t)=>{const s=o+We+t;e.setAttribute(Fe.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})})),at({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const i=o+We+t;try{lt(e.contentWindow,{method:Le,windowId:i,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}r[i]=globalThis.setTimeout((()=>at({frames:[{windowId:i,processed:!0}],sessionId:n})),Ve)})),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+We+t;let a;try{a=e.contentDocument}catch(e){}if(a)try{const t=e.contentWindow;t.stop(),nt("requestTimeouts",n,r),ot(a,s,r,n),i.push(dt(a,t,r,s,e.scrolling))}catch(e){i.push({windowId:r,processed:!0})}})),at({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function nt(e,t,s){const o=Je.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function it(e,t){const s=Je.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>at({frames:[{windowId:t,processed:!0}],sessionId:e})),1e4))}function rt(e,t,s){e.forEach(((e,o)=>{const n=t+We+o;e.removeAttribute(Fe.WIN_ID_ATTRIBUTE_NAME);try{lt(e.contentWindow,{method:Ue,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+We+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{rt(ct(i),n,s)}catch(e){}}))}function at(e){e.method=De;try{Be.singlefile.processors.frameTree.initResponse(e)}catch(t){lt(Be,e,!0)}}function lt(e,t,s){if(e==Be&&ze&&ze.runtime&&ze.runtime.sendMessage)ze.runtime.sendMessage(t);else if(s){const s=new je;e.postMessage(v+Ge.stringify({method:t.method,sessionId:t.sessionId}),Oe,[s.port2]),s.port1.postMessage(t)}else e.postMessage(v+Ge.stringify(t),Oe)}function dt(e,t,s,o,n){const i=Fe.preProcessDoc(e,t,o),r=Fe.serialize(e);Fe.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 ct(e){let t=Array.from(e.querySelectorAll(xe));return e.querySelectorAll(qe).forEach((e=>{const s=Fe.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(xe)))})),t}Je||(Je=globalThis.sessions=new Map),He&&(Ze="0",ze&&ze.runtime&&ze.runtime.onMessage&&ze.runtime.onMessage.addListener&&ze.runtime.onMessage.addListener((e=>e.method==De?(st(e),Promise.resolve({})):e.method==ke?(nt("requestTimeouts",e.sessionId,e.windowId),it(e.sessionId,e.windowId),Promise.resolve({})):void 0))),Ke="message",$e=async e=>{if("string"==typeof e.data&&e.data.startsWith(v)){e.preventDefault(),e.stopPropagation();const t=Ge.parse(e.data.substring(v.length));t.method==Le?(e.source&<(e.source,{method:ke,windowId:t.windowId,sessionId:t.sessionId}),He||(globalThis.stop(),t.options.loadDeferredImages&&ve(t.options),await et(t))):t.method==ke?(nt("requestTimeouts",t.sessionId,t.windowId),it(t.sessionId,t.windowId)):t.method==Ue?tt(t):t.method==De&&Je.get(t.sessionId)&&(e.ports[0].onmessage=e=>st(e.data))}},Xe=!0,globalThis.addEventListener(Ke,$e,Xe),e.TIMEOUT_INIT_REQUEST_MESSAGE=Ve,e.cleanup=function(e){Je.delete(e),tt({windowId:Ze,sessionId:e,options:{sessionId:e}})},e.getAsync=function(e){const t=Qe();return e=Ge.parse(Ge.stringify(e)),new Promise((s=>{Je.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),et({windowId:Ze,sessionId:t,options:e})}))},e.getSync=function(e){const t=Qe();e=Ge.parse(Ge.stringify(e)),Je.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Fe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,He||(Ze=globalThis.frameId=e.windowId);ot(Ye,e.options,Ze,t),He||(e.options.userScriptEnabled&&s&&s(Fe.ON_BEFORE_CAPTURE_EVENT_NAME),at({frames:[dt(Ye,globalThis,Ze,e.options,e.scrolling)],sessionId:t,requestedFrameId:Ye.documentElement.dataset.requestedFrameId&&Ze}),e.options.userScriptEnabled&&s&&s(Fe.ON_AFTER_CAPTURE_EVENT_NAME),delete Ye.documentElement.dataset.requestedFrameId)}({windowId:Ze,sessionId:t,options:e});const s=Je.get(t).frames;return s.sessionId=t,s},e.initResponse=st,Object.defineProperty(e,"__esModule",{value:!0})}));
|