-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
339 lines (278 loc) · 9.89 KB
/
script.js
File metadata and controls
339 lines (278 loc) · 9.89 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
if (!location.search) {
location.search = '?focus';
} else {
document.getElementById('main-search-input').focus();
}
// ============================================
// NOTES FUNCTIONALITY
// ============================================
let notes = JSON.parse(localStorage.getItem('notes')) || [];
function renderNotes() {
const list = document.getElementById('notes-list');
list.innerHTML = '';
notes.forEach((note, index) => {
const li = document.createElement('li');
li.classList.add('note-item');
const tick = document.createElement('span');
tick.textContent = '✓';
tick.classList.add('tick');
tick.setAttribute('title', 'Complete note');
tick.onclick = () => completeNote(index);
const text = document.createElement('span');
text.textContent = note;
text.classList.add('note-text');
const trash = document.createElement('span');
trash.textContent = '🗑';
trash.classList.add('trash');
trash.setAttribute('title', 'Delete note');
trash.onclick = () => deleteNote(index);
li.appendChild(tick);
li.appendChild(text);
li.appendChild(trash);
list.appendChild(li);
});
}
document.getElementById('add-note').addEventListener('click', (e) => {
e.preventDefault(); // Prevent page refresh
addNote();
});
document.getElementById('note-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
addNote();
}
});
function addNote() {
const input = document.getElementById('note-input');
const value = input.value.trim();
if (value) {
notes.push(value);
localStorage.setItem('notes', JSON.stringify(notes));
input.value = '';
renderNotes();
}
}
function completeNote(index) {
const noteItems = document.querySelectorAll('.note-text');
if (noteItems[index]) {
noteItems[index].classList.add('strike');
setTimeout(() => {
notes.splice(index, 1);
localStorage.setItem('notes', JSON.stringify(notes));
renderNotes();
}, 500);
}
}
function deleteNote(index) {
const noteItems = document.querySelectorAll('.note-item');
if (noteItems[index]) {
noteItems[index].style.transform = 'translateX(-100%)';
noteItems[index].style.opacity = '0';
setTimeout(() => {
notes.splice(index, 1);
localStorage.setItem('notes', JSON.stringify(notes));
renderNotes();
}, 300);
}
}
renderNotes();
// ============================================
// TIME AND DATE DISPLAY
// ============================================
function updateTimeDate() {
const now = new Date();
const timeStr = now.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
});
document.getElementById('time').textContent = timeStr;
const options = {
weekday: 'long',
day: '2-digit',
month: 'long',
year: 'numeric'
};
const dateStr = now.toLocaleDateString('en-US', options).replace(/(\d{1,2}),/, '$1');
const offset = -now.getTimezoneOffset() / 60;
const sign = offset >= 0 ? '+' : '-';
const absOffset = Math.abs(offset);
const tz = `${sign}${absOffset.toString().padStart(2, '0')}:00`;
document.getElementById('date').textContent = `${dateStr} (GMT${tz})`;
}
updateTimeDate();
setInterval(updateTimeDate, 1000);
// ============================================
// WEEKLY REMINDERS WITH SLIDE-IN PANEL
// ============================================
let reminders = JSON.parse(localStorage.getItem('reminders')) || [];
let pendingReminders = [];
let isPanelOpen = false;
const panel = document.getElementById('reminder-panel');
const addBtn = document.getElementById('add-reminder-btn');
const addToListBtn = document.getElementById('add-to-list');
const reminderTextInput = document.getElementById('reminder-text');
const reminderDaySelect = document.getElementById('reminder-day');
const pendingContainer = document.getElementById('pending-reminders');
// Render main reminders list - ONLY TODAY'S REMINDERS
function renderReminders() {
const list = document.getElementById('reminders-list');
const today = new Date().getDay();
list.innerHTML = '';
// Filter to show only today's reminders
const todaysReminders = reminders.filter(r => parseInt(r.day) === today);
if (todaysReminders.length === 0) {
list.innerHTML = '<p style="color: rgba(255,255,255,0.5); text-align: center; padding: 2rem 0;">No reminders for today</p>';
return;
}
todaysReminders.forEach((reminder) => {
const index = reminders.indexOf(reminder);
const li = document.createElement('li');
li.classList.add('reminder-item');
li.classList.add('today');
const header = document.createElement('div');
header.classList.add('reminder-header');
const text = document.createElement('span');
text.classList.add('reminder-text');
text.textContent = reminder.text;
const actions = document.createElement('div');
actions.classList.add('reminder-actions');
const del = document.createElement('span');
del.classList.add('reminder-delete');
del.textContent = '🗑';
del.onclick = () => deleteReminder(index);
actions.appendChild(del);
header.appendChild(text);
header.appendChild(actions);
const dayText = document.createElement('div');
dayText.classList.add('reminder-day');
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
dayText.textContent = days[reminder.day];
li.appendChild(header);
li.appendChild(dayText);
list.appendChild(li);
});
}
// Render ALL reminders in panel (not just pending)
function renderAllRemindersInPanel() {
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
pendingContainer.innerHTML = '<h4 style="font-size: 0.9rem; margin-bottom: 0.75rem; color: rgba(255,255,255,0.7);">All Reminders:</h4>';
if (reminders.length === 0 && pendingReminders.length === 0) {
pendingContainer.innerHTML += '<p style="color: rgba(255,255,255,0.5); font-size: 0.85rem;">No reminders yet</p>';
return;
}
// Show all existing reminders
reminders.forEach((reminder, index) => {
const div = document.createElement('div');
div.classList.add('pending-item');
const text = document.createElement('span');
text.classList.add('pending-item-text');
text.textContent = `${reminder.text} (${days[reminder.day]})`;
const remove = document.createElement('span');
remove.classList.add('pending-item-remove');
remove.textContent = '🗑';
remove.onclick = () => {
deleteReminder(index);
renderAllRemindersInPanel();
};
div.appendChild(text);
div.appendChild(remove);
pendingContainer.appendChild(div);
});
// Show pending reminders with different styling
if (pendingReminders.length > 0) {
const separator = document.createElement('h4');
separator.style.cssText = 'font-size: 0.9rem; margin: 1rem 0 0.75rem 0; color: rgba(255,255,255,0.7);';
separator.textContent = 'New (unsaved):';
pendingContainer.appendChild(separator);
pendingReminders.forEach((reminder, index) => {
const div = document.createElement('div');
div.classList.add('pending-item');
div.style.background = 'rgba(255, 255, 255, 0.12)';
const text = document.createElement('span');
text.classList.add('pending-item-text');
text.textContent = `${reminder.text} (${days[reminder.day]})`;
const remove = document.createElement('span');
remove.classList.add('pending-item-remove');
remove.textContent = '✕';
remove.onclick = () => {
pendingReminders.splice(index, 1);
renderAllRemindersInPanel();
};
div.appendChild(text);
div.appendChild(remove);
pendingContainer.appendChild(div);
});
}
}
// Toggle panel
addBtn.onclick = (e) => {
e.preventDefault(); // Prevent page refresh
if (!isPanelOpen) {
// Open panel
panel.classList.add('active');
addBtn.classList.add('active');
isPanelOpen = true;
pendingReminders = [];
renderAllRemindersInPanel();
reminderTextInput.focus();
} else {
// Close and save
if (pendingReminders.length > 0) {
reminders = [...reminders, ...pendingReminders];
localStorage.setItem('reminders', JSON.stringify(reminders));
renderReminders(); // Refresh main page list
}
panel.classList.remove('active');
addBtn.classList.remove('active');
isPanelOpen = false;
pendingReminders = [];
}
};
// Close panel when clicking outside
document.addEventListener('click', (e) => {
if (isPanelOpen) {
// Check if click is outside both panel and button
const clickedInsidePanel = panel.contains(e.target);
const clickedButton = addBtn.contains(e.target);
if (!clickedInsidePanel && !clickedButton) {
// Close and save if there are pending reminders
if (pendingReminders.length > 0) {
reminders = [...reminders, ...pendingReminders];
localStorage.setItem('reminders', JSON.stringify(reminders));
renderReminders(); // Refresh main page list
}
panel.classList.remove('active');
addBtn.classList.remove('active');
isPanelOpen = false;
pendingReminders = [];
}
}
});
// Add to pending list
addToListBtn.onclick = (e) => {
e.preventDefault(); // Prevent page refresh
const text = reminderTextInput.value.trim();
const day = reminderDaySelect.value;
if (!text) return;
pendingReminders.push({ text, day });
reminderTextInput.value = '';
renderAllRemindersInPanel();
reminderTextInput.focus();
};
// Enter key to add
reminderTextInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
addToListBtn.click();
}
});
// Delete reminder
function deleteReminder(index) {
reminders.splice(index, 1);
localStorage.setItem('reminders', JSON.stringify(reminders));
renderReminders(); // Refresh main page list
}
// Initial render
renderReminders();