Displaycase Value

Display the total value of items in the displaycase

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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));
})();