-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (26 loc) · 1.07 KB
/
script.js
File metadata and controls
30 lines (26 loc) · 1.07 KB
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
document.addEventListener('DOMContentLoaded', () => {
const themeToggleBtn = document.getElementById('theme-toggle');
const themeIcon = document.getElementById('theme-icon');
const body = document.body;
// Checa se o usuário já tem um tema preferido no local storage
const currentTheme = localStorage.getItem('theme');
if (currentTheme) {
body.classList.add(currentTheme);
if (currentTheme === 'dark-mode') {
themeIcon.classList.remove('bi-sun-fill');
themeIcon.classList.add('bi-moon-fill');
}
}
themeToggleBtn.addEventListener('click', () => {
body.classList.toggle('dark-mode');
if (body.classList.contains('dark-mode')) {
themeIcon.classList.remove('bi-sun-fill');
themeIcon.classList.add('bi-moon-fill');
localStorage.setItem('theme', 'dark-mode');
} else {
themeIcon.classList.remove('bi-moon-fill');
themeIcon.classList.add('bi-sun-fill');
localStorage.setItem('theme', 'light-mode');
}
});
});