-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
596 lines (489 loc) · 25.3 KB
/
Copy pathscript.js
File metadata and controls
596 lines (489 loc) · 25.3 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
document.addEventListener("DOMContentLoaded", () => {
let hrs = document.getElementById("hrs");
let min = document.getElementById("min");
let sec = document.getElementById("sec");
let ampm = document.getElementById("ampm");
// Function to enable or disable the particles
function enableRainParticles() {
const rainGifImage = document.getElementById("rainGifImage");
const rainGif = document.getElementById("rainGif");
const particlesButtonRain = document.getElementById("particlesButtonRain");
var snowParticlesCheck = document.getElementById("particlesButtonSnow");
var stormWeatherCheck = document.getElementById("weatherButtonsStorm");
var blizzardWeatherCheck = document.getElementById("weatherButtonsBlizzard");
// Check the current visibility of the rainGifImage element
if (rainGifImage.style.visibility === "visible") {
// Hide the rain GIFs and change button text to "Enable"
rainGifImage.style.visibility = "hidden";
rainGif.style.visibility = "hidden";
particlesButtonRain.textContent = "Enable";
snowParticlesCheck.disabled = false;
stormWeatherCheck.disabled = false;
blizzardWeatherCheck.disabled = false;
} else {
// Show the rain GIFs and change button text to "Disable"
rainGifImage.style.visibility = "visible";
rainGif.style.visibility = "visible";
particlesButtonRain.textContent = "Disable";
snowParticlesCheck.disabled = true;
stormWeatherCheck.disabled = true;
blizzardWeatherCheck.disabled = true;
}
}
// Set up the event listener on the particles button
let particlesButtonRain = document.getElementById("particlesButtonRain");
if (particlesButtonRain) {
particlesButtonRain.addEventListener("click", enableRainParticles);
}
function enableSnowParticles () {
var rainParticlesCheck = document.getElementById("particlesButtonRain");
var stormWeatherCheck = document.getElementById("weatherButtonsStorm");
var blizzardWeatherCheck = document.getElementById("weatherButtonsBlizzard");
const snowGifImage = document.getElementById("snowGifImage");
const snowGif = document.getElementById("snowGif");
const particlesButtonSnow = document.getElementById("particlesButtonSnow");
if (snowGifImage.style.visibility === "visible") {
snowGifImage.style.visibility = "hidden";
snowGif.style.visibility = "hidden";
particlesButtonSnow.textContent = "Enable";
rainParticlesCheck.disabled = false;
stormWeatherCheck.disabled = false;
blizzardWeatherCheck.disabled = false;
} else {
snowGifImage.style.visibility = "visible";
snowGif.style.visibility = "visible";
particlesButtonSnow.textContent = "Disable";
rainParticlesCheck.disabled = true;
stormWeatherCheck.disabled = true;
blizzardWeatherCheck.disabled = true;
}
}
let particlesButtonSnow = document.getElementById("particlesButtonSnow");
if (particlesButtonSnow) {
particlesButtonSnow.addEventListener("click", enableSnowParticles);
}
function enableBlizzard() {
const blizzardGifImage = document.getElementById("blizzardGifImage");
const blizzardGif = document.getElementById("blizzardGif");
const weatherButtonsBlizzard = document.getElementById("weatherButtonsBlizzard");
var rainParticlesCheck = document.getElementById("particlesButtonRain");
var snowParticlesCheck = document.getElementById("particlesButtonSnow");
var stormWeatherCheck = document.getElementById("weatherButtonsStorm");
if (blizzardGifImage.style.visibility === "visible") {
blizzardGifImage.style.visibility = "hidden";
blizzardGif.style.visibility = "hidden";
weatherButtonsBlizzard.textContent = "Enable";
rainParticlesCheck.disabled = false;
snowParticlesCheck.disabled = false;
stormWeatherCheck.disabled = false;
} else {
blizzardGifImage.style.visibility = "visible";
blizzardGif.style.visibility = "visible";
weatherButtonsBlizzard.textContent = "Disable";
rainParticlesCheck.disabled = true;
snowParticlesCheck.disabled = true;
stormWeatherCheck.disabled = true;
}
}
let weatherButtonsBlizzard = document.getElementById("weatherButtonsBlizzard");
if (weatherButtonsBlizzard) {
weatherButtonsBlizzard.addEventListener("click", enableBlizzard);
}
function enableStorm() {
const rainGifImage = document.getElementById("rainGifImage");
const rainGif = document.getElementById("rainGif");
var rainParticlesCheck = document.getElementById("particlesButtonRain");
var snowParticlesCheck = document.getElementById("particlesButtonSnow");
var blizzardWeatherCheck = document.getElementById("weatherButtonsBlizzard");
if (rainGifImage.style.visibility === "visible") {
// Hide the rain GIFs and change button text to "Enable"
rainGifImage.style.visibility = "hidden";
rainGif.style.visibility = "hidden";
lightningGifImage.style.visibility = "hidden";
lightningGif.style.visibility = "hidden";
weatherButtonsStorm.textContent = "Enable";
rainParticlesCheck.disabled = false;
snowParticlesCheck.disabled = false;
blizzardWeatherCheck.disabled = false;
} else {
// Show the rain GIFs and change button text to "Disable"
rainGifImage.style.visibility = "visible";
rainGif.style.visibility = "visible";
lightningGifImage.style.visibility = "visible";
lightningGif.style.visibility = "visible";
weatherButtonsStorm.textContent = "Disable";
rainParticlesCheck.disabled = true;
snowParticlesCheck.disabled = true;
blizzardWeatherCheck.disabled = true;
}
}
let weatherButtonsStorm = document.getElementById("weatherButtonsStorm");
if (weatherButtonsStorm) {
weatherButtonsStorm.addEventListener("click", enableStorm);
}
function background1Transition() {
var wallpaperBg1Btn = document.getElementById("wallpaperBg1Btn");
var wallpaperBg2Btn = document.getElementById("wallpaperBg2Btn");
var wallpaperBg3Btn = document.getElementById("wallpaperBg3Btn");
var wallpaperBg4Btn = document.getElementById("wallpaperBg4Btn");
document.body.style.backgroundImage = "url('https://wallpapers.com/images/featured/lo-fi-mvqzjym6ie17firw.jpg')";
wallpaperBg1Btn.textContent = "Chosen";
wallpaperBg1Btn.disabled = true;
wallpaperBg2Btn.disabled = false;
wallpaperBg2Btn.textContent = "Choose";
wallpaperBg3Btn.disabled = false;
wallpaperBg3Btn.textContent = "Choose";
wallpaperBg4Btn.disabled = false;
wallpaperBg4Btn.textContent = "Choose";
}
let wallpaperBg1Btn = document.getElementById("wallpaperBg1Btn");
if (wallpaperBg1Btn) {
wallpaperBg1Btn.addEventListener("click", background1Transition);
}
function background2Transition() {
var wallpaperBg1Btn = document.getElementById("wallpaperBg1Btn");
var wallpaperBg2Btn = document.getElementById("wallpaperBg2Btn");
var wallpaperBg3Btn = document.getElementById("wallpaperBg3Btn");
var wallpaperBg4Btn = document.getElementById("wallpaperBg4Btn");
document.body.style.backgroundImage = "url('https://i.pinimg.com/originals/66/29/ac/6629ac69eee96adbe0880b4f06afdc26.gif')";
wallpaperBg1Btn.disabled = false;
wallpaperBg1Btn.textContent = "Choose";
wallpaperBg2Btn.textContent = "Chosen";
wallpaperBg2Btn.disabled = true;
wallpaperBg3Btn.disabled = false;
wallpaperBg3Btn.textContent = "Choose";
wallpaperBg4Btn.disabled = false;
wallpaperBg4Btn.textContent = "Choose";
}
let wallpaperBg2Btn = document.getElementById("wallpaperBg2Btn");
if (wallpaperBg2Btn) {
wallpaperBg2Btn.addEventListener("click", background2Transition);
}
function background3Transition() {
var wallpaperBg1Btn = document.getElementById("wallpaperBg1Btn");
var wallpaperBg2Btn = document.getElementById("wallpaperBg2Btn");
var wallpaperBg3Btn = document.getElementById("wallpaperBg3Btn");
var wallpaperBg4Btn = document.getElementById("wallpaperBg4Btn");
document.body.style.backgroundImage = "url('https://s.widget-club.com/images/YyiR86zpwIMIfrCZoSs4ulVD9RF3/293280da671a76a539b89abbce741e3c/309059649f6c758fb2223a2fea97527d.jpg')";
wallpaperBg1Btn.disabled = false;
wallpaperBg1Btn.textContent = "Choose";
wallpaperBg2Btn.disabled = false;
wallpaperBg2Btn.textContent = "Choose";
wallpaperBg3Btn.textContent = "Chosen";
wallpaperBg3Btn.disabled = true;
wallpaperBg4Btn.disabled = false;
wallpaperBg4Btn.textContent = "Choose";
}
let wallpaperBg3Btn = document.getElementById("wallpaperBg3Btn");
if (wallpaperBg3Btn) {
wallpaperBg3Btn.addEventListener("click", background3Transition);
}
function background4Transition() {
var wallpaperBg1Btn = document.getElementById("wallpaperBg1Btn");
var wallpaperBg2Btn = document.getElementById("wallpaperBg2Btn");
var wallpaperBg3Btn = document.getElementById("wallpaperBg3Btn");
var wallpaperBg4Btn = document.getElementById("wallpaperBg4Btn");
document.body.style.backgroundImage = "url('https://i.postimg.cc/fWGb9PSP/Untitled-design-2.png')";
wallpaperBg1Btn.disabled = false;
wallpaperBg1Btn.textContent = "Choose";
wallpaperBg2Btn.disabled = false;
wallpaperBg2Btn.textContent = "Choose";
wallpaperBg3Btn.disabled = false;
wallpaperBg3Btn.textContent = "Choose";
wallpaperBg4Btn.textContent = "Chosen";
wallpaperBg4Btn.disabled = true;
}
let wallpaperBg4Btn = document.getElementById("wallpaperBg4Btn");
if (wallpaperBg4Btn) {
wallpaperBg4Btn.addEventListener("click", background4Transition);
}
if (document.getElementById("wallpaperBg1Btn").textContent=="Chosen") {
var wallpaperBg1Button = document.getElementById("wallpaperBg1Btn");
wallpaperBg1Button.disabled = true;
wallpaperBg2Btn.textContent = "Choose";
wallpaperBg3Btn.textContent = "Choose";
wallpaperBg4Btn.textContent = "Choose";
} else if (document.getElementById("wallpaperBg2Btn").textContent=="Chosen") {
var wallpaperBg2Button = document.getElementById("wallpaperBg2Btn");
wallpaperBg2Button.disabled = true;
wallpaperBg1Btn.textContent = "Choose";
wallpaperBg3Btn.textContent = "Choose";
wallpaperBg4Btn.textContent = "Choose";
} else if (document.getElementById("wallpaperBg3Btn").textContent=="Chosen") {
var wallpaperBg3Button = document.getElementById("wallpaperBg3Btn");
wallpaperBg3Button.disabled = true;
wallpaperBg1Btn.textContent = "Choose";
wallpaperBg2Btn.textContent = "Choose";
wallpaperBg4Btn.textContent = "Choose";
} else if (document.getElementById("wallpaperBg4Btn").textContent=="Chosen") {
var wallpaperBg4Button = document.getElementById("wallpaperBg4Btn");
wallpaperBg4Button.disabled = true;
wallpaperBg1Btn.textContent = "Choose";
wallpaperBg2Btn.textContent = "Choose";
wallpaperBg3Btn.textContent = "Choose";
}
// Audio player code
const songs = [
{ title: "", artist: "", src: ""},
{ title: "CARNIVAL", artist: "Kanye West, Ty Dolla $ign", src: "https://www.dropbox.com/scl/fi/jdm2pc5i0z4tssbtf6t2c/12-Carnival.mp3?rlkey=n9ncc8egcnwes2a9bw5660dky&st=cn0g5e0o&raw=1" },
{ title: "BURN", artist: "Kanye West, Ty Dolla $ign", src: "https://www.dropbox.com/scl/fi/kptzdit2rgx87d1uizdzb/09-Burn.mp3?rlkey=ukc7xnuxbvr1epg27ps2dg5be&st=py6tbav3&raw=1" },
{ title: "Magnolia", artist: "Playboi Carti", src: "https://www.dropbox.com/scl/fi/91dvrw5bzro2p89fddcyf/spotifydown.com-Magnolia-Playboi-Carti.mp3?rlkey=z6zq0vva6dimgy39ywilvtuwf&st=3l1tw5pz&raw=1" },
{ title: "IDGAF", artist: "BoyWithUke, blackbear", src: "https://www.dropbox.com/scl/fi/5c858z7y3ouz8nqem6jxd/spotifydown.com-IDGAF-with-blackbear-BoyWithUke.mp3?rlkey=1fa4hysag7ggge2u6sh5nyawh&st=m0l0ao9o&raw=1" },
{ title: "Save Your Tears", artist: "The Weeknd", src: "https://www.dropbox.com/scl/fi/20acf6hqe3zrbb4ywg9v4/spotifydown.com-Save-Your-Tears-The-Weeknd.mp3?rlkey=klhtvkr7f4wwuzwnui1a2bwzi&st=edx0mba0&raw=1" },
{ title: "Kerosene", artist: "Crystal Castles", src: "https://www.dropbox.com/scl/fi/pssm1vnhnf6yfbkzuz9yf/spotifydown.com-Kerosene-Crystal-Castles.mp3?rlkey=xzbkqsfjxhq8eyrv91nbchiv3&st=05674r11&raw=1"},
{ title: "3D OUTRO", artist: "LUCKI", src: "https://www.dropbox.com/scl/fi/gh1o71q4315gzhof9l45l/spotifydown.com-3D-Outro-LUCKI.mp3?rlkey=bfrc47lgyt4d1y6w7mc1pfw2q&st=fndbxgh7&raw=1"},
{ title: "Diamonds (feat. Gunna)", artist: "Young Thug, Gunna", src: "https://www.dropbox.com/scl/fi/q0sexnbnjgssrwy6xqack/spotifydown.com-Diamonds-feat.-Gunna-Young-Thug.mp3?rlkey=x7v1rwuc3j5tu12xt7u0riwps&st=bdwwpevw&raw=1" },
{ title: "ILoveUIHateU", artist: "Playboi Carti", src: "https://www.dropbox.com/scl/fi/t0cypq0lvqe0xiehfhai4/spotifydown.com-ILoveUIHateU-Playboi-Carti.mp3?rlkey=6utr3gxwy2ggdhb9rxghxtm3e&st=cn00wqkv&raw=1" },
{ title: "New N3on", artist: "Playboi Carti", src: "https://www.dropbox.com/scl/fi/wi1sae8fogv4bgdk5ei8y/spotifydown.com-New-N3on-Playboi-Carti.mp3?rlkey=0qkhbb16iy1iqxep7jzfa32o6&st=ehj7wx21&raw=1" },
{ title: "Our Time", artist: "Lil Tecca", src: "https://www.dropbox.com/scl/fi/adiktphs5yqeweepi3p29/spotifydown.com-Our-Time-Lil-Tecca.mp3?rlkey=h521ror9j3s5asc9ewbcx5diw&st=p9xkgdnj&raw=1" },
{ title: "Gang Baby", artist: "NLE Choppa", src: "https://www.dropbox.com/scl/fi/yqxibbvz1b4a4edv7ojr0/spotifydown.com-Gang-Baby-NLE-Choppa.mp3?rlkey=pd51n0sxphvyi2ets34bnddjt&st=8enciim4&raw=1" },
];
let currentSongIndex = 0;
let isAutoplayEnabled = true; // Default to autoplay ON
let isDragging = false;
const audio = document.getElementById("audio");
const songTitle = document.getElementById("song-title");
const songArtist = document.getElementById("song-artist");
const progress = document.getElementById("progress");
const progressBar = document.getElementById("progress-bar");
const progressThumb = document.getElementById("progress-thumb");
const currentTime = document.getElementById("current-time");
const totalDuration = document.getElementById("total-duration");
const playButton = document.getElementById("play-button");
const prevButton = document.getElementById("prev-button");
const nextButton = document.getElementById("next-button");
const volumeSlider = document.getElementById("volume-slider");
const playlistDropdown = document.getElementById("playlist-dropdown");
const autoplayButton = document.getElementById("autoplay-button");
function populatePlaylist() {
playlistDropdown.innerHTML = "";
songs.forEach((song, index) => {
const option = document.createElement("option");
option.value = index;
option.textContent = `${song.title} - ${song.artist}`;
playlistDropdown.appendChild(option);
});
}
function loadSong(index) {
if (index === 0) { // Check if the first item (empty) is selected
songTitle.textContent = "Nothing is selected";
songArtist.textContent = "";
audio.src = ""; // Clear audio source
audio.pause();
playButton.textContent = "▶";
return;
}
currentSongIndex = index;
const song = songs[index];
songTitle.textContent = song.title;
songArtist.textContent = song.artist;
audio.src = song.src;
playlistDropdown.value = currentSongIndex; // Update dropdown selection
audio.currentTime = 0; // Reset the progress bar
audio.play(); // Play the song immediately
playButton.textContent = audio.paused ? "▶" : "❚❚";
}
function playPause() {
if (audio.paused) {
audio.play();
playButton.textContent = "❚❚";
// Change document title to song title when playing
const song = songs[currentSongIndex];
} else {
audio.pause();
playButton.textContent = "▶";
// Change document title to "Spotify Clone" when paused
}
}
function nextSong() {
currentSongIndex = (currentSongIndex + 1) % songs.length;
loadSong(currentSongIndex);
}
function prevSong() {
currentSongIndex = (currentSongIndex - 1 + songs.length) % songs.length;
loadSong(currentSongIndex);
}
autoplayButton.addEventListener("click", () => {
isAutoplayEnabled = !isAutoplayEnabled;
autoplayButton.textContent = `Autoplay: ${isAutoplayEnabled ? "On" : "Off"}`;
});
audio.addEventListener("ended", () => {
if (isAutoplayEnabled) {
nextSong(); // Go to next song when current ends
}
});
playButton.addEventListener("click", playPause);
nextButton.addEventListener("click", nextSong);
prevButton.addEventListener("click", prevSong);
playlistDropdown.addEventListener("change", (e) => {
loadSong(parseInt(e.target.value)); // Load the selected song
});
audio.addEventListener("timeupdate", () => {
progress.style.width = `${(audio.currentTime / audio.duration) * 100}%`;
progressThumb.style.left = `${(audio.currentTime / audio.duration) * 100}%`;
currentTime.textContent = formatTime(audio.currentTime);
totalDuration.textContent = formatTime(audio.duration);
});
volumeSlider.addEventListener("input", () => {
audio.volume = volumeSlider.value;
});
progressBar.addEventListener("click", (e) => {
const clickX = e.offsetX;
const width = progressBar.clientWidth;
audio.currentTime = (clickX / width) * audio.duration;
playButton.textContent = "❚❚";
});
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${minutes}:${secs < 10 ? "0" : ""}${secs}`;
}
window.onload = () => {
populatePlaylist();
loadSong(0); // Load the first song
songTitle.textContent = "Nothing is playing";
};
// To Do List
const todoList = document.getElementById('todo-list');
const saveButton = document.getElementById('save-btn');
const addButton = document.getElementById('add-btn');
const removeButton = document.getElementById('remove-btn');
const selectAllButton = document.getElementById('select-all-btn');
// Function to check if the todo list is empty and disable/enable buttons
function checkIfEmpty() {
const todoItems = todoList.querySelectorAll('.todo-item');
// Disable the buttons if there are no items
if (todoItems.length === 0) {
removeButton.disabled = true;
selectAllButton.disabled = true;
removeButton.classList.add('disabled'); // Add a class for styling
selectAllButton.classList.add('disabled'); // Add a class for styling
} else {
removeButton.disabled = false;
selectAllButton.disabled = false;
removeButton.classList.remove('disabled'); // Remove the class
selectAllButton.classList.remove('disabled'); // Remove the class
}
}
// Function to create a new todo item
function createTodoItem(title = 'New Task', time = '12:00') {
const todoItem = document.createElement('div');
todoItem.className = 'todo-item';
todoItem.draggable = true;
todoItem.innerHTML = `
<input type="text" value="${title}" />
<input type="time" value="${time}" />
<input type="checkbox" class="select-task" />
`;
todoItem.addEventListener('dragstart', () => {
todoItem.classList.add('dragging');
});
todoItem.addEventListener('dragend', () => {
todoItem.classList.remove('dragging');
});
return todoItem;
}
// Handle drag-and-drop to reorder items
todoList.addEventListener('dragover', (e) => {
e.preventDefault();
const draggingItem = document.querySelector('.dragging');
const afterElement = getDragAfterElement(todoList, e.clientY);
if (afterElement == null) {
todoList.appendChild(draggingItem);
} else {
todoList.insertBefore(draggingItem, afterElement);
}
});
// Get the element after the dragged item based on cursor position
function getDragAfterElement(container, y) {
const draggableElements = [...container.querySelectorAll('.todo-item:not(.dragging)')];
return draggableElements.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) {
return { offset: offset, element: child };
} else {
return closest;
}
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
// Add a new todo item when the "Add" button is clicked
addButton.addEventListener('click', () => {
todoList.appendChild(createTodoItem());
checkIfEmpty(); // Recheck and disable buttons if necessary
});
// Remove selected items when the "Remove" button is clicked
removeButton.addEventListener('click', () => {
const selectedItems = todoList.querySelectorAll('.select-task:checked');
// Remove the selected items
selectedItems.forEach(item => {
todoList.removeChild(item.closest('.todo-item'));
});
// Reset the "Select All" button to "Select All" if no items are checked
const checkboxes = todoList.querySelectorAll('.select-task');
const anyChecked = Array.from(checkboxes).some(checkbox => checkbox.checked);
if (!anyChecked) {
selectAllButton.textContent = "Select All"; // Reset the button text to "Select All"
}
removeButton.textContent = "Deleted";
setTimeout(() => {
removeButton.textContent = "Delete";
}, 1000);
checkIfEmpty(); // Recheck and disable buttons if necessary
});
// Toggle select all checkboxes when the "Select All" button is clicked
selectAllButton.addEventListener('click', () => {
const allChecked = selectAllButton.textContent === "Deselect";
const checkboxes = todoList.querySelectorAll('.select-task');
checkboxes.forEach(checkbox => {
checkbox.checked = !allChecked;
});
selectAllButton.textContent = allChecked ? "Select All" : "Deselect";
});
// Save the todo list and set reminders when the "Save" button is clicked
saveButton.addEventListener('click', () => {
saveButton.textContent = "Saved";
setTimeout(() => {
saveButton.textContent = "Save List";
}, 1000);
const items = [...todoList.querySelectorAll('.todo-item')].map(item => {
return {
element: item,
title: item.querySelector('input[type="text"]').value,
time: item.querySelector('input[type="time"]').value
};
});
items.forEach(item => {
const now = new Date();
const alertTime = new Date();
const [hours, minutes] = item.time.split(':');
alertTime.setHours(hours, minutes, 0, 0);
const timeDifference = alertTime.getTime() - now.getTime();
if (timeDifference > 0) {
setTimeout(() => {
alert(`Reminder: ${item.title} at ${item.time}`);
item.element.classList.add('disabled');
item.element.querySelector('.select-task').disabled = false;
}, timeDifference);
}
});
});
// Run the check initially when the page loads to update button states
checkIfEmpty();
// Update the clock every second
setInterval(() => {
let currentTime = new Date(); // Get the current time
let hours = currentTime.getHours();
let minutes = currentTime.getMinutes();
let seconds = currentTime.getSeconds();
// Determine AM or PM
let meridian = hours >= 12 ? "PM" : "AM";
// Convert to 12-hour format
let displayHours = hours % 12 || 12; // Show 12 for midnight/noon
// Update the clock elements
hrs.innerHTML = String(displayHours).padStart(2, '0');
min.innerHTML = String(minutes).padStart(2, '0');
sec.innerHTML = String(seconds).padStart(2, '0');
ampm.innerHTML = meridian;
}, 1000); // Refresh every second
});