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