-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
73 lines (61 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
// Credit for the original script goes to https://www.reddit.com/r/javascript/comments/7f9812/i_am_the_best_webdev/
var fruitOptions = ['🍇', '🍈', '🍉', '🍊', '🍋', '🍌', '🍍', '🍎', '🍏', '🍐', '🍑', '🍒', '🍓', '🥝', '🍅', '🥑', '🍆', '🥔', '🌽', '🌮'];
var singleFruit = fruitOptions[Math.ceil(Math.random() * fruitOptions.length - 1)];
var multi = false;
function createNewFruit() {
setTimeout(createNewFruit, Math.random() * 10);
let el = document.createElement(`div`);
el.innerHTML = multi ? fruitOptions[Math.ceil(Math.random() * fruitOptions.length - 1)] : singleFruit;
el.style.position = `absolute`;
el.style.zIndex = 999999;
el.style.fontSize = (((Math.random() * 48) | 0) + 16) + `px`;
el.style.left = ((Math.random() * innerWidth) | 0) + `px`;
el.style.top = ((Math.random() * (innerHeight + pageYOffset)) | 0) + `px`;
//el.style.opacity = `.85`;
el.style.pointerEvents = `none`;
document.body.appendChild(el);
}
(function () {
// Button wrapper
var button_wrapper = document.createElement('div');
button_wrapper.id = 'button_wrapper';
button_wrapper.style.position = 'fixed';
button_wrapper.style.bottom = '30px';
button_wrapper.style.right = '30px';
button_wrapper.style.zIndex = '1000000';
button_wrapper.style.cursor = 'pointer';
button_wrapper.style.backgroundColor = 'dodgerblue';
button_wrapper.style.padding = '1rem';
button_wrapper.style.borderRadius = '1rem';
button_wrapper.style.color = 'white';
button_wrapper.style.fontFamily = 'sans-serif';
button_wrapper.style.fontSize = '16px';
button_wrapper.style["-webkit-font-smoothing"] = 'antialiased';
//button_wrapper.style.display = 'none';
// Random button
var random_button = document.createElement('div');
random_button.innerHTML = 'Random';
random_button.onclick = function () {
multi = false;
singleFruit = fruitOptions[Math.ceil(Math.random() * fruitOptions.length - 1)];
this.innerHTML = 'Switch fruit';
createNewFruit();
}
random_button.style.display = 'inline';
random_button.style.paddingRight = '.5rem';
random_button.style.borderRight = '1px solid white';
button_wrapper.appendChild(random_button);
// Salad button
var salad_button = document.createElement('div');
salad_button.innerHTML = 'Fruit Salad!';
salad_button.onclick = function () {
multi = true;
random_button.innerHTML = 'Random';
createNewFruit()
};
salad_button.style.display = 'inline';
salad_button.style.paddingLeft = '.5rem';
button_wrapper.appendChild(salad_button);
console.log(button_wrapper);
document.body.appendChild(button_wrapper);
})();