Skip to content

Commit ad37daa

Browse files
committed
YouTube JS Engine Tamer | Fix
1 parent 789fe29 commit ad37daa

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

473972.user.js

Lines changed: 64 additions & 22 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.5
4+
// @version 0.18.6
55
// @match https://www.youtube.com/*
66
// @match https://www.youtube-nocookie.com/embed/*
77
// @match https://studio.youtube.com/live_chat*
@@ -3579,6 +3579,8 @@
35793579

35803580
const csb = (a, b) => { for (const c in a) if (a.hasOwnProperty(c) && b[c]) return c; return null }
35813581
const createStampDomArrayFnE1_ = async function (a, b, c, d, shouldTriggerRendererStamperFinished, h) {
3582+
3583+
const t892 = this.__$$fs892$$__ = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
35823584
// c - mapping
35833585
// d - reuseComponents
35843586
// e - events (shouldTriggerRendererStamperFinished)
@@ -3592,6 +3594,8 @@
35923594
const c_ = c;
35933595
const a_ = a;
35943596

3597+
const {data, __data} = this; // for data integrity check
3598+
35953599
const doDeferRenderStamperBinding_ = async (cp) => {
35963600
const i = cp[stampIdxSb];
35973601
const u = a_[i];
@@ -3607,12 +3611,30 @@
36073611
const hasElement = !!domShell.firstElementChild;
36083612
const noscript = document.createElement('noscript');
36093613
// document.body.appendChild(noscript);
3614+
3615+
let doc = document;
3616+
// ---------- doc ----------
3617+
// let docHTML = '<html></html>';
3618+
// try {
3619+
// docHTML = trustedTypes.defaultPolicy.createHTML(docHTML) || docHTML;
3620+
// } catch (e) { }
3621+
// try {
3622+
// const parser = new DOMParser();
3623+
// doc = parser.parseFromString(docHTML, "text/html");
3624+
// } catch (e) { }
3625+
// ---------- doc ----------
3626+
3627+
// document.documentElement.appendChild.call(doc.documentElement, noscript);
3628+
// nativeRemoveE.call(noscript);
3629+
// doc = null;
3630+
parser = null;
3631+
// console.log(doc,38);
3632+
36103633
const nofn = () => true;
36113634
const n = a_.length;
36123635
const fns = new Array(n);
36133636
let cxt = 0;
36143637

3615-
let mutex = Promise.resolve(0);
36163638
let qxd = hasElement ? new WeakSet() : null;
36173639
const nextTickFnE1 = () => {
36183640
a_.some((u, i) => {
@@ -3626,9 +3648,9 @@
36263648
const cp = this.createComponent_(c[x], u[x], d);
36273649
cp[stampIdxSb] = i;
36283650
doDeferRenderStamperBinding_(cp);
3629-
mutex = mutex.then(() => {
3651+
// mutex = mutex.then(() => {
36303652
noscript.appendChild(cp);
3631-
});
3653+
// });
36323654

36333655
// Promise.resolve(cp).then(doDeferRenderStamperBinding_);
36343656
let q = cp;
@@ -3679,9 +3701,9 @@
36793701

36803702
cp[stampIdxSb] = i;
36813703
doDeferRenderStamperBinding_(cp);
3682-
mutex = mutex.then(() => {
3704+
// mutex = mutex.then(() => {
36833705
noscript.appendChild(cp); // ui formation
3684-
});
3706+
// });
36853707

36863708
// Promise.resolve(cp).then(doDeferRenderStamperBinding_);
36873709
let q = cp;
@@ -3730,6 +3752,11 @@
37303752
fns.length = 0;
37313753
qxd = null;
37323754

3755+
3756+
3757+
// document.documentElement.appendChild.call(doc.documentElement, noscript);
3758+
// nativeRemoveE.call(noscript);
3759+
37333760
// nativeRemoveE.call(noscript);
37343761
noscript.remove(); // trigger isAttached change
37353762
const hostElement = this.hostElement;
@@ -3748,12 +3775,27 @@
37483775

37493776

37503777
/** @type {DocumentFragment} */
3751-
const gFragment = document.createDocumentFragment();
3778+
// const gFragment = document.createDocumentFragment();
3779+
const gFragment = doc.createDocumentFragment();
3780+
3781+
const fnE = () => {
3782+
const evt = new CustomEvent("yt-rendererstamper-finished", {
3783+
bubbles: !0,
3784+
cancelable: !1,
3785+
composed: !0,
3786+
detail: {
3787+
container
3788+
}
3789+
});
3790+
hostElement.dispatchEvent(evt);
3791+
};
37523792

3753-
mutex = mutex.then(async() => {
3793+
let f1, f2;
3794+
f1 = async() => {
37543795

37553796
// await new Promise(r=>setTimeout(r, 1000));
37563797

3798+
if (t892 !== this.__$$fs892$$__ || this.data !== data || this.__data !== __data) return;
37573799

37583800
if (!hasElement && !!domShell.firstElementChild) return;
37593801
if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
@@ -3775,7 +3817,13 @@
37753817
// const t2 = performance.now();
37763818

37773819
// console.log('createStampDomArrayFn_{T2}', t2-t1);
3778-
}).then(async () => {
3820+
3821+
nextBrowserTick_(f2);
3822+
};
3823+
3824+
f2 = async () => {
3825+
3826+
if (t892 !== this.__$$fs892$$__ || this.data !== data || this.__data !== __data) return;
37793827

37803828
if (!hasElement && !!domShell.firstElementChild) return;
37813829
if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
@@ -3820,30 +3868,24 @@
38203868
// console.log('createStampDomArrayFn_{T3}', t2-t1); // time consuming
38213869

38223870
if (shouldTriggerRendererStamperFinished) {
3823-
nextBrowserTick_(() => {
3824-
const evt = new CustomEvent("yt-rendererstamper-finished", {
3825-
bubbles: !0,
3826-
cancelable: !1,
3827-
composed: !0,
3828-
detail: {
3829-
container
3830-
}
3831-
});
3832-
hostElement.dispatchEvent(evt);
3833-
})();
3871+
nextBrowserTick_(fnE);
38343872
}
38353873

38363874
// this.flushRenderStamperComponentBindings_();
38373875

38383876

38393877

38403878

3841-
});
3879+
};
3880+
3881+
nextBrowserTick_(f1);
3882+
38423883
};
38433884

38443885

38453886
const stampIdxSb = Symbol();
3846-
const byPassIs55 = new Set(['ytd-rich-grid-renderer', 'ytd-rich-item-renderer', 'ytd-rich-grid-media', 'ytd-rich-section-renderer', 'ytd-rich-shelf-renderer']); // some issues for the view model
3887+
// const byPassIs55 = new Set(['ytd-rich-grid-renderer', 'ytd-rich-item-renderer', 'ytd-rich-grid-media', 'ytd-rich-section-renderer', 'ytd-rich-shelf-renderer']); // some issues for the view model
3888+
const byPassIs55 = new Set(['ytd-rich-grid-renderer', 'ytd-rich-shelf-renderer']);
38473889
const createStampDomArrayFn_ = (fn) => {
38483890
if (val_kevlar_should_maintain_stable_list === null) {
38493891
const config_ = ((window.yt || 0).config_ || 0);

0 commit comments

Comments
 (0)