YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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