/** * @fileoverview Facebook Campaign Composer UI & Quick Reload History Registry * @module ui/facebook-ui * @description بناء واجهة محرر منشورات فيسبوك، رفع المرفقات، وسجل التعبئة السريعة للمنشورات السابقة. */ (global => { 'use strict'; let uploadedImages = []; /** * تعيين نص محرر المنشور وإطلاق حدث التحديث * @param {string} text */ const setComposerText = (text) => { const el = document.getElementById('nmr6mtwgan'); if (el) { el.value = text; el.dispatchEvent(new Event('input', { bubbles: true })); } }; /** * بناء واجهة محرر منشورات فيسبوك بالـ DOM */ const buildComposerLayout = () => { const sidebar = document.getElementById('bmh59axx92'); const contentArea = document.getElementById('s7ihkirolg'); if (!sidebar || !contentArea) return; if (!sidebar.querySelector('[data-target="sf1xx5vcac"]')) { const navItem = document.createElement('div'); navItem.className = 'f2rj8bz2yt'; navItem.setAttribute('data-target', 'sf1xx5vcac'); navItem.innerHTML = ' منشورات فيسبوك'; sidebar.appendChild(navItem); navItem.addEventListener('click', () => { window.location.hash = 'sf1xx5vcac'; }); } const host = document.getElementById('fritree-dynamic-panes-host') || contentArea; let pane = document.getElementById('sf1xx5vcac'); if (!pane) { pane = document.createElement('section'); pane.className = 'rjiai07g77'; pane.id = 'sf1xx5vcac'; const monitor = document.getElementById('cxyr0eirov'); if (host === contentArea && monitor) { contentArea.insertBefore(pane, monitor); } else { host.appendChild(pane); } } else if (pane.parentElement !== host) { host.appendChild(pane); } let grid = pane.querySelector('.xd506q5mar'); if (!grid) { grid = document.createElement('div'); grid.className = 'xd506q5mar'; grid.style.cssText = 'display: grid; grid-template-columns: repeat(auto-fit, minmax(clamp(280px, 40vw, 1fr), 1fr)); gap: var(--space-md); margin-bottom: 15px; width: 100%; box-sizing: border-box;'; pane.appendChild(grid); } let composerCol = grid.querySelector('#tm3qz6sfor'); if (composerCol) return; composerCol = document.createElement('div'); composerCol.className = 'd5tp7way8h'; composerCol.id = 'tm3qz6sfor'; composerCol.style.cssText = 'display: flex; flex-direction: column; height: 100%; box-sizing: border-box;'; composerCol.innerHTML = `
كتابة منشورات فيسبوك للحملات
محرك تجهيز نصوص الـ Spintax والتمويه
البدائل الفريدة للتوليد: 1 مستوى التفرد: 0%
إدراج متغير:
اسحب وأفلت الصور والفيديوهات هنا أو اضغط لاختيار الملفات من جهازك...
`; grid.appendChild(composerCol); injectQuickReloadUISection(pane); }; /** * بناء قسم سجل التعبئة السريعة للمنشورات الأخيرة */ const injectQuickReloadUISection = (pane) => { let recentSection = pane.querySelector('#tsh9o5nfi9'); if (!recentSection) { recentSection = document.createElement('div'); recentSection.id = 'tsh9o5nfi9'; recentSection.className = 'd5tp7way8h'; recentSection.style.cssText = 'margin-top: 14px; display: flex; flex-direction: column; width: 100%; border: 1px solid var(--border); box-sizing: border-box;'; recentSection.innerHTML = `
سجل التعبئة السريعة للمنشورات الأخيرة
لا توجد منشورات مسجلة حديثاً في سجل التعبئة السريعة.
`; pane.appendChild(recentSection); } renderRecentPublishedList(); }; /** * حفظ المنشور المنشور حديثاً بسجل التعبئة السريعة */ const savePublishedPostToRecent = async (text, images, groupIds) => { const recentList = await global.FritreeStorage.get('fbRecentPublishedPosts', []); const recentId = 'recent_fb_' + Date.now() + '_' + Math.random().toString(36).substr(2, 4); const newRecord = { id: recentId, text: text, groupIds: groupIds, images: images, timestamp: new Date().toISOString() }; for (const img of images) { const blob = await global.FritreeStorage.get(`media_blob_${img.id}`); if (blob) { await global.FritreeStorage.set(`media_blob_recent_${recentId}_${img.id}`, blob); } } recentList.unshift(newRecord); if (recentList.length > 15) { const popped = recentList.pop(); if (popped && popped.images) { for (const img of popped.images) { await global.FritreeStorage.remove(`media_blob_recent_${popped.id}_${img.id}`); } } } await global.FritreeStorage.set('fbRecentPublishedPosts', recentList); renderRecentPublishedList(); if (global.FritreeCalendar && typeof global.FritreeCalendar.logActivity === 'function') { const titleSnippet = text ? (text.length > 40 ? text.substring(0, 40) + '...' : text) : 'منشور وسائط وصور'; global.FritreeCalendar.logActivity({ title: `[منشور فيسبوك] ${titleSnippet}`, type: 'campaign', category: 'campaign', notes: `حملة نشر فيسبوك فورية على عدد (${groupIds ? groupIds.length : 0}) مجموعة مستهدفة. المرفقات: ${images ? images.length : 0} صورة/فيديو.`, priority: 'high' }); } }; /** * رسم وعرض بطاقات المنشورات الأخيرة في سجل التعبئة السريعة */ const renderRecentPublishedList = async () => { const container = document.getElementById('r7n5amvrzl'); if (!container) return; container.innerHTML = ''; const recentList = await global.FritreeStorage.get('fbRecentPublishedPosts', []); if (recentList.length === 0) { container.innerHTML = `
لا توجد منشورات مسجلة حديثاً في سجل التعبئة السريعة.
`; return; } recentList.forEach(item => { const card = document.createElement('div'); card.style.cssText = 'background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; display: flex; flex-direction: column; gap: 8px; text-align: right; direction: rtl; box-sizing: border-box; box-shadow: var(--shadow-xs);'; card.className = 'nip0io690t'; const excerpt = item.text ? (item.text.length > 50 ? item.text.substring(0, 50) + '...' : item.text) : '[صور/فيديو فقط بدون نص]'; const dateStr = new Date(item.timestamp).toLocaleTimeString('en-US', {hour: '2-digit', minute: '2-digit'}) + ' - ' + new Date(item.timestamp).toLocaleDateString(); card.innerHTML = `
منشور محفوظ ${dateStr}
${excerpt}
الجروبات: ${item.groupIds.length} الصور: ${item.images ? item.images.length : 0}
`; const groupsBtn = card.querySelector('.zutkbm6ve4'); const contentBtn = card.querySelector('.fat9x5gp73'); const allBtn = card.querySelector('.jh09fzoq3e'); const deleteBtn = card.querySelector('.uf24p49jg0'); if (groupsBtn) { groupsBtn.addEventListener('click', (e) => { e.stopPropagation(); loadRecentGroupsOnly(item.id); }); } if (contentBtn) { contentBtn.addEventListener('click', (e) => { e.stopPropagation(); loadRecentContentOnly(item.id); }); } if (allBtn) { allBtn.addEventListener('click', (e) => { e.stopPropagation(); loadRecentPublishedPost(item.id); }); } if (deleteBtn) { deleteBtn.addEventListener('click', (e) => { e.stopPropagation(); deleteRecentPublishedPost(item.id); }); } container.appendChild(card); }); }; /** * تعبئة المنشور بالكامل مع المجموعات المحددة في المحرر */ const loadRecentPublishedPost = async (recentId) => { const recentList = await global.FritreeStorage.get('fbRecentPublishedPosts', []); const item = recentList.find(c => c.id === recentId); if (!item) return; if (confirm("هل تريد تحميل نص الرسالة والمجموعات المحددة والمرفقات إلى المحرر؟")) { setComposerText(item.text || ''); if (global.FritreeFacebook && typeof global.FritreeFacebook.setSelectedIds === 'function') { global.FritreeFacebook.setSelectedIds(item.groupIds || []); } uploadedImages = []; if (item.images && Array.isArray(item.images)) { for (const img of item.images) { const blob = await global.FritreeStorage.get(`media_blob_recent_${recentId}_${img.id}`); if (blob) { await global.FritreeStorage.set(`media_blob_${img.id}`, blob); const previewUrl = URL.createObjectURL(blob); uploadedImages.push({ id: img.id, type: img.type, blob: blob, filename: img.name, localPreviewUrl: previewUrl }); } } } renderComposerMediaPreviews(); if (typeof window.addLog === 'function') { window.addLog(`تم تحميل المنشور والجروبات المحددة [${item.groupIds.length}] بنجاح في المحرر للإرسال.`, 'success'); } window.scrollTo({ top: 0, behavior: 'smooth' }); } }; const loadRecentGroupsOnly = async (recentId) => { const recentList = await global.FritreeStorage.get('fbRecentPublishedPosts', []); const item = recentList.find(c => c.id === recentId); if (!item) return; if (global.FritreeFacebook && typeof global.FritreeFacebook.setSelectedIds === 'function') { global.FritreeFacebook.setSelectedIds(item.groupIds || []); if (typeof window.addLog === 'function') { window.addLog(`تم تحميل [${item.groupIds.length}] جروب من السجل بنجاح.`, "success"); } } }; const loadRecentContentOnly = async (recentId) => { const recentList = await global.FritreeStorage.get('fbRecentPublishedPosts', []); const item = recentList.find(c => c.id === recentId); if (!item) return; setComposerText(item.text || ''); uploadedImages = []; if (item.images && Array.isArray(item.images)) { for (const img of item.images) { const blob = await global.FritreeStorage.get(`media_blob_recent_${recentId}_${img.id}`); if (blob) { await global.FritreeStorage.set(`media_blob_${img.id}`, blob); const previewUrl = URL.createObjectURL(blob); uploadedImages.push({ id: img.id, type: img.type, blob: blob, filename: img.name, localPreviewUrl: previewUrl }); } } } renderComposerMediaPreviews(); if (typeof window.addLog === 'function') { window.addLog("تم تحميل محتوى نص المنشور والصور المرفقة في المحرر بنجاح.", "success"); } }; const deleteRecentPublishedPost = async (recentId) => { if (confirm("هل أنت متأكد من حذف هذا المنشور نهائياً من سجل التعبئة السريعة؟")) { let recentList = await global.FritreeStorage.get('fbRecentPublishedPosts', []); const item = recentList.find(c => c.id === recentId); if (item && item.images) { for (const img of item.images) { await global.FritreeStorage.remove(`media_blob_recent_${recentId}_${img.id}`); } } recentList = recentList.filter(c => c.id !== recentId); await global.FritreeStorage.set('fbRecentPublishedPosts', recentList); renderRecentPublishedList(); if (typeof window.addLog === 'function') { window.addLog("تم حذف المنشور وإزالته من سجل التعبئة السريعة بنجاح.", "warn"); } } }; /** * معالجة ورفع وضغط ملفات الصور */ const processIncomingMediaFiles = async (files) => { if (typeof window.addLog === 'function') { window.addLog("جاري معالجة وتأمين المرفقات لحمايتها أثناء الرفع السريع...", "info"); } for (let i = 0; i < files.length; i++) { const file = files[i]; if (file.size > 25 * 1024 * 1024) { alert(`حجم الملف ${file.name} كبير جداً، الحد الأقصى للمرفق هو 25 ميجابايت.`); continue; } if (!file.type.startsWith('image/')) continue; const binaryHash = 'composer_' + Date.now() + "_" + Math.random().toString(36).substr(2, 4); let compressedBlob = file; if (global.FritreeImageCompressor) { compressedBlob = await global.FritreeImageCompressor.compressImage(file); } const config = await global.FritreeStorage.get('local_shield_config_matrix', { exifCleansingActive: true }); if (config.exifCleansingActive && global.FritreeStealthLinguisticEngine && typeof global.FritreeStealthLinguisticEngine.cleanImageExif === 'function') { compressedBlob = await global.FritreeStealthLinguisticEngine.cleanImageExif(compressedBlob); } const thumbUrl = URL.createObjectURL(compressedBlob); if (global.FritreeStorage) { await global.FritreeStorage.set(`media_blob_${binaryHash}`, compressedBlob); } uploadedImages.push({ id: binaryHash, type: "image/jpeg", blob: compressedBlob, filename: file.name, localPreviewUrl: thumbUrl }); } renderComposerMediaPreviews(); }; const renderComposerMediaPreviews = () => { const container = document.getElementById('b2162at4z7'); if (!container) return; container.innerHTML = ''; uploadedImages.forEach((img, idx) => { const box = document.createElement('div'); box.className = 'evr435qzb2'; const el = document.createElement('img'); el.src = img.localPreviewUrl; el.style.cssText = 'width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm);'; const closeBtn = document.createElement('button'); closeBtn.setAttribute('type', 'button'); closeBtn.innerHTML = ' '; closeBtn.addEventListener('click', async () => { URL.revokeObjectURL(img.localPreviewUrl); if (global.FritreeStorage) { await global.FritreeStorage.remove(`media_blob_${img.id}`); } uploadedImages.splice(idx, 1); renderComposerMediaPreviews(); }); box.appendChild(el); box.appendChild(closeBtn); container.appendChild(box); }); }; /** * ربط أحداث المحرر والمتغيرات */ const bindComposerEventListeners = () => { const dropzone = document.getElementById('mm0yx6izkd'); const fileInput = document.getElementById('ftglpwfdd9'); const postTextarea = document.getElementById('nmr6mtwgan'); if (dropzone && fileInput) { dropzone.addEventListener('click', () => fileInput.click()); fileInput.addEventListener('change', (e) => { if (e.target.files.length > 0) { processIncomingMediaFiles(e.target.files); } }); dropzone.addEventListener('dragover', (e) => { e.preventDefault(); dropzone.style.borderColor = 'var(--primary)'; dropzone.style.background = 'var(--primary-light)'; }); dropzone.addEventListener('dragleave', () => { dropzone.style.borderColor = 'var(--border-strong)'; dropzone.style.background = 'var(--bg-subtle)'; }); dropzone.addEventListener('drop', (e) => { e.preventDefault(); dropzone.style.borderColor = 'var(--border-strong)'; dropzone.style.background = 'var(--bg-subtle)'; if (e.dataTransfer && e.dataTransfer.files.length > 0) { processIncomingMediaFiles(e.dataTransfer.files); } }); } if (postTextarea) { postTextarea.addEventListener('input', () => { if (global.FritreeRules && typeof global.FritreeRules.updateStats === 'function') { global.FritreeRules.updateStats(); } }); } const scheduleCheck = document.getElementById('k58hokq80h'); const scheduleWrapper = document.getElementById('sed4iycyc5'); const launchBtn = document.getElementById('q0ilg5gt03'); if (scheduleCheck && scheduleWrapper && launchBtn) { scheduleCheck.addEventListener('change', (e) => { const checked = e.target.checked; scheduleWrapper.style.display = checked ? 'block' : 'none'; if (checked) { launchBtn.innerHTML = ' جدولة تشغيل الحملة'; } else { launchBtn.innerHTML = ' بدء إطلاق الحملة'; } }); } const exitRotationBtn = document.getElementById('hf3fgtgsrm'); if (exitRotationBtn) { exitRotationBtn.addEventListener('click', (e) => { e.preventDefault(); if (global.FritreeRotation && typeof global.FritreeRotation.disableRotation === 'function') { global.FritreeRotation.disableRotation(); } }); } const pacingBtn = document.getElementById('d376lqov4g'); if (pacingBtn) { pacingBtn.addEventListener('click', (e) => { e.preventDefault(); if (global.FritreePacingUI && typeof global.FritreePacingUI.openModal === 'function') { global.FritreePacingUI.openModal('fb'); } }); } const btnStealth = document.getElementById('p4x864vzc8'); const previewBlock = document.getElementById('dg3a5v2fam'); const previewBox = document.getElementById('xtl6n8x46j'); if (btnStealth && previewBlock && previewBox) { btnStealth.addEventListener('click', async () => { const textVal = document.getElementById('nmr6mtwgan').value; if (!textVal) { alert("يرجى كتابة نص المنشور أولاً لمعاينة التمويه!"); return; } if (previewBlock.style.display === 'none') { if (global.FritreeTextCompiler && typeof global.FritreeTextCompiler.compileAndObfuscate === 'function') { const obfuscated = await global.FritreeTextCompiler.compileAndObfuscate(textVal, "مجموعة_المثال"); previewBox.textContent = obfuscated; previewBlock.style.display = 'block'; } } else { previewBlock.style.display = 'none'; } }); } document.querySelectorAll('.btn-var-insert').forEach(btn => { btn.addEventListener('click', (e) => { const varTag = e.currentTarget.getAttribute('data-var'); if (postTextarea) { const start = postTextarea.selectionStart; const end = postTextarea.selectionEnd; const text = postTextarea.value; postTextarea.value = text.substring(0, start) + varTag + text.substring(end); postTextarea.focus(); postTextarea.selectionStart = postTextarea.selectionEnd = start + varTag.length; postTextarea.dispatchEvent(new Event('input', { bubbles: true })); } }); }); }; /** * استخراج إعدادات التبريد والانتظار لفيسبوك من التخزين والمدخلات */ const getFacebookDelayConfig = () => { const getVal = id => document.getElementById(id)?.value; const mode = getVal('l37axh2l1n') || 'continuous'; const minSec = parseInt(getVal('fcdd19jd0b'), 10) || 45; const maxSec = parseInt(getVal('nypjlieshn'), 10) || 120; const fixedSec = parseInt(getVal('nmngttm14l'), 10) || 60; const burstCount = parseInt(getVal('er9a6wk592'), 10) || 5; const burstPause = parseInt(getVal('f85bxwyms9'), 10) || 300; const longBreakCount = parseInt(getVal('oifuahm7ox'), 10) || 15; const longBreakPause = parseInt(getVal('l1mxkqhsts'), 10) || 900; return { mode, minSeconds: minSec, maxSeconds: maxSec, fixedSeconds: fixedSec, burstCount, burstPause, longBreakCount, longBreakPause }; }; /** * تهيئة المحرر */ const initComposer = () => { const sidebar = document.getElementById('bmh59axx92'); const mainContentArea = document.getElementById('s7ihkirolg'); if (!sidebar || !mainContentArea) return false; buildComposerLayout(); bindComposerEventListeners(); renderComposerMediaPreviews(); return true; }; /** * تصدير وحدة محرر فيسبوك */ global.FritreeFacebookComposer = { init: initComposer, getUploadedImages: () => { return Promise.resolve(uploadedImages.map(img => ({ id: img.id, name: img.filename, type: img.type }))); }, clearComposerImages: async () => { for (const img of uploadedImages) { URL.revokeObjectURL(img.localPreviewUrl); if (global.FritreeStorage) { await global.FritreeStorage.remove(`media_blob_${img.id}`); } } uploadedImages = []; renderComposerMediaPreviews(); }, getComposerText: () => { const el = document.getElementById('nmr6mtwgan'); return el ? el.value : ''; }, setComposerText, savePublishedPostToRecent, getDelayConfig: getFacebookDelayConfig }; if (typeof document !== 'undefined') { if (!initComposer()) { document.addEventListener('DOMContentLoaded', initComposer); window.addEventListener('load', initComposer); } } })(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);