Skip to content

Commit 19b4903

Browse files
committed
improve description & add common delimiter
1 parent a98f115 commit 19b4903

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/scriptlets/trusted-click-element.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
*
1919
* - `selectors` — required, string with query selectors delimited by comma
2020
* - 'delay' - optional, time in ms to delay scriptlet execution after elements are loaded and targeted on the page, defaults to 0
21-
* - `extraMatch` - optional, extra values to match on a page as keyword:value pairs delimited by commas. Possible keywords:
21+
* - `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.
22+
* 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:
2223
* - `cookie` - test substring against document.cookie string
2324
* - `localStorage` - check if localStorage item is present
2425
* **Examples**
@@ -39,7 +40,7 @@ import {
3940
*
4041
* 4. Match by cookie strings and click multiple elements by selector
4142
* ```
42-
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], input[type="submit"][value="akkoord"]', '', 'cookie:userConsentCommunity, cookie:cmpconsent')
43+
* example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], input[type="submit"][value="akkoord"]', '', 'cookie:userConsentCommunity, cookie:cmpconsent=1')
4344
* ```
4445
*
4546
* 5. Match by localStorage item 'promo' key
@@ -61,16 +62,15 @@ export function trustedClickElement(source, selectors, delay, extraMatch = '') {
6162
const log = console.log.bind(console);
6263

6364
const OBSERVER_TIMEOUT = 10000;
64-
const SELECTORS_DELIMITER = ',';
65-
const EXTRA_MATCH_DELIMITER = ',';
6665
const COOKIE_MATCH_MARKER = 'cookie:';
66+
const COMMON_DELIMITER = ',';
6767
const LOCAL_STORAGE_MATCH_MARKER = 'localStorage:';
6868

6969
let parsedDelay;
7070
if (delay) {
7171
parsedDelay = parseInt(delay, 10);
7272
if (Number.isNaN(parsedDelay) || parsedDelay > OBSERVER_TIMEOUT) {
73-
log(`Passed delay '${delay}' is invalid or bigger than ${OBSERVER_TIMEOUT}ms`);
73+
log(`Passed delay '${delay}' is invalid or bigger than ${OBSERVER_TIMEOUT} ms`);
7474
return;
7575
}
7676
}
@@ -83,7 +83,7 @@ export function trustedClickElement(source, selectors, delay, extraMatch = '') {
8383
if (extraMatch) {
8484
// Get all match marker:value pairs from argument
8585
const parsedExtraMatch = extraMatch
86-
.split(EXTRA_MATCH_DELIMITER)
86+
.split(COMMON_DELIMITER)
8787
.map((matchStr) => matchStr.trim());
8888

8989
// Filter match pairs by marker
@@ -121,7 +121,7 @@ export function trustedClickElement(source, selectors, delay, extraMatch = '') {
121121
* and prevent selectors from being queried multiple times
122122
*/
123123
let selectorsSequence = selectors
124-
.split(SELECTORS_DELIMITER)
124+
.split(COMMON_DELIMITER)
125125
.map((selector) => selector.trim());
126126

127127
/**

0 commit comments

Comments
 (0)