// === REMPLACEMENT LOGO NAVBAR PAR DELTA+ === (function() { function replaceLogo() { var img = document.querySelector('.HeaderLogo img'); if (!img) return false; // Sauvegarder l'original pour le script global if (!window._originalLogoSrc && img.src.indexOf('DPL.png') === -1) { window._originalLogoSrc = img.src; window._originalLogoAlt = img.alt; } if (img.src.indexOf('DPL.png') !== -1) return true; img.src = 'https://uploads.deltafm.fr/logos/DPL.png'; img.alt = 'Delta+'; return true; } var attempts = 0; var timer = setInterval(function() { attempts++; if (replaceLogo() || attempts > 20) clearInterval(timer); }, 500); })(); // === AUTO-SELECTION RADIO : lit le select et matche avec le player === (function() { function detectActiveStation() { var radioToggle = document.querySelector('.PlayerRadio > .dropdown-toggle img, .PlayerRadio > button img'); if (radioToggle) { var alt = (radioToggle.alt || '').trim(); if (alt) return alt; } var toggle = document.querySelector('.PlayerSources .dropdown-toggle, .PlayerSources .nav-link'); if (toggle) { var text = toggle.textContent.trim(); if (text) return text; } return ''; } function normalize(str) { return (str || '').trim().toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z0-9]/g, ''); } function autoSelectRadio() { var select = document.querySelector('#radio, select[name="radio"], .TitlesSearchRadio select'); if (!select) return false; var station = detectActiveStation(); if (!station) return false; var stationNorm = normalize(station); var options = select.querySelectorAll('option'); var bestMatch = null, bestScore = 0; options.forEach(function(opt) { var optText = normalize(opt.textContent); if (!opt.value || !optText) return; if (optText === stationNorm) { bestMatch = opt; bestScore = 100; return; } if (optText.indexOf(stationNorm) !== -1 && 80 > bestScore) { bestMatch = opt; bestScore = 80; return; } if (stationNorm.indexOf(optText) !== -1 && 70 > bestScore) { bestMatch = opt; bestScore = 70; return; } var common = 0; (stationNorm.match(/.{2,}/g) || []).forEach(function(w) { if (optText.indexOf(w) !== -1) common++; }); if (common > 0 && common * 20 > bestScore) { bestMatch = opt; bestScore = common * 20; } }); if (!bestMatch || bestScore < 20) return false; if (select.value === bestMatch.value) return true; select.value = bestMatch.value; select.dispatchEvent(new Event('change', { bubbles: true })); select.dispatchEvent(new Event('input', { bubbles: true })); var form = select.closest('form'); if (form) { var submitBtn = form.querySelector('button[type="submit"], input[type="submit"], .form-footer button'); if (submitBtn) setTimeout(function() { submitBtn.click(); }, 200); else setTimeout(function() { form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })); }, 200); } return true; } function init() { var attempts = 0; var timer = setInterval(function() { attempts++; if (autoSelectRadio() || attempts > 20) clearInterval(timer); }, 500); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init(); })();