-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
79 lines (69 loc) · 2.39 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Days Countdown Timer</title>
<meta name="theme-color" content="#000000">
<meta name="description" content="
A simple timer that counts down in days. To use,
set the URL hash value to a target date in
#YYYY-MM-DD format.
">
<style>
body {
background: black;
color: #f0f;
text-align: center;
font-family: monospace;
}
#countdown {
font-size: 33vw;
}
#help {
font-size: 2em;
}
</style>
</head>
<body onhashchange="updateText()">
<div id="countdown" title="Click to change colour"></div>
<div id="help"></div>
<script>
function updateText() {
var help, date, today, target, remaining;
help = document.head.querySelector("meta[name='description']").content;
if (document.location.hash.length !== 11) {
document.getElementById('help').innerHTML = help;
} else {
date = (document.location.hash.substring(1)).split('-');
today = (new Date()).setHours(0, 0, 0, 0);
target = new Date(date[0], date[1] - 1, date[2]);
remaining = parseInt((target - today) / 86400000);
document.getElementById('help').innerHTML = '';
document.getElementById('countdown').innerHTML = remaining;
document.title = remaining;
window.setTimeout(function () { location.reload(); }, 60000);
}
}
function randomiseColour() {
var r = Math.random() * 255;
var g = Math.random() * 255;
var b = Math.random() * 255;
var colour;
if ((r + g + b) < 255) { //ensure minimum 33% luminosity
changeColour();
} else {
colour = 'rgb(' + [r,g,b].join(',') + ')';
document.cookie = colour;
document.body.style.color = colour;
}
}
function setColorFromCookie() {
if (document.cookie.length > 0) {
document.body.style.color = document.cookie;
}
}
document.addEventListener('click', randomiseColour);
setColorFromCookie();
updateText();
</script>
</body>
</html>