-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
207 lines (160 loc) · 5.04 KB
/
timer.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
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="ie ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="ie ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="ie ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="UTF-8" />
<title>Timer</title>
<meta name="description" content=" " />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="favicon.png" />
<link rel="apple-touch-icon" href="apple-touch-icon-precomposed.png" />
<link rel="author" type="text/plain" href="humans.txt">
<!-- / meta -->
</head>
<body id="body">
<audio>
<source src="audio/sheep.mp3"></source>
</audio>
<audio>
<source src="audio/alarm_1.mp3"></source>
</audio>
<section id="fullscreen">
<h1 id="timer">5:00</h1>
</section>
<script>
var $timer = document.getElementById('timer');
var $body = document.getElementById('body');
var minutes = 5;
var seconds = 0;
var audio_warning = document.getElementsByTagName("audio")[0];
var audio_alarm = document.getElementsByTagName("audio")[1];
console.log(audio_alarm);
var updateClasses = function() {
if ( minutes < 1 ) {
if ( seconds == 59 ) {
$body.className = "minute-left";
} else if ( seconds == 30 ) {
$body.className = "seconds-left";
audio_warning.play();
}
}
}
var updateDisplay = function() {
$timer.innerText = minutes + ":" + ( ( seconds < 10 ) ? "0" + seconds : seconds );
};
var stopTimer = function() {
if ( minutes == 0 && seconds == 0 ) {
clearInterval( timer );
audio_alarm.play();
}
}
var countdown = function() {
// New minute
// e.g: 5:00 to 4:59
if ( seconds == 00 ) {
minutes -= 1;
seconds = 59;
// Same minute
// e.g: 4:59 to 4:58
} else {
seconds -= 1;
}
updateDisplay();
updateClasses();
stopTimer();
}
var timer = setInterval( countdown, 1000 );
</script>
<script>
var e = document.getElementById("fullscreen");
e.onclick = function() {
if (RunPrefixMethod(document, "FullScreen") || RunPrefixMethod(document, "IsFullScreen")) {
RunPrefixMethod(document, "CancelFullScreen");
}
else {
RunPrefixMethod(e, "RequestFullScreen");
}
}
var pfx = ["webkit", "moz", "ms", "o", ""];
function RunPrefixMethod(obj, method) {
var p = 0, m, t;
while (p < pfx.length && !obj[m]) {
m = method;
if (pfx[p] == "") {
m = m.substr(0,1).toLowerCase() + m.substr(1);
}
m = pfx[p] + m;
t = typeof obj[m];
if (t != "undefined") {
pfx = [pfx[p]];
return (t == "function" ? obj[m]() : obj[m]);
}
p++;
}
}
</script>
<style type="text/css">
body { background:#000; color:#fff; }
body.minute-left { background:#ffc97d; }
body.seconds-left { background:#fc4a50; }
h1 { text-align: center; font-size:660px; line-height:1; margin:200px 0 0 0; padding:0;}
section:-webkit-full-screen
{
float: none;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
border: 0 none;
background-color: #000;
}
body.minute-left section:-webkit-full-screen
{
background-color: #ffc97d;
}
body.seconds-left section:-webkit-full-screen
{
background-color: #fc4a50;
}
section:-moz-full-screen
{
float: none;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
border: 0 none;
}
section:-ms-full-screen
{
float: none;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
border: 0 none;
}
section:-o-full-screen
{
float: none;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
border: 0 none;
}
section:full-screen
{
float: none;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
border: 0 none;
}
</style>
</body>
</html>