Core API
if()
Conditional logic hook.
if()
Perform an action inside the queue based on a dynamically evaluated condition. The if block executes immediately if evaluated directly.
Use Cases
- Handling dynamic elements: Only clicking a notification pop-up if it is currently visible on the screen.
- Conditional flows: Skipping a "Next" button click during a tutorial if the product feature is already disabled by settings.
Example
const cursor = new Cursor();
cursor
.hover('#dynamic-btn')
.if(
() => document.querySelector('#dynamic-btn')?.classList.contains('active'),
(ctx) => {
// Runs only if the button has the "active" class
ctx.click('#dynamic-btn');
}
)
.wait(1000);