|
1 | 1 | // ==UserScript==
|
2 | 2 | // @name YouTube JS Engine Tamer
|
3 | 3 | // @namespace UserScripts
|
4 |
| -// @version 0.18.9 |
| 4 | +// @version 0.18.10 |
5 | 5 | // @match https://www.youtube.com/*
|
6 | 6 | // @match https://www.youtube-nocookie.com/embed/*
|
7 | 7 | // @match https://studio.youtube.com/live_chat*
|
|
3578 | 3578 | let val_kevlar_should_maintain_stable_list = null;
|
3579 | 3579 |
|
3580 | 3580 | const csb = (a, b) => { for (const c in a) if (a.hasOwnProperty(c) && b[c]) return c; return null }
|
3581 |
| - const createStampDomArrayFnE1_ = async function (a, b, c, d, shouldTriggerRendererStamperFinished, h) { |
| 3581 | + const createStampDomArrayFnE1_ = function (a, b, c, d, shouldTriggerRendererStamperFinished, h) { |
3582 | 3582 |
|
3583 | 3583 |
|
3584 | 3584 | // this.__$$fs894$$__ = this.__$$fs894$$__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
|
|
3770 | 3770 |
|
3771 | 3771 | // document.documentElement.appendChild.call(doc.documentElement, noscript);
|
3772 | 3772 | // nativeRemoveE.call(noscript);
|
3773 |
| - |
| 3773 | + |
3774 | 3774 | // nativeRemoveE.call(noscript);
|
3775 | 3775 | noscript.remove(); // trigger isAttached change
|
3776 | 3776 | const hostElement = this.hostElement;
|
3777 |
| - |
| 3777 | + |
3778 | 3778 | // console.log('em77', hasElement, noscript.childElementCount, domShell.childElementCount, cxt, a_.length);
|
3779 | 3779 | // if(a_.length !== noscript.childElementCount+ domShell.childElementCount+ cxt){
|
3780 | 3780 | // const pd = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
|
3781 |
| - |
| 3781 | + |
3782 | 3782 | // console.log('em77b', pd, [...a_], [...noscript.childNodes], [...domShell.childNodes])
|
3783 | 3783 | // setTimeout(()=>{
|
3784 | 3784 | // console.log('em77c', pd, [...domShell.childNodes])
|
3785 | 3785 | // }, 1000)
|
3786 | 3786 | // }
|
3787 |
| - |
| 3787 | + |
3788 | 3788 | // const sdc02 = this.__$$StampDomCounter$$__;
|
3789 |
| - |
3790 |
| - |
| 3789 | + |
| 3790 | + |
3791 | 3791 | /** @type {DocumentFragment} */
|
3792 | 3792 | // const gFragment = document.createDocumentFragment();
|
3793 | 3793 | const gFragment = doc.createDocumentFragment();
|
3794 |
| - |
| 3794 | + |
3795 | 3795 | const fnE = () => {
|
3796 | 3796 | const evt = new CustomEvent("yt-rendererstamper-finished", {
|
3797 | 3797 | bubbles: !0,
|
|
3803 | 3803 | });
|
3804 | 3804 | hostElement.dispatchEvent(evt);
|
3805 | 3805 | };
|
3806 |
| - |
| 3806 | + |
3807 | 3807 | let f1, f2;
|
3808 |
| - f1 = async() => { |
| 3808 | + f1 = async () => { |
3809 | 3809 | await new Promise(r => nextBrowserTick_(r));
|
3810 | 3810 | // if (t892 !== this.__$$fs892$$__) return;
|
3811 | 3811 | // await new Promise(r=>setTimeout(r, 1000));
|
3812 |
| - |
| 3812 | + |
3813 | 3813 | if (this.data !== data || this.__data !== __data) return;
|
3814 |
| - |
| 3814 | + |
3815 | 3815 | if (!hasElement && !!domShell.firstElementChild) return;
|
3816 | 3816 | if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
|
3817 | 3817 | return;
|
3818 | 3818 | }
|
3819 | 3819 | // const t1 = performance.now();
|
3820 |
| - |
| 3820 | + |
3821 | 3821 | if (DO_createStampDomArrayFnE1_nativeAppendD) {
|
3822 | 3822 | let elm;
|
3823 | 3823 | while (elm = noscript.firstChild) {
|
|
3830 | 3830 | }
|
3831 | 3831 | }
|
3832 | 3832 | // const t2 = performance.now();
|
3833 |
| - |
| 3833 | + |
3834 | 3834 | // console.log('createStampDomArrayFn_{T2}', t2-t1);
|
3835 |
| - |
| 3835 | + |
3836 | 3836 | // nextBrowserTick_(f2);
|
3837 | 3837 | return true;
|
3838 | 3838 | };
|
3839 |
| - |
| 3839 | + |
3840 | 3840 | f2 = async () => {
|
3841 | 3841 | await new Promise(r => nextBrowserTick_(r));
|
3842 | 3842 | // if (t892 !== this.__$$fs892$$__) return;
|
3843 | 3843 | if (this.data !== data || this.__data !== __data) return;
|
3844 |
| - |
| 3844 | + |
3845 | 3845 | if (!hasElement && !!domShell.firstElementChild) return;
|
3846 | 3846 | if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
|
3847 | 3847 | return;
|
3848 | 3848 | }
|
3849 |
| - |
| 3849 | + |
3850 | 3850 | // const t1 = performance.now();
|
3851 | 3851 | // const arr = [...noscript.childNodes];
|
3852 | 3852 | // g.append(...arr);
|
3853 |
| - |
| 3853 | + |
3854 | 3854 | // if(gFragment.childElementCount>10){
|
3855 |
| - |
3856 |
| - // for(const p of gFragment.childNodes){ |
3857 |
| - |
3858 |
| - // const w = document.createDocumentFragment(); |
3859 |
| - // w.append(p); |
3860 |
| - |
3861 |
| - // domShell.appendChild(w); |
3862 |
| - // await Promise.resolve(0); |
3863 |
| - |
3864 |
| - // } |
3865 |
| - |
3866 |
| - // }else{ |
3867 |
| - |
3868 |
| - domShell.appendChild(gFragment); |
| 3855 | + |
| 3856 | + // for(const p of gFragment.childNodes){ |
| 3857 | + |
| 3858 | + // const w = document.createDocumentFragment(); |
| 3859 | + // w.append(p); |
| 3860 | + |
| 3861 | + // domShell.appendChild(w); |
| 3862 | + // await Promise.resolve(0); |
| 3863 | + |
3869 | 3864 | // }
|
3870 |
| - |
3871 |
| - |
3872 |
| - |
| 3865 | + |
| 3866 | + // }else{ |
| 3867 | + |
| 3868 | + domShell.appendChild(gFragment); |
| 3869 | + // } |
| 3870 | + |
| 3871 | + |
| 3872 | + |
3873 | 3873 | // for (const cp of arr) {
|
3874 | 3874 | // const i = cp[stampIdxSb];
|
3875 | 3875 | // const u = a_[i];
|
3876 | 3876 | // const c = c_;
|
3877 | 3877 | // const x = csb(c, u);
|
3878 | 3878 | // this.deferRenderStamperBinding_(cp, c[x], u[x]); // necessary?
|
3879 | 3879 | // }
|
3880 |
| - |
| 3880 | + |
3881 | 3881 | this.flushRenderStamperComponentBindings_();
|
3882 | 3882 | this.markDirty && this.markDirty();
|
3883 |
| - // const t2 = performance.now(); |
3884 |
| - |
| 3883 | + // const t2 = performance.now(); |
| 3884 | + |
3885 | 3885 | // console.log('createStampDomArrayFn_{T3}', t2-t1); // time consuming
|
3886 |
| - |
3887 |
| - if (shouldTriggerRendererStamperFinished) { |
3888 |
| - nextBrowserTick_(fnE); |
3889 |
| - } |
3890 |
| - |
3891 |
| - |
| 3886 | + |
| 3887 | + if (shouldTriggerRendererStamperFinished) { |
| 3888 | + nextBrowserTick_(fnE); |
| 3889 | + } |
| 3890 | + |
| 3891 | + |
3892 | 3892 | // this.flushRenderStamperComponentBindings_();
|
3893 |
| - |
3894 |
| - |
3895 |
| - |
| 3893 | + |
| 3894 | + |
| 3895 | + |
3896 | 3896 | return true;
|
3897 |
| - |
| 3897 | + |
3898 | 3898 | };
|
3899 | 3899 |
|
3900 | 3900 | const r1 = await f1();
|
3901 |
| - if(r1 === true){ |
| 3901 | + if (r1 === true) { |
| 3902 | + |
3902 | 3903 |
|
3903 |
| - |
3904 | 3904 | const r2 = await f2();
|
3905 | 3905 | // p892R();
|
3906 | 3906 | }
|
3907 | 3907 |
|
3908 | 3908 | // console.log(1883 , this.__$$fs894$$__)
|
3909 |
| - |
3910 |
| - |
| 3909 | + |
| 3910 | + |
3911 | 3911 |
|
3912 | 3912 |
|
3913 | 3913 | }catch(err){
|
|
3918 | 3918 | //
|
3919 | 3919 | }
|
3920 | 3920 |
|
3921 |
| - }).catch(()=>0); |
| 3921 | + }).catch(() => 0); |
| 3922 | + |
3922 | 3923 |
|
3923 |
| - |
3924 | 3924 | };
|
3925 | 3925 |
|
3926 | 3926 |
|
|
3939 | 3939 | // this.__$$StampDomCounter$$__ = (this.__$$StampDomCounter$$__ || 0) + 1;
|
3940 | 3940 | // this.__$$fs892$$__ = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
|
3941 | 3941 |
|
3942 |
| - if (a.length === 1 && Object.keys(a[0]).length === 0) a.length = 0; |
3943 |
| - const isNonEmptyArray = (a || 0).length >= 1; |
3944 |
| - if (!isNonEmptyArray) { |
3945 |
| - return fn.call(this, undefined, b, undefined, d); |
3946 |
| - } else if (h === undefined && typeof b === 'string' && c && typeof c === 'object' && this.is && val_kevlar_should_maintain_stable_list) { |
| 3942 | + let t; |
| 3943 | + let n = (a || 0).length; |
| 3944 | + if (n === 1 && typeof (t = (a[0] || {})) === 'object' && Object.keys(t).length === 0) n = 0; |
| 3945 | + const isEmptyArray = !(n >= 1); |
| 3946 | + if (isEmptyArray) return fn.call(this, undefined, b, undefined, d); |
| 3947 | + |
| 3948 | + if (h === undefined && typeof b === 'string' && c && typeof c === 'object' && this.is && val_kevlar_should_maintain_stable_list) { |
3947 | 3949 | if (c.clientSideToggleMenuItemRenderer) {
|
3948 | 3950 | h = false;
|
3949 | 3951 | } else {
|
3950 | 3952 | h = true;
|
3951 | 3953 | }
|
3952 | 3954 | }
|
3953 | 3955 |
|
3954 |
| - if (DO_createStampDomArrayFnE1_ && typeof (this.is || 0) === 'string' && isNonEmptyArray && typeof (b || 0) === 'string' && typeof (c || 0) === 'object') { |
| 3956 | + if (DO_createStampDomArrayFnE1_ && typeof (this.is || 0) === 'string' && typeof (b || 0) === 'string' && typeof (c || 0) === 'object') { |
3955 | 3957 | // !!c <=> typeof c should be always object
|
3956 | 3958 |
|
3957 | 3959 | const constraintE = DO_createStampDomArrayFnE1_noConstraintE ? true : !shouldTriggerRendererStamperFinished;
|
|
3966 | 3968 |
|
3967 | 3969 | // this.__$$fs892$$__ = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
|
3968 | 3970 |
|
3969 |
| - let domShell = (container && container.__domApi); |
| 3971 | + let domShell = container.__domApi; |
3970 | 3972 |
|
3971 | 3973 | if (!domShell) {
|
3972 |
| - fn.call(this, undefined, b, undefined, d); |
3973 |
| - domShell = container && container.__domApi; |
| 3974 | + // -- request __domApi -- |
| 3975 | + const o = { |
| 3976 | + getStampContainer_: this.getStampContainer_.bind(this), |
| 3977 | + get is() { |
| 3978 | + throw new Error(); |
| 3979 | + }, |
| 3980 | + get isAttached() { |
| 3981 | + throw new Error(); |
| 3982 | + }, |
| 3983 | + get hostElement() { |
| 3984 | + throw new Error(); |
| 3985 | + } |
| 3986 | + // isAttached: false, |
| 3987 | + // hostElement: null |
| 3988 | + }; |
| 3989 | + const d = {}; |
| 3990 | + d.valueOf = () => { |
| 3991 | + throw new Error(); |
| 3992 | + }; |
| 3993 | + try { |
| 3994 | + fn.call(o, undefined, b, undefined, d); |
| 3995 | + } catch (e) { |
| 3996 | + } |
| 3997 | + // -- request __domApi -- |
| 3998 | + |
| 3999 | + // fn.call(this, undefined, b, undefined, d); // erase the contents. so byPass is required. |
| 4000 | + domShell = container.__domApi; |
| 4001 | + if (!domShell) { |
| 4002 | + try { |
| 4003 | + fn.call(this, undefined, b, undefined, d); |
| 4004 | + domShell = container.__domApi; |
| 4005 | + } catch (e) { } |
| 4006 | + } |
3974 | 4007 | }
|
3975 | 4008 |
|
3976 | 4009 |
|
|
0 commit comments