JSFiddle - React, Tailwind, and code Playground
JavaScript
function makeRandomString(len) {
var res = [];
for (; len; len--) {
res.push('qwertyuiopasdfghjklzxcvbnm1234567890-'.charAt(Math.floor(Math.random() * 37)));
}
return res.join('');
}
function makeBanner(habra) {
var bannerUrl;
var borderColor;
if (habra) {
bannerUrl = 'http://i.imgur.com/58SRA2N.png';
borderColor = 'green';
} else {
bannerUrl = 'http://perfectapp.perfectinter.net/images/pa_banner_468x60.png';
borderColor = 'red';
}
var banner = document.createElement('div');
banner.setAttribute('id', makeRandomString(16));
banner.setAttribute('style', [
"background-image: url('" + bannerUrl + "') !important;",
"width: 468px !important;",
"height: 60px !important;",
"background-repeat: repeat repeat !important;",
"background-position: center center !important;",
"cursor: pointer !important;",
"border: 3px " + borderColor + " solid;"
].join(' '));
return banner;
}
var currentBanner = null;
window.setInterval(function() {
if (currentBanner) {
document.body.removeChild(currentBanner);
}
document.body.appendChild(currentBanner = makeBanner(Math.random() < 0.5));
}, 500);