From 9ce9b1fcb9c2879b1533832178f033e900164355 Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 18 Sep 2024 12:39:44 +0300 Subject: [PATCH] feat(plugin): HideMessage --- src/plugins/hideMessage/index.tsx | 86 +++++++++++++++++++++++++++++++ src/utils/constants.ts | 4 ++ 2 files changed, 90 insertions(+) create mode 100644 src/plugins/hideMessage/index.tsx diff --git a/src/plugins/hideMessage/index.tsx b/src/plugins/hideMessage/index.tsx new file mode 100644 index 000000000..bee227196 --- /dev/null +++ b/src/plugins/hideMessage/index.tsx @@ -0,0 +1,86 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addButton, removeButton } from "@api/MessagePopover"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { ChannelStore } from "@webpack/common"; +import { get, set } from "@api/DataStore"; + +let style: HTMLStyleElement; + +const KEY = "HideMessage_HiddenIds"; + +let hiddenMessages: Set = new Set(); +const getHiddenMessages = () => get(KEY).then(set => { + hiddenMessages = set ?? new Set(); + return hiddenMessages; +}); +const saveHiddenMessages = (ids: Set) => set(KEY, ids); + +const HideIcon = () => { + return + Hidden (crossed eye) + + ; +}; + +export default definePlugin({ + name: "HideMessage", + description: "Adds an option to hide messages", + authors: [Devs.IsaacZSH], + dependencies: ["MessagePopoverAPI"], + + async start() { + style = document.createElement("style"); + style.id = "VencordHideMessage"; + document.head.appendChild(style); + + await getHiddenMessages(); + await this.buildCss(); + + addButton("HideMessage", msg => { + const handleClick = () => { + this.toggleHide(msg.id) + console.log(msg) + }; + + const label = "Hide Message"; + + return { + label, + icon: HideIcon, + message: msg, + channel: ChannelStore.getChannel(msg.channel_id), + onClick: handleClick, + }; + }); + }, + + stop() { + removeButton("HideMessage"); + }, + + async buildCss() { + console.log(hiddenMessages) + console.log(...hiddenMessages) + const elements = [...hiddenMessages].map(id => `#message-content-${id}`).join(","); + style.textContent = ` + :is(${elements}) { + display: none !important; + } + `; + }, + + async toggleHide(id: string) { + const ids = await getHiddenMessages(); + if (!ids.delete(id)) + ids.add(id); + + await saveHiddenMessages(ids); + await this.buildCss(); + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 0572fa102..4fc52ba71 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -575,6 +575,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RamziAH", id: 1279957227612147747n, }, + Isaac: { + name: "Isaac-zsh", + id: 407527870110629888n, + }, } satisfies Record); // iife so #__PURE__ works correctly