Moved status to ici.labolyon.fr
This commit is contained in:
parent
62f849e147
commit
05fa968c2f
@ -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>
|
||||||
|
|
||||||
|
20
js/status.js
20
js/status.js
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user