// Fetch real-time product data for all products when page loads
(function() {
const products = [‘B0DXFHHYW4’, ‘B0D9XLDX3W’, ‘B0D3LM2WX7’, ‘B0FGH8NKHS’, ‘B0FNMD3W4J’, ‘B0DWMF3LHX’, ‘B0B57M25F8’, ‘B07S1Z9X8D’, ‘B0F1RN9KB8’, ‘B0D69W23G2’];
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
-
Choosing the Best Plastic Bread Bags For Homemade Bread can make a real difference in how fresh and presentable your loaves stay. This roundup highlights durable, food-safe options that seal in flavor and keep crusts crisp. Whether you’re baking daily or packaging loaves for gifts, these bags strike a balance between quality and value. For…
-
The 3 in 1 microwave air fryer convection oven has become a kitchen game-changer for modern households. Combining the speed of a microwave, the crispiness of an air fryer, and the even heat of a convection oven, these versatile appliances save space and time without sacrificing quality. Whether you’re reheating leftovers, baking a batch of…
-
Looking to upgrade your kitchen with a sleek, built-in microwave that fits perfectly in your 27-inch cabinet? A built-in microwave with trim kit 27 offers both style and functionality, giving your space a seamless, professional look. Whether you’re replacing an old unit or building from scratch, finding the right microwave with a matching trim kit…
-
Looking for the perfect ice maker that uses 5 gallon water bottles? You’re not alone. More and more people are discovering how convenient and efficient these systems can be for home and office settings. Whether you need cold, room temperature, or even hot water at the touch of a button, these innovative appliances combine water…
-
Discover the Best Toaster Oven Air Fryer Rotisserie Combo options that combine versatility and countertop convenience. This roundup highlights top performers that handle air frying, rotisserie, baking, and more in a single appliance, making weeknight meals easier and weekend feasts more fun. Whether you’re upgrading from a basic toaster or outfitting a small kitchen, these…
-
Finding the best dishwasher detergent that doesn’t leave residue can make a huge difference in your kitchen routine. Over time, buildup from hard water or ineffective detergents can leave spots, streaks, and even cloudy films on your glassware and dishes. Whether you’re dealing with stubborn food particles, mineral deposits, or just want sparkling clean results…