mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-05-22 14:37:30 +08:00
fix: player page theme color
This commit is contained in:
@@ -1050,25 +1050,23 @@ function PlayPageClient() {
|
|||||||
|
|
||||||
/* -------------------- 设置 meta theme-color 为纯黑 -------------------- */
|
/* -------------------- 设置 meta theme-color 为纯黑 -------------------- */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof document === 'undefined') return;
|
const originalThemeColorTags = Array.from(
|
||||||
|
document.querySelectorAll('meta[name="theme-color"]')
|
||||||
|
);
|
||||||
|
|
||||||
// 查找或创建 meta[name="theme-color"]
|
// 移除已有的 theme-color 标签
|
||||||
let metaTag = document.querySelector(
|
originalThemeColorTags.forEach((tag) => tag.remove());
|
||||||
'meta[name="theme-color"]'
|
|
||||||
) as HTMLMetaElement | null;
|
|
||||||
|
|
||||||
if (!metaTag) {
|
// 添加播放页专用的 theme-color 标签
|
||||||
metaTag = document.createElement('meta');
|
const playerThemeColorTag = document.createElement('meta');
|
||||||
metaTag.setAttribute('name', 'theme-color');
|
playerThemeColorTag.name = 'theme-color';
|
||||||
document.head.appendChild(metaTag);
|
playerThemeColorTag.content = '#000000';
|
||||||
}
|
document.head.appendChild(playerThemeColorTag);
|
||||||
|
|
||||||
// 记录原始颜色,并设置为纯黑
|
// 组件卸载时恢复原有的 theme-color 标签
|
||||||
metaTag.setAttribute('content', '#000000');
|
|
||||||
|
|
||||||
// 卸载时恢复
|
|
||||||
return () => {
|
return () => {
|
||||||
metaTag?.setAttribute('content', '#e6f3fb');
|
playerThemeColorTag.remove();
|
||||||
|
originalThemeColorTags.forEach((tag) => document.head.appendChild(tag));
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user