Moomoo.io Auto reloader

Automatically reload the page on disconnect and handle errors such as "Server is full"

  1. // ==UserScript==
  2. // @name Moomoo.io Auto reloader
  3. // @author Murka
  4. // @description Automatically reload the page on disconnect and handle errors such as "Server is full"
  5. // @icon https://moomoo.io/img/favicon.png?v=1
  6. // @version 0.4
  7. // @match *://moomoo.io/*
  8. // @match *://*.moomoo.io/*
  9. // @run-at document-start
  10. // @grant none
  11. // @license MIT
  12. // @namespace https://greasyfork.org/users/919633
  13. // ==/UserScript==
  14. /* jshint esversion:8 */
  15.  
  16. /*
  17. Author: Murka
  18. Github: https://github.com/Murka007
  19. Discord: https://discord.gg/sG9cyfGPj5
  20. Greasyfork: https://greasyfork.org/en/users/919633
  21. MooMooForge: https://github.com/MooMooForge
  22. */
  23.  
  24. (function() {
  25. "use strict";
  26.  
  27. const log = console.log;
  28. function createHook(target, prop, callback) {
  29. const symbol = Symbol(prop);
  30. Object.defineProperty(target, prop, {
  31. get() {
  32. return this[symbol];
  33. },
  34. set(value) {
  35. callback(this, symbol, value);
  36. },
  37. configurable: true
  38. })
  39. }
  40.  
  41. function sleep(ms) {
  42. return new Promise(resolve => setTimeout(resolve, ms));
  43. }
  44.  
  45. async function reload() {
  46. await sleep(1500);
  47. window.onbeforeunload = null;
  48. location.reload();
  49. }
  50.  
  51. // Handles errors such as "Server is full", "Failed to find server index" etc
  52. createHook(Object.prototype, "errorCallback", function(that, symbol, value) {
  53. that[symbol] = value;
  54.  
  55. if (typeof value !== "function") return;
  56. that[symbol] = new Proxy(value, {
  57. apply(target, _this, args) {
  58. window.alert = function(){}
  59. reload();
  60. return target.apply(_this, args);
  61. }
  62. })
  63. })
  64.  
  65. // Handle WebSocket close and error events
  66. function handleWebsocket(method) {
  67. const set = Object.getOwnPropertyDescriptor(WebSocket.prototype, method).set;
  68. Object.defineProperty(WebSocket.prototype, method, {
  69. set(callback) {
  70. return set.call(this, new Proxy(callback, {
  71. apply(target, _this, args) {
  72. reload();
  73. return target.apply(_this, args);
  74. }
  75. }))
  76. }
  77. })
  78. }
  79. handleWebsocket("onclose");
  80. handleWebsocket("onerror");
  81.  
  82. })();