diff --git a/background.js b/background.js index f029b40..8df2903 100644 --- a/background.js +++ b/background.js @@ -1,28 +1,25 @@ -// background.js -document.addEventListener("DOMContentLoaded", function() { - const button = document.getElementById("loadImages"); - button.addEventListener("click", function() { - chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { - var activeTab = tabs[0]; - chrome.tabs.sendMessage(activeTab.id, { - message: "FETCH_IMAGE" - }); +// Run script each time Chrome extension icon clicked +document.addEventListener("DOMContentLoaded", () => { + chrome.tabs.query({ active: true, currentWindow: true }, tabs => { + var activeTab = tabs[0]; + chrome.tabs.sendMessage(activeTab.id, { + message: "FETCH_IMAGE" }); }); }); -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 containerImg = document.querySelector(".ebay-klein__main__image"); + const noImageMsg = document.querySelector(".ebay-klein__no-image"); - status ? (containerImg.style.display = "none") : null; - console.log(app); - app.innerHTML = status - ? request.results.imageSource.map( - img => `` - ) - : `
There's no images
`; + status ? (noImageMsg.style.display = "none") : 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/image.svg b/image.svg index bdaa345..2727e8b 100644 --- a/image.svg +++ b/image.svg @@ -1,2 +1,50 @@ - - + + + diff --git a/index.html b/index.html index c0b03b5..e4be704 100755 --- a/index.html +++ b/index.html @@ -15,9 +15,17 @@
+ Sorry, it seems there's no images.
Be sure you are on the
+ ebay-kleinanzeigen
+ AD page!
+