YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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