diff --git a/index.html b/index.html index 30d24e7..48b243a 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@
- show all words random word resources + show all words random word resources
diff --git a/main.js b/main.js index c47bf07..1c1e748 100644 --- a/main.js +++ b/main.js @@ -229,7 +229,7 @@ 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))}; if (values[i][o].hasOwnProperty("meaning")) searchDictionary[keys[i]].push(stripWord(values[i][o]["meaning"], true)); } } catch (e) { @@ -301,16 +301,19 @@ function clickSearch(word) { //minds too hazy for this rn though... } -function doSearch(state = true, all = false) { - if (all == true) { - header.querySelector("input").value = "show:all"; - } +function doSearch(state = true) { let val = header.querySelector("input").value; if (val == "") { main.innerHTML = "enter some search terms..."; return; } - let results = search(val == "show:all" ? "" : val); + + //Manage search methods + val = (val.indexOf("show:random") !== -1) ? random.choice(list(searchDictionary.values())) : val; + val = (val.indexOf("show:all") !== -1) ? "" : val; + + //Results + let results = search(val); if (results.length == 0) { main.innerHTML = "no results (todo: cool form)"; } else { @@ -428,9 +431,22 @@ function doSearch(state = true, all = false) { types = sortObject(types); let header = document.createElement("div"); header.classList.add("results-header"); - header.innerHTML += "search results for: " + val + "
"; + //When using search methods, accomodate search text. + switch(val) { + //show:all + case "": + val = "Showing all words"; + break; + case "\"\"": + val = "Showing all words"; + break; + //OMG A WORD + default: + val = "search results for: " + val; + } + header.innerHTML += "" + val + "
"; for (let i in types) { - header.innerHTML += ""+i+"s - "+types[i]+""; + if(i !== ""){header.innerHTML += ""+i+"s - "+types[i]+"";} } main.prepend(header); } @@ -459,7 +475,15 @@ window.onload = () => { if (header.classList.contains("fullscreen")) { animateHeader(false); } - doSearch(true, true); + header.querySelector("input").value = "show:all"; + doSearch(true); + }; + header.querySelector("#randomWord").onclick = () => { + if (header.classList.contains("fullscreen")) { + animateHeader(false); + } + header.querySelector("input").value = "show:random"; + doSearch(true); }; loadDictionary(); window.addEventListener('popstate', (e) => {