Skip to content

Instantly share code, notes, and snippets.

@lixiangwuxian
Created January 4, 2026 03:47
Show Gist options
  • Select an option

  • Save lixiangwuxian/2c1bc6e3b10fcab90e8b270c4f3c9b87 to your computer and use it in GitHub Desktop.

Select an option

Save lixiangwuxian/2c1bc6e3b10fcab90e8b270c4f3c9b87 to your computer and use it in GitHub Desktop.
移除谷歌AI概览
// ==UserScript==
// @name 移除 Google AI 概览 (通过关键字定位)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 通过查找 “AI 概览” 关键字来定位并删除 Google 搜索页面上的 AI 概览 (AI Overview) 模块。
// @author Gemini
// @match https://www.google.com/search*
// @match https://www.google.com.hk/search*
// @match https://www.google.co.jp/search*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
// 定义要查找的关键字
const KEYWORDS = ["AI 概览", "AI Overview"];
// 定义 Google 搜索结果卡片的常见容器类名
// MjjYud 是目前 Google 搜索结果卡片的标准包装类
const CONTAINER_SELECTOR = '.MjjYud, .ULSxyf, .YNk70c, .EjQTId';
function removeAIOverview() {
// 使用 XPath 查找包含特定文本的所有元素
// 查找所有文本内容精确等于关键字的元素
KEYWORDS.forEach(text => {
const xpath = `//*[text()='${text}']`;
const result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < result.snapshotLength; i++) {
let element = result.snapshotItem(i);
// 找到包含关键字的元素后,向上寻找最近的容器卡片
let container = element.closest(CONTAINER_SELECTOR);
if (container) {
// 双重确认:确保这不是网页标题或其他无关内容,而是搜索结果流的一部分
// 通常 AI 概览会出现在主要结果区域
console.log(`[Remove AI Script] Found keyword "${text}", removing container.`);
container.remove();
}
}
});
}
// 1. 页面初次加载时运行
removeAIOverview();
// 2. 监听 DOM 变化 (针对 Google 的动态加载/翻页/流式加载)
const observer = new MutationObserver((mutations) => {
// 为了性能,简单判断是否有节点增加即可触发检查
let shouldRun = false;
for (const mutation of mutations) {
if (mutation.addedNodes.length > 0) {
shouldRun = true;
break;
}
}
if (shouldRun) {
removeAIOverview();
}
});
// 开始监听 body 的变化
observer.observe(document.body, {
childList: true,
subtree: true
});
})();
@lixiangwuxian

Copy link
Copy Markdown
Author

粘贴到油猴插件内使用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment