/* Starts the page's backdrop (docs/backgrounds.md); a module of its own for the CSP (#227). The assets' version comes from this file's own address. */ const v = new URL(import.meta.url).search; const canvas = document.getElementById("backdrop"); const chosen = document.cookie.match(/(?:^|; )backdrop=(moving|still|off)/); const touch = matchMedia("(pointer: coarse)").matches && !matchMedia("(pointer: fine)").matches; const pick = chosen ? chosen[1] : (touch || (navigator.connection && navigator.connection.saveData) ? "still" : "moving"); if (pick === "off") { canvas.remove(); } else { try { const bd = await import(`/static/backdrop/backdrop.js${v}`); await bd.default({ module_or_path: `/static/backdrop/backdrop_bg.wasm${v}` }); const data = JSON.parse(document.getElementById("backdrop-data").textContent); bd.start(canvas, data, pick === "still"); // Live (ยง5): a sky that names its repositories (`mine` or `hub`) asks // every 30 s, while the page is shown, what happened since. if (data.live) { let since = data.now; const poll = async () => { if (document.hidden) return; try { const r = await fetch(`/sky/arrivals?scene=${data.live}&since=${since}`, { headers: { accept: "application/json" } }); if (!r.ok) return; const got = await r.json(); since = got.now; if (got.events.length) bd.arrive(got); } catch (e) {} }; setInterval(poll, 30000); document.addEventListener("visibilitychange", poll); } } catch (e) { canvas.remove(); } }