fix: allow backward seek but prevent forward seek
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user