Moved status to ici.labolyon.fr

This commit is contained in:
EpicKiwi 2023-08-16 01:33:10 +02:00
parent 62f849e147
commit 05fa968c2f
Signed by: epickiwi
GPG Key ID: C4B28FD2729941CE
2 changed files with 19 additions and 3 deletions

View File

@ -57,7 +57,7 @@
</section> </section>
<section> <section>
<a href="/status/" id="status">Vérifier si le local est ouvert 🠖</a> <a href="http://ici.labolyon.fr/" id="status">Vérifier si le local est ouvert 🠖</a>
<script src="/js/status.js"></script> <script src="/js/status.js"></script>
</section> </section>

View File

@ -4,7 +4,7 @@
*/ */
async function insertStatus(containerEl){ async function insertStatus(containerEl){
const baseUrl = new URL("/status/", containerEl.baseURI) const baseUrl = containerEl.href;
const res = await fetch(baseUrl, {cache:"no-cache"}); const res = await fetch(baseUrl, {cache:"no-cache"});
if(!res.ok){ if(!res.ok){
@ -14,12 +14,28 @@ async function insertStatus(containerEl){
const dom = new DOMParser().parseFromString(await res.text(), "text/html"); const dom = new DOMParser().parseFromString(await res.text(), "text/html");
let base = dom.createElement("base");
base.href = containerEl.href;
dom.head.append(base);
const main = dom.querySelector("main"); const main = dom.querySelector("main");
if(!main) if(!main)
throw new Error("Status page does not contain a <main> element"); throw new Error("Status page does not contain a <main> element");
containerEl.innerHTML = main.innerHTML; 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));
}
containerEl.className = main.className; containerEl.className = main.className;
} }