Hide Spam Messages

Hides messages from a specific user list on willyoupressthebutton.com

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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)
}