Add button to toggle chat hiding (For heathens)
adds a button to toggle the chat
This commit is contained in:
parent
2587f898e3
commit
9c3a07a8a2
1 changed files with 75 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* @name chatlessdisc
|
* @name chatlessdisc
|
||||||
* @version 1.0.0
|
* @version 1.1.0
|
||||||
* @description removes the chatting from disc, as god intended
|
* @description removes the chatting from disc, as god intended
|
||||||
* @author Julia Lange
|
* @author Julia Lange
|
||||||
*
|
*
|
||||||
|
|
@ -69,33 +69,100 @@ function clickPopOut() {
|
||||||
popOutButton.click();
|
popOutButton.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addToggleButton(button) {
|
||||||
|
let muteButton = document.querySelector("div > button[aria-label='Mute']");
|
||||||
|
if(muteButton == null) return;
|
||||||
|
let buttonList = muteButton.parentElement;
|
||||||
|
buttonList.prepend(button)
|
||||||
|
|
||||||
|
enablePortraitStyle()
|
||||||
|
}
|
||||||
|
|
||||||
|
function enablePortraitStyle() {
|
||||||
|
let portrait = document.querySelector("div[aria-label='Set Status']");
|
||||||
|
if(portrait == null) return;
|
||||||
|
portrait.style = "width: 100%; min-width: 0px";
|
||||||
|
}
|
||||||
|
|
||||||
|
function disablePortaitStyle() {
|
||||||
|
let portrait = document.querySelector("div[aria-label='Set Status']");
|
||||||
|
if(portrait == null) return;
|
||||||
|
portrait.style = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableChanges() {
|
||||||
|
expandSidebar();
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableChanges() {
|
||||||
|
contractSidebar();
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
function createToggleButton(onClickFunction) {
|
||||||
|
let toggleButton = document.createElement("button");
|
||||||
|
toggleButton.role = "switch";
|
||||||
|
toggleButton.ariaLabel = "Chattless Toggle";
|
||||||
|
toggleButton.textContent = "💬";
|
||||||
|
|
||||||
|
// Had to style instead of use the class, because otherwise the class
|
||||||
|
// wouldn't work
|
||||||
|
toggleButton.style = "height: 32px; width: 32px; border-radius: 4px; \
|
||||||
|
background: transparent;"
|
||||||
|
toggleButton.className = "chattless_button"
|
||||||
|
toggleButton.addEventListener("click", onClickFunction);
|
||||||
|
|
||||||
|
return toggleButton;
|
||||||
|
}
|
||||||
|
|
||||||
class chatlessdisc {
|
class chatlessdisc {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.enabled = false;
|
||||||
this.channelActionsModule = BdApi.findModuleByProps('selectChannel');
|
this.channelActionsModule = BdApi.findModuleByProps('selectChannel');
|
||||||
|
|
||||||
|
this.toggleButton = createToggleButton(async () => {
|
||||||
|
if(this.enabled)
|
||||||
|
this.enabled = disableChanges();
|
||||||
|
else
|
||||||
|
this.enabled = enableChanges();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
expandSidebar();
|
this.enabled = enableChanges();
|
||||||
|
addToggleButton(this.toggleButton);
|
||||||
this.channelClassName = addChannelClass();
|
this.channelClassName = addChannelClass();
|
||||||
|
|
||||||
|
BdApi.DOM.addStyle(TITLE, `.chattless_button:hover {
|
||||||
|
background: rgba(255,255,255,0.125) !important;
|
||||||
|
}`);
|
||||||
|
|
||||||
BdApi.Patcher.instead(TITLE, this.channelActionsModule,
|
BdApi.Patcher.instead(TITLE, this.channelActionsModule,
|
||||||
"selectChannel", async (_, args, originalFunction) => {
|
"selectChannel", async (_, args, originalFunction) => {
|
||||||
await originalFunction(...args);
|
await originalFunction(...args);
|
||||||
removeChat();
|
if (this.enabled) {
|
||||||
if (this.channelClassName == "")
|
removeChat();
|
||||||
this.channelClassName = addChannelClass();
|
if (this.channelClassName == "")
|
||||||
|
this.channelClassName = addChannelClass();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
BdApi.Patcher.instead(TITLE, this.channelActionsModule,
|
BdApi.Patcher.instead(TITLE, this.channelActionsModule,
|
||||||
"selectVoiceChannel", async (_, args, originalFunction) => {
|
"selectVoiceChannel", async (_, args, originalFunction) => {
|
||||||
await originalFunction(...args);
|
await originalFunction(...args);
|
||||||
await this.channelActionsModule.selectPrivateChannel(args[0]);
|
if (this.enabled) {
|
||||||
clickPopOut();
|
await this.channelActionsModule.selectPrivateChannel(args[0]);
|
||||||
|
clickPopOut();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Turn off and remove all parts of the plugin
|
//Turn off and remove all parts of the plugin
|
||||||
stop() {
|
stop() {
|
||||||
contractSidebar();
|
this.toggleButton.remove()
|
||||||
|
disableChanges();
|
||||||
BdApi.Patcher.unpatchAll(TITLE);
|
BdApi.Patcher.unpatchAll(TITLE);
|
||||||
BdApi.DOM.removeStyle(TITLE);
|
BdApi.DOM.removeStyle(TITLE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue