YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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