single-file-extension.js 36 KB

1
  1. !function(){"use strict";const t=8388608,e=0,n=[e],r=Symbol(),a=new TextEncoder,o=new TextDecoder,i=new Array(256);let s=0;function c(t,e,r,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:r}}else i[a]={serialize:t,parse:e,test:r}}async function l(e,n){const r=function(e,{chunkSize:n=t}={}){let r,a,o,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(),r=new u(h,n),await f(r,e),await r.flush()}function m(){a=new Promise((t=>o=t))}function p(){s=new Promise((t=>c=t))}async function h(t){o(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 r){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)}),L,e),c(null,(function(){return{}}),k),c(m,x,R),c(p,S,(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,I,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 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(y,C,(function(t){return"boolean"==typeof t})),c((async function(t,e){await p(t,e.description)}),(async function(t){const e=await S(t);return Symbol(e)}),N),c(null,(function(){return r}),U),c((async function(t,e){const n=e.entries();await f(t,e.size);for(const[e,r]of n)await f(t,e),await f(t,r)}),(async function(t){const e=await E(t),n=new Map;e&&await async function r(a=0){const o=await E(t),i=await E(t);t.setObject([o,i],((t,e)=>n.set(t,e))),a<e-1&&await r(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 r(a=0){const o=await E(t);t.setObject([o],(t=>n.add(t))),a<e-1&&await r(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 I(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 S(t),n=await S(t),r=new Error(e);return r.stack=n,r}),(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 S(t),n=await S(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 S(t))}),(function(t){return t instanceof String})),c((async function(t,e){await w(t,e.valueOf())}),(async function(t){return new Number(await I(t))}),(function(t){return t instanceof Number})),c((async function(t,e){await y(t,e.valueOf())}),(async function(t){return new Boolean(await C(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)&&!L(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 r=i.findIndex((({test:e}={})=>e&&e(n,t)));t.addObject(n),await t.append(new Uint8Array([r]));const a=i[r].serialize;a&&await a(t,n),r!=e&&k(n)&&(await async function(t,e){const n=Object.getOwnPropertySymbols(e),r=n.map((t=>[t,e[t]]));await m(t,r)}(t,n),await async function(t,e){if(ArrayBuffer.isView(e))await f(t,0);else{let n=Object.entries(e);R(e)&&(n=n.filter((([t])=>!T(Number(t))))),await f(t,n.length);for(const[e,r]of n)await p(t,e),await f(t,r)}}(t,n))}async function m(t,e){await f(t,e.length);const n=Object.keys(e).filter((t=>T(Number(t)))).map((t=>Number(t)));let a=0,o=n[a];for(const[i,s]of e.entries())o==i?(o=n[++a],await f(t,s)):await f(t,r)}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)&&!D(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=>D(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,r,a,o;return{next:async e=>e?async function(e){a?await a:async function(){let e;r=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=>o=t))}(),n(e),{done:!1}}(e):{value:await r,done:!0},return:()=>({done:!0})};function i(){e=new Promise((t=>n=t))}async function s(){const t=await e;return i(),o&&o(),t}}async function E(t){const n=(await t.consume(1))[0],r=i[n].parse,a=t.getObjectId(),o=await r(t);return n!=e&&k(o)&&(await async function(t,e){const n=await x(t);t.setObject([n],(t=>t.forEach((([t,n])=>e[t]=n))))}(t,o),await async function(t,e){const n=await E(t);n&&await r();async function r(a=0){const o=await S(t),i=await E(t);t.setObject([i],(t=>e[o]=t)),a<n-1&&await r(a+1)}}(t,o)),t.resolveObject(a,o),o}async function x(t){const e=await E(t),n=new Array(e);return e&&await async function r(a=0){const o=await E(t);U(o)||t.setObject([o],(t=>n[a]=t));a<e-1&&await r(a+1)}(),n}async function S(t){const e=await E(t),n=await t.consume(e);return o.decode(n)}async function I(t){const e=await t.consume(8);return new Float64Array(e.buffer)[0]}async function C(t){const e=await t.consume(1);return Boolean(e[0])}function L(t,e){return k(t)&&e.objects.includes(t)}function D(t){return t instanceof g}function k(t){return t===Object(t)}function R(t){return"number"==typeof t.length}function U(t){return t===r}function P(t){return"number"==typeof t}function T(t){return P(t)&&Number.isInteger(t)}function N(t){return"symbol"==typeof t}function O(t){return k(t)||N(t)}const B=16777216;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,saveToDropbox:e.saveToDropbox,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,embeddedImage:e.embeddedImage,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 r=new Blob([await l(t)],{type:"application/octet-stream"}),a=URL.createObjectURL(r);n.blobURL=a;const o=await browser.runtime.sendMessage(n);if(URL.revokeObjectURL(a),o.error){n.blobURL=null,n.pageData=t;let e,r=0;const a=await l(n);do{e=Array.from(a.slice(r,r+B)),r+=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||e.saveToDropbox){const e=URL.createObjectURL(new Blob([t.content],{type:"text/html"}));n.blobURL=e;const r=await browser.runtime.sendMessage(n);if(URL.revokeObjectURL(e),r.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 j="single-file-request-fetch",F="single-file-ack-fetch",W="single-file-response-fetch",q="Host fetch error (SingleFile)",z=2500,H=Boolean(window.wrappedJSObject),G=(t,e)=>window.fetch(t,e);let V=0,_=new Map;async function X(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 G(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=_.get(t.requestId);e&&(t.error?(e.reject(new Error(t.error)),_.delete(t.requestId)):(t.truncated&&(e.array?e.array=e.array.concat(t.array):(e.array=t.array,_.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}),_.delete(t.requestId))));return{}}(t):void 0));const Q=globalThis.singlefile,Z=Q.helper.SELECTED_CONTENT_ATTRIBUTE_NAME,J="singlefile-mask",K="singlefile-mask-content",Y="singlefile-progress-bar",$="singlefile-progress-bar-content",tt="single-file-selection-zone",et="singlefile-logs-window",nt="singlefile-logs",rt="singlefile-logs-line",at="singlefile-logs-line-text",ot="singlefile-logs-line-icon",it=Q.helper.SINGLE_FILE_UI_ELEMENT_CLASS,st=8,ct=browser.i18n.getMessage("logPanelDeferredImages"),lt=browser.i18n.getMessage("logPanelFrameContents"),ut=browser.i18n.getMessage("logPanelEmbeddedImage"),dt=browser.i18n.getMessage("logPanelStep"),ft=browser.i18n.getMessage("logPanelWidth"),mt=new Set(Array.from(getComputedStyle(document.documentElement)));let pt,ht;function wt(t,e){return prompt(t,e)}function yt(t){if(!document.querySelector(J)&&(t.logsEnabled&&document.documentElement.appendChild(ht),t.shadowEnabled)){const e=function(){try{let t=document.querySelector(J);if(!t){t=Rt(J,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.${Y} {\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.${$} {\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.${K} {\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 r=document.createElement("div");r.classList.add(K),e.appendChild(r),t.offsetWidth,r.style.setProperty("opacity",.3),t.offsetWidth}return t}catch(t){}}();t.progressBarEnabled&&function(t){try{if(!t.shadowRoot.querySelector("."+Y)){let e=document.createElement("div");e.classList.add(Y),t.shadowRoot.appendChild(e);const n=document.createElement("div");n.classList.add($),e.appendChild(n)}}catch(t){}}(e)}}function gt(){const t=document.querySelector(J);t&&t.remove(),ht.remove(),Ct()}function bt(t,e,n){n.shadowEnabled&&n.progressBarEnabled&&function(t,e){try{const n=document.querySelector(J);if(n){const r=n.shadowRoot.querySelector("."+Y);if(r&&e){const n=Math.floor(t/e*100)+"%";r.style.getPropertyValue("width")!=n&&(r.style.setProperty("width",n),r.offsetWidth)}}}catch(t){}}(t,e)}function At(){let t;const e=[],n=getSelection();for(let r=0;r<n.rangeCount;r++){let a=n.getRangeAt(r);if(a&&a.commonAncestorContainer){const n=document.createTreeWalker(a.commonAncestorContainer);let r=!1,o=!1;for(;!o;)(r||n.currentNode==a.startContainer||n.currentNode==a.endContainer)&&(r=!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?o=!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 vt(t){let e=Et();return e||t?e:(e=await new Promise((t=>{let e=[];function n(t){e=[],s(),t.preventDefault()}function r(t){const e=function(t){let e,n=t.target,r=n.getBoundingClientRect();for(e=kt("floor",n,t.clientX-r.left,Dt(n,"left")),e==n&&(e=kt("ceil",n,r.left+r.width-t.clientX,Dt(n,"right"))),e==n&&(e=kt("floor",n,t.clientY-r.top,Dt(n,"top"))),e==n&&(e=kt("ceil",n,r.top+r.height-t.clientY,Dt(n,"bottom"))),n=e;n&&n.clientWidth<=st&&n.clientHeight<=st;)n=n.parentElement;return n}(t);var n;e&&(pt=e,n=e,requestAnimationFrame((()=>{const t=It(),e=n.getBoundingClientRect(),r=document.scrollingElement||document.documentElement;t.style.setProperty("top",r.scrollTop+e.top-10+"px"),t.style.setProperty("left",r.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(pt,t.ctrlKey):i()}function o(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(){It().remove(),removeEventListener("mousemove",r,!0),removeEventListener("click",a,!0),removeEventListener("keyup",o,!0),pt=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",r,!0),addEventListener("click",a,!0),addEventListener("keyup",o,!0),document.addEventListener("contextmenu",n,!0),getSelection().removeAllRanges()})),e?Et():void 0)}function Et(){const t=getSelection();let e;for(let n=0;n<t.rangeCount;n++){let r=t.getRangeAt(n);if(r&&r.commonAncestorContainer){const t=document.createTreeWalker(r.commonAncestorContainer);let n=!1,a=!1;for(;!a;)(n||t.currentNode==r.startContainer||t.currentNode==r.endContainer)&&(n=!0,r.startContainer==r.endContainer&&r.startOffset==r.endOffset||(e=!0,xt(t.currentNode))),e&&t.currentNode==r.startContainer&&St(t.currentNode),t.currentNode==r.endContainer?a=!0:t.nextNode();e&&t.currentNode==r.endContainer&&t.currentNode.querySelectorAll&&t.currentNode.querySelectorAll("*").forEach((t=>xt(t)))}}return e}function xt(t){(t.nodeType==Node.ELEMENT_NODE?t:t.parentElement).setAttribute(Z,"")}function St(t){t.parentElement&&(xt(t),St(t.parentElement))}function It(){let t=document.querySelector(tt);return t||(t=Rt(tt,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 Ct(){try{if(ht=document.querySelector(et),!ht){ht=Rt(et);const t=ht.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.${nt} {\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: ${ft}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.${rt} {\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.${at} {\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.${ot} {\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(nt),t.appendChild(n)}}catch(t){}}function Lt(t,e,n,r){try{if(r.logsEnabled){const r=ht.shadowRoot.querySelector("."+nt);let a=r.querySelector("[data-id='"+t+"']");if(!a){a=document.createElement("div"),a.classList.add(rt),r.appendChild(a),a.setAttribute("data-id",t);const n=document.createElement("div");n.classList.add(at),a.appendChild(n),n.textContent=e;const o=document.createElement("div");o.classList.add(ot),a.appendChild(o)}!function(t,e,n){const r=t.childNodes[0],a=t.childNodes[1];r.textContent=e,a.style.setProperty("color","✓"==n?"#055000":"black"),"✓"==n?(r.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 Dt(t,e){let n,r=t,a=[];do{const t=r.getBoundingClientRect();if(r.parentElement){const o=r.parentElement.getBoundingClientRect();n=Math.abs(o[e]-t[e])<=st,n&&(r.parentElement.clientWidth>st&&r.parentElement.clientHeight>st&&(r.parentElement.clientWidth-r.clientWidth>st||r.parentElement.clientHeight-r.clientHeight>st)&&a.push(r.parentElement),r=r.parentElement)}else n=!1}while(n&&r);return a}function kt(t,e,n,r){return Math[t](n/st)<=r.length&&(e=r[r.length-Math[t](n/st)-1]),e}function Rt(t,e){const n=document.createElement(t);return n.className=it,e&&e.appendChild(n),mt.forEach((t=>n.style.setProperty(t,"initial","important"))),n}Ct();const Ut=globalThis.singlefile,Pt="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=",Tt=Ut.helper.SINGLE_FILE_UI_ELEMENT_CLASS,Nt="singlefile-error-bar",Ot="singlefile-open-file-bar",Bt=browser.i18n.getMessage("topPanelEmbeddedImageButton"),Mt=browser.i18n.getMessage("topPanelError"),jt=new Set(Array.from(getComputedStyle(document.documentElement)));function Ft(t,e){console.error("SingleFile",t,e),Wt(Nt,Mt+t,{link:e})}function Wt(t,e,{link:n,buttonLabel:r,buttonOnclick:a}={}){try{if(!document.querySelector(t)){const o=function(t,e){const n=document.createElement(t);n.className=Tt,e&&e.appendChild(n);return jt.forEach((t=>n.style.setProperty(t,"initial","important"))),n}(t),i=o.attachShadow({mode:"open"}),s=document.createElement("style");s.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.singlefile-open-file-bar.container {\n\t\t\t\t\tbackground-color: whitesmoke;\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\tbutton {\n\t\t\t\t\tbackground-color: grey;\n\t\t\t\t\tcolor: white;\n\t\t\t\t\tborder: 1px solid darkgrey;\n\t\t\t\t\tpadding: 3px;\n\t\t\t\t\tpadding-left: 8px;\n\t\t\t\t\tpadding-right: 8px;\n\t\t\t\t\tborder-radius: 4px;\n\t\t\t\t\tcursor: pointer;\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-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\tfont-size: .8rem;\n\t\t\t\t\talign-self: center;\n\t\t\t\t}\n\t\t\t\t.singlefile-open-file-bar .close-button {\n\t\t\t\t\tfilter: invert(1);\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",i.appendChild(s);const c=document.createElement("div");c.classList.add(t),c.classList.add("container");const l=document.createElement("span");l.classList.add("text");const u=e.split("__DOC_LINK__");if(l.textContent=u[0],n&&2==u.length){const t=document.createElement("a");t.textContent=n,t.href=n,t.target="_blank",l.appendChild(t),l.appendChild(document.createTextNode(u[1]))}if(r&&a){const t=document.createElement("button");t.textContent=r,t.onclick=()=>a(),l.appendChild(t)}c.appendChild(l);const d=document.createElement("img");d.classList.add("close-button"),c.appendChild(d),i.appendChild(c),d.src=Pt,d.onclick=t=>{0===t.button&&(a&&a(!0),o.remove())},document.body.appendChild(o)}}catch(t){}}const qt=globalThis.singlefile,zt=globalThis.singlefileBootstrap,Ht="moz-extension:";let Gt,Vt,_t,Xt;zt&&zt.initializedSingleFile||(qt.init({fetch:async function(t,e={}){try{const n={cache:"force-cache",headers:e.headers};return await(e.referrer&&H?async function(t,e){const n=new Promise(((n,r)=>{document.dispatchEvent(new CustomEvent(j,{detail:JSON.stringify({url:t,options:e})})),document.addEventListener(F,i,!1),document.addEventListener(W,o,!1);const a=setTimeout((()=>{s(),r(new Error(q))}),z);function o(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}):r(e.detail.error)):r()}function i(){clearTimeout(a)}function s(){document.removeEventListener(W,o,!1),document.removeEventListener(F,i,!1)}}));try{return await n}catch(n){if(n&&n.message==q)return G(t,e);throw n}}(t,n):G(t,n))}catch(n){V++;const r=new Promise(((t,e)=>_.set(V,{resolve:t,reject:e})));return await X({method:"singlefile.fetch",url:t,requestId:V,referrer:e.referrer,headers:e.headers}),r}},frameFetch:async function(t,e){const n=await X({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 vt(e.optionallySelected));if(!(Vt||zt&&zt.pageInfo.processing)){if(e.updatedResources=zt?zt.pageInfo.updatedResources:{},e.visitDate=zt?zt.pageInfo.visitDate:new Date,Object.keys(e.updatedResources).forEach((t=>e.updatedResources[t].retrieved=!1)),e.optionallySelected&&n&&(e.selected=!0),!e.selected||n){zt&&(zt.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||t.saveToDropbox,qt.helper.initDoc(document),yt(t),Gt=new qt.SingleFile(t);const r=[];t.insertCanonicalLink=!0;let a=0,o=0;t.onprogress=e=>{Gt.cancelled||(e.type==e.RESOURCES_INITIALIZED&&(o=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:o}),bt(a,o,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){Lt("step-"+t,`${dt} ${t+1} / 3`,"…",e)}(e.detail.step,t):e.type==e.STAGE_ENDED?e.detail.step<3&&function(t,e){Lt("step-"+t,`${dt} ${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.insertEmbeddedImage){!function(t){Lt("insert-embedded-image",ut,"…",t)}(t),Xt=function(){let t;return{display:async function(){return new Promise((e=>{t=e,Wt(Ot,"",{buttonLabel:Bt,buttonOnclick:e})}))},hide:function(){const t=document.querySelector(Ot);t&&t.remove()},cancel:function(){this.hide(),t&&t(!0)}}}();if(!await Xt.display()){const e=await function({accept:t}={accept:"image/*"}){const e=document.createElement("input");return e.type="file",e.accept=t,e.click(),new Promise((t=>{e.addEventListener("change",(e=>{if(e.target.files.length){const n=e.target.files[0],r=new FileReader;r.addEventListener("load",(async()=>{if("image/png"==n.type)t(new Uint8Array(r.result));else{const e=await new Promise((t=>{const e=new FileReader;e.addEventListener("load",(()=>t(e.result))),e.addEventListener("error",(()=>t())),e.readAsDataURL(n)}));if(e){const n=new Image;n.src=e,n.addEventListener("error",(()=>t())),await new Promise((t=>n.addEventListener("load",t)));const r=new OffscreenCanvas(n.width,n.height);r.getContext("2d").drawImage(n,0,0);const a=await r.convertToBlob({type:"image/png"}),o=new FileReader;o.addEventListener("load",(()=>t(new Uint8Array(o.result)))),o.addEventListener("error",(()=>t())),o.readAsArrayBuffer(a)}else t()}t(Array.from(new Uint8Array(r.result)))})),r.addEventListener("error",(()=>t())),r.readAsArrayBuffer(n)}else t()})),e.addEventListener("cancel",(()=>t()))}))}({accept:"image/*"});e&&(t.embeddedImage=Array.from(e)),Xt.hide(),function(t){Lt("insert-embedded-image",ut,"✓",t)}(t)}}if(!t.saveRawPage&&!Gt.cancelled){let n;if(t.loadDeferredImages&&(n=qt.processors.lazy.process(t),function(t){Lt("load-deferred-images",ct,"…",t)}(t),n.then((()=>{Gt.cancelled||function(t){Lt("load-deferred-images",ct,"✓",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){Lt("load-frames",lt,"…",t)}(t),n.then((()=>{Gt.cancelled||function(t){Lt("load-frames",lt,"✓",t)}(t)})),t.loadDeferredImagesBeforeFrames?t.frames=await new Promise((t=>{Gt.cancel=function(){i(),t([])},n.then(t)})):r.push(n)}t.loadDeferredImages&&!t.loadDeferredImagesBeforeFrames&&r.push(n)}t.loadDeferredImagesBeforeFrames||Gt.cancelled||([t.frames]=await new Promise((t=>{const e=Promise.all(r);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=wt("Infobar content",t.infobarContent)||""),c=await Gt.getPageData(),(t.selected||t.optionallySelected)&&document.querySelectorAll("["+Z+"]").forEach((t=>t.removeAttribute(Z))),gt(),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.saveToDropbox)&&e.confirmFilename&&(t.filename=wt("Save as",t.filename)||t.filename),await M(t,e))}catch(t){if(!Gt.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"});Vt=!1,zt&&(zt.pageInfo.processing=!1)}}(t),{};if("content.cancelSave"==t.method)return Gt&&(Gt.cancel(),gt(),Xt&&(Xt.cancel(),Xt=null),browser.runtime.sendMessage({method:"ui.processCancelled"})),t.options.loadDeferredImages&&qt.processors.lazy.resetZoomLevel(t.options),{};if("content.getSelectedLinks"==t.method)return{urls:At()};if("content.download"==t.method){_t||(_t=v());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 Ft(t.error,t.link),{};if("content.prompt"==t.method)return wt(t.message,t.value)}}(t)})),zt?zt.initializedSingleFile=!0:globalThis.singlefileBootstrap={initializedSingleFile:!0})}();