Compare commits

...

3 Commits

Author SHA1 Message Date
Bauke 16ba17eb9c
Specify which tab to update. 2022-10-26 18:00:42 +02:00
Bauke ed663484e2
Add enabled property to tests. 2022-10-26 14:55:04 +02:00
Bauke 055be574c5
Add an enabled property to redirects. 2022-10-26 14:52:15 +02:00
5 changed files with 8 additions and 2 deletions

View File

@ -39,13 +39,13 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
await browser.storage.local.get(),
)) {
const redirect = parseRedirect(parameters, id);
if (redirect === undefined) {
if (redirect === undefined || !redirect.parameters.enabled) {
continue;
}
if (redirect.isMatch(url)) {
const redirectedUrl = redirect.redirect(url);
await browser.tabs.update({url: redirectedUrl.href});
await browser.tabs.update(details.tabId, {url: redirectedUrl.href});
await browser.storage.local.set({
latestTime: Date.now(),
latestUrl: url.href,

View File

@ -15,6 +15,7 @@ export function narrowRedirectType(value: string): value is RedirectType {
}
export type RedirectParameters = {
enabled: boolean;
matcherType: MatcherType;
matcherValue: string;
redirectType: RedirectType;

View File

@ -16,6 +16,7 @@ import {
} from '../source/redirect/exports.js';
const hostnameParameters: RedirectParameters = {
enabled: true,
matcherType: 'hostname',
matcherValue: 'example.com',
redirectType: 'hostname',
@ -23,6 +24,7 @@ const hostnameParameters: RedirectParameters = {
};
const simpleParameters: RedirectParameters = {
enabled: true,
matcherType: 'hostname',
matcherValue: 'example.com',
redirectType: 'simple',
@ -89,6 +91,7 @@ test('Redirect.isMatch', (t) => {
} as unknown as HostnameRedirect['parameters']);
const regexMatch = new HostnameRedirect({
enabled: true,
matcherType: 'regex',
matcherValue: String.raw`^https://(www\.)?example.org/$`,
redirectType: 'simple',

View File

@ -11,6 +11,7 @@ Generated by [AVA](https://avajs.dev).
HostnameRedirect {
id: 'id',
parameters: {
enabled: true,
matcherType: 'hostname',
matcherValue: 'example.com',
redirectType: 'hostname',
@ -23,6 +24,7 @@ Generated by [AVA](https://avajs.dev).
SimpleRedirect {
id: 'id',
parameters: {
enabled: true,
matcherType: 'hostname',
matcherValue: 'example.com',
redirectType: 'simple',