document.addEventListener('DOMContentLoaded', () => { const isPDP = document.body.classList.contains('catalog-product-view'); const isCart = document.body.classList.contains('checkout-cart-index'); const isSearchPage = document.body.classList.contains('page-with-filter'); function formatPrice(priceElement) { // Verifica si el precio ya ha sido formateado if (priceElement.querySelector('span')) return; let priceText = priceElement.textContent.trim(); // Elimina el símbolo del euro, espacios no separables y espacios normales priceText = priceText.replace('€', '').replace(/\u00A0/g, '').replace(/\s/g, '').trim(); // Usa una expresión regular para dividir el precio, considerando tanto punto como coma let [, entero, decimal] = priceText.match(/(\d+)[,.]?(\d*)/) || []; if (!entero) return; let enteroSpan = document.createElement('span'); enteroSpan.textContent = '€' + entero; enteroSpan.style.fontSize = (isPDP || isCart) ? '26px' : '1.2rem'; let decimalSpan = document.createElement('span'); decimalSpan.textContent = decimal ? '.' + decimal : ''; decimalSpan.style.fontSize = (isPDP || isCart) ? '20px' : '0.8rem'; priceElement.innerHTML = ''; priceElement.appendChild(enteroSpan); priceElement.appendChild(decimalSpan); } function applyFormatting() { const prices = document.querySelectorAll(` .price-wrapper .price, .cart-price .price:not(.old-price .price), .is-Hits-item__price .promotion, .is-Hits-item__price .text-2xl, .flex.items-center.gap-4.flex-wrap .text-2xl.leading-none.font-semibold.whitespace-nowrap `); prices.forEach(price => { if (!price.closest('.old-price') && !price.classList.contains('line-through')) { formatPrice(price); } }); } // Aplicar formato inicial applyFormatting(); // Para páginas de búsqueda, esperar a que los resultados se carguen if (isSearchPage) { const checkSearchResults = setInterval(() => { if (document.querySelector('.is-Hits-item__price') || document.querySelector('.flex.items-center.gap-4.flex-wrap')) { clearInterval(checkSearchResults); applyFormatting(); } }, 100); // Limitar el tiempo de espera a 5 segundos setTimeout(() => clearInterval(checkSearchResults), 5000); } });
Secure connection
Loading...
Mifarma

*Delivery times valid for Ireland, for other regions consult conditions. During sales, Black Friday or Christmas periods, delivery times may be longer than usual.