更新 'baidu/clearAd.user.js'
This commit is contained in:
parent
6da550d7ee
commit
8cabf1b74c
@ -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.*
|
||||||
@ -10,71 +10,88 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var selectors = `
|
var selectors = `
|
||||||
#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 showCount(cn){
|
|
||||||
if(cn>0){
|
function clearDom(dom){
|
||||||
count += cn;
|
if(dom.parentNode){
|
||||||
var content_right = document.querySelector('#content_right');
|
dom.parentNode.removeChild(dom);
|
||||||
if(content_right){
|
}
|
||||||
content_right.style.position = 'relative';
|
}
|
||||||
var style = `
|
|
||||||
|
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;
|
line-height: 42px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background: #0c0;
|
background: #0c0;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
margin-bottom:30px;
|
margin-bottom:30px;
|
||||||
`;
|
`;
|
||||||
var msgCount = document.querySelector('#msg-remove');
|
var msgCount = document.querySelector('#msg-remove');
|
||||||
if(!msgCount){
|
if(!msgCount){
|
||||||
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() {
|
function clearResult(){
|
||||||
var tempCount = 0
|
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;
|
||||||
});
|
}
|
||||||
var adKeyword = ['广告', '评价']
|
|
||||||
var classKeyWord = ['.m', 'a span']
|
function clearByTag(){
|
||||||
classKeyWord.forEach(function (c) {
|
var count = 0;
|
||||||
var result = $(c)
|
var adKeyword = ['广告', '评价']
|
||||||
result.each(function (index,element) {
|
var classKeyWord = ['m', 'a span']
|
||||||
if(adKeyword.indexOf($(element).text())){
|
classKeyWord.forEach(function (c) {
|
||||||
$(element).parent().parent().remove();
|
Array.from(document.getElementsByClassName(c)).forEach(function (element) {
|
||||||
tempCount++
|
if (adKeyword.indexOf(element.innerText) > -1){
|
||||||
}
|
clearDom(element.parentNode.parentNode)
|
||||||
});
|
count++
|
||||||
})
|
}
|
||||||
$('.ad-block').each(function (index,element) {
|
});
|
||||||
$(element).parent().parent().parent().remove();
|
})
|
||||||
tempCount++
|
return count;
|
||||||
})
|
}
|
||||||
$('div a').each(function (index, element) {
|
|
||||||
if($(element).text()=="广告"){
|
function clearByClass(){
|
||||||
$(element).parent().parent().parent().parent().parent().parent().parent().remove()
|
var count = 0;
|
||||||
}
|
Array.from(document.getElementsByClassName('ad-block')).forEach(function (element) {
|
||||||
tempCount++
|
clearDom(element.parentNode.parentNode.parentNode)
|
||||||
})
|
count++
|
||||||
showCount(tempCount);
|
})
|
||||||
}
|
return count;
|
||||||
setInterval(clear, 500);
|
}
|
||||||
|
|
||||||
|
function clear() {
|
||||||
|
var tempCount = 0
|
||||||
|
tempCount += clearResult();
|
||||||
|
tempCount += clearByTag();
|
||||||
|
tempCount += clearByClass();
|
||||||
|
showCount(tempCount);
|
||||||
|
}
|
||||||
|
//setTimeout(function(){clear();}, 500);
|
||||||
|
setInterval(function(){clear();}, 500);
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue
Block a user