Skip to content

Commit

Permalink
chore: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Nov 21, 2024
1 parent 7ba8e49 commit 886809e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 50 deletions.
21 changes: 12 additions & 9 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions src/Form/FormAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,25 @@ class FormAnalyzer {
}

/**
* Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix.
* If it does, it checks if it contains an anchor element inside.
* Function that checks if the element is an external link or a custom web element that
* encapsulates a link.
* @param {any} el
* @returns
* @returns {boolean}
*/
isCustomWebElementLink(el) {
isElementExternalLink(el) {
// Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix.
// If it does, it checks if it contains an anchor element inside.
const tagName = el.nodeName.toLowerCase();
const isCustomElement = customElements != null && customElements.get(tagName) != null;
return isCustomElement && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0;
const isCustomWebElementLink =
customElements.get(tagName) != null && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0;

// if an external link matches one of the regexes, we assume the match is not pertinent to the current form
return (
(el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') ||
(el.getAttribute('role') || '').toUpperCase() === 'LINK' ||
el.matches('button[class*=secondary]') ||
isCustomWebElementLink
);
}

evaluateElement(el) {
Expand Down Expand Up @@ -270,13 +280,7 @@ class FormAnalyzer {
this.updateSignal({ string, strength, signalType: `button: ${string}`, shouldFlip });
return;
}
// if an external link matches one of the regexes, we assume the match is not pertinent to the current form
if (
(el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') ||
(el.getAttribute('role') || '').toUpperCase() === 'LINK' ||
el.matches('button[class*=secondary]') ||
this.isCustomWebElementLink(el)
) {
if (this.isElementExternalLink(el)) {
let shouldFlip = true;
let strength = 1;
// Don't flip forgotten password links
Expand Down
2 changes: 1 addition & 1 deletion src/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class DefaultScanner {

if (element.parentElement) {
element = element.parentElement;
// check if current element is the only child of the parent, and increase traversal only then
// If the parent is a redundant component (only contains a single element or is a shadowRoot) do not increase the traversal count.
if (element.childElementCount > 1) {
const inputs = element.querySelectorAll(this.matching.cssSelector('formInputsSelector'));
const buttons = element.querySelectorAll(this.matching.cssSelector('submitButtonSelector'));
Expand Down
21 changes: 12 additions & 9 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 886809e

Please sign in to comment.