diff options
author | Loek Le Blansch <l.leblansch@gmail.com> | 2020-07-14 20:36:19 +0200 |
---|---|---|
committer | Loek Le Blansch <l.leblansch@gmail.com> | 2020-07-14 20:36:19 +0200 |
commit | e6a025a7cca1abb7b2719a281308bd93f03f1a16 (patch) | |
tree | 322eea054e9efd44acbec265472e254e3c134e7f /.config/BetterDiscord/plugins/SendLargeMessages.plugin.js | |
parent | 4581376a1b136bda087190f4c6b440d55801aeaa (diff) |
commit message here
Diffstat (limited to '.config/BetterDiscord/plugins/SendLargeMessages.plugin.js')
-rw-r--r-- | .config/BetterDiscord/plugins/SendLargeMessages.plugin.js | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/.config/BetterDiscord/plugins/SendLargeMessages.plugin.js b/.config/BetterDiscord/plugins/SendLargeMessages.plugin.js index 3827ee2..110667b 100644 --- a/.config/BetterDiscord/plugins/SendLargeMessages.plugin.js +++ b/.config/BetterDiscord/plugins/SendLargeMessages.plugin.js @@ -1,10 +1,12 @@ //META{"name":"SendLargeMessages","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/SendLargeMessages","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SendLargeMessages/SendLargeMessages.plugin.js"}*// var SendLargeMessages = (_ => { + var messageDelay = 1000; //changing at own risk, might result in bans or mutes + return class SendLargeMessages { getName () {return "SendLargeMessages";} - getVersion () {return "1.6.4";} + getVersion () {return "1.6.5";} getAuthor () {return "DevilBro";} @@ -23,8 +25,6 @@ var SendLargeMessages = (_ => { } initConstructor () { - this.messageDelay = 1000; //changing at own risk, might result in bans or mutes - this.css = ` .${this.name}-modal textarea { height: 50vh; @@ -88,7 +88,7 @@ var SendLargeMessages = (_ => { BDFDB.TimeUtils.timeout(_ => { e2.originalMethod(message); if (i >= messages.length-1) BDFDB.NotificationUtils.toast(this.labels.toast_allsent_text, {type:"success"}); - }, this.messageDelay * i); + }, messageDelay * i); }); return Promise.resolve({ shouldClear: true, @@ -101,7 +101,7 @@ var SendLargeMessages = (_ => { processChannelTextAreaContainer (e) { if (e.returnvalue.ref && e.returnvalue.ref.current && BDFDB.DOMUtils.getParent(BDFDB.dotCN.chatform, e.returnvalue.ref.current)) { - let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "SlateCharacterCount"}); + let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "SlateCharacterCount"}); if (index > -1) { let text = BDFDB.LibraryModules.SlateSelectionUtils.serialize(children[index].props.document, "raw"); if (text.length > BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH) children[index] = BDFDB.ReactUtils.createElement("div", { @@ -123,15 +123,15 @@ var SendLargeMessages = (_ => { formatText (text) { text = text.replace(/\t/g, " "); - let longwords = text.match(/[\S]{1800,}/gm); - if (longwords) for (let longword of longwords) { + let longWords = text.match(new RegExp(`[^ ]{${BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20)},}`, "gm")); + if (longWords) for (let longWord of longWords) { let count1 = 0; - let shortwords = []; - longword.split("").forEach(c => { - if (shortwords[count1] && shortwords[count1].length >= BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20)) count1++; - shortwords[count1] = shortwords[count1] ? shortwords[count1] + c : c; + let shortWords = []; + longWord.split("").forEach(c => { + if (shortWords[count1] && (shortWords[count1].length >= BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20) || (c == "\n" && shortWords[count1].length >= BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20) - 100))) count1++; + shortWords[count1] = shortWords[count1] ? shortWords[count1] + c : c; }); - text = text.replace(longword, shortwords.join(" ")); + text = text.replace(longWord, shortWords.join(" ")); } let messages = []; let count2 = 0; @@ -163,7 +163,6 @@ var SendLargeMessages = (_ => { messages[j] = messages[j] + insertCodeLine; } } - return messages; } |