|
Post by Wormopolis on Jul 21, 2009 19:04:32 GMT -8
Browser Tested: IE and FF placement: footer (wherever you want it to show)
Creates a pseudo-random selection from an array of weather types. There are 2 arrays, one for images, and one for influence.
how influence works:
The array sets up each month with a short list of weather types you want to appear in that month. If you want a certain weather type to appear more often, just add it in more. if you want all weather types to have the same chance of being picked, just include them once.
The code will insert your image, and the date into a div with id="weather" that you can place anywhere on your page, with the stipulation that the div appears before the code is ran.
code:
<script type="text/javascript"> <!-- // Pseudo-Random weather generator - v1.63 // By Wormopolis - [url]wormocodes.proboards.com[/url] // Keep Header Intact
var weatherImageArray = [ ["sunny", "http://i197.photobucket.com/albums/aa250/WORMOPOLIS/sunny.jpg"], ["rainy", "http://i197.photobucket.com/albums/aa250/WORMOPOLIS/rainy.jpg"], ["windy", "http://i197.photobucket.com/albums/aa250/WORMOPOLIS/windy.jpg"], ["snowing", "http://i197.photobucket.com/albums/aa250/WORMOPOLIS/snowing.jpg"], ["storming","http://i197.photobucket.com/albums/aa250/WORMOPOLIS/storming.jpg"], ["scorching","http://i197.photobucket.com/albums/aa250/WORMOPOLIS/scorching.jpg"] //no comma last entry ];
var weatherInfluenceArray = [ // month, list of weather types seperated by commas. repeat weather types if you want to influence results ["January","sunny,sunny,snowing,snowing,snowing,windy"], ["February","windy,sunny,snowing,snowing,snowing,windy,rainy"], ["March","snowing,rainy,rainy,sunny,windy,rainy"], ["April","rainy,rainy,sunny,sunny,windy"], ["May","rainy,sunny,sunny,windy,storming,sunny"], ["June","rainy,sunny,sunny,sunny,storming,windy,storming"], ["July","sunny,scorching,windy,rainy,scorching,storming"], ["August","sunny,scorching,scorching,storming,scorching"], ["September","sunny,windy,windy,rainy,scorching"], ["October","sunny,windy,windy,snowing,windy,snowing"], ["November","sunny,windy,snowing,windy"], ["December","sunny,snowing,snowing,windy,snowing"] //no comma here ];
var putDateBelowImage=true; //set true or false var putWeatherTitleBelowImage=true; //set true or false var putImageTitleOnHover=true; //set true or false var hoursAdjust=0; //if you want to adjust the day change by positive or negative hours, set 0 if not
// no need to edit below; if (!location.href.match(/noweather/)) { var dt=new Date(), et=new Date(); dt.setMinutes(dt.getMinutes() - dt.getTimezoneOffset()); dt.setHours(dt.getHours()+hoursAdjust); et.setHours(et.getHours()+hoursAdjust); var dayseed=Math.floor(dt.getTime()/(1000*60*60*24)); dayseed=Math.floor(Math.abs(Math.cos(dayseed)*dayseed)); sel=et.getMonth(); keepday=et.getDate(); keepmonth=weatherInfluenceArray[sel][0]; var weatherTypes = weatherInfluenceArray[sel][1]; monthWeatherArray=weatherTypes.split(','); pseudoRandomNumber=dayseed%monthWeatherArray.length; dailyWeather=monthWeatherArray[pseudoRandomNumber]; for (w=0;w<weatherImageArray.length; w++) if (weatherImageArray[w][0]==dailyWeather) keep=weatherImageArray[w][1]; suff=(keepday.toString().substr(keepday.toString().length-1)); suff=((keepday>10 && keepday< 20)?'th':suff=='1'?'st':suff=='2'?'nd':suff=='3'?'rd':'th'); var datelabel=document.createTextNode(keepmonth+" "+keepday+suff); var WTlabel=document.createTextNode(dailyWeather); dispImg=document.createElement('img'); dispImg.src=keep; dispImg.border=0; if (putImageTitleOnHover) dispImg.title=dailyWeather; document.getElementById('weather').appendChild(dispImg); document.getElementById('weather').appendChild(document.createElement('br'));
if (putWeatherTitleBelowImage) { document.getElementById('weather').appendChild(WTlabel); document.getElementById('weather').appendChild(document.createElement('br')); }
if (putDateBelowImage) document.getElementById('weather').appendChild(datelabel);
document.getElementById('weather').style.display=""; } // --> </script>
Live Preview: top of this thread
|
|
|
Post by Wormopolis on Nov 2, 2009 8:27:53 GMT -8
fixed a small glitch in the "st/nd/rd/th" nomenclature that comes after the date.
|
|
Jai'byrd
Not New Member
"Weirdoes don't die; they just get hit by buses!"[Sj1:0]
Posts: 2
Jai'byrd said 0 great things
|
Post by Jai'byrd on Sept 6, 2010 11:51:11 GMT -8
I love this code, but suddenly it's not working on my site (after it had been working for quite a happy while): shataksvigil.proboards.com/index.cgiDid I bork something up? Thank you and I apologize if this isn't the place for this question...
|
|
|
Post by Wormopolis on Sept 6, 2010 14:25:26 GMT -8
harvest moon has a weather type called sunny, but sunny doesnt exist.
|
|
Jai'byrd
Not New Member
"Weirdoes don't die; they just get hit by buses!"[Sj1:0]
Posts: 2
Jai'byrd said 0 great things
|
Post by Jai'byrd on Sept 6, 2010 17:56:32 GMT -8
Fixed! Thank you so much! This is an awesome code. ;D
|
|
|
Post by Wormopolis on Sept 6, 2010 19:03:12 GMT -8
I appreciate that! Were you the one who wanted it to show a special label?
|
|
|
Post by whatsuppuddingcup on Jan 15, 2011 9:34:30 GMT -8
Hi. I'm trying to use this code for my site but I don't exactly know how to use it. I've put it in my global footer and nothings happened. Do you have any other directions that I could try?
|
|
|
Post by Wormopolis on Jan 15, 2011 11:45:46 GMT -8
You need to have an element with id="weather" somewhere in the page for it to place the contents.
|
|
|
Post by whatsuppuddingcup on Jan 15, 2011 20:48:27 GMT -8
What do you mean? how would i put it in the page?
|
|
|
Post by Wormopolis on Jan 16, 2011 0:18:41 GMT -8
the code is setup to put the weather contents into an element already on the page that has id="weather". so if you have side tables, you would put a div into one of the boxes. if you want it at the top of the page, put <center><div id="weather"></div></center>
it entirely depends on WHERE you want it to show up.
|
|
|
Post by whatsuppuddingcup on Jan 16, 2011 8:15:23 GMT -8
so if i want it on the left side tables wat would be the code?
|
|
|
Post by Wormopolis on Jan 16, 2011 14:21:15 GMT -8
put that div into one of the side boxes.
|
|
|
Post by whatsuppuddingcup on Jan 17, 2011 20:37:40 GMT -8
i put <div id="weather"></div> in my left side table but it still wont work... :/
|
|
|
Post by Wormopolis on Jan 17, 2011 21:12:13 GMT -8
then I need to see the site in order to tell whats going on now. either the array was edited with an error, or the code isnt below the div.
|
|
|
Post by whatsuppuddingcup on Jan 18, 2011 4:34:58 GMT -8
oh! so the code that you have as to be in the same side table as the div?
|
|