// Amazon Deals Page Functionality document.addEventListener('DOMContentLoaded', function() { // Simulate loading deals from Amazon API loadDeals(); // Countdown timer for deal refresh startCountdown(); // Initialize tooltips feather.replace(); }); function loadDeals() { // In a real implementation, this would fetch from an API endpoint // that pulls Amazon deals data with our affiliate tag const dealsContainer = document.getElementById('deals-container'); dealsContainer.innerHTML = ''; // Clear existing // Sample data - in real app this would come from API const sampleDeals = [ { id: 'B0BYSWG9RH', title: 'Wireless Noise Cancelling Headphones', image: 'http://static.photos/technology/640x360/1', price: 89.99, originalPrice: 149.99, discount: 40, rating: 4.5, reviewCount: 1280, isPrime: true, shipping: 'FREE delivery', dealEnds: '2023-12-31T23:59:59' }, { id: 'B08L5V9RV7', title: 'Smart Watch with Fitness Tracker', image: 'http://static.photos/technology/640x360/2', price: 129.99, originalPrice: 199.99, discount: 35, rating: 4.2, reviewCount: 876, isPrime: true, shipping: 'FREE delivery', dealEnds: '2023-12-31T23:59:59' }, { id: 'B07VGRJDFY', title: '4K Smart TV 55"', image: 'http://static.photos/technology/640x360/3', price: 399.99, originalPrice: 599.99, discount: 33, rating: 4.7, reviewCount: 2543, isPrime: true, shipping: 'FREE delivery', dealEnds: '2023-12-31T23:59:59' }, { id: 'B08N5KWB9H', title: 'Robot Vacuum Cleaner', image: 'http://static.photos/technology/640x360/4', price: 199.99, originalPrice: 349.99, discount: 43, rating: 4.3, reviewCount: 1120, isPrime: true, shipping: 'FREE delivery', dealEnds: '2023-12-31T23:59:59' }, { id: 'B08L5V9RV7', title: 'Air Fryer 5.8QT', image: 'http://static.photos/home/640x360/5', price: 79.99, originalPrice: 129.99, discount: 38, rating: 4.6, reviewCount: 4321, isPrime: true, shipping: 'FREE delivery', dealEnds: '2023-12-31T23:59:59' }, { id: 'B08N5KWB9H', title: 'Bluetooth Speaker Waterproof', image: 'http://static.photos/technology/640x360/6', price: 39.99, originalPrice: 69.99, discount: 43, rating: 4.4, reviewCount: 876, isPrime: true, shipping: 'FREE delivery', dealEnds: '2023-12-31T23:59:59' } ]; // Render deals dealsContainer.innerHTML = sampleDeals.map(deal => `
${deal.title}
${deal.discount}% off
${deal.isPrime ? '
Prime
' : ''}

${deal.title}

${Array(Math.floor(deal.rating)).fill().map(() => '' ).join('')} ${deal.rating % 1 >= 0.5 ? '' : ''}
(${deal.reviewCount})
$${deal.price.toFixed(2)} $${deal.originalPrice.toFixed(2)}
${deal.shipping}
`).join(''); // Initialize tracking for new elements initTracking(); } function startCountdown() { let seconds = 60 * 60; // 1 hour countdown const countdownElement = document.getElementById('countdown'); const timer = setInterval(() => { seconds--; const minutes = Math.floor(seconds / 60); const remainingSeconds = seconds % 60; countdownElement.textContent = `${minutes}:${remainingSeconds < 10 ? '0' + remainingSeconds : remainingSeconds}`; if (seconds <= 0) { clearInterval(timer); loadDeals(); // Refresh deals startCountdown(); // Restart timer } }, 1000); } // In a real implementation, this would be an API call to get fresh deals function refreshDeals() { console.log('Refreshing deals from Amazon API...'); // This would make a fetch request to your backend API // which would then make requests to Amazon's API with your affiliate tag // and return the data formatted for your frontend // Example of what the API call might look like: /* fetch('/api/amazon-deals?StoreID=tinder0001-20') .then(response => response.json()) .then(data => { renderDeals(data); }) .catch(error => { console.error('Error fetching deals:', error); }); */ } // Initialize tracking for all links with StoreID function initTracking() { document.querySelectorAll('a[href*="StoreID=tinder0001-20"]').forEach(link => { link.addEventListener('click', trackClick); }); } function trackClick(e) { // In a real implementation, this would send to your analytics const productId = this.closest('[data-product-id]')?.getAttribute('data-product-id'); const url = this.href; console.log(`Tracking click: ${url} for product ${productId}`); // Example tracking payload const trackingData = { storeId: 'tinder0001-20', productId: productId || null, url: url, timestamp: new Date().toISOString(), eventType: 'deal_click' }; // In a real app, this would be sent to your backend localStorage.setItem('lastTracking', JSON.stringify(trackingData)); }