forked from vimpr/vimperator-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
googlesuggest.js
34 lines (31 loc) · 1.46 KB
/
googlesuggest.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
// Vimperator plugin: 'Completion by Google Suggest'
// Last Change: 22-Oct-2008. Jan 2008
// License: Creative Commons
// Maintainer: Trapezoid <[email protected]> - http://unsigned.g.hatena.ne.jp/Trapezoid
//
// search word completion using Google Suggest script for Vimperator 0.6.*
commands.addUserCommand(['google'],"Search Web sites with Google Suggest",
function(arg){
const endpoint = "http://www.google.co.jp/search?q=";
//liberator.open(endpoint + encodeURIComponent(arg.string));
liberator.open(endpoint + encodeURIComponent(arg.string),liberator.NEW_TAB);
},
{
completer: function (filter) {
const endPoint = "http://suggestqueries.google.com/complete/search?output=firefox&client=firefox"
var [lang] = Components.classes["@mozilla.org/network/protocol;1?name=http"]
.getService(Components.interfaces.nsIHttpProtocolHandler)
.language.split("-", 1);
var xhr = new XMLHttpRequest();
var completionList = [];
xhr.open("GET",endPoint + "&hl=" + lang + "&qu=" + encodeURIComponent(filter),false);
xhr.send(null);
var response = window.eval(xhr.responseText)[1];
response.forEach(function(r) {
completionList.push([r,"Suggests"]);
});
return [0,completionList];
}
}
);
// vim:sw=4 ts=4 et: