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
+21 -19
View File
@@ -10,40 +10,42 @@
<script>
async function fetchRealCategories() {
// 1. On récupère le fichier app.js
try {
// 1. Récupération du fichier source
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');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// 2. Extraction du bloc CATEGORY_LABELS par expression régulière
// On cible le bloc entre { et }
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
// On supprime les appels t(...) et on transforme les backticks en guillemets
let cleanJson = match[1]
.replace(/'/g, '"')
.replace(/\s*:\s*`.*?\$\{t\('(.*?)'\)\}`/g, ': "$1"')
.replace(/,\s*}/g, '}');
// 4. On injecte le code
const script = iframe.contentDocument.createElement('script');
script.textContent = scriptText;
iframe.contentDocument.body.appendChild(script);
const categories = JSON.parse(cleanJson);
// 5. On attend un instant que la variable soit déclarée et on la récupère
setTimeout(() => {
const cats = iframe.contentWindow.CATEGORY_LABELS;
if (cats) {
// 3. Affichage
const select = document.getElementById('dynamic-select');
Object.entries(cats).forEach(([key, val]) => {
Object.entries(categories).forEach(([key, val]) => {
const opt = document.createElement('option');
opt.value = key;
opt.textContent = val;
select.appendChild(opt);
});
console.log("Catégories chargées avec succès :", categories);
}
} catch (err) {
console.error("Erreur de récupération :", err);
}
document.body.removeChild(iframe);
}, 500);
}
// On lance la découverte au chargement
// Exécution automatique
fetchRealCategories();
</script>
</body>