-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.ts
44 lines (39 loc) 路 1000 Bytes
/
index.ts
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
import puppeteer from 'puppeteer-extra';
import stealthPlugin from 'puppeteer-extra-plugin-stealth';
import {Config} from './config';
import {Stores} from './store/model';
import {Logger} from './logger';
import {tryLookupAndLoop} from './store';
import {getSleepTime} from './util';
import {adBlocker} from './adblocker';
puppeteer.use(stealthPlugin());
puppeteer.use(adBlocker);
/**
* Starts the bot.
*/
async function main() {
const browser = await puppeteer.launch({
headless: Config.browser.isHeadless,
defaultViewport: {
height: Config.page.height,
width: Config.page.width
}
});
for (const store of Stores) {
Logger.debug(store.links);
if (store.setupAction !== undefined) {
store.setupAction(browser);
}
setTimeout(tryLookupAndLoop, getSleepTime(), browser, store);
}
}
/**
* Will continually run until user interferes.
*/
try {
void main();
} catch (error) {
// Ignoring errors; more than likely due to rate limits
Logger.error(error);
void main();
}