organize scripts
All checks were successful
/ build (push) Successful in 32s

This commit is contained in:
Ruben 2025-04-15 11:53:22 -05:00
commit 214441ad40
No known key found for this signature in database
GPG key ID: 8EA836555FB6D9A5
12 changed files with 12 additions and 19 deletions

100
scripts/alt-popup.js Normal file
View file

@ -0,0 +1,100 @@
// custom popups that appear on hover that uses the alt/aria-label attribute on elements
// replacement for using title without the issue it causes with screen readers and such
document.addEventListener("DOMContentLoaded", function () {
let popup = document.getElementById("alt-popup");
// add popup to all elements with alt or aria-label
function initializePopups() {
// find all elements with alt or aria-label
const elementsWithAlt = document.querySelectorAll("[alt], [aria-label]");
// add mouse events to each element
elementsWithAlt.forEach((element) => {
element.addEventListener("mousemove", showPopup);
element.addEventListener("mouseout", hidePopup);
});
}
// show popup and position it near the cursor
function showPopup(event) {
// 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 (displayText) {
// use text in popup
popup.textContent = displayText;
// Make the popup visible but with position:fixed and visibility:hidden
// so we can measure its dimensions without it being visible yet
popup.style.opacity = "0";
popup.style.visibility = "visible";
popup.style.position = "fixed"; // Changed from absolute to fixed
// Get viewport dimensions
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;
// Get popup dimensions
const popupWidth = popup.offsetWidth;
const popupHeight = popup.offsetHeight;
// Use clientX/clientY which are relative to the viewport (for fixed positioning)
let leftPos = event.clientX + 20;
let topPos = event.clientY + 20;
// Check if popup would extend beyond right edge of viewport
if (leftPos + popupWidth > viewportWidth) {
// Flip to left side of cursor
leftPos = event.clientX - popupWidth - 10;
}
// Check if popup would extend beyond bottom edge of viewport
if (topPos + popupHeight > viewportHeight) {
// Flip to above cursor
topPos = event.clientY - popupHeight - 10;
}
// Additional check if flipping to left puts it offscreen
if (leftPos < 0) {
leftPos = 10;
}
// Additional check if flipping to top puts it offscreen
if (topPos < 0) {
topPos = 10;
}
// Set the final position and make it visible
popup.style.left = leftPos + "px";
popup.style.top = topPos + "px";
popup.style.opacity = "1";
popup.style.visibility = "visible";
}
}
function hidePopup() {
popup.style.opacity = "0";
popup.style.visibility = "hidden";
}
initializePopups();
if (window.MutationObserver) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length) {
initializePopups();
}
});
});
// Only set up the observer once
if (document.body) {
observer.observe(document.body, { childList: true, subtree: true });
}
}
});

14
scripts/button.js Normal file
View file

@ -0,0 +1,14 @@
// snippet that copies the html for my button(s)
function copyButtonSneexy() {
navigator.clipboard.writeText(
'<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>'
);
alert("button html copied!");
}

97
scripts/settings.js Normal file
View file

@ -0,0 +1,97 @@
document.addEventListener('DOMContentLoaded', function() {
// all available settings
const fontInputs = document.querySelectorAll('input[name="font-setting"]');
const themeInputs = document.querySelectorAll('input[name="theme-setting"]');
const uncapitalizationCheckbox = document.getElementById('uncapitalization');
const disableBgCheckbox = document.getElementById('disable-bg');
const disableAnimationsCheckbox = document.getElementById('disable-animations');
const disableAlttextCheckbox = document.getElementById('disable-alttext');
// load saved settings
loadSettings();
applyTheme();
// event listeners on all inputs
fontInputs.forEach(input => {
input.addEventListener('change', saveSettings);
});
themeInputs.forEach(input => {
input.addEventListener('change', function() {
saveSettings();
applyTheme();
});
});
uncapitalizationCheckbox.addEventListener('change', saveSettings);
disableBgCheckbox.addEventListener('change', saveSettings);
disableAnimationsCheckbox.addEventListener('change', saveSettings);
disableAlttextCheckbox.addEventListener('change', saveSettings);
// settings saving function
function saveSettings() {
// save font setting
const selectedFont = document.querySelector('input[name="font-setting"]:checked').id;
localStorage.setItem('accessibility-font', selectedFont);
// save theme setting
const selectedTheme = document.querySelector('input[name="theme-setting"]:checked').value;
localStorage.setItem('accessibility-theme', selectedTheme);
// save toggle states
localStorage.setItem('accessibility-uncapitalization', uncapitalizationCheckbox.checked);
localStorage.setItem('accessibility-disable-bg', disableBgCheckbox.checked);
localStorage.setItem('accessibility-disable-animations', disableAnimationsCheckbox.checked);
localStorage.setItem('accessibility-disable-alttext', disableAlttextCheckbox.checked);
}
// settings loading function
function loadSettings() {
// load the font setting
const savedFont = localStorage.getItem('accessibility-font');
if (savedFont) {
const fontInput = document.getElementById(savedFont);
if (fontInput) fontInput.checked = true;
}
// load the theme setting
const savedTheme = localStorage.getItem('accessibility-theme');
if (savedTheme) {
const themeInput = document.querySelector(`input[name="theme-setting"][value="${savedTheme}"]`);
if (themeInput) themeInput.checked = true;
}
// load toggle states
if (localStorage.getItem('accessibility-uncapitalization') === 'true') {
uncapitalizationCheckbox.checked = true;
}
if (localStorage.getItem('accessibility-disable-bg') === 'true') {
disableBgCheckbox.checked = true;
}
if (localStorage.getItem('accessibility-disable-animations') === 'true') {
disableAnimationsCheckbox.checked = true;
}
if (localStorage.getItem('accessibility-disable-alttext') === 'true') {
disableAlttextCheckbox.checked = true;
}
}
// apply the theme based on user preference
function applyTheme() {
const selectedTheme = document.querySelector('input[name="theme-setting"]:checked').value;
// remove any existing theme
document.documentElement.removeAttribute('data-theme');
// apply the selected theme
if (selectedTheme === 'light') {
document.documentElement.setAttribute('data-theme', 'light');
} else if (selectedTheme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
// if auto, don't set a data-theme attribute, let the media query handle it
}
});