forked from freakitties/freakitties.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreeding2.html
More file actions
560 lines (514 loc) · 36.7 KB
/
breeding2.html
File metadata and controls
560 lines (514 loc) · 36.7 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
<!--
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>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-116189657-1');
</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: 82px;
z-index: 2;
}
.fixed-top-2-back {
margin-top: 82px;
z-index: -1;
}
@media (max-width: 1024px) {
.fixed-top-2-front {
margin-top: 102px;
z-index: 2;
}
.fixed-top-2-back {
margin-top: 102px;
z-index: -1;
}
}
.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);
}
</style>
</head>
<script>
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
function initContract() {
clearInterval(acctInt);
$.ajax({
url: "../header.html",
cache: false,
dataType: "html",
success: function(data) {
$("#headerDiv").html(data);
let buttons = '<div class="text-white" 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 breeding pair</button> ' +
'<button class="btn btn-outline-light text-white float-right" onclick="bookmark()"><i class="fas fa-bookmark"></i> Bookmark</button>' +
'</div>';
$("#navContent").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) {autoBirthFee = result.toNumber(); } );
}
});
}
window.addEventListener('load', function () {
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 reconstructBookmark(hash) {
try {
let pairs = JSON.parse(atob(hash));
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 selfBreed(id) {
console.log("Breeding pair " + id);
var matronId = $("#matronId"+id).val().trim();
if (!isNumber(matronId)) {
setMsg(id, "Invalid matron ID");
return;
}
var sireId = $("#sireId"+id).val().trim();
if (!isNumber(sireId)) {
setMsg(id, "Invalid sire ID");
return;
}
matronId = parseInt(matronId);
sireId = parseInt(sireId);
if (autoBirthFee != 0.008*1e18) {alert("new autoBirthFee?" + autoBirthFee); return;}
coreInstance.canBreedWith(matronId, sireId, (err, result) => {
if (err) {
setMsg(id, "Error checking breedability: " + err);
return;
}
if (!result) {
console.log(result);
setMsg(id, "The pair is not breedable (this checks for ownership and some auction cases).");
return;
}
web3.eth.getBlockNumber((err, result) => {
if (err) {
console.log("Error getting block number: " + err);
alert("Error getting block number: " + err);
return;
}
if (typeof result == "number") {
checkCooldowns(id, result, function(ready) {
if (ready) {
$("#sireReady" + id).text("");
$("#matronReady" + id).text("");
coreInstance.breedWithAuto(matronId, sireId, {from: web3.eth.accounts[0], value: autoBirthFee}, (err, result) => {
if (err) {
alert(err);
return;
}
setMsg(id, "breedWithAuto Transaction ID: " + result, 'black');
});
}
});
} 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() { this.src = imgURL + matronId + ".png"; });
$("#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() { this.src = imgURL + sireId + ".png"; });
$("#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() { this.src = imgURL + ".png"; });
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>' +
'<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) {
$("#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);
bmInterval = setInterval(clearBmMsg, 3500);
}
function clearBmMsg() {
$("#bmMsg").fadeTo(1000, 0);
$("#bmTop").removeClass();
$("#bmTop").addClass("fixed-top fixed-top-2-back");
clearInterval(bmInterval);
}
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": matronId, "sireId": sireId, "notes": notes};
pairs.push(json);
}
let bmHash = "#"+btoa(JSON.stringify(pairs));
if(history.pushState) {
history.pushState(null, null, bmHash);
}
else {
location.hash = bmHash;
}
setBookmarkMsg("The URL has been updated. You can use your browser to bookmark this page and the breeding pairs will be saved.", "success");
}
function clearMsgs(id) {
setMsg(id, '');
$("#bmMsg").text("");
$("#sireReady" + id).text("");
$("#matronReady" + id).text("");
}
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("?");
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;
$("#" + type + "Ready" + id).text("Ready to breed in " + diff + " blocks.");
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) {
callback(false);
} else {
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/>
<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>
<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>