YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-12-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @match https://www.youtube.com/*
  5. // @match https://www.youtube-nocookie.com/embed/*
  6. // @match https://studio.youtube.com/live_chat*
  7. // @version 0.16.19
  8. // @license MIT
  9. // @author CY Fung
  10. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  11. // @description To enhance YouTube performance by modifying YouTube JS Engine
  12. // @grant none
  13. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@7221a4efffd49d852de0074ec503d4febb99f28b/library/nextBrowserTick.min.js
  14. // @run-at document-start
  15. // @unwrap
  16. // @inject-into page
  17. // @allFrames true
  18. // ==/UserScript==
  19.  
  20. (() => {
  21.  
  22. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  23.  
  24. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  25. const FIX_schedulerInstanceInstance = 2 | 4;
  26. const FIX_yt_player = true; // DONT CHANGE
  27. const FIX_Animation_n_timeline = true;
  28. const NO_PRELOAD_GENERATE_204 = false;
  29. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  30. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  31. const CHANGE_appendChild = true; // discussions#236759
  32. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  33. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  34.  
  35. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  36. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  37. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  38.  
  39. const FIX_Iframe_NULL_SRC = false;
  40.  
  41. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  42.  
  43. const FIX_ytdExpander_childrenChanged = true;
  44. const FIX_paper_ripple_animate = true;
  45. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  46. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  47.  
  48. const FIX_doIdomRender = true;
  49.  
  50. const FIX_Shady = true;
  51.  
  52. // [[ 2024.04.24 ]]
  53. const MODIFY_ShadyDOM_OBJ = true;
  54. // << if MODIFY_ShadyDOM_OBJ >>
  55. const WEAKREF_ShadyDOM = true;
  56. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  57. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  58. // << end >>
  59.  
  60. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  61.  
  62. const FIX_ytAction_ = true; // ytd-app
  63. const FIX_onVideoDataChange = false;
  64. // const FIX_onClick = true;
  65. const FIX_onStateChange = true;
  66. const FIX_onLoopRangeChange = true;
  67. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  68. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  69.  
  70. const ENABLE_discreteTasking = true;
  71. // << if ENABLE_discreteTasking >>
  72. const FIX_stampDomArray_stableList = true;
  73. const ENABLE_weakenStampReferences = true; // disabled in old browsers
  74. // << end >>
  75.  
  76. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  77. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  78.  
  79. const FIX_Polymer_dom = true;
  80.  
  81. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  82. const DEBUG_removePrune = false; // true for DEBUG
  83.  
  84. const FIX_XHR_REQUESTING = true;
  85.  
  86. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  87.  
  88. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  89.  
  90. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  91. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  92.  
  93. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  94.  
  95. const FIX_removeChild = true;
  96. const FIX_fix_requestIdleCallback_timing = true;
  97.  
  98. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  99.  
  100. // ----------------------------- Shortkey Keyboard Control -----------------------------
  101. // dependency: FIX_yt_player
  102.  
  103. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  104. // [0] no fix - not recommended
  105. // [1] basic fix - just fix the global focus detection variable
  106. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  107. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  108.  
  109. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  110. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  111.  
  112. const PROP_OverReInclusion_AVOID = true;
  113. const PROP_OverReInclusion_DEBUGLOG = false;
  114. const PROP_OverReInclusion_LIST = new Set([
  115. 'hostElement72',
  116. 'parentComponent72',
  117. 'localVisibilityObserver_72',
  118. 'cachedProviderNode_72',
  119. '__template72',
  120. '__templatizeOwner72',
  121. '__templateInfo72',
  122. '__dataHost72',
  123. '__CE_shadowRoot72',
  124. 'elements_72',
  125.  
  126. 'ky36',
  127. 'kz62',
  128. 'm822',
  129.  
  130.  
  131.  
  132. // To be reviewed.
  133.  
  134. // chat messages
  135. 'disabled', 'allowedProps',
  136. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  137.  
  138. 'dimension', 'loadTime', 'pendingPaint',
  139.  
  140. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  141.  
  142. 'respectLangDir', 'noEndpoints',
  143.  
  144.  
  145. 'objectURL',
  146. 'buttonOverrides', 'queuedMessages',
  147. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  148. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  149. 'hoverJobId', 'JSC$14573_touched',
  150.  
  151.  
  152. // tbc
  153. 'toggleable', 'isConnected',
  154. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  155. 'disableDeselectEvent',
  156. 'emojiSize',
  157.  
  158. 'buttonOverride',
  159. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  160.  
  161. // others
  162. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  163. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  164. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  165. // 'dimension', 'loadTime', 'pendingPaint',
  166. // 'disabled', 'allowedProps',
  167.  
  168.  
  169. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  170. // 'actionMap',
  171.  
  172. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  173.  
  174. 'clearTimeout',
  175. 'switchTemplateAtRegistration', 'hasUnmounted',
  176. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  177. 'tangoConfiguration',
  178. 'itemIdToDockDurationMap',
  179. 'actionMap',
  180.  
  181. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  182. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  183. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  184.  
  185. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  186. // 'stopKeyboardEventPropagation', 'emojiSize',
  187. // 'switchTemplateAtRegistration', 'hasUnmounted',
  188. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  189. // 'isReusable', 'tangoConfiguration',
  190. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  191. // */
  192.  
  193. ]);
  194.  
  195.  
  196. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  197.  
  198. // ----------------------------- Shortkey Keyboard Control -----------------------------
  199.  
  200. /*
  201. window.addEventListener('edm',()=>{
  202. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  203. });
  204.  
  205. window.addEventListener('edn',()=>{
  206. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  207. });
  208. window.addEventListener('edr',()=>{
  209. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  210. });
  211. */
  212.  
  213. // only for macOS with Chrome/Firefox 100+
  214. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  215.  
  216. const win = this instanceof Window ? this : window;
  217.  
  218. // Create a unique key for the script and check if it is already running
  219. const hkey_script = 'jswylcojvzts';
  220. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  221. win[hkey_script] = true;
  222.  
  223.  
  224.  
  225. let BY_PASS_KEYBOARD_CONTROL = false;
  226.  
  227.  
  228. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  229. /** @type {(f: ()=>{})=>{}} */
  230. const nextBrowserTick = (self || 0).nextBrowserTick || 0;
  231. const nextBrowserTick_ = nextBrowserTick || (f => f());
  232.  
  233. let p59 = 0;
  234.  
  235. const Promise = (async () => { })().constructor;
  236.  
  237. const PromiseExternal = ((resolve_, reject_) => {
  238. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  239. return class PromiseExternal extends Promise {
  240. constructor(cb = h) {
  241. super(cb);
  242. if (cb === h) {
  243. /** @type {(value: any) => void} */
  244. this.resolve = resolve_;
  245. /** @type {(reason?: any) => void} */
  246. this.reject = reject_;
  247. }
  248. }
  249. };
  250. })();
  251.  
  252. /**
  253. @param {number} x
  254. @param {number} d */
  255. const toFixed2 = (x, d) => {
  256. let t = x.toFixed(d);
  257. let y = `${+t}`;
  258. return y.length > t.length ? t : y;
  259. }
  260.  
  261.  
  262. let pf31 = new PromiseExternal();
  263.  
  264. // native RAF
  265. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  266.  
  267. // 1st wrapped RAF
  268. const baseRAF = (callback) => {
  269. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  270. pf31.then(() => {
  271. callback(hRes);
  272. });
  273. });
  274. };
  275.  
  276. // 2nd wrapped RAF
  277. window.requestAnimationFrame = baseRAF;
  278.  
  279. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  280. const indr = o => insp(o).$ || o.$ || 0;
  281.  
  282. const prototypeInherit = (d, b) => {
  283. const m = Object.getOwnPropertyDescriptors(b);
  284. for (const p in m) {
  285. if (!Object.getOwnPropertyDescriptor(d, p)) {
  286. Object.defineProperty(d, p, m[p]);
  287. }
  288. }
  289. };
  290.  
  291. /** @type {(o: Object | null) => WeakRef | null} */
  292. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  293.  
  294. /** @type {(wr: Object | null) => Object | null} */
  295. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  296.  
  297. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  298. if (DENY_requestStorageAccess) {
  299. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  300. Document.prototype.requestStorageAccessFor = undefined;
  301. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  302. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  303. Document.prototype.requestStorageAccessFor = function () {
  304. return new Promise((resolve, reject) => {
  305. reject();
  306. });
  307. };
  308. }
  309. }
  310.  
  311. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  312. // window.m3bb = new Set();
  313.  
  314. // const smb = Symbol();
  315. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  316. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  317. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  318.  
  319. // const fnProxySelf = function (...args) {
  320. // if (args[0] === smb) return this;
  321. // const cnt = kRef(this.ref);
  322. // if (cnt) {
  323. // if (typeof cnt[this.prop] !== 'function') console.error(`this.${this.prop} is not a function. [${cnt.is || 'nil'}]`)
  324. // return cnt[this.prop](...args); // might throw error
  325. // }
  326. // }
  327. // fnProxySelf.bind588 = fnProxySelf.bind;
  328. // const pFnHandler = {
  329. // get(target, prop){
  330. // if(prop === 'bind588') return 2;
  331. // const fnThis = target(smb);
  332. // if (fnThis && fnThis.prop && fnThis.ref) {
  333. // const cnt = kRef(fnThis.ref || null) || null;
  334. // if (cnt) {
  335. // const h = cnt[fnThis.prop];
  336. // const v = h[prop];
  337. // if (typeof v === 'function'){
  338. // if(typeof h === 'function'){
  339. // if (prop === 'call' || prop === 'bind' || prop === 'bind588' || prop === 'bind488' || prop === 'apply') {
  340. // if(h.bind588 === 1){
  341. // const g = function(...args){
  342. // console.log(1288, this)
  343. // return h.call(this, ...args);
  344. // };
  345. // console.log(399, g)
  346. // return g[prop];
  347. // // console.log(12778)
  348. // // console.log(target, target.call)
  349. // // return target[prop];
  350. // }
  351. // // independent of this
  352. // return v; // function.bind, function.call, function.apply
  353. // }
  354. // }
  355. // console.warn('cnt[fnThis.prop][prop] is function; might rely on this', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
  356. // // return new Proxy(fnProxySelf.bind588({ prop: prop, ref: new WeakRef(cnt[fnThis.prop]) }), pFnHandler);
  357. // }
  358. // return v;
  359. // }
  360. // }
  361. // },
  362. // set(target, prop, value) {
  363. // const fnThis = target(smb);
  364. // if (fnThis && fnThis.prop && fnThis.ref) {
  365. // const cnt = kRef(fnThis.ref || null) || null;
  366. // if (cnt) {
  367. // const h = cnt[fnThis.prop];
  368. // if (h) {
  369. // h[prop] = value;
  370. // } else {
  371. // console.log('h is nout found', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
  372. // }
  373. // }
  374. // }
  375. // return true;
  376. // }
  377. // };
  378.  
  379. const thisConversionFn = (thisArg) => {
  380. if (!thisArg) return null;
  381. const kThis = thisArg[vmb];
  382. if (kThis) {
  383. const ref = kThis.ref;
  384. return (ref ? kRef(ref) : null) || null;
  385. }
  386. return thisArg;
  387. }
  388.  
  389. const pFnHandler2 = {
  390. get(target, prop) {
  391. if (prop === vmc) return target;
  392. return Reflect.get(target, prop);
  393. },
  394. apply(target, thisArg, argumentsList) {
  395. thisArg = thisConversionFn(thisArg);
  396. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  397. }
  398. }
  399.  
  400. const proxySelfHandler = {
  401. get(target, prop) {
  402. if(prop === vmb) return target;
  403. const ref = target.ref;
  404. const cnt = kRef(ref);
  405. if (!cnt) return;
  406. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  407. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  408. return cnt[prop][vmd];
  409. }
  410. return cnt[prop];
  411. },
  412. set(target, prop, value) {
  413. const cnt = kRef(target.ref);
  414. if (!cnt) return true;
  415. if(value && (value[vmc] || value[vmb])){
  416. cnt[prop] = value[vmc] || thisConversionFn(value);
  417. return true;
  418. }
  419. cnt[prop] = value;
  420. return true;
  421. }
  422. };
  423.  
  424. const weakWrap = (thisArg) => {
  425. thisArg = thisConversionFn(thisArg);
  426. if (!thisArg) {
  427. console.error('thisArg is not found');
  428. return null;
  429. }
  430. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  431. }
  432.  
  433. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  434. window.getComputedStyle533 = window.getComputedStyle;
  435. window.getComputedStyle = function (a, ...args) {
  436. a = thisConversionFn(a);
  437. if (a) {
  438. return getComputedStyle533(a, ...args);
  439. }
  440. return null;
  441. }
  442. }
  443.  
  444. Function._count_bind_00 = 0;
  445. // Function._count_bind_01 = 0;
  446.  
  447. // let matchNativeCode = (Object+"");
  448. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  449. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  450.  
  451. // const matchConstructor = (thisArg) => {
  452. // const f = (thisArg || 0).constructor + "";
  453. // if (f.length > 45) return true;
  454. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  455. // if (f.includes('[native code]')){
  456. // return false;
  457. // }
  458. // return true;
  459. // }
  460. // return false;
  461. // }
  462.  
  463. // const acceptThis = (thisArg)=>{
  464. // // if(!thisArg || typeof thisArg !=='object') return false;
  465. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  466. // // if(typeof thisArg.path === 'string') return true;
  467. // // if(typeof thisArg.fn === 'function') return true;
  468. // // if(typeof thisArg.id === 'string') return true;
  469. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  470. // return false;
  471. // }
  472.  
  473. const patchFn = (fn) => {
  474.  
  475. let s = `${fn}`;
  476. if (s.length < 11 || s.includes('\n')) return false;
  477. if(s.includes('bind(this')) return true;
  478. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  479. // var a=this;
  480. // f.bind(this)
  481.  
  482.  
  483. return false;
  484. }
  485.  
  486. Function.prototype.bind488 = Function.prototype.bind;
  487. Function.prototype.bind = function(thisArg, ...args){
  488. if (thisConversionFn(thisArg) !== thisArg) {
  489. return this.bind488(thisArg, ...args);
  490. }
  491. if( thisArg && patchFn(this) ){
  492.  
  493. // console.log(599,`${this}`)
  494.  
  495. try {
  496. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  497. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  498. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  499. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  500. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  501. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  502. // // let b4 = false;
  503. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  504. // // b3 = false;
  505. // // b4 = false;
  506. // // b5 = false;
  507. // if (b1 || b2 || b3 ||b4 ) {
  508. const f = this;
  509. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  510. if (ps && ps[vmb]) {
  511. Function._count_bind_00++;
  512. return f.bind488(ps, ...args)
  513. }
  514. // }
  515. } catch (e) {
  516. console.warn(e)
  517. }
  518. }
  519. return this.bind488(thisArg, ...args);
  520. }
  521. Function.prototype.bind588 = 1;
  522. }
  523.  
  524.  
  525. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  526. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  527. const wm6 = new WeakMapOriginal();
  528.  
  529. const skipW = new WeakSet();
  530.  
  531.  
  532. window.WeakMap = class WeakMap extends WeakMapOriginal {
  533. constructor(iterable = undefined) {
  534. super();
  535. if (iterable && iterable[Symbol.iterator]) {
  536. for (const entry of iterable) {
  537. entry && this.set(entry[0], entry[1]);
  538. }
  539. }
  540. }
  541. delete(a) {
  542. if (!this.has(a)) return false;
  543. super.delete(a);
  544. return true;
  545. }
  546. get(a) {
  547. const p = super.get(a);
  548. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  549. let v = kRef(p);
  550. if (!v) {
  551. super.delete(a);
  552. }
  553. return v || undefined;
  554. }
  555. return p;
  556. }
  557. has(a) {
  558. if (!super.has(a)) return false;
  559. const p = super.get(a);
  560. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  561. if (!kRef(p)) {
  562. super.delete(a);
  563. return false;
  564. }
  565. }
  566. return true;
  567. }
  568. set(a, b) {
  569. let wq = b;
  570. if (b && (typeof b === 'function' || typeof b === 'object')) {
  571. if (b.deref) {
  572. skipW.add(b);
  573. wq = b;
  574. } else {
  575. wq = wm6.get(b);
  576. if (!wq) {
  577. wq = mWeakRef(b);
  578. wm6.set(b, wq);
  579. }
  580. }
  581. }
  582. super.set(a, wq);
  583. return this;
  584. }
  585. }
  586. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  587. configurable: true,
  588. enumerable: false,
  589. value: "WeakMap",
  590. writable: false
  591. });
  592. }
  593.  
  594. const isWatchPageURL = (url) => {
  595. url = url || location;
  596. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  597. };
  598.  
  599. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  600.  
  601. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  602. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  603. if (typeof customElements === 'undefined') {
  604. if (!('__CE_registry' in document)) {
  605. // https://github.com/webcomponents/polyfills/
  606. Object.defineProperty(document, '__CE_registry', {
  607. get() {
  608. // return undefined
  609. },
  610. set(nv) {
  611. if (typeof nv == 'object') {
  612. delete this.__CE_registry;
  613. this.__CE_registry = nv;
  614. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  615. }
  616. return true;
  617. },
  618. enumerable: false,
  619. configurable: true
  620. })
  621. }
  622. let eventHandler = (evt) => {
  623. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  624. const f = callback;
  625. callback = null;
  626. eventHandler = null;
  627. f();
  628. };
  629. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  630. } else {
  631. callback();
  632. }
  633. });
  634.  
  635. const whenCEDefined = isCustomElementsProvided
  636. ? (nodeName) => customElements.whenDefined(nodeName)
  637. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  638.  
  639. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  640. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  641. const f = performance.now23 = Performance.prototype.now;
  642.  
  643. let k = 0; // 0 <= k < 9998m
  644. let u = 0;
  645. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  646.  
  647. // By definition, performance.now() is mono increasing.
  648. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  649. performance.now = performance.now16 = function () {
  650. /**
  651. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  652. *
  653. * If consecutive session history entries had history.state.entryTime set to same value,
  654. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  655. * and modifying its return value slightly to make sure two close consecutive calls don't
  656. * get the same result helped with resolving the issue.
  657. */
  658. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  659. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  660.  
  661. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  662. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  663. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  664. else { // more than 9998 consecutive calls
  665. /**
  666. *
  667. * max no. of consecutive calls
  668. *
  669. * Sample Size: 4800
  670. * Sample Avg = 1565.375
  671. * Sample Median = 1469.5
  672. * Sample Max = 5660 << 7500 << 9999
  673. *
  674. *
  675. * */
  676. k = 0;
  677. s += 1 / 7;
  678. }
  679. return v + k; // 0 < v - M < v - M + k < v
  680. }
  681.  
  682. let loggerMsg = '';
  683. if (`${performance.now()}` === `${performance.now()}`) {
  684. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  685. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  686. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  687. }
  688. loggerMsg && console.warn(loggerMsg);
  689. })();
  690.  
  691. FIX_removeChild && (() => {
  692. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  693. Node.prototype.removeChild062 = Node.prototype.removeChild;
  694. Node.prototype.removeChild = function (child) {
  695. if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  696. this.removeChild062(child);
  697. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  698. // tooltip bug
  699. } else {
  700. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  701. }
  702. return child;
  703. }
  704. }
  705. })();
  706.  
  707. // WEAKREF_ShadyDOM
  708.  
  709. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  710.  
  711. const setupPlainShadyDOM = (b) => {
  712. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  713. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  714. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  715. b.patchOnDemand = true;
  716. b.preferPerformance = true;
  717. b.noPatch = true;
  718. }
  719.  
  720. const isPlainObject = (b, m) => {
  721. if (!b || typeof b !== 'object') return false;
  722. const e = Object.getOwnPropertyDescriptors(b);
  723. if (e.length <= m) return false;
  724. let pr = 0;
  725. for (const k in e) {
  726. const d = e[k];
  727. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  728. if (!('value' in d) || typeof d.value === 'function') return false;
  729. pr++;
  730. }
  731. return pr > m;
  732. }
  733.  
  734. let b;
  735.  
  736. let lz = 0;
  737.  
  738. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  739. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  740.  
  741. // Brave - ShadyDOM exists before userscripting
  742. b = sdp.value;
  743.  
  744. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  745. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  746. lz = 1;
  747. }
  748.  
  749. }
  750.  
  751.  
  752. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  753. } else if (!sdp) {
  754. } else {
  755. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  756. return;
  757. }
  758.  
  759. const shadyDOMNodeWRM = new WeakMap();
  760.  
  761. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  762.  
  763. const weakWrapperNodeHandlerFn = () => ({
  764. get() {
  765. let w = shadyDOMNodeWRM.get(this);
  766. if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
  767. return w;
  768. },
  769. set(nv) {
  770. shadyDOMNodeWRM.set(this, mWeakRef(nv));
  771. return true;
  772. },
  773. enumerable: true,
  774. configurable: true
  775. });
  776.  
  777. function weakWrapper(_ShadyDOM) {
  778. const ShadyDOM = _ShadyDOM;
  779. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  780. let nullElement = { node: null };
  781. Object.setPrototypeOf(nullElement, Element.prototype);
  782. let p = new ShadyDOM.Wrapper(nullElement);
  783. let d = Object.getOwnPropertyDescriptor(p, 'node');
  784. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  785. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  786. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  787. }
  788. }
  789. }
  790.  
  791. let previousWrapStore = null;
  792.  
  793. const standardWrap = function (a) {
  794. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  795. if (previousWrapStore) {
  796. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  797. if (s) {
  798. previousWrapStore.delete(a);
  799. shadyDOMNodeWRM.set(a, mWeakRef(s));
  800. }
  801. }
  802. let u = kRef(shadyDOMNodeWRM.get(a));
  803. if (!u) {
  804. u = new ShadyDOM.Wrapper(a);
  805. shadyDOMNodeWRM.set(a, mWeakRef(u));
  806. }
  807. return u;
  808. }
  809.  
  810.  
  811. function setupWrapFunc(_ShadyDOM) {
  812. const ShadyDOM = _ShadyDOM;
  813.  
  814.  
  815. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  816. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  817. return;
  818. }
  819. let mm = new Set();
  820. const pget = wmPD.value;
  821. WeakMap.prototype.get = function (a) {
  822. mm.add(this);
  823. return a;
  824. }
  825. try {
  826. let nullElement = { node: null };
  827. Object.setPrototypeOf(nullElement, Element.prototype);
  828. ShadyDOM.wrapIfNeeded(nullElement)
  829. ShadyDOM.wrap(nullElement)
  830. } catch (e) { }
  831. WeakMap.prototype.get = pget;
  832. if (mm.size !== 1) {
  833. mm.clear();
  834. return;
  835. }
  836. const p = mm.values().next().value;
  837. if (!(p instanceof WeakMap)) return;
  838. // p.clear();
  839. // p.get = function (a) { return a }
  840. // p.set = function (a, b) { return this }
  841. // console.log(188, window.n2n = mm, window.n2p = p)
  842.  
  843. // console.log(34929,p.size)
  844. previousWrapStore = p;
  845.  
  846. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  847. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  848. }
  849. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  850. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  851. }
  852.  
  853. }
  854.  
  855. function setupLZ3(nv) {
  856.  
  857. const ShadyDOM = nv;
  858.  
  859. const ShadyDOMSettings = ShadyDOM.settings;
  860. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  861. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  862. return false;
  863. }
  864.  
  865. weakWrapper(ShadyDOM);
  866.  
  867. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  868.  
  869. setupPlainShadyDOM(ShadyDOMSettings);
  870. setupPlainShadyDOM(ShadyDOM);
  871.  
  872. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  873.  
  874. setupWrapFunc(ShadyDOM);
  875. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  876. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  877.  
  878. // To be confirmed
  879. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  880. ShadyDOM.composedPath = function (e) {
  881. const t = (e || 0).target || null;
  882. if (!(t instanceof HTMLElement)) {
  883. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  884. }
  885. return t instanceof HTMLElement ? [t] : [];
  886. };
  887. }
  888.  
  889. }
  890.  
  891. }
  892.  
  893.  
  894. function setupLZ6(nv) {
  895.  
  896. const ShadyDOM = nv;
  897.  
  898. const ShadyDOMSettings = ShadyDOM.settings;
  899.  
  900. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  901. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  902. return false;
  903. }
  904.  
  905. weakWrapper(ShadyDOM);
  906.  
  907. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  908.  
  909. setupPlainShadyDOM(ShadyDOMSettings);
  910. setupPlainShadyDOM(ShadyDOM);
  911.  
  912. setupWrapFunc(ShadyDOM);
  913.  
  914. }
  915.  
  916. }
  917.  
  918. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  919.  
  920. const nv = b;
  921.  
  922. if (setupLZ6(nv) === false) return;
  923.  
  924. lz = 6;
  925.  
  926. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  927.  
  928. return;
  929. }
  930.  
  931. delete window.ShadyDOM;
  932.  
  933. Object.defineProperty(window, 'ShadyDOM', {
  934. get() {
  935. return b;
  936. },
  937. set(nv) {
  938. let ret = 0;
  939. try {
  940. do {
  941. if (!nv || !nv.settings) {
  942. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  943. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  944. lz = 1;
  945. break;
  946. } else {
  947. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  948. break;
  949. }
  950. }
  951.  
  952. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  953. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  954. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  955. break;
  956. }
  957.  
  958. if (setupLZ3(nv) === false) break;
  959.  
  960. lz = 3;
  961.  
  962. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  963.  
  964. ret = 1;
  965.  
  966. } while (0);
  967. } catch (e) {
  968. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  969. }
  970.  
  971. if (!ret) b = nv;
  972. else {
  973. delete this.ShadyDOM;
  974. this.ShadyDOM = nv;
  975. }
  976. return true;
  977. },
  978. enumerable: false,
  979. configurable: true
  980. });
  981.  
  982. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  983.  
  984. if (ENABLE_ASYNC_DISPATCHEVENT && nextBrowserTick) {
  985. const filter = new Set([
  986. 'yt-action',
  987. // 'iframe-src-replaced',
  988. 'shown-items-changed',
  989. 'can-show-more-changed', 'collapsed-changed',
  990.  
  991. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  992. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  993. 'yt-navigate-finish',
  994.  
  995. // 'data-changed','yt-watch-comments-ready'
  996. ])
  997. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  998. EventTarget.prototype.dispatchEvent = function (event) {
  999. const type = (event || 0).type;
  1000. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  1001. if (!filter.has(type) && !type.endsWith('-changed')) {
  1002. if (this instanceof Node || this instanceof Window) {
  1003. nextBrowserTick(() => this.dispatchEvent938(event));
  1004. return true;
  1005. }
  1006. }
  1007. }
  1008. return this.dispatchEvent938(event);
  1009. }
  1010. }
  1011.  
  1012. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  1013. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  1014. // const xhr = new XMLHttpRequest;
  1015. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  1016. if (!pdOri || pdOri.configurable !== true) return;
  1017. let propNeedles = null;
  1018. const pdNew = {
  1019. configurable: true,
  1020. enumerable: true,
  1021. get: function () {
  1022. propNeedles = this;
  1023. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  1024. throw new Error();
  1025. }
  1026. }
  1027. Object.defineProperty(Map.prototype, 'size', pdNew);
  1028. try {
  1029. XMLHttpRequest.prototype.open.call(0);
  1030. // xhr.open.call(null)
  1031. } catch (e) { }
  1032. Object.defineProperty(Map.prototype, 'size', pdOri);
  1033. if (!propNeedles) return;
  1034. const entries = [...propNeedles.entries()];
  1035. propNeedles.clear();
  1036. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  1037. })();
  1038.  
  1039. if (FIX_XHR_REQUESTING) {
  1040.  
  1041. const URL = window.URL || new Function('return URL')();
  1042. const createObjectURL = URL.createObjectURL.bind(URL);
  1043.  
  1044. XMLHttpRequest = (() => {
  1045. const XMLHttpRequest_ = XMLHttpRequest;
  1046. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  1047. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  1048. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  1049. constructor(...args) {
  1050. super(...args);
  1051. }
  1052. open(method, url, ...args) {
  1053. let skip = false;
  1054. if (!url || typeof url !== 'string') skip = true;
  1055. else if (typeof url === 'string') {
  1056. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  1057. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  1058. skip = true;
  1059. } else if (turl.includes('.youtube.com/pagead/')) {
  1060. skip = true;
  1061. } else if (turl.includes('.youtube.com/ptracking')) {
  1062. skip = true;
  1063. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  1064. skip = true;
  1065. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  1066. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  1067. skip = true;
  1068. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  1069. skip = true;
  1070. } else {
  1071. // skip = true; // for user activity logging e.g. watched videos
  1072. }
  1073. } else if (turl.includes('play.google.com/log')) {
  1074. skip = true;
  1075. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  1076. skip = true;
  1077. }
  1078. }
  1079. if (!skip) {
  1080. this.__xmMc8__ = 1;
  1081. return super.open(method, url, ...args);
  1082. } else {
  1083. this.__xmMc8__ = 2;
  1084. return super.open('GET', url0);
  1085. }
  1086. }
  1087. send(...args) {
  1088. if (this.__xmMc8__ === 1) {
  1089. return super.send(...args);
  1090. } else if (this.__xmMc8__ === 2) {
  1091. return super.send();
  1092. } else {
  1093. console.log('[yt-js-engine-tamer]', 'xhr warning');
  1094. return super.send(...args);
  1095. }
  1096. }
  1097. }
  1098. c.prototype.__xmMc8__ = 0;
  1099. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  1100. return c;
  1101. })();
  1102. }
  1103.  
  1104. // Alternative HACK -> Tabview Youtube
  1105. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  1106.  
  1107. // ---- << this.overscrollConfig HACK >> -----
  1108.  
  1109. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  1110.  
  1111. /*
  1112.  
  1113. ;function gZb(a, b) {
  1114. b = void 0 === b ? !0 : b;
  1115. a.addEventListener("wheel", hZb);
  1116. a.overscrollConfig = {
  1117. cooldown: b
  1118. }
  1119. }
  1120. function iZb(a) {
  1121. a.overscrollConfig = void 0;
  1122. a.removeEventListener("wheel", hZb)
  1123. }
  1124. function hZb(a) {
  1125. var b = a.deltaY
  1126. , c = a.target
  1127. , d = null;
  1128. if (window.Polymer && window.Polymer.Element) {
  1129. if (c = a.path || a.composedPath && a.composedPath()) {
  1130. c = g(c);
  1131. for (var e = c.next(); !e.done && (e = e.value,
  1132. !jZb(e, b)); e = c.next())
  1133. if (e.overscrollConfig) {
  1134. d = e;
  1135. break
  1136. }
  1137. }
  1138. } else
  1139. for (; c && !jZb(c, b); ) {
  1140. if (c.overscrollConfig) {
  1141. d = c;
  1142. break
  1143. }
  1144. c = c.parentElement
  1145. }
  1146. d && (b = d.overscrollConfig,
  1147. b.cooldown ? (d = a.deltaY,
  1148. c = b.lastDeltaY || 0,
  1149. b.lastDeltaY = d,
  1150. e = b.lastStopped || 0,
  1151. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  1152. c = !1) : (d = e + 600,
  1153. c = !0) : (d = Date.now() + 600,
  1154. c = !0),
  1155. d > Date.now() && (a.preventDefault(),
  1156. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  1157. }
  1158. */
  1159.  
  1160. let wheelHandler = function (a) {
  1161. if (window.Polymer && window.Polymer.Element) {
  1162. let c;
  1163. if (c = a.path || a.composedPath && a.composedPath()) {
  1164. for (const e of c) {
  1165. const cnt = insp(e);
  1166. if (e.overscrollConfig) e.overscrollConfig = void 0;
  1167. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  1168. }
  1169. }
  1170. } else {
  1171. let e = a.target;
  1172. for (; e instanceof Element; e = e.parentElement) {
  1173. const cnt = insp(e);
  1174. if (e.overscrollConfig) e.overscrollConfig = void 0;
  1175. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  1176. }
  1177. }
  1178. };
  1179.  
  1180. let checkWheelListenerObjs = null;
  1181.  
  1182. let getObjsFn = () => {
  1183. let euyVal = 0;
  1184. const eukElm = {};
  1185. Object.setPrototypeOf(eukElm, HTMLElement.prototype);
  1186. const euzObj = new Proxy(eukElm, {
  1187. get(target, prop) {
  1188. throw `ErrorF31.get(${prop})`
  1189. },
  1190. set(target, prop, value) {
  1191. throw `ErrorF33.set(${prop}, ${value})`
  1192. }
  1193. });
  1194. const euxElm = new Proxy(eukElm, {
  1195. get(target, prop) {
  1196. if (prop === 'scrollTop') {
  1197. euyVal = euyVal | 8;
  1198. return 0;
  1199. }
  1200. if (prop === 'overscrollConfig') {
  1201. euyVal = euyVal | 16;
  1202. return void 0;
  1203. }
  1204. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  1205. return 640;
  1206. }
  1207. if (prop === 'scrollLeft') {
  1208. euyVal = euyVal | 8;
  1209. return 0;
  1210. }
  1211. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  1212. return 800;
  1213. }
  1214. throw `ErrorF45.get(${prop})`
  1215. },
  1216. set(target, prop, value) {
  1217. throw `ErrorF47.set(${prop}, ${value})`
  1218. }
  1219. });
  1220. const eukEvt = {};
  1221. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  1222. const euyEvt = new Proxy(eukEvt, {
  1223. get(target, prop) {
  1224. if (prop === 'deltaY' || prop === 'deltaX') {
  1225. euyVal = euyVal | 1;
  1226. return -999;
  1227. }
  1228. if (prop === 'target') {
  1229. euyVal = euyVal | 2;
  1230. return euxElm
  1231. }
  1232. if (prop === 'path' || prop === 'composedPath') {
  1233. euyVal = euyVal | 2;
  1234. return [euxElm]
  1235. }
  1236. throw `ErrorF51.get(${prop})`
  1237. },
  1238. set(target, prop, value) {
  1239. throw `ErrorF53.set(${prop}, ${value})`
  1240. }
  1241. });
  1242. const setVal = (v) => {
  1243. euyVal = v;
  1244. }
  1245. const getVal = () => {
  1246. return euyVal;
  1247. }
  1248. return { euzObj, euyEvt, setVal, getVal };
  1249. }
  1250.  
  1251. let checkWheelListener = (callback) => {
  1252.  
  1253. let callbackIdentifier = '';
  1254.  
  1255. let res = null;
  1256. try {
  1257. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  1258. setVal(0);
  1259. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  1260. throw `RESULT${getVal()}`;
  1261. } catch (e) {
  1262. res = e;
  1263. }
  1264.  
  1265. res = `${res}` || `${null}`;
  1266. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  1267.  
  1268. callbackIdentifier = res;
  1269. if (callbackIdentifier === 'RESULT27') 0;
  1270. else if (callbackIdentifier === 'RESULT0') {
  1271. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  1272. } else if (callbackIdentifier.startsWith('RESULT')) {
  1273. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  1274. }
  1275. return callbackIdentifier;
  1276.  
  1277. };
  1278.  
  1279. let callbackFound = false;
  1280. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  1281. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  1282. // M-youtube-js-engine-tamer.52178
  1283. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  1284. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  1285. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  1286. // RESULTXX / ErrorFXX / Other...
  1287. if (callbackIdentifier === 'RESULT27') {
  1288. this.overscrollConfigDisable = true;
  1289. if (!callbackFound) {
  1290. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  1291. getObjsFn = checkWheelListener = null;
  1292. checkWheelListenerObjs = null;
  1293. wheelHandler = null;
  1294. }
  1295. return void 0;
  1296. } else if (!callbackFound && !this.overscrollConfigDisable) {
  1297. this.overscrollConfigDisable = true;
  1298. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  1299. }
  1300. }
  1301. return this.addEventListener52178(type, callback, option);
  1302. };
  1303.  
  1304. // ---- << this.overscrollConfig HACK >> -----
  1305.  
  1306. }
  1307.  
  1308. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  1309.  
  1310. let p_a_objWR = null;
  1311. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  1312. let ytPageReady = 0;
  1313.  
  1314. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  1315. let isGlobalSpaceControl = true;
  1316. let mediaPlayerElementWR = null;
  1317. let focusedElementAtSelection = null;
  1318.  
  1319. // let want_control_video = false;
  1320.  
  1321. let spaceBarControl_keyG = '';
  1322.  
  1323. let lastUserAction = 0;
  1324.  
  1325. const wmKeyControlPhase = new WeakMap();
  1326.  
  1327. let currentSelectionText = null;
  1328.  
  1329. const getCurrentSelectionText = () => {
  1330. if (currentSelectionText !== null) return currentSelectionText
  1331. return (currentSelectionText = getSelection() + "")
  1332. }
  1333.  
  1334. const pageMediaWatcher = () => {
  1335.  
  1336. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  1337. // want_control_video = false;
  1338. // }, { capture: true, passive: true });
  1339.  
  1340. document.addEventListener('yt-navigate', () => {
  1341. ytPageReady = 0;
  1342. });
  1343. document.addEventListener('yt-navigate-start', () => {
  1344. ytPageReady = 0;
  1345. });
  1346. document.addEventListener('yt-navigate-cache', () => {
  1347. ytPageReady = 0;
  1348. });
  1349.  
  1350. document.addEventListener('yt-navigate-finish', () => {
  1351. ytPageReady = 1;
  1352. });
  1353.  
  1354. document.addEventListener('durationchange', () => {
  1355. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  1356. if (elm.duration > 0.01) {
  1357. if (elm.closest('[hidden]')) continue;
  1358. mediaPlayerElementWR = mWeakRef(elm);
  1359. return;
  1360. }
  1361. }
  1362. }, { capture: true, passive: true });
  1363.  
  1364. document.addEventListener('selectionchange', (evt) => {
  1365. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  1366. currentSelectionText = null;
  1367. if (!(evt.target instanceof Node)) return;
  1368. focusedElementAtSelection = evt.target;
  1369. }, { capture: true, passive: true })
  1370.  
  1371. document.addEventListener('pointerdown', (evt) => {
  1372. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  1373. }, { capture: true, passive: true });
  1374.  
  1375.  
  1376. document.addEventListener('pointerup', (evt) => {
  1377. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  1378. }, { capture: true, passive: true });
  1379.  
  1380.  
  1381. document.addEventListener('keydown', (evt) => {
  1382. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  1383. }, { capture: true, passive: true });
  1384.  
  1385. document.addEventListener('keyup', (evt) => {
  1386. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  1387. }, { capture: true, passive: true });
  1388.  
  1389. };
  1390.  
  1391.  
  1392. const checkKeyB = (p_a_obj) => {
  1393.  
  1394. const boolList = new Set();
  1395. const p_a_obj_api = p_a_obj.api;
  1396.  
  1397. const nilFunc0 = function () {
  1398. return void 0
  1399. };
  1400. const mt = new Proxy({}, {
  1401. get(target, prop) {
  1402. if (prop === 'get') return nilFunc0;
  1403. return mt;
  1404. }
  1405. });
  1406. const nilFunc = function () {
  1407. return mt
  1408. };
  1409. const mw = new Proxy({}, {
  1410. get(target, prop) {
  1411. if (prop in p_a_obj_api) {
  1412. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  1413. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  1414. if (q && q.value) {
  1415. if (!q.writable) return q.value;
  1416. if (typeof q.value === 'string') return '';
  1417. if (typeof q.value === 'number') return 0;
  1418. if (typeof q.value === 'boolean') return false;
  1419. if (q.value && typeof q.value === 'object') return {};
  1420. }
  1421. }
  1422. return undefined;
  1423. },
  1424. set(target, prop) {
  1425. throw 'mwSet';
  1426. }
  1427. });
  1428.  
  1429. const mq = new Proxy({}, {
  1430. get(target, prop) {
  1431. if (prop === 'api') return mw;
  1432. if (prop in p_a_obj) {
  1433. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  1434. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  1435. if (q && q.value) {
  1436. if (!q.writable) return q.value;
  1437. if (typeof q.value === 'string') return '';
  1438. if (typeof q.value === 'number') return 0;
  1439. if (typeof q.value === 'boolean') return false;
  1440. if (q.value && typeof q.value === 'object') return {};
  1441. }
  1442. }
  1443. return undefined;
  1444. },
  1445. set(target, prop, val) {
  1446. if (typeof val === 'boolean') boolList.add(prop)
  1447. throw `mqSet(${prop},${val})`;
  1448. }
  1449. });
  1450.  
  1451. let res = ''
  1452. try {
  1453. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  1454. } catch (e) {
  1455. res = `ERROR::${e}`;
  1456. }
  1457.  
  1458. if (boolList.size === 1) {
  1459. const value = boolList.values().next().value;
  1460. if (res === `ERROR::mqSet(${value},${true})`) {
  1461. p_a_obj.__uZWaD__ = value;
  1462. }
  1463. }
  1464.  
  1465. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  1466.  
  1467. }
  1468.  
  1469.  
  1470. let pm_p_a = null;
  1471.  
  1472. const p_a_init = function () {
  1473. const r = this.init91();
  1474. const keyBw = this.__cPzfo__ || '__NIL__';
  1475. const p_a_obj = this[keyBw];
  1476. if (!p_a_obj) return;
  1477. try {
  1478. checkKeyB(p_a_obj);
  1479. } catch (e) { }
  1480. p_a_objWR = mWeakRef(p_a_obj);
  1481. if (FIX_SHORTCUTKEYS > 0) {
  1482. if (p_a_obj && !p_a_obj.hVhtg) {
  1483. p_a_obj.hVhtg = 1;
  1484.  
  1485. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  1486. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  1487. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  1488. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  1489. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  1490. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  1491.  
  1492. }
  1493. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  1494. // const api = p_a_obj.api
  1495. // api.hVhtg = 1;
  1496. // api.playVideo91 = api.playVideo;
  1497. // api.playVideo = p_a_jt.playVideo;
  1498. // api.pauseVideo91 = api.pauseVideo;
  1499. // api.pauseVideo = p_a_jt.pauseVideo;
  1500. // }
  1501. }
  1502. if (pm_p_a) {
  1503. pm_p_a.resolve();
  1504. pm_p_a = null;
  1505. }
  1506. return r;
  1507. };
  1508.  
  1509. const p_a_xt = {
  1510.  
  1511. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  1512.  
  1513. if (FIX_SHORTCUTKEYS === 2) {
  1514.  
  1515. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  1516.  
  1517. if (activeElement) {
  1518.  
  1519. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  1520.  
  1521. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  1522. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  1523. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  1524.  
  1525. }
  1526.  
  1527. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  1528. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  1529. // console.log(582, isDelayedSpaceBar)
  1530. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  1531.  
  1532. if (activeElement && (h === 'Space' || h === 'Enter')) {
  1533. const controlPhase = wmKeyControlPhase.get(activeElement);
  1534. if (controlPhase === 4 || controlPhase === 5) return false;
  1535. }
  1536. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  1537. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  1538. // if (!isSpaceKeyImmediate) return false;
  1539. // }
  1540. }
  1541.  
  1542. },
  1543.  
  1544. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  1545.  
  1546. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  1547.  
  1548. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  1549. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  1550. // console.log(583, isDelayedSpaceBar)
  1551. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  1552.  
  1553. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1554.  
  1555. let mediaWorking = false;
  1556. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  1557. mediaWorking = true;
  1558. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  1559. mediaWorking = true;
  1560. }
  1561. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  1562. mediaWorking && Promise.resolve().then(() => {
  1563. if (activeElement === document.activeElement) {
  1564. return activeElement.blur()
  1565. } else {
  1566. return false
  1567. }
  1568. }).then((r) => {
  1569. r !== false && mediaPlayerElement.focus();
  1570. });
  1571. }
  1572. },
  1573.  
  1574.  
  1575. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  1576.  
  1577. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  1578.  
  1579. const activeElement = document.activeElement;
  1580.  
  1581. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  1582. if (allow === false) return false;
  1583.  
  1584. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  1585. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  1586.  
  1587. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  1588.  
  1589. return ret;
  1590. },
  1591. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  1592.  
  1593.  
  1594. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  1595.  
  1596. const activeElement = document.activeElement;
  1597. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  1598. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  1599. // }
  1600. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  1601. if (allow === false) return false;
  1602.  
  1603. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  1604. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  1605.  
  1606. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  1607.  
  1608. return ret;
  1609. }
  1610.  
  1611. };
  1612.  
  1613. // const p_a_jt = { // API
  1614.  
  1615. // playVideo(a) { // without spinner effect
  1616.  
  1617. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  1618.  
  1619. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1620. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  1621. // want_control_video = true;
  1622. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  1623. // }
  1624.  
  1625. // }
  1626. // return this.playVideo91(a);
  1627.  
  1628. // },
  1629.  
  1630. // pauseVideo(a) { // without spinner effect
  1631.  
  1632. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  1633.  
  1634. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1635. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  1636. // want_control_video = true;
  1637. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  1638. // }
  1639.  
  1640. // }
  1641. // return this.pauseVideo91(a);
  1642.  
  1643. // }
  1644. // };
  1645.  
  1646. let flagSpeedMaster = null;
  1647. const getSpeedMasterControlFlag = () => {
  1648.  
  1649. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  1650. isSpeedMastSpacebarControlEnabled = false;
  1651. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  1652. isSpeedMastSpacebarControlEnabled = true;
  1653. }
  1654. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  1655. isSpeedMastSpacebarControlEnabled = true;
  1656. }
  1657.  
  1658. if (flagSpeedMaster === null) {
  1659. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  1660. if (!p) {
  1661. flagSpeedMaster = false;
  1662. } else {
  1663.  
  1664. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  1665.  
  1666. }
  1667.  
  1668. }
  1669. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  1670.  
  1671. return isSpeedMastSpacebarControlEnabled;
  1672. }
  1673.  
  1674.  
  1675. const getGlobalSpacebarControlFlag = () => {
  1676.  
  1677. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  1678. isGlobalSpaceControl = false;
  1679. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  1680. isGlobalSpaceControl = true;
  1681. }
  1682. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  1683. isGlobalSpaceControl = true;
  1684. }
  1685.  
  1686. return isGlobalSpaceControl;
  1687. }
  1688.  
  1689. const keyboardController = async (_yt_player) => {
  1690.  
  1691. const keyQT = getQT(_yt_player);
  1692. const keySV = getSV(_yt_player);
  1693. const keyDX = getDX(_yt_player);
  1694. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  1695.  
  1696. if (!keyDX) return;
  1697. if (keyDX === keyQT || keyDX === keySV) return;
  1698.  
  1699. if (typeof keyDX !== 'string') return;
  1700.  
  1701. let lastAccessKey = '';
  1702. let lastAccessKeyConfirmed = '';
  1703. const mb = new Proxy({}, {
  1704. get(target, prop) {
  1705. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  1706. throw 'mbGet'
  1707. },
  1708. set(target, prop, val) {
  1709. throw 'mbSet'
  1710. }
  1711. });
  1712. const ma = new Proxy({}, {
  1713. get(target, prop) {
  1714. lastAccessKey = prop;
  1715. return mb
  1716. },
  1717. set(target, prop, val) {
  1718. throw 'maSet'
  1719. }
  1720. });
  1721.  
  1722. let keyBw = '';
  1723. try {
  1724. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  1725. } catch (e) {
  1726. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  1727. keyBw = lastAccessKeyConfirmed;
  1728. }
  1729. }
  1730.  
  1731. if (!keyBw) return;
  1732.  
  1733. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  1734.  
  1735. pm_p_a = new PromiseExternal();
  1736.  
  1737. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  1738.  
  1739. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  1740.  
  1741. _yt_player[keyDX].prototype.init = p_a_init;
  1742.  
  1743. await pm_p_a.then();
  1744. const p_a_obj = kRef(p_a_objWR);
  1745.  
  1746. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  1747.  
  1748.  
  1749. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  1750.  
  1751. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  1752.  
  1753. if (!isSpeedMastSpacebarControlEnabled) {
  1754.  
  1755. if (config && config.EXPERIMENT_FLAGS) {
  1756. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  1757. }
  1758. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  1759. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  1760. }
  1761.  
  1762. } else {
  1763.  
  1764. if (config && config.EXPERIMENT_FLAGS) {
  1765. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  1766. }
  1767. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  1768. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  1769. }
  1770.  
  1771. }
  1772.  
  1773. }
  1774.  
  1775. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  1776.  
  1777.  
  1778.  
  1779.  
  1780. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  1781.  
  1782. // console.log(p_a_obj.handleGlobalKeyUp)
  1783. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  1784.  
  1785. // console.log(p_a_obj.api)
  1786.  
  1787.  
  1788. // QT -> DX(SV) -> p_a
  1789.  
  1790.  
  1791. /*
  1792. *
  1793. *
  1794. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  1795. b = void 0 === b ? !1 : b;
  1796. c = void 0 === c ? !1 : c;
  1797. d = void 0 === d ? !1 : d;
  1798. e = void 0 === e ? !1 : e;
  1799. var l = g.PT(this);
  1800. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  1801. }
  1802.  
  1803. */
  1804.  
  1805. /*
  1806. *
  1807. *
  1808. *
  1809. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  1810. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  1811. }
  1812.  
  1813. */
  1814.  
  1815.  
  1816. // if(!keyDX) return;
  1817.  
  1818. // console.log(4999, keyDX)
  1819.  
  1820. };
  1821.  
  1822.  
  1823. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  1824.  
  1825. const p_a_obj = kRef(p_a_objWR);
  1826. // const api = p_a_obj.api;
  1827.  
  1828.  
  1829. // console.log(540);
  1830.  
  1831. let boolList = null;
  1832. let ret;
  1833. isSpaceKeyImmediate = true;
  1834. try {
  1835.  
  1836. ret = 0;
  1837. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  1838. let p_a_objT;
  1839. if (!spaceBarControl_keyG) { // just in case
  1840. boolList = new Set();
  1841. p_a_objT = new Proxy(p_a_obj, {
  1842. get(target, prop, handler) {
  1843. const val = target[prop];
  1844. if (typeof val !== 'boolean') return val;
  1845. boolList.add(prop);
  1846. // console.log(555, prop, val);
  1847. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  1848. spaceBarControl_keyG = prop;
  1849. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  1850. val = false;
  1851. }
  1852. return val;
  1853. }
  1854. });
  1855.  
  1856.  
  1857. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  1858. p_a_obj[spaceBarControl_keyG] = false;
  1859. p_a_objT = p_a_obj;
  1860. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  1861. } else {
  1862.  
  1863. p_a_objT = p_a_obj;
  1864. }
  1865.  
  1866. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  1867.  
  1868.  
  1869. } catch (e) {
  1870. console.log(e)
  1871. }
  1872. isSpaceKeyImmediate = false;
  1873.  
  1874. if (boolList && boolList.size === 1) {
  1875. const value = boolList.values().next().value;
  1876. spaceBarControl_keyG = value;
  1877. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  1878.  
  1879. }
  1880.  
  1881. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  1882.  
  1883. return ret;
  1884. }
  1885.  
  1886. const shortcutKeysFixer = () => {
  1887.  
  1888. let pausePromiseControlJ = 0;
  1889.  
  1890.  
  1891. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  1892.  
  1893. let controlPhase = 0;
  1894. const aElm = document.activeElement;
  1895.  
  1896. if (aElm) {
  1897.  
  1898. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  1899.  
  1900. if (typeof controlPhaseCache === 'number') {
  1901.  
  1902. controlPhase = controlPhaseCache;
  1903. } else {
  1904.  
  1905. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  1906. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  1907. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  1908. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  1909. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  1910. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  1911. else {
  1912. if (aElm instanceof HTMLElement && aElm.closest('[role]')) controlPhase = 5;
  1913. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  1914. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  1915. else if (!(aElm instanceof HTMLElement) && (aElm instanceof Element)) controlPhase = 2; // svg
  1916. }
  1917.  
  1918. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement) && aElm.contains(mediaPlayerElement)) {
  1919. controlPhase = 0;
  1920. }
  1921.  
  1922. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  1923. if (aElm.closest('[contenteditable], input, textarea')) {
  1924. controlPhase = 5;
  1925. } else if (aElm.closest('button')) {
  1926. controlPhase = 4;
  1927. }
  1928. }
  1929.  
  1930. if (aElm.closest('#movie_player')) controlPhase = 6;
  1931.  
  1932. wmKeyControlPhase.set(aElm, controlPhase);
  1933.  
  1934. }
  1935. }
  1936.  
  1937. return controlPhase;
  1938.  
  1939. }
  1940.  
  1941. const isStateControllable = (api) => {
  1942. let appState = null;
  1943. let playerState = null;
  1944. let adState = null;
  1945. try {
  1946. appState = api.getAppState();
  1947. playerState = api.getPlayerState();
  1948. adState = api.getAdState();
  1949. } catch (e) { }
  1950. // ignore playerState -1
  1951. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  1952. };
  1953.  
  1954.  
  1955. const keyEventListener = (evt) => {
  1956. if (BY_PASS_KEYBOARD_CONTROL) return;
  1957.  
  1958. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  1959. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  1960. if (!ytPageReady) return;
  1961.  
  1962. if (evt.defaultPrevented === true) return;
  1963.  
  1964. const p_a_obj = kRef(p_a_objWR);
  1965.  
  1966. if (!p_a_obj) return;
  1967.  
  1968.  
  1969. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  1970. if (!mediaPlayerElement) return;
  1971.  
  1972. // let focusBodyIfSuccess = false;
  1973.  
  1974. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  1975.  
  1976. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  1977. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  1978. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  1979.  
  1980.  
  1981. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  1982.  
  1983. // console.log(`${evt.type}::controlPhase`,controlPhase)
  1984.  
  1985. // if (controlPhase == 4) {
  1986. // focusBodyIfSuccess = true;
  1987. // }
  1988.  
  1989. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  1990. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  1991.  
  1992. if (FIX_SHORTCUTKEYS < 2) return;
  1993. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  1994.  
  1995. let rr;
  1996. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  1997.  
  1998.  
  1999.  
  2000. let useImprovedPauseResume = false;
  2001.  
  2002. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  2003.  
  2004. const api = p_a_obj.api;
  2005. const stateControllable = isStateControllable(api);
  2006. // console.log(2122, appState, playerState, adState)
  2007.  
  2008. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  2009.  
  2010. useImprovedPauseResume = true;
  2011.  
  2012. }
  2013.  
  2014.  
  2015. }
  2016.  
  2017.  
  2018. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  2019. if (evt.type === 'keydown') {
  2020.  
  2021. if (useImprovedPauseResume) {
  2022.  
  2023. const isPaused = mediaPlayerElement.paused;
  2024.  
  2025. const cj = ++pausePromiseControlJ;
  2026. Promise.resolve().then(() => {
  2027.  
  2028. if (cj !== pausePromiseControlJ) return;
  2029.  
  2030. if (mediaPlayerElement.paused !== isPaused) return;
  2031.  
  2032. const ret = ytResumeFn();
  2033. if (!ret) { // fallback
  2034. isPaused ? api.playVideo() : api.pauseVideo();
  2035. }
  2036.  
  2037. /*
  2038. let a = void 0;
  2039. console.log('Rb', api.Rb())
  2040. a = !window._yt_player.nL(api.Rb());
  2041. p_a_obj.Wd.kG(a)
  2042. a ? api.playVideo() : api.pauseVideo();
  2043.  
  2044. */
  2045.  
  2046.  
  2047. });
  2048. rr = true;
  2049. } else {
  2050.  
  2051. isSpaceKeyImmediate = true;
  2052. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  2053. isSpaceKeyImmediate = false;
  2054. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  2055.  
  2056. }
  2057.  
  2058.  
  2059. } else if (evt.type === 'keyup') {
  2060.  
  2061. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  2062.  
  2063. rr = true;
  2064. } else {
  2065.  
  2066. isSpaceKeyImmediate = true;
  2067. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  2068. isSpaceKeyImmediate = false;
  2069. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  2070.  
  2071. }
  2072.  
  2073.  
  2074. /*
  2075.  
  2076. if (d)
  2077. switch (c) {
  2078. case 32:
  2079. case 13:
  2080. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  2081. b = !0,
  2082. e = !1;
  2083. else if (e) {
  2084. var m = d.getAttribute("role");
  2085. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  2086. d.click(),
  2087. f = !0)
  2088. }
  2089. break;
  2090. case 37:
  2091. case 39:
  2092. case 36:
  2093. case 35:
  2094. b = "slider" === d.getAttribute("role");
  2095. break;
  2096. case 38:
  2097. case 40:
  2098. m = d.getAttribute("role"),
  2099. d = 38 === c ? d.previousSibling : d.nextSibling,
  2100. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  2101. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  2102. f = b = !0))
  2103. }
  2104. if (e && !f)
  2105. switch (c) {
  2106. case 38:
  2107. f = Math.min(this.api.getVolume() + 5, 100);
  2108. XV(this.Wd, f, !1);
  2109. this.api.setVolume(f);
  2110. h = f = !0;
  2111. break;
  2112. case 40:
  2113. f = Math.max(this.api.getVolume() - 5, 0);
  2114. XV(this.Wd, f, !0);
  2115. this.api.setVolume(f);
  2116. h = f = !0;
  2117. break;
  2118. case 36:
  2119. this.api.Yh() && (this.api.startSeekCsiAction(),
  2120. this.api.seekTo(0, void 0, void 0, void 0, 79),
  2121. h = f = !0);
  2122. break;
  2123. case 35:
  2124. this.api.Yh() && (this.api.startSeekCsiAction(),
  2125. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  2126. h = f = !0)
  2127. }
  2128. */
  2129.  
  2130. }
  2131.  
  2132.  
  2133. if (rr) {
  2134.  
  2135. // focusBodyIfSuccess && Promise.resolve().then(() => {
  2136. // activeElement === document.activeElement && activeElement.blur();
  2137. // });
  2138.  
  2139. evt.preventDefault();
  2140. evt.stopImmediatePropagation();
  2141. evt.stopPropagation();
  2142.  
  2143. }
  2144.  
  2145. };
  2146.  
  2147. document.addEventListener('keydown', keyEventListener, { capture: true });
  2148.  
  2149.  
  2150. document.addEventListener('keyup', keyEventListener, { capture: true });
  2151.  
  2152. }
  2153.  
  2154. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  2155.  
  2156. })();
  2157.  
  2158.  
  2159. pageMediaWatcher();
  2160. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  2161.  
  2162.  
  2163. const check_for_set_key_order = (() => {
  2164.  
  2165. let mySet = new Set();
  2166.  
  2167. mySet.add("value1");
  2168. mySet.add("value2");
  2169. mySet.add("value3");
  2170.  
  2171. // Function to convert Set values to an array
  2172. function getSetValues(set) {
  2173. return Array.from(set.values());
  2174. }
  2175.  
  2176. // Function to test if the Set maintains insertion order
  2177. function testSetOrder(set, expectedOrder) {
  2178. let values = getSetValues(set);
  2179. return expectedOrder.join(',') === values.join(',');
  2180. }
  2181.  
  2182. // Test 1: Initial order
  2183. if (mySet.values().next().value !== "value1") return false;
  2184. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  2185.  
  2186. // Test 2: After deleting an element
  2187. mySet.delete("value2");
  2188. if (mySet.values().next().value !== "value1") return false;
  2189. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  2190.  
  2191. // Test 3: After re-adding a deleted element
  2192. mySet.add("value2");
  2193. if (mySet.values().next().value !== "value1") return false;
  2194. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  2195.  
  2196. // Test 4: After adding a new element
  2197. mySet.add("value4");
  2198. if (mySet.values().next().value !== "value1") return false;
  2199. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  2200.  
  2201. // Test 5: Delete+Add
  2202. mySet.delete("value1");
  2203. mySet.delete("value3");
  2204. mySet.add("value3");
  2205. mySet.add("value1");
  2206. if (mySet.values().next().value !== "value2") return false;
  2207. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  2208.  
  2209. return true;
  2210. })();
  2211.  
  2212.  
  2213. // const qm47 = Symbol();
  2214. const qm57 = Symbol();
  2215. const qm53 = Symbol();
  2216. const qn53 = Symbol();
  2217.  
  2218.  
  2219. const ump3 = new WeakMap();
  2220.  
  2221. const stp = document.createElement('noscript');
  2222. stp.id = 'weakref-placeholder'
  2223.  
  2224.  
  2225. const handlerWFs = {};
  2226.  
  2227. const createHandlerWF = (z, usePlaceholder) => {
  2228.  
  2229. return {
  2230. get() {
  2231. const elm = this;
  2232. const wr = elm[z];
  2233. if (!wr) return null;
  2234. const m = kRef(wr);
  2235. if (!m && usePlaceholder) {
  2236. if (typeof usePlaceholder === 'function') usePlaceholder(elm);
  2237. return stp;
  2238. }
  2239. return m;
  2240. },
  2241. set(nv) {
  2242. const elm = this;
  2243. elm[z] = nv ? mWeakRef(nv) : null;
  2244. return true;
  2245. },
  2246. configurable: true,
  2247. enumerable: true
  2248.  
  2249. }
  2250. }
  2251.  
  2252. const setupWF = typeof WeakRef !== 'undefined' ? (elm, s, usePlaceholder) => {
  2253. const z = `${s}72`;
  2254. if (z in elm) return;
  2255. const pd = Object.getOwnPropertyDescriptor(elm, s);
  2256. if (pd && pd.configurable && !pd.get && !pd.set) {
  2257. const p = pd.value;
  2258. delete elm[s];
  2259. const handlerWF = handlerWFs[s] || (handlerWFs[s] = createHandlerWF(z, usePlaceholder));
  2260. Object.defineProperty(elm, s, handlerWF);
  2261. elm[s] = p;
  2262. elm = null;
  2263. }
  2264. } : null;
  2265.  
  2266. const mxMapPD = new WeakMap();
  2267.  
  2268. const identifierWD = Symbol();
  2269. const handlerWD = {
  2270. get(obj, prop) {
  2271. if (prop === identifierWD) return true;
  2272. const val = obj[prop];
  2273. if (typeof (val || 0).deref === 'function') {
  2274. return val.deref();
  2275. }
  2276. return val;
  2277. },
  2278. set(obj, prop, val) {
  2279. if (val instanceof Node) {
  2280. obj[prop] = mWeakRef(val);
  2281. } else {
  2282. obj[prop] = val;
  2283. }
  2284. return true;
  2285. }
  2286. };
  2287.  
  2288.  
  2289. const configureVisibilityObserverT_ = function () {
  2290. const hostElement = this.hostElement;
  2291. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  2292. this.unobserve_();
  2293. } else {
  2294. return this.configureVisibilityObserver27_();
  2295. }
  2296. };
  2297. const getParentRendererT = function () {
  2298. const hostElement = this.hostElement;
  2299. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  2300. return null;
  2301. } else {
  2302. return this.getParentRenderer27();
  2303. }
  2304. }
  2305.  
  2306. const attachedT = function () {
  2307. const hostElement = this.hostElement;
  2308. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  2309. if (this.isAttached === true) this.isAttached = false;
  2310. return void 0;
  2311. } else {
  2312. return this.attached27();
  2313. }
  2314. }
  2315.  
  2316. const hostElementCleanUp = (dh) => {
  2317. if (typeof dh.dispose === 'function') {
  2318. try {
  2319. if (dh.visibilityMonitor || dh.visibilityObserver) {
  2320. dh.dispose();
  2321. dh.visibilityMonitor = null;
  2322. dh.visibilityObserver = null;
  2323. }
  2324. } catch (e) { }
  2325. }
  2326. if (typeof dh.detached === 'function') {
  2327. try {
  2328. if (dh.visibilityObserverForChild_ || dh.localVisibilityObserver_) {
  2329. dh.detached();
  2330. dh.visibilityObserverForChild_ = null;
  2331. dh.localVisibilityObserver_ = null;
  2332. }
  2333. } catch (e) { }
  2334. }
  2335. };
  2336.  
  2337. const setupDataHost_ = (eh) => {
  2338. if (typeof eh.configureVisibilityObserver_ === 'function' && !eh.configureVisibilityObserver27_) {
  2339. eh.configureVisibilityObserver27_ = eh.configureVisibilityObserver_;
  2340. eh.configureVisibilityObserver_ = configureVisibilityObserverT_;
  2341. }
  2342. if (typeof eh.getParentRenderer === 'function' && !eh.getParentRenderer27) {
  2343. eh.getParentRenderer27 = eh.getParentRenderer;
  2344. eh.getParentRenderer = getParentRendererT;
  2345. }
  2346. if (typeof eh.attached === 'function' && !eh.attached27) {
  2347. eh.attached27 = eh.attached;
  2348. eh.attached = attachedT;
  2349. }
  2350. }
  2351.  
  2352. PROP_OverReInclusion_AVOID && (() => {
  2353.  
  2354.  
  2355. if (typeof HTMLElement.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement.prototype.hasOwnProperty !== 'function') return;
  2356. const f = HTMLElement.prototype.hasOwnProperty72 = HTMLElement.prototype.hasOwnProperty;
  2357. let byPassVal = null;
  2358. let byPassCount = 0;
  2359. let mmw = new Set();
  2360. HTMLElement.prototype.hasOwnProperty = function (prop) {
  2361. if (arguments.length !== 1) return f.apply(this, arguments);
  2362. if (byPassVal !== null && typeof prop === 'string') {
  2363.  
  2364. if (PROP_OverReInclusion_LIST.has(prop)) {
  2365. byPassCount++;
  2366. return byPassVal;
  2367. }
  2368. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  2369.  
  2370. }
  2371. return this.hasOwnProperty72(prop);
  2372. };
  2373.  
  2374.  
  2375. /*
  2376. z.prototype.forwardDynamicProps = function() {
  2377. var B = m(this.inst);
  2378. B = h(B);
  2379. for (var F = B.next(); !F.done; F = B.next()) {
  2380. var H = h(F.value);
  2381. F = H.next().value;
  2382. H = H.next().value;
  2383. my(this, F, H);
  2384. r(b) && !ly(F) && Wua(this.inst, F)
  2385. }
  2386. }
  2387. */
  2388.  
  2389.  
  2390.  
  2391. let byPassZeroShowed = false;
  2392. const forwardDynamicPropsGeneral = function () {
  2393. byPassVal = true;
  2394. byPassCount = 0;
  2395. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  2396. const ret = this.forwardDynamicProps72();
  2397. byPassVal = null;
  2398. if (byPassCount === 0 && !byPassZeroShowed) {
  2399. byPassZeroShowed = true;
  2400. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  2401. }
  2402. byPassCount = 0;
  2403. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) console.log(399, '[yt-js-engine-tamer]', [...mmw])
  2404. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  2405. return ret;
  2406. };
  2407.  
  2408. const propCheck = (proto) => {
  2409. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  2410. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  2411. if (proto.forwardDynamicProps.length === 0) {
  2412. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  2413. }
  2414. }
  2415. };
  2416.  
  2417. const valMap = new WeakMap();
  2418. Object.defineProperty(HTMLElement.prototype, 'didForwardDynamicProps', {
  2419. get() {
  2420. propCheck(this.constructor.prototype);
  2421. return valMap.get(this);
  2422. },
  2423. set(nv) {
  2424. propCheck(this.constructor.prototype);
  2425. valMap.set(this, nv);
  2426. return true;
  2427. },
  2428. enumerable: false,
  2429. configurable: true
  2430.  
  2431. });
  2432.  
  2433. promiseForCustomYtElementsReady.then(() => {
  2434. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  2435. if (customElements.define.length !== 2) return;
  2436. customElements.define72 = customElements.define;
  2437. customElements.define = function (b, w) {
  2438. propCheck(w.prototype);
  2439. const ret = this.define72(b, w);
  2440. return ret;
  2441. }
  2442. });
  2443.  
  2444. })();
  2445.  
  2446.  
  2447. let delay300 = null;
  2448.  
  2449. const convertionFuncMap = new WeakMap();
  2450. let val_kevlar_should_maintain_stable_list = null;
  2451.  
  2452. const createStampDomArrayFn_ = (fn) => {
  2453. if (val_kevlar_should_maintain_stable_list === null) {
  2454. const config_ = ((window.yt || 0).config_ || 0);
  2455. val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true
  2456. }
  2457. const gn = function (a, b, c, d, e, h) {
  2458. const isNonEmptyArray = (a || 0).length >= 1
  2459. if (!isNonEmptyArray) {
  2460. return fn.call(this, undefined, b, undefined, d);
  2461. } else if (h === undefined && typeof b === 'string' && c && typeof c === 'object' && this.is && val_kevlar_should_maintain_stable_list) {
  2462. if (c.clientSideToggleMenuItemRenderer) {
  2463. h = false;
  2464. } else {
  2465. h = true;
  2466. }
  2467. }
  2468. return fn.call(this, a, b, c, d, e, h)
  2469. }
  2470. gn.originalFn = fn;
  2471. convertionFuncMap.set(fn, gn);
  2472. return gn;
  2473. }
  2474.  
  2475. const fixStampDomArrayStableList = (h) => {
  2476. if (!h.stampDomArray_) return;
  2477. const proto = h.__proto__;
  2478. const f = proto.stampDomArray_;
  2479. if (!proto.stampDomArrayF001_ && typeof f === 'function' && f.length === 6) {
  2480. proto.stampDomArrayF001_ = 1;
  2481. proto.stampDomArray_ = convertionFuncMap.get(f) || createStampDomArrayFn_(f);
  2482. }
  2483. }
  2484.  
  2485. const weakenStampReferences = (() => {
  2486.  
  2487. const DEBUG_STAMP = false;
  2488.  
  2489. const s1 = Symbol();
  2490. const handler1 = {
  2491. get(target, prop, receiver) {
  2492. if (prop === 'object') {
  2493. return kRef(target[s1]); // avoid memory leakage
  2494. }
  2495. if (prop === '__proxy312__') return 1;
  2496. return target[prop];
  2497. }
  2498. };
  2499. const handler2 = {
  2500. get(target, prop, receiver) {
  2501. if (prop === 'indexSplices') {
  2502. return kRef(target[s1]); // avoid memory leakage
  2503. }
  2504. if (prop === '__proxy312__') return 1;
  2505. return target[prop];
  2506. }
  2507. }
  2508. return (h) => {
  2509.  
  2510. if (h.rendererStamperApplyChangeRecord_ || h.stampDomArraySplices_) {
  2511. const proto = h.__proto__;
  2512. if (!proto.yzxer && (proto.rendererStamperApplyChangeRecord_ || proto.stampDomArraySplices_)) {
  2513. proto.yzxer = 1;
  2514.  
  2515. const list = [
  2516. // "rendererStamperObserver_", // 3 ==> rendererStamperApplyChangeRecord_
  2517. "rendererStamperApplyChangeRecord_", // 3
  2518. "forwardRendererStamperChanges_", // 3
  2519. "stampDomArraySplices_", // 3
  2520. "stampDomArray_", // 6
  2521. "deferRenderStamperBinding_", // 3
  2522. ];
  2523. for (const key of list) {
  2524. const pey = `${key}$wq0iw_`;
  2525. const vKey = proto[key];
  2526. if (typeof vKey !== 'function') continue;
  2527. if (proto[pey] || vKey.length === 0) continue;
  2528.  
  2529. if (key === 'stampDomArraySplices_' && vKey.length === 3) {
  2530. proto[pey] = vKey;
  2531. proto[key] = function (a, b, c) {
  2532.  
  2533. if (typeof a === 'string' && typeof b === 'string' && typeof c === 'object' && c && c.indexSplices && c.indexSplices.length >= 1 && !c.indexSplices.rzgjr) {
  2534.  
  2535. c.indexSplices = c.indexSplices.map(e => {
  2536. if (e.__proxy312__) return e;
  2537. e[s1] = mWeakRef(e.object);
  2538. e.object = null;
  2539. return new Proxy(e, handler1);
  2540. });
  2541. c.indexSplices.rzgjr = 1;
  2542.  
  2543. c[s1] = mWeakRef(c.indexSplices);
  2544. c.indexSplices = null;
  2545. c = new Proxy(c, handler2)
  2546. arguments[2] = c;
  2547.  
  2548. }
  2549. // console.log(key, arguments.length, [...arguments]);
  2550. return proto[pey].call(this, a, b, c);
  2551. }
  2552.  
  2553. } else if (key === 'rendererStamperApplyChangeRecord_' && vKey.length === 3) {
  2554.  
  2555. // Nil
  2556.  
  2557. } else if (DEBUG_STAMP) {
  2558.  
  2559. console.log(proto.isRenderer_, 'ms_' + key, vKey.length, h.is)
  2560. proto[pey] = vKey;
  2561. proto[key] = function () {
  2562. if (key === 'rendererStamperApplyChangeRecord_' && typeof arguments[3] === 'object') {
  2563. console.log(key, arguments.length, { value: arguments[3].value, base: arguments[3].base, })
  2564. }
  2565. console.log(key, arguments.length, [...arguments]);
  2566. return proto[pey].apply(this, arguments);
  2567. }
  2568.  
  2569. }
  2570.  
  2571. }
  2572.  
  2573.  
  2574. // const m = (Object.mkss = Object.mkss || new Set());
  2575. // Object.keys(h.__proto__).filter(e => e.toLowerCase().includes('stamp') && typeof h[e] === 'function').forEach(e => m.add(e))
  2576. // console.log([...m])
  2577. }
  2578. }
  2579.  
  2580. }
  2581. })();
  2582.  
  2583. const setupDiscreteTasks = (h, rb) => {
  2584.  
  2585. if (rb) {
  2586. if (h.ky36) return;
  2587. }
  2588.  
  2589.  
  2590. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  2591. const f = h.onYtRendererstamperFinished;
  2592. const g = ump3.get(f) || function () {
  2593. if (this.updateChildVisibilityProperties && !this.markDirty) {
  2594. return f.apply(this, arguments);
  2595. }
  2596. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2597. }
  2598. ump3.set(f, g);
  2599. g.km34 = 1;
  2600. h.onYtRendererstamperFinished = g;
  2601.  
  2602. }
  2603.  
  2604. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  2605. const f = h.onYtUpdateDescriptionAction;
  2606. const g = ump3.get(f) || function (a) {
  2607. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2608. }
  2609. ump3.set(f, g);
  2610. g.km34 = 1;
  2611. h.onYtUpdateDescriptionAction = g;
  2612.  
  2613. }
  2614.  
  2615. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  2616. const f = h.handleUpdateDescriptionAction;
  2617. const g = ump3.get(f) || function (a) {
  2618. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2619. }
  2620. ump3.set(f, g);
  2621. g.km34 = 1;
  2622. h.handleUpdateDescriptionAction = g;
  2623.  
  2624. }
  2625.  
  2626. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  2627. const f = h.handleUpdateLiveChatPollAction;
  2628. const g = ump3.get(f) || function (a) {
  2629. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2630. }
  2631. ump3.set(f, g);
  2632. g.km34 = 1;
  2633. h.handleUpdateLiveChatPollAction = g;
  2634.  
  2635. }
  2636.  
  2637. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  2638. const f = h.onTextChanged;
  2639. const g = ump3.get(f) || function () {
  2640. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2641. }
  2642. ump3.set(f, g);
  2643. g.km34 = 1;
  2644. h.onTextChanged = g;
  2645.  
  2646. }
  2647.  
  2648. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  2649. const f = h.onVideoDataChange;
  2650. const g = ump3.get(f) || function (a) {
  2651. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2652. }
  2653. ump3.set(f, g);
  2654. g.km34 = 1;
  2655. h.onVideoDataChange = g;
  2656.  
  2657. }
  2658.  
  2659. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  2660. const f = h.onVideoDataChange_;
  2661. const g = ump3.get(f) || function () {
  2662. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2663. }
  2664. ump3.set(f, g);
  2665. g.km34 = 1;
  2666. h.onVideoDataChange_ = g;
  2667.  
  2668. }
  2669.  
  2670. /*
  2671. // affect chat message icon tooltips
  2672. if (typeof h.addTooltips === 'function' && !(h.addTooltips.km34)) {
  2673.  
  2674. const f = h.addTooltips;
  2675. const g = ump3.get(f) || function () {
  2676. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2677. }
  2678. ump3.set(f, g);
  2679. g.km34 = 1;
  2680. h.addTooltips = g;
  2681.  
  2682. }
  2683. */
  2684. /*
  2685. if (typeof h.onMouseOver_ === 'function' && !(h.onMouseOver_.km34) && typeof h.createTooltipIfRequired_ === 'function') {
  2686. console.log(212, h.is);
  2687. const f = h.onMouseOver_;
  2688. const g = ump3.get(f) || function () {
  2689. if (!this.__mEZ__) {
  2690. const w = document.createElement;
  2691. let EU = null;
  2692. document.createElement = function () {
  2693. let r = w.apply(this, arguments);
  2694. EU = r;
  2695. return r;
  2696. };
  2697. let done = false;
  2698. try {
  2699. this.polymerController.createTooltipIfRequired_();
  2700. done = true;
  2701. } catch (e) {
  2702. }
  2703. if (!done) {
  2704. try {
  2705. this.createTooltipIfRequired_();
  2706. done = true;
  2707. } catch (e) {
  2708. }
  2709. }
  2710. this.__mEZ__ = EU;
  2711. document.createElement = w;
  2712. }
  2713. if(this.__mEZ__){
  2714. this.__mEZ__.remove();
  2715. // this.__mEZ__.for = null;
  2716. [...this.__mEZ__.querySelectorAll('.hidden')].forEach(e=>e.classList.remove('hidden'))
  2717. }
  2718. console.log(212,this, this.is, this.__mEZ__)
  2719. return f.apply(this, arguments)
  2720. }
  2721. ump3.set(f, g);
  2722. g.km34 = 1;
  2723. h.onMouseOver_ = g;
  2724. }
  2725. */
  2726.  
  2727.  
  2728. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  2729.  
  2730. const f = h.addTooltips_;
  2731. const g = ump3.get(f) || function () {
  2732. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2733. }
  2734. ump3.set(f, g);
  2735. g.km34 = 1;
  2736. h.addTooltips_ = g;
  2737.  
  2738. }
  2739.  
  2740. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  2741.  
  2742. const f = h.updateRenderedElements;
  2743. const g = ump3.get(f) || function () {
  2744. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2745. }
  2746. ump3.set(f, g);
  2747. g.km34 = 1;
  2748. h.updateRenderedElements = g;
  2749.  
  2750. }
  2751.  
  2752. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  2753. const f = h.loadPage_;
  2754. const g = ump3.get(f) || function (a) {
  2755. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2756. }
  2757. ump3.set(f, g);
  2758. g.km34 = 1;
  2759. h.loadPage_ = g;
  2760.  
  2761. }
  2762. // updatePageData_ : possible conflict with Omit ShadyDOM
  2763. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  2764. const f = h.updatePageData_;
  2765. const g = ump3.get(f) || function (a) {
  2766. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2767. }
  2768. ump3.set(f, g);
  2769. g.km34 = 1;
  2770. h.updatePageData_ = g;
  2771.  
  2772. }
  2773.  
  2774.  
  2775. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  2776.  
  2777. const f = h.onFocus_;
  2778. const g = ump3.get(f) || function () {
  2779. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2780. }
  2781. ump3.set(f, g);
  2782. g.km34 = 1;
  2783. h.onFocus_ = g;
  2784.  
  2785. }
  2786.  
  2787. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  2788.  
  2789. const f = h.onBlur_;
  2790. const g = ump3.get(f) || function () {
  2791. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2792. }
  2793. ump3.set(f, g);
  2794. g.km34 = 1;
  2795. h.onBlur_ = g;
  2796.  
  2797. }
  2798.  
  2799.  
  2800. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  2801.  
  2802. const f = h.buttonClassChanged_;
  2803. const g = ump3.get(f) || function (a, b) {
  2804. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2805. }
  2806. ump3.set(f, g);
  2807. g.km34 = 1;
  2808. h.buttonClassChanged_ = g;
  2809.  
  2810. }
  2811.  
  2812. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  2813.  
  2814. const f = h.buttonIconChanged_;
  2815. const g = ump3.get(f) || function (a) {
  2816. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2817. }
  2818. ump3.set(f, g);
  2819. g.km34 = 1;
  2820. h.buttonIconChanged_ = g;
  2821.  
  2822. }
  2823.  
  2824. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  2825.  
  2826. const f = h.dataChangedInBehavior_;
  2827. const g = ump3.get(f) || function () {
  2828. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2829. }
  2830. ump3.set(f, g);
  2831. g.km34 = 1;
  2832. h.dataChangedInBehavior_ = g;
  2833.  
  2834. }
  2835.  
  2836. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  2837.  
  2838. const f = h.continuationsChanged_;
  2839. const g = ump3.get(f) || function () {
  2840. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2841. }
  2842. ump3.set(f, g);
  2843. g.km34 = 1;
  2844. h.continuationsChanged_ = g;
  2845.  
  2846. }
  2847.  
  2848.  
  2849. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  2850.  
  2851. const f = h.forceChatPoll_;
  2852. const g = ump3.get(f) || function (a) {
  2853. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2854. }
  2855. ump3.set(f, g);
  2856. g.km34 = 1;
  2857. h.forceChatPoll_ = g;
  2858.  
  2859. }
  2860.  
  2861. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  2862.  
  2863. const f = h.onEndpointClick_;
  2864. const g = ump3.get(f) || function (a) {
  2865. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2866. }
  2867. ump3.set(f, g);
  2868. g.km34 = 1;
  2869. h.onEndpointClick_ = g;
  2870.  
  2871. }
  2872.  
  2873. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  2874.  
  2875. const f = h.onEndpointTap_;
  2876. const g = ump3.get(f) || function (a) {
  2877. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2878. }
  2879. ump3.set(f, g);
  2880. g.km34 = 1;
  2881. h.onEndpointTap_ = g;
  2882.  
  2883. }
  2884.  
  2885. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  2886.  
  2887. const f = h.handleClick_;
  2888. const g = ump3.get(f) || function (a, b) {
  2889. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2890. }
  2891. ump3.set(f, g);
  2892. g.km34 = 1;
  2893. h.handleClick_ = g;
  2894.  
  2895. }
  2896.  
  2897. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  2898.  
  2899. const f = h.onReadyStateChange_;
  2900. const g = ump3.get(f) || function () {
  2901. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2902. }
  2903. ump3.set(f, g);
  2904. g.km34 = 1;
  2905. h.onReadyStateChange_ = g;
  2906.  
  2907. }
  2908.  
  2909. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  2910.  
  2911. const f = h.onReadyStateChangeEntryPoint_;
  2912. const g = ump3.get(f) || function () {
  2913. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2914. }
  2915. ump3.set(f, g);
  2916. g.km34 = 1;
  2917. h.onReadyStateChangeEntryPoint_ = g;
  2918.  
  2919. }
  2920.  
  2921. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  2922.  
  2923. const f = h.readyStateChangeHandler_;
  2924. const g = ump3.get(f) || function (a) {
  2925. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2926. }
  2927. ump3.set(f, g);
  2928. g.km34 = 1;
  2929. h.readyStateChangeHandler_ = g;
  2930.  
  2931. }
  2932.  
  2933. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  2934.  
  2935. const f = h.xmlHttpHandler_;
  2936. const g = ump3.get(f) || function (a) {
  2937. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2938. }
  2939. ump3.set(f, g);
  2940. g.km34 = 1;
  2941. h.xmlHttpHandler_ = g;
  2942.  
  2943. }
  2944.  
  2945. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  2946.  
  2947. const f = h.executeCallbacks_; // overloaded
  2948. const g = ump3.get(f) || function (a) {
  2949. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2950. }
  2951. ump3.set(f, g);
  2952. g.km34 = 1;
  2953. h.executeCallbacks_ = g;
  2954.  
  2955. }
  2956.  
  2957. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  2958.  
  2959. const f = h.handleInvalidationData_;
  2960. const g = ump3.get(f) || function (a, b) {
  2961. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2962. }
  2963. ump3.set(f, g);
  2964. g.km34 = 1;
  2965. h.handleInvalidationData_ = g;
  2966.  
  2967. }
  2968.  
  2969. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  2970.  
  2971. const f = h.onInput_;
  2972. const g = ump3.get(f) || function () {
  2973. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2974. }
  2975. ump3.set(f, g);
  2976. g.km34 = 1;
  2977. h.onInput_ = g;
  2978.  
  2979. }
  2980. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  2981.  
  2982. const f = h.trigger_;
  2983. const g = ump3.get(f) || function (a) {
  2984. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2985. }
  2986. ump3.set(f, g);
  2987. g.km34 = 1;
  2988. h.trigger_ = g;
  2989.  
  2990. }
  2991.  
  2992. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  2993.  
  2994. const f = h.requestData_;
  2995. const g = ump3.get(f) || function (a) {
  2996. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  2997. }
  2998. ump3.set(f, g);
  2999. g.km34 = 1;
  3000. h.requestData_ = g;
  3001.  
  3002. }
  3003.  
  3004. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  3005.  
  3006. const f = h.onLoadReloadContinuation_;
  3007. const g = ump3.get(f) || function (a, b) {
  3008. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3009. }
  3010. ump3.set(f, g);
  3011. g.km34 = 1;
  3012. h.onLoadReloadContinuation_ = g;
  3013.  
  3014. }
  3015.  
  3016. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  3017.  
  3018. const f = h.onLoadIncrementalContinuation_;
  3019. const g = ump3.get(f) || function (a, b) {
  3020. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3021. }
  3022. ump3.set(f, g);
  3023. g.km34 = 1;
  3024. h.onLoadIncrementalContinuation_ = g;
  3025.  
  3026. }
  3027.  
  3028. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  3029.  
  3030. const f = h.onLoadSeekContinuation_;
  3031. const g = ump3.get(f) || function (a, b) {
  3032. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3033. }
  3034. ump3.set(f, g);
  3035. g.km34 = 1;
  3036. h.onLoadSeekContinuation_ = g;
  3037.  
  3038. }
  3039. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  3040.  
  3041. const f = h.onLoadReplayContinuation_;
  3042. const g = ump3.get(f) || function (a, b) {
  3043. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3044. }
  3045. ump3.set(f, g);
  3046. g.km34 = 1;
  3047. h.onLoadReplayContinuation_ = g;
  3048.  
  3049. }
  3050. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  3051.  
  3052. const f = h.onNavigate_;
  3053. const g = ump3.get(f) || function (a) {
  3054. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3055. }
  3056. ump3.set(f, g);
  3057. g.km34 = 1;
  3058. h.onNavigate_ = g;
  3059.  
  3060. }
  3061.  
  3062. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  3063.  
  3064. const f = h.ytRendererBehaviorDataObserver_;
  3065. const g = ump3.get(f) || function () {
  3066. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3067. }
  3068. ump3.set(f, g);
  3069. g.km34 = 1;
  3070. h.ytRendererBehaviorDataObserver_ = g;
  3071.  
  3072. }
  3073.  
  3074. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  3075.  
  3076. const f = h.ytRendererBehaviorTargetIdObserver_;
  3077. const g = ump3.get(f) || function () {
  3078. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3079. }
  3080. ump3.set(f, g);
  3081. g.km34 = 1;
  3082. h.ytRendererBehaviorTargetIdObserver_ = g;
  3083.  
  3084. }
  3085.  
  3086. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  3087.  
  3088. const f = h.unregisterRenderer_;
  3089. const g = ump3.get(f) || function (a) {
  3090. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3091. }
  3092. ump3.set(f, g);
  3093. g.km34 = 1;
  3094. h.unregisterRenderer_ = g;
  3095.  
  3096. }
  3097.  
  3098. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  3099.  
  3100. const f = h.textChanged_;
  3101. const g = ump3.get(f) || function (a) {
  3102. if (void 0 !== this.isAttached) {
  3103. const hostElement = this.hostElement;
  3104. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  3105. return;
  3106. }
  3107. }
  3108. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3109. }
  3110. ump3.set(f, g);
  3111. g.km34 = 1;
  3112. h.textChanged_ = g;
  3113.  
  3114. }
  3115.  
  3116.  
  3117.  
  3118. /**
  3119. *
  3120. * Neglect following
  3121. *
  3122. * h.onYtAction_
  3123. * h.startLoadingWatch [ buggy for yt-player-updated ]
  3124. * h.deferRenderStamperBinding_
  3125. *
  3126. * h.stampDomArray_
  3127. * h.stampDomArraySplices_
  3128. *
  3129. */
  3130.  
  3131.  
  3132. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  3133. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  3134. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  3135. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  3136. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  3137. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  3138.  
  3139. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  3140.  
  3141. const f = h.searchChanged_;
  3142. const g = ump3.get(f) || function () {
  3143. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3144. }
  3145. ump3.set(f, g);
  3146. g.km34 = 1;
  3147. h.searchChanged_ = g;
  3148.  
  3149. }
  3150.  
  3151. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  3152.  
  3153. const f = h.skinToneChanged_;
  3154. const g = ump3.get(f) || function (a) {
  3155. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3156. }
  3157. ump3.set(f, g);
  3158. g.km34 = 1;
  3159. h.skinToneChanged_ = g;
  3160.  
  3161. }
  3162.  
  3163. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  3164.  
  3165. const f = h.onEmojiHover_;
  3166. const g = ump3.get(f) || function (a) {
  3167. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3168. }
  3169. ump3.set(f, g);
  3170. g.km34 = 1;
  3171. h.onEmojiHover_ = g;
  3172.  
  3173. }
  3174.  
  3175. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  3176.  
  3177. const f = h.onSelectCategory_;
  3178. const g = ump3.get(f) || function (a) {
  3179. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3180. }
  3181. ump3.set(f, g);
  3182. g.km34 = 1;
  3183. h.onSelectCategory_ = g;
  3184.  
  3185. }
  3186.  
  3187. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  3188.  
  3189. const f = h.onShowEmojiVariantSelector;
  3190. const g = ump3.get(f) || function (a) {
  3191. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3192. }
  3193. ump3.set(f, g);
  3194. g.km34 = 1;
  3195. h.onShowEmojiVariantSelector = g;
  3196.  
  3197. }
  3198.  
  3199. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  3200.  
  3201. const f = h.updateCategoriesAndPlaceholder_;
  3202. const g = ump3.get(f) || function () {
  3203. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3204. }
  3205. ump3.set(f, g);
  3206. g.km34 = 1;
  3207. h.updateCategoriesAndPlaceholder_ = g;
  3208.  
  3209. }
  3210.  
  3211. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  3212.  
  3213. const f = h.watchPageActiveChanged_;
  3214. const g = ump3.get(f) || function () {
  3215. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3216. }
  3217. ump3.set(f, g);
  3218. g.km34 = 1;
  3219. h.watchPageActiveChanged_ = g;
  3220.  
  3221. }
  3222.  
  3223. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  3224.  
  3225. const f = h.activate_;
  3226. const g = ump3.get(f) || function () {
  3227. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3228. }
  3229. ump3.set(f, g);
  3230. g.km34 = 1;
  3231. h.activate_ = g;
  3232.  
  3233. }
  3234. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  3235.  
  3236. const f = h.onYtPlaylistDataUpdated_;
  3237. const g = ump3.get(f) || function () {
  3238. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3239. }
  3240. ump3.set(f, g);
  3241. g.km34 = 1;
  3242. h.onYtPlaylistDataUpdated_ = g;
  3243.  
  3244. }
  3245.  
  3246. FIX_stampDomArray_stableList && fixStampDomArrayStableList(h);
  3247. const ENABLE_weakenStampReferencesQ = ENABLE_weakenStampReferences && typeof DocumentTimeline !== 'undefined' && typeof WeakRef !== 'undefined';
  3248. ENABLE_weakenStampReferencesQ && weakenStampReferences(h);
  3249.  
  3250.  
  3251. /**
  3252. *
  3253. * Neglect following
  3254. *
  3255. * h.rendererStamperObserver_
  3256. * h.rendererStamperApplyChangeRecord_
  3257. * h.flushRenderStamperComponentBindings_
  3258. * h.forwardRendererStamperChanges_
  3259. *
  3260. */
  3261.  
  3262. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  3263.  
  3264. const f = h.tryRenderChunk_;
  3265. const g = ump3.get(f) || function () {
  3266. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3267. }
  3268. ump3.set(f, g);
  3269. g.km34 = 1;
  3270. h.tryRenderChunk_ = g;
  3271.  
  3272. }
  3273.  
  3274.  
  3275. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  3276.  
  3277. const f = h.renderChunk_;
  3278. const g = ump3.get(f) || function () {
  3279. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3280. }
  3281. ump3.set(f, g);
  3282. g.km34 = 1;
  3283. h.renderChunk_ = g;
  3284.  
  3285. }
  3286.  
  3287. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  3288.  
  3289. const f = h.deepLazyListObserver_;
  3290. const g = ump3.get(f) || function () {
  3291. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3292. }
  3293. ump3.set(f, g);
  3294. g.km34 = 1;
  3295. h.deepLazyListObserver_ = g;
  3296.  
  3297. }
  3298.  
  3299. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  3300.  
  3301. const f = h.onItemsUpdated_;
  3302. const g = ump3.get(f) || function () {
  3303. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3304. }
  3305. ump3.set(f, g);
  3306. g.km34 = 1;
  3307. h.onItemsUpdated_ = g;
  3308.  
  3309. }
  3310.  
  3311. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  3312.  
  3313. const f = h.requestRenderChunk_;
  3314. const g = ump3.get(f) || function () {
  3315. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  3316. }
  3317. ump3.set(f, g);
  3318. g.km34 = 1;
  3319. h.requestRenderChunk_ = g;
  3320.  
  3321. }
  3322.  
  3323. /**
  3324. *
  3325. * Neglect following
  3326. *
  3327. * h.dataChanged_ [ buggy for page swtiching ]
  3328. *
  3329. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  3330. *
  3331. * h.cancelPendingTasks_
  3332. * h.fillRange_
  3333. * h.addTextNodes_
  3334. * h.updateText_
  3335. * h.stampTypeChanged_
  3336. *
  3337. */
  3338.  
  3339.  
  3340. }
  3341.  
  3342. const keyStConnectedCallback = Symbol(); // avoid copying the value
  3343.  
  3344. // const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  3345. const cmf = new WeakMap();
  3346. const dmf = new WeakMap();
  3347.  
  3348. const gvGenerator = (nv) => {
  3349. return function () {
  3350. const cnt = insp(this);
  3351. const hostElement = cnt.hostElement || 0;
  3352. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  3353. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  3354. if (p && (!dollar && !this.is)) {
  3355. const nodeName = hostElement.nodeName;
  3356. if (typeof nodeName !== 'string') {
  3357. // just in case
  3358. } else if (nodeName.startsWith("DOM-")) {
  3359. // dom-if, dom-repeat, etc
  3360. } else {
  3361. // yt element - new model, yt-xxxx, anixxxxxx
  3362. p = false;
  3363. }
  3364. }
  3365. if (p) {
  3366. if (typeof cnt.markDirty === 'function') {
  3367. // the yt element might call markDirty (occasionally)
  3368. p = false;
  3369. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  3370. // see https://github.com/cyfung1031/userscript-supports/issues/20
  3371. p = false;
  3372. }
  3373. }
  3374. if (p) {
  3375.  
  3376. // << dom-repeat & dom-if >>
  3377.  
  3378. // sequence on the same instance
  3379. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  3380. } else {
  3381. nv.apply(this, arguments);
  3382. }
  3383. };
  3384. }
  3385.  
  3386. // const assignedHolderWS = new WeakSet();
  3387.  
  3388. const setupWeakRef = (h) => {
  3389.  
  3390.  
  3391. }
  3392.  
  3393.  
  3394. let nativeHTMLElement = window.HTMLElement;
  3395.  
  3396. try {
  3397.  
  3398. const q = document.createElement('template');
  3399. q.innerHTML = '<ytz-null361></ytz-null361>';
  3400. nativeHTMLElement = q.content.firstChild.constructor
  3401.  
  3402. } catch (e) { }
  3403.  
  3404. if (!nativeHTMLElement.prototype.connectedCallback) {
  3405. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  3406. nativeHTMLElement.prototype.connectedCallback = function () {
  3407. let r;
  3408. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  3409. return r;
  3410. }
  3411. }
  3412.  
  3413. ENABLE_discreteTasking && Object.defineProperty(Object.prototype, 'connectedCallback', {
  3414. get() {
  3415. const f = this[keyStConnectedCallback];
  3416. if (this.is) {
  3417. setupDiscreteTasks(this, true);
  3418. if (f) this.ky36 = 1;
  3419. }
  3420. return f;
  3421. },
  3422. set(nv) {
  3423. let gv;
  3424. if (typeof nv === 'function') {
  3425.  
  3426. gv = cmf.get(nv) || gvGenerator(nv);
  3427. if (gv !== nv) {
  3428. cmf.set(nv, gv);
  3429. cmf.set(gv, gv);
  3430. dmf.set(gv, nv);
  3431. }
  3432.  
  3433. } else {
  3434. gv = nv;
  3435. }
  3436. this[keyStConnectedCallback] = gv; // proto or object
  3437. if (this.is) {
  3438. setupDiscreteTasks(this);
  3439. }
  3440. return true;
  3441. },
  3442. enumerable: false,
  3443. configurable: true
  3444.  
  3445. });
  3446.  
  3447. const pLoad = new Promise(resolve => {
  3448. if (document.readyState !== 'loading') {
  3449. resolve();
  3450. } else {
  3451. window.addEventListener("DOMContentLoaded", resolve, false);
  3452. }
  3453. });
  3454.  
  3455. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  3456. window.requestIdleCallback471 = window.requestIdleCallback;
  3457. window.requestIdleCallback = function (f, ...args) {
  3458. return (this || window).requestIdleCallback471(async function () {
  3459. await pLoad.then();
  3460. f.call(this, ...arguments)
  3461. }, ...args);
  3462. }
  3463. }
  3464.  
  3465. pLoad.then(() => {
  3466.  
  3467. let nonce = document.querySelector('style[nonce]');
  3468. nonce = nonce ? nonce.getAttribute('nonce') : null;
  3469. const st = document.createElement('style');
  3470. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  3471. st.textContent = "none-element-k47{order:0}";
  3472. st.addEventListener('load', () => {
  3473. pf31.resolve();
  3474. p59 = 1;
  3475. }, false);
  3476. (document.body || document.head || document.documentElement).appendChild(st);
  3477.  
  3478. });
  3479.  
  3480. const prepareLogs = [];
  3481.  
  3482. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  3483.  
  3484. let winError00 = window.onerror;
  3485.  
  3486. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  3487.  
  3488. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  3489.  
  3490. ; FIX_Iframe_NULL_SRC && typeof kagi === 'undefined' && (() => {
  3491.  
  3492. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  3493. const lcOpt = { sensitivity: 'base' };
  3494. document.createElement24 = document.createElement;
  3495. document.createElement = function (t) {
  3496. if (typeof t === 'string' && t.length === 6) {
  3497. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  3498. const p = this.createElement24(t);
  3499. try {
  3500. const stack = new Error().stack;
  3501. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  3502. if (!isSearchbox) {
  3503. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  3504. }
  3505. } catch (e) { }
  3506. return p;
  3507. }
  3508. }
  3509. return this.createElement24.apply(this, arguments);
  3510. };
  3511.  
  3512. })();
  3513.  
  3514. ; fix_error_many_stack_state === 1 && (() => {
  3515.  
  3516.  
  3517. let p1 = winError00;
  3518.  
  3519. let stackNeedleDetails = null;
  3520.  
  3521. Object.defineProperty(Object.prototype, 'matchAll', {
  3522. get() {
  3523. stackNeedleDetails = this;
  3524. return true;
  3525. },
  3526. enumerable: true,
  3527. configurable: true
  3528. });
  3529.  
  3530. try {
  3531. JSON.parse("{}");
  3532. } catch (e) {
  3533. console.warn(e)
  3534. fix_error_many_stack_state = 0;
  3535. }
  3536.  
  3537. delete Object.prototype['matchAll'];
  3538.  
  3539. let p2 = window.onerror;
  3540.  
  3541. window.onerror = p1;
  3542.  
  3543. if (fix_error_many_stack_state === 0) return;
  3544.  
  3545. if (stackNeedleDetails) {
  3546. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  3547. stackNeedleDetails.matchAll = true;
  3548. }
  3549.  
  3550. if (p1 === p2) return (fix_error_many_stack_state = 0);
  3551.  
  3552. // p1!==p2
  3553. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  3554.  
  3555. })();
  3556.  
  3557. ; fix_error_many_stack_state === 2 && (() => {
  3558.  
  3559.  
  3560. let p1 = winError00;
  3561.  
  3562. let objectPrune = null;
  3563. let stackNeedleDetails = null;
  3564.  
  3565. Object.defineProperty(Function.prototype, 'findOwner', {
  3566. get() {
  3567. objectPrune = this;
  3568. return this._findOwner;
  3569. },
  3570. set(nv) {
  3571. this._findOwner = nv;
  3572. return true;
  3573. },
  3574. enumerable: true,
  3575. configurable: true
  3576. });
  3577.  
  3578. Object.defineProperty(Object.prototype, 'matchAll', {
  3579. get() {
  3580. stackNeedleDetails = this;
  3581. return true;
  3582. },
  3583. enumerable: true,
  3584. configurable: true
  3585. });
  3586.  
  3587. try {
  3588. JSON.parse("{}");
  3589. } catch (e) {
  3590. console.warn(e)
  3591. fix_error_many_stack_state = 0;
  3592. }
  3593.  
  3594. delete Function.prototype['findOwner'];
  3595. delete Object.prototype['matchAll'];
  3596.  
  3597. let p2 = window.onerror;
  3598.  
  3599. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  3600.  
  3601. if (fix_error_many_stack_state == 0) return;
  3602.  
  3603. // the following will only execute when Brave's scriptlets.js is executed.
  3604.  
  3605. prepareLogs.push("fix_error_many_stack_state NB")
  3606.  
  3607. if (stackNeedleDetails) {
  3608. stackNeedleDetails.pattern = null;
  3609. stackNeedleDetails.re = null;
  3610. stackNeedleDetails.expect = null;
  3611. stackNeedleDetails.matchAll = true;
  3612. }
  3613.  
  3614. if (objectPrune) {
  3615. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  3616. delete objectPrune._findOwner;
  3617. }
  3618.  
  3619. fix_error_many_stack_state = 3;
  3620. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  3621. JSON.parse.objectPrune = objectPrune;
  3622.  
  3623. })();
  3624.  
  3625. ; fix_error_many_stack_state === 3 && (() => {
  3626.  
  3627.  
  3628. let p1 = winError00;
  3629.  
  3630. try {
  3631. JSON.parse("{}");
  3632. } catch (e) {
  3633. console.warn(e)
  3634. fix_error_many_stack_state = 0;
  3635. }
  3636.  
  3637. let p2 = window.onerror;
  3638.  
  3639. if (p1 === p2) return;
  3640.  
  3641. window.onerror = p1;
  3642.  
  3643. if (fix_error_many_stack_state === 0) return;
  3644.  
  3645. fix_error_many_stack_state = 4; // p1 != p2
  3646.  
  3647.  
  3648. })();
  3649.  
  3650. fix_error_many_stack_state === 4 && (() => {
  3651.  
  3652. // the following will only execute when Brave's scriptlets.js is executed.
  3653.  
  3654. prepareLogs.push("fix_error_many_stack_state AB")
  3655.  
  3656. JSON.parseProxy = JSON.parse;
  3657.  
  3658. JSON.parse = ((parse) => {
  3659.  
  3660. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  3661. return function (text, reviver) {
  3662. const onerror = window.onerror;
  3663. window.onerror = null;
  3664. let r;
  3665. try {
  3666. r = parse(...arguments);
  3667. } catch (e) {
  3668. r = e;
  3669. }
  3670. window.onerror = onerror;
  3671. if (r instanceof Error) {
  3672. throw r;
  3673. }
  3674. return r;
  3675. }
  3676.  
  3677. })(JSON.parse);
  3678.  
  3679.  
  3680. })();
  3681.  
  3682.  
  3683. // << if FIX_yt_player >>
  3684.  
  3685. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  3686. const PERF_471489_ = true;
  3687. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  3688. // This script uses a much gentle way to tamer the JS engine instead.
  3689.  
  3690. // << end >>
  3691.  
  3692. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  3693.  
  3694.  
  3695.  
  3696. const nilFn = () => { };
  3697.  
  3698. let isMainWindow = false;
  3699. try {
  3700. isMainWindow = window.document === window.top.document
  3701. } catch (e) { }
  3702.  
  3703. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  3704. let headLinkCollection = null;
  3705.  
  3706.  
  3707. // const assertor = (f) => f() || console.assert(false, f + "");
  3708.  
  3709. const fnIntegrity = (f, d) => {
  3710. if (!f || typeof f !== 'function') {
  3711. console.warn('f is not a function', f);
  3712. return;
  3713. }
  3714. let p = f + "", s = 0, j = -1, w = 0;
  3715. for (let i = 0, l = p.length; i < l; i++) {
  3716. const t = p[i];
  3717. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  3718. if (j < i - 1) w++;
  3719. j = i;
  3720. } else {
  3721. s++;
  3722. }
  3723. }
  3724. let itz = `${f.length}.${s}.${w}`;
  3725. if (!d) {
  3726. return itz;
  3727. } else {
  3728. return itz === d;
  3729. }
  3730. };
  3731.  
  3732. const getZqOu = (_yt_player) => {
  3733.  
  3734. const w = 'ZqOu';
  3735.  
  3736. let arr = [];
  3737.  
  3738. for (const [k, v] of Object.entries(_yt_player)) {
  3739.  
  3740. const p = typeof v === 'function' ? v.prototype : 0;
  3741. if (p
  3742. && typeof p.start === 'function' && p.start.length === 0 // Ou
  3743. && typeof p.isActive === 'function' && p.isActive.length === 0
  3744. && typeof p.stop === 'function' && p.stop.length === 0
  3745. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  3746. && !p.send && !p.abort
  3747. && !p.sample && !p.initialize && !p.fail && !p.getName
  3748. // && !p.dispose && !p.isDisposed
  3749.  
  3750. ) {
  3751. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3752.  
  3753.  
  3754. }
  3755.  
  3756. }
  3757.  
  3758. if (arr.length === 0) {
  3759.  
  3760. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  3761. } else {
  3762.  
  3763. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  3764. return arr[0];
  3765. }
  3766.  
  3767. }
  3768.  
  3769. const getZqQu = (_yt_player) => {
  3770.  
  3771. const w = 'ZqQu';
  3772.  
  3773. let arr = [];
  3774.  
  3775.  
  3776. for (const [k, v] of Object.entries(_yt_player)) {
  3777.  
  3778. const p = typeof v === 'function' ? v.prototype : 0;
  3779. if (p
  3780. && typeof p.start === 'function' && p.start.length === 1 // Qu
  3781. && typeof p.isActive === 'function' && p.isActive.length === 0
  3782. && typeof p.stop === 'function' && p.stop.length === 0
  3783. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  3784. && !p.send && !p.abort
  3785. && !p.sample && !p.initialize && !p.fail && !p.getName
  3786. // && !p.dispose && !p.isDisposed
  3787.  
  3788. ) {
  3789. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3790.  
  3791.  
  3792. }
  3793.  
  3794. }
  3795.  
  3796. if (arr.length === 0) {
  3797.  
  3798. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  3799. } else {
  3800.  
  3801. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  3802. return arr[0];
  3803. }
  3804.  
  3805. }
  3806.  
  3807.  
  3808. const getVG = (_yt_player) => {
  3809. const w = 'VG';
  3810.  
  3811. let arr = [];
  3812.  
  3813. for (const [k, v] of Object.entries(_yt_player)) {
  3814.  
  3815. const p = typeof v === 'function' ? v.prototype : 0;
  3816. if (p
  3817. && typeof p.show === 'function' && p.show.length === 1
  3818. && typeof p.hide === 'function' && p.hide.length === 0
  3819. && typeof p.stop === 'function' && p.stop.length === 0) {
  3820.  
  3821. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3822.  
  3823. }
  3824.  
  3825. }
  3826.  
  3827.  
  3828. if (arr.length === 0) {
  3829.  
  3830. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  3831. } else {
  3832.  
  3833. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  3834. return arr[0];
  3835. }
  3836.  
  3837.  
  3838.  
  3839. }
  3840.  
  3841.  
  3842. const getzo = (_yt_player) => {
  3843. const w = 'zo';
  3844.  
  3845. let arr = [];
  3846.  
  3847. for (const [k, v] of Object.entries(_yt_player)) {
  3848.  
  3849. if (
  3850. typeof v === 'function' && v.length === 3 && k.length < 3
  3851. ) {
  3852. const vt = (v + "");
  3853. if (vt.length >= 21 && vt.includes(".style[")) {
  3854. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  3855. arr.push(k);
  3856. } else {
  3857. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  3858. }
  3859. }
  3860. }
  3861.  
  3862. }
  3863.  
  3864. if (arr.length === 0) {
  3865.  
  3866. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  3867. } else {
  3868.  
  3869. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  3870. return arr[0];
  3871. }
  3872.  
  3873. }
  3874.  
  3875. const addProtoToArr = (parent, key, arr) => {
  3876.  
  3877.  
  3878. let isChildProto = false;
  3879. for (const sr of arr) {
  3880. if (parent[key].prototype instanceof parent[sr]) {
  3881. isChildProto = true;
  3882. break;
  3883. }
  3884. }
  3885.  
  3886. if (isChildProto) return;
  3887.  
  3888. arr = arr.filter(sr => {
  3889. if (parent[sr].prototype instanceof parent[key]) {
  3890. return false;
  3891. }
  3892. return true;
  3893. });
  3894.  
  3895. arr.push(key);
  3896.  
  3897. return arr;
  3898.  
  3899.  
  3900. }
  3901.  
  3902. const getuG = (_yt_player) => {
  3903.  
  3904. const w = 'uG';
  3905.  
  3906. let arr = [];
  3907.  
  3908. for (const [k, v] of Object.entries(_yt_player)) {
  3909.  
  3910.  
  3911. const p = typeof v === 'function' ? v.prototype : 0;
  3912.  
  3913. if (p
  3914. && typeof p.createElement === 'function' && p.createElement.length === 2
  3915. && typeof p.detach === 'function' && p.detach.length === 0
  3916. && typeof p.update === 'function' && p.update.length === 1
  3917. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  3918. ) {
  3919.  
  3920. arr = addProtoToArr(_yt_player, k, arr) || arr;
  3921.  
  3922. }
  3923.  
  3924. }
  3925.  
  3926.  
  3927.  
  3928.  
  3929.  
  3930. if (arr.length === 0) {
  3931.  
  3932. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  3933. } else {
  3934.  
  3935. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  3936. return arr[0];
  3937. }
  3938.  
  3939. }
  3940.  
  3941.  
  3942. const getQT = (_yt_player) => {
  3943. const w = 'QT';
  3944.  
  3945. let arr = [];
  3946. let brr = new Map();
  3947.  
  3948. for (const [k, v] of Object.entries(_yt_player)) {
  3949.  
  3950. const p = typeof v === 'function' ? v.prototype : 0;
  3951. if (p) {
  3952. let q = 0;
  3953. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  3954. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  3955. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  3956.  
  3957. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  3958.  
  3959. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  3960.  
  3961. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  3962. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  3963. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  3964. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  3965.  
  3966.  
  3967. // differentiate QT and DX
  3968.  
  3969. q += 280;
  3970. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  3971. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  3972. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  3973. if (typeof p.seekBy === 'function') q += 4;
  3974. if (typeof p.seekTo === 'function') q += 4;
  3975. if (typeof p.getStoryboardFormat === 'function') q += 4;
  3976. if (typeof p.getDuration === 'function') q += 4;
  3977. if (typeof p.loadModule === 'function') q += 4;
  3978. if (typeof p.unloadModule === 'function') q += 4;
  3979. if (typeof p.getOption === 'function') q += 4;
  3980. if (typeof p.getOptions === 'function') q += 4;
  3981. if (typeof p.setOption === 'function') q += 4;
  3982. if (typeof p.addCueRange === 'function') q += 4;
  3983. if (typeof p.getDebugText === 'function') q += 4;
  3984. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  3985. if (typeof p.setSizeStyle === 'function') q += 4;
  3986. if (typeof p.showControls === 'function') q += 4;
  3987. if (typeof p.hideControls === 'function') q += 4;
  3988. if (typeof p.getVideoContentRect === 'function') q += 4;
  3989. if (typeof p.toggleFullscreen === 'function') q += 4;
  3990. if (typeof p.isFullscreen === 'function') q += 4;
  3991. if (typeof p.cancelPlayback === 'function') q += 4;
  3992. if (typeof p.getProgressState === 'function') q += 4;
  3993. if (typeof p.isInline === 'function') q += 4;
  3994. if (typeof p.setInline === 'function') q += 4;
  3995. if (typeof p.toggleSubtitles === 'function') q += 4;
  3996. if (typeof p.getPlayerSize === 'function') q += 4;
  3997. if (typeof p.wakeUpControls === 'function') q += 4;
  3998. if (typeof p.setCenterCrop === 'function') q += 4;
  3999. if (typeof p.getLoopVideo === 'function') q += 4;
  4000. if (typeof p.setLoopVideo === 'function') q += 4;
  4001.  
  4002.  
  4003. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  4004.  
  4005. if (q > 0) brr.set(k, q);
  4006.  
  4007. }
  4008.  
  4009. }
  4010.  
  4011. if (arr.length === 0) {
  4012.  
  4013. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  4014. } else {
  4015.  
  4016. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  4017.  
  4018. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  4019.  
  4020. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  4021. return arr[0][0];
  4022. }
  4023.  
  4024.  
  4025.  
  4026. }
  4027.  
  4028.  
  4029.  
  4030. const getSV = (_yt_player) => {
  4031. const w = 'SV';
  4032.  
  4033. let arr = [];
  4034. let brr = new Map();
  4035.  
  4036. for (const [k, v] of Object.entries(_yt_player)) {
  4037.  
  4038. const p = typeof v === 'function' ? v.prototype : 0;
  4039. if (p) {
  4040. let q = 0;
  4041. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  4042. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  4043. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  4044.  
  4045. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  4046.  
  4047. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  4048.  
  4049. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  4050. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  4051. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  4052. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  4053.  
  4054.  
  4055. // differentiate QT and DX
  4056.  
  4057.  
  4058. q += 280;
  4059.  
  4060. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  4061. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  4062. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  4063. if (typeof p.seekBy === 'function') q -= 4;
  4064. if (typeof p.seekTo === 'function') q -= 4;
  4065. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  4066. if (typeof p.getDuration === 'function') q -= 4;
  4067. if (typeof p.loadModule === 'function') q -= 4;
  4068. if (typeof p.unloadModule === 'function') q -= 4;
  4069. if (typeof p.getOption === 'function') q -= 4;
  4070. if (typeof p.getOptions === 'function') q -= 4;
  4071. if (typeof p.setOption === 'function') q -= 4;
  4072. if (typeof p.addCueRange === 'function') q -= 4;
  4073. if (typeof p.getDebugText === 'function') q -= 4;
  4074. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  4075. if (typeof p.setSizeStyle === 'function') q -= 4;
  4076. if (typeof p.showControls === 'function') q -= 4;
  4077. if (typeof p.hideControls === 'function') q -= 4;
  4078. if (typeof p.getVideoContentRect === 'function') q -= 4;
  4079. if (typeof p.toggleFullscreen === 'function') q -= 4;
  4080. if (typeof p.isFullscreen === 'function') q -= 4;
  4081. if (typeof p.cancelPlayback === 'function') q -= 4;
  4082. if (typeof p.getProgressState === 'function') q -= 4;
  4083. if (typeof p.isInline === 'function') q -= 4;
  4084. if (typeof p.setInline === 'function') q -= 4;
  4085. if (typeof p.toggleSubtitles === 'function') q -= 4;
  4086. if (typeof p.getPlayerSize === 'function') q -= 4;
  4087. if (typeof p.wakeUpControls === 'function') q -= 4;
  4088. if (typeof p.setCenterCrop === 'function') q -= 4;
  4089. if (typeof p.getLoopVideo === 'function') q -= 4;
  4090. if (typeof p.setLoopVideo === 'function') q -= 4;
  4091.  
  4092.  
  4093. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  4094.  
  4095. if (q > 0) brr.set(k, q);
  4096.  
  4097. }
  4098.  
  4099. }
  4100.  
  4101. if (arr.length === 0) {
  4102.  
  4103. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  4104. } else {
  4105.  
  4106. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  4107.  
  4108. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  4109.  
  4110. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  4111. return arr[0][0];
  4112. }
  4113.  
  4114.  
  4115.  
  4116. }
  4117.  
  4118.  
  4119.  
  4120.  
  4121. const getDX = (_yt_player) => {
  4122. const w = 'DX';
  4123.  
  4124. let arr = [];
  4125. let brr = new Map();
  4126.  
  4127. for (const [k, v] of Object.entries(_yt_player)) {
  4128.  
  4129. const p = typeof v === 'function' ? v.prototype : 0;
  4130. if (p) {
  4131. let q = 0;
  4132. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  4133. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  4134. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  4135.  
  4136. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  4137.  
  4138.  
  4139. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  4140.  
  4141. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  4142.  
  4143. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  4144. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  4145. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  4146. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  4147.  
  4148.  
  4149. // differentiate QT and DX
  4150.  
  4151.  
  4152. q += 280;
  4153.  
  4154. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  4155. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  4156. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  4157. if (typeof p.seekBy === 'function') q -= 4;
  4158. if (typeof p.seekTo === 'function') q -= 4;
  4159. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  4160. if (typeof p.getDuration === 'function') q -= 4;
  4161. if (typeof p.loadModule === 'function') q -= 4;
  4162. if (typeof p.unloadModule === 'function') q -= 4;
  4163. if (typeof p.getOption === 'function') q -= 4;
  4164. if (typeof p.getOptions === 'function') q -= 4;
  4165. if (typeof p.setOption === 'function') q -= 4;
  4166. if (typeof p.addCueRange === 'function') q -= 4;
  4167. if (typeof p.getDebugText === 'function') q -= 4;
  4168. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  4169. if (typeof p.setSizeStyle === 'function') q -= 4;
  4170. if (typeof p.showControls === 'function') q -= 4;
  4171. if (typeof p.hideControls === 'function') q -= 4;
  4172. if (typeof p.getVideoContentRect === 'function') q -= 4;
  4173. if (typeof p.toggleFullscreen === 'function') q -= 4;
  4174. if (typeof p.isFullscreen === 'function') q -= 4;
  4175. if (typeof p.cancelPlayback === 'function') q -= 4;
  4176. if (typeof p.getProgressState === 'function') q -= 4;
  4177. if (typeof p.isInline === 'function') q -= 4;
  4178. if (typeof p.setInline === 'function') q -= 4;
  4179. if (typeof p.toggleSubtitles === 'function') q -= 4;
  4180. if (typeof p.getPlayerSize === 'function') q -= 4;
  4181. if (typeof p.wakeUpControls === 'function') q -= 4;
  4182. if (typeof p.setCenterCrop === 'function') q -= 4;
  4183. if (typeof p.getLoopVideo === 'function') q -= 4;
  4184. if (typeof p.setLoopVideo === 'function') q -= 4;
  4185.  
  4186.  
  4187. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  4188.  
  4189. if (q > 0) brr.set(k, q);
  4190.  
  4191. }
  4192.  
  4193. }
  4194.  
  4195. if (arr.length === 0) {
  4196.  
  4197. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  4198. } else {
  4199.  
  4200. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  4201.  
  4202. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  4203.  
  4204. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  4205. return arr[0][0];
  4206. }
  4207.  
  4208.  
  4209.  
  4210. }
  4211.  
  4212.  
  4213.  
  4214. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  4215.  
  4216. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  4217. let pageSetupState = 0;
  4218.  
  4219. isPrepareCachedV && (() => {
  4220.  
  4221. pageSetupVideoId = '';
  4222. const clearCachedV = () => {
  4223. pageSetupVideoId = '';
  4224. pageSetupState = 0;
  4225. }
  4226. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  4227. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  4228. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  4229. document.addEventListener('yt-navigate-finish', () => {
  4230. pageSetupState = 1;
  4231. try {
  4232. const url = new URL(location.href);
  4233. if (!url || !isWatchPageURL(url)) {
  4234. pageSetupVideoId = '';
  4235. } else {
  4236. pageSetupVideoId = url.searchParams.get('v') || '';
  4237. }
  4238. } catch (e) {
  4239. pageSetupVideoId = '';
  4240. }
  4241. }, false);
  4242.  
  4243. })();
  4244.  
  4245. let videoPlayingY = null;
  4246.  
  4247. isPrepareCachedV && (() => {
  4248.  
  4249. let getNext = true;
  4250. let videoPlayingX = {
  4251. get videoId() {
  4252. if (getNext) {
  4253. getNext = false;
  4254.  
  4255. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  4256. const arr = [];
  4257. for (const element of elements) {
  4258. if (!element.closest('[hidden]')) arr.push(element);
  4259. }
  4260. if (arr.length !== 1) this.__videoId__ = '';
  4261. else {
  4262. this.__videoId__ = arr[0].getAttribute('video-id');
  4263. }
  4264.  
  4265. }
  4266. return this.__videoId__ || '';
  4267. }
  4268. }
  4269.  
  4270. videoPlayingY = videoPlayingX;
  4271. const handler = (evt) => {
  4272. const target = (evt || 0).target;
  4273. if (target instanceof HTMLVideoElement) {
  4274. getNext = true;
  4275. }
  4276. }
  4277. document.addEventListener('loadedmetadata', handler, true);
  4278. document.addEventListener('durationchange', handler, true);
  4279.  
  4280. })();
  4281.  
  4282.  
  4283.  
  4284. const cleanContext = async (win) => {
  4285. const waitFn = requestAnimationFrame; // shall have been binded to window
  4286. try {
  4287. let mx = 16; // MAX TRIAL
  4288. const frameId = 'vanillajs-iframe-v1';
  4289. /** @type {HTMLIFrameElement | null} */
  4290. let frame = document.getElementById(frameId);
  4291. let removeIframeFn = null;
  4292. if (!frame) {
  4293. frame = document.createElement('iframe');
  4294. frame.id = frameId;
  4295. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  4296. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  4297. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  4298. n.appendChild(frame);
  4299. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  4300. const root = document.documentElement;
  4301. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  4302. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  4303.  
  4304. removeIframeFn = (setTimeout) => {
  4305. const removeIframeOnDocumentReady = (e) => {
  4306. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  4307. e = n;
  4308. n = win = removeIframeFn = 0;
  4309. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  4310. }
  4311. if (!setTimeout || document.readyState !== 'loading') {
  4312. removeIframeOnDocumentReady();
  4313. } else {
  4314. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  4315. }
  4316. }
  4317. }
  4318. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  4319. const fc = frame.contentWindow;
  4320. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  4321. try {
  4322. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  4323. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  4324. for (let k in res) res[k] = res[k].bind(win); // necessary
  4325. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  4326. res.animate = fc.HTMLElement.prototype.animate;
  4327. res.perfNow = fc.performance.now;
  4328. return res;
  4329. } catch (e) {
  4330. if (removeIframeFn) removeIframeFn();
  4331. return null;
  4332. }
  4333. } catch (e) {
  4334. console.warn(e);
  4335. return null;
  4336. }
  4337. };
  4338.  
  4339. const promiseForYtActionCalled = new Promise(resolve => {
  4340. if (typeof AbortSignal !== 'undefined') {
  4341. let hn = () => {
  4342. if (!hn) return;
  4343. hn = null;
  4344. resolve(document.querySelector('ytd-app'));
  4345. };
  4346. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  4347. } else {
  4348. let hn = () => {
  4349. if (!hn) return;
  4350. document.removeEventListener('yt-action', hn, true);
  4351. hn = null;
  4352. resolve(document.querySelector('ytd-app'));
  4353. };
  4354. document.addEventListener('yt-action', hn, true);
  4355. }
  4356. });
  4357.  
  4358.  
  4359.  
  4360. cleanContext(window).then(__CONTEXT__ => {
  4361. if (!__CONTEXT__) return null;
  4362.  
  4363. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  4364.  
  4365.  
  4366. performance.now17 = perfNow.bind(performance);
  4367.  
  4368.  
  4369.  
  4370. __requestAnimationFrame__ = requestAnimationFrame;
  4371.  
  4372.  
  4373. const isGPUAccelerationAvailable = (() => {
  4374. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  4375. try {
  4376. const canvas = document.createElement('canvas');
  4377. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  4378. } catch (e) {
  4379. return false;
  4380. }
  4381. })();
  4382.  
  4383. const foregroundPromiseFn_noGPU = (() => {
  4384.  
  4385. if (isGPUAccelerationAvailable) return null;
  4386.  
  4387. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  4388. if (!pd || typeof pd.get !== 'function') return null;
  4389. const pdGet = pd.get;
  4390.  
  4391. let pr = null;
  4392.  
  4393. let hState = pdGet.call(document) === 'hidden';
  4394. // let cid = 0;
  4395. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  4396. const newHState = pdGet.call(document) === 'hidden';
  4397. if (hState !== newHState) {
  4398. // if (cid > 0) cid = clearInterval(cid);
  4399. hState = newHState;
  4400. if (!hState && pr) pr = pr.resolve();
  4401. }
  4402. });
  4403.  
  4404. // cid = setInterval(() => {
  4405. // const newHState = document.visibilityState === 'hidden';
  4406. // if (hState !== newHState) {
  4407. // hState = newHState;
  4408. // if (!hState && pr) pr = pr.resolve();
  4409. // }
  4410. // }, 100);
  4411.  
  4412.  
  4413. return (() => {
  4414. if (pr) return pr;
  4415. const w = ((!hState && setTimeout(() => {
  4416. if (!hState && pr === w) pr = pr.resolve();
  4417. })), (pr = new PromiseExternal()));
  4418. return w;
  4419. });
  4420.  
  4421. })();
  4422.  
  4423.  
  4424. let rafPromise = null;
  4425. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  4426. requestAnimationFrame(hRes => {
  4427. rafPromise = null;
  4428. resolve(hRes);
  4429. });
  4430. }));
  4431.  
  4432. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  4433.  
  4434.  
  4435. const wmComputedStyle = new WeakMap();
  4436.  
  4437. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  4438. window.__native__getComputedStyle__ = getComputedStyle;
  4439. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  4440. window.__original__getComputedStyle__ = window.getComputedStyle;
  4441. window.getComputedStyle = function (elem) {
  4442. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  4443. return window.__original__getComputedStyle__(...arguments);
  4444. }
  4445. let cs = wmComputedStyle.get(elem);
  4446. if (!cs) {
  4447. cs = window.__native__getComputedStyle__(elem);
  4448. wmComputedStyle.set(elem, cs);
  4449. }
  4450. return cs;
  4451. };
  4452. } else {
  4453. window.__original__getComputedStyle__ = null;
  4454. }
  4455. window.__jst__getComputedStyle__ = window.getComputedStyle;
  4456. }
  4457.  
  4458. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  4459. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  4460. window.getComputedStyle = window.__jst__getComputedStyle__;
  4461. }
  4462. });
  4463.  
  4464. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  4465. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  4466.  
  4467. const promiseForTamerTimeout = new Promise(resolve => {
  4468. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  4469. setTimeout(resolve, 480);
  4470. }, { capture: true, passive: true, once: true });
  4471. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  4472. setTimeout(resolve, 1200);
  4473. });
  4474. setTimeout(resolve, 3000);
  4475. });
  4476.  
  4477. const promiseForPageInitied = new Promise(resolve => {
  4478. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  4479. setTimeout(resolve, 450);
  4480. }, { capture: true, passive: true, once: true });
  4481. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  4482. setTimeout(resolve, 900);
  4483. });
  4484. setTimeout(resolve, 1800);
  4485. });
  4486.  
  4487. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  4488. NO_PRELOAD_GENERATE_204_BYPASS = true;
  4489. headLinkCollection = null;
  4490. });
  4491.  
  4492.  
  4493. NATIVE_CANVAS_ANIMATION && (() => {
  4494.  
  4495. observablePromise(() => {
  4496. HTMLCanvasElement.prototype.animate = animate;
  4497. }, promiseForTamerTimeout).obtain();
  4498.  
  4499. })();
  4500.  
  4501. FIX_ytAction_ && (async () => {
  4502.  
  4503. const ytdApp = await new Promise(resolve => {
  4504.  
  4505. whenCEDefined('ytd-app').then(() => {
  4506. const ytdApp = document.querySelector('ytd-app');
  4507. if (ytdApp) {
  4508. resolve(ytdApp);
  4509. return;
  4510. }
  4511. let mo = new MutationObserver(() => {
  4512. const ytdApp = document.querySelector('ytd-app');
  4513. if (!ytdApp) return;
  4514. if (mo) {
  4515. mo.disconnect();
  4516. mo.takeRecords();
  4517. mo = null;
  4518. }
  4519. resolve(ytdApp);
  4520. });
  4521. mo.observe(document, { subtree: true, childList: true });
  4522. });
  4523.  
  4524. });
  4525.  
  4526. if (!ytdApp) return;
  4527. const cProto = insp(ytdApp).constructor.prototype;
  4528.  
  4529. if (!cProto) return;
  4530. let mbd = 0;
  4531.  
  4532. const fixer = (_ytdApp) => {
  4533. const ytdApp = insp(_ytdApp);
  4534. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  4535. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  4536. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  4537. mbd++;
  4538. }
  4539. }
  4540.  
  4541. observablePromise(() => {
  4542.  
  4543. if (typeof cProto.created === 'function' && !cProto.created56) {
  4544. cProto.created56 = cProto.created;
  4545. cProto.created = function (...args) {
  4546. const r = this.created56(...args);
  4547. fixer(this);
  4548. return r;
  4549. };
  4550. mbd++;
  4551. }
  4552.  
  4553. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  4554. cProto.onYtAction57_ = cProto.onYtAction_;
  4555. cProto.onYtAction_ = function (...args) {
  4556. Promise.resolve().then(() => this.onYtAction57_(...args));
  4557. };
  4558. mbd++;
  4559. }
  4560.  
  4561. if (ytdApp) fixer(ytdApp);
  4562.  
  4563. /*
  4564. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  4565. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  4566. actionRouter_.handleAction57 = actionRouter_.handleAction;
  4567. actionRouter_.handleAction = function (...args) {
  4568. Promise.resolve().then(() => this.handleAction57(...args));
  4569. }
  4570. mbd++;
  4571. }
  4572. */
  4573.  
  4574. // if(mbd === 3) return 1;
  4575. if (mbd >= 3) return 1;
  4576.  
  4577. }, new Promise(r => setTimeout(r, 1000))).obtain();
  4578.  
  4579. })();
  4580.  
  4581. const observablePromise = (proc, timeoutPromise) => {
  4582. let promise = null;
  4583. return {
  4584. obtain() {
  4585. if (!promise) {
  4586. promise = new Promise(resolve => {
  4587. let mo = null;
  4588. const f = () => {
  4589. let t = proc();
  4590. if (t) {
  4591. mo.disconnect();
  4592. mo.takeRecords();
  4593. mo = null;
  4594. resolve(t);
  4595. }
  4596. }
  4597. mo = new MutationObserver(f);
  4598. mo.observe(document, { subtree: true, childList: true })
  4599. f();
  4600. timeoutPromise && timeoutPromise.then(() => {
  4601. resolve(null)
  4602. });
  4603. });
  4604. }
  4605. return promise
  4606. }
  4607. }
  4608. }
  4609.  
  4610. // let _yt_player_promise = null;
  4611. /*
  4612. const getYtPlayerPromise = () => {
  4613. if (!_yt_player_promise) {
  4614. _yt_player_promise = new Promise(resolve => {
  4615. let cid = setInterval(() => {
  4616. let t = (((window || 0)._yt_player || 0) || 0);
  4617. if (t) {
  4618. clearInterval(cid);
  4619. resolve(t);
  4620. }
  4621. }, 1);
  4622. promiseForTamerTimeout.then(() => {
  4623. resolve(null)
  4624. });
  4625. });
  4626. }
  4627. return _yt_player_promise;
  4628. }
  4629. */
  4630. const _yt_player_observable = observablePromise(() => {
  4631. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  4632. if (_yt_player) {
  4633. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  4634. return _yt_player;
  4635. }
  4636. }, promiseForTamerTimeout);
  4637.  
  4638. const polymerObservable = observablePromise(() => {
  4639. const Polymer = window.Polymer;
  4640. if (typeof Polymer !== 'function') return;
  4641. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  4642. return Polymer;
  4643. }, promiseForTamerTimeout);
  4644.  
  4645. const schedulerInstanceObservable = observablePromise(() => {
  4646. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  4647. }, promiseForTamerTimeout);
  4648.  
  4649. const timelineObservable = observablePromise(() => {
  4650. let t = (((document || 0).timeline || 0) || 0);
  4651. if (t && typeof t._play === 'function') {
  4652. return t;
  4653. }
  4654. }, promiseForTamerTimeout);
  4655. const animationObservable = observablePromise(() => {
  4656. let t = (((window || 0).Animation || 0) || 0);
  4657. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  4658. return t;
  4659. }
  4660. }, promiseForTamerTimeout);
  4661.  
  4662.  
  4663. const getScreenInfo = {
  4664. screenWidth: 0,
  4665. screenHeight: 0,
  4666. valueReady: false,
  4667. onResize: () => {
  4668. getScreenInfo.valueReady = false;
  4669. },
  4670. sizeProvided: () => {
  4671. if (getScreenInfo.valueReady) return true;
  4672. getScreenInfo.screenWidth = screen.width;
  4673. getScreenInfo.screenHeight = screen.height;
  4674. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  4675. getScreenInfo.valueReady = true;
  4676. return true;
  4677. }
  4678. return false;
  4679. }
  4680. };
  4681.  
  4682. window.addEventListener('resize', getScreenInfo.onResize, true);
  4683.  
  4684.  
  4685.  
  4686. const hookLeftPD = {
  4687. get() {
  4688. return this.getPropertyValue('left');
  4689. },
  4690. set(v) {
  4691.  
  4692.  
  4693. const style = this;
  4694. const p = 'left';
  4695. const cv = style[p];
  4696. const c = v;
  4697. if (!cv && !c) return true;
  4698. if (cv === c) return true;
  4699.  
  4700. let qcv = NaN;
  4701. let qc = NaN;
  4702.  
  4703.  
  4704. if (`${cv}`.length >= 3 && `${cv}`.endsWith('px')) {
  4705.  
  4706. qcv = +cv.slice(0, -2);
  4707. }
  4708.  
  4709. if (`${c}`.length >= 3 && `${c}`.endsWith('px')) {
  4710.  
  4711. qc = +c.slice(0, -2);
  4712. }
  4713.  
  4714.  
  4715. if (!isNaN(qcv) && !isNaN(qc) && getScreenInfo.sizeProvided()) {
  4716. const { screenWidth, screenHeight } = getScreenInfo;
  4717. let pWidth = screenWidth + 1024;
  4718. let pHeight = screenHeight + 768;
  4719. const minRatio = 0.003;
  4720. const dw = pWidth * 0.0003; // min dw = 0.3072
  4721. const dh = pHeight * 0.0003; // min dh = 0.2304
  4722. if (Math.abs(qcv - qc) < dw) return true;
  4723. }
  4724.  
  4725.  
  4726. if (!isNaN(qc)) {
  4727.  
  4728. let nv = +qc.toFixed(4);
  4729.  
  4730. if (nv > -1e-5 && nv < 1e-5) {
  4731. nv = 0;
  4732. }
  4733. this.setProperty(p, `${nv}px`);
  4734. return true;
  4735.  
  4736. }
  4737.  
  4738.  
  4739. this.setProperty('left', v);
  4740. return true;
  4741. },
  4742. enumerable: true,
  4743. configurable: true
  4744. };
  4745.  
  4746.  
  4747. if (HOOK_CSSPD_LEFT) {
  4748.  
  4749.  
  4750. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  4751.  
  4752. }
  4753.  
  4754.  
  4755.  
  4756.  
  4757.  
  4758. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  4759.  
  4760. const evKey = `${_evKey}`;
  4761. const fvKey = `${_fvKey}`;
  4762. const debug = !!_debug;
  4763.  
  4764. const _yt_player = await _yt_player_observable.obtain();
  4765.  
  4766.  
  4767. if (!_yt_player || typeof _yt_player !== 'object') return;
  4768.  
  4769.  
  4770. const getArr = (_yt_player) => {
  4771.  
  4772. let arr = [];
  4773.  
  4774. for (const [k, v] of Object.entries(_yt_player)) {
  4775.  
  4776. const p = typeof v === 'function' ? v.prototype : 0;
  4777. if (p
  4778. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  4779.  
  4780. ) {
  4781. arr = addProtoToArr(_yt_player, k, arr) || arr;
  4782.  
  4783. }
  4784.  
  4785. }
  4786.  
  4787. if (arr.length === 0) {
  4788.  
  4789. console.warn(`Key prop [${evKey}] does not exist.`);
  4790. } else {
  4791.  
  4792. return arr;
  4793. }
  4794.  
  4795. };
  4796.  
  4797. const arr = getArr(_yt_player);
  4798.  
  4799.  
  4800. if (!arr) return;
  4801.  
  4802. debug && console.log(`FIX_${evKey}`, arr);
  4803.  
  4804. const f = function (...args) {
  4805. Promise.resolve().then(() => this[fvKey](...args));
  4806. };
  4807.  
  4808.  
  4809. for (const k of arr) {
  4810.  
  4811. const g = _yt_player;
  4812. const gk = g[k];
  4813. const gkp = gk.prototype;
  4814.  
  4815. debug && console.log(237, k, gkp)
  4816.  
  4817. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  4818. gkp[fvKey] = gkp[evKey];
  4819. gkp[evKey] = f;
  4820. }
  4821. }
  4822.  
  4823.  
  4824.  
  4825.  
  4826. }
  4827.  
  4828. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  4829. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  4830. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  4831. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  4832. if (FIX_VideoEVENTS_v2) {
  4833. const FIX_VideoEVENTS_DEBUG = 0;
  4834. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  4835. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  4836. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  4837. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  4838. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  4839. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  4840. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  4841. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  4842. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  4843.  
  4844. }
  4845. // onMutedAutoplayChange
  4846. // onVolumeChange
  4847. // onPlaybackRateChange
  4848.  
  4849. // onAirPlayActiveChange
  4850. // onAirPlayAvailabilityChange
  4851. // onApiChange
  4852. // onAutoplayBlocked
  4853. // onDrmOutputRestricted
  4854. // onFullscreenChange
  4855. // onLoadProgress
  4856. // onLoadedMetadata
  4857. // onVideoDataChange
  4858. // onVideoProgress
  4859.  
  4860.  
  4861. (ENABLE_discreteTasking || FIX_Polymer_dom) && (async () => {
  4862.  
  4863. const Polymer = await polymerObservable.obtain();
  4864. if (!Polymer) return;
  4865.  
  4866. if (FIX_Polymer_dom) {
  4867.  
  4868. const checkPDFuncValue = (pd) => {
  4869. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  4870. }
  4871. const checkPDFuncValue2 = (pd) => {
  4872. return pd && typeof pd.value == 'function'
  4873. }
  4874.  
  4875. const checkPDFuncGet = (pd) => {
  4876. return pd && typeof pd.get == 'function'
  4877. }
  4878.  
  4879. const domX = Polymer.dom(document.createElement('null'));
  4880. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  4881. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  4882. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  4883. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  4884. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  4885. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  4886. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  4887. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  4888. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  4889.  
  4890.  
  4891. // getOwnerRoot - to be reviewed
  4892. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  4893.  
  4894. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  4895. domXP.getOwnerRoot = function () {
  4896. try {
  4897. const p = this.node;
  4898.  
  4899. if (p instanceof HTMLElement) {
  4900. const pp = pd2.get.call(p);
  4901. if (pp instanceof HTMLElement && pp.isConnected === true) {
  4902. return pp.getRootNode();
  4903. }
  4904.  
  4905. }
  4906. } catch (e) { }
  4907. return this.getOwnerRoot15();
  4908. }
  4909.  
  4910. Polymer.__fixedGetOwnerRoot__ = 1;
  4911. }
  4912.  
  4913.  
  4914.  
  4915.  
  4916. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  4917.  
  4918. domXP.querySelector15 = domXP.querySelector;
  4919.  
  4920. const querySelectorFn = function (query) {
  4921. try {
  4922. const p = this.node;
  4923.  
  4924. // if (p instanceof HTMLElement && p.isConnected === true) {
  4925. // return pd4.value.call(p, query);
  4926. // }
  4927.  
  4928. if (p instanceof Document && p.isConnected === true) {
  4929. return pd4b.value.call(p, query);
  4930. }
  4931.  
  4932. } catch (e) { }
  4933. return this.querySelector15(query);
  4934. }
  4935.  
  4936. Object.defineProperty(domXP, 'querySelector', {
  4937. get() {
  4938. return querySelectorFn;
  4939. },
  4940. set(nv) {
  4941. if (nv === querySelectorFn) return true;
  4942. this.querySelector15 = nv;
  4943. return true;
  4944. },
  4945.  
  4946. enumerable: false,
  4947. configurable: true
  4948. });
  4949.  
  4950. Polymer.__fixedQuerySelector__ = 1;
  4951. }
  4952.  
  4953. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  4954.  
  4955. domXP.querySelectorAll15 = domXP.querySelectorAll;
  4956.  
  4957. const querySelectorAllFn = function (query) {
  4958.  
  4959. try {
  4960.  
  4961. const p = this.node;
  4962.  
  4963. // if (p instanceof HTMLElement && p.isConnected === true) {
  4964. // return pd6.value.call(p, query);
  4965. // }
  4966.  
  4967. if (p instanceof Document && p.isConnected === true) {
  4968. return pd6b.value.call(p, query);
  4969. }
  4970.  
  4971. } catch (e) {
  4972.  
  4973. }
  4974. return this.querySelectorAll15(query);
  4975. }
  4976.  
  4977. Object.defineProperty(domXP, 'querySelectorAll', {
  4978. get() {
  4979. return querySelectorAllFn;
  4980. },
  4981. set(nv) {
  4982. if (nv === querySelectorAllFn) return true;
  4983. this.querySelectorAll15 = nv;
  4984. return true;
  4985. },
  4986.  
  4987. enumerable: false,
  4988. configurable: true
  4989. });
  4990.  
  4991. Polymer.__fixedQuerySelectorAll__ = 1;
  4992. }
  4993. }
  4994.  
  4995.  
  4996. if (ENABLE_discreteTasking) {
  4997.  
  4998. Polymer.Base.__connInit__ = function () {
  4999. setupDiscreteTasks(this);
  5000. }
  5001.  
  5002.  
  5003. /** @type {Function} */
  5004. const connectedCallbackK = function (...args) {
  5005. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  5006. const r = this[qm53](...args);
  5007. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  5008. this.mh35 = 1;
  5009. return r;
  5010. };
  5011.  
  5012. connectedCallbackK.m353 = 1;
  5013.  
  5014.  
  5015. const qt53 = Polymer.Base.connectedCallback;
  5016. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  5017.  
  5018. Polymer.Base.connectedCallback = connectedCallbackK;
  5019.  
  5020.  
  5021. /** @type {Function} */
  5022. const createdK = function (...args) {
  5023. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  5024. const r = this[qn53](...args);
  5025. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  5026. this.mh36 = 1;
  5027. return r;
  5028. };
  5029.  
  5030.  
  5031. createdK.m353 = 1;
  5032. Polymer.Base[qn53] = Polymer.Base.created;
  5033. Polymer.Base.created = createdK;
  5034.  
  5035. }
  5036.  
  5037. })();
  5038.  
  5039.  
  5040. /*
  5041.  
  5042. e.nativeAppendChild = d.prototype.appendChild,
  5043. d.prototype.appendChild = function(h) {
  5044. return function(l) {
  5045. if (l instanceof DocumentFragment) {
  5046. var m = Array.from(l.children);
  5047. l = h.nativeAppendChild.call(this, l);
  5048. if (this.isConnected) {
  5049. m = g(m);
  5050. for (var p = m.next(); !p.done; p = m.next())
  5051. YD(p.value)
  5052. }
  5053. return l
  5054. }
  5055. m = l instanceof Element && l.isConnected;
  5056. p = h.nativeAppendChild.call(this, l);
  5057. m && ZD(l);
  5058. this.isConnected && YD(l);
  5059. return p
  5060. }
  5061. }(e),
  5062.  
  5063. */
  5064.  
  5065. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  5066.  
  5067. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  5068. if (f) Node.prototype.appendChild = function (a) {
  5069. if (this instanceof Element) { // exclude DocumentFragment
  5070. try {
  5071. let checkFragmentA = (a instanceof DocumentFragment);
  5072. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  5073. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  5074. for (const node of headLinkCollection) {
  5075. if (node.rel === 'preload' && node.as === 'fetch') {
  5076. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  5077. }
  5078. }
  5079. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  5080. checkFragmentA = false;
  5081. }
  5082. if (checkFragmentA && a.firstElementChild === null) {
  5083. // no element in fragmentA
  5084. let doNormal = false;
  5085. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  5086. if (child.nodeType === 3) { doNormal = true; break; }
  5087. }
  5088. if (!doNormal) return a;
  5089. }
  5090. } catch (e) {
  5091. console.log(e);
  5092. }
  5093. }
  5094. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  5095. }
  5096.  
  5097. })();
  5098.  
  5099. if (FIX_Shady) {
  5100.  
  5101. observablePromise(() => {
  5102. const { ShadyDOM, ShadyCSS } = window;
  5103. if (ShadyDOM) {
  5104. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  5105. ShadyDOM.noPatch = true; // 1 of 10
  5106. ShadyDOM.patchOnDemand = false; // 1 of 10
  5107. ShadyDOM.preferPerformance = true; // 1 of 10
  5108. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  5109. }
  5110. if (ShadyCSS) {
  5111. ShadyCSS.nativeCss = true; // 1 of 10
  5112. ShadyCSS.nativeShadow = true; // 6 of 10
  5113. ShadyCSS.cssBuild = undefined; // 1 of 10
  5114. ShadyCSS.disableRuntime = true; // 1 of 10
  5115. }
  5116. if (ShadyDOM && ShadyCSS) return 1;
  5117. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  5118.  
  5119. }
  5120.  
  5121.  
  5122. // let schedulerInstancePropOfTimerType = '';
  5123. // let schedulerInstancePropOfTimerId = '';
  5124. (FIX_schedulerInstanceInstance & 2) && (async () => {
  5125.  
  5126. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  5127.  
  5128. if (!schedulerInstanceInstance_) return;
  5129.  
  5130. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  5131. if (checkOK) {
  5132.  
  5133. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  5134.  
  5135. let requestingFn = null;
  5136. let requestingArgs = null;
  5137.  
  5138. const f = function () {
  5139. requestingFn = this.fn;
  5140. requestingArgs = [...arguments];
  5141. return 12373;
  5142. };
  5143.  
  5144. const fakeFns = [
  5145. f.bind({ fn: requestAnimationFrame }),
  5146. f.bind({ fn: setInterval }),
  5147. f.bind({ fn: setTimeout }),
  5148. f.bind({ fn: requestIdleCallback })
  5149. ];
  5150.  
  5151. let mzt = 0;
  5152.  
  5153. let _fnSelectorProp = null;
  5154. const mkFns = new Array(4);
  5155.  
  5156. /*
  5157. case 1:
  5158. var a = this.K;
  5159. this.g = this.I ? window.requestIdleCallback(a, {
  5160. timeout: 3E3
  5161. }) : window.setTimeout(a, ma);
  5162. break;
  5163. case 2:
  5164. this.g = window.setTimeout(this.M, this.N);
  5165. break;
  5166. case 3:
  5167. this.g = window.requestAnimationFrame(this.L);
  5168. break;
  5169. case 4:
  5170. this.g = window.setTimeout(this.J, 0)
  5171. }
  5172.  
  5173. */
  5174. const startFnHandler = {
  5175. get(target, prop, receiver) {
  5176. if (prop === '$$12377$$') return true;
  5177. if (prop === '$$12378$$') return target;
  5178.  
  5179. // console.log('get',prop)
  5180. return target[prop]
  5181. },
  5182. set(target, prop, value, receiver) {
  5183. // console.log('set', prop, value)
  5184.  
  5185. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  5186. if (value === 12373 && _fnSelectorProp) {
  5187.  
  5188. const schedulerTypeSelection = target[_fnSelectorProp];
  5189. const timerIdProp = prop;
  5190.  
  5191. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  5192. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  5193. // schedulerInstancePropOfTimerId = timerIdProp || '';
  5194. // }
  5195.  
  5196. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  5197. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  5198. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  5199. // rare
  5200. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  5201. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  5202. // often
  5203. if ((FIX_schedulerInstanceInstance & 4) && typeof nextBrowserTick == 'function') {
  5204. const f = requestingArgs[0];
  5205. const tir = ++mzt;
  5206. nextBrowserTick(() => {
  5207. if (target[timerIdProp] === -tir) f();
  5208. });
  5209. target[_fnSelectorProp] = 940;
  5210. target[timerIdProp] = -tir;
  5211. } else {
  5212. const f = requestingArgs[0];
  5213. const tir = ++mzt;
  5214. Promise.resolve().then(() => {
  5215. if (target[timerIdProp] === -tir) f();
  5216. });
  5217. target[_fnSelectorProp] = 930;
  5218. target[timerIdProp] = -tir;
  5219. }
  5220. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  5221. // often
  5222. if (requestingFn === requestIdleCallback) {
  5223. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  5224. } else {
  5225. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  5226. }
  5227. } else {
  5228. target[_fnSelectorProp] = 0;
  5229. target[timerIdProp] = 0;
  5230. }
  5231. } else {
  5232. target[prop] = value;
  5233. }
  5234. return true;
  5235. }
  5236. };
  5237.  
  5238. let startBusy = false;
  5239. schedulerInstanceInstance_.start = function () {
  5240. if (startBusy) return;
  5241. startBusy = true;
  5242. try {
  5243. mkFns[0] = window.requestAnimationFrame;
  5244. mkFns[1] = window.setInterval;
  5245. mkFns[2] = window.setTimeout;
  5246. mkFns[3] = window.requestIdleCallback;
  5247. const tThis = this['$$12378$$'] || this;
  5248. window.requestAnimationFrame = fakeFns[0]
  5249. window.setInterval = fakeFns[1]
  5250. window.setTimeout = fakeFns[2]
  5251. window.requestIdleCallback = fakeFns[3]
  5252. _fnSelectorProp = null;
  5253. tThis.start993.call(new Proxy(tThis, startFnHandler));
  5254. _fnSelectorProp = null;
  5255. window.requestAnimationFrame = mkFns[0];
  5256. window.setInterval = mkFns[1];
  5257. window.setTimeout = mkFns[2];
  5258. window.requestIdleCallback = mkFns[3];
  5259. } catch (e) {
  5260. console.warn(e);
  5261. }
  5262. startBusy = false;
  5263. }
  5264.  
  5265. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  5266.  
  5267. }
  5268. })();
  5269.  
  5270. FIX_yt_player && (async () => {
  5271.  
  5272. const fOption = 1 | 2 | 4;
  5273.  
  5274. const _yt_player = await _yt_player_observable.obtain();
  5275.  
  5276. if (!_yt_player || typeof _yt_player !== 'object') return;
  5277.  
  5278. const g = _yt_player;
  5279. let k;
  5280.  
  5281. if (fOption & 1) {
  5282.  
  5283. // rAf scheduling
  5284.  
  5285. const keyZqOu = getZqOu(_yt_player);
  5286. if (!keyZqOu) {
  5287. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  5288. return;
  5289. }
  5290. k = keyZqOu
  5291.  
  5292. const gk = g[k];
  5293. if (typeof gk !== 'function') {
  5294. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  5295. return;
  5296. }
  5297. const gkp = gk.prototype;
  5298.  
  5299. const dummyObject = new gk;
  5300. const nilFunc = () => { };
  5301.  
  5302. const nilObj = {};
  5303.  
  5304. // console.log(1111111111)
  5305.  
  5306. let keyBoolD = '';
  5307. let keyWindow = '';
  5308. let keyFuncC = '';
  5309. let keyCidj = '';
  5310.  
  5311. for (const [t, y] of Object.entries(dummyObject)) {
  5312. if (y instanceof Window) keyWindow = t;
  5313. }
  5314.  
  5315. const dummyObjectProxyHandler = {
  5316. get(target, prop) {
  5317. let v = target[prop]
  5318. if (v instanceof Window && !keyWindow) {
  5319. keyWindow = t;
  5320. }
  5321. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  5322. if (prop === keyWindow) y = {
  5323. requestAnimationFrame(f) {
  5324. return 3;
  5325. },
  5326. cancelAnimationFrame() {
  5327.  
  5328. }
  5329. }
  5330. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  5331. keyFuncC = prop;
  5332. }
  5333. // console.log('[get]', prop, typeof target[prop])
  5334.  
  5335.  
  5336. return y;
  5337. },
  5338. set(target, prop, value) {
  5339.  
  5340. if (typeof value === 'boolean' && !keyBoolD) {
  5341. keyBoolD = prop;
  5342. }
  5343. if (typeof value === 'number' && !keyCidj && value >= 2) {
  5344. keyCidj = prop;
  5345. }
  5346.  
  5347. // console.log('[set]', prop, value)
  5348. target[prop] = value;
  5349.  
  5350. return true;
  5351. }
  5352. };
  5353.  
  5354. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  5355.  
  5356. // console.log('gkp.start',gkp.start);
  5357. // console.log('gkp.stop',gkp.stop);
  5358. gkp._activation = false;
  5359.  
  5360. gkp.start = function () {
  5361. // p59 || console.log(12100)
  5362. if (!this._activation) {
  5363. this._activation = true;
  5364. foregroundPromiseFn().then(() => {
  5365. this._activation = false;
  5366. if (this[keyCidj]) {
  5367. Promise.resolve().then(this[keyFuncC]);
  5368. }
  5369. });
  5370. }
  5371. this[keyCidj] = 1;
  5372. this[keyBoolD] = true;
  5373. };
  5374.  
  5375. gkp.stop = function () {
  5376. this[keyCidj] = null;
  5377. };
  5378.  
  5379.  
  5380. /*
  5381. g[k].start = function() {
  5382. this.stop();
  5383. this.D = true;
  5384. var a = requestAnimationFrame
  5385. , b = cancelAnimationFrame;
  5386. this.j = a.call(this.B, this.C)
  5387. }
  5388. ;
  5389. g[k].stop = function() {
  5390. if (this.isActive()) {
  5391. var a = requestAnimationFrame
  5392. , b = cancelAnimationFrame;
  5393. b.call(this.B, this.j)
  5394. }
  5395. this.j = null
  5396. }
  5397. */
  5398. }
  5399.  
  5400. if (fOption & 2) {
  5401. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  5402.  
  5403. if (keyzo) {
  5404.  
  5405. k = keyzo;
  5406.  
  5407. const attrUpdateFn = g[k];
  5408. // console.log(5992, attrUpdateFn)
  5409. g['$$original$$' + k] = attrUpdateFn;
  5410. const zoTransform = async (a, c) => {
  5411.  
  5412. let transformType = '';
  5413. let transformValue = 0;
  5414. let transformUnit = '';
  5415. let transformTypeI = 0;
  5416.  
  5417. const aStyle = a.style;
  5418.  
  5419. if (c.length < 9) {
  5420.  
  5421. } else if (c.startsWith('scalex(0.') || (c === 'scalex(0)' || c === 'scalex(1)')) {
  5422. let p = c.substring(7, c.length - 1);
  5423. let q = p.length >= 1 ? parseFloat(p) : -1;
  5424. if (q > -1e-5 && q < 1 + 1e-5) {
  5425. transformType = 'scaleX'
  5426. transformValue = q;
  5427. transformUnit = '';
  5428. transformTypeI = 1;
  5429. }
  5430. } else if (c.startsWith('translateX(') && c.endsWith('px)')) {
  5431. let p = c.substring(11, c.length - 3);
  5432. let q = p.length >= 1 ? parseFloat(p) : NaN;
  5433. if (typeof q === 'number' && !isNaN(q)) {
  5434. transformType = 'translateX'
  5435. transformValue = q;
  5436. transformUnit = 'px';
  5437. transformTypeI = 2;
  5438. } else if (p === 'NaN') {
  5439. return;
  5440. }
  5441. } else if (c.startsWith('scaley(0.') || (c === 'scaley(0)' || c === 'scaley(1)')) {
  5442. let p = c.substring(7, c.length - 1);
  5443. let q = p.length >= 1 ? parseFloat(p) : -1;
  5444. if (q > -1e-5 && q < 1 + 1e-5) {
  5445. transformType = 'scaleY'
  5446. transformValue = q;
  5447. transformUnit = '';
  5448. transformTypeI = 1;
  5449. }
  5450. } else if (c.startsWith('translateY(') && c.endsWith('px)')) {
  5451. let p = c.substring(11, c.length - 3);
  5452. let q = p.length >= 1 ? parseFloat(p) : NaN;
  5453. if (typeof q === 'number' && !isNaN(q)) {
  5454. transformType = 'translateY'
  5455. transformValue = q;
  5456. transformUnit = 'px';
  5457. transformTypeI = 2;
  5458. } else if (p === 'NaN') {
  5459. return;
  5460. }
  5461. } else if (c.startsWith('scalex(') && c.includes('e-')) {
  5462. // scalex(1.252057684158767e-16)
  5463. // scalex(3.0393632069734948e-9)
  5464. let p = c.substring(7, c.length - 1);
  5465. let q = p.length >= 1 ? parseFloat(p) : -1;
  5466. if (q > -1e-5 && q < 1e-5) {
  5467. transformType = 'scaleX'
  5468. transformValue = 0;
  5469. transformUnit = '';
  5470. transformTypeI = 1;
  5471. }
  5472. } else if (c.startsWith('scaley(') && c.includes('e-')) {
  5473. let p = c.substring(7, c.length - 1);
  5474. let q = p.length >= 1 ? parseFloat(p) : -1;
  5475. if (q > -1e-5 && q < 1e-5) {
  5476. transformType = 'scaleY'
  5477. transformValue = 0;
  5478. transformUnit = '';
  5479. transformTypeI = 1;
  5480. }
  5481. } else {
  5482. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  5483. }
  5484.  
  5485. if (transformTypeI === 1) {
  5486. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  5487. const vz = toFixed2(q, 3);
  5488. c = `${transformType}(${vz})`;
  5489. const cv = aStyle.transform;
  5490. if (c === cv) return;
  5491. aStyle.transform = c;
  5492. } else if (transformTypeI === 2) {
  5493. const q = transformValue;
  5494. const vz = toFixed2(q, 1);
  5495. c = `${transformType}(${vz}${transformUnit})`;
  5496. const cv = aStyle.transform;
  5497. if (c === cv) return;
  5498. aStyle.transform = c;
  5499. } else { // eg empty
  5500. const cv = aStyle.transform;
  5501. if (!c && !cv) return;
  5502. else if (c === cv) return;
  5503. aStyle.transform = c;
  5504. }
  5505.  
  5506. };
  5507.  
  5508. const elmTransformTemp = new WeakMap();
  5509. const elmPropTemps = {
  5510. 'display': new WeakMap(),
  5511. 'width': new WeakMap(),
  5512. 'height': new WeakMap(),
  5513. 'outlineWidth': new WeakMap(),
  5514. 'position': new WeakMap(),
  5515. 'padding': new WeakMap(),
  5516. "cssText": new WeakMap(),
  5517. "right": new WeakMap(),
  5518. "left": new WeakMap(),
  5519. "top": new WeakMap(),
  5520. "bottom": new WeakMap(),
  5521. "transitionDelay": new WeakMap(),
  5522. "marginLeft": new WeakMap(),
  5523. "marginTop": new WeakMap(),
  5524. "marginRight": new WeakMap(),
  5525. "marginBottom": new WeakMap(),
  5526. }
  5527.  
  5528. const ns5 = Symbol();
  5529. const nextModify = (a, c, m, f, immediate) => {
  5530. const a_ = a;
  5531. const m_ = m;
  5532. const noKey = !m_.has(a_);
  5533. if (immediate || noKey) {
  5534. m_.set(a_, ns5);
  5535. f(a_, c);
  5536. noKey && nextBrowserTick_(() => {
  5537. const d = m_.get(a_);
  5538. if (d === undefined) return;
  5539. m_.delete(a_);
  5540. if (d !== ns5) f(a_, d);
  5541. });
  5542. } else {
  5543. m_.set(a_, c);
  5544. }
  5545. };
  5546.  
  5547. const set66 = new Set();
  5548. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  5549.  
  5550. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  5551.  
  5552. // console.log(140000, a, b, c);
  5553. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement) {
  5554. const num = c;
  5555. c = `${num}`;
  5556. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  5557. }
  5558.  
  5559. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement) {
  5560.  
  5561. let elmPropTemp = null;
  5562.  
  5563. if (b === "transform") {
  5564. // div.ytp-hover-progress.ytp-hover-progress-light
  5565. // div.ytp-play-progress.ytp-swatch-background-color
  5566.  
  5567. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  5568. // let ast = null;
  5569. // if (a instanceof HTMLElement && !('__styleH745__' in a) && (ast = a.style)) {
  5570. // a.__styleH745__ = 1;
  5571. // Object.defineProperty(ast, 'left', hookLeftPD);
  5572. // }
  5573. return;
  5574.  
  5575. } else if (elmPropTemp = elmPropTemps[b]) {
  5576.  
  5577. // if (c.length > 5 && c.includes('.')) {
  5578. // console.log(123213, c)
  5579. // }
  5580.  
  5581. const b_ = b;
  5582. nextModify(a, c, elmPropTemp, (a, c) => {
  5583. const style = a.style;
  5584. const cv = style[b_];
  5585. if (!cv && !c) return;
  5586. if (cv === c) return;
  5587. style[b_] = c;
  5588. }, immediateChange);
  5589. return;
  5590.  
  5591. } else if (b === "outline-width") {
  5592.  
  5593. const b_ = 'outlineWidth';
  5594. elmPropTemp = elmPropTemps[b_];
  5595. nextModify(a, c, elmPropTemp, (a, c) => {
  5596. const style = a.style;
  5597. const cv = style[b_];
  5598. if (!cv && !c) return;
  5599. if (cv === c) return;
  5600. style[b_] = c;
  5601. }, immediateChange);
  5602. return;
  5603.  
  5604. } else if (b === 'maxWidth' || b === 'maxHeight') {
  5605. // I think these can be directly assigned.
  5606.  
  5607. const b_ = b;
  5608. const style = a.style;
  5609. const cv = style[b_];
  5610. if (!cv && !c) return;
  5611. if (cv === c) return;
  5612. style[b_] = c;
  5613. return;
  5614.  
  5615. } else {
  5616. // if(immediate && elmPropTemps[b]){
  5617. // console.log(5191, b)
  5618. // }
  5619. // caption-window
  5620. // margin-left max-height max-width font-family fill color font-size background white-space margin
  5621. // text-align background-color
  5622. // console.log(27304, a, b, c)
  5623. if (!set66.has(b)) {
  5624. set66.add(b);
  5625. nextBrowserTick_(() => {
  5626. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  5627. console.log(27304, a, b, c)
  5628. }
  5629. })
  5630. }
  5631. }
  5632.  
  5633. attrUpdateFn.call(this, a, b, c);
  5634. return;
  5635. } else if (typeof (b || 0) === 'object') {
  5636.  
  5637. // this is to fix caption positioning
  5638. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  5639. const immediate = (a.id || 0).length > 14;
  5640. for (const [k, v] of Object.entries(b)) {
  5641. modifiedFn.call(this, a, k, v, immediate);
  5642. }
  5643.  
  5644. } else {
  5645. console.log(27306, a, b, c);
  5646.  
  5647. attrUpdateFn.call(this, a, b, c);
  5648. return;
  5649. }
  5650.  
  5651. // console.log(130000, a, b, c);
  5652.  
  5653. };
  5654. g[k] = modifiedFn;
  5655.  
  5656.  
  5657. /*
  5658. g.zo = function(a, b, c) {
  5659. if ("string" === typeof b)
  5660. (b = yo(a, b)) && (a.style[b] = c);
  5661. else
  5662. for (var d in b) {
  5663. c = a;
  5664. var e = b[d]
  5665. , f = yo(c, d);
  5666. f && (c.style[f] = e)
  5667. }
  5668. }
  5669. */
  5670.  
  5671.  
  5672. }
  5673. }
  5674.  
  5675. if (fOption & 4) {
  5676. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  5677.  
  5678. if (keyuG) {
  5679.  
  5680. k = keyuG;
  5681.  
  5682. const gk = g[k];
  5683. const gkp = gk.prototype;
  5684.  
  5685.  
  5686. /** @type { Map<string, WeakMap<any, any>> } */
  5687. const ntLogs = new Map();
  5688.  
  5689. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  5690.  
  5691. gkp.updateValue31 = gkp.updateValue;
  5692. gkp.updateValue = function (a, b) {
  5693. if (typeof a !== 'string') return this.updateValue31(a, b);
  5694.  
  5695. const element = this.element;
  5696. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  5697.  
  5698. let ntLog = ntLogs.get(a);
  5699. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  5700.  
  5701. let cache = ntLog.get(element);
  5702. if (cache && cache.value === b) {
  5703. return;
  5704. }
  5705. if (!cache) {
  5706. this.__oldValueByUpdateValue__ = null;
  5707. ntLog.set(element, cache = { value: b });
  5708. } else {
  5709. this.__oldValueByUpdateValue__ = cache.value;
  5710. cache.value = b;
  5711. }
  5712.  
  5713. return this.updateValue31(a, b);
  5714. }
  5715.  
  5716. /*
  5717. g.k.update = function(a) {
  5718. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  5719. c = c.value,
  5720. this.updateValue(c, a[c])
  5721. }
  5722. ;
  5723. g.k.updateValue = function(a, b) {
  5724. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  5725. }
  5726. */
  5727.  
  5728. }
  5729.  
  5730.  
  5731. }
  5732. }
  5733.  
  5734.  
  5735.  
  5736. })();
  5737.  
  5738.  
  5739. FIX_yt_player && FIX_SHORTCUTKEYS > 0 && (async () => {
  5740. // keyboard shortcut keys controller
  5741.  
  5742. const _yt_player = await _yt_player_observable.obtain();
  5743.  
  5744. if (!_yt_player || typeof _yt_player !== 'object') return;
  5745.  
  5746. keyboardController(_yt_player);
  5747.  
  5748. })();
  5749.  
  5750. FIX_yt_player && (async () => {
  5751. // timer scheduling
  5752.  
  5753. const _yt_player = await _yt_player_observable.obtain();
  5754.  
  5755. if (!_yt_player || typeof _yt_player !== 'object') return;
  5756.  
  5757. let keyZqQu = getZqQu(_yt_player);
  5758.  
  5759. if (!keyZqQu) return;
  5760.  
  5761. const g = _yt_player
  5762. let k = keyZqQu
  5763.  
  5764. const gk = g[k];
  5765. if (typeof gk !== 'function') return;
  5766. const gkp = gk.prototype;
  5767.  
  5768. const extractKeysZqQu = () => {
  5769.  
  5770.  
  5771. let _keyeC = '';
  5772. try {
  5773. gkp.stop.call(new Proxy({
  5774. isActive: () => { }
  5775. }, {
  5776. set(target, prop, value) {
  5777. if (value === 0) _keyeC = prop;
  5778. return true;
  5779. }
  5780. }));
  5781. } catch (e) { }
  5782. if (!_keyeC) return;
  5783. const keyeC = _keyeC;
  5784.  
  5785. let keyC = ''; // this.C = this.ST.bind(this)
  5786. let keyhj = ''; // 1000ms
  5787. try {
  5788. gkp.start.call(new Proxy({
  5789. stop: () => { },
  5790. [keyeC]: 0,
  5791. }, {
  5792. get(target, prop) {
  5793. if (prop in target) return target[prop];
  5794. if (!keyC) {
  5795. keyC = prop;
  5796. return null; // throw error
  5797. }
  5798. else if (!keyhj) {
  5799. keyhj = prop;
  5800. }
  5801.  
  5802. }
  5803. }));
  5804. } catch (e) {
  5805. if (!keyC || !keyhj) {
  5806. console.log(e)
  5807. }
  5808. }
  5809.  
  5810. if (!keyC || !keyhj) return;
  5811. let keyST = '';
  5812. let keyj = '';
  5813. let keyB = '';
  5814. let keyxa = '';
  5815.  
  5816. const possibleKs = new Set();
  5817.  
  5818. for (const [k, v] of Object.entries(gkp)) {
  5819. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  5820. continue;
  5821. }
  5822. if (typeof v === 'function') {
  5823. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  5824. if (m) {
  5825. keyST = k;
  5826. keyj = m[1];
  5827. keyB = m[2];
  5828. } else {
  5829. possibleKs.add(k);
  5830. }
  5831. }
  5832. }
  5833.  
  5834. if (!keyST || !keyj || !keyB) return;
  5835.  
  5836. for (const k of possibleKs) {
  5837. if (k === keyST || k === keyj || k === keyB) {
  5838. continue;
  5839. }
  5840. const v = gkp[k];
  5841. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  5842. keyxa = k;
  5843. }
  5844. }
  5845.  
  5846. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  5847.  
  5848. }
  5849.  
  5850. const keys = extractKeysZqQu();
  5851. if (!keys || !keys.length) return;
  5852. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  5853.  
  5854. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  5855.  
  5856. let disposeKeys = null;
  5857.  
  5858. gkp[keyxa] = function () {
  5859. // dispose
  5860. if (!disposeKeys) {
  5861. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  5862. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  5863. const t = typeof this[key];
  5864. return t === 'undefined' || t === 'object'
  5865. }
  5866. return false;
  5867. });
  5868. }
  5869. for (const key of disposeKeys) {
  5870. const v = this[key];
  5871. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  5872. }
  5873. if (this[keyeC] > 0) this.stop();
  5874. this[keyj] = null;
  5875. this[keyB] = null;
  5876. };
  5877.  
  5878. gkp.start = function (a) {
  5879. if (this[keyeC] > 0) this.stop();
  5880. const delay = void 0 !== a ? a : this[keyhj];
  5881. this[keyeC] = window.setTimeout(this[keyC], delay);
  5882. };
  5883. gkp.stop = function () {
  5884. if (this[keyeC] > 0) {
  5885. window.clearTimeout(this[keyeC]);
  5886. this[keyeC] = 0;
  5887. }
  5888. };
  5889.  
  5890. gkp.isActive = function () {
  5891. return this[keyeC] > 0;
  5892. };
  5893.  
  5894. gkp[keyST] = function () {
  5895. this.stop(); // this[keyeC] = 0;
  5896. const fn = this[keyj];
  5897. const obj = this[keyB];
  5898. let skip = false;
  5899. if (!fn) skip = true;
  5900. else if (IGNORE_bufferhealth_CHECK && obj) {
  5901. let m;
  5902. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  5903. if (m.has("bufferhealth")) skip = true;
  5904. }
  5905. }
  5906. if (!skip) {
  5907. fn.call(obj);
  5908. }
  5909. };
  5910.  
  5911.  
  5912.  
  5913.  
  5914. /*
  5915.  
  5916. g.k.eC = 0;
  5917. g.k.xa = function() {
  5918. g.Qu.Vf.xa.call(this);
  5919. this.stop();
  5920. delete this.j;
  5921. delete this.B
  5922. }
  5923. ;
  5924. g.k.start = function(a) {
  5925. this.stop();
  5926. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  5927. }
  5928. ;
  5929. g.k.stop = function() {
  5930. this.isActive() && g.Sa.clearTimeout(this.eC);
  5931. this.eC = 0
  5932. }
  5933. ;
  5934. g.k.isActive = function() {
  5935. return 0 != this.eC
  5936. }
  5937. ;
  5938. g.k.ST = function() {
  5939. this.eC = 0;
  5940. this.j && this.j.call(this.B)
  5941. }
  5942. ;
  5943. */
  5944.  
  5945.  
  5946.  
  5947.  
  5948. })();
  5949.  
  5950. FIX_Animation_n_timeline && (async () => {
  5951.  
  5952. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  5953.  
  5954. if (!timeline || !Animation) return;
  5955.  
  5956. const aniProto = Animation.prototype;
  5957. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  5958.  
  5959. const getXroto = (x) => {
  5960. try {
  5961. return x.__proto__;
  5962. } catch (e) { }
  5963. return null;
  5964. }
  5965. const timProto = getXroto(timeline);
  5966. if (!timProto) return;
  5967. if (
  5968. (
  5969. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  5970. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  5971. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  5972. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  5973. )
  5974.  
  5975. ) {
  5976.  
  5977. timProto.nofCQ = 1;
  5978. aniProto.nofYH = 1;
  5979.  
  5980. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  5981.  
  5982.  
  5983. /*
  5984. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  5985. return c._updatePromises();
  5986. });
  5987. */
  5988.  
  5989. const p = Array.prototype.filter;
  5990.  
  5991. let res = null;
  5992. Array.prototype.filter = function () {
  5993.  
  5994. res = this;
  5995. return this;
  5996.  
  5997. };
  5998.  
  5999. _updateAnimationsPromises.call({});
  6000.  
  6001. Array.prototype.filter = p;
  6002.  
  6003. if (res && typeof res.length === 'number') {
  6004. /** @type {any[]} */
  6005. const _res = res;
  6006. return _res;
  6007. }
  6008.  
  6009.  
  6010. return null;
  6011.  
  6012.  
  6013.  
  6014.  
  6015. })(timProto._updateAnimationsPromises);
  6016.  
  6017. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  6018.  
  6019. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  6020.  
  6021. aniProto._updatePromises31 = aniProto._updatePromises;
  6022.  
  6023. /*
  6024. aniProto._updatePromises = function(){
  6025. console.log('eff',this._oldPlayState, this.playState)
  6026. return this._updatePromises31.apply(this, arguments)
  6027. }
  6028. */
  6029.  
  6030. aniProto._updatePromises = function () {
  6031. var oldPlayState = this._oldPlayState;
  6032. var newPlayState = this.playState;
  6033. // console.log('ett', oldPlayState, newPlayState)
  6034. if (newPlayState !== oldPlayState) {
  6035. this._oldPlayState = newPlayState;
  6036. if (this._readyPromise) {
  6037. if ("idle" == newPlayState) {
  6038. this._rejectReadyPromise();
  6039. this._readyPromise = void 0;
  6040. } else if ("pending" == oldPlayState) {
  6041. this._resolveReadyPromise();
  6042. } else if ("pending" == newPlayState) {
  6043. this._readyPromise = void 0;
  6044. }
  6045. }
  6046. if (this._finishedPromise) {
  6047. if ("idle" == newPlayState) {
  6048. this._rejectFinishedPromise();
  6049. this._finishedPromise = void 0;
  6050. } else if ("finished" == newPlayState) {
  6051. this._resolveFinishedPromise();
  6052. } else if ("finished" == oldPlayState) {
  6053. this._finishedPromise = void 0;
  6054. }
  6055. }
  6056. }
  6057. return this._readyPromise || this._finishedPromise;
  6058. };
  6059.  
  6060.  
  6061. let restartWebAnimationsNextTickFlag = false;
  6062.  
  6063. const looperMethodT = () => {
  6064.  
  6065. const runnerFn = (hRes) => {
  6066. var b = timeline;
  6067. b.currentTime = hRes;
  6068. b._discardAnimations();
  6069. if (0 == b._animations.length) {
  6070. restartWebAnimationsNextTickFlag = false;
  6071. } else {
  6072. getRafPromise().then(runnerFn);
  6073. }
  6074. }
  6075.  
  6076. const restartWebAnimationsNextTick = () => {
  6077. if (!restartWebAnimationsNextTickFlag) {
  6078. restartWebAnimationsNextTickFlag = true;
  6079. getRafPromise().then(runnerFn);
  6080. }
  6081. }
  6082.  
  6083. return { restartWebAnimationsNextTick }
  6084. };
  6085.  
  6086.  
  6087. const looperMethodN = () => {
  6088.  
  6089. const acs = document.createElement('a-f');
  6090. acs.id = 'a-f';
  6091.  
  6092. if (!document.getElementById('afscript')) {
  6093. const style = document.createElement('style');
  6094. style.id = 'afscript';
  6095. style.textContent = `
  6096. @keyFrames aF1 {
  6097. 0% {
  6098. order: 0;
  6099. }
  6100. 100% {
  6101. order: 1;
  6102. }
  6103. }
  6104. #a-f[id] {
  6105. visibility: collapse !important;
  6106. position: fixed !important;
  6107. display: block !important;
  6108. top: -100px !important;
  6109. left: -100px !important;
  6110. margin:0 !important;
  6111. padding:0 !important;
  6112. outline:0 !important;
  6113. border:0 !important;
  6114. z-index:-1 !important;
  6115. width: 0px !important;
  6116. height: 0px !important;
  6117. contain: strict !important;
  6118. pointer-events: none !important;
  6119. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  6120. }
  6121. `;
  6122. (document.head || document.documentElement).appendChild(style);
  6123. }
  6124.  
  6125. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  6126.  
  6127. const _onanimationiteration = function (evt) {
  6128. const hRes = evt.timeStamp;
  6129. var b = timeline;
  6130. b.currentTime = hRes;
  6131. b._discardAnimations();
  6132. if (0 == b._animations.length) {
  6133. restartWebAnimationsNextTickFlag = false;
  6134. acs.onanimationiteration = null;
  6135. } else {
  6136. acs.onanimationiteration = _onanimationiteration;
  6137. }
  6138.  
  6139. }
  6140.  
  6141.  
  6142.  
  6143. const restartWebAnimationsNextTick = () => {
  6144. if (!restartWebAnimationsNextTickFlag) {
  6145. restartWebAnimationsNextTickFlag = true;
  6146. acs.onanimationiteration = _onanimationiteration;
  6147.  
  6148. }
  6149. }
  6150.  
  6151. return { restartWebAnimationsNextTick }
  6152. };
  6153.  
  6154.  
  6155.  
  6156. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  6157.  
  6158.  
  6159. // console.log(571, timProto);
  6160. timProto._play = function (c) {
  6161. c = new Animation(c, this);
  6162. this._animations.push(c);
  6163. restartWebAnimationsNextTick();
  6164. c._updatePromises();
  6165. c._animation.play();
  6166. c._updatePromises();
  6167. return c
  6168. }
  6169.  
  6170. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  6171. originalAnimationsWithPromises.length = 0;
  6172. originalAnimationsWithPromises.push = null;
  6173. originalAnimationsWithPromises.splice = null;
  6174. originalAnimationsWithPromises.slice = null;
  6175. originalAnimationsWithPromises.indexOf = null;
  6176. originalAnimationsWithPromises.unshift = null;
  6177. originalAnimationsWithPromises.shift = null;
  6178. originalAnimationsWithPromises.pop = null;
  6179. originalAnimationsWithPromises.filter = null;
  6180. originalAnimationsWithPromises.forEach = null;
  6181. originalAnimationsWithPromises.map = null;
  6182.  
  6183.  
  6184. const _updateAnimationsPromises = () => {
  6185. animationsWithPromisesMap.forEach(c => {
  6186. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  6187. });
  6188. /*
  6189. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  6190. return c._updatePromises();
  6191. });
  6192. */
  6193. }
  6194.  
  6195. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  6196.  
  6197. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  6198.  
  6199. delete timProto._updateAnimationsPromises;
  6200. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  6201. get() {
  6202. if (animationsWithPromisesMap.size === 0) return nilFn;
  6203. return _updateAnimationsPromises;
  6204. },
  6205. set(nv) {
  6206. delete this._updateAnimationsPromises;
  6207. this._updateAnimationsPromises = nv;
  6208. },
  6209. enumerable: true,
  6210. configurable: true,
  6211. });
  6212.  
  6213.  
  6214. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  6215. aniProto.__finished_native_get__ = pdFinished.get;
  6216. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  6217.  
  6218.  
  6219. Object.defineProperty(aniProto, 'finished', {
  6220. get() {
  6221. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  6222. this._finishedPromise = new Promise((resolve, reject) => {
  6223. this._resolveFinishedPromise = function () {
  6224. resolve(this)
  6225. };
  6226. this._rejectFinishedPromise = function () {
  6227. reject({
  6228. type: DOMException.ABORT_ERR,
  6229. name: "AbortError"
  6230. })
  6231. };
  6232. }),
  6233. "finished" == this.playState && this._resolveFinishedPromise());
  6234. return this._finishedPromise
  6235. },
  6236. set: undefined,
  6237. enumerable: true,
  6238. configurable: true
  6239. });
  6240.  
  6241. }
  6242.  
  6243.  
  6244.  
  6245. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  6246. aniProto.__ready_native_get__ = pdReady.get;
  6247. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  6248.  
  6249. Object.defineProperty(aniProto, 'ready', {
  6250. get() {
  6251. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  6252. this._readyPromise = new Promise((resolve, reject) => {
  6253. this._resolveReadyPromise = function () {
  6254. resolve(this)
  6255. };
  6256. this._rejectReadyPromise = function () {
  6257. reject({
  6258. type: DOMException.ABORT_ERR,
  6259. name: "AbortError"
  6260. })
  6261. };
  6262. }),
  6263. "pending" !== this.playState && this._resolveReadyPromise());
  6264. return this._readyPromise
  6265. },
  6266. set: undefined,
  6267. enumerable: true,
  6268. configurable: true
  6269. });
  6270.  
  6271. }
  6272.  
  6273.  
  6274. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  6275.  
  6276. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  6277. const _rebuildUnderlyingAnimation = function () {
  6278. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  6279. this.effect && this.effect._onsample && (this.effect._onsample = null);
  6280. return this._rebuildUnderlyingAnimation21();
  6281. }
  6282. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  6283. // delete aniProto._rebuildUnderlyingAnimation;
  6284. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  6285. // get() {
  6286. // if (isNaN(this._sequenceNumber)) return nilFn;
  6287. // return this._rebuildUnderlyingAnimation21;
  6288. // },
  6289. // set(nv) {
  6290. // delete this._rebuildUnderlyingAnimation;
  6291. // this._rebuildUnderlyingAnimation = nv;
  6292. // },
  6293. // enumerable: true,
  6294. // configurable: true
  6295. // });
  6296. }
  6297.  
  6298.  
  6299. /*
  6300.  
  6301.  
  6302. function f(c) {
  6303. var b = v.timeline;
  6304. b.currentTime = c;
  6305. b._discardAnimations();
  6306. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  6307. }
  6308. var h = window.requestAnimationFrame;
  6309. window.requestAnimationFrame = function(c) {
  6310. return h(function(b) {
  6311. v.timeline._updateAnimationsPromises();
  6312. c(b);
  6313. v.timeline._updateAnimationsPromises()
  6314. })
  6315. }
  6316. ;
  6317. v.AnimationTimeline = function() {
  6318. this._animations = [];
  6319. this.currentTime = void 0
  6320. }
  6321. ;
  6322. v.AnimationTimeline.prototype = {
  6323. getAnimations: function() {
  6324. this._discardAnimations();
  6325. return this._animations.slice()
  6326. },
  6327. _updateAnimationsPromises: function() {
  6328. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  6329. return c._updatePromises()
  6330. })
  6331. },
  6332. _discardAnimations: function() {
  6333. this._updateAnimationsPromises();
  6334. this._animations = this._animations.filter(function(c) {
  6335. return "finished" != c.playState && "idle" != c.playState
  6336. })
  6337. },
  6338. _play: function(c) {
  6339. c = new v.Animation(c,this);
  6340. this._animations.push(c);
  6341. v.restartWebAnimationsNextTick();
  6342. c._updatePromises();
  6343. c._animation.play();
  6344. c._updatePromises();
  6345. return c
  6346. },
  6347. play: function(c) {
  6348. c && c.remove();
  6349. return this._play(c)
  6350. }
  6351. };
  6352. var d = !1;
  6353. v.restartWebAnimationsNextTick = function() {
  6354. d || (d = !0,
  6355. requestAnimationFrame(f))
  6356. }
  6357. ;
  6358. var a = new v.AnimationTimeline;
  6359. v.timeline = a;
  6360. try {
  6361. Object.defineProperty(window.document, "timeline", {
  6362. configurable: !0,
  6363. get: function() {
  6364. return a
  6365. }
  6366. })
  6367. } catch (c) {}
  6368. try {
  6369. window.document.timeline = a
  6370. } catch (c) {}
  6371.  
  6372. */
  6373.  
  6374.  
  6375.  
  6376. /*
  6377.  
  6378. var g = window.getComputedStyle;
  6379. Object.defineProperty(window, "getComputedStyle", {
  6380. configurable: !0,
  6381. enumerable: !0,
  6382. value: function() {
  6383. v.timeline._updateAnimationsPromises();
  6384. var e = g.apply(this, arguments);
  6385. h() && (e = g.apply(this, arguments));
  6386. v.timeline._updateAnimationsPromises();
  6387. return e
  6388. }
  6389. });
  6390.  
  6391. */
  6392.  
  6393.  
  6394.  
  6395.  
  6396. }
  6397.  
  6398.  
  6399.  
  6400.  
  6401. })();
  6402.  
  6403. !isUrlInEmbed && Promise.resolve().then(() => {
  6404.  
  6405. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  6406.  
  6407.  
  6408.  
  6409. class LimitedSizeSet extends Set {
  6410. constructor(n) {
  6411. super();
  6412. this.limit = n;
  6413. }
  6414.  
  6415. add(key) {
  6416. if (!super.has(key)) {
  6417. super.add(key);
  6418. let n = super.size - this.limit;
  6419. if (n > 0) {
  6420. const iterator = super.values();
  6421. do {
  6422. const firstKey = iterator.next().value; // Get the first (oldest) key
  6423. super.delete(firstKey); // Delete the oldest key
  6424. } while (--n > 0)
  6425. }
  6426. }
  6427. }
  6428.  
  6429. removeAdd(key) {
  6430. super.delete(key);
  6431. this.add(key);
  6432. }
  6433.  
  6434. }
  6435.  
  6436. // const wk3 = new WeakMap();
  6437.  
  6438. // let mtxVideoId = '';
  6439. // let aje3 = [];
  6440. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  6441. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  6442. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  6443. let mtzCount = 0; // the key keeps unchanged
  6444. // let mjtNextMainKey = '';
  6445. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  6446. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  6447. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  6448. // let allowNoDelay322=false;
  6449. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  6450.  
  6451. let mpKey22 = ''; // last success continutation key & url pair
  6452. let mpUrl22 = ''; // last success continutation key & url pair
  6453. let mpKey21 = ''; // latest requested continutation key & url pair
  6454. let mpUrl21 = ''; // latest requested continutation key & url pair
  6455.  
  6456.  
  6457. async function sha1Hex(message) {
  6458. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  6459. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  6460. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  6461. const hashHex = hashArray
  6462. .map((b) => b.toString(16).padStart(2, "0"))
  6463. .join(""); // convert bytes to hex string
  6464. return hashHex;
  6465. }
  6466.  
  6467. async function continuationLog(a, ...args) {
  6468. let b = a;
  6469. try {
  6470. if (advanceLogging) b = await sha1Hex(a);
  6471. let c = args.map(e => {
  6472. return e === a ? b : e
  6473. });
  6474. console.log(...c)
  6475. } catch (e) { console.warn(e) }
  6476. }
  6477.  
  6478. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  6479.  
  6480.  
  6481. if (mfvContinuationRecorded.length > 0) {
  6482. for (const [e, d] of mfvContinuationRecorded) {
  6483. mfyContinuationIgnored.removeAdd(e);
  6484. }
  6485. toClearRecorded && mfvContinuationRecorded.clear();
  6486. }
  6487.  
  6488. }
  6489.  
  6490. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  6491.  
  6492. const tmProto = taskMgr.constructor.prototype;
  6493. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  6494.  
  6495. if (!tmProto.addJob714) {
  6496.  
  6497. tmProto.addJob714 = tmProto.addJob;
  6498.  
  6499. tmProto.addJob = function (a, b, c) {
  6500. const jobId = this.addJob714(a, b, c);
  6501. if (jobId > 0) {
  6502. // const ez = wk3.get(this);
  6503. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  6504. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  6505.  
  6506. this.__lastJobId863__ = jobId;
  6507. }
  6508. return jobId;
  6509. }
  6510.  
  6511. }
  6512.  
  6513. if (!tmProto.cancelJob714) {
  6514.  
  6515. tmProto.cancelJob714 = tmProto.cancelJob;
  6516.  
  6517. tmProto.cancelJob = function (a) {
  6518. const res = this.cancelJob714(a);
  6519. // if (a > 0) {
  6520. // for (const e of aje3) {
  6521. // if (e.jobId === a) e.cancelled = true;
  6522. // }
  6523. // }
  6524. return res;
  6525. }
  6526.  
  6527. }
  6528.  
  6529. }
  6530. }
  6531.  
  6532.  
  6533. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order;
  6534.  
  6535.  
  6536. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  6537. let dummy;
  6538. let cProto;
  6539. // let mc = 4;
  6540. // dummy = await observablePromise(() => {
  6541. // const r = document.querySelector('ytd-video-primary-info-renderer');
  6542. // if (!r) return;
  6543. // let cProto = insp(r).constructor.prototype;
  6544. // if (cProto.fetchUpdatedMetadata) return r;
  6545. // if (--mc < 0) return -1;
  6546. // return null;
  6547. // }).obtain();
  6548. dummy = document.createElement('ytd-video-primary-info-renderer');
  6549. if (!(dummy instanceof Element)) return;
  6550. // console.log(5022, dummy)
  6551. cProto = insp(dummy).constructor.prototype;
  6552.  
  6553. cProto.__getEmittorTaskMgr859__ = function () {
  6554. let taskMgr_ = null;
  6555. try {
  6556. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  6557. } catch (e) { }
  6558. return taskMgr_;
  6559. }
  6560. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  6561. // console.log(1234, cProto, cProto.is)
  6562. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  6563.  
  6564. let c_;
  6565. cProto.fetchUpdatedMetadata718 = function (a) {
  6566. // delay or immediate call the actual fetchUpdatedMetadata
  6567.  
  6568. let doImmediately = false;
  6569. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  6570.  
  6571. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  6572.  
  6573. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  6574.  
  6575. doImmediately = true;
  6576.  
  6577. }
  6578.  
  6579. if (mbCId322) {
  6580. clearTimeout(mbCId322);
  6581. mbCId322 = 0;
  6582. }
  6583.  
  6584. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  6585.  
  6586. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  6587.  
  6588. mbCId322 = setTimeout(() => {
  6589. this.fetchUpdatedMetadata717(a);
  6590. }, delay);
  6591.  
  6592. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  6593.  
  6594. }
  6595.  
  6596. cProto.fetchUpdatedMetadata = function (a) {
  6597.  
  6598. if (!pageSetupState) {
  6599. if (c_) clearTimeout(c_);
  6600. c_ = setTimeout(() => {
  6601. this.fetchUpdatedMetadata718(a);
  6602. }, 300);
  6603. return;
  6604. }
  6605.  
  6606. // pageSetupState == 0
  6607.  
  6608. try {
  6609.  
  6610. mbDelayBelowNCalls++;
  6611.  
  6612. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  6613. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  6614. }
  6615.  
  6616. // console.log('fum377', a)
  6617. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  6618. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  6619. return;
  6620. }
  6621.  
  6622. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  6623. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  6624. mjtLockPreviousKey = mjtRecordedPrevKey;
  6625. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  6626. }
  6627. // mjtNextMainKey = true;
  6628. mtzlastAllowedContinuation = '';
  6629. mtzCount = 0;
  6630. // allowNoDelay322 = false;
  6631. // fetch new metadata, cancel all previous continuations
  6632. copyPreviousContiuationToIgnored374(true);
  6633. } else if (typeof a === 'string') {
  6634. const videoPlayingId = videoPlayingY.videoId;
  6635.  
  6636. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  6637.  
  6638. let update21 = !!pageSetupVideoId;
  6639. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  6640. update21 = true;
  6641. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  6642. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  6643. return;
  6644. }
  6645. if (update21) {
  6646. mpKey21 = a;
  6647. mpUrl21 = pageSetupVideoId || videoPlayingId;
  6648. }
  6649.  
  6650. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  6651. }
  6652. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  6653. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  6654. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  6655. return this.fetchUpdatedMetadata718(a);
  6656.  
  6657. } catch (e) {
  6658. console.log('Code Error in fetchUpdatedMetadata', e);
  6659. }
  6660. return this.fetchUpdatedMetadata717(a)
  6661. }
  6662. }
  6663.  
  6664.  
  6665. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  6666. // console.log(1234, cProto, cProto.is)
  6667. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  6668. let mJob = null;
  6669.  
  6670. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  6671.  
  6672. try {
  6673.  
  6674. if (arguments.length > 0) {
  6675. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  6676. }
  6677. // mfy = mfv;
  6678.  
  6679. // mjtNextMainKey = '';
  6680. mtzlastAllowedContinuation = '';
  6681. mtzCount = 0;
  6682. if (mbCId322) {
  6683. clearTimeout(mbCId322);
  6684. mbCId322 = 0;
  6685. }
  6686. mbDelayBelowNCalls = 0;
  6687. // allowNoDelay322 = false;
  6688. copyPreviousContiuationToIgnored374(true);
  6689.  
  6690. const taskMgr = this.__getEmittorTaskMgr859__();
  6691. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  6692. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  6693. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  6694. }
  6695.  
  6696. // prevent depulicated schedule job by clearing previous JobId
  6697. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  6698.  
  6699. let res;
  6700.  
  6701. if (mJob) {
  6702. const job = mJob;
  6703. mJob = null;
  6704. console.log('cancelJob', job)
  6705. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  6706. // p.cancelJob(a,b);
  6707. }
  6708.  
  6709. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  6710.  
  6711. let pza = taskMgr.__lastJobId863__;
  6712. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  6713. let pzb = taskMgr.__lastJobId863__
  6714. if (pza !== pzb) {
  6715. mJob = pzb; // set [Interval Meta Update] jobId
  6716. }
  6717.  
  6718. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  6719. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  6720. // } else {
  6721. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  6722. // }
  6723.  
  6724. return res;
  6725.  
  6726. } else {
  6727. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  6728. }
  6729.  
  6730. } catch (e) {
  6731. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  6732. }
  6733.  
  6734.  
  6735. return this.scheduleInitialUpdatedMetadataRequest717();
  6736. }
  6737. }
  6738.  
  6739.  
  6740. });
  6741.  
  6742. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  6743. let dummy;
  6744. let cProto;
  6745. dummy = ytAppDom;
  6746. if (!(dummy instanceof Element)) return;
  6747. cProto = insp(dummy).constructor.prototype;
  6748. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  6749. // console.log(1234, cProto, cProto.is);
  6750. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  6751. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  6752. // console.log(123401, arguments);
  6753. // return this.handleServiceRequest717_(a, b, c, d);
  6754. // }
  6755.  
  6756. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  6757.  
  6758. // cProto.handleServiceRequest_ = function(a,b,c,d){
  6759. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  6760. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  6761. // console.log('mfv', c.continuation);
  6762. // mfv.add( c.continuation);
  6763. // }
  6764. // return this.handleServiceRequest717_(a,b,c,d);
  6765. // }
  6766.  
  6767. function extraArguments322(a, b, c) {
  6768. let is = (a || 0).is;
  6769. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  6770. let continuation = (c || 0).continuation;
  6771. if (typeof is !== 'string') is = null;
  6772. if (typeof videoId !== 'string') videoId = null;
  6773. if (typeof continuation !== 'string') continuation = null;
  6774. return { is, videoId, continuation };
  6775. }
  6776.  
  6777. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  6778. cProto.sendServiceAjax_ = function (a, b, c, d) {
  6779.  
  6780. // console.log(8001)
  6781. try {
  6782.  
  6783. const { is, videoId, continuation } = extraArguments322(a, b, c);
  6784.  
  6785. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  6786. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  6787. }
  6788.  
  6789. if (pageSetupVideoId && videoId && continuation) {
  6790. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  6791. mfyContinuationIgnored.removeAdd(continuation);
  6792. mfvContinuationRecorded.delete(continuation);
  6793. return;
  6794. }
  6795. }
  6796.  
  6797. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  6798. copyPreviousContiuationToIgnored374(false);
  6799. mfyContinuationIgnored.delete(continuation);
  6800. mfvContinuationRecorded.removeAdd(continuation);
  6801. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  6802. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  6803. mjtLockPreviousKey = '';
  6804. }
  6805. // if (mjtNextMainKey === continuation) {
  6806. // copyPreviousContiuationToIgnored(false);
  6807. // mfyContinuationIgnored.delete(continuation);
  6808. // mfvContinuationRecorded.add(continuation);
  6809. // }
  6810.  
  6811.  
  6812. if (mfyContinuationIgnored && continuation) {
  6813. if (mfyContinuationIgnored.has(continuation)) {
  6814. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  6815. return;
  6816. }
  6817. }
  6818.  
  6819. // console.log(59902, a?.is, b,c,d)
  6820. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  6821. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  6822. // console.log('mfv377', continuation);
  6823. mfvContinuationRecorded.add(continuation);
  6824. }
  6825.  
  6826. // if (videoId) {
  6827. // if (!pageSetupVideoId) return; // ignore page not ready
  6828. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  6829. // if (videoId !== pageSetupVideoId) {
  6830. // return;
  6831. // }
  6832. // }
  6833.  
  6834. } catch (e) {
  6835. console.log('Coding Error in sendServiceAjax_', e)
  6836. }
  6837. // console.log(8002)
  6838. // console.log(123402, arguments);
  6839. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  6840.  
  6841. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  6842. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  6843. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  6844. // get(target, prop, receiver){
  6845. // console.log('xxs99', target.videoId, mtx)
  6846. // if(prop ==='kdkw33') return 1;
  6847. // console.log(3322, prop, target)
  6848. // if(prop === 'initialDelayMs') {
  6849. // throw new Error("ABCC");
  6850. // }
  6851. // return target[prop];
  6852. // },
  6853. // set(target, prop, value, receiver){
  6854.  
  6855. // if(prop ==='kdkw33') return true;
  6856. // target[prop]=value;
  6857. // return true;
  6858. // }
  6859. // });
  6860. // }
  6861. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  6862. return this.sendServiceAjax717_(a, b, c, d);
  6863. }
  6864. }
  6865.  
  6866. function delayClearOtherKeys(lztContinuation) {
  6867. // // schedule delayed removal if mfyContinuationIgnored is not empty
  6868. // getRafPromise().then(() => {
  6869. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  6870. // // foreground page only
  6871.  
  6872. // });
  6873.  
  6874.  
  6875. if (lztContinuation !== mtzlastAllowedContinuation) return;
  6876. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  6877. if (!mfyContinuationIgnored.size) return;
  6878. if (mfyContinuationIgnored.size > 1) {
  6879. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  6880. }
  6881. mfyContinuationIgnored.forEach((value, key) => {
  6882. if (key !== lztContinuation) {
  6883. mfyContinuationIgnored.delete(key);
  6884. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  6885. }
  6886. });
  6887.  
  6888. }
  6889. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  6890. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  6891. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  6892.  
  6893. // console.log(8003)
  6894. try {
  6895.  
  6896.  
  6897. const { is, videoId, continuation } = extraArguments322(b, c, d);
  6898.  
  6899. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  6900. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  6901. }
  6902.  
  6903. if (pageSetupVideoId && videoId && continuation) {
  6904. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  6905. mfyContinuationIgnored.removeAdd(continuation);
  6906. mfvContinuationRecorded.delete(continuation);
  6907. return;
  6908. }
  6909. }
  6910.  
  6911. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  6912. copyPreviousContiuationToIgnored374(false);
  6913. mfyContinuationIgnored.delete(continuation);
  6914. mfvContinuationRecorded.removeAdd(continuation);
  6915. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  6916. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  6917. mjtLockPreviousKey = '';
  6918. }
  6919.  
  6920. // if (mjtNextMainKey === continuation) {
  6921. // copyPreviousContiuationToIgnored(false);
  6922. // mfyContinuationIgnored.delete(continuation);
  6923. // mfvContinuationRecorded.add(continuation);
  6924. // }
  6925.  
  6926. const lztContinuation = continuation;
  6927.  
  6928. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  6929. if (mfyContinuationIgnored.has(lztContinuation)) {
  6930. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  6931. return;
  6932. }
  6933. }
  6934.  
  6935. // if (videoId) {
  6936. // if (!pageSetupVideoId) return; // ignore page not ready
  6937. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  6938. // if (videoId !== pageSetupVideoId) {
  6939. // return;
  6940. // }
  6941. // }
  6942.  
  6943. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  6944. mtzlastAllowedContinuation = lztContinuation;
  6945. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  6946.  
  6947. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  6948. mjtRecordedPrevKey = lztContinuation;
  6949. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  6950. // if (mfyContinuationIgnored.size > 0) {
  6951. // delayClearOtherKeys(lztContinuation);
  6952. // }
  6953. mtzCount = 0;
  6954. // allowNoDelay322 = false;
  6955. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  6956. // repeated
  6957. if (mtzCount > 1e9) mtzCount = 1e4;
  6958. ++mtzCount;
  6959. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  6960.  
  6961. // if (mtzCount >= 3) allowNoDelay322 = true;
  6962. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  6963. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  6964. }
  6965. if (mtzCount === 5) {
  6966. mfvContinuationRecorded.clear();
  6967. mfvContinuationRecorded.add(lztContinuation);
  6968. }
  6969.  
  6970. }
  6971.  
  6972. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  6973. mpKey22 = lztContinuation;
  6974. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  6975. }
  6976.  
  6977. if (mbCId322) {
  6978. clearTimeout(mbCId322);
  6979. mbCId322 = 0;
  6980. }
  6981. } catch (e) {
  6982. console.log('Coding Error in getCancellableNetworkPromise_', e)
  6983. }
  6984.  
  6985. // console.log(8004)
  6986. // console.log(123403, arguments);
  6987. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  6988.  
  6989. // console.log(5163, a?.is,b,c,d,e);
  6990. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  6991. }
  6992. }
  6993. });
  6994.  
  6995. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  6996.  
  6997.  
  6998. FIX_ytdExpander_childrenChanged && whenCEDefined('ytd-expander').then(() => {
  6999.  
  7000. let dummy;
  7001. let cProto;
  7002.  
  7003. dummy = document.createElement('ytd-expander');
  7004. cProto = insp(dummy).constructor.prototype;
  7005.  
  7006. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  7007.  
  7008. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  7009. cProto.childrenChanged14 = cProto.childrenChanged;
  7010.  
  7011. cProto.initChildrenObserver = function () {
  7012. var a = this;
  7013. this.observer = new MutationObserver(function () {
  7014. a.childrenChanged()
  7015. }
  7016. );
  7017. this.observer.observe(this.content, {
  7018. subtree: !0,
  7019. childList: !0,
  7020. attributes: !0,
  7021. characterData: !0
  7022. });
  7023. this.childrenChanged()
  7024. }
  7025. ;
  7026. cProto.childrenChanged = function () {
  7027. if (this.alwaysToggleable) {
  7028. this.canToggle = this.alwaysToggleable;
  7029. } else if (!this.canToggleJobId) {
  7030. this.canToggleJobId = 1;
  7031. foregroundPromiseFn().then(() => {
  7032. this.canToggleJobId = 0;
  7033. this.calculateCanCollapse()
  7034. })
  7035. }
  7036. }
  7037.  
  7038. // console.log(cProto.initChildrenObserver)
  7039. console.debug('ytd-expander-fix-childrenChanged');
  7040.  
  7041. }
  7042.  
  7043. });
  7044.  
  7045.  
  7046. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  7047.  
  7048. let dummy;
  7049. let cProto;
  7050. dummy = document.createElement('paper-ripple');
  7051. cProto = insp(dummy).constructor.prototype;
  7052.  
  7053. if (fnIntegrity(cProto.animate, '0.74.5')) {
  7054.  
  7055.  
  7056. cProto.animate34 = cProto.animate;
  7057. cProto.animate = function () {
  7058. if (this._animating) {
  7059. var a;
  7060. const ripples = this.ripples;
  7061. for (a = 0; a < ripples.length; ++a) {
  7062. var b = ripples[a];
  7063. b.draw();
  7064. this.$.background.style.opacity = b.outerOpacity;
  7065. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  7066. }
  7067. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  7068. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  7069. foregroundPromiseFn().then(this._boundAnimate38);
  7070. } else {
  7071. this.onAnimationComplete();
  7072. }
  7073. }
  7074. }
  7075.  
  7076. console.debug('FIX_paper_ripple_animate')
  7077.  
  7078. // console.log(cProto.animate)
  7079.  
  7080. }
  7081.  
  7082. });
  7083.  
  7084. if (FIX_doIdomRender) {
  7085.  
  7086. const xsetTimeout = function (f, d) {
  7087. if (xsetTimeout.m511 === 1 && !d) {
  7088. xsetTimeout.m511 = 2;
  7089. xsetTimeout.m568 = f;
  7090. } else {
  7091. return setTimeout.apply(window, arguments)
  7092. }
  7093.  
  7094. }
  7095.  
  7096. /**
  7097. *
  7098. IGb = function(a) {
  7099. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  7100. c || (a.requestAninmationFrameResolver = new Vi,
  7101. c = a.requestAninmationFrameResolver.promise,
  7102. Da.requestAnimationFrame(function() {
  7103. var d;
  7104. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  7105. a.requestAninmationFrameResolver = null
  7106. }));
  7107. return c
  7108. }
  7109.  
  7110. */
  7111.  
  7112. const xrequestAnimationFrame = function (f) {
  7113. const h = f + "";
  7114. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  7115. let t = null;
  7116. xsetTimeout.m511 = 1;
  7117. f();
  7118. if (xsetTimeout.m511 === 2) {
  7119. t = xsetTimeout.m568;
  7120. xsetTimeout.m568 = null;
  7121. }
  7122. xsetTimeout.m511 = 0;
  7123. if (typeof t === 'function') {
  7124. foregroundPromiseFn().then(t);
  7125. }
  7126. } else if (h.includes("requestAninmationFrameResolver")) {
  7127. foregroundPromiseFn().then(f);
  7128. } else {
  7129. return requestAnimationFrame.apply(window, arguments);
  7130. }
  7131. }
  7132.  
  7133. let busy = false;
  7134. const doIdomRender = function () {
  7135.  
  7136. if (!this) return;
  7137. if (busy) {
  7138. return this.doIdomRender13(...arguments);
  7139. }
  7140. busy = true;
  7141. const { requestAnimationFrame, setTimeout } = window;
  7142. window.requestAnimationFrame = xrequestAnimationFrame;
  7143. window.setTimeout = xsetTimeout;
  7144. let r = this.doIdomRender13(...arguments);
  7145. window.requestAnimationFrame = requestAnimationFrame;
  7146. window.setTimeout = setTimeout;
  7147. busy = false;
  7148. return r;
  7149. };
  7150. 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']) {
  7151.  
  7152.  
  7153. whenCEDefined(ytTag).then(() => {
  7154.  
  7155. let dummy;
  7156. let cProto;
  7157. dummy = document.createElement(ytTag);
  7158. cProto = insp(dummy).constructor.prototype;
  7159.  
  7160. cProto.doIdomRender13 = cProto.doIdomRender;
  7161. cProto.doIdomRender = doIdomRender;
  7162.  
  7163. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  7164.  
  7165. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  7166.  
  7167.  
  7168.  
  7169. });
  7170.  
  7171. }
  7172.  
  7173. }
  7174.  
  7175.  
  7176.  
  7177. });
  7178.  
  7179. });
  7180.  
  7181.  
  7182.  
  7183.  
  7184. if (isMainWindow) {
  7185.  
  7186. console.groupCollapsed(
  7187. "%cYouTube JS Engine Tamer",
  7188. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  7189. );
  7190.  
  7191.  
  7192.  
  7193. console.log("Script is loaded.");
  7194. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  7195.  
  7196. console.log("This script is experimental and subject to further changes.");
  7197.  
  7198. console.log("This might boost your YouTube performance.");
  7199.  
  7200. console.log("CAUTION: This might break your YouTube.");
  7201.  
  7202.  
  7203. if (prepareLogs.length >= 1) {
  7204. console.log(" =========================================================================== ");
  7205.  
  7206. for (const msg of prepareLogs) {
  7207. console.log(msg)
  7208. }
  7209.  
  7210. console.log(" =========================================================================== ");
  7211. }
  7212.  
  7213. console.groupEnd();
  7214.  
  7215. }
  7216.  
  7217.  
  7218.  
  7219. })();