全新のGitHub

让您在任何环境下都拥有最舒适的浏览体验:将背景颜色变为知拾蓝。

// ==UserScript==
// @name         全新のGitHub
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  让您在任何环境下都拥有最舒适的浏览体验:将背景颜色变为知拾蓝。
// @author       DreamProStudio
// @match        https://github.com/*
// @grant        none
// @license      GPL-3.0
// ==/UserScript==

(function() {
    'use strict';

    // 修改元素背景颜色的函数
    function changeBackgroundColor() {
        // 将整个页面的背景颜色设置为知拾蓝
        document.body.style.backgroundColor = '#EFF4F8';
        
        // 修改所有元素的背景颜色以确保一致性
        const allElements = document.querySelectorAll('*');
        allElements.forEach(element => {
            // 获取元素的计算样式
            const computedStyle = getComputedStyle(element);
            // 如果元素的背景颜色是透明或未设置,则将其改为知拾蓝
            if (computedStyle.backgroundColor === 'rgba(0, 0, 0, 0)' || computedStyle.backgroundColor === 'transparent') {
                element.style.backgroundColor = '#EFF4F8';
            }
        });
    }

    // 初次运行函数以修改背景颜色
    changeBackgroundColor();

    // 使用 requestAnimationFrame 的观察者回调
    const observerCallback = () => {
        // 当DOM变化时,重新应用背景颜色
        requestAnimationFrame(changeBackgroundColor);
    };

    // 观察DOM的变化以动态应用背景颜色
    const observer = new MutationObserver(observerCallback);
    observer.observe(document.body, { attributes: true, childList: true, subtree: true });
})();