-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
102 lines (78 loc) · 2.73 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
document.addEventListener("DOMContentLoaded", () => {
const magicDivSample = `
<div class="dropped-coin-sample drop">
<div class="magic-square simple">
<span></span>
<span></span>
<span></span>
<span></span>
<div class="content"></div>
</div>
</div>
`
const mainButton = document.querySelector('.clicker-button');
mainButton.addEventListener('click', () =>{
randomSquareRespawn(collectGridAndCreateRandomSquare(),magicDivSample);
})
const changeColorBtn = document.querySelector('.change-color-theme');
changeColorBtn.addEventListener('click', () =>{
changeTheme();
})
const logInBtn = document.querySelector('.send-form-button');
logInBtn.addEventListener('click', () =>{
// logIn();
})
const colorArray = ['red', 'blueviolet', '#0066ff','Lime','yellow','orange','Fuchsia','#00ccff','white']
let i = 0;
const changeTheme = () =>{
if(i >= colorArray.length) i=0;
document.documentElement.style.setProperty('--mainColor', colorArray[i]);
i++;
}
const triggerInputs = () => {
const inputsLeft = document.querySelectorAll('.input-left');
inputsLeft.forEach(el => {
el.addEventListener('focusout', () => {
if (el.value !== '') {
el.closest('.input-container').classList.add('up');
} else {
el.closest('.input-container').classList.remove('up');
}
})
})
}
const drawGrid = () =>{
const mainButton = document.querySelector('.clicker-button');
for(let j=0; j<=269; j++){
const newDiv = document.createElement('div');
newDiv.classList.add('one-piece-square');
mainButton.appendChild(newDiv);
}
}
const collectGridAndCreateRandomSquare = () =>{
const divNode = document.querySelectorAll('.one-piece-square');
let divArray = Array.from(divNode);
return divArray
}
const randomSquareRespawn = (divsArray, magicDivSample) =>{
let rand = Math.floor(Math.random() * divsArray.length);
divsArray[rand].insertAdjacentHTML('afterbegin',magicDivSample);
}
// const logIn = async () =>{
// const loginURL = "http://gierka.local/login.php"
// const login = document.getElementById('login-input').value;
// const password = document.getElementById('password-input').value;
// const data = {login, password};
// console.log(data);
// const response = await fetch(loginURL, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(data)
// });
// console.log(response.json());
// };
triggerInputs();
drawGrid();
});