2019-01-08 06:33:58 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name 百度广告去除
|
|
|
|
// @namespace http://ide.yumc.pw/
|
2019-01-15 09:53:52 +00:00
|
|
|
// @version 0.0.8
|
2019-01-08 06:33:58 +00:00
|
|
|
// @description 去除百度上下推广广告
|
|
|
|
// @author MiaoWoo
|
|
|
|
// @include http*://*.baidu.*
|
|
|
|
// @grant none
|
|
|
|
// @namespace yumc
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
(function() {
|
2019-01-15 09:53:52 +00:00
|
|
|
'use strict';
|
|
|
|
var selectors = `
|
2019-01-08 06:43:16 +00:00
|
|
|
#content_left [style*="display:block !important;visibility:visible !important"]
|
|
|
|
[tpl="right_toplist"]
|
|
|
|
[class="c-gray c-feedback"]
|
|
|
|
`;
|
2019-01-15 09:53:52 +00:00
|
|
|
selectors = selectors.trim().split('\n');
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
function clearDom(dom){
|
|
|
|
if(dom.parentNode){
|
|
|
|
dom.parentNode.removeChild(dom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = `
|
2019-01-08 06:43:16 +00:00
|
|
|
line-height: 42px;
|
|
|
|
text-align: center;
|
|
|
|
background: #0c0;
|
|
|
|
color: #fff;
|
|
|
|
margin-bottom:30px;
|
|
|
|
`;
|
2019-01-15 09:53:52 +00:00
|
|
|
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:43:16 +00:00
|
|
|
}
|
2019-01-08 06:33:58 +00:00
|
|
|
}
|
2019-01-15 09:53:52 +00:00
|
|
|
|
|
|
|
function clearResult(){
|
|
|
|
var count = 0;
|
|
|
|
selectors.forEach(function(selector) {
|
|
|
|
var doms = document.querySelectorAll(selector);
|
|
|
|
if(doms.length){
|
|
|
|
doms = Array.from(doms);
|
|
|
|
count += doms.length;
|
|
|
|
doms.forEach(dom => clearDom(dom));
|
|
|
|
}
|
2019-01-08 06:43:16 +00:00
|
|
|
});
|
2019-01-15 09:53:52 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearByTag(){
|
|
|
|
var count = 0;
|
|
|
|
var adKeyword = ['广告', '评价']
|
|
|
|
var classKeyWord = ['m', 'a span']
|
|
|
|
classKeyWord.forEach(function (c) {
|
|
|
|
Array.from(document.getElementsByClassName(c)).forEach(function (element) {
|
|
|
|
if (adKeyword.indexOf(element.innerText) > -1){
|
|
|
|
clearDom(element.parentNode.parentNode)
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearByClass(){
|
|
|
|
var count = 0;
|
|
|
|
Array.from(document.getElementsByClassName('ad-block')).forEach(function (element) {
|
|
|
|
clearDom(element.parentNode.parentNode.parentNode)
|
|
|
|
count++
|
|
|
|
})
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
|
|
|
var tempCount = 0
|
|
|
|
tempCount += clearResult();
|
|
|
|
tempCount += clearByTag();
|
|
|
|
tempCount += clearByClass();
|
|
|
|
showCount(tempCount);
|
|
|
|
}
|
|
|
|
//setTimeout(function(){clear();}, 500);
|
|
|
|
setInterval(function(){clear();}, 500);
|
2019-01-08 06:33:58 +00:00
|
|
|
})();
|