-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTamperMonkey.js
78 lines (64 loc) · 2.18 KB
/
TamperMonkey.js
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
// ==UserScript==
// @name 屏蔽百度推广|Powered by qii404.me
// @namespace https://qii404.me/
// @version 0.1
// @description 为了你,为了你的家人在百度搜索的时候不至于被广告所蒙蔽
// @author qii404
// @match *://www.baidu.com/s*
// @run-at document-start
// @homepage https://github.com/qishibo/shieldBaiduPromotion
// @icon https://imgup.qii404.me/shield_baidu_128.png
// @downloadURL https://github.com/qishibo/shieldBaiduPromotion/blob/master/TamperMonkey.js
// @supportURL https://qii404.me/
// ==/UserScript==
Object.defineProperty(window, 'MutationObserver', {
value: window.MutationObserver,
writable: false,
configurable: false,
enumerable: false
});
window.addEventListener ("load", function() {
qii404.init();
});
var qii404 = {
init: function() {
this.removeAds();
this.bindAction();
},
removeAds: function() {
this.removeNormalAds();
this.removeMockAds();
},
removeNormalAds: function() {
console.log('start removing normal ads...');
var ads = document.querySelectorAll('#content_left>div:not([class*="result"]):not([class="leftBlock"])');
for (var i = 0; i < ads.length; i++) {
ads[i].remove();
console.log(ads[i]);
}
},
removeMockAds: function() {
console.log('start removing mock ads...');
var ads = document.querySelectorAll('#content_left>div');
for (var i = 0; i < ads.length; i++) {
var ms = ads[i].querySelectorAll('span');
for (var j = 0; j < ms.length; j++) {
if (ms[j].innerHTML === '广告') {
ads[i].remove();
console.log(ads[i]);
break;
}
}
}
},
bindAction: function() {
var this_ = this;
var observer = new window.MutationObserver(function() {
this_.removeAds();
});
observer.observe(
document.querySelector('#wrapper_wrapper'),
{'childList': true, 'characterData': false, 'attributes': false, 'subtree': true}
);
}
}