This commit is contained in:
Mirco Wittrien 2019-12-11 08:51:09 +01:00
parent f7f705612a
commit 53800532be
2 changed files with 55 additions and 54 deletions

View File

@ -3,7 +3,7 @@
class ChatAliases { class ChatAliases {
getName () {return "ChatAliases";} getName () {return "ChatAliases";}
getVersion () {return "2.0.1";} getVersion () {return "2.0.2";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -11,12 +11,12 @@ class ChatAliases {
constructor () { constructor () {
this.changelog = { this.changelog = {
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]] "fixed":[["Little Fix","Sendings works again, but some stuff is still broken"]]
}; };
this.patchedModules = { this.patchedModules = {
after: { after: {
ChannelTextArea: "componentDidMount" ChannelTextArea: ["render", "componentDidMount"]
} }
}; };
} }
@ -329,61 +329,62 @@ class ChatAliases {
processChannelTextArea (e) { processChannelTextArea (e) {
if (e.instance.props.channel && e.instance.props.type) { if (e.instance.props.channel && e.instance.props.type) {
var textarea = e.node.querySelector("textarea"); if (e.returnvalue) {
if (!textarea) return; if (!BDFDB.ModuleUtils.isPatched(this, e.instance, "handleSubmit")) BDFDB.ModuleUtils.patch(this, e.instance, "handleSubmit", {before: e2 => {
let settings = BDFDB.DataUtils.get(this, "settings"); let messageData = this.formatText(e2.methodArguments[0]);
BDFDB.ListenerUtils.add(this, textarea, "input", () => { if (messageData) {
if (this.format) { if (messageData.text != null) {
this.format = false; e2.methodArguments[0] = messageData.text;
textarea.focus(); if (!messageData.text) {
textarea.selectionStart = 0; e.instance.props.textValue = "";
textarea.selectionEnd = textarea.value.length; if (e.instance.props.richValue) e.instance.props.richValue = BDFDB.StringUtils.copyRichValue("", e.instance.props.richValue);
if (document.activeElement == textarea) { BDFDB.ReactUtils.forceUpdate(e.instance);
var messageInput = this.formatText(textarea.value);
if (messageInput) {
if (messageInput.text != null) {
document.execCommand("insertText", false, messageInput.text ? messageInput.text + " " : "");
}
if (messageInput.files.length > 0 && (e.instance.props.channel.type == 1 || BDFDB.UserUtils.can("ATTACH_FILES"))) {
BDFDB.LibraryModules.UploadUtils.instantBatchUpload(e.instance.props.channel.id, messageInput.files);
} }
} }
if (messageData.files.length > 0 && (e.instance.props.channel.type == 1 || BDFDB.UserUtils.can("ATTACH_FILES"))) {
BDFDB.LibraryModules.UploadUtils.instantBatchUpload(e.instance.props.channel.id, messageData.files);
}
} }
} }}, true);
}); }
BDFDB.ListenerUtils.add(this, textarea, "keydown", event => { if (e.node) {
let autocompletemenu = textarea.parentElement.querySelector(BDFDB.dotCN.autocomplete); let textarea = e.node.querySelector("textarea");
if (autocompletemenu && (event.which == 9 || event.which == 13)) { if (!textarea) return;
if (BDFDB.DOMUtils.containsClass(autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected).parentElement, "autocompleteAliasesRow")) { let settings = BDFDB.DataUtils.get(this, "settings");
BDFDB.ListenerUtils.stopEvent(event); BDFDB.ListenerUtils.add(this, textarea, "keydown", event => {
this.swapWordWithAlias(textarea); let autocompletemenu = textarea.parentElement.querySelector(BDFDB.dotCN.autocomplete);
if (autocompletemenu && (event.which == 9 || event.which == 13)) {
if (BDFDB.DOMUtils.containsClass(autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected).parentElement, "autocompleteAliasesRow")) {
BDFDB.ListenerUtils.stopEvent(event);
this.swapWordWithAlias(textarea);
}
} }
} else if (autocompletemenu && (event.which == 38 || event.which == 40)) {
else if (autocompletemenu && (event.which == 38 || event.which == 40)) { let autocompleteitems = autocompletemenu.querySelectorAll(BDFDB.dotCN.autocompleteselectable + ":not(.autocompleteAliasesSelector)");
let autocompleteitems = autocompletemenu.querySelectorAll(BDFDB.dotCN.autocompleteselectable + ":not(.autocompleteAliasesSelector)"); let selected = autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected);
let selected = autocompletemenu.querySelector(BDFDB.dotCN.autocompleteselected); if (BDFDB.DOMUtils.containsClass(selected, "autocompleteAliasesSelector") || autocompleteitems[event.which == 38 ? 0 : (autocompleteitems.length-1)] == selected) {
if (BDFDB.DOMUtils.containsClass(selected, "autocompleteAliasesSelector") || autocompleteitems[event.which == 38 ? 0 : (autocompleteitems.length-1)] == selected) { BDFDB.ListenerUtils.stopEvent(event);
BDFDB.ListenerUtils.stopEvent(event); let next = this.getNextSelection(autocompletemenu, null, event.which == 38 ? false : true);
let next = this.getNextSelection(autocompletemenu, null, event.which == 38 ? false : true); BDFDB.DOMUtils.removeClass(selected, BDFDB.disCN.autocompleteselected);
BDFDB.DOMUtils.removeClass(selected, BDFDB.disCN.autocompleteselected); BDFDB.DOMUtils.addClass(selected, BDFDB.disCN.autocompleteselector);
BDFDB.DOMUtils.addClass(selected, BDFDB.disCN.autocompleteselector); BDFDB.DOMUtils.addClass(next, BDFDB.disCN.autocompleteselected);
BDFDB.DOMUtils.addClass(next, BDFDB.disCN.autocompleteselected); }
}
else if (textarea.value && !event.shiftKey && event.which == 13 && !autocompletemenu && textarea.value.indexOf("s/") != 0) {
this.format = true;
textarea.dispatchEvent(new Event("input"));
}
else if (!event.ctrlKey && event.which != 16 && settings.addAutoComplete && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length) {
BDFDB.TimeUtils.clear(textarea.ChatAliasAutocompleteTimeout);
textarea.ChatAliasAutocompleteTimeout = BDFDB.TimeUtils.timeout(() => {this.addAutoCompleteMenu(textarea);},100);
} }
}
else if (textarea.value && !event.shiftKey && event.which == 13 && !autocompletemenu && textarea.value.indexOf("s/") != 0) {
this.format = true;
textarea.dispatchEvent(new Event("input"));
}
else if (!event.ctrlKey && event.which != 16 && settings.addAutoComplete && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length) {
BDFDB.TimeUtils.clear(textarea.ChatAliasAutocompleteTimeout);
textarea.ChatAliasAutocompleteTimeout = BDFDB.TimeUtils.timeout(() => {this.addAutoCompleteMenu(textarea);},100);
}
if (!event.ctrlKey && event.which != 38 && event.which != 40 && !(event.which == 39 && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length)) BDFDB.DOMUtils.remove(".autocompleteAliases", ".autocompleteAliasesRow"); if (!event.ctrlKey && event.which != 38 && event.which != 40 && !(event.which == 39 && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length)) BDFDB.DOMUtils.remove(".autocompleteAliases", ".autocompleteAliasesRow");
}); });
BDFDB.ListenerUtils.add(this, textarea, "click", _ => { BDFDB.ListenerUtils.add(this, textarea, "click", _ => {
if (settings.addAutoComplete && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length) BDFDB.TimeUtils.timeout(() => {this.addAutoCompleteMenu(textarea);}); if (settings.addAutoComplete && textarea.selectionStart == textarea.selectionEnd && textarea.selectionEnd == textarea.value.length) BDFDB.TimeUtils.timeout(() => {this.addAutoCompleteMenu(textarea);});
}); });
}
} }
} }

View File

@ -3,7 +3,7 @@
class GoogleTranslateOption { class GoogleTranslateOption {
getName () {return "GoogleTranslateOption";} getName () {return "GoogleTranslateOption";}
getVersion () {return "1.8.3";} getVersion () {return "1.8.4";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -244,7 +244,7 @@ class GoogleTranslateOption {
}); });
} }
else e2.callOriginalMethod(); else e2.callOriginalMethod();
}}); }}, true);
} }
} }