fix: reinit player safely

This commit is contained in:
2026-05-26 22:20:26 +02:00
parent 6da80df655
commit 30441c3e1f
8 changed files with 96 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ import { updateQualityOptions } from '../quality';
import { updateModeButtons } from '../mode';
import { updateOverlay, isAutoplayEnabled, switchEpisodeRange } from './ui';
import { markEpisodeTransition } from '../progress';
import { safeLocalStorage } from '../storage';
/**
* Handles video end: either marks complete or loads next episode.
@@ -71,7 +72,7 @@ export const goToNextEpisode = async (): Promise<void> => {
state.container.dataset.startTimeSeconds = String(state.startTimeSeconds);
// load new video (keep preferences)
const preferredQuality = localStorage.getItem('mal:preferred-quality') || 'best';
const preferredQuality = safeLocalStorage.getItem('mal:preferred-quality') || 'best';
state.video.src = `${state.streamURL}?mode=${encodeURIComponent(fallback)}&token=${encodeURIComponent(state.modeSources[fallback].token)}${preferredQuality !== 'best' ? `&quality=${encodeURIComponent(preferredQuality)}` : ''}`;
state.video.load();
if (!state.video.paused) {

View File

@@ -1,5 +1,6 @@
import { state } from '../state';
import { qs } from '../../q';
import { safeLocalStorage } from '../storage';
/**
* Syncs autoplay checkbox with localStorage on init.
@@ -8,11 +9,11 @@ import { qs } from '../../q';
export const setupAutoplayButton = (): void => {
const btn = document.querySelector('[data-autoplay]') as HTMLInputElement | null;
if (!btn) return;
btn.checked = localStorage.getItem('mal:autoplay-enabled') !== 'false';
btn.checked = safeLocalStorage.getItem('mal:autoplay-enabled') !== 'false';
};
export const isAutoplayEnabled = (): boolean =>
localStorage.getItem('mal:autoplay-enabled') !== 'false';
safeLocalStorage.getItem('mal:autoplay-enabled') !== 'false';
/**
* Updates video overlay text (shown briefly on episode change).