YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

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