-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
confetti.html
283 lines (251 loc) · 8.45 KB
/
confetti.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confetti Celebration</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
background-color:#0000;
}
#confetti-wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9999;
}
.confetti {
position: absolute;
width: 10px;
height: 10px;
opacity: 1; /* Make sure they're fully visible */
z-index: 10000;
}
</style>
</head>
<body>
<div id="confetti-wrapper"></div>
<script>
window.onerror = function backupErr(errorMsg, url=false, lineNumber=false) {
console.error(errorMsg);
console.error(lineNumber);
console.error("Unhandled Error occured");
return false;
};
try {
if (electronApi){ // fix for electron dragging.
document.body.style.width = "95%";
setTimeout(function(){
document.body.style.width = "100%";
},1000);
setTimeout(function(){
document.body.style.width = "98%";
},2000);
setTimeout(function(){
document.body.style.width = "100%";
},5000);
}
} catch(e){
}
function getById(id) {
var el = document.getElementById(id);
if (!el) {
el = document.createElement("span");
}
return el;
}
(function (w) {
w.URLSearchParams = w.URLSearchParams || function (searchString) {
var self = this;
self.searchString = searchString;
self.get = function (name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(self.searchString);
if (results == null) {
return null;
} else {
return decodeURI(results[1]) || 0;
}
};
};
})(window);
var urlParams = new URLSearchParams(window.location.search);
var iframe = null;
var roomID = "test";
var scale = 1;
var drawmode = false;
if (urlParams.has("session")){
roomID = urlParams.get("session");
} else if (urlParams.has("s")){
roomID = urlParams.get("s");
} else if (urlParams.has("id")){
roomID = urlParams.get("id");
} else if (window.location.protocol=="file:"){
roomID = prompt("Enter your session ID here, or add it to the URL.");
if (roomID){
var href = window.location.href;
var arr = href.split('?');
var newurl;
if (arr.length > 1 && arr[1] !== '') {
newurl = href + '&session=' + roomID;
} else {
newurl = href + '?session=' + roomID;
}
window.history.pushState({path: newurl.toString()}, '', newurl.toString());
} else {
alert("You need to provide your extension's session ID for this page to work");
}
}
var password = "false";
if (urlParams.has("password")){
password = urlParams.get("password") || "false";
}
if (urlParams.has("scale")){
scale = urlParams.get("scale") || 1.0;
scale = parseFloat(scale);
document.documentElement.style.setProperty("--width", parseInt(computedStyle.getPropertyValue("--width")) * scale+"px");
document.documentElement.style.setProperty("--font-size", parseInt(computedStyle.getPropertyValue("--font-size")) * scale+"%");
document.documentElement.style.setProperty("--padding", parseInt(computedStyle.getPropertyValue("--padding")) * scale+"px");
}
var conCon = 1;
var socketserver = false;
var serverURL = "wss://io.socialstream.ninja";
function setupSocket(){
socketserver.onclose = function (){
setTimeout(function(){
conCon+=1;
socketserver = new WebSocket(serverURL);
setupSocket();
},100*conCon);
};
socketserver.onopen = function (){
conCon = 1;
socketserver.send(JSON.stringify({"join":roomID, "out":3, "in":4}));
};
socketserver.addEventListener('message', function (event) {
var resp = false
if (event.data){
var data = JSON.parse(event.data);
processInput(data);
if (data.get){
var ret = {};
ret.callback = {};
ret.callback.get = data.get
ret.callback.result = true;
socketserver.send(JSON.stringify(ret));
}
}
});
}
if (urlParams.has("server") || urlParams.has("server2")){
serverURL = urlParams.get("server") || urlParams.get("server2") || serverURL;
socketserver = new WebSocket(serverURL);
setupSocket();
}
if (urlParams.has("chroma")){
var chroma = urlParams.get("chroma") || "0F0";
document.body.style.backgroundColor = "#"+chroma;
}
if (urlParams.has("transparent")){
document.documentElement.style.setProperty("--background-color", "#0000", "important");
}
function processInput(data){
if ("drawmode" in data){
drawmode = data.drawmode || false;
}
if ("waitlist" in data){
var winnerStatus = 0;
if (data.waitlist === false){
//document.getElementById("parentHolder").classList.add("hidden");
} else if (!data.waitlist.length){
//document.getElementById("parentHolder").classList.remove("hidden");
} else {
for (var i = 0; i<data.waitlist.length;i++){
if (data.waitlist[i]){
if (data.waitlist[i].waitStatus == 1){
continue;
}
if (drawmode || ("randomStatus" in data.waitlist[i])){
if (data.waitlist[i].randomStatus === 1){
// "winner";
winnerStatus += 1;
} else if (data.waitlist[i].randomStatus === 2){
// previous winner
}
}
}
}
if (drawmode && winnerStatus){
createConfetti(150);
}
}
}
}
iframe = document.createElement("iframe");
iframe.src = "https://vdo.socialstream.ninja/?ln&salt=vdo.ninja&password="+password+"¬mobile&solo&view="+roomID+"&novideo&noaudio&label=waitlist&cleanoutput&room="+roomID; // view only connection (data two way of course)
iframe.style.width = "0px";
iframe.style.height = "0px";
iframe.style.position = "fixed";
iframe.style.left = "-100px";
iframe.style.top = "-100px";
iframe.id = "frame1"
document.body.appendChild(iframe);
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";
eventer(messageEvent, function (e) {
if (e.source != iframe.contentWindow){return} // reject messages send from other iframes
if ("dataReceived" in e.data){ // raw data
if ("overlayNinja" in e.data.dataReceived){
processInput(e.data.dataReceived.overlayNinja);
}
}
});
const confettiWrapper = document.getElementById('confetti-wrapper');
function createConfetti(num) {
for (let i = 0; i < num; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
confetti.style.position = 'absolute';
confetti.style.top = '-10px'; // Start above the viewport
confetti.style.left = `${Math.random() * confettiWrapper.offsetWidth}px`; // Random start horizontally
confetti.style.backgroundColor = getRandomColor();
confetti.style.transform = `scale(${Math.random() + 0.5})`;
confetti.style.opacity = `${Math.random()}`;
confetti.style.width = '10px';
confetti.style.height = '10px';
confettiWrapper.appendChild(confetti);
//console.log('Initial left:', confetti.style.left); // Log to check the value
animateConfetti(confetti);
}
}
function getRandomColor() {
const colors = ['#FFC300', '#FF5733', '#C70039', '#900C3F', '#581845'];
return colors[Math.floor(Math.random() * colors.length)];
}
function animateConfetti(confetti) {
const xStart = parseInt(confetti.style.left, 10); // Ensure this is a number
const yStart = -10; // initial top position
const xEnd = xStart + (Math.random() * 500 - 250); // Random end position allowing left and right movement
const yEnd = window.innerHeight + 20;
const spin = (Math.random() * 2000 - 1000) + 'deg'; // random spin
const duration = Math.random() * 3000 + 3000;
//console.log(confetti.style.left);
confetti.animate([
{ transform: `translate(0px, 0px) rotate(0deg)` }, // Start at current position
{ transform: `translate(${xEnd - xStart}px, ${yEnd - yStart}px) rotate(${spin})` } // End at a random position off-screen
], {
duration: duration,
easing: 'ease-out'
}).onfinish = () => {
confetti.remove();
};
}
</script>
</body>
</html>