-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (21 loc) · 708 Bytes
/
Copy pathscript.js
File metadata and controls
24 lines (21 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function applyTheme(isLight) {
const html = document.documentElement
html.classList.toggle("light", isLight)
const img = document.querySelector("#profile img")
img.setAttribute(
"src",
isLight ? "./assets/foto-perfil-light.png" : "./assets/foto-perfil.png",
)
}
function toggleMode() {
const isLight = !document.documentElement.classList.contains("light")
applyTheme(isLight)
localStorage.setItem("theme", isLight ? "light" : "dark")
}
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("switch").addEventListener("click", toggleMode)
const savedTheme = localStorage.getItem("theme")
if (savedTheme === "light") {
applyTheme(true)
}
})