-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
96 lines (91 loc) · 2.62 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Lightning Timer</title>
<!-- By Simon Willison - http://simonwillison.net/2008/Nov/12/lightning/ -->
<script type="text/javascript">
// Default settings: 5 minutes, warning at 1 minute
var count = 5 * 60;
var warning = 60;
window.onload = function() {
// Can optionally set count and warning in the url
// e.g. http://www.lightningtimer.net/#30,15 = 30 seconds, warning at 15
// http://www.lightningtimer.net/#300 = 5 minutes, no warning
var match = /(\d+),?(\d+)?/.exec(location.hash);
if (match && match[1]) {
count = parseInt(match[1], 10);
}
if (match && match[2]) {
warning = parseInt(match[2], 10);
}
if (match && !match[2]) {
warning = -1; // Disable warning
}
document.getElementById('countdown').onclick = function() {
this.onclick = null;
countdown();
}
document.getElementById('countdown').style.cursor = 'pointer';
}
function countdown() {
if (count > 0) {
document.getElementById('countdown').style.cursor = '';
var obj = document.getElementById("countdown");
obj.replaceChild(
document.createTextNode(count.toMinutesAndSeconds()),
obj.firstChild
);
document.title = count.toMinutesAndSeconds();
count--;
if (count < warning) {
document.body.className = 'warning';
}
window.setTimeout(countdown, 1000);
} else {
document.body.className = 'deadline';
var obj = document.getElementById("countdown");
obj.replaceChild(
document.createTextNode(count.toMinutesAndSeconds()),
obj.firstChild
);
document.title = count.toMinutesAndSeconds();
obj.onclick = function() {
location.reload();
};
obj.style.cursor = 'pointer';
}
}
Number.prototype.toMinutesAndSeconds = function() {
// convert numeric seconds input to minutes and seconds string output
var nn, curTime = new Date(this * 1000);
return nn = curTime.getMinutes() + ":" + (
((nn = curTime.getSeconds()) < 10) ? "0" + nn : nn
);
}
</script>
<style type="text/css">
body {
text-align: center;
font-family: verdana;
font-weight: bold;
font-size: 20em;
color: white;
background-color: black;
}
body.warning {
background-color: pink;
color: black;
}
body.deadline {
text-decoration: blink;
background-color: red;
color: white;
}
</style>
</head>
<body>
<body class="start">
<span id="countdown">Start</span>
</body>
</html>