minor refactor

This commit is contained in:
2026-01-11 21:17:10 +01:00
parent 67dbb9c685
commit 1cf4940453
2 changed files with 6 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import { getHost, hosts, type Host, type HostMatch } from '@/lib/host'; import { getHost, HostMatchType, hosts, type HostMatch } from '@/lib/host';
import { FF2MPVSettings } from '@/lib/settings'; import { FF2MPVSettings } from '@/lib/settings';
export default defineContentScript({ export default defineContentScript({
@@ -13,10 +13,8 @@ export default defineContentScript({
}); });
async function main() { async function main() {
let host: Host | null; const host = await getHost(window.location.host);
if ((host = await getHost(window.location.host)) === null) { if (!host) return;
return;
}
let re = null; let re = null;
for (const regex of host.regex) { for (const regex of host.regex) {
@@ -24,7 +22,7 @@ async function main() {
break; break;
} }
} }
if (re === null) { if (!re) {
return; return;
} }
@@ -42,7 +40,7 @@ async function main() {
await browser.runtime.sendMessage({ action: 'ff2mpv', url: hostMatch.url }); await browser.runtime.sendMessage({ action: 'ff2mpv', url: hostMatch.url });
} }
if (host.replace && hostMatch.type != 'hls') { if (host.replace && hostMatch.type != HostMatchType.HLS) {
// this destroys all intervals that may spawn popups or events // this destroys all intervals that may spawn popups or events
let intervalId = window.setInterval(() => {}, 0); let intervalId = window.setInterval(() => {}, 0);
while (intervalId--) { while (intervalId--) {

View File

@@ -63,7 +63,7 @@ export const hosts = [
Vupload Vupload
]; ];
export async function getHost(domain: string) { export async function getHost(domain: string): Promise<Host | null> {
if (await HostSettings.getAllHostsDisabled()) return null; if (await HostSettings.getAllHostsDisabled()) return null;
const disabledIds = await HostSettings.getDisabledHosts(); const disabledIds = await HostSettings.getDisabledHosts();