Skip to content

Commit

Permalink
0.4:修改註解,調整登入邏輯
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Smilin committed Apr 16, 2024
1 parent 91e387f commit f736190
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ async function login(page, username, password) {
await page.waitForSelector('button[type="submit"]');
await page.click('button[type="submit"]');
await delay(3000);
try {
await page.$eval('button[type="submit"]', (button) => button.click());
} catch {}
}

//#endregion
Expand All @@ -95,12 +98,12 @@ async function checkPopup(page) {
//#endregion

//#region 點擊頁首圖標
async function selectProfileButton(driver) {
async function selectProfileButton(page) {
while (true) {
try {
// 確認是否已登入
console.log("確認是否已登入");
const headerText = await driver.$eval(
const headerText = await page.$eval(
"header > div:nth-of-type(2)",
(el) => el.innerText
);
Expand All @@ -113,33 +116,33 @@ async function selectProfileButton(driver) {
}
} catch {
await delay(300);
const isPopupClosed = await checkPopup(driver);
const isPopupClosed = await checkPopup(page);
try {
// 檢查個人資料頭像並點擊
console.log("點擊圖片頭像");
await driver.$eval("header > img", (el) => el.click());
await page.$eval("header > img", (el) => el.click());
console.log("成功");
await delay(300);
break;
} catch {
try {
// 如果沒有頭像的話會是div
console.log("點擊文字頭像");
await driver.$eval("header > div", (el) => el.click());
await page.$eval("header > div", (el) => el.click());
console.log("成功");
await delay(300);
break;
} catch (err) {
try {
// 檢查密碼錯誤
await driver.$eval(
await page.$eval(
'svg[data-testid="ReportProblemOutlinedIcon"]',
(el) => el
);
throw new Error(username, "登入失敗!");
} catch {
if (!isPopupClosed) {
await checkPopup(driver);
await checkPopup(page);
}
}
}
Expand Down Expand Up @@ -207,6 +210,8 @@ async function claimCredit(page) {
(el) => el.innerText
);

await delay(300);

// 確認是不是 "Claimed"
if (updatedClaimBtnText.toLowerCase() === "claimed") {
console.log("領取成功");
Expand Down Expand Up @@ -242,5 +247,5 @@ async function claimCredit(page) {
//#endregion

loginAndScrape(url, username, password, isDocker)
.then(() => console.log("領取成功"))
.then(() => console.log("領取完畢"))
.catch((error) => console.error("異常:", error));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-pixai",
"version": "0.3",
"version": "0.4",
"description": "",
"main": "app.js",
"scripts": {
Expand Down

0 comments on commit f736190

Please sign in to comment.