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!
17 define_variable('google_images_imgrefurl_commands',
18 ["follow", "follow-new-buffer",
19 "follow-new-buffer-background",
20 "follow-new-window", "copy"],
21 "List of commands for which the google-images-imgrefurl browser object "+
22 "should be used in Google Images Mode");
24 define_variable('google_images_imgurl_commands',
25 ["save", "shell-command-on-file"],
26 "List of commands for which the google-images-imgurl browser object "+
27 "should be used in Google Images Mode");
29 function google_images_get_image_uri (I, prompt) {
30 var result = yield I.buffer.window.minibuffer.read_hinted_element(
33 $hint_xpath_expression = "//a[img]");
34 if (result instanceof Ci.nsIDOMHTMLElement) {
35 var u = Cc["@mozilla.org/network/standard-url;1"]
36 .createInstance(Ci.nsIURL);
40 yield co_return(result);
43 define_browser_object_class("google-images-imgrefurl", null,
44 function (I, prompt) {
45 var u = yield google_images_get_image_uri(I, prompt);
46 if (u instanceof Ci.nsIURL) {
47 var imgrefurl = unescape(u.query.match(/&imgrefurl=([^&]*)/)[1]);
48 yield co_return(imgrefurl);
53 define_browser_object_class("google-images-imgurl", null,
54 function (I, prompt) {
55 var u = yield google_images_get_image_uri(I, prompt);
56 if (u instanceof Ci.nsIURL) {
57 var imgurl = unescape(u.query.match(/imgurl=([^&]*)/)[1]);
58 yield co_return(imgurl);
63 define_page_mode("google-images-mode",
64 build_url_regexp($domain = /(.*\.)?google/, $path = "images"),
65 function enable (buffer) {
66 for each (var c in google_images_imgrefurl_commands) {
67 buffer.default_browser_object_classes[c] =
68 browser_object_google_images_imgrefurl;
70 for each (var c in google_images_imgurl_commands) {
71 buffer.default_browser_object_classes[c] =
72 browser_object_google_images_imgurl;
75 function disable (buffer) {
76 for each (var c in google_images_imgrefurl_commands) {
77 delete buffer.default_browser_object_classes[c];
79 for each (var c in google_images_imgurl_commands) {
80 delete buffer.default_browser_object_classes[c];
83 $display_name = "Google Images");
85 page_mode_activate(google_images_mode);
87 provide("google-images");