YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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