Vencord/src/plugins/viewIcons.tsx

82 lines
3.7 KiB
TypeScript
Raw Normal View History

2022-10-21 19:17:06 -04:00
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2022-09-30 20:27:28 -04:00
import { Devs } from "../utils/constants";
import { LazyComponent } from "../utils/misc";
import { ModalRoot, ModalSize, openModal } from "../utils/modal";
2022-10-22 12:18:41 -04:00
import definePlugin from "../utils/types";
2022-10-14 16:38:49 -04:00
import { find } from "../webpack";
const ImageModal = LazyComponent(() => find(m => m.prototype?.render?.toString().includes("OPEN_ORIGINAL_IMAGE")));
const MaskedLink = LazyComponent(() => find(m => m.type?.toString().includes("MASKED_LINK)")));
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) {
openModal(modalProps => (
<ModalRoot size={ModalSize.DYNAMIC} {...modalProps}>
<ImageModal
shouldAnimate={true}
original={url}
src={url}
renderLinkComponent={() => <MaskedLink />}
/>
</ModalRoot>
));
},
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: {
// global because Discord has two components that are 99% identical with one small change ._.
match: /\{src:(.{1,2}),avatarDecoration/g,
replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}.replace(/\\?.+$/, "")+"?size=512"),avatarDecoration`
2022-09-02 13:05:52 -04:00
}
}, {
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, style) => `onClick:${style}.backgroundImage&&(${style}.cursor="pointer",()=>${OPEN_URL}${style}.backgroundImage.replace("url(", "").replace(/(\\?size=.+)?\\)/, "?size=512"))),${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-10-20 05:58:20 -04:00
match: /(?<=createElement\((.{1,5}),\{id:"leave-guild".{0,100},)(.{1,2}\.createElement)\((.{1,5}),null,(.{1,2})\)(?=\)\}function)/,
2022-09-27 12:03:21 -04:00
replace: (_, menu, createElement, menuGroup, copyIdElement) =>
`${createElement}(${menuGroup},null,[` +
`_guild.icon&&${createElement}(${menu},` +
`{id:"viewicons-copy-icon",label:"View Icon",action:()=>${OPEN_URL}_guild.getIconURL(void 0,true)+"size=512")}),` +
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=512"))})`
2022-09-27 12:03:21 -04:00
+ `,${copyIdElement}])`
2022-09-02 13:05:52 -04:00
}
]
}
]
});