-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
636 lines (516 loc) · 24.4 KB
/
index.html
File metadata and controls
636 lines (516 loc) · 24.4 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
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<html>
<head>
<title>Fanta Shokata</title>
</head>
<style>
.page {
background-color: #99CCFF;
}
.content-frame {
border: 0px;
padding: 0px;
margin-left: auto;
margin-right: auto;
width: 673px !important;
min-width: 673px !important;
max-width: 673px !important;
border-spacing: 0px;
}
th, td {
padding-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
}
.header-cell {
padding-left: 0px;
padding-right: 0px;
padding-top: 44px;
padding-bottom: 0px;
text-align: center;
vertical-align: top;
}
.main-cell {
padding-left: 40px;
padding-right: 40px;
padding-top: 0px;
padding-bottom: 10px;
}
.footer-cell {
padding-left: 0px;
padding-right: 0px;
padding-top: 10px;
padding-bottom: 0px;
text-align: center;
vertical-align: top;
}
.menu-item {
font-family: Verdana, Tahoma;
font-size: 10pt;
font-weight: bold;
color: #3A60A5;
text-decoration: none;
}
.menu-item:hover {
font-family: Verdana, Tahoma;
font-size: 10pt;
font-weight: bold;
color: #EFE1A3;
text-decoration: none;
}
.video-player{
background-color: black;
width: 480px !important;
min-width: 480px !important;
max-width: 480px !important;
height: 440px !important;
min-height: 440px !important;
max-height: 440px !important;
}
.body-text {
font-family: Verdana, Tahoma;
font-size: 8pt;
color: #3A60A5;
text-decoration: none;
}
.footer-text {
font-family: Verdana, Tahoma;
font-size: 8pt;
font-weight: bold;
color: #3A60A5;
text-decoration: none;
}
.footer-link {
font-family: Verdana, Tahoma;
font-size: 8pt;
font-weight: bold;
color: #3A60A5;
}
.footer-link:hover {
font-family: Verdana, Tahoma;
font-size: 8pt;
font-weight: bold;
color: #EFE1A3;
text-decoration: none;
}
.createvideo-div {
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
padding-bottom: 10px;
font-family: Verdana, Tahoma;
font-size: 8pt;
color: #3A60A5;
text-decoration: none;
}
.movie-span {
text-align: center;
vertical-align: top;
width: 100%;
}
</style>
<body class="page">
<script language="JavaScript">
/*
Invokes the page handler when the DOM is fully loaded.
*/
document.addEventListener("DOMContentLoaded", function() {
startUp();
});
</script>
<table class="content-frame">
<tr>
<td width="673" height="158" class="header-cell" style="background-image: url(i/header.png);">
<div style="float: left; width: 160px; text-align: center"><a href="?p=Home" class="menu-item">HOME</a></div>
<div style="float: right; width: 160px; text-align: center"><a href="?p=Create" class="menu-item">MAKE MOVIES</a></div>
</td>
</tr>
<tr>
<td width="673" style="background-image: url(i/body-background.png);"><img src="i/transparent.png" width="673" height="1" /></td>
</tr>
<tr>
<td width="673"><div id="BodyContents" class="main-cell" style="background-image: url(i/body-background.png);"></div></td>
</tr>
<tr>
<td width="1" height="36" class="footer-cell" style="background-image: url(i/footer.png);"><span class="footer-text">You like? Then drop me a <a href="mailto:daniel@mydan.com" class="footer-link">line</a>, boss.</span></td>
</tr>
</table>
<script language="JavaScript">
// A base 64 encoded JSON containing default captions for each video, and timings
const _captions = 'ewogICAidmlkZW9zIjpbCiAgICAgIHsKICAgICAgICAgImlkIjoiMDEiLAogICAgICAgICAiY3VlcyI6WwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MiwKICAgICAgICAgICAgICAgImVuZCI6Ny41LAogICAgICAgICAgICAgICAidGV4dCI6IkFoaCEgIFRoaXMgaXMgcHJlbWl1bSEgIFdoYXQgaXMgdGhlIHNlY3JldCB0byB5b3VyIHF1YWxpdHkgbmFhbj8iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgInN0YXJ0Ijo4LjIsCiAgICAgICAgICAgICAgICJlbmQiOjEyLAogICAgICAgICAgICAgICAidGV4dCI6IldoeSBpdCBpcyBzdWdhciwgY29jb251dCBhbmQgcmFpc2lucyEiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgInN0YXJ0IjoxNCwKICAgICAgICAgICAgICAgImVuZCI6MTgsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiSXQncyBhIHRhZCBzd2VldCBmb3IgY3VycnkhIgogICAgICAgICAgICB9CiAgICAgICAgIF0KICAgICAgfSwKICAgICAgewogICAgICAgICAiaWQiOiIwMiIsCiAgICAgICAgICJjdWVzIjpbCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgInN0YXJ0Ijo5LjUsCiAgICAgICAgICAgICAgICJlbmQiOjE1LAogICAgICAgICAgICAgICAidGV4dCI6IkFuZCB3aGF0IGRvIHlvdSB0aGluayB5b3UncmUgdXAgdG8_IgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MTUuMiwKICAgICAgICAgICAgICAgImVuZCI6MjEsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiUmVzdCBhc3N1cmVkIEknbSBseWluZyBoZXJlIG5vdywgYnV0IG9uZSBkYXkgSSdtIGdvaW5nIHRvIGVhdCB0aGUgZmluZXN0IGN1cnJ5ISIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjIyLjUsCiAgICAgICAgICAgICAgICJlbmQiOjI3LAogICAgICAgICAgICAgICAidGV4dCI6IkFuZCBJIHdpbGwgZ2l2ZSB5b3UgdGhlIGZpbmVzdCBwZXNod2FyaSBuYWFuISIKICAgICAgICAgICAgfQogICAgICAgICBdCiAgICAgIH0sCiAgICAgIHsKICAgICAgICAgImlkIjoiMDMiLAogICAgICAgICAiY3VlcyI6WwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MC41LAogICAgICAgICAgICAgICAiZW5kIjoxLjYsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiSSB3aXNoIEkgY291bGQgc2hvdyB5b3UgdGhlIHdheSEiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgInN0YXJ0IjoxLjcsCiAgICAgICAgICAgICAgICJlbmQiOjQuMywKICAgICAgICAgICAgICAgInRleHQiOiJXaGF0Li4uIHdpdGggYSBwZXNod2FyaSBuYWFuPyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjUsCiAgICAgICAgICAgICAgICJlbmQiOjkuNSwKICAgICAgICAgICAgICAgInRleHQiOiJZb3UndmUgZ29uZSBhbmQgZG9uZSBpdC4gIFlvdSd2ZSB0b29rIG15IGRpZ25pdHkgZnJvbSBtZSEiCiAgICAgICAgICAgIH0KICAgICAgICAgXQogICAgICB9LAogICAgICB7CiAgICAgICAgICJpZCI6IjA0IiwKICAgICAgICAgImN1ZXMiOlsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjQuOCwKICAgICAgICAgICAgICAgImVuZCI6NiwKICAgICAgICAgICAgICAgInRleHQiOiJHb3QgYW55IHBlc2h3YXJpIG5hYW5zPyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjYuMSwKICAgICAgICAgICAgICAgImVuZCI6OC4xLAogICAgICAgICAgICAgICAidGV4dCI6IkkgZG8gbm90IHNlbGwgc2hpdC4iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgInN0YXJ0Ijo4LjgsCiAgICAgICAgICAgICAgICJlbmQiOjExLAogICAgICAgICAgICAgICAidGV4dCI6IllvdSwgbXkgc29uLCBoYXZlIG5vdCBiZWVuIGVubGlnaHRlbmVkISIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjExLjYsCiAgICAgICAgICAgICAgICJlbmQiOjEzLAogICAgICAgICAgICAgICAidGV4dCI6IkJhaGhoaCEiCiAgICAgICAgICAgIH0KICAgICAgICAgXQogICAgICB9LAogICAgICB7CiAgICAgICAgICJpZCI6IjA1IiwKICAgICAgICAgImN1ZXMiOlsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjAuOSwKICAgICAgICAgICAgICAgImVuZCI6NS45LAogICAgICAgICAgICAgICAidGV4dCI6IldoYXQgZG8geW91IHRoaW5rIGhlJ3MgZ290IHBsYW5uZWQ_IgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6Ni4zLAogICAgICAgICAgICAgICAiZW5kIjo5LjQsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiSSdtIG5vdCBzdXJlLCBidXQgSSBrbm93IGhlJ3MgbmVhcmJ5Li4uIgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6OS40LAogICAgICAgICAgICAgICAiZW5kIjoxNiwKICAgICAgICAgICAgICAgInRleHQiOiJIYXZlIHlvdSBkcm9wcGVkIHlvdXIgZ3V0cz8gIEl0IHN0aW5rcyB0byBraW5nZG9tIGNvbWUuICBJIHN3ZWFyIHRvIEdvZCBpZiB5b3UgaGF2ZSBJJ2xsIGhhbmQgeW91IHlvdXIgYXNzISIKICAgICAgICAgICAgfQogICAgICAgICBdCiAgICAgIH0sCiAgICAgIHsKICAgICAgICAgImlkIjoiMDYiLAogICAgICAgICAiY3VlcyI6WwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MC42LAogICAgICAgICAgICAgICAiZW5kIjoxLjksCiAgICAgICAgICAgICAgICJ0ZXh0IjoiVGVsbCBtZSB3aGF0IGhlIHdhbnRzPyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjIsCiAgICAgICAgICAgICAgICJlbmQiOjYuOCwKICAgICAgICAgICAgICAgInRleHQiOiJQbGVhc2UganVzdCBsaXN0ZW4gdG8gaGltLCBoZSBzYXlzIHJhaXNpbnMsIHN1Z2FyIGFuZCBjb2NvbnV0IGdvIGdyZWF0IGluIGJyZWFkISIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjgsCiAgICAgICAgICAgICAgICJlbmQiOjE4LAogICAgICAgICAgICAgICAidGV4dCI6IkhlIGNvbWVzIGhlcmUsIHRlbGxzIG1lIHRoYXQgc2hpdCwgYW5kIGV4cGVjdHMgbWUgdG8gYmVsaWV2ZSBoaW0_ICBJIGdvaW5nIHRvIHRocm93IGhpbSBmcm9tIHRoZSByb29mISIKICAgICAgICAgICAgfQogICAgICAgICBdCiAgICAgIH0sCiAgICAgIHsKICAgICAgICAgImlkIjoiMDciLAogICAgICAgICAiY3VlcyI6WwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MC4zLAogICAgICAgICAgICAgICAiZW5kIjo2LAogICAgICAgICAgICAgICAidGV4dCI6IllvdSBrbm93IHRoZXJlIGFyZSBzb21lIHBlb3BsZSBvdXQgdGhlcmUgd2hvIHRoaW5rIHBlc2h3YXJpIG5hYW5zIGFyZSBpbmNyZWRpYmxlPyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjExLAogICAgICAgICAgICAgICAiZW5kIjoxNS45LAogICAgICAgICAgICAgICAidGV4dCI6IldobyBvbiBFYXJ0aCB0b2xkIHRoZW0gdGhhdCBzaGl0PyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjE3LAogICAgICAgICAgICAgICAiZW5kIjoyMiwKICAgICAgICAgICAgICAgInRleHQiOiJNZSEhICBCZWNhdXNlIEkgYW0gYSBiYXN0YXJkISIKICAgICAgICAgICAgfQogICAgICAgICBdCiAgICAgIH0sCiAgICAgIHsKICAgICAgICAgImlkIjoiMDgiLAogICAgICAgICAiY3VlcyI6WwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MC4xLAogICAgICAgICAgICAgICAiZW5kIjozLjYsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiTXkgc2VjcmV0IHJlY2lwZSBmb3IgcGVzaHdhcmkgbmFhbnMgaXMgbmVhcmx5IGNvbXBsZXRlISIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjMuOSwKICAgICAgICAgICAgICAgImVuZCI6NS41LAogICAgICAgICAgICAgICAidGV4dCI6IllvdSBkbyBrbm93IG5vIG9uZSBnaXZlcyBhIHNoaXQsIHJpZ2h0PyIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjksCiAgICAgICAgICAgICAgICJlbmQiOjkuOCwKICAgICAgICAgICAgICAgInRleHQiOiJJJ20gdGVsbGluZyB5b3UsIG5vIG9uZSEiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgInN0YXJ0IjoxMCwKICAgICAgICAgICAgICAgImVuZCI6MTMsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiSnVzdCB5b3Ugd2FpdCBhbmQgc2VlISAgR29kIGJsZXNzIHlvdSEiCiAgICAgICAgICAgIH0KICAgICAgICAgXQogICAgICB9LAogICAgICB7CiAgICAgICAgICJpZCI6IjA5IiwKICAgICAgICAgImN1ZXMiOlsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjExLjcsCiAgICAgICAgICAgICAgICJlbmQiOjE1LjgsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiTGV0J3MgZ28gZ2V0IGEgY3VycnksIHNraW5ueSBsZWdzISIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjE2LAogICAgICAgICAgICAgICAiZW5kIjoyMC41LAogICAgICAgICAgICAgICAidGV4dCI6IkJ1dCBjdXJyaWVzIHJvdCBteSBndXRzLCBJJ2xsIHNwZW5kIGFsbCBuaWdodCBvbiB0aGUgdG9pbGV0ISIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjIzLAogICAgICAgICAgICAgICAiZW5kIjoyNi41LAogICAgICAgICAgICAgICAidGV4dCI6IkJ1dCBJIGtub3cgd2hhdCB3aWxsIHNldHRsZSBpdCEgIEEgc3dlZXQgcGVzaHdhcmkgbmFhbiEgIEkgcHJvbWlzZSEiCiAgICAgICAgICAgIH0KICAgICAgICAgXQogICAgICB9LAogICAgICB7CiAgICAgICAgICJpZCI6IjEwIiwKICAgICAgICAgImN1ZXMiOlsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAic3RhcnQiOjUsCiAgICAgICAgICAgICAgICJlbmQiOjguOCwKICAgICAgICAgICAgICAgInRleHQiOiJIYWhhLCBhcmUgeW91IHRyeWluZyB0byBidXJuIG9mZiB0aGF0IGZhdC1ib3kgY3Vycnk_IgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MTEuMywKICAgICAgICAgICAgICAgImVuZCI6MTMuMywKICAgICAgICAgICAgICAgInRleHQiOiJTbyB3aGF0IGlmIEkgYW0_IgogICAgICAgICAgICB9LAogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICJzdGFydCI6MTQuOCwKICAgICAgICAgICAgICAgImVuZCI6MTgsCiAgICAgICAgICAgICAgICJ0ZXh0IjoiSXQncyBwb2ludGxlc3MuICBPbmNlIGdoZWUgc3RpY2tzIHRvIHlvdXIgYm9uZXMgeW91IGFpbid0IG5ldmVyIGdldHRpbmcgcmlkISIKICAgICAgICAgICAgfQogICAgICAgICBdCiAgICAgIH0KICAgXQp9';
const _max_length_of_caption = 200;
/*
Returns a value from the querystring
Null in the case of exception or missing
*/
function getQueryStringParam(paramName)
{
returnVal = null;
try
{
const urlParams = new URLSearchParams(window.location.search);
const paramValue = urlParams.get(paramName);
returnVal = paramValue;
}
catch (e)
{
returnVal = null;
}
return returnVal;
}
/*
Runs when the page is first started and is used to generate the page content based on requested context
*/
function startUp()
{
try
{
const pageParam = getQueryStringParam('p');
if (pageParam == 'Create')
{
generateCreate();
}
else if (pageParam == 'Play')
{
generatePlayer();
}
else
{
generateFrontPage();
}
}
catch (e)
{
dumpError(e);
}
}
/*
Displays front page content, used when the context is not one of Play or Create
*/
function generateFrontPage()
{
try
{
document.getElementById('BodyContents').innerHTML = '<div class="body-text">In 2002, fanta.dk ran a promo website for Fanta Shokata which allowed visitors to create their own funny movies based on scenes from Indian movies. Sadly, the site ceased to be in early 2003 and took all the videos people made with it.<br /><br />This page was created in respect of that work, leveraging some content from archive.org, some reverse-engineering of the original Shockwave Flash content, some videos found on YouTube (thanks <a href="https://www.youtube.com/@ShadowEffex" target="_new">ShadowFX</a>) and some of my own scrappy HTML (I\'m talking tables for positioning AND css AND divs AND spans), JavaScript and image editing to fill the gaps.<br /><br />It is meant to be a little fun. Please treat it as such, and if you find any bugs with the site, please contact me below.<br /><br /><br /><br /><b>This site has no affiliation with Fanta.</b><br />\'Fanta\' and Fanta Shokata are trademarks of The Coca-Cola Company. (c) 2002 The Coca-Cola Company.<br /><br /><br />With all that said, go create your own movies by clicking MAKE MOVIES at the top right!</div>';
}
catch (e)
{
dumpError(e);
}
}
/*
Briefs out any error to the user, hopefully useful in debugging
*/
function dumpError(e)
{
try
{
document.getElementById('BodyContents').innerHTML = '<span class="body-text">There was an error processing the request.<br /><br />The error was:<br />' + e.message + '</span>';
}
catch(x)
{
// Jeez just messagbox it
window.alert(x.message);
}
}
/*
Returns the JSON structure relating to the videoId passed in
or NULL in the event of error
*/
function getCaptionContent(videoId)
{
returnVal = null;
try
{
// Decode the default captions
rawCaptions = base64URLdecode(_captions);
// Parse the baseline JSON and then the content
jsonCaptions = JSON.parse(rawCaptions);
// Set the captions
for (let videoIndex = 0; videoIndex < jsonCaptions['videos'].length; videoIndex++)
{
let currentVideo = jsonCaptions['videos'][videoIndex];
if (currentVideo['id'] == videoId)
{
returnVal = currentVideo;
break;
}
}
}
catch(e)
{
dumpError(e);
returnVal = null;
}
return returnVal;
}
/*
Generates the player page
by...
Pulling out the 'c' querystring parameter and getting the supplied JSON
Renders a video player on the screen
Sets the player to the video within the supplied JSON
Adds the captions to the video with the known timestamps, but with cues in the supplied JSON
*/
function generatePlayer()
{
try
{
// Get the content from the query string
contentParam = getQueryStringParam('c');
contentParam = contentParam || ''
// Test data, uncomment if needed
// contentParam = 'ewogICAiaWQiOiIwMSIsCiAgICJjdWVzIjpbCiAgICAgICJsaW5lIDEiLAogICAgICAibGluZSAyIiwKICAgICAgImxpbmUgMyIKICAgXQp9';
// Decode the Base64URL encoded querystring
rawContent = base64URLdecode(contentParam);
// Parse it into a JSON object
jsonContent = JSON.parse(rawContent);
// And pull out the requsted video ID
videoId = jsonContent['id'];
// Now go off and find the baseline data for this video id
captionContent = getCaptionContent(videoId);
if (captionContent == null)
{
throw new Error('The requested Video ID was not found in the baseline list!');
}
// Create the movie player
document.getElementById('BodyContents').innerHTML = '<div class="movie-span"><video controls id="VideoPlayer" class="video-player" preload="metadata"><source id="VideoSource" src="" type="video/mp4"></video></div>';
// Set the source and load it
document.getElementById('VideoSource').src = 'v/Fanta Shokata - Clip ' + videoId + '.mp4#t=0.2';
document.getElementById('VideoPlayer').load();
// Set the captions
let video = document.getElementById("VideoPlayer");
// Create a track
let track = video.addTextTrack("captions", "Captions", "en");
// Now iterate the cues within the definition
for (let cueIndex = 0; cueIndex < captionContent['cues'].length; cueIndex++)
{
let currentCue = captionContent['cues'][cueIndex];
// Using the cuetext from within the querystring, trim if necessary
cueText = jsonContent['cues'][cueIndex] || '';
cueText = cueText.substring(0, _max_length_of_caption);
// Create a cue, with known values which work for the video size and position
let cue = new VTTCue(currentCue['start'], currentCue['end'], cueText);
cue.position = 50;
cue.align = "center";
cue.size = 80;
cue.snapToLines = true; // line works in % downwards
cue.line = 12;
// Add the cue to the track
track.addCue(cue);
}
track.mode = "showing";
// And start it playing, not supported by browsers
//document.getElementById('VideoPlayer').play();
}
catch (e)
{
dumpError(e);
}
}
/*
Creates the Make Movies page
*/
function generateCreate()
{
try
{
// Render a drop down
dropDown = '<select id="VideoSelect" onchange="UpdateForVideo(this)" class="body-text">'
// Decode the default captions
rawCaptions = base64URLdecode(_captions);
// Parse the baseline JSON and then the content
jsonCaptions = JSON.parse(rawCaptions);
dropDown = dropDown + '<option class="body-text" value="">Select Clip</option>';
// Add all the known videos to the drop down
for (let videoIndex = 0; videoIndex < jsonCaptions['videos'].length; videoIndex++)
{
let currentVideo = jsonCaptions['videos'][videoIndex];
dropDown = dropDown + '<option class="body-text" value="' + currentVideo['id'] + '">Clip ' + currentVideo['id'] + '</option>';
}
dropDown = dropDown + '</select>';
// Materialise it, and set the selected index to the blank one at the top
document.getElementById('BodyContents').innerHTML = dropDown + '<br /><br /><div id="CreateContents" class="createvideo-div"></div>';
document.getElementById('VideoSelect').selectedIndex = 0;
}
catch (e)
{
dumpError(e);
}
}
/*
Updates the Make Movies page with details relevant for the video
*/
function UpdateForVideo(selectedItem)
{
// At this point we have an identifier, i.e. 01, 02, 10 in selectedItem.value
// Build form which includes a video player, as many text boxes as needed for the video in question
// Pre-populate everything and include a button for test. Also include a button for generate a link
try
{
if (selectedItem.value == '')
{
// Cope with the user going back to 'Select Clip'
document.getElementById('CreateContents').innerHTML = '';
}
else
{
createContent = '<div class="movie-span"><video controls id="VideoPreview" class="video-player" preload="metadata"><source id="VideoPreviewSource" src="" type="video/mp4"></video></div>';
// Now go off and find the baseline data for this video id
captionContent = getCaptionContent(selectedItem.value);
if (captionContent == null)
{
throw new Error('The requested Video ID was not found in the baseline list!');
}
// Found the video, build a rudimentary form
for (let cueIndex = 0; cueIndex < captionContent['cues'].length; cueIndex++)
{
let currentCue = captionContent['cues'][cueIndex];
createContent = createContent + '<br /><div class="movie-span">Caption ' + (cueIndex + 1).toString() + ': <input class="body-text" maxlength="' + _max_length_of_caption.toString() + '" size="60" type="text" id="cue' + cueIndex.toString() + '" value="' + currentCue['text'] + '"></input></div>';
}
createContent = createContent + '<br /><div class="movie-span"><input type="button" class="body-text" value="Preview" onclick="PreviewVideo(\'' + selectedItem.value + '\')" /> <input type="button" class="body-text" value="Share" onclick="ShareVideo(\'' + selectedItem.value + '\')" /></div><br /><br /><div class="movie-span" id="ShareDiv"></div>';
document.getElementById('CreateContents').innerHTML = createContent;
// Set the source and load it
document.getElementById('VideoPreviewSource').src = 'v/Fanta Shokata - Clip ' + selectedItem.value + '.mp4#t=0.2';
document.getElementById('VideoPreview').load();
// Add a track, cues will be generated when the preview button is pressed.
let track = document.getElementById('VideoPreview').addTextTrack("captions", "Captions", "en");
track.mode = "showing";
}
}
catch (e)
{
dumpError(e);
}
}
function PreviewVideo(selectedVideo)
{
try
{
// Get rid of existing cues for the baseline track
track = document.getElementById("VideoPreview").textTracks[0];
track.mode = "hidden";
while (track.cues.length)
{
track.removeCue(track.cues[0]);
}
// Now add the new cues based on what is in the text boxes
// Now go off and find the baseline data for this video id
captionContent = getCaptionContent(selectedVideo);
if (captionContent == null)
{
throw new Error('The requested Video ID was not found in the baseline list!');
}
let video = document.getElementById("VideoPreview");
// Now iterate the cues within the definition
for (let cueIndex = 0; cueIndex < captionContent['cues'].length; cueIndex++)
{
let currentCue = captionContent['cues'][cueIndex];
// Swap out the definition's text for the value in the content, trim if necessary
cueText = document.getElementById('cue' + cueIndex.toString()).value || '';
cueText = cueText.substring(0, _max_length_of_caption);
// Create a cue, with known values which work for the video size and position
let cue = new VTTCue(currentCue['start'], currentCue['end'], cueText);
cue.position = 50;
cue.align = "center";
cue.size = 80;
cue.snapToLines = true; // line works in % downwards
cue.line = 12;
// Add the cue to the track
track.addCue(cue);
}
track.mode = "showing";
// And start it playing
document.getElementById('VideoPreview').currentTime = 0;
document.getElementById('VideoPreview').play();
}
catch (e)
{
dumpError(e)
}
}
/*
Generates a share link and gives it to the user
*/
function ShareVideo(selectedVideo)
{
try
{
// Quickly build some JSON
outputJson = '{"id":"' + selectedVideo + '","cues":[';
// Iterate every cue textbox within the DOM
cueCounter = 0;
while (document.getElementById('cue' + cueCounter.toString()) != null)
{
if (cueCounter > 0)
{
outputJson = outputJson + ',';
}
// Get the value of the textbox, trim if necessary - safeguard double quotes for JSON
cueText = document.getElementById('cue' + cueCounter.toString()).value || '';
cueText = cueText.substring(0, _max_length_of_caption).replaceAll('"', '\\"');
outputJson = outputJson + '"' + cueText + '"';
cueCounter++;
}
// Finish the JSON off
outputJson = outputJson + ']}';
console.log(outputJson);
// Encode it
outputJsonEncoded = base64URLencode(outputJson);
console.log(outputJsonEncoded);
// Generate a URL for everyone
url = window.location.href.split('?')[0] + "?p=Play&c=" + outputJsonEncoded;
// Output it
document.getElementById('ShareDiv').innerHTML = '<b>Your unique <a href="' + url + '" target="_new">Share URL</a> is:<br /><textarea id="shareURL" rows="10" cols="70">' + url + '</textarea><br /><button class="body-text" onclick="copyShareURL()">Copy Share URL</button>';
}
catch (e)
{
dumpError(e)
}
}
/*
Copies the URL to the clipboard
*/
function copyShareURL()
{
try
{
// Get the text field
var copyText = document.getElementById("shareURL");
// Select the text field
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
// Copy the text inside the text field
navigator.clipboard.writeText(copyText.value);
}
catch (e)
{
// Just sack it off...
}
}
/*
Helper function to encode JSON into a base64 string suitable for the querystring
*/
function base64URLencode(str)
{
//const utf8Arr = new TextEncoder().encode(str);
//const base64Encoded = btoa(utf8Arr);
const base64Encoded = btoa(str);
return base64Encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
/*
Helper function to decode base64url data into its underlying content
*/
function base64URLdecode(str)
{
const base64Encoded = str.replace(/-/g, '+').replace(/_/g, '/');
const padding = str.length % 4 === 0 ? '' : '='.repeat(4 - (str.length % 4));
const base64WithPadding = base64Encoded + padding;
return atob(base64WithPadding)
.split('')
.map(char => String.fromCharCode(char.charCodeAt(0)))
.join('');
}
</script>
</body>
</html>