| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <html>
- <head>
- <script src="superagent.js"></script>
- <style>
- body {
- font-family: Helvetica;
- }
- .status {
- font-size: 22px;
- }
- .fail {
- color: red;
- }
- .success {
- color: green;
- }
- </style>
- </head>
- <body>
- <center>
- <h1> Network Status </h1>
- <p>Success rate to Google: <span id="successRateGoogle" class="status">0</span></p>
- <p>Success rate to local router: <span id="successRateRouter" class="status">0</span></p>
- </center>
- <script>
- function update(elem, data) {
- var rate = (100 * (data.successCount / data.tests)).toFixed(2);
- elem.innerText = rate + '%';
- if (rate < 90) {
- elem.classList.add('fail');
- elem.classList.remove('success');
- } else {
- elem.classList.remove('fail');
- elem.classList.add('success');
- }
- }
- function fetch() {
- superagent.get('/status', function (error, result) {
- if (error) {
- setTimeout(fetch, 1000);
- return console.error(error);
- }
- update(document.getElementById('successRateGoogle'), result.body.google);
- update(document.getElementById('successRateRouter'), result.body.router);
- setTimeout(fetch, 500);
- });
- }
- fetch();
- </script>
- </body>
- </html>
|