站点js屏蔽他人广告
作者:admin发布时间:2021-09-11分类:横幅广告浏览:评论:25
前言
以前自己建设博客的时候,出现一个问题,那就是动不动弹出广告,不晓得这个是怎么查到我的站点的,但是加入了屏蔽js,就没遇到了,在此分享。
正文
防止动态加载脚本
((){=;=(tag){(tag){case''('禁用动态添加脚本,防止广告加载');break;default:returncreateElement.apply(this,arguments);}}})();
iframe广告
//注入页面的脚本文件;$(function(){varclearAd={//由于manifest文件匹配规则只有通配没有非功能,所以可在此处添加不想删除广告的页面checkUrl:function(){varCheckflag=0,url=window.location.href;//手动添加不需要清除广告的域varnotDel=["www.baidu.com","taobao.com","tmall.com","jd.com"];//正则匹配for(vari=0;inotDel.length;i++){varreg=newRegExp(notDel[i],"g");if(reg.test(url)){console.log('Thispagedoesnotclearads.');break;}else{if(i==notDel.length-1){Checkflag=1;}}}if(Checkflag==1){this.clear();this.findSomeAdPossible();}},clear:function(){console.log('ClearStart');//此处可手动添加广告框id名,去除顽疾ad必备varad_id_name=["cproIframe2001holder","cproIframe2002holder","cproIframe2003holder","cproIframe2004holder","cproIframe2005holder","cproIframe2006holder","cproIframe2007holder","cproIframe2008holder","cproIframe2009holder","id_300x250_banner_top","ads","google_image_div","mx_cs_71603_1261456","AC_TR86_71603","cproIframe_u2060917_1","content_right","left-promotion","top_ads","layerd"];//此处添加广告框类名varad_css_name=["cproIframe_u410704_3","img_ad","hover_btn"];for(vari=0;iad_id_name.length;i++){//使用remove删除节点,提升性能$('#'+ad_id_name[i]).remove();}for(vari=0;iad_css_name.length;i++){$('.'+ad_css_name[i]).remove();}},//简单的智能算法findSomeAdPossible:function(){varsap=$('diviframe'),ad_img=$('divscript').parent().find('img,embed'),float_img=$('divobject').parent().find('img,embed');this.arrayDel(sap,360,200);this.arrayDel(ad_img,350,150);this.arrayDel(float_img,350,150);},arrayDel:function(arr,conWidth,conHeight){varlen=arr.length;for(vari=0;ilen;i++){varself=arr.eq(i);if(self.width()=conWidth||self.height()=conHeight){self.remove();}}},init:function(){this.checkUrl();}}$(document).ready(function(){clearAd.init();//为防止ajax异步延时加载的广告隔4s再清除一次setTimeout(function(){clearAd.init();},4000)});})
- 上一篇:小米手机每次开机都有广告
- 下一篇:去广告的js脚js脚本屏蔽手机广告本
相关推荐
你 发表评论:
欢迎- 横幅广告排行
- 最近发表
已有25位网友发表了看法: