-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (85 loc) · 2.94 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const sandTimer = document.querySelector(`.sand-timer`);
const stopWatch = document.querySelector(`.stop-watch`);
const worldClock = document.querySelector(`.worldClock`);
const header = document.getElementById("header");
const sandTimerBackground = document.querySelector(`.sand-timer--icon`);
const stopWatchBackground = document.querySelector(`.stop-watch--icon`);
const clockBackground = document.querySelector(`.clock--icon`);
const body = document.body;
const listElement = document.getElementById("menu");
const toggleList = () => {
if (listElement.style.display === "block") {
listElement.style.display = "none";
} else {
listElement.style.display = "block";
}
};
function hideMenuList() {
listElement.style.display = "none";
}
document.body.addEventListener("click", function (event) {
if (!event.target.closest(".menu") && !event.target.closest(".menu-list")) {
hideMenuList();
}
});
function toggleMode() {
body.classList.toggle("dark_mode");
if (body.classList.contains("dark_mode")) {
listElement.innerHTML = "Switch to light mode";
localStorage.setItem("currentMode", "darkMode");
} else {
listElement.innerHTML = "Switch to dark mode";
localStorage.setItem("currentMode", "lightMode");
}
hideMenuList();
}
document.addEventListener("DOMContentLoaded", function () {
const storedMode = localStorage.getItem("currentMode");
if (storedMode === "darkMode") {
body.classList.toggle("dark_mode");
listElement.innerHTML = "Switch to light mode";
} else {
listElement.innerHTML = "Switch to dark mode";
}
});
function toggleSandTimer() {
sandTimerBackground.style.backgroundColor = "#00C2FF3D";
stopWatchBackground.style.backgroundColor = "";
clockBackground.style.backgroundColor = "";
header.innerHTML = "Timer";
sandTimer.style.display = "block";
stopWatch.style.display = "none";
worldClock.style.display = "none";
localStorage.setItem("currentPage", "sandTimer");
}
function toggleStopwatch() {
sandTimerBackground.style.backgroundColor = "";
clockBackground.style.backgroundColor = "";
stopWatchBackground.style.backgroundColor = "#00C2FF3D";
header.innerHTML = "Stopwatch";
stopWatch.style.display = "block";
sandTimer.style.display = "none";
worldClock.style.display = "none";
localStorage.setItem("currentPage", "stopWatch");
}
function toggleClock() {
sandTimerBackground.style.backgroundColor = "";
stopWatchBackground.style.backgroundColor = "";
clockBackground.style.backgroundColor = "#00C2FF3D";
header.innerHTML = "Clock";
sandTimer.style.display = "none";
stopWatch.style.display = "none";
worldClock.style.display = "block";
localStorage.setItem("currentPage", "clock");
}
document.addEventListener("DOMContentLoaded", function () {
const storedMode = localStorage.getItem("currentPage");
if (storedMode === "sandTimer") {
toggleSandTimer();
} else {
toggleStopwatch();
if (storedMode === "clock") {
toggleClock();
}
}
});