Hacking Gmail

(Grace) #1

100 Part II — Getting Inside Gmail


Listing 6-1(continued)

}
if
(window.location.href==’http://gmail.google.com/gmail?logout&h
l=en’ || window.location.href.substr(0,57) ==
‘https://www.google.com/accounts/ServiceLogin?service=mail’ ){
//GM_log/gci(‘logout’);
GM_setValue(‘subs’,null);
GM_setValue(‘subs_update’,null);
GM_setValue(‘subs_cached_html’,null);
}else{
if(init()){
getsubs();
setInterval(checkifpresenthtml,1000);
}
}
})()

How It Works


Have a read through the preceding code. From the knowledge you have from the
chapters on skinning CSS and how the JavaScript within Gmail works, you
should be able to glean a little inkling into how it works. For the sake of brevity, I
won’t repeat all of the functions here, but to walk through, the first interesting
things are the _getsubs(note the plural and underscore) and parsesubsfunc-
tions._getsubsuses the same xmlhttprequest system that Gmail does._getsubs
requests your list of subscriptions from Bloglines.

Once the subs have been got by _getsubs, the script goes through a series of
functions to cache them. That is all at the top of the script, and causes the sub-
scriptions list to be collected only once an hour. (At the bottom of the script, the
very last function, is code to check if the page Greasemonkey can see is the one
you get only if the user has logged out of Gmail. If that page is hit, the cache is
emptied as well.)

A freshly retrieved list of subs is then passed through the parsesubsfunction.
This parses the XML of the subscription list into an array.

Note here that this is, so far, very useful stuff. Many sites provide information
feeds in XML, and all you have here really is a script that pulls in a feed (after
checking it’s not in a cache) and parses it. You can reuse that structure to pull in
data from just about anywhere. Indeed, if an ordinary website has no feed, but is
well-formed XHTML, you can even use this same technique to screenscrape
something and display that information within a page.
Free download pdf