index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="shortcut icon" href="favicon.ico">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
  6. <meta charset="UTF-8" />
  7. <script type="text/javascript" src="speedtest.js"></script>
  8. <script type="text/javascript">
  9. function I(i){return document.getElementById(i);}
  10. //LIST OF TEST SERVERS. Leave empty if you're doing a standalone installation. See documentation for details
  11. var SPEEDTEST_SERVERS=[
  12. /*{ //this server doesn't actually exist, remove it
  13. name:"Example Server 1", //user friendly name for the server
  14. server:"//test1.mydomain.com/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically
  15. dlURL:"backend/garbage.php", //path to download test on this server (garbage.php or replacement)
  16. ulURL:"backend/empty.php", //path to upload test on this server (empty.php or replacement)
  17. pingURL:"backend/empty.php", //path to ping/jitter test on this server (empty.php or replacement)
  18. getIpURL:"backend/getIP.php" //path to getIP on this server (getIP.php or replacement)
  19. },
  20. { //this server doesn't actually exist, remove it
  21. name:"Example Server 2", //user friendly name for the server
  22. server:"//test2.example.com/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically
  23. dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
  24. ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
  25. pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
  26. getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
  27. }*/
  28. //add other servers here, comma separated
  29. ];
  30. //INITIALIZE SPEEDTEST
  31. var s=new Speedtest(); //create speed test object
  32. s.setParameter("telemetry_level","basic"); //enable basic telemetry (for results sharing)
  33. //SERVER AUTO SELECTION
  34. function initServers(){
  35. if(SPEEDTEST_SERVERS.length==0){ //standalone installation
  36. //just make the UI visible
  37. I("loading").className="hidden";
  38. I("serverArea").style.display="none";
  39. I("testWrapper").className="visible";
  40. initUI();
  41. }else{ //multiple servers
  42. var noServersAvailable=function(){
  43. I("message").innerHTML="No servers available";
  44. }
  45. var runServerSelect=function(){
  46. s.selectServer(function(server){
  47. if(server!=null){ //at least 1 server is available
  48. I("loading").className="hidden"; //hide loading message
  49. //populate server list for manual selection
  50. for(var i=0;i<SPEEDTEST_SERVERS.length;i++){
  51. if(SPEEDTEST_SERVERS[i].pingT==-1) continue;
  52. var option=document.createElement("option");
  53. option.value=i;
  54. option.textContent=SPEEDTEST_SERVERS[i].name;
  55. if(SPEEDTEST_SERVERS[i]===server) option.selected=true;
  56. I("server").appendChild(option);
  57. }
  58. //show test UI
  59. I("testWrapper").className="visible";
  60. initUI();
  61. }else{ //no servers are available, the test cannot proceed
  62. noServersAvailable();
  63. }
  64. });
  65. }
  66. if(typeof SPEEDTEST_SERVERS === "string"){
  67. //need to fetch list of servers from specified URL
  68. s.loadServerList(SPEEDTEST_SERVERS,function(servers){
  69. if(servers==null){ //failed to load server list
  70. noServersAvailable();
  71. }else{ //server list loaded
  72. SPEEDTEST_SERVERS=servers;
  73. runServerSelect();
  74. }
  75. });
  76. }else{
  77. //hardcoded server list
  78. s.addTestPoints(SPEEDTEST_SERVERS);
  79. runServerSelect();
  80. }
  81. }
  82. }
  83. var meterBk=/Trident.*rv:(\d+\.\d+)/i.test(navigator.userAgent)?"#EAEAEA":"#80808040";
  84. var dlColor="#6060AA",
  85. ulColor="#616161";
  86. var progColor=meterBk;
  87. //CODE FOR GAUGES
  88. function drawMeter(c,amount,bk,fg,progress,prog){
  89. var ctx=c.getContext("2d");
  90. var dp=window.devicePixelRatio||1;
  91. var cw=c.clientWidth*dp, ch=c.clientHeight*dp;
  92. var sizScale=ch*0.0055;
  93. if(c.width==cw&&c.height==ch){
  94. ctx.clearRect(0,0,cw,ch);
  95. }else{
  96. c.width=cw;
  97. c.height=ch;
  98. }
  99. ctx.beginPath();
  100. ctx.strokeStyle=bk;
  101. ctx.lineWidth=12*sizScale;
  102. ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,Math.PI*0.1);
  103. ctx.stroke();
  104. ctx.beginPath();
  105. ctx.strokeStyle=fg;
  106. ctx.lineWidth=12*sizScale;
  107. ctx.arc(c.width/2,c.height-58*sizScale,c.height/1.8-ctx.lineWidth,-Math.PI*1.1,amount*Math.PI*1.2-Math.PI*1.1);
  108. ctx.stroke();
  109. if(typeof progress !== "undefined"){
  110. ctx.fillStyle=prog;
  111. ctx.fillRect(c.width*0.3,c.height-16*sizScale,c.width*0.4*progress,4*sizScale);
  112. }
  113. }
  114. function mbpsToAmount(s){
  115. return 1-(1/(Math.pow(1.3,Math.sqrt(s))));
  116. }
  117. function format(d){
  118. d=Number(d);
  119. if(d<10) return d.toFixed(2);
  120. if(d<100) return d.toFixed(1);
  121. return d.toFixed(0);
  122. }
  123. //UI CODE
  124. var uiData=null;
  125. function startStop(){
  126. if(s.getState()==3){
  127. //speed test is running, abort
  128. s.abort();
  129. data=null;
  130. I("startStopBtn").className="";
  131. I("server").disabled=false;
  132. initUI();
  133. }else{
  134. //test is not running, begin
  135. I("startStopBtn").className="running";
  136. I("shareArea").style.display="none";
  137. I("server").disabled=true;
  138. s.onupdate=function(data){
  139. uiData=data;
  140. };
  141. s.onend=function(aborted){
  142. I("startStopBtn").className="";
  143. I("server").disabled=false;
  144. updateUI(true);
  145. if(!aborted){
  146. //if testId is present, show sharing panel, otherwise do nothing
  147. try{
  148. var testId=uiData.testId;
  149. if(testId!=null){
  150. var shareURL=window.location.href.substring(0,window.location.href.lastIndexOf("/"))+"/results/?id="+testId;
  151. I("resultsImg").src=shareURL;
  152. I("resultsURL").value=shareURL;
  153. I("testId").innerHTML=testId;
  154. I("shareArea").style.display="";
  155. }
  156. }catch(e){}
  157. }
  158. };
  159. s.start();
  160. }
  161. }
  162. //this function reads the data sent back by the test and updates the UI
  163. function updateUI(forced){
  164. if(!forced&&s.getState()!=3) return;
  165. if(uiData==null) return;
  166. var status=uiData.testState;
  167. I("ip").textContent=uiData.clientIp;
  168. I("dlText").textContent=(status==1&&uiData.dlStatus==0)?"...":format(uiData.dlStatus);
  169. drawMeter(I("dlMeter"),mbpsToAmount(Number(uiData.dlStatus*(status==1?oscillate():1))),meterBk,dlColor,Number(uiData.dlProgress),progColor);
  170. I("ulText").textContent=(status==3&&uiData.ulStatus==0)?"...":format(uiData.ulStatus);
  171. drawMeter(I("ulMeter"),mbpsToAmount(Number(uiData.ulStatus*(status==3?oscillate():1))),meterBk,ulColor,Number(uiData.ulProgress),progColor);
  172. I("pingText").textContent=format(uiData.pingStatus);
  173. I("jitText").textContent=format(uiData.jitterStatus);
  174. }
  175. function oscillate(){
  176. return 1+0.02*Math.sin(Date.now()/100);
  177. }
  178. //update the UI every frame
  179. window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||(function(callback,element){setTimeout(callback,1000/60);});
  180. function frame(){
  181. requestAnimationFrame(frame);
  182. updateUI();
  183. }
  184. frame(); //start frame loop
  185. //function to (re)initialize UI
  186. function initUI(){
  187. drawMeter(I("dlMeter"),0,meterBk,dlColor,0);
  188. drawMeter(I("ulMeter"),0,meterBk,ulColor,0);
  189. I("dlText").textContent="";
  190. I("ulText").textContent="";
  191. I("pingText").textContent="";
  192. I("jitText").textContent="";
  193. I("ip").textContent="";
  194. }
  195. </script>
  196. <style type="text/css">
  197. html,body{
  198. border:none; padding:0; margin:0;
  199. background:#FFFFFF;
  200. color:#202020;
  201. }
  202. body{
  203. text-align:center;
  204. font-family:"Roboto",sans-serif;
  205. }
  206. h1{
  207. color:#404040;
  208. }
  209. #loading{
  210. background-color:#FFFFFF;
  211. color:#404040;
  212. text-align:center;
  213. }
  214. span.loadCircle{
  215. display:inline-block;
  216. width:2em;
  217. height:2em;
  218. vertical-align:middle;
  219. background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAP1BMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZyFzwnAAAAFHRSTlMAEvRFvX406baecwbf0casimhSHyiwmqgAAADpSURBVHja7dbJbQMxAENRahnN5lkc//5rDRAkDeRgHszXgACJoKiIiIiIiIiIiIiIiIiIiIj4HHspsrpAVhdVVguzrA4OWc10WcEqpwKbnBo0OU1Q5NSpsoJFTgOecrrdEag85DRgktNqfoEdTjnd7hrEHMEJvmRUYJbTYk5Agy6nau6Abp5Cm7mDBtRdPi9gyKdU7w4p1fsLvyqs8hl4z9/w3n/Hmr9WoQ65lAU4d7lMYOz//QboRR5jBZibLMZdAR6O/Vfa1PlxNr3XdS3HzK/HVPRu/KnLs8iAOh993VpRRERERMT/fAN60wwWaVyWwAAAAABJRU5ErkJggg==');
  220. background-size:2em 2em;
  221. margin-right:0.5em;
  222. animation: spin 0.6s linear infinite;
  223. }
  224. @keyframes spin{
  225. 0%{transform:rotate(0deg);}
  226. 100%{transform:rotate(359deg);}
  227. }
  228. #startStopBtn{
  229. display:inline-block;
  230. margin:0 auto;
  231. color:#6060AA;
  232. background-color:rgba(0,0,0,0);
  233. border:0.15em solid #6060FF;
  234. border-radius:0.3em;
  235. transition:all 0.3s;
  236. box-sizing:border-box;
  237. width:8em; height:3em;
  238. line-height:2.7em;
  239. cursor:pointer;
  240. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  241. }
  242. #startStopBtn:hover{
  243. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  244. }
  245. #startStopBtn.running{
  246. background-color:#FF3030;
  247. border-color:#FF6060;
  248. color:#FFFFFF;
  249. }
  250. #startStopBtn:before{
  251. content:"Start";
  252. }
  253. #startStopBtn.running:before{
  254. content:"Abort";
  255. }
  256. #serverArea{
  257. margin-top:1em;
  258. }
  259. #server{
  260. font-size:1em;
  261. padding:0.2em;
  262. }
  263. #test{
  264. margin-top:2em;
  265. margin-bottom:12em;
  266. }
  267. div.testArea{
  268. display:inline-block;
  269. width:16em;
  270. height:12.5em;
  271. position:relative;
  272. box-sizing:border-box;
  273. }
  274. div.testArea2{
  275. display:inline-block;
  276. width:14em;
  277. height:7em;
  278. position:relative;
  279. box-sizing:border-box;
  280. text-align:center;
  281. }
  282. div.testArea div.testName{
  283. position:absolute;
  284. top:0.1em; left:0;
  285. width:100%;
  286. font-size:1.4em;
  287. z-index:9;
  288. }
  289. div.testArea2 div.testName{
  290. display:block;
  291. text-align:center;
  292. font-size:1.4em;
  293. }
  294. div.testArea div.meterText{
  295. position:absolute;
  296. bottom:1.55em; left:0;
  297. width:100%;
  298. font-size:2.5em;
  299. z-index:9;
  300. }
  301. div.testArea2 div.meterText{
  302. display:inline-block;
  303. font-size:2.5em;
  304. }
  305. div.meterText:empty:before{
  306. content:"0.00";
  307. }
  308. div.testArea div.unit{
  309. position:absolute;
  310. bottom:2em; left:0;
  311. width:100%;
  312. z-index:9;
  313. }
  314. div.testArea2 div.unit{
  315. display:inline-block;
  316. }
  317. div.testArea canvas{
  318. position:absolute;
  319. top:0; left:0; width:100%; height:100%;
  320. z-index:1;
  321. }
  322. div.testGroup{
  323. display:block;
  324. margin: 0 auto;
  325. }
  326. #shareArea{
  327. width:95%;
  328. max-width:40em;
  329. margin:0 auto;
  330. margin-top:2em;
  331. }
  332. #shareArea > *{
  333. display:block;
  334. width:100%;
  335. height:auto;
  336. margin: 0.25em 0;
  337. }
  338. #privacyPolicy{
  339. position:fixed;
  340. top:2em;
  341. bottom:2em;
  342. left:2em;
  343. right:2em;
  344. overflow-y:auto;
  345. width:auto;
  346. height:auto;
  347. box-shadow:0 0 3em 1em #000000;
  348. z-index:999999;
  349. text-align:left;
  350. background-color:#FFFFFF;
  351. padding:1em;
  352. }
  353. a.privacy{
  354. text-align:center;
  355. font-size:0.8em;
  356. color:#808080;
  357. padding: 0 3em;
  358. }
  359. div.closePrivacyPolicy {
  360. width: 100%;
  361. text-align: center;
  362. }
  363. div.closePrivacyPolicy a.privacy {
  364. padding: 1em 3em;
  365. }
  366. @media all and (max-width:40em){
  367. body{
  368. font-size:0.8em;
  369. }
  370. }
  371. div.visible{
  372. animation: fadeIn 0.4s;
  373. display:block;
  374. }
  375. div.hidden{
  376. animation: fadeOut 0.4s;
  377. display:none;
  378. }
  379. @keyframes fadeIn{
  380. 0%{
  381. opacity:0;
  382. }
  383. 100%{
  384. opacity:1;
  385. }
  386. }
  387. @keyframes fadeOut{
  388. 0%{
  389. display:block;
  390. opacity:1;
  391. }
  392. 100%{
  393. display:block;
  394. opacity:0;
  395. }
  396. }
  397. @media all and (prefers-color-scheme: dark){
  398. html,body,#loading{
  399. background:#202020;
  400. color:#F4F4F4;
  401. color-scheme:dark;
  402. }
  403. h1{
  404. color:#E0E0E0;
  405. }
  406. a{
  407. color:#9090FF;
  408. }
  409. #privacyPolicy{
  410. background:#000000;
  411. }
  412. #resultsImg{
  413. filter: invert(1);
  414. }
  415. }
  416. </style>
  417. <title>LibreSpeed</title>
  418. </head>
  419. <body onload="initServers()">
  420. <h1>LibreSpeed</h1>
  421. <div id="loading" class="visible">
  422. <p id="message"><span class="loadCircle"></span>Selecting a server...</p>
  423. </div>
  424. <div id="testWrapper" class="hidden">
  425. <div id="startStopBtn" onclick="startStop()"></div><br/>
  426. <a class="privacy" href="#" onclick="I('privacyPolicy').style.display=''">Privacy</a>
  427. <div id="serverArea">
  428. Server: <select id="server" onchange="s.setSelectedServer(SPEEDTEST_SERVERS[this.value])"></select>
  429. </div>
  430. <div id="test">
  431. <div class="testGroup">
  432. <div class="testArea2">
  433. <div class="testName">Ping</div>
  434. <div id="pingText" class="meterText" style="color:#AA6060"></div>
  435. <div class="unit">ms</div>
  436. </div>
  437. <div class="testArea2">
  438. <div class="testName">Jitter</div>
  439. <div id="jitText" class="meterText" style="color:#AA6060"></div>
  440. <div class="unit">ms</div>
  441. </div>
  442. </div>
  443. <div class="testGroup">
  444. <div class="testArea">
  445. <div class="testName">Download</div>
  446. <canvas id="dlMeter" class="meter"></canvas>
  447. <div id="dlText" class="meterText"></div>
  448. <div class="unit">Mbit/s</div>
  449. </div>
  450. <div class="testArea">
  451. <div class="testName">Upload</div>
  452. <canvas id="ulMeter" class="meter"></canvas>
  453. <div id="ulText" class="meterText"></div>
  454. <div class="unit">Mbit/s</div>
  455. </div>
  456. </div>
  457. <div id="ipArea">
  458. <span id="ip"></span>
  459. </div>
  460. <div id="shareArea" style="display:none">
  461. <h3>Share results</h3>
  462. <p>Test ID: <span id="testId"></span></p>
  463. <input type="text" value="" id="resultsURL" readonly="readonly" onclick="this.select();this.focus();this.select();document.execCommand('copy');alert('Link copied')"/>
  464. <img src="" id="resultsImg" />
  465. </div>
  466. </div>
  467. <a href="https://github.com/librespeed/speedtest">Source code</a>
  468. </div>
  469. <div id="privacyPolicy" style="display:none">
  470. <h2>Privacy Policy</h2>
  471. <p>This HTML5 speed test server is configured with telemetry enabled.</p>
  472. <h4>What data we collect</h4>
  473. <p>
  474. At the end of the test, the following data is collected and stored:
  475. <ul>
  476. <li>Test ID</li>
  477. <li>Time of testing</li>
  478. <li>Test results (download and upload speed, ping and jitter)</li>
  479. <li>IP address</li>
  480. <li>ISP information</li>
  481. <li>Approximate location (inferred from IP address, not GPS)</li>
  482. <li>User agent and browser locale</li>
  483. <li>Test log (contains no personal information)</li>
  484. </ul>
  485. </p>
  486. <h4>How we use the data</h4>
  487. <p>
  488. Data collected through this service is used to:
  489. <ul>
  490. <li>Allow sharing of test results (sharable image for forums, etc.)</li>
  491. <li>To improve the service offered to you (for instance, to detect problems on our side)</li>
  492. </ul>
  493. No personal information is disclosed to third parties.
  494. </p>
  495. <h4>Your consent</h4>
  496. <p>
  497. By starting the test, you consent to the terms of this privacy policy.
  498. </p>
  499. <h4>Data removal</h4>
  500. <p>
  501. If you want to have your information deleted, you need to provide either the ID of the test or your IP address. This is the only way to identify your data, without this information we won't be able to comply with your request.<br/><br/>
  502. Contact this email address for all deletion requests: <a href="mailto:PUT@YOUR_EMAIL.HERE">TO BE FILLED BY DEVELOPER</a>.
  503. </p>
  504. <br/><br/>
  505. <div class="closePrivacyPolicy">
  506. <a class="privacy" href="#" onclick="I('privacyPolicy').style.display='none'">Close</a>
  507. </div>
  508. <br/>
  509. </div>
  510. </body>
  511. </html>