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