-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (32 loc) · 1.21 KB
/
script.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
(() => {
console.warn("Seja bem vindo!")
const html = document.documentElement
const switchButton = document.querySelector(".switch > button")
const musicButton = document.querySelector(".music")
const toggleTheme = light => {
const theme = light ? "light" : "dark"
localStorage.setItem("theme", theme)
html.classList.toggle("light", light)
}
switchButton.addEventListener("click", () => {
const isLight = html.classList.contains("light")
toggleTheme(!isLight)
})
const theme = localStorage.getItem("theme") || "dark"
toggleTheme(theme === "light")
const musicLofi = new Audio("./lofi.mp3")
musicLofi.loop = true
musicLofi.volume = 0.1
const toggleMusic = () => {
if (musicLofi.paused) {
musicLofi.play();
musicButton.setAttribute("title", "Pausar Lofi");
musicButton.style.backgroundImage = "var(--music-mute-bg-url)";
} else {
musicLofi.pause();
musicButton.setAttribute("title", "Começar Lofi");
musicButton.style.backgroundImage = "var(--music-wave-bg-url)";
}
}
musicButton.addEventListener("click", toggleMusic)
})()