-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (53 loc) · 2.09 KB
/
Copy pathscript.js
File metadata and controls
62 lines (53 loc) · 2.09 KB
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
const symbols = "0123456789abcdef"
let colorBtn = document.querySelector(".color");
let gradientBtn = document.querySelector(".gradient");
let body = document.querySelector("body");
let container = document.querySelector(".syntax");
let copied = document.querySelector(".copied");
RandomGradientGenerator();
colorBtn.addEventListener("click", RandomColorGenerator)
gradientBtn.addEventListener("click", RandomGradientGenerator)
function RandomGradientGenerator() {
copied.classList.remove("copiedAnimation");
let NewCode = [];
symbolsArr = symbols.split("");
for (let j = 0; j < 3; j++) {
let temp = "#";
for (let i = 0; i < 6; i++) {
temp += symbolsArr[Math.floor(Math.random() * 16)];
}
NewCode.push(temp);
}
let orientation = ["to right", "to bottom", "45deg", "90deg", "75deg", "135deg", "to left", "180deg"]
let RandomDir = orientation[Math.floor(Math.random() * 8)];
console.log(RandomDir);
body.style.backgroundImage = 'linear-gradient(' + RandomDir + ', ' + NewCode[0] + ', ' + NewCode[1] + ", " + NewCode[2] + ')';
let code = ` background-image: linear-gradient(${RandomDir}, ${NewCode[0]} , ${NewCode[1]},${NewCode[2]});`;
const el = document.createElement('textarea');
el.value = code;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
copied.classList.add("copiedAnimation");
container.innerText = code;
}
function RandomColorGenerator() {
copied.classList.remove("copiedAnimation");
body.style.backgroundImage = "none"
let NewCode = "#";
symbolsArr = symbols.split("");
for (let i = 0; i < 6; i++) {
NewCode += symbolsArr[Math.floor(Math.random() * 16)];
}
let code = `background-color: ${NewCode};`
const el = document.createElement('textarea');
el.value = code;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
copied.classList.add("copiedAnimation");
body.style.backgroundColor = NewCode;
container.innerText = code;
}