Fixed double binding for event listeners

This commit is contained in:
Eduard Urbach 2018-12-08 07:02:22 +09:00
parent d2dadb41c7
commit 3776b87d7e

View File

@ -895,6 +895,7 @@ export default class AnimeNotifier {
// Once the video becomes visible, load it // Once the video becomes visible, load it
video["became visible"] = () => { video["became visible"] = () => {
if(!video["listeners attached"]) {
// Prevent context menu // Prevent context menu
video.addEventListener("contextmenu", e => e.preventDefault()) video.addEventListener("contextmenu", e => e.preventDefault())
@ -919,7 +920,15 @@ export default class AnimeNotifier {
let progressContainer = video.parentElement.getElementsByClassName("video-progress-container")[0] let progressContainer = video.parentElement.getElementsByClassName("video-progress-container")[0]
let timeElement = video.parentElement.getElementsByClassName("video-time")[0] let timeElement = video.parentElement.getElementsByClassName("video-time")[0]
video.addEventListener("canplay", () => {
video["playable"] = true
})
video.addEventListener("timeupdate", () => { video.addEventListener("timeupdate", () => {
if(!video["playable"]) {
return
}
let time = video.currentTime let time = video.currentTime
let minutes = Math.trunc(time / 60) let minutes = Math.trunc(time / 60)
let seconds = Math.trunc(time) % 60 let seconds = Math.trunc(time) % 60
@ -945,6 +954,9 @@ export default class AnimeNotifier {
e.stopPropagation() e.stopPropagation()
}) })
video["listeners attached"] = true
}
let modified = false let modified = false
for(let child of video.children) { for(let child of video.children) {
@ -962,6 +974,8 @@ export default class AnimeNotifier {
} }
if(modified) { if(modified) {
video["playable"] = false
Diff.mutations.queue(() => { Diff.mutations.queue(() => {
video.load() video.load()
video.classList.add("element-found") video.classList.add("element-found")