-
Notifications
You must be signed in to change notification settings - Fork 0
/
ardatube.html
1003 lines (877 loc) · 29.5 KB
/
ardatube.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
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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="h-100 w-100">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/css/tachyons.min.css"/>
<style media="screen">
#keyboard {
max-width: 44rem;
display: grid;
grid-template-columns: repeat(48, 1fr);
grid-template-rows: repeat(5, 3rem);
grid-gap: 0.2rem;
margin: auto;
}
.key {
grid-column: span 4;
border-radius: .25rem;
text-align: center;
/*display: flex;*/
/*flex-flow: column;*/
/*justify-content: center;*/
padding-top: .3rem;
}
.arrowkey {
grid-column: span 4;
}
#ArrowUp {
grid-row: 4;
}
#ArrowUp, #ArrowDown {
grid-column: 41 / span 4;
}
#ArrowLeft { grid-column: 37 / span 4; }
#ArrowRight { grid-column: 45 / span 4; }
#KeyQ { grid-column: 2 / span 4; }
#KeyA { grid-column: 3 / span 4; }
#KeyZ { grid-column: 4 / span 4; }
#Slash { grid-column: 35 / span 4; }
#Space { grid-column: 12 / span 20;}
.row5 { grid-row: 5;}
.row5 { grid-row: 5;}
.row5 { grid-row: 5;}
.gridspan3 { grid-column: span 3; }
.desc { font-style: italic; font-weight: 900;}
.activekey {
transition: all 0.07s ease-in-out;
}
.activekey:hover {
transform: scale(1.2);
box-shadow: 0 .2rem .25rem rgba(0,0,0,0.1);
}
.activekey:active {
transform: scale(1.1);
box-shadow: 0 .2rem .25rem rgba(0,0,0,0.2);
}
.keydown {
transition: 0s !important;
transform: stcale(1) !important;
box-shadow: inset 0 .1rem .5rem rgba(0,0,0,0.7) !important;
}
#heightRegulator {
width: 100%;
height: 56.25vw;
max-height: 100%;
}
#widthRegulator {
max-width: calc(16 / 9 * 100vh);
height: 100%;
}
}
</style>
<body class="sans-serif bg-near-black h-100 w-100" onload="">
<div class="bg-navy">
<div class="lh-copy ph4 pt1 pb3 fw4 light-gray mw7 center">
<h1 class="f2 fw4 measure-wide">Hi there! Thanks for checking out <i class="fw7">ardatube</i>.</h1>
<h3 class="fw4 measure-wide">Ardatube is an opinionated wrapper for YouTube, curing what I see as its main pain points:</h3>
<ul class="lh-copy measure-wide">
<li class="pb2">the video isn't <b>FULL WIDTH</b> on the page. c'mon youtube, why do you have such large padding?!</b></li>
<li class="pb2">there are no keyboard controls for <b>video quality</b> or <b>playback speed</b></li>
<li class="pb2">comments, descriptions, and other features are often distracting</li>
<li class="pb2">the related videos have no quality indication (several browser extensions exist to solve this)</li>
</ul>
<h3 class="fw4 measure-wide"><i class="fw7">ardatube</i> aims to rectify this. Alas, it is still a work in progress—many of the features are not yet complete. </h3>
<h3 class="fw4 measure-wide">For the full list of features in development, <a href="https://github.com/arda-/ardatube/issues" class="fw5 white">check out the issues page on github</a>; while you're here, play around and enjoy!</h3>
</div>
</div>
<div class="white" id="heightRegulator">
<div class="bg-green h4 center" id="widthRegulator">
<div id="player"></div>
</div>
</div>
<div id="overlay w-100 relative z-0">
<div id="keyInfoBox" class="sans-serif near-white measure h4 center">
<h3 class="fw4 avenir measure tc pa0 ma0 mt4">Here are the available keyboard shortcuts. Hover over a key for an explanation. Press the key, or click the on-screen key to see it in action.</h3>
</div>
<div id="keyboard" class="">
<div id="Digit1"
class="key activekey pointer bg-blue">
<div>1</div>
<div class="desc">10%</div>
</div>
<div id="Digit2" class="key activekey pointer bg-blue">
<div>2</div>
<div class="desc">20%</div>
</div>
<div id="Digit3" class="key activekey pointer bg-blue">
<div>3</div>
<div class="desc">30%</div>
</div>
<div id="Digit4" class="key activekey pointer bg-blue">
<div>4</div>
<div class="desc">40%</div>
</div>
<div id="Digit5" class="key activekey pointer bg-blue">
<div>5</div>
<div class="desc">50%</div>
</div>
<div id="Digit6" class="key activekey pointer bg-blue">
<div>6</div>
<div class="desc">60%</div>
</div>
<div id="Digit7" class="key activekey pointer bg-blue">
<div>7</div>
<div class="desc">70%</div>
</div>
<div id="Digit8" class="key activekey pointer bg-blue">
<div>8</div>
<div class="desc">80%</div>
</div>
<div id="Digit9" class="key activekey pointer bg-blue">
<div>9</div>
<div class="desc">90%</div>
</div>
<div id="Digit0" class="key activekey pointer bg-blue">
<div>0</div>
<div class="desc">0%</div>
</div>
<div id="Minus" class="key activekey pointer bg-gold">
<div class="desc">−</div>
<div class="desc">vol</div>
</div>
<div id="Equal" class="key activekey pointer bg-gold">
<div class="desc">+</div>
<div class="desc">vol</div>
</div>
<div id="KeyQ" class="key activekey pointer bg-dark-red black">
<div>Q</div>
<div class="desc">quit</div>
</div>
<div id="KeyW" class="key bg-silver ">W</div>
<div id="KeyE" class="key bg-silver ">E</div>
<div id="KeyR" class="key bg-silver ">R</div>
<div id="KeyT" class="key bg-silver ">T</div>
<div id="KeyY" class="key bg-silver ">Y</div>
<div id="KeyU" class="key bg-silver ">U</div>
<div id="KeyI" class="key bg-silver ">I</div>
<div id="KeyO" class="key bg-silver ">O</div>
<div id="KeyP" class="key bg-silver ">P</div>
<div id="BracketLeft" class="key bg-silver gridspan3">[</div>
<div id="BracketRight" class="key bg-silver gridspan3">]</div>
<div id="KeyA" class="key bg-silver ">A</div>
<div id="KeyS" class="key activekey pointer bg-light-green">
<div>S</div>
<div class="desc">src</div>
</div>
<div id="KeyD" class="key bg-silver ">D</div>
<div id="KeyF" class="key activekey pointer bg-light-pink">
<div>F</div>
<div class="desc">full</div>
</div>
<div id="KeyG" class="key pointer bg-silver ">G</div>
<div id="KeyH" class="key activekey pointer bg-blue">
<div>H</div>
<div class="desc">-30s</div>
</div>
<div id="KeyJ" class="key activekey pointer bg-blue">
<div>J</div>
<div class="desc">-10s</div>
</div>
<div id="KeyK" class="key activekey pointer bg-light-blue">
<div>K</div>
<div class="fw9">▶/ ❙❙</div>
</div>
<div id="KeyL" class="key activekey pointer bg-blue">
<div>L</div>
<div class="desc">+10s</div>
</div>
<div id="Semicolon" class="key activekey pointer bg-blue">
<div>;</div>
<div class="desc">+30s</div>
</div>
<div id="Quote" class="key pointer bg-silver gridspan3">'</div>
<div id="KeyZ" class="key pointer bg-silver ">Z</div>
<div id="KeyX" class="key pointer bg-silver ">X</div>
<div id="KeyC" class="key pointer bg-silver ">C</div>
<div id="KeyV" class="key pointer bg-silver ">V</div>
<div id="KeyB" class="key activekey pointer bg-light-purple">
<div>B</div>
<div class="desc">prev</div>
</div>
<div id="KeyN" class="key activekey pointer bg-light-purple">
<div>N</div>
<div class="desc">next</div>
</div>
<div id="KeyM" class="key activekey pointer bg-gold">
<div>M</div>
<div class="desc">mute</div>
</div>
<div id="Slash" class="key activekey pointer bg-orange">
<div>?</div>
<div class="desc">help</div>
</div>
<div id="ArrowUp" class="key activekey pointer bg-pink arrowkey">
<div>▲</div>
<div class="desc">qual</div>
</div>
<div id="Space"
class="key activekey pointer bg-light-blue row5">
<div>space</div>
<div class="fw9">▶/ ❙❙</div>
</div>
<div id="ArrowLeft" class="key activekey pointer bg-light-blue row5 arrowkey">
<div>◀</div>
<div class="desc">slow</div>
</div>
<div id="ArrowDown" class="key activekey pointer bg-pink row5 arrowkey">
<div>▼</div>
<div class="desc">qual</div>
</div>
<div id="ArrowRight" class="key activekey pointer bg-light-blue row5 arrowkey">
<div>▶</div>
<div class="desc">ffw</div>
</div>
</div>
</div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var sourceURL = "https://www.youtube.com/watch?v=M7lc1UVf-VE";
var youtubeSourceTag = "M7lc1UVf-VE";
var timeToStart = 0;
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: 'M7lc1UVf-VE',
playerVars: {
'autoplay': 1,
'controls': 1,
'iv_load_policy': 3,
'enablejsapi': 1,
'disablekb':1, // disables keyboard
'rel': 0, // disables showing related video
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onPlaybackQualityChange': onQualChange,
},
width: '100%',
height: '100%',
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stop, 610000);
done = true;
}
}
function onSpeedChange(event) {
showFeedback("speed: " + player.getPlaybackRate() + "x");
}
function onQualChange(event) {
showFeedback("vid quality: " + player.getPlaybackQuality());
}
// ==== playback functions ====
function togglePlay() {
var state = player.getPlayerState();
console.log(state==1);
switch (state) {
case -1: case 0:
showFeedback("play");
skipTo(0);
break;
case 1: // playing
showFeedback("pause");
player.pauseVideo();
break;
case 2: // unstarted, stopped, or paused
showFeedback("play");
player.playVideo();
break;
default:
}
}
function skip(delta) {
player.seekTo(player.getCurrentTime() + delta, true);
showFeedback("skip " + delta + " s");
}
function skipTo(intFromZeroToTen) {
player.seekTo(intFromZeroToTen * (player.getDuration() / 10));
showFeedback("skip to " + intFromZeroToTen + "/10 of video");
}
function speedUp() {
var rates = player.getAvailablePlaybackRates();
if ( rates.length > 1) {
var currentSpeed = player.getPlaybackRate();
var currentSpeedIndex = rates.indexOf(currentSpeed);
var maxSpeedIndex = rates.length - 1;
if (currentSpeedIndex != maxSpeedIndex) {
var newPlaybackRate = rates[currentSpeedIndex + 1];
player.setPlaybackRate(newPlaybackRate);
// showFeedback("speed: " + newPlaybackRate + "x");
// ^^^ the above occurs in the onSpeechChange function instead,
// according to YouTube's API recommendations
// https://developers.google.com/youtube/iframe_api_reference#onPlaybackRateChange
} else {
showFeedback("can't go faster than speed: " + currentSpeed + "x");
}
} else {
showFeedback("video does not allow ffw");
}
}
function slowDown() {
var rates = player.getAvailablePlaybackRates();
if ( rates.length > 1) {
var currentSpeed = player.getPlaybackRate();
var currentSpeedIndex = rates.indexOf(currentSpeed);
var maxSpeedIndex = rates.length - 1;
if (currentSpeedIndex != 0) {
var newPlaybackRate = rates[currentSpeedIndex - 1];
player.setPlaybackRate(newPlaybackRate);
// showFeedback("speed: " + newPlaybackRate + "x");
// ^^^ the above occurs in the onSpeechChange function instead,
// according to YouTube's API recommendations
// https://developers.google.com/youtube/iframe_api_reference#onPlaybackRateChange
} else {
showFeedback("can't go slower than speed: " + currentSpeed + "x");
}
} else {
showFeedback("video does not allow slow playback");
}
}
// ==== volume functions ====
function toggleMute() {
switch (player.isMuted()) {
case true: // playing
showFeedback("m = unmute");
player.unMute();
break;
case false: // paused
showFeedback("m = mute");
player.mute();
player.setVolume(0);
break;
default:
}
}
function volumeUp() {
if (player.isMuted()) {
player.unMute();
player.setVolume(20);
showFeedback("Vol = 20");
return;
}
var vol = player.getVolume();
if ( vol < 100) {
vol += 20;
player.setVolume(vol);
}
showFeedback("Vol = " + vol);
}
function volumeDown() {
if (player.isMuted()) {
showFeedback("Vol = 0");
return;
}
var vol = player.getVolume();
if ( vol > 0) {
vol -= 20;
player.setVolume(vol);
}
showFeedback("Vol = " + vol);
}
// ==== quality functions ====
function qualityUp() {
var qualities = player.getAvailableQualityLevels();
if ( qualities.length > 1) {
var curQual = player.getPlaybackQuality();
var curQualIndex = qualities.indexOf(curQual);
if (curQualIndex != 0) {
var newQual = qualities[curQualIndex - 1];
player.setPlaybackQuality(newQual);
} else {
showFeedback("no higher quality than: " + curQual);
}
} else {
showFeedback("this is the only video quality available");
}
}
function qualityDown() {
var qualities = player.getAvailableQualityLevels();
if ( qualities.length > 1) {
var curQual = player.getPlaybackQuality();
var curQualIndex = qualities.indexOf(curQual);
var minQualIndex = qualities.length - 2;
if (curQualIndex != minQualIndex) {
var newQual = qualities[curQualIndex + 1];
player.setPlaybackQuality(newQual);
} else {
showFeedback("no lower quality than: " + curQual);
}
} else {
showFeedback("this is the only video quality available");
}
}
// ==== OTHER FUNCTIONS
function showKeyInfo(key) {
var entry = activeKeyMap[key]
if (entry == undefined) {
console.log("couldn't find "+key+" in activeKeyMap.")
} else {
renderKeyInfoBlurb(entry.char, entry.name, entry.blurb);
}
}
function renderKeyInfoBlurb(key, name, blurb) {
element = document.getElementById('keyInfoBox');
previousBlurb = document.getElementById('keyInfoContent');
if (previousBlurb != undefined) removeKeyInfo();
if (key == "K" || key == "space") {
var htmlstr =
'<p class="lh-copy measure center" id="keyInfoContent">'
+ key + ' : <span class="fw9">'
+ name + '</span><br>'
+ blurb + '</p></div>';
} else {
var htmlstr =
'<p class="lh-copy measure center" id="keyInfoContent">'
+ key + ' : <i class="fw9">'
+ name + '</i><br>'
+ blurb + '</p></div>';
}
element.insertAdjacentHTML('beforeend',htmlstr);
}
function removeKeyInfo() {
keyInfoBox = document.getElementById('keyInfoBox');
keyInfoContent = document.getElementById('keyInfoContent');
keyInfoBox.removeChild(keyInfoContent);
}
// ==== feedback helper functions ====
function showFeedback(message) {
element = document.getElementById('feedbackDiv');
if (element) removeFeedback();
var htmlstr =
"<div id='feedbackDiv' class='dib white bg-black-50 sans-serif pa1 br2'>"
+ message +
"</div>";
document.body.insertAdjacentHTML('beforeend',htmlstr);
setTimeout(removeFeedback, 700);
}
function removeFeedback() {
element = document.getElementById('feedbackDiv');
document.body.removeChild(element);
}
function goToSource() {
window.open(sourceURL, "_self");
}
// ==== key mappings objects =====
var activeKeyMap = {
'Digit1': {
'char': "1",
'name': "10%",
'blurb': "skip to 10% in the video.",
},
'Digit2': {
'char': "2",
'name': "20%",
'blurb': "skip to 20% in the video.",
},
'Digit3': {
'char': "3",
'name': "30%",
'blurb': "skip to 30% in the video.",
},
'Digit4': {
'char': "4",
'name': "40%",
'blurb': "skip to 40% in the video.",
},
'Digit5': {
'char': "5",
'name': "50%",
'blurb': "skip to 50% in the video.",
},
'Digit6': {
'char': "6",
'name': "60%",
'blurb': "skip to 60% in the video.",
},
'Digit7': {
'char': "7",
'name': "70%",
'blurb': "skip to 70% in the video.",
},
'Digit8': {
'char': "8",
'name': "80%",
'blurb': "skip to 80% in the video.",
},
'Digit9': {
'char': "9",
'name': "90%",
'blurb': "skip to 90% in the video.",
},
'Digit0': {
'char': "0",
'name': "0%",
'blurb': "skip to beginning (seek to 0% in the video).",
},
'Minus': {
'char': "<b>−</b>",
'name': "volume down",
'blurb': "decrease volume by 20%",
},
'Equal': {
'char': "<b>+</b>",
'name': "volume up",
'blurb': "increase volume by 20%",
},
'KeyQ': {
'char': "Q",
'name': "quit video",
'blurb': "stops the video and disables playback.",
},
'KeyS': {
'char': "S",
'name': "source",
'blurb': "redirect to the original video.",
},
'KeyF': {
'char': "F",
'name': "fulscreen toggle",
'blurb': "enter or exit fullscreen mode.",
},
'KeyH': {
'char': "H",
'name': "-30s",
'blurb': "seek back 30 seconds in the video, if possible.",
},
'KeyJ': {
'char': "J",
'name': "-10s",
'blurb': "seek back 10 seconds in the video, if possible.",
},
'KeyK': {
'char': "K",
'name': "▶/ ❙❙",
'blurb': "toggle playback of video.",
},
'KeyL': {
'char': "L",
'name': "+10s",
'blurb': "seek forward 10 seconds in the video, if possible.",
},
"Semicolon": {
'char': "<b>;</b>",
'name': "+30s",
'blurb': "seek forward 30 seconds in the video, if possible.",
},
'KeyB': {
'char': "B",
'name': "previous video",
'blurb': "if you've added videos to the ardatube queue, skip to the previous video in the KeyB.",
},
'KeyN': {
'char': "N",
'name': "next video",
'blurb': "if you've added videos to the ardatube queue, skip to the next video in the queue.",
},
'KeyM': {
'char': "M",
'name': "mute toggle",
'blurb': "mute or unmute the volume.",
},
'Slash': {
'char': '?',
'name': "help toggle",
'blurb': "mute or unmute the volume.",
},
"ArrowUp": {
'char': "▲",
'name': "quality up",
'blurb': "increase the resolution of the video, if available.",
},
"ArrowDown": {
'char': "▼",
'name': "quality down",
'blurb': "decrease the resolution of the video, if available.",
},
"Space": {
'char': "space",
'name': "▶/ ❙❙",
'blurb': "toggle playback of video.",
},
"ArrowLeft": {
'char': "◀",
'name': "slow down",
'blurb': "slow the playback speed of the video, if possible.",
},
"ArrowRight": {
'char': "◀",
'name': "fast forward",
'blurb': "slow the playback speed of the video, if possible.",
}
}
var allKeyArray = [
"Digit1",
"Digit2",
"Digit3",
"Digit4",
"Digit5",
"Digit6",
"Digit7",
"Digit8",
"Digit9",
"Digit0",
"Minus",
"Equal", //plus
"KeyQ",
"KeyW",
"KeyE",
"KeyR",
"KeyT",
"KeyY",
"KeyU",
"KeyI",
"KeyO",
"KeyP",
"BracketLeft",
"BracketRight",
"KeyA",
"KeyS",
"KeyD",
"KeyF",
"KeyG",
"KeyH",
"KeyJ",
"KeyK",
"KeyL",
"Semicolon",
"Quote",
"KeyZ",
"KeyX",
"KeyC",
"KeyV",
"KeyB",
"KeyN",
"KeyM",
"Slash", //question
"Space",
"ArrowUp",
"ArrowDown",
"ArrowLeft",
"ArrowRight",
]
var activeKeyArray = [
"Digit1",
"Digit2",
"Digit3",
"Digit4",
"Digit5",
"Digit6",
"Digit7",
"Digit8",
"Digit9",
"Digit0",
"Minus",
"Equal", //plus
"KeyQ",
// mind the gap
"KeyS",
//
"KeyF",
//
"KeyH",
"KeyJ",
"KeyK",
"KeyL",
"Semicolon",
// mind the gap
"KeyB",
"KeyN",
"KeyM",
"Slash", //question
"Space",
"ArrowUp",
"ArrowDown",
"ArrowLeft",
"ArrowRight",
]
var DEBUG = true;
function debugPrint(x) {
if (DEBUG) console.log(x);
}
window.addEventListener("load", init);
function init() {
initKeys()
}
function initKeys() {
for (var i = 0; i < activeKeyArray.length; i++) {
addEventListeners(activeKeyArray[i]);
}
}
// GUI mouse related listeners
function addEventListeners(element) {
keyNode = document.getElementById(element)
keyNode.onmouseover = function() {
showKeyInfo(element);
}
keyNode.onmouseleave = function() {
removeKeyInfo();
}
keyNode.onclick = function() {
keyAction(element);
}
};
// keyboard-related listeners
window.addEventListener("keydown", function(event) {
let str = "KeyboardEvent: key='" + event.key + "' | code='" +
event.code + "'";
console.log(str);
console.log("KEYDOWN " + str);
if (allKeyArray.includes(event.code)) {
switch (event.code) {
case "ArrowUp":
event.preventDefault();
break;
case "ArrowDown":
event.preventDefault();
break;
case "ArrowRight":
event.preventDefault();
break;
case "ArrowLeft":
event.preventDefault();
break;
case "Space":
event.preventDefault();
break;
default:
}
addKeydown(event.code);
keyAction(event.code);
}
}, true);
window.addEventListener("keyup", function(event) {
let str = "KeyboardEvent: key='" + event.key + "' | code='" +
event.code + "'";
console.log("KEYUP " + str);
if (allKeyArray.includes(event.code)) {
removeKeydown(event.code);
}
}, true);
document.onkeydown = function(e) {
e = e || window.event;
var input = e.keyCode || e.which;
}
function addKeydown(keycode) {
var key = document.getElementById(keycode);
key.classList.add('keydown');
}
function removeKeydown(keycode) {
var key = document.getElementById(keycode);
key.classList.remove('keydown')
}
function keyAction(keycode) {
switch (keycode) {
// OTHER CHARS
case "KeyQ":
showFeedback("escape");
player.stopVideo();
break;
case "Slash": // question
// toggle keyboard overlay with help info
break;
case "KeyS": // question
goToSource();
break;
// NUMBERS
case "Digit0":
skipTo(0);
break;
case "Digit1":
skipTo(1);
break;
case "Digit2":
skipTo(2);
break;
case "Digit3":
skipTo(3);
break;
case "Digit4":
skipTo(4);
break;
case "Digit5":
skipTo(5);
break;
case "Digit6":
skipTo(6);
break;
case "Digit7":
skipTo(7);
break;
case "Digit8":
skipTo(8);
break;
case "Digit9":
skipTo(9);
break;
// PLAYBACK CONTROLS
case "Space":
togglePlay();
break;
case "KeyH":
skip(-30);
break;
case "KeyJ":
skip(-10);
break;
case "KeyK":
togglePlay();
break;
case "KeyL":
skip(10);
break;
case "Semicolon":
skip(30);
break;
case "ArrowLeft":
slowDown();
break;
case "ArrowRight":
speedUp();
break;
// VOLUME CONTROLS
case "KeyM":
showFeedback("m = mute")
toggleMute();
break;
case "Equals": // plus
volumeUp();
break;
case "Minus":
volumeDown();
break;
// QUALITY CONTROL
case "ArrowUp":
qualityUp();
break;
case "ArrowDown":
qualityDown();
break;
default:
}
}