style: format static/player/skip/index.ts
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
import { state } from "../state";
|
|
||||||
import { displayTimeFromAbsolute, absoluteTimeFromDisplay } from "../timeline";
|
|
||||||
import { showControls } from "../controls";
|
import { showControls } from "../controls";
|
||||||
import { saveProgress } from "../progress";
|
import { saveProgress } from "../progress";
|
||||||
|
import { state } from "../state";
|
||||||
import { safeLocalStorage } from "../storage";
|
import { safeLocalStorage } from "../storage";
|
||||||
|
import { displayTimeFromAbsolute, absoluteTimeFromDisplay } from "../timeline";
|
||||||
|
|
||||||
// button label based on segment type
|
// 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.
|
* Updates skip button visibility and auto-skip logic. Called on timeupdate. Shows button when in
|
||||||
* Called on timeupdate. Shows button when in active segment.
|
* active segment.
|
||||||
*/
|
*/
|
||||||
export const updateSkipButton = (currentTime: number): void => {
|
export const updateSkipButton = (currentTime: number): void => {
|
||||||
const btn = state.elements.container.querySelector("[data-skip]") as HTMLButtonElement | null;
|
const btn = state.elements.container.querySelector("[data-skip]") as HTMLButtonElement | null;
|
||||||
@@ -46,22 +46,20 @@ export const updateSkipButton = (currentTime: number): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** Syncs autoskip checkbox with localStorage. */
|
||||||
* 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;
|
||||||
if (!btn) return;
|
if (!btn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
btn.checked = safeLocalStorage.getItem("mal:autoskip-enabled") === "true";
|
btn.checked = safeLocalStorage.getItem("mal:autoskip-enabled") === "true";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** Binds autoskip toggle change handler. */
|
||||||
* 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;
|
||||||
if (target.hasAttribute("data-autoskip")) {
|
if (Object.hasOwn(target.dataset, "autoskip")) {
|
||||||
safeLocalStorage.setItem(
|
safeLocalStorage.setItem(
|
||||||
"mal:autoskip-enabled",
|
"mal:autoskip-enabled",
|
||||||
(target as HTMLInputElement).checked ? "true" : "false",
|
(target as HTMLInputElement).checked ? "true" : "false",
|
||||||
|
|||||||
Reference in New Issue
Block a user