Schau mal in die Weather.js....
Code:
var postal;
var demoMode = false;
var enabled;
if (location.href.indexOf("LockBackground") == -1){
stylesheet = stylesheetWall;
iconSet = iconSetWall;
iconExt = iconExtWall;
enabled = enableWallpaper;
}else{
stylesheet = stylesheetLock;
iconSet = iconSetLock;
iconExt = iconExtLock;
enabled = enableLockScreen;
}
if(enabled == true){
if(iconSet == null || iconSet == 'null' || iconSet == ""){
var iconSet = stylesheet;
}
var headID = document.getElementsByTagName("head")[0];
var styleNode = document.createElement('link');
styleNode.type = 'text/css';
styleNode.rel = 'stylesheet';
styleNode.href = 'Stylesheets/'+stylesheet+'.css';
headID.appendChild(styleNode);
var scriptNode = document.createElement('script');
scriptNode.type = 'text/javascript';
scriptNode.src = 'Sources/'+source+'.js';
headID.appendChild(scriptNode);
}
function onLoad(){
if (enabled == true){
if (demoMode == true){
document.getElementById("weatherIcon").src="Icon Sets/"+iconSet+"/"+"cloudy1"+iconExt;
document.getElementById("city").innerText="Somewhere";
document.getElementById("desc").innerText="Partly Cloudy";
document.getElementById("temp").innerText="100º";
}else{
document.getElementById("weatherIcon").src="Icon Sets/"+iconSet+"/"+"dunno"+iconExt;
validateWeatherLocation(escape(locale).replace(/^%u/g, "%"), setPostal)
}
}else{
document.getElementsByTagName("body")[0].innerText='';
}
}
function convertTemp(num)
{
if (isCelsius == true)
return Math.round ((num - 32) * 5 / 9);
else
return num;
}
function setPostal(obj){
if (obj.error == false){
if(obj.cities.length > 0){
postal = escape(obj.cities[0].zip).replace(/^%u/g, "%")
document.getElementById("WeatherContainer").className = "";
weatherRefresherTemp();
}else{
document.getElementById("city").innerText="Not Found";
document.getElementById("WeatherContainer").className = "errorLocaleNotFound";
}
}else{
document.getElementById("city").innerText=obj.errorString;
document.getElementById("WeatherContainer").className = "errorLocaleValidate";
setTimeout('validateWeatherLocation(escape(locale).replace(/^%u/g, "%"), setPostal)', Math.round(1000*60*5));
}
}
function dealWithWeather(obj){
if (obj.error == false){
document.getElementById("city").innerText=obj.city;
document.getElementById("desc").innerText=obj.description.toLowerCase();
translatedesc=obj.description.toLowerCase();
// ************************************Dutch translation by wim66 modmyi.com***********************************
// ******* TRANSLATE DESCRIPTION ***************************
// ******* ALWAYS USE SMALL CAPS (i.e 'sunny') ***************************
if (translatedesc=='description') { document.getElementById("desc").innerHTML='Your Description'; }
if (translatedesc=='tornado') { document.getElementById("desc").innerHTML='Tornado!'; }
if (translatedesc=='tropical storm') { document.getElementById("desc").innerHTML='Tropischer Sturm'; }
if (translatedesc=='hurricane') { document.getElementById("desc").innerHTML='Hurrikan!'; }
if (translatedesc=='severe thunderstorms') { document.getElementById("desc").innerHTML='Sturm/Gewitter'; }
if (translatedesc=='thunderstorms') { document.getElementById("desc").innerHTML='Gewitter'; }
if (translatedesc=='mixed rain and snow') { document.getElementById("desc").innerHTML='Regen/Schnee'; }
if (translatedesc=='mixed rain and sleet') { document.getElementById("desc").innerHTML='Regen/Graupel'; }
if (translatedesc=='mixed snow and sleet') { document.getElementById("desc").innerHTML='Schnee/Graupel'; }
if (translatedesc=='freezing drizzle') { document.getElementById("desc").innerHTML='gefr Nieselregen'; }
if (translatedesc=='drizzle') { document.getElementById("desc").innerHTML='Nieselregen'; }
if (translatedesc=='freezing rain') { document.getElementById("desc").innerHTML='Eisregen'; }
if (translatedesc=='showers') { document.getElementById("desc").innerHTML='Schauer'; }
if (translatedesc=='snow flurries') { document.getElementById("desc").innerHTML='Schneegestoeber'; }
if (translatedesc=='light snow showers') { document.getElementById("desc").innerHTML='Leichter Schneefall'; }
if (translatedesc=='blowing snow') { document.getElementById("desc").innerHTML='Schneetreiben'; }
if (translatedesc=='snow') { document.getElementById("desc").innerHTML='Schnee'; }
if (translatedesc=='hail') { document.getElementById("desc").innerHTML='Hagel'; }
if (translatedesc=='sleet') { document.getElementById("desc").innerHTML='Schneeregen'; }
if (translatedesc=='dust') { document.getElementById("desc").innerHTML='Trueb'; }
if (translatedesc=='foggy') { document.getElementById("desc").innerHTML='Neblig'; }
if (translatedesc=='haze') { document.getElementById("desc").innerHTML='Dunstig'; }
if (translatedesc=='smoky') { document.getElementById("desc").innerHTML='Verraucht'; }
if (translatedesc=='blustery') { document.getElementById("desc").innerHTML='Stuermisch'; }
if (translatedesc=='mostly cloudy/windy') { document.getElementById("desc").innerHTML='Wolkig/Windig'; }
if (translatedesc=='windy') { document.getElementById("desc").innerHTML='Windig'; }
if (translatedesc=='cold') { document.getElementById("desc").innerHTML='Kalt'; }
if (translatedesc=='cloudy') { document.getElementById("desc").innerHTML='Bewoelkt'; }
if (translatedesc=='mostly cloudy') { document.getElementById("desc").innerHTML='Ueberw Bewoelkt'; }
if (translatedesc=='partly cloudy') { document.getElementById("desc").innerHTML='Teilw Bewoelkt'; }
if (translatedesc=='clear') { document.getElementById("desc").innerHTML='Klar'; }
if (translatedesc=='sunny') { document.getElementById("desc").innerHTML='Sonnig'; }
if (translatedesc=='mist') { document.getElementById("desc").innerHTML='Nebel'; }
if (translatedesc=='rain') { document.getElementById("desc").innerHTML='Regen'; }
if (translatedesc=='fair') { document.getElementById("desc").innerHTML='Klar'; }
if (translatedesc=='fog') { document.getElementById("desc").innerHTML='Nebel'; }
if (translatedesc=='mixed rain and hail') { document.getElementById("desc").innerHTML='Regen/Hagel'; }
if (translatedesc=='hot') { document.getElementById("desc").innerHTML='Heiss'; }
if (translatedesc=='isolated thunderstorms') { document.getElementById("desc").innerHTML='Vereinz Gewitter'; }
if (translatedesc=='scattered thunderstorms') { document.getElementById("desc").innerHTML='Einzelne Gewitter'; }
if (translatedesc=='scattered showers') { document.getElementById("desc").innerHTML='Einzelne Schauer'; }
if (translatedesc=='heavy snow') { document.getElementById("desc").innerHTML='Starker Schneefall'; }
if (translatedesc=='scattered snow showers') { document.getElementById("desc").innerHTML='Einz Schneeschauer'; }
if (translatedesc=='partly cloudy') { document.getElementById("desc").innerHTML='Teilw Bewoelkt'; }
if (translatedesc=='thundershowers') { document.getElementById("desc").innerHTML='Gewitter'; }
if (translatedesc=='snow showers') { document.getElementById("desc").innerHTML='Schneeschauer'; }
if (translatedesc=='isolated thundershowers') { document.getElementById("desc").innerHTML='Vereinz Gewitter'; }
if (translatedesc=='light rain shower') { document.getElementById("desc").innerHTML='Schauer/Leicht'; }
if (translatedesc=='not available') { document.getElementById("desc").innerHTML='Nicht Verfuegbar'; }
if (translatedesc=='showers in the vicinity') { document.getElementById("desc").innerHTML='Umliegende Schauer'; }
if (translatedesc=='partly sunny') { document.getElementById("desc").innerHTML='Teils Sonnig'; }
if (translatedesc=='ground fog') { document.getElementById("desc").innerHTML='Bodennebel'; }
if (translatedesc=='light drizzle') { document.getElementById("desc").innerHTML='Nieselregen'; }
if (translatedesc=='light rain') { document.getElementById("desc").innerHTML='Leichter Regen'; }
if (translatedesc=='light snow') { document.getElementById("desc").innerHTML='Leichter Schnee'; }
if (translatedesc=='rain and snow') { document.getElementById("desc").innerHTML='Schneeregen'; }
// ******* END TRANSLATE DESCRIPTION ***************************
var MiniIcons =
[
"tstorm3", //0 tornado
"tstorm3", //1 tropical storm
"tstorm3", //2 hurricane
"tstorm3", //3 severe thunderstorms
"tstorm2", //4 thunderstorms
"sleet", //5 mixed rain and snow
"sleet", //6 mixed rain and sleet
"sleet", //7 mixed snow and sleet
"sleet", //8 freezing drizzle
"light_rain", //9 drizzle
"sleet", //10 freezing rain
"shower2", //11 showers
"shower5", //12 showers
"snow1", //13 snow flurries
"snow2", //14 light snow showers
"snow4", //15 blowing snow
"snow4", //16 snow
"hail", //17 hail
"sleet", //18 sleet
"mist", //19 dust
"fog", //20 foggy
"haze", //21 haze
"haze", //22 smoky
"cloudy1", //23 blustery
"wind", //24 windy
"overcast", //25 cold
"cloudy4", //26 cloudy
"cloudy3_night", //27 mostly cloudy (night)
"cloudy3", //28 mostly cloudy (day)
"cloudy2_night", //29 partly cloudy (night)
"cloudy2", //30 partly cloudy (day)
"sunny_night", //31 clear (night)
"sunny", //32 sunny
"fair_night", //33 fair (night)
"fair", //34 fair (day)
"hail", //35 mixed rain and hail
"sunny", //36 hot
"tstorm1", //37 isolated thunderstorms
"tstorm2", //38 scattered thunderstorms
"tstorm2", //39 scattered thunderstorms
"tstorm2", //40 scattered showers
"snow5", //41 heavy snow
"snow3", //42 scattered snow showers
"snow5", //43 heavy snow
"cloudy1", //44 partly cloudy
"storm1", //45 thundershowers
"snow2", //46 snow showers
"tstorm1", //47 isolated thundershowers
"dunno",
//3200 not available
]
if(useRealFeel == true){
tempValue = convertTemp(obj.realFeel);
}else{
tempValue = convertTemp(obj.temp)
}
document.getElementById("temp").innerText=tempValue+"º";
document.getElementById("weatherIcon").src="Icon Sets/"+iconSet+"/"+MiniIcons[obj.icon]+iconExt;
document.getElementById("WeatherContainer").className = "";
}else{
document.getElementById("WeatherContainer").className = "errorWeatherDataFetch";
}
}
function weatherRefresherTemp(){ //this is one of my nice works so far... dont forget to find me and thank me "ibnyaffa".
fetchWeatherData(dealWithWeather,postal);
setTimeout(weatherRefresherTemp, 60*1000*updateInterval);
}
function constructError (string)
{
return {error:true, errorString:string};
}
function findChild (element, nodeName)
{
var child;
for (child = element.firstChild; child != null; child = child.nextSibling)
{
if (child.nodeName == nodeName)
return child;
}
return null;
}
function fetchWeatherData (callback, zip)
{
url="http://weather.yahooapis.com/forecastrss?u=f&p=" //u=Farenheit, because accuWeather sucks
var xml_request = new XMLHttpRequest();
xml_request.onload = function(e) {xml_loaded(e, xml_request, callback);}
xml_request.overrideMimeType("text/xml");
xml_request.open("GET", url+zip);
xml_request.setRequestHeader("Cache-Control", "no-cache");
xml_request.send(null);
return xml_request;
}
function xml_loaded (event, request, callback)
{
if (request.responseXML)
{
var obj = {error:false, errorString:null};
var effectiveRoot = findChild(findChild(request.responseXML, "rss"), "channel");
obj.city = findChild(effectiveRoot, "yweather:location").getAttribute("city");
obj.realFeel = findChild(effectiveRoot, "yweather:wind").getAttribute("chill");//Only accounts for windChill
conditionTag = findChild(findChild(effectiveRoot, "item"), "yweather:condition");
obj.temp = conditionTag.getAttribute("temp");
obj.icon = conditionTag.getAttribute("code");
obj.description = conditionTag.getAttribute("text");
callback (obj);
}else{
callback ({error:true, errorString:"XML request failed. no responseXML"});
}
}
function validateWeatherLocation (location, callback)
{
var obj = {error:false, errorString:null, cities: new Array};
obj.cities[0] = {zip: location}; //Not very clever, are we?
callback (obj);
}