Compare commits

...

2 Commits

Author SHA1 Message Date
3834e579a6 Merge commit 'ea141bfde63d43f180c1f50646f239142228822f' 2025-04-24 19:08:03 +02:00
f0b9052211 export du script js 2025-04-24 18:59:50 +02:00
2 changed files with 6 additions and 34 deletions

View File

@ -80,8 +80,8 @@ $grille = new Grille($hauteur, $largeur, $id);
</table>
</h1>
<form id="grilleForm" class="grille" method="get" location=".">
<input type="hidden" id="hauteur" name="lignes" value="<?= $hauteur ?>" />
<input type="hidden" id="largeur" name="colonnes" value="<?= $largeur ?>" />
<input type="hidden" id="lignes" name="lignes" value="<?= $hauteur ?>" />
<input type="hidden" id="colonnes" name="colonnes" value="<?= $largeur ?>" />
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
<table>
<tr>

View File

@ -1,6 +1,3 @@
const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]'));
let nb_cases = inputs.length;
async function sha256(text) {
const encoder = new TextEncoder();
const data = encoder.encode(text);
@ -9,7 +6,11 @@ async function sha256(text) {
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]'));
let largeur = Number(colonnes.value);
let nb_cases = inputs.length;
let index = 0;
inputs.forEach(input => {
input.index = index++;
@ -18,9 +19,6 @@ inputs.forEach(input => {
};
input.onkeydown = function (event) {
console.log(largeur);
largeur = Number(largeur.value);
console.log(largeur);
switch (event.key) {
case 'ArrowUp':
inputs[(input.index - largeur + nb_cases) % nb_cases].focus();
@ -37,32 +35,6 @@ inputs.forEach(input => {
}
};
input.oninput = function (event) {
this.value = this.value.toUpperCase();
if (!input.checkValidity()) {
input.value = '';
}
if (grilleForm.checkValidity()) {
sha256(inputs.map(input => input.value).join('')).then(hash => {
if (hash == '<?= $grille->hash() ?>') {
if (confirm('Bravo ! \nUne nouvelle partie ?')) {
location.href = location.href.replace(/grille=[a-f0-9]{13}&/, '');
}
}
});
}
};
});
document.querySelectorAll('input').forEach(input => {
input.onkeydown = function (event) {
switch (event.key) {
case 'ArrowRight':
inputs[(input.index + 1) % nb_cases].focus();
break;
}
};
input.oninput = function (event) {
this.value = this.value.toUpperCase();
if (!input.checkValidity()) {