mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Compare commits
No commits in common. "f9a59d89e10764ec9fbb6edfb1fecd3fbc7ab3d3" and "f2b6dcbb912a3f3f4f20c9f2a1454fc30950dc8b" have entirely different histories.
f9a59d89e1
...
f2b6dcbb91
1 changed files with 68 additions and 8 deletions
|
@ -5,11 +5,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { addButton, removeButton } from "@api/MessagePopover";
|
import { addButton, removeButton } from "@api/MessagePopover";
|
||||||
|
import { Settings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { ChannelStore } from "@webpack/common";
|
import { ChannelStore } from "@webpack/common";
|
||||||
import { FluxDispatcher } from "@webpack/common";
|
import { get, set } from "@api/DataStore";
|
||||||
import { Message } from "discord-types/general";
|
|
||||||
|
let style: HTMLStyleElement;
|
||||||
|
|
||||||
|
const KEY = "HideMessage_HiddenMessages";
|
||||||
|
|
||||||
|
let hiddenMessages: Set<string> = new Set();
|
||||||
|
const getHiddenMessages = () => get(KEY).then(set => {
|
||||||
|
hiddenMessages = set ?? new Set<string>();
|
||||||
|
return hiddenMessages;
|
||||||
|
});
|
||||||
|
const saveHiddenMessages = (ids: Set<string>) => set(KEY, ids);
|
||||||
|
|
||||||
const HideIcon = () => {
|
const HideIcon = () => {
|
||||||
return <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-labelledby="eyeCrossedIconTitle" stroke="currentColor" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="miter" fill="none" color="currentColor">
|
return <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-labelledby="eyeCrossedIconTitle" stroke="currentColor" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="miter" fill="none" color="currentColor">
|
||||||
|
@ -22,12 +33,23 @@ export default definePlugin({
|
||||||
name: "HideMessage",
|
name: "HideMessage",
|
||||||
description: "Adds an option to hide messages",
|
description: "Adds an option to hide messages",
|
||||||
authors: [Devs.Isaac],
|
authors: [Devs.Isaac],
|
||||||
|
dependencies: ["MessagePopoverAPI"],
|
||||||
hideMessage(msg: Message) {
|
options: {
|
||||||
FluxDispatcher.dispatch({type: "MESSAGE_DELETE", channelId: msg.channel_id, id: msg.id});
|
showMessageHiddenText: {
|
||||||
|
description: `Hidden messages will contain a small text indicating they're hidden.`,
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
async start() {
|
||||||
|
style = document.createElement("style");
|
||||||
|
style.id = "VencordHideMessage";
|
||||||
|
document.head.appendChild(style);
|
||||||
|
|
||||||
|
await getHiddenMessages();
|
||||||
|
await this.buildCss();
|
||||||
|
|
||||||
addButton("HideMessage", msg => {
|
addButton("HideMessage", msg => {
|
||||||
const label = "Hide Message";
|
const label = "Hide Message";
|
||||||
|
|
||||||
|
@ -36,7 +58,7 @@ export default definePlugin({
|
||||||
icon: HideIcon,
|
icon: HideIcon,
|
||||||
message: msg,
|
message: msg,
|
||||||
channel: ChannelStore.getChannel(msg.channel_id),
|
channel: ChannelStore.getChannel(msg.channel_id),
|
||||||
onClick: () => this.hideMessage(msg)
|
onClick: () => this.toggleHide(`{"channelId": "${msg.channel_id}", "messageId": "${msg.id}"}`)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -44,4 +66,42 @@ export default definePlugin({
|
||||||
stop() {
|
stop() {
|
||||||
removeButton("HideMessage");
|
removeButton("HideMessage");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async buildCss() {
|
||||||
|
const chatMessages = [...hiddenMessages].map(ids => `#chat-messages-${JSON.parse(ids).channelId}-${JSON.parse(ids).messageId}`).join(",");
|
||||||
|
const messagesContent = [...hiddenMessages].map(ids => `#message-content-${JSON.parse(ids).messageId}`).join(",");
|
||||||
|
const messagesAccessories = [...hiddenMessages].map(ids => `#message-accessories-${JSON.parse(ids).messageId}`).join(",");
|
||||||
|
style.textContent = `
|
||||||
|
:is(${chatMessages}) :is([class*="message_d5deea"]) :is([class*="embedWrapper"], [class*="clickableSticker"]) {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
:is(${messagesContent}) {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
:is(${messagesAccessories}) {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
if (Settings.plugins.HideMessage.showMessageHiddenText) {
|
||||||
|
style.textContent += `
|
||||||
|
:is(${messagesContent})::after {
|
||||||
|
visibility: visible;
|
||||||
|
content: "Message hidden" !important;
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 80%;
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
},
|
||||||
|
|
||||||
|
async toggleHide(sentIds: string) {
|
||||||
|
const ids = await getHiddenMessages();
|
||||||
|
if (!ids.delete(sentIds))
|
||||||
|
ids.add(sentIds);
|
||||||
|
|
||||||
|
await saveHiddenMessages(ids);
|
||||||
|
await this.buildCss();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue