Masiro Block User

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

当前为 2024-01-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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)