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