Labs/Ubiquity/Writing A Search Command: Difference between revisions

Line 163: Line 163:


== Examples ==
== Examples ==
=== The bare essentials ===
CmdUtils.makeSearchCommand({
  name: "Google",
  url: "http://www.google.com/search?q={QUERY}",
});
=== Adding a preview ===
CmdUtils.makeSearchCommand({
  name: "YouTube",
  url: "http://www.youtube.com/results?search_type=&search_query={QUERY}&aq=f",
  parser: {container: "div.video-entry",
            title: "div.video-long-title a",
            preview: "div.video-description",
            thumbnail: "img.vimg120"}
});
=== Using the JSON parser ===
CmdUtils.makeSearchCommand({
  name: "Google",
  url: "http://www.google.com/search?q={QUERY}",
  parser: {type: "JSON",
            url: "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={QUERY}",
            container: "responseData.results",
            title: "titleNoFormatting",
            preview: "content",
            href: "url"}
});
=== Using functions in the parser ===
CmdUtils.makeSearchCommand({
  name: "MovieZoo",
  url: "http://www.moviezoo.dk/alle-produkter/soeg/{QUERY}",
  parser: {
    container: "table.nyhedsbrev_tabel2",
    title: "tr:nth-child(2) tr tr:first-child b",
    href: function(c) {return jQuery("a.nyhedsbrev",c).attr("href");},
    preview: function(c) {var p = ""; jQuery("table table tr:not(:first)",c).each(function(){p += jQuery(this).text()+"<br>";});return p;},
    thumbnail: "img.lister_img",
    maxResults: 3
  }
});
47

edits