-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
181 lines (152 loc) · 4.74 KB
/
main.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
var start = document.getElementById('start');
var stop = document.getElementById('stop');
var reset = document.getElementById('reset');
var wm = document.getElementById('w_minutes');
var ws = document.getElementById('w_seconds');
var bm = document.getElementById('b_minutes');
var bs = document.getElementById('b_seconds');
var video = document.getElementById('video');
var audio = new Audio("file:///Users/aidanchadha/Desktop/VS%20Code%20Practice%20Work/Pomodoro%20Clock/microwave-timer-117077.mp3")
var workMinute30 = document.getElementById("30")
var workMinute25 = document.getElementById("25")
var workMinute15 = document.getElementById("15")
var breakMinute15 = document.getElementById("15b")
var breakMinute10 = document.getElementById("10")
var breakMinute5 = document.getElementById("5")
var fullscreenButton = document.getElementById("fullscreen-button");
var selectedTime;
var lastWorkMinutesSelected;
var lastBreakMinutesSelected;
//store a reference to a timer variable
var startTimer;
//function to make it fullscreen
fullscreenButton.addEventListener('click', function() {
document.documentElement.requestFullscreen().catch((e) => {
console.log(e)
});
});
//function to stop a sound
function stopSound() {
audio.pause();
}
//function to play a sound
function playSound() {
audio.play();
setTimeout(stopSound, 2000);
}
//changing the time from the work time and break time buttons
workMinute30.addEventListener('click', function() {
lastWorkMinutesSelected = 30
wm.innerText = 30
ws.innerText = "00"
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
});
workMinute25.addEventListener('click', function() {
lastWorkMinutesSelected = 25
wm.innerText = 25
ws.innerText = "00"
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
});
workMinute15.addEventListener('click', function() {
lastWorkMinutesSelected = 15
wm.innerText = 15
ws.innerText = "00"
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
});
breakMinute15.addEventListener('click', function() {
lastBreakMinutesSelected = 15;
bm.innerText = 15
bs.innerText = "00"
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
});
breakMinute10.addEventListener('click', function() {
lastBreakMinutesSelected = 10;
bm.innerText = 10
bs.innerText = "00"
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
});
breakMinute5.addEventListener('click', function() {
lastBreakMinutesSelected = 5;
bm.innerText = 5
bs.innerText = "00"
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
});
start.addEventListener('click', function(){
if(startTimer === undefined){
startTimer = setInterval(timer, 1000)
} else {
alert("Timer is already running");
}
})
reset.addEventListener('click', function(){
if (lastWorkMinutesSelected) {
wm.innerText = lastWorkMinutesSelected;
ws.innerText = "00";
} else {
wm.innerText = 25;
ws.innerText = "00";
}
if (lastBreakMinutesSelected) {
bm.innerText = lastBreakMinutesSelected;
bs.innerText = "00"
} else {
bm.innerText = 5;
bs.innerText = "00";
}
document.getElementById('counter').innerText = 0;
stopInterval()
startTimer = undefined;
})
stop.addEventListener('click', function(){
stopInterval()
startTimer = undefined;
})
//Start Timer Function
function timer(){
//Work Timer Countdown
if(ws.innerText != 0){
ws.innerText = parseInt(ws.innerText)
ws.innerText--;
ws.innerText = ws.innerText.toString().padStart(2, '0');
} else if(wm.innerText != 0 && ws.innerText == 0){
ws.innerText = 59;
wm.innerText--;
}
//Break Timer Countdown
if(wm.innerText == 0 && ws.innerText == 0){
playSound();
if(bs.innerText != 0){
bs.innerText = parseInt(bs.innerText)
bs.innerText--;
bs.innerText = bs.innerText.toString().padStart(2, '0');
} else if(bm.innerText != 0 && bs.innerText == 0){
bs.innerText = 59;
bm.innerText--;
}
}
//Increment Counter by one if one full cycle is completed
if(wm.innerText == 0 && ws.innerText == 0 && bm.innerText == 0 && bs.innerText == 0){
playSound();
wm.innerText = 25;
ws.innerText = "00";
bm.innerText = 5;
bs.innerText = "00";
document.getElementById('counter').innerText++;
}
}
//Stop Timer Function
function stopInterval(){
clearInterval(startTimer);
}