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