document.addEventListener('DOMContentLoaded', () => { const emailAddress = ['beammeup', 'dmxsquad.com'].join('@'); document.querySelectorAll('[data-email-link]').forEach((link) => { const subject = link.dataset.emailSubject; link.href = `mailto:${emailAddress}${subject ? `?subject=${encodeURIComponent(subject)}` : ''}`; if (link.dataset.emailLabel === 'address') { link.textContent = emailAddress; } }); // Random text selection color functionality // List of 10 saturated colors const saturatedColors = [ '#FF0000', // Red '#00FF00', // Green '#0000FF', // Blue '#FF00FF', // Magenta '#00FFFF', // Cyan '#FFA500', // Orange '#800080', // Purple '#FF4500', // OrangeRed '#00CED1', // DarkTurquoise '#DC143C' // Crimson ]; let currentSelectionColor = ''; // Function to get a random color from the list function getRandomColor() { const randomIndex = Math.floor(Math.random() * saturatedColors.length); return saturatedColors[randomIndex]; } // Function to apply the selection color function applySelectionColor() { currentSelectionColor = getRandomColor(); const style = document.createElement('style'); style.id = 'selection-color-style'; style.innerHTML = ` ::selection { background: ${currentSelectionColor}; color: ${getContrastColor(currentSelectionColor)}; } ::-moz-selection { background: ${currentSelectionColor}; color: ${getContrastColor(currentSelectionColor)}; } `; // Remove existing style if it exists const existingStyle = document.getElementById('selection-color-style'); if (existingStyle) { existingStyle.remove(); } document.head.appendChild(style); } // Helper function to determine if color is light or dark for contrast function getContrastColor(hexColor) { // Convert hex to RGB const r = parseInt(hexColor.substr(1, 2), 16); const g = parseInt(hexColor.substr(3, 2), 16); const b = parseInt(hexColor.substr(5, 2), 16); // Calculate luminance const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255; // Return black for bright colors, white for dark colors return luminance > 0.5 ? '#000000' : '#FFFFFF'; } function updateArticlePopColor(article) { const articleColor = getRandomColor(); article.style.setProperty('--article-pop-color', articleColor); article.style.setProperty('--article-pop-text', getContrastColor(articleColor)); } document.querySelectorAll('article').forEach((article) => { updateArticlePopColor(article); article.addEventListener('mousedown', () => updateArticlePopColor(article)); article.addEventListener('mouseleave', () => updateArticlePopColor(article)); }); document.addEventListener('mousedown', function () { const selection = window.getSelection(); if (selection.toString().length > 0) { applySelectionColor(); } }); // Initialize with a random color applySelectionColor(); });