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