YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2023-10-07 提交的版本,查看 最新版本

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