Revisions

gist: 142227 Download_button fork
public
Public Clone URL: git://gist.github.com/142227.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
37
38
39
40
41
42
43
44
45
46
47
48
49
var noun_url = {
  label: "url",
  noExternalCalls: true,
  rankLast: true,
  suggest: function(text, html, callback, selectionIndices) {
    var url = text;
    if (/^(?![A-Za-z][A-Za-z\d.+-]*:)/.test(url)) {
      let p = "http://", n = p.length;
      url = p + url;
      if (selectionIndices) selectionIndices = [n, n + url.length];
    }
    Utils.history.search(text, function(results) {
      if (results.length){
        callback([CmdUtils.makeSugg(r.url, r.title, r.favicon, 1)
                  for each (r in results)]);
      } else {
        callback([]);
      }
    }, 5);
  }
};
 
CmdUtils.CreateCommand({
  names: ["go to"],
  arguments: [{role: 'object', nountype: noun_url}],
  preview: function preview(pblock, args) {
    pblock.innerHTML = "Opens <b><a href='" + args.object.text + "'>" + args.object.html + " - " + args.object.text + "</a></b> in a new tab";
  },
  execute: function execute(args) {
    if(args.object.text){
       Utils.openUrlInBrowser(args.object.text);
    }
  }
});
 
CmdUtils.CreateCommand({
  names: ["copy link"],
  arguments: [{role: 'object', nountype: noun_url}],
  preview: function preview(pblock, args) {
    pblock.innerHTML = "Copies <b><a href='" + args.object.text + "'>" + args.object.html + "</a></b> to the clipboard";
  },
  execute: function execute(args) {
    if(args.object.text){
      Utils.clipboard.text = args.object.text;
    }
  }
});