mess with how the code looks too much. sorry, yari >~<
This commit is contained in:
parent
ce1c8c7bbb
commit
0e8ac06e26
30
main.js
30
main.js
@ -1,7 +1,6 @@
|
||||
let json = null;
|
||||
|
||||
let searchDictionary = {};
|
||||
let auxTranslatedDictionaryArray = [];
|
||||
|
||||
let header = null;
|
||||
let main = null;
|
||||
@ -232,7 +231,6 @@ function loadDictionary() {
|
||||
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))
|
||||
auxTranslatedDictionaryArray.push(stripWord(values[i][o]["translation"], true))
|
||||
};
|
||||
if (values[i][o].hasOwnProperty("meaning")) searchDictionary[keys[i]].push(stripWord(values[i][o]["meaning"], true));
|
||||
}
|
||||
@ -251,7 +249,14 @@ function loadDictionary() {
|
||||
});
|
||||
}
|
||||
|
||||
function search(word) {
|
||||
function search(word, type) {
|
||||
console.log(type);
|
||||
if (type == "all") {word = ""};
|
||||
if (type == "random") {
|
||||
let random = Math.floor(Math.random() * Object.keys(json).length);
|
||||
return [Object.keys(json)[random]];
|
||||
}
|
||||
console.log(word);
|
||||
let words = word.split(" ");
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
words[i] = stripWord(words[i]);
|
||||
@ -313,11 +318,15 @@ function doSearch(state = true) {
|
||||
}
|
||||
|
||||
//Manage search methods
|
||||
val = (val.indexOf("show:random") !== -1) ? auxTranslatedDictionaryArray[(Math.floor(Math.random() * auxTranslatedDictionaryArray.length))] : val;
|
||||
val = (val.indexOf("show:all") !== -1) ? "" : val;
|
||||
let type = "normal";
|
||||
if (val.includes("show:random")) {
|
||||
type = "random";
|
||||
} else if (val.includes("show:all")) {
|
||||
type = "all";
|
||||
}
|
||||
|
||||
//Results
|
||||
let results = search(val);
|
||||
let results = search(val, type);
|
||||
if (results.length == 0) {
|
||||
main.innerHTML = "no results (todo: cool form)";
|
||||
} else {
|
||||
@ -436,17 +445,18 @@ function doSearch(state = true) {
|
||||
let header = document.createElement("div");
|
||||
header.classList.add("results-header");
|
||||
//When using search methods, accomodate search text.
|
||||
switch(val) {
|
||||
switch(type) {
|
||||
//show:all
|
||||
case "":
|
||||
case "all":
|
||||
val = "Showing all words";
|
||||
break;
|
||||
case "\"\"":
|
||||
val = "Showing all words";
|
||||
case "random":
|
||||
val = "Showing random word: " + results[0];
|
||||
break;
|
||||
//OMG A WORD
|
||||
default:
|
||||
val = "search results for: " + val;
|
||||
break;
|
||||
}
|
||||
header.innerHTML += "<span class='heonian'>" + val + "</span><br>";
|
||||
for (let i in types) {
|
||||
|
Loading…
Reference in New Issue
Block a user