OXYGENHUB
# f993f792537e oxygenhub / templates / backdrop.html
1.2 KiB · HTML · last changed feat(web): the mark, ripples, the swarm and adrift (closes #167) 23 days ago source blame history raw
6246d1e5 Andy McCall ↶ 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;
0a3b244b Andy McCall ↶ 4
   unset, a touch-only device or Save-Data gets a still sky. Any failure
5
   leaves no backdrop and nothing else changed. #}
6
<canvas id="backdrop" aria-hidden="true"></canvas>
7
<script type="module">
8
const canvas = document.getElementById("backdrop");
9
const chosen = document.cookie.match(/(?:^|; )backdrop=(moving|still|off)/);
10
const touch = matchMedia("(pointer: coarse)").matches && !matchMedia("(pointer: fine)").matches;
11
const pick = chosen ? chosen[1] : (touch || (navigator.connection && navigator.connection.saveData) ? "still" : "moving");
12
if (pick === "off") {
13
  canvas.remove();
14
} else {
15
  try {
16
    const bd = await import("/static/backdrop/backdrop.js?v={{ shell.assets() }}");
17
    await bd.default({ module_or_path: "/static/backdrop/backdrop_bg.wasm?v={{ shell.assets() }}" });
18
    bd.start(canvas, JSON.parse(document.getElementById("backdrop-data").textContent), pick === "still");
19
  } catch (e) {
20
    canvas.remove();
21
  }
22
}
23
</script>