INGDirectElectricOrange

By Phillip Roberts Last update May 31, 2009 — Installed 159 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

There are 9 previous versions of this script.

// ==UserScript==

// @name           INGDirectElectricOrange

// @namespace      com.phillroberts.greasemonkey.scripts

// @description    Enhancements to the Electric Orange UI

// @include        https://secure.ingdirect.com/myaccount/INGDirect.html?command=displayAccountDetails*

// @include        http://home.ingdirect.com/

// @require       http://code.jquery.com/jquery-latest.min.js

// ==/UserScript==



phillroberts = {};

phillroberts.ingdirect = function()

{           

	var updateNavigationEvents = function()

	{

		var backLink = $("img[src*='back.gif']").parent().click(gotoPage);		    

		var nextLink = $("img[src*='next.gif']").parent().click(gotoPage);	
		

	};   

	

	var addCollapsibleEvents = function()

	{
		var history = $("table:contains('History'):last");
		if(history.length > 0)
		{
			$(history).css({'cursor':'pointer'}).click(function(){
				$(this).next().slideToggle();
			});
		}

		var pending = $("table:contains('Pending and On Hold')");
		if(pending.length > 0)
		{
			$(pending).css({'cursor':'pointer'}).click(function(){
				$(this).next().slideToggle();
			});

		}

		var scheduled = $("table:contains('Scheduled'):last");
		if(scheduled.length > 0)
		{
			$(scheduled).css({'cursor':'pointer'}).click(function(){
				$(this).next().slideToggle();
			});

		}
		

	}                                  		   

	var format = function(strValue)

    {

        var regex = new RegExp("(-?[0-9]+)([0-9]{3})"); 		        

    	while (regex.test(strValue)) {

    		strValue = strValue.replace(regex, "$1,$2");			

    	}


    	return strValue;

    };

    

    var displayAccountDetails = function()

	{   			

		var rows = $("img[src*='go_but.gif']").parent().parent().parent();	

		$(rows).find("td:first").html(" ");		

						

		// Fix up ING's colspan attributes and add the new Available balance column								

		var headerRows = $(rows[0]).siblings().slice(0,3);

		var fixTheseRows = headerRows.slice(0,2);			

		fixTheseRows.each(function(i,e){

			var col = $(e).children()[0];

			$(col).attr('colspan',7);				

		});

		

		// Add the Available Balance column

		var deleteColumn = $(headerRows[2]).find("th:last");

		deleteColumn.clone(true).html("Available Balance").insertAfter(deleteColumn);			

        

		// Get the balance/pending information

		var balanceInfo = $("td:contains('Balance')").slice(3).find("td:contains('$')").slice(0,3);

		var balance = $(balanceInfo[2]).text();						

		var overdraft = balance.indexOf(")") > -1 ? true : false;

		var availableBalance = parseFloat(balance.replace(/[^0-9.]/g, ""));

		availableBalance = (overdraft ? availableBalance * (-1) : availableBalance);			
		var deposit = location.href.indexOf('deposit=') > -1 ? location.href.split('deposit=')[1] : 0;
		availableBalance += parseFloat(deposit);

        var total = 0;	        

        

        rows.each(function(i,e){

	        var amountEl = $(e).find("td:eq(4)");

	        var amount = amountEl.text();

	        var mult = amount.indexOf(")") > -1 ? -1 : 1;

	        amount = parseFloat(amount.replace(/[^0-9.]/g, "")) * mult;

	        total += amount;

	        

	        var newBal = availableBalance + total;

	        var displayVal = newBal.toFixed(2);

	        displayVal = (newBal < 0 ? "(" + displayVal * -1 + ")" : displayVal) + '';

	        displayVal = format(displayVal);

	        var lastEl = $(e).find("td:last");		        

	        var newBalTd = $(amountEl).clone(true).html(displayVal).insertAfter(lastEl).css({'font-weight':'bold'});

	        

	        if(newBal < 0)

	        {

		        $(newBalTd).parent().find("td a").css({'color':'white'});

		        $(newBalTd).parent().css({'background-color':'red','color':'#FFFFFF'});				        

	        }

	    });	

	    

	    updateNavigationEvents();	 

	    addCollapsibleEvents();

	  

	};

	

	var viewMyAccount = function()

	{

		var myaccount = $('a[href*="myaccount"]').attr("href");	        

		location.replace(myaccount);

	};

	

	var gotoPage = function(evt)

	{

		var url = evt.currentTarget.href;

		$("table:contains('History'):last").next().fadeTo("normal",.2);

		console.log(url);

		// load the page via an ajax call and populate the appropriate area of the page.

		$.get(url, function(data){

		  var history = $(data).find("table:contains('History'):last").next();	

		  $("table:contains('History'):last").next().replaceWith(history);		  

		  
// update buttons

		  var buttons = $(data).find("img[src*='next.gif']").parent().parent().parent();

		  $("img[src*='next.gif']").parent().parent().parent().replaceWith(buttons);

		  updateNavigationEvents();

		  $("#tooltip table:contains('History'):last").next().show();		  

		});		

		return false;

		

	};		

	

	return {

		// public stuff here

		init:function()

		{			

		    var loc = window.location.href;		    

			if (loc.indexOf("displayAccountDetails") > -1) 

			{					

				displayAccountDetails();	

			}

			else

			{

				viewMyAccount();

			}						

		},

		DisplayAccountDetails:displayAccountDetails,

		ViewMyAccount:viewMyAccount

	};

}();



phillroberts.ingdirect.init();