21 lines
467 B
JavaScript
21 lines
467 B
JavaScript
const KEY = 'filehost.theme';
|
|
|
|
export function currentTheme() {
|
|
return document.documentElement.classList.contains('dark') ? 'dark' : 'light';
|
|
}
|
|
|
|
export function applyTheme(theme) {
|
|
document.documentElement.classList.toggle('dark', theme === 'dark');
|
|
try {
|
|
localStorage.setItem(KEY, theme);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
|
|
export function toggleTheme() {
|
|
const next = currentTheme() === 'dark' ? 'light' : 'dark';
|
|
applyTheme(next);
|
|
return next;
|
|
}
|