fix: satisfy typecheck in player
This commit is contained in:
@@ -5,12 +5,14 @@ import { state } from '../state';
|
|||||||
* Injects images into episode cards, replaces placeholder.
|
* Injects images into episode cards, replaces placeholder.
|
||||||
*/
|
*/
|
||||||
export const setupThumbnails = (): void => {
|
export const setupThumbnails = (): void => {
|
||||||
|
const episodeList = state.episodeList;
|
||||||
|
if (!episodeList) return;
|
||||||
|
|
||||||
fetch(`/api/watch/thumbnails/${state.malID}`)
|
fetch(`/api/watch/thumbnails/${state.malID}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then((data: { mal_id: number; url: string; title?: string }[]) => {
|
.then((data: { mal_id: number; url: string; title?: string }[]) => {
|
||||||
if (!state.episodeList) return;
|
|
||||||
data.forEach(item => {
|
data.forEach(item => {
|
||||||
const card = state.episodeList.querySelector(`[data-episode-id="${item.mal_id}"]`);
|
const card = episodeList.querySelector(`[data-episode-id="${item.mal_id}"]`);
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
|
||||||
// inject thumbnail image
|
// inject thumbnail image
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ export const switchMode = (mode: string): void => {
|
|||||||
if (!state.availableModes.includes(mode) || mode === state.currentMode) return;
|
if (!state.availableModes.includes(mode) || mode === state.currentMode) return;
|
||||||
state.currentMode = mode;
|
state.currentMode = mode;
|
||||||
localStorage.setItem('player-audio-mode', mode);
|
localStorage.setItem('player-audio-mode', mode);
|
||||||
loadVideo(streamUrlForMode(mode, state.container.querySelector('[data-quality-select]')?.value));
|
const qualitySelect = state.container.querySelector(
|
||||||
|
'[data-quality-select]'
|
||||||
|
) as HTMLSelectElement | null;
|
||||||
|
loadVideo(streamUrlForMode(mode, qualitySelect?.value));
|
||||||
updateSubtitleOptions();
|
updateSubtitleOptions();
|
||||||
updateQualityOptions();
|
updateQualityOptions();
|
||||||
updateModeButtons();
|
updateModeButtons();
|
||||||
|
|||||||
@@ -105,27 +105,18 @@ const findElement = <T extends Element>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const requiredPlayerElements = (container: HTMLElement): RequiredPlayerElements | null => {
|
const requiredPlayerElements = (container: HTMLElement): RequiredPlayerElements | null => {
|
||||||
const elements = {
|
const video = findElement(container, 'video', HTMLVideoElement);
|
||||||
video: findElement(container, 'video', HTMLVideoElement),
|
const progress = findElement(container, '[data-progress]', HTMLElement);
|
||||||
progress: findElement(container, '[data-progress]', HTMLElement),
|
const scrubber = findElement(container, '[data-scrubber]', HTMLElement);
|
||||||
scrubber: findElement(container, '[data-scrubber]', HTMLElement),
|
const buffered = findElement(container, '[data-buffered]', HTMLElement);
|
||||||
buffered: findElement(container, '[data-buffered]', HTMLElement),
|
const timeDisplay = findElement(container, '[data-time]', HTMLElement);
|
||||||
timeDisplay: findElement(container, '[data-time]', HTMLElement),
|
const durationDisplay = findElement(container, '[data-duration]', HTMLElement);
|
||||||
durationDisplay: findElement(container, '[data-duration]', HTMLElement),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (
|
if (!video || !progress || !scrubber || !buffered || !timeDisplay || !durationDisplay) {
|
||||||
!elements.video ||
|
|
||||||
!elements.progress ||
|
|
||||||
!elements.scrubber ||
|
|
||||||
!elements.buffered ||
|
|
||||||
!elements.timeDisplay ||
|
|
||||||
!elements.durationDisplay
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return elements;
|
return { video, progress, scrubber, buffered, timeDisplay, durationDisplay };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user