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 onclick function, in turn, opens the
page in Gmail that allows a mail to be composed. Because mailto: links can contain 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 compose 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:ben.hammersley@gmail.com,
this will produce the URL https://mail.google.com/mail?view=cm&tf=
0?&to-ben@benhammersley.com.
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 userscripts is ever increasing. Here are some more scripts that provide additional functionality 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 functionality. 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
to the link instead. When you click such a link, Firefox fires off the JavaScript
function instead of following the link. The onclick function, in turn, opens the
page in Gmail that allows a mail to be composed. Because mailto: links can contain 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 compose 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:ben.hammersley@gmail.com,
this will produce the URL https://mail.google.com/mail?view=cm&tf=
0?&to-ben@benhammersley.com.
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 userscripts is ever increasing. Here are some more scripts that provide additional functionality 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 functionality. 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
