-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
124 lines (101 loc) · 3.17 KB
/
script.js
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
function loadPageWithDelay() {
const loader = document.getElementById("loader");
loader.style.display = "block";
setTimeout(function () {
loader.style.display = "none";
const content = document.getElementById("content");
content.style.display = "block";
}, 1200);
}
// digital clock
let timeformatbtn = document.querySelector(".time-format-btn");
let formatValue = "12";
timeformatbtn.addEventListener("click", () => {
timeformatbtn.classList.toggle("active");
if (formatValue === "12") {
timeformatbtn.setAttribute("time-format-val", "24");
formatValue = "24";
} else {
timeformatbtn.setAttribute("time-format-val", "12");
formatValue = "12";
}
});
let timetype = document.getElementById("timetype");
let crnt_dt = document.getElementById("crnt_dt");
setInterval(function updateClock() {
let dt = new Date();
crnt_dt.innerHTML = dt.toDateString();
let hr = dt.getHours();
let min = dt.getMinutes();
let sec = dt.getSeconds();
// Time Format
if (hr >= 12) {
timetype.innerHTML = "PM";
} else {
timetype.innerHTML = "AM";
}
// Set 12-hour clock format
if (formatValue === "12") {
hr = hr > 12 ? hr % 12 : hr;
}
document.querySelector("#hr").innerHTML = hr;
document.querySelector("#min").innerHTML = min;
document.querySelector("#sec").innerHTML = sec;
}, 1000);
// Toggle-switch button
let dotmenuBtn = document.querySelector(".dot-menu-btn");
let dotmenu = document.querySelector(".dot-menu");
dotmenuBtn.addEventListener("click", (e) => {
dotmenu.classList.toggle("active");
e.stopPropagation();
});
document.addEventListener("click", (e) => {
if (!dotmenu.contains(e.target) && !dotmenuBtn.contains(e.target)) {
dotmenu.classList.remove("active");
}
});
//Alarm part of the code
const alarmTimeInput = document.getElementById("alarmTime");
const setAlarmButton = document.getElementById("setAlarm");
const alarmMessage = document.getElementById("alarmMessage");
const alarmSound = document.getElementById("alarmSound");
let alarmInterval;
setAlarmButton.addEventListener("click", () => {
const alarmTime = alarmTimeInput.value;
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const [alarmHours, alarmMinutes, alarmSeconds] = alarmTime.split(":");
if (
hours == alarmHours &&
minutes == alarmMinutes &&
seconds == alarmSeconds
) {
alarmMessage.innerText = "Rupali lover Want to tell You something!";
alarmSound.play();
clearInterval(alarmInterval);
} else {
alarmMessage.innerText = "Alarm set for " + alarmTime;
alarmInterval = setInterval(checkAlarm, 1000);
}
});
function checkAlarm() {
console.log("Checking if alarm is set or not");
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const [alarmHours, alarmMinutes, alarmSeconds] =
alarmTimeInput.value.split(":");
if (
hours == alarmHours &&
minutes == alarmMinutes &&
seconds == alarmSeconds
) {
alarmMessage.innerText = "Wake Up Asur might come!";
alarmSound.play();
clearInterval(alarmInterval);
}
}
loadPageWithDelay();