return (word.letters === initLetter) ? null : word;
}
+ function isNewWord(newWord, words) {
+ if (newWord === null) {
+ return false;
+ }
+ for (const k of Object.keys(words)) {
+ if ((words[k].letters === newWord.letters) &&
+ (words[k].row === newWord.row) &&
+ (words[k].col === newWord.col) &&
+ (words[k].incRow === newWord.incRow) &&
+ (words[k].incCol === newWord.incCol)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
function searchNewWords() {
const words = [];
/* Look for word in column */
const newWordInCol = searchWordInLine(row, col, 1, 0);
- if ((newWordInCol !== null) && (!words.find(element => element.letters === newWordInCol.letters))) {
+ if (isNewWord(newWordInCol, words)) {
words.push(newWordInCol);
}
/* Look for word in row */
const newWordInRow = searchWordInLine(row, col, 0, 1);
- if ((newWordInRow !== null) && (!words.find(element => element.letters === newWordInRow.letters))) {
+ if (isNewWord(newWordInRow, words)) {
words.push(newWordInRow);
}
function checkSpelling() {
let newWords = searchNewWords();
+ if (newWords.length === 0) {
+ myAlert(_("No new word found"));
+ return;
+ }
/* Check if words are in dictionary */
let words = [];
let badWords = [];
for (const k of Object.keys(newWords)) {
- words.push(newWords[k].letters.replace(/ /g, "?"));
+ let currentWord = newWords[k].letters.replace(/ /g, "?");
+ if (words.indexOf(currentWord) === -1) {
+ words.push(currentWord);
+ }
modifyTileClass(newWords[k], "tile-spelling-ok", true);
- setTimeout(function () {modifyTileClass(newWords[k], "tile-spelling-ok", false);}, 5000);
const pattern = "^" + newWords[k].letters.replace(/ /g, ".") + "$";
if (!dictionary.find(element => element.match(pattern))) {
- badWords.push(newWords[k].letters.replace(/ /g, "?"));
+ if (badWords.indexOf(currentWord) === -1) {
+ badWords.push(currentWord);
+ }
modifyTileClass(newWords[k], "tile-spelling-nok", true);
- setTimeout(function () {modifyTileClass(newWords[k], "tile-spelling-nok", false);}, 5000);
}
}
+ setTimeout(function () {
+ modifyTileClass(null, "tile-spelling-ok", false);
+ modifyTileClass(null, "tile-spelling-nok", false);
+ }, 5000);
words = words.join(", ").trim();
badWords = badWords.join(", ").trim();
if (badWords.length > 0) {
const msg = chatMessage("", format(_("Incorrect spelling for {0} from {1}"), badWords, words));
msg.classList.add("error");
- } else if (words.length > 0) {
- chatMessage("", format(_("All words are correct: {0}"), words));
} else {
- myAlert(_("No new word found"));
+ chatMessage("", format(_("All words are correct: {0}"), words));
}
}