mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
reorganizations
This commit is contained in:
@@ -1 +1 @@
|
||||
The icon "beasts.png" is taken from the IconBeast Lite iconset, and used under the terms of its license, with a link back to the website: http://www.iconbeast.com/free/.
|
||||
The icon "beasts.png" is taken from the IconBeast Lite iconset, and used under the terms of its license (http://www.iconbeast.com/faq/), with a link back to the website: http://www.iconbeast.com/free/.
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
document.addEventListener("click", function(e) {
|
||||
if (! e.target.classList.contains("beast")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var chosenBeast = e.target.textContent;
|
||||
console.log(chosenBeast);
|
||||
|
||||
chrome.tabs.executeScript({
|
||||
file: "content_scripts/beastify.js"
|
||||
}, setBeast);
|
||||
|
||||
function setBeast() {
|
||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
chrome.tabs.sendMessage(tabs[0].id, {beast: chosenBeast});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
// Assign beastify() as a listener for messages from the extension.
|
||||
chrome.runtime.onMessage.addListener(beastify);
|
||||
|
||||
function beastify(request, sender, sendResponse) {
|
||||
@@ -8,7 +8,7 @@ function beastify(request, sender, sendResponse) {
|
||||
images[i].setAttribute("src", beastURL);
|
||||
}
|
||||
|
||||
document.body.style.backgroundImage = "url(" + beastURL + ")";
|
||||
chrome.runtime.onMessage.removeListener(beastify);
|
||||
}
|
||||
|
||||
function beastNameToURL(beastName) {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"browser_action": {
|
||||
"default_icon": "button/beasts.png",
|
||||
"default_title": "Beastify",
|
||||
"default_popup": "button/popup/choose_beast.html"
|
||||
"default_popup": "popup/choose_beast.html"
|
||||
},
|
||||
|
||||
"web_accessible_resources": [
|
||||
|
||||
32
beastify/popup/choose_beast.js
Normal file
32
beastify/popup/choose_beast.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.
|
||||
|
||||
Run the "beastify.js" content script in the active tab, calling setBeast()
|
||||
once the content script has executed.
|
||||
|
||||
Inside setBeast(), get the active tab, then send it a message containing
|
||||
the chosen beast's name. This message will be received by the content script
|
||||
we just executed.
|
||||
*/
|
||||
document.addEventListener("click", function(e) {
|
||||
if (!e.target.classList.contains("beast")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var chosenBeast = e.target.textContent;
|
||||
|
||||
chrome.tabs.executeScript({
|
||||
file: "content_scripts/beastify.js"
|
||||
}, setBeast);
|
||||
|
||||
function setBeast() {
|
||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
chrome.tabs.sendMessage(tabs[0].id, {beast: chosenBeast});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user