style: apply prettier/eslint quote consistency and add missing comments
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
import tseslint from "@typescript-eslint/eslint-plugin";
|
import tseslint from '@typescript-eslint/eslint-plugin';
|
||||||
import tsParser from "@typescript-eslint/parser";
|
import tsParser from '@typescript-eslint/parser';
|
||||||
import prettier from "eslint-plugin-prettier";
|
import prettier from 'eslint-plugin-prettier';
|
||||||
import eslintConfigPrettier from "eslint-config-prettier";
|
import eslintConfigPrettier from 'eslint-config-prettier';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
ignores: ["dist/**", "node_modules/**", "server", "*.js"],
|
ignores: ['dist/**', 'node_modules/**', 'server', '*.js'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
files: ["**/*.ts"],
|
files: ['**/*.ts'],
|
||||||
plugins: {
|
plugins: {
|
||||||
"@typescript-eslint": tseslint,
|
'@typescript-eslint': tseslint,
|
||||||
prettier,
|
prettier,
|
||||||
},
|
},
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
@@ -18,9 +18,12 @@ export default [
|
|||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
...eslintConfigPrettier.rules,
|
...eslintConfigPrettier.rules,
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" }],
|
'@typescript-eslint/no-unused-vars': [
|
||||||
"prettier/prettier": "error",
|
'warn',
|
||||||
|
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
|
||||||
|
],
|
||||||
|
'prettier/prettier': 'error',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { state } from '../state';
|
import { state } from '../state';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches episode thumbnails and titles from API.
|
||||||
|
* Injects images into episode cards, replaces placeholder.
|
||||||
|
*/
|
||||||
export const setupThumbnails = (): void => {
|
export const setupThumbnails = (): void => {
|
||||||
fetch(`/api/watch/thumbnails/${state.malID}`)
|
fetch(`/api/watch/thumbnails/${state.malID}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
@@ -9,11 +13,13 @@ export const setupThumbnails = (): void => {
|
|||||||
const card = state.episodeList.querySelector(`[data-episode-id="${item.mal_id}"]`);
|
const card = state.episodeList.querySelector(`[data-episode-id="${item.mal_id}"]`);
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
|
||||||
|
// inject thumbnail image
|
||||||
if (item.url) {
|
if (item.url) {
|
||||||
const imgContainer = card.querySelector('.relative.aspect-video');
|
const imgContainer = card.querySelector('.relative.aspect-video');
|
||||||
if (imgContainer) {
|
if (imgContainer) {
|
||||||
let img = imgContainer.querySelector('img');
|
let img = imgContainer.querySelector('img');
|
||||||
if (!img) {
|
if (!img) {
|
||||||
|
// replace placeholder with actual image
|
||||||
img = document.createElement('img');
|
img = document.createElement('img');
|
||||||
img.className =
|
img.className =
|
||||||
'h-full w-full object-cover transition-transform group-hover:scale-105';
|
'h-full w-full object-cover transition-transform group-hover:scale-105';
|
||||||
@@ -28,6 +34,7 @@ export const setupThumbnails = (): void => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inject title text
|
||||||
if (item.title) {
|
if (item.title) {
|
||||||
const titleEl = card.querySelector('[data-episode-title]');
|
const titleEl = card.querySelector('[data-episode-title]');
|
||||||
if (titleEl) titleEl.textContent = item.title;
|
if (titleEl) titleEl.textContent = item.title;
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import { state } from '../state';
|
import { state } from '../state';
|
||||||
import { displayTimeFromAbsolute, absoluteTimeFromDisplay } from '../timeline';
|
import { displayTimeFromAbsolute, absoluteTimeFromDisplay } from '../timeline';
|
||||||
import { showControls } from '../controls';
|
import { showControls } from '../controls';
|
||||||
import { resolveActiveSegments, renderSegments } from './segments';
|
|
||||||
|
|
||||||
|
// button label based on segment type
|
||||||
const skipLabel = (type: string): string => (type === 'ed' ? 'Skip outro' : 'Skip intro');
|
const skipLabel = (type: string): string => (type === 'ed' ? 'Skip outro' : 'Skip intro');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates skip button visibility and auto-skip logic.
|
||||||
|
* Called on timeupdate. Shows button when in active segment.
|
||||||
|
*/
|
||||||
export const updateSkipButton = (currentTime: number): void => {
|
export const updateSkipButton = (currentTime: number): void => {
|
||||||
const btn = state.container.querySelector('[data-skip]') as HTMLButtonElement | null;
|
const btn = state.container.querySelector('[data-skip]') as HTMLButtonElement | null;
|
||||||
const displayTime = displayTimeFromAbsolute(currentTime);
|
const displayTime = displayTimeFromAbsolute(currentTime);
|
||||||
|
|
||||||
|
// find segment that contains current time (with delay buffer)
|
||||||
const segment = state.activeSegments.find(s => {
|
const segment = state.activeSegments.find(s => {
|
||||||
const delay = Math.min(1, Math.max(0.25, (s.end - s.start) * 0.02));
|
const delay = Math.min(1, Math.max(0.25, (s.end - s.start) * 0.02));
|
||||||
return displayTime >= s.start + delay && displayTime < s.end;
|
return displayTime >= s.start + delay && displayTime < s.end;
|
||||||
@@ -20,12 +25,14 @@ export const updateSkipButton = (currentTime: number): void => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// auto-skip: jump to end if enabled
|
||||||
const autoSkip = localStorage.getItem('mal:autoskip-enabled') === 'true';
|
const autoSkip = localStorage.getItem('mal:autoskip-enabled') === 'true';
|
||||||
if (autoSkip && displayTime >= segment.start && displayTime < segment.end) {
|
if (autoSkip && displayTime >= segment.start && displayTime < segment.end) {
|
||||||
state.video.currentTime = absoluteTimeFromDisplay(segment.end + 0.01);
|
state.video.currentTime = absoluteTimeFromDisplay(segment.end + 0.01);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// show skip button
|
||||||
state.activeSkipSegment = segment;
|
state.activeSkipSegment = segment;
|
||||||
if (btn) {
|
if (btn) {
|
||||||
btn.textContent = skipLabel(segment.type);
|
btn.textContent = skipLabel(segment.type);
|
||||||
@@ -34,11 +41,17 @@ export const updateSkipButton = (currentTime: number): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syncs autoskip checkbox with localStorage.
|
||||||
|
*/
|
||||||
export const updateAutoSkipButton = (): void => {
|
export const updateAutoSkipButton = (): void => {
|
||||||
const btn = document.querySelector('[data-autoskip]') as HTMLInputElement | null;
|
const btn = document.querySelector('[data-autoskip]') as HTMLInputElement | null;
|
||||||
btn && (btn.checked = localStorage.getItem('mal:autoskip-enabled') === 'true');
|
btn && (btn.checked = localStorage.getItem('mal:autoskip-enabled') === 'true');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds autoskip toggle change handler.
|
||||||
|
*/
|
||||||
export const setupSkip = (): void => {
|
export const setupSkip = (): void => {
|
||||||
document.addEventListener('change', e => {
|
document.addEventListener('change', e => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { SkipSegment } from '../types';
|
|
||||||
import { state } from '../state';
|
import { state } from '../state';
|
||||||
|
|
||||||
const MIN_SEGMENT_DURATION = 20;
|
// filter bounds for valid segments
|
||||||
const MAX_SEGMENT_DURATION = 240;
|
const MIN_SEGMENT_DURATION = 20; // at least 20s
|
||||||
const MAX_INTRO_START = 180;
|
const MAX_SEGMENT_DURATION = 240; // at most 4 min
|
||||||
const MIN_OUTRO_START_RATIO = 0.5;
|
const MAX_INTRO_START = 180; // intro must start before 3min
|
||||||
|
const MIN_OUTRO_START_RATIO = 0.5; // outro must start at least 50% in
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters parsed segments to only those within video bounds and sensible duration.
|
||||||
|
* Validates intro/outro positioning.
|
||||||
|
*/
|
||||||
export const resolveActiveSegments = (): void => {
|
export const resolveActiveSegments = (): void => {
|
||||||
const bounds = state.video.duration;
|
const bounds = state.video.duration;
|
||||||
if (bounds <= 0) {
|
if (bounds <= 0) {
|
||||||
@@ -15,12 +19,16 @@ export const resolveActiveSegments = (): void => {
|
|||||||
|
|
||||||
state.activeSegments = state.parsedSegments.filter(s => {
|
state.activeSegments = state.parsedSegments.filter(s => {
|
||||||
const len = s.end - s.start;
|
const len = s.end - s.start;
|
||||||
|
// duration filter
|
||||||
if (len < MIN_SEGMENT_DURATION || len > MAX_SEGMENT_DURATION) return false;
|
if (len < MIN_SEGMENT_DURATION || len > MAX_SEGMENT_DURATION) return false;
|
||||||
|
// bounds check
|
||||||
if (s.start < 0 || s.end <= s.start || s.end > bounds + 1) return false;
|
if (s.start < 0 || s.end <= s.start || s.end > bounds + 1) return false;
|
||||||
|
|
||||||
|
// intro: starts early, before 50% of video
|
||||||
if (s.type === 'op') {
|
if (s.type === 'op') {
|
||||||
return s.start <= MAX_INTRO_START && s.start <= bounds * 0.5;
|
return s.start <= MAX_INTRO_START && s.start <= bounds * 0.5;
|
||||||
}
|
}
|
||||||
|
// outro: starts in second half of video
|
||||||
if (s.type === 'ed') {
|
if (s.type === 'ed') {
|
||||||
return s.start >= bounds * MIN_OUTRO_START_RATIO;
|
return s.start >= bounds * MIN_OUTRO_START_RATIO;
|
||||||
}
|
}
|
||||||
@@ -28,6 +36,9 @@ export const resolveActiveSegments = (): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders segment markers on the timeline progress bar.
|
||||||
|
*/
|
||||||
export const renderSegments = (): void => {
|
export const renderSegments = (): void => {
|
||||||
const track = state.container.querySelector('[data-segments]') as HTMLElement | null;
|
const track = state.container.querySelector('[data-segments]') as HTMLElement | null;
|
||||||
if (!track) return;
|
if (!track) return;
|
||||||
@@ -36,6 +47,7 @@ export const renderSegments = (): void => {
|
|||||||
const bounds = state.video.duration;
|
const bounds = state.video.duration;
|
||||||
if (bounds <= 0) return;
|
if (bounds <= 0) return;
|
||||||
|
|
||||||
|
// create small white bars for each segment
|
||||||
state.activeSegments.forEach(s => {
|
state.activeSegments.forEach(s => {
|
||||||
const bar = document.createElement('div');
|
const bar = document.createElement('div');
|
||||||
bar.className = 'absolute top-0 h-full bg-white/80';
|
bar.className = 'absolute top-0 h-full bg-white/80';
|
||||||
|
|||||||
Reference in New Issue
Block a user