// API ключ от WeatherAPI const API_KEY = "485eff906f7d473b913104046250710"; // Yandex Metrika counter ID (замените на свой) const YM_COUNTER_ID = 104563496; // Замените на реальный ID счетчика // Функция для отправки событий в Yandex Metrika function ymSendEvent(eventName, params = {}) { if (typeof ym !== "undefined" && YM_COUNTER_ID !== "YOUR_COUNTER_ID") { ym(YM_COUNTER_ID, "reachGoal", eventName, params); console.log(`Yandex Metrika event: ${eventName}`, params); } } // Глобальные переменные для темы const themeButtons = { light: document.getElementById("theme-light"), auto: document.getElementById("theme-auto"), dark: document.getElementById("theme-dark"), }; const cityInput = document.getElementById("city"); const cityList = document.getElementById("city-list"); let searchTimeout = null; const getWeatherBtn = document.getElementById("get-weather"); const geolocationBtn = document.getElementById("geolocation-btn"); const timelapseContainer = document.getElementById("timelapse-container"); const currentWeatherDiv = document.getElementById("current-weather"); const currentTempEl = document.getElementById("current-temp"); const currentDescEl = document.getElementById("current-desc"); const currentHumidityEl = document.getElementById("current-humidity"); const currentWindEl = document.getElementById("current-wind"); // Глобальные переменные для координат пользователя (для fallback) let userLatitude = null; let userLongitude = null; // Глобальная переменная для Swiper let weatherSwiper; // Глобальные переменные для графиков let temperatureChart = null; let precipitationChart = null; // Функция поиска городов через API async function searchCities(query) { if (!query || query.length < 3) { cityList.innerHTML = ""; return; } try { const url = `https://api.weatherapi.com/v1/search.json?key=${API_KEY}&q=${encodeURIComponent( query )}`; const response = await fetch(url); if (!response.ok) { throw new Error(`API error: ${response.status}`); } const cities = await response.json(); // Ограничить до 10 результатов const limitedCities = cities.slice(0, 10); // Заполнить datalist cityList.innerHTML = limitedCities .map((city) => { const displayName = `${city.name}, ${city.region}, ${city.country}`; return `