Skip to content

Instantly share code, notes, and snippets.

@erickedji
Created April 27, 2009 11:53
Show Gist options
  • Select an option

  • Save erickedji/102450 to your computer and use it in GitHub Desktop.

Select an option

Save erickedji/102450 to your computer and use it in GitHub Desktop.
Shorten a URL with bit.ly (uses bit.ly's google spreadsheet API key)
/*
* Shorten a URL with bit.ly (uses bit.ly's google spreadsheet API key)
*
* Eric KEDJI <eric.kedji@gmail.com>
*/
CmdUtils.CreateCommand({
name: "bitly",
homepage: "http://erickedji.wordpress.com/",
author: {name: "Eric", email: "eric.kedji@gmail.com"},
license: "GPL",
description: "Shorten the selected URL using bit.ly",
help: "Invoke it on a chunk of text",
takes: {"input": /.*/},
preview: function(pblock, input) {
pblock.innerHTML = "Shorten the selected URL.";
},
execute: function(input, mod) {
var url = input.text;
jQuery.get('http://api.bit.ly/shorten?version=2.0.1&login=bitlyspreadsheets&apiKey=R_ec5820b9a63b11ef0adfda8f98810713&format=text&longUrl=' + encodeURIComponent(url),
{}, function (reply) { CmdUtils.setSelection(reply); } );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment