jjdelc (owner)

Revisions

gist: 202697 Download_button fork
public
Description:
Ubiquity ir.pe command
Public Clone URL: git://gist.github.com/202697.git
Embed All Files: show embed
x.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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);
  },
});