检索网页中的康熙部首

高亮康熙部首字

// ==UserScript==
// @name         检索网页中的康熙部首
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  高亮康熙部首字
// @author       沉石鱼惊旋
// @match        *://*/*
// @license      MIT
// ==/UserScript==

function highlightKangxiRadicals() {
    const kangxiRegex = /[\u2F00-\u2FD5]/g;

    function isEditable(el) {
        return el.isContentEditable ||
            el.tagName === 'TEXTAREA' ||
            (el.tagName === 'INPUT' && /text|search|email|url|tel|password/.test(el.type));
    }

    function highlightNode(node) {
        if (node.nodeType === Node.TEXT_NODE &&
            kangxiRegex.test(node.nodeValue) &&
            !isEditable(node.parentElement)) {

            const span = document.createElement('span');
            span.innerHTML = node.nodeValue.replace(kangxiRegex, char =>
                `<span style="background: yellow; color: red; font-weight: bold;">${char}</span>`
            );
            node.parentNode.replaceChild(span, node);
        } else if (node.nodeType === Node.ELEMENT_NODE &&
            node.tagName !== 'SCRIPT' &&
            node.tagName !== 'STYLE' &&
            !isEditable(node)) {
            Array.from(node.childNodes).forEach(highlightNode);
        }
    }

    highlightNode(document.body);
}

(function () {
    'use strict';
    setInterval(function () {
        highlightKangxiRadicals();
    }, 1000);
})();

QingJ © 2025

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