YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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