-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
88 lines (77 loc) · 2.33 KB
/
index.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bitcoin Alert</title>
<meta name="description" content="Bitcoin Alert">
<meta name="author" content="Nathan Jordan">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<style type="text/css">
audio {
display: none;
}
body {
background-image: url('https://wallpapercave.com/wp/mbfPHPK.jpg');
background-size: 100% auto;
color: white;
font-family: "Comic Sans MS", cursive, sans-serif;
padding: 1em;
}
h1 {
font-size: 6rem;
margin: 0;
}
</style>
</head>
<body>
<script>
const currentPriceURL = "https://api.coindesk.com/v1/bpi/currentprice.json"
const updateInterval = 10000; // 10 seconds
const threshold = 6800; // threshold at which it is not worth it to mine
var currentPrice;
var belowThreshold = true;
$(document).ready(function() {
// request for the current price of bitcoin
var updatePrice = function() {
$.getJSON(currentPriceURL, function( data ) {
currentPrice = data.bpi.USD.rate_float;
updatePriceDisplay(currentPrice);
console.log(currentPrice);
if (belowThreshold && currentPrice > threshold) {
belowThreshold = false;
playSong();
return;
}
if (!belowThreshold && currentPrice < threshold) {
belowThreshold = true;
playSong();
return;
}
});
};
var updatePriceDisplay = function(price) {
$("#price").html(formatUSD(price));
};
var playSong = function() {
$("#you_suffer").trigger("play");
};
var formatUSD = function(num) {
return "$" + num.toString();
};
// update price and watch
updatePrice();
setInterval(updatePrice, updateInterval);
// display threshold
$("#threshold").html(formatUSD(threshold));
}) // document.ready
</script>
<h1>BTC Price: <span id="price">?</span></h1>
<h1>Threshold: <span id="threshold">?</span></h1>
<audio id="you_suffer" controls="controls">
<source src="you_suffer.mp3" type="audio/mpeg"/>
</audio>
</body>
</html>