-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
2401 lines (2147 loc) · 75.5 KB
/
content.js
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
var insts=[];
var tempInsts=[];
var activeInsts=[];
var dfSpd=2.2;
var dfStp=0.1;
var mbMde=false;
var mbMdeFs=false;
var sks=10;
var skp=4;
var blacklist='';
var sk_buff=false;
var prefPerc=false;
var cvs_clk=0;
var cvs_clkd=false;
var justUp=false;
var doWB=false;
var WB_defMtx,WB_defMtx_JSON,WB_defMtx_flat;
const wb_filt=[" filter: saturate(3.15) contrast(1.74) !important"," filter: saturate(3.12) contrast(1.56) brightness(0.75) !important;"];
let clrMtrx_tag=`<svg xmlns="http://www.w3.org/2000/svg">
<filter id="clrMtrx_svg">
<feColorMatrix type="matrix"
values="${WB_defMtx_flat}">
</feColorMatrix>
</filter>
</svg>`;
let svg_blob = new Blob([clrMtrx_tag], { type: 'image/svg+xml' });
let svg_url = URL.createObjectURL(svg_blob);
WB_defMtx_blob=svg_url;
function hex2rgb(hex) { //Source: https://stackoverflow.com/a/12342275
let h=hex.replace('#', '');
h = h.match(new RegExp('(.{'+h.length/3+'})', 'g'));
for(let j=0, len_j=h.length; j<len_j; j++){
h[j] = parseInt(
(h[j].length==1? h[j]+h[j] : h[j])
, 16
);
}
return h;
}
function showBtns(i){
let bdkCol,txCol,bdkCol2,bdc;
if(i.ff===1){ // Playback rate adj. activated (button green)
bdkCol=["buttonface","#007500"];
txCol=["black","white"];
bdkCol2="#00750080";
bdc="#00750080";
}else{
bdkCol=["buttonface","buttonface"];
txCol=["black","black"];
bdkCol2="#f0f0f080";
bdc='buttonface';
}
let bfStyle="all: initial !important;font-family: system-ui !important;min-width: 42px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0.05ch 0.25ch 0.05ch 0.25ch !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bdkCol[0]+" !important; border-color: buttonface !important; float: initial !important; text-align-last: center !important; color: "+txCol[0]+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
let bfStyle_plp="all: initial !important;font-family: Segoe UI Symbol !important;min-width: 42px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0ch 0ch 0.188ch 0ch !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bdkCol[0]+" !important; border-color: buttonface !important; float: initial !important; text-align-last: center !important; color: "+txCol[0]+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
let ds_i=" display: initial !important;";
let ds_n=" display: none !important;";
i.plp.style.cssText=bfStyle_plp+ds_i;
i.skb.style.cssText=bfStyle+ds_i;
i.skf.style.cssText=bfStyle+ds_i;
if(doWB){
i.tglWB.style.cssText=bfStyle+ds_i+wb_filt[1]+'background: #8a8a8a !important;';
}
if(!sk_buff){
i.skb_l.style.cssText=bfStyle+ds_n;
i.skf_l.style.cssText=bfStyle+ds_n;
}else{
i.skb_l.style.cssText=bfStyle+ds_i;
i.skf_l.style.cssText=bfStyle+ds_i;
}
i.butn.style.cssText = "all: initial !important;font-family: system-ui !important;min-width: 75px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0.05ch 0.25ch 0.05ch 0.25ch !important; display: initial !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bdkCol[1]+" !important; border-color: "+bdc+" !important; float: initial !important; text-align-last: right !important; color: "+txCol[1]+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
i.clse.style.cssText = "all: initial !important;font-family: system-ui !important;-webkit-text-fill-color: #ececec !important;max-width: max-content !important;line-height: 1.91ch !important;transform: translate(0px, 0.06ch) !important;padding: 0em 0.27em 0em 0.27em !important;display: initial !important;visibility: initial !important;background-color: #f00000 !important;float: initial !important;text-align-last: left !important;font-size: unset !important;border-radius: 0% !important;user-select: none !important;margin: 0px !important;min-width: 75px !important;border: 0px !important;color: #ececec !important;";
i.faded=false;
i.fadedBtns=false;
}
function fadeBtns(i){
let bdkCol,txCol,bdkCol2,bdc;
if(i.ff===1){ // Playback rate adj. activated (button green)
bdkCol=["#f0f0f080","#00750080"];
txCol=["black","white"];
bdc=["#007500","#00750080"];
}else{
bdkCol=["#f0f0f080","#f0f0f080"];
txCol=["black","black"];
bdc=["buttonface",'transparent'];
}
let ds_i=" display: initial !important;";
let ds_n=" display: none !important;";
let bfStyle2="all: initial !important;font-family: system-ui !important;min-width: 42px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0.05ch 0.25ch 0.05ch 0.25ch !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bdkCol[0]+" !important; border-color: #00000000 !important; float: initial !important; text-align-last: center !important; color: "+txCol[0]+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
let bfStyle2_plp="all: initial !important;font-family: Segoe UI Symbol !important;min-width: 42px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0ch 0ch 0.188ch 0ch !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bdkCol[0]+" !important; border-color: #00000000 !important; float: initial !important; text-align-last: center !important; color: "+txCol[0]+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
i.plp.style.cssText=bfStyle2_plp+ds_i;
i.skb.style.cssText=bfStyle2+ds_i;
i.skf.style.cssText=bfStyle2+ds_i;
if(doWB){
i.tglWB.style.cssText=bfStyle2+ds_i+wb_filt[0]+'background: #8a8a8a80 !important;';
}
if(!sk_buff){
i.skb_l.style.cssText=bfStyle2+ds_n;
i.skf_l.style.cssText=bfStyle2+ds_n;
}else{
i.skb_l.style.cssText=bfStyle2+ds_i;
i.skf_l.style.cssText=bfStyle2+ds_i;
}
i.butn.style.cssText = "all: initial !important;font-family: system-ui !important;min-width: 75px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0.05ch 0.25ch 0.05ch 0.25ch !important; display: initial !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bdkCol[1]+" !important; border-color: "+bdc[1]+" !important; float: initial !important; text-align-last: right !important; color: "+txCol[1]+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
i.clse.style.cssText ="all: initial !important;font-family: system-ui !important;-webkit-text-fill-color: #ececec !important;max-width: max-content !important;line-height: 1.91ch !important;transform: translate(0px, 0.06ch) !important;padding: 0em 0.27em 0em 0.27em !important;display: initial !important;visibility: initial !important;background-color: rgba(240, 0, 0, 0.5) !important;float: initial !important;text-align-last: left !important;font-size: unset !important;border-radius: 0% !important;user-select: none !important;margin: 0px !important;min-width: 75px !important;border: 0px !important;color: #ececec !important;";
i.fadedBtns=true;
i.fadedBtnsTime=true;
i.faded=true;
}
function keepMatchesShadow(els,slcArr,isNodeName){
if(slcArr[0]===false){
return els;
}else{
let out=[];
for(let i=0, len=els.length; i<len; i++){
let n=els[i];
for(let k=0, len_k=slcArr.length; k<len_k; k++){
let sk=slcArr[k];
if(isNodeName){
if((n.nodeName.toLocaleLowerCase())===sk){
out.push(n);
}
}else{ //selector
if(!!n.matches && typeof n.matches!=='undefined' && n.matches(sk)){
out.push(n);
}
}
}
}
return out;
}
}
function getMatchingNodesShadow(docm, slc, isNodeName, onlyShadowRoots){
let slcArr=[];
if(typeof(slc)==='string'){
slc=(isNodeName && slc!==false)?(slc.toLocaleLowerCase()):slc;
slcArr=[slc];
}else if(typeof(slc[0])!=='undefined'){
for(let i=0, len=slc.length; i<len; i++){
let s=slc[i];
slcArr.push((isNodeName && slc!==false)?(s.toLocaleLowerCase()):s)
}
}else{
slcArr=[slc];
}
var shrc=[docm];
var shrc_l=1;
var out=[];
let srCnt=0;
while(srCnt<shrc_l){
let curr=shrc[srCnt];
let sh=(!!curr.shadowRoot && typeof curr.shadowRoot !=='undefined')?true:false;
let nk=keepMatchesShadow([curr],slcArr,isNodeName);
let nk_l=nk.length;
if( !onlyShadowRoots && nk_l>0){
for(let i=0; i<nk_l; i++){
out.push(nk[i]);
}
}
for(let i=0, len=curr.childNodes.length; i<len; i++){
shrc.push(curr.childNodes[i]);
}
if(sh){
let cs=curr.shadowRoot;
let csc=[...cs.childNodes];
if(onlyShadowRoots){
if(nk_l>0){
out.push({root:nk[0], childNodes:csc});
}
}
for(let i=0, len=csc.length; i<len; i++){
shrc.push(csc[i]);
}
}
srCnt++;
shrc_l=shrc.length;
}
return out;
}
function getScreenWidth(mx){
let w=[
//document?.documentElement?.scrollWidth,
//document?.body?.parentNode?.scrollWidth,
//document?.body?.scrollWidth,
//document?.head?.scrollWidth,
//window.screen.availWidth,
//window.screen.width,
document?.documentElement?.clientWidth,
document?.body?.parentNode?.clientWidth,
document?.body?.clientWidth,
document?.head?.clientWidth
].filter( (d)=>{return d>0} );
if(w.length>0){
if(mx){
return Math.max(...w);
}else{
return Math.min(...w);
}
}else{
return 0;
}
}
function getScreenHeight(mx){
let w=[
//document?.documentElement?.scrollHeight,
//document?.body?.parentNode?.scrollHeight,
//document?.body?.scrollHeight,
//document?.head?.scrollHeight,
//window.screen.availHeight,
//window.screen.Height,
document?.documentElement?.clientHeight,
document?.body?.parentNode?.clientHeight,
document?.body?.clientHeight,
document?.head?.clientHeight
].filter( (d)=>{return d>0} );
if(w.length>0){
if(mx){
return Math.max(...w);
}else{
return Math.min(...w);
}
}else{
return 0;
}
}
function absBoundingClientRect(el){
let st = [window?.scrollY,
window?.pageYOffset,
el?.ownerDocument?.documentElement?.scrollTop,
document?.documentElement?.scrollTop,
document?.body?.parentNode?.scrollTop,
document?.body?.scrollTop,
document?.head?.scrollTop];
let sl = [window?.scrollX,
window?.pageXOffset,
el?.ownerDocument?.documentElement?.scrollLeft,
document?.documentElement?.scrollLeft,
document?.body?.parentNode?.scrollLeft,
document?.body?.scrollLeft,
document?.head?.scrollLeft];
let scrollTop=0;
for(let k=0; k<st.length; k++){
if(!!st[k] && typeof st[k] !=='undefined' && st[k]>0){
scrollTop=(st[k]>scrollTop)?st[k]:scrollTop;
}
}
let scrollLeft=0;
for(let k=0; k<sl.length; k++){
if(!!sl[k] && typeof sl[k] !=='undefined' && sl[k]>0){
scrollLeft=(sl[k]>scrollLeft)?sl[k]:scrollLeft;
}
}
const rct=el.getBoundingClientRect();
let r={};
r.left_raw=rct.left;
r.right_raw=rct.right;
r.top_raw=rct.top;
r.bottom_raw=rct.left;
r.left=rct.left+scrollLeft;
r.right=rct.right+scrollLeft;
r.top=rct.top+scrollTop;
r.bottom=rct.bottom+scrollTop;
r.height=rct.height;
r.width=rct.width;
return r;
}
function getParent(el,elementsOnly,doc_head_body){
if(!!el && typeof el!=='undefined'){
let out=null;
let curr=el;
let end=false;
while(!end){
if(!!curr.parentNode && typeof curr.parentNode!=='undefined'){
out=curr.parentNode;
curr=out;
end=(elementsOnly && out.nodeType!=1)?false:true;
}else if(!!curr.parentElement && typeof curr.parentElement!=='undefined'){
out=curr.parentElement;
end=true;
curr=out;
}else if(!!curr.host && typeof curr.host!=='undefined'){
out=curr.host;
end=(elementsOnly && out.nodeType!=1)?false:true;
curr=out;
}else{
out=null;
end=true;
}
}
if(out!==null){
if(!doc_head_body){
if(out.nodeName==='BODY' || out.nodeName==='HEAD' || out.nodeName==='HTML'){
out=null;
}
}
}
return out;
}else{
return null;
}
}
function getAncestors(el, elementsOnly, elToHTML, doc_head_body, notInShadow){
let curr=el;
let ancestors=[el];
let outAncestors=[];
let end=false;
while(!end){
let p=getParent(curr,elementsOnly,doc_head_body);
if(p!==null){
if(elToHTML){
ancestors.push(p);
}else{
ancestors.unshift(p)
}
curr=p;
}else{
end=true;
}
}
if(notInShadow){
if(elToHTML){
for(let i=ancestors.length-1; i>=0; i--){
outAncestors.unshift(ancestors[i]);
if(!!ancestors[i].shadowRoot && typeof ancestors[i].shadowRoot !=='undefined'){
i=0;
}
}
}else{
for(let i=0, len=ancestors.length; i<len; i++){
outAncestors.push(ancestors[i]);
if(!!ancestors[i].shadowRoot && typeof ancestors[i].shadowRoot !=='undefined'){
i=len-1;
}
}
}
}else{
outAncestors=ancestors;
}
return outAncestors;
}
function hasAncestor(el,p){
let out=false;
let curr=el;
let end=false;
while(!end){
let r=getParent(curr,false,true);
curr=r;
if(r===null){
end=true;
}else if(r===p){
out=true;
end=true;
}
}
return out;
}
function findIndexTotalInsens(string, substring, index) {
string = string.toLocaleLowerCase();
substring = substring.toLocaleLowerCase();
for (let i = 0; i < string.length ; i++) {
if ((string.includes(substring, i)) && (!(string.includes(substring, i + 1)))) {
index.push(i);
break;
}
}
return index;
}
function blacklistMatch(array, t) {
var found = false;
var blSite='';
if (!((array.length == 1 && array[0] == "") || (array.length == 0))) {
ts = t.toLocaleLowerCase();
for (var i = 0; i < array.length; i++) {
let spl = array[i].split('*');
spl = removeEls("", spl);
var spl_mt = [];
for (let k = 0; k < spl.length; k++) {
var spl_m = [];
findIndexTotalInsens(ts, spl[k], spl_m);
spl_mt.push(spl_m);
}
found = true;
if ((spl_mt.length == 1) && (typeof spl_mt[0][0] === "undefined")) {
found = false;
} else if (!((spl_mt.length == 1) && (typeof spl_mt[0][0] !== "undefined"))) {
for (let m = 0; m < spl_mt.length - 1; m++) {
if ((typeof spl_mt[m][0] === "undefined") || (typeof spl_mt[m + 1][0] === "undefined")) {
found = false;
m = spl_mt.length - 2; //EARLY TERMINATE
} else if (!(spl_mt[m + 1][0] > spl_mt[m][0])) {
found = false;
}
}
}
if(found){
blSite = array[i];
i = array.length - 1;
}
}
}
//console.log(found);
return [found,blSite];
}
var isCurrentSiteBlacklisted = function()
{
return blacklistMatch(blacklist, window.location.href);
};
function forcePlaybackRate(i,noAdj){
if(noAdj!==true && i.ff===1){
let vN=(Number.isNaN(i.clse.valueAsNumber))?1:i.clse.valueAsNumber;
i.video.playbackRate=vN;
}
i.butn.innerText=i.video.playbackRate.toLocaleString('en-GB', {minimumFractionDigits: 0, maximumFractionDigits: 7})+"x [Buffered: "+i.ldd+"]";
}
var sDivsCSS="all: initial !important;font-family: system-ui !important;max-width: max-content !important; line-height: 0px !important; padding: 0px !important; display: flex !important; flex-flow: column nowrap !important; justify-content: flex-start !important; align-items: stretch !important; align-content: flex-start !important; gap: 0px 0px !important; visibility: initial !important; float: initial !important; z-index: "+Number.MAX_SAFE_INTEGER+" !important; position: absolute !important; background-color: transparent !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
function bf_s_hmmss(s, z)
{
var ss = "00";
var mm = "00";
var hh = "";
var hours = Math.max(0,Math.floor(Math.ceil(s) / 3600));
if (hours > 0)
{
hh = hours + ":";
}
var mins = Math.max(0,Math.floor((Math.ceil(s) - hours * 3600) / 60));
if ((hours > 0 && mins<10) || (z && mins<10))
{
mm = "0" + mins;
}
else
{
mm = mins;
}
var secs = Math.max(0,Math.floor(s - hours * 3600 - mins * 60));
if (secs < 10)
{
ss = "0" + secs;
}
else
{
ss = secs;
}
return hh + mm + ":" + ss;
}
function findInst(v){
for(let i=0, len_i=insts.length; i<len_i; ++i){
let inst=insts[i];
if(inst.video===v){
return inst;
}
}
return null;
}
function chkVisTime(i){
return (i.prgBarTime.style['display']==='none')?false:true;
}
function chkVis(i,cvs){
return (((cvs)?i.cvs:i.sdivs).style['opacity']==='0')?false:true;
}
function positionBar(i,scrl, showPrg,onlyReloc){
let ftr_css=false;
if(scrl && cvs_clkd===false && onlyReloc!==true){
i.sdivs.style.cssText=sDivsCSS+'opacity: 0 !important;';
ftr_css=true;
i.faded=true;
i.cvs.style.setProperty('opacity',0,'important');
//i.prgBarTime.style.setProperty('display','none','important');
}
let vrct=absBoundingClientRect(i.video);
let sdrct;
let wg=0.001*vrct.width;
let sdp=i.sdivs.parentElement;
let ancUndef=(sdp===null || typeof(sdp)==='undefined' || sdp===document.body || sdp===document.head || sdp===document.documentElement)?true:false;
let ancR=(ancUndef===true)?{left:0,top:0}:absBoundingClientRect(sdp);
let vdc=i.video.ownerDocument;
let vdcf=vdc.fullscreenElement;
let fsa=hasAncestor(i.video,vdcf);
if( (vdc.fullscreen===true || ( vdcf===i.video || fsa===true ) ) && ancUndef===false){
ancR.left=ancR.left_raw;
ancR.top=ancR.top_raw;
}
i.left=vrct.left+wg-ancR.left;
vrct.vid_width=vrct.width-2*wg;
let forcedTR=( vrct.top_raw===0 && vrct.left_raw===0 && vrct.height===0 && vrct.width===0 )?true:false; //if true, place in middle
let ftp,flf;
if(forcedTR===true){
if( ftr_css===false ){
i.sdivs.style.cssText=sDivsCSS+'opacity: 0 !important;';
}
sdrct=absBoundingClientRect(i.bdivs);
ftp=vrct.top+getScreenHeight(true)*0.5 - sdrct.height;
flf=vrct.left+getScreenWidth(false)*0.5 - sdrct.width*0.5;
}else{
sdrct=absBoundingClientRect(i.bdivs);
}
if(i.video.tagName==='AUDIO'){
if(forcedTR===true){
i.sDivsCSS2='top: '+ftp+'px !important; left: '+flf+'px !important;';
}else if(vrct.top<2*sdrct.height+0.102*vrct.height){
i.sDivsCSS2='top: '+(vrct.bottom+0.102*vrct.height-ancR.top)+'px !important; left: '+(i.left-ancR.left)+'px !important;';
}else{
i.sDivsCSS2='top: '+(vrct.top-2*sdrct.height-0.102*vrct.height-ancR.top)+'px !important; left: '+(i.left-ancR.left)+'px !important;';
}
}else{
i.top=0.102*vrct.height-ancR.top;
if(forcedTR===true){
i.top=ftp-ancR.top;
i.left=flf-ancR.left;
}else if( !( vdc.fullscreen===true &&
!!vdcf &&
( vdcf===i.video ||
( fsa===true &&
( vdcf.clientHeight===i.video.clientHeight ||
absBoundingClientRect(vdcf).top===vrct.top )
)
)
)
){
vrct.centre_y=vrct.top+vrct.height*0.5;
let wScl= i.video.videoWidth===0 ? 1 : vrct.width/i.video.videoWidth;
let hScld=wScl*i.video.videoHeight;
let hScl=i.video.videoHeight===0 ? 1 : vrct.height/i.video.videoHeight;
let wScld=hScl*i.video.videoWidth;
let hlf_h=0.5*((wScl<=hScl)?hScld:vrct.height);
vrct.vid_top=vrct.centre_y-hlf_h;
vrct.vid_bottom=vrct.centre_y+hlf_h;
vrct.vid_height=vrct.vid_bottom-vrct.vid_top;
let hlf_w=0.5*((wScl<=hScl)?vrct.width:wScld);
vrct.centre_x=vrct.left+vrct.width*0.5;
vrct.vid_left=vrct.centre_x-hlf_w;
vrct.vid_right=vrct.centre_x+hlf_w;
vrct.vid_width=vrct.vid_right-vrct.vid_left;
wg=0.001*vrct.vid_width;
vrct.vid_width-=2*wg;
i.left=vrct.vid_left+wg-ancR.left;
i.top=vrct.vid_top+0.102*vrct.vid_height-ancR.top;
}
i.sDivsCSS2='top: '+i.top+'px !important; left: '+i.left+'px !important;';
}
if(onlyReloc===true){
i.sdivs.style.cssText=sDivsCSS+i.sDivsCSS2;
drawBuffered(i);
return;
}
if(scrl && cvs_clkd===false){
if(!i.entered){
i.sdivs.style.cssText=sDivsCSS+i.sDivsCSS2+'opacity: 0 !important;';
i.faded=true;
}
if(!i.entered_cvs){
i.cvs.style.setProperty('opacity',0,'important');
i.prgBarTime.style.setProperty('display','none','important');
}
}else{
i.sdivs.style.cssText=sDivsCSS+i.sDivsCSS2;
i.faded=false;
}
sdrct=absBoundingClientRect(i.bdivs);
let cvsChg=false;
let ncw=(sdrct.width>vrct.vid_width)?sdrct.width:vrct.vid_width;
ncw=Math.floor(ncw);
let nch=Math.floor(i.skb.getBoundingClientRect().height);
if(ncw!==i.cvs.width){
i.cvs.width=ncw;
cvsChg=true;
}
if(nch!==i.cvs.height){
i.cvs.height=nch;
cvsChg=true;
}
if(cvsChg===true){
drawBuffered(i);
}
if(cvs_clkd===false && (scrl || !showPrg) && !i.entered_cvs ){
i.cvs.style.setProperty('opacity',0,'important');
i.prgBarTime.style.setProperty('display','none','important');
}else{
if(!i.faded){
if(i.bufEnd || !i.firstBuf){
drawBuffered(i);
}
i.cvs.style.setProperty('opacity',0.64,'important');
}
}
}
function def_retCSS(i,bool, showPrg){
positionBar(i,bool, showPrg);
if((i.fadedBtnsTime===false || i.entered===false) && (cvs_clkd===false && justUp===false)){
showBtns(i);
}else{
let bdc,bck,txCol;
if(i.ff===1){ // Playback rate adj. activated (button green)
if(i.fadedBtns){
txCol="white";
bdc="#00750080";
bck="#00750080";
}else{
txCol="white";
bdc="#007500";
bck="#007500";
}
}else{
txCol="black";
if(i.fadedBtns){
bdc="transparent";
bck="#f0f0f080";
}else{
bdc="buttonface";
bck="buttonface";
}
}
i.butn.style.cssText = "all: initial !important;font-family: system-ui !important;min-width: 75px !important; line-height: 1.91ch !important; transform: translate(0, 0.06ch) !important; padding: 0.05ch 0.25ch 0.05ch 0.25ch !important; display: initial !important; visibility:initial !important; webkit-text-fill-color: black !important; border-width: 2px !important; border-style: outset !important; background-color: "+bck+" !important; border-color: "+bdc+" !important; float: initial !important; text-align-last: right !important; color: "+txCol+" !important; font-size: unset !important; border-radius: 0% !important; user-select: none !important;";
}
if(justUp===true && cvs_clkd===false){
i.fadedBtnsTime=false;
showBtns(i);
}
clearTimeout(i.timer3);
i.timer3 = setTimeout(function(){
if(!i.entered_cvs){
if(i.entered){
if(i.bufEnd){
forcePlaybackRate(i);
drawBuffered(i);
}else if(!i.firstBuf){
drawBuffered(i);
}
i.cvs.style.setProperty('opacity',0.64,'important');
}else if(!i.entered_cvs){
i.cvs.style.setProperty('opacity',0,'important');
i.prgBarTime.style.setProperty('display','none','important');
}
}
},1250);
clearTimeout(i.timer2);
i.timer2 = setTimeout(function(){
let visTime=chkVisTime(i);
if(!i.entered /*|| visTime===true*/){
if(/*visTime===true ||*/ mbMde || (mbMdeFs && !(document.fullscreen || document.webkitIsFullScreen))){
fadeBtns(i);
if(cvs_clkd===false && !i.entered_cvs && visTime===false){
i.cvs.style.setProperty('opacity',0,'important');
i.prgBarTime.style.setProperty('display','none','important');
}
}else if (cvs_clkd===false){
if(!i.entered && visTime===false){
i.sdivs.style.cssText=sDivsCSS+i.sDivsCSS2+'opacity: 0 !important;';
i.faded=true;
}
if(!i.entered_cvs){
i.cvs.style.setProperty('opacity',0,'important');
i.prgBarTime.style.setProperty('display','none','important');
}
}
}
}, 3000);
}
function chgFlgs(i,on){
i.pg_e=(on)?1:0;
i.wt_e=(on)?1:0;
i.pl_e=(on)?1:0;
i.skd_e=(on)?1:0;
i.rc_e=(on)?1:0;
i.wh_e=(on)?1:0;
i.ip_e=(on)?1:0;
}
function eligVid(vid){
let anc=getAncestors(vid, false, false, true, false);
let fnd=false;
let dEl=document.documentElement;
for(let i=0, len=anc.length; i<len; ++i){
if(anc[i]===dEl){
fnd=true;
break;
}
}
if( (fnd===true) && (get_src(vid)!=='') && (vid.readyState > 0) ){
return [fnd,true];
}else{
return [fnd,false];
}
}
function get_src(vid){
if (vid.src !== "") {
return vid.src;
} else if (vid.currentSrc !== "") {
return vid.currentSrc;
}else{
return '';
}
}
function checkInclude(arr,el){
let arrChk=arr.filter((a)=>{return a===el;});
return (arrChk.length>0)?true:false;
}
function removeEls(d, array) {
return array.filter((a)=>{return a!==d});
}
function elRemover(el){
try{
el.parentNode.removeChild(el);
}catch(e){;}
try{
el.remove();
}catch(e){;}
}
function setPix(pixels, x, y, r, g, b, width) {
var index = 4 * (x + y * width);
pixels[index] = r;
pixels[index+1] = g;
pixels[index+2] = b;
pixels[index+3] =255;
}
function drawBuffered(i){
let len=i.video.buffered.length;
if(len>0){
let ctx = i.cvs.getContext('2d', {willReadFrequently: true});
ctx.globalCompositeOperation = "source-over";
let canvasWidth = i.cvs.width;
let canvasHeight = i.cvs.height;
if(canvasWidth>0 && canvasHeight>0){
let canvasWidth_1 = canvasWidth-1;
if(i.firstBuf===false){
i.firstBuf=true;
}
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
let iData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
let pixels = iData.data;
let dur=i.video.duration;
if(isFinite(dur)){
i.cvs.setAttribute('start', 0);
i.cvs.setAttribute('end', dur);
for (let k=len-1; k>=0; --k){
let t_i=i.video.buffered.end(k);
let s_i=i.video.buffered.start(k);
let prp=canvasWidth_1/dur;
let xds=Math.ceil(s_i*prp);
let xdt=Math.floor(t_i*prp);
let c_i=i.video.currentTime;
let xdc=(c_i>=s_i && c_i<=t_i)?Math.ceil(c_i*prp):-1;
for (let x=xds; x<=xdt; ++x){
if(x===xdc){
for (let y=canvasHeight-1; y>=0; --y){
setPix(pixels, x, y, 198,198,22, canvasWidth);
}
}else{
let grn=(xdc!=-1 && x>=xdc && x<=xdt)?true:false;
if(grn===true){
for (let y=canvasHeight-1; y>=0; --y){
setPix(pixels, x, y, 0,171,14, canvasWidth);
}
}else{
for (let y=canvasHeight-1; y>=0; --y){
setPix(pixels, x, y, 144,67,204, canvasWidth);
}
}
}
}
}
}else{
let c_i=i.video.currentTime;
let latest=Math.max(i.video.buffered.end(len-1), c_i);
let earliest=Math.min(i.video.buffered.start(0), c_i);
i.cvs.setAttribute('start', earliest);
i.cvs.setAttribute('end', latest);
for (let k=len-1; k>=0; --k){
let t_i=i.video.buffered.end(k);
let s_i=i.video.buffered.start(k);
let prp=canvasWidth_1/(latest-earliest);
let xds=Math.ceil((s_i-earliest)*prp);
let xdt=Math.floor((t_i-earliest)*prp);
let c_i=i.video.currentTime;
let xdc=(c_i>=s_i && c_i<=t_i)?Math.ceil((c_i-earliest)*prp):-1;
for (let x=xds; x<=xdt; ++x){
if(x===xdc){
for (let y=canvasHeight-1; y>=0; --y){
setPix(pixels, x, y,198,198,22, canvasWidth);
}
}else{
let grn=(xdc!=-1 && x>=xdc && x<=xdt)?true:false;
if(grn===true){
for (let y=canvasHeight-1; y>=0; --y){
setPix(pixels, x, y, 0,171,14, canvasWidth);
}
}else{
for (let y=canvasHeight-1; y>=0; --y){
setPix(pixels, x, y, 144,67,204, canvasWidth);
}
}
}
}
}
}
ctx.putImageData(iData, 0, 0);
}
}
}
function calcSp(i,noAdj){
var lddRaw;
var rgs=[];
var lastPart=false;
let c_i=i.video.currentTime;
for (let k=i.video.buffered.length-1; k>=0; k--){
let t_i=i.video.buffered.end(k);
let s_i=i.video.buffered.start(k);
if(t_i==i.video.duration && c_i>=s_i){
lastPart=true;
break;
}else if(c_i>=s_i && t_i>=c_i){
rgs.push([s_i,t_i]);
}
}
if(lastPart){
i.bufEnd=true;
i.ldd='END';
forcePlaybackRate(i,noAdj);
}else{
i.bufEnd=false;
var tot=0;
if(rgs.length>0){
let sorted=rgs.sort((a, b) => {return a[0] - b[0];})
tot=sorted[0][1]-c_i;
for (let k=1; k<sorted.length; k++){
if(sorted[k-1][1]==sorted[k][0]){
tot+=sorted[k][1]-sorted[k][0];
}else{
break;
}
}
}
lddRaw=(i.video.playbackRate==0)?tot:tot/i.video.playbackRate;
if(!noAdj && ( (!i.video.paused) || (i.video.paused && lddRaw<2))){
let prev_mx=(i.lddArr.length==0)?lddRaw:Math.max(...i.lddArr);
i.lddArr.push(lddRaw);
let vN=(Number.isNaN(i.clse.valueAsNumber))?1:i.clse.valueAsNumber;
let outSp=vN;
if(lddRaw!=2){
//50*tot=(1/2)*100*tot ; for >= 2 real secs loaded
if(lddRaw<2){
outSp=Math.min(vN,Math.max(Math.floor(50*tot)*0.01,1));
}else if(lddRaw>prev_mx){
i.lddArr=[];
}else{
//let mx=Math.max(...i.lddArr);
let mn=Math.min(...i.lddArr);
let rng=prev_mx-mn;
let rng_norm=(prev_mx==0)?1:Math.sqrt(rng/prev_mx);
let outSp=Math.min(Math.floor(100*((1-rng_norm)*vN+rng_norm))*0.01,Math.min(vN,Math.max(Math.floor(50*tot)*0.01,1)));
}
}
if(outSp==i.video.playbackRate){
lddRaw=(i.video.playbackRate==0)?tot:tot/i.video.playbackRate;
i.ldd=bf_s_hmmss(lddRaw, false);
i.butn.innerText=i.video.playbackRate.toLocaleString('en-GB', {minimumFractionDigits: 0, maximumFractionDigits: 7})+"x [Buffered: "+i.ldd+"]";
}else{
lddRaw=tot/outSp;
i.ldd=bf_s_hmmss(lddRaw, false);
i.video.playbackRate=outSp;
i.butn.innerText=i.video.playbackRate.toLocaleString('en-GB', {minimumFractionDigits: 0, maximumFractionDigits: 7})+"x [Buffered: "+i.ldd+"]";
}
}else{
lddRaw=(i.video.playbackRate==0)?tot:tot/i.video.playbackRate;
i.ldd=bf_s_hmmss(lddRaw, false);
i.butn.innerText=i.video.playbackRate.toLocaleString('en-GB', {minimumFractionDigits: 0, maximumFractionDigits: 7})+"x [Buffered: "+i.ldd+"]";
}
}
drawBuffered(i);
}
function progress_hdl(event) {
let i=findInst(event.target);
if(!!i){
if(i.pg_e==1){
if(i.video.readyState>2){
calcSp(i,false);
}else{
i.video.playbackRate=1;
}
}else{
calcSp(i,true);
}
}
}
function ended_hdl(event) {
let i=findInst(event.target);