| 1 |
- !function(){"use strict";const t=8388608,e=0,n=[e],o=Symbol(),a=new TextEncoder,r=new TextDecoder,i=new Array(256);let s=0;function c(t,e,o,a){if(void 0===a){if(s++,!(i.length-s>=n.length))throw new Error("Reached maximum number of custom types");i[i.length-s]={serialize:t,parse:e,test:o}}else i[a]={serialize:t,parse:e,test:o}}async function l(t,e){const n=f(t,e);let o=new Uint8Array([]);for await(const t of n){const e=o;o=new Uint8Array(e.length+t.length),o.set(e,0),o.set(t,e.length)}return o}c((async function(t,e){const n=t.objects.indexOf(e);await m(t,n)}),(async function(t){const e=await S(t);return new b(e,t)}),R,e),c(null,(function(){return{}}),D),c(p,x,k),c(h,C,(function(t){return"string"==typeof t})),c(w,(async function(t){const e=await S(t),n=await t.consume(8*e);return new Float64Array(n.buffer)}),(function(t){return t instanceof Float64Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(4*e);return new Float32Array(n.buffer)}),(function(t){return t instanceof Float32Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(4*e);return new Uint32Array(n.buffer)}),(function(t){return t instanceof Uint32Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(4*e);return new Int32Array(n.buffer)}),(function(t){return t instanceof Int32Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(2*e);return new Uint16Array(n.buffer)}),(function(t){return t instanceof Uint16Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(2*e);return new Int16Array(n.buffer)}),(function(t){return t instanceof Int16Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(e);return new Uint8ClampedArray(n.buffer)}),(function(t){return t instanceof Uint8ClampedArray})),c(w,(async function(t){const e=await S(t);return await t.consume(e)}),(function(t){return t instanceof Uint8Array})),c(w,(async function(t){const e=await S(t),n=await t.consume(e);return new Int8Array(n.buffer)}),(function(t){return t instanceof Int8Array})),c((async function(t,e){await m(t,e.byteLength),await t.append(new Uint8Array(e))}),(async function(t){const e=await S(t);return(await t.consume(e)).buffer}),(function(t){return t instanceof ArrayBuffer})),c(y,I,N),c((async function(t,e){const n=new Uint8Array(new Uint32Array([e]).buffer);await t.append(n)}),(async function(t){const e=await t.consume(4);return new Uint32Array(e.buffer)[0]}),(function(t){return T(t)&&t>=0&&t<=4294967295})),c((async function(t,e){const n=new Uint8Array(new Int32Array([e]).buffer);await t.append(n)}),(async function(t){const e=await t.consume(4);return new Int32Array(e.buffer)[0]}),(function(t){return T(t)&&t>=-2147483648&&t<=2147483647})),c((async function(t,e){const n=new Uint8Array(new Uint16Array([e]).buffer);await t.append(n)}),(async function(t){const e=await t.consume(2);return new Uint16Array(e.buffer)[0]}),(function(t){return T(t)&&t>=0&&t<=65535})),c((async function(t,e){const n=new Uint8Array(new Int16Array([e]).buffer);await t.append(n)}),(async function(t){const e=await t.consume(2);return new Int16Array(e.buffer)[0]}),(function(t){return T(t)&&t>=-32768&&t<=32767})),c((async function(t,e){const n=new Uint8Array([e]);await t.append(n)}),(async function(t){const e=await t.consume(1);return new Uint8Array(e.buffer)[0]}),(function(t){return T(t)&&t>=0&&t<=255})),c((async function(t,e){const n=new Uint8Array(new Int8Array([e]).buffer);await t.append(n)}),(async function(t){const e=await t.consume(1);return new Int8Array(e.buffer)[0]}),(function(t){return T(t)&&t>=-128&&t<=127})),c(null,(function(){return}),(function(t){return void 0===t})),c(null,(function(){return null}),(function(t){return null===t})),c(null,(function(){return NaN}),(function(t){return Number.isNaN(t)})),c(g,L,(function(t){return"boolean"==typeof t})),c((async function(t,e){await h(t,e.description)}),(async function(t){const e=await C(t);return Symbol(e)}),O),c(null,(function(){return o}),P),c((async function(t,e){const n=e.entries();await m(t,e.size);for(const[e,o]of n)await m(t,e),await m(t,o)}),(async function(t){const e=await S(t),n=new Map;e&&await async function o(a=0){const r=await S(t),i=await S(t);t.setObject([r,i],((t,e)=>n.set(t,e))),a<e-1&&await o(a+1)}();return n}),(function(t){return t instanceof Map})),c((async function(t,e){await m(t,e.size);for(const n of e)await m(t,n)}),(async function(t){const e=await S(t),n=new Set;e&&await async function o(a=0){const r=await S(t);t.setObject([r],(t=>n.add(t))),a<e-1&&await o(a+1)}();return n}),(function(t){return t instanceof Set})),c((async function(t,e){await y(t,e.getTime())}),(async function(t){const e=await I(t);return new Date(e)}),(function(t){return t instanceof Date})),c((async function(t,e){await h(t,e.message),await h(t,e.stack)}),(async function(t){const e=await C(t),n=await C(t),o=new Error(e);return o.stack=n,o}),(function(t){return t instanceof Error})),c((async function(t,e){await h(t,e.source),await h(t,e.flags)}),(async function(t){const e=await C(t),n=await C(t);return new RegExp(e,n)}),(function(t){return t instanceof RegExp})),c((async function(t,e){await h(t,e.valueOf())}),(async function(t){return new String(await C(t))}),(function(t){return t instanceof String})),c((async function(t,e){await y(t,e.valueOf())}),(async function(t){return new Number(await I(t))}),(function(t){return t instanceof Number})),c((async function(t,e){await g(t,e.valueOf())}),(async function(t){return new Boolean(await L(t))}),(function(t){return t instanceof Boolean}));class u{constructor(t,e){this.stream=new d(t,e),this.objects=[]}append(t){return this.stream.append(t)}flush(){return this.stream.flush()}addObject(t){this.objects.push(B(t)&&!R(t,this)?t:void 0)}}class d{constructor(t,e){this.offset=0,this.appendData=t,this.value=new Uint8Array(e)}async append(t){if(this.offset+t.length>this.value.length){const e=this.value.length-this.offset;await this.append(t.subarray(0,e)),await this.appendData({value:this.value}),this.offset=0,await this.append(t.subarray(e))}else this.value.set(t,this.offset),this.offset+=t.length}async flush(){this.offset&&await this.appendData({value:this.value.subarray(0,this.offset),done:!0})}}function f(e,{chunkSize:n=t}={}){let o,a,r,i,s,c;return{[Symbol.asyncIterator]:()=>({next:()=>i?{done:i}:async function(){c?c():l().catch((()=>{}));s=new Promise((t=>c=t));const t=await async function(){const{value:t,done:e}=await a;i=e,e||d();return t}();return{value:t}}(),return:()=>({done:!0})})};async function l(){d(),o=new u(f,n),await m(o,e),await o.flush()}function d(){a=new Promise((t=>r=t))}async function f(t){r(t),await s}}async function m(t,n){const o=i.findIndex((({test:e}={})=>e&&e(n,t)));t.addObject(n),await t.append(new Uint8Array([o]));const a=i[o].serialize;a&&await a(t,n),o!=e&&D(n)&&(await async function(t,e){const n=Object.getOwnPropertySymbols(e),o=n.map((t=>[t,e[t]]));await p(t,o)}(t,n),await async function(t,e){let n=Object.entries(e);k(e)&&(n=n.filter((([t])=>!T(Number(t)))));await m(t,n.length);for(const[e,o]of n)await h(t,e),await m(t,o)}(t,n))}async function p(t,e){await m(t,e.length);const n=Object.keys(e).filter((t=>T(Number(t)))).map((t=>Number(t)));let a=0,r=n[a];for(const[i,s]of e.entries())r==i?(r=n[++a],await m(t,s)):await m(t,o)}async function h(t,e){const n=a.encode(e);await m(t,n.length),await t.append(n)}async function w(t,e){await m(t,e.length),await t.append(new Uint8Array(e.buffer))}async function y(t,e){const n=new Uint8Array(new Float64Array([e]).buffer);await t.append(n)}async function g(t,e){const n=new Uint8Array([Number(e)]);await t.append(n)}class b{constructor(t,e){this.index=t,this.data=e}getObject(){return this.data.objects[this.index]}}class A{constructor(t){this.stream=new v(t),this.objects=[],this.setters=[]}consume(t){return this.stream.consume(t)}getObjectId(){const t=this.objects.length;return this.objects.push(void 0),t}resolveObject(t,e){B(e)&&!U(e)&&(this.objects[t]=e)}setObject(t,e){this.setters.push({functionArguments:t,setterFunction:e})}executeSetters(){this.setters.forEach((({functionArguments:t,setterFunction:e})=>{e(...t.map((t=>U(t)?t.getObject():t)))}))}}class v{constructor(t){this.offset=0,this.value=new Uint8Array(0),this.consumeData=t}async consume(t){if(this.offset+t>this.value.length){const e=this.value.subarray(this.offset,this.value.length),n=await this.consumeData();return e.length+n.length!=this.value.length&&(this.value=new Uint8Array(e.length+n.length)),this.value.set(e),this.value.set(n,e.length),this.offset=0,this.consume(t)}{const e=this.value.slice(this.offset,this.offset+t);return this.offset+=e.length,e}}}function E(){let t,e,n,o,a,r;return{next:async e=>e?async function(e){a?await a:async function(){let e;o=new Promise((t=>e=t)),t=new A(s),i();const n=await S(t);t.executeSetters(),e(n)}().catch((()=>{}));return function(){a=new Promise((t=>r=t))}(),n(e),{done:!1}}(e):{value:await o,done:!0},return:()=>({done:!0})};function i(){e=new Promise((t=>n=t))}async function s(){const t=await e;return i(),r&&r(),t}}async function S(t){const n=(await t.consume(1))[0],o=i[n].parse,a=t.getObjectId(),r=await o(t);return n!=e&&D(r)&&(await async function(t,e){const n=await x(t);t.setObject([n],(t=>t.forEach((([t,n])=>e[t]=n))))}(t,r),await async function(t,e){const n=await S(t);n&&await o();async function o(a=0){const r=await C(t),i=await S(t);t.setObject([i],(t=>e[r]=t)),a<n-1&&await o(a+1)}}(t,r)),t.resolveObject(a,r),r}async function x(t){const e=await S(t),n=new Array(e);return e&&await async function o(a=0){const r=await S(t);P(r)||t.setObject([r],(t=>n[a]=t));a<e-1&&await o(a+1)}(),n}async function C(t){const e=await S(t),n=await t.consume(e);return r.decode(n)}async function I(t){const e=await t.consume(8);return new Float64Array(e.buffer)[0]}async function L(t){const e=await t.consume(1);return Boolean(e[0])}function R(t,e){return D(t)&&e.objects.includes(t)}function U(t){return t instanceof b}function D(t){return t===Object(t)}function k(t){return"number"==typeof t.length}function P(t){return t===o}function N(t){return"number"==typeof t}function T(t){return N(t)&&Number.isInteger(t)}function O(t){return"symbol"==typeof t}function B(t){return D(t)||O(t)}const j=33554432;async function M(t,e){e.includeBOM&&(t.content="\ufeff"+t.content);const n={method:"downloads.download",taskId:e.taskId,insertTextBody:e.insertTextBody,confirmFilename:e.confirmFilename,filenameConflictAction:e.filenameConflictAction,filename:t.filename,saveToClipboard:e.saveToClipboard,saveToGDrive:e.saveToGDrive,saveWithWebDAV:e.saveWithWebDAV,webDAVURL:e.webDAVURL,webDAVUser:e.webDAVUser,webDAVPassword:e.webDAVPassword,saveToGitHub:e.saveToGitHub,githubToken:e.githubToken,githubUser:e.githubUser,githubRepository:e.githubRepository,githubBranch:e.githubBranch,saveWithCompanion:e.saveWithCompanion,forceWebAuthFlow:e.forceWebAuthFlow,filenameReplacementCharacter:e.filenameReplacementCharacter,openEditor:e.openEditor,openSavedPage:e.openSavedPage,compressHTML:e.compressHTML,backgroundSave:e.backgroundSave,bookmarkId:e.bookmarkId,replaceBookmarkURL:e.replaceBookmarkURL,applySystemTheme:e.applySystemTheme,defaultEditorMode:e.defaultEditorMode,includeInfobar:e.includeInfobar,warnUnsavedPage:e.warnUnsavedPage,createRootDirectory:e.createRootDirectory,selfExtractingArchive:e.selfExtractingArchive,extractDataFromPage:e.extractDataFromPage,insertCanonicalLink:e.insertCanonicalLink,insertMetaNoIndex:e.insertMetaNoIndex,password:e.password,compressContent:e.compressContent,foregroundSave:e.foregroundSave};if(e.compressContent){const o=URL.createObjectURL(new Blob([await l(t)],{type:"application/octet-stream"}));n.blobURL=o;const a=await browser.runtime.sendMessage(n);if(URL.revokeObjectURL(o),a.error){n.blobURL=null,n.pageData=t;const e=f(n);for await(const t of e)await browser.runtime.sendMessage({method:"downloads.download",compressContent:!0,data:Array.from(t)});await browser.runtime.sendMessage({method:"downloads.download",compressContent:!0})}e.backgroundSave&&await browser.runtime.sendMessage({method:"downloads.end",taskId:e.taskId})}else{if(e.backgroundSave||e.openEditor||e.saveToGDrive||e.saveToGitHub||e.saveWithCompanion||e.saveWithWebDAV){const e=URL.createObjectURL(new Blob([t.content],{type:"text/html"}));n.blobURL=e;const o=await browser.runtime.sendMessage(n);if(URL.revokeObjectURL(e),o.error){n.blobURL=null;for(let e=0;e*j<t.content.length;e++)n.truncated=t.content.length>j,n.truncated?(n.finished=(e+1)*j>t.content.length,n.content=t.content.substring(e*j,(e+1)*j)):n.content=t.content,await browser.runtime.sendMessage(n)}}else e.saveToClipboard?function(t){const e="copy";function n(e){e.clipboardData.setData("text/html",t.content),e.clipboardData.setData("text/plain",t.content),e.preventDefault()}document.addEventListener(e,n),document.execCommand(e),document.removeEventListener(e,n)}(t):await async function(t){if(t.filename&&t.filename.length){const e=document.createElement("a");e.download=t.filename,e.href=URL.createObjectURL(new Blob([t.content],{type:"text/html"})),e.dispatchEvent(new MouseEvent("click")),setTimeout((()=>URL.revokeObjectURL(e.href)),1e3)}return new Promise((t=>setTimeout(t,1)))}(t),e.openSavedPage&&open(URL.createObjectURL(new Blob([t.content],{type:"text/html"}))),browser.runtime.sendMessage({method:"ui.processEnd"});await browser.runtime.sendMessage({method:"downloads.end",taskId:e.taskId,hash:t.hash,woleetKey:e.woleetKey})}}const F="single-file-request-fetch",W="single-file-ack-fetch",q="single-file-response-fetch",H="Host fetch error (SingleFile)",z=2500,G=Boolean(window.wrappedJSObject),V=(t,e,n)=>window.addEventListener(t,e,n),_=t=>window.dispatchEvent(t),X=(t,e,n)=>window.removeEventListener(t,e,n),Q=(t,e)=>window.fetch(t,e);let Z=0,J=new Map;async function K(t){const e=await browser.runtime.sendMessage(t);if(!e||e.error)throw new Error(e&&e.error&&e.error.toString());return e}browser.runtime.onMessage.addListener((t=>"singlefile.fetchFrame"==t.method&&window.frameId&&window.frameId==t.frameId?async function(t){try{const e=await Q(t.url,{cache:"force-cache",headers:t.headers});return{status:e.status,headers:[...e.headers],array:Array.from(new Uint8Array(await e.arrayBuffer()))}}catch(t){return{error:t&&t.toString()}}}(t):"singlefile.fetchResponse"==t.method?async function(t){const e=J.get(t.requestId);e&&(t.error?(e.reject(new Error(t.error)),J.delete(t.requestId)):(t.truncated&&(e.array?e.array=e.array.concat(t.array):(e.array=t.array,J.set(t.requestId,e)),t.finished&&(t.array=e.array)),t.truncated&&!t.finished||(e.resolve({status:t.status,headers:{get:e=>t.headers&&t.headers[e]},arrayBuffer:async()=>new Uint8Array(t.array).buffer}),J.delete(t.requestId))));return{}}(t):void 0));const Y=globalThis.singlefile,$=Y.helper.SELECTED_CONTENT_ATTRIBUTE_NAME,tt="singlefile-mask",et="singlefile-mask-content",nt="singlefile-progress-bar",ot="singlefile-progress-bar-content",at="single-file-selection-zone",rt="singlefile-logs-window",it="singlefile-logs",st="singlefile-logs-line",ct="singlefile-logs-line-text",lt="singlefile-logs-line-icon",ut=Y.helper.SINGLE_FILE_UI_ELEMENT_CLASS,dt=8,ft=browser.i18n.getMessage("logPanelDeferredImages"),mt=browser.i18n.getMessage("logPanelFrameContents"),pt=browser.i18n.getMessage("logPanelStep"),ht=browser.i18n.getMessage("logPanelWidth"),wt=new Set(Array.from(getComputedStyle(document.documentElement)));let yt,gt;function bt(t,e){return prompt(t,e)}function At(t){if(!document.querySelector(tt)&&(t.logsEnabled&&document.documentElement.appendChild(gt),t.shadowEnabled)){const e=function(){try{let t=document.querySelector(tt);if(!t){t=Nt(tt,document.documentElement);const e=t.attachShadow({mode:"open"}),n=document.createElement("style");n.textContent=`\n\t\t\t\t@keyframes single-file-progress { \n\t\t\t\t\t0% { \n\t\t\t\t\t\tleft: -50px;\n\t\t\t\t\t} \n\t\t\t\t\t100% { \n\t\t\t\t\t\tleft: 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t.${nt} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: 0;\n\t\t\t\t\tleft: 0;\n\t\t\t\t\twidth: 0;\n\t\t\t\t\theight: 8px;\n\t\t\t\t\tz-index: 2147483646;\n\t\t\t\t\topacity: .5;\n\t\t\t\t\toverflow: hidden;\t\t\t\t\t\n\t\t\t\t\ttransition: width 200ms ease-in-out;\n\t\t\t\t}\n\t\t\t\t.${ot} {\n\t\t\t\t\tposition: absolute;\n\t\t\t\t\tleft: 0;\n\t\t\t\t\tanimation: single-file-progress 3s linear infinite reverse;\n\t\t\t\t\tbackground: \n\t\t\t\t\t\twhite \n\t\t\t\t\t\tlinear-gradient(-45deg, rgba(0, 0, 0, 0.075) 25%, \n\t\t\t\t\t\t\ttransparent 25%, \n\t\t\t\t\t\t\ttransparent 50%, \n\t\t\t\t\t\t\trgba(0, 0, 0, 0.075) 50%, \n\t\t\t\t\t\t\trgba(0, 0, 0, 0.075) 75%, \n\t\t\t\t\t\t\ttransparent 75%, transparent)\n\t\t\t\t\t\trepeat scroll 0% 0% / 50px 50px padding-box border-box;\n\t\t\t\t\twidth: calc(100% + 50px);\n\t\t\t\t\theight: 100%;\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t.${et} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: 0;\n\t\t\t\t\tleft: 0;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\theight: 100%;\n\t\t\t\t\tz-index: 2147483646;\n\t\t\t\t\topacity: 0;\n\t\t\t\t\tbackground-color: black;\n\t\t\t\t\ttransition: opacity 250ms;\n\t\t\t\t}\n\t\t\t`,e.appendChild(n);let o=document.createElement("div");o.classList.add(et),e.appendChild(o),t.offsetWidth,o.style.setProperty("opacity",.3),t.offsetWidth}return t}catch(t){}}();t.progressBarEnabled&&function(t){try{if(!t.shadowRoot.querySelector("."+nt)){let e=document.createElement("div");e.classList.add(nt),t.shadowRoot.appendChild(e);const n=document.createElement("div");n.classList.add(ot),e.appendChild(n)}}catch(t){}}(e)}}function vt(){const t=document.querySelector(tt);t&&t.remove(),gt.remove(),Ut()}function Et(t,e,n){n.shadowEnabled&&n.progressBarEnabled&&function(t,e){try{const n=document.querySelector(tt);if(n){const o=n.shadowRoot.querySelector("."+nt);if(o&&e){const n=Math.floor(t/e*100)+"%";o.style.getPropertyValue("width")!=n&&(o.style.setProperty("width",n),o.offsetWidth)}}}catch(t){}}(t,e)}function St(){let t;const e=[],n=getSelection();for(let o=0;o<n.rangeCount;o++){let a=n.getRangeAt(o);if(a&&a.commonAncestorContainer){const n=document.createTreeWalker(a.commonAncestorContainer);let o=!1,r=!1;for(;!r;)(o||n.currentNode==a.startContainer||n.currentNode==a.endContainer)&&(o=!0,a.startContainer==a.endContainer&&a.startOffset==a.endOffset||(t=!0,"A"==n.currentNode.tagName&&n.currentNode.href&&e.push(n.currentNode.href))),n.currentNode==a.endContainer?r=!0:n.nextNode();t&&n.currentNode==a.endContainer&&n.currentNode.querySelectorAll&&n.currentNode.querySelectorAll("*").forEach((t=>{"A"==t.tagName&&t.href&&e.push(n.currentNode.href)}))}}return Array.from(new Set(e))}async function xt(t){let e=Ct();return e||t?e:(e=await new Promise((t=>{let e=[];function n(t){e=[],s(),t.preventDefault()}function o(t){const e=function(t){let e,n=t.target,o=n.getBoundingClientRect();for(e=Pt("floor",n,t.clientX-o.left,kt(n,"left")),e==n&&(e=Pt("ceil",n,o.left+o.width-t.clientX,kt(n,"right"))),e==n&&(e=Pt("floor",n,t.clientY-o.top,kt(n,"top"))),e==n&&(e=Pt("ceil",n,o.top+o.height-t.clientY,kt(n,"bottom"))),n=e;n&&n.clientWidth<=dt&&n.clientHeight<=dt;)n=n.parentElement;return n}(t);var n;e&&(yt=e,n=e,requestAnimationFrame((()=>{const t=Rt(),e=n.getBoundingClientRect(),o=document.scrollingElement||document.documentElement;t.style.setProperty("top",o.scrollTop+e.top-10+"px"),t.style.setProperty("left",o.scrollLeft+e.left-10+"px"),t.style.setProperty("width",e.width+20+"px"),t.style.setProperty("height",e.height+20+"px")})))}function a(t){t.preventDefault(),t.stopPropagation(),0==t.button?s(yt,t.ctrlKey):i()}function r(t){"Escape"==t.key&&i()}function i(){e.length&&getSelection().removeAllRanges(),e=[],l()}function s(t,e){if(t){e||u();const n=document.createRange();n.selectNodeContents(t),c(),getSelection().addRange(n),d(),e||l()}else l()}function c(){const t=getSelection();for(let e=t.rangeCount-1;e>=0;e--){const n=t.getRangeAt(e);n.startOffset==n.endOffset&&(t.removeRange(n),e--)}}function l(){Rt().remove(),removeEventListener("mousemove",o,!0),removeEventListener("click",a,!0),removeEventListener("keyup",r,!0),yt=null,t(Boolean(e.length)),setTimeout((()=>document.removeEventListener("contextmenu",n,!0)),0)}function u(){getSelection().removeAllRanges(),e.forEach((t=>getSelection().addRange(t)))}function d(){e=[];for(let t=0;t<getSelection().rangeCount;t++){const n=getSelection().getRangeAt(t);e.push(n)}}addEventListener("mousemove",o,!0),addEventListener("click",a,!0),addEventListener("keyup",r,!0),document.addEventListener("contextmenu",n,!0),getSelection().removeAllRanges()})),e?Ct():void 0)}function Ct(){const t=getSelection();let e;for(let n=0;n<t.rangeCount;n++){let o=t.getRangeAt(n);if(o&&o.commonAncestorContainer){const t=document.createTreeWalker(o.commonAncestorContainer);let n=!1,a=!1;for(;!a;)(n||t.currentNode==o.startContainer||t.currentNode==o.endContainer)&&(n=!0,o.startContainer==o.endContainer&&o.startOffset==o.endOffset||(e=!0,It(t.currentNode))),e&&t.currentNode==o.startContainer&&Lt(t.currentNode),t.currentNode==o.endContainer?a=!0:t.nextNode();e&&t.currentNode==o.endContainer&&t.currentNode.querySelectorAll&&t.currentNode.querySelectorAll("*").forEach((t=>It(t)))}}return e}function It(t){(t.nodeType==Node.ELEMENT_NODE?t:t.parentElement).setAttribute($,"")}function Lt(t){t.parentElement&&(It(t),Lt(t.parentElement))}function Rt(){let t=document.querySelector(at);return t||(t=Nt(at,document.body),t.style.setProperty("box-sizing","border-box","important"),t.style.setProperty("background-color","#3ea9d7","important"),t.style.setProperty("border","10px solid #0b4892","important"),t.style.setProperty("border-radius","2px","important"),t.style.setProperty("opacity",".25","important"),t.style.setProperty("pointer-events","none","important"),t.style.setProperty("position","absolute","important"),t.style.setProperty("transition","all 100ms","important"),t.style.setProperty("cursor","pointer","important"),t.style.setProperty("z-index","2147483647","important"),t.style.removeProperty("border-inline-end"),t.style.removeProperty("border-inline-start"),t.style.removeProperty("inline-size"),t.style.removeProperty("block-size"),t.style.removeProperty("inset-block-start"),t.style.removeProperty("inset-inline-end"),t.style.removeProperty("inset-block-end"),t.style.removeProperty("inset-inline-start")),t}function Ut(){try{if(gt=document.querySelector(rt),!gt){gt=Nt(rt);const t=gt.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=`\n\t\t\t\t@keyframes single-file-pulse { \n\t\t\t\t\t0% { \n\t\t\t\t\t\topacity: .25;\n\t\t\t\t\t} \n\t\t\t\t\t100% { \n\t\t\t\t\t\topacity: 1;\n\t\t\t\t\t} \n\t\t\t\t}\n\t\t\t\t.${it} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\tbottom: 24px;\n\t\t\t\t\tleft: 8px;\n\t\t\t\t\tz-index: 2147483647;\n\t\t\t\t\topacity: 0.9;\n\t\t\t\t\tpadding: 4px;\n\t\t\t\t\tbackground-color: white;\n\t\t\t\t\tmin-width: ${ht}px;\n\t\t\t\t\tmin-height: 16px;\n\t\t\t\t\ttransition: height 100ms;\n\t\t\t\t}\n\t\t\t\t.${st} {\n\t\t\t\t\tdisplay: flex;\n\t\t\t\t\tjustify-content: space-between;\n\t\t\t\t\tpadding: 2px;\n\t\t\t\t\tfont-family: arial, sans-serif;\n\t\t\t\t\tcolor: black;\n\t\t\t\t\tbackground-color: white;\n\t\t\t\t}\n\t\t\t\t.${ct} {\n\t\t\t\t\tfont-size: 13px;\n\t\t\t\t\topacity: 1;\n\t\t\t\t\ttransition: opacity 200ms;\n\t\t\t\t}\n\t\t\t\t.${lt} {\n\t\t\t\t\tfont-size: 11px;\n\t\t\t\t\tmin-width: 15px;\n\t\t\t\t\ttext-align: center;\n\t\t\t\t\tposition: relative;\n\t\t\t\t\ttop: 1px;\n\t\t\t\t}\n\t\t\t`,t.appendChild(e);const n=document.createElement("div");n.classList.add(it),t.appendChild(n)}}catch(t){}}function Dt(t,e,n,o){try{if(o.logsEnabled){const o=gt.shadowRoot.querySelector("."+it);let a=o.querySelector("[data-id='"+t+"']");if(!a){a=document.createElement("div"),a.classList.add(st),o.appendChild(a),a.setAttribute("data-id",t);const n=document.createElement("div");n.classList.add(ct),a.appendChild(n),n.textContent=e;const r=document.createElement("div");r.classList.add(lt),a.appendChild(r)}!function(t,e,n){const o=t.childNodes[0],a=t.childNodes[1];o.textContent=e,a.style.setProperty("color","✓"==n?"#055000":"black"),"✓"==n?(o.style.setProperty("opacity",".5"),a.style.setProperty("opacity",".5"),a.style.setProperty("animation","none")):a.style.setProperty("animation","1s ease-in-out 0s infinite alternate none running single-file-pulse");a.textContent=n}(a,e,n)}}catch(t){}}function kt(t,e){let n,o=t,a=[];do{const t=o.getBoundingClientRect();if(o.parentElement){const r=o.parentElement.getBoundingClientRect();n=Math.abs(r[e]-t[e])<=dt,n&&(o.parentElement.clientWidth>dt&&o.parentElement.clientHeight>dt&&(o.parentElement.clientWidth-o.clientWidth>dt||o.parentElement.clientHeight-o.clientHeight>dt)&&a.push(o.parentElement),o=o.parentElement)}else n=!1}while(n&&o);return a}function Pt(t,e,n,o){return Math[t](n/dt)<=o.length&&(e=o[o.length-Math[t](n/dt)-1]),e}function Nt(t,e){const n=document.createElement(t);return n.className=ut,e&&e.appendChild(n),wt.forEach((t=>n.style.setProperty(t,"initial","important"))),n}Ut();const Tt=globalThis.singlefile,Ot="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AYht+mSlUqHewg4hChOogFURFHqWIRLJS2QqsOJpf+CE0akhQXR8G14ODPYtXBxVlXB1dBEPwBcXNzUnSREr9LCi1ivOO4h/e+9+XuO0Col5lqdowDqmYZqXhMzOZWxMAruhGiOYohiZl6Ir2Qgef4uoeP73dRnuVd9+foVfImA3wi8SzTDYt4nXh609I57xOHWUlSiM+Jxwy6IPEj12WX3zgXHRZ4ZtjIpOaIw8RisY3lNmYlQyWeIo4oqkb5QtZlhfMWZ7VcZc178hcG89pymuu0BhHHIhJIQoSMKjZQhoUo7RopJlJ0HvPwDzj+JLlkcm2AkWMeFaiQHD/4H/zurVmYnHCTgjGg88W2P4aBwC7QqNn297FtN04A/zNwpbX8lTow80l6raVFjoDQNnBx3dLkPeByB+h/0iVDciQ/LaFQAN7P6JtyQN8t0LPq9q15jtMHIEO9WroBDg6BkSJlr3m8u6u9b//WNPv3A6mTcr3f/E/sAAAABmJLR0QAigCKAIrj2uckAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5QkPDysvCdPVuwAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAELSURBVHja7ZpLFsIwDAPj3v/OsGHDe1BIa8tKO7Mnlkw+dpoxAAAAAGCfx4ur6Yx/B337UUS4mp/VuWUEcjSfOgO+BXCZCWe0hSqQo/npBLglIUNLdAV2MH84Ad1JyIwdLkK6YoabIHWscBWmihHuAqvHtv+XqmdXOK9TxdKy3axUm2vZkXXGgPJksTuz1bVFeeU2Y6ijsLIpXbtKa1kDs2ews69o7+A+ihJ2lvI+/lcS1G21zUVG18XKNm4OS4BNkGOQQohSmGaIdpgLESvzyiRwKepsXjE2H0ZWMF8Zi4+jK5mviM0DiRXNZ2rhkdTK5jO0xermz2o8dCnq+FS2XNNVH0sDAAAA3JYnre9cH8BZmhEAAAAASUVORK5CYII=",Bt=Tt.helper.SINGLE_FILE_UI_ELEMENT_CLASS,jt="singlefile-error-bar",Mt=new Set(Array.from(getComputedStyle(document.documentElement)));let Ft;function Wt(t,e){try{if(console.error("SingleFile",t,e),Ft=document.querySelector(jt),!Ft){Ft=function(t,e){const n=document.createElement(t);n.className=Bt,e&&e.appendChild(n);return Mt.forEach((t=>n.style.setProperty(t,"initial","important"))),n}(jt);const n=Ft.attachShadow({mode:"open"}),o=document.createElement("style");o.textContent="\n\t\t\t\t.container {\n\t\t\t\t\tbackground-color: #ff6c00;\n\t\t\t\t\tcolor: white;\n\t\t\t\t\tdisplay: flex;\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: 0px;\n\t\t\t\t\tleft: 0px;\n\t\t\t\t\tright: 0px;\n\t\t\t\t\theight: auto;\n\t\t\t\t\twidth: auto;\n\t\t\t\t\tmin-height: 24px;\n\t\t\t\t\tmin-width: 24px;\t\t\t\t\t\n\t\t\t\t\tz-index: 2147483647;\n\t\t\t\t\tmargin: 0;\n\t\t\t\t\tpadding: 2px;\n\t\t\t\t\tfont-family: Arial;\n\t\t\t\t}\n\t\t\t\t.text {\n\t\t\t\t\tflex: 1;\n\t\t\t\t\tpadding-top: 4px;\n\t\t\t\t\tpadding-bottom: 4px;\n\t\t\t\t\tpadding-left: 8px;\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t.close-button {\n\t\t\t\t\topacity: .7;\n\t\t\t\t\tpadding-top: 4px;\n\t\t\t\t\tpadding-left: 8px;\n\t\t\t\t\tpadding-right: 8px;\n\t\t\t\t\tcursor: pointer;\n\t\t\t\t\ttransition: opacity 250ms;\n\t\t\t\t\theight: 16px;\n\t\t\t\t}\n\t\t\t\ta {\n\t\t\t\t\tcolor: #303036;\n\t\t\t\t}\n\t\t\t\t.close-button:hover {\n\t\t\t\t\topacity: 1;\n\t\t\t\t}\n\t\t\t",n.appendChild(o);const a=document.createElement("div");a.className="container";const r=document.createElement("span");r.classList.add("text");const i=t.split("__DOC_LINK__");if(r.textContent="SingleFile error: "+i[0],e&&2==i.length){const t=document.createElement("a");t.textContent=e,t.href=e,t.target="_blank",r.appendChild(t),r.appendChild(document.createTextNode(i[1]))}a.appendChild(r);const s=document.createElement("img");s.classList.add("close-button"),a.appendChild(s),n.appendChild(a),s.src=Ot,s.onclick=t=>{0===t.button&&Ft.remove()},document.body.appendChild(Ft)}}catch(t){}}const qt=globalThis.singlefile,Ht=globalThis.singlefileBootstrap,zt="moz-extension:";let Gt,Vt,_t;Ht&&Ht.initializedSingleFile||(qt.init({fetch:async function(t,e={}){try{const n={cache:"force-cache",headers:e.headers};return await(e.referrer&&G?async function(t,e){const n=new Promise(((n,o)=>{_(new CustomEvent(F,{detail:JSON.stringify({url:t,options:e})})),V(W,i,!1),V(q,r,!1);const a=setTimeout((()=>{s(),o(new Error(H))}),z);function r(e){e.detail?e.detail.url==t&&(s(),e.detail.response?n({status:e.detail.status,headers:new Map(e.detail.headers),arrayBuffer:async()=>e.detail.response}):o(e.detail.error)):o()}function i(){clearTimeout(a)}function s(){X(q,r,!1),X(W,i,!1)}}));try{return await n}catch(n){if(n&&n.message==H)return Q(t,e);throw n}}(t,n):Q(t,n))}catch(n){Z++;const o=new Promise(((t,e)=>J.set(Z,{resolve:t,reject:e})));return await K({method:"singlefile.fetch",url:t,requestId:Z,referrer:e.referrer,headers:e.headers}),o}},frameFetch:async function(t,e){const n=await K({method:"singlefile.fetchFrame",url:t,frameId:e.frameId,referrer:e.referrer,headers:e.headers});return{status:n.status,headers:new Map(n.headers),arrayBuffer:async()=>new Uint8Array(n.array).buffer}}}),browser.runtime.onMessage.addListener((t=>{if("content.save"==t.method||"content.cancelSave"==t.method||"content.download"==t.method||"content.getSelectedLinks"==t.method||"content.error"==t.method||"content.prompt"==t.method)return async function(t){if(!location.href.startsWith(zt)){if("content.save"==t.method)return await async function(t){const e=t.options;let n;(e.selected||e.optionallySelected)&&(n=await xt(e.optionallySelected));if(!(Vt||Ht&&Ht.pageInfo.processing)){if(e.updatedResources=Ht?Ht.pageInfo.updatedResources:{},e.visitDate=Ht?Ht.pageInfo.visitDate:new Date,Object.keys(e.updatedResources).forEach((t=>e.updatedResources[t].retrieved=!1)),e.optionallySelected&&n&&(e.selected=!0),!e.selected||n){Ht&&(Ht.pageInfo.processing=!0),Vt=!0;try{const t=await async function(t){const e=qt.processors.frameTree;let n;t.keepFilename=t.saveToGDrive||t.saveToGitHub||t.saveWithWebDAV,qt.helper.initDoc(document),At(t),Gt=new qt.SingleFile(t);const o=[];t.insertCanonicalLink=!0;let a=0,r=0;t.onprogress=e=>{Gt.cancelled||(e.type==e.RESOURCES_INITIALIZED&&(r=e.detail.max,t.loadDeferredImages&&qt.processors.lazy.resetZoomLevel(t)),e.type==e.RESOURCES_INITIALIZED||e.type==e.RESOURCE_LOADED?(e.type==e.RESOURCE_LOADED&&a++,browser.runtime.sendMessage({method:"ui.processProgress",index:a,maxIndex:r}),Et(a,r,t)):e.detail.frame||e.type==e.PAGE_LOADING||e.type==e.PAGE_LOADED||(e.type==e.STAGE_STARTED?e.detail.step<3&&function(t,e){Dt("step-"+t,`${pt} ${t+1} / 3`,"…",e)}(e.detail.step,t):e.type==e.STAGE_ENDED?e.detail.step<3&&function(t,e){Dt("step-"+t,`${pt} ${t+1} / 3`,"✓",e)}(e.detail.step,t):(e.type==e.STAGE_TASK_STARTED||e.type==e.STAGE_TASK_ENDED)&&(e.detail.step,e.detail.task)))};const i=Gt.cancel.bind(Gt);if(!t.saveRawPage){let n;if(t.loadDeferredImages&&(n=qt.processors.lazy.process(t),function(t){Dt("load-deferred-images",ft,"…",t)}(t),n.then((()=>{Gt.cancelled||function(t){Dt("load-deferred-images",ft,"✓",t)}(t)})),t.loadDeferredImagesBeforeFrames&&await n),!t.removeFrames&&e&&globalThis.frames){let n;n=t.loadDeferredImages?new Promise((n=>globalThis.setTimeout((()=>n(e.getAsync(t))),t.loadDeferredImagesBeforeFrames||!t.loadDeferredImages?0:t.loadDeferredImagesMaxIdleTime))):e.getAsync(t),function(t){Dt("load-frames",mt,"…",t)}(t),n.then((()=>{Gt.cancelled||function(t){Dt("load-frames",mt,"✓",t)}(t)})),t.loadDeferredImagesBeforeFrames?t.frames=await new Promise((t=>{Gt.cancel=function(){i(),t([])},n.then(t)})):o.push(n)}t.loadDeferredImages&&!t.loadDeferredImagesBeforeFrames&&o.push(n)}t.loadDeferredImagesBeforeFrames||([t.frames]=await new Promise((t=>{const e=Promise.all(o);Gt.cancel=function(){i(),t([[]])},e.then((()=>t(e)))})));n=t.frames&&t.frames.sessionId;const s=t.frames&&t.frames.find((t=>t.requestedFrame));t.win=globalThis,s?(t.content=s.content,t.url=s.baseURI,t.canvases=s.canvases,t.fonts=s.fonts,t.stylesheets=s.stylesheets,t.images=s.images,t.posters=s.posters,t.videos=s.videos,t.usedFonts=s.usedFonts,t.shadowRoots=s.shadowRoots,t.adoptedStyleSheets=s.adoptedStyleSheets):t.doc=document;Gt.cancelled||await Gt.run();n&&e.cleanup(n);let c;Gt.cancelled||(t.confirmInfobarContent&&(t.infobarContent=bt("Infobar content",t.infobarContent)||""),c=await Gt.getPageData(),(t.selected||t.optionallySelected)&&document.querySelectorAll("["+$+"]").forEach((t=>t.removeAttribute($))),vt(),t.displayStats&&(console.log("SingleFile stats"),console.table(c.stats)));return c}(e);t&&((!e.backgroundSave&&!e.saveToClipboard||e.saveToGDrive||e.saveToGitHub||e.saveWithCompanion||e.saveWithWebDAV)&&e.confirmFilename&&(t.filename=bt("Save as",t.filename)||t.filename),await M(t,e))}catch(t){Gt.cancelled||(console.error(t),browser.runtime.sendMessage({method:"ui.processError",error:t}))}}else browser.runtime.sendMessage({method:"ui.processCancelled"});Vt=!1,Ht&&(Ht.pageInfo.processing=!1)}}(t),{};if("content.cancelSave"==t.method)return Gt&&(Gt.cancel(),vt(),browser.runtime.sendMessage({method:"ui.processCancelled"})),t.options.loadDeferredImages&&qt.processors.lazy.resetZoomLevel(t.options),{};if("content.getSelectedLinks"==t.method)return{urls:St()};if("content.download"==t.method){_t||(_t=E());const e=await _t.next(t.data);if(e.done){_t=null;const t=document.createElement("a");t.download=e.value.filename,t.href=URL.createObjectURL(new Blob([e.value.content]),"text/html"),t.dispatchEvent(new MouseEvent("click")),URL.revokeObjectURL(t.href),await browser.runtime.sendMessage({method:"downloads.end",taskId:e.value.taskId})}return{}}if("content.error"==t.method)return Wt(t.error,t.link),{};if("content.prompt"==t.method)return bt(t.message,t.value)}}(t)})),Ht?Ht.initializedSingleFile=!0:globalThis.singlefileBootstrap={initializedSingleFile:!0})}();
|