-
-
Save vilterp/22457 to your computer and use it in GitHub Desktop.
is.gd Ubiquity command
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
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