YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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