From 71849cac9a6313432cd9976cb5de4ce060e74b0e Mon Sep 17 00:00:00 2001 From: Kode Date: Thu, 13 Apr 2023 03:25:38 +0100 Subject: Fix ViewIcons on webhooks and default avatars! (#880) Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Co-authored-by: Vendicated --- src/plugins/viewIcons.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/viewIcons.tsx b/src/plugins/viewIcons.tsx index cff4fe6..85105c5 100644 --- a/src/plugins/viewIcons.tsx +++ b/src/plugins/viewIcons.tsx @@ -63,9 +63,10 @@ const settings = definePluginSettings({ }); function openImage(url: string) { - const u = new URL(url); + const format = url.startsWith("/") ? "png" : settings.store.format; + const u = new URL(url, window.location.href); u.searchParams.set("size", "512"); - u.pathname = u.pathname.replace(/\.(png|jpe?g|webp)$/, `.${settings.store.format}`); + u.pathname = u.pathname.replace(/\.(png|jpe?g|webp)$/, `.${format}`); url = u.toString(); openModal(modalProps => ( @@ -148,8 +149,8 @@ const GuildContext: NavContextMenuPatchCallback = (children, { guild: { id, icon export default definePlugin({ name: "ViewIcons", - authors: [Devs.Ven], - description: "Makes Avatars/Banners in user profiles clickable, and adds View Icon/Banner entries in the user and server context menu", + authors: [Devs.Ven, Devs.TheKodeToad, Devs.Nuckyz], + description: "Makes avatars and banners in user profiles clickable, and adds View Icon/Banner entries in the user and server context menu", settings, @@ -171,15 +172,21 @@ export default definePlugin({ replacement: { // global because Discord has two components that are 99% identical with one small change ._. match: /\{src:(\i),avatarDecoration/g, - replace: (_, src) => `{src:${src},onClick:()=>$self.openImage(${src}),avatarDecoration` + replace: "{src:$1,onClick:()=>$self.openImage($1),avatarDecoration" } }, { find: ".popoutNoBannerPremium", replacement: { match: /style:.{0,10}\{\},(\i)\)/, - replace: (m, style) => - `onClick:${style}.backgroundImage&&(${style}.cursor="pointer",` + - `()=>$self.openImage(${style}.backgroundImage.replace("url(", ""))),${m}` + replace: + "onClick:$1.backgroundImage&&($1.cursor=\"pointer\"," + + "()=>$self.openImage($1.backgroundImage.replace(\"url(\", \"\"))),$&" + } + }, { + find: "().avatarWrapperNonUserBot", + replacement: { + match: /(avatarPositionPanel.+?)onClick:(\i\|\|\i)\?void 0(?<=,(\i)=\i\.avatarSrc.+?)/, + replace: "$1style:($2)?{cursor:\"pointer\"}:{},onClick:$2?()=>{$self.openImage($3)}" } } ] -- cgit