Add files via upload
This commit is contained in:
parent
37a256934e
commit
5dba2c2c9f
1 changed files with 21 additions and 0 deletions
21
website/js/dark.js
Normal file
21
website/js/dark.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// Dark mode and local storage preference
|
||||||
|
|
||||||
|
function toggleDarkMode(useDark) {
|
||||||
|
if (useDark) {
|
||||||
|
document.documentElement.classList.add('dark');
|
||||||
|
document.documentElement.classList.remove('light');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.documentElement.classList.remove('dark');
|
||||||
|
document.documentElement.classList.add('light');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let useDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
if (!useDark && localStorage.getItem('dark-mode') === 'true') {
|
||||||
|
useDark = true;
|
||||||
|
toggleDarkMode(useDark);
|
||||||
|
}
|
||||||
|
else if (localStorage.getItem('dark-mode') === 'false') {
|
||||||
|
useDark = false;
|
||||||
|
toggleDarkMode(useDark);
|
||||||
|
}
|
Loading…
Reference in a new issue