Hacking Gmail

(Grace) #1

Chapter 6 — Gmail and Greasemonkey 101


Even better, the script then has to go use the data in the subs list, which is placed


inside an array. In the getsubfunction (note the singular, and lack of underscore),
the script retrieves the XML of the feed. Once you have that, use the functions


displaysubhtmland inithtmlto convert the XML of the feed into HTML
and display it on the page. From Chapter 4, even if you know no JavaScript, you


should be able decipher the meaning of lines such as this:


document.getElementById(‘ds_spam’).parentNode.style.display=’none’;


They prevent the browser from displaying that particular div, making space for the


HTML it then adds onto the screen.


To go more deeply into this script would require another book, on JavaScript and


Greasemonkey at the very least, but I hope by reading through it you can see how
it works. It’s very hackable — have a go at converting it to displaying information


from other XML-providing sources. The weather forecasts available at http://
weather.gov/xml/are a good starting point. For extra inspiration, consider dis-


playing the weather at the location of a new mail’s sender. Tricky one, that.


Add a Delete Button.


Not content with grabbing data from other sources and chucking it all over the


site like some crazed mash-up DJ, you can also use Greasemonkey to add addi-
tional user interface elements. Anthony Lieuallen’s script at http://www.arantius.


com/article/arantius/gmail+delete+button/adds a Delete button to the
menu, as shown in Figure 6-3.


FIGURE6-3: The added
Delete button


Without such a button, as you know, you have to move the message to trash.
Not much of a change, admittedly, but a nice UI improvement. Listing 6-2 shows


the code.

Free download pdf