-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
102 lines (88 loc) · 3.31 KB
/
Copy pathscript.js
File metadata and controls
102 lines (88 loc) · 3.31 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const loginPage = document.getElementById('login-page');
const todoPage = document.getElementById('todo-page');
const themeToggle = document.getElementById('theme-toggle');
const loginForm = document.getElementById('login-form');
const usernameInput = document.getElementById('username');
const greeting = document.getElementById('user-greeting');
const form = document.getElementById('todo-form');
const input = document.getElementById('todo-input');
const reminderInput = document.getElementById('reminder-time');
const list = document.getElementById('todo-list');
const reminderSound = document.getElementById('reminder-sound');
// Login
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = usernameInput.value.trim();
if (username) {
greeting.textContent = `${username}'s To-Do List`;
loginPage.classList.add('hidden');
todoPage.classList.remove('hidden');
themeToggle.classList.remove('hidden');
}
});
// Add Task
form.addEventListener('submit', (e) => {
e.preventDefault();
const taskText = input.value.trim();
const reminderMinutes = parseInt(reminderInput.value);
if (taskText) {
addTask(taskText, reminderMinutes);
input.value = '';
reminderInput.value = '';
}
});
function addTask(text, reminderMinutes) {
const li = document.createElement('li');
li.className = 'todo-item';
const span = document.createElement('span');
span.textContent = text;
const actions = document.createElement('div');
actions.className = 'todo-actions';
const completeBtn = document.createElement('button');
completeBtn.textContent = '✓';
completeBtn.title = 'Mark as complete';
completeBtn.addEventListener('click', () => {
li.classList.toggle('completed');
});}
const deleteBtn = document.createElement('button');
deleteBtn.textContent = '🗑';
deleteBtn.title = 'Delete task';
deleteBtn.addEventListener('click', () => {
li.remove();
});
// Get the theme switcher input element
const themeSwitch = document.getElementById('theme-switch');
// Check if the user has a previously saved theme preference
const savedTheme = localStorage.getItem('theme');
// If a saved theme exists, apply it to the body
if (savedTheme) {
document.body.classList.toggle('dark', savedTheme === 'dark');
themeSwitch.checked = savedTheme === 'dark';
} else {
// Default theme (light mode)
document.body.classList.remove('dark');
themeSwitch.checked = false;
}
// Function to handle theme change
themeSwitch.addEventListener('change', function() {
// Toggle dark mode on the body element
if (themeSwitch.checked) {
document.body.classList.add('dark');
localStorage.setItem('theme', 'dark');
} else {
document.body.classList.remove('dark');
localStorage.setItem('theme', 'light');
}
});
// Ensure dark mode toggle is always positioned correctly
function adjustDarkModePosition() {
const themeToggle = document.querySelector('.theme-toggle');
if (window.innerWidth <= 768) {
themeToggle.style.top = '20px'; // Keep it near the top for mobile
} else {
themeToggle.style.top = '10px'; // Adjust the position for larger screens
}
}
// Adjust position on page load and window resize
window.addEventListener('load', adjustDarkModePosition);
window.addEventListener('resize', adjustDarkModePosition);