pushing despite. not very done cuz i wanna upload

This commit is contained in:
remi 2022-06-10 04:53:11 +02:00
parent fad6471e48
commit 85f9625fea

30
main.js
View File

@ -78,8 +78,9 @@ document.addEventListener("keydown", (e) => {
}
});
function stripWord(word) {
return word.replace(/[^a-zA-Z-]/gu, "").toLowerCase();
function stripWord(word, space = false) {
return space == false ? word.replace(/[^a-zA-Z-]/gu, "").toLowerCase() :
word.replace(/[^a-zA-Z-\s]/gu, "").toLowerCase();
}
heonianVowels = {
@ -153,6 +154,13 @@ function heonianToRoman(text) {
return roman;
}
function processVerb(word) {
//basically, turn welikanyapash into liku
//and uhhhhhhhhhhh maybe. return as an object with. all the things . used, for info
return word;
//but ... not yet uwu
}
function loadDictionary() {
fetch("./wordlist.json").then((e) => {
if (e.status === 200) {
@ -173,11 +181,13 @@ function loadDictionary() {
//add: romanized word
searchDictionary[keys[i]].push(stripWord(heonianToRoman(keys[i])));
//what if i add it here.
searchDictionary[keys[i]].push(stripWord(heonianToRoman(keys[i]).replace("dsh","z")));
//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"]));
if (values[i][o].hasOwnProperty("meaning")) searchDictionary[keys[i]].push(stripWord(values[i][o]["meaning"]));
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) {
console.log(keys[i] + " failed to load :/");
@ -195,8 +205,14 @@ function loadDictionary() {
}
function search(word) {
word = stripWord(word);
word = heonianToRoman(word);
let words = word.split(" ");
for (let i = 0; i < words.length; i++) {
words[i] = stripWord(words[i]);
words[i] = heonianToRoman(words[i]);
words[i] = processVerb(words[i]);
}
word = words.join("");
console.log("debug - search: " + word);
let result = [];
for (let key in searchDictionary) {
for (let value in searchDictionary[key]) {
@ -251,7 +267,7 @@ function doSearch() {
//ripping off jisho: Bold, word type (*required)
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;
types[json[results[i]][o]["type"]] = 1;
} else {
types[json[results[i]][o]["type"]]++;
}