Skip to content

Commit 436b1e8

Browse files
committed
YouTube JS Engine Tamer | Code Fix
1 parent 178ca98 commit 436b1e8

File tree

1 file changed

+98
-65
lines changed

1 file changed

+98
-65
lines changed

473972.user.js

Lines changed: 98 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name YouTube JS Engine Tamer
33
// @namespace UserScripts
4-
// @version 0.18.9
4+
// @version 0.18.10
55
// @match https://www.youtube.com/*
66
// @match https://www.youtube-nocookie.com/embed/*
77
// @match https://studio.youtube.com/live_chat*
@@ -3578,7 +3578,7 @@
35783578
let val_kevlar_should_maintain_stable_list = null;
35793579

35803580
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) {
35823582

35833583

35843584
// this.__$$fs894$$__ = this.__$$fs894$$__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
@@ -3770,28 +3770,28 @@
37703770

37713771
// document.documentElement.appendChild.call(doc.documentElement, noscript);
37723772
// nativeRemoveE.call(noscript);
3773-
3773+
37743774
// nativeRemoveE.call(noscript);
37753775
noscript.remove(); // trigger isAttached change
37763776
const hostElement = this.hostElement;
3777-
3777+
37783778
// console.log('em77', hasElement, noscript.childElementCount, domShell.childElementCount, cxt, a_.length);
37793779
// if(a_.length !== noscript.childElementCount+ domShell.childElementCount+ cxt){
37803780
// const pd = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
3781-
3781+
37823782
// console.log('em77b', pd, [...a_], [...noscript.childNodes], [...domShell.childNodes])
37833783
// setTimeout(()=>{
37843784
// console.log('em77c', pd, [...domShell.childNodes])
37853785
// }, 1000)
37863786
// }
3787-
3787+
37883788
// const sdc02 = this.__$$StampDomCounter$$__;
3789-
3790-
3789+
3790+
37913791
/** @type {DocumentFragment} */
37923792
// const gFragment = document.createDocumentFragment();
37933793
const gFragment = doc.createDocumentFragment();
3794-
3794+
37953795
const fnE = () => {
37963796
const evt = new CustomEvent("yt-rendererstamper-finished", {
37973797
bubbles: !0,
@@ -3803,21 +3803,21 @@
38033803
});
38043804
hostElement.dispatchEvent(evt);
38053805
};
3806-
3806+
38073807
let f1, f2;
3808-
f1 = async() => {
3808+
f1 = async () => {
38093809
await new Promise(r => nextBrowserTick_(r));
38103810
// if (t892 !== this.__$$fs892$$__) return;
38113811
// await new Promise(r=>setTimeout(r, 1000));
3812-
3812+
38133813
if (this.data !== data || this.__data !== __data) return;
3814-
3814+
38153815
if (!hasElement && !!domShell.firstElementChild) return;
38163816
if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
38173817
return;
38183818
}
38193819
// const t1 = performance.now();
3820-
3820+
38213821
if (DO_createStampDomArrayFnE1_nativeAppendD) {
38223822
let elm;
38233823
while (elm = noscript.firstChild) {
@@ -3830,84 +3830,84 @@
38303830
}
38313831
}
38323832
// const t2 = performance.now();
3833-
3833+
38343834
// console.log('createStampDomArrayFn_{T2}', t2-t1);
3835-
3835+
38363836
// nextBrowserTick_(f2);
38373837
return true;
38383838
};
3839-
3839+
38403840
f2 = async () => {
38413841
await new Promise(r => nextBrowserTick_(r));
38423842
// if (t892 !== this.__$$fs892$$__) return;
38433843
if (this.data !== data || this.__data !== __data) return;
3844-
3844+
38453845
if (!hasElement && !!domShell.firstElementChild) return;
38463846
if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
38473847
return;
38483848
}
3849-
3849+
38503850
// const t1 = performance.now();
38513851
// const arr = [...noscript.childNodes];
38523852
// g.append(...arr);
3853-
3853+
38543854
// 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+
38693864
// }
3870-
3871-
3872-
3865+
3866+
// }else{
3867+
3868+
domShell.appendChild(gFragment);
3869+
// }
3870+
3871+
3872+
38733873
// for (const cp of arr) {
38743874
// const i = cp[stampIdxSb];
38753875
// const u = a_[i];
38763876
// const c = c_;
38773877
// const x = csb(c, u);
38783878
// this.deferRenderStamperBinding_(cp, c[x], u[x]); // necessary?
38793879
// }
3880-
3880+
38813881
this.flushRenderStamperComponentBindings_();
38823882
this.markDirty && this.markDirty();
3883-
// const t2 = performance.now();
3884-
3883+
// const t2 = performance.now();
3884+
38853885
// 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+
38923892
// this.flushRenderStamperComponentBindings_();
3893-
3894-
3895-
3893+
3894+
3895+
38963896
return true;
3897-
3897+
38983898
};
38993899

39003900
const r1 = await f1();
3901-
if(r1 === true){
3901+
if (r1 === true) {
3902+
39023903

3903-
39043904
const r2 = await f2();
39053905
// p892R();
39063906
}
39073907

39083908
// console.log(1883 , this.__$$fs894$$__)
3909-
3910-
3909+
3910+
39113911

39123912

39133913
}catch(err){
@@ -3918,9 +3918,9 @@
39183918
//
39193919
}
39203920

3921-
}).catch(()=>0);
3921+
}).catch(() => 0);
3922+
39223923

3923-
39243924
};
39253925

39263926

@@ -3939,19 +3939,21 @@
39393939
// this.__$$StampDomCounter$$__ = (this.__$$StampDomCounter$$__ || 0) + 1;
39403940
// this.__$$fs892$$__ = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
39413941

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) {
39473949
if (c.clientSideToggleMenuItemRenderer) {
39483950
h = false;
39493951
} else {
39503952
h = true;
39513953
}
39523954
}
39533955

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') {
39553957
// !!c <=> typeof c should be always object
39563958

39573959
const constraintE = DO_createStampDomArrayFnE1_noConstraintE ? true : !shouldTriggerRendererStamperFinished;
@@ -3966,11 +3968,42 @@
39663968

39673969
// this.__$$fs892$$__ = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
39683970

3969-
let domShell = (container && container.__domApi);
3971+
let domShell = container.__domApi;
39703972

39713973
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+
}
39744007
}
39754008

39764009

0 commit comments

Comments
 (0)