2021-01-05 18:16:23 +00:00
|
|
|
export function toggleTheme() {
|
2021-12-30 00:49:43 +00:00
|
|
|
document.documentElement.classList.toggle('dark');
|
|
|
|
document.documentElement.classList.toggle('light');
|
|
|
|
localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? "dark" : "light");
|
2021-01-05 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function loadTheme() {
|
|
|
|
const theme = localStorage.getItem("theme");
|
|
|
|
if (theme == "dark") {
|
2021-12-30 00:49:43 +00:00
|
|
|
document.documentElement.classList.add('dark');
|
|
|
|
document.documentElement.classList.remove('light');
|
2021-01-05 18:16:23 +00:00
|
|
|
} else if (theme == "light") {
|
2021-12-30 00:49:43 +00:00
|
|
|
document.documentElement.classList.add('light');
|
|
|
|
document.documentElement.classList.remove('dark');
|
2021-03-10 19:42:40 +00:00
|
|
|
} else if (window.matchMedia('(prefers-color-scheme: dark)').media !== 'not all') {
|
2021-12-30 00:49:43 +00:00
|
|
|
document.documentElement.classList.add('dark');
|
|
|
|
document.documentElement.classList.remove('light');
|
2021-01-05 18:16:23 +00:00
|
|
|
}
|
|
|
|
}
|