-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
156 lines (137 loc) · 5.29 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Climbing Timer</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<style>
body {
background-color: black;
}
#time {
font-size: 35vw;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
color: white;
}
.container {
height: 90vh;
display: flex;
align-items: center;
justify-content: center;
}
button {
color: white;
background-color: black;
border: 0;
padding: 10px 10px;
cursor: pointer;
}
button:hover {
color: #2980b9;
}
button:focus {
outline: 0;
}
</style>
</head>
<body>
<button id="startPauseTimer"><i class="fas fa-play"></i></button>
<button id="setTimer360">6min</button>
<button id="setTimer240">4min</button>
<button id="setTimer40">40sec</button>
<audio id="singleBeep">
<source src="single-beep.wav" type="audio/wav">
<source src="single-beep.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<audio id="singleBeepLow">
<source src="single-beep-low.wav" type="audio/wav">
<source src="single-beep-low.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="container">
<h1 id="time">06:00</h1>
</div>
<script>
var singleBeep = document.getElementById("singleBeep"),
startPauseTimer = document.getElementById("startPauseTimer"),
display = document.querySelector('#time'),
running = 0,
timerDuration = 360 + 1,
pauseTime,
timerID;
function startTimer(duration) {
var timer = duration, minutes, seconds;
timerID = setInterval(function () {
running = 1;
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
//Beep on start
if (timer > duration - 1 ) {
singleBeep.play();
} else if (timer == duration - 1) {
singleBeepLow.play();
} else {
display.textContent = minutes + ":" + seconds;
}
//Beep on every second below 5
if (timer == 60 || (timer < 6 && timer > 0)) {
singleBeep.play();
} else if (timer == 0) {
singleBeepLow.play();
}
//Reset timer
if (--timer < 0) {
clearInterval(timerID);
running = 0;
startPauseTimer.innerHTML = "<i class='fas fa-play'></i>";
}
}, 1000);
}
window.onload = function () {
document.getElementById("startPauseTimer").addEventListener("click", function(){
var curTime, curMinutes, curSeconds;
if (!running) {
running = 1;
startPauseTimer.innerHTML = "<i class='fas fa-pause'></i>";
startTimer(timerDuration);
} else {
running = 0;
startPauseTimer.innerHTML = "<i class='fas fa-play'></i>";
curTime = document.getElementById("time").textContent.split(":");
curMinutes = parseInt(curTime[0]);
curSeconds = parseInt(curTime[1]);
timerDuration = curMinutes * 60 + curSeconds + 1;
clearInterval(timerID);
}
});
document.getElementById("setTimer40").addEventListener("click", function(){
startPauseTimer.innerHTML = "<i class='fas fa-play'></i>";
timerDuration = 40 + 1;
clearInterval(timerID);
display.textContent = "00:40";
running = 0;
});
document.getElementById("setTimer360").addEventListener("click", function(){
startPauseTimer.innerHTML = "<i class='fas fa-play'></i>";
timerDuration = 360 + 1;
clearInterval(timerID);
display.textContent = "06:00";
running = 0;
});
document.getElementById("setTimer240").addEventListener("click", function(){
startPauseTimer.innerHTML = "<i class='fas fa-play'></i>";
timerDuration = 240 + 1;
clearInterval(timerID);
display.textContent = "04:00";
running = 0;
});
};
</script>
</body>
</html>