煎蛋屏蔽器

鼠标悬停在ID附近,根据用户名屏蔽

// ==UserScript==
// @name        煎蛋屏蔽器
// @match       https://jandan.net/treehole*
// @match       https://jandan.net/pic*
// @match       https://jandan.net/top*
// @match       https://jandan.net/qa*
// @match       https://jandan.net/top*
// @match       https://jandan.net/ooxx*
// @match       https://jandan.net/duan
// @version     1.4.2
// @namespace   https://github.com/zunpiau
// @author      多巴胺
// @description 鼠标悬停在ID附近,根据用户名屏蔽
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_registerMenuCommand
// ==/UserScript==


let authors = GM_getValue("用户名列表") || {}
const l = location.toString().indexOf('jandan.net/top') >= 0 ?
      document.querySelector('.top-container > div') :
      document.querySelector('#comments')
const callback = function (mutationsList, observer) {
  for (let mutation of mutationsList) {
    mutation.addedNodes.forEach(node => {
      if (node.nodeType !== 1) {
        return
      }
      const meta = node.querySelector('.comment-meta')
      if (!meta) {
        return
      }
      const authorElem = meta.querySelector('.author-anonymous') || meta.querySelector('.author-logged')
      if (!authorElem) {
        return
      }
      const author = authorElem.innerText
      if (authors[author]) {
        l.removeChild(node)
      } else {
        const authorBtn = document.createElement('a')
        authorBtn.setAttribute('style', 'display:none')
        authorBtn.innerText = '屏蔽用户名'
        meta.addEventListener("mouseover", () => {
          authorBtn.setAttribute('style', 'margin-left: 0.5rem')
        })
        meta.addEventListener("mouseleave", () => {
          authorBtn.setAttribute('style', 'display:none')
        })
        authorBtn.addEventListener("click", () => {
          authors = GM_getValue("用户名列表") || {}
          authors[author] = " "
          GM_setValue("用户名列表", authors)
          l.removeChild(node)
        })
        meta.appendChild(authorBtn)
      }
    })
  }
};
new MutationObserver(callback).observe(l, { attributes: false, childList: true, subtree: false });

GM_registerMenuCommand("清空屏蔽用户名列表",function() {
  GM_setValue("用户名列表", {})
});