// Add logic to handle 'Load More' document.addEventListener("DOMContentLoaded", function () { let currentIndex = 51; const btn = document.getElementById('load-more-btn'); if (btn) { btn.addEventListener('click', async () => { const urlParams = new URLSearchParams(window.location.search); const tag = urlParams.get('tag'); const gender = urlParams.get('gender'); // Set loading state const originalText = btn.innerText; btn.innerText = 'Loading...'; btn.disabled = true; const models = await fetchModels({ index: currentIndex, length: 50, tag, gender }); const gridContainer = document.getElementById('camsoda-model-grid'); if (models && models.length > 0) { const newHtml = models.map(model => createModelCardHtml(model)).join(''); gridContainer.insertAdjacentHTML('beforeend', newHtml); currentIndex += 50; } else { btn.innerText = 'No more models'; return; // keep disabled } btn.innerText = originalText; btn.disabled = false; }); } });