class InfiniteScroll { constructor(options = {}) { this.container = document.getElementById('items-thumbs'); this.initialItemCount = this.container ? this.container.children.length : 0; if (!this.container || this.initialItemCount < 12) { // console.log('Not enough items for infinite scroll, skipping initialization'); if (window.location.href.includes('page=')) { const cleanUrl = window.location.href.replace(/[&?]page=\d+/, '').replace(/\?$/, ''); window.history.replaceState({}, '', cleanUrl); } return; } this.loadingElement = this.createLoadingElement(); this.page = 1; this.loading = false; this.isFullListingPage = this.isAllWatchesOrHome(); this.hasMore = true; this.lastCount = this.initialItemCount; this.loadedOnce = false; this.allItemsLoaded = !this.isFullListingPage && this.initialItemCount < 96; this.baseURI = window.location.href.replace(/[&?]page=\d+/, '').replace(/\?$/, ''); // Add a Set to track loaded item IDs this.loadedItems = new Set(); this.initializeLoadedItems(); this.init(); } // Initialize the loadedItems Set with current items' stock IDs initializeLoadedItems() { const currentItems = this.container.querySelectorAll('img[alt]'); currentItems.forEach(item => { this.loadedItems.add(item.getAttribute('alt')); }); } isAllWatchesOrHome() { const url = window.location.href; return url.includes('all-watches') || url.endsWith('/preowned/') || url.endsWith('/preowned'); } createLoadingElement() { const div = document.createElement('div'); div.className = 'loading-spinner'; div.innerHTML = `