// Load PDS data and populate table document.addEventListener('DOMContentLoaded', function() { // Check if mobile and show popup if (window.innerWidth < 768) { document.getElementById('mobile-popup').style.display = 'flex'; } // Close mobile popup button document.getElementById('close-mobile-popup').addEventListener('click', function() { document.getElementById('mobile-popup').style.display = 'none'; }); // Search input document.getElementById('search-input').addEventListener('input', filterData); // Invite filter radios document.querySelectorAll('input[name="invite-filter"]').forEach(radio => { radio.addEventListener('change', filterData); }); loadPDSData(); }); // Store all PDS data globally for filtering let allPDSData = []; async function loadPDSData() { const loading = document.getElementById('loading'); const content = document.getElementById('content'); const tableBody = document.getElementById('table-body'); const noData = document.getElementById('no-data'); const serverCount = document.getElementById('server-count'); try { const response = await fetch('./pdslist.json'); const pdsData = await response.json(); allPDSData = pdsData; // Store for filtering // Hide loading loading.style.display = 'none'; content.style.display = 'block'; if (pdsData.length === 0) { noData.style.display = 'block'; return; } // Update server count serverCount.textContent = pdsData.length; // Populate table pdsData.forEach(pds => { const row = createTableRow(pds); tableBody.appendChild(row); }); // Set initial filtered count to total document.getElementById('filtered-count').textContent = pdsData.length; } catch (error) { console.error('Error loading PDS data:', error); loading.innerHTML = '
Error loading database. Please check console.
'; } } function filterData() { const searchTerm = document.getElementById('search-input').value.toLowerCase(); const inviteFilter = document.querySelector('input[name="invite-filter"]:checked').value; const tableBody = document.getElementById('table-body'); const rows = tableBody.querySelectorAll('tr'); let visibleCount = 0; rows.forEach((row, index) => { const pds = allPDSData[index]; if (shouldShowRow(pds, searchTerm, inviteFilter)) { row.style.display = ''; visibleCount++; } else { row.style.display = 'none'; } }); // Update the filtered count document.getElementById('filtered-count').textContent = visibleCount; } function shouldShowRow(pds, searchTerm, inviteFilter) { // Apply search filter const searchMatch = !searchTerm || pds.url.toLowerCase().includes(searchTerm) || (pds.supportedHandles && pds.supportedHandles.some(h => h.toLowerCase().includes(searchTerm))) || (pds.maintainer && pds.maintainer.toLowerCase().includes(searchTerm)) || (pds.contactEmail && pds.contactEmail.toLowerCase().includes(searchTerm)); // Apply invite filter const inviteMatch = inviteFilter === 'all' || (inviteFilter === 'yes' && pds.inviteCodeRequired) || (inviteFilter === 'no' && !pds.inviteCodeRequired); return searchMatch && inviteMatch; } function createTableRow(pds) { const row = document.createElement('tr'); // URL const urlCell = document.createElement('td'); const urlLink = document.createElement('p'); // sanitize URL by removing any '@' characters const safeUrl = pds.url ? pds.url.replace(/@/g, '') : ''; urlLink.href = safeUrl; urlLink.target = '_blank'; urlLink.textContent = safeUrl; urlCell.appendChild(urlLink); row.appendChild(urlCell); // Handles const handlesCell = document.createElement('td'); if (pds.supportedHandles && pds.supportedHandles.length > 0) { handlesCell.textContent = pds.supportedHandles.join(', '); } else { handlesCell.textContent = 'N/A'; } row.appendChild(handlesCell); // Maintainer const maintainerCell = document.createElement('td'); if (pds.maintainer) { const link = document.createElement('a'); // sanitize maintainer by removing any '@' characters before using in URL and display const safeMaintainer = pds.maintainer.replace(/@/g, ''); link.href = `https://madebydanny.uk/followonbsky.html?did=${encodeURIComponent(safeMaintainer)}`; link.target = '_blank'; link.textContent = safeMaintainer; maintainerCell.appendChild(link); } else { maintainerCell.textContent = '—'; } row.appendChild(maintainerCell); // Server Location const locationCell = document.createElement('td'); if (pds.serverLocation) { locationCell.textContent = pds.serverLocation; } else { locationCell.textContent = '—'; } row.appendChild(locationCell); // Contact Email const emailCell = document.createElement('td'); if (pds.contactEmail) { const link = document.createElement('a'); link.href = `mailto:${pds.contactEmail}`; link.textContent = pds.contactEmail; emailCell.appendChild(link); } else { emailCell.textContent = '—'; } row.appendChild(emailCell); // Invite Code Required const inviteCell = document.createElement('td'); inviteCell.textContent = pds.inviteCodeRequired ? 'Yes' : 'No'; row.appendChild(inviteCell); // Terms of Service const tosCell = document.createElement('td'); if (pds.tosUrl) { const link = document.createElement('a'); link.href = pds.tosUrl; link.target = '_blank'; link.rel = 'noopener noreferrer'; link.textContent = 'Link'; tosCell.appendChild(link); } else { tosCell.textContent = '—'; } row.appendChild(tosCell); // Privacy Policy const privacyCell = document.createElement('td'); if (pds.privacyUrl) { const link = document.createElement('a'); link.href = pds.privacyUrl; link.target = '_blank'; link.rel = 'noopener noreferrer'; link.textContent = 'Link'; privacyCell.appendChild(link); } else { privacyCell.textContent = '—'; } row.appendChild(privacyCell); return row; }