-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeedtest.html
More file actions
768 lines (715 loc) Β· 25.1 KB
/
speedtest.html
File metadata and controls
768 lines (715 loc) Β· 25.1 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>SpeedTest Pro | Netflix-Style Speed Test</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #0a0c10;
font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
/* main container - new premium color scheme (dark royal & neon accents) */
.speedtest-container {
max-width: 780px;
width: 100%;
background: #0b0e17;
border-radius: 36px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
padding: 2rem 2rem 2.2rem;
border: 1px solid rgba(255, 215, 0, 0.2);
transition: all 0.2s;
}
/* header */
.brand {
display: flex;
justify-content: space-between;
align-items: baseline;
flex-wrap: wrap;
margin-bottom: 2.2rem;
border-bottom: 1px solid #2a2f3c;
padding-bottom: 1rem;
}
.logo {
font-weight: 700;
font-size: 1.6rem;
background: linear-gradient(135deg, #FFD966, #FFB347);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
letter-spacing: -0.5px;
}
/* speedometer area */
.speed-panel {
background: #080b12;
border-radius: 44px;
padding: 2rem 1.2rem;
margin-bottom: 1.8rem;
box-shadow: inset 0 1px 3px #00000040, 0 10px 25px -5px black;
border: 1px solid #2a2f40;
}
.speed-number {
text-align: center;
}
.speed-main {
font-size: 5.5rem;
font-weight: 800;
font-family: 'JetBrains Mono', monospace;
color: #FFE6B0;
letter-spacing: -2px;
line-height: 1;
}
.speed-unit {
font-size: 1.6rem;
font-weight: 500;
color: #B9A97C;
margin-left: 8px;
}
.speed-label {
text-align: center;
color: #A7B5D9;
letter-spacing: 1px;
font-size: 0.85rem;
margin-top: 6px;
font-weight: 500;
}
/* latency row style */
.latency-panel {
display: flex;
justify-content: space-between;
gap: 16px;
margin: 20px 0 24px;
flex-wrap: wrap;
}
.latency-card {
background: #0f121c;
flex: 1;
border-radius: 32px;
padding: 12px 16px;
text-align: center;
border: 1px solid #292f3e;
}
.latency-title {
font-size: 0.7rem;
text-transform: uppercase;
color: #B8C7FF;
letter-spacing: 1px;
}
.latency-value {
font-size: 1.8rem;
font-weight: 600;
color: #FFF2DF;
margin-top: 6px;
}
.latency-unit {
font-size: 0.8rem;
color: #A2B0D0;
}
.upload-row {
margin-top: 12px;
background: #0f121c;
border-radius: 52px;
padding: 18px 20px;
display: flex;
justify-content: space-between;
align-items: baseline;
flex-wrap: wrap;
border: 1px solid #2d3345;
}
.upload-text {
font-weight: 500;
color: #D9D2BF;
}
.upload-value {
font-size: 1.9rem;
font-weight: 700;
color: #FFE2B5;
font-family: monospace;
}
/* button & status - vibrant gradient */
.test-btn {
width: 100%;
background: linear-gradient(95deg, #E68A2E, #FFB347);
border: none;
padding: 18px;
font-size: 1.3rem;
font-weight: bold;
font-family: inherit;
color: #0F1117;
border-radius: 60px;
cursor: pointer;
transition: 0.2s;
margin: 24px 0 16px;
box-shadow: 0 8px 20px rgba(255, 180, 71, 0.3);
}
.test-btn:active {
transform: scale(0.98);
background: linear-gradient(95deg, #DD751B, #FFA01E);
}
.test-btn:disabled {
opacity: 0.6;
transform: none;
cursor: not-allowed;
}
.status-msg {
text-align: center;
font-size: 0.85rem;
color: #B7C3E6;
background: #0B0E17;
border-radius: 36px;
padding: 12px;
}
footer {
font-size: 0.7rem;
text-align: center;
margin-top: 26px;
color: #4C5B7A;
}
.spinner-sm {
display: inline-block;
width: 18px;
height: 18px;
border: 2px solid rgba(0,0,0,0.2);
border-top: 2px solid white;
border-radius: 50%;
animation: spin 0.7s linear infinite;
margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* ============= RESULT MODAL ============= */
.result-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.88);
backdrop-filter: blur(14px);
z-index: 1000;
display: flex;
justify-content: center;
align-items: center;
visibility: hidden;
opacity: 0;
transition: visibility 0.2s, opacity 0.2s;
}
.result-overlay.active {
visibility: visible;
opacity: 1;
}
.result-card {
background: linear-gradient(145deg, #0F172A, #0A0F1C);
max-width: 540px;
width: 90%;
border-radius: 56px;
padding: 2rem;
text-align: center;
border: 1px solid rgba(255, 180, 71, 0.5);
box-shadow: 0 40px 70px rgba(0, 0, 0, 0.7);
transform: scale(0.9);
transition: transform 0.25s ease;
}
.result-overlay.active .result-card {
transform: scale(1);
}
.result-icon {
font-size: 4rem;
margin-bottom: 0.5rem;
}
.result-title {
font-size: 1.8rem;
font-weight: 800;
background: linear-gradient(135deg, #FFD966, #FFA947);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
margin-bottom: 1.2rem;
}
.result-item {
display: flex;
justify-content: space-between;
align-items: center;
background: #111a2b;
margin: 12px 0;
padding: 14px 20px;
border-radius: 60px;
font-weight: 500;
}
.result-label {
color: #B9C7E0;
font-size: 1rem;
}
.result-value {
color: #FFF0CE;
font-size: 1.3rem;
font-weight: 700;
font-family: monospace;
}
/* DETAILS BUTTON & DETAILS PANEL (expandable) */
.details-btn {
background: #1F2A3E;
border: 1px solid #FFB347;
color: #FFD791;
padding: 12px 18px;
border-radius: 44px;
font-weight: 600;
margin: 16px 0 8px;
width: 100%;
cursor: pointer;
font-size: 0.95rem;
transition: 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.details-btn:active {
transform: scale(0.97);
background: #2A364E;
}
.extra-details {
background: #0D1424;
border-radius: 38px;
padding: 0 16px;
max-height: 0;
overflow: hidden;
transition: max-height 0.4s ease-out, padding 0.2s;
margin-top: 8px;
border: 1px solid transparent;
}
.extra-details.show-details {
max-height: 280px;
padding: 16px 16px;
border-color: #FFB34740;
background: #0A1020;
}
.detail-line {
display: flex;
justify-content: space-between;
margin: 12px 6px;
font-size: 0.9rem;
border-bottom: 1px dashed #2a3145;
padding-bottom: 6px;
}
.detail-label {
color: #97A9D0;
font-weight: 500;
}
.detail-value {
color: #FFE2B5;
font-family: monospace;
font-weight: 500;
}
.close-result-btn {
width: 100%;
background: linear-gradient(95deg, #f59e0b, #f97316);
border: none;
padding: 14px;
font-size: 1.1rem;
font-weight: bold;
border-radius: 60px;
color: #0f172a;
margin-top: 12px;
cursor: pointer;
transition: 0.1s;
}
.close-result-btn:active {
transform: scale(0.97);
}
</style>
</head>
<body>
<div class="speedtest-container">
<div class="brand">
<div class="logo">β‘ SpeedTest by (CURL-XD)</div>
</div>
<!-- main speed panel: Download -->
<div class="speed-panel">
<div class="speed-number">
<span id="downloadMain" class="speed-main">0</span>
<span id="downloadUnit" class="speed-unit">Mbps</span>
</div>
<div class="speed-label">DOWNLOAD SPEED</div>
</div>
<!-- latency (unloaded + loaded) -->
<div class="latency-panel">
<div class="latency-card">
<div class="latency-title">PING (UNLOADED)</div>
<div class="latency-value"><span id="unloadedLatency">β</span><span class="latency-unit">ms</span></div>
</div>
<div class="latency-card">
<div class="latency-title">LOADED LATENCY <span style="font-size:10px">(during DL)</span></div>
<div class="latency-value"><span id="loadedLatency">β</span><span class="latency-unit">ms</span></div>
</div>
</div>
<!-- upload + extra -->
<div class="upload-row">
<span class="upload-text">π€ UPLOAD SPEED</span>
<span><span id="uploadValue" class="upload-value">0.00</span> <span id="uploadUnitLabel" class="latency-unit">Mbps</span></span>
</div>
<button id="runTestBtn" class="test-btn">π START SPEED TEST</button>
<div id="statusMessagePro" class="status-msg">Ready. Click the button to begin.</div>
<footer>β‘ Parallel connections x4 Β· Accurate real-time results</footer>
</div>
<!-- RESULT MODAL (new page style) with DETAILS option -->
<div id="resultModal" class="result-overlay">
<div class="result-card">
<div class="result-icon">π</div>
<div class="result-title">Your Speed Results</div>
<div class="result-item">
<span class="result-label">π₯ Download Speed</span>
<span class="result-value" id="resultDownload">β</span>
</div>
<div class="result-item">
<span class="result-label">π€ Upload Speed</span>
<span class="result-value" id="resultUpload">β</span>
</div>
<div class="result-item">
<span class="result-label">π‘ Ping (Unloaded)</span>
<span class="result-value" id="resultPing">β</span>
</div>
<div class="result-item">
<span class="result-label">β‘ Loaded Latency</span>
<span class="result-value" id="resultLoaded">β</span>
</div>
<!-- Details button (tap to see IP, country, ISP, etc) -->
<button id="toggleDetailsBtn" class="details-btn">π View Details (IP, Country, ISP)</button>
<div id="extraDetailsPanel" class="extra-details">
<div class="detail-line">
<span class="detail-label">π IP Address</span>
<span class="detail-value" id="detailIp">β</span>
</div>
<div class="detail-line">
<span class="detail-label">π Country / Region</span>
<span class="detail-value" id="detailCountry">β</span>
</div>
<div class="detail-line">
<span class="detail-label">π’ ISP / Network</span>
<span class="detail-value" id="detailISP">β</span>
</div>
<div class="detail-line">
<span class="detail-label">π Server Time</span>
<span class="detail-value" id="detailTime">β</span>
</div>
</div>
<button class="close-result-btn" id="closeResultBtn">π RUN NEW TEST</button>
</div>
</div>
<script>
(function(){
// DOM elements - main UI
const downloadSpan = document.getElementById('downloadMain');
const downloadUnitSpan = document.getElementById('downloadUnit');
const unloadedLatSpan = document.getElementById('unloadedLatency');
const loadedLatSpan = document.getElementById('loadedLatency');
const uploadSpan = document.getElementById('uploadValue');
const uploadUnitLabel = document.getElementById('uploadUnitLabel');
const statusDiv = document.getElementById('statusMessagePro');
const testBtn = document.getElementById('runTestBtn');
// result modal elements
const resultModal = document.getElementById('resultModal');
const resultDownloadSpan = document.getElementById('resultDownload');
const resultUploadSpan = document.getElementById('resultUpload');
const resultPingSpan = document.getElementById('resultPing');
const resultLoadedSpan = document.getElementById('resultLoaded');
const closeResultBtn = document.getElementById('closeResultBtn');
const toggleDetailsBtn = document.getElementById('toggleDetailsBtn');
const extraDetailsPanel = document.getElementById('extraDetailsPanel');
// details fields
const detailIpSpan = document.getElementById('detailIp');
const detailCountrySpan = document.getElementById('detailCountry');
const detailISPSpan = document.getElementById('detailISP');
const detailTimeSpan = document.getElementById('detailTime');
let isRunning = false;
let lastResults = { download: null, upload: null, ping: null, loaded: null };
let networkDetailsCache = { ip: 'β', country: 'β', isp: 'β' };
// Fetch IP, Country & ISP from free APIs (robust fallback)
async function fetchNetworkDetails() {
// Try ipapi.co first (reliable, no token)
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 4500);
const response = await fetch('https://ipapi.co/json/', { signal: controller.signal });
clearTimeout(timeoutId);
if (response.ok) {
const data = await response.json();
networkDetailsCache = {
ip: data.ip || 'β',
country: data.country_name ? `${data.country_name} (${data.country_code})` : (data.country || 'β'),
isp: data.org || data.asn ? (data.org || data.asn) : (data.isp || 'Network not specified')
};
updateDetailsUI();
return;
}
} catch (e) {
console.warn("ipapi.co failed, trying fallback...");
}
// Fallback 1: ipinfo.io (requires no token for demo, but limited)
try {
const resFallback = await fetch('https://ipinfo.io/json?nocache='+Date.now(), { signal: AbortSignal.timeout(4000) });
if (resFallback.ok) {
const fallbackData = await resFallback.json();
networkDetailsCache = {
ip: fallbackData.ip || 'β',
country: fallbackData.country ? `${fallbackData.country}` : (fallbackData.region || 'β'),
isp: fallbackData.org || fallbackData.hostname || 'ISP info not available'
};
updateDetailsUI();
return;
}
} catch(e) { console.warn("ipinfo fallback failed") }
// Final fallback: cloudflare trace (shows IP)
try {
const cfRes = await fetch('https://www.cloudflare.com/cdn-cgi/trace', { cache: 'no-store', signal: AbortSignal.timeout(3000) });
if (cfRes.ok) {
const text = await cfRes.text();
const ipMatch = text.match(/ip=([^\n]+)/);
const ip = ipMatch ? ipMatch[1] : 'β';
networkDetailsCache = {
ip: ip,
country: 'Not detected',
isp: 'Cloudflare CDN'
};
updateDetailsUI();
return;
}
} catch(e) {}
networkDetailsCache = { ip: 'Unavailable', country: 'Unknown', isp: 'Could not retrieve' };
updateDetailsUI();
}
function updateDetailsUI() {
detailIpSpan.innerText = networkDetailsCache.ip;
detailCountrySpan.innerText = networkDetailsCache.country;
detailISPSpan.innerText = networkDetailsCache.isp;
detailTimeSpan.innerText = new Date().toLocaleString();
}
// Toggle details panel open/close
toggleDetailsBtn.addEventListener('click', () => {
extraDetailsPanel.classList.toggle('show-details');
// Also refresh network details each time user opens for freshness
if (extraDetailsPanel.classList.contains('show-details')) {
fetchNetworkDetails(); // refresh IP / country / ISP
toggleDetailsBtn.innerHTML = 'π½ Hide IP & Country';
} else {
toggleDetailsBtn.innerHTML = 'π View Details (IP, Country, ISP)';
}
});
function setStatus(msg, isError = false) {
statusDiv.innerHTML = msg;
statusDiv.style.color = isError ? "#FFBC8C" : "#A7B5D9";
}
function showResultModal() {
if (lastResults.download !== null) {
resultDownloadSpan.innerHTML = lastResults.download;
resultUploadSpan.innerHTML = lastResults.upload;
resultPingSpan.innerHTML = lastResults.ping;
resultLoadedSpan.innerHTML = lastResults.loaded;
// Always update details panel with latest network info before showing
fetchNetworkDetails().then(() => {
detailIpSpan.innerText = networkDetailsCache.ip;
detailCountrySpan.innerText = networkDetailsCache.country;
detailISPSpan.innerText = networkDetailsCache.isp;
detailTimeSpan.innerText = new Date().toLocaleString();
});
// ensure details panel collapsed initially
extraDetailsPanel.classList.remove('show-details');
toggleDetailsBtn.innerHTML = 'π View Details (IP, Country, ISP)';
resultModal.classList.add('active');
}
}
function hideResultModal() {
resultModal.classList.remove('active');
}
// Utility: measure unloaded latency
async function getUnloadedLatency(timeout=5000) {
const start = performance.now();
try {
const ctrl = new AbortController();
const tid = setTimeout(() => ctrl.abort(), timeout);
await fetch('https://www.cloudflare.com/cdn-cgi/trace?nocache='+Date.now(), { method: 'HEAD', signal: ctrl.signal, cache: 'no-store' });
clearTimeout(tid);
return performance.now() - start;
} catch(e) {
try {
const start2 = performance.now();
await fetch('https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2?cacheb='+Date.now(), { method: 'GET', cache: 'no-store', signal: AbortSignal.timeout(4000) });
return performance.now() - start2;
} catch(e2) {
return null;
}
}
}
// Loaded latency measurement DURING download test
async function measureLoadedLatencyDuringDownload(downloadPromise, sampleIntervalMs = 400) {
let measurements = [];
let intervalId;
const latencySampler = async () => {
try {
const s = performance.now();
await fetch('https://www.cloudflare.com/cdn-cgi/trace?ping='+Date.now(), { method: 'HEAD', cache: 'no-store', signal: AbortSignal.timeout(800) });
const dur = performance.now() - s;
if (dur < 2000) measurements.push(dur);
} catch(e) {}
};
intervalId = setInterval(latencySampler, sampleIntervalMs);
try {
await downloadPromise;
} finally {
clearInterval(intervalId);
}
if (measurements.length === 0) return null;
measurements.sort((a,b)=>a-b);
const median = measurements[Math.floor(measurements.length/2)];
return Math.round(median);
}
// Advanced Download: parallel connections
async function runParallelDownload(numConnections = 4, testBytes = 7 * 1024 * 1024) {
const urls = Array(numConnections).fill().map((_,idx) => `https://speed.cloudflare.com/__down?bytes=${testBytes}&conn=${idx}&v=${Date.now()}`);
const fetchPromises = urls.map(async (url) => {
const start = performance.now();
const res = await fetch(url, { cache: 'no-store', signal: AbortSignal.timeout(12000) });
if (!res.ok) throw new Error(`DL fail status: ${res.status}`);
const data = await res.arrayBuffer();
const duration = (performance.now() - start) / 1000;
const bytesLoaded = data.byteLength;
const bits = bytesLoaded * 8;
const speedMbps = (bits / duration) / (1024 * 1024);
return speedMbps;
});
const speeds = await Promise.all(fetchPromises);
const totalMbps = speeds.reduce((sum, sp) => sum + sp, 0);
return totalMbps;
}
// Upload measurement with parallel POSTs
async function measureUploadParallel(simultaneous = 3, chunkSizeMB = 2.5) {
const uploadUrl = 'https://httpbin.org/post';
const payloadSize = chunkSizeMB * 1024 * 1024;
const generateBlob = () => {
const buffer = new Uint8Array(payloadSize);
for (let i = 0; i < buffer.length; i+= 16384) {
const fill = new Uint8Array(Math.min(16384, buffer.length - i));
for (let j=0;j<fill.length;j++) fill[j] = (i+j) % 256;
buffer.set(fill, i);
}
return new Blob([buffer], {type: 'application/octet-stream'});
};
const tasks = [];
for (let i=0; i<simultaneous; i++) {
const formData = new FormData();
formData.append('upfile', generateBlob(), `test${i}.dat`);
tasks.push(fetch(uploadUrl, { method: 'POST', body: formData, cache: 'no-store', signal: AbortSignal.timeout(15000) }));
}
const startTotal = performance.now();
const responses = await Promise.all(tasks);
for (let res of responses) if (!res.ok) throw new Error('upload part failed');
await Promise.all(responses.map(r => r.json()));
const durationSec = (performance.now() - startTotal) / 1000;
const totalBits = (payloadSize * 8) * simultaneous;
const speedMbps = (totalBits / durationSec) / (1024 * 1024);
return speedMbps;
}
function formatSpeed(mbps) {
if (mbps >= 1000) {
return { val: (mbps / 1000).toFixed(1), unit: "Gbps" };
}
return { val: mbps.toFixed(1), unit: "Mbps" };
}
async function runSpeedtest() {
if (isRunning) { setStatus("Test in progress, please wait..."); return; }
isRunning = true;
testBtn.disabled = true;
testBtn.innerHTML = '<span class="spinner-sm"></span> Testing...';
setStatus("π Starting parallel connection speed test...");
// reset UI
downloadSpan.innerText = "0";
downloadUnitSpan.innerText = "Mbps";
unloadedLatSpan.innerText = "β";
loadedLatSpan.innerText = "β";
uploadSpan.innerText = "0.00";
uploadUnitLabel.innerText = "Mbps";
try {
// Refresh network details before test (optional but good)
await fetchNetworkDetails();
// measure unloaded latency
setStatus("π‘ Measuring ping...");
const unloaded = await getUnloadedLatency();
const pingDisplay = (unloaded !== null) ? Math.round(unloaded) : "?";
unloadedLatSpan.innerText = pingDisplay;
await new Promise(r => setTimeout(r, 300));
// Step 2: parallel download + loaded latency
setStatus("β¬οΈ Measuring download speed (4 parallel connections)...");
const downloadPromise = runParallelDownload(4, 7 * 1024 * 1024);
const loadedLatencyMs = await measureLoadedLatencyDuringDownload(downloadPromise, 400);
if (loadedLatencyMs) loadedLatSpan.innerText = loadedLatencyMs;
else loadedLatSpan.innerText = "β";
let downloadMbps = await downloadPromise;
const dlFormatted = formatSpeed(downloadMbps);
downloadSpan.innerText = dlFormatted.val;
downloadUnitSpan.innerText = dlFormatted.unit;
setStatus(`β¬οΈ Measuring upload speed...`);
await new Promise(r => setTimeout(r, 500));
// Step 3: upload test
let uploadMbps = await measureUploadParallel(3, 2.5);
const upFormatted = formatSpeed(uploadMbps);
uploadSpan.innerText = upFormatted.val;
uploadUnitLabel.innerText = upFormatted.unit;
// Store results for modal
lastResults = {
download: `${dlFormatted.val} ${dlFormatted.unit}`,
upload: `${upFormatted.val} ${upFormatted.unit}`,
ping: (unloaded !== null) ? `${Math.round(unloaded)} ms` : "? ms",
loaded: (loadedLatencyMs) ? `${loadedLatencyMs} ms` : "β ms"
};
setStatus(`β
Test completed! Showing results...`);
// Show modal after completion
showResultModal();
} catch (err) {
console.error("speedtest error", err);
setStatus(`β οΈ Test failed: ${err.message || "Check network connectivity"}`, true);
downloadSpan.innerText = "0";
uploadSpan.innerText = "0.00";
lastResults = {
download: "0 Mbps",
upload: "0 Mbps",
ping: "β",
loaded: "β"
};
} finally {
isRunning = false;
testBtn.disabled = false;
testBtn.innerHTML = "π START SPEED TEST";
}
}
// Close modal and reset status message (remove any extra text)
function closeModalAndReset() {
hideResultModal();
setStatus("Ready. Click the button to begin.");
}
testBtn.addEventListener('click', () => {
if (!isRunning) {
runSpeedtest();
}
});
closeResultBtn.addEventListener('click', () => {
hideResultModal();
setStatus("Ready. Click the button to begin.");
});
// Load initial network details on page load, but no extra "Click ..." removed.
window.addEventListener('load', () => {
setStatus("Ready. Click the button to begin.");
fetchNetworkDetails();
});
})();
</script>
</body>
</html>