-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
41 lines (35 loc) · 1.12 KB
/
theme.js
File metadata and controls
41 lines (35 loc) · 1.12 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
var d = new Date();
var h = d.getHours();
var theme;
var next;
var greeting;
pickTheme = (hour) => {
return hour >= 6 && hour < 18 ? 'light' : 'dark';
}
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;
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');
}