From a4936f521575b0978a3564b5df69d7947d484345 Mon Sep 17 00:00:00 2001 From: Michal Wozniak <2554268w@student.gla.ac.uk> Date: Mon, 13 Jun 2022 00:04:50 +0100 Subject: [PATCH] Undone whitespace --- beastify/popup/choose_beast.js | 131 +++++++++++++++++---------------- 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/beastify/popup/choose_beast.js b/beastify/popup/choose_beast.js index e529693..71f9adf 100644 --- a/beastify/popup/choose_beast.js +++ b/beastify/popup/choose_beast.js @@ -11,70 +11,71 @@ const hidePage = `body > :not(.beastify-image) { * the content script in the page. */ function listenForClicks() { - document.addEventListener("click", (e) => { + document.addEventListener("click", (e) => { - /** - * Given the name of a beast, get the URL to the corresponding image. - */ - function beastNameToURL(beastName) { - switch (beastName) { - case "Frog": - return browser.runtime.getURL("beasts/frog.jpg"); - case "Snake": - return browser.runtime.getURL("beasts/snake.jpg"); - case "Turtle": - return browser.runtime.getURL("beasts/turtle.jpg"); - } - } + /** + * Given the name of a beast, get the URL to the corresponding image. + */ + function beastNameToURL(beastName) { + switch (beastName) { + case "Frog": + return browser.runtime.getURL("beasts/frog.jpg"); + case "Snake": + return browser.runtime.getURL("beasts/snake.jpg"); + case "Turtle": + return browser.runtime.getURL("beasts/turtle.jpg"); + } + } - /** - * Insert the page-hiding CSS into the active tab, - * then get the beast URL and - * send a "beastify" message to the content script in the active tab. - */ - function beastify(tabs) { - browser.tabs.insertCSS({ code: hidePage }).then(() => { - let url = beastNameToURL(e.target.textContent); - browser.tabs.sendMessage(tabs[0].id, { - command: "beastify", - beastURL: url - }); - }); - } + /** + * Insert the page-hiding CSS into the active tab, + * then get the beast URL and + * send a "beastify" message to the content script in the active tab. + */ + function beastify(tabs) { + browser.tabs.insertCSS({code: hidePage}).then(() => { + let url = beastNameToURL(e.target.textContent); + browser.tabs.sendMessage(tabs[0].id, { + command: "beastify", + beastURL: url + }); + }); + } - /** - * Remove the page-hiding CSS from the active tab, - * send a "reset" message to the content script in the active tab. - */ - function reset(tabs) { - browser.tabs.removeCSS({ code: hidePage }).then(() => { - browser.tabs.sendMessage(tabs[0].id, { - command: "reset", - }); - }); - } + /** + * Remove the page-hiding CSS from the active tab, + * send a "reset" message to the content script in the active tab. + */ + function reset(tabs) { + browser.tabs.removeCSS({code: hidePage}).then(() => { + browser.tabs.sendMessage(tabs[0].id, { + command: "reset", + }); + }); + } - /** - * Just log the error to the console. - */ - function reportError(error) { - console.error(`Could not beastify: ${error}`); - } + /** + * Just log the error to the console. + */ + function reportError(error) { + console.error(`Could not beastify: ${error}`); + } - /** - * Get the active tab, - * then call "beastify()" or "reset()" as appropriate. - */ - if (e.target.classList.contains("beast")) { - browser.tabs.query({ active: true, currentWindow: true }) - .then(beastify) - .catch(reportError); - } else if (e.target.classList.contains("reset")) { - browser.tabs.query({ active: true, currentWindow: true }) - .then(reset) - .catch(reportError); - } - }); + /** + * Get the active tab, + * then call "beastify()" or "reset()" as appropriate. + */ + if (e.target.classList.contains("beast")) { + browser.tabs.query({active: true, currentWindow: true}) + .then(beastify) + .catch(reportError); + } + else if (e.target.classList.contains("reset")) { + browser.tabs.query({active: true, currentWindow: true}) + .then(reset) + .catch(reportError); + } + }); } /** @@ -82,9 +83,9 @@ function listenForClicks() { * Display the popup's error message, and hide the normal UI. */ function reportExecuteScriptError(error) { - document.querySelector("#popup-content").classList.add("hidden"); - document.querySelector("#error-content").classList.remove("hidden"); - console.error(`Failed to execute beastify content script: ${error.message}`); + document.querySelector("#popup-content").classList.add("hidden"); + document.querySelector("#error-content").classList.remove("hidden"); + console.error(`Failed to execute beastify content script: ${error.message}`); } /** @@ -92,6 +93,6 @@ function reportExecuteScriptError(error) { * and add a click handler. * If we couldn't inject the script, handle the error. */ -browser.tabs.executeScript({ file: "/content_scripts/beastify.js" }) - .then(listenForClicks) - .catch(reportExecuteScriptError); \ No newline at end of file +browser.tabs.executeScript({file: "/content_scripts/beastify.js"}) +.then(listenForClicks) +.catch(reportExecuteScriptError);