2025-02-27 14:23:39 -06:00
|
|
|
// custom popups that appear on hover that uses the alt attribute on elements
|
|
|
|
|
// generated with ai i'm SORRY but i'm stupid and this works so its probably fiiiine
|
|
|
|
|
// i'll probably redo this when i can be assed to learn js myself
|
|
|
|
|
// Wait for DOM to be fully loaded before executing code (do we even need this. my site is just basic bitch html)
|
2025-02-27 14:43:41 -06:00
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
|
let popup = document.getElementById("alt-popup");
|
|
|
|
|
|
2025-04-07 11:26:39 -05:00
|
|
|
// add popup to all elements with alt or aria-label
|
2025-02-27 14:23:39 -06:00
|
|
|
function initializePopups() {
|
2025-04-07 11:26:39 -05:00
|
|
|
// find all elements with alt or aria-label
|
|
|
|
|
const elementsWithAlt = document.querySelectorAll("[alt], [aria-label]");
|
2025-02-27 14:43:41 -06:00
|
|
|
|
|
|
|
|
// add mouse events to each element
|
|
|
|
|
elementsWithAlt.forEach((element) => {
|
|
|
|
|
element.addEventListener("mousemove", showPopup);
|
|
|
|
|
element.addEventListener("mouseout", hidePopup);
|
2025-02-27 14:23:39 -06:00
|
|
|
});
|
|
|
|
|
}
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-02-27 14:23:39 -06:00
|
|
|
// show popup and position it near the cursor
|
|
|
|
|
function showPopup(event) {
|
2025-04-07 11:26:39 -05:00
|
|
|
// get alt text or aria-label
|
2025-02-27 14:43:41 -06:00
|
|
|
const altText = event.target.getAttribute("alt");
|
2025-04-07 11:26:39 -05:00
|
|
|
const ariaLabel = event.target.getAttribute("aria-label");
|
|
|
|
|
|
|
|
|
|
// Use alt text if available, otherwise use aria-label
|
|
|
|
|
const displayText = altText || ariaLabel;
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-04-07 11:26:39 -05:00
|
|
|
if (displayText) {
|
|
|
|
|
// use text in popup
|
|
|
|
|
popup.textContent = displayText;
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-02-27 14:23:39 -06:00
|
|
|
// correct popup positioning away from cursor and make it visible
|
2025-02-27 14:43:41 -06:00
|
|
|
popup.style.left = event.clientX + 20 + "px";
|
|
|
|
|
popup.style.top = event.clientY + 20 + "px";
|
|
|
|
|
popup.style.opacity = "1";
|
2025-02-27 14:23:39 -06:00
|
|
|
}
|
|
|
|
|
}
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-02-27 14:23:39 -06:00
|
|
|
function hidePopup() {
|
2025-02-27 14:43:41 -06:00
|
|
|
popup.style.opacity = "0";
|
2025-02-27 14:23:39 -06:00
|
|
|
}
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-02-27 14:23:39 -06:00
|
|
|
initializePopups();
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-02-27 14:23:39 -06:00
|
|
|
if (window.MutationObserver) {
|
2025-02-27 14:43:41 -06:00
|
|
|
const observer = new MutationObserver((mutations) => {
|
|
|
|
|
mutations.forEach((mutation) => {
|
2025-02-27 14:23:39 -06:00
|
|
|
if (mutation.addedNodes.length) {
|
|
|
|
|
initializePopups();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-02-27 14:43:41 -06:00
|
|
|
|
2025-04-07 11:26:39 -05:00
|
|
|
// Only set up the observer once
|
2025-02-27 14:23:39 -06:00
|
|
|
if (document.body) {
|
|
|
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-28 01:25:39 -05:00
|
|
|
// snippet that copies the html for my button(s)
|
2025-02-27 15:31:29 -06:00
|
|
|
function copyButtonSneexy() {
|
2025-02-27 14:43:41 -06:00
|
|
|
navigator.clipboard.writeText(
|
2025-02-27 15:31:29 -06:00
|
|
|
'<a href="https://synth.download"><img src="https://synth.download/assets/buttons/sneexy.svg" alt="Sneexy"></a>'
|
|
|
|
|
);
|
|
|
|
|
alert("button html copied!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function copyButtonSynthDownload() {
|
|
|
|
|
navigator.clipboard.writeText(
|
|
|
|
|
'<a href="https://synth.download"><img src="https://synth.download/assets/buttons/synth.download.svg" alt="Synth.Download!"></a>'
|
2025-02-27 14:43:41 -06:00
|
|
|
);
|
2024-09-25 20:21:07 -05:00
|
|
|
alert("button html copied!");
|
2025-02-27 14:43:41 -06:00
|
|
|
}
|