refactor: 必要时取消定时器,提高性能

This commit is contained in:
itcatplayit
2023-05-21 10:08:31 +08:00
parent d6a41df2d0
commit e329eb4e80

View File

@@ -6,14 +6,12 @@ const getVideoElement = () => {
return videoWrapper.querySelector('video')
}
var danmukuBoxLoaded = false
setInterval(function () {
if (danmukuBoxLoaded) return
let danmukuBox = null
const timerIframe = setInterval(function () {
if (danmukuBox) return clearInterval(timerIframe)
var danmukuBox = document.getElementById('danmukuBox')
danmukuBox = document.getElementById('danmukuBox')
if (danmukuBox) {
danmukuBoxLoaded = true
setTimeout(function () {
var vKey = ''
for (const key in danmukuBox?.dataset) {
if (key.startsWith('v-')) {
@@ -32,7 +30,6 @@ setInterval(function () {
}
//insert before first child
danmukuBox?.insertBefore(iframe, danmukuBox?.firstChild)
}, 1500)
}
}, 1000)