1 Star 6 Fork 0

ju-do-it/NetworkSpeedTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index_443.html 18.72 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="favicon.png">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
<!--<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">-->
<meta charset="UTF-8" />
<script type="text/javascript" src="speedtest.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function I(i){return document.getElementById(i);}
//LIST OF TEST SERVERS. See documentation for details if needed
var SPEEDTEST_SERVERS=[
{ //this is my demo server, remove it
name:"VPN",
server:"//nettest.vipkid.com.cn/",
// server:"http://172.20.251.18:88/",
// server:"http://114.113.81.13/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
},
// { //this is my demo server, remove it
// name:"邮箱", //user friendly name for the server
// server:"//nettest.vipkid.com.cn/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically
// dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
// ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
// pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
// getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
// },
//add other servers here, comma separated
];
//INITIALIZE SPEEDTEST
var s=new Speedtest(); //create speedtest object
s.setParameter("telemetry_level","basic"); //enable telemetry
s.addTestPoints(SPEEDTEST_SERVERS); //add list of servers
//SERVER AUTO SELECTION
function initServers(){
s.selectServer(function(server){
if(server!=null){ //at least 1 server is available
I("loading").className="hidden"; //hide loading message
//populate server list for manual selection
for(var i=0;i<SPEEDTEST_SERVERS.length;i++){
if(SPEEDTEST_SERVERS[i].pingT==-1) continue;
var option=document.createElement("option");
option.value=i;
option.textContent=SPEEDTEST_SERVERS[i].name;
if(SPEEDTEST_SERVERS[i]===server) option.selected=true;
I("server").appendChild(option);
}
//show test UI
I("testWrapper").className="visible";
initUI();
}else{ //no servers are available, the test cannot proceed
I("message").innerHTML="服务器节点不可达,建议重新登录VPN或咨询IT支持!";
}
});
}
var meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#80808040";
var dlColor="#f85415",
ulColor="#f85415";
pingColor="#f85415",
jitColor="#f85415";
var progColor=meterBk;
//CODE FOR GAUGES
function drawMeter(c,amount,bk,fg,progress,prog){
var ctx=c.getContext("2d");
var dp=window.devicePixelRatio||1;
var cw=c.clientWidth*dp, ch=c.clientHeight*dp;
var sizScale=ch*0.0055;
if(c.width==cw&&c.height==ch){
ctx.clearRect(0,0,cw,ch);
}else{
c.width=cw;
c.height=ch;
}
ctx.beginPath();
ctx.strokeStyle=bk;
ctx.lineWidth=12*sizScale;
ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,Math.PI*0.1);
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle=fg;
ctx.lineWidth=12*sizScale;
ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,amount*Math.PI*1.2-Math.PI*1.1);
ctx.stroke();
if(typeof progress !== "undefined"){
ctx.fillStyle=prog;
ctx.fillRect(c.width*0.3,c.height-16*sizScale,c.width*0.4*progress,4*sizScale);
}
}
function mbpsToAmount(s){
return 1-(1/(Math.pow(1.3,Math.sqrt(s))));
}
var w=null; //speedtest worker
var data=null; //data from worker
function msToAmount(s){
return 1-(1/(Math.pow(1.08,Math.sqrt(s))));
}
function format(d){
d=Number(d);
if(d<10) return d.toFixed(2);
if(d<100) return d.toFixed(1);
return d.toFixed(0);
}
//UI CODE
var uiData=null;
var stop_flag = "";
function startStop(){
if(s.getState()==3){
//speedtest is running, abort
s.abort();
data=null;
I("startStopBtn").className="";
I("server").disabled=false;
initUI();
stop_flag = "yes"
uiData = "";
}else{
//test is not running, begin
I("startStopBtn").className="running";
I("shareArea").style.display="none";
I("server").disabled=true;
s.onupdate=function(data){
uiData=data;
};
s.onend=function(aborted){
I("startStopBtn").className="";
I("server").disabled=false;
updateUI(true);
console.log("返回结果 --->", JSON.stringify(uiData));
// I("resultsURL").value=JSON.stringify(uiData);
// "pingStatus":"21.55" , "dlStatus":"7.75",
// str_uiData = JSON.stringify(uiData)
pingStatus = uiData.pingStatus;
dlStatus = uiData.dlStatus;
var result_1_1 = ""
var result_1_2 = ""
var result_2_1 = ""
var result_2_2 = ""
if( !aborted && uiData ) {
I("shareArea").style.display="";
if (pingStatus > 0 && pingStatus <= 150) {
result_1_1 = "网络连通性:";
result_1_2 = "优良<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#4FAC5B";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#4FAC5B",
jitColor = "#4FAC5B";
} else if (pingStatus > 150 && pingStatus <= 350) {
result_1_1 = "网络连通性:";
result_1_2 = "正常<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#2971BB";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#2971BB";
jitColor = "#2971BB";
} else if (pingStatus > 350 && pingStatus <= 500) {
result_1_1 = "网络连通性:";
result_1_2 = "一般<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#E08043";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#E08043";
jitColor = "#E08043";
} else if (pingStatus > 500 && pingStatus <= 1000) {
result_1_1 = "网络连通性:";
result_1_2 = "很差,建议检查本地网络环境!<br>";
result_2_1 = "端口检测:";
result_2_2 = "正常<br>";
I("testId_1.2").style.color = "#B22218";
I("testId_2.2").style.color = "#4FAC5B";
pingColor = "#B22218";
jitColor = "#B22218";
} else {
result_1_1 = "网络连通性:";
result_1_2 = "检测失败,建议重启VPN或咨询IT支持!<br>";
result_2_1 = "端口检测:";
result_2_2 = "失败<br>";
I("testId_1.2").style.color = "red";
I("testId_2.2").style.color = "red";
pingColor = "red";
jitColor = "red";
}
// 当前网速相当于20M~50M宽带,已超越全国52%的网络用户
if (dlStatus > 0 && dlStatus < 5) {
result_3_1 = "网络速度:";
result_3_2 = "很差<br>";
I("testId_3.2").style.color = "#B22218";
dlColor = "#B22218"
ulColor = "#B22218";
} else if (dlStatus >= 5 && dlStatus < 10) {
result_3_1 = "网络速度:";
result_3_2 = "一般 <br>";
I("testId_3.2").style.color = "#E08043";
dlColor = "#E08043"
ulColor = "#E08043";
} else if (dlStatus > 10 && dlStatus < 20) {
result_3_1 = "网络速度:";
result_3_2 = "正常 <br>";
I("testId_3.2").style.color = "#2971BB";
dlColor = "#2971BB"
ulColor = "#2971BB";
} else if (dlStatus >= 20 && dlStatus < 30) {
result_3_1 = "网络速度:";
result_3_2 = "优良 <br>";
I("testId_3.2").style.color = "#4FAC5B";
dlColor = "#4FAC5B"
ulColor = "#4FAC5B";
// result2 = "网络速度:相当于80 ~ 100M宽带,已超越全国83%的网络用户"
} else if (dlStatus >= 30 && dlStatus < 1000) {
result_3_1 = "网络速度:";
result_3_2 = "优良 <br>";
I("testId_3.2").style.color = "#4FAC5B";
dlColor = "#4FAC5B"
ulColor = "#4FAC5B";
// result2 = "网络速度:相当于80 ~ 100M宽带,已超越全国83%的网络用户"
}
I("testId_0").innerHTML = "测试结果:";
I("testId_1.1").innerHTML = result_1_1;
I("testId_1.2").innerHTML = result_1_2;
I("testId_2.1").innerHTML = result_2_1;
I("testId_2.2").innerHTML = result_2_2;
I("testId_3.1").innerHTML = result_3_1;
I("testId_3.2").innerHTML = result_3_2;
frame();
stop_flag = ""
}
if(!aborted){
//if testId is present, show sharing panel, otherwise do nothing
try{
var testId=uiData.testId;
if(testId!=null){
// var shareURL=window.location.href.substring(0,window.location.href.lastIndexOf("/"))+"/results/?id="+testId;
// I("resultsImg").src=shareURL;
// I("resultsURL").value=shareURL;
// I("testId").innerHTML=testId;
// I("shareArea").style.display="";
}
}catch(e){}
}
};
s.start();
}
}
//this function reads the data sent back by the test and updates the UI
function updateUI(forced){
if(!forced&&s.getState()!=3) return;
if(uiData==null) return;
var status=uiData.testState;
// I("ip").textContent=uiData.clientIp;
I("dlText").textContent=(status==1&&uiData.dlStatus==0)?"...":format(uiData.dlStatus);
drawMeter(I("dlMeter"),mbpsToAmount(Number(uiData.dlStatus*(status==1?oscillate():1))),meterBk,dlColor,Number(uiData.dlProgress),progColor);
I("ulText").textContent=(status==3&&uiData.ulStatus==0)?"...":format(uiData.ulStatus);
drawMeter(I("ulMeter"),mbpsToAmount(Number(uiData.ulStatus*(status==3?oscillate():1))),meterBk,ulColor,Number(uiData.ulProgress),progColor);
I("pingText").textContent=format(uiData.pingStatus);
I("jitText").textContent=format(uiData.jitterStatus);
// 新增
drawMeter(I("pingMeter"),msToAmount(Number(uiData.pingStatus*(status==2?oscillate():1))),meterBk,pingColor,Number(uiData.pingProgress),progColor);
I("jitText").textContent=uiData.jitterStatus;
drawMeter(I("jitMeter"),msToAmount(Number(uiData.jitterStatus*(status==2?oscillate():1))),meterBk,jitColor,Number(uiData.pingProgress),progColor);
}
function oscillate(){
return 1+0.02*Math.sin(Date.now()/100);
}
//update the UI every frame
window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||(function(callback,element){setTimeout(callback,1000/60);});
function frame(){
requestAnimationFrame(frame);
updateUI();
}
frame(); //start frame loop
//function to (re)initialize UI
const ip = ""
function initUI(){
drawMeter(I("dlMeter"),0,meterBk,dlColor,0);
drawMeter(I("ulMeter"),0,meterBk,ulColor,0);
drawMeter(I("pingMeter"),0,meterBk,pingColor,0);
drawMeter(I("jitMeter"),0,meterBk,jitColor,0);
I("dlText").textContent="";
I("ulText").textContent="";
I("pingText").textContent="";
I("jitText").textContent="";
I("ip").textContent="";
$.ajax({
async: true,
cache: false,
// url: "http://www.cip.cc/",
// url: "http://api.online-service.vip/ip/me",
// url: "https://nettest.vipkid.com.cn/ip_me",
url: "https://apis.map.qq.com/ws/location/v1/ip",
type: "GET",
// dataType : "text",//指定返回的数据格式
dataType: 'jsonp',
data: {
key: "4JRBZ-2CXE6-NVRSK-ELA57-LA4JH-YGB5Y",
output : "jsonp"
},
success: function(data) {//客户端jquery预先定义好的callback函数,成功获取跨域服务器上的json数据后,会动态执行这个callback函数
console.log("公网出口IP 结果 --->>", data);
ip_me = data.result.ip;
if (ip_me) {
I("ip").textContent="您的IP是: " + ip_me;
I("me_ip").src="https://nettest.vipkid.com.cn/cc/" + ip_me
}
},
error: function(data) {
//jsonp 方式此方法不被触发.原因可能是dataType如果指定为jsonp的话,就已经不是ajax事件了
//请求出错处理
// alert("请求出错(请检查相关度网络状况.)");
console.log("公网出口IP ---->> 请求出错");
}
});
}
</script>
<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;*/
font-family: microsoft yahei
}
h1{
color:#404040;
}
#loading{
background-color:#FFFFFF;
color:#404040;
text-align:center;
}
span.loadCircle{
display:inline-block;
width:2em;
height:2em;
vertical-align:middle;
background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAP1BMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZyFzwnAAAAFHRSTlMAEvRFvX406baecwbf0casimhSHyiwmqgAAADpSURBVHja7dbJbQMxAENRahnN5lkc//5rDRAkDeRgHszXgACJoKiIiIiIiIiIiIiIiIiIiIj4HHspsrpAVhdVVguzrA4OWc10WcEqpwKbnBo0OU1Q5NSpsoJFTgOecrrdEag85DRgktNqfoEdTjnd7hrEHMEJvmRUYJbTYk5Agy6nau6Abp5Cm7mDBtRdPi9gyKdU7w4p1fsLvyqs8hl4z9/w3n/Hmr9WoQ65lAU4d7lMYOz//QboRR5jBZibLMZdAR6O/Vfa1PlxNr3XdS3HzK/HVPRu/KnLs8iAOh993VpRRERERMT/fAN60wwWaVyWwAAAAABJRU5ErkJggg==');
background-size:2em 2em;
margin-right:0.5em;
animation: spin 0.6s linear infinite;
}
@keyframes spin{
0%{transform:rotate(0deg);}
100%{transform:rotate(359deg);}
}
#startStopBtn{
display:inline-block;
margin:30px;
color: #FFFFFF;
/*background-color: rgba(0,0,0,0);*/
background-color: #f85415;
border:0.15em solid #f85415;
/*color:#6060AA;*/
/*background-color:rgba(0,0,0,0);*/
/*border:0.15em solid #6060FF;*/
border-radius:50em;
transition:all 0.3s;
box-sizing:border-box;
/*width:7em; */
/*height:3em;*/
/*line-height:2.7em;*/
width: 7em;
height: 2.4em;
line-height: 2em;
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:"开始测速";
}
#startStopBtn.running:before{
content:"强制终止";
}
#serverArea{
margin-top:0em;
}
#server{
font-size:14px;
padding:0.2em;
}
#test{
margin-top:2em;
margin-bottom:12em;
}
div.testArea{
display:inline-block;
width:16em;
height:12.5em;
position:relative;
box-sizing:border-box;
}
div.testArea2{
display:inline-block;
width:14em;
height:7em;
position:relative;
box-sizing:border-box;
text-align:center;
}
div.testArea div.testName{
position:absolute;
top:0.1em; left:0;
width:100%;
font-size:17px;
z-index:9;
}
div.testArea2 div.testName{
display:block;
text-align:center;
font-size:17px;
}
div.testArea div.meterText{
position:absolute;
bottom:1.55em; left:0;
width:100%;
font-size:2.0em;
z-index:9;
}
div.testArea2 div.meterText{
display:inline-block;
font-size:2.0em;
}
div.meterText:empty:before{
content:"0.00";
}
div.testArea div.unit{
position:absolute;
bottom:2em; left:0;
width:100%;
z-index:9;
}
div.testArea2 div.unit{
display:inline-block;
}
div.testArea canvas{
position:absolute;
top:0; left:0; width:100%; height:100%;
z-index:1;
}
div.testGroup{
display:inline-block;
margin: 0 auto;
}
#shareArea{
width:95%;
max-width:40em;
margin:0 auto;
margin-top:2em;
}
#shareArea > *{
display:block;
width:100%;
height:auto;
margin: 0.25em 0;
}
#privacyPolicy{
position:fixed;
top:2em;
bottom:2em;
left:2em;
right:2em;
overflow-y:auto;
width:auto;
height:520px;
box-shadow:0 0 3em 1em #000000;
z-index:999999;
text-align:left;
background-color:#FFFFFF;
padding:1em;
}
a.privacy{
text-align:center;
font-size:0.8em;
color:#808080;
display:block;
}
@media all and (max-width:40em){
body{
font-size:0.8em;
}
}
div.visible{
animation: fadeIn 0.4s;
display:block;
}
div.hidden{
animation: fadeOut 0.4s;
display:none;
}
@keyframes fadeIn{
0%{
opacity:0;
}
100%{
opacity:1;
}
}
@keyframes fadeOut{
0%{
display:block;
opacity:1;
}
100%{
display:block;
opacity:0;
}
}
</style>
<title>IT-网络测速</title>
</head>
<body onload="initServers()">
<!--<h1>IT - 网络测速</h1>-->
<div id="loading" class="visible">
<p id="message"><span class="loadCircle"></span>Selecting a server...</p>
</div>
<div id="testWrapper" class="hidden">
<div id="startStopBtn" onclick="startStop()"></div>
<!-- <a class="privacy" href="#" onclick="I('privacyPolicy').style.display=''">Privacy</a>-->
<div id="serverArea">
<span style="font-size: 15px">
检测项目:
</span> <select id="server" onchange="s.setSelectedServer(SPEEDTEST_SERVERS[this.value])"></select>
</div>
<div id="test">
<div class="testGroup">
<div class="testArea">
<div class="testName">网络延迟</div>
<canvas id="pingMeter" class="meter" ></canvas>
<div id="pingText" class="meterText" ></div>
<div class="unit">ms</div>
</div>
<div class="testArea">
<div class="testName">网络抖动</div>
<canvas id="jitMeter" class="meter"></canvas>
<div id="jitText" class="meterText" ></div>
<div class="unit">ms</div>
</div>
</div>
<div class="testGroup">
<div class="testArea">
<div class="testName">下载</div>
<canvas id="dlMeter" class="meter"></canvas>
<div id="dlText" class="meterText"></div>
<div class="unit">Mbps</div>
</div>
<div class="testArea">
<div class="testName">上传</div>
<canvas id="ulMeter" class="meter"></canvas>
<div id="ulText" class="meterText"></div>
<div class="unit">Mbps</div>
</div>
</div>
<div id="ipArea" style="margin-top: 30px">
<span id="ip"></span>
<a style="font-size: 15px;color: #f85415" class="privacy" href="#" onclick="I('privacyPolicy').style.display=''">查询IP运营商归属</a>
</div>
<div id="shareArea" style="display: none" >
<h3 id="testId_0"></h3>
<p><span id="testId_1.1"></span><span id="testId_1.2"></span>
<span id="testId_2.1"></span><span id="testId_2.2"></span>
<span id="testId_3.1"></span><span id="testId_3.2"></span>
</p>
<!-- <input style="width:400px ;height:128px" type="text" value="" id="resultsURL" readonly="readonly" />-->
</div>
<div style="margin-top: 160px">
<span style="text-align:center;font-size: 8px" href="javascript:;">©2020 VIPKID 网络测速工具V1.0 by IT技术部</span>
</div>
</div>
</div>
<div id="privacyPolicy" style="display:none">
<h4>查询IP运营商信息</h4>
<!-- https://nettest.vipkid.com.cn/cc-->
<div style="margin-top: -350px;">
<iframe id="me_ip" style="width:100%;height:540px;padding-bottom: 40px" scrolling="no" frameborder="0" src="https://nettest.vipkid.com.cn/cc" ></iframe>
<a style="font-size: 14px;color: red;margin-top: 200px" class="privacy" href="#" onclick="I('privacyPolicy').style.display='none'">关闭</a><br/>
</div>
</div>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ju-do-it/NetworkSpeedTest.git
git@gitee.com:ju-do-it/NetworkSpeedTest.git
ju-do-it
NetworkSpeedTest
NetworkSpeedTest
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385