-
Notifications
You must be signed in to change notification settings - Fork 3
/
473972.user.js
7377 lines (5778 loc) · 238 KB
/
473972.user.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
// ==UserScript==
// @name YouTube JS Engine Tamer
// @namespace UserScripts
// @match https://www.youtube.com/*
// @version 0.16.16
// @license MIT
// @author CY Fung
// @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
// @description To enhance YouTube performance by modifying YouTube JS Engine
// @grant none
// @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@7221a4efffd49d852de0074ec503d4febb99f28b/library/nextBrowserTick.min.js
// @run-at document-start
// @unwrap
// @inject-into page
// @allFrames true
// ==/UserScript==
(() => {
const WeakMap = window.WeakMapOriginal || window.WeakMap;
const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
const FIX_schedulerInstanceInstance = 2 | 4;
const FIX_yt_player = true; // DONT CHANGE
const FIX_Animation_n_timeline = true;
const NO_PRELOAD_GENERATE_204 = false;
const ENABLE_COMPUTEDSTYLE_CACHE = true;
const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
const CHANGE_appendChild = true; // discussions#236759
const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
// const FIX_error_many_stack_keepAliveDuration = 200; // ms
// const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
const FIX_Iframe_NULL_SRC = false;
const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
const FIX_ytdExpander_childrenChanged = true;
const FIX_paper_ripple_animate = true;
const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
const FIX_doIdomRender = true;
const FIX_Shady = true;
// [[ 2024.04.24 ]]
const MODIFY_ShadyDOM_OBJ = true;
// << if MODIFY_ShadyDOM_OBJ >>
const WEAKREF_ShadyDOM = true;
const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
// << end >>
const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
const FIX_ytAction_ = true; // ytd-app
const FIX_onVideoDataChange = false;
// const FIX_onClick = true;
const FIX_onStateChange = true;
const FIX_onLoopRangeChange = true;
// const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
const SCRIPTLET_NOFIX_setTimeout = true;
const ENABLE_discreteTasking = true;
// << if ENABLE_discreteTasking >>
const FIX_stampDomArray_stableList = true;
const ENABLE_weakenStampReferences = true; // disabled in old browsers
// << end >>
const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
const UNLOAD_DETACHED_POLYMER = false; // unstable
const FIX_Polymer_dom = true;
const WEAK_REF_BINDING = false; // false if your browser is slow // disabled due to memory leakage
// << if WEAK_REF_BINDING >>
const WEAK_REF_PROXY_DOLLAR = true; // false if your browser is slow
// << end >>
const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
const DEBUG_removePrune = false; // true for DEBUG
const FIX_XHR_REQUESTING = true;
const FIX_VIDEO_BLOCKING = false; // usually it is a ads block issue // disabled due to memory leakage
const LOG_FETCHMETA_UPDATE = false; // for DEBUG
const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
const FIX_removeChild = true;
const FIX_fix_requestIdleCallback_timing = true;
// ----------------------------- Shortkey Keyboard Control -----------------------------
// dependency: FIX_yt_player
const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
// [0] no fix - not recommended
// [1] basic fix - just fix the global focus detection variable
// [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
// (note) 0 or 1 if you find conflict with other userscripts/plugin
const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
const PROP_OverReInclusion_AVOID = true;
const PROP_OverReInclusion_DEBUGLOG = false;
const PROP_OverReInclusion_LIST = new Set([
'hostElement72',
'parentComponent72',
'localVisibilityObserver_72',
'cachedProviderNode_72',
'__template72',
'__templatizeOwner72',
'__templateInfo72',
'__dataHost72',
'__CE_shadowRoot72',
'elements_72',
'ky36',
'kz62',
'm822',
// To be reviewed.
// chat messages
'disabled', 'allowedProps',
'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
'dimension', 'loadTime', 'pendingPaint',
'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
'respectLangDir', 'noEndpoints',
'objectURL',
'buttonOverrides', 'queuedMessages',
'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
'hoverJobId', 'JSC$14573_touched',
// tbc
'toggleable', 'isConnected',
'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
'disableDeselectEvent',
'emojiSize',
'buttonOverride',
'shouldUseStickyPreferences', 'longPressTimeoutId',
// others
'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
// 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
// 'dimension', 'loadTime', 'pendingPaint',
// 'disabled', 'allowedProps',
// 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
// 'actionMap',
// 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
'clearTimeout',
'switchTemplateAtRegistration', 'hasUnmounted',
'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
'tangoConfiguration',
'itemIdToDockDurationMap',
'actionMap',
'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
// 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
// 'stopKeyboardEventPropagation', 'emojiSize',
// 'switchTemplateAtRegistration', 'hasUnmounted',
// 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
// 'isReusable', 'tangoConfiguration',
// 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
// */
]);
// const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
// ----------------------------- Shortkey Keyboard Control -----------------------------
/*
window.addEventListener('edm',()=>{
let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
});
window.addEventListener('edn',()=>{
let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
});
window.addEventListener('edr',()=>{
let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
});
*/
// only for macOS with Chrome/Firefox 100+
const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
const win = this instanceof Window ? this : window;
// Create a unique key for the script and check if it is already running
const hkey_script = 'jswylcojvzts';
if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
win[hkey_script] = true;
let BY_PASS_KEYBOARD_CONTROL = false;
// const setImmediate = ((self || 0).jmt || 0).setImmediate;
/** @type {(f: ()=>{})=>{}} */
const nextBrowserTick = (self || 0).nextBrowserTick || 0;
const nextBrowserTick_ = nextBrowserTick || (f => f());
let p59 = 0;
const Promise = (async () => { })().constructor;
const PromiseExternal = ((resolve_, reject_) => {
const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
return class PromiseExternal extends Promise {
constructor(cb = h) {
super(cb);
if (cb === h) {
/** @type {(value: any) => void} */
this.resolve = resolve_;
/** @type {(reason?: any) => void} */
this.reject = reject_;
}
}
};
})();
/**
@param {number} x
@param {number} d */
const toFixed2 = (x, d) => {
let t = x.toFixed(d);
let y = `${+t}`;
return y.length > t.length ? t : y;
}
let pf31 = new PromiseExternal();
// native RAF
let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
// 1st wrapped RAF
const baseRAF = (callback) => {
return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
pf31.then(() => {
callback(hRes);
});
});
};
// 2nd wrapped RAF
window.requestAnimationFrame = baseRAF;
const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
const indr = o => insp(o).$ || o.$ || 0;
const prototypeInherit = (d, b) => {
const m = Object.getOwnPropertyDescriptors(b);
for (const p in m) {
if (!Object.getOwnPropertyDescriptor(d, p)) {
Object.defineProperty(d, p, m[p]);
}
}
};
/** @type {(o: Object | null) => WeakRef | null} */
const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
/** @type {(wr: Object | null) => Object | null} */
const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
if (typeof Document.prototype.requestStorageAccessFor === 'function') {
if (DENY_requestStorageAccess) {
// https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
Document.prototype.requestStorageAccessFor = undefined;
console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
} else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
Document.prototype.requestStorageAccessFor = function () {
return new Promise((resolve, reject) => {
reject();
});
};
}
}
if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
// window.m3bb = new Set();
// const smb = Symbol();
const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
// const fnProxySelf = function (...args) {
// if (args[0] === smb) return this;
// const cnt = kRef(this.ref);
// if (cnt) {
// if (typeof cnt[this.prop] !== 'function') console.error(`this.${this.prop} is not a function. [${cnt.is || 'nil'}]`)
// return cnt[this.prop](...args); // might throw error
// }
// }
// fnProxySelf.bind588 = fnProxySelf.bind;
// const pFnHandler = {
// get(target, prop){
// if(prop === 'bind588') return 2;
// const fnThis = target(smb);
// if (fnThis && fnThis.prop && fnThis.ref) {
// const cnt = kRef(fnThis.ref || null) || null;
// if (cnt) {
// const h = cnt[fnThis.prop];
// const v = h[prop];
// if (typeof v === 'function'){
// if(typeof h === 'function'){
// if (prop === 'call' || prop === 'bind' || prop === 'bind588' || prop === 'bind488' || prop === 'apply') {
// if(h.bind588 === 1){
// const g = function(...args){
// console.log(1288, this)
// return h.call(this, ...args);
// };
// console.log(399, g)
// return g[prop];
// // console.log(12778)
// // console.log(target, target.call)
// // return target[prop];
// }
// // independent of this
// return v; // function.bind, function.call, function.apply
// }
// }
// console.warn('cnt[fnThis.prop][prop] is function; might rely on this', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
// // return new Proxy(fnProxySelf.bind588({ prop: prop, ref: new WeakRef(cnt[fnThis.prop]) }), pFnHandler);
// }
// return v;
// }
// }
// },
// set(target, prop, value) {
// const fnThis = target(smb);
// if (fnThis && fnThis.prop && fnThis.ref) {
// const cnt = kRef(fnThis.ref || null) || null;
// if (cnt) {
// const h = cnt[fnThis.prop];
// if (h) {
// h[prop] = value;
// } else {
// console.log('h is nout found', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
// }
// }
// }
// return true;
// }
// };
const thisConversionFn = (thisArg) => {
if (!thisArg) return null;
const kThis = thisArg[vmb];
if (kThis) {
const ref = kThis.ref;
return (ref ? kRef(ref) : null) || null;
}
return thisArg;
}
const pFnHandler2 = {
get(target, prop) {
if (prop === vmc) return target;
return Reflect.get(target, prop);
},
apply(target, thisArg, argumentsList) {
thisArg = thisConversionFn(thisArg);
if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
}
}
const proxySelfHandler = {
get(target, prop) {
if(prop === vmb) return target;
const ref = target.ref;
const cnt = kRef(ref);
if (!cnt) return;
if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
return cnt[prop][vmd];
}
return cnt[prop];
},
set(target, prop, value) {
const cnt = kRef(target.ref);
if (!cnt) return true;
if(value && (value[vmc] || value[vmb])){
cnt[prop] = value[vmc] || thisConversionFn(value);
return true;
}
cnt[prop] = value;
return true;
}
};
const weakWrap = (thisArg) => {
thisArg = thisConversionFn(thisArg);
if (!thisArg) {
console.error('thisArg is not found');
return null;
}
return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
}
if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
window.getComputedStyle533 = window.getComputedStyle;
window.getComputedStyle = function (a, ...args) {
a = thisConversionFn(a);
if (a) {
return getComputedStyle533(a, ...args);
}
return null;
}
}
Function._count_bind_00 = 0;
// Function._count_bind_01 = 0;
// let matchNativeCode = (Object+"");
// let matchNativeCode1 = matchNativeCode.includes("[native code]");
// let matchNativeLen = matchNativeCode.length - Object.name.length;
// const matchConstructor = (thisArg) => {
// const f = (thisArg || 0).constructor + "";
// if (f.length > 45) return true;
// if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
// if (f.includes('[native code]')){
// return false;
// }
// return true;
// }
// return false;
// }
// const acceptThis = (thisArg)=>{
// // if(!thisArg || typeof thisArg !=='object') return false;
// // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
// // if(typeof thisArg.path === 'string') return true;
// // if(typeof thisArg.fn === 'function') return true;
// // if(typeof thisArg.id === 'string') return true;
// // if(typeof thisArg.isLoaded === 'boolean') return true;
// return false;
// }
const patchFn = (fn) => {
let s = `${fn}`;
if (s.length < 11 || s.includes('\n')) return false;
if(s.includes('bind(this')) return true;
if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
// var a=this;
// f.bind(this)
return false;
}
Function.prototype.bind488 = Function.prototype.bind;
Function.prototype.bind = function(thisArg, ...args){
if (thisConversionFn(thisArg) !== thisArg) {
return this.bind488(thisArg, ...args);
}
if( thisArg && patchFn(this) ){
// console.log(599,`${this}`)
try {
// let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
// let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
// let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
// // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
// // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
// // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
// // let b4 = false;
// let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
// // b3 = false;
// // b4 = false;
// // b5 = false;
// if (b1 || b2 || b3 ||b4 ) {
const f = this;
const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
if (ps && ps[vmb]) {
Function._count_bind_00++;
return f.bind488(ps, ...args)
}
// }
} catch (e) {
console.warn(e)
}
}
return this.bind488(thisArg, ...args);
}
Function.prototype.bind588 = 1;
}
if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
const wm6 = new WeakMapOriginal();
const skipW = new WeakSet();
window.WeakMap = class WeakMap extends WeakMapOriginal {
constructor(iterable = undefined) {
super();
if (iterable && iterable[Symbol.iterator]) {
for (const entry of iterable) {
entry && this.set(entry[0], entry[1]);
}
}
}
delete(a) {
if (!this.has(a)) return false;
super.delete(a);
return true;
}
get(a) {
const p = super.get(a);
if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
let v = kRef(p);
if (!v) {
super.delete(a);
}
return v || undefined;
}
return p;
}
has(a) {
if (!super.has(a)) return false;
const p = super.get(a);
if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
if (!kRef(p)) {
super.delete(a);
return false;
}
}
return true;
}
set(a, b) {
let wq = b;
if (b && (typeof b === 'function' || typeof b === 'object')) {
if (b.deref) {
skipW.add(b);
wq = b;
} else {
wq = wm6.get(b);
if (!wq) {
wq = mWeakRef(b);
wm6.set(b, wq);
}
}
}
super.set(a, wq);
return this;
}
}
Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
configurable: true,
enumerable: false,
value: "WeakMap",
writable: false
});
}
const isWatchPageURL = (url) => {
url = url || location;
return location.pathname === '/watch' || location.pathname.startsWith('/live/')
};
const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
if (typeof customElements === 'undefined') {
if (!('__CE_registry' in document)) {
// https://github.com/webcomponents/polyfills/
Object.defineProperty(document, '__CE_registry', {
get() {
// return undefined
},
set(nv) {
if (typeof nv == 'object') {
delete this.__CE_registry;
this.__CE_registry = nv;
this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
}
return true;
},
enumerable: false,
configurable: true
})
}
let eventHandler = (evt) => {
document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
const f = callback;
callback = null;
eventHandler = null;
f();
};
document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
} else {
callback();
}
});
const whenCEDefined = isCustomElementsProvided
? (nodeName) => customElements.whenDefined(nodeName)
: (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
FIX_perfNow && performance.timeOrigin > 9 && (() => {
if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
const f = performance.now23 = Performance.prototype.now;
let k = 0; // 0 <= k < 9998m
let u = 0;
let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
// By definition, performance.now() is mono increasing.
// Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
performance.now = performance.now16 = function () {
/**
* Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
*
* If consecutive session history entries had history.state.entryTime set to same value,
* back button doesn't work as expected. The entryTime value is coming from performance.now()
* and modifying its return value slightly to make sure two close consecutive calls don't
* get the same result helped with resolving the issue.
*/
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
else { // more than 9998 consecutive calls
/**
*
* max no. of consecutive calls
*
* Sample Size: 4800
* Sample Avg = 1565.375
* Sample Median = 1469.5
* Sample Max = 5660 << 7500 << 9999
*
*
* */
k = 0;
s += 1 / 7;
}
return v + k; // 0 < v - M < v - M + k < v
}
let loggerMsg = '';
if (`${performance.now()}` === `${performance.now()}`) {
const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
}
loggerMsg && console.warn(loggerMsg);
})();
FIX_removeChild && (() => {
if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
Node.prototype.removeChild062 = Node.prototype.removeChild;
Node.prototype.removeChild = function (child) {
if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
this.removeChild062(child);
} else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
// tooltip bug
} else {
console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
}
return child;
}
}
})();
// WEAKREF_ShadyDOM
MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
const setupPlainShadyDOM = (b) => {
(OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
(OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
(OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
b.patchOnDemand = true;
b.preferPerformance = true;
b.noPatch = true;
}
const isPlainObject = (b, m) => {
if (!b || typeof b !== 'object') return false;
const e = Object.getOwnPropertyDescriptors(b);
if (e.length <= m) return false;
let pr = 0;
for (const k in e) {
const d = e[k];
if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
if (!('value' in d) || typeof d.value === 'function') return false;
pr++;
}
return pr > m;
}
let b;
let lz = 0;
const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
// Brave - ShadyDOM exists before userscripting
b = sdp.value;
if (b && typeof b === 'object' && isPlainObject(b, 0)) {
OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
lz = 1;
}
}
if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
} else if (!sdp) {
} else {
console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
return;
}
const shadyDOMNodeWRM = new WeakMap();
console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
const weakWrapperNodeHandlerFn = () => ({
get() {
let w = shadyDOMNodeWRM.get(this);
if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
return w;
},
set(nv) {
shadyDOMNodeWRM.set(this, mWeakRef(nv));
return true;
},
enumerable: true,
configurable: true
});
function weakWrapper(_ShadyDOM) {
const ShadyDOM = _ShadyDOM;
if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
let nullElement = { node: null };
Object.setPrototypeOf(nullElement, Element.prototype);
let p = new ShadyDOM.Wrapper(nullElement);
let d = Object.getOwnPropertyDescriptor(p, 'node');
if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
}
}
}
let previousWrapStore = null;
const standardWrap = function (a) {
if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
if (previousWrapStore) {
const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
if (s) {
previousWrapStore.delete(a);
shadyDOMNodeWRM.set(a, mWeakRef(s));
}
}
let u = kRef(shadyDOMNodeWRM.get(a));
if (!u) {
u = new ShadyDOM.Wrapper(a);
shadyDOMNodeWRM.set(a, mWeakRef(u));
}
return u;
}
function setupWrapFunc(_ShadyDOM) {
const ShadyDOM = _ShadyDOM;
const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
return;
}
let mm = new Set();
const pget = wmPD.value;
WeakMap.prototype.get = function (a) {
mm.add(this);
return a;
}
try {
let nullElement = { node: null };
Object.setPrototypeOf(nullElement, Element.prototype);
ShadyDOM.wrapIfNeeded(nullElement)
ShadyDOM.wrap(nullElement)
} catch (e) { }
WeakMap.prototype.get = pget;
if (mm.size !== 1) {
mm.clear();
return;
}
const p = mm.values().next().value;
if (!(p instanceof WeakMap)) return;
// p.clear();
// p.get = function (a) { return a }
// p.set = function (a, b) { return this }
// console.log(188, window.n2n = mm, window.n2p = p)
// console.log(34929,p.size)
previousWrapStore = p;
if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
}
if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
}
}
function setupLZ3(nv) {
const ShadyDOM = nv;
const ShadyDOMSettings = ShadyDOM.settings;
if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
return false;
}
weakWrapper(ShadyDOM);
if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
setupPlainShadyDOM(ShadyDOMSettings);
setupPlainShadyDOM(ShadyDOM);
ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
setupWrapFunc(ShadyDOM);
ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
// To be confirmed
if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
ShadyDOM.composedPath = function (e) {
const t = (e || 0).target || null;
if (!(t instanceof HTMLElement)) {
console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
}
return t instanceof HTMLElement ? [t] : [];
};
}
}
}
function setupLZ6(nv) {
const ShadyDOM = nv;
const ShadyDOMSettings = ShadyDOM.settings;
if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
return false;
}
weakWrapper(ShadyDOM);
if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
setupPlainShadyDOM(ShadyDOMSettings);
setupPlainShadyDOM(ShadyDOM);
setupWrapFunc(ShadyDOM);
}
}
if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
const nv = b;
if (setupLZ6(nv) === false) return;
lz = 6;
console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
return;
}
delete window.ShadyDOM;
Object.defineProperty(window, 'ShadyDOM', {
get() {
return b;
},
set(nv) {
let ret = 0;
try {
do {
if (!nv || !nv.settings) {
if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
lz = 1;
break;
} else {
console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
break;
}
}
const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
break;
}
if (setupLZ3(nv) === false) break;
lz = 3;
console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
ret = 1;
} while (0);
} catch (e) {
console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
}
if (!ret) b = nv;
else {
delete this.ShadyDOM;
this.ShadyDOM = nv;
}
return true;
},
enumerable: false,
configurable: true
});
})(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
if (ENABLE_ASYNC_DISPATCHEVENT && nextBrowserTick) {
const filter = new Set([
'yt-action',
// 'iframe-src-replaced',
'shown-items-changed',
'can-show-more-changed', 'collapsed-changed',
'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',