YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-04-14 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址