forked from TylerPohn/chromeExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
29 lines (26 loc) · 1.04 KB
/
popup.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
// Initialize butotn with users's prefered image
let changeImage = document.getElementById("changeImage");
// let imgURL = chrome.runtime.getURL("/images/comboSkeleton.gif");
//button style
chrome.storage.sync.get("image", ({ image }) => {
const img = document.createElement('img');
img.src = chrome.runtime.getURL('/images/skeleton.jpg');
changeImage.style.backgroundImage = img;
});
// When the button is clicked, inject setPageBackgroundimage into current page
changeImage.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: setPageBackgroundImage,
});
});
// The body of this function will be execuetd as a content script inside the
// current page
function setPageBackgroundImage() {
chrome.storage.sync.get("image", ({ image }) => {
const img = document.createElement('img');
img.src = chrome.runtime.getURL('/images/skeleton.jpg');
document.body.style.backgroundImage = img;
});
}