-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (33 loc) · 1.07 KB
/
app.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
const darkModeBtn = document.querySelector(".darkmode-toggle");
// console.log(darkModeBtn);
const body = document.body;
darkModeBtn.addEventListener("click", changeMode);
const nameEl = document.querySelector(".name");
// adding theme to local storage
let theme = localStorage.getItem("theme");
theme === "light" ? enableLightMode() : enableDarkMode();
function changeMode() {
theme === "light" ? enableDarkMode() : enableLightMode();
body.classList.contains("dark")
? (darkModeBtn.innerHTML = "<i class='bx bxs-sun'></i>")
: (darkModeBtn.innerHTML = "<i class='bx bxs-moon'></i>");
}
function enableLightMode() {
body.classList.remove("dark");
theme = "light";
localStorage.setItem("theme", "light");
}
function enableDarkMode() {
body.classList.add("dark");
theme = "dark";
localStorage.setItem("theme", "dark");
}
// console.log(theme)
// time and year
const today = new Date();
const year = today.getFullYear();
// console.log(year);
// curent year
const yearContainer = document.querySelector(".year");
yearContainer.textContent = year;
// console.log(year);