reorganizations

This commit is contained in:
Will Bamberg
2015-09-02 14:07:18 -07:00
parent 979370c3ca
commit 88f703edd6
7 changed files with 36 additions and 24 deletions

View File

@@ -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/.

View File

@@ -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});
});
}
});

View File

@@ -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) {

View File

@@ -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": [

View 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});
});
}
});