Skip to content

Commit

Permalink
EditChannels Compatibility (1.5.4)
Browse files Browse the repository at this point in the history
Fixed patching of titleBar title with EditChannels and stopped memory leak / app freezing from occuring when switching to a channel patched with EditChannels
  • Loading branch information
Break-Ben committed Sep 13, 2023
1 parent a8d7999 commit 72462e4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions BetterChatNames/BetterChatNames.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @name BetterChatNames
* @author Break
* @description Improves chat names by automatically capitalising them, and removing dashes & underscores
* @version 1.5.3
* @version 1.5.4
* @authorLink https://github.com/Break-Ben
* @website https://github.com/Break-Ben/BetterDiscordAddons
* @source https://github.com/Break-Ben/BetterDiscordAddons/tree/main/BetterChatNames
Expand Down Expand Up @@ -47,7 +47,13 @@ module.exports = class BetterChatNames {
titleBar[n].props.children.filter(c => c)[0].props.children[1].props.children = this.patchText(titleBar[n].props.children.filter(c => c)[0].props.children[1].props.children)
}
else { //If in chat/forum
titleBar[n].props.children[3].props.children.props.children[2] = this.patchText(titleBar[n].props.children[3].props.children.props.children[2])
const chatName = titleBar?.[n]?.props?.children?.[3]?.props?.children?.props
if (chatName) { // If channel not patched with EditChannels
chatName.children[2] = this.patchText(chatName.children[2])
}
else {
titleBar[n].props.children[3].props.children = this.patchText(titleBar[n].props.children[3].props.children)
}
}
}
})
Expand All @@ -63,7 +69,7 @@ module.exports = class BetterChatNames {

// Chat mention
Patcher.after(Mention, 'Z', (_, args, data) => {
const mention = data?.props?.children?.[1].props?.children?.[0]?.props || data?.props?.children?.[1]?.props; //If in chat or text area
const mention = data?.props?.children?.[1].props?.children?.[0]?.props || data?.props?.children?.[1]?.props //If in chat or text area
if (mention) {
mention.children = this.patchText(mention.children)
}
Expand Down Expand Up @@ -94,7 +100,13 @@ module.exports = class BetterChatNames {
}

start() {
titleObserver = new MutationObserver(_ => { this.patchTitle() })
var lastUnpatchedAppTitle
titleObserver = new MutationObserver(_ => {
if (document.title != lastUnpatchedAppTitle) { // Resolves conflicts with EditChannels' MutationObserver
lastUnpatchedAppTitle = document.title
this.patchTitle()
}
})
titleObserver.observe(document.querySelector('title'), { childList: true })
this.patchNames()
this.refreshChannel()
Expand Down

0 comments on commit 72462e4

Please sign in to comment.