Post by Xesna on Mar 1, 2019 21:24:20 GMT -8
You can easily follow the code since majority of it is just list of arrays containing a list of strings to certain weather conditions and whether each one met the precipitation/humidity requirement to do that condition with the following cold or hot temperature.
The area of focus is again, retaining the value without it changing until the site is closed.
//localStorage.setItem("weather", weather);
//document.getElementById("weather_result").innerHTML = localStorage.getItem("weather");
I had it working previously, but after I tried applying the method to temperature, direction, win_number, per, and rain_number; however, it broke the weather from being retained throughout the local storage. I know I used something like typeof(Storage) !== "undefined" for the setItem(), then used the same if with the added localStorage.getItem("result") !== "undefined" for the getItem(). But, again, I wasn't able to recover what I did.
TL;DR: After hours of trying to properly implement, I still can't seem to retain the value of weather after a refresh, switching to a different view, etc.
If anyone can assist me in my plight, I'd be grateful.
FYI: I do not want to use a weather widget, it is useless if you're trying to create your own weather for an fictional world. Plus, the widgets look ugly.
<div class="fade">
<a href="http://nindao.proboards.com/board/13/meteor-country">
<div align="center">
<div style="float:center;
width: 225px;
height: 40px;
background-image: url(https://i.ibb.co/khnn59V/Size.jpg);
background-position: center;
-moz-border-radius: 100px;
-webkit-border-radius: 100px;
-o-border-radius: 100px;
border-radius: 100px;
border: 2px solid #444444;">
</div>
</div>
</a>
<div align="center">
<div style="font: 25pt Garamond; float:center;"> <i>Kakougakure</i><br>
<div style="font: 10pt Garamond; line-height: 100%; letter-spacing: 1px;">
<i><p id = "temperature_result"></p><br/>
<p id ="weather_result"></p><br/>
<p id = "windspd_result"></p><br/>
<p id = "chance_result"></p><br/></i>
</div>
<script type="text/javascript">
var t = (Math.floor((Math.random() * 87) + 1)).toString();
var weather;
// 3
var bkn = ["Mostly Cloudy", "Mostly Cloudy with Haze", "Mostly Cloud and Breezy"];
// 6
var skc = ["Fair", "Clear", "Fair with Haze", "Clear with Haze", "Fair and Breezy",
"Clear and Breezy"];
// 3
var few = ["A Few Clouds", "A Few Clouds with Haze", "A Few Clouds and Breezy"];
// 3
var sct = ["Partly Cloudy", "Partly Cloudy with Haze", "Partly Cloudy and Breezy"];
// 3
var ovc = ["Overcast", "Overcast with Haze", "Overcast and Breezy"];
// 13
var fg = ["Mist", "Fog", "Freezing Fog", "Shallow Fog", "Partial Fog", "Patches of Fog",
"Fog in Vicinity", "Freezing Fog in Vicinity", "Partial Fog in Vicinity",
"Patches of Fog in Vicinity", "Showers in Vicinity Fog", "Light Freezing Fog",
"Heavy Freezing Fog"];
// 1
var smoke = ["Smoke"];
// 7
var fzra = ["Freezing Rain", "Freezing Drizzle", "Light Freezing Rain", "Light Freezing Drizzle",
"Heavy Freezing Drizzle", "Freezing Rain in Vicinity", "Freezing Drizzle in Vicinity"];
// 16
var ip = ["Ice Pellets", "Light Ice Pellets", "Heavy Ice Pellets", "Ice Pellets in Vicinity",
"Drizziling Ice Pellets", "Thunderstorm Ice Pellets", "Ice Crystals", "Hail", "Small Hail",
"Snow Pellets", "Light Small Hail", "Light Snow Pellets", "Heavy Small Hail", "Heavy Snow Pellets",
"Drizziling Hail", "Hail Showers"];
// 12
var mix = ["Freezing Rain Snow", "Light Freezing Rain Snow", "Heavy Freezing Rain Snow",
"Freezing Drizzle Snow", "Light Freezing Drizzle Snow", "Heavy Freezing Drizzle Snow",
"Snow Freezing Rain", "Light Snow Freezing Rain", "Heavy Snow Freezing Rain",
"Snow Freezing Drizzle", "Light Snow Freezing Drizzle", "Heavy Snow Freezing Drizzle"];
// 12
var raip = ["Raining Ice Pellets", "Light Rain Ice Pellets", "Heavy Rain Ice Pellets", "Drizzle Ice Pellets",
"Light Drizzle Ice Pellets", "Heavy Drizzle Ice Pellets", "Ice Pellets Rain", "Light Ice Pellets Rain",
"Heavy Ice Pellets Rain", "Ice Pellets Drizzle", "Light Ice Pellets Drizzle", "Heavy Ice Pellets Drizzle"];
// 12
var rasn = ["Rain Snow", "Light Rain Snow", "Heavy Rain Snow", "Snow Rain", "Light Snow Rain", "Heavy Snow Rain",
"Drizzle Snow", "Light Drizzle Snow", "Heavy Drizzle Snow", "Snow Drizzle", "Light Snow Drizzle", "Heavy Drizzle Snow"];
// 21
var shra = ["Rain Showers", "Light Rain Showers", "Light Rain and Breezy", "Heavy Rain Showers", "Rain Showers in Vicinity",
"Light Rain Showers", "Heavy Rain Showers", "Rain Shower", "Rain Shower in Vicinity", "Foggy Rain Showers",
"Misty Rain Showers", "Light Foggy Rain Showers", "Light Misty Rain Showers", "Heavy Foggy Rain Showers",
"Heavy Misty Rain Showers", "Foggy Rain Showers in Vicinity", "Misty Rain Showers in Vicinity",
"Light Foggy Rain Showers", "Light Misty Rain Showers", "Heavy Foggy Rain Showers", "Heavy Misty Rain Showers"];
// 52
var tsra = ["Thunderstorm", "Thunderstorm with Rain", "Light Thunderstorm Rain", "Heavy Thunderstorm with Rain", "Thunderstorm with Rain and Fog",
"Thunderstorm with Rain and Mist", "Light Thunderstorm with Rain and Fog,", "Light Thunderstorm with Rain and Mist", "Heavy Thunderstorm with Rain and Fog",
"Heavy Thunderstorm with Rain and Wind", "Heavy Thunderstorm with Rain and Mist", "Thunderstorm with Showers in Vicinity", "Light Thunderstorm with Rain and Haze",
"Heavy Thunderstorm with Rain and Haze", "Thunderstorm with Fog", "Thunderstorm with Light Rain", "Thunderstorm with Heavy Rain", "Thunderstorm with Light Rain and Fog",
"Thunderstorm with Light Rain and Mist", "Thunderstorm with Heavy Rain and Fog", "Thunderstorm with Heavy Rain and Mist", "Thunderstorm in Vicinity with Fog",
"Thunderstorm in Vicinity with Mist", "Thunderstorm with Showers in Vicinity", "Thunderstorm in Vicinity with Haze", "Thunderstorm with Light Rain and Haze",
"Thunderstorm with Heavy Rain and Haze", "Thunderstorm with Fog", "Thunderstorm and Hail", "Light Thunderstorm with Rain and Hail", "Heavy Thunderstorm with Rain and Hail",
"Thunderstorm with Rain, Hail, and Fog", "Thunderstorm with Rain, Hail, and Mist", "Light Thunderstorm with Rain, Hail, and Fog", "Light Thunderstorm with Rain, Hail, and Mist",
"Heavy Thunderstorm with Rain, Hail, and Fog", "Heavy Thunderstorm with Rain, Hail, and Mist", "Thunderstorm with Showers in Vicinity and Hail", "Light Thunderstorm with Rain, Hail, and Haze",
"Thunderstorm with Hail and Fog", "Thunderstorm in Vicinity and Hail", "Thunderstorm in Vicinity with Hail and Haze", "Thunderstorm with Haze in Vicinity and Hail",
"Thunderstorm with Small Hail", "Thunderstorm with Snow Pellets", "Thunderstorm with Rain and Small Hail", "Thunderstorm with Rain and Snow Pellets", "Light Thunderstorm with Rain and Small Hail",
"Light Thunderstorm with Rain and Snow Pellets", "Heavy Thunderstorm with Rain and Small Hail", "Heavy Thunderstorm with Rain and Snow Pellets"];
// 44
var sn = ["Snow", "Light Snow", "Heavy Snow", "Snow with Showers", "Light Snow with Showers", "Heavy Snow with Showers", "Snow with Fog", "Snow with Mist", "Light Snow with Fog", "Light Snow with Mist",
"Heavy Snow with Fog", "Heavy Snow with Mist", "Snow with Showers and Fog", "Snow with Showers and Mist", "Light Snow with Showers and Fog", "Light Snow with Showers and Mist", "Heavy Snow with Showers and Fog",
"Heavy Snow with Showers and Mist", "Snow and Fog", "Light Snow and Fog", "Heavy Snow with Fog", "Snow with Showers and Fog", "Snow with Showers and Fog", "Light Showers with Snow and Fog", "Heavy Showers with Snow and Fog",
"Showers in Vicinity with Snow", "Snow with Showers in Vicinity and Fog", "Snow with Showers in Vicinity and Mist", "Low Drifting Snow", "Blowing Snow", "Light Snow with Low Drifting", "Heavy Snow with Low Drifting",
"Blowing Light Snow", "Blowing Heavy Snow", "Blowing Light Snow with Fog", "Blowing Light Snow with Mist", "Heavy Snow with Low Drifting", "Thunderstorm with Snow", "Light Thunderstorm with Snow", "Heavy Thunderstorm with Snow",
"Snow Grains", "Light Snow Grains", "Heavy Snow Grains", "Blowing Snow in Vicinity"];
// 7
var wind = ["Windy", "Breezy", "Fair and Windy", "A Few Clouds and Windy", "Partly Cloudy and Windy", "Mostly Cloudy and Windy", "Overcast and Windy"];
// 4
var nsvrtsra = ["Funnel Cloud", "Funnel Cloud in Vicinity", "Tornado", "Water Spout"];
// 17
var dust = ["Dust", "Low Drifting Dust", "Blowing Dust", "Sand", "Blowing Sand", "Low Drifting Sand", "Dust Whirls", "Sand Whirls", "Dust Whirls in Vicinity", "Sand Whirls in Vicinity", "Dust Storm", "Heavy Dust Storm",
"Dust Storm in Vicinity", "Sand Storm", "Heavy Sand Storm", "Sand Storm in Vicinity"];
// 1
var haze = ["Haze"];
// Wind Velocity
var win_number = Math.floor((Math.random() * 52) + 1).toString();
// Rain Chance
var rain_number = Math.floor((Math.random() * 100) + 1).toString();
// Cardinal Direction
var i = Math.floor((Math.random() * 8) + 1);
var direction = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
var per;
var percent = ["Drizzle", "Isolated", "Scattered", "Numerous"];
// Drizzle of Superarid to Perarid
if(rain_number < 20)
{
per = percent[0];
// Tundra to Tropical
if(t >= 33)
{
var hotArray = Math.floor((Math.random() * 6) + 1);
if(hotArray == 1)
{
var bknArray = Math.floor((Math.random() * 3) + 1);
weather = bkn[bknArray];
}
else if(hotArray == 2)
{
var skcArray = Math.floor((Math.random() * 6) + 1);
weather = skc[skcArray];
}
else if(hotArray == 3)
{
var fewArray = Math.floor((Math.random() * 3) + 1);
weather = few[fewArray];
}
else if(hotArray == 4)
{
var sctArray = Math.floor((Math.random() * 3) + 1);
weather = sct[sctArray];
}
else if(hotArray == 5)
{
var ovcArray = Math.floor((Math.random() * 3) + 1);
weather = ovc[ovcArray];
}
else
{
var windArray = Math.floor((Math.random() * 7) + 1);
weather = wind[windArray];
}
}
// Tundra to Arctic
else
{
var snArray = Math.floor((Math.random() * 44) + 1);
weather = sn[snArray];
}
}
// Isolated of Arid to Semi-humid
else if(rain_number >= 20 && rain_number <= 29)
{
per = percent[1];
// Confierous to Tropical
if(t >= 38)
{
var hotArray = Math.floor((Math.random() * 7) + 1);
if(hotArray == 1)
{
var bknArray = Math.floor((Math.random() * 3) + 1);
weather = bkn[bknArray];
}
else if(hotArray == 2)
{
var skcArray = Math.floor((Math.random() * 6) + 1);
weather = skc[skcArray];
}
else if(hotArray == 3)
{
var fewArray = Math.floor((Math.random() * 3) + 1);
weather = few[fewArray];
}
else if(hotArray == 4)
{
var sctArray = Math.floor((Math.random() * 3) + 1);
weather = sct[sctArray];
}
else if(hotArray == 5)
{
var ovcArray = Math.floor((Math.random() * 3) + 1);
weather = ovc[ovcArray];
}
else if(hotArray == 6)
{
var windArray = Math.floor((Math.random() * 7) + 1);
weather = wind[windArray];
}
else
{
var fgArray = Math.floor((Math.random() * 13) + 1);
weather = fg[fgArray];
}
}
// Taiga to Arctic
else
{
var snArray = Math.floor((Math.random() * 44) + 1);
weather = sn[snArray];
}
}
// Scattered of Humid to Perhumid
else if(rain_number >= 30 && rain_number <= 50)
{
per = percent[2];
// Decidous to Tropical
if(t >= 43)
{
var hotArray = Math.floor((Math.random() * 5) + 1);
if(hotArray == 1)
{
var shraArray = Math.floor((Math.random() * 21) + 1);
weather = shra[shraArray];
}
else if(hotArray == 2)
{
var tsraArray = Math.floor((Math.random() * 52) + 1);
weather = tsra[tsraArray];
}
else if(hotArray == 3)
{
var windArray = Math.floor((Math.random() * 7) + 1);
weather = wind[windArray];
}
else if(hotArray == 4)
{
var fgArray = Math.floor((Math.random() * 13) + 1);
weather = fg[fgArray];
}
else
weather = haze[0];
}
// Coniferous to Arctic
else
{
var coldArray = Math.floor((Math.random() * 5) + 1);
if(coldArray == 1)
{
var mixArray = Math.floor((Math.random() * 12) + 1);
weather = mix[mixArray];
}
else if(coldArray == 2)
{
var rasnArray = Math.floor((Math.random() * 12) + 1);
weather = rasn[rasnArray];
}
else if(coldArray == 3)
{
var fzraArray = Math.floor((Math.random() * 7) + 1);
weather = fzra[fzraArray];
}
else if(coldArray == 4)
{
var ipArray = Math.floor((Math.random() * 16) + 1);
weather = ip[ipArray];
}
else
{
var snArray = Math.floor((Math.random() * 44) + 1);
weather = sn[snArray];
}
}
}
// Numerous of Superhumid
else
{
per = percent[3];
// Mediterranean to Tropical
if(t >= 54)
{
var hotArray = Math.floor((Math.random() * 3) + 1);
if(hotArray == 1)
{
var shraArray = Math.floor((Math.random() * 21) + 1);
weather = shra[shraArray];
}
else if(hotArray == 2)
{
var tsraArray = Math.floor((Math.random() * 52) + 1);
weather = tsra[tsraArray];
}
else
{
var windArray = Math.floor((Math.random() * 7) + 1);
weather = wind[windArray];
}
}
// Decidous to Arctic
else
{
var coldArray = Math.floor((Math.random() * 3) + 1);
if(coldArray == 1)
{
var mixArray = Math.floor((Math.random() * 12) + 1);
weather = mix[mixArray];
}
else if(coldArray == 2)
{
var rasnArray = Math.floor((Math.random() * 12) + 1);
weather = rasn[rasnArray];
}
else
{
var snArray = Math.floor((Math.random() * 44) + 1);
weather = sn[snArray];
}
}
}
document.getElementById("temperature_result").innerHTML = t + "°C";
//localStorage.setItem("weather", weather);
//document.getElementById("weather_result").innerHTML = localStorage.getItem("weather");
document.getElementById("windspd_result").innerHTML = "Windy: " + direction[i] + " " + win_number + " km/h";
document.getElementById("chance_result").innerHTML = per + " Chance of Rain: " + rain_number + "%";
document.getElementById("temperature_result").style.fontSize = "16px";
document.getElementById("weather_result").style.fontSize = "16px";
document.getElementById("windspd_result").style.fontSize = "16px";
document.getElementById("chance_result").style.fontSize = "16px";
</script>
</div>
</div>
</div>
The area of focus is again, retaining the value without it changing until the site is closed.
//localStorage.setItem("weather", weather);
//document.getElementById("weather_result").innerHTML = localStorage.getItem("weather");
I had it working previously, but after I tried applying the method to temperature, direction, win_number, per, and rain_number; however, it broke the weather from being retained throughout the local storage. I know I used something like typeof(Storage) !== "undefined" for the setItem(), then used the same if with the added localStorage.getItem("result") !== "undefined" for the getItem(). But, again, I wasn't able to recover what I did.
TL;DR: After hours of trying to properly implement, I still can't seem to retain the value of weather after a refresh, switching to a different view, etc.
If anyone can assist me in my plight, I'd be grateful.
FYI: I do not want to use a weather widget, it is useless if you're trying to create your own weather for an fictional world. Plus, the widgets look ugly.