From cb877de1ede5b3f17ece62030054293fc682483a Mon Sep 17 00:00:00 2001 From: EvolvedCode Date: Sat, 15 Oct 2016 14:18:31 +0300 Subject: [PATCH] Almost done --- beastify/content_scripts/clear.js | 27 ------------- beastify/popup/choose_beast.css | 4 +- beastify/popup/choose_beast.html | 3 +- beastify/popup/choose_beast.js | 65 +++++-------------------------- 4 files changed, 13 insertions(+), 86 deletions(-) delete mode 100644 beastify/content_scripts/clear.js diff --git a/beastify/content_scripts/clear.js b/beastify/content_scripts/clear.js deleted file mode 100644 index 0f2c2dd..0000000 --- a/beastify/content_scripts/clear.js +++ /dev/null @@ -1,27 +0,0 @@ -/* -clear(): -* either reloads or clears the page depending on the request -*/ -function clear(request, sender, sendResponse) { - switch (request.type){ - case "Reload": - location.reload(); - break; - case "Blank": - removeEverything(); - break; - } - - chrome.runtime.onMessage.removeListener(clear); -} - -function removeEverything() { - while (document.body.firstChild) { - document.body.firstChild.remove(); - } -} - -/* -Assign clear() as a listener for messages from the extension. -*/ -chrome.runtime.onMessage.addListener(clear); diff --git a/beastify/popup/choose_beast.css b/beastify/popup/choose_beast.css index 1b5aef6..5f6f456 100644 --- a/beastify/popup/choose_beast.css +++ b/beastify/popup/choose_beast.css @@ -19,11 +19,11 @@ html, body { } .clear { - background-color: #E74C3C; + background-color: #FBFBC9; } .clear:hover { - background-color: #C0392B; + background-color: #EAEA9D; } .inactive { diff --git a/beastify/popup/choose_beast.html b/beastify/popup/choose_beast.html index dfd3043..5984a4e 100644 --- a/beastify/popup/choose_beast.html +++ b/beastify/popup/choose_beast.html @@ -10,8 +10,7 @@
Frog
Turtle
Snake
-
Reload
-
Blank
+
Reset
diff --git a/beastify/popup/choose_beast.js b/beastify/popup/choose_beast.js index c4787e4..b691e1a 100644 --- a/beastify/popup/choose_beast.js +++ b/beastify/popup/choose_beast.js @@ -1,30 +1,6 @@ /* Given the name of a beast, get the URL to the corresponding image. */ - -/* -updateButtons(): -* looks in the self.beast variable to see if the page is beastified or not, -* updates the buttons with the inactive property if the page is not beastified -* does tho opposite in the case it is beastified -*/ -function updateButtons() { - if (self.beast) { - var list = document.getElementsByClassName("clear"); - for (var i = 0; i < list.length; i++) { - list[i].className = "button clear"; - } - } - else { - var list = document.getElementsByClassName("clear"); - for (var i = 0; i < list.length; i++) { - list[i].className = "button clear inactive"; - } - } -} - -updateButtons(); - function beastNameToURL(beastName) { switch (beastName) { case "Frog": @@ -36,24 +12,18 @@ function beastNameToURL(beastName) { } } + /* Listen for clicks in the popup. -If the click is on one of the beast buttons: - The text content of the node is the name of the beast we want. +If the click is not on one of the beasts, return early. - Inject the "beastify.js" content script in the active tab. +Otherwise, the text content of the node is the name of the beast we want. - Then get the active tab and send "beastify.js" a message - containing the URL to the chosen beast's image. +Inject the "beastify.js" content script in the active tab. -Else if the click is on one of the clear buttons: - The text content of the node is the clear method we want. - - Inject the "clear.js" content script in the active tab. - - Then get the active tab and send "clear.js" a message - containing the clear method. +Then get the active tab and send "beastify.js" a message +containing the URL to the chosen beast's image. */ document.addEventListener("click", function(e) { if (e.target.classList.contains("beast")) { @@ -67,26 +37,11 @@ document.addEventListener("click", function(e) { chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, {beastURL: chosenBeastURL}); }); - - self.beast = true; - - updateButtons(); + return; } else if (e.target.classList.contains("clear")) { - var chosenMethod = e.target.textContent; - - chrome.tabs.executeScript(null, { - file: "/content_scripts/clear.js" - }); - - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, {type: chosenMethod}); - }); - - self.beast = false; - - updateButtons(); + chrome.tabs.reload(); + + return; } - - return; });