-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
47 lines (38 loc) · 1.01 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
45
46
47
let btn = document.querySelector('.colorbtn')
let colorPick = document.querySelector('.colorGrid')
let colorValue = document.querySelector('.colorValue')
let messageBox = document.querySelector('.message')
btn.addEventListener('click', async () => {
let [tab] = await chrome.tabs.query({
active: true,
currentWindow: true,
})
chrome.scripting.executeScript(
{
target: { tabId: tab.id },
function: pickColor,
},
async (result) => {
let [data] = result
if (data.result) {
let color = data.result.sRGBHex
colorPick.style.backgroundColor = color
colorValue.innerText = color
messageBox.innerText = 'color code copy in your clipboard'
try {
await navigator.clipboard.writeText(color)
} catch (error) {
console.log(error)
}
}
},
)
})
async function pickColor() {
try {
let eyeDroper = new EyeDropper()
return await eyeDroper.open()
} catch (error) {
console.log(error)
}
}