example-singleServer-customSettings.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. //CUSTOM SETTINGS HERE
  13. s.setParameter("test_order","D_U"); //we only want download and upload test
  14. s.setParameter("time_auto",false); //fixed duration for tests
  15. s.setParameter("time_dl_max",10); //10 seconds for the download test
  16. s.setParameter("time_ul_max",15); //15 seconds for the upload test
  17. //END OF CUSTOM SETTINGS
  18. s.onupdate=function(data){ //callback to update data in UI
  19. I("dlText").textContent=(data.testState==1&&data.dlStatus==0)?"...":data.dlStatus;
  20. I("ulText").textContent=(data.testState==3&&data.ulStatus==0)?"...":data.ulStatus;
  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. }
  28. }
  29. function startStop(){ //start/stop button pressed
  30. if(s.getState()==3){
  31. //speedtest is running, abort
  32. s.abort();
  33. }else{
  34. //test is not running, begin
  35. s.start();
  36. I("startStopBtn").className="running";
  37. I("startStopBtn").setAttribute("aria-label","Abort");
  38. }
  39. }
  40. //function to (re)initialize UI
  41. function initUI(){
  42. I("dlText").textContent="";
  43. I("ulText").textContent="";
  44. }
  45. function I(id){return document.getElementById(id);}
  46. </script>
  47. <style type="text/css">
  48. html,body{
  49. border:none; padding:0; margin:0;
  50. background:#FFFFFF;
  51. color:#202020;
  52. }
  53. body{
  54. text-align:center;
  55. font-family:"Roboto",sans-serif;
  56. }
  57. h1{
  58. color:#404040;
  59. }
  60. #startStopBtn{
  61. display:inline-block;
  62. margin:0 auto;
  63. color:#6060AA;
  64. background-color:rgba(0,0,0,0);
  65. border:0.15em solid #6060FF;
  66. padding:0;
  67. font:inherit;
  68. border-radius:0.3em;
  69. transition:all 0.3s;
  70. box-sizing:border-box;
  71. width:8em; height:3em;
  72. line-height:2.7em;
  73. cursor:pointer;
  74. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  75. }
  76. #startStopBtn:hover{
  77. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  78. }
  79. #startStopBtn.running{
  80. background-color:#FF3030;
  81. border-color:#FF6060;
  82. color:#FFFFFF;
  83. }
  84. #startStopBtn:before{
  85. content:"Start";
  86. }
  87. #startStopBtn.running:before{
  88. content:"Abort";
  89. }
  90. #test{
  91. margin-top:2em;
  92. margin-bottom:12em;
  93. }
  94. div.testArea{
  95. display:inline-block;
  96. width:14em;
  97. height:9em;
  98. position:relative;
  99. box-sizing:border-box;
  100. }
  101. div.testName{
  102. position:absolute;
  103. top:0.1em; left:0;
  104. width:100%;
  105. font-size:1.4em;
  106. z-index:9;
  107. }
  108. div.meterText{
  109. position:absolute;
  110. bottom:1.5em; left:0;
  111. width:100%;
  112. font-size:2.5em;
  113. z-index:9;
  114. }
  115. #dlText{
  116. color:#6060AA;
  117. }
  118. #ulText{
  119. color:#309030;
  120. }
  121. div.meterText:empty:before{
  122. color:#505050 !important;
  123. content:"0.00";
  124. }
  125. div.unit{
  126. position:absolute;
  127. bottom:2em; left:0;
  128. width:100%;
  129. z-index:9;
  130. }
  131. div.testGroup{
  132. display:inline-block;
  133. }
  134. @media all and (max-width:65em){
  135. body{
  136. font-size:2vw;
  137. }
  138. }
  139. @media all and (max-width:40em){
  140. body{
  141. font-size:0.8em;
  142. }
  143. div.testGroup{
  144. display:block;
  145. margin: 0 auto;
  146. }
  147. }
  148. </style>
  149. </head>
  150. <body>
  151. <h1>LibreSpeed Example</h1>
  152. <button id="startStopBtn" onclick="startStop()" aria-label="Start"></button>
  153. <div id="test">
  154. <div class="testGroup">
  155. <div class="testArea">
  156. <div class="testName">Download</div>
  157. <div id="dlText" class="meterText"></div>
  158. <div class="unit">Mbit/s</div>
  159. </div>
  160. <div class="testArea">
  161. <div class="testName">Upload</div>
  162. <div id="ulText" class="meterText"></div>
  163. <div class="unit">Mbit/s</div>
  164. </div>
  165. </div>
  166. </div>
  167. <a href="https://github.com/librespeed/speedtest">Source code</a>
  168. <script type="text/javascript">
  169. initUI();
  170. </script>
  171. </body>
  172. </html>