Compare commits

..

2 Commits

Author SHA1 Message Date
Bauke 263c0497f3
Add the background script. 2022-10-14 18:15:04 +02:00
Bauke 4cbe31c63a
Turn off no-await-in-loop everywhere. 2022-10-14 18:13:45 +02:00
2 changed files with 39 additions and 3 deletions

View File

@ -70,8 +70,7 @@
{
"files": "tests/**/*.test.ts",
"rules": {
"@typescript-eslint/triple-slash-reference": "off",
"no-await-in-loop": "off"
"@typescript-eslint/triple-slash-reference": "off"
}
}
],
@ -79,7 +78,8 @@
"rules": {
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-type-imports": "off",
"n/file-extension-in-import": "off"
"n/file-extension-in-import": "off",
"no-await-in-loop": "off"
},
"space": true
}

View File

@ -0,0 +1,36 @@
import browser from 'webextension-polyfill';
import {parseRedirect} from '../redirect/exports.js';
async function browserActionClicked() {
await browser.runtime.openOptionsPage();
}
if (import.meta.env.VITE_BROWSER === 'chromium') {
browser.action.onClicked.addListener(browserActionClicked);
} else {
browser.browserAction.onClicked.addListener(browserActionClicked);
}
browser.runtime.onInstalled.addListener(async () => {
if (import.meta.env.DEV) {
await browser.runtime.openOptionsPage();
}
});
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
const url = new URL(details.url);
for (const parameters of Object.values(await browser.storage.local.get())) {
const redirect = parseRedirect(parameters);
if (redirect === undefined) {
continue;
}
if (redirect.isMatch(url)) {
const redirectedUrl = redirect.redirect(url);
await browser.tabs.update({url: redirectedUrl.href});
break;
}
}
});