Hacking Gmail

(Grace) #1

114 Part II — Getting Inside Gmail


to the link instead. When you click such a link, Firefox fires off the JavaScript
function instead of following the link. The onclickfunction, in turn, opens the
page in Gmail that allows a mail to be composed. Because mailto:links can con-
tain the recipients, message subject, and body text, the userscript has to retrieve
these and add them to the Gmail compose page. You already know that the com-
pose mail URL can be built up in this way, so it’s pretty easy to do that. Here’s the
code that does it:

mailtoLink.href = “https://mail.google.com/mail?view=cm&tf=0”
+
(emailTo? (“&to=” + emailTo) : “”) +
(emailCC? (“&cc=” + emailCC) : “”) +
(emailSubject? (“&su=” + emailSubject) : “”)
+
(emailBody? (“&body=” + emailBody) : “”);
// mailtoLink.onclick = function() { location.href
= newUrl; return false; };
}

When you run on a link that points to mailto:[email protected],
this will produce the URL https://mail.google.com/mail?view=cm&tf=
[email protected].

Perfect. Using this code, you can compose other messages. Perhaps you might like
to use it to produce an “e-mail this to me” userscript, populating the message body
with the contents of the page.

Other Userscripts


Greasemonkey continues to recruit happy developers, and the number of user-
scripts is ever increasing. Here are some more scripts that provide additional func-
tionality to Gmail. More still can be found at http://userscripts.org.

As ever, of course, you must remember that Gmail’s interface is an ever-changing
mélange of weirdness, and these userscripts may well fade in and out of function-
ality. If one stops working, check its coder’s website for updates.

Mark Read Button


Documentation:http://userscripts.org/scripts/show/689

Userscript:http://userscripts.org/scripts/source/689.user.js
Free download pdf