File size: 4,056 Bytes
439ea03 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | // ===== util =====
const toastEl = document.getElementById('toast');
function toast(msg) {
toastEl.hidden = false;
toastEl.textContent = msg;
clearTimeout(toast._t);
toast._t = setTimeout(() => (toastEl.hidden = true), 1400);
}
// ===== éléments =====
const promptInput = document.getElementById('promptInput');
const generateBtn = document.getElementById('generateBtn');
const micBtn = document.getElementById('micBtn');
const codeOutput = document.getElementById('codeOutput');
const copyBtn = document.getElementById('copyBtn');
const clearBtn = document.getElementById('clearBtn');
const colRight = document.getElementById('colRight');
const appTitle = document.getElementById('appTitle');
const appSubtitle = document.getElementById('appSubtitle');
// ===== générateur de code (factice) =====
function fakeGenerate(prompt) {
const p = (prompt || '').trim();
if (!p) return "// Écris une demande puis clique sur Générer ✨";
return `// ✅ Demande reçue : ${p}
function main() {
console.log("Hello Espace Codage!");
}
main();`;
}
// ===== moteur de consignes UI (simple) =====
function isUiCommand(text) {
const t = (text || '').toLowerCase();
return ['colonne', 'cache', 'affiche', 'vide', 'titre', 'sous-titre', 'espace codage'].some((k) => t.includes(k));
}
function applyUiCommand(text) {
const raw = text || '';
const t = raw.toLowerCase();
if (t.includes('cache') && (t.includes('colonne 3') || t.includes('colonne trois') || t.includes('droite'))) {
colRight.style.display = 'none';
toast('✅ Colonne 3 masquée');
return true;
}
if ((t.includes('affiche') || t.includes('montre')) && (t.includes('colonne 3') || t.includes('droite'))) {
colRight.style.display = '';
toast('✅ Colonne 3 affichée');
return true;
}
if (t.includes('colonne 3') && t.includes('vide')) {
colRight.innerHTML = '';
colRight.style.display = '';
toast('✅ Colonne 3 vidée');
return true;
}
// Titre: ...
const mTitle = raw.match(/(?:titre|nom)\s*[:=]\s*(.+)$/i);
if (mTitle) {
appTitle.textContent = mTitle[1].trim();
toast('✅ Titre mis à jour');
return true;
}
// Sous-titre: ...
const mSub = raw.match(/(?:sous[-\s]?titre|description)\s*[:=]\s*(.+)$/i);
if (mSub) {
appSubtitle.textContent = mSub[1].trim();
toast('✅ Sous-titre mis à jour');
return true;
}
toast('ℹ️ Consigne non reconnue');
return false;
}
// ===== actions =====
generateBtn.addEventListener('click', () => {
const text = promptInput.value;
if (isUiCommand(text)) {
if (applyUiCommand(text)) return;
}
codeOutput.textContent = fakeGenerate(text);
});
document.querySelectorAll('.chip').forEach((btn) => {
btn.addEventListener('click', () => {
const p = btn.dataset.prompt || '';
promptInput.value = p;
codeOutput.textContent = fakeGenerate(p);
});
});
copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(codeOutput.textContent);
toast('✅ Copié');
} catch {
alert('Copie impossible automatiquement.');
}
});
clearBtn.addEventListener('click', () => {
promptInput.value = '';
codeOutput.textContent = "// Le code généré apparaîtra ici…";
toast('✅ Effacé');
});
// Micro (si disponible)
let recognition = null;
if ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window) {
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
recognition = new SR();
recognition.lang = 'fr-FR';
recognition.interimResults = true;
recognition.onresult = (event) => {
let transcript = '';
for (let i = event.resultIndex; i < event.results.length; i++) {
transcript += event.results[i][0].transcript;
}
promptInput.value = transcript.trim();
};
}
micBtn.addEventListener('click', () => {
if (!recognition) {
alert('Micro non disponible sur ce navigateur.');
return;
}
try {
recognition.start();
} catch {}
});
// Preuve que le JS charge
toast('✅ Espace Codage prêt'); |