Revelav3/public/ultra/ultra.sw.js
2023-12-13 16:19:29 -05:00

4 lines
8.5 KiB
JavaScript

// @ts-nocheck
(()=>{var f=self.Ultraviolet,w=["cross-origin-embedder-policy","cross-origin-opener-policy","cross-origin-resource-policy","content-security-policy","content-security-policy-report-only","expect-ct","feature-policy","origin-isolation","strict-transport-security","upgrade-insecure-requests","x-content-type-options","x-download-options","x-frame-options","x-permitted-cross-domain-policies","x-powered-by","x-xss-protection"],S=["GET","HEAD"],b=class extends f.EventEmitter{constructor(e=__uv$config){super(),e.bare||(e.bare="/bare/"),e.prefix||(e.prefix="/service/"),this.config=e;let s=(Array.isArray(e.bare)?e.bare:[e.bare]).map(t=>new URL(t,location).toString());this.address=s[~~(Math.random()*s.length)],this.bareClient=new f.BareClient(this.address)}async fetch({request:e}){let s;try{if(!e.url.startsWith(location.origin+this.config.prefix))return await fetch(e);let t=new f(this.config,this.address);typeof this.config.construct=="function"&&this.config.construct(t,"service");let a=await t.cookie.db();t.meta.origin=location.origin,t.meta.base=t.meta.url=new URL(t.sourceUrl(e.url));let r=new g(e,this,t,S.includes(e.method.toUpperCase())?null:await e.blob());if(t.meta.url.protocol==="blob:"&&(r.blob=!0,r.base=r.url=new URL(r.url.pathname)),e.referrer&&e.referrer.startsWith(location.origin)){let n=new URL(t.sourceUrl(e.referrer));(r.headers.origin||t.meta.url.origin!==n.origin&&e.mode==="cors")&&(r.headers.origin=n.origin),r.headers.referer=n.href}let l=await t.cookie.getCookies(a)||[],c=t.cookie.serialize(l,t.meta,!1);r.headers["user-agent"]=navigator.userAgent,c&&(r.headers.cookie=c);let p=new m(r,null,null);if(this.emit("request",p),p.intercepted)return p.returnValue;s=r.blob?"blob:"+location.origin+r.url.pathname:r.url;let h=await this.bareClient.fetch(s,{headers:r.headers,method:r.method,body:r.body,credentials:r.credentials,mode:location.origin!==r.address.origin?"cors":r.mode,cache:r.cache,redirect:r.redirect}),o=new y(r,h),d=new m(o,null,null);if(this.emit("beforemod",d),d.intercepted)return d.returnValue;for(let n of w)o.headers[n]&&delete o.headers[n];if(o.headers.location&&(o.headers.location=t.rewriteUrl(o.headers.location)),e.destination==="document"){let n=o.headers["content-disposition"];if(!/\s*?((inline|attachment);\s*?)filename=/i.test(n)){let u=/^\s*?attachment/i.test(n)?"attachment":"inline",[v]=new URL(h.finalURL).pathname.split("/").slice(-1);o.headers["content-disposition"]=`${u}; filename=${JSON.stringify(v)}`}}if(o.headers["set-cookie"]&&(Promise.resolve(t.cookie.setCookies(o.headers["set-cookie"],a,t.meta)).then(()=>{self.clients.matchAll().then(function(n){n.forEach(function(u){u.postMessage({msg:"updateCookies",url:t.meta.url.href})})})}),delete o.headers["set-cookie"]),o.body)switch(e.destination){case"script":case"worker":{let n=[t.bundleScript,t.clientScript,t.configScript,t.handlerScript].map(u=>JSON.stringify(u)).join(",");o.body=`if (!self.__uv && self.importScripts) { ${t.createJsInject(this.address,this.bareClient.manifest,t.cookie.serialize(l,t.meta,!0),e.referrer)} importScripts(${n}); }
`,o.body+=t.js.rewrite(await h.text());break}case"style":o.body=t.rewriteCSS(await h.text());break;case"iframe":case"document":x(t.meta.url,o.headers["content-type"]||"")&&(o.body=t.rewriteHtml(await h.text(),{document:!0,injectHead:t.createHtmlInject(t.handlerScript,t.bundleScript,t.clientScript,t.configScript,this.address,this.bareClient.manifest,t.cookie.serialize(l,t.meta,!0),e.referrer)}))}return r.headers.accept==="text/event-stream"&&(o.headers["content-type"]="text/event-stream"),crossOriginIsolated&&(o.headers["Cross-Origin-Embedder-Policy"]="require-corp"),this.emit("response",d),d.intercepted?d.returnValue:new Response(o.body,{headers:o.headers,status:o.status,statusText:o.statusText})}catch(t){return["document","iframe"].includes(e.destination)?(console.error(t),k(t,s,this.address)):new Response(void 0,{status:500})}}static Ultraviolet=f};self.UVServiceWorker=b;var y=class{constructor(e,s){this.request=e,this.raw=s,this.ultraviolet=e.ultraviolet,this.headers={};for(let t in s.rawHeaders)this.headers[t.toLowerCase()]=s.rawHeaders[t];this.status=s.status,this.statusText=s.statusText,this.body=s.body}get url(){return this.request.url}get base(){return this.request.base}set base(e){this.request.base=e}},g=class{constructor(e,s,t,a=null){this.ultraviolet=t,this.request=e,this.headers=Object.fromEntries(e.headers.entries()),this.method=e.method,this.address=s.address,this.body=a||null,this.cache=e.cache,this.redirect=e.redirect,this.credentials="omit",this.mode=e.mode==="cors"?e.mode:"same-origin",this.blob=!1}get url(){return this.ultraviolet.meta.url}set url(e){this.ultraviolet.meta.url=e}get base(){return this.ultraviolet.meta.base}set base(e){this.ultraviolet.meta.base=e}};function x(i,e=""){return(f.mime.contentType(e||i.pathname)||"text/html").split(";")[0]==="text/html"}var m=class{#e;#t;constructor(e={},s=null,t=null){this.#e=!1,this.#t=null,this.data=e,this.target=s,this.that=t}get intercepted(){return this.#e}get returnValue(){return this.#t}respondWith(e){this.#t=e,this.#e=!0}};function C(i,e){let s=new URL(i),t=`remoteHostname.textContent = ${JSON.stringify(s.hostname)};bareServer.href = ${JSON.stringify(e)};uvHostname.textContent = ${JSON.stringify(location.hostname)};reload.addEventListener("click", () => location.reload());uvVersion.textContent = ${JSON.stringify("2.0.0")};`;return`<!DOCTYPE html><html><head><meta charset='utf-8' /><title>Error</title><link rel="stylesheet" href="uv.styles.css"/></head><body><h1>This site can\u2019t be reached</h1><hr /><p><b id="remoteHostname"></b>\u2019s server IP address could not be found.</p><p>Try:</p><ul><li>Verifying you entered the correct address</li><li>Clearing the site data</li><li>Contacting <b id="uvHostname"></b>'s administrator</li><li>Verifying the <a id='bareServer' title='Bare server'>Bare server</a> isn't censored</li></ul><button id="reload">Reload</button><hr /><p><i>Ultraviolet (Sodium Hybrid) v<span id="uvVersion"></span></i></p><script src="${"data:application/javascript,"+encodeURIComponent(t)}"><\/script></body></html>`}function E(i,e,s,t,a,r,l){if(t==="The specified host could not be resolved.")return C(r,l);let c=`errorTitle.textContent = ${JSON.stringify(i)};errorCode.textContent = ${JSON.stringify(e)};`+(s?`errorId.textContent = ${JSON.stringify(s)};`:"")+`errorMessage.textContent = ${JSON.stringify(t)};errorTrace.value = ${JSON.stringify(a)};fetchedURL.textContent = ${JSON.stringify(r)};bareServer.href = ${JSON.stringify(l)};for (const node of document.querySelectorAll("#uvHostname")) node.textContent = ${JSON.stringify(location.hostname)};reload.addEventListener("click", () => location.reload());uvVersion.textContent = ${JSON.stringify("2.0.0")};`;return`<!DOCTYPE html><html><head><meta charset='utf-8' /><title>Error</title><link rel="stylesheet" href="uv.styles.css"/></head><body><h1 id='errorTitle'></h1><hr /><p>Failed to load <b id="fetchedURL"></b></p><p id="errorMessage"></p><table><tbody><tr><td>Code:</td><td id="errorCode"></td></tr>`+(s?'<tr><td>ID:</td><td id="errorId"></td></tr>':"")+`</tbody></table><textarea id="errorTrace" cols="40" rows="10" readonly></textarea><p>Try:</p><ul><li>Checking your internet connection</li><li>Verifying you entered the correct address</li><li>Clearing the site data</li><li>Contacting <b id="uvHostname"></b>'s administrator</li><li>Verify the <a id='bareServer' title='Bare server'>Bare server</a> isn't censored</li></ul><p>If you're the administrator of <b id="uvHostname"></b>, try:</p><ul><li>Restarting your Bare server</li><li>Updating Ultraviolet</li><li>Troubleshooting the error on the <a href="https://github.com/titaniumnetwork-dev/Ultraviolet" target="_blank">GitHub repository</a></li></ul><button id="reload">Reload</button><hr /><p><i>Ultraviolet (Sodium Hybrid) v<span id="uvVersion"></span></i></p><script src="${"data:application/javascript,"+encodeURIComponent(c)}"><\/script></body></html>`}function U(i){return i instanceof Error&&typeof i.body=="object"}function k(i,e,s){let t,a,r,l="",c;return U(i)?(t=i.status,a="Error communicating with the Bare server",c=i.body.message,r=i.body.code,l=i.body.id):(t=500,a="Error processing your request",c="Internal Server Error",r=i instanceof Error?i.name:"UNKNOWN"),new Response(E(a,r,l,c,String(i),e,s),{status:t,headers:{"content-type":"text/html"}})}self.addEventListener("install",i=>{i.waitUntil(caches.open("uv-assets").then(e=>e.addAll(["uv.styles.css"])))});self.addEventListener("fetch",i=>{i.respondWith(caches.match(i.request).then(e=>e||fetch(i.request)))});})();
//# sourceMappingURL=uv.sw.js.map