-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
58 lines (45 loc) · 1.94 KB
/
core.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//alert(String.fromCharCode(event.keyCode));
var STRING_EMPTY = "";
var highlightCssClass = "nomouse-chrome-extension-highlight";
var pointer = -1;
var selectedUrl = STRING_EMPTY;
var KEY_ARROW_DOWN = 40;
var KEY_ARROW_RIGHT = 39;
var KEY_ARROW_LEFT = 37;
var KEY_ARROW_UP = 38;
var KEY_SPECIAL_ENTER = 13;
document.onkeydown = function (e) {
$("span#knavm").remove() // Remove default and buggy google keyboard navigation
if (e.shiftKey) {
//find all search results
var eles = $("li.g");
var elementsCount = eles.length;
if (e.keyCode == KEY_SPECIAL_ENTER && selectedUrl != STRING_EMPTY) {
//shift + enter = go to highlighted
window.location = selectedUrl;
} else if (e.keyCode == KEY_ARROW_RIGHT) {
window.location = $(".navend:last a").attr("href");
//go to next page
} else if (e.keyCode == KEY_ARROW_LEFT) {
//go to previous page
if ($("td.cur").text()!=1) //if we are on the first page, we can't go back
window.location = $(".navend:first a").attr("href");
}else if (e.keyCode == KEY_ARROW_DOWN || e.keyCode == KEY_ARROW_UP) {
//turn off highlight for previous item
eles.eq(pointer).removeClass(highlightCssClass);
//highlight current item, go out of index and hide highlight
//when user navigates over the limit
if (e.keyCode == KEY_ARROW_DOWN && pointer != elementsCount) {
eles.eq(++pointer).addClass(highlightCssClass);
} else if (e.keyCode == KEY_ARROW_UP && pointer != -1) {
eles.eq(--pointer).addClass(highlightCssClass);
}
//if no visible highlight, reset selectedUrl
if(pointer==-1 || pointer == elementsCount){
selectedUrl = STRING_EMPTY;
}else{
selectedUrl = eles.eq(pointer).find("a[href]:first").attr("href");
}
}
}//shift
};