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