2022-10-21 23:17:06 +00: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/>.
|
|
|
|
*/
|
|
|
|
|
2023-04-12 01:27:31 +00:00
|
|
|
import { addContextMenuPatch, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
|
|
|
import { definePluginSettings } from "@api/settings";
|
2022-11-28 12:37:55 +00:00
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
import { LazyComponent } from "@utils/misc";
|
|
|
|
import { ModalRoot, ModalSize, openModal } from "@utils/modal";
|
2023-04-12 01:27:31 +00:00
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2023-01-21 13:37:36 +00:00
|
|
|
import { find, findByCode, findByPropsLazy } from "@webpack";
|
2023-04-12 01:27:31 +00:00
|
|
|
import { GuildMemberStore, Menu } from "@webpack/common";
|
|
|
|
import type { Channel, Guild, User } from "discord-types/general";
|
2022-11-11 15:14:05 +00:00
|
|
|
|
2023-01-21 13:37:36 +00:00
|
|
|
const ImageModal = LazyComponent(() => findByCode(".MEDIA_MODAL_CLOSE,"));
|
2022-11-06 17:37:01 +00:00
|
|
|
const MaskedLink = LazyComponent(() => find(m => m.type?.toString().includes("MASKED_LINK)")));
|
2023-04-12 01:27:31 +00:00
|
|
|
const BannerStore = findByPropsLazy("getGuildBannerURL");
|
2022-09-08 20:25:21 +00:00
|
|
|
|
2023-04-12 01:27:31 +00:00
|
|
|
interface UserContextProps {
|
|
|
|
channel: Channel;
|
|
|
|
guildId?: string;
|
|
|
|
user: User;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface GuildContextProps {
|
|
|
|
guild: Guild;
|
|
|
|
}
|
|
|
|
|
|
|
|
const settings = definePluginSettings({
|
|
|
|
format: {
|
|
|
|
type: OptionType.SELECT,
|
|
|
|
description: "Choose the image format to use for non animated images. Animated images will always use .gif",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
label: "webp",
|
|
|
|
value: "webp",
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "png",
|
|
|
|
value: "png",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "jpg",
|
|
|
|
value: "jpg",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function openImage(url: string) {
|
|
|
|
const u = new URL(url);
|
|
|
|
u.searchParams.set("size", "512");
|
|
|
|
u.pathname = u.pathname.replace(/\.(png|jpe?g|webp)$/, `.${settings.store.format}`);
|
|
|
|
url = u.toString();
|
|
|
|
|
|
|
|
openModal(modalProps => (
|
|
|
|
<ModalRoot size={ModalSize.DYNAMIC} {...modalProps}>
|
|
|
|
<ImageModal
|
|
|
|
shouldAnimate={true}
|
|
|
|
original={url}
|
|
|
|
src={url}
|
|
|
|
renderLinkComponent={MaskedLink}
|
|
|
|
/>
|
|
|
|
</ModalRoot>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
const UserContext: NavContextMenuPatchCallback = (children, { user, guildId }: UserContextProps) => {
|
|
|
|
const memberAvatar = GuildMemberStore.getMember(guildId!, user.id)?.avatar || null;
|
|
|
|
|
|
|
|
children.splice(1, 0, (
|
|
|
|
<Menu.MenuGroup>
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-avatar"
|
|
|
|
label="View Avatar"
|
|
|
|
action={() => openImage(BannerStore.getUserAvatarURL(user, true, 512))}
|
|
|
|
/>
|
|
|
|
{memberAvatar && (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-server-avatar"
|
|
|
|
label="View Server Avatar"
|
|
|
|
action={() => openImage(BannerStore.getGuildMemberAvatarURLSimple({
|
|
|
|
userId: user.id,
|
|
|
|
avatar: memberAvatar,
|
|
|
|
guildId
|
|
|
|
}, true))}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Menu.MenuGroup>
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
|
|
|
const GuildContext: NavContextMenuPatchCallback = (children, { guild: { id, icon, banner } }: GuildContextProps) => {
|
|
|
|
if (!banner && !icon) return;
|
|
|
|
|
|
|
|
// before copy id (if it exists)
|
|
|
|
const idx = children.length +
|
|
|
|
children[children.length - 1]?.props?.children?.props?.id === "devmode-copy-id"
|
|
|
|
? -2
|
|
|
|
: -1;
|
|
|
|
|
|
|
|
children.splice(idx, 0, (
|
|
|
|
<Menu.MenuGroup>
|
|
|
|
{icon ? (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-icon"
|
|
|
|
label="View Icon"
|
|
|
|
action={() =>
|
|
|
|
openImage(BannerStore.getGuildIconURL({
|
|
|
|
id,
|
|
|
|
icon,
|
|
|
|
size: 512,
|
|
|
|
canAnimate: true
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{banner ? (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-banner"
|
|
|
|
label="View Banner"
|
|
|
|
action={() =>
|
|
|
|
openImage(BannerStore.getGuildBannerURL({
|
|
|
|
id,
|
|
|
|
banner,
|
|
|
|
}, true))
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</Menu.MenuGroup>
|
|
|
|
));
|
|
|
|
};
|
2022-11-11 15:14:05 +00:00
|
|
|
|
2023-03-23 03:37:32 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "ViewIcons",
|
|
|
|
authors: [Devs.Ven],
|
2023-04-12 01:27:31 +00:00
|
|
|
description: "Makes Avatars/Banners in user profiles clickable, and adds View Icon/Banner entries in the user and server context menu",
|
|
|
|
|
|
|
|
settings,
|
|
|
|
|
|
|
|
openImage,
|
|
|
|
|
|
|
|
start() {
|
|
|
|
addContextMenuPatch("user-context", UserContext);
|
|
|
|
addContextMenuPatch("guild-context", GuildContext);
|
|
|
|
},
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
removeContextMenuPatch("user-context", UserContext);
|
|
|
|
removeContextMenuPatch("guild-context", GuildContext);
|
2023-03-23 03:37:32 +00:00
|
|
|
},
|
2022-09-08 20:25:21 +00:00
|
|
|
|
2023-03-23 03:37:32 +00:00
|
|
|
patches: [
|
2022-09-02 17:05:52 +00:00
|
|
|
{
|
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 ._.
|
2023-04-12 01:27:31 +00:00
|
|
|
match: /\{src:(\i),avatarDecoration/g,
|
|
|
|
replace: (_, src) => `{src:${src},onClick:()=>$self.openImage(${src}),avatarDecoration`
|
2022-09-02 17:05:52 +00:00
|
|
|
}
|
|
|
|
}, {
|
2023-01-07 02:19:28 +00:00
|
|
|
find: ".popoutNoBannerPremium",
|
2022-09-02 17:05:52 +00:00
|
|
|
replacement: {
|
2023-04-12 01:27:31 +00:00
|
|
|
match: /style:.{0,10}\{\},(\i)\)/,
|
2022-11-11 15:14:05 +00:00
|
|
|
replace: (m, style) =>
|
|
|
|
`onClick:${style}.backgroundImage&&(${style}.cursor="pointer",` +
|
2023-04-12 01:27:31 +00:00
|
|
|
`()=>$self.openImage(${style}.backgroundImage.replace("url(", ""))),${m}`
|
2022-09-02 17:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-12 01:27:31 +00:00
|
|
|
]
|
2023-03-23 03:37:32 +00:00
|
|
|
});
|