-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.mining-ticker.js
126 lines (100 loc) · 4.25 KB
/
jquery.mining-ticker.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
$.fn.miningTicker = function () {
var miningTicker = function () {
return {
options: {
'currency': 'ETH',
'url': 'https://min-api.cryptocompare.com/data/price',
'pool': 'nanopool',
'titleSelector': '.crypto-mining-currency-title',
'hashRateSelector': '.crypt-currency-hashrate',
'balanceSelector': '.crypt-currency-balance'
},
init: function (elem) {
var me = this;
me._$container = elem;
me.applyDataAttributes();
me._$hashRate = $(me.options.hashRateSelector, me._$container);
me._$balance = $(me.options.balanceSelector, me._$container);
me._$title = $(me.options.titleSelector, me._$container);
me._$title.text(me.options.currency + ' ' + me.options.pool);
me._storage = window.localStorage;
me.callApi();
setInterval($.proxy(me.callApi, me), 90000);
},
callApi: function () {
var me = this,
options = {
type: 'GET',
success: $.proxy(me.renderPrice, me)
};
$.ajax(me.options.url, options);
},
renderPrice: function (response) {
var me = this;
switch (me.options.pool) {
case 'nanopool':
me.renderNanopool(response);
break;
case 'zenmine':
me.renderZenmine(response);
break;
case 'nicehash':
me.renderNicehash(response);
break;
case 'siamining':
me.renderSiamining(response);
break;
default :
break;
}
},
renderNanopool: function (response) {
var me = this, precision = (me.options.currency === 'SIA') ? 2 : 5;
me._$balance.text(response.data.balance.toFixed(precision));
me._$hashRate.text(response.data.hashrate + ((me.options.currency === 'ZEC') ? ' S/s' : ' MH/s'));
},
renderZenmine: function (response) {
var me = this, immature = 0;
response.rewards.forEach(function (reward) {
if(reward.immature){
immature += (reward.reward / Math.pow(10, 8));
}
});
me._$balance.html((response.stats.balance / Math.pow(10, 8)).toFixed(5) + '<br>' + immature.toFixed(5));
me._$hashRate.text(response.currentHashrate.toFixed(5) + ' S/s');
},
renderNicehash: function (response) {
var me = this, balance = 0.0, hashes = 'multiple Sources';
if (typeof response === 'string') {
response = JSON.parse(response);
}
response.result.stats.forEach(function (miner) {
balance += Number(miner.balance);
});
me._$balance.text(balance.toFixed(6));
me._$hashRate.text(hashes);
},
renderSiamining: function (response) {
var me = this;
if (typeof response === 'string') {
response = JSON.parse(response);
}
me._$balance.text(Number(response.balance).toFixed(2));
me._$hashRate.text((Number(response.intervals[0].hash_rate) / Math.pow(10, 6)).toFixed(2) + ' MH/s');
},
applyDataAttributes: function () {
var me = this;
Object.getOwnPropertyNames(me.options).forEach(function (key) {
var dataVal = me._$container.attr('data-' + key);
if (dataVal) {
me.options[key] = dataVal;
}
});
}
}
};
return this.each(function () {
var cT = new miningTicker();
cT.init($(this));
});
};