(() => { const storageKey = "tacticusApiScraper.theme"; const root = document.documentElement; let theme = "light"; try { if (window.localStorage.getItem(storageKey) === "dark") { theme = "dark"; } } catch (error) { console.error("Could not read the saved theme preference:", error); } function applyTheme(nextTheme, savePreference) { theme = nextTheme; root.setAttribute("data-bs-theme", theme); const toggle = document.getElementById("theme-toggle"); if (toggle) { const targetTheme = theme === "dark" ? "light" : "dark"; toggle.textContent = `Switch to ${targetTheme} theme`; toggle.setAttribute("aria-label", `Switch to ${targetTheme} theme`); toggle.setAttribute("aria-pressed", String(theme === "dark")); } if (savePreference) { try { window.localStorage.setItem(storageKey, theme); } catch (error) { console.error("Could not save the theme preference:", error); } } } applyTheme(theme, false); document.addEventListener("DOMContentLoaded", () => { const toggle = document.getElementById("theme-toggle"); if (!toggle) { return; } toggle.addEventListener("click", () => { applyTheme(theme === "dark" ? "light" : "dark", true); }); applyTheme(theme, false); }); })();