【TamperMonkey】知乎隐藏标题

文章目录
  1. 1. 脚本内容
概述

知乎隐藏标题

相关说明

一个简单的 TamperMonkey 脚本

[toc]

脚本内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name 知乎隐藏标题
// @namespace http://tampermonkey.net/
// @version 2025-09-28
// @description try to take over the world!
// @author Montarius
// @match *://*/question/*
// @icon https://static.zhihu.com/heifetz/assets/apple-touch-icon-152.81060cab.png
// @grant none
// ==/UserScript==

(function() {
'use strict';

console.log("知乎测试1111111111111111111111111");

// Your code here...
const selectors = [
"#root > div > div.css-s8xum0 > header > div > div.css-51utkw > div.css-14iuq0r > div > div > div > div.QuestionHeader-main > h1",
"h1[data-cy='question-title']", // 备用选择器
"h1.title" // 通用备用方案
];

const findElement = () => {
for (const selector of selectors) {
const element = document.querySelector(selector);
if (element) return element;
}
return null;
};

const element = findElement();
if (element) {
console.log(" 元素内容:", element.innerText);
element.style.display = "none";
} else {
console.warn(" 元素未找到,尝试监听动态加载...");
const observer = new MutationObserver(() => {
const el = findElement();
if (el) {
observer.disconnect();
console.log(" 动态加载的元素:", el);
el.style.display = "none";
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
})();