YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2023-10-03 提交的版本,查看 最新版本

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