toggle-full-screen: use new helper function window_set_full_screen
[conkeror.git] / modules / page-modes / google-images.js
blob06a41d2ae03561b6c3f4d4da373367922c6bd6e0
1 /**
2  * (C) Copyright 2009 John J. Foerch
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 /**
9  * Google Images Mode
10  *
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!
15  */
17 in_module(null);
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(
33         $buffer = I.buffer,
34         $prompt = prompt,
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);
39         u.spec = result.href;
40         yield co_return(u);
41     } else
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);
51         } else
52             yield co_return(u);
53     });
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);
61         } else
62             yield co_return(u);
63     });
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;
71         }
72         for each (var c in google_images_imgurl_commands) {
73             buffer.default_browser_object_classes[c] =
74                 browser_object_google_images_imgurl;
75         }
76     });
79 let (rx = build_url_regex($domain = /(.*\.)?google/,
80                           $path = "images")) {
81     auto_mode_list.push([rx, google_images_mode]);
84 provide("google-images");