example-singleServer-modern.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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</title>
  7. <link rel="shortcut icon" href="favicon.ico">
  8. <link rel="preconnect" href="https://fonts.googleapis.com">
  9. <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Open+Sans:wght@400;700&family=Noto+Color+Emoji&display=swap" rel="stylesheet">
  10. <script type="text/javascript" src="speedtest.js"></script>
  11. <script type="text/javascript">
  12. //INITIALIZE SPEEDTEST
  13. var s=new Speedtest(); //create speedtest object
  14. s.setParameter("telemetry_level","basic"); //enable telemetry
  15. s.onupdate=function(data){ //callback to update data in UI
  16. I("ip").textContent=data.clientIp;
  17. I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
  18. I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus;
  19. I("pingText").textContent=data.pingStatus;
  20. I("jitText").textContent=data.jitterStatus;
  21. }
  22. s.onend=function(aborted){ //callback for test ended/aborted
  23. I("startStopBtn").className=""; //show start button again
  24. if(aborted){ //if the test was aborted, clear the UI and prepare for new test
  25. initUI();
  26. } else {
  27. // Check if download speed is greater than 50 Mbit/s
  28. var dlSpeed = parseFloat(I("dlText").textContent);
  29. if (dlSpeed > 50) {
  30. I("speedMessage").textContent = "📽️👍";
  31. } else {
  32. I("speedMessage").textContent = "🙄";
  33. }
  34. }
  35. }
  36. function startStop(){ //start/stop button pressed
  37. if(s.getState()==3){
  38. //speedtest is running, abort
  39. s.abort();
  40. }else{
  41. //test is not running, begin
  42. s.start();
  43. I("startStopBtn").className="running";
  44. }
  45. }
  46. //function to (re)initialize UI
  47. function initUI(){
  48. I("dlText").textContent="";
  49. I("ulText").textContent="";
  50. I("pingText").textContent="";
  51. I("jitText").textContent="";
  52. I("ip").textContent="";
  53. }
  54. function I(id){return document.getElementById(id);}
  55. // Automatically start the test when the page loads
  56. window.onload = function() {
  57. startStop();
  58. }
  59. </script>
  60. <style type="text/css">
  61. html,body{
  62. border:none; padding:0; margin:0;
  63. background:#f4f4f9;
  64. color:#333;
  65. font-family:"Roboto",sans-serif;
  66. }
  67. body{
  68. text-align:center;
  69. }
  70. h1{
  71. color:#333;
  72. margin-top:1em;
  73. }
  74. #startStopBtn{
  75. display:inline-block;
  76. margin:1em auto;
  77. color:#fff;
  78. background-color:#007bff;
  79. border:none;
  80. border-radius:0.3em;
  81. transition:all 0.3s;
  82. box-sizing:border-box;
  83. width:10em; height:3em;
  84. line-height:3em;
  85. cursor:pointer;
  86. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  87. font-size:1em;
  88. }
  89. #startStopBtn:hover{
  90. background-color:#0056b3;
  91. }
  92. #startStopBtn.running{
  93. background-color:#dc3545;
  94. }
  95. #startStopBtn:before{
  96. content:"Start";
  97. }
  98. #startStopBtn.running:before{
  99. content:"Abort";
  100. }
  101. #test{
  102. margin-top:2em;
  103. margin-bottom:4em;
  104. }
  105. div.testArea{
  106. display:inline-block;
  107. width:14em;
  108. height:9em;
  109. position:relative;
  110. box-sizing:border-box;
  111. margin:1em;
  112. background:#fff;
  113. border-radius:0.5em;
  114. box-shadow:0 0 10px rgba(0,0,0,0.1);
  115. padding:1em;
  116. }
  117. div.testName{
  118. position:absolute;
  119. top:0.5em; left:0;
  120. width:100%;
  121. font-size:1.2em;
  122. z-index:9;
  123. color:#555;
  124. }
  125. div.meterText{
  126. position:absolute;
  127. bottom:1.5em; left:0;
  128. width:100%;
  129. font-size:2.5em;
  130. z-index:9;
  131. color:#007bff;
  132. }
  133. div.testConclusion{
  134. position:absolute;
  135. bottom:2em; left:0;
  136. width:100%;
  137. font-size:5em;
  138. z-index:9;
  139. color:#333;
  140. text-shadow:0 0 10px #888;
  141. }
  142. #dlText{
  143. color:#007bff;
  144. }
  145. #ulText{
  146. color:#28a745;
  147. }
  148. #pingText,#jitText{
  149. color:#dc3545;
  150. }
  151. div.meterText:empty:before{
  152. color:#ccc !important;
  153. content:"0.00";
  154. }
  155. div.unit{
  156. position:absolute;
  157. bottom:2em; left:0;
  158. width:100%;
  159. z-index:9;
  160. color:#777;
  161. }
  162. div.testGroup{
  163. display:inline-block;
  164. }
  165. @media all and (max-width:65em){
  166. body{
  167. font-size:1.5vw;
  168. }
  169. }
  170. @media all and (max-width:40em){
  171. body{
  172. font-size:0.8em;
  173. }
  174. div.testGroup{
  175. display:block;
  176. margin: 0 auto;
  177. }
  178. }
  179. </style>
  180. </head>
  181. <body>
  182. <h1>LibreSpeed</h1>
  183. <div id="startStopBtn" onclick="startStop()"></div>
  184. <div id="test">
  185. <div class="testGroup">
  186. <div class="testArea">
  187. <div class="testName">Download</div>
  188. <div id="dlText" class="meterText"></div>
  189. <div class="unit">Mbit/s</div>
  190. </div>
  191. <div class="testArea">
  192. <div class="testName">Upload</div>
  193. <div id="ulText" class="meterText"></div>
  194. <div class="unit">Mbit/s</div>
  195. </div>
  196. </div>
  197. <div class="testGroup">
  198. <div class="testArea">
  199. <div class="testName">Ping</div>
  200. <div id="pingText" class="meterText"></div>
  201. <div class="unit">ms</div>
  202. </div>
  203. <div class="testArea">
  204. <div class="testName">Jitter</div>
  205. <div id="jitText" class="meterText"></div>
  206. <div class="unit">ms</div>
  207. </div>
  208. </div>
  209. <div id="speedMessage" class="testConclusion">
  210. </div>
  211. <div id="ipArea">
  212. IP Address: <span id="ip"></span>
  213. </div>
  214. </div>
  215. <a href="https://github.com/librespeed/speedtest">Source code</a>
  216. <script type="text/javascript">
  217. initUI();
  218. </script>
  219. </body>
  220. </html>