YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前为 2024-01-17 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.10.3
  6. // @license MIT
  7. // @author CY Fung
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/yt-engine.png
  9. // @description To enhance YouTube performance by modifying YouTube JS Engine
  10. // @grant none
  11. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@4871cab1b40a53521e6578f92ca10fc03b4ce823/library/nextBrowserTick.min.js
  12. // @run-at document-start
  13. // @unwrap
  14. // @inject-into page
  15. // @allFrames true
  16. // ==/UserScript==
  17.  
  18. (() => {
  19.  
  20. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  21. const FIX_schedulerInstanceInstance_V1 = false;
  22. const FIX_schedulerInstanceInstance_V2 = true;
  23. const FIX_yt_player = true;
  24. const FIX_Animation_n_timeline = true;
  25. const NO_PRELOAD_GENERATE_204 = false;
  26. const CHANGE_appendChild = true;
  27.  
  28. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  29. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  30. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  31.  
  32. const FIX_Iframe_NULL_SRC = true;
  33.  
  34. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  35.  
  36. const FIX_stampDomArray_stableList = true;
  37. const FIX_ytdExpander_childrenChanged = true;
  38. const FIX_paper_ripple_animate = true;
  39. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  40. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  41.  
  42. const FIX_doIdomRender = true;
  43.  
  44. const FIX_Shady = true;
  45.  
  46. const FIX_ytAction_ = true; // ytd-app
  47. const FIX_onVideoDataChange = false;
  48. // const FIX_onClick = true;
  49. const FIX_onStateChange = true;
  50. const FIX_onLoopRangeChange = true;
  51. const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  52. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  53.  
  54. const ENABLE_discreteTasking = true;
  55. // << if ENABLE_discreteTasking >>
  56. const ENABLE_weakenStampReferences = true;
  57. // << end >>
  58.  
  59. const FIX_perfNow = true;
  60. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  61.  
  62. const UNLOAD_DETACHED_POLYMER = false; // unstable
  63.  
  64. const WEAK_REF_BINDING = true; // false if your browser is slow
  65. // << if WEAK_REF_BINDING >>
  66. const WEAK_REF_PROXY_DOLLAR = true; // false if your browser is slow
  67. // << end >>
  68.  
  69. const FIX_XHR_REQUESTING = true;
  70. const FIX_VIDEO_BLOCKING = true; // usually it is a ads block issue
  71.  
  72.  
  73. /*
  74. window.addEventListener('edm',()=>{
  75. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  76. });
  77.  
  78. window.addEventListener('edn',()=>{
  79. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  80. });
  81. window.addEventListener('edr',()=>{
  82. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  83. });
  84. */
  85.  
  86. // only for macOS with Chrome/Firefox 100+
  87. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  88.  
  89. const win = this instanceof Window ? this : window;
  90.  
  91. // Create a unique key for the script and check if it is already running
  92. const hkey_script = 'jswylcojvzts';
  93. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  94. win[hkey_script] = true;
  95.  
  96.  
  97. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  98. /** @type {(f: ()=>{})=>{}} */
  99. const nextBrowserTick = (self || 0).nextBrowserTick || 0;
  100.  
  101. let p59 = 0;
  102.  
  103. const Promise = (async () => { })().constructor;
  104.  
  105. const PromiseExternal = ((resolve_, reject_) => {
  106. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  107. return class PromiseExternal extends Promise {
  108. constructor(cb = h) {
  109. super(cb);
  110. if (cb === h) {
  111. /** @type {(value: any) => void} */
  112. this.resolve = resolve_;
  113. /** @type {(reason?: any) => void} */
  114. this.reject = reject_;
  115. }
  116. }
  117. };
  118. })();
  119.  
  120.  
  121. let pf31 = new PromiseExternal();
  122.  
  123. // native RAF
  124. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  125.  
  126. // 1st wrapped RAF
  127. const baseRAF = (callback) => {
  128. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  129. pf31.then(() => {
  130. callback(hRes);
  131. });
  132. });
  133. };
  134.  
  135. // 2nd wrapped RAF
  136. window.requestAnimationFrame = baseRAF;
  137.  
  138. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  139. const indr = o => insp(o).$ || o.$ || 0;
  140.  
  141. /** @type {(o: Object | null) => WeakRef | null} */
  142. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  143.  
  144. /** @type {(wr: Object | null) => Object | null} */
  145. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  146.  
  147. FIX_perfNow && (() => {
  148. let nowh = -1;
  149. const dtl = new DocumentTimeline();
  150. performance.now = performance.now16 = function () {
  151.  
  152. /**
  153. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  154. *
  155. * If consecutive session history entries had history.state.entryTime set to same value,
  156. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  157. * and modifying its return value slightly to make sure two close consecutive calls don't
  158. * get the same result helped with resolving the issue.
  159. */
  160.  
  161. let t = nowh;
  162. let c = dtl.currentTime;
  163. return (nowh = (t + 1e-7 > c ? t + 1e-5 : c));
  164. }
  165. if (performance.now !== performance.now16) { // might not able to set in Firefox
  166. if (performance.now() === performance.now()) console.warn('performance.now() is not mono increasing.');
  167. }
  168. })();
  169.  
  170. if (ENABLE_ASYNC_DISPATCHEVENT && nextBrowserTick) {
  171. const filter = new Set([
  172. 'yt-action',
  173. // 'iframe-src-replaced',
  174. 'shown-items-changed',
  175. 'can-show-more-changed', 'collapsed-changed',
  176.  
  177. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  178. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  179. 'yt-navigate-finish',
  180.  
  181. // 'data-changed','yt-watch-comments-ready'
  182. ])
  183. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  184. EventTarget.prototype.dispatchEvent = function (event) {
  185. const type = (event || 0).type;
  186. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  187. if (!filter.has(type) && !type.endsWith('-changed')) {
  188. if (this instanceof Node || this instanceof Window) {
  189. nextBrowserTick(() => this.dispatchEvent938(event));
  190. return true;
  191. }
  192. }
  193. }
  194. return this.dispatchEvent938(event);
  195. }
  196. }
  197.  
  198. if (FIX_XHR_REQUESTING) {
  199.  
  200. const URL = window.URL || new Function('return URL')();
  201. const createObjectURL = URL.createObjectURL.bind(URL);
  202.  
  203. XMLHttpRequest = (() => {
  204. const XMLHttpRequest_ = XMLHttpRequest;
  205. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  206. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  207. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  208. constructor(...args) {
  209. super(...args);
  210. }
  211. open(method, url, ...args) {
  212. let skip = false;
  213. if (!url || typeof url !== 'string') skip = true;
  214. else if (typeof url === 'string') {
  215. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  216. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  217. skip = true;
  218. } else if (turl.includes('.youtube.com/pagead/')) {
  219. skip = true;
  220. } else if (turl.includes('.youtube.com/ptracking')) {
  221. skip = true;
  222. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  223. skip = true;
  224. } else if (turl.includes('play.google.com/log')) {
  225. skip = true;
  226. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  227. skip = true;
  228. }
  229. }
  230. if (!skip) {
  231. this.__xmMc8__ = 1;
  232. return super.open(method, url, ...args);
  233. } else {
  234. this.__xmMc8__ = 2;
  235. return super.open('GET', url0);
  236. }
  237. }
  238. send(...args) {
  239. if (this.__xmMc8__ === 1) {
  240. return super.send(...args);
  241. } else if (this.__xmMc8__ === 2) {
  242. return super.send();
  243. } else {
  244. console.log('xhr warning');
  245. return super.send(...args);
  246. }
  247. }
  248. }
  249. c.prototype.__xmMc8__ = 0;
  250. return c;
  251. })();
  252. }
  253.  
  254.  
  255.  
  256. const check_for_set_key_order = (() => {
  257.  
  258. let mySet = new Set();
  259.  
  260. mySet.add("value1");
  261. mySet.add("value2");
  262. mySet.add("value3");
  263.  
  264. // Function to convert Set values to an array
  265. function getSetValues(set) {
  266. return Array.from(set.values());
  267. }
  268.  
  269. // Function to test if the Set maintains insertion order
  270. function testSetOrder(set, expectedOrder) {
  271. let values = getSetValues(set);
  272. return expectedOrder.join(',') === values.join(',');
  273. }
  274.  
  275. // Test 1: Initial order
  276. if (mySet.values().next().value !== "value1") return false;
  277. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  278.  
  279. // Test 2: After deleting an element
  280. mySet.delete("value2");
  281. if (mySet.values().next().value !== "value1") return false;
  282. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  283.  
  284. // Test 3: After re-adding a deleted element
  285. mySet.add("value2");
  286. if (mySet.values().next().value !== "value1") return false;
  287. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  288.  
  289. // Test 4: After adding a new element
  290. mySet.add("value4");
  291. if (mySet.values().next().value !== "value1") return false;
  292. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  293.  
  294. // Test 5: Delete+Add
  295. mySet.delete("value1");
  296. mySet.delete("value3");
  297. mySet.add("value3");
  298. mySet.add("value1");
  299. if (mySet.values().next().value !== "value2") return false;
  300. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  301.  
  302. return true;
  303. })();
  304.  
  305.  
  306.  
  307. // const qm47 = Symbol();
  308. const qm57 = Symbol();
  309. const qm53 = Symbol();
  310. const qn53 = Symbol();
  311.  
  312.  
  313. const ump3 = new WeakMap();
  314.  
  315. const stp = document.createElement('noscript');
  316. stp.id = 'weakref-placeholder'
  317.  
  318.  
  319. const setupD = typeof WeakRef !== 'undefined' ? (elm, s, usePlaceholder) => {
  320.  
  321. const z = `${s}72`;
  322.  
  323. if (s in elm) {
  324. // console.log(1162, elm[s], elm)
  325.  
  326. const p = elm[s];
  327.  
  328. delete elm[s];
  329.  
  330. Object.defineProperty(elm, s, {
  331. get() {
  332. const elm = this;
  333. const wr = elm[z];
  334. if (!wr) return null;
  335. const m = kRef(wr);
  336. if (!m && usePlaceholder) {
  337. if (typeof usePlaceholder === 'function') usePlaceholder(elm);
  338. return stp;
  339. }
  340. return m;
  341. },
  342. set(nv) {
  343. const elm = this;
  344. elm[z] = nv ? mWeakRef(nv) : null;
  345. return true;
  346. },
  347. configurable: true,
  348. enumerable: true
  349.  
  350. });
  351.  
  352. elm[s] = p;
  353. elm = null;
  354.  
  355.  
  356. }
  357. } : null;
  358.  
  359. const mxMap = new WeakMap();
  360.  
  361. const myMap = new WeakSet();
  362.  
  363. const setup$ = typeof WeakRef !== 'undefined' ? function (dh) {
  364.  
  365. const $ = dh.$;
  366. // const elements_ = dh.elements_;
  367.  
  368. // setupD(dh, '$');
  369.  
  370.  
  371. if (WEAK_REF_PROXY_DOLLAR && $ && typeof $ === 'object' && !dh.$ky37) {
  372.  
  373. dh.$ky37 = 1;
  374.  
  375. if (!myMap.has($)) {
  376.  
  377.  
  378.  
  379.  
  380. for (const k of Object.keys($)) {
  381.  
  382. const v = $[k];
  383. if ($[k] instanceof Node) {
  384.  
  385. $[k] = mWeakRef($[k]);
  386.  
  387. }
  388.  
  389. }
  390.  
  391.  
  392.  
  393. dh.$ = mxMap.get($) || new Proxy($, {
  394. get(obj, prop) {
  395. const val = obj[prop];
  396. if (typeof (val || 0).deref === 'function') {
  397. return val.deref();
  398. }
  399. return val;
  400. },
  401. set(obj, prop, val) {
  402. if (val instanceof Node) {
  403. obj[prop] = mWeakRef(val);
  404. } else {
  405. obj[prop] = val;
  406. }
  407. return true;
  408. }
  409. });
  410.  
  411. mxMap.set($, dh.$);
  412. myMap.add(dh.$);
  413.  
  414. }
  415.  
  416.  
  417.  
  418.  
  419. }
  420.  
  421.  
  422.  
  423.  
  424. // if (WEAK_REF_PROXY_DOLLAR && elements_ && typeof elements_ === 'object' && !dh.$ky38) {
  425.  
  426. // dh.$ky38 = 1;
  427.  
  428. // if (!myMap.has(elements_)) {
  429.  
  430.  
  431.  
  432.  
  433. // for (const k of Object.keys(elements_)) {
  434.  
  435. // const v = elements_[k];
  436. // if (elements_[k] instanceof Node) {
  437.  
  438. // elements_[k] = new WeakRef(elements_[k]);
  439.  
  440. // }
  441.  
  442. // }
  443.  
  444. // /*
  445.  
  446.  
  447.  
  448. // dh.elements_ = mxMap.get(elements_) || new Proxy(elements_, {
  449. // get(obj, prop) {
  450. // const val = obj[prop];
  451. // if (typeof (val || 0).deref === 'function') {
  452. // return val.deref();
  453. // }
  454. // return val;
  455. // },
  456. // set(obj, prop, val) {
  457. // if (val instanceof Node) {
  458. // obj[prop] = new WeakRef(val);
  459. // } else {
  460. // obj[prop] = val;
  461. // }
  462. // return true;
  463. // }
  464. // });
  465.  
  466. // console.log(dh, dh.elements_, elements_)
  467.  
  468. // mxMap.set(elements_, dh.elements_);
  469. // myMap.add(dh.elements_);
  470.  
  471. // */
  472. // }
  473.  
  474.  
  475.  
  476.  
  477. // }
  478.  
  479.  
  480.  
  481.  
  482.  
  483. } : null;
  484.  
  485.  
  486. const configureVisibilityObserverT_ = function () {
  487. const hostElement = this.hostElement;
  488. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  489. this.unobserve_();
  490. } else {
  491. return this.configureVisibilityObserver27_();
  492. }
  493. };
  494. const getParentRendererT = function () {
  495. const hostElement = this.hostElement;
  496. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  497. return null;
  498. } else {
  499. return this.getParentRenderer27();
  500. }
  501. }
  502. const readyT = function () {
  503. const hostElement = this.hostElement;
  504. let b = false;
  505. if (this.enableContentEditableChanged_) {
  506. b = true;
  507. } else if (this.is && this.is.length > 15 && this.is.length < 20) {
  508.  
  509. } else {
  510. b = true;
  511. }
  512. if (b) {
  513. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  514. return void 0;
  515. }
  516. }
  517. return this.ready27.apply(this, arguments);
  518. }
  519. const _enablePropertiesT = function () {
  520. const hostElement = this.hostElement;
  521. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  522. return void 0;
  523. }
  524. return this._enableProperties27();
  525. }
  526.  
  527. const attachedT = function () {
  528. const hostElement = this.hostElement;
  529. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  530. if (this.isAttached === true) this.isAttached = false;
  531. return void 0;
  532. } else {
  533. return this.attached27();
  534. }
  535. }
  536.  
  537. const hostElementCleanUp = (dh) => {
  538. if (typeof dh.dispose === 'function') {
  539. try {
  540. if (dh.visibilityMonitor || dh.visibilityObserver) {
  541. dh.dispose();
  542. dh.visibilityMonitor = null;
  543. dh.visibilityObserver = null;
  544. }
  545. } catch (e) { }
  546. }
  547. if (typeof dh.detached === 'function') {
  548. try {
  549. if (dh.visibilityObserverForChild_ || dh.localVisibilityObserver_) {
  550. dh.detached();
  551. dh.visibilityObserverForChild_ = null;
  552. dh.localVisibilityObserver_ = null;
  553. }
  554. } catch (e) { }
  555. }
  556. // if (dh.__dataEnabled === true) {
  557. // dh.__dataEnabled = false;
  558. // }
  559. };
  560. const setupDataHost = setupD && setup$ ? function (dh, opt) {
  561.  
  562. if (dh && typeof dh === 'object') {
  563.  
  564. if (typeof dh.configureVisibilityObserver_ === 'function' && !dh.configureVisibilityObserver27_) {
  565. dh.configureVisibilityObserver27_ = dh.configureVisibilityObserver_;
  566. dh.configureVisibilityObserver_ = configureVisibilityObserverT_;
  567. }
  568.  
  569. if (typeof dh.getParentRenderer === 'function' && !dh.getParentRenderer27) {
  570. dh.getParentRenderer27 = dh.getParentRenderer;
  571. dh.getParentRenderer = getParentRendererT;
  572. }
  573.  
  574. // if (!opt) {
  575.  
  576. // if (typeof dh.ready === 'function' && !dh.ready27) {
  577. // dh.ready27 = dh.ready;
  578. // dh.ready = readyT;
  579. // }
  580.  
  581. // }
  582.  
  583. // if (typeof dh._enableProperties === 'function' && !dh._enableProperties27) {
  584. // dh._enableProperties27 = dh._enableProperties;
  585. // dh._enableProperties = _enablePropertiesT;
  586. // }
  587.  
  588. if (typeof dh.attached === 'function' && !dh.attached27) {
  589. dh.attached27 = dh.attached;
  590. dh.attached = attachedT;
  591. }
  592.  
  593. setupD(dh, 'hostElement', hostElementCleanUp);
  594. setupD(dh, 'parentComponent');
  595. setupD(dh, 'localVisibilityObserver_');
  596. setupD(dh, 'cachedProviderNode_');
  597.  
  598.  
  599. setupD(dh, '__template');
  600. setupD(dh, '__templatizeOwner');
  601. setupD(dh, '__templateInfo');
  602.  
  603. // setupD(dh, 'root', 1);
  604.  
  605. const elements_ = dh.elements_;
  606. if (elements_ && typeof elements_ === 'object' && Object.keys(elements_).length > 0) setupD(dh, 'elements_');
  607.  
  608.  
  609.  
  610. setup$(dh);
  611. }
  612.  
  613.  
  614.  
  615.  
  616. } : null;
  617.  
  618.  
  619. let delay300 = null;
  620.  
  621. if (UNLOAD_DETACHED_POLYMER || WEAK_REF_BINDING) {
  622. delay300 = new PromiseExternal();
  623. setInterval(() => {
  624. delay300.resolve();
  625. delay300 = new PromiseExternal();
  626. }, 300);
  627. }
  628.  
  629. const aDelay = async function () {
  630. await delay300.then();
  631. await delay300.then();
  632. }
  633.  
  634. const convertionFuncMap = new WeakMap();
  635. let val_kevlar_should_maintain_stable_list = null;
  636.  
  637. const createStampDomArrayFn_ = (fn) => {
  638. if (val_kevlar_should_maintain_stable_list === null) {
  639. const config_ = ((window.yt || 0).config_ || 0);
  640. val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true
  641. }
  642. const gn = function (a, b, c, d, e, h) {
  643. const isNonEmptyArray = (a || 0).length >= 1
  644. if (!isNonEmptyArray) {
  645. return fn.call(this, undefined, b, undefined, d);
  646. } else if (h === undefined && typeof b === 'string' && c && typeof c === 'object' && this.is && val_kevlar_should_maintain_stable_list) {
  647. if (c.clientSideToggleMenuItemRenderer) {
  648. h = false;
  649. } else {
  650. h = true;
  651. }
  652. }
  653. return fn.call(this, a, b, c, d, e, h)
  654. }
  655. gn.originalFn = fn;
  656. convertionFuncMap.set(fn, gn);
  657. return gn;
  658. }
  659.  
  660. const fixStampDomArrayStableList = (h) => {
  661. if (!h.stampDomArray_) return;
  662. const proto = h.__proto__;
  663. const f = proto.stampDomArray_;
  664. if (!proto.stampDomArrayF001_ && typeof f === 'function' && f.length === 6) {
  665. proto.stampDomArrayF001_ = 1;
  666. proto.stampDomArray_ = convertionFuncMap.get(f) || createStampDomArrayFn_(f);
  667. }
  668. }
  669.  
  670. const weakenStampReferences = (() => {
  671.  
  672. const DEBUG_STAMP = false;
  673.  
  674. const s1 = Symbol();
  675. const handler1 = {
  676. get(target, prop, receiver) {
  677. if (prop === 'object') {
  678. return kRef(target[s1]); // avoid memory leakage
  679. }
  680. if (prop === '__proxy312__') return 1;
  681. return target[prop];
  682. }
  683. };
  684. const handler2 = {
  685. get(target, prop, receiver) {
  686. if (prop === 'indexSplices') {
  687. return kRef(target[s1]); // avoid memory leakage
  688. }
  689. if (prop === '__proxy312__') return 1;
  690. return target[prop];
  691. }
  692. }
  693. const handler3 = {
  694. get(target, prop, receiver) {
  695. if (prop === '__proxy312__') return 1;
  696. let w = target[prop]
  697. if (w && typeof w === 'object' && typeof w.deref === 'function') {
  698. return w.deref();
  699. }
  700. return w;
  701. }
  702. }
  703. return (h) => {
  704.  
  705. if (h.rendererStamperApplyChangeRecord_ || h.stampDomArraySplices_) {
  706. const proto = h.__proto__;
  707. if (!proto.yzxer && (proto.rendererStamperApplyChangeRecord_ || proto.stampDomArraySplices_)) {
  708. proto.yzxer = 1;
  709.  
  710. const list = [
  711. // "rendererStamperObserver_", // 3 ==> rendererStamperApplyChangeRecord_
  712. "rendererStamperApplyChangeRecord_", // 3
  713. "forwardRendererStamperChanges_", // 3
  714. "stampDomArraySplices_", // 3
  715. "stampDomArray_", // 6
  716. "deferRenderStamperBinding_", // 3
  717. ];
  718. for (const key of list) {
  719. const pey = `${key}$wq0iw_`
  720. if (typeof proto[key] !== 'function') continue;
  721. // console.log( proto.isRenderer_, 'ms_'+key, proto[key].length, h.is)
  722. if (proto[pey] || proto[key].length === 0) continue;
  723.  
  724. // proto[pey] = proto[key];
  725. // proto[key] = function () {
  726. // console.log(key, arguments.length, [...arguments]);
  727.  
  728. // return proto[pey].apply(this, arguments);
  729. // }
  730.  
  731.  
  732. if (key === 'stampDomArraySplices_' && proto[key].length === 3) {
  733. proto[pey] = proto[key];
  734. proto[key] = function (a, b, c) {
  735.  
  736. if (typeof a === 'string' && typeof b === 'string' && typeof c === 'object' && c && c.indexSplices && c.indexSplices.length >= 1 && !c.indexSplices.rzgjr) {
  737.  
  738. c.indexSplices = c.indexSplices.map(e => {
  739. if (e.__proxy312__) return e;
  740. e[s1] = mWeakRef(e.object);
  741. e.object = null;
  742. return new Proxy(e, handler1);
  743. });
  744. c.indexSplices.rzgjr = 1;
  745.  
  746. c[s1] = mWeakRef(c.indexSplices);
  747. c.indexSplices = null;
  748. c = new Proxy(c, handler2)
  749. arguments[2] = c;
  750.  
  751. }
  752. // console.log(key, arguments.length, [...arguments]);
  753. return proto[pey].call(this, a, b, c);
  754. }
  755.  
  756. } else if (key === 'rendererStamperApplyChangeRecord_' && proto[key].length === 3) {
  757.  
  758.  
  759. // proto[pey] = proto[key];
  760. // proto[key] = function (a, b, c) {
  761.  
  762. // if (typeof a === 'string' && typeof b === 'string' && typeof c === 'object' && c && c.value && c.base) {
  763.  
  764. // if(c.value.length >=1){
  765.  
  766.  
  767. // c.value = c.value.map(e=>{
  768.  
  769. // if(!e.__proxy312__){
  770.  
  771. // for (const k of Object.keys(e)) {
  772. // const v = e[k];
  773. // if(typeof v ==='object' && v && typeof v.length ==='undefined' && !v.deref) e[k] = mWeakRef(v)
  774.  
  775. // }
  776. // return new Proxy(e, handler3);
  777.  
  778. // }
  779.  
  780. // })
  781.  
  782.  
  783. // window.se3=c.value;
  784.  
  785. // }
  786.  
  787. // if(c.base.length >=1){
  788.  
  789. // c.base = c.base.map(e=>{
  790.  
  791. // if(!e.__proxy312__){
  792.  
  793.  
  794. // for (const k of Object.keys(e)) {
  795. // const v = e[k];
  796. // if(typeof v ==='object' && v && typeof v.length ==='undefined' && !v.deref) e[k] = mWeakRef(v)
  797. // }
  798. // return new Proxy(e, handler3);
  799. // }
  800.  
  801.  
  802. // })
  803.  
  804. // console.log(c.base);
  805.  
  806.  
  807. // window.se4=c.base;
  808.  
  809. // }
  810.  
  811.  
  812. // }
  813. // // console.log(key, arguments.length, [...arguments]);
  814. // return proto[pey].call(this, a, b, c);
  815. // }
  816.  
  817. } else if (DEBUG_STAMP) {
  818.  
  819. console.log(proto.isRenderer_, 'ms_' + key, proto[key].length, h.is)
  820. proto[pey] = proto[key];
  821. proto[key] = function () {
  822. if (key === 'rendererStamperApplyChangeRecord_' && typeof arguments[3] === 'object') {
  823. console.log(key, arguments.length, { value: arguments[3].value, base: arguments[3].base, })
  824. }
  825. console.log(key, arguments.length, [...arguments]);
  826. return proto[pey].apply(this, arguments);
  827. }
  828.  
  829. }
  830.  
  831. }
  832.  
  833.  
  834. // const m = (Object.mkss = Object.mkss || new Set());
  835. // Object.keys(h.__proto__).filter(e => e.toLowerCase().includes('stamp') && typeof h[e] === 'function').forEach(e => m.add(e))
  836. // console.log([...m])
  837. }
  838. }
  839.  
  840. }
  841. })();
  842.  
  843. const setupDiscreteTasks = (h, rb) => {
  844.  
  845. if (rb) {
  846. if (h.ky36) return;
  847. }
  848.  
  849.  
  850. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  851. const f = h.onYtRendererstamperFinished;
  852. const g = ump3.get(f) || function () {
  853. if (this.updateChildVisibilityProperties && !this.markDirty) {
  854. return f.apply(this, arguments);
  855. }
  856. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  857. }
  858. ump3.set(f, g);
  859. g.km34 = 1;
  860. h.onYtRendererstamperFinished = g;
  861.  
  862. }
  863.  
  864.  
  865.  
  866.  
  867. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  868. const f = h.onYtUpdateDescriptionAction;
  869. const g = ump3.get(f) || function (a) {
  870. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  871. }
  872. ump3.set(f, g);
  873. g.km34 = 1;
  874. h.onYtUpdateDescriptionAction = g;
  875.  
  876. }
  877.  
  878.  
  879.  
  880. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  881. const f = h.handleUpdateDescriptionAction;
  882. const g = ump3.get(f) || function (a) {
  883. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  884. }
  885. ump3.set(f, g);
  886. g.km34 = 1;
  887. h.handleUpdateDescriptionAction = g;
  888.  
  889. }
  890.  
  891. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  892. const f = h.handleUpdateLiveChatPollAction;
  893. const g = ump3.get(f) || function (a) {
  894. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  895. }
  896. ump3.set(f, g);
  897. g.km34 = 1;
  898. h.handleUpdateLiveChatPollAction = g;
  899.  
  900. }
  901.  
  902.  
  903.  
  904. /*
  905.  
  906.  
  907. if (typeof h.onYtAction_ === 'function' && !(h.onYtAction_.km34)) {
  908. const f = h.onYtAction_;
  909. const g = ump3.get(f) || function (a) {
  910. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  911. }
  912. ump3.set(f, g);
  913. g.km34 = 1;
  914. h.onYtAction_ = g;
  915.  
  916. }
  917.  
  918. */
  919.  
  920.  
  921.  
  922. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  923. const f = h.onTextChanged;
  924. const g = ump3.get(f) || function () {
  925. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  926. }
  927. ump3.set(f, g);
  928. g.km34 = 1;
  929. h.onTextChanged = g;
  930.  
  931. }
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  939. const f = h.onVideoDataChange;
  940. const g = ump3.get(f) || function (a) {
  941. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  942. }
  943. ump3.set(f, g);
  944. g.km34 = 1;
  945. h.onVideoDataChange = g;
  946.  
  947. }
  948.  
  949.  
  950.  
  951.  
  952.  
  953. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  954. const f = h.onVideoDataChange_;
  955. const g = ump3.get(f) || function () {
  956. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  957. }
  958. ump3.set(f, g);
  959. g.km34 = 1;
  960. h.onVideoDataChange_ = g;
  961.  
  962. }
  963.  
  964.  
  965.  
  966.  
  967. if (typeof h.addTooltips === 'function' && !(h.addTooltips.km34)) {
  968.  
  969. const f = h.addTooltips;
  970. const g = ump3.get(f) || function () {
  971. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  972. }
  973. ump3.set(f, g);
  974. g.km34 = 1;
  975. h.addTooltips = g;
  976.  
  977. }
  978.  
  979.  
  980.  
  981.  
  982. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  983.  
  984. const f = h.addTooltips_;
  985. const g = ump3.get(f) || function () {
  986. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  987. }
  988. ump3.set(f, g);
  989. g.km34 = 1;
  990. h.addTooltips_ = g;
  991.  
  992. }
  993.  
  994.  
  995.  
  996. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  997.  
  998. const f = h.updateRenderedElements;
  999. const g = ump3.get(f) || function () {
  1000. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1001. }
  1002. ump3.set(f, g);
  1003. g.km34 = 1;
  1004. h.updateRenderedElements = g;
  1005.  
  1006. }
  1007.  
  1008.  
  1009.  
  1010.  
  1011. /*
  1012. // buggy for yt-player-updated
  1013. if (typeof h.startLoadingWatch === 'function' && !(h.startLoadingWatch.km34)) {
  1014.  
  1015. const f = h.startLoadingWatch;
  1016. const g = ump3.get(f) || function () {
  1017. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1018. }
  1019. ump3.set(f, g);
  1020. g.km34 = 1;
  1021. h.startLoadingWatch = g;
  1022.  
  1023. }
  1024. */
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038. if (typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  1039. const f = h.loadPage_;
  1040. const g = ump3.get(f) || function (a) {
  1041. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1042. }
  1043. ump3.set(f, g);
  1044. g.km34 = 1;
  1045. h.loadPage_ = g;
  1046.  
  1047. }
  1048. if (typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  1049. const f = h.updatePageData_;
  1050. const g = ump3.get(f) || function (a) {
  1051. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1052. }
  1053. ump3.set(f, g);
  1054. g.km34 = 1;
  1055. h.updatePageData_ = g;
  1056.  
  1057. }
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067. if (typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  1068.  
  1069. const f = h.onFocus_;
  1070. const g = ump3.get(f) || function () {
  1071. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1072. }
  1073. ump3.set(f, g);
  1074. g.km34 = 1;
  1075. h.onFocus_ = g;
  1076.  
  1077. }
  1078.  
  1079. if (typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  1080.  
  1081. const f = h.onBlur_;
  1082. const g = ump3.get(f) || function () {
  1083. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1084. }
  1085. ump3.set(f, g);
  1086. g.km34 = 1;
  1087. h.onBlur_ = g;
  1088.  
  1089. }
  1090.  
  1091.  
  1092. if (typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  1093.  
  1094. const f = h.buttonClassChanged_;
  1095. const g = ump3.get(f) || function (a, b) {
  1096. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1097. }
  1098. ump3.set(f, g);
  1099. g.km34 = 1;
  1100. h.buttonClassChanged_ = g;
  1101.  
  1102. }
  1103.  
  1104.  
  1105. if (typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  1106.  
  1107. const f = h.buttonIconChanged_;
  1108. const g = ump3.get(f) || function (a) {
  1109. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1110. }
  1111. ump3.set(f, g);
  1112. g.km34 = 1;
  1113. h.buttonIconChanged_ = g;
  1114.  
  1115. }
  1116.  
  1117.  
  1118. if (typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  1119.  
  1120. const f = h.dataChangedInBehavior_;
  1121. const g = ump3.get(f) || function () {
  1122. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1123. }
  1124. ump3.set(f, g);
  1125. g.km34 = 1;
  1126. h.dataChangedInBehavior_ = g;
  1127.  
  1128. }
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134. if (typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  1135.  
  1136. const f = h.continuationsChanged_;
  1137. const g = ump3.get(f) || function () {
  1138. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1139. }
  1140. ump3.set(f, g);
  1141. g.km34 = 1;
  1142. h.continuationsChanged_ = g;
  1143.  
  1144. }
  1145.  
  1146.  
  1147. if (typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  1148.  
  1149. const f = h.forceChatPoll_;
  1150. const g = ump3.get(f) || function (a) {
  1151. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1152. }
  1153. ump3.set(f, g);
  1154. g.km34 = 1;
  1155. h.forceChatPoll_ = g;
  1156.  
  1157. }
  1158.  
  1159.  
  1160.  
  1161. if (typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  1162.  
  1163. const f = h.onEndpointClick_;
  1164. const g = ump3.get(f) || function (a) {
  1165. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1166. }
  1167. ump3.set(f, g);
  1168. g.km34 = 1;
  1169. h.onEndpointClick_ = g;
  1170.  
  1171. }
  1172.  
  1173.  
  1174. if (typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  1175.  
  1176. const f = h.onEndpointTap_;
  1177. const g = ump3.get(f) || function (a) {
  1178. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1179. }
  1180. ump3.set(f, g);
  1181. g.km34 = 1;
  1182. h.onEndpointTap_ = g;
  1183.  
  1184. }
  1185.  
  1186.  
  1187. if (typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  1188.  
  1189. const f = h.handleClick_;
  1190. const g = ump3.get(f) || function (a, b) {
  1191. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1192. }
  1193. ump3.set(f, g);
  1194. g.km34 = 1;
  1195. h.handleClick_ = g;
  1196.  
  1197. }
  1198.  
  1199.  
  1200.  
  1201. // return;
  1202.  
  1203.  
  1204.  
  1205. if (typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  1206.  
  1207. const f = h.onReadyStateChange_;
  1208. const g = ump3.get(f) || function () {
  1209. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1210. }
  1211. ump3.set(f, g);
  1212. g.km34 = 1;
  1213. h.onReadyStateChange_ = g;
  1214.  
  1215. }
  1216.  
  1217. if (typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  1218.  
  1219. const f = h.onReadyStateChangeEntryPoint_;
  1220. const g = ump3.get(f) || function () {
  1221. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1222. }
  1223. ump3.set(f, g);
  1224. g.km34 = 1;
  1225. h.onReadyStateChangeEntryPoint_ = g;
  1226.  
  1227. }
  1228.  
  1229.  
  1230. if (typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  1231.  
  1232. const f = h.readyStateChangeHandler_;
  1233. const g = ump3.get(f) || function (a) {
  1234. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1235. }
  1236. ump3.set(f, g);
  1237. g.km34 = 1;
  1238. h.readyStateChangeHandler_ = g;
  1239.  
  1240. }
  1241.  
  1242.  
  1243.  
  1244.  
  1245. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  1246.  
  1247. const f = h.xmlHttpHandler_;
  1248. const g = ump3.get(f) || function (a) {
  1249. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1250. }
  1251. ump3.set(f, g);
  1252. g.km34 = 1;
  1253. h.xmlHttpHandler_ = g;
  1254.  
  1255. }
  1256.  
  1257.  
  1258. if (typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  1259.  
  1260. const f = h.executeCallbacks_; // overloaded
  1261. const g = ump3.get(f) || function (a) {
  1262. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1263. }
  1264. ump3.set(f, g);
  1265. g.km34 = 1;
  1266. h.executeCallbacks_ = g;
  1267.  
  1268. }
  1269.  
  1270.  
  1271.  
  1272. if (typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  1273.  
  1274. const f = h.handleInvalidationData_;
  1275. const g = ump3.get(f) || function (a, b) {
  1276. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1277. }
  1278. ump3.set(f, g);
  1279. g.km34 = 1;
  1280. h.handleInvalidationData_ = g;
  1281.  
  1282. }
  1283.  
  1284. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  1285.  
  1286. const f = h.onInput_;
  1287. const g = ump3.get(f) || function () {
  1288. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1289. }
  1290. ump3.set(f, g);
  1291. g.km34 = 1;
  1292. h.onInput_ = g;
  1293.  
  1294. }
  1295.  
  1296.  
  1297. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  1298.  
  1299. const f = h.trigger_;
  1300. const g = ump3.get(f) || function (a) {
  1301. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1302. }
  1303. ump3.set(f, g);
  1304. g.km34 = 1;
  1305. h.trigger_ = g;
  1306.  
  1307. }
  1308.  
  1309.  
  1310. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  1311.  
  1312. const f = h.requestData_;
  1313. const g = ump3.get(f) || function (a) {
  1314. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1315. }
  1316. ump3.set(f, g);
  1317. g.km34 = 1;
  1318. h.requestData_ = g;
  1319.  
  1320. }
  1321.  
  1322. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  1323.  
  1324. const f = h.onLoadReloadContinuation_;
  1325. const g = ump3.get(f) || function (a, b) {
  1326. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1327. }
  1328. ump3.set(f, g);
  1329. g.km34 = 1;
  1330. h.onLoadReloadContinuation_ = g;
  1331.  
  1332. }
  1333.  
  1334.  
  1335.  
  1336. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  1337.  
  1338. const f = h.onLoadIncrementalContinuation_;
  1339. const g = ump3.get(f) || function (a, b) {
  1340. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1341. }
  1342. ump3.set(f, g);
  1343. g.km34 = 1;
  1344. h.onLoadIncrementalContinuation_ = g;
  1345.  
  1346. }
  1347.  
  1348. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  1349.  
  1350. const f = h.onLoadSeekContinuation_;
  1351. const g = ump3.get(f) || function (a, b) {
  1352. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1353. }
  1354. ump3.set(f, g);
  1355. g.km34 = 1;
  1356. h.onLoadSeekContinuation_ = g;
  1357.  
  1358. }
  1359. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  1360.  
  1361. const f = h.onLoadReplayContinuation_;
  1362. const g = ump3.get(f) || function (a, b) {
  1363. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1364. }
  1365. ump3.set(f, g);
  1366. g.km34 = 1;
  1367. h.onLoadReplayContinuation_ = g;
  1368.  
  1369. }
  1370. if (typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  1371.  
  1372. const f = h.onNavigate_;
  1373. const g = ump3.get(f) || function (a) {
  1374. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1375. }
  1376. ump3.set(f, g);
  1377. g.km34 = 1;
  1378. h.onNavigate_ = g;
  1379.  
  1380. }
  1381.  
  1382. /*
  1383. if(typeof h.deferRenderStamperBinding_ ==='function' && !(h.deferRenderStamperBinding_.km34)){
  1384.  
  1385. const f = h.deferRenderStamperBinding_;
  1386. const g = function(){
  1387. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1388. }
  1389. g.km34 = 1;
  1390. h.deferRenderStamperBinding_ = g;
  1391.  
  1392. }
  1393. */
  1394.  
  1395.  
  1396.  
  1397. if (typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  1398.  
  1399. const f = h.ytRendererBehaviorDataObserver_;
  1400. const g = ump3.get(f) || function () {
  1401. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1402. }
  1403. ump3.set(f, g);
  1404. g.km34 = 1;
  1405. h.ytRendererBehaviorDataObserver_ = g;
  1406.  
  1407. }
  1408.  
  1409. if (typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  1410.  
  1411. const f = h.ytRendererBehaviorTargetIdObserver_;
  1412. const g = ump3.get(f) || function () {
  1413. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1414. }
  1415. ump3.set(f, g);
  1416. g.km34 = 1;
  1417. h.ytRendererBehaviorTargetIdObserver_ = g;
  1418.  
  1419. }
  1420.  
  1421. if (typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  1422.  
  1423. const f = h.unregisterRenderer_;
  1424. const g = ump3.get(f) || function (a) {
  1425. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1426. }
  1427. ump3.set(f, g);
  1428. g.km34 = 1;
  1429. h.unregisterRenderer_ = g;
  1430.  
  1431. }
  1432.  
  1433.  
  1434.  
  1435. if (typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  1436.  
  1437. const f = h.textChanged_;
  1438. const g = ump3.get(f) || function (a) {
  1439. if (void 0 !== this.isAttached) {
  1440. const hostElement = this.hostElement;
  1441. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  1442. return;
  1443. }
  1444. }
  1445. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1446. }
  1447. ump3.set(f, g);
  1448. g.km34 = 1;
  1449. h.textChanged_ = g;
  1450.  
  1451. }
  1452.  
  1453.  
  1454.  
  1455.  
  1456. /*
  1457. if(typeof h.stampDomArray_ ==='function' && !(h.stampDomArray_.km34)){
  1458.  
  1459. if( h.stampDomArray_.length === 6){
  1460.  
  1461. const f = h.stampDomArray_;
  1462. const g = function(a,b,c,d,e,h){
  1463. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1464. }
  1465. g.km34 = 1;
  1466. h.stampDomArray_ = g;
  1467.  
  1468. }else{
  1469.  
  1470.  
  1471.  
  1472. const f = h.stampDomArray_;
  1473. const g = function(){
  1474. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1475. }
  1476. g.km34 = 1;
  1477. h.stampDomArray_ = g;
  1478. }
  1479.  
  1480.  
  1481. }
  1482. */
  1483.  
  1484. /*
  1485. if(typeof h.stampDomArraySplices_ ==='function' && !(h.stampDomArraySplices_.km34)){
  1486.  
  1487. if(h.stampDomArraySplices_.length === 3){
  1488.  
  1489.  
  1490.  
  1491. const f = h.stampDomArraySplices_;
  1492. const g = function(a,b,c){
  1493. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1494. }
  1495. g.km34 = 1;
  1496. h.stampDomArraySplices_ = g;
  1497.  
  1498.  
  1499. }else{
  1500.  
  1501.  
  1502.  
  1503. const f = h.stampDomArraySplices_;
  1504. const g = function(){
  1505. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1506. }
  1507. g.km34 = 1;
  1508. h.stampDomArraySplices_ = g;
  1509.  
  1510.  
  1511. }
  1512.  
  1513. }
  1514. */
  1515.  
  1516.  
  1517.  
  1518.  
  1519. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  1520. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  1521. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  1522. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  1523. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  1524. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  1525.  
  1526.  
  1527.  
  1528. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  1529.  
  1530. const f = h.searchChanged_;
  1531. const g = ump3.get(f) || function () {
  1532. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1533. }
  1534. ump3.set(f, g);
  1535. g.km34 = 1;
  1536. h.searchChanged_ = g;
  1537.  
  1538. }
  1539.  
  1540. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  1541.  
  1542. const f = h.skinToneChanged_;
  1543. const g = ump3.get(f) || function (a) {
  1544. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1545. }
  1546. ump3.set(f, g);
  1547. g.km34 = 1;
  1548. h.skinToneChanged_ = g;
  1549.  
  1550. }
  1551.  
  1552. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  1553.  
  1554. const f = h.onEmojiHover_;
  1555. const g = ump3.get(f) || function (a) {
  1556. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1557. }
  1558. ump3.set(f, g);
  1559. g.km34 = 1;
  1560. h.onEmojiHover_ = g;
  1561.  
  1562. }
  1563.  
  1564. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  1565.  
  1566. const f = h.onSelectCategory_;
  1567. const g = ump3.get(f) || function (a) {
  1568. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1569. }
  1570. ump3.set(f, g);
  1571. g.km34 = 1;
  1572. h.onSelectCategory_ = g;
  1573.  
  1574. }
  1575.  
  1576. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  1577.  
  1578. const f = h.onShowEmojiVariantSelector;
  1579. const g = ump3.get(f) || function (a) {
  1580. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1581. }
  1582. ump3.set(f, g);
  1583. g.km34 = 1;
  1584. h.onShowEmojiVariantSelector = g;
  1585.  
  1586. }
  1587.  
  1588. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  1589.  
  1590. const f = h.updateCategoriesAndPlaceholder_;
  1591. const g = ump3.get(f) || function () {
  1592. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1593. }
  1594. ump3.set(f, g);
  1595. g.km34 = 1;
  1596. h.updateCategoriesAndPlaceholder_ = g;
  1597.  
  1598. }
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  1605.  
  1606. const f = h.watchPageActiveChanged_;
  1607. const g = ump3.get(f) || function () {
  1608. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1609. }
  1610. ump3.set(f, g);
  1611. g.km34 = 1;
  1612. h.watchPageActiveChanged_ = g;
  1613.  
  1614. }
  1615.  
  1616.  
  1617. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  1618.  
  1619. const f = h.activate_;
  1620. const g = ump3.get(f) || function () {
  1621. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1622. }
  1623. ump3.set(f, g);
  1624. g.km34 = 1;
  1625. h.activate_ = g;
  1626.  
  1627. }
  1628. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  1629.  
  1630. const f = h.onYtPlaylistDataUpdated_;
  1631. const g = ump3.get(f) || function () {
  1632. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1633. }
  1634. ump3.set(f, g);
  1635. g.km34 = 1;
  1636. h.onYtPlaylistDataUpdated_ = g;
  1637.  
  1638. }
  1639.  
  1640. FIX_stampDomArray_stableList && fixStampDomArrayStableList(h);
  1641. ENABLE_weakenStampReferences && weakenStampReferences(h);
  1642.  
  1643.  
  1644.  
  1645. /// -----------------------
  1646.  
  1647.  
  1648. // const isMainRenderer = (h) => {
  1649. // if (h.is && h.$ && h.__dataEnabled && h.__dataReady && h.__shady && h.__templateInfo && h.root && h.hostElement) {
  1650. // const q = (h.parentComponent ? 1 : 0) | (h.ytComponentBehavior ? 2 : 0);
  1651. // if (q === 3) {
  1652. // // chat renderer
  1653. // if (h.is.endsWith('-renderer')) {
  1654. // return true;
  1655. // }
  1656. // } else if (q === 0) {
  1657. // // custom lyrics engagement panel
  1658. // if (h.is.endsWith('-renderer')) {
  1659. // return true;
  1660. // }
  1661. // } else if (q === 1) {
  1662. // // input renderer
  1663. // if (h.is.endsWith('-renderer')) {
  1664. // return true;
  1665. // }
  1666. // }
  1667. // }
  1668. // return false;
  1669. // }
  1670.  
  1671. // const skipRenderer = (h) => {
  1672. // return (h.is === 'yt-live-chat-renderer') ||
  1673. // (h.is === 'yt-live-chat-item-list-renderer') ||
  1674. // (h.is === 'yt-live-chat-text-input-field-renderer') ||
  1675. // (h.is === 'yt-live-chat-message-buy-flow-renderer') ||
  1676. // false;
  1677. // }
  1678.  
  1679.  
  1680. /*
  1681. if (typeof h.rendererStamperApplyChangeRecord_ === 'function' && !(h.rendererStamperApplyChangeRecord_.km31) && h.rendererStamperApplyChangeRecord_.length === 3) {
  1682.  
  1683. const f = h.rendererStamperApplyChangeRecord_;
  1684. h.rendererStamperApplyChangeRecord31_ = f;
  1685. const g = ump3.get(f) || function (a, b, c) {
  1686. if (isMainRenderer(this) || (this.updateChildVisibilityProperties && !this.markDirty)) {
  1687. let y = false;
  1688. if (!this.markDirty) {
  1689. // yt-live-chat-dialog-renderer
  1690. // ytd-engagement-panel-section-list-renderer
  1691. y = true;
  1692. } else if (!this.visibilityObserverForChild_ && !!this.getVisibilityObserverForChild) {
  1693. const lobs = this.localVisibilityObserver_;
  1694. if (this.isRenderer_ === true) {
  1695. if (lobs) {
  1696. if (lobs.observer && lobs.isConnected === true) {
  1697. // if (lobs.observer && lobs.isConnected === true && lobs.pauseObservingUntilReconnect === false && lobs.handlers && lobs.handlers.size > 0) {
  1698. // if ((this.__data || 0).isEmpty === false) {
  1699. // // by pass
  1700. // } else if (this.is === 'yt-live-chat-renderer') {
  1701. // y = true;
  1702. // }
  1703. if (this.is === 'yt-live-chat-renderer') {
  1704. y = true;
  1705. }
  1706. } else {
  1707. y = true;
  1708. }
  1709. } else if (lobs === null) {
  1710. y = true;
  1711. } else {
  1712. console.log('renderer-check-failure 01', this.is)
  1713. }
  1714. } else {
  1715. console.log('renderer-check-failure 02', this.is)
  1716. }
  1717. }
  1718. if (y) {
  1719. return f.apply(this, arguments);
  1720. }
  1721. }
  1722. let c2 = c;
  1723. if (c && typeof c === 'object') {
  1724. c2 = {};
  1725. for (const entry of Object.entries(c)) {
  1726. const [key, value] = entry;
  1727. let choice = 0;
  1728. if (value && typeof value === 'object') {
  1729. if (key === 'base' && value.length >= 1) choice = 1;
  1730. else if (key === 'value' && value.indexSplices && value.indexSplices.length >= 1) choice = 2;
  1731. }
  1732. if (choice === 1) c2[key] = value.slice(0);
  1733. else if (choice === 2) c2[key] = Object.assign({}, value, { indexSplices: value.indexSplices.map(splice=>{
  1734.  
  1735. if (!splice || typeof splice !== 'object') return splice;
  1736. if (splice.removed && splice.removed.length >= 1) splice.removed = splice.removed.slice(0);
  1737. if (splice.object && splice.object.length >= 1) splice.object = splice.object.slice(0);
  1738.  
  1739. return splice;
  1740.  
  1741. }) });
  1742. else c2[key] = value;
  1743. }
  1744. }
  1745. const acceptable = () => {
  1746. return this.isAttached && this.data && this.__dataEnabled
  1747. }
  1748. // sequence on the same proto
  1749. this[qm47] = (this[qm47] || Promise.resolve()).then(() => acceptable() && this.rendererStamperApplyChangeRecord31_(a, b, c2)).catch(console.log);
  1750. }
  1751. ump3.set(f, g);
  1752. g.km31 = 1;
  1753. h.rendererStamperApplyChangeRecord_ = g;
  1754.  
  1755.  
  1756. }
  1757. */
  1758.  
  1759.  
  1760.  
  1761.  
  1762. /*
  1763. if (typeof h.rendererStamperObserver_ === 'function' && !(h.rendererStamperObserver_.km34)) {
  1764.  
  1765. const f = h.rendererStamperObserver_;
  1766. const g = ump3.get(f) || function (a, b, c) {
  1767. if (isMainRenderer(this)) {
  1768. return f.apply(this, arguments);
  1769. }
  1770. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1771. }
  1772. ump3.set(f, g);
  1773. g.km34 = 1;
  1774. h.rendererStamperObserver_ = g;
  1775.  
  1776. }
  1777.  
  1778.  
  1779. if (typeof h.rendererStamperApplyChangeRecord_ === 'function' && !(h.rendererStamperApplyChangeRecord_.km34)) {
  1780.  
  1781. const f = h.rendererStamperApplyChangeRecord_;
  1782. const g = ump3.get(f) || function () {
  1783. if (isMainRenderer(this)) {
  1784. return f.apply(this, arguments);
  1785. }
  1786. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1787. }
  1788. ump3.set(f, g);
  1789. g.km34 = 1;
  1790. h.rendererStamperApplyChangeRecord_ = g;
  1791.  
  1792. }
  1793.  
  1794.  
  1795.  
  1796. if (typeof h.flushRenderStamperComponentBindings_ === 'function' && !(h.flushRenderStamperComponentBindings_.km34)) {
  1797.  
  1798. const f = h.flushRenderStamperComponentBindings_;
  1799. const g = ump3.get(f) || function () {
  1800. if (isMainRenderer(this)) {
  1801. return f.apply(this, arguments);
  1802. }
  1803. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1804. }
  1805. ump3.set(f, g);
  1806. g.km34 = 1;
  1807. h.flushRenderStamperComponentBindings_ = g;
  1808.  
  1809. }
  1810.  
  1811.  
  1812. if (typeof h.forwardRendererStamperChanges_ === 'function' && !(h.forwardRendererStamperChanges_.km34)) {
  1813.  
  1814. const f = h.forwardRendererStamperChanges_;
  1815. const g = ump3.get(f) || function () {
  1816. if (isMainRenderer(this)) {
  1817. return f.apply(this, arguments);
  1818. }
  1819. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1820. }
  1821. ump3.set(f, g);
  1822. g.km34 = 1;
  1823. h.forwardRendererStamperChanges_ = g;
  1824.  
  1825. }
  1826. */
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832. // console.log(123)
  1833.  
  1834. // return;
  1835.  
  1836.  
  1837. /*
  1838.  
  1839. // buggy for page swtiching
  1840.  
  1841. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km31)) {
  1842.  
  1843.  
  1844.  
  1845.  
  1846. const f = h.dataChanged_;
  1847. h.dataChanged31_ = f;
  1848. const g = ump3.get(f) || function (...args) {
  1849.  
  1850. if (isMainRenderer(this)) {
  1851. return f.apply(this, arguments);
  1852. }
  1853.  
  1854. // sequence on the same proto
  1855. this[qm47] = (this[qm47] || Promise.resolve()).then(() => this.dataChanged31_(...args)).catch(console.log);
  1856. }
  1857. ump3.set(f, g);
  1858. g.km31 = 1;
  1859. h.dataChanged_ = g;
  1860.  
  1861.  
  1862. }
  1863. */
  1864.  
  1865.  
  1866. /*
  1867.  
  1868. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km34)) {
  1869.  
  1870. const f = h.dataChanged_;
  1871. const g = ump3.get(f) || function () {
  1872. if (isMainRenderer(this)) {
  1873. return f.apply(this, arguments);
  1874. }
  1875. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1876. }
  1877. ump3.set(f, g);
  1878. g.km34 = 1;
  1879. h.dataChanged_ = g;
  1880.  
  1881. }
  1882. */
  1883.  
  1884.  
  1885.  
  1886. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  1887.  
  1888. const f = h.tryRenderChunk_;
  1889. const g = ump3.get(f) || function () {
  1890. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1891. }
  1892. ump3.set(f, g);
  1893. g.km34 = 1;
  1894. h.tryRenderChunk_ = g;
  1895.  
  1896. }
  1897.  
  1898.  
  1899. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  1900.  
  1901. const f = h.renderChunk_;
  1902. const g = ump3.get(f) || function () {
  1903. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1904. }
  1905. ump3.set(f, g);
  1906. g.km34 = 1;
  1907. h.renderChunk_ = g;
  1908.  
  1909. }
  1910.  
  1911. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  1912.  
  1913. const f = h.deepLazyListObserver_;
  1914. const g = ump3.get(f) || function () {
  1915. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1916. }
  1917. ump3.set(f, g);
  1918. g.km34 = 1;
  1919. h.deepLazyListObserver_ = g;
  1920.  
  1921. }
  1922.  
  1923.  
  1924. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  1925.  
  1926. const f = h.onItemsUpdated_;
  1927. const g = ump3.get(f) || function () {
  1928. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1929. }
  1930. ump3.set(f, g);
  1931. g.km34 = 1;
  1932. h.onItemsUpdated_ = g;
  1933.  
  1934. }
  1935.  
  1936. /*
  1937. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1938. if (typeof h.updateChangeRecord_ === 'function' && !(h.updateChangeRecord_.km34)) {
  1939.  
  1940. const f = h.updateChangeRecord_;
  1941. const g = ump3.get(f) || function () {
  1942. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1943. }
  1944. ump3.set(f, g);
  1945. g.km34 = 1;
  1946. h.updateChangeRecord_ = g;
  1947.  
  1948. }
  1949. */
  1950.  
  1951.  
  1952. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  1953.  
  1954. const f = h.requestRenderChunk_;
  1955. const g = ump3.get(f) || function () {
  1956. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1957. }
  1958. ump3.set(f, g);
  1959. g.km34 = 1;
  1960. h.requestRenderChunk_ = g;
  1961.  
  1962. }
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968. return;
  1969.  
  1970.  
  1971.  
  1972. /*
  1973. if (typeof h.cancelPendingTasks_ === 'function' && !(h.cancelPendingTasks_.km34)) {
  1974.  
  1975. const f = h.cancelPendingTasks_;
  1976. const g = ump3.get(f) || function () {
  1977. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1978. }
  1979. ump3.set(f, g);
  1980. g.km34 = 1;
  1981. h.cancelPendingTasks_ = g;
  1982.  
  1983. }
  1984.  
  1985.  
  1986. if (typeof h.fillRange_ === 'function' && !(h.fillRange_.km34)) {
  1987.  
  1988. const f = h.fillRange_;
  1989. const g = ump3.get(f) || function () {
  1990. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1991. }
  1992. ump3.set(f, g);
  1993. g.km34 = 1;
  1994. h.fillRange_ = g;
  1995.  
  1996. }
  1997. */
  1998.  
  1999.  
  2000.  
  2001.  
  2002. if (typeof h.addTextNodes_ === 'function' && !(h.addTextNodes_.km34)) {
  2003.  
  2004. const f = h.addTextNodes_;
  2005. const g = function () {
  2006. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  2007. }
  2008. g.km34 = 1;
  2009. h.addTextNodes_ = g;
  2010.  
  2011. }
  2012.  
  2013.  
  2014.  
  2015.  
  2016. if (typeof h.updateText_ === 'function' && !(h.updateText_.km34)) {
  2017.  
  2018. const f = h.updateText_;
  2019. const g = function () {
  2020. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  2021. }
  2022. g.km34 = 1;
  2023. h.updateText_ = g;
  2024.  
  2025. }
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031. if (typeof h.stampTypeChanged_ === 'function' && !(h.stampTypeChanged_.km34)) {
  2032.  
  2033. const f = h.stampTypeChanged_;
  2034. const g = function () {
  2035. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  2036. }
  2037. g.km34 = 1;
  2038. h.stampTypeChanged_ = g;
  2039.  
  2040. }
  2041.  
  2042.  
  2043.  
  2044.  
  2045. // console.log(166)
  2046.  
  2047.  
  2048.  
  2049.  
  2050. }
  2051.  
  2052. const keyStConnectedCallback = Symbol(); // avoid copying the value
  2053.  
  2054. const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  2055. const cmf = new WeakMap();
  2056. const dmf = new WeakMap();
  2057.  
  2058. const gvGenerator = (nv) => {
  2059. return function () {
  2060. const cnt = insp(this);
  2061. const hostElement = cnt.hostElement || 0;
  2062. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  2063. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  2064. if (p && (!dollar && !this.is)) {
  2065. const nodeName = hostElement.nodeName;
  2066. if (typeof nodeName !== 'string') {
  2067. // just in case
  2068. } else if (nodeName.startsWith("DOM-")) {
  2069. // dom-if, dom-repeat, etc
  2070. } else {
  2071. // yt element - new model, yt-xxxx, anixxxxxx
  2072. p = false;
  2073. }
  2074. }
  2075. if (p) {
  2076. if (typeof cnt.markDirty === 'function') {
  2077. // the yt element might call markDirty (occasionally)
  2078. p = false;
  2079. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  2080. // see https://github.com/cyfung1031/userscript-supports/issues/20
  2081. p = false;
  2082. }
  2083. }
  2084. if (p) {
  2085.  
  2086. // << dom-repeat & dom-if >>
  2087.  
  2088. // sequence on the same instance
  2089. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  2090. } else {
  2091. nv.apply(this, arguments);
  2092. }
  2093. };
  2094. }
  2095.  
  2096. const setupWeakRef = (h) => {
  2097.  
  2098.  
  2099. if (WEAK_REF_BINDING && !h.kz62 && setup$ && setupD && setupDataHost && (h.is || h.__dataHost)) {
  2100.  
  2101. let skip = false;
  2102. // if (h.is && typeof h.is === 'string' && h.is.length > 15 && h.is.length < 30) {
  2103. // if (h.is.includes('yt-') && !h.$ && h.is.length !== 20 && h.is.length !== 21 && h.is.length !== 22) {
  2104. // skip = true;
  2105. // // return;
  2106. // }
  2107. // }
  2108.  
  2109. h.kz62 = 1;
  2110.  
  2111. //
  2112.  
  2113. setup$(h);
  2114. const hostElement = h.hostElement;
  2115.  
  2116. if (hostElement !== h) {
  2117.  
  2118. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  2119. setupD(h, s);
  2120.  
  2121. }
  2122.  
  2123. const dh = h.__dataHost;
  2124.  
  2125. setupDataHost(dh, skip)
  2126. }
  2127.  
  2128.  
  2129.  
  2130.  
  2131. if (hostElement) {
  2132.  
  2133. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  2134. setupD(hostElement, s);
  2135.  
  2136. }
  2137.  
  2138. const dh = hostElement.__dataHost;
  2139.  
  2140. setupDataHost(dh, skip)
  2141.  
  2142.  
  2143.  
  2144.  
  2145. aDelay().then(() => {
  2146. setupD(hostElement, '__CE_shadowRoot');
  2147. });
  2148.  
  2149.  
  2150. }
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156. }
  2157.  
  2158. }
  2159.  
  2160.  
  2161. let nativeHTMLElement = window.HTMLElement;
  2162.  
  2163. try {
  2164.  
  2165. const q = document.createElement('template');
  2166. q.innerHTML = '<ytz-null361></ytz-null361>';
  2167. nativeHTMLElement = q.content.firstChild.constructor
  2168.  
  2169. } catch (e) { }
  2170.  
  2171. if (!nativeHTMLElement.prototype.connectedCallback) {
  2172. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  2173. nativeHTMLElement.prototype.connectedCallback = function () {
  2174. let r;
  2175. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  2176.  
  2177. if (WEAK_REF_BINDING && (this instanceof Node) && (this.is || this.__dataHost)) {
  2178. setupWeakRef(this)
  2179. // setupWeakRef(this.__dataHost)
  2180. }
  2181. return r;
  2182. }
  2183. }
  2184.  
  2185. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  2186. get() {
  2187. const f = this[keyStConnectedCallback];
  2188. if (this.is) {
  2189. setupDiscreteTasks(this, true);
  2190. if (f) this.ky36 = 1;
  2191. }
  2192. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  2193. setupWeakRef(this)
  2194. }
  2195. return f;
  2196. },
  2197. set(nv) {
  2198. let gv;
  2199. if (typeof nv === 'function') {
  2200.  
  2201. gv = cmf.get(nv) || gvGenerator(nv);
  2202. if (gv !== nv) {
  2203. cmf.set(nv, gv);
  2204. cmf.set(gv, gv);
  2205. dmf.set(gv, nv);
  2206. }
  2207.  
  2208. } else {
  2209. gv = nv;
  2210. }
  2211. this[keyStConnectedCallback] = gv; // proto or object
  2212. if (this.is) {
  2213. setupDiscreteTasks(this);
  2214. }
  2215. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  2216. setupWeakRef(this)
  2217. }
  2218. return true;
  2219. },
  2220. enumerable: false,
  2221. configurable: true
  2222.  
  2223. });
  2224.  
  2225. const pLoad = new Promise(resolve => {
  2226. if (document.readyState !== 'loading') {
  2227. resolve();
  2228. } else {
  2229. window.addEventListener("DOMContentLoaded", resolve, false);
  2230. }
  2231. });
  2232. pLoad.then(() => {
  2233.  
  2234. let nonce = document.querySelector('style[nonce]');
  2235. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2236. const st = document.createElement('style');
  2237. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2238. st.textContent = "none-element-k47{order:0}";
  2239. st.addEventListener('load', () => {
  2240. pf31.resolve();
  2241. p59 = 1;
  2242. }, false);
  2243. document.body.appendChild(st);
  2244.  
  2245.  
  2246. // console.debug('90002', location.pathname)
  2247. // console.log(90000, location.pathname)
  2248.  
  2249. });
  2250.  
  2251. const prepareLogs = [];
  2252.  
  2253. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  2254.  
  2255. let winError00 = window.onerror;
  2256.  
  2257. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  2258.  
  2259. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  2260.  
  2261. ; FIX_Iframe_NULL_SRC && (() => {
  2262.  
  2263. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  2264. const lcOpt = { sensitivity: 'base' };
  2265. document.createElement24 = document.createElement;
  2266. document.createElement = function (t) {
  2267. if (typeof t === 'string' && t.length === 6) {
  2268. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  2269. const p = this.createElement24(t);
  2270. try {
  2271. const stack = new Error().stack;
  2272. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  2273. if (!isSearchbox) {
  2274. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  2275. }
  2276. } catch (e) { }
  2277. return p;
  2278. }
  2279. }
  2280. return this.createElement24.apply(this, arguments);
  2281. };
  2282.  
  2283. })();
  2284.  
  2285. ; fix_error_many_stack_state === 1 && (() => {
  2286.  
  2287.  
  2288. let p1 = winError00;
  2289.  
  2290. let stackNeedleDetails = null;
  2291.  
  2292. Object.defineProperty(Object.prototype, 'matchAll', {
  2293. get() {
  2294. stackNeedleDetails = this;
  2295. return true;
  2296. },
  2297. enumerable: true,
  2298. configurable: true
  2299. });
  2300.  
  2301. try {
  2302. JSON.parse("{}");
  2303. } catch (e) {
  2304. console.warn(e)
  2305. fix_error_many_stack_state = 0;
  2306. }
  2307.  
  2308. delete Object.prototype['matchAll'];
  2309.  
  2310. let p2 = window.onerror;
  2311.  
  2312. window.onerror = p1;
  2313.  
  2314. if (fix_error_many_stack_state === 0) return;
  2315.  
  2316. if (stackNeedleDetails) {
  2317. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  2318. stackNeedleDetails.matchAll = true;
  2319. }
  2320.  
  2321. if (p1 === p2) return (fix_error_many_stack_state = 0);
  2322.  
  2323. // p1!==p2
  2324. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  2325.  
  2326. })();
  2327.  
  2328. ; fix_error_many_stack_state === 2 && (() => {
  2329.  
  2330.  
  2331. let p1 = winError00;
  2332.  
  2333. let objectPrune = null;
  2334. let stackNeedleDetails = null;
  2335.  
  2336. Object.defineProperty(Function.prototype, 'findOwner', {
  2337. get() {
  2338. objectPrune = this;
  2339. return this._findOwner;
  2340. },
  2341. set(nv) {
  2342. this._findOwner = nv;
  2343. return true;
  2344. },
  2345. enumerable: true,
  2346. configurable: true
  2347. });
  2348.  
  2349. Object.defineProperty(Object.prototype, 'matchAll', {
  2350. get() {
  2351. stackNeedleDetails = this;
  2352. return true;
  2353. },
  2354. enumerable: true,
  2355. configurable: true
  2356. });
  2357.  
  2358. try {
  2359. JSON.parse("{}");
  2360. } catch (e) {
  2361. console.warn(e)
  2362. fix_error_many_stack_state = 0;
  2363. }
  2364.  
  2365. delete Function.prototype['findOwner'];
  2366. delete Object.prototype['matchAll'];
  2367.  
  2368. let p2 = window.onerror;
  2369.  
  2370. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  2371.  
  2372. if (fix_error_many_stack_state == 0) return;
  2373.  
  2374. // the following will only execute when Brave's scriptlets.js is executed.
  2375.  
  2376. prepareLogs.push("fix_error_many_stack_state NB")
  2377.  
  2378. if (stackNeedleDetails) {
  2379. stackNeedleDetails.pattern = null;
  2380. stackNeedleDetails.re = null;
  2381. stackNeedleDetails.expect = null;
  2382. stackNeedleDetails.matchAll = true;
  2383. }
  2384.  
  2385. if (objectPrune) {
  2386. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  2387. delete objectPrune._findOwner;
  2388. }
  2389.  
  2390. fix_error_many_stack_state = 3;
  2391. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  2392. JSON.parse.objectPrune = objectPrune;
  2393.  
  2394. })();
  2395.  
  2396. ; fix_error_many_stack_state === 3 && (() => {
  2397.  
  2398.  
  2399. let p1 = winError00;
  2400.  
  2401. try {
  2402. JSON.parse("{}");
  2403. } catch (e) {
  2404. console.warn(e)
  2405. fix_error_many_stack_state = 0;
  2406. }
  2407.  
  2408. let p2 = window.onerror;
  2409.  
  2410. if (p1 === p2) return;
  2411.  
  2412. window.onerror = p1;
  2413.  
  2414. if (fix_error_many_stack_state === 0) return;
  2415.  
  2416. fix_error_many_stack_state = 4; // p1 != p2
  2417.  
  2418.  
  2419. })();
  2420.  
  2421. fix_error_many_stack_state === 4 && (() => {
  2422.  
  2423. // the following will only execute when Brave's scriptlets.js is executed.
  2424.  
  2425. prepareLogs.push("fix_error_many_stack_state AB")
  2426.  
  2427. JSON.parseProxy = JSON.parse;
  2428.  
  2429. JSON.parse = ((parse) => {
  2430.  
  2431. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  2432. return function (text, reviver) {
  2433. const onerror = window.onerror;
  2434. window.onerror = null;
  2435. let r;
  2436. try {
  2437. r = parse(...arguments);
  2438. } catch (e) {
  2439. r = e;
  2440. }
  2441. window.onerror = onerror;
  2442. if (r instanceof Error) {
  2443. throw r;
  2444. }
  2445. return r;
  2446. }
  2447.  
  2448. })(JSON.parse);
  2449.  
  2450.  
  2451. })();
  2452.  
  2453.  
  2454.  
  2455. // ================================================ 0.4.5 ================================================
  2456.  
  2457.  
  2458. // ; (() => {
  2459.  
  2460. // if (FIX_error_many_stack && self instanceof Window) {
  2461. // // infinite stack due to matchesStackTrace inside objectPrune of AdsBlock
  2462.  
  2463. // const pdK = Object.getOwnPropertyDescriptor(window, 'onerror');
  2464. // if (!pdK || (pdK.get && pdK.configurable)) {
  2465.  
  2466. // } else {
  2467. // return;
  2468. // }
  2469.  
  2470. // let unsupportErrorFix = false;
  2471.  
  2472. // let firstHook = true;
  2473. // let busy33 = false;
  2474.  
  2475. // let state = 0;
  2476.  
  2477. // if (pdK) {
  2478. // delete window['onerror'];
  2479. // }
  2480.  
  2481. // const pd = {
  2482. // get() {
  2483. // const stack = (new Error()).stack;
  2484. // // targetStack = stack;
  2485. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  2486. // state = isGetExceptionToken ? 1 : 0;
  2487. // delete Window.prototype['onerror'];
  2488. // let r = pdK ? pdK.get.call(this) : this.onerror;
  2489. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2490. // // console.log('onerror get', r)
  2491. // return r;
  2492. // },
  2493. // set(nv) {
  2494. // const stack = (new Error()).stack;
  2495. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  2496. // state = state === 1 && isGetExceptionToken ? 2 : 0;
  2497. // /** @type {string?} */
  2498. // let sToken = null;
  2499. // if (unsupportErrorFix || busy33) {
  2500.  
  2501. // } else if (typeof nv === 'function' && state === 2) {
  2502. // if (firstHook) {
  2503. // firstHook = false;
  2504. // console.groupCollapsed('Infinite onerror Bug Found');
  2505. // console.log(location.href);
  2506. // console.log(stack);
  2507. // console.log(nv);
  2508. // console.groupEnd();
  2509. // }
  2510. // let _token = null;
  2511. // busy33 = true;
  2512. // String.prototype.includes76 = String.prototype.includes;
  2513. // String.prototype.includes = function (token) {
  2514. // _token = token;
  2515. // return true;
  2516. // }
  2517. // nv('token');
  2518. // String.prototype.includes = String.prototype.includes76;
  2519. // sToken = _token;
  2520. // busy33 = false;
  2521. // if (typeof sToken !== 'string') {
  2522. // unsupportErrorFix = true;
  2523. // }
  2524. // }
  2525. // delete Window.prototype['onerror'];
  2526. // if (typeof sToken === 'string' && sToken.length > 1) {
  2527. // /** @type {string} */
  2528. // const token = sToken;
  2529. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>?} } */
  2530. // const currentOnerror = pdK ? pdK.get.call(this) : this.onerror;
  2531.  
  2532. // const now = Date.now();
  2533. // const tokenEntry = {
  2534. // token,
  2535. // expired: now + FIX_error_many_stack_keepAliveDuration
  2536. // }
  2537. // /** @typedef {typeof tokenEntry} TokenEntry */
  2538.  
  2539. // /** @type {Set<TokenEntry>} */
  2540. // const errorTokens = currentOnerror.errorTokens;
  2541.  
  2542. // if (errorTokens) {
  2543. // if (errorTokens.size > FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than) {
  2544. // for (const entry of errorTokens) {
  2545. // if (entry.expired < now) {
  2546. // errorTokens.delete(entry);
  2547. // }
  2548. // }
  2549. // }
  2550. // errorTokens.add(tokenEntry)
  2551. // } else {
  2552. // /** @type {Set<TokenEntry>} */
  2553. // const errorTokens = new Set([tokenEntry]);
  2554. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>} } */
  2555. // const newOnerror = ((oe) => {
  2556. // const r = function (msg, ...args) {
  2557. // if (typeof msg === 'string' && errorTokens.size > 0) {
  2558. // for (const entry of errorTokens) {
  2559. // if (msg.includes(entry.token)) return true;
  2560. // }
  2561. // }
  2562. // if (typeof oe === 'function') {
  2563. // return oe.apply(this, arguments);
  2564. // }
  2565. // };
  2566. // r.errorTokens = errorTokens;
  2567. // return r;
  2568. // })(currentOnerror);
  2569.  
  2570. // if (pdK && pdK.set) pdK.set.call(this, newOnerror);
  2571. // else this.onerror = newOnerror;
  2572. // }
  2573. // } else {
  2574. // if (pdK && pdK.set) pdK.set.call(this, nv);
  2575. // else this.onerror = nv;
  2576. // }
  2577. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2578.  
  2579. // // console.log('onerror set', nv)
  2580. // return true;
  2581. // },
  2582. // enumerable: true,
  2583. // configurable: true
  2584. // }
  2585.  
  2586. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2587.  
  2588.  
  2589. // }
  2590.  
  2591.  
  2592. // })();
  2593.  
  2594.  
  2595.  
  2596. // ================================================ 0.4.5 ================================================
  2597.  
  2598.  
  2599. // << if FIX_yt_player >>
  2600.  
  2601. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  2602. const PERF_471489_ = true;
  2603. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  2604. // This script uses a much gentle way to tamer the JS engine instead.
  2605.  
  2606. // << end >>
  2607.  
  2608. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  2609.  
  2610.  
  2611.  
  2612. const nilFn = () => { };
  2613.  
  2614. let isMainWindow = false;
  2615. try {
  2616. isMainWindow = window.document === window.top.document
  2617. } catch (e) { }
  2618.  
  2619. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  2620.  
  2621. const onRegistryReady = (callback) => {
  2622. if (typeof customElements === 'undefined') {
  2623. if (!('__CE_registry' in document)) {
  2624. // https://github.com/webcomponents/polyfills/
  2625. Object.defineProperty(document, '__CE_registry', {
  2626. get() {
  2627. // return undefined
  2628. },
  2629. set(nv) {
  2630. if (typeof nv == 'object') {
  2631. delete this.__CE_registry;
  2632. this.__CE_registry = nv;
  2633. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2634. }
  2635. return true;
  2636. },
  2637. enumerable: false,
  2638. configurable: true
  2639. })
  2640. }
  2641. let eventHandler = (evt) => {
  2642. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2643. const f = callback;
  2644. callback = null;
  2645. eventHandler = null;
  2646. f();
  2647. };
  2648. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2649. } else {
  2650. callback();
  2651. }
  2652. };
  2653.  
  2654.  
  2655. const assertor = (f) => f() || console.assert(false, f + "");
  2656.  
  2657. const fnIntegrity = (f, d) => {
  2658. if (!f || typeof f !== 'function') {
  2659. console.warn('f is not a function', f);
  2660. return;
  2661. }
  2662. let p = f + "", s = 0, j = -1, w = 0;
  2663. for (let i = 0, l = p.length; i < l; i++) {
  2664. const t = p[i];
  2665. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  2666. if (j < i - 1) w++;
  2667. j = i;
  2668. } else {
  2669. s++;
  2670. }
  2671. }
  2672. let itz = `${f.length}.${s}.${w}`;
  2673. if (!d) {
  2674. return itz;
  2675. } else {
  2676. return itz === d;
  2677. }
  2678. };
  2679.  
  2680. const getZq = (_yt_player) => {
  2681.  
  2682. const w = 'Zq';
  2683.  
  2684. let arr = [];
  2685.  
  2686. for (const [k, v] of Object.entries(_yt_player)) {
  2687.  
  2688. const p = typeof v === 'function' ? v.prototype : 0;
  2689. if (p
  2690. && typeof p.start === 'function' && p.start.length === 0
  2691. && typeof p.isActive === 'function' && p.isActive.length === 0
  2692. && typeof p.stop === 'function' && p.stop.length === 0
  2693. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  2694. && !p.send && !p.abort
  2695. && !p.sample && !p.initialize && !p.fail && !p.getName
  2696. // && !p.dispose && !p.isDisposed
  2697.  
  2698. ) {
  2699. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2700.  
  2701.  
  2702. }
  2703.  
  2704. }
  2705.  
  2706. if (arr.length === 0) {
  2707.  
  2708. console.warn(`Key does not exist. [${w}]`);
  2709. } else {
  2710.  
  2711. console.log(`[${w}]`, arr);
  2712. return arr[0];
  2713. }
  2714.  
  2715.  
  2716.  
  2717.  
  2718. }
  2719.  
  2720.  
  2721. const getVG = (_yt_player) => {
  2722. const w = 'VG';
  2723.  
  2724. let arr = [];
  2725.  
  2726. for (const [k, v] of Object.entries(_yt_player)) {
  2727.  
  2728. const p = typeof v === 'function' ? v.prototype : 0;
  2729. if (p
  2730. && typeof p.show === 'function' && p.show.length === 1
  2731. && typeof p.hide === 'function' && p.hide.length === 0
  2732. && typeof p.stop === 'function' && p.stop.length === 0) {
  2733.  
  2734. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2735.  
  2736. }
  2737.  
  2738. }
  2739.  
  2740.  
  2741. if (arr.length === 0) {
  2742.  
  2743. console.warn(`Key does not exist. [${w}]`);
  2744. } else {
  2745.  
  2746. console.log(`[${w}]`, arr);
  2747. return arr[0];
  2748. }
  2749.  
  2750.  
  2751.  
  2752. }
  2753.  
  2754.  
  2755. const getzo = (_yt_player) => {
  2756. const w = 'zo';
  2757.  
  2758. let arr = [];
  2759.  
  2760. for (const [k, v] of Object.entries(_yt_player)) {
  2761.  
  2762. if (
  2763. typeof v === 'function' && v.length === 3 && k.length < 3
  2764. && (v + "").includes("a.style[b]=c")
  2765. ) {
  2766.  
  2767. arr.push(k);
  2768.  
  2769. }
  2770.  
  2771. }
  2772.  
  2773.  
  2774. if (arr.length === 0) {
  2775.  
  2776. console.warn(`Key does not exist. [${w}]`);
  2777. } else {
  2778.  
  2779. console.log(`[${w}]`, arr);
  2780. return arr[0];
  2781. }
  2782.  
  2783. }
  2784.  
  2785. const addProtoToArr = (parent, key, arr) => {
  2786.  
  2787.  
  2788. let isChildProto = false;
  2789. for (const sr of arr) {
  2790. if (parent[key].prototype instanceof parent[sr]) {
  2791. isChildProto = true;
  2792. break;
  2793. }
  2794. }
  2795.  
  2796. if (isChildProto) return;
  2797.  
  2798. arr = arr.filter(sr => {
  2799. if (parent[sr].prototype instanceof parent[key]) {
  2800. return false;
  2801. }
  2802. return true;
  2803. });
  2804.  
  2805. arr.push(key);
  2806.  
  2807. return arr;
  2808.  
  2809.  
  2810. }
  2811.  
  2812. const getuG = (_yt_player) => {
  2813.  
  2814. const w = 'uG';
  2815.  
  2816. let arr = [];
  2817.  
  2818. for (const [k, v] of Object.entries(_yt_player)) {
  2819.  
  2820.  
  2821. const p = typeof v === 'function' ? v.prototype : 0;
  2822.  
  2823. if (p
  2824. && typeof p.createElement === 'function' && p.createElement.length === 2
  2825. && typeof p.detach === 'function' && p.detach.length === 0
  2826. && typeof p.update === 'function' && p.update.length === 1
  2827. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  2828. ) {
  2829.  
  2830. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2831.  
  2832. }
  2833.  
  2834. }
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840. if (arr.length === 0) {
  2841.  
  2842. console.warn(`Key does not exist. [${w}]`);
  2843. } else {
  2844.  
  2845. console.log(`[${w}]`, arr);
  2846. return arr[0];
  2847. }
  2848.  
  2849. }
  2850.  
  2851.  
  2852.  
  2853. // << if FIX_schedulerInstanceInstance_ >>
  2854.  
  2855. let idleFrom = Date.now() + 2700;
  2856. let slowMode = false;
  2857.  
  2858. let ytEvented = false;
  2859.  
  2860.  
  2861. const setupEvents = FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 ? () => {
  2862.  
  2863. document.addEventListener('yt-navigate', () => {
  2864.  
  2865. ytEvented = true;
  2866. slowMode = false;
  2867. idleFrom = Date.now() + 2700;
  2868.  
  2869. });
  2870. document.addEventListener('yt-navigate-start', () => {
  2871.  
  2872. ytEvented = true;
  2873. slowMode = false;
  2874. idleFrom = Date.now() + 2700;
  2875.  
  2876. });
  2877.  
  2878. document.addEventListener('yt-page-type-changed', () => {
  2879.  
  2880. ytEvented = true;
  2881. slowMode = false;
  2882. idleFrom = Date.now() + 1700;
  2883.  
  2884. });
  2885.  
  2886.  
  2887. document.addEventListener('yt-player-updated', () => {
  2888.  
  2889. ytEvented = true;
  2890. slowMode = false;
  2891. idleFrom = Date.now() + 1700;
  2892.  
  2893. });
  2894.  
  2895.  
  2896. document.addEventListener('yt-page-data-fetched', () => {
  2897.  
  2898. ytEvented = true;
  2899. slowMode = false;
  2900. idleFrom = Date.now() + 1700;
  2901.  
  2902. });
  2903.  
  2904. document.addEventListener('yt-navigate-finish', () => {
  2905.  
  2906. ytEvented = true;
  2907. slowMode = false;
  2908. let t = Date.now() + 700;
  2909. if (t > idleFrom) idleFrom = t;
  2910.  
  2911. });
  2912.  
  2913. document.addEventListener('yt-page-data-updated', () => {
  2914.  
  2915. ytEvented = true;
  2916. slowMode = false;
  2917. let t = Date.now() + 700;
  2918. if (t > idleFrom) idleFrom = t;
  2919.  
  2920. });
  2921.  
  2922. document.addEventListener('yt-watch-comments-ready', () => {
  2923.  
  2924. ytEvented = true;
  2925. slowMode = false;
  2926. let t = Date.now() + 700;
  2927. if (t > idleFrom) idleFrom = t;
  2928.  
  2929. });
  2930. } : () => { };
  2931.  
  2932.  
  2933. // << end >>
  2934.  
  2935. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  2936.  
  2937. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  2938. let pageSetupState = 0;
  2939.  
  2940. isPrepareCachedV && (() => {
  2941.  
  2942. pageSetupVideoId = '';
  2943. const clearCachedV = () => {
  2944. pageSetupVideoId = '';
  2945. pageSetupState = 0;
  2946. }
  2947. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  2948. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  2949. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  2950. document.addEventListener('yt-navigate-finish', () => {
  2951. pageSetupState = 1;
  2952. try {
  2953. const url = new URL(location.href);
  2954. if (!url || url.pathname !== '/watch') {
  2955. pageSetupVideoId = '';
  2956. } else {
  2957. pageSetupVideoId = url.searchParams.get('v') || '';
  2958. }
  2959. } catch (e) {
  2960. pageSetupVideoId = '';
  2961. }
  2962. }, false);
  2963.  
  2964. })();
  2965.  
  2966. let videoPlayingY = null;
  2967.  
  2968. isPrepareCachedV && (() => {
  2969.  
  2970. let getNext = true;
  2971. let videoPlayingX = {
  2972. get videoId(){
  2973. if(getNext){
  2974. getNext = false;
  2975.  
  2976. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  2977. const arr = [];
  2978. for (const element of elements) {
  2979. if (!element.closest('[hidden]')) arr.push(element);
  2980. }
  2981. if (arr.length !== 1) this.__videoId__ = '';
  2982. else {
  2983. this.__videoId__ = arr[0].getAttribute('video-id');
  2984. }
  2985. }
  2986. return this.__videoId__ || '';
  2987. }
  2988. }
  2989.  
  2990. videoPlayingY = videoPlayingX;
  2991. const handler = (evt) => {
  2992. const target = (evt || 0).target;
  2993. if (target instanceof HTMLVideoElement) {
  2994. getNext = true;
  2995. }
  2996. }
  2997. document.addEventListener('loadedmetadata', handler, true);
  2998. document.addEventListener('durationchange', handler, true);
  2999.  
  3000. })();
  3001.  
  3002.  
  3003.  
  3004. const cleanContext = async (win) => {
  3005. const waitFn = requestAnimationFrame; // shall have been binded to window
  3006. try {
  3007. let mx = 16; // MAX TRIAL
  3008. const frameId = 'vanillajs-iframe-v1';
  3009. /** @type {HTMLIFrameElement | null} */
  3010. let frame = document.getElementById(frameId);
  3011. let removeIframeFn = null;
  3012. if (!frame) {
  3013. frame = document.createElement('iframe');
  3014. frame.id = frameId;
  3015. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  3016. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  3017. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  3018. n.appendChild(frame);
  3019. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  3020. const root = document.documentElement;
  3021. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  3022. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  3023.  
  3024. removeIframeFn = (setTimeout) => {
  3025. const removeIframeOnDocumentReady = (e) => {
  3026. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  3027. e = n;
  3028. n = win = removeIframeFn = 0;
  3029. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  3030. }
  3031. if (!setTimeout || document.readyState !== 'loading') {
  3032. removeIframeOnDocumentReady();
  3033. } else {
  3034. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  3035. }
  3036. }
  3037. }
  3038. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  3039. const fc = frame.contentWindow;
  3040. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  3041. try {
  3042. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  3043. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  3044. for (let k in res) res[k] = res[k].bind(win); // necessary
  3045. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  3046. res.animate = fc.HTMLElement.prototype.animate;
  3047. res.perfNow = fc.performance.now;
  3048. return res;
  3049. } catch (e) {
  3050. if (removeIframeFn) removeIframeFn();
  3051. return null;
  3052. }
  3053. } catch (e) {
  3054. console.warn(e);
  3055. return null;
  3056. }
  3057. };
  3058.  
  3059. const promiseForYtActionCalled = new Promise(resolve => {
  3060. let hn = () => {
  3061. if (!hn) return;
  3062. document.removeEventListener('yt-action', hn, true);
  3063. hn = null;
  3064. resolve(document.querySelector('ytd-app'));
  3065. };
  3066. document.addEventListener('yt-action', hn, true);
  3067. });
  3068.  
  3069.  
  3070.  
  3071. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  3072.  
  3073. cleanContext(window).then(__CONTEXT__ => {
  3074. if (!__CONTEXT__) return null;
  3075.  
  3076. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  3077.  
  3078.  
  3079. performance.now17 = perfNow.bind(performance);
  3080. // performance.now = performance.now16;
  3081. /*
  3082. let nowh = -1;
  3083. performance.now = function () {
  3084. let t = nowh;
  3085. let c = this.now17();
  3086. return (nowh = (t + 1e-7 > c ? t + 0.1 : c));
  3087. }
  3088. */
  3089.  
  3090. // console.log(performance.now())
  3091. // console.log(performance.now())
  3092. // console.log(performance.now())
  3093. // console.log(performance.now())
  3094.  
  3095.  
  3096.  
  3097. __requestAnimationFrame__ = requestAnimationFrame;
  3098.  
  3099. let rafPromise = null;
  3100.  
  3101. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  3102. requestAnimationFrame(hRes => {
  3103. rafPromise = null;
  3104. resolve(hRes);
  3105. });
  3106. }));
  3107.  
  3108. const getForegroundPromise = () => {
  3109. if (document.visibilityState === 'visible') {
  3110. return Promise.resolve();
  3111. } else {
  3112. return getRafPromise();
  3113. }
  3114. };
  3115.  
  3116. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  3117. setTimeout(() => {
  3118. NO_PRELOAD_GENERATE_204_BYPASS = true;
  3119. }, 1270);
  3120. });
  3121.  
  3122. const promiseForTamerTimeout = new Promise(resolve => {
  3123. promiseForCustomYtElementsReady.then(() => {
  3124. customElements.whenDefined('ytd-app').then(() => {
  3125. setTimeout(resolve, 1200);
  3126. });
  3127. });
  3128. setTimeout(resolve, 3000);
  3129. });
  3130.  
  3131.  
  3132. class RAFHub {
  3133. constructor() {
  3134. /** @type {number} */
  3135. this.startAt = 8170;
  3136. /** @type {number} */
  3137. this.counter = 0;
  3138. /** @type {number} */
  3139. this.rid = 0;
  3140. /** @type {Map<number, FrameRequestCallback>} */
  3141. this.funcs = new Map();
  3142. const funcs = this.funcs;
  3143. /** @type {FrameRequestCallback} */
  3144. this.bCallback = this.mCallback.bind(this);
  3145. this.pClear = () => funcs.clear();
  3146. }
  3147. /** @param {DOMHighResTimeStamp} highResTime */
  3148. mCallback(highResTime) {
  3149. this.rid = 0;
  3150. Promise.resolve().then(this.pClear);
  3151. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  3152. }
  3153. /** @param {FrameRequestCallback} f */
  3154. request(f) {
  3155. if (this.counter > 1e9) this.counter = 9;
  3156. let cid = this.startAt + (++this.counter);
  3157. this.funcs.set(cid, f);
  3158. if (this.rid === 0) {
  3159. console.log(2455)
  3160. this.rid = requestAnimationFrame(this.bCallback);
  3161. }
  3162. return cid;
  3163. }
  3164. /** @param {number} cid */
  3165. cancel(cid) {
  3166. cid = +cid;
  3167. if (cid > 0) {
  3168. if (cid <= this.startAt) {
  3169. return cancelAnimationFrame(cid);
  3170. }
  3171. if (this.rid > 0) {
  3172. this.funcs.delete(cid);
  3173. if (this.funcs.size === 0) {
  3174. cancelAnimationFrame(this.rid);
  3175. this.rid = 0;
  3176. }
  3177. }
  3178. }
  3179. }
  3180. /** @param {number} cid */
  3181. /** @param {FrameRequestCallback} f */
  3182. replaceFunc(cid, f) {
  3183. if (typeof this.funcs.get(cid) === 'function') {
  3184. this.funcs.set(cid, f);
  3185. return cid;
  3186. } else {
  3187. let r = this.request(f);
  3188. this.cancel(cid);
  3189. return r;
  3190. }
  3191. }
  3192. }
  3193.  
  3194.  
  3195. // WEAK_REF_BINDING && (async () => {
  3196.  
  3197. // ['tp-yt-paper-menu-button'].forEach(async tag => {
  3198.  
  3199. // const dummy = await new Promise(resolve => {
  3200. // promiseForCustomYtElementsReady.then(() => {
  3201. // customElements.whenDefined(tag).then(() => {
  3202. // resolve(document.createElement(tag));
  3203. // });
  3204. // });
  3205.  
  3206. // });
  3207.  
  3208. // if (!dummy || dummy.is !== tag) return;
  3209.  
  3210. // const cProto = insp(dummy).constructor.prototype;
  3211.  
  3212. // if (typeof cProto.close === 'function' && !cProto.close58) {
  3213. // cProto.close58 = cProto.close;
  3214. // console.log(cProto.close58)
  3215. // cProto.close = function () {
  3216. // // const dropdown = (this.$ || 0).dropdown || 0;
  3217. // // if (!dropdown) return;
  3218. // try{
  3219. // return this.close58.apply(this, arguments);
  3220. // }catch(e){
  3221.  
  3222. // }
  3223.  
  3224. // }
  3225. // }
  3226.  
  3227.  
  3228. // });
  3229.  
  3230. // })();
  3231.  
  3232. NATIVE_CANVAS_ANIMATION && (() => {
  3233.  
  3234. observablePromise(() => {
  3235. HTMLCanvasElement.prototype.animate = animate;
  3236. }, promiseForTamerTimeout).obtain();
  3237.  
  3238. })();
  3239.  
  3240. FIX_ytAction_ && (async () => {
  3241.  
  3242. const ytdApp = await new Promise(resolve => {
  3243.  
  3244. promiseForCustomYtElementsReady.then(() => {
  3245. customElements.whenDefined('ytd-app').then(() => {
  3246. const ytdApp = document.querySelector('ytd-app');
  3247. if (ytdApp) {
  3248. resolve(ytdApp);
  3249. return;
  3250. }
  3251. let mo = new MutationObserver(() => {
  3252. const ytdApp = document.querySelector('ytd-app');
  3253. if (!ytdApp) return;
  3254. if (mo) {
  3255. mo.disconnect();
  3256. mo.takeRecords();
  3257. mo = null;
  3258. }
  3259. resolve(ytdApp);
  3260. });
  3261. mo.observe(document, { subtree: true, childList: true });
  3262. });
  3263. });
  3264.  
  3265. });
  3266.  
  3267. if (!ytdApp) return;
  3268. const cProto = insp(ytdApp).constructor.prototype;
  3269.  
  3270. if (!cProto) return;
  3271. let mbd = 0;
  3272.  
  3273. const fixer = (_ytdApp) => {
  3274. const ytdApp = insp(_ytdApp);
  3275. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  3276. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  3277. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  3278. mbd++;
  3279. }
  3280. }
  3281.  
  3282. observablePromise(() => {
  3283.  
  3284. if (typeof cProto.created === 'function' && !cProto.created56) {
  3285. cProto.created56 = cProto.created;
  3286. cProto.created = function (...args) {
  3287. const r = this.created56(...args);
  3288. fixer(this);
  3289. return r;
  3290. };
  3291. mbd++;
  3292. }
  3293.  
  3294. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  3295. cProto.onYtAction57_ = cProto.onYtAction_;
  3296. cProto.onYtAction_ = function (...args) {
  3297. Promise.resolve().then(() => this.onYtAction57_(...args));
  3298. };
  3299. mbd++;
  3300. }
  3301.  
  3302. if (ytdApp) fixer(ytdApp);
  3303.  
  3304. /*
  3305. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  3306. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  3307. actionRouter_.handleAction57 = actionRouter_.handleAction;
  3308. actionRouter_.handleAction = function (...args) {
  3309. Promise.resolve().then(() => this.handleAction57(...args));
  3310. }
  3311. mbd++;
  3312. }
  3313. */
  3314.  
  3315. // if(mbd === 3) return 1;
  3316. if (mbd >= 3) return 1;
  3317.  
  3318. }, new Promise(r => setTimeout(r, 1000))).obtain();
  3319.  
  3320. })();
  3321.  
  3322. const observablePromise = (proc, timeoutPromise) => {
  3323. let promise = null;
  3324. return {
  3325. obtain() {
  3326. if (!promise) {
  3327. promise = new Promise(resolve => {
  3328. let mo = null;
  3329. const f = () => {
  3330. let t = proc();
  3331. if (t) {
  3332. mo.disconnect();
  3333. mo.takeRecords();
  3334. mo = null;
  3335. resolve(t);
  3336. }
  3337. }
  3338. mo = new MutationObserver(f);
  3339. mo.observe(document, { subtree: true, childList: true })
  3340. f();
  3341. timeoutPromise && timeoutPromise.then(() => {
  3342. resolve(null)
  3343. });
  3344. });
  3345. }
  3346. return promise
  3347. }
  3348. }
  3349. }
  3350.  
  3351. // let _yt_player_promise = null;
  3352. /*
  3353. const getYtPlayerPromise = () => {
  3354. if (!_yt_player_promise) {
  3355. _yt_player_promise = new Promise(resolve => {
  3356. let cid = setInterval(() => {
  3357. let t = (((window || 0)._yt_player || 0) || 0);
  3358. if (t) {
  3359. clearInterval(cid);
  3360. resolve(t);
  3361. }
  3362. }, 1);
  3363. promiseForTamerTimeout.then(() => {
  3364. resolve(null)
  3365. });
  3366. });
  3367. }
  3368. return _yt_player_promise;
  3369. }
  3370. */
  3371. const _yt_player_observable = observablePromise(() => {
  3372. return (((window || 0)._yt_player || 0) || 0);
  3373. }, promiseForTamerTimeout);
  3374.  
  3375. const polymerObservable = observablePromise(() => {
  3376. const Polymer = window.Polymer;
  3377. if (typeof Polymer !== 'function') return;
  3378. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  3379. return Polymer;
  3380. }, promiseForTamerTimeout);
  3381.  
  3382. const schedulerInstanceObservable = observablePromise(() => {
  3383. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  3384. }, promiseForTamerTimeout);
  3385.  
  3386. const timelineObservable = observablePromise(() => {
  3387. let t = (((document || 0).timeline || 0) || 0);
  3388. if (t && typeof t._play === 'function') {
  3389. return t;
  3390. }
  3391. }, promiseForTamerTimeout);
  3392. const animationObservable = observablePromise(() => {
  3393. let t = (((window || 0).Animation || 0) || 0);
  3394. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  3395. return t;
  3396. }
  3397. }, promiseForTamerTimeout);
  3398.  
  3399.  
  3400.  
  3401.  
  3402. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  3403.  
  3404. const evKey = `${_evKey}`;
  3405. const fvKey = `${_fvKey}`;
  3406. const debug = !!_debug;
  3407.  
  3408.  
  3409. // const rafHub = new RAFHub();
  3410.  
  3411.  
  3412. const _yt_player = await _yt_player_observable.obtain();
  3413.  
  3414.  
  3415. if (!_yt_player || typeof _yt_player !== 'object') return;
  3416.  
  3417.  
  3418. const getArr = (_yt_player) => {
  3419.  
  3420. let arr = [];
  3421.  
  3422. for (const [k, v] of Object.entries(_yt_player)) {
  3423.  
  3424. const p = typeof v === 'function' ? v.prototype : 0;
  3425. if (p
  3426. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  3427.  
  3428. ) {
  3429. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3430.  
  3431. }
  3432.  
  3433. }
  3434.  
  3435. if (arr.length === 0) {
  3436.  
  3437. console.warn(`Key prop [${evKey}] does not exist.`);
  3438. } else {
  3439.  
  3440. return arr;
  3441. }
  3442.  
  3443. };
  3444.  
  3445. const arr = getArr(_yt_player);
  3446.  
  3447.  
  3448. if (!arr) return;
  3449.  
  3450. debug && console.log(`FIX_${evKey}`, arr);
  3451.  
  3452. const f = function (...args) {
  3453. Promise.resolve().then(() => this[fvKey](...args));
  3454. };
  3455.  
  3456.  
  3457. for (const k of arr) {
  3458.  
  3459. const g = _yt_player;
  3460. const gk = g[k];
  3461. const gkp = gk.prototype;
  3462.  
  3463. debug && console.log(237, k, gkp)
  3464.  
  3465. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  3466. gkp[fvKey] = gkp[evKey];
  3467. gkp[evKey] = f;
  3468. }
  3469. }
  3470.  
  3471.  
  3472.  
  3473.  
  3474. }
  3475.  
  3476. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  3477. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  3478. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  3479. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  3480. if (FIX_VideoEVENTS_v2) {
  3481. const FIX_VideoEVENTS_DEBUG = 0;
  3482. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  3483. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  3484. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  3485. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  3486. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  3487. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  3488. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  3489. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  3490. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  3491.  
  3492. }
  3493. // onMutedAutoplayChange
  3494. // onVolumeChange
  3495. // onPlaybackRateChange
  3496.  
  3497. // onAirPlayActiveChange
  3498. // onAirPlayAvailabilityChange
  3499. // onApiChange
  3500. // onAutoplayBlocked
  3501. // onDrmOutputRestricted
  3502. // onFullscreenChange
  3503. // onLoadProgress
  3504. // onLoadedMetadata
  3505. // onVideoDataChange
  3506. // onVideoProgress
  3507.  
  3508. (FIX_maybeUpdateFlexibleMenu || WEAK_REF_BINDING) && (async () => {
  3509.  
  3510.  
  3511. const dummy = await new Promise(resolve => {
  3512.  
  3513. promiseForCustomYtElementsReady.then(() => {
  3514. customElements.whenDefined('ytd-menu-renderer').then(() => {
  3515.  
  3516. resolve(document.createElement('ytd-menu-renderer'));
  3517. });
  3518. });
  3519.  
  3520.  
  3521.  
  3522. });
  3523.  
  3524.  
  3525. if (!dummy || dummy.is !== 'ytd-menu-renderer') return;
  3526.  
  3527. const cProto = insp(dummy).constructor.prototype;
  3528.  
  3529. if (FIX_maybeUpdateFlexibleMenu && typeof cProto.created === 'function' && !cProto.created58) {
  3530. cProto.created58 = cProto.created;
  3531. cProto.created = function (...args) {
  3532. const r = this.created58(...args);
  3533. if (typeof this.maybeUpdateFlexibleMenu === 'function' && !this.maybeUpdateFlexibleMenu57) {
  3534. this.maybeUpdateFlexibleMenu57 = this.maybeUpdateFlexibleMenu;
  3535. this.maybeUpdateFlexibleMenu = function (...args) {
  3536. Promise.resolve().then(() => this.maybeUpdateFlexibleMenu57(...args));
  3537. }
  3538. }
  3539. return r;
  3540. }
  3541.  
  3542. }
  3543.  
  3544.  
  3545.  
  3546. // if (WEAK_REF_BINDING && typeof cProto.setupFlexibleMenu === 'function' && !cProto.setupFlexibleMenu58) {
  3547. // cProto.setupFlexibleMenu58 = cProto.setupFlexibleMenu;
  3548. // cProto.setupFlexibleMenu = function () {
  3549.  
  3550. // const hostElement = this.hostElement;
  3551. // if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  3552. // return void 0;
  3553. // } else {
  3554. // return this.setupFlexibleMenu58.apply(this, arguments);
  3555. // }
  3556.  
  3557. // }
  3558.  
  3559.  
  3560.  
  3561. // }
  3562.  
  3563.  
  3564. // if (WEAK_REF_BINDING && typeof cProto.stampDomArray_ === 'function' && !cProto.stampDomArray58_) {
  3565. // cProto.stampDomArray58_ = cProto.stampDomArray_;
  3566. // cProto.stampDomArray_ = function (a, b, c, d, e, h) {
  3567.  
  3568. // const hostElement = this.hostElement;
  3569. // if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  3570. // return void 0;
  3571. // } else {
  3572. // return this.stampDomArray58_.apply(this, arguments);
  3573. // }
  3574.  
  3575. // }
  3576.  
  3577.  
  3578.  
  3579. // }
  3580.  
  3581.  
  3582.  
  3583.  
  3584.  
  3585. //console.log(144,cProto.maybeUpdateFlexibleMenu)
  3586.  
  3587.  
  3588.  
  3589.  
  3590.  
  3591.  
  3592. })();
  3593.  
  3594. (ENABLE_discreteTasking || UNLOAD_DETACHED_POLYMER) && (async () => {
  3595.  
  3596. const Polymer = await polymerObservable.obtain();
  3597. if (!Polymer) return;
  3598.  
  3599.  
  3600. if (UNLOAD_DETACHED_POLYMER && typeof Polymer.Base.detached === 'function' && !Polymer.Base.detached92 && Polymer.Base.detached.length === 0) {
  3601. Polymer.Base.detached92 = Polymer.Base.detached;
  3602.  
  3603. const detachedPlus = async function (elem) {
  3604. await delay300.then();
  3605. if (elem.isAttached !== false) return;
  3606. await delay300.then();
  3607. if (elem.isAttached !== false) return;
  3608.  
  3609. if (elem.__dataClientsReady === true) elem.__dataClientsReady = false;
  3610. // if (elem.__dataEnabled === true) elem.__dataEnabled = false;
  3611. if (elem.__dataReady === true) elem.__dataReady = false;
  3612.  
  3613. elem.__dataLinkedPaths = elem.__dataToNotify = elem.__dataPendingClients = null;
  3614. elem.__dataHasPaths = false;
  3615. // elem.__dataCompoundStorage = null;
  3616. elem.__dataHost = null;
  3617. elem.__dataTemp = null;
  3618. elem.__dataClientsInitialized = false;
  3619.  
  3620.  
  3621. // elem.data = {};
  3622. elem.data = null;
  3623. elem.__dataPending = null;
  3624. elem.__dataOld = null;
  3625. elem.__dataInstanceProps = null;
  3626.  
  3627. elem.__dataCounter = 0;
  3628. elem.__serializing = false;
  3629.  
  3630. // if (elem.$) elem.$ = {};
  3631. // if (elem.root) elem.root = null;
  3632.  
  3633. // let hostElement = elem.hostElement, tlm;
  3634. // if (hostElement instanceof Node) {
  3635. // // if (hostElement.isConnected === false) {
  3636. // // while (tlm = hostElement.firstChild) tlm.remove();
  3637. // // }
  3638. // elem.hostElement = hostElement = null;
  3639. // }
  3640.  
  3641.  
  3642. // if (hostElement === null) {
  3643.  
  3644. // if (elem.animatedIconElement instanceof Node) elem.animatedIconElement = null;
  3645. // if (elem._target instanceof Node) elem._target = null;
  3646. // if (elem.iconset instanceof Node) elem.iconset = null;
  3647. // if (elem._svgIcon instanceof Node) elem._svgIcon = null;
  3648.  
  3649. // }
  3650.  
  3651.  
  3652. }
  3653. Polymer.Base.detached = function () {
  3654. Promise.resolve(this).then(detachedPlus);
  3655. return Polymer.Base.detached92();
  3656. };
  3657. }
  3658.  
  3659.  
  3660. if (ENABLE_discreteTasking) {
  3661.  
  3662. Polymer.Base.__connInit__ = function () {
  3663. setupDiscreteTasks(this);
  3664. // if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  3665. // setupWeakRef(this)
  3666. // }
  3667. }
  3668.  
  3669.  
  3670. /** @type {Function} */
  3671. const connectedCallbackK = function (...args) {
  3672. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3673. const r = this[qm53](...args);
  3674. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3675. this.mh35 = 1;
  3676. return r;
  3677. };
  3678.  
  3679. connectedCallbackK.m353 = 1;
  3680.  
  3681.  
  3682. const qt53 = Polymer.Base.connectedCallback;
  3683. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  3684.  
  3685. Polymer.Base.connectedCallback = connectedCallbackK;
  3686.  
  3687.  
  3688. /** @type {Function} */
  3689. const createdK = function (...args) {
  3690. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3691. const r = this[qn53](...args);
  3692. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3693. this.mh36 = 1;
  3694. return r;
  3695. };
  3696.  
  3697.  
  3698. createdK.m353 = 1;
  3699. Polymer.Base[qn53] = Polymer.Base.created;
  3700. Polymer.Base.created = createdK;
  3701.  
  3702. }
  3703.  
  3704. })();
  3705.  
  3706. CHANGE_appendChild && (() => {
  3707.  
  3708. const f = HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  3709. if (f) HTMLElement.prototype.appendChild = function (a) {
  3710.  
  3711. if (a instanceof HTMLVideoElement && FIX_VIDEO_BLOCKING) {
  3712. try {
  3713. const src = `${a.src}`;
  3714. const b = src.length > 5 && src.startsWith('blob:') && typeof a.ontimeupdate === 'function' && a.autoplay === false && a.paused === true && a.isConnected === false && typeof nextBrowserTick === 'function' && typeof AbortSignal !== 'undefined';
  3715. if (b) {
  3716. a.addEventListener('canplay', (evt) => {
  3717. const a = evt.target;
  3718. console.log(`video element added to dom | canplay`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  3719. if (a.currentTime < 1e-8 && a.currentTime > -1e-9) a.currentTime += 1e-8;
  3720. }, { once: true, passive: true, capture: false });
  3721. a.addEventListener('timeupdate', (evt) => {
  3722. const a = evt.target;
  3723. console.log(`video element added to dom | ontimeupdate`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  3724. if (a.duration > 1.99 && a.duration < 2.01 && a.currentSrc === src) {
  3725. URL.revokeObjectURL(src);
  3726. console.log(`video element added to dom | revokeObjectURL`, mWeakRef(a), a.readyState, a.networkState, a.currentTime);
  3727. }
  3728. }, { once: true, passive: true, capture: false });
  3729. }
  3730. console.log(`video element added to dom | treatment = ${b}`, mWeakRef(a), a.readyState, a.networkState);
  3731. } catch (e) {
  3732. console.log(e);
  3733. }
  3734. } else if (this instanceof HTMLElement) {
  3735.  
  3736. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  3737. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  3738. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  3739. node.__m848__ = 1;
  3740. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  3741. }
  3742. }
  3743. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  3744. return this.appendChild73.apply(this, arguments);
  3745. }
  3746.  
  3747. if (a instanceof DocumentFragment) {
  3748. if (a.firstElementChild === null) {
  3749. let child = a.firstChild;
  3750. if (child === null) return a;
  3751. let doNormal = false;
  3752. while (child instanceof Node) {
  3753. if (child.nodeType === 3) { doNormal = true; break; }
  3754. child = child.nextSibling;
  3755. }
  3756. if (!doNormal) return a;
  3757. }
  3758. }
  3759.  
  3760. return (this.appendChild73 || f).apply(this, arguments);
  3761. }
  3762.  
  3763.  
  3764. return (HTMLElement.prototype.appendChild73 || f).apply(this, arguments);
  3765. }
  3766.  
  3767.  
  3768. })();
  3769.  
  3770. if (FIX_Shady) {
  3771.  
  3772. observablePromise(() => {
  3773. const { ShadyDOM, ShadyCSS } = window;
  3774. if (ShadyDOM) {
  3775. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  3776. ShadyDOM.noPatch = true; // 1 of 10
  3777. ShadyDOM.patchOnDemand = false; // 1 of 10
  3778. ShadyDOM.preferPerformance = true; // 1 of 10
  3779. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  3780. }
  3781. if (ShadyCSS) {
  3782. ShadyCSS.nativeCss = true; // 1 of 10
  3783. ShadyCSS.nativeShadow = true; // 6 of 10
  3784. ShadyCSS.cssBuild = undefined; // 1 of 10
  3785. ShadyCSS.disableRuntime = true; // 1 of 10
  3786. }
  3787. if (ShadyDOM && ShadyCSS) return 1;
  3788. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  3789.  
  3790. }
  3791.  
  3792.  
  3793. FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 && (async () => {
  3794.  
  3795.  
  3796. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  3797.  
  3798. if (!schedulerInstanceInstance_) return;
  3799.  
  3800.  
  3801. if (!ytEvented) {
  3802. idleFrom = Date.now() + 2700;
  3803. slowMode = false; // integrity
  3804. }
  3805.  
  3806. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  3807. if (checkOK) {
  3808.  
  3809.  
  3810. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  3811.  
  3812. let requestingFn = null;
  3813. let requestingArgs = null;
  3814. let requestingDT = 0;
  3815.  
  3816. // let timerId = null;
  3817. const entries = [];
  3818. const f = function () {
  3819. requestingFn = this.fn;
  3820. requestingArgs = [...arguments];
  3821. requestingDT = Date.now();
  3822. entries.push({
  3823. fn: requestingFn,
  3824. args: requestingArgs,
  3825. t: requestingDT
  3826. });
  3827. // if (Date.now() < idleFrom) {
  3828. // timerId = this.fn.apply(window, arguments);
  3829. // } else {
  3830. // timerId = this.fn.apply(window, arguments);
  3831.  
  3832. // }
  3833. // timerId = 12377;
  3834. return 12377;
  3835. }
  3836.  
  3837.  
  3838. const fakeFns = [
  3839. f.bind({ fn: requestAnimationFrame }),
  3840. f.bind({ fn: setInterval }),
  3841. f.bind({ fn: setTimeout }),
  3842. f.bind({ fn: requestIdleCallback })
  3843. ]
  3844.  
  3845.  
  3846.  
  3847.  
  3848. let timerResolve = null;
  3849. setInterval(() => {
  3850. timerResolve && timerResolve();
  3851. timerResolve = null;
  3852. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  3853. }, 250);
  3854.  
  3855. let mzt = 0;
  3856.  
  3857. let fnSelectorProp = null;
  3858.  
  3859. schedulerInstanceInstance_.start = function () {
  3860.  
  3861. const mk1 = window.requestAnimationFrame
  3862. const mk2 = window.setInterval
  3863. const mk3 = window.setTimeout
  3864. const mk4 = window.requestIdleCallback
  3865.  
  3866. const tThis = this['$$12378$$'] || this;
  3867.  
  3868.  
  3869. window.requestAnimationFrame = fakeFns[0]
  3870. window.setInterval = fakeFns[1]
  3871. window.setTimeout = fakeFns[2]
  3872. window.requestIdleCallback = fakeFns[3]
  3873.  
  3874. fnSelectorProp = null;
  3875.  
  3876.  
  3877. tThis.start991.call(new Proxy(tThis, {
  3878. get(target, prop, receiver) {
  3879. if (prop === '$$12377$$') return true;
  3880. if (prop === '$$12378$$') return target;
  3881.  
  3882. // console.log('get',prop)
  3883. return target[prop]
  3884. },
  3885. set(target, prop, value, receiver) {
  3886. // console.log('set', prop, value)
  3887.  
  3888.  
  3889. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  3890. if (value === 12377 && fnSelectorProp) {
  3891.  
  3892. const originalSelection = target[fnSelectorProp];
  3893. const timerIdProp = prop;
  3894.  
  3895. /*
  3896.  
  3897.  
  3898. case 1:
  3899. var a = this.K;
  3900. this.g = this.I ? window.requestIdleCallback(a, {
  3901. timeout: 3E3
  3902. }) : window.setTimeout(a, ma);
  3903. break;
  3904. case 2:
  3905. this.g = window.setTimeout(this.M, this.N);
  3906. break;
  3907. case 3:
  3908. this.g = window.requestAnimationFrame(this.L);
  3909. break;
  3910. case 4:
  3911. this.g = window.setTimeout(this.J, 0)
  3912. }
  3913.  
  3914. */
  3915.  
  3916. const doForegroundSlowMode = () => {
  3917.  
  3918. const tir = ++mzt;
  3919. const f = requestingArgs[0];
  3920.  
  3921.  
  3922. getForegroundPromise().then(() => {
  3923.  
  3924.  
  3925. new Promise(r => {
  3926. timerResolve = r
  3927. }).then(() => {
  3928. if (target[timerIdProp] === -tir) f();
  3929. });
  3930.  
  3931. })
  3932.  
  3933. target[fnSelectorProp] = 931;
  3934. target[prop] = -tir;
  3935. }
  3936.  
  3937. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  3938. if (slowMode && !(requestingArgs[1] > 250)) {
  3939.  
  3940. doForegroundSlowMode();
  3941.  
  3942. } else {
  3943. target[prop] = setTimeout.apply(window, requestingArgs);
  3944.  
  3945. }
  3946.  
  3947. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  3948.  
  3949. if (slowMode) {
  3950.  
  3951. doForegroundSlowMode();
  3952.  
  3953. } else {
  3954. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  3955. }
  3956.  
  3957.  
  3958. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  3959.  
  3960. const f = requestingArgs[0];
  3961. const tir = ++mzt;
  3962. Promise.resolve().then(() => {
  3963. if (target[timerIdProp] === -tir) f();
  3964. });
  3965. target[fnSelectorProp] = 930;
  3966. target[prop] = -tir;
  3967.  
  3968. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  3969.  
  3970. doForegroundSlowMode();
  3971.  
  3972. } else {
  3973. // target[prop] = timerId;
  3974. target[fnSelectorProp] = 0;
  3975. target[prop] = 0;
  3976. }
  3977.  
  3978. // *****
  3979. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  3980. } else {
  3981.  
  3982. target[prop] = value;
  3983. }
  3984. // console.log('set',prop,value)
  3985. return true;
  3986. }
  3987. }));
  3988.  
  3989. fnSelectorProp = null;
  3990.  
  3991.  
  3992. window.requestAnimationFrame = mk1;
  3993. window.setInterval = mk2
  3994. window.setTimeout = mk3
  3995. window.requestIdleCallback = mk4;
  3996.  
  3997.  
  3998.  
  3999. }
  4000.  
  4001. schedulerInstanceInstance_.start.toString = function () {
  4002. return schedulerInstanceInstance_.start991.toString();
  4003. }
  4004.  
  4005. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  4006. // prop,
  4007. // value: schedulerInstanceInstance_[prop],
  4008. // type: typeof schedulerInstanceInstance_[prop]
  4009.  
  4010. // }));
  4011. // console.log('fcc', funcNames)
  4012.  
  4013.  
  4014.  
  4015.  
  4016. }
  4017. })();
  4018.  
  4019.  
  4020.  
  4021. FIX_schedulerInstanceInstance_V2 && !FIX_schedulerInstanceInstance_V1 && (async () => {
  4022.  
  4023.  
  4024. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  4025.  
  4026. if (!schedulerInstanceInstance_) return;
  4027.  
  4028.  
  4029. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  4030. if (checkOK) {
  4031.  
  4032. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  4033.  
  4034.  
  4035.  
  4036. let busy = false;
  4037.  
  4038. // console.log('1667',schedulerInstanceInstance_.start);
  4039. schedulerInstanceInstance_.start = function () {
  4040.  
  4041. // p59 || console.log(location.pathname, 16400);
  4042.  
  4043. if (busy) {
  4044.  
  4045. return this.start991.call(this);
  4046.  
  4047. }
  4048.  
  4049. busy = true;
  4050.  
  4051. const mk1 = window.requestAnimationFrame
  4052. // const mk2 = window.setInterval
  4053. // const mk3 = window.setTimeout
  4054. // const mk4 = window.requestIdleCallback
  4055.  
  4056. // by pass Youtube Engine's wrapping
  4057. window.requestAnimationFrame = baseRAF;
  4058. // window.setInterval = setInterval
  4059. // window.setTimeout = setTimeout
  4060. // window.requestIdleCallback = requestIdleCallback
  4061.  
  4062.  
  4063. this.start991.call(this);
  4064.  
  4065.  
  4066. window.requestAnimationFrame = mk1;
  4067. // window.setInterval = mk2
  4068. // window.setTimeout = mk3
  4069. // window.requestIdleCallback = mk4;
  4070.  
  4071. busy = false;
  4072.  
  4073.  
  4074.  
  4075. }
  4076.  
  4077. schedulerInstanceInstance_.start.toString = function () {
  4078. return schedulerInstanceInstance_.start991.toString();
  4079. }
  4080.  
  4081. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  4082. // prop,
  4083. // value: schedulerInstanceInstance_[prop],
  4084. // type: typeof schedulerInstanceInstance_[prop]
  4085.  
  4086. // }));
  4087. // console.log('fcc', funcNames)
  4088.  
  4089.  
  4090.  
  4091.  
  4092. }
  4093. })();
  4094.  
  4095. FIX_yt_player && (async () => {
  4096.  
  4097.  
  4098.  
  4099. // const rafHub = new RAFHub();
  4100.  
  4101.  
  4102. const _yt_player = await _yt_player_observable.obtain();
  4103.  
  4104.  
  4105.  
  4106. if (!_yt_player || typeof _yt_player !== 'object') return;
  4107.  
  4108.  
  4109.  
  4110. let keyZq = getZq(_yt_player);
  4111. // let keyVG = getVG(_yt_player);
  4112. // let buildVG = _yt_player[keyVG];
  4113. // let u = new buildVG({
  4114. // api: {},
  4115. // element: document.createElement('noscript'),
  4116. // api: {},
  4117. // hide: () => { }
  4118. // }, 250);
  4119. // const timeDelayConstructor = u.delay.constructor; // g.br
  4120. // console.log(keyVG, u)
  4121. // buildVG.prototype.show = function(){}
  4122. // _yt_player[keyZq] = g.k
  4123.  
  4124. if (!keyZq) return;
  4125.  
  4126.  
  4127. const g = _yt_player
  4128. let k = keyZq
  4129.  
  4130. const gk = g[k];
  4131. if (typeof gk !== 'function') return;
  4132. const gkp = gk.prototype;
  4133.  
  4134. let dummyObject = new gk;
  4135. let nilFunc = () => { };
  4136.  
  4137. let nilObj = {};
  4138.  
  4139. // console.log(1111111111)
  4140.  
  4141. let keyBoolD = '';
  4142. let keyWindow = '';
  4143. let keyFuncC = '';
  4144. let keyCidj = '';
  4145.  
  4146. for (const [t, y] of Object.entries(dummyObject)) {
  4147. if (y instanceof Window) keyWindow = t;
  4148. }
  4149.  
  4150. const dummyObjectProxyHandler = {
  4151. get(target, prop) {
  4152. let v = target[prop]
  4153. if (v instanceof Window && !keyWindow) {
  4154. keyWindow = t;
  4155. }
  4156. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  4157. if (prop === keyWindow) y = {
  4158. requestAnimationFrame(f) {
  4159. return 3;
  4160. },
  4161. cancelAnimationFrame() {
  4162.  
  4163. }
  4164. }
  4165. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  4166. keyFuncC = prop;
  4167. }
  4168. // console.log('[get]', prop, typeof target[prop])
  4169.  
  4170.  
  4171. return y;
  4172. },
  4173. set(target, prop, value) {
  4174.  
  4175. if (typeof value === 'boolean' && !keyBoolD) {
  4176. keyBoolD = prop;
  4177. }
  4178. if (typeof value === 'number' && !keyCidj && value >= 2) {
  4179. keyCidj = prop;
  4180. }
  4181.  
  4182. // console.log('[set]', prop, value)
  4183. target[prop] = value
  4184.  
  4185. return true;
  4186. }
  4187. };
  4188.  
  4189. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  4190.  
  4191. /*
  4192. console.log({
  4193. keyBoolD,
  4194. keyFuncC,
  4195. keyWindow,
  4196. keyCidj
  4197. })
  4198.  
  4199. console.log( dummyObject[keyFuncC])
  4200.  
  4201.  
  4202. console.log(2222222222)
  4203. */
  4204.  
  4205.  
  4206. // console.log('gkp.start',gkp.start);
  4207. // console.log('gkp.stop',gkp.stop);
  4208. gkp._activation = false;
  4209.  
  4210. gkp.start = function () {
  4211. // p59 || console.log(12100)
  4212. if (!this._activation) {
  4213. this._activation = true;
  4214. getRafPromise().then(() => {
  4215. this._activation = false;
  4216. if (this[keyCidj]) {
  4217. Promise.resolve().then(this[keyFuncC]);
  4218. }
  4219. });
  4220. }
  4221. this[keyCidj] = 1;
  4222. this[keyBoolD] = true;
  4223. }
  4224. ;
  4225. gkp.stop = function () {
  4226. this[keyCidj] = null
  4227. }
  4228.  
  4229.  
  4230. /*
  4231. g[k].start = function() {
  4232. this.stop();
  4233. this.D = true;
  4234. var a = requestAnimationFrame
  4235. , b = cancelAnimationFrame;
  4236. this.j = a.call(this.B, this.C)
  4237. }
  4238. ;
  4239. g[k].stop = function() {
  4240. if (this.isActive()) {
  4241. var a = requestAnimationFrame
  4242. , b = cancelAnimationFrame;
  4243. b.call(this.B, this.j)
  4244. }
  4245. this.j = null
  4246. }
  4247. */
  4248.  
  4249.  
  4250.  
  4251. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  4252.  
  4253. if (keyzo) {
  4254.  
  4255. k = keyzo
  4256.  
  4257. const setCSSProp = (() => {
  4258.  
  4259. let animationPropCapable = false;
  4260. try {
  4261. const propName = "--ibxpf"
  4262. const value = 2;
  4263. const keyframes = [{
  4264. [propName]: value
  4265. }];
  4266. window.CSS.registerProperty({
  4267. name: "--ibxpf",
  4268. syntax: "<number>",
  4269. inherits: false,
  4270. initialValue: 1,
  4271. });
  4272. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  4273. } catch (e) { }
  4274.  
  4275. if (!animationPropCapable) {
  4276. return (element, cssProp, value) => {
  4277.  
  4278.  
  4279. element.style.setProperty(cssProp, value);
  4280.  
  4281. }
  4282. }
  4283.  
  4284. const propMaps = new Map();
  4285.  
  4286. function setCustomCSSProperty(element, propName, value) {
  4287. let wm = propMaps.get(propName);
  4288. if (!wm) {
  4289.  
  4290. try {
  4291. window.CSS.registerProperty({
  4292. name: propName,
  4293. syntax: "*",
  4294. inherits: false
  4295. });
  4296. } catch (e) {
  4297. console.warn(e);
  4298. }
  4299.  
  4300. propMaps.set(propName, (wm = new WeakMap()));
  4301. }
  4302.  
  4303. // Create the animation keyframes with the provided property and value
  4304. const keyframes = [{
  4305. [propName]: value
  4306. }];
  4307.  
  4308. let currentAnimation = wm.get(element);
  4309. if (currentAnimation) {
  4310.  
  4311. currentAnimation.effect.setKeyframes(keyframes);
  4312.  
  4313. } else {
  4314.  
  4315.  
  4316.  
  4317. // Set the animation on the element and immediately pause it
  4318. const animation = animate.call(element, keyframes, {
  4319. duration: 1, // Very short duration as we just want to set the value
  4320. fill: 'forwards',
  4321. iterationStart: 1,
  4322. iterations: 2,
  4323. direction: 'alternate'
  4324. });
  4325.  
  4326.  
  4327. // animation.currentTime = 1;
  4328. animation.pause();
  4329.  
  4330. wm.set(element, animation);
  4331.  
  4332.  
  4333. }
  4334.  
  4335. }
  4336.  
  4337. return setCustomCSSProperty;
  4338.  
  4339.  
  4340. })();
  4341.  
  4342.  
  4343. const attrUpdateFn = g[k];
  4344. g['$$original$$' + k] = attrUpdateFn;
  4345. g[k] = function (a, b, c) {
  4346.  
  4347. // console.log(140000, a, b, c);
  4348.  
  4349. let transformType = '';
  4350. let transformValue = 0;
  4351. let transformUnit = '';
  4352.  
  4353. let byPassDefaultFn = false;
  4354. if (b === "transform" && typeof c === 'string') {
  4355.  
  4356. byPassDefaultFn = true;
  4357.  
  4358. const aStyle = a.style;
  4359.  
  4360. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  4361. if (!(a instanceof HTMLElement)) return;
  4362. if (c.length === 0) {
  4363.  
  4364. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  4365. let p = c.substring(7, c.length - 1);
  4366. let q = p.length >= 1 ? parseFloat(p) : -1;
  4367. if (q > -1e-5 && q < 1 + 1e-5) {
  4368. transformType = 'scalex'
  4369. transformValue = q;
  4370. transformUnit = '';
  4371. }
  4372.  
  4373.  
  4374. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  4375.  
  4376. let p = c.substring(11, c.length - 3);
  4377. let q = p.length >= 1 ? parseFloat(p) : NaN;
  4378.  
  4379. if (typeof q === 'number' && !isNaN(q)) {
  4380. transformType = 'translateX'
  4381. transformValue = q;
  4382. transformUnit = 'px';
  4383. }
  4384.  
  4385.  
  4386. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  4387. let p = c.substring(7, c.length - 1);
  4388. let q = p.length >= 1 ? parseFloat(p) : -1;
  4389. if (q > -1e-5 && q < 1 + 1e-5) {
  4390. transformType = 'scaley'
  4391. transformValue = q;
  4392. transformUnit = '';
  4393. }
  4394.  
  4395.  
  4396. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  4397.  
  4398. let p = c.substring(11, c.length - 3);
  4399. let q = p.length >= 1 ? parseFloat(p) : NaN;
  4400.  
  4401. if (typeof q === 'number' && !isNaN(q)) {
  4402. transformType = 'translateY'
  4403. transformValue = q;
  4404. transformUnit = 'px';
  4405. }
  4406.  
  4407.  
  4408. }
  4409.  
  4410. if (transformType) {
  4411.  
  4412. if (transformType === 'scalex' || transformType === 'scaley') {
  4413.  
  4414. const q = transformValue;
  4415.  
  4416.  
  4417. /*
  4418.  
  4419. let vz = Math.round(steppingScaleN * q);
  4420. const customPropName = '--discrete-'+transformType
  4421.  
  4422. const currentValue = aStyle.getPropertyValue(customPropName);
  4423.  
  4424. const transform = (aStyle.transform || '');
  4425. const u = transform.includes(customPropName)
  4426. if (`${currentValue}` === `${vz}`) {
  4427. if (u) return;
  4428. }
  4429.  
  4430.  
  4431. setCSSProp(a,customPropName, vz);
  4432. // aStyle.setProperty(customPropName, vz)
  4433.  
  4434. let ck = '';
  4435.  
  4436. if (c.length === 9) ck = c;
  4437. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  4438.  
  4439. if (ck && beforeMq !== ck) {
  4440. aStyle.setProperty('--mq-transform', ck);
  4441. }
  4442.  
  4443. if (u) return;
  4444. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  4445.  
  4446.  
  4447.  
  4448. */
  4449.  
  4450. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  4451.  
  4452. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  4453. const cv = aStyle.transform;
  4454.  
  4455. // console.log(157, cv,c)
  4456.  
  4457. if (c === cv) return;
  4458. // console.log(257, cv,c)
  4459.  
  4460. aStyle.transform = c;
  4461.  
  4462. // return;
  4463.  
  4464. } else if (transformType === 'translateX' || transformType === 'translateY') {
  4465.  
  4466. const q = transformValue;
  4467.  
  4468. /*
  4469.  
  4470. let vz = q.toFixed(1);
  4471. const customPropName = '--discrete-'+transformType
  4472.  
  4473. const aStyle = a.style;
  4474. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  4475.  
  4476.  
  4477. const transform = (aStyle.transform || '');
  4478. const u = transform.includes(customPropName)
  4479. if (parseFloat(currentValue).toFixed(1) === vz) {
  4480. if (u) return;
  4481. }
  4482.  
  4483. setCSSProp(a,customPropName, vz + 'px');
  4484. // aStyle.setProperty(customPropName, vz + 'px')
  4485.  
  4486. let ck = '';
  4487. if (c.length === 15) ck = c;
  4488. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  4489.  
  4490. if (ck && beforeMq !== ck) {
  4491. aStyle.setProperty('--mq-transform', ck);
  4492. }
  4493.  
  4494. if (u) return;
  4495. c = `${transformType}(var(--discrete-${transformType}))`;
  4496.  
  4497. */
  4498.  
  4499.  
  4500. const vz = +q.toFixed(1);
  4501.  
  4502. c = `${transformType}(${vz}${transformUnit})`
  4503. const cv = aStyle.transform;
  4504.  
  4505. // console.log(158, cv,c)
  4506.  
  4507. if (c === cv) return;
  4508. // console.log(258, cv,c)
  4509.  
  4510. aStyle.transform = c;
  4511.  
  4512. // return;
  4513.  
  4514. } else {
  4515. throw new Error();
  4516. }
  4517.  
  4518. } else {
  4519. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  4520. const cv = aStyle.transform
  4521. if (!c && !cv) return;
  4522. else if (c === cv) return;
  4523. aStyle.transform = c;
  4524. // return;
  4525. }
  4526.  
  4527. } else if (b === "display") {
  4528.  
  4529. const cv = a.style.display;
  4530. if (!cv && !c) return;
  4531. if (cv === c) return;
  4532.  
  4533.  
  4534. } else if (b === "width") {
  4535.  
  4536. const cv = a.style.width;
  4537. if (!cv && !c) return;
  4538. if (cv === c) return;
  4539.  
  4540. }
  4541.  
  4542. // console.log(130000, a, b, c);
  4543.  
  4544. if (byPassDefaultFn) return;
  4545. return attrUpdateFn.call(this, a, b, c);
  4546. }
  4547.  
  4548.  
  4549. /*
  4550.  
  4551. g.zo = function(a, b, c) {
  4552. if ("string" === typeof b)
  4553. (b = yo(a, b)) && (a.style[b] = c);
  4554. else
  4555. for (var d in b) {
  4556. c = a;
  4557. var e = b[d]
  4558. , f = yo(c, d);
  4559. f && (c.style[f] = e)
  4560. }
  4561. }
  4562.  
  4563.  
  4564. */
  4565.  
  4566.  
  4567. }
  4568.  
  4569.  
  4570.  
  4571. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  4572.  
  4573. if (keyuG) {
  4574.  
  4575. k = keyuG;
  4576.  
  4577. const gk = g[k];
  4578. const gkp = gk.prototype;
  4579.  
  4580.  
  4581. /** @type { Map<string, WeakMap<any, any>> } */
  4582. const ntLogs = new Map();
  4583.  
  4584. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  4585.  
  4586. gkp.updateValue31 = gkp.updateValue;
  4587. gkp.updateValue = function (a, b) {
  4588. if (typeof a !== 'string') return this.updateValue31(a, b);
  4589.  
  4590. const element = this.element;
  4591. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  4592.  
  4593. let ntLog = ntLogs.get(a);
  4594. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  4595.  
  4596. let cache = ntLog.get(element);
  4597. if (cache && cache.value === b) {
  4598. return;
  4599. }
  4600. if (!cache) {
  4601. this.__oldValueByUpdateValue__ = null;
  4602. ntLog.set(element, cache = { value: b });
  4603. } else {
  4604. this.__oldValueByUpdateValue__ = cache.value;
  4605. cache.value = b;
  4606. }
  4607.  
  4608.  
  4609. return this.updateValue31(a, b);
  4610. }
  4611.  
  4612.  
  4613. /*
  4614. g.k.update = function(a) {
  4615. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  4616. c = c.value,
  4617. this.updateValue(c, a[c])
  4618. }
  4619. ;
  4620. g.k.updateValue = function(a, b) {
  4621. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  4622. }
  4623. */
  4624.  
  4625.  
  4626. }
  4627.  
  4628.  
  4629. }
  4630.  
  4631.  
  4632.  
  4633.  
  4634. })();
  4635.  
  4636.  
  4637.  
  4638. FIX_Animation_n_timeline && (async () => {
  4639.  
  4640.  
  4641. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  4642.  
  4643. if (!timeline || !Animation) return;
  4644.  
  4645. const aniProto = Animation.prototype;
  4646. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  4647.  
  4648. const getXroto = (x) => {
  4649. try {
  4650. return x.__proto__;
  4651. } catch (e) { }
  4652. return null;
  4653. }
  4654. const timProto = getXroto(timeline);
  4655. if (!timProto) return;
  4656. if (
  4657. (
  4658. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  4659. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  4660. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  4661. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  4662. )
  4663.  
  4664. ) {
  4665.  
  4666. timProto.nofCQ = 1;
  4667. aniProto.nofYH = 1;
  4668.  
  4669. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  4670.  
  4671.  
  4672. /*
  4673. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  4674. return c._updatePromises();
  4675. });
  4676. */
  4677.  
  4678. const p = Array.prototype.filter;
  4679.  
  4680. let res = null;
  4681. Array.prototype.filter = function () {
  4682.  
  4683. res = this;
  4684. return this;
  4685.  
  4686. };
  4687.  
  4688. _updateAnimationsPromises.call({});
  4689.  
  4690. Array.prototype.filter = p;
  4691.  
  4692. if (res && typeof res.length === 'number') {
  4693. /** @type {any[]} */
  4694. const _res = res;
  4695. return _res;
  4696. }
  4697.  
  4698.  
  4699. return null;
  4700.  
  4701.  
  4702.  
  4703.  
  4704. })(timProto._updateAnimationsPromises);
  4705.  
  4706. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  4707.  
  4708. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  4709.  
  4710. aniProto._updatePromises31 = aniProto._updatePromises;
  4711.  
  4712. /*
  4713. aniProto._updatePromises = function(){
  4714. console.log('eff',this._oldPlayState, this.playState)
  4715. return this._updatePromises31.apply(this, arguments)
  4716. }
  4717. */
  4718.  
  4719. aniProto._updatePromises = function () {
  4720. var oldPlayState = this._oldPlayState;
  4721. var newPlayState = this.playState;
  4722. // console.log('ett', oldPlayState, newPlayState)
  4723. if (newPlayState !== oldPlayState) {
  4724. this._oldPlayState = newPlayState;
  4725. if (this._readyPromise) {
  4726. if ("idle" == newPlayState) {
  4727. this._rejectReadyPromise();
  4728. this._readyPromise = void 0;
  4729. } else if ("pending" == oldPlayState) {
  4730. this._resolveReadyPromise();
  4731. } else if ("pending" == newPlayState) {
  4732. this._readyPromise = void 0;
  4733. }
  4734. }
  4735. if (this._finishedPromise) {
  4736. if ("idle" == newPlayState) {
  4737. this._rejectFinishedPromise();
  4738. this._finishedPromise = void 0;
  4739. } else if ("finished" == newPlayState) {
  4740. this._resolveFinishedPromise();
  4741. } else if ("finished" == oldPlayState) {
  4742. this._finishedPromise = void 0;
  4743. }
  4744. }
  4745. }
  4746. return this._readyPromise || this._finishedPromise;
  4747. };
  4748.  
  4749.  
  4750. let restartWebAnimationsNextTickFlag = false;
  4751.  
  4752. const looperMethodT = () => {
  4753.  
  4754. const runnerFn = (hRes) => {
  4755. var b = timeline;
  4756. b.currentTime = hRes;
  4757. b._discardAnimations();
  4758. if (0 == b._animations.length) {
  4759. restartWebAnimationsNextTickFlag = false;
  4760. } else {
  4761. getRafPromise().then(runnerFn);
  4762. }
  4763. }
  4764.  
  4765. const restartWebAnimationsNextTick = () => {
  4766. if (!restartWebAnimationsNextTickFlag) {
  4767. restartWebAnimationsNextTickFlag = true;
  4768. getRafPromise().then(runnerFn);
  4769. }
  4770. }
  4771.  
  4772. return { restartWebAnimationsNextTick }
  4773. };
  4774.  
  4775.  
  4776. const looperMethodN = () => {
  4777.  
  4778. const acs = document.createElement('a-f');
  4779. acs.id = 'a-f';
  4780.  
  4781. const style = document.createElement('style');
  4782. style.textContent = `
  4783. @keyFrames aF1 {
  4784. 0% {
  4785. order: 0;
  4786. }
  4787. 100% {
  4788. order: 6;
  4789. }
  4790. }
  4791. #a-f[id] {
  4792. visibility: collapse !important;
  4793. position: fixed !important;
  4794. top: -100px !important;
  4795. left: -100px !important;
  4796. margin:0 !important;
  4797. padding:0 !important;
  4798. outline:0 !important;
  4799. border:0 !important;
  4800. z-index:-1 !important;
  4801. width: 0px !important;
  4802. height: 0px !important;
  4803. contain: strict !important;
  4804. pointer-events: none !important;
  4805. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  4806. }
  4807. `;
  4808. (document.head || document.documentElement).appendChild(style);
  4809.  
  4810. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  4811.  
  4812. const _onanimationiteration = function (evt) {
  4813. const hRes = evt.timeStamp;
  4814. var b = timeline;
  4815. b.currentTime = hRes;
  4816. b._discardAnimations();
  4817. if (0 == b._animations.length) {
  4818. restartWebAnimationsNextTickFlag = false;
  4819. acs.onanimationiteration = null;
  4820. } else {
  4821. acs.onanimationiteration = _onanimationiteration;
  4822. }
  4823.  
  4824. }
  4825.  
  4826.  
  4827.  
  4828. const restartWebAnimationsNextTick = () => {
  4829. if (!restartWebAnimationsNextTickFlag) {
  4830. restartWebAnimationsNextTickFlag = true;
  4831. acs.onanimationiteration = _onanimationiteration;
  4832.  
  4833. }
  4834. }
  4835.  
  4836. return { restartWebAnimationsNextTick }
  4837. };
  4838.  
  4839.  
  4840.  
  4841. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  4842.  
  4843.  
  4844. // console.log(571, timProto);
  4845. timProto._play = function (c) {
  4846. c = new Animation(c, this);
  4847. this._animations.push(c);
  4848. restartWebAnimationsNextTick();
  4849. c._updatePromises();
  4850. c._animation.play();
  4851. c._updatePromises();
  4852. return c
  4853. }
  4854.  
  4855. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  4856. originalAnimationsWithPromises.length = 0;
  4857. originalAnimationsWithPromises.push = null;
  4858. originalAnimationsWithPromises.splice = null;
  4859. originalAnimationsWithPromises.slice = null;
  4860. originalAnimationsWithPromises.indexOf = null;
  4861. originalAnimationsWithPromises.unshift = null;
  4862. originalAnimationsWithPromises.shift = null;
  4863. originalAnimationsWithPromises.pop = null;
  4864. originalAnimationsWithPromises.filter = null;
  4865. originalAnimationsWithPromises.forEach = null;
  4866. originalAnimationsWithPromises.map = null;
  4867.  
  4868.  
  4869. const _updateAnimationsPromises = () => {
  4870. animationsWithPromisesMap.forEach(c => {
  4871. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  4872. });
  4873. /*
  4874. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  4875. return c._updatePromises();
  4876. });
  4877. */
  4878. }
  4879.  
  4880. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  4881.  
  4882. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  4883.  
  4884. delete timProto._updateAnimationsPromises;
  4885. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  4886. get() {
  4887. if (animationsWithPromisesMap.size === 0) return nilFn;
  4888. return _updateAnimationsPromises;
  4889. },
  4890. set(nv) {
  4891. delete this._updateAnimationsPromises;
  4892. this._updateAnimationsPromises = nv;
  4893. },
  4894. enumerable: true,
  4895. configurable: true,
  4896. });
  4897.  
  4898.  
  4899. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  4900. aniProto.__finished_native_get__ = pdFinished.get;
  4901. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  4902.  
  4903.  
  4904. Object.defineProperty(aniProto, 'finished', {
  4905. get() {
  4906. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  4907. this._finishedPromise = new Promise((resolve, reject) => {
  4908. this._resolveFinishedPromise = function () {
  4909. resolve(this)
  4910. };
  4911. this._rejectFinishedPromise = function () {
  4912. reject({
  4913. type: DOMException.ABORT_ERR,
  4914. name: "AbortError"
  4915. })
  4916. };
  4917. }),
  4918. "finished" == this.playState && this._resolveFinishedPromise());
  4919. return this._finishedPromise
  4920. },
  4921. set: undefined,
  4922. enumerable: true,
  4923. configurable: true
  4924. });
  4925.  
  4926. }
  4927.  
  4928.  
  4929.  
  4930. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  4931. aniProto.__ready_native_get__ = pdReady.get;
  4932. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  4933.  
  4934. Object.defineProperty(aniProto, 'ready', {
  4935. get() {
  4936. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  4937. this._readyPromise = new Promise((resolve, reject) => {
  4938. this._resolveReadyPromise = function () {
  4939. resolve(this)
  4940. };
  4941. this._rejectReadyPromise = function () {
  4942. reject({
  4943. type: DOMException.ABORT_ERR,
  4944. name: "AbortError"
  4945. })
  4946. };
  4947. }),
  4948. "pending" !== this.playState && this._resolveReadyPromise());
  4949. return this._readyPromise
  4950. },
  4951. set: undefined,
  4952. enumerable: true,
  4953. configurable: true
  4954. });
  4955.  
  4956. }
  4957.  
  4958.  
  4959. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  4960.  
  4961. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  4962. const _rebuildUnderlyingAnimation = function () {
  4963. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  4964. this.effect && this.effect._onsample && (this.effect._onsample = null);
  4965. return this._rebuildUnderlyingAnimation21();
  4966. }
  4967. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  4968. // delete aniProto._rebuildUnderlyingAnimation;
  4969. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  4970. // get() {
  4971. // if (isNaN(this._sequenceNumber)) return nilFn;
  4972. // return this._rebuildUnderlyingAnimation21;
  4973. // },
  4974. // set(nv) {
  4975. // delete this._rebuildUnderlyingAnimation;
  4976. // this._rebuildUnderlyingAnimation = nv;
  4977. // },
  4978. // enumerable: true,
  4979. // configurable: true
  4980. // });
  4981. }
  4982.  
  4983.  
  4984. /*
  4985.  
  4986.  
  4987. function f(c) {
  4988. var b = v.timeline;
  4989. b.currentTime = c;
  4990. b._discardAnimations();
  4991. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  4992. }
  4993. var h = window.requestAnimationFrame;
  4994. window.requestAnimationFrame = function(c) {
  4995. return h(function(b) {
  4996. v.timeline._updateAnimationsPromises();
  4997. c(b);
  4998. v.timeline._updateAnimationsPromises()
  4999. })
  5000. }
  5001. ;
  5002. v.AnimationTimeline = function() {
  5003. this._animations = [];
  5004. this.currentTime = void 0
  5005. }
  5006. ;
  5007. v.AnimationTimeline.prototype = {
  5008. getAnimations: function() {
  5009. this._discardAnimations();
  5010. return this._animations.slice()
  5011. },
  5012. _updateAnimationsPromises: function() {
  5013. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  5014. return c._updatePromises()
  5015. })
  5016. },
  5017. _discardAnimations: function() {
  5018. this._updateAnimationsPromises();
  5019. this._animations = this._animations.filter(function(c) {
  5020. return "finished" != c.playState && "idle" != c.playState
  5021. })
  5022. },
  5023. _play: function(c) {
  5024. c = new v.Animation(c,this);
  5025. this._animations.push(c);
  5026. v.restartWebAnimationsNextTick();
  5027. c._updatePromises();
  5028. c._animation.play();
  5029. c._updatePromises();
  5030. return c
  5031. },
  5032. play: function(c) {
  5033. c && c.remove();
  5034. return this._play(c)
  5035. }
  5036. };
  5037. var d = !1;
  5038. v.restartWebAnimationsNextTick = function() {
  5039. d || (d = !0,
  5040. requestAnimationFrame(f))
  5041. }
  5042. ;
  5043. var a = new v.AnimationTimeline;
  5044. v.timeline = a;
  5045. try {
  5046. Object.defineProperty(window.document, "timeline", {
  5047. configurable: !0,
  5048. get: function() {
  5049. return a
  5050. }
  5051. })
  5052. } catch (c) {}
  5053. try {
  5054. window.document.timeline = a
  5055. } catch (c) {}
  5056.  
  5057. */
  5058.  
  5059.  
  5060.  
  5061. /*
  5062.  
  5063. var g = window.getComputedStyle;
  5064. Object.defineProperty(window, "getComputedStyle", {
  5065. configurable: !0,
  5066. enumerable: !0,
  5067. value: function() {
  5068. v.timeline._updateAnimationsPromises();
  5069. var e = g.apply(this, arguments);
  5070. h() && (e = g.apply(this, arguments));
  5071. v.timeline._updateAnimationsPromises();
  5072. return e
  5073. }
  5074. });
  5075.  
  5076. */
  5077.  
  5078.  
  5079.  
  5080.  
  5081. }
  5082.  
  5083.  
  5084.  
  5085.  
  5086. })();
  5087.  
  5088. promiseForCustomYtElementsReady.then(() => {
  5089.  
  5090. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  5091.  
  5092.  
  5093.  
  5094. class LimitedSizeSet extends Set {
  5095. constructor(n) {
  5096. super();
  5097.  
  5098. this.limit = n;
  5099. }
  5100.  
  5101. add(key) {
  5102. if (!super.has(key)) {
  5103. super.add(key); // Set the key with a dummy value (true)
  5104. while (super.size > this.limit) {
  5105. const firstKey = super.values().next().value; // Get the first (oldest) key
  5106. super.delete(firstKey); // Delete the oldest key
  5107. }
  5108. }
  5109. }
  5110.  
  5111. removeAdd(key){
  5112. super.delete(key);
  5113. super.add(key);
  5114. }
  5115.  
  5116. }
  5117.  
  5118. // const wk3 = new WeakMap();
  5119.  
  5120. // let mtxVideoId = '';
  5121. // let aje3 = [];
  5122. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  5123. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  5124. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  5125. let mtzCount = 0; // the key keeps unchanged
  5126. // let mjtNextMainKey = '';
  5127. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  5128. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  5129. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  5130. // let allowNoDelay322=false;
  5131. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  5132.  
  5133. let mpKey22 = ''; // last success continutation key & url pair
  5134. let mpUrl22 = ''; // last success continutation key & url pair
  5135. let mpKey21 = ''; // latest requested continutation key & url pair
  5136. let mpUrl21 = ''; // latest requested continutation key & url pair
  5137.  
  5138.  
  5139. async function sha1Hex(message) {
  5140. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  5141. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  5142. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  5143. const hashHex = hashArray
  5144. .map((b) => b.toString(16).padStart(2, "0"))
  5145. .join(""); // convert bytes to hex string
  5146. return hashHex;
  5147. }
  5148.  
  5149. async function continuationLog(a, ...args) {
  5150. let b = a;
  5151. try {
  5152. if (advanceLogging) b = await sha1Hex(a);
  5153. let c = args.map(e => {
  5154. return e === a ? b : e
  5155. });
  5156. console.log(...c)
  5157. } catch (e) { console.warn(e) }
  5158. }
  5159.  
  5160. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  5161.  
  5162.  
  5163. if (mfvContinuationRecorded.length > 0) {
  5164. for (const [e, d] of mfvContinuationRecorded) {
  5165. mfyContinuationIgnored.removeAdd(e);
  5166. }
  5167. toClearRecorded && mfvContinuationRecorded.clear();
  5168. }
  5169.  
  5170. }
  5171.  
  5172. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  5173.  
  5174. const tmProto = taskMgr.constructor.prototype;
  5175. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  5176.  
  5177. if (!tmProto.addJob714) {
  5178.  
  5179. tmProto.addJob714 = tmProto.addJob;
  5180.  
  5181. tmProto.addJob = function (a, b, c) {
  5182. const jobId = this.addJob714(a, b, c);
  5183. if (jobId > 0) {
  5184. // const ez = wk3.get(this);
  5185. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  5186. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  5187.  
  5188. this.__lastJobId863__ = jobId;
  5189. }
  5190. return jobId;
  5191. }
  5192.  
  5193. }
  5194.  
  5195. if (!tmProto.cancelJob714) {
  5196.  
  5197. tmProto.cancelJob714 = tmProto.cancelJob;
  5198.  
  5199. tmProto.cancelJob = function (a) {
  5200. const res = this.cancelJob714(a);
  5201. // if (a > 0) {
  5202. // for (const e of aje3) {
  5203. // if (e.jobId === a) e.cancelled = true;
  5204. // }
  5205. // }
  5206. return res;
  5207. }
  5208.  
  5209. }
  5210.  
  5211. }
  5212. }
  5213.  
  5214.  
  5215. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && (pageSetupVideoId !== null) && check_for_set_key_order;
  5216.  
  5217.  
  5218. FIX_avoid_incorrect_video_meta_bool && customElements.whenDefined('ytd-video-primary-info-renderer').then(() => {
  5219. let dummy;
  5220. let cProto;
  5221. // let mc = 4;
  5222. // dummy = await observablePromise(() => {
  5223. // const r = document.querySelector('ytd-video-primary-info-renderer');
  5224. // if (!r) return;
  5225. // let cProto = insp(r).constructor.prototype;
  5226. // if (cProto.fetchUpdatedMetadata) return r;
  5227. // if (--mc < 0) return -1;
  5228. // return null;
  5229. // }).obtain();
  5230. dummy = document.createElement('ytd-video-primary-info-renderer');
  5231. if (!(dummy instanceof Element)) return;
  5232. // console.log(5022, dummy)
  5233. cProto = insp(dummy).constructor.prototype;
  5234.  
  5235. cProto.__getEmittorTaskMgr859__ = function () {
  5236. let taskMgr_ = null;
  5237. try {
  5238. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  5239. } catch (e) { }
  5240. return taskMgr_;
  5241. }
  5242. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  5243. // console.log(1234, cProto, cProto.is)
  5244. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  5245.  
  5246. let c_;
  5247. cProto.fetchUpdatedMetadata718 = function (a) {
  5248. // delay or immediate call the actual fetchUpdatedMetadata
  5249.  
  5250. let doImmediately = false;
  5251. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  5252.  
  5253. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  5254.  
  5255. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  5256.  
  5257. doImmediately = true;
  5258.  
  5259. }
  5260.  
  5261. if (mbCId322) {
  5262. clearTimeout(mbCId322);
  5263. mbCId322 = 0;
  5264. }
  5265.  
  5266. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  5267.  
  5268. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  5269.  
  5270. mbCId322 = setTimeout(() => {
  5271. this.fetchUpdatedMetadata717(a);
  5272. }, delay);
  5273.  
  5274. console.log('5190 delayed fetchUpdatedMetadata', delay);
  5275.  
  5276. }
  5277.  
  5278. cProto.fetchUpdatedMetadata = function (a) {
  5279.  
  5280. if (!pageSetupState) {
  5281. if (c_) clearTimeout(c_);
  5282. c_ = setTimeout(() => {
  5283. this.fetchUpdatedMetadata718(a);
  5284. }, 300);
  5285. return;
  5286. }
  5287.  
  5288. // pageSetupState == 0
  5289.  
  5290. try {
  5291.  
  5292. mbDelayBelowNCalls++;
  5293.  
  5294. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  5295. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  5296. }
  5297.  
  5298. // console.log('fum377', a)
  5299. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  5300. console.log('5040 skip fetchUpdatedMetadata', a);
  5301. return;
  5302. }
  5303.  
  5304. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  5305. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  5306. mjtLockPreviousKey = mjtRecordedPrevKey;
  5307. continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  5308. }
  5309. // mjtNextMainKey = true;
  5310. mtzlastAllowedContinuation = '';
  5311. mtzCount = 0;
  5312. // allowNoDelay322 = false;
  5313. // fetch new metadata, cancel all previous continuations
  5314. copyPreviousContiuationToIgnored374(true);
  5315. } else if (typeof a === 'string') {
  5316. const videoPlayingId = videoPlayingY.videoId;
  5317.  
  5318. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  5319.  
  5320. let update21 = !!pageSetupVideoId;
  5321. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  5322. update21 = true;
  5323. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  5324. continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)' , videoPlayingId || '(null)' );
  5325. return;
  5326. }
  5327. if (update21) {
  5328. mpKey21 = a;
  5329. mpUrl21 = pageSetupVideoId || videoPlayingId;
  5330. }
  5331.  
  5332. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  5333. }
  5334. continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)' , videoPlayingY.videoId || '(null)' );
  5335. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  5336. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  5337. return this.fetchUpdatedMetadata718(a);
  5338.  
  5339. } catch (e) {
  5340. console.log('Code Error in fetchUpdatedMetadata', e);
  5341. }
  5342. return this.fetchUpdatedMetadata717(a)
  5343. }
  5344. }
  5345.  
  5346.  
  5347. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  5348. // console.log(1234, cProto, cProto.is)
  5349. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  5350. let mJob = null;
  5351.  
  5352. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  5353.  
  5354. try {
  5355.  
  5356. if (arguments.length > 0) {
  5357. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  5358. }
  5359. // mfy = mfv;
  5360.  
  5361. // mjtNextMainKey = '';
  5362. mtzlastAllowedContinuation = '';
  5363. mtzCount = 0;
  5364. if (mbCId322) {
  5365. clearTimeout(mbCId322);
  5366. mbCId322 = 0;
  5367. }
  5368. mbDelayBelowNCalls = 0;
  5369. // allowNoDelay322 = false;
  5370. copyPreviousContiuationToIgnored374(true);
  5371.  
  5372. const taskMgr = this.__getEmittorTaskMgr859__();
  5373. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  5374. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  5375. console.log('YouTube Super Fast Chat', 'scheduleInitialUpdatedMetadataRequest error 507');
  5376. }
  5377.  
  5378. // prevent depulicated schedule job by clearing previous JobId
  5379. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  5380.  
  5381. let res;
  5382.  
  5383. if (mJob) {
  5384. const job = mJob;
  5385. mJob = null;
  5386. console.log('cancelJob', job)
  5387. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  5388. // p.cancelJob(a,b);
  5389. }
  5390.  
  5391. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  5392.  
  5393. let pza = taskMgr.__lastJobId863__;
  5394. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  5395. let pzb = taskMgr.__lastJobId863__
  5396. if (pza !== pzb) {
  5397. mJob = pzb; // set [Interval Meta Update] jobId
  5398. }
  5399.  
  5400. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  5401. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  5402. // } else {
  5403. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  5404. // }
  5405.  
  5406. return res;
  5407.  
  5408. } else {
  5409. console.log('YouTube Super Fast Chat', 'scheduleInitialUpdatedMetadataRequest error 601');
  5410. }
  5411.  
  5412. } catch (e) {
  5413. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  5414. }
  5415.  
  5416.  
  5417. return this.scheduleInitialUpdatedMetadataRequest717();
  5418. }
  5419. }
  5420.  
  5421.  
  5422. });
  5423.  
  5424. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  5425. let dummy;
  5426. let cProto;
  5427. dummy = ytAppDom;
  5428. if (!(dummy instanceof Element)) return;
  5429. cProto = insp(dummy).constructor.prototype;
  5430. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  5431. // console.log(1234, cProto, cProto.is);
  5432. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  5433. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  5434. // console.log(123401, arguments);
  5435. // return this.handleServiceRequest717_(a, b, c, d);
  5436. // }
  5437.  
  5438. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  5439.  
  5440. // cProto.handleServiceRequest_ = function(a,b,c,d){
  5441. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  5442. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  5443. // console.log('mfv', c.continuation);
  5444. // mfv.add( c.continuation);
  5445. // }
  5446. // return this.handleServiceRequest717_(a,b,c,d);
  5447. // }
  5448.  
  5449. function extraArguments322(a, b, c) {
  5450. let is = (a || 0).is;
  5451. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  5452. let continuation = (c || 0).continuation;
  5453. if (typeof is !== 'string') is = null;
  5454. if (typeof videoId !== 'string') videoId = null;
  5455. if (typeof continuation !== 'string') continuation = null;
  5456. return { is, videoId, continuation };
  5457. }
  5458.  
  5459. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  5460. cProto.sendServiceAjax_ = function (a, b, c, d) {
  5461.  
  5462. // console.log(8001)
  5463. try {
  5464.  
  5465. const { is, videoId, continuation } = extraArguments322(a, b, c);
  5466.  
  5467. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  5468. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  5469. }
  5470.  
  5471. if (pageSetupVideoId && videoId && continuation) {
  5472. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  5473. mfyContinuationIgnored.removeAdd(continuation);
  5474. mfvContinuationRecorded.delete(continuation);
  5475. return;
  5476. }
  5477. }
  5478.  
  5479. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  5480. copyPreviousContiuationToIgnored374(false);
  5481. mfyContinuationIgnored.delete(continuation);
  5482. mfvContinuationRecorded.removeAdd(continuation);
  5483. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  5484. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  5485. mjtLockPreviousKey = '';
  5486. }
  5487. // if (mjtNextMainKey === continuation) {
  5488. // copyPreviousContiuationToIgnored(false);
  5489. // mfyContinuationIgnored.delete(continuation);
  5490. // mfvContinuationRecorded.add(continuation);
  5491. // }
  5492.  
  5493.  
  5494. if (mfyContinuationIgnored && continuation) {
  5495. if (mfyContinuationIgnored.has(continuation)) {
  5496. continuationLog(continuation, '5260 matched01', continuation)
  5497. return;
  5498. }
  5499. }
  5500.  
  5501. // console.log(59902, a?.is, b,c,d)
  5502. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  5503. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  5504. // console.log('mfv377', continuation);
  5505. mfvContinuationRecorded.add(continuation);
  5506. }
  5507.  
  5508. // if (videoId) {
  5509. // if (!pageSetupVideoId) return; // ignore page not ready
  5510. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  5511. // if (videoId !== pageSetupVideoId) {
  5512. // return;
  5513. // }
  5514. // }
  5515.  
  5516. } catch (e) {
  5517. console.log('Coding Error in sendServiceAjax_', e)
  5518. }
  5519. // console.log(8002)
  5520. // console.log(123402, arguments);
  5521. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  5522.  
  5523. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  5524. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  5525. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  5526. // get(target, prop, receiver){
  5527. // console.log('xxs99', target.videoId, mtx)
  5528. // if(prop ==='kdkw33') return 1;
  5529. // console.log(3322, prop, target)
  5530. // if(prop === 'initialDelayMs') {
  5531. // throw new Error("ABCC");
  5532. // }
  5533. // return target[prop];
  5534. // },
  5535. // set(target, prop, value, receiver){
  5536.  
  5537. // if(prop ==='kdkw33') return true;
  5538. // target[prop]=value;
  5539. // return true;
  5540. // }
  5541. // });
  5542. // }
  5543. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  5544. return this.sendServiceAjax717_(a, b, c, d);
  5545. }
  5546. }
  5547.  
  5548. function delayClearOtherKeys(lztContinuation) {
  5549. // // schedule delayed removal if mfyContinuationIgnored is not empty
  5550. // getRafPromise().then(() => {
  5551. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  5552. // // foreground page only
  5553.  
  5554. // });
  5555.  
  5556.  
  5557. if (lztContinuation !== mtzlastAllowedContinuation) return;
  5558. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  5559. if (!mfyContinuationIgnored.size) return;
  5560. if (mfyContinuationIgnored.size > 1) {
  5561. continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  5562. }
  5563. mfyContinuationIgnored.forEach((value, key) => {
  5564. if (key !== lztContinuation) {
  5565. mfyContinuationIgnored.delete(key);
  5566. continuationLog(key, 'previous continuation removed from ignored store', key);
  5567. }
  5568. });
  5569.  
  5570. }
  5571. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  5572. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  5573. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  5574.  
  5575. // console.log(8003)
  5576. try {
  5577.  
  5578.  
  5579. const { is, videoId, continuation } = extraArguments322(b, c, d);
  5580.  
  5581. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  5582. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  5583. }
  5584.  
  5585. if (pageSetupVideoId && videoId && continuation) {
  5586. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  5587. mfyContinuationIgnored.removeAdd(continuation);
  5588. mfvContinuationRecorded.delete(continuation);
  5589. return;
  5590. }
  5591. }
  5592.  
  5593. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  5594. copyPreviousContiuationToIgnored374(false);
  5595. mfyContinuationIgnored.delete(continuation);
  5596. mfvContinuationRecorded.removeAdd(continuation);
  5597. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  5598. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  5599. mjtLockPreviousKey = '';
  5600. }
  5601.  
  5602. // if (mjtNextMainKey === continuation) {
  5603. // copyPreviousContiuationToIgnored(false);
  5604. // mfyContinuationIgnored.delete(continuation);
  5605. // mfvContinuationRecorded.add(continuation);
  5606. // }
  5607.  
  5608. const lztContinuation = continuation;
  5609.  
  5610. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  5611. if (mfyContinuationIgnored.has(lztContinuation)) {
  5612. continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  5613. return;
  5614. }
  5615. }
  5616.  
  5617. // if (videoId) {
  5618. // if (!pageSetupVideoId) return; // ignore page not ready
  5619. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  5620. // if (videoId !== pageSetupVideoId) {
  5621. // return;
  5622. // }
  5623. // }
  5624.  
  5625. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  5626. mtzlastAllowedContinuation = lztContinuation;
  5627. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  5628.  
  5629. continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  5630. mjtRecordedPrevKey = lztContinuation;
  5631. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  5632. // if (mfyContinuationIgnored.size > 0) {
  5633. // delayClearOtherKeys(lztContinuation);
  5634. // }
  5635. mtzCount = 0;
  5636. // allowNoDelay322 = false;
  5637. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  5638. // repeated
  5639. if (mtzCount > 1e9) mtzCount = 1e4;
  5640. ++mtzCount;
  5641. continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  5642.  
  5643. // if (mtzCount >= 3) allowNoDelay322 = true;
  5644. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  5645. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  5646. }
  5647. if (mtzCount === 5) {
  5648. mfvContinuationRecorded.clear();
  5649. mfvContinuationRecorded.add(lztContinuation);
  5650. }
  5651.  
  5652. }
  5653.  
  5654. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId) ) {
  5655. mpKey22 = lztContinuation;
  5656. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  5657. }
  5658.  
  5659. if (mbCId322) {
  5660. clearTimeout(mbCId322);
  5661. mbCId322 = 0;
  5662. }
  5663. } catch (e) {
  5664. console.log('Coding Error in getCancellableNetworkPromise_', e)
  5665. }
  5666.  
  5667. // console.log(8004)
  5668. // console.log(123403, arguments);
  5669. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  5670.  
  5671. // console.log(5163, a?.is,b,c,d,e);
  5672. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  5673. }
  5674. }
  5675. });
  5676.  
  5677. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  5678.  
  5679.  
  5680. FIX_ytdExpander_childrenChanged && customElements.whenDefined('ytd-expander').then(() => {
  5681.  
  5682. let dummy;
  5683. let cProto;
  5684.  
  5685. dummy = document.createElement('ytd-expander');
  5686. cProto = insp(dummy).constructor.prototype;
  5687.  
  5688. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  5689.  
  5690. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  5691. cProto.childrenChanged14 = cProto.childrenChanged;
  5692.  
  5693. cProto.initChildrenObserver = function () {
  5694. var a = this;
  5695. this.observer = new MutationObserver(function () {
  5696. a.childrenChanged()
  5697. }
  5698. );
  5699. this.observer.observe(this.content, {
  5700. subtree: !0,
  5701. childList: !0,
  5702. attributes: !0,
  5703. characterData: !0
  5704. });
  5705. this.childrenChanged()
  5706. }
  5707. ;
  5708. cProto.childrenChanged = function () {
  5709. if (this.alwaysToggleable) {
  5710. this.canToggle = this.alwaysToggleable;
  5711. } else if (!this.canToggleJobId) {
  5712. this.canToggleJobId = 1;
  5713. getRafPromise().then(() => {
  5714. this.canToggleJobId = 0;
  5715. this.calculateCanCollapse()
  5716. })
  5717. }
  5718. }
  5719.  
  5720. // console.log(cProto.initChildrenObserver)
  5721. console.debug('ytd-expander-fix-childrenChanged');
  5722.  
  5723. }
  5724.  
  5725. });
  5726.  
  5727.  
  5728. FIX_paper_ripple_animate && customElements.whenDefined('paper-ripple').then(() => {
  5729.  
  5730. let dummy;
  5731. let cProto;
  5732. dummy = document.createElement('paper-ripple');
  5733. cProto = insp(dummy).constructor.prototype;
  5734.  
  5735. if (fnIntegrity(cProto.animate, '0.74.5')) {
  5736.  
  5737.  
  5738. cProto.animate34 = cProto.animate;
  5739. cProto.animate = function () {
  5740. if (this._animating) {
  5741. var a;
  5742. const ripples = this.ripples;
  5743. for (a = 0; a < ripples.length; ++a) {
  5744. var b = ripples[a];
  5745. b.draw();
  5746. this.$.background.style.opacity = b.outerOpacity;
  5747. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  5748. }
  5749. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  5750. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  5751. getRafPromise().then(this._boundAnimate38);
  5752. } else {
  5753. this.onAnimationComplete()
  5754. }
  5755. }
  5756. }
  5757.  
  5758. console.debug('FIX_paper_ripple_animate')
  5759.  
  5760. // console.log(cProto.animate)
  5761.  
  5762. }
  5763.  
  5764. });
  5765.  
  5766. if (FIX_doIdomRender) {
  5767.  
  5768.  
  5769. const xsetTimeout = function (f, d) {
  5770. if (xsetTimeout.m511 === 1 && !d) {
  5771. xsetTimeout.m511 = 2;
  5772. getRafPromise().then(f);
  5773. } else {
  5774. return setTimeout.apply(window, arguments)
  5775. }
  5776.  
  5777. }
  5778.  
  5779. const xrequestAnimationFrame = function (f) {
  5780. const h = f + "";
  5781. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  5782. xsetTimeout.m511 = 1;
  5783. f();
  5784. xsetTimeout.m511 = 0;
  5785. } else if (h.includes("requestAninmationFrameResolver")) {
  5786. getRafPromise().then(f);
  5787. } else {
  5788. return requestAnimationFrame.apply(window, arguments);
  5789. }
  5790. }
  5791.  
  5792. let busy = false;
  5793. const doIdomRender = function () {
  5794. if (busy) {
  5795. return this.doIdomRender13.apply(this, arguments);
  5796. }
  5797. busy = true;
  5798. const { requestAnimationFrame, setTimeout } = window;
  5799. window.requestAnimationFrame = xrequestAnimationFrame;
  5800. window.setTimeout = xsetTimeout;
  5801. let r = this.doIdomRender13.apply(this, arguments);
  5802. window.requestAnimationFrame = requestAnimationFrame;
  5803. window.setTimeout = setTimeout;
  5804. busy = false;
  5805. return r;
  5806. };
  5807. for (const ytTag of ['ytd-lottie-player', 'yt-attributed-string', 'yt-image', 'yt-icon-shape', 'yt-button-shape', 'yt-button-view-model', 'yt-icon-badge-shape']) {
  5808.  
  5809.  
  5810. customElements.whenDefined(ytTag).then(() => {
  5811.  
  5812. let dummy;
  5813. let cProto;
  5814. dummy = document.createElement(ytTag);
  5815. cProto = insp(dummy).constructor.prototype;
  5816.  
  5817. cProto.doIdomRender13 = cProto.doIdomRender;
  5818. cProto.doIdomRender = doIdomRender;
  5819.  
  5820. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  5821.  
  5822. console.debug('FIX_doIdomRender', ytTag)
  5823.  
  5824.  
  5825.  
  5826. });
  5827.  
  5828. }
  5829.  
  5830. }
  5831.  
  5832.  
  5833.  
  5834. });
  5835.  
  5836. });
  5837.  
  5838.  
  5839. setupEvents();
  5840.  
  5841.  
  5842.  
  5843. if (isMainWindow) {
  5844.  
  5845. console.groupCollapsed(
  5846. "%cYouTube JS Engine Tamer",
  5847. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  5848. );
  5849.  
  5850.  
  5851.  
  5852. console.log("Script is loaded.");
  5853. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  5854.  
  5855. console.log("This script is experimental and subject to further changes.");
  5856.  
  5857. console.log("This might boost your YouTube performance.");
  5858.  
  5859. console.log("CAUTION: This might break your YouTube.");
  5860.  
  5861.  
  5862. if (prepareLogs.length >= 1) {
  5863. console.log(" =========================================================================== ");
  5864.  
  5865. for (const msg of prepareLogs) {
  5866. console.log(msg)
  5867. }
  5868.  
  5869. console.log(" =========================================================================== ");
  5870. }
  5871.  
  5872. console.groupEnd();
  5873.  
  5874. }
  5875.  
  5876.  
  5877.  
  5878. })();