2 * (C) Copyright 2008 Jeremy Maitin-Shepard
3 * (C) Copyright 2009-2010 John J. Foerch
5 * Use, modification, and distribution are subject to the terms specified in the
9 require("content-buffer.js");
12 define_keymap("google_search_results_keymap", $display_name = "google-search-results");
14 // Keys for the "experimental" keyboard search
15 define_key(google_search_results_keymap, "j", "ensure-content-focused", $fallthrough);
16 define_key(google_search_results_keymap, "k", "ensure-content-focused", $fallthrough);
17 define_key(google_search_results_keymap, "o", "ensure-content-focused", $fallthrough);
18 define_key(google_search_results_keymap, "/", "ensure-content-focused", $fallthrough);
19 define_key(google_search_results_keymap, "return", "ensure-content-focused", $fallthrough);//BAD
22 * Note: escape already does the same thing as the Google key binding.
25 define_browser_object_class("google-search-results-links", null,
26 xpath_browser_object_handler("//a[@class='l']|//a[@class='l vst']|//a[@class='gs-title']|//h3[@class='r']/a"),
27 $hint = "select search result");
30 // Bind keys 1 through 9 to follow corresponding results links
32 define_browser_object_class("google-search-result-by-digit", null,
33 function (I, prompt) {
34 var doc = I.buffer.document;
35 var digit = I.event.charCode - 48;
36 var res = doc.evaluate("//a[parent::node()/@class='r']", doc, null,
37 Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
39 yield co_return(res.snapshotItem(digit - 1));
42 function google_search_bind_number_shortcuts () {
43 for (var j = 1; j <= 9; j++) {
45 var function_name = "gsearch-follow-result-" + j;
46 interactive(function_name,
47 "Follow google search result number " + j,
49 $browser_object = browser_object_google_search_result_by_digit);
50 define_key(google_search_results_keymap, String(j), function_name);
55 var google_search_results_link_commands =
56 ["follow", "follow-new-buffer", "follow-new-buffer-background",
57 "follow-new-window", "save", "copy", "shell-command-on-file"];
59 var google_search_results_modality = {
60 normal: google_search_results_keymap
64 define_page_mode("google-search-results-mode",
65 build_url_regexp($domain = /(?:encrypted\.)?google/,
67 $path = /search\?|cse\?/,
68 $tlds = ["com", "com.au", "co.uk", "de", "dk", "es",
69 "fr", "it", "no", "se", "uk"]),
70 function enable (buffer) {
71 for each (var c in google_search_results_link_commands) {
72 buffer.default_browser_object_classes[c] =
73 browser_object_google_search_results_links;
75 buffer.content_modalities.push(google_search_results_modality);
77 function disable (buffer) {
78 for each (var c in google_search_results_link_commands) {
79 delete buffer.default_browser_object_classes[c];
81 var i = buffer.content_modalities.indexOf(google_search_results_modality);
83 buffer.content_modalities.splice(i, 1);
85 $display_name = "Google Search Results");
87 page_mode_activate(google_search_results_mode);
89 provide("google-search-results");