Date problem

Go down

Solved Date problem

Post by Duckbunny80 on 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:
Date problem Cats6510

Problem:
Date problem Cats10


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

Posts : 3
Reputation : 2
Language : English

http://forum-try-here.forumotion.co.uk

Back to top Go down

Solved Re: Date problem

Post by Occultist on 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".
Occultist
Occultist
Forumember

Posts : 221
Reputation : 56
Language : English and couple others

https://idonthaveaforum.forumotion.com

Back to top Go down

Solved Re: Date problem

Post by Duckbunny80 on 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?
Duckbunny80
Duckbunny80
New Member

Posts : 3
Reputation : 2
Language : English

http://forum-try-here.forumotion.co.uk

Back to top Go down

Solved Re: Date problem

Post by Occultist on 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.
Occultist
Occultist
Forumember

Posts : 221
Reputation : 56
Language : English and couple others

https://idonthaveaforum.forumotion.com

Back to top Go down

Solved Re: Date problem

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

Ohhh man you are a very intelligent, and kind. Sooo sooo thank you. Smile
problem is Solved.
Duckbunny80
Duckbunny80
New Member

Posts : 3
Reputation : 2
Language : English

http://forum-try-here.forumotion.co.uk

Back to top Go down

Solved Re: Date problem

Post by APE on 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
APE
APE
Administrator
Administrator

Male Posts : 15056
Reputation : 1621
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top


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