Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move applies moveDelay #128

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Moves the mouse to the specified selector or element.
- **options (optional):** Additional options for moving.
- `paddingPercentage (number):` Percentage of padding to be added around the element. Default is `0`.
- `waitForSelector (number):` Time to wait for the selector to appear in milliseconds. Default is to not wait for selector.
- `moveDelay (number):` Delay after moving the mouse in milliseconds. Default is `2000`.
- `moveDelay (number):` Delay after moving the mouse in milliseconds. Default is `0`.
- `maxTries (number):` Maximum number of attempts to mouse-over the element. Default is `10`.
- `moveSpeed (number):` Speed of mouse movement. Default is random.
- `overshootThreshold (number):` Distance from current location to destination that triggers overshoot to occur. (Below this distance, no overshoot will occur). Default is `500`.
Expand Down
17 changes: 14 additions & 3 deletions src/spoof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface MoveOptions extends BoxOptions {
readonly waitForSelector?: number
/**
* Delay after moving the mouse in milliseconds.
* @default 2000
* @default 0
*/
readonly moveDelay?: number
/**
Expand Down Expand Up @@ -60,6 +60,11 @@ export interface ClickOptions extends MoveOptions {
* @default 0
*/
readonly waitForClick?: number
/**
* Delay after performing the click in milliseconds.
* @default 2000
*/
readonly moveDelay?: number
}

export interface PathOptions {
Expand Down Expand Up @@ -323,7 +328,11 @@ export const createCursor = (
actions.toggleRandomMove(false)

if (selector !== undefined) {
await actions.move(selector, options)
await actions.move(selector, {
...options,
// apply moveDelay after click, but not after actual move
moveDelay: 0
})
actions.toggleRandomMove(false)
}

Expand Down Expand Up @@ -430,7 +439,9 @@ export const createCursor = (
return await go(iteration + 1)
}
}
return await go(0)
await go(0)

await delay(Math.random() * (options?.moveDelay ?? 0))
},
async moveTo (destination: Vector): Promise<void> {
actions.toggleRandomMove(false)
Expand Down