diff --git a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js index c8f567473e..51a0252b13 100644 --- a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js +++ b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js @@ -2,6 +2,11 @@ class ReadAllNotificationsButton { initConstructor () { + this.patchModules = { + "Guilds":"componentDidMount", + "RecentMentions":"componentDidMount" + }; + this.RANbuttonMarkup = `
@@ -12,7 +17,7 @@ class ReadAllNotificationsButton {
`; this.RAMbuttonMarkup = - ``; @@ -27,7 +32,7 @@ class ReadAllNotificationsButton { getDescription () {return "Adds a button to clear all notifications.";} - getVersion () {return "1.3.6";} + getVersion () {return "1.3.7";} getAuthor () {return "DevilBro";} @@ -71,47 +76,7 @@ class ReadAllNotificationsButton { if (typeof BDFDB === "object") { BDFDB.loadMessage(this); - var observer = null; - - observer = new MutationObserver((changes, _) => { - changes.forEach( - (change, i) => { - if (change.addedNodes) { - change.addedNodes.forEach((node) => { - var mentionspopout = null; - if (node.tagName && (mentionspopout = node.querySelector(BDFDB.dotCN.recentmentionspopout)) != null && node.querySelector(BDFDB.dotCN.recentmentionsmentionfilter)) { - $(this.RAMbuttonMarkup).appendTo(BDFDB.dotCN.recentmentionstitle, mentionspopout) - .on("click", () => { - var loadinterval = setInterval(() => { - if (!mentionspopout || !mentionspopout.parentElement) clearInterval(loadinterval); - var loadbutton = mentionspopout.querySelector(BDFDB.dotCNS.messagespopouthasmore + "button"); - var closebuttons = mentionspopout.querySelectorAll(BDFDB.dotCN.messagespopoutclosebutton); - if (!loadbutton) { - closebuttons.forEach((btn) => {btn.click();}); - clearInterval(loadinterval); - } - else { - closebuttons.forEach((btn,i) => {if (closebuttons.length-1 > i) btn.click();}); - loadbutton.click(); - } - },2000); - }); - mentionspopout.classList.add("RAM-added"); - } - }); - } - } - ); - }); - BDFDB.addObserver(this, BDFDB.dotCN.popouts, {name:"mentionsPopoutObserver",instance:observer}, {childList: true}); - - $(this.RANbuttonMarkup).insertBefore(document.querySelector(BDFDB.dotCN.guildseparator)) - .on("click", ".RANbutton", () => { - let servers = BDFDB.getData("includeMuted", this, "settings") ? BDFDB.readServerList() : BDFDB.readUnreadServerList(); - BDFDB.clearReadNotifications(servers); - }); - - $(BDFDB.dotCN.guilds).addClass("RAN-added"); + BDFDB.WebModules.forceAllUpdates(this); } else { console.error(this.getName() + ": Fatal Error: Could not load BD functions!"); @@ -120,11 +85,8 @@ class ReadAllNotificationsButton { stop () { if (typeof BDFDB === "object") { - $(".RANbutton-frame, .RAMbutton").remove(); - - $(".RAN-added").removeClass("RAN-added"); - $(".RAM-added").removeClass("RAM-added"); - + BDFDB.removeEles(".RANbutton-frame", ".RAMbutton"); + BDFDB.removeClasses("RAN-added", "RAM-added"); BDFDB.unloadMessage(this); } } @@ -139,4 +101,30 @@ class ReadAllNotificationsButton { } BDFDB.saveAllData(settings, this, "settings"); } + + processGuilds (instance, wrapper) { + $(this.RANbuttonMarkup).insertBefore(wrapper.querySelector(BDFDB.dotCN.guildseparator)) + .on("click", ".RANbutton", () => { + BDFDB.clearReadNotifications(BDFDB.getData("includeMuted", this, "settings") ? BDFDB.readServerList() : BDFDB.readUnreadServerList()); + }); + wrapper.classList.add("RAN-added"); + } + + processRecentMentions (instance, wrapper) { + BDFDB.removeEles(".RAMbutton"); + if (instance.props && instance.props.popoutName == "RECENT_MENTIONS_POPOUT") { + wrapper.classList.add("RAM-added"); + $(this.RAMbuttonMarkup).appendTo(wrapper.querySelector(BDFDB.dotCN.recentmentionstitle)) + .on("click", () => {this.clearMentions(instance, wrapper);}); + } + } + + clearMentions (instance, wrapper) { + let closebuttons = wrapper.querySelectorAll(BDFDB.dotCN.messagespopoutclosebutton); + for (let btn of wrapper.querySelectorAll(BDFDB.dotCN.messagespopoutclosebutton)) btn.click(); + if (closebuttons.length) { + instance.loadMore(); + setTimeout(() => {this.clearMentions(instance, wrapper);},3000); + } + } }