mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 05:41:20 -08:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import style from './style.less?inline'
|
|
|
|
if (typeof document !== 'undefined') {
|
|
const id = 'artplayer-plugin-danmuku'
|
|
const pending = Symbol.for('artplayer-plugin-danmuku.pending-style')
|
|
const styleDocument = document as Document & { [key: symbol]: HTMLElement | undefined }
|
|
let $style = document.getElementById(id) || styleDocument[pending]
|
|
if (!$style) {
|
|
$style = document.createElement('style')
|
|
$style.id = id
|
|
if (document.readyState === 'loading') {
|
|
styleDocument[pending] = $style
|
|
const ready = () => {
|
|
document.removeEventListener('DOMContentLoaded', ready)
|
|
if (styleDocument[pending] === $style)
|
|
delete styleDocument[pending]
|
|
const existing = document.getElementById(id)
|
|
if (existing)
|
|
existing.textContent = $style!.textContent
|
|
else
|
|
(document.head || document.documentElement).appendChild($style!)
|
|
}
|
|
document.addEventListener('DOMContentLoaded', ready, { once: true })
|
|
}
|
|
else {
|
|
(document.head || document.documentElement).appendChild($style!)
|
|
}
|
|
}
|
|
$style.textContent = style
|
|
}
|