Money Value Display 2.0

Money Value display

// ==UserScript==
// @name         Money Value Display 2.0
// @namespace    Madwolf
// @version      1.2
// @description  Money Value display
// @author       MadWolf [376657]
// @license      MadWolf [376657]
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @include      https://www.torn.com/*
// @exclude      https://www.torn.com/war.php?step=rankreport&rankID=*
// @exclude      https://www.torn.com/page.php?sid=points
// @exclude      https://www.torn.com/factions.php?step=your&type=1#/war/rank
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle changes in player scores
    function handleScoreChanges(mutationsList) {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                // Handle changes to player scores here
                // You might want to check if the relevant elements have been added or modified
                // and perform actions accordingly.
                console.log('Player scores have changed!');
                // Add your code to update the scores or perform other actions
            }
        }
    }

    // Create a Mutation Observer
    const observer = new MutationObserver(handleScoreChanges);

    // Options for the observer (configure as needed)
    const observerConfig = { childList: true, subtree: true };

    // Start observing the target node for changes
    const targetNode = document.getElementById('your-target-node-id'); // Replace with the actual ID
    if (targetNode) {
        observer.observe(targetNode, observerConfig);
    } else {
        console.error("TM script => Target node not found.");
    }

    // The rest of your script...

    var formatter = new Intl.NumberFormat('en-US', {
        style: 'currency',
        currency: 'USD',
        maximumFractionDigits: 0
    });

    // Example AJAX request (replace with your actual logic)
    $.ajax({
        url: 'https://api.torn.com/user',
        data: {
            selections: 'money',
            key: 'API KEY IN THIS'
        },
        beforeSend: function () {
            // Show loader or perform any necessary actions before the request
        },
        success: function (data) {
            var money = data;
            console.log("Vault amount: " + money.vault_amount);
            console.log("Cayman bank money: " + money.cayman_bank);
            console.log("Company funds: " + money.company_funds);

            // Display user and company data under Points.
            var resultsDiv = $(`
                <div class="point-block___to3YE" style="white-space: nowrap; font-size: 10pt; font-weight: bold">
                    ${money.vault_amount !== null && money.vault_amount !== 0 ? `
                    <div style="margin-top: 3px;">
                        <span>Vault: </span>
                        <span style="font-size: 10pt; color: green; font-weight: bold;">${formatter.format(money.vault_amount)}</span>
                    </div>` : ''}
                    ${money.cayman_bank !== 0 ? `
                    <div style="margin-top: 3px;">
                        <span>Cayman: </span>
                        <span style="font-size: 10pt; color: green; font-weight: bold;">${formatter.format(money.cayman_bank)}</span>
                    </div>` : ''}
                    ${money.company_funds !== 0 ? `
                    <div style="margin-top: 3px;">
                        <span>Company: </span>
                        <span style="font-size: 10pt; color: green; font-weight: bold;">${formatter.format(money.company_funds)}</span>
                    </div>` : ''}
                </div>
            `);

            var targetNode = $('div[class^=points]');
            if (targetNode.length)
                targetNode.append(resultsDiv);
            else
                console.error("TM script => Target node not found.");
        },
        complete: function () {
            // Perform any actions after the request is complete
        },
        error: function () {
            console.log('There was an error. Please try again.');
        }
    });

    GM_addStyle(`
        .tmJsonMashupResults {
            color: black;
            background: #f9fff9;
            margin-top: 10px;
            padding: 1.4ex 1.3ex;
            border: 1px double gray;
            border-radius: 1ex;
        }
    `);

})();