2023-02-01 07:38:02 -05:00
|
|
|
/*
|
|
|
|
* 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";
|
|
|
|
|
2023-06-04 16:22:21 -04:00
|
|
|
const SpoilerClasses = findByPropsLazy("spoilerContent");
|
2023-02-01 07:38:02 -05:00
|
|
|
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: [
|
|
|
|
{
|
2023-02-27 18:41:14 -05:00
|
|
|
find: ".removeObscurity=function",
|
2023-02-01 07:38:02 -05:00
|
|
|
replacement: {
|
2023-03-07 22:11:59 -05:00
|
|
|
match: /(?<=\.removeObscurity=function\((\i)\){)/,
|
|
|
|
replace: (_, event) => `$self.reveal(${event});`
|
2023-02-01 07:38:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
reveal(event: MouseEvent) {
|
|
|
|
const { ctrlKey, shiftKey, target } = event;
|
|
|
|
|
|
|
|
if (!ctrlKey) { return; }
|
|
|
|
|
2023-06-04 16:22:21 -04:00
|
|
|
const { spoilerContent, hidden } = SpoilerClasses;
|
2023-02-01 07:38:02 -05:00
|
|
|
const { messagesWrapper } = MessagesClasses;
|
|
|
|
|
|
|
|
const parent = shiftKey
|
|
|
|
? document.querySelector(`div.${messagesWrapper}`)
|
|
|
|
: (target as HTMLSpanElement).parentElement;
|
|
|
|
|
2023-06-04 16:22:21 -04:00
|
|
|
for (const spoiler of parent!.querySelectorAll(`span.${spoilerContent}.${hidden}`)) {
|
2023-02-01 07:38:02 -05:00
|
|
|
(spoiler as HTMLSpanElement).click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|