YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前為 2023-12-09 提交的版本,檢視 最新版本

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