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