Order Accounts by Balance

Edit 4/8:  The steps below are now obsolete. I have created a Chrome  Extension that does the account sorting automatically and adds a lot more functionality to Mint. See this post for more details. Original post follows:

After Mint.com broke the account sorting functionality for the second time in less than a year I decided to take matters into my own hands.  I wrote a small Javascript snippet that reorders accounts by balance on the fly. The neat thing is that everything is done client-side (I’m simply reordering the page markup), so your account information is safe. I developed/tested this using Chrome but it also works in Firefox. If you like this post consider making a donation .

Steps

  1. On your computer login to Mint.com as you usually do.
  2. Once you are logged in your URL should be something like https://wwws.mint.com/overview.event.
  3. Press F12, this should bring up the Javascript Console.
  4. Copy and paste the following text snippet  and hit enter:
javascript:(YUI().use("*",function(e){e.all("li.moduleAccount").each(function(e,t,n){var r=[];e.all("li.accounts-data-li").each(function(e){r.push(e.cloneNode(true))});r.sort(function(e,t){var n=e.one("span.balance").get("text");var r=t.one("span.balance").get("text");var i=Number(n.replace(/[^-0-9\.]+/g,""));var s=Number(r.replace(/[^-0-9\.]+/g,""));var o=i-s;return o});e.all("li.accounts-data-li").each(function(e){var t=r.pop().get("innerHTML");e.set("innerHTML",t)})})}))

The account balances should be reordered now. You can close the console again by pressing F12.

For reference below are two screenshots for Chrome/Firefox showing you where you need to paste this code. (Click on the thumbnails to see a larger image)

chrome

firefox

Other option is to create a shortcut on your bookmarks bar. Give it any title and on the URL address just paste the code there. Then you would click on your bookmarklet when you want to fix the account balance order. Edit:  If you don’t like having the Bookmarks bar visible here’s a good explanation about how to create a bookmarklet in Chrome for quick access. If you are a Firefox user you could setup a smart bookmark or creating a hotkey shortcut.

I’m also looking into possibly converting this script into a Chrome Extension / GreaseMonkey user script so that changes are applied automatically every time you visit the website.

Feel free to post a comment if you have any questions or suggestions. Below is an unminified/readable version of the code.

YUI().use('*', function (Y) {
    Y.all('li.moduleAccount').each(
     function (node, idx, lst) {
         var arr = [];
         //For each Account Section iterate through all the different accounts. 
         node.all("li.accounts-data-li").each(function (n) { arr.push(n.cloneNode(true)) });
         arr.sort(function (a, b) {
             //locate the HTML element that holds the balance for an account
             var currencyA = a.one("span.balance").get('text');
             var currencyB = b.one("span.balance").get('text');
             //Convert the balance to number that javascript can understand
             var keyA = Number(currencyA.replace(/[^-0-9\.]+/g, ""));
             var keyB = Number(currencyB.replace(/[^-0-9\.]+/g, ""));
             var result = keyA - keyB;
             return result;

         });
         //Replace markup with sorted accounts
         node.all("li.accounts-data-li").each(function (n) {
             var ordered = arr.pop().get('innerHTML');
             n.set("innerHTML", ordered);
         });
     }
   );
});

I provide this code under a BSD License.  Now buy me a beer 😉  Buy me a beer if you like this :)

Advertisements

14 comments

  1. I left a comment on the Mint website also but want to thank you again for taking the time and initiative to come up with a solution! Well done!

  2. I tried putting the code in a greasemonkey script and it doesn’t seem to work there. Also tried nesting inside YAHOO.util.Event.onDOMReady() without any luck. Any ideas?

    1. This sees to work as a greasemonkey script for a quick and dirty solution. It’s not ideal but gets the job done. The final number (2000) is the number of milliseconds to wait before sorting, if it’s not working for you increase the timeout.

      setTimeout(function() {
      YUI().use(‘*’, function (Y) {
      Y.all(‘li.moduleAccount’).each(
      function (node, idx, lst) {
      var arr = [];
      //For each Account Section iterate through all the different accounts.
      node.all(“li.accounts-data-li”).each(function (n) { arr.push(n.cloneNode(true)) });
      arr.sort(function (a, b) {
      //locate the HTML element that holds the balance for an account
      var currencyA = a.one(“span.balance”).get(‘text’);
      var currencyB = b.one(“span.balance”).get(‘text’);
      //Convert the balance to number that javascript can understand
      var keyA = Number(currencyA.replace(/[^-0-9\.]+/g, “”));
      var keyB = Number(currencyB.replace(/[^-0-9\.]+/g, “”));
      var result = keyA – keyB;
      return result;

      });
      //Replace markup with sorted accounts
      node.all(“li.accounts-data-li”).each(function (n) {
      var ordered = arr.pop().get(‘innerHTML’);
      n.set(“innerHTML”, ordered);
      });
      }
      );
      })}, 2000);

      1. Try pasting it into notepad and then copy it from notepad and paste it into grease monkey. That should clear everything except the text out of your clipboard.

  3. I’ll buy you a beer, but you gotta pay for that beer in Dogecoin. Let me know if you want some Dogecoin for your efforts

  4. Thanks for this, I use it EVERY time I log into mint!

    I bought you a beer 🙂

    Have you had any luck with the greasemonkey script or the chrome extension? Would definitely be willing to spend the .99 cents to buy this as an extension!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s