commit e0c2c83577a04f20253e89d06f583be40872ed56 Author: Julia Lange Date: Thu Jan 25 20:41:03 2024 -0800 Plugin 1.0, and readme diff --git a/README.md b/README.md new file mode 100644 index 0000000..08a8afc --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Chatless Discord + +A discord plugin I wrote to remove the chat from discord + +It additionally causes the discord call pop-out to open when joining a call + +I use this for my personal setup where I use Beeper for my discord channels, and +use Discord exclusively for calling. + +It can be installed by first installing +[Better Discord](https://betterdiscord.app/) and then putting the file into the +plugins folder. diff --git a/core.plugin.js b/core.plugin.js new file mode 100644 index 0000000..c77350f --- /dev/null +++ b/core.plugin.js @@ -0,0 +1,103 @@ +/** + * @name chatlessdisc + * @version 1.0.0 + * @description removes the chatting from disc, as god intended + * @author Julia Lange + * + */ + +const TITLE = "chatless-disc"; + +function getChat() { + let chatsPotentialChild = document.querySelector( + "div > section[aria-label='Channel header']"); + if(chatsPotentialChild) { + let chat = chatsPotentialChild.parentElement; + return chat; + } + return null; +} + +function removeChat() { + let chat = getChat() + if (chat) chat.style = "display: none"; +} +function restoreChat() { + let chat = getChat() + if (chat) chat.style = "display: flex"; +} + +function expandSidebar() { + let userArea = document.querySelector("section[aria-label='User area']"); + let sidebar = userArea.parentElement; + sidebar.style = "width: 100%"; + removeChat(); + + userArea.childNodes.forEach(node => { + node.style = "justify-content: space-between"; + }); +} + +function contractSidebar() { + let userArea = document.querySelector("section[aria-label='User area']"); + let sidebar = userArea.parentElement; + sidebar.style = ""; + restoreChat(); + + userArea.childNodes.forEach(node => { + node.style = ""; + }); +} + +function addChannelClass() { + let dms = document.querySelector("ul[aria-label='Direct Messages'"); + if(dms == null) return ""; + let friendsElement = dms.childNodes[1] + if(friendsElement == null) return ""; + let channelClassName = friendsElement.className.split(" ")[0] + if (channelClassName != "") { + BdApi.DOM.addStyle(TITLE, `.${channelClassName} { + max-width: 100%; + }`); + } + return channelClassName; +} + +function clickPopOut() { + let popOutButton = document.querySelector("button[aria-label='Pop Out'"); + if(popOutButton == null) return; + popOutButton.click(); +} + +class chatlessdisc { + + constructor() { + // this.channelClassName = ""; + this.channelActionsModule = BdApi.findModuleByProps('selectChannel'); + } + + start() { + expandSidebar(); + this.channelClassName = addChannelClass(); + + BdApi.Patcher.instead(TITLE, this.channelActionsModule, + "selectChannel", async (_, args, originalFunction) => { + await originalFunction(...args); + removeChat(); + if (this.channelClassName == "") + this.channelClassName = addChannelClass(); + }); + BdApi.Patcher.instead(TITLE, this.channelActionsModule, + "selectVoiceChannel", async (_, args, originalFunction) => { + await originalFunction(...args); + await this.channelActionsModule.selectPrivateChannel(args[0]); + clickPopOut(); + }); + } + //Turn off and remove all parts of the plugin + stop() { + contractSidebar(); + BdApi.Patcher.unpatchAll(TITLE); + BdApi.DOM.removeStyle(TITLE); + } +}