-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
44 lines (36 loc) · 1.16 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const btn = document.querySelector(".changeColorBtn");
const colorGrid = document.querySelector(".colorGrid")
const colorValue = document.querySelector(".colorValue");
const copy = document.querySelector(".copy");
btn.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({active : true, currentWindow: true});
console.log(tab);
chrome.scripting.executeScript({
target : {tabId: tab.id},
function : pickColor,
}, async(injectionResults) => {
const [data] = injectionResults;
if(data.result){
const color = data.result.sRGBHex;
colorGrid.style.background = color;
colorValue.innerText = color;
copy.addEventListener("click" , async() => {
try {
await navigator.clipboard.writeText(color);
} catch (error) {
console.log(error);
}
})
copy.style.display = "block";
console.log(colorGrid);
}
});
});
async function pickColor(){
try {
const eyeDropper = new EyeDropper();
return await eyeDropper.open();
} catch (err) {
console.log(err);
}
}