Last active
April 6, 2017 20:41
-
-
Save macdonaldr93/4f22dafffc394a1c772b6d7da30aec66 to your computer and use it in GitHub Desktop.
Calculate the column total on the Capitol One Transactions & Details page
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
/** | |
* 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".'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Go to Transactions & Details in your Capitol One account page.