Last active
April 1, 2018 14:39
-
-
Save strongriley/6a011ad49254b7dc5796515852aecebf to your computer and use it in GitHub Desktop.
Export Betterment Account Balances
This file contains hidden or 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
var search = $('h5.SummaryTable-label:contains("Balance")'); | |
var formatDate = function(date) { | |
return date.toISOString().substring(0, 10); | |
}; | |
var balances = search.map(function() { | |
var arr = $(this).parent().parent().find('.u-secondaryHeading').map(function() { | |
return $(this).text().trim().replace(/(Off|On) Track/, '').trim(); | |
}).get(); | |
var d = new Date(); | |
if ($(this).find('span').size() > 0) { | |
var relative = $(this).find('span').text(); | |
var relativeSearch = /(\d+) (month|day|hour|minute)s? ago/; | |
var match = relativeSearch.exec(relative); | |
var units = parseInt(match[1], 10); | |
switch(match[2]) { | |
case "hour": | |
d.setHours(d.getHours() - units); | |
break; | |
case "day": | |
d.setDate(d.getDate() - units); | |
break; | |
case "month": | |
d.setMonth(d.getMonth() - units); | |
break; | |
case "minute": | |
d.setMinutes(d.getMinutes() - units); | |
break; | |
default: | |
throw 'Unknown relative time: ' + match[2]; | |
} | |
} | |
arr.push(formatDate(d)); | |
// Nested to prevent flattening | |
return [arr]; | |
}).get(); | |
var text = balances.reduce(function(acc, currentValue) { | |
return acc + "\n" + currentValue.join('\t'); | |
}, ''); | |
copy(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment