This commit is contained in:
Mirco Wittrien 2019-10-18 12:16:34 +02:00
parent f91da34fc2
commit dae9763b0b
2 changed files with 31 additions and 33 deletions

View File

@ -1,6 +1,6 @@
if (window.BDFDB && BDFDB.ListenerUtils && typeof BDFDB.ListenerUtils.remove == "function") BDFDB.ListenerUtils.remove(BDFDB);
if (window.BDFDB && BDFDB.WebModules && typeof BDFDB.WebModules.unpatchall == "function") BDFDB.WebModules.unpatchall(BDFDB);
if (window.BDFDB && BDFDB.ObserverUtils && typeof BDFDB.ObserverUtils.disconnect == "function") BDFDB.ObserverUtils.disconnect(BDFDB);
if (window.BDFDB && BDFDB.WebModules && typeof BDFDB.WebModules.unpatchall == "function") BDFDB.WebModules.unpatchall(BDFDB);
var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api: BDFDB && BDFDB.BDv2Api ? BDFDB.BDv2Api : undefined, creationTime: performance.now(), cachedData: {}, pressedKeys: [], mousePosition: {pageX: 0, pageY: 0}, name: "$BDFDB"};
(() => {
var id = Math.round(Math.random() * 10000000000000000), InternalBDFDB = {};
@ -31,8 +31,9 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
}
if (typeof plugin.css === "string") BDFDB.appendLocalStyle(plugin.name, plugin.css);
BDFDB.WebModules.patchModules(plugin);
BDFDB.WebModules.patchModules(plugin);
InternalBDFDB.addOnSwitchListener(plugin);
InternalBDFDB.addContextListeners(plugin);
BDFDB.PluginUtils.translate(plugin);
@ -63,17 +64,16 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
if (typeof plugin.css === "string") BDFDB.removeLocalStyle(plugin.name);
BDFDB.WebModules.unpatchall(plugin);
BDFDB.removeOnSwitchListener(plugin);
BDFDB.ListenerUtils.remove(plugin);
BDFDB.ObserverUtils.disconnect(plugin);
BDFDB.WebModules.unpatchall(plugin);
InternalBDFDB.removeOnSwitchListener(plugin);
for (let modal of document.querySelectorAll(`.${plugin.name}-modal, .${plugin.name.toLowerCase()}-modal, .${plugin.name}-settingsmodal, .${plugin.name.toLowerCase()}-settingsmodal`)) {
let closebutton = modal.querySelector(BDFDB.dotCN.modalclose);
if (closebutton) closebutton.click();
}
BDFDB.ObserverUtils.disconnect(plugin);
delete window.PluginUpdates.plugins[url];
if (BDFDB.ObjectUtils.isEmpty(window.PluginUpdates.plugins)) BDFDB.removeEles("#bd-settingspane-container .bd-updatebtn" + BDFDB.dotCN._repofolderbutton);
@ -240,6 +240,29 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
clearTimeout(plugin.libLoadTimeout);
delete plugin.libLoadTimeout;
};
InternalBDFDB.addOnSwitchListener = function (plugin) {
if (BDFDB.ObjectUtils.is(plugin) && typeof plugin.onSwitch === "function") {
InternalBDFDB.removeOnSwitchListener(plugin);
var spacer = document.querySelector(`${BDFDB.dotCN.guildswrapper} ~ * > ${BDFDB.dotCN.chatspacer}`);
if (spacer) {
var nochannelobserver = new MutationObserver(changes => {changes.forEach(change => {
if (change.target && BDFDB.containsClass(change.target, BDFDB.disCN.nochannel)) plugin.onSwitch();
});});
var nochannel = spacer.querySelector(BDFDB.dotCNC.chat + BDFDB.dotCN.nochannel);
if (nochannel) nochannelobserver.observe(nochannel, {attributes:true});
plugin.onSwitchFix = new MutationObserver(changes => {changes.forEach(change => {if (change.addedNodes) {change.addedNodes.forEach(node => {
if (BDFDB.containsClass(node, BDFDB.disCN.chat, BDFDB.disCN.nochannel, false)) nochannelobserver.observe(node, {attributes:true});
});}});});
plugin.onSwitchFix.observe(spacer, {childList:true});
}
}
};
InternalBDFDB.removeOnSwitchListener = function (plugin) {
if (BDFDB.ObjectUtils.is(plugin) && typeof plugin.onSwitch === "function" && BDFDB.ObjectUtils.is(plugin.onSwitchFix)) {
plugin.onSwitchFix.disconnect();
delete plugin.onSwitchFix;
}
};
BDFDB.ObserverUtils = {};
BDFDB.ObserverUtils.connect = function (plugin, eleOrSelec, observer, config = {childList: true}) {
@ -1482,31 +1505,6 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
}
};
BDFDB.addOnSwitchListener = function (plugin) {
if (typeof plugin.onSwitch === "function") {
BDFDB.removeOnSwitchListener(plugin);
var spacer = document.querySelector(`${BDFDB.dotCN.guildswrapper} ~ * > ${BDFDB.dotCN.chatspacer}`);
if (spacer) {
var nochannelobserver = new MutationObserver(changes => {changes.forEach(change => {
if (change.target && BDFDB.containsClass(change.target, BDFDB.disCN.nochannel)) plugin.onSwitch();
});});
var nochannel = spacer.querySelector(BDFDB.dotCNC.chat + BDFDB.dotCN.nochannel);
if (nochannel) nochannelobserver.observe(nochannel, {attributes:true});
plugin.onSwitchFix = new MutationObserver(changes => {changes.forEach(change => {if (change.addedNodes) {change.addedNodes.forEach(node => {
if (BDFDB.containsClass(node, BDFDB.disCN.chat, BDFDB.disCN.nochannel, false)) nochannelobserver.observe(node, {attributes:true});
});}});});
plugin.onSwitchFix.observe(spacer, {childList:true});
}
}
};
BDFDB.removeOnSwitchListener = function (plugin) {
if (typeof plugin.onSwitch === "function" && BDFDB.ObjectUtils.is(plugin.onSwitchFix)) {
plugin.onSwitchFix.disconnect();
delete plugin.onSwitchFix;
}
};
var NoFluxContextMenus = ["ChannelContextMenu", "DeveloperContextMenu", "GuildContextMenu", "GuildRoleContextMenu", "LfgContextMenu", "MessageContextMenu", "NativeContextMenu", "ScreenshareContextMenu", "UserContextMenu", "UserSettingsCogContextMenu"];
var NoFluxPopouts = ["MessageOptionPopout"];
var FluxContextMenus = ["ApplicationContextMenu", "GroupDMContextMenu"];

File diff suppressed because one or more lines are too long