消除知乎直答标记(蓝色字体)

移除知乎网页端回答和文章中类似"知乎直答✦"的关键词链接

// ==UserScript==
// @name         消除知乎直答标记(蓝色字体)
// @namespace    
// @version      1.1
// @description  移除知乎网页端回答和文章中类似"知乎直答✦"的关键词链接
// @author       
// @match        *://*.zhihu.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const targetClass = "RichContent-EntityWord";

    // 移除链接并清理角标
    function removeLinks() {
        const links = document.querySelectorAll(`a.${targetClass}:not([data-processed])`);
        links.forEach(link => {
            // 获取纯文本内容并移除✦
            let text = link.textContent.replace(/✦/g, '');

            // 创建纯文本节点
            const textNode = document.createTextNode(text);

            // 用纯文本替换链接
            link.parentNode.replaceChild(textNode, link);

            // 标记为已处理(虽然元素已被替换,但为保险起见)
            textNode.data = textNode.data + ' '; // 添加标记但不影响显示
        });
    }

    // 页面加载时初次处理
    removeLinks();

    // 设置MutationObserver处理动态内容
    const observer = new MutationObserver(mutations => {
        let needsProcess = false;
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length) {
                needsProcess = true;
            }
        });
        if (needsProcess) {
            removeLinks();
        }
    });

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

    // 添加防抖处理滚动加载
    let timer;
    window.addEventListener('scroll', () => {
        clearTimeout(timer);
        timer = setTimeout(removeLinks, 300);
    });
})();

QingJ © 2025

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