| |
| const toastEl = document.getElementById('toast'); |
| function toast(msg) { |
| toastEl.hidden = false; |
| toastEl.textContent = msg; |
| clearTimeout(toast._t); |
| toast._t = setTimeout(() => (toastEl.hidden = true), 1400); |
| } |
|
|
| |
| 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'); |
|
|
| |
| 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();`; |
| } |
|
|
| |
| 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; |
| } |
|
|
| |
| const mTitle = raw.match(/(?:titre|nom)\s*[:=]\s*(.+)$/i); |
| if (mTitle) { |
| appTitle.textContent = mTitle[1].trim(); |
| toast('✅ Titre mis à jour'); |
| return true; |
| } |
|
|
| |
| 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; |
| } |
|
|
| |
| 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é'); |
| }); |
|
|
| |
| 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 {} |
| }); |
|
|
| |
| toast('✅ Espace Codage prêt'); |