ViewIcons: fix conflicts with profile/group modal (#3720)

This commit is contained in:
sadan 2026-07-26 13:11:18 -04:00 • committed by GitHub
parent a040c8dbe6
commit 42b3ae8026
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,6 +24,7 @@ import { openImageModal } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import type { Channel, Guild, User } from "@vencord/discord-types";
import { GuildMemberStore, IconUtils, Menu } from "@webpack/common";
import type { MouseEvent } from "react";
interface UserContextProps {
@ -68,10 +69,18 @@ const settings = definePluginSettings({
}
});
const openAvatar = (url: string) => openImage(url, 512, 512);
const openBanner = (url: string) => openImage(url, 1024);
const openAvatar = (url: string, event?: MouseEvent) => openImage({ url, width: 512, height: 512, event });
const openBanner = (url: string, event?: MouseEvent) => openImage({ url, width: 1024, event });
function openImage(url: string, width: number, height?: number) {
interface OpenImageProps {
url: string;
width: number;
height?: number;
event?: MouseEvent;
}
function openImage({ url, width, height, event }: OpenImageProps) {
event?.stopPropagation();
const u = new URL(url, window.location.href);
const format = url.startsWith("/")
@ -224,7 +233,7 @@ export default definePlugin({
find: 'backgroundColor:"COMPLETE"',
replacement: {
match: /(overflow:"visible",.{0,125}?!1\),)style:{(?=.+?backgroundImage:null!=(\i)\?`url\(\$\{\2\}\))/,
replace: (_, rest, bannerSrc) => `${rest}onClick:()=>${bannerSrc}!=null&&$self.openBanner(${bannerSrc}),style:{cursor:${bannerSrc}!=null?"pointer":void 0,`
replace: (_, rest, bannerSrc) => `${rest}onClick:vcEvent=>${bannerSrc}!=null&&$self.openBanner(${bannerSrc}, vcEvent),style:{cursor:${bannerSrc}!=null?"pointer":void 0,`
}
},
// Group DMs top small & large icon
@ -233,7 +242,7 @@ export default definePlugin({
replacement: {
match: /null==\i\.icon\?.+?src:(\(0,\i\.\i\).+?\))(?=[,}])/,
// We have to check that icon is not an unread GDM in the server bar
replace: (m, iconUrl) => `${m},onClick:()=>arguments[0]?.size!=="SIZE_48"&&$self.openAvatar(${iconUrl})`
replace: (m, iconUrl) => `${m},onClick:vcEvent=>arguments[0]?.size!=="SIZE_48"&&$self.openAvatar(${iconUrl},vcEvent)`
}
},
// User DMs top small icon
@ -241,7 +250,7 @@ export default definePlugin({
find: ".channel.getRecipientId(),",
replacement: {
match: /(?=,src:(\i.getAvatarURL\(.+?[)]))/,
replace: (_, avatarUrl) => `,onClick:()=>$self.openAvatar(${avatarUrl})`
replace: (_, avatarUrl) => `,onClick:vcEvent=>$self.openAvatar(${avatarUrl},vcEvent)`
}
},
// User Dms top large icon
@ -249,7 +258,7 @@ export default definePlugin({
find: ".EMPTY_GROUP_DM)",
replacement: {
match: /(?<=SIZE_80,)(?=src:(.+?\))[,}])/,
replace: (_, avatarUrl) => `onClick:()=>$self.openAvatar(${avatarUrl}),`
replace: (_, avatarUrl) => `onClick:vcEvent=>$self.openAvatar(${avatarUrl},vcEvent),`
}
}
]