forked from khtlamlsc/timer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
149 lines (131 loc) · 5.14 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Examination Timer</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
background-color: black;
color: white;
}
#currentTime {
font-size: 250pt;
margin: 20px 0;
color: green;
}
#currentDate, #subjectDisplay {
font-size: 70px;
margin: 20px 0;
}
#examTimer {
font-size: 10px;
margin: 20px 0;
}
#examInfo {
font-size: 100px;
margin: 20px 0;
font-weight:bold;
}
input, button, textarea {
font-size: 18px;
margin: 10px;
padding: 5px;
}
#subject {
width: 80%;
height: 100px;
}
#subjectDisplay {
display: none;
font-size: 50px;
}
</style>
</head>
<body>
<h1 id="title">Examination Timer</h1>
<div id="subjectDisplay"></div>
<div id="currentDate"></div>
<div id="currentTime"></div>
<input type="number" id="duration" placeholder="Enter duration in minutes" min="1">
<button onclick="startTimer()">Start</button>
<div id="examInfo"></div>
<div id="examTimer"></div>
<textarea id="subject" placeholder="Enter subject details"></textarea>
<script>
let timer;
let endTime;
let startTime;
const fiveMinAudio = new Audio('five_min_left.mp3');
const fifteenMinAudio = new Audio('fifteen_min_left.mp3');
const timeUpAudio = new Audio('time_up.mp3');
let level = 0;
function updateCurrentTime() {
const now = new Date();
document.getElementById('currentTime').textContent = now.toLocaleTimeString('en-GB', { hour12: false });
document.getElementById('currentDate').textContent = now.toLocaleDateString();
}
function startTimer() {
const duration = document.getElementById('duration').value;
const subject = document.getElementById('subject').value;
if (!duration) return;
clearInterval(timer);
startTime = new Date();
endTime = new Date(startTime.getTime() + duration * 60000);
document.getElementById('examInfo').innerHTML = `
${startTime.toLocaleTimeString('en-GB', { hour12: false })} - ${endTime.toLocaleTimeString('en-GB', { hour12: false })}
`;
document.getElementById('title').style.display = 'none';
document.getElementById('subjectDisplay').style.display = 'block';
document.getElementById('subjectDisplay').textContent = subject;
document.getElementById('subject').style.display = 'none';
document.getElementById('duration').style.display = 'none';
document.querySelector('button').style.display = 'none';
document.getElementById('currentTime').style.color = 'white';
timer = setInterval(() => {
const now = new Date();
const diff = endTime - now;
if (diff <= 0) {
clearInterval(timer);
document.getElementById('examTimer').textContent = "Time's up!";
timeUpAudio.play();
document.getElementById('currentTime').style.color = 'green';
document.body.style.backgroundColor = 'yellow';
return;
}
const minutes = Math.floor(diff / 60000);
const seconds = Math.floor((diff % 60000) / 1000);
document.getElementById('examTimer').textContent =
`Time Remaining: ${minutes}:${seconds.toString().padStart(2, '0')}`;
if (minutes == 15 && seconds == 0) {
level = 1;
fifteenMinAudio.play();
}
if (minutes == 14 && level == 0 && seconds > 50) {
level = 1;
fifteenMinAudio.play();
}
if (minutes == 5 && seconds == 0) {
level = 2;
fiveMinAudio.play();
}
if (minutes < 15 && minutes >= 5) {
document.getElementById('currentTime').style.color = 'yellow';
}
if (minutes < 5) {
document.getElementById('currentTime').style.color = '#E78587';
if (level < 2) {
level = 2;
fiveMinAudio.play()
}
}
}, 1000);
}
setInterval(updateCurrentTime, 100);
updateCurrentTime();
</script>
</body>
</html>