隐藏 X.com 私信列表。鼠标悬停在区域上时,所有对话会清晰显示。此版本极其稳定。
当前为
// ==UserScript==
// @name X.com 私信列表模糊处理
// @name:en X.com DM Blur
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 隐藏 X.com 私信列表。鼠标悬停在区域上时,所有对话会清晰显示。此版本极其稳定。
// @description:en Reliably hides the DM list on X.com by blurring the entire "All conversations" section. The section becomes clear on hover. This version is extremely stable.
// @author BlingCc
// @match https://x.com/messages/*
// @match https://x.com/messages
// @icon https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 1. 注入CSS样式
// 这次我们定义一个作用于整个容器的模糊类
const style = document.createElement('style');
style.textContent = `
/* 模糊容器的样式 */
.dm-blur-section-container {
/* 核心模糊效果 */
filter: blur(5px);
/* 平滑过渡动画 */
transition: filter 0.2s ease-in-out;
/* 解决边缘模糊不清晰的问题,可以稍微加一点内边距 */
padding-top: 5px;
margin-top: -5px;
}
/* 鼠标悬停在容器上时,移除模糊 */
.dm-blur-section-container:hover {
filter: blur(0);
}
`;
document.head.appendChild(style);
// 2. 核心处理函数
function processAndBlur() {
// 使用 XPath 查找包含“所有对话”文本的 h2 元素。
// 这是最可靠的定位锚点。
const headingXpath = "//h2[.//span[contains(text(), '所有对话')]]";
const heading = document.evaluate(headingXpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (!heading) {
// 如果没找到,说明页面未加载完成,稍后重试
return;
}
// 找到标题后,向上追溯找到它所属的 <section> 容器
// X.com 的页面结构通常使用 <section> 来划分区域
const conversationSection = heading.closest('section');
if (!conversationSection) {
// 如果找到了标题但没找到 section 容器,也稍后重试
return;
}
// 检查这个 section 是否已经被我们处理过,避免重复操作
if (!conversationSection.classList.contains('dm-blur-section-container')) {
console.log('Tampermonkey: 找到了“所有对话”区域,正在应用模糊效果。');
// 将我们定义好的CSS类添加到这个区域上
conversationSection.classList.add('dm-blur-section-container');
}
}
// 3. 使用 MutationObserver 持续监控页面变化
// 这是确保动态加载内容也能被处理的关键
const observer = new MutationObserver(() => {
// 任何DOM变化都可能意味着“所有对话”区域出现了,所以我们运行一次处理函数
processAndBlur();
});
// 4. 启动监控
// 监控整个文档的变化,因为我们不确定内容会出现在哪里
observer.observe(document.body, {
childList: true,
subtree: true
});
// 5. 初始执行
// 页面刚加载时,也尝试运行一次
setTimeout(processAndBlur, 1000); // 延迟1秒,给页面足够的时间来初步渲染
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址