Twitter Stats using Greasemonkey & jQuery
1 min read

I wrote a simple Greasemonkey script that uses jQuery to read the Following, Followers, and Updates count from your Twitter Home page and displays them in the title of your Firefox tab (as seen in the image to the left).

Since I enjoy using jQuery, I tend to use this script as the starting point for several other of my custom Greasemoney scripts.

You can install the following Greasemonkey script from the userscripts.org website.

// ==UserScript==
// @name           Twitter Stats
// @namespace      //zi.ma/webdev
// @description    Display your Twitter Stats in the Tab Title
// @include        //twitter.com/home
// ==/UserScript==

//BEGIN - Load jQuery//is.gd/j6G
var GM_JQ = document.createElement('script');
GM_JQ.src = '//jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

function GM_wait() {
   if (typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
   else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
//END - Load jQuery //is.gd/j6G

// All your GM code must be inside this function
function letsJQuery() {
   unsafeWindow.console.log('BEGIN letsJQuery');

   var followers = $("#follower_count").html();
   var following = $("#following_count").html();
   var updates = $("#update_count").html();
   document.title = 'Twitter / Ing: ' + $.trim(following) + '; Ers: ' + $.trim(followers);

   unsafeWindow.console.log('END letsJQuery');
}

unsafeWindow.alert = function alert(message) {
   //do nothing
};

The above script first loads the jQuery framework and then retrieves the Twitter values.

You might notice the use of unsafeWindow.console.log('Your message here...');

I mainly used this to help debug the script.

You can find these messages displayed in your Firebug console.

Once you have installed the script, it could be easily be coupled with the ReloadEvery firefox extension so that you can sit back and watch your stats update to your heart's content :)

Edit post on GitHub


ASP.NET MVC 1.0 RTM, Source, Docs, Videos, and More
Screencast: Dive Into ASP.NET MVC RC2