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-11-11 10:14:05 -05:00
|
|
|
import type { Guild } from "discord-types/general";
|
|
|
|
|
2022-09-30 20:27:28 -04:00
|
|
|
import { Devs } from "../utils/constants";
|
2022-11-11 10:14:05 -05:00
|
|
|
import { LazyComponent, lazyWebpack } from "../utils/misc";
|
2022-10-17 15:18:25 -04:00
|
|
|
import { ModalRoot, ModalSize, openModal } from "../utils/modal";
|
2022-11-12 09:09:02 -05:00
|
|
|
import { PluginDef } from "../utils/types";
|
2022-11-11 10:14:05 -05:00
|
|
|
import { filters, find } from "../webpack";
|
|
|
|
import { Menu } from "../webpack/common";
|
2022-10-14 16:38:49 -04:00
|
|
|
|
2022-11-06 12:37:01 -05:00
|
|
|
const ImageModal = LazyComponent(() => find(m => m.prototype?.render?.toString().includes("OPEN_ORIGINAL_IMAGE")));
|
|
|
|
const MaskedLink = LazyComponent(() => find(m => m.type?.toString().includes("MASKED_LINK)")));
|
2022-09-08 16:25:21 -04:00
|
|
|
|
2022-11-11 10:14:05 -05:00
|
|
|
const GuildBannerStore = lazyWebpack(filters.byProps("getGuildBannerURL"));
|
|
|
|
|
2022-09-08 16:25:21 -04:00
|
|
|
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(";
|
2022-11-12 09:09:02 -05:00
|
|
|
export default new class ViewIcons implements PluginDef {
|
|
|
|
name = "ViewIcons";
|
|
|
|
authors = [Devs.Ven];
|
|
|
|
description = "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon.";
|
2022-09-08 16:25:21 -04:00
|
|
|
|
2022-11-14 12:05:41 -05:00
|
|
|
dependencies = ["MenuItemDeobfuscatorAPI"];
|
2022-11-11 12:49:47 -05:00
|
|
|
|
2022-09-08 16:25:21 -04:00
|
|
|
openImage(url: string) {
|
2022-11-11 10:14:05 -05:00
|
|
|
const u = new URL(url);
|
|
|
|
u.searchParams.set("size", "512");
|
|
|
|
url = u.toString();
|
|
|
|
|
2022-10-17 15:18:25 -04:00
|
|
|
openModal(modalProps => (
|
|
|
|
<ModalRoot size={ModalSize.DYNAMIC} {...modalProps}>
|
|
|
|
<ImageModal
|
|
|
|
shouldAnimate={true}
|
|
|
|
original={url}
|
|
|
|
src={url}
|
2022-11-06 12:37:01 -05:00
|
|
|
renderLinkComponent={() => <MaskedLink />}
|
2022-10-17 15:18:25 -04:00
|
|
|
/>
|
|
|
|
</ModalRoot>
|
|
|
|
));
|
2022-11-12 09:09:02 -05:00
|
|
|
}
|
2022-09-08 16:25:21 -04:00
|
|
|
|
2022-11-12 09:09:02 -05:00
|
|
|
patches = [
|
2022-09-02 13:05:52 -04:00
|
|
|
{
|
2022-09-27 12:03:21 -04:00
|
|
|
find: "onAddFriend:",
|
2022-09-02 13:05:52 -04:00
|
|
|
replacement: {
|
2022-10-19 13:45:22 -04:00
|
|
|
// global because Discord has two components that are 99% identical with one small change ._.
|
|
|
|
match: /\{src:(.{1,2}),avatarDecoration/g,
|
2022-11-11 10:14:05 -05:00
|
|
|
replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}),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})\)/,
|
2022-11-11 10:14:05 -05:00
|
|
|
replace: (m, style) =>
|
|
|
|
`onClick:${style}.backgroundImage&&(${style}.cursor="pointer",` +
|
|
|
|
`()=>${OPEN_URL}${style}.backgroundImage.replace("url(", ""))),${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/,
|
2022-11-11 10:14:05 -05:00
|
|
|
replace: "_guild=$1,$&"
|
2022-09-02 13:05:52 -04:00
|
|
|
},
|
|
|
|
{
|
2022-11-11 10:14:05 -05:00
|
|
|
match: /(id:"leave-guild".{0,200}),(\(0,.{1,3}\.jsxs?\).{0,200}function)/,
|
|
|
|
replace: "$1,Vencord.Plugins.plugins.ViewIcons.buildGuildContextMenuEntries(_guild),$2"
|
2022-09-02 13:05:52 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-11-12 09:09:02 -05:00
|
|
|
];
|
2022-11-11 10:14:05 -05:00
|
|
|
|
|
|
|
buildGuildContextMenuEntries(guild: Guild) {
|
|
|
|
return (
|
|
|
|
<Menu.MenuGroup>
|
|
|
|
{guild.banner && (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-banner"
|
|
|
|
key="view-banner"
|
|
|
|
label="View Banner"
|
|
|
|
action={() => this.openImage(GuildBannerStore.getGuildBannerURL(guild))}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{guild.icon && (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-icon"
|
|
|
|
key="view-icon"
|
|
|
|
label="View Icon"
|
|
|
|
action={() => this.openImage(guild.getIconURL(0, true))}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Menu.MenuGroup>
|
|
|
|
);
|
|
|
|
}
|
2022-11-12 09:09:02 -05:00
|
|
|
};
|