example-singleServer-customSettings.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. //CUSTOM SETTINGS HERE
  12. s.setParameter("test_order","D_U"); //we only want download and upload test
  13. s.setParameter("time_auto",false); //fixed duration for tests
  14. s.setParameter("time_dl_max",10); //10 seconds for the download test
  15. s.setParameter("time_ul_max",15); //15 seconds for the upload test
  16. //END OF CUSTOM SETTINGS
  17. s.onupdate=function(data){ //callback to update data in UI
  18. I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
  19. I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus;
  20. }
  21. s.onend=function(aborted){ //callback for test ended/aborted
  22. I("startStopBtn").className=""; //show start button again
  23. if(aborted){ //if the test was aborted, clear the UI and prepare for new test
  24. initUI();
  25. }
  26. }
  27. function startStop(){ //start/stop button pressed
  28. if(s.getState()==3){
  29. //speedtest is running, abort
  30. s.abort();
  31. }else{
  32. //test is not running, begin
  33. s.start();
  34. I("startStopBtn").className="running";
  35. }
  36. }
  37. //function to (re)initialize UI
  38. function initUI(){
  39. I("dlText").textContent="";
  40. I("ulText").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. div.meterText:empty:before{
  117. color:#505050 !important;
  118. content:"0.00";
  119. }
  120. div.unit{
  121. position:absolute;
  122. bottom:2em; left:0;
  123. width:100%;
  124. z-index:9;
  125. }
  126. div.testGroup{
  127. display:inline-block;
  128. }
  129. @media all and (max-width:65em){
  130. body{
  131. font-size:2vw;
  132. }
  133. }
  134. @media all and (max-width:40em){
  135. body{
  136. font-size:0.8em;
  137. }
  138. div.testGroup{
  139. display:block;
  140. margin: 0 auto;
  141. }
  142. }
  143. </style>
  144. </head>
  145. <body>
  146. <h1>HTML5 Speedtest</h1>
  147. <div id="startStopBtn" onclick="startStop()"></div>
  148. <div id="test">
  149. <div class="testGroup">
  150. <div class="testArea">
  151. <div class="testName">Download</div>
  152. <div id="dlText" class="meterText"></div>
  153. <div class="unit">Mbps</div>
  154. </div>
  155. <div class="testArea">
  156. <div class="testName">Upload</div>
  157. <div id="ulText" class="meterText"></div>
  158. <div class="unit">Mbps</div>
  159. </div>
  160. </div>
  161. </div>
  162. <a href="https://github.com/adolfintel/speedtest">Source code</a>
  163. <script type="text/javascript">
  164. initUI();
  165. </script>
  166. </body>
  167. </html>