Masiro Block User

31/03/2023, 5:40:10 am

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Masiro Block User
// @namespace   Violentmonkey Scripts
// @license     GPL
// @match       *://masiro.me/*
// @require     https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM.getValue
// @grant       GM.setValue
// @version     1.0
// @author      Hou Rui
// @description 31/03/2023, 5:40:10 am
// ==/UserScript==

let config = new GM_config({
  'id': 'MisiroBlockUserConfig',
  'title': 'Masiro Block User',
  'fields': {
    'blockedUsers': {
      'label': '每行输入一个用户名',
      'section': ['屏蔽用户列表'],
      'type': 'textarea',
    }
  },
  'events': {
    'init': loadConfig,
    'save': loadConfig,
  },
  'css': '#MisiroBlockUserConfig textarea { width: 100%; height: 70%; }'
})

function loadConfig() {
  let blockNames = config.get('blockedUsers').split('\n').map(line => line.trim())
  console.log(`Blocked users: ${blockNames}`)

  let contentBlocks = document.querySelectorAll('span.reply_content, div.comment-content')
  for (let block of contentBlocks) {
    let attrs = block.attributes['data-name']
    if (attrs === undefined) {
      return;
    }
    let userName = attrs.value
    if (blockNames.includes(userName)) {
      block.innerHTML = '[已屏蔽]'
      let sibling = block.parentElement.nextElementSibling
      if (sibling === null) {
        return;
      }
      if (sibling.className === 'reply_list') {
        sibling.innerHTML = ''
      }
    }
  }
}

let commentButton = document.getElementById('comment-btn')
let configButton = document.createElement('button')

configButton.classList.add('btn', 'btn-primary')
configButton.textContent = '屏蔽设置'
configButton.style.float = 'right'
configButton.style.padding = commentButton.style.padding;
configButton.style.marginRight = commentButton.style.marginRight;
configButton.style.fontSize = commentButton.style.fontSize;
configButton.onclick = () => config.open()

commentButton.parentNode.appendChild(configButton)