Skip to content

Instantly share code, notes, and snippets.

@allannnnf allannnnf/unu
Created Aug 11, 2009

Embed
What would you like to do?
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
You can’t perform that action at this time.