Merge with v4.5
This commit is contained in:
parent
2a72700e56
commit
ec6b55ca11
296
index.html
296
index.html
|
@ -1,113 +1,193 @@
|
|||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
|
||||
<title>Speedtest</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
|
||||
<title>HTML5 Speedtest</title>
|
||||
<style type="text/css">
|
||||
html,body{
|
||||
border:none; padding:0; margin:0;
|
||||
background:#FFFFFF;
|
||||
color:#202020;
|
||||
}
|
||||
body{
|
||||
text-align:center;
|
||||
font-family:"Roboto",sans-serif;
|
||||
}
|
||||
h1{
|
||||
color:#404040;
|
||||
}
|
||||
#startStopBtn{
|
||||
display:inline-block;
|
||||
margin:0 auto;
|
||||
color:#6060AA;
|
||||
background-color:rgba(0,0,0,0);
|
||||
border:0.15em solid #6060FF;
|
||||
border-radius:0.3em;
|
||||
transition:all 0.3s;
|
||||
box-sizing:border-box;
|
||||
width:8em; height:3em;
|
||||
line-height:2.7em;
|
||||
cursor:pointer;
|
||||
box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
|
||||
}
|
||||
#startStopBtn:hover{
|
||||
box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
|
||||
}
|
||||
#startStopBtn.running{
|
||||
background-color:#FF3030;
|
||||
border-color:#FF6060;
|
||||
color:#FFFFFF;
|
||||
}
|
||||
#startStopBtn:before{
|
||||
content:"Start";
|
||||
}
|
||||
#startStopBtn.running:before{
|
||||
content:"Abort";
|
||||
}
|
||||
#test{
|
||||
margin-top:2em;
|
||||
margin-bottom:12em;
|
||||
}
|
||||
div.testArea{
|
||||
display:inline-block;
|
||||
width:14em;
|
||||
height:9em;
|
||||
position:relative;
|
||||
box-sizing:border-box;
|
||||
}
|
||||
div.testName{
|
||||
position:absolute;
|
||||
top:0.1em; left:0;
|
||||
width:100%;
|
||||
font-size:1.4em;
|
||||
z-index:9;
|
||||
}
|
||||
div.meterText{
|
||||
position:absolute;
|
||||
bottom:1.5em; left:0;
|
||||
width:100%;
|
||||
font-size:2.5em;
|
||||
z-index:9;
|
||||
}
|
||||
#dlText{
|
||||
color:#6060AA;
|
||||
}
|
||||
#ulText{
|
||||
color:#309030;
|
||||
}
|
||||
#pingText,#jitText{
|
||||
color:#AA6060;
|
||||
}
|
||||
div.meterText:empty:before{
|
||||
color:#505050 !important;
|
||||
content:"0.00";
|
||||
}
|
||||
div.unit{
|
||||
position:absolute;
|
||||
bottom:2em; left:0;
|
||||
width:100%;
|
||||
z-index:9;
|
||||
}
|
||||
div.testGroup{
|
||||
display:inline-block;
|
||||
}
|
||||
@media all and (max-width:65em){
|
||||
body{
|
||||
font-size:1.5vw;
|
||||
}
|
||||
}
|
||||
@media all and (max-width:40em){
|
||||
body{
|
||||
font-size:0.8em;
|
||||
}
|
||||
div.testGroup{
|
||||
display:block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<style type="text/css">
|
||||
.st-block {
|
||||
text-align: center;
|
||||
}
|
||||
.st-btn {
|
||||
margin-top: -0.5rem;
|
||||
margin-left: 1.5rem;
|
||||
}
|
||||
.st-value>span:empty::before {
|
||||
content: "0.00";
|
||||
color: #636c72;
|
||||
}
|
||||
#st-ip:empty::before {
|
||||
content: "___.___.___.___";
|
||||
color: #636c72;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function I(id){return document.getElementById(id);}
|
||||
|
||||
var w=null; //speedtest worker
|
||||
function startStop(){
|
||||
if(w!=null){
|
||||
//speedtest is running, abort
|
||||
w.postMessage('abort');
|
||||
w=null;
|
||||
I("startStopBtn").className="";
|
||||
initUI();
|
||||
}else{
|
||||
//test is not running, begin
|
||||
w=new Worker('speedtest_worker.min.js');
|
||||
w.postMessage('start'); //Add optional parameters as a JSON object to this command
|
||||
I("startStopBtn").className="running";
|
||||
w.onmessage=function(e){
|
||||
var data=e.data.split(';');
|
||||
var status=Number(data[0]);
|
||||
if(status>=4){
|
||||
//test completed
|
||||
I("startStopBtn").className="";
|
||||
w=null;
|
||||
}
|
||||
I("ip").textContent=data[4];
|
||||
I("dlText").textContent=(status==1&&data[1]==0)?"...":data[1];
|
||||
I("ulText").textContent=(status==3&&data[2]==0)?"...":data[2];
|
||||
I("pingText").textContent=data[3];
|
||||
I("jitText").textContent=data[5];
|
||||
};
|
||||
}
|
||||
}
|
||||
//poll the status from the worker every 200ms (this will also update the UI)
|
||||
setInterval(function(){
|
||||
if(w) w.postMessage('status');
|
||||
},200);
|
||||
//function to (re)initialize UI
|
||||
function initUI(){
|
||||
I("dlText").textContent="";
|
||||
I("ulText").textContent="";
|
||||
I("pingText").textContent="";
|
||||
I("jitText").textContent="";
|
||||
I("ip").textContent="";
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="my-4">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 mb-3">
|
||||
<p class="h1">
|
||||
Speedtest
|
||||
<button id="st-start" class="btn btn-outline-primary st-btn" onclick="startTest()">Start</button>
|
||||
<button id="st-stop" class="btn btn-danger st-btn" onclick="stopTest()" hidden="true">Stop</button>
|
||||
</p>
|
||||
<p class="lead">
|
||||
Your IP: <span id="st-ip"></span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-3 st-block">
|
||||
<h3>Download</h3>
|
||||
<p class="display-4 st-value"><span id="st-download"></span></p>
|
||||
<p class="lead">Mbit/s</p>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-3 st-block">
|
||||
<h3>Upload</h3>
|
||||
<p class="display-4 st-value"><span id="st-upload"></span></p>
|
||||
<p class="lead">Mbit/s</p>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-3 st-block">
|
||||
<h3>Ping</h3>
|
||||
<p class="display-4 st-value"><span id="st-ping"></span></p>
|
||||
<p class="lead">ms</p>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-3 st-block">
|
||||
<h3>Jitter</h3>
|
||||
<p class="display-4 st-value"><span id="st-jitter"></span></p>
|
||||
<p class="lead">ms</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div>
|
||||
<p>
|
||||
Created by <a href="https://github.com/adolfintel/speedtest/"><img src="github.png" height=20 width=20> adolfintel</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var worker = null
|
||||
function startTest() {
|
||||
document.getElementById('st-start').hidden = true
|
||||
document.getElementById('st-stop').hidden = false
|
||||
worker = new Worker('speedtest_worker.min.js')
|
||||
var interval = setInterval(function () { worker.postMessage('status') }, 100)
|
||||
worker.onmessage = function (event) {
|
||||
var download = document.getElementById('st-download')
|
||||
var upload = document.getElementById('st-upload')
|
||||
var ping = document.getElementById('st-ping')
|
||||
var jitter = document.getElementById('st-jitter')
|
||||
var ip = document.getElementById('st-ip')
|
||||
|
||||
var data = event.data.split(';')
|
||||
var status = Number(data[0])
|
||||
if (status >= 4) {
|
||||
clearInterval(interval)
|
||||
document.getElementById('st-start').hidden = false
|
||||
document.getElementById('st-stop').hidden = true
|
||||
w = null
|
||||
}
|
||||
if (status === 5) {
|
||||
// speedtest cancelled, clear output data
|
||||
data = []
|
||||
}
|
||||
download.textContent = (status==1&&data[1]==0)?"Starting":data[1]
|
||||
upload.textContent = (status==3&&data[2]==0)?"Starting":data[2]
|
||||
ping.textContent = data[3]
|
||||
ip.textContent = data[4]
|
||||
jitter.textContent = data[5]
|
||||
}
|
||||
worker.postMessage('start')
|
||||
}
|
||||
function stopTest() {
|
||||
if (worker) worker.postMessage('abort')
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
<h1>HTML5 Speedtest</h1>
|
||||
<div id="startStopBtn" onclick="startStop()"></div>
|
||||
<div id="test">
|
||||
<div class="testGroup">
|
||||
<div class="testArea">
|
||||
<div class="testName">Download</div>
|
||||
<div id="dlText" class="meterText"></div>
|
||||
<div class="unit">Mbps</div>
|
||||
</div>
|
||||
<div class="testArea">
|
||||
<div class="testName">Upload</div>
|
||||
<div id="ulText" class="meterText"></div>
|
||||
<div class="unit">Mbps</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="testGroup">
|
||||
<div class="testArea">
|
||||
<div class="testName">Ping</div>
|
||||
<div id="pingText" class="meterText"></div>
|
||||
<div class="unit">ms</div>
|
||||
</div>
|
||||
<div class="testArea">
|
||||
<div class="testName">Jitter</div>
|
||||
<div id="jitText" class="meterText"></div>
|
||||
<div class="unit">ms</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="ipArea">
|
||||
IP Address: <span id="ip"></span>
|
||||
</div>
|
||||
</div>
|
||||
<a href="https://github.com/adolfintel/speedtest">Source code</a>
|
||||
<script type="text/javascript">initUI();</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
Loading…
Reference in a new issue