fix(player): add safeJsonParse and DOM existence check
This commit is contained in:
@@ -65,11 +65,20 @@ const initPlayer = (): void => {
|
|||||||
const animeTitleJapanese = container.getAttribute('data-anime-title-japanese') || ''
|
const animeTitleJapanese = container.getAttribute('data-anime-title-japanese') || ''
|
||||||
const animeImage = container.getAttribute('data-anime-image') || ''
|
const animeImage = container.getAttribute('data-anime-image') || ''
|
||||||
const animeAiring = (container.getAttribute('data-anime-airing') || '').toLowerCase() === 'true'
|
const animeAiring = (container.getAttribute('data-anime-airing') || '').toLowerCase() === 'true'
|
||||||
|
const safeJsonParse = <T>(raw: string | null, fallback: T): T => {
|
||||||
|
if (!raw) return fallback
|
||||||
|
try {
|
||||||
|
return JSON.parse(raw) as T
|
||||||
|
} catch {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const startTimeSeconds = Number.parseFloat(container.getAttribute('data-start-time-seconds') || '0')
|
const startTimeSeconds = Number.parseFloat(container.getAttribute('data-start-time-seconds') || '0')
|
||||||
const modeSources = JSON.parse(container.getAttribute('data-mode-sources') || '{}')
|
const modeSources = safeJsonParse(container.getAttribute('data-mode-sources'), {} as Record<string, string>)
|
||||||
const availableModes = JSON.parse(container.getAttribute('data-available-modes') || '[]')
|
const availableModes = safeJsonParse(container.getAttribute('data-available-modes'), [] as string[])
|
||||||
const initialMode = container.getAttribute('data-initial-mode') || 'dub'
|
const initialMode = container.getAttribute('data-initial-mode') || 'dub'
|
||||||
const segments = JSON.parse(container.getAttribute('data-segments') || '[]')
|
const segments = safeJsonParse(container.getAttribute('data-segments'), [] as SkipSegment[])
|
||||||
const maxIntroStartSeconds = 180
|
const maxIntroStartSeconds = 180
|
||||||
const minOutroStartRatio = 0.5
|
const minOutroStartRatio = 0.5
|
||||||
const minSegmentDurationSeconds = 20
|
const minSegmentDurationSeconds = 20
|
||||||
@@ -820,6 +829,7 @@ const goToNextEpisode = (): void => {
|
|||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
}).then(async (res) => {
|
}).then(async (res) => {
|
||||||
if (!res.ok) return
|
if (!res.ok) return
|
||||||
|
if (!watchStatusDropdown || !watchStatusDropdown.isConnected) return
|
||||||
const html = await res.text()
|
const html = await res.text()
|
||||||
const wrapper = document.createElement('span')
|
const wrapper = document.createElement('span')
|
||||||
wrapper.id = 'watch-status-dropdown'
|
wrapper.id = 'watch-status-dropdown'
|
||||||
|
|||||||
Reference in New Issue
Block a user