Change section every 2 hours

Description: Change section every 2 hours

Use code under Section Loader Plugin code

<style>
.wm-home-hidden {
  display: none !important;
}
</style>

<script>
const CONFIG = {
  sourcePage: '/home-alt',
  updateInterval: 7200
};

(async function() {
  const SECONDS_MS = CONFIG.updateInterval * 1000;
  
  function isHomePage() {
    return window.location.pathname === '/' || window.location.pathname === '/home';
  }
  
  if (!isHomePage()) return;
  
  const article = document.querySelector('article.sections');
  if (!article) return;
  
  const originalSections = Array.from(article.querySelectorAll(':scope > section'));
  
  const fragment = await wm$.getFragment(CONFIG.sourcePage, 'article.sections');
  const altSections = Array.from(fragment.querySelectorAll('section'));
  
  altSections.forEach(section => {
    article.appendChild(section);
  });
  
  await wm$.reloadSquarespaceLifecycle(altSections);
  
  let showingOriginal = true;
  
  function toggle() {
    if (showingOriginal) {
      originalSections.forEach(s => s.classList.add('wm-home-hidden'));
      altSections.forEach(s => s.classList.remove('wm-home-hidden'));
    } else {
      originalSections.forEach(s => s.classList.remove('wm-home-hidden'));
      altSections.forEach(s => s.classList.add('wm-home-hidden'));
    }
    showingOriginal = !showingOriginal;
  }
  
  altSections.forEach(s => s.classList.add('wm-home-hidden'));
  
  setInterval(toggle, SECONDS_MS);
})();
</script>

 

 

Buy me a coffee