From 7d2ba28b0b20fd79bc643c4c1dbbdb28c16dafce Mon Sep 17 00:00:00 2001 From: Will Bamberg Date: Mon, 11 Sep 2017 21:59:52 -0700 Subject: [PATCH] Ensure tabID is unchanged; fix image styles --- beastify/content_scripts/beastify.js | 3 +-- beastify/popup/choose_beast.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/beastify/content_scripts/beastify.js b/beastify/content_scripts/beastify.js index 90efffe..240512e 100644 --- a/beastify/content_scripts/beastify.js +++ b/beastify/content_scripts/beastify.js @@ -35,8 +35,7 @@ function insertBeast(beastURL) { var beastImage = document.createElement("img"); beastImage.setAttribute("src", beastURL); - beastImage.setAttribute("style", "width: 100vw"); - beastImage.setAttribute("style", "height: 100vh"); + beastImage.style.height = "100vh"; document.body.appendChild(beastImage); } diff --git a/beastify/popup/choose_beast.js b/beastify/popup/choose_beast.js index 8fb48dd..d9d4f9f 100644 --- a/beastify/popup/choose_beast.js +++ b/beastify/popup/choose_beast.js @@ -27,23 +27,23 @@ If it's on a button which contains class "clear": */ document.addEventListener("click", (e) => { - function messageBeastify() { - var chosenBeast = e.target.textContent; - var chosenBeastURL = beastNameToURL(chosenBeast); - var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true}); - gettingActiveTab.then((tabs) => { - browser.tabs.sendMessage(tabs[0].id, {beastURL: chosenBeastURL}); + function reportError(error) { + console.error(`Could not beastify: ${error}`); + } + + function beastify(tabs) { + browser.tabs.executeScript(tabs[0].id, { + file: "/content_scripts/beastify.js" + }).then(() => { + var chosenBeast = e.target.textContent; + var url = beastNameToURL(chosenBeast); + browser.tabs.sendMessage(tabs[0].id, {beastURL: url}); }); } - function reportError(error) { - console.error(`Could not inject content script: ${error}`); - } - if (e.target.classList.contains("beast")) { - browser.tabs.executeScript({ - file: "/content_scripts/beastify.js" - }).then(messageBeastify) + browser.tabs.query({active: true, currentWindow: true}) + .then(beastify) .catch(reportError); } else if (e.target.classList.contains("clear")) {