This repository was archived by the owner on Nov 7, 2024. It is now read-only.
forked from ad3978/flashfocus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpomotimer.html
More file actions
116 lines (98 loc) · 3.88 KB
/
pomotimer.html
File metadata and controls
116 lines (98 loc) · 3.88 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
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
<!--POMODORO TIMER-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="pomo.css" />
<title id="timer">25:00</title>
</head>
<body class="pmt-page">
<!--REDIRECTORY BUTTONS-->
<div class="jc-center ta-center pmt-btn">
<a href="flashcards.html">Flashcards</a>
<a href="pomotimer.html">Pomodoro</a>
<a href="alerts.html">Alerts</a>
</div>
<!-- POMODORO, LONG BREAK, SHORT BREAK-->
<div class="jc-center ta-center longshort">
<button class="button-2" id="pomodoro-btn" onclick="audio.play();">Pomodoro</button>
<button class="button-2" id="short-break-btn" onclick="audio.play();">Short Break</button>
<button class="button-2" id="long-break-btn" onclick="audio.play();">Long Break</button>
</div>
<!--TIMER DISPLAY, START / STOP / RESET-->
<div class="fulltime">
<div class="jc-center ta-center displaytime" id="timer">25:00</div>
<div class="runningtime">
<button class="button-1" id="start" onclick="audio.play();">Start</button>
<button class="button-1" id="stop" onclick="audio.play();">Stop</button>
<button class="button-1" id="reset" onclick="audio.play();">Reset</button>
</div>
</div>
<!--TIMER SCRIPT-->
<script>
const startButton = document.getElementById("start");
const stopButton = document.getElementById("stop");
const resetButton = document.getElementById("reset");
const timerDisplay = document.getElementById("timer");
const shortBreakBtn = document.getElementById("short-break-btn");
const longBreakBtn = document.getElementById("long-break-btn");
const pomodoroBtn = document.getElementById("pomodoro-btn");
const audio = new Audio();
audio.src = "timer-button.mp3"
let timer;
let seconds = 1500; // 25 minutes
startButton.addEventListener("click", startTimer);
stopButton.addEventListener("click", stopTimer);
resetButton.addEventListener("click", resetTimer);
shortBreakBtn.addEventListener("click", startShortBreak);
longBreakBtn.addEventListener("click", startLongBreak);
pomodoroBtn.addEventListener("click", startPomodoro);
function startTimer() {
timer = setInterval(function() {
seconds--;
displayTime();
if (seconds === 0) {
stopTimer();
audio.play();
startShortBreak();
startTimer();
}
}, 1000);
startButton.disabled = true;
stopButton.disabled = false;
}
function stopTimer() {
clearInterval(timer);
startButton.disabled = false;
stopButton.disabled = true;
}
function resetTimer() {
stopTimer();
seconds = 1500;
displayTime();
}
function startShortBreak() {
stopTimer();
seconds = 300;
displayTime();
}
function startLongBreak() {
stopTimer();
seconds = 600;
displayTime();
}
function startPomodoro() {
stopTimer();
seconds = 1500;
displayTime();
}
function displayTime() {
let minutes = Math.floor(seconds / 60);
let remainingSeconds = seconds % 60;
timerDisplay.innerHTML = `${minutes}:${remainingSeconds < 10 ? "0" : ""}${remainingSeconds}`;
}
</script>
</body>
</html>