YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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