/
credits.html
449 lines (390 loc) · 16 KB
/
credits.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!doctype html>
<html lang="en">
<head>
<title>Credits</title>
<meta charset="utf-8">
<meta name="robots" content="index, follow">
<meta name="theme-color" content="#f4f5f6">
<meta name="apple-mobile-web-app-status-bar-style" content="#f4f5f6">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet">
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/auth/token.js"></script>
<style>
@import url(https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
.end {
position: relative;
text-align: center;
}
html, body {
height: 100vh;
overflow: hidden;
}
#wrapper {
position: absolute;
left: -500%;
width: 100%;
font: 300 3rem/1 'Open Sans Condensed', sans-serif;
text-align: center;
text-transform: uppercase;
color: #fff;
text-shadow: 0px 0px 1rem #000;
}
.clip {
vertical-align: middle;
text-align: center;
}
.clip-title {
text-align: left;
padding-bottom: 1rem;
}
.clip-title .name {
font-size: 3rem;
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-left: 14%; padding-right: 14%;
padding-top: 15px; margin-top: -15px;
padding-bottom: 15px; margin-bottom: -15px;
}
iframe, img {
width: 75%;
height: 75%;
}
.title {
font-weight: bold;
margin-left: 5%;
margin-right: 5%;
}
.subtitle {
margin-left: 5%;
margin-right: 5%;
margin-bottom: 50px;
}
.last-message {
margin-bottom: 10px;
font-weight: bold
}
.last-submessage {
margin-bottom: 10px;
margin-bottom: 200px;
}
.social {
margin-bottom: 10px;
margin-left: 10%;
font-size: 3rem;
text-align: left;
}
.job, .header {
font-size: 3rem;
}
.separator {
padding-bottom: 4rem;
}
.hosted-by, .bigHeader, .aggregated-by {
font-size: 6rem;
}
.top-clips {
font-size: 6rem;
margin-bottom: 150px;
}
.message, .smallText {
font-size: 2.5rem;
margin-bottom: 50px;
}
.last-message, .last-submessage {
margin-right: 5%;
margin-left: 5%;
}
.name, .host-name, .text {
font-size: 4rem;
width: 100%;
display: inline-block;
}
.host-name {
margin-bottom: 5px;
margin-top: 5px;
}
.hosted-column, .aggregated-column {
column-count: 2;
}
.aggregated-column, .aggregated-by {
padding-top: 50px;
}
.aggregated-column {
padding-bottom: 100px;
}
</style>
</head>
<body>
<div id='wrapper'>
<div class='title'><span id="game"></span></div>
<div class='subtitle'><span id="title"></span></div>
<div class='job' id="stream-by"></div>
<div class='name' id="streamer"></div>
<div class="message"></div>
<div id="events"></div>
<div class='hosted-by' id="hosted-by"></div>
<div class='hosted-column' id="hosts"></div>
<div class="clips" id="clips"></div>
<div class="custom" id="custom"></div>
<div class="half-end"><!-- empty page --></div>
<div class="end">
<div class="center">
<div class="last-message"><span id="last-message"></span></div>
<div class="last-submessage"><span id="last-submessage"></span></div>
<div id="social"></div>
</div>
</div>
</div>
<script src="/dist/jquery/js/jquery.min.js"></script>
<script src="/dist/lodash/js/lodash.min.js"></script>
<script src="/dist/velocity-animate/js/velocity.min.js"></script>
<script>
var resize = function (el, max, size, width) {
if (size === max) return size
width = width || 0
size = size || 1
$(el).css('font-size', (size + 1) + 'px')
if ($(el).width() >= width) {
return resize(el, max, size + 1, $(el).width())
} else {
$(el).css('font-size', (size - 1) + 'px')
}
return size
}
var socket = io('/overlays/credits', {query: "token="+token})
socket.emit('custom.text.load', (err, cb) => { // load custom.text.load at first, then rest
if (err) return console.error(err)
cb = _.sortBy(cb, 'order')
const $custom = $('#custom')
for (let input of cb) {
if (input.type === 'separator') $custom.append(`<div class="${input.type}"></div>`)
else if (input.type === 'bigHeader') $custom.append(`<div class="${input.type}">${input.text.middle}</div>`)
else {
let columns = 0
if (input.text.left.trim().length > 0) columns++
if (input.text.middle.trim().length > 0) columns++
if (input.text.right.trim().length > 0) columns++
let width = 100 / columns
$custom.append(`
<div class="${input.type}" style="display: inline-flex; width: 100%; padding-left:5%; padding-right: 5%">
<div style="width:${input.text.left.trim().length > 0 ? width : 0}%; text-align:left; display: inline-block;">${input.text.left}</div>
<div style="width:${input.text.middle.trim().length > 0 ? width : 0}%; display: inline-block;">${input.text.middle}</div>
<div style="width:${input.text.right.trim().length > 0 ? width : 0}%; text-align:right; display: inline-block;">${input.text.right}</div>
</div>`)
}
}
socket.emit('load', (err, events, streamer, game, title, hosts, socials, messages, custom, speed, show, clips, maxFontSize, aggregate) => {
$('#streamer').text(streamer)
$('#game').text(game)
$('#title').text(title)
for (let [key, value] of Object.entries(messages)) {
$('.hosted-by').text(`${_.get(custom, 'hosted-by', 'hosted by')}`)
if (key === 'lastMessage') $('#last-message').html(value)
else $('#last-submessage').html(value)
}
let size = resize('#game', maxFontSize)
resize('#title', size - Math.floor((size / 4))) // title should be smaller than game
size = resize('#last-message', maxFontSize)
resize('#last-submessage', size - Math.floor((size / 4))) // submessage should be smaller than message
let $events = $('#events')
let $hosts = $('#hosts')
let followers = []
let cheers = []
let subs = []
let tips = []
for (let [index, event] of Object.entries(events)) {
event.message = _.get(event, 'message', '')
if (event.event === 'follow' && show.followers) {
if (aggregate) followers.push({ username: event.username })
else $events.append(`
<div class='job'>${_.get(custom, 'followed-by', 'followed by')}</div>
<div class='name'>${event.username}</div>
<div class="message">${event.message}</div>
`)
} else if (event.event === 'cheer' && show.cheers) {
if (aggregate) cheers.push({ username: event.username, bits: event.bits })
else $events.append(`
<div class='job'>${_.get(custom, 'cheer-by', 'cheer <strong>$bits bits</strong> by').replace('$bits', event.bits)}</div>
<div class='name'>${event.username}</div>
<div class="message">${event.message}</div>
`)
} else if (event.event === 'sub' && show.subscribers) {
if (aggregate) subs.push({ username: event.username })
else $events.append(`
<div class='job'>${_.get(custom, 'subscribed-by', 'subscribed by')}</div>
<div class='name'>${event.username}</div>
<div class="message">${event.message}</div>
`)
} else if (event.event === 'resub' && show.resubs) {
if (aggregate) subs.push({ username: event.username, months: event.months })
else $events.append(`
<div class='job'>${_.get(custom, 'resubscribed-by', 'resubscribed <strong>$months months</strong> by').replace('$months', event.months)}</div>
<div class='name'>${event.username}</div>
<div class="message">${event.message}</div>
`)
} else if (event.event === 'subgift' && show.subgifts) {
if (aggregate) subs.push({ username: event.username })
else $events.append(`
<div class='job'>${_.get(custom, 'subgift-by', '<strong>$from</strong> gifted subscribe to').replace('$from', event.from)}</div>
<div class='name'>${event.username}</div>
<div class="message">${event.message}</div>
`)
} else if (event.event === 'tip' && show.tips) {
if (aggregate) tips.push({ username: event.username, currency: event.currency, amount: event.amount })
else $events.append(`
<div class='job'>${_.get(custom, 'tip-by', 'tip <strong>$currency$amount</strong>').replace('$currency', event.currency).replace('$amount', event.amount)}</div>
<div class='name'>${event.username}</div>
<div class="message">${event.message}</div>
`)
}
}
if (aggregate) {
if (followers.length > 0) {
let output = `
<div class='aggregated-by'>Follows</div>
<div class='aggregated-column'>
`
for (let follow of followers) {
output += `<div class='host-name'>${follow.username}</div>`
}
output += `</div>`
$events.append(output)
}
if (cheers.length > 0) {
let output = `
<div class='aggregated-by'>Cheers</div>
<div class='aggregated-column'>
`
for (let cheer of _(cheers).groupBy('username').map((o, k) => ({ 'username': k, 'bits': _.sumBy(o, (o) => parseInt(o.bits, 10)) }))) {
output += `<div class='host-name'>${cheer.username} - ${cheer.bits} bits</div>`
}
output += `</div>`
$events.append(output)
}
if (subs.length > 0) {
let output = `
<div class='aggregated-by'>Subs/Resubs</div>
<div class='aggregated-column'>
`
for (let sub of subs) {
output += `<div class='host-name'>${sub.months > 0 ? `${sub.months}x `: ``}${sub.username}</div>`
}
output += `</div>`
$events.append(output)
}
if (tips.length > 0) {
let output = `
<div class='aggregated-by'>Tips</div>
<div class='aggregated-column'>
`
for (let tip of _(tips).groupBy('username').map((o, k) => ({ 'username': k, 'amount': Number.parseFloat(_.sumBy(o, 'amount')).toFixed(2), 'currency': _.find(tips, (b) => b.username === k).currency }))) {
output += `<div class='host-name'>${tip.username} ${tip.currency}${tip.amount}</div>`
}
output += `</div>`
$events.append(output)
}
}
if (show.hosts) {
for (let host of hosts) {
$hosts.append(`<div class='host-name'>${host}</div>`)
}
}
socials = _.orderBy(socials, 'order')
for (let social of socials) {
$('#social').append(`
<div class="social"><i class="fab fa-fw fa-${social.type}"></i> ${social.text}</div>
`)
}
if ($hosts.text().length === 0) {
$('.hosted-by').remove()
$('.hosted-column').remove()
}
$('#stream-by').text(`${_.get(custom, 'stream-by', 'stream by')}`)
// window height
let wHeight = $(document).height()
if (clips.list.length > 0) {
$('#clips').append(`
<div class="half-end"></div>
<div class='top-clips'>${_.get(custom, 'top-clips', 'top clips')}</div>
`)
}
let i = 0
for (let clip of clips.list) {
i++
$('#clips').append(`
<div class="clip-title" style="text-align:${i % 2 === 0 ? 'right' : 'left'}" data-id="${clip.tracking_id}">
<div style="position:absolute; opacity: 0.5; font-weight: bold; margin-top: -5px; font-size: 10rem; ${i % 2 === 0 ? 'left: 15%;' : 'right: 15%;'}">${i}</div>
<div class='name' style="padding-${i % 2 === 0 ? 'left' : 'right'}: 22%">${clip.title}</div>
<div class='name' style="padding-${i % 2 === 0 ? 'left' : 'right'}: 22%"><strong>${clip.game}</strong></div>
<div class="name" style="padding-${i % 2 === 0 ? 'left' : 'right'}: 22%">${_.get(custom, 'clipped-by', 'clipped by')} ${clip.curator.display_name}</div>
</div>
<div class="clip" style="height: ${wHeight}px" data-duration="${clip.duration}" data-embed="${clip.embed_html}" data-thumbnail="${clip.thumbnails.medium}">
<img src="${clip.thumbnails.medium}" data-id="${clip.tracking_id}"></img>
</div>`)
}
// set windows height for end (to be on "separate" page)
$('.end').css('height', `${wHeight}px`)
$('.half-end').css('height', `${wHeight/2}px`)
// get height of wrapper
let height = $('#wrapper').innerHeight()
let delay = 0 //10 * 1000 // 10s delay
// set css of wrapper
$('#wrapper')
.css('left', 0)
.css('top', `${wHeight}px`)
// roll after delay
setTimeout(() => {
$('#wrapper').velocity({ top: (wHeight - height) + 'px' }, "linear", (wHeight + height) * speed)
}, delay)
let elements = $('#wrapper *')
//remove end from elements
if (clips.list.length > 0 && clips.play) {
// check for clips
let clips = $('.clip')
let clipsBackup = _.clone(clips)
let triggerHeight = wHeight / 4.5
setInterval(() => {
for (let i in clips) {
try {
if (!clips.hasOwnProperty(i) || i === 'length' || i === 'prevObject') continue
if ($(clips[i]).offset().top <= triggerHeight) {
$('#wrapper').velocity("pause")
$(clips[i]).empty()
$(clips[i]).append($(clips[i]).data('embed'))
setTimeout(() => {
$(clipsBackup[i]).empty()
$(clipsBackup[i]).append(`<img src="${$(clipsBackup[i]).data('thumbnail')}"></img>`)
$('#wrapper').velocity("resume")
}, ($(clipsBackup[i]).data('duration') + 1) * 1000)
delete clips[i]
}
} catch (e) {
console.debug(e)
console.debug(clips[i])
continue
}
}
}, 100)
}
})
})
</script>
</body>
</html>