only get one click

This commit is contained in:
j 2021-10-25 09:23:06 +01:00
parent 0577adffb8
commit e4877ab3a9

View file

@ -16,51 +16,57 @@ function setVideoSrc(video, src) {
}
video.src = src.replace('.webm', videoExtension)
}
var video
document.querySelector('a#play-fullscreen').addEventListener('click', event => {
event.preventDefault()
event.stopPropagation()
var video = document.createElement('video')
video.classList.add('player')
setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm')
video.controls = true
document.querySelector('main').appendChild(video)
video.style.display = 'none'
if (continueTimecode) {
video.currentTime = continueTimecode
}
function enterFullscreen(event) {
if (video.webkitEnterFullScreen) {
video.webkitEnterFullScreen();
} else {
video.requestFullscreen().catch(err => {
console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
video.remove()
});
if (!video) {
video = document.createElement('video')
video.classList.add('player')
setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm')
video.controls = true
document.querySelector('main').appendChild(video)
video.style.display = 'none'
if (continueTimecode) {
video.currentTime = continueTimecode
}
video.removeEventListener('play', enterFullscreen);
setTimeout(() => {
video.style.display = 'block'
}, 150)
}
video.addEventListener('play', enterFullscreen);
video.addEventListener('fullscreenchange', event => {
if (document.fullscreenElement === null) {
continueTimecode = video.currentTime
function enterFullscreen(event) {
video.removeEventListener('play', enterFullscreen);
if (video.webkitRequestFullscreen) {
video.requestFullscreen();
} else {
video.requestFullscreen().catch(err => {
console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
video.remove()
video = null
});
}
setTimeout(() => {
video.style.display = 'block'
}, 150)
}
video.addEventListener('play', enterFullscreen);
video.addEventListener('fullscreenchange', event => {
if (document.fullscreenElement === null) {
continueTimecode = video.currentTime
video.remove()
if (document.fullscreenElement) {
document.exitFullscreen();
}
video = null
}
});
video.addEventListener('pause', event => {
})
video.addEventListener('ended', event => {
continueTimecode = 0
video.remove()
if (document.fullscreenElement) {
document.exitFullscreen();
}
}
});
video.addEventListener('pause', event => {
})
video.addEventListener('ended', event => {
continueTimecode = 0
video.remove()
if (document.fullscreenElement) {
document.exitFullscreen();
}
});
video.play()
video = null
});
video.play()
}
})