-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-search-result-helper.user.js
63 lines (55 loc) · 1.6 KB
/
google-search-result-helper.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ==UserScript==
// @name google-search-result-helper
// @namespace https://github.com/nhosoya
// @version 0.2.8
// @description Shortcut(j, k, /) for Google search result
// @author nhosoya
// @include https://www.google.co.jp/search?*
// @include https://www.google.com/search?*
// @require https://cdnjs.cloudflare.com/ajax/libs/keymaster/1.6.1/keymaster.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/Caret.js/0.3.1/jquery.caret.min.js
// @grant none
// ==/UserScript==
(function () {
"use strict";
let focusSearchBox = function () {
let searchBox = $("form[role='search'] input[type='text']");
var temp = searchBox.val();
searchBox.focus();
searchBox.val("");
searchBox.val(temp);
return false;
};
var i = -1;
var resultLinks = $(
'.g a:not(".fl"):not(".ab_button"):not(".exp-r"):not(".GHDvEf")'
);
let focusNextLink = function () {
i++;
validateIndex();
resultLinks[i].focus();
return false;
};
let focusPreviousLink = function () {
i--;
validateIndex();
resultLinks[i].focus();
return false;
};
let validateIndex = function () {
i = Math.max(i, 0);
i = Math.min(i, resultLinks.length - 1);
};
let startImageSearch = function () {
if (location.search.includes("tbm=isch")) {
return false;
}
location.href += "&tbm=isch";
return false;
};
key("/", focusSearchBox);
key("j", focusNextLink);
key("k", focusPreviousLink);
key("i", startImageSearch);
})();