Created
October 27, 2008 14:14
-
-
Save garyhodgson/20103 to your computer and use it in GitHub Desktop.
Ubiquity Command that uses bit.ly to shorten urls
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
/** | |
* Command to shorten URLs using bit.ly | |
* | |
* Copied from http://mskadu.googlepages.com/bitly | |
*/ | |
CmdUtils.CreateCommand({ | |
name: "bitly", | |
takes: {"url to shorten": noun_arb_text}, | |
icon: "http://bit.ly/static/images/favicon.png", | |
description: "Replaces the selected URL with a shortened version from <a href=\"http://bit.ly/go\">Bit.ly</a><br/>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:"<br>"" | |
+ urlToShorten ; | |
}, | |
execute: function( urlToShorten ) { | |
jQuery.get( "http://bit.ly/api?url=" + urlToShorten.text, function( bitly ) { | |
CmdUtils.setSelection( bitly ); | |
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); | |
gClipboardHelper.copyString(bitly ); | |
displayMessage(bitly + " copied to the clipboard"); | |
}) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment