2022-10-27 19:13:02 +00:00
|
|
|
import browser from 'webextension-polyfill';
|
|
|
|
|
|
|
|
import {RedirectParameters} from '../redirect/base.js';
|
|
|
|
import storage from '../redirect/storage.js';
|
2022-10-27 13:48:34 +00:00
|
|
|
|
|
|
|
const examples: RedirectParameters[] = [
|
|
|
|
{
|
|
|
|
enabled: true,
|
2022-10-27 19:13:02 +00:00
|
|
|
id: -1,
|
2022-10-27 13:48:34 +00:00
|
|
|
matcherType: 'hostname',
|
|
|
|
matcherValue: 'twitter.com',
|
|
|
|
redirectType: 'hostname',
|
|
|
|
redirectValue: 'nitter.net',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enabled: true,
|
2022-10-27 19:13:02 +00:00
|
|
|
id: -1,
|
2022-10-27 13:48:34 +00:00
|
|
|
matcherType: 'hostname',
|
|
|
|
matcherValue: 'reddit.com',
|
|
|
|
redirectType: 'hostname',
|
|
|
|
redirectValue: 'r.nf',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enabled: true,
|
2022-10-27 19:13:02 +00:00
|
|
|
id: -1,
|
2022-10-27 13:48:34 +00:00
|
|
|
matcherType: 'regex',
|
|
|
|
matcherValue: '^https?://holllo\\.org/renav/?$',
|
|
|
|
redirectType: 'simple',
|
|
|
|
redirectValue: 'https://holllo.org/re-nav',
|
|
|
|
},
|
2022-11-02 10:30:02 +00:00
|
|
|
{
|
|
|
|
enabled: true,
|
|
|
|
id: -1,
|
|
|
|
matcherType: 'regex',
|
|
|
|
matcherValue: '^(?<base>https://holllo\\.org)/(?<one>1)-(?<two>2)$',
|
|
|
|
redirectType: 'regex',
|
|
|
|
redirectValue: '$<base>/$<two>-$<one>',
|
|
|
|
},
|
2022-10-27 13:48:34 +00:00
|
|
|
];
|
|
|
|
|
2022-10-27 19:13:02 +00:00
|
|
|
export async function generateExamples(): Promise<
|
|
|
|
Record<string, RedirectParameters>
|
|
|
|
> {
|
|
|
|
const prepared: Record<string, RedirectParameters> = {};
|
|
|
|
let nextId = await storage.nextRedirectId();
|
2022-10-27 13:48:34 +00:00
|
|
|
for (const example of examples) {
|
2022-10-27 19:13:02 +00:00
|
|
|
example.id = nextId;
|
|
|
|
prepared[`redirect:${nextId}`] = example;
|
|
|
|
nextId += 1;
|
2022-10-27 13:48:34 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 19:13:02 +00:00
|
|
|
await browser.storage.local.set({latestId: nextId - 1});
|
|
|
|
return prepared;
|
2022-10-27 13:48:34 +00:00
|
|
|
}
|