-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (45 loc) · 2 KB
/
index.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
const colorScheme = document.querySelector(".color-scheme")
const clrInput = document.getElementById("color-input")
const schemes = document.getElementById("schemes")
const btn = document.getElementById("get-scheme")
btn.addEventListener("click", function(){
let colorsArray = []
const baseClr = clrInput.value
const baseScheme = schemes.value
const clrOne = document.getElementById("color-one")
const clrTwo = document.getElementById("color-two")
const clrThree = document.getElementById("color-three")
const clrFour = document.getElementById("color-four")
const clrFive = document.getElementById("color-five")
const clrOneText = document.getElementById("color-one-text")
const clrTwoText = document.getElementById("color-two-text")
const clrThreeText = document.getElementById("color-three-text")
const clrFourText = document.getElementById("color-four-text")
const clrFiveText = document.getElementById("color-five-text")
fetch(`https://www.thecolorapi.com/scheme?hex=${baseClr.substr(1)}&mode=${baseScheme}&count=5`)
.then(res => res.json())
.then(data => {
for(let color of data.colors) {
colorsArray.push(color["hex"]["value"])
}
clrOne.style.backgroundColor = colorsArray[0]
clrTwo.style.backgroundColor = colorsArray[1]
clrThree.style.backgroundColor = colorsArray[2]
clrFour.style.backgroundColor = colorsArray[3]
clrFive.style.backgroundColor = colorsArray[4]
clrOneText.innerHTML = colorsArray[0]
clrTwoText.innerHTML = colorsArray[1]
clrThreeText.innerHTML = colorsArray[2]
clrFourText.innerHTML = colorsArray[3]
clrFiveText.innerHTML = colorsArray[4]
})})
colorScheme.addEventListener('click', function(e) {
const color = e.target.textContent
const link = e.target
if (!color) {
navigator.clipboard.writeText(link.nextElementSibling.innerHTML)
}
else {
navigator.clipboard.writeText(color)
}
})