Greasy Fork

Greasy Fork is available in English.

修改小红书 PWA 标题栏颜色

修改小红书 PWA 标题栏颜色为 #0A0A0A

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         修改小红书 PWA 标题栏颜色
// @version      0.1
// @description  修改小红书 PWA 标题栏颜色为 #0A0A0A
// @author       hiisme
// @match        https://www.xiaohongshu.com/*
// @grant        GM_addStyle
// @namespace http://greasyfork.icu/users/217852
// ==/UserScript==

(function() {
    'use strict';

    // 修改标题栏颜色的 CSS 样式
    const style = `
        /* 修改标题栏颜色为 #0A0A0A */
        @media (display-mode: standalone) {
            /* 修改 PWA 独立显示模式下的标题栏颜色 */
            header {
                background-color: #0A0A0A !important;
            }
        }
    `;

    // 将样式添加到页面
    GM_addStyle(style);

    // 监听页面变化
    const observer = new MutationObserver(() => {
        // 重新设置标题栏颜色
        const changePwaTitleBarColor = () => {
            const metaThemeColor = document.querySelector('meta[name="theme-color"]');
            if (metaThemeColor) {
                metaThemeColor.setAttribute('content', '#0A0A0A');
            } else {
                const newMetaTag = document.createElement('meta');
                newMetaTag.setAttribute('name', 'theme-color');
                newMetaTag.setAttribute('content', '#0A0A0A');
                document.head.appendChild(newMetaTag);
            }
        };

        // 重新调用修改标题栏颜色的函数
        changePwaTitleBarColor();
    });

    // 配置并启动 MutationObserver
    const config = { attributes: true, childList: true, subtree: true };
    observer.observe(document.body, config);
})();