-
-
Save Nemo157/106885 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
name: "mail", | |
takes: {"message": noun_arb_text}, | |
icon: "chrome://ubiquity/content/icons/email.png", | |
modifiers: {to: noun_type_contact}, | |
description: "Begins composing an email to a person from your contact list.", | |
help: "Currently works with the mail client you have set as your default application to handle mailto: links. Try selecting part of a web page (note: images, and other dynamic elements will not be included) and then issuing "mail this". You can also specify the recipient of the email using the word "to" and the name of someone from your contact list or address book. For example, try issuing "mail hello to jono" (assuming you have a friend named "jono").", | |
preview: function(pblock, directObj, modifiers) { | |
var html = "Creates an email message "; | |
if (modifiers.to) { | |
html += "to " + modifiers.to.text + " "; | |
} | |
if (directObj.html) { | |
html += "with these contents:" + directObj.html; | |
} else { | |
html += "with a link to the current page."; | |
} | |
pblock.innerHTML = html; | |
}, | |
execute: function(directObj, headers) { | |
var html = directObj.html; | |
var document = context.focusedWindow.document; | |
var title; | |
var toAddress = ""; | |
if (document.title) | |
title = document.title; | |
else | |
title = html; | |
var location = document.location; | |
var pageLink = title + " (" + location + ") "; | |
if (html) | |
html = ("From the page " + pageLink + ": \n" + html); | |
else // If there's no selection, just send the current page. | |
html = "You might be interested in " + pageLink + "."; | |
if (headers.to) | |
if (headers.to.text) | |
toAddress = headers.to.text; | |
html = html.replace(/<br(?:.|\s)*?>/gi, '%0D').replace(/<\/p>/gi, '%0D').replace(/\n/g, '%0D'); //replace newlines | |
html = html.replace(/<(?:.|\s)*?>/g, ' '); | |
//mailto:gebruiker@provider.nl?CC=een@ander.nl&subject=title&body=body... | |
var link = "mailto:" + toAddress + "?subject=" + title + "&body=" + html; | |
var tab = Application.activeWindow.open(Utils.url(link)); | |
tab.close(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment