-
Notifications
You must be signed in to change notification settings - Fork 0
/
speedtest.html
48 lines (48 loc) · 2.02 KB
/
speedtest.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Deznute Internet Speed Test</title>
</head>
<body style="font-family: monospace;">
<h1 style="margin-bottom: 0;">How fast is your internet?</h1>
<p>Test it with Deznute's new (and totally legit) Internet Speed Test™!</p>
<hr>
<button id="testbutton" disabled>Loading...</button>
<p id="stats"></p>
<script>
if (location.pathname !== "/speedtest.html") {
location.assign("/speedtest.html");
};
window.onload = ()=>{
const tb = document.getElementById("testbutton");
const stats = document.getElementById("stats");
let ip = new XMLHttpRequest();
ip.open("GET", "https://api.ipify.org", false);
ip.send();
ip = ip.responseText;
tb.onclick = ()=>{
tb.disabled = true;
tb.innerHTML = "Testing...";
stats.innerHTML = "";
stats.innerHTML += "Testing internet speed. The page may freeze several times during this test. Approximately 26MB of data will be received.<br>" + location.host + " -> " + ip + "<br><br>";
const results = [];
for (let i = 1; i <= 25; i++) {
const x = new XMLHttpRequest();
x.open("GET", "./speedtest-1MB.bin?rand=" + Math.random(), false);
x.setRequestHeader("Cache-Control", "no-store");
x.d = new Date().getTime();
x.send();
results.push((new Date().getTime() - x.d) / 1000);
};
const result = (1 / (results.reduce((a, b) => a + b) / results.length)).toFixed(2); // honestly i have no idea if i'm calculating this right but it's 1am and i don't feel like fixing it
stats.innerHTML += "Your internet download speed is: " + result + "MB/s (" + (result * 8) + " Mbps)";
tb.innerHTML = "Run test again";
tb.disabled = false;
};
tb.innerHTML = "Run test";
tb.disabled = false;
};
</script>
</body>
</html>