🧩
Plugin

BetterChatNames

von Break

Improves chat names by automatically capitalising them and/or removing dashes/underscores

🏷️ v1.9.0 📦 9.3 KB 🗓️ 4.5.2026 📄 249 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.
BetterChatNames.plugin.js · 249 Zeilen · 9.3 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
/*
  FILE META START
  name: BetterChatNames.plugin.js
  version: 0.0.10
  description: Multi-surface admin, cloud, bot host, login, and secure chat server.
  lastModified: 2026-05-04T20:22:59.632Z
  checksum: 7bd5f94014cb0e8f9ee893f79f74568504d9981798fe3fc4f68a0bea6841324d
  FILE META END
*/

/**
 * @name BetterChatNames
 * @author Break
 * @description Improves chat names by automatically capitalising them and/or removing dashes/underscores
 * @version 1.9.0
 * @invite J6wTJJ5fp
 * @website https://github.com/Break-Ben/BetterDiscordAddons
 * @source https://github.com/Break-Ben/BetterDiscordAddons/tree/main/BetterChatNames
 * @updateUrl https://raw.githubusercontent.com/Break-Ben/BetterDiscordAddons/main/BetterChatNames/BetterChatNames.plugin.js
 */



const defaultSettings = {
    capitalise: true,
    removeDashes: true,
    removeEmojis: false,
    patchUnrestricted: true,
    capitalOverrides: 'and, or, of, the, for, to, at, a, FAQ, VC, GitHub'
}

const unrestrictedChannels = {
    voice: 2,
    thread: 11,
    stage: 13
}
const regex = {
    dash: /-|_/g,
    capital: /(?<=(^|[^\p{L}'’]))\p{L}/gu,
    word: /\b\p{L}+\b/gu,
    emoji: /([-_]?\p{Extended_Pictographic}[-_┃]?)|(\uFE0F\u20E3)/gu
}

let titleObserver
const { Webpack, Patcher, Utils, Data, UI } = new BdApi('BetterChatNames')
const { getModule, getByStrings, getByKeys, getByPrototypeKeys } = Webpack
const { findInTree } = Utils
const searchOptions = { walkable: ['children', 'props'] } // For Utils.findInTree

const currentServer = getByKeys('getLastSelectedGuildId')
const currentChannel = getByKeys('getLastSelectedChannelId')
const transitionTo = getByStrings('transitionTo - Transitioning to', { searchExports: true })

const sidebar = getModule(m => m?.render?.toString()?.includes('.CHANNEL'))
const header = getByStrings('.HEADER_BAR)', { defaultExport: false })
const placeholder = getByPrototypeKeys('getPlaceholder').prototype
const mention = getByStrings('channelWithIcon', { defaultExport: false })

const debounceTimeMs = 1000

module.exports = class BetterChatNames {
    start() {
        this.settings = Object.assign({}, defaultSettings, Data.load('settings'))
        this.updateOverrideMap()
        this.observeAppTitle()
        this.patchNames()
        this.refreshChannel()
    }

    stop() {
        titleObserver.disconnect()
        Patcher.unpatchAll()
        this.refreshChannel()
    }

    getSettingsPanel = () => UI.buildSettingsPanel({
        settings: [
            {
                id: 'capitalise',
                name: 'Capitalise Words',
                type: 'switch',
                value: this.settings.capitalise
            },
            {
                id: 'removeDashes',
                name: 'Remove Dashes and Underscores',
                type: 'switch',
                value: this.settings.removeDashes
            },
            {
                id: 'removeEmojis',
                name: 'Remove Emojis',
                type: 'switch',
                value: this.settings.removeEmojis
            },
            {
                id: 'patchUnrestricted',
                name: 'Patch Unrestricted Channels',
                note: 'Change the names of channels that can already contain capital letters and spaces, such as voice channels, threads, and stages.',
                type: 'switch',
                value: this.settings.patchUnrestricted
            },
            {
                id: 'capitalOverrides',
                name: 'Capitalisation Overrides',
                note: 'A comma-separated list of words with custom capitalisations. For example: "and, FAQ, GitHub, iPhone". Only enabled if "Capitalise Words" is enabled, and can be cleared to be disabled.',
                type: 'text',
                inline: false,
                value: this.settings.capitalOverrides
            }
        ],
        onChange: (_, id, value) => {
            if (id === 'capitalOverrides') {
                clearTimeout(this.debounceTimer)
                this.debounceTimer = setTimeout(() => {
                    this.settings[id] = value
                    Data.save('settings', this.settings)
                    this.updateOverrideMap()
                    if (this.settings.capitalise)
                        this.refreshChannel()
                }, debounceTimeMs)
                return
            }
            
            this.settings[id] = value
            Data.save('settings', this.settings)
            this.refreshChannel()
        }
    })

    observeAppTitle() {
        let lastUnpatchedAppTitle
        titleObserver = new MutationObserver(() => {
            if (document.title !== lastUnpatchedAppTitle) { // Resolves conflicts with EditChannels' MutationObserver
                lastUnpatchedAppTitle = document.title
                this.patchAppTitle()
            }
        })
        titleObserver.observe(document.querySelector('title'), { childList: true })
    }

    patchAppTitle() {
        const patchedTitle = this.patchText(document.title)

        if (currentServer?.getGuildId() && document.title !== patchedTitle) // If in server and title not already patched
            document.title = patchedTitle
    }

    patchNames() {
        this.patchSidebar()
        this.patchHeader()
        this.patchChatPlaceholder()
        this.patchMention()
    }

    patchSidebar() {
        Patcher.after(sidebar, 'render', (_, __, data) => {
            const channelName = findInTree(data, prop => prop?.name, searchOptions)
            const channelType = findInTree(data, prop => prop?.channel, searchOptions).channel.type

            if (!Object.values(unrestrictedChannels).includes(channelType) || this.settings.patchUnrestricted) // If not a voice/stage channel or patchUnrestricted is enabled
                channelName.name = this.patchText(channelName.name)
        })
    }

    patchHeader() {
        Patcher.after(header, 'A', (_, __, data) => {
            const rootChannel = findInTree(data, prop => prop?.level, searchOptions)
            if (!rootChannel)
                return

            if (rootChannel.level === 1) // If not in thread
                rootChannel.children.props.children[2] = this.patchText(rootChannel.children.props.children[2])
            else if (rootChannel.level === 2) { // If in thread
                rootChannel.children = this.patchText(rootChannel.children)
                if (this.settings.patchUnrestricted) {
                    const threadName = findInTree(data, prop => Array.isArray(prop) && prop[1] === ' ', searchOptions)
                    threadName[2] = this.patchText(threadName[2])
                }
            }
        })
    }

    patchChatPlaceholder() {
        Patcher.after(placeholder, 'render', (_, __, data) => {
            const textArea = findInTree(data, prop => prop.channel, searchOptions)
            const isThread = textArea.channel.type === unrestrictedChannels.thread

            if (textArea.channel.guild_id && (!isThread || this.settings.patchUnrestricted) && !textArea.disabled && textArea.type.analyticsName === 'normal') { // If in a server, not in a thread (or patchUnrestricted is enabled), can message and not editing a message
                const splitIndex = (isThread ? textArea.placeholder.indexOf('"') : textArea.placeholder.indexOf('#')) + 1 // Indicates where the channel name starts
                textArea.placeholder = textArea.placeholder.substring(0, splitIndex) + this.patchText(textArea.placeholder.substr(splitIndex))
            }
        })
    }

    patchMention() {
        Patcher.after(mention, 'A', (_, __, data) => {
            const channelName = findInTree(data, prop => typeof prop.children === 'string', searchOptions)

            if (data.props.className.includes('iconMentionText') || this.settings.patchUnrestricted) // If is a normal chat mention (not a thread) or patchUnrestricted is enabled
                channelName.children = this.patchText(channelName.children)
        })
    }

    patchText(text) {
        if (this.settings.removeEmojis)
            text = text.replace(regex.emoji, '')

        if (this.settings.removeDashes)
            text = text.replace(regex.dash, ' ')

        if (this.settings.capitalise) {
            text = text.replace(regex.capital, letter => letter.toUpperCase())

            if (this.settings.capitalOverrides) {
                let wordCount = 0
                text = text.replace(regex.word, word => {
                    wordCount++
                    const wordLower = word.toLowerCase()
                    if (!this.overrideMap.has(wordLower))
                        return word

                    const wordOverride = this.overrideMap.get(wordLower)
                    if (wordCount == 1 && wordOverride === wordLower)
                        return word

                    return wordOverride
                })
            }
        }

        return text
    }

    refreshChannel() {
        const currentServerId = currentServer?.getGuildId()
        const currentChannelId = currentChannel?.getChannelId()

        if (currentServerId) { // If not in a DM
            transitionTo('/channels/@me')
            setImmediate(() => transitionTo(`/channels/${currentServerId}/${currentChannelId}`))
        }
    }

    updateOverrideMap() {
        // Maps lowercase words to their custom capitalised versions
        this.overrideMap = new Map((this.settings.capitalOverrides).split(',').map(w => w.trim()).filter(w => w).map(w => [w.toLowerCase(), w]))
    }
}
← Alle Plugins & Themes index.json headcraft.cloud