The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
+3
Neptune-
YoshiGM
SarkZKalie
7 posters

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

    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1443
    Reputation : 220
    Language : English

    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 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:
    Or, you can add more text
    Spoiler:
    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

    TonnyKamper, Jucarese, TheCrow and The Last Outlaw like this post

    YoshiGM
    YoshiGM
    Active Poster


    Male Posts : 1562
    Reputation : 146
    Language : Spanish & English
    Location : Mexico

    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 June 7th 2020, 7:15 pm

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


    Female Posts : 496
    Reputation : 104
    Language : French (10), English (8), CSS (5), HTML (4), Javascript (4)
    Location : Scotland, UK

    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- June 7th 2020, 8:14 pm

    Hello,

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


    Male Posts : 155
    Reputation : 47
    Language : French & English
    Location : France

    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 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]

    KimiD56 likes this post

    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1443
    Reputation : 220
    Language : English

    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 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
    KimiD56
    KimiD56
    New Member


    Female Posts : 14
    Reputation : 1
    Language : English
    Location : Ohio, USA

    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 KimiD56 November 4th 2020, 7:15 pm

    Thank you, this is awesome! I'm not very good with codes. Can you tell me where the CSS code to change the text color goes?
    #greeting {color:red}
    #greeting a {color:blue}
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1443
    Reputation : 220
    Language : English

    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 November 8th 2020, 7:28 am

    @KimiD56 hi, you may find it in Admin Control Panel -> Display -> CSS Smile



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

    KimiD56 likes this post

    KimiD56
    KimiD56
    New Member


    Female Posts : 14
    Reputation : 1
    Language : English
    Location : Ohio, USA

    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 KimiD56 November 8th 2020, 4:17 pm

    Thank you

    SarkZKalie likes this post

    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    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 TheCrow November 9th 2020, 5:57 pm

    Thank you for sharing this @SarkZKalie,

    I added this to my forum, in a different way, but it's a nice feature. Great work! How to create a simple randomly greeting widget based on user's time of day 1f60d

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



    How to create a simple randomly greeting widget based on user's time of day Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!

    BlackScorpion, SarkZKalie and The Last Outlaw like this post

    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1443
    Reputation : 220
    Language : English

    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 November 11th 2020, 5:45 am

    @TheCrow whaaaaaa that was great idea, my dear Smile))



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

    TheCrow and The Last Outlaw like this post

    The Last Outlaw
    The Last Outlaw
    Forumember


    Male Posts : 430
    Reputation : 11
    Language : English (US)
    Location : Salem, Oregon, USA

    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 The Last Outlaw November 17th 2020, 9:41 pm

    @SarkZKalie I want to do this the same way @TheCrow did it. I've tried it a few times and it didn't work like I wanted it to. Can you advise me as to how to set it all up?
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    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 TheCrow November 18th 2020, 8:21 am

    @The Last Outlaw, it is easy. You only add the html tags wherever you want in your template, and then you add the script as a javascript to your forum and it will be shown like mine. Nothing too difficult! Wink



    How to create a simple randomly greeting widget based on user's time of day Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    The Last Outlaw
    The Last Outlaw
    Forumember


    Male Posts : 430
    Reputation : 11
    Language : English (US)
    Location : Salem, Oregon, USA

    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 The Last Outlaw November 18th 2020, 8:27 am

    TheCrow wrote:@The Last Outlaw, it is easy. You only add the html tags wherever you want in your template, and then you add the script as a javascript to your forum and it will be shown like mine. Nothing too difficult! Wink

    Which one? Overall Header?
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    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 TheCrow November 18th 2020, 10:27 am

    That depends on where you want this to appear. If you want it to the header of the forum like I did, then yes, overall_header would be the one. Wink



    How to create a simple randomly greeting widget based on user's time of day Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    The Last Outlaw
    The Last Outlaw
    Forumember


    Male Posts : 430
    Reputation : 11
    Language : English (US)
    Location : Salem, Oregon, USA

    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 The Last Outlaw November 28th 2020, 6:07 pm

    Not working for me.

      Current date/time is November 11th 2024, 5:44 pm