Reddit Full Numbers

Replaces "k" abbreviations with full comma-separated numbers on Reddit for votes and comments

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Reddit Full Numbers
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Replaces "k" abbreviations with full comma-separated numbers on Reddit for votes and comments
// @author       Rehan Dilawar
// @license      MIT
// @icon         https://redditinc.com/hs-fs/hubfs/Reddit%20Inc/Content/Brand%20Page/Reddit_Logo.png
// @match        https://www.reddit.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const format = (n) => parseInt(n).toLocaleString();

    // Pierces through shadow roots to find the hidden faceplate-number elements
    const fixNumbersDeep = (root) => {
        // 1. Find all faceplate-number elements in the current root (light or shadow)
        const targets = root.querySelectorAll('faceplate-number[number]');
        targets.forEach(el => {
            const rawValue = el.getAttribute('number');
            if (rawValue) {
                const fullNum = format(rawValue);
                // Remove 'pretty' to stop Reddit from reverting the change
                if (el.hasAttribute('pretty')) el.removeAttribute('pretty');
                if (el.textContent !== fullNum) el.textContent = fullNum;
            }
        });

        // 2. Recursively find and enter all Shadow Roots of child elements
        const allElements = root.querySelectorAll('*');
        allElements.forEach(el => {
            if (el.shadowRoot) {
                fixNumbersDeep(el.shadowRoot);
            }
        });
    };

    // Robust observer to handle infinite scroll and dynamic Shadow DOM insertion
    const observer = new MutationObserver(() => {
        fixNumbersDeep(document.documentElement);
    });

    // Start watching immediately
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // Initial pass
    window.addEventListener('load', () => fixNumbersDeep(document.documentElement));
})();