mirror of
https://github.com/NotXia/notxia.github.io.git
synced 2025-12-15 19:22:21 +01:00
22 lines
701 B
TypeScript
22 lines
701 B
TypeScript
export function getTheme():string {
|
|
return localStorage.getItem("theme") ?? "dark";
|
|
}
|
|
|
|
export function setTheme(theme:string):void {
|
|
if (theme !== "dark" && theme !== "light") { theme = "dark"; }
|
|
localStorage.setItem("theme", theme);
|
|
}
|
|
|
|
export function flipTheme():void {
|
|
setTheme(getTheme() === "dark" ? "light" : "dark");
|
|
}
|
|
|
|
export function applyTheme(theme?:string):void {
|
|
if (!theme) { theme = getTheme(); }
|
|
|
|
switch (theme) {
|
|
case "dark": document.documentElement.classList.add("dark"); break;
|
|
case "light": document.documentElement.classList.remove("dark"); break;
|
|
default: document.documentElement.classList.add("dark"); break;
|
|
}
|
|
} |