Skip to content

Commit

Permalink
feat(plugin): RevealAllSpoilers (Vendicated#381)
Browse files Browse the repository at this point in the history
Co-authored-by: Ven <[email protected]>
  • Loading branch information
whqwert and Vendicated committed Feb 1, 2023
1 parent 369d179 commit de09904
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/plugins/revealAllSpoilers.ts
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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();
}
}

});
4 changes: 4 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({
captain: {
name: "Captain",
id: 347366054806159360n
},
whqwert: {
name: "whqwert",
id: 586239091520176128n
}
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"esModuleInterop": true,
"lib": [
"DOM",
"DOM.Iterable",
"esnext",
"esnext.array",
"esnext.asynciterable",
Expand Down

0 comments on commit de09904

Please sign in to comment.