example-singleServer-modern.html 6.0 KB

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