Get Total Purchase Value

Get total purchase value from API and display it

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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