Skip to content

Commit 8182b30

Browse files
committed
fix: Compatible with the new UI
1 parent 17c2434 commit 8182b30

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,6 @@ cython_debug/
165165
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166166
# and can be added to the global gitignore or merged into this file. For a more nuclear
167167
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168-
#.idea/
168+
#.idea/
169+
170+
accounts.json

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<strong>中文</strong> | <a href="README.md">English</a>
33
</div>
44

5-
<img src="https://www.serv00.com/static/ct8/img/logo.jpg" alt="serv00 logo" width="50" height="50" align="right" />
5+
<img src="https://www.serv00.com/wp-content/themes/serv00/public/svg/logo.svg" alt="serv00 logo" width="50" height="50" align="right" />
66

77
<div align="center">
88

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"author": "",
1616
"license": "ISC",
1717
"dependencies": {
18-
"axios": "^1.7.7",
19-
"puppeteer": "^23.7.0"
18+
"axios": "^1.13.2",
19+
"puppeteer": "^24.33.0"
2020
}
2121
}

src/main.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,8 @@ async function sendTelegramMessage(token, chatId, message) {
2020
};
2121
try {
2222
const response = await axios.post(url, data);
23-
// console.log('消息已发送到 Telegram:', response.data);
2423
console.log('消息已发送到 Telegram');
2524
} catch (error) {
26-
// if (error.response) {
27-
// console.error('发送 Telegram 消息时出错:', error.response.status, error.response.data);
28-
// } else if (error.request) {
29-
// console.error('发送 Telegram 消息时出错:', error.request);
30-
// } else {
31-
// console.error('发送 Telegram 消息时出错:', error.message);
32-
// }
3325
console.error('Telegram 消息发生失败');
3426
}
3527
}
@@ -43,7 +35,6 @@ async function sendTelegramMessage(token, chatId, message) {
4335
for (const account of accounts) {
4436
const { username, password, panel } = account;
4537

46-
// 显示浏览器窗口&使用自定义窗口大小
4738
const browser = await puppeteer.launch({
4839
headless: false,
4940
args: [
@@ -57,31 +48,24 @@ async function sendTelegramMessage(token, chatId, message) {
5748
ignoreHTTPSErrors: true
5849
});
5950
const page = await browser.newPage();
60-
// await page.setViewport({ width: 1366, height: 768 });
61-
// await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36');
62-
// await page.evaluateOnNewDocument(() => {
63-
// delete Object.getPrototypeOf(navigator).webdriver;
64-
// });
6551

6652
let url = `https://${panel}/login/?next=/`;
6753

6854
try {
6955
await page.goto(url);
7056

71-
const usernameInput = await page.$('#id_username');
57+
const usernameInput = await page.$('input[name="username"]');
7258
if (usernameInput) {
7359
await usernameInput.click({ clickCount: 3 });
7460
await usernameInput.press('Backspace');
7561
}
76-
await page.type('#id_username', username);
77-
await page.type('#id_password', password);
62+
await page.type('input[name="username"]', username);
63+
await page.type('input[name="password"]', password);
7864

79-
const loginButton = await page.$('#submit');
80-
if (loginButton) {
81-
await loginButton.click();
82-
} else {
83-
throw new Error('无法找到登录按钮');
84-
}
65+
const loginButton = await page.$('div.login-form__button button[type="submit"]');
66+
67+
if (!loginButton) throw new Error('无法找到登录按钮');
68+
await loginButton.click();
8569

8670
await page.waitForNavigation();
8771

@@ -109,16 +93,11 @@ async function sendTelegramMessage(token, chatId, message) {
10993
await sendTelegramMessage(telegramToken, telegramChatId, `账号 ${username} 登录时出现错误: ${error.message}`);
11094
}
11195
} finally {
112-
// 模拟人类行为
113-
// await page.waitForTimeout(1000 + Math.floor(Math.random() * 2000));
114-
// await page.type('#id_username', 'testuser', { delay: 100 + Math.floor(Math.random() * 100) });
115-
// await page.click('#submit');
116-
// await page.waitForNavigation();
11796
await page.close();
11897
await browser.close();
11998
const delay = Math.floor(Math.random() * 5000) + 1000; // 随机延时1秒到5秒之间
12099
await delayTime(delay);
121100
}
122101
}
123102
console.log('所有账号登录完成!');
124-
})();
103+
})();

0 commit comments

Comments
 (0)