fix json + work on search page

This commit is contained in:
2022-06-09 01:29:35 +02:00
parent 09ccb57b80
commit 312bf4b720
3 changed files with 84 additions and 14 deletions

42
main.js
View File

@@ -120,10 +120,14 @@ function heonianToRoman(text) {
let h = text.codePointAt(i);
if (h >= 57344 && h <= 57606) {
h = text.codePointAt(i).toString(16).split("");
if (h[1] == 0 && h[2] == 0) {
if (h[1] == 0 && h[2] == 0) { //if vowel
roman += heonianVowelsSeparate[h[3]];
} else {
roman += heonianConsonants[h[1] + "" + h[2]] + heonianVowels[h[3] - 1];
} else { //if consonant
if (h[1] == 0 && h[2] == 6 && h[3] == 1) {
roman += "n";
} else {
roman += heonianConsonants[h[1] + "" + h[2]] + heonianVowels[h[3] - 1];
}
}
} else {
roman += text.charAt(i);
@@ -193,7 +197,8 @@ function doSearch() {
[words - 420 found / expressions - 69 found / wahtever else - ygettheidea] (click one to filter to just those)
*/
for (let i = 0; i < results.length; i++) {
let div = document.createElement("div");
let result = document.createElement("div");
result.classList.add("result");
// 1. add word in heo + romanized ruby as header
let header = document.createElement("ruby");
@@ -213,14 +218,31 @@ function doSearch() {
and. source/who made it/etc
repeat for all meanings of word,
*/
div.appendChild(header);
result.appendChild(header);
for (let o = 0; o < json[results[i]].length; o++) {
let div2 = document.createElement("div");
div2.classList.add("result-meaning");
div2.innerHTML = json[results[i]][o]["meaning"];
div.appendChild(div2); //y, yeah.
let meaning = document.createElement("div");
meaning.classList.add("result-meaning");
//ripping off jisho: Bold, word type (*required)
meaning.innerHTML += "<b class='capitalize'>"+json[results[i]][o]["type"]+"</b>";
//number, meaning (*required)
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)
if (json[results[i]][o]["translation"] != undefined) {
meaning.innerHTML += "<br><details><summary>Translation</summary><p>"+json[results[i]][o]["translation"]+"</p></details>";
}
//example
if (json[results[i]][o]["example"] != undefined) {
//todo
}
//notes
if (json[results[i]][o]["notes"] != undefined) {
meaning.innerHTML += "<br><p class='result-notes'>"+json[results[i]][o]["notes"]+"</p>";
}
//(source, etc)
//todo
result.appendChild(meaning); //y, yeah.
}
main.appendChild(div);
main.appendChild(result);
}
}
}