(function() { function ready(fn) { if (window.jQuery) return fn(); setTimeout(function() { ready(fn); }, 50); } ready(function() { if (typeof window.allMarketDomains === 'undefined') return; // State management const state = { priceType: '', // '', 'fixed', 'inquiry' domainType: '', // '', 'english', 'numeric', 'idn' selectedSuffixes: [], // array of suffixes tempSuffixes: [], // temp checkbox selection before '确定' is clicked searchQuery: '', // prefix search string sortBy: 'time', // 'time', 'length', 'price' sortOrder: 'desc', // 'asc', 'desc' (default desc for time) page: 1, pageSize: 20 }; // Filter and Render handler window.renderDomainList = function() { let list = [...window.allMarketDomains]; // 1. Filter by price type if (state.priceType) { list = list.filter(d => d.price_type === state.priceType); } // 2. Filter by domain type if (state.domainType) { list = list.filter(d => d.domain_type === state.domainType); } // 3. Filter by suffixes if (state.selectedSuffixes && state.selectedSuffixes.length > 0) { list = list.filter(d => state.selectedSuffixes.includes(d.suffix)); } // 4. Filter by prefix search query if (state.searchQuery) { const query = state.searchQuery.toLowerCase(); list = list.filter(d => d.domain.toLowerCase().startsWith(query)); } // 5. Sort list if (state.sortBy === 'time') { list.sort((a, b) => { const diff = parseInt(b.create_date) - parseInt(a.create_date); return state.sortOrder === 'asc' ? -diff : diff; }); } else if (state.sortBy === 'length') { list.sort((a, b) => { const diff = parseInt(a.length) - parseInt(b.length); return state.sortOrder === 'desc' ? -diff : diff; }); } else if (state.sortBy === 'price') { list.sort((a, b) => { const valA = a.price_type === 'inquiry' ? -1 : parseFloat(a.price); const valB = b.price_type === 'inquiry' ? -1 : parseFloat(b.price); const diff = valA - valB; return state.sortOrder === 'desc' ? -diff : diff; }); } // 6. Paginate list const totalCount = list.length; const totalPages = Math.ceil(totalCount / state.pageSize) || 1; if (state.page > totalPages) state.page = totalPages; const startIdx = (state.page - 1) * state.pageSize; const paginatedList = list.slice(startIdx, startIdx + state.pageSize); // Render table body const $tbody = $('#domain-list-tbody'); $tbody.empty(); if (paginatedList.length === 0) { $tbody.append('
没有符合筛选条件的域名
'); } else { paginatedList.forEach(d => { const isVerified = parseInt(d.verify_status) === 1; const verifyBadge = isVerified ? `` : ``; const priceStyle = d.price_type === 'inquiry' ? 'color: #3b82f6;' : 'color: #ef4444;'; const row = `
${verifyBadge} ${xn.htmlspecialchars(d.domain)}
${d.length}
${xn.htmlspecialchars(d.description || '--')}
${d.price_display}
`; $tbody.append(row); }); } // Render pagination const $nav = $('#pagination-nav'); $nav.empty(); if (totalPages > 1) { const $ul = $('

'); // Prev button const prevDisabled = state.page === 1 ? 'disabled' : ''; $ul.append(`
- «
`); // Page numbers for (let i = 1; i <= totalPages; i++) { if (totalPages > 8 && Math.abs(state.page - i) > 2 && i !== 1 && i !== totalPages) { if (i === 2 || i === totalPages - 1) { $ul.append('
- ...
'); } continue; } const activeClass = state.page === i ? 'active' : ''; $ul.append(`
- ${i}
`); } // Next button const nextDisabled = state.page === totalPages ? 'disabled' : ''; $ul.append(`
- »
`); $nav.append($ul); } }; // Actions window.setPriceTypeFilter = function(priceType, btn) { state.priceType = priceType; state.page = 1; $('.price-tab-btn').removeClass('active'); $(btn).addClass('active'); window.renderDomainList(); }; window.toggleDomainTypeDropdown = function(e) { if (e) e.stopPropagation(); $('#domain-type-dropdown').slideToggle(150); $('#suffix-dropdown').slideUp(150); }; window.setDomainTypeFilter = function(type, labelText, item, e) { if (e) e.stopPropagation(); state.domainType = type; state.page = 1; $('#domain-type-text').text(labelText); $('.domain-type-option-item').removeClass('active'); $(item).addClass('active'); $('#domain-type-dropdown').slideUp(150); window.renderDomainList(); }; window.toggleSuffixDropdown = function(e) { if (e) e.stopPropagation(); $('#suffix-dropdown').slideToggle(150); $('#domain-type-dropdown').slideUp(150); }; window.updateSuffixSelection = function(checkbox) { const val = checkbox.value; if (checkbox.checked) { if (!state.tempSuffixes.includes(val)) { state.tempSuffixes.push(val); } } else { state.tempSuffixes = state.tempSuffixes.filter(v => v !== val); } }; window.filterSuffixOptions = function(query) { const q = query.toLowerCase(); $('.suffix-option-item').each(function() { const sfx = $(this).find('input').val().toLowerCase(); if (sfx.indexOf(q) !== -1) { $(this).show(); } else { $(this).hide(); } }); }; window.clearSuffixes = function(e) { if (e) e.stopPropagation(); $('.suffix-checkbox').prop('checked', false); state.tempSuffixes = []; state.selectedSuffixes = []; state.page = 1; $('#suffix-text').text('后缀筛选'); $('#suffix-dropdown').slideUp(150); window.renderDomainList(); }; window.applySuffixes = function(e) { if (e) e.stopPropagation(); state.selectedSuffixes = [...state.tempSuffixes]; state.page = 1; if (state.selectedSuffixes.length > 0) { $('#suffix-text').text(state.selectedSuffixes.length + ' 个后缀'); } else { $('#suffix-text').text('后缀筛选'); } $('#suffix-dropdown').slideUp(150); window.renderDomainList(); }; window.performSearch = function() { state.searchQuery = $('#domain-search-input').val().trim(); state.page = 1; window.renderDomainList(); }; window.setPage = function(page) { state.page = page; window.renderDomainList(); const topOffset = $('#theme-feed-tabs').offset().top - 20; if ($(window).scrollTop() > topOffset) { $('html, body').animate({ scrollTop: topOffset }, 100); } }; // Sorting window.sortByTime = function(btn) { state.sortBy = 'time'; state.sortOrder = state.sortOrder === 'desc' ? 'asc' : 'desc'; // Reset other icons $('#sort-length-icon, #sort-price-icon').removeClass('fa-sort-up fa-sort-down').addClass('fa-sort').css('opacity', '0.4'); // Update time icon const icon = $('#sort-time-icon'); icon.removeClass('fa-sort fa-sort-up fa-sort-down'); if (state.sortOrder === 'asc') { icon.addClass('fa-sort-up').css('opacity', '1'); } else { icon.addClass('fa-sort-down').css('opacity', '1'); } window.renderDomainList(); }; window.sortByLength = function(th) { state.sortBy = 'length'; state.sortOrder = state.sortOrder === 'asc' ? 'desc' : 'asc'; // Reset other icons $('#sort-time-icon, #sort-price-icon').removeClass('fa-sort-up fa-sort-down').addClass('fa-sort').css('opacity', '0.4'); // Update length icon const icon = $('#sort-length-icon'); icon.removeClass('fa-sort fa-sort-up fa-sort-down'); if (state.sortOrder === 'asc') { icon.addClass('fa-sort-up').css('opacity', '1'); } else { icon.addClass('fa-sort-down').css('opacity', '1'); } window.renderDomainList(); }; window.sortByPrice = function(th) { state.sortBy = 'price'; state.sortOrder = state.sortOrder === 'asc' ? 'desc' : 'asc'; // Reset other icons $('#sort-time-icon, #sort-length-icon').removeClass('fa-sort-up fa-sort-down').addClass('fa-sort').css('opacity', '0.4'); // Update price icon const icon = $('#sort-price-icon'); icon.removeClass('fa-sort fa-sort-up fa-sort-down'); if (state.sortOrder === 'asc') { icon.addClass('fa-sort-up').css('opacity', '1'); } else { icon.addClass('fa-sort-down').css('opacity', '1'); } window.renderDomainList(); }; // Global click to close dropdowns $(document).on('click', function(e) { if (!$(e.target).closest('#domain-type-trigger, #domain-type-dropdown').length) { $('#domain-type-dropdown').slideUp(150); } if (!$(e.target).closest('#suffix-trigger, #suffix-dropdown').length) { $('#suffix-dropdown').slideUp(150); } }); // Initialize render window.renderDomainList(); // Detail popup trigger window.showDomainDetail = function(id) { var $modal = $('#domain-detail-modal'); if (!$modal.length) { $modal = $('
' + '
' + '
' + '
').appendTo('body'); $modal.on('click', function(e) { if (e.target === this) { window.closeDomainModal(); } }); } $('#domain-detail-modal-container').html('
加载中...
'); $modal.removeClass('hidden'); $.ajax({ url: xn.url('jishidetail-' + id), type: 'GET', dataType: 'html', success: function(html) { $('#domain-detail-modal-container').html(html); }, error: function() { $('#domain-detail-modal-container').html('
加载失败，请重试。
'); } }); }; window.closeDomainModal = function() { $('#domain-detail-modal').addClass('hidden'); }; window.showDomainWhois = function(domain, event) { if (event) { event.stopPropagation(); event.preventDefault(); } window.open('https://whois.aliyun.com/whois/domain/' + domain, '_blank'); }; }); })();