Compare commits

..

No commits in common. "1fbe1efb908e37ec1d13856b238c53185ae703ae" and "459380cb6984944e287f364120ee620993dba27a" have entirely different histories.

9 changed files with 5 additions and 86 deletions

View File

@ -19,7 +19,7 @@ browser.runtime.onInstalled.addListener(async () => {
});
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
if (!details.url.startsWith('http') || details.frameId > 0) {
if (!details.url.startsWith('http')) {
return;
}

View File

@ -95,7 +95,7 @@ export default class Usage extends Component {
<td>https://<b>tildes.net</b>/~creative.timasomo</td>
</tr>
<tr class="alt">
<td class="bold center-text" rowspan="3">Regex</td>
<td class="bold center-text" rowspan="2">Regex</td>
<td class="center-text">HOL{3}O</td>
<td>https://git.bauke.xyz/<b>holllo</b><sup>2</sup></td>
</tr>
@ -103,12 +103,6 @@ export default class Usage extends Component {
<td class="center-text">^https?://www\\.holllo\\.org/?$</td>
<td><b>https://www.holllo.org/</b></td>
</tr>
<tr>
<td class="center-text">
${'^(?<base>https://holllo\\.org)/(?<one>1)-(?<two>2)$'}
</td>
<td><b>https://holllo.org/1-2</b></td>
</tr>
</tbody>
</table>
@ -155,21 +149,11 @@ export default class Usage extends Component {
<td>https://holllo.org/home</td>
<td><b>https://holllo.org</b></td>
</tr>
<tr>
<td class="bold center-text">Regex<sup>2</sup></td>
<td>${'$<base>/$<two>-$<one>'}</td>
<td>https://holllo.org/1-2</td>
<td><b>https://holllo.org/2-1</b></td>
</tr>
</tbody>
</table>
<ol class="footnotes">
<li>The bold highlighted text shows what will be changed.</li>
<li>
The regex redirect only works in combination with the regex matcher,
as the regex matcher will be used for the capturing groups.
</li>
</ol>
</details>
`;

View File

@ -28,14 +28,6 @@ const examples: RedirectParameters[] = [
redirectType: 'simple',
redirectValue: 'https://holllo.org/re-nav',
},
{
enabled: true,
id: -1,
matcherType: 'regex',
matcherValue: '^(?<base>https://holllo\\.org)/(?<one>1)-(?<two>2)$',
redirectType: 'regex',
redirectValue: '$<base>/$<two>-$<one>',
},
];
export async function generateExamples(): Promise<

View File

@ -1,5 +1,5 @@
export const matcherTypes = ['hostname', 'regex'] as const;
export const redirectTypes = ['hostname', 'regex', 'simple'] as const;
export const redirectTypes = ['hostname', 'simple'] as const;
export type MatcherType = typeof matcherTypes[number];
export type RedirectType = typeof redirectTypes[number];

View File

@ -1,11 +1,9 @@
import {RedirectParameters} from './base.js';
import {HostnameRedirect} from './hostname.js';
import {RegexRedirect} from './regex.js';
import {SimpleRedirect} from './simple.js';
export * from './base.js';
export * from './hostname.js';
export * from './regex.js';
export * from './simple.js';
export type Redirects = HostnameRedirect | SimpleRedirect;
@ -13,7 +11,6 @@ export type Redirects = HostnameRedirect | SimpleRedirect;
export function parseRedirect(
parameters: RedirectParameters,
): Redirects | undefined {
const matcherType = parameters?.matcherType;
const redirectType = parameters?.redirectType;
if (redirectType === 'hostname') {
@ -23,8 +20,4 @@ export function parseRedirect(
if (redirectType === 'simple') {
return new SimpleRedirect(parameters);
}
if (matcherType === 'regex' && redirectType === 'regex') {
return new RegexRedirect(parameters);
}
}

View File

@ -1,9 +0,0 @@
import {Redirect} from './base.js';
export class RegexRedirect extends Redirect {
public redirect(redirect: URL | string): URL {
const url = redirect instanceof URL ? redirect.href : redirect;
const regex = new RegExp(this.parameters.matcherValue, 'gi');
return new URL(url.replace(regex, this.parameters.redirectValue));
}
}

View File

@ -12,7 +12,6 @@ import {
Redirect,
Redirects,
RedirectParameters,
RegexRedirect,
SimpleRedirect,
} from '../source/redirect/exports.js';
@ -34,15 +33,6 @@ const simpleParameters: RedirectParameters = {
redirectValue: 'https://example.org/simple',
};
const regexParameters: RedirectParameters = {
enabled: true,
id: 3,
matcherType: 'regex',
matcherValue: '(.+)\\.com',
redirectType: 'regex',
redirectValue: '$1.org',
};
test('parseRedirect', (t) => {
const samples: RedirectParameters[] = [
{
@ -51,7 +41,6 @@ test('parseRedirect', (t) => {
undefined as unknown as RedirectParameters,
hostnameParameters,
simpleParameters,
regexParameters,
];
for (const sample of samples) {
@ -69,21 +58,18 @@ test('parseRedirect', (t) => {
test('Redirect.redirect', (t) => {
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
const simpleRedirect = new SimpleRedirect(simpleParameters);
const regexRedirect = new RegexRedirect(regexParameters);
const samples: Array<[string | URL, Redirect]> = [
const samples: Array<[string, Redirect]> = [
['https://example.com', hostnameRedirect],
['https://example.com/path#hash?query=test', hostnameRedirect],
['https://example.com', simpleRedirect],
['https://example.com/path', simpleRedirect],
['https://example.com', regexRedirect],
[new URL('https://example.com'), regexRedirect],
];
for (const [index, [url, redirect]] of samples.entries()) {
t.snapshot(
{
original: url instanceof URL ? url.href : url,
original: url,
redirected: redirect.redirect(url).href,
},
`${index} ${redirect.constructor.name}`,

View File

@ -32,19 +32,6 @@ Generated by [AVA](https://avajs.dev).
},
}
> Class RegexRedirect
RegexRedirect {
parameters: {
enabled: true,
id: 3,
matcherType: 'regex',
matcherValue: '(.+)\\.com',
redirectType: 'regex',
redirectValue: '$1.org',
},
}
## Redirect.redirect
> 0 HostnameRedirect
@ -74,17 +61,3 @@ Generated by [AVA](https://avajs.dev).
original: 'https://example.com/path',
redirected: 'https://example.org/simple',
}
> 4 RegexRedirect
{
original: 'https://example.com',
redirected: 'https://example.org/',
}
> 5 RegexRedirect
{
original: 'https://example.com/',
redirected: 'https://example.org/',
}