module.exports = (Plugin, Api, Vendor) => { if (!global.BDFDB || typeof BDFDB != "object") global.BDFDB = {myPlugins:{}, BDv2Api: Api}; return class extends Plugin { initConstructor () { this.patchModules = { "Guilds":"componentDidMount", "RecentMentions":"componentDidMount" }; this.RANcontextMenuMarkup = `
`; this.RANbuttonMarkup = ` `; this.RAMbuttonMarkup = ``; this.defaults = { settings: { includeGuilds: {value:true, description:"unread Servers"}, includeMuted: {value:false, description:"muted unread Servers"}, includeDMs: {value:false, description:"unread DMs"} } }; } onStart () { if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.name] = this; var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (!global.BDFDB || typeof BDFDB != "object" || performance.now() - BDFDB.creationTime > 600000e.now() - BDFDB.creationTime > 600000) { if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); libraryScript.setAttribute("date", performance.now()); libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();}); document.head.appendChild(libraryScript); } else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); this.startTimeout = setTimeout(() => {this.initialize();}, 30000); } initialize () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (this.started) return true; BDFDB.loadMessage(this); BDFDB.WebModules.forceAllUpdates(this); return true; } else { console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); return false; } } onStop () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { BDFDB.removeEles(".RANbutton-frame", ".RAMbutton"); BDFDB.removeClasses("RAN-added", "RAM-added"); BDFDB.unloadMessage(this); return true; } else { return false; } } // begin of own functions processGuilds (instance, wrapper) { BDFDB.removeEles(".RANbutton-frame"); let guildseparator = wrapper.querySelector(BDFDB.dotCN.guildseparator); if (guildseparator) { let ranbutton = BDFDB.htmlToElement(this.RANbuttonMarkup); guildseparator.parentElement.insertBefore(ranbutton, guildseparator); ranbutton.addEventListener("click", () => { let settings = BDFDB.getAllData(this, "settings"); if (settings.includeGuilds) BDFDB.markGuildAsRead(settings.includeMuted ? BDFDB.readServerList() : BDFDB.readUnreadServerList()); if (settings.includeDMs) BDFDB.markChannelAsRead(BDFDB.readDmList()); }); ranbutton.addEventListener("contextmenu", e => { let RANcontextMenu = BDFDB.htmlToElement(this.RANcontextMenuMarkup); RANcontextMenu.querySelector(".readguilds-item").addEventListener("click", () => { BDFDB.removeEles(RANcontextMenu); BDFDB.markGuildAsRead(BDFDB.readUnreadServerList()); }); RANcontextMenu.querySelector(".readmutedguilds-item").addEventListener("click", () => { BDFDB.removeEles(RANcontextMenu); BDFDB.markGuildAsRead(BDFDB.readServerList()); }); RANcontextMenu.querySelector(".readdms-item").addEventListener("click", () => { BDFDB.removeEles(RANcontextMenu); BDFDB.markChannelAsRead(BDFDB.readDmList()); }); BDFDB.appendContextMenu(RANcontextMenu, e); }); BDFDB.addClass(wrapper, "RAN-added"); } } processRecentMentions (instance, wrapper) { BDFDB.removeEles(".RAMbutton"); if (instance.props && instance.props.popoutName == "RECENT_MENTIONS_POPOUT") { let recentmentionstitle = wrapper.querySelector(BDFDB.dotCN.recentmentionstitle); if (recentmentionstitle) { let ranbutton = BDFDB.htmlToElement(this.RAMbuttonMarkup); recentmentionstitle.appendChild(ranbutton); ranbutton.addEventListener("click", () => {this.clearMentions(instance, wrapper);}); BDFDB.addClass(wrapper, "RAM-added"); } } } 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); } } getSettingsPanel () { if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; var settings = BDFDB.getAllData(this, "settings"); var settingshtml = `