From 6099179f0230e3c6eb449a2cd7f6a5c5d79201f2 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Thu, 8 Sep 2022 22:25:21 +0200 Subject: ViewIcons: Now opens icons in image viewer --- build.mjs | 2 +- src/plugins/viewIcons.ts | 41 -------------------------------- src/plugins/viewIcons.tsx | 60 +++++++++++++++++++++++++++++++++++++++++++++++ src/utils/modal.tsx | 8 +++---- 4 files changed, 65 insertions(+), 46 deletions(-) delete mode 100644 src/plugins/viewIcons.ts create mode 100644 src/plugins/viewIcons.tsx diff --git a/build.mjs b/build.mjs index 6bdeffa..c1ab3cf 100755 --- a/build.mjs +++ b/build.mjs @@ -48,7 +48,7 @@ const globPlugins = { continue; } const mod = `__pluginMod${i}`; - code += `import ${mod} from "./${files[i].replace(".ts", "")}";\n`; + code += `import ${mod} from "./${files[i].replace(/.tsx?$/, "")}";\n`; obj += `[${mod}.name]: ${mod},`; } code += `export default {${obj}}`; diff --git a/src/plugins/viewIcons.ts b/src/plugins/viewIcons.ts deleted file mode 100644 index a6ba4d4..0000000 --- a/src/plugins/viewIcons.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { REACT_GLOBAL } from "../utils/constants"; -import IpcEvents from "../utils/IpcEvents"; -import definePlugin from '../utils/types'; - -const OPEN_URL = `VencordNative.ipc.invoke("${IpcEvents.OPEN_EXTERNAL}",`; -export default definePlugin({ - name: "ViewIcons", - author: "Vendicated", - description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon. Crashes if you don't have Developer Mode enabled, will fix in the future.", - patches: [ - { - find: "UserProfileModalHeader", - replacement: { - match: /\{src:(.{1,2}),avatarDecoration/, - replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}.replace(/\\?.+$/, "")+"?size=2048"),avatarDecoration` - } - }, { - find: "default.popoutNoBannerPremium", - replacement: { - match: /style:.{1,2}\(\{\},(.{1,2}),/, - replace: (m, bannerObj) => `onClick:${bannerObj}.backgroundImage&&(()=>${OPEN_URL}${bannerObj}.backgroundImage.replace("url(", "").replace(/(\\?size=.+)?\\)/, "?size=2048"))),${m}` - } - }, { - find: "GuildContextMenuWrapper", - replacement: [ - { - match: /\w=(\w)\.id/, - replace: (m, guild) => `_guild=${guild},${m}` - }, - { - match: /,(.{1,2})\((.{1,2}\.MenuGroup),\{\},void 0,(.{1,2})\)(?=\)\}.{1,2}\.displayName)/, - replace: (_, factory, menuGroup, copyIdElement) => `,${factory}(${menuGroup},{},void 0,[` + - `_guild.icon&&${REACT_GLOBAL}.cloneElement(${copyIdElement},` + - `{key:"viewicons-copy-icon",id:"viewicons-copy-icon",action:()=>${OPEN_URL}_guild.getIconURL(undefined,true)+"size=2048"),label:"View Icon",icon:null}),` + - `_guild.banner&&${REACT_GLOBAL}.cloneElement(${copyIdElement},` + - `{key:"viewicons-copy-banner",id:"viewicons-copy-banner",action:()=>${OPEN_URL}Vencord.Webpack.findByProps("getGuildBannerURL").getGuildBannerURL(_guild).replace(/\\?size=.+/, "?size=2048")),label:"View Banner",icon:null}),${copyIdElement}])` - } - ] - } - ] -}); diff --git a/src/plugins/viewIcons.tsx b/src/plugins/viewIcons.tsx new file mode 100644 index 0000000..39c4303 --- /dev/null +++ b/src/plugins/viewIcons.tsx @@ -0,0 +1,60 @@ +import { REACT_GLOBAL } from "../utils/constants"; +import { Modal, openModal } from "../utils/modal"; +import definePlugin from '../utils/types'; +import { filters, waitFor } from "../webpack"; + +let ImageModal: any; +let renderMaskedLink: any; + +waitFor(filters.byDisplayName("ImageModal"), m => ImageModal = m.default); +waitFor("renderMaskedLinkComponent", m => renderMaskedLink = m.renderMaskedLinkComponent); + +const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage("; +export default definePlugin({ + name: "ViewIcons", + author: "Vendicated", + description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon. Crashes if you don't have Developer Mode enabled, will fix in the future.", + + openImage(url: string) { + openModal(() => ( + + ), { size: Modal.ModalSize.DYNAMIC }); + }, + + patches: [ + { + find: "UserProfileModalHeader", + replacement: { + match: /\{src:(.{1,2}),avatarDecoration/, + replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}.replace(/\\?.+$/, "")+"?size=2048"),avatarDecoration` + } + }, { + find: "default.popoutNoBannerPremium", + replacement: { + match: /style:.{1,2}\(\{\},(.{1,2}),/, + replace: (m, bannerObj) => `onClick:${bannerObj}.backgroundImage&&(()=>${OPEN_URL}${bannerObj}.backgroundImage.replace("url(", "").replace(/(\\?size=.+)?\\)/, "?size=2048"))),${m}` + } + }, { + find: "GuildContextMenuWrapper", + replacement: [ + { + match: /\w=(\w)\.id/, + replace: (m, guild) => `_guild=${guild},${m}` + }, + { + match: /,(.{1,2})\((.{1,2}\.MenuGroup),\{\},void 0,(.{1,2})\)(?=\)\}.{1,2}\.displayName)/, + replace: (_, factory, menuGroup, copyIdElement) => `,${factory}(${menuGroup},{},void 0,[` + + `_guild.icon&&${REACT_GLOBAL}.cloneElement(${copyIdElement},` + + `{key:"viewicons-copy-icon",id:"viewicons-copy-icon",action:()=>${OPEN_URL}_guild.getIconURL(undefined,true)+"size=2048"),label:"View Icon",icon:null}),` + + `_guild.banner&&${REACT_GLOBAL}.cloneElement(${copyIdElement},` + + `{key:"viewicons-copy-banner",id:"viewicons-copy-banner",action:()=>${OPEN_URL}Vencord.Webpack.findByProps("getGuildBannerURL").getGuildBannerURL(_guild).replace(/\\?size=.+/, "?size=2048")),label:"View Banner",icon:null}),${copyIdElement}])` + } + ] + } + ] +}); diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index 5628ebe..63821f3 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -1,8 +1,8 @@ import Components from "discord-types/components"; import { waitFor } from "../webpack"; -let Modal: Components.Modal; -let modals: any; +export let Modal: Components.Modal; +export let modals: any; waitFor("openModalLazy", m => modals = m); waitFor("ModalRoot", m => Modal = m); @@ -14,10 +14,10 @@ let modalId = 1337; * @param Component The component to render in the modal * @returns The key of this modal. This can be used to close the modal later with closeModal */ -export function openModal(Component: React.ComponentType) { +export function openModal(Component: React.ComponentType, modalProps: Record) { let key = `Vencord${modalId++}`; modals.openModal(props => - + , { modalKey: key }); -- cgit