-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily.html
More file actions
976 lines (844 loc) · 34.4 KB
/
daily.html
File metadata and controls
976 lines (844 loc) · 34.4 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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="icon" type="image/png" sizes="32x32" href="/icon-32.png?v=2">
<link rel="icon" type="image/png" sizes="16x16" href="/icon-16.png?v=2">
<link rel="apple-touch-icon" href="/icon-192.png?v=2">
<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#0f1222">
<title>Daily</title>
<style>
:root{
--bg:#0f1222; --panel:#171a2b; --ink:#e9ecff; --muted:#a6adda; --accent:#7c5cff; --good:#2bd576; --bad:#ff6b6b;
}
*{box-sizing:border-box}
html,body{height:100%}
html{background:#0b0e1a}
body{
margin:0;
font-family:Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
background: radial-gradient(1200px 800px at 70% -10%, #1a1f3a 0%, #0f1222 60%, #0b0e1a 100%);
color:var(--ink);
display:flex; align-items:center; justify-content:center;
padding:24px;
overscroll-behavior:contain;
padding-left:max(24px, env(safe-area-inset-left));
padding-right:max(24px, env(safe-area-inset-right));
padding-bottom:max(24px, env(safe-area-inset-bottom));
-webkit-text-size-adjust:100%;
}
.app{width:min(920px,100%)}
.card{
background:linear-gradient(180deg,#1a1e33 0%, #14182b 100%);
border:1px solid rgba(255,255,255,.06);
box-shadow:0 10px 30px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.04);
border-radius:20px; padding:24px; backdrop-filter:blur(6px);
}
h1{margin:0 0 12px; font-size:clamp(20px, 2.8vw, 34px); letter-spacing:.3px}
.sub{color:var(--muted); margin-bottom:18px}
.layout{display:grid; grid-template-columns:1.3fr 1fr; gap:22px}
@media (max-width:880px){ .layout{grid-template-columns:1fr} }
.stage{
background: radial-gradient(600px 400px at 60% -20%, #1f2444, #151a2f);
border:1px solid rgba(255,255,255,.06);
border-radius:16px; padding:10px;
display:flex; align-items:center; justify-content:center;
aspect-ratio:1/1; min-height:320px;
}
svg{width:100%; height:100%}
.controls{background:var(--panel); border:1px solid rgba(255,255,255,.06); border-radius:16px; padding:16px}
.row{display:flex; gap:12px; align-items:center; flex-wrap:wrap}
/* Input + Confirm : ratio fixe 3/4 – 1/4 */
.inputline{ display:flex; align-items:center; justify-content:space-between; gap:8px; width:100% }
.inputline #guess{ flex:0 0 75%; min-width:0 }
.inputline #confirmBtn{ flex:0 0 25%; padding:10px; text-align:center }
input[type=number]{
background:#0f1326; color:var(--ink);
border:1px solid rgba(255,255,255,.12); border-radius:12px;
padding:12px 14px; font-size:16px; width:140px;
transition:border .15s ease, box-shadow .15s ease; outline:none;
}
input[type=number]:focus{ border-color:var(--accent); box-shadow:0 0 0 6px rgba(124,92,255,.15) }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button{ -webkit-appearance:none; margin:0 }
input[type=number]{ -moz-appearance:textfield }
.btn{
appearance:none; border:none; cursor:pointer;
color:#fff; font-weight:600; letter-spacing:.2px;
padding:12px 16px; border-radius:12px;
background:linear-gradient(180deg, #8a6bff, #6945ff);
box-shadow:0 6px 16px rgba(105,69,255,.35);
transition:transform .05s ease;
}
.btn:active{ transform:translateY(1px) }
.btn.secondary{ background:transparent; border:1px solid rgba(255,255,255,.18); box-shadow:none; color:var(--muted) }
.feedback{ margin-top:14px; display:flex; gap:12px; align-items:center; flex-wrap:wrap }
.meta{ margin-top:10px; color:var(--muted); font-size:14px }
.meter{ height:10px; background:#0f1326; border-radius:999px; overflow:hidden; border:1px solid rgba(255,255,255,.08) }
.meter > div{ height:100%; width:0%; background:linear-gradient(90deg,#2bd576,#ffd166,#ff8b6b,#ff6b6b); transition:width .25s ease }
#errorMsg{ color:var(--bad); font-size:14px; margin:6px 0 10px; opacity:0; transition:opacity .2s ease }
#errorMsg.visible{ opacity:1 }
.guesses{ margin-top:4px; display:flex; flex-wrap:wrap; gap:6px }
.guess-item{ background:rgba(255,255,255,.05); border:1px solid rgba(255,255,255,.08); border-radius:8px; padding:4px 10px; font-size:14px; color:var(--muted); transition:background .2s ease }
.guess-item:hover{ background:rgba(124,92,255,.15); color:var(--ink) }
.guess-item.added{ animation:pop .25s ease-out }
@keyframes pop{ 0%{transform:scale(.7);opacity:0} 60%{transform:scale(1.08);opacity:1} 100%{transform:scale(1)} }
.card-header{ display:flex; justify-content:flex-start; margin-bottom:12px }
.backbtn{
display:inline-flex; align-items:center; gap:8px;
padding:10px 14px; border-radius:999px;
background:rgba(255,255,255,.06);
border:1px solid rgba(255,255,255,.12);
color:var(--ink); text-decoration:none; font-weight:600; line-height:1;
transition:background .15s ease, border-color .15s ease, transform .05s ease;
}
.backbtn:hover{ background:rgba(124,92,255,.16); border-color:rgba(124,92,255,.35) }
.backbtn:active{ transform:translateY(1px) }
.card-intro{
display:flex; align-items:flex-start; justify-content:flex-start;
gap:12px 16px; margin-bottom:14px; flex-wrap:wrap; align-content:flex-start;
}
.card-intro .sub{ margin:0; flex:1 1 auto; min-width:0 }
#streakBar,
.streakchip{
display:inline-flex; align-items:center; gap:8px;
padding:8px 12px; border-radius:999px;
border:1px solid rgba(255,255,255,.12);
background:#0e1326; color:#ffd166; font-weight:700;
white-space:nowrap; box-shadow:inset 0 1px 0 rgba(255,255,255,.04);
margin:0; text-align:left;
}
.madeby{
position:fixed; bottom:12px; left:50%; transform:translateX(-50%);
text-align:center; font-size:13px; color:var(--muted); opacity:.75;
letter-spacing:.3px; transition:opacity .2s ease, color .2s ease; pointer-events:none;
}
.madeby strong{ color:var(--ink) }
.madeby:hover{ opacity:1; color:var(--accent) }
/* ====== TEST MODE ====== */
.testbar{
position:fixed; top:12px; right:12px; z-index:1000;
background:rgba(20,24,43,.95);
border:1px solid rgba(255,255,255,.1);
backdrop-filter:blur(8px);
color:var(--ink);
padding:12px; border-radius:12px;
display:none; width:320px;
box-shadow:0 8px 24px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.04);
}
.testbar.visible{ display:block }
.testbar h3{ margin:0 0 8px; font-size:14px; color:var(--muted); font-weight:700; letter-spacing:.3px }
.testgrid{ display:grid; grid-template-columns:1fr 1fr; gap:8px }
.testbar input[type="date"]{
width:100%; background:#0f1326; color:var(--ink);
border:1px solid rgba(255,255,255,.12); border-radius:10px;
padding:8px 10px; font-size:13px;
}
.testbar .btn{ padding:8px 10px; font-size:12px; border-radius:10px }
.testbar .row{ gap:8px }
.testnote{ margin-top:8px; font-size:12px; color:var(--muted) }
.test-login-backdrop{
position:fixed; inset:0; z-index:2000;
background:rgba(0,0,0,.55); backdrop-filter:blur(4px);
display:none; align-items:center; justify-content:center;
}
.test-login-backdrop.visible{ display:flex }
.test-login{
width:min(360px,92vw);
background:rgba(20,24,43,.98);
border:1px solid rgba(255,255,255,.1);
box-shadow:0 12px 28px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.04);
border-radius:14px; padding:16px; color:var(--ink);
}
.test-login h3{ margin:0 0 10px; font-size:16px; letter-spacing:.2px }
.test-login label{ display:block; font-size:13px; color:var(--muted); margin:10px 0 6px }
.test-login input{
width:100%; background:#0f1326; color:var(--ink);
border:1px solid rgba(255,255,255,.12); border-radius:10px;
padding:10px 12px; font-size:14px; outline:none;
}
.test-login .row{ display:flex; gap:8px; margin-top:12px }
.test-login .btn{ flex:1; padding:10px 12px; font-size:14px; border-radius:10px }
.test-login .err{ color:var(--bad); font-size:13px; margin-top:8px; min-height:18px }
/* ====== RESPONSIVE ====== */
@media (max-width:640px){
.card-intro{ flex-direction:column; align-items:flex-start; gap:10px }
.backbtn{ padding:8px 12px; font-size:14px }
}
@media (max-width:430px){
/* no-scroll + layout plein écran */
html,body{ height:100dvh; overflow:scroll }
.app{ height:100%; display:flex; flex-direction:column }
.card{ flex:1 1 auto; display:flex; flex-direction:column }
.layout{ grid-template-columns:1fr; gap:12px }
/* stage pleine largeur, hauteur souple */
.stage{
aspect-ratio:auto; min-height:unset;
height:clamp(180px,60vw,320px);
padding:8px; border-radius:14px;
}
.card{ padding:14px; border-radius:16px }
.controls{ padding:12px; border-radius:14px }
.sub{ font-size:14px; margin-bottom:10px }
h1{ font-size:clamp(26px, 7vw, 36px); margin-bottom:10px }
}
@media (max-width:360px){
.card{ padding:12px; border-radius:14px }
.stage{ height:clamp(160px, 58vw, 260px); padding:6px; border-radius:12px }
.controls{ padding:10px; border-radius:12px }
}
#precision { display: none; }
#precision.visible { display: block; opacity: 1; }
/* compat avec ta classe existante */
#precision.invisible { display: none !important; opacity: 0; }
</style>
</head>
<div id="testLoginBackdrop" class="test-login-backdrop" aria-hidden="true">
<div class="test-login" role="dialog" aria-modal="true" aria-labelledby="testLoginTitle">
<h3 id="testLoginTitle">🧪 Accès test</h3>
<p class="sub" style="margin:0 0 8px">Identifiez-vous pour ouvrir le mode test.</p>
<label for="testLoginUser">Login</label>
<input id="testLoginUser" autocomplete="username" />
<label for="testLoginPass">Mot de passe</label>
<input id="testLoginPass" type="password" autocomplete="current-password" />
<div class="row">
<button class="btn" id="testLoginSubmit" type="button">Se connecter</button>
<button class="btn secondary" id="testLoginCancel" type="button">Annuler</button>
</div>
<div id="testLoginErr" class="err"></div>
</div>
</div>
<body>
<div class="app">
<div style="text-align:center;">
<h1 style="font-size: clamp(40px, 6vw, 70px); margin-bottom: 24px;">🎯 Daily</h1>
</div>
<div class="card">
<div class="card-header">
<a href="/" class="backbtn" aria-label="Retour au menu">← Menu</a>
</div>
<div class="card-intro">
<p class="sub">
You have <strong>5 attempts</strong> to guess the angle (1° to 179°). Help: ⬆️/⬇️ and 🔥/🥶 depending on your accuracy.
</p>
<div id="streakBar" class="streakchip"></div>
</div>
<div class="layout">
<div class="stage" id="stage">
<svg viewBox="0 0 400 400">
<rect width="400" height="400" fill="url(#grid)" />
<circle cx="200" cy="200" r="3" fill="#a6adda" opacity=".9" />
<line id="rayA" x1="200" y1="200" x2="360" y2="200" stroke="#e9ecff" stroke-width="4" stroke-linecap="round"/>
<line id="rayB" x1="200" y1="200" x2="360" y2="200" stroke="#7c5cff" stroke-width="4" stroke-linecap="round"/>
<path id="arc" d="" fill="none" stroke="#ffd166" stroke-width="4" opacity=".9"/>
</svg>
</div>
<div class="controls">
<form id="form" autocomplete="off" novalidate>
<label class="discreet" for="guess">Your proposal</label>
<!-- NEW: input + confirm on the same line -->
<div class="inputline">
<input id="guess" name="guess" type="number" inputmode="numeric" min="1" max="179" placeholder="ex. 27" />
<button class="btn" type="submit" id="confirmBtn">Confirm</button>
</div>
<div id="errorMsg"></div>
<!-- daily: pas de bouton New game -->
</form>
<div id="feedback" class="feedback"></div>
<div id="precision" class="invisible">
<div class="meta">Accuracy</div>
<div class="meter"><div id="heatbar"></div></div>
</div>
<strong><div class="meta" id="stats"></div></strong>
<div class="meta" id="guesses-title" style="margin-top:8px; margin-bottom:8px; font-weight:600;"></div>
<div id="guesses-list" class="guesses"></div>
</div>
</div>
</div>
<footer class="madeby">
Made with ❤️ by <strong>GrandTh</strong>
</footer>
</div>
<div id="testbar" class="testbar">
<h3>🧪 Daily — Test mode</h3>
<div class="row" style="margin-bottom:8px;">
<input type="date" id="test-date" />
<button class="btn" id="btn-apply-date" type="button">Apply date</button>
</div>
<div class="row" style="margin-bottom:8px;">
<button class="btn secondary" id="btn-prev-day" type="button">← Previous day</button>
<button class="btn secondary" id="btn-next-day" type="button">Next day →</button>
</div>
<div class="testgrid" style="margin-bottom:8px;">
<button class="btn secondary" id="btn-reset-game" type="button">Reset saved game</button>
<button class="btn secondary" id="btn-reset-streak" type="button">Reset streak/best</button>
<button class="btn secondary" id="btn-force-win" type="button">Force WIN</button>
<button class="btn secondary" id="btn-force-lose" type="button">Force LOSE</button>
</div>
<div class="testnote" id="test-info"></div>
</div>
<script>
const DAILY_GAME_KEY = 'angle_guessr_daily_game_v1';
const DAILY_STREAK_KEY = 'angle_guessr_daily_streak_v1';
const DAILY_BEST_KEY = 'angle_guessr_daily_best_v1';
const DAILY_SIG_KEY = 'angle_guessr_daily_sig_v1';
const DAILY_LAST_WIN = 'angle_guessr_daily_last_win_v1';
const INSTALL_ID = 'angle_guessr_install_id_v1';
const QS = new URLSearchParams(location.search);
const TEST_MODE = QS.has('test');
let TEST_DATE_KEY = null;
let targetAngle = 0;
let attempts = 0;
const maxAttempts = 5;
let previousGuesses = [];
let gameActive = false;
let finished = false;
const rayB = document.getElementById('rayB');
const arc = document.getElementById('arc');
const feedback = document.getElementById('feedback');
const heatbar = document.getElementById('heatbar');
const stats = document.getElementById('stats');
const form = document.getElementById('form');
const guessInput = document.getElementById('guess');
const confirmBtn = document.getElementById('confirmBtn');
const errorMsg = document.getElementById('errorMsg');
const guessesTitle = document.getElementById('guesses-title');
const guessesList = document.getElementById('guesses-list');
const precisionDiv = document.getElementById('precision');
const TEST_AUTH_TOKEN_KEY = 'angle_guessr_test_auth_token_v1';
function setInputsDisabled(disabled){
if (guessInput) guessInput.disabled = disabled;
if (confirmBtn) confirmBtn.disabled = disabled;
}
function hideAccuracy() {
if (!precisionDiv) return;
precisionDiv.classList.add('invisible');
precisionDiv.classList.remove('visible');
if (heatbar) heatbar.style.width = '0%';
}
function showAccuracyFromDiff(diff) {
if (!precisionDiv) return;
if (heatbar) heatbar.style.width = heatPercent(diff) + '%';
precisionDiv.classList.remove('invisible');
precisionDiv.classList.add('visible');
}
function realTodayDDMMYYYY(){
const d = new Date();
const dd = String(d.getDate()).padStart(2,'0');
const mm = String(d.getMonth()+1).padStart(2,'0');
const yyyy = d.getFullYear();
return `${dd}/${mm}/${yyyy}`;
}
async function setTestAuthToken(username){
const payload = {
u: username,
date: realTodayDDMMYYYY(),
ts: Date.now()
};
const boxed = await encryptObject(payload);
localStorage.setItem(TEST_AUTH_TOKEN_KEY, JSON.stringify(boxed));
}
async function getValidTestAuth(){
const raw = localStorage.getItem(TEST_AUTH_TOKEN_KEY);
if(!raw) return null;
try{
const boxed = JSON.parse(raw);
const obj = await decryptObject(boxed);
if(!obj || typeof obj !== 'object') return null;
if(obj.date !== realTodayDDMMYYYY()) return null;
if(obj.u !== 'admin') return null;
return obj;
}catch(e){ return null; }
}
function showTestLogin(){
const b = document.getElementById('testLoginBackdrop');
const u = document.getElementById('testLoginUser');
const p = document.getElementById('testLoginPass');
const s = document.getElementById('testLoginSubmit');
const c = document.getElementById('testLoginCancel');
const err = document.getElementById('testLoginErr');
if(!b || !u || !p || !s || !c) return new Promise(res => res(false));
b.classList.add('visible'); b.setAttribute('aria-hidden','false');
u.value = 'admin';
p.value = '';
err.textContent = '';
setTimeout(()=> p.focus(), 0);
return new Promise(resolve=>{
const onSubmit = async ()=>{
err.textContent = '';
const user = u.value.trim();
const pass = p.value.trim();
const expected = realTodayDDMMYYYY();
if(user === 'admin' && pass === expected){
await setTestAuthToken(user);
cleanup();
resolve(true);
}else{
err.textContent = 'Identifiants invalides.';
}
};
const onCancel = ()=>{
cleanup();
resolve(false);
};
const onKey = (e)=>{
if(e.key === 'Enter') onSubmit();
if(e.key === 'Escape') onCancel();
};
function cleanup(){
s.removeEventListener('click', onSubmit);
c.removeEventListener('click', onCancel);
document.removeEventListener('keydown', onKey);
b.classList.remove('visible'); b.setAttribute('aria-hidden','true');
}
s.addEventListener('click', onSubmit);
c.addEventListener('click', onCancel);
document.addEventListener('keydown', onKey);
});
}
async function ensureTestAuth(){
const valid = await getValidTestAuth();
if(valid) return true;
const ok = await showTestLogin();
return !!ok;
}
function realLocalDateKey(){
const d = new Date();
const y = d.getFullYear();
const m = String(d.getMonth()+1).padStart(2,'0');
const day = String(d.getDate()).padStart(2,'0');
return `${y}-${m}-${day}`;
}
function localDateKey(){
return TEST_DATE_KEY || realLocalDateKey();
}
function dateFromKey(key){
const [y,m,d] = key.split('-').map(Number);
const dt = new Date(y, (m||1)-1, d||1);
return dt;
}
function keyFromDate(dt){
const y = dt.getFullYear();
const m = String(dt.getMonth()+1).padStart(2,'0');
const d = String(dt.getDate()).padStart(2,'0');
return `${y}-${m}-${d}`;
}
function hashStringDjb2(str){
let h = 5381;
for(let i=0;i<str.length;i++){ h=((h<<5)+h)+str.charCodeAt(i); h|=0; }
return h;
}
function xmur3(str){
let h = 1779033703 ^ str.length;
for (let i=0; i<str.length; i++){
h = Math.imul(h ^ str.charCodeAt(i), 3432918353);
h = (h << 13) | (h >>> 19);
}
return function(){
h = Math.imul(h ^ (h >>> 16), 2246822507);
h = Math.imul(h ^ (h >>> 13), 3266489909);
return (h ^= h >>> 16) >>> 0;
};
}
function mulberry32(a){
return function(){
let t = a += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function todayAngle(){
const key = localDateKey();
const seedGen = xmur3('ANGLE_DAILY|' + key);
const s1 = seedGen();
const s2 = seedGen() ^ (new Date(key).getDate() * 2654435761);
const s3 = (s1 ^ s2) >>> 0;
const rand = mulberry32(s3);
rand(); rand();
const angle = Math.floor(rand() * 179) + 1;
if (angle === 90) {
return Math.floor(rand() * 179) + 1;
}
return angle;
}
function pointAt(cx,cy,r,deg){const rad=deg*Math.PI/180;return{x:cx+r*Math.cos(rad),y:cy-r*Math.sin(rad)}}
function drawAngle(deg){
const c={x:200,y:200},r=160,p=pointAt(c.x,c.y,r,deg);
rayB.setAttribute('x2',p.x); rayB.setAttribute('y2',p.y);
const ar=52,s=pointAt(c.x,c.y,ar,0),e=pointAt(c.x,c.y,ar,deg),
d=`M ${s.x} ${s.y} A ${ar} ${ar} 0 0 0 ${e.x} ${e.y}`;
arc.setAttribute('d',d);
}
function animateAngle(start,end,duration){
const startTime=performance.now(); const diff=end-start;
function easeOut(t){return 1-Math.pow(1-t,3);}
function step(now){
const elapsed=now-startTime; const progress=Math.min(elapsed/duration,1);
const eased=easeOut(progress); const current=start+diff*eased;
drawAngle(current); if(progress<1)requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
function heatEmoji(diff){if(diff===0)return'🎯 Perfect !';if(diff<=2)return'🔥🔥 Very hot';if(diff<=5)return'🔥 Warm';if(diff<=10)return'🙂 Lukewarm';if(diff<=20)return'🧊 cool';return'🥶 Freezing';}
function heatPercent(diff){return(100-Math.min(diff,180)/180*100);}
function arrowHint(g){if(g<targetAngle)return'⬆️ Higher';if(g>targetAngle)return'⬇️ Lower';return'✅ Exact';}
function getInstallId(){
let id = localStorage.getItem(INSTALL_ID);
if(!id){
id = (crypto && crypto.randomUUID) ? crypto.randomUUID() : String(Math.random()).slice(2) + Date.now();
try { localStorage.setItem(INSTALL_ID, id); } catch {}
}
return id;
}
async function sha256(text){
const enc = new TextEncoder().encode(text);
const buf = await crypto.subtle.digest('SHA-256', enc);
return Array.from(new Uint8Array(buf)).map(b=>b.toString(16).padStart(2,'0')).join('');
}
function getNum(key){ const v=Number(localStorage.getItem(key)); return Number.isFinite(v) ? v : 0; }
async function computeSig(streak, best){
const material = `[DAILY]|${streak}|${best}|${getInstallId()}|${navigator.userAgent}`;
return await sha256(material);
}
async function saveSig(s,b){
try { localStorage.setItem(DAILY_SIG_KEY, await computeSig(s,b)); } catch {}
}
function setStreak(v){ try{ localStorage.setItem(DAILY_STREAK_KEY, String(v)); }catch{} }
function setBest(v){ try{ localStorage.setItem(DAILY_BEST_KEY, String(v)); }catch{} }
async function loadStreakSafe(){
const s = getNum(DAILY_STREAK_KEY);
const b = getNum(DAILY_BEST_KEY);
const sig = localStorage.getItem(DAILY_SIG_KEY) || '';
const expect = await computeSig(s,b);
if(sig !== expect){
setStreak(0);
await saveSig(0, b);
return {streak:0, best:b};
}
return {streak:s, best:b};
}
function renderStreak(s = getNum(DAILY_STREAK_KEY), b = getNum(DAILY_BEST_KEY)) {
const el = document.getElementById('streakBar');
if (!el) return;
if (s >= 1) el.textContent = `🔥${s} (best ${b})`;
else el.textContent = `(best ${b})`;
}
function lastWinDate(){ return localStorage.getItem(DAILY_LAST_WIN) || ''; }
function setLastWinToday(){ try{ localStorage.setItem(DAILY_LAST_WIN, localDateKey()); }catch{} }
async function bumpStreakOncePerDay(){
const today = localDateKey();
if (lastWinDate() === today) return;
const cur = getNum(DAILY_STREAK_KEY) + 1;
setStreak(cur);
const best = Math.max(getNum(DAILY_BEST_KEY), cur);
setBest(best);
await saveSig(cur, best);
setLastWinToday();
renderStreak(cur, best);
}
async function resetStreak(){
const best = getNum(DAILY_BEST_KEY);
setStreak(0);
await saveSig(0, best);
renderStreak(0, best);
}
window.addEventListener('storage', async (e)=>{
if([DAILY_STREAK_KEY,DAILY_BEST_KEY,DAILY_SIG_KEY,DAILY_LAST_WIN].includes(e.key)){
await loadStreakSafe(); renderStreak();
}
});
function openIDB(){
return new Promise((resolve, reject) => {
const req = indexedDB.open('angle_guessr_keys_v1', 1);
req.onupgradeneeded = () => { req.result.createObjectStore('keys'); };
req.onsuccess = () => resolve(req.result);
req.onerror = () => reject(req.error);
});
}
async function putKeyInIDB(keyName, cryptoKey){
const db = await openIDB();
return new Promise((res, rej) => {
const tx = db.transaction('keys','readwrite');
tx.objectStore('keys').put(cryptoKey, keyName);
tx.oncomplete = () => { db.close(); res(true); };
tx.onerror = () => { db.close(); rej(tx.error); };
});
}
async function getKeyFromIDB(keyName){
const db = await openIDB();
return new Promise((res, rej) => {
const tx = db.transaction('keys','readonly');
const store = tx.objectStore('keys').get(keyName);
store.onsuccess = () => { db.close(); res(store.result || null); };
store.onerror = () => { db.close(); rej(store.error); };
});
}
async function getMasterKey(){
let key = await getKeyFromIDB('master');
if(key) return key;
key = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt','decrypt']);
await putKeyInIDB('master', key);
return key;
}
function toHex(buffer){ return Array.from(new Uint8Array(buffer)).map(b=>b.toString(16).padStart(2,'0')).join(''); }
function fromHex(hex){ const bytes = new Uint8Array(hex.length/2); for(let i=0;i<bytes.length;i++) bytes[i] = parseInt(hex.substr(i*2,2),16); return bytes.buffer; }
async function encryptObject(obj){
const key = await getMasterKey();
const iv = crypto.getRandomValues(new Uint8Array(12));
const data = new TextEncoder().encode(JSON.stringify(obj));
const ct = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, data);
return { iv: toHex(iv.buffer), ct: toHex(ct) };
}
async function decryptObject(stored){
try {
const key = await getMasterKey();
const iv = new Uint8Array(fromHex(stored.iv));
const ct = fromHex(stored.ct);
const plain = await crypto.subtle.decrypt({ name:'AES-GCM', iv }, key, ct);
return JSON.parse(new TextDecoder().decode(plain));
} catch (err) {
return null;
}
}
async function saveGame(){
const payload = { targetAngle, attempts, previousGuesses, gameActive, finished, date: localDateKey() };
try {
const boxed = await encryptObject(payload);
localStorage.setItem(DAILY_GAME_KEY, JSON.stringify(boxed));
} catch (e){ console.warn('saveGame failed', e); }
}
async function restoreGame(){
const raw = localStorage.getItem(DAILY_GAME_KEY);
if(!raw) return false;
try{
const boxed = JSON.parse(raw);
const g = await decryptObject(boxed);
if(!g || typeof g !== 'object') return false;
const today = localDateKey();
const todayAng = todayAngle();
if (g.date !== today) return false;
targetAngle = todayAng;
attempts = g.attempts ?? 0;
previousGuesses = Array.isArray(g.previousGuesses) ? g.previousGuesses : [];
finished = !!g.finished;
gameActive = !!g.gameActive && !finished;
drawAngle(targetAngle);
feedback.innerHTML = '';
heatbar.style.width = previousGuesses.length
? heatPercent(Math.abs(previousGuesses[previousGuesses.length-1]-targetAngle)) + '%'
: '0%';
const showPrecision = (attempts >= maxAttempts - 1) && gameActive;
if (finished && previousGuesses.length) {
const last = previousGuesses[previousGuesses.length - 1];
showAccuracyFromDiff(Math.abs(last - targetAngle));
} else {
hideAccuracy();
}
stats.textContent = finished
? `Partie terminée.`
: (gameActive ? `Try ${attempts}/${maxAttempts}` : `Game over.`);
updateGuesses();
setInputsDisabled(finished || !gameActive);
return true;
}catch(err){
console.warn('restoreGame failed', err);
return false;
}
}
function updateGuesses(){
if(previousGuesses.length===0){
guessesTitle.textContent=''; guessesList.innerHTML=''; return;
}
guessesTitle.textContent='🧠 Your previous attempts :';
guessesList.innerHTML='';
previousGuesses.forEach((g, i)=>{
const item=document.createElement('div');
item.className='guess-item';
item.textContent=`${g}°`;
guessesList.appendChild(item);
if(i===previousGuesses.length-1){ void item.offsetWidth; item.classList.add('added'); }
});
}
function startDailyOnce(){
attempts=0; previousGuesses=[];
hideAccuracy();
targetAngle = todayAngle();
finished = false;
gameActive = true;
feedback.innerHTML=''; heatbar.style.width='0%';
stats.textContent='New game, you have 5 attempts.';
guessesTitle.textContent=''; guessesList.innerHTML='';
setInputsDisabled(false);
guessInput.value='';
errorMsg.textContent='';
errorMsg.classList.remove('visible');
animateAngle(0,targetAngle,500);
guessInput.focus();
saveGame();
}
form.addEventListener('submit', async (e)=>{
e.preventDefault();
if(!gameActive || finished){ return; }
errorMsg.textContent=''; errorMsg.classList.remove('visible');
const value=guessInput.value.trim();
if(value===''){
errorMsg.textContent='⚠️ Enter a value before confirming !';
errorMsg.classList.add('visible');
return;
}
if(attempts>=maxAttempts) return;
const g=Number(value);
if(!Number.isFinite(g)) return;
const guess=Math.max(1,Math.min(179,Math.round(g)));
attempts++;
previousGuesses.push(guess);
updateGuesses();
const diff=Math.abs(guess-targetAngle);
if (guess === targetAngle) {
showAccuracyFromDiff(diff);
} else if (attempts >= maxAttempts - 1) {
showAccuracyFromDiff(diff);
} else {
hideAccuracy();
}
feedback.innerHTML='';
const arrow=document.createElement('div');arrow.className='chip';arrow.textContent=arrowHint(guess);
const heat=document.createElement('div');heat.className='chip';heat.textContent=heatEmoji(diff);
feedback.appendChild(arrow); feedback.appendChild(heat);
heatbar.style.width=heatPercent(diff)+'%';
if(guess===targetAngle){
stats.textContent=`Well done! The angle was ${targetAngle}°. Found in ${attempts} try(s) 🔥`;
setInputsDisabled(true);
gameActive = false;
finished = true;
await bumpStreakOncePerDay();
await saveGame();
return;
}
if(attempts>=maxAttempts){
stats.textContent=`Lost 💀 The angle was ${targetAngle}°.`;
setInputsDisabled(true);
gameActive = false;
finished = true;
await resetStreak();
await saveGame();
return;
}
stats.textContent=`Try ${attempts}/${maxAttempts}`;
await saveGame();
guessInput.value = '';
});
window.addEventListener('beforeunload', ()=>{ if(gameActive && !finished) saveGame(); });
function setTestInfo() {
const el = document.getElementById('test-info');
if (!el) return;
const prodKey = realLocalDateKey();
const curKey = localDateKey();
const angle = todayAngle();
el.textContent = `Date active: ${curKey} (prod: ${prodKey}) • Angle: ${angle}° • Attempts: ${attempts}/${maxAttempts}`;
}
async function resetSavedGame() {
localStorage.removeItem(DAILY_GAME_KEY);
attempts = 0; previousGuesses = []; finished = false; gameActive = false;
startDailyOnce();
await saveGame();
setTestInfo();
}
async function resetStreakCompletely() {
localStorage.removeItem(DAILY_STREAK_KEY);
localStorage.removeItem(DAILY_BEST_KEY);
localStorage.removeItem(DAILY_SIG_KEY);
localStorage.removeItem(DAILY_LAST_WIN);
await loadStreakSafe();
renderStreak();
setTestInfo();
}
function applyDateKey(key){
TEST_DATE_KEY = key;
localStorage.removeItem(DAILY_GAME_KEY);
targetAngle = todayAngle();
drawAngle(targetAngle);
startDailyOnce();
setTestInfo();
}
function shiftTestDate(days){
const baseKey = localDateKey();
const dt = dateFromKey(baseKey);
dt.setDate(dt.getDate() + days);
applyDateKey( keyFromDate(dt) );
const input = document.getElementById('test-date');
if (input) input.value = keyFromDate(dt);
}
function forceWin() {
if (!gameActive || finished) startDailyOnce();
guessInput.value = String(targetAngle);
form.dispatchEvent(new Event('submit', {cancelable:true}));
setTestInfo();
}
function forceLose() {
if (!gameActive || finished) startDailyOnce();
const wrong = (targetAngle === 1) ? 179 : 1;
const doTry = () => {
if (finished) { setTestInfo(); return; }
guessInput.value = String(wrong);
form.dispatchEvent(new Event('submit', {cancelable:true}));
if (!finished) setTimeout(doTry, 10);
};
doTry();
}
(async function init(){
await loadStreakSafe();
renderStreak();
targetAngle = todayAngle();
drawAngle(targetAngle);
if (TEST_MODE) {
const bar = document.getElementById('testbar');
bar.classList.add('visible');
const input = document.getElementById('test-date');
const currentKey = localDateKey();
input.value = currentKey;
document.getElementById('btn-apply-date').addEventListener('click', () => {
const val = input.value;
if (/^\d{4}-\d{2}-\d{2}$/.test(val)) applyDateKey(val);
});
document.getElementById('btn-prev-day').addEventListener('click', () => shiftTestDate(-1));
document.getElementById('btn-next-day').addEventListener('click', () => shiftTestDate(1));
document.getElementById('btn-reset-game').addEventListener('click', resetSavedGame);
document.getElementById('btn-reset-streak').addEventListener('click', resetStreakCompletely);
document.getElementById('btn-force-win').addEventListener('click', forceWin);
document.getElementById('btn-force-lose').addEventListener('click', forceLose);
}
const restored = await restoreGame();
if (!restored) {
startDailyOnce();
}
if (TEST_MODE) {
const ok = await ensureTestAuth();
if (!ok) {
console.warn('Test mode blocked: authentication failed/canceled.');
} else {
const bar = document.getElementById('testbar');
bar.classList.add('visible');
const input = document.getElementById('test-date');
const currentKey = localDateKey();
input.value = currentKey;
document.getElementById('btn-apply-date').addEventListener('click', () => {
const val = input.value;
if (/^\d{4}-\d{2}-\d{2}$/.test(val)) applyDateKey(val);
});
document.getElementById('btn-prev-day').addEventListener('click', () => shiftTestDate(-1));
document.getElementById('btn-next-day').addEventListener('click', () => shiftTestDate(1));
document.getElementById('btn-reset-game').addEventListener('click', resetSavedGame);
document.getElementById('btn-reset-streak').addEventListener('click', resetStreakCompletely);
document.getElementById('btn-force-win').addEventListener('click', forceWin);
document.getElementById('btn-force-lose').addEventListener('click', forceLose);
setTestInfo();
}
}
})();
</script>
</body>
</html>