From de0990434e2859141c71b9ab42931297480fb6e2 Mon Sep 17 00:00:00 2001 From: whqwert <94757998+whqwert@users.noreply.github.com> Date: Wed, 1 Feb 2023 06:38:02 -0600 Subject: [PATCH] feat(plugin): RevealAllSpoilers (#381) Co-authored-by: Ven --- src/plugins/revealAllSpoilers.ts | 58 ++++++++++++++++++++++++++++++++ src/utils/constants.ts | 4 +++ tsconfig.json | 1 + 3 files changed, 63 insertions(+) create mode 100644 src/plugins/revealAllSpoilers.ts diff --git a/src/plugins/revealAllSpoilers.ts b/src/plugins/revealAllSpoilers.ts new file mode 100644 index 00000000..b508b6a0 --- /dev/null +++ b/src/plugins/revealAllSpoilers.ts @@ -0,0 +1,58 @@ +/* + * 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 { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { findByPropsLazy } from "@webpack"; + +const SpoilerClasses = findByPropsLazy("spoilerText"); +const MessagesClasses = findByPropsLazy("messagesWrapper", "messages"); + +export default definePlugin({ + name: "RevealAllSpoilers", + description: "Reveal all spoilers in a message by Ctrl-clicking a spoiler, or in the chat with Ctrl+Shift-click", + authors: [Devs.whqwert], + + patches: [ + { + find: ".revealSpoiler=function", + replacement: { + match: /\.revealSpoiler=function\((.{1,2})\){/, + replace: ".revealSpoiler=function($1){$self.reveal($1);" + } + } + ], + + reveal(event: MouseEvent) { + const { ctrlKey, shiftKey, target } = event; + + if (!ctrlKey) { return; } + + const { spoilerText, hidden } = SpoilerClasses; + const { messagesWrapper } = MessagesClasses; + + const parent = shiftKey + ? document.querySelector(`div.${messagesWrapper}`) + : (target as HTMLSpanElement).parentElement; + + for (const spoiler of parent!.querySelectorAll(`span.${spoilerText}.${hidden}`)) { + (spoiler as HTMLSpanElement).click(); + } + } + +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 1eba7130..de63de82 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -192,5 +192,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({ captain: { name: "Captain", id: 347366054806159360n + }, + whqwert: { + name: "whqwert", + id: 586239091520176128n } }); diff --git a/tsconfig.json b/tsconfig.json index f811c00a..db540745 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "esModuleInterop": true, "lib": [ "DOM", + "DOM.Iterable", "esnext", "esnext.array", "esnext.asynciterable",