labolyon.fr/js/status.js

26 lines
771 B
JavaScript
Raw Normal View History

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){
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"))