/
index.html
60 lines (52 loc) · 1.3 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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<title></title>
<style>
#counter { position: absolute; bottom: 0; left: 0; right: 0;
font-size: 100vmin; text-align: center;
color: black; text-shadow: 0 0 3px white;
}
</style>
<script>
function getCounter() {
var data = ~~ window.localStorage.getItem('count') + 1;
return data;
}
function incrementCounter() {
window.localStorage.setItem('count', getCounter());
}
function displayCounter() {
var counter = getCounter();
var element = document.getElementById('counter');
element.textContent = counter;
document.documentElement.style.background = "rgb("
+ random(255) + ","
+ random(255) + ","
+ random(255) + ")";
document.getElementsByTagName('title')[0].textContent = counter;
location.hash = counter;
}
function random(num) {
return Math.floor(Math.random() * num);
}
function updateCounter() {
displayCounter();
incrementCounter();
}
function resetCounter() {
window.localStorage.clear();
displayCounter();
}
window.addEventListener('load', function() {
updateCounter();
document.getElementById('counter').addEventListener('click', resetCounter);
});
</script>
</head>
<body>
<div id="counter">∞</div>
</body>
</html>