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