OXYGENHUB
# addec2bd6423 oxygenhub / templates / backdrop.html
1.9 KiB · HTML · last changed Live arrivals on the sky 22 days ago source blame history raw
1
{# A backdrop (docs/backgrounds.md): the scene the page's
2
   `#backdrop-data` names (written just before this include) drawn by the
3
   engine, Rust compiled to WebAssembly. The viewer's choice (Settings › Appearance) is a cookie;
4
   unset, a touch-only device or Save-Data gets a still sky. Any failure
5
   leaves no backdrop and nothing else changed. A sky with `live` polls
6
   `/sky/arrivals` for what happened since and adds it. #}
7
<canvas id="backdrop" aria-hidden="true"></canvas>
8
<script type="module">
9
const canvas = document.getElementById("backdrop");
10
const chosen = document.cookie.match(/(?:^|; )backdrop=(moving|still|off)/);
11
const touch = matchMedia("(pointer: coarse)").matches && !matchMedia("(pointer: fine)").matches;
12
const pick = chosen ? chosen[1] : (touch || (navigator.connection && navigator.connection.saveData) ? "still" : "moving");
13
if (pick === "off") {
14
  canvas.remove();
15
} else {
16
  try {
17
    const bd = await import("/static/backdrop/backdrop.js?v={{ shell.assets() }}");
18
    await bd.default({ module_or_path: "/static/backdrop/backdrop_bg.wasm?v={{ shell.assets() }}" });
19
    const data = JSON.parse(document.getElementById("backdrop-data").textContent);
20
    bd.start(canvas, data, pick === "still");
21
    // Live (§5): a sky that names its repositories (`mine` or `hub`) asks
22
    // every 30 s, while the page is shown, what happened since.
23
    if (data.live) {
24
      let since = data.now;
25
      const poll = async () => {
26
        if (document.hidden) return;
27
        try {
28
          const r = await fetch(`/sky/arrivals?scene=${data.live}&since=${since}`, { headers: { accept: "application/json" } });
29
          if (!r.ok) return;
30
          const got = await r.json();
31
          since = got.now;
32
          if (got.events.length) bd.arrive(got);
33
        } catch (e) {}
34
      };
35
      setInterval(poll, 30000);
36
      document.addEventListener("visibilitychange", poll);
37
    }
38
  } catch (e) {
39
    canvas.remove();
40
  }
41
}
42
</script>