From 19c9a132733dfb67de6d62d6da1348944cbe1146 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 11 Jan 2023 01:50:00 +0100 Subject: Fix InvisibleChat button getting hidden by themes --- .../invisibleChat/components/DecryptionModal.tsx | 77 +++++++ .../invisibleChat/components/EncryptionModal.tsx | 116 +++++++++++ src/plugins/invisibleChat/index.tsx | 222 +++++++++++++++++++++ .../invisiblechat/components/DecryptionModal.tsx | 77 ------- .../invisiblechat/components/EncryptionModal.tsx | 116 ----------- src/plugins/invisiblechat/index.tsx | 213 -------------------- 6 files changed, 415 insertions(+), 406 deletions(-) create mode 100644 src/plugins/invisibleChat/components/DecryptionModal.tsx create mode 100644 src/plugins/invisibleChat/components/EncryptionModal.tsx create mode 100644 src/plugins/invisibleChat/index.tsx delete mode 100644 src/plugins/invisiblechat/components/DecryptionModal.tsx delete mode 100644 src/plugins/invisiblechat/components/EncryptionModal.tsx delete mode 100644 src/plugins/invisiblechat/index.tsx (limited to 'src') diff --git a/src/plugins/invisibleChat/components/DecryptionModal.tsx b/src/plugins/invisibleChat/components/DecryptionModal.tsx new file mode 100644 index 0000000..7d70444 --- /dev/null +++ b/src/plugins/invisibleChat/components/DecryptionModal.tsx @@ -0,0 +1,77 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 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 . +*/ + +import { + ModalContent, + ModalFooter, + ModalHeader, + ModalRoot, + openModal, +} from "@utils/modal"; +import { Button, Forms, React, TextInput } from "@webpack/common"; + +import { decrypt } from "../index"; + +export function DecModal(props: any) { + const secret: string = props?.message?.content; + const [password, setPassword] = React.useState("password"); + + return ( + + + Decrypt Message + + + + Secret + + Password + + + + + + + + + ); +} + +export function buildDecModal(msg: any): any { + openModal((props: any) => ); +} diff --git a/src/plugins/invisibleChat/components/EncryptionModal.tsx b/src/plugins/invisibleChat/components/EncryptionModal.tsx new file mode 100644 index 0000000..f650f28 --- /dev/null +++ b/src/plugins/invisibleChat/components/EncryptionModal.tsx @@ -0,0 +1,116 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 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 . +*/ + +import { + ModalContent, + ModalFooter, + ModalHeader, + ModalProps, + ModalRoot, + openModal, +} from "@utils/modal"; +import { findLazy } from "@webpack"; +import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; + +import { encrypt } from "../index"; + +const ComponentDispatch = findLazy(m => m.emitter?._events?.INSERT_TEXT); + +function EncModal(props: ModalProps) { + const [secret, setSecret] = React.useState(""); + const [cover, setCover] = React.useState(""); + const [password, setPassword] = React.useState("password"); + const [noCover, setNoCover] = React.useState(false); + + const isValid = secret && (noCover || (cover && /\w \w/.test(cover))); + + return ( + + + Encrypt Message + + + + Secret + { + setSecret(e); + }} + /> + Cover (2 or more Words!!) + { + setCover(e); + }} + /> + Password + { + setPassword(e); + }} + /> + { + setNoCover(e); + }} + > + Don't use a Cover + + + + + + + + + ); +} + +export function buildEncModal(): any { + openModal(props => ); +} diff --git a/src/plugins/invisibleChat/index.tsx b/src/plugins/invisibleChat/index.tsx new file mode 100644 index 0000000..e2f7769 --- /dev/null +++ b/src/plugins/invisibleChat/index.tsx @@ -0,0 +1,222 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 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 . +*/ + +import { addButton, removeButton } from "@api/MessagePopover"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import { getStegCloak } from "@utils/dependencies"; +import definePlugin from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { Button, ButtonLooks, ChannelStore, FluxDispatcher, Tooltip } from "@webpack/common"; + +import { buildDecModal } from "./components/DecryptionModal"; +import { buildEncModal } from "./components/EncryptionModal"; + +const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent"); + +let steggo: any; + +function PopOverIcon() { + return ( + + + + + ); +} + + +function Indicator() { + return ( + + {({ onMouseEnter, onMouseLeave }) => ( + + )} + + + ); + +} + +function ChatBarIcon() { + return ( + + {({ onMouseEnter, onMouseLeave }) => ( + // size="" = Button.Sizes.NONE + /* + many themes set "> button" to display: none, as the gift button is + the only directly descending button (all the other elements are divs.) + Thus, wrap in a div here to avoid getting hidden by that. + flex is for some reason necessary as otherwise the button goes flying off + */ +
+ +
+ ) + } +
+ ); +} + + +export default definePlugin({ + name: "InvisibleChat", + description: "Encrypt your Messages in a non-suspicious way! This plugin makes requests to >>https://embed.sammcheese.net<< to provide embeds to decrypted links!", + authors: [Devs.SammCheese], + patches: [ + { + // Indicator + find: ".Messages.MESSAGE_EDITED,", + replacement: { + match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm, + replace: "try {$1 && $self.INV_REGEX.test($1.content[0]) ? $1.content.push($self.indicator()) : null } catch {};$&" + } + }, + { + find: ".activeCommandOption", + replacement: { + match: /.=.\.activeCommand,.=.\.activeCommandOption,.{1,133}(.)=\[\];/, + replace: "$&;$1.push($self.chatBarIcon());", + } + }, + ], + + EMBED_API_URL: "https://embed.sammcheese.net", + INV_REGEX: new RegExp(/( \u200c|\u200d |[\u2060-\u2064])[^\u200b]/), + URL_REGEX: new RegExp( + /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/, + ), + + async start() { + const { default: StegCloak } = await getStegCloak(); + steggo = new StegCloak(true, false); + + addButton("invDecrypt", message => { + return this.INV_REGEX.test(message?.content) + ? { + label: "Decrypt Message", + icon: this.popOverIcon, + message: message, + channel: ChannelStore.getChannel(message.channel_id), + onClick: () => buildDecModal({ message }) + } + : null; + }); + }, + + stop() { + removeButton("invDecrypt"); + }, + + // Gets the Embed of a Link + async getEmbed(url: URL): Promise { + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), 5000); + + const options: RequestInit = { + signal: controller.signal, + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + url, + }), + }; + + // AWS hosted url to discord embed object + const rawRes = await fetch(this.EMBED_API_URL, options); + clearTimeout(timeout); + + return await rawRes.json(); + }, + + async buildEmbed(message: any, revealed: string): Promise { + const urlCheck = revealed.match(this.URL_REGEX); + + message.embeds.push({ + type: "rich", + title: "Decrypted Message", + color: "0x45f5f5", + description: revealed, + footer: { + text: "Made with ❤️ by c0dine and Sammy!", + }, + }); + + if (urlCheck?.length) + message.embeds.push(await this.getEmbed(new URL(urlCheck[0]))); + + this.updateMessage(message); + }, + + updateMessage: (message: any) => { + FluxDispatcher.dispatch({ + type: "MESSAGE_UPDATE", + message, + }); + }, + + chatBarIcon: ErrorBoundary.wrap(ChatBarIcon, { noop: true }), + popOverIcon: () => , + indicator: ErrorBoundary.wrap(Indicator, { noop: true }) +}); + +export function encrypt(secret: string, password: string, cover: string): string { + return steggo.hide(secret + "\u200b", password, cover); +} + +export function decrypt(secret: string, password: string): string { + return steggo.reveal(secret, password).replace("\u200b", ""); +} + diff --git a/src/plugins/invisiblechat/components/DecryptionModal.tsx b/src/plugins/invisiblechat/components/DecryptionModal.tsx deleted file mode 100644 index 7d70444..0000000 --- a/src/plugins/invisiblechat/components/DecryptionModal.tsx +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2023 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 . -*/ - -import { - ModalContent, - ModalFooter, - ModalHeader, - ModalRoot, - openModal, -} from "@utils/modal"; -import { Button, Forms, React, TextInput } from "@webpack/common"; - -import { decrypt } from "../index"; - -export function DecModal(props: any) { - const secret: string = props?.message?.content; - const [password, setPassword] = React.useState("password"); - - return ( - - - Decrypt Message - - - - Secret - - Password - - - - - - - - - ); -} - -export function buildDecModal(msg: any): any { - openModal((props: any) => ); -} diff --git a/src/plugins/invisiblechat/components/EncryptionModal.tsx b/src/plugins/invisiblechat/components/EncryptionModal.tsx deleted file mode 100644 index f650f28..0000000 --- a/src/plugins/invisiblechat/components/EncryptionModal.tsx +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2023 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 . -*/ - -import { - ModalContent, - ModalFooter, - ModalHeader, - ModalProps, - ModalRoot, - openModal, -} from "@utils/modal"; -import { findLazy } from "@webpack"; -import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; - -import { encrypt } from "../index"; - -const ComponentDispatch = findLazy(m => m.emitter?._events?.INSERT_TEXT); - -function EncModal(props: ModalProps) { - const [secret, setSecret] = React.useState(""); - const [cover, setCover] = React.useState(""); - const [password, setPassword] = React.useState("password"); - const [noCover, setNoCover] = React.useState(false); - - const isValid = secret && (noCover || (cover && /\w \w/.test(cover))); - - return ( - - - Encrypt Message - - - - Secret - { - setSecret(e); - }} - /> - Cover (2 or more Words!!) - { - setCover(e); - }} - /> - Password - { - setPassword(e); - }} - /> - { - setNoCover(e); - }} - > - Don't use a Cover - - - - - - - - - ); -} - -export function buildEncModal(): any { - openModal(props => ); -} diff --git a/src/plugins/invisiblechat/index.tsx b/src/plugins/invisiblechat/index.tsx deleted file mode 100644 index 89d2d61..0000000 --- a/src/plugins/invisiblechat/index.tsx +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2023 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 . -*/ - -import { addButton, removeButton } from "@api/MessagePopover"; -import ErrorBoundary from "@components/ErrorBoundary"; -import { Devs } from "@utils/constants"; -import { getStegCloak } from "@utils/dependencies"; -import definePlugin from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { Button, ButtonLooks, ChannelStore, FluxDispatcher, Tooltip } from "@webpack/common"; - -import { buildDecModal } from "./components/DecryptionModal"; -import { buildEncModal } from "./components/EncryptionModal"; - -const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent"); - -let steggo: any; - -function PopOverIcon() { - return ( - - - - - ); -} - - -function Indicator() { - return ( - - {({ onMouseEnter, onMouseLeave }) => ( - - )} - - - ); - -} - -function ChatBarIcon() { - return ( - - {({ onMouseEnter, onMouseLeave }) => ( - // size="" = Button.Sizes.NONE - - )} - - ); -} - - -export default definePlugin({ - name: "InvisibleChat", - description: "Encrypt your Messages in a non-suspicious way! This plugin makes requests to >>https://embed.sammcheese.net<< to provide embeds to decrypted links!", - authors: [Devs.SammCheese], - patches: [ - { - // Indicator - find: ".Messages.MESSAGE_EDITED,", - replacement: { - match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm, - replace: "try {$1 && $self.INV_REGEX.test($1.content[0]) ? $1.content.push($self.indicator()) : null } catch {};$&" - } - }, - { - find: ".activeCommandOption", - replacement: { - match: /.=.\.activeCommand,.=.\.activeCommandOption,.{1,133}(.)=\[\];/, - replace: "$&;$1.push($self.chatBarIcon());", - } - }, - ], - - EMBED_API_URL: "https://embed.sammcheese.net", - INV_REGEX: new RegExp(/( \u200c|\u200d |[\u2060-\u2064])[^\u200b]/), - URL_REGEX: new RegExp( - /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/, - ), - - async start() { - const { default: StegCloak } = await getStegCloak(); - steggo = new StegCloak(true, false); - - addButton("invDecrypt", message => { - return this.INV_REGEX.test(message?.content) - ? { - label: "Decrypt Message", - icon: this.popOverIcon, - message: message, - channel: ChannelStore.getChannel(message.channel_id), - onClick: () => buildDecModal({ message }) - } - : null; - }); - }, - - stop() { - removeButton("invDecrypt"); - }, - - // Gets the Embed of a Link - async getEmbed(url: URL): Promise { - const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 5000); - - const options: RequestInit = { - signal: controller.signal, - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - url, - }), - }; - - // AWS hosted url to discord embed object - const rawRes = await fetch(this.EMBED_API_URL, options); - clearTimeout(timeout); - - return await rawRes.json(); - }, - - async buildEmbed(message: any, revealed: string): Promise { - const urlCheck = revealed.match(this.URL_REGEX); - - message.embeds.push({ - type: "rich", - title: "Decrypted Message", - color: "0x45f5f5", - description: revealed, - footer: { - text: "Made with ❤️ by c0dine and Sammy!", - }, - }); - - if (urlCheck?.length) - message.embeds.push(await this.getEmbed(new URL(urlCheck[0]))); - - this.updateMessage(message); - }, - - updateMessage: (message: any) => { - FluxDispatcher.dispatch({ - type: "MESSAGE_UPDATE", - message, - }); - }, - - chatBarIcon: ErrorBoundary.wrap(ChatBarIcon, { noop: true }), - popOverIcon: () => , - indicator: ErrorBoundary.wrap(Indicator, { noop: true }) -}); - -export function encrypt(secret: string, password: string, cover: string): string { - return steggo.hide(secret + "\u200b", password, cover); -} - -export function decrypt(secret: string, password: string): string { - return steggo.reveal(secret, password).replace("\u200b", ""); -} - -- cgit