BetterDiscordAddons/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton....

331 lines
15 KiB
JavaScript
Raw Normal View History

2019-01-31 17:06:48 +01:00
//META{"name":"ReadAllNotificationsButton","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ReadAllNotificationsButton","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class ReadAllNotificationsButton {
2019-01-17 23:48:29 +01:00
getName () {return "ReadAllNotificationsButton";}
2019-03-07 23:56:18 +01:00
getVersion () {return "1.4.3";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
getDescription () {return "Adds a button to clear all notifications.";}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
initConstructor () {
this.changelog = {
2019-03-07 23:56:18 +01:00
"fixed":[["Changes","Fixed for the new server classes"]]
};
this.patchModules = {
"Guilds":"componentDidMount",
2019-03-07 23:56:18 +01:00
"RecentMentions":"componentDidMount",
"DirectMessage":"componentDidMount"
};
2019-01-26 22:45:19 +01:00
this.RANcontextMenuMarkup =
`<div class="${BDFDB.disCN.contextmenu} RANbutton-contextmenu">
<div class="${BDFDB.disCN.contextmenuitemgroup}">
<div class="${BDFDB.disCN.contextmenuitem} readguilds-item">
2019-04-18 09:28:20 +02:00
<span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">REPLACE_context_guilds_text</div></span>
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
<div class="${BDFDB.disCN.contextmenuitem} readmutedguilds-item">
2019-04-18 09:28:20 +02:00
<span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">REPLACE_context_mutedguilds_text</div></span>
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
<div class="${BDFDB.disCN.contextmenuitem} readdms-item">
2019-04-18 09:28:20 +02:00
<span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">REPLACE_context_dms_text</div></span>
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
</div>
</div>`;
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>`;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
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>`;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.defaults = {
settings: {
2019-02-08 21:33:47 +01:00
addClearButton: {value:true, inner:false, description:"Adds a 'Clear Mentions' button to the recent mentions popout"},
includeGuilds: {value:true, inner:true, description:"unread Servers"},
includeMuted: {value:false, inner:true, description:"muted unread Servers"},
includeDMs: {value:false, inner:true, description:"unread DMs"}
2018-10-11 10:21:26 +02:00
}
};
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
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-04-18 09:28:20 +02:00
var settingshtml = `<div class="${this.name}-settings BDFDB-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="BDFDB-settings-inner">`;
2019-02-08 21:33:47 +01:00
for (let key in settings) {
if (!this.defaults.settings[key].inner) 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>`;
}
2019-04-18 09:28:20 +02: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: 0 0 auto;">When left clicking the button mark following elements as unread:</h3></div><div class="BDFDB-settings-inner-list">`;
2018-10-11 10:21:26 +02:00
for (let key in settings) {
2019-02-08 21:33:47 +01:00
if (this.defaults.settings[key].inner) 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>`;
2018-10-11 10:21:26 +02:00
settingshtml += `</div></div>`;
2019-01-26 22:45:19 +01:00
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);
let mutedinput = settingspanel.querySelector(".settings-switch[value='settings includeMuted']").parentElement.parentElement;
BDFDB.toggleEles(mutedinput, settings.includeGuilds);
BDFDB.addEventListener(this, settingspanel, "click", ".settings-switch[value='settings includeGuilds']", e => {
BDFDB.toggleEles(mutedinput, e.currentTarget.checked);
});
2018-10-11 10:21:26 +02:00
return settingspanel;
}
//legacy
load () {}
start () {
2019-02-04 09:13:15 +01:00
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
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());
2019-01-30 21:23:49 +01:00
libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) 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);
2019-01-26 22:45:19 +01:00
BDFDB.WebModules.forceAllUpdates(this);
2018-10-11 10:21:26 +02:00
}
else {
2019-02-12 21:56:34 +01:00
console.error(`%c[${this.getName()}]%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);
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-01-26 22:45:19 +01:00
changeLanguageStrings () {
this.RANcontextMenuMarkup = this.RANcontextMenuMarkup.replace("REPLACE_context_guilds_text", this.labels.context_guilds_text);
this.RANcontextMenuMarkup = this.RANcontextMenuMarkup.replace("REPLACE_context_mutedguilds_text", this.labels.context_mutedguilds_text);
this.RANcontextMenuMarkup = this.RANcontextMenuMarkup.replace("REPLACE_context_dms_text", this.labels.context_dms_text);
}
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", () => {
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);
});
2019-01-17 23:48:29 +01:00
BDFDB.addClass(wrapper, "RAN-added");
}
}
2019-01-26 22:45:19 +01:00
2019-03-07 23:56:18 +01:00
processDirectMessage (instance, wrapper, methodnames) {
let ranbutton = document.querySelector(".RANbutton-frame");
let guildseparator = wrapper.parentElement.parentElement.querySelector(BDFDB.dotCN.guildseparator);
if (ranbutton && guildseparator) guildseparator.parentElement.insertBefore(ranbutton, guildseparator);
}
processRecentMentions (instance, wrapper) {
BDFDB.removeEles(".RAMbutton");
2019-02-08 21:33:47 +01:00
if (instance.props && instance.props.popoutName == "RECENT_MENTIONS_POPOUT" && BDFDB.getData("addClearButton", this, "settings")) {
let recentmentionstitle = wrapper.querySelector(BDFDB.dotCN.messagespopouttitle);
2019-01-17 23:48:29 +01:00
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");
}
}
}
2019-01-26 22:45:19 +01:00
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);
}
2019-03-07 23:56:18 +01:00
}
setLabelsByLanguage () {
switch (BDFDB.getDiscordLanguage().id) {
case "hr": //croatian
return {
context_guilds_text: "Poslužitelji",
context_mutedguilds_text: "Prigušeni Poslužitelji",
context_dms_text: "Prikvacene Izravne"
};
case "da": //danish
return {
context_guilds_text: "Servere",
context_mutedguilds_text: "Dæmpede Servere",
context_dms_text: "Private Beskeder"
};
case "de": //german
return {
context_guilds_text: "Server",
2019-03-29 19:50:03 +01:00
context_mutedguilds_text: "Stummgeschaltene Server",
context_dms_text: "Direktnachrichten"
};
case "es": //spanish
return {
context_guilds_text: "Servidores",
context_mutedguilds_text: "Servidores silenciados",
context_dms_text: "Mensajes directos"
};
case "fr": //french
return {
context_guilds_text: "Serveurs",
context_mutedguilds_text: "Serveurs en sourdine",
context_dms_text: "Messages privés"
};
case "it": //italian
return {
context_guilds_text: "Server",
context_mutedguilds_text: "Server disattivati",
context_dms_text: "Messaggi diretti"
};
case "nl": //dutch
return {
context_guilds_text: "Servers",
context_mutedguilds_text: "Gedempte Servers",
context_dms_text: "Prive Berichten"
};
case "no": //norwegian
return {
context_guilds_text: "Servere",
context_mutedguilds_text: "Dempet Servere",
context_dms_text: "Direktemeldinger"
};
case "pl": //polish
return {
context_guilds_text: "Serwery",
context_mutedguilds_text: "Wyciszone Serwery",
context_dms_text: "Prywatne Wiadomości"
};
case "pt-BR": //portuguese (brazil)
return {
context_guilds_text: "Servidores",
context_mutedguilds_text: "Servidores Silenciosos",
context_dms_text: "Mensagens Diretas"
};
case "fi": //finnish
return {
context_guilds_text: "Palvelimet",
context_mutedguilds_text: "Mykistetyt Palvelimet",
context_dms_text: "Yksityisviestit"
};
case "sv": //swedish
return {
context_guilds_text: "Servrar",
context_mutedguilds_text: "Dämpade Servrar",
context_dms_text: "Direktmeddelanden"
};
case "tr": //turkish
return {
context_guilds_text: "Sunucular",
context_mutedguilds_text: "Sessiz Sunucular",
context_dms_text: "Özel Mesajlar"
};
case "cs": //czech
return {
context_guilds_text: "Servery",
context_mutedguilds_text: "Tlumené Servery",
context_dms_text: "Přímé Zpráva"
};
case "bg": //bulgarian
return {
context_guilds_text: "Сървъри",
context_mutedguilds_text: "приглушени Сървъри",
context_dms_text: "директно Съобщение"
};
case "ru": //russian
return {
context_guilds_text: "Серверы",
context_mutedguilds_text: "Отключенные Серверы",
context_dms_text: "Прямые Сообщения"
};
case "uk": //ukrainian
return {
context_guilds_text: "Сервери",
context_mutedguilds_text: "Приглушені Сервери",
context_dms_text: "Прямі Повідомлення"
};
case "ja": //japanese
return {
context_guilds_text: "サーバー",
context_mutedguilds_text: "ミュートサーバー",
context_dms_text: "ダイレクトメッセージ"
};
case "zh-TW": //chinese (traditional)
return {
context_guilds_text: "服務器",
context_mutedguilds_text: "靜音服務器",
context_dms_text: "直接消息",
};
case "ko": //korean
return {
context_guilds_text: "서버",
context_mutedguilds_text: "음소거 된 서버",
context_dms_text: "직접 메시지"
};
default: //default: english
return {
context_guilds_text: "Servers",
context_mutedguilds_text: "Muted Servers",
context_dms_text: "Direct Messages"
};
}
}
2018-10-11 10:21:26 +02:00
}