24.07.2017 Views

Hacking Gmail

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6 — <strong>Gmail</strong> and Greasemonkey<br />

101<br />

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

inside an array. In the getsub function (note the singular, and lack of underscore),<br />

the script retrieves the XML of the feed. Once you have that, use the functions<br />

displaysubhtml and inithtml to convert the XML of the feed into HTML<br />

and display it on the page. From Chapter 4, even if you know no JavaScript, you<br />

should be able decipher the meaning of lines such as this:<br />

document.getElementById(‘ds_spam’).parentNode.style.display=’none’;<br />

They prevent the browser from displaying that particular div, making space for the<br />

HTML it then adds onto the screen.<br />

To go more deeply into this script would require another book, on JavaScript and<br />

Greasemonkey at the very least, but I hope by reading through it you can see how<br />

it works. It’s very hackable — have a go at converting it to displaying information<br />

from other XML-providing sources. The weather forecasts available at http://<br />

weather.gov/xml/ are a good starting point. For extra inspiration, consider displaying<br />

the weather at the location of a new mail’s sender. Tricky one, that.<br />

Add a Delete Button<br />

Not content with grabbing data from other sources and chucking it all over the<br />

site like some crazed mash-up DJ, you can also use Greasemonkey to add additional<br />

user interface elements. Anthony Lieuallen’s script at www.arantius.<br />

com/article/arantius/gmail+delete+button/ adds a Delete button to the<br />

menu, as shown in Figure 6-3.<br />

FIGURE 6-3: The added<br />

Delete button<br />

Without such a button, as you know, you have to move the message to trash.<br />

Not much of a change, admittedly, but a nice UI improvement. Listing 6-2 shows<br />

the code.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!