Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
🤖 Added setting up IMAP feature
Browse files Browse the repository at this point in the history
- added setting up IMAP feature
- changed getting chrome path method
  • Loading branch information
NightStrang6r committed Sep 16, 2022
1 parent e7d9350 commit 0a78a28
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 42 deletions.
2 changes: 2 additions & 0 deletions Build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nexe src/index.js --build --verbose -t windows --python=C:\My\Programs\Python3 --name=RamblerAutoReg
pause
92 changes: 90 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "autorambler",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"main": "src/index.js",
"type": "module",
"dependencies": {
"chalk": "^5.0.1",
"get-chrome": "^0.0.2",
"inquirer": "^9.1.0",
"puppeteer": "^13.5.1"
},
Expand All @@ -14,4 +15,4 @@
},
"author": "",
"license": "ISC"
}
}
12 changes: 12 additions & 0 deletions src/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class Ask {
return answers.startValue;
}

async askToEnableIMAP() {
const questions =
[{
name: 'imap',
type: 'confirm',
message: 'Do you want to enable IMAP for emails?'
}];

const answers = await inquirer.prompt(questions);
return answers.imap;
}

async ask() {
const questions =
[{
Expand Down
30 changes: 2 additions & 28 deletions src/chrome.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import puppeteer from 'puppeteer';
import { execFile } from 'child_process';
import path from 'path';
import getChrome from 'get-chrome';

class Chrome {
constructor(chromePath = '') {
Expand Down Expand Up @@ -28,32 +27,7 @@ class Chrome {
}

async getPath() {
const promise = new Promise((resolve, reject) => {
const __dirname = path.resolve(path.dirname(''));
const pathToBat = path.resolve(__dirname, 'src/utils/chromePath.bat');

execFile(pathToBat, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
resolve(false);
}
if (stderr!= "")
resolve(false);;

let result = stdout.split('"');

for(let i = 0; i < result.length; i++) {
if(result[i].includes('chrome.exe')) {
result = result[i];
break;
}
}

resolve(result);
});
});

return promise;
return getChrome();
}

setPath(path) {
Expand Down
47 changes: 41 additions & 6 deletions src/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Registration {
questionSelect: "div[data-cerber-id*='Почтовый индекс ваших родителей']",
questionAnswer: "#answer",
hCapcha: "#checkbox",
submit: "button[type=submit]"
submit: "button[type=submit]",
submitImapChange: 'button.MailAppsChange-submitButton-S7'
};
}

Expand All @@ -40,14 +41,16 @@ class Registration {

log(c.green(`File ${this.settings.mailsFile} found`));

const imap = await this.ask.askToEnableIMAP();

const mails = this.storage.parseMailsFile();
if(!mails || ! mails.length) return;
log(`Loaded ${mails.length} mails`);

const toStart = await this.ask.askToStartRegistration();
if(!toStart) return;

this.regMails(mails, 'move');
this.regMails(mails, 'move', imap);
}

async byGenerate() {
Expand All @@ -74,23 +77,25 @@ class Registration {
if(startValue == 0) {
startValue = 1;
}

const imap = await this.ask.askToEnableIMAP();

const mails = await this.generateAccounts(login, domain, passLength, emailsCount, startValue, code);
const toStart = await this.ask.askToStartRegistration();
if(!toStart) return;

this.regMails(mails, 'add');
this.regMails(mails, 'add', imap);
}

async regMails(mails, toFile) {
async regMails(mails, toFile, imap = false) {
let registered = 0;
await this.chrome.launch();

for(let i = 0; i < mails.length; i++) {
const mail = mails[i];

log(c.cyan(`[${(i + 1)}] Registering ${mail.login}...`));
const res = await this.reg(mail.login, mail.domain, mail.pass, mail.code);
const res = await this.reg(mail.login, mail.domain, mail.pass, mail.code, imap);

if(res) {
log(`${c.green(`[${(i + 1)}] Mail`)} ${c.magenta(mail.email)} ${c.green(`successfully registered:`)}`);
Expand All @@ -117,7 +122,7 @@ class Registration {
log(c.green(`Successfully registered ${c.yellowBright(registered)} accounts.`));
}

async reg(login, domain, pass, code) {
async reg(login, domain, pass, code, imap) {
let result = false;

try {
Expand Down Expand Up @@ -156,6 +161,17 @@ class Registration {

await page.type(this.selectors.questionAnswer, code, {delay: 20});
await page.evaluate('window.scrollTo(0, document.body.scrollHeight)');

const iframeHandle = await page.$('iframe');
const iframe = await iframeHandle.contentFrame();

await iframe.evaluate(() => {
return new Promise((resolve, reject) => {
const checkbox = document.querySelector('div#checkbox');
checkbox.click();
resolve();
});
});

await page.evaluate(() => {
return new Promise((resolve, reject) => {
Expand All @@ -174,6 +190,25 @@ class Registration {
while(!(await page.target()._targetInfo.url).includes(this.links.readyPage)) {
await this.sleep(500);
}

if(imap) {
await page.goto('https://mail.rambler.ru/settings/mailapps/change');
await page.waitForSelector(this.selectors.submitImapChange);

await page.evaluate((submitImapChange) => {
return new Promise((resolve, reject) => {
setInterval(() => {
const element = document.querySelector(submitImapChange);
console.log(element.disabled);
if(!element || element.disabled == true) return;
resolve();
}, 200);
});
}, this.selectors.submitImapChange);

await page.click(this.selectors.submitImapChange);
}

await this.chrome.deleteCookies(page);

result = {
Expand Down
4 changes: 0 additions & 4 deletions src/utils/chromePath.bat

This file was deleted.

0 comments on commit 0a78a28

Please sign in to comment.