// 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 = ‘ugratechnology-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 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…
-
Spread the loveWhen shopping for a new laptop, the return policy is a critical factor that can make or break your purchase. A lenient return policy allows you to test the laptop risk-free, ensuring it meets your performance and usability needs. Retailers like Best Buy often set the standard with generous return windows and no…
-
Spread the loveFinding the best laptop for computer aided design can feel overwhelming. There are so many options out there. You need something that can handle heavy software like AutoCAD, SolidWorks, or Revit without slowing down. Whether you are a student, a professional engineer, or a hobbyist designer, the right laptop makes all the difference….
-
Spread the loveFinding a laptop that can keep up with your busy day without constantly hunting for an outlet is a challenge. That’s why we’ve hand‑picked the best laptops for battery life that blend long‑lasting power with solid performance, so you can stay productive wherever you go. Quick Product Comparison Product Image Check Price 1….
-
Spread the loveLooking for the best buy gaming computer laptop that delivers strong performance without breaking the bank? You’re in the right place. The market is flooded with options, but finding that sweet spot between price, power, and build quality can be tricky. Whether you’re a casual gamer or a competitive player, a great gaming…
-
Spread the loveFinding the best for video editing laptop can feel overwhelming. There are so many options out there, and not all laptops handle video editing equally. Whether you’re a YouTuber, a filmmaker, or just someone who loves editing family videos, you need a machine that won’t slow you down. We’ve tested and researched the…