EditChannels now uses patching instead of observing

This commit is contained in:
Mirco Wittrien 2018-12-26 21:00:43 +01:00
parent 5b45fc7c67
commit dcb831c97b
1 changed files with 240 additions and 257 deletions

View File

@ -4,7 +4,14 @@ class EditChannels {
initConstructor () { initConstructor () {
this.labels = {}; this.labels = {};
this.updateChannels = false; this.moduleTypes = {
"ChannelTextArea":"componentDidMount",
"AuditLog":"componentDidMount",
"ChannelCategoryItem":"componentDidMount",
"ChannelItem":"componentDidMount",
"HeaderBar":["componentDidMount","componentDidUpdate"],
"Clickable":"componentDidMount"
};
this.channelContextEntryMarkup = this.channelContextEntryMarkup =
`<div class="${BDFDB.disCN.contextmenuitemgroup}"> `<div class="${BDFDB.disCN.contextmenuitemgroup}">
@ -84,8 +91,7 @@ class EditChannels {
this.defaults = { this.defaults = {
settings: { settings: {
changeChannelIcon: {value:true, description:"Change color of Channel Icon."}, changeChannelIcon: {value:true, description:"Change color of Channel Icon."},
changeUnreadIndicator: {value:true, description:"Change color of Unread Indicator."}, changeUnreadIndicator: {value:true, description:"Change color of Unread Indicator."}
changeInChannelHeader: {value:true, description:"Change in Channel Header."}
} }
}; };
} }
@ -94,7 +100,7 @@ class EditChannels {
getDescription () {return "Allows you to rename and recolor channelnames.";} getDescription () {return "Allows you to rename and recolor channelnames.";}
getVersion () {return "3.8.2";} getVersion () {return "3.8.3";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -114,7 +120,12 @@ class EditChannels {
$(settingspanel) $(settingspanel)
.on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);}) .on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);})
.on("click", ".reset-button", () => {this.resetAll();}); .on("click", ".reset-button", () => {
if (confirm("Are you sure you want to reset all channels?")) {
BDFDB.removeAllData(this, "channels");
this.forceAllUpdates();
}
});
return settingspanel; return settingspanel;
} }
@ -140,74 +151,18 @@ class EditChannels {
if (typeof BDFDB === "object") { if (typeof BDFDB === "object") {
BDFDB.loadMessage(this); BDFDB.loadMessage(this);
for (let type in this.moduleTypes) {
let module = BDFDB.WebModules.findByName(type);
if (module && module.prototype) BDFDB.WebModules.patch(module.prototype, this.moduleTypes[type], this, {after: (e) => {this.initiateProcess(e.thisObject, type);}});
}
this.UserUtils = BDFDB.WebModules.findByProperties("getUsers","getUser");
this.ChannelUtils = BDFDB.WebModules.findByProperties("getChannels","getChannel");
this.CurrentChannelUtils = BDFDB.WebModules.findByProperties("getChannels","getDefaultChannel");
this.LastGuildStore = BDFDB.WebModules.findByProperties("getLastSelectedGuildId"); this.LastGuildStore = BDFDB.WebModules.findByProperties("getLastSelectedGuildId");
this.LastChannelStore = BDFDB.WebModules.findByProperties("getLastSelectedChannelId");
var observer = null; this.forceAllUpdates();
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.attributeName == "class") {
var node = change.target;
if (node.className && node.className.length > -1 && node.className.includes("wrapper") && $("[custom-editchannels]").has(node)[0]) {
let info = BDFDB.getKeyInformation({"node":node, "key":"channel"});
if (info) this.loadChannel(BDFDB.getDivOfChannel(info.id));
}
}
if (change.addedNodes) {
change.addedNodes.forEach((node) => {
if (node && node.classList && (node.classList.contains(BDFDB.disCN.channelcontainerdefault) || node.classList.contains(BDFDB.disCN.categorycontainerdefault))) {
let info = BDFDB.getKeyInformation({"node":node, "key":"channel"});
if (info) this.loadChannel(BDFDB.getDivOfChannel(info.id));
}
if (node.className && node.className.length > -1 && node.className.includes("container-")) {
for (let channel of node.querySelectorAll(BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault)) {
let info = BDFDB.getKeyInformation({"node":channel, "key":"channel"});
if (info) this.loadChannel(BDFDB.getDivOfChannel(info.id));
}
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.channels, {name:"channelListObserver",instance:observer}, {childList: true, attributes:true, subtree: true});
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.removedNodes) {
change.removedNodes.forEach((node) => {
if (this.updateChannels && node.tagName && node.getAttribute("layer-id") == "user-settings") {
this.resetAllChannels();
this.loadAllChannels();
this.updateChannels = false;
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.layers, {name:"settingsWindowObserver",instance:observer}, {childList:true});
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.addedNodes) {
change.addedNodes.forEach((node) => {
if (node && node.nodeType == 1 && node.className.includes(BDFDB.disCN.contextmenu)) {
this.onContextMenu(node);
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.appmount, {name:"channelContextObserver",instance:observer}, {childList: true});
this.loadAllChannels();
this.changeChannelHeader();
} }
else { else {
console.error(this.getName() + ": Fatal Error: Could not load BD functions!"); console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
@ -216,25 +171,15 @@ class EditChannels {
stop () { stop () {
if (typeof BDFDB === "object") { if (typeof BDFDB === "object") {
this.resetAllChannels(); let data = BDFDB.loadAllData(this, "channels");
BDFDB.removeAllData(this, "channels");
this.forceAllUpdates();
BDFDB.saveAllData(data, this, "channels");
BDFDB.unloadMessage(this); BDFDB.unloadMessage(this);
} }
} }
onSwitch () {
if (typeof BDFDB === "object") {
var channelHeader = document.querySelector(BDFDB.dotCN.channelheadertitletext + "[custom-editchannelsheader]");
if (channelHeader) {
channelHeader.removeAttribute("custom-editchannelsheader");
var channel = channelHeader.querySelector(BDFDB.dotCN.channelheaderchannelname + BDFDB.dotCN.channelheaderprivate);
if (channel) this.uncolorChannel(channel);
}
this.loadAllChannels();
setImmediate(() => {this.changeChannelHeader();}); //setImmediate so EditChannels sets the color after EditUsers set it back to white
}
}
// begin of own functions // begin of own functions
@ -247,14 +192,6 @@ class EditChannels {
this.updateChannels = true; this.updateChannels = true;
} }
resetAll () {
if (confirm("Are you sure you want to reset all channels?")) {
BDFDB.removeAllData(this, "channels");
this.resetAllChannels();
}
}
changeLanguageStrings () { changeLanguageStrings () {
this.channelContextEntryMarkup = this.channelContextEntryMarkup.replace("REPLACE_context_localchannelsettings_text", this.labels.context_localchannelsettings_text); this.channelContextEntryMarkup = this.channelContextEntryMarkup.replace("REPLACE_context_localchannelsettings_text", this.labels.context_localchannelsettings_text);
@ -267,39 +204,29 @@ class EditChannels {
this.channelSettingsModalMarkup = this.channelSettingsModalMarkup.replace("REPLACE_btn_save_text", this.labels.btn_save_text); this.channelSettingsModalMarkup = this.channelSettingsModalMarkup.replace("REPLACE_btn_save_text", this.labels.btn_save_text);
} }
onContextMenu (context) { onChannelContextMenu (instance, menu) {
if (!context || !context.tagName || !context.parentElement || context.querySelector(".localchannelsettings-item")) return; if (instance.props && instance.props.channel && !menu.querySelector(".localchannelsettings-item")) {
var info = BDFDB.getKeyInformation({"node":context, "key":"channel"}); $(menu).append(this.channelContextEntryMarkup)
if (info && BDFDB.getKeyInformation({"node":context, "key":"displayName", "value":"ChannelDeleteGroup"})) {
$(context).append(this.channelContextEntryMarkup)
.on("mouseenter", ".localchannelsettings-item", (e) => { .on("mouseenter", ".localchannelsettings-item", (e) => {
this.createContextSubMenu(info, e, context); var channelContextSubMenu = $(this.channelContextSubMenuMarkup);
}); channelContextSubMenu
.on("click", ".channelsettings-item", () => {
BDFDB.updateContextPosition(context); $(menu).hide();
} this.showChannelSettings(instance.props.channel);
} });
if (BDFDB.loadData(instance.props.channel.id, this, "channels")) {
createContextSubMenu (info, e, context) { channelContextSubMenu
var channelContextSubMenu = $(this.channelContextSubMenuMarkup); .find(".resetsettings-item")
.removeClass(BDFDB.disCN.contextmenuitemdisabled)
channelContextSubMenu .on("click", () => {
.on("click", ".channelsettings-item", () => { $(menu).hide();
$(context).hide(); BDFDB.removeData(instance.props.channel.id, this, "channels");
this.showChannelSettings(info); this.forceAllUpdates();
}); });
}
if (BDFDB.loadData(info.id, this, "channels")) { BDFDB.appendSubMenu(e.currentTarget, channelContextSubMenu);
channelContextSubMenu
.find(".resetsettings-item")
.removeClass(BDFDB.disCN.contextmenuitemdisabled)
.on("click", () => {
$(context).hide();
this.removeChannelData(info);
}); });
} }
BDFDB.appendSubMenu(e.currentTarget, channelContextSubMenu);
} }
showChannelSettings (info) { showChannelSettings (info) {
@ -332,175 +259,231 @@ class EditChannels {
if (color[0] < 30 && color[1] < 30 && color[2] < 30) BDFDB.colorCHANGE(color, 30); if (color[0] < 30 && color[1] < 30 && color[2] < 30) BDFDB.colorCHANGE(color, 30);
else if (color[0] > 225 && color[1] > 225 && color[2] > 225) BDFDB.colorCHANGE(color, -30); else if (color[0] > 225 && color[1] > 225 && color[2] > 225) BDFDB.colorCHANGE(color, -30);
} }
if (name == null && color == null) { if (name == null && color == null) {
this.removeChannelData(info); BDFDB.removeData(info.id, this, "channels");
} }
else { else {
BDFDB.saveData(info.id, {name,color}, this, "channels"); BDFDB.saveData(info.id, {name,color}, this, "channels");
this.loadChannel(channelObj);
this.changeChannelHeader();
} }
this.forceAllUpdates();
}); });
channelSettingsModal.find("#input-channelname").focus(); channelSettingsModal.find("#input-channelname").focus();
} }
removeChannelData (info) { initiateProcess (instance, type) {
this.resetChannel(BDFDB.getDivOfChannel(info.id)); type = type.replace(/[^A-z]/g,"");
type = type[0].toUpperCase() + type.slice(1);
BDFDB.removeData(info.id, this, "channels"); if (typeof this["process" + type] == "function") {
let wrapper = BDFDB.React.findDOMNodeSafe(instance);
this.changeChannelHeader(); if (wrapper) this["process" + type](instance, wrapper);
else setImmediate(() => {
this["process" + type](instance, BDFDB.React.findDOMNodeSafe(instance));
});
}
} }
resetChannel (channelObj) { processChannelTextArea (instance, wrapper) {
if (!channelObj || !channelObj.div) return; if (!wrapper) return;
if (instance.props && instance.props.type == "normal" && instance.props.channel && instance.props.channel.type == 0) {
var channel = channelObj.div.querySelector(BDFDB.dotCNC.channelname + BDFDB.dotCN.categorycolortransition); let channel = instance.props.channel;
let data = BDFDB.loadData(channel.id, this, "channels") || {};
if (channel && channel.EditChannelsObserver && typeof channel.EditChannelsObserver.disconnect == "function") channel.EditChannelsObserver.disconnect(); wrapper.querySelector("textarea").setAttribute("placeholder", BDFDB.LanguageStrings.TEXTAREA_PLACEHOLDER.replace("{{channel}}", "#" + (data.name || channel.name)));
}
channelObj.div.removeAttribute("custom-editchannels");
this.uncolorChannel(channel);
BDFDB.setInnerText(channel, channelObj.name);
} }
loadChannel (channelObj) { processAuditLog (instance, wrapper) {
if (!channelObj || !channelObj.div) return; if (!wrapper) return;
if (instance.props && instance.props.log && instance.props.log.options && instance.props.log.options.channel) {
let hooks = wrapper.querySelectorAll(BDFDB.dotCN.flexchild + " > span:not(" + BDFDB.dotCN.auditloguserhook + ")");
if (hooks.length > 0) this.changeChannel2(instance.props.log.options.channel, hooks[0].firstChild);
}
}
var channel = channelObj.div.querySelector(BDFDB.dotCNC.channelname + BDFDB.dotCN.categorycolortransition); processChannelCategoryItem (instance, wrapper) {
if (!wrapper) return;
if (instance.props && instance.props.channel) {
this.changeChannel(instance.props.channel, wrapper.querySelector(BDFDB.dotCN.categorycolortransition));
}
}
if (channel && channel.EditChannelsObserver && typeof channel.EditChannelsObserver.disconnect == "function") channel.EditChannelsObserver.disconnect(); processChannelItem (instance, wrapper) {
if (!wrapper) return;
if (instance.props && instance.props.channel) {
this.changeChannel(instance.props.channel, wrapper.querySelector(BDFDB.dotCN.channelname));
}
}
var data = BDFDB.loadData(channelObj.id, this, "channels"); processHeaderBar (instance, wrapper) {
if (data) { let fiber = instance._reactInternalFiber;
var name = data.name ? data.name : channelObj.name; if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.channelId) {
var color = data.color ? this.chooseColor(channel, data.color) : ""; let channelname = wrapper.querySelector(BDFDB.dotCN.channelheaderchannelname);
if (channelname) {
let channel = this.ChannelUtils.getChannel(fiber.return.memoizedProps.channelId);
if (channel) {
if (channel.type == 0) this.changeChannel(channel, wrapper.querySelector(BDFDB.dotCN.channelheaderchannelname));
else {
if (channel.type == 1) channel = this.UserUtils.getUser(channel.recipients[0]) || channel;
if (channelname.EditChannelsChangeObserver && typeof channelname.EditChannelsChangeObserver.disconnect == "function") channelname.EditChannelsChangeObserver.disconnect();
channelname.style.removeProperty("color");
channelname.style.removeProperty("background");
BDFDB.setInnerText(channelname, channel.name);
}
}
}
}
}
this.colorChannel(channel, color); processClickable (instance, wrapper) {
if (color) { if (!wrapper || !instance.props || !instance.props.className) return;
channel.EditChannelsObserver = new MutationObserver((changes, _) => { else if (instance.props.tag == "span" && instance.props.className.indexOf(BDFDB.disCN.mentionwrapper) > -1 && instance.props.className.indexOf(BDFDB.disCN.mention) == -1) {
changes.forEach( let fiber = instance._reactInternalFiber;
(change, i) => { if (fiber.memoizedProps && fiber.memoizedProps.children && typeof fiber.memoizedProps.children[0] == "string") {
if (change.type == "childList" && change.addedNodes.length && change.target.tagName && (change.target.tagName == "SVG" || change.target.querySelector("svg")) || change.type == "attributes" && change.attributeName == "class" && change.target.className.length && change.target.className.indexOf("name") > -1) { let channelname = fiber.memoizedProps.children[0].slice(1);
this.colorChannel(channel, this.chooseColor(channel, data.color)); let categoryname = fiber.return && fiber.return.return && fiber.return.return.type && fiber.return.return.type.displayName == "Tooltip" ? fiber.return.return.memoizedProps.text : null;
} for (let channel of this.CurrentChannelUtils.getChannels(this.LastGuildStore.getGuildId())[0]) {
if (channelname == channel.channel.name) {
let category = categoryname ? this.ChannelUtils.getChannel(channel.channel.parent_id) : null;
if (!category || category && categoryname == category.name) {
this.changeMention(channel.channel, wrapper, category || {});
break;
} }
); }
});
channel.EditChannelsObserver.observe(channel.parentElement, {attributes:true, childList:true, subtree:true});
}
BDFDB.setInnerText(channel, name);
}
}
loadAllChannels () {
for (let channelObj of BDFDB.readChannelList()) {
this.loadChannel(channelObj);
}
}
changeChannelHeader () {
if (BDFDB.getData("changeInChannelHeader", this, "settings") && this.LastGuildStore.getGuildId()) {
var channelHeader = document.querySelector(BDFDB.dotCNS.channelheadertitle + BDFDB.dotCN.channelheadertitletext);
if (!channelHeader) return;
var channel = channelHeader.querySelector(BDFDB.dotCN.channelheaderchannelname);
if (!channel) return;
var info = BDFDB.getKeyInformation({"node":channelHeader,"key":"channel"});
if (info) {
var data = BDFDB.loadData(info.id, this, "channels");
var name = data && data.name ? data.name : info.name;
var color = data && data.color ? BDFDB.colorCHANGE(data.color, 0.5, "RGB") : "";
if (data && (data.name || data.color)) {
channelHeader.setAttribute("custom-editchannelsheader", true);
this.colorChannel(channel, color);
} }
else { }
channelHeader.removeAttribute("custom-editchannelsheader"); }
this.uncolorChannel(channel); else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.quickswitchresult) > -1) {
let fiber = instance._reactInternalFiber;
if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.result && fiber.return.memoizedProps.result.type == "TEXT_CHANNEL") {
this.changeChannel(fiber.return.memoizedProps.result.record, wrapper.querySelector(BDFDB.dotCN.quickswitchresultmatch));
if (fiber.return.memoizedProps.result.record.parent_id) {
this.changeChannel(this.ChannelUtils.getChannel(fiber.return.memoizedProps.result.record.parent_id), wrapper.querySelector(BDFDB.dotCN.quickswitchresultnote));
} }
}
BDFDB.setInnerText(channel, name); }
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.autocompleterow) > -1) {
let fiber = instance._reactInternalFiber;
if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.channel) {
this.changeChannel(fiber.return.memoizedProps.channel, wrapper.querySelector(BDFDB.dotCN.marginleft4));
if (fiber.return.memoizedProps.category) this.changeChannel(fiber.return.memoizedProps.category, wrapper.querySelector(BDFDB.dotCN.autocompletedescription));
} }
} }
} }
resetAllChannels () { changeChannel (info, channelname) {
document.querySelectorAll("[custom-editchannels]").forEach(channelDiv => { if (!info || !channelname || !channelname.parentElement) return;
var info = BDFDB.getKeyInformation({"node":channelDiv, "key":"channel"}); if (channelname.EditChannelsChangeObserver && typeof channelname.EditChannelsChangeObserver.disconnect == "function") channelname.EditChannelsChangeObserver.disconnect();
if (info) this.resetChannel({div:channelDiv,info}); let data = BDFDB.loadData(info.id, this, "channels") || {};
}); let settings = BDFDB.getAllData(this, "settings");
let color = this.chooseColor(channelname, data.color);
var channelHeader = document.querySelector("[custom-editchannelsheader]"); channelname.style.setProperty("color", color, "important");
if (channelHeader) { BDFDB.setInnerText(channelname, data.name || info.name);
var info = BDFDB.getKeyInformation({"node":channelHeader, "key":"channel"}); let iconparent = channelname.classList && channelname.classList.contains(BDFDB.disCN.quickswitchresultmatch) ? channelname.parentElement.parentElement : channelname.parentElement;
if (info) { if (channelname.classList && !channelname.classList.contains(BDFDB.disCN.autocompletedescription)) {
var channel = channelHeader.querySelector(BDFDB.dotCN.channelheaderchannelname); iconparent.querySelectorAll('svg [stroke]:not([stroke="none"]').forEach(icon => {
if (!icon.getAttribute("oldstroke")) icon.setAttribute("oldstroke", icon.getAttribute("stroke"));
channelHeader.removeAttribute("custom-editchannelsheader"); icon.setAttribute("stroke", color && settings.changeChannelIcon ? color : icon.getAttribute("oldstroke"), "important");
channel.style.removeProperty("color"); icon.style.setProperty("stroke", color && settings.changeChannelIcon ? color : icon.getAttribute("oldstroke"), "important");
BDFDB.setInnerText(channel, info.name);
}
}
}
colorChannel (channel, color) {
if (!channel) return;
var settings = BDFDB.getAllData(this, "settings");
channel.style.setProperty("color", color, "important");
if (settings.changeChannelIcon) {
channel.parentElement.querySelectorAll("svg [stroke='currentColor'], svg [stroke='#ffffff'], svg [oldstroke]").forEach(icon => {
icon.setAttribute("oldstroke", icon.getAttribute("oldstroke") || icon.getAttribute("stroke"));
icon.setAttribute("stroke", color, "important");
}); });
channel.parentElement.querySelectorAll("svg [fill='currentColor'], svg [fill='#ffffff'], svg [oldfill]").forEach(icon => { iconparent.querySelectorAll('svg [fill]:not([fill="none"]').forEach(icon => {
icon.setAttribute("oldfill", icon.getAttribute("oldfill") || icon.getAttribute("fill")); if (!icon.getAttribute("oldfill")) icon.setAttribute("oldfill", icon.getAttribute("fill"));
icon.setAttribute("fill", color, "important"); icon.setAttribute("fill", color && settings.changeChannelIcon ? color : icon.getAttribute("oldfill"), "important");
icon.style.setProperty("fill", color && settings.changeChannelIcon ? color : icon.getAttribute("oldfill"), "important");
}); });
let unread = iconparent.querySelector(BDFDB.dotCN.channelunread);
if (unread) unread.style.setProperty("background-color", color && settings.changeUnreadIndicator ? color : "currentColor", "important");
} }
if (settings.changeUnreadIndicator) { if (color) {
var unread = channel.parentElement.querySelector(BDFDB.dotCN.channelunread); channelname.EditChannelsChangeObserver = new MutationObserver((changes, _) => {
if (unread) unread.style.setProperty("background-color", color, "important"); changes.forEach(
(change, i) => {
if (change.type == "childList" && change.addedNodes.length && change.target.tagName && (change.target.tagName == "SVG" || change.target.querySelector("svg")) || change.type == "attributes" && change.attributeName == "class" && change.target.className.length && change.target.className.indexOf("name") > -1) {
channelname.EditChannelsChangeObserver.disconnect();
this.changeChannel(info, channelname);
}
}
);
});
channelname.EditChannelsChangeObserver.observe(iconparent, {attributes:true, childList:true, subtree:true});
} }
} }
uncolorChannel (channel) { changeChannel2 (info, channelname) {
if (!channel) return; if (!info || !channelname || !channelname.parentElement) return;
channel.style.removeProperty("color"); if (channelname.EditChannelsChangeObserver && typeof channelname.EditChannelsChangeObserver.disconnect == "function") channelname.EditChannelsChangeObserver.disconnect();
channel.style.removeProperty("background-color"); let data = BDFDB.loadData(info.id, this, "channels") || {};
channel.parentElement.querySelectorAll("svg [oldstroke]").forEach(icon => { let color = this.chooseColor(channelname, data.color);
icon.setAttribute("stroke", icon.getAttribute("oldstroke")); console.log();
icon.removeAttribute("oldstroke"); channelname.style.setProperty("color", color, "important");
}); BDFDB.setInnerText(channelname, "#" + (data.name || info.name));
channel.parentElement.querySelectorAll("svg [oldfill]").forEach(icon => { if (color) {
icon.setAttribute("fill", icon.getAttribute("oldfill")); channelname.EditChannelsChangeObserver = new MutationObserver((changes, _) => {
icon.removeAttribute("oldfill"); changes.forEach(
}); (change, i) => {
var unread = channel.parentElement.querySelector(BDFDB.dotCN.channelunread); if (change.type == "childList" && change.addedNodes.length && change.target.tagName && (change.target.tagName == "SVG" || change.target.querySelector("svg")) || change.type == "attributes" && change.attributeName == "class" && change.target.className.length && change.target.className.indexOf("name") > -1) {
if (unread) unread.style.removeProperty("background-color"); channelname.EditChannelsChangeObserver.disconnect();
this.changeChannel2(info, channelname);
}
}
);
});
channelname.EditChannelsChangeObserver.observe(channelname.parentElement, {attributes:true, childList:true, subtree:true});
}
} }
chooseColor (channel, color) { changeMention (info, mention, categoryinfo) {
if (color && channel && channel.className) { if (!info || !mention || !mention.parentElement) return;
if (channel.className.indexOf("nameMuted") > -1 || channel.className.indexOf("nameLocked") > -1) { if (mention.EditChannelsChangeObserver && typeof mention.EditChannelsChangeObserver.disconnect == "function") mention.EditChannelsChangeObserver.disconnect();
color = BDFDB.colorCHANGE(color, -0.5); let data = BDFDB.loadData(info.id, this, "channels") || {};
} let color = BDFDB.colorCONVERT(data.color, "RGBCOMP");
if (channel.className.indexOf("nameDefault") > -1) { BDFDB.setInnerText(mention, "#" + (data.name || info.name));
color = color; if (mention.EditChannelsHovered) colorHover();
} else colorDefault();
if (channel.className.indexOf("nameSelected") > -1 || channel.className.indexOf("nameHovered") > -1 || channel.className.indexOf("nameUnread") > -1) { $(mention)
color = BDFDB.colorCHANGE(color, 0.5); .off("mouseenter." + this.getName()).off("mouseleave." + this.getName())
} .on("mouseenter." + this.getName(), (e) => {
mention.EditChannelsHovered = true;
colorHover();
let categorydata = BDFDB.loadData(categoryinfo.id, this, "channels") || {};
if (categorydata.name) BDFDB.createTooltip(categorydata.name, mention, {type:"top",selector:"EditChannels-tooltip",css:`body ${BDFDB.dotCN.tooltip}:not(.EditChannels-tooltip) {display: none !important;}`});
})
.on("mouseleave." + this.getName(), (e) => {
mention.EditChannelsHovered = false;
colorDefault();
});
mention.EditChannelsChangeObserver = new MutationObserver((changes, _) => {
mention.EditChannelsChangeObserver.disconnect();
this.changeMention(info, mention, categoryinfo);
});
mention.EditChannelsChangeObserver.observe(mention, {attributes:true});
function colorDefault() {
mention.style.setProperty("color", color ? "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")" : null, "important");
mention.style.setProperty("background", color ? "rgba(" + color[0] + "," + color[1] + "," + color[2] + ",.1)" : null, "important");
}
function colorHover() {
mention.style.setProperty("color", color ? "#FFFFFF" : null, "important");
mention.style.setProperty("background", color ? "rgba(" + color[0] + "," + color[1] + "," + color[2] + ",.7)" : null, "important");
}
}
chooseColor (channelname, color) {
if (color && channelname) {
let classname = channelname.className ? channelname.className.toLowerCase() : "";
if (classname.indexOf("muted") > -1 || classname.indexOf("locked") > -1) color = BDFDB.colorCHANGE(color, -0.5);
else if (classname.indexOf("selected") > -1 || classname.indexOf("hovered") > -1 || classname.indexOf("unread") > -1) color = BDFDB.colorCHANGE(color, 0.5);
return BDFDB.colorCONVERT(color, "RGB"); return BDFDB.colorCONVERT(color, "RGB");
} }
return null; return null;
} }
forceAllUpdates () {
let app = document.querySelector(BDFDB.dotCN.app);
if (app) {
let ins = BDFDB.getOwnerInstance({node:app, name:Object.keys(this.moduleTypes), all:true, noCopies:true, group:true, depth:99999999, time:99999999});
for (let type in ins) for (let i in ins[type]) this.initiateProcess(ins[type][i], type);
}
}
setLabelsByLanguage () { setLabelsByLanguage () {
switch (BDFDB.getDiscordLanguage().id) { switch (BDFDB.getDiscordLanguage().id) {
case "hr": //croatian case "hr": //croatian