This script calculates your spent on twitch. Follow the instructions and run on the console of your browser's inspector tools. Currently supports €. Change it if your currency differs.
- Navigate to https://www.twitch.tv/wallet?tab=purchase-history
- Make sure the date range covers the period you want to calculate the spent on
- Open developer tools, go to console and run:
function sumCurrentPage(table) {
return Array
.from(table.querySelectorAll(".tw-table-cell:nth-of-type(4) > * p.CoreText-sc-cpl358-0"))
.map(v => Number.parseFloat(v.innerHTML.replace('€', '').replace('+', '-')))
.filter(v => !!v)
.reduce((total, v) => total + v, 0);
}
(async () => {
const table = $('table.tw-table > tbody.tw-table-body');
const previous = $('[data-test-selector=table-pagination__back-button]');
const next = $('[data-test-selector=table-pagination__next-button]');
const sleep = (ms) => new Promise((resolve) => window.setTimeout(resolve, ms));
while(!previous.disabled) {
previous.click();
await sleep(2000);
}
let total = sumCurrentPage(table);
while(!next.disabled) {
next.click();
await sleep(2000);
total += sumCurrentPage(table);
}
console.log('Total spent', Math.ceil(total));
})();