fix: player page theme color

This commit is contained in:
shinya
2025-06-26 21:20:06 +08:00
parent a50071a4d6
commit 4061cc9f59

View File

@@ -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));
}; };
}, []); }, []);