-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
31 lines (27 loc) · 1019 Bytes
/
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
// constants
const color = document.getElementById("input");
const p1 = document.getElementById("colorCode");
const p2 = document.getElementById("result");
const CopyButton = document.getElementById("copyColorClipboard");
// select color
color.addEventListener("input", (e) => {
console.log(e.target.value);
// document.body.style.backgroundColor = e.target.value;
document.getElementById("colorCode").style.backgroundColor = e.target.value;
p1.innerHTML = e.target.value;
p2.innerHTML = "Color Code Captured!..";
});
//click event for input color element
// document.getElementById("input").dispatchEvent(new Event("click"));
// copy color code to clipboard
CopyButton.addEventListener("click", () => {
navigator.clipboard.writeText(
document.getElementById("colorCode").textContent
);
//copy button messages
if (p1.textContent.startsWith("#")) {
p2.innerHTML = `Copied! </br> Now, you can paste HEX color code...`;
} else {
p2.innerHTML = "Error: Please pick a color!...";
}
});