-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
79 lines (62 loc) · 2.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
window.addEventListener('DOMContentLoaded', () => {
const mainCont = document.getElementById("mainCont");
const buttonCont = document.getElementById("picker_btn_cont");
const resultList = document.getElementById("result");
const GiveMetheChild = (color, msg) => {
const errorLabel = document.createElement("p")
errorLabel.setAttribute("class", "errorLabel")
errorLabel.style.backgroundColor = color
errorLabel.innerText = msg
mainCont.appendChild(errorLabel)
setTimeout(() => {
mainCont.removeChild(errorLabel)
}, 2000)
}
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
const tab = tabs[0]
if (tab.url === undefined || tab.url.indexOf('chrome') == 0) {
buttonCont.innerHTML = '<span style="font-family: lobster, sans-serif">Eye Dropper</span> can\'t access <i>Chrome pages</i>'
}
else if (tab.url.indexOf('file') === 0) {
buttonCont.innerHTML = '<span style="font-family: lobster, sans-serif">Eye Dropper</span> can\'t access <i>local pages</i>'
} else {
const button = document.createElement("button")
button.setAttribute("id", "picker_btn")
button.innerText = "Pick Color from webpage"
button.addEventListener("click", () => {
if (!window.EyeDropper) {
GiveMetheChild("#ad5049", 'Your browser does not support the EyeDropper API')
return
}
chrome.tabs.sendMessage(
tabs[0].id,
{ from: "popup", query: "eye_dropper_clicked" }
);
window.close()
})
buttonCont.appendChild(button)
}
});
chrome.storage.local.get("color_hex_code", (resp) => {
if (resp.color_hex_code && resp.color_hex_code.length > 0) {
resp.color_hex_code.forEach(hexCode => {
const liElem = document.createElement("li")
liElem.innerText = hexCode
liElem.style.backgroundColor = hexCode
liElem.addEventListener("click", () => {
navigator.clipboard.writeText(hexCode);
GiveMetheChild("#e19526", "Hex code is copied to clipboard!")
})
resultList.appendChild(liElem)
})
const ClearButton = document.createElement("button")
ClearButton.innerText = "Clear Memory"
ClearButton.setAttribute("id", "ClearButton")
ClearButton.addEventListener("click", () => {
chrome.storage.local.remove("color_hex_code")
window.close()
})
mainCont.appendChild(ClearButton)
}
})
})