-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
254 lines (212 loc) · 7.76 KB
/
script.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// DOM elements
const body = document.querySelector("body")
const minutes = document.getElementById("minutes");
const seconds = document.getElementById("seconds");
const colon = document.getElementById("colon")
const startBtn = document.getElementById("startBtn");
const stopBtn = document.getElementById("stopBtn");
const minS = document.getElementById("minS");
const minB = document.getElementById("minB");
const displayS = document.getElementById("displayS");
const displayB = document.getElementById("displayB");
const info = document.getElementById("info");
const dots = document.querySelectorAll(".box");
const icons = document.querySelectorAll("i")
const progress = document.querySelector(".path");
const circle = document.querySelector(".circle")
const fullScreenBtn = document.getElementById("fullScreenBtn")
const exitFullScreen = document.getElementById("exitFullScreenBtn")
const pauseStartBtn = document.getElementById("pauseStartBtn")
const pauseEndBtn = document.getElementById("pauseEndBtn")
const startSound = new Audio ("start.mp3")
const stopSound = new Audio ("stop.mp3")
// app variables
let minutesInSession = 25;
let minutesInBreak = 3;
let secondsInTotal;
var counting;
let timeForBreak = false;
let sessionCounter = 1;
let lastSession = false;
let longerBreak = false
// adjusting the duration of session/break
minS.addEventListener("input", () => {
displayS.textContent = "Session " + minS.value + " min";
minutesInSession = parseInt(minS.value);
minutes.textContent = minutesInSession;
return minutesInSession;
});
minB.addEventListener("input", () => {
displayB.textContent = "Break " + minB.value + " min";
minutesInBreak = parseInt(minB.value);
return minutesInBreak;
});
// starting the timer
startBtn.addEventListener("click", () => {
startBtn.classList.toggle("hidden");
stopBtn.classList.toggle("hidden");
sessionMode();
});
function sessionMode() {
theme("#1e88e5b3", "#ffc10799")
// progress.style.animation = " ";
switch(sessionCounter){
case 1:
startSound.play()
document.getElementById("circle1").style.backgroundColor="rgba(33, 33, 33, 0.5)";
document.getElementById("circle1").style.border="3px solid rgba(255, 255, 255, 0.5)";
document.getElementById("circle1").style.boxShadow=`inset 2px 2px 2px 0 rgba(0, 0, 0, 0.4),
-1px -1px 1px 0 rgba(255, 255, 255, 0.3)`
break
case 2:
document.getElementById("circle2").style.backgroundColor="rgba(33, 33, 33, 0.5)";
document.getElementById("circle2").style.border="3px solid rgba(255, 255, 255, 0.5)";
document.getElementById("circle2").style.boxShadow=`inset 2px 2px 2px 0 rgba(0, 0, 0, 0.4),
-1px -1px 1px 0 rgba(255, 255, 255, 0.3)`
break
case 3:
document.getElementById("circle3").style.backgroundColor="rgba(33, 33, 33, 0.5)";
document.getElementById("circle3").style.border="3px solid rgba(255, 255, 255, 0.5)";
document.getElementById("circle3").style.boxShadow=`inset 2px 2px 2px 0 rgba(0, 0, 0, 0.4),
-1px -1px 1px 0 rgba(255, 255, 255, 0.3)`
break
case 4:
document.getElementById("circle4").style.backgroundColor="rgba(33, 33, 33, 0.5)";
document.getElementById("circle4").style.border="3px solid rgba(255, 255, 255, 0.5)";
document.getElementById("circle4").style.boxShadow=`inset 2px 2px 2px 0 rgba(0, 0, 0, 0.4),
-1px -1px 1px 0 rgba(255, 255, 255, 0.3)`
timeForBreak = false;
lastSession = true;
break
default:
}
info.textContent = `You are in the session ${sessionCounter} `;
timeForBreak = true;
secondsInTotal = minutesInSession * 60;
if (sessionCounter===4){
clearInterval(counting);
}
progress.style.animation = `move ${secondsInTotal}s linear`;
counting = setInterval(countDown, 1000);
rotate(secondsInTotal, "backward")
}
function breakMode() {
progress.style.animation = " ";
minutesInBreak = minB.value;
minutes.textContent = minutesInBreak;
secondsInTotal = minutesInBreak * 60;
info.textContent = `Break for ${minB.value} minute(s)!`;
timeForBreak = false;
counting = setInterval(countDown, 1000);
rotate(secondsInTotal, "forward");
theme("#00c853", "#7e57c2");
}
function countDown() {
secondsInTotal--;
minutes.textContent = Math.floor(secondsInTotal / 60);
seconds.textContent = secondsInTotal % 60;
if (seconds.textContent < 10) {
seconds.textContent = "0" + (secondsInTotal % 60);
}
if (secondsInTotal == 0){
stopSound.play()
}
if (secondsInTotal === 0 && timeForBreak == true && lastSession==false) {
sessionCounter++
clearInterval(counting);
breakMode();
}
if (secondsInTotal === 0 && lastSession==false) {
clearInterval(counting);
sessionMode();
}
if (secondsInTotal === 0 && longerBreak==false ){
clearInterval(counting)
longBrake()
}
if (secondsInTotal ===0 && longerBreak===true){
clearInterval(counting)
}
}
function rotate(duration, direction){
progress.style.transform = "rotate 0(deg)";
if (direction=="backward"){
progress.style.animation = `moveBackward ${duration}s linear`;
} else {
progress.style.animation = `moveForward ${duration}s linear`;
}
console.log("rotating for " + duration + " in " + direction);
}
function longBrake(){
progress.style.animation = " ";
theme("#ffc10799","#e57373" )
minutesInBreak = 20;
minutes.textContent = minutesInBreak;
secondsInTotal = minutesInBreak * 60;
info.textContent = `Take 20 minutes break and start again`;
longerBreak = true;
rotate(secondsInTotal, "forward");
counting = setInterval(countDown, 1000);
}
function theme(colorA, colorB){
minutes.style.color = `${colorA}`;
colon.style.color = `${colorA}`;
seconds.style.color = `${colorA}`;
for (icon of icons){
icon.style.color = `${colorA}`;
}
circle.style.boxShadow = `-16px -16px 25px ${colorA}, 16px 16px 25px ${colorB}`;
}
// stopping the timer
stopBtn.addEventListener("click", () => {
startBtn.classList.toggle("hidden");
stopBtn.classList.toggle("hidden");
clearInterval(counting);
sessionCounter = 1
for (let dot of dots){
dot.style.backgroundColor= ""
dot.style.boxShadow=`inset 2px 2px 3px 0 rgba(0, 0, 0, 0.2),
inset -1px -1px 2px 0 rgba(255, 255, 255, 0.5)`;
dot.style.border="3px solid transparent"
}
minutes.textContent = minS.value;
seconds.textContent = "00";
secondsInTotal = minutesInSession * 60;
theme("#212121", "")
circle.style.boxShadow = `16px 16px 25px rgb(163, 177, 198, 0.7),
-16px -16px 25px rgba(255, 255, 255, 0.6)`;
info.textContent = "Press start";
progress.style.animation="10ms comeBack linear";
});
// full screen
fullScreenBtn.addEventListener("click", ()=> {
if (fullScreenBtn.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (fullScreenBtn.mozRequestFullScreen) { /* Firefox */
document.documentElement.mozRequestFullScreen();
} else if (fullScreenBtn.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
document.documentElement.webkitRequestFullscreen();
} else if (fullScreenBtn.msRequestFullscreen) { /* IE/Edge */
document.documentElement.msRequestFullscreen();
}
fullScreenBtn.classList.toggle("hidden");
exitFullScreen.classList.toggle("hidden");
});
exitFullScreen.addEventListener("click", ()=> {
document.exitFullscreen()
fullScreenBtn.classList.toggle("hidden");
exitFullScreen.classList.toggle("hidden");
})
//pause the counting
pauseStartBtn.addEventListener("click", ()=>{
pauseStartBtn.classList.toggle("hidden");
pauseEndBtn.classList.toggle("hidden");
progress.style.animationPlayState="paused"
clearInterval(counting)
})
pauseEndBtn.addEventListener("click", ()=>{
counting = setInterval(countDown, 1000);
pauseStartBtn.classList.toggle("hidden");
pauseEndBtn.classList.toggle("hidden");
progress.style.animationPlayState="running"
})