速度测试代码

ExpandedBlockStart.gif 代码
< html >
< head >
 
< meta content = " text/html "  http - equiv = Content - Type >
< META HTTP - EQUIV = " Pragma "  CONTENT = " no-cache " >  
< META HTTP - EQUIV = " Cache-Control "  CONTENT = " no-cache " >  
< META HTTP - EQUIV = " Expires "  CONTENT = " 0 " >
< meta http - equiv = " Content-Type "  content = " text/html; charset=gb2312 "   />
< style type = " text/css " >  
<!--
body {overflow:auto;}
body,td,th,tr {font:normal 12px Verdana;color: #
000 ;margin: 0 ;padding: 0 ;}
.speed {width:460px;margin:20px;padding:
0 ;list - style:none;height:300px ! important;height:auto}
.speed li {
float :left;border - bottom:1px solid #f2f2f2;margin - top:6px}
.speed .li_left {width:120px;height:24px;text
- align:left;}
.speed .li_right {width:310px
! important;width:335px;height:24px;padding - left:12px;}
.normal {font
- weight:normal;color:# 868686 ;}
.btn {width:60px;font
- size:12px;height:22px;line - height: 0 ! important;line - height:18px;line - height: /**/ 18px;padding: 0  9px 2px 9px ! important;padding: 0 ;padding: /**/ 0 ;margin:5px 4px  0   0 }
-->
</ style >
< title > 测速并更换服务器 </ title >
</ head >
< script >  
var gbIsNoCheck 
=   true ;
</ script >
< script language = " javascript "  src = " http://rescdn.qqmail.com/zh_CN/htmledition20091230/js/all.js " ></ script >
< script >  
var stdspeed 
=   0 ;
var protocol 
=   " http:// " ;
// var Path = "/zh_CN/images/help012_clip_image003.gif";
var Path  =   " /zh_CN/images/jh_mail_3.gif "
var Dom 
=   new  Array( 4 );
var userpos 
=   0 ;
var resuserpos 
=   0 ;
var resame 
=   0 ;
var timer 
=   0 ;
var idc_p 
=   " 0 " ;
Dom[
1 =   1 ;
Dom[
2 =   1 ;
Dom[
3 =   1 ;
var HostList;
// var ResList;
var sHost  =   0 ;
function testspeed()
{
    var obj
= this ;
    var n 
=  obj.id;
    var timer
= new  Date().getTime();
    var img
= new  Image();
    img.src
= protocol + obj.url + Path + " ? " + Math.random();
    img.onload
= function()
    {
        obj.size
= 22009 ;
        obj.time
= new  Date().getTime() - timer;
        obj.speed
= Math.round(obj.size * 1.02 * 10 / obj.time) / 10 ;
    }
    img.onerror
= function()
    {
        var idx 
=   " show "   +  n;
        var showx 
=  document.getElementById(idx);
        showx.innerHTML
= ( " <div style=margin-top:2px;color:red>连接超时</div> " );
    }    
}
function Host(id,url,size,time,speed)
{
    
this .id  =  id;
    
this .url  =  url;
    
this .size  =  size;
    
this .time  =  time;
    
this .speed  =  speed;
    
this .testspeed  =  testspeed;
}
function CreateHostList(count)
{
    HostList 
=   new  Array(count + 1 );
}
function PushToTestArray(id,url,size,time,speed)
{
    var eHost 
=   new  Host(id,url,size,time,speed);
    HostList[id] 
=  eHost;
}
 
function checkclick(submitype)
{
/*
    if ( document.getElementById('infobtn').disabled == true )
    {
        return false;
    }
    
*/
    var act 
=  document.getElementById( " actions " );
    var tform 
=  document.getElementById( " testform " );
    var logtype 
=  document.getElementById( " logtype " );
    act.value 
=   " save " ;
    GetSpeedLog();
    delete HostList;
    
if  ( submitype  ==   " close "   ||  submitype  ==   " save "   ||  submitype  ==   " login "  )
    {
        
if ( idc_p == " 0 "  ) 
        {
            var expdate 
=   new  Date();
            expdate.setTime(
- 1 );
            document.cookie 
=   " section "   +   " = "   +  escape( "" +   " ; expires= "   +  expdate.toGMTString()  +   " ; path=/; domain=mail.qq.com " ;
        }
        
else
        {    
            savebox 
=  document.getElementById( " saveset " );
            
if  (savebox. checked == true ) {SetCookie_edition( 0 );}
            
else  {SetCookie_edition( 1 );}
        }
    }
    
if (submitype == " close "
    {
        tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;    
        logtype.value 
=   " 3 " ;
    }
    
else   if (submitype == " save " )
    {
        
if (confirm( " 保存成功。点“确定”立即退出并登录新选择的服务器, " + " \n\n " + " 点“取消”则下次登录时生效。 " ))
        {
            
if  (window.opener.getTop())
            {
                logtype.value 
=   " 1 " ;
                tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
                window.opener.getTop().location.href 
=   " /cgi-bin/logout?sid=fUOOkPl424-PWVEa&from=stat " ;
            }
        }
        
else
        {    
            logtype.value 
=   " 2 " ;
            tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
        }
    }
    
else   if  ( submitype == " cancel "  )
    {
        logtype.value 
=   " 6 " ;
        tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
    }
    
else   if (submitype == " login " )
    {
        
try  
        {
            
if  ( window.opener.getTop() ) {
                logtype.value 
=   " 5 " ;
                window.opener.getTop().location.href 
=   " http://mail.qq.com " ;
                tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
            }
            
else  {
                
throw  {};
            }
        }
        
catch ( e ) 
        {
            location.href 
=   " http://mail.qq.com " ;
        }
    }
    
else   if  ( submitype  ==   " basic " )
    {
        
if  (window.opener.getTop())
        {
            logtype.value 
=   " 4 " ;
            tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
            window.opener.getTop().location.href 
=   " /cgi-bin/loginswitch?f=html&nf=xhtml&sid=fUOOkPl424-PWVEa&url=%2Fcgi-bin%2Ftoday " ;
        }
    }
    
else   if  ( submitype  ==   " unload "  )
    {
        logtype.value 
=   " 11 " ;
        tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
    }
    
else   if  ( submitype  ==   " auto "  )
    {
        logtype.value 
=   " 10 " ;
        tform.action
= " http://m56.mail.qq.com/cgi-bin/speedstat " ;
    }
    act.value 
=   " log " ;
    tform.submit();
    
if  ( submitype  !=   " unload "   &&  submitype  !=   " auto "  )
    {
        setTimeout( function(){
            window.close();
        }, 
100  );
    }
    
return   true ;
}
function setCookie(sName, sValue,type)
{
    var expdate 
=   new  Date();
    
if (type == 1 ){ expdate.setTime(expdate.getTime()  +  (  24   *   3600   *   1000  ));}
    
else  {expdate.setTime(expdate.getTime()  +  (  30   *   24   *   3600   *   1000  ));}
    document.cookie 
=  sName  +   " = "   +  escape(sValue)  +   " ; expires= "   +  expdate.toGMTString()  +   " ; path=/; domain=mail.qq.com " ;
}
 
function SetCookie_edition(type)
{
    setCookie(
" section " ,idc_p,type);
}
 
function DisplayResult(flag)
{
    var maxspeed 
=  document.getElementById( " maxspeed " );
    var maxpos 
=  document.getElementById( " maxpos " ).value;
    
try {
    
for  (loop = 1 ; loop < HostList.length; loop ++ )
    {
        
if  (HostList[loop].speed > maxspeed.value) 
        {
            maxspeed.value 
=  HostList[loop].speed;
            maxpos 
=  document.getElementById( " idc " + loop).value;
        }
    }
    
for  (loop = 1 ; loop < HostList.length; loop ++ )
    {
        var idx 
=   " show " + loop;
        var showx 
=  document.getElementById(idx);
        
if  (HostList[loop].speed  !=   0 )
        {    
            showx.innerHTML
= ( " <div style=margin-top:4px><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width=' " + Math.ceil(HostList[loop].speed / maxspeed.value * 80 ) + " %' style='background:url(http://rescdn.qqmail.com/zh_CN/htmledition20091230/images/pic_ft_process.gif) repeat-x;height:10px;font-size:1px;border:1px solid #85bc00'>&nbsp;</td><td style='height:10px;font-size:1px;'>&nbsp;</td></tr></table></div> " );
        }
    }
    document.getElementById(
" maxpos " ).value = maxpos;
    }
catch (e){}
}
function DisplayClose()
{
    var maxspeed 
=  document.getElementById( " maxspeed " );
    var maxpos 
=  document.getElementById( " maxpos " ).value;
    
try {
    
for  (loop = 1 ; loop < HostList.length; loop ++ )
    {
        
if  (HostList[loop].speed > maxspeed.value) 
        {
            maxspeed.value 
=  HostList[loop].speed;
            maxpos 
=  document.getElementById( " idc " + loop).value;
        }
        var idx 
=   " show " + loop;
        var showx 
=  document.getElementById(idx);
        
if  (HostList[loop].speed  !=   0 )
        {
            showx.innerHTML
= ( " <div style=margin-top:4px><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width=' " + Math.ceil(HostList[loop].speed / maxspeed.value * 80 ) + " %' style='background:url(http://rescdn.qqmail.com/zh_CN/htmledition20091230/images/pic_ft_process.gif) repeat-x;height:10px;font-size:1px;border:1px solid #85bc00'>&nbsp;</td><td style='height:10px;font-size:1px;'>&nbsp;</td></tr></table></div> " );
        }
        
else  showx.innerHTML = " <div style=margin-top:2px;color:red>连接超时</div> " ;
    }
    }
catch (e){}
    document.getElementById(
" maxpos " ).value = "" + maxpos;
    document.getElementById(
" infodiv " ).style.display = "" ;
    document.getElementById(
" infoloading " ).style.display = " none " ;
    document.getElementById(
" infobtn " ).disabled  =   false ;
    document.getElementById(
" finish " ).value  =   " 1 " ;
            checkclick(
" auto " );
    }
function tryarray()
{
    timer
++ ;
    
try
    {
        
if  (timer >= HostList.length)  return   0 ;
        
else
        {
            HostList[timer].testspeed();
            setTimeout(tryarray,
900 );
        }
    }
    
catch (e){}
}
function ChangeIdc(radio_idc)
{
    idc_p 
=  radio_idc.value;
}
 
function GetSpeedLog()
{
    log 
=  document.getElementById( " speedlist " );
    log.value 
=    "" +  HostList[ 1 ].time;
    
for  (loop  =   2 ; loop  <  HostList.length; loop ++  )
    {
        log.value 
+=   " ; " + HostList[loop].time;
    }
}
 
function OnUnLoad()
{
    var _slogtype 
=  document.getElementById( " logtype " );
    var _sFinish 
=  document.getElementById( " finish " );
    
if  ( _slogtype  ==   null   ||  _slogtype.value  ==   " 0 "  )
    {
        checkclick(
" unload " );
        
if  ( _sFinish  &&  _sFinish  ==   " 1 "  )
        {
            
return   " 您还没有保存结果,确定要离开吗? "
        }
        
else
        {
            
return   " 测速还没有完成,确定要离开吗? "
        }
    }
    
}
</ script >
< body  class = " bd_upload "  onbeforeunload = " return OnUnLoad(); "   >
< div style = " background:#eaf3ff;height:50px;line-height:50px;text-align:center;margin:2px 2px 0 2px; "  id = " infoloading " >
    
< div style = " margin:8px 4px 0 0 " >< img src = " http://rescdn.qqmail.com/zh_CN/htmledition20091230/images/ico_loading2.gif "  align = " absmiddle "   style = " margin:0 8px 0 0 " />   正在测速中,整个过程可能会花几十秒时间,请耐心等待 … </ div >
</ div >
< form id = ' testform '  name = " testform "  action = " /cgi-bin/logout?sid=0,2,zh_CN "  method = " POST "  target = " actionFrame " >
< input id = " actions "  name = " actions "  TYPE = " hidden "   />
< input id = ' upos '  name = " upos "  TYPE = " hidden "  value = " 1 "   />
< input type = ' hidden '  id = ' maxspeed '  value = ' 0 '  syncBehavior = " true "   />
< input type = ' hidden '  id = ' maxpos '  name = " maxpos "  value = " 0 " />
< input type = ' hidden '  id = ' speedlist '  name = " speedlist "  TYPE = " hidden " >
< input type = ' hidden '  id = ' logtype '  name = " logtype "  TYPE = " hidden "  value = " 0 " >
< input type = ' hidden '  id = ' sid '  name = " sid "  value = " fUOOkPl424-PWVEa "   />
< input type = ' hidden '  id = ' finish '  name = ' finish '  value = " 0 "   />
< script > CreateHostList( 7 ) </ script >
< div id = " infodiv "  name = " infodiv "  style = " display:none;background:#eaf3ff;margin:2px 2px 0 2px; " >
    
< div style = " padding:15px 2px 0 10px " >< img src = " http://rescdn.qqmail.com/zh_CN/htmledition20091230/images/ico_ft_upload_success.gif "  align = " absmiddle "   />   < b > 速度测试完成。 </ b ></ div >
 
    
< div style = " padding:8px 0 15px 12px; " > 绿色进度条表示服务器速度,绿色条越长速度越快。请在下面选择最快的服务器: </ div >
</ div >
< div  class = " speed "   >
            
< table width = " 100% "  style = " border-bottom:1px solid #f2f2f2; " >< td width = 1 %  nowrap >< input type = " radio "   name = " idc "  id = ' idc0 '  value = " 0 "    checked  onClick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " 0 " > 自动选择服务器 </ label >& nbsp; </ td ></ tr ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc1 '  value = " 1 "   checked  onClick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc1 " > 电信1 < span  class = ' normal ' >  (当前位置) </ span > </ label ></ td >< td id = ' show1 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 1 , " m1.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc6 '  value = " 6 "   onclick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc6 " > 电信2: </ label ></ td >< td id = ' show6 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 6 , " m34.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc2 '  value = " 2 "   onclick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc2 " > 网通1: </ label ></ td >< td id = ' show2 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 2 , " m50.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc4 '  value = " 4 "   onclick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc4 " > 网通2: </ label ></ td >< td id = ' show4 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 4 , " m168.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc3 '  value = " 3 "   onclick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc3 " > 教育1: </ label ></ td >< td id = ' show3 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 3 , " m201.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc7 '  value = " 7 "   onclick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc7 " > 教育2: </ label ></ td >< td id = ' show7 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 7 , " m77.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
                
< table style = " border-bottom:1px solid #f2f2f2; " >< td >< input type = " radio "   name = " idc "  id = ' idc5 '  value = " 5 "   onclick = " ChangeIdc(this) " ></ td >< td  class = " li_left "  nowrap >< label  for = " idc5 " > 移动1: </ label ></ td >< td id = ' show5 '   class = " li_right "   >< span  class = " normal " > 测速中... </ span >
            
< script type = ' text/javascript ' > PushToTestArray( 5 , " m179.mail.qq.com " , 0 , 0 , 0 ); </ script ></ td ></ table >
    
</ div >
< script >  
//     setUserPos(1);
    idc_p  =   " 1 "   ?   " 1 "  :  " 0 " ;
</ script >
< div id = " infobtn "  style = " position:absolute;top:401px;width:495px;left:2px; "  disabled = " true "    >
        
< div style = " padding:0 0 0 8px " >< input type = " checkbox "  id = " saveset "  name = " abstract "  value = " 0 "    checked   >< label  for = " saveset " > 记住我的选择 < span  class = " normal " >  (对当前电脑有效,有效期为  1  个月) </ span ></ label ></ div >
    
< div style = " background:#eaf3ff;height:30px;line-height:30px;text-align:right;margin-top:8px; " >
    
< input type = " button "  id  = " save "   class = " btn "  style = " margin:1px 1px 0 0;width:96px "   value = ' 保存并重新登录 '  onClick = " checkclick('save') " >< input type = " button "    class = " btn "   value = ' 保存并关闭 '  style = " margin:1px 1px 0 0;width:96px "  onClick = " checkclick('close') " >< input type = " button "  id  = " save "   class = " btn "  style = " margin:1px 1px 0 0;width:96px "   value = ' 登录到简洁版 '  onClick = " checkclick('basic') " >      </ div >
</ div >
</ form >
< script > setTimeout(tryarray, 900 ); </ script >
< script > setTimeout(DisplayResult, 9000 ); </ script >
< script > setTimeout(DisplayClose, 15000 ); </ script >
</ body >
</ html >

 

转载于:https://www.cnblogs.com/dengwujie/archive/2010/01/03/1638371.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值