example-singleServer-pretty.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <script type="text/javascript" src="speedtest.js"></script>
  8. <script type="text/javascript">
  9. //INITIALIZE SPEEDTEST
  10. var s=new Speedtest(); //create speedtest object
  11. s.onupdate=function(data){ //callback to update data in UI
  12. I("ip").textContent=data.clientIp;
  13. I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
  14. I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus;
  15. I("pingText").textContent=data.pingStatus;
  16. I("jitText").textContent=data.jitterStatus;
  17. }
  18. s.onend=function(aborted){ //callback for test ended/aborted
  19. I("startStopBtn").className=""; //show start button again
  20. if(aborted){ //if the test was aborted, clear the UI and prepare for new test
  21. initUI();
  22. }
  23. }
  24. function startStop(){ //start/stop button pressed
  25. if(s.getState()==3){
  26. //speedtest is running, abort
  27. s.abort();
  28. }else{
  29. //test is not running, begin
  30. s.start();
  31. I("startStopBtn").className="running";
  32. }
  33. }
  34. //function to (re)initialize UI
  35. function initUI(){
  36. I("dlText").textContent="";
  37. I("ulText").textContent="";
  38. I("pingText").textContent="";
  39. I("jitText").textContent="";
  40. I("ip").textContent="";
  41. }
  42. function I(id){return document.getElementById(id);}
  43. </script>
  44. <style type="text/css">
  45. html,body{
  46. border:none; padding:0; margin:0;
  47. background:#FFFFFF;
  48. color:#202020;
  49. }
  50. body{
  51. text-align:center;
  52. font-family:"Roboto",sans-serif;
  53. }
  54. h1{
  55. color:#404040;
  56. }
  57. #startStopBtn{
  58. display:inline-block;
  59. margin:0 auto;
  60. color:#6060AA;
  61. background-color:rgba(0,0,0,0);
  62. border:0.15em solid #6060FF;
  63. border-radius:0.3em;
  64. transition:all 0.3s;
  65. box-sizing:border-box;
  66. width:8em; height:3em;
  67. line-height:2.7em;
  68. cursor:pointer;
  69. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  70. }
  71. #startStopBtn:hover{
  72. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  73. }
  74. #startStopBtn.running{
  75. background-color:#FF3030;
  76. border-color:#FF6060;
  77. color:#FFFFFF;
  78. }
  79. #startStopBtn:before{
  80. content:"Start";
  81. }
  82. #startStopBtn.running:before{
  83. content:"Abort";
  84. }
  85. #test{
  86. margin-top:2em;
  87. margin-bottom:12em;
  88. }
  89. div.testArea{
  90. display:inline-block;
  91. width:14em;
  92. height:9em;
  93. position:relative;
  94. box-sizing:border-box;
  95. }
  96. div.testName{
  97. position:absolute;
  98. top:0.1em; left:0;
  99. width:100%;
  100. font-size:1.4em;
  101. z-index:9;
  102. }
  103. div.meterText{
  104. position:absolute;
  105. bottom:1.5em; left:0;
  106. width:100%;
  107. font-size:2.5em;
  108. z-index:9;
  109. }
  110. #dlText{
  111. color:#6060AA;
  112. }
  113. #ulText{
  114. color:#309030;
  115. }
  116. #pingText,#jitText{
  117. color:#AA6060;
  118. }
  119. div.meterText:empty:before{
  120. color:#505050 !important;
  121. content:"0.00";
  122. }
  123. div.unit{
  124. position:absolute;
  125. bottom:2em; left:0;
  126. width:100%;
  127. z-index:9;
  128. }
  129. div.testGroup{
  130. display:inline-block;
  131. }
  132. @media all and (max-width:65em){
  133. body{
  134. font-size:1.5vw;
  135. }
  136. }
  137. @media all and (max-width:40em){
  138. body{
  139. font-size:0.8em;
  140. }
  141. div.testGroup{
  142. display:block;
  143. margin: 0 auto;
  144. }
  145. }
  146. </style>
  147. </head>
  148. <body>
  149. <h1>HTML5 Speedtest</h1>
  150. <div id="startStopBtn" onclick="startStop()"></div>
  151. <div id="test">
  152. <div class="testGroup">
  153. <div class="testArea">
  154. <div class="testName">Download</div>
  155. <div id="dlText" class="meterText"></div>
  156. <div class="unit">Mbps</div>
  157. </div>
  158. <div class="testArea">
  159. <div class="testName">Upload</div>
  160. <div id="ulText" class="meterText"></div>
  161. <div class="unit">Mbps</div>
  162. </div>
  163. </div>
  164. <div class="testGroup">
  165. <div class="testArea">
  166. <div class="testName">Ping</div>
  167. <div id="pingText" class="meterText"></div>
  168. <div class="unit">ms</div>
  169. </div>
  170. <div class="testArea">
  171. <div class="testName">Jitter</div>
  172. <div id="jitText" class="meterText"></div>
  173. <div class="unit">ms</div>
  174. </div>
  175. </div>
  176. <div id="ipArea">
  177. IP Address: <span id="ip"></span>
  178. </div>
  179. </div>
  180. <a href="https://github.com/adolfintel/speedtest">Source code</a>
  181. <script type="text/javascript">
  182. initUI();
  183. </script>
  184. </body>
  185. </html>