YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前为 2024-03-02 提交的版本。查看 最新版本

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