Files
horizon-airdef/website/src/chrome.js
T
Ludovic Marie aae60c16ba Website: a Releases page, "Recently added" on the home page, and a Benchmarks page
- /releases: every game and launcher release on one page, newest first, Stable / Alpha / Launcher marked and
  filterable. The newest three are open; each shows what it added and fixed, the full notes, its downloads and
  a link to GitHub. Baked at build time, refreshed from GitHub when a newer release is out. /releases#release-<tag>
  opens one.
- Home: "Recently added" replaces the patch notes block: the last five releases on one line each and three
  highlights from what they added.
- /benchmarks: Horizon against vanilla Java Edition 26.3 measured on our machines (average FPS, 1% lows, p95
  frame time, start to world, chunk loads, memory, at render distance 12 and 32), saying where Java is ahead;
  a GPU + CPU picker that shows a measurement when there is one and otherwise a marked estimate with a range,
  from our own spec table (method explained on the page); players' results read live from the telemetry
  server's GET /v1/benchmarks/summary, falling back to the baked public/benchmarks.json, groups of 3+ installs
  only.
- scripts/benchmarks.mjs builds public/benchmarks.json from our reports (and, for tests, telemetry items) with
  the same rules as the server; fixtures shared with the server's test.
- Releases and Benchmarks in the nav and footer; docs/performance.md links the page.
- Pixelify Sans' "fi" ligature drew "fixes" as "Axes": common ligatures off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 21:43:36 +02:00

91 lines
3.5 KiB
JavaScript

// What every page with the site's top bar shares: the light and dark switch and the phone menu.
// Used by main.js (the home page) and page.js (Releases, Benchmarks).
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
// The page follows the system; the toggle picks the other appearance and remembers it.
export function setUpTheme() {
const root = document.documentElement;
const button = document.querySelector(".theme-toggle");
if (!button) return;
const label = button.querySelector("[data-theme-label]");
const system = matchMedia("(prefers-color-scheme: dark)");
const dark = () => (root.dataset.theme ? root.dataset.theme === "dark" : system.matches);
const show = () => (label.textContent = dark() ? "Light" : "Dark");
button.addEventListener("click", () => {
root.dataset.theme = dark() ? "light" : "dark";
try {
localStorage.setItem("theme", root.dataset.theme);
} catch {}
show();
});
system.addEventListener("change", show);
show();
}
// The phone menu: a full-screen sheet; the page behind it is inert while it is open.
export function setUpMenu() {
const bar = document.querySelector(".nav");
const button = document.querySelector(".menu-button");
const menu = document.getElementById("menu");
const main = document.getElementById("main");
if (!bar || !button || !menu) return;
const label = button.querySelector(".menu-label");
const items = [...menu.querySelectorAll("nav a")];
items.forEach((a, i) => a.style.setProperty("transition-delay", `${60 + i * 35}ms`));
let closing;
const setOpen = (open) => {
clearTimeout(closing);
button.setAttribute("aria-expanded", String(open));
label.textContent = open ? "Close" : "Menu";
bar.classList.toggle("is-menu", open);
main.inert = open;
document.body.style.overflow = open ? "hidden" : "";
if (open) {
menu.hidden = false;
requestAnimationFrame(() => requestAnimationFrame(() => menu.classList.add("is-open")));
items[0].focus({ preventScroll: true });
} else {
menu.classList.remove("is-open");
closing = setTimeout(() => (menu.hidden = true), reducedMotion ? 0 : 320);
}
};
button.addEventListener("click", () => setOpen(button.getAttribute("aria-expanded") !== "true"));
items.forEach((a) => a.addEventListener("click", () => setOpen(false)));
addEventListener("keydown", (e) => {
if (e.key === "Escape" && button.getAttribute("aria-expanded") === "true") {
setOpen(false);
button.focus();
}
});
matchMedia("(min-width: 1120px)").addEventListener("change", (e) => e.matches && setOpen(false));
}
// GitHub answers, cached for ten minutes in the tab.
export async function cached(key, load) {
try {
const hit = JSON.parse(sessionStorage.getItem(key) || "null");
if (hit && Date.now() - hit.at < 10 * 60 * 1000) return hit.value;
} catch {}
const value = await load();
try {
sessionStorage.setItem(key, JSON.stringify({ at: Date.now(), value }));
} catch {}
return value;
}
export async function get(url, as = "json") {
const res = await fetch(url, { headers: as === "json" ? { Accept: "application/vnd.github+json" } : {} });
if (!res.ok) throw new Error(`${res.status}`);
return as === "json" ? res.json() : res.text();
}
export const slim = (r) => ({
tag_name: r.tag_name,
name: r.name,
published_at: r.published_at,
html_url: r.html_url,
prerelease: r.prerelease,
body: r.body || "",
assets: (r.assets || []).map((a) => ({ name: a.name, browser_download_url: a.browser_download_url, size: a.size })),
});