Skip to content

Instantly share code, notes, and snippets.

@Irungaray
Created January 24, 2023 11:41
Show Gist options
  • Save Irungaray/a43ef9bb9638cdd9d3b39cf81a72e06f to your computer and use it in GitHub Desktop.
Save Irungaray/a43ef9bb9638cdd9d3b39cf81a72e06f to your computer and use it in GitHub Desktop.
const regex = /^(\d*([.,](?=\d{3}))?\d+)+((?!\2)[.,]\d\d)?$/
const dollar = await fetch('https://api.bluelytics.com.ar/v2/latest')
.then(res => res.json())
.then(data => data.blue.value_sell)
.catch(err => console.log(err))
document.querySelectorAll('*').forEach((node) => {
const word = node.textContent.split(' ')
const isPrice = regex.test(word) && word > 0
if (isPrice) {
const valueInArs = Number(word[0].split('.').join(''))
const formattedNumber = (valueInArs / dollar).toFixed(2)
node.textContent = formattedNumber
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment