You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
551 B
19 lines
551 B
export const script = (mode: string) => {
|
|
const documentElement = document.documentElement;
|
|
|
|
function getSystemColorMode() {
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
? 'dark'
|
|
: 'light';
|
|
}
|
|
|
|
try {
|
|
const isSystem = mode === 'system';
|
|
const theme = isSystem ? getSystemColorMode() : mode;
|
|
documentElement.classList.remove(theme === 'light' ? 'dark' : 'light');
|
|
documentElement.classList.add(theme);
|
|
documentElement.style.colorScheme = theme;
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
};
|