Text Selection & Call Origination Javascript bookmarklet

As you all may know I have worked for Barracuda Networks for a bit under two years.  The product I work with everyday is the Cudatel.  Based on FreeSWITCH, it has the potential to be quite the game-changer within the VOIP world (that is, if Barracuda plays their cards right).  I figured it would be fitting if the first post to the new website would be some good ol code I slapped together that uses the Cudatel’s restAPI.  Below is a bookmarklet that lets one’s cursor selection within a browser be sent out to the Cudatel.  This gives the user potential to select a phone number, and dial out; eliminating the need for a TAPI interface (at least within a browser).

This could be taken to an extreme with a number autodetection browser integration plugin (much like skype has with FireFox, IE, and Chrome.  But for now, this works spectacular.  Not much thought was put into this as there could be many more conditions for error checking and perhaps conversion between alpha and numeric characters (1-800-abc-defg).

Enjoy.

javascript:(function(){var num = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text;num = num.replace(/[^\d.]/g, "");if(num.length < 10){alert("Failure");}var iframe = document.createElement('iframe');iframe.src="http://<url_of_your_cudatel>/gui/freeswitch/originate?__auth_user=<USERNAME>&__auth_pass=<YOURPASSWORD>&destination=" + num;document.body.appendChild(iframe);})()

 

EDIT July 2, 2013 – Thanks to my friend Michael, he thought it would be swell to add an alternative popup box when nothing is highlighted so one could always put in a number:


javascript:(function(){var num = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text;num = num.replace(/[^\d.]/g, "");if(!num){void(num=prompt('What number, please:',''))};if(num.length < 10){alert("Invalid number, please try again.")};var iframe = document.createElement('iframe');iframe.src="http://<url_of_your_cudatel>/gui/freeswitch/originate?__auth_user=<EXT>&__auth_pass=<PASS>&destination=" + num;document.body.appendChild(iframe);})()