-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
946 lines (820 loc) · 33.3 KB
/
index.html
File metadata and controls
946 lines (820 loc) · 33.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crossword Wheel - Crossword Anagram Helper & Letter Shuffler</title>
<!-- Favicons -->
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<link rel="alternate icon" href="/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@700&display=swap" rel="stylesheet">
<meta name="description" content="Free crossword anagram helper to shuffle letters and solve anagram clues. Lock letters in place and shuffle the rest until you find the answer. Perfect for NYT crossword and cryptic puzzles.">
<meta name="keywords" content="crossword wheel, crossword anagram helper, anagram shuffler, letter shuffle, crossword helper, crossword tool, word puzzle, cryptic crossword, anagram tool">
<meta name="author" content="ogoodwin505">
<meta name="google-site-verification" content="bOeqm42-4RNFFJkyIqFZbCDJ6KcdIM0sy1lRLU9XOmY" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://crosswordwheel.com/">
<meta property="og:title" content="Crossword Wheel - Crossword Anagram Helper">
<meta property="og:description" content="Free crossword anagram helper to shuffle letters and solve anagram clues. Lock letters in place and shuffle the rest until you find the answer. Perfect for crossword enthusiasts.">
<meta property="og:image" content="https://crosswordwheel.com/preview.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://crosswordwheel.com/">
<meta property="twitter:title" content="Crossword Wheel - Crossword Anagram Helper">
<meta property="twitter:description" content="Free crossword anagram helper to shuffle letters and solve anagram clues. Lock letters in place and shuffle the rest until you find the answer.">
<meta property="twitter:image" content="https://crosswordwheel.com/preview.png">
<!-- Canonical URL -->
<link rel="canonical" href="https://crosswordwheel.com/">
<script data-goatcounter="https://ogoodwin505.goatcounter.com/count"
async src="//gc.zgo.at/count.js"></script>
<!-- Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "Crossword Wheel",
"description": "Free crossword anagram helper and letter shuffler. Shuffle letters, lock them in place, and solve anagram clues in crossword puzzles.",
"url": "https://crosswordwheel.com/",
"applicationCategory": "GameApplication",
"operatingSystem": "Any",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
},
"featureList": "Letter shuffling, Lock letters in place, Visual letter wheel, Crossword-style input, Privacy-friendly"
}
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f5f5f0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 12px;
padding: 40px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
}
h1 {
text-align: center;
color: #2d5016;
margin-bottom: 30px;
font-size: 2em;
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
}
.logo {
position: relative;
width: 60px;
height: 60px;
flex-shrink: 0;
}
.logo-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 20px;
height: 20px;
background: #4a7c2c;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 14px;
font-weight: bold;
font-family: 'Montserrat', sans-serif;
}
.logo-outer {
position: absolute;
width: 16px;
height: 16px;
background: #6b9d3e;
border-radius: 50%;
}
.input-section {
margin-bottom: 30px;
}
.input-section.hidden {
display: none;
}
label {
display: block;
margin-bottom: 8px;
color: #333;
font-weight: 600;
}
input[type="text"] {
width: 100%;
padding: 12px;
border: 2px solid #d4a574;
border-radius: 6px;
font-size: 16px;
text-transform: uppercase;
transition: border-color 0.3s;
background: #fffbf5;
}
input[type="text"]:focus {
outline: none;
border-color: #4a7c2c;
}
.letter-wheel {
position: relative;
width: 280px;
height: 280px;
margin: 30px auto;
}
.empty-state {
text-align: center;
color: #999;
font-size: 16px;
margin: 30px 0;
padding: 40px 20px;
background: #f9f9f5;
border-radius: 8px;
border: 2px dashed #d4d4c8;
}
.empty-state-wheel {
position: relative;
width: 180px;
height: 180px;
margin: 0 auto 20px;
}
.empty-state-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 40px;
height: 40px;
background: #d4d4c8;
color: #888;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
font-weight: bold;
font-family: 'Montserrat', sans-serif;
}
.empty-state-outer {
position: absolute;
width: 40px;
height: 40px;
background: #e8e8dc;
color: #999;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
font-weight: bold;
font-family: 'Montserrat', sans-serif;
}
.empty-state-boxes {
display: flex;
justify-content: center;
gap: 0;
margin: 20px auto 15px;
max-width: 200px;
}
.empty-state-box {
width: 32px;
height: 32px;
border: 2px solid #d4d4c8;
border-left: none;
background: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
font-weight: 700;
color: #ccc;
font-family: 'Montserrat', sans-serif;
}
.empty-state-box:first-child {
border-left: 2px solid #d4d4c8;
}
.center-letter {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 50px;
height: 50px;
background: #4a7c2c;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
font-weight: bold;
box-shadow: 0 2px 8px rgba(74, 124, 44, 0.3);
z-index: 10;
transition: opacity 0.3s, background 0.3s;
}
.center-letter.used {
opacity: 0.65;
background: #a8c99a;
}
.outer-letter {
position: absolute;
width: 50px;
height: 50px;
background: #6b9d3e;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
font-weight: bold;
box-shadow: 0 2px 8px rgba(107, 157, 62, 0.3);
transition: opacity 0.3s, background 0.3s;
}
.outer-letter.used {
opacity: 0.65;
background: #a8c99a;
}
.crossword-container {
display: inline-flex;
justify-content: center;
margin: 30px auto;
flex-wrap: nowrap;
border: none;
}
.crossword-container::-webkit-scrollbar {
height: 8px;
}
.crossword-container::-webkit-scrollbar-track {
background: #f0e8d8;
border-radius: 4px;
}
.crossword-container::-webkit-scrollbar-thumb {
background: #d4a574;
border-radius: 4px;
}
.crossword-box {
width: 48px;
min-width: 15px;
max-width: 48px;
aspect-ratio: 1 / 1;
border: 2px solid #2d2d2d;
border-left: none;
background: #f5f5f0;
text-align: center;
font-size: 28px;
font-weight: 700;
text-transform: uppercase;
transition: background 0.2s, color 0.2s;
font-family: 'Montserrat', sans-serif;
flex: 1 1 48px;
padding: 0;
margin: 0;
line-height: 48px;
cursor: pointer;
text-indent: 0;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
outline: none;
-webkit-user-select: text;
user-select: text;
caret-color: transparent;
}
@media (max-width: 768px) {
.crossword-box {
max-width: 38px;
flex: 1 1 38px;
}
}
@media (max-width: 480px) {
.crossword-box {
max-width: 32px;
flex: 1 1 32px;
}
}
.crossword-box:first-child {
border-left: 2px solid #2d2d2d;
}
.crossword-box.manually-entered {
background: #d4a574;
color: #2d2d2d;
}
.crossword-box:focus {
outline: none;
background: #f0e8d8;
}
button {
width: 100%;
padding: 15px;
background: #4a7c2c;
color: white;
border: none;
border-radius: 6px;
font-size: 18px;
font-weight: bold;
cursor: pointer;
transition: background 0.2s, transform 0.1s;
}
button:hover {
background: #3d6624;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.button-group {
display: flex;
gap: 10px;
margin-top: 20px;
}
.button-group button {
flex: 1;
}
.share-button {
background: #d4a574;
color: #2d2d2d;
}
.share-button:hover {
background: #c89660;
}
.error-message {
color: #e74c3c;
text-align: center;
margin: 10px 0;
font-size: 14px;
min-height: 20px;
}
.instructions {
background: #f0e8d8;
padding: 15px;
border-radius: 6px;
margin-bottom: 20px;
font-size: 14px;
color: #2d2d2d;
border-left: 4px solid #d4a574;
}
.instructions ul {
margin-left: 20px;
margin-top: 8px;
}
.instructions li {
margin: 5px 0;
}
.crossword-wrapper {
display: flex;
justify-content: center;
width: 100%;
max-width: 100%;
overflow: hidden;
padding: 0 10px;
}
.crossword-container {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h1>
<div class="logo">
<div class="logo-center">?</div>
<div class="logo-outer" style="left: 22px; top: 3px;"></div>
<div class="logo-outer" style="left: 38px; top: 14px;"></div>
<div class="logo-outer" style="left: 38px; top: 30px;"></div>
<div class="logo-outer" style="left: 22px; top: 41px;"></div>
<div class="logo-outer" style="left: 6px; top: 30px;"></div>
<div class="logo-outer" style="left: 6px; top: 14px;"></div>
</div>
<span>The Crossword Wheel</span>
</h1>
<div class="input-section">
<label for="letters-input">Enter letters to Anagram:</label>
<input type="text" id="letters-input" placeholder="Enter letters" maxlength="20">
</div>
<div class="input-section hidden">
<label for="length-input">Word Length (optional):</label>
<input type="text" id="length-input" placeholder="Leave empty to use all letters" maxlength="2">
</div>
<div class="error-message" id="error-message"></div>
<div id="empty-state" class="empty-state">
<div class="empty-state-wheel">
<div class="empty-state-center">C</div>
<div class="empty-state-outer" style="left: 70px; top: 0px;">R</div>
<div class="empty-state-outer" style="left: 130px; top: 40px;">Y</div>
<div class="empty-state-outer" style="left: 130px; top: 100px;">P</div>
<div class="empty-state-outer" style="left: 70px; top: 140px;">T</div>
<div class="empty-state-outer" style="left: 10px; top: 100px;">I</div>
<div class="empty-state-outer" style="left: 10px; top: 40px;">C</div>
</div>
<div class="empty-state-boxes">
<div class="empty-state-box">?</div>
<div class="empty-state-box">?</div>
<div class="empty-state-box">?</div>
<div class="empty-state-box">?</div>
<div class="empty-state-box">?</div>
</div>
<p>Enter letters above to get started!</p>
</div>
<div class="letter-wheel" id="letter-wheel"></div>
<div class="crossword-wrapper">
<div class="crossword-container" id="crossword-container"></div>
</div>
<button onclick="shuffle()" id="shuffle-button" style="display: none;">🔀 Shuffle Letters</button>
<button class="share-button" onclick="shareApp()" id="share-button" style="margin-top: 10px; display: none;">📤 Share</button>
<div class="instructions" style="margin-top: 30px;">
<strong>How to use:</strong>
<ul>
<li>Enter your letters (one will be placed in the center)</li>
<li>Click a crossword box and type a letter to fix it in place</li>
<li>Click shuffle to randomize remaining letters</li>
</ul>
</div>
</div>
<script>
let availableLetters = [];
let centerLetter = '';
let wordLength = 0;
let fixedLetters = {};
let manuallyEnteredPositions = new Set(); // Track which positions were manually typed
let selectedBoxIndex = null; // Track currently selected box
// Initialize the app
document.getElementById('letters-input').addEventListener('input', function(e) {
const value = e.target.value.toUpperCase().replace(/[^A-Z]/g, '');
e.target.value = value;
initializeGame();
});
document.getElementById('length-input').addEventListener('input', function(e) {
const value = e.target.value.replace(/[^0-9]/g, '');
e.target.value = value;
initializeGame();
});
function initializeGame() {
const lettersInput = document.getElementById('letters-input').value.toUpperCase();
const lengthInput = document.getElementById('length-input').value;
const errorMessage = document.getElementById('error-message');
const emptyState = document.getElementById('empty-state');
const shuffleButton = document.getElementById('shuffle-button');
const shareButton = document.getElementById('share-button');
errorMessage.textContent = '';
if (lettersInput.length === 0) {
document.getElementById('letter-wheel').innerHTML = '';
document.getElementById('crossword-container').innerHTML = '';
emptyState.style.display = 'block';
shuffleButton.style.display = 'none';
shareButton.style.display = 'none';
return;
}
if (lettersInput.length < 3) {
errorMessage.textContent = 'Please enter at least 3 letters';
emptyState.style.display = 'block';
shuffleButton.style.display = 'none';
shareButton.style.display = 'none';
return;
}
// Hide empty state and show buttons when letters are entered
emptyState.style.display = 'none';
shuffleButton.style.display = 'block';
shareButton.style.display = 'block';
availableLetters = lettersInput.split('');
centerLetter = availableLetters[0];
wordLength = lengthInput ? parseInt(lengthInput) : availableLetters.length;
if (wordLength > availableLetters.length) {
errorMessage.textContent = 'Word length cannot exceed available letters';
wordLength = availableLetters.length;
}
if (wordLength < 1) {
wordLength = availableLetters.length;
}
fixedLetters = {};
manuallyEnteredPositions.clear();
renderWheel();
renderCrossword();
}
function renderWheel() {
const wheel = document.getElementById('letter-wheel');
wheel.innerHTML = '';
// Center letter
const centerDiv = document.createElement('div');
centerDiv.className = 'center-letter';
centerDiv.textContent = centerLetter;
wheel.appendChild(centerDiv);
// Outer letters
const outerLetters = availableLetters.slice(1);
const angleStep = (2 * Math.PI) / outerLetters.length;
const radius = 110;
outerLetters.forEach((letter, index) => {
const angle = angleStep * index - Math.PI / 2;
const x = 140 + radius * Math.cos(angle);
const y = 140 + radius * Math.sin(angle);
const letterDiv = document.createElement('div');
letterDiv.className = 'outer-letter';
letterDiv.textContent = letter;
letterDiv.style.left = (x - 25) + 'px';
letterDiv.style.top = (y - 25) + 'px';
// Check if this letter is used in fixed positions
const isUsed = Object.values(fixedLetters).filter(l => l === letter).length >
availableLetters.filter(l => l === letter).length -
outerLetters.filter(l => l === letter).length;
wheel.appendChild(letterDiv);
});
updateWheelOpacity();
}
function renderCrossword() {
const container = document.getElementById('crossword-container');
container.innerHTML = '';
for (let i = 0; i < wordLength; i++) {
const box = document.createElement('div');
box.className = 'crossword-box';
box.dataset.index = i;
box.textContent = fixedLetters[i] || '';
box.contentEditable = true; // Makes keyboard appear on mobile
box.inputMode = 'text'; // Optimizes mobile keyboard
box.autocapitalize = 'characters';
box.spellcheck = false;
// Apply manually-entered styling if this position was manually entered
if (manuallyEnteredPositions.has(i)) {
box.classList.add('manually-entered');
}
// Focus to select box
box.addEventListener('focus', function(e) {
selectedBoxIndex = i;
// Remove focus style from all boxes
container.querySelectorAll('.crossword-box').forEach(b => {
b.style.boxShadow = 'none';
});
// Add focus style to selected box
e.target.style.boxShadow = 'inset 0 0 0 3px #4a7c2c';
// Select all text on focus for easy replacement
setTimeout(() => {
const range = document.createRange();
range.selectNodeContents(e.target);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}, 10);
});
// Handle blur
box.addEventListener('blur', function(e) {
e.target.style.boxShadow = 'none';
});
// Handle input event
box.addEventListener('input', function(e) {
const text = e.target.textContent;
if (text) {
const value = text.toUpperCase().replace(/[^A-Z]/g, '');
if (value) {
const lastChar = value[value.length - 1];
// Check if letter is available
const usedCount = Object.values(fixedLetters).filter(l => l === lastChar).length;
const availableCount = availableLetters.filter(l => l === lastChar).length;
if (usedCount >= availableCount) {
e.target.textContent = fixedLetters[i] || '';
return;
}
// Set the letter
fixedLetters[i] = lastChar;
manuallyEnteredPositions.add(i);
e.target.textContent = lastChar;
e.target.classList.add('manually-entered');
updateWheelOpacity();
// Move to next box
const nextIndex = i + 1;
const nextBox = container.querySelector(`div[data-index="${nextIndex}"]`);
if (nextBox) {
nextBox.focus();
}
} else {
// Clear if no valid letter
e.target.textContent = '';
}
}
});
// Prevent newlines and limit to 1 character
box.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
return false;
}
});
// Paste prevention to avoid multi-character paste
box.addEventListener('paste', function(e) {
e.preventDefault();
const text = (e.clipboardData || window.clipboardData).getData('text');
const char = text.toUpperCase().replace(/[^A-Z]/g, '')[0];
if (char) {
document.execCommand('insertText', false, char);
}
});
container.appendChild(box);
}
// Dynamically adjust font size based on actual box size
setTimeout(() => {
const boxes = document.querySelectorAll('.crossword-box');
if (boxes.length > 0) {
const actualWidth = boxes[0].offsetWidth;
const fontSize = actualWidth * 0.50; // 50% of box width to fit wide letters like W
boxes.forEach(box => {
box.style.fontSize = `${fontSize}px`;
box.style.lineHeight = `${actualWidth}px`; // Match box height for vertical centering
});
}
}, 50);
}
function updateWheelOpacity() {
const wheel = document.getElementById('letter-wheel');
const centerLetterDiv = wheel.querySelector('.center-letter');
const outerLetterDivs = wheel.querySelectorAll('.outer-letter');
// Count how many times each letter is used in fixed positions
const fixedCounts = {};
Object.values(fixedLetters).forEach(letter => {
fixedCounts[letter] = (fixedCounts[letter] || 0) + 1;
});
// Grey out letters one by one as they are used
// For each unique letter, grey the first N occurrences where N = times it's used
// Process center letter
if (centerLetterDiv) {
const centerLetter = centerLetterDiv.textContent;
const usedCount = fixedCounts[centerLetter] || 0;
// Count how many of this letter we've greyed so far
let greyedSoFar = 0;
// Grey center if we still need to grey more instances
if (greyedSoFar < usedCount) {
centerLetterDiv.classList.add('used');
greyedSoFar++;
} else {
centerLetterDiv.classList.remove('used');
}
// Store for outer letters of same type
fixedCounts[centerLetter + '_greyed'] = greyedSoFar;
}
// Process each outer letter
const outerLetters = availableLetters.slice(1);
outerLetterDivs.forEach((div, index) => {
const letter = outerLetters[index];
const usedCount = fixedCounts[letter] || 0;
// Get how many we've already greyed (including center if same letter)
let greyedSoFar = fixedCounts[letter + '_greyed'] || 0;
// Grey this occurrence if we still need to grey more
if (greyedSoFar < usedCount) {
div.classList.add('used');
greyedSoFar++;
fixedCounts[letter + '_greyed'] = greyedSoFar;
} else {
div.classList.remove('used');
}
});
}
function shuffle() {
if (availableLetters.length === 0) {
document.getElementById('error-message').textContent = 'Please enter letters first';
return;
}
// Get unfixed positions
const unfixedPositions = [];
for (let i = 0; i < wordLength; i++) {
if (!fixedLetters[i]) {
unfixedPositions.push(i);
}
}
// Get unfixed letters from available letters
const usedLetters = Object.values(fixedLetters);
const unfixedLetters = [];
// Get unique letters to avoid processing duplicates multiple times
const uniqueLetters = [...new Set(availableLetters)];
uniqueLetters.forEach(letter => {
const usedCount = usedLetters.filter(l => l === letter).length;
const availableCount = availableLetters.filter(l => l === letter).length;
const remainingCount = availableCount - usedCount;
for (let i = 0; i < remainingCount; i++) {
unfixedLetters.push(letter);
}
});
// Shuffle unfixed letters
const shuffled = unfixedLetters.sort(() => Math.random() - 0.5);
// Place shuffled letters in unfixed positions
unfixedPositions.forEach((pos, index) => {
if (index < shuffled.length) {
const box = document.querySelector(`div[data-index="${pos}"]`);
if (box) {
box.textContent = shuffled[index];
// Remove manually-entered styling from shuffled letters
box.classList.remove('manually-entered');
manuallyEnteredPositions.delete(pos);
}
}
});
// Shuffle the wheel - shuffle ALL letters including center
availableLetters = availableLetters.sort(() => Math.random() - 0.5);
centerLetter = availableLetters[0];
renderWheel();
}
// Share function
async function shareApp() {
const shareData = {
title: 'Crossword Wheel - Crossword Helper',
text: 'Check out this free tool to shuffle letters and solve anagram clues in crosswords!',
url: 'https://crosswordwheel.com/'
};
try {
// Try native Web Share API first (mobile-friendly)
if (navigator.share) {
await navigator.share(shareData);
} else {
// Fallback: copy to clipboard
await navigator.clipboard.writeText(shareData.url);
// Show feedback
const errorMsg = document.getElementById('error-message');
const originalText = errorMsg.textContent;
errorMsg.style.color = '#10b981';
errorMsg.textContent = 'Link copied to clipboard!';
setTimeout(() => {
errorMsg.textContent = originalText;
errorMsg.style.color = '#e74c3c';
}, 3000);
}
} catch (err) {
console.log('Share failed:', err);
}
}
// Global keyboard listener for crossword box input (mainly for backspace and arrow keys)
document.addEventListener('keydown', function(e) {
// Ignore if typing in the letters input field
if (document.activeElement.id === 'letters-input' ||
document.activeElement.id === 'length-input') {
return;
}
// Check if a crossword box is focused
const currentBox = document.activeElement;
if (!currentBox.classList.contains('crossword-box')) return;
const container = document.getElementById('crossword-container');
const currentIndex = parseInt(currentBox.dataset.index);
// Handle backspace
if (e.key === 'Backspace') {
if (!currentBox.textContent) {
e.preventDefault();
// Move to previous box
const prevIndex = currentIndex - 1;
const prevBox = container.querySelector(`div[data-index="${prevIndex}"]`);
if (prevBox) {
prevBox.focus();
// Clear the previous box
delete fixedLetters[prevIndex];
manuallyEnteredPositions.delete(prevIndex);
prevBox.textContent = '';
prevBox.classList.remove('manually-entered');
updateWheelOpacity();
}
} else {
// Clear current box
delete fixedLetters[currentIndex];
manuallyEnteredPositions.delete(currentIndex);
currentBox.classList.remove('manually-entered');
updateWheelOpacity();
}
}
// Handle arrow keys for navigation
else if (e.key === 'ArrowRight') {
e.preventDefault();
const nextIndex = currentIndex + 1;
const nextBox = container.querySelector(`div[data-index="${nextIndex}"]`);
if (nextBox) {
nextBox.focus();
}
}
else if (e.key === 'ArrowLeft') {
e.preventDefault();
const prevIndex = currentIndex - 1;
const prevBox = container.querySelector(`div[data-index="${prevIndex}"]`);
if (prevBox) {
prevBox.focus();
}
}
});
// Initialize on load
window.addEventListener('load', initializeGame);
</script>
</body>
</html>