forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popout.html
369 lines (327 loc) · 10.3 KB
/
popout.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!DOCTYPE html>
<html lang="en">
<head>
<title>VDO.Ninja Chat Pop-out</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#ffffff" />
<style>
:root {
--discord-grey-0: #121212;
--discord-grey-1: #1e1f22;
--discord-grey-1a: #1e1f22;
--discord-grey-2: #232428;
--discord-grey-3: #2b2d31;
--discord-grey-4: #2e3035;
--discord-grey-5: #313338;
--discord-grey-6: #383a40;
--discord-grey-7: #404249;
--discord-grey-8: #5e6064;
--discord-text: hsl( 210 calc(1 * 9.1%) 87.1% /1);
--baby-blue: #BCF;
}
* {
padding: 0;
margin: 0;
border: 0;
box-sizing: border-box;
}
body{
background-color: var(--discord-grey-0);
height: 100vh;
width: 100vw;
}
#chatModule{
display: flex;
flex-direction: column;
padding: 5px;
height: 100%;
gap: 5px;
justify-content: flex-end;
}
#chatBody {
display: flex;
flex-direction: column;
gap: 5px;
overflow-y: auto;
}
.outMessage, .inMessage {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 5px;
font-family: 'Roboto';
font-size: 14px;
text-align: right;
background-color: var(--baby-blue);
border-radius: 4px;
padding: 2px 5px;
}
.inMessage {
color: var(--discord-text);
background-color: var(--discord-grey-7);
}
.outMessage .chat_message {
font-weight: bold;
}
::-webkit-input-placeholder {
color: #ccc !important;
}
.controls {
display: flex;
flex-direction: row;
gap: 5px;
height: 25px;
flex-shrink: 0;
}
.controls input {
border-radius: 4px;
flex: 3;
color: var(--discord-text);
background-color: var(--discord-grey-5);
border: 1px solid var(--discord-grey-8);
padding: 0px 5px;
}
.controls button {
border-radius: 4px;
flex: 1;
color: var(--discord-text);
background-color: var(--discord-grey-2);
border: 1px solid var(--discord-grey-8);
}
/* SCROLL BAR STYLING */
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
background-color: var(--discord-grey-1);
border-radius: 4px;
}
::-webkit-scrollbar-thumb {
background-color: var(--discord-grey-7);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background-color: var(--discord-grey-8);
}
</style>
</head>
<body>
<div id="chatModule" >
<div id="chatBody">
<div class="inMessage" data-translate='welcome-to-vdo-ninja-chat'>
Welcome to VDO.Ninja! You can send text messages directly to connected peers from here.
</div>
</div>
<div class="controls">
<input id="chatInput" placeholder="Enter chat message to send here" onkeypress="EnterButtonChat(event)" />
<button onclick="sendChatMessage()" data-translate='send-chat'>Send</button>
</div>
</div>
<script>
/// If you have a routing system setup, you could have just one global listener for all iframes instead.
//var chatUpdateTimeout = null;
var messageList = [];
(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);
function replaceURLs(message) {
if(!message) return;
var urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
return message.replace(urlRegex, function (url) {
url = url.replace(/</g, "<").replace(/>/g, ">").replace(/["']/g, ""); // try to sanitize things, just in case.
var punc = "";
while (url[url.length-1] === "."){
url = url.slice(0,-1);
punc += ".";
}
while (url[url.length-1] === ";"){
url = url.slice(0,-1);
punc += ";";
}
while (url[url.length-1] === ","){
url = url.slice(0,-1);
punc += ",";
}
while (url[url.length-1] === "!"){
url = url.slice(0,-1);
punc += "!";
}
while (url[url.length-1] === ":"){
url = url.slice(0,-1);
punc += ":";
}
while (url[url.length-1] === "*"){
url = url.slice(0,-1);
punc += "*";
}
while (url[url.length-1] === ")"){
url = url.slice(0,-1);
punc += ")";
}
while (url[url.length-1] === "?"){
url = url.slice(0,-1);
punc += "?";
}
var hyperlink = url;
if (!hyperlink.match('^https?:\/\/')) {
hyperlink = 'http://' + hyperlink;
}
if (url.length>35){
url = url.substring(0, 35)+"...";
}
return '<a href="' + hyperlink + '" title="Click to open the link in a new tab" target="_blank" rel="noopener noreferrer">' + url + '</a>'+punc;
});
}
if (urlParams.has("id")){
var bid = urlParams.get("id");
}
var bc = new BroadcastChannel(bid);
bc.postMessage({"loaded":true});
bc.onmessage = function (e) {
//if (e.source != iframe.contentWindow){return} // reject messages send from other iframes
console.log(e);
if ("data" in e){
if ("msg" in e.data){
messageList.push(e.data);
messageList = messageList.slice(-100);
updateMessages(e.data);
} else if ("messageList" in e.data){
messageList = e.data.messageList;
updateMessages();
}
}
};
function sanitize(string) {
var temp = document.createElement('div');
temp.textContent = string;
return temp.innerHTML;
}
function EnterButtonChat(event){
// Number 13 is the "Enter" key on the keyboard
var key = event.which || event.keyCode;
if (key === 13) {
// Cancel the default action, if needed
event.preventDefault();
// Trigger the button element with a click
sendChatMessage();
}
}
function sendChatMessage(chatMsg = false){ // filtered + visual
var msg = document.getElementById('chatInput').value;
msg = sanitize(msg);
if (msg==""){return;}
console.log(msg);
bc.postMessage({"msg":msg})
document.getElementById('chatInput').value = "";
messageList.push({"msg":msg, type: "sent"});
messageList = messageList.slice(-100);
updateMessages({"msg":msg, type: "sent"});
}
function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);
var interval = seconds / 31536000;
if (interval > 1) {
return Math.floor(interval) + " years";
}
interval = seconds / 2592000;
if (interval > 1) {
return Math.floor(interval) + " months";
}
interval = seconds / 86400;
if (interval > 1) {
return Math.floor(interval) + " days";
}
interval = seconds / 3600;
if (interval > 1) {
return Math.floor(interval) + " hours";
}
interval = seconds / 60;
if (interval > 1) {
return Math.floor(interval) + " minutes";
}
return "Seconds ago";
}
function updateMessages(message = false){
if (message){
var time = timeSince(message.time);
var msg = document.createElement("div");
////// KEEP THIS IN /////////
console.log(message.msg); // Display Recieved messages for View-Only clients.
/////////////////////////////
var label = "";
if (message.label){
label = message.label;
}
message.msg = replaceURLs(message.msg);
if (message.type == "sent"){
msg.innerHTML = "<span class='chat_message chat_sent'>"+message.msg + " </span><i><small> <small>- "+time+"</small></small></i><span style='display:none'>"+label+"</span>";
msg.classList.add("outMessage");
} else if (message.type == "recv"){
msg.innerHTML = label+"<span class='chat_message chat_recv'>"+message.msg + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("inMessage");
} else if (message.type == "action"){
msg.innerHTML = label+"<span class='chat_message chat_action'>"+message.msg + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("actionMessage");
} else if (message.type == "alert"){
msg.innerHTML = "<span class='chat_message chat_alert'>"+message.msg + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("inMessage");
} else {
msg.innerHTML = "<span class='chat_message chat_other'>"+message.msg + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("inMessage");
}
document.getElementById("chatBody").appendChild(msg);
} else {
document.getElementById("chatBody").innerHTML = "";
for (i in messageList){
var time = timeSince(messageList[i].time);
var msg = document.createElement("div");
////// KEEP THIS IN /////////
console.log(messageList[i].msg); // Display Recieved messages for View-Only clients.
/////////////////////////////
var label = "";
if (messageList[i].label){
label = messageList[i].label;
}
var message = replaceURLs(messageList[i].msg);
if (messageList[i].type == "sent"){
msg.innerHTML = "<span class='chat_message chat_sent'>"+message + " </span><i><small> <small>- "+time+"</small></small></i><span style='display:none'>"+label+"</span>";
msg.classList.add("outMessage");
} else if (messageList[i].type == "recv"){
msg.innerHTML = label+"<span class='chat_message chat_recv'>"+message + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("inMessage");
} else if (messageList[i].type == "action"){
msg.innerHTML = label+"<span class='chat_message chat_action'>"+message + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("actionMessage");
} else if (messageList[i].type == "alert"){
msg.innerHTML = "<span class='chat_message chat_alert'>"+message + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("inMessage");
} else {
msg.innerHTML = "<span class='chat_message chat_other'>"+message + " </span><i><small> <small>- "+time+"</small></small></i>";
msg.classList.add("inMessage");
}
document.getElementById("chatBody").appendChild(msg);
}
}
//if (chatUpdateTimeout){
// clearInterval(chatUpdateTimeout);
//}
document.getElementById("chatBody").scrollTop = document.getElementById("chatBody").scrollHeight;
//chatUpdateTimeout = setTimeout(function(){updateMessages()},60000);
}
</script>
</body>
</html>