This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
196 lines (184 loc) · 8.21 KB
/
main.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
/*
shitty mod loader
*/
// we need some useful functions
const rotisserie = {
tooltip: function(text, inptype = "blue") {
let type = 'noticeInfo-3v29SJ'
switch(inptype) {
case "green":
type = 'noticeSuccess-P1EnBb';break;
case "red":
type = 'noticeDanger-1SIxaf';break;
case "purple":
type = 'noticeStreamerMode-1OlfKV';break;
case "dark-blue":
type = 'noticeFacebook-1eAoSW';break;
case "blurple":
type = 'noticeBrand-3o3fQA';break;
case "orange":
type = 'noticeDefault-16Om2m';break;
case "spotify":
type ='noticeSpotify-27AKmv';break;
default:
type = 'noticeInfo-3v29SJ'
break
}
document.querySelector('.tooltips').innerHTML = `
<div class="flexChild-1KGW5q" style="flex: 0 0 auto;">
<div>
<div class="${type} notice-3I4-y_ size14-1wjlWP weightMedium-13x9Y8 height36-13sPn7">
<div class="dismiss-1QjyJW" onclick="console.log(this);"></div>
${text}
</div>
</div>
</div>` + document.querySelector('.tooltips').innerHTML
const lele = document.querySelectorAll(".dismiss-1QjyJW")
lele.forEach(item => {
item.addEventListener("click", function() {
var parentElement = item.parentElement.parentElement.parentElement;
parentElement.remove();
});
})
},
cookie: {
set: function(name, value, days = 30) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
},
get: function(name) {
var nameEQ = name + "=";
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
while (cookie.charAt(0) == ' ') {
cookie = cookie.substring(1, cookie.length);
}
if (cookie.indexOf(nameEQ) == 0) {
return cookie.substring(nameEQ.length, cookie.length);
}
}
return null;
},
delete: function(name) {
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
}
}
// shorterhand variables
const rts = rotisserie
const rt = rotisserie
const chicken = rotisserie // lol
const loader_funcs = {
verifyMod: function(modDetails) {
const requiredFields = [
'name',
'description',
'version',
'creator',
'class_to_look_for',
'does_look_for_classes',
'custom_message'
];
let missingFields = [];
let booleanFields = ['does_look_for_classes', 'custom_message'];
let stringFields = ['name', 'description', 'version', 'creator', 'class_to_look_for'];
for (const field of requiredFields) {
if (!modDetails.hasOwnProperty(field)) {
missingFields.push(field);
} else {
const value = modDetails[field];
if (booleanFields.includes(field) && typeof value !== 'boolean') {
return { error: true, message: `Invalid type for ${field}. Expected boolean.` };
} else if (!booleanFields.includes(field) && typeof value !== 'string') {
return { error: true, message: `Invalid type for ${field}. Expected string.` };
}
}
}
if (missingFields.length > 0) {
return { error: true, message: `Missing fields: ${missingFields.join(', ')}` };
}
return { error: false };
},
startup: async function(mods) {
console.log(`%cRotisserie Mod Loader\n%cVersion: ${ml_vars.version}\n%cVersion Date: ${ml_vars.date}\nhttps://github.com/nilenta/rotisserie-modloader`, "font-size: 36px; font-weight: bold; color: lightgreen;", "font-size: 28px; color: lightblue;", "font-size: 24px; color: black;");
console.log("")
console.log("%cLoading client mods.", "font-size: 30px; font-weight: bold; color: lightblue;");
console.log("%cMods that are getting loaded will show below.", "font-size: 14px; color: lightblue;");
console.log(" ")
mods.forEach(mod => {
const verification = this.verifyMod(mod?.info)
if (verification.error) {
console.error(`%cAn error occurred with ${mod.info.name ? `the mod "${mod.info?.name}"` : `a mod!`}\nMessage: ${verification.message ? verification.message : 'No error message was provided.'}`, "font-size: 20px; font-weight: bold; color: red;");
} else {
if (mod?.startup) mod?.startup() // Blehhhh
if (!mod.info.custom_message) {
mod.started = true // maybe i shouldnt declare this before it logs it in console
console.log(`%c${mod.info.name}\n%cVersion: ${mod.info.version}\n%cDescription: ${mod.info.description}\n%cAuthor: ${mod.info.creator}\n%cHas startup script: ${mod.startup ? 'yes' : 'no'}\n%cChecks for classes: ${mod.info.does_look_for_classes ? 'yes' : 'no'}`, "font-size: 20px; font-weight: bold; color: lightblue;", "font-size: 16px; color: lightgreen;", "font-size: 14px; color: black;", "font-size: 14px; color: lightblue;", "font-size: 14px; color: lightblue;", "font-size: 14px; color: lightblue;");
} else {
if (mod?.startup_message) {
mod.startup_message()
mod.started = true
} else {
console.log(`%cError: An error occurred with the mod "${mod.info.name}".\nThere is no 'startup_message' function in the mod object.`, "font-size: 20px; font-weight: bold; color: red;");
}
}
}
})
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
const elements = node.querySelectorAll('*');
elements.forEach((element) => {
mods.forEach(async (pair) => {
if (element.classList && element.classList.contains(pair.info.class_to_look_for) && pair.info.does_look_for_classes && pair?.started) {
await pair.callback(element);
}
});
});
}
});
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
console.log(" ")
console.log("%cLoaded all client mods!", "font-size: 30px; font-weight: bold; color: lightblue;");
}
}
// maybe i should seperate mods into js files
// DONE!
// will remove client_mods array someday lol
let client_mods = [
...ext_mods,
/* example mod:
{
info: {
name: 'Example mod',
description: `Test mod`,
version: `1.0.0`,
creator: 'yourname',
class_to_look_for: ``,
does_look_for_classes: false,
custom_message: false
},
// startup is executed when the page is loaded
startup: function() {
},
// callback is for when a class gets added to the page
callback: (node) => {
},
// startup_message must be declared if custom_message is set to true, will run while the mod is loading mods.
startup_message: function() {
}
},
*/
];
await loader_funcs.startup(client_mods); // Yeah