2023-06-10 22:24:21 +02:00
|
|
|
/**
|
|
|
|
* Fetch status content and insert main content into provided container
|
|
|
|
* @param {Element} containerEl Container to insert status into
|
|
|
|
*/
|
|
|
|
async function insertStatus(containerEl){
|
|
|
|
|
2023-08-16 01:33:10 +02:00
|
|
|
const baseUrl = containerEl.href;
|
2023-06-15 12:15:22 +02:00
|
|
|
const res = await fetch(baseUrl, {cache:"no-cache"});
|
2023-06-10 22:24:21 +02:00
|
|
|
|
|
|
|
if(!res.ok){
|
|
|
|
console.info(`Network error requesting status : ${res.status} ${res.statusText}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dom = new DOMParser().parseFromString(await res.text(), "text/html");
|
|
|
|
|
2023-08-16 01:33:10 +02:00
|
|
|
|
|
|
|
let base = dom.createElement("base");
|
|
|
|
base.href = containerEl.href;
|
|
|
|
dom.head.append(base);
|
|
|
|
|
2023-06-10 22:24:21 +02:00
|
|
|
const main = dom.querySelector("main");
|
|
|
|
|
|
|
|
if(!main)
|
|
|
|
throw new Error("Status page does not contain a <main> element");
|
|
|
|
|
2023-08-16 01:33:10 +02:00
|
|
|
for(let it of main.querySelectorAll("[href],[src]")){
|
|
|
|
if(it.hasAttribute("href")){
|
|
|
|
it.href = it.href
|
|
|
|
} else {
|
|
|
|
it.src = it.src
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
containerEl.innerHTML = "";
|
|
|
|
for(let node of main.childNodes){
|
|
|
|
containerEl.append(document.importNode(node, true));
|
|
|
|
}
|
2023-06-10 22:24:21 +02:00
|
|
|
containerEl.className = main.className;
|
|
|
|
}
|
|
|
|
|
|
|
|
insertStatus(document.getElementById("status"))
|