Plugin
AccountPanelServerProfile
Right click your account panel in the bottom left to view your profile in the current server
1
import { definePluginSettings } from "@api/Settings";2
import ErrorBoundary from "@components/ErrorBoundary";3
import { Devs } from "@utils/constants";4
import { getCurrentChannel } from "@utils/discord";5
import definePlugin, { OptionType } from "@utils/types";6
import { User } from "@vencord/discord-types";7
import { findComponentByCodeLazy } from "@webpack";8
import { ContextMenuApi, Menu } from "@webpack/common";9
10
interface UserProfileProps {11
popoutProps: Record<string, any>;12
currentUser: User;13
originalRenderPopout: () => React.ReactNode;14
}15
16
const UserProfile = findComponentByCodeLazy(".isNonUserBot()?", ",onClickContainer:");17
18
let openAlternatePopout = false;19
let accountPanelRef: React.RefObject<HTMLDivElement | null> = { current: null };20
21
const AccountPanelContextMenu = ErrorBoundary.wrap(() => {22
const { prioritizeServerProfile } = settings.use(["prioritizeServerProfile"]);23
24
return (25
<Menu.Menu26
navId="vc-ap-server-profile"27
onClose={ContextMenuApi.closeContextMenu}28
>29
<Menu.MenuItem30
id="vc-ap-view-alternate-popout"31
label={prioritizeServerProfile ? "View Account Profile" : "View Server Profile"}32
disabled={getCurrentChannel()?.getGuildId() == null}33
action={e => {34
openAlternatePopout = true;35
accountPanelRef.current?.click();36
}}37
/>38
<Menu.MenuCheckboxItem39
id="vc-ap-prioritize-server-profile"40
label="Prioritize Server Profile"41
checked={prioritizeServerProfile}42
action={() => settings.store.prioritizeServerProfile = !prioritizeServerProfile}43
/>44
</Menu.Menu>45
);46
}, { noop: true });47
48
const settings = definePluginSettings({49
prioritizeServerProfile: {50
type: OptionType.BOOLEAN,51
description: "Prioritize Server Profile when left clicking your account panel",52
default: false53
}54
});55
56
export default definePlugin({57
name: "AccountPanelServerProfile",58
description: "Right click your account panel in the bottom left to view your profile in the current server",59
tags: ["Appearance", "Servers"],60
authors: [Devs.Nuckyz, Devs.relitrix],61
settings,62
63
patches: [64
{65
find: "handleOpenSettingsContextMenu=",66
group: true,67
replacement: [68
{69
match: /(\.AVATAR,children:.+?renderPopout:\((\i),\i\)=>)\{(.+?)\}(?=,position)(?<=currentUser:(\i).+?)/,70
replace: (_, rest, popoutProps, originalPopout, currentUser) => `${rest}$self.UserProfile({popoutProps:${popoutProps},currentUser:${currentUser},originalRenderPopout:()=>{${originalPopout}}})`71
},72
{73
match: /\.AVATAR,children:.+?onRequestClose:\(\)=>\{/,74
replace: "$&$self.onPopoutClose();"75
},76
{77
match: /ref:(\i),style:\i(?=.{0,250}#{intl::USER_PROFILE_ACCOUNT_POPOUT_BUTTON_A11Y_LABEL})/,78
replace: "$&,onContextMenu:($self.grabRef($1),$self.openAccountPanelContextMenu)"79
}80
]81
}82
],83
84
get accountPanelRef() {85
return accountPanelRef;86
},87
88
grabRef(ref: React.RefObject<HTMLDivElement>) {89
accountPanelRef = ref;90
return ref;91
},92
93
openAccountPanelContextMenu(event: React.UIEvent) {94
ContextMenuApi.openContextMenu(event, AccountPanelContextMenu);95
},96
97
onPopoutClose() {98
openAlternatePopout = false;99
},100
101
UserProfile: ErrorBoundary.wrap(({ popoutProps, currentUser, originalRenderPopout }: UserProfileProps) => {102
if (103
(settings.store.prioritizeServerProfile && openAlternatePopout) ||104
(!settings.store.prioritizeServerProfile && !openAlternatePopout)105
) {106
return originalRenderPopout();107
}108
109
const currentChannel = getCurrentChannel();110
if (currentChannel?.getGuildId() == null || !UserProfile.$$vencordGetWrappedComponent()) {111
return originalRenderPopout();112
}113
114
return (115
<UserProfile116
{...popoutProps}117
user={currentUser}118
currentUser={currentUser}119
guildId={currentChannel.getGuildId()}120
channelId={currentChannel.id}121
/>122
);123
}, { noop: true })124
});125