Get Total Purchase Value

Get total purchase value from API and display it

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Get Total Purchase Value
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Get total purchase value from API and display it
// @author       You
// @match        https://*.battle.net/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    // Create button
    var button = document.createElement('button');
    button.textContent = 'Get Total Purchase Value';
    document.body.appendChild(button);

    // Create text element to display total value
    var totalValueText = document.createElement('p');
    document.body.appendChild(totalValueText);

    // Add click event listener to button
    button.addEventListener('click', function() {
        GM_xmlhttpRequest({
            method: 'GET',
            url: 'https://account.battle.net/api/transactions?regionId=2',
            onload: function(response) {
                var data = JSON.parse(response.responseText);
                var purchases = data['purchases'];
                var totalValue = 0;

                // Loop through purchases and add up total value
                for (var i = 0; i < purchases.length; i++) {
                    totalValue += purchases[i]['total'].value;
                    console.log(purchases[i]['total'].value);
                }

                // Display total value
                totalValueText.textContent = 'Total Purchase Value: ' + totalValue;
            }
        });
    });
})();