-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
ticker.html
339 lines (291 loc) · 9.81 KB
/
ticker.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="./icons/favicon.ico" />
<title>News Ticker</title>
<style>
:root {
--font-color: #FFF;
--font-family: Arial, sans-serif, Roboto;
--background-color: #001f3f;
--border-top: 5px solid #ff4136;
--font-size: 24px;
--electron-drag-fix: drag;
}
body {
margin: 0;
padding: 0;
overflow: hidden;
font-family: var(--font-family);
background-color: #0000;
}
.ticker-container {
width: 100%;
height: 60px;
background-color: var(--background-color);
color: var(--font-color);
display: flex;
align-items: center;
overflow: hidden;
position: fixed;
bottom: 0;
border-top: var(--border-top);
}
.ticker-wrapper {
display: flex;
white-space: nowrap;
}
.ticker-item {
padding: 0 50px;
font-size: var(--font-size);
line-height: 60px;
opacity: 0;
transition: opacity 1s;
}
.ticker-item.show {
opacity: 1;
}
</style>
</head>
<body>
<div class="ticker-container">
<div id="ticker" class="ticker-wrapper">
</div>
</div>
<script>
(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 darkmode = null;
var scale = 1;
var isOBSBrowserSource = 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){
}
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");
}
} else {
window.location.href = "https://github.com/steveseguin/live-chat-overlay#readme";
}
var password = "false";
if (urlParams.has("password")){
password = urlParams.get("password") || "false";
}
function loadGoogleFont(fontName) {
const formattedFontName = fontName.replace(/\s/g, '+');
const link = document.createElement('link');
link.href = `https://fonts.googleapis.com/css2?family=${formattedFontName}&display=swap`;
link.rel = 'stylesheet';
document.head.appendChild(link);
var currentFont = getComputedStyle(document.documentElement).getPropertyValue('--font-family').trim();
document.documentElement.style.setProperty("--font-family", "'"+fontName.replaceAll("+"," ")+"', "+currentFont);
}
if (urlParams.get("font")){
document.documentElement.style.setProperty("--font-family", urlParams.get("font") + ", Sora, Roboto, Avenir Next, Helvetica, Geneva, Verdana, Arial, sans-serif");
}
if (urlParams.get("googlefont")) {
loadGoogleFont(urlParams.get("googlefont"));
}
if (urlParams.has('css')){
var cssURL = urlParams.get('css');
cssURL = decodeURI(cssURL);
var cssStylesheet = document.createElement('link');
cssStylesheet.rel = 'stylesheet';
cssStylesheet.type = 'text/css';
cssStylesheet.media = 'screen';
cssStylesheet.href = cssURL;
document.getElementsByTagName('head')[0].appendChild(cssStylesheet);
}
if (urlParams.has("base64css") || urlParams.has("b64css") || urlParams.has("cssbase64") || urlParams.has("cssb64")) {
try {
var base64Css = urlParams.get("base64css") || urlParams.get("b64css") || urlParams.get("cssbase64") || urlParams.get("cssb64");
var css = decodeURIComponent(atob(base64Css)); // window.btoa(encodeURIComponent("#mainmenu{background-color: pink; ❤" ));
var cssStyleSheet = document.createElement("style");
cssStyleSheet.innerText = css;
document.querySelector("head").appendChild(cssStyleSheet);
} catch(e){console.error(e);}
}
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":7, "in":8}));
};
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")){ // not doing anything yet.
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;
}
var speed = 1.0;
if (urlParams.has("speed")){
speed = parseFloat(urlParams.get("speed")) || 1;
}
try {
if (window.obsstudio){
window.obsstudio.getStatus(function(obsStatus){
isOBSBrowserSource = true;
});
}
} catch(e){}
if (urlParams.has("transparent")){
document.documentElement.style.setProperty("--background-color", "#0000", "important");
}
const tickerElement = document.getElementById("ticker");
let scrollAnimationFrame = null;
function processInput(data){
console.log(data);
if ("ticker" in data){
cancelAnimationFrame(scrollAnimationFrame);
tickerElement.innerHTML = ""; // Clear current items
data.ticker.forEach(data=>{
let tik = document.createElement("div");
tik.className = "ticker-item";
tik.innerHTML = data;
document.getElementById("ticker").appendChild(tik);
setTimeout(() => {
tik.classList.add("show");
}, 50);
});
data.ticker.forEach(data=>{
let tik = document.createElement("div");
tik.className = "ticker-item";
tik.innerHTML = data;
document.getElementById("ticker").appendChild(tik);
setTimeout(() => {
tik.classList.add("show");
}, 50);
});
startScrolling();
}
}
function startScrolling() {
const ticker = document.getElementById('ticker');
let tickerWidth = ticker.scrollWidth / 2;
let containerWidth = document.querySelector('.ticker-container').clientWidth;
let position = 0;
speed = 1; // Pixels per frame
function scroll() {
position -= speed;
if (position <= -tickerWidth) {
position = 0;
}
ticker.style.transform = `translateX(${position}px)`;
scrollAnimationFrame = requestAnimationFrame(scroll);
}
scroll();
}
iframe = document.createElement("iframe");
iframe.src = "https://vdo.socialstream.ninja/?ln&salt=vdo.ninja&password="+password+"&solo&view="+roomID+"&novideo&noaudio&label=ticker&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);
}
}
});
if (urlParams.has('js')){ // ie: &js=https%3A%2F%2Fvdo.ninja%2Fexamples%2Ftestjs.js
console.warn("Third-party Javascript has been injected into the code. Security cannot be ensured.");
var jsURL = urlParams.get('js');
jsURL = decodeURI(jsURL);
console.log(jsURL);
var externalJavaascript = document.createElement('script');
externalJavaascript.type = 'text/javascript';
externalJavaascript.crossorigin = 'anonymous';
externalJavaascript.src = jsURL;
externalJavaascript.onerror = function() {
console.warn("Third-party Javascript failed to load");
};
externalJavaascript.onload = function() {
console.log("Third-party Javascript loaded");
};
document.head.appendChild(externalJavaascript);
}
</script>
</body>
</html>