YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-01-15 提交的版本,查看 最新版本

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