2 * (C) Copyright 2009 John J. Foerch
4 * Use, modification, and distribution are subject to the terms specified in the
11 * Provides browser-object overrides for various commands at
12 * google-images, to follow directly to the page that contains an
13 * image, or directly save the full-size image. Never see that
14 * annoying frameset page from google again!
19 define_variable('google_images_imgrefurl_commands',
20 ["follow", "follow-new-buffer",
21 "follow-new-buffer-background",
22 "follow-new-window", "copy"],
23 "List of commands for which the google-images-imgrefurl browser object "+
24 "should be used in Google Images Mode");
26 define_variable('google_images_imgurl_commands',
27 ["save", "shell-command-on-file"],
28 "List of commands for which the google-images-imgurl browser object "+
29 "should be used in Google Images Mode");
31 function google_images_get_image_uri (I, prompt) {
32 var result = yield I.buffer.window.minibuffer.read_hinted_element(
35 $hint_xpath_expression = "//a[img]");
36 if (result instanceof Ci.nsIDOMHTMLElement) {
37 var u = Cc["@mozilla.org/network/standard-url;1"]
38 .createInstance(Ci.nsIURL);
42 yield co_return(result);
45 define_browser_object_class("google-images-imgrefurl", null,
46 function (I, prompt) {
47 var u = yield google_images_get_image_uri(I, prompt);
48 if (u instanceof Ci.nsIURL) {
49 var imgrefurl = unescape(/&imgrefurl=([^&]*)/(u.query)[1]);
50 yield co_return(imgrefurl);
55 define_browser_object_class("google-images-imgurl", null,
56 function (I, prompt) {
57 var u = yield google_images_get_image_uri(I, prompt);
58 if (u instanceof Ci.nsIURL) {
59 var imgurl = unescape(/imgurl=([^&]*)/(u.query)[1]);
60 yield co_return(imgurl);
65 define_page_mode("google_images_mode",
66 $display_name = "Google Images",
67 $enable = function (buffer) {
68 for each (var c in google_images_imgrefurl_commands) {
69 buffer.default_browser_object_classes[c] =
70 browser_object_google_images_imgrefurl;
72 for each (var c in google_images_imgurl_commands) {
73 buffer.default_browser_object_classes[c] =
74 browser_object_google_images_imgurl;
79 let (rx = build_url_regex($domain = /(.*\.)?google/,
81 auto_mode_list.push([rx, google_images_mode]);
84 provide("google-images");