function copy_to_clipboard(thing) { // FROM: http://developer.mozilla.org/en/Using_the_Clipboard const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); gClipboardHelper.copyString(thing); displayMessage(thing + " copied to the clipboard"); } CmdUtils.CreateCommand({ name: "bitly", takes: {"url to shorten": noun_arb_text}, icon: "http://bit.ly/favicon.png", description: "Replaces the selected URL with a shortened version from Bit.ly
And copies it to your clipboard for further use", license: "MPL", preview: function( pblock, urlToShorten ){ pblock.innerHTML = "Replaces the selected URL with a shorted version (using bit.ly)."; var baseUrl = "http://bit.ly/api?url="; pblock.innerHTML = "Replaces the selected URL with ", jQuery.get( baseUrl + urlToShorten.text, function( bitly ) { if(bitly != "Error") pblock.innerHTML += bitly; }); }, execute: function( urlToShorten ) { var baseUrl = "http://bit.ly/api?url="; jQuery.get( baseUrl + urlToShorten.text, function( bitly ) { CmdUtils.setSelection( bitly ); copy_to_clipboard( bitly ); }) } });