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.55
  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)) {
  1318.  
  1319.  
  1320.  
  1321.  
  1322. const f = h.rendererStamperApplyChangeRecord_;
  1323. h.rendererStamperApplyChangeRecord31_ = f;
  1324. const g = ump3.get(f) || function (a, b, c) {
  1325. if (isMainRenderer(this) || (this.updateChildVisibilityProperties && !this.markDirty)) {
  1326. let b = false;
  1327. if (!this.markDirty) {
  1328. b = true;
  1329. } else if (!this.localVisibilityObserver_) {
  1330. // b = false
  1331. } else if (!this.visibilityObserverForChild_ && !!this.getVisibilityObserverForChild) {
  1332. b = true;
  1333. }
  1334. if (b) {
  1335. return f.apply(this, arguments);
  1336. }
  1337. }
  1338.  
  1339. // sequence on the same proto
  1340. this[qm47] = (this[qm47] || Promise.resolve()).then(() => this.rendererStamperApplyChangeRecord31_(a, b, c)).catch(console.log);
  1341. }
  1342. ump3.set(f, g);
  1343. g.km31 = 1;
  1344. h.rendererStamperApplyChangeRecord_ = g;
  1345.  
  1346.  
  1347. }
  1348.  
  1349.  
  1350.  
  1351.  
  1352. /*
  1353. if (typeof h.rendererStamperObserver_ === 'function' && !(h.rendererStamperObserver_.km34)) {
  1354.  
  1355. const f = h.rendererStamperObserver_;
  1356. const g = ump3.get(f) || function (a, b, c) {
  1357. if (isMainRenderer(this)) {
  1358. return f.apply(this, arguments);
  1359. }
  1360. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1361. }
  1362. ump3.set(f, g);
  1363. g.km34 = 1;
  1364. h.rendererStamperObserver_ = g;
  1365.  
  1366. }
  1367.  
  1368.  
  1369. if (typeof h.rendererStamperApplyChangeRecord_ === 'function' && !(h.rendererStamperApplyChangeRecord_.km34)) {
  1370.  
  1371. const f = h.rendererStamperApplyChangeRecord_;
  1372. const g = ump3.get(f) || function () {
  1373. if (isMainRenderer(this)) {
  1374. return f.apply(this, arguments);
  1375. }
  1376. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1377. }
  1378. ump3.set(f, g);
  1379. g.km34 = 1;
  1380. h.rendererStamperApplyChangeRecord_ = g;
  1381.  
  1382. }
  1383.  
  1384.  
  1385.  
  1386. if (typeof h.flushRenderStamperComponentBindings_ === 'function' && !(h.flushRenderStamperComponentBindings_.km34)) {
  1387.  
  1388. const f = h.flushRenderStamperComponentBindings_;
  1389. const g = ump3.get(f) || function () {
  1390. if (isMainRenderer(this)) {
  1391. return f.apply(this, arguments);
  1392. }
  1393. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1394. }
  1395. ump3.set(f, g);
  1396. g.km34 = 1;
  1397. h.flushRenderStamperComponentBindings_ = g;
  1398.  
  1399. }
  1400.  
  1401.  
  1402. if (typeof h.forwardRendererStamperChanges_ === 'function' && !(h.forwardRendererStamperChanges_.km34)) {
  1403.  
  1404. const f = h.forwardRendererStamperChanges_;
  1405. const g = ump3.get(f) || function () {
  1406. if (isMainRenderer(this)) {
  1407. return f.apply(this, arguments);
  1408. }
  1409. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1410. }
  1411. ump3.set(f, g);
  1412. g.km34 = 1;
  1413. h.forwardRendererStamperChanges_ = g;
  1414.  
  1415. }
  1416. */
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422. // console.log(123)
  1423.  
  1424. // return;
  1425.  
  1426.  
  1427. /*
  1428.  
  1429. // buggy for page swtiching
  1430.  
  1431. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km31)) {
  1432.  
  1433.  
  1434.  
  1435.  
  1436. const f = h.dataChanged_;
  1437. h.dataChanged31_ = f;
  1438. const g = ump3.get(f) || function (...args) {
  1439.  
  1440. if (isMainRenderer(this)) {
  1441. return f.apply(this, arguments);
  1442. }
  1443.  
  1444. // sequence on the same proto
  1445. this[qm47] = (this[qm47] || Promise.resolve()).then(() => this.dataChanged31_(...args)).catch(console.log);
  1446. }
  1447. ump3.set(f, g);
  1448. g.km31 = 1;
  1449. h.dataChanged_ = g;
  1450.  
  1451.  
  1452. }
  1453. */
  1454.  
  1455.  
  1456. /*
  1457.  
  1458. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km34)) {
  1459.  
  1460. const f = h.dataChanged_;
  1461. const g = ump3.get(f) || function () {
  1462. if (isMainRenderer(this)) {
  1463. return f.apply(this, arguments);
  1464. }
  1465. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1466. }
  1467. ump3.set(f, g);
  1468. g.km34 = 1;
  1469. h.dataChanged_ = g;
  1470.  
  1471. }
  1472. */
  1473.  
  1474.  
  1475.  
  1476. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  1477.  
  1478. const f = h.tryRenderChunk_;
  1479. const g = ump3.get(f) || function () {
  1480. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1481. }
  1482. ump3.set(f, g);
  1483. g.km34 = 1;
  1484. h.tryRenderChunk_ = g;
  1485.  
  1486. }
  1487.  
  1488.  
  1489. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  1490.  
  1491. const f = h.renderChunk_;
  1492. const g = ump3.get(f) || function () {
  1493. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1494. }
  1495. ump3.set(f, g);
  1496. g.km34 = 1;
  1497. h.renderChunk_ = g;
  1498.  
  1499. }
  1500.  
  1501. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  1502.  
  1503. const f = h.deepLazyListObserver_;
  1504. const g = ump3.get(f) || function () {
  1505. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1506. }
  1507. ump3.set(f, g);
  1508. g.km34 = 1;
  1509. h.deepLazyListObserver_ = g;
  1510.  
  1511. }
  1512.  
  1513.  
  1514. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  1515.  
  1516. const f = h.onItemsUpdated_;
  1517. const g = ump3.get(f) || function () {
  1518. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1519. }
  1520. ump3.set(f, g);
  1521. g.km34 = 1;
  1522. h.onItemsUpdated_ = g;
  1523.  
  1524. }
  1525.  
  1526. /*
  1527. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1528. if (typeof h.updateChangeRecord_ === 'function' && !(h.updateChangeRecord_.km34)) {
  1529.  
  1530. const f = h.updateChangeRecord_;
  1531. const g = ump3.get(f) || function () {
  1532. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1533. }
  1534. ump3.set(f, g);
  1535. g.km34 = 1;
  1536. h.updateChangeRecord_ = g;
  1537.  
  1538. }
  1539. */
  1540.  
  1541.  
  1542. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  1543.  
  1544. const f = h.requestRenderChunk_;
  1545. const g = ump3.get(f) || function () {
  1546. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1547. }
  1548. ump3.set(f, g);
  1549. g.km34 = 1;
  1550. h.requestRenderChunk_ = g;
  1551.  
  1552. }
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558. return;
  1559.  
  1560.  
  1561.  
  1562. /*
  1563. if (typeof h.cancelPendingTasks_ === 'function' && !(h.cancelPendingTasks_.km34)) {
  1564.  
  1565. const f = h.cancelPendingTasks_;
  1566. const g = ump3.get(f) || function () {
  1567. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1568. }
  1569. ump3.set(f, g);
  1570. g.km34 = 1;
  1571. h.cancelPendingTasks_ = g;
  1572.  
  1573. }
  1574.  
  1575.  
  1576. if (typeof h.fillRange_ === 'function' && !(h.fillRange_.km34)) {
  1577.  
  1578. const f = h.fillRange_;
  1579. const g = ump3.get(f) || function () {
  1580. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1581. }
  1582. ump3.set(f, g);
  1583. g.km34 = 1;
  1584. h.fillRange_ = g;
  1585.  
  1586. }
  1587. */
  1588.  
  1589.  
  1590.  
  1591.  
  1592. if (typeof h.addTextNodes_ === 'function' && !(h.addTextNodes_.km34)) {
  1593.  
  1594. const f = h.addTextNodes_;
  1595. const g = function () {
  1596. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1597. }
  1598. g.km34 = 1;
  1599. h.addTextNodes_ = g;
  1600.  
  1601. }
  1602.  
  1603.  
  1604.  
  1605.  
  1606. if (typeof h.updateText_ === 'function' && !(h.updateText_.km34)) {
  1607.  
  1608. const f = h.updateText_;
  1609. const g = function () {
  1610. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1611. }
  1612. g.km34 = 1;
  1613. h.updateText_ = g;
  1614.  
  1615. }
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621. if (typeof h.stampTypeChanged_ === 'function' && !(h.stampTypeChanged_.km34)) {
  1622.  
  1623. const f = h.stampTypeChanged_;
  1624. const g = function () {
  1625. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1626. }
  1627. g.km34 = 1;
  1628. h.stampTypeChanged_ = g;
  1629.  
  1630. }
  1631.  
  1632.  
  1633.  
  1634.  
  1635. // console.log(166)
  1636.  
  1637.  
  1638.  
  1639.  
  1640. }
  1641.  
  1642. const keyStConnectedCallback = Symbol(); // avoid copying the value
  1643.  
  1644. const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  1645. const cmf = new WeakMap();
  1646. const dmf = new WeakMap();
  1647.  
  1648. const gvGenerator = (nv) => {
  1649. return function () {
  1650. const cnt = insp(this);
  1651. const hostElement = cnt.hostElement || 0;
  1652. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  1653. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  1654. if (p && (!dollar && !this.is)) {
  1655. const nodeName = hostElement.nodeName;
  1656. if (typeof nodeName !== 'string') {
  1657. // just in case
  1658. } else if (nodeName.startsWith("DOM-")) {
  1659. // dom-if, dom-repeat, etc
  1660. } else {
  1661. // yt element - new model, yt-xxxx, anixxxxxx
  1662. p = false;
  1663. }
  1664. }
  1665. if (p) {
  1666. if (typeof cnt.markDirty === 'function') {
  1667. // the yt element might call markDirty (occasionally)
  1668. p = false;
  1669. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  1670. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1671. p = false;
  1672. }
  1673. }
  1674. if (p) {
  1675.  
  1676. // << dom-repeat & dom-if >>
  1677.  
  1678. // sequence on the same instance
  1679. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  1680. } else {
  1681. nv.apply(this, arguments);
  1682. }
  1683. };
  1684. }
  1685.  
  1686. const setupWeakRef = (h) => {
  1687.  
  1688.  
  1689. if (WEAK_REF_BINDING && !h.kz62 && setup$ && setupD && setupDataHost && (h.is || h.__dataHost)) {
  1690.  
  1691. let skip = false;
  1692. // if (h.is && typeof h.is === 'string' && h.is.length > 15 && h.is.length < 30) {
  1693. // if (h.is.includes('yt-') && !h.$ && h.is.length !== 20 && h.is.length !== 21 && h.is.length !== 22) {
  1694. // skip = true;
  1695. // // return;
  1696. // }
  1697. // }
  1698.  
  1699. h.kz62 = 1;
  1700.  
  1701. //
  1702.  
  1703. setup$(h);
  1704. const hostElement = h.hostElement;
  1705.  
  1706. if (hostElement !== h) {
  1707.  
  1708. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  1709. setupD(h, s);
  1710.  
  1711. }
  1712.  
  1713. const dh = h.__dataHost;
  1714.  
  1715. setupDataHost(dh, skip)
  1716. }
  1717.  
  1718.  
  1719.  
  1720.  
  1721. if (hostElement) {
  1722.  
  1723. for (const s of ['__dataHost', '__CE_shadowRoot', '__template', '__templatizeOwner']) {
  1724. setupD(hostElement, s);
  1725.  
  1726. }
  1727.  
  1728. const dh = hostElement.__dataHost;
  1729.  
  1730. setupDataHost(dh, skip)
  1731.  
  1732.  
  1733.  
  1734.  
  1735. aDelay().then(() => {
  1736. setupD(hostElement, '__CE_shadowRoot');
  1737. });
  1738.  
  1739.  
  1740. }
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746. }
  1747.  
  1748. }
  1749.  
  1750.  
  1751. let nativeHTMLElement = window.HTMLElement;
  1752.  
  1753. try {
  1754.  
  1755. const q = document.createElement('template');
  1756. q.innerHTML = '<ytz-null361></ytz-null361>';
  1757. nativeHTMLElement = q.content.firstChild.constructor
  1758.  
  1759. } catch (e) { }
  1760.  
  1761. if (!nativeHTMLElement.prototype.connectedCallback) {
  1762. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  1763. nativeHTMLElement.prototype.connectedCallback = function () {
  1764. let r;
  1765. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  1766.  
  1767. if (WEAK_REF_BINDING && (this instanceof Node) && (this.is || this.__dataHost)) {
  1768. setupWeakRef(this)
  1769. // setupWeakRef(this.__dataHost)
  1770. }
  1771. return r;
  1772. }
  1773. }
  1774.  
  1775. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  1776. get() {
  1777. const f = this[keyStConnectedCallback];
  1778. if (this.is) {
  1779. setupDiscreteTasks(this, true);
  1780. if (f) this.ky36 = 1;
  1781. }
  1782. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  1783. setupWeakRef(this)
  1784. }
  1785. return f;
  1786. },
  1787. set(nv) {
  1788. let gv;
  1789. if (typeof nv === 'function') {
  1790.  
  1791. gv = cmf.get(nv) || gvGenerator(nv);
  1792. if (gv !== nv) {
  1793. cmf.set(nv, gv);
  1794. cmf.set(gv, gv);
  1795. dmf.set(gv, nv);
  1796. }
  1797.  
  1798. } else {
  1799. gv = nv;
  1800. }
  1801. this[keyStConnectedCallback] = gv; // proto or object
  1802. if (this.is) {
  1803. setupDiscreteTasks(this);
  1804. }
  1805. if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  1806. setupWeakRef(this)
  1807. }
  1808. return true;
  1809. },
  1810. enumerable: false,
  1811. configurable: true
  1812.  
  1813. });
  1814.  
  1815. const pLoad = new Promise(resolve => {
  1816. if (document.readyState !== 'loading') {
  1817. resolve();
  1818. } else {
  1819. window.addEventListener("DOMContentLoaded", resolve, false);
  1820. }
  1821. });
  1822. pLoad.then(() => {
  1823.  
  1824. let nonce = document.querySelector('style[nonce]');
  1825. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1826. const st = document.createElement('style');
  1827. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1828. st.textContent = "none-element-k47{order:0}";
  1829. st.addEventListener('load', () => {
  1830. pf31.resolve();
  1831. p59 = 1;
  1832. }, false);
  1833. document.body.appendChild(st);
  1834.  
  1835.  
  1836. // console.debug('90002', location.pathname)
  1837. // console.log(90000, location.pathname)
  1838.  
  1839. });
  1840.  
  1841. const prepareLogs = [];
  1842.  
  1843. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  1844.  
  1845. let winError00 = window.onerror;
  1846.  
  1847. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  1848.  
  1849. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  1850.  
  1851. ; FIX_Iframe_NULL_SRC && (() => {
  1852.  
  1853. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  1854. const lcOpt = { sensitivity: 'base' };
  1855. document.createElement24 = document.createElement;
  1856. document.createElement = function (t) {
  1857. if (typeof t === 'string' && t.length === 6) {
  1858. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  1859. const p = this.createElement24(t);
  1860. const stack = new Error().stack;
  1861. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  1862. if (!isSearchbox) {
  1863. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  1864. }
  1865. return p;
  1866. }
  1867. }
  1868. return this.createElement24.apply(this, arguments);
  1869. };
  1870.  
  1871. })();
  1872.  
  1873. ; fix_error_many_stack_state === 1 && (() => {
  1874.  
  1875.  
  1876. let p1 = winError00;
  1877.  
  1878. let stackNeedleDetails = null;
  1879.  
  1880. Object.defineProperty(Object.prototype, 'matchAll', {
  1881. get() {
  1882. stackNeedleDetails = this;
  1883. return true;
  1884. },
  1885. enumerable: true,
  1886. configurable: true
  1887. });
  1888.  
  1889. try {
  1890. JSON.parse("{}");
  1891. } catch (e) {
  1892. console.warn(e)
  1893. fix_error_many_stack_state = 0;
  1894. }
  1895.  
  1896. delete Object.prototype['matchAll'];
  1897.  
  1898. let p2 = window.onerror;
  1899.  
  1900. window.onerror = p1;
  1901.  
  1902. if (fix_error_many_stack_state === 0) return;
  1903.  
  1904. if (stackNeedleDetails) {
  1905. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1906. stackNeedleDetails.matchAll = true;
  1907. }
  1908.  
  1909. if (p1 === p2) return (fix_error_many_stack_state = 0);
  1910.  
  1911. // p1!==p2
  1912. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  1913.  
  1914. })();
  1915.  
  1916. ; fix_error_many_stack_state === 2 && (() => {
  1917.  
  1918.  
  1919. let p1 = winError00;
  1920.  
  1921. let objectPrune = null;
  1922. let stackNeedleDetails = null;
  1923.  
  1924. Object.defineProperty(Function.prototype, 'findOwner', {
  1925. get() {
  1926. objectPrune = this;
  1927. return this._findOwner;
  1928. },
  1929. set(nv) {
  1930. this._findOwner = nv;
  1931. return true;
  1932. },
  1933. enumerable: true,
  1934. configurable: true
  1935. });
  1936.  
  1937. Object.defineProperty(Object.prototype, 'matchAll', {
  1938. get() {
  1939. stackNeedleDetails = this;
  1940. return true;
  1941. },
  1942. enumerable: true,
  1943. configurable: true
  1944. });
  1945.  
  1946. try {
  1947. JSON.parse("{}");
  1948. } catch (e) {
  1949. console.warn(e)
  1950. fix_error_many_stack_state = 0;
  1951. }
  1952.  
  1953. delete Function.prototype['findOwner'];
  1954. delete Object.prototype['matchAll'];
  1955.  
  1956. let p2 = window.onerror;
  1957.  
  1958. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  1959.  
  1960. if (fix_error_many_stack_state == 0) return;
  1961.  
  1962. // the following will only execute when Brave's scriptlets.js is executed.
  1963.  
  1964. prepareLogs.push("fix_error_many_stack_state NB")
  1965.  
  1966. if (stackNeedleDetails) {
  1967. stackNeedleDetails.pattern = null;
  1968. stackNeedleDetails.re = null;
  1969. stackNeedleDetails.expect = null;
  1970. stackNeedleDetails.matchAll = true;
  1971. }
  1972.  
  1973. if (objectPrune) {
  1974. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  1975. delete objectPrune._findOwner;
  1976. }
  1977.  
  1978. fix_error_many_stack_state = 3;
  1979. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1980. JSON.parse.objectPrune = objectPrune;
  1981.  
  1982. })();
  1983.  
  1984. ; fix_error_many_stack_state === 3 && (() => {
  1985.  
  1986.  
  1987. let p1 = winError00;
  1988.  
  1989. try {
  1990. JSON.parse("{}");
  1991. } catch (e) {
  1992. console.warn(e)
  1993. fix_error_many_stack_state = 0;
  1994. }
  1995.  
  1996. let p2 = window.onerror;
  1997.  
  1998. if (p1 === p2) return;
  1999.  
  2000. window.onerror = p1;
  2001.  
  2002. if (fix_error_many_stack_state === 0) return;
  2003.  
  2004. fix_error_many_stack_state = 4; // p1 != p2
  2005.  
  2006.  
  2007. })();
  2008.  
  2009. fix_error_many_stack_state === 4 && (() => {
  2010.  
  2011. // the following will only execute when Brave's scriptlets.js is executed.
  2012.  
  2013. prepareLogs.push("fix_error_many_stack_state AB")
  2014.  
  2015. JSON.parseProxy = JSON.parse;
  2016.  
  2017. JSON.parse = ((parse) => {
  2018.  
  2019. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  2020. return function (text, reviver) {
  2021. const onerror = window.onerror;
  2022. window.onerror = null;
  2023. let r;
  2024. try {
  2025. r = parse(...arguments);
  2026. } catch (e) {
  2027. r = e;
  2028. }
  2029. window.onerror = onerror;
  2030. if (r instanceof Error) {
  2031. throw r;
  2032. }
  2033. return r;
  2034. }
  2035.  
  2036. })(JSON.parse);
  2037.  
  2038.  
  2039. })();
  2040.  
  2041.  
  2042.  
  2043. // ================================================ 0.4.5 ================================================
  2044.  
  2045.  
  2046. // ; (() => {
  2047.  
  2048. // if (FIX_error_many_stack && self instanceof Window) {
  2049. // // infinite stack due to matchesStackTrace inside objectPrune of AdsBlock
  2050.  
  2051. // const pdK = Object.getOwnPropertyDescriptor(window, 'onerror');
  2052. // if (!pdK || (pdK.get && pdK.configurable)) {
  2053.  
  2054. // } else {
  2055. // return;
  2056. // }
  2057.  
  2058. // let unsupportErrorFix = false;
  2059.  
  2060. // let firstHook = true;
  2061. // let busy33 = false;
  2062.  
  2063. // let state = 0;
  2064.  
  2065. // if (pdK) {
  2066. // delete window['onerror'];
  2067. // }
  2068.  
  2069. // const pd = {
  2070. // get() {
  2071. // const stack = (new Error()).stack;
  2072. // // targetStack = stack;
  2073. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  2074. // state = isGetExceptionToken ? 1 : 0;
  2075. // delete Window.prototype['onerror'];
  2076. // let r = pdK ? pdK.get.call(this) : this.onerror;
  2077. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2078. // // console.log('onerror get', r)
  2079. // return r;
  2080. // },
  2081. // set(nv) {
  2082. // const stack = (new Error()).stack;
  2083. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  2084. // state = state === 1 && isGetExceptionToken ? 2 : 0;
  2085. // /** @type {string?} */
  2086. // let sToken = null;
  2087. // if (unsupportErrorFix || busy33) {
  2088.  
  2089. // } else if (typeof nv === 'function' && state === 2) {
  2090. // if (firstHook) {
  2091. // firstHook = false;
  2092. // console.groupCollapsed('Infinite onerror Bug Found');
  2093. // console.log(location.href);
  2094. // console.log(stack);
  2095. // console.log(nv);
  2096. // console.groupEnd();
  2097. // }
  2098. // let _token = null;
  2099. // busy33 = true;
  2100. // String.prototype.includes76 = String.prototype.includes;
  2101. // String.prototype.includes = function (token) {
  2102. // _token = token;
  2103. // return true;
  2104. // }
  2105. // nv('token');
  2106. // String.prototype.includes = String.prototype.includes76;
  2107. // sToken = _token;
  2108. // busy33 = false;
  2109. // if (typeof sToken !== 'string') {
  2110. // unsupportErrorFix = true;
  2111. // }
  2112. // }
  2113. // delete Window.prototype['onerror'];
  2114. // if (typeof sToken === 'string' && sToken.length > 1) {
  2115. // /** @type {string} */
  2116. // const token = sToken;
  2117. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>?} } */
  2118. // const currentOnerror = pdK ? pdK.get.call(this) : this.onerror;
  2119.  
  2120. // const now = Date.now();
  2121. // const tokenEntry = {
  2122. // token,
  2123. // expired: now + FIX_error_many_stack_keepAliveDuration
  2124. // }
  2125. // /** @typedef {typeof tokenEntry} TokenEntry */
  2126.  
  2127. // /** @type {Set<TokenEntry>} */
  2128. // const errorTokens = currentOnerror.errorTokens;
  2129.  
  2130. // if (errorTokens) {
  2131. // if (errorTokens.size > FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than) {
  2132. // for (const entry of errorTokens) {
  2133. // if (entry.expired < now) {
  2134. // errorTokens.delete(entry);
  2135. // }
  2136. // }
  2137. // }
  2138. // errorTokens.add(tokenEntry)
  2139. // } else {
  2140. // /** @type {Set<TokenEntry>} */
  2141. // const errorTokens = new Set([tokenEntry]);
  2142. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>} } */
  2143. // const newOnerror = ((oe) => {
  2144. // const r = function (msg, ...args) {
  2145. // if (typeof msg === 'string' && errorTokens.size > 0) {
  2146. // for (const entry of errorTokens) {
  2147. // if (msg.includes(entry.token)) return true;
  2148. // }
  2149. // }
  2150. // if (typeof oe === 'function') {
  2151. // return oe.apply(this, arguments);
  2152. // }
  2153. // };
  2154. // r.errorTokens = errorTokens;
  2155. // return r;
  2156. // })(currentOnerror);
  2157.  
  2158. // if (pdK && pdK.set) pdK.set.call(this, newOnerror);
  2159. // else this.onerror = newOnerror;
  2160. // }
  2161. // } else {
  2162. // if (pdK && pdK.set) pdK.set.call(this, nv);
  2163. // else this.onerror = nv;
  2164. // }
  2165. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2166.  
  2167. // // console.log('onerror set', nv)
  2168. // return true;
  2169. // },
  2170. // enumerable: true,
  2171. // configurable: true
  2172. // }
  2173.  
  2174. // Object.defineProperty(Window.prototype, 'onerror', pd);
  2175.  
  2176.  
  2177. // }
  2178.  
  2179.  
  2180. // })();
  2181.  
  2182.  
  2183.  
  2184. // ================================================ 0.4.5 ================================================
  2185.  
  2186.  
  2187. // << if FIX_yt_player >>
  2188.  
  2189. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  2190. const PERF_471489_ = true;
  2191. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  2192. // This script uses a much gentle way to tamer the JS engine instead.
  2193.  
  2194. // << end >>
  2195.  
  2196. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  2197.  
  2198.  
  2199.  
  2200. const nilFn = () => { };
  2201.  
  2202. let isMainWindow = false;
  2203. try {
  2204. isMainWindow = window.document === window.top.document
  2205. } catch (e) { }
  2206.  
  2207. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  2208.  
  2209. const onRegistryReady = (callback) => {
  2210. if (typeof customElements === 'undefined') {
  2211. if (!('__CE_registry' in document)) {
  2212. // https://github.com/webcomponents/polyfills/
  2213. Object.defineProperty(document, '__CE_registry', {
  2214. get() {
  2215. // return undefined
  2216. },
  2217. set(nv) {
  2218. if (typeof nv == 'object') {
  2219. delete this.__CE_registry;
  2220. this.__CE_registry = nv;
  2221. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2222. }
  2223. return true;
  2224. },
  2225. enumerable: false,
  2226. configurable: true
  2227. })
  2228. }
  2229. let eventHandler = (evt) => {
  2230. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2231. const f = callback;
  2232. callback = null;
  2233. eventHandler = null;
  2234. f();
  2235. };
  2236. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2237. } else {
  2238. callback();
  2239. }
  2240. };
  2241.  
  2242.  
  2243. const assertor = (f) => f() || console.assert(false, f + "");
  2244.  
  2245. const fnIntegrity = (f, d) => {
  2246. if (!f || typeof f !== 'function') {
  2247. console.warn('f is not a function', f);
  2248. return;
  2249. }
  2250. let p = f + "", s = 0, j = -1, w = 0;
  2251. for (let i = 0, l = p.length; i < l; i++) {
  2252. const t = p[i];
  2253. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  2254. if (j < i - 1) w++;
  2255. j = i;
  2256. } else {
  2257. s++;
  2258. }
  2259. }
  2260. let itz = `${f.length}.${s}.${w}`;
  2261. if (!d) {
  2262. return itz;
  2263. } else {
  2264. return itz === d;
  2265. }
  2266. };
  2267.  
  2268. const getZq = (_yt_player) => {
  2269.  
  2270. const w = 'Zq';
  2271.  
  2272. let arr = [];
  2273.  
  2274. for (const [k, v] of Object.entries(_yt_player)) {
  2275.  
  2276. const p = typeof v === 'function' ? v.prototype : 0;
  2277. if (p
  2278. && typeof p.start === 'function' && p.start.length === 0
  2279. && typeof p.isActive === 'function' && p.isActive.length === 0
  2280. && typeof p.stop === 'function' && p.stop.length === 0
  2281. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  2282. && !p.send && !p.abort
  2283. && !p.sample && !p.initialize && !p.fail && !p.getName
  2284. // && !p.dispose && !p.isDisposed
  2285.  
  2286. ) {
  2287. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2288.  
  2289.  
  2290. }
  2291.  
  2292. }
  2293.  
  2294. if (arr.length === 0) {
  2295.  
  2296. console.warn(`Key does not exist. [${w}]`);
  2297. } else {
  2298.  
  2299. console.log(`[${w}]`, arr);
  2300. return arr[0];
  2301. }
  2302.  
  2303.  
  2304.  
  2305.  
  2306. }
  2307.  
  2308.  
  2309. const getVG = (_yt_player) => {
  2310. const w = 'VG';
  2311.  
  2312. let arr = [];
  2313.  
  2314. for (const [k, v] of Object.entries(_yt_player)) {
  2315.  
  2316. const p = typeof v === 'function' ? v.prototype : 0;
  2317. if (p
  2318. && typeof p.show === 'function' && p.show.length === 1
  2319. && typeof p.hide === 'function' && p.hide.length === 0
  2320. && typeof p.stop === 'function' && p.stop.length === 0) {
  2321.  
  2322. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2323.  
  2324. }
  2325.  
  2326. }
  2327.  
  2328.  
  2329. if (arr.length === 0) {
  2330.  
  2331. console.warn(`Key does not exist. [${w}]`);
  2332. } else {
  2333.  
  2334. console.log(`[${w}]`, arr);
  2335. return arr[0];
  2336. }
  2337.  
  2338.  
  2339.  
  2340. }
  2341.  
  2342.  
  2343. const getzo = (_yt_player) => {
  2344. const w = 'zo';
  2345.  
  2346. let arr = [];
  2347.  
  2348. for (const [k, v] of Object.entries(_yt_player)) {
  2349.  
  2350. if (
  2351. typeof v === 'function' && v.length === 3 && k.length < 3
  2352. && (v + "").includes("a.style[b]=c")
  2353. ) {
  2354.  
  2355. arr.push(k);
  2356.  
  2357. }
  2358.  
  2359. }
  2360.  
  2361.  
  2362. if (arr.length === 0) {
  2363.  
  2364. console.warn(`Key does not exist. [${w}]`);
  2365. } else {
  2366.  
  2367. console.log(`[${w}]`, arr);
  2368. return arr[0];
  2369. }
  2370.  
  2371. }
  2372.  
  2373. const addProtoToArr = (parent, key, arr) => {
  2374.  
  2375.  
  2376. let isChildProto = false;
  2377. for (const sr of arr) {
  2378. if (parent[key].prototype instanceof parent[sr]) {
  2379. isChildProto = true;
  2380. break;
  2381. }
  2382. }
  2383.  
  2384. if (isChildProto) return;
  2385.  
  2386. arr = arr.filter(sr => {
  2387. if (parent[sr].prototype instanceof parent[key]) {
  2388. return false;
  2389. }
  2390. return true;
  2391. });
  2392.  
  2393. arr.push(key);
  2394.  
  2395. return arr;
  2396.  
  2397.  
  2398. }
  2399.  
  2400. const getuG = (_yt_player) => {
  2401.  
  2402. const w = 'uG';
  2403.  
  2404. let arr = [];
  2405.  
  2406. for (const [k, v] of Object.entries(_yt_player)) {
  2407.  
  2408.  
  2409. const p = typeof v === 'function' ? v.prototype : 0;
  2410.  
  2411. if (p
  2412. && typeof p.createElement === 'function' && p.createElement.length === 2
  2413. && typeof p.detach === 'function' && p.detach.length === 0
  2414. && typeof p.update === 'function' && p.update.length === 1
  2415. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  2416. ) {
  2417.  
  2418. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2419.  
  2420. }
  2421.  
  2422. }
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428. if (arr.length === 0) {
  2429.  
  2430. console.warn(`Key does not exist. [${w}]`);
  2431. } else {
  2432.  
  2433. console.log(`[${w}]`, arr);
  2434. return arr[0];
  2435. }
  2436.  
  2437. }
  2438.  
  2439.  
  2440.  
  2441. // << if FIX_schedulerInstanceInstance_ >>
  2442.  
  2443. let idleFrom = Date.now() + 2700;
  2444. let slowMode = false;
  2445.  
  2446. let ytEvented = false;
  2447.  
  2448.  
  2449. const setupEvents = FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 ? () => {
  2450.  
  2451. document.addEventListener('yt-navigate', () => {
  2452.  
  2453. ytEvented = true;
  2454. slowMode = false;
  2455. idleFrom = Date.now() + 2700;
  2456.  
  2457. });
  2458. document.addEventListener('yt-navigate-start', () => {
  2459.  
  2460. ytEvented = true;
  2461. slowMode = false;
  2462. idleFrom = Date.now() + 2700;
  2463.  
  2464. });
  2465.  
  2466. document.addEventListener('yt-page-type-changed', () => {
  2467.  
  2468. ytEvented = true;
  2469. slowMode = false;
  2470. idleFrom = Date.now() + 1700;
  2471.  
  2472. });
  2473.  
  2474.  
  2475. document.addEventListener('yt-player-updated', () => {
  2476.  
  2477. ytEvented = true;
  2478. slowMode = false;
  2479. idleFrom = Date.now() + 1700;
  2480.  
  2481. });
  2482.  
  2483.  
  2484. document.addEventListener('yt-page-data-fetched', () => {
  2485.  
  2486. ytEvented = true;
  2487. slowMode = false;
  2488. idleFrom = Date.now() + 1700;
  2489.  
  2490. });
  2491.  
  2492. document.addEventListener('yt-navigate-finish', () => {
  2493.  
  2494. ytEvented = true;
  2495. slowMode = false;
  2496. let t = Date.now() + 700;
  2497. if (t > idleFrom) idleFrom = t;
  2498.  
  2499. });
  2500.  
  2501. document.addEventListener('yt-page-data-updated', () => {
  2502.  
  2503. ytEvented = true;
  2504. slowMode = false;
  2505. let t = Date.now() + 700;
  2506. if (t > idleFrom) idleFrom = t;
  2507.  
  2508. });
  2509.  
  2510. document.addEventListener('yt-watch-comments-ready', () => {
  2511.  
  2512. ytEvented = true;
  2513. slowMode = false;
  2514. let t = Date.now() + 700;
  2515. if (t > idleFrom) idleFrom = t;
  2516.  
  2517. });
  2518. } : () => { };
  2519.  
  2520.  
  2521. // << end >>
  2522.  
  2523. const cleanContext = async (win) => {
  2524. const waitFn = requestAnimationFrame; // shall have been binded to window
  2525. try {
  2526. let mx = 16; // MAX TRIAL
  2527. const frameId = 'vanillajs-iframe-v1';
  2528. /** @type {HTMLIFrameElement | null} */
  2529. let frame = document.getElementById(frameId);
  2530. let removeIframeFn = null;
  2531. if (!frame) {
  2532. frame = document.createElement('iframe');
  2533. frame.id = frameId;
  2534. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2535. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2536. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2537. n.appendChild(frame);
  2538. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2539. const root = document.documentElement;
  2540. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2541. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2542.  
  2543. removeIframeFn = (setTimeout) => {
  2544. const removeIframeOnDocumentReady = (e) => {
  2545. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2546. e = n;
  2547. n = win = removeIframeFn = 0;
  2548. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2549. }
  2550. if (!setTimeout || document.readyState !== 'loading') {
  2551. removeIframeOnDocumentReady();
  2552. } else {
  2553. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2554. }
  2555. }
  2556. }
  2557. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2558. const fc = frame.contentWindow;
  2559. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2560. try {
  2561. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  2562. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  2563. for (let k in res) res[k] = res[k].bind(win); // necessary
  2564. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2565. res.animate = fc.HTMLElement.prototype.animate;
  2566. res.perfNow = fc.performance.now;
  2567. return res;
  2568. } catch (e) {
  2569. if (removeIframeFn) removeIframeFn();
  2570. return null;
  2571. }
  2572. } catch (e) {
  2573. console.warn(e);
  2574. return null;
  2575. }
  2576. };
  2577.  
  2578.  
  2579. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  2580.  
  2581. cleanContext(window).then(__CONTEXT__ => {
  2582. if (!__CONTEXT__) return null;
  2583.  
  2584. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  2585.  
  2586.  
  2587. performance.now17 = perfNow.bind(performance);
  2588. // performance.now = performance.now16;
  2589. /*
  2590. let nowh = -1;
  2591. performance.now = function () {
  2592. let t = nowh;
  2593. let c = this.now17();
  2594. return (nowh = (t + 1e-7 > c ? t + 0.1 : c));
  2595. }
  2596. */
  2597.  
  2598. // console.log(performance.now())
  2599. // console.log(performance.now())
  2600. // console.log(performance.now())
  2601. // console.log(performance.now())
  2602.  
  2603.  
  2604.  
  2605. __requestAnimationFrame__ = requestAnimationFrame;
  2606.  
  2607. let rafPromise = null;
  2608.  
  2609. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2610. requestAnimationFrame(hRes => {
  2611. rafPromise = null;
  2612. resolve(hRes);
  2613. });
  2614. }));
  2615.  
  2616. const getForegroundPromise = () => {
  2617. if (document.visibilityState === 'visible') {
  2618. return Promise.resolve();
  2619. } else {
  2620. return getRafPromise();
  2621. }
  2622. };
  2623.  
  2624. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  2625. setTimeout(() => {
  2626. NO_PRELOAD_GENERATE_204_BYPASS = true;
  2627. }, 1270);
  2628. });
  2629.  
  2630. const promiseForTamerTimeout = new Promise(resolve => {
  2631. promiseForCustomYtElementsReady.then(() => {
  2632. customElements.whenDefined('ytd-app').then(() => {
  2633. setTimeout(resolve, 1200);
  2634. });
  2635. });
  2636. setTimeout(resolve, 3000);
  2637. });
  2638.  
  2639.  
  2640. class RAFHub {
  2641. constructor() {
  2642. /** @type {number} */
  2643. this.startAt = 8170;
  2644. /** @type {number} */
  2645. this.counter = 0;
  2646. /** @type {number} */
  2647. this.rid = 0;
  2648. /** @type {Map<number, FrameRequestCallback>} */
  2649. this.funcs = new Map();
  2650. const funcs = this.funcs;
  2651. /** @type {FrameRequestCallback} */
  2652. this.bCallback = this.mCallback.bind(this);
  2653. this.pClear = () => funcs.clear();
  2654. }
  2655. /** @param {DOMHighResTimeStamp} highResTime */
  2656. mCallback(highResTime) {
  2657. this.rid = 0;
  2658. Promise.resolve().then(this.pClear);
  2659. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2660. }
  2661. /** @param {FrameRequestCallback} f */
  2662. request(f) {
  2663. if (this.counter > 1e9) this.counter = 9;
  2664. let cid = this.startAt + (++this.counter);
  2665. this.funcs.set(cid, f);
  2666. if (this.rid === 0) {
  2667. console.log(2455)
  2668. this.rid = requestAnimationFrame(this.bCallback);
  2669. }
  2670. return cid;
  2671. }
  2672. /** @param {number} cid */
  2673. cancel(cid) {
  2674. cid = +cid;
  2675. if (cid > 0) {
  2676. if (cid <= this.startAt) {
  2677. return cancelAnimationFrame(cid);
  2678. }
  2679. if (this.rid > 0) {
  2680. this.funcs.delete(cid);
  2681. if (this.funcs.size === 0) {
  2682. cancelAnimationFrame(this.rid);
  2683. this.rid = 0;
  2684. }
  2685. }
  2686. }
  2687. }
  2688. /** @param {number} cid */
  2689. /** @param {FrameRequestCallback} f */
  2690. replaceFunc(cid, f) {
  2691. if (typeof this.funcs.get(cid) === 'function') {
  2692. this.funcs.set(cid, f);
  2693. return cid;
  2694. } else {
  2695. let r = this.request(f);
  2696. this.cancel(cid);
  2697. return r;
  2698. }
  2699. }
  2700. }
  2701.  
  2702.  
  2703. // WEAK_REF_BINDING && (async () => {
  2704.  
  2705. // ['tp-yt-paper-menu-button'].forEach(async tag => {
  2706.  
  2707. // const dummy = await new Promise(resolve => {
  2708. // promiseForCustomYtElementsReady.then(() => {
  2709. // customElements.whenDefined(tag).then(() => {
  2710. // resolve(document.createElement(tag));
  2711. // });
  2712. // });
  2713.  
  2714. // });
  2715.  
  2716. // if (!dummy || dummy.is !== tag) return;
  2717.  
  2718. // const cProto = insp(dummy).constructor.prototype;
  2719.  
  2720. // if (typeof cProto.close === 'function' && !cProto.close58) {
  2721. // cProto.close58 = cProto.close;
  2722. // console.log(cProto.close58)
  2723. // cProto.close = function () {
  2724. // // const dropdown = (this.$ || 0).dropdown || 0;
  2725. // // if (!dropdown) return;
  2726. // try{
  2727. // return this.close58.apply(this, arguments);
  2728. // }catch(e){
  2729.  
  2730. // }
  2731.  
  2732. // }
  2733. // }
  2734.  
  2735.  
  2736. // });
  2737.  
  2738. // })();
  2739.  
  2740. NATIVE_CANVAS_ANIMATION && (() => {
  2741.  
  2742. HTMLCanvasElement.prototype.animate = animate;
  2743.  
  2744. let cid = setInterval(() => {
  2745. HTMLCanvasElement.prototype.animate = animate;
  2746. }, 1);
  2747.  
  2748. promiseForTamerTimeout.then(() => {
  2749. clearInterval(cid)
  2750. });
  2751.  
  2752. })();
  2753.  
  2754. FIX_ytAction_ && (async () => {
  2755.  
  2756. const ytdApp = await new Promise(resolve => {
  2757.  
  2758. promiseForCustomYtElementsReady.then(() => {
  2759. customElements.whenDefined('ytd-app').then(() => {
  2760. const ytdApp = document.querySelector('ytd-app');
  2761. if (ytdApp) {
  2762. resolve(ytdApp);
  2763. return;
  2764. }
  2765. let mo = new MutationObserver(() => {
  2766. const ytdApp = document.querySelector('ytd-app');
  2767. if (!ytdApp) return;
  2768. if (mo) {
  2769. mo.disconnect();
  2770. mo.takeRecords();
  2771. mo = null;
  2772. }
  2773. resolve(ytdApp);
  2774. });
  2775. mo.observe(document, { subtree: true, childList: true });
  2776. });
  2777. });
  2778.  
  2779.  
  2780.  
  2781. });
  2782.  
  2783.  
  2784.  
  2785. if (!ytdApp) return;
  2786. const cProto = insp(ytdApp).constructor.prototype;
  2787.  
  2788.  
  2789. if (!cProto) return;
  2790. let mbd = 0;
  2791.  
  2792. const fixer = (_ytdApp) => {
  2793.  
  2794. const ytdApp = insp(_ytdApp);
  2795.  
  2796. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  2797. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  2798. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  2799. mbd++;
  2800. }
  2801.  
  2802.  
  2803. }
  2804.  
  2805. let cid = setInterval(() => {
  2806.  
  2807.  
  2808. if (typeof cProto.created === 'function' && !cProto.created56) {
  2809. cProto.created56 = cProto.created;
  2810. cProto.created = function (...args) {
  2811. const r = this.created56(...args);
  2812. fixer(this);
  2813. return r;
  2814. };
  2815. mbd++;
  2816. }
  2817.  
  2818.  
  2819. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  2820. cProto.onYtAction57_ = cProto.onYtAction_;
  2821. cProto.onYtAction_ = function (...args) {
  2822. Promise.resolve().then(() => this.onYtAction57_(...args));
  2823. };
  2824. mbd++;
  2825. }
  2826.  
  2827. if (ytdApp) fixer(ytdApp);
  2828.  
  2829. /*
  2830. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  2831. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  2832. actionRouter_.handleAction57 = actionRouter_.handleAction;
  2833. actionRouter_.handleAction = function (...args) {
  2834. Promise.resolve().then(() => this.handleAction57(...args));
  2835. }
  2836. mbd++;
  2837. }
  2838. */
  2839.  
  2840. // if(mbd === 3) clearInterval(cid);
  2841. if (mbd >= 3) clearInterval(cid);
  2842.  
  2843. }, 1);
  2844.  
  2845. setTimeout(() => {
  2846.  
  2847. clearInterval(cid);
  2848. }, 1000);
  2849.  
  2850. })();
  2851.  
  2852.  
  2853. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  2854.  
  2855. const evKey = `${_evKey}`;
  2856. const fvKey = `${_fvKey}`;
  2857. const debug = !!_debug;
  2858.  
  2859.  
  2860. // const rafHub = new RAFHub();
  2861.  
  2862.  
  2863. const _yt_player = await new Promise(resolve => {
  2864.  
  2865. let cid = setInterval(() => {
  2866. let t = (((window || 0)._yt_player || 0) || 0);
  2867. if (t) {
  2868.  
  2869. clearInterval(cid);
  2870. resolve(t);
  2871. }
  2872. }, 1);
  2873.  
  2874. promiseForTamerTimeout.then(() => {
  2875. resolve(null)
  2876. });
  2877.  
  2878. });
  2879.  
  2880.  
  2881. if (!_yt_player || typeof _yt_player !== 'object') return;
  2882.  
  2883.  
  2884. const getArr = (_yt_player) => {
  2885.  
  2886. let arr = [];
  2887.  
  2888. for (const [k, v] of Object.entries(_yt_player)) {
  2889.  
  2890. const p = typeof v === 'function' ? v.prototype : 0;
  2891. if (p
  2892. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  2893.  
  2894. ) {
  2895. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2896.  
  2897. }
  2898.  
  2899. }
  2900.  
  2901. if (arr.length === 0) {
  2902.  
  2903. console.warn(`Key prop [${evKey}] does not exist.`);
  2904. } else {
  2905.  
  2906. return arr;
  2907. }
  2908.  
  2909. };
  2910.  
  2911. const arr = getArr(_yt_player);
  2912.  
  2913.  
  2914. if (!arr) return;
  2915.  
  2916. debug && console.log(`FIX_${evKey}`, arr);
  2917.  
  2918. const f = function (...args) {
  2919. Promise.resolve().then(() => this[fvKey](...args));
  2920. };
  2921.  
  2922.  
  2923. for (const k of arr) {
  2924.  
  2925. const g = _yt_player;
  2926. const gk = g[k];
  2927. const gkp = gk.prototype;
  2928.  
  2929. debug && console.log(237, k, gkp)
  2930.  
  2931. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  2932. gkp[fvKey] = gkp[evKey];
  2933. gkp[evKey] = f;
  2934. }
  2935. }
  2936.  
  2937.  
  2938.  
  2939.  
  2940. }
  2941.  
  2942. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  2943. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  2944. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  2945. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  2946. if (FIX_VideoEVENTS_v2) {
  2947. const FIX_VideoEVENTS_DEBUG = 0;
  2948. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  2949. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  2950. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  2951. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  2952. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  2953. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  2954. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  2955. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  2956. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  2957.  
  2958. }
  2959. // onMutedAutoplayChange
  2960. // onVolumeChange
  2961. // onPlaybackRateChange
  2962.  
  2963. // onAirPlayActiveChange
  2964. // onAirPlayAvailabilityChange
  2965. // onApiChange
  2966. // onAutoplayBlocked
  2967. // onDrmOutputRestricted
  2968. // onFullscreenChange
  2969. // onLoadProgress
  2970. // onLoadedMetadata
  2971. // onVideoDataChange
  2972. // onVideoProgress
  2973.  
  2974. (FIX_maybeUpdateFlexibleMenu || WEAK_REF_BINDING) && (async () => {
  2975.  
  2976.  
  2977. const dummy = await new Promise(resolve => {
  2978.  
  2979. promiseForCustomYtElementsReady.then(() => {
  2980. customElements.whenDefined('ytd-menu-renderer').then(() => {
  2981.  
  2982. resolve(document.createElement('ytd-menu-renderer'));
  2983. });
  2984. });
  2985.  
  2986.  
  2987.  
  2988. });
  2989.  
  2990.  
  2991. if (!dummy || dummy.is !== 'ytd-menu-renderer') return;
  2992.  
  2993. const cProto = insp(dummy).constructor.prototype;
  2994.  
  2995. if (FIX_maybeUpdateFlexibleMenu && typeof cProto.created === 'function' && !cProto.created58) {
  2996. cProto.created58 = cProto.created;
  2997. cProto.created = function (...args) {
  2998. const r = this.created58(...args);
  2999. if (typeof this.maybeUpdateFlexibleMenu === 'function' && !this.maybeUpdateFlexibleMenu57) {
  3000. this.maybeUpdateFlexibleMenu57 = this.maybeUpdateFlexibleMenu;
  3001. this.maybeUpdateFlexibleMenu = function (...args) {
  3002. Promise.resolve().then(() => this.maybeUpdateFlexibleMenu57(...args));
  3003. }
  3004. }
  3005. return r;
  3006. }
  3007.  
  3008. }
  3009.  
  3010.  
  3011.  
  3012. // if (WEAK_REF_BINDING && typeof cProto.setupFlexibleMenu === 'function' && !cProto.setupFlexibleMenu58) {
  3013. // cProto.setupFlexibleMenu58 = cProto.setupFlexibleMenu;
  3014. // cProto.setupFlexibleMenu = function () {
  3015.  
  3016. // const hostElement = this.hostElement;
  3017. // if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  3018. // return void 0;
  3019. // } else {
  3020. // return this.setupFlexibleMenu58.apply(this, arguments);
  3021. // }
  3022.  
  3023. // }
  3024.  
  3025.  
  3026.  
  3027. // }
  3028.  
  3029.  
  3030. // if (WEAK_REF_BINDING && typeof cProto.stampDomArray_ === 'function' && !cProto.stampDomArray58_) {
  3031. // cProto.stampDomArray58_ = cProto.stampDomArray_;
  3032. // cProto.stampDomArray_ = function (a, b, c, d, e, h) {
  3033.  
  3034. // const hostElement = this.hostElement;
  3035. // if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  3036. // return void 0;
  3037. // } else {
  3038. // return this.stampDomArray58_.apply(this, arguments);
  3039. // }
  3040.  
  3041. // }
  3042.  
  3043.  
  3044.  
  3045. // }
  3046.  
  3047.  
  3048.  
  3049.  
  3050.  
  3051. //console.log(144,cProto.maybeUpdateFlexibleMenu)
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057.  
  3058. })();
  3059.  
  3060. (ENABLE_discreteTasking || UNLOAD_DETACHED_POLYMER) && (async () => {
  3061.  
  3062. const Polymer = await new Promise(resolve => {
  3063.  
  3064. let cid = 0;
  3065. const f = () => {
  3066. const Polymer = window.Polymer;
  3067. if (typeof Polymer !== 'function') return;
  3068. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  3069. cid && clearInterval(cid);
  3070. cid = 0;
  3071. resolve(Polymer);
  3072. };
  3073. cid = setInterval(f, 1);
  3074.  
  3075. });
  3076. if (!Polymer) return;
  3077.  
  3078.  
  3079. if (UNLOAD_DETACHED_POLYMER && typeof Polymer.Base.detached === 'function' && !Polymer.Base.detached92 && Polymer.Base.detached.length === 0) {
  3080. Polymer.Base.detached92 = Polymer.Base.detached;
  3081.  
  3082. const detachedPlus = async function (elem) {
  3083. await delay300.then();
  3084. if (elem.isAttached !== false) return;
  3085. await delay300.then();
  3086. if (elem.isAttached !== false) return;
  3087.  
  3088. if (elem.__dataClientsReady === true) elem.__dataClientsReady = false;
  3089. // if (elem.__dataEnabled === true) elem.__dataEnabled = false;
  3090. if (elem.__dataReady === true) elem.__dataReady = false;
  3091.  
  3092. elem.__dataLinkedPaths = elem.__dataToNotify = elem.__dataPendingClients = null;
  3093. elem.__dataHasPaths = false;
  3094. // elem.__dataCompoundStorage = null;
  3095. elem.__dataHost = null;
  3096. elem.__dataTemp = null;
  3097. elem.__dataClientsInitialized = false;
  3098.  
  3099.  
  3100. // elem.data = {};
  3101. elem.data = null;
  3102. elem.__dataPending = null;
  3103. elem.__dataOld = null;
  3104. elem.__dataInstanceProps = null;
  3105.  
  3106. elem.__dataCounter = 0;
  3107. elem.__serializing = false;
  3108.  
  3109. // if (elem.$) elem.$ = {};
  3110. // if (elem.root) elem.root = null;
  3111.  
  3112. // let hostElement = elem.hostElement, tlm;
  3113. // if (hostElement instanceof Node) {
  3114. // // if (hostElement.isConnected === false) {
  3115. // // while (tlm = hostElement.firstChild) tlm.remove();
  3116. // // }
  3117. // elem.hostElement = hostElement = null;
  3118. // }
  3119.  
  3120.  
  3121. // if (hostElement === null) {
  3122.  
  3123. // if (elem.animatedIconElement instanceof Node) elem.animatedIconElement = null;
  3124. // if (elem._target instanceof Node) elem._target = null;
  3125. // if (elem.iconset instanceof Node) elem.iconset = null;
  3126. // if (elem._svgIcon instanceof Node) elem._svgIcon = null;
  3127.  
  3128. // }
  3129.  
  3130.  
  3131. }
  3132. Polymer.Base.detached = function () {
  3133. Promise.resolve(this).then(detachedPlus);
  3134. return Polymer.Base.detached92();
  3135. };
  3136. }
  3137.  
  3138.  
  3139. if (ENABLE_discreteTasking) {
  3140.  
  3141. Polymer.Base.__connInit__ = function () {
  3142. setupDiscreteTasks(this);
  3143. // if (WEAK_REF_BINDING && (this.is || this instanceof Node)) {
  3144. // setupWeakRef(this)
  3145. // }
  3146. }
  3147.  
  3148.  
  3149. /** @type {Function} */
  3150. const connectedCallbackK = function (...args) {
  3151. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3152. const r = this[qm53](...args);
  3153. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3154. this.mh35 = 1;
  3155. return r;
  3156. };
  3157.  
  3158. connectedCallbackK.m353 = 1;
  3159.  
  3160.  
  3161. const qt53 = Polymer.Base.connectedCallback;
  3162. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  3163.  
  3164. Polymer.Base.connectedCallback = connectedCallbackK;
  3165.  
  3166.  
  3167. /** @type {Function} */
  3168. const createdK = function (...args) {
  3169. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3170. const r = this[qn53](...args);
  3171. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  3172. this.mh36 = 1;
  3173. return r;
  3174. };
  3175.  
  3176.  
  3177. createdK.m353 = 1;
  3178. Polymer.Base[qn53] = Polymer.Base.created;
  3179. Polymer.Base.created = createdK;
  3180.  
  3181. }
  3182.  
  3183. })();
  3184.  
  3185. CHANGE_appendChild && (() => {
  3186.  
  3187. const f = HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  3188. if (f) HTMLElement.prototype.appendChild = function (a) {
  3189.  
  3190.  
  3191. if (this instanceof HTMLElement) {
  3192.  
  3193. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  3194. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  3195. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  3196. node.__m848__ = 1;
  3197. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  3198. }
  3199. }
  3200. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  3201. return this.appendChild73.apply(this, arguments);
  3202. }
  3203.  
  3204. if (a instanceof DocumentFragment) {
  3205. if (a.firstElementChild === null) {
  3206. let child = a.firstChild;
  3207. if (child === null) return a;
  3208. let doNormal = false;
  3209. while (child instanceof Node) {
  3210. if (child.nodeType === 3) { doNormal = true; break; }
  3211. child = child.nextSibling;
  3212. }
  3213. if (!doNormal) return a;
  3214. }
  3215. }
  3216.  
  3217. return (this.appendChild73 || f).apply(this, arguments);
  3218. }
  3219.  
  3220.  
  3221. return (HTMLElement.prototype.appendChild73 || f).apply(this, arguments);
  3222. }
  3223.  
  3224.  
  3225. })();
  3226.  
  3227. if (FIX_Shady) {
  3228.  
  3229. let cidSL = setInterval(() => {
  3230. const { ShadyDOM, ShadyCSS } = window;
  3231. if (ShadyDOM && ShadyCSS) {
  3232. clearInterval(cidSL);
  3233. cidSL = 0;
  3234. }
  3235. if (ShadyDOM) {
  3236. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  3237. ShadyDOM.noPatch = true; // 1 of 10
  3238. ShadyDOM.patchOnDemand = false; // 1 of 10
  3239. ShadyDOM.preferPerformance = true; // 1 of 10
  3240. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  3241. }
  3242. if (ShadyCSS) {
  3243. ShadyCSS.nativeCss = true; // 1 of 10
  3244. ShadyCSS.nativeShadow = true; // 6 of 10
  3245. ShadyCSS.cssBuild = undefined; // 1 of 10
  3246. ShadyCSS.disableRuntime = true; // 1 of 10
  3247. }
  3248. }, 1);
  3249.  
  3250. }
  3251.  
  3252.  
  3253. FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 && (async () => {
  3254.  
  3255.  
  3256. const schedulerInstanceInstance_ = await new Promise(resolve => {
  3257.  
  3258. let cid = setInterval(() => {
  3259. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  3260. if (t) {
  3261.  
  3262. clearInterval(cid);
  3263. resolve(t);
  3264. }
  3265. }, 1);
  3266. promiseForTamerTimeout.then(() => {
  3267. resolve(null)
  3268. });
  3269. });
  3270.  
  3271. if (!schedulerInstanceInstance_) return;
  3272.  
  3273.  
  3274. if (!ytEvented) {
  3275. idleFrom = Date.now() + 2700;
  3276. slowMode = false; // integrity
  3277. }
  3278.  
  3279. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  3280. if (checkOK) {
  3281.  
  3282.  
  3283. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  3284.  
  3285. let requestingFn = null;
  3286. let requestingArgs = null;
  3287. let requestingDT = 0;
  3288.  
  3289. // let timerId = null;
  3290. const entries = [];
  3291. const f = function () {
  3292. requestingFn = this.fn;
  3293. requestingArgs = [...arguments];
  3294. requestingDT = Date.now();
  3295. entries.push({
  3296. fn: requestingFn,
  3297. args: requestingArgs,
  3298. t: requestingDT
  3299. });
  3300. // if (Date.now() < idleFrom) {
  3301. // timerId = this.fn.apply(window, arguments);
  3302. // } else {
  3303. // timerId = this.fn.apply(window, arguments);
  3304.  
  3305. // }
  3306. // timerId = 12377;
  3307. return 12377;
  3308. }
  3309.  
  3310.  
  3311. const fakeFns = [
  3312. f.bind({ fn: requestAnimationFrame }),
  3313. f.bind({ fn: setInterval }),
  3314. f.bind({ fn: setTimeout }),
  3315. f.bind({ fn: requestIdleCallback })
  3316. ]
  3317.  
  3318.  
  3319.  
  3320.  
  3321. let timerResolve = null;
  3322. setInterval(() => {
  3323. timerResolve && timerResolve();
  3324. timerResolve = null;
  3325. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  3326. }, 250);
  3327.  
  3328. let mzt = 0;
  3329.  
  3330. let fnSelectorProp = null;
  3331.  
  3332. schedulerInstanceInstance_.start = function () {
  3333.  
  3334. const mk1 = window.requestAnimationFrame
  3335. const mk2 = window.setInterval
  3336. const mk3 = window.setTimeout
  3337. const mk4 = window.requestIdleCallback
  3338.  
  3339. const tThis = this['$$12378$$'] || this;
  3340.  
  3341.  
  3342. window.requestAnimationFrame = fakeFns[0]
  3343. window.setInterval = fakeFns[1]
  3344. window.setTimeout = fakeFns[2]
  3345. window.requestIdleCallback = fakeFns[3]
  3346.  
  3347. fnSelectorProp = null;
  3348.  
  3349.  
  3350. tThis.start991.call(new Proxy(tThis, {
  3351. get(target, prop, receiver) {
  3352. if (prop === '$$12377$$') return true;
  3353. if (prop === '$$12378$$') return target;
  3354.  
  3355. // console.log('get',prop)
  3356. return target[prop]
  3357. },
  3358. set(target, prop, value, receiver) {
  3359. // console.log('set', prop, value)
  3360.  
  3361.  
  3362. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  3363. if (value === 12377 && fnSelectorProp) {
  3364.  
  3365. const originalSelection = target[fnSelectorProp];
  3366. const timerIdProp = prop;
  3367.  
  3368. /*
  3369.  
  3370.  
  3371. case 1:
  3372. var a = this.K;
  3373. this.g = this.I ? window.requestIdleCallback(a, {
  3374. timeout: 3E3
  3375. }) : window.setTimeout(a, ma);
  3376. break;
  3377. case 2:
  3378. this.g = window.setTimeout(this.M, this.N);
  3379. break;
  3380. case 3:
  3381. this.g = window.requestAnimationFrame(this.L);
  3382. break;
  3383. case 4:
  3384. this.g = window.setTimeout(this.J, 0)
  3385. }
  3386.  
  3387. */
  3388.  
  3389. const doForegroundSlowMode = () => {
  3390.  
  3391. const tir = ++mzt;
  3392. const f = requestingArgs[0];
  3393.  
  3394.  
  3395. getForegroundPromise().then(() => {
  3396.  
  3397.  
  3398. new Promise(r => {
  3399. timerResolve = r
  3400. }).then(() => {
  3401. if (target[timerIdProp] === -tir) f();
  3402. });
  3403.  
  3404. })
  3405.  
  3406. target[fnSelectorProp] = 931;
  3407. target[prop] = -tir;
  3408. }
  3409.  
  3410. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  3411. if (slowMode && !(requestingArgs[1] > 250)) {
  3412.  
  3413. doForegroundSlowMode();
  3414.  
  3415. } else {
  3416. target[prop] = setTimeout.apply(window, requestingArgs);
  3417.  
  3418. }
  3419.  
  3420. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  3421.  
  3422. if (slowMode) {
  3423.  
  3424. doForegroundSlowMode();
  3425.  
  3426. } else {
  3427. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  3428. }
  3429.  
  3430.  
  3431. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  3432.  
  3433. const f = requestingArgs[0];
  3434. const tir = ++mzt;
  3435. Promise.resolve().then(() => {
  3436. if (target[timerIdProp] === -tir) f();
  3437. });
  3438. target[fnSelectorProp] = 930;
  3439. target[prop] = -tir;
  3440.  
  3441. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  3442.  
  3443. doForegroundSlowMode();
  3444.  
  3445. } else {
  3446. // target[prop] = timerId;
  3447. target[fnSelectorProp] = 0;
  3448. target[prop] = 0;
  3449. }
  3450.  
  3451. // *****
  3452. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  3453. } else {
  3454.  
  3455. target[prop] = value;
  3456. }
  3457. // console.log('set',prop,value)
  3458. return true;
  3459. }
  3460. }));
  3461.  
  3462. fnSelectorProp = null;
  3463.  
  3464.  
  3465. window.requestAnimationFrame = mk1;
  3466. window.setInterval = mk2
  3467. window.setTimeout = mk3
  3468. window.requestIdleCallback = mk4;
  3469.  
  3470.  
  3471.  
  3472. }
  3473.  
  3474. schedulerInstanceInstance_.start.toString = function () {
  3475. return schedulerInstanceInstance_.start991.toString();
  3476. }
  3477.  
  3478. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  3479. // prop,
  3480. // value: schedulerInstanceInstance_[prop],
  3481. // type: typeof schedulerInstanceInstance_[prop]
  3482.  
  3483. // }));
  3484. // console.log('fcc', funcNames)
  3485.  
  3486.  
  3487.  
  3488.  
  3489. }
  3490. })();
  3491.  
  3492.  
  3493.  
  3494. FIX_schedulerInstanceInstance_V2 && !FIX_schedulerInstanceInstance_V1 && (async () => {
  3495.  
  3496.  
  3497. const schedulerInstanceInstance_ = await new Promise(resolve => {
  3498.  
  3499. let cid = setInterval(() => {
  3500. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  3501. if (t) {
  3502.  
  3503. clearInterval(cid);
  3504. resolve(t);
  3505. }
  3506. }, 1);
  3507. promiseForTamerTimeout.then(() => {
  3508. resolve(null)
  3509. });
  3510. });
  3511.  
  3512. if (!schedulerInstanceInstance_) return;
  3513.  
  3514.  
  3515. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  3516. if (checkOK) {
  3517.  
  3518. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  3519.  
  3520.  
  3521.  
  3522. let busy = false;
  3523.  
  3524. // console.log('1667',schedulerInstanceInstance_.start);
  3525. schedulerInstanceInstance_.start = function () {
  3526.  
  3527. // p59 || console.log(location.pathname, 16400);
  3528.  
  3529. if (busy) {
  3530.  
  3531. return this.start991.call(this);
  3532.  
  3533. }
  3534.  
  3535. busy = true;
  3536.  
  3537. const mk1 = window.requestAnimationFrame
  3538. // const mk2 = window.setInterval
  3539. // const mk3 = window.setTimeout
  3540. // const mk4 = window.requestIdleCallback
  3541.  
  3542. // by pass Youtube Engine's wrapping
  3543. window.requestAnimationFrame = baseRAF;
  3544. // window.setInterval = setInterval
  3545. // window.setTimeout = setTimeout
  3546. // window.requestIdleCallback = requestIdleCallback
  3547.  
  3548.  
  3549. this.start991.call(this);
  3550.  
  3551.  
  3552. window.requestAnimationFrame = mk1;
  3553. // window.setInterval = mk2
  3554. // window.setTimeout = mk3
  3555. // window.requestIdleCallback = mk4;
  3556.  
  3557. busy = false;
  3558.  
  3559.  
  3560.  
  3561. }
  3562.  
  3563. schedulerInstanceInstance_.start.toString = function () {
  3564. return schedulerInstanceInstance_.start991.toString();
  3565. }
  3566.  
  3567. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  3568. // prop,
  3569. // value: schedulerInstanceInstance_[prop],
  3570. // type: typeof schedulerInstanceInstance_[prop]
  3571.  
  3572. // }));
  3573. // console.log('fcc', funcNames)
  3574.  
  3575.  
  3576.  
  3577.  
  3578. }
  3579. })();
  3580.  
  3581. FIX_yt_player && (async () => {
  3582.  
  3583.  
  3584.  
  3585. // const rafHub = new RAFHub();
  3586.  
  3587.  
  3588. const _yt_player = await new Promise(resolve => {
  3589.  
  3590. let cid = setInterval(() => {
  3591. let t = (((window || 0)._yt_player || 0) || 0);
  3592. if (t) {
  3593.  
  3594. clearInterval(cid);
  3595. resolve(t);
  3596. }
  3597. }, 1);
  3598.  
  3599. promiseForTamerTimeout.then(() => {
  3600. resolve(null)
  3601. });
  3602.  
  3603. });
  3604.  
  3605.  
  3606.  
  3607. if (!_yt_player || typeof _yt_player !== 'object') return;
  3608.  
  3609.  
  3610.  
  3611. let keyZq = getZq(_yt_player);
  3612. // let keyVG = getVG(_yt_player);
  3613. // let buildVG = _yt_player[keyVG];
  3614. // let u = new buildVG({
  3615. // api: {},
  3616. // element: document.createElement('noscript'),
  3617. // api: {},
  3618. // hide: () => { }
  3619. // }, 250);
  3620. // const timeDelayConstructor = u.delay.constructor; // g.br
  3621. // console.log(keyVG, u)
  3622. // buildVG.prototype.show = function(){}
  3623. // _yt_player[keyZq] = g.k
  3624.  
  3625. if (!keyZq) return;
  3626.  
  3627.  
  3628. const g = _yt_player
  3629. let k = keyZq
  3630.  
  3631. const gk = g[k];
  3632. if (typeof gk !== 'function') return;
  3633. const gkp = gk.prototype;
  3634.  
  3635. let dummyObject = new gk;
  3636. let nilFunc = () => { };
  3637.  
  3638. let nilObj = {};
  3639.  
  3640. // console.log(1111111111)
  3641.  
  3642. let keyBoolD = '';
  3643. let keyWindow = '';
  3644. let keyFuncC = '';
  3645. let keyCidj = '';
  3646.  
  3647. for (const [t, y] of Object.entries(dummyObject)) {
  3648. if (y instanceof Window) keyWindow = t;
  3649. }
  3650.  
  3651. const dummyObjectProxyHandler = {
  3652. get(target, prop) {
  3653. let v = target[prop]
  3654. if (v instanceof Window && !keyWindow) {
  3655. keyWindow = t;
  3656. }
  3657. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  3658. if (prop === keyWindow) y = {
  3659. requestAnimationFrame(f) {
  3660. return 3;
  3661. },
  3662. cancelAnimationFrame() {
  3663.  
  3664. }
  3665. }
  3666. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  3667. keyFuncC = prop;
  3668. }
  3669. // console.log('[get]', prop, typeof target[prop])
  3670.  
  3671.  
  3672. return y;
  3673. },
  3674. set(target, prop, value) {
  3675.  
  3676. if (typeof value === 'boolean' && !keyBoolD) {
  3677. keyBoolD = prop;
  3678. }
  3679. if (typeof value === 'number' && !keyCidj && value >= 2) {
  3680. keyCidj = prop;
  3681. }
  3682.  
  3683. // console.log('[set]', prop, value)
  3684. target[prop] = value
  3685.  
  3686. return true;
  3687. }
  3688. };
  3689.  
  3690. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  3691.  
  3692. /*
  3693. console.log({
  3694. keyBoolD,
  3695. keyFuncC,
  3696. keyWindow,
  3697. keyCidj
  3698. })
  3699.  
  3700. console.log( dummyObject[keyFuncC])
  3701.  
  3702.  
  3703. console.log(2222222222)
  3704. */
  3705.  
  3706.  
  3707. // console.log('gkp.start',gkp.start);
  3708. // console.log('gkp.stop',gkp.stop);
  3709. gkp._activation = false;
  3710.  
  3711. gkp.start = function () {
  3712. // p59 || console.log(12100)
  3713. if (!this._activation) {
  3714. this._activation = true;
  3715. getRafPromise().then(() => {
  3716. this._activation = false;
  3717. if (this[keyCidj]) {
  3718. Promise.resolve().then(this[keyFuncC]);
  3719. }
  3720. });
  3721. }
  3722. this[keyCidj] = 1;
  3723. this[keyBoolD] = true;
  3724. }
  3725. ;
  3726. gkp.stop = function () {
  3727. this[keyCidj] = null
  3728. }
  3729.  
  3730.  
  3731. /*
  3732. g[k].start = function() {
  3733. this.stop();
  3734. this.D = true;
  3735. var a = requestAnimationFrame
  3736. , b = cancelAnimationFrame;
  3737. this.j = a.call(this.B, this.C)
  3738. }
  3739. ;
  3740. g[k].stop = function() {
  3741. if (this.isActive()) {
  3742. var a = requestAnimationFrame
  3743. , b = cancelAnimationFrame;
  3744. b.call(this.B, this.j)
  3745. }
  3746. this.j = null
  3747. }
  3748. */
  3749.  
  3750.  
  3751.  
  3752. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  3753.  
  3754. if (keyzo) {
  3755.  
  3756. k = keyzo
  3757.  
  3758. const setCSSProp = (() => {
  3759.  
  3760. let animationPropCapable = false;
  3761. try {
  3762. const propName = "--ibxpf"
  3763. const value = 2;
  3764. const keyframes = [{
  3765. [propName]: value
  3766. }];
  3767. window.CSS.registerProperty({
  3768. name: "--ibxpf",
  3769. syntax: "<number>",
  3770. inherits: false,
  3771. initialValue: 1,
  3772. });
  3773. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  3774. } catch (e) { }
  3775.  
  3776. if (!animationPropCapable) {
  3777. return (element, cssProp, value) => {
  3778.  
  3779.  
  3780. element.style.setProperty(cssProp, value);
  3781.  
  3782. }
  3783. }
  3784.  
  3785. const propMaps = new Map();
  3786.  
  3787. function setCustomCSSProperty(element, propName, value) {
  3788. let wm = propMaps.get(propName);
  3789. if (!wm) {
  3790.  
  3791. try {
  3792. window.CSS.registerProperty({
  3793. name: propName,
  3794. syntax: "*",
  3795. inherits: false
  3796. });
  3797. } catch (e) {
  3798. console.warn(e);
  3799. }
  3800.  
  3801. propMaps.set(propName, (wm = new WeakMap()));
  3802. }
  3803.  
  3804. // Create the animation keyframes with the provided property and value
  3805. const keyframes = [{
  3806. [propName]: value
  3807. }];
  3808.  
  3809. let currentAnimation = wm.get(element);
  3810. if (currentAnimation) {
  3811.  
  3812. currentAnimation.effect.setKeyframes(keyframes);
  3813.  
  3814. } else {
  3815.  
  3816.  
  3817.  
  3818. // Set the animation on the element and immediately pause it
  3819. const animation = animate.call(element, keyframes, {
  3820. duration: 1, // Very short duration as we just want to set the value
  3821. fill: 'forwards',
  3822. iterationStart: 1,
  3823. iterations: 2,
  3824. direction: 'alternate'
  3825. });
  3826.  
  3827.  
  3828. // animation.currentTime = 1;
  3829. animation.pause();
  3830.  
  3831. wm.set(element, animation);
  3832.  
  3833.  
  3834. }
  3835.  
  3836. }
  3837.  
  3838. return setCustomCSSProperty;
  3839.  
  3840.  
  3841. })();
  3842.  
  3843.  
  3844. const attrUpdateFn = g[k];
  3845. g['$$original$$' + k] = attrUpdateFn;
  3846. g[k] = function (a, b, c) {
  3847.  
  3848. // console.log(140000, a, b, c);
  3849.  
  3850. let transformType = '';
  3851. let transformValue = 0;
  3852. let transformUnit = '';
  3853.  
  3854. let byPassDefaultFn = false;
  3855. if (b === "transform" && typeof c === 'string') {
  3856.  
  3857. byPassDefaultFn = true;
  3858.  
  3859. const aStyle = a.style;
  3860.  
  3861. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  3862. if (!(a instanceof HTMLElement)) return;
  3863. if (c.length === 0) {
  3864.  
  3865. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  3866. let p = c.substring(7, c.length - 1);
  3867. let q = p.length >= 1 ? parseFloat(p) : -1;
  3868. if (q > -1e-5 && q < 1 + 1e-5) {
  3869. transformType = 'scalex'
  3870. transformValue = q;
  3871. transformUnit = '';
  3872. }
  3873.  
  3874.  
  3875. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  3876.  
  3877. let p = c.substring(11, c.length - 3);
  3878. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3879.  
  3880. if (typeof q === 'number' && !isNaN(q)) {
  3881. transformType = 'translateX'
  3882. transformValue = q;
  3883. transformUnit = 'px';
  3884. }
  3885.  
  3886.  
  3887. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  3888. let p = c.substring(7, c.length - 1);
  3889. let q = p.length >= 1 ? parseFloat(p) : -1;
  3890. if (q > -1e-5 && q < 1 + 1e-5) {
  3891. transformType = 'scaley'
  3892. transformValue = q;
  3893. transformUnit = '';
  3894. }
  3895.  
  3896.  
  3897. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  3898.  
  3899. let p = c.substring(11, c.length - 3);
  3900. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3901.  
  3902. if (typeof q === 'number' && !isNaN(q)) {
  3903. transformType = 'translateY'
  3904. transformValue = q;
  3905. transformUnit = 'px';
  3906. }
  3907.  
  3908.  
  3909. }
  3910.  
  3911. if (transformType) {
  3912.  
  3913. if (transformType === 'scalex' || transformType === 'scaley') {
  3914.  
  3915. const q = transformValue;
  3916.  
  3917.  
  3918. /*
  3919.  
  3920. let vz = Math.round(steppingScaleN * q);
  3921. const customPropName = '--discrete-'+transformType
  3922.  
  3923. const currentValue = aStyle.getPropertyValue(customPropName);
  3924.  
  3925. const transform = (aStyle.transform || '');
  3926. const u = transform.includes(customPropName)
  3927. if (`${currentValue}` === `${vz}`) {
  3928. if (u) return;
  3929. }
  3930.  
  3931.  
  3932. setCSSProp(a,customPropName, vz);
  3933. // aStyle.setProperty(customPropName, vz)
  3934.  
  3935. let ck = '';
  3936.  
  3937. if (c.length === 9) ck = c;
  3938. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3939.  
  3940. if (ck && beforeMq !== ck) {
  3941. aStyle.setProperty('--mq-transform', ck);
  3942. }
  3943.  
  3944. if (u) return;
  3945. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  3946.  
  3947.  
  3948.  
  3949. */
  3950.  
  3951. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  3952.  
  3953. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  3954. const cv = aStyle.transform;
  3955.  
  3956. // console.log(157, cv,c)
  3957.  
  3958. if (c === cv) return;
  3959. // console.log(257, cv,c)
  3960.  
  3961. aStyle.transform = c;
  3962.  
  3963. // return;
  3964.  
  3965. } else if (transformType === 'translateX' || transformType === 'translateY') {
  3966.  
  3967. const q = transformValue;
  3968.  
  3969. /*
  3970.  
  3971. let vz = q.toFixed(1);
  3972. const customPropName = '--discrete-'+transformType
  3973.  
  3974. const aStyle = a.style;
  3975. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  3976.  
  3977.  
  3978. const transform = (aStyle.transform || '');
  3979. const u = transform.includes(customPropName)
  3980. if (parseFloat(currentValue).toFixed(1) === vz) {
  3981. if (u) return;
  3982. }
  3983.  
  3984. setCSSProp(a,customPropName, vz + 'px');
  3985. // aStyle.setProperty(customPropName, vz + 'px')
  3986.  
  3987. let ck = '';
  3988. if (c.length === 15) ck = c;
  3989. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3990.  
  3991. if (ck && beforeMq !== ck) {
  3992. aStyle.setProperty('--mq-transform', ck);
  3993. }
  3994.  
  3995. if (u) return;
  3996. c = `${transformType}(var(--discrete-${transformType}))`;
  3997.  
  3998. */
  3999.  
  4000.  
  4001. const vz = +q.toFixed(1);
  4002.  
  4003. c = `${transformType}(${vz}${transformUnit})`
  4004. const cv = aStyle.transform;
  4005.  
  4006. // console.log(158, cv,c)
  4007.  
  4008. if (c === cv) return;
  4009. // console.log(258, cv,c)
  4010.  
  4011. aStyle.transform = c;
  4012.  
  4013. // return;
  4014.  
  4015. } else {
  4016. throw new Error();
  4017. }
  4018.  
  4019. } else {
  4020. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  4021. const cv = aStyle.transform
  4022. if (!c && !cv) return;
  4023. else if (c === cv) return;
  4024. aStyle.transform = c;
  4025. // return;
  4026. }
  4027.  
  4028. } else if (b === "display") {
  4029.  
  4030. const cv = a.style.display;
  4031. if (!cv && !c) return;
  4032. if (cv === c) return;
  4033.  
  4034.  
  4035. } else if (b === "width") {
  4036.  
  4037. const cv = a.style.width;
  4038. if (!cv && !c) return;
  4039. if (cv === c) return;
  4040.  
  4041. }
  4042.  
  4043. // console.log(130000, a, b, c);
  4044.  
  4045. if (byPassDefaultFn) return;
  4046. return attrUpdateFn.call(this, a, b, c);
  4047. }
  4048.  
  4049.  
  4050. /*
  4051.  
  4052. g.zo = function(a, b, c) {
  4053. if ("string" === typeof b)
  4054. (b = yo(a, b)) && (a.style[b] = c);
  4055. else
  4056. for (var d in b) {
  4057. c = a;
  4058. var e = b[d]
  4059. , f = yo(c, d);
  4060. f && (c.style[f] = e)
  4061. }
  4062. }
  4063.  
  4064.  
  4065. */
  4066.  
  4067.  
  4068. }
  4069.  
  4070.  
  4071.  
  4072. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  4073.  
  4074. if (keyuG) {
  4075.  
  4076. k = keyuG;
  4077.  
  4078. const gk = g[k];
  4079. const gkp = gk.prototype;
  4080.  
  4081.  
  4082. /** @type { Map<string, WeakMap<any, any>> } */
  4083. const ntLogs = new Map();
  4084.  
  4085. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  4086.  
  4087. gkp.updateValue31 = gkp.updateValue;
  4088. gkp.updateValue = function (a, b) {
  4089. if (typeof a !== 'string') return this.updateValue31(a, b);
  4090.  
  4091. const element = this.element;
  4092. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  4093.  
  4094. let ntLog = ntLogs.get(a);
  4095. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  4096.  
  4097. let cache = ntLog.get(element);
  4098. if (cache && cache.value === b) {
  4099. return;
  4100. }
  4101. if (!cache) {
  4102. this.__oldValueByUpdateValue__ = null;
  4103. ntLog.set(element, cache = { value: b });
  4104. } else {
  4105. this.__oldValueByUpdateValue__ = cache.value;
  4106. cache.value = b;
  4107. }
  4108.  
  4109.  
  4110. return this.updateValue31(a, b);
  4111. }
  4112.  
  4113.  
  4114. /*
  4115. g.k.update = function(a) {
  4116. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  4117. c = c.value,
  4118. this.updateValue(c, a[c])
  4119. }
  4120. ;
  4121. g.k.updateValue = function(a, b) {
  4122. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  4123. }
  4124. */
  4125.  
  4126.  
  4127. }
  4128.  
  4129.  
  4130. }
  4131.  
  4132.  
  4133.  
  4134.  
  4135. })();
  4136.  
  4137.  
  4138.  
  4139. FIX_Animation_n_timeline && (async () => {
  4140.  
  4141.  
  4142. const timeline = await new Promise(resolve => {
  4143.  
  4144. let cid = setInterval(() => {
  4145. let t = (((document || 0).timeline || 0) || 0);
  4146. if (t && typeof t._play === 'function') {
  4147.  
  4148. clearInterval(cid);
  4149. resolve(t);
  4150. }
  4151. }, 1);
  4152.  
  4153. promiseForTamerTimeout.then(() => {
  4154. resolve(null)
  4155. });
  4156.  
  4157. });
  4158.  
  4159.  
  4160. const Animation = await new Promise(resolve => {
  4161.  
  4162. let cid = setInterval(() => {
  4163. let t = (((window || 0).Animation || 0) || 0);
  4164. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  4165.  
  4166. clearInterval(cid);
  4167. resolve(t);
  4168. }
  4169. }, 1);
  4170.  
  4171. promiseForTamerTimeout.then(() => {
  4172. resolve(null)
  4173. });
  4174.  
  4175. });
  4176.  
  4177. if (!timeline) return;
  4178. if (!Animation) return;
  4179.  
  4180. const aniProto = Animation.prototype;
  4181. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  4182.  
  4183. const getXroto = (x) => {
  4184. try {
  4185. return x.__proto__;
  4186. } catch (e) { }
  4187. return null;
  4188. }
  4189. const timProto = getXroto(timeline);
  4190. if (!timProto) return;
  4191. if (
  4192. (
  4193. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  4194. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  4195. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  4196. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  4197. )
  4198.  
  4199. ) {
  4200.  
  4201. timProto.nofCQ = 1;
  4202. aniProto.nofYH = 1;
  4203.  
  4204. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  4205.  
  4206.  
  4207. /*
  4208. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  4209. return c._updatePromises();
  4210. });
  4211. */
  4212.  
  4213. const p = Array.prototype.filter;
  4214.  
  4215. let res = null;
  4216. Array.prototype.filter = function () {
  4217.  
  4218. res = this;
  4219. return this;
  4220.  
  4221. };
  4222.  
  4223. _updateAnimationsPromises.call({});
  4224.  
  4225. Array.prototype.filter = p;
  4226.  
  4227. if (res && typeof res.length === 'number') {
  4228. /** @type {any[]} */
  4229. const _res = res;
  4230. return _res;
  4231. }
  4232.  
  4233.  
  4234. return null;
  4235.  
  4236.  
  4237.  
  4238.  
  4239. })(timProto._updateAnimationsPromises);
  4240.  
  4241. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  4242.  
  4243. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  4244.  
  4245. aniProto._updatePromises31 = aniProto._updatePromises;
  4246.  
  4247. /*
  4248. aniProto._updatePromises = function(){
  4249. console.log('eff',this._oldPlayState, this.playState)
  4250. return this._updatePromises31.apply(this, arguments)
  4251. }
  4252. */
  4253.  
  4254. aniProto._updatePromises = function () {
  4255. var oldPlayState = this._oldPlayState;
  4256. var newPlayState = this.playState;
  4257. // console.log('ett', oldPlayState, newPlayState)
  4258. if (newPlayState !== oldPlayState) {
  4259. this._oldPlayState = newPlayState;
  4260. if (this._readyPromise) {
  4261. if ("idle" == newPlayState) {
  4262. this._rejectReadyPromise();
  4263. this._readyPromise = void 0;
  4264. } else if ("pending" == oldPlayState) {
  4265. this._resolveReadyPromise();
  4266. } else if ("pending" == newPlayState) {
  4267. this._readyPromise = void 0;
  4268. }
  4269. }
  4270. if (this._finishedPromise) {
  4271. if ("idle" == newPlayState) {
  4272. this._rejectFinishedPromise();
  4273. this._finishedPromise = void 0;
  4274. } else if ("finished" == newPlayState) {
  4275. this._resolveFinishedPromise();
  4276. } else if ("finished" == oldPlayState) {
  4277. this._finishedPromise = void 0;
  4278. }
  4279. }
  4280. }
  4281. return this._readyPromise || this._finishedPromise;
  4282. };
  4283.  
  4284.  
  4285. let restartWebAnimationsNextTickFlag = false;
  4286.  
  4287. const looperMethodT = () => {
  4288.  
  4289. const runnerFn = (hRes) => {
  4290. var b = timeline;
  4291. b.currentTime = hRes;
  4292. b._discardAnimations();
  4293. if (0 == b._animations.length) {
  4294. restartWebAnimationsNextTickFlag = false;
  4295. } else {
  4296. getRafPromise().then(runnerFn);
  4297. }
  4298. }
  4299.  
  4300. const restartWebAnimationsNextTick = () => {
  4301. if (!restartWebAnimationsNextTickFlag) {
  4302. restartWebAnimationsNextTickFlag = true;
  4303. getRafPromise().then(runnerFn);
  4304. }
  4305. }
  4306.  
  4307. return { restartWebAnimationsNextTick }
  4308. };
  4309.  
  4310.  
  4311. const looperMethodN = () => {
  4312.  
  4313. const acs = document.createElement('a-f');
  4314. acs.id = 'a-f';
  4315.  
  4316. const style = document.createElement('style');
  4317. style.textContent = `
  4318. @keyFrames aF1 {
  4319. 0% {
  4320. order: 0;
  4321. }
  4322. 100% {
  4323. order: 6;
  4324. }
  4325. }
  4326. #a-f[id] {
  4327. visibility: collapse !important;
  4328. position: fixed !important;
  4329. top: -100px !important;
  4330. left: -100px !important;
  4331. margin:0 !important;
  4332. padding:0 !important;
  4333. outline:0 !important;
  4334. border:0 !important;
  4335. z-index:-1 !important;
  4336. width: 0px !important;
  4337. height: 0px !important;
  4338. contain: strict !important;
  4339. pointer-events: none !important;
  4340. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  4341. }
  4342. `;
  4343. (document.head || document.documentElement).appendChild(style);
  4344.  
  4345. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  4346.  
  4347. const _onanimationiteration = function (evt) {
  4348. const hRes = evt.timeStamp;
  4349. var b = timeline;
  4350. b.currentTime = hRes;
  4351. b._discardAnimations();
  4352. if (0 == b._animations.length) {
  4353. restartWebAnimationsNextTickFlag = false;
  4354. acs.onanimationiteration = null;
  4355. } else {
  4356. acs.onanimationiteration = _onanimationiteration;
  4357. }
  4358.  
  4359. }
  4360.  
  4361.  
  4362.  
  4363. const restartWebAnimationsNextTick = () => {
  4364. if (!restartWebAnimationsNextTickFlag) {
  4365. restartWebAnimationsNextTickFlag = true;
  4366. acs.onanimationiteration = _onanimationiteration;
  4367.  
  4368. }
  4369. }
  4370.  
  4371. return { restartWebAnimationsNextTick }
  4372. };
  4373.  
  4374.  
  4375.  
  4376. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  4377.  
  4378.  
  4379. // console.log(571, timProto);
  4380. timProto._play = function (c) {
  4381. c = new Animation(c, this);
  4382. this._animations.push(c);
  4383. restartWebAnimationsNextTick();
  4384. c._updatePromises();
  4385. c._animation.play();
  4386. c._updatePromises();
  4387. return c
  4388. }
  4389.  
  4390. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  4391. originalAnimationsWithPromises.length = 0;
  4392. originalAnimationsWithPromises.push = null;
  4393. originalAnimationsWithPromises.splice = null;
  4394. originalAnimationsWithPromises.slice = null;
  4395. originalAnimationsWithPromises.indexOf = null;
  4396. originalAnimationsWithPromises.unshift = null;
  4397. originalAnimationsWithPromises.shift = null;
  4398. originalAnimationsWithPromises.pop = null;
  4399. originalAnimationsWithPromises.filter = null;
  4400. originalAnimationsWithPromises.forEach = null;
  4401. originalAnimationsWithPromises.map = null;
  4402.  
  4403.  
  4404. const _updateAnimationsPromises = () => {
  4405. animationsWithPromisesMap.forEach(c => {
  4406. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  4407. });
  4408. /*
  4409. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  4410. return c._updatePromises();
  4411. });
  4412. */
  4413. }
  4414.  
  4415. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  4416.  
  4417. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  4418.  
  4419. delete timProto._updateAnimationsPromises;
  4420. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  4421. get() {
  4422. if (animationsWithPromisesMap.size === 0) return nilFn;
  4423. return _updateAnimationsPromises;
  4424. },
  4425. set(nv) {
  4426. delete this._updateAnimationsPromises;
  4427. this._updateAnimationsPromises = nv;
  4428. },
  4429. enumerable: true,
  4430. configurable: true,
  4431. });
  4432.  
  4433.  
  4434. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  4435. aniProto.__finished_native_get__ = pdFinished.get;
  4436. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  4437.  
  4438.  
  4439. Object.defineProperty(aniProto, 'finished', {
  4440. get() {
  4441. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  4442. this._finishedPromise = new Promise((resolve, reject) => {
  4443. this._resolveFinishedPromise = function () {
  4444. resolve(this)
  4445. };
  4446. this._rejectFinishedPromise = function () {
  4447. reject({
  4448. type: DOMException.ABORT_ERR,
  4449. name: "AbortError"
  4450. })
  4451. };
  4452. }),
  4453. "finished" == this.playState && this._resolveFinishedPromise());
  4454. return this._finishedPromise
  4455. },
  4456. set: undefined,
  4457. enumerable: true,
  4458. configurable: true
  4459. });
  4460.  
  4461. }
  4462.  
  4463.  
  4464.  
  4465. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  4466. aniProto.__ready_native_get__ = pdReady.get;
  4467. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  4468.  
  4469. Object.defineProperty(aniProto, 'ready', {
  4470. get() {
  4471. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  4472. this._readyPromise = new Promise((resolve, reject) => {
  4473. this._resolveReadyPromise = function () {
  4474. resolve(this)
  4475. };
  4476. this._rejectReadyPromise = function () {
  4477. reject({
  4478. type: DOMException.ABORT_ERR,
  4479. name: "AbortError"
  4480. })
  4481. };
  4482. }),
  4483. "pending" !== this.playState && this._resolveReadyPromise());
  4484. return this._readyPromise
  4485. },
  4486. set: undefined,
  4487. enumerable: true,
  4488. configurable: true
  4489. });
  4490.  
  4491. }
  4492.  
  4493.  
  4494. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  4495.  
  4496. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  4497. const _rebuildUnderlyingAnimation = function () {
  4498. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  4499. this.effect && this.effect._onsample && (this.effect._onsample = null);
  4500. return this._rebuildUnderlyingAnimation21();
  4501. }
  4502. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  4503. // delete aniProto._rebuildUnderlyingAnimation;
  4504. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  4505. // get() {
  4506. // if (isNaN(this._sequenceNumber)) return nilFn;
  4507. // return this._rebuildUnderlyingAnimation21;
  4508. // },
  4509. // set(nv) {
  4510. // delete this._rebuildUnderlyingAnimation;
  4511. // this._rebuildUnderlyingAnimation = nv;
  4512. // },
  4513. // enumerable: true,
  4514. // configurable: true
  4515. // });
  4516. }
  4517.  
  4518.  
  4519. /*
  4520.  
  4521.  
  4522. function f(c) {
  4523. var b = v.timeline;
  4524. b.currentTime = c;
  4525. b._discardAnimations();
  4526. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  4527. }
  4528. var h = window.requestAnimationFrame;
  4529. window.requestAnimationFrame = function(c) {
  4530. return h(function(b) {
  4531. v.timeline._updateAnimationsPromises();
  4532. c(b);
  4533. v.timeline._updateAnimationsPromises()
  4534. })
  4535. }
  4536. ;
  4537. v.AnimationTimeline = function() {
  4538. this._animations = [];
  4539. this.currentTime = void 0
  4540. }
  4541. ;
  4542. v.AnimationTimeline.prototype = {
  4543. getAnimations: function() {
  4544. this._discardAnimations();
  4545. return this._animations.slice()
  4546. },
  4547. _updateAnimationsPromises: function() {
  4548. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  4549. return c._updatePromises()
  4550. })
  4551. },
  4552. _discardAnimations: function() {
  4553. this._updateAnimationsPromises();
  4554. this._animations = this._animations.filter(function(c) {
  4555. return "finished" != c.playState && "idle" != c.playState
  4556. })
  4557. },
  4558. _play: function(c) {
  4559. c = new v.Animation(c,this);
  4560. this._animations.push(c);
  4561. v.restartWebAnimationsNextTick();
  4562. c._updatePromises();
  4563. c._animation.play();
  4564. c._updatePromises();
  4565. return c
  4566. },
  4567. play: function(c) {
  4568. c && c.remove();
  4569. return this._play(c)
  4570. }
  4571. };
  4572. var d = !1;
  4573. v.restartWebAnimationsNextTick = function() {
  4574. d || (d = !0,
  4575. requestAnimationFrame(f))
  4576. }
  4577. ;
  4578. var a = new v.AnimationTimeline;
  4579. v.timeline = a;
  4580. try {
  4581. Object.defineProperty(window.document, "timeline", {
  4582. configurable: !0,
  4583. get: function() {
  4584. return a
  4585. }
  4586. })
  4587. } catch (c) {}
  4588. try {
  4589. window.document.timeline = a
  4590. } catch (c) {}
  4591.  
  4592. */
  4593.  
  4594.  
  4595.  
  4596. /*
  4597.  
  4598. var g = window.getComputedStyle;
  4599. Object.defineProperty(window, "getComputedStyle", {
  4600. configurable: !0,
  4601. enumerable: !0,
  4602. value: function() {
  4603. v.timeline._updateAnimationsPromises();
  4604. var e = g.apply(this, arguments);
  4605. h() && (e = g.apply(this, arguments));
  4606. v.timeline._updateAnimationsPromises();
  4607. return e
  4608. }
  4609. });
  4610.  
  4611. */
  4612.  
  4613.  
  4614.  
  4615.  
  4616. }
  4617.  
  4618.  
  4619.  
  4620.  
  4621. })();
  4622.  
  4623.  
  4624.  
  4625.  
  4626. promiseForCustomYtElementsReady.then(() => {
  4627.  
  4628. FIX_ytdExpander_childrenChanged && customElements.whenDefined('ytd-expander').then(() => {
  4629.  
  4630.  
  4631.  
  4632. let dummy;
  4633. let cProto;
  4634.  
  4635.  
  4636.  
  4637. dummy = document.createElement('ytd-expander');
  4638. cProto = insp(dummy).constructor.prototype;
  4639.  
  4640.  
  4641. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  4642.  
  4643.  
  4644. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  4645. cProto.childrenChanged14 = cProto.childrenChanged;
  4646.  
  4647. cProto.initChildrenObserver = function () {
  4648. var a = this;
  4649. this.observer = new MutationObserver(function () {
  4650. a.childrenChanged()
  4651. }
  4652. );
  4653. this.observer.observe(this.content, {
  4654. subtree: !0,
  4655. childList: !0,
  4656. attributes: !0,
  4657. characterData: !0
  4658. });
  4659. this.childrenChanged()
  4660. }
  4661. ;
  4662. cProto.childrenChanged = function () {
  4663. if (this.alwaysToggleable) {
  4664. this.canToggle = this.alwaysToggleable;
  4665. } else if (!this.canToggleJobId) {
  4666. this.canToggleJobId = 1;
  4667. getRafPromise().then(() => {
  4668. this.canToggleJobId = 0;
  4669. this.calculateCanCollapse()
  4670. })
  4671. }
  4672. }
  4673.  
  4674.  
  4675. // console.log(cProto.initChildrenObserver)
  4676. console.debug('ytd-expander-fix-childrenChanged');
  4677.  
  4678. }
  4679.  
  4680. })
  4681.  
  4682.  
  4683.  
  4684. FIX_paper_ripple_animate && customElements.whenDefined('paper-ripple').then(() => {
  4685.  
  4686.  
  4687.  
  4688. let dummy;
  4689. let cProto;
  4690. dummy = document.createElement('paper-ripple');
  4691. cProto = insp(dummy).constructor.prototype;
  4692.  
  4693. if (fnIntegrity(cProto.animate, '0.74.5')) {
  4694.  
  4695.  
  4696. cProto.animate34 = cProto.animate;
  4697. cProto.animate = function () {
  4698. if (this._animating) {
  4699. var a;
  4700. const ripples = this.ripples;
  4701. for (a = 0; a < ripples.length; ++a) {
  4702. var b = ripples[a];
  4703. b.draw();
  4704. this.$.background.style.opacity = b.outerOpacity;
  4705. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  4706. }
  4707. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  4708. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  4709. getRafPromise().then(this._boundAnimate38);
  4710. } else {
  4711. this.onAnimationComplete()
  4712. }
  4713. }
  4714. }
  4715.  
  4716. console.debug('FIX_paper_ripple_animate')
  4717.  
  4718. // console.log(cProto.animate)
  4719.  
  4720. }
  4721.  
  4722. });
  4723.  
  4724. if (FIX_doIdomRender) {
  4725.  
  4726.  
  4727. const xsetTimeout = function (f, d) {
  4728. if (xsetTimeout.m511 === 1 && !d) {
  4729. xsetTimeout.m511 = 2;
  4730. getRafPromise().then(f);
  4731. } else {
  4732. return setTimeout.apply(window, arguments)
  4733. }
  4734.  
  4735. }
  4736.  
  4737. const xrequestAnimationFrame = function (f) {
  4738. const h = f + "";
  4739. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  4740. xsetTimeout.m511 = 1;
  4741. f();
  4742. xsetTimeout.m511 = 0;
  4743. } else if (h.includes("requestAninmationFrameResolver")) {
  4744. getRafPromise().then(f);
  4745. } else {
  4746. return requestAnimationFrame.apply(window, arguments);
  4747. }
  4748. }
  4749.  
  4750. let busy = false;
  4751. const doIdomRender = function () {
  4752. if (busy) {
  4753. return this.doIdomRender13.apply(this, arguments);
  4754. }
  4755. busy = true;
  4756. const { requestAnimationFrame, setTimeout } = window;
  4757. window.requestAnimationFrame = xrequestAnimationFrame;
  4758. window.setTimeout = xsetTimeout;
  4759. let r = this.doIdomRender13.apply(this, arguments);
  4760. window.requestAnimationFrame = requestAnimationFrame;
  4761. window.setTimeout = setTimeout;
  4762. busy = false;
  4763. return r;
  4764. };
  4765. 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']) {
  4766.  
  4767.  
  4768. customElements.whenDefined(ytTag).then(() => {
  4769.  
  4770. let dummy;
  4771. let cProto;
  4772. dummy = document.createElement(ytTag);
  4773. cProto = insp(dummy).constructor.prototype;
  4774.  
  4775. cProto.doIdomRender13 = cProto.doIdomRender;
  4776. cProto.doIdomRender = doIdomRender;
  4777.  
  4778. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  4779.  
  4780. console.debug('FIX_doIdomRender', ytTag)
  4781.  
  4782.  
  4783.  
  4784. });
  4785.  
  4786. }
  4787.  
  4788. }
  4789.  
  4790.  
  4791.  
  4792. });
  4793.  
  4794. });
  4795.  
  4796.  
  4797. setupEvents();
  4798.  
  4799.  
  4800.  
  4801. if (isMainWindow) {
  4802.  
  4803. console.groupCollapsed(
  4804. "%cYouTube JS Engine Tamer",
  4805. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  4806. );
  4807.  
  4808.  
  4809.  
  4810. console.log("Script is loaded.");
  4811. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  4812.  
  4813. console.log("This script is experimental and subject to further changes.");
  4814.  
  4815. console.log("This might boost your YouTube performance.");
  4816.  
  4817. console.log("CAUTION: This might break your YouTube.");
  4818.  
  4819.  
  4820. if (prepareLogs.length >= 1) {
  4821. console.log(" =========================================================================== ");
  4822.  
  4823. for (const msg of prepareLogs) {
  4824. console.log(msg)
  4825. }
  4826.  
  4827. console.log(" =========================================================================== ");
  4828. }
  4829.  
  4830. console.groupEnd();
  4831.  
  4832. }
  4833.  
  4834.  
  4835.  
  4836.  
  4837.  
  4838.  
  4839. })();