Skip to content

Instantly share code, notes, and snippets.

@spig
Last active December 23, 2016 16:54
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 spig/5d3e80b262b564e1e21ef0cfe79483eb to your computer and use it in GitHub Desktop.
Save spig/5d3e80b262b564e1e21ef0cfe79483eb to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Remove Kids Accounts from Total Balance
// @namespace http://stevespiga.rel.li/
// @version 0.2
// @description remove kid account balances from total balances - money and savings
// @author Steve Spigarelli
// @match https://secure.capitalone360.com/myaccount/banking/account_summary.vm
// @grant none
// ==/UserScript==
(function() {
'use strict';
var total = document.querySelector('#m_total_deposit');
var totalBalanceTD = total.querySelector('td.m_balance');
var totalAvailableTD = total.querySelector('td.m_available');
var totalBalance = getTotalBalance();
var totalAvailable = getTotalAvailableBalance();
function hasKidsAccount(element) {
var foundKidsAccount = false;
element.querySelectorAll('a').forEach(a => {
if (a.textContent.search(/Kids Saving/) !== -1 || a.textContent.search(/MONEY/) !== -1) {
foundKidsAccount = true;
}
});
return foundKidsAccount;
}
function getBalance(element) {
return Number.parseFloat(element.querySelector('td.m_balance > a').textContent.trim());
}
function getAvailable(element) {
return Number.parseFloat(element.querySelector('td.m_available > a').textContent.trim());
}
function adjustTotalBalance(amount) {
totalBalance = totalBalance + amount;
totalBalanceTD.textContent = totalBalance.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
function adjustAvailableBalance(amount) {
totalAvailable = totalAvailable + amount;
totalAvailableTD.textContent = totalAvailable.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
function getTotalBalance() {
var totalBalance = totalBalanceTD.textContent.trim();
var totalBalanceMatches = totalBalance.match(/[0-9,.]+/);
if (totalBalanceMatches.length > 0) {
totalBalance = totalBalanceMatches[0].replace(/,/, '');
}
return Number.parseFloat(totalBalance);
}
function getTotalAvailableBalance() {
var totalAvailable = totalAvailableTD.textContent.trim();
var totalAvailableMatches = totalAvailable.match(/[0-9,.]+/);
if (totalAvailableMatches.length > 0) {
totalAvailable = totalAvailableMatches[0].replace(/,/, '');
}
return Number.parseFloat(totalAvailable);
}
document.querySelectorAll('tr.m_item_deposit').forEach(e => {
if (hasKidsAccount(e)) {
adjustTotalBalance(-1 * getBalance(e));
adjustAvailableBalance(-1 * getAvailable(e));
//e.parentNode.removeChild(e);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment