-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalarme.js
45 lines (40 loc) · 1.46 KB
/
alarme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<div>
<p>TRB: <span id="prix-trb"></span></p>
<audio id="audio" controls>
<source src="https://github.com/berru-g/console-play-music/raw/master/son/FL_HHL_Green_078_Guitars.wav" type="audio/mpeg">
Votre navigateur ne supporte pas l'élément audio.
</audio>
</div>
<script>
const coinGeckoURL = "https://api.coingecko.com/api/v3/simple/price";
const params = {
ids: "worldcoin-wld",
vs_currencies: "usd",
};
const seuilSuperieur = 1.85;
const seuilInferieur = 1.75;
const prixTRBElement = document.getElementById("prix-trb");
const audioElement = document.getElementById("audio");
function fetchPrixTRB() {
fetch(`${coinGeckoURL}?${new URLSearchParams(params)}`)
.then((response) => response.json())
.then((data) => {
const prixTRB = data.["worldcoin-wld"].usd;
prixTRBElement.textContent = prixTRB + " USD";
if (prixTRB > seuilSuperieur) {
console.log("Gain");
audioElement.play();
document.querySelector('body').style.backgroundColor = 'lightgreen';
} else if (prixTRB < seuilInferieur) {
console.log("Perte");
audioElement.play();
document.querySelector('body').style.backgroundColor = 'lightcoral';
}
})
.catch((error) => {
console.error("Erreur lors de la récupération des données de CoinGecko:", error);
});
}
setInterval(fetchPrixTRB, 10000);
fetchPrixTRB();
</script>