Greasy Fork

Greasy Fork is available in English.

洛谷关键词屏蔽讨论

屏蔽标题中包含关键词的讨论

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         洛谷关键词屏蔽讨论
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  屏蔽标题中包含关键词的讨论
// @author       You
// @match        https://www.luogu.com.cn
// @match        https://www.luogu.com.cn/discuss*
// @icon         https://www.luogu.com.cn/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
  const BLOCKLIST = [' 求调 ', ' 站外题 ', ' 小游戏 ', ' 咕值 ', ' 估值 ', ' 捞 ', 'pts', ' 全 WA',
    ' 全 wa',
  ];
  const BLOCKLISTREGEX = [/\d {1,2} 分 /];
  const HREF = document.location.href;
  setTimeout (() => {
    if (HREF.indexOf ('discuss') === -1) {
      const DISCUSSLIST = document.querySelectorAll ('.am-panel-primary');
      console.log (DISCUSSLIST);
      for (const DISCUSS of DISCUSSLIST) {
        if (DISCUSS.children [0].children [1] === undefined) {
          continue;
        }
        const TITLE = DISCUSS.children [0].children [1].children [0].innerText;
        let erased = false;
        for (const KEY of BLOCKLIST) {
          if (TITLE.indexOf (KEY) !== -1) {
            DISCUSS.parentNode.removeChild (DISCUSS);
            erased = true;
            break;
          }
        }
        if (erased) {
          continue;
        }
        for (const REGEXP of BLOCKLISTREGEX) {
          if (REGEXP.test (TITLE)) {
            DISCUSS.parentNode.removeChild (DISCUSS);
            break;
          }
        }
      }
    } else {
      const DISCUSSLIST =
       document.querySelectorAll ('.card.post-item.padding-default');
      for (const DISCUSS of DISCUSSLIST) {
        const TITLE =
          DISCUSS.children [0].children [1].children [0].children [0].innerText;
        let erased = false;
        for (const KEY of BLOCKLIST) {
          if (TITLE.indexOf (KEY) !== -1) {
            DISCUSS.parentNode.removeChild (DISCUSS);
            erased = true;
            break;
          }
        }
        if (erased) {
          continue;
        }
        for (const REGEXP of BLOCKLISTREGEX) {
          if (REGEXP.test (TITLE)) {
            DISCUSS.parentNode.removeChild (DISCUSS);
            break;
          }
        }
      }
    }
  }, 1000);
})();