Last active
July 28, 2026 19:23
-
-
Save gabrielsroka/1cf04be9aed54a22056e9e356f53c5f1 to your computer and use it in GitHub Desktop.
NYT Connections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(() => { | |
| const words = document.querySelectorAll('label'); | |
| const today = new Date().toDateString(); | |
| const stored = JSON.parse(localStorage.connectionsColors || '{}'); | |
| const colors = stored.date === today ? stored.colors : {}; | |
| const order = ['orchid', 'lightsteelblue', 'yellowgreen', 'khaki']; | |
| let colorMode = true, groupIdx = 0; | |
| words.forEach(word => { | |
| const text = word.querySelector('input').value; | |
| if (colors[text]) word.style.backgroundColor = colors[text]; | |
| word.onclick = evt => { | |
| if (colorMode) { | |
| const rect = word.getBoundingClientRect(); | |
| const left = evt.clientX - rect.left < rect.width / 2, top = evt.clientY - rect.top < rect.height / 2; | |
| const color = top && left ? 'khaki' : top ? 'yellowgreen' : left ? 'lightsteelblue' : 'orchid'; | |
| word.style.backgroundColor = color; | |
| colors[text] = color; | |
| localStorage.connectionsColors = JSON.stringify({date: today, colors}); | |
| document.querySelector('[data-testid=deselect-btn]').click(); | |
| } | |
| }; | |
| }); | |
| const shuffleBtn = document.querySelector('[data-testid=shuffle-btn]'); | |
| const button = document.createElement('button'); | |
| button.textContent = `Submit ${order[groupIdx]}`; | |
| button.className = shuffleBtn.className; | |
| button.onclick = async () => { | |
| colorMode = false; | |
| const color = order[groupIdx]; | |
| words.forEach(word => { | |
| if (word.style.backgroundColor === color) { | |
| const props = word[Object.keys(word).find(k => k.startsWith('__reactProps'))]; | |
| props.onPointerDown(); | |
| props.onPointerUp(); | |
| } | |
| }); | |
| await new Promise(res => setTimeout(res, 0)); | |
| document.querySelector('button[type=submit]').click(); | |
| groupIdx++; | |
| button.textContent = groupIdx < order.length ? `Submit ${order[groupIdx]}` : 'Done'; | |
| }; | |
| shuffleBtn.before(button); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment