| 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(e,n){const o=function(e,{chunkSize:n=t}={}){let o,a,r,i,s,c;return{[Symbol.asyncIterator]:()=>({next:()=>i?{done:i}:l(),return:()=>({done:!0})})};async function l(){c?c():d().catch((()=>{})),p();return{value:await w()}}async function d(){m(),o=new u(h,n),await f(o,e),await o.flush()}function m(){a=new Promise((t=>r=t))}function p(){s=new Promise((t=>c=t))}async function h(t){r(t),await s}async function w(){const{value:t,done:e}=await a;return i=e,e||m(),t}}(e,n);let a=new Uint8Array([]);for await(const t of o){const e=a;a=new Uint8Array(e.length+t.length),a.set(e,0),a.set(t,e.length)}return a}c((async function(t,e){const n=t.objects.indexOf(e);await f(t,n)}),(async function(t){const e=await E(t);return new g(e,t)}),D,e),c(null,(function(){return{}}),R),c(m,S,U),c(p,x,(function(t){return"string"==typeof t})),c(h,(async function(t){const e=await E(t),n=await t.consume(8*e);return new Float64Array(n.buffer)}),(function(t){return t instanceof Float64Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(4*e);return new Float32Array(n.buffer)}),(function(t){return t instanceof Float32Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(4*e);return new Uint32Array(n.buffer)}),(function(t){return t instanceof Uint32Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(4*e);return new Int32Array(n.buffer)}),(function(t){return t instanceof Int32Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(2*e);return new Uint16Array(n.buffer)}),(function(t){return t instanceof Uint16Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(2*e);return new Int16Array(n.buffer)}),(function(t){return t instanceof Int16Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(e);return new Uint8ClampedArray(n.buffer)}),(function(t){return t instanceof Uint8ClampedArray})),c(h,(async function(t){const e=await E(t);return await t.consume(e)}),(function(t){return t instanceof Uint8Array})),c(h,(async function(t){const e=await E(t),n=await t.consume(e);return new Int8Array(n.buffer)}),(function(t){return t instanceof Int8Array})),c((async function(t,e){await f(t,e.byteLength),await t.append(new Uint8Array(e))}),(async function(t){const e=await E(t);return(await t.consume(e)).buffer}),(function(t){return t instanceof ArrayBuffer})),c(w,C,P),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 N(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 N(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 N(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 N(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 N(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 N(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(y,I,(function(t){return"boolean"==typeof t})),c((async function(t,e){await p(t,e.description)}),(async function(t){const e=await x(t);return Symbol(e)}),T),c(null,(function(){return o}),k),c((async function(t,e){const n=e.entries();await f(t,e.size);for(const[e,o]of n)await f(t,e),await f(t,o)}),(async function(t){const e=await E(t),n=new Map;e&&await async function o(a=0){const r=await E(t),i=await E(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 f(t,e.size);for(const n of e)await f(t,n)}),(async function(t){const e=await E(t),n=new Set;e&&await async function o(a=0){const r=await E(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 w(t,e.getTime())}),(async function(t){const e=await C(t);return new Date(e)}),(function(t){return t instanceof Date})),c((async function(t,e){await p(t,e.message),await p(t,e.stack)}),(async function(t){const e=await x(t),n=await x(t),o=new Error(e);return o.stack=n,o}),(function(t){return t instanceof Error})),c((async function(t,e){await p(t,e.source),await p(t,e.flags)}),(async function(t){const e=await x(t),n=await x(t);return new RegExp(e,n)}),(function(t){return t instanceof RegExp})),c((async function(t,e){await p(t,e.valueOf())}),(async function(t){return new String(await x(t))}),(function(t){return t instanceof String})),c((async function(t,e){await w(t,e.valueOf())}),(async function(t){return new Number(await C(t))}),(function(t){return t instanceof Number})),c((async function(t,e){await y(t,e.valueOf())}),(async function(t){return new Boolean(await I(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(O(t)&&!D(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})}}async function f(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&&R(n)&&(await async function(t,e){const n=Object.getOwnPropertySymbols(e),o=n.map((t=>[t,e[t]]));await m(t,o)}(t,n),await async function(t,e){if(ArrayBuffer.isView(e))await f(t,0);else{let n=Object.entries(e);U(e)&&(n=n.filter((([t])=>!N(Number(t))))),await f(t,n.length);for(const[e,o]of n)await p(t,e),await f(t,o)}}(t,n))}async function m(t,e){await f(t,e.length);const n=Object.keys(e).filter((t=>N(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 f(t,s)):await f(t,o)}async function p(t,e){const n=a.encode(e);await f(t,n.length),await t.append(n)}async function h(t,e){await f(t,e.length),await t.append(e instanceof Uint8Array?e:new Uint8Array(e.buffer))}async function w(t,e){const n=new Uint8Array(new Float64Array([e]).buffer);await t.append(n)}async function y(t,e){const n=new Uint8Array([Number(e)]);await t.append(n)}class g{constructor(t,e){this.index=t,this.data=e}getObject(){return this.data.objects[this.index]}}class b{constructor(t){this.stream=new A(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){O(e)&&!L(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=>L(t)?t.getObject():t)))}))}}class A{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 v(){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 b(s),i();const n=await E(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 E(t){const n=(await t.consume(1))[0],o=i[n].parse,a=t.getObjectId(),r=await o(t);return n!=e&&R(r)&&(await async function(t,e){const n=await S(t);t.setObject([n],(t=>t.forEach((([t,n])=>e[t]=n))))}(t,r),await async function(t,e){const n=await E(t);n&&await o();async function o(a=0){const r=await x(t),i=await E(t);t.setObject([i],(t=>e[r]=t)),a<n-1&&await o(a+1)}}(t,r)),t.resolveObject(a,r),r}async function S(t){const e=await E(t),n=new Array(e);return e&&await async function o(a=0){const r=await E(t);k(r)||t.setObject([r],(t=>n[a]=t));a<e-1&&await o(a+1)}(),n}async function x(t){const e=await E(t),n=await t.consume(e);return r.decode(n)}async function C(t){const e=await t.consume(8);return new Float64Array(e.buffer)[0]}async function I(t){const e=await t.consume(1);return Boolean(e[0])}function D(t,e){return R(t)&&e.objects.includes(t)}function L(t){return t instanceof g}function R(t){return t===Object(t)}function U(t){return"number"==typeof t.length}function k(t){return t===o}function P(t){return"number"==typeof t}function N(t){return P(t)&&Number.isInteger(t)}function T(t){return"symbol"==typeof t}function O(t){return R(t)||T(t)}const B=16777216;async function j(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,preventAppendedData:e.preventAppendedData,extractDataFromPage:e.extractDataFromPage,insertCanonicalLink:e.insertCanonicalLink,insertMetaNoIndex:e.insertMetaNoIndex,password:e.password,compressContent:e.compressContent,foregroundSave:e.foregroundSave};if(e.compressContent){const o=new Blob([await l(t)],{type:"application/octet-stream"}),a=URL.createObjectURL(o);n.blobURL=a;const r=await browser.runtime.sendMessage(n);if(URL.revokeObjectURL(a),r.error){n.blobURL=null,n.pageData=t;let e,o=0;const a=await l(n);do{e=Array.from(a.slice(o,o+B)),o+=B,await browser.runtime.sendMessage({method:"downloads.download",compressContent:!0,data:e})}while(e.length);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*B<t.content.length;e++)n.truncated=t.content.length>B,n.truncated?(n.finished=(e+1)*B>t.content.length,n.content=t.content.substring(e*B,(e+1)*B)):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 M="single-file-request-fetch",F="single-file-ack-fetch",W="single-file-response-fetch",q="Host fetch error (SingleFile)",H=2500,z=Boolean(window.wrappedJSObject),G=(t,e,n)=>window.addEventListener(t,e,n),V=t=>window.dispatchEvent(t),_=(t,e,n)=>window.removeEventListener(t,e,n),X=(t,e)=>window.fetch(t,e);let Q=0,Z=new Map;async function J(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 X(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=Z.get(t.requestId);e&&(t.error?(e.reject(new Error(t.error)),Z.delete(t.requestId)):(t.truncated&&(e.array?e.array=e.array.concat(t.array):(e.array=t.array,Z.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}),Z.delete(t.requestId))));return{}}(t):void 0));const K=globalThis.singlefile,Y=K.helper.SELECTED_CONTENT_ATTRIBUTE_NAME,$="singlefile-mask",tt="singlefile-mask-content",et="singlefile-progress-bar",nt="singlefile-progress-bar-content",ot="single-file-selection-zone",at="singlefile-logs-window",rt="singlefile-logs",it="singlefile-logs-line",st="singlefile-logs-line-text",ct="singlefile-logs-line-icon",lt=K.helper.SINGLE_FILE_UI_ELEMENT_CLASS,ut=8,dt=browser.i18n.getMessage("logPanelDeferredImages"),ft=browser.i18n.getMessage("logPanelFrameContents"),mt=browser.i18n.getMessage("logPanelStep"),pt=browser.i18n.getMessage("logPanelWidth"),ht=new Set(Array.from(getComputedStyle(document.documentElement)));let wt,yt;function gt(t,e){return prompt(t,e)}function bt(t){if(!document.querySelector($)&&(t.logsEnabled&&document.documentElement.appendChild(yt),t.shadowEnabled)){const e=function(){try{let t=document.querySelector($);if(!t){t=Pt($,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.${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: 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.${nt} {\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.${tt} {\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(tt),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("."+et)){let e=document.createElement("div");e.classList.add(et),t.shadowRoot.appendChild(e);const n=document.createElement("div");n.classList.add(nt),e.appendChild(n)}}catch(t){}}(e)}}function At(){const t=document.querySelector($);t&&t.remove(),yt.remove(),Lt()}function vt(t,e,n){n.shadowEnabled&&n.progressBarEnabled&&function(t,e){try{const n=document.querySelector($);if(n){const o=n.shadowRoot.querySelector("."+et);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 Et(){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 St(t){let e=xt();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=kt("floor",n,t.clientX-o.left,Ut(n,"left")),e==n&&(e=kt("ceil",n,o.left+o.width-t.clientX,Ut(n,"right"))),e==n&&(e=kt("floor",n,t.clientY-o.top,Ut(n,"top"))),e==n&&(e=kt("ceil",n,o.top+o.height-t.clientY,Ut(n,"bottom"))),n=e;n&&n.clientWidth<=ut&&n.clientHeight<=ut;)n=n.parentElement;return n}(t);var n;e&&(wt=e,n=e,requestAnimationFrame((()=>{const t=Dt(),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(wt,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(){Dt().remove(),removeEventListener("mousemove",o,!0),removeEventListener("click",a,!0),removeEventListener("keyup",r,!0),wt=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?xt():void 0)}function xt(){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,Ct(t.currentNode))),e&&t.currentNode==o.startContainer&&It(t.currentNode),t.currentNode==o.endContainer?a=!0:t.nextNode();e&&t.currentNode==o.endContainer&&t.currentNode.querySelectorAll&&t.currentNode.querySelectorAll("*").forEach((t=>Ct(t)))}}return e}function Ct(t){(t.nodeType==Node.ELEMENT_NODE?t:t.parentElement).setAttribute(Y,"")}function It(t){t.parentElement&&(Ct(t),It(t.parentElement))}function Dt(){let t=document.querySelector(ot);return t||(t=Pt(ot,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 Lt(){try{if(yt=document.querySelector(at),!yt){yt=Pt(at);const t=yt.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.${rt} {\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: ${pt}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.${it} {\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.${st} {\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.${ct} {\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(rt),t.appendChild(n)}}catch(t){}}function Rt(t,e,n,o){try{if(o.logsEnabled){const o=yt.shadowRoot.querySelector("."+rt);let a=o.querySelector("[data-id='"+t+"']");if(!a){a=document.createElement("div"),a.classList.add(it),o.appendChild(a),a.setAttribute("data-id",t);const n=document.createElement("div");n.classList.add(st),a.appendChild(n),n.textContent=e;const r=document.createElement("div");r.classList.add(ct),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 Ut(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])<=ut,n&&(o.parentElement.clientWidth>ut&&o.parentElement.clientHeight>ut&&(o.parentElement.clientWidth-o.clientWidth>ut||o.parentElement.clientHeight-o.clientHeight>ut)&&a.push(o.parentElement),o=o.parentElement)}else n=!1}while(n&&o);return a}function kt(t,e,n,o){return Math[t](n/ut)<=o.length&&(e=o[o.length-Math[t](n/ut)-1]),e}function Pt(t,e){const n=document.createElement(t);return n.className=lt,e&&e.appendChild(n),ht.forEach((t=>n.style.setProperty(t,"initial","important"))),n}Lt();const Nt=globalThis.singlefile,Tt="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=",Ot=Nt.helper.SINGLE_FILE_UI_ELEMENT_CLASS,Bt="singlefile-error-bar",jt=new Set(Array.from(getComputedStyle(document.documentElement)));let Mt;function Ft(t,e){try{if(console.error("SingleFile",t,e),Mt=document.querySelector(Bt),!Mt){Mt=function(t,e){const n=document.createElement(t);n.className=Ot,e&&e.appendChild(n);return jt.forEach((t=>n.style.setProperty(t,"initial","important"))),n}(Bt);const n=Mt.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=Tt,s.onclick=t=>{0===t.button&&Mt.remove()},document.body.appendChild(Mt)}}catch(t){}}const Wt=globalThis.singlefile,qt=globalThis.singlefileBootstrap,Ht="moz-extension:";let zt,Gt,Vt;qt&&qt.initializedSingleFile||(Wt.init({fetch:async function(t,e={}){try{const n={cache:"force-cache",headers:e.headers};return await(e.referrer&&z?async function(t,e){const n=new Promise(((n,o)=>{V(new CustomEvent(M,{detail:JSON.stringify({url:t,options:e})})),G(F,i,!1),G(W,r,!1);const a=setTimeout((()=>{s(),o(new Error(q))}),H);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(){_(W,r,!1),_(F,i,!1)}}));try{return await n}catch(n){if(n&&n.message==q)return X(t,e);throw n}}(t,n):X(t,n))}catch(n){Q++;const o=new Promise(((t,e)=>Z.set(Q,{resolve:t,reject:e})));return await J({method:"singlefile.fetch",url:t,requestId:Q,referrer:e.referrer,headers:e.headers}),o}},frameFetch:async function(t,e){const n=await J({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(Ht)){if("content.save"==t.method)return await async function(t){const e=t.options;let n;(e.selected||e.optionallySelected)&&(n=await St(e.optionallySelected));if(!(Gt||qt&&qt.pageInfo.processing)){if(e.updatedResources=qt?qt.pageInfo.updatedResources:{},e.visitDate=qt?qt.pageInfo.visitDate:new Date,Object.keys(e.updatedResources).forEach((t=>e.updatedResources[t].retrieved=!1)),e.optionallySelected&&n&&(e.selected=!0),!e.selected||n){qt&&(qt.pageInfo.processing=!0),Gt=!0;try{const t=await async function(t){const e=Wt.processors.frameTree;let n;t.keepFilename=t.saveToGDrive||t.saveToGitHub||t.saveWithWebDAV,Wt.helper.initDoc(document),bt(t),zt=new Wt.SingleFile(t);const o=[];t.insertCanonicalLink=!0;let a=0,r=0;t.onprogress=e=>{zt.cancelled||(e.type==e.RESOURCES_INITIALIZED&&(r=e.detail.max,t.loadDeferredImages&&Wt.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}),vt(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){Rt("step-"+t,`${mt} ${t+1} / 3`,"…",e)}(e.detail.step,t):e.type==e.STAGE_ENDED?e.detail.step<3&&function(t,e){Rt("step-"+t,`${mt} ${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=zt.cancel.bind(zt);if(!t.saveRawPage){let n;if(t.loadDeferredImages&&(n=Wt.processors.lazy.process(t),function(t){Rt("load-deferred-images",dt,"…",t)}(t),n.then((()=>{zt.cancelled||function(t){Rt("load-deferred-images",dt,"✓",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){Rt("load-frames",ft,"…",t)}(t),n.then((()=>{zt.cancelled||function(t){Rt("load-frames",ft,"✓",t)}(t)})),t.loadDeferredImagesBeforeFrames?t.frames=await new Promise((t=>{zt.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);zt.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;zt.cancelled||await zt.run();n&&e.cleanup(n);let c;zt.cancelled||(t.confirmInfobarContent&&(t.infobarContent=gt("Infobar content",t.infobarContent)||""),c=await zt.getPageData(),(t.selected||t.optionallySelected)&&document.querySelectorAll("["+Y+"]").forEach((t=>t.removeAttribute(Y))),At(),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=gt("Save as",t.filename)||t.filename),await j(t,e))}catch(t){if(!zt.cancelled){console.error(t);const e=t.toString();browser.runtime.sendMessage({method:"ui.processError",error:e}),Ft(e)}}}else browser.runtime.sendMessage({method:"ui.processCancelled"});Gt=!1,qt&&(qt.pageInfo.processing=!1)}}(t),{};if("content.cancelSave"==t.method)return zt&&(zt.cancel(),At(),browser.runtime.sendMessage({method:"ui.processCancelled"})),t.options.loadDeferredImages&&Wt.processors.lazy.resetZoomLevel(t.options),{};if("content.getSelectedLinks"==t.method)return{urls:Et()};if("content.download"==t.method){Vt||(Vt=v());const e=await Vt.next(t.data);if(e.done){Vt=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 Ft(t.error,t.link),{};if("content.prompt"==t.method)return gt(t.message,t.value)}}(t)})),qt?qt.initializedSingleFile=!0:globalThis.singlefileBootstrap={initializedSingleFile:!0})}();
|