index-classic.html 16 KB

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