-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (38 loc) · 1.25 KB
/
Copy pathscript.js
File metadata and controls
44 lines (38 loc) · 1.25 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const themeSwitch = document.getElementById('theme-switch');
const icon = document.querySelector('.theme-switcher__icon');
const noteTextarea = document.getElementById('note');
const saveButton = document.getElementById('save-btn');
const clearButton = document.getElementById('clear-btn');
const body = document.querySelector('body');
// Check for saved theme preference
const currentTheme = localStorage.getItem('theme');
if (currentTheme === 'dark') {
body.classList.add('dark-theme');
themeSwitch.checked = true;
icon.innerText = '🌙';
}
// Update theme preference
themeSwitch.addEventListener('change', () => {
if (themeSwitch.checked) {
body.classList.add('dark-theme');
localStorage.setItem('theme', 'dark');
icon.innerText = '🌙';
} else {
body.classList.remove('dark-theme');
localStorage.setItem('theme', 'light');
icon.innerText = '☀️';
}
});
// Clear button functionality
clearButton.addEventListener('click', function () {
noteTextarea.value = '';
});
// Save button functionality
saveButton.addEventListener('click', function () {
localStorage.setItem('note', noteTextarea.value);
});
// Check for saved note
const savedNote = localStorage.getItem('note');
if (savedNote) {
noteTextarea.value = savedNote;
}