-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
47 lines (42 loc) · 1.43 KB
/
api.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
_fetchModules = function () {
this.modules = [];
window.webpackChunkdiscord_app.push([[''], {}, e => {for (let c in e.c) this.modules.push(e.c[c])}]);
}
getAllModules = function () {
if (void 0 === this.modules) {
this._fetchModules();
}
return this.modules;
}
findModuleByFunctionName = function (name) {
const modules = this.getAllModules();
let e;
for (const m of modules) {
e = m?.exports;
if (!e) continue;
if (typeof e.default?.[name] === 'function') return e.default;
if (typeof e[name] === 'function') return e;
}
};
findFunctionByName = function (name) {
const functionModule = this.findModuleByFunctionName(name);
return functionModule?.[name]?.bind(functionModule);
};
findFunctionsMatchingPattern = function (pattern) {
const matches = {}
const modules = this.getAllModules();
modules.forEach(m => {
let e = m?.exports;
let d = e?.default;
e && Object.keys(e).forEach(i => RegExp(pattern, "i").test(i) && typeof e[i] === 'function' && (matches[i] = (matches[i] || []).concat(e[i].bind(e))));
d && Object.keys(d).forEach(i => RegExp(pattern, "i").test(i) && typeof d[i] === 'function' && (matches[i] = (matches[i] || []).concat(d[i].bind(d))));
});
return matches;
}
module.exports = {
_fetchModules,
getAllModules,
findModuleByFunctionName,
findFunctionByName,
findFunctionsMatchingPattern
};