diff --git a/src/entries/contentScript/main.ts b/src/entries/contentScript/main.ts index 573e556..fdbdd24 100644 --- a/src/entries/contentScript/main.ts +++ b/src/entries/contentScript/main.ts @@ -1,6 +1,5 @@ -import type { Match } from '~/lib/match'; -import { getMatch } from '~/lib/match'; -import { Other, Redirect } from '~/lib/settings'; +import {getMatch, type Match, MatchMediaType} from '~/lib/match'; +import {Other, Redirect} from '~/lib/settings'; async function main() { let match: Match | null; @@ -35,19 +34,19 @@ async function main() { } let url: string | null; - let urlType: 'hls' | 'native'; + let urlType: MatchMediaType | null; try { const matchResult = await match.match(re); if (matchResult && typeof matchResult === 'string') { url = matchResult; - urlType = url.includes('.m3u8') ? 'hls' : 'native'; + urlType = url.includes('.m3u8') ? MatchMediaType.Hls : MatchMediaType.Native; } else if (matchResult && typeof matchResult === 'object') { - if ('hls' in matchResult) { - url = matchResult['hls']; - urlType = 'hls'; - } else if ('native' in matchResult) { - url = matchResult['native']; - urlType = 'native'; + if (MatchMediaType.Hls in matchResult) { + url = matchResult[MatchMediaType.Hls]; + urlType = MatchMediaType.Hls; + } else if (MatchMediaType.Native in matchResult) { + url = matchResult[MatchMediaType.Native]; + urlType = MatchMediaType.Native; } } } catch { @@ -65,7 +64,7 @@ async function main() { await chrome.runtime.sendMessage({ action: 'ff2mpv', url: url }); } - if (match.replace && urlType !== 'hls') { + if (match.replace && urlType != MatchMediaType.Hls) { // this destroys all intervals that may spawn popups or events let intervalId = window.setInterval(() => {}, 0); while (intervalId--) { diff --git a/src/entries/player/player.ts b/src/entries/player/player.ts index 7403236..b88fd98 100644 --- a/src/entries/player/player.ts +++ b/src/entries/player/player.ts @@ -1,6 +1,6 @@ -import { matches } from '~/lib/match'; +import {matches, MatchMediaType} from '~/lib/match'; import Hls from 'hls.js'; -import { UrlReferer } from '~/lib/settings'; +import {UrlReferer} from '~/lib/settings'; async function playNative(url: string, domain: string, videoElem: HTMLVideoElement) { await UrlReferer.set(new URL(url).hostname, domain); @@ -31,7 +31,7 @@ export async function play(videoElem: HTMLVideoElement) { const id = urlQuery.get('id') as string; const url = decodeURIComponent(urlQuery.get('url') as string); const domain = urlQuery.get('domain') as string; - const urlType = urlQuery.get('urlType') as string; + const urlType = urlQuery.get('urlType') as MatchMediaType; const match = matches[id]; if (match === undefined) { @@ -39,9 +39,9 @@ export async function play(videoElem: HTMLVideoElement) { } document.title = `Stream Bypass (${domain})`; - if (urlType === 'hls') { + if (urlType === MatchMediaType.Hls) { await playHls(url, domain, videoElem); - } else if (urlType === 'native') { + } else if (urlType === MatchMediaType.Native) { await playNative(url, domain, videoElem); } } diff --git a/src/lib/match.ts b/src/lib/match.ts index 96f73a1..efeecd7 100644 --- a/src/lib/match.ts +++ b/src/lib/match.ts @@ -10,7 +10,12 @@ export interface Match { regex: RegExp[]; notice?: string; - match(match: RegExpMatchArray): Promise; + match(match: RegExpMatchArray): Promise; +} + +export enum MatchMediaType { + Hls = 'hls', + Native = 'native', } export const Doodstream: Match = { @@ -129,7 +134,7 @@ export const LoadX: Match = { const videoSource: string = responseJson['videoSource']; // extension of extracted url is '.txt', so we have to manually specify that it's a hls - return {hls: videoSource.replace('\\/', '/')}; + return {[MatchMediaType.Hls]: videoSource.replace('\\/', '/')}; } };