Greasy Fork

Greasy Fork is available in English.

New script - weibo.com

2021/6/19 上午12:35:38

当前为 2021-06-18 提交的版本,查看 最新版本

// ==UserScript==
// @name        New script - weibo.com
// @namespace   Violentmonkey Scripts
// @match       https://weibo.com/u/3043061127/home
// @grant       none
// @version     1.0
// @author      -
// @description 2021/6/19 上午12:35:38
// ==/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) 
  }
  
})()