Created
January 18, 2023 15:22
-
-
Save jorgevilaca82/ac1f08d963d7be8e8ede5b8e82aeea49 to your computer and use it in GitHub Desktop.
Notifys you when a target value is reached
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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