diff --git a/src/models/OCRResult.js b/src/models/OCRResult.js index ea471d8..b2180e2 100644 --- a/src/models/OCRResult.js +++ b/src/models/OCRResult.js @@ -23,5 +23,6 @@ const OCRResult = { BRAVE_PRIVACY_PUB: Symbol("BRAVE_PRIVACY_PUB"), BRAVE_NOTIFICATION: Symbol("BRAVE_NOTIFICATION"), CHOOSE_POSITION: Symbol("CHOOSE_POSITION"), + BRAVE_VPN_SKIP: Symbol("BRAVE_VPN_SKIP"), } module.exports = OCRResult \ No newline at end of file diff --git a/src/utiles/TextExtractor.js b/src/utiles/TextExtractor.js new file mode 100644 index 0000000..68d3335 --- /dev/null +++ b/src/utiles/TextExtractor.js @@ -0,0 +1,24 @@ +const tesseract = require("node-tesseract-ocr"); +const Jimp = require("jimp"); + +const config = { + lang: "eng", + oem: 1, + psm: 3, +} + +async function convertImageToWhiteBlack(image_path) { + const image = await Jimp.read(image_path); + image.().write(image_path + ".wb"); + return image_path + ".wb"; +} + +// let filePath = "/Users/panlei/Desktop/blocked_000c3af9-711e-4b7e-b8ac-5c0a5a2122e7.png" +let filePath = "/Users/panlei/Desktop/01c2456c-blocked_0423a70a-171d-4cb2-9d7d-06ca0dcf6169.png" +convertImageToWhiteBlack(filePath).then(newFilePath => { + tesseract + .recognize(newFilePath, config).then(result => { + console.log(result) + }) +}) + diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index aa812d1..6113c4d 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -91,6 +91,30 @@ class CommandorPage { this.firstStart = true; } + async getActivePage(browser, timeout) { + const start = new Date().getTime(); + while (new Date().getTime() - start < timeout) { + logWithDevice("get pages", this.device) + let pages = await browser.pages(); + try { + pages.forEach((currentPage) => { + if (currentPage.url() === RDV_URL) { + return currentPage; + } else { + try { + currentPage.close() + } catch (e) { + console.log(e) + } + } + }) + } catch (e) { + this.isTerminated = true; + console.log(e) + } + } + throw "Unable to get active page"; + } async connect_to_browser(ocrResult) { console.log("connect_to_browser() called"); @@ -193,7 +217,6 @@ class CommandorPage { } } catch (e) { logWithDevice("failed to connect to device", this.device) - console.log(e) // await this.resetBrowser() await this.checkResultWithOcr() @@ -214,6 +237,7 @@ class CommandorPage { await this.acceptCookies(); await this.enableDisableAirPlanMode(); await delay(10 * 1000); + // await this.checkResultWithOcr() await this.clickOnlineAppointment(); } else { this.isTerminated = true; @@ -262,13 +286,8 @@ class CommandorPage { console.log(e) } } - - // if (this.page.url() === RDV_URL) { - // if (!this.isFillingFields) - // await this.fillFields(this.page, false); - // } } catch (e) { - log(e) + console.log(e) await this.checkResultWithOcr(); } } @@ -680,10 +699,11 @@ class CommandorPage { try { let content = await this.page.content(); let captcha_url = "geo.captcha-delivery.com/captcha"; - if (content.toString().includes(captcha_url)) { - await this.checkResultWithOcr() - logWithDevice("发现datadome", this.device); - } else if (content.includes("502 Bad Gateway")) { + // if (content.toString().includes(captcha_url)) { + // await this.checkResultWithOcr() + // logWithDevice("发现datadome", this.device); + // } else + if (content.includes("502 Bad Gateway")) { logWithDevice("502 Bad Gateway found", this.device) await this.page.reload() } else if (this.page.url().includes("sorry")) { @@ -728,8 +748,8 @@ class CommandorPage { async slidingCaptcha(onResult) { logWithDevice("slidingCaptcha", this.device); - if (this.device.model() === "MI 5s") { - let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 295` + if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD") { + let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 195` await exec(cmd); await delay(1000); } @@ -857,9 +877,14 @@ class CommandorPage { } } + async checkResultWithOcr() { logWithDevice("checkResultWithOcr() called.", this.device) - await delay(4000); + if (this.device.model() === "M2006C3LG") + await delay(6000); + else { + await delay(4000); + } let checkResult = await this.ocrChecker.get_result(); console.log(checkResult); while (checkResult === OCRResult.RECHECK || checkResult === OCRResult.NO_INTERNET) { @@ -888,7 +913,6 @@ class CommandorPage { await this.connect_to_browser(checkResult) break; case OCRResult.FILL_FIELD: - // console.log("browser.isConnected: " + this.browser.isConnected()); if (this.browser === undefined || !this.browser.isConnected()) { logWithDevice("trying to connect to browser", this.device) try { @@ -930,8 +954,6 @@ class CommandorPage { logWithDevice("get pages", this.device) let pages = await this.browser.pages(); logWithDevice("get current page", this.device) - // let needPages = pages.filter(currentPage => currentPage.url() === RDV_URL) - // this.page = needPages[0] try { pages.forEach((currentPage) => { if (currentPage.url() === RDV_URL) { @@ -994,10 +1016,11 @@ class CommandorPage { case OCRResult.BRAVE_PRIVACY: if (this.device.model() === "MI 5s") { await this.tapForDevice(this.device, 530, 970) - // await this.device.shell("input tap " + 530 + " " + 970) - } else if (this.device.model() === "ONEPLUS A6000") + } else if (this.device.model() === "ONEPLUS A6000") { await this.device.shell("input tap " + 530 + " " + 1064) - else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") { + } else if (this.device.model() === "M2006C3LG") { + await this.tapForDevice(this.device, 350, 777) + } else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") { await this.tapForDevice(this.device, 500, 1200) await this.tapForDevice(this.device, 500, 1120) } else @@ -1037,6 +1060,12 @@ class CommandorPage { await this.tapForDevice(this.device, 300, 1700) await this.checkResultWithOcr(); break; + case OCRResult.BRAVE_VPN_SKIP: + logWithDevice("BRAVE_VPN_SKIP", this.device) + if (this.device.model() === "M2006C3LG") { + await this.tapForDevice(this.device, 580, 445) + } + break; case OCRResult.TO_SKIP : logWithDevice("TO_SKIP", this.device) @@ -1122,6 +1151,8 @@ class CommandorPage { await this.device.shell("input tap " + 558 + " " + 1160) } else if (model === "MI 5s") { await this.tapForDevice(this.device, 530, 1000) + } else if (model === "M2006C3LG") { + await this.tapForDevice(this.device, 360, 777) } else if (model === "ONEPLUS A6000") { await this.device.shell("input tap " + 530 + " " + 1106) } else { @@ -1246,6 +1277,8 @@ class CommandorPage { await this.tapForDevice(this.device, 411, 2020) } else if (this.browserPackageName.includes("brave") && this.device.model() === "21091116C") { await this.tapForDevice(this.device, 411, 2020) + } else if (this.browserPackageName.includes("brave") && this.device.model() === "M2006C3LG") {//redmi 9a + await this.tapForDevice(this.device, 411, 1300) } else { await this.tapForDevice(this.device, 411, 2100) } diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index 06bf344..dbe1429 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -13,6 +13,7 @@ function delay(delayInMs) { } const NO_INTERNET_FR = "Aucun accés a Internet" +const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave" const MESSAGE_URL_VALIDATION_FR = "envoyé un lien par e-mail." const MESSAGE_URL_VALIDATION_FR_2 = "un lien par e-mail" const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" @@ -32,6 +33,7 @@ const SLIDING_CAPTCHA_FR = "Pourquoi cette vérification" const SLIDING_CAPTCHA_FR_2 = "Glissez vers la droite pour" const SLIDING_CAPTCHA_FR_3 = "la droite pour completer le puzzle" const SLIDING_CAPTCHA_FR_4 = " s'assure qu'on s'adresse bien" +const SLIDING_CAPTCHA_FR_5 = "On s'assure que c'est" const MESSAGE_FILL_FIELD_FR = "Demande de rendez-vous pour" const MESSAGE_FILL_FIELD_FR_2 = "des champs de données doivent étre complétés" const MESSAGE_FILL_FIELD_FR_3 = "Sans préféré" @@ -92,6 +94,10 @@ class OCRChecker { } else if (result.includes(CHOOSE_POSITION_GOOGLE_FR)) { await this.deleteFile(fileName) return OCRResult.CHOOSE_POSITION + } else if (result.includes(BRAVE_VPN_SKIP)) { + await this.deleteFile(fileName) + await this.deleteFile(screenShot) + return OCRResult.BRAVE_VPN_SKIP } else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5)) { await this.deleteFile(fileName) return OCRResult.FILL_FIELD @@ -108,7 +114,7 @@ class OCRChecker { } else if (result.includes(BRAVE_NOTIFICATION)) { await this.deleteFile(fileName) return OCRResult.BRAVE_NOTIFICATION - } else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4)) { + } else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4) || result.includes(SLIDING_CAPTCHA_FR_5)) { await this.deleteFile(fileName) // await this.deleteFile(screenShot) // if (result.includes("rac"))