feat: add comments and cleanup unused imports across codebase

This commit is contained in:
2026-05-10 20:00:04 +02:00
parent b152e246ff
commit e48d95cb4e
68 changed files with 560 additions and 88 deletions

View File

@@ -1,6 +1,7 @@
import { state } from './state';
import { displayTimeFromAbsolute, absoluteTimeFromDisplay } from './timeline';
import { displayTimeFromAbsolute } from './timeline';
// same as mode.ts - could be extracted to shared util
const streamUrlForMode = (mode: string, quality?: string): string => {
const src = state.modeSources[mode];
if (!src?.token) return '';
@@ -19,6 +20,10 @@ const loadVideo = (url: string): void => {
if (wasPlaying) state.video.play().catch(() => {});
};
/**
* Switches video quality (resolution).
* Persists preference to localStorage.
*/
export const switchQuality = (quality: string): void => {
const url = streamUrlForMode(state.currentMode, quality);
if (!url) return;
@@ -26,6 +31,10 @@ export const switchQuality = (quality: string): void => {
loadVideo(url);
};
/**
* Rebuilds quality dropdown options from current mode's available qualities.
* Shows/hides dropdown based on availability.
*/
export const updateQualityOptions = (): void => {
const select = state.container.querySelector('[data-quality-select]') as HTMLSelectElement | null;
if (!select) return;
@@ -44,13 +53,18 @@ export const updateQualityOptions = (): void => {
select.appendChild(opt);
});
// restore saved preference
const preferred = localStorage.getItem('mal:preferred-quality') || 'best';
select.value = qualities.includes(preferred) ? preferred : 'best';
// hide if no quality options
const wrapper = select.parentElement;
wrapper?.classList.toggle('hidden', qualities.length === 0);
};
/**
* Binds quality select change handler.
*/
export const setupQuality = (): void => {
const select = state.container.querySelector('[data-quality-select]') as HTMLSelectElement | null;
select?.addEventListener('change', e => {