pratham (owner)

Revisions

gist: 10704 Download_button fork
public
Description:
Ubiquity - Google Image Search.
Public Clone URL: git://gist.github.com/10704.git
Embed All Files: show embed
JavaScript #
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
50
51
52
53
54
55
56
if (CmdUtils.parserVersion == 2) {
CmdUtils.CreateCommand({
  names: ["image", "gim"],
  icon: "http://www.google.com/favicon.ico",
  author: {name: "Pratham Kumar", email: "pratham@pratham.name"},
  description: "Google Image Search - shows the first result as a preview",
  homepage: "http://pratham.name/",
  arguments: [{role: 'object', nountype: noun_arb_text, label: 'query'}],
 
  preview: function (html, q) {
    var params = {q: q.object.text};
    html.innerHTML = 'Google Image Search for <b>'+q.object.text+'</b>';
 
    if (q.object.text == '')
      return;
 
    jQuery.get ('http://images.google.com/images', params, function (data) {
      var regex = new RegExp ("dyn.setResults...\"[^\"]*\",\"[^\"]*\",\"([^\"]*)\",\"([^\"]*)\"", "gi");
 
      line = regex.exec (data);
      html.innerHTML = '<div style="height:125px"><img src="http://tbn0.google.com/images?q=tbn:'+line [1]+":"+line [2]+'"></div><br>';
    });
  },
 
  execute: function (q) {
    var url = "http://images.google.com/images?q="+q.object.text;
    Utils.openUrlInBrowser (url);
  }
});
} else {
CmdUtils.CreateCommand({
  name: "image",
  icon: "http://www.google.com/favicon.ico",
  author: {name: "Pratham Kumar", email: "pratham@pratham.name"},
  description: "Google Image Search - shows the first result as a preview",
  homepage: "http://pratham.name/",
  takes: {"query": noun_arb_text},
 
  preview: function (html, q) {
    var params = {q: q.text};
    html.innerHTML = 'Google Image Search for <b>'+q.text+'</b>';
 
    jQuery.get ('http://images.google.com/images', params, function (data) {
      var regex = new RegExp ("dyn.setResults...\"[^\"]*\",\"[^\"]*\",\"([^\"]*)\",\"([^\"]*)\"", "gi");
 
      line = regex.exec (data);
      html.innerHTML = '<div style="height:125px"><img src="http://tbn0.google.com/images?q=tbn:'+line [1]+line [2]+'"></div><br>';
    });
  },
 
  execute: function (q) {
    var url = "http://images.google.com/images?q="+q.text;
    Utils.openUrlInBrowser (url);
  }
});
}