-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
92 lines (76 loc) · 2.33 KB
/
javascript.js
File metadata and controls
92 lines (76 loc) · 2.33 KB
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
89
90
91
92
var noSleep = new NoSleep();
var btcNowDisp = null;
var btcMinDisp = null;
var btcMaxDisp = null;
var btcNowPrice = 0;
var btcMinPrice = 3775;
var btcMaxPrice = 58330;
var ethNowDisp = null;
var ethMinDisp = null;
var ethMaxDisp = null;
var ethNowPrice = 0;
var ethMinPrice = 108;
var ethMaxPrice = 2036;
function setUp(displays) {
var obj;
for (obj of displays) {
obj.sevenSeg({
digits: 5,
value: 0,
colorOff: "#7d7d7d",
colorBackground: "#828882",
colorOn: "Black",
decimalPoint: false
});
}
}
function updateDisplay(display, price) {
display.sevenSeg({
value: price
})
}
function updateBitcoinPrices() {
$.get('https://blockchain.info/tobtc?currency=USD&value=1', function(response) {
btcNowFloat = 1 / parseFloat(response)
btcNowPrice = parseInt(btcNowFloat);
btcMinPrice = Math.min(btcMinPrice, btcNowPrice);
btcMaxPrice = Math.max(btcMaxPrice, btcNowPrice);
updateDisplay(btcNowDisp, btcNowPrice);
updateDisplay(btcMinDisp, btcMinPrice);
updateDisplay(btcMaxDisp, btcMaxPrice);
});
}
function updateEthereumPrices() {
$.get('https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=USD', function(response) {
ethNowPrice = parseInt(response["ethereum"]["usd"]);
ethMinPrice = Math.min(ethMinPrice, ethNowPrice);
ethMaxPrice = Math.max(ethMaxPrice, ethNowPrice);
updateDisplay(ethNowDisp, ethNowPrice);
updateDisplay(ethMinDisp, ethMinPrice);
updateDisplay(ethMaxDisp, ethMaxPrice);
});
}
function enableNoSleep() {
noSleep.enable();
// document.removeEventListener('click', enableNoSleep, false);
}
$(document).ready(function () {
document.addEventListener('click', enableNoSleep, false);
btcNowDisp = $("#btc-main");
btcMinDisp = $("#btc-min");
btcMaxDisp = $("#btc-max");
ethNowDisp = $("#eth-main");
ethMinDisp = $("#eth-min");
ethMaxDisp = $("#eth-max");
setUp([btcNowDisp, btcMinDisp, btcMaxDisp, ethNowDisp, ethMinDisp, ethMaxDisp]);
updateDisplay(btcMinDisp, btcMinPrice);
updateDisplay(btcMaxDisp, btcMaxPrice);
updateBitcoinPrices();
updateDisplay(ethMinDisp, ethMinPrice);
updateDisplay(ethMaxDisp, ethMaxPrice);
updateEthereumPrices();
setInterval(function() {
updateBitcoinPrices();
updateEthereumPrices();
}, 300000); // 300 000 ms = update prices every 5 minutes
});