-
Notifications
You must be signed in to change notification settings - Fork 3
/
PuddingInit.js
142 lines (117 loc) · 4.29 KB
/
PuddingInit.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
window.PuddingMod = {};
////////////////////////////////////////////////////////////////////
//RUNCODEBEFORE
////////////////////////////////////////////////////////////////////
window.PuddingMod.runCodeBefore = function () {
window.isVisi = false;
console.log("Thank you for loading Yarmiplay's Pudding Mod! Hope you enjoy :)");
console.log("Please provide feedback and report bugs in #snake-modding in the Official Google Snake Discord");
console.log("Google Snake SRC Discord link: https://discord.gg/dDuCTm62EZ");
window.getRandomBoolean = function () {
return Math.random() < 0.5;
}
window.getRandomInt = function (min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
window.escapeRegex = function escapeRegex(string) {
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
}
window.loadCode = function loadAndRunCodeSynchronous(url) {
let req = new XMLHttpRequest();
req.open('GET', url, false);
req.onload = function () {
if (this.status === 200) {
(1, eval)(this.responseText);
} else {
console.log(`Loading selected mod returned non-200 status. Received: ${this.status}`);
}
};
req.onerror = function (event) {
console.error(`Error when attempting to retrieve mod code from ${url}`);
console.log(event);
};
req.send();
}
window.NepDebug = false;
if (localStorage.getItem('snakeChosenMod') === "customUrl") {
console.log("Detect customUrl - enabling debug mode and printing initial code")
window.NepDebug = true;
}
window.catchError = function catchError(culprit_regex, code) {
try {
something = code.match(culprit_regex)[0];
} catch (e) {
console.log("I caught it!")
console.log(culprit_regex)
console.log(code)
throw e
}
return false;
}
//Style differently depending on if snake is centered.
let isSnakeCentered = !window.location.href.includes('fbx');
let advancedSettings = JSON.parse(localStorage.getItem('snakeAdvancedSettings')) ?? {};
if (advancedSettings.hasOwnProperty('fbxCentered') && advancedSettings.fbxCentered) {
isSnakeCentered = true;
}
//if (!isSnakeCentered) {
// Move menu so it doesn't overlap panels
//document.getElementsByClassName('bZUgDf')[0].style.width = '50%';
//}
window.Libraries = [
"Core",
"Theme",
"DistinctVisual",
"Counter",
"TimeKeeper",
"Fruit",
"TopBar",
"SnakeColor",
"SettingsSaver",
"SpeedInfo",
"InputDisplay",
"Timer",
"BootstrapMenu",
"CustomPortalPairs"];
console.log("Enabling Pudding Mod");
libUrlPrefix = window.NepDebug ? "http://127.0.0.1:5500/Libraries/" : "https://raw.githubusercontent.com/DarkSnakeGang/GoogleSnakePudding/main/Libraries/";
window.Libraries.forEach(LibName => {
console.log("Loading library: " + LibName)
eval("window." + LibName + ".make();")
});
};
////////////////////////////////////////////////////////////////////
//ALTERSNAKECODE
////////////////////////////////////////////////////////////////////
window.PuddingMod.alterSnakeCode = function (code) {
if (window.NepDebug) {
console.log(code)
}
code = code.replaceAll(/\$\$/gm, `doubleD`)
code = code.replaceAll(/\$\&/gm, `$ &`)
//code = code.assertReplaceAll(/\$i/gm, `something_i`)
window.Libraries.forEach(LibName => {
console.log("Alter code with library: " + LibName)
eval("code = window." + LibName + ".alterCode(code);")
});
console.log("Done, enjoy Pudding Mod!");
if (window.NepDebug) {
console.log(code)
}
return code;
};
////////////////////////////////////////////////////////////////////
//RUNCODEAFTER
////////////////////////////////////////////////////////////////////
window.PuddingMod.runCodeAfter = function () {
let modIndicator = document.createElement('div');
modIndicator.style = 'position:absolute;font-family:Roboto,Arial,sans-serif;color:white;font-size:14px;padding-top:4px;padding-left:30px;user-select: none;';
modIndicator.textContent = 'Pudding Mod';
if (window.loaded_code) {
modIndicator.textContent = 'Pudding Mod - Google Test Version';
}
let canvasNode = document.getElementsByClassName('jNB0Ic')[0];
document.getElementsByClassName('EjCLSb')[0].insertBefore(modIndicator, canvasNode);
};