dark theme stuff owo
This commit is contained in:
parent
329ac23ca2
commit
00e202978d
7 changed files with 294 additions and 121 deletions
|
@ -11,3 +11,33 @@ links.forEach((link) => {
|
|||
}, 3 * 1000);
|
||||
});
|
||||
*/
|
||||
let scheme = window.matchMedia(`(prefers-color-scheme: dark)`);
|
||||
let theme = window.localStorage.getItem('prefer-light');
|
||||
let title = document.getElementsByClassName('title')[0];
|
||||
let body = document.getElementsByTagName('body')[0];
|
||||
|
||||
if (theme === 'yes') {
|
||||
body.classList.add('light');
|
||||
} else if (theme === 'no') {
|
||||
console.log('User does not like light, removing Light');
|
||||
body.classList.remove('light');
|
||||
} else {
|
||||
if (scheme) {
|
||||
body.classList.remove('light');
|
||||
console.log('User has not yet visited, but prefers dark');
|
||||
} else {
|
||||
body.classList.add('light');
|
||||
console.log('User has not yet visited, but prefers light');
|
||||
}
|
||||
}
|
||||
|
||||
title.addEventListener('click', (e) => {
|
||||
body.classList.toggle('light');
|
||||
if (body.classList.contains('light')) {
|
||||
window.localStorage.setItem('prefer-light', 'yes');
|
||||
console.log('user likes light');
|
||||
} else {
|
||||
window.localStorage.setItem('prefer-light', 'no');
|
||||
console.log('user likes dark');
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue