// ==UserScript== // @name 🔥🆕移除百度推广和广告内容🔥 // @namespace http://tampermonkey.net/ // @version 3.0.1 // @author iemsauce3 // @description [正常使用 🟢]移除烦人和可能不确信的推广及广告(小浮窗监视屏蔽数量,可手动关闭) // @match *://*.baidu.com/* // @license MIT // @downloadURL none // ==/UserScript== //---------------------------------------------------------- //重新封装Storage class Storage{ constructor(name){ this.name = 'storage'; } //设置缓存 setItem(params){ let obj = { name:'', value:'', date:todayFormate()//记录何时将值存入缓存,eg: 2022-04-22 } let options = {}; //将obj和传进来的params合并 Object.assign(options,obj,params); //如果options.expires没有设置,就判断一下value的类型 let type = Object.prototype.toString.call(params); //如果value是对象或者数组对象的类型,就先用JSON.stringify转一下,再存进去 if(type == '[object Object]' || type == '[object Array]'){ options = JSON.stringify(options); } localStorage.setItem(params.name,options); } setItemValue(name,value){ let item = this.getItemObj(name); let type = Object.prototype.toString.call(item); if(item == null || type == '[object Object]' || type == '[object Array]'){ this.setItem({name:name, value:value}); } else{ localStorage.setItem(name,value); } } getItemObj(name){ let item = localStorage.getItem(name); //先将拿到的试着进行json转为对象的形式 try{ item = JSON.parse(item); }catch(error){ //如果不行就不是json的字符串,就直接返回 item = item; } return item; } //拿到缓存 getItemValue(name){ let item = localStorage.getItem(name); if(item == null) return item; //先将拿到的试着进行json转为对象的形式 try{ item = JSON.parse(item); }catch(error){ //如果不行就不是json的字符串,就直接返回 item = item; } let type = Object.prototype.toString.call(item); if(type == '[object Object]' || type == '[object Array]'){ return item.value; }else{ return item; } } //移出缓存 removeItem(name){ localStorage.removeItem(name); } //移出全部缓存 clear(){ localStorage.clear(); } } var tgTotal=0, ggTotal=0; removeTimes=0; var todayAds = 0, allAds = 0; var adsInterval = null; $(document).ready(function(){ initStorage(); //初始化 var uri = window.location.href; if(uri.indexOf('baidu.com') < 0) return; if(uri.indexOf('fanyi.baidu.com') > 0) { $('#footer-products-container').remove(); $('.follow-wrapper').remove(); } else if(uri.indexOf('www.baidu.com') > 0){ $('#wrapper_wrapper').before(`
关闭浮窗

「广告+推广」
今日过滤 0
总计 0

拦截情况
`); setTimeout(function(){ if(getCookie("close") == ""){ $('#closeView').parent().show(); $('#showView').parent().hide(); } else{ $('#closeView').parent().hide(); $('#showView').parent().show(); } removePre(); },500); $('#su').click(function(){ console.log('点击了搜索'); removePre(); }); $('#page div a').click(function(){ console.log('点击了页码'); removePre(); }); $('#closeView').click(function(){ $(this).parent().hide(); setCookie("close","true",7*24*3600); $('#showView').parent().show(); }); $('#showView').click(function(){ $(this).parent().hide(); setCookie("close","true",0.1); $('#closeView').parent().show(); }); } }); // 初始化相关storage initStorage = function(){ let initFlag = localStorage.getItem('initFlag'); if(initFlag == 1) return; console.log('【移除百度推广和广告内容】初始化数据...'); let storage = new Storage(); storage.setItem({name:'todayAds',value:0}); storage.setItem({name:'allAds',value:0}); localStorage.setItem('initFlag',1); console.log('【移除百度推广和广告内容】初始化完成!'); } var removePre = function(){ //每次手动按“搜索”后广告移除次数阀值清零 removeTimes = 0; adsInterval = setInterval(function(){ removeTimes++; removeAds(); if(removeTimes==2) reBindEvent(); },1000); } var removeAds = function(){ getStorageAdCounts(); var rs=''; var content = $('#content_left'); var tuiguang = content.find('.ec-tuiguang'); var newAds = 0; if(tuiguang.length>0){ tgTotal+=tuiguang.length; for(var i=0;i 10){ clearInterval(adsInterval); removeTimes = 0; console.log('Interval Over'); } } //重新绑定事件 reBindEvent = function(){ console.log('reBindEvent'); $('#page div a').unbind('click').bind('click',function(){ console.log('reBindEvent-点击了页码'); removePre(); }); $('#rs_new a').unbind('click').bind('click',function(){ console.log('reBindEvent-点击了相关搜索下的按钮'); removePre(); }); } function setCookie(cname,cvalue,exdays){ var d = new Date(); d.setTime(d.getTime()+(exdays*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } function getCookie(cname){ var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i