Compare commits

..

No commits in common. "f88202b792708238b9b17ead7350510801d8c2b2" and "980ab5b84c58f6c7108217a7b135f9f568f96289" have entirely different histories.

50
main.js
View File

@ -59,7 +59,7 @@ document.addEventListener("keydown", (e) => {
//if search box not focused, and if we're not on the home page, go back to home page
if (!header.querySelector("input").matches(":focus") && !header.classList.contains("fullscreen")) {
e.preventDefault();
goHome();
animateHeader(true);
} else if (header.querySelector("input").matches(":focus") && ime != null) {
toggleIME();
} else if (header.querySelector("input").matches(":focus")) {
@ -226,33 +226,15 @@ function search(word) {
for (let key in searchDictionary) {
for (let value in searchDictionary[key]) {
if (searchDictionary[key][value].includes(word)) {
if (value == 0) {
result.push(key);
break;
} else {
//if its a description (i.e: includes a space)
//do startsWith or something instead to prevent
//false positive search results
let t = false;
let d = searchDictionary[key][value].split(" ")
for (let w in d) {
if (d[w].startsWith(word)) {
t = true;
console.log(searchDictionary[key][value] + " " + d[w]);
}
}
if (t) {
result.push(key);
break;
}
}
break; //????
}
}
}
return result;
}
function doSearch(state = true) {
function doSearch() {
let val = header.querySelector("input").value;
let results = search(val);
if (results.length == 0) {
@ -341,16 +323,6 @@ function doSearch(state = true) {
}
main.prepend(header);
}
const url = new URL(window.location);
url.searchParams.set('s', val);
if (state == true) history.pushState(val, "", url);
}
function goHome(state = true) {
animateHeader(true);
const url = new URL(window.location);
url.searchParams.delete('s');
if (state == true) history.pushState(null, "", url);
}
window.onload = () => {
@ -359,24 +331,10 @@ window.onload = () => {
header.querySelector("#search button").onclick = () => {toggleIME();};
header.querySelector("span.heonian").onclick = () => {
if (!header.classList.contains("fullscreen")) {
goHome();
animateHeader(true);
}
};
loadDictionary();
window.addEventListener('popstate', (e) => {
if (e.state == null) {
if (!header.classList.contains("fullscreen")) {
goHome(false);
}
} else {
if (header.classList.contains("fullscreen")) {
animateHeader(false);
}
header.querySelector("input").value = e.state;
doSearch(false);
}
console.log("location: " + document.location + ", state: " + JSON.stringify(e.state));
});
}
const sortObject = obj => Object.keys(obj).sort().reduce((res, key) => (res[key] = obj[key], res), {})