/ clis / facebook / memories.js
memories.js
 1  import { cli } from '@jackwener/opencli/registry';
 2  cli({
 3      site: 'facebook',
 4      name: 'memories',
 5      description: 'Get your Facebook memories (On This Day)',
 6      domain: 'www.facebook.com',
 7      args: [
 8          { name: 'limit', type: 'int', default: 10, help: 'Number of memories' },
 9      ],
10      columns: ['index', 'source', 'content', 'time'],
11      pipeline: [
12          { navigate: { url: 'https://www.facebook.com/onthisday', settleMs: 4000 } },
13          { evaluate: `(() => {
14    const limit = \${{ args.limit }};
15    const articles = document.querySelectorAll('[role="article"]');
16    return Array.from(articles)
17      .slice(0, limit)
18      .map((el, i) => {
19        const headerLink = el.querySelector('h2 a, h3 a, h4 a, strong a');
20        const spans = Array.from(el.querySelectorAll('div[dir="auto"]'))
21          .map(s => s.textContent.trim())
22          .filter(t => t.length > 5 && t.length < 500);
23        const timeEl = el.querySelector('a[href*="/posts/"] span, a[href*="story_fbid"] span');
24        return {
25          index: i + 1,
26          source: headerLink ? headerLink.textContent.trim().substring(0, 50) : '-',
27          content: (spans[0] || '').replace(/\\n/g, ' ').substring(0, 150),
28          time: timeEl ? timeEl.textContent.trim() : '-',
29        };
30      })
31      .filter(item => item.content.length > 0 || item.source !== '-');
32  })()
33  ` },
34      ],
35  });