// Fetch real-time product data for all products when page loads
(function() {
const products = [‘B0FKGZQHQB’, ‘B0GY41B3RR’, ‘B0GTYLB5BV’, ‘B0GY39CQ5Z’, ‘B0G1S117G7’, ‘B0GX9YZVSC’, ‘B0G6482YDW’, ‘B0GQXYBDPP’, ‘B0F6MYQWL2’, ‘B0GLG5XLRK’];
const affiliateTag = ‘arah05-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();
}
})();
Ugra Technology
At Ugra Technology Private Limited, we are passionate about technology and committed to helping individuals and businesses make smarter digital decisions.
Similar Posts
-
Learn what the Windows Feature Experience Pack is, how it works, and why it matters for your laptop. Get clear answers on system requirements, features, and …
-
What Is Shift 2 On Keyboard? Learn the right shift key functions, common shortcuts, and how Shift 2 works on your laptop for faster typing.
-
Spread the loveFinding a reliable laptop for under 500 bucks can feel like hunting for a needle in a haystack, especially when you need solid performance for school, work, or light entertainment. We’ve tested dozens of budget-friendly models and narrowed the list down to the ten best options that deliver real value without breaking the bank. Whether…
-
Learn how to share laptop internet with other devices easily. Step-by-step guide on turning your laptop into a hotspot for seamless connectivity.
-
Learn proven strategies to prevent laptop theft from your car. Discover tips, products, and best practices to keep your device safe every time you park.
-
Learn what eMMC is in laptops, how it works, and how it compares to SSDs. Our guide covers speed, storage capacity, and whether eMMC is right for your needs.