// 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 30 French door refrigerator with water dispenser? You’re not alone. With so many models on the market, choosing the right one can feel overwhelming. Whether you’re upgrading your kitchen or replacing an old unit, finding a reliable, energy-efficient fridge with convenient water dispensing is key to making everyday life easier. In…
-
Looking for the best carbon steel wok for electric stove 2? You’re in the right place! Whether you’re a home cook craving authentic stir-fries or a professional chef seeking reliable performance, finding the perfect wok can make all the difference. In this guide, we’ve tested and reviewed top-rated options specifically designed to work flawlessly on…
-
Choosing the right rubber floor mats for restaurant kitchens can make a big difference in safety, comfort, and cleanliness. The best mats combine drainage, anti-fatigue support, and a non-slip surface to handle grease, water, and high foot traffic. Below is a curated round-up of top picks that perform well in busy kitchen environments. Quick Product…
-
For home cooks who love sweet potato fries, a dependable French fry cutter can turn tough prep into quick, uniform batches. The right cutter makes it easy to slice sweet potatoes to consistent thickness, so your fries cook evenly every time. In this roundup, we test three popular models for performance, durability, and value, with…
-
Finding the perfect kitchen appliance that combines multiple functions without taking up too much space can be a challenge. The Best Air Fryer Microwave Toaster Oven Combo offers an all-in-one solution for modern kitchens, providing the convenience of a microwave, the crispiness of an air fryer, and the versatility of a toaster oven—all in a…
-
Finding the best Belgium waffle maker with removable plates can be challenging, especially when you want consistent quality, easy cleanup, and the perfect Belgian-style waffles every time. Whether you’re a home baker or hosting a weekend brunch, these top-rated models offer premium features like nonstick surfaces, adjustable browning settings, and dishwasher-safe components to make waffle-making…