aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/viewIcons.tsx
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-11-11 16:14:05 +0100
committerVendicated <vendicated@riseup.net>2022-11-11 16:14:09 +0100
commit1176896a1b7aa5615b4aae28cc885683f0dadd1a (patch)
treed314a46e6ddcab6e3f328d0a3f535319e7c8f796 /src/plugins/viewIcons.tsx
parentf3aba3edb0fc67118546629f7dbdda5ff6b0ebff (diff)
downloadVencord-1176896a1b7aa5615b4aae28cc885683f0dadd1a.tar.gz
Vencord-1176896a1b7aa5615b4aae28cc885683f0dadd1a.tar.bz2
Vencord-1176896a1b7aa5615b4aae28cc885683f0dadd1a.zip
fix(plugins): PronounDB, ViewIcons, WebhookTags, NoBlockedMessages, BetterGifAltText, MessageAccessories
Diffstat (limited to 'src/plugins/viewIcons.tsx')
-rw-r--r--src/plugins/viewIcons.tsx56
1 files changed, 42 insertions, 14 deletions
diff --git a/src/plugins/viewIcons.tsx b/src/plugins/viewIcons.tsx
index bd70bd6..399bf72 100644
--- a/src/plugins/viewIcons.tsx
+++ b/src/plugins/viewIcons.tsx
@@ -16,15 +16,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import type { Guild } from "discord-types/general";
+
import { Devs } from "../utils/constants";
-import { LazyComponent } from "../utils/misc";
+import { LazyComponent, lazyWebpack } from "../utils/misc";
import { ModalRoot, ModalSize, openModal } from "../utils/modal";
import definePlugin from "../utils/types";
-import { find } from "../webpack";
+import { filters, find } from "../webpack";
+import { Menu } from "../webpack/common";
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 GuildBannerStore = lazyWebpack(filters.byProps("getGuildBannerURL"));
+
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(";
export default definePlugin({
name: "ViewIcons",
@@ -32,6 +37,10 @@ export default definePlugin({
description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon.",
openImage(url: string) {
+ const u = new URL(url);
+ u.searchParams.set("size", "512");
+ url = u.toString();
+
openModal(modalProps => (
<ModalRoot size={ModalSize.DYNAMIC} {...modalProps}>
<ImageModal
@@ -50,32 +59,51 @@ export default definePlugin({
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`
+ replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}),avatarDecoration`
}
}, {
find: "().popoutNoBannerPremium",
replacement: {
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}`
+ replace: (m, style) =>
+ `onClick:${style}.backgroundImage&&(${style}.cursor="pointer",` +
+ `()=>${OPEN_URL}${style}.backgroundImage.replace("url(", ""))),${m}`
}
}, {
find: '"GuildContextMenu:',
replacement: [
{
match: /\w=(\w)\.id/,
- replace: (m, guild) => `_guild=${guild},${m}`
+ replace: "_guild=$1,$&"
},
{
- 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},` +
- `{id:"viewicons-copy-icon",label:"View Icon",action:()=>${OPEN_URL}_guild.getIconURL(void 0,true)+"size=512")}),` +
- `_guild.banner&&${createElement}(${menu},` +
- `{id:"viewicons-copy-banner",label:"View Banner",action:()=>${OPEN_URL}Vencord.Webpack.findByProps("getGuildBannerURL").getGuildBannerURL(_guild).replace(/\\?size=.+/, "?size=512"))})`
- + `,${copyIdElement}])`
+ match: /(id:"leave-guild".{0,200}),(\(0,.{1,3}\.jsxs?\).{0,200}function)/,
+ replace: "$1,Vencord.Plugins.plugins.ViewIcons.buildGuildContextMenuEntries(_guild),$2"
}
]
}
- ]
+ ],
+
+ 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>
+ );
+ }
});