-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
473 lines (410 loc) · 16.7 KB
/
index.html
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!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">
<title>Workout-Timer App</title>
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;500&display=swap" rel="stylesheet">
<style>
body {
height: 100vh;
font-family: 'Roboto Mono', monospace;
margin: 0;
background-color: black;
color: lightgray;
text-align: center;
}
h1 {
text-align: center;
margin-top: 40px;
font-size: 50px;
margin-bottom: 30px;
}
#settings {
font-size: 20px;
width: max-content;
margin: auto;
/* display: grid;
place-items: center; */
}
button,
#workDuration,
#restDuration,
#pauseDuration,
#rounds {
display: inline-block;
margin: 0px 10px;
vertical-align: middle;
}
.button-left {
float: left;
}
.button-right {
float: right;
}
.settings {
height: fit-content;
vertical-align: middle;
margin-bottom: 12px;
}
#roundCounter {
font-size: 25px;
margin-top: 60px;
margin-bottom: 00px;
height: 30px;
box-sizing: content-box;
line-height: 25px;
}
#status {
font-size: 50px;
margin-top: 0px;
margin-bottom: 0px;
height: 60px;
box-sizing: content-box;
line-height: 50px;
}
#timer {
font-size: 50px;
margin-top: 0px;
margin-bottom: 10px;
height: 60px;
box-sizing: content-box;
line-height: 50px;
}
#progressBar {
width: 200px;
margin: auto;
margin-bottom: 40px;
margin-top: 0px;
}
#comment {
width: 300px;
margin: auto;
margin-bottom: 0px;
margin-top: 50px;
font-size: 12px;
line-height: 14px;
}
</style>
<script>
let alarm = new Audio('alarm.mp3');
let alarmShort = new Audio('alarm_short.mp3');
// let workTime = 6000;
// let restTime = 4000;
// let pauseTime = 10000;
// let rounds = 2;
let workTime = 20000;
let restTime = 10000;
let pauseTime = 120000;
let rounds = 8;
let roundCounter = 1;
let timeLeft = 10000;
let status = "rest"; //rest, work or pause
// let startTime;
// let endTime;
let refreshLoop;
//Set duration für work timer
function setWorkDuration(timeChange) {
if (workTime + timeChange < 0) return
workTime = workTime + timeChange;
//Display time as MM:SS
let workTimeMinutes = workTime / (1000 * 60);
workTimeMinutes = Math.floor(workTimeMinutes);
workTimeMinutes = ('0' + workTimeMinutes).slice(-1);
let workTimeSeconds = (workTime / 1000) % 60;
workTimeSeconds = Math.round(workTimeSeconds);
workTimeSeconds = ('0' + workTimeSeconds).slice(-2);
let timerText = '0' + workTimeMinutes + ':' + workTimeSeconds;
workDuration.innerHTML = 'work ' + timerText;
console.log('workTime', workTime / 1000);
}
//Set duration für rest timer
function setRestDuration(timeChange) {
if (restTime + timeChange < 0) return
restTime = restTime + timeChange;
//Display time as MM:SS
let restTimeMinutes = restTime / (1000 * 60);
restTimeMinutes = Math.floor(restTimeMinutes);
restTimeMinutes = ('0' + restTimeMinutes).slice(-1);
let restTimeSeconds = (restTime / 1000) % 60;
restTimeSeconds = Math.round(restTimeSeconds);
restTimeSeconds = ('0' + restTimeSeconds).slice(-2);
let timerText = '0' + restTimeMinutes + ':' + restTimeSeconds;
restDuration.innerHTML = 'rest ' + timerText;
console.log('restTime', restTime / 1000);
}
//Set number of rounds
function setRounds(roundsChange) {
if (rounds + roundsChange < 1) return
rounds = rounds + roundsChange;
// //Display time as MM:SS
// let restTimeMinutes = restTime / (1000 * 60);
// restTimeMinutes = Math.floor(restTimeMinutes);
// restTimeMinutes = ('0' + restTimeMinutes).slice(-1);
// let restTimeSeconds = (restTime / 1000) % 60;
// restTimeSeconds = Math.round(restTimeSeconds);
// restTimeSeconds = ('0' + restTimeSeconds).slice(-2);
// let timerText = '0' + restTimeMinutes + ':' + restTimeSeconds;
document.querySelector('#rounds').innerHTML = rounds + ' rounds';
console.log('rounds', rounds);
}
//Set duration für pause timer
function setPauseDuration(timeChange) {
if (pauseTime + timeChange < 0) return
pauseTime = pauseTime + timeChange;
//Display time as MM:SS
let pauseTimeMinutes = pauseTime / (1000 * 60);
pauseTimeMinutes = Math.floor(pauseTimeMinutes);
pauseTimeMinutes = ('0' + pauseTimeMinutes).slice(-1);
let pauseTimeSeconds = (pauseTime / 1000) % 60;
pauseTimeSeconds = Math.round(pauseTimeSeconds);
pauseTimeSeconds = ('0' + pauseTimeSeconds).slice(-2);
let timerText = '0' + pauseTimeMinutes + ':' + pauseTimeSeconds;
pauseDuration.innerHTML = 'pause ' + timerText;
console.log('pauseTime', pauseTime / 1000);
}
function startTimer() {
alarm.play(); //play once to enable audio on Safari
alarmShort.play(); //play once to enable audio on Safari
displayStopButton();
console.log(status);
//refreshLoop starten, damit alle Anzeigen geupdatet werden und timeLeft -1000
refreshLoop = setInterval(refresh, 1000, restTime);
// //refreshLoop starten, damit alle Anzeigen geupdatet werden und timeLeft -1000
// switch (status) {
// case 'rest':
// refreshLoop = setInterval(refresh, 1000, restTime);
// break;
// case 'work':
// refreshLoop = setInterval(refresh, 1000, workTime);
// break;
// case 'pause':
// refreshLoop = setInterval(refresh, 1000, pauseTime);
// break;
// }
}
function playAlarm() {
switch (timeLeft / 1000) {
case 3:
alarmShort.play();
break;
case 2:
alarmShort.play();
break;
case 1:
alarmShort.play();
break;
case 0:
alarm.play();
break;
}
}
function endRefreshLoop() {
if (timeLeft / 1000 == 0) {
// alarm.play();
// console.log('alarm abgespielt');
clearInterval(refreshLoop);
console.log('refreshLoop gestoppt');
//status umstellen
if (roundCounter == rounds) {
status = 'pause';
} else {
switch (status) {
case 'rest':
status = 'work';
console.log('status umgestellt');
break;
case 'work':
status = 'rest';
break;
case 'pause':
status = 'rest';
timeLeft = pauseTime;
break;
}
}
//timeLeft neu einstellen
switch (status) {
case 'rest':
timeLeft = restTime;
console.log('switch timeLeft: rest');
break;
case 'work':
timeLeft = workTime;
console.log('switch timeLeft: work');
break;
case 'pause':
timeLeft = pauseTime;
console.log('switch timeLeft: pause');
break;
}
console.log(timeLeft / 1000);
//roundsCounter weiter/zurückstellen
switch (status) {
case 'work':
roundCounter++;
break;
case 'pause':
roundCounter = 0;
break;
}
refreshLoop = setInterval(refresh, 1000, restTime);
}
}
function refresh() {
timeLeft = timeLeft - 1000;
displayRoundCounter();
displayStatus();
displayTimer();
displayProgressBar();
console.log(timeLeft / 1000);
playAlarm();
endRefreshLoop()
}
function displayStopButton() {
button.innerHTML = ('<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" onclick="pauseButton()"><i class="material-icons">pause</i></button ><button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" onclick="stopButton()"><i class="material-icons">stop</i></button >');
}
function displayStartButton() {
button.innerHTML = ('<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" onclick="startTimer()"><i class="material-icons">play_arrow</i></button >');
}
function displayRoundCounter() {
document.querySelector('#roundCounter').innerHTML = 'round ' + roundCounter + ' of ' + rounds;
}
function displayStatus() {
document.querySelector('#status').innerHTML = '>>' + status;
}
function displayTimer() {
let timeLeftMinutes = timeLeft / (1000 * 60);
timeLeftMinutes = Math.floor(timeLeftMinutes);
timeLeftMinutes = ('0' + timeLeftMinutes).slice(-1);
let timeLeftSeconds = (timeLeft / 1000) % 60;
timeLeftSeconds = Math.round(timeLeftSeconds);
timeLeftSeconds = ('0' + timeLeftSeconds).slice(-2);
let timerText = '0' + timeLeftMinutes + ':' + timeLeftSeconds;
// console.log(timerText);
document.querySelector('#timer').innerHTML = timerText;
}
function displayProgressBar() {
switch (status) {
case 'rest':
document.querySelector('#progressBar1').MaterialProgress.setProgress(Math.round(100 - (timeLeft / restTime * 100)));
break;
case 'work':
document.querySelector('#progressBar1').MaterialProgress.setProgress(Math.round(100 - (timeLeft / workTime * 100)));
break;
case 'pause':
document.querySelector('#progressBar1').MaterialProgress.setProgress(Math.round(100 - (timeLeft / pauseTime * 100)));
break;
}
}
function pauseButton() {
console.log('pause timer');
// console.log(doRest);
// console.log(doRest);
clearInterval(refreshLoop);
displayStartButton();
}
function stopButton() {
console.log('stop timer');
clearInterval(refreshLoop);
// console.log(doRest);
roundCounter = 1;
timeLeft = 10000;
status = "rest"; //rest, work or pause
document.querySelector('#status').innerHTML = 'READY';
displayTimer();
// console.log(doRest);
displayStartButton();
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>Workout-Timer</h1>
</div>
<div id="settings">
<div id="settingsWork" class="settings">
<button
class="button-left mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setWorkDuration(-5000)">
<i class="material-icons">remove</i>
</button>
<div id="workDuration">work 00:20</div>
<button
class="button-right mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setWorkDuration(5000)">
<i class="material-icons">add</i>
</button>
</div> <br>
<div id="settingsRest" class="settings">
<button
class="button-left mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setRestDuration(-5000)">
<i class="material-icons">remove</i>
</button>
<div id="restDuration">rest 00:10</div>
<button
class="button-right mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setRestDuration(5000)">
<i class="material-icons">add</i>
</button>
</div> <br>
<div id="settingsRounds" class="settings">
<button
class="button-left mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setRounds(-1)">
<i class="material-icons">remove</i>
</button>
<div id="rounds">8 rounds</div>
<button
class="button-right mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setRounds(1)">
<i class="material-icons">add</i>
</button>
</div> <br>
<div id="settingsPause" class="settings">
<button
class="button-left mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setPauseDuration(-10000)">
<i class="material-icons">remove</i>
</button>
<div id="pauseDuration">pause 02:00</div>
<button
class="button-right mdl-button mdl-js-button mdl-button--primary mdl-button--fab mdl-button--mini-fab mdl-button--colored"
onclick="setPauseDuration(10000)">
<i class="material-icons">add</i>
</button>
</div>
</div>
<div id="roundCounter">
</div>
<div id="status">
READY
</div>
<div id="timer">
00:00
</div>
<div id="progressBar">
<div id="progressBar1" class="mdl-progress mdl-js-progress"></div>
</div>
<div id="button">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" onclick="startTimer()">
<i class="material-icons">play_arrow</i>
</button>
</div>
<div id="comment"> Three separate adjustable timers and a round counter that run in a specific order, update the
time display and progress
bar and play a sound when finished (even on iOS devices!) <br> This PWA is managed with git and
automatically
deployed on netlify.</div>
</div>
</body>
</html>