2 * (C) Copyright 2010 Dave Kerschner
4 * Use, modification, and distribution are subject to the terms specified in the
7 * StackExchange page mode
9 * Provides ability to vote on Stack Exchange sites without having to grab
14 * browser_object_class that finds the vote images
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",
31 var elem = yield read_browser_object(I);
32 dom_node_click(elem, 1, 1);
34 $browser_object = browser_object_stackexchange_votes);
36 interactive("stackexchange-accept-answer",
37 "Accept an answer on StackExchange site",
39 var elem = yield read_browser_object(I);
40 dom_node_click(elem, 1, 1);
42 $browser_object = browser_object_stackexchange_accept_answers);
44 interactive("stackexchange-favorite-question",
45 "Favorite a question on StackExchange site",
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);
52 if(xpr && (elem = xpr.iterateNext())) {
53 dom_node_click(elem, 1, 1);
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");