-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
118 lines (108 loc) · 2.95 KB
/
index.html
File metadata and controls
118 lines (108 loc) · 2.95 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Speed Test</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #1f1c2c, #928dab);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #fff;
}
.container {
background-color: rgba(0, 0, 0, 0.7);
padding: 2rem;
border-radius: 1rem;
text-align: center;
width: 90%;
max-width: 400px;
box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}
h1 {
margin-bottom: 1rem;
}
button {
background-color: #00c9ff;
border: none;
color: white;
padding: 0.75rem 2rem;
border-radius: 50px;
font-size: 1rem;
cursor: pointer;
margin-top: 1rem;
transition: background-color 0.3s;
}
button:hover {
background-color: #0096c7;
}
.result {
margin-top: 1.5rem;
font-size: 1.2rem;
}
.loader {
margin-top: 1rem;
border: 4px solid rgba(255, 255, 255, 0.2);
border-top: 4px solid #00c9ff;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
display: none;
margin-left: auto;
margin-right: auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@media screen and (max-width: 500px) {
.container {
padding: 1.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Internet Speed Test</h1>
<button onclick="startSpeedTest()">Start Test</button>
<div class="loader" id="loader"></div>
<div class="result" id="result"></div>
</div>
<script>
async function startSpeedTest() {
const resultEl = document.getElementById("result");
const loader = document.getElementById("loader");
resultEl.textContent = '';
loader.style.display = 'block';
// Simulate test (you can replace with actual API or logic)
const testStart = performance.now();
try {
const response = await fetch("https://speed.hetzner.de/100MB.bin"); // 100MB test file
const reader = response.body.getReader();
let totalBytes = 0;
while (true) {
const { done, value } = await reader.read();
if (done) break;
totalBytes += value.length;
}
const testEnd = performance.now();
const duration = (testEnd - testStart) / 1000;
const speedMbps = ((totalBytes * 8) / 1_000_000) / duration;
loader.style.display = 'none';
resultEl.textContent = `Download Speed: ${speedMbps.toFixed(2)} Mbps`;
} catch (err) {
loader.style.display = 'none';
resultEl.textContent = "Test failed. Check your connection.";
}
}
</script>
</body>
</html>