simple search results stats
This commit is contained in:
parent
260e25e37a
commit
fad6471e48
18
main.css
18
main.css
@ -128,6 +128,9 @@ header input:focus {
|
|||||||
|
|
||||||
header span.heonian {
|
header span.heonian {
|
||||||
font-size: 1.5rem;
|
font-size: 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
header.fullscreen {
|
header.fullscreen {
|
||||||
@ -145,6 +148,7 @@ header.fullscreen {
|
|||||||
|
|
||||||
header.fullscreen span.heonian {
|
header.fullscreen span.heonian {
|
||||||
font-size: 8rem;
|
font-size: 8rem;
|
||||||
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
header.fullscreen #search {
|
header.fullscreen #search {
|
||||||
@ -191,6 +195,10 @@ main {
|
|||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.result:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
.result-meaning {
|
.result-meaning {
|
||||||
padding-bottom: 8px;
|
padding-bottom: 8px;
|
||||||
}
|
}
|
||||||
@ -222,6 +230,8 @@ main {
|
|||||||
color: var(--darkgrey);
|
color: var(--darkgrey);
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
|
border-left: 3px solid var(--darkgrey);
|
||||||
|
padding-left: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result-translation {
|
.result-translation {
|
||||||
@ -244,4 +254,12 @@ main {
|
|||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.results-header-count::after {
|
||||||
|
content: ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
.results-header-count:last-child::after {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
|
||||||
/* todo. organize this file better. this is a fucking mess */
|
/* todo. organize this file better. this is a fucking mess */
|
33
main.js
33
main.js
@ -169,7 +169,7 @@ function loadDictionary() {
|
|||||||
searchDictionary[keys[i]] = [];
|
searchDictionary[keys[i]] = [];
|
||||||
|
|
||||||
//add: word
|
//add: word
|
||||||
searchDictionary[keys[i]].push(keys[i]);
|
// searchDictionary[keys[i]].push(keys[i]);
|
||||||
|
|
||||||
//add: romanized word
|
//add: romanized word
|
||||||
searchDictionary[keys[i]].push(stripWord(heonianToRoman(keys[i])));
|
searchDictionary[keys[i]].push(stripWord(heonianToRoman(keys[i])));
|
||||||
@ -196,6 +196,7 @@ function loadDictionary() {
|
|||||||
|
|
||||||
function search(word) {
|
function search(word) {
|
||||||
word = stripWord(word);
|
word = stripWord(word);
|
||||||
|
word = heonianToRoman(word);
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let key in searchDictionary) {
|
for (let key in searchDictionary) {
|
||||||
for (let value in searchDictionary[key]) {
|
for (let value in searchDictionary[key]) {
|
||||||
@ -209,7 +210,8 @@ function search(word) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doSearch() {
|
function doSearch() {
|
||||||
let results = search(header.querySelector("input").value);
|
let val = header.querySelector("input").value;
|
||||||
|
let results = search(val);
|
||||||
if (results.length == 0) {
|
if (results.length == 0) {
|
||||||
main.innerHTML = "no results lulw";
|
main.innerHTML = "no results lulw";
|
||||||
} else {
|
} else {
|
||||||
@ -217,6 +219,7 @@ function doSearch() {
|
|||||||
/*
|
/*
|
||||||
[words - 420 found / expressions - 69 found / wahtever else - ygettheidea] (click one to filter to just those)
|
[words - 420 found / expressions - 69 found / wahtever else - ygettheidea] (click one to filter to just those)
|
||||||
*/
|
*/
|
||||||
|
let types = {}
|
||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
let result = document.createElement("div");
|
let result = document.createElement("div");
|
||||||
result.classList.add("result");
|
result.classList.add("result");
|
||||||
@ -227,8 +230,10 @@ function doSearch() {
|
|||||||
header.innerHTML = results[i] + " <rt>" + heonianToRoman(results[i]) + "</rt>";
|
header.innerHTML = results[i] + " <rt>" + heonianToRoman(results[i]) + "</rt>";
|
||||||
|
|
||||||
// 2. add tags [tags like. common word, slang, formal???, type, etc]
|
// 2. add tags [tags like. common word, slang, formal???, type, etc]
|
||||||
|
// hhh how do i do this part, what tags. would i add. would this be. per word, or per definition?
|
||||||
|
|
||||||
// 3. formal/nonformal versions, inflections button
|
// 3. formal/nonformal versions, inflections button
|
||||||
|
// could try to work on this though
|
||||||
|
|
||||||
// 4. audio clip if found
|
// 4. audio clip if found
|
||||||
|
|
||||||
@ -245,6 +250,11 @@ function doSearch() {
|
|||||||
meaning.classList.add("result-meaning");
|
meaning.classList.add("result-meaning");
|
||||||
//ripping off jisho: Bold, word type (*required)
|
//ripping off jisho: Bold, word type (*required)
|
||||||
meaning.innerHTML += "<b class='capitalize'>"+json[results[i]][o]["type"]+"</b>";
|
meaning.innerHTML += "<b class='capitalize'>"+json[results[i]][o]["type"]+"</b>";
|
||||||
|
if (types[json[results[i]][o]["type"]] == undefined) {
|
||||||
|
types[json[results[i]][o]["type"]] = 0;
|
||||||
|
} else {
|
||||||
|
types[json[results[i]][o]["type"]]++;
|
||||||
|
}
|
||||||
//number, meaning (*required)
|
//number, meaning (*required)
|
||||||
meaning.innerHTML += "<br><span class='result-number'>"+(o+1)+"</span><span class='result-big'>"+json[results[i]][o]["meaning"]+"</span>";
|
meaning.innerHTML += "<br><span class='result-number'>"+(o+1)+"</span><span class='result-big'>"+json[results[i]][o]["meaning"]+"</span>";
|
||||||
//longer translation (below are not required, make sure to check for them)
|
//longer translation (below are not required, make sure to check for them)
|
||||||
@ -256,7 +266,7 @@ function doSearch() {
|
|||||||
let temp = ""
|
let temp = ""
|
||||||
temp += "<details><summary>Examples</summary><p>";
|
temp += "<details><summary>Examples</summary><p>";
|
||||||
for (let e in json[results[i]][o]["examples"]) {
|
for (let e in json[results[i]][o]["examples"]) {
|
||||||
temp += "<span class='heonian'>"+e+"</span> - "+json[results[i]][o]["examples"][e];
|
temp += "<span class='heonian'>"+e+"</span> - "+json[results[i]][o]["examples"][e]+"<br>";
|
||||||
}
|
}
|
||||||
temp += "</p></details>";
|
temp += "</p></details>";
|
||||||
meaning.innerHTML += temp;
|
meaning.innerHTML += temp;
|
||||||
@ -277,6 +287,14 @@ function doSearch() {
|
|||||||
}
|
}
|
||||||
main.appendChild(result);
|
main.appendChild(result);
|
||||||
}
|
}
|
||||||
|
types = sortObject(types);
|
||||||
|
let header = document.createElement("div");
|
||||||
|
header.classList.add("results-header");
|
||||||
|
header.innerHTML += "<span class='heonian'>search results for: " + val + "</span><br>";
|
||||||
|
for (let i in types) {
|
||||||
|
header.innerHTML += "<span class='results-header-count'>"+i+"s - "+types[i]+"</span>";
|
||||||
|
}
|
||||||
|
main.prepend(header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,5 +302,12 @@ window.onload = () => {
|
|||||||
header = document.querySelector("header");
|
header = document.querySelector("header");
|
||||||
main = document.querySelector("main");
|
main = document.querySelector("main");
|
||||||
header.querySelector("#search button").onclick = () => {toggleIME();};
|
header.querySelector("#search button").onclick = () => {toggleIME();};
|
||||||
|
header.querySelector("span.heonian").onclick = () => {
|
||||||
|
if (!header.classList.contains("fullscreen")) {
|
||||||
|
animateHeader(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
loadDictionary();
|
loadDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sortObject = obj => Object.keys(obj).sort().reduce((res, key) => (res[key] = obj[key], res), {})
|
Loading…
Reference in New Issue
Block a user