import { ComponentEntry } from '@/components/types' import { contentLoaded } from '@/core/life-cycle' import { addComponentListener, removeComponentListener } from '@/core/settings' import { BackgroundImage, BackgroundPosition, BackgroundSize, options as optionsMetadata, Options, } from './options' const componentName = 'videoPageBackground' const layerId = 'be-video-page-background' const cssProperties = [ '--be-video-page-background-image', '--be-video-page-background-image-opacity', '--be-video-page-background-mask-opacity', '--be-video-page-background-blur', '--be-video-page-background-size', '--be-video-page-background-position', '--be-video-page-background-color', '--be-video-page-background-mask-color', ] const backgroundSizeMap: Record = { [BackgroundSize.Cover]: 'cover', [BackgroundSize.Contain]: 'contain', [BackgroundSize.Original]: 'auto', } const backgroundPositionMap: Record = { [BackgroundPosition.CenterBottom]: 'center bottom', [BackgroundPosition.Center]: 'center center', [BackgroundPosition.LeftBottom]: 'left bottom', [BackgroundPosition.RightBottom]: 'right bottom', } let currentOptions: Options let listenersAdded = false let themeObserver: MutationObserver | null = null let lastDarkState: boolean | null = null const isDarkMode = () => { // B 站官方深色主题:新版页用 ``,老版视频页用 ``。 const htmlClasses = document.documentElement.classList if (htmlClasses.contains('bili_dark') || htmlClasses.contains('night-mode')) { return true } // `` 是本扩展「夜间模式 / 深色模式」组件的共同标志。 if (document.body.classList.contains('dark')) { // 进一步区分: // - 「夜间模式」(darkMode):unload 时 body.dark 延迟 200ms 才移除,但 `