-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (35 loc) · 1.19 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
let red = 0;
let green = 0;
let blue = 0;
let isgenerating = false;
let interval;
//
document.querySelector('.container').addEventListener('click', () => {
if (isgenerating) {
clearInterval(interval)
isgenerating = false
document.querySelector('.container')
.innerHTML = `<p>rgb(${red}, ${green}, ${blue})<br>🖇</p>`;
const rgb = `rgb(${red}, ${green}, ${blue})`;
const textarea = document.createElement('textarea');
textarea.value = rgb;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
} else {
isgenerating = true
interval = setInterval(() => {
red = Math.round((Math.random()) * 255);
green = Math.round((Math.random()) * 255);
blue = Math.round((Math.random()) * 255);
document.body.style.
backgroundColor = `rgb(${red}, ${green}, ${blue})`;
document.querySelector('.container')
.innerHTML =
`red<span>${red}</span><br>
green<span>${green}</span><br>
blue<span>${blue}</span>`
}, 1000);
}
})