feat & fix : intégration IA éditeur + onglet admin IA + corrections CSP (v1.6.24-25)
- #96 : boutons IA sidebar éditeur (analyse critique / réécriture) via Anthropic API - #97 : onglet admin /admin/ia — provider anthropic/claude_code, modèle, procédure CLI - #95 : extraction scripts inline vers fichiers JS (comments.js, post_confirm.js, admin.js) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
// ai-editor.js — boutons IA dans la sidebar éditeur
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var btnCritique = document.getElementById('btn-ai-critique');
|
||||
var btnRewrite = document.getElementById('btn-ai-rewrite');
|
||||
if (!btnCritique || !btnRewrite) return;
|
||||
|
||||
var panel = document.getElementById('ai-result-panel');
|
||||
var labelEl = document.getElementById('ai-result-label');
|
||||
var resultEl = document.getElementById('ai-result-content');
|
||||
var btnApply = document.getElementById('btn-ai-apply');
|
||||
var btnClose = document.getElementById('btn-ai-close');
|
||||
var ta = document.getElementById('content');
|
||||
var titleEl = document.getElementById('title');
|
||||
|
||||
var lastRewrite = '';
|
||||
|
||||
function setLoading(btn, loading) {
|
||||
btn.disabled = loading;
|
||||
if (loading) {
|
||||
btn._origText = btn.textContent;
|
||||
btn.textContent = 'En cours…';
|
||||
} else {
|
||||
btn.textContent = btn._origText || btn.textContent;
|
||||
}
|
||||
}
|
||||
|
||||
async function callAi(action) {
|
||||
var btn = (action === 'critique') ? btnCritique : btnRewrite;
|
||||
|
||||
setLoading(btn, true);
|
||||
panel.style.display = 'none';
|
||||
btnApply.style.display = 'none';
|
||||
lastRewrite = '';
|
||||
|
||||
try {
|
||||
var res = await fetch('/?action=ai_query', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams({
|
||||
action: action,
|
||||
title: titleEl ? titleEl.value : '',
|
||||
content: ta ? ta.value : '',
|
||||
}),
|
||||
});
|
||||
|
||||
var data = await res.json();
|
||||
|
||||
if (!data.ok) {
|
||||
labelEl.textContent = 'Erreur';
|
||||
resultEl.textContent = data.error || 'Erreur inconnue.';
|
||||
} else {
|
||||
labelEl.textContent = (action === 'critique') ? 'Analyse critique' : 'Réécriture';
|
||||
resultEl.textContent = data.text;
|
||||
if (action === 'rewrite') {
|
||||
lastRewrite = data.text;
|
||||
btnApply.style.display = '';
|
||||
}
|
||||
}
|
||||
panel.style.display = '';
|
||||
} catch (e) {
|
||||
labelEl.textContent = 'Erreur';
|
||||
resultEl.textContent = 'Erreur de connexion.';
|
||||
panel.style.display = '';
|
||||
} finally {
|
||||
setLoading(btn, false);
|
||||
}
|
||||
}
|
||||
|
||||
btnCritique.addEventListener('click', function () { callAi('critique'); });
|
||||
btnRewrite.addEventListener('click', function () { callAi('rewrite'); });
|
||||
|
||||
btnApply.addEventListener('click', function () {
|
||||
if (!lastRewrite) return;
|
||||
if (!confirm("Remplacer le contenu de l’éditeur par la réécriture IA ?")) return;
|
||||
if (ta) {
|
||||
ta.value = lastRewrite;
|
||||
ta.dispatchEvent(new Event('input'));
|
||||
}
|
||||
panel.style.display = 'none';
|
||||
btnApply.style.display = 'none';
|
||||
lastRewrite = '';
|
||||
});
|
||||
|
||||
btnClose.addEventListener('click', function () {
|
||||
panel.style.display = 'none';
|
||||
btnApply.style.display = 'none';
|
||||
lastRewrite = '';
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user