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