-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm.js
75 lines (63 loc) · 2.64 KB
/
alarm.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
const audio = document.querySelector("#audioPlayer")
let date
let houre
let minute
let second
let userHoure
let userMinute
let userSecond
let userMusic
// this code is for showing the top clock.
setInterval(() => {
date = new Date;
houre = date.getHours();
minute = date.getMinutes();
second = date.getSeconds();
document.querySelector(".houre").innerHTML = houre + " :";
document.querySelector(".minute").innerHTML = minute + " :";
document.querySelector(".second").innerHTML = second;
if (second.toString().length === 1) {
document.querySelector(".second").innerHTML = "0" + second;
};
if (minute.toString().length === 1) {
document.querySelector(".minute").innerHTML = "0" + minute;
};
if (houre.toString().length === 1) {
document.querySelector(".houre").innerHTML = "0" + houre;
};
}, 1000);
// cheks if the real time is equal with the user input time. so it rings!
document.querySelector("#set").addEventListener("click", function () {
document.querySelector(".form-box").classList.remove("d-none");
document.querySelector("button[type=submit]").addEventListener("click", function () {
userHoure = Number(document.querySelector("input[name=houre]").value);
userMinute = Number(document.querySelector("input[name=minute]").value);
userSecond = Number(document.querySelector("input[name=second]").value);
userMusic = document.querySelector("input[type=file]")
if (userHoure && userMinute && userSecond && userMusic) {
const file = userMusic.files[0]
const fileURL = URL.createObjectURL(file)
audio.setAttribute("src", fileURL)
setInterval(function () {
if (userHoure === houre && userMinute === minute && userSecond === second) {
setInterval(function(){audio.play()},10)
document.querySelector(".alert").classList.remove("d-none")
}
}, 1000)
} else if (userHoure || userMinute || userSecond === 0) {
const file = userMusic.files[0]
const fileURL = URL.createObjectURL(file)
audio.setAttribute("src", fileURL)
setInterval(function () {
if (userHoure === houre && userMinute === minute && userSecond === second) {
setInterval(function(){audio.play()},10)
document.querySelector(".alert").classList.remove("d-none")
}
}, 1000)
}
});
});
// reloading the page if you click on refresh button
document.querySelector("#refresh").addEventListener("click",function(){
location.reload()
})