-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (45 loc) · 1.42 KB
/
app.js
File metadata and controls
51 lines (45 loc) · 1.42 KB
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
42
43
44
45
46
47
48
49
50
51
const VERBOSE = false;
window.osIsDarkTheme = function() {
let osTheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
VERBOSE && console.info("OS Theme: ", osTheme ? 'dark' : 'light')
return osTheme;
}
window.detectTheme = function() {
let theme = localStorage.theme === 'dark' || (!('theme' in localStorage) && osIsDarkTheme());
VERBOSE && console.info("Detected Theme: ", theme ? 'dark' : 'light');
return theme;
}
window.reloadTheme = function() {
document.documentElement.classList.toggle(
'dark',
window.detectTheme()
)
}
window.setTheme = function(theme) {
if (theme == null) {
VERBOSE && console.info("Clearing theme.", " previously ", localStorage.theme)
localStorage.removeItem('theme');
} else {
VERBOSE && console.info("Setting theme to: ", theme, " previously ", localStorage.theme);
localStorage.theme = theme;
}
window.reloadTheme();
}
window.getTheme = function(theme) {
return localStorage.theme ?? (osIsDarkTheme() ? 'dark' : 'light');
}
window.toggleTheme = function() {
window.setTheme(window.getTheme() == 'dark' ? 'light' : 'dark');
}
async function boot() {
console.log("Boot...");
//window.setTheme('dark');
//window.setTheme('light');
window.setTheme(undefined);
setInterval(() => {
window.reloadTheme();
}, 500);
//window.setTheme(null);
console.log("\t...done.");
}
boot();