Files
webextensions-examples/notify-link-clicks-i18n/content-script.js
rebloor 82217a05bc Replace var with let in examples (#484)
* Replace var with let in examples

store-collected-images/webextension-plain/deps/uuidv4.js

* Reverted third–party code
2022-08-11 04:27:28 +12:00

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) {
let 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);