This commit is contained in:
parent
f81e4bb5f1
commit
6ef069cadc
8 changed files with 74 additions and 74 deletions
22
script.js
22
script.js
|
|
@ -5,10 +5,10 @@
|
|||
document.addEventListener("DOMContentLoaded", function () {
|
||||
let popup = document.getElementById("alt-popup");
|
||||
|
||||
// add popup to all elements with alt
|
||||
// add popup to all elements with alt or aria-label
|
||||
function initializePopups() {
|
||||
// find all elements with alt
|
||||
const elementsWithAlt = document.querySelectorAll("[alt]");
|
||||
// find all elements with alt or aria-label
|
||||
const elementsWithAlt = document.querySelectorAll("[alt], [aria-label]");
|
||||
|
||||
// add mouse events to each element
|
||||
elementsWithAlt.forEach((element) => {
|
||||
|
|
@ -19,12 +19,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
|
||||
// show popup and position it near the cursor
|
||||
function showPopup(event) {
|
||||
// get alt text
|
||||
// get alt text or aria-label
|
||||
const altText = event.target.getAttribute("alt");
|
||||
const ariaLabel = event.target.getAttribute("aria-label");
|
||||
|
||||
// Use alt text if available, otherwise use aria-label
|
||||
const displayText = altText || ariaLabel;
|
||||
|
||||
if (altText) {
|
||||
// use alt text in popup
|
||||
popup.textContent = altText;
|
||||
if (displayText) {
|
||||
// use text in popup
|
||||
popup.textContent = displayText;
|
||||
|
||||
// correct popup positioning away from cursor and make it visible
|
||||
popup.style.left = event.clientX + 20 + "px";
|
||||
|
|
@ -48,15 +52,13 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
});
|
||||
});
|
||||
|
||||
// Only set up the observer once
|
||||
if (document.body) {
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Start observing the document with the configured parameters
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
// snippet that copies the html for my button(s)
|
||||
function copyButtonSneexy() {
|
||||
navigator.clipboard.writeText(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue