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
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:
@@ -2,63 +2,49 @@
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>⚡ Sandbox - Découverte de Table</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; background: #333; padding: 50px; color: white; }
|
||||
.modal { background: white; padding: 20px; border-radius: 12px; width: 400px; margin: 0 auto; color: black; }
|
||||
.debug-panel { margin-top: 20px; padding: 15px; background: #222; border-radius: 8px; font-family: monospace; }
|
||||
.btn { padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; margin: 5px; background: #1976d2; color: white; }
|
||||
</style>
|
||||
<title>⚡ Récupération Dynamique Totale</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="modal">
|
||||
<h3>Découverte automatique</h3>
|
||||
<button class="btn" onclick="discoverCategories()">Lancer la lecture de la table</button>
|
||||
<div id="result-area"></div>
|
||||
</div>
|
||||
|
||||
<div class="debug-panel">
|
||||
<strong>Table des catégories trouvées :</strong>
|
||||
<pre id="table-display">En attente...</pre>
|
||||
</div>
|
||||
<h3>Catégories récupérées en temps réel :</h3>
|
||||
<select id="dynamic-select" style="width:100%; padding:10px;"></select>
|
||||
|
||||
<script>
|
||||
async function discoverCategories() {
|
||||
try {
|
||||
// On lit le fichier source directement depuis le serveur
|
||||
const response = await fetch('/assets/js/app.js');
|
||||
const text = await response.text();
|
||||
|
||||
// On cherche la définition de CATEGORY_LABELS par regex
|
||||
const match = text.match(/const CATEGORY_LABELS = ({[\s\S]*?});/);
|
||||
|
||||
if (match) {
|
||||
// On transforme le bloc trouvé en objet JS
|
||||
const categoryObject = eval('(' + match[1] + ')');
|
||||
|
||||
// Affichage dans le panneau de debug
|
||||
document.getElementById('table-display').innerText = JSON.stringify(categoryObject, null, 2);
|
||||
|
||||
// Génération du menu déroulant
|
||||
renderDropdown(categoryObject);
|
||||
} else {
|
||||
document.getElementById('table-display').innerText = "Erreur : Table CATEGORY_LABELS introuvable dans app.js.";
|
||||
async function fetchRealCategories() {
|
||||
// 1. On récupère le fichier app.js
|
||||
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);
|
||||
|
||||
// 3. On définit un mock pour la fonction de traduction 't' qui bloquait tout
|
||||
iframe.contentWindow.t = (key) => key.split('.').pop();
|
||||
|
||||
// 4. On injecte le code
|
||||
const script = iframe.contentDocument.createElement('script');
|
||||
script.textContent = scriptText;
|
||||
iframe.contentDocument.body.appendChild(script);
|
||||
|
||||
// 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) {
|
||||
const select = document.getElementById('dynamic-select');
|
||||
Object.entries(cats).forEach(([key, val]) => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = key;
|
||||
opt.textContent = val;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById('table-display').innerText = "Erreur de lecture : " + e.message;
|
||||
}
|
||||
document.body.removeChild(iframe);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function renderDropdown(data) {
|
||||
const area = document.getElementById('result-area');
|
||||
const options = Object.entries(data).map(([k, v]) => `<option value="${k}">${v}</option>`).join('');
|
||||
area.innerHTML = `
|
||||
<select style="width:100%; padding:10px; margin-top:10px;">
|
||||
${options}
|
||||
</select>
|
||||
`;
|
||||
}
|
||||
// On lance la découverte au chargement
|
||||
fetchRealCategories();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user