YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2023-12-09 提交的版本,查看 最新版本

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