forked from nettleweb/nettleweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed.js
1 lines (1 loc) · 1.22 KB
/
embed.js
1
"use strict";(async({window:e,document:t})=>{"complete"!==t.readyState&&await new Promise((e=>{const o=()=>{"complete"===t.readyState&&(t.removeEventListener("readystatechange",o),setTimeout(e,500,null))};t.addEventListener("readystatechange",o,{passive:!0})}));const o=e.history,r=t.body,n=new DOMParser;if(null!=r&&"text/html"===t.contentType){r.textContent="Loading... (1)",await new Promise((e=>{setTimeout(e,1e3,null)})),r.textContent="Loading... (2)",e.stop(),e.focus(),o.scrollRestoration="manual",o.replaceState(void 0,"","/");try{const e=await fetch("/",{mode:"same-origin",cache:"no-cache",method:"GET",headers:{Accept:"text/html"}});if(!e.ok)throw new Error("Failed to fetch required resources");if("text/html"!==(e.headers.get("content-type")||"").split(";",2)[0].trim())throw new Error("Remote returned invalid response");const o=n.parseFromString(await e.text(),"application/xhtml+xml");o.title="NettleWeb",o.querySelector("script[src=\"main.js\"]").remove(),t.documentElement.replaceWith(o.documentElement);const r=o.createElement("script");r.type="text/javascript",r.src="main.js",t.body.appendChild(r)}catch(e){console.error(e),r.textContent="Error: Failed to load. Message: "+String(e)}}else console.error("Invalid document")})(self);