Script simplification: Greatly clarify element tracking logic

This commit is contained in:
Ali Khaleqi Yekta 2025-05-04 12:17:08 +03:30
parent 671dcfceb5
commit b26fc15fa0
No known key found for this signature in database
GPG key ID: 8CE90F8CC149DE8C

View file

@ -112,15 +112,16 @@
const eventName = parentElement.getAttribute(eventNameAttribute);
if (!eventName) return;
if (parentElement.tagName === 'A') {
if (parentElement.tagName === 'BUTTON') {
return trackElement(parentElement);
}
if (parentElement.tagName === 'A' && href) {
const external =
target === '_blank' ||
e.ctrlKey ||
e.shiftKey ||
e.metaKey ||
(e.button && e.button === 1);
if (eventName && href) {
if (!external) e.preventDefault();
return trackElement(parentElement).then(() => {
if (!external) {
@ -128,9 +129,6 @@
}
});
}
} else if (parentElement.tagName === 'BUTTON') {
return trackElement(parentElement);
}
},
true,
);