// 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
-
Spread the loveFinding the perfect laptop for coding and programming can feel like hunting for a needle in a haystack. You need raw power for compiling, a comfortable keyboard for long typing sessions, and reliable battery life to keep you productive on the go. Below you’ll find a curated list of the top 10 laptops…
-
Spread the loveBlack Friday is the ultimate time to snag a Best Buy laptop at a price that feels almost too good to be true. We’ve scoured the deals, compared specs, and tested performance so you can walk into Best Buy with confidence. Whether you need a powerhouse for work, a sleek notebook for school, or…
-
Learn what Pn in Nmap means and how the -Pn flag skips host discovery for faster network scans. Get practical examples and expert tips here.
-
Learn what Control V does, how to use this paste shortcut on your laptop, and why mastering keyboard commands boosts your daily productivity.
-
Learn how to upgrade your KVM for 1440p60hz with our expert guide. Discover the best KVM switches, setup tips, and compatibility advice for a seamless high-r…
-
Spread the loveFinding the perfect laptop for CAD software can feel like solving a complex 3‑D model—there are many variables to balance, from processing power to graphics performance and portability. In this roundup we’ve tested dozens of machines and narrowed the field to the ten best options that deliver smooth rendering, reliable multitasking, and a…