YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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