-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
162 lines (145 loc) · 3.87 KB
/
app.js
File metadata and controls
162 lines (145 loc) · 3.87 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const showArea = document.querySelector("#show-area");
const popSound = document.getElementById("pop");
let noobsCount = 0;
// const noobShow = `<div class="rounded-lg p-2 random" >noob</div>`;
updateNoobCount();
const BgCollection = [
"#455954",
"#9d7463",
"yellow",
"#dfdbd8",
"#A3845A",
"#6DF0AF",
"#9839A3",
"#BB2020",
"#06111C",
"#FFEB4D",
"#90CBFB",
"#4B3617",
"#D94C1A",
"#A6341B",
"#60371E",
];
// generate random color
function getRandomColor() {
var color = "#";
for (var i = 0; i < 6; i++) {
color += Math.floor(Math.random() * 10);
}
return color;
}
function changeBg(el) {
var randomBg = getRandomColor();
$(el).css("background", randomBg);
}
function playPopSound() {
popSound.play();
}
function randomPos(el) {
var randomBg = getRandomColor();
var operator = Math.random();
if (operator < 0.5) {
operator = "-";
} else {
operator = "+";
}
let degrees = operator + Math.random() * 10 + 9;
$(el).css({
top:
Math.random() * ($("#show-area").height() - $(".random").height() - 30) +
"px",
left:
Math.random() * ($("#show-area").width() - $(".random").width() - 30) +
"px",
transform: "rotate(" + degrees + "deg)",
});
$("#show-area").css("border", "5px solid" + randomBg);
setTimeout(() => {
$(".random").css({ transform: "scale(1.25) " });
}, 750);
}
function updateNoobCount() {
document.querySelector("#noob-count").innerHTML = noobsCount;
}
function showRandomNoob() {
++noobsCount;
updateNoobCount();
const noobShow = document.createElement("div");
noobShow.classList.add("random");
randomPos(noobShow);
setTimeout(() => {
noobShow.innerHTML = `<h3>noob!</h3>`;
showArea.appendChild(noobShow);
changeBg(noobShow);
}, 100);
}
$("#appear-btn").on("click", () => {
$("#show-area").css("display", "block");
$("#clear-btn").css("display", "inline-block");
$("#stop-btn").css("display", "inline-block");
$("#appear-btn").text("Claim more");
$(".random h3").css("animation-play-state", "running");
let count = 250;
let interval = setInterval(() => {
if (count > 0) {
showRandomNoob();
tiltNoobs();
if (localStorage.getItem("volume") == "on") {
playPopSound();
}
count--;
}
// randomPos($('.random'))
//tiltNoobs()
}, 10);
$("#stop-btn").on("click", () => {
clearInterval(interval);
setTimeout(() => {
tiltNoobs();
}, 1000);
$(".random h3").css("animation-play-state", "paused");
});
});
$("#clear-btn").on("click", () => {
showArea.innerHTML = ``;
noobsCount = 0;
updateNoobCount();
});
if (localStorage.getItem("volume") == null) {
localStorage.setItem("volume", "on");
} else {
localStorage.setItem("volume", localStorage.getItem("volume"));
if (localStorage.getItem("volume") == "off") {
$("#volume-btn").val("off");
$("#volume-btn i").toggleClass("fa-volume-up fa-volume-mute");
$("#volume-btn i").toggleClass("text-success text-danger");
}
}
$("#volume-btn").on("click", () => {
//Toggle volume on/off
val = $("#volume-btn").val();
if (val == "on") {
$("#volume-btn").val("off");
localStorage.setItem("volume", "off");
$("#volume-btn i").toggleClass("fa-volume-up fa-volume-mute");
$("#volume-btn i").toggleClass("text-success text-danger");
} else if (val == "off") {
$("#volume-btn").val("on");
localStorage.setItem("volume", "on");
$("#volume-btn i").toggleClass("fa-volume-mute fa-volume-up");
$("#volume-btn i").toggleClass("text-danger text-success");
}
});
function tiltNoobs() {
var operator = Math.random();
if (operator < 0.5) {
operator = "-";
} else {
operator = "+";
}
let evenNoobs = document.querySelectorAll(".random");
for (let i = 0; i < evenNoobs.length; i++) {
let degrees = operator + Math.random() * 10 + 9;
evenNoobs[i].style.transform = "rotate(" + degrees + "deg)";
}
}