Skip to content

Instantly share code, notes, and snippets.

@vilterp
Created November 5, 2008 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vilterp/22457 to your computer and use it in GitHub Desktop.
Save vilterp/22457 to your computer and use it in GitHub Desktop.
is.gd Ubiquity command
CmdUtils.CreateCommand({
name: "is.gd",
takes: {"url to shorten": noun_type_url},
icon: "http://is.gd/favicon.ico",
description: "Shortens the selected url with <a href=\"http://is.gd/\">is.gd</a>",
preview: function(pblock, urlToShorten){
pblock.innerHTML = "Shortens the selected url with is.gd.";
var baseUrl = "http://is.gd/api.php?longurl=";
pblock.innerHTML = "Replaces the selected URL with ";
jQuery.ajax({
url: baseURL + urlToShorten.text,
dataType: "text",
success: function(shortened) {
pblock.innerHTML += shortened;
},
error: function(xhr, textStatus, errorThrown) {
pblock.innerHTML = "Something went wrong.";
console.log([xhr,textStatus,errorThrown]);
}
});
},
execute: function(urlToShorten) {
var baseUrl = "http://is.gd/api.php?longurl=";
jQuery.ajax({
url: baseURL + urlToShorten.text,
dataType: "text",
success: function(shortened) {
CmdUtils.setSelection(shortened);
},
error: function() {
CmdUtils.displayMessage("Something went wrong.");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment