-
Notifications
You must be signed in to change notification settings - Fork 13
/
Utils.js
238 lines (213 loc) · 9.81 KB
/
Utils.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
"use strict";
//************************************Callbacks************************************
//Boot up sequence
window.currentManifestVersion = "1.2.9.4";
window.currentVersion = 62;
let AlwaysOn;
let isLoaded;
try {
AlwaysOn = localStorage.getItem("bc-cursed-always-on");
} catch (err) { console.log(err); }
LoginListener();
async function LoginListener() {
while (!isLoaded) {
try {
while ((!window.CurrentScreen || window.CurrentScreen == "Login") && !isLoaded) {
await new Promise(r => setTimeout(r, 2000));
}
isLoaded = true;
//Initialize base functions
//InitBasedFns();
//AlwaysOn
if (AlwaysOn == "enabled") {
CursedStarter();
TryPopTip(31);
}
} catch (err) { console.log(err); }
await new Promise(r => setTimeout(r, 2000));
}
}
/** Starts the script */
function CursedStarterBtn() {
CursedStarter();
}
async function CursedStarter() {
try {
//Verify if we can start the curse
const isNotOk = await CheckVersion();
if (isNotOk) {
return;
}
console.log(`Loading Curse! Version: ${window.currentManifestVersion}`);
//Cleans the existing chatlog
document.querySelectorAll(".ChatMessage:not([verified=true]").forEach(msg => {
let verifiedAtt = document.createAttribute("verified");
verifiedAtt.value = "true";
msg.setAttributeNode(verifiedAtt);
});
// Just restarts if the curse already exists (prevents dupes)
if (window.cursedConfigInit && cursedConfig.isRunning == false) {
//Runs the script
cursedConfig.isRunning = true;
cursedConfig.onRestart = true;
InventoryAdd(Player, "Curse", "CurseItems");
InventoryAdd(Player, "Curse" + currentVersion, "CurseItems");
popChatSilent("Curse restarted.", "System");
} else if (!window.cursedConfigInit) {
InitCursedConfig();
window.cursedConfig = { ...cursedConfigInit };
window.oldStorage = null;
window.oldVersion = null;
window.vibratorGroups = ["ItemButt", "ItemFeet", "ItemVulva", "ItemNipples", "ItemVulvaPiercings", "ItemNipplesPiercings", "ItemDevices"];
window.brokenVibratingItems = ["MermaidSuit", "AnalHook"];
//Tries to load configs
let beforeParseStorage = null;
let beforeParseVersion = null;
try {
beforeParseStorage = localStorage.getItem(`bc-cursedConfig-${Player.MemberNumber}`);
beforeParseVersion = localStorage.getItem(`bc-cursedConfig-version-${Player.MemberNumber}`);
oldStorage = JSON.parse(beforeParseStorage);
oldVersion = JSON.parse(beforeParseVersion);
} catch (err) {
console.log(err);
alert(`CURSE ERROR: Invalid Configs Detected. Your stored data for #${Player.MemberNumber} could not be parsed and was reset. View the console to recover your flushed data. Error: M08`);
console.log(`Flushed data for #${Player.MemberNumber}: ${beforeParseStorage}`);
console.warn("You can fix your data and re-inject it through the console. This is a risky manipulation.");
}
//Pull config from log or create
if (!oldStorage) {
SendChat("The curse awakens on " + Player.Name + ".");
popChatSilent("Welcome to the curse! The curse allows for many mysterious things to happen... have fun discovering them. The help command should be able to get you started (" + cursedConfig.commandChar + cursedConfig.slaveIdentifier + " help). You can also get tips by using this command: " + cursedConfig.commandChar + cursedConfig.slaveIdentifier + " tip . There is an official discord if you have anything to say: https://discord.gg/9dtkVFP . Please report any issues or bug you encounter to ace (12401) - Ace__#5558 or on the discord server.", "System");
try {
localStorage.setItem(`bc-cursedConfig-version-${Player.MemberNumber}`, JSON.stringify(currentVersion));
} catch (err) { console.log(err); }
} else {
//Load previous data, takes care of upgrades or downgrades
cursedConfig = { ...cursedConfig, ...oldStorage };
//Set name immediately
let user = cursedConfig.charData.filter(c => c.Number == Player.MemberNumber);
if (user.length > 0 && user[0].Nickname) {
if (Player.Name != user[0].Nickname && !user[0].SavedName) {
cursedConfig.charData.filter(c => c.Number == Player.MemberNumber)[0].SavedName = Player.Name;
}
Player.Name = cursedConfig.hasIntenseVersion && ChatRoomSpace != "LARP" ? user[0].Nickname : user[0].SavedName;
}
if (oldVersion > currentVersion) {
alert("WARNING! Downgrading the curse to an old version is not supported. This may cause issues with your settings. Please reinstall the latest version. (Ignore this message if downgrading was the recommended action to a problem.) Error: V03");
}
if (oldVersion != currentVersion) {
localStorage.setItem(`bc-cursedConfig-version-${Player.MemberNumber}`, JSON.stringify(currentVersion));
alert("IMPORTANT! Please make sure you refreshed your page after updating. You might also need to refresh the extension in chrome://extensions.");
//Update messages after alert so they are not lost if wearer refreshes on alert and storage was updated
SendChat("The curse following " + Player.Name + " has changed.");
popChatSilent("You have loaded an updated version of the curse, make sure you have refreshed your page before using this version. Please report any new bugs on discord https://discord.gg/9dtkVFP. This update may have introduced new features, don't forget to use the help command to see the available commands. (" + cursedConfig.commandChar + cursedConfig.slaveIdentifier + " help)", "System");
} else if (oldVersion == currentVersion) {
SendChat("The curse follows " + Player.Name + ".");
popChatSilent("Have fun~ Please report any issues or bug you encounter to ace (12401) - Ace__#5558.", "System");
}
if (curseTips.find(T => !cursedConfig.seenTips.includes(T.ID) && !T.isContextual)) {
popChatSilent("There are unseen tips available. Use '" + cursedConfig.commandChar + cursedConfig.slaveIdentifier + " tip' to see one", "System");
}
}
//Runs the script
cursedConfig.isRunning = true;
cursedConfig.onRestart = true;
InitStartup();
InitHelpMsg();
InitAlteredFns();
InitCleanup(); //Cleans up the arrays/migrations
CursedCheckUp(); //Initial check
ChatlogProcess(); //Chatlog handling
ReminderProcess(); //Reminders handling
}
} catch (err) { console.error(err); }
}
/** Stops the script */
function CursedStopper() {
try {
if (cursedConfig.isRunning) {
cursedConfig.isRunning = false;
InventoryDelete(Player, "Curse", "CurseItems");
InventoryDelete(Player, "Curse" + currentVersion, "CurseItems");
popChatSilent("Curse stopped", "System");
}
} catch (err) { console.error(err); }
}
/** Intense Mode Switch On */
function CursedIntenseOn() {
try {
if (!cursedConfig.hasIntenseVersion) {
cursedConfig.hasIntenseVersion = true;
TryPopTip(2);
popChatSilent("Intense mode activated (risky).", "System");
}
} catch (err) { console.error(err); }
}
/** Intense Mode Switch Off */
function CursedIntenseOff() {
try {
if (cursedConfig.hasIntenseVersion) {
cursedConfig.hasIntenseVersion = false;
cursedConfig.say = "";
cursedConfig.hasFullMuteChat = false;
popChatSilent("Intense mode deactivated (safe).", "System");
}
} catch (err) { console.error(err); }
}
/** Always on mode to start on load switch on */
function AlwaysOnTurnOn() {
localStorage.setItem("bc-cursed-always-on", "enabled");
}
/** Always on mode to start on load switch off */
function AlwaysOnTurnOff() {
localStorage.setItem("bc-cursed-always-on", "disabled");
}
/** Checks if a version is not under a specific one ("X.X.X.X" format)*/
function VersionIsEqualOrAbove(v, c) {
let isOk = 0;
const vParsed = v.split(".");
const cParsed = c.split(".");
cParsed.forEach((N, Idx) => {
if (isOk == 0 && N > (vParsed[Idx] || 0)) {
isOk = -1;
}
if (isOk == 0 && N < (vParsed[Idx] || 0)) {
isOk = 1;
}
});
return isOk >= 0;
}
let cursedVersionData = null;
/** Version checking on startup
* @returns {Promise<Boolean>} If the curse has to be stopped
*/
async function CheckVersion() {
try {
const response = await fetch("https://ace-1331.github.io/ace12401-cursedscript/curseVersion.json");
if (response.ok) {
cursedVersionData = await response.json();
// When under minimum
if (!VersionIsEqualOrAbove(currentManifestVersion, cursedVersionData.minimum)) {
CursedStarter = () => {
alert("ERROR X80: Cannot start the curse. You are below the required version. Please update it to the latest stable version now if you wish to use it.");
};
CursedStarter();
return true;
}
// When under stable
if (!VersionIsEqualOrAbove(currentManifestVersion, cursedVersionData.stable)) {
alert("A new stable release is available. Please update the curse. If you stay in this out-of-date state for too long, you will eventually be forced to update when your version is no longer compatible.");
return;
}
// When under beta
/*if (!VersionIsEqualOrAbove(currentManifestVersion, cursedVersionData.beta)) {
alert("A new beta is available.");
return;
}*/
// When latest or beta, do nothing
}
} catch (err) {
//If first origin fails, we try again
console.log("Could not verify curse version: " + err);
}
}