-
-
Save jjdelc/202697 to your computer and use it in GitHub Desktop.
Ubiquity ir.pe command
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: ["irpe", "Irpe"], | |
icon: "http://ir.pe/favicon.ico", | |
description: "Replaces a url with a short ir.pe one.", | |
help: "irpe url", | |
author: {name: "Jesús Del Carpio", email: "jjdelc@gmail.com"}, | |
license: "GPL", | |
homepage: "http://isgeek.net/", | |
arguments: [{role: 'object', nountype: noun_arb_text}], | |
preview: function preview(pblock, {object:{text}}) { | |
if (!text) { | |
pblock.innerHTML = this.description; | |
return; | |
} | |
var me = this; | |
pblock.innerHTML = "Replaces the current URL with ..."; | |
CmdUtils.previewGet(pblock, me._api(text), function(url){ | |
pblock.innerHTML = _("Replace ${original} with <b>${url}</b>.", {url:me._link(url), original:text}); | |
}); | |
}, | |
execute: function execute(args) { | |
var me = this; | |
jQuery.get(this._api(args.object.text), function(url){ | |
CmdUtils.setSelection(me._link(url), {text: url}); | |
Utils.clipboard.text = url; | |
}); | |
}, | |
_api: function(url)("http://ir.pe/?url=" + url + "&api=1"), | |
_link: function(url){ | |
var escaped_url = Utils.escapeHtml(url); | |
return escaped_url.link(escaped_url); | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment