YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

当前为 2024-04-28 提交的版本,查看 最新版本

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