-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
47 lines (38 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const {
getBrowser,
startChrome,
pageWithDefaultProfile
} = require('./lib/chrome');
const {observeAddedNodes} = require('./lib/observe-added-nodes');
const {scrollWhileChanging} = require('./lib/scroll');
const GROUPS_URL = 'https://www.facebook.com/groups';
(async () => {
const [,,path] = process.argv;
const chrome = await startChrome();
const browser = await getBrowser(chrome);
const page = await pageWithDefaultProfile(browser);
page.setViewport({ width: 1280, height: 926 });
await page.goto(`${GROUPS_URL}/${path}/`);
await page.evaluate(() => {
window.onNodeAdded = node => {
if (node.id && node.id.startsWith('mall_post_')) {
const permalinkId = node.id.replace(/:.*/, '')
.replace('mall_post_', '');
const timestamp = node.querySelector('abbr').dataset.utime;
console.log(`permalink/${permalinkId}, ${timestamp}`);
}
}
})
await observeAddedNodes(page, '[aria-label="News Feed"]');
const detectChanges = (onChange) =>
page.on('console', async (msg) => {
if (msg._text && msg._text.startsWith('permalink')) {
const [permalink, timestamp] = msg._text.split(',');
const date = new Date(timestamp * 1000).toISOString();
console.log(`${date}, ${GROUPS_URL}/${path}/${permalink}`);
onChange();
}
});
await scrollWhileChanging(page, 10, detectChanges)
await browser.close();
})();