Greasy Fork

修改网页复选框颜色

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

当前为 2023-03-13 提交的版本,查看 最新版本

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


(function() {
    'use strict';

    // 修改选中框的颜&选中文字的字体颜色
    const selectionColor = '#00000005 !important';
    const fontColor = '#6FB7FF !important';

    // 添加样式
    const style = document.createElement('style');
    style.innerHTML = `::selection { background-color: ${selectionColor}; color: ${fontColor}; }`;
    document.head.appendChild(style);

    // 强制覆盖
    const elementsToOverride = document.querySelectorAll('input[type="checkbox"], 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');
    }
})();