Displaycase Value

Display the total value of items in the displaycase

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Displaycase Value
// @namespace    com.torn.GamingAnonymous
// @version      1.1
// @description  Display the total value of items in the displaycase
// @author       GamingAnonymous
// @match        *.torn.com/displaycase.php*
// @grant        none
// ==/UserScript==

// Your API Key
var apiKey = "yourAPIKey";
var worthTotal = 0;

(function() {
    'use strict';
    console.log("API Key: " + apiKey);

    // get the ID of the displaycase you are currently viewing
    let currentPage = window.location.href;
    let urlElements = currentPage.split('/');
    let currentPageUserID = urlElements[urlElements.length - 1];
    console.log(currentPageUserID);

    // Get the information from the API for this displaycase
    let url = 'https://api.torn.com/user/' + currentPageUserID + '?selections=display&key=' + apiKey;
    fetch(url)
        .then(res => res.json())
        .then((out) => {
        for(let i = 0; i < out.display.length; i++)
        {
            // Add up the worth of the items
            worthTotal += out.display[i].market_price;
        }

        // Display the worth formatted with commas
        window.alert("This display case is worth: $" + worthTotal.toLocaleString(undefined));
    })
    .catch(err => console.error(err));
})();