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