const currencyRates = { "$": 4.02, "€": 4.32, } const createElementWithOptions = (type, options = {}) => Object.assign(document.createElement(type), options); const prices = Array.from(document.querySelectorAll(".price")).flatMap(el => Array.from(el.childNodes).slice(1, 3)); prices.forEach(el => { if(el.textContent.includes("zł")) return; const trimmed = el.textContent.trim(); console.log(trimmed); const textContent = `${(Number(trimmed.substring(1)) * currencyRates[trimmed[0]]).toFixed(2)} zł`.replace('.', ','); el.textContent = el.nodeName !== "#text" ? textContent : ` ${textContent} `; if (el.nodeName !== "#text") { return; } el.nextElementSibling.textContent = `${trimmed} ${el.nextElementSibling.textContent}`; const smallEl = createElementWithOptions("small", {'textContent': 'ok.'}); smallEl.style.fontWeight = "normal"; smallEl.style.fontSize = "12px"; el.parentElement.insertBefore(smallEl, el); });