Skip to content

Commit

Permalink
improve delay arg
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Oct 7, 2022
1 parent bb06036 commit ade2862
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/scriptlets/trusted-click-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
* ```
*
* - `selectors` — required, string with query selectors delimited by comma
* - 'delay' - optional, time in ms to delay scriptlet execution after elements are loaded and targeted on the page, defaults to 0
* - `extraMatch` — optional, extra condition to check on a page; allows to match `cookie` and `localStorage`; can be set as `name:key[=value]` where `value` is optional.
* Multiple conditions are allowed inside one `extraMatch` but they should be delimited by comma and each of them should match the syntax. Possible `name`s:
* - `cookie` - test substring against document.cookie string
* - `localStorage` - check if localStorage item is present
* - 'delay' - optional, time in ms to delay scriptlet execution, defaults to instant execution.
* **Examples**
* 1. Click elements by selector
* ```
Expand Down Expand Up @@ -54,7 +54,7 @@ import {
* ```
*/
/* eslint-enable max-len */
export function trustedClickElement(source, selectors, delay, extraMatch = '') {
export function trustedClickElement(source, selectors, extraMatch = '', delay = NaN) {
if (!selectors) {
return;
}
Expand All @@ -69,7 +69,8 @@ export function trustedClickElement(source, selectors, delay, extraMatch = '') {
let parsedDelay;
if (delay) {
parsedDelay = parseInt(delay, 10);
if (Number.isNaN(parsedDelay) || parsedDelay > OBSERVER_TIMEOUT) {
const isValidDelay = !Number.isNaN(parsedDelay) || parsedDelay < OBSERVER_TIMEOUT;
if (!isValidDelay) {
log(`Passed delay '${delay}' is invalid or bigger than ${OBSERVER_TIMEOUT} ms`);
return;
}
Expand Down

0 comments on commit ade2862

Please sign in to comment.