Files
webextensions-examples/notify-link-clicks-i18n/content-script.js
2016-01-14 15:06:44 -08:00

21 lines
530 B
JavaScript

/*
Add notifyExtension() as a listener to click events.
*/
window.addEventListener("click", notifyExtension);
/*
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");
chrome.runtime.sendMessage({"url": target.href});
}