YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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