Facebook Auto Group Poster

نشر تلقائي في جميع مجموعات الفيسبوك

Size

14.3 KB

Version

1.0.1

Created

Mar 8, 2026

Updated

14 days ago

1// ==UserScript==
2// @name		Facebook Auto Group Poster
3// @description		نشر تلقائي في جميع مجموعات الفيسبوك
4// @version		1.0.1
5// @match		https://*.facebook.com/*
6// @match		https://*.fb.com/*
7// @icon		https://robomonkey.io/favicon.ico
8// ==/UserScript==
9(function() {
10    'use strict';
11
12    console.log('Facebook Auto Group Poster - Extension Started');
13
14    // إضافة أنماط CSS للواجهة
15    TM_addStyle(`
16        #fb-auto-poster-panel {
17            position: fixed;
18            top: 20px;
19            right: 20px;
20            width: 350px;
21            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
22            border-radius: 15px;
23            padding: 20px;
24            box-shadow: 0 10px 40px rgba(0,0,0,0.3);
25            z-index: 999999;
26            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
27            color: white;
28        }
29        
30        #fb-auto-poster-panel h3 {
31            margin: 0 0 15px 0;
32            font-size: 20px;
33            font-weight: bold;
34            text-align: center;
35            color: white;
36        }
37        
38        #fb-auto-poster-panel textarea {
39            width: 100%;
40            min-height: 120px;
41            padding: 12px;
42            border: none;
43            border-radius: 8px;
44            font-size: 14px;
45            resize: vertical;
46            box-sizing: border-box;
47            font-family: inherit;
48            background: white;
49            color: #333;
50        }
51        
52        #fb-auto-poster-panel button {
53            width: 100%;
54            padding: 12px;
55            margin-top: 10px;
56            border: none;
57            border-radius: 8px;
58            font-size: 16px;
59            font-weight: bold;
60            cursor: pointer;
61            transition: all 0.3s ease;
62            color: white;
63        }
64        
65        #fb-start-posting {
66            background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
67        }
68        
69        #fb-start-posting:hover {
70            transform: translateY(-2px);
71            box-shadow: 0 5px 20px rgba(56, 239, 125, 0.4);
72        }
73        
74        #fb-start-posting:disabled {
75            background: #ccc;
76            cursor: not-allowed;
77            transform: none;
78        }
79        
80        #fb-stop-posting {
81            background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
82            display: none;
83        }
84        
85        #fb-stop-posting:hover {
86            transform: translateY(-2px);
87            box-shadow: 0 5px 20px rgba(235, 51, 73, 0.4);
88        }
89        
90        #fb-close-panel {
91            background: rgba(255, 255, 255, 0.2);
92            margin-top: 5px;
93        }
94        
95        #fb-close-panel:hover {
96            background: rgba(255, 255, 255, 0.3);
97        }
98        
99        .fb-status {
100            margin-top: 15px;
101            padding: 12px;
102            background: rgba(255, 255, 255, 0.2);
103            border-radius: 8px;
104            font-size: 14px;
105            text-align: center;
106            backdrop-filter: blur(10px);
107        }
108        
109        .fb-progress {
110            margin-top: 10px;
111            font-weight: bold;
112            font-size: 16px;
113        }
114        
115        #fb-open-panel-btn {
116            position: fixed;
117            bottom: 30px;
118            right: 30px;
119            width: 60px;
120            height: 60px;
121            border-radius: 50%;
122            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
123            border: none;
124            color: white;
125            font-size: 24px;
126            cursor: pointer;
127            box-shadow: 0 5px 25px rgba(102, 126, 234, 0.5);
128            z-index: 999998;
129            transition: all 0.3s ease;
130            display: flex;
131            align-items: center;
132            justify-content: center;
133        }
134        
135        #fb-open-panel-btn:hover {
136            transform: scale(1.1);
137            box-shadow: 0 8px 30px rgba(102, 126, 234, 0.7);
138        }
139    `);
140
141    let isPosting = false;
142    let shouldStop = false;
143
144    // إنشاء واجهة المستخدم
145    function createUI() {
146        // زر فتح اللوحة
147        const openBtn = document.createElement('button');
148        openBtn.id = 'fb-open-panel-btn';
149        openBtn.innerHTML = '📝';
150        openBtn.title = 'فتح لوحة النشر التلقائي';
151        document.body.appendChild(openBtn);
152
153        // لوحة التحكم
154        const panel = document.createElement('div');
155        panel.id = 'fb-auto-poster-panel';
156        panel.style.display = 'none';
157        panel.innerHTML = `
158            <h3>📢 النشر التلقائي في المجموعات</h3>
159            <textarea id="fb-post-content" placeholder="اكتب المنشور هنا..."></textarea>
160            <button id="fb-start-posting">🚀 ابدأ النشر</button>
161            <button id="fb-stop-posting">⏹️ إيقاف النشر</button>
162            <button id="fb-close-panel">✖️ إغلاق</button>
163            <div class="fb-status" id="fb-status">جاهز للنشر</div>
164        `;
165        document.body.appendChild(panel);
166
167        // ربط الأحداث
168        openBtn.addEventListener('click', () => {
169            panel.style.display = 'block';
170            openBtn.style.display = 'none';
171        });
172
173        document.getElementById('fb-close-panel').addEventListener('click', () => {
174            panel.style.display = 'none';
175            openBtn.style.display = 'flex';
176        });
177
178        document.getElementById('fb-start-posting').addEventListener('click', startPosting);
179        document.getElementById('fb-stop-posting').addEventListener('click', stopPosting);
180    }
181
182    // الحصول على جميع المجموعات
183    async function getAllGroups() {
184        console.log('جاري البحث عن المجموعات...');
185        
186        // الانتقال إلى صفحة المجموعات
187        if (!window.location.href.includes('/groups/feeds')) {
188            updateStatus('جاري الانتقال إلى صفحة المجموعات...');
189            window.location.href = 'https://www.facebook.com/groups/feeds/';
190            return null;
191        }
192
193        // الانتظار لتحميل الصفحة
194        await sleep(3000);
195
196        // التمرير لتحميل المزيد من المجموعات
197        updateStatus('جاري تحميل قائمة المجموعات...');
198        for (let i = 0; i < 3; i++) {
199            window.scrollTo(0, document.body.scrollHeight);
200            await sleep(2000);
201        }
202
203        // البحث عن روابط المجموعات
204        const groupLinks = [];
205        const links = document.querySelectorAll('a[href*="/groups/"]');
206        
207        links.forEach(link => {
208            const href = link.href;
209            const match = href.match(/facebook\.com\/groups\/([^\/\?]+)/);
210            if (match && match[1] && !groupLinks.includes(match[1])) {
211                // تجاهل الروابط العامة
212                if (!match[1].includes('feeds') && !match[1].includes('discover')) {
213                    groupLinks.push(match[1]);
214                }
215            }
216        });
217
218        console.log(`تم العثور على ${groupLinks.length} مجموعة`);
219        return groupLinks;
220    }
221
222    // النشر في مجموعة واحدة
223    async function postToGroup(groupId, content) {
224        try {
225            console.log(`جاري النشر في المجموعة: ${groupId}`);
226            
227            // الانتقال إلى صفحة المجموعة
228            window.location.href = `https://www.facebook.com/groups/${groupId}`;
229            await sleep(5000);
230
231            // البحث عن مربع النص للنشر
232            const postBoxSelectors = [
233                'div[role="textbox"][contenteditable="true"]',
234                'div[aria-label*="منشور"]',
235                'div[aria-label*="post"]',
236                'div.notranslate[contenteditable="true"]'
237            ];
238
239            let postBox = null;
240            for (const selector of postBoxSelectors) {
241                postBox = document.querySelector(selector);
242                if (postBox) break;
243            }
244
245            if (!postBox) {
246                console.error('لم يتم العثور على مربع النشر');
247                return false;
248            }
249
250            // النقر على مربع النشر
251            postBox.click();
252            await sleep(2000);
253
254            // كتابة المحتوى
255            postBox.focus();
256            document.execCommand('insertText', false, content);
257            await sleep(2000);
258
259            // البحث عن زر النشر
260            const postButtonSelectors = [
261                'div[aria-label="نشر"][role="button"]',
262                'div[aria-label="Post"][role="button"]',
263                'span:contains("نشر")',
264                'span:contains("Post")'
265            ];
266
267            let postButton = null;
268            for (const selector of postButtonSelectors) {
269                const buttons = document.querySelectorAll('div[role="button"]');
270                for (const btn of buttons) {
271                    const text = btn.textContent.trim();
272                    if (text === 'نشر' || text === 'Post') {
273                        postButton = btn;
274                        break;
275                    }
276                }
277                if (postButton) break;
278            }
279
280            if (postButton) {
281                postButton.click();
282                await sleep(3000);
283                console.log('تم النشر بنجاح');
284                return true;
285            } else {
286                console.error('لم يتم العثور على زر النشر');
287                return false;
288            }
289
290        } catch (error) {
291            console.error('خطأ في النشر:', error);
292            return false;
293        }
294    }
295
296    // بدء عملية النشر
297    async function startPosting() {
298        const content = document.getElementById('fb-post-content').value.trim();
299        
300        if (!content) {
301            alert('الرجاء كتابة محتوى المنشور');
302            return;
303        }
304
305        isPosting = true;
306        shouldStop = false;
307        
308        document.getElementById('fb-start-posting').disabled = true;
309        document.getElementById('fb-start-posting').style.display = 'none';
310        document.getElementById('fb-stop-posting').style.display = 'block';
311
312        // حفظ المحتوى
313        await GM.setValue('fb_post_content', content);
314        await GM.setValue('fb_is_posting', true);
315        await GM.setValue('fb_current_index', 0);
316
317        // الحصول على المجموعات
318        let groups = await GM.getValue('fb_groups_list');
319        
320        if (!groups) {
321            const groupsList = await getAllGroups();
322            if (!groupsList) {
323                return; // سيتم إعادة التوجيه
324            }
325            await GM.setValue('fb_groups_list', JSON.stringify(groupsList));
326            groups = JSON.stringify(groupsList);
327        }
328
329        const groupsArray = JSON.parse(groups);
330        const currentIndex = await GM.getValue('fb_current_index', 0);
331
332        updateStatus(`جاري النشر في ${groupsArray.length} مجموعة...`);
333
334        // النشر في كل مجموعة
335        for (let i = currentIndex; i < groupsArray.length; i++) {
336            if (shouldStop) {
337                await GM.setValue('fb_current_index', i);
338                break;
339            }
340
341            updateStatus(`النشر في المجموعة ${i + 1} من ${groupsArray.length}`, i + 1, groupsArray.length);
342            
343            const success = await postToGroup(groupsArray[i], content);
344            
345            if (success) {
346                await GM.setValue('fb_current_index', i + 1);
347            }
348
349            // انتظار بين المنشورات
350            await sleep(10000);
351        }
352
353        // إنهاء العملية
354        await GM.deleteValue('fb_is_posting');
355        await GM.deleteValue('fb_groups_list');
356        await GM.deleteValue('fb_current_index');
357        
358        updateStatus('✅ تم الانتهاء من النشر في جميع المجموعات!');
359        resetUI();
360    }
361
362    // إيقاف النشر
363    async function stopPosting() {
364        shouldStop = true;
365        await GM.setValue('fb_is_posting', false);
366        updateStatus('⏸️ تم إيقاف النشر');
367        resetUI();
368    }
369
370    // تحديث حالة النشر
371    function updateStatus(message, current = 0, total = 0) {
372        const statusDiv = document.getElementById('fb-status');
373        if (statusDiv) {
374            let html = message;
375            if (current > 0 && total > 0) {
376                const percentage = Math.round((current / total) * 100);
377                html += `<div class="fb-progress">${percentage}% (${current}/${total})</div>`;
378            }
379            statusDiv.innerHTML = html;
380        }
381    }
382
383    // إعادة تعيين الواجهة
384    function resetUI() {
385        isPosting = false;
386        document.getElementById('fb-start-posting').disabled = false;
387        document.getElementById('fb-start-posting').style.display = 'block';
388        document.getElementById('fb-stop-posting').style.display = 'none';
389    }
390
391    // دالة الانتظار
392    function sleep(ms) {
393        return new Promise(resolve => setTimeout(resolve, ms));
394    }
395
396    // التحقق من استمرار النشر بعد إعادة التحميل
397    async function checkContinuePosting() {
398        const isPostingStored = await GM.getValue('fb_is_posting', false);
399        if (isPostingStored) {
400            const content = await GM.getValue('fb_post_content', '');
401            if (content) {
402                document.getElementById('fb-post-content').value = content;
403                setTimeout(() => {
404                    startPosting();
405                }, 2000);
406            }
407        }
408    }
409
410    // تهيئة الإضافة
411    function init() {
412        console.log('تهيئة إضافة النشر التلقائي...');
413        
414        // الانتظار حتى يتم تحميل الصفحة
415        if (document.readyState === 'loading') {
416            document.addEventListener('DOMContentLoaded', () => {
417                createUI();
418                checkContinuePosting();
419            });
420        } else {
421            createUI();
422            checkContinuePosting();
423        }
424    }
425
426    // بدء التشغيل
427    init();
428
429})();