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,24 +112,22 @@
const eventName = parentElement.getAttribute(eventNameAttribute); const eventName = parentElement.getAttribute(eventNameAttribute);
if (!eventName) return; if (!eventName) return;
if (parentElement.tagName === 'A') { if (parentElement.tagName === 'BUTTON') {
return trackElement(parentElement);
}
if (parentElement.tagName === 'A' && href) {
const external = const external =
target === '_blank' || target === '_blank' ||
e.ctrlKey || e.ctrlKey ||
e.shiftKey || e.shiftKey ||
e.metaKey || e.metaKey ||
(e.button && e.button === 1); (e.button && e.button === 1);
if (!external) e.preventDefault();
if (eventName && href) { return trackElement(parentElement).then(() => {
if (!external) e.preventDefault(); if (!external) {
return trackElement(parentElement).then(() => { (target === '_top' ? top.location : location).href = href;
if (!external) { }
(target === '_top' ? top.location : location).href = href; });
}
});
}
} else if (parentElement.tagName === 'BUTTON') {
return trackElement(parentElement);
} }
}, },
true, true,