-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathscript.js
57 lines (53 loc) · 1.47 KB
/
script.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
// note: key library was modified to enable capture in addEventListener
(function() {
var idx = 0;
var select = function(focus) {
$('h3.r a').css('background-color', 'inherit');
var link = $('h3.r:nth('+idx+') a');
link.css('background-color', '#fcc');
if (focus) {link.focus(); }
return link;
};
key('⌘+return', function(ev) {
var link = select();
window.open(link.attr('href'));
ev.stopPropagation();
ev.preventDefault();
});
key('return', function(ev) {
var link = select();
location.href = link.attr('href');
ev.stopPropagation();
ev.preventDefault();
});
var node = null;
$(function() {
document.getElementById('main').addEventListener("DOMSubtreeModified", function () {
var newNode = $('h3.r:nth(0) a');
if (!node || (node.attr('href') != newNode.attr('href'))) {
idx = 0;
select();
node = newNode;
}
});
});
key('j', function(ev) {
if (idx < $('h3.r a').length-1) {
idx++;
select(true);
}
ev.stopPropagation();
});
key('k', function(ev) {
if (idx > 0) {
idx--;
select(true);
}
ev.stopPropagation();
});
key('/', function(ev) {
$('#gbqfq').focus();
ev.stopPropagation();
ev.preventDefault();
});
})();