Kirka.io Comma's

Format numbers with commas as thousand separators

  1. // ==UserScript==
  2. // @name Kirka.io Comma's
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Format numbers with commas as thousand separators
  6. // @author Life.css
  7. // @license life.css - https://github.com/LifeCss
  8. // @match https://snipers.io/
  9. // @match https://kirka.io/
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=snipers.io
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to format numbers with commas
  18. function formatNumberWithCommas(number) {
  19. // Convert the number to a string
  20. let numStr = number.toString();
  21.  
  22. // Use regex to add commas as thousand separators
  23. return numStr.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  24. }
  25.  
  26. // Function to find and format all numbers in the DOM
  27. function formatAllNumbers() {
  28. // Get all text nodes in the document
  29. const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
  30. let node;
  31.  
  32. // Loop through all text nodes
  33. while (node = walker.nextNode()) {
  34. const text = node.nodeValue;
  35.  
  36. // Use regex to find numbers in the text
  37. const formattedText = text.replace(/\b\d{4,}\b/g, (match) => {
  38. return formatNumberWithCommas(match);
  39. });
  40.  
  41. // Update the text node if changes were made
  42. if (formattedText !== text) {
  43. node.nodeValue = formattedText;
  44. }
  45. }
  46. }
  47.  
  48. // Run the formatter when the page loads
  49. window.addEventListener('load', formatAllNumbers);
  50.  
  51. // Optional: Run the formatter periodically to handle dynamically loaded content
  52. setInterval(formatAllNumbers, 1000); // Check every second
  53. })();