Hacking Gmail

(Grace) #1

112 Part II — Getting Inside Gmail


Listing 6-4(continued)

// -----------------------------------------------------------
---------
//
// ==UserScript==
// @name Mailto Compose In GMail
// @namespace
http://blog.monstuff.com/archives/000238.html
// @description Rewrites “mailto:” links to GMail compose
links
// @include *
// @exclude http://gmail.google.com
// ==/UserScript==

(function() {

var processMailtoLinks = function() {
var xpath = “//a[starts-with(@href,’mailto:’)]”;
var res = document.evaluate(xpath, document, null,

XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

var linkIndex, mailtoLink;
for (linkIndex = 0; linkIndex < res.snapshotLength;
linkIndex++) {
mailtoLink = res.snapshotItem(linkIndex);
//alert(mailtoLink.href);

var m = mailtoLink.href;
var matches =
m.match(/^mailto:([^\?]+)(\?([^?]*))?/);
var emailTo, params, emailCC, emailSubject,
emailBody;

emailTo = matches[1];
//alert(“Found to=” + emailTo);

params = matches[3];
if (params) {
var splitQS = params.split(‘&’);
var paramIndex, param;

for (paramIndex = 0; paramIndex <
splitQS.length; paramIndex++) {
param = splitQS[paramIndex];
nameValue = param.match(/([^=]+)=(.*)/);
Free download pdf