Furvilla - Commas pls

Comma seperates numbers across Furvilla

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Furvilla - Commas pls
// @namespace    furvilla
// @version      2023.01.02
// @description  Comma seperates numbers across Furvilla
// @match        *://*.furvilla.com/*
// @license      MIT
// @author       kiri
// ==/UserScript==
//Use at your own risk. No guarantees or waranties. Does not convert all numbers, but hopefully I got most of the important areas.


(function() {
    'use strict';

    // Function to add commas to a number
    function numberWithCommas(x) {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }

    function checkThenReplace(elem) {
        let number = parseInt(elem.textContent, 10);

            // Check if it's a valid number
            if (!isNaN(number)) {
                elem.textContent = numberWithCommas(number); // Setting formatted number
            }
    }

    // Sidebar on-hand FC, FD, inventory amounts
    let bElements1 = document.querySelectorAll('div.user-info strong:not(:has(a))');
    let bElements2 = document.querySelectorAll('div.user-info strong a');

    // Loop through all the selected elements
    for (let elem of bElements1) {
            checkThenReplace(elem);
    }
    for (let elem of bElements2) {
            checkThenReplace(elem);
    }

     // Bank page elements, Career page stats
    let divNums = document.querySelectorAll('div.registration-well div:not(.progress-text)');

    for (let elem of divNums) {
        const val = elem.innerHTML;
        const line = (val.trim()).split(" ");

        if (typeof line === "undefined" || typeof line[2] === "undefined") {
            checkThenReplace(elem);
        }
        else if (line[2].includes("furcash.gif") || line[2].includes("furdollars.gif")) {
             let number = parseInt(elem.textContent, 10);

            // Check if it's a valid number
            if (!isNaN(number)) {
                elem.innerHTML = numberWithCommas(number) + " " + line[1] + " " + line[2]; // Setting formatted number
            }
        }
    }


    //Stall net prices
    let stallNets = document.querySelectorAll('td.text-center span.net');

    // Loop through all the selected elements
    for (let elem of stallNets) {
            checkThenReplace(elem);
    }


     // Stall stuff
    let stallElements = document.querySelectorAll('td');

    for (let elem of stallElements) {
        const val = elem.innerHTML;
        const line = (val.trim()).split(" ");

        if (typeof line === "undefined" || typeof line[3] === "undefined") {
           checkThenReplace(elem);
        }
        else if(!isNaN(parseInt(line[0]))) {

            if(line[3].includes("furcoins.gif") || line[3].includes("furdollars.gif")) {
                elem.innerHTML = numberWithCommas(parseInt(line[0])) + " " + line[1] + " " + line[2] + " " + line[3]; // Setting formatted number
            } //why is stall till coded differently lol
            else if(line[2].includes("furcash.gif")) {
                elem.innerHTML = numberWithCommas(parseInt(line[0])) + " <img src='//furvilla.com/img/furcash.gif'>"; // Setting formatted number
            }
            else if(line[2].includes("furdollars.gif")) {
                elem.innerHTML = numberWithCommas(parseInt(line[0])) + " <img src='//furvilla.com/img/furdollars.gif'>"; // Setting formatted number
            }
        }

    }


})();