mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 06:48:37 +02:00
29 lines
712 B
JavaScript
29 lines
712 B
JavaScript
/*
|
|
Listen for clicks in the popup.
|
|
|
|
If the click is not on one of the beasts, return early.
|
|
|
|
Otherwise, the text content of the node is the name of the beast we want.
|
|
|
|
Inject the "beastify.js" content script in the active tab.
|
|
|
|
Then get the active tab and send "beastify.js" a message
|
|
containing the chosen beast's name.
|
|
*/
|
|
document.addEventListener("click", function(e) {
|
|
if (!e.target.classList.contains("beast")) {
|
|
return;
|
|
}
|
|
|
|
var chosenBeast = e.target.textContent;
|
|
|
|
chrome.tabs.executeScript(null, {
|
|
file: "/content_scripts/beastify.js"
|
|
});
|
|
|
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
|
chrome.tabs.sendMessage(tabs[0].id, {beast: chosenBeast});
|
|
});
|
|
|
|
});
|