// ==UserScript==
// @name 广告去除
// @namespace http://tampermonkey.net/
// @version 0.6
// @description 移除广告
// @author You
// @match *://*.csdn.net/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 广告classname
var fuck_class_ad = ["programmer1Box","toolbar-advert",'blog-slide-ad-box','top-special-info','app-qr-box'];
// 广告id
var fuck_id_ad = ['recommendAdBox','kp_box_ww9877','kp_box_www_content','kp_box_www_swiper','kp_box_www_swiper_ban','nps-box'];
var ad_class_len = fuck_class_ad.length;
var ad_id_len = fuck_id_ad.length;
// 已经干掉的数量
var ad_kill_num = 0;
// 重复检查10轮
var check_num = 10;
console.log('广告去除启动...');
// 循环检查
var t = setInterval(function(){
// 寻找指定classname标签的元素并干掉
for(var i = 0;i<ad_class_len;i++){
//console.log('寻找 classname=:'+fuck_class_ad[i]+'的元素');
var ad = document.getElementsByClassName(fuck_class_ad[i])[0];
if(ad != undefined){
ad_kill_num = ad_kill_num + 1;
ad.remove();
console.log( 'classname='+ fuck_class_ad[i] + '的元素找到了,并且已干掉!!!');
}else{
//console.log(ad);
}
}
// 寻找指定id标签的元素并干掉
for(var i2=0;i2<ad_id_len;i2++){
//console.log('寻找 id=:'+fuck_id_ad[i]+'的元素');
var ad2 = document.getElementById(fuck_id_ad[i2]);
if(ad2 != null){
ad_kill_num = ad_kill_num + 1;
ad2.remove();
console.log( 'id='+ fuck_id_ad[i] + '的元素找到了,并且已干掉!!!');
}else{
//console.log(ad2);
}
}
if(ad_kill_num == (ad_class_len + ad_id_len) || check_num <= 0){
console.log('广告清除完毕...');
clearInterval(t);
}
check_num = check_num - 1;
},1000);
})();
标签:box,ad,fuck,id,classname,广告,var,油猴 From: https://www.cnblogs.com/hwnd/p/16978519.html