YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前為 2024-03-02 提交的版本,檢視 最新版本

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