Untitled
unknown
plain_text
a month ago
6.9 kB
4
Indexable
Never
(function (window) { const testId = 'AB-05'; console.log(testId) waitFor(pageReady) .then(runVariant) .catch((err) => console.error(testId, err)); function runVariant() { // once document.querySelector('.front-row > p').innerHTML = document.querySelector('.front-row > p').innerHTML.replace('Record Print', 'Price') document.querySelector('.front-row > p').style.margin = 0; changeSaving(); // every update // document.querySelectorAll('.front-row .badge').forEach(x => x.remove()) // Seleciona o elemento alvo const targetNode = document.querySelector('span.discount.color-yellow'); // Configura as opções de observação (neste caso, observamos alterações nos atributos e no conteúdo do texto) const config = { attributes: true, childList: true, subtree: true, characterData: true }; // Define a callback para executar quando uma mutação for detectada const callback = function (mutationsList, observer) { for (const mutation of mutationsList) { if (mutation.type === 'childList') { changeSaving(); } else if (mutation.type === 'attributes') { changeSaving(); } else if (mutation.type === 'characterData') { changeSaving(); } } }; // Cria uma instância do MutationObserver com a callback const observer = new MutationObserver(callback); // Começa a observar o elemento alvo com as opções de configuração especificadas if (targetNode) { observer.observe(targetNode, config); } else { console.log('AB05 not found!'); } } function changeSaving() { // document.querySelector('.front-row .badge').textContent = 'SAVE: ' + document.querySelector('.front-row .discount.color-yellow').textContent.replace(' OFF', ''); let newTotal = document.querySelector('.product__accordion_custom .price__container .price__sale .price-item.price-item--sale.price-item--last .money').textContent; let oldTotal = document.querySelector('.product__accordion_custom .price__container .price__sale .price-item.price-item--regular:not(.price-item--last) .money').textContent; if (!newTotal || !oldTotal) return; newTotal = newTotal.replace(/[^\d.]/g, ''); oldTotal = oldTotal.replace(/[^\d.]/g, ''); const printValue = ((1 - (newTotal / oldTotal)) * 100).toFixed(2); document.querySelector('.front-row .badge').textContent = 'SAVE: ' + printValue + '%'; document.querySelector('.quantityRow span.discount.color-yellow').textContent = 'YOU SAVE $' + (oldTotal - newTotal).toFixed(2); } function pageReady() { return document.querySelector('.recordPrint .front-row'); } function waitFor(condition, timeout) { const stopTime = typeof timeout === 'number' ? timeout : 7000; let stop = false; window.setTimeout(function () { stop = true; }, stopTime); // eslint-disable-next-line no-undef return new Promise(function (resolve, reject) { (function _innerWaitFor() { const value = condition(); if (stop) { reject(); } else if (value) { resolve(value); } else { window.setTimeout(_innerWaitFor, 50); } })(); }); } })(typeof unsafeWindow === 'undefined' ? window : unsafeWindow); /* .product__accordion_custom .recordPrint .front-row>p, .product__accordion_custom .recordPrint .front-row .price_front .price, .product__accordion_custom .recordPrint .front-row .price_front .price .price__container .price__sale { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; } .product__accordion_custom .recordPrint .front-row .price_front .price, .product__accordion_custom .recordPrint .front-row .price_front .price .price__container .price__sale { gap: 4px; }*/ .secound-row .saveMoney { display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-end; gap: 5; } .secound-row .saveMoney .discount.color-yellow { padding: 2px 8px; } .front-row .price-item.price-item--regular > .money.bacurr-money, .front-row .price-item.price-item--regular > .money { font-size: 12px !important; font-weight: 700; line-height: 14.4px; text-align: left; color: #9493A6 !important; } .front-row .price-item.price-item--sale.price-item--last > .money.bacurr-money, .front-row .price-item.price-item--sale.price-item--last > .money { font-size: 16px !important; font-weight: 700; line-height: 19.2px; text-align: left; } .span.badge.price__badge-sale.color-accent-2 { padding: 4.5px 8px; line-height: unset; } .discount.color-yellow { visibility: hidden; width: 0px; display: block; height: 0px; } .front-row { justify-content: flex-start !important; padding: 17px 0 20px !important; align-items: flex-start !important; } .recordPrint .front-row p { margin: 0px !important; line-height: unset !important; font-size: 12px !important; font-weight: 700 !important; line-height: 12px; letter-spacing: 2px; padding-top: 2px; } span.badge.price__badge-sale.color-accent-2 { margin: 0; } .front-row .price_front .price__container .price__sale { gap: 4px; margin-left: 8px; margin-right: 4px; display: flex; } @media screen and (min-width: 1024px) { .front-row .price-item.price-item--regular > .money.bacurr-money, .front-row .price-item.price-item--regular > .money { font-size: 16px !important; line-height: 19.2px; } .front-row .price-item.price-item--sale.price-item--last > .money.bacurr-money, .front-row .price-item.price-item--sale.price-item--last > .money { font-size: 20px !important; font-weight: 700; line-height: 14px; } .secound-row .saveMoney .discount.color-yellow { padding: 5px 8px; } .recordPrint .front-row p { padding-top: 4px; } } @media (max-width: 1199px) { .recordPrint .front-row p { width: unset; } } .secound-row .saveMoney .discount.color-yellow { height: fit-content; width: fit-content; display: flex; align-items: center; visibility: visible; } .discount.color-yellow.d-flex .white { color: #fdcb0f; }
Leave a Comment