1
0

example-singleServer-customSettings.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. if(aborted){ //if the test was aborted, clear the UI and prepare for new test
  25. initUI();
  26. }
  27. }
  28. function startStop(){ //start/stop button pressed
  29. if(s.getState()==3){
  30. //speedtest is running, abort
  31. s.abort();
  32. }else{
  33. //test is not running, begin
  34. s.start();
  35. I("startStopBtn").className="running";
  36. }
  37. }
  38. //function to (re)initialize UI
  39. function initUI(){
  40. I("dlText").textContent="";
  41. I("ulText").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. div.meterText:empty:before{
  118. color:#505050 !important;
  119. content:"0.00";
  120. }
  121. div.unit{
  122. position:absolute;
  123. bottom:2em; left:0;
  124. width:100%;
  125. z-index:9;
  126. }
  127. div.testGroup{
  128. display:inline-block;
  129. }
  130. @media all and (max-width:65em){
  131. body{
  132. font-size:2vw;
  133. }
  134. }
  135. @media all and (max-width:40em){
  136. body{
  137. font-size:0.8em;
  138. }
  139. div.testGroup{
  140. display:block;
  141. margin: 0 auto;
  142. }
  143. }
  144. </style>
  145. </head>
  146. <body>
  147. <h1>LibreSpeed Example</h1>
  148. <div id="startStopBtn" onclick="startStop()"></div>
  149. <div id="test">
  150. <div class="testGroup">
  151. <div class="testArea">
  152. <div class="testName">Download</div>
  153. <div id="dlText" class="meterText"></div>
  154. <div class="unit">Mbit/s</div>
  155. </div>
  156. <div class="testArea">
  157. <div class="testName">Upload</div>
  158. <div id="ulText" class="meterText"></div>
  159. <div class="unit">Mbit/s</div>
  160. </div>
  161. </div>
  162. </div>
  163. <a href="https://github.com/librespeed/speedtest">Source code</a>
  164. <script type="text/javascript">
  165. initUI();
  166. </script>
  167. </body>
  168. </html>