YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前为 2023-10-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.6.17
  6. // @license MIT
  7. // @author CY Fung
  8. // @icon https://github.com/cyfung1031/userscript-supports/raw/main/icons/yt-engine.png
  9. // @description To enhance YouTube performance by modifying YouTube JS Engine
  10. // @grant none
  11. // @run-at document-start
  12. // @unwrap
  13. // @inject-into page
  14. // @allFrames true
  15. // ==/UserScript==
  16.  
  17. (() => {
  18.  
  19. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  20. const FIX_schedulerInstanceInstance_V1 = false;
  21. const FIX_schedulerInstanceInstance_V2 = true;
  22. const FIX_yt_player = true;
  23. const FIX_Animation_n_timeline = true;
  24. const NO_PRELOAD_GENERATE_204 = false;
  25. const CHANGE_appendChild = true;
  26.  
  27. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  28. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  29. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  30.  
  31. const FIX_Iframe_NULL_SRC = true;
  32.  
  33. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  34.  
  35. const FIX_ytdExpander_childrenChanged = true;
  36. const FIX_paper_ripple_animate = true;
  37.  
  38. const FIX_doIdomRender = true;
  39.  
  40. const FIX_Shady = true;
  41.  
  42. const FIX_ytAction_ = true; // ytd-app
  43. const FIX_onVideoDataChange = true;
  44. // const FIX_onClick = true;
  45. const FIX_onStateChange = true;
  46. const FIX_onLoopRangeChange = true;
  47. const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  48. const FIX_VideoEVENTS = false; // 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) {
  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);
  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. HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  2566. 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. }
  2596.  
  2597.  
  2598. return this.appendChild73.apply(this, arguments)
  2599. }
  2600.  
  2601.  
  2602. })();
  2603.  
  2604. if (FIX_Shady) {
  2605.  
  2606. let cidSL = setInterval(() => {
  2607. const { ShadyDOM, ShadyCSS } = window;
  2608. if (ShadyDOM && ShadyCSS) {
  2609. clearInterval(cidSL);
  2610. cidSL = 0;
  2611. }
  2612. if (ShadyDOM) {
  2613. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  2614. ShadyDOM.noPatch = true; // 1 of 10
  2615. ShadyDOM.patchOnDemand = false; // 1 of 10
  2616. ShadyDOM.preferPerformance = true; // 1 of 10
  2617. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  2618. }
  2619. if (ShadyCSS) {
  2620. ShadyCSS.nativeCss = true; // 1 of 10
  2621. ShadyCSS.nativeShadow = true; // 6 of 10
  2622. ShadyCSS.cssBuild = undefined; // 1 of 10
  2623. ShadyCSS.disableRuntime = true; // 1 of 10
  2624. }
  2625. }, 1);
  2626.  
  2627. }
  2628.  
  2629.  
  2630. FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 && (async () => {
  2631.  
  2632.  
  2633. const schedulerInstanceInstance_ = await new Promise(resolve => {
  2634.  
  2635. let cid = setInterval(() => {
  2636. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2637. if (t) {
  2638.  
  2639. clearInterval(cid);
  2640. resolve(t);
  2641. }
  2642. }, 1);
  2643. promiseForTamerTimeout.then(() => {
  2644. resolve(null)
  2645. });
  2646. });
  2647.  
  2648. if (!schedulerInstanceInstance_) return;
  2649.  
  2650.  
  2651. if (!ytEvented) {
  2652. idleFrom = Date.now() + 2700;
  2653. slowMode = false; // integrity
  2654. }
  2655.  
  2656. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2657. if (checkOK) {
  2658.  
  2659.  
  2660. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  2661.  
  2662. let requestingFn = null;
  2663. let requestingArgs = null;
  2664. let requestingDT = 0;
  2665.  
  2666. // let timerId = null;
  2667. const entries = [];
  2668. const f = function () {
  2669. requestingFn = this.fn;
  2670. requestingArgs = [...arguments];
  2671. requestingDT = Date.now();
  2672. entries.push({
  2673. fn: requestingFn,
  2674. args: requestingArgs,
  2675. t: requestingDT
  2676. });
  2677. // if (Date.now() < idleFrom) {
  2678. // timerId = this.fn.apply(window, arguments);
  2679. // } else {
  2680. // timerId = this.fn.apply(window, arguments);
  2681.  
  2682. // }
  2683. // timerId = 12377;
  2684. return 12377;
  2685. }
  2686.  
  2687.  
  2688. const fakeFns = [
  2689. f.bind({ fn: requestAnimationFrame }),
  2690. f.bind({ fn: setInterval }),
  2691. f.bind({ fn: setTimeout }),
  2692. f.bind({ fn: requestIdleCallback })
  2693. ]
  2694.  
  2695.  
  2696.  
  2697.  
  2698. let timerResolve = null;
  2699. setInterval(() => {
  2700. timerResolve && timerResolve();
  2701. timerResolve = null;
  2702. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  2703. }, 250);
  2704.  
  2705. let mzt = 0;
  2706.  
  2707. let fnSelectorProp = null;
  2708.  
  2709. schedulerInstanceInstance_.start = function () {
  2710.  
  2711. const mk1 = window.requestAnimationFrame
  2712. const mk2 = window.setInterval
  2713. const mk3 = window.setTimeout
  2714. const mk4 = window.requestIdleCallback
  2715.  
  2716. const tThis = this['$$12378$$'] || this;
  2717.  
  2718.  
  2719. window.requestAnimationFrame = fakeFns[0]
  2720. window.setInterval = fakeFns[1]
  2721. window.setTimeout = fakeFns[2]
  2722. window.requestIdleCallback = fakeFns[3]
  2723.  
  2724. fnSelectorProp = null;
  2725.  
  2726.  
  2727. tThis.start991.call(new Proxy(tThis, {
  2728. get(target, prop, receiver) {
  2729. if (prop === '$$12377$$') return true;
  2730. if (prop === '$$12378$$') return target;
  2731.  
  2732. // console.log('get',prop)
  2733. return target[prop]
  2734. },
  2735. set(target, prop, value, receiver) {
  2736. // console.log('set', prop, value)
  2737.  
  2738.  
  2739. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  2740. if (value === 12377 && fnSelectorProp) {
  2741.  
  2742. const originalSelection = target[fnSelectorProp];
  2743. const timerIdProp = prop;
  2744.  
  2745. /*
  2746.  
  2747.  
  2748. case 1:
  2749. var a = this.K;
  2750. this.g = this.I ? window.requestIdleCallback(a, {
  2751. timeout: 3E3
  2752. }) : window.setTimeout(a, ma);
  2753. break;
  2754. case 2:
  2755. this.g = window.setTimeout(this.M, this.N);
  2756. break;
  2757. case 3:
  2758. this.g = window.requestAnimationFrame(this.L);
  2759. break;
  2760. case 4:
  2761. this.g = window.setTimeout(this.J, 0)
  2762. }
  2763.  
  2764. */
  2765.  
  2766. const doForegroundSlowMode = () => {
  2767.  
  2768. const tir = ++mzt;
  2769. const f = requestingArgs[0];
  2770.  
  2771.  
  2772. getForegroundPromise().then(() => {
  2773.  
  2774.  
  2775. new Promise(r => {
  2776. timerResolve = r
  2777. }).then(() => {
  2778. if (target[timerIdProp] === -tir) f();
  2779. });
  2780.  
  2781. })
  2782.  
  2783. target[fnSelectorProp] = 931;
  2784. target[prop] = -tir;
  2785. }
  2786.  
  2787. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  2788. if (slowMode && !(requestingArgs[1] > 250)) {
  2789.  
  2790. doForegroundSlowMode();
  2791.  
  2792. } else {
  2793. target[prop] = setTimeout.apply(window, requestingArgs);
  2794.  
  2795. }
  2796.  
  2797. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  2798.  
  2799. if (slowMode) {
  2800.  
  2801. doForegroundSlowMode();
  2802.  
  2803. } else {
  2804. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  2805. }
  2806.  
  2807.  
  2808. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  2809.  
  2810. const f = requestingArgs[0];
  2811. const tir = ++mzt;
  2812. Promise.resolve().then(() => {
  2813. if (target[timerIdProp] === -tir) f();
  2814. });
  2815. target[fnSelectorProp] = 930;
  2816. target[prop] = -tir;
  2817.  
  2818. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  2819.  
  2820. doForegroundSlowMode();
  2821.  
  2822. } else {
  2823. // target[prop] = timerId;
  2824. target[fnSelectorProp] = 0;
  2825. target[prop] = 0;
  2826. }
  2827.  
  2828. // *****
  2829. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  2830. } else {
  2831.  
  2832. target[prop] = value;
  2833. }
  2834. // console.log('set',prop,value)
  2835. return true;
  2836. }
  2837. }));
  2838.  
  2839. fnSelectorProp = null;
  2840.  
  2841.  
  2842. window.requestAnimationFrame = mk1;
  2843. window.setInterval = mk2
  2844. window.setTimeout = mk3
  2845. window.requestIdleCallback = mk4;
  2846.  
  2847.  
  2848.  
  2849. }
  2850.  
  2851. schedulerInstanceInstance_.start.toString = function () {
  2852. return schedulerInstanceInstance_.start991.toString();
  2853. }
  2854.  
  2855. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  2856. // prop,
  2857. // value: schedulerInstanceInstance_[prop],
  2858. // type: typeof schedulerInstanceInstance_[prop]
  2859.  
  2860. // }));
  2861. // console.log('fcc', funcNames)
  2862.  
  2863.  
  2864.  
  2865.  
  2866. }
  2867. })();
  2868.  
  2869.  
  2870.  
  2871. FIX_schedulerInstanceInstance_V2 && !FIX_schedulerInstanceInstance_V1 && (async () => {
  2872.  
  2873.  
  2874. const schedulerInstanceInstance_ = await new Promise(resolve => {
  2875.  
  2876. let cid = setInterval(() => {
  2877. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2878. if (t) {
  2879.  
  2880. clearInterval(cid);
  2881. resolve(t);
  2882. }
  2883. }, 1);
  2884. promiseForTamerTimeout.then(() => {
  2885. resolve(null)
  2886. });
  2887. });
  2888.  
  2889. if (!schedulerInstanceInstance_) return;
  2890.  
  2891.  
  2892. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2893. if (checkOK) {
  2894.  
  2895. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  2896.  
  2897.  
  2898.  
  2899. let busy = false;
  2900.  
  2901. // console.log('1667',schedulerInstanceInstance_.start);
  2902. schedulerInstanceInstance_.start = function () {
  2903.  
  2904. // p59 || console.log(location.pathname, 16400);
  2905.  
  2906. if (busy) {
  2907.  
  2908. return this.start991.call(this);
  2909.  
  2910. }
  2911.  
  2912. busy = true;
  2913.  
  2914. const mk1 = window.requestAnimationFrame
  2915. // const mk2 = window.setInterval
  2916. // const mk3 = window.setTimeout
  2917. // const mk4 = window.requestIdleCallback
  2918.  
  2919. // by pass Youtube Engine's wrapping
  2920. window.requestAnimationFrame = baseRAF;
  2921. // window.setInterval = setInterval
  2922. // window.setTimeout = setTimeout
  2923. // window.requestIdleCallback = requestIdleCallback
  2924.  
  2925.  
  2926. this.start991.call(this);
  2927.  
  2928.  
  2929. window.requestAnimationFrame = mk1;
  2930. // window.setInterval = mk2
  2931. // window.setTimeout = mk3
  2932. // window.requestIdleCallback = mk4;
  2933.  
  2934. busy = false;
  2935.  
  2936.  
  2937.  
  2938. }
  2939.  
  2940. schedulerInstanceInstance_.start.toString = function () {
  2941. return schedulerInstanceInstance_.start991.toString();
  2942. }
  2943.  
  2944. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  2945. // prop,
  2946. // value: schedulerInstanceInstance_[prop],
  2947. // type: typeof schedulerInstanceInstance_[prop]
  2948.  
  2949. // }));
  2950. // console.log('fcc', funcNames)
  2951.  
  2952.  
  2953.  
  2954.  
  2955. }
  2956. })();
  2957.  
  2958. FIX_yt_player && (async () => {
  2959.  
  2960.  
  2961.  
  2962. // const rafHub = new RAFHub();
  2963.  
  2964.  
  2965. const _yt_player = await new Promise(resolve => {
  2966.  
  2967. let cid = setInterval(() => {
  2968. let t = (((window || 0)._yt_player || 0) || 0);
  2969. if (t) {
  2970.  
  2971. clearInterval(cid);
  2972. resolve(t);
  2973. }
  2974. }, 1);
  2975.  
  2976. promiseForTamerTimeout.then(() => {
  2977. resolve(null)
  2978. });
  2979.  
  2980. });
  2981.  
  2982.  
  2983.  
  2984. if (!_yt_player || typeof _yt_player !== 'object') return;
  2985.  
  2986.  
  2987.  
  2988. let keyZq = getZq(_yt_player);
  2989. // let keyVG = getVG(_yt_player);
  2990. // let buildVG = _yt_player[keyVG];
  2991. // let u = new buildVG({
  2992. // api: {},
  2993. // element: document.createElement('noscript'),
  2994. // api: {},
  2995. // hide: () => { }
  2996. // }, 250);
  2997. // const timeDelayConstructor = u.delay.constructor; // g.br
  2998. // console.log(keyVG, u)
  2999. // buildVG.prototype.show = function(){}
  3000. // _yt_player[keyZq] = g.k
  3001.  
  3002. if (!keyZq) return;
  3003.  
  3004.  
  3005. const g = _yt_player
  3006. let k = keyZq
  3007.  
  3008. const gk = g[k];
  3009. if (typeof gk !== 'function') return;
  3010. const gkp = gk.prototype;
  3011.  
  3012. let dummyObject = new gk;
  3013. let nilFunc = () => { };
  3014.  
  3015. let nilObj = {};
  3016.  
  3017. // console.log(1111111111)
  3018.  
  3019. let keyBoolD = '';
  3020. let keyWindow = '';
  3021. let keyFuncC = '';
  3022. let keyCidj = '';
  3023.  
  3024. for (const [t, y] of Object.entries(dummyObject)) {
  3025. if (y instanceof Window) keyWindow = t;
  3026. }
  3027.  
  3028. const dummyObjectProxyHandler = {
  3029. get(target, prop) {
  3030. let v = target[prop]
  3031. if (v instanceof Window && !keyWindow) {
  3032. keyWindow = t;
  3033. }
  3034. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  3035. if (prop === keyWindow) y = {
  3036. requestAnimationFrame(f) {
  3037. return 3;
  3038. },
  3039. cancelAnimationFrame() {
  3040.  
  3041. }
  3042. }
  3043. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  3044. keyFuncC = prop;
  3045. }
  3046. // console.log('[get]', prop, typeof target[prop])
  3047.  
  3048.  
  3049. return y;
  3050. },
  3051. set(target, prop, value) {
  3052.  
  3053. if (typeof value === 'boolean' && !keyBoolD) {
  3054. keyBoolD = prop;
  3055. }
  3056. if (typeof value === 'number' && !keyCidj && value >= 2) {
  3057. keyCidj = prop;
  3058. }
  3059.  
  3060. // console.log('[set]', prop, value)
  3061. target[prop] = value
  3062.  
  3063. return true;
  3064. }
  3065. };
  3066.  
  3067. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  3068.  
  3069. /*
  3070. console.log({
  3071. keyBoolD,
  3072. keyFuncC,
  3073. keyWindow,
  3074. keyCidj
  3075. })
  3076.  
  3077. console.log( dummyObject[keyFuncC])
  3078.  
  3079.  
  3080. console.log(2222222222)
  3081. */
  3082.  
  3083.  
  3084. // console.log('gkp.start',gkp.start);
  3085. // console.log('gkp.stop',gkp.stop);
  3086. gkp._activation = false;
  3087.  
  3088. gkp.start = function () {
  3089. // p59 || console.log(12100)
  3090. if (!this._activation) {
  3091. this._activation = true;
  3092. getRafPromise().then(() => {
  3093. this._activation = false;
  3094. if (this[keyCidj]) {
  3095. Promise.resolve().then(this[keyFuncC]);
  3096. }
  3097. });
  3098. }
  3099. this[keyCidj] = 1;
  3100. this[keyBoolD] = true;
  3101. }
  3102. ;
  3103. gkp.stop = function () {
  3104. this[keyCidj] = null
  3105. }
  3106.  
  3107.  
  3108. /*
  3109. g[k].start = function() {
  3110. this.stop();
  3111. this.D = true;
  3112. var a = requestAnimationFrame
  3113. , b = cancelAnimationFrame;
  3114. this.j = a.call(this.B, this.C)
  3115. }
  3116. ;
  3117. g[k].stop = function() {
  3118. if (this.isActive()) {
  3119. var a = requestAnimationFrame
  3120. , b = cancelAnimationFrame;
  3121. b.call(this.B, this.j)
  3122. }
  3123. this.j = null
  3124. }
  3125. */
  3126.  
  3127.  
  3128.  
  3129. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  3130.  
  3131. if (keyzo) {
  3132.  
  3133. k = keyzo
  3134.  
  3135. const setCSSProp = (() => {
  3136.  
  3137. let animationPropCapable = false;
  3138. try {
  3139. const propName = "--ibxpf"
  3140. const value = 2;
  3141. const keyframes = [{
  3142. [propName]: value
  3143. }];
  3144. window.CSS.registerProperty({
  3145. name: "--ibxpf",
  3146. syntax: "<number>",
  3147. inherits: false,
  3148. initialValue: 1,
  3149. });
  3150. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  3151. } catch (e) { }
  3152.  
  3153. if (!animationPropCapable) {
  3154. return (element, cssProp, value) => {
  3155.  
  3156.  
  3157. element.style.setProperty(cssProp, value);
  3158.  
  3159. }
  3160. }
  3161.  
  3162. const propMaps = new Map();
  3163.  
  3164. function setCustomCSSProperty(element, propName, value) {
  3165. let wm = propMaps.get(propName);
  3166. if (!wm) {
  3167.  
  3168. try {
  3169. window.CSS.registerProperty({
  3170. name: propName,
  3171. syntax: "*",
  3172. inherits: false
  3173. });
  3174. } catch (e) {
  3175. console.warn(e);
  3176. }
  3177.  
  3178. propMaps.set(propName, (wm = new WeakMap()));
  3179. }
  3180.  
  3181. // Create the animation keyframes with the provided property and value
  3182. const keyframes = [{
  3183. [propName]: value
  3184. }];
  3185.  
  3186. let currentAnimation = wm.get(element);
  3187. if (currentAnimation) {
  3188.  
  3189. currentAnimation.effect.setKeyframes(keyframes);
  3190.  
  3191. } else {
  3192.  
  3193.  
  3194.  
  3195. // Set the animation on the element and immediately pause it
  3196. const animation = animate.call(element, keyframes, {
  3197. duration: 1, // Very short duration as we just want to set the value
  3198. fill: 'forwards',
  3199. iterationStart: 1,
  3200. iterations: 2,
  3201. direction: 'alternate'
  3202. });
  3203.  
  3204.  
  3205. // animation.currentTime = 1;
  3206. animation.pause();
  3207.  
  3208. wm.set(element, animation);
  3209.  
  3210.  
  3211. }
  3212.  
  3213. }
  3214.  
  3215. return setCustomCSSProperty;
  3216.  
  3217.  
  3218. })();
  3219.  
  3220.  
  3221. const attrUpdateFn = g[k];
  3222. g['$$original$$' + k] = attrUpdateFn;
  3223. g[k] = function (a, b, c) {
  3224.  
  3225. // console.log(140000, a, b, c);
  3226.  
  3227. let transformType = '';
  3228. let transformValue = 0;
  3229. let transformUnit = '';
  3230.  
  3231. let byPassDefaultFn = false;
  3232. if (b === "transform" && typeof c === 'string') {
  3233.  
  3234. byPassDefaultFn = true;
  3235.  
  3236. const aStyle = a.style;
  3237.  
  3238. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  3239. if (!(a instanceof HTMLElement)) return;
  3240. if (c.length === 0) {
  3241.  
  3242. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  3243. let p = c.substring(7, c.length - 1);
  3244. let q = p.length >= 1 ? parseFloat(p) : -1;
  3245. if (q > -1e-5 && q < 1 + 1e-5) {
  3246. transformType = 'scalex'
  3247. transformValue = q;
  3248. transformUnit = '';
  3249. }
  3250.  
  3251.  
  3252. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  3253.  
  3254. let p = c.substring(11, c.length - 3);
  3255. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3256.  
  3257. if (typeof q === 'number' && !isNaN(q)) {
  3258. transformType = 'translateX'
  3259. transformValue = q;
  3260. transformUnit = 'px';
  3261. }
  3262.  
  3263.  
  3264. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  3265. let p = c.substring(7, c.length - 1);
  3266. let q = p.length >= 1 ? parseFloat(p) : -1;
  3267. if (q > -1e-5 && q < 1 + 1e-5) {
  3268. transformType = 'scaley'
  3269. transformValue = q;
  3270. transformUnit = '';
  3271. }
  3272.  
  3273.  
  3274. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  3275.  
  3276. let p = c.substring(11, c.length - 3);
  3277. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3278.  
  3279. if (typeof q === 'number' && !isNaN(q)) {
  3280. transformType = 'translateY'
  3281. transformValue = q;
  3282. transformUnit = 'px';
  3283. }
  3284.  
  3285.  
  3286. }
  3287.  
  3288. if (transformType) {
  3289.  
  3290. if (transformType === 'scalex' || transformType === 'scaley') {
  3291.  
  3292. const q = transformValue;
  3293.  
  3294.  
  3295. /*
  3296.  
  3297. let vz = Math.round(steppingScaleN * q);
  3298. const customPropName = '--discrete-'+transformType
  3299.  
  3300. const currentValue = aStyle.getPropertyValue(customPropName);
  3301.  
  3302. const transform = (aStyle.transform || '');
  3303. const u = transform.includes(customPropName)
  3304. if (`${currentValue}` === `${vz}`) {
  3305. if (u) return;
  3306. }
  3307.  
  3308.  
  3309. setCSSProp(a,customPropName, vz);
  3310. // aStyle.setProperty(customPropName, vz)
  3311.  
  3312. let ck = '';
  3313.  
  3314. if (c.length === 9) ck = c;
  3315. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3316.  
  3317. if (ck && beforeMq !== ck) {
  3318. aStyle.setProperty('--mq-transform', ck);
  3319. }
  3320.  
  3321. if (u) return;
  3322. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  3323.  
  3324.  
  3325.  
  3326. */
  3327.  
  3328. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  3329.  
  3330. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  3331. const cv = aStyle.transform;
  3332.  
  3333. // console.log(157, cv,c)
  3334.  
  3335. if (c === cv) return;
  3336. // console.log(257, cv,c)
  3337.  
  3338. aStyle.transform = c;
  3339.  
  3340. // return;
  3341.  
  3342. } else if (transformType === 'translateX' || transformType === 'translateY') {
  3343.  
  3344. const q = transformValue;
  3345.  
  3346. /*
  3347.  
  3348. let vz = q.toFixed(1);
  3349. const customPropName = '--discrete-'+transformType
  3350.  
  3351. const aStyle = a.style;
  3352. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  3353.  
  3354.  
  3355. const transform = (aStyle.transform || '');
  3356. const u = transform.includes(customPropName)
  3357. if (parseFloat(currentValue).toFixed(1) === vz) {
  3358. if (u) return;
  3359. }
  3360.  
  3361. setCSSProp(a,customPropName, vz + 'px');
  3362. // aStyle.setProperty(customPropName, vz + 'px')
  3363.  
  3364. let ck = '';
  3365. if (c.length === 15) ck = c;
  3366. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3367.  
  3368. if (ck && beforeMq !== ck) {
  3369. aStyle.setProperty('--mq-transform', ck);
  3370. }
  3371.  
  3372. if (u) return;
  3373. c = `${transformType}(var(--discrete-${transformType}))`;
  3374.  
  3375. */
  3376.  
  3377.  
  3378. const vz = +q.toFixed(1);
  3379.  
  3380. c = `${transformType}(${vz}${transformUnit})`
  3381. const cv = aStyle.transform;
  3382.  
  3383. // console.log(158, cv,c)
  3384.  
  3385. if (c === cv) return;
  3386. // console.log(258, cv,c)
  3387.  
  3388. aStyle.transform = c;
  3389.  
  3390. // return;
  3391.  
  3392. } else {
  3393. throw new Error();
  3394. }
  3395.  
  3396. } else {
  3397. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  3398. const cv = aStyle.transform
  3399. if (!c && !cv) return;
  3400. else if (c === cv) return;
  3401. aStyle.transform = c;
  3402. // return;
  3403. }
  3404.  
  3405. } else if (b === "display") {
  3406.  
  3407. const cv = a.style.display;
  3408. if (!cv && !c) return;
  3409. if (cv === c) return;
  3410.  
  3411.  
  3412. } else if (b === "width") {
  3413.  
  3414. const cv = a.style.width;
  3415. if (!cv && !c) return;
  3416. if (cv === c) return;
  3417.  
  3418. }
  3419.  
  3420. // console.log(130000, a, b, c);
  3421.  
  3422. if (byPassDefaultFn) return;
  3423. return attrUpdateFn.call(this, a, b, c);
  3424. }
  3425.  
  3426.  
  3427. /*
  3428.  
  3429. g.zo = function(a, b, c) {
  3430. if ("string" === typeof b)
  3431. (b = yo(a, b)) && (a.style[b] = c);
  3432. else
  3433. for (var d in b) {
  3434. c = a;
  3435. var e = b[d]
  3436. , f = yo(c, d);
  3437. f && (c.style[f] = e)
  3438. }
  3439. }
  3440.  
  3441.  
  3442. */
  3443.  
  3444.  
  3445. }
  3446.  
  3447.  
  3448.  
  3449. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  3450.  
  3451. if (keyuG) {
  3452.  
  3453. k = keyuG;
  3454.  
  3455. const gk = g[k];
  3456. const gkp = gk.prototype;
  3457.  
  3458.  
  3459. /** @type { Map<string, WeakMap<any, any>> } */
  3460. const ntLogs = new Map();
  3461.  
  3462. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  3463.  
  3464. gkp.updateValue31 = gkp.updateValue;
  3465. gkp.updateValue = function (a, b) {
  3466. if (typeof a !== 'string') return this.updateValue31(a, b);
  3467.  
  3468. const element = this.element;
  3469. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  3470.  
  3471. let ntLog = ntLogs.get(a);
  3472. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  3473.  
  3474. let cache = ntLog.get(element);
  3475. if (cache && cache.value === b) {
  3476. return;
  3477. }
  3478. if (!cache) {
  3479. this.__oldValueByUpdateValue__ = null;
  3480. ntLog.set(element, cache = { value: b });
  3481. } else {
  3482. this.__oldValueByUpdateValue__ = cache.value;
  3483. cache.value = b;
  3484. }
  3485.  
  3486.  
  3487. return this.updateValue31(a, b);
  3488. }
  3489.  
  3490.  
  3491. /*
  3492. g.k.update = function(a) {
  3493. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  3494. c = c.value,
  3495. this.updateValue(c, a[c])
  3496. }
  3497. ;
  3498. g.k.updateValue = function(a, b) {
  3499. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  3500. }
  3501. */
  3502.  
  3503.  
  3504. }
  3505.  
  3506.  
  3507. }
  3508.  
  3509.  
  3510.  
  3511.  
  3512. })();
  3513.  
  3514.  
  3515.  
  3516. FIX_Animation_n_timeline && (async () => {
  3517.  
  3518.  
  3519. const timeline = await new Promise(resolve => {
  3520.  
  3521. let cid = setInterval(() => {
  3522. let t = (((document || 0).timeline || 0) || 0);
  3523. if (t && typeof t._play === 'function') {
  3524.  
  3525. clearInterval(cid);
  3526. resolve(t);
  3527. }
  3528. }, 1);
  3529.  
  3530. promiseForTamerTimeout.then(() => {
  3531. resolve(null)
  3532. });
  3533.  
  3534. });
  3535.  
  3536.  
  3537. const Animation = await new Promise(resolve => {
  3538.  
  3539. let cid = setInterval(() => {
  3540. let t = (((window || 0).Animation || 0) || 0);
  3541. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  3542.  
  3543. clearInterval(cid);
  3544. resolve(t);
  3545. }
  3546. }, 1);
  3547.  
  3548. promiseForTamerTimeout.then(() => {
  3549. resolve(null)
  3550. });
  3551.  
  3552. });
  3553.  
  3554. if (!timeline) return;
  3555. if (!Animation) return;
  3556.  
  3557. const aniProto = Animation.prototype;
  3558. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  3559.  
  3560. const getXroto = (x) => {
  3561. try {
  3562. return x.__proto__;
  3563. } catch (e) { }
  3564. return null;
  3565. }
  3566. const timProto = getXroto(timeline);
  3567. if (!timProto) return;
  3568. if (
  3569. (
  3570. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  3571. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  3572. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  3573. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  3574. )
  3575.  
  3576. ) {
  3577.  
  3578. timProto.nofCQ = 1;
  3579. aniProto.nofYH = 1;
  3580.  
  3581. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  3582.  
  3583.  
  3584. /*
  3585. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3586. return c._updatePromises();
  3587. });
  3588. */
  3589.  
  3590. const p = Array.prototype.filter;
  3591.  
  3592. let res = null;
  3593. Array.prototype.filter = function () {
  3594.  
  3595. res = this;
  3596. return this;
  3597.  
  3598. };
  3599.  
  3600. _updateAnimationsPromises.call({});
  3601.  
  3602. Array.prototype.filter = p;
  3603.  
  3604. if (res && typeof res.length === 'number') {
  3605. /** @type {any[]} */
  3606. const _res = res;
  3607. return _res;
  3608. }
  3609.  
  3610.  
  3611. return null;
  3612.  
  3613.  
  3614.  
  3615.  
  3616. })(timProto._updateAnimationsPromises);
  3617.  
  3618. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  3619.  
  3620. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  3621.  
  3622. aniProto._updatePromises31 = aniProto._updatePromises;
  3623.  
  3624. /*
  3625. aniProto._updatePromises = function(){
  3626. console.log('eff',this._oldPlayState, this.playState)
  3627. return this._updatePromises31.apply(this, arguments)
  3628. }
  3629. */
  3630.  
  3631. aniProto._updatePromises = function () {
  3632. var oldPlayState = this._oldPlayState;
  3633. var newPlayState = this.playState;
  3634. // console.log('ett', oldPlayState, newPlayState)
  3635. if (newPlayState !== oldPlayState) {
  3636. this._oldPlayState = newPlayState;
  3637. if (this._readyPromise) {
  3638. if ("idle" == newPlayState) {
  3639. this._rejectReadyPromise();
  3640. this._readyPromise = void 0;
  3641. } else if ("pending" == oldPlayState) {
  3642. this._resolveReadyPromise();
  3643. } else if ("pending" == newPlayState) {
  3644. this._readyPromise = void 0;
  3645. }
  3646. }
  3647. if (this._finishedPromise) {
  3648. if ("idle" == newPlayState) {
  3649. this._rejectFinishedPromise();
  3650. this._finishedPromise = void 0;
  3651. } else if ("finished" == newPlayState) {
  3652. this._resolveFinishedPromise();
  3653. } else if ("finished" == oldPlayState) {
  3654. this._finishedPromise = void 0;
  3655. }
  3656. }
  3657. }
  3658. return this._readyPromise || this._finishedPromise;
  3659. };
  3660.  
  3661.  
  3662. let restartWebAnimationsNextTickFlag = false;
  3663.  
  3664. const looperMethodT = () => {
  3665.  
  3666. const runnerFn = (hRes) => {
  3667. var b = timeline;
  3668. b.currentTime = hRes;
  3669. b._discardAnimations();
  3670. if (0 == b._animations.length) {
  3671. restartWebAnimationsNextTickFlag = false;
  3672. } else {
  3673. getRafPromise().then(runnerFn);
  3674. }
  3675. }
  3676.  
  3677. const restartWebAnimationsNextTick = () => {
  3678. if (!restartWebAnimationsNextTickFlag) {
  3679. restartWebAnimationsNextTickFlag = true;
  3680. getRafPromise().then(runnerFn);
  3681. }
  3682. }
  3683.  
  3684. return { restartWebAnimationsNextTick }
  3685. };
  3686.  
  3687.  
  3688. const looperMethodN = () => {
  3689.  
  3690. const acs = document.createElement('a-f');
  3691. acs.id = 'a-f';
  3692.  
  3693. const style = document.createElement('style');
  3694. style.textContent = `
  3695. @keyFrames aF1 {
  3696. 0% {
  3697. order: 0;
  3698. }
  3699. 100% {
  3700. order: 6;
  3701. }
  3702. }
  3703. #a-f[id] {
  3704. visibility: collapse !important;
  3705. position: fixed !important;
  3706. top: -100px !important;
  3707. left: -100px !important;
  3708. margin:0 !important;
  3709. padding:0 !important;
  3710. outline:0 !important;
  3711. border:0 !important;
  3712. z-index:-1 !important;
  3713. width: 0px !important;
  3714. height: 0px !important;
  3715. contain: strict !important;
  3716. pointer-events: none !important;
  3717. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  3718. }
  3719. `;
  3720. (document.head || document.documentElement).appendChild(style);
  3721.  
  3722. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  3723.  
  3724. const _onanimationiteration = function (evt) {
  3725. const hRes = evt.timeStamp;
  3726. var b = timeline;
  3727. b.currentTime = hRes;
  3728. b._discardAnimations();
  3729. if (0 == b._animations.length) {
  3730. restartWebAnimationsNextTickFlag = false;
  3731. acs.onanimationiteration = null;
  3732. } else {
  3733. acs.onanimationiteration = _onanimationiteration;
  3734. }
  3735.  
  3736. }
  3737.  
  3738.  
  3739.  
  3740. const restartWebAnimationsNextTick = () => {
  3741. if (!restartWebAnimationsNextTickFlag) {
  3742. restartWebAnimationsNextTickFlag = true;
  3743. acs.onanimationiteration = _onanimationiteration;
  3744.  
  3745. }
  3746. }
  3747.  
  3748. return { restartWebAnimationsNextTick }
  3749. };
  3750.  
  3751.  
  3752.  
  3753. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  3754.  
  3755.  
  3756. // console.log(571, timProto);
  3757. timProto._play = function (c) {
  3758. c = new Animation(c, this);
  3759. this._animations.push(c);
  3760. restartWebAnimationsNextTick();
  3761. c._updatePromises();
  3762. c._animation.play();
  3763. c._updatePromises();
  3764. return c
  3765. }
  3766.  
  3767. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  3768. originalAnimationsWithPromises.length = 0;
  3769. originalAnimationsWithPromises.push = null;
  3770. originalAnimationsWithPromises.splice = null;
  3771. originalAnimationsWithPromises.slice = null;
  3772. originalAnimationsWithPromises.indexOf = null;
  3773. originalAnimationsWithPromises.unshift = null;
  3774. originalAnimationsWithPromises.shift = null;
  3775. originalAnimationsWithPromises.pop = null;
  3776. originalAnimationsWithPromises.filter = null;
  3777. originalAnimationsWithPromises.forEach = null;
  3778. originalAnimationsWithPromises.map = null;
  3779.  
  3780.  
  3781. const _updateAnimationsPromises = () => {
  3782. animationsWithPromisesMap.forEach(c => {
  3783. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  3784. });
  3785. /*
  3786. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3787. return c._updatePromises();
  3788. });
  3789. */
  3790. }
  3791.  
  3792. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  3793.  
  3794. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  3795.  
  3796. delete timProto._updateAnimationsPromises;
  3797. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  3798. get() {
  3799. if (animationsWithPromisesMap.size === 0) return nilFn;
  3800. return _updateAnimationsPromises;
  3801. },
  3802. set(nv) {
  3803. delete this._updateAnimationsPromises;
  3804. this._updateAnimationsPromises = nv;
  3805. },
  3806. enumerable: true,
  3807. configurable: true,
  3808. });
  3809.  
  3810.  
  3811. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  3812. aniProto.__finished_native_get__ = pdFinished.get;
  3813. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  3814.  
  3815.  
  3816. Object.defineProperty(aniProto, 'finished', {
  3817. get() {
  3818. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3819. this._finishedPromise = new Promise((resolve, reject) => {
  3820. this._resolveFinishedPromise = function () {
  3821. resolve(this)
  3822. };
  3823. this._rejectFinishedPromise = function () {
  3824. reject({
  3825. type: DOMException.ABORT_ERR,
  3826. name: "AbortError"
  3827. })
  3828. };
  3829. }),
  3830. "finished" == this.playState && this._resolveFinishedPromise());
  3831. return this._finishedPromise
  3832. },
  3833. set: undefined,
  3834. enumerable: true,
  3835. configurable: true
  3836. });
  3837.  
  3838. }
  3839.  
  3840.  
  3841.  
  3842. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  3843. aniProto.__ready_native_get__ = pdReady.get;
  3844. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  3845.  
  3846. Object.defineProperty(aniProto, 'ready', {
  3847. get() {
  3848. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3849. this._readyPromise = new Promise((resolve, reject) => {
  3850. this._resolveReadyPromise = function () {
  3851. resolve(this)
  3852. };
  3853. this._rejectReadyPromise = function () {
  3854. reject({
  3855. type: DOMException.ABORT_ERR,
  3856. name: "AbortError"
  3857. })
  3858. };
  3859. }),
  3860. "pending" !== this.playState && this._resolveReadyPromise());
  3861. return this._readyPromise
  3862. },
  3863. set: undefined,
  3864. enumerable: true,
  3865. configurable: true
  3866. });
  3867.  
  3868. }
  3869.  
  3870.  
  3871. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  3872.  
  3873. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  3874. const _rebuildUnderlyingAnimation = function () {
  3875. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  3876. this.effect && this.effect._onsample && (this.effect._onsample = null);
  3877. return this._rebuildUnderlyingAnimation21();
  3878. }
  3879. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  3880. // delete aniProto._rebuildUnderlyingAnimation;
  3881. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  3882. // get() {
  3883. // if (isNaN(this._sequenceNumber)) return nilFn;
  3884. // return this._rebuildUnderlyingAnimation21;
  3885. // },
  3886. // set(nv) {
  3887. // delete this._rebuildUnderlyingAnimation;
  3888. // this._rebuildUnderlyingAnimation = nv;
  3889. // },
  3890. // enumerable: true,
  3891. // configurable: true
  3892. // });
  3893. }
  3894.  
  3895.  
  3896. /*
  3897.  
  3898.  
  3899. function f(c) {
  3900. var b = v.timeline;
  3901. b.currentTime = c;
  3902. b._discardAnimations();
  3903. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  3904. }
  3905. var h = window.requestAnimationFrame;
  3906. window.requestAnimationFrame = function(c) {
  3907. return h(function(b) {
  3908. v.timeline._updateAnimationsPromises();
  3909. c(b);
  3910. v.timeline._updateAnimationsPromises()
  3911. })
  3912. }
  3913. ;
  3914. v.AnimationTimeline = function() {
  3915. this._animations = [];
  3916. this.currentTime = void 0
  3917. }
  3918. ;
  3919. v.AnimationTimeline.prototype = {
  3920. getAnimations: function() {
  3921. this._discardAnimations();
  3922. return this._animations.slice()
  3923. },
  3924. _updateAnimationsPromises: function() {
  3925. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  3926. return c._updatePromises()
  3927. })
  3928. },
  3929. _discardAnimations: function() {
  3930. this._updateAnimationsPromises();
  3931. this._animations = this._animations.filter(function(c) {
  3932. return "finished" != c.playState && "idle" != c.playState
  3933. })
  3934. },
  3935. _play: function(c) {
  3936. c = new v.Animation(c,this);
  3937. this._animations.push(c);
  3938. v.restartWebAnimationsNextTick();
  3939. c._updatePromises();
  3940. c._animation.play();
  3941. c._updatePromises();
  3942. return c
  3943. },
  3944. play: function(c) {
  3945. c && c.remove();
  3946. return this._play(c)
  3947. }
  3948. };
  3949. var d = !1;
  3950. v.restartWebAnimationsNextTick = function() {
  3951. d || (d = !0,
  3952. requestAnimationFrame(f))
  3953. }
  3954. ;
  3955. var a = new v.AnimationTimeline;
  3956. v.timeline = a;
  3957. try {
  3958. Object.defineProperty(window.document, "timeline", {
  3959. configurable: !0,
  3960. get: function() {
  3961. return a
  3962. }
  3963. })
  3964. } catch (c) {}
  3965. try {
  3966. window.document.timeline = a
  3967. } catch (c) {}
  3968.  
  3969. */
  3970.  
  3971.  
  3972.  
  3973. /*
  3974.  
  3975. var g = window.getComputedStyle;
  3976. Object.defineProperty(window, "getComputedStyle", {
  3977. configurable: !0,
  3978. enumerable: !0,
  3979. value: function() {
  3980. v.timeline._updateAnimationsPromises();
  3981. var e = g.apply(this, arguments);
  3982. h() && (e = g.apply(this, arguments));
  3983. v.timeline._updateAnimationsPromises();
  3984. return e
  3985. }
  3986. });
  3987.  
  3988. */
  3989.  
  3990.  
  3991.  
  3992.  
  3993. }
  3994.  
  3995.  
  3996.  
  3997.  
  3998. })();
  3999.  
  4000.  
  4001.  
  4002.  
  4003. promiseForCustomYtElementsReady.then(() => {
  4004.  
  4005. FIX_ytdExpander_childrenChanged && customElements.whenDefined('ytd-expander').then(() => {
  4006.  
  4007.  
  4008.  
  4009. let dummy;
  4010. let cProto;
  4011.  
  4012.  
  4013.  
  4014. dummy = document.createElement('ytd-expander');
  4015. cProto = (dummy.inst || dummy).constructor.prototype;
  4016.  
  4017.  
  4018. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  4019.  
  4020.  
  4021. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  4022. cProto.childrenChanged14 = cProto.childrenChanged;
  4023.  
  4024. cProto.initChildrenObserver = function () {
  4025. var a = this;
  4026. this.observer = new MutationObserver(function () {
  4027. a.childrenChanged()
  4028. }
  4029. );
  4030. this.observer.observe(this.content, {
  4031. subtree: !0,
  4032. childList: !0,
  4033. attributes: !0,
  4034. characterData: !0
  4035. });
  4036. this.childrenChanged()
  4037. }
  4038. ;
  4039. cProto.childrenChanged = function () {
  4040. if (this.alwaysToggleable) {
  4041. this.canToggle = this.alwaysToggleable;
  4042. } else if (!this.canToggleJobId) {
  4043. this.canToggleJobId = 1;
  4044. getRafPromise().then(() => {
  4045. this.canToggleJobId = 0;
  4046. this.calculateCanCollapse()
  4047. })
  4048. }
  4049. }
  4050.  
  4051.  
  4052. // console.log(cProto.initChildrenObserver)
  4053. console.debug('ytd-expander-fix-childrenChanged');
  4054.  
  4055. }
  4056.  
  4057. })
  4058.  
  4059.  
  4060.  
  4061. FIX_paper_ripple_animate && customElements.whenDefined('paper-ripple').then(() => {
  4062.  
  4063.  
  4064.  
  4065. let dummy;
  4066. let cProto;
  4067. dummy = document.createElement('paper-ripple');
  4068. cProto = (dummy.inst || dummy).constructor.prototype;
  4069.  
  4070. if (fnIntegrity(cProto.animate, '0.74.5')) {
  4071.  
  4072.  
  4073. cProto.animate34 = cProto.animate;
  4074. cProto.animate = function () {
  4075. if (this._animating) {
  4076. var a;
  4077. const ripples = this.ripples;
  4078. for (a = 0; a < ripples.length; ++a) {
  4079. var b = ripples[a];
  4080. b.draw();
  4081. this.$.background.style.opacity = b.outerOpacity;
  4082. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  4083. }
  4084. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  4085. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  4086. getRafPromise().then(this._boundAnimate38);
  4087. } else {
  4088. this.onAnimationComplete()
  4089. }
  4090. }
  4091. }
  4092.  
  4093. console.debug('FIX_paper_ripple_animate')
  4094.  
  4095. // console.log(cProto.animate)
  4096.  
  4097. }
  4098.  
  4099. });
  4100.  
  4101. if (FIX_doIdomRender) {
  4102.  
  4103.  
  4104. const xsetTimeout = function (f, d) {
  4105. if (xsetTimeout.m511 === 1 && !d) {
  4106. xsetTimeout.m511 = 2;
  4107. getRafPromise().then(f);
  4108. } else {
  4109. return setTimeout.apply(window, arguments)
  4110. }
  4111.  
  4112. }
  4113.  
  4114. const xrequestAnimationFrame = function (f) {
  4115. const h = f + "";
  4116. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  4117. xsetTimeout.m511 = 1;
  4118. f();
  4119. xsetTimeout.m511 = 0;
  4120. } else if (h.includes("requestAninmationFrameResolver")) {
  4121. getRafPromise().then(f);
  4122. } else {
  4123. return requestAnimationFrame.apply(window, arguments);
  4124. }
  4125. }
  4126.  
  4127. let busy = false;
  4128. const doIdomRender = function () {
  4129. if (busy) {
  4130. return this.doIdomRender13.apply(this, arguments);
  4131. }
  4132. busy = true;
  4133. const { requestAnimationFrame, setTimeout } = window;
  4134. window.requestAnimationFrame = xrequestAnimationFrame;
  4135. window.setTimeout = xsetTimeout;
  4136. let r = this.doIdomRender13.apply(this, arguments);
  4137. window.requestAnimationFrame = requestAnimationFrame;
  4138. window.setTimeout = setTimeout;
  4139. busy = false;
  4140. return r;
  4141. };
  4142. 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']) {
  4143.  
  4144.  
  4145. customElements.whenDefined(ytTag).then(() => {
  4146.  
  4147. let dummy;
  4148. let cProto;
  4149. dummy = document.createElement(ytTag);
  4150. cProto = (dummy.inst || dummy).constructor.prototype;
  4151.  
  4152. cProto.doIdomRender13 = cProto.doIdomRender;
  4153. cProto.doIdomRender = doIdomRender;
  4154.  
  4155. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  4156.  
  4157. console.debug('FIX_doIdomRender', ytTag)
  4158.  
  4159.  
  4160.  
  4161. });
  4162.  
  4163. }
  4164.  
  4165. }
  4166.  
  4167.  
  4168.  
  4169. });
  4170.  
  4171. });
  4172.  
  4173.  
  4174. setupEvents();
  4175.  
  4176.  
  4177.  
  4178. if (isMainWindow) {
  4179.  
  4180. console.groupCollapsed(
  4181. "%cYouTube JS Engine Tamer",
  4182. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  4183. );
  4184.  
  4185.  
  4186.  
  4187. console.log("Script is loaded.");
  4188. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  4189.  
  4190. console.log("This script is experimental and subject to further changes.");
  4191.  
  4192. console.log("This might boost your YouTube performance.");
  4193.  
  4194. console.log("CAUTION: This might break your YouTube.");
  4195.  
  4196.  
  4197. if (prepareLogs.length >= 1) {
  4198. console.log(" =========================================================================== ");
  4199.  
  4200. for (const msg of prepareLogs) {
  4201. console.log(msg)
  4202. }
  4203.  
  4204. console.log(" =========================================================================== ");
  4205. }
  4206.  
  4207. console.groupEnd();
  4208.  
  4209. }
  4210.  
  4211.  
  4212.  
  4213.  
  4214.  
  4215.  
  4216. })();