-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (35 loc) · 1.18 KB
/
script.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
31
32
33
34
35
36
37
38
const btn = document.querySelector('.changeColorBtn');
const backgroundColor = document.querySelector('.backgroundColor');
const colorGrid = document.querySelector('.colorGrid');
const colorValue = document.querySelector('.colorValue');
btn.addEventListener('click', async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript(
{
target: { tabId: tab.id },
function: pickColor,
},
async (injectionResults) => {
const [data] = injectionResults;
if (data.result) {
const color = data.result.sRGBHex;
backgroundColor.style.backgroundColor=color;
colorGrid.style.backgroundColor = color;
colorValue.innerText = color;
try {
await navigator.clipboard.writeText(color);
} catch (err) {
console.error(err);
}
}
}
);
});
async function pickColor() {
try {
const eyeDropper = new EyeDropper();
return await eyeDropper.open();
} catch (err) {
console.error(err);
}
}