Created
May 24, 2021 11:37
-
-
Save anishd19/4641a6e012b83eae1c194b0dddc0c317 to your computer and use it in GitHub Desktop.
cowin covaxin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function runProcessLoop() { | |
| let succeeded = false; | |
| const sleep = function sleep(ms) { | |
| return new Promise((resolve) => setTimeout(resolve, ms)); | |
| }; | |
| const computeIsSearchInfotextVisible = function () { | |
| const selector = | |
| "#main-content > app-appointment-table > ion-content > div > div > ion-grid > ion-row > ion-grid > ion-row > ion-col > ion-grid > ion-row > ion-col:nth-child(2) > form > ion-grid > ion-row:nth-child(2) > ion-col.search-dose-txt.ng-star-inserted.md.hydrated"; | |
| let result = document.querySelector(selector) !== null; | |
| // result = confirm(`result is ${result}`); | |
| // succeeded = confirm("force succeeded"); | |
| console.warn("computeIsSearchInfotexVisible invoked, result is : ", result); | |
| return true; | |
| // return result; | |
| }; | |
| const searchBtnSelector = | |
| "#main-content > app-appointment-table > ion-content > div > div > ion-grid > ion-row > ion-grid > ion-row > ion-col > ion-grid > ion-row > ion-col:nth-child(2) > form > ion-grid > ion-row:nth-child(1) > ion-col.col-padding.ng-star-inserted.md.hydrated > ion-row > ion-col.ion-text-start.col-space-mobile.md.hydrated > ion-button"; | |
| const age18BtnSelector = | |
| "#main-content > app-appointment-table > ion-content > div > div > ion-grid > ion-row > ion-grid > ion-row > ion-col > ion-grid > ion-row > ion-col:nth-child(2) > form > ion-grid > ion-row:nth-child(2) > ion-col:nth-child(1) > div > div:nth-child(1) > label"; | |
| const covaxinBtnSelector = | |
| "#main-content > app-appointment-table > ion-content > div > div > ion-grid > ion-row > ion-grid > ion-row > ion-col > ion-grid > ion-row > ion-col:nth-child(2) > form > ion-grid > ion-row:nth-child(2) > ion-col:nth-child(1) > div > div:nth-child(4) > label"; | |
| const searchBtn = document.querySelector(searchBtnSelector); | |
| const age18Btn = document.querySelector(age18BtnSelector); | |
| const covaxinBtn = document.querySelector(covaxinBtnSelector); | |
| if (!succeeded) { | |
| const allNodes = document.querySelectorAll(".slots-box"); | |
| for (let i = 0; i < allNodes.length; i++) { | |
| const node = allNodes[i]; | |
| if ( | |
| !node.classList.contains("no-seat") && | |
| !node.classList.contains("less-seat") && | |
| !node.classList.contains("no-available") | |
| ) { | |
| console.log("AVAILABLE!!", node); | |
| node.click(); | |
| succeeded = true; | |
| break; | |
| } | |
| } | |
| console.warn("Not available"); | |
| if (succeeded) { | |
| return; | |
| } | |
| new Promise((resolve, reject) => { | |
| setTimeout(resolve, 15000); | |
| }).then(() => { | |
| new Promise((resolve, reject) => { | |
| console.log('clicking searchBtn now after 15 seconds'); | |
| searchBtn.click(); | |
| // let isSearchInfotextVisible = false; | |
| // while (!isSearchInfotextVisible) { | |
| // console.warn( | |
| // "waiting Search to be completed", | |
| // !isSearchInfotextVisible | |
| // ); | |
| // isSearchInfotextVisible = computeIsSearchInfotextVisible(); | |
| // } | |
| console.warn("waiting Search to be completed"); | |
| setTimeout(resolve, 3000); | |
| }).then(() => { | |
| new Promise((resolve, reject) => { | |
| age18Btn.click(); | |
| const intervalOne = setInterval(() => { | |
| if (window.getComputedStyle(age18Btn).color !== "rgb(0, 32, 96)") { | |
| clearInterval(intervalOne); | |
| resolve(); | |
| } | |
| console.warn("waiting age18Btn to be clicked"); | |
| }, 2000); | |
| }).then(() => { | |
| new Promise((resolve, reject) => { | |
| covaxinBtn.click(); | |
| const intervalTwo = setInterval(() => { | |
| if ( | |
| window.getComputedStyle(covaxinBtn).color !== "rgb(0, 32, 96)" | |
| ) { | |
| clearInterval(intervalTwo); | |
| resolve(); | |
| } | |
| console.warn("waiting covaxinBtn to be clicked"); | |
| }, 2000); | |
| }).then(() => { | |
| runProcessLoop(); | |
| }); | |
| }); | |
| }); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment