events.js
1 import { cli } from '@jackwener/opencli/registry'; 2 cli({ 3 site: 'facebook', 4 name: 'events', 5 description: 'Browse Facebook event categories', 6 domain: 'www.facebook.com', 7 args: [ 8 { name: 'limit', type: 'int', default: 15, help: 'Number of categories' }, 9 ], 10 columns: ['index', 'name'], 11 pipeline: [ 12 { navigate: { url: 'https://www.facebook.com/events', settleMs: 3000 } }, 13 { evaluate: `(() => { 14 const limit = \${{ args.limit }}; 15 // Try actual event items first 16 const articles = document.querySelectorAll('[role="article"]'); 17 if (articles.length > 0) { 18 return Array.from(articles).slice(0, limit).map((el, i) => ({ 19 index: i + 1, 20 name: el.textContent.trim().replace(/\\s+/g, ' ').substring(0, 120), 21 })); 22 } 23 24 // List event categories from sidebar navigation 25 const links = Array.from(document.querySelectorAll('[role="navigation"] a')) 26 .filter(a => { 27 const href = a.href || ''; 28 const text = a.textContent.trim(); 29 return href.includes('/events/') && text.length > 1 && text.length < 60 && 30 !href.includes('create'); 31 }); 32 33 return links.slice(0, limit).map((a, i) => ({ 34 index: i + 1, 35 name: a.textContent.trim(), 36 })); 37 })() 38 ` }, 39 ], 40 });