Skip to content

Commit

Permalink
style: no need to destructure object
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt committed May 7, 2024
1 parent 476e21d commit 54017f2
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/spoof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ export interface GhostCursor {
}

// Helper function to wait a specified number of milliseconds
const delay = async (ms: number): Promise<void> =>
const delay = async (ms: number): Promise<void> => {
if (ms < 1) return

await new Promise((resolve) => setTimeout(resolve, ms))
}

/**
* Calculate the amount of time needed to move from (x1, y1) to (x2, y2)
Expand Down Expand Up @@ -282,9 +285,7 @@ export const createCursor = (
try {
if (!moving) {
const rand = await getRandomPagePoint(page)
await tracePath(path(previous, rand, {
moveSpeed: options?.moveSpeed
}), true)
await tracePath(path(previous, rand, options), true)
previous = rand
}
if (options?.moveDelay !== undefined && options.moveDelay >= 0) {
Expand Down Expand Up @@ -318,13 +319,9 @@ export const createCursor = (
}

try {
if (options?.hesitate !== undefined) {
await delay(options.hesitate)
}
await delay(options?.hesitate ?? 0)
await page.mouse.down()
if (options?.waitForClick !== undefined) {
await delay(options.waitForClick)
}
await delay(options?.waitForClick ?? 0)
await page.mouse.up()
} catch (error) {
log('Warning: could not click mouse, error message:', error)
Expand Down Expand Up @@ -400,14 +397,12 @@ export const createCursor = (
? overshoot(destination, overshootRadius)
: destination

await tracePath(path(previous, to, {
moveSpeed: options?.moveSpeed
}))
await tracePath(path(previous, to, options))

if (overshooting) {
const correction = path(to, { ...dimensions, ...destination }, {
spreadOverride: overshootSpread,
moveSpeed: options?.moveSpeed
...options,
spreadOverride: overshootSpread
})

await tracePath(correction)
Expand Down

0 comments on commit 54017f2

Please sign in to comment.