YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-07-02 提交的版本,查看 最新版本

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