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
2 posters

    Date problem

    Duckbunny80
    Duckbunny80
    New Member


    Posts : 16
    Reputation : 2
    Language : English

    Solved Date problem

    Post by Duckbunny80 September 20th 2019, 3:45 pm

    Hey! I hope somebody can help me. Hello
    Code place: viewtopic_body
    I have chrome
    version: phpBB2
    Try forum: http://forum-try-here.forumotion.co.uk/t37-hey
    settings:

    Problem:


    I want change date in postbody. What i want? Just i want other words. I have got java code, only changed the top message. BUT I want all "Today at" in this page.

    So what i would like? For example;
    all "Today at" in to --> "we was here today"



    I think in my code miss some replay or something, but i don't know what is the replay in java language xD... Can somebody help me? Good bless you if you guys can! Embarassed


    My java code:
    Code:
    document.getElementById('latepost').innerHTML=document.getElementById('latepost').innerHTML.replace(/Today at/,"we was here today ");

    in the viewtopic_body:
    Code:
    <span id="latepost">{postrow.displayed.POST_DATE} </span>





    Last edited by Duckbunny80 on September 20th 2019, 7:12 pm; edited 1 time in total
    avatar
    Guest
    Guest


    Solved Re: Date problem

    Post by Guest September 20th 2019, 4:37 pm

    Your javascript(java is another language) only targets the first element. To target all of the elements, you need to use this code:
    Code:
    Array.from(document.querySelectorAll("#latepost")).forEach((elem)=>{
    elem.innerHTML=elem.innerHTML.replace("Today at", "we was here today");
    })
    document.querySelectorAll("#latepost") returns a list of all the elements with the id #lastpost. This list is in the form of a NodeList. We transform this NodeList to an array with Array.from, so that we can use forEach on it. forEach goes through every element of the array and does the same modification that you did in your code.

    You will need to wrap this code in a DOMContentLoaded event listener, but I suppose you already know how to do that. Let me know if you need help with that. If you add the code to the template, you may be able to directly use the code with no modifications.

    One last thing, "we was" is not correct english. The correct form is "we were".
    Duckbunny80
    Duckbunny80
    New Member


    Posts : 16
    Reputation : 2
    Language : English

    Solved Re: Date problem

    Post by Duckbunny80 September 20th 2019, 6:52 pm

    Hello dear!

    Thanks it oke but i have more question.

    If i want change all yesterday too can I? Or is this just for one?

    update:
    I I tried it: Today is working thanks, BUT with "Yesterday at" no. Why?
    avatar
    Guest
    Guest


    Solved Re: Date problem

    Post by Guest September 20th 2019, 7:01 pm

    Hello again,

    Replace the code with this one:
    Code:
    var c={
    "Today at":"we was here today",
    "am":"...",
    }, _keys=Object.keys(c);
    Array.from(document.querySelectorAll("#latepost")).forEach((elem)=>{
    var h=elem.innerHTML;
    _keys.forEach((key)=>{
    h=h.replace(key, c[key]);
    });
    elem.innerHTML=h;
    })
    You need to edit the c object. For every replacing that you want to do, you need to add a new line to that object. For example, the first line is
    Code:
    "Today at":"we was here today",
    .
    The text before the
    Code:
    :
    (called the key) is the value that needs to be replaced. The text after
    Code:
    :
    (called the value) is the replacement for the first value. You can add as many lines as you want. You can also remove one, or edit it as you see fit. The comma separated the pairs. It's not necessary to leave a comma at the end of the last line, but it's generally a good idea so that you don't forget to add it later on. Let me know if the code works, or if you want me to explain it as I did in the first post.
    Duckbunny80
    Duckbunny80
    New Member


    Posts : 16
    Reputation : 2
    Language : English

    Solved Re: Date problem

    Post by Duckbunny80 September 20th 2019, 7:11 pm

    Ohhh man you are a very intelligent, and kind. Sooo sooo thank you. Smile
    problem is Solved.
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19325
    Reputation : 2005
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: Date problem

    Post by Ape September 20th 2019, 7:41 pm

    Thank you for your help @Occultist
    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules



    Date problem Left1212Date problem Center11Date problem Right112
    Date problem Ape_b110
    Date problem Ape1010

      Current date/time is September 23rd 2024, 6:29 am