// Fetch real-time product data for all products when page loads
(function() {
const products = [‘B0FTDN9N3N’, ‘B08G6NJ5R9’, ‘B0G5PWWP6Q’, ‘B0FXM2CYVT’, ‘B0FTFR572F’, ‘B08ML95T9G’, ‘B0FNLL4B6T’, ‘B0FHJVLGKD’, ‘B0F8Z9Y1Y3’, ‘B00JV94EMG’];
const affiliateTag = ‘kitchenstitchcom-20’;
async function fetchLiveProductData(asin) {
try {
const updateTimeEl = document.getElementById(‘update-time-‘ + asin);
if (updateTimeEl) updateTimeEl.innerHTML = ‘⏳ Fetching…’;
const amazonUrl = ‘https://www.amazon.com/dp/’ + asin;
const response = await fetch(‘https://api.allorigins.win/raw?url=’ + encodeURIComponent(amazonUrl));
const html = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(html, ‘text/html’);
let price = null;
const priceWhole = doc.querySelector(‘.a-price-whole’);
const priceFraction = doc.querySelector(‘.a-price-fraction’);
if (priceWhole) {
price = ‘$’ + priceWhole.textContent.trim() + (priceFraction ? priceFraction.textContent.trim() : ”);
}
let rating = null;
const ratingEl = doc.querySelector(‘[data-hook=”average-star-rating”] .a-icon-alt’);
if (ratingEl) {
const match = ratingEl.textContent.match(/(\d+\.\d+)/);
if (match) rating = match[1];
}
let reviewCount = null;
const reviewEl = doc.querySelector(‘#acrCustomerReviewText’);
if (reviewEl) reviewCount = reviewEl.textContent.trim();
if (price) {
const priceEl = document.getElementById(‘price-‘ + asin);
if (priceEl) {
priceEl.innerHTML = price;
priceEl.style.animation = ‘pulse 0.5s’;
}
}
// if (rating) {
// const ratingEl = document.getElementById(‘rating-‘ + asin);
// if (ratingEl) {
// const stars = ‘⭐’.repeat(Math.floor(parseFloat(rating)));
// ratingEl.innerHTML = stars + ‘ ‘ + rating + ‘/5’;
// ratingEl.style.animation = ‘pulse 0.5s’;
// }
// }
if (reviewCount) {
const reviewsEl = document.getElementById(‘reviews-‘ + asin);
if (reviewsEl) {
reviewsEl.innerHTML = reviewCount;
reviewsEl.style.animation = ‘pulse 0.5s’;
}
}
if (updateTimeEl) {
const now = new Date();
const timeStr = now.toLocaleString(‘en-US’, {
month: ‘long’, day: ‘numeric’, year: ‘numeric’,
hour: ‘numeric’, minute: ‘2-digit’, hour12: true
});
updateTimeEl.innerHTML = ‘✓ Updated: ‘ + timeStr;
}
} catch (error) {
const updateTimeEl = document.getElementById(‘update-time-‘ + asin);
if (updateTimeEl) updateTimeEl.innerHTML = ‘✓ Cached data’;
}
}
const style = document.createElement(‘style’);
style.textContent = `@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }`;
document.head.appendChild(style);
function loadAllProducts() {
products.forEach((asin, index) => {
setTimeout(() => fetchLiveProductData(asin), index * 2000);
});
}
if (document.readyState === ‘loading’) {
document.addEventListener(‘DOMContentLoaded’, loadAllProducts);
} else {
loadAllProducts();
}
})();
Similar Posts
-
Looking for the best 36 inch over the range microwave with vent? You’re not alone. This popular kitchen upgrade combines cooking power with built-in ventilation, saving space and boosting efficiency in modern homes. Whether you’re replacing an old unit or building a new kitchen, finding the right model can make all the difference. In this…
-
Looking for the perfect kitchen companion that can pressure cook meals, cook fluffy rice, and handle multiple cooking tasks? A pressure cooker and rice cooker in one appliance combines convenience, speed, and versatility into a single device. These all-in-one units save counter space, reduce cleanup time, and simplify meal prep—whether you’re making stews, porridge, yogurt,…
-
Maintaining your grill’s porcelain enameled cast iron grates is essential for both performance and longevity. Unlike traditional wire brushes that can scratch or damage the delicate surface, you need a specialized tool designed to clean without causing harm. The right grill brush not only removes stubborn grease and food residue but also protects your investment…
-
Looking for a best 36 inch microwave with exhaust fan? The right over-the-range microwave with an integrated exhaust fan is essential for keeping your kitchen fresh, odors at bay, and maintaining optimal air quality. These models combine cooking convenience with powerful ventilation, making them ideal for busy households or open-concept kitchens. Whether you’re reheating leftovers,…
-
Looking to elevate your cocktail game with perfectly clear, slow-melting ice balls? You’re not alone. Whether you’re a whiskey connoisseur or just want to impress guests at your next dinner party, the right ice maker that makes ice balls can transform your drink experience. From traditional silicone molds to countertop machines designed specifically for crystal-clear…
-
Looking for the best glass jars with lids for food storage? You’re in the right place. Whether you’re organizing your pantry, storing dry goods, or preserving fresh ingredients, high-quality glass containers make all the difference. Unlike plastic alternatives, glass doesn’t absorb odors or harbor bacteria, and its transparency lets you see contents at a glance….