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";
|
2023-05-05 23:36:00 +00:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
2023-05-13 21:49:47 +00:00
|
|
|
import { ImageIcon } from "@components/Icons";
|
2022-11-28 12:37:55 +00:00
|
|
|
import { Devs } from "@utils/constants";
|
2023-06-16 17:35:50 +00:00
|
|
|
import { openImageModal } from "@utils/discord";
|
2023-04-12 01:27:31 +00:00
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2023-06-16 17:35:50 +00:00
|
|
|
import { 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-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 {
|
2023-06-27 20:41:52 +00:00
|
|
|
guild?: Guild;
|
2023-04-12 01:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
]
|
2023-06-16 17:35:50 +00:00
|
|
|
},
|
|
|
|
imgSize: {
|
|
|
|
type: OptionType.SELECT,
|
|
|
|
description: "The image size to use",
|
|
|
|
options: ["128", "256", "512", "1024", "2048", "4096"].map(n => ({ label: n, value: n, default: n === "1024" }))
|
2023-04-12 01:27:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function openImage(url: string) {
|
2023-04-13 02:25:38 +00:00
|
|
|
const format = url.startsWith("/") ? "png" : settings.store.format;
|
2023-06-16 17:35:50 +00:00
|
|
|
|
2023-04-13 02:25:38 +00:00
|
|
|
const u = new URL(url, window.location.href);
|
2023-06-16 17:35:50 +00:00
|
|
|
u.searchParams.set("size", settings.store.imgSize);
|
2023-04-13 02:25:38 +00:00
|
|
|
u.pathname = u.pathname.replace(/\.(png|jpe?g|webp)$/, `.${format}`);
|
2023-04-12 01:27:31 +00:00
|
|
|
url = u.toString();
|
|
|
|
|
2023-06-16 17:35:50 +00:00
|
|
|
u.searchParams.set("size", "4096");
|
|
|
|
const originalUrl = u.toString();
|
|
|
|
|
|
|
|
openImageModal(url, {
|
|
|
|
original: originalUrl,
|
|
|
|
height: 256
|
|
|
|
});
|
2023-04-12 01:27:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-15 00:47:03 +00:00
|
|
|
const UserContext: NavContextMenuPatchCallback = (children, { user, guildId }: UserContextProps) => () => {
|
2023-09-25 23:48:09 +00:00
|
|
|
if (!user) return;
|
2023-04-12 01:27:31 +00:00
|
|
|
const memberAvatar = GuildMemberStore.getMember(guildId!, user.id)?.avatar || null;
|
|
|
|
|
2023-05-11 17:26:55 +00:00
|
|
|
children.splice(-1, 0, (
|
2023-04-12 01:27:31 +00:00
|
|
|
<Menu.MenuGroup>
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-avatar"
|
|
|
|
label="View Avatar"
|
2023-06-16 17:35:50 +00:00
|
|
|
action={() => openImage(BannerStore.getUserAvatarURL(user, true))}
|
2023-05-13 21:49:47 +00:00
|
|
|
icon={ImageIcon}
|
2023-04-12 01:27:31 +00:00
|
|
|
/>
|
|
|
|
{memberAvatar && (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-server-avatar"
|
|
|
|
label="View Server Avatar"
|
|
|
|
action={() => openImage(BannerStore.getGuildMemberAvatarURLSimple({
|
|
|
|
userId: user.id,
|
|
|
|
avatar: memberAvatar,
|
2023-06-27 20:41:52 +00:00
|
|
|
guildId,
|
|
|
|
canAnimate: true
|
2023-04-12 01:27:31 +00:00
|
|
|
}, true))}
|
2023-05-13 21:49:47 +00:00
|
|
|
icon={ImageIcon}
|
2023-04-12 01:27:31 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Menu.MenuGroup>
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
2023-06-27 20:41:52 +00:00
|
|
|
const GuildContext: NavContextMenuPatchCallback = (children, { guild }: GuildContextProps) => () => {
|
2023-09-25 23:48:09 +00:00
|
|
|
if (!guild) return;
|
2023-06-27 20:41:52 +00:00
|
|
|
|
|
|
|
const { id, icon, banner } = guild;
|
2023-04-12 01:27:31 +00:00
|
|
|
if (!banner && !icon) return;
|
|
|
|
|
2023-05-11 17:26:55 +00:00
|
|
|
children.splice(-1, 0, (
|
2023-04-12 01:27:31 +00:00
|
|
|
<Menu.MenuGroup>
|
|
|
|
{icon ? (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-icon"
|
|
|
|
label="View Icon"
|
|
|
|
action={() =>
|
|
|
|
openImage(BannerStore.getGuildIconURL({
|
|
|
|
id,
|
|
|
|
icon,
|
|
|
|
canAnimate: true
|
|
|
|
}))
|
|
|
|
}
|
2023-05-13 21:49:47 +00:00
|
|
|
icon={ImageIcon}
|
2023-04-12 01:27:31 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{banner ? (
|
|
|
|
<Menu.MenuItem
|
|
|
|
id="view-banner"
|
|
|
|
label="View Banner"
|
|
|
|
action={() =>
|
|
|
|
openImage(BannerStore.getGuildBannerURL({
|
|
|
|
id,
|
|
|
|
banner,
|
|
|
|
}, true))
|
|
|
|
}
|
2023-05-13 21:49:47 +00:00
|
|
|
icon={ImageIcon}
|
2023-04-12 01:27:31 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</Menu.MenuGroup>
|
|
|
|
));
|
|
|
|
};
|
2022-11-11 15:14:05 +00:00
|
|
|
|
2023-03-23 03:37:32 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "ViewIcons",
|
2023-04-13 02:25:38 +00:00
|
|
|
authors: [Devs.Ven, Devs.TheKodeToad, Devs.Nuckyz],
|
|
|
|
description: "Makes avatars and banners in user profiles clickable, and adds View Icon/Banner entries in the user and server context menu",
|
2023-05-12 01:41:00 +00:00
|
|
|
tags: ["ImageUtilities"],
|
2023-04-12 01:27:31 +00:00
|
|
|
|
|
|
|
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: [
|
2023-04-28 16:36:22 +00:00
|
|
|
// Make pfps clickable
|
2022-09-02 17:05:52 +00:00
|
|
|
{
|
2023-10-25 17:08:28 +00:00
|
|
|
find: "onAddFriend:function",
|
2022-09-02 17:05:52 +00:00
|
|
|
replacement: {
|
2023-04-28 16:36:22 +00:00
|
|
|
match: /\{src:(\i)(?=,avatarDecoration)/,
|
|
|
|
replace: "{src:$1,onClick:()=>$self.openImage($1)"
|
2022-09-02 17:05:52 +00:00
|
|
|
}
|
2023-04-28 16:36:22 +00:00
|
|
|
},
|
|
|
|
// Make banners clickable
|
|
|
|
{
|
|
|
|
find: ".NITRO_BANNER,",
|
2022-09-02 17:05:52 +00:00
|
|
|
replacement: {
|
2023-04-28 16:36:22 +00:00
|
|
|
// style: { backgroundImage: shouldShowBanner ? "url(".concat(bannerUrl,
|
|
|
|
match: /style:\{(?=backgroundImage:(\i&&\i)\?"url\("\.concat\((\i),)/,
|
2023-04-13 02:25:38 +00:00
|
|
|
replace:
|
2023-06-27 20:41:52 +00:00
|
|
|
// onClick: () => shouldShowBanner && ev.target.style.backgroundImage && openImage(bannerUrl), style: { cursor: shouldShowBanner ? "pointer" : void 0,
|
|
|
|
'onClick:ev=>$1&&ev.target.style.backgroundImage&&$self.openImage($2),style:{cursor:$1?"pointer":void 0,'
|
2023-04-13 02:25:38 +00:00
|
|
|
}
|
2023-04-28 16:36:22 +00:00
|
|
|
},
|
|
|
|
{
|
2023-10-25 17:08:28 +00:00
|
|
|
find: ".avatarPositionPanel",
|
2023-04-13 02:25:38 +00:00
|
|
|
replacement: {
|
2023-10-25 17:08:28 +00:00
|
|
|
match: /(?<=avatarWrapperNonUserBot.{0,50})onClick:(\i\|\|\i)\?void 0(?<=,avatarSrc:(\i).+?)/,
|
2023-04-28 16:36:22 +00:00
|
|
|
replace: "style:($1)?{cursor:\"pointer\"}:{},onClick:$1?()=>{$self.openImage($2)}"
|
2022-09-02 17:05:52 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-12 01:27:31 +00:00
|
|
|
]
|
2023-03-23 03:37:32 +00:00
|
|
|
});
|