-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
123 lines (108 loc) · 2.73 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
<!doctype html>
<html>
<head>
<title>Timer</title>
<meta name="viewport" content="width=640" />
<style type="text/css">
.green {
background-color: #00ff51;
}
.light-green {
background-color: #9ee80c;
}
.yellow {
background-color: #ffca00;
}
.orange {
background-color: #e86d0c;
}
.red {
background-color: #ff0000;
}
#container {
bottom: 0;
left: 0;
right: 0;
top: 0;
position: fixed;
}
#button {
background-color: rgba(192, 192, 192, 0.5);
border: 0;
bottom: 0;
display: block;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 4em;
font-weight: 100;
letter-spacing: 3px;
margin: 0;
left: 0;
right: 0;
padding: 22px 0;
position: fixed;
}
#box {
color: white;
display: block;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 40em;
font-weight: 100;
line-height: 1;
text-align: center;
}
</style>
</head>
<body>
<div id="container" class="green">
<main id="box">
5
</main>
<button id="button">
Start
</button>
<!-- Siren from http://soundbible.com/1355-Warning-Siren.html -->
<audio id="alarm">
<source src="siren.mp3" />
</audio>
</div>
<script type="text/javascript">
var container = document.getElementById("container");
var button = document.getElementById("button");
var box = document.getElementById("box");
var audio = document.getElementById("alarm");
var defaultClass = container.className;
var defaultTime = parseInt(box.innerHTML); // seconds
var time;
var interval;
button.onclick = function() {
this.innerHTML = "Reset";
audio.pause();
audio.currentTime = 0
time = defaultTime;
clearInterval(interval);
tick();
interval = setInterval(tick, 60000); // one minute
};
var tick = function() {
if(time <= 0) {
container.className = "red";
audio.play();
} else if(time == 1) {
container.className = "orange";
} else if(time == 2) {
container.className = "yellow";
} else if(time == 3) {
container.className = "light-green";
} else {
container.className = defaultClass;
}
updateText(time);
time--;
};
var updateText = function(value) {
box.innerHTML = value;
document.title = value;
}
</script>
</body>
</html>