🧩
Plugin

MoreRoleColors

von HeadX

Adds role colors to usernames across Discord - including messages, voice channels, typing indicators, mentions, account area, text editor, audit log, role headers, user profiles, and tags

🏷️ v2.0.11 📦 44.6 KB 🗓️ 2.7.2026 📄 1076 Zeilen
⬇️ Download 📄 Raw ansehen 🌐 Source
Installation: Datei herunterladen und in deinen BetterDiscord-Ordner legen — %appdata%\\BetterDiscord\\plugins (Windows) bzw. über Discord: Einstellungen → Plugins → Plugin-Ordner öffnen.
MoreRoleColors.plugin.js · 1076 Zeilen · 44.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
/*
  FILE META START
  name: MoreRoleColors.plugin.js
  version: 0.0.10
  description: Multi-surface admin, cloud, bot host, login, and secure chat server.
  lastModified: 2026-05-04T20:22:59.642Z
  checksum: 1fc4cdee3aefd812f6cc7a9d5f1a27ddf820ed60c5383f8237da241a864a65d6
  FILE META END
*/

/**
 * @name MoreRoleColors
 * @author HeadX
 * @authorId 808385710700494919
 * @description Adds role colors to usernames across Discord - including messages, voice channels, typing indicators, mentions, account area, text editor, audit log, role headers, user profiles, and tags
 * @version 2.0.11
 * @invite J6wTJJ5fp
 * @website https://headcraft.cloud/better-discord
 * @source https://headcraft.cloud/better-discord/MoreRoleColors.plugin.js
 * @updateUrl https://headcraft.cloud/better-discord/MoreRoleColors.plugin.js
 */



const { Webpack, React, Patcher, ReactUtils, Utils } = BdApi;
const { getStore, getByStrings, getBySource, getWithKey, Filters, getModule } = Webpack;
const VoiceUser = getBySource("g4", "H", "getAvatarURL");
const GuildMemberStore = getStore("GuildMemberStore");
const SelectedGuildStore = getStore("SelectedGuildStore");
const RelationshipStore = getStore("RelationshipStore");
const TypingStore = getStore("TypingStore");
const TypingModule = getBySource('activityInviteEducationActivity')
const [MentionModule, key] = getWithKey(Filters.byStrings('USER_MENTION',"getNickname", "inlinePreview"));
const ChannelStore = getStore("ChannelStore");
const UserStore = getStore("UserStore");
const GuildStore = getStore("GuildStore");
const useStateFromStores = getModule(Webpack.Filters.byStrings("getStateFromStores"), { searchExports: true });
const GuildRoleStore = getStore("GuildRoleStore");

//types for changelog: added, fixed, improved, progress.
const config = {
    banner: "",
    changelog: [
        {
            "title": "2.0.10 - Fixed",
            "type": "fixed",
            "items": [
                "Fixed account area coloring not updating when switching servers under certain conditions",
                "Fixes for discord update"
            ]
        }
    ],
    settings: [
        {
            "type": "category",
            "id": "accountAreaColoring",
            "name": "Account Area",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "accountArea",
                    "name": "Enable Account Area Coloring",
                    "note": "Colors your username in the account area",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.accountArea ?? true
                },
                {
                    "type": "switch",
                    "id": "accountAreaGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to account area colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.accountAreaGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "auditLogColoring",
            "name": "Audit Log",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "auditLog",
                    "name": "Enable Audit Log Coloring",
                    "note": "Colors usernames in the audit log",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.auditLog ?? true
                },
                {
                    "type": "switch",
                    "id": "auditLogGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to audit log colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.auditLogGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "mentionsColoring",
            "name": "Mentions",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "mentions",
                    "name": "Enable Mentions Coloring",
                    "note": "Colors usernames in mentions",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.mentions ?? true
                },
                {
                    "type": "switch",
                    "id": "mentionsGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to mention colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.mentionsGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "messagesColoring",
            "name": "Messages",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "messages",
                    "name": "Enable Messages Coloring",
                    "note": "Colors users text by their role color",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.messages ?? true
                },
                {
                    "type": "switch",
                    "id": "messagesGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to message text colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.messagesGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "roleHeadersColoring",
            "name": "Role Headers",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "roleHeaders",
                    "name": "Enable Role Headers Coloring",
                    "note": "Colors usernames in role headers",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.roleHeaders ?? true
                },
                {
                    "type": "switch",
                    "id": "roleHeadersGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to role header colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.roleHeadersGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "serverProfileDisplayNameColoring",
            "name": "Server Profile Display Name",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "serverProfileDisplayName",
                    "name": "Enable Server Profile Display Name Coloring",
                    "note": "Colors display names in server profiles",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.serverProfileDisplayName ?? true
                },
                {
                    "type": "switch",
                    "id": "serverProfileDisplayNameGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to server profile display name colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.serverProfileDisplayNameGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "tagsColoring",
            "name": "Tags",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "Tags",
                    "name": "Enable Tags Coloring",
                    "note": "Colors tags to match role colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.Tags ?? true
                },
                {
                    "type": "switch",
                    "id": "TagsGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to tag colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.TagsGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "textEditorColoring",
            "name": "Text Editor",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "textEditor",
                    "name": "Enable Text Editor Coloring",
                    "note": "Colors mentions in the text editor",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.textEditor ?? true
                },
                {
                    "type": "switch",
                    "id": "textEditorGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to text editor colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.textEditorGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "typingUsersColoring",
            "name": "Typing Indicator",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "typingUsers",
                    "name": "Enable Typing Indicator Coloring",
                    "note": "Colors usernames in typing indicators",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.typingUsers ?? true
                },
                {
                    "type": "switch",
                    "id": "typingUsersGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to typing indicator colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.typingUsersGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "userProfileColoring",
            "name": "User Profile",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "userProfile",
                    "name": "Enable User Profile Coloring",
                    "note": "Colors usernames in user profiles",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.userProfile ?? true
                },
                {
                    "type": "switch",
                    "id": "userProfileGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to user profile colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.userProfileGradient ?? true
                }
            ]
        },
        {
            "type": "category",
            "id": "voiceUsersColoring",
            "name": "Voice Users",
            "collapsible": true,
            "shown": false,
            "settings": [
                {
                    "type": "switch",
                    "id": "voiceUsers",
                    "name": "Enable Voice Users Coloring",
                    "note": "Colors usernames in voice channels",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.voiceUsers ?? true
                },
                {
                    "type": "switch",
                    "id": "speakingIndicator",
                    "name": "Enable Speaking Indicator",
                    "note": "Changes opacity of voice usernames when speaking",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.speakingIndicator ?? false
                },
                {
                    "type": "switch",
                    "id": "voiceUsersGradient",
                    "name": "Use Gradient Coloring",
                    "note": "Apply gradient effect to voice user colors",
                    "value": BdApi.Data.load('MoreRoleColors', 'settings')?.voiceUsersGradient ?? true
                }
            ]
        }
    ]
};
module.exports = class MoreRoleColors {
    constructor(meta) {
        this.meta = meta;
        this.defaultSettings = {
            voiceUsers: true,
            voiceUsersGradient: true,
            speakingIndicator: false,
            typingUsers: true,
            typingUsersGradient: true,
            mentions: true,
            mentionsGradient: true,
            accountArea: true,
            accountAreaGradient: true,
            textEditor: true,
            textEditorGradient: true,
            auditLog: true,
            auditLogGradient: true,
            roleHeaders: true,
            roleHeadersGradient: true,
            messages: false,
            messagesGradient: false,
            userProfile: true,
            userProfileGradient: true,
            serverProfileDisplayName: true,
            serverProfileDisplayNameGradient: true,
            Tags: true
        };
        this.settings = this.loadSettings();
    }

    start() {
        const lastVersion = BdApi.Data.load('MoreRoleColors', 'lastVersion');
        if (lastVersion !== this.meta.version) {
            BdApi.UI.showChangelogModal({
                title: this.meta.name,
                subtitle: this.meta.version,
                banner: config.banner,
                changes: config.changelog
            });
            BdApi.Data.save('MoreRoleColors', 'lastVersion', this.meta.version);
        }

        if (this.settings.voiceUsers) this.patchVoiceUsers();
        if (this.settings.typingUsers) this.patchTypingUsers();
        if (this.settings.mentions) this.patchMentions();
        if (this.settings.accountArea) this.patchAccountArea();
        if (this.settings.textEditor) this.patchTextEditor();
        if (this.settings.auditLog) this.patchAuditLog();
        if (this.settings.roleHeaders) this.patchRoleHeaders();
        if (this.settings.messages) this.patchMessages();
        if (this.settings.userProfile) this.patchUserProfile();
        if (this.settings.Tags) this.patchTags();
        if (this.settings.serverProfileDisplayName) this.patchServerProfileDisplayName();
        this.forceUpdateComponents();
    }

    loadSettings() {
        return { ...this.defaultSettings, ...BdApi.Data.load('MoreRoleColors', 'settings') };
    }

    saveSettings(newSettings) {
        this.settings = newSettings;
        BdApi.Data.save('MoreRoleColors', 'settings', newSettings);
    }

    getSettingsPanel() {
        config.settings.forEach(category => {
            if (category.settings) {
                category.settings.forEach(setting => {
                    setting.value = this.settings[setting.id];
                });
            }
        });

        return BdApi.UI.buildSettingsPanel({
            settings: config.settings,
            onChange: (category, id, value) => {
                const newSettings = { ...this.settings, [id]: value };
                this.saveSettings(newSettings);
                
                if (value) {
                    switch (id) {
                        case 'voiceUsers': this.patchVoiceUsers(); break;
                        case 'typingUsers': this.patchTypingUsers(); break;
                        case 'mentions': this.patchMentions(); break;
                        case 'accountArea': this.patchAccountArea(); break;
                        case 'textEditor': this.patchTextEditor(); break;
                        case 'auditLog': this.patchAuditLog(); break;
                        case 'roleHeaders': this.patchRoleHeaders(); break;
                        case 'messages': this.patchMessages(); break;
                        case 'userProfile': this.patchUserProfile(); break;
                        case 'Tags': this.patchTags(); break;
                        case 'serverProfileDisplayName': this.patchServerProfileDisplayName(); break;
                    }
                } else {
                    if (id === 'serverProfileDisplayName') {
                        Patcher.unpatchAll("MoreRoleColors-ServerProfileDisplayName");
                        Patcher.unpatchAll("MoreRoleColors-ServerProfileGuildSelector");
                    } else {
                        Patcher.unpatchAll(`MoreRoleColors-${id}`);
                    }
                    if (id === 'accountArea' && this._unpatchAccountArea) {
                        this._unpatchAccountArea();
                    }
                }

                this.forceUpdateComponents();
            }
        });
    }

    stop() {
        Patcher.unpatchAll("MoreRoleColors-voiceUsers");
        Patcher.unpatchAll("MoreRoleColors-typingUsers");
        Patcher.unpatchAll("MoreRoleColors-mentions");
        Patcher.unpatchAll("MoreRoleColors-accountArea");
        Patcher.unpatchAll("MoreRoleColors-textEditor");
        Patcher.unpatchAll("MoreRoleColors-auditLog");
        Patcher.unpatchAll("MoreRoleColors-roleHeaders");
        Patcher.unpatchAll("MoreRoleColors-messages");
        Patcher.unpatchAll("MoreRoleColors-ServerProfileDisplayName");
        Patcher.unpatchAll("MoreRoleColors-ServerProfileGuildSelector");
        Patcher.unpatchAll("MoreRoleColors-userProfile");
        if (this._unpatchAccountArea) this._unpatchAccountArea();
        if (this._unpatchUserProfile) this._unpatchUserProfile();
        if (this._unpatchTags) this._unpatchTags();
        this.forceUpdateComponents();
    }

    onSwitch() {
        if (this.settings.accountArea) this.patchAccountArea();
    }

    forceUpdateComponents() {
        const voiceUsers = Array.from(document.querySelectorAll("[class^=voiceUser_]"), m => BdApi.ReactUtils.getOwnerInstance(m, { filter: m=> !m?.renderInner }).forceUpdate());
        const accountArea = document.querySelectorAll("[class^=avatarWrapper_]");
        const typingUsers = document.querySelectorAll("[class^=channelBottomBarArea_]");
        for (const node of voiceUsers) {
            ReactUtils.getOwnerInstance(node)?.forceUpdate();
        }
        for (const node of accountArea) {
            ReactUtils.getOwnerInstance(node, { filter: m => m.renderNameTag })?.forceUpdate();
        }
        for (const node of typingUsers) {
            ReactUtils.getOwnerInstance(node, { filter: m => m.typingUsers })?.forceUpdate();
        }
    }

    applyRoleStyle(element, colorObject, type) {
        if (!type) {
            element.style = {color: colorObject.colorString};
            return;
        }
        if (!GuildStore.getGuild(SelectedGuildStore.getGuildId())?.features?.has?.("ENHANCED_ROLE_COLORS")) {
            element.style = {color: colorObject.colorString};
            return;
        }
        
        if (colorObject.colorStrings && colorObject.colorStrings.primaryColor && colorObject.colorStrings.secondaryColor) {
            let gradient;
            if (colorObject.colorStrings.tertiaryColor) {
                gradient = `linear-gradient(to right, ${colorObject.colorStrings.primaryColor} 0%, ${colorObject.colorStrings.secondaryColor} 50%, ${colorObject.colorStrings.tertiaryColor} 100%)`;
            } else {
                gradient = `linear-gradient(to right, ${colorObject.colorStrings.primaryColor} 0%, ${colorObject.colorStrings.secondaryColor} 100%)`;
            }

            element.style = {
                color: "unset",
                background: `${gradient} text`,
                WebkitBackgroundClip: "text",
                WebkitTextFillColor: "transparent"
            };
        } else {
            element.style = {
                color: colorObject.colorString,
                background: "none",
                backgroundClip: "unset",
                WebkitBackgroundClip: "unset",
                WebkitTextFillColor: "unset"
            };
        }
    }

    getColorObjectForMember(guildId, member) {
        if (member.colorStrings) {
            return member;
        }

        const roles = Object.values(GuildRoleStore.getRolesSnapshot(guildId));
        const matchingRole = roles.find(role => role.colorString === member.colorString);

        return matchingRole || member;
    }
    
    patchVoiceUsers() {
        Patcher.after("MoreRoleColors-voiceUsers", VoiceUser, "Ay", (_, [props], res) => {
            if (!res?.props) return;
            
            const guildId = SelectedGuildStore.getGuildId();
            const member = GuildMemberStore.getMember(guildId, props?.user?.id);
            if (!member?.colorString) return;

            const usernameElement = Utils.findInTree(res, x => x?.className?.includes('usernameFont'), {
                walkable: ['props', 'children']
            });
            if (!usernameElement) return;
            
            const colorObject = this.getColorObjectForMember(guildId, member);
            this.applyRoleStyle(usernameElement, colorObject, this.settings.voiceUsersGradient);
            
            const isSpeaking = props?.speaking;
            if (this.settings.speakingIndicator && !isSpeaking) {
                usernameElement.style.opacity = "0.56";
            }
            
            usernameElement.style.backfaceVisibility = "hidden";
        });
    }

    patchTypingUsers() {        
        const cache = new WeakMap();
        const pluginInstance = this;

        Patcher.after("MoreRoleColors-typingUsers", TypingModule, "Ay", (that, args, res) => {
            let newType = cache.get(res.type);

            if (!newType) {
                const target = res.type;

                newType = function(props) {
                    const channelId = props.channel?.id;
                    const typingUsersStore = useStateFromStores([TypingStore], () => 
                        TypingStore.getTypingUsers(channelId)
                    );

                    const res = target.apply(this, arguments);

                    const typingUsers = Object.keys(typingUsersStore)
                        .filter(e => e != UserStore.getCurrentUser().id)
                        .filter(e => !RelationshipStore.isBlockedOrIgnored(e))
                        .map(e => UserStore.getUser(e))
                        .filter(e => e != null);

                    const typing = Utils.findInTree(res, (node) => node?.className?.includes("typingDots"), {
                        walkable: ["props", "children"]
                    });

                    if (typing && typeof typing?.children?.[1]?.props?.children !== "string") {
                        const validUserIds = typingUsers.map(u => u.id);

                        if (validUserIds.length <= 3) {
                            let count = 0;
                            typing.children[1].props.children = typing.children[1].props.children.map((m, i) => {
                                if (typeof m === "string") return m;
                                
                                const member = GuildMemberStore.getMember(props.guildId, validUserIds[count++]);
                                let elementStyle = {};
                                
                                if (member?.colorString) {
                                    const colorObject = pluginInstance.getColorObjectForMember(props.guildId, member);
                                    const tempElement = { style: {} };
                                    pluginInstance.applyRoleStyle(tempElement, colorObject, pluginInstance.settings.typingUsersGradient);
                                    elementStyle = tempElement.style;
                                }
                                
                                return React.createElement("strong", {
                                    key: i,
                                    children: m.props.children,
                                    style: elementStyle
                                });
                            });
                        }
                    }

                    return res;
                }

                cache.set(res.type, newType);
                cache.set(newType, newType);
            }

            res.type = newType;
        });
    }

    patchMentions() {
        Patcher.after("MoreRoleColors-mentions", MentionModule, key, (_, [props], res) => {
            if (!props?.userId || !res?.props?.children?.props) return res;

            const guildId = (() => {
                if (!BdApi.Plugins.isEnabled("PingNotification")) return SelectedGuildStore.getGuildId();
                
                let element = document.activeElement;
                while (element && !element.classList.contains('ping-notification')) {
                    element = element.parentElement;
                }
                
                if (element) {
                    const channelId = element.getAttribute('data-channel-id');
                    if (channelId) {
                        const channel = ChannelStore.getChannel(channelId);
                        if (channel?.guild_id) return channel.guild_id;
                    }
                }
                
                if (props.channelId) {
                    const channel = ChannelStore.getChannel(props.channelId);
                    if (channel?.guild_id) return channel.guild_id;
                    if (!channel?.guild_id) return;
                }
                
                return SelectedGuildStore.getGuildId();
            })();

            if (!guildId) return res;
            
            const member = GuildMemberStore.getMember(guildId, props.userId);
            if (!member?.colorString) return res;

            const colorObject = this.getColorObjectForMember(guildId, member);
            
            const original = res.props.children.props.children;
            res.props.children.props.children = (props, context) => {
                const ret = original(props, context);
                if (ret?.props) {
                    ret.props.color = parseInt(member.colorString.slice(1), 16);
                    
                    if (this.settings.mentionsGradient && 
                        GuildStore.getGuild(guildId)?.features?.has?.("ENHANCED_ROLE_COLORS") &&
                        colorObject.colorStrings && 
                        colorObject.colorStrings.primaryColor && colorObject.colorStrings.secondaryColor) {
                        ret.props.roleColors = {
                            primaryColor: colorObject.colorStrings.primaryColor,
                            secondaryColor: colorObject.colorStrings.secondaryColor,
                            tertiaryColor: colorObject.colorStrings.tertiaryColor || null
                        };
                    }
                }
                
                return ret;
            };

            return res;
        });
    }

    patchAccountArea() {
        const cache = new WeakMap();
        const MAX_RETRIES = 10;
        
        const patchAccountAreaWithRetry = (attempts = 0) => {
            if (attempts >= MAX_RETRIES) {
                return;
            }

            const accountArea = document.querySelector("[class^=avatarWrapper_]");
            if (!accountArea) {
                setTimeout(() => patchAccountAreaWithRetry(attempts + 1), 1000);
                return;
            }

            const owner = ReactUtils.getOwnerInstance(accountArea, { filter: m => m.renderNameTag });
            if (!owner) {
                setTimeout(() => patchAccountAreaWithRetry(attempts + 1), 1000);
                return;
            }

            const renderNameTag = owner.renderNameTag;
            const pluginInstance = this;
            owner.renderNameTag = function() {
                const res = renderNameTag.call(this);
                const type = res.props.children[0].props.children.type;

                if (type.__MoreRoleColors) return res;

                let component = cache.get(type);
                if (!component) {          
                    component = new Proxy(type, {
                        apply: (target, thisArg, argArray) => {
                            const res = Reflect.apply(target, thisArg, argArray);
                            const guildId = SelectedGuildStore.getGuildId();
                            const member = GuildMemberStore.getMember(
                                guildId, 
                                this.props?.currentUser?.id || UserStore.getCurrentUser()?.id
                            );
                            
                            if (member?.colorString) {
                                const colorObject = pluginInstance.getColorObjectForMember(guildId, member);
                                const tempElement = { style: {} };
                                pluginInstance.applyRoleStyle(tempElement, colorObject, pluginInstance.settings.accountAreaGradient);
                                res.props.style = tempElement.style;
                            }
                            
                            return res;
                        },
                        get(target, key, receiver) {
                            if (key === "__MoreRoleColors") return true;
                            return Reflect.get(target, key, receiver);
                        }
                    });            
                    cache.set(type, component);
                }

                res.props.children[0].props.children.type = component;
                return res;
            }.bind(owner);

            this._unpatchAccountArea = () => {
                owner.renderNameTag = renderNameTag;
            };
            owner.forceUpdate();
        };

        patchAccountAreaWithRetry();
    }

    patchTextEditor() {
        const [ module, key ] = BdApi.Webpack.getWithKey(BdApi.Webpack.Filters.byStrings(".hidePersonalInformation", "#", "<@", ".discriminator"));
        const pluginInstance = this;
        BdApi.Patcher.after("MoreRoleColors-textEditor", module, key, (that, [{ id, guildId }], res) => {
            const member = GuildMemberStore.getMember(guildId, id);
            if (!member?.colorString) return res;

            const colorObject = pluginInstance.getColorObjectForMember(guildId, member);
            const color = parseInt(member.colorString.slice(1), 16);
            const innerMention = res.props.children?.props?.children;
            
            if (!innerMention?.props) return res;
            
            return BdApi.React.cloneElement(res, {
                children: BdApi.React.cloneElement(res.props.children, {
                    children: BdApi.React.cloneElement(innerMention, {
                        ...innerMention.props,
                        color,
                        ...(pluginInstance.settings.textEditorGradient && 
                            GuildStore.getGuild(guildId)?.features?.has?.("ENHANCED_ROLE_COLORS") &&
                            colorObject.colorStrings?.primaryColor && colorObject.colorStrings?.secondaryColor && {
                                roleColors: {
                                    primaryColor: colorObject.colorStrings.primaryColor,
                                    secondaryColor: colorObject.colorStrings.secondaryColor,
                                    tertiaryColor: colorObject.colorStrings.tertiaryColor || null
                                }
                            })
                    })
                })
            });
        }); 
    }

    patchAuditLog() {
        let AuditLogUser;
        const pluginInstance = this;

        function patchAuditLogUser() {
            BdApi.Patcher.after("MoreRoleColors-auditLog", AuditLogUser.prototype, "render", (that, args, res) => {
                const member = GuildMemberStore.getMember(SelectedGuildStore.getGuildId(), that.props.user.id);

                if (!member?.colorString) return;
                
                if (res.props?.children?.[0]?.props) {
                    const colorObject = pluginInstance.getColorObjectForMember(SelectedGuildStore.getGuildId(), member);
                    const tempElement = { style: {} };
                    pluginInstance.applyRoleStyle(tempElement, colorObject, pluginInstance.settings.auditLogGradient);
                    res.props.children[0].props.style = tempElement.style;
                }
            });
        }

        function attemptPatchAuditLogUser() {
            if (AuditLogUser) {
                patchAuditLogUser();
                return;
            }
            
            const undo = BdApi.Patcher.after("MoreRoleColors-auditLog-temp", BdApi.Webpack.getModule(m => m.displayName === "ForwardRef(FluxContainer(GuildSettingsAuditLogEntry))"), "render", (that, [props], res) => { 
                undo();
                
                const a = res?.type?.prototype?.render?.call({
                    props: res.props,
                    memoizedGetStateFromStores: () => ({
                        theme: "dark"
                    })
                });

                const { render } = a.type;
                a.type = {
                    ...a.type,
                    render() {
                        const ret = render.apply(this, arguments);

                        const undo = BdApi.Patcher.after("MoreRoleColors-auditLog-temp2", ret.props, "children", (that, args, res) => {
                            undo();

                            const node = BdApi.Utils.findInTree(res, (m) => m?.type?.prototype?.render && m.props.user?.id, {
                                walkable: [ "children", "props" ]
                            });

                            if (node?.type) {
                                AuditLogUser = node.type;
                                patchAuditLogUser();
                            }
                        });
                        
                        return ret;
                    }
                }

                return a;
            });
        }

        BdApi.Webpack.waitForModule(m => m.displayName === "ForwardRef(FluxContainer(GuildSettingsAuditLogEntry))").then(() => {
            attemptPatchAuditLogUser();
        });
    }

    patchRoleHeaders() {
        const roleHeaderModule = BdApi.Webpack.getBySource(/,.{1,3}.kL,.{1,3}.wx\)/)
        BdApi.Patcher.after("MoreRoleColors-roleHeaders", roleHeaderModule, "A", (_, [props], res) => {
            let roleNameArea = Utils.findInTree(res, (m) => m?.className?.includes('membersGroupName'))
            if (roleNameArea) {
                const guildId = SelectedGuildStore.getGuildId();
                const roles = Object.values(GuildRoleStore.getRolesSnapshot(guildId));

                let roleName = roleNameArea.children;
                let role = roles.find(r => r.name === roleName);
                if (role) {
                    this.applyRoleStyle(res.props.children[1].props, role, this.settings.roleHeadersGradient);
                } else {
                    roleName = res.props.children[1].props.children[1];
                    role = roles.find(r => r.name === roleName);
                    if (role) {
                        this.applyRoleStyle(res.props.children[1].props, role, this.settings.roleHeadersGradient);
                    }
                }
            }
        }); 
    }

    patchMessages() {
        const MessageContentMRC = BdApi.Webpack.getModule((m) => 
            m?.type?.toString?.()?.includes("BK") && 
            m?.type?.toString?.()?.includes("w3")
        );
        BdApi.Patcher.after("MoreRoleColors-messages", MessageContentMRC, "type", (_, [props], res) => {
            if (!props?.message?.author?.id) return res;
            
            const guildId = SelectedGuildStore.getGuildId();
            if (!guildId) return res;

            const member = GuildMemberStore.getMember(guildId, props.message.author.id);
            if (member?.colorString) {
                const colorObject = this.getColorObjectForMember(guildId, member);
                
                const hasCodeBlock = Array.isArray(res?.props?.children?.[0]) && 
                    res.props.children[0].some(child => child?.type === 'pre');
                const isCompact = props?.compact === true;
                const useGradient = this.settings.messagesGradient && !(isCompact && hasCodeBlock);
                
                if (!res.props.style) res.props.style = {};
                const tempElement = { style: {} };
                this.applyRoleStyle(tempElement, colorObject, useGradient);
                Object.assign(res.props.style, tempElement.style);
            }

            return res;
        });
    }

    patchUserProfile() {
        const UserProfileModule = BdApi.Webpack.getByStrings("displayProfile", "hasAvatarForGuild", { defaultExport: false });
        const cache = new WeakMap();
        const pluginInstance = this;

        const GuildMemberStore = BdApi.Webpack.getStore("GuildMemberStore");

        BdApi.Patcher.after("MoreRoleColors-userProfile", UserProfileModule, "A", (_, [props], res) => {
            const profileComponent = res.props.children[1];

            let newType = cache.get(profileComponent.type);
            if (!newType) {            
                newType = new Proxy(profileComponent.type, {
                    apply: (target, thisArg, args) => {
                        const res = Reflect.apply(target, thisArg, args);

                        const displayProfile = args[0].tags.props.displayProfile;

                        const member = GuildMemberStore.getMember(displayProfile?.guildId, displayProfile?.userId);

                        if (!res?.props) return res;

                        const userObject = BdApi.Utils.findInTree(res,x=>x?.className?.includes('nickname'), {walkable: ['props','children']})
                        if (!userObject) return res;
                        
                        if (member?.colorString) {
                            const colorObject = pluginInstance.getColorObjectForMember(displayProfile?.guildId, member);
                            const tempElement = { style: {} };
                            pluginInstance.applyRoleStyle(tempElement, colorObject, pluginInstance.settings.userProfileGradient);
                            
                            if (!userObject?.style) {
                                Object.defineProperty(userObject, "style", {
                                    value: tempElement.style,
                                    writable: true,
                                    enumerable: true,
                                    configurable: true
                                });
                            } else {
                                Object.assign(userObject.style, tempElement.style);
                            }
                        }

                        return res;
                    }
                });

                cache.set(profileComponent.type, newType);
                cache.set(newType, newType);
            }

            profileComponent.type = newType;
            return res;
        });
    }

    patchTags() {
        const TagModule = BdApi.Webpack.getByStrings(".BOT", ".ORIGINAL_POSTER", { defaultExport: false });

        function hexToRgb(hex) {
            hex = hex.replace(/^#/, "");
            if (hex.length === 3) {
                hex = hex.split("").map(x => x + x).join("");
            }
            const num = parseInt(hex, 16);
            return `rgb(${(num >> 16) & 255}, ${(num >> 8) & 255}, ${num & 255})`;
        }

        class TagWrapper extends BdApi.React.Component {
            constructor(props) {
                super(props);
                this.tagRef = BdApi.React.createRef();
            }

            componentDidMount() {
                const node = this.tagRef.current;
                if (!node) return;
                if (!node.parentElement) return;
                const username = node.parentElement.querySelector("[class*=username]");
                if (!username) return;

                const style = username.querySelector("[style]") || username;
                let backgroundColor = style?.style?.color;

                if (!backgroundColor) {
                    const computed = window.getComputedStyle(style);
                    let gradientColor = computed.getPropertyValue("--custom-gradient-color-1")?.trim();
                    if (gradientColor) {
                        if (gradientColor.startsWith("#")) {
                            backgroundColor = hexToRgb(gradientColor);
                        } else if (gradientColor.startsWith("rgb")) {
                            backgroundColor = gradientColor;
                        }
                    }
                }

                if (!backgroundColor) return;

                node.style.backgroundColor = backgroundColor;
                const contrast = this.getContrastingColor(backgroundColor);
                
                node.style.color = contrast;
                
                const svgElements = node.querySelectorAll("svg");
                svgElements.forEach((svg) => {
                    const paths = svg.querySelectorAll("path");
                    paths.forEach((path) => {
                        path.style.fill = contrast;
                    });
                });
                
                const tagTextSpans = node.querySelectorAll("span");
                tagTextSpans.forEach((span) => {
                    span.style.color = contrast;
                });
            }

            getContrastingColor(color) {
                let r, g, b;
                if (color.startsWith('#')) {
                    const hex = color.substring(1);
                    r = parseInt(hex.substring(0, 2), 16);
                    g = parseInt(hex.substring(2, 4), 16);
                    b = parseInt(hex.substring(4, 6), 16);
                } else if (color.startsWith('rgb')) {
                    const rgbValues = color.match(/\d+/g);
                    if (rgbValues && rgbValues.length >= 3) {
                        r = parseInt(rgbValues[0]);
                        g = parseInt(rgbValues[1]);
                        b = parseInt(rgbValues[2]);
                    } else {
                        return "#000000";
                    }
                } else {
                    return "#000000";
                }

                const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
                return luminance > 0.5 ? "#000000" : "#FFFFFF";
            }

            render() {
                if (!this.props.tag) return null;
                return BdApi.React.cloneElement(this.props.tag, { ref: this.tagRef });
            }
        }

        Patcher.after("MoreRoleColors-Tags", TagModule, "A", (_, args, res) => {
            return BdApi.React.createElement(TagWrapper, { tag: res });
        });

        this._unpatchTags = () => {
            Patcher.unpatchAll("MoreRoleColors-Tags");
        };
    }

    patchServerProfileDisplayName() {
        BdApi.UI.showToast("server profile disabled. will fix later.");
    //     const ServerProfileGuildSelector = BdApi.Webpack.getBySource(".getFlattenedGuildIds", ".getGuilds", "A", "Sizes.SMOL", { defaultExport: false });
    //     console.log("MRC", ServerProfileGuildSelector);
    //     let currentProfileGuildId = null;
    //     const pluginInstance = this;

    //     Patcher.after("MoreRoleColors-ServerProfileGuildSelector", ServerProfileGuildSelector, "A", (_, [props], res) => {
    //         console.log("selector",res)
    //         currentProfileGuildId = res.props.children.props.guildId;
    //         return res;
    //     });

    //     BdApi.Webpack.waitForModule((e, m) => 
    //         BdApi.Webpack.modules[m.id]?.toString?.()?.includes(".isVerifiedBot", "forceUsername:!0")
    //     ).then(ServerProfileDisplayNameModule => {
    //         console.log("MRC2", ServerProfileDisplayNameModule);
    //         Patcher.after("MoreRoleColors-ServerProfileDisplayName", ServerProfileDisplayNameModule.A, "type", (_, [props], res) => {          
    //             console.log("displayname",res);
    //             const target = res.props.children[0].props.children[0].props;
    //             const currentUser = UserStore.getCurrentUser();
    //             const member = GuildMemberStore.getMember(currentProfileGuildId, currentUser.id);
                
    //             if (member?.colorString) {
    //                 const colorObject = pluginInstance.getColorObjectForMember(currentProfileGuildId, member);
    //                 const tempElement = { style: {} };
    //                 pluginInstance.applyRoleStyle(tempElement, colorObject, pluginInstance.settings.serverProfileDisplayNameGradient);
    //                 target.style = tempElement.style;
    //             }
                
    //             return res;
    //         });

    //     });
    }
}
← Alle Plugins & Themes index.json headcraft.cloud