BetterDiscordAddons/Plugins/EditChannels/EditChannels.plugin.js

896 lines
47 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"EditChannels","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/EditChannels","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/EditChannels/EditChannels.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class EditChannels {
2019-01-17 23:48:29 +01:00
getName () {return "EditChannels";}
2019-10-21 17:06:50 +02:00
getVersion () {return "4.0.7";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
getDescription () {return "Allows you to rename and recolor channelnames.";}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor () {
2019-02-13 12:00:42 +01:00
this.changelog = {
2019-10-21 17:06:50 +02:00
"fixed":[["Settings","Fixed issue where settings could not be saved"]]
2019-02-13 12:00:42 +01:00
};
2019-09-04 12:34:02 +02:00
2019-11-14 17:56:26 +01:00
this.patchedModules = {
after: {
"ChannelTextArea":"componentDidMount",
"AuditLog":"componentDidMount",
"InviteCard":"render",
"ChannelCategoryItem":["componentDidMount","componentDidUpdate"],
"ChannelItem":["componentDidMount","componentDidUpdate"],
"HeaderBar":["componentDidMount","componentDidUpdate"],
"HeaderBarContainer":["componentDidMount","componentDidUpdate"],
"Clickable":"componentDidMount",
"StandardSidebarView":"componentWillUnmount"
}
};
2019-09-04 12:34:02 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
initConstructor () {
2018-12-14 22:08:19 +01:00
this.css = `
2019-02-13 12:00:42 +01:00
${BDFDB.dotCN.guildsettingsinvitechannelname}[changed-by-editchannels] {
opacity: 1;
}
2018-12-14 22:08:19 +01:00
`;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.defaults = {
settings: {
2019-02-13 12:00:42 +01:00
changeChannelIcon: {value:true, inner:false, description:"Change color of Channel Icon."},
changeUnreadIndicator: {value:true, inner:false, description:"Change color of Unread Indicator."},
changeInChatTextarea: {value:true, inner:true, description:"Chat Textarea"},
changeInMentions: {value:true, inner:true, description:"Mentions"},
changeInChannelList: {value:true, inner:true, description:"Channel List"},
changeInChannelHeader: {value:true, inner:true, description:"Channel Header"},
changeInRecentMentions: {value:true, inner:true, description:"Recent Mentions Popout"},
changeInAutoComplete: {value:true, inner:true, description:"Autocomplete Menu"},
changeInAuditLog: {value:true, inner:true, description:"Audit Log"},
changeInInviteLog: {value:true, inner:true, description:"Invite Log"},
changeInSearchPopout: {value:true, inner:true, description:"Search Popout"}
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;
2019-10-22 23:04:35 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
2019-12-18 16:45:08 +01:00
let settingspanel, settingsitems = [], inneritems = [];
2019-10-16 22:18:15 +02:00
2019-11-01 22:47:23 +01:00
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
2019-10-16 22:18:15 +02:00
className: BDFDB.disCN.marginbottom8,
2019-11-01 22:47:23 +01:00
type: "Switch",
2019-10-16 22:18:15 +02:00
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
2019-10-22 18:55:25 +02:00
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
2019-10-17 18:54:51 +02:00
title: "Change Channels in:",
2019-11-05 08:56:21 +01:00
first: settingsitems.length == 0,
2019-10-17 18:54:51 +02:00
children: inneritems
2019-10-16 22:18:15 +02:00
}));
2019-10-22 18:55:25 +02:00
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
2019-10-16 22:18:15 +02:00
type: "Button",
className: BDFDB.disCN.marginbottom8,
color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Reset all Channels",
onClick: _ => {
2019-10-30 13:27:14 +01:00
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all channels?", () => {
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.remove(this, "channels");
2019-10-17 11:36:34 +02:00
this.forceUpdateAll();
2019-10-16 22:18:15 +02:00
});
},
2019-10-19 11:41:39 +02:00
children: BDFDB.LanguageUtils.LanguageStrings.RESET
2019-10-16 22:18:15 +02:00
}));
2019-12-18 16:45:08 +01:00
return settingspanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
2018-10-11 10:21:26 +02:00
}
//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-05-26 13:55:26 +02:00
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
2018-10-11 10:21:26 +02:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
2019-05-26 13:55:26 +02:00
libraryScript.setAttribute("id", "BDFDBLibraryScript");
2018-10-11 10:21:26 +02:00
libraryScript.setAttribute("type", "text/javascript");
2019-10-18 10:56:41 +02:00
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("date", performance.now());
2019-05-26 13:55:26 +02:00
libraryScript.addEventListener("load", () => {this.initialize();});
2018-10-11 10:21:26 +02:00
document.head.appendChild(libraryScript);
2019-05-26 13:55:26 +02:00
}
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2019-11-01 10:27:07 +01:00
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);
2018-10-11 10:21:26 +02:00
}
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;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.init(this);
2019-01-26 22:45:19 +01:00
2019-08-19 11:17:57 +02:00
var observer = new MutationObserver(() => {this.changeAppTitle();});
2019-10-22 18:55:25 +02:00
BDFDB.ObserverUtils.connect(this, document.head.querySelector("title"), {name:"appTitleObserver",instance:observer}, {childList:true});
2019-10-17 11:36:34 +02:00
this.forceUpdateAll();
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01:00
else 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) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-10-22 19:49:57 +02:00
let data = BDFDB.DataUtils.load(this, "channels");
BDFDB.DataUtils.remove(this, "channels");
2019-10-17 11:36:34 +02:00
try {this.forceUpdateAll();} catch (err) {}
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(data, this, "channels");
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(".autocompleteEditChannels", ".autocompleteEditChannelsRow");
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-12-10 13:59:44 +01:00
onChannelContextMenu (e) {
if (e.instance.props.channel && !BDFDB.DOMUtils.getParent(".container-hidden", e.instance.props.target)) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
2019-12-05 09:10:14 +01:00
children.splice(index > -1 ? index : children.length, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
2019-09-11 12:14:43 +02:00
children: [
2019-12-05 09:10:14 +01:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Sub, {
2019-09-11 12:14:43 +02:00
label: this.labels.context_localchannelsettings_text,
2019-12-05 09:10:14 +01:00
render: [BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
2019-09-11 12:14:43 +02:00
children: [
2019-12-05 09:10:14 +01:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
2019-09-11 12:14:43 +02:00
label: this.labels.submenu_channelsettings_text,
2019-11-21 11:38:04 +01:00
action: _ => {
2019-12-10 13:59:44 +01:00
BDFDB.ContextMenuUtils.close(e.instance);
this.showChannelSettings(e.instance.props.channel);
2019-09-11 12:14:43 +02:00
}
}),
2019-12-05 09:10:14 +01:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
2019-09-11 12:14:43 +02:00
label: this.labels.submenu_resetsettings_text,
2019-12-10 13:59:44 +01:00
disabled: !BDFDB.DataUtils.load(this, "channels", e.instance.props.channel.id),
2019-11-21 11:38:04 +01:00
action: _ => {
2019-12-10 13:59:44 +01:00
BDFDB.ContextMenuUtils.close(e.instance);
BDFDB.DataUtils.remove(this, "channels", e.instance.props.channel.id);
2019-10-17 11:36:34 +02:00
this.forceUpdateAll();
2019-09-11 12:14:43 +02:00
}
})
]
})]
})
]
2019-12-02 20:43:01 +01:00
}));
2018-10-11 10:21:26 +02:00
}
}
2019-10-17 11:36:34 +02:00
forceUpdateAll () {
this.changeAppTitle();
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.forceAllUpdates(this);
2019-10-17 11:36:34 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
showChannelSettings (info) {
2019-10-22 20:16:05 +02:00
var data = BDFDB.DataUtils.load(this, "channels", info.id) || {};
2019-10-14 14:08:20 +02:00
2019-10-30 13:27:14 +01:00
BDFDB.ModalUtils.open(this, {
2019-10-14 14:08:20 +02:00
size: "MEDIUM",
header: this.labels.modal_header_text,
subheader: info.name,
2019-10-14 23:01:41 +02:00
children: [
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
2019-10-14 14:08:20 +02:00
title: this.labels.modal_channelname_text,
2019-10-14 23:01:41 +02:00
className: BDFDB.disCN.marginbottom20 + " input-channelname",
children: [
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
2019-10-17 11:36:34 +02:00
value: data.name,
2019-10-14 23:01:41 +02:00
placeholder: info.name,
autoFocus: true
}),
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
2019-10-15 11:46:37 +02:00
className: BDFDB.disCN.dividerdefault
2019-10-14 23:01:41 +02:00
})
]
}),
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
2019-10-14 14:08:20 +02:00
title: this.labels.modal_colorpicker1_text,
2019-10-14 23:01:41 +02:00
className: BDFDB.disCN.marginbottom20,
children: [
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ColorSwatches, {
2019-10-17 11:36:34 +02:00
color: data.color,
2019-10-14 23:01:41 +02:00
number: 1
})
]
}),
2019-10-22 18:55:25 +02:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
2019-10-16 22:18:15 +02:00
type: "Switch",
2019-10-14 14:08:20 +02:00
className: BDFDB.disCN.marginbottom20 + " input-inheritcolor",
2019-10-16 22:18:15 +02:00
label: this.labels.modal_inheritcolor_text,
2019-10-17 11:36:34 +02:00
value: info.type == 4 && data.inheritColor,
2019-10-16 22:18:15 +02:00
disabled: info.type != 4
2019-10-14 23:01:41 +02:00
})
2019-10-14 14:08:20 +02:00
],
buttons: [{
2019-10-19 11:41:39 +02:00
contents: BDFDB.LanguageUtils.LanguageStrings.SAVE,
2019-10-14 14:08:20 +02:00
color: "BRAND",
close: true,
click: modal => {
2019-10-21 17:06:50 +02:00
let olddata = Object.assign({}, data);
2019-10-14 14:08:20 +02:00
let channelnameinput = modal.querySelector(".input-channelname " + BDFDB.dotCN.input);
let inheritcolorinput = modal.querySelector(".input-inheritcolor " + BDFDB.dotCN.switchinner);
2019-10-17 11:36:34 +02:00
data.name = channelnameinput.value.trim() || null;
2019-10-14 14:08:20 +02:00
2019-10-23 11:10:01 +02:00
data.color = BDFDB.ColorUtils.getSwatchColor(modal, 1);
2019-10-22 18:55:25 +02:00
if (data.color != null && !BDFDB.ObjectUtils.is(data.color)) {
2019-10-23 10:03:33 +02:00
if (data.color[0] < 30 && data.color[1] < 30 && data.color[2] < 30) data.color = BDFDB.ColorUtils.change(data.color, 30);
else if (data.color[0] > 225 && data.color[1] > 225 && data.color[2] > 225) data.color = BDFDB.ColorUtils.change(data.color, -30);
2019-10-14 14:08:20 +02:00
}
2019-01-26 22:45:19 +01:00
2019-10-17 11:36:34 +02:00
data.inheritColor = inheritcolorinput.checked;
let changed = false;
2019-10-22 20:16:05 +02:00
if (Object.keys(data).every(key => data[key] == null || data[key] == false) && (changed = true)) BDFDB.DataUtils.remove(this, "channels", info.id);
else if (!BDFDB.equals(olddata, data) && (changed = true)) BDFDB.DataUtils.save(data, this, "channels", info.id);
2019-10-17 11:36:34 +02:00
if (changed) this.forceUpdateAll();
2019-10-14 14:08:20 +02:00
}
}]
2019-01-17 23:48:29 +01:00
});
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processChannelTextArea (instance, wrapper, returnvalue) {
2019-10-22 18:55:25 +02:00
let channel = BDFDB.ReactUtils.getValue(instance, "props.channel");
if (channel) {
var textarea = wrapper.querySelector("textarea");
if (!textarea) return;
2019-06-26 08:52:17 +02:00
if (channel.type == 0 && instance.props.type == "normal" && !instance.props.disabled) {
2019-02-13 12:00:42 +01:00
let data = this.getChannelData(channel.id, wrapper);
2019-10-25 11:30:50 +02:00
textarea.setAttribute("placeholder", BDFDB.LanguageUtils.LanguageStringsFormat("TEXTAREA_PLACEHOLDER", `#${data.name || channel.name}`));
}
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.remove(this, textarea);
2019-10-22 20:16:05 +02:00
if (BDFDB.DataUtils.get(this, "settings", "changeInAutoComplete")) {
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, textarea, "keydown", e => {
2019-02-13 12:00:42 +01:00
let autocompletemenu = textarea.parentElement.querySelector(BDFDB.dotCN.autocomplete);
if (autocompletemenu && (e.which == 9 || e.which == 13)) {
2019-10-23 11:10:01 +02:00
if (BDFDB.DOMUtils.containsClass(autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected).parentElement, "autocompleteEditChannelsRow")) {
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.stopEvent(e);
2019-09-04 12:34:02 +02:00
this.swapWordWithMention(textarea);
2019-02-13 12:00:42 +01:00
}
}
2019-02-13 12:00:42 +01:00
else if (autocompletemenu && (e.which == 38 || e.which == 40)) {
let autocompleteitems = autocompletemenu.querySelectorAll(BDFDB.dotCN.autocompleteselectable + ":not(.autocompleteEditChannelsSelector)");
let selected = autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected);
2019-10-23 11:10:01 +02:00
if (BDFDB.DOMUtils.containsClass(selected, "autocompleteEditChannelsSelector") || autocompleteitems[e.which == 38 ? 0 : (autocompleteitems.length-1)] == selected) {
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.stopEvent(e);
2019-02-13 12:00:42 +01:00
let next = this.getNextSelection(autocompletemenu, null, e.which == 38 ? false : true);
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.removeClass(selected, BDFDB.disCN.autocompleteselected);
BDFDB.DOMUtils.addClass(selected, BDFDB.disCN.autocompleteselector);
BDFDB.DOMUtils.addClass(next, BDFDB.disCN.autocompleteselected);
2019-02-13 12:00:42 +01:00
}
}
else if (textarea.value && !e.shiftKey && e.which == 13 && !autocompletemenu && textarea.value.indexOf("s/") != 0) {
this.format = true;
textarea.dispatchEvent(new Event("input"));
}
else if (!e.ctrlKey && e.which != 16 && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length) {
2019-11-01 11:09:32 +01:00
BDFDB.TimeUtils.clear(textarea.EditChannelsAutocompleteTimeout);
textarea.EditChannelsAutocompleteTimeout = BDFDB.TimeUtils.timeout(() => {this.addAutoCompleteMenu(textarea, channel);},100);
}
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
if (!e.ctrlKey && e.which != 38 && e.which != 40 && !(e.which == 39 && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length)) BDFDB.DOMUtils.remove(".autocompleteEditChannels", ".autocompleteEditChannelsRow");
2019-02-13 12:00:42 +01:00
});
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, textarea, "click", e => {
2019-11-01 11:09:32 +01:00
if (textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length) BDFDB.TimeUtils.timeout(() => {this.addAutoCompleteMenu(textarea, channel);});
2019-02-13 12:00:42 +01:00
});
}
}
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processAuditLog (instance, wrapper, returnvalue) {
2019-10-22 18:55:25 +02:00
let channel = BDFDB.ReactUtils.getValue(instance, "props.log.options.channel");
2019-01-17 23:48:29 +01:00
if (channel) {
2019-01-22 12:22:17 +01:00
let hooks = wrapper.querySelectorAll(`${BDFDB.dotCN.flexchild} > span${BDFDB.notCN.auditloguserhook}`);
2019-01-17 23:48:29 +01:00
if (hooks.length > 0) this.changeChannel2(channel, hooks[0].firstChild);
}
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processInviteCard (instance, wrapper, returnvalue) {
2019-10-22 18:55:25 +02:00
let invite = BDFDB.ReactUtils.getValue(instance, "props.invite");
2019-02-13 12:00:42 +01:00
if (invite && invite.inviter && invite.channel) {
let channelname = wrapper.querySelector(BDFDB.dotCN.guildsettingsinvitechannelname);
if (channelname) this.changeChannel2(invite.channel, channelname);
}
}
2019-09-11 12:14:43 +02:00
processChannelCategoryItem (instance, wrapper, returnvalue) {
2019-11-11 11:11:33 +01:00
if (instance.props.channel) {
2019-05-02 20:55:34 +02:00
this.changeChannel(instance.props.channel, wrapper.querySelector(BDFDB.dotCN.categoryname), true);
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processChannelItem (instance, wrapper, returnvalue) {
2019-11-11 11:11:33 +01:00
if (instance.props.channel) {
2019-05-02 20:55:34 +02:00
this.changeChannel(instance.props.channel, wrapper.querySelector(BDFDB.dotCN.channelname), true);
2018-10-11 10:21:26 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-09-11 12:14:43 +02:00
processHeaderBarContainer (instance, wrapper, returnvalue) {
2019-04-29 09:11:09 +02:00
this.processHeaderBar(instance, wrapper);
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processHeaderBar (instance, wrapper, returnvalue) {
2019-10-22 18:55:25 +02:00
let channel_id = BDFDB.ReactUtils.getValue(instance, "props.channelId") || BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.memoizedProps.channelId");
2019-01-17 23:48:29 +01:00
if (channel_id) {
2019-04-23 10:43:46 +02:00
let channelname = wrapper.querySelector(BDFDB.dotCN.channelheaderheaderbartitle);
if (channelname) {
2019-09-11 12:14:43 +02:00
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(channel_id);
if (channel) {
2019-05-02 20:55:34 +02:00
if (channel.type == 0 || channel.type == 2) this.changeChannel(channel, channelname);
else {
2019-09-11 12:14:43 +02:00
if (channel.type == 1) channel = BDFDB.LibraryModules.UserStore.getUser(channel.recipients[0]) || channel;
if (channelname.EditChannelsChangeObserver && typeof channelname.EditChannelsChangeObserver.disconnect == "function") channelname.EditChannelsChangeObserver.disconnect();
2019-10-23 11:10:01 +02:00
if (BDFDB.BDUtils.isPluginEnabled("EditUsers")) BDFDB.BDUtils.getPlugin("EditUsers").changeName(channel, channelname);
2019-08-29 23:23:06 +02:00
else {
channelname.style.removeProperty("color");
channelname.style.removeProperty("background");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(channelname, channel.name || channel.username);
2019-08-29 23:23:06 +02:00
}
}
2018-12-14 22:08:19 +01:00
}
2018-10-11 10:21:26 +02:00
}
}
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processClickable (instance, wrapper, returnvalue) {
2018-12-27 10:19:30 +01:00
if (!instance.props || !instance.props.className) return;
else if (instance.props.tag == "span" && instance.props.className.indexOf(BDFDB.disCN.mentionwrapper) > -1 && instance.props.className.indexOf(BDFDB.disCN.mention) == -1) {
2019-10-22 18:55:25 +02:00
let children = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.memoizedProps.children");
2019-01-17 23:48:29 +01:00
if (children && typeof children[0] == "string") {
let channelname = children[0].slice(1);
2019-10-22 18:55:25 +02:00
let categoryname = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.return.type.displayName") == "Tooltip" ? BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.return.memoizedProps.text") : null
2019-09-11 12:14:43 +02:00
let channelid = BDFDB.LibraryModules.LastGuildStore.getGuildId();
let channels = channelid ? (BDFDB.LibraryModules.GuildChannelStore.getChannels(channelid)[0] || BDFDB.LibraryModules.GuildChannelStore.getChannels(channelid).SELECTABLE) : null;
2019-02-28 09:03:02 +01:00
if (Array.isArray(channels)) for (let channel of channels) {
if (channelname == channel.channel.name) {
2019-09-11 12:14:43 +02:00
let category = categoryname ? BDFDB.LibraryModules.ChannelStore.getChannel(channel.channel.parent_id) : null;
if (!category || category && categoryname == category.name) {
this.changeMention(channel.channel, wrapper, category || {});
break;
}
}
}
}
}
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.quickswitchresult) > -1) {
2019-10-22 18:55:25 +02:00
let channel = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.return.memoizedProps.channel");
2019-03-13 13:02:06 +01:00
if (channel) {
this.changeChannel(channel, wrapper.querySelector(BDFDB.dotCN.quickswitchresultmatch));
2019-09-11 12:14:43 +02:00
if (channel.parent_id) this.changeChannel(BDFDB.LibraryModules.ChannelStore.getChannel(channel.parent_id), wrapper.querySelector(BDFDB.dotCN.quickswitchresultnote));
}
}
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.autocompleterow) > -1) {
2019-10-22 18:55:25 +02:00
let channel = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.memoizedProps.channel");
2019-01-17 23:48:29 +01:00
if (channel) {
this.changeChannel(channel, wrapper.querySelector(BDFDB.dotCN.marginleft4));
2019-10-22 18:55:25 +02:00
let category = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.memoizedProps.category");
2019-01-17 23:48:29 +01:00
if (category) this.changeChannel(category, wrapper.querySelector(BDFDB.dotCN.autocompletedescription));
2018-10-11 10:21:26 +02:00
}
}
else if (instance.props.tag == "span" && instance.props.className.indexOf(BDFDB.disCN.messagespopoutchannelname) > -1) {
2019-10-22 18:55:25 +02:00
let channel = BDFDB.ReactUtils.getValue(instance, "_reactInternalFiber.return.sibling.child.child.memoizedProps.channel");
2019-01-17 23:48:29 +01:00
if (channel) this.changeChannel2(channel, wrapper);
}
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processStandardSidebarView (instance, wrapper, returnvalue) {
2019-01-17 23:48:29 +01:00
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
2019-10-17 11:36:34 +02:00
this.forceUpdateAll();
2018-12-27 10:19:30 +01:00
}
}
2019-09-04 12:34:02 +02:00
2019-08-19 11:17:57 +02:00
changeAppTitle () {
2019-09-11 12:14:43 +02:00
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(BDFDB.LibraryModules.LastChannelStore.getChannelId());
2019-08-19 11:17:57 +02:00
let title = document.head.querySelector("title");
if (title && channel && channel.type != 1) {
let data = this.getChannelData(channel.id, channel.parent_id, title);
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(title, "@" + (data.name || channel.name));
2019-08-19 11:17:57 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-05-02 20:55:34 +02:00
changeChannel (info, channelname, hoverlistener = false) {
if (!info || !channelname || !channelname.parentElement) return;
2019-05-02 20:55:34 +02:00
var change = () => {
if (channelname.EditChannelsChangeObserver && typeof channelname.EditChannelsChangeObserver.disconnect == "function") channelname.EditChannelsChangeObserver.disconnect();
2019-07-01 11:53:52 +02:00
let data = this.getChannelData(info.id, info.parent_id, channelname);
2019-05-02 20:55:34 +02:00
if (data.name || data.color || channelname.parentElement.getAttribute("changed-by-editchannels")) {
2019-10-22 18:55:25 +02:00
let isgradient = data.color && BDFDB.ObjectUtils.is(data.color);
2019-05-02 20:55:34 +02:00
let color = this.chooseColor(channelname, data.color);
2019-08-19 11:17:57 +02:00
if (isgradient) {
2019-10-23 10:03:33 +02:00
channelname.style.setProperty("color", BDFDB.ColorUtils.convert(data.color[Object.keys(data.color)[0]], "RGBA"), "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(channelname, BDFDB.DOMUtils.create(`<span style="pointer-events: none; -webkit-background-clip: text !important; color: transparent !important; background-image: ${BDFDB.ColorUtils.createGradient(color)} !important;">${BDFDB.StringUtils.htmlEscape(data.name || info.name)}</span>`));
2019-08-19 11:17:57 +02:00
}
else {
channelname.style.setProperty("color", color, "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(channelname, data.name || info.name);
2019-08-19 11:17:57 +02:00
}
2019-10-23 11:10:01 +02:00
let iconparent = BDFDB.DOMUtils.containsClass(channelname, BDFDB.disCN.quickswitchresultmatch) ? channelname.parentElement.parentElement : channelname.parentElement;
if (!BDFDB.DOMUtils.containsClass(channelname, BDFDB.disCN.autocompletedescription)) {
2019-10-22 19:49:57 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
2019-05-02 20:55:34 +02:00
iconparent.querySelectorAll('svg [stroke]:not([stroke="none"]').forEach(icon => {
2019-10-23 11:10:01 +02:00
let iconcolor = color && BDFDB.DOMUtils.getParent(BDFDB.dotCN.channelheadertitle, icon) ? BDFDB.ColorUtils.setAlpha(isgradient ? color[0] : color, 0.6) : (isgradient ? color[0] : color);
2019-05-02 20:55:34 +02:00
if (!icon.getAttribute("oldstroke")) icon.setAttribute("oldstroke", icon.getAttribute("stroke"));
icon.setAttribute("stroke", iconcolor && settings.changeChannelIcon ? iconcolor : icon.getAttribute("oldstroke"), "important");
icon.style.setProperty("stroke", iconcolor && settings.changeChannelIcon ? iconcolor : icon.getAttribute("oldstroke"), "important");
});
iconparent.querySelectorAll('svg [fill]:not([fill="none"]').forEach(icon => {
2019-10-23 11:10:01 +02:00
let iconcolor = color && BDFDB.DOMUtils.getParent(BDFDB.dotCN.channelheadertitle, icon) ? BDFDB.ColorUtils.setAlpha(isgradient ? color[0] : color, 0.6) : (isgradient ? color[0] : color);
2019-05-02 20:55:34 +02:00
if (!icon.getAttribute("oldfill")) icon.setAttribute("oldfill", icon.getAttribute("fill"));
icon.setAttribute("fill", iconcolor && settings.changeChannelIcon ? iconcolor : icon.getAttribute("oldfill"), "important");
icon.style.setProperty("fill", iconcolor && settings.changeChannelIcon ? iconcolor : icon.getAttribute("oldfill"), "important");
});
let unread = iconparent.parentElement.querySelector(BDFDB.dotCN.channelunread);
2019-08-19 11:17:57 +02:00
if (unread) unread.style.setProperty("background-color", color && settings.changeUnreadIndicator ? (isgradient ? color[0] : color) : null, "important");
2019-05-02 20:55:34 +02:00
}
if (data.name || data.color) {
channelname.parentElement.setAttribute("changed-by-editchannels", true);
channelname.EditChannelsChangeObserver = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
2019-10-23 11:10:01 +02:00
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 || change.type == "attributes" && change.attributeName == "style" && BDFDB.DOMUtils.containsClass(change.target, BDFDB.disCN.channelheaderheaderbartitle)) {
2019-05-02 20:55:34 +02:00
channelname.EditChannelsChangeObserver.disconnect();
this.changeChannel(info, channelname);
}
2019-02-13 12:00:42 +01:00
}
2019-05-02 20:55:34 +02:00
);
});
channelname.EditChannelsChangeObserver.observe(iconparent, {attributes:true, childList:true, subtree:true});
}
else channelname.parentElement.removeAttribute("changed-by-editchannels");
}
}
change();
if (hoverlistener) {
2019-10-23 11:10:01 +02:00
let wrapper = info.type == 4 ? BDFDB.DOMUtils.getParent(BDFDB.dotCN.categorywrapper, channelname) : BDFDB.DOMUtils.getParent(BDFDB.dotCN.channelwrapper, channelname);
2019-05-02 20:55:34 +02:00
if (wrapper) {
wrapper.removeEventListener("mouseover", wrapper.mouseoverListenerEditChannels);
wrapper.removeEventListener("mouseout", wrapper.mouseoutListenerEditChannels);
wrapper.mouseoverListenerEditChannels = () => {
channelname.EditChannelsHovered = true;
change();
};
wrapper.mouseoutListenerEditChannels = () => {
delete channelname.EditChannelsHovered;
change();
};
wrapper.addEventListener("mouseover", wrapper.mouseoverListenerEditChannels);
wrapper.addEventListener("mouseout", wrapper.mouseoutListenerEditChannels);
2019-02-13 12:00:42 +01:00
}
2018-12-14 22:08:19 +01:00
}
}
2019-01-26 22:45:19 +01:00
changeChannel2 (info, channelname) {
if (!info || !channelname || !channelname.parentElement) return;
if (channelname.EditChannelsChangeObserver && typeof channelname.EditChannelsChangeObserver.disconnect == "function") channelname.EditChannelsChangeObserver.disconnect();
2019-07-01 11:53:52 +02:00
let data = this.getChannelData(info.id, info.parent_id, channelname);
2019-02-13 12:00:42 +01:00
if (data.name || data.color || channelname.getAttribute("changed-by-editchannels")) {
2019-10-22 18:55:25 +02:00
if (BDFDB.ObjectUtils.is(data.color)) {
2019-10-23 10:03:33 +02:00
channelname.style.setProperty("color", BDFDB.ColorUtils.convert(data.color[Object.keys(data.color)[0]], "RGBA"), "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(channelname, BDFDB.DOMUtils.create(`<span style="pointer-events: none; -webkit-background-clip: text !important; color: transparent !important; background-image: ${BDFDB.ColorUtils.createGradient(this.chooseColor(channelname, data.color))} !important;">${BDFDB.StringUtils.htmlEscape("#" + (data.name || info.name))}</span>`));
2019-08-19 11:17:57 +02:00
}
else {
channelname.style.setProperty("color", this.chooseColor(channelname, data.color), "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(channelname, "#" + (data.name || info.name));
2019-08-19 11:17:57 +02:00
}
2019-02-13 12:00:42 +01:00
if (data.name || data.color) {
channelname.setAttribute("changed-by-editchannels", true);
channelname.EditChannelsChangeObserver = new MutationObserver((changes, _) => {
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.changeChannel2(info, channelname);
}
}
2019-02-13 12:00:42 +01:00
);
});
channelname.EditChannelsChangeObserver.observe(channelname.parentElement, {attributes:true, childList:true, subtree:true});
}
else channelname.removeAttribute("changed-by-editchannels");
}
}
2019-01-26 22:45:19 +01:00
changeMention (info, mention, categoryinfo) {
if (!info || !mention || !mention.parentElement) return;
if (mention.EditChannelsChangeObserver && typeof mention.EditChannelsChangeObserver.disconnect == "function") mention.EditChannelsChangeObserver.disconnect();
2019-01-17 23:48:29 +01:00
mention.removeEventListener("mouseover", mention.mouseoverListenerEditChannels);
mention.removeEventListener("mouseout", mention.mouseoutListenerEditChannels);
2019-07-01 11:53:52 +02:00
let data = this.getChannelData(info.id, info.parent_id, mention);
2019-08-19 11:17:57 +02:00
let name = "#" + (data.name || info.name);
2019-09-04 12:34:02 +02:00
2019-10-22 18:55:25 +02:00
let isgradient = data.color && BDFDB.ObjectUtils.is(data.color);
2019-10-23 10:03:33 +02:00
let color = isgradient ? BDFDB.ColorUtils.createGradient(data.color) : BDFDB.ColorUtils.convert(data.color, "RGBA");
let color0_1 = isgradient ? BDFDB.ColorUtils.createGradient(BDFDB.ColorUtils.setAlpha(data.color, 0.1, "RGBA")) : BDFDB.ColorUtils.setAlpha(data.color, 0.1, "RGBA");
let color0_7 = isgradient ? BDFDB.ColorUtils.createGradient(BDFDB.ColorUtils.setAlpha(data.color, 0.7, "RGBA")) : BDFDB.ColorUtils.setAlpha(data.color, 0.7, "RGBA");
2019-09-04 12:34:02 +02:00
if (mention.EditChannelsHovered) colorHover();
else colorDefault();
2019-01-17 23:48:29 +01:00
mention.mouseoverListenerEditChannels = () => {
mention.EditChannelsHovered = true;
colorHover();
2019-07-01 11:53:52 +02:00
let categorydata = this.getChannelData(categoryinfo.id, null, mention);
2019-10-22 18:55:25 +02:00
if (categorydata.name) BDFDB.TooltipUtils.create(mention, categorydata.name, {type:"top", selector:"EditChannels-tooltip", hide:true});
2019-01-17 23:48:29 +01:00
};
mention.mouseoutListenerEditChannels = () => {
delete mention.EditChannelsHovered;
colorDefault();
};
mention.addEventListener("mouseover", mention.mouseoverListenerEditChannels);
mention.addEventListener("mouseout", mention.mouseoutListenerEditChannels);
mention.EditChannelsChangeObserver = new MutationObserver((changes, _) => {
mention.EditChannelsChangeObserver.disconnect();
this.changeMention(info, mention, categoryinfo);
2018-12-14 22:08:19 +01:00
});
mention.EditChannelsChangeObserver.observe(mention, {attributes:true});
function colorDefault() {
2019-08-19 11:17:57 +02:00
mention.style.setProperty("background", color0_1, "important");
if (isgradient) {
2019-10-23 10:03:33 +02:00
mention.style.setProperty("color", BDFDB.ColorUtils.convert(data.color[Object.keys(data.color)[0]], "RGBA"), "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(mention, BDFDB.DOMUtils.create(`<span style="pointer-events: none; -webkit-background-clip: text !important; color: transparent !important; background-image: ${color} !important;">${BDFDB.StringUtils.htmlEscape(name)}</span>`));
2019-08-19 11:17:57 +02:00
}
else {
mention.style.setProperty("color", color, "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(mention, name);
2019-08-19 11:17:57 +02:00
}
}
function colorHover() {
2019-08-19 11:17:57 +02:00
mention.style.setProperty("background", color0_7, "important");
mention.style.setProperty("color", data.color ? "#FFFFFF" : null, "important");
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.setText(mention, name);
}
2018-12-14 22:08:19 +01:00
}
2018-10-11 10:21:26 +02:00
chooseColor (channelname, color) {
if (color && channelname) {
2019-05-02 20:55:34 +02:00
let hovered = channelname.EditChannelsHovered;
2019-10-23 11:10:01 +02:00
channelname = BDFDB.DOMUtils.containsClass(channelname, BDFDB.disCN.channelname) ? channelname.parentElement.parentElement : channelname;
let classname = channelname.className ? channelname.className.toLowerCase() : "";
2019-10-23 10:03:33 +02:00
if (classname.indexOf("muted") > -1 || classname.indexOf("locked") > -1) color = BDFDB.ColorUtils.change(color, -0.5);
else if (hovered || classname.indexOf("selected") > -1 || classname.indexOf("hovered") > -1 || classname.indexOf("unread") > -1 || classname.indexOf("connected") > -1) color = BDFDB.ColorUtils.change(color, 0.5);
return BDFDB.ObjectUtils.is(color) ? color : BDFDB.ColorUtils.convert(color, "RGBA");
2018-10-11 10:21:26 +02:00
}
return null;
}
2019-09-04 12:34:02 +02:00
2019-07-01 11:53:52 +02:00
getChannelData (id, categoryid, wrapper) {
2019-10-22 20:16:05 +02:00
let data = BDFDB.DataUtils.load(this, "channels", id);
let categorydata = categoryid ? BDFDB.DataUtils.load(this, "channels", categoryid) : null;
2019-07-01 11:53:52 +02:00
if (!data && (!categorydata || (categorydata && !categorydata.color && !categorydata.inheritColor))) return {};
if (!data) data = {};
data.color = data.color ? data.color : (categorydata && categorydata.color && categorydata.inheritColor ? categorydata.color : null);
2019-10-22 19:49:57 +02:00
let allenabled = true, settings = BDFDB.DataUtils.get(this, "settings");
2019-02-13 12:00:42 +01:00
for (let i in settings) if (!settings[i]) {
allenabled = false;
break;
}
if (allenabled) return data;
let key = null;
2019-10-23 11:10:01 +02:00
if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.textareawrapchat, wrapper)) key = "changeInChatTextarea";
else if (BDFDB.DOMUtils.containsClass(wrapper, BDFDB.disCN.mentionwrapper)) key = "changeInMentions";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildchannels, wrapper)) key = "changeInChannelList";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.channelheaderheaderbar, wrapper)) key = "changeInChannelHeader";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.recentmentionspopout, wrapper)) key = "changeInRecentMentions";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.autocomplete, wrapper)) key = "changeInAutoComplete";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.auditlog, wrapper)) key = "changeInAuditLog";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildsettingsinvitecard, wrapper)) key = "changeInInviteLog";
else if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.searchpopout, wrapper) || BDFDB.DOMUtils.getParent(BDFDB.dotCN.quickswitcher, wrapper)) key = "changeInSearchPopout";
2019-02-13 12:00:42 +01:00
return !key || settings[key] ? data : {};
}
2019-01-26 22:45:19 +01:00
addAutoCompleteMenu (textarea, channel) {
if (textarea.parentElement.querySelector(".autocompleteEditChannelsRow")) return;
let words = textarea.value.split(/\s/);
let lastword = words[words.length-1].trim();
if (lastword && lastword.length > 1 && lastword[0] == "#") {
2019-10-22 19:49:57 +02:00
let channels = BDFDB.DataUtils.load(this, "channels");
if (!channels) return;
let channelarray = [];
for (let id in channels) if (channels[id].name) {
2019-09-11 12:14:43 +02:00
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(id);
let category = channel && channel.parent_id ? BDFDB.LibraryModules.ChannelStore.getChannel(channel.parent_id) : null;
let catdata = (category ? channels[category.id] : null) || {};
2019-09-04 12:34:02 +02:00
if (channel && channel.type == 0) channelarray.push(Object.assign({lowercasename:channels[id].name.toLowerCase(),lowercasecatname:(catdata && catdata.name ? catdata.name.toLowerCase() : null),channel,category,catdata},channels[id]));
}
2019-10-22 18:55:25 +02:00
channelarray = BDFDB.ArrayUtils.keySort(channelarray.filter(n => n.lowercasename.indexOf(lastword.toLowerCase().slice(1)) != -1 || (n.lowercasecatname && n.lowercasecatname.indexOf(lastword.toLowerCase().slice(1)) != -1)), "lowercasename");
if (channelarray.length) {
2019-10-22 19:49:57 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
let autocompletemenu = textarea.parentElement.querySelector(BDFDB.dotCNS.autocomplete + BDFDB.dotCN.autocompleteinner), amount = 15;
if (!autocompletemenu) {
2019-10-23 11:10:01 +02:00
autocompletemenu = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCNS.autocomplete + BDFDB.disCN.autocomplete2} autocompleteEditChannels"><div class="${BDFDB.disCN.autocompleteinner}"><div class="${BDFDB.disCNS.autocompleterowvertical + BDFDB.disCN.autocompleterow} autocompleteEditChannelsRow"><div class="${BDFDB.disCN.autocompleteselector} autocompleteEditChannelsSelector"><div class="${BDFDB.disCNS.autocompletecontenttitle + BDFDB.disCNS.small + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCN.weightsemibold}">${BDFDB.LanguageUtils.LanguageStrings.TEXT_CHANNELS_MATCHING.replace("{{prefix}}", BDFDB.StringUtils.htmlEscape(lastword))}</strong></div></div></div></div></div>`);
textarea.parentElement.appendChild(autocompletemenu);
autocompletemenu = autocompletemenu.firstElementChild;
}
else {
amount -= autocompletemenu.querySelectorAll(BDFDB.dotCN.autocompleteselectable).length;
}
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, autocompletemenu, "mouseenter", BDFDB.dotCN.autocompleteselectable, e => {
var selected = autocompletemenu.querySelectorAll(BDFDB.dotCN.autocompleteselected);
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.removeClass(selected, BDFDB.disCN.autocompleteselected);
BDFDB.DOMUtils.addClass(selected, BDFDB.disCN.autocompleteselector);
BDFDB.DOMUtils.addClass(e.currentTarget, BDFDB.disCN.autocompleteselected);
});
2019-01-26 22:45:19 +01:00
for (let data of channelarray) {
if (amount-- < 1) break;
2019-10-23 10:03:33 +02:00
let color = BDFDB.ColorUtils.convert(data.color, "RGBA");
let catcolor = BDFDB.ColorUtils.convert(data.catdata.color, "RGBA");
2019-10-23 11:10:01 +02:00
let autocompleterow = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCNS.autocompleterowvertical + BDFDB.disCN.autocompleterow} autocompleteEditChannelsRow"><div channelid="${data.channel.id}" class="${BDFDB.disCNS.autocompleteselector + BDFDB.disCN.autocompleteselectable} autocompleteEditChannelsSelector"><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.autocompletecontent}" style="flex: 1 1 auto;"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" class="${BDFDB.disCN.autocompleteicon}"><path class="${BDFDB.disCN.autocompleteiconforeground}" d="M2.27333333,12 L2.74666667,9.33333333 L0.08,9.33333333 L0.313333333,8 L2.98,8 L3.68666667,4 L1.02,4 L1.25333333,2.66666667 L3.92,2.66666667 L4.39333333,0 L5.72666667,0 L5.25333333,2.66666667 L9.25333333,2.66666667 L9.72666667,0 L11.06,0 L10.5866667,2.66666667 L13.2533333,2.66666667 L13.02,4 L10.3533333,4 L9.64666667,8 L12.3133333,8 L12.08,9.33333333 L9.41333333,9.33333333 L8.94,12 L7.60666667,12 L8.08,9.33333333 L4.08,9.33333333 L3.60666667,12 L2.27333333,12 L2.27333333,12 Z M5.02,4 L4.31333333,8 L8.31333333,8 L9.02,4 L5.02,4 L5.02,4 Z" transform="translate(1.333 2)" ${settings.changeChannelIcon && color ? ('fill="' + color + '" oldfill="currentColor" style="fill: ' + color + ' !important;"') : 'fill="currentColor"'}></path></svg><div class="${BDFDB.disCN.marginleft4}" changed-by-editchannels="true" style="flex: 1 1 auto;${color ? (' color: ' + color + ' !important;') : ''}">${BDFDB.StringUtils.htmlEscape(data.name || data.channel.name)}</div>${data.category ? '<div class="${BDFDB.disCN.autocompletedescription}"' + (catcolor ? (' style="color: ' + catcolor + ' !important;"') : '') + '>' + BDFDB.StringUtils.htmlEscape(data.catdata.name || data.category.name) + '</div>' : ''}</div></div></div>`);
autocompleterow.querySelector(BDFDB.dotCN.autocompleteselectable).addEventListener("click", () => {this.swapWordWithMention(textarea);});
autocompletemenu.appendChild(autocompleterow);
}
if (!autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected)) {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.addClass(autocompletemenu.querySelector(".autocompleteEditChannelsRow " + BDFDB.dotCN.autocompleteselectable), BDFDB.disCN.autocompleteselected);
}
}
}
}
2019-01-26 22:45:19 +01:00
getNextSelection (menu, selected, forward) {
selected = selected ? selected : menu.querySelector(BDFDB.dotCN.autocompleteselected).parentElement;
let next, sibling = forward ? selected.nextElementSibling : selected.previousElementSibling;
if (sibling) {
next = sibling.querySelector(BDFDB.dotCN.autocompleteselectable);
}
else {
let items = menu.querySelectorAll(BDFDB.dotCN.autocompleteselectable);
2019-09-04 12:34:02 +02:00
next = forward ? items[0] : items[items.length-1];
}
return next ? next : this.getNextSelection(menu, sibling, forward);
}
2019-01-26 22:45:19 +01:00
swapWordWithMention (textarea) {
let selected = textarea.parentElement.querySelector(".autocompleteEditChannelsRow " + BDFDB.dotCN.autocompleteselected);
let channelid = selected ? selected.getAttribute("channelid") : null;
let words = textarea.value.split(/\s/);
let lastword = words[words.length-1].trim();
if (channelid && lastword) {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(".autocompleteEditChannels", ".autocompleteEditChannelsRow");
2019-09-04 12:34:02 +02:00
textarea.focus();
textarea.selectionStart = textarea.value.length - lastword.length;
textarea.selectionEnd = textarea.value.length;
document.execCommand("insertText", false, `<#${channelid}> `);
textarea.selectionStart = textarea.value.length;
textarea.selectionEnd = textarea.value.length;
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
setLabelsByLanguage () {
2019-10-24 11:47:57 +02:00
switch (BDFDB.LanguageUtils.getLanguage().id) {
2018-10-11 10:21:26 +02:00
case "hr": //croatian
return {
context_localchannelsettings_text: "Postavke lokalnih kanala",
submenu_channelsettings_text: "Promijeni postavke",
submenu_resetsettings_text: "Vraćanje kanala",
modal_header_text: "Postavke lokalnih kanala",
modal_channelname_text: "Naziv lokalnog kanala",
modal_colorpicker1_text: "Boja lokalnog kanala",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Naslijedi boju u potkanale"
2018-10-11 10:21:26 +02:00
};
case "da": //danish
return {
context_localchannelsettings_text: "Lokal kanalindstillinger",
submenu_channelsettings_text: "Skift indstillinger",
submenu_resetsettings_text: "Nulstil kanal",
modal_header_text: "Lokal kanalindstillinger",
modal_channelname_text: "Lokalt kanalnavn",
modal_colorpicker1_text: "Lokal kanalfarve",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Arve farve til subkanaler"
2018-10-11 10:21:26 +02:00
};
case "de": //german
return {
context_localchannelsettings_text: "Lokale Kanaleinstellungen",
submenu_channelsettings_text: "Einstellungen ändern",
submenu_resetsettings_text: "Kanal zurücksetzen",
modal_header_text: "Lokale Kanaleinstellungen",
modal_channelname_text: "Lokaler Kanalname",
modal_colorpicker1_text: "Lokale Kanalfarbe",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Farbe an Unterkanäle vererben"
2018-10-11 10:21:26 +02:00
};
case "es": //spanish
return {
context_localchannelsettings_text: "Ajustes local de canal",
submenu_channelsettings_text: "Cambiar ajustes",
submenu_resetsettings_text: "Restablecer canal",
modal_header_text: "Ajustes local de canal",
modal_channelname_text: "Nombre local del canal",
modal_colorpicker1_text: "Color local del canal",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Heredar color a sub-canales"
2018-10-11 10:21:26 +02:00
};
case "fr": //french
return {
2019-12-02 20:43:01 +01:00
context_localchannelsettings_text: "Paramètres locale du salon",
2018-10-11 10:21:26 +02:00
submenu_channelsettings_text: "Modifier les paramètres",
2019-12-02 20:43:01 +01:00
submenu_resetsettings_text: "Réinitialiser le salon",
modal_header_text: "Paramètres locale du salon",
modal_channelname_text: "Nom local du salon",
modal_colorpicker1_text: "Couleur locale du salon",
modal_inheritcolor_text: "Hériter de la couleur sur les sous-salons"
2018-10-11 10:21:26 +02:00
};
case "it": //italian
return {
context_localchannelsettings_text: "Impostazioni locale canale",
submenu_channelsettings_text: "Cambia impostazioni",
submenu_resetsettings_text: "Ripristina canale",
modal_header_text: "Impostazioni locale canale",
modal_channelname_text: "Nome locale canale",
modal_colorpicker1_text: "Colore locale canale",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Eredita colore per sub-canali"
2018-10-11 10:21:26 +02:00
};
case "nl": //dutch
return {
context_localchannelsettings_text: "Lokale kanaalinstellingen",
submenu_channelsettings_text: "Verandere instellingen",
submenu_resetsettings_text: "Reset kanaal",
modal_header_text: "Lokale kanaalinstellingen",
modal_channelname_text: "Lokale kanaalnaam",
modal_colorpicker1_text: "Lokale kanaalkleur",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Overerving van kleuren naar subkanalen"
2018-10-11 10:21:26 +02:00
};
case "no": //norwegian
return {
context_localchannelsettings_text: "Lokal kanalinnstillinger",
submenu_channelsettings_text: "Endre innstillinger",
submenu_resetsettings_text: "Tilbakestill kanal",
modal_header_text: "Lokal kanalinnstillinger",
modal_channelname_text: "Lokalt kanalnavn",
modal_colorpicker1_text: "Lokal kanalfarge",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Arve farge til underkanaler"
2018-10-11 10:21:26 +02:00
};
case "pl": //polish
return {
context_localchannelsettings_text: "Lokalne ustawienia kanału",
submenu_channelsettings_text: "Zmień ustawienia",
submenu_resetsettings_text: "Resetuj ustawienia",
modal_header_text: "Lokalne ustawienia kanału",
modal_channelname_text: "Lokalna nazwa kanału",
modal_colorpicker1_text: "Lokalny kolor kanału",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Dziedzicz kolor do podkanałów"
2018-10-11 10:21:26 +02:00
};
case "pt-BR": //portuguese (brazil)
return {
context_localchannelsettings_text: "Configurações local do canal",
submenu_channelsettings_text: "Mudar configurações",
submenu_resetsettings_text: "Redefinir canal",
modal_header_text: "Configurações local do canal",
modal_channelname_text: "Nome local do canal",
modal_colorpicker1_text: "Cor local do canal",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Herdar cor aos sub-canais"
2018-10-11 10:21:26 +02:00
};
case "fi": //finnish
return {
context_localchannelsettings_text: "Paikallinen kanavan asetukset",
submenu_channelsettings_text: "Vaihda asetuksia",
submenu_resetsettings_text: "Nollaa kanava",
modal_header_text: "Paikallinen kanavan asetukset",
modal_channelname_text: "Paikallinen kanavanimi",
modal_colorpicker1_text: "Paikallinen kanavanväri",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Hävitä väri alikanaville"
2018-10-11 10:21:26 +02:00
};
case "sv": //swedish
return {
context_localchannelsettings_text: "Lokal kanalinställningar",
submenu_channelsettings_text: "Ändra inställningar",
submenu_resetsettings_text: "Återställ kanal",
modal_header_text: "Lokal kanalinställningar",
modal_channelname_text: "Lokalt kanalnamn",
modal_colorpicker1_text: "Lokal kanalfärg",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Inherit färg till subkanaler"
2018-10-11 10:21:26 +02:00
};
case "tr": //turkish
return {
context_localchannelsettings_text: "Yerel Kanal Ayarları",
submenu_channelsettings_text: "Ayarları Değiştir",
submenu_resetsettings_text: "Kanal Sıfırla",
modal_header_text: "Yerel Kanal Ayarları",
modal_channelname_text: "Yerel Kanal Adı",
modal_colorpicker1_text: "Yerel Kanal Rengi",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Renkleri alt kanallara miras alma"
2018-10-11 10:21:26 +02:00
};
case "cs": //czech
return {
context_localchannelsettings_text: "Místní nastavení kanálu",
submenu_channelsettings_text: "Změnit nastavení",
submenu_resetsettings_text: "Obnovit kanál",
modal_header_text: "Místní nastavení kanálu",
modal_channelname_text: "Místní název kanálu",
modal_colorpicker1_text: "Místní barvy kanálu",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Zdědit barvu na subkanály"
2018-10-11 10:21:26 +02:00
};
case "bg": //bulgarian
return {
context_localchannelsettings_text: "Настройки за локални канали",
submenu_channelsettings_text: "Промяна на настройките",
submenu_resetsettings_text: "Възстановяване на канал",
modal_header_text: "Настройки за локални канали",
modal_channelname_text: "Локално име на канал",
modal_colorpicker1_text: "Локален цветен канал",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Наследи цвета до подканали"
2018-10-11 10:21:26 +02:00
};
case "ru": //russian
return {
context_localchannelsettings_text: "Настройки локального канала",
submenu_channelsettings_text: "Изменить настройки",
submenu_resetsettings_text: "Сбросить канал",
modal_header_text: "Настройки локального канала",
modal_channelname_text: "Имя локального канала",
modal_colorpicker1_text: "Цвет локального канала",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Наследовать цвет на подканалы"
2018-10-11 10:21:26 +02:00
};
case "uk": //ukrainian
return {
context_localchannelsettings_text: "Налаштування локального каналу",
submenu_channelsettings_text: "Змінити налаштування",
submenu_resetsettings_text: "Скидання каналу",
modal_header_text: "Налаштування локального каналу",
modal_channelname_text: "Локальне ім'я каналу",
modal_colorpicker1_text: "Колір місцевого каналу",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Успадковують колір до підканалів"
2018-10-11 10:21:26 +02:00
};
case "ja": //japanese
return {
context_localchannelsettings_text: "ローカルチャネル設定",
submenu_channelsettings_text: "設定を変更する",
submenu_resetsettings_text: "チャネルをリセットする",
modal_header_text: "ローカルチャネル設定",
modal_channelname_text: "ローカルチャネル名",
modal_colorpicker1_text: "ローカルチャネルの色",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "サブチャンネルに色を継承"
2018-10-11 10:21:26 +02:00
};
case "zh-TW": //chinese (traditional)
return {
context_localchannelsettings_text: "本地頻道設置",
submenu_channelsettings_text: "更改設置",
submenu_resetsettings_text: "重置通道",
modal_header_text: "本地頻道設置",
modal_channelname_text: "本地頻道名稱",
modal_colorpicker1_text: "本地頻道顏色",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "繼承子通道的顏色"
2018-10-11 10:21:26 +02:00
};
case "ko": //korean
return {
context_localchannelsettings_text: "로컬 채널 설정",
submenu_channelsettings_text: "설정 변경",
submenu_resetsettings_text: "채널 재설정",
modal_header_text: "로컬 채널 설정",
modal_channelname_text: "로컬 채널 이름",
modal_colorpicker1_text: "지역 채널 색깔",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "하위 채널에 색상 상속"
2018-10-11 10:21:26 +02:00
};
default: //default: english
return {
context_localchannelsettings_text: "Local Channelsettings",
submenu_channelsettings_text: "Change Settings",
submenu_resetsettings_text: "Reset Channel",
modal_header_text: "Local Channelsettings",
modal_channelname_text: "Local Channelname",
modal_colorpicker1_text: "Local Channelcolor",
2019-09-11 12:14:43 +02:00
modal_inheritcolor_text: "Inherit color to Sub-Channels"
2018-10-11 10:21:26 +02:00
};
}
}
}