function ju_ab_testing(){ var newWidgets = [ // {url: '/wid10145.php?js/4.3.1/wgt-loader.js'}, // {url: '/wid10145.php?js/4.3.11/wgt-loader.js'}, {url: '/wid10145.php?js/4.2.34/wgt-loader.js'} // {url: '/wid10145.php?js/4.3.22/wgt-loader.js'} ]; function randomIntFromInterval(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } var WidgetNubmer; if (localStorage.getItem('widgetLoaded')) { WidgetNubmer = newWidgets.length <= localStorage.getItem('widgetLoaded') ? newWidgets.length - 1 : localStorage.getItem('widgetLoaded'); localStorage.setItem('widgetLoaded', WidgetNubmer); } else { WidgetNubmer = `${randomIntFromInterval(0, newWidgets.length - 1)}`; localStorage.setItem('widgetLoaded', WidgetNubmer); } var script = document.createElement('script'); script.setAttribute('src', newWidgets[WidgetNubmer].url); document.querySelector('body').appendChild(script); } ju_ab_testing();