diff --git a/HideSystemMessages.plugin.js b/HideSystemMessages.plugin.js
index 28ee50c..c0638e4 100644
--- a/HideSystemMessages.plugin.js
+++ b/HideSystemMessages.plugin.js
@@ -3,7 +3,7 @@
* @author TenorTheHusky
* @authorId 563652755814875146
* @description Adds buttons to toggle system messages and chat dividers
- * @version 1.0.2
+ * @version 1.0.3
* @website https://github.com/programmer2514/BetterDiscord-HideSystemMessages
* @source https://raw.githubusercontent.com/programmer2514/BetterDiscord-HideSystemMessages/main/HideSystemMessages.plugin.js
*/
@@ -19,12 +19,17 @@ module.exports = (() => {
discord_id: '563652755814875146',
github_username: 'programmer2514'
}],
- version: '1.0.2',
+ version: '1.0.3',
description: 'Adds buttons to toggle system messages and chat dividers',
github: 'https://github.com/programmer2514/BetterDiscord-HideSystemMessages',
github_raw: 'https://raw.githubusercontent.com/programmer2514/BetterDiscord-HideSystemMessages/main/HideSystemMessages.plugin.js'
},
changelog: [{
+ title: '1.0.3',
+ items: [
+ 'Cleaned up unnecessary console warnings'
+ ]
+ }, {
title: '1.0.2',
items: [
'Cleaned up method of getting plugin instance'
@@ -96,116 +101,120 @@ module.exports = (() => {
// Clean up UI
this.terminate();
- // Create eventListener
- this.eventListenerController = new AbortController();
- this.eventListenerSignal = this.eventListenerController.signal;
-
- // Create plugin stylesheet
- this.pluginStyle = document.createElement("style");
- this.pluginStyle.setAttribute('id', 'hsm-stylesheet');
- this.pluginStyle.appendChild(document.createTextNode(""));
- document.head.appendChild(this.pluginStyle);
- this.pluginStyle.sheet.insertRule("." + this.classSystemMessage + " {}", 0);
- this.pluginStyle.sheet.insertRule("." + this.classChatDivider + " {}", 1);
-
- // Define & add toolbar container
- this.toolbarContainer = document.createElement('div');
- this.toolbarContainer.setAttribute('id', 'hsm-toolbar-container');
- this.toolbarContainer.classList.add('hsm-element');
- this.toolbarContainer.style.alignItems = 'left';
- this.toolbarContainer.style.display = 'flex';
- this.toolbarContainer.style.padding = '0px';
- this.toolbarContainer.style.margin = '0px';
- this.toolbarContainer.style.border = '0px';
- this.toolbarContainer.style.opacity = '0.1';
- this.toolbarContainer.style.transition = 'opacity 100ms';
- this.toolbarContainer.style.position = 'absolute';
- this.toolbarContainer.style.zIndex = '100000';
- this.toolbarContainer.innerHTML = '
';
-
- // Insert toolbar in the correct spot
- this.insertPoint.appendChild(this.toolbarContainer);
-
- // Add mutation observer to the app wrapper because otherwise BDFDB nukes the toolbar
- let hsm = this;
- this.appObserver = new MutationObserver((mutationList) => {
- try {
- for (let i = 0; i < mutationList.length; i++) {
- if (mutationList[i].addedNodes[0])
- if (mutationList[i].addedNodes[0].classList.contains(hsm.classAppWrapper))
- hsm.initialize();
+ // Only run if the messages wrapper exists
+ if (this.insertPoint) {
+
+ // Create eventListener
+ this.eventListenerController = new AbortController();
+ this.eventListenerSignal = this.eventListenerController.signal;
+
+ // Create plugin stylesheet
+ this.pluginStyle = document.createElement("style");
+ this.pluginStyle.setAttribute('id', 'hsm-stylesheet');
+ this.pluginStyle.appendChild(document.createTextNode(""));
+ document.head.appendChild(this.pluginStyle);
+ this.pluginStyle.sheet.insertRule("." + this.classSystemMessage + " {}", 0);
+ this.pluginStyle.sheet.insertRule("." + this.classChatDivider + " {}", 1);
+
+ // Define & add toolbar container
+ this.toolbarContainer = document.createElement('div');
+ this.toolbarContainer.setAttribute('id', 'hsm-toolbar-container');
+ this.toolbarContainer.classList.add('hsm-element');
+ this.toolbarContainer.style.alignItems = 'left';
+ this.toolbarContainer.style.display = 'flex';
+ this.toolbarContainer.style.padding = '0px';
+ this.toolbarContainer.style.margin = '0px';
+ this.toolbarContainer.style.border = '0px';
+ this.toolbarContainer.style.opacity = '0.1';
+ this.toolbarContainer.style.transition = 'opacity 100ms';
+ this.toolbarContainer.style.position = 'absolute';
+ this.toolbarContainer.style.zIndex = '100000';
+ this.toolbarContainer.innerHTML = '';
+
+ // Insert toolbar in the correct spot
+ this.insertPoint.appendChild(this.toolbarContainer);
+
+ // Add mutation observer to the app wrapper because otherwise BDFDB nukes the toolbar
+ let hsm = this;
+ this.appObserver = new MutationObserver((mutationList) => {
+ try {
+ for (let i = 0; i < mutationList.length; i++) {
+ if (mutationList[i].addedNodes[0])
+ if (mutationList[i].addedNodes[0].classList.contains(hsm.classAppWrapper))
+ hsm.initialize();
+ }
+ } catch(e) {
+ console.warn('%c[HideSystemMessages] ' + '%cFailed to trigger mutationObserver reload! (see below)', 'color: #3a71c1; font-weight: 700;', '');
+ console.warn(e);
}
- } catch(e) {
- console.warn('%c[HideSystemMessages] ' + '%cFailed to trigger mutationObserver reload! (see below)', 'color: #3a71c1; font-weight: 700;', '');
- console.warn(e);
+ });
+ this.appObserver.observe(this.appWrapper, {childList: true});
+
+ // Define & add new toolbar icons
+ // Icons are part of the Bootstrap Icons library, which can be found at https://icons.getbootstrap.com/
+ this.systemMessageButton = this.addButton("System Messages", '', '-8 -8 24 24');
+ this.chatDividerButton = this.addButton("Chat Dividers", '', '-8 -8 24 24');
+
+ // Read stored user data to decide active state of System Messages button
+ if (BdApi.getData('HideSystemMessages', 'systemMessageButtonActive') === 'false') {
+ this.systemMessageButton.classList.remove(this.classSelected);
+ this.systemMessageButton.style.opacity = '0.5';
+
+ this.pluginStyle.sheet.deleteRule(0);
+ this.pluginStyle.sheet.insertRule("." + this.classSystemMessage + " { display: none;}", 0);
+
+ } else if (BdApi.getData('HideSystemMessages', 'systemMessageButtonActive') === 'true') {
+ this.systemMessageButton.classList.add(this.classSelected);
+ this.systemMessageButton.style.opacity = '1.0';
+ } else {
+ BdApi.setData('HideSystemMessages', 'systemMessageButtonActive', 'true');
+ this.systemMessageButton.classList.add(this.classSelected);
+ this.systemMessageButton.style.opacity = '1.0';
}
- });
- this.appObserver.observe(this.appWrapper, {childList: true});
-
- // Define & add new toolbar icons
- // Icons are part of the Bootstrap Icons library, which can be found at https://icons.getbootstrap.com/
- this.systemMessageButton = this.addButton("System Messages", '', '-8 -8 24 24');
- this.chatDividerButton = this.addButton("Chat Dividers", '', '-8 -8 24 24');
-
- // Read stored user data to decide active state of System Messages button
- if (BdApi.getData('HideSystemMessages', 'systemMessageButtonActive') === 'false') {
- this.systemMessageButton.classList.remove(this.classSelected);
- this.systemMessageButton.style.opacity = '0.5';
-
- this.pluginStyle.sheet.deleteRule(0);
- this.pluginStyle.sheet.insertRule("." + this.classSystemMessage + " { display: none;}", 0);
-
- } else if (BdApi.getData('HideSystemMessages', 'systemMessageButtonActive') === 'true') {
- this.systemMessageButton.classList.add(this.classSelected);
- this.systemMessageButton.style.opacity = '1.0';
- } else {
- BdApi.setData('HideSystemMessages', 'systemMessageButtonActive', 'true');
- this.systemMessageButton.classList.add(this.classSelected);
- this.systemMessageButton.style.opacity = '1.0';
- }
- // Read stored user data to decide active state of Chat Dividers button
- if (BdApi.getData('HideSystemMessages', 'chatDividerButtonActive') === 'false') {
- this.chatDividerButton.classList.remove(this.classSelected);
- this.chatDividerButton.style.opacity = '0.5';
-
- this.pluginStyle.sheet.deleteRule(1);
- this.pluginStyle.sheet.insertRule("." + this.classChatDivider + " { display: none;}", 1);
-
- } else if (BdApi.getData('HideSystemMessages', 'chatDividerButtonActive') === 'true') {
- this.chatDividerButton.classList.add(this.classSelected);
- this.chatDividerButton.style.opacity = '1.0';
- } else {
- BdApi.setData('HideSystemMessages', 'chatDividerButtonActive', 'true');
- this.chatDividerButton.classList.add(this.classSelected);
- this.chatDividerButton.style.opacity = '1.0';
- }
+ // Read stored user data to decide active state of Chat Dividers button
+ if (BdApi.getData('HideSystemMessages', 'chatDividerButtonActive') === 'false') {
+ this.chatDividerButton.classList.remove(this.classSelected);
+ this.chatDividerButton.style.opacity = '0.5';
+
+ this.pluginStyle.sheet.deleteRule(1);
+ this.pluginStyle.sheet.insertRule("." + this.classChatDivider + " { display: none;}", 1);
+
+ } else if (BdApi.getData('HideSystemMessages', 'chatDividerButtonActive') === 'true') {
+ this.chatDividerButton.classList.add(this.classSelected);
+ this.chatDividerButton.style.opacity = '1.0';
+ } else {
+ BdApi.setData('HideSystemMessages', 'chatDividerButtonActive', 'true');
+ this.chatDividerButton.classList.add(this.classSelected);
+ this.chatDividerButton.style.opacity = '1.0';
+ }
- // Add event listener to the System Messages button to update on click and hover
- this.systemMessageButton.addEventListener('click', function(){
- hsm.toggleButton(0);
- }, {signal: this.eventListenerSignal});
+ // Add event listener to the System Messages button to update on click and hover
+ this.systemMessageButton.addEventListener('click', function(){
+ hsm.toggleButton(0);
+ }, {signal: this.eventListenerSignal});
- this.systemMessageButton.addEventListener('mouseenter', function(){
- hsm.toolbarContainer.style.opacity = '1.0';
- }, {signal: this.eventListenerSignal});
+ this.systemMessageButton.addEventListener('mouseenter', function(){
+ hsm.toolbarContainer.style.opacity = '1.0';
+ }, {signal: this.eventListenerSignal});
- this.systemMessageButton.addEventListener('mouseleave', function(){
- hsm.toolbarContainer.style.opacity = '0.1';
- }, {signal: this.eventListenerSignal});
+ this.systemMessageButton.addEventListener('mouseleave', function(){
+ hsm.toolbarContainer.style.opacity = '0.1';
+ }, {signal: this.eventListenerSignal});
- // Add event listener to the Chat Dividers button to update on click
- this.chatDividerButton.addEventListener('click', function(){
- hsm.toggleButton(1);
- }, {signal: this.eventListenerSignal});
+ // Add event listener to the Chat Dividers button to update on click
+ this.chatDividerButton.addEventListener('click', function(){
+ hsm.toggleButton(1);
+ }, {signal: this.eventListenerSignal});
- this.chatDividerButton.addEventListener('mouseenter', function(){
- hsm.toolbarContainer.style.opacity = '1.0';
- }, {signal: this.eventListenerSignal});
+ this.chatDividerButton.addEventListener('mouseenter', function(){
+ hsm.toolbarContainer.style.opacity = '1.0';
+ }, {signal: this.eventListenerSignal});
- this.chatDividerButton.addEventListener('mouseleave', function(){
- hsm.toolbarContainer.style.opacity = '0.1';
- }, {signal: this.eventListenerSignal});
+ this.chatDividerButton.addEventListener('mouseleave', function(){
+ hsm.toolbarContainer.style.opacity = '0.1';
+ }, {signal: this.eventListenerSignal});
+ }
}
// Terminate the plugin and undo its effects
@@ -214,8 +223,7 @@ module.exports = (() => {
document.querySelectorAll('.hsm-element').forEach(e => e.remove());
// Undo plugin effects
- if (this.pluginStyle)
- this.pluginStyle.parentNode.removeChild(this.pluginStyle);
+ this.pluginStyle?.parentNode?.removeChild(this.pluginStyle);
// Abort listeners & observers
if (this.eventListenerController)