Skip to content

Commit

Permalink
Refactor countdown timer and csv url
Browse files Browse the repository at this point in the history
  • Loading branch information
chunkingz committed Dec 29, 2024
1 parent 788c4da commit ec40394
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"skipTitle": "Skipping job with title",
"applyTo": "Applying to",
"limit": "You've reached the Easy Apply application limit for today. Exiting the app",
"counter": "counter",
"jobSkipped": "Job Skipped",
"scrolledPage": "Finished scrolling page N°",
"badSelector": "Error clicking element with selector",
"elSelector": "Element with selector",
"notFound": "not found",
"el404Scroll": "Element not found for scrolling",
"errorOnScroll": "Error scrolling",
"alreadyApplied": "Skipping this job... Reason: Already Applied"
"alreadyApplied": "Skipping this job... Reason: Already Applied",
"waiting": "Waiting for user input",
"remains": "s remaining"
}
31 changes: 17 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ async function clickElement(selector) {
try {
await page.waitForSelector(selector);
const element = await page.$(selector);
if(element !== null){
if (element !== null) {
await element.click();
}else{
console.error(`${t.elSelector}: "${selector}" ${t.notFound}.`);
} else {
console.error(`\n${t.elSelector}: "${selector}" ${t.notFound}.`);
}
} catch (error) {
console.error(`${t.badSelector}: "${selector}". \n${error}`);
console.error(error);
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ async function jobCriteriaByTime() {
await clickElement(
"ul.search-reusables__filter-list>li:nth-child(4)>div>span>button"
);
await pause();
await pause(2000);
await clickElement(
`form > fieldset > div.pl4.pr6 > ul > li:nth-child(${
periodOfTime === "Past 24 hours" ? 4 : 3
Expand Down Expand Up @@ -240,7 +240,7 @@ async function fillAndApply() {
while (currentPage <= maxPagination) {
for (let index = 0; index < numberOfJobsPerPage; index++) {
if (currentJobIndex > totalJobCount) {
console.log(`==========\n${t.endOfScript}.\n==========`);
console.log(`\n==========\n${t.endOfScript}.\n==========`);
exit(0);
}
let state = true;
Expand Down Expand Up @@ -354,16 +354,17 @@ async function fillAndApply() {
// }
// });
// }
let counter = 0;

let counter = 30;
let finalPage = false;
do {
await pause();
const modalExists = await page.$(
'div[class*="artdeco-modal-overlay"]>div>div+div>div>button>span'
);
if (!modalExists) {
counter++;
console.log(`${t.counter}: ${counter}`);
counter--;
process.stdout.write(`\r${t.waiting}: ${counter}${t.remains}`);

finalPage = await page.evaluate(() => {
const nextButton = document.querySelector(
Expand All @@ -376,11 +377,13 @@ async function fillAndApply() {
return true;
}
});
} else counter = -2;
} while (counter >= 0 && counter < 20 && finalPage === false);
} else {
counter = -2;
}
} while (counter > 0 && counter <= 30 && finalPage === false);

let skipped = false;
if (counter >= 5 && finalPage === false) {
if (finalPage === false) {
// due to inactivity, skip the job
await pause();
await clickElement(
Expand All @@ -391,7 +394,7 @@ async function fillAndApply() {
'[data-control-name="discard_application_confirm_btn"]'
);
skipped = true;
console.log(`${t.jobSkipped}`);
console.log(`\n${t.jobSkipped}`);
} else {
// Finish the job application by closing the dialog with the `X` button.
await pause();
Expand All @@ -406,7 +409,7 @@ async function fillAndApply() {
// Add the Job to the CSV file
writeInCSV({
jobTitle: jobTitle,
link: "https://www.linkedin.com" + jobLink,
link: jobLink,
status: skipped ? "Skipped" : "Applied",
});
}
Expand Down

0 comments on commit ec40394

Please sign in to comment.