-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththemes.js
78 lines (73 loc) · 2.06 KB
/
themes.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const SUN = "Sun"
// black on white
const BW = "BoW"
const MOON = "Moon"
// whtie on black
const WB = "WoB"
// code to handle setting theme and updating theme related things
function setInitialTheme() {
let theme = localStorage.getItem("theme");
// if no custom theme selected for site
if ((theme != BW && theme != WB) || theme == null) {
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: light)").matches
) {
localStorage.setItem("theme", WB);
} else {
localStorage.setItem("theme", BW);
}
}
theme = localStorage.getItem("theme");
let html = document.querySelector("html");
html.classList = [theme];
// Set the theme regardless of if its default on load of the page,
// won't be able to find the celestial if it the page doesn't exist
onload = () => {
let celestial = document.getElementsByClassName("sun")[0];
// if (theme == "light") { celestial.textContent = WB; }
if (theme == BW) { celestial.textContent = WB; }
// if (theme == "dark") { celestial.textContent = BW; }
if (theme == WB) { celestial.textContent = BW; }
// defualt to sun
// else { celestial.textContent = SUN; }
};
}
setInitialTheme();
const themeToDisplay = {
WB: "dark",
BW: "light",
}
const displayToTheme = {
"dark": WB,
"light": BW,
}
const themes = {
WB: BW,
BW: BW,
}
const set_theme = (new_theme) => {
let html = document.querySelector("html");
html.classList = [new_theme];
localStorage.setItem("theme", new_theme);
}
// is sun? should be sun?
cycle_theme = () => {
let celestial = document.getElementsByClassName("sun")[0];
// if (celestial.textContent === SUN) {
// set_theme(SUN);
// celestial.textContent = WB;
// }
if (celestial.textContent === BW) {
set_theme(BW);
celestial.textContent = WB; // always loop back to sun
}
// else if (celestial.textContent === MOON) {
// set_theme(MOON);
// celestial.textContent = BW;
// }
else if (celestial.textContent === WB) {
set_theme(WB);
celestial.textContent = BW; // always loop back to sun
}
};