Compare commits
3 Commits
a93b5ed92d
...
16ba17eb9c
Author | SHA1 | Date |
---|---|---|
Bauke | 16ba17eb9c | |
Bauke | ed663484e2 | |
Bauke | 055be574c5 |
|
@ -39,13 +39,13 @@ browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
||||||
await browser.storage.local.get(),
|
await browser.storage.local.get(),
|
||||||
)) {
|
)) {
|
||||||
const redirect = parseRedirect(parameters, id);
|
const redirect = parseRedirect(parameters, id);
|
||||||
if (redirect === undefined) {
|
if (redirect === undefined || !redirect.parameters.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirect.isMatch(url)) {
|
if (redirect.isMatch(url)) {
|
||||||
const redirectedUrl = redirect.redirect(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({
|
await browser.storage.local.set({
|
||||||
latestTime: Date.now(),
|
latestTime: Date.now(),
|
||||||
latestUrl: url.href,
|
latestUrl: url.href,
|
||||||
|
|
|
@ -15,6 +15,7 @@ export function narrowRedirectType(value: string): value is RedirectType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RedirectParameters = {
|
export type RedirectParameters = {
|
||||||
|
enabled: boolean;
|
||||||
matcherType: MatcherType;
|
matcherType: MatcherType;
|
||||||
matcherValue: string;
|
matcherValue: string;
|
||||||
redirectType: RedirectType;
|
redirectType: RedirectType;
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
} from '../source/redirect/exports.js';
|
} from '../source/redirect/exports.js';
|
||||||
|
|
||||||
const hostnameParameters: RedirectParameters = {
|
const hostnameParameters: RedirectParameters = {
|
||||||
|
enabled: true,
|
||||||
matcherType: 'hostname',
|
matcherType: 'hostname',
|
||||||
matcherValue: 'example.com',
|
matcherValue: 'example.com',
|
||||||
redirectType: 'hostname',
|
redirectType: 'hostname',
|
||||||
|
@ -23,6 +24,7 @@ const hostnameParameters: RedirectParameters = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const simpleParameters: RedirectParameters = {
|
const simpleParameters: RedirectParameters = {
|
||||||
|
enabled: true,
|
||||||
matcherType: 'hostname',
|
matcherType: 'hostname',
|
||||||
matcherValue: 'example.com',
|
matcherValue: 'example.com',
|
||||||
redirectType: 'simple',
|
redirectType: 'simple',
|
||||||
|
@ -89,6 +91,7 @@ test('Redirect.isMatch', (t) => {
|
||||||
} as unknown as HostnameRedirect['parameters']);
|
} as unknown as HostnameRedirect['parameters']);
|
||||||
|
|
||||||
const regexMatch = new HostnameRedirect({
|
const regexMatch = new HostnameRedirect({
|
||||||
|
enabled: true,
|
||||||
matcherType: 'regex',
|
matcherType: 'regex',
|
||||||
matcherValue: String.raw`^https://(www\.)?example.org/$`,
|
matcherValue: String.raw`^https://(www\.)?example.org/$`,
|
||||||
redirectType: 'simple',
|
redirectType: 'simple',
|
||||||
|
|
|
@ -11,6 +11,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
HostnameRedirect {
|
HostnameRedirect {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
parameters: {
|
parameters: {
|
||||||
|
enabled: true,
|
||||||
matcherType: 'hostname',
|
matcherType: 'hostname',
|
||||||
matcherValue: 'example.com',
|
matcherValue: 'example.com',
|
||||||
redirectType: 'hostname',
|
redirectType: 'hostname',
|
||||||
|
@ -23,6 +24,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
SimpleRedirect {
|
SimpleRedirect {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
parameters: {
|
parameters: {
|
||||||
|
enabled: true,
|
||||||
matcherType: 'hostname',
|
matcherType: 'hostname',
|
||||||
matcherValue: 'example.com',
|
matcherValue: 'example.com',
|
||||||
redirectType: 'simple',
|
redirectType: 'simple',
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue