example-singleServer-pretty.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. border-radius:0.3em;
  65. transition:all 0.3s;
  66. box-sizing:border-box;
  67. width:8em; height:3em;
  68. line-height:2.7em;
  69. cursor:pointer;
  70. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  71. }
  72. #startStopBtn:hover{
  73. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  74. }
  75. #startStopBtn.running{
  76. background-color:#FF3030;
  77. border-color:#FF6060;
  78. color:#FFFFFF;
  79. }
  80. #startStopBtn:before{
  81. content:"Start";
  82. }
  83. #startStopBtn.running:before{
  84. content:"Abort";
  85. }
  86. #test{
  87. margin-top:2em;
  88. margin-bottom:12em;
  89. }
  90. div.testArea{
  91. display:inline-block;
  92. width:14em;
  93. height:9em;
  94. position:relative;
  95. box-sizing:border-box;
  96. }
  97. div.testName{
  98. position:absolute;
  99. top:0.1em; left:0;
  100. width:100%;
  101. font-size:1.4em;
  102. z-index:9;
  103. }
  104. div.meterText{
  105. position:absolute;
  106. bottom:1.5em; left:0;
  107. width:100%;
  108. font-size:2.5em;
  109. z-index:9;
  110. }
  111. #dlText{
  112. color:#6060AA;
  113. }
  114. #ulText{
  115. color:#309030;
  116. }
  117. #pingText,#jitText{
  118. color:#AA6060;
  119. }
  120. div.meterText:empty:before{
  121. color:#505050 !important;
  122. content:"0.00";
  123. }
  124. div.unit{
  125. position:absolute;
  126. bottom:2em; left:0;
  127. width:100%;
  128. z-index:9;
  129. }
  130. div.testGroup{
  131. display:inline-block;
  132. }
  133. @media all and (max-width:65em){
  134. body{
  135. font-size:1.5vw;
  136. }
  137. }
  138. @media all and (max-width:40em){
  139. body{
  140. font-size:0.8em;
  141. }
  142. div.testGroup{
  143. display:block;
  144. margin: 0 auto;
  145. }
  146. }
  147. </style>
  148. </head>
  149. <body>
  150. <h1>LibreSpeed Example</h1>
  151. <div id="startStopBtn" onclick="startStop()"></div>
  152. <div id="test">
  153. <div class="testGroup">
  154. <div class="testArea">
  155. <div class="testName">Download</div>
  156. <div id="dlText" class="meterText"></div>
  157. <div class="unit">Mbit/s</div>
  158. </div>
  159. <div class="testArea">
  160. <div class="testName">Upload</div>
  161. <div id="ulText" class="meterText"></div>
  162. <div class="unit">Mbit/s</div>
  163. </div>
  164. </div>
  165. <div class="testGroup">
  166. <div class="testArea">
  167. <div class="testName">Ping</div>
  168. <div id="pingText" class="meterText"></div>
  169. <div class="unit">ms</div>
  170. </div>
  171. <div class="testArea">
  172. <div class="testName">Jitter</div>
  173. <div id="jitText" class="meterText"></div>
  174. <div class="unit">ms</div>
  175. </div>
  176. </div>
  177. <div id="ipArea">
  178. IP Address: <span id="ip"></span>
  179. </div>
  180. </div>
  181. <a href="https://github.com/librespeed/speedtest">Source code</a>
  182. <script type="text/javascript">
  183. initUI();
  184. </script>
  185. </body>
  186. </html>