43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
var s=new Speedtest(); //create speedtest object
|
|
|
|
s.setParameter("test_order","IP_D"); //we only want download test
|
|
s.setParameter("time_auto",true); //fixed duration for tests
|
|
s.setParameter("time_dl_max",10); //10 seconds for the download test
|
|
|
|
s.onupdate=function(data){
|
|
I("ip").textContent=data.clientIp;
|
|
I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
|
|
I("pingText").textContent=data.pingStatus;
|
|
I("jitText").textContent=data.jitterStatus;
|
|
var prog=(Number(data.dlProgress)*2+Number(data.pingProgress))/3;
|
|
I("progress").style.width=(100*prog)+"%";
|
|
}
|
|
|
|
s.onend=function(aborted){
|
|
I("startStopBtn").className=""; //show start button again
|
|
if(aborted){
|
|
initUI();
|
|
}
|
|
}
|
|
|
|
function startStop(){
|
|
if(s.getState()==3){
|
|
//speedtest is running, abort
|
|
s.abort();
|
|
}else{
|
|
//test is not running, begin
|
|
s.start();
|
|
I("startStopBtn").className="running";
|
|
}
|
|
}
|
|
|
|
function initUI(){
|
|
I("dlText").textContent="";
|
|
I("pingText").textContent="";
|
|
I("jitText").textContent="";
|
|
I("ip").textContent="";
|
|
}
|
|
|
|
function I(id){
|
|
return document.getElementById(id);
|
|
}
|