-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
58 lines (52 loc) · 1.36 KB
/
script.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
strips = document.querySelectorAll('.strips');
c_tags = document.querySelectorAll('h3');
strips.forEach(changecolor);
strips.forEach(fillcolor);
c_tags.forEach(copycolor);
document.body.onkeydown = function(e){
if(e.keyCode == 32 && e.target == document.body){
e.preventDefault();
strips.forEach(changecolor);
}
}
function fillcolor(box){
box.addEventListener("click", function() {
changecolor(box);
});
}
function changecolor(box){
generateColor();
box.style.backgroundColor = hex;
c= box.children;
c[0].innerHTML=hex;
}
function copycolor(tag) {
tag.addEventListener("click", function(e){
var text = tag.innerText;
var elem = document.createElement("textarea");
document.body.appendChild(elem);
elem.value = text;
elem.select();
document.execCommand("copy");
document.body.removeChild(elem);
e.stopPropagation();
});
}
function generateColor(){
r=Math.ceil((Math.random())*255);
g=Math.ceil((Math.random())*255);
b=Math.ceil((Math.random())*255);
rh=Number(r).toString(16);
if (r<16){
rh = "0"+rh;
}
gh=Number(g).toString(16);
if (g<16){
gh = "0"+gh;
}
bh=Number(b).toString(16);
if (b<16){
bh = "0"+bh;
}
hex="#"+rh+gh+bh
}