From 4d5fef442356b9f4e76aea26e019881b70be12e5 Mon Sep 17 00:00:00 2001 From: Mindaugas Jakutis <4mr.minj@gmail.com> Date: Tue, 5 Jan 2016 22:42:10 +0200 Subject: [PATCH 1/2] 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. --- notify-link-clicks/content-script.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/notify-link-clicks/content-script.js b/notify-link-clicks/content-script.js index 43b6f2f..1f0fc94 100644 --- a/notify-link-clicks/content-script.js +++ b/notify-link-clicks/content-script.js @@ -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}); } From 933d5df99d474916352782ed5f47b9741370b408 Mon Sep 17 00:00:00 2001 From: Mindaugas Jakutis <4mr.minj@gmail.com> Date: Tue, 5 Jan 2016 22:42:10 +0200 Subject: [PATCH 2/2] improve link detection in notify-link-clicks-i18n 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. --- notify-link-clicks-i18n/content-script.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/notify-link-clicks-i18n/content-script.js b/notify-link-clicks-i18n/content-script.js index 47899bb..1f0fc94 100644 --- a/notify-link-clicks-i18n/content-script.js +++ b/notify-link-clicks-i18n/content-script.js @@ -1,9 +1,13 @@ window.addEventListener("click", notifyExtension); function notifyExtension(e) { - console.log("content script sending message"); - if (e.target.tagName != "A") { - return; + var target = e.target; + while ((target.tagName != "A" || !target.href) && target.parentNode) { + target = target.parentNode; } - chrome.runtime.sendMessage({"url": e.target.href}); + if (target.tagName != "A") + return; + + console.log("content script sending message"); + chrome.runtime.sendMessage({"url": target.href}); }