From b5345e1a4de36ece16f93bed0fafb5e679854f69 Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 30 Mar 2023 01:12:02 +0200 Subject: [PATCH 1/2] optimize --- js/sudoku.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/sudoku.js b/js/sudoku.js index bcb0758..b7a3c89 100755 --- a/js/sudoku.js +++ b/js/sudoku.js @@ -10,6 +10,7 @@ let valueToInsert = "" let history = [] let accessKeyModifiers = "AccessKey+" let easyBoxes = [] +let insertRadios = [] function shuffle(iterable) { array = Array.from(iterable) @@ -59,11 +60,14 @@ window.onload = function() { boxes.forEach(box => { box.neighbourhood = new Set(rows[box.rowId].concat(columns[box.columnId]).concat(regions[box.regionId])) + box.andNeighbourhood = Array.from(box.neighbourhood) box.neighbourhood.delete(box) box.neighbourhood = Array.from(box.neighbourhood) searchCandidatesOf(box) }) + insertRadios = Array.from(insertRadioGroup.getElementsByTagName("input")) + for (label of document.getElementsByTagName("label")) { label.control.label = label } @@ -169,7 +173,7 @@ function refreshBox(box) { } function checkBox(box) { - box.neighbourhood.concat([box]).forEach(neighbour => { + box.andNeighbourhood.forEach(neighbour => { neighbour.setCustomValidity("") neighbour.classList.remove("is-invalid") searchCandidatesOf(neighbour) @@ -217,7 +221,7 @@ function refreshUI() { } function enableRadio() { - for (radio of insertRadioGroup.getElementsByTagName("input")) { + for (radio of insertRadios) { if (boxes.filter(box => box.value == "").some(box => box.candidates.has(radio.value))) { radio.disabled = false radio.label.title = `Insérer un ${radio.value} [${radio.accessKeyLabel||(accessKeyModifiers+radio.accessKey)}]` @@ -228,6 +232,7 @@ function enableRadio() { valueToInsert = "" } } + insertRadios = insertRadios.filter(radio => !radio.disabled) } function highlight() { @@ -241,6 +246,7 @@ function highlight() { box.parentElement.classList.remove("table-primary") box.tabIndex = 0 } + if (valueToInsert && highlighterCheckbox.checked && !box.candidates.has(valueToInsert)) { box.parentElement.classList.add("table-active") box.tabIndex = -1 @@ -261,7 +267,7 @@ function onblur() { if (this.classList.contains("pencil")) { this.placeholder = this.value this.value = "" - //this.type = "number" + //this.type = "number" this.classList.remove("pencil") } } From 9191b6836c359fcdfb654c98cc23053827fe6ec1 Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 30 Mar 2023 01:21:34 +0200 Subject: [PATCH 2/2] fix insertRadio filter --- js/sudoku.js | 1 - sudoku.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/sudoku.js b/js/sudoku.js index b7a3c89..3f34690 100755 --- a/js/sudoku.js +++ b/js/sudoku.js @@ -232,7 +232,6 @@ function enableRadio() { valueToInsert = "" } } - insertRadios = insertRadios.filter(radio => !radio.disabled) } function highlight() { diff --git a/sudoku.php b/sudoku.php index 1f1d04a..ad87e6a 100755 --- a/sudoku.php +++ b/sudoku.php @@ -74,7 +74,7 @@
\n"; + echo " \n"; } ?>