// SPDX-License-Identifier: GPL-3.0-or-later /* === Theme toggle === */ function currentTheme() { try { return localStorage.getItem("ld-theme") || "auto"; } catch { return "auto"; } } /* Theme button icon: crescent for dark, sun for light — each wrapped in the .ico pattern so the emoji shows only if inline SVG ever fails to render. */ const THEME_ICON_MOON = '🌙'; const THEME_ICON_SUN = '☀️'; const THEME_ICON_TERM = '>_'; /* Browser chrome (mobile address bar, PWA titlebar) follows the theme. */ const THEME_BG = { dark: "#080a11", light: "#f4f6fa", terminal: "#060906" }; function applyTheme() { const t = currentTheme(); const theme = t === "terminal" ? "terminal" : t === "dark" || (t === "auto" && window.matchMedia("(prefers-color-scheme: dark)").matches) ? "dark" : "light"; document.documentElement.setAttribute("data-theme", theme); const meta = document.querySelector('meta[name="theme-color"]'); if (meta) meta.setAttribute("content", THEME_BG[theme] || THEME_BG.dark); const btn = $("#theme"); if (btn) { btn.innerHTML = '"; btn.title = "Theme: " + t + " \u2014 click to change"; } } function cycleTheme() { const next = THEME_ORDER[(THEME_ORDER.indexOf(currentTheme()) + 1) % THEME_ORDER.length]; try { localStorage.setItem("ld-theme", next); } catch {} applyTheme(); }