Skip to content

Instantly share code, notes, and snippets.

@rcmdnk
Created December 16, 2014 09:28
Show Gist options
  • Save rcmdnk/fa04da82a25c602c0505 to your computer and use it in GitHub Desktop.
Save rcmdnk/fa04da82a25c602c0505 to your computer and use it in GitHub Desktop.
jQuery(function($){
$(document).on('copy', function(e) {
var selected = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
selected = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
selected = document.selection.createRange().htmlText;
}
}
var title = document.title;
var url = location.href;
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': 'YOUR_API_KEY',
'message': {
'from_email': 'your_sender@example.com',
'to': [
{
'email': 'your_receiver@example.com',
'name': 'your receiver',
'type': 'to'
}
],
'subject': 'Copied at ' + title,
'html': '<div><a href="' + url + '">' + title + '</a></div><br><br><div>' + selected + '</div>'
}
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment