YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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