// Function to show the popup with a fade-in animation
function showPopup() {
const popup = document.getElementById('popupLoader');
if (popup) {
popup.style.display = 'block';
popup.style.opacity = '0';
let opacity = 0;
const fadeIn = setInterval(() => {
if (opacity < 1) {
opacity += 0.1;
popup.style.opacity = opacity.toString();
} else {
clearInterval(fadeIn);
}
}, 30);
}
}
// Function to set the popup display time in localStorage
function setPopupDisplayTime() {
try {
localStorage.setItem('popupLastShown', new Date().getTime().toString());
} catch (e) {
console.error('Local storage is not available:', e);
}
}
// Function to check if the popup should be shown
function shouldShowPopup() {
try {
const lastShown = localStorage.getItem('popupLastShown');
if (!lastShown) {
return true;
}
const currentTime = new Date().getTime();
const timeDifference = currentTime - parseInt(lastShown, 10);
const daysSinceLastShown = timeDifference / (1000 * 3600 * 24);
// Change this value to adjust how often the popup appears (in days)
const daysBeforeShowingAgain = 3;
return daysSinceLastShown >= daysBeforeShowingAgain;
} catch (e) {
console.error('Error checking popup display condition:', e);
return true; // Show popup if there's an error
}
}
// Main function to handle popup display
function handlePopupDisplay() {
if (shouldShowPopup()) {
showPopup();
setPopupDisplayTime();
}
}
// Event listener for when the DOM is fully loaded
document.addEventListener('DOMContentLoaded', handlePopupDisplay);