Actualiser test.html
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled

This commit is contained in:
2026-06-17 17:35:47 +00:00
parent eaf9ebc52e
commit a6f59cabfb
+26 -24
View File
@@ -10,40 +10,42 @@
<script> <script>
async function fetchRealCategories() { async function fetchRealCategories() {
// 1. On récupère le fichier app.js try {
const response = await fetch('/assets/js/app.js'); // 1. Récupération du fichier source
const scriptText = await response.text(); const response = await fetch('/assets/js/app.js');
const scriptText = await response.text();
// 2. On crée un "bac à sable" (iframe) pour exécuter le code sans erreurs
const iframe = document.createElement('iframe'); // 2. Extraction du bloc CATEGORY_LABELS par expression régulière
iframe.style.display = 'none'; // On cible le bloc entre { et }
document.body.appendChild(iframe); const regex = /const CATEGORY_LABELS = ({[\s\S]*?});/;
const match = scriptText.match(regex);
// 3. On définit un mock pour la fonction de traduction 't' qui bloquait tout
iframe.contentWindow.t = (key) => key.split('.').pop(); if (match) {
// On nettoie le texte pour le rendre compatible JSON
// 4. On injecte le code // On supprime les appels t(...) et on transforme les backticks en guillemets
const script = iframe.contentDocument.createElement('script'); let cleanJson = match[1]
script.textContent = scriptText; .replace(/'/g, '"')
iframe.contentDocument.body.appendChild(script); .replace(/\s*:\s*`.*?\$\{t\('(.*?)'\)\}`/g, ': "$1"')
.replace(/,\s*}/g, '}');
// 5. On attend un instant que la variable soit déclarée et on la récupère const categories = JSON.parse(cleanJson);
setTimeout(() => {
const cats = iframe.contentWindow.CATEGORY_LABELS; // 3. Affichage
if (cats) {
const select = document.getElementById('dynamic-select'); const select = document.getElementById('dynamic-select');
Object.entries(cats).forEach(([key, val]) => { Object.entries(categories).forEach(([key, val]) => {
const opt = document.createElement('option'); const opt = document.createElement('option');
opt.value = key; opt.value = key;
opt.textContent = val; opt.textContent = val;
select.appendChild(opt); select.appendChild(opt);
}); });
console.log("Catégories chargées avec succès :", categories);
} }
document.body.removeChild(iframe); } catch (err) {
}, 500); console.error("Erreur de récupération :", err);
}
} }
// On lance la découverte au chargement // Exécution automatique
fetchRealCategories(); fetchRealCategories();
</script> </script>
</body> </body>