example-customSettings.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. </style>
  110. <script type="text/javascript">
  111. function I(id){return document.getElementById(id);}
  112. var w=null; //speedtest worker
  113. var parameters={ //custom test parameters. See doc.md for a complete list
  114. time_dl: 10, //download test lasts 10 seconds
  115. time_ul: 10, //upload test lasts 10 seconds
  116. count_ping: 20, //ping+jitter test does 20 pings
  117. getIp_ispInfo: false //will only get IP address without ISP info
  118. };
  119. function startStop(){
  120. if(w!=null){
  121. //speedtest is running, abort
  122. w.postMessage('abort');
  123. w=null;
  124. I("startStopBtn").className="";
  125. initUI();
  126. }else{
  127. //test is not running, begin
  128. w=new Worker('speedtest_worker.min.js');
  129. w.postMessage('start '+JSON.stringify(parameters)); //run the test with custom parameters
  130. I("startStopBtn").className="running";
  131. w.onmessage=function(e){
  132. var data=JSON.parse(e.data);
  133. var status=data.testState;
  134. if(status>=4){
  135. //test completed
  136. I("startStopBtn").className="";
  137. w=null;
  138. }
  139. I("ip").textContent=data.clientIp;
  140. I("dlText").textContent=(status==1&&data.dlStatus==0)?"...":data.dlStatus;
  141. I("ulText").textContent=(status==3&&data.ulStatus==0)?"...":data.ulStatus;
  142. I("pingText").textContent=data.pingStatus;
  143. I("jitText").textContent=data.jitterStatus;
  144. };
  145. }
  146. }
  147. //poll the status from the worker every 200ms (this will also update the UI)
  148. setInterval(function(){
  149. if(w) w.postMessage('status');
  150. },200);
  151. //function to (re)initialize UI
  152. function initUI(){
  153. I("dlText").textContent="";
  154. I("ulText").textContent="";
  155. I("pingText").textContent="";
  156. I("jitText").textContent="";
  157. I("ip").textContent="";
  158. }
  159. </script>
  160. </head>
  161. <body>
  162. <h1>HTML5 Speedtest - Custom settings example</h1>
  163. <div id="startStopBtn" onclick="startStop()"></div>
  164. <div id="test">
  165. <div class="testGroup">
  166. <div class="testArea">
  167. <div class="testName">Download</div>
  168. <div id="dlText" class="meterText"></div>
  169. <div class="unit">Mbps</div>
  170. </div>
  171. <div class="testArea">
  172. <div class="testName">Upload</div>
  173. <div id="ulText" class="meterText"></div>
  174. <div class="unit">Mbps</div>
  175. </div>
  176. </div>
  177. <div class="testGroup">
  178. <div class="testArea">
  179. <div class="testName">Ping</div>
  180. <div id="pingText" class="meterText"></div>
  181. <div class="unit">ms</div>
  182. </div>
  183. <div class="testArea">
  184. <div class="testName">Jitter</div>
  185. <div id="jitText" class="meterText"></div>
  186. <div class="unit">ms</div>
  187. </div>
  188. </div>
  189. <div id="ipArea">
  190. IP Address: <span id="ip"></span>
  191. </div>
  192. </div>
  193. <div>Custom parameters: <span id="params"></span><script type="text/javascript">I("params").textContent=JSON.stringify(parameters)</script></div>
  194. <a href="https://github.com/adolfintel/speedtest">Source code</a>
  195. <script type="text/javascript">initUI();</script>
  196. </body>
  197. </html>