1
0
Fork 0

更新 'baidu/clearAd.user.js'

master
502647092 2019-01-15 17:53:52 +08:00
parent 6da550d7ee
commit 8cabf1b74c
1 changed files with 72 additions and 55 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 百度广告去除 // @name 百度广告去除
// @namespace http://ide.yumc.pw/ // @namespace http://ide.yumc.pw/
// @version 0.0.7 // @version 0.0.8
// @description 去除百度上下推广广告 // @description 去除百度上下推广广告
// @author MiaoWoo // @author MiaoWoo
// @include http*://*.baidu.* // @include http*://*.baidu.*
@ -15,10 +15,16 @@
#content_left [style*="display:block !important;visibility:visible !important"] #content_left [style*="display:block !important;visibility:visible !important"]
[tpl="right_toplist"] [tpl="right_toplist"]
[class="c-gray c-feedback"] [class="c-gray c-feedback"]
[data-click*="vLevel"]
`; `;
selectors = selectors.trim().split('\n'); selectors = selectors.trim().split('\n');
var count = 0; var count = 0;
function clearDom(dom){
if(dom.parentNode){
dom.parentNode.removeChild(dom);
}
}
function showCount(cn){ function showCount(cn){
if(cn>0){ if(cn>0){
count += cn; count += cn;
@ -37,44 +43,55 @@ margin-bottom:30px;
content_right.insertAdjacentHTML('afterbegin','<div id="msg-remove" style="'+style+'"></div>'); content_right.insertAdjacentHTML('afterbegin','<div id="msg-remove" style="'+style+'"></div>');
msgCount = document.querySelector('#msg-remove'); msgCount = document.querySelector('#msg-remove');
} }
msgCount.innerHTML = '已过滤:'+count+'条垃圾广告,本次过滤:'+cn+'条'; msgCount.innerHTML = `已过滤 ${count}条垃圾广告 本次过滤:${cn}`;
} }
} }
} }
function clear() {
var tempCount = 0 function clearResult(){
var count = 0;
selectors.forEach(function(selector) { selectors.forEach(function(selector) {
var doms = document.querySelectorAll(selector); var doms = document.querySelectorAll(selector);
if(doms.length){ if(doms.length){
doms = Array.from(doms); doms = Array.from(doms);
tempCount += doms.length; count += doms.length;
doms.forEach(function(dom) { doms.forEach(dom => clearDom(dom));
dom.parentNode.removeChild(dom);
});
} }
}); });
return count;
}
function clearByTag(){
var count = 0;
var adKeyword = ['广告', '评价'] var adKeyword = ['广告', '评价']
var classKeyWord = ['.m', 'a span'] var classKeyWord = ['m', 'a span']
classKeyWord.forEach(function (c) { classKeyWord.forEach(function (c) {
var result = $(c) Array.from(document.getElementsByClassName(c)).forEach(function (element) {
result.each(function (index,element) { if (adKeyword.indexOf(element.innerText) > -1){
if(adKeyword.indexOf($(element).text())){ clearDom(element.parentNode.parentNode)
$(element).parent().parent().remove(); count++
tempCount++
} }
}); });
}) })
$('.ad-block').each(function (index,element) { return count;
$(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++
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); showCount(tempCount);
} }
setInterval(clear, 500); //setTimeout(function(){clear();}, 500);
setInterval(function(){clear();}, 500);
})(); })();