Hide full rooms - bonk.io

Hides rooms that are full in bonk.io.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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 full rooms - bonk.io
// @namespace   left paren
// @match        https://bonk.io/gameframe-release.html
// @grant       none
// @version     1.0
// @author      left paren
// @license     Unlicense
// @description Hides rooms that are full in bonk.io.
// ==/UserScript==


let hfrOldSend = XMLHttpRequest.prototype.send
let hfrOldOpen = XMLHttpRequest.prototype.open

XMLHttpRequest.prototype.open = function(_, url) {
    if (url.includes("scripts/getrooms.php")) {
        this.hfrIsGetRooms = true
    }
    hfrOldOpen.call(this, ...arguments)
}

XMLHttpRequest.prototype.send = function(data) {
    if (this.isGetRooms) {
        this.hfrOldReadyChange = this.onreadystatechange
        this.onreadystatechange = function () {
            if (this.readyState == 4) {
                var respJson = JSON.parse(this.response)
                if (respJson.rooms) {
                  respJson.rooms = respJson.rooms.filter(room => room.players < room.maxplayers)
                }

                let newText = JSON.stringify(respJson)
                var newResp = () => {
                    return newText
                }
                this.__defineGetter__("responseText", newResp)
                this.__defineGetter__("response", newResp)
            }
            this.hfrOldReadyChange?.call(this, ...arguments)
        }
    }
    hfrOldSend.call(this, ...arguments)
}