Add function to get classes and fix emote autocomplete injection

This commit is contained in:
Samuel Elliott 2018-07-07 01:17:17 +01:00
parent c384920275
commit b6f38a73dc
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
5 changed files with 33 additions and 10 deletions

View File

@ -214,9 +214,9 @@ export default new class EmoteModule {
}
async patchChannelTextArea() {
const selector = '.' + WebpackModules.getModuleByProps(['channelTextArea', 'emojiButton']).channelTextArea;
const selector = '.' + WebpackModules.getClassName('channelTextArea', 'emojiButton');
const ChannelTextArea = await ReactComponents.getComponent('ChannelTextArea', {selector});
this.unpatchChannelTextArea = MonkeyPatch('BD:ReactComponents', ChannelTextArea.component.prototype).after('render', (component, args, retVal) => {
if (!(retVal.props.children instanceof Array)) retVal.props.children = [retVal.props.children];

View File

@ -457,6 +457,12 @@ export default class PluginApi {
waitForWebpackModuleByPrototypeFields(...props) {
return WebpackModules.waitForModuleByPrototypes(props);
}
getWebpackClassName(...classes) {
return WebpackModules.getClassName(...classes);
}
waitForWebpackClassName(...classes) {
return WebpackModules.waitForClassName(...classes);
}
get WebpackModules() {
return new Proxy({
getModule: this.getWebpackModule.bind(this),
@ -475,6 +481,8 @@ export default class PluginApi {
waitForModulesByRegex: this.waitForWebpackModulesByRegex.bind(this),
waitForModuleByProperties: this.waitForWebpackModuleByProperties.bind(this),
waitForModuleByPrototypeFields: this.waitForWebpackModuleByPrototypeFields.bind(this),
getClassName: this.getWebpackClassName.bind(this),
waitForClassName: this.waitForWebpackClassName.bind(this),
get KnownModules() { return WebpackModules.KnownModules },
get require() { return WebpackModules.require }
}, {

View File

@ -342,7 +342,7 @@ export class ReactAutoPatcher {
}
static async patchChannelMember() {
const selector = '.' + WebpackModules.getModuleByProps(['member', 'memberInner', 'activity']).member;
const selector = '.' + WebpackModules.getClassName('member', 'memberInner', 'activity');
this.ChannelMember = await ReactComponents.getComponent('ChannelMember', { selector }, m => m.prototype.renderActivity);
this.unpatchChannelMemberRender = MonkeyPatch('BD:ReactComponents', this.ChannelMember.component.prototype).after('render', (component, args, retVal) => {
@ -393,8 +393,8 @@ export class ReactAutoPatcher {
}
static async patchChannelList() {
const selector = '.' + WebpackModules.getModuleByProps(['containerDefault', 'actionIcon']).containerDefault;
this.GuildChannel = await ReactComponents.getComponent('GuildChannel', { selector: '.containerDefault-1ZnADq' });
const selector = '.' + WebpackModules.getClassName('containerDefault', 'actionIcon');
this.GuildChannel = await ReactComponents.getComponent('GuildChannel', { selector });
this.unpatchGuildChannel = MonkeyPatch('BD:ReactComponents', this.GuildChannel.component.prototype).after('render', (component, args, retVal) => {
const { channel } = component.props;
@ -412,7 +412,7 @@ export class ReactAutoPatcher {
}
static async patchUserProfileModal() {
const selector = '.' + WebpackModules.getModuleByProps(['root', 'topSectionNormal']).root;
const selector = '.' + WebpackModules.getClassName('root', 'topSectionNormal');
this.UserProfileModal = await ReactComponents.getComponent('UserProfileModal', { selector }, Filters.byPrototypeFields(['renderHeader', 'renderBadges']));
this.unpatchUserProfileModal = MonkeyPatch('BD:ReactComponents', this.UserProfileModal.component.prototype).after('render', (component, args, retVal) => {
@ -429,7 +429,7 @@ export class ReactAutoPatcher {
}
static async patchUserPopout() {
const selector = '.' + WebpackModules.getModuleByProps(['userPopout', 'headerNormal']).userPopout;
const selector = '.' + WebpackModules.getClassName('userPopout', 'headerNormal');
this.UserPopout = await ReactComponents.getComponent('UserPopout', { selector });
this.unpatchUserPopout = MonkeyPatch('BD:ReactComponents', this.UserPopout.component.prototype).after('render', (component, args, retVal) => {

View File

@ -384,6 +384,21 @@ class WebpackModules {
return this.waitForModule(Filters.byPrototypeFields(props));
}
/**
* Searches for a class module and returns a class from it.
* @param {String} base The first part of the class to find
* @param {String} ...additional_classes Additional classes to look for to filter duplicate class modules
* @return {String}
*/
static getClassName(base, ...additional_classes) {
const class_module = this.getModuleByProps([base, ...additional_classes]);
if (class_module && class_module[base]) return class_module[base].split(' ')[0];
}
static async waitForClassName(base, ...additional_classes) {
const class_module = await this.waitForModuleByProps([base, ...additional_classes]);
if (class_module && class_module[base]) return class_module[base].split(' ')[0];
}
/**
* Returns all loaded modules.
* @return {Array}

View File

@ -81,7 +81,7 @@ export default class extends Module {
// Rerender all channel members
if (this.PatchedNameTag) {
const selector = '.' + WebpackModules.getModuleByProps(['member', 'memberInner', 'activity']).member;
const selector = '.' + WebpackModules.getClassName('member', 'memberInner', 'activity');
for (const channelMember of document.querySelectorAll(selector)) {
Reflection(channelMember).forceUpdate();
@ -96,7 +96,7 @@ export default class extends Module {
if (this.PatchedNameTag) return this.PatchedNameTag;
const ProfileBadges = this;
const selector = '.' + WebpackModules.getModuleByProps(['nameTag', 'username', 'discriminator', 'ownerIcon']).nameTag;
const selector = '.' + WebpackModules.getClassName('nameTag', 'username', 'discriminator', 'ownerIcon');
const NameTag = await ReactComponents.getComponent('NameTag', { selector });
this.PatchedNameTag = class extends NameTag.component {
@ -123,7 +123,7 @@ export default class extends Module {
// Rerender all channel members
if (this.unpatchChannelMemberRender) {
const selector = '.' + WebpackModules.getModuleByProps(['member', 'memberInner', 'activity']).member;
const selector = '.' + WebpackModules.getClassName('member', 'memberInner', 'activity');
for (const channelMember of document.querySelectorAll(selector)) {
Reflection(channelMember).forceUpdate();