HideAttachments Refactor to use Styles API

This commit is contained in:
Sqaaakoi 2025-01-20 05:48:44 +13:00
parent b029ce47a0
commit 55090b76cd
No known key found for this signature in database

View file

@ -18,6 +18,7 @@
import { get, set } from "@api/DataStore"; import { get, set } from "@api/DataStore";
import { addButton, removeButton } from "@api/MessagePopover"; import { addButton, removeButton } from "@api/MessagePopover";
import { setStyle } from "@api/Styles";
import { ImageInvisible, ImageVisible } from "@components/Icons"; import { ImageInvisible, ImageVisible } from "@components/Icons";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
@ -41,10 +42,6 @@ export default definePlugin({
dependencies: ["MessagePopoverAPI"], dependencies: ["MessagePopoverAPI"],
async start() { async start() {
style = document.createElement("style");
style.id = "VencordHideAttachments";
document.head.appendChild(style);
await getHiddenMessages(); await getHiddenMessages();
await this.buildCss(); await this.buildCss();
@ -64,24 +61,30 @@ export default definePlugin({
}, },
stop() { stop() {
style.remove(); setStyle({
name: "HideAttachments",
enabled: false
});
hiddenMessages.clear(); hiddenMessages.clear();
removeButton("HideAttachments"); removeButton("HideAttachments");
}, },
async buildCss() { async buildCss() {
const elements = [...hiddenMessages].map(id => `#message-accessories-${id}`).join(","); const elements = [...hiddenMessages].map(id => `#message-accessories-${id}`).join(",");
style.textContent = ` setStyle({
:is(${elements}) :is([class*="embedWrapper"], [class*="clickableSticker"]) { name: "HideAttachments",
/* important is not necessary, but add it to make sure bad themes won't break it */ source: `
display: none !important; :is(${elements}) :is([class*="embedWrapper"], [class*="clickableSticker"]) {
} /* important is not necessary, but add it to make sure bad themes won't break it */
:is(${elements})::after { display: none !important;
content: "Attachments hidden"; }
color: var(--text-muted); :is(${elements})::after {
font-size: 80%; content: "Attachments hidden";
} color: var(--text-muted);
`; font-size: 80%;
}
`
});
}, },
async toggleHide(id: string) { async toggleHide(id: string) {