YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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