-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (47 loc) · 2.22 KB
/
script.js
File metadata and controls
55 lines (47 loc) · 2.22 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
function updateTime() {
const now = new Date();
const currentTimeElement = document.getElementById('current-time');
currentTimeElement.textContent = now.toLocaleTimeString();
}
function setAlarm() {
const alarmTime = document.getElementById('alarm-time').value;
const now = new Date();
const alarmDate = new Date(now.toDateString() + ' ' + alarmTime);
const timeUntilAlarm = alarmDate - now;
if (timeUntilAlarm <= 0) {
alert('Please select a future time for the alarm.');
return;
}
// Display the alarm set message
const alarmSetMessage = document.getElementById('alarm-set-message');
const alarmSetTime = document.getElementById('alarm-set-time');
alarmSetTime.textContent = alarmDate.toLocaleTimeString();
alarmSetMessage.style.display = 'block';
setTimeout(function() {
showNotification();
}, timeUntilAlarm);
}
function showNotification() {
if ('Notification' in window && Notification.permission === 'granted') {
new Notification('Alarm Triggered', {
body: 'Your alarm time has been reached!',
icon: 'pngtree-alarm-clock-icon-alarm-clock-that-sounds-loudly-in-the-morning-png-image_5299951.jpg'
});
} else if ('Notification' in window && Notification.permission !== 'denied') {
Notification.requestPermission().then(function(permission) {
if (permission === 'granted') {
showNotification();
}
});
}
}
setInterval(updateTime, 1000);
const modeToggle = document.getElementById('mode-toggle');
const body = document.body;
modeToggle.addEventListener('change', () => {
if (modeToggle.checked) {
body.classList.add('dark-mode');
} else {
body.classList.remove('dark-mode');
}
});