madx / ubiquity-commands

Some homemade Ubiquity commands

This URL has Read+Write access

ubiquity-commands / shorten.js
100644 26 lines (21 sloc) 0.707 kb
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
/*
*/
CmdUtils.CreateCommand({
  name: "shorten",
  homepage: "http://yapok.org/",
  author: {name: "MadX", email: "root+ubiq@yapok.org"},
  license: "WTFPL",
  description: "Replace an url with a shorter one using is.gd",
  
  takes: {"url to shorten": noun_arb_text},
  
  preview: function( pblock ) {
    var msg = "Replace <b>${url}</b> by a shorter url made with is.gd";
    pblock.innerHTML = CmdUtils.renderTemplate( msg, {url: CmdUtils.getSelection()} );
  },
  
  execute: function( urlToShorten ) {
    var baseUrl = "http://is.gd/api.php";
    var params = {longurl: urlToShorten.text};
    jQuery.get( baseUrl, params, function( isGd ) {
      CmdUtils.setSelection( isGd );
    })
  }
  
});