-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.html
79 lines (79 loc) · 2.38 KB
/
widget.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
<html lang="en">
<head>
<script>
// get target domain from URL query parameters
var targetDomain = new URLSearchParams(window.location.search).get("domain");
// build URL to fetch count from
// var url = "http://127.0.0.1:7711?domain=" + targetDomain;
var url = "https://ipnotes.page/stats?domain=" + targetDomain;
// fetch count from URL with AJAX
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = function() {
// parse response as JSON
var response = JSON.parse(xhr.responseText);
document.getElementById("ipnotes-domain").innerHTML = response.domain;
var count = response.count;
if (count < 0) {
document.getElementById("counts").style.display = "none";
document.getElementById("offline").style.display = "block";
} else {
// add commas to count
count = count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
document.getElementById("ipnotes-count").innerHTML = count;
}
// reveal widget
document.getElementById("ipnotes-box").style.display = "block";
}
xhr.send();
</script>
<style>
body {
background-color: black;
margin: 0;
padding: 0;
font-family: sans-serif;
width: 100%;
height: 100%;
}
#ipnotes-box {
color: white;
padding: 0.5em;
max-width: 350px;
max-height: 350px;
margin: 0 auto;
display: none;
}
#ipnotes-box #header {
font-size: 1em;
font-weight: bold;
margin-bottom: 0.5em;
}
#offline {
display: none;
}
</style>
</head>
<body>
<div id="ipnotes-box">
<div id="header">
<!-- wifi icon -->
<span id="ipnotes-domain"></span>
</div>
<div id="counts">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-circle-fill" fill="#28a745" xmlns="http://www.w3.org/2000/svg">
<circle cx="8" cy="8" r="8"/>
</svg>
<span>Users online:</span>
<span id="ipnotes-count"></span>
</div>
<div id="offline">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-circle-fill" fill="#dc3545" xmlns="http://www.w3.org/2000/svg">
<circle cx="8" cy="8" r="8"/>
</svg>
<span>Users online:</span>
<span>N/A</span>
</div>
</div>
</body>
</html>