Skip to content

Instantly share code, notes, and snippets.

@lambtron
Created January 10, 2013 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lambtron/4500267 to your computer and use it in GitHub Desktop.
Save lambtron/4500267 to your computer and use it in GitHub Desktop.
This is the javascript file that is being imported with the bookmarklet script, so as to allow the bookmarklet to capture the highlighted text and also to send the necessary data points to the server for SMS delivery.
function getSelText() {
var txt = '';
if (window.getSelection) {
txt = window.getSelection();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
} else return;
return txt;
}
function sendSMS( recipient ) {
var body = getSelText();
if ( body == '' ) {
alert("You have not highlighted anything to send to your phone!");
} else {
// Create object.
var http = new XMLHttpRequest();
// POST
var data = "recipient=" + recipient + "&body=" + body;
var url = "http://www.andy-jiang.com/textme/send_sms/";
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send(data);
alert("A text was just sent to " + recipient);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment