YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2023-09-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.4.9
  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. // @run-at document-start
  12. // @unwrap
  13. // @inject-into page
  14. // @allFrames true
  15. // ==/UserScript==
  16.  
  17. (() => {
  18.  
  19. const NATIVE_CANVAS_ANIMATION = true; // for #cinematics
  20. const FIX_schedulerInstanceInstance_ = true;
  21. const FIX_yt_player = true;
  22. const FIX_Animation_n_timeline = true;
  23. const NO_PRELOAD_GENERATE_204 = false;
  24. const CHANGE_appendChild = true;
  25.  
  26. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  27. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  28. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  29.  
  30. /*
  31. window.addEventListener('edm',()=>{
  32. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  33. });
  34.  
  35. window.addEventListener('edn',()=>{
  36. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  37. });
  38. window.addEventListener('edr',()=>{
  39. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  40. });
  41. */
  42.  
  43.  
  44. const prepareLogs = [];
  45.  
  46. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  47.  
  48. let winError00 = window.onerror;
  49.  
  50. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  51.  
  52. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  53.  
  54.  
  55. ; fix_error_many_stack_state === 1 && (() => {
  56.  
  57.  
  58. let p1 = winError00;
  59.  
  60. let stackNeedleDetails = null;
  61.  
  62. Object.defineProperty(Object.prototype, 'matchAll', {
  63. get() {
  64. stackNeedleDetails = this;
  65. return true;
  66. },
  67. enumerable: true,
  68. configurable: true
  69. });
  70.  
  71. try {
  72. JSON.parse("{}");
  73. } catch (e) {
  74. console.warn(e)
  75. fix_error_many_stack_state = 0;
  76. }
  77.  
  78. delete Object.prototype['matchAll'];
  79.  
  80. let p2 = window.onerror;
  81.  
  82. window.onerror = p1;
  83.  
  84. if (fix_error_many_stack_state === 0) return;
  85.  
  86. if (stackNeedleDetails) {
  87. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  88. stackNeedleDetails.matchAll = true;
  89. }
  90.  
  91. if (p1 === p2) return (fix_error_many_stack_state = 0);
  92.  
  93. // p1!==p2
  94. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  95.  
  96. })();
  97.  
  98. ; fix_error_many_stack_state === 2 && (() => {
  99.  
  100.  
  101. let p1 = winError00;
  102.  
  103. let objectPrune = null;
  104. let stackNeedleDetails = null;
  105.  
  106. Object.defineProperty(Function.prototype, 'findOwner', {
  107. get() {
  108. objectPrune = this;
  109. return this._findOwner;
  110. },
  111. set(nv) {
  112. this._findOwner = nv;
  113. return true;
  114. },
  115. enumerable: true,
  116. configurable: true
  117. });
  118.  
  119. Object.defineProperty(Object.prototype, 'matchAll', {
  120. get() {
  121. stackNeedleDetails = this;
  122. return true;
  123. },
  124. enumerable: true,
  125. configurable: true
  126. });
  127.  
  128. try {
  129. JSON.parse("{}");
  130. } catch (e) {
  131. console.warn(e)
  132. fix_error_many_stack_state = 0;
  133. }
  134.  
  135. delete Function.prototype['findOwner'];
  136. delete Object.prototype['matchAll'];
  137.  
  138. let p2 = window.onerror;
  139.  
  140. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  141.  
  142. if (fix_error_many_stack_state == 0) return;
  143.  
  144. // the following will only execute when Brave's scriptlets.js is executed.
  145.  
  146. prepareLogs.push("fix_error_many_stack_state NB")
  147.  
  148. if (stackNeedleDetails) {
  149. stackNeedleDetails.pattern = null;
  150. stackNeedleDetails.re = null;
  151. stackNeedleDetails.expect = null;
  152. stackNeedleDetails.matchAll = true;
  153. }
  154.  
  155. if (objectPrune) {
  156. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  157. delete objectPrune._findOwner;
  158. }
  159.  
  160. fix_error_many_stack_state = 3;
  161. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  162. JSON.parse.objectPrune = objectPrune;
  163.  
  164. })();
  165.  
  166. ; fix_error_many_stack_state === 3 && (() => {
  167.  
  168.  
  169. let p1 = winError00;
  170.  
  171. try {
  172. JSON.parse("{}");
  173. } catch (e) {
  174. console.warn(e)
  175. fix_error_many_stack_state = 0;
  176. }
  177.  
  178. let p2 = window.onerror;
  179.  
  180. if (p1 === p2) return;
  181.  
  182. window.onerror = p1;
  183.  
  184. if (fix_error_many_stack_state === 0) return;
  185.  
  186. fix_error_many_stack_state = 4; // p1 != p2
  187.  
  188.  
  189. })();
  190.  
  191. fix_error_many_stack_state === 4 && (() => {
  192.  
  193. // the following will only execute when Brave's scriptlets.js is executed.
  194.  
  195. prepareLogs.push("fix_error_many_stack_state AB")
  196.  
  197. JSON.parseProxy = JSON.parse;
  198.  
  199. JSON.parse = ((parse) => {
  200.  
  201. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  202. return function (text, reviver) {
  203. const onerror = window.onerror;
  204. window.onerror = null;
  205. let r;
  206. try {
  207. r = parse(...arguments);
  208. } catch (e) {
  209. r = e;
  210. }
  211. window.onerror = onerror;
  212. if (r instanceof Error) {
  213. throw r;
  214. }
  215. return r;
  216. }
  217.  
  218. })(JSON.parse);
  219.  
  220.  
  221. })();
  222.  
  223.  
  224.  
  225. // ================================================ 0.4.5 ================================================
  226.  
  227.  
  228. // ; (() => {
  229.  
  230. // if (FIX_error_many_stack && self instanceof Window) {
  231. // // infinite stack due to matchesStackTrace inside objectPrune of AdsBlock
  232.  
  233. // const pdK = Object.getOwnPropertyDescriptor(window, 'onerror');
  234. // if (!pdK || (pdK.get && pdK.configurable)) {
  235.  
  236. // } else {
  237. // return;
  238. // }
  239.  
  240. // let unsupportErrorFix = false;
  241.  
  242. // let firstHook = true;
  243. // let busy33 = false;
  244.  
  245. // let state = 0;
  246.  
  247. // if (pdK) {
  248. // delete window['onerror'];
  249. // }
  250.  
  251. // const pd = {
  252. // get() {
  253. // const stack = (new Error()).stack;
  254. // // targetStack = stack;
  255. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  256. // state = isGetExceptionToken ? 1 : 0;
  257. // delete Window.prototype['onerror'];
  258. // let r = pdK ? pdK.get.call(this) : this.onerror;
  259. // Object.defineProperty(Window.prototype, 'onerror', pd);
  260. // // console.log('onerror get', r)
  261. // return r;
  262. // },
  263. // set(nv) {
  264. // const stack = (new Error()).stack;
  265. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  266. // state = state === 1 && isGetExceptionToken ? 2 : 0;
  267. // /** @type {string?} */
  268. // let sToken = null;
  269. // if (unsupportErrorFix || busy33) {
  270.  
  271. // } else if (typeof nv === 'function' && state === 2) {
  272. // if (firstHook) {
  273. // firstHook = false;
  274. // console.groupCollapsed('Infinite onerror Bug Found');
  275. // console.log(location.href);
  276. // console.log(stack);
  277. // console.log(nv);
  278. // console.groupEnd();
  279. // }
  280. // let _token = null;
  281. // busy33 = true;
  282. // String.prototype.includes76 = String.prototype.includes;
  283. // String.prototype.includes = function (token) {
  284. // _token = token;
  285. // return true;
  286. // }
  287. // nv('token');
  288. // String.prototype.includes = String.prototype.includes76;
  289. // sToken = _token;
  290. // busy33 = false;
  291. // if (typeof sToken !== 'string') {
  292. // unsupportErrorFix = true;
  293. // }
  294. // }
  295. // delete Window.prototype['onerror'];
  296. // if (typeof sToken === 'string' && sToken.length > 1) {
  297. // /** @type {string} */
  298. // const token = sToken;
  299. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>?} } */
  300. // const currentOnerror = pdK ? pdK.get.call(this) : this.onerror;
  301.  
  302. // const now = Date.now();
  303. // const tokenEntry = {
  304. // token,
  305. // expired: now + FIX_error_many_stack_keepAliveDuration
  306. // }
  307. // /** @typedef {typeof tokenEntry} TokenEntry */
  308.  
  309. // /** @type {Set<TokenEntry>} */
  310. // const errorTokens = currentOnerror.errorTokens;
  311.  
  312. // if (errorTokens) {
  313. // if (errorTokens.size > FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than) {
  314. // for (const entry of errorTokens) {
  315. // if (entry.expired < now) {
  316. // errorTokens.delete(entry);
  317. // }
  318. // }
  319. // }
  320. // errorTokens.add(tokenEntry)
  321. // } else {
  322. // /** @type {Set<TokenEntry>} */
  323. // const errorTokens = new Set([tokenEntry]);
  324. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>} } */
  325. // const newOnerror = ((oe) => {
  326. // const r = function (msg, ...args) {
  327. // if (typeof msg === 'string' && errorTokens.size > 0) {
  328. // for (const entry of errorTokens) {
  329. // if (msg.includes(entry.token)) return true;
  330. // }
  331. // }
  332. // if (typeof oe === 'function') {
  333. // return oe.apply(this, arguments);
  334. // }
  335. // };
  336. // r.errorTokens = errorTokens;
  337. // return r;
  338. // })(currentOnerror);
  339.  
  340. // if (pdK && pdK.set) pdK.set.call(this, newOnerror);
  341. // else this.onerror = newOnerror;
  342. // }
  343. // } else {
  344. // if (pdK && pdK.set) pdK.set.call(this, nv);
  345. // else this.onerror = nv;
  346. // }
  347. // Object.defineProperty(Window.prototype, 'onerror', pd);
  348.  
  349. // // console.log('onerror set', nv)
  350. // return true;
  351. // },
  352. // enumerable: true,
  353. // configurable: true
  354. // }
  355.  
  356. // Object.defineProperty(Window.prototype, 'onerror', pd);
  357.  
  358.  
  359. // }
  360.  
  361.  
  362. // })();
  363.  
  364.  
  365.  
  366. // ================================================ 0.4.5 ================================================
  367.  
  368.  
  369. // << if FIX_yt_player >>
  370.  
  371. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  372. const PERF_471489_ = true;
  373. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  374. // This script uses a much gentle way to tamer the JS engine instead.
  375.  
  376. // << end >>
  377.  
  378. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  379.  
  380. const Promise = (async () => { })().constructor;
  381.  
  382. let isMainWindow = false;
  383. try {
  384. isMainWindow = window.document === window.top.document
  385. } catch (e) { }
  386.  
  387. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  388.  
  389. const onRegistryReady = (callback) => {
  390. if (typeof customElements === 'undefined') {
  391. if (!('__CE_registry' in document)) {
  392. // https://github.com/webcomponents/polyfills/
  393. Object.defineProperty(document, '__CE_registry', {
  394. get() {
  395. // return undefined
  396. },
  397. set(nv) {
  398. if (typeof nv == 'object') {
  399. delete this.__CE_registry;
  400. this.__CE_registry = nv;
  401. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  402. }
  403. return true;
  404. },
  405. enumerable: false,
  406. configurable: true
  407. })
  408. }
  409. let eventHandler = (evt) => {
  410. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  411. const f = callback;
  412. callback = null;
  413. eventHandler = null;
  414. f();
  415. };
  416. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  417. } else {
  418. callback();
  419. }
  420. };
  421.  
  422. const getZq = (_yt_player) => {
  423.  
  424. const w = 'Zq';
  425.  
  426. let arr = [];
  427.  
  428. for (const [k, v] of Object.entries(_yt_player)) {
  429.  
  430. const p = typeof v === 'function' ? v.prototype : 0;
  431. if (p
  432. && typeof p.start === 'function' && p.start.length === 0
  433. && typeof p.isActive === 'function' && p.isActive.length === 0
  434. && typeof p.stop === 'function' && p.stop.length === 0
  435. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  436. && !p.send && !p.abort
  437. && !p.sample && !p.initialize && !p.fail && !p.getName
  438. // && !p.dispose && !p.isDisposed
  439.  
  440. ) {
  441. arr = addProtoToArr(_yt_player, k, arr) || arr;
  442.  
  443.  
  444. }
  445.  
  446. }
  447.  
  448. if (arr.length === 0) {
  449.  
  450. console.warn(`Key does not exist. [${w}]`);
  451. } else {
  452.  
  453. console.log(`[${w}]`, arr);
  454. return arr[0];
  455. }
  456.  
  457.  
  458.  
  459.  
  460. }
  461.  
  462.  
  463. const getVG = (_yt_player) => {
  464. const w = 'VG';
  465.  
  466. let arr = [];
  467.  
  468. for (const [k, v] of Object.entries(_yt_player)) {
  469.  
  470. const p = typeof v === 'function' ? v.prototype : 0;
  471. if (p
  472. && typeof p.show === 'function' && p.show.length === 1
  473. && typeof p.hide === 'function' && p.hide.length === 0
  474. && typeof p.stop === 'function' && p.stop.length === 0) {
  475.  
  476. arr = addProtoToArr(_yt_player, k, arr) || arr;
  477.  
  478. }
  479.  
  480. }
  481.  
  482.  
  483. if (arr.length === 0) {
  484.  
  485. console.warn(`Key does not exist. [${w}]`);
  486. } else {
  487.  
  488. console.log(`[${w}]`, arr);
  489. return arr[0];
  490. }
  491.  
  492.  
  493.  
  494. }
  495.  
  496.  
  497. const getzo = (_yt_player) => {
  498. const w = 'zo';
  499.  
  500. let arr = [];
  501.  
  502. for (const [k, v] of Object.entries(_yt_player)) {
  503.  
  504. if (
  505. typeof v === 'function' && v.length === 3 && k.length < 3
  506. && (v + "").includes("a.style[b]=c")
  507. ) {
  508.  
  509. arr.push(k);
  510.  
  511. }
  512.  
  513. }
  514.  
  515.  
  516. if (arr.length === 0) {
  517.  
  518. console.warn(`Key does not exist. [${w}]`);
  519. } else {
  520.  
  521. console.log(`[${w}]`, arr);
  522. return arr[0];
  523. }
  524.  
  525. }
  526.  
  527. const addProtoToArr = (parent, key, arr) => {
  528.  
  529.  
  530. let isChildProto = false;
  531. for (const sr of arr) {
  532. if (parent[key].prototype instanceof parent[sr]) {
  533. isChildProto = true;
  534. break;
  535. }
  536. }
  537.  
  538. if (isChildProto) return;
  539.  
  540. arr = arr.filter(sr => {
  541. if (parent[sr].prototype instanceof parent[key]) {
  542. return false;
  543. }
  544. return true;
  545. });
  546.  
  547. arr.push(key);
  548.  
  549. return arr;
  550.  
  551.  
  552. }
  553.  
  554. const getuG = (_yt_player) => {
  555.  
  556. const w = 'uG';
  557.  
  558. let arr = [];
  559.  
  560. for (const [k, v] of Object.entries(_yt_player)) {
  561.  
  562.  
  563. const p = typeof v === 'function' ? v.prototype : 0;
  564.  
  565. if (p
  566. && typeof p.createElement === 'function' && p.createElement.length === 2
  567. && typeof p.detach === 'function' && p.detach.length === 0
  568. && typeof p.update === 'function' && p.update.length === 1
  569. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  570. ) {
  571.  
  572. arr = addProtoToArr(_yt_player, k, arr) || arr;
  573.  
  574. }
  575.  
  576. }
  577.  
  578.  
  579.  
  580.  
  581.  
  582. if (arr.length === 0) {
  583.  
  584. console.warn(`Key does not exist. [${w}]`);
  585. } else {
  586.  
  587. console.log(`[${w}]`, arr);
  588. return arr[0];
  589. }
  590.  
  591. }
  592.  
  593.  
  594.  
  595. // << if FIX_schedulerInstanceInstance_ >>
  596.  
  597. let idleFrom = Date.now() + 2700;
  598. let slowMode = false;
  599.  
  600. let ytEvented = false;
  601.  
  602.  
  603. function setupEvents() {
  604.  
  605. document.addEventListener('yt-navigate', () => {
  606.  
  607. ytEvented = true;
  608. slowMode = false;
  609. idleFrom = Date.now() + 2700;
  610.  
  611. });
  612. document.addEventListener('yt-navigate-start', () => {
  613.  
  614. ytEvented = true;
  615. slowMode = false;
  616. idleFrom = Date.now() + 2700;
  617.  
  618. });
  619.  
  620. document.addEventListener('yt-page-type-changed', () => {
  621.  
  622. ytEvented = true;
  623. slowMode = false;
  624. idleFrom = Date.now() + 1700;
  625.  
  626. });
  627.  
  628.  
  629. document.addEventListener('yt-player-updated', () => {
  630.  
  631. ytEvented = true;
  632. slowMode = false;
  633. idleFrom = Date.now() + 1700;
  634.  
  635. });
  636.  
  637.  
  638. document.addEventListener('yt-page-data-fetched', () => {
  639.  
  640. ytEvented = true;
  641. slowMode = false;
  642. idleFrom = Date.now() + 1700;
  643.  
  644. });
  645.  
  646. document.addEventListener('yt-navigate-finish', () => {
  647.  
  648. ytEvented = true;
  649. slowMode = false;
  650. let t = Date.now() + 700;
  651. if (t > idleFrom) idleFrom = t;
  652.  
  653. });
  654.  
  655. document.addEventListener('yt-page-data-updated', () => {
  656.  
  657. ytEvented = true;
  658. slowMode = false;
  659. let t = Date.now() + 700;
  660. if (t > idleFrom) idleFrom = t;
  661.  
  662. });
  663.  
  664. document.addEventListener('yt-watch-comments-ready', () => {
  665.  
  666. ytEvented = true;
  667. slowMode = false;
  668. let t = Date.now() + 700;
  669. if (t > idleFrom) idleFrom = t;
  670.  
  671. });
  672. }
  673.  
  674.  
  675. // << end >>
  676.  
  677. const cleanContext = async (win) => {
  678. const waitFn = requestAnimationFrame; // shall have been binded to window
  679. try {
  680. let mx = 16; // MAX TRIAL
  681. const frameId = 'vanillajs-iframe-v1';
  682. /** @type {HTMLIFrameElement | null} */
  683. let frame = document.getElementById(frameId);
  684. let removeIframeFn = null;
  685. if (!frame) {
  686. frame = document.createElement('iframe');
  687. frame.id = 'vanillajs-iframe-v1';
  688. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  689. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  690. n.appendChild(frame);
  691. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  692. const root = document.documentElement;
  693. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  694. removeIframeFn = (setTimeout) => {
  695. const removeIframeOnDocumentReady = (e) => {
  696. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  697. win = null;
  698. setTimeout(() => {
  699. n.remove();
  700. n = null;
  701. }, 200);
  702. }
  703. if (document.readyState !== 'loading') {
  704. removeIframeOnDocumentReady();
  705. } else {
  706. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  707. }
  708. }
  709. }
  710. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  711. const fc = frame.contentWindow;
  712. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  713. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  714. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  715. for (let k in res) res[k] = res[k].bind(win); // necessary
  716. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  717. res.animate = fc.HTMLElement.prototype.animate;
  718. return res;
  719. } catch (e) {
  720. console.warn(e);
  721. return null;
  722. }
  723. };
  724.  
  725.  
  726. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  727.  
  728. cleanContext(window).then(__CONTEXT__ => {
  729. if (!__CONTEXT__) return null;
  730.  
  731. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle } = __CONTEXT__;
  732.  
  733.  
  734.  
  735. let rafPromiseForTickers = null;
  736.  
  737. const getRafPromiseForTickers = () => rafPromiseForTickers || (rafPromiseForTickers = new Promise(resolve => {
  738. requestAnimationFrame(hRes => {
  739. rafPromiseForTickers = null;
  740. resolve(hRes);
  741. });
  742. }));
  743.  
  744. const getForegroundPromise = () => {
  745. if (document.visibilityState === 'visible') {
  746. return Promise.resolve();
  747. } else {
  748. return getRafPromiseForTickers();
  749. }
  750. };
  751.  
  752. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  753. setTimeout(() => {
  754. NO_PRELOAD_GENERATE_204_BYPASS = true;
  755. }, 1270);
  756. });
  757.  
  758. const promiseForTamerTimeout = new Promise(resolve => {
  759. promiseForCustomYtElementsReady.then(() => {
  760. customElements.whenDefined('ytd-app').then(() => {
  761. setTimeout(resolve, 1200);
  762. });
  763. });
  764. setTimeout(resolve, 3000);
  765. });
  766.  
  767.  
  768. class RAFHub {
  769. constructor() {
  770. /** @type {number} */
  771. this.startAt = 8170;
  772. /** @type {number} */
  773. this.counter = 0;
  774. /** @type {number} */
  775. this.rid = 0;
  776. /** @type {Map<number, FrameRequestCallback>} */
  777. this.funcs = new Map();
  778. const funcs = this.funcs;
  779. /** @type {FrameRequestCallback} */
  780. this.bCallback = this.mCallback.bind(this);
  781. this.pClear = () => funcs.clear();
  782. }
  783. /** @param {DOMHighResTimeStamp} highResTime */
  784. mCallback(highResTime) {
  785. this.rid = 0;
  786. Promise.resolve().then(this.pClear);
  787. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  788. }
  789. /** @param {FrameRequestCallback} f */
  790. request(f) {
  791. if (this.counter > 1e9) this.counter = 9;
  792. let cid = this.startAt + (++this.counter);
  793. this.funcs.set(cid, f);
  794. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  795. return cid;
  796. }
  797. /** @param {number} cid */
  798. cancel(cid) {
  799. cid = +cid;
  800. if (cid > 0) {
  801. if (cid <= this.startAt) {
  802. return cancelAnimationFrame(cid);
  803. }
  804. if (this.rid > 0) {
  805. this.funcs.delete(cid);
  806. if (this.funcs.size === 0) {
  807. cancelAnimationFrame(this.rid);
  808. this.rid = 0;
  809. }
  810. }
  811. }
  812. }
  813. }
  814.  
  815.  
  816.  
  817. NATIVE_CANVAS_ANIMATION && (() => {
  818.  
  819. HTMLCanvasElement.prototype.animate = animate;
  820.  
  821. let cid = setInterval(() => {
  822. HTMLCanvasElement.prototype.animate = animate;
  823. }, 1);
  824.  
  825. promiseForTamerTimeout.then(() => {
  826. clearInterval(cid)
  827. });
  828.  
  829. })();
  830.  
  831. CHANGE_appendChild && (() => {
  832.  
  833. HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  834. HTMLElement.prototype.appendChild = function (a) {
  835. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  836. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  837. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  838. node.__m848__ = 1;
  839. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  840. }
  841. }
  842. } else if (this && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  843. return this.appendChild73.apply(this, arguments);
  844. }
  845. if (a instanceof DocumentFragment) {
  846. if (a.firstElementChild === null) return a;
  847. }
  848. return this.appendChild73.apply(this, arguments)
  849. }
  850.  
  851.  
  852. })();
  853.  
  854.  
  855. FIX_schedulerInstanceInstance_ && (async () => {
  856.  
  857.  
  858. const schedulerInstanceInstance_ = await new Promise(resolve => {
  859.  
  860. let cid = setInterval(() => {
  861. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  862. if (t) {
  863.  
  864. clearInterval(cid);
  865. resolve(t);
  866. }
  867. }, 1);
  868. promiseForTamerTimeout.then(() => {
  869. resolve(null)
  870. });
  871. });
  872.  
  873. if (!schedulerInstanceInstance_) return;
  874.  
  875.  
  876. if (!ytEvented) {
  877. idleFrom = Date.now() + 2700;
  878. slowMode = false; // integrity
  879. }
  880.  
  881. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  882. if (checkOK) {
  883.  
  884. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  885.  
  886. let requestingFn = null;
  887. let requestingArgs = null;
  888. let requestingDT = 0;
  889.  
  890. // let timerId = null;
  891. const entries = [];
  892. const f = function () {
  893. requestingFn = this.fn;
  894. requestingArgs = [...arguments];
  895. requestingDT = Date.now();
  896. entries.push({
  897. fn: requestingFn,
  898. args: requestingArgs,
  899. t: requestingDT
  900. });
  901. // if (Date.now() < idleFrom) {
  902. // timerId = this.fn.apply(window, arguments);
  903. // } else {
  904. // timerId = this.fn.apply(window, arguments);
  905.  
  906. // }
  907. // timerId = 12377;
  908. return 12377;
  909. }
  910.  
  911.  
  912. const fakeFns = [
  913. f.bind({ fn: requestAnimationFrame }),
  914. f.bind({ fn: setInterval }),
  915. f.bind({ fn: setTimeout }),
  916. f.bind({ fn: requestIdleCallback })
  917. ]
  918.  
  919.  
  920.  
  921.  
  922. let timerResolve = null;
  923. setInterval(() => {
  924. timerResolve && timerResolve();
  925. timerResolve = null;
  926. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  927. }, 250);
  928.  
  929. let mzt = 0;
  930.  
  931. let fnSelectorProp = null;
  932.  
  933. schedulerInstanceInstance_.start = function () {
  934.  
  935. const mk1 = window.requestAnimationFrame
  936. const mk2 = window.setInterval
  937. const mk3 = window.setTimeout
  938. const mk4 = window.requestIdleCallback
  939.  
  940. const tThis = this['$$12378$$'] || this;
  941.  
  942.  
  943. window.requestAnimationFrame = fakeFns[0]
  944. window.setInterval = fakeFns[1]
  945. window.setTimeout = fakeFns[2]
  946. window.requestIdleCallback = fakeFns[3]
  947.  
  948. fnSelectorProp = null;
  949.  
  950.  
  951. tThis.start991.call(new Proxy(tThis, {
  952. get(target, prop, receiver) {
  953. if (prop === '$$12377$$') return true;
  954. if (prop === '$$12378$$') return target;
  955.  
  956. // console.log('get',prop)
  957. return target[prop]
  958. },
  959. set(target, prop, value, receiver) {
  960. // console.log('set', prop, value)
  961.  
  962.  
  963. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  964. if (value === 12377 && fnSelectorProp) {
  965.  
  966. const originalSelection = target[fnSelectorProp];
  967. const timerIdProp = prop;
  968.  
  969. /*
  970.  
  971.  
  972. case 1:
  973. var a = this.K;
  974. this.g = this.I ? window.requestIdleCallback(a, {
  975. timeout: 3E3
  976. }) : window.setTimeout(a, ma);
  977. break;
  978. case 2:
  979. this.g = window.setTimeout(this.M, this.N);
  980. break;
  981. case 3:
  982. this.g = window.requestAnimationFrame(this.L);
  983. break;
  984. case 4:
  985. this.g = window.setTimeout(this.J, 0)
  986. }
  987.  
  988. */
  989.  
  990. const doForegroundSlowMode = () => {
  991.  
  992. const tir = ++mzt;
  993. const f = requestingArgs[0];
  994.  
  995.  
  996. getForegroundPromise().then(() => {
  997.  
  998.  
  999. new Promise(r => {
  1000. timerResolve = r
  1001. }).then(() => {
  1002. if (target[timerIdProp] === -tir) f();
  1003. });
  1004.  
  1005. })
  1006.  
  1007. target[fnSelectorProp] = 931;
  1008. target[prop] = -tir;
  1009. }
  1010.  
  1011. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  1012. if (slowMode && !(requestingArgs[1] > 250)) {
  1013.  
  1014. doForegroundSlowMode();
  1015.  
  1016. } else {
  1017. target[prop] = setTimeout.apply(window, requestingArgs);
  1018.  
  1019. }
  1020.  
  1021. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  1022.  
  1023. if (slowMode) {
  1024.  
  1025. doForegroundSlowMode();
  1026.  
  1027. } else {
  1028. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  1029. }
  1030.  
  1031.  
  1032. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  1033.  
  1034. const f = requestingArgs[0];
  1035. const tir = ++mzt;
  1036. Promise.resolve().then(() => {
  1037. if (target[timerIdProp] === -tir) f();
  1038. });
  1039. target[fnSelectorProp] = 930;
  1040. target[prop] = -tir;
  1041.  
  1042. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  1043.  
  1044. doForegroundSlowMode();
  1045.  
  1046. } else {
  1047. // target[prop] = timerId;
  1048. target[fnSelectorProp] = 0;
  1049. target[prop] = 0;
  1050. }
  1051.  
  1052. // *****
  1053. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  1054. } else {
  1055.  
  1056. target[prop] = value;
  1057. }
  1058. // console.log('set',prop,value)
  1059. return true;
  1060. }
  1061. }));
  1062.  
  1063. fnSelectorProp = null;
  1064.  
  1065.  
  1066. window.requestAnimationFrame = mk1;
  1067. window.setInterval = mk2
  1068. window.setTimeout = mk3
  1069. window.requestIdleCallback = mk4;
  1070.  
  1071.  
  1072.  
  1073. }
  1074.  
  1075. schedulerInstanceInstance_.start.toString = function () {
  1076. return schedulerInstanceInstance_.start991.toString();
  1077. }
  1078.  
  1079. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  1080. // prop,
  1081. // value: schedulerInstanceInstance_[prop],
  1082. // type: typeof schedulerInstanceInstance_[prop]
  1083.  
  1084. // }));
  1085. // console.log('fcc', funcNames)
  1086.  
  1087.  
  1088.  
  1089.  
  1090. }
  1091. })();
  1092.  
  1093.  
  1094. FIX_yt_player && (async () => {
  1095.  
  1096.  
  1097.  
  1098. const rafHub = new RAFHub();
  1099.  
  1100.  
  1101. const _yt_player = await new Promise(resolve => {
  1102.  
  1103. let cid = setInterval(() => {
  1104. let t = (((window || 0)._yt_player || 0) || 0);
  1105. if (t) {
  1106.  
  1107. clearInterval(cid);
  1108. resolve(t);
  1109. }
  1110. }, 1);
  1111.  
  1112. promiseForTamerTimeout.then(() => {
  1113. resolve(null)
  1114. });
  1115.  
  1116. });
  1117.  
  1118.  
  1119.  
  1120. if (!_yt_player || typeof _yt_player !== 'object') return;
  1121.  
  1122.  
  1123.  
  1124. let keyZq = getZq(_yt_player);
  1125. let keyVG = getVG(_yt_player);
  1126. let buildVG = _yt_player[keyVG];
  1127. let u = new buildVG({
  1128. api: {},
  1129. element: document.createElement('noscript'),
  1130. api: {},
  1131. hide: () => { }
  1132. }, 250);
  1133. const timeDelayConstructor = u.delay.constructor; // g.br
  1134. // console.log(keyVG, u)
  1135. // buildVG.prototype.show = function(){}
  1136. // _yt_player[keyZq] = g.k
  1137.  
  1138. if (!keyZq) return;
  1139.  
  1140.  
  1141. const g = _yt_player
  1142. let k = keyZq
  1143.  
  1144. const gk = g[k];
  1145. if (typeof gk !== 'function') return;
  1146.  
  1147. let dummyObject = new gk;
  1148. let nilFunc = () => { };
  1149.  
  1150. let nilObj = {};
  1151.  
  1152. // console.log(1111111111)
  1153.  
  1154. let keyBoolD = '';
  1155. let keyWindow = '';
  1156. let keyFuncC = '';
  1157. let keyCidj = '';
  1158.  
  1159. for (const [t, y] of Object.entries(dummyObject)) {
  1160. if (y instanceof Window) keyWindow = t;
  1161. }
  1162.  
  1163. const dummyObjectProxyHandler = {
  1164. get(target, prop) {
  1165. let v = target[prop]
  1166. if (v instanceof Window && !keyWindow) {
  1167. keyWindow = t;
  1168. }
  1169. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  1170. if (prop === keyWindow) y = {
  1171. requestAnimationFrame(f) {
  1172. return 3;
  1173. },
  1174. cancelAnimationFrame() {
  1175.  
  1176. }
  1177. }
  1178. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  1179. keyFuncC = prop;
  1180. }
  1181. // console.log('[get]', prop, typeof target[prop])
  1182.  
  1183.  
  1184. return y;
  1185. },
  1186. set(target, prop, value) {
  1187.  
  1188. if (typeof value === 'boolean' && !keyBoolD) {
  1189. keyBoolD = prop;
  1190. }
  1191. if (typeof value === 'number' && !keyCidj && value >= 2) {
  1192. keyCidj = prop;
  1193. }
  1194.  
  1195. // console.log('[set]', prop, value)
  1196. target[prop] = value
  1197.  
  1198. return true;
  1199. }
  1200. };
  1201.  
  1202. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  1203.  
  1204. /*
  1205. console.log({
  1206. keyBoolD,
  1207. keyFuncC,
  1208. keyWindow,
  1209. keyCidj
  1210. })
  1211.  
  1212. console.log( dummyObject[keyFuncC])
  1213.  
  1214.  
  1215. console.log(2222222222)
  1216. */
  1217.  
  1218.  
  1219.  
  1220.  
  1221. g[k].prototype.start = function () {
  1222. this.stop();
  1223. this[keyBoolD] = true;
  1224. this[keyCidj] = rafHub.request(this[keyFuncC]);
  1225. }
  1226. ;
  1227. g[k].prototype.stop = function () {
  1228. if (this.isActive() && this[keyCidj]) {
  1229. rafHub.cancel(this[keyCidj]);
  1230. }
  1231. this[keyCidj] = null
  1232. }
  1233.  
  1234.  
  1235. /*
  1236. g[k].start = function() {
  1237. this.stop();
  1238. this.D = true;
  1239. var a = requestAnimationFrame
  1240. , b = cancelAnimationFrame;
  1241. this.j = a.call(this.B, this.C)
  1242. }
  1243. ;
  1244. g[k].stop = function() {
  1245. if (this.isActive()) {
  1246. var a = requestAnimationFrame
  1247. , b = cancelAnimationFrame;
  1248. b.call(this.B, this.j)
  1249. }
  1250. this.j = null
  1251. }
  1252. */
  1253.  
  1254.  
  1255.  
  1256. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  1257.  
  1258. if (keyzo) {
  1259.  
  1260. k = keyzo
  1261.  
  1262. const setCSSProp = (() => {
  1263.  
  1264. let animationPropCapable = false;
  1265. try {
  1266. const propName = "--ibxpf"
  1267. const value = 2;
  1268. const keyframes = [{
  1269. [propName]: value
  1270. }];
  1271. window.CSS.registerProperty({
  1272. name: "--ibxpf",
  1273. syntax: "<number>",
  1274. inherits: false,
  1275. initialValue: 1,
  1276. });
  1277. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  1278. } catch (e) { }
  1279.  
  1280. if (!animationPropCapable) {
  1281. return (element, cssProp, value) => {
  1282.  
  1283.  
  1284. element.style.setProperty(cssProp, value);
  1285.  
  1286. }
  1287. }
  1288.  
  1289. const propMaps = new Map();
  1290.  
  1291. function setCustomCSSProperty(element, propName, value) {
  1292. let wm = propMaps.get(propName);
  1293. if (!wm) {
  1294.  
  1295. try {
  1296. window.CSS.registerProperty({
  1297. name: propName,
  1298. syntax: "*",
  1299. inherits: false
  1300. });
  1301. } catch (e) {
  1302. console.warn(e);
  1303. }
  1304.  
  1305. propMaps.set(propName, (wm = new WeakMap()));
  1306. }
  1307.  
  1308. // Create the animation keyframes with the provided property and value
  1309. const keyframes = [{
  1310. [propName]: value
  1311. }];
  1312.  
  1313. let currentAnimation = wm.get(element);
  1314. if (currentAnimation) {
  1315.  
  1316. currentAnimation.effect.setKeyframes(keyframes);
  1317.  
  1318. } else {
  1319.  
  1320.  
  1321.  
  1322. // Set the animation on the element and immediately pause it
  1323. const animation = animate.call(element, keyframes, {
  1324. duration: 1, // Very short duration as we just want to set the value
  1325. fill: 'forwards',
  1326. iterationStart: 1,
  1327. iterations: 2,
  1328. direction: 'alternate'
  1329. });
  1330.  
  1331.  
  1332. // animation.currentTime = 1;
  1333. animation.pause();
  1334.  
  1335. wm.set(element, animation);
  1336.  
  1337.  
  1338. }
  1339.  
  1340. }
  1341.  
  1342. return setCustomCSSProperty;
  1343.  
  1344.  
  1345. })();
  1346.  
  1347.  
  1348. const attrUpdateFn = g[k];
  1349. g['$$original$$' + k] = attrUpdateFn;
  1350. g[k] = function (a, b, c) {
  1351.  
  1352. // console.log(140000, a, b, c);
  1353.  
  1354. let transformType = '';
  1355. let transformValue = 0;
  1356. let transformUnit = '';
  1357.  
  1358. let byPassDefaultFn = false;
  1359. if (b === "transform" && typeof c === 'string') {
  1360.  
  1361. byPassDefaultFn = true;
  1362.  
  1363. const aStyle = a.style;
  1364.  
  1365. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  1366. if (!(a instanceof HTMLElement)) return;
  1367. if (c.length === 0) {
  1368.  
  1369. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  1370. let p = c.substring(7, c.length - 1);
  1371. let q = p.length >= 1 ? parseFloat(p) : -1;
  1372. if (q > -1e-5 && q < 1 + 1e-5) {
  1373. transformType = 'scalex'
  1374. transformValue = q;
  1375. transformUnit = '';
  1376. }
  1377.  
  1378.  
  1379. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  1380.  
  1381. let p = c.substring(11, c.length - 3);
  1382. let q = p.length >= 1 ? parseFloat(p) : NaN;
  1383.  
  1384. if (typeof q === 'number' && !isNaN(q)) {
  1385. transformType = 'translateX'
  1386. transformValue = q;
  1387. transformUnit = 'px';
  1388. }
  1389.  
  1390.  
  1391. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  1392. let p = c.substring(7, c.length - 1);
  1393. let q = p.length >= 1 ? parseFloat(p) : -1;
  1394. if (q > -1e-5 && q < 1 + 1e-5) {
  1395. transformType = 'scaley'
  1396. transformValue = q;
  1397. transformUnit = '';
  1398. }
  1399.  
  1400.  
  1401. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  1402.  
  1403. let p = c.substring(11, c.length - 3);
  1404. let q = p.length >= 1 ? parseFloat(p) : NaN;
  1405.  
  1406. if (typeof q === 'number' && !isNaN(q)) {
  1407. transformType = 'translateY'
  1408. transformValue = q;
  1409. transformUnit = 'px';
  1410. }
  1411.  
  1412.  
  1413. }
  1414.  
  1415. if (transformType) {
  1416.  
  1417. if (transformType === 'scalex' || transformType === 'scaley') {
  1418.  
  1419. const q = transformValue;
  1420.  
  1421.  
  1422. /*
  1423.  
  1424. let vz = Math.round(steppingScaleN * q);
  1425. const customPropName = '--discrete-'+transformType
  1426.  
  1427. const currentValue = aStyle.getPropertyValue(customPropName);
  1428.  
  1429. const transform = (aStyle.transform || '');
  1430. const u = transform.includes(customPropName)
  1431. if (`${currentValue}` === `${vz}`) {
  1432. if (u) return;
  1433. }
  1434.  
  1435.  
  1436. setCSSProp(a,customPropName, vz);
  1437. // aStyle.setProperty(customPropName, vz)
  1438.  
  1439. let ck = '';
  1440.  
  1441. if (c.length === 9) ck = c;
  1442. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  1443.  
  1444. if (ck && beforeMq !== ck) {
  1445. aStyle.setProperty('--mq-transform', ck);
  1446. }
  1447.  
  1448. if (u) return;
  1449. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  1450.  
  1451.  
  1452.  
  1453. */
  1454.  
  1455. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  1456.  
  1457. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  1458. const cv = aStyle.transform;
  1459.  
  1460. // console.log(157, cv,c)
  1461.  
  1462. if (c === cv) return;
  1463. // console.log(257, cv,c)
  1464.  
  1465. aStyle.transform = c;
  1466.  
  1467. // return;
  1468.  
  1469. } else if (transformType === 'translateX' || transformType === 'translateY') {
  1470.  
  1471. const q = transformValue;
  1472.  
  1473. /*
  1474.  
  1475. let vz = q.toFixed(1);
  1476. const customPropName = '--discrete-'+transformType
  1477.  
  1478. const aStyle = a.style;
  1479. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  1480.  
  1481.  
  1482. const transform = (aStyle.transform || '');
  1483. const u = transform.includes(customPropName)
  1484. if (parseFloat(currentValue).toFixed(1) === vz) {
  1485. if (u) return;
  1486. }
  1487.  
  1488. setCSSProp(a,customPropName, vz + 'px');
  1489. // aStyle.setProperty(customPropName, vz + 'px')
  1490.  
  1491. let ck = '';
  1492. if (c.length === 15) ck = c;
  1493. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  1494.  
  1495. if (ck && beforeMq !== ck) {
  1496. aStyle.setProperty('--mq-transform', ck);
  1497. }
  1498.  
  1499. if (u) return;
  1500. c = `${transformType}(var(--discrete-${transformType}))`;
  1501.  
  1502. */
  1503.  
  1504.  
  1505. const vz = +q.toFixed(1);
  1506.  
  1507. c = `${transformType}(${vz}${transformUnit})`
  1508. const cv = aStyle.transform;
  1509.  
  1510. // console.log(158, cv,c)
  1511.  
  1512. if (c === cv) return;
  1513. // console.log(258, cv,c)
  1514.  
  1515. aStyle.transform = c;
  1516.  
  1517. // return;
  1518.  
  1519. } else {
  1520. throw new Error();
  1521. }
  1522.  
  1523. } else {
  1524. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  1525. const cv = aStyle.transform
  1526. if (!c && !cv) return;
  1527. else if (c === cv) return;
  1528. aStyle.transform = c;
  1529. // return;
  1530. }
  1531.  
  1532. } else if (b === "display") {
  1533.  
  1534. const cv = a.style.display;
  1535. if (!cv && !c) return;
  1536. if (cv === c) return;
  1537.  
  1538.  
  1539. } else if (b === "width") {
  1540.  
  1541. const cv = a.style.width;
  1542. if (!cv && !c) return;
  1543. if (cv === c) return;
  1544.  
  1545. }
  1546.  
  1547. // console.log(130000, a, b, c);
  1548.  
  1549. if (byPassDefaultFn) return;
  1550. return attrUpdateFn.call(this, a, b, c);
  1551. }
  1552.  
  1553.  
  1554. /*
  1555.  
  1556. g.zo = function(a, b, c) {
  1557. if ("string" === typeof b)
  1558. (b = yo(a, b)) && (a.style[b] = c);
  1559. else
  1560. for (var d in b) {
  1561. c = a;
  1562. var e = b[d]
  1563. , f = yo(c, d);
  1564. f && (c.style[f] = e)
  1565. }
  1566. }
  1567.  
  1568.  
  1569. */
  1570.  
  1571.  
  1572. }
  1573.  
  1574.  
  1575.  
  1576. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  1577.  
  1578. if (keyuG) {
  1579.  
  1580. k = keyuG;
  1581.  
  1582. const gk = g[k];
  1583. const gkp = gk.prototype;
  1584.  
  1585.  
  1586. /** @type { Map<string, WeakMap<any, any>> } */
  1587. const ntLogs = new Map();
  1588.  
  1589. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  1590.  
  1591. gkp.updateValue31 = gkp.updateValue;
  1592. gkp.updateValue = function (a, b) {
  1593. if (typeof a !== 'string') return this.updateValue31(a, b);
  1594.  
  1595. const element = this.element;
  1596. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  1597.  
  1598. let ntLog = ntLogs.get(a);
  1599. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  1600.  
  1601. let cache = ntLog.get(element);
  1602. if (cache && cache.value === b) {
  1603. return;
  1604. }
  1605. if (!cache) {
  1606. this.__oldValueByUpdateValue__ = null;
  1607. ntLog.set(element, cache = { value: b });
  1608. } else {
  1609. this.__oldValueByUpdateValue__ = cache.value;
  1610. cache.value = b;
  1611. }
  1612.  
  1613.  
  1614. return this.updateValue31(a, b);
  1615. }
  1616.  
  1617.  
  1618. /*
  1619. g.k.update = function(a) {
  1620. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  1621. c = c.value,
  1622. this.updateValue(c, a[c])
  1623. }
  1624. ;
  1625. g.k.updateValue = function(a, b) {
  1626. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  1627. }
  1628. */
  1629.  
  1630.  
  1631. }
  1632.  
  1633.  
  1634. }
  1635.  
  1636.  
  1637.  
  1638.  
  1639. })();
  1640.  
  1641.  
  1642.  
  1643. FIX_Animation_n_timeline && (async () => {
  1644.  
  1645.  
  1646. const timeline = await new Promise(resolve => {
  1647.  
  1648. let cid = setInterval(() => {
  1649. let t = (((document || 0).timeline || 0) || 0);
  1650. if (t && typeof t._play === 'function') {
  1651.  
  1652. clearInterval(cid);
  1653. resolve(t);
  1654. }
  1655. }, 1);
  1656.  
  1657. promiseForTamerTimeout.then(() => {
  1658. resolve(null)
  1659. });
  1660.  
  1661. });
  1662.  
  1663.  
  1664. const Animation = await new Promise(resolve => {
  1665.  
  1666. let cid = setInterval(() => {
  1667. let t = (((window || 0).Animation || 0) || 0);
  1668. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  1669.  
  1670. clearInterval(cid);
  1671. resolve(t);
  1672. }
  1673. }, 1);
  1674.  
  1675. promiseForTamerTimeout.then(() => {
  1676. resolve(null)
  1677. });
  1678.  
  1679. });
  1680.  
  1681. if (!timeline) return;
  1682. if (!Animation) return;
  1683.  
  1684. const aniProto = Animation.prototype;
  1685.  
  1686. const getXroto = (x) => {
  1687. try {
  1688. return x.__proto__;
  1689. } catch (e) { }
  1690. return null;
  1691. }
  1692. const timProto = getXroto(timeline);
  1693. if (!timProto) return;
  1694. if (
  1695. (
  1696. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  1697. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  1698. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  1699. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  1700. )
  1701.  
  1702. ) {
  1703.  
  1704. timProto.nofCQ = 1;
  1705. aniProto.nofYH = 1;
  1706.  
  1707. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  1708.  
  1709.  
  1710. /*
  1711. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  1712. return c._updatePromises();
  1713. });
  1714. */
  1715.  
  1716. const p = Array.prototype.filter;
  1717.  
  1718. let res = null;
  1719. Array.prototype.filter = function () {
  1720.  
  1721. res = this;
  1722. return this;
  1723.  
  1724. };
  1725.  
  1726. _updateAnimationsPromises.call({});
  1727.  
  1728. Array.prototype.filter = p;
  1729.  
  1730. if (res && typeof res.length === 'number') {
  1731. /** @type {any[]} */
  1732. const _res = res;
  1733. return _res;
  1734. }
  1735.  
  1736.  
  1737. return null;
  1738.  
  1739.  
  1740.  
  1741.  
  1742. })(timProto._updateAnimationsPromises);
  1743.  
  1744. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  1745.  
  1746. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  1747.  
  1748. aniProto._updatePromises31 = aniProto._updatePromises;
  1749.  
  1750. /*
  1751. aniProto._updatePromises = function(){
  1752. console.log('eff',this._oldPlayState, this.playState)
  1753. return this._updatePromises31.apply(this, arguments)
  1754. }
  1755. */
  1756.  
  1757. aniProto._updatePromises = function () {
  1758. var oldPlayState = this._oldPlayState;
  1759. var newPlayState = this.playState;
  1760. // console.log('ett', oldPlayState, newPlayState)
  1761. if (newPlayState !== oldPlayState) {
  1762. this._oldPlayState = newPlayState;
  1763. if (this._readyPromise) {
  1764. if ("idle" == newPlayState) {
  1765. this._rejectReadyPromise();
  1766. this._readyPromise = void 0;
  1767. } else if ("pending" == oldPlayState) {
  1768. this._resolveReadyPromise();
  1769. } else if ("pending" == newPlayState) {
  1770. this._readyPromise = void 0;
  1771. }
  1772. }
  1773. if (this._finishedPromise) {
  1774. if ("idle" == newPlayState) {
  1775. this._rejectFinishedPromise();
  1776. this._finishedPromise = void 0;
  1777. } else if ("finished" == newPlayState) {
  1778. this._resolveFinishedPromise();
  1779. } else if ("finished" == oldPlayState) {
  1780. this._finishedPromise = void 0;
  1781. }
  1782. }
  1783. }
  1784. return this._readyPromise || this._finishedPromise;
  1785. };
  1786.  
  1787.  
  1788. let restartWebAnimationsNextTickFlag = false;
  1789.  
  1790. const looperMethodT = () => {
  1791.  
  1792. const runnerFn = (hRes) => {
  1793. var b = timeline;
  1794. b.currentTime = hRes;
  1795. b._discardAnimations();
  1796. if (0 == b._animations.length) {
  1797. restartWebAnimationsNextTickFlag = false;
  1798. } else {
  1799. getRafPromiseForTickers().then(runnerFn);
  1800. }
  1801. }
  1802.  
  1803. const restartWebAnimationsNextTick = () => {
  1804. if (!restartWebAnimationsNextTickFlag) {
  1805. restartWebAnimationsNextTickFlag = true;
  1806. getRafPromiseForTickers().then(runnerFn);
  1807. }
  1808. }
  1809.  
  1810. return { restartWebAnimationsNextTick }
  1811. };
  1812.  
  1813.  
  1814. const looperMethodN = () => {
  1815.  
  1816. const acs = document.createElement('a-f');
  1817. acs.id = 'a-f';
  1818.  
  1819. const style = document.createElement('style');
  1820. style.textContent = `
  1821. @keyFrames aF1 {
  1822. 0% {
  1823. order: 0;
  1824. }
  1825. 100% {
  1826. order: 6;
  1827. }
  1828. }
  1829. #a-f[id] {
  1830. visibility: collapse !important;
  1831. position: fixed !important;
  1832. top: -100px !important;
  1833. left: -100px !important;
  1834. margin:0 !important;
  1835. padding:0 !important;
  1836. outline:0 !important;
  1837. border:0 !important;
  1838. z-index:-1 !important;
  1839. width: 0px !important;
  1840. height: 0px !important;
  1841. contain: strict !important;
  1842. pointer-events: none !important;
  1843. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  1844. }
  1845. `;
  1846. (document.head || document.documentElement).appendChild(style);
  1847.  
  1848. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  1849.  
  1850. const _onanimationiteration = function (evt) {
  1851. const hRes = evt.timeStamp;
  1852. var b = timeline;
  1853. b.currentTime = hRes;
  1854. b._discardAnimations();
  1855. if (0 == b._animations.length) {
  1856. restartWebAnimationsNextTickFlag = false;
  1857. acs.onanimationiteration = null;
  1858. } else {
  1859. acs.onanimationiteration = _onanimationiteration;
  1860. }
  1861.  
  1862. }
  1863.  
  1864.  
  1865.  
  1866. const restartWebAnimationsNextTick = () => {
  1867. if (!restartWebAnimationsNextTickFlag) {
  1868. restartWebAnimationsNextTickFlag = true;
  1869. acs.onanimationiteration = _onanimationiteration;
  1870.  
  1871. }
  1872. }
  1873.  
  1874. return { restartWebAnimationsNextTick }
  1875. };
  1876.  
  1877.  
  1878.  
  1879. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  1880.  
  1881. timProto._play = function (c) {
  1882. c = new Animation(c, this);
  1883. this._animations.push(c);
  1884. restartWebAnimationsNextTick();
  1885. c._updatePromises();
  1886. c._animation.play();
  1887. c._updatePromises();
  1888. return c
  1889. }
  1890.  
  1891. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  1892. originalAnimationsWithPromises.length = 0;
  1893. originalAnimationsWithPromises.push = null;
  1894. originalAnimationsWithPromises.splice = null;
  1895. originalAnimationsWithPromises.slice = null;
  1896. originalAnimationsWithPromises.indexOf = null;
  1897. originalAnimationsWithPromises.unshift = null;
  1898. originalAnimationsWithPromises.shift = null;
  1899. originalAnimationsWithPromises.pop = null;
  1900. originalAnimationsWithPromises.filter = null;
  1901. originalAnimationsWithPromises.forEach = null;
  1902. originalAnimationsWithPromises.map = null;
  1903.  
  1904.  
  1905.  
  1906. const _updateAnimationsPromises = () => {
  1907. animationsWithPromisesMap.forEach(c => {
  1908. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  1909. })
  1910. /*
  1911. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  1912. return c._updatePromises();
  1913. });
  1914. */
  1915. }
  1916.  
  1917. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  1918.  
  1919. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  1920.  
  1921.  
  1922. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  1923. aniProto.__finished_native_get__ = pdFinished.get;
  1924. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  1925.  
  1926.  
  1927. Object.defineProperty(aniProto, 'finished', {
  1928. get() {
  1929. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  1930. this._finishedPromise = new Promise((resolve, reject) => {
  1931. this._resolveFinishedPromise = function () {
  1932. resolve(this)
  1933. };
  1934. this._rejectFinishedPromise = function () {
  1935. reject({
  1936. type: DOMException.ABORT_ERR,
  1937. name: "AbortError"
  1938. })
  1939. };
  1940. }),
  1941. "finished" == this.playState && this._resolveFinishedPromise());
  1942. return this._finishedPromise
  1943. },
  1944. set: undefined,
  1945. enumerable: true,
  1946. configurable: true
  1947. });
  1948.  
  1949. }
  1950.  
  1951.  
  1952.  
  1953. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  1954. aniProto.__ready_native_get__ = pdReady.get;
  1955. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  1956.  
  1957. Object.defineProperty(aniProto, 'ready', {
  1958. get() {
  1959. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  1960. this._readyPromise = new Promise((resolve, reject) => {
  1961. this._resolveReadyPromise = function () {
  1962. resolve(this)
  1963. };
  1964. this._rejectReadyPromise = function () {
  1965. reject({
  1966. type: DOMException.ABORT_ERR,
  1967. name: "AbortError"
  1968. })
  1969. };
  1970. }),
  1971. "pending" !== this.playState && this._resolveReadyPromise());
  1972. return this._readyPromise
  1973. },
  1974. set: undefined,
  1975. enumerable: true,
  1976. configurable: true
  1977. });
  1978.  
  1979. }
  1980.  
  1981.  
  1982.  
  1983.  
  1984. /*
  1985.  
  1986.  
  1987. function f(c) {
  1988. var b = v.timeline;
  1989. b.currentTime = c;
  1990. b._discardAnimations();
  1991. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  1992. }
  1993. var h = window.requestAnimationFrame;
  1994. window.requestAnimationFrame = function(c) {
  1995. return h(function(b) {
  1996. v.timeline._updateAnimationsPromises();
  1997. c(b);
  1998. v.timeline._updateAnimationsPromises()
  1999. })
  2000. }
  2001. ;
  2002. v.AnimationTimeline = function() {
  2003. this._animations = [];
  2004. this.currentTime = void 0
  2005. }
  2006. ;
  2007. v.AnimationTimeline.prototype = {
  2008. getAnimations: function() {
  2009. this._discardAnimations();
  2010. return this._animations.slice()
  2011. },
  2012. _updateAnimationsPromises: function() {
  2013. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  2014. return c._updatePromises()
  2015. })
  2016. },
  2017. _discardAnimations: function() {
  2018. this._updateAnimationsPromises();
  2019. this._animations = this._animations.filter(function(c) {
  2020. return "finished" != c.playState && "idle" != c.playState
  2021. })
  2022. },
  2023. _play: function(c) {
  2024. c = new v.Animation(c,this);
  2025. this._animations.push(c);
  2026. v.restartWebAnimationsNextTick();
  2027. c._updatePromises();
  2028. c._animation.play();
  2029. c._updatePromises();
  2030. return c
  2031. },
  2032. play: function(c) {
  2033. c && c.remove();
  2034. return this._play(c)
  2035. }
  2036. };
  2037. var d = !1;
  2038. v.restartWebAnimationsNextTick = function() {
  2039. d || (d = !0,
  2040. requestAnimationFrame(f))
  2041. }
  2042. ;
  2043. var a = new v.AnimationTimeline;
  2044. v.timeline = a;
  2045. try {
  2046. Object.defineProperty(window.document, "timeline", {
  2047. configurable: !0,
  2048. get: function() {
  2049. return a
  2050. }
  2051. })
  2052. } catch (c) {}
  2053. try {
  2054. window.document.timeline = a
  2055. } catch (c) {}
  2056.  
  2057. */
  2058.  
  2059.  
  2060.  
  2061. /*
  2062.  
  2063. var g = window.getComputedStyle;
  2064. Object.defineProperty(window, "getComputedStyle", {
  2065. configurable: !0,
  2066. enumerable: !0,
  2067. value: function() {
  2068. v.timeline._updateAnimationsPromises();
  2069. var e = g.apply(this, arguments);
  2070. h() && (e = g.apply(this, arguments));
  2071. v.timeline._updateAnimationsPromises();
  2072. return e
  2073. }
  2074. });
  2075.  
  2076. */
  2077.  
  2078.  
  2079.  
  2080.  
  2081. }
  2082.  
  2083.  
  2084.  
  2085.  
  2086. })();
  2087.  
  2088.  
  2089.  
  2090. });
  2091.  
  2092.  
  2093. setupEvents();
  2094.  
  2095.  
  2096.  
  2097. if (isMainWindow) {
  2098.  
  2099. console.groupCollapsed(
  2100. "%cYouTube JS Engine Tamer",
  2101. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  2102. );
  2103.  
  2104.  
  2105.  
  2106. console.log("Script is loaded.");
  2107. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  2108.  
  2109. console.log("This script is experimental and subject to further changes.");
  2110.  
  2111. console.log("This might boost your YouTube performance.");
  2112.  
  2113. console.log("CAUTION: This might break your YouTube.");
  2114.  
  2115.  
  2116. if (prepareLogs.length >= 1) {
  2117. console.log(" =========================================================================== ");
  2118.  
  2119. for (const msg of prepareLogs) {
  2120. console.log(msg)
  2121. }
  2122.  
  2123. console.log(" =========================================================================== ");
  2124. }
  2125.  
  2126. console.groupEnd();
  2127.  
  2128. }
  2129.  
  2130.  
  2131. })();