YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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