Ping Counter

Optimized Ping Counter for Bloxd.io

  1. // ==UserScript==
  2. // @name Ping Counter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Optimized Ping Counter for Bloxd.io
  6. // @author Ankit
  7. // @match https://bloxd.io
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. class PingCounter {
  16. constructor(url) {
  17. this.url = url;
  18. this.lastPing = null;
  19.  
  20. this.display = document.createElement('div');
  21. this.display.id = 'pingDisplay';
  22. this.display.textContent = 'Ping: ...';
  23.  
  24. Object.assign(this.display.style, {
  25. position: 'fixed',
  26. top: '10px',
  27. left: '50%',
  28. transform: 'translateX(-50%)',
  29. padding: '8px 12px',
  30. backgroundColor: 'rgba(0, 0, 0, 0.7)',
  31. color: '#fff',
  32. borderRadius: '6px',
  33. fontSize: '16px',
  34. fontFamily: 'monospace',
  35. zIndex: 1000
  36. });
  37.  
  38. document.body.appendChild(this.display);
  39. }
  40.  
  41. ping() {
  42. const start = performance.now();
  43. fetch(this.url, { method: 'HEAD', mode: 'no-cors', cache: 'no-store' })
  44. .then(() => {
  45. const ping = Math.round(performance.now() - start);
  46. if (ping !== this.lastPing) {
  47. this.display.textContent = `Ping: ${ping} ms`;
  48. this.lastPing = ping;
  49. }
  50. })
  51. .catch(() => {
  52. this.display.textContent = 'Ping: Failed';
  53. });
  54. }
  55.  
  56. start(interval = 1500) {
  57. this.ping();
  58. this.timer = setInterval(() => this.ping(), interval);
  59. }
  60. }
  61.  
  62. // Initialize and start pinging every 1.5 seconds
  63. const counter = new PingCounter('https://bloxd.io');
  64. counter.start(1500);
  65. })();