修改网页复选框颜色

修改所有网页文字复选框颜色

// ==UserScript==
// @name         修改网页复选框颜色
// @namespace    https://gf.qytechs.cn/zh-CN/scripts/461245
// @version      1.0.5
// @description  修改所有网页文字复选框颜色
// @author       nosora
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function addGlobalStyle(css) {
        const head = document.getElementsByTagName('head')[0];
        if (!head) return;
        const style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }

    document.addEventListener('DOMContentLoaded', function() {
        // 修改选中框的颜&选中文字的字体颜色
        const selectionColor = 'rgba(0, 0, 0, 0.05)';
        const fontColor = '#6FB7FF';

        // 添加样式
        addGlobalStyle(`::selection { background-color: ${selectionColor} !important; color: ${fontColor} !important; }`);

        // 强制覆盖
        const elementsToOverride = document.querySelectorAll('body input[type="checkbox"], body input[type="radio"]');
        for (let i = 0; i < elementsToOverride.length; i++) {
            elementsToOverride[i].style.setProperty('background-color', selectionColor, 'important');
            elementsToOverride[i].style.setProperty('color', fontColor, 'important');
        }
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址