Created
January 10, 2013 07:52
-
-
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.
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
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