YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

As of 09.12.2023. See ბოლო ვერსია.

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.6.44
  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. // @run-at document-start
  12. // @unwrap
  13. // @inject-into page
  14. // @allFrames true
  15. // ==/UserScript==
  16.  
  17. (() => {
  18.  
  19. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  20. const FIX_schedulerInstanceInstance_V1 = false;
  21. const FIX_schedulerInstanceInstance_V2 = true;
  22. const FIX_yt_player = true;
  23. const FIX_Animation_n_timeline = true;
  24. const NO_PRELOAD_GENERATE_204 = false;
  25. const CHANGE_appendChild = true;
  26.  
  27. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  28. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  29. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  30.  
  31. const FIX_Iframe_NULL_SRC = true;
  32.  
  33. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  34.  
  35. const FIX_ytdExpander_childrenChanged = true;
  36. const FIX_paper_ripple_animate = true;
  37.  
  38. const FIX_doIdomRender = true;
  39.  
  40. const FIX_Shady = true;
  41.  
  42. const FIX_ytAction_ = true; // ytd-app
  43. const FIX_onVideoDataChange = false;
  44. // const FIX_onClick = true;
  45. const FIX_onStateChange = true;
  46. const FIX_onLoopRangeChange = true;
  47. const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  48. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  49.  
  50. const ENABLE_discreteTasking = true;
  51.  
  52. const FIX_perfNow = true;
  53.  
  54. const UNLOAD_DETACHED_POLYMER = true;
  55.  
  56. const WEAK_REF_BINDING = true; // false if your browser is slow
  57. // << if WEAK_REF_BINDING >>
  58. const WEAK_REF_PROXY_DOLLAR = true; // false if your browser is slow
  59. // << end >>
  60.  
  61.  
  62.  
  63. /*
  64. window.addEventListener('edm',()=>{
  65. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  66. });
  67.  
  68. window.addEventListener('edn',()=>{
  69. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  70. });
  71. window.addEventListener('edr',()=>{
  72. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  73. });
  74. */
  75.  
  76.  
  77. const win = this instanceof Window ? this : window;
  78.  
  79. // Create a unique key for the script and check if it is already running
  80. const hkey_script = 'jswylcojvzts';
  81. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  82. win[hkey_script] = true;
  83.  
  84.  
  85.  
  86.  
  87. let p59 = 0;
  88.  
  89. const Promise = (async () => { })().constructor;
  90.  
  91. const PromiseExternal = ((resolve_, reject_) => {
  92. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  93. return class PromiseExternal extends Promise {
  94. constructor(cb = h) {
  95. super(cb);
  96. if (cb === h) {
  97. /** @type {(value: any) => void} */
  98. this.resolve = resolve_;
  99. /** @type {(reason?: any) => void} */
  100. this.reject = reject_;
  101. }
  102. }
  103. };
  104. })();
  105.  
  106.  
  107. let pf31 = new PromiseExternal();
  108.  
  109. // native RAF
  110. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  111.  
  112. // 1st wrapped RAF
  113. const baseRAF = (callback) => {
  114. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  115. pf31.then(() => {
  116. callback(hRes);
  117. });
  118. });
  119. };
  120.  
  121. // 2nd wrapped RAF
  122. window.requestAnimationFrame = baseRAF;
  123.  
  124. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  125. const indr = o => insp(o).$ || o.$ || 0;
  126.  
  127. FIX_perfNow && (() => {
  128. let nowh = -1;
  129. const dtl = new DocumentTimeline();
  130. performance.now = performance.now16 = function () {
  131.  
  132. /**
  133. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  134. *
  135. * If consecutive session history entries had history.state.entryTime set to same value,
  136. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  137. * and modifying its return value slightly to make sure two close consecutive calls don't
  138. * get the same result helped with resolving the issue.
  139. */
  140.  
  141. let t = nowh;
  142. let c = dtl.currentTime;
  143. return (nowh = (t + 1e-7 > c ? t + 1e-5 : c));
  144. }
  145. if (performance.now !== performance.now16) { // might not able to set in Firefox
  146. if (performance.now() === performance.now()) console.warn('performance.now() is not mono increasing.');
  147. }
  148. })();
  149.  
  150.  
  151.  
  152. const qm47 = Symbol();
  153. const qm57 = Symbol();
  154. const qm53 = Symbol();
  155. const qn53 = Symbol();
  156.  
  157.  
  158. const ump3 = new WeakMap();
  159.  
  160. const stp = document.createElement('noscript');
  161. stp.id = 'weakref-placeholder'
  162.  
  163.  
  164. const setupD = typeof WeakRef !== 'undefined' ? (elm, s, usePlaceholder) => {
  165.  
  166. const z = `${s}72`;
  167.  
  168. if (s in elm) {
  169. // console.log(1162, elm[s], elm)
  170.  
  171. const p = elm[s];
  172.  
  173. delete elm[s];
  174.  
  175. Object.defineProperty(elm, s, {
  176. get() {
  177. const elm = this;
  178. const wr = elm[z];
  179. if (!wr) return null;
  180. const m = wr.deref();
  181. if (!m && usePlaceholder) {
  182. if (typeof usePlaceholder === 'function') usePlaceholder(elm);
  183. return stp;
  184. }
  185. return m;
  186. },
  187. set(nv) {
  188. const elm = this;
  189. elm[z] = nv ? new WeakRef(nv) : null;
  190. return true;
  191. },
  192. configurable: true,
  193. enumerable: true
  194.  
  195. });
  196.  
  197. elm[s] = p;
  198. elm = null;
  199.  
  200.  
  201. }
  202. } : null;
  203.  
  204. const mxMap = new WeakMap();
  205.  
  206. const myMap = new WeakSet();
  207.  
  208. const setup$ = typeof WeakRef !== 'undefined' ? function (dh) {
  209.  
  210. const $ = dh.$;
  211. // const elements_ = dh.elements_;
  212.  
  213. // setupD(dh, '$');
  214.  
  215.  
  216. if (WEAK_REF_PROXY_DOLLAR && $ && typeof $ === 'object' && !dh.$ky37) {
  217.  
  218. dh.$ky37 = 1;
  219.  
  220. if (!myMap.has($)) {
  221.  
  222.  
  223.  
  224.  
  225. for (const k of Object.keys($)) {
  226.  
  227. const v = $[k];
  228. if ($[k] instanceof Node) {
  229.  
  230. $[k] = new WeakRef($[k]);
  231.  
  232. }
  233.  
  234. }
  235.  
  236.  
  237.  
  238. dh.$ = mxMap.get($) || new Proxy($, {
  239. get(obj, prop) {
  240. const val = obj[prop];
  241. if (typeof (val || 0).deref === 'function') {
  242. return val.deref();
  243. }
  244. return val;
  245. },
  246. set(obj, prop, val) {
  247. if (val instanceof Node) {
  248. obj[prop] = new WeakRef(val);
  249. } else {
  250. obj[prop] = val;
  251. }
  252. return true;
  253. }
  254. });
  255.  
  256. mxMap.set($, dh.$);
  257. myMap.add(dh.$);
  258.  
  259. }
  260.  
  261.  
  262.  
  263.  
  264. }
  265.  
  266.  
  267.  
  268.  
  269. // if (WEAK_REF_PROXY_DOLLAR && elements_ && typeof elements_ === 'object' && !dh.$ky38) {
  270.  
  271. // dh.$ky38 = 1;
  272.  
  273. // if (!myMap.has(elements_)) {
  274.  
  275.  
  276.  
  277.  
  278. // for (const k of Object.keys(elements_)) {
  279.  
  280. // const v = elements_[k];
  281. // if (elements_[k] instanceof Node) {
  282.  
  283. // elements_[k] = new WeakRef(elements_[k]);
  284.  
  285. // }
  286.  
  287. // }
  288.  
  289. // /*
  290.  
  291.  
  292.  
  293. // dh.elements_ = mxMap.get(elements_) || new Proxy(elements_, {
  294. // get(obj, prop) {
  295. // const val = obj[prop];
  296. // if (typeof (val || 0).deref === 'function') {
  297. // return val.deref();
  298. // }
  299. // return val;
  300. // },
  301. // set(obj, prop, val) {
  302. // if (val instanceof Node) {
  303. // obj[prop] = new WeakRef(val);
  304. // } else {
  305. // obj[prop] = val;
  306. // }
  307. // return true;
  308. // }
  309. // });
  310.  
  311. // console.log(dh, dh.elements_, elements_)
  312.  
  313. // mxMap.set(elements_, dh.elements_);
  314. // myMap.add(dh.elements_);
  315.  
  316. // */
  317. // }
  318.  
  319.  
  320.  
  321.  
  322. // }
  323.  
  324.  
  325.  
  326.  
  327.  
  328. } : null;
  329.  
  330.  
  331. const configureVisibilityObserverT_ = function () {
  332. const hostElement = this.hostElement;
  333. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  334. this.unobserve_();
  335. } else {
  336. return this.configureVisibilityObserver27_();
  337. }
  338. };
  339. const getParentRendererT = function () {
  340. const hostElement = this.hostElement;
  341. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  342. return null;
  343. } else {
  344. return this.getParentRenderer27();
  345. }
  346. }
  347. const readyT = function () {
  348. const hostElement = this.hostElement;
  349. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  350. return void 0;
  351. } else {
  352. return this.ready27();
  353. }
  354. }
  355. const _enablePropertiesT = function () {
  356. const hostElement = this.hostElement;
  357. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  358. if (this.__dataEnabled === true) this.__dataEnabled = false;
  359. }
  360. return this._enableProperties27();
  361. }
  362.  
  363. const attachedT = function () {
  364. const hostElement = this.hostElement;
  365. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  366. if (this.isAttached === true) this.isAttached = false;
  367. return void 0;
  368. } else {
  369. return this.attached27();
  370. }
  371. }
  372.  
  373. const hostElementCleanUp = (dh) => {
  374. if (typeof dh.dispose === 'function') {
  375. try {
  376. if (dh.visibilityMonitor || dh.visibilityObserver) {
  377. dh.dispose();
  378. dh.visibilityMonitor = null;
  379. dh.visibilityObserver = null;
  380. }
  381. } catch (e) { }
  382. }
  383. if (typeof dh.detached === 'function') {
  384. try {
  385. if (dh.visibilityObserverForChild_ || dh.localVisibilityObserver_) {
  386. dh.detached();
  387. dh.visibilityObserverForChild_ = null;
  388. dh.localVisibilityObserver_ = null;
  389. }
  390. } catch (e) { }
  391. }
  392. if (dh.__dataEnabled === true) {
  393. dh.__dataEnabled = false;
  394. }
  395. };
  396. const setupDataHost = setupD && setup$ ? function (dh) {
  397.  
  398. if (dh && typeof dh === 'object') {
  399.  
  400. if (typeof dh.configureVisibilityObserver_ === 'function' && !dh.configureVisibilityObserver27_) {
  401. dh.configureVisibilityObserver27_ = dh.configureVisibilityObserver_;
  402. dh.configureVisibilityObserver_ = configureVisibilityObserverT_;
  403. }
  404.  
  405. if (typeof dh.getParentRenderer === 'function' && !dh.getParentRenderer27) {
  406. dh.getParentRenderer27 = dh.getParentRenderer;
  407. dh.getParentRenderer = getParentRendererT;
  408. }
  409.  
  410. if (typeof dh.ready === 'function' && !dh.ready27) {
  411. dh.ready27 = dh.ready;
  412. dh.ready = readyT;
  413. }
  414.  
  415. if (typeof dh._enableProperties === 'function' && !dh._enableProperties27) {
  416. dh._enableProperties27 = dh._enableProperties;
  417. dh._enableProperties = _enablePropertiesT;
  418. }
  419.  
  420. if (typeof dh.attached === 'function' && !dh.attached27) {
  421. dh.attached27 = dh.attached;
  422. dh.attached = attachedT;
  423. }
  424.  
  425. setupD(dh, 'hostElement', hostElementCleanUp);
  426. setupD(dh, 'parentComponent');
  427. setupD(dh, 'localVisibilityObserver_');
  428. setupD(dh, 'cachedProviderNode_');
  429.  
  430. setupD(dh, '__template');
  431. setupD(dh, '__templatizeOwner');
  432. setupD(dh, '__templateInfo');
  433.  
  434. setupD(dh, 'root', 1);
  435. const elements_ = dh.elements_;
  436. if (elements_ && typeof elements_ === 'object' && Object.keys(elements_).length > 0) setupD(dh, 'elements_');
  437.  
  438.  
  439.  
  440. setup$(dh);
  441.  
  442. }
  443.  
  444. } : null;
  445.  
  446.  
  447. let delay300 = null;
  448.  
  449. if (UNLOAD_DETACHED_POLYMER || WEAK_REF_BINDING) {
  450. delay300 = new PromiseExternal();
  451. setInterval(() => {
  452. delay300.resolve();
  453. delay300 = new PromiseExternal();
  454. }, 300);
  455. }
  456.  
  457. const aDelay = async function () {
  458. await delay300.then();
  459. await delay300.then();
  460. }
  461.  
  462. const setupDiscreteTasks = (h, rb) => {
  463.  
  464. if (rb) {
  465. if (h.ky36) return;
  466. }
  467.  
  468.  
  469. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  470. const f = h.onYtRendererstamperFinished;
  471. const g = ump3.get(f) || function () {
  472. if (this.updateChildVisibilityProperties && !this.markDirty) {
  473. return f.apply(this, arguments);
  474. }
  475. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  476. }
  477. ump3.set(f, g);
  478. g.km34 = 1;
  479. h.onYtRendererstamperFinished = g;
  480.  
  481. }
  482.  
  483.  
  484.  
  485.  
  486. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  487. const f = h.onYtUpdateDescriptionAction;
  488. const g = ump3.get(f) || function (a) {
  489. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  490. }
  491. ump3.set(f, g);
  492. g.km34 = 1;
  493. h.onYtUpdateDescriptionAction = g;
  494.  
  495. }
  496.  
  497.  
  498.  
  499. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  500. const f = h.handleUpdateDescriptionAction;
  501. const g = ump3.get(f) || function (a) {
  502. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  503. }
  504. ump3.set(f, g);
  505. g.km34 = 1;
  506. h.handleUpdateDescriptionAction = g;
  507.  
  508. }
  509.  
  510. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  511. const f = h.handleUpdateLiveChatPollAction;
  512. const g = ump3.get(f) || function (a) {
  513. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  514. }
  515. ump3.set(f, g);
  516. g.km34 = 1;
  517. h.handleUpdateLiveChatPollAction = g;
  518.  
  519. }
  520.  
  521.  
  522.  
  523. /*
  524.  
  525.  
  526. if (typeof h.onYtAction_ === 'function' && !(h.onYtAction_.km34)) {
  527. const f = h.onYtAction_;
  528. const g = ump3.get(f) || function (a) {
  529. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  530. }
  531. ump3.set(f, g);
  532. g.km34 = 1;
  533. h.onYtAction_ = g;
  534.  
  535. }
  536.  
  537. */
  538.  
  539.  
  540.  
  541. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  542. const f = h.onTextChanged;
  543. const g = ump3.get(f) || function () {
  544. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  545. }
  546. ump3.set(f, g);
  547. g.km34 = 1;
  548. h.onTextChanged = g;
  549.  
  550. }
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  558. const f = h.onVideoDataChange;
  559. const g = ump3.get(f) || function (a) {
  560. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  561. }
  562. ump3.set(f, g);
  563. g.km34 = 1;
  564. h.onVideoDataChange = g;
  565.  
  566. }
  567.  
  568.  
  569.  
  570.  
  571.  
  572. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  573. const f = h.onVideoDataChange_;
  574. const g = ump3.get(f) || function () {
  575. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  576. }
  577. ump3.set(f, g);
  578. g.km34 = 1;
  579. h.onVideoDataChange_ = g;
  580.  
  581. }
  582.  
  583.  
  584.  
  585.  
  586. if (typeof h.addTooltips === 'function' && !(h.addTooltips.km34)) {
  587.  
  588. const f = h.addTooltips;
  589. const g = ump3.get(f) || function () {
  590. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  591. }
  592. ump3.set(f, g);
  593. g.km34 = 1;
  594. h.addTooltips = g;
  595.  
  596. }
  597.  
  598.  
  599.  
  600.  
  601. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  602.  
  603. const f = h.addTooltips_;
  604. const g = ump3.get(f) || function () {
  605. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  606. }
  607. ump3.set(f, g);
  608. g.km34 = 1;
  609. h.addTooltips_ = g;
  610.  
  611. }
  612.  
  613.  
  614.  
  615. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  616.  
  617. const f = h.updateRenderedElements;
  618. const g = ump3.get(f) || function () {
  619. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  620. }
  621. ump3.set(f, g);
  622. g.km34 = 1;
  623. h.updateRenderedElements = g;
  624.  
  625. }
  626.  
  627.  
  628.  
  629.  
  630. /*
  631. // buggy for yt-player-updated
  632. if (typeof h.startLoadingWatch === 'function' && !(h.startLoadingWatch.km34)) {
  633.  
  634. const f = h.startLoadingWatch;
  635. const g = ump3.get(f) || function () {
  636. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  637. }
  638. ump3.set(f, g);
  639. g.km34 = 1;
  640. h.startLoadingWatch = g;
  641.  
  642. }
  643. */
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657. if (typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  658. const f = h.loadPage_;
  659. const g = ump3.get(f) || function (a) {
  660. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  661. }
  662. ump3.set(f, g);
  663. g.km34 = 1;
  664. h.loadPage_ = g;
  665.  
  666. }
  667. if (typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  668. const f = h.updatePageData_;
  669. const g = ump3.get(f) || function (a) {
  670. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  671. }
  672. ump3.set(f, g);
  673. g.km34 = 1;
  674. h.updatePageData_ = g;
  675.  
  676. }
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686. if (typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  687.  
  688. const f = h.onFocus_;
  689. const g = ump3.get(f) || function () {
  690. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  691. }
  692. ump3.set(f, g);
  693. g.km34 = 1;
  694. h.onFocus_ = g;
  695.  
  696. }
  697.  
  698. if (typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  699.  
  700. const f = h.onBlur_;
  701. const g = ump3.get(f) || function () {
  702. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  703. }
  704. ump3.set(f, g);
  705. g.km34 = 1;
  706. h.onBlur_ = g;
  707.  
  708. }
  709.  
  710.  
  711. if (typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  712.  
  713. const f = h.buttonClassChanged_;
  714. const g = ump3.get(f) || function (a, b) {
  715. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  716. }
  717. ump3.set(f, g);
  718. g.km34 = 1;
  719. h.buttonClassChanged_ = g;
  720.  
  721. }
  722.  
  723.  
  724. if (typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  725.  
  726. const f = h.buttonIconChanged_;
  727. const g = ump3.get(f) || function (a) {
  728. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  729. }
  730. ump3.set(f, g);
  731. g.km34 = 1;
  732. h.buttonIconChanged_ = g;
  733.  
  734. }
  735.  
  736.  
  737. if (typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  738.  
  739. const f = h.dataChangedInBehavior_;
  740. const g = ump3.get(f) || function () {
  741. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  742. }
  743. ump3.set(f, g);
  744. g.km34 = 1;
  745. h.dataChangedInBehavior_ = g;
  746.  
  747. }
  748.  
  749.  
  750.  
  751.  
  752.  
  753. if (typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  754.  
  755. const f = h.continuationsChanged_;
  756. const g = ump3.get(f) || function () {
  757. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  758. }
  759. ump3.set(f, g);
  760. g.km34 = 1;
  761. h.continuationsChanged_ = g;
  762.  
  763. }
  764.  
  765.  
  766. if (typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  767.  
  768. const f = h.forceChatPoll_;
  769. const g = ump3.get(f) || function (a) {
  770. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  771. }
  772. ump3.set(f, g);
  773. g.km34 = 1;
  774. h.forceChatPoll_ = g;
  775.  
  776. }
  777.  
  778.  
  779.  
  780. if (typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  781.  
  782. const f = h.onEndpointClick_;
  783. const g = ump3.get(f) || function (a) {
  784. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  785. }
  786. ump3.set(f, g);
  787. g.km34 = 1;
  788. h.onEndpointClick_ = g;
  789.  
  790. }
  791.  
  792.  
  793. if (typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  794.  
  795. const f = h.onEndpointTap_;
  796. const g = ump3.get(f) || function (a) {
  797. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  798. }
  799. ump3.set(f, g);
  800. g.km34 = 1;
  801. h.onEndpointTap_ = g;
  802.  
  803. }
  804.  
  805.  
  806. if (typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  807.  
  808. const f = h.handleClick_;
  809. const g = ump3.get(f) || function (a, b) {
  810. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  811. }
  812. ump3.set(f, g);
  813. g.km34 = 1;
  814. h.handleClick_ = g;
  815.  
  816. }
  817.  
  818.  
  819.  
  820. // return;
  821.  
  822.  
  823.  
  824. if (typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  825.  
  826. const f = h.onReadyStateChange_;
  827. const g = ump3.get(f) || function () {
  828. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  829. }
  830. ump3.set(f, g);
  831. g.km34 = 1;
  832. h.onReadyStateChange_ = g;
  833.  
  834. }
  835.  
  836. if (typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  837.  
  838. const f = h.onReadyStateChangeEntryPoint_;
  839. const g = ump3.get(f) || function () {
  840. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  841. }
  842. ump3.set(f, g);
  843. g.km34 = 1;
  844. h.onReadyStateChangeEntryPoint_ = g;
  845.  
  846. }
  847.  
  848.  
  849. if (typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  850.  
  851. const f = h.readyStateChangeHandler_;
  852. const g = ump3.get(f) || function (a) {
  853. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  854. }
  855. ump3.set(f, g);
  856. g.km34 = 1;
  857. h.readyStateChangeHandler_ = g;
  858.  
  859. }
  860.  
  861.  
  862.  
  863.  
  864. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  865.  
  866. const f = h.xmlHttpHandler_;
  867. const g = ump3.get(f) || function (a) {
  868. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  869. }
  870. ump3.set(f, g);
  871. g.km34 = 1;
  872. h.xmlHttpHandler_ = g;
  873.  
  874. }
  875.  
  876.  
  877. if (typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  878.  
  879. const f = h.executeCallbacks_; // overloaded
  880. const g = ump3.get(f) || function (a) {
  881. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  882. }
  883. ump3.set(f, g);
  884. g.km34 = 1;
  885. h.executeCallbacks_ = g;
  886.  
  887. }
  888.  
  889.  
  890.  
  891. if (typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  892.  
  893. const f = h.handleInvalidationData_;
  894. const g = ump3.get(f) || function (a, b) {
  895. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  896. }
  897. ump3.set(f, g);
  898. g.km34 = 1;
  899. h.handleInvalidationData_ = g;
  900.  
  901. }
  902.  
  903. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  904.  
  905. const f = h.onInput_;
  906. const g = ump3.get(f) || function () {
  907. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  908. }
  909. ump3.set(f, g);
  910. g.km34 = 1;
  911. h.onInput_ = g;
  912.  
  913. }
  914.  
  915.  
  916. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  917.  
  918. const f = h.trigger_;
  919. const g = ump3.get(f) || function (a) {
  920. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  921. }
  922. ump3.set(f, g);
  923. g.km34 = 1;
  924. h.trigger_ = g;
  925.  
  926. }
  927.  
  928.  
  929. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  930.  
  931. const f = h.requestData_;
  932. const g = ump3.get(f) || function (a) {
  933. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  934. }
  935. ump3.set(f, g);
  936. g.km34 = 1;
  937. h.requestData_ = g;
  938.  
  939. }
  940.  
  941. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  942.  
  943. const f = h.onLoadReloadContinuation_;
  944. const g = ump3.get(f) || function (a, b) {
  945. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  946. }
  947. ump3.set(f, g);
  948. g.km34 = 1;
  949. h.onLoadReloadContinuation_ = g;
  950.  
  951. }
  952.  
  953.  
  954.  
  955. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  956.  
  957. const f = h.onLoadIncrementalContinuation_;
  958. const g = ump3.get(f) || function (a, b) {
  959. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  960. }
  961. ump3.set(f, g);
  962. g.km34 = 1;
  963. h.onLoadIncrementalContinuation_ = g;
  964.  
  965. }
  966.  
  967. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  968.  
  969. const f = h.onLoadSeekContinuation_;
  970. const g = ump3.get(f) || function (a, b) {
  971. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  972. }
  973. ump3.set(f, g);
  974. g.km34 = 1;
  975. h.onLoadSeekContinuation_ = g;
  976.  
  977. }
  978. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  979.  
  980. const f = h.onLoadReplayContinuation_;
  981. const g = ump3.get(f) || function (a, b) {
  982. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  983. }
  984. ump3.set(f, g);
  985. g.km34 = 1;
  986. h.onLoadReplayContinuation_ = g;
  987.  
  988. }
  989. if (typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  990.  
  991. const f = h.onNavigate_;
  992. const g = ump3.get(f) || function (a) {
  993. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  994. }
  995. ump3.set(f, g);
  996. g.km34 = 1;
  997. h.onNavigate_ = g;
  998.  
  999. }
  1000.  
  1001. /*
  1002. if(typeof h.deferRenderStamperBinding_ ==='function' && !(h.deferRenderStamperBinding_.km34)){
  1003.  
  1004. const f = h.deferRenderStamperBinding_;
  1005. const g = function(){
  1006. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1007. }
  1008. g.km34 = 1;
  1009. h.deferRenderStamperBinding_ = g;
  1010.  
  1011. }
  1012. */
  1013.  
  1014.  
  1015.  
  1016. if (typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  1017.  
  1018. const f = h.ytRendererBehaviorDataObserver_;
  1019. const g = ump3.get(f) || function () {
  1020. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1021. }
  1022. ump3.set(f, g);
  1023. g.km34 = 1;
  1024. h.ytRendererBehaviorDataObserver_ = g;
  1025.  
  1026. }
  1027.  
  1028. if (typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  1029.  
  1030. const f = h.ytRendererBehaviorTargetIdObserver_;
  1031. const g = ump3.get(f) || function () {
  1032. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1033. }
  1034. ump3.set(f, g);
  1035. g.km34 = 1;
  1036. h.ytRendererBehaviorTargetIdObserver_ = g;
  1037.  
  1038. }
  1039.  
  1040. if (typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  1041.  
  1042. const f = h.unregisterRenderer_;
  1043. const g = ump3.get(f) || function (a) {
  1044. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1045. }
  1046. ump3.set(f, g);
  1047. g.km34 = 1;
  1048. h.unregisterRenderer_ = g;
  1049.  
  1050. }
  1051.  
  1052.  
  1053.  
  1054. if (typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  1055.  
  1056. const f = h.textChanged_;
  1057. const g = ump3.get(f) || function (a) {
  1058. if (void 0 !== this.isAttached) {
  1059. const hostElement = this.hostElement;
  1060. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  1061. return;
  1062. }
  1063. }
  1064. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1065. }
  1066. ump3.set(f, g);
  1067. g.km34 = 1;
  1068. h.textChanged_ = g;
  1069.  
  1070. }
  1071.  
  1072.  
  1073.  
  1074.  
  1075. /*
  1076. if(typeof h.stampDomArray_ ==='function' && !(h.stampDomArray_.km34)){
  1077.  
  1078. if( h.stampDomArray_.length === 6){
  1079.  
  1080. const f = h.stampDomArray_;
  1081. const g = function(a,b,c,d,e,h){
  1082. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1083. }
  1084. g.km34 = 1;
  1085. h.stampDomArray_ = g;
  1086.  
  1087. }else{
  1088.  
  1089.  
  1090.  
  1091. const f = h.stampDomArray_;
  1092. const g = function(){
  1093. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1094. }
  1095. g.km34 = 1;
  1096. h.stampDomArray_ = g;
  1097. }
  1098.  
  1099.  
  1100. }
  1101. */
  1102.  
  1103. /*
  1104. if(typeof h.stampDomArraySplices_ ==='function' && !(h.stampDomArraySplices_.km34)){
  1105.  
  1106. if(h.stampDomArraySplices_.length === 3){
  1107.  
  1108.  
  1109.  
  1110. const f = h.stampDomArraySplices_;
  1111. const g = function(a,b,c){
  1112. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1113. }
  1114. g.km34 = 1;
  1115. h.stampDomArraySplices_ = g;
  1116.  
  1117.  
  1118. }else{
  1119.  
  1120.  
  1121.  
  1122. const f = h.stampDomArraySplices_;
  1123. const g = function(){
  1124. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  1125. }
  1126. g.km34 = 1;
  1127. h.stampDomArraySplices_ = g;
  1128.  
  1129.  
  1130. }
  1131.  
  1132. }
  1133. */
  1134.  
  1135.  
  1136.  
  1137.  
  1138. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  1139. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  1140. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  1141. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  1142. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  1143. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  1144.  
  1145.  
  1146.  
  1147. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  1148.  
  1149. const f = h.searchChanged_;
  1150. const g = ump3.get(f) || function () {
  1151. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1152. }
  1153. ump3.set(f, g);
  1154. g.km34 = 1;
  1155. h.searchChanged_ = g;
  1156.  
  1157. }
  1158.  
  1159. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  1160.  
  1161. const f = h.skinToneChanged_;
  1162. const g = ump3.get(f) || function (a) {
  1163. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1164. }
  1165. ump3.set(f, g);
  1166. g.km34 = 1;
  1167. h.skinToneChanged_ = g;
  1168.  
  1169. }
  1170.  
  1171. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  1172.  
  1173. const f = h.onEmojiHover_;
  1174. const g = ump3.get(f) || function (a) {
  1175. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1176. }
  1177. ump3.set(f, g);
  1178. g.km34 = 1;
  1179. h.onEmojiHover_ = g;
  1180.  
  1181. }
  1182.  
  1183. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  1184.  
  1185. const f = h.onSelectCategory_;
  1186. const g = ump3.get(f) || function (a) {
  1187. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1188. }
  1189. ump3.set(f, g);
  1190. g.km34 = 1;
  1191. h.onSelectCategory_ = g;
  1192.  
  1193. }
  1194.  
  1195. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  1196.  
  1197. const f = h.onShowEmojiVariantSelector;
  1198. const g = ump3.get(f) || function (a) {
  1199. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1200. }
  1201. ump3.set(f, g);
  1202. g.km34 = 1;
  1203. h.onShowEmojiVariantSelector = g;
  1204.  
  1205. }
  1206.  
  1207. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  1208.  
  1209. const f = h.updateCategoriesAndPlaceholder_;
  1210. const g = ump3.get(f) || function () {
  1211. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1212. }
  1213. ump3.set(f, g);
  1214. g.km34 = 1;
  1215. h.updateCategoriesAndPlaceholder_ = g;
  1216.  
  1217. }
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  1224.  
  1225. const f = h.watchPageActiveChanged_;
  1226. const g = ump3.get(f) || function () {
  1227. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1228. }
  1229. ump3.set(f, g);
  1230. g.km34 = 1;
  1231. h.watchPageActiveChanged_ = g;
  1232.  
  1233. }
  1234.  
  1235.  
  1236. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  1237.  
  1238. const f = h.activate_;
  1239. const g = ump3.get(f) || function () {
  1240. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1241. }
  1242. ump3.set(f, g);
  1243. g.km34 = 1;
  1244. h.activate_ = g;
  1245.  
  1246. }
  1247. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  1248.  
  1249. const f = h.onYtPlaylistDataUpdated_;
  1250. const g = ump3.get(f) || function () {
  1251. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1252. }
  1253. ump3.set(f, g);
  1254. g.km34 = 1;
  1255. h.onYtPlaylistDataUpdated_ = g;
  1256.  
  1257. }
  1258.  
  1259.  
  1260.  
  1261. /// -----------------------
  1262.  
  1263.  
  1264. const isMainRenderer = (h) => {
  1265.  
  1266. if (h.is && h.$ && h.__dataEnabled && h.__dataReady && h.__shady && h.__templateInfo && h.root && h.hostElement) {
  1267.  
  1268. const q = (h.parentComponent ? 1 : 0) | (h.ytComponentBehavior ? 2 : 0);
  1269. if (q === 3) {
  1270. // chat renderer
  1271. if (h.is.endsWith('-renderer')) {
  1272. return true;
  1273. }
  1274. } else if (q === 0) {
  1275. // custom lyrics engagement panel
  1276. if (h.is.endsWith('-renderer')) {
  1277. return true;
  1278. }
  1279. } else if (q === 1) {
  1280. // input renderer
  1281. if (h.is.endsWith('-renderer')) {
  1282. return true;
  1283. }
  1284. }
  1285.  
  1286. }
  1287.  
  1288. return false;
  1289. /*
  1290. return (h.is === 'yt-live-chat-renderer') ||
  1291. (h.is === 'yt-live-chat-item-list-renderer') ||
  1292. (h.is === 'yt-live-chat-text-input-field-renderer') ||
  1293. 0;
  1294. */
  1295. }
  1296.  
  1297.  
  1298.  
  1299. if (typeof h.rendererStamperApplyChangeRecord_ === 'function' && !(h.rendererStamperApplyChangeRecord_.km31)) {
  1300.  
  1301.  
  1302.  
  1303.  
  1304. const f = h.rendererStamperApplyChangeRecord_;
  1305. h.rendererStamperApplyChangeRecord31_ = f;
  1306. const g = ump3.get(f) || function (a, b, c) {
  1307. if (isMainRenderer(this) || (this.updateChildVisibilityProperties && !this.markDirty)) {
  1308. let b = false;
  1309. if (!this.markDirty) {
  1310. b = true;
  1311. } else if (!this.localVisibilityObserver_) {
  1312. // b = false
  1313. } else if (!this.visibilityObserverForChild_ && !!this.getVisibilityObserverForChild) {
  1314. b = true;
  1315. }
  1316. if (b) {
  1317. return f.apply(this, arguments);
  1318. }
  1319. }
  1320.  
  1321. // sequence on the same proto
  1322. this[qm47] = (this[qm47] || Promise.resolve()).then(() => this.rendererStamperApplyChangeRecord31_(a, b, c)).catch(console.log);
  1323. }
  1324. ump3.set(f, g);
  1325. g.km31 = 1;
  1326. h.rendererStamperApplyChangeRecord_ = g;
  1327.  
  1328.  
  1329. }
  1330.  
  1331.  
  1332.  
  1333.  
  1334. /*
  1335. if (typeof h.rendererStamperObserver_ === 'function' && !(h.rendererStamperObserver_.km34)) {
  1336.  
  1337. const f = h.rendererStamperObserver_;
  1338. const g = ump3.get(f) || function (a, b, c) {
  1339. if (isMainRenderer(this)) {
  1340. return f.apply(this, arguments);
  1341. }
  1342. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1343. }
  1344. ump3.set(f, g);
  1345. g.km34 = 1;
  1346. h.rendererStamperObserver_ = g;
  1347.  
  1348. }
  1349.  
  1350.  
  1351. if (typeof h.rendererStamperApplyChangeRecord_ === 'function' && !(h.rendererStamperApplyChangeRecord_.km34)) {
  1352.  
  1353. const f = h.rendererStamperApplyChangeRecord_;
  1354. const g = ump3.get(f) || function () {
  1355. if (isMainRenderer(this)) {
  1356. return f.apply(this, arguments);
  1357. }
  1358. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1359. }
  1360. ump3.set(f, g);
  1361. g.km34 = 1;
  1362. h.rendererStamperApplyChangeRecord_ = g;
  1363.  
  1364. }
  1365.  
  1366.  
  1367.  
  1368. if (typeof h.flushRenderStamperComponentBindings_ === 'function' && !(h.flushRenderStamperComponentBindings_.km34)) {
  1369.  
  1370. const f = h.flushRenderStamperComponentBindings_;
  1371. const g = ump3.get(f) || function () {
  1372. if (isMainRenderer(this)) {
  1373. return f.apply(this, arguments);
  1374. }
  1375. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1376. }
  1377. ump3.set(f, g);
  1378. g.km34 = 1;
  1379. h.flushRenderStamperComponentBindings_ = g;
  1380.  
  1381. }
  1382.  
  1383.  
  1384. if (typeof h.forwardRendererStamperChanges_ === 'function' && !(h.forwardRendererStamperChanges_.km34)) {
  1385.  
  1386. const f = h.forwardRendererStamperChanges_;
  1387. const g = ump3.get(f) || function () {
  1388. if (isMainRenderer(this)) {
  1389. return f.apply(this, arguments);
  1390. }
  1391. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1392. }
  1393. ump3.set(f, g);
  1394. g.km34 = 1;
  1395. h.forwardRendererStamperChanges_ = g;
  1396.  
  1397. }
  1398. */
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404. // console.log(123)
  1405.  
  1406. // return;
  1407.  
  1408.  
  1409. /*
  1410.  
  1411. // buggy for page swtiching
  1412.  
  1413. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km31)) {
  1414.  
  1415.  
  1416.  
  1417.  
  1418. const f = h.dataChanged_;
  1419. h.dataChanged31_ = f;
  1420. const g = ump3.get(f) || function (...args) {
  1421.  
  1422. if (isMainRenderer(this)) {
  1423. return f.apply(this, arguments);
  1424. }
  1425.  
  1426. // sequence on the same proto
  1427. this[qm47] = (this[qm47] || Promise.resolve()).then(() => this.dataChanged31_(...args)).catch(console.log);
  1428. }
  1429. ump3.set(f, g);
  1430. g.km31 = 1;
  1431. h.dataChanged_ = g;
  1432.  
  1433.  
  1434. }
  1435. */
  1436.  
  1437.  
  1438. /*
  1439.  
  1440. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km34)) {
  1441.  
  1442. const f = h.dataChanged_;
  1443. const g = ump3.get(f) || function () {
  1444. if (isMainRenderer(this)) {
  1445. return f.apply(this, arguments);
  1446. }
  1447. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1448. }
  1449. ump3.set(f, g);
  1450. g.km34 = 1;
  1451. h.dataChanged_ = g;
  1452.  
  1453. }
  1454. */
  1455.  
  1456.  
  1457.  
  1458. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  1459.  
  1460. const f = h.tryRenderChunk_;
  1461. const g = ump3.get(f) || function () {
  1462. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1463. }
  1464. ump3.set(f, g);
  1465. g.km34 = 1;
  1466. h.tryRenderChunk_ = g;
  1467.  
  1468. }
  1469.  
  1470.  
  1471. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  1472.  
  1473. const f = h.renderChunk_;
  1474. const g = ump3.get(f) || function () {
  1475. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1476. }
  1477. ump3.set(f, g);
  1478. g.km34 = 1;
  1479. h.renderChunk_ = g;
  1480.  
  1481. }
  1482.  
  1483. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  1484.  
  1485. const f = h.deepLazyListObserver_;
  1486. const g = ump3.get(f) || function () {
  1487. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1488. }
  1489. ump3.set(f, g);
  1490. g.km34 = 1;
  1491. h.deepLazyListObserver_ = g;
  1492.  
  1493. }
  1494.  
  1495.  
  1496. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  1497.  
  1498. const f = h.onItemsUpdated_;
  1499. const g = ump3.get(f) || function () {
  1500. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1501. }
  1502. ump3.set(f, g);
  1503. g.km34 = 1;
  1504. h.onItemsUpdated_ = g;
  1505.  
  1506. }
  1507.  
  1508. /*
  1509. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1510. if (typeof h.updateChangeRecord_ === 'function' && !(h.updateChangeRecord_.km34)) {
  1511.  
  1512. const f = h.updateChangeRecord_;
  1513. const g = ump3.get(f) || function () {
  1514. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1515. }
  1516. ump3.set(f, g);
  1517. g.km34 = 1;
  1518. h.updateChangeRecord_ = g;
  1519.  
  1520. }
  1521. */
  1522.  
  1523.  
  1524. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  1525.  
  1526. const f = h.requestRenderChunk_;
  1527. const g = ump3.get(f) || function () {
  1528. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1529. }
  1530. ump3.set(f, g);
  1531. g.km34 = 1;
  1532. h.requestRenderChunk_ = g;
  1533.  
  1534. }
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540. return;
  1541.  
  1542.  
  1543.  
  1544. /*
  1545. if (typeof h.cancelPendingTasks_ === 'function' && !(h.cancelPendingTasks_.km34)) {
  1546.  
  1547. const f = h.cancelPendingTasks_;
  1548. const g = ump3.get(f) || function () {
  1549. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1550. }
  1551. ump3.set(f, g);
  1552. g.km34 = 1;
  1553. h.cancelPendingTasks_ = g;
  1554.  
  1555. }
  1556.  
  1557.  
  1558. if (typeof h.fillRange_ === 'function' && !(h.fillRange_.km34)) {
  1559.  
  1560. const f = h.fillRange_;
  1561. const g = ump3.get(f) || function () {
  1562. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1563. }
  1564. ump3.set(f, g);
  1565. g.km34 = 1;
  1566. h.fillRange_ = g;
  1567.  
  1568. }
  1569. */
  1570.  
  1571.  
  1572.  
  1573.  
  1574. if (typeof h.addTextNodes_ === 'function' && !(h.addTextNodes_.km34)) {
  1575.  
  1576. const f = h.addTextNodes_;
  1577. const g = function () {
  1578. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1579. }
  1580. g.km34 = 1;
  1581. h.addTextNodes_ = g;
  1582.  
  1583. }
  1584.  
  1585.  
  1586.  
  1587.  
  1588. if (typeof h.updateText_ === 'function' && !(h.updateText_.km34)) {
  1589.  
  1590. const f = h.updateText_;
  1591. const g = function () {
  1592. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1593. }
  1594. g.km34 = 1;
  1595. h.updateText_ = g;
  1596.  
  1597. }
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603. if (typeof h.stampTypeChanged_ === 'function' && !(h.stampTypeChanged_.km34)) {
  1604.  
  1605. const f = h.stampTypeChanged_;
  1606. const g = function () {
  1607. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1608. }
  1609. g.km34 = 1;
  1610. h.stampTypeChanged_ = g;
  1611.  
  1612. }
  1613.  
  1614.  
  1615.  
  1616.  
  1617. // console.log(166)
  1618.  
  1619.  
  1620.  
  1621.  
  1622. }
  1623.  
  1624. const keyStConnectedCallback = Symbol(); // avoid copying the value
  1625.  
  1626. const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  1627. const cmf = new WeakMap();
  1628. const dmf = new WeakMap();
  1629.  
  1630. const gvGenerator = (nv) => {
  1631. return function () {
  1632. const cnt = insp(this);
  1633. const hostElement = cnt.hostElement || 0;
  1634. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  1635. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  1636. if (p && (!dollar && !this.is)) {
  1637. const nodeName = hostElement.nodeName;
  1638. if (typeof nodeName !== 'string') {
  1639. // just in case
  1640. } else if (nodeName.startsWith("DOM-")) {
  1641. // dom-if, dom-repeat, etc
  1642. } else {
  1643. // yt element - new model, yt-xxxx, anixxxxxx
  1644. p = false;
  1645. }
  1646. }
  1647. if (p) {
  1648. if (typeof cnt.markDirty === 'function') {
  1649. // the yt element might call markDirty (occasionally)
  1650. p = false;
  1651. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  1652. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1653. p = false;
  1654. }
  1655. }
  1656. if (p) {
  1657.  
  1658. // << dom-repeat & dom-if >>
  1659.  
  1660. // sequence on the same instance
  1661. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  1662. } else {
  1663. nv.apply(this, arguments);
  1664. }
  1665. };
  1666. }
  1667.  
  1668. const setupWeakRef = (h) => {
  1669.  
  1670.  
  1671. if (WEAK_REF_BINDING && !h.kz62 && setup$ && setupD && setupDataHost && (h.is || h.__dataHost)) {
  1672. h.kz62 = 1;
  1673.  
  1674. //
  1675.  
  1676.  
  1677. setup$(h);
  1678. const hostElement = h.hostElement;
  1679.  
  1680. if (hostElement !== h) {
  1681.  
  1682. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  1683. setupD(h, s);
  1684.  
  1685. }
  1686.  
  1687. const dh = h.__dataHost;
  1688.  
  1689. setupDataHost(dh)
  1690. }
  1691.  
  1692.  
  1693.  
  1694.  
  1695. if (hostElement) {
  1696.  
  1697. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  1698. setupD(hostElement, s);
  1699.  
  1700. }
  1701.  
  1702. const dh = hostElement.__dataHost;
  1703.  
  1704. setupDataHost(dh)
  1705.  
  1706.  
  1707.  
  1708.  
  1709. aDelay().then(() => {
  1710. setupD(hostElement, '__CE_shadowRoot');
  1711. });
  1712.  
  1713.  
  1714. }
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720. }
  1721.  
  1722. }
  1723.  
  1724.  
  1725. let nativeHTMLElements = window.HTMLElement;
  1726.  
  1727. try {
  1728.  
  1729. const q = document.createElement('template');
  1730. q.innerHTML = '<ytz-null361></ytz-null361>';
  1731. nativeHTMLElements = q.content.firstChild.constructor
  1732.  
  1733. } catch (e) { }
  1734.  
  1735. if (!nativeHTMLElements.prototype.connectedCallback) {
  1736. nativeHTMLElements.prototype.connectedCallback79 = nativeHTMLElements.prototype.connectedCallback;
  1737. nativeHTMLElements.prototype.connectedCallback = function () {
  1738. let r;
  1739. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  1740.  
  1741. if (WEAK_REF_BINDING && (this instanceof Node) && (this.is || this.__dataHost)) {
  1742. setupWeakRef(this)
  1743. // setupWeakRef(this.__dataHost)
  1744. }
  1745. return r;
  1746. }
  1747. }
  1748.  
  1749. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  1750. get() {
  1751. const f = this[keyStConnectedCallback];
  1752. if (this.is) {
  1753. setupDiscreteTasks(this, true);
  1754. if (f) this.ky36 = 1;
  1755. }
  1756. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  1757. setupWeakRef(this)
  1758. }
  1759. return f;
  1760. },
  1761. set(nv) {
  1762. let gv;
  1763. if (typeof nv === 'function') {
  1764.  
  1765. gv = cmf.get(nv) || gvGenerator(nv);
  1766. if (gv !== nv) {
  1767. cmf.set(nv, gv);
  1768. cmf.set(gv, gv);
  1769. dmf.set(gv, nv);
  1770. }
  1771.  
  1772. } else {
  1773. gv = nv;
  1774. }
  1775. this[keyStConnectedCallback] = gv; // proto or object
  1776. if (this.is) {
  1777. setupDiscreteTasks(this);
  1778. }
  1779. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  1780. setupWeakRef(this)
  1781. }
  1782. return true;
  1783. },
  1784. enumerable: false,
  1785. configurable: true
  1786.  
  1787. });
  1788.  
  1789. const pLoad = new Promise(resolve => {
  1790. if (document.readyState !== 'loading') {
  1791. resolve();
  1792. } else {
  1793. window.addEventListener("DOMContentLoaded", resolve, false);
  1794. }
  1795. });
  1796. pLoad.then(() => {
  1797.  
  1798. let nonce = document.querySelector('style[nonce]');
  1799. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1800. const st = document.createElement('style');
  1801. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1802. st.textContent = "none-element-k47{order:0}";
  1803. st.addEventListener('load', () => {
  1804. pf31.resolve();
  1805. p59 = 1;
  1806. }, false);
  1807. document.body.appendChild(st);
  1808.  
  1809.  
  1810. // console.debug('90002', location.pathname)
  1811. // console.log(90000, location.pathname)
  1812.  
  1813. });
  1814.  
  1815. const prepareLogs = [];
  1816.  
  1817. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  1818.  
  1819. let winError00 = window.onerror;
  1820.  
  1821. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  1822.  
  1823. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  1824.  
  1825. ; FIX_Iframe_NULL_SRC && (() => {
  1826.  
  1827. let emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  1828. const lcOpt = { sensitivity: 'base' };
  1829. document.createElement24 = document.createElement;
  1830. document.createElement = function (t) {
  1831. if (typeof t === 'string' && t.length === 6) {
  1832. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  1833. let p = this.createElement24(t);
  1834. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  1835. return p;
  1836. }
  1837. }
  1838. return this.createElement24.apply(this, arguments);
  1839. };
  1840.  
  1841. })();
  1842.  
  1843. ; fix_error_many_stack_state === 1 && (() => {
  1844.  
  1845.  
  1846. let p1 = winError00;
  1847.  
  1848. let stackNeedleDetails = null;
  1849.  
  1850. Object.defineProperty(Object.prototype, 'matchAll', {
  1851. get() {
  1852. stackNeedleDetails = this;
  1853. return true;
  1854. },
  1855. enumerable: true,
  1856. configurable: true
  1857. });
  1858.  
  1859. try {
  1860. JSON.parse("{}");
  1861. } catch (e) {
  1862. console.warn(e)
  1863. fix_error_many_stack_state = 0;
  1864. }
  1865.  
  1866. delete Object.prototype['matchAll'];
  1867.  
  1868. let p2 = window.onerror;
  1869.  
  1870. window.onerror = p1;
  1871.  
  1872. if (fix_error_many_stack_state === 0) return;
  1873.  
  1874. if (stackNeedleDetails) {
  1875. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1876. stackNeedleDetails.matchAll = true;
  1877. }
  1878.  
  1879. if (p1 === p2) return (fix_error_many_stack_state = 0);
  1880.  
  1881. // p1!==p2
  1882. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  1883.  
  1884. })();
  1885.  
  1886. ; fix_error_many_stack_state === 2 && (() => {
  1887.  
  1888.  
  1889. let p1 = winError00;
  1890.  
  1891. let objectPrune = null;
  1892. let stackNeedleDetails = null;
  1893.  
  1894. Object.defineProperty(Function.prototype, 'findOwner', {
  1895. get() {
  1896. objectPrune = this;
  1897. return this._findOwner;
  1898. },
  1899. set(nv) {
  1900. this._findOwner = nv;
  1901. return true;
  1902. },
  1903. enumerable: true,
  1904. configurable: true
  1905. });
  1906.  
  1907. Object.defineProperty(Object.prototype, 'matchAll', {
  1908. get() {
  1909. stackNeedleDetails = this;
  1910. return true;
  1911. },
  1912. enumerable: true,
  1913. configurable: true
  1914. });
  1915.  
  1916. try {
  1917. JSON.parse("{}");
  1918. } catch (e) {
  1919. console.warn(e)
  1920. fix_error_many_stack_state = 0;
  1921. }
  1922.  
  1923. delete Function.prototype['findOwner'];
  1924. delete Object.prototype['matchAll'];
  1925.  
  1926. let p2 = window.onerror;
  1927.  
  1928. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  1929.  
  1930. if (fix_error_many_stack_state == 0) return;
  1931.  
  1932. // the following will only execute when Brave's scriptlets.js is executed.
  1933.  
  1934. prepareLogs.push("fix_error_many_stack_state NB")
  1935.  
  1936. if (stackNeedleDetails) {
  1937. stackNeedleDetails.pattern = null;
  1938. stackNeedleDetails.re = null;
  1939. stackNeedleDetails.expect = null;
  1940. stackNeedleDetails.matchAll = true;
  1941. }
  1942.  
  1943. if (objectPrune) {
  1944. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  1945. delete objectPrune._findOwner;
  1946. }
  1947.  
  1948. fix_error_many_stack_state = 3;
  1949. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1950. JSON.parse.objectPrune = objectPrune;
  1951.  
  1952. })();
  1953.  
  1954. ; fix_error_many_stack_state === 3 && (() => {
  1955.  
  1956.  
  1957. let p1 = winError00;
  1958.  
  1959. try {
  1960. JSON.parse("{}");
  1961. } catch (e) {
  1962. console.warn(e)
  1963. fix_error_many_stack_state = 0;
  1964. }
  1965.  
  1966. let p2 = window.onerror;
  1967.  
  1968. if (p1 === p2) return;
  1969.  
  1970. window.onerror = p1;
  1971.  
  1972. if (fix_error_many_stack_state === 0) return;
  1973.  
  1974. fix_error_many_stack_state = 4; // p1 != p2
  1975.  
  1976.  
  1977. })();
  1978.  
  1979. fix_error_many_stack_state === 4 && (() => {
  1980.  
  1981. // the following will only execute when Brave's scriptlets.js is executed.
  1982.  
  1983. prepareLogs.push("fix_error_many_stack_state AB")
  1984.  
  1985. JSON.parseProxy = JSON.parse;
  1986.  
  1987. JSON.parse = ((parse) => {
  1988.  
  1989. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  1990. return function (text, reviver) {
  1991. const onerror = window.onerror;
  1992. window.onerror = null;
  1993. let r;
  1994. try {
  1995. r = parse(...arguments);
  1996. } catch (e) {
  1997. r = e;
  1998. }
  1999. window.onerror = onerror;
  2000. if (r instanceof Error) {
  2001. throw r;
  2002. }
  2003. return r;
  2004. }
  2005.  
  2006. })(JSON.parse);
  2007.  
  2008.  
  2009. })();
  2010.  
  2011.  
  2012.  
  2013. // ================================================ 0.4.5 ================================================
  2014.  
  2015.  
  2016. // ; (() => {
  2017.  
  2018. // if (FIX_error_many_stack && self instanceof Window) {
  2019. // // infinite stack due to matchesStackTrace inside objectPrune of AdsBlock
  2020.  
  2021. // const pdK = Object.getOwnPropertyDescriptor(window, 'onerror');
  2022. // if (!pdK || (pdK.get && pdK.configurable)) {
  2023.  
  2024. // } else {
  2025. // return;
  2026. // }
  2027.  
  2028. // let unsupportErrorFix = false;
  2029.  
  2030. // let firstHook = true;
  2031. // let busy33 = false;
  2032.  
  2033. // let state = 0;
  2034.  
  2035. // if (pdK) {
  2036. // delete window['onerror'];
  2037. // }
  2038.  
  2039. // const pd = {
  2040. // get() {
  2041. // const stack = (new Error()).stack;
  2042. // // targetStack = stack;
  2043. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  2044. // state = isGetExceptionToken ? 1 : 0;
  2045. // delete Window.prototype['onerror'];
  2046. // let r = pdK ? pdK.get.call(this) : this.onerror;
  2047. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2048. // // console.log('onerror get', r)
  2049. // return r;
  2050. // },
  2051. // set(nv) {
  2052. // const stack = (new Error()).stack;
  2053. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  2054. // state = state === 1 && isGetExceptionToken ? 2 : 0;
  2055. // /** @type {string?} */
  2056. // let sToken = null;
  2057. // if (unsupportErrorFix || busy33) {
  2058.  
  2059. // } else if (typeof nv === 'function' && state === 2) {
  2060. // if (firstHook) {
  2061. // firstHook = false;
  2062. // console.groupCollapsed('Infinite onerror Bug Found');
  2063. // console.log(location.href);
  2064. // console.log(stack);
  2065. // console.log(nv);
  2066. // console.groupEnd();
  2067. // }
  2068. // let _token = null;
  2069. // busy33 = true;
  2070. // String.prototype.includes76 = String.prototype.includes;
  2071. // String.prototype.includes = function (token) {
  2072. // _token = token;
  2073. // return true;
  2074. // }
  2075. // nv('token');
  2076. // String.prototype.includes = String.prototype.includes76;
  2077. // sToken = _token;
  2078. // busy33 = false;
  2079. // if (typeof sToken !== 'string') {
  2080. // unsupportErrorFix = true;
  2081. // }
  2082. // }
  2083. // delete Window.prototype['onerror'];
  2084. // if (typeof sToken === 'string' && sToken.length > 1) {
  2085. // /** @type {string} */
  2086. // const token = sToken;
  2087. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>?} } */
  2088. // const currentOnerror = pdK ? pdK.get.call(this) : this.onerror;
  2089.  
  2090. // const now = Date.now();
  2091. // const tokenEntry = {
  2092. // token,
  2093. // expired: now + FIX_error_many_stack_keepAliveDuration
  2094. // }
  2095. // /** @typedef {typeof tokenEntry} TokenEntry */
  2096.  
  2097. // /** @type {Set<TokenEntry>} */
  2098. // const errorTokens = currentOnerror.errorTokens;
  2099.  
  2100. // if (errorTokens) {
  2101. // if (errorTokens.size > FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than) {
  2102. // for (const entry of errorTokens) {
  2103. // if (entry.expired < now) {
  2104. // errorTokens.delete(entry);
  2105. // }
  2106. // }
  2107. // }
  2108. // errorTokens.add(tokenEntry)
  2109. // } else {
  2110. // /** @type {Set<TokenEntry>} */
  2111. // const errorTokens = new Set([tokenEntry]);
  2112. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>} } */
  2113. // const newOnerror = ((oe) => {
  2114. // const r = function (msg, ...args) {
  2115. // if (typeof msg === 'string' && errorTokens.size > 0) {
  2116. // for (const entry of errorTokens) {
  2117. // if (msg.includes(entry.token)) return true;
  2118. // }
  2119. // }
  2120. // if (typeof oe === 'function') {
  2121. // return oe.apply(this, arguments);
  2122. // }
  2123. // };
  2124. // r.errorTokens = errorTokens;
  2125. // return r;
  2126. // })(currentOnerror);
  2127.  
  2128. // if (pdK && pdK.set) pdK.set.call(this, newOnerror);
  2129. // else this.onerror = newOnerror;
  2130. // }
  2131. // } else {
  2132. // if (pdK && pdK.set) pdK.set.call(this, nv);
  2133. // else this.onerror = nv;
  2134. // }
  2135. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2136.  
  2137. // // console.log('onerror set', nv)
  2138. // return true;
  2139. // },
  2140. // enumerable: true,
  2141. // configurable: true
  2142. // }
  2143.  
  2144. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2145.  
  2146.  
  2147. // }
  2148.  
  2149.  
  2150. // })();
  2151.  
  2152.  
  2153.  
  2154. // ================================================ 0.4.5 ================================================
  2155.  
  2156.  
  2157. // << if FIX_yt_player >>
  2158.  
  2159. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  2160. const PERF_471489_ = true;
  2161. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  2162. // This script uses a much gentle way to tamer the JS engine instead.
  2163.  
  2164. // << end >>
  2165.  
  2166. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  2167.  
  2168.  
  2169.  
  2170. const nilFn = () => { };
  2171.  
  2172. let isMainWindow = false;
  2173. try {
  2174. isMainWindow = window.document === window.top.document
  2175. } catch (e) { }
  2176.  
  2177. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  2178.  
  2179. const onRegistryReady = (callback) => {
  2180. if (typeof customElements === 'undefined') {
  2181. if (!('__CE_registry' in document)) {
  2182. // https://github.com/webcomponents/polyfills/
  2183. Object.defineProperty(document, '__CE_registry', {
  2184. get() {
  2185. // return undefined
  2186. },
  2187. set(nv) {
  2188. if (typeof nv == 'object') {
  2189. delete this.__CE_registry;
  2190. this.__CE_registry = nv;
  2191. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2192. }
  2193. return true;
  2194. },
  2195. enumerable: false,
  2196. configurable: true
  2197. })
  2198. }
  2199. let eventHandler = (evt) => {
  2200. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2201. const f = callback;
  2202. callback = null;
  2203. eventHandler = null;
  2204. f();
  2205. };
  2206. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2207. } else {
  2208. callback();
  2209. }
  2210. };
  2211.  
  2212.  
  2213. const assertor = (f) => f() || console.assert(false, f + "");
  2214.  
  2215. const fnIntegrity = (f, d) => {
  2216. if (!f || typeof f !== 'function') {
  2217. console.warn('f is not a function', f);
  2218. return;
  2219. }
  2220. let p = f + "", s = 0, j = -1, w = 0;
  2221. for (let i = 0, l = p.length; i < l; i++) {
  2222. const t = p[i];
  2223. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  2224. if (j < i - 1) w++;
  2225. j = i;
  2226. } else {
  2227. s++;
  2228. }
  2229. }
  2230. let itz = `${f.length}.${s}.${w}`;
  2231. if (!d) {
  2232. return itz;
  2233. } else {
  2234. return itz === d;
  2235. }
  2236. };
  2237.  
  2238. const getZq = (_yt_player) => {
  2239.  
  2240. const w = 'Zq';
  2241.  
  2242. let arr = [];
  2243.  
  2244. for (const [k, v] of Object.entries(_yt_player)) {
  2245.  
  2246. const p = typeof v === 'function' ? v.prototype : 0;
  2247. if (p
  2248. && typeof p.start === 'function' && p.start.length === 0
  2249. && typeof p.isActive === 'function' && p.isActive.length === 0
  2250. && typeof p.stop === 'function' && p.stop.length === 0
  2251. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  2252. && !p.send && !p.abort
  2253. && !p.sample && !p.initialize && !p.fail && !p.getName
  2254. // && !p.dispose && !p.isDisposed
  2255.  
  2256. ) {
  2257. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2258.  
  2259.  
  2260. }
  2261.  
  2262. }
  2263.  
  2264. if (arr.length === 0) {
  2265.  
  2266. console.warn(`Key does not exist. [${w}]`);
  2267. } else {
  2268.  
  2269. console.log(`[${w}]`, arr);
  2270. return arr[0];
  2271. }
  2272.  
  2273.  
  2274.  
  2275.  
  2276. }
  2277.  
  2278.  
  2279. const getVG = (_yt_player) => {
  2280. const w = 'VG';
  2281.  
  2282. let arr = [];
  2283.  
  2284. for (const [k, v] of Object.entries(_yt_player)) {
  2285.  
  2286. const p = typeof v === 'function' ? v.prototype : 0;
  2287. if (p
  2288. && typeof p.show === 'function' && p.show.length === 1
  2289. && typeof p.hide === 'function' && p.hide.length === 0
  2290. && typeof p.stop === 'function' && p.stop.length === 0) {
  2291.  
  2292. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2293.  
  2294. }
  2295.  
  2296. }
  2297.  
  2298.  
  2299. if (arr.length === 0) {
  2300.  
  2301. console.warn(`Key does not exist. [${w}]`);
  2302. } else {
  2303.  
  2304. console.log(`[${w}]`, arr);
  2305. return arr[0];
  2306. }
  2307.  
  2308.  
  2309.  
  2310. }
  2311.  
  2312.  
  2313. const getzo = (_yt_player) => {
  2314. const w = 'zo';
  2315.  
  2316. let arr = [];
  2317.  
  2318. for (const [k, v] of Object.entries(_yt_player)) {
  2319.  
  2320. if (
  2321. typeof v === 'function' && v.length === 3 && k.length < 3
  2322. && (v + "").includes("a.style[b]=c")
  2323. ) {
  2324.  
  2325. arr.push(k);
  2326.  
  2327. }
  2328.  
  2329. }
  2330.  
  2331.  
  2332. if (arr.length === 0) {
  2333.  
  2334. console.warn(`Key does not exist. [${w}]`);
  2335. } else {
  2336.  
  2337. console.log(`[${w}]`, arr);
  2338. return arr[0];
  2339. }
  2340.  
  2341. }
  2342.  
  2343. const addProtoToArr = (parent, key, arr) => {
  2344.  
  2345.  
  2346. let isChildProto = false;
  2347. for (const sr of arr) {
  2348. if (parent[key].prototype instanceof parent[sr]) {
  2349. isChildProto = true;
  2350. break;
  2351. }
  2352. }
  2353.  
  2354. if (isChildProto) return;
  2355.  
  2356. arr = arr.filter(sr => {
  2357. if (parent[sr].prototype instanceof parent[key]) {
  2358. return false;
  2359. }
  2360. return true;
  2361. });
  2362.  
  2363. arr.push(key);
  2364.  
  2365. return arr;
  2366.  
  2367.  
  2368. }
  2369.  
  2370. const getuG = (_yt_player) => {
  2371.  
  2372. const w = 'uG';
  2373.  
  2374. let arr = [];
  2375.  
  2376. for (const [k, v] of Object.entries(_yt_player)) {
  2377.  
  2378.  
  2379. const p = typeof v === 'function' ? v.prototype : 0;
  2380.  
  2381. if (p
  2382. && typeof p.createElement === 'function' && p.createElement.length === 2
  2383. && typeof p.detach === 'function' && p.detach.length === 0
  2384. && typeof p.update === 'function' && p.update.length === 1
  2385. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  2386. ) {
  2387.  
  2388. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2389.  
  2390. }
  2391.  
  2392. }
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398. if (arr.length === 0) {
  2399.  
  2400. console.warn(`Key does not exist. [${w}]`);
  2401. } else {
  2402.  
  2403. console.log(`[${w}]`, arr);
  2404. return arr[0];
  2405. }
  2406.  
  2407. }
  2408.  
  2409.  
  2410.  
  2411. // << if FIX_schedulerInstanceInstance_ >>
  2412.  
  2413. let idleFrom = Date.now() + 2700;
  2414. let slowMode = false;
  2415.  
  2416. let ytEvented = false;
  2417.  
  2418.  
  2419. const setupEvents = FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 ? () => {
  2420.  
  2421. document.addEventListener('yt-navigate', () => {
  2422.  
  2423. ytEvented = true;
  2424. slowMode = false;
  2425. idleFrom = Date.now() + 2700;
  2426.  
  2427. });
  2428. document.addEventListener('yt-navigate-start', () => {
  2429.  
  2430. ytEvented = true;
  2431. slowMode = false;
  2432. idleFrom = Date.now() + 2700;
  2433.  
  2434. });
  2435.  
  2436. document.addEventListener('yt-page-type-changed', () => {
  2437.  
  2438. ytEvented = true;
  2439. slowMode = false;
  2440. idleFrom = Date.now() + 1700;
  2441.  
  2442. });
  2443.  
  2444.  
  2445. document.addEventListener('yt-player-updated', () => {
  2446.  
  2447. ytEvented = true;
  2448. slowMode = false;
  2449. idleFrom = Date.now() + 1700;
  2450.  
  2451. });
  2452.  
  2453.  
  2454. document.addEventListener('yt-page-data-fetched', () => {
  2455.  
  2456. ytEvented = true;
  2457. slowMode = false;
  2458. idleFrom = Date.now() + 1700;
  2459.  
  2460. });
  2461.  
  2462. document.addEventListener('yt-navigate-finish', () => {
  2463.  
  2464. ytEvented = true;
  2465. slowMode = false;
  2466. let t = Date.now() + 700;
  2467. if (t > idleFrom) idleFrom = t;
  2468.  
  2469. });
  2470.  
  2471. document.addEventListener('yt-page-data-updated', () => {
  2472.  
  2473. ytEvented = true;
  2474. slowMode = false;
  2475. let t = Date.now() + 700;
  2476. if (t > idleFrom) idleFrom = t;
  2477.  
  2478. });
  2479.  
  2480. document.addEventListener('yt-watch-comments-ready', () => {
  2481.  
  2482. ytEvented = true;
  2483. slowMode = false;
  2484. let t = Date.now() + 700;
  2485. if (t > idleFrom) idleFrom = t;
  2486.  
  2487. });
  2488. } : () => { };
  2489.  
  2490.  
  2491. // << end >>
  2492.  
  2493. const cleanContext = async (win) => {
  2494. const waitFn = requestAnimationFrame; // shall have been binded to window
  2495. try {
  2496. let mx = 16; // MAX TRIAL
  2497. const frameId = 'vanillajs-iframe-v1';
  2498. /** @type {HTMLIFrameElement | null} */
  2499. let frame = document.getElementById(frameId);
  2500. let removeIframeFn = null;
  2501. if (!frame) {
  2502. frame = document.createElement('iframe');
  2503. frame.id = frameId;
  2504. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2505. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2506. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2507. n.appendChild(frame);
  2508. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2509. const root = document.documentElement;
  2510. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2511. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2512.  
  2513. removeIframeFn = (setTimeout) => {
  2514. const removeIframeOnDocumentReady = (e) => {
  2515. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2516. e = n;
  2517. n = win = removeIframeFn = 0;
  2518. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2519. }
  2520. if (!setTimeout || document.readyState !== 'loading') {
  2521. removeIframeOnDocumentReady();
  2522. } else {
  2523. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2524. }
  2525. }
  2526. }
  2527. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2528. const fc = frame.contentWindow;
  2529. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2530. try {
  2531. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  2532. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  2533. for (let k in res) res[k] = res[k].bind(win); // necessary
  2534. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2535. res.animate = fc.HTMLElement.prototype.animate;
  2536. res.perfNow = fc.performance.now;
  2537. return res;
  2538. } catch (e) {
  2539. if (removeIframeFn) removeIframeFn();
  2540. return null;
  2541. }
  2542. } catch (e) {
  2543. console.warn(e);
  2544. return null;
  2545. }
  2546. };
  2547.  
  2548.  
  2549. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  2550.  
  2551. cleanContext(window).then(__CONTEXT__ => {
  2552. if (!__CONTEXT__) return null;
  2553.  
  2554. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  2555.  
  2556.  
  2557. performance.now17 = perfNow.bind(performance);
  2558. // performance.now = performance.now16;
  2559. /*
  2560. let nowh = -1;
  2561. performance.now = function () {
  2562. let t = nowh;
  2563. let c = this.now17();
  2564. return (nowh = (t + 1e-7 > c ? t + 0.1 : c));
  2565. }
  2566. */
  2567.  
  2568. // console.log(performance.now())
  2569. // console.log(performance.now())
  2570. // console.log(performance.now())
  2571. // console.log(performance.now())
  2572.  
  2573.  
  2574.  
  2575. __requestAnimationFrame__ = requestAnimationFrame;
  2576.  
  2577. let rafPromise = null;
  2578.  
  2579. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2580. requestAnimationFrame(hRes => {
  2581. rafPromise = null;
  2582. resolve(hRes);
  2583. });
  2584. }));
  2585.  
  2586. const getForegroundPromise = () => {
  2587. if (document.visibilityState === 'visible') {
  2588. return Promise.resolve();
  2589. } else {
  2590. return getRafPromise();
  2591. }
  2592. };
  2593.  
  2594. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  2595. setTimeout(() => {
  2596. NO_PRELOAD_GENERATE_204_BYPASS = true;
  2597. }, 1270);
  2598. });
  2599.  
  2600. const promiseForTamerTimeout = new Promise(resolve => {
  2601. promiseForCustomYtElementsReady.then(() => {
  2602. customElements.whenDefined('ytd-app').then(() => {
  2603. setTimeout(resolve, 1200);
  2604. });
  2605. });
  2606. setTimeout(resolve, 3000);
  2607. });
  2608.  
  2609.  
  2610. class RAFHub {
  2611. constructor() {
  2612. /** @type {number} */
  2613. this.startAt = 8170;
  2614. /** @type {number} */
  2615. this.counter = 0;
  2616. /** @type {number} */
  2617. this.rid = 0;
  2618. /** @type {Map<number, FrameRequestCallback>} */
  2619. this.funcs = new Map();
  2620. const funcs = this.funcs;
  2621. /** @type {FrameRequestCallback} */
  2622. this.bCallback = this.mCallback.bind(this);
  2623. this.pClear = () => funcs.clear();
  2624. }
  2625. /** @param {DOMHighResTimeStamp} highResTime */
  2626. mCallback(highResTime) {
  2627. this.rid = 0;
  2628. Promise.resolve().then(this.pClear);
  2629. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2630. }
  2631. /** @param {FrameRequestCallback} f */
  2632. request(f) {
  2633. if (this.counter > 1e9) this.counter = 9;
  2634. let cid = this.startAt + (++this.counter);
  2635. this.funcs.set(cid, f);
  2636. if (this.rid === 0) {
  2637. console.log(2455)
  2638. this.rid = requestAnimationFrame(this.bCallback);
  2639. }
  2640. return cid;
  2641. }
  2642. /** @param {number} cid */
  2643. cancel(cid) {
  2644. cid = +cid;
  2645. if (cid > 0) {
  2646. if (cid <= this.startAt) {
  2647. return cancelAnimationFrame(cid);
  2648. }
  2649. if (this.rid > 0) {
  2650. this.funcs.delete(cid);
  2651. if (this.funcs.size === 0) {
  2652. cancelAnimationFrame(this.rid);
  2653. this.rid = 0;
  2654. }
  2655. }
  2656. }
  2657. }
  2658. /** @param {number} cid */
  2659. /** @param {FrameRequestCallback} f */
  2660. replaceFunc(cid, f) {
  2661. if (typeof this.funcs.get(cid) === 'function') {
  2662. this.funcs.set(cid, f);
  2663. return cid;
  2664. } else {
  2665. let r = this.request(f);
  2666. this.cancel(cid);
  2667. return r;
  2668. }
  2669. }
  2670. }
  2671.  
  2672.  
  2673.  
  2674. NATIVE_CANVAS_ANIMATION && (() => {
  2675.  
  2676. HTMLCanvasElement.prototype.animate = animate;
  2677.  
  2678. let cid = setInterval(() => {
  2679. HTMLCanvasElement.prototype.animate = animate;
  2680. }, 1);
  2681.  
  2682. promiseForTamerTimeout.then(() => {
  2683. clearInterval(cid)
  2684. });
  2685.  
  2686. })();
  2687.  
  2688. FIX_ytAction_ && (async () => {
  2689.  
  2690. const ytdApp = await new Promise(resolve => {
  2691.  
  2692. promiseForCustomYtElementsReady.then(() => {
  2693. customElements.whenDefined('ytd-app').then(() => {
  2694. const ytdApp = document.querySelector('ytd-app');
  2695. if (ytdApp) {
  2696. resolve(ytdApp);
  2697. return;
  2698. }
  2699. let mo = new MutationObserver(() => {
  2700. const ytdApp = document.querySelector('ytd-app');
  2701. if (!ytdApp) return;
  2702. if (mo) {
  2703. mo.disconnect();
  2704. mo.takeRecords();
  2705. mo = null;
  2706. }
  2707. resolve(ytdApp);
  2708. });
  2709. mo.observe(document, { subtree: true, childList: true });
  2710. });
  2711. });
  2712.  
  2713.  
  2714.  
  2715. });
  2716.  
  2717.  
  2718.  
  2719. if (!ytdApp) return;
  2720. const cProto = insp(ytdApp).constructor.prototype;
  2721.  
  2722.  
  2723. if (!cProto) return;
  2724. let mbd = 0;
  2725.  
  2726. const fixer = (_ytdApp) => {
  2727.  
  2728. const ytdApp = insp(_ytdApp);
  2729.  
  2730. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  2731. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  2732. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  2733. mbd++;
  2734. }
  2735.  
  2736.  
  2737. }
  2738.  
  2739. let cid = setInterval(() => {
  2740.  
  2741.  
  2742. if (typeof cProto.created === 'function' && !cProto.created56) {
  2743. cProto.created56 = cProto.created;
  2744. cProto.created = function (...args) {
  2745. const r = this.created56(...args);
  2746. fixer(this);
  2747. return r;
  2748. };
  2749. mbd++;
  2750. }
  2751.  
  2752.  
  2753. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  2754. cProto.onYtAction57_ = cProto.onYtAction_;
  2755. cProto.onYtAction_ = function (...args) {
  2756. Promise.resolve().then(() => this.onYtAction57_(...args));
  2757. };
  2758. mbd++;
  2759. }
  2760.  
  2761. if (ytdApp) fixer(ytdApp);
  2762.  
  2763. /*
  2764. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  2765. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  2766. actionRouter_.handleAction57 = actionRouter_.handleAction;
  2767. actionRouter_.handleAction = function (...args) {
  2768. Promise.resolve().then(() => this.handleAction57(...args));
  2769. }
  2770. mbd++;
  2771. }
  2772. */
  2773.  
  2774. // if(mbd === 3) clearInterval(cid);
  2775. if (mbd >= 3) clearInterval(cid);
  2776.  
  2777. }, 1);
  2778.  
  2779. setTimeout(() => {
  2780.  
  2781. clearInterval(cid);
  2782. }, 1000);
  2783.  
  2784. })();
  2785.  
  2786.  
  2787. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  2788.  
  2789. const evKey = `${_evKey}`;
  2790. const fvKey = `${_fvKey}`;
  2791. const debug = !!_debug;
  2792.  
  2793.  
  2794. // const rafHub = new RAFHub();
  2795.  
  2796.  
  2797. const _yt_player = await new Promise(resolve => {
  2798.  
  2799. let cid = setInterval(() => {
  2800. let t = (((window || 0)._yt_player || 0) || 0);
  2801. if (t) {
  2802.  
  2803. clearInterval(cid);
  2804. resolve(t);
  2805. }
  2806. }, 1);
  2807.  
  2808. promiseForTamerTimeout.then(() => {
  2809. resolve(null)
  2810. });
  2811.  
  2812. });
  2813.  
  2814.  
  2815. if (!_yt_player || typeof _yt_player !== 'object') return;
  2816.  
  2817.  
  2818. const getArr = (_yt_player) => {
  2819.  
  2820. let arr = [];
  2821.  
  2822. for (const [k, v] of Object.entries(_yt_player)) {
  2823.  
  2824. const p = typeof v === 'function' ? v.prototype : 0;
  2825. if (p
  2826. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  2827.  
  2828. ) {
  2829. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2830.  
  2831. }
  2832.  
  2833. }
  2834.  
  2835. if (arr.length === 0) {
  2836.  
  2837. console.warn(`Key prop [${evKey}] does not exist.`);
  2838. } else {
  2839.  
  2840. return arr;
  2841. }
  2842.  
  2843. };
  2844.  
  2845. const arr = getArr(_yt_player);
  2846.  
  2847.  
  2848. if (!arr) return;
  2849.  
  2850. debug && console.log(`FIX_${evKey}`, arr);
  2851.  
  2852. const f = function (...args) {
  2853. Promise.resolve().then(() => this[fvKey](...args));
  2854. };
  2855.  
  2856.  
  2857. for (const k of arr) {
  2858.  
  2859. const g = _yt_player;
  2860. const gk = g[k];
  2861. const gkp = gk.prototype;
  2862.  
  2863. debug && console.log(237, k, gkp)
  2864.  
  2865. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  2866. gkp[fvKey] = gkp[evKey];
  2867. gkp[evKey] = f;
  2868. }
  2869. }
  2870.  
  2871.  
  2872.  
  2873.  
  2874. }
  2875.  
  2876. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  2877. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  2878. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  2879. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  2880. if (FIX_VideoEVENTS_v2) {
  2881. const FIX_VideoEVENTS_DEBUG = 0;
  2882. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  2883. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  2884. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  2885. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  2886. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  2887. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  2888. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  2889. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  2890. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  2891.  
  2892. }
  2893. // onMutedAutoplayChange
  2894. // onVolumeChange
  2895. // onPlaybackRateChange
  2896.  
  2897. // onAirPlayActiveChange
  2898. // onAirPlayAvailabilityChange
  2899. // onApiChange
  2900. // onAutoplayBlocked
  2901. // onDrmOutputRestricted
  2902. // onFullscreenChange
  2903. // onLoadProgress
  2904. // onLoadedMetadata
  2905. // onVideoDataChange
  2906. // onVideoProgress
  2907.  
  2908. WEAK_REF_BINDING && (async () => {
  2909.  
  2910.  
  2911. const dummy = await new Promise(resolve => {
  2912.  
  2913. promiseForCustomYtElementsReady.then(() => {
  2914. customElements.whenDefined('tp-yt-paper-menu-button').then(() => {
  2915.  
  2916. resolve(document.createElement('tp-yt-paper-menu-button'));
  2917. });
  2918. });
  2919.  
  2920.  
  2921.  
  2922. });
  2923.  
  2924.  
  2925. if (!dummy || dummy.is !== 'tp-yt-paper-menu-button') return;
  2926.  
  2927.  
  2928. const cProto = insp(dummy).constructor.prototype;
  2929.  
  2930. if (typeof cProto.close === 'function' && !cProto.close58) {
  2931. cProto.close58 = cProto.close;
  2932. cProto.close = function () {
  2933. const dropdown = (this.$ || 0).dropdown || 0;
  2934. if (!dropdown) return;
  2935. return this.close58.apply(this, arguments);
  2936. }
  2937. }
  2938.  
  2939. });
  2940.  
  2941. FIX_maybeUpdateFlexibleMenu && (async () => {
  2942.  
  2943.  
  2944. const dummy = await new Promise(resolve => {
  2945.  
  2946. promiseForCustomYtElementsReady.then(() => {
  2947. customElements.whenDefined('ytd-menu-renderer').then(() => {
  2948.  
  2949. resolve(document.createElement('ytd-menu-renderer'));
  2950. });
  2951. });
  2952.  
  2953.  
  2954.  
  2955. });
  2956.  
  2957.  
  2958. if (!dummy || dummy.is !== 'ytd-menu-renderer') return;
  2959.  
  2960. const cProto = insp(dummy).constructor.prototype;
  2961.  
  2962. if (typeof cProto.created === 'function' && !cProto.created58) {
  2963. cProto.created58 = cProto.created;
  2964. cProto.created = function (...args) {
  2965. const r = this.created58(...args);
  2966. if (typeof this.maybeUpdateFlexibleMenu === 'function' && !this.maybeUpdateFlexibleMenu57) {
  2967. this.maybeUpdateFlexibleMenu57 = this.maybeUpdateFlexibleMenu;
  2968. this.maybeUpdateFlexibleMenu = function (...args) {
  2969. Promise.resolve().then(() => this.maybeUpdateFlexibleMenu57(...args));
  2970. }
  2971. }
  2972. return r;
  2973. }
  2974.  
  2975. }
  2976.  
  2977. //console.log(144,cProto.maybeUpdateFlexibleMenu)
  2978.  
  2979.  
  2980.  
  2981.  
  2982.  
  2983.  
  2984. })();
  2985.  
  2986. ENABLE_discreteTasking && (async () => {
  2987.  
  2988. const Polymer = await new Promise(resolve => {
  2989.  
  2990. let cid = 0;
  2991. const f = () => {
  2992. const Polymer = window.Polymer;
  2993. if (typeof Polymer !== 'function') return;
  2994. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  2995. cid && clearInterval(cid);
  2996. cid = 0;
  2997. resolve(Polymer);
  2998. };
  2999. cid = setInterval(f, 1);
  3000.  
  3001. });
  3002. if (!Polymer) return;
  3003.  
  3004.  
  3005. if (UNLOAD_DETACHED_POLYMER && typeof Polymer.Base.detached === 'function' && !Polymer.Base.detached92 && Polymer.Base.detached.length === 0) {
  3006. Polymer.Base.detached92 = Polymer.Base.detached;
  3007.  
  3008. const detachedPlus = async function (elem) {
  3009. await delay300.then();
  3010. if (elem.isAttached !== false) return;
  3011. await delay300.then();
  3012. if (elem.isAttached !== false) return;
  3013.  
  3014. if (elem.__dataClientsReady === true) elem.__dataClientsReady = false;
  3015. if (elem.__dataEnabled === true) elem.__dataEnabled = false;
  3016. if (elem.__dataReady === true) elem.__dataReady = false;
  3017.  
  3018. elem.__dataLinkedPaths = elem.__dataToNotify = elem.__dataPendingClients = null;
  3019. elem.__dataHasPaths = false;
  3020. // elem.__dataCompoundStorage = null;
  3021. elem.__dataHost = null;
  3022. elem.__dataTemp = null;
  3023. elem.__dataClientsInitialized = false;
  3024.  
  3025.  
  3026. // elem.data = {};
  3027. elem.data = null;
  3028. elem.__dataPending = null;
  3029. elem.__dataOld = null;
  3030. elem.__dataInstanceProps = null;
  3031.  
  3032. elem.__dataCounter = 0;
  3033. elem.__serializing = false;
  3034.  
  3035. if (elem.$) elem.$ = {};
  3036. if (elem.root) elem.root = null;
  3037.  
  3038. let hostElement = elem.hostElement, tlm;
  3039. if (hostElement instanceof Node) {
  3040. // if (hostElement.isConnected === false) {
  3041. // while (tlm = hostElement.firstChild) tlm.remove();
  3042. // }
  3043. elem.hostElement = hostElement = null;
  3044. }
  3045.  
  3046.  
  3047. if (hostElement === null) {
  3048.  
  3049. if (elem.animatedIconElement instanceof Node) elem.animatedIconElement = null;
  3050. if (elem._target instanceof Node) elem._target = null;
  3051. if (elem.iconset instanceof Node) elem.iconset = null;
  3052. if (elem._svgIcon instanceof Node) elem._svgIcon = null;
  3053.  
  3054. }
  3055.  
  3056.  
  3057. }
  3058. Polymer.Base.detached = function () {
  3059. Promise.resolve(this).then(detachedPlus);
  3060. return Polymer.Base.detached92();
  3061. };
  3062. }
  3063.  
  3064. Polymer.Base.__connInit__ = function () {
  3065. setupDiscreteTasks(this);
  3066. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  3067. setupWeakRef(this)
  3068. }
  3069. }
  3070.  
  3071.  
  3072. /** @type {Function} */
  3073. const connectedCallbackK = function (...args) {
  3074. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3075. const r = this[qm53](...args);
  3076. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3077. this.mh35 = 1;
  3078. return r;
  3079. };
  3080.  
  3081. connectedCallbackK.m353 = 1;
  3082.  
  3083.  
  3084. const qt53 = Polymer.Base.connectedCallback;
  3085. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  3086.  
  3087. Polymer.Base.connectedCallback = connectedCallbackK;
  3088.  
  3089.  
  3090. /** @type {Function} */
  3091. const createdK = function (...args) {
  3092. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3093. const r = this[qn53](...args);
  3094. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3095. this.mh36 = 1;
  3096. return r;
  3097. };
  3098.  
  3099.  
  3100. createdK.m353 = 1;
  3101. Polymer.Base[qn53] = Polymer.Base.created;
  3102. Polymer.Base.created = createdK;
  3103.  
  3104. })();
  3105.  
  3106. CHANGE_appendChild && (() => {
  3107.  
  3108. const f = HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  3109. if (f) HTMLElement.prototype.appendChild = function (a) {
  3110.  
  3111.  
  3112. if (this instanceof HTMLElement) {
  3113.  
  3114. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  3115. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  3116. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  3117. node.__m848__ = 1;
  3118. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  3119. }
  3120. }
  3121. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  3122. return this.appendChild73.apply(this, arguments);
  3123. }
  3124.  
  3125. if (a instanceof DocumentFragment) {
  3126. if (a.firstElementChild === null) {
  3127. let child = a.firstChild;
  3128. if (child === null) return a;
  3129. let doNormal = false;
  3130. while (child instanceof Node) {
  3131. if (child.nodeType === 3) { doNormal = true; break; }
  3132. child = child.nextSibling;
  3133. }
  3134. if (!doNormal) return a;
  3135. }
  3136. }
  3137.  
  3138. return (this.appendChild73 || f).apply(this, arguments);
  3139. }
  3140.  
  3141.  
  3142. return (HTMLElement.prototype.appendChild73 || f).apply(this, arguments);
  3143. }
  3144.  
  3145.  
  3146. })();
  3147.  
  3148. if (FIX_Shady) {
  3149.  
  3150. let cidSL = setInterval(() => {
  3151. const { ShadyDOM, ShadyCSS } = window;
  3152. if (ShadyDOM && ShadyCSS) {
  3153. clearInterval(cidSL);
  3154. cidSL = 0;
  3155. }
  3156. if (ShadyDOM) {
  3157. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  3158. ShadyDOM.noPatch = true; // 1 of 10
  3159. ShadyDOM.patchOnDemand = false; // 1 of 10
  3160. ShadyDOM.preferPerformance = true; // 1 of 10
  3161. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  3162. }
  3163. if (ShadyCSS) {
  3164. ShadyCSS.nativeCss = true; // 1 of 10
  3165. ShadyCSS.nativeShadow = true; // 6 of 10
  3166. ShadyCSS.cssBuild = undefined; // 1 of 10
  3167. ShadyCSS.disableRuntime = true; // 1 of 10
  3168. }
  3169. }, 1);
  3170.  
  3171. }
  3172.  
  3173.  
  3174. FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 && (async () => {
  3175.  
  3176.  
  3177. const schedulerInstanceInstance_ = await new Promise(resolve => {
  3178.  
  3179. let cid = setInterval(() => {
  3180. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  3181. if (t) {
  3182.  
  3183. clearInterval(cid);
  3184. resolve(t);
  3185. }
  3186. }, 1);
  3187. promiseForTamerTimeout.then(() => {
  3188. resolve(null)
  3189. });
  3190. });
  3191.  
  3192. if (!schedulerInstanceInstance_) return;
  3193.  
  3194.  
  3195. if (!ytEvented) {
  3196. idleFrom = Date.now() + 2700;
  3197. slowMode = false; // integrity
  3198. }
  3199.  
  3200. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  3201. if (checkOK) {
  3202.  
  3203.  
  3204. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  3205.  
  3206. let requestingFn = null;
  3207. let requestingArgs = null;
  3208. let requestingDT = 0;
  3209.  
  3210. // let timerId = null;
  3211. const entries = [];
  3212. const f = function () {
  3213. requestingFn = this.fn;
  3214. requestingArgs = [...arguments];
  3215. requestingDT = Date.now();
  3216. entries.push({
  3217. fn: requestingFn,
  3218. args: requestingArgs,
  3219. t: requestingDT
  3220. });
  3221. // if (Date.now() < idleFrom) {
  3222. // timerId = this.fn.apply(window, arguments);
  3223. // } else {
  3224. // timerId = this.fn.apply(window, arguments);
  3225.  
  3226. // }
  3227. // timerId = 12377;
  3228. return 12377;
  3229. }
  3230.  
  3231.  
  3232. const fakeFns = [
  3233. f.bind({ fn: requestAnimationFrame }),
  3234. f.bind({ fn: setInterval }),
  3235. f.bind({ fn: setTimeout }),
  3236. f.bind({ fn: requestIdleCallback })
  3237. ]
  3238.  
  3239.  
  3240.  
  3241.  
  3242. let timerResolve = null;
  3243. setInterval(() => {
  3244. timerResolve && timerResolve();
  3245. timerResolve = null;
  3246. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  3247. }, 250);
  3248.  
  3249. let mzt = 0;
  3250.  
  3251. let fnSelectorProp = null;
  3252.  
  3253. schedulerInstanceInstance_.start = function () {
  3254.  
  3255. const mk1 = window.requestAnimationFrame
  3256. const mk2 = window.setInterval
  3257. const mk3 = window.setTimeout
  3258. const mk4 = window.requestIdleCallback
  3259.  
  3260. const tThis = this['$$12378$$'] || this;
  3261.  
  3262.  
  3263. window.requestAnimationFrame = fakeFns[0]
  3264. window.setInterval = fakeFns[1]
  3265. window.setTimeout = fakeFns[2]
  3266. window.requestIdleCallback = fakeFns[3]
  3267.  
  3268. fnSelectorProp = null;
  3269.  
  3270.  
  3271. tThis.start991.call(new Proxy(tThis, {
  3272. get(target, prop, receiver) {
  3273. if (prop === '$$12377$$') return true;
  3274. if (prop === '$$12378$$') return target;
  3275.  
  3276. // console.log('get',prop)
  3277. return target[prop]
  3278. },
  3279. set(target, prop, value, receiver) {
  3280. // console.log('set', prop, value)
  3281.  
  3282.  
  3283. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  3284. if (value === 12377 && fnSelectorProp) {
  3285.  
  3286. const originalSelection = target[fnSelectorProp];
  3287. const timerIdProp = prop;
  3288.  
  3289. /*
  3290.  
  3291.  
  3292. case 1:
  3293. var a = this.K;
  3294. this.g = this.I ? window.requestIdleCallback(a, {
  3295. timeout: 3E3
  3296. }) : window.setTimeout(a, ma);
  3297. break;
  3298. case 2:
  3299. this.g = window.setTimeout(this.M, this.N);
  3300. break;
  3301. case 3:
  3302. this.g = window.requestAnimationFrame(this.L);
  3303. break;
  3304. case 4:
  3305. this.g = window.setTimeout(this.J, 0)
  3306. }
  3307.  
  3308. */
  3309.  
  3310. const doForegroundSlowMode = () => {
  3311.  
  3312. const tir = ++mzt;
  3313. const f = requestingArgs[0];
  3314.  
  3315.  
  3316. getForegroundPromise().then(() => {
  3317.  
  3318.  
  3319. new Promise(r => {
  3320. timerResolve = r
  3321. }).then(() => {
  3322. if (target[timerIdProp] === -tir) f();
  3323. });
  3324.  
  3325. })
  3326.  
  3327. target[fnSelectorProp] = 931;
  3328. target[prop] = -tir;
  3329. }
  3330.  
  3331. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  3332. if (slowMode && !(requestingArgs[1] > 250)) {
  3333.  
  3334. doForegroundSlowMode();
  3335.  
  3336. } else {
  3337. target[prop] = setTimeout.apply(window, requestingArgs);
  3338.  
  3339. }
  3340.  
  3341. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  3342.  
  3343. if (slowMode) {
  3344.  
  3345. doForegroundSlowMode();
  3346.  
  3347. } else {
  3348. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  3349. }
  3350.  
  3351.  
  3352. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  3353.  
  3354. const f = requestingArgs[0];
  3355. const tir = ++mzt;
  3356. Promise.resolve().then(() => {
  3357. if (target[timerIdProp] === -tir) f();
  3358. });
  3359. target[fnSelectorProp] = 930;
  3360. target[prop] = -tir;
  3361.  
  3362. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  3363.  
  3364. doForegroundSlowMode();
  3365.  
  3366. } else {
  3367. // target[prop] = timerId;
  3368. target[fnSelectorProp] = 0;
  3369. target[prop] = 0;
  3370. }
  3371.  
  3372. // *****
  3373. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  3374. } else {
  3375.  
  3376. target[prop] = value;
  3377. }
  3378. // console.log('set',prop,value)
  3379. return true;
  3380. }
  3381. }));
  3382.  
  3383. fnSelectorProp = null;
  3384.  
  3385.  
  3386. window.requestAnimationFrame = mk1;
  3387. window.setInterval = mk2
  3388. window.setTimeout = mk3
  3389. window.requestIdleCallback = mk4;
  3390.  
  3391.  
  3392.  
  3393. }
  3394.  
  3395. schedulerInstanceInstance_.start.toString = function () {
  3396. return schedulerInstanceInstance_.start991.toString();
  3397. }
  3398.  
  3399. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  3400. // prop,
  3401. // value: schedulerInstanceInstance_[prop],
  3402. // type: typeof schedulerInstanceInstance_[prop]
  3403.  
  3404. // }));
  3405. // console.log('fcc', funcNames)
  3406.  
  3407.  
  3408.  
  3409.  
  3410. }
  3411. })();
  3412.  
  3413.  
  3414.  
  3415. FIX_schedulerInstanceInstance_V2 && !FIX_schedulerInstanceInstance_V1 && (async () => {
  3416.  
  3417.  
  3418. const schedulerInstanceInstance_ = await new Promise(resolve => {
  3419.  
  3420. let cid = setInterval(() => {
  3421. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  3422. if (t) {
  3423.  
  3424. clearInterval(cid);
  3425. resolve(t);
  3426. }
  3427. }, 1);
  3428. promiseForTamerTimeout.then(() => {
  3429. resolve(null)
  3430. });
  3431. });
  3432.  
  3433. if (!schedulerInstanceInstance_) return;
  3434.  
  3435.  
  3436. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  3437. if (checkOK) {
  3438.  
  3439. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  3440.  
  3441.  
  3442.  
  3443. let busy = false;
  3444.  
  3445. // console.log('1667',schedulerInstanceInstance_.start);
  3446. schedulerInstanceInstance_.start = function () {
  3447.  
  3448. // p59 || console.log(location.pathname, 16400);
  3449.  
  3450. if (busy) {
  3451.  
  3452. return this.start991.call(this);
  3453.  
  3454. }
  3455.  
  3456. busy = true;
  3457.  
  3458. const mk1 = window.requestAnimationFrame
  3459. // const mk2 = window.setInterval
  3460. // const mk3 = window.setTimeout
  3461. // const mk4 = window.requestIdleCallback
  3462.  
  3463. // by pass Youtube Engine's wrapping
  3464. window.requestAnimationFrame = baseRAF;
  3465. // window.setInterval = setInterval
  3466. // window.setTimeout = setTimeout
  3467. // window.requestIdleCallback = requestIdleCallback
  3468.  
  3469.  
  3470. this.start991.call(this);
  3471.  
  3472.  
  3473. window.requestAnimationFrame = mk1;
  3474. // window.setInterval = mk2
  3475. // window.setTimeout = mk3
  3476. // window.requestIdleCallback = mk4;
  3477.  
  3478. busy = false;
  3479.  
  3480.  
  3481.  
  3482. }
  3483.  
  3484. schedulerInstanceInstance_.start.toString = function () {
  3485. return schedulerInstanceInstance_.start991.toString();
  3486. }
  3487.  
  3488. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  3489. // prop,
  3490. // value: schedulerInstanceInstance_[prop],
  3491. // type: typeof schedulerInstanceInstance_[prop]
  3492.  
  3493. // }));
  3494. // console.log('fcc', funcNames)
  3495.  
  3496.  
  3497.  
  3498.  
  3499. }
  3500. })();
  3501.  
  3502. FIX_yt_player && (async () => {
  3503.  
  3504.  
  3505.  
  3506. // const rafHub = new RAFHub();
  3507.  
  3508.  
  3509. const _yt_player = await new Promise(resolve => {
  3510.  
  3511. let cid = setInterval(() => {
  3512. let t = (((window || 0)._yt_player || 0) || 0);
  3513. if (t) {
  3514.  
  3515. clearInterval(cid);
  3516. resolve(t);
  3517. }
  3518. }, 1);
  3519.  
  3520. promiseForTamerTimeout.then(() => {
  3521. resolve(null)
  3522. });
  3523.  
  3524. });
  3525.  
  3526.  
  3527.  
  3528. if (!_yt_player || typeof _yt_player !== 'object') return;
  3529.  
  3530.  
  3531.  
  3532. let keyZq = getZq(_yt_player);
  3533. // let keyVG = getVG(_yt_player);
  3534. // let buildVG = _yt_player[keyVG];
  3535. // let u = new buildVG({
  3536. // api: {},
  3537. // element: document.createElement('noscript'),
  3538. // api: {},
  3539. // hide: () => { }
  3540. // }, 250);
  3541. // const timeDelayConstructor = u.delay.constructor; // g.br
  3542. // console.log(keyVG, u)
  3543. // buildVG.prototype.show = function(){}
  3544. // _yt_player[keyZq] = g.k
  3545.  
  3546. if (!keyZq) return;
  3547.  
  3548.  
  3549. const g = _yt_player
  3550. let k = keyZq
  3551.  
  3552. const gk = g[k];
  3553. if (typeof gk !== 'function') return;
  3554. const gkp = gk.prototype;
  3555.  
  3556. let dummyObject = new gk;
  3557. let nilFunc = () => { };
  3558.  
  3559. let nilObj = {};
  3560.  
  3561. // console.log(1111111111)
  3562.  
  3563. let keyBoolD = '';
  3564. let keyWindow = '';
  3565. let keyFuncC = '';
  3566. let keyCidj = '';
  3567.  
  3568. for (const [t, y] of Object.entries(dummyObject)) {
  3569. if (y instanceof Window) keyWindow = t;
  3570. }
  3571.  
  3572. const dummyObjectProxyHandler = {
  3573. get(target, prop) {
  3574. let v = target[prop]
  3575. if (v instanceof Window && !keyWindow) {
  3576. keyWindow = t;
  3577. }
  3578. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  3579. if (prop === keyWindow) y = {
  3580. requestAnimationFrame(f) {
  3581. return 3;
  3582. },
  3583. cancelAnimationFrame() {
  3584.  
  3585. }
  3586. }
  3587. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  3588. keyFuncC = prop;
  3589. }
  3590. // console.log('[get]', prop, typeof target[prop])
  3591.  
  3592.  
  3593. return y;
  3594. },
  3595. set(target, prop, value) {
  3596.  
  3597. if (typeof value === 'boolean' && !keyBoolD) {
  3598. keyBoolD = prop;
  3599. }
  3600. if (typeof value === 'number' && !keyCidj && value >= 2) {
  3601. keyCidj = prop;
  3602. }
  3603.  
  3604. // console.log('[set]', prop, value)
  3605. target[prop] = value
  3606.  
  3607. return true;
  3608. }
  3609. };
  3610.  
  3611. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  3612.  
  3613. /*
  3614. console.log({
  3615. keyBoolD,
  3616. keyFuncC,
  3617. keyWindow,
  3618. keyCidj
  3619. })
  3620.  
  3621. console.log( dummyObject[keyFuncC])
  3622.  
  3623.  
  3624. console.log(2222222222)
  3625. */
  3626.  
  3627.  
  3628. // console.log('gkp.start',gkp.start);
  3629. // console.log('gkp.stop',gkp.stop);
  3630. gkp._activation = false;
  3631.  
  3632. gkp.start = function () {
  3633. // p59 || console.log(12100)
  3634. if (!this._activation) {
  3635. this._activation = true;
  3636. getRafPromise().then(() => {
  3637. this._activation = false;
  3638. if (this[keyCidj]) {
  3639. Promise.resolve().then(this[keyFuncC]);
  3640. }
  3641. });
  3642. }
  3643. this[keyCidj] = 1;
  3644. this[keyBoolD] = true;
  3645. }
  3646. ;
  3647. gkp.stop = function () {
  3648. this[keyCidj] = null
  3649. }
  3650.  
  3651.  
  3652. /*
  3653. g[k].start = function() {
  3654. this.stop();
  3655. this.D = true;
  3656. var a = requestAnimationFrame
  3657. , b = cancelAnimationFrame;
  3658. this.j = a.call(this.B, this.C)
  3659. }
  3660. ;
  3661. g[k].stop = function() {
  3662. if (this.isActive()) {
  3663. var a = requestAnimationFrame
  3664. , b = cancelAnimationFrame;
  3665. b.call(this.B, this.j)
  3666. }
  3667. this.j = null
  3668. }
  3669. */
  3670.  
  3671.  
  3672.  
  3673. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  3674.  
  3675. if (keyzo) {
  3676.  
  3677. k = keyzo
  3678.  
  3679. const setCSSProp = (() => {
  3680.  
  3681. let animationPropCapable = false;
  3682. try {
  3683. const propName = "--ibxpf"
  3684. const value = 2;
  3685. const keyframes = [{
  3686. [propName]: value
  3687. }];
  3688. window.CSS.registerProperty({
  3689. name: "--ibxpf",
  3690. syntax: "<number>",
  3691. inherits: false,
  3692. initialValue: 1,
  3693. });
  3694. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  3695. } catch (e) { }
  3696.  
  3697. if (!animationPropCapable) {
  3698. return (element, cssProp, value) => {
  3699.  
  3700.  
  3701. element.style.setProperty(cssProp, value);
  3702.  
  3703. }
  3704. }
  3705.  
  3706. const propMaps = new Map();
  3707.  
  3708. function setCustomCSSProperty(element, propName, value) {
  3709. let wm = propMaps.get(propName);
  3710. if (!wm) {
  3711.  
  3712. try {
  3713. window.CSS.registerProperty({
  3714. name: propName,
  3715. syntax: "*",
  3716. inherits: false
  3717. });
  3718. } catch (e) {
  3719. console.warn(e);
  3720. }
  3721.  
  3722. propMaps.set(propName, (wm = new WeakMap()));
  3723. }
  3724.  
  3725. // Create the animation keyframes with the provided property and value
  3726. const keyframes = [{
  3727. [propName]: value
  3728. }];
  3729.  
  3730. let currentAnimation = wm.get(element);
  3731. if (currentAnimation) {
  3732.  
  3733. currentAnimation.effect.setKeyframes(keyframes);
  3734.  
  3735. } else {
  3736.  
  3737.  
  3738.  
  3739. // Set the animation on the element and immediately pause it
  3740. const animation = animate.call(element, keyframes, {
  3741. duration: 1, // Very short duration as we just want to set the value
  3742. fill: 'forwards',
  3743. iterationStart: 1,
  3744. iterations: 2,
  3745. direction: 'alternate'
  3746. });
  3747.  
  3748.  
  3749. // animation.currentTime = 1;
  3750. animation.pause();
  3751.  
  3752. wm.set(element, animation);
  3753.  
  3754.  
  3755. }
  3756.  
  3757. }
  3758.  
  3759. return setCustomCSSProperty;
  3760.  
  3761.  
  3762. })();
  3763.  
  3764.  
  3765. const attrUpdateFn = g[k];
  3766. g['$$original$$' + k] = attrUpdateFn;
  3767. g[k] = function (a, b, c) {
  3768.  
  3769. // console.log(140000, a, b, c);
  3770.  
  3771. let transformType = '';
  3772. let transformValue = 0;
  3773. let transformUnit = '';
  3774.  
  3775. let byPassDefaultFn = false;
  3776. if (b === "transform" && typeof c === 'string') {
  3777.  
  3778. byPassDefaultFn = true;
  3779.  
  3780. const aStyle = a.style;
  3781.  
  3782. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  3783. if (!(a instanceof HTMLElement)) return;
  3784. if (c.length === 0) {
  3785.  
  3786. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  3787. let p = c.substring(7, c.length - 1);
  3788. let q = p.length >= 1 ? parseFloat(p) : -1;
  3789. if (q > -1e-5 && q < 1 + 1e-5) {
  3790. transformType = 'scalex'
  3791. transformValue = q;
  3792. transformUnit = '';
  3793. }
  3794.  
  3795.  
  3796. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  3797.  
  3798. let p = c.substring(11, c.length - 3);
  3799. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3800.  
  3801. if (typeof q === 'number' && !isNaN(q)) {
  3802. transformType = 'translateX'
  3803. transformValue = q;
  3804. transformUnit = 'px';
  3805. }
  3806.  
  3807.  
  3808. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  3809. let p = c.substring(7, c.length - 1);
  3810. let q = p.length >= 1 ? parseFloat(p) : -1;
  3811. if (q > -1e-5 && q < 1 + 1e-5) {
  3812. transformType = 'scaley'
  3813. transformValue = q;
  3814. transformUnit = '';
  3815. }
  3816.  
  3817.  
  3818. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  3819.  
  3820. let p = c.substring(11, c.length - 3);
  3821. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3822.  
  3823. if (typeof q === 'number' && !isNaN(q)) {
  3824. transformType = 'translateY'
  3825. transformValue = q;
  3826. transformUnit = 'px';
  3827. }
  3828.  
  3829.  
  3830. }
  3831.  
  3832. if (transformType) {
  3833.  
  3834. if (transformType === 'scalex' || transformType === 'scaley') {
  3835.  
  3836. const q = transformValue;
  3837.  
  3838.  
  3839. /*
  3840.  
  3841. let vz = Math.round(steppingScaleN * q);
  3842. const customPropName = '--discrete-'+transformType
  3843.  
  3844. const currentValue = aStyle.getPropertyValue(customPropName);
  3845.  
  3846. const transform = (aStyle.transform || '');
  3847. const u = transform.includes(customPropName)
  3848. if (`${currentValue}` === `${vz}`) {
  3849. if (u) return;
  3850. }
  3851.  
  3852.  
  3853. setCSSProp(a,customPropName, vz);
  3854. // aStyle.setProperty(customPropName, vz)
  3855.  
  3856. let ck = '';
  3857.  
  3858. if (c.length === 9) ck = c;
  3859. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3860.  
  3861. if (ck && beforeMq !== ck) {
  3862. aStyle.setProperty('--mq-transform', ck);
  3863. }
  3864.  
  3865. if (u) return;
  3866. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  3867.  
  3868.  
  3869.  
  3870. */
  3871.  
  3872. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  3873.  
  3874. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  3875. const cv = aStyle.transform;
  3876.  
  3877. // console.log(157, cv,c)
  3878.  
  3879. if (c === cv) return;
  3880. // console.log(257, cv,c)
  3881.  
  3882. aStyle.transform = c;
  3883.  
  3884. // return;
  3885.  
  3886. } else if (transformType === 'translateX' || transformType === 'translateY') {
  3887.  
  3888. const q = transformValue;
  3889.  
  3890. /*
  3891.  
  3892. let vz = q.toFixed(1);
  3893. const customPropName = '--discrete-'+transformType
  3894.  
  3895. const aStyle = a.style;
  3896. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  3897.  
  3898.  
  3899. const transform = (aStyle.transform || '');
  3900. const u = transform.includes(customPropName)
  3901. if (parseFloat(currentValue).toFixed(1) === vz) {
  3902. if (u) return;
  3903. }
  3904.  
  3905. setCSSProp(a,customPropName, vz + 'px');
  3906. // aStyle.setProperty(customPropName, vz + 'px')
  3907.  
  3908. let ck = '';
  3909. if (c.length === 15) ck = c;
  3910. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3911.  
  3912. if (ck && beforeMq !== ck) {
  3913. aStyle.setProperty('--mq-transform', ck);
  3914. }
  3915.  
  3916. if (u) return;
  3917. c = `${transformType}(var(--discrete-${transformType}))`;
  3918.  
  3919. */
  3920.  
  3921.  
  3922. const vz = +q.toFixed(1);
  3923.  
  3924. c = `${transformType}(${vz}${transformUnit})`
  3925. const cv = aStyle.transform;
  3926.  
  3927. // console.log(158, cv,c)
  3928.  
  3929. if (c === cv) return;
  3930. // console.log(258, cv,c)
  3931.  
  3932. aStyle.transform = c;
  3933.  
  3934. // return;
  3935.  
  3936. } else {
  3937. throw new Error();
  3938. }
  3939.  
  3940. } else {
  3941. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  3942. const cv = aStyle.transform
  3943. if (!c && !cv) return;
  3944. else if (c === cv) return;
  3945. aStyle.transform = c;
  3946. // return;
  3947. }
  3948.  
  3949. } else if (b === "display") {
  3950.  
  3951. const cv = a.style.display;
  3952. if (!cv && !c) return;
  3953. if (cv === c) return;
  3954.  
  3955.  
  3956. } else if (b === "width") {
  3957.  
  3958. const cv = a.style.width;
  3959. if (!cv && !c) return;
  3960. if (cv === c) return;
  3961.  
  3962. }
  3963.  
  3964. // console.log(130000, a, b, c);
  3965.  
  3966. if (byPassDefaultFn) return;
  3967. return attrUpdateFn.call(this, a, b, c);
  3968. }
  3969.  
  3970.  
  3971. /*
  3972.  
  3973. g.zo = function(a, b, c) {
  3974. if ("string" === typeof b)
  3975. (b = yo(a, b)) && (a.style[b] = c);
  3976. else
  3977. for (var d in b) {
  3978. c = a;
  3979. var e = b[d]
  3980. , f = yo(c, d);
  3981. f && (c.style[f] = e)
  3982. }
  3983. }
  3984.  
  3985.  
  3986. */
  3987.  
  3988.  
  3989. }
  3990.  
  3991.  
  3992.  
  3993. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  3994.  
  3995. if (keyuG) {
  3996.  
  3997. k = keyuG;
  3998.  
  3999. const gk = g[k];
  4000. const gkp = gk.prototype;
  4001.  
  4002.  
  4003. /** @type { Map<string, WeakMap<any, any>> } */
  4004. const ntLogs = new Map();
  4005.  
  4006. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  4007.  
  4008. gkp.updateValue31 = gkp.updateValue;
  4009. gkp.updateValue = function (a, b) {
  4010. if (typeof a !== 'string') return this.updateValue31(a, b);
  4011.  
  4012. const element = this.element;
  4013. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  4014.  
  4015. let ntLog = ntLogs.get(a);
  4016. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  4017.  
  4018. let cache = ntLog.get(element);
  4019. if (cache && cache.value === b) {
  4020. return;
  4021. }
  4022. if (!cache) {
  4023. this.__oldValueByUpdateValue__ = null;
  4024. ntLog.set(element, cache = { value: b });
  4025. } else {
  4026. this.__oldValueByUpdateValue__ = cache.value;
  4027. cache.value = b;
  4028. }
  4029.  
  4030.  
  4031. return this.updateValue31(a, b);
  4032. }
  4033.  
  4034.  
  4035. /*
  4036. g.k.update = function(a) {
  4037. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  4038. c = c.value,
  4039. this.updateValue(c, a[c])
  4040. }
  4041. ;
  4042. g.k.updateValue = function(a, b) {
  4043. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  4044. }
  4045. */
  4046.  
  4047.  
  4048. }
  4049.  
  4050.  
  4051. }
  4052.  
  4053.  
  4054.  
  4055.  
  4056. })();
  4057.  
  4058.  
  4059.  
  4060. FIX_Animation_n_timeline && (async () => {
  4061.  
  4062.  
  4063. const timeline = await new Promise(resolve => {
  4064.  
  4065. let cid = setInterval(() => {
  4066. let t = (((document || 0).timeline || 0) || 0);
  4067. if (t && typeof t._play === 'function') {
  4068.  
  4069. clearInterval(cid);
  4070. resolve(t);
  4071. }
  4072. }, 1);
  4073.  
  4074. promiseForTamerTimeout.then(() => {
  4075. resolve(null)
  4076. });
  4077.  
  4078. });
  4079.  
  4080.  
  4081. const Animation = await new Promise(resolve => {
  4082.  
  4083. let cid = setInterval(() => {
  4084. let t = (((window || 0).Animation || 0) || 0);
  4085. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  4086.  
  4087. clearInterval(cid);
  4088. resolve(t);
  4089. }
  4090. }, 1);
  4091.  
  4092. promiseForTamerTimeout.then(() => {
  4093. resolve(null)
  4094. });
  4095.  
  4096. });
  4097.  
  4098. if (!timeline) return;
  4099. if (!Animation) return;
  4100.  
  4101. const aniProto = Animation.prototype;
  4102. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  4103.  
  4104. const getXroto = (x) => {
  4105. try {
  4106. return x.__proto__;
  4107. } catch (e) { }
  4108. return null;
  4109. }
  4110. const timProto = getXroto(timeline);
  4111. if (!timProto) return;
  4112. if (
  4113. (
  4114. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  4115. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  4116. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  4117. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  4118. )
  4119.  
  4120. ) {
  4121.  
  4122. timProto.nofCQ = 1;
  4123. aniProto.nofYH = 1;
  4124.  
  4125. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  4126.  
  4127.  
  4128. /*
  4129. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  4130. return c._updatePromises();
  4131. });
  4132. */
  4133.  
  4134. const p = Array.prototype.filter;
  4135.  
  4136. let res = null;
  4137. Array.prototype.filter = function () {
  4138.  
  4139. res = this;
  4140. return this;
  4141.  
  4142. };
  4143.  
  4144. _updateAnimationsPromises.call({});
  4145.  
  4146. Array.prototype.filter = p;
  4147.  
  4148. if (res && typeof res.length === 'number') {
  4149. /** @type {any[]} */
  4150. const _res = res;
  4151. return _res;
  4152. }
  4153.  
  4154.  
  4155. return null;
  4156.  
  4157.  
  4158.  
  4159.  
  4160. })(timProto._updateAnimationsPromises);
  4161.  
  4162. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  4163.  
  4164. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  4165.  
  4166. aniProto._updatePromises31 = aniProto._updatePromises;
  4167.  
  4168. /*
  4169. aniProto._updatePromises = function(){
  4170. console.log('eff',this._oldPlayState, this.playState)
  4171. return this._updatePromises31.apply(this, arguments)
  4172. }
  4173. */
  4174.  
  4175. aniProto._updatePromises = function () {
  4176. var oldPlayState = this._oldPlayState;
  4177. var newPlayState = this.playState;
  4178. // console.log('ett', oldPlayState, newPlayState)
  4179. if (newPlayState !== oldPlayState) {
  4180. this._oldPlayState = newPlayState;
  4181. if (this._readyPromise) {
  4182. if ("idle" == newPlayState) {
  4183. this._rejectReadyPromise();
  4184. this._readyPromise = void 0;
  4185. } else if ("pending" == oldPlayState) {
  4186. this._resolveReadyPromise();
  4187. } else if ("pending" == newPlayState) {
  4188. this._readyPromise = void 0;
  4189. }
  4190. }
  4191. if (this._finishedPromise) {
  4192. if ("idle" == newPlayState) {
  4193. this._rejectFinishedPromise();
  4194. this._finishedPromise = void 0;
  4195. } else if ("finished" == newPlayState) {
  4196. this._resolveFinishedPromise();
  4197. } else if ("finished" == oldPlayState) {
  4198. this._finishedPromise = void 0;
  4199. }
  4200. }
  4201. }
  4202. return this._readyPromise || this._finishedPromise;
  4203. };
  4204.  
  4205.  
  4206. let restartWebAnimationsNextTickFlag = false;
  4207.  
  4208. const looperMethodT = () => {
  4209.  
  4210. const runnerFn = (hRes) => {
  4211. var b = timeline;
  4212. b.currentTime = hRes;
  4213. b._discardAnimations();
  4214. if (0 == b._animations.length) {
  4215. restartWebAnimationsNextTickFlag = false;
  4216. } else {
  4217. getRafPromise().then(runnerFn);
  4218. }
  4219. }
  4220.  
  4221. const restartWebAnimationsNextTick = () => {
  4222. if (!restartWebAnimationsNextTickFlag) {
  4223. restartWebAnimationsNextTickFlag = true;
  4224. getRafPromise().then(runnerFn);
  4225. }
  4226. }
  4227.  
  4228. return { restartWebAnimationsNextTick }
  4229. };
  4230.  
  4231.  
  4232. const looperMethodN = () => {
  4233.  
  4234. const acs = document.createElement('a-f');
  4235. acs.id = 'a-f';
  4236.  
  4237. const style = document.createElement('style');
  4238. style.textContent = `
  4239. @keyFrames aF1 {
  4240. 0% {
  4241. order: 0;
  4242. }
  4243. 100% {
  4244. order: 6;
  4245. }
  4246. }
  4247. #a-f[id] {
  4248. visibility: collapse !important;
  4249. position: fixed !important;
  4250. top: -100px !important;
  4251. left: -100px !important;
  4252. margin:0 !important;
  4253. padding:0 !important;
  4254. outline:0 !important;
  4255. border:0 !important;
  4256. z-index:-1 !important;
  4257. width: 0px !important;
  4258. height: 0px !important;
  4259. contain: strict !important;
  4260. pointer-events: none !important;
  4261. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  4262. }
  4263. `;
  4264. (document.head || document.documentElement).appendChild(style);
  4265.  
  4266. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  4267.  
  4268. const _onanimationiteration = function (evt) {
  4269. const hRes = evt.timeStamp;
  4270. var b = timeline;
  4271. b.currentTime = hRes;
  4272. b._discardAnimations();
  4273. if (0 == b._animations.length) {
  4274. restartWebAnimationsNextTickFlag = false;
  4275. acs.onanimationiteration = null;
  4276. } else {
  4277. acs.onanimationiteration = _onanimationiteration;
  4278. }
  4279.  
  4280. }
  4281.  
  4282.  
  4283.  
  4284. const restartWebAnimationsNextTick = () => {
  4285. if (!restartWebAnimationsNextTickFlag) {
  4286. restartWebAnimationsNextTickFlag = true;
  4287. acs.onanimationiteration = _onanimationiteration;
  4288.  
  4289. }
  4290. }
  4291.  
  4292. return { restartWebAnimationsNextTick }
  4293. };
  4294.  
  4295.  
  4296.  
  4297. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  4298.  
  4299.  
  4300. // console.log(571, timProto);
  4301. timProto._play = function (c) {
  4302. c = new Animation(c, this);
  4303. this._animations.push(c);
  4304. restartWebAnimationsNextTick();
  4305. c._updatePromises();
  4306. c._animation.play();
  4307. c._updatePromises();
  4308. return c
  4309. }
  4310.  
  4311. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  4312. originalAnimationsWithPromises.length = 0;
  4313. originalAnimationsWithPromises.push = null;
  4314. originalAnimationsWithPromises.splice = null;
  4315. originalAnimationsWithPromises.slice = null;
  4316. originalAnimationsWithPromises.indexOf = null;
  4317. originalAnimationsWithPromises.unshift = null;
  4318. originalAnimationsWithPromises.shift = null;
  4319. originalAnimationsWithPromises.pop = null;
  4320. originalAnimationsWithPromises.filter = null;
  4321. originalAnimationsWithPromises.forEach = null;
  4322. originalAnimationsWithPromises.map = null;
  4323.  
  4324.  
  4325. const _updateAnimationsPromises = () => {
  4326. animationsWithPromisesMap.forEach(c => {
  4327. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  4328. });
  4329. /*
  4330. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  4331. return c._updatePromises();
  4332. });
  4333. */
  4334. }
  4335.  
  4336. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  4337.  
  4338. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  4339.  
  4340. delete timProto._updateAnimationsPromises;
  4341. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  4342. get() {
  4343. if (animationsWithPromisesMap.size === 0) return nilFn;
  4344. return _updateAnimationsPromises;
  4345. },
  4346. set(nv) {
  4347. delete this._updateAnimationsPromises;
  4348. this._updateAnimationsPromises = nv;
  4349. },
  4350. enumerable: true,
  4351. configurable: true,
  4352. });
  4353.  
  4354.  
  4355. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  4356. aniProto.__finished_native_get__ = pdFinished.get;
  4357. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  4358.  
  4359.  
  4360. Object.defineProperty(aniProto, 'finished', {
  4361. get() {
  4362. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  4363. this._finishedPromise = new Promise((resolve, reject) => {
  4364. this._resolveFinishedPromise = function () {
  4365. resolve(this)
  4366. };
  4367. this._rejectFinishedPromise = function () {
  4368. reject({
  4369. type: DOMException.ABORT_ERR,
  4370. name: "AbortError"
  4371. })
  4372. };
  4373. }),
  4374. "finished" == this.playState && this._resolveFinishedPromise());
  4375. return this._finishedPromise
  4376. },
  4377. set: undefined,
  4378. enumerable: true,
  4379. configurable: true
  4380. });
  4381.  
  4382. }
  4383.  
  4384.  
  4385.  
  4386. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  4387. aniProto.__ready_native_get__ = pdReady.get;
  4388. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  4389.  
  4390. Object.defineProperty(aniProto, 'ready', {
  4391. get() {
  4392. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  4393. this._readyPromise = new Promise((resolve, reject) => {
  4394. this._resolveReadyPromise = function () {
  4395. resolve(this)
  4396. };
  4397. this._rejectReadyPromise = function () {
  4398. reject({
  4399. type: DOMException.ABORT_ERR,
  4400. name: "AbortError"
  4401. })
  4402. };
  4403. }),
  4404. "pending" !== this.playState && this._resolveReadyPromise());
  4405. return this._readyPromise
  4406. },
  4407. set: undefined,
  4408. enumerable: true,
  4409. configurable: true
  4410. });
  4411.  
  4412. }
  4413.  
  4414.  
  4415. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  4416.  
  4417. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  4418. const _rebuildUnderlyingAnimation = function () {
  4419. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  4420. this.effect && this.effect._onsample && (this.effect._onsample = null);
  4421. return this._rebuildUnderlyingAnimation21();
  4422. }
  4423. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  4424. // delete aniProto._rebuildUnderlyingAnimation;
  4425. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  4426. // get() {
  4427. // if (isNaN(this._sequenceNumber)) return nilFn;
  4428. // return this._rebuildUnderlyingAnimation21;
  4429. // },
  4430. // set(nv) {
  4431. // delete this._rebuildUnderlyingAnimation;
  4432. // this._rebuildUnderlyingAnimation = nv;
  4433. // },
  4434. // enumerable: true,
  4435. // configurable: true
  4436. // });
  4437. }
  4438.  
  4439.  
  4440. /*
  4441.  
  4442.  
  4443. function f(c) {
  4444. var b = v.timeline;
  4445. b.currentTime = c;
  4446. b._discardAnimations();
  4447. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  4448. }
  4449. var h = window.requestAnimationFrame;
  4450. window.requestAnimationFrame = function(c) {
  4451. return h(function(b) {
  4452. v.timeline._updateAnimationsPromises();
  4453. c(b);
  4454. v.timeline._updateAnimationsPromises()
  4455. })
  4456. }
  4457. ;
  4458. v.AnimationTimeline = function() {
  4459. this._animations = [];
  4460. this.currentTime = void 0
  4461. }
  4462. ;
  4463. v.AnimationTimeline.prototype = {
  4464. getAnimations: function() {
  4465. this._discardAnimations();
  4466. return this._animations.slice()
  4467. },
  4468. _updateAnimationsPromises: function() {
  4469. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  4470. return c._updatePromises()
  4471. })
  4472. },
  4473. _discardAnimations: function() {
  4474. this._updateAnimationsPromises();
  4475. this._animations = this._animations.filter(function(c) {
  4476. return "finished" != c.playState && "idle" != c.playState
  4477. })
  4478. },
  4479. _play: function(c) {
  4480. c = new v.Animation(c,this);
  4481. this._animations.push(c);
  4482. v.restartWebAnimationsNextTick();
  4483. c._updatePromises();
  4484. c._animation.play();
  4485. c._updatePromises();
  4486. return c
  4487. },
  4488. play: function(c) {
  4489. c && c.remove();
  4490. return this._play(c)
  4491. }
  4492. };
  4493. var d = !1;
  4494. v.restartWebAnimationsNextTick = function() {
  4495. d || (d = !0,
  4496. requestAnimationFrame(f))
  4497. }
  4498. ;
  4499. var a = new v.AnimationTimeline;
  4500. v.timeline = a;
  4501. try {
  4502. Object.defineProperty(window.document, "timeline", {
  4503. configurable: !0,
  4504. get: function() {
  4505. return a
  4506. }
  4507. })
  4508. } catch (c) {}
  4509. try {
  4510. window.document.timeline = a
  4511. } catch (c) {}
  4512.  
  4513. */
  4514.  
  4515.  
  4516.  
  4517. /*
  4518.  
  4519. var g = window.getComputedStyle;
  4520. Object.defineProperty(window, "getComputedStyle", {
  4521. configurable: !0,
  4522. enumerable: !0,
  4523. value: function() {
  4524. v.timeline._updateAnimationsPromises();
  4525. var e = g.apply(this, arguments);
  4526. h() && (e = g.apply(this, arguments));
  4527. v.timeline._updateAnimationsPromises();
  4528. return e
  4529. }
  4530. });
  4531.  
  4532. */
  4533.  
  4534.  
  4535.  
  4536.  
  4537. }
  4538.  
  4539.  
  4540.  
  4541.  
  4542. })();
  4543.  
  4544.  
  4545.  
  4546.  
  4547. promiseForCustomYtElementsReady.then(() => {
  4548.  
  4549. FIX_ytdExpander_childrenChanged && customElements.whenDefined('ytd-expander').then(() => {
  4550.  
  4551.  
  4552.  
  4553. let dummy;
  4554. let cProto;
  4555.  
  4556.  
  4557.  
  4558. dummy = document.createElement('ytd-expander');
  4559. cProto = insp(dummy).constructor.prototype;
  4560.  
  4561.  
  4562. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  4563.  
  4564.  
  4565. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  4566. cProto.childrenChanged14 = cProto.childrenChanged;
  4567.  
  4568. cProto.initChildrenObserver = function () {
  4569. var a = this;
  4570. this.observer = new MutationObserver(function () {
  4571. a.childrenChanged()
  4572. }
  4573. );
  4574. this.observer.observe(this.content, {
  4575. subtree: !0,
  4576. childList: !0,
  4577. attributes: !0,
  4578. characterData: !0
  4579. });
  4580. this.childrenChanged()
  4581. }
  4582. ;
  4583. cProto.childrenChanged = function () {
  4584. if (this.alwaysToggleable) {
  4585. this.canToggle = this.alwaysToggleable;
  4586. } else if (!this.canToggleJobId) {
  4587. this.canToggleJobId = 1;
  4588. getRafPromise().then(() => {
  4589. this.canToggleJobId = 0;
  4590. this.calculateCanCollapse()
  4591. })
  4592. }
  4593. }
  4594.  
  4595.  
  4596. // console.log(cProto.initChildrenObserver)
  4597. console.debug('ytd-expander-fix-childrenChanged');
  4598.  
  4599. }
  4600.  
  4601. })
  4602.  
  4603.  
  4604.  
  4605. FIX_paper_ripple_animate && customElements.whenDefined('paper-ripple').then(() => {
  4606.  
  4607.  
  4608.  
  4609. let dummy;
  4610. let cProto;
  4611. dummy = document.createElement('paper-ripple');
  4612. cProto = insp(dummy).constructor.prototype;
  4613.  
  4614. if (fnIntegrity(cProto.animate, '0.74.5')) {
  4615.  
  4616.  
  4617. cProto.animate34 = cProto.animate;
  4618. cProto.animate = function () {
  4619. if (this._animating) {
  4620. var a;
  4621. const ripples = this.ripples;
  4622. for (a = 0; a < ripples.length; ++a) {
  4623. var b = ripples[a];
  4624. b.draw();
  4625. this.$.background.style.opacity = b.outerOpacity;
  4626. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  4627. }
  4628. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  4629. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  4630. getRafPromise().then(this._boundAnimate38);
  4631. } else {
  4632. this.onAnimationComplete()
  4633. }
  4634. }
  4635. }
  4636.  
  4637. console.debug('FIX_paper_ripple_animate')
  4638.  
  4639. // console.log(cProto.animate)
  4640.  
  4641. }
  4642.  
  4643. });
  4644.  
  4645. if (FIX_doIdomRender) {
  4646.  
  4647.  
  4648. const xsetTimeout = function (f, d) {
  4649. if (xsetTimeout.m511 === 1 && !d) {
  4650. xsetTimeout.m511 = 2;
  4651. getRafPromise().then(f);
  4652. } else {
  4653. return setTimeout.apply(window, arguments)
  4654. }
  4655.  
  4656. }
  4657.  
  4658. const xrequestAnimationFrame = function (f) {
  4659. const h = f + "";
  4660. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  4661. xsetTimeout.m511 = 1;
  4662. f();
  4663. xsetTimeout.m511 = 0;
  4664. } else if (h.includes("requestAninmationFrameResolver")) {
  4665. getRafPromise().then(f);
  4666. } else {
  4667. return requestAnimationFrame.apply(window, arguments);
  4668. }
  4669. }
  4670.  
  4671. let busy = false;
  4672. const doIdomRender = function () {
  4673. if (busy) {
  4674. return this.doIdomRender13.apply(this, arguments);
  4675. }
  4676. busy = true;
  4677. const { requestAnimationFrame, setTimeout } = window;
  4678. window.requestAnimationFrame = xrequestAnimationFrame;
  4679. window.setTimeout = xsetTimeout;
  4680. let r = this.doIdomRender13.apply(this, arguments);
  4681. window.requestAnimationFrame = requestAnimationFrame;
  4682. window.setTimeout = setTimeout;
  4683. busy = false;
  4684. return r;
  4685. };
  4686. 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']) {
  4687.  
  4688.  
  4689. customElements.whenDefined(ytTag).then(() => {
  4690.  
  4691. let dummy;
  4692. let cProto;
  4693. dummy = document.createElement(ytTag);
  4694. cProto = insp(dummy).constructor.prototype;
  4695.  
  4696. cProto.doIdomRender13 = cProto.doIdomRender;
  4697. cProto.doIdomRender = doIdomRender;
  4698.  
  4699. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  4700.  
  4701. console.debug('FIX_doIdomRender', ytTag)
  4702.  
  4703.  
  4704.  
  4705. });
  4706.  
  4707. }
  4708.  
  4709. }
  4710.  
  4711.  
  4712.  
  4713. });
  4714.  
  4715. });
  4716.  
  4717.  
  4718. setupEvents();
  4719.  
  4720.  
  4721.  
  4722. if (isMainWindow) {
  4723.  
  4724. console.groupCollapsed(
  4725. "%cYouTube JS Engine Tamer",
  4726. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  4727. );
  4728.  
  4729.  
  4730.  
  4731. console.log("Script is loaded.");
  4732. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  4733.  
  4734. console.log("This script is experimental and subject to further changes.");
  4735.  
  4736. console.log("This might boost your YouTube performance.");
  4737.  
  4738. console.log("CAUTION: This might break your YouTube.");
  4739.  
  4740.  
  4741. if (prepareLogs.length >= 1) {
  4742. console.log(" =========================================================================== ");
  4743.  
  4744. for (const msg of prepareLogs) {
  4745. console.log(msg)
  4746. }
  4747.  
  4748. console.log(" =========================================================================== ");
  4749. }
  4750.  
  4751. console.groupEnd();
  4752.  
  4753. }
  4754.  
  4755.  
  4756.  
  4757.  
  4758.  
  4759.  
  4760. })();