网页脚本-智能聚光灯:在Linux论坛中突显关键信息

利用chatgpt制作的关键词高亮脚本,如下:

// ==UserScript==
// @name         智能聚光灯
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Highlight multiple keywords in deep blue on Linux.do
// @author       Your Name
// @match        https://linux.do/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    const keywords = ["免费", "bin", "病友", "白嫖", "公益", "开源", "github", "节点"];
    const color = "#28a745";  // 设置高亮颜色为柔和的绿色

    function highlightText(node) {
        if (node.nodeType === 3) {
            let text = node.nodeValue;
            const regex = new RegExp(`(${keywords.join('|')})`, 'gi');
            const newHTML = text.replace(regex, `<span style="color: ${color};">$1</span>`);
            
            if (newHTML !== text) {
                const newSpan = document.createElement('span');
                newSpan.innerHTML = newHTML;
                node.parentNode.replaceChild(newSpan, node);
                return true;
            }
            return false;
        } else if (node.nodeType === 1 && node.nodeName.toLowerCase() !== 'script' && node.nodeName.toLowerCase() !== 'style') {
            for (const child of node.childNodes) {
                if (highlightText(child)) {
                    return true;
                }
            }
        }
        return false;
    }

    function applyHighlight() {
        const nodes = document.querySelectorAll('p, h1, h2, h3, h4, h5, h6, li, td');
        nodes.forEach(node => {
            highlightText(node);
        });
    }

    // Start a periodic check to apply highlights. Adjusted to every 1000 milliseconds (1 seconds)
    setInterval(applyHighlight, 1000);

    applyHighlight();  // Initial application
})();

6 个赞

哈哈哈哈哈!!!好玩
不知道在暗色模式显示啥好

什么奇思妙想 :face_with_peeking_eye:

哈哈哈,刷论坛更有动力了

这可太实用了

玩出花了

试用

奇思妙想