Skip to content

Instantly share code, notes, and snippets.

@allannnnf
Created August 11, 2009 23:03
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 allannnnf/166170 to your computer and use it in GitHub Desktop.
Save allannnnf/166170 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
names: ["unu", "u"],
arguments: noun_type_url,
icon: "http://u.nu/favicon.ico",
description: "Enter your big bad URL and u.nu will cut it down to size.",
author: {name:"Allan Freitas", email:"allanf.cpp@gmail.com"},
preview: function(pblock, {object: {text}}){
if (!text) {
pblock.innerHTML = this.description;
return;
}
var me = this;
pblock.innerHTML = _("Big bad URL is now... ");
CmdUtils.previewGet(pblock, this._api(text), function(uNu) {
if(uNu !== "Error")
pblock.innerHTML = _("Replaces the selected URL with <b>${u}</b>.",
{u:me._link(uNu)});
});
},
execute: function(args) {
var me = this;
jQuery.get(this._api(args.object.text), function(uNu) {
CmdUtils.setSelection(me._link(uNu), {text: uNu});
Utils.clipboard.text = uNu;
});
},
_api: function(url)("http://u.nu/unu-api-simple?url=" +
encodeURIComponent(url)),
_link: function(url) {
var eu = Utils.escapeHtml(url);
return eu.link(eu);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment