Greasy Fork 还支持 简体中文。

YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

目前為 2023-09-01 提交的版本,檢視 最新版本

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