Last Ping: ${server.last_ping ? new Date(server.last_ping).toLocaleString() : ''}
`;
$list.append(card);
if (typeof data.displayed === 'number') {
// Find the "Showing X of Y results" div and update X
const $showing = $results.find('> div').first();
if ($showing.length && $showing.text().startsWith('Showing')) {
// Add the number of new results to displayed
const match = $showing.text().match(/^Showing (\d+) of (\d+) results/);
if (match) {
const newDisplayed = parseInt(match[1]) + data.displayed;
$showing.text(`Showing ${newDisplayed} of ${match[2]} results`);
}
}
}
});
// Restore scroll position so user stays at previous bottom
//const newScrollHeight = $(document).height();
//$(window).scrollTop(newScrollHeight - prevScrollHeight + $(window).scrollTop());
loading = false;
}).fail(function () {
$('#loading-more').html('Load more');
$results.append('
Failed to fetch more results.
');
loading = false;
moreResults = false;
});
}
/*
$(window).on('scroll', function () {
if (!moreResults || loading) return;
if ($(window).scrollTop() + $(window).height() + 100 >= $(document).height()) {
$(window).scrollTop($(window).scrollTop() - 500);
console.log('Fetching next page:', nextPage);
fetchNextPage();
}
});
*/
$('form').on('submit', function () {
// After a new search, reset paging state
const params = {};
$(this).serializeArray().forEach(({ name, value }) => {
if (value !== '') params[name] = value;
});
lastQuery = $.param(params);
nextPage = 2;
moreResults = true;
loading = false;
});