-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTampermonkey_baiduAd.js
54 lines (54 loc) · 1.56 KB
/
Tampermonkey_baiduAd.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
// ==UserScript==
// @name ad-baidu
// @namespace https://baidu.com/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.baidu.com/**
// @grant none
// ==/UserScript==
var selectors = `
#content_left [style*="display:block !important;visibility:visible !important"]
[tpl="right_toplist"]
[class="c-gray c-feedback"]
[data-click*="vLevel"]
`;
selectors = selectors.trim().split('\n');
var count = 0;
function showCount(cn){
if(cn>0){
count+=cn;
var content_right = document.querySelector('#content_right');
if(content_right){
content_right.style.position = 'relative';
var style = `
line-height: 42px;
text-align: center;
background: #0c0;
color: #fff;
margin-bottom:30px;
`;
var msgCount = document.querySelector('#msg-remove');
if(!msgCount){
content_right.insertAdjacentHTML('afterbegin','<div id="msg-remove" style="'+style+'"></div>');
msgCount = document.querySelector('#msg-remove');
}
msgCount.innerHTML = '已过滤:'+count+'条垃圾广告,本次过滤:'+cn+'条';
}
}
}
function clear() {
selectors.forEach(function(selector) {
var doms = document.querySelectorAll(selector);
if(doms.length){
doms = Array.from(doms);
showCount(doms.length);
doms.forEach(function(dom) {
dom.parentNode.removeChild(dom);
});
}
});
}
setInterval(function () {
clear();
},500);