-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathscript.js
2192 lines (2065 loc) · 76.6 KB
/
script.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var mde = 'l',
$Q = {
'pool':{
'nme':'SupportXMR', //also sets the cookie prefix
},
'clr':{
'main':'f06923', //C1
'secondary':'818181', //C2
'back-l':'e8e8e8', //C0 - light
'back-d':'313131' //C0 - dark
},
'cur':{
'nme':'Monero',
'sym':'XMR',
'blk':2, //blocktime in minutes
'reg':/^[4|8]{1}([A-Za-z0-9]{105}|[A-Za-z0-9]{94})$/ //address regex
},
'api':'https://supportxmr.com/api/',
//'api':'http://69.164.198.226/api/',
'explorer':'https://xmrchain.net/block/',
'explorertx':'https://xmrchain.net/tx/',
'news':false, //enable news (motd) alerts on homepage
'email':false, //enable email notifications
'timer':60, //refresh timer in seconds
'graph':{
'hrs':8, //max chart length in hours
'pplns':false, //show pplns window on chart
'blockmin':25 //min number of blocks to show (blocks take their own time scale) max 100
},
'pay':{
'min_inst':0.01, //minimum for instant pay
'min_auto':0.1, //minimum for automatic threshold
'dec_auto':4 //decimal places for threshold
}
},
$$ = {
'calc':{
'1':'Per Day',
'7':'Per Week',
'30':'Per Month',
'365':'Per Year',
},
'hlp':{
'head':'Welcome to '+$Q['pool']['nme'],
'text':'Getting started is easy and this pool has a large and friendly community that are happy to help you. The pool operators are M5M400 and Snipa22 who can be reached in the #monero-pools IRC or at <a href="mailto:[email protected]" class="C1 hov">[email protected]</a>. Please be patient and someone will get back to you. Most of the time help can be found quicker in the chat. The pool has a quite stable and knowlegable community - you can join the chat and seek help and a friendly chat there :)'
},
'msg':{
'welcome':{'head':'Welcome to '+$Q['pool']['nme'], 'text':'Visit the <u class="nav C1" data-tar="help">help section</u> to get setup, then enter your '+$Q['cur']['nme']+' address above. After you\'ve submitted a share, your stats will appear here.'},
'addr_invalid':{'head':'Invalid '+$Q['cur']['nme']+' Address', 'text':'Double check that your address is complete.'},
'addr_notfound':{'head':'Address Not Found', 'text':'If you\'ve submitted your first share, be patient, it may take a minute or two to update. If your shares are being rejected, visit the <u class="nav C1" data-tar="help">help section.</u>'},
'addr_nodata':{'head':'No Data', 'text':''}
},
'nav':{
'home':'Home',
'blocks':'Blocks',
'payments':'Payments',
'help':'Help'
},
'pay':{
'DashPending':{'lbl':$Q['cur']['sym']+' Pending', 'var':'due'},
'DashPaid':{'lbl':$Q['cur']['sym']+' Paid', 'var':'paid'}
},
'sts':{
'MinerWorkerCount':{'lbl':'<span id="MinerLastHash">--</span>'},
'MinerHashes':{'lbl':'Total Hashes', 'var':'hashes'},
'MinerShares':{'lbl':'Valid / Invalid Shares', 'def':'-- / --', 'var':'shares'},
'MinerCalc':{'lbl':'<input type="text" id="MinerCalcHsh" size="3" /><select id="MinerCalcUnit"></select><select id="MinerCalcFld"></select>'}
},
'tbl':{
'poolpay':{
'tme':{'lbl':'Payment Sent', 'cls':'condte'},
'payees':{'lbl':'Payees', 'cls':'consmall'},
'amnt':{'lbl':'Amount ('+$Q['cur']['sym']+')', 'cls':'consmall'},
'fee':{'lbl':'Fee ('+$Q['cur']['sym']+')', 'cls':'right'}
},
'blockhistory':{
'tme':{'lbl':'Block Mined', 'cls':'condte'},
'togo':{'lbl':'Maturity', 'cls':'consmall'},
'eff':{'lbl':'Effort', 'cls':'continy'},
'reward':{'lbl':'Reward ('+$Q['cur']['sym']+')', 'cls':'consmall'},
'height':{'lbl':'Height', 'cls':'consmall'},
'hash':{'lbl':'Transaction', 'cls':'right', 'hsh':'y'}
},
'pay':{
'tme':{'lbl':'Payment Sent', 'cls':'condte'},
'amnt':{'lbl':'Amount ('+$Q['cur']['sym']+')', 'cls':'center'},
'hash':{'lbl':'Transaction', 'cls':'right', 'hsh':'y'}
}
},
'trn':{
'avgeff':'Avg Effort',
'conf':'Confirmed',
'eff':'Effort',
'eml_on':'Email Alerts On',
'eml_off':'Email Alerts Off',
'min':'Minimum',
'que':'Payment Queued',
'rcnt':'Recent',
'set':'Set Auto Pay',
'updt':'Updated',
'vwpy':'View Your Payments'
}
};
/*--------------------------------------*/
/*-----End of Customization Section------- (You can customize the rest, but shouldn't need to) */
/*--------------------------------------*/
var addr = UrlVars()['addr'] || '',
pref = 'LNA',
cookieprefix = $Q['pool']['nme'].replace(/[ ,;]/g, ''),
resizeTimer,
updateTimer = $Q['timer'],
updateCounter,
outoffocus = 0,
now = Rnd((new Date()).getTime() / 1000),
width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
netpop_open = '',
$A = {}, //Account Memory
$C = { //Selector Cache
'TogMode':'',
'Timer':'',
'NetGraph':'',
'Addr':'',
'Stage':'',
'DashPayBtn':'',
'AddrField':'',
'TimerPie':'',
'TimerText':'',
'TimerRefresh':''
},
$U = { //Update Times
'net':0,
'netheight':0,
'pool':0,
'poolstats':0,
'news':0
},
$L ={ //Localization
'perc':'9 %',
'thou':',',
'dec':'.',
'tme':'G:i'
},
$D = { //Data Digests
'news':{},
'block':{},
'blockhistory':{},
'net':{},
'pool':{},
'poolstats':{},
'pay':{},
'poolpay':{},
'netheight':'',
'hashconv':{
'GH':1000000000,
'MH':1000000,
'kH':1000,
'H':1
}
},
$I = { //Icons
'l':'<svg viewBox="0 0 99 99"><circle opacity=".6" cx="49.5" cy="49.5" r="31.5"/><path d="M87.6 57.1L99 49.5 87.7 42l7.5-11.3L82 27.9l2.6-13.4-13.4 2.7-2.6-13.4L57 11.4 49.5 0 42 11.3 30.6 3.8 27.9 17l-13.4-2.6 2.7 13.4-13.4 2.6L11.4 42 0 49.5 11.3 57 3.8 68.4 17 71.1l-2.6 13.4 13.4-2.7 2.6 13.4L42 87.6 49.5 99 57 87.7l11.3 7.5L71.1 82l13.4 2.6-2.7-13.4 13.4-2.6L87.6 57zM49.5 80a30.5 30.5 0 1 1 0-61 30.5 30.5 0 0 1 0 61z"/></svg>',
'd':'<svg viewBox="0 0 99 99"><path d="M25.2 19.6l5.3 10.6 11.7 1.7-8.5 8.3 2 11.6-10.5-5.5-10.4 5.5 2-11.6-8.5-8.3L20 30.2l5.2-10.6zm29.6-3.4l2.7 5.5 6 .9-4.3 4.2 1 6-5.4-2.8-5.5 2.9 1-6-4.3-4.3 6-1 2.8-5.4zM64.8 0A46 46 0 0 1 0 64.4 50.9 50.9 0 1 0 64.6 0z"/></svg>',
'settings':'<svg viewBox="0 0 99 99"><path d="M19.7 50.74V10.92l-6.4 1.69v38.12a16.1 16.1 0 0 0 0 31.53v4.17l6.4 1.65v-5.82a16.09 16.09 0 0 0 0-31.52zm-3.2 25.34a9.58 9.58 0 1 1 0-19.16 9.58 9.58 0 0 1 0 19.16zm36.2-59.51S52.66 0 52.7 0h-6.4v16.57a16.09 16.09 0 0 0 0 31.53V99h6.4V48.1a16.09 16.09 0 0 0 0-31.53zm-3.2 25.35a9.58 9.58 0 1 1 0-19.17 9.58 9.58 0 0 1 0 19.17zm36.2-1.18V12.62l-6.4-1.7v29.81a16.09 16.09 0 0 0 0 31.53v15.82l6.4-1.68V72.26a16.09 16.09 0 0 0 0-31.52zm-3.2 25.34a9.58 9.58 0 1 1 0-19.16 9.58 9.58 0 0 1 0 19.16z"/></svg>',
'loadico':'<svg viewBox="0 0 99 99"><path d="M49.5 0A49.5 49.5 0 0199 49.5c0 5.8-1.6 15.8-4.7 19.6a50.2 50.2 0 01-50.2 8.6c19.5 3.4 34.1-12.3 34.1-28.2a28.7 28.7 0 10-57.4 0c0 24.3 33.8 47 70.7 26.1A49.5 49.5 0 1149.5 0z"/><path opacity=".08" fill="#000" d="M44.1 77.7c41.9 5.9 60.6-41.7 35-68C91 18.9 99 33.3 99 49.6c0 5.8-1.6 15.8-4.7 19.6a50.2 50.2 0 01-50.2 8.6z"/></svg>',
'arrow':'<svg viewBox="0 0 99 99"><path d="M27 78l28-29-28-28C17 10 33-8 45 4l35 37c5 5 5 12 0 17L45 95c-12 12-29-6-18-17z"/></svg>',
'check':'<svg viewBox="0 0 99 99"><path d="M97 21l-8-9c-3-3-7-3-9 0L38 55 19 36c-2-3-6-3-8 0l-9 9c-3 3-2 7 0 9l23 24 9 9c2 3 6 3 8 0l9-9 46-48c3-3 3-7 0-9z"/></svg>',
'sort':'<svg viewBox="0 0 99 99"><path d="M56 45L35 25 15 45C8 52-6 40 3 32L29 6c4-3 9-3 12 0l27 26c9 8-4 20-12 13zm-13 9l21 20 20-20c7-7 21 5 12 13L70 93c-4 3-9 3-12 0L31 67c-9-8 4-20 12-13z"/></svg>',
'refresh':'<svg viewBox="0 0 99 99"><path d="M0 55.7v31l9.2-8.5a49.5 49.5 0 0 0 89.4-22.5H86.1a37.1 37.1 0 0 1-67.7 14l15.3-14H0zM49.5 0C24.3 0 3.5 18.9.4 43.3h12.5a37.1 37.1 0 0 1 68.3-13.1L68.1 43.3H99v-31l-8.9 9A49.4 49.4 0 0 0 49.5 0z"/></svg>',
'x':'<svg viewBox="0 0 99 99"><path d="M99 77L71 50l28-28L77 0 50 28 22 0 0 22l28 28L0 77l22 22 28-28 27 28"/></svg>',
'delete':'<svg viewBox="0 0 99 99"><path d="M8 28L7 15h86l-2 13H8zM31 0l-1 10h39L68 0H31zM10 33l9 66h61l9-66H10zm18 56l-3-47h8l3 47h-8zm26 0h-9V42h9v47zm17 0h-8l3-47h8l-3 47z"/></svg>',
};
$I['load'] = '<div class="LoadCon C1fl o9 Loader">'+$I['loadico']+'</div>';
//Event Binding
window.addEventListener('resize', function(){Resize()});
document.body.addEventListener('change', function(e){
var id = ['#HeadMenu select', '#TblPagBox', '#AddrField', '#AddrRecent select', '#MinerCalcHsh', '#MinerCalcUnit', '#MinerCalcFld', '#AutoPayFld'];
for(var i = 0; i < id.length; i++){
var el = e.target.matches(id[i]);
if(el){
if(id[i] === '#HeadMenu select'){
Navigate(document.querySelector(id[i]).value);
}else if(id[i] === '#TblPagBox'){
var pge = e.target.value.replace(/\D/g,''),
typ = e.target.getAttribute('data-func');
if(typ === 'blockhistory'){
dta_Blocks(pge);
}else if(typ === 'poolpay'){
dta_Payments(pge);
}
}else if(id[i] === '#AddrField' || id[i] === '#AddrRecent select'){
addr = document.querySelector(id[i]).value;
SaveAddr(addr, 'add');
}else if(id[i] === '#MinerCalcHsh' || id[i] === '#MinerCalcUnit' || id[i] === '#MinerCalcFld'){
Dash_calc();
}else if(id[i] === '#AutoPayFld'){
AutoPayCheck();
}
}
}
}, false);
document.body.addEventListener('click', function(e){
var id = ['#TogMode','#Timer', '#DashPayBtn', '#NetGraphClose', '#NewsClose', '#InstaPayBtn', '#AutoPayBtn', '#PaymentHistoryBtn', '#PaymentHistoryBtnClose', '#EmailToggleBtn', '#AddrDelete', '#WorkerPopClose', '#WorkerSortName', '#WorkerSortRate', '.nav', '.PagBtn', '.Worker', '.blockgroup', '.helptitle'];
for(var i = 0; i < id.length; i++){
var el = e.target.closest(id[i]);
if(el){
if(id[i] === '#TogMode'){
mde = (mde === 'd') ? 'l' : 'd';
SwitchMode();
SavePref('mode', mde.toUpperCase());
}else if(id[i] === '#Timer'){
TimerLoading('on');
setTimeout(function(){
TimerUpdateData();
}, 1500);
}else if(id[i] === '#DashPayBtn'){
MinerPayments();
}else if(id[i] === '#NetGraphClose'){
netpop_open = '';
document.getElementById('GPop').classList.add('hide');
}else if(id[i] === '#NewsClose'){
document.getElementById('News').className = 'hide';
setCookie('News', $D['news']['created']);
}else if(id[i] === '#InstaPayBtn'){
InstaPay();
}else if(id[i] === '#AutoPayBtn'){
AutoPay();
}else if(id[i] === '#PaymentHistoryBtn'){
MinerPaymentHistory(1);
}else if(id[i] === '#PaymentHistoryBtnClose'){
MinerPayments('back');
}else if(id[i] === '#EmailToggleBtn'){
EmailToggle();
}else if(id[i] === '#InstaPayBtn'){
document.getElementById('MinerPaymentsMenu').innerHTML = $I['load'];
setTimeout(function(){
document.getElementById('MinerPaymentsMenu').innerHTML = '<div class="center C3'+mde+' txt">Demo - Need Endpoint</div>';
}, 1500);
}else if(id[i] === '#AddrDelete'){
SaveAddr($C['AddrField'].value, 'del');
}else if(id[i] === '#WorkerPopClose'){
Workers_detail();
}else if(id[i] === '#WorkerSortName'){
SavePref('sort', 'N'+el.getAttribute('data-ord'));
Workers_init();
}else if(id[i] === '#WorkerSortRate'){
SavePref('sort', 'R'+el.getAttribute('data-ord'));
Workers_init();
}else if(id[i] === '.nav'){
Navigate(el.getAttribute('data-tar'));
}else if(id[i] === '.PagBtn'){
var f = el.getAttribute('data-func'),
p = parseInt(el.getAttribute('data-page'));
if(f === 'poolpay'){
dta_Payments(p);
}else if(f === 'blockhistory'){
dta_Blocks(p);
}else if(f === 'pay'){
MinerPaymentHistory(p);
}
}else if(id[i] === '.Worker'){
Workers_detail(el.getAttribute('data-key'));
}else if(id[i] === '.blockgroup'){
netpop_open = el.getAttribute('data-block');
Graph_NetPop(netpop_open);
}else if(id[i] === '.helptitle'){
var b = el.querySelector('.btnback'), b_cl = 'btnback', c_cl = 'helpcontent', t_cl = 'helpteaser';
if(b.classList.contains('rot90')){
c_cl += ' hide';
}else{
b_cl += ' rot90';
t_cl += ' hide';
}
b.className = b_cl;
el.parentNode.querySelector('.helpcontent').className = c_cl;
el.parentNode.querySelector('.helpteaser').className = t_cl;
}else{
return;
}
return;
}
}
}, false);
document.body.addEventListener('keyup', function(e){
if(e.target.closest('#TblPagBox')){
PaginationBoxWidth();
return;
}
});
document.getElementById('Timer').onmouseover = function(e){
$C['TimerRefresh'].classList.remove('hide');
};
document.getElementById('Timer').onmouseout = function(e){
$C['TimerRefresh'].classList.add('hide');
};
function init(){
Localize();
//Cache Selectors
var k = Object.keys($C), i = k.length;
while(i--){
$C[k[i]] = document.getElementById(k[i]);
}
//Populate Icons
$C['TogMode'].innerHTML = $I['d'];
$C['TimerRefresh'].innerHTML = $I['refresh'];
document.getElementById('TimerLoader').innerHTML = $I['load'];
document.querySelector('#HeadMenu .select-point').innerHTML = $I['arrow'];
document.getElementById('AddrDelete').innerHTML = $I['delete'];
document.querySelector('#AddrRecent .select-point').innerHTML = $I['arrow'];
document.getElementById('DashPendingLbl').innerHTML = $$['pay']['DashPending']['lbl'];
document.getElementById('DashPaidLbl').innerHTML = $$['pay']['DashPaid']['lbl'];
Dash_btn('loading');
TimerLoading('on');
//Load Menu
var i = 0, mn = '', ft = '';
for(var m in $$['nav']){
mn += '<option value="'+m+'">'+$$['nav'][m]+'</option>';
if(i !== 0) ft += ' · ';
ft += '<span class="nav" data-tar="'+m+'">'+$$['nav'][m]+'</span>';
i++;
}
document.querySelector('#HeadMenu select').innerHTML = mn;
document.getElementById('FootR').innerHTML = ft;
//User Memory from Cookie
var cka = getCookie('Addr'),
ckp = getCookie('Pref'),
cookie_addr = '';
if(cka){
if(cka.indexOf('#') >= 0){ //multi address
var ck_arr = cka.split('#');
for(var i = 0; i < ck_arr.length; i++){
if(i === 0) cookie_addr = ck_arr[i];
$A[ck_arr[i]] = {};
}
}else{ //single address
cookie_addr = cka;
$A[cka] = {};
}
}
if(ckp) pref = ckp;
if(addr){
//override from URL param
}else if(cookie_addr){
//first addr from cookie
addr = cookie_addr;
}
if(addr){
$C['AddrField'].value = addr;
$C['AddrField'].blur();
}else{
$C['AddrField'].setAttribute('placeholder', 'Your '+$Q['cur']['nme']+' Address...');
}
if(mde === 'l' && pref && pref.charAt(0) === 'D'){
mde = 'd';
SwitchMode();
}
Dash_init();
TimerUpdateData();
}
function ErrAlert(tar, err){
var n = document.querySelector('#NetGraph svg'),
m = document.querySelector('#MinerGraph svg'),
w = document.getElementById('MinerWorkers'),
a = document.querySelectorAll('.GAlert');
if(tar === 'X'){
$C['TimerText'].innerHTML = updateTimer;
if(n != null) n.classList.remove('o3');
if(m != null) m.classList.remove('o3');
if(w != null) w.classList.remove('o3');
if(a != null && a.parentNode != null) a.parentNode.removeChild(a);
}else{
var msg = '',
iserr = 'C4',
err_msg = 'Try refreshing, check your connection; otherwise we\'ll be back up soon.';
if(tar === 'NetGraph'){
msg = 'Network API Connection Error';
if(n != null) n.classList.add('o3');
}else if(tar === 'MinerGraph'){
if(err === 'NoData'){
iserr = 'C2',
msg = 'No Data Available';
err_msg = 'Stats will appear when miner is active.';
}else{
msg = 'Miner API Connection Error';
}
if(m != null) m.classList.add('o3');
if(w != null) w.classList.add('o3');
}else{
return false;
}
if(iserr === 'C4'){
$C['TimerText'].innerHTML = '<div class="C4fl">'+$I['x']+'</div>';
$C['TimerRefresh'].classList.add('hide');
}
if(msg){
var t = document.getElementById(tar);
if(t != null) t.innerHTML += '<div class="GAlert C0bk'+mde+' '+iserr+'br center"><div class="txtmed '+iserr+'">'+msg+'</div><div class="txtsmall C3'+mde+'">'+err_msg+'</div></div>';
}
}
}
function LoadTimer(){
clearInterval(updateCounter);
TimerLoading('off');
updateCounter = setInterval(function(){
if(document.hasFocus()){
if(outoffocus > 120){
//if returning after long absence
updateTimer = 0;
outoffocus = 0;
}else{
updateTimer--;
}
}else{
if(outoffocus < 122) outoffocus++;
}
if(updateTimer <= 0){
TimerLoading('on');
clearInterval(updateCounter);
setTimeout(function(){
TimerUpdateData();
}, 1500);
}else{
var clr = (mde === 'd') ? $Q['clr']['back-d'] : $Q['clr']['back-l'],
grd = 'linear-gradient('+(-90 + (360 * updateTimer / $Q['timer']))+'deg, transparent 50%, #F06A25';
if(updateTimer < ($Q['timer'] / 2)) grd = 'linear-gradient('+(90 + (360 * updateTimer / $Q['timer']))+'deg, transparent 50%, #'+clr;
$C['TimerPie'].style.backgroundImage = grd+' 50%),linear-gradient(90deg, #'+clr+' 50%, transparent 50%)';
$C['TimerText'].innerHTML = updateTimer;
}
}, 1000);
}
function TimerLoading(sts){
var l = document.getElementById('TimerLoader');
if(sts === 'on'){
l.classList.remove('hide');
}else{
l.classList.add('hide');
}
}
function TimerUpdateData(){
api('block').then(function(){
ErrAlert('X');
}).catch(function(err){ErrAlert('NetGraph', '')});
var l = document.getElementById('MinerHashes');
if(l){
var typ = (l.innerHTML !== '--') ? 'refresh' : '';
Dash_load(typ);
}
api('net').then(function(){
api('pool').then(function(){
Graph_Net();
updateTimer = $Q['timer'];
$C['TimerText'].innerHTML = updateTimer;
LoadTimer();
}).catch(function(err){ErrAlert('NetGraph', '')});
}).catch(function(err){ErrAlert('NetGraph', '')});
if($Q['news']){
var n = document.getElementById('News'), c = document.getElementById('NewsCard'), h = '';
if(n != null && c.innerHTML === ''){
api('news').then(function(){
if($D['news'] && $D['news']['created']){
if(getCookie('News') == $D['news']['created']){
h = 'hide';
}else{
c.innerHTML = '<div class="txtmed">'+$D['news']['subject']+'<div id="NewsTime" class="txttny noselect">('+Ago($D['news']['created'], 'y')+')</div></div>'+
'<div id="NewsBody" class="txt">'+$D['news']['body'].replace(/^(<br>)/,'')+'</div>'+
'<div id="NewsClose" class="Btn32 Btn32Corner C1fl">'+$I['x']+'</div>';
}
n.className = h;
}
});
}
}
}
function Resize(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function(){
width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
Graph_Net();
Graph_Miner_init();
Workers_init();
HashTrun();
var p = document.getElementById('MinerPaymentsPage');
if(p != null) MinerPaymentHistory(p.value);
}, 250);
}
function SwitchMode(){
var $CL = ['C0','C0fl','C0bk','C0st','C3','C3fl','FLD'],
$clr = {'l':{'f':'454545','b':'efefef'},'d':{'f':'b3b3b3','b':'3b3b3b'}},
bt = (mde === 'd') ? 'l' : 'd',
i = $CL.length;
$C['TogMode'].innerHTML = $I[bt];
while(i--){
document.querySelectorAll('.'+$CL[i]+bt).forEach(function(x){
x.classList.add($CL[i]+mde);
x.classList.remove($CL[i]+bt);
});
}
document.querySelector('meta[name=theme-color]').setAttribute('content', '#'+$clr[mde]['b']);
}
function SaveAddr(adr, m){
var fin = '', fst = '', j = 0, val = '';
if(m === 'add'){
if(!$A[adr] || isEmpty($A[adr])) $A[adr] = {};
}else if(m === 'del'){
delete $A[adr];
}else{
return;
}
Dash_reset();
for(var k in $A){
if($A.hasOwnProperty(k) && j < 25){
if(j === 0){
fst = k;
fin += k;
}else{
fin += '#'+k;
}
j++;
}
}
setCookie('Addr', fin);
$C['AddrField'].value = (m === 'del') ? fst : adr;
Dash_init();
Dash_load();
MultipleAddress();
}
function SavePref(col, val){
var m = (pref[0] === 'D') ? 'D' : 'L',
s = (pref[1] === 'R') ? 'R' : 'N',
o = (pref[2] === 'D') ? 'D' : 'A',
so = s+o;
if(col === 'mode'){
m = val;
}else if(col === 'sort'){
so = val;
}
pref = m+so;
setCookie('Pref', m+so);
}
function MultipleAddress(){
var numadr = numObj($A),
r = document.getElementById('AddrRecent'),
h = 'hide';
if(numadr > 1){
ins = '<option value="">'+$$['trn']['rcnt']+'</option>';
for(var k in $A){
if($A.hasOwnProperty(k) && k !== addr){
ins += '<option value="'+k+'">'+k.substring(0, 3)+'...'+k.substr(k.length - 4)+'</option>';
}
}
r.querySelector('select').innerHTML = ins;
h = '';
}
r.parentNode.className = h;
document.getElementById('AddrDelete').parentNode.className = h;
}
function Navigate(tar){
$C['Stage'].className = '';
document.querySelectorAll('.nav').forEach(function(x){
x.classList.remove('o5');
});
setTimeout(function(){
var n = '', m = 'StageFade', h = '', d = 'LR85 C3l';
if(tar && ['blocks','payments','help'].indexOf(tar) >= 0){
n = 'short';
m += ' short';
h = '<div class="LR85"><div id="PageTopL" class="C3'+mde+' txtmed"></div><div id="PageTopR" class="right"></div></div>'+
'<div class="pbar"></div>'+
'<div id="PageBot" class="LR80 C3'+mde+' txt shim10">'+$I['load']+'</div>';
d += ' hide';
}else{
tar = 'home';
}
$C['NetGraph'].className = n;
$C['Stage'].className = m;
$C['Stage'].innerHTML = h;
$C['Addr'].className = d;
if(tar === 'blocks'){
dta_Blocks(1);
}else if(tar === 'payments'){
dta_Payments(1);
}else if(tar === 'help'){
dta_Help();
}else{
Dash_init();
Dash_load();
}
Graph_Net();
document.querySelector('#HeadMenu select').value = tar;
document.querySelector('#FootR .nav[data-tar="'+tar+'"]').classList.add('o5');
}, 300);
}
//Dash
function Dash_init(){
var $S = ['SplitL', 'SplitR'],
ins = '<div id="News" class="hide"><div id="NewsCard" class="LR85 C0bk'+mde+' C3'+mde+' shimtop20"></div></div>'+
'<div id="MinerPayments"></div>'+
'<div id="MinerGraph"></div>'+
'<div id="MinerDash" class="LR85 txtbig C3'+mde+' hide"></div>'+
'<div id="WorkerList" class="LR85 shimtop20"></div>';
$C['Stage'].innerHTML = ins;
ins = '';
for(var j = 0; j < 2; j++){
ins += '<div class="'+$S[j]+'">';
var i = 0;
for(var k in $$['sts']){
if((j === 0 && i < 2) || (j === 1 && i >= 2)){
var d = $$['sts'][k]['def'] || '--';
ins += '<div class="Spl">'+
'<div id="'+k+'">'+d+'</div>'+
'<div class="hbar shim4 o8"></div>'+
'<div class="C2 txttny">'+$$['sts'][k]['lbl']+'</div>'+
'</div>';
}
i++;
}
ins += '</div>';
}
document.getElementById('MinerDash').innerHTML = ins;
var f = document.getElementById('MinerCalcFld'),
h = document.getElementById('MinerCalcHsh'),
u = document.getElementById('MinerCalcUnit');
ins = '';
for(var k in $$['calc']){
ins += '<option value="'+k+'">'+$$['calc'][k]+'</option>';
}
f.innerHTML = ins;
f.className = 'FrmElem txttny C0'+mde+' C1bk';
ins = '';
for(var k in $D['hashconv']){
ins += '<option value="'+k+'">'+k+'/s</option>';
}
u.innerHTML = ins;
u.value = 'H';
u.className = 'FrmElem txttny C0'+mde+' C1bk';
h.className = 'FrmElem txttny C0'+mde+' C1bk';
}
function Dash_load(typ){
var m = document.getElementById('MinerGraph'),
l = document.getElementById('WorkerList'),
g = document.getElementById('MinerDash');
if(addr){
if($Q['cur']['reg'].test(addr)){
$C['AddrField'].classList.remove('C4');
if(typ !== 'refresh'){
Dash_btn('loading');
l.innerHTML = $I['load'];
}
api('account').then(function(){
if($A[addr] && $A[addr]['hashes']){
g.classList.remove('hide');
for(var k in $$['pay']){
var val = $A[addr][$$['pay'][k]['var']], dec = 8;
if(val > 99999){
dec = 4;
}else if(val > 9999){
dec = 5;
}else if(val > 999){
dec = 6;
}else if(val > 99){
dec = 7;
}
document.getElementById(k).innerHTML = Rnd(val, dec, 'txt');
}
document.getElementById('MinerHashes').innerHTML = Num($A[addr]['hashes']);
document.getElementById('MinerShares').innerHTML = $A[addr]['shares'];
if(typ !== 'refresh') Dash_btn('loaded');
Graph_Miner_init();
MultipleAddress();
api('workers', addr).then(function(){
var wcn = ($A[addr]['wrkrs'] && numObj($A[addr]['wrkrs']) > 0) ? numObj($A[addr]['wrkrs']) : 0,
plr = (wcn === 1) ? '' : 's';
document.getElementById('MinerWorkerCount').innerHTML = wcn+' Worker'+plr;
document.getElementById('MinerLastHash').innerHTML = Ago($A[addr]['last'], 'y');
Workers_init();
}).catch(function(err){console.log(err)});
}else{
Dash_reset();
m.innerHTML = '<div class="MinerMsg C3'+mde+'"><div class="txtmed">'+$$['msg']['addr_notfound']['head']+'</div><div class="LR80 txt shim10">'+$$['msg']['addr_notfound']['text']+'</div></div>';
}
}).catch(function(err){console.log(err)});
}else{
Dash_reset();
$C['AddrField'].classList.add('C4');
m.innerHTML = '<div class="MinerMsg C3'+mde+'"><div class="txtmed">'+$$['msg']['addr_invalid']['head']+'</div><div class="LR80 txt shim10">'+$$['msg']['addr_invalid']['text']+'</div></div>';
}
}else{
Dash_reset();
m.innerHTML = '<div class="MinerMsg C3'+mde+'"><div class="txtmed">'+$$['msg']['welcome']['head']+'</div><div class="LR80 txt shim10">'+$$['msg']['welcome']['text']+'</div></div>';
}
}
function Dash_reset(){
Dash_btn('inactive');
var $R = {
'WorkerList':{'v':''},
'MinerGraph':{'v':''},
'MinerPayments':{'r':'Opened','v':''},
},
k = Object.keys($R);
for(var i = 0; i < k.length; i++){
var id = k[i], el = document.getElementById(id);
el.innerHTML = $R[id]['v'];
if($R[id]['r']) el.classList.remove($R[id]['r']);
}
for(var k in $$['pay']){
var e = document.getElementById(k);
if(e) e.innerHTML = $$['pay'][k]['def'] || '--';
}
for(var k in $$['sts']){
var e = document.getElementById(k);
if(e) e.innerHTML = $$['sts'][k]['def'] || '--';
}
}
function Dash_btn(m){
var b = $C['DashPayBtn'], c = 'nopoint C2fl o5', h = $I['settings'];
if(m === 'loading'){
c = 'nopoint';
h = $I['load'];
}else if(m === 'loaded'){
c = 'C1fl hov';
}else if(m === 'closer'){
c = 'C1fl';
h = '<div class="Closer hov">'+$I['x']+'</div>';
}
b.className = c;
b.innerHTML = h;
}
function Dash_calc(){
var f = document.getElementById('MinerCalcFld'),
f_val = f.value || 1,
h = document.getElementById('MinerCalcHsh'),
h_raw = 0,
h_val = h.value || 0,
u = document.getElementById('MinerCalcUnit'),
u_val = u.value || 'H',
rew = 0;
if(h_val && h_val > 0){
h_raw = h_val * $D['hashconv'][u_val];
}else{
h_raw = document.getElementById('MinerGraphAvg').getAttribute('data-hsh') || 0;
}
var hs = HashConv(h_raw),
j = 0;
h_val = hs['num'];
u_val = hs['unit'].replace('/s', '');
h.value = h_val;
u.value = u_val;
f.value = f_val;
for(var i = 0; i < 6; i++){
if($D['block'][i]){
rew = rew + parseFloat($D['block'][i]['reward'].replace($L['dec'], '.'));
j++;
}
}
var t = h_raw / $D['net'][0]['hash'] * 1440 / $Q['cur']['blk'] * rew / j * f.value;
document.getElementById('MinerCalc').innerHTML = Rnd(t, 4, 'txt')+' '+$Q['cur']['sym'];
}
//Workers
function Workers_init(){ ///check this, getting called alot
var l = document.getElementById('WorkerList');
if($A[addr] && $A[addr]['wrkrs'] && l){
var numwrk = numObj($A[addr]['wrkrs']),
i = 0,
d = '',
ky = '',
blkclss = '',
ins = '<div id="WorkerSortGroup" class="hide txttny C2">'+
'<div id="WorkerSortName" class="C2bk C0fl'+mde+'" data-ord="D">'+$I['sort']+'</div>'+
'<div id="WorkerSortRate" class="C2bk C0fl'+mde+'" data-ord="D">'+$I['sort']+'</div>'+
'</div>'+
'<div class="WingPanel">';
srt = (pref.charAt(1) === 'R') ? 'rate' : 'name',
ord = 'A',
s = [];
if(['A','D'].indexOf(pref.charAt(2)) >= 0) ord = pref.charAt(2);
for(i = 0; i < numwrk; i++){
s.push([i, $A[addr]['wrkrs'][i][srt]]);
}
if(srt === 'name'){
s.sort(function(a, b){return a[1].toLowerCase().localeCompare(b[1].toLowerCase())});
if(ord === 'D') s.reverse();
}else if(srt === 'rate'){
if(ord === 'D'){
s.sort(function(a, b){return -(a[1] - b[1])});
}else{
s.sort(function(a, b){return a[1] - b[1]});
}
}
if(numwrk < 8) blkclss = ' WBlockFewGrid';
for(i = 0; i < numwrk; i++){
ky = s[i][0];
ins += '<div class="WorkerWrap '+blkclss+'">'+
'<div class="Worker C1br C2br_hov C3'+mde+'" data-key="'+ky+'">'+
'<div id="WName-'+ky+'" class="txtmed LblL">--</div><div id="WRate-'+ky+'" class="txtmed LblR">--</div>'+
'<div class="WorkerChart" data-worker="'+ky+'"></div>'+
'</div>'+
'</div>';
}
l.innerHTML = ins+'</div><div class="clear"></div>';
if(numwrk > 0){
var bwid = document.getElementById('WName-0').clientWidth;
for(i = 0; i < numwrk; i++){
document.getElementById('WName-'+s[i][0]).innerHTML = Truncate($A[addr]['wrkrs'][s[i][0]]['name'], Rnd(bwid / 6.25));
}
}
if(numwrk > 1){
document.getElementById('WorkerSortGroup').classList.remove('hide');
Workers_sort(srt, ord, 'n');
}
var cnt = 0;
for(i = 0; i < s.length; i++){
api('worker', s[i][0], $A[addr]['wrkrs'][s[i][0]]['name']).then(function(k){
var d = $A[addr]['wrkrs'][k],
hsh = (d && d['stats'] && d['stats'][0] && d['stats'][0]['hsh']) ? d['stats'][0]['hsh'] : 0;
if(hsh > 0){
hsh = HashConv(hsh);
document.getElementById('WRate-'+k).innerHTML = hsh['num']+' '+hsh['unit'];
if(d['stats']) Graph_Worker(k);
}else{
document.querySelector('.Worker[data-key="'+k+'"]').classList.add('C4','C4br');
}
cnt++;
if(numwrk > 1 && cnt === numwrk) Workers_sort(srt, ord, 'y');
}).catch(function(err){console.log(err)});
}
}
}
function Workers_sort(srt, ord, sts){
var n = document.getElementById('WorkerSortName'),
n_cl = 'C2bk C0fl'+mde+' hov',
n_in = $I['sort'],
r = document.getElementById('WorkerSortRate'),
r_cl = 'C2bk C0fl'+mde+' hov',
r_in = $I['load'],
ordV = (ord === 'D') ? 'A' : 'D',
orot = (ord === 'D') ? 'rot90' : 'rot270';
if(sts === 'y'){
if(srt === 'rate'){
r_cl = 'C1bk C0fl'+mde+' hov '+orot;
r_in = $I['arrow'];
}else if(srt === 'name'){
r_in = $I['sort'];
}
}else{
if(srt === 'rate') r_cl = 'C1bk C0fl'+mde+' nopoint';
}
if(srt === 'rate'){
r.setAttribute('data-ord', ordV);
}else if(srt === 'name'){
n.setAttribute('data-ord', ordV);
n_cl = 'C1bk C0fl'+mde+' hov '+orot;
n_in = $I['arrow'];
}
n.className = n_cl;
n.innerHTML = n_in;
r.className = r_cl;
r.innerHTML = r_in;
}
function Workers_detail(xid){
if(xid){
var w = document.querySelector('.Worker[data-key="'+xid+'"]'),
sts = (w.querySelector('#WorkerPop') != null) ? 'remove' : '';
}
removeElement('WorkerPop');
document.querySelectorAll('.Worker').forEach(function(x){
x.classList.remove('C1');
x.classList.add('C3'+mde);
});
if(xid && sts !== 'remove'){
w.classList.add('C1');
w.classList.remove('C3'+mde);
w.innerHTML += '<div id="WorkerPop" class="C0bk'+mde+' C1br C3'+mde+' txtsmall"></div>';
var d = $A[addr]['wrkrs'][xid],
p = document.getElementById('WorkerPop');
p.innerHTML = $I['load'];
api('workerdetail', xid, d['name']).then(function(){
var avg = 0,
havg = 0,
timestart = 99999999999999999,
cnt = numObj($A[addr]['wrkrs'][xid]['stats']),
i = cnt;
while(i--){
avg = avg + parseInt($A[addr]['wrkrs'][xid]['stats'][i]['hsh']);
SynchTime($A[addr]['wrkrs'][xid]['stats'][i]['tme']);
if($A[addr]['wrkrs'][xid]['stats'][i]['tme'] < timestart) timestart = $A[addr]['wrkrs'][xid]['stats'][i]['tme'];
}
havg = HashConv(Rnd(avg / cnt, 0));
p.innerHTML = '<div id="WorkerPopClose" class="C1fl Btn16 Btn16Corner">'+$I['x']+'</div>'+
'<div class="BoxL center">'+havg['num']+' '+havg['unit']+'</div>'+
'<div class="BoxR center">'+Ago(d['last'], 'y')+'</div>'+
'<div class="pbar shim4"></div>'+
'<div class="BoxL txttny C2 center">Avg '+Ago(timestart)+'</div>'+
'<div class="BoxR txttny C2 center">Last Share</div>'+
'<div class="shim10"></div>'+
'<div class="BoxL center">'+Num(d['hashes'])+'</div>'+
'<div class="BoxR center">'+Num(d['val'])+' / '+Num(d['inv'])+'</div>'+
'<div class="pbar shim4"></div>'+
'<div class="BoxL txttny C2 center">'+$$['sts']['MinerHashes']['lbl']+'</div>'+
'<div class="BoxR txttny C2 center">'+$$['sts']['MinerShares']['lbl']+'</div>';
}).catch(function(err){console.log(err)});
}
}
//Miner Payments
function MinerPayments(typ){
typ = typ || '';
if(addr && $A[addr] && $A[addr]['hashes'] && $A[addr]['hashes'] > 0){
var m = document.getElementById('MinerPayments'), n = document.getElementById('NewsBody');
if(typ !== 'back' && (m.classList.contains('Opened') || m.classList.contains('OpenedBig'))){
if(n) n.classList.remove('hide');
m.className = '';
m.innerHTML = '';
Dash_btn('loaded');
return;
}else{
if(n) n.classList.add('hide');
m.className = 'Opened';
m.innerHTML = '<div class="hbar"></div><div id="MinerPaymentsStage">'+$I['load']+'</div>';
Dash_btn('closer');
}
}else{
return;
}
api('user').then(function(){
var t = $Q['pay']['min_inst']+' '+$Q['cur']['sym']+' '+$$['trn']['min'],
c = 'o5 nopoint',
eml = ($Q['email']) ? 'EmailTog' : '',
ins = '';
if($A[addr]['due'] >= $Q['pay']['min_inst']){
t = 'Pay '+$A[addr]['due']+' '+$Q['cur']['sym']+' Now';
c = 'C2bk_hov';
}
ins = '<div class="LR50 shimtop20 C0'+mde+' txtmed">'+
'<div id="InstaPayBtn" class="BtnElem C1bk '+c+'">'+t+'</div><div class="hbar shim10"></div>'+
'<input type="text" id="AutoPayFld" class="FrmElem txt C0bk'+mde+' C3'+mde+' C1br" autocomplete="off" placeholder="Auto Pay Amount...">'+
'<div id="AutoPayBtn" class="BtnElem C1bk C2bk_hov o5">'+$$['trn']['set']+'</div><div class="hbar shim10"></div>'+
'</div>'+
'<div id="PaymentHistory"><div class="LR50">'+
'<div id="PaymentHistoryBtn" class="BtnElem '+eml+' C0'+mde+' txtmed C1bk C2bk_hov">'+$$['trn']['vwpy']+'</div>';
if($Q['email']){
var check = $I['x'],
lbl = $$['trn']['eml_off'];
if($A[addr]['email'] == '1'){
check = $I['check'];
lbl = $$['trn']['eml_on'];
}