forked from jonellcc/botpack-fixed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.jsh
149 lines (126 loc) · 4.67 KB
/
monitor.jsh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const fs = require('fs');
const path = require('path');
const freeport = require('freeport');
const ProxyChain = require('proxy-chain');
const puppeteer = require('puppeteer-extra');
const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha');
const { exec } = require('node:child_process');
const { promisify } = require('node:util');
const { CookieJar } = require('tough-cookie');
const { FileCookieStore } = require('tough-cookie-file-store');
const screenshotPath = path.join(__dirname, 'screenshot.jpg');
const cookiesPath = path.join(__dirname, 'cookies.txt');
const email = "[email protected]";
const password = "jonell10";
const CAPTCHA_API_KEY = "9ef8ccb1a940127ba54e5c9111656506";
puppeteer.use(
RecaptchaPlugin({
provider: {
id: '2captcha',
token: CAPTCHA_API_KEY,
},
visualFeedback: true,
})
);
const userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1";
const mobileViewport = {
width: 375,
height: 812,
isMobile: true,
hasTouch: true,
isLandscape: false,
};
let browser, page;
async function saveCookiesToFile(cookies, filePath) {
const cookieJar = new CookieJar(new FileCookieStore(filePath));
await cookieJar.setCookie(cookies);
}
async function initializeBrowser(proxyPort) {
try {
const { stdout: chromiumPath } = await promisify(exec)("which chromium");
browser = await puppeteer.launch({
headless: false,
executablePath: chromiumPath.trim(),
ignoreHTTPSErrors: true,
args: [
'--ignore-certificate-errors',
'--disable-gpu',
'--disable-software-rasterizer',
'--disable-dev-shm-usage',
'--no-sandbox',
`--proxy-server=127.0.0.1:${proxyPort}`
]
});
browser.on('disconnected', async () => {
await initializeBrowser(proxyPort);
});
page = await browser.newPage();
await page.setUserAgent(userAgent);
await page.setViewport(mobileViewport);
} catch (error) {
process.exit(1);
}
}
async function run() {
try {
freeport(async (err, proxyPort) => {
if (err) {
return;
}
const proxyServer = new ProxyChain.Server({ port: proxyPort });
proxyServer.listen(async (proxyServerErr) => {
if (proxyServerErr) {
return;
}
await initializeBrowser(proxyPort);
if (fs.existsSync(cookiesPath)) {
const cookies = fs.readFileSync(cookiesPath, 'utf8');
const cookiesParsed = JSON.parse(cookies);
await page.setCookie(...cookiesParsed);
} else {
try {
await page.goto('https://replit.com/login', { waitUntil: 'networkidle2' });
await page.type('input[name="username"]', email);
await page.type('input[name="password"]', password);
await page.click('button[data-cy="log-in-btn"]');
await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 });
if (page.url() === 'https://replit.com/~') {
const cookies = await page.cookies();
fs.writeFileSync(cookiesPath, JSON.stringify(cookies, null, 2));
} else {
throw new Error('Failed to log in or redirected to an unexpected page.');
}
} catch (e) {
const { captchas, solved, error } = await page.solveRecaptchas();
if (solved.length > 0) {
await page.click('button[data-cy="log-in-btn"]');
await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 });
if (page.url() === 'https://replit.com/~') {
const cookies = await page.cookies();
fs.writeFileSync(cookiesPath, JSON.stringify(cookies, null, 2));
}
}
}
}
const currentUrl = "https://replit.com/@Jonellmagallanes10/datr-getter#index.js";
await page.goto(currentUrl, { waitUntil: 'networkidle2' });
const newPage = await browser.newPage();
await newPage.goto('https://replit.com/@Jonellmagallanes10/Bot-Botpack-With-Hanabishi-Washing-Machine#index.js', { waitUntil: 'networkidle2' });
async function switchTabs() {
let currentIndex = 0;
const pages = await browser.pages();
setInterval(async () => {
currentIndex = (currentIndex + 1) % 2; // Toggle between the first two tabs only
await pages[currentIndex].bringToFront();
}, 5000);
}
switchTabs();
await page.screenshot({ path: screenshotPath, type: 'jpeg' });
});
});
} catch (err) {
}
}
process.on('unhandledRejection', (reason, promise) => {
});
run();