油猴脚本:屏蔽 Google Bing 搜索结果中的垃圾采集站
使用 Google Bing搜索过程,经常会遇到某几个采集站、广告站、垃圾站等,影响搜索体验。使用AI完成了一个油猴脚本,屏蔽这些垃圾采集站。
// ==UserScript==
// @name 搜索结果域名屏蔽(适用于Google/Bing)
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 屏蔽某些低质量/采集站在搜索引擎的结果展示,干净搜索体验!
// @author npc
// @match *://www.google.com/*
// @match *://www.google.com.hk/*
// @match *://www.bing.com/*
// @match *://www.baidu.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
const blockedDomains = [
// 添加需要屏蔽的域名
'example.com',
];
// 工具函数:判断 URL 是否属于屏蔽域名
function isBlocked(url) {
try {
const hostname = new URL(url).hostname.replace(/^www\./, '');
return blockedDomains.some(domain => hostname === domain || hostname.endsWith('.' + domain));
} catch (e) {
return false;
}
}
// 处理 Google 搜索结果
function cleanGoogle() {
document.querySelectorAll('div.g, div[data-header-feature]').forEach(result => {
const link = result.querySelector('a');
if (link && isBlocked(link.href)) {
result.remove();
}
});
}
// 处理 Bing 搜索结果
function cleanBing() {
document.querySelectorAll('#b_results > li.b_algo').forEach(result => {
const link = result.querySelector('a');
if (link && isBlocked(link.href)) {
result.remove();
}
});
}
// 处理 百度 搜索结果
function cleanBaidu() {
document.querySelectorAll('div.result, div.result-op').forEach(result => {
const link = result.querySelector('a');
if (link && isBlocked(link.href)) {
result.remove();
}
});
}
// 主清理函数
function clean() {
if (location.hostname.includes('google.')) {
cleanGoogle();
} else if (location.hostname.includes('bing.')) {
cleanBing();
} else if (location.hostname.includes('baidu.')) {
cleanBaidu();
}
}
// 初次执行
clean();
// 监听搜索结果的动态变化(适用于滚动加载的搜索)
const observer = new MutationObserver(() => clean());
observer.observe(document.body, { childList: true, subtree: true });
})();
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
编辑 (opens new window)
最后一次更新于: 2025/10/08, 01:43:29