-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathindex.js
More file actions
126 lines (121 loc) · 6.09 KB
/
index.js
File metadata and controls
126 lines (121 loc) · 6.09 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const puppeteer = require('puppeteer');
const { CronJob } = require('cron');
const readlineSync = require('readline-sync');
require('colors');
function checkWebsite(address, callback) {
puppeteer
.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
})
.then((browser) => {
browser.newPage().then((page) => {
page.goto('https://artio.faucet.berachain.com/').then(() => {
const termsCheckboxSelector = '#terms';
page.waitForSelector(termsCheckboxSelector).then(() => {
page.click(termsCheckboxSelector).then(() => {
const agreeButtonSelector =
'//button[contains(text(), "I AGREE")]';
page.waitForXPath(agreeButtonSelector).then(() => {
page.$x(agreeButtonSelector).then((agreeButtons) => {
if (agreeButtons.length > 0) {
agreeButtons[0].click().then(() => {
const addressInputSelector =
'body > div:nth-child(12) > div.relative.flex.min-h-screen.w-full.flex-col.overflow-hidden.bg-background > main > div > div.flex.w-full.flex-col-reverse.items-center.justify-between.py-12.xl\\:flex-row > div > div.flex.flex-col.gap-1 > div.relative > div > input';
page.waitForSelector(addressInputSelector).then(() => {
page.type(addressInputSelector, address).then(() => {
const buttonSelector =
'body > div:nth-child(12) > div.relative.flex.min-h-screen.w-full.flex-col.overflow-hidden.bg-background > main > div > div.flex.w-full.flex-col-reverse.items-center.justify-between.py-12.xl\\:flex-row > div > button';
page.waitForSelector(buttonSelector).then(() => {
page.click(buttonSelector).then(() => {
page.waitForTimeout(3000).then(() => {
page.click(buttonSelector).then(() => {
page
.waitForSelector('div[role="alert"]', {
timeout: 5000,
})
.then(() => {
page
.$(
'div[role="alert"].border-destructive-foreground'
)
.then((errorElement) => {
if (errorElement) {
page
.evaluate(
(el) => el.textContent,
errorElement
)
.then((errorMessage) => {
console.log(
'Error: '.red +
errorMessage.red
);
browser.close();
callback('error');
});
} else {
page
.$(
'div[role="alert"].border-success-foreground'
)
.then((successElement) => {
if (successElement) {
page
.evaluate(
(el) => el.textContent,
successElement
)
.then((successMessage) => {
console.log(
'Success: '.green +
successMessage.green
);
browser.close();
callback('success');
});
} else {
browser.close();
callback('none');
}
});
}
})
.catch(() => {
browser.close();
callback('none');
});
});
});
});
});
});
});
});
});
}
});
});
});
});
});
});
});
}
function scheduleCronJob(address) {
const job = new CronJob('0 */8 * * *', () => {
console.log('Running cron job'.yellow);
checkWebsite(address, (status) => {
console.log('Status:'.yellow, status.yellow);
});
});
job.start();
console.log('Cron job scheduled'.blue);
}
const address = readlineSync.question('Enter the wallet address: '.cyan);
checkWebsite(address, (status) => {
console.log('Initial status:'.cyan, status.cyan);
if (status !== 'none') {
scheduleCronJob(address);
}
});