Skip to content

Commit

Permalink
Rename elementContainsText to doesElementContainText and refactor it
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed May 23, 2024
1 parent 7fab2a8 commit a47011e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/scriptlets/trusted-click-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,21 @@ export function trustedClickElement(source, selectors, extraMatch = '', delay =
}
}

const parsedTextToMatch = textMatches ? toRegExp(textMatches) : '';
const textMatchRegexp = textMatches ? toRegExp(textMatches) : null;

/**
* Checks if an element contains the specified text.
*
* @param {Element} element - The element to check.
* @param {string} textMatch - The text to match.
* @param {string} matchRegexp - The text to match.
* @returns {boolean} Returns true if the element contains the specified text, otherwise false.
*/
const elementContainsText = (element, textMatch) => {
if (!element || !textMatch) {
const doesElementContainText = (element, matchRegexp) => {
const { textContent } = element;
if (!textContent) {
return false;
}
const elementText = element.textContent;
return parsedTextToMatch.test(elementText);
return matchRegexp.test(textContent);
};

/**
Expand Down Expand Up @@ -285,7 +285,7 @@ export function trustedClickElement(source, selectors, extraMatch = '', delay =
}
// Skip already clicked elements
if (!elementObj.clicked) {
if (parsedTextToMatch && !elementContainsText(elementObj.element, parsedTextToMatch)) {
if (textMatchRegexp && !doesElementContainText(elementObj.element, textMatchRegexp)) {
continue;
}
elementObj.element.click();
Expand Down

0 comments on commit a47011e

Please sign in to comment.