forked from zlrs/color-customizer-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
27 lines (25 loc) · 908 Bytes
/
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
// This is a background script.
// It runs in the background!
// Essentially, it is a service worker, in newest standard (manifest V3)
// Colors: http://zhongguose.com
function setBackgroundColor(r, g, b) {
let colorStyle = "rgb(" + r + "," + g + "," + b + ")";
console.log("Set background color: ", colorStyle);
document.body.style.backgroundColor = colorStyle;
}
// Change color of active tab on message
chrome.runtime.onMessage.addListener(async function(message, sender, sendResponse) {
let {r, g, b} = message;
if (typeof(r) === 'number' &&
typeof(g) === 'number' &&
typeof(b) === 'number') {
let tabs = await chrome.tabs.query({ active: true, currentWindow: true });
let activeTab = tabs[0];
chrome.scripting.executeScript({
target: { tabId: activeTab.id },
function: setBackgroundColor,
args: [r, g, b]
});
}
}
);