Files
webextensions-examples/notify-link-clicks-i18n/content-script.js

21 lines
531 B
JavaScript

/*
If the click was on a link, send a message to the background page.
The message contains the link's URL.
*/
function notifyExtension(e) {
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");
browser.runtime.sendMessage({"url": target.href});
}
/*
Add notifyExtension() as a listener to click events.
*/
window.addEventListener("click", notifyExtension);