-
Notifications
You must be signed in to change notification settings - Fork 0
/
troll.js
104 lines (92 loc) · 2.11 KB
/
troll.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
103
104
;(function(){
// lets start trolling
/**
* random int in interval
* https://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript
* @param {Number} a
* @param {Number} b
* @return {Number}
*/
const randomInt = (min,max) => Math.floor(Math.random()*(max-min+1)+min);
/**
* colors
* @type {Array}
*/
const colors = [
'blue',
'red',
'green',
'black'
];
/**
* operators
* @type {Array}
*/
const op = [
'-',
'+'
];
/**
* all elements
* @type {Array}
*/
const elements = [].slice.call(document.querySelectorAll('*'));
/**
* sets a background color
* @param {Node}
*/
const setBackground = (el) => {
el.style.backgroundColor = colors[randomInt(0, 3)];
};
/**
* sets a color
* @param {Node}
*/
const setColor = (el) => {
el.style.color = colors[randomInt(0, colors.length - 1)];
};
/**
* sets a background color
* @param {Node}
*/
const setOpacity = (el) => {
el.style.opacity = randomInt(0, 1).toString();
};
/**
* sets a font size
* @param {Node}
*/
const setFontSize = (el) => {
el.style.fontSize = randomInt(1, 50).toString() + 'px';
};
/**
* sets transform translate
* @param {Node}
*/
const setTransform = (el) => {
el.style.transform = `translate(${op[randomInt(0, op.length -1)].toString()}%)`;
};
/**
* functions we call
* @type {Array}
*/
const funcs = [
setBackground,
setColor,
setOpacity,
setFontSize
];
/**
* run
*/
const run = (fn, wait) => {
setTimeout(function(){
const el = elements[randomInt(0, elements.length - 1)];
fn(el);
console.log(el);
run(funcs[randomInt(0, funcs.length - 1)], randomInt(10, 30));
}, wait * 1000);
};
// init :)
run(funcs[randomInt(0, funcs.length - 1)], 1);
}());