Skip to content

Commit

Permalink
Migrated all logins to a more human behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
elpatronaco committed Mar 22, 2021
1 parent d01bcb2 commit 1c8440c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 42 deletions.
39 changes: 27 additions & 12 deletions src/scripts/aussar/login.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
const { createCursor, getRandomPagePoint } = require('ghost-cursor')
const { randomNumberRange } = require('ghost-cursor/lib/math')
const { humanType } = require('../../utils')

module.exports = async (page, { email, password }) => {
await page.goto('https://www.aussar.es/iniciar-sesion', { waitUntil: 'networkidle2' })

// fills the form and logs in
const values = await Promise.all([
page.$("input[name='email']"),
page.$("input[name='password']"),
page.$('#submit-login')
])

await values[0].focus()
await page.keyboard.type(email.trim())
await values[1].focus()
await page.keyboard.type(password.trim())
await values[2].click()
await page.waitForTimeout(randomNumberRange(1000, 3000))

const cursor = createCursor(page, await getRandomPagePoint(page))

await cursor.click("input[name='email']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, email.trim())

await cursor.click("input[name='password']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, password.trim())

await cursor.click('#submit-login', {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})

await page.waitForTimeout(10000)

Expand Down
39 changes: 29 additions & 10 deletions src/scripts/coolmod/login.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
const { createCursor, getRandomPagePoint } = require('ghost-cursor')
const { randomNumberRange } = require('ghost-cursor/lib/math')
const { humanType } = require('../../utils')

module.exports = async (page, { email, password }) => {
await page.goto('https://www.coolmod.com/mi-cuenta', {
waitUntil: 'networkidle2'
})

const values = await Promise.all([
page.$("input[name='username']"),
page.$("input[name='password']")
])
await values[0].click()
await values[0].focus()
await page.keyboard.type(email.trim())
await values[1].click()
await values[1].focus()
await page.keyboard.type(password.trim())
await page.waitForTimeout(randomNumberRange(1000, 3000))

const cursor = createCursor(page, await getRandomPagePoint(page))

const modalCloseBtn = await page.$('button.confirm')
if (modalCloseBtn)
await cursor.click(modalCloseBtn, {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})

await cursor.click("input[name='username']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, email.trim())

await cursor.click("input[name='password']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, password.trim())
await page.keyboard.press('Enter')

await page.waitForTimeout(10000)
Expand Down
27 changes: 21 additions & 6 deletions src/scripts/ldlc/login.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
const { createCursor, getRandomPagePoint } = require('ghost-cursor')
const { randomNumberRange } = require('ghost-cursor/lib/math')
const { humanType } = require('../../utils')

module.exports = async (page, { email, password }) => {
await page.goto('https://secure2.ldlc.com/es-es/Login/Login?returnUrl=%2Fes-es%2FAccount', {
waitUntil: 'networkidle2'
})

// fills the form and logs in
const values = await Promise.all([page.$('#Email'), page.$('#Password')])
await values[0].focus()
await page.keyboard.type(email.trim())
await values[1].focus()
await page.keyboard.type(password.trim())
await page.waitForTimeout(randomNumberRange(1000, 3000))

const cursor = createCursor(page, await getRandomPagePoint(page))

await cursor.click('#Email', {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, email.trim())

await cursor.click('#Password', {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, password.trim())
await page.keyboard.press('Enter')

await page.waitForTimeout(10000)
Expand Down
39 changes: 27 additions & 12 deletions src/scripts/pccomponentes/login.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
const { createCursor, getRandomPagePoint } = require('ghost-cursor')
const { randomNumberRange } = require('ghost-cursor/lib/math')
const { humanType } = require('../../utils')

module.exports = async (page, { email, password }) => {
await page.goto('https://www.pccomponentes.com/login', { waitUntil: 'networkidle2' })

// fills the form and logs in
const values = await Promise.all([
page.$("input[data-cy='email']"),
page.$("input[data-cy='password']"),
page.$("button[data-cy='log-in']")
])

await values[0].focus()
await page.keyboard.type(email.trim())
await values[1].focus()
await page.keyboard.type(password.trim())
await values[2].click()
await page.waitForTimeout(randomNumberRange(1000, 3000))

const cursor = createCursor(page, await getRandomPagePoint(page))

await cursor.click("input[data-cy='email']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, email.trim())

await cursor.click("input[data-cy='password']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})
await humanType(page, password.trim())

await cursor.click("button[data-cy='log-in']", {
waitForClick: randomNumberRange(1000, 3000),
moveDelay: randomNumberRange(1000, 3000),
paddingPercentage: 20
})

await page.waitForTimeout(10000)

Expand Down
16 changes: 14 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs')
const { randomNumberRange } = require('ghost-cursor/lib/math')
const readline = require('readline')

Array.prototype.forEachAsync = async function (fn) {
Expand All @@ -7,6 +8,12 @@ Array.prototype.forEachAsync = async function (fn) {
}
}

String.prototype.forEachAsync = async function (fn) {
for (let t of this) {
await fn(t)
}
}

const getDirectoryNames = path =>
fs.readdirSync(path).filter(file => fs.statSync(`${path}/${file}`).isDirectory())

Expand All @@ -19,6 +26,11 @@ const rl = readline.createInterface({

const question = str => new Promise(resolve => rl.question(str, resolve))

const randomIntFromInterval = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
const humanType = async (page, str) => {
await [...str].forEachAsync(async letter => {
await page.keyboard.type(letter)
await page.waitForTimeout(randomNumberRange(30, 100))
})
}

module.exports = { getDirectoryNames, sleep, question, rl, randomIntFromInterval }
module.exports = { getDirectoryNames, sleep, question, rl, humanType }

0 comments on commit 1c8440c

Please sign in to comment.