jQuery(document).ready(function($){
let refreshInterval;
function loadNotification(){
$.ajax({
url: ran_ajax_object.ajax_url,
type: 'POST',
data: {
action: 'ran_get_latest_comment'
},
success: function(response){
if(response.success){
var notificationText=response.data.notification;
$('#comment-notification-bar').html(notificationText).fadeIn();
setTimeout(function(){
$('#comment-notification-bar').fadeOut();
}, 15000);
}else{
$('#comment-notification-bar').fadeOut();
}},
error: function(){
$('#comment-notification-bar').fadeOut();
}});
}
function startRefreshing(){
refreshInterval=setInterval(function(){
loadNotification();
}, 15000);
}
function stopRefreshing(){
clearInterval(refreshInterval);
}
document.addEventListener('visibilitychange', function(){
if(document.visibilityState==='visible'){
loadNotification();
startRefreshing();
}else{
stopRefreshing();
}});
if(document.visibilityState==='visible'){
startRefreshing();
}});