let textElements = ['element-1195'] let loopDelay = 1000; // process runs every n milliseconds let updateChances = 3; // chance that a number will be incremented (lower is higher chance) let doubleChance = 9; // chance that a number will be incremented by 2 (lower is higher chance) let fadeAmount = 0.4; let fadeInDuration = 750; function tryUpdate(elementName) { if (Math.floor(Math.random() * Math.floor(updateChances)) == 1) { reduceByOne(elementName); if (Math.floor(Math.random() * Math.floor(doubleChance)) == 1) { reduceByOne(elementName); } } } function reduceByOne(elementName) { const pattern = /([0-9,]{2,})/; var recently = $("#" + elementName + " span:contains('Recently')"); var incAmout = 1; salesCount = parseInt(recently.text().replace(/,/g, '').match(pattern, recently.text()[1])) + 1; newText = recently.text().replace(pattern, salesCount.toLocaleString()); $("#" + elementName + " span:contains('Recently')").fadeTo( 1, fadeAmount ); $("#" + elementName + " span:contains('Recently')").text(newText); $("#" + elementName + " span:contains('Recently')").fadeTo( fadeInDuration, 1 ); $("#" + elementName + " span:contains('Recently')").fadeIn(); } function updateLoop() { textElements.forEach(element => tryUpdate(element)) setTimeout(updateLoop, loopDelay); } updateLoop();