(function () { var LIGHT = "light"; var DARK = "dark"; var AUTO = "auto"; var MANAGER_THEME_KEY = "managerTheme"; function isManagerPage() { return /(^|\/)manager(?:[-.]|$)|(^|\/)admin(?:[-.]|$)/i.test(window.location.pathname || ""); } function getSystemTheme() { return window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches ? LIGHT : DARK; } function setTheme(theme) { var root = document.documentElement; root.setAttribute("data-auto-theme", theme); root.style.colorScheme = theme; } function normalizeManagerThemeMode(value) { return value === LIGHT || value === DARK || value === AUTO ? value : AUTO; } function resolveManagerTheme(mode) { return mode === AUTO ? getSystemTheme() : mode; } function applyManagerTheme(mode) { var safeMode = normalizeManagerThemeMode(mode); var resolved = resolveManagerTheme(safeMode); document.documentElement.dataset.theme = resolved; document.documentElement.setAttribute("data-theme-mode", safeMode); try { window.localStorage.setItem(MANAGER_THEME_KEY, safeMode); } catch (error) {} } function readManagerThemeMode() { try { return normalizeManagerThemeMode(window.localStorage.getItem(MANAGER_THEME_KEY)); } catch (error) { return AUTO; } } function installThemeStyles() { if (document.getElementById("auto-theme-light-mode")) return; var style = document.createElement("style"); style.id = "auto-theme-light-mode"; style.textContent = [ "html {", " background: #060a12 !important;", "}", "body {", " background: #060a12 !important;", "}", "html::before,", "html::after {", " content: '';", " position: fixed;", " left: 0;", " right: 0;", " background: #060a12;", " pointer-events: none;", " z-index: 2147483647;", "}", "html::before {", " top: 0;", " height: calc(env(safe-area-inset-top, 0px) + 14px);", "}", "html::after {", " bottom: 0;", " height: calc(env(safe-area-inset-bottom, 0px) + 14px);", "}", "html[data-auto-theme='light'] body {", " filter: invert(1) hue-rotate(180deg);", "}", "html[data-auto-theme='light'] img,", "html[data-auto-theme='light'] video,", "html[data-auto-theme='light'] iframe,", "html[data-auto-theme='light'] canvas,", "html[data-auto-theme='light'] svg,", "html[data-auto-theme='light'] picture,", "html[data-auto-theme='light'] [data-no-theme-invert='true'] {", " filter: invert(1) hue-rotate(180deg);", "}", "html[data-auto-theme='light'] ::-webkit-scrollbar-thumb {", " background: rgba(120, 138, 170, 0.55);", "}" ].join("\n"); document.head.appendChild(style); } function upsertThemeColorMeta() { var metas = Array.prototype.slice.call(document.querySelectorAll('meta[name="theme-color"]')); metas.forEach(function (node) { if (node.parentNode) node.parentNode.removeChild(node); }); var generic = document.createElement("meta"); generic.setAttribute("name", "theme-color"); generic.setAttribute("content", "#060a12"); document.head.appendChild(generic); var dark = document.createElement("meta"); dark.setAttribute("name", "theme-color"); dark.setAttribute("media", "(prefers-color-scheme: dark)"); dark.setAttribute("content", "#060a12"); document.head.appendChild(dark); var light = document.createElement("meta"); light.setAttribute("name", "theme-color"); light.setAttribute("media", "(prefers-color-scheme: light)"); light.setAttribute("content", "#060a12"); document.head.appendChild(light); } function syncManagerThemeFromSettings() { if (!isManagerPage()) return; fetch("/api/settings", { cache: "no-store" }) .then(function (res) { return res.ok ? res.json() : null; }) .then(function (settings) { var mode = normalizeManagerThemeMode(settings && settings.managerTheme); applyManagerTheme(mode); }) .catch(function () {}); } function initialize() { var onManagerPage = isManagerPage(); installThemeStyles(); upsertThemeColorMeta(); if (onManagerPage) { var initialMode = readManagerThemeMode(); applyManagerTheme(initialMode); syncManagerThemeFromSettings(); setTimeout(function () { applyManagerTheme(readManagerThemeMode()); }, 120); setTimeout(function () { applyManagerTheme(readManagerThemeMode()); }, 600); setTimeout(function () { applyManagerTheme(readManagerThemeMode()); }, 1400); } else { setTheme(getSystemTheme()); } if (window.matchMedia) { var media = window.matchMedia("(prefers-color-scheme: light)"); var onChange = function () { if (onManagerPage) { if (readManagerThemeMode() === AUTO) { applyManagerTheme(AUTO); } } else { setTheme(getSystemTheme()); } upsertThemeColorMeta(); }; if (typeof media.addEventListener === "function") { media.addEventListener("change", onChange); } else if (typeof media.addListener === "function") { media.addListener(onChange); } } } document.documentElement.style.backgroundColor = "#060a12"; document.documentElement.style.colorScheme = "dark"; initialize(); })();