-
Notifications
You must be signed in to change notification settings - Fork 2
/
average.html
145 lines (124 loc) · 5.03 KB
/
average.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Real SpeedTest</title>
<meta charset="UTF-8">
<meta name="description" content="Test your internet connection for download speed and latency for real life usage.">
<meta name="keywords" content="speedtest">
<meta name="author" content="TheDoggyBrad">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="resources/favicon.png">
<link rel="preload" href="resources/dark.css" as="style" />
<link rel="preload" href="resources/light.css" as="style" />
<link rel="preload" href="resources/dark-mode-toggle-playground.mjs" as="script" />
<link rel="preload" href="resources/dark-mode-toggle.mjs" as="script" />
<link rel="preload" href="resources/sliders.css" as="style" />
<link rel="preload" href="testing/latency-script.js" as="script" />
<link rel="preload" href="testing/downloadtest.js" as="script" />
<link rel="preload" href="testing/latencytest.js" as="script" />
<link rel="preload" href="resources/default.js" as="script" />
<link rel="preload" href="resources/style.css" as="style" />
<link rel="stylesheet" href="resources/style.css">
<script src="resources/default.js"></script>
<link
rel="stylesheet"
href="resources/dark.css"
media="(prefers-color-scheme: dark)"
/>
<link
rel="stylesheet"
href="resources/light.css"
media="(prefers-color-scheme: light)"
/>
<link rel="stylesheet" href="resources/sliders.css" />
<script type="module" src="resources/dark-mode-toggle-playground.mjs"></script>
<script type="module" src="resources/dark-mode-toggle.mjs"></script>
<script>
var imageAddr = "https://github.com/thedoggybrad/speedtest/releases/download/nextgenimg/average.jpg";
var downloadSize = 17600000; //bytes
function ShowProgressMessage(msg) {
if (console) {
if (typeof msg == "string") {
console.log(msg);
} else {
for (var i = 0; i < msg.length; i++) {
console.log(msg[i]);
}
}
}
var oProgress = document.getElementById("progress");
if (oProgress) {
var actualHTML = (typeof msg == "string") ? msg : msg.join("<br />");
oProgress.innerHTML = actualHTML;
}
}
function InitiateSpeedDetection() {
ShowProgressMessage("Testing...");
window.setTimeout(MeasureConnectionSpeed, 1);
};
if (window.addEventListener) {
window.addEventListener('load', InitiateSpeedDetection, false);
} else if (window.attachEvent) {
window.attachEvent('onload', InitiateSpeedDetection);
}
function MeasureConnectionSpeed() {
var startTime, endTime;
var download = new Image();
download.onload = function () {
endTime = (new Date()).getTime();
showResults();
}
download.onerror = function (err, msg) {
ShowProgressMessage("Retry testing again!");
}
startTime = (new Date()).getTime();
var cacheBuster = "?nnn=" + startTime;
download.src = imageAddr + cacheBuster;
function showResults() {
var duration = (endTime - startTime) / 1000;
var bitsLoaded = downloadSize * 8;
var speedBps = (bitsLoaded / duration).toFixed(2);
var speedKbps = (speedBps / 1024).toFixed(2);
var speedMbps = (speedKbps / 1024).toFixed(2);
var speedMps = (speedMbps / 8).toFixed(2);
ShowProgressMessage([
speedMbps + " Mbps (Bits)<br>" +
speedMps + " MBps (Bytes)"
]);
}
}
</script>
<script src="testing/latency-script.js"></script>
</head>
<body>
<a href="index.html">Return to home</a>
<dark-mode-toggle
id="dark-mode-toggle-5"
class="slider"
legend="Dark Mode"
appearance="toggle"
remember="Remember this"
></dark-mode-toggle>
<img src="resources/favicon.png" alt="LOGO" class="imgcenter" width="64" height="64">
<h1 class="header">Real SpeedTest</h1></div>
<h3 class="intro">Test your internet connection for download speed and latency for real life usage.</h3>
<br>
<div style="text-align: center;" class="latency">
<img id="latency-injection" hidden="hidden" />
<h1 style="text-align: center; position: relative;" class="lt1">Latency:</h1>
<h1 style="text-align: center; position: relative;" class="lt2" id="latency-result">Testing....</h1>
</div>
<script src="testing/latencytest.js"></script>
<br>
<div style="text-align: center; position: relative;" class="download">
<h1 style="text-align: center; position: relative;" class="lt1">Download Speed:</h1>
<br>
<h1 style="text-align: center; position: relative;" id="progress" class="progress">Please Wait...</h1>
</div>
<br>
<br>
<button class="retest-btn" onClick="window.location.reload();">Re-test</button>
<footer class="documentation"><p><a href="https://github.com/thedoggybrad/speedtest/blob/main/README.md">Documentation</a></p></footer>
<footer class="footer"><p>©<a href="https://github.com/thedoggybrad/">TheDoggyBrad Software Lab</a>. Provided under <a href="https://github.com/thedoggybrad/speedtest/blob/main/License/">ISC License</a>.</p></footer>
</body>
</html>