Equicord/src/plugins/themeAttributes/index.ts
thororen1234 ca4b63c386
Visual Refresh
Co-Authored-By: sadan4 <117494111+sadan4@users.noreply.github.com>
Co-Authored-By: doyle31 <abacubabacus@gmail.com>
Co-Authored-By: iilwy <iilwy@omg.games>
Co-Authored-By: Noa <164402463+nroggendorff@users.noreply.github.com>
Co-Authored-By: rini c <rini@rinici.de>
Co-Authored-By: Cassie <37855219+codef53@users.noreply.github.com>
Co-Authored-By: jamesbt365 <moxy@mothoxi.de>
Co-Authored-By: khcrysalis <97859147+khcrysalis@users.noreply.github.com>
Co-Authored-By: nin0dev <75569739+nin0-dev@users.noreply.github.com>
2025-03-31 17:36:21 -04:00

77 lines
2.4 KiB
TypeScript

/*
* 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, Devs.Board],
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])"
}
},
// add --avatar-url-<resolution> css variable to avatar img elements
// popout profiles
{
find: "#{intl::LABEL_WITH_ONLINE_STATUS}",
replacement: {
match: /src:null!=\i\?(\i).{1,50}"aria-hidden":!0/,
replace: "$&,style:$self.getAvatarStyles($1)"
}
},
// chat avatars
{
find: "showCommunicationDisabledStyles",
replacement: {
match: /src:(\i),"aria-hidden":!0/,
replace: "$&,style:$self.getAvatarStyles($1)"
}
}
],
getAvatarStyles(src: string | null) {
if (src == null || src.startsWith("data:")) return {};
return Object.fromEntries(
[128, 256, 512, 1024, 2048, 4096].map(size => [
`--avatar-url-${size}`,
`url(${src.replace(/\d+$/, String(size))})`
])
);
},
getMessageProps(props: { message: Message; }) {
const author = props.message?.author;
const authorId = author?.id;
return {
"data-author-id": authorId,
"data-author-username": author?.username,
"data-is-self": authorId && authorId === UserStore.getCurrentUser()?.id,
};
}
});