diff --git a/beastify/button/LICENSE b/beastify/button/LICENSE index f202e45..c3727aa 100644 --- a/beastify/button/LICENSE +++ b/beastify/button/LICENSE @@ -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/. diff --git a/beastify/button/popup/choose_beast.js b/beastify/button/popup/choose_beast.js deleted file mode 100644 index 10be1f1..0000000 --- a/beastify/button/popup/choose_beast.js +++ /dev/null @@ -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}); - }); - } - -}); diff --git a/beastify/content_scripts/beastify.js b/beastify/content_scripts/beastify.js index 71226b3..ab28332 100644 --- a/beastify/content_scripts/beastify.js +++ b/beastify/content_scripts/beastify.js @@ -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) { diff --git a/beastify/manifest.json b/beastify/manifest.json index a406a7f..c25e853 100644 --- a/beastify/manifest.json +++ b/beastify/manifest.json @@ -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": [ diff --git a/beastify/button/popup/choose_beast.css b/beastify/popup/choose_beast.css similarity index 100% rename from beastify/button/popup/choose_beast.css rename to beastify/popup/choose_beast.css diff --git a/beastify/button/popup/choose_beast.html b/beastify/popup/choose_beast.html similarity index 100% rename from beastify/button/popup/choose_beast.html rename to beastify/popup/choose_beast.html diff --git a/beastify/popup/choose_beast.js b/beastify/popup/choose_beast.js new file mode 100644 index 0000000..a565d8f --- /dev/null +++ b/beastify/popup/choose_beast.js @@ -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}); + }); + } + +});