| 1 |
// Initialize butotn with users's prefered color |
| 2 |
let changeColor = document.getElementById("changeColor"); |
| 3 |
|
| 4 |
chrome.storage.sync.get("color", ({ color }) => { |
| 5 |
changeColor.style.backgroundColor = color; |
| 6 |
}); |
| 7 |
|
| 8 |
// When the button is clicked, inject setPageBackgroundColor into current page |
| 9 |
changeColor.addEventListener("click", async () => { |
| 10 |
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); |
| 11 |
|
| 12 |
chrome.scripting.executeScript({ |
| 13 |
target: { tabId: tab.id }, |
| 14 |
function: setPageBackgroundColor, |
| 15 |
}); |
| 16 |
}); |
| 17 |
|
| 18 |
// The body of this function will be execuetd as a content script inside the |
| 19 |
// current page |
| 20 |
function setPageBackgroundColor() { |
| 21 |
chrome.storage.sync.get("color", ({ color }) => { |
| 22 |
document.body.style.backgroundColor = color; |
| 23 |
}); |
| 24 |
} |