Last active
December 3, 2023 21:11
-
-
Save smarthall/5b01a396ff30921625b1ac7175842d10 to your computer and use it in GitHub Desktop.
TamperMonker UserScript to Export Amazon Transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Amazon Transaction Export to CSV | |
// @namespace http://www.danielhall.me/ | |
// @version 0.4 | |
// @description Adds a link to Amazon to export transactions as a CSV for import into YNAB | |
// @updateURL https://gist.github.com/smarthall/5b01a396ff30921625b1ac7175842d10/raw/amzn-txn-export-csv.user.js | |
// @downloadURL https://gist.github.com/smarthall/5b01a396ff30921625b1ac7175842d10/raw/amzn-txn-export-csv.user.js | |
// @author Daniel Hall <[email protected]> | |
// @match https://www.amazon.com.au/cpe/yourpayments/transactions | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=amazon.com.au | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var csv = "Date,Payee,Memo,Amount\n" | |
const transactionElements = document.querySelector('form.a-spacing-none').getElementsByClassName('apx-transaction-date-container'); | |
for (const d of transactionElements) { | |
const date = new Date(d.firstChild.innerText); | |
const dateString = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate(); | |
const txnContainers = d.nextSibling.querySelectorAll('div.apx-transactions-line-item-component-container'); | |
for (const t of txnContainers) { | |
const id = t.querySelector('a.a-link-normal').innerText; | |
const price = t.querySelector('div.a-text-right.a-span-last').firstChild.innerText.replace('$', ''); | |
csv += dateString + ",Amazon,\"" + id + "\"," + price + "\n"; | |
} | |
} | |
const heading = document.querySelector('h1.a-spacing-small.a-text-bold'); | |
const element = document.createElement('a'); | |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(csv)); | |
element.setAttribute('download', 'amazon-export.csv'); | |
element.innerText = 'Download CSV'; | |
heading.insertAdjacentElement('afterend', element); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment