YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.6.0
  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. const ENABLE_discreteTasking = true; // TBC
  52.  
  53.  
  54. /*
  55. window.addEventListener('edm',()=>{
  56. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  57. });
  58.  
  59. window.addEventListener('edn',()=>{
  60. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  61. });
  62. window.addEventListener('edr',()=>{
  63. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  64. });
  65. */
  66.  
  67.  
  68.  
  69. let p59 = 0;
  70.  
  71. const Promise = (async () => { })().constructor;
  72.  
  73. const PromiseExternal = ((resolve_, reject_) => {
  74. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  75. return class PromiseExternal extends Promise {
  76. constructor(cb = h) {
  77. super(cb);
  78. if (cb === h) {
  79. /** @type {(value: any) => void} */
  80. this.resolve = resolve_;
  81. /** @type {(reason?: any) => void} */
  82. this.reject = reject_;
  83. }
  84. }
  85. };
  86. })();
  87.  
  88.  
  89. let pf31 = new PromiseExternal();
  90.  
  91. // native RAF
  92. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  93.  
  94. // 1st wrapped RAF
  95. const baseRAF = (callback) => {
  96. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  97. pf31.then(() => {
  98. callback(hRes);
  99. });
  100. });
  101. };
  102.  
  103. // 2nd wrapped RAF
  104. window.requestAnimationFrame = baseRAF;
  105.  
  106. /*
  107. const pmf = new WeakMap();
  108.  
  109.  
  110. Object.defineProperty(Object.prototype, 'connectedCallback', {
  111. get(){
  112. const f = this._stconnectedCallback;
  113. if(typeof this.constructor.prototype.attached ==='function' && !pmf.has(this.constructor.prototype.attached)){
  114. const f = this.constructor.prototype.attached;
  115. const g = function(){
  116. if(!this._btcbr) this._btcbr = Promise.resolve();
  117. if(!this.$) this.$ = 0;
  118. this._btcbr = this._btcbr.then(()=>{
  119. try{
  120. f.call(this);
  121. }catch(e){
  122. console.log(e)
  123. }
  124. });
  125.  
  126. }
  127. pmf.set(g, true);
  128. this.constructor.prototype.attached = g;
  129. }
  130.  
  131. if(typeof this.constructor.prototype.detached ==='function' && !pmf.has(this.constructor.prototype.detached)){
  132. const f = this.constructor.prototype.detached;
  133. const g = function(){
  134. if(!this._btcbr) this._btcbr = Promise.resolve();
  135. if(!this.$) this.$ = 0;
  136. this._btcbr = this._btcbr.then(()=>{
  137. try{
  138. f.call(this);
  139. }catch(e){
  140. console.log(e)
  141. }
  142. });
  143.  
  144. }
  145. pmf.set(g, true);
  146. this.constructor.prototype.detached = g;
  147. }
  148.  
  149. if(typeof this.constructor.prototype.onYtRendererstamperFinished ==='function' && !pmf.has(this.constructor.prototype.onYtRendererstamperFinished)){
  150. const f = this.constructor.prototype.onYtRendererstamperFinished;
  151. const g = function(){
  152. if(!this._btcbr) this._btcbr = Promise.resolve();
  153. if(!this.$) this.$ = 0;
  154. this._btcbr = this._btcbr.then(()=>{
  155. try{
  156. setTimeout(()=>f.call(this));
  157. }catch(e){
  158. console.log(e)
  159. }
  160. });
  161.  
  162. }
  163. pmf.set(g, true);
  164. this.constructor.prototype.onYtRendererstamperFinished = g;
  165. }
  166. return typeof f ==='function' ? (pmf.get(f) || f) : f;
  167. },
  168. set(nv){
  169. if(typeof nv ==='function' && !pmf.has(nv)){
  170. const f = nv;
  171. const g = function(){
  172. if(!this._btcbr) this._btcbr = Promise.resolve();
  173. if(!this.ku37) this.ku37 = g;
  174. if(!this.$) this.$ = 0;
  175. if(this.ku37 === g){
  176.  
  177. this._btcbr = this._btcbr.then(()=>{
  178. try{
  179. f.call(this)
  180. }catch(e){
  181. console.log(e)
  182. }
  183. });
  184.  
  185. }else{
  186. return f.call(this)
  187. }
  188. }
  189. pmf.set(f, g);
  190. pmf.set(g, g);
  191. }
  192. this._stconnectedCallback = nv;
  193. return true;
  194. },
  195. enumerable: false,
  196. configurable: true
  197.  
  198. });
  199.  
  200.  
  201.  
  202. Object.defineProperty(Object.prototype, 'disconnectedCallback', {
  203. get(){
  204. const f = this._stdisconnectedCallback;
  205. if(typeof this.constructor.prototype.attached ==='function' && !pmf.has(this.constructor.prototype.attached)){
  206. const f = this.constructor.prototype.attached;
  207. const g = function(){
  208. if(!this._btcbr) this._btcbr = Promise.resolve();
  209. if(!this.$) this.$ = 0;
  210. this._btcbr = this._btcbr.then(()=>{
  211. try{
  212. f.call(this);
  213. }catch(e){
  214. console.log(e)
  215. }
  216. });
  217.  
  218. }
  219. pmf.set(g, true);
  220. this.constructor.prototype.attached = g;
  221. }
  222.  
  223. if(typeof this.constructor.prototype.detached ==='function' && !pmf.has(this.constructor.prototype.detached)){
  224. const f = this.constructor.prototype.detached;
  225. const g = function(){
  226. if(!this._btcbr) this._btcbr = Promise.resolve();
  227. if(!this.$) this.$ = 0;
  228. this._btcbr = this._btcbr.then(()=>{
  229. try{
  230. f.call(this);
  231. }catch(e){
  232. console.log(e)
  233. }
  234. });
  235.  
  236. }
  237. pmf.set(g, true);
  238. this.constructor.prototype.detached = g;
  239. }
  240.  
  241. if(typeof this.constructor.prototype.onYtRendererstamperFinished ==='function' && !pmf.has(this.constructor.prototype.onYtRendererstamperFinished)){
  242. const f = this.constructor.prototype.onYtRendererstamperFinished;
  243. const g = function(){
  244. if(!this._btcbr) this._btcbr = Promise.resolve();
  245. if(!this.$) this.$ = 0;
  246. this._btcbr = this._btcbr.then(()=>{
  247. try{
  248. setTimeout(()=>f.call(this));
  249. }catch(e){
  250. console.log(e)
  251. }
  252. });
  253.  
  254. }
  255. pmf.set(g, true);
  256. this.constructor.prototype.onYtRendererstamperFinished = g;
  257. }
  258. return typeof f ==='function' ? (pmf.get(f) || f) : f;
  259. },
  260. set(nv){
  261. if(typeof nv ==='function' && !pmf.has(nv)){
  262. const f = nv;
  263. const g = function(){
  264. if(!this._btcbr) this._btcbr = Promise.resolve();
  265. if(!this.ku38) this.ku38 = g;
  266. if(!this.$) this.$ = 0;
  267. if(this.ku38 === g){
  268.  
  269. this._btcbr = this._btcbr.then(()=>{
  270. try{
  271. f.call(this)
  272. }catch(e){
  273. console.log(e)
  274. }
  275. });
  276.  
  277. }else{
  278. return f.call(this)
  279. }
  280. }
  281. pmf.set(f, g);
  282. pmf.set(g, g);
  283. }
  284. this._stdisconnectedCallback = nv;
  285. return true;
  286. },
  287. enumerable: false,
  288. configurable: true
  289.  
  290. });
  291. */
  292.  
  293. // requestAnimationFrame is likely to be wrapped into YT Engine's rAf.
  294.  
  295.  
  296.  
  297.  
  298. // const setup2= (h)=>{
  299.  
  300.  
  301. // if(typeof h.rendererStamperApplyChangeRecord_ ==='function' && !(h.rendererStamperApplyChangeRecord_.km34)){
  302.  
  303. // const f = h.rendererStamperApplyChangeRecord_;
  304. // const g = function(){
  305. // Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  306. // }
  307. // g.km34 = 1;
  308. // h.rendererStamperApplyChangeRecord_ = g;
  309.  
  310. // }
  311.  
  312.  
  313.  
  314. // if(typeof h.forwardRendererStamperChanges_ ==='function' && !(h.forwardRendererStamperChanges_.km34)){
  315.  
  316. // const f = h.forwardRendererStamperChanges_;
  317. // const g = function(){
  318. // Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  319. // }
  320. // g.km34 = 1;
  321. // h.forwardRendererStamperChanges_ = g;
  322.  
  323. // }
  324.  
  325.  
  326. // if(typeof h.stampDomArray_ ==='function' && !(h.stampDomArray_.km34)){
  327.  
  328. // const f = h.stampDomArray_;
  329. // const g = function(){
  330. // Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  331. // }
  332. // g.km34 = 1;
  333. // h.stampDomArray_ = g;
  334.  
  335. // }
  336. // if(typeof h.stampDomArraySplices_ ==='function' && !(h.stampDomArraySplices_.km34)){
  337.  
  338. // const f = h.stampDomArraySplices_;
  339. // const g = function(){
  340. // Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  341. // }
  342. // g.km34 = 1;
  343. // h.stampDomArraySplices_ = g;
  344.  
  345. // }
  346. // }
  347.  
  348. const ump3 = new WeakMap();
  349.  
  350. const setupDiscreteTasks = (h, rb) => {
  351.  
  352. if (rb) {
  353. // const p = this._stconnectedCallback;
  354. // if(this.kb35=== p) return;
  355. // this.kb35 = p;
  356. if (this.ky36) return;
  357. }
  358.  
  359.  
  360.  
  361. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  362. const f = h.onYtRendererstamperFinished;
  363. const g = ump3.get(f) || function () {
  364. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  365. }
  366. ump3.set(f, g);
  367. g.km34 = 1;
  368. h.onYtRendererstamperFinished = g;
  369.  
  370. }
  371.  
  372.  
  373.  
  374.  
  375. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  376. const f = h.onYtUpdateDescriptionAction;
  377. const g = ump3.get(f) || function (a) {
  378. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  379. }
  380. ump3.set(f, g);
  381. g.km34 = 1;
  382. h.onYtUpdateDescriptionAction = g;
  383.  
  384. }
  385.  
  386.  
  387.  
  388. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  389. const f = h.handleUpdateDescriptionAction;
  390. const g = ump3.get(f) || function (a) {
  391. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  392. }
  393. ump3.set(f, g);
  394. g.km34 = 1;
  395. h.handleUpdateDescriptionAction = g;
  396.  
  397. }
  398.  
  399. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  400. const f = h.handleUpdateLiveChatPollAction;
  401. const g = ump3.get(f) || function (a) {
  402. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  403. }
  404. ump3.set(f, g);
  405. g.km34 = 1;
  406. h.handleUpdateLiveChatPollAction = g;
  407.  
  408. }
  409.  
  410.  
  411.  
  412.  
  413. if (typeof h.onYtAction_ === 'function' && !(h.onYtAction_.km34)) {
  414. const f = h.onYtAction_;
  415. const g = ump3.get(f) || function (a) {
  416. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  417. }
  418. ump3.set(f, g);
  419. g.km34 = 1;
  420. h.onYtAction_ = g;
  421.  
  422. }
  423.  
  424.  
  425.  
  426.  
  427. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  428. const f = h.onTextChanged;
  429. const g = ump3.get(f) || function () {
  430. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  431. }
  432. ump3.set(f, g);
  433. g.km34 = 1;
  434. h.onTextChanged = g;
  435.  
  436. }
  437.  
  438.  
  439.  
  440.  
  441. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  442. const f = h.onVideoDataChange;
  443. const g = ump3.get(f) || function (a) {
  444. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  445. }
  446. ump3.set(f, g);
  447. g.km34 = 1;
  448. h.onVideoDataChange = g;
  449.  
  450. }
  451.  
  452.  
  453.  
  454. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  455. const f = h.onVideoDataChange_;
  456. const g = ump3.get(f) || function () {
  457. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  458. }
  459. ump3.set(f, g);
  460. g.km34 = 1;
  461. h.onVideoDataChange_ = g;
  462.  
  463. }
  464.  
  465.  
  466. if (typeof h.addTooltips === 'function' && !(h.addTooltips.km34)) {
  467.  
  468. const f = h.addTooltips;
  469. const g = ump3.get(f) || function () {
  470. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  471. }
  472. ump3.set(f, g);
  473. g.km34 = 1;
  474. h.addTooltips = g;
  475.  
  476. }
  477.  
  478.  
  479.  
  480. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  481.  
  482. const f = h.addTooltips_;
  483. const g = ump3.get(f) || function () {
  484. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  485. }
  486. ump3.set(f, g);
  487. g.km34 = 1;
  488. h.addTooltips_ = g;
  489.  
  490. }
  491.  
  492.  
  493. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  494.  
  495. const f = h.updateRenderedElements;
  496. const g = ump3.get(f) || function () {
  497. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  498. }
  499. ump3.set(f, g);
  500. g.km34 = 1;
  501. h.updateRenderedElements = g;
  502.  
  503. }
  504.  
  505.  
  506.  
  507. if (typeof h.startLoadingWatch === 'function' && !(h.startLoadingWatch.km34)) {
  508.  
  509. const f = h.startLoadingWatch;
  510. const g = ump3.get(f) || function () {
  511. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  512. }
  513. ump3.set(f, g);
  514. g.km34 = 1;
  515. h.startLoadingWatch = g;
  516.  
  517. }
  518.  
  519.  
  520.  
  521.  
  522. if (typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  523. const f = h.loadPage_;
  524. const g = ump3.get(f) || function (a) {
  525. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  526. }
  527. ump3.set(f, g);
  528. g.km34 = 1;
  529. h.loadPage_ = g;
  530.  
  531. }
  532. if (typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  533. const f = h.updatePageData_;
  534. const g = ump3.get(f) || function (a) {
  535. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  536. }
  537. ump3.set(f, g);
  538. g.km34 = 1;
  539. h.updatePageData_ = g;
  540.  
  541. }
  542.  
  543. if (typeof h.rendererStamperObserver_ === 'function' && !(h.rendererStamperObserver_.km34)) {
  544.  
  545. const f = h.rendererStamperObserver_;
  546. const g = ump3.get(f) || function (a, b, c) {
  547. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  548. }
  549. ump3.set(f, g);
  550. g.km34 = 1;
  551. h.rendererStamperObserver_ = g;
  552.  
  553. }
  554.  
  555.  
  556. if (typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  557.  
  558. const f = h.onFocus_;
  559. const g = ump3.get(f) || function () {
  560. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  561. }
  562. ump3.set(f, g);
  563. g.km34 = 1;
  564. h.onFocus_ = g;
  565.  
  566. }
  567.  
  568. if (typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  569.  
  570. const f = h.onBlur_;
  571. const g = ump3.get(f) || function () {
  572. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  573. }
  574. ump3.set(f, g);
  575. g.km34 = 1;
  576. h.onBlur_ = g;
  577.  
  578. }
  579.  
  580.  
  581. if (typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  582.  
  583. const f = h.buttonClassChanged_;
  584. const g = ump3.get(f) || function (a, b) {
  585. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  586. }
  587. ump3.set(f, g);
  588. g.km34 = 1;
  589. h.buttonClassChanged_ = g;
  590.  
  591. }
  592.  
  593.  
  594. if (typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  595.  
  596. const f = h.buttonIconChanged_;
  597. const g = ump3.get(f) || function (a) {
  598. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  599. }
  600. ump3.set(f, g);
  601. g.km34 = 1;
  602. h.buttonIconChanged_ = g;
  603.  
  604. }
  605.  
  606.  
  607. if (typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  608.  
  609. const f = h.dataChangedInBehavior_;
  610. const g = ump3.get(f) || function () {
  611. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  612. }
  613. ump3.set(f, g);
  614. g.km34 = 1;
  615. h.dataChangedInBehavior_ = g;
  616.  
  617. }
  618.  
  619.  
  620. if (typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  621.  
  622. const f = h.continuationsChanged_;
  623. const g = ump3.get(f) || function () {
  624. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  625. }
  626. ump3.set(f, g);
  627. g.km34 = 1;
  628. h.continuationsChanged_ = g;
  629.  
  630. }
  631.  
  632.  
  633. if (typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  634.  
  635. const f = h.forceChatPoll_;
  636. const g = ump3.get(f) || function (a) {
  637. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  638. }
  639. ump3.set(f, g);
  640. g.km34 = 1;
  641. h.forceChatPoll_ = g;
  642.  
  643. }
  644.  
  645.  
  646.  
  647. if (typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  648.  
  649. const f = h.onEndpointClick_;
  650. const g = ump3.get(f) || function (a) {
  651. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  652. }
  653. ump3.set(f, g);
  654. g.km34 = 1;
  655. h.onEndpointClick_ = g;
  656.  
  657. }
  658.  
  659.  
  660. if (typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  661.  
  662. const f = h.onEndpointTap_;
  663. const g = ump3.get(f) || function (a) {
  664. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  665. }
  666. ump3.set(f, g);
  667. g.km34 = 1;
  668. h.onEndpointTap_ = g;
  669.  
  670. }
  671.  
  672.  
  673. if (typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  674.  
  675. const f = h.handleClick_;
  676. const g = ump3.get(f) || function (a, b) {
  677. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  678. }
  679. ump3.set(f, g);
  680. g.km34 = 1;
  681. h.handleClick_ = g;
  682.  
  683. }
  684.  
  685.  
  686.  
  687. if (typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  688.  
  689. const f = h.onReadyStateChange_;
  690. const g = ump3.get(f) || function () {
  691. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  692. }
  693. ump3.set(f, g);
  694. g.km34 = 1;
  695. h.onReadyStateChange_ = g;
  696.  
  697. }
  698.  
  699. if (typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  700.  
  701. const f = h.onReadyStateChangeEntryPoint_;
  702. const g = ump3.get(f) || function () {
  703. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  704. }
  705. ump3.set(f, g);
  706. g.km34 = 1;
  707. h.onReadyStateChangeEntryPoint_ = g;
  708.  
  709. }
  710.  
  711.  
  712. if (typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  713.  
  714. const f = h.readyStateChangeHandler_;
  715. const g = ump3.get(f) || function (a) {
  716. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  717. }
  718. ump3.set(f, g);
  719. g.km34 = 1;
  720. h.readyStateChangeHandler_ = g;
  721.  
  722. }
  723.  
  724.  
  725.  
  726.  
  727. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  728.  
  729. const f = h.xmlHttpHandler_;
  730. const g = ump3.get(f) || function (a) {
  731. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  732. }
  733. ump3.set(f, g);
  734. g.km34 = 1;
  735. h.xmlHttpHandler_ = g;
  736.  
  737. }
  738.  
  739.  
  740. if (typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  741.  
  742. const f = h.executeCallbacks_; // overloaded
  743. const g = ump3.get(f) || function (a) {
  744. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  745. }
  746. ump3.set(f, g);
  747. g.km34 = 1;
  748. h.executeCallbacks_ = g;
  749.  
  750. }
  751.  
  752.  
  753.  
  754. if (typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  755.  
  756. const f = h.handleInvalidationData_;
  757. const g = ump3.get(f) || function (a, b) {
  758. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  759. }
  760. ump3.set(f, g);
  761. g.km34 = 1;
  762. h.handleInvalidationData_ = g;
  763.  
  764. }
  765.  
  766.  
  767. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  768.  
  769. const f = h.onInput_;
  770. const g = ump3.get(f) || function () {
  771. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  772. }
  773. ump3.set(f, g);
  774. g.km34 = 1;
  775. h.onInput_ = g;
  776.  
  777. }
  778.  
  779.  
  780. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  781.  
  782. const f = h.trigger_;
  783. const g = ump3.get(f) || function (a) {
  784. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  785. }
  786. ump3.set(f, g);
  787. g.km34 = 1;
  788. h.trigger_ = g;
  789.  
  790. }
  791.  
  792.  
  793. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  794.  
  795. const f = h.requestData_;
  796. const g = ump3.get(f) || function (a) {
  797. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  798. }
  799. ump3.set(f, g);
  800. g.km34 = 1;
  801. h.requestData_ = g;
  802.  
  803. }
  804.  
  805. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  806.  
  807. const f = h.onLoadReloadContinuation_;
  808. const g = ump3.get(f) || function (a, b) {
  809. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  810. }
  811. ump3.set(f, g);
  812. g.km34 = 1;
  813. h.onLoadReloadContinuation_ = g;
  814.  
  815. }
  816.  
  817.  
  818.  
  819. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  820.  
  821. const f = h.onLoadIncrementalContinuation_;
  822. const g = ump3.get(f) || function (a, b) {
  823. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  824. }
  825. ump3.set(f, g);
  826. g.km34 = 1;
  827. h.onLoadIncrementalContinuation_ = g;
  828.  
  829. }
  830.  
  831. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  832.  
  833. const f = h.onLoadSeekContinuation_;
  834. const g = ump3.get(f) || function (a, b) {
  835. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  836. }
  837. ump3.set(f, g);
  838. g.km34 = 1;
  839. h.onLoadSeekContinuation_ = g;
  840.  
  841. }
  842. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  843.  
  844. const f = h.onLoadReplayContinuation_;
  845. const g = ump3.get(f) || function (a, b) {
  846. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  847. }
  848. ump3.set(f, g);
  849. g.km34 = 1;
  850. h.onLoadReplayContinuation_ = g;
  851.  
  852. }
  853. if (typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  854.  
  855. const f = h.onNavigate_;
  856. const g = ump3.get(f) || function (a) {
  857. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  858. }
  859. ump3.set(f, g);
  860. g.km34 = 1;
  861. h.onNavigate_ = g;
  862.  
  863. }
  864.  
  865. /*
  866. if(typeof h.deferRenderStamperBinding_ ==='function' && !(h.deferRenderStamperBinding_.km34)){
  867.  
  868. const f = h.deferRenderStamperBinding_;
  869. const g = function(){
  870. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  871. }
  872. g.km34 = 1;
  873. h.deferRenderStamperBinding_ = g;
  874.  
  875. }
  876. */
  877.  
  878.  
  879.  
  880. if (typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  881.  
  882. const f = h.ytRendererBehaviorDataObserver_;
  883. const g = ump3.get(f) || function () {
  884. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  885. }
  886. ump3.set(f, g);
  887. g.km34 = 1;
  888. h.ytRendererBehaviorDataObserver_ = g;
  889.  
  890. }
  891.  
  892. if (typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  893.  
  894. const f = h.ytRendererBehaviorTargetIdObserver_;
  895. const g = ump3.get(f) || function () {
  896. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  897. }
  898. ump3.set(f, g);
  899. g.km34 = 1;
  900. h.ytRendererBehaviorTargetIdObserver_ = g;
  901.  
  902. }
  903.  
  904. if (typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  905.  
  906. const f = h.unregisterRenderer_;
  907. const g = ump3.get(f) || function (a) {
  908. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  909. }
  910. ump3.set(f, g);
  911. g.km34 = 1;
  912. h.unregisterRenderer_ = g;
  913.  
  914. }
  915.  
  916.  
  917.  
  918. if (typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  919.  
  920. const f = h.textChanged_;
  921. const g = ump3.get(f) || function (a) {
  922. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  923. }
  924. ump3.set(f, g);
  925. g.km34 = 1;
  926. h.textChanged_ = g;
  927.  
  928. }
  929.  
  930.  
  931.  
  932.  
  933. /*
  934. if(typeof h.stampDomArray_ ==='function' && !(h.stampDomArray_.km34)){
  935.  
  936. if( h.stampDomArray_.length === 6){
  937.  
  938. const f = h.stampDomArray_;
  939. const g = function(a,b,c,d,e,h){
  940. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  941. }
  942. g.km34 = 1;
  943. h.stampDomArray_ = g;
  944.  
  945. }else{
  946.  
  947.  
  948.  
  949. const f = h.stampDomArray_;
  950. const g = function(){
  951. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  952. }
  953. g.km34 = 1;
  954. h.stampDomArray_ = g;
  955. }
  956.  
  957.  
  958. }
  959. */
  960.  
  961. /*
  962. if(typeof h.stampDomArraySplices_ ==='function' && !(h.stampDomArraySplices_.km34)){
  963.  
  964. if(h.stampDomArraySplices_.length === 3){
  965.  
  966.  
  967.  
  968. const f = h.stampDomArraySplices_;
  969. const g = function(a,b,c){
  970. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  971. }
  972. g.km34 = 1;
  973. h.stampDomArraySplices_ = g;
  974.  
  975.  
  976. }else{
  977.  
  978.  
  979.  
  980. const f = h.stampDomArraySplices_;
  981. const g = function(){
  982. Promise.resolve().then(()=>f.apply(this, arguments)).catch(console.log);;
  983. }
  984. g.km34 = 1;
  985. h.stampDomArraySplices_ = g;
  986.  
  987.  
  988. }
  989.  
  990. }
  991. */
  992.  
  993.  
  994.  
  995.  
  996. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  997. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  998. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  999. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  1000. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  1001. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  1002.  
  1003.  
  1004.  
  1005. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  1006.  
  1007. const f = h.searchChanged_;
  1008. const g = ump3.get(f) || function () {
  1009. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1010. }
  1011. ump3.set(f, g);
  1012. g.km34 = 1;
  1013. h.searchChanged_ = g;
  1014.  
  1015. }
  1016.  
  1017. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  1018.  
  1019. const f = h.skinToneChanged_;
  1020. const g = ump3.get(f) || function (a) {
  1021. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1022. }
  1023. ump3.set(f, g);
  1024. g.km34 = 1;
  1025. h.skinToneChanged_ = g;
  1026.  
  1027. }
  1028.  
  1029. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  1030.  
  1031. const f = h.onEmojiHover_;
  1032. const g = ump3.get(f) || function (a) {
  1033. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1034. }
  1035. ump3.set(f, g);
  1036. g.km34 = 1;
  1037. h.onEmojiHover_ = g;
  1038.  
  1039. }
  1040.  
  1041. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  1042.  
  1043. const f = h.onSelectCategory_;
  1044. const g = ump3.get(f) || function (a) {
  1045. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1046. }
  1047. ump3.set(f, g);
  1048. g.km34 = 1;
  1049. h.onSelectCategory_ = g;
  1050.  
  1051. }
  1052.  
  1053. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  1054.  
  1055. const f = h.onShowEmojiVariantSelector;
  1056. const g = ump3.get(f) || function (a) {
  1057. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1058. }
  1059. ump3.set(f, g);
  1060. g.km34 = 1;
  1061. h.onShowEmojiVariantSelector = g;
  1062.  
  1063. }
  1064.  
  1065. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  1066.  
  1067. const f = h.updateCategoriesAndPlaceholder_;
  1068. const g = ump3.get(f) || function () {
  1069. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  1070. }
  1071. ump3.set(f, g);
  1072. g.km34 = 1;
  1073. h.updateCategoriesAndPlaceholder_ = g;
  1074.  
  1075. }
  1076.  
  1077.  
  1078. // console.log(123)
  1079.  
  1080. return;
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086. if (typeof h.dataChanged_ === 'function' && !(h.dataChanged_.km34)) {
  1087.  
  1088. const f = h.dataChanged_;
  1089. const g = function () {
  1090. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1091. }
  1092. g.km34 = 1;
  1093. h.dataChanged_ = g;
  1094.  
  1095. }
  1096.  
  1097.  
  1098. if (typeof h.addTextNodes_ === 'function' && !(h.addTextNodes_.km34)) {
  1099.  
  1100. const f = h.addTextNodes_;
  1101. const g = function () {
  1102. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1103. }
  1104. g.km34 = 1;
  1105. h.addTextNodes_ = g;
  1106.  
  1107. }
  1108.  
  1109.  
  1110.  
  1111.  
  1112. if (typeof h.updateText_ === 'function' && !(h.updateText_.km34)) {
  1113.  
  1114. const f = h.updateText_;
  1115. const g = function () {
  1116. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1117. }
  1118. g.km34 = 1;
  1119. h.updateText_ = g;
  1120.  
  1121. }
  1122.  
  1123.  
  1124.  
  1125.  
  1126. if (typeof h.flushRenderStamperComponentBindings_ === 'function' && !(h.flushRenderStamperComponentBindings_.km34)) {
  1127.  
  1128. const f = h.flushRenderStamperComponentBindings_;
  1129. const g = function () {
  1130. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1131. }
  1132. g.km34 = 1;
  1133. h.flushRenderStamperComponentBindings_ = g;
  1134.  
  1135. }
  1136.  
  1137.  
  1138. if (typeof h.forwardRendererStamperChanges_ === 'function' && !(h.forwardRendererStamperChanges_.km34)) {
  1139.  
  1140. const f = h.forwardRendererStamperChanges_;
  1141. const g = function () {
  1142. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1143. }
  1144. g.km34 = 1;
  1145. h.forwardRendererStamperChanges_ = g;
  1146.  
  1147. }
  1148.  
  1149.  
  1150.  
  1151. if (typeof h.stampTypeChanged_ === 'function' && !(h.stampTypeChanged_.km34)) {
  1152.  
  1153. const f = h.stampTypeChanged_;
  1154. const g = function () {
  1155. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1156. }
  1157. g.km34 = 1;
  1158. h.stampTypeChanged_ = g;
  1159.  
  1160. }
  1161.  
  1162.  
  1163. if (typeof h.rendererStamperApplyChangeRecord_ === 'function' && !(h.rendererStamperApplyChangeRecord_.km34)) {
  1164.  
  1165. const f = h.rendererStamperApplyChangeRecord_;
  1166. const g = function () {
  1167. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);;
  1168. }
  1169. g.km34 = 1;
  1170. h.rendererStamperApplyChangeRecord_ = g;
  1171.  
  1172. }
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179. }
  1180.  
  1181.  
  1182. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  1183. get() {
  1184. const f = this._stconnectedCallback;
  1185. setupDiscreteTasks(this, true);
  1186. if (f) this.ky36 = 1;
  1187. return f;
  1188. },
  1189. set(nv) {
  1190. this._stconnectedCallback = nv; // proto or object
  1191. setupDiscreteTasks(this);
  1192. return true;
  1193. },
  1194. enumerable: false,
  1195. configurable: true
  1196.  
  1197. });
  1198.  
  1199.  
  1200. const pLoad = new Promise(resolve => {
  1201. if (document.readyState !== 'loading') {
  1202. resolve();
  1203. } else {
  1204. window.addEventListener("DOMContentLoaded", resolve, false);
  1205. }
  1206. });
  1207. pLoad.then(() => {
  1208.  
  1209. let nonce = document.querySelector('style[nonce]');
  1210. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1211. const st = document.createElement('style');
  1212. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1213. st.textContent = "none-element-k47{order:0}";
  1214. st.addEventListener('load', () => {
  1215. pf31.resolve();
  1216. p59 = 1;
  1217. }, false);
  1218. document.body.appendChild(st);
  1219.  
  1220.  
  1221. // console.debug('90002', location.pathname)
  1222. // console.log(90000, location.pathname)
  1223.  
  1224. });
  1225.  
  1226. const prepareLogs = [];
  1227.  
  1228. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  1229.  
  1230. let winError00 = window.onerror;
  1231.  
  1232. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  1233.  
  1234. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  1235.  
  1236. ; FIX_Iframe_NULL_SRC && (() => {
  1237.  
  1238. let emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  1239. const lcOpt = { sensitivity: 'base' };
  1240. document.createElement24 = document.createElement;
  1241. document.createElement = function (t) {
  1242. if (typeof t === 'string' && t.length === 6) {
  1243. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  1244. let p = this.createElement24(t);
  1245. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  1246. return p;
  1247. }
  1248. }
  1249. return this.createElement24.apply(this, arguments);
  1250. };
  1251.  
  1252. })();
  1253.  
  1254. ; fix_error_many_stack_state === 1 && (() => {
  1255.  
  1256.  
  1257. let p1 = winError00;
  1258.  
  1259. let stackNeedleDetails = null;
  1260.  
  1261. Object.defineProperty(Object.prototype, 'matchAll', {
  1262. get() {
  1263. stackNeedleDetails = this;
  1264. return true;
  1265. },
  1266. enumerable: true,
  1267. configurable: true
  1268. });
  1269.  
  1270. try {
  1271. JSON.parse("{}");
  1272. } catch (e) {
  1273. console.warn(e)
  1274. fix_error_many_stack_state = 0;
  1275. }
  1276.  
  1277. delete Object.prototype['matchAll'];
  1278.  
  1279. let p2 = window.onerror;
  1280.  
  1281. window.onerror = p1;
  1282.  
  1283. if (fix_error_many_stack_state === 0) return;
  1284.  
  1285. if (stackNeedleDetails) {
  1286. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1287. stackNeedleDetails.matchAll = true;
  1288. }
  1289.  
  1290. if (p1 === p2) return (fix_error_many_stack_state = 0);
  1291.  
  1292. // p1!==p2
  1293. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  1294.  
  1295. })();
  1296.  
  1297. ; fix_error_many_stack_state === 2 && (() => {
  1298.  
  1299.  
  1300. let p1 = winError00;
  1301.  
  1302. let objectPrune = null;
  1303. let stackNeedleDetails = null;
  1304.  
  1305. Object.defineProperty(Function.prototype, 'findOwner', {
  1306. get() {
  1307. objectPrune = this;
  1308. return this._findOwner;
  1309. },
  1310. set(nv) {
  1311. this._findOwner = nv;
  1312. return true;
  1313. },
  1314. enumerable: true,
  1315. configurable: true
  1316. });
  1317.  
  1318. Object.defineProperty(Object.prototype, 'matchAll', {
  1319. get() {
  1320. stackNeedleDetails = this;
  1321. return true;
  1322. },
  1323. enumerable: true,
  1324. configurable: true
  1325. });
  1326.  
  1327. try {
  1328. JSON.parse("{}");
  1329. } catch (e) {
  1330. console.warn(e)
  1331. fix_error_many_stack_state = 0;
  1332. }
  1333.  
  1334. delete Function.prototype['findOwner'];
  1335. delete Object.prototype['matchAll'];
  1336.  
  1337. let p2 = window.onerror;
  1338.  
  1339. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  1340.  
  1341. if (fix_error_many_stack_state == 0) return;
  1342.  
  1343. // the following will only execute when Brave's scriptlets.js is executed.
  1344.  
  1345. prepareLogs.push("fix_error_many_stack_state NB")
  1346.  
  1347. if (stackNeedleDetails) {
  1348. stackNeedleDetails.pattern = null;
  1349. stackNeedleDetails.re = null;
  1350. stackNeedleDetails.expect = null;
  1351. stackNeedleDetails.matchAll = true;
  1352. }
  1353.  
  1354. if (objectPrune) {
  1355. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  1356. delete objectPrune._findOwner;
  1357. }
  1358.  
  1359. fix_error_many_stack_state = 3;
  1360. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  1361. JSON.parse.objectPrune = objectPrune;
  1362.  
  1363. })();
  1364.  
  1365. ; fix_error_many_stack_state === 3 && (() => {
  1366.  
  1367.  
  1368. let p1 = winError00;
  1369.  
  1370. try {
  1371. JSON.parse("{}");
  1372. } catch (e) {
  1373. console.warn(e)
  1374. fix_error_many_stack_state = 0;
  1375. }
  1376.  
  1377. let p2 = window.onerror;
  1378.  
  1379. if (p1 === p2) return;
  1380.  
  1381. window.onerror = p1;
  1382.  
  1383. if (fix_error_many_stack_state === 0) return;
  1384.  
  1385. fix_error_many_stack_state = 4; // p1 != p2
  1386.  
  1387.  
  1388. })();
  1389.  
  1390. fix_error_many_stack_state === 4 && (() => {
  1391.  
  1392. // the following will only execute when Brave's scriptlets.js is executed.
  1393.  
  1394. prepareLogs.push("fix_error_many_stack_state AB")
  1395.  
  1396. JSON.parseProxy = JSON.parse;
  1397.  
  1398. JSON.parse = ((parse) => {
  1399.  
  1400. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  1401. return function (text, reviver) {
  1402. const onerror = window.onerror;
  1403. window.onerror = null;
  1404. let r;
  1405. try {
  1406. r = parse(...arguments);
  1407. } catch (e) {
  1408. r = e;
  1409. }
  1410. window.onerror = onerror;
  1411. if (r instanceof Error) {
  1412. throw r;
  1413. }
  1414. return r;
  1415. }
  1416.  
  1417. })(JSON.parse);
  1418.  
  1419.  
  1420. })();
  1421.  
  1422.  
  1423.  
  1424. // ================================================ 0.4.5 ================================================
  1425.  
  1426.  
  1427. // ; (() => {
  1428.  
  1429. // if (FIX_error_many_stack && self instanceof Window) {
  1430. // // infinite stack due to matchesStackTrace inside objectPrune of AdsBlock
  1431.  
  1432. // const pdK = Object.getOwnPropertyDescriptor(window, 'onerror');
  1433. // if (!pdK || (pdK.get && pdK.configurable)) {
  1434.  
  1435. // } else {
  1436. // return;
  1437. // }
  1438.  
  1439. // let unsupportErrorFix = false;
  1440.  
  1441. // let firstHook = true;
  1442. // let busy33 = false;
  1443.  
  1444. // let state = 0;
  1445.  
  1446. // if (pdK) {
  1447. // delete window['onerror'];
  1448. // }
  1449.  
  1450. // const pd = {
  1451. // get() {
  1452. // const stack = (new Error()).stack;
  1453. // // targetStack = stack;
  1454. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  1455. // state = isGetExceptionToken ? 1 : 0;
  1456. // delete Window.prototype['onerror'];
  1457. // let r = pdK ? pdK.get.call(this) : this.onerror;
  1458. // Object.defineProperty(Window.prototype, 'onerror', pd);
  1459. // // console.log('onerror get', r)
  1460. // return r;
  1461. // },
  1462. // set(nv) {
  1463. // const stack = (new Error()).stack;
  1464. // let isGetExceptionToken = stack.indexOf('getExceptionToken') >= 0;
  1465. // state = state === 1 && isGetExceptionToken ? 2 : 0;
  1466. // /** @type {string?} */
  1467. // let sToken = null;
  1468. // if (unsupportErrorFix || busy33) {
  1469.  
  1470. // } else if (typeof nv === 'function' && state === 2) {
  1471. // if (firstHook) {
  1472. // firstHook = false;
  1473. // console.groupCollapsed('Infinite onerror Bug Found');
  1474. // console.log(location.href);
  1475. // console.log(stack);
  1476. // console.log(nv);
  1477. // console.groupEnd();
  1478. // }
  1479. // let _token = null;
  1480. // busy33 = true;
  1481. // String.prototype.includes76 = String.prototype.includes;
  1482. // String.prototype.includes = function (token) {
  1483. // _token = token;
  1484. // return true;
  1485. // }
  1486. // nv('token');
  1487. // String.prototype.includes = String.prototype.includes76;
  1488. // sToken = _token;
  1489. // busy33 = false;
  1490. // if (typeof sToken !== 'string') {
  1491. // unsupportErrorFix = true;
  1492. // }
  1493. // }
  1494. // delete Window.prototype['onerror'];
  1495. // if (typeof sToken === 'string' && sToken.length > 1) {
  1496. // /** @type {string} */
  1497. // const token = sToken;
  1498. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>?} } */
  1499. // const currentOnerror = pdK ? pdK.get.call(this) : this.onerror;
  1500.  
  1501. // const now = Date.now();
  1502. // const tokenEntry = {
  1503. // token,
  1504. // expired: now + FIX_error_many_stack_keepAliveDuration
  1505. // }
  1506. // /** @typedef {typeof tokenEntry} TokenEntry */
  1507.  
  1508. // /** @type {Set<TokenEntry>} */
  1509. // const errorTokens = currentOnerror.errorTokens;
  1510.  
  1511. // if (errorTokens) {
  1512. // if (errorTokens.size > FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than) {
  1513. // for (const entry of errorTokens) {
  1514. // if (entry.expired < now) {
  1515. // errorTokens.delete(entry);
  1516. // }
  1517. // }
  1518. // }
  1519. // errorTokens.add(tokenEntry)
  1520. // } else {
  1521. // /** @type {Set<TokenEntry>} */
  1522. // const errorTokens = new Set([tokenEntry]);
  1523. // /** @type {OnErrorEventHandler & {errorTokens: Set<string>} } */
  1524. // const newOnerror = ((oe) => {
  1525. // const r = function (msg, ...args) {
  1526. // if (typeof msg === 'string' && errorTokens.size > 0) {
  1527. // for (const entry of errorTokens) {
  1528. // if (msg.includes(entry.token)) return true;
  1529. // }
  1530. // }
  1531. // if (typeof oe === 'function') {
  1532. // return oe.apply(this, arguments);
  1533. // }
  1534. // };
  1535. // r.errorTokens = errorTokens;
  1536. // return r;
  1537. // })(currentOnerror);
  1538.  
  1539. // if (pdK && pdK.set) pdK.set.call(this, newOnerror);
  1540. // else this.onerror = newOnerror;
  1541. // }
  1542. // } else {
  1543. // if (pdK && pdK.set) pdK.set.call(this, nv);
  1544. // else this.onerror = nv;
  1545. // }
  1546. // Object.defineProperty(Window.prototype, 'onerror', pd);
  1547.  
  1548. // // console.log('onerror set', nv)
  1549. // return true;
  1550. // },
  1551. // enumerable: true,
  1552. // configurable: true
  1553. // }
  1554.  
  1555. // Object.defineProperty(Window.prototype, 'onerror', pd);
  1556.  
  1557.  
  1558. // }
  1559.  
  1560.  
  1561. // })();
  1562.  
  1563.  
  1564.  
  1565. // ================================================ 0.4.5 ================================================
  1566.  
  1567.  
  1568. // << if FIX_yt_player >>
  1569.  
  1570. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  1571. const PERF_471489_ = true;
  1572. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  1573. // This script uses a much gentle way to tamer the JS engine instead.
  1574.  
  1575. // << end >>
  1576.  
  1577. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  1578.  
  1579.  
  1580.  
  1581. const nilFn = () => { };
  1582.  
  1583. let isMainWindow = false;
  1584. try {
  1585. isMainWindow = window.document === window.top.document
  1586. } catch (e) { }
  1587.  
  1588. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  1589.  
  1590. const onRegistryReady = (callback) => {
  1591. if (typeof customElements === 'undefined') {
  1592. if (!('__CE_registry' in document)) {
  1593. // https://github.com/webcomponents/polyfills/
  1594. Object.defineProperty(document, '__CE_registry', {
  1595. get() {
  1596. // return undefined
  1597. },
  1598. set(nv) {
  1599. if (typeof nv == 'object') {
  1600. delete this.__CE_registry;
  1601. this.__CE_registry = nv;
  1602. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1603. }
  1604. return true;
  1605. },
  1606. enumerable: false,
  1607. configurable: true
  1608. })
  1609. }
  1610. let eventHandler = (evt) => {
  1611. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1612. const f = callback;
  1613. callback = null;
  1614. eventHandler = null;
  1615. f();
  1616. };
  1617. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1618. } else {
  1619. callback();
  1620. }
  1621. };
  1622.  
  1623.  
  1624. const assertor = (f) => f() || console.assert(false, f + "");
  1625.  
  1626. const fnIntegrity = (f, d) => {
  1627. if (!f || typeof f !== 'function') {
  1628. console.warn('f is not a function', f);
  1629. return;
  1630. }
  1631. let p = f + "", s = 0, j = -1, w = 0;
  1632. for (let i = 0, l = p.length; i < l; i++) {
  1633. const t = p[i];
  1634. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  1635. if (j < i - 1) w++;
  1636. j = i;
  1637. } else {
  1638. s++;
  1639. }
  1640. }
  1641. let itz = `${f.length}.${s}.${w}`;
  1642. if (!d) {
  1643. return itz;
  1644. } else {
  1645. return itz === d;
  1646. }
  1647. };
  1648.  
  1649. const getZq = (_yt_player) => {
  1650.  
  1651. const w = 'Zq';
  1652.  
  1653. let arr = [];
  1654.  
  1655. for (const [k, v] of Object.entries(_yt_player)) {
  1656.  
  1657. const p = typeof v === 'function' ? v.prototype : 0;
  1658. if (p
  1659. && typeof p.start === 'function' && p.start.length === 0
  1660. && typeof p.isActive === 'function' && p.isActive.length === 0
  1661. && typeof p.stop === 'function' && p.stop.length === 0
  1662. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  1663. && !p.send && !p.abort
  1664. && !p.sample && !p.initialize && !p.fail && !p.getName
  1665. // && !p.dispose && !p.isDisposed
  1666.  
  1667. ) {
  1668. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1669.  
  1670.  
  1671. }
  1672.  
  1673. }
  1674.  
  1675. if (arr.length === 0) {
  1676.  
  1677. console.warn(`Key does not exist. [${w}]`);
  1678. } else {
  1679.  
  1680. console.log(`[${w}]`, arr);
  1681. return arr[0];
  1682. }
  1683.  
  1684.  
  1685.  
  1686.  
  1687. }
  1688.  
  1689.  
  1690. const getVG = (_yt_player) => {
  1691. const w = 'VG';
  1692.  
  1693. let arr = [];
  1694.  
  1695. for (const [k, v] of Object.entries(_yt_player)) {
  1696.  
  1697. const p = typeof v === 'function' ? v.prototype : 0;
  1698. if (p
  1699. && typeof p.show === 'function' && p.show.length === 1
  1700. && typeof p.hide === 'function' && p.hide.length === 0
  1701. && typeof p.stop === 'function' && p.stop.length === 0) {
  1702.  
  1703. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1704.  
  1705. }
  1706.  
  1707. }
  1708.  
  1709.  
  1710. if (arr.length === 0) {
  1711.  
  1712. console.warn(`Key does not exist. [${w}]`);
  1713. } else {
  1714.  
  1715. console.log(`[${w}]`, arr);
  1716. return arr[0];
  1717. }
  1718.  
  1719.  
  1720.  
  1721. }
  1722.  
  1723.  
  1724. const getzo = (_yt_player) => {
  1725. const w = 'zo';
  1726.  
  1727. let arr = [];
  1728.  
  1729. for (const [k, v] of Object.entries(_yt_player)) {
  1730.  
  1731. if (
  1732. typeof v === 'function' && v.length === 3 && k.length < 3
  1733. && (v + "").includes("a.style[b]=c")
  1734. ) {
  1735.  
  1736. arr.push(k);
  1737.  
  1738. }
  1739.  
  1740. }
  1741.  
  1742.  
  1743. if (arr.length === 0) {
  1744.  
  1745. console.warn(`Key does not exist. [${w}]`);
  1746. } else {
  1747.  
  1748. console.log(`[${w}]`, arr);
  1749. return arr[0];
  1750. }
  1751.  
  1752. }
  1753.  
  1754. const addProtoToArr = (parent, key, arr) => {
  1755.  
  1756.  
  1757. let isChildProto = false;
  1758. for (const sr of arr) {
  1759. if (parent[key].prototype instanceof parent[sr]) {
  1760. isChildProto = true;
  1761. break;
  1762. }
  1763. }
  1764.  
  1765. if (isChildProto) return;
  1766.  
  1767. arr = arr.filter(sr => {
  1768. if (parent[sr].prototype instanceof parent[key]) {
  1769. return false;
  1770. }
  1771. return true;
  1772. });
  1773.  
  1774. arr.push(key);
  1775.  
  1776. return arr;
  1777.  
  1778.  
  1779. }
  1780.  
  1781. const getuG = (_yt_player) => {
  1782.  
  1783. const w = 'uG';
  1784.  
  1785. let arr = [];
  1786.  
  1787. for (const [k, v] of Object.entries(_yt_player)) {
  1788.  
  1789.  
  1790. const p = typeof v === 'function' ? v.prototype : 0;
  1791.  
  1792. if (p
  1793. && typeof p.createElement === 'function' && p.createElement.length === 2
  1794. && typeof p.detach === 'function' && p.detach.length === 0
  1795. && typeof p.update === 'function' && p.update.length === 1
  1796. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  1797. ) {
  1798.  
  1799. arr = addProtoToArr(_yt_player, k, arr) || arr;
  1800.  
  1801. }
  1802.  
  1803. }
  1804.  
  1805.  
  1806.  
  1807.  
  1808.  
  1809. if (arr.length === 0) {
  1810.  
  1811. console.warn(`Key does not exist. [${w}]`);
  1812. } else {
  1813.  
  1814. console.log(`[${w}]`, arr);
  1815. return arr[0];
  1816. }
  1817.  
  1818. }
  1819.  
  1820.  
  1821.  
  1822. // << if FIX_schedulerInstanceInstance_ >>
  1823.  
  1824. let idleFrom = Date.now() + 2700;
  1825. let slowMode = false;
  1826.  
  1827. let ytEvented = false;
  1828.  
  1829.  
  1830. const setupEvents = FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 ? () => {
  1831.  
  1832. document.addEventListener('yt-navigate', () => {
  1833.  
  1834. ytEvented = true;
  1835. slowMode = false;
  1836. idleFrom = Date.now() + 2700;
  1837.  
  1838. });
  1839. document.addEventListener('yt-navigate-start', () => {
  1840.  
  1841. ytEvented = true;
  1842. slowMode = false;
  1843. idleFrom = Date.now() + 2700;
  1844.  
  1845. });
  1846.  
  1847. document.addEventListener('yt-page-type-changed', () => {
  1848.  
  1849. ytEvented = true;
  1850. slowMode = false;
  1851. idleFrom = Date.now() + 1700;
  1852.  
  1853. });
  1854.  
  1855.  
  1856. document.addEventListener('yt-player-updated', () => {
  1857.  
  1858. ytEvented = true;
  1859. slowMode = false;
  1860. idleFrom = Date.now() + 1700;
  1861.  
  1862. });
  1863.  
  1864.  
  1865. document.addEventListener('yt-page-data-fetched', () => {
  1866.  
  1867. ytEvented = true;
  1868. slowMode = false;
  1869. idleFrom = Date.now() + 1700;
  1870.  
  1871. });
  1872.  
  1873. document.addEventListener('yt-navigate-finish', () => {
  1874.  
  1875. ytEvented = true;
  1876. slowMode = false;
  1877. let t = Date.now() + 700;
  1878. if (t > idleFrom) idleFrom = t;
  1879.  
  1880. });
  1881.  
  1882. document.addEventListener('yt-page-data-updated', () => {
  1883.  
  1884. ytEvented = true;
  1885. slowMode = false;
  1886. let t = Date.now() + 700;
  1887. if (t > idleFrom) idleFrom = t;
  1888.  
  1889. });
  1890.  
  1891. document.addEventListener('yt-watch-comments-ready', () => {
  1892.  
  1893. ytEvented = true;
  1894. slowMode = false;
  1895. let t = Date.now() + 700;
  1896. if (t > idleFrom) idleFrom = t;
  1897.  
  1898. });
  1899. } : () => { };
  1900.  
  1901.  
  1902. // << end >>
  1903.  
  1904. const cleanContext = async (win) => {
  1905. const waitFn = requestAnimationFrame; // shall have been binded to window
  1906. try {
  1907. let mx = 16; // MAX TRIAL
  1908. const frameId = 'vanillajs-iframe-v1';
  1909. /** @type {HTMLIFrameElement | null} */
  1910. let frame = document.getElementById(frameId);
  1911. let removeIframeFn = null;
  1912. if (!frame) {
  1913. frame = document.createElement('iframe');
  1914. frame.id = frameId;
  1915. const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  1916. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  1917. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  1918. n.appendChild(frame);
  1919. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  1920. const root = document.documentElement;
  1921. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  1922. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  1923.  
  1924. removeIframeFn = (setTimeout) => {
  1925. const removeIframeOnDocumentReady = (e) => {
  1926. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1927. win = null;
  1928. const m = n;
  1929. n = null;
  1930. setTimeout(() => m.remove(), 200);
  1931. }
  1932. if (document.readyState !== 'loading') {
  1933. removeIframeOnDocumentReady();
  1934. } else {
  1935. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  1936. }
  1937. }
  1938. }
  1939. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  1940. const fc = frame.contentWindow;
  1941. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  1942. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  1943. const res = { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  1944. for (let k in res) res[k] = res[k].bind(win); // necessary
  1945. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  1946. res.animate = fc.HTMLElement.prototype.animate;
  1947. return res;
  1948. } catch (e) {
  1949. console.warn(e);
  1950. return null;
  1951. }
  1952. };
  1953.  
  1954.  
  1955. const promiseForCustomYtElementsReady = new Promise(onRegistryReady);
  1956.  
  1957. cleanContext(window).then(__CONTEXT__ => {
  1958. if (!__CONTEXT__) return null;
  1959.  
  1960. const { requestAnimationFrame, setTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle } = __CONTEXT__;
  1961.  
  1962. __requestAnimationFrame__ = requestAnimationFrame;
  1963.  
  1964. let rafPromise = null;
  1965.  
  1966. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  1967. requestAnimationFrame(hRes => {
  1968. rafPromise = null;
  1969. resolve(hRes);
  1970. });
  1971. }));
  1972.  
  1973. const getForegroundPromise = () => {
  1974. if (document.visibilityState === 'visible') {
  1975. return Promise.resolve();
  1976. } else {
  1977. return getRafPromise();
  1978. }
  1979. };
  1980.  
  1981. NO_PRELOAD_GENERATE_204_BYPASS || promiseForCustomYtElementsReady.then(() => {
  1982. setTimeout(() => {
  1983. NO_PRELOAD_GENERATE_204_BYPASS = true;
  1984. }, 1270);
  1985. });
  1986.  
  1987. const promiseForTamerTimeout = new Promise(resolve => {
  1988. promiseForCustomYtElementsReady.then(() => {
  1989. customElements.whenDefined('ytd-app').then(() => {
  1990. setTimeout(resolve, 1200);
  1991. });
  1992. });
  1993. setTimeout(resolve, 3000);
  1994. });
  1995.  
  1996.  
  1997. class RAFHub {
  1998. constructor() {
  1999. /** @type {number} */
  2000. this.startAt = 8170;
  2001. /** @type {number} */
  2002. this.counter = 0;
  2003. /** @type {number} */
  2004. this.rid = 0;
  2005. /** @type {Map<number, FrameRequestCallback>} */
  2006. this.funcs = new Map();
  2007. const funcs = this.funcs;
  2008. /** @type {FrameRequestCallback} */
  2009. this.bCallback = this.mCallback.bind(this);
  2010. this.pClear = () => funcs.clear();
  2011. }
  2012. /** @param {DOMHighResTimeStamp} highResTime */
  2013. mCallback(highResTime) {
  2014. this.rid = 0;
  2015. Promise.resolve().then(this.pClear);
  2016. this.funcs.forEach(func => Promise.resolve(highResTime).then(func).catch(console.warn));
  2017. }
  2018. /** @param {FrameRequestCallback} f */
  2019. request(f) {
  2020. if (this.counter > 1e9) this.counter = 9;
  2021. let cid = this.startAt + (++this.counter);
  2022. this.funcs.set(cid, f);
  2023. if (this.rid === 0) {
  2024. console.log(2455)
  2025. this.rid = requestAnimationFrame(this.bCallback);
  2026. }
  2027. return cid;
  2028. }
  2029. /** @param {number} cid */
  2030. cancel(cid) {
  2031. cid = +cid;
  2032. if (cid > 0) {
  2033. if (cid <= this.startAt) {
  2034. return cancelAnimationFrame(cid);
  2035. }
  2036. if (this.rid > 0) {
  2037. this.funcs.delete(cid);
  2038. if (this.funcs.size === 0) {
  2039. cancelAnimationFrame(this.rid);
  2040. this.rid = 0;
  2041. }
  2042. }
  2043. }
  2044. }
  2045. /** @param {number} cid */
  2046. /** @param {FrameRequestCallback} f */
  2047. replaceFunc(cid, f) {
  2048. if (typeof this.funcs.get(cid) === 'function') {
  2049. this.funcs.set(cid, f);
  2050. return cid;
  2051. } else {
  2052. let r = this.request(f);
  2053. this.cancel(cid);
  2054. return r;
  2055. }
  2056. }
  2057. }
  2058.  
  2059.  
  2060.  
  2061. NATIVE_CANVAS_ANIMATION && (() => {
  2062.  
  2063. HTMLCanvasElement.prototype.animate = animate;
  2064.  
  2065. let cid = setInterval(() => {
  2066. HTMLCanvasElement.prototype.animate = animate;
  2067. }, 1);
  2068.  
  2069. promiseForTamerTimeout.then(() => {
  2070. clearInterval(cid)
  2071. });
  2072.  
  2073. })();
  2074.  
  2075. FIX_ytAction_ && (async () => {
  2076.  
  2077. const ytdApp = await new Promise(resolve => {
  2078.  
  2079. promiseForCustomYtElementsReady.then(() => {
  2080. customElements.whenDefined('ytd-app').then(() => {
  2081. const ytdApp = document.querySelector('ytd-app');
  2082. if (ytdApp) {
  2083. resolve(ytdApp);
  2084. return;
  2085. }
  2086. let mo = new MutationObserver(() => {
  2087. const ytdApp = document.querySelector('ytd-app');
  2088. if (!ytdApp) return;
  2089. if (mo) {
  2090. mo.disconnect();
  2091. mo.takeRecords();
  2092. mo = null;
  2093. }
  2094. resolve(ytdApp);
  2095. });
  2096. mo.observe(document, { subtree: true, childList: true });
  2097. });
  2098. });
  2099.  
  2100.  
  2101.  
  2102. });
  2103.  
  2104.  
  2105.  
  2106. if (!ytdApp) return;
  2107. const cProto = (ytdApp.inst || ytdApp).constructor.prototype;
  2108.  
  2109.  
  2110. if (!cProto) return;
  2111. let mbd = 0;
  2112.  
  2113. const fixer = (_ytdApp) => {
  2114.  
  2115. const ytdApp = _ytdApp ? (_ytdApp.inst || _ytdApp) : null;
  2116.  
  2117. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  2118. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  2119. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  2120. mbd++;
  2121. }
  2122.  
  2123.  
  2124. }
  2125.  
  2126. let cid = setInterval(() => {
  2127.  
  2128.  
  2129. if (typeof cProto.created === 'function' && !cProto.created57) {
  2130. cProto.created57 = cProto.created;
  2131. cProto.created = function (...args) {
  2132. const r = this.created57(...args);
  2133. fixer(this);
  2134. return r;
  2135. };
  2136. mbd++;
  2137. }
  2138.  
  2139.  
  2140. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  2141. cProto.onYtAction57_ = cProto.onYtAction_;
  2142. cProto.onYtAction_ = function (...args) {
  2143. Promise.resolve().then(() => this.onYtAction57_(...args));
  2144. };
  2145. mbd++;
  2146. }
  2147.  
  2148. if (ytdApp) fixer(ytdApp);
  2149.  
  2150. /*
  2151. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  2152. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  2153. actionRouter_.handleAction57 = actionRouter_.handleAction;
  2154. actionRouter_.handleAction = function (...args) {
  2155. Promise.resolve().then(() => this.handleAction57(...args));
  2156. }
  2157. mbd++;
  2158. }
  2159. */
  2160.  
  2161. // if(mbd === 3) clearInterval(cid);
  2162. if (mbd >= 3) clearInterval(cid);
  2163.  
  2164. }, 1);
  2165.  
  2166. setTimeout(() => {
  2167.  
  2168. clearInterval(cid);
  2169. }, 1000);
  2170.  
  2171. })();
  2172.  
  2173.  
  2174. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  2175.  
  2176. const evKey = `${_evKey}`;
  2177. const fvKey = `${_fvKey}`;
  2178. const debug = !!_debug;
  2179.  
  2180.  
  2181. // const rafHub = new RAFHub();
  2182.  
  2183.  
  2184. const _yt_player = await new Promise(resolve => {
  2185.  
  2186. let cid = setInterval(() => {
  2187. let t = (((window || 0)._yt_player || 0) || 0);
  2188. if (t) {
  2189.  
  2190. clearInterval(cid);
  2191. resolve(t);
  2192. }
  2193. }, 1);
  2194.  
  2195. promiseForTamerTimeout.then(() => {
  2196. resolve(null)
  2197. });
  2198.  
  2199. });
  2200.  
  2201.  
  2202. if (!_yt_player || typeof _yt_player !== 'object') return;
  2203.  
  2204.  
  2205. const getArr = (_yt_player) => {
  2206.  
  2207. let arr = [];
  2208.  
  2209. for (const [k, v] of Object.entries(_yt_player)) {
  2210.  
  2211. const p = typeof v === 'function' ? v.prototype : 0;
  2212. if (p
  2213. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  2214.  
  2215. ) {
  2216. arr = addProtoToArr(_yt_player, k, arr) || arr;
  2217.  
  2218. }
  2219.  
  2220. }
  2221.  
  2222. if (arr.length === 0) {
  2223.  
  2224. console.warn(`Key prop [${evKey}] does not exist.`);
  2225. } else {
  2226.  
  2227. return arr;
  2228. }
  2229.  
  2230. };
  2231.  
  2232. const arr = getArr(_yt_player);
  2233.  
  2234.  
  2235. if (!arr) return;
  2236.  
  2237. debug && console.log(`FIX_${evKey}`, arr);
  2238.  
  2239. const f = function (...args) {
  2240. Promise.resolve().then(() => this[fvKey](...args));
  2241. };
  2242.  
  2243.  
  2244. for (const k of arr) {
  2245.  
  2246. const g = _yt_player;
  2247. const gk = g[k];
  2248. const gkp = gk.prototype;
  2249.  
  2250. debug && console.log(237, k, gkp)
  2251.  
  2252. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  2253. gkp[fvKey] = gkp[evKey];
  2254. gkp[evKey] = f;
  2255. }
  2256. }
  2257.  
  2258.  
  2259.  
  2260.  
  2261. }
  2262.  
  2263. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  2264. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  2265. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  2266. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  2267. if (FIX_VideoEVENTS) {
  2268. const FIX_VideoEVENTS_DEBUG = 0;
  2269. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG);
  2270. generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  2271. generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG);
  2272. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG);
  2273. generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  2274. generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  2275. generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  2276. generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  2277. generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  2278.  
  2279. }
  2280. // onMutedAutoplayChange
  2281. // onVolumeChange
  2282. // onPlaybackRateChange
  2283.  
  2284. // onAirPlayActiveChange
  2285. // onAirPlayAvailabilityChange
  2286. // onApiChange
  2287. // onAutoplayBlocked
  2288. // onDrmOutputRestricted
  2289. // onFullscreenChange
  2290. // onLoadProgress
  2291. // onLoadedMetadata
  2292. // onVideoDataChange
  2293. // onVideoProgress
  2294.  
  2295. FIX_maybeUpdateFlexibleMenu && (async () => {
  2296.  
  2297.  
  2298. const dummy = await new Promise(resolve => {
  2299.  
  2300. promiseForCustomYtElementsReady.then(() => {
  2301. customElements.whenDefined('ytd-menu-renderer').then(() => {
  2302.  
  2303. resolve(document.createElement('ytd-menu-renderer'));
  2304. });
  2305. });
  2306.  
  2307.  
  2308.  
  2309. });
  2310.  
  2311.  
  2312. if (!dummy || dummy.is !== 'ytd-menu-renderer') return;
  2313.  
  2314. const cProto = (dummy.inst || dummy).constructor.prototype;
  2315.  
  2316. if (typeof cProto.created === 'function' && !cProto.created57) {
  2317. cProto.created57 = cProto.created;
  2318. cProto.created = function (...args) {
  2319. const r = this.created57(...args);
  2320. if (typeof this.maybeUpdateFlexibleMenu === 'function' && !this.maybeUpdateFlexibleMenu57) {
  2321. this.maybeUpdateFlexibleMenu57 = this.maybeUpdateFlexibleMenu;
  2322. this.maybeUpdateFlexibleMenu = function (...args) {
  2323. Promise.resolve().then(() => this.maybeUpdateFlexibleMenu57(...args));
  2324. }
  2325. }
  2326. return r;
  2327. }
  2328.  
  2329. }
  2330.  
  2331. //console.log(144,cProto.maybeUpdateFlexibleMenu)
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338. })();
  2339.  
  2340. ENABLE_discreteTasking && (async () => {
  2341.  
  2342. const Polymer = await new Promise(resolve => {
  2343.  
  2344. let cid = 0;
  2345. const f = () => {
  2346. const Polymer = window.Polymer;
  2347. if (typeof Polymer !== 'function') return;
  2348. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  2349. cid && clearInterval(cid);
  2350. cid = 0;
  2351. resolve(Polymer);
  2352. };
  2353. cid = setInterval(f, 1);
  2354.  
  2355. });
  2356. if (!Polymer) return;
  2357.  
  2358. Polymer.Base.__connInit__ = function () {
  2359. setupDiscreteTasks(this);
  2360. }
  2361.  
  2362.  
  2363. /** @type {Function} */
  2364. const connectedCallbackK = function (...args) {
  2365. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2366. const r = this.connectedCallback53(...args);
  2367. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2368. this.mh35 = 1;
  2369. return r;
  2370. };
  2371.  
  2372.  
  2373. // /** @type {Function} */
  2374. // const disconnectedCallbackK = function (...args) {
  2375. // typeof this.__connInit__ === 'function' && this.__connInit__();
  2376. // this.disconnectedCallback53(...args);
  2377. // typeof this.__connInit__ === 'function' && this.__connInit__();
  2378. // };
  2379.  
  2380.  
  2381. connectedCallbackK.m353 = 1;
  2382. // disconnectedCallbackK.m353 = 1;
  2383.  
  2384.  
  2385.  
  2386. Polymer.Base.connectedCallback53 = Polymer.Base.connectedCallback;
  2387. // Polymer.Base.disconnectedCallback53 = Polymer.Base.disconnectedCallback;
  2388.  
  2389. Polymer.Base.connectedCallback = connectedCallbackK;
  2390. // Polymer.Base.disconnectedCallback = disconnectedCallbackK;
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397. /** @type {Function} */
  2398. const createdK = function (...args) {
  2399. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2400. const r = this.created53(...args);
  2401. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  2402. this.mh36 = 1;
  2403. return r;
  2404. };
  2405.  
  2406.  
  2407. createdK.m353 = 1;
  2408. Polymer.Base.created53 = Polymer.Base.created;
  2409. Polymer.Base.created = createdK;
  2410.  
  2411.  
  2412.  
  2413. })();
  2414. const FIX_PolymerBase = false;
  2415. FIX_PolymerBase && (async () => {
  2416.  
  2417. const Polymer = await new Promise(resolve => {
  2418.  
  2419. let cid = 0;
  2420. const f = () => {
  2421. const Polymer = window.Polymer;
  2422. if (typeof Polymer !== 'function') return;
  2423. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  2424. cid && clearInterval(cid);
  2425. cid = 0;
  2426. resolve(Polymer);
  2427. };
  2428. cid = setInterval(f, 1);
  2429.  
  2430. });
  2431. if (!Polymer) return;
  2432.  
  2433. /*
  2434. Polymer.Base.connectedCallback =function(...args){
  2435. const c = Date.now();
  2436. const p = this.callbackSyncLastTimestamp;
  2437. this.callbackSyncLastTimestamp = c;
  2438. if(c - p < 4 && c >= p){
  2439. this.connectedCallback53(...args);
  2440. }else{
  2441. Promise.resolve().then(()=>this.connectedCallback53(...args))
  2442. }
  2443. };
  2444. Polymer.Base.disconnectedCallback =function(){
  2445. const c = Date.now();
  2446. const p = this.callbackSyncLastTimestamp;
  2447. this.callbackSyncLastTimestamp = c;
  2448. if(c - p < 4 && c >= p){
  2449. this.disconnectedCallback53(...args);
  2450. }else{
  2451. Promise.resolve().then(()=>this.disconnectedCallback53(...args))
  2452. }
  2453. };
  2454. */
  2455.  
  2456. /** @type {Function} */
  2457. const attachedK = function (...args) {
  2458. this.connPromise = this.connPromise.then(() => this.attached53(...args)).catch(console.warn);
  2459. }
  2460.  
  2461. /** @type {Function} */
  2462. const detachedK = function (...args) {
  2463. this.connPromise = this.connPromise.then(() => this.detached53(...args)).catch(console.warn);
  2464. }
  2465.  
  2466. /** @type {Function} */
  2467. const _removeListenersK = function () {
  2468. if (!this.$) this.$ = {};
  2469. this._removeListeners53();
  2470. }
  2471.  
  2472. /** @type {Function} */
  2473. const unlistenK = function (...args) {
  2474. if (!args[0]) return;
  2475. this.unlisten53(...args);
  2476. }
  2477.  
  2478.  
  2479. /** @type {Function} */
  2480. const connectedCallbackK = function (...args) {
  2481. typeof this.__connInit__ === 'function' && this.__connInit__();
  2482. this.connPromise = this.connPromise.then(() => this.connectedCallback53(...args)).catch(console.warn);
  2483. };
  2484.  
  2485. /** @type {Function} */
  2486. const disconnectedCallbackK = function () {
  2487. typeof this.__connInit__ === 'function' && this.__connInit__();
  2488. if (this._removeListeners && this._removeListeners53) this._removeListeners();
  2489. this.connPromise = this.connPromise.then(() => this.disconnectedCallback53(...args)).catch(console.warn);
  2490. };
  2491.  
  2492.  
  2493. connectedCallbackK.m353 = 1;
  2494. disconnectedCallbackK.m353 = 1;
  2495.  
  2496.  
  2497. Polymer.Base.__connInit__ = function () {
  2498. if (!this.connPromise) this.connPromise = Promise.resolve();
  2499. if (typeof this.attached === 'function' && !this.attached53) {
  2500. this.attached53 = this.attached;
  2501. this.attached = attachedK;
  2502. }
  2503. if (typeof this.detached === 'function' && !this.detached53) {
  2504. this.detached53 = this.detached;
  2505. this.detached = detachedK;
  2506. }
  2507. if (typeof this._removeListeners === 'function' && !this._removeListeners53 && this._removeListeners.length === 0) {
  2508. this._removeListeners53 = this._removeListeners;
  2509. this._removeListeners = _removeListenersK;
  2510. if (typeof this.unlisten === 'function' && !this.unlisten53) {
  2511. this.unlisten53 = this.unlisten;
  2512. this.unlisten = unlistenK;
  2513. }
  2514. }
  2515.  
  2516. if (this.connectedCallback && !this.connectedCallback.m353 && !this.connectedCallback53) {
  2517.  
  2518. Polymer.Base.connectedCallback53 = Polymer.Base.connectedCallback;
  2519.  
  2520. Polymer.Base.connectedCallback = connectedCallbackK;
  2521. }
  2522.  
  2523. if (this.disconnectedCallback && !this.disconnectedCallback.m353 && !this.disconnectedCallback53) {
  2524.  
  2525. Polymer.Base.disconnectedCallback53 = Polymer.Base.disconnectedCallback;
  2526.  
  2527. Polymer.Base.disconnectedCallback = disconnectedCallbackK;
  2528. }
  2529. }
  2530.  
  2531. Polymer.Base.connectedCallback53 = Polymer.Base.connectedCallback;
  2532. Polymer.Base.disconnectedCallback53 = Polymer.Base.disconnectedCallback;
  2533.  
  2534. Polymer.Base.connectedCallback = connectedCallbackK;
  2535. Polymer.Base.disconnectedCallback = disconnectedCallbackK;
  2536.  
  2537.  
  2538.  
  2539. })();
  2540.  
  2541. CHANGE_appendChild && (() => {
  2542.  
  2543. HTMLElement.prototype.appendChild73 = HTMLElement.prototype.appendChild;
  2544. HTMLElement.prototype.appendChild = function (a) {
  2545.  
  2546.  
  2547. if (this instanceof HTMLElement) {
  2548.  
  2549. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  2550. for (let node = this.firstElementChild; node instanceof HTMLElement; node = node.nextElementSibling) {
  2551. if (node.nodeName === 'LINK' && node.rel === 'preload' && node.as === 'fetch' && !node.__m848__) {
  2552. node.__m848__ = 1;
  2553. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  2554. }
  2555. }
  2556. } else if (this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  2557. return this.appendChild73.apply(this, arguments);
  2558. }
  2559.  
  2560. if (a instanceof DocumentFragment) {
  2561. if (a.firstElementChild === null) {
  2562. let child = a.firstChild;
  2563. if (child === null) return a;
  2564. let doNormal = false;
  2565. while (child instanceof Node) {
  2566. if (child.nodeType === 3) { doNormal = true; break; }
  2567. child = child.nextSibling;
  2568. }
  2569. if (!doNormal) return a;
  2570. }
  2571. }
  2572.  
  2573. }
  2574.  
  2575.  
  2576. return this.appendChild73.apply(this, arguments)
  2577. }
  2578.  
  2579.  
  2580. })();
  2581.  
  2582. if (FIX_Shady) {
  2583.  
  2584. let cidSL = setInterval(() => {
  2585. const { ShadyDOM, ShadyCSS } = window;
  2586. if (ShadyDOM && ShadyCSS) {
  2587. clearInterval(cidSL);
  2588. cidSL = 0;
  2589. }
  2590. if (ShadyDOM) {
  2591. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  2592. ShadyDOM.noPatch = true; // 1 of 10
  2593. ShadyDOM.patchOnDemand = false; // 1 of 10
  2594. ShadyDOM.preferPerformance = true; // 1 of 10
  2595. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  2596. }
  2597. if (ShadyCSS) {
  2598. ShadyCSS.nativeCss = true; // 1 of 10
  2599. ShadyCSS.nativeShadow = true; // 6 of 10
  2600. ShadyCSS.cssBuild = undefined; // 1 of 10
  2601. ShadyCSS.disableRuntime = true; // 1 of 10
  2602. }
  2603. }, 1);
  2604.  
  2605. }
  2606.  
  2607.  
  2608. FIX_schedulerInstanceInstance_V1 && !FIX_schedulerInstanceInstance_V2 && (async () => {
  2609.  
  2610.  
  2611. const schedulerInstanceInstance_ = await new Promise(resolve => {
  2612.  
  2613. let cid = setInterval(() => {
  2614. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2615. if (t) {
  2616.  
  2617. clearInterval(cid);
  2618. resolve(t);
  2619. }
  2620. }, 1);
  2621. promiseForTamerTimeout.then(() => {
  2622. resolve(null)
  2623. });
  2624. });
  2625.  
  2626. if (!schedulerInstanceInstance_) return;
  2627.  
  2628.  
  2629. if (!ytEvented) {
  2630. idleFrom = Date.now() + 2700;
  2631. slowMode = false; // integrity
  2632. }
  2633.  
  2634. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2635. if (checkOK) {
  2636.  
  2637.  
  2638. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  2639.  
  2640. let requestingFn = null;
  2641. let requestingArgs = null;
  2642. let requestingDT = 0;
  2643.  
  2644. // let timerId = null;
  2645. const entries = [];
  2646. const f = function () {
  2647. requestingFn = this.fn;
  2648. requestingArgs = [...arguments];
  2649. requestingDT = Date.now();
  2650. entries.push({
  2651. fn: requestingFn,
  2652. args: requestingArgs,
  2653. t: requestingDT
  2654. });
  2655. // if (Date.now() < idleFrom) {
  2656. // timerId = this.fn.apply(window, arguments);
  2657. // } else {
  2658. // timerId = this.fn.apply(window, arguments);
  2659.  
  2660. // }
  2661. // timerId = 12377;
  2662. return 12377;
  2663. }
  2664.  
  2665.  
  2666. const fakeFns = [
  2667. f.bind({ fn: requestAnimationFrame }),
  2668. f.bind({ fn: setInterval }),
  2669. f.bind({ fn: setTimeout }),
  2670. f.bind({ fn: requestIdleCallback })
  2671. ]
  2672.  
  2673.  
  2674.  
  2675.  
  2676. let timerResolve = null;
  2677. setInterval(() => {
  2678. timerResolve && timerResolve();
  2679. timerResolve = null;
  2680. if (!slowMode && Date.now() > idleFrom) slowMode = true;
  2681. }, 250);
  2682.  
  2683. let mzt = 0;
  2684.  
  2685. let fnSelectorProp = null;
  2686.  
  2687. schedulerInstanceInstance_.start = function () {
  2688.  
  2689. const mk1 = window.requestAnimationFrame
  2690. const mk2 = window.setInterval
  2691. const mk3 = window.setTimeout
  2692. const mk4 = window.requestIdleCallback
  2693.  
  2694. const tThis = this['$$12378$$'] || this;
  2695.  
  2696.  
  2697. window.requestAnimationFrame = fakeFns[0]
  2698. window.setInterval = fakeFns[1]
  2699. window.setTimeout = fakeFns[2]
  2700. window.requestIdleCallback = fakeFns[3]
  2701.  
  2702. fnSelectorProp = null;
  2703.  
  2704.  
  2705. tThis.start991.call(new Proxy(tThis, {
  2706. get(target, prop, receiver) {
  2707. if (prop === '$$12377$$') return true;
  2708. if (prop === '$$12378$$') return target;
  2709.  
  2710. // console.log('get',prop)
  2711. return target[prop]
  2712. },
  2713. set(target, prop, value, receiver) {
  2714. // console.log('set', prop, value)
  2715.  
  2716.  
  2717. if (value >= 1 && value <= 4) fnSelectorProp = prop;
  2718. if (value === 12377 && fnSelectorProp) {
  2719.  
  2720. const originalSelection = target[fnSelectorProp];
  2721. const timerIdProp = prop;
  2722.  
  2723. /*
  2724.  
  2725.  
  2726. case 1:
  2727. var a = this.K;
  2728. this.g = this.I ? window.requestIdleCallback(a, {
  2729. timeout: 3E3
  2730. }) : window.setTimeout(a, ma);
  2731. break;
  2732. case 2:
  2733. this.g = window.setTimeout(this.M, this.N);
  2734. break;
  2735. case 3:
  2736. this.g = window.requestAnimationFrame(this.L);
  2737. break;
  2738. case 4:
  2739. this.g = window.setTimeout(this.J, 0)
  2740. }
  2741.  
  2742. */
  2743.  
  2744. const doForegroundSlowMode = () => {
  2745.  
  2746. const tir = ++mzt;
  2747. const f = requestingArgs[0];
  2748.  
  2749.  
  2750. getForegroundPromise().then(() => {
  2751.  
  2752.  
  2753. new Promise(r => {
  2754. timerResolve = r
  2755. }).then(() => {
  2756. if (target[timerIdProp] === -tir) f();
  2757. });
  2758.  
  2759. })
  2760.  
  2761. target[fnSelectorProp] = 931;
  2762. target[prop] = -tir;
  2763. }
  2764.  
  2765. if (target[fnSelectorProp] === 2 && requestingFn === setTimeout) {
  2766. if (slowMode && !(requestingArgs[1] > 250)) {
  2767.  
  2768. doForegroundSlowMode();
  2769.  
  2770. } else {
  2771. target[prop] = setTimeout.apply(window, requestingArgs);
  2772.  
  2773. }
  2774.  
  2775. } else if (target[fnSelectorProp] === 3 && requestingFn === requestAnimationFrame) {
  2776.  
  2777. if (slowMode) {
  2778.  
  2779. doForegroundSlowMode();
  2780.  
  2781. } else {
  2782. target[prop] = requestAnimationFrame.apply(window, requestingArgs);
  2783. }
  2784.  
  2785.  
  2786. } else if (target[fnSelectorProp] === 4 && requestingFn === setTimeout && !requestingArgs[1]) {
  2787.  
  2788. const f = requestingArgs[0];
  2789. const tir = ++mzt;
  2790. Promise.resolve().then(() => {
  2791. if (target[timerIdProp] === -tir) f();
  2792. });
  2793. target[fnSelectorProp] = 930;
  2794. target[prop] = -tir;
  2795.  
  2796. } else if (target[fnSelectorProp] === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) {
  2797.  
  2798. doForegroundSlowMode();
  2799.  
  2800. } else {
  2801. // target[prop] = timerId;
  2802. target[fnSelectorProp] = 0;
  2803. target[prop] = 0;
  2804. }
  2805.  
  2806. // *****
  2807. // console.log('[[set]]', slowMode , prop, value, `fnSelectorProp: ${originalSelection} -> ${target[fnSelectorProp]}`)
  2808. } else {
  2809.  
  2810. target[prop] = value;
  2811. }
  2812. // console.log('set',prop,value)
  2813. return true;
  2814. }
  2815. }));
  2816.  
  2817. fnSelectorProp = null;
  2818.  
  2819.  
  2820. window.requestAnimationFrame = mk1;
  2821. window.setInterval = mk2
  2822. window.setTimeout = mk3
  2823. window.requestIdleCallback = mk4;
  2824.  
  2825.  
  2826.  
  2827. }
  2828.  
  2829. schedulerInstanceInstance_.start.toString = function () {
  2830. return schedulerInstanceInstance_.start991.toString();
  2831. }
  2832.  
  2833. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  2834. // prop,
  2835. // value: schedulerInstanceInstance_[prop],
  2836. // type: typeof schedulerInstanceInstance_[prop]
  2837.  
  2838. // }));
  2839. // console.log('fcc', funcNames)
  2840.  
  2841.  
  2842.  
  2843.  
  2844. }
  2845. })();
  2846.  
  2847.  
  2848.  
  2849. FIX_schedulerInstanceInstance_V2 && !FIX_schedulerInstanceInstance_V1 && (async () => {
  2850.  
  2851.  
  2852. const schedulerInstanceInstance_ = await new Promise(resolve => {
  2853.  
  2854. let cid = setInterval(() => {
  2855. let t = (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  2856. if (t) {
  2857.  
  2858. clearInterval(cid);
  2859. resolve(t);
  2860. }
  2861. }, 1);
  2862. promiseForTamerTimeout.then(() => {
  2863. resolve(null)
  2864. });
  2865. });
  2866.  
  2867. if (!schedulerInstanceInstance_) return;
  2868.  
  2869.  
  2870. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start991 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  2871. if (checkOK) {
  2872.  
  2873. schedulerInstanceInstance_.start991 = schedulerInstanceInstance_.start;
  2874.  
  2875.  
  2876.  
  2877. let busy = false;
  2878.  
  2879. // console.log('1667',schedulerInstanceInstance_.start);
  2880. schedulerInstanceInstance_.start = function () {
  2881.  
  2882. // p59 || console.log(location.pathname, 16400);
  2883.  
  2884. if (busy) {
  2885.  
  2886. return this.start991.call(this);
  2887.  
  2888. }
  2889.  
  2890. busy = true;
  2891.  
  2892. const mk1 = window.requestAnimationFrame
  2893. // const mk2 = window.setInterval
  2894. // const mk3 = window.setTimeout
  2895. // const mk4 = window.requestIdleCallback
  2896.  
  2897. // by pass Youtube Engine's wrapping
  2898. window.requestAnimationFrame = baseRAF;
  2899. // window.setInterval = setInterval
  2900. // window.setTimeout = setTimeout
  2901. // window.requestIdleCallback = requestIdleCallback
  2902.  
  2903.  
  2904. this.start991.call(this);
  2905.  
  2906.  
  2907. window.requestAnimationFrame = mk1;
  2908. // window.setInterval = mk2
  2909. // window.setTimeout = mk3
  2910. // window.requestIdleCallback = mk4;
  2911.  
  2912. busy = false;
  2913.  
  2914.  
  2915.  
  2916. }
  2917.  
  2918. schedulerInstanceInstance_.start.toString = function () {
  2919. return schedulerInstanceInstance_.start991.toString();
  2920. }
  2921.  
  2922. // const funcNames = [...(schedulerInstanceInstance_.start + "").matchAll(/[\(,]this\.(\w{1,2})[,\)]/g)].map(e => e[1]).map(prop => ({
  2923. // prop,
  2924. // value: schedulerInstanceInstance_[prop],
  2925. // type: typeof schedulerInstanceInstance_[prop]
  2926.  
  2927. // }));
  2928. // console.log('fcc', funcNames)
  2929.  
  2930.  
  2931.  
  2932.  
  2933. }
  2934. })();
  2935.  
  2936. FIX_yt_player && (async () => {
  2937.  
  2938.  
  2939.  
  2940. // const rafHub = new RAFHub();
  2941.  
  2942.  
  2943. const _yt_player = await new Promise(resolve => {
  2944.  
  2945. let cid = setInterval(() => {
  2946. let t = (((window || 0)._yt_player || 0) || 0);
  2947. if (t) {
  2948.  
  2949. clearInterval(cid);
  2950. resolve(t);
  2951. }
  2952. }, 1);
  2953.  
  2954. promiseForTamerTimeout.then(() => {
  2955. resolve(null)
  2956. });
  2957.  
  2958. });
  2959.  
  2960.  
  2961.  
  2962. if (!_yt_player || typeof _yt_player !== 'object') return;
  2963.  
  2964.  
  2965.  
  2966. let keyZq = getZq(_yt_player);
  2967. let keyVG = getVG(_yt_player);
  2968. let buildVG = _yt_player[keyVG];
  2969. let u = new buildVG({
  2970. api: {},
  2971. element: document.createElement('noscript'),
  2972. api: {},
  2973. hide: () => { }
  2974. }, 250);
  2975. const timeDelayConstructor = u.delay.constructor; // g.br
  2976. // console.log(keyVG, u)
  2977. // buildVG.prototype.show = function(){}
  2978. // _yt_player[keyZq] = g.k
  2979.  
  2980. if (!keyZq) return;
  2981.  
  2982.  
  2983. const g = _yt_player
  2984. let k = keyZq
  2985.  
  2986. const gk = g[k];
  2987. if (typeof gk !== 'function') return;
  2988. const gkp = gk.prototype;
  2989.  
  2990. let dummyObject = new gk;
  2991. let nilFunc = () => { };
  2992.  
  2993. let nilObj = {};
  2994.  
  2995. // console.log(1111111111)
  2996.  
  2997. let keyBoolD = '';
  2998. let keyWindow = '';
  2999. let keyFuncC = '';
  3000. let keyCidj = '';
  3001.  
  3002. for (const [t, y] of Object.entries(dummyObject)) {
  3003. if (y instanceof Window) keyWindow = t;
  3004. }
  3005.  
  3006. const dummyObjectProxyHandler = {
  3007. get(target, prop) {
  3008. let v = target[prop]
  3009. if (v instanceof Window && !keyWindow) {
  3010. keyWindow = t;
  3011. }
  3012. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  3013. if (prop === keyWindow) y = {
  3014. requestAnimationFrame(f) {
  3015. return 3;
  3016. },
  3017. cancelAnimationFrame() {
  3018.  
  3019. }
  3020. }
  3021. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  3022. keyFuncC = prop;
  3023. }
  3024. // console.log('[get]', prop, typeof target[prop])
  3025.  
  3026.  
  3027. return y;
  3028. },
  3029. set(target, prop, value) {
  3030.  
  3031. if (typeof value === 'boolean' && !keyBoolD) {
  3032. keyBoolD = prop;
  3033. }
  3034. if (typeof value === 'number' && !keyCidj && value >= 2) {
  3035. keyCidj = prop;
  3036. }
  3037.  
  3038. // console.log('[set]', prop, value)
  3039. target[prop] = value
  3040.  
  3041. return true;
  3042. }
  3043. };
  3044.  
  3045. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler))
  3046.  
  3047. /*
  3048. console.log({
  3049. keyBoolD,
  3050. keyFuncC,
  3051. keyWindow,
  3052. keyCidj
  3053. })
  3054.  
  3055. console.log( dummyObject[keyFuncC])
  3056.  
  3057.  
  3058. console.log(2222222222)
  3059. */
  3060.  
  3061.  
  3062. // console.log('gkp.start',gkp.start);
  3063. // console.log('gkp.stop',gkp.stop);
  3064. gkp._activation = false;
  3065.  
  3066. gkp.start = function () {
  3067. // p59 || console.log(12100)
  3068. if (!this._activation) {
  3069. this._activation = true;
  3070. getRafPromise().then(() => {
  3071. this._activation = false;
  3072. if (this[keyCidj]) {
  3073. Promise.resolve().then(this[keyFuncC]);
  3074. }
  3075. });
  3076. }
  3077. this[keyCidj] = 1;
  3078. this[keyBoolD] = true;
  3079. }
  3080. ;
  3081. gkp.stop = function () {
  3082. this[keyCidj] = null
  3083. }
  3084.  
  3085.  
  3086. /*
  3087. g[k].start = function() {
  3088. this.stop();
  3089. this.D = true;
  3090. var a = requestAnimationFrame
  3091. , b = cancelAnimationFrame;
  3092. this.j = a.call(this.B, this.C)
  3093. }
  3094. ;
  3095. g[k].stop = function() {
  3096. if (this.isActive()) {
  3097. var a = requestAnimationFrame
  3098. , b = cancelAnimationFrame;
  3099. b.call(this.B, this.j)
  3100. }
  3101. this.j = null
  3102. }
  3103. */
  3104.  
  3105.  
  3106.  
  3107. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  3108.  
  3109. if (keyzo) {
  3110.  
  3111. k = keyzo
  3112.  
  3113. const setCSSProp = (() => {
  3114.  
  3115. let animationPropCapable = false;
  3116. try {
  3117. const propName = "--ibxpf"
  3118. const value = 2;
  3119. const keyframes = [{
  3120. [propName]: value
  3121. }];
  3122. window.CSS.registerProperty({
  3123. name: "--ibxpf",
  3124. syntax: "<number>",
  3125. inherits: false,
  3126. initialValue: 1,
  3127. });
  3128. animationPropCapable = '1' === `${getComputedStyle(document.documentElement).getPropertyValue('--ibxpf')}`
  3129. } catch (e) { }
  3130.  
  3131. if (!animationPropCapable) {
  3132. return (element, cssProp, value) => {
  3133.  
  3134.  
  3135. element.style.setProperty(cssProp, value);
  3136.  
  3137. }
  3138. }
  3139.  
  3140. const propMaps = new Map();
  3141.  
  3142. function setCustomCSSProperty(element, propName, value) {
  3143. let wm = propMaps.get(propName);
  3144. if (!wm) {
  3145.  
  3146. try {
  3147. window.CSS.registerProperty({
  3148. name: propName,
  3149. syntax: "*",
  3150. inherits: false
  3151. });
  3152. } catch (e) {
  3153. console.warn(e);
  3154. }
  3155.  
  3156. propMaps.set(propName, (wm = new WeakMap()));
  3157. }
  3158.  
  3159. // Create the animation keyframes with the provided property and value
  3160. const keyframes = [{
  3161. [propName]: value
  3162. }];
  3163.  
  3164. let currentAnimation = wm.get(element);
  3165. if (currentAnimation) {
  3166.  
  3167. currentAnimation.effect.setKeyframes(keyframes);
  3168.  
  3169. } else {
  3170.  
  3171.  
  3172.  
  3173. // Set the animation on the element and immediately pause it
  3174. const animation = animate.call(element, keyframes, {
  3175. duration: 1, // Very short duration as we just want to set the value
  3176. fill: 'forwards',
  3177. iterationStart: 1,
  3178. iterations: 2,
  3179. direction: 'alternate'
  3180. });
  3181.  
  3182.  
  3183. // animation.currentTime = 1;
  3184. animation.pause();
  3185.  
  3186. wm.set(element, animation);
  3187.  
  3188.  
  3189. }
  3190.  
  3191. }
  3192.  
  3193. return setCustomCSSProperty;
  3194.  
  3195.  
  3196. })();
  3197.  
  3198.  
  3199. const attrUpdateFn = g[k];
  3200. g['$$original$$' + k] = attrUpdateFn;
  3201. g[k] = function (a, b, c) {
  3202.  
  3203. // console.log(140000, a, b, c);
  3204.  
  3205. let transformType = '';
  3206. let transformValue = 0;
  3207. let transformUnit = '';
  3208.  
  3209. let byPassDefaultFn = false;
  3210. if (b === "transform" && typeof c === 'string') {
  3211.  
  3212. byPassDefaultFn = true;
  3213.  
  3214. const aStyle = a.style;
  3215.  
  3216. // let beforeMq = aStyle.getPropertyValue('--mq-transform');
  3217. if (!(a instanceof HTMLElement)) return;
  3218. if (c.length === 0) {
  3219.  
  3220. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  3221. let p = c.substring(7, c.length - 1);
  3222. let q = p.length >= 1 ? parseFloat(p) : -1;
  3223. if (q > -1e-5 && q < 1 + 1e-5) {
  3224. transformType = 'scalex'
  3225. transformValue = q;
  3226. transformUnit = '';
  3227. }
  3228.  
  3229.  
  3230. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  3231.  
  3232. let p = c.substring(11, c.length - 3);
  3233. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3234.  
  3235. if (typeof q === 'number' && !isNaN(q)) {
  3236. transformType = 'translateX'
  3237. transformValue = q;
  3238. transformUnit = 'px';
  3239. }
  3240.  
  3241.  
  3242. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  3243. let p = c.substring(7, c.length - 1);
  3244. let q = p.length >= 1 ? parseFloat(p) : -1;
  3245. if (q > -1e-5 && q < 1 + 1e-5) {
  3246. transformType = 'scaley'
  3247. transformValue = q;
  3248. transformUnit = '';
  3249. }
  3250.  
  3251.  
  3252. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  3253.  
  3254. let p = c.substring(11, c.length - 3);
  3255. let q = p.length >= 1 ? parseFloat(p) : NaN;
  3256.  
  3257. if (typeof q === 'number' && !isNaN(q)) {
  3258. transformType = 'translateY'
  3259. transformValue = q;
  3260. transformUnit = 'px';
  3261. }
  3262.  
  3263.  
  3264. }
  3265.  
  3266. if (transformType) {
  3267.  
  3268. if (transformType === 'scalex' || transformType === 'scaley') {
  3269.  
  3270. const q = transformValue;
  3271.  
  3272.  
  3273. /*
  3274.  
  3275. let vz = Math.round(steppingScaleN * q);
  3276. const customPropName = '--discrete-'+transformType
  3277.  
  3278. const currentValue = aStyle.getPropertyValue(customPropName);
  3279.  
  3280. const transform = (aStyle.transform || '');
  3281. const u = transform.includes(customPropName)
  3282. if (`${currentValue}` === `${vz}`) {
  3283. if (u) return;
  3284. }
  3285.  
  3286.  
  3287. setCSSProp(a,customPropName, vz);
  3288. // aStyle.setProperty(customPropName, vz)
  3289.  
  3290. let ck = '';
  3291.  
  3292. if (c.length === 9) ck = c;
  3293. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3294.  
  3295. if (ck && beforeMq !== ck) {
  3296. aStyle.setProperty('--mq-transform', ck);
  3297. }
  3298.  
  3299. if (u) return;
  3300. c = `${transformType}(calc(var(--discrete-${transformType})/${steppingScaleN}))`;
  3301.  
  3302.  
  3303.  
  3304. */
  3305.  
  3306. const vz = +(Math.round(q * steppingScaleN) / steppingScaleN).toFixed(3);
  3307.  
  3308. c = `${transformType === 'scalex' ? 'scaleX' : 'scaleY'}(${vz})`
  3309. const cv = aStyle.transform;
  3310.  
  3311. // console.log(157, cv,c)
  3312.  
  3313. if (c === cv) return;
  3314. // console.log(257, cv,c)
  3315.  
  3316. aStyle.transform = c;
  3317.  
  3318. // return;
  3319.  
  3320. } else if (transformType === 'translateX' || transformType === 'translateY') {
  3321.  
  3322. const q = transformValue;
  3323.  
  3324. /*
  3325.  
  3326. let vz = q.toFixed(1);
  3327. const customPropName = '--discrete-'+transformType
  3328.  
  3329. const aStyle = a.style;
  3330. const currentValue = (aStyle.getPropertyValue(customPropName) || '').replace('px', '');
  3331.  
  3332.  
  3333. const transform = (aStyle.transform || '');
  3334. const u = transform.includes(customPropName)
  3335. if (parseFloat(currentValue).toFixed(1) === vz) {
  3336. if (u) return;
  3337. }
  3338.  
  3339. setCSSProp(a,customPropName, vz + 'px');
  3340. // aStyle.setProperty(customPropName, vz + 'px')
  3341.  
  3342. let ck = '';
  3343. if (c.length === 15) ck = c;
  3344. else if (!u) ck = c.replace(/[.\d]+/, '0.5');
  3345.  
  3346. if (ck && beforeMq !== ck) {
  3347. aStyle.setProperty('--mq-transform', ck);
  3348. }
  3349.  
  3350. if (u) return;
  3351. c = `${transformType}(var(--discrete-${transformType}))`;
  3352.  
  3353. */
  3354.  
  3355.  
  3356. const vz = +q.toFixed(1);
  3357.  
  3358. c = `${transformType}(${vz}${transformUnit})`
  3359. const cv = aStyle.transform;
  3360.  
  3361. // console.log(158, cv,c)
  3362.  
  3363. if (c === cv) return;
  3364. // console.log(258, cv,c)
  3365.  
  3366. aStyle.transform = c;
  3367.  
  3368. // return;
  3369.  
  3370. } else {
  3371. throw new Error();
  3372. }
  3373.  
  3374. } else {
  3375. // if(beforeMq) a.style.setProperty('--mq-transform', '');
  3376. const cv = aStyle.transform
  3377. if (!c && !cv) return;
  3378. else if (c === cv) return;
  3379. aStyle.transform = c;
  3380. // return;
  3381. }
  3382.  
  3383. } else if (b === "display") {
  3384.  
  3385. const cv = a.style.display;
  3386. if (!cv && !c) return;
  3387. if (cv === c) return;
  3388.  
  3389.  
  3390. } else if (b === "width") {
  3391.  
  3392. const cv = a.style.width;
  3393. if (!cv && !c) return;
  3394. if (cv === c) return;
  3395.  
  3396. }
  3397.  
  3398. // console.log(130000, a, b, c);
  3399.  
  3400. if (byPassDefaultFn) return;
  3401. return attrUpdateFn.call(this, a, b, c);
  3402. }
  3403.  
  3404.  
  3405. /*
  3406.  
  3407. g.zo = function(a, b, c) {
  3408. if ("string" === typeof b)
  3409. (b = yo(a, b)) && (a.style[b] = c);
  3410. else
  3411. for (var d in b) {
  3412. c = a;
  3413. var e = b[d]
  3414. , f = yo(c, d);
  3415. f && (c.style[f] = e)
  3416. }
  3417. }
  3418.  
  3419.  
  3420. */
  3421.  
  3422.  
  3423. }
  3424.  
  3425.  
  3426.  
  3427. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  3428.  
  3429. if (keyuG) {
  3430.  
  3431. k = keyuG;
  3432.  
  3433. const gk = g[k];
  3434. const gkp = gk.prototype;
  3435.  
  3436.  
  3437. /** @type { Map<string, WeakMap<any, any>> } */
  3438. const ntLogs = new Map();
  3439.  
  3440. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  3441.  
  3442. gkp.updateValue31 = gkp.updateValue;
  3443. gkp.updateValue = function (a, b) {
  3444. if (typeof a !== 'string') return this.updateValue31(a, b);
  3445.  
  3446. const element = this.element;
  3447. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  3448.  
  3449. let ntLog = ntLogs.get(a);
  3450. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  3451.  
  3452. let cache = ntLog.get(element);
  3453. if (cache && cache.value === b) {
  3454. return;
  3455. }
  3456. if (!cache) {
  3457. this.__oldValueByUpdateValue__ = null;
  3458. ntLog.set(element, cache = { value: b });
  3459. } else {
  3460. this.__oldValueByUpdateValue__ = cache.value;
  3461. cache.value = b;
  3462. }
  3463.  
  3464.  
  3465. return this.updateValue31(a, b);
  3466. }
  3467.  
  3468.  
  3469. /*
  3470. g.k.update = function(a) {
  3471. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  3472. c = c.value,
  3473. this.updateValue(c, a[c])
  3474. }
  3475. ;
  3476. g.k.updateValue = function(a, b) {
  3477. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  3478. }
  3479. */
  3480.  
  3481.  
  3482. }
  3483.  
  3484.  
  3485. }
  3486.  
  3487.  
  3488.  
  3489.  
  3490. })();
  3491.  
  3492.  
  3493.  
  3494. FIX_Animation_n_timeline && (async () => {
  3495.  
  3496.  
  3497. const timeline = await new Promise(resolve => {
  3498.  
  3499. let cid = setInterval(() => {
  3500. let t = (((document || 0).timeline || 0) || 0);
  3501. if (t && typeof t._play === 'function') {
  3502.  
  3503. clearInterval(cid);
  3504. resolve(t);
  3505. }
  3506. }, 1);
  3507.  
  3508. promiseForTamerTimeout.then(() => {
  3509. resolve(null)
  3510. });
  3511.  
  3512. });
  3513.  
  3514.  
  3515. const Animation = await new Promise(resolve => {
  3516.  
  3517. let cid = setInterval(() => {
  3518. let t = (((window || 0).Animation || 0) || 0);
  3519. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  3520.  
  3521. clearInterval(cid);
  3522. resolve(t);
  3523. }
  3524. }, 1);
  3525.  
  3526. promiseForTamerTimeout.then(() => {
  3527. resolve(null)
  3528. });
  3529.  
  3530. });
  3531.  
  3532. if (!timeline) return;
  3533. if (!Animation) return;
  3534.  
  3535. const aniProto = Animation.prototype;
  3536. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  3537.  
  3538. const getXroto = (x) => {
  3539. try {
  3540. return x.__proto__;
  3541. } catch (e) { }
  3542. return null;
  3543. }
  3544. const timProto = getXroto(timeline);
  3545. if (!timProto) return;
  3546. if (
  3547. (
  3548. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  3549. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  3550. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  3551. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  3552. )
  3553.  
  3554. ) {
  3555.  
  3556. timProto.nofCQ = 1;
  3557. aniProto.nofYH = 1;
  3558.  
  3559. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  3560.  
  3561.  
  3562. /*
  3563. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3564. return c._updatePromises();
  3565. });
  3566. */
  3567.  
  3568. const p = Array.prototype.filter;
  3569.  
  3570. let res = null;
  3571. Array.prototype.filter = function () {
  3572.  
  3573. res = this;
  3574. return this;
  3575.  
  3576. };
  3577.  
  3578. _updateAnimationsPromises.call({});
  3579.  
  3580. Array.prototype.filter = p;
  3581.  
  3582. if (res && typeof res.length === 'number') {
  3583. /** @type {any[]} */
  3584. const _res = res;
  3585. return _res;
  3586. }
  3587.  
  3588.  
  3589. return null;
  3590.  
  3591.  
  3592.  
  3593.  
  3594. })(timProto._updateAnimationsPromises);
  3595.  
  3596. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  3597.  
  3598. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  3599.  
  3600. aniProto._updatePromises31 = aniProto._updatePromises;
  3601.  
  3602. /*
  3603. aniProto._updatePromises = function(){
  3604. console.log('eff',this._oldPlayState, this.playState)
  3605. return this._updatePromises31.apply(this, arguments)
  3606. }
  3607. */
  3608.  
  3609. aniProto._updatePromises = function () {
  3610. var oldPlayState = this._oldPlayState;
  3611. var newPlayState = this.playState;
  3612. // console.log('ett', oldPlayState, newPlayState)
  3613. if (newPlayState !== oldPlayState) {
  3614. this._oldPlayState = newPlayState;
  3615. if (this._readyPromise) {
  3616. if ("idle" == newPlayState) {
  3617. this._rejectReadyPromise();
  3618. this._readyPromise = void 0;
  3619. } else if ("pending" == oldPlayState) {
  3620. this._resolveReadyPromise();
  3621. } else if ("pending" == newPlayState) {
  3622. this._readyPromise = void 0;
  3623. }
  3624. }
  3625. if (this._finishedPromise) {
  3626. if ("idle" == newPlayState) {
  3627. this._rejectFinishedPromise();
  3628. this._finishedPromise = void 0;
  3629. } else if ("finished" == newPlayState) {
  3630. this._resolveFinishedPromise();
  3631. } else if ("finished" == oldPlayState) {
  3632. this._finishedPromise = void 0;
  3633. }
  3634. }
  3635. }
  3636. return this._readyPromise || this._finishedPromise;
  3637. };
  3638.  
  3639.  
  3640. let restartWebAnimationsNextTickFlag = false;
  3641.  
  3642. const looperMethodT = () => {
  3643.  
  3644. const runnerFn = (hRes) => {
  3645. var b = timeline;
  3646. b.currentTime = hRes;
  3647. b._discardAnimations();
  3648. if (0 == b._animations.length) {
  3649. restartWebAnimationsNextTickFlag = false;
  3650. } else {
  3651. getRafPromise().then(runnerFn);
  3652. }
  3653. }
  3654.  
  3655. const restartWebAnimationsNextTick = () => {
  3656. if (!restartWebAnimationsNextTickFlag) {
  3657. restartWebAnimationsNextTickFlag = true;
  3658. getRafPromise().then(runnerFn);
  3659. }
  3660. }
  3661.  
  3662. return { restartWebAnimationsNextTick }
  3663. };
  3664.  
  3665.  
  3666. const looperMethodN = () => {
  3667.  
  3668. const acs = document.createElement('a-f');
  3669. acs.id = 'a-f';
  3670.  
  3671. const style = document.createElement('style');
  3672. style.textContent = `
  3673. @keyFrames aF1 {
  3674. 0% {
  3675. order: 0;
  3676. }
  3677. 100% {
  3678. order: 6;
  3679. }
  3680. }
  3681. #a-f[id] {
  3682. visibility: collapse !important;
  3683. position: fixed !important;
  3684. top: -100px !important;
  3685. left: -100px !important;
  3686. margin:0 !important;
  3687. padding:0 !important;
  3688. outline:0 !important;
  3689. border:0 !important;
  3690. z-index:-1 !important;
  3691. width: 0px !important;
  3692. height: 0px !important;
  3693. contain: strict !important;
  3694. pointer-events: none !important;
  3695. animation: 1ms steps(2) 0ms infinite alternate forwards running aF1 !important;
  3696. }
  3697. `;
  3698. (document.head || document.documentElement).appendChild(style);
  3699.  
  3700. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  3701.  
  3702. const _onanimationiteration = function (evt) {
  3703. const hRes = evt.timeStamp;
  3704. var b = timeline;
  3705. b.currentTime = hRes;
  3706. b._discardAnimations();
  3707. if (0 == b._animations.length) {
  3708. restartWebAnimationsNextTickFlag = false;
  3709. acs.onanimationiteration = null;
  3710. } else {
  3711. acs.onanimationiteration = _onanimationiteration;
  3712. }
  3713.  
  3714. }
  3715.  
  3716.  
  3717.  
  3718. const restartWebAnimationsNextTick = () => {
  3719. if (!restartWebAnimationsNextTickFlag) {
  3720. restartWebAnimationsNextTickFlag = true;
  3721. acs.onanimationiteration = _onanimationiteration;
  3722.  
  3723. }
  3724. }
  3725.  
  3726. return { restartWebAnimationsNextTick }
  3727. };
  3728.  
  3729.  
  3730.  
  3731. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  3732.  
  3733.  
  3734. // console.log(571, timProto);
  3735. timProto._play = function (c) {
  3736. c = new Animation(c, this);
  3737. this._animations.push(c);
  3738. restartWebAnimationsNextTick();
  3739. c._updatePromises();
  3740. c._animation.play();
  3741. c._updatePromises();
  3742. return c
  3743. }
  3744.  
  3745. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  3746. originalAnimationsWithPromises.length = 0;
  3747. originalAnimationsWithPromises.push = null;
  3748. originalAnimationsWithPromises.splice = null;
  3749. originalAnimationsWithPromises.slice = null;
  3750. originalAnimationsWithPromises.indexOf = null;
  3751. originalAnimationsWithPromises.unshift = null;
  3752. originalAnimationsWithPromises.shift = null;
  3753. originalAnimationsWithPromises.pop = null;
  3754. originalAnimationsWithPromises.filter = null;
  3755. originalAnimationsWithPromises.forEach = null;
  3756. originalAnimationsWithPromises.map = null;
  3757.  
  3758.  
  3759. const _updateAnimationsPromises = () => {
  3760. animationsWithPromisesMap.forEach(c => {
  3761. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  3762. });
  3763. /*
  3764. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  3765. return c._updatePromises();
  3766. });
  3767. */
  3768. }
  3769.  
  3770. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  3771.  
  3772. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  3773.  
  3774. delete timProto._updateAnimationsPromises;
  3775. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  3776. get() {
  3777. if (animationsWithPromisesMap.size === 0) return nilFn;
  3778. return _updateAnimationsPromises;
  3779. },
  3780. set(nv) {
  3781. delete this._updateAnimationsPromises;
  3782. this._updateAnimationsPromises = nv;
  3783. },
  3784. enumerable: true,
  3785. configurable: true,
  3786. });
  3787.  
  3788.  
  3789. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  3790. aniProto.__finished_native_get__ = pdFinished.get;
  3791. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  3792.  
  3793.  
  3794. Object.defineProperty(aniProto, 'finished', {
  3795. get() {
  3796. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3797. this._finishedPromise = new Promise((resolve, reject) => {
  3798. this._resolveFinishedPromise = function () {
  3799. resolve(this)
  3800. };
  3801. this._rejectFinishedPromise = function () {
  3802. reject({
  3803. type: DOMException.ABORT_ERR,
  3804. name: "AbortError"
  3805. })
  3806. };
  3807. }),
  3808. "finished" == this.playState && this._resolveFinishedPromise());
  3809. return this._finishedPromise
  3810. },
  3811. set: undefined,
  3812. enumerable: true,
  3813. configurable: true
  3814. });
  3815.  
  3816. }
  3817.  
  3818.  
  3819.  
  3820. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  3821. aniProto.__ready_native_get__ = pdReady.get;
  3822. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  3823.  
  3824. Object.defineProperty(aniProto, 'ready', {
  3825. get() {
  3826. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  3827. this._readyPromise = new Promise((resolve, reject) => {
  3828. this._resolveReadyPromise = function () {
  3829. resolve(this)
  3830. };
  3831. this._rejectReadyPromise = function () {
  3832. reject({
  3833. type: DOMException.ABORT_ERR,
  3834. name: "AbortError"
  3835. })
  3836. };
  3837. }),
  3838. "pending" !== this.playState && this._resolveReadyPromise());
  3839. return this._readyPromise
  3840. },
  3841. set: undefined,
  3842. enumerable: true,
  3843. configurable: true
  3844. });
  3845.  
  3846. }
  3847.  
  3848.  
  3849. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  3850.  
  3851. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  3852. const _rebuildUnderlyingAnimation = function () {
  3853. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  3854. this.effect && this.effect._onsample && (this.effect._onsample = null);
  3855. return this._rebuildUnderlyingAnimation21();
  3856. }
  3857. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  3858. // delete aniProto._rebuildUnderlyingAnimation;
  3859. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  3860. // get() {
  3861. // if (isNaN(this._sequenceNumber)) return nilFn;
  3862. // return this._rebuildUnderlyingAnimation21;
  3863. // },
  3864. // set(nv) {
  3865. // delete this._rebuildUnderlyingAnimation;
  3866. // this._rebuildUnderlyingAnimation = nv;
  3867. // },
  3868. // enumerable: true,
  3869. // configurable: true
  3870. // });
  3871. }
  3872.  
  3873.  
  3874. /*
  3875.  
  3876.  
  3877. function f(c) {
  3878. var b = v.timeline;
  3879. b.currentTime = c;
  3880. b._discardAnimations();
  3881. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  3882. }
  3883. var h = window.requestAnimationFrame;
  3884. window.requestAnimationFrame = function(c) {
  3885. return h(function(b) {
  3886. v.timeline._updateAnimationsPromises();
  3887. c(b);
  3888. v.timeline._updateAnimationsPromises()
  3889. })
  3890. }
  3891. ;
  3892. v.AnimationTimeline = function() {
  3893. this._animations = [];
  3894. this.currentTime = void 0
  3895. }
  3896. ;
  3897. v.AnimationTimeline.prototype = {
  3898. getAnimations: function() {
  3899. this._discardAnimations();
  3900. return this._animations.slice()
  3901. },
  3902. _updateAnimationsPromises: function() {
  3903. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  3904. return c._updatePromises()
  3905. })
  3906. },
  3907. _discardAnimations: function() {
  3908. this._updateAnimationsPromises();
  3909. this._animations = this._animations.filter(function(c) {
  3910. return "finished" != c.playState && "idle" != c.playState
  3911. })
  3912. },
  3913. _play: function(c) {
  3914. c = new v.Animation(c,this);
  3915. this._animations.push(c);
  3916. v.restartWebAnimationsNextTick();
  3917. c._updatePromises();
  3918. c._animation.play();
  3919. c._updatePromises();
  3920. return c
  3921. },
  3922. play: function(c) {
  3923. c && c.remove();
  3924. return this._play(c)
  3925. }
  3926. };
  3927. var d = !1;
  3928. v.restartWebAnimationsNextTick = function() {
  3929. d || (d = !0,
  3930. requestAnimationFrame(f))
  3931. }
  3932. ;
  3933. var a = new v.AnimationTimeline;
  3934. v.timeline = a;
  3935. try {
  3936. Object.defineProperty(window.document, "timeline", {
  3937. configurable: !0,
  3938. get: function() {
  3939. return a
  3940. }
  3941. })
  3942. } catch (c) {}
  3943. try {
  3944. window.document.timeline = a
  3945. } catch (c) {}
  3946.  
  3947. */
  3948.  
  3949.  
  3950.  
  3951. /*
  3952.  
  3953. var g = window.getComputedStyle;
  3954. Object.defineProperty(window, "getComputedStyle", {
  3955. configurable: !0,
  3956. enumerable: !0,
  3957. value: function() {
  3958. v.timeline._updateAnimationsPromises();
  3959. var e = g.apply(this, arguments);
  3960. h() && (e = g.apply(this, arguments));
  3961. v.timeline._updateAnimationsPromises();
  3962. return e
  3963. }
  3964. });
  3965.  
  3966. */
  3967.  
  3968.  
  3969.  
  3970.  
  3971. }
  3972.  
  3973.  
  3974.  
  3975.  
  3976. })();
  3977.  
  3978.  
  3979.  
  3980.  
  3981. promiseForCustomYtElementsReady.then(() => {
  3982.  
  3983. FIX_ytdExpander_childrenChanged && customElements.whenDefined('ytd-expander').then(() => {
  3984.  
  3985.  
  3986.  
  3987. let dummy;
  3988. let cProto;
  3989.  
  3990.  
  3991.  
  3992. dummy = document.createElement('ytd-expander');
  3993. cProto = (dummy.inst || dummy).constructor.prototype;
  3994.  
  3995.  
  3996. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  3997.  
  3998.  
  3999. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  4000. cProto.childrenChanged14 = cProto.childrenChanged;
  4001.  
  4002. cProto.initChildrenObserver = function () {
  4003. var a = this;
  4004. this.observer = new MutationObserver(function () {
  4005. a.childrenChanged()
  4006. }
  4007. );
  4008. this.observer.observe(this.content, {
  4009. subtree: !0,
  4010. childList: !0,
  4011. attributes: !0,
  4012. characterData: !0
  4013. });
  4014. this.childrenChanged()
  4015. }
  4016. ;
  4017. cProto.childrenChanged = function () {
  4018. if (this.alwaysToggleable) {
  4019. this.canToggle = this.alwaysToggleable;
  4020. } else if (!this.canToggleJobId) {
  4021. this.canToggleJobId = 1;
  4022. getRafPromise().then(() => {
  4023. this.canToggleJobId = 0;
  4024. this.calculateCanCollapse()
  4025. })
  4026. }
  4027. }
  4028.  
  4029.  
  4030. // console.log(cProto.initChildrenObserver)
  4031. console.debug('ytd-expander-fix-childrenChanged');
  4032.  
  4033. }
  4034.  
  4035. })
  4036.  
  4037.  
  4038.  
  4039. FIX_paper_ripple_animate && customElements.whenDefined('paper-ripple').then(() => {
  4040.  
  4041.  
  4042.  
  4043. let dummy;
  4044. let cProto;
  4045. dummy = document.createElement('paper-ripple');
  4046. cProto = (dummy.inst || dummy).constructor.prototype;
  4047.  
  4048. if (fnIntegrity(cProto.animate, '0.74.5')) {
  4049.  
  4050.  
  4051. cProto.animate34 = cProto.animate;
  4052. cProto.animate = function () {
  4053. if (this._animating) {
  4054. var a;
  4055. const ripples = this.ripples;
  4056. for (a = 0; a < ripples.length; ++a) {
  4057. var b = ripples[a];
  4058. b.draw();
  4059. this.$.background.style.opacity = b.outerOpacity;
  4060. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  4061. }
  4062. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  4063. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  4064. getRafPromise().then(this._boundAnimate38);
  4065. } else {
  4066. this.onAnimationComplete()
  4067. }
  4068. }
  4069. }
  4070.  
  4071. console.debug('FIX_paper_ripple_animate')
  4072.  
  4073. // console.log(cProto.animate)
  4074.  
  4075. }
  4076.  
  4077. });
  4078.  
  4079. if (FIX_doIdomRender) {
  4080.  
  4081.  
  4082. const xsetTimeout = function (f, d) {
  4083. if (xsetTimeout.m511 === 1 && !d) {
  4084. xsetTimeout.m511 = 2;
  4085. getRafPromise().then(f);
  4086. } else {
  4087. return setTimeout.apply(window, arguments)
  4088. }
  4089.  
  4090. }
  4091.  
  4092. const xrequestAnimationFrame = function (f) {
  4093. const h = f + "";
  4094. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  4095. xsetTimeout.m511 = 1;
  4096. f();
  4097. xsetTimeout.m511 = 0;
  4098. } else if (h.includes("requestAninmationFrameResolver")) {
  4099. getRafPromise().then(f);
  4100. } else {
  4101. return requestAnimationFrame.apply(window, arguments);
  4102. }
  4103. }
  4104.  
  4105. let busy = false;
  4106. const doIdomRender = function () {
  4107. if (busy) {
  4108. return this.doIdomRender13.apply(this, arguments);
  4109. }
  4110. busy = true;
  4111. const { requestAnimationFrame, setTimeout } = window;
  4112. window.requestAnimationFrame = xrequestAnimationFrame;
  4113. window.setTimeout = xsetTimeout;
  4114. let r = this.doIdomRender13.apply(this, arguments);
  4115. window.requestAnimationFrame = requestAnimationFrame;
  4116. window.setTimeout = setTimeout;
  4117. busy = false;
  4118. return r;
  4119. };
  4120. 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']) {
  4121.  
  4122.  
  4123. customElements.whenDefined(ytTag).then(() => {
  4124.  
  4125. let dummy;
  4126. let cProto;
  4127. dummy = document.createElement(ytTag);
  4128. cProto = (dummy.inst || dummy).constructor.prototype;
  4129.  
  4130. cProto.doIdomRender13 = cProto.doIdomRender;
  4131. cProto.doIdomRender = doIdomRender;
  4132.  
  4133. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  4134.  
  4135. console.debug('FIX_doIdomRender', ytTag)
  4136.  
  4137.  
  4138.  
  4139. });
  4140.  
  4141. }
  4142.  
  4143. }
  4144.  
  4145.  
  4146.  
  4147. });
  4148.  
  4149. });
  4150.  
  4151.  
  4152. setupEvents();
  4153.  
  4154.  
  4155.  
  4156. if (isMainWindow) {
  4157.  
  4158. console.groupCollapsed(
  4159. "%cYouTube JS Engine Tamer",
  4160. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  4161. );
  4162.  
  4163.  
  4164.  
  4165. console.log("Script is loaded.");
  4166. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  4167.  
  4168. console.log("This script is experimental and subject to further changes.");
  4169.  
  4170. console.log("This might boost your YouTube performance.");
  4171.  
  4172. console.log("CAUTION: This might break your YouTube.");
  4173.  
  4174.  
  4175. if (prepareLogs.length >= 1) {
  4176. console.log(" =========================================================================== ");
  4177.  
  4178. for (const msg of prepareLogs) {
  4179. console.log(msg)
  4180. }
  4181.  
  4182. console.log(" =========================================================================== ");
  4183. }
  4184.  
  4185. console.groupEnd();
  4186.  
  4187. }
  4188.  
  4189.  
  4190.  
  4191.  
  4192.  
  4193.  
  4194. })();