fix: allow backward seek but prevent forward seek

This commit is contained in:
Jannat Patel
2025-07-01 19:16:13 +05:30
parent e526a6fd64
commit b4cf290f4d
4 changed files with 37 additions and 6 deletions

View File

@@ -566,18 +566,39 @@ const setupPlyrForVideo = (video, players) => {
'fullscreen',
]
if (useSettings().preventSkippingVideos.data) {
controls.splice(controls.indexOf('progress'), 1)
}
const player = new Plyr(video, {
youtube: { noCookie: true },
controls: controls,
listeners: {
seek: function customSeekBehavior(e) {
const current_time = player.currentTime
const newTime = getTargetTime(player, e)
if (
useSettings().preventSkippingVideos.data &&
parseFloat(newTime) > current_time
) {
e.preventDefault()
player.currentTime = current_time
return false
}
},
},
})
players.push(player)
}
const getTargetTime = (plyr, input) => {
if (
typeof input === 'object' &&
(input.type === 'input' || input.type === 'change')
) {
return (input.target.value / input.target.max) * plyr.duration
} else {
return Number(input)
}
}
const extractYouTubeId = (url) => {
try {
const parsedUrl = new URL(url)