Force Connect ✝ By Pashka

Join our Discord — dsc.gg/moo-moo

// ==UserScript==
// @name         Force Connect ✝ By Pashka
// @namespace    Join our Discord — dsc.gg/moo-moo
// @author       Pashka
// @description  Join our Discord — dsc.gg/moo-moo
// @icon         https://r2.e-z.host/b178d1da-d695-49e8-a6c1-9a15c1ddf697/lfsn1c1t.png
// @match        *://moomoo.io/*
// @match        *://sandbox.moomoo.io/*
// @match        *://dev.moomoo.io/*
// @grant        none
// @run-at       document-start
// @version      1.1
// ==/UserScript==

// Reloads the Website if the Server is Full
(function() {
    "use strict";

    const customLog = console.log;

    function createCustomHook(target, prop, callback) {
        const customSymbol = Symbol(prop);
        Object.defineProperty(target, prop, {
            get() {
                return this[customSymbol];
            },
            set(value) {
                callback(this, customSymbol, value);
            },
            configurable: true
        });
    }

    function customSleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    async function customReload() {
        await customSleep(1500);
        window.onbeforeunload = null;
        location.reload();
    }

    createCustomHook(Object.prototype, "errorCallback", function(that, symbol, value) {
        that[symbol] = value;

        if (typeof value !== "function") return;
        that[symbol] = new Proxy(value, {
            apply(target, _this, args) {
                window.alert = function() {}
                customReload();
                return target.apply(_this, args);
            }
        });
    });

    function customizeWebsocketHandler(method) {
        const set = Object.getOwnPropertyDescriptor(WebSocket.prototype, method).set;
        Object.defineProperty(WebSocket.prototype, method, {
            set(callback) {
                return set.call(this, new Proxy(callback, {
                    apply(target, _this, args) {
                        customReload();
                        return target.apply(_this, args);
                    }
                }));
            }
        });
    }

    customizeWebsocketHandler("onclose");
    customizeWebsocketHandler("onerror");

})();