forked from HaJaeKyung/KittyExtension
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript
456 lines (424 loc) Β· 21.4 KB
/
script
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
// ==UserScript==
// @name Crypto Kitty Info Extension
// @namespace https://github.com/HaJaeKyung/KittyExtension
// @version 0.31
// @description Adds stat info to the site
// @author HaJaeKyung
// @match *.cryptokitties.co/*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require http://code.jquery.com/jquery-3.2.1.min.js
// ==/UserScript==
/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext: false */
/* jshint esversion: 6 */
// Your code here...
/* jshint ignore:start */
]]></>).toString();
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
/* jshint ignore:end */
$(document).ready(() => {
console.log('CryptoKitties Extension Loaded');
$("head").append("<style> .extAttUl { overflow: visible; z-index: 3; padding: 0px; margin: 0px; } </style>");
$("head").append("<style> .extAtt { min-width: 75px; padding-left: 2px; padding-right: 2px; color: rgba(255,255,255, 0.99); text-align: center; line-height: 1.85rem; font-size: 1.6rem; border-style: solid; border-color: rgba(66, 66, 66, 0.35); border-width: 1.5px; border-radius: 20px; background-color: #00bcd4; } </style>");
$("head").append("<style> .extBounce {animation: mover 1s infinite alternate; padding-right: 2px;} @keyframes mover {0% { transform: translateY(0); }100% { transform: translateY(-6px); } </style>");
$("head").append("<style> .extWrapper {position:absolute; bottom: 0; right: 0; display: flex; flex-direction: row-reverse; align-items: flex-end; } </style>");
$("head").append("<style> .extUSD { z-index: 100; position:absolute; top:0; left:0; box-shadow: 0 3px rgba(143, 141, 138, 0.6); border-width: 0.5px; background-color: #dff7f1; } </style>");
$("head").append("<style> .extUSD:focus { outline:0; } .extUSD:active { box-shadow: 0 1px rgba(143, 141, 118, 0.6); transform: translateY(2px);} .extUSD:hover {background-color:#dff7f1;}</style>");
$("head").append("<style> .extCD { font-size: 1.1rem; font-weight: 100; } </style>");
$("head").append("<style> .KittyCard { overflow: visible; } </style>");
const version = "0.31";
let foundId = [];
let curCat = 'n/a';
let curId = 'n/a';
let hasChanged = false;
let ethPrice = false;
let url = location.href;
let restrictAPI = 0;
document.body.addEventListener('click', () => {
requestAnimationFrame(()=> {
if (url!==location.href) {
//Clears id cache on page change
foundId = [];
url = location.href;
}
});
}, true);
let tbl = {"oldlace":{"count":0.017},"wolfgrey":{"count":0.0421},"gerbil":{"count":0.0754},"cottoncandy":{"count":0.13},"violet":{"count":0.2525},"wingtips":{"count":0.267},"mainecoon":{"count":0.4731},"jaguar":{"count":0.8789},"cerulian":{"count":1.0146},"chartreux":{"count":1.3721},"googly":{"count":1.4286},"fabulous":{"count":1.509},"whixtensions":{"count":1.651},"peach":{"count":3.1255},"bubblegum":{"count":3.4188},"dali":{"count":3.5325},"otaku":{"count":4.0565},"skyblue":{"count":4.8908},"gold":{"count":5.0987},"bloodred":{"count":5.2143},"scarlet":{"count":5.306},"tigerpunk":{"count":5.4725},"limegreen":{"count":5.8042},"beard":{"count":6.6335},"cloudwhite":{"count":6.9049},"emeraldgreen":{"count":7.1863},"laperm":{"count":7.5752},"spock":{"count":7.5966},"calicool":{"count":7.6506},"barkbrown":{"count":7.7587},"chestnut":{"count":8.5854},"tongue":{"count":9.2476},"mauveover":{"count":9.6534},"cymric":{"count":11.437},"shadowgrey":{"count":13.4737},"coffee":{"count":13.5572},"saycheese":{"count":14.4958},"salmon":{"count":14.6102},"royalpurple":{"count":14.9337},"mintgreen":{"count":15.7441},"swampgreen":{"count":16.1462},"chocolate":{"count":16.1606},"lemonade":{"count":16.4333},"sphynx":{"count":16.5715},"topaz":{"count":16.6437},"simple":{"count":16.765},"orangesoda":{"count":17.0533},"aquamarine":{"count":17.304},"greymatter":{"count":17.3587},"munchkin":{"count":17.6967},"raisedbrow":{"count":18.5435},"happygokitty":{"count":19.4054},"soserious":{"count":19.6398},"strawberry":{"count":20.2291},"ragamuffin":{"count":20.3453},"sizzurp":{"count":20.9509},"himalayan":{"count":21.047},"pouty":{"count":21.7745},"crazy":{"count":26.5899},"thicccbrowz":{"count":27.3055},"luckystripe":{"count":28.8785},"kittencream":{"count":40.046},"granitegrey":{"count":40.8979},"totesbasic":{"count":45.9847}};
function saveStorage(id, cattributes) {
if (window.location.pathname == "/my-kitties") {
storageMyTbl['id'+id] = cattributes;
localStorage.setItem('kittyExtensionMyTbl', JSON.stringify(storageMyTbl));
} else {
storageTbl['id'+id] = cattributes;
if (Object.keys(storageTbl).length > 1000) {
for (let first in storageTbl) break;
delete storageTbl[first];
}
localStorage.setItem('kittyExtensionTbl', JSON.stringify(storageTbl));
}
}
function checkVersion(){
if(hasLocalStorage){
let savedVersion = localStorage.getItem('kittyExtensionVersion') || 0;
if (savedVersion !== version){
localStorage.setItem('kittyExtensionTbl', JSON.stringify({}));
localStorage.setItem('kittyExtensionMyTbl', JSON.stringify({}));
localStorage.setItem('kittyExtensionVersion', version);
console.log('New version loaded:',version);
}
}
}
let hasLocalStorage = typeof(Storage) !== "undefined";
checkVersion();
let storageTbl = JSON.parse(localStorage.getItem('kittyExtensionTbl')) || {};
let storageMyTbl = JSON.parse(localStorage.getItem('kittyExtensionMyTbl')) || {};
let currency = localStorage.getItem('kittyExtensionEtherUSD') || "π²π";
$.get("https://api.coinmarketcap.com/v1/ticker/ethereum/", data => {
ethPrice = parseFloat(data[0].price_usd);
$("body").append("<button onclick='switchPrice(event)' class='extUSD extAtt'>"+currency+"</button>");
changePrices();
});
function getColor(catt) {
let color, count;
if (tbl[catt]) {
if (tbl[catt].count <= 0.15) {
color = "#ff0dbf"; // legendary
} else if (tbl[catt].count <= 1.8) {
color = "#ff8000"; // legendary
} else if (tbl[catt].count < 8) {
color = "#a335ee"; // epic
} else if (tbl[catt].count <= 16) {
color = "#0070ff"; // rare
} else if (tbl[catt].count <= 20) {
color = "white"; // common
} else {
color = "white"; // common
}
count = tbl[catt].count < 1 ? tbl[catt].count.toFixed(3) : tbl[catt].count.toFixed(1);
count = tbl[catt].count <= 20 ? " ("+ count +"%)" : " (20%+)";
} else {
color = "rgba(255,255,255, 0.98)";
count = " (Ultra%)";
}
return [color, count];
}
function requestId(element, stats) {
$.getJSON( "https://api.cryptokitties.co/kitties/"+stats.id, data => {
finalizeOverlay(data.cattributes, element, stats);
if (hasLocalStorage) {
if (data.children.length === 0) {
let ul = element.getElementsByClassName("extWrapper")[0];
ul.innerHTML += "<ul class='extAttUl'><li style='list-style: none;' class='extAtt'><span style='font-weight: 500;'> virgin </span></li></ul>";
}
if (!data.status.is_ready) {
let note = element.getElementsByClassName('KittyStatus-note');
let cd = (((data.status.cooldown - Date.now())/6000/600));
let time = timeDisplay(cd * 3600);
note[note[1] ? 1 : 0].textContent = time;
}
saveStorage(stats.id, data.cattributes);
}
}).fail(() => {
let ul = element.getElementsByClassName("extAttUl")[0];
ul.classList.remove("extBounce");
ul.innerHTML = "πΏ";
});
}
function timeDisplay(seconds) {
if (typeof seconds === "number") {
seconds = Math.floor(seconds);
let hourS = seconds / 3600;
let minute = Math.floor(seconds / 60);
let second = seconds % 60;
second = second < 10 ? '0'+second : second;
if (hourS> 1) {
let hour = Math.floor(seconds / 3600);
minute = minute % 60;
minute = minute < 10 ? '0' + minute : minute;
if (hourS > 24) {
return hour + ' hours';
} else {
return hour + ':' + minute;
}
} else {
return minute + ' minutes';
}
} else {
return '';
}
}
function finalizeOverlay(cattributes, element, stats) {
let ul = element.getElementsByClassName("extAttUl")[0];
ul.classList.remove("extBounce");
ul.innerHTML = "";
for (let x in cattributes) {
if (cattributes[x]) {
let background_color = getColor(cattributes[x].description)[0];
let color = background_color == 'white' ? 'rgba(0,0,0, 0.76)' : 'rgba(255,255,255, 0.98)';
ul.innerHTML += "<li class='extAtt' style=\'background-color:"+background_color+"; color: "+color+"\'>"+cattributes[x].description+"</li>";
}
}
//if (window.location.hostname == 'www.cryptokitties.co') {
//calcPrice(stats.id , cattributes, stats, element);
//}
}
function isValidId(id) {
return !isNaN(id) && id !== "" && id.substring(0,2) != "0x" && id != curId && !foundId.includes(id) && !document.URL.includes("activity");
}
//Creates overlay on hover
var timer = Date.now();
function overlay() {
let nativeElement = $( this )[0];
let id = /[^/]*$/.exec(nativeElement)[0];
if (isValidId(id)) {
curId = id;
foundId.push(id);
let mainSite = window.location.hostname == 'www.cryptokitties.co';
let element = mainSite ? nativeElement.getElementsByClassName('KittyCard')[0] : nativeElement;
if (element) {
let stats = {"id": curId, "fast":false, "gen": false, "cd": false};
if (mainSite) {
let status = nativeElement.getElementsByClassName('KittyCard-status')[0];
if (status) {
stats.cd = status.innerHTML.includes("Resting");
}
let speed = nativeElement.getElementsByClassName('KittyCard-coldown')[0];
if (speed) {
let cdTbl = ["Fast", "Swift", "Snappy", "Brisk", "Plodding", "Slow", "Sluggish", "Catatonic"];
stats.fast = cdTbl.indexOf(speed.innerText);
}
stats.gen = nativeElement.getElementsByClassName('KittyCard-subname')[0].innerText.split('Gen ').pop();
}
element.innerHTML += "<div class='extWrapper'><ul style='list-style: none;' class='extBounce extAttUl'>π</ul></div>";
setTimeout(()=> {
console.log('KittyExtension: Requesting - '+ id);
requestId(element, stats);
}, timer - Date.now());
restrictAPI += 1000;
setTimeout(()=> {
restrictAPI -= 1000;
}, 1000);
timer = Date.now() + restrictAPI;
}
}
}
$( "body").on( "mouseover", "a", overlay);
$("body").on("mouseover", '.KittyCard-wrapper', function(){$(this).find('.extWrapper').show();});
$("body").on('mouseout','.KittyCard-wrapper',function(){$(this).find('.extWrapper').hide();});
//Updates attributes on specific kitty page
setInterval(() => {
let curPage = document.getElementsByClassName("KittyHeader-details");
if (curPage.length > 0 && curPage[0].innerHTML.substr(0, curPage[0].innerHTML.indexOf('</span>')) != curCat) {
curCat = curPage[0].innerHTML.substr(0, curPage[0].innerHTML.indexOf('</span>'));
if (document.getElementsByClassName("ListAttributes-item").length > 0) {
let cattributes = document.getElementsByClassName("ListAttributes-item");
for (let att in cattributes) {
if (cattributes[att].style) {
let catt = cattributes[att].innerText;
let arr = getColor(catt);
let color = arr[0];
let num = arr[1];
cattributes[att].style.backgroundColor = color;
cattributes[att].style.color = color == 'white' ? '#000' : '#fff';
cattributes[att].innerHTML += num;
}
}
}
}
}, 2000);
function calcPrice(id, cattributes, stats, element) {
let base = "https://api.cryptokitties.co/auctions";
let query = "?type=sale&limit=15&sorting=cheap&orderBy=current_price&orderDirection=asc&sorting=cheap&status=open&search=";
let totalGen = ' gen:'+stats.gen;
if (stats.gen >= 10) {
totalGen += ' gen:'+(stats.gen-1)+' gen:';
totalGen += parseInt(stats.gen)+1;
}
let rareTbl = getBestRares(cattributes);
let search = totalGen + rareTbl[0];
function finishPrice(data, index) {
let newMultiplier = stats.id == data.auctions[index].kitty.id ? 1 : rareTbl[1];
let nomralizePrice = data.auctions[index].current_price/1000000000000000000;
return (nomralizePrice*newMultiplier).toFixed(2);
}
$.getJSON( base+query+search, (data) => {
if (data.total > 0) {
if (data.total == 1) {
if (data.auctions[0].kitty.id == id) {
renderPrice(element, 'Name your price', query + search, false);
} else {
renderPrice(element, finishPrice(data, 0), query + search, true);
}
} else {
let cdTbl = ["Fast", "Swift", "Snappy", "Brisk", "Plodding", "Slow", "Sluggish", "Catatonic"];
let cdValueTbl = ["Fast","Swift","Swift","Snappy","Snappy","Brisk","Brisk","Plodding","Plodding","Slow","Slow","Sluggish","Sluggish","Catatonic"];
for (let x in data.auctions) {
let cdValue = cdTbl.indexOf(cdValueTbl[data.auctions[x].kitty.status.cooldown_index]);
if (stats.cd && stats.fast > 1) {
renderPrice(element, finishPrice(data, x), query + search, false);
return;
} else if (stats.fast > 4 || stats.fast >= cdValue) {
renderPrice(element, finishPrice(data, x), query + search, false);
return;
} else if (stats.cd && data.auctions[x].kitty.status.is_ready) {
renderPrice(element, finishPrice(data, x), query + search, false);
return;
} if (x == data.auctions.length - 1) {
renderPrice(element, finishPrice(data, x), query + search, true);
return;
}
}
}
} else {
renderPrice(element, 'Name your price', query + search, false);
}
}).fail(() => {
});
}
function renderPrice(element, price, url, fast) {
if (price >= 50) {
price = Math.ceil(price / 10) * 10;
price += '+';
} else if (fast) {
price += '+';
}
let ul = element.getElementsByClassName("extWrapper")[0];
ul.innerHTML += "<ul class='extAttUl' onclick='searchSimilarKitties(event, ""+ url +"")'><li style='list-style: none;' class='extAtt'><span style='font-weight: 500;'>Score:</span> " + price + "</li></ul>";
}
function getBestRares(cattributes, adjust) {
let newCatts = [];
for (let single in cattributes) {
newCatts.push(cattributes[single].description);
}
cattributes = newCatts;
let best = '';
let hasRare = false;
let count = adjust || 0;
if (cattributes.length === 0) {
hasRare = ' type:fancy';
}
for (let x in cattributes) {
if (!tbl[cattributes[x]]) {
best += ' ' + x;
count += 3;
hasRare = ' ' + x;
}
}
let score = 0;
let multiplier = 1;
let multCount = 0;
for (let key1 in tbl) {
if (tbl[key1].count) {
for (let key in cattributes) {
if (tbl[key1].count <= 0.4) {
multiplier *= 1.55;
} else if(tbl[key1].count <= 1.8) {
multiplier *= 1.25;
} else if (tbl[key1].count <= 5) {
multiplier *= 1.05;
} else if (tbl[key1].count <= 10) {
multiplier *= 1.025;
}
}
}
}
console.log(multiplier);
for (let key in tbl) {
if (cattributes.includes(key)) {
if (tbl[key].count <= 1.2) {
} else if (tbl[key].count <= 6) {
}
}
if (count >= 3) {
return [' ' + best, multiplier];
}
}
let attrCount = 0;
cattributes.forEach((key)=>{
if (tbl[key]) {
if (tbl[key].count <= 0.4) {
attrCount += 3;
} else if(tbl[key].count <= 1.8) {
attrCount += 2;
} else if (tbl[key].count <= 5) {
attrCount += 1;
} else if (tbl[key].count <= 10) {
attrCount += 1;
} else {
score += 0;
}
} else {
attrCount += 5;
}
score = ((attrCount/6)*7)+1;
console.log(score);
if (cattributes.length === 0) {
score = 8;
} else if (cattributes.length > 8) {
score -= cattributes.length - 8;
}
});
console.log('score',score);
return score;
}
document.searchSimilarKitties = (e, query) => {
e.preventDefault();
window.location.href = "https://www.cryptokitties.co/marketplace/sale" + query;
};
function changePrices() {
let items = document.getElementsByClassName('KittyStatus-itemText');
if (ethPrice && items.length > 0 && document.getElementsByClassName('extUSD').length > 0) {
for (let item of items) {
if (item.parentElement.parentElement.className == "KittyStatus" || item.parentElement.parentElement.className == "KittyStatus KittyStatus--list") {
if (!item.parentElement.innerHTML.includes("Icon--timer") && !item.parentElement.innerHTML.includes('Bun in oven')) {
let cur = item.getElementsByTagName('span')[0].innerText.split(' ');
if (currency == "π²π" && cur[0] != "$") {
let endPrice = (cur[1] * ethPrice ).toFixed(2);
if (endPrice != 'NaN') {
item.getElementsByTagName('span')[0].innerText = '$ ' + endPrice;
}
} else if (currency == "π²π" && cur[0] != "Ξ") {
let endPrice = (cur[1] / ethPrice ).toFixed(4);
if (endPrice != 'NaN') {
item.getElementsByTagName('span')[0].innerText = 'Ξ ' + endPrice;
}
}
} else {
}
}
}
}
}
let saleNum = 0;
document.switchPrice = (e) => {
e.preventDefault();
hasChanged = true;
let element = document.getElementsByClassName('extUSD')[0];
currency = currency == "π²π" ? "π²π" : "π²π";
localStorage.setItem('kittyExtensionEtherUSD', currency);
element.innerText = currency;
changePrices();
};
$(document).bind('DOMSubtreeModified',function(){
let items = document.getElementsByClassName('KittyStatus-itemText');
if (items.length != saleNum) {
saleNum = items.length;
if (hasChanged || currency == "π²π") {
changePrices();
}
}
let mItems = document.getElementsByClassName('KittyStatus KittyStatus--multiple');
[...mItems].forEach((i)=>{
let replace = i.children[1].innerHTML.replace("Resting", "");
let hasText = i.children[1].getElementsByClassName("KittyStatus-note")[0];
if(hasText && hasText.textContent && hasText.textContent !== '') {
i.children[1].innerHTML = replace;
}
i.classList.remove('KittyStatus--multiple');
});
});
});