From 2b97c381c4c7886d83308995653c557b36e7005e Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Mon, 25 May 2020 18:35:25 +0200 Subject: [PATCH] Update SpellCheck.plugin.js --- Plugins/SpellCheck/SpellCheck.plugin.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Plugins/SpellCheck/SpellCheck.plugin.js b/Plugins/SpellCheck/SpellCheck.plugin.js index 1db00524a2..6c3ad5cb00 100644 --- a/Plugins/SpellCheck/SpellCheck.plugin.js +++ b/Plugins/SpellCheck/SpellCheck.plugin.js @@ -6,7 +6,7 @@ var SpellCheck = (_ => { return class SpellCheck { getName () {return "SpellCheck";} - getVersion () {return "1.4.4";} + getVersion () {return "1.4.5";} getAuthor () {return "DevilBro";} @@ -298,14 +298,14 @@ var SpellCheck = (_ => { languageToasts[key].textContent = languageToasts[key].textContent.indexOf(".....") > -1 ? "Grabbing dictionary (" + this.getLanguageName(languages[lang]) + "). Please wait" : languageToasts[key].textContent + "."; }, 500); languageToasts[key].lang = lang - BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/SpellCheck/dic/" + lang + ".dic", (error, response, result) => { - if (error || (response && result.toLowerCase().indexOf("") > -1)) { + BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/SpellCheck/dic/" + lang + ".dic", (error, response, body) => { + if (error || (response && body.toLowerCase().indexOf("") > -1)) { this.killLanguageToast(key); BDFDB.NotificationUtils.toast("Failed to grab dictionary (" + this.getLanguageName(languages[lang]) + ").", {type: "error"}); } else if (response && languageToasts[key].lang == lang) { - langDictionaries[key] = result.split("\n"); - dictionaries[key] = this.formatDictionary(langDictionaries[key].concat(ownDictionary).map(word => word.toLowerCase()).filter(n => typeof n == "string")); + langDictionaries[key] = body.toLowerCase().replace(/\r/g, "").split("\n"); + dictionaries[key] = this.formatDictionary(langDictionaries[key].concat(ownDictionary)); this.killLanguageToast(key); BDFDB.NotificationUtils.toast("Successfully grabbed dictionary (" + this.getLanguageName(languages[lang]) + ").", {type: "success"}); } @@ -318,14 +318,14 @@ var SpellCheck = (_ => { } formatDictionary (words) { - let dictionary = {}; - for (let word of words.filter(n => typeof n == "string")) { + let i = 0; + return words.reduce((dictionary, word) => { let firstLetterLower = word.charAt(0).toLowerCase(); if (!dictionary[firstLetterLower]) dictionary[firstLetterLower] = {}; if (!dictionary[firstLetterLower][word.length]) dictionary[firstLetterLower][word.length] = []; - if (!dictionary[firstLetterLower][word.length].includes(word)) dictionary[firstLetterLower][word.length].push(word); - } - return dictionary; + dictionary[firstLetterLower][word.length].push(word); + return dictionary; + }, {}); } killLanguageToast (key) {