You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
// @flow
|
|
type ModuleType = Object /* { [symbol]: any } */;
|
|
type FilterFunc = (module: ModuleType) => boolean;
|
|
|
|
function getModules(): any {
|
|
let modules: { c: mixed[] } = {};
|
|
|
|
window.webpackChunkdiscord_app.push([
|
|
[Math.random().toString(36)],
|
|
{},
|
|
(e) => {
|
|
modules = e;
|
|
}
|
|
]);
|
|
|
|
return modules.c;
|
|
}
|
|
|
|
function filter(filter: FilterFunc, moduleList: any): Array<Object> {
|
|
let modules: Array<mixed[]> = [];
|
|
for (const mod in moduleList) {
|
|
const module = moduleList[mod].exports;
|
|
if (module) {
|
|
if (module.default && module.__esModule && filter(module.default)) {
|
|
modules.push(module.default);
|
|
} else if (filter(module)) {
|
|
modules.push(module);
|
|
}
|
|
}
|
|
}
|
|
return modules;
|
|
}
|
|
|
|
type WebpackModules = {
|
|
modules: () => any,
|
|
filter: (filter: FilterFunc, moduleList: any) => Object[],
|
|
find: (filter: FilterFunc) => Object,
|
|
findAll: (filter: FilterFunc) => Object[],
|
|
findByProps: (...props: string[]) => Object,
|
|
findByPropsAll: (...props: string[]) => Object[],
|
|
findByDisplayName: (prop: string) => Object[],
|
|
reloadModules: () => void
|
|
};
|
|
|
|
let webpack: WebpackModules = {
|
|
modules: getModules(),
|
|
filter: filter,
|
|
find: (filter: FilterFunc) => webpack.filter(filter, webpack.modules)[0],
|
|
findAll: (filter: FilterFunc) => webpack.filter(filter, webpack.modules),
|
|
findByProps: (...props: Array<string>) => {
|
|
return webpack.find((module) => {
|
|
return props.every((prop) => module[prop] !== undefined);
|
|
});
|
|
},
|
|
findByPropsAll: (...props: Array<string>) => {
|
|
return webpack.findAll((module) =>
|
|
props.every((prop) => module[prop] !== undefined)
|
|
);
|
|
},
|
|
findByDisplayName: (prop: string) => {
|
|
return webpack.find((m) => m?.default?.displayName === prop);
|
|
},
|
|
reloadModules: () => {
|
|
//NOTE: i have no idea why this could even feasibly need to be used, but i'm adding it anyways
|
|
webpack.modules = getModules();
|
|
}
|
|
};
|
|
|
|
export default webpack;
|