forked from nettleweb/nettleweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
56 lines (51 loc) · 1.29 KB
/
search.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
"use strict"; (async ({ window: win, document: doc }) => {
if (doc.readyState !== "complete") {
await new Promise((resolve) => {
const callback = () => {
if (doc.readyState === "complete") {
doc.removeEventListener("readystatechange", callback);
setTimeout(resolve, 500, null);
}
};
doc.addEventListener("readystatechange", callback, { passive: true });
});
}
const loc = win.location;
const body = doc.body;
const q = (new URLSearchParams(loc.search).get("q") || "").trim();
if (q.length === 0) {
loc.replace("/");
return;
}
win.stop();
win.focus();
doc.title = q + " - NettleWeb Search";
body.innerHTML = "<div class=\"gcse-search\"></div>";
Object.defineProperty(win, "history", {
value: Object.freeze(Object.setPrototypeOf({
get state() {
return null;
},
get length() {
return 0;
},
get scrollRestoration() {
return "auto";
},
go: () => void 0,
back: () => void 0,
forward: () => void 0,
pushState: () => void 0,
replaceState: () => void 0
}, null)),
writable: false,
enumerable: true,
configurable: false
});
const e = doc.createElement("script");
e.type = "text/javascript";
e.src = "https://cse.google.com/cse.js?cx=6505c81d738124627";
e.async = true;
e.defer = true;
body.appendChild(e);
})(window);