forked from thomasst/GoogleShortcuts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
108 lines (99 loc) · 2.8 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// note: key library was modified to enable capture in addEventListener
(function() {
var idx = 0;
var select = function(focus) {
$('div.g a').css('background-color', 'inherit');
var link = $('div.g:nth('+idx+') a:nth(0)');
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();
});
key('l', function(ev) {
var link = $('#pnnext');
if (link.length){
location.href = link.attr('href');
}
ev.stopPropagation();
ev.preventDefault();
});
key('h', function(ev) {
var link = $('#pnprev');
if (link.length){
location.href = link.attr('href');
}
ev.stopPropagation();
ev.preventDefault();
});
var node = null;
$(function() {
document.getElementById('main').addEventListener("DOMSubtreeModified", function () {
var newNode = $('div.g:nth(0) a');
if (!node || (node.attr('href') != newNode.attr('href'))) {
idx = 0;
select(true);
node = newNode;
}
});
});
key('j', function(ev) {
if (idx < $('div.g a').length-1) {
idx++;
select(true);
}
ev.stopPropagation();
});
key('k', function(ev) {
if (idx > 0) {
idx--;
select(true);
}
ev.stopPropagation();
});
key('/', function(ev) {
$('input.gLFyf.gsfi').select();
ev.stopPropagation();
ev.preventDefault();
});
$(function() {
$('div.hdtb-mitem a').each(function(index){
$(this).html($(this).text() + '(' + (index+1).toString()+ ')');
var url = $(this).attr('href');
if (index < 9){
key((index+1).toString(), function(ev){
location.href = url
ev.stopPropagation();
ev.preventDefault();
});
}
});
});
$(function() {
$('span.spell_orig').html( $('span.spell_orig').text() + '(press i to search origin keyword)<br>');
if (! $('a.spell_orig').text()){
$('span.spell').html( $('span.spell').text() + '(press i to search revised keyword)<br>');
}
});
key('i', function(ev) {
var link = $('a.spell_orig');
if (! link.length || ! link.text()){
link = $('a.spell');
}
if (link.length && link.text()){
location.href = link.attr('href');
}
ev.stopPropagation();
ev.preventDefault();
});
})();