26 lines
771 B
JavaScript
26 lines
771 B
JavaScript
/**
|
|
* Fetch status content and insert main content into provided container
|
|
* @param {Element} containerEl Container to insert status into
|
|
*/
|
|
async function insertStatus(containerEl){
|
|
|
|
const baseUrl = new URL("/status/", containerEl.baseURI)
|
|
const res = await fetch(baseUrl);
|
|
|
|
if(!res.ok){
|
|
console.info(`Network error requesting status : ${res.status} ${res.statusText}`);
|
|
return;
|
|
}
|
|
|
|
const dom = new DOMParser().parseFromString(await res.text(), "text/html");
|
|
|
|
const main = dom.querySelector("main");
|
|
|
|
if(!main)
|
|
throw new Error("Status page does not contain a <main> element");
|
|
|
|
containerEl.innerHTML = main.innerHTML;
|
|
containerEl.className = main.className;
|
|
}
|
|
|
|
insertStatus(document.getElementById("status")) |