181 lines
5.7 KiB
JavaScript
181 lines
5.7 KiB
JavaScript
const fs = require('fs');
|
|
const { By, Key, until } = require('selenium-webdriver');
|
|
|
|
const { createIdentity } = require('./identityHandler');
|
|
const { getCodeFromEmail } = require('./codeHandler');
|
|
const { clickTime, urlTime, timeoutLoading } = require('./speedHandler').getSpeed();
|
|
|
|
async function createAccount(driver) {
|
|
|
|
try {
|
|
const identity = await createIdentity();
|
|
|
|
await driver.get('https://rewards.microsoft.com/');
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.wait(until.titleContains('Sign in to'), timeoutLoading);
|
|
|
|
const emailInput = await driver.findElement(By.name('loginfmt'));
|
|
await emailInput.sendKeys(identity.email);
|
|
await driver.sleep(clickTime);
|
|
await emailInput.sendKeys(Key.RETURN);
|
|
|
|
await driver.sleep(urlTime);
|
|
|
|
const getANewOneButton = await driver.findElement(By.id('idA_PWD_SignUp'));
|
|
await getANewOneButton.click();
|
|
await driver.sleep(urlTime);
|
|
|
|
await driver.findElement(By.id('iSignupAction')).click();
|
|
await driver.sleep(clickTime);
|
|
|
|
await driver.wait(until.titleContains('password'), timeoutLoading);
|
|
|
|
const passwordInput = await await driver.findElement(By.id('PasswordInput'));
|
|
await passwordInput.sendKeys(identity.password);
|
|
|
|
await driver.findElement(By.id('iSignupAction')).click();
|
|
await driver.sleep(clickTime);
|
|
|
|
await driver.wait(until.titleContains('name'), timeoutLoading);
|
|
|
|
const firstNameInput = await await driver.findElement(By.id('FirstName'));
|
|
await firstNameInput.sendKeys(identity.first_name);
|
|
|
|
const lastNameInput = await await driver.findElement(By.id('LastName'));
|
|
await lastNameInput.sendKeys(identity.last_name);
|
|
|
|
await driver.sleep(urlTime);
|
|
await driver.findElement(By.id('iSignupAction')).click();
|
|
await driver.sleep(clickTime);
|
|
|
|
await driver.wait(until.titleContains('birthdate'), timeoutLoading);
|
|
|
|
await driver.sleep(urlTime);
|
|
driver.findElement(By.id('BirthMonth')).then(function(birthMonthSelect) {
|
|
birthMonthSelect.findElement(By.css(`option[value="${identity.birth_date.getMonth() + 1}"]`)).click();
|
|
});
|
|
|
|
driver.findElement(By.id('BirthDay')).then(function(birthDaySelect) {
|
|
birthDaySelect.findElement(By.css(`option[value="${identity.birth_date.getDate()}"]`)).click();
|
|
});
|
|
|
|
driver.findElement(By.id('BirthYear')).then(function(birthYearInput) {
|
|
birthYearInput.clear();
|
|
birthYearInput.sendKeys(identity.birth_date.getFullYear());
|
|
});
|
|
|
|
await driver.sleep(clickTime);
|
|
await driver.findElement(By.id('iSignupAction')).click();
|
|
|
|
await driver.wait(until.titleContains('code'), timeoutLoading);
|
|
|
|
// VerificationCode
|
|
const VerificationCodeInput = await await driver.findElement(By.id('VerificationCode'));
|
|
try {
|
|
const code = await getCodeFromEmail();
|
|
await VerificationCodeInput.sendKeys(`${code}`);
|
|
}
|
|
catch (err) {
|
|
return;
|
|
}
|
|
await driver.findElement(By.id('iOptinEmail')).click();
|
|
await driver.sleep(clickTime);
|
|
await driver.findElement(By.id('iSignupAction')).click();
|
|
|
|
await driver.sleep(urlTime + 4000);
|
|
const source = await driver.getPageSource();
|
|
if (source.includes('Phone number')) {
|
|
console.log('Ip usage exceeded please switch IP');
|
|
}
|
|
else {
|
|
await driver.wait(until.titleContains('Welcome'), 300000);
|
|
|
|
const account = {
|
|
'name': identity.first_name + ' ' + identity.last_name,
|
|
'birthdate': identity.birth_date,
|
|
'username': identity.email,
|
|
'password': identity.password,
|
|
};
|
|
|
|
|
|
let accounts = [];
|
|
if (fs.existsSync('../accounts/accounts.json')) {
|
|
const content = fs.readFileSync('accounts.json', 'utf8');
|
|
accounts = JSON.parse(content);
|
|
}
|
|
|
|
accounts.push(account);
|
|
fs.writeFileSync('../accounts/accounts.json', JSON.stringify(accounts));
|
|
|
|
console.log('Account saved to accounts.json, there are currently ' + accounts.length + ' accounts');
|
|
|
|
await driver.sleep(urlTime);
|
|
try {
|
|
await driver.findElement(By.xpath('//button[contains(text(),\'Reject\')]')).click();
|
|
await driver.sleep(clickTime);
|
|
}
|
|
catch (err) {
|
|
console.log(err);
|
|
}
|
|
const startEarningLink = By.id('start-earning-rewards-link');
|
|
let linkFound = false;
|
|
while (!linkFound) {
|
|
try {
|
|
await driver.findElement(startEarningLink).click();
|
|
linkFound = true;
|
|
}
|
|
catch (error) {
|
|
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
}
|
|
}
|
|
|
|
await driver.sleep(clickTime);
|
|
|
|
await driver.wait(until.titleContains('Rewards'), timeoutLoading);
|
|
await driver.sleep(5000);
|
|
try {
|
|
await driver.findElement(By.css('a.welcome-tour-next-button.c-call-to-action.c-glyph')).click();
|
|
await driver.sleep(clickTime);
|
|
let buttons = await driver.findElements(By.css('a.quiz-link.gray-button.c-call-to-action.c-glyph.f-lightweight'));
|
|
buttons[1].click();
|
|
|
|
await driver.sleep(clickTime);
|
|
await driver.get('https://rewards.microsoft.com/');
|
|
|
|
await driver.sleep(urlTime);
|
|
await driver.get('https://rewards.bing.com/welcometour');
|
|
|
|
await driver.sleep(urlTime);
|
|
buttons = await driver.findElements(By.css('a.quiz-link.gray-button.c-call-to-action.c-glyph.f-lightweight'));
|
|
buttons[0].click();
|
|
|
|
await driver.sleep(clickTime);
|
|
await driver.get('https://rewards.microsoft.com/');
|
|
|
|
await driver.sleep(urlTime);
|
|
await driver.get('https://rewards.bing.com/welcometour');
|
|
|
|
await driver.sleep(clickTime);
|
|
buttons = await driver.findElements(By.css('a.quiz-link.gray-button.c-call-to-action.c-glyph.f-lightweight'));
|
|
buttons[0].click();
|
|
}
|
|
catch (err) {
|
|
console.log(err);
|
|
}
|
|
await driver.sleep(clickTime);
|
|
await driver.get('https://rewards.bing.com/redeem/000803000032');
|
|
|
|
await driver.sleep(urlTime);
|
|
await driver.findElement(By.xpath('//span[contains(text(), "SET AS GOAL")]')).click();
|
|
|
|
await driver.sleep(2000);
|
|
}
|
|
}
|
|
finally {
|
|
await driver.quit();
|
|
}
|
|
return;
|
|
}
|
|
|
|
module.exports = { createAccount }; |