-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
252 lines (217 loc) · 9.79 KB
/
Copy pathscript.js
File metadata and controls
252 lines (217 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/**
* Radio ECCI — script.js
* Liquid Glass · Tema claro/oscuro · Radio Browser API
*/
document.addEventListener('DOMContentLoaded', function () {
/* =============================================
1. AÑO EN FOOTER
============================================= */
var yr = document.getElementById('year');
if (yr) yr.textContent = new Date().getFullYear();
/* =============================================
2. TEMA CLARO / OSCURO
============================================= */
var html = document.documentElement;
var themeToggle = document.getElementById('themeToggle');
var themeIcon = document.getElementById('themeIcon');
// Leer preferencia guardada o del sistema
var saved = localStorage.getItem('reccitheme');
var prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
var currentTheme = saved || (prefersDark ? 'dark' : 'light');
applyTheme(currentTheme);
function applyTheme(theme) {
html.setAttribute('data-theme', theme);
themeIcon.textContent = theme === 'dark' ? '☀️' : '🌙';
themeToggle.setAttribute('aria-label', theme === 'dark' ? 'Cambiar a tema claro' : 'Cambiar a tema oscuro');
try { localStorage.setItem('reccitheme', theme); } catch (e) { }
}
if (themeToggle) {
themeToggle.addEventListener('click', function () {
var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
applyTheme(next);
});
}
// Escuchar cambios del sistema
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function (e) {
if (!localStorage.getItem('reccitheme')) {
applyTheme(e.matches ? 'dark' : 'light');
}
});
/* =============================================
3. MENÚ HAMBURGUESA
============================================= */
var menuToggle = document.getElementById('menuToggle');
var navMenu = document.getElementById('nav-menu');
if (menuToggle && navMenu) {
menuToggle.addEventListener('click', function () {
var open = menuToggle.getAttribute('aria-expanded') === 'true';
menuToggle.setAttribute('aria-expanded', String(!open));
navMenu.classList.toggle('open', !open);
document.body.style.overflow = !open ? 'hidden' : '';
});
navMenu.querySelectorAll('a').forEach(function (a) {
a.addEventListener('click', function () {
menuToggle.setAttribute('aria-expanded', 'false');
navMenu.classList.remove('open');
document.body.style.overflow = '';
});
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && navMenu.classList.contains('open')) {
menuToggle.setAttribute('aria-expanded', 'false');
navMenu.classList.remove('open');
document.body.style.overflow = '';
menuToggle.focus();
}
});
// Cerrar al hacer clic fuera
document.addEventListener('click', function (e) {
if (navMenu.classList.contains('open') &&
!navMenu.contains(e.target) &&
!menuToggle.contains(e.target)) {
menuToggle.setAttribute('aria-expanded', 'false');
navMenu.classList.remove('open');
document.body.style.overflow = '';
}
});
}
/* =============================================
4. HEADER — sombra al scroll
============================================= */
var siteHeader = document.getElementById('siteHeader');
if (siteHeader) {
window.addEventListener('scroll', function () {
siteHeader.style.boxShadow = window.scrollY > 12
? '0 4px 30px rgba(0,0,0,0.25)'
: 'none';
}, { passive: true });
}
/* =============================================
5. NAV ACTIVO con IntersectionObserver
============================================= */
var sections = document.querySelectorAll('section[id]');
var navLinks = document.querySelectorAll('#nav-menu a');
if ('IntersectionObserver' in window && navLinks.length) {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
var id = '#' + entry.target.id;
navLinks.forEach(function (link) {
var active = link.getAttribute('href') === id;
link.setAttribute('aria-current', active ? 'true' : 'false');
});
}
});
}, { rootMargin: '-50% 0px -50% 0px' });
sections.forEach(function (s) { io.observe(s); });
}
/* =============================================
6. REPRODUCTOR — Salsa Radio (streams hardcodeados)
Sin API key · Sin dependencias externas
Lista de fallbacks HTTPS: si uno falla, prueba el siguiente
============================================= */
// Streams HTTPS de salsa conocidos y confiables
var STATIONS = [
{ name: 'Salsa Total', tags: 'Salsa · Cumbia · Latino', url: 'https://stream.zeno.fm/yn65m6v4g8zuv' },
{ name: 'Radio Latina', tags: 'Salsa · Merengue · Bachata', url: 'https://stream.zeno.fm/fg8yjmxrp0zuv' },
{ name: 'Tropicana CO', tags: 'Salsa · Tropical · Colombia', url: 'https://playerservices.streamtheworld.com/api/livestream-redirect/TROPICANA_SC' },
{ name: 'La Salsa+', tags: 'Salsa dura · Clásica', url: 'https://stream.zeno.fm/3mhzxq6nv8zuv' }
];
var stIdx = 0; // índice del stream actual
var playing = false;
var audio = document.getElementById('radioAudio');
var btnPlay = document.getElementById('btnPlay');
var volRange = document.getElementById('volumeRange');
var stName = document.getElementById('stationName');
var stTags = document.getElementById('stationTags');
var stStatus = document.getElementById('playerStatus');
var liveTag = document.getElementById('liveTag');
var waveEl = document.getElementById('waveContainer');
var iconPlay = document.getElementById('iconPlay');
var iconPause = document.getElementById('iconPause');
if (!audio || !btnPlay) return;
audio.volume = parseFloat(volRange ? volRange.value : 0.8);
/* Cargar un stream por índice */
function loadStream(idx) {
stIdx = idx % STATIONS.length;
var s = STATIONS[stIdx];
audio.src = s.url;
if (stName) stName.textContent = s.name;
if (stTags) stTags.textContent = s.tags;
if (stStatus) stStatus.textContent = 'Cargando…';
}
/* Intentar reproducir; si falla probar el siguiente fallback */
function tryPlay() {
if (stIdx >= STATIONS.length) {
if (stStatus) stStatus.textContent = 'Sin streams disponibles ahora';
setPlaying(false);
return;
}
if (stStatus) stStatus.textContent = 'Conectando…';
var p = audio.play();
if (p) {
p.catch(function (e) {
console.warn('Stream', STATIONS[stIdx].name, 'fallo:', e.name);
if (e.name === 'NotAllowedError') {
// Autoplay bloqueado por el navegador — es OK, esperar clic
if (stStatus) stStatus.textContent = 'Presiona ▶ para reproducir';
setPlaying(false);
} else {
// Stream no funciona → siguiente fallback
loadStream(stIdx + 1);
tryPlay();
}
});
}
}
/* Estado visual */
function setPlaying(on) {
playing = on;
if (iconPlay) iconPlay.style.display = on ? 'none' : 'block';
if (iconPause) iconPause.style.display = on ? 'block' : 'none';
btnPlay.setAttribute('aria-label', on ? 'Pausar' : 'Reproducir');
btnPlay.setAttribute('aria-pressed', on ? 'true' : 'false');
if (waveEl) waveEl.classList.toggle('playing', on);
if (liveTag) liveTag.style.display = on ? 'flex' : 'none';
}
/* Eventos del audio */
audio.addEventListener('playing', function () {
setPlaying(true);
if (stStatus) stStatus.textContent = 'En vivo';
});
audio.addEventListener('waiting', function () {
if (stStatus) stStatus.textContent = 'Buffering…';
});
audio.addEventListener('pause', function () {
setPlaying(false);
if (stStatus) stStatus.textContent = 'En pausa';
});
audio.addEventListener('error', function () {
if (playing) {
// Error de red en mitad de la reproducción → siguiente fallback
if (stStatus) stStatus.textContent = 'Error — buscando alternativa…';
loadStream(stIdx + 1);
tryPlay();
} else {
if (stStatus) stStatus.textContent = 'Error de stream';
}
});
/* Botón Play / Pause */
btnPlay.addEventListener('click', function () {
if (!audio.paused && !audio.ended) {
audio.pause();
} else {
if (!audio.src) loadStream(0);
tryPlay();
}
});
/* Volumen */
if (volRange) {
volRange.addEventListener('input', function () {
audio.volume = parseFloat(this.value);
});
}
/* Cargar el primer stream al iniciar (sin reproducir — esperar clic del usuario) */
loadStream(0);
if (stStatus) stStatus.textContent = 'Listo — presiona ▶';
});