Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript document.body.textContent with replace or replace all

Hi Guys,

Could you please help me to use document.body.textContent in console log on a website?

For example I want to change this format of 4.500,00 to 4,500.00 or 4500.00?
How is it possible in this way i.e on this site EuroDreams auf win2day - die Spieleseite der Österreichischen Lotterien| win2day?

Thank you in advance for your help.

Best regards,
YoungZeeZee
Hi there,
First of all, let me ask you this... is this your site, or do you permission to change it?
 
Hi there,
First of all, let me ask you this... is this your site, or do you permission to change it?
Hi @Antero360 ,

Thank you for your message.
It is not my website. i can manipulate any website via console which does not make universal changes. the change appears on my browser until i refresh it.
so
Let’s simplify my question as i am not really experienced in javascript and do not want a very professional solution.

How can i manipulate a site in console with document.body.textContent
I need the following things:
1: remove every dots “.”
2: change commas ","to dots “.”

Thank you in advance for your help.
Screenshot 2023-12-21 at 15.47.33.png
 
Hi @Antero360 ,

Thank you for your message.
It is not my website. i can manipulate any website via console which does not make universal changes. the change appears on my browser until i refresh it.
so
Let’s simplify my question as i am not really experienced in javascript and do not want a very professional solution.

How can i manipulate a site in console with document.body.textContent
I need the following things:
1: remove every dots “.”
2: change commas ","to dots “.”

Thank you in advance for your help.
View attachment 2438
Why do you need to "manipulate" it via js? What is your end goal by doing so?
 
Why do you need to "manipulate" it via js? What is your end goal by doing so?
As it would help me in my hobby. I record some data to myself and with this js code it would be easier.
Now I need to change things on the data one by one.

i.e. i have this piece code but it does not work with all the sites and if i change td to div, it messes it up the site

JavaScript:
let numTD = document.getElementsByTagName('td').length;
for (let i = 0; i < numTD; i++) {
let current = document.getElementsByTagName('td')[i];
if (current.innerText.includes(".")) {
current.innerText = current.innerText.replaceAll(".", "");
}
}

Then i found that method (document.body.textContent) in a js tutorial and thought it would be easier to have a piece of codes that works with nearly every sites.

Thank you in advance
 
I'm not that good in regular expressions, but hope this crutch helps

JavaScript:
console.log(
document.body.innerText
    .replace(/([\s\d]+).([\d]+),([\d]{2})/g , '$1$2,$3')
        .replace(/([\d]+),([\d]{2})/g , '$1.$2')
)

I believe this can be done with only one replace, may be somebody knows how
 
I'm not that good in regular expressions, but hope this crutch helps

JavaScript:
console.log(
document.body.innerText
    .replace(/([\s\d]+).([\d]+),([\d]{2})/g , '$1$2,$3')
        .replace(/([\d]+),([\d]{2})/g , '$1.$2')
)

I believe this can be done with only one replace, may be somebody knows how
Thank you i will have a look at it 🙂
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom