forked from vimpr/vimperator-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogleselect.js
96 lines (86 loc) · 3.08 KB
/
googleselect.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
// PLUGIN_INFO {{{
let PLUGIN_INFO = xml`
<VimperatorPlugin>
<name>GoogleSelect</name>
<name lang="ja">グーグルセレクト</name>
<description>you can quick select in Google search result page</description>
<description lang="ja">Google検索結果からページ選択を楽にできる</description>
<version>1.0</version>
<author mail="[email protected]" homepage="blog.elzup.com">elzup</author>
<minVersion>1.0</minVersion>
<maxVersion>2.0pre</maxVersion>
<detail lang="ja"><![CDATA[
]]></detail>
</VimperatorPlugin>`;
// }}}
(function () {
var google_url = 'https:\/\/www.google.co.jp\/search.*';
/* user config */
// 選択状態表示マーカー
var SELECT_MARKER_CHAR = '▶';
// マーカー位置微調整
var SELECT_MARKER_REPOSITION_LEFT = '0em';
var SELECT_MARKER_REPOSITION_TOP = '0.3em';
/* hard config */
var GOOGLE_SELECTION_CLASS = 'r';
var GOOGLE_SELECTION_SELECTED_CLASS = 'r-selected';
commands.addUserCommand(
['googleselect'],
'move select in google search result',
function (args) {
var v = 1;
if (args.length && args[0] == 'back') {
v = -1;
}
var $rs = window.content.window.document.getElementsByClassName(GOOGLE_SELECTION_CLASS);
var pre = -1;
for (var i = 0; i < $rs.length; i++) {
if ($rs[i].className.indexOf(GOOGLE_SELECTION_SELECTED_CLASS) != -1) {
pre = i;
break;
}
}
// ターゲット表示スタイル
var $pointer = window.content.window.document.createElement('span');
$pointer.style.color = 'blue';
$pointer.id = 'google-select-pointer';
$pointer.style.position = 'absolute';
$pointer.style.marginTop = SELECT_MARKER_REPOSITION_TOP;
$pointer.style.left = SELECT_MARKER_REPOSITION_LEFT;
$pointer.innerHTML = SELECT_MARKER_CHAR;
if (pre != -1) {
// 現在の選択状態削除
$rs[pre].className = GOOGLE_SELECTION_CLASS;
// $rs[pre].style.borderLeft = "none";
$rs[pre].childNodes[0].blur();
var $e = window.content.window.document.getElementById('google-select-pointer');
$e.parentNode.removeChild($e);
} else if (v == -1) {
pre = $rs.length;
}
if ((pre == 0 && v == -1) || (pre == $rs.length - 1 && v == 1)) {
return;
}
// $rs[pre + v].style.borderLeft = "solid 5px blue";
$rs[pre + v].className = $rs[pre + v].className + " " + GOOGLE_SELECTION_SELECTED_CLASS;
$rs[pre + v].childNodes[0].focus();
$rs[pre + v].parentNode.parentNode.insertBefore($pointer, $rs[pre + v].parentNode.parentNode.firstChild);
},
{
literal: 0,
bang: true,
count: true,
argCount: '?',
options: [],
completer: function (context, args) {
context.title = ['value', 'description'];
context.completions = [
['front', 'move front item'],
['back', 'move back item']
];
}
},
true // replace
);
})();
// vim:sw=2 ts=2 et si fdm=marker: