/** * Author Thiago Tedeschi * @copyright Todos os direitos reservados a equipe NODZ */ let canShowAudio = false let showWpAlertInterval = '' function getBuyers() { return new Promise((resolve, reject) => { const http = new XMLHttpRequest() var url = wpAlertConvert.siteurl + '/getLastBuyersWpAlert'; let params = "type=ajax&pageOrPost="+wpAlertConvert.pageOrPost+"¤t_slug="+wpAlertConvert.current_slug+"¤tePageID="+wpAlertConvert.currentePageID http.open('POST', url, true); http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); http.onreadystatechange = function () { if (http.readyState == 4 && http.status == 200) { const response = JSON.parse(http.responseText) if (response.status) { resolve(response.result) } else { reject(false) } } else if (http.readyState == 4 && http.status != 200) { reject(false) } } http.send(params); }) } function notificationWpAlertaConversao() { getBuyers().then(result => { let limitShowAlert = result.alert.numberAlerts let timesShowedAlert = getCookieWpAlert("showWpAlertConvert") timesShowedAlert = parseInt(timesShowedAlert) limitShowAlert = parseInt(limitShowAlert) if (limitShowAlert == 0 || timesShowedAlert <= limitShowAlert) { let showtimeFadeInWpAlert = parseInt(result.alert.timeFadeInWpAlert) let showtimeFadeOutWpAlert = parseInt(result.alert.timeFadeOutWpAlert) let showinitialTimeFadeInWpAlert = parseInt(result.alert.initialTimeFadeInWpAlert) let showtimeFadeOutWpAlertInitial = showinitialTimeFadeInWpAlert + showtimeFadeOutWpAlert let showTimeInterval = (showtimeFadeInWpAlert + showtimeFadeOutWpAlert) * 1000 let spanShowAlertBox = document.createElement("span"); spanShowAlertBox.setAttribute("id", "showWpAlertBox"); document.body.appendChild(spanShowAlertBox); showNotificationsWpAlertInitial(result,showinitialTimeFadeInWpAlert) hideNotificationsWpAlertInitial(showtimeFadeOutWpAlertInitial).then(snap => { showWpAlertInterval = setInterval(function () { showNotificationsWpAlert(result) hideNotificationsWpAlert(showtimeFadeOutWpAlert) }, showTimeInterval) }) } document.body.addEventListener("click", function () { canShowAudio = true }) if(limitShowAlert != 0){ let showedToUser = getCookieWpAlert("showWpAlertConvert") if(!showedToUser){ setCookieWpAlert("showWpAlertConvert",1,1) }else{ showedToUser = parseInt(showedToUser) + 1 setCookieWpAlert("showWpAlertConvert",showedToUser,1) } }else{ setCookieWpAlert("showWpAlertConvert","","-1") } }).catch(err =>{}) } function showNotificationsWpAlert(result) { let buyerNames = result.buyers.buyers let buyerCities = result.buyers.cities let buyerProducts = result.buyers.products buyerNames = buyerNames.split(",") buyerCities = buyerCities.split(",") buyerProducts = buyerProducts.split(",") buyerNameAlert = buyerNames.sort(function () { return 0.5 - Math.random() }) buyerNameAlert = buyerNameAlert[0] buyerCityAlert = buyerCities.sort(function () { return 0.5 - Math.random() }) buyerCityAlert = buyerCityAlert[0] buyerProductAlert = buyerProducts.sort(function () { return 0.5 - Math.random() }) buyerProductAlert = buyerProductAlert[0] let dataNotification = { positionAlertHorizontal: result.alert.positionAlertHorizontal, positionAlert: result.alert.positionAlert, bg_color: result.alert.bg_color, content_padding: result.alert.content_padding, border_color: result.alert.border_color, border_width: result.alert.border_width, styleBox: result.alert.styleBox, showBorderRadius: result.alert.showBorderRadius, text_color: result.alert.text_color, buyerName: buyerNameAlert, buyerCity: buyerCityAlert, showCloseAlert: result.alert.enableCloseAlertByUser, second_text_color: result.alert.second_text_color, textNotification: result.alert.textNotification, buyerProduct: buyerProductAlert, purchaseTime: changePurchaseTime(result.alert.purchaseTime), affiliateUrl: result.alert.affiliateUrl, enableAffiliateLink: result.alert.enableAffiliateLink, linkInBox: result.alert.linkInBox, linkInBoxTarget: result.alert.linkInBoxTarget, imageAlert: result.image.imageAlert, showImage: result.image.showImage, showBorderImageRadius: result.image.showBorderImageRadius, timeFadeInWpAlert: result.alert.timeFadeInWpAlert, timeFadeOutWpAlert: result.alert.timeFadeOutWpAlert, initialTimeFadeInWpAlert: result.alert.initialTimeFadeInWpAlert, showProgressBar: result.alert.showProgressBar, bgColorProgressBar: result.alert.bgColorProgressBar, colorProgressBar: result.alert.colorProgressBar, } document.getElementById("showWpAlertBox").innerHTML = getNotificationWpAlert(dataNotification,result.alert.timeFadeOutWpAlert) jQuery("#showWpAlertBox").fadeIn("slow"); if(canShowAudio && result.alert.soundPurchase){ let audio = new Audio(result.alert.soundPurchase); audio.play() } if(result.alert.enableCloseAlertByUser == 'enabled'){ document.getElementById("closeWpAlertConvert").addEventListener("click", function(){ document.getElementById("boxTotal").style.display = "none" clearInterval(showWpAlertInterval) }) } } function hideNotificationsWpAlert(timeFadeOutWpAlert) { timeFadeOutWpAlert = timeFadeOutWpAlert * 1000 setTimeout(function () { jQuery("#showWpAlertBox").fadeOut("slow") }, timeFadeOutWpAlert) } function showNotificationsWpAlertInitial(result, timeFadeInWpAlert) { let ShowtimeFadeInWpAlert = timeFadeInWpAlert * 1000 setTimeout(function () { let buyerNames = result.buyers.buyers let buyerCities = result.buyers.cities let buyerProducts = result.buyers.products buyerNames = buyerNames.split(",") buyerCities = buyerCities.split(",") buyerProducts = buyerProducts.split(",") buyerNameAlert = buyerNames.sort(function () { return 0.5 - Math.random() }) buyerNameAlert = buyerNameAlert[0] buyerCityAlert = buyerCities.sort(function () { return 0.5 - Math.random() }) buyerCityAlert = buyerCityAlert[0] buyerProductAlert = buyerProducts.sort(function () { return 0.5 - Math.random() }) buyerProductAlert = buyerProductAlert[0] let dataNotification = { positionAlertHorizontal: result.alert.positionAlertHorizontal, positionAlert: result.alert.positionAlert, bg_color: result.alert.bg_color, content_padding: result.alert.content_padding, border_color: result.alert.border_color, border_width: result.alert.border_width, styleBox: result.alert.styleBox, showBorderRadius: result.alert.showBorderRadius, text_color: result.alert.text_color, buyerName: buyerNameAlert, buyerCity: buyerCityAlert, showCloseAlert: result.alert.enableCloseAlertByUser, second_text_color: result.alert.second_text_color, textNotification: result.alert.textNotification, buyerProduct: buyerProductAlert, purchaseTime: changePurchaseTime(result.alert.purchaseTime), affiliateUrl: result.alert.affiliateUrl, enableAffiliateLink: result.alert.enableAffiliateLink, linkInBox: result.alert.linkInBox, linkInBoxTarget: result.alert.linkInBoxTarget, imageAlert: result.image.imageAlert, showImage: result.image.showImage, showBorderImageRadius: result.image.showBorderImageRadius, timeFadeInWpAlert: result.alert.timeFadeInWpAlert, timeFadeOutWpAlert: result.alert.timeFadeOutWpAlert, initialTimeFadeInWpAlert: result.alert.initialTimeFadeInWpAlert, showProgressBar: result.alert.showProgressBar, bgColorProgressBar: result.alert.bgColorProgressBar, colorProgressBar: result.alert.colorProgressBar, } document.getElementById("showWpAlertBox").innerHTML = getNotificationWpAlert(dataNotification,result.alert.timeFadeOutWpAlert) jQuery("#showWpAlertBox").fadeIn("slow"); if(canShowAudio && result.alert.soundPurchase){ let audio = new Audio(result.alert.soundPurchase); audio.play() } if(result.alert.enableCloseAlertByUser == 'enabled'){ document.getElementById("closeWpAlertConvert").addEventListener("click", function(){ document.getElementById("boxTotal").style.display = "none" clearInterval(showWpAlertInterval) }) } }, ShowtimeFadeInWpAlert) } function hideNotificationsWpAlertInitial(timeFadeOutWpAlert) { return new Promise((resolve, reject) => { timeFadeOutWpAlert = timeFadeOutWpAlert * 1000 setTimeout(function () { jQuery("#showWpAlertBox").fadeOut("slow") resolve(true) }, timeFadeOutWpAlert) }) } function changePurchaseTime(purchaseTime = '') { if (purchaseTime != "") { let timesRandom = purchaseTime timesRandom = timesRandom.split(",").sort(function () { return 0.5 - Math.random() }) timesRandom = timesRandom[0] return timesRandom } else { return "" } } function randomTimeWpAlert(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; } function getCookieWpAlert(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(";"); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function setCookieWpAlert(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;"; } function getNotificationWpAlert(data,timeFadeInWpAlert) { let htmlShowCloseAlert = "" if (data.showCloseAlert == "disabled") { htmlShowCloseAlert = "display: none;" } let htmlShowAffiliateLink = "" if (data.affiliateUrl == "" || data.enableAffiliateLink == "disabled") { htmlShowAffiliateLink = "display: none;" } let htmlShowImage = "" if (data.showImage == "disabled") { htmlShowImage = "display: none;" } let tempoExibicao = parseInt(timeFadeInWpAlert) + parseInt(data.timeFadeOutWpAlert) let htmlShowProgressBar = "" if (data.showProgressBar == "disabled") { htmlShowProgressBar = "display: none;" } let showLinkTotalAlert = ""; let showCloseLinkTotalAlert = ""; if(data.linkInBox != ""){ showLinkTotalAlert = ''; showCloseLinkTotalAlert = ""; } let boxNotification = ` ${showLinkTotalAlert}