Add autoplay toggle button to video player
Agent-Logs-Url: https://github.com/mkelvers/mal/sessions/72375034-49a9-451f-8e30-ee26c9c20eab Co-authored-by: melosh101 <59763532+melosh101@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9b33c7593b
commit
77be47297f
@@ -81,6 +81,7 @@ const initPlayer = (): void => {
|
|||||||
const forwardBtn = container.querySelector('[data-forward]') as HTMLButtonElement
|
const forwardBtn = container.querySelector('[data-forward]') as HTMLButtonElement
|
||||||
const fullscreenBtn = container.querySelector('[data-fullscreen]') as HTMLButtonElement
|
const fullscreenBtn = container.querySelector('[data-fullscreen]') as HTMLButtonElement
|
||||||
const skipSegmentBtn = container.querySelector('[data-skip]') as HTMLButtonElement
|
const skipSegmentBtn = container.querySelector('[data-skip]') as HTMLButtonElement
|
||||||
|
const autoplayBtn = container.querySelector('[data-autoplay]') as HTMLButtonElement
|
||||||
const subtitleText = container.querySelector('[data-subtitle-text]') as HTMLElement
|
const subtitleText = container.querySelector('[data-subtitle-text]') as HTMLElement
|
||||||
|
|
||||||
const streamURL = container.getAttribute('data-stream-url') || '/watch/proxy/stream'
|
const streamURL = container.getAttribute('data-stream-url') || '/watch/proxy/stream'
|
||||||
@@ -176,6 +177,15 @@ const initPlayer = (): void => {
|
|||||||
|
|
||||||
const skipLabel = (segmentType: string): string => segmentType === 'ed' ? 'Skip outro' : 'Skip intro'
|
const skipLabel = (segmentType: string): string => segmentType === 'ed' ? 'Skip outro' : 'Skip intro'
|
||||||
|
|
||||||
|
const isAutoplayEnabled = (): boolean => localStorage.getItem('mal:autoplay-enabled') !== 'false'
|
||||||
|
|
||||||
|
const updateAutoplayButton = (): void => {
|
||||||
|
if (!autoplayBtn) return
|
||||||
|
const enabled = isAutoplayEnabled()
|
||||||
|
autoplayBtn.title = enabled ? 'Autoplay: On' : 'Autoplay: Off'
|
||||||
|
autoplayBtn.classList.toggle('opacity-40', !enabled)
|
||||||
|
}
|
||||||
|
|
||||||
const timelineBounds = (): { start: number, end: number, duration: number } => {
|
const timelineBounds = (): { start: number, end: number, duration: number } => {
|
||||||
const duration = Number.isFinite(video.duration) && video.duration > 0 ? video.duration : 0
|
const duration = Number.isFinite(video.duration) && video.duration > 0 ? video.duration : 0
|
||||||
|
|
||||||
@@ -803,6 +813,8 @@ const goToNextEpisode = (): void => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isAutoplayEnabled()) return
|
||||||
|
|
||||||
const nextEpisode = currentEpisodeNumber + 1
|
const nextEpisode = currentEpisodeNumber + 1
|
||||||
markEpisodeTransition(nextEpisode)
|
markEpisodeTransition(nextEpisode)
|
||||||
|
|
||||||
@@ -862,7 +874,9 @@ const loadNextEpisodeInPlace = async (animeID: number, nextEpisode: number): Pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
video.load()
|
video.load()
|
||||||
video.play().catch(() => {})
|
if (isAutoplayEnabled()) {
|
||||||
|
video.play().catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
parsedSegments = (data.segments || [])
|
parsedSegments = (data.segments || [])
|
||||||
.map((segment: SkipSegment) => {
|
.map((segment: SkipSegment) => {
|
||||||
@@ -1036,6 +1050,12 @@ const loadNextEpisodeInPlace = async (animeID: number, nextEpisode: number): Pro
|
|||||||
modeDub?.addEventListener('click', toggleDub)
|
modeDub?.addEventListener('click', toggleDub)
|
||||||
modeSub?.addEventListener('click', toggleSub)
|
modeSub?.addEventListener('click', toggleSub)
|
||||||
|
|
||||||
|
autoplayBtn?.addEventListener('click', () => {
|
||||||
|
localStorage.setItem('mal:autoplay-enabled', isAutoplayEnabled() ? 'false' : 'true')
|
||||||
|
updateAutoplayButton()
|
||||||
|
showControls()
|
||||||
|
})
|
||||||
|
|
||||||
subtitleSelect?.addEventListener('change', async () => {
|
subtitleSelect?.addEventListener('change', async () => {
|
||||||
const selected = subtitleSelect.value
|
const selected = subtitleSelect.value
|
||||||
if (selected === 'none') {
|
if (selected === 'none') {
|
||||||
@@ -1142,6 +1162,7 @@ const loadNextEpisodeInPlace = async (animeID: number, nextEpisode: number): Pro
|
|||||||
updatePlayPauseIcons(false)
|
updatePlayPauseIcons(false)
|
||||||
syncVolumeUI()
|
syncVolumeUI()
|
||||||
updateSkipButton(0)
|
updateSkipButton(0)
|
||||||
|
updateAutoplayButton()
|
||||||
showControls()
|
showControls()
|
||||||
|
|
||||||
playerInitialized = true
|
playerInitialized = true
|
||||||
|
|||||||
@@ -251,6 +251,20 @@ templ VideoPlayer(data shared.WatchPageData, displayTitle string) {
|
|||||||
<path d="M11.9894 5.45398V0L2 7.79529L11.9894 15.5914V10.3033H47.0886V40.1506H33.2442V45H52V5.45398H11.9894Z" fill="white"></path>
|
<path d="M11.9894 5.45398V0L2 7.79529L11.9894 15.5914V10.3033H47.0886V40.1506H33.2442V45H52V5.45398H11.9894Z" fill="white"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
data-autoplay
|
||||||
|
class="flex h-9 w-9 items-center justify-center text-white sm:h-10 sm:w-10"
|
||||||
|
title="Autoplay: On"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="h-5 w-5 sm:h-6 sm:w-6"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<polygon points="5 6 16 12 5 18" fill="white" stroke="none"></polygon>
|
||||||
|
<line x1="19" y1="6" x2="19" y2="18" stroke="white" stroke-width="2" stroke-linecap="round"></line>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
data-fullscreen
|
data-fullscreen
|
||||||
class="flex h-9 w-9 items-center justify-center text-white sm:h-10 sm:w-10"
|
class="flex h-9 w-9 items-center justify-center text-white sm:h-10 sm:w-10"
|
||||||
|
|||||||
Reference in New Issue
Block a user