Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (64 loc) · 2 KB
/
Copy pathscript.js
File metadata and controls
77 lines (64 loc) · 2 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
let timerInterval;
let totalTime = 0;
let isPaused = false;
function updateClock() {
const now = new Date();
const hour = String(now.getHours()).padStart(2, '0');
const minute = String(now.getMinutes()).padStart(2, '0');
const second = String(now.getSeconds()).padStart(2, '0');
document.getElementById("clock").textContent = `${hour}:${minute}:${second}`;
}
setInterval(updateClock, 1000);
updateClock();
function updateTimerDisplay() {
const minute = String(Math.floor(totalTime / 60)).padStart(2, '0');
const second = String(totalTime % 60).padStart(2, '0');
document.getElementById("timer").textContent = `${minute}:${second}`;
}
function startTimer() {
if (!isPaused) {
const mins = parseInt(document.getElementById("minutes").value || 0);
const secs = parseInt(document.getElementById("seconds").value || 0);
totalTime = mins * 60 + secs;
}
if (totalTime <= 0) return;
clearInterval(timerInterval);
timerInterval = setInterval(() => {
if (totalTime <= 0) {
clearInterval(timerInterval);
const beep = document.getElementById("beep-sound");
beep.currentTime = 0;
beep.play().catch((e) => console.warn("Audio error:", e));
showToast();
return;
}
totalTime--;
updateTimerDisplay();
}, 1000);
isPaused = false;
}
function pauseTimer() {
clearInterval(timerInterval);
isPaused = true;
}
function resetTimer() {
clearInterval(timerInterval);
timerInterval = null;
totalTime = 0;
isPaused = false;
document.getElementById("minutes").value = "";
document.getElementById("seconds").value = "";
updateTimerDisplay();
const toast = document.getElementById("toast");
toast.style.top = "-100px";
toast.style.opacity = 0;
}
function showToast() {
const toast = document.getElementById("toast");
toast.style.top = "30px";
toast.style.opacity = 1;
setTimeout(() => {
toast.style.top = "-100px";
toast.style.opacity = 0;
}, 3000);
}