BetterDiscordAddons/Plugins/RemoveBlockedMessages/RemoveBlockedMessages.plugi...

97 lines
4.1 KiB
JavaScript
Raw Normal View History

2020-02-27 08:44:03 +01:00
//META{"name":"RemoveBlockedMessages","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/RemoveBlockedMessages","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/RemoveBlockedMessages/RemoveBlockedMessages.plugin.js"}*//
2020-02-04 10:22:02 +01:00
var RemoveBlockedMessages = (_ => {
return class RemoveBlockedMessages {
getName () {return "RemoveBlockedMessages";}
2020-09-16 16:20:38 +02:00
getVersion () {return "1.0.5";}
2020-02-04 10:22:02 +01:00
getAuthor () {return "DevilBro";}
2020-09-16 16:20:38 +02:00
getDescription () {return "Completely removes blocked messages.";}
2020-02-04 10:22:02 +01:00
2020-08-15 14:24:48 +02:00
constructor () {
this.changelog = {
2020-09-16 16:20:38 +02:00
"fixed":[["Date Deviders","No longer shows date deviders of blocked messages"]]
2020-08-15 14:24:48 +02:00
};
2020-02-04 10:22:02 +01:00
this.patchedModules = {
2020-08-15 14:24:48 +02:00
after: {
Messages: "type"
2020-02-04 10:22:02 +01:00
}
};
}
2020-04-11 19:32:58 +02:00
// Legacy
2020-08-21 16:17:47 +02:00
load () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) BDFDB.PluginUtils.load(this);
}
2020-02-04 10:22:02 +01:00
start () {
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("id", "BDFDBLibraryScript");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", _ => {this.initialize();});
document.head.appendChild(libraryScript);
}
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(_ => {
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
}
initialize () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.PluginUtils.init(this);
2020-08-15 14:24:48 +02:00
BDFDB.MessageUtils.rerenderAll();
2020-02-04 10:22:02 +01:00
}
else {
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
}
}
stop () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
this.stopping = true;
2020-08-15 14:24:48 +02:00
BDFDB.MessageUtils.rerenderAll();
2020-02-04 10:22:02 +01:00
BDFDB.PluginUtils.clear(this);
}
}
2020-04-11 19:32:58 +02:00
// Begin of own functions
2020-02-04 10:22:02 +01:00
processMessages (e) {
2020-08-15 20:35:58 +02:00
let messagesIns = e.returnvalue.props.children;
2020-09-16 16:20:38 +02:00
if (BDFDB.ArrayUtils.is(messagesIns.props.channelStream)) {
let oldStream = messagesIns.props.channelStream.filter(n => n.type != "MESSAGE_GROUP_BLOCKED"), newChannelStream = [];
for (let i in oldStream) {
let next = parseInt(i)+1;
if (oldStream[i].type != "DIVIDER" || (oldStream[next] && oldStream[i].type == "DIVIDER" && oldStream[next].type != "DIVIDER" && oldStream.slice(next).some(nextStream => nextStream.type != "DIVIDER"))) newChannelStream.push(oldStream[i]);
}
messagesIns.props.channelStream = newChannelStream;
}
2020-08-15 20:35:58 +02:00
if (BDFDB.ObjectUtils.is(messagesIns.props.messages) && BDFDB.ArrayUtils.is(messagesIns.props.messages._array)) {
let messages = messagesIns.props.messages;
messagesIns.props.messages = new BDFDB.DiscordObjects.Messages(messages);
for (let key in messages) messagesIns.props.messages[key] = messages[key];
messagesIns.props.messages._array = [].concat(messagesIns.props.messages._array.filter(n => n.author && !BDFDB.LibraryModules.FriendUtils.isBlocked(n.author.id)));
if (messagesIns.props.oldestUnreadMessageId && messagesIns.props.messages._array.every(n => n.id != messagesIns.props.oldestUnreadMessageId)) messagesIns.props.oldestUnreadMessageId = null;
2020-02-04 10:22:02 +01:00
}
}
}
2020-07-26 16:39:51 +02:00
})();
module.exports = RemoveBlockedMessages;