mirror of
https://github.com/bytedream/stream-bypass.git
synced 2025-05-11 13:15:13 +02:00
Fix linting errors
This commit is contained in:
parent
c57cd03407
commit
1c9f95cebc
@ -5,11 +5,13 @@ import { storageDelete, storageGet, storageSet } from '~/lib/settings';
|
|||||||
import { getMatch } from '~/lib/match';
|
import { getMatch } from '~/lib/match';
|
||||||
|
|
||||||
chrome.webRequest.onBeforeSendHeaders.addListener(
|
chrome.webRequest.onBeforeSendHeaders.addListener(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
async (details) => {
|
async (details) => {
|
||||||
const referer: { domain: string } | undefined = await storageGet('referer');
|
const referer: { domain: string } | undefined = await storageGet('referer');
|
||||||
if (referer === undefined) return;
|
if (referer === undefined) return;
|
||||||
|
|
||||||
details.requestHeaders.push({
|
details.requestHeaders!.push({
|
||||||
name: 'Referer',
|
name: 'Referer',
|
||||||
value: `https://${referer.domain}/`
|
value: `https://${referer.domain}/`
|
||||||
});
|
});
|
||||||
@ -26,8 +28,8 @@ chrome.webRequest.onBeforeRedirect.addListener(
|
|||||||
async (details) => {
|
async (details) => {
|
||||||
// check if redirects origins from a previous redirect
|
// check if redirects origins from a previous redirect
|
||||||
if ((await storageGet('redirect')) === undefined) {
|
if ((await storageGet('redirect')) === undefined) {
|
||||||
let match: Match;
|
let match: Match | null;
|
||||||
if ((match = await getMatch(new URL(details.url).hostname)) !== undefined) {
|
if ((match = await getMatch(new URL(details.url).hostname)) !== null) {
|
||||||
await storageSet('redirect', match.id);
|
await storageSet('redirect', match.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,7 +3,7 @@ import { getMatch } from '~/lib/match';
|
|||||||
import { Other, Redirect } from '~/lib/settings';
|
import { Other, Redirect } from '~/lib/settings';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
let match: Match;
|
let match: Match | null;
|
||||||
let redirect = false;
|
let redirect = false;
|
||||||
if ((match = await getMatch(window.location.host)) === null) {
|
if ((match = await getMatch(window.location.host)) === null) {
|
||||||
if ((match = await Redirect.get()) === null) {
|
if ((match = await Redirect.get()) === null) {
|
||||||
@ -20,7 +20,12 @@ async function main() {
|
|||||||
await Redirect.delete();
|
await Redirect.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = await match.match(re);
|
let url: string;
|
||||||
|
try {
|
||||||
|
url = await match.match(re);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// send the url to the ff2mpv (https://github.com/woodruffw/ff2mpv) application
|
// send the url to the ff2mpv (https://github.com/woodruffw/ff2mpv) application
|
||||||
if (await Other.getFf2mpv()) {
|
if (await Other.getFf2mpv()) {
|
||||||
|
@ -22,9 +22,9 @@ async function playHls(url: string, videoElem: HTMLVideoElement) {
|
|||||||
|
|
||||||
export async function play(videoElem: HTMLVideoElement) {
|
export async function play(videoElem: HTMLVideoElement) {
|
||||||
const urlQuery = new URLSearchParams(window.location.search);
|
const urlQuery = new URLSearchParams(window.location.search);
|
||||||
const id = urlQuery.get('id');
|
const id = urlQuery.get('id') as string;
|
||||||
const url = decodeURIComponent(urlQuery.get('url'));
|
const url = decodeURIComponent(urlQuery.get('url') as string);
|
||||||
const domain = urlQuery.get('domain');
|
const domain = urlQuery.get('domain') as string;
|
||||||
|
|
||||||
const match = matches[id];
|
const match = matches[id];
|
||||||
if (match === undefined) {
|
if (match === undefined) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import App from './Popup.svelte';
|
import App from './Popup.svelte';
|
||||||
|
|
||||||
new App({
|
new App({
|
||||||
target: document.getElementById('app')
|
target: document.getElementById('app') as Element
|
||||||
});
|
});
|
||||||
|
@ -56,7 +56,7 @@ export const DropLoad: Match = {
|
|||||||
|
|
||||||
match: async (match: RegExpMatchArray) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
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) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
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) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
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) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
const unpacked = await unpack(match[0]);
|
||||||
const url = unpacked.match(/(?<=MDCore.wurl=").*(?=")/)[0];
|
const url = unpacked.match(/(?<=MDCore.wurl=").*(?=")/)![0];
|
||||||
return `https:${url}`;
|
return `https:${url}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -117,7 +117,7 @@ export const Mp4Upload: Match = {
|
|||||||
|
|
||||||
match: async (match: RegExpMatchArray) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
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) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
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) => {
|
match: async (match: RegExpMatchArray) => {
|
||||||
const unpacked = await unpack(match[0]);
|
const unpacked = await unpack(match[0]);
|
||||||
return unpacked.match(/(?<=file:").*(?=")/)[0];
|
return unpacked.match(/(?<=file:").*(?=")/)![0];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,11 +3,11 @@ import { matches } from './match';
|
|||||||
|
|
||||||
export const Hosters = {
|
export const Hosters = {
|
||||||
getDisabled: async () => {
|
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);
|
return disabled.map((id) => matches[id]).filter((m) => m !== undefined);
|
||||||
},
|
},
|
||||||
disable: async (match: Match) => {
|
disable: async (match: Match) => {
|
||||||
const disabled = await storageGet('hosters.disabled', []);
|
const disabled = (await storageGet('hosters.disabled', [])) as string[];
|
||||||
const index = disabled.indexOf(match.id);
|
const index = disabled.indexOf(match.id);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
disabled.push(match.id);
|
disabled.push(match.id);
|
||||||
@ -15,7 +15,7 @@ export const Hosters = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
enable: async (match: Match) => {
|
enable: async (match: Match) => {
|
||||||
const disabled = await storageGet('hosters.disabled', []);
|
const disabled = (await storageGet('hosters.disabled', [])) as string[];
|
||||||
const index = disabled.indexOf(match.id);
|
const index = disabled.indexOf(match.id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
disabled.splice(index, 1);
|
disabled.splice(index, 1);
|
||||||
@ -35,7 +35,7 @@ export const Hosters = {
|
|||||||
|
|
||||||
export const Redirect = {
|
export const Redirect = {
|
||||||
get: async (): Promise<Match | null> => {
|
get: async (): Promise<Match | null> => {
|
||||||
return matches[await storageGet<string>('redirect')] || null;
|
return matches[(await storageGet('redirect')) as string] || null;
|
||||||
},
|
},
|
||||||
set: async (match: Match) => {
|
set: async (match: Match) => {
|
||||||
await storageSet('redirect', match.id);
|
await storageSet('redirect', match.id);
|
||||||
|
@ -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
|
return res
|
||||||
.replace(/;/g, ';\n')
|
.replace(/;/g, ';\n')
|
||||||
.replace(/{/g, '\n{\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
|
// 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
|
// test that we are running with the allow-scripts permission
|
||||||
try {
|
try {
|
||||||
window.sessionStorage;
|
window.sessionStorage;
|
||||||
@ -44,7 +44,8 @@ async function runInPageContext<T>(toExecute: string): Promise<T> {
|
|||||||
const scriptElm = document.createElement('script');
|
const scriptElm = document.createElement('script');
|
||||||
scriptElm.setAttribute('type', 'application/javascript');
|
scriptElm.setAttribute('type', 'application/javascript');
|
||||||
|
|
||||||
const code = `
|
// inject the script
|
||||||
|
scriptElm.textContent = `
|
||||||
(
|
(
|
||||||
async function () {
|
async function () {
|
||||||
|
|
||||||
@ -63,9 +64,6 @@ async function runInPageContext<T>(toExecute: string): Promise<T> {
|
|||||||
)();
|
)();
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// inject the script
|
|
||||||
scriptElm.textContent = code;
|
|
||||||
|
|
||||||
// run the script
|
// run the script
|
||||||
document.documentElement.appendChild(scriptElm);
|
document.documentElement.appendChild(scriptElm);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ const ManifestV2 = {
|
|||||||
scripts: ['src/entries/background/mv2.ts'],
|
scripts: ['src/entries/background/mv2.ts'],
|
||||||
persistent: true
|
persistent: true
|
||||||
},
|
},
|
||||||
content_scripts: [{ ...sharedManifest.content_scripts[0], matches: ['<all_urls>'] }],
|
content_scripts: [{ ...sharedManifest.content_scripts![0], matches: ['<all_urls>'] }],
|
||||||
browser_action: browserAction,
|
browser_action: browserAction,
|
||||||
permissions: [...sharedManifest.permissions, 'webRequest', 'webRequestBlocking', '<all_urls>']
|
permissions: [...sharedManifest.permissions, 'webRequest', 'webRequestBlocking', '<all_urls>']
|
||||||
};
|
};
|
||||||
@ -67,7 +67,7 @@ export function getManifest(
|
|||||||
...manifest,
|
...manifest,
|
||||||
...ManifestV2,
|
...ManifestV2,
|
||||||
manifest_version: manifestVersion
|
manifest_version: manifestVersion
|
||||||
};
|
} as chrome.runtime.ManifestV2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manifestVersion === 3) {
|
if (manifestVersion === 3) {
|
||||||
@ -78,7 +78,7 @@ export function getManifest(
|
|||||||
name: `${manifest.name} Lite`,
|
name: `${manifest.name} Lite`,
|
||||||
...ManifestV3,
|
...ManifestV3,
|
||||||
manifest_version: manifestVersion
|
manifest_version: manifestVersion
|
||||||
};
|
} as chrome.runtime.ManifestV3;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Missing manifest definition for manifestVersion ${manifestVersion}`);
|
throw new Error(`Missing manifest definition for manifestVersion ${manifestVersion}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user