白宫官网特朗普名字高亮

Bold and highlight all occurrences of the name “Donald Trump” on the whitehouse.gov

// ==UserScript==
// @name         白宫官网特朗普名字高亮
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Bold and highlight all occurrences of the name “Donald Trump” on the whitehouse.gov 
// @author       三太阳同志
// @match        *://*.whitehouse.gov/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    const patterns = [
        /\bDonald\s+Trump\b/gi,
        /\bDonald\s+J\.?\s+Trump\b/gi,
        /\bMr\.?\s+Trump\b/gi,
        /\bPresident\s+Trump\b/gi
    ];

    function processTextNode(textNode) {
        let text = textNode.nodeValue;
        let replaced = false;

        for (const pattern of patterns) {
            if (pattern.test(text)) {
                text = text.replace(pattern, match =>
                    `<span style="font-weight:bold; font-family:Arial, sans-serif; color:red;">${match}</span>`
                );
                replaced = true;
            }
        }

        if (replaced) {
            const span = document.createElement('span');
            span.innerHTML = text;
            textNode.parentNode.replaceChild(span, textNode);
        }
    }

    function walkAndProcess(node) {
        let child, next;
        switch (node.nodeType) {
            case 1: // Element
            case 9: // Document
            case 11: // Document fragment
                child = node.firstChild;
                while (child) {
                    next = child.nextSibling;
                    walkAndProcess(child);
                    child = next;
                }
                break;
            case 3: // Text node
                processTextNode(node);
                break;
        }
    }

    // Initial processing
    walkAndProcess(document.body);

    // MutationObserver for dynamic content
    const observer = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.nodeType === 1 || node.nodeType === 11) {
                    walkAndProcess(node);
                } else if (node.nodeType === 3) {
                    processTextNode(node);
                }
            }
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();

QingJ © 2025

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