2022-09-02 13:05:52 -04:00
import { REACT_GLOBAL } from "../utils/constants" ;
2022-09-08 16:25:21 -04:00
import { Modal , openModal } from "../utils/modal" ;
2022-09-02 13:05:52 -04:00
import definePlugin from '../utils/types' ;
2022-09-08 16:25:21 -04:00
import { filters , waitFor } from "../webpack" ;
2022-09-02 13:05:52 -04:00
2022-09-08 16:25:21 -04:00
let ImageModal : any ;
let renderMaskedLink : any ;
waitFor ( filters . byDisplayName ( "ImageModal" ) , m = > ImageModal = m . default ) ;
waitFor ( "renderMaskedLinkComponent" , m = > renderMaskedLink = m . renderMaskedLinkComponent ) ;
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(" ;
2022-09-02 13:05:52 -04:00
export default definePlugin ( {
name : "ViewIcons" ,
author : "Vendicated" ,
2022-09-02 17:02:08 -04:00
description : "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon. Crashes if you don't have Developer Mode enabled, will fix in the future." ,
2022-09-08 16:25:21 -04:00
openImage ( url : string ) {
openModal ( ( ) = > (
< ImageModal
shouldAnimate = { true }
original = { url }
src = { url }
renderLinkComponent = { renderMaskedLink }
/ >
) , { size : Modal.ModalSize.DYNAMIC } ) ;
} ,
2022-09-02 13:05:52 -04:00
patches : [
{
find : "UserProfileModalHeader" ,
replacement : {
match : /\{src:(.{1,2}),avatarDecoration/ ,
replace : ( _ , src ) = > ` {src: ${ src } ,onClick:()=> ${ OPEN_URL } ${ src } .replace(/ \\ ?.+ $ /, "")+"?size=2048"),avatarDecoration `
}
} , {
find : "default.popoutNoBannerPremium" ,
replacement : {
match : /style:.{1,2}\(\{\},(.{1,2}),/ ,
2022-09-02 17:02:08 -04:00
replace : ( m , bannerObj ) = > ` onClick: ${ bannerObj } .backgroundImage&&(()=> ${ OPEN_URL } ${ bannerObj } .backgroundImage.replace("url(", "").replace(/( \\ ?size=.+)? \\ )/, "?size=2048"))), ${ m } `
2022-09-02 13:05:52 -04:00
}
} , {
find : "GuildContextMenuWrapper" ,
replacement : [
{
match : /\w=(\w)\.id/ ,
replace : ( m , guild ) = > ` _guild= ${ guild } , ${ m } `
} ,
{
2022-09-08 16:44:54 -04:00
match : /,(.{1,2})\((.{1,2})\.MenuGroup,\{\},void 0,(.{1,2})\)(?=\)\}.{1,2}\.displayName)/ ,
replace : ( _ , factory , menu , copyIdElement ) = > ` , ${ factory } ( ${ menu } .MenuGroup,{},void 0,[ ` +
` _guild.icon&& ${ REACT_GLOBAL } .createElement( ${ menu } .MenuItem, ` +
2022-09-02 13:05:52 -04:00
` {key:"viewicons-copy-icon",id:"viewicons-copy-icon",action:()=> ${ OPEN_URL } _guild.getIconURL(undefined,true)+"size=2048"),label:"View Icon",icon:null}), ` +
2022-09-08 16:44:54 -04:00
` _guild.banner&& ${ REACT_GLOBAL } .createElement( ${ menu } .MenuItem, ` +
2022-09-02 13:05:52 -04:00
` {key:"viewicons-copy-banner",id:"viewicons-copy-banner",action:()=> ${ OPEN_URL } Vencord.Webpack.findByProps("getGuildBannerURL").getGuildBannerURL(_guild).replace(/ \\ ?size=.+/, "?size=2048")),label:"View Banner",icon:null}), ${ copyIdElement } ]) `
}
]
}
]
} ) ;