oclaw/interfaces/admin/static/admin-theme.js
oliver cbd9942b0b Align Admin/Chat UI with NetX dark ops shell.
Add a netx theme preset as the default, variable-drive chrome styles, and keep legacy DeepSeek/other palettes available.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-11 03:25:48 +08:00

56 lines
1.6 KiB
JavaScript

/* Admin + standalone /chat: restore palette from localStorage before first paint. */
(function () {
const STORAGE_KEY = "oclaw_admin_theme";
const DEFAULT_THEME = "netx";
const THEMES = ["netx", "deepseek", "github", "nord", "dracula", "forest", "catppuccin", "light"];
const LEGIT = new Set(THEMES);
function applyAdminTheme(theme) {
const t = theme && LEGIT.has(theme) ? theme : DEFAULT_THEME;
if (t === "deepseek") document.body.removeAttribute("data-admin-theme");
else document.body.setAttribute("data-admin-theme", t);
}
function initAdminThemeFromStorage() {
let raw = DEFAULT_THEME;
try {
const stored = localStorage.getItem(STORAGE_KEY);
// Missing key → netx. Existing deepseek/github/… prefs are preserved.
raw = stored == null || stored === "" ? DEFAULT_THEME : stored;
} catch (_) {
raw = DEFAULT_THEME;
}
if (!LEGIT.has(raw)) raw = DEFAULT_THEME;
applyAdminTheme(raw);
return raw;
}
function persistAdminTheme(theme) {
const t = theme && LEGIT.has(theme) ? theme : DEFAULT_THEME;
try {
localStorage.setItem(STORAGE_KEY, t);
} catch (_) {}
applyAdminTheme(t);
}
function currentAdminTheme() {
try {
const v = localStorage.getItem(STORAGE_KEY);
if (v == null || v === "") return DEFAULT_THEME;
return LEGIT.has(v) ? v : DEFAULT_THEME;
} catch (_) {
return DEFAULT_THEME;
}
}
window.OclawAdminTheme = {
STORAGE_KEY,
DEFAULT_THEME,
THEMES,
applyAdminTheme,
initAdminThemeFromStorage,
persistAdminTheme,
currentAdminTheme,
};
initAdminThemeFromStorage();
})();