-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreallysimpleweather-1.0.0.min.js
More file actions
1 lines (1 loc) · 3.49 KB
/
reallysimpleweather-1.0.0.min.js
File metadata and controls
1 lines (1 loc) · 3.49 KB
1
var reallySimpleWeather={getAltTemp:function(a,b){return"f"===a?Math.round(5/9*(b-32)):Math.round(1.8*b+32)},weather:function(a){a=a;var b=new Date,c="https://query.yahooapis.com/v1/public/yql?format=json&rnd="+b.getFullYear()+b.getMonth()+b.getDay()+b.getHours()+"&diagnostics=true&q=";if(""!==a.location){var d="";d=/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/.test(a.location)?"("+a.location+")":a.location,c+="select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='"+d+"') and u='"+a.unit+"'"}else{if(""===a.woeid)return a.error("Could not retrieve weather due to an invalid location."),!1;c+="select * from weather.forecast where woeid="+a.woeid+" and u='"+a.unit+"'"}var e=new XMLHttpRequest;return e.open("GET",encodeURI(c)),e.send(null),e.onreadystatechange=function(){var b=4,c=200;if(e.readyState===b){if(e.status===c)var d=JSON.parse(e.responseText);var h,f=d.query.results.channel,g={},i=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"],j="https://s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png";g.title=f.item.title,g.temp=f.item.condition.temp,g.code=f.item.condition.code,g.todayCode=f.item.forecast[0].code,g.currently=f.item.condition.text,g.high=f.item.forecast[0].high,g.low=f.item.forecast[0].low,g.text=f.item.forecast[0].text,g.humidity=f.atmosphere.humidity,g.pressure=f.atmosphere.pressure,g.rising=f.atmosphere.rising,g.visibility=f.atmosphere.visibility,g.sunrise=f.astronomy.sunrise,g.sunset=f.astronomy.sunset,g.description=f.item.description,g.city=f.location.city,g.country=f.location.country,g.region=f.location.region,g.updated=f.item.pubDate,g.link=f.item.link,g.units={temp:f.units.temperature,distance:f.units.distance,pressure:f.units.pressure,speed:f.units.speed},g.wind={chill:f.wind.chill,direction:i[Math.round(f.wind.direction/22.5)],speed:f.wind.speed},f.item.condition.temp<80&&f.atmosphere.humidity<40?g.heatindex=-42.379+2.04901523*f.item.condition.temp+10.14333127*f.atmosphere.humidity-.22475541*f.item.condition.temp*f.atmosphere.humidity-6.83783*Math.pow(10,-3)*Math.pow(f.item.condition.temp,2)-5.481717*Math.pow(10,-2)*Math.pow(f.atmosphere.humidity,2)+1.22874*Math.pow(10,-3)*Math.pow(f.item.condition.temp,2)*f.atmosphere.humidity+8.5282*Math.pow(10,-4)*f.item.condition.temp*Math.pow(f.atmosphere.humidity,2)-1.99*Math.pow(10,-6)*Math.pow(f.item.condition.temp,2)*Math.pow(f.atmosphere.humidity,2):g.heatindex=f.item.condition.temp,"3200"==f.item.condition.code?(g.thumbnail=j,g.image=j):(g.thumbnail="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+f.item.condition.code+"ds.png",g.image="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+f.item.condition.code+"d.png"),g.alt={temp:reallySimpleWeather.getAltTemp(a.unit,f.item.condition.temp),high:reallySimpleWeather.getAltTemp(a.unit,f.item.forecast[0].high),low:reallySimpleWeather.getAltTemp(a.unit,f.item.forecast[0].low)},"f"===a.unit?g.alt.unit="c":g.alt.unit="f",g.forecast=[];for(var k=0;k<f.item.forecast.length;k++)h=f.item.forecast[k],h.alt={high:reallySimpleWeather.getAltTemp(a.unit,f.item.forecast[k].high),low:reallySimpleWeather.getAltTemp(a.unit,f.item.forecast[k].low)},"3200"==f.item.forecast[k].code?(h.thumbnail=j,h.image=j):(h.thumbnail="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+f.item.forecast[k].code+"ds.png",h.image="https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/"+f.item.forecast[k].code+"d.png"),g.forecast.push(h);a.success(g)}else a.error("Yahoo is having a problem sending the latest weather. Please try again.")},this}};