煎蛋屏蔽器

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

目前為 2025-02-06 提交的版本,檢視 最新版本

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


let authorIds = GM_getValue("防伪码列表") || {}
let authorNames = GM_getValue("用户名列表") || {}
const l = document.querySelector('ol.commentlist')
l.querySelectorAll('li').forEach(e => {
  const authorElem = e.querySelector('.author')
  if (!authorElem) {
    return
  }
  const strong = authorElem.querySelector('strong')
  const authorId = strong.getAttribute('title').substr(4)
  const authorName = strong.innerText
  if (authorIds[authorId] || authorNames[authorName]) {
    l.removeChild(e)
  } else {
    const authorIdBtn = document.createElement('a')
    const authorNameBtn = document.createElement('a')
    authorIdBtn.setAttribute('style', 'display:none')
    authorIdBtn.innerText = '屏蔽防伪码'
    authorNameBtn.setAttribute('style', 'display:none')
    authorNameBtn.innerText = '屏蔽用户名'
    authorElem.addEventListener("mouseover", () => {
      authorIdBtn.setAttribute('style', '')
      authorNameBtn.setAttribute('style', '')
    })
    authorElem.addEventListener("mouseleave", () => {
      authorIdBtn.setAttribute('style', 'display:none')
      authorNameBtn.setAttribute('style', 'display:none')
    })
    authorIdBtn.addEventListener("click", () => {
      authorIds = GM_getValue("防伪码列表") || {}
      authorIds[authorId] = authorName
      GM_setValue("防伪码列表", authorIds)
      l.removeChild(e)
    })
    authorNameBtn.addEventListener("click", () => {
      authorNames = GM_getValue("用户名列表") || {}
      authorNames[authorName] = authorId
      GM_setValue("用户名列表", authorNames)
      l.removeChild(e)
    })

    authorElem.appendChild(document.createElement('br'))
    authorElem.appendChild(authorIdBtn)
    authorElem.appendChild(document.createElement('br'))
    authorElem.appendChild(authorNameBtn)
  }
})