aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/themeAttributes/index.ts
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-08-31 01:49:53 +0200
committerGitHub <noreply@github.com>2023-08-31 01:49:53 +0200
commit0b7c0e958772d4204ad286f0c09fff0add1f1f2d (patch)
tree3ecae4ea95c7f3a84118c731dbf110352143eccb /src/plugins/themeAttributes/index.ts
parentd88524e8cf3a61e3399e049f615fa5d28d66693f (diff)
downloadVencord-0b7c0e958772d4204ad286f0c09fff0add1f1f2d.tar.gz
Vencord-0b7c0e958772d4204ad286f0c09fff0add1f1f2d.tar.bz2
Vencord-0b7c0e958772d4204ad286f0c09fff0add1f1f2d.zip
new plugin: themeAttributes (#1686)
Diffstat (limited to 'src/plugins/themeAttributes/index.ts')
-rw-r--r--src/plugins/themeAttributes/index.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/plugins/themeAttributes/index.ts b/src/plugins/themeAttributes/index.ts
new file mode 100644
index 0000000..8afc212
--- /dev/null
+++ b/src/plugins/themeAttributes/index.ts
@@ -0,0 +1,45 @@
+/*
+ * Vencord, a Discord client mod
+ * Copyright (c) 2023 Vendicated and contributors
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+import { Devs } from "@utils/constants";
+import definePlugin from "@utils/types";
+import { UserStore } from "@webpack/common";
+import { Message } from "discord-types/general";
+
+export default definePlugin({
+ name: "ThemeAttributes",
+ description: "Adds data attributes to various elements for theming purposes",
+ authors: [Devs.Ven],
+
+ patches: [
+ // Add data-tab-id to all tab bar items
+ // This for examples applies to the User and Server settings sidebars
+ {
+ find: ".tabBarRef",
+ replacement: {
+ match: /style:this\.getStyle\(\),role:"tab"/,
+ replace: "$&,'data-tab-id':this.props.id"
+ }
+ },
+
+ // Add data-author-id and data-is-self to all messages
+ {
+ find: ".messageListItem",
+ replacement: {
+ match: /\.messageListItem(?=,"aria)/,
+ replace: "$&,...$self.getMessageProps(arguments[0])"
+ }
+ }
+ ],
+
+ getMessageProps(props: { message: Message; }) {
+ const authorId = props.message?.author?.id;
+ return {
+ "data-author-id": authorId,
+ "data-is-self": authorId && authorId === UserStore.getCurrentUser()?.id
+ };
+ }
+});