single-file-extension-frames.js 2.9 KB

1
  1. !function(){"use strict";const e=globalThis.document;if(e instanceof globalThis.Document){let n=e.createElement("script");n.src="data:,("+t.toString()+")()",(e.documentElement||e).appendChild(n),n.remove(),n=e.createElement("script"),n.textContent="("+t.toString()+")()",(e.documentElement||e).appendChild(n),n.remove()}function t(){"undefined"==typeof globalThis&&(window.globalThis=window);const e=globalThis.document,t=globalThis.CustomEvent,n=globalThis.FileReader,r=globalThis.Blob,a={family:"font-family",style:"font-style",weight:"font-weight",stretch:"font-stretch",unicodeRange:"unicode-range",variant:"font-variant",featureSettings:"font-feature-settings"};if(globalThis.FontFace){const n=globalThis.FontFace;globalThis.FontFace=function(){return o(...arguments).then((n=>e.dispatchEvent(new t("single-file-new-font-face",{detail:n})))),new n(...arguments)},globalThis.FontFace.prototype=n.prototype,globalThis.FontFace.toString=function(){return"function FontFace() { [native code] }"};const r=e.fonts.delete;e.fonts.delete=function(n){return o(n.family).then((n=>e.dispatchEvent(new t("single-file-delete-font",{detail:n})))),r.call(e.fonts,n)},e.fonts.delete.toString=function(){return"function delete() { [native code] }"};const a=e.fonts.clear;e.fonts.clear=function(){return e.dispatchEvent(new t("single-file-clear-fonts")),a.call(e.fonts)},e.fonts.clear.toString=function(){return"function clear() { [native code] }"}}async function o(e,t,o){const s={};return s["font-family"]=e,s.src=t,o&&Object.keys(o).forEach((e=>{a[e]&&(s[a[e]]=o[e])})),new Promise((e=>{if(s.src instanceof ArrayBuffer){const t=new n;t.readAsDataURL(new r([s.src])),t.addEventListener("load",(()=>{s.src="url("+t.result+")",e(s)}))}else e(s)}))}}const n=globalThis.browser,r=globalThis.document;if(r instanceof globalThis.Document&&n&&n.runtime&&n.runtime.getURL){const e=r.createElement("script");e.src=n.runtime.getURL("/lib/single-file-hooks-frames.js"),e.async=!1,(r.documentElement||r).appendChild(e),e.remove()}const a=window.fetch.bind(window);let o=new Map;browser.runtime.onMessage.addListener((e=>"singlefile.fetchFrame"==e.method&&window.frameId&&window.frameId==e.frameId?async function(e){try{const t=await a(e.url,{cache:"force-cache",headers:e.headers,referrerPolicy:"strict-origin-when-cross-origin"});return{status:t.status,headers:[...t.headers],array:Array.from(new Uint8Array(await t.arrayBuffer()))}}catch(e){return{error:e&&(e.message||e.toString())}}}(e):"singlefile.fetchResponse"==e.method?async function(e){const t=o.get(e.requestId);t&&(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({status:e.status,headers:{get:t=>e.headers&&e.headers[t]},arrayBuffer:async()=>new Uint8Array(e.array).buffer}),o.delete(e.requestId))));return{}}(e):void 0))}();