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