// ==UserScript== // @name 去除广告模块 // @namespace Violentmonkey Scripts // @match https://weibo.com/u/3043061127/home // @grant none // @version 1.1 // @author - // @description 隐藏“全部关注”列表中的广告模块的简易脚本,被隐藏的部分会留有空白 // @downloadURL none // ==/UserScript== (function(){ // window.addEventListener('scroll',function(){ // const scroller = document.querySelector('#scroller') // const viewList = scroller.querySelectorAll('.vue-recycle-scroller__item-view') // for(const node of viewList){ // //判断是否含有负反馈 // const rubbish = node.querySelector('i.woo-font--cross[title=负反馈]') // console.log('rubbish',rubbish) // if(rubbish){ // node.style.display = 'none' // } // } // }) window.onload = () => { function throttle(fn,delay){ let valid = true return function() { if(!valid){ //休息时间 暂不接客 return false } // 工作时间,执行函数并且在间隔期内把状态位设为无效 valid = false setTimeout(() => { fn() valid = true; }, delay) } } /* 请注意,节流函数并不止上面这种实现方案, 例如可以完全不借助setTimeout,可以把状态位换成时间戳,然后利用时间戳差值是否大于指定间隔时间来做判定。 也可以直接将setTimeout的返回的标记当做判断条件-判断当前定时器是否存在,如果存在表示还在冷却,并且在执行fn之后消除定时器表示激活,原理都一样 */ // 以下照旧 function showTop () { const scroller = document.querySelector('#scroller') const viewList = scroller.querySelectorAll('.vue-recycle-scroller__item-view') for(const node of viewList){ //判断是否含有负反馈 const rubbish = node.querySelector('i.woo-font--cross[title=负反馈]') console.log('rubbish',rubbish) if(rubbish){ node.style.display = 'none' } } } window.onscroll = throttle(showTop, 500) } })()