From 2499f8c0ab965ccf611ef648f8558f09c35c0882 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 29 Apr 2018 17:41:12 +0100 Subject: [PATCH] Get class names from internal modules --- client/src/modules/reactcomponents.js | 24 ++++++++++++++++-------- client/src/ui/profilebadges.js | 7 +++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index 53c8f207..38d33744 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -336,7 +336,9 @@ export class ReactAutoPatcher { } static async patchChannelMember() { - this.ChannelMember = await ReactComponents.getComponent('ChannelMember', { selector: '.member-3W1lQa' }); + const selector = '.' + WebpackModules.getModuleByProps(['member', 'memberInner', 'activity']).member; + + this.ChannelMember = await ReactComponents.getComponent('ChannelMember', { selector }); this.unpatchChannelMemberRender = MonkeyPatch('BD:ReactComponents', this.ChannelMember.component.prototype).after('render', (component, args, retVal) => { if (!retVal.props || !retVal.props.children) return; const user = Helpers.findProp(component, 'user'); @@ -344,7 +346,7 @@ export class ReactAutoPatcher { retVal.props['data-user-id'] = user.id; }); - for (const e of document.querySelectorAll('.member-sFrNV0')) { + for (const e of document.querySelectorAll(selector)) { Reflection(e).forceUpdate(); } } @@ -378,7 +380,9 @@ export class ReactAutoPatcher { } static async patchChannelList() { - this.GuildChannel = await ReactComponents.getComponent('GuildChannel', { selector: '.containerDefault-7RImuF' }); + const selector = '.' + WebpackModules.getModuleByProps(['containerDefault', 'actionIcon']).containerDefault; + + this.GuildChannel = await ReactComponents.getComponent('GuildChannel', { selector: '.containerDefault-1ZnADq' }); this.unpatchGuildChannel = MonkeyPatch('BD:ReactComponents', this.GuildChannel.component.prototype).after('render', (component, args, retVal) => { const { channel } = component.props; if (!channel) return; @@ -386,13 +390,15 @@ export class ReactAutoPatcher { retVal.props['data-channel-name'] = channel.name; }); - for (const e of document.querySelectorAll('.containerDefault-7RImuF')) { + for (const e of document.querySelectorAll(selector)) { Reflection(e).forceUpdate(); } } static async patchUserProfileModal() { - this.UserProfileModal = await ReactComponents.getComponent('UserProfileModal', { selector: '.root-SR8cQa' }, Filters.byPrototypeFields(['renderHeader', 'renderBadges'])); + const selector = '.' + WebpackModules.getModuleByProps(['root', 'topSectionNormal']).root; + + 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) => { const { user } = component.props; if (!user) return; @@ -401,13 +407,15 @@ export class ReactAutoPatcher { if (user.id === DiscordApi.currentUser.id) retVal.props.className += ' bd-isCurrentUser'; }); - for (const e of document.querySelectorAll('.root-SR8cQa')) { + for (const e of document.querySelectorAll(selector)) { Reflection(e).forceUpdate(); } } static async patchUserPopout() { - this.UserProfileModal = await ReactComponents.getComponent('UserPopout', { selector: '.userPopout-3XzG_A' }); + const selector = '.' + WebpackModules.getModuleByProps(['userPopout', 'headerNormal']).userPopout; + + this.UserProfileModal = await ReactComponents.getComponent('UserPopout', { selector }); this.unpatchUserProfileModal = MonkeyPatch('BD:ReactComponents', this.UserProfileModal.component.prototype).after('render', (component, args, retVal) => { const { user, guild, guildMember } = component.props; if (!user) return; @@ -420,7 +428,7 @@ export class ReactAutoPatcher { if (guildMember && guildMember.roles.length) retVal.props.className += ' bd-hasRoles'; }); - for (const e of document.querySelectorAll('.userPopout-3XzG_A')) { + for (const e of document.querySelectorAll(selector)) { Reflection(e).forceUpdate(); } } diff --git a/client/src/ui/profilebadges.js b/client/src/ui/profilebadges.js index 7ef448a3..d193b417 100644 --- a/client/src/ui/profilebadges.js +++ b/client/src/ui/profilebadges.js @@ -105,7 +105,8 @@ export default class extends Module { if (this.PatchedNameTag) return this.PatchedNameTag; const ProfileBadges = this; - const NameTag = await ReactComponents.getComponent('NameTag', {selector: '.nameTag-m8r81H'}); + const selector = '.' + WebpackModules.getModuleByProps(['nameTag', 'username', 'discriminator', 'ownerIcon']).nameTag; + const NameTag = await ReactComponents.getComponent('NameTag', { selector }); this.PatchedNameTag = class extends NameTag.component { render() { @@ -143,7 +144,9 @@ export default class extends Module { // Rerender all channel members if (this.unpatchChannelMemberRender) { - for (const channelMember of document.querySelectorAll('.member-3W1lQa')) { + const selector = '.' + WebpackModules.getModuleByProps(['member', 'memberInner', 'activity']).member; + + for (const channelMember of document.querySelectorAll(selector)) { Reflection(channelMember).forceUpdate(); } }