Created
January 27, 2012 05:25
-
-
Save andrewroth/1687161 to your computer and use it in GitHub Desktop.
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 mint.com Net Total | |
// @description Shows net total on Transactions tab. | |
// @include https://wwws.mint.com/transaction.event* | |
// ==/UserScript== | |
window.addEventListener('load', function() { | |
//add commas between every 3 digits | |
var add_commas = function(nStr) { | |
nStr += ''; | |
x = nStr.split('.'); | |
x1 = x[0]; | |
x2 = x.length > 1 ? '.' + x[1] : ''; | |
var rgx = /(\d+)(\d{3})/; | |
while(rgx.test(x1)) { | |
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
} | |
return x1 + x2; | |
} | |
var sum_table_bank = function() { sum_total('account-table-all-bank'); setTimeout(sum_table_bank, 1500); } | |
var sum_table_cash = function() { sum_total('account-table-all-cashonly'); setTimeout(sum_table_cash, 1500); } | |
var sum_total = function(table_id) { | |
//add "Net Total" header | |
var totalTable = document.getElementById(table_id); | |
if (totalTable == null) { return; } | |
var tableHeaders = totalTable.firstChild; | |
var tableHeadersArray = tableHeaders.getElementsByTagName('th'); | |
tableHeadersArray[2].innerHTML = 'Net Total'; | |
if (document.getElementById('net_total') != null) { return; } | |
//add net total amount | |
var tableValues = tableHeaders.nextSibling; | |
var tableValuesArray = tableValues.getElementsByTagName('td'); | |
tableValuesArray[0].className = 'money'; | |
tableValuesArray[1].removeAttribute('colspan'); | |
var totalCash = tableValuesArray[0].innerHTML.replace('$', ''); | |
totalCash = totalCash.replace(',', ''); | |
var totalDebt = tableValuesArray[1].innerHTML.replace(',', ''); | |
totalDebt = totalDebt.substring(2); | |
var netTotal = document.createElement('td'); | |
netTotal.className = 'money large positive'; | |
netTotal.id = 'net_total'; | |
netTotal.innerHTML = '$' + add_commas((new Number(totalCash) - new Number(totalDebt)).toFixed(2)); | |
netTotal.setAttribute('colspan', '3'); | |
tableValues.appendChild(netTotal); | |
} | |
setTimeout(sum_table_bank, 1500); | |
setTimeout(sum_table_cash, 1500); | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment