Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export 28degress master card transactions to CSV

export-28deg.js

Export 28degress master card transactions to CSV

  1. Visit 28 degress transactions page
  2. Open Developer Console
  3. Paste code
  4. Press enter
(async()=>{
const all = document.querySelectorAll.bind(document);
const one = (s,e=document)=>e.querySelector(s);
const byname = (n,e=document)=>one(`[name=${n}]`, e);
const text = (e,s)=>{
const c = e.querySelector(s);
if (c) {
return c.textContent;
}
return null;
}
const hidden = e=>e.style.visibility === "hidden";
const getTransactions = ()=>{
const trs = all("[name=DataContainer]");
return Array.from(trs).map(tr=>({
date: text(tr, "[name=Transaction_TransactionDate]"),
description: text(tr, "[name=Transaction_TransactionDescription]"),
amount: text(tr, "[name=Transaction_Amount]"),
})).filter(row => row.date && row.amount);
}
window.getTransactions = getTransactions;
const hash = ()=>{
return JSON.stringify(getTransactions());
}
const dl = contents=>{
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([contents],{
type: 'text/csv'
}));
a.download = 'export.csv';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
const sleep = ms=>new Promise(d=>setTimeout(d, ms));
const wait = async()=>{
const h0 = hash();
for (let i = 0; i < 100; i++) {
await sleep(100);
const h1 = hash();
if (h0 === h1) {
continue;
}
return true;
}
throw `no change`;
}
;
const first = byname("firstButton");
if (!hidden(first)) {
first.click();
await wait();
console.log("reset");
}
let tx = [];
while (true) {
const page = getTransactions();
tx = tx.concat(page);
console.log(tx.length);
if(hidden(byname("lastButton"))) {
break;
}
byname("nextButton").click();
await wait();
}
console.log(tx.length, "done");
const csv =
"Date,Description,Amount\n"+
tx.map(row => {
return [row.date, row.description, row.amount]
.map(v => `"${v}"`)
.join(",");
}).join("\n");
//finally
dl(csv);
})().catch(err => console.error("ERR",err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment