-
-
Save allannnnf/166170 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
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