'); $.ajax({ type: "POST", url: "open_bentbucks", data: {}, success: function (data) { bentbucksWindow.location.href = data; }, error: function() { bentbucksWindow.close(); alert('Failed to open BentBucks. Please try again.'); } }); }; // Open Random Photo Modal function openRandomPhotoModal() { if (!accessToken) { showLoginRequiredModal(); return; } // Reset modal content $('#randomPhotoModalBody').html(`
Try Your Luck!

Get One Random Photo

Feeling lucky? Get one random surprise photo from our Featured Collection for just $1! You never know what you'll discover! 🍀

Your Balance: ${currentBentBucks.toFixed(2)} BentBucks
`); var modal = new bootstrap.Modal(document.getElementById('randomPhotoModal')); modal.show(); } // Purchase Random Photo async function purchaseRandomPhoto() { if (currentBentBucks < 1) { swal({ title: 'Insufficient Balance', text: 'You need at least 1 BentBuck to purchase a random photo.', icon: 'warning', buttons: { cancel: "Cancel", confirm: "Buy BentBucks" } }).then((willBuy) => { if (willBuy) { window.purchaseTokens(); } }); return; } // Show loading state $('#randomPhotoModalBody').html(`

Loading your random photo...

`); try { const response = await fetch('/get_last_boxes_random_image.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ page: 'featured', accessToken: accessToken }) }); const data = await response.json(); if (data.success && data.image_url) { // Update balance currentBentBucks = Math.max(0, currentBentBucks - 1); $('#modalBentBucksBalance').text(currentBentBucks.toFixed(2)); // Show image const boxUrl = data.box_id ? `https://bentbox.co/box?${data.box_id}` : '#'; const boxLink = data.box_id ? `

This image is from: Box #${data.box_id}

` : ''; $('#randomPhotoModalBody').html(`
You Got Lucky! 🍀

Your Lucky Photo

Random Photo
${boxLink}
Your Balance: ${currentBentBucks.toFixed(2)} BentBucks
`); } else { throw new Error(data.error || 'Failed to load random photo'); } } catch (error) { console.error('Error purchasing random photo:', error); $('#randomPhotoModalBody').html(`

Error

${error.message}

`); } } // Fullscreen Image Viewer function openImageFullscreen(imageUrl) { // Create fullscreen overlay const overlay = document.createElement('div'); overlay.id = 'fullscreenImageOverlay'; overlay.style.cssText = ` position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.95); z-index: 10000; display: flex; align-items: center; justify-content: center; cursor: zoom-out; `; // Create close button const closeBtn = document.createElement('button'); closeBtn.innerHTML = ''; closeBtn.style.cssText = ` position: absolute; top: 20px; right: 20px; background: rgba(255, 255, 255, 0.2); color: white; border: none; border-radius: 50%; width: 50px; height: 50px; font-size: 2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10001; transition: background 0.3s ease; `; closeBtn.onmouseover = () => closeBtn.style.background = 'rgba(255, 255, 255, 0.3)'; closeBtn.onmouseout = () => closeBtn.style.background = 'rgba(255, 255, 255, 0.2)'; // Create image const img = document.createElement('img'); img.src = imageUrl; img.style.cssText = ` max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: 8px; `; // Close on click const closeOverlay = () => { document.body.removeChild(overlay); }; closeBtn.onclick = closeOverlay; overlay.onclick = (e) => { if (e.target === overlay) closeOverlay(); }; // Add ESC key support const handleEsc = (e) => { if (e.key === 'Escape') { closeOverlay(); document.removeEventListener('keydown', handleEsc); } }; document.addEventListener('keydown', handleEsc); // Assemble and show overlay.appendChild(closeBtn); overlay.appendChild(img); document.body.appendChild(overlay); }