the other half or smth

This commit is contained in:
remi 2022-05-05 18:31:14 +02:00
parent ad32ca9c46
commit b323a78e38
3 changed files with 386 additions and 411 deletions

View File

@ -37,7 +37,7 @@ function process_content(content)
<span
class="clickable"
onclick="showPopup('REPLACE_WORD','REPLACE_SEARCH','REPLACE_DATA')"
onmouseover="checkHover('REPLACE_WORD','REPLACE_SEARCH','REPLACE_DATA')"
onmouseover="checkHover('REPLACE_WORD','REPLACE_SEARCH',this,'REPLACE_DATA')"
onmouseout="clearHover()">
REPLACE_PRINT
</span>

67
main.js
View File

@ -11,7 +11,6 @@ let timeout = "";
function init() {
createWordList();
// injectWords();
document.querySelector("#popup-container").addEventListener("click", () => {
document.querySelector("#popup-container").style.opacity = 0;
document.querySelector("#popup-container").style.pointerEvents = "none";
@ -25,9 +24,11 @@ function cleanWord(word) {
return word.replace(/[^a-zA-Z]/g, "").toLowerCase();
}
function showPopup(ogword, word, quirks) {
function showPopup(ogword, word, quirks = "") {
try {
clearHover();
//same shit as in smolpopup
//todo: make all of this less sphagetti LOL
let p = document.querySelector("#popup");
let c = document.querySelector("#popup-container");
word = cleanWord(word);
@ -45,16 +46,21 @@ function showPopup(ogword, word, quirks) {
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";
} catch (e) {
console.log(e);
//eya
//failure is expected,
//but mightaswell print less RED ERRORs to the console
}
}
function showSmolPopup(ogword, word, quirks) {
function showSmolPopup(ogword, word, self, quirks) {
let p = document.querySelector("#smol-popup");
word = cleanWord(word);
if (currentFont == "r") {
@ -79,19 +85,24 @@ function showSmolPopup(ogword, word, quirks) {
p.style.opacity = 1;
p.style.pointerEvents = "all";
// set position to cursor position (but we dont have the event)
let rect = document.body.getBoundingClientRect();
let x = rect.left + window.event.clientX;
let y = rect.top + window.event.clientY;
let rect = self.getBoundingClientRect();
let x = rect.left+rect.width/2;
let y = rect.top;
p.style.left = x - 100 + "px";
p.style.top = y + 25 + "px";
}
function checkHover(ogword, word, quirks = "") {
function checkHover(ogword, word, self, quirks = "") {
if (timeout != "") {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
showSmolPopup(ogword, word, quirks);
try {
showSmolPopup(ogword, word, self, quirks);
} catch (e) {
console.log(e);
//i fucking love error handling
}
}, 450);
}
@ -109,7 +120,7 @@ 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.replace(".", "");
let n = cleanWord(e[1].innerText);
words[n] = {};
words[n]["heonian"] = e[0].innerText;
words[n]["romanization"] = e[1].innerText.replace(". ", "");
@ -120,42 +131,6 @@ function createWordList() { //sometimes i really dislike javascript..
});
}
function injectWords() {
Object.values(words).forEach(word => {
document.querySelectorAll(".convo p").forEach(convo => {
if (convo.innerText.includes(word["romanization"])) {
let m = convo.innerHTML.split(word["romanization"]);
let newhtml = document.createElement("p");
let c = m.length*2-1;
for (let x = 0; x < c; x++) {
if (x % 2 == 0) {
newhtml.innerHTML += m[x/2];
} else {
var e = document.createElement("span");
e.innerText = word["romanization"];
e.classList.add("clickable");
newhtml.appendChild(e)
}
}
convo.innerHTML = newhtml.innerHTML;
convo.querySelectorAll(".clickable").forEach(element => {
element.addEventListener('click', function(e) {
showPopup(element.innerText);
}, false);
element.addEventListener('mouseover', function(e) {
checkHover(element.innerText, e);
}
, false);
element.addEventListener('mouseout', function(e) {
clearHover();
}
, false);
});
}
});
});
}
function fontButton() {
if (currentFont == "r") {
document.querySelector("#style-heonian").disabled = false;

728
test.html

File diff suppressed because it is too large Load Diff