Get class names from internal modules

This commit is contained in:
Samuel Elliott 2018-04-29 17:41:12 +01:00
parent 3f2eb1047e
commit 2499f8c0ab
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 21 additions and 10 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}