Skip to content

[知乎增强] 希望添加 “屏蔽划词弹框” 功能 #595

Description

@amorphobia

功能需求

Image

如上图所示,鼠标选取文字后,页面上会弹出这样的气泡框,希望可以屏蔽掉

预期目标

希望打开该功能后,鼠标选取文字不再弹框

Activity

  1. XIU2 commented on May 31, 2026

    @XIU2
    Owner

    这个不好处理,主要是这个元素的类名是随机生成的(这几年知乎新出的功能的元素类名都变成这种了,不管是对于屏蔽显示还是其他相关功能都难以处理)。

    Image

    不过这个并不是每次打开网页都是随机的,而是取决于知乎的变动,我建议你可以先在广告屏蔽扩展的自定义规则里加上:

    www.zhihu.com##.css-16vbw36
    

    来实现屏蔽效果。

  2. amorphobia commented on Jun 1, 2026

    @amorphobia
    Author

    我注意到这样的 div 是紧随 body 的子元素,让 AI 写了一个,目前看起来是有效果的:

    展开查看代码
    // ==UserScript==
    // @name         屏蔽 body 直接子元素 css-div
    // @namespace    http://tampermonkey.net/
    // @version      1.0
    // @match        https://*.zhihu.com/*
    // @grant        none
    // @run-at       document-start
    // ==/UserScript==
    
    (function() {
        'use strict';
    
        function isTargetDiv(el) {
            return el.tagName === 'DIV' && /^css-[a-zA-Z0-9]{6,}$/.test(el.className);
        }
    
        function hideElement(el) {
            if (!el.hasAttribute('data-hidden')) {
                el.style.display = 'none';
                el.setAttribute('data-hidden', 'true');
            }
        }
    
        // 屏蔽现有的
        if (document.body) {
            Array.from(document.body.children).filter(isTargetDiv).forEach(hideElement);
        }
    
        // 监听未来的
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                mutation.addedNodes.forEach((node) => {
                    if (node.nodeType === 1 && node.parentNode === document.body && isTargetDiv(node)) {
                        hideElement(node);
                    }
                });
            });
        });
    
        function start() {
            if (document.body) {
                observer.observe(document.body, { childList: true, subtree: false });
            } else {
                document.addEventListener('DOMContentLoaded', start);
            }
        }
    
        start();
    })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions