/** * Spy Stations Mode * Number stations and diplomatic HF radio networks */ const SpyStations = (function() { // State let stations = []; let filteredStations = []; let activeFilters = { types: ['number', 'diplomatic'], countries: [], modes: [] }; // Country flag emoji map const countryFlags = { 'RU': '\u{1F1F7}\u{1F1FA}', 'CU': '\u{1F1E8}\u{1F1FA}', 'BG': '\u{1F1E7}\u{1F1EC}', 'CZ': '\u{1F1E8}\u{1F1FF}', 'EG': '\u{1F1EA}\u{1F1EC}', 'KP': '\u{1F1F0}\u{1F1F5}', 'TN': '\u{1F1F9}\u{1F1F3}', 'US': '\u{1F1FA}\u{1F1F8}', 'PL': '\u{1F1F5}\u{1F1F1}', 'IL': '\u{1F1EE}\u{1F1F1}', 'CN': '\u{1F1E8}\u{1F1F3}', 'MA': '\u{1F1F2}\u{1F1E6}', 'FR': '\u{1F1EB}\u{1F1F7}', 'RO': '\u{1F1F7}\u{1F1F4}', 'DZ': '\u{1F1E9}\u{1F1FF}' }; /** * Initialize the spy stations mode */ function init() { fetchStations(); checkTuneFrequency(); } /** * Fetch stations from the API */ async function fetchStations() { try { const response = await fetch('/spy-stations/stations'); const data = await response.json(); if (data.status === 'success') { stations = data.stations; initFilters(); applyFilters(); updateStats(); } } catch (err) { console.error('Failed to fetch spy stations:', err); } } /** * Initialize filter checkboxes */ function initFilters() { // Get unique countries and modes const countries = [...new Set(stations.map(s => JSON.stringify({name: s.country, code: s.country_code})))].map(s => JSON.parse(s)); const modes = [...new Set(stations.map(s => s.mode.split('/')[0]))].sort(); // Populate country filters const countryContainer = document.getElementById('countryFilters'); if (countryContainer) { countryContainer.innerHTML = countries.map(c => ` `).join(''); } // Populate mode filters const modeContainer = document.getElementById('modeFilters'); if (modeContainer) { modeContainer.innerHTML = modes.map(m => ` `).join(''); } // Set initial filter states activeFilters.countries = countries.map(c => c.code); activeFilters.modes = modes; } /** * Apply filters and render stations */ function applyFilters() { // Read type filters const typeNumber = document.getElementById('filterTypeNumber'); const typeDiplomatic = document.getElementById('filterTypeDiplomatic'); activeFilters.types = []; if (typeNumber && typeNumber.checked) activeFilters.types.push('number'); if (typeDiplomatic && typeDiplomatic.checked) activeFilters.types.push('diplomatic'); // Read country filters activeFilters.countries = []; document.querySelectorAll('#countryFilters input[data-country]:checked').forEach(cb => { activeFilters.countries.push(cb.dataset.country); }); // Read mode filters activeFilters.modes = []; document.querySelectorAll('#modeFilters input[data-mode]:checked').forEach(cb => { activeFilters.modes.push(cb.dataset.mode); }); // Apply filters filteredStations = stations.filter(s => { if (!activeFilters.types.includes(s.type)) return false; if (!activeFilters.countries.includes(s.country_code)) return false; const stationMode = s.mode.split('/')[0]; if (!activeFilters.modes.includes(stationMode)) return false; return true; }); renderStations(); updateStats(true); } /** * Render station cards */ function renderStations() { const container = document.getElementById('spyStationsGrid'); if (!container) return; if (filteredStations.length === 0) { container.innerHTML = `
No stations match your filters