index.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <html>
  2. <head>
  3. <script src="superagent.js"></script>
  4. <style>
  5. body {
  6. font-family: Helvetica;
  7. }
  8. .status {
  9. font-size: 22px;
  10. }
  11. .fail {
  12. color: red;
  13. }
  14. .success {
  15. color: green;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <center>
  21. <h1> Network Status </h1>
  22. <p>Success rate to Google: <span id="successRateGoogle" class="status">0</span></p>
  23. <p>Success rate to local router: <span id="successRateRouter" class="status">0</span></p>
  24. </center>
  25. <script>
  26. function update(elem, data) {
  27. var rate = (100 * (data.successCount / data.tests)).toFixed(2);
  28. elem.innerText = rate + '%';
  29. if (rate < 90) {
  30. elem.classList.add('fail');
  31. elem.classList.remove('success');
  32. } else {
  33. elem.classList.remove('fail');
  34. elem.classList.add('success');
  35. }
  36. }
  37. function fetch() {
  38. superagent.get('/status', function (error, result) {
  39. if (error) {
  40. setTimeout(fetch, 1000);
  41. return console.error(error);
  42. }
  43. update(document.getElementById('successRateGoogle'), result.body.google);
  44. update(document.getElementById('successRateRouter'), result.body.router);
  45. setTimeout(fetch, 500);
  46. });
  47. }
  48. fetch();
  49. </script>
  50. </body>
  51. </html>