YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址