Skip to content

Instantly share code, notes, and snippets.

@macdonaldr93
Last active April 6, 2017 20:41
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 macdonaldr93/4f22dafffc394a1c772b6d7da30aec66 to your computer and use it in GitHub Desktop.
Save macdonaldr93/4f22dafffc394a1c772b6d7da30aec66 to your computer and use it in GitHub Desktop.
Calculate the column total on the Capitol One Transactions & Details page
/**
* Calculate the column total on the Capitol One Transactions & Details page.
*
* Usage: Paste function into console. Then, run calculateTotalAmountOnPage() in console.
*
* @author https://github.com/macdonaldr93/
* @license GNU GPLv3
*/
function calculateTotalAmountOnPage() {
function stringToFloat(string) {
var noDecimal = string.replace(',', '');
var numbers = noDecimal.replace(/[^0-9,.-]*/gi, '');
return parseFloat(numbers);
}
function outputResultToConsole(result) {
var searchCriteria = $('#search_trans').val();
var message = null;
if (searchCriteria) {
message = 'The total spent on "' + searchCriteria + '" is $';
} else {
message = 'The total spent in this table is $';
}
console.info(message + parseFloat(totalSpent).toFixed(2));
}
var totalSpent = 0;
var $totalRows = $('.amount [bo-id="\'transaction.display.amount\' + transaction.displayId"]');
if ($totalRows.length > 0) {
$totalRows.each(function() {
var amount = stringToFloat($(this).text());
totalSpent += amount;
});
outputResultToConsole(totalSpent);
} else {
console.warn('No rows were found in table. Please make sure there are transactions under "Posted Transactions".');
}
}
@macdonaldr93
Copy link
Author

Usage

Go to Transactions & Details in your Capitol One account page.

http://g.recordit.co/lEik1O09re.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment