-
Notifications
You must be signed in to change notification settings - Fork 0
/
goodreads-arrow-pager.user.js
43 lines (36 loc) · 1.11 KB
/
goodreads-arrow-pager.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// ==UserScript==
// @name Goodreads giveaways arrow pager
// @namespace randomecho.com
// @description Navigate giveaway pages with left and right arrow keys
// @include https://www.goodreads.com/giveaway*
// @include http://www.goodreads.com/giveaway*
// @grant none
// @copyright 2014 Soon Van
// @author Soon Van - randomecho.com
// @license http://opensource.org/licenses/BSD-3-Clause
// @version 1.1
// ==/UserScript==
function arrowPager(e) {
pager_class = detectArrowKeyPressed(e);
if (pager_class !== false) {
changeToPage(document.getElementsByClassName(pager_class));
}
}
function changeToPage(pager_node) {
if (typeof(pager_node[0]) != 'undefined') {
page_url = pager_node[0].getAttribute('href');
// First and last pager links will not have a URL set
if (page_url) {
document.location = page_url;
}
}
}
function detectArrowKeyPressed(e) {
if (e.keyCode == 39) {
return 'next_page';
} else if (e.keyCode == 37) {
return 'previous_page';
}
return false;
}
document.addEventListener('keydown', arrowPager, false);