-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (34 loc) · 1.26 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js')
.then((registration) => {
// console.log('yee', registration);
})
.catch((error) => {
console.log('nee', error);
});
}
document.addEventListener('DOMContentLoaded', function() {
var doc = document.querySelector('html');
if (localStorage.getItem('use-dark-color-scheme') === null) {
if (window.matchMedia) {
localStorage.setItem('use-dark-color-scheme', window.matchMedia("(prefers-color-scheme: dark)").matches);
} else {
localStorage.setItem('use-dark-color-scheme', 'true');
}
}
doc.setAttribute('dark', localStorage.getItem('use-dark-color-scheme'));
window.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', e => {
localStorage.setItem('use-dark-color-scheme', e.matches);
doc.setAttribute('dark', localStorage.getItem('use-dark-color-scheme'));
});
var gem = document.getElementById('gem');
gem.addEventListener('click', () => {
if (doc.getAttribute('dark') === 'true') {
localStorage.setItem('use-dark-color-scheme', 'false');
} else {
localStorage.setItem('use-dark-color-scheme', 'true');
}
doc.setAttribute('dark', localStorage.getItem('use-dark-color-scheme')) ;
}, false);
});