Twitter Stats using Greasemonkey & jQuery

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 website.

// ==UserScript==
// @name Twitter Stats
// @namespace
// @description Display your Twitter Stats in the Tab Title
// @include
// ==/UserScript==

//BEGIN - Load jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = '';
GM_JQ.type = 'text/javascript';

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

// 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 :)