Vencord/src/plugins/viewIcons.tsx

58 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-09-30 20:27:28 -04:00
import { Devs } from "../utils/constants";
2022-09-27 12:03:21 -04:00
import IpcEvents from "../utils/IpcEvents";
2022-09-02 13:05:52 -04:00
import definePlugin from '../utils/types';
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(";
2022-09-02 13:05:52 -04:00
export default definePlugin({
name: "ViewIcons",
2022-09-30 20:27:28 -04:00
authors: [Devs.Ven],
2022-09-27 12:03:21 -04:00
description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon.",
openImage(url: string) {
2022-09-27 12:03:21 -04:00
VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, url);
// husk
/* openModal(() => (
<ImageModal
shouldAnimate={true}
original={url}
src={url}
renderLinkComponent={renderMaskedLink}
/>
2022-09-27 12:03:21 -04:00
), { size: Modal.ModalSize.DYNAMIC }); */
},
2022-09-02 13:05:52 -04:00
patches: [
{
2022-09-27 12:03:21 -04:00
find: "onAddFriend:",
2022-09-02 13:05:52 -04:00
replacement: {
match: /\{src:(.{1,2}),avatarDecoration/,
replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}.replace(/\\?.+$/, "")+"?size=2048"),avatarDecoration`
}
}, {
2022-09-27 12:03:21 -04:00
find: "().popoutNoBannerPremium",
2022-09-02 13:05:52 -04:00
replacement: {
2022-09-27 12:03:21 -04:00
match: /style:.{0,10}\{\},(.{1,2})\)/,
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
}
}, {
2022-09-27 12:03:21 -04:00
find: '"GuildContextMenu:',
2022-09-02 13:05:52 -04:00
replacement: [
{
match: /\w=(\w)\.id/,
replace: (m, guild) => `_guild=${guild},${m}`
},
{
2022-09-27 12:03:21 -04:00
match: /(?<=createElement\((.{1,5}),\{id:"leave-guild".{0,100}\,)(.{1,2}\.createElement)\((.{1,5}),null,(.{1,2})\)(?=\)\}function)/,
replace: (_, menu, createElement, menuGroup, copyIdElement) =>
`${createElement}(${menuGroup},null,[` +
`_guild.icon&&${createElement}(${menu},` +
2022-09-15 12:03:48 -04:00
`{id:"viewicons-copy-icon",label:"View Icon",action:()=>${OPEN_URL}_guild.getIconURL(void 0,true)+"size=2048")}),` +
2022-09-27 12:03:21 -04:00
`_guild.banner&&${createElement}(${menu},` +
`{id:"viewicons-copy-banner",label:"View Banner",action:()=>${OPEN_URL}Vencord.Webpack.findByProps("getGuildBannerURL").getGuildBannerURL(_guild).replace(/\\?size=.+/, "?size=2048"))})`
+ `,${copyIdElement}])`
2022-09-02 13:05:52 -04:00
}
]
}
]
});