How to create a simple randomly greeting widget based on user's time of day

Go down

How to create a simple randomly greeting widget based on user's time of day Empty How to create a simple randomly greeting widget based on user's time of day

Post by SarkZKalie on June 7th 2020, 12:21 pm

Hello, it's me again Very Happy

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.

How to create a simple randomly greeting widget based on user's time of day Good-m10

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}">&nbsp;{USERNAME}&nbsp;</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>
CSS (optional):
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"];
Or, you can add more text
Spoiler:
greeta = ["Howdy", "Hallå", "Bonjour", "Konnichiwa", "Marhaba", "Namaskar", "Zdraveite", "Hola", "Guten tag", "Yasou"];
Live demo

Enjoy! Twisted Evil


Last edited by SarkZKalie on June 8th 2020, 12:18 am; edited 1 time in total


How to create a simple randomly greeting widget based on user's time of day Sarkzk10
SarkZKalie
SarkZKalie
Support Moderator
Support Moderator

Male Posts : 1173
Reputation : 192
Language : English

View user profile https://www.rotavn.xyz/

Back to top Go down

How to create a simple randomly greeting widget based on user's time of day Empty Re: How to create a simple randomly greeting widget based on user's time of day

Post by YoshiGM on June 7th 2020, 7:15 pm

Sounds interesing.
Thanks for the code and your hardwok @SarkZKalie Very good
YoshiGM
YoshiGM
Forumember

Male Posts : 919
Reputation : 120
Language : Spanish & English
Location : Mexico

View user profile http://asistencia.foroactivo.com/u21373

Back to top Go down

How to create a simple randomly greeting widget based on user's time of day Empty Re: How to create a simple randomly greeting widget based on user's time of day

Post by Neptune- on June 7th 2020, 8:14 pm

Hello,

Nice job, but live demo seems to be broken (it worked few hours ago)
Neptune-
Neptune-
Forumember

Male Posts : 394
Reputation : 83
Language : French (10), English (8), CSS (5), HTML (4), Javascript (4)
Location : France

View user profile https://www.galaxie-series.net/

Back to top Go down

How to create a simple randomly greeting widget based on user's time of day Empty Re: How to create a simple randomly greeting widget based on user's time of day

Post by mSyx on June 7th 2020, 11:38 pm

Oy o/
Nice one, thanks.

You may want to fix this; there's a letter missing here (thread and live demo):
Code:
      if (today.getHours() > 17 && today.getHours() <= 24) {
        document.getElementById('greeting').innerHTML = greetc[greetz] + userz;
      }

greetc[greetz] » greetc[greetzc]
mSyx
mSyx
Forumember

Male Posts : 131
Reputation : 29
Language : French & English
Location : France

View user profile https://help.forumotion.com/

Back to top Go down

How to create a simple randomly greeting widget based on user's time of day Empty Re: How to create a simple randomly greeting widget based on user's time of day

Post by SarkZKalie on June 8th 2020, 1:06 am

Hi guys, thank you. I've edited the first post

Hope you like it Smile


How to create a simple randomly greeting widget based on user's time of day Sarkzk10
SarkZKalie
SarkZKalie
Support Moderator
Support Moderator

Male Posts : 1173
Reputation : 192
Language : English

View user profile https://www.rotavn.xyz/

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum