From ce1c8c7bbbf89ec1c1e41c0f6c4f24c2d9711903 Mon Sep 17 00:00:00 2001 From: Bizcochito Date: Sat, 11 Jun 2022 09:23:53 +0200 Subject: [PATCH] worked on #14, now show:random gets a random english word with translation and querries it with an aux array --- main.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 1c1e748..86f83bf 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ let json = null; let searchDictionary = {}; +let auxTranslatedDictionaryArray = []; let header = null; let main = null; @@ -229,7 +230,10 @@ function loadDictionary() { //add: translations, meanings for (let o = 0; o < values[i].length; o++) { - if (values[i][o].hasOwnProperty("translation")){searchDictionary[keys[i]].push(stripWord(values[i][o]["translation"], true))}; + if (values[i][o].hasOwnProperty("translation")){ + searchDictionary[keys[i]].push(stripWord(values[i][o]["translation"], true)) + auxTranslatedDictionaryArray.push(stripWord(values[i][o]["translation"], true)) + }; if (values[i][o].hasOwnProperty("meaning")) searchDictionary[keys[i]].push(stripWord(values[i][o]["meaning"], true)); } } catch (e) { @@ -309,7 +313,7 @@ function doSearch(state = true) { } //Manage search methods - val = (val.indexOf("show:random") !== -1) ? random.choice(list(searchDictionary.values())) : val; + val = (val.indexOf("show:random") !== -1) ? auxTranslatedDictionaryArray[(Math.floor(Math.random() * auxTranslatedDictionaryArray.length))] : val; val = (val.indexOf("show:all") !== -1) ? "" : val; //Results