Skip to content

Instantly share code, notes, and snippets.

@jorgevilaca82
Created January 18, 2023 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgevilaca82/ac1f08d963d7be8e8ede5b8e82aeea49 to your computer and use it in GitHub Desktop.
Save jorgevilaca82/ac1f08d963d7be8e8ede5b8e82aeea49 to your computer and use it in GitHub Desktop.
Notifys you when a target value is reached
Notification.requestPermission()
const CURRENCY = "USD-BRL"
let myTargetValue = window.prompt("Targe value")
let intervalId = null
async function checkCurrency(targeValue, currency) {
let currencyKey = currency.replace("-", "")
let response = await fetch(`https://economia.awesomeapi.com.br/last/${currency}`)
json = await response.json()
console.log(json)
if (json[currencyKey]["ask"] >= targeValue) {
new Notification("Currency Notification", {
body: `Target value of ${targeValue} was reached!`,
})
clearInterval(intervalId)
}
}
intervalId = setInterval(checkCurrency, 30000, myTargetValue, CURRENCY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment