First Commit

This commit is contained in:
cesnimda
2026-03-21 11:55:27 +01:00
commit 2e8a29b4d0
1757 changed files with 166084 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import { decodeJwtPayload, getAuthToken } from "./auth";
export type ThemeModePref = "system" | "light" | "dark";
export function getUserKeyFromToken(): string {
const token = getAuthToken();
if (!token) return "anon";
const payload = decodeJwtPayload(token) ?? {};
const candidates = [
payload.sub,
payload.nameid,
payload["nameid"],
payload["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"],
payload["http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid"],
];
for (const c of candidates) {
if (typeof c === "string" && c.trim().length > 0) return c.trim();
}
return "anon";
}
function k(base: string) {
return `${base}:${getUserKeyFromToken()}`;
}
export function getThemeModePref(): ThemeModePref {
const raw = window.localStorage.getItem(k("themeMode"));
if (raw === "light" || raw === "dark" || raw === "system") return raw;
return "system";
}
export function setThemeModePref(v: ThemeModePref) {
window.localStorage.setItem(k("themeMode"), v);
}
export function getAccentColor(): string {
const raw = window.localStorage.getItem(k("accentColor"));
if (raw && /^#[0-9a-fA-F]{6}$/.test(raw)) return raw;
return "#7c4dff";
}
export function setAccentColor(v: string) {
if (v && /^#[0-9a-fA-F]{6}$/.test(v)) window.localStorage.setItem(k("accentColor"), v);
}
export function clearAccentColor() {
window.localStorage.removeItem(k("accentColor"));
}