Greasy Fork

Greasy Fork is available in English.

掘金沸点过滤器

过滤掉那些看起来很睿智的沸点和伙计

当前为 2019-08-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         掘金沸点过滤器
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  过滤掉那些看起来很睿智的沸点和伙计
// @author       睿智的河水
// @match        *://juejin.im/pins*
// @match        *://juejin.im/topic/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict'

  /**
   * 获取缓存数据
   */
  const getLocal = key => {
    return JSON.parse(localStorage.getItem(key))
  }

  /**
   * 设置缓存数据
   */
  const setLocal = (key, val) => {
    return localStorage.setItem(key, JSON.stringify(val))
  }

  /**
   * 过滤列表数据
   */
  const filterList = () => {
    const pinlist = document.querySelectorAll('.pin')
    const blockList = getLocal('BLOCK_LIST') || []
    const blockUser = getLocal('BLOCK_USER') || []

    for (const v of Array.from(pinlist)) {
      const vInfo = v.__vue__.pin
      if (
        blockList.includes(vInfo.id) ||
        blockUser.includes(vInfo.uid)
      ) {
        v.parentElement.classList.add('hidden')
        continue
      }
      const menu = v.querySelector('.dropdown-menu')
      if (menu && !menu.classList.contains('is-append')) {
        const bPin = document.createElement('li')
        const bUser = document.createElement('li')
        bPin.textContent = '屏蔽此条'
        bUser.textContent = '屏蔽此人'
        bPin.dataset['v-1776af1f'] = ''
        bUser.dataset['v-1776af1f'] = ''
        bPin.onclick = () => {
          blockList.push(vInfo.id)
          setLocal('BLOCK_LIST', blockList)
          v.parentElement.classList.add('hidden')
        }
        bUser.onclick = () => {
          blockUser.push(vInfo.uid)
          setLocal('BLOCK_USER', blockUser)
          v.parentElement.classList.add('hidden')
          filterList()
        }
        menu.appendChild(bPin)
        menu.appendChild(bUser)
        menu.classList.add('is-append')
      }
    }
  }

  /**
   * 监听数据变化
   */
  const juejin = document.querySelector('#juejin').__vue__
  const watchList = [
    '$store.state.view.activityIndex.activityList',
    '$store.state.view.activityIndex.topicPinList.list',
    '$store.state.view.activityIndex.hotList.list',
    '$store.state.view.topic.pinlist.list'
  ]
  watchList.forEach(v => {
    juejin.$watch(
      v,
      list => {
        juejin.$nextTick(()=> {
          filterList()
        })
      }
    )
  })
})()