-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
34 lines (29 loc) · 1.13 KB
/
main.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
var main = function (highlight = true) {
const getRandomColor = function (alpha = '') {
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
return "#" + randomColor + alpha;
}
const divs = document.getElementsByTagName('div');
const divsInitial = [];
if (divsInitial.length <= 0) {
for (let i = 0; i < divs.length; i++) {
divsInitial[i] = divs[i];
}
}
const changeDivColor = function () {
for (let i = 0; i < divs.length; i++) {
const randomColor = getRandomColor();
divs[i].style.backgroundColor = randomColor + '88';
divs[i].style.border = 'solid ' + randomColor + 'ff';
}
}
if (highlight) { changeDivColor(); }
const restoreDivColor = function () {
for (let i = 0; i < divs.length; i++) {
divs[i].style.backgroundColor = divsInitial[i].style.backgroundColor ? divsInitial[i].style.backgroundColor : '';
divs[i].style.border = divsInitial[i].style.border ? divsInitial[i].style.border : '';
}
}
if (!highlight) { restoreDivColor(); }
}
main();