Created
February 22, 2023 16:52
-
-
Save serhatyuna/805d596e3ccdb608d718c27cb997309e to your computer and use it in GitHub Desktop.
sudoku.com solver
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
function solve() { | |
const notesButton = document.querySelector('.game-controls-item.game-controls-pencil'); | |
notesButton.dispatchEvent(new Event('mousedown')); | |
notesButton.dispatchEvent(new Event('mousedown')); | |
const game = JSON.parse(localStorage.getItem('main_game')); | |
const solution = game.solution; | |
const values = game.values.map(value => value.editable); | |
const keyCodes = { '1': 49, '2': 50, '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, '8': 56, '9': 57 }; | |
window.dispatchEvent(new Event('focus')); | |
for(let i = 1; i <= 81; i++) { | |
if (values[i - 1]) { | |
window.dispatchEvent(new KeyboardEvent('keydown', {'keyCode': keyCodes[solution[i - 1]]})); | |
} | |
if (i != 81 && i % 9 === 0) { | |
window.dispatchEvent(new KeyboardEvent('keydown', {'keyCode': 40})); | |
for (let j = 0; j < 9; j++) { | |
window.dispatchEvent(new KeyboardEvent('keydown', {'keyCode': 37})); | |
} | |
} else { | |
window.dispatchEvent(new KeyboardEvent('keydown', {'keyCode': 39})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment