-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
90 lines (90 loc) · 2.9 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hit-Count-Server</title>
<style>
body {
color: white;
font-size: 25px;
font-weight: bold;
height: 100vh;
padding: 15px;
position: relative;
width: 100vw;
transition: background .8s;
}
#main {
left: 50%;
position: absolute;
top: 50%;
text-align: center;
transform: translate(-50%, -50%);
}
#header {
font-size: 48px;
}
button {
padding: 10px;
border-radius: 10px;
font-weight: bold;
font-size: 16px;
outline: none;
}
</style>
</head>
<body>
<div>
<button class="button" onclick="fetchCount('cs-playground-react')">cs-playground-react</button>
<button class="button" onclick="fetchCount('portfolio')">peterweinberg.me</button>
</div>
<div id='main'>
<div id="header">
█▬█ █ ▀█▀
</div>
<div id="currentSite"></div>
<div id="currentHits"></div>
<div id="startedDate"></div>
<div id="currentDate"></div>
<div id="todaysCount"></div>
<div id="averageHits"></div>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.min.js'></script>
<script>
const setBackground = () => {
const rand = () => Math.round(Math.random() * (250));
const red = rand();
const blue = rand();
const green = rand();
const randColor = `rgb(${red}, ${green}, ${blue})`;
document.body.style.background = randColor;
document.getElementsByClassName('button')[0].style.color = randColor;
document.getElementsByClassName('button')[1].style.color = randColor;
}
(function() {
setBackground();
setInterval(() => setBackground(), 5000);
})();
let currentHost = 'cs-playground-react';
const fetchCount = (host) => {
currentHost = host;
axios.get(`/get-count/${currentHost}`)
.then(res => {
document.getElementById('currentSite').innerHTML = `Counting hits for: <a href="${res.data.host}" target="_blank" rel="noopener noreferrer">${res.data.host}</a>`;
document.getElementById('currentHits').innerHTML = `The current count is: ${res.data.totalCount}`;
document.getElementById('startedDate').innerHTML = `The count began on ${res.data.startDate}`;
document.getElementById('currentDate').innerHTML = `Today's date is ${res.data.currentDate}`;
document.getElementById('todaysCount').innerHTML = `Hits today: ${res.data.todaysCount}`;
document.getElementById('averageHits').innerHTML = `Average hits per day: ${res.data.average}`;
})
.catch(err => {
document.getElementById('main').innerHTML = 'There was an error fetching the count...';
});
};
(function() {
fetchCount(currentHost);
setInterval(() => fetchCount(currentHost), 60000);
})();
</script>
</body>
</html>