Sunday, June 26, 2005

AJAX, GreaseMonkey, Bloglines and Firefox

Yes, I confess, this post's title will bring me a lot of traffic due to its high profile words. I say, bring 'em on!

After that said, I've been playing around with Greasemonkey lately, looking to see what all the hype was about.

The cool thing about Greasemonkey is how easy the scripts are to write and how it opens the door for anyone who can do simple javascript to tweak things that bother them.

One thing that bothers me about Bloglines is that it doesn't show the number of unread items in the title like GMail does. I leave GMail and Bloglines open all the time in tabs, so it would be convenient if I could just look at the titles to see if I should switch over and pay attention to them.

I looked in the greasemonkey script repositories, but I couldn't find this tweak :(

So I set out to write a Greasemonkey script to fix this annoyance. You can do Ajax stuff with Greasemonkey via the GM_xmlhttprequest function, so I combined that with the Bloglines API for getting the number of unread items.

and voila, here it is:

// ==UserScript==
// @name Bloglines Unread Items Title
// @namespace http://rodolforuiz.blogspot.com
// @include http://bloglines.com/*
// @include http://www.bloglines.com/*
// ==/UserScript==
(function() {
GM_xmlhttpRequest({
method: 'GET',
url: 'http://rpc.bloglines.com/update?user=email@email.com&ver=1', onload: function(changeTitle) {
var unreadItems='';
var i=1;
while (changeTitle.responseText.charAt(i) != '|') {
unreadItems = unreadItems + changeTitle.responseText.charAt(i);
i++;
}
if (unreadItems == '0') top.document.title = 'Bloglines';
else top.document.title = 'Bloglines (' + unreadItems + ')'; }
});
})();

Note, you must edit this script to input your email address.

If you happen to have a + or special character in your email address, you'll have to URL encode it.

Please, let me know if it worked for you or any other enhancement that you code yourself. Remember, thsi script is GNU protected - meaning, copy it and do to it whatever your will is :)

0 Comments:

Post a Comment

<< Home