Get Total Purchase Value

Get total purchase value from API and display it

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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