2022-10-01 00:27:28 +00:00
|
|
|
import { Devs } from "../utils/constants";
|
2022-10-05 22:42:58 +00:00
|
|
|
import definePlugin from "../utils/types";
|
2022-10-14 20:38:49 +00:00
|
|
|
import { lazyWebpack, makeLazy } from "../utils/misc";
|
2022-10-17 19:18:25 +00:00
|
|
|
import { ModalRoot, ModalSize, openModal } from "../utils/modal";
|
2022-10-14 20:38:49 +00:00
|
|
|
import { find } from "../webpack";
|
|
|
|
import { React } from "../webpack/common";
|
|
|
|
|
|
|
|
const ImageModal = lazyWebpack(m => m.prototype?.render?.toString().includes("OPEN_ORIGINAL_IMAGE"));
|
|
|
|
const getMaskedLink = makeLazy(() => find(m => m.type?.toString().includes("MASKED_LINK)")));
|
2022-09-08 20:25:21 +00:00
|
|
|
|
|
|
|
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(";
|
2022-09-02 17:05:52 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "ViewIcons",
|
2022-10-01 00:27:28 +00:00
|
|
|
authors: [Devs.Ven],
|
2022-09-27 16:03:21 +00:00
|
|
|
description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon.",
|
2022-09-08 20:25:21 +00:00
|
|
|
|
|
|
|
openImage(url: string) {
|
2022-10-17 19:18:25 +00:00
|
|
|
openModal(modalProps => (
|
|
|
|
<ModalRoot size={ModalSize.DYNAMIC} {...modalProps}>
|
|
|
|
<ImageModal
|
|
|
|
shouldAnimate={true}
|
|
|
|
original={url}
|
|
|
|
src={url}
|
|
|
|
renderLinkComponent={props => React.createElement(getMaskedLink(), props)}
|
|
|
|
/>
|
|
|
|
</ModalRoot>
|
|
|
|
));
|
2022-09-08 20:25:21 +00:00
|
|
|
},
|
|
|
|
|
2022-09-02 17:05:52 +00:00
|
|
|
patches: [
|
|
|
|
{
|
2022-09-27 16:03:21 +00:00
|
|
|
find: "onAddFriend:",
|
2022-09-02 17:05:52 +00:00
|
|
|
replacement: {
|
2022-10-19 17:45:22 +00:00
|
|
|
// global because Discord has two components that are 99% identical with one small change ._.
|
|
|
|
match: /\{src:(.{1,2}),avatarDecoration/g,
|
2022-09-02 17:05:52 +00:00
|
|
|
replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}.replace(/\\?.+$/, "")+"?size=2048"),avatarDecoration`
|
|
|
|
}
|
|
|
|
}, {
|
2022-09-27 16:03:21 +00:00
|
|
|
find: "().popoutNoBannerPremium",
|
2022-09-02 17:05:52 +00:00
|
|
|
replacement: {
|
2022-09-27 16:03:21 +00:00
|
|
|
match: /style:.{0,10}\{\},(.{1,2})\)/,
|
2022-10-19 17:45:22 +00:00
|
|
|
replace: (m, style) => `onClick:${style}.backgroundImage&&(${style}.cursor="pointer",()=>${OPEN_URL}${style}.backgroundImage.replace("url(", "").replace(/(\\?size=.+)?\\)/, "?size=2048"))),${m}`
|
2022-09-02 17:05:52 +00:00
|
|
|
}
|
|
|
|
}, {
|
2022-09-27 16:03:21 +00:00
|
|
|
find: '"GuildContextMenu:',
|
2022-09-02 17:05:52 +00:00
|
|
|
replacement: [
|
|
|
|
{
|
|
|
|
match: /\w=(\w)\.id/,
|
|
|
|
replace: (m, guild) => `_guild=${guild},${m}`
|
|
|
|
},
|
|
|
|
{
|
2022-09-27 16:03:21 +00: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 16:03:48 +00:00
|
|
|
`{id:"viewicons-copy-icon",label:"View Icon",action:()=>${OPEN_URL}_guild.getIconURL(void 0,true)+"size=2048")}),` +
|
2022-09-27 16:03:21 +00: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 17:05:52 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|