' + '
' + '
' + '
'; total.before(caixa); } if (centavos <= 0) { if (!caixa.hidden) caixa.hidden = true; return; } if (caixa.hidden) caixa.hidden = false; /* Link para editar quantidades no carrinho completo */ if (!caixa.querySelector('.bf-editar-quantidades')) { const finalizar = Array.from( carrinho.querySelectorAll('.footer-cart a') ).find(function (link) { return link.textContent.includes('Fechar pedido'); }); if (finalizar) { const link = document.createElement('a'); link.className = 'bf-editar-quantidades'; link.href = finalizar.href; link.textContent = 'Alterar quantidades (+ / -)'; caixa.appendChild(link); } } const faltam = Math.max(0, META - centavos); const dinheiro = (faltam / 100).toLocaleString( 'pt-BR', { style: 'currency', currency: 'BRL' } ); const mensagem = faltam > 0 ? 'Adicione mais ' + dinheiro + ' para aproveitar 50% OFF no atacado!' : 'Meta atingida! Confira o desconto de 50% no pedido.'; const texto = caixa.querySelector('.bf-progresso-texto'); if (texto.textContent !== mensagem) { texto.textContent = mensagem; } const percentual = Math.min(100, centavos / META * 100).toFixed(1) + '%'; const barra = caixa.querySelector( '.bf-progresso-preenchimento' ); if (barra.style.width !== percentual) { barra.style.width = percentual; } } function agendar() { if (agendado) return; agendado = true; requestAnimationFrame(function () { agendado = false; atualizar(); }); } function iniciar() { const carrinho = document.querySelector('#sidecart'); if (!carrinho) return; const observador = new MutationObserver(function (mutacoes) { const alteracaoExterna = mutacoes.some(function (m) { const elemento = m.target.nodeType === 3 ? m.target.parentElement : m.target; return elemento && !elemento.closest('.bf-progresso-atacado'); }); if (alteracaoExterna) { agendar(); } }); observador.observe(carrinho, { childList: true, subtree: true, characterData: true }); agendar(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', iniciar); } else { iniciar(); } })();