Kirka.io Comma's

Format numbers with commas as thousand separators

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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
})();