diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js index 1dcfb61f..5b25797b 100644 --- a/client/src/modules/pluginapi.js +++ b/client/src/modules/pluginapi.js @@ -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'; diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index 412767c4..69c3bad8 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -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 { diff --git a/client/src/modules/webpackmodules.js b/client/src/modules/webpackmodules.js index 6fa3cc54..fe0d424c 100644 --- a/client/src/modules/webpackmodules.js +++ b/client/src/modules/webpackmodules.js @@ -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 } } diff --git a/client/src/ui/reflection.js b/client/src/ui/reflection.js index b3c1433b..b4898b0c 100644 --- a/client/src/ui/reflection.js +++ b/client/src/ui/reflection.js @@ -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) { diff --git a/common/modules/common.js b/common/modules/common.js index 41865a34..3ae581aa 100644 --- a/common/modules/common.js +++ b/common/modules/common.js @@ -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'; diff --git a/common/modules/filters.js b/common/modules/filters.js new file mode 100644 index 00000000..9295a8e5 --- /dev/null +++ b/common/modules/filters.js @@ -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)); + }; + } +}