example-singleServer-pretty.html 4.1 KB

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