BetterDiscordAddons/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton....

134 lines
5.7 KiB
JavaScript
Raw Normal View History

2018-10-11 10:21:26 +02:00
//META{"name":"ReadAllNotificationsButton"}*//
class ReadAllNotificationsButton {
2019-01-17 23:48:29 +01:00
getName () {return "ReadAllNotificationsButton";}
2019-01-20 19:11:47 +01:00
getVersion () {return "1.3.9";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
getDescription () {return "Adds a button to clear all notifications.";}
2018-10-11 10:21:26 +02:00
initConstructor () {
this.patchModules = {
"Guilds":"componentDidMount",
"RecentMentions":"componentDidMount"
};
2018-10-11 10:21:26 +02:00
this.RANbuttonMarkup =
2018-12-07 12:38:15 +01:00
`<div class="${BDFDB.disCN.guild} RANbutton-frame" id="bd-pub-li" style="height: 20px; margin-bottom: 10px;">
2018-10-11 10:21:26 +02:00
<div class="${BDFDB.disCN.guildinner}" style="height: 20px; border-radius: 4px;">
<a>
2018-12-07 12:38:15 +01:00
<div class="RANbutton" id="bd-pub-button" style="line-height: 20px; font-size: 12px;">read all</div>
2018-10-11 10:21:26 +02:00
</a>
</div>
</div>`;
this.RAMbuttonMarkup =
`<button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonsizemin + BDFDB.disCN.buttongrow} RAMbutton" style="flex: 0 0 auto; margin-left: 25px; height: 25px;">
<div class="${BDFDB.disCN.buttoncontents}">Clear Mentions</div>
2018-10-11 10:21:26 +02:00
</button>`;
this.defaults = {
settings: {
includeMuted: {value:false, description:"Include muted Servers (means more API-Requests):"}
}
};
}
getSettingsPanel () {
2019-01-22 11:28:32 +01:00
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2018-10-11 10:21:26 +02:00
var settings = BDFDB.getAllData(this, "settings");
2019-01-24 13:37:08 +01:00
var settingshtml = `<div class="${this.name}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="DevilBro-settings-inner">`;
2018-10-11 10:21:26 +02:00
for (let key in settings) {
2019-01-17 23:48:29 +01:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
2018-10-11 10:21:26 +02:00
}
settingshtml += `</div></div>`;
2019-01-17 23:48:29 +01:00
let settingspanel = BDFDB.htmlToElement(settingshtml);
2018-10-11 10:21:26 +02:00
2019-01-17 23:48:29 +01:00
BDFDB.initElements(settingspanel, this);
2018-10-11 10:21:26 +02:00
return settingspanel;
}
//legacy
load () {}
start () {
2019-01-17 23:48:29 +01:00
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
2018-10-11 10:21:26 +02:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", () => {
BDFDB.loaded = true;
this.initialize();
});
2018-10-11 10:21:26 +02:00
document.head.appendChild(libraryScript);
}
2019-01-17 23:48:29 +01:00
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2018-10-11 10:21:26 +02:00
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
}
initialize () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-01-22 11:05:54 +01:00
if (this.started) return;
2018-10-11 10:21:26 +02:00
BDFDB.loadMessage(this);
BDFDB.WebModules.forceAllUpdates(this);
2018-10-11 10:21:26 +02:00
}
else {
2019-01-24 13:37:08 +01:00
console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
2018-10-11 10:21:26 +02:00
}
}
stop () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
BDFDB.removeEles(".RANbutton-frame", ".RAMbutton");
BDFDB.removeClasses("RAN-added", "RAM-added");
2018-10-11 10:21:26 +02:00
BDFDB.unloadMessage(this);
}
}
// begin of own functions
processGuilds (instance, wrapper) {
2019-01-20 19:11:47 +01:00
BDFDB.removeEles(".RANbutton-frame");
2019-01-17 23:48:29 +01:00
let guildseparator = wrapper.querySelector(BDFDB.dotCN.guildseparator);
if (guildseparator) {
let ranbutton = BDFDB.htmlToElement(this.RANbuttonMarkup);
guildseparator.parentElement.insertBefore(ranbutton, guildseparator);
ranbutton.addEventListener("click", () => {
BDFDB.clearReadNotifications(BDFDB.getData("includeMuted", this, "settings") ? BDFDB.readServerList() : BDFDB.readUnreadServerList());
});
2019-01-17 23:48:29 +01:00
BDFDB.addClass(wrapper, "RAN-added");
}
}
processRecentMentions (instance, wrapper) {
BDFDB.removeEles(".RAMbutton");
if (instance.props && instance.props.popoutName == "RECENT_MENTIONS_POPOUT") {
2019-01-17 23:48:29 +01:00
let recentmentionstitle = wrapper.querySelector(BDFDB.dotCN.recentmentionstitle);
if (recentmentionstitle) {
let ranbutton = BDFDB.htmlToElement(this.RAMbuttonMarkup);
2019-01-17 23:48:29 +01:00
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);
}
}
2018-10-11 10:21:26 +02:00
}