kill_buffer: go to about:blank instead of erroring when killing last buffer
[conkeror.git] / modules / page-modes / stackexchange.js
blob222714dbd6376e258853bedcbbfe839ac700a594
1 /**
2  * (C) Copyright 2010 Dave Kerschner
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6  *
7  * StackExchange page mode
8  *
9  * Provides ability to vote on Stack Exchange sites without having to grab
10  * the mouse.
11  */
13 /**
14  * browser_object_class that finds the vote images
15  */
16 define_browser_object_class("stackexchange-votes",
17     "Browser object class for selecting a vote arrow via hinting.",
18                             xpath_browser_object_handler('//span[contains(@class,"vote-up-off")]' +
19                                   ' | //span[contains(@class,"vote-down-off")]'),
20      $hint = "select a vote");
22 define_browser_object_class("stackexchange-accept-answers",
23     "Browser object class for selecting an accepted answer check via hinting.",
24                             xpath_browser_object_handler('//span[contains(@class,"vote-accepted-off")]'),
25     $hint = "select an accepted answer");
28 interactive("stackexchange-vote",
29     "Vote on StackExchange sites",
30     function (I) {
31         var elem = yield read_browser_object(I);
32         dom_node_click(elem, 1, 1);
33     },
34     $browser_object = browser_object_stackexchange_votes);
36 interactive("stackexchange-accept-answer",
37     "Accept an answer on StackExchange site",
38     function (I) {
39         var elem = yield read_browser_object(I);
40         dom_node_click(elem, 1, 1);
41     },
42     $browser_object = browser_object_stackexchange_accept_answers);
44 interactive("stackexchange-favorite-question",
45     "Favorite a question on StackExchange site",
46     function (I) {
47         var xpr = I.buffer.document.evaluate(
48             '//span[contains(@class,"star-off")]',
49             I.buffer.document, null,
50             Ci.nsIDOMXPathResult.ORCERD_NOTE_ITERATOR_TYPE, null);
51         let elem;
52         if(xpr && (elem = xpr.iterateNext())) {
53             dom_node_click(elem, 1, 1);
54         }
55     });
58 define_keymap("stackexchange_keymap", $display_name = "stackexchange");
59 define_key(stackexchange_keymap, "V", "stackexchange-vote");
60 define_key(stackexchange_keymap, "A", "stackexchange-accept-answer");
61 define_key(stackexchange_keymap, "O", "stackexchange-favorite-question");
63 define_keymaps_page_mode("stackexchange-mode",
64     /^https?:\/\/(?:www.|meta.)?(stackoverflow|serverfault|superuser|stackapps)\.(?:com)\//,
65     { normal: stackexchange_keymap },
66     $display_name = "StackExchange");
68 page_mode_activate(stackexchange_mode);
70 provide("stackexchange");