This script calculates your spent on amazon. Follow the instructions and run on the console of your browser's inspector tools. Currently supports € and £, calculates in POUNDS. Make sure to update the exchange rate.
- Navigate to https://www.amazon.co.uk/cpe/yourpayments/transactions
- Open developer tools, go to console and run:
function sumCurrentPage() {
const table = $('.a-box-inner.a-padding-none');
return Array
.from(table.querySelectorAll('.a-column:nth-of-type(2) > span'))
.map(v => {
if (v.innerHTML.indexOf('£')) {
return Number.parseFloat(v.innerHTML.replace('£', '')) || 0;
}
else if (v.innerHTML.indexOf('EUR')) {
return (Number.parseFloat(v.innerHTML.replace('EUR ', '')) || 0) * 0.863816;
}
return 0;
})
.filter(v => !!v)
.reduce((total, v) => total - v, 0);
}
(async () => {
const sleep = (ms) => new Promise((resolve) => window.setTimeout(resolve, ms));
let previous = Array.from(document.querySelectorAll('span')).find(el => el.textContent.toLowerCase().includes('previous page')).querySelector('input');
while(previous) {
previous.click();
await sleep(2000);
previous = Array.from(document.querySelectorAll('span')).find(el => el.textContent.toLowerCase().includes('previous page')).querySelector('input');
}
let total = sumCurrentPage();
let next = Array.from(document.querySelectorAll('span')).find(el => el.textContent.toLowerCase().includes('next page')).querySelector('input');
while(next) {
next.click();
await sleep(2000);
next = Array.from(document.querySelectorAll('span')).find(el => el.textContent.toLowerCase().includes('next page')).querySelector('input');
total += sumCurrentPage();
}
console.log(`Total spent: £${Math.ceil(total)}`);
})();