forked from Demon/demoncord
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.
61 lines
1.6 KiB
61 lines
1.6 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[],
|
|
};
|
|
|
|
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)
|
|
);
|
|
},
|
|
};
|
|
|
|
export default webpack;
|