2018-12-07 00:54:17 +00:00
|
|
|
import AnimeNotifier from "../AnimeNotifier"
|
|
|
|
|
2018-12-09 02:57:37 +00:00
|
|
|
// Toggle play video
|
|
|
|
export function togglePlayVideo(arn: AnimeNotifier, element: HTMLElement) {
|
2019-11-17 09:25:14 +00:00
|
|
|
const mediaId = element.dataset.mediaId
|
2019-04-22 06:59:08 +00:00
|
|
|
|
|
|
|
if(!mediaId) {
|
|
|
|
console.error("Missing data-media-id:", element)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
const container = document.getElementById(mediaId)
|
2018-12-09 02:57:37 +00:00
|
|
|
|
2019-04-22 06:59:08 +00:00
|
|
|
if(!container) {
|
|
|
|
console.error("Invalid data-media-id:", element)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
const video = container.getElementsByTagName("video")[0]
|
2018-12-07 00:54:17 +00:00
|
|
|
video.volume = arn.audioPlayer.volume
|
|
|
|
|
|
|
|
if(video.readyState >= 2) {
|
2018-12-09 02:57:37 +00:00
|
|
|
togglePlayVideoElement(video)
|
2018-12-07 00:54:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-07 20:19:50 +00:00
|
|
|
video.addEventListener("canplay", () => {
|
2018-12-09 02:57:37 +00:00
|
|
|
togglePlayVideoElement(video)
|
2018-12-07 00:54:17 +00:00
|
|
|
})
|
2018-12-07 19:40:27 +00:00
|
|
|
|
|
|
|
video.load()
|
2018-12-07 00:54:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 02:57:37 +00:00
|
|
|
function togglePlayVideoElement(video: HTMLVideoElement) {
|
2018-12-07 00:54:17 +00:00
|
|
|
if(video.paused) {
|
|
|
|
video.play()
|
|
|
|
} else {
|
|
|
|
video.pause()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle fullscreen
|
2019-04-22 09:06:50 +00:00
|
|
|
export function toggleFullscreen(_: AnimeNotifier, button: HTMLElement) {
|
2019-11-17 09:25:14 +00:00
|
|
|
const elementId = button.dataset.id
|
2019-04-22 06:59:08 +00:00
|
|
|
|
|
|
|
if(!elementId) {
|
|
|
|
console.error("Missing data-id:", button)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
const element = document.getElementById(elementId)
|
2019-04-22 06:59:08 +00:00
|
|
|
|
|
|
|
if(!element) {
|
|
|
|
console.error("Invalid data-id:", button)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:25:14 +00:00
|
|
|
const requestFullscreen = element.requestFullscreen || element["mozRequestFullScreen"] || element["webkitRequestFullScreen"] || element["msRequestFullscreen"]
|
|
|
|
const exitFullscreen = document.exitFullscreen || document["mozCancelFullScreen"] || document["webkitExitFullscreen"] || document["msExitFullscreen"]
|
|
|
|
const fullscreen = document.fullscreen || document["webkitIsFullScreen"] || document["mozFullScreen"]
|
2018-12-07 00:54:17 +00:00
|
|
|
|
2018-12-07 21:45:26 +00:00
|
|
|
if(fullscreen) {
|
2018-12-07 21:35:42 +00:00
|
|
|
exitFullscreen.call(document)
|
2018-12-07 00:54:17 +00:00
|
|
|
} else {
|
2018-12-07 21:35:42 +00:00
|
|
|
requestFullscreen.call(element)
|
2018-12-07 00:54:17 +00:00
|
|
|
}
|
2019-11-17 09:44:30 +00:00
|
|
|
}
|