Skip to content

Instantly share code, notes, and snippets.

@jorgenpt
Last active August 29, 2015 14:26
Show Gist options
  • Save jorgenpt/ddf70d3e44fb2ca1c463 to your computer and use it in GitHub Desktop.
Save jorgenpt/ddf70d3e44fb2ca1c463 to your computer and use it in GitHub Desktop.
// To be run on https://store.steampowered.com/account/history/
function parseTotals()
{
var transactions = document.getElementsByClassName('wallet_table_row');
var totals = { usd: 0, eur: 0 };
for (var i = 0; i < transactions.length; ++i)
{
var transaction = transactions[i];
var items = transaction.getElementsByClassName('wht_items')[0];
if (items && items.innerText.indexOf('Wallet Credit') >= 0)
continue;
var total = transaction.getElementsByClassName('wht_total')[0];
if (!total)
continue;
total = total.innerText.strip();
if (total[0] == '$')
{
total = total.substr(1);
totals.usd += parseFloat(total);
}
else if (total[total.length - 1] == '€')
{
total = total.replace(',', '.').substr(0, total.length - 1);
totals.eur += parseFloat(total);
}
}
return totals;
}
function printTotals()
{
var loadMore = document.getElementById('load_more_button');
if (loadMore && loadMore.style.display !== 'none')
{
loadMore.click();
console.log("Loading more transactions first...");
setTimeout(printTotals, 2000);
return;
}
var historyLoading = document.getElementById('wallet_history_loading');
if (historyLoading && historyLoading.style.display !== 'none')
{
console.log("Waiting for transaction loading to finish...");
setTimeout(printTotals, 2000);
return;
}
var totals = parseTotals()
if (totals.usd > 0)
console.log("USD: $" + totals.usd.toFixed(2));
if (totals.eur > 0)
console.log("EUR: " + totals.eur.toFixed(2) + "€");
}
printTotals();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment