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,51 +2,39 @@
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>⚡ Récupération Dynamique Totale</title>
|
||||
<title>⚡ Récupération Directe</title>
|
||||
</head>
|
||||
<body>
|
||||
<h3>Catégories récupérées en temps réel :</h3>
|
||||
<h3>Catégories récupérées depuis la mémoire :</h3>
|
||||
<select id="dynamic-select" style="width:100%; padding:10px;"></select>
|
||||
|
||||
<script>
|
||||
async function fetchRealCategories() {
|
||||
try {
|
||||
// 1. Récupération du fichier source
|
||||
const response = await fetch('/assets/js/app.js');
|
||||
const scriptText = await response.text();
|
||||
// On crée une balise script qui pointe vers le fichier source d'EverShelf
|
||||
const script = document.createElement('script');
|
||||
script.src = '/assets/js/app.js';
|
||||
|
||||
// 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);
|
||||
script.onload = () => {
|
||||
// Une fois le script chargé, la variable CATEGORY_LABELS est maintenant disponible dans la mémoire de cette page
|
||||
const cats = window.CATEGORY_LABELS;
|
||||
|
||||
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, '}');
|
||||
|
||||
const categories = JSON.parse(cleanJson);
|
||||
|
||||
// 3. Affichage
|
||||
if (cats) {
|
||||
const select = document.getElementById('dynamic-select');
|
||||
Object.entries(categories).forEach(([key, val]) => {
|
||||
|
||||
// On itère sur les clés de l'objet
|
||||
Object.keys(cats).forEach(key => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = key;
|
||||
opt.textContent = val;
|
||||
// On affiche le texte brut (en ignorant le résultat de la fonction t())
|
||||
opt.textContent = key;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
console.log("Catégories chargées avec succès :", categories);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Erreur de récupération :", err);
|
||||
}
|
||||
console.log("Données récupérées :", cats);
|
||||
} else {
|
||||
console.error("Variable CATEGORY_LABELS non trouvée après chargement.");
|
||||
}
|
||||
};
|
||||
|
||||
// Exécution automatique
|
||||
fetchRealCategories();
|
||||
document.head.appendChild(script);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user