Move filters to common
This commit is contained in:
parent
ca7a7c1f91
commit
244b7e5bd1
|
@ -11,14 +11,14 @@
|
|||
import { EmoteModule } from 'builtin';
|
||||
import { SettingsSet, SettingsCategory, Setting, SettingsScheme } from 'structs';
|
||||
import { BdMenu, Modals, DOM, Reflection } from 'ui';
|
||||
import { Utils, ClientLogger as Logger, ClientIPC, AsyncEventEmitter } from 'common';
|
||||
import { Utils, Filters, ClientLogger as Logger, ClientIPC, AsyncEventEmitter } from 'common';
|
||||
import Settings from './settings';
|
||||
import ExtModuleManager from './extmodulemanager';
|
||||
import PluginManager from './pluginmanager';
|
||||
import ThemeManager from './thememanager';
|
||||
import Events from './events';
|
||||
import EventsWrapper from './eventswrapper';
|
||||
import { WebpackModules, Filters } from './webpackmodules';
|
||||
import { WebpackModules } from './webpackmodules';
|
||||
import DiscordApi from './discordapi';
|
||||
import { ReactComponents } from './reactcomponents';
|
||||
import { Patcher, MonkeyPatch } from './patcher';
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
import { EmoteModule } from 'builtin';
|
||||
import { Reflection } from 'ui';
|
||||
import { ClientLogger as Logger } from 'common';
|
||||
import { Filters, ClientLogger as Logger } from 'common';
|
||||
import { MonkeyPatch, Patcher } from './patcher';
|
||||
import { WebpackModules, Filters } from './webpackmodules';
|
||||
import { WebpackModules } from './webpackmodules';
|
||||
import DiscordApi from './discordapi';
|
||||
|
||||
class Helpers {
|
||||
|
|
|
@ -8,44 +8,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
export class Filters {
|
||||
static byProperties(props, selector = m => m) {
|
||||
return module => {
|
||||
const component = selector(module);
|
||||
if (!component) return false;
|
||||
return props.every(property => component[property] !== undefined);
|
||||
};
|
||||
}
|
||||
|
||||
static byPrototypeFields(fields, selector = m => m) {
|
||||
return module => {
|
||||
const component = selector(module);
|
||||
if (!component) return false;
|
||||
if (!component.prototype) return false;
|
||||
return fields.every(field => component.prototype[field] !== undefined);
|
||||
};
|
||||
}
|
||||
|
||||
static byCode(search, selector = m => m) {
|
||||
return module => {
|
||||
const method = selector(module);
|
||||
if (!method) return false;
|
||||
return method.toString().search(search) !== -1;
|
||||
};
|
||||
}
|
||||
|
||||
static byDisplayName(name) {
|
||||
return module => {
|
||||
return module && module.displayName === name;
|
||||
};
|
||||
}
|
||||
|
||||
static combine(...filters) {
|
||||
return module => {
|
||||
return filters.every(filter => filter(module));
|
||||
};
|
||||
}
|
||||
}
|
||||
import { Filters } from 'common';
|
||||
|
||||
const KnownModules = {
|
||||
React: Filters.byProperties(['createElement', 'cloneElement']),
|
||||
|
@ -321,7 +284,6 @@ export class WebpackModules {
|
|||
return Object.keys(KnownModules);
|
||||
}
|
||||
|
||||
static get Filters() { return Filters }
|
||||
static get KnownModules() { return KnownModules }
|
||||
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Filters } from 'modules';
|
||||
import { ClientLogger as Logger } from 'common';
|
||||
import { Filters, ClientLogger as Logger } from 'common';
|
||||
|
||||
class Reflection {
|
||||
static reactInternalInstance(node) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export { default as ClientIPC } from './bdipc';
|
||||
export * from './utils';
|
||||
export { ClientLogger } from './logger';
|
||||
export { default as Filters } from './filters';
|
||||
export { default as Logger, ClientLogger } from './logger';
|
||||
export { default as ClientIPC } from './bdipc';
|
||||
export { default as AsyncEventEmitter } from './async-eventemitter';
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* BetterDiscord Filters Module
|
||||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
||||
* All rights reserved.
|
||||
* https://betterdiscord.net
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
export default class Filters {
|
||||
static byProperties(props, selector = m => m) {
|
||||
return module => {
|
||||
const component = selector(module);
|
||||
if (!component) return false;
|
||||
return props.every(property => component[property] !== undefined);
|
||||
};
|
||||
}
|
||||
|
||||
static byPrototypeFields(fields, selector = m => m) {
|
||||
return module => {
|
||||
const component = selector(module);
|
||||
if (!component) return false;
|
||||
if (!component.prototype) return false;
|
||||
return fields.every(field => component.prototype[field] !== undefined);
|
||||
};
|
||||
}
|
||||
|
||||
static byCode(search, selector = m => m) {
|
||||
return module => {
|
||||
const method = selector(module);
|
||||
if (!method) return false;
|
||||
return method.toString().search(search) !== -1;
|
||||
};
|
||||
}
|
||||
|
||||
static byDisplayName(name) {
|
||||
return module => {
|
||||
return module && module.displayName === name;
|
||||
};
|
||||
}
|
||||
|
||||
static combine(...filters) {
|
||||
return module => {
|
||||
return filters.every(filter => filter(module));
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue