Skip to content

Instantly share code, notes, and snippets.

@eladkehat
Created August 6, 2009 08:19
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 eladkehat/163191 to your computer and use it in GitHub Desktop.
Save eladkehat/163191 to your computer and use it in GitHub Desktop.
/* Use cli.gs to shorten URLs in Ubiquity. */
CmdUtils.CreateCommand({
names: ["cligs", "cli.gs", "cl.gs"],
icon: "http://cli.gs/favicon.ico",
description: "Shortens a URL using cli.gs",
help: "Type the URL to shorten. When executed, it's copied to the clipboard.",
author: {name: "Elad Kehat", email: "eladkehat@gmail.com"},
license: "GPL",
homepage: "http://philobuster.wordpress.com/",
arguments: [{role: 'object', nountype: noun_arb_text, label: "URL to shorten"},
{role: 'alias', nountype: noun_arb_text, label: "Title for the short URL"}],
preview: function preview(pblock, args) {
var escapedUrl = encodeURIComponent(args.object.text);
var apiUrl = "http://cli.gs/api/v1/cligs/create?url=" + escapedUrl;
var urlTitle = args.alias.text;
if (urlTitle.length > 0) {
apiUrl += "&title=" + encodeURIComponent(urlTitle);
}
pblock.innerHTML = "Replace the long URL with (calling " + apiUrl + "...)";
var me = this;
jQuery.get(apiUrl, {}, function(response) {
if (response.indexOf("http") == 0) {
me.shortUrl = response;
pblock.innerHTML = "Replaces the long URL with <strong>" + me.shortUrl + "</strong>";
} else {
pblock.innerHTML = "Error shortening URL";
}
}, 'text');
},
execute: function execute() {
if (this.shortUrl) {
CmdUtils.setSelection(this.shortUrl);
CmdUtils.copyToClipboard(this.shortUrl);
displayMessage({icon: this.icon, title: "Copied to clipboard", text: this.shortUrl});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment