Create tooltip.js

It's a mod that adds a tooltip that shows the description of a hovered element at the bottom of the screen.
This commit is contained in:
MollTheCoder 2023-07-03 12:47:08 -04:00 committed by GitHub
parent 4b069a9422
commit 8ab0e2d1ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

21
mods/tooltip.js Normal file
View File

@ -0,0 +1,21 @@
const defaultTooltip = "---";
let tooltipEle;
window.addEventListener("load", ()=>{
tooltipEle = document.createElement("p");
tooltipEle.innerHTML = defaultTooltip;
document.getElementById("extraInfo").children[1].appendChild(tooltipEle);
let buttons = document.getElementsByClassName("elementButton");
[...buttons].forEach(button=>{
let ele = button.getAttribute("element");
button.addEventListener("mouseenter", e=>{
if(elements.hasOwnProperty(ele)) {
if(elements[ele].hasOwnProperty("desc")) {
tooltipEle.innerHTML = elements[ele].desc;
}
}
});
button.addEventListener("mouseleave", e=>{
tooltipEle.innerHTML = defaultTooltip;
});
});
});