-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
61 lines (54 loc) · 1.56 KB
/
theme.js
File metadata and controls
61 lines (54 loc) · 1.56 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
52
53
54
55
56
57
58
59
60
var d = new Date();
var h = d.getHours();
var theme;
var next;
var greeting;
pickTheme = (hour) => {
if (hour >= 2 && hour < 6) {
return 'night';
} else if (hour >= 6 && hour < 10) {
return 'sunrise';
} else if (hour >= 10 && hour < 14) {
return 'midday';
} else if (hour >= 14 && hour < 18) {
return 'light';
} else if (hour >= 18 && hour < 22) {
return 'sunset';
} else {
return 'moonlight';
}
}
custom = window.localStorage.getItem('customTheme');
if (custom) {
theme = custom;
} else {
theme = pickTheme(h);
}
if (h >= 5 && h < 12) {
greeting = "Good morning";
} else if (h >= 12 && h < 18) {
greeting = "Good afternoon";
} else {
greeting = "Good evening";
}
document.getElementById("theme-display").innerHTML = theme;
theme = theme.toLowerCase();
document.getElementById("theme").classList.add(theme + '-theme');
// document.getElementById("next-theme").innerHTML = next;
greetingElement = document.getElementById("greeting");
if (greetingElement != null) {
greetingElement.innerHTML = greeting;
}
changeTheme = (newTheme) => {
themeElement = document.getElementById("theme");
themeElement.setAttribute("class", "");
themeElement.classList.add(newTheme.toLowerCase() + '-theme');
document.getElementById("theme-display").innerHTML = newTheme;
window.localStorage.setItem('customTheme', newTheme);
}
removeTheme = () => {
var date = new Date();
var hour = d.getHours();
changeTheme(pickTheme(hour));
window.localStorage.removeItem('customTheme');
}