/* === PortAI Weather Widget v2 — Light/Dark adaptive === */ (function(){ var weatherCodes={0:'快晴',1:'晴れ',2:'曇りがち',3:'曇り',45:'霧',48:'霧氷',51:'霧雨',53:'霧雨',55:'霧雨',56:'着氷性霧雨',61:'小雨',63:'雨',65:'大雨',66:'着氷性雨',71:'小雪',73:'雪',75:'大雪',77:'霧雪',80:'にわか雨',81:'にわか雨',82:'豪雨',85:'にわか雪',86:'にわか大雪',95:'雷雨',96:'雹を伴う雷雨',99:'雹を伴う雷雨'}; var weatherIcons={0:'☀️',1:'🌤',2:'⛅',3:'☁️',45:'🌫',48:'🌫',51:'🌧',53:'🌧',55:'🌧',61:'🌧',63:'🌧',65:'🌧',71:'🌨',73:'🌨',80:'🌦',81:'🌦',82:'🌦',95:'⛈',96:'⛈',99:'⛈'}; function renderWeather(container){ var lat=container.dataset.lat; var lng=container.dataset.lng; var port=container.dataset.port||''; if(!lat||!lng)return; container.innerHTML='
天気情報を取得中...
'; var url='https://api.open-meteo.com/v1/forecast?latitude='+lat+'&longitude='+lng +'¤t=temperature_2m,weather_code,wind_speed_10m,wind_direction_10m,relative_humidity_2m' +'&daily=weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max' +'&timezone=Asia/Tokyo&forecast_days=3'; fetch(url).then(function(r){return r.json()}).then(function(data){ var c=data.current||{}; var d=data.daily||{}; var code=c.weather_code||0; var temp=c.temperature_2m; var wind=c.wind_speed_10m; var humidity=c.relative_humidity_2m; var icon=weatherIcons[code]||'🌤'; var desc=weatherCodes[code]||'不明'; var windMs=(wind/3.6).toFixed(1); var windStatus=''; var windColor='#16a34a'; if(wind>=54){windStatus='⚠ 欠航の可能性';windColor='#dc2626';} else if(wind>=36){windStatus='△ 揺れに注意';windColor='#d97706';} else{windStatus='○ 通常運航';windColor='#16a34a';} var html='
'; /* Header */ html+='
'; html+=''; html+=''+port+''; html+='Open-Meteo'; html+='
'; /* Current weather */ html+='
'; html+=''+icon+''; html+='
'; html+='
'+temp+'°C
'; html+='
'+desc+' | 湿度 '+humidity+'%
'; html+='
'; html+='
'; /* Wind & ferry status */ html+='
'; html+='
'; html+='
風速
'; html+='
'+wind+' km/h ('+windMs+' m/s)
'; html+='
'; html+='
'; html+='
高速船運航
'; html+='
'+windStatus+'
'; html+='
'; html+='
'; /* 3-day forecast */ html+='
'; var days=['日','月','火','水','木','金','土']; for(var i=0;i<3&&d.time&&i'; html+='
'+dIcon+'
'; html+='
'+d.temperature_2m_min[i]+'〜'+d.temperature_2m_max[i]+'°
'; html+='
☔ '+rain+'%
'; html+='
'; } html+='
'; html+=''; container.innerHTML=html; }).catch(function(){ container.innerHTML='
天気情報を取得できませんでした
'; }); } function init(){ document.querySelectorAll('.portai-weather').forEach(renderWeather); } if(document.readyState==='loading'){ document.addEventListener('DOMContentLoaded',init); }else{ init(); } })();