Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Last active January 3, 2024 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/6ed6fd25b46682145e622eff4845b30d to your computer and use it in GitHub Desktop.
Save nocodesupplyco/6ed6fd25b46682145e622eff4845b30d to your computer and use it in GitHub Desktop.
Show a Preloader Once Per Day
// Target the preloader element
const preloaderElement = document.getElementById('preloader');
// Set the amount of time to wait in milliseconds
// Test by changing to 1 * 60 * 1000 for 1 min
const waitTime = 24 * 60 * 60 * 1000; // 24 hours
// Check if the local storage item is present and valid
if (!localStorage.getItem('preloaderShown') || Date.now() - localStorage.getItem('preloaderShown') >
waitTime) {
// Show the preloader element
preloaderElement.style.display = 'block';
// Store the current timestamp in local storage
localStorage.setItem('preloaderShown', Date.now());
} else {
// Hide the preloader element
preloaderElement.style.display = 'none';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment