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.11
  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 = frameId;
  688. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  689. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  690. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  691. n.appendChild(frame);
  692. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  693. const root = document.documentElement;
  694. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  695. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  696.  
  697. removeIframeFn = (setTimeout) => {
  698. const removeIframeOnDocumentReady = (e) => {
  699. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  700. win = null;
  701. const m = n;
  702. n = null;
  703. setTimeout(() => m.remove(), 200);
  704. }
  705. if (document.readyState !== 'loading') {
  706. removeIframeOnDocumentReady();
  707. } else {
  708. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  709. }
  710. }
  711. }
  712. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  713. const fc = frame.contentWindow;
  714. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  715. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  716. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  717. for (let k in res) res[k] = res[k].bind(win); // necessary
  718. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  719. res.animate = fc.HTMLElement.prototype.animate;
  720. return res;
  721. } catch (e) {
  722. console.warn(e);
  723. return null;
  724. }
  725. };
  726.  
  727.  
  728. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  729.  
  730. cleanContext(window).then(__CONTEXT__ => {
  731. if (!__CONTEXT__) return null;
  732.  
  733. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle } = __CONTEXT__;
  734.  
  735.  
  736.  
  737. let rafPromiseForTickers = null;
  738.  
  739. const getRafPromiseForTickers = () => rafPromiseForTickers || (rafPromiseForTickers = new Promise(resolve => {
  740. requestAnimationFrame(hRes => {
  741. rafPromiseForTickers = null;
  742. resolve(hRes);
  743. });
  744. }));
  745.  
  746. const getForegroundPromise = () => {
  747. if (document.visibilityState === 'visible') {
  748. return Promise.resolve();
  749. } else {
  750. return getRafPromiseForTickers();
  751. }
  752. };
  753.  
  754. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  755. setTimeout(() => {
  756. NO_PRELOAD_GENERATE_204_BYPASS = true;
  757. }, 1270);
  758. });
  759.  
  760. const promiseForTamerTimeout = new Promise(resolve => {
  761. promiseForCustomYtElementsReady.then(() => {
  762. customElements.whenDefined('ytd-app').then(() => {
  763. setTimeout(resolve, 1200);
  764. });
  765. });
  766. setTimeout(resolve, 3000);
  767. });
  768.  
  769.  
  770. class RAFHub {
  771. constructor() {
  772. /** @type {number} */
  773. this.startAt = 8170;
  774. /** @type {number} */
  775. this.counter = 0;
  776. /** @type {number} */
  777. this.rid = 0;
  778. /** @type {Map<number, FrameRequestCallback>} */
  779. this.funcs = new Map();
  780. const funcs = this.funcs;
  781. /** @type {FrameRequestCallback} */
  782. this.bCallback = this.mCallback.bind(this);
  783. this.pClear = () => funcs.clear();
  784. }
  785. /** @param {DOMHighResTimeStamp} highResTime */
  786. mCallback(highResTime) {
  787. this.rid = 0;
  788. Promise.resolve().then(this.pClear);
  789. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  790. }
  791. /** @param {FrameRequestCallback} f */
  792. request(f) {
  793. if (this.counter > 1e9) this.counter = 9;
  794. let cid = this.startAt + (++this.counter);
  795. this.funcs.set(cid, f);
  796. if (this.rid === 0) this.rid = requestAnimationFrame(this.bCallback);
  797. return cid;
  798. }
  799. /** @param {number} cid */
  800. cancel(cid) {
  801. cid = +cid;
  802. if (cid > 0) {
  803. if (cid <= this.startAt) {
  804. return cancelAnimationFrame(cid);
  805. }
  806. if (this.rid > 0) {
  807. this.funcs.delete(cid);
  808. if (this.funcs.size === 0) {
  809. cancelAnimationFrame(this.rid);
  810. this.rid = 0;
  811. }
  812. }
  813. }
  814. }
  815. }
  816.  
  817.  
  818.  
  819. NATIVE_CANVAS_ANIMATION && (() => {
  820.  
  821. HTMLCanvasElement.prototype.animate = animate;
  822.  
  823. let cid = setInterval(() => {
  824. HTMLCanvasElement.prototype.animate = animate;
  825. }, 1);
  826.  
  827. promiseForTamerTimeout.then(() => {
  828. clearInterval(cid)
  829. });
  830.  
  831. })();
  832.  
  833. CHANGE_appendChild && (() => {
  834.  
  835. HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  836. HTMLElement.prototype.appendChild = function (a) {
  837.  
  838. if (this instanceof HTMLElement) {
  839. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  840. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  841. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  842. node.__m848__ = 1;
  843. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  844. }
  845. }
  846. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  847. return this.appendChild73.apply(this, arguments);
  848. }
  849. if (a instanceof DocumentFragment) {
  850. if (a.firstElementChild === null) return a;
  851. }
  852. }
  853.  
  854. return this.appendChild73.apply(this, arguments)
  855. }
  856.  
  857.  
  858. })();
  859.  
  860.  
  861. FIX_schedulerInstanceInstance_ && (async () => {
  862.  
  863.  
  864. const schedulerInstanceInstance_ = await new Promise(resolve => {
  865.  
  866. let cid = setInterval(() => {
  867. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  868. if (t) {
  869.  
  870. clearInterval(cid);
  871. resolve(t);
  872. }
  873. }, 1);
  874. promiseForTamerTimeout.then(() => {
  875. resolve(null)
  876. });
  877. });
  878.  
  879. if (!schedulerInstanceInstance_) return;
  880.  
  881.  
  882. if (!ytEvented) {
  883. idleFrom = Date.now() + 2700;
  884. slowMode = false; // integrity
  885. }
  886.  
  887. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  888. if (checkOK) {
  889.  
  890. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  891.  
  892. let requestingFn = null;
  893. let requestingArgs = null;
  894. let requestingDT = 0;
  895.  
  896. // let timerId = null;
  897. const entries = [];
  898. const f = function () {
  899. requestingFn = this.fn;
  900. requestingArgs = [...arguments];
  901. requestingDT = Date.now();
  902. entries.push({
  903. fn: requestingFn,
  904. args: requestingArgs,
  905. t: requestingDT
  906. });
  907. // if (Date.now() < idleFrom) {
  908. // timerId = this.fn.apply(window, arguments);
  909. // } else {
  910. // timerId = this.fn.apply(window, arguments);
  911.  
  912. // }
  913. // timerId = 12377;
  914. return 12377;
  915. }
  916.  
  917.  
  918. const fakeFns = [
  919. f.bind({ fn: requestAnimationFrame }),
  920. f.bind({ fn: setInterval }),
  921. f.bind({ fn: setTimeout }),
  922. f.bind({ fn: requestIdleCallback })
  923. ]
  924.  
  925.  
  926.  
  927.  
  928. let timerResolve = null;
  929. setInterval(() => {
  930. timerResolve && timerResolve();
  931. timerResolve = null;
  932. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  933. }, 250);
  934.  
  935. let mzt = 0;
  936.  
  937. let fnSelectorProp = null;
  938.  
  939. schedulerInstanceInstance_.start = function () {
  940.  
  941. const mk1 = window.requestAnimationFrame
  942. const mk2 = window.setInterval
  943. const mk3 = window.setTimeout
  944. const mk4 = window.requestIdleCallback
  945.  
  946. const tThis = this['$$12378$$'] || this;
  947.  
  948.  
  949. window.requestAnimationFrame = fakeFns[0]
  950. window.setInterval = fakeFns[1]
  951. window.setTimeout = fakeFns[2]
  952. window.requestIdleCallback = fakeFns[3]
  953.  
  954. fnSelectorProp = null;
  955.  
  956.  
  957. tThis.start991.call(new Proxy(tThis, {
  958. get(target, prop, receiver) {
  959. if (prop === '$$12377$$') return true;
  960. if (prop === '$$12378$$') return target;
  961.  
  962. // console.log('get',prop)
  963. return target[prop]
  964. },
  965. set(target, prop, value, receiver) {
  966. // console.log('set', prop, value)
  967.  
  968.  
  969. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  970. if (value === 12377 && fnSelectorProp) {
  971.  
  972. const originalSelection = target[fnSelectorProp];
  973. const timerIdProp = prop;
  974.  
  975. /*
  976.  
  977.  
  978. case 1:
  979. var a = this.K;
  980. this.g = this.I ? window.requestIdleCallback(a, {
  981. timeout: 3E3
  982. }) : window.setTimeout(a, ma);
  983. break;
  984. case 2:
  985. this.g = window.setTimeout(this.M, this.N);
  986. break;
  987. case 3:
  988. this.g = window.requestAnimationFrame(this.L);
  989. break;
  990. case 4:
  991. this.g = window.setTimeout(this.J, 0)
  992. }
  993.  
  994. */
  995.  
  996. const doForegroundSlowMode = () => {
  997.  
  998. const tir = ++mzt;
  999. const f = requestingArgs[0];
  1000.  
  1001.  
  1002. getForegroundPromise().then(() => {
  1003.  
  1004.  
  1005. new Promise(r => {
  1006. timerResolve = r
  1007. }).then(() => {
  1008. if (target[timerIdProp] === -tir) f();
  1009. });
  1010.  
  1011. })
  1012.  
  1013. target[fnSelectorProp] = 931;
  1014. target[prop] = -tir;
  1015. }
  1016.  
  1017. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  1018. if (slowMode && !(requestingArgs[1] > 250)) {
  1019.  
  1020. doForegroundSlowMode();
  1021.  
  1022. } else {
  1023. target[prop] = setTimeout.apply(window, requestingArgs);
  1024.  
  1025. }
  1026.  
  1027. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  1028.  
  1029. if (slowMode) {
  1030.  
  1031. doForegroundSlowMode();
  1032.  
  1033. } else {
  1034. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  1035. }
  1036.  
  1037.  
  1038. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  1039.  
  1040. const f = requestingArgs[0];
  1041. const tir = ++mzt;
  1042. Promise.resolve().then(() => {
  1043. if (target[timerIdProp] === -tir) f();
  1044. });
  1045. target[fnSelectorProp] = 930;
  1046. target[prop] = -tir;
  1047.  
  1048. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  1049.  
  1050. doForegroundSlowMode();
  1051.  
  1052. } else {
  1053. // target[prop] = timerId;
  1054. target[fnSelectorProp] = 0;
  1055. target[prop] = 0;
  1056. }
  1057.  
  1058. // *****
  1059. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  1060. } else {
  1061.  
  1062. target[prop] = value;
  1063. }
  1064. // console.log('set',prop,value)
  1065. return true;
  1066. }
  1067. }));
  1068.  
  1069. fnSelectorProp = null;
  1070.  
  1071.  
  1072. window.requestAnimationFrame = mk1;
  1073. window.setInterval = mk2
  1074. window.setTimeout = mk3
  1075. window.requestIdleCallback = mk4;
  1076.  
  1077.  
  1078.  
  1079. }
  1080.  
  1081. schedulerInstanceInstance_.start.toString = function () {
  1082. return schedulerInstanceInstance_.start991.toString();
  1083. }
  1084.  
  1085. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  1086. // prop,
  1087. // value: schedulerInstanceInstance_[prop],
  1088. // type: typeof schedulerInstanceInstance_[prop]
  1089.  
  1090. // }));
  1091. // console.log('fcc', funcNames)
  1092.  
  1093.  
  1094.  
  1095.  
  1096. }
  1097. })();
  1098.  
  1099.  
  1100. FIX_yt_player && (async () => {
  1101.  
  1102.  
  1103.  
  1104. const rafHub = new RAFHub();
  1105.  
  1106.  
  1107. const _yt_player = await new Promise(resolve => {
  1108.  
  1109. let cid = setInterval(() => {
  1110. let t = (((window || 0)._yt_player || 0) || 0);
  1111. if (t) {
  1112.  
  1113. clearInterval(cid);
  1114. resolve(t);
  1115. }
  1116. }, 1);
  1117.  
  1118. promiseForTamerTimeout.then(() => {
  1119. resolve(null)
  1120. });
  1121.  
  1122. });
  1123.  
  1124.  
  1125.  
  1126. if (!_yt_player || typeof _yt_player !== 'object') return;
  1127.  
  1128.  
  1129.  
  1130. let keyZq = getZq(_yt_player);
  1131. let keyVG = getVG(_yt_player);
  1132. let buildVG = _yt_player[keyVG];
  1133. let u = new buildVG({
  1134. api: {},
  1135. element: document.createElement('noscript'),
  1136. api: {},
  1137. hide: () => { }
  1138. }, 250);
  1139. const timeDelayConstructor = u.delay.constructor; // g.br
  1140. // console.log(keyVG, u)
  1141. // buildVG.prototype.show = function(){}
  1142. // _yt_player[keyZq] = g.k
  1143.  
  1144. if (!keyZq) return;
  1145.  
  1146.  
  1147. const g = _yt_player
  1148. let k = keyZq
  1149.  
  1150. const gk = g[k];
  1151. if (typeof gk !== 'function') return;
  1152.  
  1153. let dummyObject = new gk;
  1154. let nilFunc = () => { };
  1155.  
  1156. let nilObj = {};
  1157.  
  1158. // console.log(1111111111)
  1159.  
  1160. let keyBoolD = '';
  1161. let keyWindow = '';
  1162. let keyFuncC = '';
  1163. let keyCidj = '';
  1164.  
  1165. for (const [t, y] of Object.entries(dummyObject)) {
  1166. if (y instanceof Window) keyWindow = t;
  1167. }
  1168.  
  1169. const dummyObjectProxyHandler = {
  1170. get(target, prop) {
  1171. let v = target[prop]
  1172. if (v instanceof Window && !keyWindow) {
  1173. keyWindow = t;
  1174. }
  1175. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  1176. if (prop === keyWindow) y = {
  1177. requestAnimationFrame(f) {
  1178. return 3;
  1179. },
  1180. cancelAnimationFrame() {
  1181.  
  1182. }
  1183. }
  1184. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  1185. keyFuncC = prop;
  1186. }
  1187. // console.log('[get]', prop, typeof target[prop])
  1188.  
  1189.  
  1190. return y;
  1191. },
  1192. set(target, prop, value) {
  1193.  
  1194. if (typeof value === 'boolean' && !keyBoolD) {
  1195. keyBoolD = prop;
  1196. }
  1197. if (typeof value === 'number' && !keyCidj && value >= 2) {
  1198. keyCidj = prop;
  1199. }
  1200.  
  1201. // console.log('[set]', prop, value)
  1202. target[prop] = value
  1203.  
  1204. return true;
  1205. }
  1206. };
  1207.  
  1208. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  1209.  
  1210. /*
  1211. console.log({
  1212. keyBoolD,
  1213. keyFuncC,
  1214. keyWindow,
  1215. keyCidj
  1216. })
  1217.  
  1218. console.log( dummyObject[keyFuncC])
  1219.  
  1220.  
  1221. console.log(2222222222)
  1222. */
  1223.  
  1224.  
  1225.  
  1226.  
  1227. g[k].prototype.start = function () {
  1228. this.stop();
  1229. this[keyBoolD] = true;
  1230. this[keyCidj] = rafHub.request(this[keyFuncC]);
  1231. }
  1232. ;
  1233. g[k].prototype.stop = function () {
  1234. if (this.isActive() && this[keyCidj]) {
  1235. rafHub.cancel(this[keyCidj]);
  1236. }
  1237. this[keyCidj] = null
  1238. }
  1239.  
  1240.  
  1241. /*
  1242. g[k].start = function() {
  1243. this.stop();
  1244. this.D = true;
  1245. var a = requestAnimationFrame
  1246. , b = cancelAnimationFrame;
  1247. this.j = a.call(this.B, this.C)
  1248. }
  1249. ;
  1250. g[k].stop = function() {
  1251. if (this.isActive()) {
  1252. var a = requestAnimationFrame
  1253. , b = cancelAnimationFrame;
  1254. b.call(this.B, this.j)
  1255. }
  1256. this.j = null
  1257. }
  1258. */
  1259.  
  1260.  
  1261.  
  1262. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  1263.  
  1264. if (keyzo) {
  1265.  
  1266. k = keyzo
  1267.  
  1268. const setCSSProp = (() => {
  1269.  
  1270. let animationPropCapable = false;
  1271. try {
  1272. const propName = "--ibxpf"
  1273. const value = 2;
  1274. const keyframes = [{
  1275. [propName]: value
  1276. }];
  1277. window.CSS.registerProperty({
  1278. name: "--ibxpf",
  1279. syntax: "<number>",
  1280. inherits: false,
  1281. initialValue: 1,
  1282. });
  1283. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  1284. } catch (e) { }
  1285.  
  1286. if (!animationPropCapable) {
  1287. return (element, cssProp, value) => {
  1288.  
  1289.  
  1290. element.style.setProperty(cssProp, value);
  1291.  
  1292. }
  1293. }
  1294.  
  1295. const propMaps = new Map();
  1296.  
  1297. function setCustomCSSProperty(element, propName, value) {
  1298. let wm = propMaps.get(propName);
  1299. if (!wm) {
  1300.  
  1301. try {
  1302. window.CSS.registerProperty({
  1303. name: propName,
  1304. syntax: "*",
  1305. inherits: false
  1306. });
  1307. } catch (e) {
  1308. console.warn(e);
  1309. }
  1310.  
  1311. propMaps.set(propName, (wm = new WeakMap()));
  1312. }
  1313.  
  1314. // Create the animation keyframes with the provided property and value
  1315. const keyframes = [{
  1316. [propName]: value
  1317. }];
  1318.  
  1319. let currentAnimation = wm.get(element);
  1320. if (currentAnimation) {
  1321.  
  1322. currentAnimation.effect.setKeyframes(keyframes);
  1323.  
  1324. } else {
  1325.  
  1326.  
  1327.  
  1328. // Set the animation on the element and immediately pause it
  1329. const animation = animate.call(element, keyframes, {
  1330. duration: 1, // Very short duration as we just want to set the value
  1331. fill: 'forwards',
  1332. iterationStart: 1,
  1333. iterations: 2,
  1334. direction: 'alternate'
  1335. });
  1336.  
  1337.  
  1338. // animation.currentTime = 1;
  1339. animation.pause();
  1340.  
  1341. wm.set(element, animation);
  1342.  
  1343.  
  1344. }
  1345.  
  1346. }
  1347.  
  1348. return setCustomCSSProperty;
  1349.  
  1350.  
  1351. })();
  1352.  
  1353.  
  1354. const attrUpdateFn = g[k];
  1355. g['$$original$$' + k] = attrUpdateFn;
  1356. g[k] = function (a, b, c) {
  1357.  
  1358. // console.log(140000, a, b, c);
  1359.  
  1360. let transformType = '';
  1361. let transformValue = 0;
  1362. let transformUnit = '';
  1363.  
  1364. let byPassDefaultFn = false;
  1365. if (b === "transform" && typeof c === 'string') {
  1366.  
  1367. byPassDefaultFn = true;
  1368.  
  1369. const aStyle = a.style;
  1370.  
  1371. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  1372. if (!(a instanceof HTMLElement)) return;
  1373. if (c.length === 0) {
  1374.  
  1375. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  1376. let p = c.substring(7, c.length - 1);
  1377. let q = p.length >= 1 ? parseFloat(p) : -1;
  1378. if (q > -1e-5 && q < 1 + 1e-5) {
  1379. transformType = 'scalex'
  1380. transformValue = q;
  1381. transformUnit = '';
  1382. }
  1383.  
  1384.  
  1385. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  1386.  
  1387. let p = c.substring(11, c.length - 3);
  1388. let q = p.length >= 1 ? parseFloat(p) : NaN;
  1389.  
  1390. if (typeof q === 'number' && !isNaN(q)) {
  1391. transformType = 'translateX'
  1392. transformValue = q;
  1393. transformUnit = 'px';
  1394. }
  1395.  
  1396.  
  1397. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  1398. let p = c.substring(7, c.length - 1);
  1399. let q = p.length >= 1 ? parseFloat(p) : -1;
  1400. if (q > -1e-5 && q < 1 + 1e-5) {
  1401. transformType = 'scaley'
  1402. transformValue = q;
  1403. transformUnit = '';
  1404. }
  1405.  
  1406.  
  1407. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  1408.  
  1409. let p = c.substring(11, c.length - 3);
  1410. let q = p.length >= 1 ? parseFloat(p) : NaN;
  1411.  
  1412. if (typeof q === 'number' && !isNaN(q)) {
  1413. transformType = 'translateY'
  1414. transformValue = q;
  1415. transformUnit = 'px';
  1416. }
  1417.  
  1418.  
  1419. }
  1420.  
  1421. if (transformType) {
  1422.  
  1423. if (transformType === 'scalex' || transformType === 'scaley') {
  1424.  
  1425. const q = transformValue;
  1426.  
  1427.  
  1428. /*
  1429.  
  1430. let vz = Math.round(steppingScaleN * q);
  1431. const customPropName = '--discrete-'+transformType
  1432.  
  1433. const currentValue = aStyle.getPropertyValue(customPropName);
  1434.  
  1435. const transform = (aStyle.transform || '');
  1436. const u = transform.includes(customPropName)
  1437. if (`${currentValue}` === `${vz}`) {
  1438. if (u) return;
  1439. }
  1440.  
  1441.  
  1442. setCSSProp(a,customPropName, vz);
  1443. // aStyle.setProperty(customPropName, vz)
  1444.  
  1445. let ck = '';
  1446.  
  1447. if (c.length === 9) ck = c;
  1448. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  1449.  
  1450. if (ck && beforeMq !== ck) {
  1451. aStyle.setProperty('--mq-transform', ck);
  1452. }
  1453.  
  1454. if (u) return;
  1455. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  1456.  
  1457.  
  1458.  
  1459. */
  1460.  
  1461. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  1462.  
  1463. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  1464. const cv = aStyle.transform;
  1465.  
  1466. // console.log(157, cv,c)
  1467.  
  1468. if (c === cv) return;
  1469. // console.log(257, cv,c)
  1470.  
  1471. aStyle.transform = c;
  1472.  
  1473. // return;
  1474.  
  1475. } else if (transformType === 'translateX' || transformType === 'translateY') {
  1476.  
  1477. const q = transformValue;
  1478.  
  1479. /*
  1480.  
  1481. let vz = q.toFixed(1);
  1482. const customPropName = '--discrete-'+transformType
  1483.  
  1484. const aStyle = a.style;
  1485. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  1486.  
  1487.  
  1488. const transform = (aStyle.transform || '');
  1489. const u = transform.includes(customPropName)
  1490. if (parseFloat(currentValue).toFixed(1) === vz) {
  1491. if (u) return;
  1492. }
  1493.  
  1494. setCSSProp(a,customPropName, vz + 'px');
  1495. // aStyle.setProperty(customPropName, vz + 'px')
  1496.  
  1497. let ck = '';
  1498. if (c.length === 15) ck = c;
  1499. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  1500.  
  1501. if (ck && beforeMq !== ck) {
  1502. aStyle.setProperty('--mq-transform', ck);
  1503. }
  1504.  
  1505. if (u) return;
  1506. c = `${transformType}(var(--discrete-${transformType}))`;
  1507.  
  1508. */
  1509.  
  1510.  
  1511. const vz = +q.toFixed(1);
  1512.  
  1513. c = `${transformType}(${vz}${transformUnit})`
  1514. const cv = aStyle.transform;
  1515.  
  1516. // console.log(158, cv,c)
  1517.  
  1518. if (c === cv) return;
  1519. // console.log(258, cv,c)
  1520.  
  1521. aStyle.transform = c;
  1522.  
  1523. // return;
  1524.  
  1525. } else {
  1526. throw new Error();
  1527. }
  1528.  
  1529. } else {
  1530. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  1531. const cv = aStyle.transform
  1532. if (!c && !cv) return;
  1533. else if (c === cv) return;
  1534. aStyle.transform = c;
  1535. // return;
  1536. }
  1537.  
  1538. } else if (b === "display") {
  1539.  
  1540. const cv = a.style.display;
  1541. if (!cv && !c) return;
  1542. if (cv === c) return;
  1543.  
  1544.  
  1545. } else if (b === "width") {
  1546.  
  1547. const cv = a.style.width;
  1548. if (!cv && !c) return;
  1549. if (cv === c) return;
  1550.  
  1551. }
  1552.  
  1553. // console.log(130000, a, b, c);
  1554.  
  1555. if (byPassDefaultFn) return;
  1556. return attrUpdateFn.call(this, a, b, c);
  1557. }
  1558.  
  1559.  
  1560. /*
  1561.  
  1562. g.zo = function(a, b, c) {
  1563. if ("string" === typeof b)
  1564. (b = yo(a, b)) && (a.style[b] = c);
  1565. else
  1566. for (var d in b) {
  1567. c = a;
  1568. var e = b[d]
  1569. , f = yo(c, d);
  1570. f && (c.style[f] = e)
  1571. }
  1572. }
  1573.  
  1574.  
  1575. */
  1576.  
  1577.  
  1578. }
  1579.  
  1580.  
  1581.  
  1582. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  1583.  
  1584. if (keyuG) {
  1585.  
  1586. k = keyuG;
  1587.  
  1588. const gk = g[k];
  1589. const gkp = gk.prototype;
  1590.  
  1591.  
  1592. /** @type { Map<string, WeakMap<any, any>> } */
  1593. const ntLogs = new Map();
  1594.  
  1595. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  1596.  
  1597. gkp.updateValue31 = gkp.updateValue;
  1598. gkp.updateValue = function (a, b) {
  1599. if (typeof a !== 'string') return this.updateValue31(a, b);
  1600.  
  1601. const element = this.element;
  1602. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  1603.  
  1604. let ntLog = ntLogs.get(a);
  1605. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  1606.  
  1607. let cache = ntLog.get(element);
  1608. if (cache && cache.value === b) {
  1609. return;
  1610. }
  1611. if (!cache) {
  1612. this.__oldValueByUpdateValue__ = null;
  1613. ntLog.set(element, cache = { value: b });
  1614. } else {
  1615. this.__oldValueByUpdateValue__ = cache.value;
  1616. cache.value = b;
  1617. }
  1618.  
  1619.  
  1620. return this.updateValue31(a, b);
  1621. }
  1622.  
  1623.  
  1624. /*
  1625. g.k.update = function(a) {
  1626. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  1627. c = c.value,
  1628. this.updateValue(c, a[c])
  1629. }
  1630. ;
  1631. g.k.updateValue = function(a, b) {
  1632. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  1633. }
  1634. */
  1635.  
  1636.  
  1637. }
  1638.  
  1639.  
  1640. }
  1641.  
  1642.  
  1643.  
  1644.  
  1645. })();
  1646.  
  1647.  
  1648.  
  1649. FIX_Animation_n_timeline && (async () => {
  1650.  
  1651.  
  1652. const timeline = await new Promise(resolve => {
  1653.  
  1654. let cid = setInterval(() => {
  1655. let t = (((document || 0).timeline || 0) || 0);
  1656. if (t && typeof t._play === 'function') {
  1657.  
  1658. clearInterval(cid);
  1659. resolve(t);
  1660. }
  1661. }, 1);
  1662.  
  1663. promiseForTamerTimeout.then(() => {
  1664. resolve(null)
  1665. });
  1666.  
  1667. });
  1668.  
  1669.  
  1670. const Animation = await new Promise(resolve => {
  1671.  
  1672. let cid = setInterval(() => {
  1673. let t = (((window || 0).Animation || 0) || 0);
  1674. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  1675.  
  1676. clearInterval(cid);
  1677. resolve(t);
  1678. }
  1679. }, 1);
  1680.  
  1681. promiseForTamerTimeout.then(() => {
  1682. resolve(null)
  1683. });
  1684.  
  1685. });
  1686.  
  1687. if (!timeline) return;
  1688. if (!Animation) return;
  1689.  
  1690. const aniProto = Animation.prototype;
  1691.  
  1692. const getXroto = (x) => {
  1693. try {
  1694. return x.__proto__;
  1695. } catch (e) { }
  1696. return null;
  1697. }
  1698. const timProto = getXroto(timeline);
  1699. if (!timProto) return;
  1700. if (
  1701. (
  1702. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  1703. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  1704. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  1705. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  1706. )
  1707.  
  1708. ) {
  1709.  
  1710. timProto.nofCQ = 1;
  1711. aniProto.nofYH = 1;
  1712.  
  1713. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  1714.  
  1715.  
  1716. /*
  1717. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  1718. return c._updatePromises();
  1719. });
  1720. */
  1721.  
  1722. const p = Array.prototype.filter;
  1723.  
  1724. let res = null;
  1725. Array.prototype.filter = function () {
  1726.  
  1727. res = this;
  1728. return this;
  1729.  
  1730. };
  1731.  
  1732. _updateAnimationsPromises.call({});
  1733.  
  1734. Array.prototype.filter = p;
  1735.  
  1736. if (res && typeof res.length === 'number') {
  1737. /** @type {any[]} */
  1738. const _res = res;
  1739. return _res;
  1740. }
  1741.  
  1742.  
  1743. return null;
  1744.  
  1745.  
  1746.  
  1747.  
  1748. })(timProto._updateAnimationsPromises);
  1749.  
  1750. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  1751.  
  1752. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  1753.  
  1754. aniProto._updatePromises31 = aniProto._updatePromises;
  1755.  
  1756. /*
  1757. aniProto._updatePromises = function(){
  1758. console.log('eff',this._oldPlayState, this.playState)
  1759. return this._updatePromises31.apply(this, arguments)
  1760. }
  1761. */
  1762.  
  1763. aniProto._updatePromises = function () {
  1764. var oldPlayState = this._oldPlayState;
  1765. var newPlayState = this.playState;
  1766. // console.log('ett', oldPlayState, newPlayState)
  1767. if (newPlayState !== oldPlayState) {
  1768. this._oldPlayState = newPlayState;
  1769. if (this._readyPromise) {
  1770. if ("idle" == newPlayState) {
  1771. this._rejectReadyPromise();
  1772. this._readyPromise = void 0;
  1773. } else if ("pending" == oldPlayState) {
  1774. this._resolveReadyPromise();
  1775. } else if ("pending" == newPlayState) {
  1776. this._readyPromise = void 0;
  1777. }
  1778. }
  1779. if (this._finishedPromise) {
  1780. if ("idle" == newPlayState) {
  1781. this._rejectFinishedPromise();
  1782. this._finishedPromise = void 0;
  1783. } else if ("finished" == newPlayState) {
  1784. this._resolveFinishedPromise();
  1785. } else if ("finished" == oldPlayState) {
  1786. this._finishedPromise = void 0;
  1787. }
  1788. }
  1789. }
  1790. return this._readyPromise || this._finishedPromise;
  1791. };
  1792.  
  1793.  
  1794. let restartWebAnimationsNextTickFlag = false;
  1795.  
  1796. const looperMethodT = () => {
  1797.  
  1798. const runnerFn = (hRes) => {
  1799. var b = timeline;
  1800. b.currentTime = hRes;
  1801. b._discardAnimations();
  1802. if (0 == b._animations.length) {
  1803. restartWebAnimationsNextTickFlag = false;
  1804. } else {
  1805. getRafPromiseForTickers().then(runnerFn);
  1806. }
  1807. }
  1808.  
  1809. const restartWebAnimationsNextTick = () => {
  1810. if (!restartWebAnimationsNextTickFlag) {
  1811. restartWebAnimationsNextTickFlag = true;
  1812. getRafPromiseForTickers().then(runnerFn);
  1813. }
  1814. }
  1815.  
  1816. return { restartWebAnimationsNextTick }
  1817. };
  1818.  
  1819.  
  1820. const looperMethodN = () => {
  1821.  
  1822. const acs = document.createElement('a-f');
  1823. acs.id = 'a-f';
  1824.  
  1825. const style = document.createElement('style');
  1826. style.textContent = `
  1827. @keyFrames aF1 {
  1828. 0% {
  1829. order: 0;
  1830. }
  1831. 100% {
  1832. order: 6;
  1833. }
  1834. }
  1835. #a-f[id] {
  1836. visibility: collapse !important;
  1837. position: fixed !important;
  1838. top: -100px !important;
  1839. left: -100px !important;
  1840. margin:0 !important;
  1841. padding:0 !important;
  1842. outline:0 !important;
  1843. border:0 !important;
  1844. z-index:-1 !important;
  1845. width: 0px !important;
  1846. height: 0px !important;
  1847. contain: strict !important;
  1848. pointer-events: none !important;
  1849. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  1850. }
  1851. `;
  1852. (document.head || document.documentElement).appendChild(style);
  1853.  
  1854. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  1855.  
  1856. const _onanimationiteration = function (evt) {
  1857. const hRes = evt.timeStamp;
  1858. var b = timeline;
  1859. b.currentTime = hRes;
  1860. b._discardAnimations();
  1861. if (0 == b._animations.length) {
  1862. restartWebAnimationsNextTickFlag = false;
  1863. acs.onanimationiteration = null;
  1864. } else {
  1865. acs.onanimationiteration = _onanimationiteration;
  1866. }
  1867.  
  1868. }
  1869.  
  1870.  
  1871.  
  1872. const restartWebAnimationsNextTick = () => {
  1873. if (!restartWebAnimationsNextTickFlag) {
  1874. restartWebAnimationsNextTickFlag = true;
  1875. acs.onanimationiteration = _onanimationiteration;
  1876.  
  1877. }
  1878. }
  1879.  
  1880. return { restartWebAnimationsNextTick }
  1881. };
  1882.  
  1883.  
  1884.  
  1885. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  1886.  
  1887. timProto._play = function (c) {
  1888. c = new Animation(c, this);
  1889. this._animations.push(c);
  1890. restartWebAnimationsNextTick();
  1891. c._updatePromises();
  1892. c._animation.play();
  1893. c._updatePromises();
  1894. return c
  1895. }
  1896.  
  1897. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  1898. originalAnimationsWithPromises.length = 0;
  1899. originalAnimationsWithPromises.push = null;
  1900. originalAnimationsWithPromises.splice = null;
  1901. originalAnimationsWithPromises.slice = null;
  1902. originalAnimationsWithPromises.indexOf = null;
  1903. originalAnimationsWithPromises.unshift = null;
  1904. originalAnimationsWithPromises.shift = null;
  1905. originalAnimationsWithPromises.pop = null;
  1906. originalAnimationsWithPromises.filter = null;
  1907. originalAnimationsWithPromises.forEach = null;
  1908. originalAnimationsWithPromises.map = null;
  1909.  
  1910.  
  1911.  
  1912. const _updateAnimationsPromises = () => {
  1913. animationsWithPromisesMap.forEach(c => {
  1914. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  1915. })
  1916. /*
  1917. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  1918. return c._updatePromises();
  1919. });
  1920. */
  1921. }
  1922.  
  1923. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  1924.  
  1925. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  1926.  
  1927.  
  1928. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  1929. aniProto.__finished_native_get__ = pdFinished.get;
  1930. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  1931.  
  1932.  
  1933. Object.defineProperty(aniProto, 'finished', {
  1934. get() {
  1935. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  1936. this._finishedPromise = new Promise((resolve, reject) => {
  1937. this._resolveFinishedPromise = function () {
  1938. resolve(this)
  1939. };
  1940. this._rejectFinishedPromise = function () {
  1941. reject({
  1942. type: DOMException.ABORT_ERR,
  1943. name: "AbortError"
  1944. })
  1945. };
  1946. }),
  1947. "finished" == this.playState && this._resolveFinishedPromise());
  1948. return this._finishedPromise
  1949. },
  1950. set: undefined,
  1951. enumerable: true,
  1952. configurable: true
  1953. });
  1954.  
  1955. }
  1956.  
  1957.  
  1958.  
  1959. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  1960. aniProto.__ready_native_get__ = pdReady.get;
  1961. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  1962.  
  1963. Object.defineProperty(aniProto, 'ready', {
  1964. get() {
  1965. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  1966. this._readyPromise = new Promise((resolve, reject) => {
  1967. this._resolveReadyPromise = function () {
  1968. resolve(this)
  1969. };
  1970. this._rejectReadyPromise = function () {
  1971. reject({
  1972. type: DOMException.ABORT_ERR,
  1973. name: "AbortError"
  1974. })
  1975. };
  1976. }),
  1977. "pending" !== this.playState && this._resolveReadyPromise());
  1978. return this._readyPromise
  1979. },
  1980. set: undefined,
  1981. enumerable: true,
  1982. configurable: true
  1983. });
  1984.  
  1985. }
  1986.  
  1987.  
  1988.  
  1989.  
  1990. /*
  1991.  
  1992.  
  1993. function f(c) {
  1994. var b = v.timeline;
  1995. b.currentTime = c;
  1996. b._discardAnimations();
  1997. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  1998. }
  1999. var h = window.requestAnimationFrame;
  2000. window.requestAnimationFrame = function(c) {
  2001. return h(function(b) {
  2002. v.timeline._updateAnimationsPromises();
  2003. c(b);
  2004. v.timeline._updateAnimationsPromises()
  2005. })
  2006. }
  2007. ;
  2008. v.AnimationTimeline = function() {
  2009. this._animations = [];
  2010. this.currentTime = void 0
  2011. }
  2012. ;
  2013. v.AnimationTimeline.prototype = {
  2014. getAnimations: function() {
  2015. this._discardAnimations();
  2016. return this._animations.slice()
  2017. },
  2018. _updateAnimationsPromises: function() {
  2019. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  2020. return c._updatePromises()
  2021. })
  2022. },
  2023. _discardAnimations: function() {
  2024. this._updateAnimationsPromises();
  2025. this._animations = this._animations.filter(function(c) {
  2026. return "finished" != c.playState && "idle" != c.playState
  2027. })
  2028. },
  2029. _play: function(c) {
  2030. c = new v.Animation(c,this);
  2031. this._animations.push(c);
  2032. v.restartWebAnimationsNextTick();
  2033. c._updatePromises();
  2034. c._animation.play();
  2035. c._updatePromises();
  2036. return c
  2037. },
  2038. play: function(c) {
  2039. c && c.remove();
  2040. return this._play(c)
  2041. }
  2042. };
  2043. var d = !1;
  2044. v.restartWebAnimationsNextTick = function() {
  2045. d || (d = !0,
  2046. requestAnimationFrame(f))
  2047. }
  2048. ;
  2049. var a = new v.AnimationTimeline;
  2050. v.timeline = a;
  2051. try {
  2052. Object.defineProperty(window.document, "timeline", {
  2053. configurable: !0,
  2054. get: function() {
  2055. return a
  2056. }
  2057. })
  2058. } catch (c) {}
  2059. try {
  2060. window.document.timeline = a
  2061. } catch (c) {}
  2062.  
  2063. */
  2064.  
  2065.  
  2066.  
  2067. /*
  2068.  
  2069. var g = window.getComputedStyle;
  2070. Object.defineProperty(window, "getComputedStyle", {
  2071. configurable: !0,
  2072. enumerable: !0,
  2073. value: function() {
  2074. v.timeline._updateAnimationsPromises();
  2075. var e = g.apply(this, arguments);
  2076. h() && (e = g.apply(this, arguments));
  2077. v.timeline._updateAnimationsPromises();
  2078. return e
  2079. }
  2080. });
  2081.  
  2082. */
  2083.  
  2084.  
  2085.  
  2086.  
  2087. }
  2088.  
  2089.  
  2090.  
  2091.  
  2092. })();
  2093.  
  2094.  
  2095.  
  2096. });
  2097.  
  2098.  
  2099. setupEvents();
  2100.  
  2101.  
  2102.  
  2103. if (isMainWindow) {
  2104.  
  2105. console.groupCollapsed(
  2106. "%cYouTube JS Engine Tamer",
  2107. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  2108. );
  2109.  
  2110.  
  2111.  
  2112. console.log("Script is loaded.");
  2113. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  2114.  
  2115. console.log("This script is experimental and subject to further changes.");
  2116.  
  2117. console.log("This might boost your YouTube performance.");
  2118.  
  2119. console.log("CAUTION: This might break your YouTube.");
  2120.  
  2121.  
  2122. if (prepareLogs.length >= 1) {
  2123. console.log(" =========================================================================== ");
  2124.  
  2125. for (const msg of prepareLogs) {
  2126. console.log(msg)
  2127. }
  2128.  
  2129. console.log(" =========================================================================== ");
  2130. }
  2131.  
  2132. console.groupEnd();
  2133.  
  2134. }
  2135.  
  2136.  
  2137. })();