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.26
  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. /*
  1180. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1181. if (typeof h.updateChangeRecord_ === 'function' && !(h.updateChangeRecord_.km34)) {
  1182.  
  1183. const f = h.updateChangeRecord_;
  1184. const g = ump3.get(f) || function () {
  1185. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1186. }
  1187. ump3.set(f, g);
  1188. g.km34 = 1;
  1189. h.updateChangeRecord_ = g;
  1190.  
  1191. }
  1192. */
  1193.  
  1194.  
  1195. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  1196.  
  1197. const f = h.requestRenderChunk_;
  1198. const g = ump3.get(f) || function () {
  1199. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1200. }
  1201. ump3.set(f, g);
  1202. g.km34 = 1;
  1203. h.requestRenderChunk_ = g;
  1204.  
  1205. }
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211. return;
  1212.  
  1213.  
  1214.  
  1215. /*
  1216. if (typeof h.cancelPendingTasks_ === 'function' && !(h.cancelPendingTasks_.km34)) {
  1217.  
  1218. const f = h.cancelPendingTasks_;
  1219. const g = ump3.get(f) || function () {
  1220. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1221. }
  1222. ump3.set(f, g);
  1223. g.km34 = 1;
  1224. h.cancelPendingTasks_ = g;
  1225.  
  1226. }
  1227.  
  1228.  
  1229. if (typeof h.fillRange_ === 'function' && !(h.fillRange_.km34)) {
  1230.  
  1231. const f = h.fillRange_;
  1232. const g = ump3.get(f) || function () {
  1233. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1234. }
  1235. ump3.set(f, g);
  1236. g.km34 = 1;
  1237. h.fillRange_ = g;
  1238.  
  1239. }
  1240. */
  1241.  
  1242.  
  1243.  
  1244.  
  1245. if (typeof h.addTextNodes_ === 'function' && !(h.addTextNodes_.km34)) {
  1246.  
  1247. const f = h.addTextNodes_;
  1248. const g = function () {
  1249. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1250. }
  1251. g.km34 = 1;
  1252. h.addTextNodes_ = g;
  1253.  
  1254. }
  1255.  
  1256.  
  1257.  
  1258.  
  1259. if (typeof h.updateText_ === 'function' && !(h.updateText_.km34)) {
  1260.  
  1261. const f = h.updateText_;
  1262. const g = function () {
  1263. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1264. }
  1265. g.km34 = 1;
  1266. h.updateText_ = g;
  1267.  
  1268. }
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274. if (typeof h.stampTypeChanged_ === 'function' && !(h.stampTypeChanged_.km34)) {
  1275.  
  1276. const f = h.stampTypeChanged_;
  1277. const g = function () {
  1278. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1279. }
  1280. g.km34 = 1;
  1281. h.stampTypeChanged_ = g;
  1282.  
  1283. }
  1284.  
  1285.  
  1286.  
  1287.  
  1288. // console.log(166)
  1289.  
  1290.  
  1291.  
  1292.  
  1293. }
  1294.  
  1295. const keyStConnectedCallback = Symbol(); // avoid copying the value
  1296.  
  1297. const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  1298. const cmf = new WeakMap();
  1299. const dmf = new WeakMap();
  1300.  
  1301. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  1302. get() {
  1303. const f = this[keyStConnectedCallback];
  1304. if (this.is) {
  1305. setupDiscreteTasks(this, true);
  1306. if (f) this.ky36 = 1;
  1307. }
  1308. return f;
  1309. },
  1310. set(nv) {
  1311. let gv;
  1312. if (typeof nv === 'function') {
  1313.  
  1314. gv = cmf.get(nv) || function () {
  1315. const cnt = this.inst || this;
  1316. const hostElement = cnt.hostElement || 0;
  1317. const dollar = hostElement ? (this.$ || (this.inst ? this.inst.$ : 0)) : 0;
  1318. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  1319. if (p && (!dollar && !this.is)) {
  1320. const nodeName = hostElement.nodeName;
  1321. if (typeof nodeName !== 'string') {
  1322. // just in case
  1323. } else if (nodeName.startsWith("DOM-")) {
  1324. // dom-if, dom-repeat, etc
  1325. } else {
  1326. // yt element - new model, yt-xxxx, anixxxxxx
  1327. p = false;
  1328. }
  1329. }
  1330. if (p) {
  1331. if (typeof cnt.markDirty === 'function') {
  1332. // the yt element might call markDirty (occasionally)
  1333. p = false;
  1334. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  1335. // see https://github.com/cyfung1031/userscript-supports/issues/20
  1336. p = false;
  1337. }
  1338. }
  1339. if (p) {
  1340.  
  1341. // << dom-repeat & dom-if >>
  1342.  
  1343. // sequence on the same instance
  1344. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  1345. } else {
  1346. nv.apply(this, arguments);
  1347. }
  1348. };
  1349. if (gv !== nv) {
  1350. cmf.set(nv, gv);
  1351. cmf.set(gv, gv);
  1352. dmf.set(gv, nv);
  1353. }
  1354.  
  1355. } else {
  1356. gv = nv;
  1357. }
  1358. this[keyStConnectedCallback] = gv; // proto or object
  1359. if (this.is) {
  1360. setupDiscreteTasks(this);
  1361. }
  1362. return true;
  1363. },
  1364. enumerable: false,
  1365. configurable: true
  1366.  
  1367. });
  1368.  
  1369. const pLoad = new Promise(resolve => {
  1370. if (document.readyState !== 'loading') {
  1371. resolve();
  1372. } else {
  1373. window.addEventListener("DOMContentLoaded", resolve, false);
  1374. }
  1375. });
  1376. pLoad.then(() => {
  1377.  
  1378. let nonce = document.querySelector('style[nonce]');
  1379. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1380. const st = document.createElement('style');
  1381. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1382. st.textContent = "none-element-k47{order:0}";
  1383. st.addEventListener('load', () => {
  1384. pf31.resolve();
  1385. p59 = 1;
  1386. }, false);
  1387. document.body.appendChild(st);
  1388.  
  1389.  
  1390. // console.debug('90002', location.pathname)
  1391. // console.log(90000, location.pathname)
  1392.  
  1393. });
  1394.  
  1395. const prepareLogs = [];
  1396.  
  1397. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  1398.  
  1399. let winError00 = window.onerror;
  1400.  
  1401. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  1402.  
  1403. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  1404.  
  1405. ; FIX_Iframe_NULL_SRC && (() => {
  1406.  
  1407. let emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  1408. const lcOpt = { sensitivity: 'base' };
  1409. document.createElement24 = document.createElement;
  1410. document.createElement = function (t) {
  1411. if (typeof t === 'string' && t.length === 6) {
  1412. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  1413. let p = this.createElement24(t);
  1414. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  1415. return p;
  1416. }
  1417. }
  1418. return this.createElement24.apply(this, arguments);
  1419. };
  1420.  
  1421. })();
  1422.  
  1423. ; fix_error_many_stack_state === 1 && (() => {
  1424.  
  1425.  
  1426. let p1 = winError00;
  1427.  
  1428. let stackNeedleDetails = null;
  1429.  
  1430. Object.defineProperty(Object.prototype, 'matchAll', {
  1431. get() {
  1432. stackNeedleDetails = this;
  1433. return true;
  1434. },
  1435. enumerable: true,
  1436. configurable: true
  1437. });
  1438.  
  1439. try {
  1440. JSON.parse("{}");
  1441. } catch (e) {
  1442. console.warn(e)
  1443. fix_error_many_stack_state = 0;
  1444. }
  1445.  
  1446. delete Object.prototype['matchAll'];
  1447.  
  1448. let p2 = window.onerror;
  1449.  
  1450. window.onerror = p1;
  1451.  
  1452. if (fix_error_many_stack_state === 0) return;
  1453.  
  1454. if (stackNeedleDetails) {
  1455. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1456. stackNeedleDetails.matchAll = true;
  1457. }
  1458.  
  1459. if (p1 === p2) return (fix_error_many_stack_state = 0);
  1460.  
  1461. // p1!==p2
  1462. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  1463.  
  1464. })();
  1465.  
  1466. ; fix_error_many_stack_state === 2 && (() => {
  1467.  
  1468.  
  1469. let p1 = winError00;
  1470.  
  1471. let objectPrune = null;
  1472. let stackNeedleDetails = null;
  1473.  
  1474. Object.defineProperty(Function.prototype, 'findOwner', {
  1475. get() {
  1476. objectPrune = this;
  1477. return this._findOwner;
  1478. },
  1479. set(nv) {
  1480. this._findOwner = nv;
  1481. return true;
  1482. },
  1483. enumerable: true,
  1484. configurable: true
  1485. });
  1486.  
  1487. Object.defineProperty(Object.prototype, 'matchAll', {
  1488. get() {
  1489. stackNeedleDetails = this;
  1490. return true;
  1491. },
  1492. enumerable: true,
  1493. configurable: true
  1494. });
  1495.  
  1496. try {
  1497. JSON.parse("{}");
  1498. } catch (e) {
  1499. console.warn(e)
  1500. fix_error_many_stack_state = 0;
  1501. }
  1502.  
  1503. delete Function.prototype['findOwner'];
  1504. delete Object.prototype['matchAll'];
  1505.  
  1506. let p2 = window.onerror;
  1507.  
  1508. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  1509.  
  1510. if (fix_error_many_stack_state == 0) return;
  1511.  
  1512. // the following will only execute when Brave's scriptlets.js is executed.
  1513.  
  1514. prepareLogs.push("fix_error_many_stack_state NB")
  1515.  
  1516. if (stackNeedleDetails) {
  1517. stackNeedleDetails.pattern = null;
  1518. stackNeedleDetails.re = null;
  1519. stackNeedleDetails.expect = null;
  1520. stackNeedleDetails.matchAll = true;
  1521. }
  1522.  
  1523. if (objectPrune) {
  1524. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  1525. delete objectPrune._findOwner;
  1526. }
  1527.  
  1528. fix_error_many_stack_state = 3;
  1529. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1530. JSON.parse.objectPrune = objectPrune;
  1531.  
  1532. })();
  1533.  
  1534. ; fix_error_many_stack_state === 3 && (() => {
  1535.  
  1536.  
  1537. let p1 = winError00;
  1538.  
  1539. try {
  1540. JSON.parse("{}");
  1541. } catch (e) {
  1542. console.warn(e)
  1543. fix_error_many_stack_state = 0;
  1544. }
  1545.  
  1546. let p2 = window.onerror;
  1547.  
  1548. if (p1 === p2) return;
  1549.  
  1550. window.onerror = p1;
  1551.  
  1552. if (fix_error_many_stack_state === 0) return;
  1553.  
  1554. fix_error_many_stack_state = 4; // p1 != p2
  1555.  
  1556.  
  1557. })();
  1558.  
  1559. fix_error_many_stack_state === 4 && (() => {
  1560.  
  1561. // the following will only execute when Brave's scriptlets.js is executed.
  1562.  
  1563. prepareLogs.push("fix_error_many_stack_state AB")
  1564.  
  1565. JSON.parseProxy = JSON.parse;
  1566.  
  1567. JSON.parse = ((parse) => {
  1568.  
  1569. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  1570. return function (text, reviver) {
  1571. const onerror = window.onerror;
  1572. window.onerror = null;
  1573. let r;
  1574. try {
  1575. r = parse(...arguments);
  1576. } catch (e) {
  1577. r = e;
  1578. }
  1579. window.onerror = onerror;
  1580. if (r instanceof Error) {
  1581. throw r;
  1582. }
  1583. return r;
  1584. }
  1585.  
  1586. })(JSON.parse);
  1587.  
  1588.  
  1589. })();
  1590.  
  1591.  
  1592.  
  1593. // ================================================ 0.4.5 ================================================
  1594.  
  1595.  
  1596. // ; (() => {
  1597.  
  1598. // if (FIX_error_many_stack && self instanceof Window) {
  1599. // // infinite stack due to matchesStackTrace inside objectPrune of AdsBlock
  1600.  
  1601. // const pdK = Object.getOwnPropertyDescriptor(window, 'onerror');
  1602. // if (!pdK || (pdK.get && pdK.configurable)) {
  1603.  
  1604. // } else {
  1605. // return;
  1606. // }
  1607.  
  1608. // let unsupportErrorFix = false;
  1609.  
  1610. // let firstHook = true;
  1611. // let busy33 = false;
  1612.  
  1613. // let state = 0;
  1614.  
  1615. // if (pdK) {
  1616. // delete window['onerror'];
  1617. // }
  1618.  
  1619. // const pd = {
  1620. // get() {
  1621. // const stack = (new Error()).stack;
  1622. // // targetStack = stack;
  1623. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  1624. // state = isGetExceptionToken ? 1 : 0;
  1625. // delete Window.prototype['onerror'];
  1626. // let r = pdK ? pdK.get.call(this) : this.onerror;
  1627. // Object.defineProperty(Window.prototype, 'onerror', pd);
  1628. // // console.log('onerror get', r)
  1629. // return r;
  1630. // },
  1631. // set(nv) {
  1632. // const stack = (new Error()).stack;
  1633. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  1634. // state = state === 1 && isGetExceptionToken ? 2 : 0;
  1635. // /** @type {string?} */
  1636. // let sToken = null;
  1637. // if (unsupportErrorFix || busy33) {
  1638.  
  1639. // } else if (typeof nv === 'function' && state === 2) {
  1640. // if (firstHook) {
  1641. // firstHook = false;
  1642. // console.groupCollapsed('Infinite onerror Bug Found');
  1643. // console.log(location.href);
  1644. // console.log(stack);
  1645. // console.log(nv);
  1646. // console.groupEnd();
  1647. // }
  1648. // let _token = null;
  1649. // busy33 = true;
  1650. // String.prototype.includes76 = String.prototype.includes;
  1651. // String.prototype.includes = function (token) {
  1652. // _token = token;
  1653. // return true;
  1654. // }
  1655. // nv('token');
  1656. // String.prototype.includes = String.prototype.includes76;
  1657. // sToken = _token;
  1658. // busy33 = false;
  1659. // if (typeof sToken !== 'string') {
  1660. // unsupportErrorFix = true;
  1661. // }
  1662. // }
  1663. // delete Window.prototype['onerror'];
  1664. // if (typeof sToken === 'string' && sToken.length > 1) {
  1665. // /** @type {string} */
  1666. // const token = sToken;
  1667. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>?} } */
  1668. // const currentOnerror = pdK ? pdK.get.call(this) : this.onerror;
  1669.  
  1670. // const now = Date.now();
  1671. // const tokenEntry = {
  1672. // token,
  1673. // expired: now + FIX_error_many_stack_keepAliveDuration
  1674. // }
  1675. // /** @typedef {typeof tokenEntry} TokenEntry */
  1676.  
  1677. // /** @type {Set<TokenEntry>} */
  1678. // const errorTokens = currentOnerror.errorTokens;
  1679.  
  1680. // if (errorTokens) {
  1681. // if (errorTokens.size > FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than) {
  1682. // for (const entry of errorTokens) {
  1683. // if (entry.expired < now) {
  1684. // errorTokens.delete(entry);
  1685. // }
  1686. // }
  1687. // }
  1688. // errorTokens.add(tokenEntry)
  1689. // } else {
  1690. // /** @type {Set<TokenEntry>} */
  1691. // const errorTokens = new Set([tokenEntry]);
  1692. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>} } */
  1693. // const newOnerror = ((oe) => {
  1694. // const r = function (msg, ...args) {
  1695. // if (typeof msg === 'string' && errorTokens.size > 0) {
  1696. // for (const entry of errorTokens) {
  1697. // if (msg.includes(entry.token)) return true;
  1698. // }
  1699. // }
  1700. // if (typeof oe === 'function') {
  1701. // return oe.apply(this, arguments);
  1702. // }
  1703. // };
  1704. // r.errorTokens = errorTokens;
  1705. // return r;
  1706. // })(currentOnerror);
  1707.  
  1708. // if (pdK && pdK.set) pdK.set.call(this, newOnerror);
  1709. // else this.onerror = newOnerror;
  1710. // }
  1711. // } else {
  1712. // if (pdK && pdK.set) pdK.set.call(this, nv);
  1713. // else this.onerror = nv;
  1714. // }
  1715. // Object.defineProperty(Window.prototype, 'onerror', pd);
  1716.  
  1717. // // console.log('onerror set', nv)
  1718. // return true;
  1719. // },
  1720. // enumerable: true,
  1721. // configurable: true
  1722. // }
  1723.  
  1724. // Object.defineProperty(Window.prototype, 'onerror', pd);
  1725.  
  1726.  
  1727. // }
  1728.  
  1729.  
  1730. // })();
  1731.  
  1732.  
  1733.  
  1734. // ================================================ 0.4.5 ================================================
  1735.  
  1736.  
  1737. // << if FIX_yt_player >>
  1738.  
  1739. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  1740. const PERF_471489_ = true;
  1741. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  1742. // This script uses a much gentle way to tamer the JS engine instead.
  1743.  
  1744. // << end >>
  1745.  
  1746. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  1747.  
  1748.  
  1749.  
  1750. const nilFn = () => { };
  1751.  
  1752. let isMainWindow = false;
  1753. try {
  1754. isMainWindow = window.document === window.top.document
  1755. } catch (e) { }
  1756.  
  1757. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  1758.  
  1759. const onRegistryReady = (callback) => {
  1760. if (typeof customElements === 'undefined') {
  1761. if (!('__CE_registry' in document)) {
  1762. // https://github.com/webcomponents/polyfills/
  1763. Object.defineProperty(document, '__CE_registry', {
  1764. get() {
  1765. // return undefined
  1766. },
  1767. set(nv) {
  1768. if (typeof nv == 'object') {
  1769. delete this.__CE_registry;
  1770. this.__CE_registry = nv;
  1771. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1772. }
  1773. return true;
  1774. },
  1775. enumerable: false,
  1776. configurable: true
  1777. })
  1778. }
  1779. let eventHandler = (evt) => {
  1780. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1781. const f = callback;
  1782. callback = null;
  1783. eventHandler = null;
  1784. f();
  1785. };
  1786. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1787. } else {
  1788. callback();
  1789. }
  1790. };
  1791.  
  1792.  
  1793. const assertor = (f) => f() || console.assert(false, f + "");
  1794.  
  1795. const fnIntegrity = (f, d) => {
  1796. if (!f || typeof f !== 'function') {
  1797. console.warn('f is not a function', f);
  1798. return;
  1799. }
  1800. let p = f + "", s = 0, j = -1, w = 0;
  1801. for (let i = 0, l = p.length; i < l; i++) {
  1802. const t = p[i];
  1803. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1804. if (j < i - 1) w++;
  1805. j = i;
  1806. } else {
  1807. s++;
  1808. }
  1809. }
  1810. let itz = `${f.length}.${s}.${w}`;
  1811. if (!d) {
  1812. return itz;
  1813. } else {
  1814. return itz === d;
  1815. }
  1816. };
  1817.  
  1818. const getZq = (_yt_player) => {
  1819.  
  1820. const w = 'Zq';
  1821.  
  1822. let arr = [];
  1823.  
  1824. for (const [k, v] of Object.entries(_yt_player)) {
  1825.  
  1826. const p = typeof v === 'function' ? v.prototype : 0;
  1827. if (p
  1828. && typeof p.start === 'function' && p.start.length === 0
  1829. && typeof p.isActive === 'function' && p.isActive.length === 0
  1830. && typeof p.stop === 'function' && p.stop.length === 0
  1831. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  1832. && !p.send && !p.abort
  1833. && !p.sample && !p.initialize && !p.fail && !p.getName
  1834. // && !p.dispose && !p.isDisposed
  1835.  
  1836. ) {
  1837. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1838.  
  1839.  
  1840. }
  1841.  
  1842. }
  1843.  
  1844. if (arr.length === 0) {
  1845.  
  1846. console.warn(`Key does not exist. [${w}]`);
  1847. } else {
  1848.  
  1849. console.log(`[${w}]`, arr);
  1850. return arr[0];
  1851. }
  1852.  
  1853.  
  1854.  
  1855.  
  1856. }
  1857.  
  1858.  
  1859. const getVG = (_yt_player) => {
  1860. const w = 'VG';
  1861.  
  1862. let arr = [];
  1863.  
  1864. for (const [k, v] of Object.entries(_yt_player)) {
  1865.  
  1866. const p = typeof v === 'function' ? v.prototype : 0;
  1867. if (p
  1868. && typeof p.show === 'function' && p.show.length === 1
  1869. && typeof p.hide === 'function' && p.hide.length === 0
  1870. && typeof p.stop === 'function' && p.stop.length === 0) {
  1871.  
  1872. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1873.  
  1874. }
  1875.  
  1876. }
  1877.  
  1878.  
  1879. if (arr.length === 0) {
  1880.  
  1881. console.warn(`Key does not exist. [${w}]`);
  1882. } else {
  1883.  
  1884. console.log(`[${w}]`, arr);
  1885. return arr[0];
  1886. }
  1887.  
  1888.  
  1889.  
  1890. }
  1891.  
  1892.  
  1893. const getzo = (_yt_player) => {
  1894. const w = 'zo';
  1895.  
  1896. let arr = [];
  1897.  
  1898. for (const [k, v] of Object.entries(_yt_player)) {
  1899.  
  1900. if (
  1901. typeof v === 'function' && v.length === 3 && k.length < 3
  1902. && (v + "").includes("a.style[b]=c")
  1903. ) {
  1904.  
  1905. arr.push(k);
  1906.  
  1907. }
  1908.  
  1909. }
  1910.  
  1911.  
  1912. if (arr.length === 0) {
  1913.  
  1914. console.warn(`Key does not exist. [${w}]`);
  1915. } else {
  1916.  
  1917. console.log(`[${w}]`, arr);
  1918. return arr[0];
  1919. }
  1920.  
  1921. }
  1922.  
  1923. const addProtoToArr = (parent, key, arr) => {
  1924.  
  1925.  
  1926. let isChildProto = false;
  1927. for (const sr of arr) {
  1928. if (parent[key].prototype instanceof parent[sr]) {
  1929. isChildProto = true;
  1930. break;
  1931. }
  1932. }
  1933.  
  1934. if (isChildProto) return;
  1935.  
  1936. arr = arr.filter(sr => {
  1937. if (parent[sr].prototype instanceof parent[key]) {
  1938. return false;
  1939. }
  1940. return true;
  1941. });
  1942.  
  1943. arr.push(key);
  1944.  
  1945. return arr;
  1946.  
  1947.  
  1948. }
  1949.  
  1950. const getuG = (_yt_player) => {
  1951.  
  1952. const w = 'uG';
  1953.  
  1954. let arr = [];
  1955.  
  1956. for (const [k, v] of Object.entries(_yt_player)) {
  1957.  
  1958.  
  1959. const p = typeof v === 'function' ? v.prototype : 0;
  1960.  
  1961. if (p
  1962. && typeof p.createElement === 'function' && p.createElement.length === 2
  1963. && typeof p.detach === 'function' && p.detach.length === 0
  1964. && typeof p.update === 'function' && p.update.length === 1
  1965. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  1966. ) {
  1967.  
  1968. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1969.  
  1970. }
  1971.  
  1972. }
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978. if (arr.length === 0) {
  1979.  
  1980. console.warn(`Key does not exist. [${w}]`);
  1981. } else {
  1982.  
  1983. console.log(`[${w}]`, arr);
  1984. return arr[0];
  1985. }
  1986.  
  1987. }
  1988.  
  1989.  
  1990.  
  1991. // << if FIX_schedulerInstanceInstance_ >>
  1992.  
  1993. let idleFrom = Date.now() + 2700;
  1994. let slowMode = false;
  1995.  
  1996. let ytEvented = false;
  1997.  
  1998.  
  1999. const setupEvents = FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 ? () => {
  2000.  
  2001. document.addEventListener('yt-navigate', () => {
  2002.  
  2003. ytEvented = true;
  2004. slowMode = false;
  2005. idleFrom = Date.now() + 2700;
  2006.  
  2007. });
  2008. document.addEventListener('yt-navigate-start', () => {
  2009.  
  2010. ytEvented = true;
  2011. slowMode = false;
  2012. idleFrom = Date.now() + 2700;
  2013.  
  2014. });
  2015.  
  2016. document.addEventListener('yt-page-type-changed', () => {
  2017.  
  2018. ytEvented = true;
  2019. slowMode = false;
  2020. idleFrom = Date.now() + 1700;
  2021.  
  2022. });
  2023.  
  2024.  
  2025. document.addEventListener('yt-player-updated', () => {
  2026.  
  2027. ytEvented = true;
  2028. slowMode = false;
  2029. idleFrom = Date.now() + 1700;
  2030.  
  2031. });
  2032.  
  2033.  
  2034. document.addEventListener('yt-page-data-fetched', () => {
  2035.  
  2036. ytEvented = true;
  2037. slowMode = false;
  2038. idleFrom = Date.now() + 1700;
  2039.  
  2040. });
  2041.  
  2042. document.addEventListener('yt-navigate-finish', () => {
  2043.  
  2044. ytEvented = true;
  2045. slowMode = false;
  2046. let t = Date.now() + 700;
  2047. if (t > idleFrom) idleFrom = t;
  2048.  
  2049. });
  2050.  
  2051. document.addEventListener('yt-page-data-updated', () => {
  2052.  
  2053. ytEvented = true;
  2054. slowMode = false;
  2055. let t = Date.now() + 700;
  2056. if (t > idleFrom) idleFrom = t;
  2057.  
  2058. });
  2059.  
  2060. document.addEventListener('yt-watch-comments-ready', () => {
  2061.  
  2062. ytEvented = true;
  2063. slowMode = false;
  2064. let t = Date.now() + 700;
  2065. if (t > idleFrom) idleFrom = t;
  2066.  
  2067. });
  2068. } : () => { };
  2069.  
  2070.  
  2071. // << end >>
  2072.  
  2073. const cleanContext = async (win) => {
  2074. const waitFn = requestAnimationFrame; // shall have been binded to window
  2075. try {
  2076. let mx = 16; // MAX TRIAL
  2077. const frameId = 'vanillajs-iframe-v1';
  2078. /** @type {HTMLIFrameElement | null} */
  2079. let frame = document.getElementById(frameId);
  2080. let removeIframeFn = null;
  2081. if (!frame) {
  2082. frame = document.createElement('iframe');
  2083. frame.id = frameId;
  2084. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  2085. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  2086. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  2087. n.appendChild(frame);
  2088. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  2089. const root = document.documentElement;
  2090. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  2091. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  2092.  
  2093. removeIframeFn = (setTimeout) => {
  2094. const removeIframeOnDocumentReady = (e) => {
  2095. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2096. e = n;
  2097. n = win = removeIframeFn = 0;
  2098. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  2099. }
  2100. if (!setTimeout || document.readyState !== 'loading') {
  2101. removeIframeOnDocumentReady();
  2102. } else {
  2103. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  2104. }
  2105. }
  2106. }
  2107. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  2108. const fc = frame.contentWindow;
  2109. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  2110. try {
  2111. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  2112. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  2113. for (let k in res) res[k] = res[k].bind(win); // necessary
  2114. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  2115. res.animate = fc.HTMLElement.prototype.animate;
  2116. res.perfNow = fc.performance.now;
  2117. return res;
  2118. } catch (e) {
  2119. if (removeIframeFn) removeIframeFn();
  2120. return null;
  2121. }
  2122. } catch (e) {
  2123. console.warn(e);
  2124. return null;
  2125. }
  2126. };
  2127.  
  2128.  
  2129. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  2130.  
  2131. cleanContext(window).then(__CONTEXT__ => {
  2132. if (!__CONTEXT__) return null;
  2133.  
  2134. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  2135.  
  2136.  
  2137. performance.now17 = perfNow.bind(performance);
  2138. // performance.now = performance.now16;
  2139. /*
  2140. let nowh = -1;
  2141. performance.now = function () {
  2142. let t = nowh;
  2143. let c = this.now17();
  2144. return (nowh = (t + 1e-7 > c ? t + 0.1 : c));
  2145. }
  2146. */
  2147.  
  2148. // console.log(performance.now())
  2149. // console.log(performance.now())
  2150. // console.log(performance.now())
  2151. // console.log(performance.now())
  2152.  
  2153.  
  2154.  
  2155. __requestAnimationFrame__ = requestAnimationFrame;
  2156.  
  2157. let rafPromise = null;
  2158.  
  2159. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  2160. requestAnimationFrame(hRes => {
  2161. rafPromise = null;
  2162. resolve(hRes);
  2163. });
  2164. }));
  2165.  
  2166. const getForegroundPromise = () => {
  2167. if (document.visibilityState === 'visible') {
  2168. return Promise.resolve();
  2169. } else {
  2170. return getRafPromise();
  2171. }
  2172. };
  2173.  
  2174. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  2175. setTimeout(() => {
  2176. NO_PRELOAD_GENERATE_204_BYPASS = true;
  2177. }, 1270);
  2178. });
  2179.  
  2180. const promiseForTamerTimeout = new Promise(resolve => {
  2181. promiseForCustomYtElementsReady.then(() => {
  2182. customElements.whenDefined('ytd-app').then(() => {
  2183. setTimeout(resolve, 1200);
  2184. });
  2185. });
  2186. setTimeout(resolve, 3000);
  2187. });
  2188.  
  2189.  
  2190. class RAFHub {
  2191. constructor() {
  2192. /** @type {number} */
  2193. this.startAt = 8170;
  2194. /** @type {number} */
  2195. this.counter = 0;
  2196. /** @type {number} */
  2197. this.rid = 0;
  2198. /** @type {Map<number, FrameRequestCallback>} */
  2199. this.funcs = new Map();
  2200. const funcs = this.funcs;
  2201. /** @type {FrameRequestCallback} */
  2202. this.bCallback = this.mCallback.bind(this);
  2203. this.pClear = () => funcs.clear();
  2204. }
  2205. /** @param {DOMHighResTimeStamp} highResTime */
  2206. mCallback(highResTime) {
  2207. this.rid = 0;
  2208. Promise.resolve().then(this.pClear);
  2209. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2210. }
  2211. /** @param {FrameRequestCallback} f */
  2212. request(f) {
  2213. if (this.counter > 1e9) this.counter = 9;
  2214. let cid = this.startAt + (++this.counter);
  2215. this.funcs.set(cid, f);
  2216. if (this.rid === 0) {
  2217. console.log(2455)
  2218. this.rid = requestAnimationFrame(this.bCallback);
  2219. }
  2220. return cid;
  2221. }
  2222. /** @param {number} cid */
  2223. cancel(cid) {
  2224. cid = +cid;
  2225. if (cid > 0) {
  2226. if (cid <= this.startAt) {
  2227. return cancelAnimationFrame(cid);
  2228. }
  2229. if (this.rid > 0) {
  2230. this.funcs.delete(cid);
  2231. if (this.funcs.size === 0) {
  2232. cancelAnimationFrame(this.rid);
  2233. this.rid = 0;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. /** @param {number} cid */
  2239. /** @param {FrameRequestCallback} f */
  2240. replaceFunc(cid, f) {
  2241. if (typeof this.funcs.get(cid) === 'function') {
  2242. this.funcs.set(cid, f);
  2243. return cid;
  2244. } else {
  2245. let r = this.request(f);
  2246. this.cancel(cid);
  2247. return r;
  2248. }
  2249. }
  2250. }
  2251.  
  2252.  
  2253.  
  2254. NATIVE_CANVAS_ANIMATION && (() => {
  2255.  
  2256. HTMLCanvasElement.prototype.animate = animate;
  2257.  
  2258. let cid = setInterval(() => {
  2259. HTMLCanvasElement.prototype.animate = animate;
  2260. }, 1);
  2261.  
  2262. promiseForTamerTimeout.then(() => {
  2263. clearInterval(cid)
  2264. });
  2265.  
  2266. })();
  2267.  
  2268. FIX_ytAction_ && (async () => {
  2269.  
  2270. const ytdApp = await new Promise(resolve => {
  2271.  
  2272. promiseForCustomYtElementsReady.then(() => {
  2273. customElements.whenDefined('ytd-app').then(() => {
  2274. const ytdApp = document.querySelector('ytd-app');
  2275. if (ytdApp) {
  2276. resolve(ytdApp);
  2277. return;
  2278. }
  2279. let mo = new MutationObserver(() => {
  2280. const ytdApp = document.querySelector('ytd-app');
  2281. if (!ytdApp) return;
  2282. if (mo) {
  2283. mo.disconnect();
  2284. mo.takeRecords();
  2285. mo = null;
  2286. }
  2287. resolve(ytdApp);
  2288. });
  2289. mo.observe(document, { subtree: true, childList: true });
  2290. });
  2291. });
  2292.  
  2293.  
  2294.  
  2295. });
  2296.  
  2297.  
  2298.  
  2299. if (!ytdApp) return;
  2300. const cProto = (ytdApp.inst || ytdApp).constructor.prototype;
  2301.  
  2302.  
  2303. if (!cProto) return;
  2304. let mbd = 0;
  2305.  
  2306. const fixer = (_ytdApp) => {
  2307.  
  2308. const ytdApp = _ytdApp ? (_ytdApp.inst || _ytdApp) : null;
  2309.  
  2310. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  2311. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  2312. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  2313. mbd++;
  2314. }
  2315.  
  2316.  
  2317. }
  2318.  
  2319. let cid = setInterval(() => {
  2320.  
  2321.  
  2322. if (typeof cProto.created === 'function' && !cProto.created56) {
  2323. cProto.created56 = cProto.created;
  2324. cProto.created = function (...args) {
  2325. const r = this.created56(...args);
  2326. fixer(this);
  2327. return r;
  2328. };
  2329. mbd++;
  2330. }
  2331.  
  2332.  
  2333. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  2334. cProto.onYtAction57_ = cProto.onYtAction_;
  2335. cProto.onYtAction_ = function (...args) {
  2336. Promise.resolve().then(() => this.onYtAction57_(...args));
  2337. };
  2338. mbd++;
  2339. }
  2340.  
  2341. if (ytdApp) fixer(ytdApp);
  2342.  
  2343. /*
  2344. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  2345. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  2346. actionRouter_.handleAction57 = actionRouter_.handleAction;
  2347. actionRouter_.handleAction = function (...args) {
  2348. Promise.resolve().then(() => this.handleAction57(...args));
  2349. }
  2350. mbd++;
  2351. }
  2352. */
  2353.  
  2354. // if(mbd === 3) clearInterval(cid);
  2355. if (mbd >= 3) clearInterval(cid);
  2356.  
  2357. }, 1);
  2358.  
  2359. setTimeout(() => {
  2360.  
  2361. clearInterval(cid);
  2362. }, 1000);
  2363.  
  2364. })();
  2365.  
  2366.  
  2367. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  2368.  
  2369. const evKey = `${_evKey}`;
  2370. const fvKey = `${_fvKey}`;
  2371. const debug = !!_debug;
  2372.  
  2373.  
  2374. // const rafHub = new RAFHub();
  2375.  
  2376.  
  2377. const _yt_player = await new Promise(resolve => {
  2378.  
  2379. let cid = setInterval(() => {
  2380. let t = (((window || 0)._yt_player || 0) || 0);
  2381. if (t) {
  2382.  
  2383. clearInterval(cid);
  2384. resolve(t);
  2385. }
  2386. }, 1);
  2387.  
  2388. promiseForTamerTimeout.then(() => {
  2389. resolve(null)
  2390. });
  2391.  
  2392. });
  2393.  
  2394.  
  2395. if (!_yt_player || typeof _yt_player !== 'object') return;
  2396.  
  2397.  
  2398. const getArr = (_yt_player) => {
  2399.  
  2400. let arr = [];
  2401.  
  2402. for (const [k, v] of Object.entries(_yt_player)) {
  2403.  
  2404. const p = typeof v === 'function' ? v.prototype : 0;
  2405. if (p
  2406. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  2407.  
  2408. ) {
  2409. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2410.  
  2411. }
  2412.  
  2413. }
  2414.  
  2415. if (arr.length === 0) {
  2416.  
  2417. console.warn(`Key prop [${evKey}] does not exist.`);
  2418. } else {
  2419.  
  2420. return arr;
  2421. }
  2422.  
  2423. };
  2424.  
  2425. const arr = getArr(_yt_player);
  2426.  
  2427.  
  2428. if (!arr) return;
  2429.  
  2430. debug && console.log(`FIX_${evKey}`, arr);
  2431.  
  2432. const f = function (...args) {
  2433. Promise.resolve().then(() => this[fvKey](...args));
  2434. };
  2435.  
  2436.  
  2437. for (const k of arr) {
  2438.  
  2439. const g = _yt_player;
  2440. const gk = g[k];
  2441. const gkp = gk.prototype;
  2442.  
  2443. debug && console.log(237, k, gkp)
  2444.  
  2445. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  2446. gkp[fvKey] = gkp[evKey];
  2447. gkp[evKey] = f;
  2448. }
  2449. }
  2450.  
  2451.  
  2452.  
  2453.  
  2454. }
  2455.  
  2456. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  2457. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  2458. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  2459. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  2460. if (FIX_VideoEVENTS_v2) {
  2461. const FIX_VideoEVENTS_DEBUG = 0;
  2462. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  2463. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  2464. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  2465. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  2466. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  2467. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  2468. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  2469. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  2470. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  2471.  
  2472. }
  2473. // onMutedAutoplayChange
  2474. // onVolumeChange
  2475. // onPlaybackRateChange
  2476.  
  2477. // onAirPlayActiveChange
  2478. // onAirPlayAvailabilityChange
  2479. // onApiChange
  2480. // onAutoplayBlocked
  2481. // onDrmOutputRestricted
  2482. // onFullscreenChange
  2483. // onLoadProgress
  2484. // onLoadedMetadata
  2485. // onVideoDataChange
  2486. // onVideoProgress
  2487.  
  2488. FIX_maybeUpdateFlexibleMenu && (async () => {
  2489.  
  2490.  
  2491. const dummy = await new Promise(resolve => {
  2492.  
  2493. promiseForCustomYtElementsReady.then(() => {
  2494. customElements.whenDefined('ytd-menu-renderer').then(() => {
  2495.  
  2496. resolve(document.createElement('ytd-menu-renderer'));
  2497. });
  2498. });
  2499.  
  2500.  
  2501.  
  2502. });
  2503.  
  2504.  
  2505. if (!dummy || dummy.is !== 'ytd-menu-renderer') return;
  2506.  
  2507. const cProto = (dummy.inst || dummy).constructor.prototype;
  2508.  
  2509. if (typeof cProto.created === 'function' && !cProto.created58) {
  2510. cProto.created58 = cProto.created;
  2511. cProto.created = function (...args) {
  2512. const r = this.created58(...args);
  2513. if (typeof this.maybeUpdateFlexibleMenu === 'function' && !this.maybeUpdateFlexibleMenu57) {
  2514. this.maybeUpdateFlexibleMenu57 = this.maybeUpdateFlexibleMenu;
  2515. this.maybeUpdateFlexibleMenu = function (...args) {
  2516. Promise.resolve().then(() => this.maybeUpdateFlexibleMenu57(...args));
  2517. }
  2518. }
  2519. return r;
  2520. }
  2521.  
  2522. }
  2523.  
  2524. //console.log(144,cProto.maybeUpdateFlexibleMenu)
  2525.  
  2526.  
  2527.  
  2528.  
  2529.  
  2530.  
  2531. })();
  2532.  
  2533. ENABLE_discreteTasking && (async () => {
  2534.  
  2535. const Polymer = await new Promise(resolve => {
  2536.  
  2537. let cid = 0;
  2538. const f = () => {
  2539. const Polymer = window.Polymer;
  2540. if (typeof Polymer !== 'function') return;
  2541. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  2542. cid && clearInterval(cid);
  2543. cid = 0;
  2544. resolve(Polymer);
  2545. };
  2546. cid = setInterval(f, 1);
  2547.  
  2548. });
  2549. if (!Polymer) return;
  2550.  
  2551. Polymer.Base.__connInit__ = function () {
  2552. setupDiscreteTasks(this);
  2553. }
  2554.  
  2555.  
  2556. /** @type {Function} */
  2557. const connectedCallbackK = function (...args) {
  2558. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2559. const r = this[qm53](...args);
  2560. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2561. this.mh35 = 1;
  2562. return r;
  2563. };
  2564.  
  2565. connectedCallbackK.m353 = 1;
  2566.  
  2567.  
  2568. const qt53 = Polymer.Base.connectedCallback;
  2569. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  2570.  
  2571. Polymer.Base.connectedCallback = connectedCallbackK;
  2572.  
  2573.  
  2574. /** @type {Function} */
  2575. const createdK = function (...args) {
  2576. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2577. const r = this[qn53](...args);
  2578. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2579. this.mh36 = 1;
  2580. return r;
  2581. };
  2582.  
  2583.  
  2584. createdK.m353 = 1;
  2585. Polymer.Base[qn53] = Polymer.Base.created;
  2586. Polymer.Base.created = createdK;
  2587.  
  2588. })();
  2589.  
  2590. CHANGE_appendChild && (() => {
  2591.  
  2592. const f = HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  2593. if (f) HTMLElement.prototype.appendChild = function (a) {
  2594.  
  2595.  
  2596. if (this instanceof HTMLElement) {
  2597.  
  2598. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  2599. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  2600. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  2601. node.__m848__ = 1;
  2602. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  2603. }
  2604. }
  2605. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  2606. return this.appendChild73.apply(this, arguments);
  2607. }
  2608.  
  2609. if (a instanceof DocumentFragment) {
  2610. if (a.firstElementChild === null) {
  2611. let child = a.firstChild;
  2612. if (child === null) return a;
  2613. let doNormal = false;
  2614. while (child instanceof Node) {
  2615. if (child.nodeType === 3) { doNormal = true; break; }
  2616. child = child.nextSibling;
  2617. }
  2618. if (!doNormal) return a;
  2619. }
  2620. }
  2621.  
  2622. return (this.appendChild73 || f).apply(this, arguments);
  2623. }
  2624.  
  2625.  
  2626. return (HTMLElement.prototype.appendChild73 || f).apply(this, arguments);
  2627. }
  2628.  
  2629.  
  2630. })();
  2631.  
  2632. if (FIX_Shady) {
  2633.  
  2634. let cidSL = setInterval(() => {
  2635. const { ShadyDOM, ShadyCSS } = window;
  2636. if (ShadyDOM && ShadyCSS) {
  2637. clearInterval(cidSL);
  2638. cidSL = 0;
  2639. }
  2640. if (ShadyDOM) {
  2641. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  2642. ShadyDOM.noPatch = true; // 1 of 10
  2643. ShadyDOM.patchOnDemand = false; // 1 of 10
  2644. ShadyDOM.preferPerformance = true; // 1 of 10
  2645. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  2646. }
  2647. if (ShadyCSS) {
  2648. ShadyCSS.nativeCss = true; // 1 of 10
  2649. ShadyCSS.nativeShadow = true; // 6 of 10
  2650. ShadyCSS.cssBuild = undefined; // 1 of 10
  2651. ShadyCSS.disableRuntime = true; // 1 of 10
  2652. }
  2653. }, 1);
  2654.  
  2655. }
  2656.  
  2657.  
  2658. FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 && (async () => {
  2659.  
  2660.  
  2661. const schedulerInstanceInstance_ = await new Promise(resolve => {
  2662.  
  2663. let cid = setInterval(() => {
  2664. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2665. if (t) {
  2666.  
  2667. clearInterval(cid);
  2668. resolve(t);
  2669. }
  2670. }, 1);
  2671. promiseForTamerTimeout.then(() => {
  2672. resolve(null)
  2673. });
  2674. });
  2675.  
  2676. if (!schedulerInstanceInstance_) return;
  2677.  
  2678.  
  2679. if (!ytEvented) {
  2680. idleFrom = Date.now() + 2700;
  2681. slowMode = false; // integrity
  2682. }
  2683.  
  2684. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2685. if (checkOK) {
  2686.  
  2687.  
  2688. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  2689.  
  2690. let requestingFn = null;
  2691. let requestingArgs = null;
  2692. let requestingDT = 0;
  2693.  
  2694. // let timerId = null;
  2695. const entries = [];
  2696. const f = function () {
  2697. requestingFn = this.fn;
  2698. requestingArgs = [...arguments];
  2699. requestingDT = Date.now();
  2700. entries.push({
  2701. fn: requestingFn,
  2702. args: requestingArgs,
  2703. t: requestingDT
  2704. });
  2705. // if (Date.now() < idleFrom) {
  2706. // timerId = this.fn.apply(window, arguments);
  2707. // } else {
  2708. // timerId = this.fn.apply(window, arguments);
  2709.  
  2710. // }
  2711. // timerId = 12377;
  2712. return 12377;
  2713. }
  2714.  
  2715.  
  2716. const fakeFns = [
  2717. f.bind({ fn: requestAnimationFrame }),
  2718. f.bind({ fn: setInterval }),
  2719. f.bind({ fn: setTimeout }),
  2720. f.bind({ fn: requestIdleCallback })
  2721. ]
  2722.  
  2723.  
  2724.  
  2725.  
  2726. let timerResolve = null;
  2727. setInterval(() => {
  2728. timerResolve && timerResolve();
  2729. timerResolve = null;
  2730. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  2731. }, 250);
  2732.  
  2733. let mzt = 0;
  2734.  
  2735. let fnSelectorProp = null;
  2736.  
  2737. schedulerInstanceInstance_.start = function () {
  2738.  
  2739. const mk1 = window.requestAnimationFrame
  2740. const mk2 = window.setInterval
  2741. const mk3 = window.setTimeout
  2742. const mk4 = window.requestIdleCallback
  2743.  
  2744. const tThis = this['$$12378$$'] || this;
  2745.  
  2746.  
  2747. window.requestAnimationFrame = fakeFns[0]
  2748. window.setInterval = fakeFns[1]
  2749. window.setTimeout = fakeFns[2]
  2750. window.requestIdleCallback = fakeFns[3]
  2751.  
  2752. fnSelectorProp = null;
  2753.  
  2754.  
  2755. tThis.start991.call(new Proxy(tThis, {
  2756. get(target, prop, receiver) {
  2757. if (prop === '$$12377$$') return true;
  2758. if (prop === '$$12378$$') return target;
  2759.  
  2760. // console.log('get',prop)
  2761. return target[prop]
  2762. },
  2763. set(target, prop, value, receiver) {
  2764. // console.log('set', prop, value)
  2765.  
  2766.  
  2767. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  2768. if (value === 12377 && fnSelectorProp) {
  2769.  
  2770. const originalSelection = target[fnSelectorProp];
  2771. const timerIdProp = prop;
  2772.  
  2773. /*
  2774.  
  2775.  
  2776. case 1:
  2777. var a = this.K;
  2778. this.g = this.I ? window.requestIdleCallback(a, {
  2779. timeout: 3E3
  2780. }) : window.setTimeout(a, ma);
  2781. break;
  2782. case 2:
  2783. this.g = window.setTimeout(this.M, this.N);
  2784. break;
  2785. case 3:
  2786. this.g = window.requestAnimationFrame(this.L);
  2787. break;
  2788. case 4:
  2789. this.g = window.setTimeout(this.J, 0)
  2790. }
  2791.  
  2792. */
  2793.  
  2794. const doForegroundSlowMode = () => {
  2795.  
  2796. const tir = ++mzt;
  2797. const f = requestingArgs[0];
  2798.  
  2799.  
  2800. getForegroundPromise().then(() => {
  2801.  
  2802.  
  2803. new Promise(r => {
  2804. timerResolve = r
  2805. }).then(() => {
  2806. if (target[timerIdProp] === -tir) f();
  2807. });
  2808.  
  2809. })
  2810.  
  2811. target[fnSelectorProp] = 931;
  2812. target[prop] = -tir;
  2813. }
  2814.  
  2815. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  2816. if (slowMode && !(requestingArgs[1] > 250)) {
  2817.  
  2818. doForegroundSlowMode();
  2819.  
  2820. } else {
  2821. target[prop] = setTimeout.apply(window, requestingArgs);
  2822.  
  2823. }
  2824.  
  2825. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  2826.  
  2827. if (slowMode) {
  2828.  
  2829. doForegroundSlowMode();
  2830.  
  2831. } else {
  2832. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  2833. }
  2834.  
  2835.  
  2836. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  2837.  
  2838. const f = requestingArgs[0];
  2839. const tir = ++mzt;
  2840. Promise.resolve().then(() => {
  2841. if (target[timerIdProp] === -tir) f();
  2842. });
  2843. target[fnSelectorProp] = 930;
  2844. target[prop] = -tir;
  2845.  
  2846. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  2847.  
  2848. doForegroundSlowMode();
  2849.  
  2850. } else {
  2851. // target[prop] = timerId;
  2852. target[fnSelectorProp] = 0;
  2853. target[prop] = 0;
  2854. }
  2855.  
  2856. // *****
  2857. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  2858. } else {
  2859.  
  2860. target[prop] = value;
  2861. }
  2862. // console.log('set',prop,value)
  2863. return true;
  2864. }
  2865. }));
  2866.  
  2867. fnSelectorProp = null;
  2868.  
  2869.  
  2870. window.requestAnimationFrame = mk1;
  2871. window.setInterval = mk2
  2872. window.setTimeout = mk3
  2873. window.requestIdleCallback = mk4;
  2874.  
  2875.  
  2876.  
  2877. }
  2878.  
  2879. schedulerInstanceInstance_.start.toString = function () {
  2880. return schedulerInstanceInstance_.start991.toString();
  2881. }
  2882.  
  2883. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  2884. // prop,
  2885. // value: schedulerInstanceInstance_[prop],
  2886. // type: typeof schedulerInstanceInstance_[prop]
  2887.  
  2888. // }));
  2889. // console.log('fcc', funcNames)
  2890.  
  2891.  
  2892.  
  2893.  
  2894. }
  2895. })();
  2896.  
  2897.  
  2898.  
  2899. FIX_schedulerInstanceInstance_V2 && !FIX_schedulerInstanceInstance_V1 && (async () => {
  2900.  
  2901.  
  2902. const schedulerInstanceInstance_ = await new Promise(resolve => {
  2903.  
  2904. let cid = setInterval(() => {
  2905. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2906. if (t) {
  2907.  
  2908. clearInterval(cid);
  2909. resolve(t);
  2910. }
  2911. }, 1);
  2912. promiseForTamerTimeout.then(() => {
  2913. resolve(null)
  2914. });
  2915. });
  2916.  
  2917. if (!schedulerInstanceInstance_) return;
  2918.  
  2919.  
  2920. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2921. if (checkOK) {
  2922.  
  2923. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  2924.  
  2925.  
  2926.  
  2927. let busy = false;
  2928.  
  2929. // console.log('1667',schedulerInstanceInstance_.start);
  2930. schedulerInstanceInstance_.start = function () {
  2931.  
  2932. // p59 || console.log(location.pathname, 16400);
  2933.  
  2934. if (busy) {
  2935.  
  2936. return this.start991.call(this);
  2937.  
  2938. }
  2939.  
  2940. busy = true;
  2941.  
  2942. const mk1 = window.requestAnimationFrame
  2943. // const mk2 = window.setInterval
  2944. // const mk3 = window.setTimeout
  2945. // const mk4 = window.requestIdleCallback
  2946.  
  2947. // by pass Youtube Engine's wrapping
  2948. window.requestAnimationFrame = baseRAF;
  2949. // window.setInterval = setInterval
  2950. // window.setTimeout = setTimeout
  2951. // window.requestIdleCallback = requestIdleCallback
  2952.  
  2953.  
  2954. this.start991.call(this);
  2955.  
  2956.  
  2957. window.requestAnimationFrame = mk1;
  2958. // window.setInterval = mk2
  2959. // window.setTimeout = mk3
  2960. // window.requestIdleCallback = mk4;
  2961.  
  2962. busy = false;
  2963.  
  2964.  
  2965.  
  2966. }
  2967.  
  2968. schedulerInstanceInstance_.start.toString = function () {
  2969. return schedulerInstanceInstance_.start991.toString();
  2970. }
  2971.  
  2972. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  2973. // prop,
  2974. // value: schedulerInstanceInstance_[prop],
  2975. // type: typeof schedulerInstanceInstance_[prop]
  2976.  
  2977. // }));
  2978. // console.log('fcc', funcNames)
  2979.  
  2980.  
  2981.  
  2982.  
  2983. }
  2984. })();
  2985.  
  2986. FIX_yt_player && (async () => {
  2987.  
  2988.  
  2989.  
  2990. // const rafHub = new RAFHub();
  2991.  
  2992.  
  2993. const _yt_player = await new Promise(resolve => {
  2994.  
  2995. let cid = setInterval(() => {
  2996. let t = (((window || 0)._yt_player || 0) || 0);
  2997. if (t) {
  2998.  
  2999. clearInterval(cid);
  3000. resolve(t);
  3001. }
  3002. }, 1);
  3003.  
  3004. promiseForTamerTimeout.then(() => {
  3005. resolve(null)
  3006. });
  3007.  
  3008. });
  3009.  
  3010.  
  3011.  
  3012. if (!_yt_player || typeof _yt_player !== 'object') return;
  3013.  
  3014.  
  3015.  
  3016. let keyZq = getZq(_yt_player);
  3017. // let keyVG = getVG(_yt_player);
  3018. // let buildVG = _yt_player[keyVG];
  3019. // let u = new buildVG({
  3020. // api: {},
  3021. // element: document.createElement('noscript'),
  3022. // api: {},
  3023. // hide: () => { }
  3024. // }, 250);
  3025. // const timeDelayConstructor = u.delay.constructor; // g.br
  3026. // console.log(keyVG, u)
  3027. // buildVG.prototype.show = function(){}
  3028. // _yt_player[keyZq] = g.k
  3029.  
  3030. if (!keyZq) return;
  3031.  
  3032.  
  3033. const g = _yt_player
  3034. let k = keyZq
  3035.  
  3036. const gk = g[k];
  3037. if (typeof gk !== 'function') return;
  3038. const gkp = gk.prototype;
  3039.  
  3040. let dummyObject = new gk;
  3041. let nilFunc = () => { };
  3042.  
  3043. let nilObj = {};
  3044.  
  3045. // console.log(1111111111)
  3046.  
  3047. let keyBoolD = '';
  3048. let keyWindow = '';
  3049. let keyFuncC = '';
  3050. let keyCidj = '';
  3051.  
  3052. for (const [t, y] of Object.entries(dummyObject)) {
  3053. if (y instanceof Window) keyWindow = t;
  3054. }
  3055.  
  3056. const dummyObjectProxyHandler = {
  3057. get(target, prop) {
  3058. let v = target[prop]
  3059. if (v instanceof Window && !keyWindow) {
  3060. keyWindow = t;
  3061. }
  3062. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  3063. if (prop === keyWindow) y = {
  3064. requestAnimationFrame(f) {
  3065. return 3;
  3066. },
  3067. cancelAnimationFrame() {
  3068.  
  3069. }
  3070. }
  3071. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  3072. keyFuncC = prop;
  3073. }
  3074. // console.log('[get]', prop, typeof target[prop])
  3075.  
  3076.  
  3077. return y;
  3078. },
  3079. set(target, prop, value) {
  3080.  
  3081. if (typeof value === 'boolean' && !keyBoolD) {
  3082. keyBoolD = prop;
  3083. }
  3084. if (typeof value === 'number' && !keyCidj && value >= 2) {
  3085. keyCidj = prop;
  3086. }
  3087.  
  3088. // console.log('[set]', prop, value)
  3089. target[prop] = value
  3090.  
  3091. return true;
  3092. }
  3093. };
  3094.  
  3095. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  3096.  
  3097. /*
  3098. console.log({
  3099. keyBoolD,
  3100. keyFuncC,
  3101. keyWindow,
  3102. keyCidj
  3103. })
  3104.  
  3105. console.log( dummyObject[keyFuncC])
  3106.  
  3107.  
  3108. console.log(2222222222)
  3109. */
  3110.  
  3111.  
  3112. // console.log('gkp.start',gkp.start);
  3113. // console.log('gkp.stop',gkp.stop);
  3114. gkp._activation = false;
  3115.  
  3116. gkp.start = function () {
  3117. // p59 || console.log(12100)
  3118. if (!this._activation) {
  3119. this._activation = true;
  3120. getRafPromise().then(() => {
  3121. this._activation = false;
  3122. if (this[keyCidj]) {
  3123. Promise.resolve().then(this[keyFuncC]);
  3124. }
  3125. });
  3126. }
  3127. this[keyCidj] = 1;
  3128. this[keyBoolD] = true;
  3129. }
  3130. ;
  3131. gkp.stop = function () {
  3132. this[keyCidj] = null
  3133. }
  3134.  
  3135.  
  3136. /*
  3137. g[k].start = function() {
  3138. this.stop();
  3139. this.D = true;
  3140. var a = requestAnimationFrame
  3141. , b = cancelAnimationFrame;
  3142. this.j = a.call(this.B, this.C)
  3143. }
  3144. ;
  3145. g[k].stop = function() {
  3146. if (this.isActive()) {
  3147. var a = requestAnimationFrame
  3148. , b = cancelAnimationFrame;
  3149. b.call(this.B, this.j)
  3150. }
  3151. this.j = null
  3152. }
  3153. */
  3154.  
  3155.  
  3156.  
  3157. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  3158.  
  3159. if (keyzo) {
  3160.  
  3161. k = keyzo
  3162.  
  3163. const setCSSProp = (() => {
  3164.  
  3165. let animationPropCapable = false;
  3166. try {
  3167. const propName = "--ibxpf"
  3168. const value = 2;
  3169. const keyframes = [{
  3170. [propName]: value
  3171. }];
  3172. window.CSS.registerProperty({
  3173. name: "--ibxpf",
  3174. syntax: "<number>",
  3175. inherits: false,
  3176. initialValue: 1,
  3177. });
  3178. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  3179. } catch (e) { }
  3180.  
  3181. if (!animationPropCapable) {
  3182. return (element, cssProp, value) => {
  3183.  
  3184.  
  3185. element.style.setProperty(cssProp, value);
  3186.  
  3187. }
  3188. }
  3189.  
  3190. const propMaps = new Map();
  3191.  
  3192. function setCustomCSSProperty(element, propName, value) {
  3193. let wm = propMaps.get(propName);
  3194. if (!wm) {
  3195.  
  3196. try {
  3197. window.CSS.registerProperty({
  3198. name: propName,
  3199. syntax: "*",
  3200. inherits: false
  3201. });
  3202. } catch (e) {
  3203. console.warn(e);
  3204. }
  3205.  
  3206. propMaps.set(propName, (wm = new WeakMap()));
  3207. }
  3208.  
  3209. // Create the animation keyframes with the provided property and value
  3210. const keyframes = [{
  3211. [propName]: value
  3212. }];
  3213.  
  3214. let currentAnimation = wm.get(element);
  3215. if (currentAnimation) {
  3216.  
  3217. currentAnimation.effect.setKeyframes(keyframes);
  3218.  
  3219. } else {
  3220.  
  3221.  
  3222.  
  3223. // Set the animation on the element and immediately pause it
  3224. const animation = animate.call(element, keyframes, {
  3225. duration: 1, // Very short duration as we just want to set the value
  3226. fill: 'forwards',
  3227. iterationStart: 1,
  3228. iterations: 2,
  3229. direction: 'alternate'
  3230. });
  3231.  
  3232.  
  3233. // animation.currentTime = 1;
  3234. animation.pause();
  3235.  
  3236. wm.set(element, animation);
  3237.  
  3238.  
  3239. }
  3240.  
  3241. }
  3242.  
  3243. return setCustomCSSProperty;
  3244.  
  3245.  
  3246. })();
  3247.  
  3248.  
  3249. const attrUpdateFn = g[k];
  3250. g['$$original$$' + k] = attrUpdateFn;
  3251. g[k] = function (a, b, c) {
  3252.  
  3253. // console.log(140000, a, b, c);
  3254.  
  3255. let transformType = '';
  3256. let transformValue = 0;
  3257. let transformUnit = '';
  3258.  
  3259. let byPassDefaultFn = false;
  3260. if (b === "transform" && typeof c === 'string') {
  3261.  
  3262. byPassDefaultFn = true;
  3263.  
  3264. const aStyle = a.style;
  3265.  
  3266. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  3267. if (!(a instanceof HTMLElement)) return;
  3268. if (c.length === 0) {
  3269.  
  3270. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  3271. let p = c.substring(7, c.length - 1);
  3272. let q = p.length >= 1 ? parseFloat(p) : -1;
  3273. if (q > -1e-5 && q < 1 + 1e-5) {
  3274. transformType = 'scalex'
  3275. transformValue = q;
  3276. transformUnit = '';
  3277. }
  3278.  
  3279.  
  3280. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  3281.  
  3282. let p = c.substring(11, c.length - 3);
  3283. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3284.  
  3285. if (typeof q === 'number' && !isNaN(q)) {
  3286. transformType = 'translateX'
  3287. transformValue = q;
  3288. transformUnit = 'px';
  3289. }
  3290.  
  3291.  
  3292. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  3293. let p = c.substring(7, c.length - 1);
  3294. let q = p.length >= 1 ? parseFloat(p) : -1;
  3295. if (q > -1e-5 && q < 1 + 1e-5) {
  3296. transformType = 'scaley'
  3297. transformValue = q;
  3298. transformUnit = '';
  3299. }
  3300.  
  3301.  
  3302. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  3303.  
  3304. let p = c.substring(11, c.length - 3);
  3305. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3306.  
  3307. if (typeof q === 'number' && !isNaN(q)) {
  3308. transformType = 'translateY'
  3309. transformValue = q;
  3310. transformUnit = 'px';
  3311. }
  3312.  
  3313.  
  3314. }
  3315.  
  3316. if (transformType) {
  3317.  
  3318. if (transformType === 'scalex' || transformType === 'scaley') {
  3319.  
  3320. const q = transformValue;
  3321.  
  3322.  
  3323. /*
  3324.  
  3325. let vz = Math.round(steppingScaleN * q);
  3326. const customPropName = '--discrete-'+transformType
  3327.  
  3328. const currentValue = aStyle.getPropertyValue(customPropName);
  3329.  
  3330. const transform = (aStyle.transform || '');
  3331. const u = transform.includes(customPropName)
  3332. if (`${currentValue}` === `${vz}`) {
  3333. if (u) return;
  3334. }
  3335.  
  3336.  
  3337. setCSSProp(a,customPropName, vz);
  3338. // aStyle.setProperty(customPropName, vz)
  3339.  
  3340. let ck = '';
  3341.  
  3342. if (c.length === 9) ck = c;
  3343. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3344.  
  3345. if (ck && beforeMq !== ck) {
  3346. aStyle.setProperty('--mq-transform', ck);
  3347. }
  3348.  
  3349. if (u) return;
  3350. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  3351.  
  3352.  
  3353.  
  3354. */
  3355.  
  3356. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  3357.  
  3358. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  3359. const cv = aStyle.transform;
  3360.  
  3361. // console.log(157, cv,c)
  3362.  
  3363. if (c === cv) return;
  3364. // console.log(257, cv,c)
  3365.  
  3366. aStyle.transform = c;
  3367.  
  3368. // return;
  3369.  
  3370. } else if (transformType === 'translateX' || transformType === 'translateY') {
  3371.  
  3372. const q = transformValue;
  3373.  
  3374. /*
  3375.  
  3376. let vz = q.toFixed(1);
  3377. const customPropName = '--discrete-'+transformType
  3378.  
  3379. const aStyle = a.style;
  3380. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  3381.  
  3382.  
  3383. const transform = (aStyle.transform || '');
  3384. const u = transform.includes(customPropName)
  3385. if (parseFloat(currentValue).toFixed(1) === vz) {
  3386. if (u) return;
  3387. }
  3388.  
  3389. setCSSProp(a,customPropName, vz + 'px');
  3390. // aStyle.setProperty(customPropName, vz + 'px')
  3391.  
  3392. let ck = '';
  3393. if (c.length === 15) ck = c;
  3394. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3395.  
  3396. if (ck && beforeMq !== ck) {
  3397. aStyle.setProperty('--mq-transform', ck);
  3398. }
  3399.  
  3400. if (u) return;
  3401. c = `${transformType}(var(--discrete-${transformType}))`;
  3402.  
  3403. */
  3404.  
  3405.  
  3406. const vz = +q.toFixed(1);
  3407.  
  3408. c = `${transformType}(${vz}${transformUnit})`
  3409. const cv = aStyle.transform;
  3410.  
  3411. // console.log(158, cv,c)
  3412.  
  3413. if (c === cv) return;
  3414. // console.log(258, cv,c)
  3415.  
  3416. aStyle.transform = c;
  3417.  
  3418. // return;
  3419.  
  3420. } else {
  3421. throw new Error();
  3422. }
  3423.  
  3424. } else {
  3425. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  3426. const cv = aStyle.transform
  3427. if (!c && !cv) return;
  3428. else if (c === cv) return;
  3429. aStyle.transform = c;
  3430. // return;
  3431. }
  3432.  
  3433. } else if (b === "display") {
  3434.  
  3435. const cv = a.style.display;
  3436. if (!cv && !c) return;
  3437. if (cv === c) return;
  3438.  
  3439.  
  3440. } else if (b === "width") {
  3441.  
  3442. const cv = a.style.width;
  3443. if (!cv && !c) return;
  3444. if (cv === c) return;
  3445.  
  3446. }
  3447.  
  3448. // console.log(130000, a, b, c);
  3449.  
  3450. if (byPassDefaultFn) return;
  3451. return attrUpdateFn.call(this, a, b, c);
  3452. }
  3453.  
  3454.  
  3455. /*
  3456.  
  3457. g.zo = function(a, b, c) {
  3458. if ("string" === typeof b)
  3459. (b = yo(a, b)) && (a.style[b] = c);
  3460. else
  3461. for (var d in b) {
  3462. c = a;
  3463. var e = b[d]
  3464. , f = yo(c, d);
  3465. f && (c.style[f] = e)
  3466. }
  3467. }
  3468.  
  3469.  
  3470. */
  3471.  
  3472.  
  3473. }
  3474.  
  3475.  
  3476.  
  3477. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  3478.  
  3479. if (keyuG) {
  3480.  
  3481. k = keyuG;
  3482.  
  3483. const gk = g[k];
  3484. const gkp = gk.prototype;
  3485.  
  3486.  
  3487. /** @type { Map<string, WeakMap<any, any>> } */
  3488. const ntLogs = new Map();
  3489.  
  3490. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  3491.  
  3492. gkp.updateValue31 = gkp.updateValue;
  3493. gkp.updateValue = function (a, b) {
  3494. if (typeof a !== 'string') return this.updateValue31(a, b);
  3495.  
  3496. const element = this.element;
  3497. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  3498.  
  3499. let ntLog = ntLogs.get(a);
  3500. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  3501.  
  3502. let cache = ntLog.get(element);
  3503. if (cache && cache.value === b) {
  3504. return;
  3505. }
  3506. if (!cache) {
  3507. this.__oldValueByUpdateValue__ = null;
  3508. ntLog.set(element, cache = { value: b });
  3509. } else {
  3510. this.__oldValueByUpdateValue__ = cache.value;
  3511. cache.value = b;
  3512. }
  3513.  
  3514.  
  3515. return this.updateValue31(a, b);
  3516. }
  3517.  
  3518.  
  3519. /*
  3520. g.k.update = function(a) {
  3521. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  3522. c = c.value,
  3523. this.updateValue(c, a[c])
  3524. }
  3525. ;
  3526. g.k.updateValue = function(a, b) {
  3527. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  3528. }
  3529. */
  3530.  
  3531.  
  3532. }
  3533.  
  3534.  
  3535. }
  3536.  
  3537.  
  3538.  
  3539.  
  3540. })();
  3541.  
  3542.  
  3543.  
  3544. FIX_Animation_n_timeline && (async () => {
  3545.  
  3546.  
  3547. const timeline = await new Promise(resolve => {
  3548.  
  3549. let cid = setInterval(() => {
  3550. let t = (((document || 0).timeline || 0) || 0);
  3551. if (t && typeof t._play === 'function') {
  3552.  
  3553. clearInterval(cid);
  3554. resolve(t);
  3555. }
  3556. }, 1);
  3557.  
  3558. promiseForTamerTimeout.then(() => {
  3559. resolve(null)
  3560. });
  3561.  
  3562. });
  3563.  
  3564.  
  3565. const Animation = await new Promise(resolve => {
  3566.  
  3567. let cid = setInterval(() => {
  3568. let t = (((window || 0).Animation || 0) || 0);
  3569. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  3570.  
  3571. clearInterval(cid);
  3572. resolve(t);
  3573. }
  3574. }, 1);
  3575.  
  3576. promiseForTamerTimeout.then(() => {
  3577. resolve(null)
  3578. });
  3579.  
  3580. });
  3581.  
  3582. if (!timeline) return;
  3583. if (!Animation) return;
  3584.  
  3585. const aniProto = Animation.prototype;
  3586. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  3587.  
  3588. const getXroto = (x) => {
  3589. try {
  3590. return x.__proto__;
  3591. } catch (e) { }
  3592. return null;
  3593. }
  3594. const timProto = getXroto(timeline);
  3595. if (!timProto) return;
  3596. if (
  3597. (
  3598. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  3599. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  3600. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  3601. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  3602. )
  3603.  
  3604. ) {
  3605.  
  3606. timProto.nofCQ = 1;
  3607. aniProto.nofYH = 1;
  3608.  
  3609. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  3610.  
  3611.  
  3612. /*
  3613. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3614. return c._updatePromises();
  3615. });
  3616. */
  3617.  
  3618. const p = Array.prototype.filter;
  3619.  
  3620. let res = null;
  3621. Array.prototype.filter = function () {
  3622.  
  3623. res = this;
  3624. return this;
  3625.  
  3626. };
  3627.  
  3628. _updateAnimationsPromises.call({});
  3629.  
  3630. Array.prototype.filter = p;
  3631.  
  3632. if (res && typeof res.length === 'number') {
  3633. /** @type {any[]} */
  3634. const _res = res;
  3635. return _res;
  3636. }
  3637.  
  3638.  
  3639. return null;
  3640.  
  3641.  
  3642.  
  3643.  
  3644. })(timProto._updateAnimationsPromises);
  3645.  
  3646. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  3647.  
  3648. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  3649.  
  3650. aniProto._updatePromises31 = aniProto._updatePromises;
  3651.  
  3652. /*
  3653. aniProto._updatePromises = function(){
  3654. console.log('eff',this._oldPlayState, this.playState)
  3655. return this._updatePromises31.apply(this, arguments)
  3656. }
  3657. */
  3658.  
  3659. aniProto._updatePromises = function () {
  3660. var oldPlayState = this._oldPlayState;
  3661. var newPlayState = this.playState;
  3662. // console.log('ett', oldPlayState, newPlayState)
  3663. if (newPlayState !== oldPlayState) {
  3664. this._oldPlayState = newPlayState;
  3665. if (this._readyPromise) {
  3666. if ("idle" == newPlayState) {
  3667. this._rejectReadyPromise();
  3668. this._readyPromise = void 0;
  3669. } else if ("pending" == oldPlayState) {
  3670. this._resolveReadyPromise();
  3671. } else if ("pending" == newPlayState) {
  3672. this._readyPromise = void 0;
  3673. }
  3674. }
  3675. if (this._finishedPromise) {
  3676. if ("idle" == newPlayState) {
  3677. this._rejectFinishedPromise();
  3678. this._finishedPromise = void 0;
  3679. } else if ("finished" == newPlayState) {
  3680. this._resolveFinishedPromise();
  3681. } else if ("finished" == oldPlayState) {
  3682. this._finishedPromise = void 0;
  3683. }
  3684. }
  3685. }
  3686. return this._readyPromise || this._finishedPromise;
  3687. };
  3688.  
  3689.  
  3690. let restartWebAnimationsNextTickFlag = false;
  3691.  
  3692. const looperMethodT = () => {
  3693.  
  3694. const runnerFn = (hRes) => {
  3695. var b = timeline;
  3696. b.currentTime = hRes;
  3697. b._discardAnimations();
  3698. if (0 == b._animations.length) {
  3699. restartWebAnimationsNextTickFlag = false;
  3700. } else {
  3701. getRafPromise().then(runnerFn);
  3702. }
  3703. }
  3704.  
  3705. const restartWebAnimationsNextTick = () => {
  3706. if (!restartWebAnimationsNextTickFlag) {
  3707. restartWebAnimationsNextTickFlag = true;
  3708. getRafPromise().then(runnerFn);
  3709. }
  3710. }
  3711.  
  3712. return { restartWebAnimationsNextTick }
  3713. };
  3714.  
  3715.  
  3716. const looperMethodN = () => {
  3717.  
  3718. const acs = document.createElement('a-f');
  3719. acs.id = 'a-f';
  3720.  
  3721. const style = document.createElement('style');
  3722. style.textContent = `
  3723. @keyFrames aF1 {
  3724. 0% {
  3725. order: 0;
  3726. }
  3727. 100% {
  3728. order: 6;
  3729. }
  3730. }
  3731. #a-f[id] {
  3732. visibility: collapse !important;
  3733. position: fixed !important;
  3734. top: -100px !important;
  3735. left: -100px !important;
  3736. margin:0 !important;
  3737. padding:0 !important;
  3738. outline:0 !important;
  3739. border:0 !important;
  3740. z-index:-1 !important;
  3741. width: 0px !important;
  3742. height: 0px !important;
  3743. contain: strict !important;
  3744. pointer-events: none !important;
  3745. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  3746. }
  3747. `;
  3748. (document.head || document.documentElement).appendChild(style);
  3749.  
  3750. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  3751.  
  3752. const _onanimationiteration = function (evt) {
  3753. const hRes = evt.timeStamp;
  3754. var b = timeline;
  3755. b.currentTime = hRes;
  3756. b._discardAnimations();
  3757. if (0 == b._animations.length) {
  3758. restartWebAnimationsNextTickFlag = false;
  3759. acs.onanimationiteration = null;
  3760. } else {
  3761. acs.onanimationiteration = _onanimationiteration;
  3762. }
  3763.  
  3764. }
  3765.  
  3766.  
  3767.  
  3768. const restartWebAnimationsNextTick = () => {
  3769. if (!restartWebAnimationsNextTickFlag) {
  3770. restartWebAnimationsNextTickFlag = true;
  3771. acs.onanimationiteration = _onanimationiteration;
  3772.  
  3773. }
  3774. }
  3775.  
  3776. return { restartWebAnimationsNextTick }
  3777. };
  3778.  
  3779.  
  3780.  
  3781. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  3782.  
  3783.  
  3784. // console.log(571, timProto);
  3785. timProto._play = function (c) {
  3786. c = new Animation(c, this);
  3787. this._animations.push(c);
  3788. restartWebAnimationsNextTick();
  3789. c._updatePromises();
  3790. c._animation.play();
  3791. c._updatePromises();
  3792. return c
  3793. }
  3794.  
  3795. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  3796. originalAnimationsWithPromises.length = 0;
  3797. originalAnimationsWithPromises.push = null;
  3798. originalAnimationsWithPromises.splice = null;
  3799. originalAnimationsWithPromises.slice = null;
  3800. originalAnimationsWithPromises.indexOf = null;
  3801. originalAnimationsWithPromises.unshift = null;
  3802. originalAnimationsWithPromises.shift = null;
  3803. originalAnimationsWithPromises.pop = null;
  3804. originalAnimationsWithPromises.filter = null;
  3805. originalAnimationsWithPromises.forEach = null;
  3806. originalAnimationsWithPromises.map = null;
  3807.  
  3808.  
  3809. const _updateAnimationsPromises = () => {
  3810. animationsWithPromisesMap.forEach(c => {
  3811. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  3812. });
  3813. /*
  3814. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3815. return c._updatePromises();
  3816. });
  3817. */
  3818. }
  3819.  
  3820. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  3821.  
  3822. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  3823.  
  3824. delete timProto._updateAnimationsPromises;
  3825. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  3826. get() {
  3827. if (animationsWithPromisesMap.size === 0) return nilFn;
  3828. return _updateAnimationsPromises;
  3829. },
  3830. set(nv) {
  3831. delete this._updateAnimationsPromises;
  3832. this._updateAnimationsPromises = nv;
  3833. },
  3834. enumerable: true,
  3835. configurable: true,
  3836. });
  3837.  
  3838.  
  3839. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  3840. aniProto.__finished_native_get__ = pdFinished.get;
  3841. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  3842.  
  3843.  
  3844. Object.defineProperty(aniProto, 'finished', {
  3845. get() {
  3846. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3847. this._finishedPromise = new Promise((resolve, reject) => {
  3848. this._resolveFinishedPromise = function () {
  3849. resolve(this)
  3850. };
  3851. this._rejectFinishedPromise = function () {
  3852. reject({
  3853. type: DOMException.ABORT_ERR,
  3854. name: "AbortError"
  3855. })
  3856. };
  3857. }),
  3858. "finished" == this.playState && this._resolveFinishedPromise());
  3859. return this._finishedPromise
  3860. },
  3861. set: undefined,
  3862. enumerable: true,
  3863. configurable: true
  3864. });
  3865.  
  3866. }
  3867.  
  3868.  
  3869.  
  3870. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  3871. aniProto.__ready_native_get__ = pdReady.get;
  3872. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  3873.  
  3874. Object.defineProperty(aniProto, 'ready', {
  3875. get() {
  3876. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3877. this._readyPromise = new Promise((resolve, reject) => {
  3878. this._resolveReadyPromise = function () {
  3879. resolve(this)
  3880. };
  3881. this._rejectReadyPromise = function () {
  3882. reject({
  3883. type: DOMException.ABORT_ERR,
  3884. name: "AbortError"
  3885. })
  3886. };
  3887. }),
  3888. "pending" !== this.playState && this._resolveReadyPromise());
  3889. return this._readyPromise
  3890. },
  3891. set: undefined,
  3892. enumerable: true,
  3893. configurable: true
  3894. });
  3895.  
  3896. }
  3897.  
  3898.  
  3899. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  3900.  
  3901. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  3902. const _rebuildUnderlyingAnimation = function () {
  3903. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  3904. this.effect && this.effect._onsample && (this.effect._onsample = null);
  3905. return this._rebuildUnderlyingAnimation21();
  3906. }
  3907. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  3908. // delete aniProto._rebuildUnderlyingAnimation;
  3909. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  3910. // get() {
  3911. // if (isNaN(this._sequenceNumber)) return nilFn;
  3912. // return this._rebuildUnderlyingAnimation21;
  3913. // },
  3914. // set(nv) {
  3915. // delete this._rebuildUnderlyingAnimation;
  3916. // this._rebuildUnderlyingAnimation = nv;
  3917. // },
  3918. // enumerable: true,
  3919. // configurable: true
  3920. // });
  3921. }
  3922.  
  3923.  
  3924. /*
  3925.  
  3926.  
  3927. function f(c) {
  3928. var b = v.timeline;
  3929. b.currentTime = c;
  3930. b._discardAnimations();
  3931. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  3932. }
  3933. var h = window.requestAnimationFrame;
  3934. window.requestAnimationFrame = function(c) {
  3935. return h(function(b) {
  3936. v.timeline._updateAnimationsPromises();
  3937. c(b);
  3938. v.timeline._updateAnimationsPromises()
  3939. })
  3940. }
  3941. ;
  3942. v.AnimationTimeline = function() {
  3943. this._animations = [];
  3944. this.currentTime = void 0
  3945. }
  3946. ;
  3947. v.AnimationTimeline.prototype = {
  3948. getAnimations: function() {
  3949. this._discardAnimations();
  3950. return this._animations.slice()
  3951. },
  3952. _updateAnimationsPromises: function() {
  3953. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  3954. return c._updatePromises()
  3955. })
  3956. },
  3957. _discardAnimations: function() {
  3958. this._updateAnimationsPromises();
  3959. this._animations = this._animations.filter(function(c) {
  3960. return "finished" != c.playState && "idle" != c.playState
  3961. })
  3962. },
  3963. _play: function(c) {
  3964. c = new v.Animation(c,this);
  3965. this._animations.push(c);
  3966. v.restartWebAnimationsNextTick();
  3967. c._updatePromises();
  3968. c._animation.play();
  3969. c._updatePromises();
  3970. return c
  3971. },
  3972. play: function(c) {
  3973. c && c.remove();
  3974. return this._play(c)
  3975. }
  3976. };
  3977. var d = !1;
  3978. v.restartWebAnimationsNextTick = function() {
  3979. d || (d = !0,
  3980. requestAnimationFrame(f))
  3981. }
  3982. ;
  3983. var a = new v.AnimationTimeline;
  3984. v.timeline = a;
  3985. try {
  3986. Object.defineProperty(window.document, "timeline", {
  3987. configurable: !0,
  3988. get: function() {
  3989. return a
  3990. }
  3991. })
  3992. } catch (c) {}
  3993. try {
  3994. window.document.timeline = a
  3995. } catch (c) {}
  3996.  
  3997. */
  3998.  
  3999.  
  4000.  
  4001. /*
  4002.  
  4003. var g = window.getComputedStyle;
  4004. Object.defineProperty(window, "getComputedStyle", {
  4005. configurable: !0,
  4006. enumerable: !0,
  4007. value: function() {
  4008. v.timeline._updateAnimationsPromises();
  4009. var e = g.apply(this, arguments);
  4010. h() && (e = g.apply(this, arguments));
  4011. v.timeline._updateAnimationsPromises();
  4012. return e
  4013. }
  4014. });
  4015.  
  4016. */
  4017.  
  4018.  
  4019.  
  4020.  
  4021. }
  4022.  
  4023.  
  4024.  
  4025.  
  4026. })();
  4027.  
  4028.  
  4029.  
  4030.  
  4031. promiseForCustomYtElementsReady.then(() => {
  4032.  
  4033. FIX_ytdExpander_childrenChanged && customElements.whenDefined('ytd-expander').then(() => {
  4034.  
  4035.  
  4036.  
  4037. let dummy;
  4038. let cProto;
  4039.  
  4040.  
  4041.  
  4042. dummy = document.createElement('ytd-expander');
  4043. cProto = (dummy.inst || dummy).constructor.prototype;
  4044.  
  4045.  
  4046. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  4047.  
  4048.  
  4049. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  4050. cProto.childrenChanged14 = cProto.childrenChanged;
  4051.  
  4052. cProto.initChildrenObserver = function () {
  4053. var a = this;
  4054. this.observer = new MutationObserver(function () {
  4055. a.childrenChanged()
  4056. }
  4057. );
  4058. this.observer.observe(this.content, {
  4059. subtree: !0,
  4060. childList: !0,
  4061. attributes: !0,
  4062. characterData: !0
  4063. });
  4064. this.childrenChanged()
  4065. }
  4066. ;
  4067. cProto.childrenChanged = function () {
  4068. if (this.alwaysToggleable) {
  4069. this.canToggle = this.alwaysToggleable;
  4070. } else if (!this.canToggleJobId) {
  4071. this.canToggleJobId = 1;
  4072. getRafPromise().then(() => {
  4073. this.canToggleJobId = 0;
  4074. this.calculateCanCollapse()
  4075. })
  4076. }
  4077. }
  4078.  
  4079.  
  4080. // console.log(cProto.initChildrenObserver)
  4081. console.debug('ytd-expander-fix-childrenChanged');
  4082.  
  4083. }
  4084.  
  4085. })
  4086.  
  4087.  
  4088.  
  4089. FIX_paper_ripple_animate && customElements.whenDefined('paper-ripple').then(() => {
  4090.  
  4091.  
  4092.  
  4093. let dummy;
  4094. let cProto;
  4095. dummy = document.createElement('paper-ripple');
  4096. cProto = (dummy.inst || dummy).constructor.prototype;
  4097.  
  4098. if (fnIntegrity(cProto.animate, '0.74.5')) {
  4099.  
  4100.  
  4101. cProto.animate34 = cProto.animate;
  4102. cProto.animate = function () {
  4103. if (this._animating) {
  4104. var a;
  4105. const ripples = this.ripples;
  4106. for (a = 0; a < ripples.length; ++a) {
  4107. var b = ripples[a];
  4108. b.draw();
  4109. this.$.background.style.opacity = b.outerOpacity;
  4110. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  4111. }
  4112. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  4113. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  4114. getRafPromise().then(this._boundAnimate38);
  4115. } else {
  4116. this.onAnimationComplete()
  4117. }
  4118. }
  4119. }
  4120.  
  4121. console.debug('FIX_paper_ripple_animate')
  4122.  
  4123. // console.log(cProto.animate)
  4124.  
  4125. }
  4126.  
  4127. });
  4128.  
  4129. if (FIX_doIdomRender) {
  4130.  
  4131.  
  4132. const xsetTimeout = function (f, d) {
  4133. if (xsetTimeout.m511 === 1 && !d) {
  4134. xsetTimeout.m511 = 2;
  4135. getRafPromise().then(f);
  4136. } else {
  4137. return setTimeout.apply(window, arguments)
  4138. }
  4139.  
  4140. }
  4141.  
  4142. const xrequestAnimationFrame = function (f) {
  4143. const h = f + "";
  4144. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  4145. xsetTimeout.m511 = 1;
  4146. f();
  4147. xsetTimeout.m511 = 0;
  4148. } else if (h.includes("requestAninmationFrameResolver")) {
  4149. getRafPromise().then(f);
  4150. } else {
  4151. return requestAnimationFrame.apply(window, arguments);
  4152. }
  4153. }
  4154.  
  4155. let busy = false;
  4156. const doIdomRender = function () {
  4157. if (busy) {
  4158. return this.doIdomRender13.apply(this, arguments);
  4159. }
  4160. busy = true;
  4161. const { requestAnimationFrame, setTimeout } = window;
  4162. window.requestAnimationFrame = xrequestAnimationFrame;
  4163. window.setTimeout = xsetTimeout;
  4164. let r = this.doIdomRender13.apply(this, arguments);
  4165. window.requestAnimationFrame = requestAnimationFrame;
  4166. window.setTimeout = setTimeout;
  4167. busy = false;
  4168. return r;
  4169. };
  4170. 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']) {
  4171.  
  4172.  
  4173. customElements.whenDefined(ytTag).then(() => {
  4174.  
  4175. let dummy;
  4176. let cProto;
  4177. dummy = document.createElement(ytTag);
  4178. cProto = (dummy.inst || dummy).constructor.prototype;
  4179.  
  4180. cProto.doIdomRender13 = cProto.doIdomRender;
  4181. cProto.doIdomRender = doIdomRender;
  4182.  
  4183. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  4184.  
  4185. console.debug('FIX_doIdomRender', ytTag)
  4186.  
  4187.  
  4188.  
  4189. });
  4190.  
  4191. }
  4192.  
  4193. }
  4194.  
  4195.  
  4196.  
  4197. });
  4198.  
  4199. });
  4200.  
  4201.  
  4202. setupEvents();
  4203.  
  4204.  
  4205.  
  4206. if (isMainWindow) {
  4207.  
  4208. console.groupCollapsed(
  4209. "%cYouTube JS Engine Tamer",
  4210. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  4211. );
  4212.  
  4213.  
  4214.  
  4215. console.log("Script is loaded.");
  4216. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  4217.  
  4218. console.log("This script is experimental and subject to further changes.");
  4219.  
  4220. console.log("This might boost your YouTube performance.");
  4221.  
  4222. console.log("CAUTION: This might break your YouTube.");
  4223.  
  4224.  
  4225. if (prepareLogs.length >= 1) {
  4226. console.log(" =========================================================================== ");
  4227.  
  4228. for (const msg of prepareLogs) {
  4229. console.log(msg)
  4230. }
  4231.  
  4232. console.log(" =========================================================================== ");
  4233. }
  4234.  
  4235. console.groupEnd();
  4236.  
  4237. }
  4238.  
  4239.  
  4240.  
  4241.  
  4242.  
  4243.  
  4244. })();