Repository navigation
Expand file tree
/
Copy pathBlookJS.js
More file actions
2253 lines (2116 loc) · 153 KB
/
Copy pathBlookJS.js
File metadata and controls
2253 lines (2116 loc) · 153 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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(() => {
if (window.BlookJS && typeof window.BlookJS.destroy === "function") window.BlookJS.destroy();
const CHOICE_SELECTOR = '[class*="_choiceInside_"]';
const HACK_BUTTON_SELECTOR = '[class*="_buttonContainer_"] [class*="_button_"]';
const PUMPKIN_SELECTOR = '[class*="_choice1_"], [class*="_choice2_"], [class*="_choice3_"]';
const wrongGuesses = new Map();
const flags = { skip: false, prize: false, random: false, cont: false };
const timers = { attach: null, loop: null, refresh: null };
let observer = null;
let menuHost = null;
let refreshMenu = () => {};
let removeKeyHandler = () => {};
let attachedRoom = null;
let cachedCtx = null;
let cachedAt = 0;
let selfCache = null;
let lastPrize = null;
let lastHackOptions = null;
let lastGuess = null;
let auto = false;
let questAuto = false;
let prizeDelay = 450;
let prizeAttempt = null;
let cryptoAttempt = null;
let cryptoFresh = false;
let wasPrizeStage = false;
let removeHackClick = () => {};
let cryptoSkipTypes = [];
const cflags = { skip: false, prize: false, random: false, cont: false };
const GUESS_WAIT = 4500;
let answered = null;
let seenQuestion = null;
let lastAnswerScan = 0;
let contState = null;
let lastContinue = 0;
let answerDelay = 0;
let destroyed = false;
const fflags = { fish: false, random: false, cont: false, reveal: false, skip: false };
const gflags = { random: false, cont: false };
let lobbyBusy = false;
let fakeOn = false;
const fakeAdded = new Map();
let lastActionVia = "";
let fakeTimer = null;
const kflags = { serve: false, ask: false };
let lastCafe = 0;
let lastAsk = 0;
const lastServe = new Map();
const armedSell = { kind: null, until: 0 };
let lastFish = 0;
let onlineType = null;
let lastReveal = 0;
let lastSkipTick = 0;
let distractHash;
let fontFaces = [];
let unlimitedMinutes = false;
let removeMinutesGuard = () => {};
let distractHashAt = 0;
let lastPress = null;
const prizeTable = [
{ type: "gold", val: 10, text: "+ 10 Candy" },
{ type: "gold", val: 20, text: "+ 20 Candy" },
{ type: "gold", val: 30, text: "+ 30 Candy" },
{ type: "gold", val: 40, text: "+ 40 Candy" },
{ type: "gold", val: 50, text: "+ 50 Candy" },
{ type: "gold", val: 100, text: "+ 100 Candy" },
{ type: "multiply", val: 2, text: "Double Candy!", blook: "Mummy" },
{ type: "multiply", val: 3, text: "Triple Candy!", blook: "Werewolf" },
{ type: "give", val: 0.1, text: "Lose 10% to the King", blook: "Zombie" },
{ type: "give", val: 0.25, text: "Lose 25% to the King", blook: "Vampire Bat" },
{ type: "jackpot", text: "Pumpkin King's Treasure!", blook: "goldKing" },
{ type: "swap", text: "SWAP!", blook: "Ghost" },
{ type: "take", val: 0.1, text: "Take 10%", blook: "Frankenstein" },
{ type: "take", val: 0.25, text: "Take 25%", blook: "Vampire" },
{ type: "nothing", text: "Nothing!", blook: "Pumpkin" },
];
const rootFiber = () => {
const holders = [
document.getElementById("root"),
document.getElementById("__next"),
document,
document.body,
document.documentElement,
];
for (const holder of holders) {
if (!holder) continue;
const key = Object.keys(holder).find(k => k.startsWith("__reactContainer$"));
if (!key) continue;
const host = holder[key];
return host && host.stateNode && host.stateNode.current ? host.stateNode.current : host;
}
return null;
};
const walk = visit => {
const start = rootFiber();
if (!start) return;
const stack = [start];
while (stack.length) {
const fiber = stack.pop();
if (visit(fiber.memoizedProps, fiber)) return;
if (fiber.sibling) stack.push(fiber.sibling);
if (fiber.child) stack.push(fiber.child);
}
};
const findContext = () => {
let found = null;
let fallback = null;
walk(props => {
const value = props && props.value;
if (value && value.room && typeof value.send === "function") {
if (value.userId) {
found = value;
return true;
}
if (!fallback) fallback = value;
}
return false;
});
return found || fallback;
};
const getCtx = () => {
const now = Date.now();
if (now - cachedAt < (cachedCtx ? 1500 : 500)) return cachedCtx;
cachedCtx = findContext();
cachedAt = now;
return cachedCtx;
};
const send = (type, payload) => {
if (destroyed) return false;
const ctx = getCtx();
if (!ctx) return false;
ctx.send(type, payload);
return true;
};
const plain = value => (value && typeof value.toJSON === "function" ? value.toJSON() : value);
const stageIs = (player, name) => Boolean(player) && String(player.stage || "").toLowerCase() === name;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const hackButtons = () => [...document.querySelectorAll(HACK_BUTTON_SELECTOR)];
const isNothing = prize => Boolean(prize) && (prize.type === "nothing" || /^nothing\b/i.test(String(prize.text || "")));
const questSkippable = prize => Boolean(prize) && (prize.type === "give" || isNothing(prize));
const cryptoSkippable = prize => Boolean(prize) && (cryptoSkipTypes.includes(prize.type) || isNothing(prize));
const me = () => {
const ctx = getCtx();
if (!ctx) return null;
if (selfCache && selfCache.room === ctx.room && selfCache.player.sessionId === ctx.room.sessionId) {
return selfCache.player;
}
const players = ctx.room.state.players;
let player = ctx.userId ? players.get(ctx.userId) : null;
if (!player) {
players.forEach(p => {
if (!player && p.sessionId && p.sessionId === ctx.room.sessionId) player = p;
});
}
selfCache = player ? { room: ctx.room, player } : null;
return player || null;
};
const allPlayers = () => {
const ctx = getCtx();
const out = {};
if (ctx) ctx.room.state.players.forEach((p, id) => (out[id] = plain(p)));
return out;
};
const paint = prize => {
const text = String(prize.text ?? prize.type ?? "");
document.querySelectorAll(CHOICE_SELECTOR).forEach(el => {
if (el.textContent !== text) el.textContent = text;
});
};
const entryFor = index => {
if (typeof index !== "number") return null;
return { index, ...(prizeTable[index] || { type: "unknown", text: "Unknown (" + index + ")" }) };
};
const questPrize = () => {
const player = me();
return player ? entryFor(player.pendingPrizeIndex) : null;
};
const paintQuest = prize => {
const text = prize.text.replace(/\n/g, " ");
document.querySelectorAll(PUMPKIN_SELECTOR).forEach(el => {
let tag = el.querySelector("[data-blookjs]");
if (!tag) {
if (getComputedStyle(el).position === "static") el.style.position = "relative";
tag = document.createElement("div");
tag.setAttribute("data-blookjs", "");
Object.assign(tag.style, {
position: "absolute",
left: "0",
right: "0",
bottom: "0",
padding: "6px 14px",
background: "#18181b",
color: "#fafafa",
borderRadius: "12px",
fontFamily: "'BlookJS Nunito', 'Nunito', system-ui, sans-serif",
fontWeight: "700",
fontSize: "14px",
textAlign: "center",
pointerEvents: "none",
zIndex: "5",
});
el.appendChild(tag);
}
if (tag.textContent !== text) tag.textContent = text;
});
};
const skipPrize = (force = false) => {
const prize = questPrize();
const player = me();
if (!prize || !player) return Promise.resolve({ sent: false, reason: "no pending prize" });
if (player.stage !== "prize") return Promise.resolve({ sent: false, reason: "not on prize stage", prize });
if (!force && !questSkippable(prize)) return Promise.resolve({ sent: false, reason: "prize is not skippable", prize });
const stageBefore = player.stage;
const sent = send("playerGetNewQuestion", {});
return new Promise(resolve => {
setTimeout(() => {
const after = me();
const stageAfter = after ? after.stage : null;
resolve({ sent, prize, stageBefore, stageAfter, worked: stageAfter !== stageBefore });
}, 800);
});
};
const pickPrize = () => {
const player = me();
if (!player) return Promise.resolve({ sent: false, reason: "not in a game" });
if (player.stage !== "prize") return Promise.resolve({ sent: false, reason: "not on prize stage" });
const prize = questPrize();
if (!send("revealPrize", {})) return Promise.resolve({ sent: false, reason: "not in a game" });
return new Promise(resolve => {
setTimeout(() => {
const sent = send("claimPrize", {});
resolve({ sent, prize, reason: sent ? undefined : "not in a game" });
}, prizeDelay);
});
};
const readQuestion = () => {
let props = null;
walk(p => {
if (p && Array.isArray(p.questions) && typeof p.sendAnswer === "function") {
props = p;
return true;
}
return false;
});
if (!props) return null;
const index = typeof props.currentIndex === "number" ? props.currentIndex : props.questions.length - 1;
const question = props.questions[index];
if (!question) return null;
const choices = Array.isArray(question.answers) ? question.answers.map(String) : [];
const feedback = props.feedbacks ? props.feedbacks[index] : undefined;
return { props, index, question, choices, feedback, done: Boolean(feedback) };
};
const questionKey = info => info.index + ":" + (info.question.number ?? "") + ":" + info.question.text;
const pressKey = key => {
window.dispatchEvent(new KeyboardEvent("keydown", { key, code: "Digit" + key, bubbles: true, cancelable: true }));
};
const randomAnswerTick = () => {
const now = Date.now();
if (now - lastAnswerScan < 40) return;
lastAnswerScan = now;
const info = readQuestion();
if (!info) {
answered = null;
seenQuestion = null;
return;
}
const key = questionKey(info);
if (info.done) {
answered = null;
return;
}
if (!info.choices.length) return;
if (!seenQuestion || seenQuestion.key !== key) seenQuestion = { key, due: now + answerDelay };
if (now < seenQuestion.due) return;
if (!answered || answered.key !== key) {
const position = Math.floor(Math.random() * info.choices.length);
answered = { key, at: now, via: position < 4 ? "key" : "direct", position };
if (position >= 4) {
info.props.sendAnswer(info.choices[position]);
return;
}
}
if (answered.via !== "key") return;
if (now - answered.at > 2000) {
answered = { ...answered, via: "direct" };
info.props.sendAnswer(info.choices[answered.position]);
return;
}
pressKey(String(answered.position + 1));
};
const continueTick = () => {
const now = Date.now();
if (now - lastContinue < 40) return;
lastContinue = now;
const info = readQuestion();
if (!info || !info.done) {
contState = null;
return;
}
const key = questionKey(info);
if (!contState || contState.key !== key) contState = { key, sends: 0, last: 0 };
if (contState.sends >= 6 || now - contState.last < 400) return;
contState.sends += 1;
contState.last = now;
if (contState.sends === 1 && typeof info.props.sendAnswerNext === "function") {
info.props.sendAnswerNext();
return;
}
window.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
};
const FISH_ODDS = [
[["Old Boot", 15], ["Waffle", 5], ["Two of Spades", 5], ["Jellyfish", 15], ["Clownfish", 15], ["Goldfish", 10], ["Frog", 15], ["Blizzard Clownfish", 5], ["Turtle", 5], ["Cat", 5], ["Lovely Frog", 3], ["Lucky Frog", 1], ["Poison Dart Frog", 1]],
[["Old Boot", 3], ["Waffle", 1], ["Two of Spades", 1], ["Jellyfish", 10], ["Clownfish", 5], ["Goldfish", 3], ["Frog", 10], ["Blizzard Clownfish", 7], ["Turtle", 4], ["Cat", 3], ["Lovely Frog", 6], ["Lucky Frog", 1], ["Poison Dart Frog", 5], ["Seal", 5], ["Walrus", 5], ["Fairy", 2], ["Crab", 10], ["Lemon Crab", 7], ["Pufferfish", 7], ["Blobfish", 5]],
[["Jellyfish", 5], ["Frog", 5], ["Blizzard Clownfish", 2], ["Turtle", 1], ["Cat", 1], ["Lovely Frog", 1], ["Lucky Frog", 1], ["Poison Dart Frog", 2], ["Seal", 5], ["Walrus", 5], ["Fairy", 2], ["Crab", 10], ["Lemon Crab", 6], ["Pufferfish", 10], ["Blobfish", 10], ["Rainbow Jellyfish", 6], ["Octopus", 15], ["Pirate Pufferfish", 4], ["Donut Blobfish", 4], ["Crimson Octopus", 5]],
[["Seal", 3], ["Walrus", 3], ["Fairy", 2], ["Crab", 5], ["Lemon Crab", 2], ["Pufferfish", 8], ["Blobfish", 8], ["Rainbow Jellyfish", 10], ["Octopus", 15], ["Pirate Pufferfish", 8], ["Donut Blobfish", 8], ["Crimson Octopus", 7], ["Narwhal", 8], ["Baby Shark", 7], ["Megalodon", 6]],
[["Crab", 1], ["Lemon Crab", 1], ["Pufferfish", 1], ["Blobfish", 3], ["Rainbow Jellyfish", 6], ["Octopus", 12], ["Pirate Pufferfish", 8], ["Donut Blobfish", 8], ["Crimson Octopus", 10], ["Narwhal", 17], ["Baby Shark", 14], ["Megalodon", 12], ["Alien", 1.2], ["Rainbow Narwhal", 4.25], ["UFO", 1], ["Santa Claus", 0.1], ["Swamp Monster", 0.1], ["Red Astronaut", 0.1], ["Spooky Pumpkin", 0.1], ["Dragon", 0.1], ["Tim the Alien", 0.05]],
];
const soloFishState = () => {
let found = null;
walk((props, fiber) => {
if (props && fiber && typeof props.setWeight === "function" && typeof props.endGame === "function" && "weight" in props) {
found = { props, fiber };
return true;
}
return false;
});
if (!found) return null;
const hooks = [];
let hook = found.fiber.memoizedState;
while (hook && hooks.length < 40) {
hooks.push(hook.memoizedState);
hook = hook.next;
}
const valid = typeof hooks[1] === "number" && typeof hooks[2] === "boolean" && typeof hooks[3] === "number"
&& typeof hooks[4] === "boolean" && typeof hooks[5] === "boolean" && typeof hooks[6] === "boolean"
&& typeof hooks[11] === "string" && typeof hooks[12] === "boolean";
if (!valid) return null;
const stage = stageOf({
question: hooks[12],
text: hooks[11],
caught: hooks[7],
claimReady: hooks[6],
hooked: hooks[4],
isCast: hooks[2],
castReady: hooks[5],
});
const caught = hooks[9];
let prize = null;
if (caught && typeof caught === "object") {
prize = { name: caught.name, rarity: caught.rarity, tier: caught.tier, weight: caught.weight };
} else if (caught === "Lure Upgrade") {
prize = { name: "Lure Upgrade", rarity: "Upgrade", weight: 0 };
} else if (caught === "Frenzy") {
prize = { name: "Frenzy!", rarity: "Special", weight: 0 };
}
return {
stage,
online: false,
weight: found.props.weight,
prize,
lure: hooks[3],
frenzy: hooks[1] > Date.now(),
secondsLeft: typeof hooks[13] === "number" ? hooks[13] : null,
};
};
const stageOf = st => {
if (st.question) return "Question";
if (st.caught) return st.claimReady ? "Claim" : "Caught";
if (st.hooked) return "Hooked";
if (st.isCast) return "Casting";
if (st.text === "lost" && !st.castReady) return "Lost";
if (st.castReady) return "Ready";
return "Idle";
};
const hookList = fiber => {
const list = [];
let hook = fiber.memoizedState;
while (hook && list.length < 40) {
list.push(hook.memoizedState);
hook = hook.next;
}
return list;
};
const looksOnline = h => typeof h[0] === "number" && typeof h[1] === "number" && typeof h[2] === "number"
&& typeof h[3] === "boolean" && typeof h[4] === "boolean" && typeof h[5] === "boolean" && typeof h[6] === "boolean"
&& typeof h[7] === "string" && typeof h[9] === "boolean" && typeof h[11] === "boolean" && typeof h[12] === "string"
&& (h[8] === null || typeof h[8] === "object" || typeof h[8] === "string");
const findOnlineHooks = () => {
let result = null;
walk((props, fiber) => {
if (!fiber || typeof fiber.type !== "function" || !fiber.memoizedState) return false;
if (onlineType && fiber.type !== onlineType) return false;
const list = hookList(fiber);
if (!looksOnline(list)) return false;
onlineType = fiber.type;
result = list;
return true;
});
return result;
};
const activeDistractions = () => {
const ctx = getCtx();
const out = [];
if (!ctx || !ctx.room.state.distractions) return out;
const now = Date.now();
ctx.room.state.distractions.forEach((d, id) => {
if (d.endTime > now) out.push({ id, fish: d.fishName, by: d.triggeredBy, secondsLeft: Math.ceil((d.endTime - now) / 1000) });
});
return out;
};
const onlineFishState = player => {
const ctx = getCtx();
const h = findOnlineHooks();
const question = Boolean(player.inQuestion);
const stage = h
? stageOf({ question, text: h[12], caught: h[7], claimReady: h[6], hooked: h[4], isCast: h[3], castReady: h[5] })
: (question ? "Question" : "Idle");
let prize = null;
if (player.pendingFishIsLureUpgrade) {
prize = { name: "Lure Upgrade", rarity: "Upgrade", weight: 0 };
} else if (player.pendingFishIsFrenzy) {
prize = { name: "Frenzy!", rarity: "Special", weight: 0 };
} else if (player.pendingFishName) {
prize = {
name: player.pendingFishName,
rarity: player.pendingFishRarity,
tier: player.pendingFishTier,
weight: player.pendingFishWeight,
special: Boolean(player.pendingFishIsSpecial),
};
} else if (h && h[8] && typeof h[8] === "object") {
prize = { name: h[8].name, rarity: h[8].rarity, tier: h[8].tier, weight: h[8].weight, special: Boolean(h[8].isSpecial) };
}
return {
stage,
online: true,
weight: player.weight,
prize,
lure: player.lure,
frenzy: Boolean(ctx && ctx.room.state.frenzyEndTime > Date.now()),
secondsLeft: h && typeof h[10] === "number" ? h[10] : null,
distractions: activeDistractions(),
};
};
const fishState = () => {
const player = me();
if (player && typeof player.pendingFishName === "string") return onlineFishState(player);
return soloFishState();
};
const NO_DISTRACT_ID = "blookjs-nodistract";
const findDistractHash = () => {
for (const sheet of Array.from(document.styleSheets)) {
let rules;
try {
rules = sheet.cssRules;
} catch (error) {
continue;
}
for (const rule of Array.from(rules || [])) {
const match = /\._crabDance1_([a-z0-9]+)_\d+/.exec(rule.selectorText || "");
if (match) return match[1];
}
}
return null;
};
const hideDistractions = () => {
if (document.getElementById(NO_DISTRACT_ID)) return;
const now = Date.now();
if (distractHash === undefined || (distractHash === null && now - distractHashAt > 3000)) {
distractHash = findDistractHash();
distractHashAt = now;
}
if (distractHash) {
const style = document.createElement("style");
style.id = NO_DISTRACT_ID;
style.textContent = '[class*="_wrapper_' + distractHash + '_"] { display: none !important; }';
document.head.appendChild(style);
return;
}
walk((props, fiber) => {
if (props && typeof props.fish === "string" && !("lureLevel" in props) && fiber.child) {
let node = fiber.child;
while (node && !(node.stateNode && node.stateNode.nodeType === 1)) node = node.child;
if (node && node.stateNode.style) node.stateNode.style.display = "none";
return true;
}
return false;
});
};
const showDistractions = () => {
const style = document.getElementById(NO_DISTRACT_ID);
if (style) style.remove();
};
const fishSkipTick = () => {
const now = Date.now();
if (now - lastSkipTick < 150) return;
lastSkipTick = now;
hideDistractions();
};
const fishRevealTick = () => {
const now = Date.now();
if (now - lastReveal < 150) return;
lastReveal = now;
const st = fishState();
let badge = document.querySelector('[data-blookjs="reveal"]');
if (!st || !st.online || !st.prize) {
if (badge) badge.remove();
return;
}
if (!badge) {
badge = document.createElement("div");
badge.setAttribute("data-blookjs", "reveal");
Object.assign(badge.style, {
position: "fixed",
top: "12px",
left: "50%",
transform: "translateX(-50%)",
padding: "8px 18px",
background: "#18181b",
color: "#fafafa",
borderRadius: "12px",
fontFamily: "'BlookJS Nunito', 'Nunito', system-ui, sans-serif",
fontWeight: "800",
fontSize: "15px",
pointerEvents: "none",
whiteSpace: "nowrap",
zIndex: "2147482000",
});
document.body.appendChild(badge);
}
const text = "Next: " + fishPrizeText(st.prize) + (st.prize.rarity ? " - " + st.prize.rarity : "");
if (badge.textContent !== text) badge.textContent = text;
};
const PROTECTED_RARITIES = ["Legendary", "Chroma", "Mystical", "Unique"];
const SELL_ACTION_ID = "504d5bfe3d4b01def79630a2138ec4f50f85bee9";
const BUY_PACK_ACTION_ID = "07f506cbf77b3c76f2fe32f5e1ef295935f4c113";
const webpackRequires = () => {
const out = [];
Object.keys(window).filter(k => k.startsWith("webpackChunk")).forEach(k => {
const chunk = window[k];
if (!chunk || typeof chunk.push !== "function") return;
try {
chunk.push([[Symbol("blookjs")], {}, r => {
out.push(r);
}]);
} catch (error) {
return;
}
});
return out;
};
const findCallServer = () => {
const info = { globals: Object.keys(window).filter(k => k.startsWith("webpackChunk")), requires: 0, cached: 0, fn: null };
for (const req of webpackRequires()) {
info.requires += 1;
const cache = req.c || {};
for (const id of Object.keys(cache)) {
info.cached += 1;
let fn = null;
try {
const entry = cache[id];
fn = entry && entry.exports && entry.exports.callServer;
} catch (error) {
fn = null;
}
if (typeof fn === "function") {
info.fn = fn;
return info;
}
}
const factories = req.m || {};
for (const id of Object.keys(factories)) {
let text = "";
try {
text = String(factories[id]);
} catch (error) {
text = "";
}
if (text.indexOf("getServerActionDispatcher") === -1 || text.indexOf("callServer") === -1) continue;
try {
const mod = req(id);
if (mod && typeof mod.callServer === "function") {
info.fn = mod.callServer;
return info;
}
} catch (error) {
continue;
}
}
}
return info;
};
const fetchAction = async (id, fields) => {
const body = new FormData();
body.append("0", JSON.stringify([{ message: "", status: "idle" }, "$K1"]));
Object.keys(fields).forEach(key => body.append("1_" + key, fields[key]));
const response = await fetch(window.location.pathname + window.location.search, {
method: "POST",
headers: { Accept: "text/x-component", "Next-Action": id },
body,
credentials: "same-origin",
});
const text = await response.text();
const chunks = {};
text.split("\n").forEach(line => {
const match = /^([0-9a-f]+):(.*)$/.exec(line);
if (match) chunks[match[1]] = match[2];
});
if (!Object.keys(chunks).length) throw new Error("server action request failed (HTTP " + response.status + ")");
let root = null;
try {
root = JSON.parse(chunks["0"] || "null");
} catch (error) {
root = null;
}
const ref = root && typeof root.a === "string" ? root.a.replace(/^\$@?/, "") : "1";
const raw = chunks[ref];
if (raw === undefined) throw new Error("unexpected server response (HTTP " + response.status + ")");
if (raw.charAt(0) === "E") throw new Error("the server threw an error (HTTP " + response.status + ")");
const value = JSON.parse(raw);
return typeof value === "string" ? null : value;
};
const runAction = async (id, fields) => {
const info = findCallServer();
if (info.fn) {
const form = new FormData();
Object.keys(fields).forEach(key => form.append(key, fields[key]));
try {
lastActionVia = "callServer";
return await info.fn(id, [{ message: "", status: "idle" }, form]);
} catch (error) {
if (!/dispatcher/i.test(String(error && error.message))) throw error;
}
}
lastActionVia = "fetch";
return fetchAction(id, fields);
};
const readActionResult = result => {
if (!result || typeof result !== "object") return { ok: false, error: "no response from the server" };
let data = null;
if (typeof result.message === "string") {
try {
data = JSON.parse(result.message);
} catch (error) {
data = null;
}
}
if (result.error || result.status === "error") {
return { ok: false, error: String(result.error || result.message || "the server rejected the request") };
}
if (data && typeof data === "object") return { ok: true, data };
return { ok: false, error: String(result.message || result.status || "unexpected response") };
};
const lobbyLock = async run => {
if (lobbyBusy) return { ok: false, error: "another Lobby action is still running" };
lobbyBusy = true;
try {
return await run();
} catch (error) {
return { ok: false, error: error && error.message ? error.message : String(error) };
} finally {
lobbyBusy = false;
}
};
const marketState = () => {
let found = null;
walk(props => {
if (props && Array.isArray(props.packs) && typeof props.setUserTokens === "function" && "userTokens" in props) {
found = props;
return true;
}
return false;
});
return found;
};
const packKey = name => String(name || "").trim().toLowerCase().replace(/\s*pack$/, "");
const findPack = (state, wanted) => state.packs.find(p => packKey(p.name) === packKey(wanted)) || null;
const buyPacks = async (packName, amountRaw, report) => {
const state = marketState();
if (!state) return { ok: false, error: "open the Market page first" };
if (!String(packName || "").trim()) return { ok: false, error: "type a pack name" };
const pack = findPack(state, packName);
if (!pack) {
return { ok: false, error: 'no pack named "' + String(packName).trim() + '" - available: ' + state.packs.map(p => p.name).join(", ") };
}
const amount = Math.floor(Number(amountRaw));
if (!Number.isFinite(amount) || amount < 1) return { ok: false, error: "amount must be 1 or more" };
if (typeof state.userTokens !== "number") return { ok: false, error: "token balance has not loaded yet" };
const cost = pack.price * amount;
if (cost > state.userTokens) {
return { ok: false, error: "need " + cost.toLocaleString() + " tokens for " + amount + " x " + pack.name + ", you have " + state.userTokens.toLocaleString() };
}
let remaining = amount;
let bought = 0;
let opened = 0;
let fresh = 0;
let left = state.userTokens;
while (remaining > 0) {
const chunk = Math.min(remaining, 100);
const result = await runAction(BUY_PACK_ACTION_ID, {
itemId: pack.packId,
quantity: String(chunk),
shopItem: JSON.stringify({ name: pack.name, price: pack.price, itemId: pack.packId }),
});
const parsed = readActionResult(result);
if (!parsed.ok) return { ok: false, error: parsed.error, pack: pack.name, bought, opened, fresh, tokensLeft: left };
const info = Array.isArray(parsed.data.purchaseInfo) ? parsed.data.purchaseInfo : [];
opened += info.length;
fresh += info.filter(i => i && i.isNewToUser).length;
const rest = parseInt(parsed.data.remainingTokens, 10);
if (Number.isFinite(rest)) {
left = rest;
const live = marketState();
if (live) live.setUserTokens(rest);
}
bought += chunk;
remaining -= chunk;
if (report) report("Bought " + bought + " of " + amount + "...");
}
return { ok: true, pack: pack.name, bought, opened, fresh, tokensLeft: left };
};
const blooksState = () => {
let found = null;
walk(props => {
if (props && Array.isArray(props.userBlooks) && typeof props.setUserBlooks === "function" && Array.isArray(props.packs)) {
found = props;
return true;
}
return false;
});
return found;
};
const blookCatalog = state => {
const map = new Map();
const add = pack => (pack && pack.blooks ? pack.blooks : []).forEach(b => {
if (b && b.name && !map.has(b.name)) map.set(b.name, b);
});
state.packs.forEach(add);
(state.freePacks || []).forEach(add);
return map;
};
const isFakeEntry = entry => fakeAdded.has(entry.blook) && entry.quantity === 1 && entry.sellPrice === fakeAdded.get(entry.blook);
const sellPlan = kind => {
const state = blooksState();
if (!state) return { ok: false, error: "open the Blooks page first" };
const catalog = blookCatalog(state);
const items = [];
state.userBlooks.forEach(entry => {
if (isFakeEntry(entry)) return;
const meta = catalog.get(entry.blook);
const rarity = meta && meta.rarity;
if (!rarity) return;
const owned = Number(entry.quantity) || 0;
let sell = 0;
if (kind === "duplicates") sell = PROTECTED_RARITIES.includes(rarity) ? 0 : owned - 1;
else if (kind === "commons") sell = rarity === "Common" ? owned : 0;
else if (kind === "uncommons") sell = rarity === "Common" || rarity === "Uncommon" ? owned : 0;
if (sell > 0) items.push({ name: entry.blook, rarity, quantity: sell, owned, last: sell >= owned, price: Number(entry.sellPrice) || 0 });
});
return {
ok: true,
kind,
items,
copies: items.reduce((sum, i) => sum + i.quantity, 0),
tokens: items.reduce((sum, i) => sum + i.quantity * i.price, 0),
};
};
const sellBlooks = async (kind, report) => {
const plan = sellPlan(kind);
if (!plan.ok) return plan;
if (!plan.items.length) return { ok: true, kinds: 0, copies: 0, tokens: null };
let copies = 0;
let kinds = 0;
let tokens = null;
for (const item of plan.items) {
const fields = { blook: item.name, quantity: String(item.quantity) };
if (item.last) fields.confirm = item.name;
const result = await runAction(SELL_ACTION_ID, fields);
const parsed = readActionResult(result);
if (!parsed.ok) return { ok: false, error: item.name + ": " + parsed.error, kinds, copies, tokens };
const remaining = parseInt(parsed.data.remainingQuantity, 10);
const rest = parseInt(parsed.data.tokens, 10);
copies += item.quantity;
kinds += 1;
if (Number.isFinite(rest)) tokens = rest;
const live = blooksState();
if (live && Number.isFinite(remaining)) {
live.setUserBlooks(list => {
const others = list.filter(e => e.blook !== item.name);
return remaining === 0 ? others : [...others, { blook: item.name, quantity: remaining, sellPrice: item.price }];
});
if (Number.isFinite(rest) && typeof live.setUserTokens === "function") live.setUserTokens(rest);
}
if (report) report("Sold " + kinds + " of " + plan.items.length + " blooks...");
await sleep(120);
}
return { ok: true, kinds, copies, tokens };
};
const askSell = (kind, label, report) => {
const plan = sellPlan(kind);
if (!plan.ok) return Promise.resolve("Not sold: " + plan.error);
if (!plan.items.length) return Promise.resolve("Nothing to sell (" + label + ")");
const now = Date.now();
if (armedSell.kind !== kind || now > armedSell.until) {
armedSell.kind = kind;
armedSell.until = now + 6000;
return Promise.resolve("Press again to confirm (6 sec)");
}
armedSell.kind = null;
return lobbyLock(() => sellBlooks(kind, report)).then(r => {
if (!r.ok) return "Stopped: " + r.error + (r.copies ? " (sold " + r.copies + " copies first)" : "");
return "Sold " + r.copies + " copies of " + r.kinds + " blooks" + (r.tokens !== null ? " - " + r.tokens.toLocaleString() + " tokens now" : "");
});
};
const syncCardQuantities = list => {
const byName = new Map(list.map(e => [e.blook, e.quantity]));
walk((props, fiber) => {
const blook = props && props.blook;
if (blook && typeof blook === "object" && typeof blook.name === "string" && "rarity" in blook && typeof props.setUserBlooks === "function" && fiber.memoizedState) {
let hook = fiber.memoizedState;
for (let i = 0; i < 2 && hook; i += 1) hook = hook.next;
if (hook && typeof hook.memoizedState === "number" && hook.queue && typeof hook.queue.dispatch === "function") {
const target = byName.has(blook.name) ? byName.get(blook.name) : 0;
if (hook.memoizedState !== target) hook.queue.dispatch(target);
}
}
return false;
});
};
const scheduleCardSync = list => {
syncCardQuantities(list);
[150, 600].forEach(ms => setTimeout(() => {
if (!destroyed) syncCardQuantities(list);
}, ms));
};
const FAKE_PRICES = { Common: 5, Uncommon: 20, Rare: 75, Epic: 350, Legendary: 1500, Chroma: 5000, Mystical: 10000, Unique: 20000 };
const userBlooksSetter = state => {
let setter = null;
walk((props, fiber) => {
if (props && Array.isArray(props.unlockedBlooks) && Array.isArray(props.modifiedPacks) && fiber.memoizedState) {
let hook = fiber.memoizedState;
while (hook) {
if (Array.isArray(hook.memoizedState) && hook.memoizedState === state.userBlooks && hook.queue && typeof hook.queue.dispatch === "function") {
setter = hook.queue.dispatch;
break;
}
hook = hook.next;
}
return true;
}
return false;
});
return setter || state.setUserBlooks;
};
const setFakeUnlock = enabled => {
const state = blooksState();
if (!state) return { ok: false, error: "open the Blooks page first" };
const set = userBlooksSetter(state);
if (enabled) {
const catalog = blookCatalog(state);
const owned = new Set(state.userBlooks.map(e => e.blook));
const realPrice = {};
state.userBlooks.forEach(e => {
const meta = catalog.get(e.blook);
if (meta && meta.rarity && e.sellPrice > 0 && realPrice[meta.rarity] === undefined) realPrice[meta.rarity] = e.sellPrice;
});
const added = [];
catalog.forEach((meta, name) => {
if (owned.has(name)) return;
const price = realPrice[meta.rarity] !== undefined ? realPrice[meta.rarity] : (FAKE_PRICES[meta.rarity] || 0);
added.push({ blook: name, quantity: 1, sellPrice: price });
});
added.forEach(e => fakeAdded.set(e.blook, e.sellPrice));
set(list => [...list, ...added.filter(e => !list.some(x => x.blook === e.blook))]);
scheduleCardSync([...state.userBlooks, ...added.filter(e => !state.userBlooks.some(x => x.blook === e.blook))]);
if (!fakeTimer) {
fakeTimer = setInterval(() => {
const live = blooksState();
if (live) syncCardQuantities(live.userBlooks);
}, 800);
}
fakeOn = true;
return { ok: true, enabled: true, added: added.length };
}
const names = new Map(fakeAdded);
const isFake = e => names.has(e.blook) && e.quantity === 1 && e.sellPrice === names.get(e.blook);
set(list => list.filter(e => !isFake(e)));
clearInterval(fakeTimer);
fakeTimer = null;
scheduleCardSync(state.userBlooks.filter(e => !isFake(e)));
fakeAdded.clear();
fakeOn = false;
return { ok: true, enabled: false };
};
const isCafePlayer = p => Boolean(p) && Boolean(p.foods) && Boolean(p.customers);
const pendingOrder = customer => {
if (!customer || customer.hasPaid || !customer.order || !customer.order.lines) return false;
return mapValues(customer.order.lines).some(quantity => Number(quantity) > 0);
};
const mapValues = collection => {
const out = [];
if (collection && typeof collection.forEach === "function") collection.forEach(value => out.push(value));
return out;
};
const cafeState = () => {
const player = me();
if (!isCafePlayer(player)) return null;
const foods = mapValues(player.foods);
const customers = mapValues(player.customers).filter(pendingOrder);
return {
money: Number(player.score) || 0,
level: player.cafeLevel,
customers: customers.length,
stock: foods.reduce((sum, f) => sum + (Number(f.quantity) || 0), 0),
busySeconds: Math.max(0, Math.ceil(Number(player.remainingInspectionTime) || 0)),
inQuestion: Boolean(player.inQuestion),
inTutorial: Boolean(player.inTutorial),
};
};
const serveCustomers = player => {
const now = Date.now();
let sent = 0;
mapValues(player.customers).forEach(customer => {
if (!pendingOrder(customer)) return;
if (now - (lastServe.get(customer.id) || 0) < 450) return;
lastServe.set(customer.id, now);
if (send("playerPlaceCustomerOrder", { customer })) sent += 1;
});
return sent;
};