-
Notifications
You must be signed in to change notification settings - Fork 0
/
pomo.js
105 lines (93 loc) · 2.53 KB
/
pomo.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
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
// pomo.js
// Variáveis globais
let minutos = 25;
let segundos = 0;
let intervalId;
let isPaused = false;
const minutosSpan = document.getElementById("minutos");
const segundosSpan = document.getElementById("secundos");
const focoButton = document.getElementById("foco");
const curtoButton = document.getElementById("curto");
const longoButton = document.getElementById("longo");
const pauseButton = document.getElementById("pause");
const stopButton = document.getElementById("stop");
function iniciarTimer() {
intervalId = setInterval(atualizarTempo, 1000);
focoButton.style.display = "none";
curtoButton.style.display = "none";
longoButton.style.display = "none";
pauseButton.style.display = "block";
pauseButton.textContent = "Pause";
stopButton.style.display = "block";
}
function pausarTimer() {
clearInterval(intervalId);
isPaused = true;
pauseButton.textContent = "Play";
stopButton.style.display = "block";
focoButton.style.display = "none";
curtoButton.style.display = "none";
longoButton.style.display = "none";
}
function retomarTimer() {
isPaused = false;
pauseButton.textContent = "Pause";
iniciarTimer();
}
function atualizarTempo() {
if (!isPaused) {
if (segundos === 0) {
if (minutos === 0) {
clearInterval(intervalId);
alert("Acabou o tempo :)");
resetarTimer();
return;
} else {
minutos--;
segundos = 59;
}
} else {
segundos--;
}
minutosSpan.textContent = minutos < 10 ? "0" + minutos : minutos;
segundosSpan.textContent = segundos < 10 ? "0" + segundos : segundos;
}
}
function resetarTimer() {
minutos = 25;
segundos = 0;
minutosSpan.textContent = "25";
segundosSpan.textContent = "00";
clearInterval(intervalId);
focoButton.style.display = "block";
curtoButton.style.display = "block";
longoButton.style.display = "block";
pauseButton.style.display = "none";
pauseButton.textContent = "Pause";
stopButton.style.display = "none";
}
focoButton.addEventListener("click", function () {
minutos = 25;
minutosSpan.textContent = "25";
iniciarTimer();
});
curtoButton.addEventListener("click", function () {
minutos = 5;
minutosSpan.textContent = "05";
iniciarTimer();
});
longoButton.addEventListener("click", function () {
minutos = 15;
minutosSpan.textContent = "15";
iniciarTimer();
});
pauseButton.addEventListener("click", function () {
if (isPaused) {
retomarTimer();
} else {
pausarTimer();
}
});
stopButton.addEventListener("click", function () {
resetarTimer();
});