| 1 |
- !function(){"use strict";const e=33554432,t=globalThis.singlefileBootstrap,o=new Map;let n,a,r,s,d,i,c,l,u,m,h,f,v,p;async function E(){if(document.documentElement.dataset&&void 0!==document.documentElement.dataset.sfz){const e=await g();document.querySelectorAll("#sfz-error-message").forEach((e=>e.remove())),function(e){document.dispatchEvent(new CustomEvent("single-file-bootstrap",{detail:{data:e}}))}(e)}else if(document.body&&1==document.body.childNodes.length&&"PRE"==document.body.childNodes[0].tagName&&/<html[^>]* data-sfz[^>]*>/i.test(document.body.childNodes[0].textContent)){const e=(new DOMParser).parseFromString(document.body.childNodes[0].textContent,"text/html");document.replaceChild(e.documentElement,document.documentElement),document.querySelectorAll("script").forEach((e=>{const t=document.createElement("script");t.textContent=e.textContent,e.parentElement.replaceChild(t,e)})),await E()}}function g(){return new Promise(((e,t)=>{const n=new XMLHttpRequest;n.open("GET",location.href),n.send(),n.responseType="arraybuffer",n.onload=()=>e(new Uint8Array(n.response)),n.onerror=()=>{const n=document.getElementById("sfz-error-message");n&&n.remove();const a=o.size;o.set(a,{resolve:e,reject:t}),browser.runtime.sendMessage({method:"singlefile.fetch",requestId:a,url:location.href})}}))}async function y(e){return d&&"content.autosave"==e.method?(async function(e){a=e.options,"complete"!=document.readyState&&await new Promise((e=>globalThis.addEventListener("load",e)));await b(),a.autoSaveRepeat&&setTimeout((()=>{d&&!c&&(l=!1,a.autoSaveDelay=0,y(e))}),1e3*a.autoSaveRepeatDelay)}(e),{}):"content.maybeInit"==e.method?(S(),{}):"content.init"==e.method?(a=e.options,d=e.autoSaveEnabled,w(),{}):"content.openEditor"==e.method?(M(document)?D(document):w(),{}):"devtools.resourceCommitted"==e.method?(t.pageInfo.updatedResources[e.url]={content:e.content,type:e.type,encoding:e.encoding},{}):"singlefile.fetchResponse"==e.method?await async function(e){const t=o.get(e.requestId);if(t)return e.error?(t.reject(new Error(e.error)),o.delete(e.requestId)):(e.truncated&&(t.array?t.array=t.array.concat(e.array):(t.array=e.array,o.set(e.requestId,t)),e.finished&&(e.array=t.array)),e.truncated&&!e.finished||(t.resolve(e.array),o.delete(e.requestId))),{}}(e):void 0}function S(){const e=document.querySelector("singlefile-infobar");e&&e.remove(),u==location.href||t.pageInfo.processing||(l=!1,u=location.href,browser.runtime.sendMessage({method:"tabs.init",savedPageDetected:M(document)}).catch((()=>{})),browser.runtime.sendMessage({method:"ui.processInit"}).catch((()=>{})))}async function b(){const e=t.helper;if((!c||i)&&!l)if(c=!0,a.autoSaveDelay&&!i)await new Promise((e=>i=setTimeout(e,1e3*a.autoSaveDelay))),await b();else{const o=globalThis[e.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];let n,r=[];i=null,!a.removeFrames&&globalThis.frames&&globalThis.frames.length&&(r=await t.processors.frameTree.getAsync(a)),n=r&&r.sessionId,a.userScriptEnabled&&o&&await o(e.ON_BEFORE_CAPTURE_EVENT_NAME);const s=e.preProcessDoc(document,globalThis,a);A(s,r),n&&t.processors.frameTree.cleanup(n),e.postProcessDoc(document,s.markedElements,s.invalidElements),a.userScriptEnabled&&o&&await o(e.ON_AFTER_CAPTURE_EVENT_NAME),l=!0,c=!1}}function w(){d&&a&&(a.autoSaveUnload||a.autoSaveLoadOrUnload||a.autoSaveDiscard||a.autoSaveRemove)?n||(globalThis.addEventListener("unload",T),document.addEventListener("visibilitychange",R),n=!0):(globalThis.removeEventListener("unload",T),document.removeEventListener("visibilitychange",R),n=!1)}function R(){"hidden"==document.visibilityState&&a.autoSaveDiscard&&C({autoSaveDiscard:a.autoSaveDiscard})}function T(){!l&&(a.autoSaveUnload||a.autoSaveLoadOrUnload||a.autoSaveRemove)&&C({autoSaveUnload:a.autoSaveUnload,autoSaveRemove:a.autoSaveRemove})}function C({autoSaveUnload:e,autoSaveDiscard:o,autoSaveRemove:n}){const r=t.helper,s=globalThis[r.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];let d=[];!a.removeFrames&&globalThis.frames&&globalThis.frames.length&&(d=t.processors.frameTree.getSync(a)),a.userScriptEnabled&&s&&s(r.ON_BEFORE_CAPTURE_EVENT_NAME);A(r.preProcessDoc(document,globalThis,a),d,{autoSaveUnload:e,autoSaveDiscard:o,autoSaveRemove:n})}function A(e,o,{autoSaveUnload:n,autoSaveDiscard:d,autoSaveRemove:i}={}){const c=t.helper,l=t.pageInfo.updatedResources,u=t.pageInfo.visitDate.getTime();Object.keys(l).forEach((e=>l[e].retrieved=!1)),browser.runtime.sendMessage({method:"autosave.save",tabId:r,tabIndex:s,taskId:a.taskId,content:c.serialize(document),canvases:e.canvases,fonts:e.fonts,stylesheets:e.stylesheets,images:e.images,posters:e.posters,usedFonts:e.usedFonts,shadowRoots:e.shadowRoots,videos:e.videos,referrer:e.referrer,adoptedStyleSheets:e.adoptedStyleSheets,worklets:e.worklets,frames:o,url:location.href,updatedResources:l,visitDate:u,autoSaveUnload:n,autoSaveDiscard:d,autoSaveRemove:i})}async function D(o){let n;h?n=await g():(O(o),n=t.helper.serialize(o));for(let t=0;t*e<n.length;t++){const o={method:"editor.open",filename:decodeURIComponent(location.href.match(/^.*\/(.*)$/)[1]),compressContent:h,extractDataFromPageTags:f,insertTextBody:v,insertMetaCSP:p,selfExtractingArchive:h};o.truncated=n.length>e,o.truncated?(o.finished=(t+1)*e>n.length,n instanceof Uint8Array?o.content=Array.from(n.subarray(t*e,(t+1)*e)):o.content=n.substring(t*e,(t+1)*e)):(o.embeddedImage=await I(n),o.content=n instanceof Uint8Array?Array.from(n):n),await browser.runtime.sendMessage(o)}}async function I(e){if(137==e[0]&&80==e[1]&&78==e[2]&&71==e[3]){let t=new Blob([new Uint8Array(e)],{type:"image/png"});const o=URL.createObjectURL(t),n=new Image;n.src=o,await new Promise(((e,t)=>{n.onload=e,n.onerror=t}));const a=new OffscreenCanvas(n.width,n.height);a.getContext("2d").drawImage(n,0,0),t=await a.convertToBlob({type:"image/png"});const r=await t.arrayBuffer();return Array.from(new Uint8Array(r))}}function M(e){if(void 0===m){const o=t.helper,n=e.documentElement.firstChild;h=e.documentElement.dataset&&""==e.documentElement.dataset.sfz,f=Boolean(e.querySelector("sfz-extra-data")),v=Boolean(e.querySelector("body > main[hidden]")),p=Boolean(e.querySelector("meta[http-equiv=content-security-policy]")),m=h||n.nodeType==Node.COMMENT_NODE&&(n.textContent.includes(o.COMMENT_HEADER)||n.textContent.includes(o.COMMENT_HEADER_LEGACY))}return m}function O(e){e.querySelectorAll("*").forEach((e=>{const o=t.helper.getShadowRoot(e);if(o){O(o);const t=document.createElement("template");t.setAttribute("shadowrootmode","open"),Array.from(o.childNodes).forEach((e=>t.appendChild(e))),e.appendChild(t)}}))}t.pageInfo={updatedResources:{},visitDate:new Date},browser.runtime.sendMessage({method:"bootstrap.init"}).then((e=>{a=e.optionsAutoSave;const t=e.options;r=e.tabId,s=e.tabIndex,d=e.autoSaveEnabled,t&&t.autoOpenEditor&&M(document)?"loading"==document.readyState?document.addEventListener("DOMContentLoaded",(()=>D(document))):D(document):"loading"==document.readyState?document.addEventListener("DOMContentLoaded",w):w()})),browser.runtime.onMessage.addListener((e=>{if(d&&"content.autosave"==e.method||"content.maybeInit"==e.method||"content.init"==e.method||"content.openEditor"==e.method||"devtools.resourceCommitted"==e.method||"singlefile.fetchResponse"==e.method)return y(e)})),document.addEventListener("DOMContentLoaded",S,!1),globalThis.window==globalThis.top&&location&&location.href&&(location.href.startsWith("file://")||location.href.startsWith("content://"))&&("loading"==document.readyState?document.addEventListener("DOMContentLoaded",E,!1):E())}();
|