diff --git a/background.js b/background.js index ae5501d..8df2903 100644 --- a/background.js +++ b/background.js @@ -1,6 +1,6 @@ // Run script each time Chrome extension icon clicked -document.addEventListener("DOMContentLoaded", function() { - chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { +document.addEventListener("DOMContentLoaded", () => { + chrome.tabs.query({ active: true, currentWindow: true }, tabs => { var activeTab = tabs[0]; chrome.tabs.sendMessage(activeTab.id, { message: "FETCH_IMAGE" @@ -8,18 +8,18 @@ document.addEventListener("DOMContentLoaded", function() { }); }); -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.message === "SHOW_RESULTS") { - const status = request.results.status; + const status = request.results.imageSource.length; const app = document.querySelector(".ebay-klein__result"); const noImageMsg = document.querySelector(".ebay-klein__no-image"); status ? (noImageMsg.style.display = "none") : null; - app.innerHTML = status - ? request.results.imageSource.map( - img => `` - ) - : null; + if (status) { + app.innerHTML = request.results.imageSource + .map(img => ``) + .join(" "); + } } }); diff --git a/content.js b/content.js index 2bebddb..96515bf 100644 --- a/content.js +++ b/content.js @@ -1,4 +1,4 @@ -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.message === "FETCH_IMAGE") { // Extract images from product page or gallery const imageContainer = @@ -9,11 +9,11 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { const imageSource = imageArray.length && imageArray.map(src => src.getAttribute("src")); + console.log(imageSource[0]); // Listener chrome.runtime.sendMessage({ message: "SHOW_RESULTS", results: { - status: imageSource ? true : false, imageSource: imageSource } }); diff --git a/style.css b/style.css index 06d0f23..9d3e785 100644 --- a/style.css +++ b/style.css @@ -45,7 +45,6 @@ background: rgb(255, 255, 255); margin: 8px 0px; } - .ebay-klein__main__image { background: url("image.svg") no-repeat center center; background-size: cover; @@ -64,6 +63,7 @@ padding: 5px; justify-content: space-evenly; } + .ebay-klein__result a { margin: 5px; width: 45%;