Ping Counter

Ping Counter for Bloxd.io

  1. // ==UserScript==
  2. // @name Ping Counter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 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. class PingCounter {
  13. constructor(url) {
  14. this.url = url;
  15. this.pingCount = 0;
  16.  
  17. // Create an element to display ping time
  18. this.pingTimeDisplay = document.createElement('div');
  19. this.pingTimeDisplay.id = 'pingTimeDisplay';
  20. this.pingTimeDisplay.innerText = 'Ping : ';
  21.  
  22. // Style the ping time display
  23. this.pingTimeDisplay.style.position = 'fixed'; // Fix position
  24. this.pingTimeDisplay.style.top = '10px'; // Distance from the top
  25. this.pingTimeDisplay.style.left = '50%'; // Center horizontally
  26. this.pingTimeDisplay.style.transform = 'translateX(-50%)'; // Adjust for center alignment
  27. this.pingTimeDisplay.style.padding = '10px'; // Padding for better spacing
  28. this.pingTimeDisplay.style.backgroundColor = 'rgba(0, 0, 0, 0.7)'; // Semi-transparent background
  29. this.pingTimeDisplay.style.color = 'white'; // Text color
  30. this.pingTimeDisplay.style.borderRadius = '5px'; // Rounded corners
  31. this.pingTimeDisplay.style.fontSize = '20px'; // Font size
  32. this.pingTimeDisplay.style.zIndex = '1000'; // Ensure it's above other content
  33.  
  34. // Append the element to the body
  35. document.body.appendChild(this.pingTimeDisplay);
  36. }
  37.  
  38. ping() {
  39. const start = new Date().getTime();
  40. fetch(this.url, { method: 'HEAD', mode: 'no-cors' })
  41. .then(() => {
  42. const end = new Date().getTime();
  43. const pingTime = end - start;
  44.  
  45. // Update ping time on screen
  46. this.pingTimeDisplay.innerText = `Ping : ${pingTime} ms`;
  47. this.pingCount++;
  48. })
  49. .catch((error) => {
  50. console.error('Ping failed:', error);
  51. });
  52. }
  53.  
  54. startPinging(interval) {
  55. this.ping();
  56. setInterval(() => this.ping(), interval);
  57. }
  58. }
  59.  
  60. // Usage
  61. const pingCounter = new PingCounter('https://bloxd.io');
  62. pingCounter.startPinging(1500); // Ping every 1.5 seconds