YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-03-07 提交的版本,查看 最新版本

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