Today, i will show you how to create a simple a randomly greeting widget based on user's time of day for your Forumotion site.
First of all, create a new widget (or put anywhere you want), copy and paste the following code :
- Code:
<p id="greeting"></p>
<script type="text/javascript">
greeta = ["Morning1", "Morning2", "Morning3"];
greetb = ["Afternoon1", "Afternoon2", "Afternoon3"];
greetc = ["Evening1", "Evening2", "Evening3"];
userz = '<a href="{USERLINK}"> {USERNAME} </a>';
greetza = Math.floor(Math.random() * greeta.length);
greetzb = Math.floor(Math.random() * greetb.length);
greetzc = Math.floor(Math.random() * greetc.length);
today = new Date()
if (today.getHours() >=6 && today.getHours() < 12) {
document.getElementById('greeting').innerHTML = greeta[greetza] + userz;
}
else
if (today.getHours() >= 12 && today.getHours() <= 17) {
document.getElementById('greeting').innerHTML = greetb[greetzb] + userz;
}
else
if (today.getHours() > 17 && today.getHours() <= 24) {
document.getElementById('greeting').innerHTML = greetc[greetzc] + userz;
}
else
document.getElementById('greeting').innerHTML = 'Sleep well zZz';
</script>
- Code:
#greeting {color:red}
#greeting a {color:blue}
Next step, replace the default text in Morning1-2-3, Afternoon1-2-3 and Evening1-2-3 to any word or text you want.
For example :
- Spoiler:
- greeta = ["Howdy", "Hello", "Bonjour"];
- Spoiler:
- greeta = ["Howdy", "Hallå", "Bonjour", "Konnichiwa", "Marhaba", "Namaskar", "Zdraveite", "Hola", "Guten tag", "Yasou"];
Enjoy!
Last edited by SarkZKalie on June 8th 2020, 12:18 am; edited 1 time in total