-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (59 loc) · 1.98 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import puppeteer from 'puppeteer';
import { sleep } from 'bun';
let loop = true;
process.on("SIGINT", async () => {
console.log("Received SIGINT");
loop = false;
});
(async () => {
const browser = await puppeteer.launch({
// For the initial login, set `headless` to `false`, do the login, and then
// set `headless` back to "new" once the `user_dir` has been copied to the
// server.
// headless: false,
headless: "new",
executablePath: "chromium",
userDataDir: "./user_data",
});
const page = await browser.newPage();
await page.setViewport({
width: 1920,
height: 1080,
});
await page.goto("https://zupass.org/#/?folder=FrogCrypto");
const getButtons = async () => await page?.$x("//button[contains(., 'search')]")
const getElText = async element => await element?.evaluate(el => el.textContent);
const getText = async () => {
let text = [];
for (const button of await getButtons()) {
text.push(await getElText(button));
}
return text;
};
const logText = async text => console.log("[" + (new Date().toISOString()) + "] " + text);
logText(await getText());
const intervalID = setInterval(async () => logText(await getText()), 60_000);
await saveFrogs(page);
while (loop) {
const buttons = await getButtons();
for (const button of buttons) {
if (!await button?.evaluate(el => el.disabled)) {
// There is a very simple "anti-automation" check where if the button
// is not in the viewport, it will not do anything on click.
// This seems to fix it.
await button.scrollIntoView();
await button.click();
logText("Clicked " + await getElText(button));
}
}
await sleep(1000);
}
clearInterval(intervalID);
await saveFrogs(page);
await browser.close();
})();
async function saveFrogs(page) {
const localStorageData = await page.evaluate(() =>
localStorage.getItem("pcd_collection"));
await Bun.write("localStorage", localStorageData)
}