Kirka.io Comma's

Format numbers with commas as thousand separators

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Kirka.io Comma's
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Format numbers with commas as thousand separators
// @author       Life.css 
// @license      life.css - https://github.com/LifeCss
// @match        https://snipers.io/
// @match        https://kirka.io/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=snipers.io
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to format numbers with commas
    function formatNumberWithCommas(number) {
        // Convert the number to a string
        let numStr = number.toString();

        // Use regex to add commas as thousand separators
        return numStr.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }

    // Function to find and format all numbers in the DOM
    function formatAllNumbers() {
        // Get all text nodes in the document
        const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
        let node;

        // Loop through all text nodes
        while (node = walker.nextNode()) {
            const text = node.nodeValue;

            // Use regex to find numbers in the text
            const formattedText = text.replace(/\b\d{4,}\b/g, (match) => {
                return formatNumberWithCommas(match);
            });

            // Update the text node if changes were made
            if (formattedText !== text) {
                node.nodeValue = formattedText;
            }
        }
    }

    // Run the formatter when the page loads
    window.addEventListener('load', formatAllNumbers);

    // Optional: Run the formatter periodically to handle dynamically loaded content
    setInterval(formatAllNumbers, 1000); // Check every second
})();