-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (76 loc) · 2.53 KB
/
index.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
79
80
81
82
83
84
document.body.onload = function(){
if(localStorage.getItem('theme')==null) {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
setDark();
}
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
setLight();
}
else {
setDark();
}
}
else if (localStorage.getItem('theme')!=null) {
if(localStorage.getItem('theme')=='dark') {
setDark()
}
else if (localStorage.getItem('theme')=='light') {
setLight()
}
}
};
let menuButton=false;
menu = document.getElementById('menu');
document.getElementById('menu-button').addEventListener("click", (event) => {
if (menuButton==false) {
menu.style.animation="slide 500ms";
if (window.matchMedia("(max-width: 600px)").matches) {
menu.style.width="55%";
}
else {
menu.style.width="20%";
}
menuButton=true;
}
else {
menu.style.animation="slideback 500ms";
menu.style.width="0";
menuButton=false;
}
});
let themeButton = document.getElementById('theme-button');
// Get the root element
let cssRoot = document.querySelector(':root');
//dark theme color scheme
let darkBgColor="#161D27"
let primaryColor="#07459d"
let darkSecondaryColor="#141b25"
let darkTextColor="#dceafe"
//light theme color scheme
lightBgColor= "#e2e7ef";
lightSecondaryColor= "#dee4ed";
lightTextColor= "#161D27";
function setLight() {
cssRoot.style.setProperty('--bg-color',lightBgColor);
cssRoot.style.setProperty('--secondary-color',lightSecondaryColor)
cssRoot.style.setProperty('--text-color',lightTextColor)
cssRoot.style.setProperty('--moon-icon','url("images/moon.svg")')
cssRoot.style.setProperty('--menu-icon','url("images/menu-light.svg")');
localStorage.setItem('theme','light');
}
function setDark() {
cssRoot.style.setProperty('--bg-color',darkBgColor);
cssRoot.style.setProperty('--secondary-color',darkSecondaryColor);
cssRoot.style.setProperty('--text-color',darkTextColor);
cssRoot.style.setProperty('--moon-icon','url("images/moon-filled.svg")');
cssRoot.style.setProperty('--menu-icon','url("images/menu-dark.svg")');
localStorage.setItem('theme','dark');
}
themeButton.addEventListener("click", (event) => {
if(localStorage.getItem('theme')=='dark') {
setLight()
}
else if (localStorage.getItem('theme')=='light') {
setDark()
}
});