Created
August 6, 2009 08:19
-
-
Save eladkehat/163191 to your computer and use it in GitHub Desktop.
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
/* 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