您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
隐藏知乎页面中的问题标题
// ==UserScript== // @name 隐藏知乎问题标题 // @namespace https://example.com/ // @version 0.1 // @description 隐藏知乎页面中的问题标题 // @author lyx // @match https://www.zhihu.com/* // @grant none // @license MIT // ==/UserScript== (async () => { // 目标 DOM 路径 const targetXPath = '/html/body/div[1]/div/div[2]/header/div[2]/div/div/div[1]/h1'; // 使用 XPath 查找目标元素 const hideElementByXPath = (xpath) => { const targetElement = document.evaluate( xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; if (targetElement) { targetElement.style.display = 'none'; } }; // 初始化时隐藏元素 hideElementByXPath(targetXPath); // 监听 DOM 变化,实时隐藏新生成的标题 const observer = new MutationObserver((mutationsList) => { mutationsList.forEach((mutation) => { if (mutation.type === 'childList' || mutation.type === 'subtree') { hideElementByXPath(targetXPath); } }); }); // 配置 observer,监听整个文档的 DOM 变化 observer.observe(document.body, { childList: true, subtree: true, }); })();