forked from freakitties/freakitties.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreeding.html
More file actions
836 lines (768 loc) · 47.9 KB
/
breeding.html
File metadata and controls
836 lines (768 loc) · 47.9 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
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
<!--
Copyright 2018 freakitties@gmail.com
You can copy and use this code if you agree to pay $1 per page load.
-->
<html>
<head>
<title>Cryptokitties Breeder</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-116189657-1"></script>
<script src="https://www.gstatic.com/firebasejs/5.4.2/firebase-app.js"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-116189657-1');
// Initialize Firebase
//Supposedly this is ok to expose...
var config = {
apiKey: "AIzaSyArHJaCBMR2_I0CvBz_9yOj043P23VTQcY",
authDomain: "breeder-93a3f.firebaseapp.com",
databaseURL: "https://breeder-93a3f.firebaseio.com",
projectId: "breeder-93a3f",
storageBucket: "breeder-93a3f.appspot.com",
messagingSenderId: "137307226712"
};
firebase.initializeApp(config);
</script>
<!--web3 v0.20.6-->
<script src="/js/web3.min.js" integrity="sha384-rXHfd7f1o1jpr3t+dYI17CkzUY3Wswo1OGbiXPGSbg4s2E42+jkRgllwt7ss2Vlq"></script>
<script src="https://cdn.rawgit.com/dcodeIO/protobuf.js/6.8.8/dist/protobuf.min.js" integrity="sha384-5dStEkuAXC5qJwZ7qXJyPslZhTKvpzs3my5U4jIjrbl/PYn3w8kilaCpCOHBSAmq" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js" integrity="sha384-feJI7QwhOS+hwpX2zkaeJQjeiwlhOP+SdQDqhgvvo1DsjtiSQByFdThsxO669S2D" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/solid.js" integrity="sha384-+Ga2s7YBbhOD6nie0DzrZpJes+b2K1xkpKxTFFcx59QmVPaSA8c7pycsNaFwUK6l" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/fontawesome.js" integrity="sha384-7ox8Q2yzO/uWircfojVuCQOZl+ZZBg2D2J5nkpLqzH1HY0C1dHlTKIbpRz/LG23c" crossorigin="anonymous"></script>
<style type="text/css">
.bg-dark {
background-color: #5a5a5a!important;
}
.btn-dark {
background-color: #5a5a5a!important;
border-color: #5a5a5a!important;
}
.default-hide {
display: none;
}
.autoBig:hover {
width: 38;
}
.autoBig:hover {
height:120;
width: 120;
}
.btn-outline-light:hover, .btn-outline-light:focus, .btn-outline-light:active, .btn-outline-light.active, .open>.dropdown-toggle.btn-outline-light {
color: #fff;
background-color: #5a6268;
border-color: #545b62;
}
.fixed-top-2-front {
margin-top: 75px;
z-index: 2;
}
.fixed-top-2-back {
margin-top: 75px;
z-index: -1;
}
@media (max-width: 1024px) {
.fixed-top-2-front {
margin-top: 150px;
z-index: 2;
}
.fixed-top-2-back {
margin-top: 150px;
z-index: -1;
}
.mobile-space {
margin-top: 50px;
}
}
.back {
position: relative;
z-index: 1;
}
body {
padding-top: 110px;
}
.boxshadow {
transition: box-shadow 400ms;
box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.1),
4px 4px 10px rgba(12, 167, 12, 0.5);
}
.green-led {
margin: 0 auto;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #80FF00;
box-shadow: #7D7B80 0 0px 1px 1px, inset #460 0 -1px 3px, #80FF00 0px 1px 0px;
}
.red-led {
margin: 0 auto;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #F00;
box-shadow: #7D7B80 0 0px 1px 1px, inset #600 0 -1px 3px, #F00 0 0px 1px 0px;
}
.orange-led {
margin: 0 auto;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #FF7000;
box-shadow: #7D7B80 0 0px 1px 1px, inset #630 0 -1px 3px, #FF7000 0px 1px 0px;
}
</style>
</head>
<script>
//XXX: ack...numPairs is number of pairs not including the first one
numPairs = 0;
core_abi = [{"constant":true,"inputs":[{"name":"_interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cfoAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_preferredTransport","type":"string"}],"name":"tokenMetadata","outputs":[{"name":"infoUrl","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"promoCreatedCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"ceoAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"GEN0_STARTING_PRICE","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"setSiringAuctionAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pregnantKitties","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_kittyId","type":"uint256"}],"name":"isPregnant","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"GEN0_AUCTION_DURATION","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"siringAuction","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"setGeneScienceAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newCEO","type":"address"}],"name":"setCEO","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newCOO","type":"address"}],"name":"setCOO","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_kittyId","type":"uint256"},{"name":"_startingPrice","type":"uint256"},{"name":"_endingPrice","type":"uint256"},{"name":"_duration","type":"uint256"}],"name":"createSaleAuction","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"sireAllowedToAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_matronId","type":"uint256"},{"name":"_sireId","type":"uint256"}],"name":"canBreedWith","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"kittyIndexToApproved","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_kittyId","type":"uint256"},{"name":"_startingPrice","type":"uint256"},{"name":"_endingPrice","type":"uint256"},{"name":"_duration","type":"uint256"}],"name":"createSiringAuction","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"val","type":"uint256"}],"name":"setAutoBirthFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"},{"name":"_sireId","type":"uint256"}],"name":"approveSiring","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newCFO","type":"address"}],"name":"setCFO","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_genes","type":"uint256"},{"name":"_owner","type":"address"}],"name":"createPromoKitty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"secs","type":"uint256"}],"name":"setSecondsPerBlock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdrawBalance","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"GEN0_CREATION_LIMIT","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"newContractAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"setSaleAuctionAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_v2Address","type":"address"}],"name":"setNewAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"secondsPerBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"tokensOfOwner","outputs":[{"name":"ownerTokens","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_matronId","type":"uint256"}],"name":"giveBirth","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdrawAuctionBalances","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"cooldowns","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"kittyIndexToOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"cooAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"autoBirthFee","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"erc721Metadata","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_genes","type":"uint256"}],"name":"createGen0Auction","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_kittyId","type":"uint256"}],"name":"isReadyToBreed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"PROMO_CREATION_LIMIT","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_contractAddress","type":"address"}],"name":"setMetadataAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"saleAuction","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getKitty","outputs":[{"name":"isGestating","type":"bool"},{"name":"isReady","type":"bool"},{"name":"cooldownIndex","type":"uint256"},{"name":"nextActionAt","type":"uint256"},{"name":"siringWithId","type":"uint256"},{"name":"birthTime","type":"uint256"},{"name":"matronId","type":"uint256"},{"name":"sireId","type":"uint256"},{"name":"generation","type":"uint256"},{"name":"genes","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_sireId","type":"uint256"},{"name":"_matronId","type":"uint256"}],"name":"bidOnSiringAuction","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"gen0CreatedCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"geneScience","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_matronId","type":"uint256"},{"name":"_sireId","type":"uint256"}],"name":"breedWithAuto","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"matronId","type":"uint256"},{"indexed":false,"name":"sireId","type":"uint256"},{"indexed":false,"name":"cooldownEndBlock","type":"uint256"}],"name":"Pregnant","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"from","type":"address"},{"indexed":false,"name":"to","type":"address"},{"indexed":false,"name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"approved","type":"address"},{"indexed":false,"name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"kittyId","type":"uint256"},{"indexed":false,"name":"matronId","type":"uint256"},{"indexed":false,"name":"sireId","type":"uint256"},{"indexed":false,"name":"genes","type":"uint256"}],"name":"Birth","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newContract","type":"address"}],"name":"ContractUpgrade","type":"event"}];
core_addr = '0x06012c8cf97bead5deae237070f9587f8e7a266d'; //main net
const proto = "message Pairs {\
repeated Pair pairs = 0;\
}\
\
message Pair {\
required int32 matronId = 0;\
required int32 sireId = 1;\
optional string notes = 2;\
}";
var source = protobuf.parse(proto);
function initContract() {
clearInterval(acctInt);
$.ajax({
url: "../header.html",
cache: false,
dataType: "html",
success: function(data) {
$("#headerDiv").html(data);
let buttons = //'<div class="text-white small" id="account"></div>' +
//'<br/>' +
'<div class="row col-12 mb-1">' +
'<button class="btn btn-outline-light text-white" onclick="createForm()"><i class="fas fa-plus-circle"></i> Add a pair</button> ' +
'<button class="btn btn-outline-light text-white float-right" onclick="bookmark()"><i class="fas fa-bookmark"></i> Bookmark</button> ' +
'<button class="btn btn-light float-right" onclick="breedAll()"><i class="fas fa-globe"></i> Breed All</button>' +
'</div>';
$("#navContentLeft").append(buttons);
if (typeof web3 == 'undefined') {
$("#account").text("Web3 enabled browser not detected.");
return;
}
if (typeof web3.eth.accounts[0] == "undefined") {
$("#account").text("Can't detect your account. Unlock your wallet or try reloading the page and waiting a few seconds.");
return;
} else {
$("#account").text("Your Account: " + web3.eth.accounts[0]);
}
coreContract = web3.eth.contract(core_abi);
coreInstance = coreContract.at(core_addr);
coreInstance.autoBirthFee(function(error, result) {
if (error) {
alert(error);
}
autoBirthFee = result.toNumber();
//check breedability
breedAll(true);
setInterval(function() {breedAll(true)}, 300000);
} );
}
});
}
var BigNumber;
window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(ethereum);
BigNumber = web3.BigNumber;
try {
// Request account access if needed
await ethereum.enable();
console.log("modern dapp browser");
} catch (error) {
// User denied account access...
console.log("User denied ethereum account access.")
}
}
// Legacy dapp browsers...
else if (window.web3) {
window.web3 = new Web3(web3.currentProvider);
BigNumber = web3.BigNumber;
// Acccounts always exposed
console.log("legacy dapp browser");
}
// Non-dapp browsers...
else {
console.log('Non-Ethereum browser detected.');
//since we are using our own web3.min.js
let w3 = new Web3();
BigNumber = w3.BigNumber;
}
checkEthGas();
acctInt = setInterval(initContract, 250);
$('[data-toggle="tooltip"]').tooltip();
var hash = window.location.hash.substr(1);
if (hash == "") {
return;
}
reconstructBookmark(hash);
$('[data-toggle="tooltip"]').tooltip();
});
function checkEthGas() {
$.getJSON("https://ethgasstation.info/json/ethgasAPI.json", (ethGas) => {
if (isNaN(ethGas.average)) {
alert("Couldn't get the gas cost from ethGasStation");
return;
}
let gasPriceGwei = Math.round( (ethGas.average/10 + 0.1) * 100) / 100;
$("#customGas").val(gasPriceGwei);
}).fail(() => {
alert("Failed to get ethGasPrice from ethgasstation");
});
}
function breedAll(checkOnly=false) {
for (let i = 0; i <= numPairs; i++) {
var matronId = $("#matronId" + i).val().trim();
var sireId = $("#sireId" + i).val().trim();
if (matronId && sireId) {
selfBreed(i, checkOnly);
}
}
}
function reconstructBookmark(hash) {
var pairs;
try {
pairs = JSON.parse(atob(hash));
} catch (err) {
pairs = source.root.Pairs.decode(b64ToArr(hash)).pairs;
}
try {
for (let i = 0; i < pairs.length; i++) {
let matronId = pairs[i].matronId;
let sireId = pairs[i].sireId;
let notes = pairs[i].notes;
if (i != 0) {
createForm();
}
setFormValues(numPairs, matronId, sireId, notes);
}
} catch (err) {
console.log("Error reconstructing bookmark: " + err);
}
}
function isNumber(str) {
if (str.match("^[0-9]+$")) return true;
return false;
}
function setMsg(id, msg, type = "error") {
var box = $("#msg" + id);
box.text(msg);
box.removeClass();
if (msg == "") return;
if (type == "error") {
box.addClass("alert alert-danger");
} else {
box.addClass("alert alert-success");
}
}
function setBreedStatus(id, color) {
$("#breedStatus" + id).removeClass();
if (color == "red") {
$("#breedStatus" + id).addClass("red-led float-right");
} else if (color == "green") {
$("#breedStatus" + id).addClass("green-led float-right");
} else {
$("#breedStatus" + id).addClass("orange-led float-right");
}
}
var feeAlerted = false;
function selfBreed(id, checkOnly=false) {
if (!checkOnly) console.log("Breeding pair " + id);
var matronId = $("#matronId"+id).val().trim();
if (!isNumber(matronId)) {
setMsg(id, "Invalid matron ID");
setBreedStatus(id, "red");
return;
}
var sireId = $("#sireId"+id).val().trim();
if (!isNumber(sireId)) {
setMsg(id, "Invalid sire ID");
setBreedStatus(id, "red");
return;
}
matronId = parseInt(matronId);
sireId = parseInt(sireId);
if (autoBirthFee != 0.008*1e18) {
if (!feeAlerted) {
feeAlerted = true;
alert("Birthing fee has changed to: " + autoBirthFee);
/*return;*/
}
}
coreInstance.canBreedWith(matronId, sireId, (err, result) => {
if (err) {
setMsg(id, "Error checking breedability: " + err);
setBreedStatus(id, "red");
return;
}
if (!result) {
setMsg(id, "The pair is not breedable (this checks for ownership and some auction cases).");
setBreedStatus(id, "red");
return;
}
web3.eth.getBlockNumber((err, result) => {
if (err) {
console.log("Error getting block number: " + err);
alert("Error getting block number: " + err);
setBreedStatus(id, "orange");
return;
}
if (typeof result == "number") {
//checkCooldowns will setBreedStatus
checkCooldowns(id, result, function(ready) {
if (ready) {
if (checkOnly) {
$("#sireReady" + id).text("");
$("#matronReady" + id).text("");
} else {
$("#sireReady" + id).text("");
$("#matronReady" + id).text("");
let gasPriceGwei = parseFloat($("#customGas").val());
let gasPrice = gasPriceGwei * 1e9;
coreInstance.breedWithAuto(matronId, sireId, {from: web3.eth.accounts[0], value: autoBirthFee, gasPrice: gasPrice}, (err, result) => {
if (err) {
//alert(err);
console.log(err);
return;
}
setMsg(id, "breedWithAuto Transaction ID: " + result, 'black');
$("#sireReady" + id).text("Just bred");
$("#matronReady" + id).text("Just bred");
setBreedStatus(id, "red");
});
}
}
});
} else {
console.log("Unknown result type");
}
});
});
}
function setFormValues(index, matronId, sireId, notes) {
matronId = parseInt(matronId);
sireId = parseInt(sireId);
$("#matronId" + index).val(matronId);
$("#sireId" + index).val(sireId);
$("#notes" + index).val(notes);
let imgURL = "https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/";
//This doesn't work right for early exclusives and fancies...both svg and png exist for those early cats.
$("#matronImg" + index).attr("src", imgURL + matronId + ".svg");
$("#matronImg" + index).on("error", function() {
var url = imgURL + matronId + ".png";
$.get(url).done(function() {
this.src = url;
}).fail(function() {
return;
});
});
$("#matronImg" + index).show();
$("#matronImgLink" + index).attr("href", "https://www.cryptokitties.co/kitty/" + matronId);
$("#sireImg" + index).attr("src", imgURL + sireId + ".svg");
$("#sireImg" + index).on("error", function() {
var url = imgURL + sireId + ".png";
$.get(url).done(function() {
this.src = url;
}).fail(function() {
return;
});
});
$("#sireImg" + index).show();
$("#sireImgLink" + index).attr("href", "https://www.cryptokitties.co/kitty/" + sireId);
}
function handleChange(id, type) {
clearMsgs(id);
var img = null;
var kittyId = null;
var imgLink = null;
if (type == "matron") {
img = $("#matronImg" + id);
imgLink = $("#matronImgLink" + id);
kittyId = $("#matronId"+id).val().trim();
} else if (type == "sire") {
img = $("#sireImg" + id);
imgLink = $("#sireImgLink" + id);
kittyId = $("#sireId"+id).val().trim();
}
if (img == null || kittyId == null || !isNumber(kittyId)) {
if (img != null) {
img.attr("src", "");
img.hide();
imgLink.attr("href", "");
}
return;
}
let imgURL = "https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/" + kittyId;
img.attr("src", imgURL + ".svg");
img.on("error", function() {
var url = imgURL + ".png";
$.get(url).done(function() {
this.src = url;
}).fail(function() {
return;
});
});
imgLink.attr("href", "https://www.cryptokitties.co/kitty/" + kittyId);
img.show();
}
function createForm() {
numPairs++;
var template =
'<div id="pair{ID}">' +
'<div class="col-md-9 border" onmouseover="$(\'#upButton{ID}\').show();$(\'#downButton{ID}\').show();$(\'#closeButton{ID}\').show();" onmouseout="$(\'#upButton{ID}\').hide();$(\'#downButton{ID}\').hide();$(\'#closeButton{ID}\').hide();" >' +
'<div class="d-flex" id="buttons{ID}">' +
'<div data-toggle="tooltip" data-placement="left" title="Move pair up" class="p-1"><i class="default-hide mt-1 float-left fas fa-arrow-circle-up" id="upButton{ID}" onclick="movePairUp({ID});"></i></div>' +
'<div data-toggle="tooltip" data-placement="left" title="Move pair down" class="mr-auto p-1"><i class="default-hide mt-1 float-left fas fa-arrow-circle-down" id="downButton{ID}" onclick="movePairDown({ID});"></i></div>' +
'<div data-toggle="tooltip" data-placement="right" title="Remove pair" class="p-2"><i class="default-hide mt-1 float-right fas fa-times-circle" id="closeButton{ID}" onclick="removePair({ID});"></i></div>' +
'</div>' +
'<div class="col-12">' +
'<div id="breedStatus{ID}" class="float-right"></div>' +
'</div>' +
'<br/>' +
'<div class="form-group row mb-1 mr-1">' +
'<label class="col-form-label col-md-3" for="notes{ID}">Notes for pair {ID}</label>' +
'<textarea class="form-control col-md-9" type="text" placeholder="Notes about this pair. Not used in TX." id="notes{ID}"></textarea>' +
'</div>' +
'<div class="form-group row mb-1 mr-1">' +
'<label class="col-form-label col-md-3" for="matronId{ID}">Matron ID</label>' +
'<input class="form-control col-md-2" type="text" id="matronId{ID}" onchange="handleChange({ID}, \'matron\');"/>' +
'<a target="_blank" id="matronImgLink{ID}" href=""><img class="autoBig" height="38" src="" style="display: none;" id="matronImg{ID}"/></a>' +
'<div class="col-md-5 col-form-label-sm" id="matronReady{ID}"></div>' +
'</div>' +
'<div class="form-group row mb-1 mr-1">' +
'<label class="col-form-label col-md-3" for="sireId{ID}">Sire ID</label>' +
'<input class="form-control col-md-2" type="text" id="sireId{ID}" onchange="handleChange({ID}, \'sire\');"/>' +
'<a target="_blank" id="sireImgLink{ID}" href=""><img class="autoBig" height="38" src="" style="display: none;" id="sireImg{ID}"/></a>' +
'<div class="col-md-5 col-form-label-sm" id="sireReady{ID}"></div>' +
'</div>' +
'<button type="submit" class="btn btn-secondary" onclick="selfBreed({ID});" id="breedButton{ID}">Breed Pair {ID}</button> ' +
'<button type="submit" class="btn btn-light" onclick="openCalc({ID});" id="CalcButton{ID}">Check KittyCalc</button>' +
'<br/>' +
'<br/><div id="msg{ID}"></div>' +
'</div>' +
'<br/>' +
'</div>';
newForm = template.replace(/{ID}/g, numPairs);
$("#breedersDiv").append(newForm);
}
var bmInterval;
function setBookmarkMsg(msg, type, timeout) {
$("#bmTop").removeClass();
$("#bmTop").addClass("fixed-top fixed-top-2-front");
$("#bmMsg").removeClass();
$("#bmMsg").text("");
if (type == "warning") {
$("#bmMsg").addClass("alert alert-warning");
$("#bmMsg").text(msg);
$("#bmMsg").alert();
} else if (type == "success") {
$("#bmMsg").addClass("alert alert-success");
$("#bmMsg").text(msg);
$("#bmMsg").alert();
}
$("#bmMsg").fadeTo(0, 1);
if (timeout) {
bmInterval = setInterval(clearBmMsg, timeout);
} else {
bmInterval = setInterval(clearBmMsg, 3500);
}
}
function clearBmMsg() {
$("#bmMsg").fadeTo(1000, 0);
$("#bmTop").removeClass();
$("#bmTop").addClass("fixed-top fixed-top-2-back");
clearInterval(bmInterval);
}
function updateClipboard(newClip) {
navigator.clipboard.writeText(newClip).then(function() {
/* clipboard successfully set */
}, function() {
/* clipboard write failed */
alert("failed to copy url to clipboard");
});
}
function arrToB64 (arrayBuffer) {
return btoa(new Uint8Array(arrayBuffer).reduce((data, byte) => data + String.fromCharCode(byte), ''));
}
function b64ToArr (str) {
return atob(str).split('').map(function (c) { return c.charCodeAt(0); });
}
function bookmark() {
$("#bmMsg").text("");
var pairs = [];
for (let i = 0; i <= numPairs; i++) {
if ($("#pair" + i).length == 0) continue;
let matronId = $("#matronId" + i).val().trim();
if (!isNumber(matronId)) {
setBookmarkMsg("Matron ID is invalid in pair " + i, "warning");
return;
}
let sireId = $("#sireId" + i).val().trim();
if (!isNumber(sireId)) {
setBookmarkMsg("Sire ID is invalid in pair " + i, "warning");
return;
}
let notes = $("#notes" + i).val();
console.log(matronId + ", " + sireId + " : " + notes);
let json = {"matronId": parseInt(matronId), "sireId": parseInt(sireId), "notes": notes};
pairs.push(json);
}
//let bmHash = "#"+btoa(JSON.stringify(pairs));
let buf = source.root.Pairs.fromObject({pairs: pairs});
let bin = source.root.Pairs.encode(buf).finish();
let bmHash = "#" + arrToB64(bin);
if(history.pushState) {
history.pushState(null, null, bmHash);
}
else {
location.hash = bmHash;
}
$.ajax({
method: "POST",
url: "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + config.apiKey,
data: JSON.stringify({"dynamicLinkInfo": {"dynamicLinkDomain": "cryptokitties.page.link","link": location.href}}),
contentType: 'application/json'
}).done(function( data ) {
navigator.permissions.query({name: "clipboard-write"}).then(result => {
if (result.state == "granted" || result.state == "prompt") {
updateClipboard(data.shortLink);
setBookmarkMsg("The URL has been updated. Bookmark this URL to access your saved breeding pairs. Here's a short link: " + data.shortLink + " It's also been saved to your clipboard.", "success", 7000);
} else {
setBookmarkMsg("The URL has been updated. Bookmark this URL to access your saved breeding pairs. Here's a short link: " + data.shortLink, "success", 10000);
}
});
}).fail(function (xhr, textStatus, errorThrown) {
//alert("Failed to generate a short URL. " + textStatus + " " + xhr.responseText);
console.log("Failed to generate a short URL. " + textStatus + " " + xhr.responseText);
setBookmarkMsg("The URL has been updated. Bookmark this URL to access your saved breeding pairs. However, a short URL could not be created due to too many breeding pairs.", "success");
});
}
function clearMsgs(id) {
setMsg(id, '');
$("#bmMsg").text("");
$("#sireReady" + id).text("");
$("#matronReady" + id).text("");
}
function blocksToTime(numBlocks) {
let timeLeft = numBlocks * 15;
let out = "";
if (Math.floor(timeLeft / 86400) > 0) {
let days = Math.floor(timeLeft / 86400);
out += days + "d";
let hours = Math.floor(timeLeft % 86400 / 3600);
if (hours > 1) {
out += " " + hours + "h";
}
} else if (Math.floor(timeLeft / 3600) > 0) {
let hours = Math.floor(timeLeft / 3600);
out += hours + "h";
let minutes = Math.floor(timeLeft % 3600 / 60);
if (minutes > 1) {
out += " " + minutes + "m";
}
} else if (Math.floor(timeLeft / 60) > 0) {
let minutes = Math.floor(timeLeft / 60);
out += minutes + "m";
} else {
out = "less than a minute";
}
return out;
}
function checkCatCooldown(id, catId, type, currentBlock, callback) {
if (type != "sire" && type != "matron") return;
coreInstance.getKitty(catId, (err, result) => {
if (err) {
console.log("Error getting kitty: " + err);
$("#" + type + "Ready" + id).text("?");
setBreedStatus(id, "orange");
callback(false);
return;
}
var nextActionAt = result[3].toNumber();
if (currentBlock >= nextActionAt) {
//$("#" + type + "Ready" + id).text("Ready to breed");
callback(true);
} else {
let diff = nextActionAt - currentBlock;
let timeLeft = blocksToTime(diff);
$("#" + type + "Ready" + id).text("Ready to breed in " + diff + " blocks. (~" + timeLeft + ")");
callback(false);
}
});
}
function checkCooldowns(index, currentBlock, callback) {
let matronId = $("#matronId" + index).val().trim();
if (!isNumber(matronId)) {
return;
}
let sireId = $("#sireId" + index).val().trim();
if (!isNumber(sireId)) {
return;
}
checkCatCooldown(index, matronId, "matron", currentBlock, function(matronReady) {
checkCatCooldown(index, sireId, "sire", currentBlock, function(sireReady) {
if (matronReady == false || sireReady == false) {
setBreedStatus(index, "red");
callback(false);
} else {
setBreedStatus(index, "green");
callback(true);
}
});
});
}
function removePair(id) {
let div = $("#pair" + id);
if (div.length > 0) {
div.remove();
}
}
function swapPair(id1, id2) {
let notes1 = $("#notes" + id1).val();
let matronId1 = parseInt($("#matronId" + id1).val());
let sireId1 = parseInt($("#sireId" + id1).val());
let notes2 = $("#notes" + id2).val();
let matronId2 = parseInt($("#matronId" + id2).val());
let sireId2 = parseInt($("#sireId" + id2).val());
if (isNaN(matronId1)) {
setMsg(id1, "Invalid matron ID");
return;
}
if (isNaN(sireId1)) {
setMsg(id1, "Invalid sire ID");
return;
}
if (isNaN(matronId2)) {
setMsg(id2, "Invalid matron ID");
return;
}
if (isNaN(sireId2)) {
setMsg(id2, "Invalid sire ID");
return;
}
setFormValues(id1, matronId2, sireId2, notes2);
setFormValues(id2, matronId1, sireId1, notes1);
setMsg(id1, "");
setMsg(id2, "");
}
function movePairDown(id) {
if (id < numPairs) {
let divTop = $("#pair" + id);
if (divTop.length == 0) return;
let bottomID = id + 1;
let divBottom = $("#pair" + bottomID);
while (divBottom.length == 0 && bottomID < numPairs) {
bottomID++;
divBottom = $("#pair" + bottomID);
}
if (divBottom.length == 0) return;
swapPair(id, bottomID);
let margin = $("#bmTop").css("margin-top");
$("#pair" + bottomID).children().addClass("boxshadow");
$('html, body').animate({scrollTop: $("#pair" + bottomID).offset().top - parseInt(margin.slice(0, margin.length - 2))}, 400, function() {
let intID = setInterval(function() {
clearInterval(intID);
$("#pair" + bottomID).children().removeClass("boxshadow");
}, 2000);
});
}
}
function movePairUp(id) {
if (id > 0) {
let divBottom = $("#pair" + id);
if (divBottom.length == 0) return;
let topID = id - 1;
let divTop = $("#pair" + topID);
while (divTop.length == 0 && topID > 0) {
topID--;
divTop = $("#pair" + topID);
}
if (divTop.length == 0) return;
swapPair(id, topID);
let margin = $("#bmTop").css("margin-top");
$("#pair" + topID).children().addClass("boxshadow");
$('html, body').animate({scrollTop: $("#pair" + topID).offset().top - parseInt(margin.slice(0, margin.length - 2))}, 400, function() {
let intID = setInterval(function() {
clearInterval(intID);
$("#pair" + topID).children().removeClass("boxshadow");
}, 2000);
});
}
}
function openCalc(id) {
let matronId = $("#matronId" + id).val().trim();
if (!isNumber(matronId)) {
setMsg(id, "Invalid matron ID");
return;
}
let sireId = $("#sireId" + id).val().trim();
if (!isNumber(sireId)) {
setMsg(id, "Invalid sire ID");
return;
}
window.open("https://kittycalc.co/?k1=" + sireId + "&k2=" + matronId);
}
</script>
<body>
<!-- header -->
<div class="fixed-top" id="headerDiv"></div>
<div class="fixed-top fixed-top-2-back" id="bmTop">
<div class="alert" role="alert" id="bmMsg"></div>
</div>
<div id="breedersDiv" class="container back">
<br/>
<br/>
<div class="row">
<div class="text-left col-6 col-form-label mobile-space" id="account"></div><br/><br/>
</div>
<div class="col-6 row">
<label for="customGas" class="col-form-label col-sm-4 col-lg-3">Gas Price:</label>
<input class="form-control col-sm-4 col-lg-3" type="text" id="customGas" value="5">
</div>
<br>
<div id="pair0">
<div class="col-md-9 border" onmouseover="$('#upButton0').show();$('#downButton0').show();$('#closeButton0').show();" onmouseout="$('#upButton0').hide();$('#downButton0').hide();$('#closeButton0').hide();" >
<div class="d-flex" id="buttons0">
<div data-toggle="tooltip" data-placement="left" title="Move pair up" class="p-1"><i class="default-hide mt-1 float-left fas fa-arrow-circle-up" id="upButton0" onclick="movePairUp(0);"></i></div>
<div data-toggle="tooltip" data-placement="left" title="Move pair down" class="mr-auto p-1"><i class="default-hide mt-1 float-left fas fa-arrow-circle-down" id="downButton0" onclick="movePairDown(0);"></i></div>
<div data-toggle="tooltip" data-placement="right" title="Remove pair" class="p-2"><i class="default-hide mt-1 float-right fas fa-times-circle" id="closeButton0" onclick="removePair(0);"></i></div>
</div>
<div class="col-12">
<div id="breedStatus0" class="float-right"></div>
</div>
<br/>
<div class="form-group row mb-1 mr-1">
<label class="col-form-label col-md-3" for="notes0">Notes for pair 0</label>
<textarea class="form-control col-md-9" type="text" placeholder="Notes about this pair. Not used in TX." id="notes0"></textarea>
</div>
<div class="form-group row mb-1 mr-1">
<label class="col-form-label col-md-3" for="matronId0">Matron ID</label>
<input class="form-control col-md-2" type="text" id="matronId0" onchange="handleChange(0, 'matron');"/><a target="_blank" id="matronImgLink0" href=""><img class="autoBig" height="38" src="" style="display: none;" id="matronImg0"/></a><div class="col-md-5 col-form-label-sm" id="matronReady0"></div>
</div>
<div class="form-group row mb-1 mr-1">
<label class="col-form-label col-md-3" for="sireId0">Sire ID</label>
<input class="form-control col-md-2" type="text" id="sireId0" onchange="handleChange(0, 'sire');"/><a target="_blank" id="sireImgLink0" href=""><img class="autoBig" height="38" src="" style="display: none;" id="sireImg0"/></a><div class="col-md-5 col-form-label-sm" id="sireReady0"></div>
</div>
<button type="submit" class="btn btn-secondary" onclick="selfBreed(0);" id="breedButton0">Breed Pair 0</button>
<button type="submit" class="btn btn-light" onclick="openCalc(0);" id="CalcButton0">Check KittyCalc</button>
<br/>
<br/>
<div id="msg0"></div>
</div>
<br/>
</div>
</div>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</body>
</html>