@@ -1471,6 +1471,106 @@ <h3>${project.title}</h3>
14711471 } , 100 ) ;
14721472 </ script >
14731473
1474+ <!-- FIX: Surprise Me Button - Enhanced Random Project Loading -->
1475+ < script >
1476+ ( function ( ) {
1477+ console . log ( '🎲 Enhancing Surprise Me button...' ) ;
1478+
1479+ // Store reference to original function
1480+ const originalOpenProject = window . openProjectSafe ;
1481+
1482+ // Enhanced random project selector
1483+ function getRandomProject ( ) {
1484+ const projectCards = document . querySelectorAll ( '.project-card' ) ;
1485+ const visibleProjects = Array . from ( projectCards ) . filter ( card =>
1486+ card . style . display !== 'none'
1487+ ) ;
1488+
1489+ // If no visible projects, use all projects
1490+ const pool = visibleProjects . length > 0 ? visibleProjects : projectCards ;
1491+
1492+ if ( pool . length === 0 ) {
1493+ console . warn ( '⚠️ No projects available' ) ;
1494+ return null ;
1495+ }
1496+
1497+ const randomIndex = Math . floor ( Math . random ( ) * pool . length ) ;
1498+ const selectedCard = pool [ randomIndex ] ;
1499+ const projectName = selectedCard . getAttribute ( 'data-project' ) ;
1500+
1501+ console . log ( `🎲 Random project selected: ${ projectName } ` ) ;
1502+ return { name : projectName , element : selectedCard } ;
1503+ }
1504+
1505+ // Override Surprise Me functionality
1506+ function handleSurpriseMe ( buttonElement ) {
1507+ const project = getRandomProject ( ) ;
1508+
1509+ if ( ! project ) {
1510+ // Show user-friendly message if no projects
1511+ const toast = document . createElement ( 'div' ) ;
1512+ toast . className = 'share-toast' ;
1513+ toast . textContent = 'No projects available. Try again!' ;
1514+ document . body . appendChild ( toast ) ;
1515+
1516+ setTimeout ( ( ) => {
1517+ toast . classList . add ( 'share-toast--visible' ) ;
1518+ setTimeout ( ( ) => {
1519+ toast . classList . remove ( 'share-toast--visible' ) ;
1520+ setTimeout ( ( ) => toast . remove ( ) , 300 ) ;
1521+ } , 2000 ) ;
1522+ } , 100 ) ;
1523+ return ;
1524+ }
1525+
1526+ // Use the existing openProjectSafe function
1527+ if ( typeof originalOpenProject === 'function' ) {
1528+ originalOpenProject ( project . name , buttonElement || project . element ) ;
1529+ } else {
1530+ console . error ( '❌ openProjectSafe not found' ) ;
1531+ }
1532+ }
1533+
1534+ // Find all Surprise Me buttons
1535+ const surpriseButtons = document . querySelectorAll ( '#randomProjectBtn, #randomProjectBtnSidebar' ) ;
1536+
1537+ surpriseButtons . forEach ( button => {
1538+ // Remove existing listeners by cloning
1539+ const newButton = button . cloneNode ( true ) ;
1540+ button . parentNode . replaceChild ( newButton , button ) ;
1541+
1542+ // Add enhanced click handler
1543+ newButton . addEventListener ( 'click' , function ( e ) {
1544+ e . preventDefault ( ) ;
1545+ e . stopPropagation ( ) ;
1546+
1547+ // Add visual feedback
1548+ this . style . transform = 'scale(0.95)' ;
1549+ setTimeout ( ( ) => {
1550+ this . style . transform = '' ;
1551+ } , 200 ) ;
1552+
1553+ handleSurpriseMe ( this ) ;
1554+ } ) ;
1555+
1556+ console . log ( `✅ Surprise Me button enhanced: ${ newButton . id || 'unnamed' } ` ) ;
1557+ } ) ;
1558+
1559+ // Also handle stats card click for Surprise
1560+ const statsCards = document . querySelectorAll ( '.stats-card' ) ;
1561+ statsCards . forEach ( card => {
1562+ if ( card . getAttribute ( 'data-filter' ) === 'surprise' ) {
1563+ card . addEventListener ( 'click' , function ( e ) {
1564+ e . preventDefault ( ) ;
1565+ handleSurpriseMe ( this ) ;
1566+ } ) ;
1567+ }
1568+ } ) ;
1569+
1570+ console . log ( '✅ Surprise Me feature enhanced successfully!' ) ;
1571+ } ) ( ) ;
1572+ </ script >
1573+
14741574 <!-- Info Modal Popup -->
14751575 < div id ="infoModalOverlay " class ="info-modal-overlay ">
14761576 < div class ="info-modal-content ">
0 commit comments