1
0
Fork 0
UserScript/baidu/clearAd.user.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-01-08 06:33:58 +00:00
// ==UserScript==
// @name 百度广告去除
// @namespace http://ide.yumc.pw/
2019-01-08 07:29:03 +00:00
// @version 0.0.7
2019-01-08 06:33:58 +00:00
// @description 去除百度上下推广广告
// @author MiaoWoo
// @include http*://*.baidu.*
// @grant none
// @namespace yumc
// ==/UserScript==
(function() {
2019-01-08 06:36:10 +00:00
'use strict';
2019-01-08 06:43:16 +00:00
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){
2019-01-08 07:28:03 +00:00
count += cn;
2019-01-08 06:43:16 +00:00
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+'条';
2019-01-08 06:36:10 +00:00
}
2019-01-08 06:33:58 +00:00
}
2019-01-08 06:36:10 +00:00
}
2019-01-08 06:43:16 +00:00
function clear() {
2019-01-08 07:29:03 +00:00
var tempCount = 0
2019-01-08 06:43:16 +00:00
selectors.forEach(function(selector) {
var doms = document.querySelectorAll(selector);
if(doms.length){
doms = Array.from(doms);
2019-01-08 07:28:03 +00:00
tempCount += doms.length;
2019-01-08 06:43:16 +00:00
doms.forEach(function(dom) {
dom.parentNode.removeChild(dom);
});
}
});
2019-01-08 07:28:03 +00:00
var adKeyword = ['广告', '评价']
var classKeyWord = ['.m', 'a span']
classKeyWord.forEach(function (c) {
2019-01-08 07:01:25 +00:00
var result = $(c)
result.each(function (index,element) {
2019-01-08 07:28:03 +00:00
if(adKeyword.indexOf($(element).text())){
2019-01-08 07:01:25 +00:00
$(element).parent().parent().remove();
tempCount++
}
});
})
2019-01-08 07:28:03 +00:00
$('.ad-block').each(function (index,element) {
$(element).parent().parent().parent().remove();
tempCount++
})
$('div a').each(function (index, element) {
if($(element).text()=="广告"){
$(element).parent().parent().parent().parent().parent().parent().parent().remove()
}
tempCount++
})
showCount(tempCount);
2019-01-08 06:43:16 +00:00
}
2019-01-08 07:01:25 +00:00
setInterval(clear, 500);
2019-01-08 06:33:58 +00:00
})();