-
Notifications
You must be signed in to change notification settings - Fork 1
/
import-html.old.js
1 lines (1 loc) · 1.08 KB
/
import-html.old.js
1
const htmlBody=document.querySelector("body");class HtmlImport extends HTMLElement{constructor(){super();const e=this.dataset.src,t=new XMLHttpRequest;try{if(e.split(".").includes("html"))return t.addEventListener("load",this.reqListener),t.addEventListener("loadend",this.errorHandler),t.open("GET",e),t.responseType="text",void t.send();let n=document.createElement("div");n.innerHTML=errorMessage(`this file ${e} is not HTML`),htmlBody.appendChild(n)}catch(e){console.log(e)}}reqListener(){if(404===this.status){const e=location.href.split("/");e.pop();const t=e.join("/");let n=document.createElement("div");n.innerHTML=errorMessage(this.responseURL.replace(t,"~")),console.log(this.responseURL.replace(t,"~")),htmlBody.appendChild(n)}else{let e=document.createElement("div");e.innerHTML=this.responseText,htmlBody.appendChild(e)}}errorHandler(){if(404===this.status)throw console.log("Eror here",this),node.innerHTML="Cannot File",new Error(`cannot ${this.responseURL} ile`)}}const errorMessage=e=>`<code style="color:red">Hey,\n <b> ${e}</b>\n </code>`;customElements.define("import-html",HtmlImport);