example-multipleServers-pretty.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="shortcut icon" href="favicon.ico">
  5. <meta charset="UTF-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
  7. <title>HTML5 Speedtest</title>
  8. <script type="text/javascript" src="speedtest.js"></script>
  9. <script type="text/javascript">
  10. //LIST OF TEST SERVERS. See documentation for details if needed
  11. var SPEEDTEST_SERVERS=[
  12. { //this is my demo server, remove it
  13. name:"Speedtest Demo Server (Helsinki)", //user friendly name for the server
  14. server:"//fi.openspeed.org/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically
  15. dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
  16. ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
  17. pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
  18. getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
  19. },
  20. { //this is my demo server, remove it
  21. name:"Old Speedtest Demo Server",
  22. server:"//mpotdemo.fdossena.com/",
  23. dlURL:"garbage.php",
  24. ulURL:"empty.php",
  25. pingURL:"empty.php",
  26. getIpURL:"getIP.php"
  27. }
  28. //add other servers here, comma separated
  29. ];
  30. //INITIALIZE SPEEDTEST
  31. var s=new Speedtest(); //create speedtest object
  32. s.addTestPoints(SPEEDTEST_SERVERS); //add list of servers
  33. s.onupdate=function(data){ //callback to update data in UI
  34. I("ip").textContent=data.clientIp;
  35. I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
  36. I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus;
  37. I("pingText").textContent=data.pingStatus;
  38. I("jitText").textContent=data.jitterStatus;
  39. }
  40. s.onend=function(aborted){ //callback for test ended/aborted
  41. I("startStopBtn").className=""; //show start button again
  42. if(aborted){ //if the test was aborted, clear the UI and prepare for new test
  43. initUI();
  44. }
  45. }
  46. function selectServer(){ //called when the page is fully loaded
  47. I("startStopBtn").style.display="none"; //hide start/stop button during server selection
  48. s.selectServer(function(server){ //run server selection. When the server has been selected, display it in the UI
  49. I("startStopBtn").style.display=""; //show start/stop button again
  50. I("serverId").textContent=server.name; //show name of test server
  51. });
  52. }
  53. function startStop(){ //start/stop button pressed
  54. if(s.getState()==3){
  55. //speedtest is running, abort
  56. s.abort();
  57. }else{
  58. //test is not running, begin
  59. s.start();
  60. I("startStopBtn").className="running";
  61. }
  62. }
  63. //function to (re)initialize UI
  64. function initUI(){
  65. I("dlText").textContent="";
  66. I("ulText").textContent="";
  67. I("pingText").textContent="";
  68. I("jitText").textContent="";
  69. I("ip").textContent="";
  70. }
  71. function I(id){return document.getElementById(id);}
  72. </script>
  73. <style type="text/css">
  74. html,body{
  75. border:none; padding:0; margin:0;
  76. background:#FFFFFF;
  77. color:#202020;
  78. }
  79. body{
  80. text-align:center;
  81. font-family:"Roboto",sans-serif;
  82. }
  83. h1{
  84. color:#404040;
  85. }
  86. #startStopBtn{
  87. display:inline-block;
  88. margin:0 auto;
  89. color:#6060AA;
  90. background-color:rgba(0,0,0,0);
  91. border:0.15em solid #6060FF;
  92. border-radius:0.3em;
  93. transition:all 0.3s;
  94. box-sizing:border-box;
  95. width:8em; height:3em;
  96. line-height:2.7em;
  97. cursor:pointer;
  98. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  99. }
  100. #startStopBtn:hover{
  101. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  102. }
  103. #startStopBtn.running{
  104. background-color:#FF3030;
  105. border-color:#FF6060;
  106. color:#FFFFFF;
  107. }
  108. #startStopBtn:before{
  109. content:"Start";
  110. }
  111. #startStopBtn.running:before{
  112. content:"Abort";
  113. }
  114. #test{
  115. margin-top:2em;
  116. margin-bottom:12em;
  117. }
  118. div.testArea{
  119. display:inline-block;
  120. width:14em;
  121. height:9em;
  122. position:relative;
  123. box-sizing:border-box;
  124. }
  125. div.testName{
  126. position:absolute;
  127. top:0.1em; left:0;
  128. width:100%;
  129. font-size:1.4em;
  130. z-index:9;
  131. }
  132. div.meterText{
  133. position:absolute;
  134. bottom:1.5em; left:0;
  135. width:100%;
  136. font-size:2.5em;
  137. z-index:9;
  138. }
  139. #dlText{
  140. color:#6060AA;
  141. }
  142. #ulText{
  143. color:#309030;
  144. }
  145. #pingText,#jitText{
  146. color:#AA6060;
  147. }
  148. div.meterText:empty:before{
  149. color:#505050 !important;
  150. content:"0.00";
  151. }
  152. div.unit{
  153. position:absolute;
  154. bottom:2em; left:0;
  155. width:100%;
  156. z-index:9;
  157. }
  158. div.testGroup{
  159. display:inline-block;
  160. }
  161. @media all and (max-width:65em){
  162. body{
  163. font-size:1.5vw;
  164. }
  165. }
  166. @media all and (max-width:40em){
  167. body{
  168. font-size:0.8em;
  169. }
  170. div.testGroup{
  171. display:block;
  172. margin: 0 auto;
  173. }
  174. }
  175. </style>
  176. </head>
  177. <body>
  178. <h1>HTML5 Speedtest</h1>
  179. <div id="startStopBtn" onclick="startStop()"></div>
  180. <div id="serverId">Selecting server...</div>
  181. <div id="test">
  182. <div class="testGroup">
  183. <div class="testArea">
  184. <div class="testName">Download</div>
  185. <div id="dlText" class="meterText"></div>
  186. <div class="unit">Mbps</div>
  187. </div>
  188. <div class="testArea">
  189. <div class="testName">Upload</div>
  190. <div id="ulText" class="meterText"></div>
  191. <div class="unit">Mbps</div>
  192. </div>
  193. </div>
  194. <div class="testGroup">
  195. <div class="testArea">
  196. <div class="testName">Ping</div>
  197. <div id="pingText" class="meterText"></div>
  198. <div class="unit">ms</div>
  199. </div>
  200. <div class="testArea">
  201. <div class="testName">Jitter</div>
  202. <div id="jitText" class="meterText"></div>
  203. <div class="unit">ms</div>
  204. </div>
  205. </div>
  206. <div id="ipArea">
  207. IP Address: <span id="ip"></span>
  208. </div>
  209. </div>
  210. <a href="https://github.com/adolfintel/speedtest">Source code</a>
  211. <script type="text/javascript">
  212. initUI();
  213. selectServer();
  214. </script>
  215. </body>
  216. </html>