YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址