Skip to content

Instantly share code, notes, and snippets.

@luisfavila
Last active July 1, 2022 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisfavila/2c8eec6f7c472fbb773aa2a2a82c1f8c to your computer and use it in GitHub Desktop.
Save luisfavila/2c8eec6f7c472fbb773aa2a2a82c1f8c to your computer and use it in GitHub Desktop.
Calculate money spent on twitch

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.

  1. Navigate to https://www.twitch.tv/wallet?tab=purchase-history
  2. Make sure the date range covers the period you want to calculate the spent on
  3. 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));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment