-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
45 lines (40 loc) · 1.08 KB
/
background.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
const newWiki = "https://wiki.gtnewhorizons.com";
const excludedPaths = [];
// https://wiki.gtnewhorizons.com/w/index.php?search=asfgadfd&title=Special%3ASearch&wprov=acrw1
browser.webRequest.onBeforeRequest.addListener(
function (details) {
const url = new URL(details.url);
if (url.hostname === "wiki.gtnewhorizons.org") {
console.log("Already at new wiki, not redirecting.");
return;
}
if (url.search.length !== 0) {
let newUrl = `${newWiki}${url.pathname}?${url.searchParams}`;
console.log(
`User search detected, redirecting to search from ${url.href} to ${newUrl}`
);
return {
redirectUrl: newUrl,
};
}
let newUrl = `${newWiki}${url.pathname}?${url.searchParams}`;
console.log(`Redirecting from ${url.href} to ${newUrl}`);
return {
redirectUrl: newUrl,
};
},
{
urls: ["*://gtnh.miraheze.org/*"],
types: [
"main_frame",
"sub_frame",
"stylesheet",
"script",
"image",
"object",
"xmlhttprequest",
"other",
],
},
["blocking"]
);