Skip to content

Commit

Permalink
code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmilosev committed Nov 25, 2019
1 parent ab882e7 commit 0211b51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// 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"
});
});
});

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 => `<a href="${img}" target="_blank"><img src="${img}"/></a>`
)
: null;
if (status) {
app.innerHTML = request.results.imageSource
.map(img => `<a href="${img}" target="_blank"><img src="${img}"/></a>`)
.join(" ");
}
}
});
4 changes: 2 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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
}
});
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,6 +63,7 @@
padding: 5px;
justify-content: space-evenly;
}

.ebay-klein__result a {
margin: 5px;
width: 45%;
Expand Down

0 comments on commit 0211b51

Please sign in to comment.