Update SpellCheck.plugin.js
This commit is contained in:
parent
0f3c015ca0
commit
3ffacac4f9
|
@ -6,7 +6,7 @@ var SpellCheck = (_ => {
|
||||||
return class SpellCheck {
|
return class SpellCheck {
|
||||||
getName () {return "SpellCheck";}
|
getName () {return "SpellCheck";}
|
||||||
|
|
||||||
getVersion () {return "1.4.3";}
|
getVersion () {return "1.4.4";}
|
||||||
|
|
||||||
getAuthor () {return "DevilBro";}
|
getAuthor () {return "DevilBro";}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ var SpellCheck = (_ => {
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.changelog = {
|
this.changelog = {
|
||||||
"added":[["Secondary","You can now set a secondary language in the plugin settings"]]
|
"improved":[["Performance","Redesigned dictionaries to speed up error check"]],
|
||||||
|
"fixed":[["Punctuation","Words with a '.' etc. no longer get marked as errors"]]
|
||||||
};
|
};
|
||||||
|
|
||||||
this.patchedModules = {
|
this.patchedModules = {
|
||||||
|
@ -96,7 +97,7 @@ var SpellCheck = (_ => {
|
||||||
onRemove: _ => {
|
onRemove: _ => {
|
||||||
BDFDB.ArrayUtils.remove(ownDictionary, word);
|
BDFDB.ArrayUtils.remove(ownDictionary, word);
|
||||||
BDFDB.DataUtils.save(ownDictionary, this, "owndics", choices.dictionaryLanguage);
|
BDFDB.DataUtils.save(ownDictionary, this, "owndics", choices.dictionaryLanguage);
|
||||||
dictionaries.dictionaryLanguage = langDictionaries.dictionaryLanguage.concat(ownDictionary);
|
dictionaries.dictionaryLanguage = this.formatDictionary(langDictionaries.dictionaryLanguage.concat(ownDictionary));
|
||||||
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel);
|
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel);
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
@ -282,7 +283,7 @@ var SpellCheck = (_ => {
|
||||||
ownDictionary.push(wordLow);
|
ownDictionary.push(wordLow);
|
||||||
BDFDB.DataUtils.save(ownDictionary, this, "owndics", lang);
|
BDFDB.DataUtils.save(ownDictionary, this, "owndics", lang);
|
||||||
BDFDB.NotificationUtils.toast(this.labels.toast_wordadd_text.replace("${word}", word).replace("${dicName}", this.getLanguageName(languages[lang])), {type:"success"});
|
BDFDB.NotificationUtils.toast(this.labels.toast_wordadd_text.replace("${word}", word).replace("${dicName}", this.getLanguageName(languages[lang])), {type:"success"});
|
||||||
dictionaries.dictionaryLanguage = langDictionaries.dictionaryLanguage.concat(ownDictionary);
|
dictionaries.dictionaryLanguage = this.formatDictionary(langDictionaries.dictionaryLanguage.concat(ownDictionary));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,7 +292,7 @@ var SpellCheck = (_ => {
|
||||||
setDictionary (key, lang) {
|
setDictionary (key, lang) {
|
||||||
this.killLanguageToast(key);
|
this.killLanguageToast(key);
|
||||||
if (languages[lang]) {
|
if (languages[lang]) {
|
||||||
dictionaries[key] = BDFDB.DataUtils.load(this, "owndics", lang) || [];
|
let ownDictionary = BDFDB.DataUtils.load(this, "owndics", lang) || [];
|
||||||
languageToasts[key] = BDFDB.NotificationUtils.toast("Grabbing dictionary (" + this.getLanguageName(languages[lang]) + "). Please wait", {timeout:0});
|
languageToasts[key] = BDFDB.NotificationUtils.toast("Grabbing dictionary (" + this.getLanguageName(languages[lang]) + "). Please wait", {timeout:0});
|
||||||
languageToasts[key].interval = BDFDB.TimeUtils.interval(_ => {
|
languageToasts[key].interval = BDFDB.TimeUtils.interval(_ => {
|
||||||
languageToasts[key].textContent = languageToasts[key].textContent.indexOf(".....") > -1 ? "Grabbing dictionary (" + this.getLanguageName(languages[lang]) + "). Please wait" : languageToasts[key].textContent + ".";
|
languageToasts[key].textContent = languageToasts[key].textContent.indexOf(".....") > -1 ? "Grabbing dictionary (" + this.getLanguageName(languages[lang]) + "). Please wait" : languageToasts[key].textContent + ".";
|
||||||
|
@ -304,7 +305,7 @@ var SpellCheck = (_ => {
|
||||||
}
|
}
|
||||||
else if (response && languageToasts[key].lang == lang) {
|
else if (response && languageToasts[key].lang == lang) {
|
||||||
langDictionaries[key] = result.split("\n");
|
langDictionaries[key] = result.split("\n");
|
||||||
dictionaries[key] = langDictionaries[key].concat(dictionaries[key]).map(word => word.toLowerCase()).filter(n => n);
|
dictionaries[key] = this.formatDictionary(langDictionaries[key].concat(ownDictionary).map(word => word.toLowerCase()).filter(n => typeof n == "string"));
|
||||||
this.killLanguageToast(key);
|
this.killLanguageToast(key);
|
||||||
BDFDB.NotificationUtils.toast("Successfully grabbed dictionary (" + this.getLanguageName(languages[lang]) + ").", {type: "success"});
|
BDFDB.NotificationUtils.toast("Successfully grabbed dictionary (" + this.getLanguageName(languages[lang]) + ").", {type: "success"});
|
||||||
}
|
}
|
||||||
|
@ -316,6 +317,17 @@ var SpellCheck = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formatDictionary (words) {
|
||||||
|
let dictionary = {};
|
||||||
|
for (let word of words.filter(n => typeof n == "string")) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
killLanguageToast (key) {
|
killLanguageToast (key) {
|
||||||
if (languageToasts[key] && typeof languageToasts[key].close == "function") {
|
if (languageToasts[key] && typeof languageToasts[key].close == "function") {
|
||||||
BDFDB.TimeUtils.clear(languageToasts[key].interval);
|
BDFDB.TimeUtils.clear(languageToasts[key].interval);
|
||||||
|
@ -323,12 +335,15 @@ var SpellCheck = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isWordNotInDictionary (word) {
|
isWordNotInDictionary (unformatedWord) {
|
||||||
let wordLow = word.toLowerCase();
|
let wordLow = unformatedWord.toLowerCase();
|
||||||
let wordWithoutSymbols = wordLow.replace(/[0-9\µ\@\$\£\€\¥\¢\²\³\>\<\|\,\;\.\:\_\#\+\*\~\?\¿\\\´\`\}\=\]\)\[\(\{\/\&\%\§\"\!\¡\^\°\n\t\r]/g, "");
|
let wordWithoutSymbols = wordLow.replace(/[0-9\µ\@\$\£\€\¥\¢\²\³\>\<\|\,\;\.\:\_\#\+\*\~\?\¿\\\´\`\}\=\]\)\[\(\{\/\&\%\§\"\!\¡\^\°\n\t\r]/g, "");
|
||||||
if (wordLow.indexOf("http://") != 0 && wordLow.indexOf("https://") != 0 && wordWithoutSymbols) {
|
if (wordLow.indexOf("http://") != 0 && wordLow.indexOf("https://") != 0 && wordWithoutSymbols) {
|
||||||
for (let key in dictionaries) {
|
for (let key in dictionaries) {
|
||||||
if (Array.isArray(dictionaries[key]) && dictionaries[key].includes(wordLow) && dictionaries[key].includes(wordWithoutSymbols)) return false;
|
for (let word of [wordLow, wordWithoutSymbols]) {
|
||||||
|
let firstLetterLower = word.charAt(0).toLowerCase();
|
||||||
|
if (dictionaries[key] && dictionaries[key][firstLetterLower] && dictionaries[key][firstLetterLower][word.length] && dictionaries[key][firstLetterLower][word.length].includes(word)) return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -339,10 +354,12 @@ var SpellCheck = (_ => {
|
||||||
getSimilarWords (word) {
|
getSimilarWords (word) {
|
||||||
let maxAmount = BDFDB.DataUtils.get(this, "amounts", "maxSimilarAmount"), similarWords = [];
|
let maxAmount = BDFDB.DataUtils.get(this, "amounts", "maxSimilarAmount"), similarWords = [];
|
||||||
if (maxAmount > 0) {
|
if (maxAmount > 0) {
|
||||||
let firstLetterLower = word.toLowerCase().charAt(0);
|
let firstLetterLower = word.charAt(0).toLowerCase();
|
||||||
let sameLetterDic = BDFDB.ArrayUtils.removeCopies(BDFDB.ObjectUtils.toArray(dictionaries).flat()).filter(string => string.indexOf(firstLetterLower) == 0 && string);
|
let possibilities = [];
|
||||||
|
for (let key in dictionaries) if (dictionaries[key] && dictionaries[key][firstLetterLower]) possibilities = possibilities.concat(BDFDB.ObjectUtils.toArray(dictionaries[key][firstLetterLower]).flat());
|
||||||
|
possibilities = BDFDB.ArrayUtils.removeCopies(possibilities);
|
||||||
let similarities = {};
|
let similarities = {};
|
||||||
for (let string of sameLetterDic) {
|
for (let string of possibilities) {
|
||||||
let value = this.wordSimilarity(word, string);
|
let value = this.wordSimilarity(word, string);
|
||||||
if (!similarities[value]) similarities[value] = [];
|
if (!similarities[value]) similarities[value] = [];
|
||||||
similarities[value].push(string);
|
similarities[value].push(string);
|
||||||
|
|
Loading…
Reference in New Issue