Compare commits
No commits in common. "1fbe1efb908e37ec1d13856b238c53185ae703ae" and "459380cb6984944e287f364120ee620993dba27a" have entirely different histories.
1fbe1efb90
...
459380cb69
|
@ -19,7 +19,7 @@ browser.runtime.onInstalled.addListener(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
browser.webNavigation.onBeforeNavigate.addListener(async (details) => {
|
||||||
if (!details.url.startsWith('http') || details.frameId > 0) {
|
if (!details.url.startsWith('http')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ export default class Usage extends Component {
|
||||||
<td>https://<b>tildes.net</b>/~creative.timasomo</td>
|
<td>https://<b>tildes.net</b>/~creative.timasomo</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="alt">
|
<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 class="center-text">HOL{3}O</td>
|
||||||
<td>https://git.bauke.xyz/<b>holllo</b><sup>2</sup></td>
|
<td>https://git.bauke.xyz/<b>holllo</b><sup>2</sup></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -103,12 +103,6 @@ export default class Usage extends Component {
|
||||||
<td class="center-text">^https?://www\\.holllo\\.org/?$</td>
|
<td class="center-text">^https?://www\\.holllo\\.org/?$</td>
|
||||||
<td><b>https://www.holllo.org/</b></td>
|
<td><b>https://www.holllo.org/</b></td>
|
||||||
</tr>
|
</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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -155,21 +149,11 @@ export default class Usage extends Component {
|
||||||
<td>https://holllo.org/home</td>
|
<td>https://holllo.org/home</td>
|
||||||
<td><b>https://holllo.org</b></td>
|
<td><b>https://holllo.org</b></td>
|
||||||
</tr>
|
</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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<ol class="footnotes">
|
<ol class="footnotes">
|
||||||
<li>The bold highlighted text shows what will be changed.</li>
|
<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>
|
</ol>
|
||||||
</details>
|
</details>
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -28,14 +28,6 @@ const examples: RedirectParameters[] = [
|
||||||
redirectType: 'simple',
|
redirectType: 'simple',
|
||||||
redirectValue: 'https://holllo.org/re-nav',
|
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<
|
export async function generateExamples(): Promise<
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export const matcherTypes = ['hostname', 'regex'] as const;
|
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 MatcherType = typeof matcherTypes[number];
|
||||||
export type RedirectType = typeof redirectTypes[number];
|
export type RedirectType = typeof redirectTypes[number];
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import {RedirectParameters} from './base.js';
|
import {RedirectParameters} from './base.js';
|
||||||
import {HostnameRedirect} from './hostname.js';
|
import {HostnameRedirect} from './hostname.js';
|
||||||
import {RegexRedirect} from './regex.js';
|
|
||||||
import {SimpleRedirect} from './simple.js';
|
import {SimpleRedirect} from './simple.js';
|
||||||
|
|
||||||
export * from './base.js';
|
export * from './base.js';
|
||||||
export * from './hostname.js';
|
export * from './hostname.js';
|
||||||
export * from './regex.js';
|
|
||||||
export * from './simple.js';
|
export * from './simple.js';
|
||||||
|
|
||||||
export type Redirects = HostnameRedirect | SimpleRedirect;
|
export type Redirects = HostnameRedirect | SimpleRedirect;
|
||||||
|
@ -13,7 +11,6 @@ export type Redirects = HostnameRedirect | SimpleRedirect;
|
||||||
export function parseRedirect(
|
export function parseRedirect(
|
||||||
parameters: RedirectParameters,
|
parameters: RedirectParameters,
|
||||||
): Redirects | undefined {
|
): Redirects | undefined {
|
||||||
const matcherType = parameters?.matcherType;
|
|
||||||
const redirectType = parameters?.redirectType;
|
const redirectType = parameters?.redirectType;
|
||||||
|
|
||||||
if (redirectType === 'hostname') {
|
if (redirectType === 'hostname') {
|
||||||
|
@ -23,8 +20,4 @@ export function parseRedirect(
|
||||||
if (redirectType === 'simple') {
|
if (redirectType === 'simple') {
|
||||||
return new SimpleRedirect(parameters);
|
return new SimpleRedirect(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matcherType === 'regex' && redirectType === 'regex') {
|
|
||||||
return new RegexRedirect(parameters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
Redirect,
|
Redirect,
|
||||||
Redirects,
|
Redirects,
|
||||||
RedirectParameters,
|
RedirectParameters,
|
||||||
RegexRedirect,
|
|
||||||
SimpleRedirect,
|
SimpleRedirect,
|
||||||
} from '../source/redirect/exports.js';
|
} from '../source/redirect/exports.js';
|
||||||
|
|
||||||
|
@ -34,15 +33,6 @@ const simpleParameters: RedirectParameters = {
|
||||||
redirectValue: 'https://example.org/simple',
|
redirectValue: 'https://example.org/simple',
|
||||||
};
|
};
|
||||||
|
|
||||||
const regexParameters: RedirectParameters = {
|
|
||||||
enabled: true,
|
|
||||||
id: 3,
|
|
||||||
matcherType: 'regex',
|
|
||||||
matcherValue: '(.+)\\.com',
|
|
||||||
redirectType: 'regex',
|
|
||||||
redirectValue: '$1.org',
|
|
||||||
};
|
|
||||||
|
|
||||||
test('parseRedirect', (t) => {
|
test('parseRedirect', (t) => {
|
||||||
const samples: RedirectParameters[] = [
|
const samples: RedirectParameters[] = [
|
||||||
{
|
{
|
||||||
|
@ -51,7 +41,6 @@ test('parseRedirect', (t) => {
|
||||||
undefined as unknown as RedirectParameters,
|
undefined as unknown as RedirectParameters,
|
||||||
hostnameParameters,
|
hostnameParameters,
|
||||||
simpleParameters,
|
simpleParameters,
|
||||||
regexParameters,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const sample of samples) {
|
for (const sample of samples) {
|
||||||
|
@ -69,21 +58,18 @@ test('parseRedirect', (t) => {
|
||||||
test('Redirect.redirect', (t) => {
|
test('Redirect.redirect', (t) => {
|
||||||
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
|
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
|
||||||
const simpleRedirect = new SimpleRedirect(simpleParameters);
|
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', hostnameRedirect],
|
||||||
['https://example.com/path#hash?query=test', hostnameRedirect],
|
['https://example.com/path#hash?query=test', hostnameRedirect],
|
||||||
['https://example.com', simpleRedirect],
|
['https://example.com', simpleRedirect],
|
||||||
['https://example.com/path', simpleRedirect],
|
['https://example.com/path', simpleRedirect],
|
||||||
['https://example.com', regexRedirect],
|
|
||||||
[new URL('https://example.com'), regexRedirect],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const [index, [url, redirect]] of samples.entries()) {
|
for (const [index, [url, redirect]] of samples.entries()) {
|
||||||
t.snapshot(
|
t.snapshot(
|
||||||
{
|
{
|
||||||
original: url instanceof URL ? url.href : url,
|
original: url,
|
||||||
redirected: redirect.redirect(url).href,
|
redirected: redirect.redirect(url).href,
|
||||||
},
|
},
|
||||||
`${index} ${redirect.constructor.name}`,
|
`${index} ${redirect.constructor.name}`,
|
||||||
|
|
|
@ -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
|
## Redirect.redirect
|
||||||
|
|
||||||
> 0 HostnameRedirect
|
> 0 HostnameRedirect
|
||||||
|
@ -74,17 +61,3 @@ Generated by [AVA](https://avajs.dev).
|
||||||
original: 'https://example.com/path',
|
original: 'https://example.com/path',
|
||||||
redirected: 'https://example.org/simple',
|
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/',
|
|
||||||
}
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue