PageSourceSearch

https://elfrente.com.co/assets/js/topbar-widgets.js?v=7fe77b792b

js elfrente.com.co collected 2026-09-24 23:50:11 UTC 2,571 bytes, 55 lines download raw bytes

1/* Topbar: temperatura de Bucaramanga (Open-Meteo) + TRM oficial (datos.gov.co).
2   Ambas APIs gratuitas, sin key, con CORS. Falla en silencio (oculta el widget). */
3(function () {
4  // ---- Clima ----
5  function weatherIcon(code) {
6    // WMO weather codes → emoji aproximado
7    if (code === 0) return '☀';
8    if (code <= 2) return '🌤';
9    if (code === 3) return '☁';
10    if (code >= 45 && code <= 48) return '🌫';
11    if (code >= 51 && code <= 67) return '🌦';
12    if (code >= 71 && code <= 77) return '🌨';
13    if (code >= 80 && code <= 82) return '🌧';
14    if (code >= 95) return '⛈';
15    return '☀';
16  }
17
18  async function loadWeather() {
19    const wrap = document.getElementById('tai-weather');
20    if (!wrap) return;
21    try {
22      const r = await fetch('https://api.open-meteo.com/v1/forecast?latitude=7.1254&longitude=-73.1198&current=temperature_2m,weather_code&timezone=America/Bogota');
23      const d = (await r.json()).current;
24      document.getElementById('tai-weather-temp').textContent = Math.round(d.temperature_2m) + '°';
25      document.getElementById('tai-weather-icon').textContent = weatherIcon(d.weather_code);
26      wrap.hidden = false;
27      const sep = document.querySelector('.tai-weather-sep'); if (sep) sep.hidden = false;
28    } catch (e) { console.warn('weather:', e); }
29  }
30
31  // ---- TRM ----
32  async function loadTRM() {
33    const wrap = document.getElementById('tai-trm');
34    if (!wrap) return;
35    try {
36      const r = await fetch('https://www.datos.gov.co/resource/32sa-8pi3.json?$order=vigenciadesde%20DESC&$limit=2');
37      const rows = await r.json();
38      if (!rows.length) return;
39      const hoy = parseFloat(rows[0].valor);
40      const ayer = rows[1] ? parseFloat(rows[1].valor) : hoy;
41      document.getElementById('tai-trm-val').textContent = '$' + hoy.toLocaleString('es-CO', { maximumFractionDigits: 0 });
42      const delta = ayer ? ((hoy - ayer) / ayer) * 100 : 0;
43      const deltaEl = document.getElementById('tai-trm-delta');
44      const arrow = delta > 0 ? '▲' : delta < 0 ? '▼' : '▬';
45      deltaEl.textContent = `${arrow} ${Math.abs(delta).toFixed(2)}%`;
46      deltaEl.classList.add(delta > 0 ? 'tai-trm-up' : delta < 0 ? 'tai-trm-down' : 'tai-trm-flat');
47      wrap.hidden = false;
48      const sep = document.querySelector('.tai-trm-sep'); if (sep) sep.hidden = false;
49    } catch (e) { console.warn('trm:', e); }
50  }
51
52  function init() { loadWeather(); loadTRM(); }
53  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
54  else init();
55})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.