document.addEventListener("DOMContentLoaded", function () { function parsePrice(value) { if (!value) return null; let price = value.replace(/[^\d.,]/g, ""); if (price.includes(",") && price.includes(".")) { price = price.replace(/,/g, ""); } else { price = price.replace(",", "."); } return parseFloat(price); } function addPromotion(container, discount) { if (!container) return; const promo = container.querySelector(".promo"); if (promo && !promo.innerHTML.includes("%")) { promo.innerHTML += ` -${discount}%`; } } // Product listing if (document.body.classList.contains("shop_product_list")) { document.querySelectorAll(".product").forEach(product => { const currentPrice = product.querySelector(".price em"); const regularPrice = product.querySelector(".price__regular del"); if (!currentPrice || !regularPrice) return; const current = parsePrice(currentPrice.textContent); const regular = parsePrice(regularPrice.textContent); if (!current || !regular || regular <= current) return; const discount = Math.round(100 * (1 - current / regular)); addPromotion(product.querySelector(".tags"), discount); }); } // Single product if (document.body.classList.contains("shop_product")) { const currentPrice = document.querySelector( "#box_productfull .price .main-price.color" ); const regularPrice = document.querySelector( "#box_productfull .price__regular del" ); const tags = document.querySelector( "#box_productfull .productdetailsimgsize .tags" ); if (!currentPrice || !regularPrice || !tags) return; const current = parsePrice(currentPrice.textContent); const regular = parsePrice(regularPrice.textContent); if (!current || !regular || regular <= current) return; const discount = Math.round(100 * (1 - current / regular)); addPromotion(tags, discount); } });