groups.js
1 import { cli } from '@jackwener/opencli/registry'; 2 cli({ 3 site: 'facebook', 4 name: 'groups', 5 description: 'List your Facebook groups', 6 domain: 'www.facebook.com', 7 args: [ 8 { name: 'limit', type: 'int', default: 20, help: 'Number of groups' }, 9 ], 10 columns: ['index', 'name', 'last_post', 'url'], 11 pipeline: [ 12 { navigate: { url: 'https://www.facebook.com/groups/feed/', settleMs: 3000 } }, 13 { evaluate: `(() => { 14 const limit = \${{ args.limit }}; 15 const links = Array.from(document.querySelectorAll('a')) 16 .filter(a => { 17 const href = a.href || ''; 18 return href.includes('/groups/') && 19 !href.includes('/feed') && 20 !href.includes('/discover') && 21 !href.includes('/joins') && 22 !href.includes('category=create') && 23 a.textContent.trim().length > 2; 24 }); 25 26 // Deduplicate by href 27 const seen = new Set(); 28 const groups = []; 29 for (const a of links) { 30 const href = a.href.split('?')[0]; 31 if (seen.has(href)) continue; 32 seen.add(href); 33 const raw = a.textContent.trim().replace(/\\s+/g, ' '); 34 // Split name from "上次发帖" info 35 const parts = raw.split(/上次发帖|Last post/); 36 groups.push({ 37 name: (parts[0] || '').trim().substring(0, 60), 38 last_post: parts[1] ? parts[1].replace(/^[::]/, '').trim() : '-', 39 url: href, 40 }); 41 } 42 return groups.slice(0, limit).map((g, i) => ({ index: i + 1, ...g })); 43 })() 44 ` }, 45 ], 46 });