Merge pull request #7 from itcatplayit/master

优化性能 & 解决一个小报错
This commit is contained in:
IndieKKY
2023-05-21 10:44:16 +08:00
committed by GitHub

View File

@@ -6,33 +6,30 @@ const getVideoElement = () => {
return videoWrapper.querySelector('video') return videoWrapper.querySelector('video')
} }
var danmukuBoxLoaded = false let danmukuBox = null
setInterval(function () { const timerIframe = setInterval(function () {
if (danmukuBoxLoaded) return if (danmukuBox) return clearInterval(timerIframe)
var danmukuBox = document.getElementById('danmukuBox') danmukuBox = document.getElementById('danmukuBox')
if (danmukuBox) { if (danmukuBox) {
danmukuBoxLoaded = true var vKey = ''
setTimeout(function () { for (const key in danmukuBox?.dataset) {
var vKey = '' if (key.startsWith('v-')) {
for (const key in danmukuBox?.dataset) { vKey = key
if (key.startsWith('v-')) { break
vKey = key
break
}
} }
}
const iframe = document.createElement('iframe') const iframe = document.createElement('iframe')
iframe.id = IFRAME_ID iframe.id = IFRAME_ID
iframe.src = chrome.runtime.getURL('index.html') iframe.src = chrome.runtime.getURL('index.html')
iframe.style = 'border: none; width: 100%; height: 44px;' iframe.style = 'border: none; width: 100%; height: 44px;'
iframe.allow = 'clipboard-read; clipboard-write;' iframe.allow = 'clipboard-read; clipboard-write;'
if (vKey) { if (vKey) {
iframe.dataset[vKey] = danmukuBox?.dataset[vKey] iframe.dataset[vKey] = danmukuBox?.dataset[vKey]
} }
//insert before first child //insert before first child
danmukuBox?.insertBefore(iframe, danmukuBox?.firstChild) danmukuBox?.insertBefore(iframe, danmukuBox?.firstChild)
}, 1500)
} }
}, 1000) }, 1000)
@@ -237,7 +234,7 @@ window.addEventListener("message", (event) => {
container.append(div) container.append(div)
} }
} }
text.style.display = trans ? 'block' : 'none' text && (text.style.display = trans ? 'block' : 'none')
} }
}, false); }, false);