From ad32ca9c46faa4c5d496a2b60f700abc8934153b Mon Sep 17 00:00:00 2001 From: remi Date: Thu, 5 May 2022 18:20:24 +0200 Subject: [PATCH] popup halfway (no error handling, fails to figure out where cursor is) --- html/pop_up.html | 8 +++--- main.js | 67 ++++++++++++++++++++++++++++++++++++++---------- test.html | 8 +++--- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/html/pop_up.html b/html/pop_up.html index 42a7bb2..b586338 100644 --- a/html/pop_up.html +++ b/html/pop_up.html @@ -3,7 +3,8 @@

um

heonian:
- type: + type:
+ quirks:
@@ -11,8 +12,9 @@

um

- heonian:
- type: + heonian:
+ type:
+ quirks:

\ No newline at end of file diff --git a/main.js b/main.js index 2f64005..a47b228 100644 --- a/main.js +++ b/main.js @@ -20,40 +20,78 @@ function init() { document.querySelector("#font-button").addEventListener("click", () => {fontButton();}); } -function showPopup(word) { +function cleanWord(word) { + //only a-z, lowercase, stripped + return word.replace(/[^a-zA-Z]/g, "").toLowerCase(); +} + +function showPopup(ogword, word, quirks) { clearHover(); + //same shit as in smolpopup let p = document.querySelector("#popup"); - let c = document.querySelector("#popup-container") - p.querySelector("h1").innerText = word; - p.querySelector("#popup-heo").innerText = words[word]["heonian"]; + let c = document.querySelector("#popup-container"); + word = cleanWord(word); + if (currentFont == "r") { + p.querySelector("h1").innerText = words[word]["romanizationProper"]; + p.querySelector("#popup-heo").innerText = words[word]["heonian"]; + p.querySelector("h1").style.fontFamily = "var(--font-normal)"; + p.querySelector("#popup-heo").style.fontFamily = "var(--font-heonian)"; + } else { + p.querySelector("h1").innerText = words[word]["heonian"]; + p.querySelector("#popup-heo").innerText = words[word]["romanizationProper"]; + p.querySelector("h1").style.fontFamily = "var(--font-heonian)"; + p.querySelector("#popup-heo").style.fontFamily = "var(--font-normal)"; + } p.querySelector("#popup-type").innerText = words[word]["type"]; p.querySelector("#popup-meaning").innerText = words[word]["meaning"]; + let wq = ""; + //todo: make all of this less sphagetti LOL + if (quirks.trim() != "") { + wq = quirks.split(" ").join(", "); + } + p.querySelector("#popup-quirks").innerText = wq; c.style.opacity = 1; c.style.pointerEvents = "all"; } -function showSmolPopup(word, event) { +function showSmolPopup(ogword, word, quirks) { let p = document.querySelector("#smol-popup"); - p.querySelector("h1").innerText = word; - p.querySelector("#smol-heo").innerText = words[word]["heonian"]; + word = cleanWord(word); + if (currentFont == "r") { + p.querySelector("h1").innerText = words[word]["romanizationProper"]; + p.querySelector("#smol-heo").innerText = words[word]["heonian"]; + p.querySelector("h1").style.fontFamily = "var(--font-normal)"; + p.querySelector("#smol-e").innerText = "heonian: "; + } else { + p.querySelector("h1").innerText = words[word]["heonian"]; + p.querySelector("#smol-heo").innerText = words[word]["romanizationProper"]; + p.querySelector("h1").style.fontFamily = "var(--font-heonian)"; + p.querySelector("#smol-e").innerText = "romanization: "; + } p.querySelector("#smol-type").innerText = words[word]["type"]; p.querySelector("#smol-meaning").innerText = words[word]["meaning"]; + let wq = ""; + console.log(quirks); + if (quirks.trim() != "") { + wq = quirks.split(" ").join(", "); + } + p.querySelector("#smol-quirks").innerText = wq; p.style.opacity = 1; p.style.pointerEvents = "all"; - // set position to cursor position + // set position to cursor position (but we dont have the event) let rect = document.body.getBoundingClientRect(); - let x = event.clientX - rect.left; - let y = event.clientY - rect.top; + let x = rect.left + window.event.clientX; + let y = rect.top + window.event.clientY; p.style.left = x - 100 + "px"; p.style.top = y + 25 + "px"; } -function checkHover(word, event) { +function checkHover(ogword, word, quirks = "") { if (timeout != "") { clearTimeout(timeout); } timeout = setTimeout(() => { - showSmolPopup(word, event); + showSmolPopup(ogword, word, quirks); }, 450); } @@ -71,10 +109,11 @@ function createWordList() { //sometimes i really dislike javascript.. t.querySelectorAll("tr").forEach(element => { if (element.querySelector("td")) { let e = element.querySelectorAll("td"); - let n = e[1].innerText; + let n = e[1].innerText.replace(".", ""); words[n] = {}; words[n]["heonian"] = e[0].innerText; - words[n]["romanization"] = e[1].innerText; + words[n]["romanization"] = e[1].innerText.replace(". ", ""); + words[n]["romanizationProper"] = e[1].innerText; words[n]["type"] = e[2].innerText; words[n]["meaning"] = e[3].innerText; } diff --git a/test.html b/test.html index 34f0966..8fc819e 100644 --- a/test.html +++ b/test.html @@ -4331,7 +4331,8 @@ fayu

um

heonian:
- type: + type:
+ quirks:
@@ -4339,8 +4340,9 @@ fayu

um

- heonian:
- type: + heonian:
+ type:
+ quirks: