function formatPriceElements(container) {
console.log("formatPriceElements calling");
  const priceSelectors = ['.new_price.card_price', '.compare_product_price'];
  priceSelectors.forEach(selector => {
    container.querySelectorAll(selector).forEach(el => {
      let text = el.textContent.trim();
      let number = text.replace(/[^0-9]/g, '');
      if (!number) return;
      let formatted = new Intl.NumberFormat('id-ID', {
        style: 'currency',
        currency: 'IDR',
        minimumFractionDigits: 2
      }).format(number);
      el.textContent = formatted.replace('Rp', 'Rp ');
    });
  });
}
const processedContainers = new WeakSet();
const observer = new MutationObserver(() => {
  document.querySelectorAll('.qe_container').forEach(container => {
    if (container.offsetParent !== null && !processedContainers.has(container)) {
      processedContainers.add(container);
      setTimeout(() => {
        formatPriceElements(container);
      }, 1000);
    }
  });
});
observer.observe(document.body, { childList: true, subtree: true });
function attachButton(button) {
    button.addEventListener('click', function(event) {
        event.preventDefault(); 
        
        setTimeout(() => {
            window.location.reload();
        }, 2000);
    });
}
document.querySelectorAll('.product_addtocart_btn_card.addtocart_btn').forEach(attachButton);
const cartButtonObserver = new MutationObserver(mutations => {
    mutations.forEach(mutation => {
        if (mutation.addedNodes.length > 0) {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1) { 
                    if (node.matches('.product_addtocart_btn_card.addtocart_btn')) {
                        attachButton(node);
                    }
                    node.querySelectorAll('.product_addtocart_btn_card.addtocart_btn').forEach(attachButton);
                }
            });
        }
    });
});
cartButtonObserver.observe(document.body, { childList: true, subtree: true });