YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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