diff options
author | metamuffin <metamuffin@disroot.org> | 2024-04-14 02:09:18 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-04-14 02:09:18 +0200 |
commit | 03a70f09afae32f1edf59fe9cc19d23908463aac (patch) | |
tree | 1f1591167ed579b53e7937ab7e71304ce0fbd3f6 /web/script/player | |
parent | e503d5af484fb55a07125b3708ba658606e56c5d (diff) | |
download | jellything-03a70f09afae32f1edf59fe9cc19d23908463aac.tar jellything-03a70f09afae32f1edf59fe9cc19d23908463aac.tar.bz2 jellything-03a70f09afae32f1edf59fe9cc19d23908463aac.tar.zst |
jsp: next/prev chapter keybinds like mpv
Diffstat (limited to 'web/script/player')
-rw-r--r-- | web/script/player/mod.ts | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/web/script/player/mod.ts b/web/script/player/mod.ts index 693f04c..dd26cb2 100644 --- a/web/script/player/mod.ts +++ b/web/script/player/mod.ts @@ -244,8 +244,6 @@ function initialize_player(el: HTMLElement, node_id: string) { player.seek(p * player.duration.value) }) - - document.body.addEventListener("keydown", k => { if (k.ctrlKey || k.altKey || k.metaKey) return if (k.code == "Period") player.pause(), player.frame_forward() @@ -263,6 +261,8 @@ function initialize_player(el: HTMLElement, node_id: string) { else if (k.code == "ArrowRight") player.seek(player.position.value + 5) else if (k.code == "ArrowUp") player.seek(player.position.value - 60) else if (k.code == "ArrowDown") player.seek(player.position.value + 60) + else if (k.code == "PageUp") player.seek(find_closest_chaps(player).prev?.time_start ?? 0) + else if (k.code == "PageDown") player.seek(find_closest_chaps(player).next?.time_start ?? player.duration.value) else return; k.preventDefault() }) @@ -330,4 +330,17 @@ function show_profile(profile: EncodingProfile): string { if (profile.video) return `codec=${profile.video.codec} br=${show.metric(profile.video.bitrate, "b/s")} w=${profile.video.width} preset=${profile.video.preset}` if (profile.subtitles) return `codec=${profile.subtitles.codec}` return `???` -}
\ No newline at end of file +} + +function find_closest_chaps(player: Player) { + const now = player.position.value + const chaps = player.chapters.value + let prev, next; + for (const c of chaps) { + const t_start = (c.time_start ?? 0) + next = c; + if (t_start > now) break + prev = c; + } + return { next, prev } +} |