Hide Spam Messages

Hides messages from a specific user list on willyoupressthebutton.com

当前为 2022-11-01 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hide Spam Messages
// @namespace    https://greasyfork.org/en/users/945115
// @version      0.2
// @description  Hides messages from a specific user list on willyoupressthebutton.com
// @author       Unmatched Bracket
// @match        *://www.willyoupressthebutton.com/*
// @match        *://willyoupressthebutton.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=willyoupressthebutton.com
// @grant        none
// @license      The Unlicence
// ==/UserScript==

var oldSend = XMLHttpRequest.prototype.send
var oldOpen = XMLHttpRequest.prototype.open

// Block list. Messages from these usernames will be hidden.
const block_list = [
    "This_is_legal", // pure spam
    "SweetCandy98", // inaproppriate spamming
]

XMLHttpRequest.prototype.open = function(_, url) {
    if (url.includes("api/comments/get")) {
        this.doInject = true
    }
    oldOpen.call(this, ...arguments)
}

XMLHttpRequest.prototype.send = function() {
    if (this.doInject) {
        var oldReadyChange = this.onreadystatechange
        this.onreadystatechange = function () {
            //console.log(this.readyState, this.status, this.responseType)
            if (this.readyState == 4) {
                console.log(this.response)
                var respJson = JSON.parse(this.response)
                respJson.injected = true
                respJson.data = respJson.data.filter((comment) => {
                    return !comment.user || !block_list.includes(comment.user.name)
                })

                var newText = JSON.stringify(respJson)
                var newResp = () => {
                    return newText
                }
                this.__defineGetter__("responseText", newResp)
                this.__defineGetter__("response", newResp)
            }
            oldReadyChange.call(this, "debug text")
        }
    }
    oldSend.call(this)
}