Fix linting errors

This commit is contained in:
2024-07-14 21:07:51 +02:00
parent c57cd03407
commit 1c9f95cebc
8 changed files with 34 additions and 29 deletions

View File

@@ -56,7 +56,7 @@ export const DropLoad: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
return unpacked.match(/(?<=file:").*(?=")/)[0];
return unpacked.match(/(?<=file:").*(?=")/)![0];
}
};
@@ -68,7 +68,7 @@ export const Filemoon: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
return unpacked.match(/(?<=file:").*(?=")/)[0];
return unpacked.match(/(?<=file:").*(?=")/)![0];
}
};
@@ -91,7 +91,7 @@ export const Kwik: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
return unpacked.match(/(?<=source=').*(?=')/)[0];
return unpacked.match(/(?<=source=').*(?=')/)![0];
}
};
@@ -103,7 +103,7 @@ export const Mixdrop: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
const url = unpacked.match(/(?<=MDCore.wurl=").*(?=")/)[0];
const url = unpacked.match(/(?<=MDCore.wurl=").*(?=")/)![0];
return `https:${url}`;
}
};
@@ -117,7 +117,7 @@ export const Mp4Upload: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
return unpacked.match(/(?<=player.src\(").*(?=")/)[0];
return unpacked.match(/(?<=player.src\(").*(?=")/)![0];
}
};
@@ -179,7 +179,7 @@ export const SuperVideo: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
return unpacked.match(/(?<=file:").*(?=")/)[0];
return unpacked.match(/(?<=file:").*(?=")/)![0];
}
};
@@ -191,7 +191,7 @@ export const Upstream: Match = {
match: async (match: RegExpMatchArray) => {
const unpacked = await unpack(match[0]);
return unpacked.match(/(?<=file:").*(?=")/)[0];
return unpacked.match(/(?<=file:").*(?=")/)![0];
}
};

View File

@@ -3,11 +3,11 @@ import { matches } from './match';
export const Hosters = {
getDisabled: async () => {
const disabled = await storageGet<string[]>('hosters.disabled', []);
const disabled = (await storageGet('hosters.disabled', [])) as string[];
return disabled.map((id) => matches[id]).filter((m) => m !== undefined);
},
disable: async (match: Match) => {
const disabled = await storageGet('hosters.disabled', []);
const disabled = (await storageGet('hosters.disabled', [])) as string[];
const index = disabled.indexOf(match.id);
if (index === -1) {
disabled.push(match.id);
@@ -15,7 +15,7 @@ export const Hosters = {
}
},
enable: async (match: Match) => {
const disabled = await storageGet('hosters.disabled', []);
const disabled = (await storageGet('hosters.disabled', [])) as string[];
const index = disabled.indexOf(match.id);
if (index !== -1) {
disabled.splice(index, 1);
@@ -35,7 +35,7 @@ export const Hosters = {
export const Redirect = {
get: async (): Promise<Match | null> => {
return matches[await storageGet<string>('redirect')] || null;
return matches[(await storageGet('redirect')) as string] || null;
},
set: async (match: Match) => {
await storageSet('redirect', match.id);

View File

@@ -19,7 +19,7 @@ export async function unpack(packed: string): Promise<string> {
}'
`;
const res: string = await runInPageContext(toExecute);
const res = (await runInPageContext(toExecute)) as string;
return res
.replace(/;/g, ';\n')
.replace(/{/g, '\n{\n')
@@ -29,7 +29,7 @@ export async function unpack(packed: string): Promise<string> {
}
// Adapted from: https://github.com/arikw/extension-page-context
async function runInPageContext<T>(toExecute: string): Promise<T> {
async function runInPageContext<T>(toExecute: string): Promise<T | null> {
// test that we are running with the allow-scripts permission
try {
window.sessionStorage;
@@ -44,7 +44,8 @@ async function runInPageContext<T>(toExecute: string): Promise<T> {
const scriptElm = document.createElement('script');
scriptElm.setAttribute('type', 'application/javascript');
const code = `
// inject the script
scriptElm.textContent = `
(
async function () {
@@ -63,9 +64,6 @@ async function runInPageContext<T>(toExecute: string): Promise<T> {
)();
`;
// inject the script
scriptElm.textContent = code;
// run the script
document.documentElement.appendChild(scriptElm);