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 ${url}.", {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); }, });