mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
21 lines
531 B
JavaScript
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);
|