Auto-deploy: 2026-05-26 17:30:24

This commit is contained in:
Hamza-Ayed
2026-05-26 17:30:24 +03:00
parent 76113e7d84
commit 9dbdae8684
2 changed files with 40 additions and 37 deletions

View File

@@ -96,24 +96,28 @@
}
// ─── Create the comment suggestion box ───────────────────────────────────
function createCommentBox(postEl, commentText) {
function createCommentBox(postEl, commentText, arabicSummary) {
const existing = postEl.querySelector('.' + BOX_CLASS);
if (existing) existing.remove();
const isRTL = /[\u0600-\u06FF]/.test(commentText);
const box = document.createElement('div');
box.className = BOX_CLASS;
box.innerHTML = `
<div class="lja-cb-header">
<span class="lja-cb-icon">🤖</span>
<span class="lja-cb-title">Smart Comment</span>
<span class="lja-cb-title">Smart Comment & Analysis</span>
<button class="lja-cb-close" title="Close">✕</button>
</div>
<div style="padding: 10px 14px; background: rgba(108, 99, 255, 0.05); border-bottom: 1px solid rgba(255, 255, 255, 0.06);">
<div style="font-size: 11px; color: #a89cff; margin-bottom: 4px; font-weight: 600;">📝 ملخص المنشور:</div>
<div style="font-size: 12px; color: #e0deff; line-height: 1.5; text-align: right;" dir="rtl">
${arabicSummary}
</div>
</div>
<textarea
class="lja-cb-text"
dir="${isRTL ? 'rtl' : 'ltr'}"
style="text-align: ${isRTL ? 'right' : 'left'}"
dir="ltr"
style="text-align: left; font-family: monospace; font-size: 13px;"
>${commentText}</textarea>
<div class="lja-cb-actions">
<button class="lja-cb-copy">📋 Copy</button>
@@ -204,8 +208,24 @@
throw new Error(response.error || 'Unknown error');
}
const commentText = response.data.comment || response.data;
createCommentBox(postEl, commentText);
// Parse the JSON returned by Gemini
let resultData;
let rawText = response.data.comment || response.data;
// Clean up markdown blocks if the AI accidentally adds them
rawText = rawText.replace(/```json/gi, '').replace(/```/g, '').trim();
try {
resultData = JSON.parse(rawText);
} catch (parseError) {
throw new Error('Failed to parse AI response. Raw output: ' + rawText);
}
const arabicSummary = resultData.arabic_summary || 'لم يتم توليد ملخص.';
// Wrap the comment in a code block automatically before placing it in the text area
const commentText = `\`\`\`\n${resultData.comment}\n\`\`\``;
createCommentBox(postEl, commentText, arabicSummary);
} catch (e) {
console.error('[LJA Feed]', e);