// ElectroFox Designs (Max Smiley)
// http://www.efoxdesigns.com
// GPL
//Please send any bugs / webmail url change notices to support@efoxdesigns.com Enjoy!
//need a place to test it? why not "http://www.efoxdesigns.com/max/downloads"? Hover over the email link at the top...
// ==UserScript==
// @name Mailto 2 Webmail
// @namespace http://*
// @description Makes "mailto" links open in your favorite web-based email account, instead of a pop-3 client (like Outlook, Eudora, Thunderbird, etc.)
// @exclude http://mail.google.com/*
// @exclude https://mail.google.com/*
// ==/UserScript==
//#EDIT THIS ONLY Set whichService to be your webmail service. If using yahoo, you must set your yahooServer.
var whichService = "Gmail"; //use "gmail" or "yahoo"* *new Yahoo Mail (beta) users: mailto links open in the old version. This is only for that session.
var showAlert = false; //use true or false (no quotes!) **Hotmail & Aim Mail users: Sorry, but hotmail & aim mail don't support this. I may try to see if I can get these to work. I'm also open to suggestions.
var openNewWindow = true; //set to false to have email composer open in the same window. leave as true to have it open in a new window or tab (gmail will automatically close).
//Advanced options:
var gmailDomain = ""; // If using GoogleApps, and have gmail on your domain, set this to be your domain name without the www(example "efoxdesigns.com")
var yahooServer = "us.f576" //if using yahoo, you will have to put your server here. to find this, log into your yahoo email account (make sure your at your mail).
//Your server is the part right between "http://" and ".mail.yahoo..." it will look something like us.f576 (http://us.f306.mail.yahoo...)
//#END EDIT That's all. You're done. Sit back and watch mailto links open in your web-based email client
//-------- DO NOT EDIT BELOW THIS POINT! -------//
var mailUrl = ""; var whoTo = ""; var theRest = ""; var alertText = ""; var anError = false;
var pageLinks = document.evaluate("//a[@href[contains(.,'ailto:')]]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
var currentLink;
for(var i = 0; i < pageLinks.snapshotLength; i++) {
currentLink = pageLinks.snapshotItem(i); //rather than write pageLinks.snapshotItem(i) all over the place
switch(whichService.toLowerCase())
{
case "gmail":
mailUrl = getGmailString(currentLink.href); break;
case "yahoo":
mailUrl = getYahooString(currentLink.href); break;
case "hotmail":
mailUrl = getHotmailString(currentLink.href); break;
case "aol":
mailUrl = getAolString(currentLink.href); break;
default:
alertText = "Mailto 2 Webmail\nUh oh... It appears you have set the email service incorrectly.\nMake sure that \"whichService\" is set to one of the values listed,\nand that that value is surrounded by (1 set of) quotes.";
showAlert = true; anError = true;
break;
}
currentLink.setAttribute('href', mailUrl); //re-write the link here
currentLink.setAttribute('title', "Link will go to " + whichService); //and the title
if (openNewWindow) currentLink.setAttribute('target', "_blank"); //opens in a new window, if desired
if (!anError) alertText += "Mailto link found: \"" + currentLink.textContent + "\"\n";
if (i == (pageLinks.snapshotLength - 1)) if (showAlert && alertText != "") alert(alertText);
}
function getGmailString(theHref)
{
var continueWhere = "&continue=http://mail.google.com/";
if (openNewWindow) continueWhere = "";
var whichDomain = "mail";
if (gmailDomain != "") whichDomain = "a/" + gmailDomain;
var theElement = "https://mail.google.com/" + whichDomain + "/?ui=1&view=cm&fs=1&tf=1&to="; var begin; var subLength;
begin = theHref.toLowerCase().indexOf("mailto:") + 7;
subLength = theHref.indexOf("?") - begin;
if (theHref.indexOf("?") > 0) theElement += theHref.substr(begin,subLength); //in case there are no subject, etc specifications
else theElement += theHref.substr(7);
begin = theHref.indexOf("?") + 1; //re-using begin
if (theHref.indexOf("?") > 0) theElement += "&" + theHref.substr(begin).replace(/subject=/,"su=");
theElement += continueWhere;
return theElement;
}
function getYahooString(theHref)
{
var theElement = "http://" + yahooServer + ".mail.yahoo.com/ym/Compose?To="; var begin; var subLength;
begin = theHref.toLowerCase().indexOf("mailto:") + 7;
subLength = theHref.indexOf("?") - begin;
if (theHref.indexOf("?") > 0) theElement += theHref.substr(begin,subLength); //in case there are no subject, etc specifications
else theElement += theHref.substr(7);
begin = theHref.indexOf("?") + 1; //re-using begin
if (theHref.indexOf("?") > 0) theElement += "&" + theHref.substr(begin).replace(/subject=/,"Subj=");
theElement += "&ymv=0";
return theElement;
}
function getHotmailString(theHref)
{
alertText = "Mailto 2 Webmail\nSorry, Hotmail isn't supported at this time.\n(And probably won't be.)";
showAlert = true; anError = true;
return theHref;
}
function getAolString(theHref)
{
alertText = "Mailto 2 Webmail\nSorry, Aim Mail isn't supported at this time.\n(And probably won't be.)";
showAlert = true; anError = true;
return theHref;
}