-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
30 lines (27 loc) · 1.01 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Run script each time Chrome extension icon clicked
document.addEventListener("DOMContentLoaded", () => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
const activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {
message: "FETCH_IMAGE"
});
});
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.message === "SHOW_RESULTS") {
const status = request.results.imageSource.length;
const app = document.querySelector(".ebay-klein__result");
const noImageMsg = document.querySelector(".ebay-klein__no-image");
const spinner = document.querySelector(".ebay-klein__spinner");
if (status) {
spinner.style.display = "none";
noImageMsg.style.display = "none";
app.innerHTML = request.results.imageSource
.map(img => `<a href="${img}" target="_blank"><img src="${img}"/></a>`)
.join(" ");
} else {
spinner.style.display = "none";
noImageMsg.style.display = "block";
}
}
});