Fix false-positive error message

This commit is contained in:
bytedream 2022-09-10 18:10:48 +02:00
parent 1a7c22ec0e
commit 6da0050df4
2 changed files with 18 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import {getMatch} from "./match/match"; import {getMatch} from "./match/match";
import {storageGet, storageSet} from "./store/store"; import {storageDelete, storageGet, storageSet} from "./store/store";
import {Match} from "./match/matches"; import {Match} from "./match/matches";
chrome.webRequest.onBeforeRedirect.addListener(async details => { chrome.webRequest.onBeforeRedirect.addListener(async details => {
@ -9,6 +9,8 @@ chrome.webRequest.onBeforeRedirect.addListener(async details => {
if ((match = await getMatch(new URL(details.url).host)) !== undefined) { if ((match = await getMatch(new URL(details.url).host)) !== undefined) {
await storageSet('redirect', match.id) await storageSet('redirect', match.id)
} }
} else {
await storageDelete('redirect')
} }
}, { }, {
urls: ['<all_urls>'], urls: ['<all_urls>'],

View File

@ -8,13 +8,15 @@ function show_message(message: string) {
document.getElementById('video').hidden = true document.getElementById('video').hidden = true
} }
async function check_loaded(match: Match, check: () => boolean) { async function check_loaded(match: Match, check: Promise<boolean>) {
const loaded = await new Promise((resolve, reject) => { const loaded = await new Promise((resolve, _) => {
setTimeout(() => { setTimeout(() => {
resolve(false) resolve(false)
}, match.reliability * 3000) }, match.reliability * 3000)
check() ? resolve(true) : resolve(false) check
.then(value => resolve(value))
.catch(_ => resolve(false))
}) })
if (!loaded) { if (!loaded) {
@ -43,7 +45,11 @@ async function play_native(url: string, match: Match) {
video.controls = true video.controls = true
video.src = url video.src = url
await check_loaded(match, () => { return video.readyState >= 3 }) const readyState = new Promise<boolean>((resolve, _) => {
video.onloadeddata = () => resolve(true)
})
await check_loaded(match, readyState)
} }
async function play_hls(url: string, match: Match) { async function play_hls(url: string, match: Match) {
@ -59,7 +65,11 @@ async function play_hls(url: string, match: Match) {
hls.loadSource(url) hls.loadSource(url)
hls.attachMedia(video) hls.attachMedia(video)
await check_loaded(match, () => { return video.readyState >= 3 }) const readyState = new Promise<boolean>((resolve, _) => {
video.onloadeddata = () => resolve(true)
})
await check_loaded(match, readyState)
} else { } else {
show_message('Failed to play m3u8 video (hls is not supported). Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues/new">here</a>') show_message('Failed to play m3u8 video (hls is not supported). Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues/new">here</a>')
} }