From 1d8ea48530e69097280900486a3a2cef17f303a4 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:23:12 -0400 Subject: [PATCH] BannersEverywhere --- .../bannersEverywhere/index.css | 10 ++ .../bannersEverywhere/index.tsx | 93 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/equicordplugins/bannersEverywhere/index.css create mode 100644 src/equicordplugins/bannersEverywhere/index.tsx diff --git a/src/equicordplugins/bannersEverywhere/index.css b/src/equicordplugins/bannersEverywhere/index.css new file mode 100644 index 000000000..bc875ba5b --- /dev/null +++ b/src/equicordplugins/bannersEverywhere/index.css @@ -0,0 +1,10 @@ +/* stylelint-disable property-no-vendor-prefix */ +.vc-banners-everywhere-memberlist { + opacity: 0.8; + -webkit-mask-image: linear-gradient(to right, transparent 20%, #fff); + mask-image: linear-gradient(to right, transparent 20%, #fff); + width: 100%; + height: 100%; + position: absolute; + cursor: pointer; +} diff --git a/src/equicordplugins/bannersEverywhere/index.tsx b/src/equicordplugins/bannersEverywhere/index.tsx new file mode 100644 index 000000000..dc345220e --- /dev/null +++ b/src/equicordplugins/bannersEverywhere/index.tsx @@ -0,0 +1,93 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import * as DataStore from "@api/DataStore"; +import { definePluginSettings } from "@api/Settings"; +import { disableStyle, enableStyle } from "@api/Styles"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType, Plugin } from "@utils/types"; +import { findStoreLazy } from "@webpack"; +import { User } from "discord-types/general"; + +import style from "./index.css?managed"; + +interface iUSRBG extends Plugin { + data: { [key: string]: string; }; +} + +const settings = definePluginSettings({ + animate: { + description: "Animate banners", + type: OptionType.BOOLEAN, + default: false + }, +}); + +const DATASTORE_KEY = "bannersEverywhere"; + +const UserProfileStore = findStoreLazy("UserProfileStore"); + + +export default definePlugin({ + name: "BannersEverywhere", + description: "Displays banners in the member list ", + authors: [Devs.ImLvna, Devs.AutumnVN], + settings, + patches: [ + { + find: ".Messages.GUILD_OWNER,", + replacement: + { + // We add the banner as a property while we can still access the user id + match: /verified:(\i).isVerifiedBot.*?name:null.*?(?=avatar:)/, + replace: "$&banner:$self.memberListBannerHook($1),", + }, + }, + { + find: "role:\"listitem\",innerRef", + replacement: + { + // We cant access the user id here, so we take the banner property we set earlier + match: /let{avatar:\i.*?focusProps:\i.*?=(\i).*?children:\[/, + replace: "$&$1.banner," + } + } + ], + + data: {}, + + async start() { + enableStyle(style); + this.data = await DataStore.get(DATASTORE_KEY) || {}; + }, + + stop() { + disableStyle(style); + DataStore.set(DATASTORE_KEY, this.data); + }, + + memberListBannerHook(user: User) { + let url = this.getBanner(user.id); + if (!url) return; + if (!settings.store.animate) url = url.replace(".gif", ".png"); + + return ( + + ); + }, + + getBanner(userId: string): string | undefined { + if (Vencord.Plugins.isPluginEnabled("USRBG") && (Vencord.Plugins.plugins.USRBG as iUSRBG).data[userId]) { + return (Vencord.Plugins.plugins.USRBG as iUSRBG).data[userId]; + } + const userProfile = UserProfileStore.getUserProfile(userId); + if (userProfile?.banner) { + this.data[userId] = `https://cdn.discordapp.com/banners/${userId}/${userProfile.banner}.${userProfile.banner.startsWith("a_") ? "gif" : "png"}`; + DataStore.set(DATASTORE_KEY, this.data); + } + return this.data[userId]; + }, +});