You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
  6. <title>HTML5 Speedtest</title>
  7. <style type="text/css">
  8. html,body{
  9. border:none; padding:0; margin:0;
  10. background:#FFFFFF;
  11. color:#202020;
  12. }
  13. body{
  14. text-align:center;
  15. font-family:"Roboto",sans-serif;
  16. }
  17. h1{
  18. color:#404040;
  19. }
  20. #startStopBtn{
  21. display:inline-block;
  22. margin:0 auto;
  23. color:#6060AA;
  24. background-color:rgba(0,0,0,0);
  25. border:0.15em solid #6060FF;
  26. border-radius:0.3em;
  27. transition:all 0.3s;
  28. box-sizing:border-box;
  29. width:8em; height:3em;
  30. line-height:2.7em;
  31. cursor:pointer;
  32. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  33. }
  34. #startStopBtn:hover{
  35. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  36. }
  37. #startStopBtn.running{
  38. background-color:#FF3030;
  39. border-color:#FF6060;
  40. color:#FFFFFF;
  41. }
  42. #startStopBtn:before{
  43. content:"Start";
  44. }
  45. #startStopBtn.running:before{
  46. content:"Abort";
  47. }
  48. #test{
  49. margin-top:2em;
  50. margin-bottom:12em;
  51. }
  52. div.testArea{
  53. display:inline-block;
  54. width:14em;
  55. height:9em;
  56. position:relative;
  57. box-sizing:border-box;
  58. }
  59. div.testName{
  60. position:absolute;
  61. top:0.1em; left:0;
  62. width:100%;
  63. font-size:1.4em;
  64. z-index:9;
  65. }
  66. div.meterText{
  67. position:absolute;
  68. bottom:1.5em; left:0;
  69. width:100%;
  70. font-size:2.5em;
  71. z-index:9;
  72. }
  73. #dlText{
  74. color:#6060AA;
  75. }
  76. #ulText{
  77. color:#309030;
  78. }
  79. #pingText,#jitText{
  80. color:#AA6060;
  81. }
  82. div.meterText:empty:before{
  83. color:#505050 !important;
  84. content:"0.00";
  85. }
  86. div.unit{
  87. position:absolute;
  88. bottom:2em; left:0;
  89. width:100%;
  90. z-index:9;
  91. }
  92. div.testGroup{
  93. display:inline-block;
  94. }
  95. @media all and (max-width:65em){
  96. body{
  97. font-size:1.5vw;
  98. }
  99. }
  100. @media all and (max-width:40em){
  101. body{
  102. font-size:0.8em;
  103. }
  104. div.testGroup{
  105. display:block;
  106. margin: 0 auto;
  107. }
  108. }
  109. #progressBar{
  110. width:90%;
  111. height:0.3em;
  112. background-color:#EEEEEE;
  113. position:relative;
  114. display:block;
  115. margin:0 auto;
  116. margin-bottom:2em;
  117. }
  118. #progress{
  119. position:absolute;
  120. top:0; left:0;
  121. height:100%;
  122. width:0%;
  123. transition: width 2s;
  124. background-color:#90BBFF;
  125. }
  126. </style>
  127. <script type="text/javascript">
  128. function I(id){return document.getElementById(id);}
  129. var w=null; //speedtest worker
  130. function startStop(){
  131. if(w!=null){
  132. //speedtest is running, abort
  133. w.postMessage('abort');
  134. w=null;
  135. I("startStopBtn").className="";
  136. initUI();
  137. }else{
  138. //test is not running, begin
  139. w=new Worker('speedtest_worker.min.js');
  140. w.postMessage('start', {
  141. time_dl_max: 20,
  142. time_ul_max: 20,
  143. time_auto: false,
  144. getIp_ispInfo: false,
  145. getIp_ispInfo_distance: false
  146. }); //Add optional parameters as a JSON object to this command
  147. I("startStopBtn").className="running";
  148. w.onmessage=function(e){
  149. var data=JSON.parse(e.data);
  150. var status=data.testState;
  151. if(status>=4){
  152. //test completed
  153. I("startStopBtn").className="";
  154. w=null;
  155. }
  156. I("ip").textContent=data.clientIp;
  157. I("dlText").textContent=(status==1&&data.dlStatus==0)?"...":data.dlStatus;
  158. I("ulText").textContent=(status==3&&data.ulStatus==0)?"...":data.ulStatus;
  159. I("pingText").textContent=data.pingStatus;
  160. I("jitText").textContent=data.jitterStatus;
  161. var prog=(Number(data.dlProgress)*2+Number(data.ulProgress)*2+Number(data.pingProgress))/5;
  162. I("progress").style.width=(100*prog)+"%";
  163. };
  164. }
  165. }
  166. //poll the status from the worker every 200ms (this will also update the UI)
  167. setInterval(function(){
  168. if(w) w.postMessage('status');
  169. },200);
  170. //function to (re)initialize UI
  171. function initUI(){
  172. I("dlText").textContent="";
  173. I("ulText").textContent="";
  174. I("pingText").textContent="";
  175. I("jitText").textContent="";
  176. I("ip").textContent="";
  177. I("progress").style.width="";
  178. }
  179. </script>
  180. </head>
  181. <body>
  182. <h1>HTML5 Speedtest</h1>
  183. <div id="startStopBtn" onclick="startStop()"></div>
  184. <div id="test">
  185. <div id="progressBar"><div id="progress"></div></div>
  186. <div class="testGroup">
  187. <div class="testArea">
  188. <div class="testName">Download</div>
  189. <div id="dlText" class="meterText"></div>
  190. <div class="unit">Mbps</div>
  191. </div>
  192. <div class="testArea">
  193. <div class="testName">Upload</div>
  194. <div id="ulText" class="meterText"></div>
  195. <div class="unit">Mbps</div>
  196. </div>
  197. </div>
  198. <div class="testGroup">
  199. <div class="testArea">
  200. <div class="testName">Ping</div>
  201. <div id="pingText" class="meterText"></div>
  202. <div class="unit">ms</div>
  203. </div>
  204. <div class="testArea">
  205. <div class="testName">Jitter</div>
  206. <div id="jitText" class="meterText"></div>
  207. <div class="unit">ms</div>
  208. </div>
  209. </div>
  210. <div id="ipArea">
  211. IP Address: <span id="ip"></span>
  212. </div>
  213. </div>
  214. <a href="https://github.com/adolfintel/speedtest">Source code</a>
  215. <script type="text/javascript">initUI();</script>
  216. </body>
  217. </html>