-
Notifications
You must be signed in to change notification settings - Fork 123
/
google-exopen.js
41 lines (35 loc) · 1.15 KB
/
google-exopen.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
// INFO {{{
var PLUGIN_INFO = xml`
<VimperatorPlugin>
<name>google-exopen</name>
<description>useful in google search</description>
<description lang="ja">openを拡張し前回のGoogle検索クエリを入力済みにする</description>
<author>akameco</author>
<license>New BSD License</license>
<version>0.1</version>
</VimperatorPlugin>`;
// }}}
(function () {
const original = mappings.getDefault(modes.NORMAL, 'o');
mappings.addUserMap([modes.NORMAL], ['o'], ':open', () => {
const location = window.content.window.location;
// google検索か判定
if (!/www.google/.test(location.host)) {
return original.action.apply(this, arguments);
}
const str = location.hash.length === 0 ? location.search : location.hash;
const query = str.replace(/^(\?|#|&)/, '');
let ret = {};
query.split('&').forEach(param => {
const parts = param.replace(/\+/g, ' ').split('=');
const key = parts.shift();
const val = decodeURIComponent(parts) || '';
ret[key] = val;
});
if (ret.q) {
commandline.open('', commands.commandToString({command: `open ${ret.q}`}), modes.EX);
} else {
original.action.apply(this, arguments);
}
});
})();