Moomoo.io Auto reloader

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

当前为 2022-06-24 提交的版本,查看 最新版本

  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.2
  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. */
  22.  
  23. (function() {
  24. "use strict";
  25.  
  26. const log = console.log;
  27. function createHook(target, prop, callback) {
  28. const symbol = Symbol(prop);
  29. Object.defineProperty(target, prop, {
  30. get() {
  31. return this[symbol];
  32. },
  33. set(value) {
  34. callback(this, symbol, value);
  35. },
  36. configurable: true
  37. })
  38. }
  39.  
  40. function sleep(ms) {
  41. return new Promise(resolve => setTimeout(resolve, ms));
  42. }
  43.  
  44. async function reload() {
  45. await sleep(1500);
  46. window.onbeforeunload = null;
  47. location.reload();
  48. }
  49.  
  50. // Handles errors such as "Server is full", "Failed to find server index" etc
  51. createHook(Object.prototype, "errorCallback", function(that, symbol, value) {
  52. that[symbol] = value;
  53.  
  54. if (typeof value !== "function") return;
  55. that[symbol] = new Proxy(value, {
  56. apply(target, _this, args) {
  57. window.alert = function(){}
  58. reload();
  59. return target.apply(_this, args);
  60. }
  61. })
  62. })
  63.  
  64. // Handle WebSocket close and error events
  65. window.WebSocket = class extends WebSocket {
  66. constructor(...args) {
  67. super(...args);
  68. this.addEventListener("close", () => reload());
  69. this.addEventListener("error", () => reload());
  70. }
  71. }
  72.  
  73. })();