diff --git a/index.html b/index.html index e4de5b1..78fc641 100644 --- a/index.html +++ b/index.html @@ -1625,8 +1625,34 @@ window.weatherThemes = { } // ============ Weather ============ - var WEATHER_LAT = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) || 48.5667; - var WEATHER_LON = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lon) || 13.4319; + // Default location: London, UK + var DEFAULT_LAT = 51.5074; + var DEFAULT_LON = -0.1278; + + var WEATHER_LAT = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) || DEFAULT_LAT; + var WEATHER_LON = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lon) || DEFAULT_LON; + + // Try browser geolocation if no config location set + function initBrowserGeolocation() { + if (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) return; + if (!navigator.geolocation) return; + navigator.geolocation.getCurrentPosition( + function(pos) { + WEATHER_LAT = pos.coords.latitude; + WEATHER_LON = pos.coords.longitude; + window.CONFIG.location = { lat: WEATHER_LAT, lon: WEATHER_LON }; + // Reload weather with new coordinates + if (typeof fetchWeather === 'function') fetchWeather(); + }, + function() { /* ignored - keep default */ }, + { timeout: 10000 } + ); + } + + // Get timezone offset based on user's local time + function getTimezoneOffsetMinutes() { + return new Date().getTimezoneOffset(); + } var weatherData = null; var WMO_ICONS = { @@ -1819,6 +1845,8 @@ window.weatherThemes = { if (debugEl && !(window.CONFIG && window.CONFIG.debug)) { debugEl.style.display = 'none'; } + // Try browser geolocation if no explicit location configured + initBrowserGeolocation(); animate(); tick();