YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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