YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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