document.addEventListener("DOMContentLoaded", function() { const statusDot = document.getElementById('dx-api-status-dot'); const statusText = document.getElementById('dx-api-status-text'); const activeCountEl = document.getElementById('dx-active-count'); const refreshBtn = document.getElementById('dx-refresh-btn'); if (!document.getElementById('dx-live-panel')) return; async function fetchLiveData(force = false) { if (statusDot && statusText) { statusDot.style.background = '#ff9800'; statusDot.style.boxShadow = '0 0 10px #ff9800'; statusText.textContent = 'Обновление...'; statusText.style.color = '#ff9800'; } if (force && refreshBtn) { refreshBtn.innerHTML = '⏳ Обновление...'; refreshBtn.style.opacity = '0.7'; refreshBtn.style.pointerEvents = 'none'; } try { const url = '/wp-admin/admin-ajax.php?action=get_live_dx' + (force ? '&force=1' : ''); const response = await fetch(url); const res = await response.json(); if (res.success && res.data && res.data.length > 0) { if (statusDot && statusText) { statusDot.style.background = '#4caf50'; statusDot.style.boxShadow = '0 0 10px #4caf50'; statusText.textContent = 'Актуально'; statusText.style.color = '#4caf50'; } document.querySelectorAll('.live-on-air').forEach(el => el.classList.remove('live-on-air')); document.querySelectorAll('.dx-live-btn').forEach(el => el.remove()); document.querySelectorAll('.gantt-bar.has-live-btn').forEach(el => el.classList.remove('has-live-btn')); let attempts = 0; const maxAttempts = 30; const checkInterval = setInterval(() => { attempts++; const ganttBars = document.querySelectorAll('.gantt-bar'); if (ganttBars.length > 0) { let matchedActiveCount = 0; ganttBars.forEach(bar => { let clone = bar.cloneNode(true); clone.querySelectorAll('.dx-live-btn').forEach(el => el.remove()); let callText = clone.textContent.trim().toUpperCase(); const streamData = res.data.find(item => item.call === callText); if (streamData) { // Создаем текстовую кнопку LIVE const btn = document.createElement('a'); btn.className = 'dx-live-btn'; btn.href = streamData.url; btn.target = '_blank'; btn.innerHTML = 'LIVE'; btn.onclick = (e) => e.stopPropagation(); bar.appendChild(btn); bar.classList.add('has-live-btn'); const now = new Date(); const nowUtc = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()); const qsoTime = new Date(streamData.time.replace(' ', 'T') + 'Z').getTime(); const diffMinutes = (nowUtc - qsoTime) / 1000 / 60; if (diffMinutes <= 10) { matchedActiveCount++; bar.classList.add('live-on-air'); bar.style.cursor = 'pointer'; bar.onclick = function() { window.open(streamData.url, '_blank'); }; let currentTitle = bar.getAttribute('data-title') || ''; if (!currentTitle.includes('В ЭФИРЕ')) { bar.setAttribute('data-title', currentTitle + ' 🟢 [В ЭФИРЕ. Клик для перехода]'); } } } }); if (activeCountEl) activeCountEl.textContent = matchedActiveCount; clearInterval(checkInterval); } else if (attempts >= maxAttempts) { if (activeCountEl) activeCountEl.textContent = '0'; clearInterval(checkInterval); } }, 500); } else { throw new Error('Пустые данные'); } } catch (error) { console.error('DX Live Error:', error); if (statusDot && statusText) { statusDot.style.background = '#f44336'; statusDot.style.boxShadow = '0 0 10px #f44336'; statusText.textContent = 'Не актуально'; statusText.style.color = '#f44336'; } if (activeCountEl) activeCountEl.textContent = '?'; } finally { if (force && refreshBtn) { refreshBtn.innerHTML = '🔄 Обновить'; refreshBtn.style.opacity = '1'; refreshBtn.style.pointerEvents = 'auto'; } } } setTimeout(() => fetchLiveData(false), 1000); if (refreshBtn) { refreshBtn.addEventListener('click', function() { fetchLiveData(true); }); } }); https://ru3dnn.ru/wp-sitemap-posts-post-1.xmlhttps://ru3dnn.ru/wp-sitemap-posts-page-1.xmlhttps://ru3dnn.ru/wp-sitemap-taxonomies-category-1.xmlhttps://ru3dnn.ru/wp-sitemap-users-1.xml