-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (73 loc) · 2.21 KB
/
Copy pathscript.js
File metadata and controls
85 lines (73 loc) · 2.21 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
78
79
80
81
82
83
84
85
let timer;
let isRunning = false;
let hours = 0;
let minutes = 0;
let seconds = 0;
const hoursDisplay = document.getElementById("hours");
const minutesDisplay = document.getElementById("minutes");
const secondsDisplay = document.getElementById("seconds");
const startButton = document.getElementById("start");
const pauseButton = document.getElementById("pause");
const resetButton = document.getElementById("reset");
const applySettingsButton = document.getElementById("apply-settings");
startButton.addEventListener("click", startTimer);
pauseButton.addEventListener("click", pauseTimer);
resetButton.addEventListener("click", resetTimer);
applySettingsButton.addEventListener("click", applySettings);
function updateDisplay() {
hoursDisplay.textContent = String(hours).padStart(2, "0");
minutesDisplay.textContent = String(minutes).padStart(2, "0");
secondsDisplay.textContent = String(seconds).padStart(2, "0");
}
function startTimer() {
if (isRunning) return;
isRunning = true;
timer = setInterval(() => {
if (seconds === 0) {
if (minutes === 0) {
if (hours === 0) {
clearInterval(timer);
playSound(); // Play sound when timer ends
alert("Time's up!");
return;
}
hours--;
minutes = 59;
} else {
minutes--;
}
seconds = 59;
} else {
seconds--;
}
updateDisplay();
}, 1000);
}
function pauseTimer() {
clearInterval(timer);
isRunning = false;
}
function resetTimer() {
clearInterval(timer);
isRunning = false;
hours = 0;
minutes = 0;
seconds = 0;
updateDisplay();
}
function applySettings() {
const workHours = parseInt(document.getElementById("work-hours").value, 10) || 0;
const workMinutes = parseInt(document.getElementById("work-minutes").value, 10) || 0;
const workSeconds = parseInt(document.getElementById("work-minutes").value, 10) || 0;
hours = workHours;
minutes = workMinutes;
seconds = 0;
updateDisplay();
}
function playSound() {
const enableSound = document.getElementById("enable-sound").checked;
if (!enableSound) return;
const soundChoice = document.getElementById("sound-select").value;
const audio = new Audio(`sounds/${soundChoice}.mp3`);
audio.play();
}