import $ from 'jquery'; import * as JSX from './jsx'; var interval = null; function cacheWeather( result: any ) { const timestamp = new Date().getTime(); localStorage.setItem( "weather", JSON.stringify( result ) ); localStorage.setItem( "weather_timestamp", timestamp.toString() ); } function getWeatherCache() { const timestamp = localStorage.getItem( "weather_timestamp" ); if( !timestamp ) return null; if( parseInt( timestamp ) + 60 * 60 * 1000 < new Date().getTime() ) { localStorage.removeItem( "weather" ); localStorage.removeItem( "weather_timestamp" ); return null; } try { const res = JSON.parse( localStorage.getItem( "weather" ) ); return res; } catch( e ) { console.log( e ); return null; } } async function updateWeather() { let weather = getWeatherCache(); if( !weather ) { weather = await fetch( "https://api.open-meteo.com/v1/forecast?latitude=35.0647937&longitude=137.1784597¤t=temperature_2m,wind_speed_10m,relative_humidity_2m" ) weather = await weather.json(); cacheWeather( weather ); } $( "#temp" ).text( weather.current.temperature_2m ); $( "#wind" ).text( weather.current.wind_speed_10m ); $( "#humi" ).text( weather.current.relative_humidity_2m ); setTimeout( updateWeather, 60 * 60 * 1000 ); } function Weather() { setTimeout( updateWeather ); const weather = getWeatherCache(); if( weather && weather.current ) { const temp = weather.current.temperature_2m; const wind = weather.current.wind_speed_10m; const humi = weather.current.relative_humidity_2m; return