-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
27 lines (24 loc) · 954 Bytes
/
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
browser.webRequest.onBeforeRequest.addListener(
async function(details) {
const url = new URL(details.url);
const { skin, isEnabled, forceSkin } = await browser.storage.sync.get({ skin: 'timeless', isEnabled: true, forceSkin: false });
if (!isEnabled) {
return;
}
// Redirect to the non-mobile version if mobile link is detected
if (url.hostname.startsWith('m.')) {
url.hostname = url.hostname.replace('m.', '');
}
// Check if the skin is already set
if (forceSkin || !url.searchParams.has('useskin')) {
const { skin } = await browser.storage.sync.get({ skin: 'timeless' });
url.searchParams.set('useskin', skin);
}
const newUrl = url.toString();
if (newUrl !== details.url) {
return { redirectUrl: newUrl };
}
},
{ urls: ["*://*.wikipedia.org/wiki/*"] },
["blocking"]
);