improve link detection in notify-link-clicks

Original approach is a bit too naive and misses all links
that contain other elements which can grab mouse clicks.
E. g. simple target checking fails on the grid @ mozilla.org.

Traversing up the tree to look for valid links fixes this problem.
This commit is contained in:
Mindaugas Jakutis
2016-01-05 22:42:10 +02:00
parent 8de8946ef2
commit 4d5fef4423

View File

@@ -1,9 +1,13 @@
window.addEventListener("click", notifyExtension);
function notifyExtension(e) {
if (e.target.tagName != "A") {
return;
var target = e.target;
while ((target.tagName != "A" || !target.href) && target.parentNode) {
target = target.parentNode;
}
if (target.tagName != "A")
return;
console.log("content script sending message");
chrome.runtime.sendMessage({"url": e.target.href});
chrome.runtime.sendMessage({"url": target.href});
}