YouTube JS Engine Tamer

修改 YouTube 的 JS 引擎以提升性能

当前为 2025-06-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @name:ja YouTube JS Engine Tamer
  4. // @name:zh-TW YouTube JS Engine Tamer
  5. // @name:zh-CN YouTube JS Engine Tamer
  6. // @namespace UserScripts
  7. // @version 0.41.13
  8. // @match https://www.youtube.com/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @match https://studio.youtube.com/live_chat*
  11. // @license MIT
  12. // @author CY Fung
  13. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  14. // @grant none
  15. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@c2b707e4977f77792042d4a5015fb188aae4772e/library/nextBrowserTick.min.js
  16. // @run-at document-start
  17. // @unwrap
  18. // @inject-into page
  19. // @allFrames true
  20. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  21. //
  22. // @description To enhance YouTube performance by modifying YouTube JS Engine
  23. // @description:ja YouTubeのJSエンジンを変更してパフォーマンスを向上させる
  24. // @description:zh-TW 修改 YouTube 的 JS 引擎以提升效能
  25. // @description:zh-CN 修改 YouTube 的 JS 引擎以提升性能
  26. //
  27. // ==/UserScript==
  28.  
  29. (() => {
  30.  
  31. /** @type {WeakMapConstructor} */
  32. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  33.  
  34. const HOOK_ACTIVE_MODULES = true; // added in 0.37.0
  35. const HOOK_ACTIVE_MODULES_fetchUpdatedMetadata = true; // added in 0.37.0 (make likeCount update)
  36. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  37. const FIX_schedulerInstanceInstance = 2 | 4;
  38. const FIX_yt_player = true; // DONT CHANGE
  39. const FIX_Animation_n_timeline = true;
  40. const FIX_Animation_n_timeline_cinematic = true;
  41. const FIX_ytScheduler = true;
  42. const NO_PRELOAD_GENERATE_204 = false;
  43. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  44. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  45. const CHANGE_appendChild = true; // discussions#236759
  46. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  47.  
  48. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  49.  
  50. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  51.  
  52. const FIX_ytdExpander_childrenChanged = true;
  53. const FIX_paper_ripple_animate = true;
  54. const FIX_avoid_incorrect_video_meta = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  55. const FIX_avoid_incorrect_video_meta_emitterBehavior = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  56.  
  57. const FIX_doIdomRender = true;
  58.  
  59. const FIX_Shady = true;
  60.  
  61. // [[ 2024.04.24 ]]
  62. const MODIFY_ShadyDOM_OBJ = true; // DON'T CHANGE. MUST BE TRUE
  63. // << if MODIFY_ShadyDOM_OBJ >>
  64. const WEAKREF_ShadyDOM = true;
  65. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  66. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  67. // << end >>
  68.  
  69. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  70.  
  71. const FIX_ytAction_ = true; // ytd-app
  72. const FIX_onVideoDataChange = false;
  73. // const FIX_onClick = true;
  74. const FIX_onStateChange = true;
  75. const FIX_onLoopRangeChange = true;
  76. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  77. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  78.  
  79. const FIX_stampDomArray_ = true; // v0.30.0
  80. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  81. // const stampDomArray_MemoryFix_Flag001 = false;
  82. const XFlag = true; // root issue tbc
  83. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  84. // 32 required for new stampDomArray
  85. // 128 to be tested
  86.  
  87. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  88. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  89.  
  90. const FIX_Polymer_dom = true;
  91. const FIX_Polymer_AF = true;
  92.  
  93. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  94. const DEBUG_removePrune = false; // true for DEBUG
  95.  
  96. const FIX_XHR_REQUESTING = true;
  97.  
  98. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  99.  
  100. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  101.  
  102. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  103. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  104.  
  105. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  106.  
  107. const FIX_removeChild = true;
  108. const FIX_fix_requestIdleCallback_timing = true;
  109.  
  110. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  111. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  112.  
  113. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  114.  
  115. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  116.  
  117. // ------------------------------------------------------------------
  118.  
  119. const MEMORY_RELEASE_NF00 = true;
  120. const MEMORY_RELEASE_NF00_SHOW_MESSAGE = false;
  121. const MEMORY_RELEASE_MAP_SET_REMOVE_NODE = true;
  122. const FULLY_REMOVE_ALL_EVENT_LISTENERS = true; // require MEMORY_RELEASE_NF00
  123. const FUZZY_EVENT_LISTENER_REMOVAL = true;
  124. const WEAK_CE_ROOT = true; // shadowRoot of the return value of attachShadow on the node
  125.  
  126. const FIX_TEMPLATE_BINDING = true;
  127. const FIX_TEMPLATE_BINDING_SHOW_MESSAGE = false;
  128.  
  129. const FIX_SHADY_METHODS = true;
  130. const FIX_FRAGEMENT_HOST = true;
  131.  
  132. const USE_fastDomIf = 2; // fastDomIf is seem to be experimental 0 = no change, 1 = enable, 2 = disable
  133. const ENHANCE_DOMIF_createAndInsertInstance = true; // root does not need to store in the instance
  134. const ENHANCE_DOMIF_TEARDOWN = true; // require MEMORY_RELEASE_NF00
  135.  
  136. const FIX_DOM_IF_DETACH = true;
  137. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  138. const FIX_DOM_IF_TEMPLATE = true;
  139. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  140.  
  141. const DEBUG_DBR847 = false;
  142. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  143.  
  144. const FIX_ICON_RENDER = true;
  145. const FIX_GUIDE_ICON = true;
  146. const FIX_ACTIONS_TOOLTIPS = true;
  147.  
  148. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  149.  
  150. const DISABLE_isLowLatencyLiveStream = false; // TBC
  151.  
  152. const FIX_FlexibleItemSizing = true;
  153. const FIX_ROLLING_NUMBER_UPDATE = true;
  154.  
  155.  
  156. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  157. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  158. // first tp-yt-paper-dialog: show once the page is loaded.
  159. // second tp-yt-paper-dialog: click "...more"
  160. // third tp-yt-paper-dialog: click "... and 3 more links"
  161. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  162. // currently, uniqueId is preassigned by the network resolveCommand.
  163. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  164. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  165.  
  166. // handleOpenPopupAction -> createCacheKey
  167. // handleClosePopupAction_ -> createCacheKey
  168. // handleGetPopupOpenedAction_ -> createCacheKey
  169. // getAndMaybeCreatePopup_ -> createCacheKey
  170. // closePopup -> createCacheKey
  171.  
  172. // yt-close-popup-command -> handleClosePopupCommand_
  173.  
  174. // ensurePopup_ -> getAndMaybeCreatePopup_
  175.  
  176. // yt-close-popup-action -> handleClosePopupAction_
  177. // closePopup -> handleClosePopupAction_
  178. // handleOpenPopupAction -> handleClosePopupAction_
  179. // handleClosePopupCommand_ -> handleClosePopupAction_
  180. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  181.  
  182. // yt-open-popup-action -> handleOpenPopupAction
  183.  
  184.  
  185. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  186. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  187.  
  188. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  189. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  190. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  191.  
  192.  
  193. // ----------------------------- Shortkey Keyboard Control -----------------------------
  194. // dependency: FIX_yt_player
  195.  
  196. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  197. // [0] no fix - not recommended
  198. // [1] basic fix - just fix the global focus detection variable
  199. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  200. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  201.  
  202. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  203. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  204.  
  205. const PROP_OverReInclusion_AVOID = true;
  206. const PROP_OverReInclusion_DEBUGLOG = false;
  207. const PROP_OverReInclusion_LIST = new Set([
  208. 'hostElement72',
  209. 'parentComponent72',
  210. 'localVisibilityObserver_72',
  211. 'cachedProviderNode_72',
  212. '__template72',
  213. '__templatizeOwner72',
  214. '__templateInfo72',
  215. '__dataHost72',
  216. '__CE_shadowRoot72',
  217. 'elements_72',
  218.  
  219. 'ky36',
  220. 'kz62',
  221. 'm822',
  222.  
  223.  
  224.  
  225. // To be reviewed.
  226.  
  227. // chat messages
  228. 'disabled', 'allowedProps',
  229. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  230.  
  231. 'dimension', 'loadTime', 'pendingPaint',
  232.  
  233. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  234.  
  235. 'respectLangDir', 'noEndpoints',
  236.  
  237.  
  238. 'objectURL',
  239. 'buttonOverrides', 'queuedMessages',
  240. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  241. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  242. 'hoverJobId', 'JSC$14573_touched',
  243.  
  244.  
  245. // tbc
  246. 'toggleable', 'isConnected',
  247. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  248. 'disableDeselectEvent',
  249. 'emojiSize',
  250.  
  251. 'buttonOverride',
  252. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  253.  
  254. // others
  255. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  256. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  257. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  258. // 'dimension', 'loadTime', 'pendingPaint',
  259. // 'disabled', 'allowedProps',
  260.  
  261.  
  262. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  263. // 'actionMap',
  264.  
  265. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  266.  
  267. 'clearTimeout',
  268. 'switchTemplateAtRegistration', 'hasUnmounted',
  269. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  270. 'tangoConfiguration',
  271. 'itemIdToDockDurationMap',
  272. 'actionMap',
  273.  
  274. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  275. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  276. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  277.  
  278. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  279. // 'stopKeyboardEventPropagation', 'emojiSize',
  280. // 'switchTemplateAtRegistration', 'hasUnmounted',
  281. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  282. // 'isReusable', 'tangoConfiguration',
  283. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  284. // */
  285.  
  286. ]);
  287.  
  288.  
  289. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  290.  
  291. // ----------------------------- Shortkey Keyboard Control -----------------------------
  292.  
  293. /*
  294. window.addEventListener('edm',()=>{
  295. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  296. });
  297.  
  298. window.addEventListener('edn',()=>{
  299. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  300. });
  301. window.addEventListener('edr',()=>{
  302. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  303. });
  304. */
  305.  
  306. // only for macOS with Chrome/Firefox 100+
  307. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  308.  
  309. const win = this instanceof Window ? this : window;
  310.  
  311. // Create a unique key for the script and check if it is already running
  312. const hkey_script = 'jswylcojvzts';
  313. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  314. win[hkey_script] = true;
  315.  
  316.  
  317.  
  318. const wk = Symbol();
  319.  
  320. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  321.  
  322. let BY_PASS_KEYBOARD_CONTROL = false;
  323.  
  324.  
  325. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  326. /** @type {(f: ()=>{})=>{}} */
  327. const nextBrowserTick_ = nextBrowserTick;
  328. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  329. console.log('nextBrowserTick is not found.');
  330. return;
  331. }
  332.  
  333. let p59 = 0;
  334.  
  335. const Promise = (async () => { })().constructor;
  336.  
  337. const PromiseExternal = ((resolve_, reject_) => {
  338. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  339. return class PromiseExternal extends Promise {
  340. constructor(cb = h) {
  341. super(cb);
  342. if (cb === h) {
  343. /** @type {(value: any) => void} */
  344. this.resolve = resolve_;
  345. /** @type {(reason?: any) => void} */
  346. this.reject = reject_;
  347. }
  348. }
  349. };
  350. })();
  351.  
  352. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  353. constructor(callback = undefined) {
  354.  
  355. }
  356. register(target, heldValue, unregisterToken = undefined) {
  357.  
  358. }
  359. unregister(unregisterToken) {
  360.  
  361. }
  362. }
  363.  
  364. let ttpHTML = (s) => {
  365. ttpHTML = s => s;
  366. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  367. let s = s => s;
  368. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  369. }
  370. return s;
  371. }
  372.  
  373.  
  374. /** @type { typeof HTMLElement } */
  375. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  376. const nativeAppendE = HTMLElement_.prototype.append;
  377. const nativeRemoveE = HTMLElement_.prototype.remove;
  378. const DocumentFragment_ = DocumentFragment;
  379. const nativeAppendD = DocumentFragment_.prototype.append;
  380. const Node_ = Node;
  381.  
  382. /**
  383. @param {number} x
  384. @param {number} d */
  385. const toFixed2 = (x, d) => {
  386. let t = x.toFixed(d);
  387. let y = `${+t}`;
  388. return y.length > t.length ? t : y;
  389. }
  390.  
  391.  
  392. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  393.  
  394.  
  395. const TRANSLATE_DEBUG = false;
  396.  
  397.  
  398. let xdeadc00 = null; // a deteched node with __domApi
  399. let xlivec00 = null; // a deteched node with __domApi
  400.  
  401. let removeTNodeRM = null;
  402. let removeTNodeBP = false;
  403.  
  404.  
  405. if (Node.isConnectedOverrided === undefined) {
  406. const pdConnected = Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected');
  407. if (pdConnected && pdConnected.get && pdConnected.configurable) {
  408. Node.isConnectedOverrided = null;
  409. const get_ = pdConnected.get;
  410. const get = function () {
  411. const overrided = Node.isConnectedOverrided;
  412. if (typeof overrided === 'boolean') return overrided;
  413. return get_.call(this);
  414. }
  415. Object.defineProperty(Node.prototype, 'isConnected', {
  416. ...pdConnected,
  417. get
  418. });
  419. }
  420. }
  421.  
  422. const _nmSet = new Set();
  423. _nmSet.add = _nmSet.addOriginal || _nmSet.add;
  424. const _nmMap = new Set();
  425. _nmMap.add = _nmMap.addOriginal || _nmMap.add;
  426. const _nmMapV = new Set();
  427. _nmMapV.add = _nmMapV.addOriginal || _nmMapV.add;
  428. if (MEMORY_RELEASE_MAP_SET_REMOVE_NODE && !Set.prototype.addOriginal && !Map.prototype.setOriginal) {
  429. const Node_ = Node;
  430. Set.prototype.addOriginal = Set.prototype.add;
  431. Set.prototype.add = function (n) {
  432. if (n instanceof Node_) {
  433. if (!this[wk]) this[wk] = mWeakRef(this);
  434. _nmSet.add(this[wk]);
  435. }
  436. return this.addOriginal(n);
  437. };
  438. Map.prototype.setOriginal = Map.prototype.set;
  439. Map.prototype.set = function (n, v) {
  440. if (n instanceof Node_) {
  441. if (!this[wk]) this[wk] = mWeakRef(this);
  442. _nmMap.add(this[wk]);
  443. }
  444. if (v instanceof Node_) {
  445. if (!this[wk]) this[wk] = mWeakRef(this);
  446. _nmMapV.add(this[wk]);
  447. }
  448. return this.setOriginal(n, v);
  449. };
  450. }
  451.  
  452. window.showNM00 = () => {
  453. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  454. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  455. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  456. return { nmSet, nmMap, nmMapV };
  457. };
  458.  
  459. window.testNM00 = (x) => {
  460. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  461. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  462. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  463. for (const s of nmSet) if (s.has(x)) return 1;
  464. for (const m of nmMap) if (m.has(x)) return 2;
  465. for (const m of nmMapV) {
  466. for (const [u, v] of m.entries()) {
  467. if (v === x) return 4;
  468. }
  469. }
  470. return 0;
  471. };
  472.  
  473. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  474.  
  475. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  476.  
  477. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  478.  
  479. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  480.  
  481. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  482. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  483. return;
  484. }
  485.  
  486. const mapGet = Map.prototype.get;
  487. const setHas = Set.prototype.has;
  488.  
  489. /** @type {Map | null} */
  490. let qcMap = null;
  491.  
  492. Set.prototype.has = function (a) {
  493. if (a === 'dummy-4718') return false; // false to allow re-use?
  494. return setHas.call(this, a);
  495. }
  496.  
  497. Map.prototype.get = function (a) {
  498. if (a === 'dummy-4718') qcMap = this;
  499. return mapGet.call(this, a);
  500. };
  501. let r;
  502. try {
  503. r = mainCnt.createComponent_('dummy-4718', {}, true);
  504. } catch (e) {
  505.  
  506. }
  507.  
  508. Map.prototype.get = mapGet;
  509. Set.prototype.has = setHas;
  510.  
  511. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  512.  
  513.  
  514. // clearInterval(ckId);
  515. // ckId = 0;
  516.  
  517. if (qcMap !== null && qcMap instanceof Map) {
  518.  
  519. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  520. qcMap.__qcMap8781__ = true;
  521.  
  522. const setArrayC = (c) => {
  523. if (c instanceof Array) {
  524. c.length = 0;
  525. c.push = function () { };
  526. c.pop = function () { };
  527. c.shift = function () { };
  528. c.unshift = function () { };
  529. c.splice = function () { };
  530. c.sort = function () { };
  531. c.reverse = function () { };
  532. }
  533. }
  534.  
  535. const cleaning = function (m) {
  536. m.forEach(setArrayC);
  537. m.clear();
  538. }
  539.  
  540. qcMap.set = function (b, c) {
  541. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  542.  
  543. setArrayC(c);
  544.  
  545. // console.log('qcMap.set', b, c);
  546.  
  547. if (this.size > 0) {
  548. // play safe
  549.  
  550. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  551. cleaning(this);
  552. }
  553.  
  554. }
  555. qcMap.get = function (b) {
  556. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  557.  
  558. // console.log('qcMap.get', b);
  559.  
  560. if (this.size > 0) {
  561. // play safe
  562.  
  563. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  564. cleaning(this);
  565. }
  566.  
  567. }
  568.  
  569.  
  570. if (qcMap.size > 0) {
  571.  
  572. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  573. cleaning(qcMap);
  574. }
  575.  
  576. }
  577.  
  578. }
  579.  
  580. r = null;
  581. qcMap = null;
  582.  
  583. }
  584.  
  585. const renderPathMake = (elements) => {
  586. if(!elements) return;
  587. if (!elements.length) elements = [elements];
  588. const s = new Set();
  589. s.add = s.addOriginal || s.add;
  590. for (const element of elements) {
  591. if (element && element.nodeType >= 1) {
  592. s.add(element);
  593. if (element.querySelectorAll) {
  594. for (const e of element.querySelectorAll('*')) {
  595. s.add(e);
  596. }
  597. }
  598. }
  599. }
  600. const y = [...s];
  601. s.clear();
  602.  
  603. const f = (elm) => {
  604. let x = elm.nodeName.toLowerCase();
  605. let y = elm.id;
  606. return y ? `${x}#${y}` : `${x}`;
  607. }
  608. for (const element of y) {
  609. if (element && (element.nodeType >= 1) && !element.__renderPath522__) {
  610. let t = element;
  611. let w = [f(t)];
  612. if (!element.is) {
  613. while (t = t.parentNode) {
  614. w.unshift(f(t))
  615. if (t.is) break;
  616. }
  617. }
  618. element.__renderPath522__ = w.join('/');
  619. }
  620. }
  621. }
  622.  
  623.  
  624. const dispatchYtEvent = function (a, b, c, d) {
  625. d || (d = {
  626. bubbles: !0,
  627. cancelable: !1,
  628. composed: !0
  629. });
  630. c !== null && c !== void 0 && (d.detail = c);
  631. b = new CustomEvent(b, d);
  632. a.dispatchEvent(b);
  633. return b
  634. };
  635.  
  636. if (DISABLE_isLowLatencyLiveStream) {
  637. const sm = Symbol();
  638. const f = () => {
  639. try {
  640. const videoDetails = ytInitialPlayerResponse.videoDetails;
  641. if (videoDetails && videoDetails.isLowLatencyLiveStream) {
  642. videoDetails.isLowLatencyLiveStream = false;
  643. }
  644. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW') {
  645. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  646. }
  647. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  648. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  649. }
  650. } catch (e) { }
  651. }
  652. Object.defineProperty(Object.prototype, 'isLowLatencyLiveStream', {
  653. get() {
  654. const v = this[sm];
  655. if (typeof v === 'undefined') return v;
  656. f();
  657. return v;
  658. },
  659. set(nv) {
  660. f();
  661. if (nv === true) nv = false;
  662. this[sm] = nv;
  663. },
  664. enumerable: false,
  665. configurable: true
  666. });
  667.  
  668. const sm3 = Symbol();
  669. Object.defineProperty(Object.prototype, 'latencyClass', {
  670. get() {
  671. const v = this[sm3];
  672. if (typeof v === 'undefined') return v;
  673. f();
  674. return v;
  675. },
  676. set(nv) {
  677. f();
  678. if (nv === 'ULTRALOW' || nv === 'LOW') {
  679. nv = 'NORMAL';
  680. } else if (nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW' || nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  681. nv = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  682. }
  683. this[sm3] = nv;
  684. },
  685. enumerable: false,
  686. configurable: true
  687. });
  688.  
  689. }
  690.  
  691. class PlainHTMLElement extends HTMLTitleElement {
  692.  
  693. }
  694.  
  695. const removeShady = function (shady) {
  696. if (!shady || typeof shady !== 'object') return;
  697. const props = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  698. for (const prop of props) {
  699. const node = shady[prop];
  700. if (typeof (node || 0) !== 'object') continue;
  701. if (node.nodeType >= 1 && node.isConnected === false) _removedElements.addNode(node);
  702. }
  703. }
  704.  
  705. const shadys = new Set();
  706. shadys.add = shadys.addOriginal || shadys.add;
  707.  
  708. window.showShadys00 = ()=>[...shadys].map(e=>kRef(e));
  709.  
  710. const _removedElements = new Set();
  711. _removedElements.add = _removedElements.addOriginal || _removedElements.add;
  712. _removedElements.addNode_ = MEMORY_RELEASE_NF00 ? function (node) {
  713. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  714. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  715. if (!node[wk]) node[wk] = mWeakRef(node);
  716. return this.add(node[wk]);
  717. }
  718. } : () => { };
  719.  
  720. _removedElements.addNode = MEMORY_RELEASE_NF00 ? (node) => {
  721. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  722. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  723. try {
  724. const rootNode = node.getRootNode();
  725. if (rootNode && rootNode !== node) {
  726. if (rootNode.nodeType >= 1 && rootNode.nodeType !== 9) _removedElements.addNode_(rootNode);
  727. }
  728. } catch (e) { }
  729. _removedElements.addNode_(node);
  730. }
  731. } : () => { };
  732.  
  733. if (WEAK_CE_ROOT) {
  734. Object.defineProperty(Object.prototype, '__CE_shadowRoot', {
  735. get() {
  736. return kRef(this.__CE_shadowRoot366);
  737. },
  738. set(nv) {
  739. if (typeof nv !== 'object') { // null is okay
  740. if (this.__CE_shadowRoot366) this.__CE_shadowRoot366 = null;
  741. return false;
  742. }
  743. if (!nv || typeof nv !== 'object') {
  744. this.__CE_shadowRoot366 = nv;
  745. } else {
  746. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  747. this.__CE_shadowRoot366 = nv[wk];
  748. }
  749. return true;
  750. }
  751. });
  752. }
  753.  
  754. const _emptyElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  755. const _emptyTipsElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  756. const _emptyVisibilityElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  757. // const _emptyShady = new (class EmptyShady { });
  758.  
  759. const nf00 = new FinalizationRegistry_((x) => {
  760. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: node[${x}] fully removed`);
  761. });
  762. let ud00 = 0;
  763. const ng00 = new Set();
  764. nf00.registerNode = function (node) {
  765. if (node && node.nodeType >= 1) {
  766. if (!node.t792) {
  767. node.t792 = (ud00 = (ud00 & 1073741823) + 1);
  768. const x = `${node.nodeName.toLowerCase()}#${node.t792}`;
  769. this.register(node, x);
  770. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: try remove node[${x}]`);
  771. ng00.add(mWeakRef(node));
  772. }
  773. }
  774. }
  775. window.showNg00 = () => {
  776. const ng01 = new Set();
  777. ng01.add = ng01.addOriginal || ng01.add;
  778. for (const e of ng00) {
  779. const f = kRef(e);
  780. if (!f) continue;
  781. ng01.add(f);
  782. }
  783. const ng02 = [...ng01];
  784. ng01.clear();
  785. window.showNg01 = [...ng02];
  786. return window.showNg01;
  787. }
  788. window.showTemplates00 = () => {
  789. const result = {};
  790. const elements = document.querySelectorAll('*');
  791. for (const element of elements) {
  792. const tag = element.nodeName.toLocaleLowerCase();
  793. const r = result[tag] || [];
  794. const cnt = insp(element);
  795. if (cnt !== element) {
  796. if (cnt.templateInfo) {
  797. r.push(['cnt0', cnt.templateInfo, element]);
  798. }
  799. if (element._templateInfo) {
  800. r.push(['cnt1', cnt._templateInfo, element]);
  801. }
  802. if (element.__templateInfo) {
  803. r.push(['cnt2', cnt.__templateInfo, element]);
  804. }
  805. }
  806. if (element.templateInfo) {
  807. r.push(['elm0', element.templateInfo, element]);
  808. }
  809. if (element._templateInfo) {
  810. r.push(['elm1', element._templateInfo, element]);
  811. }
  812. if (element.__templateInfo) {
  813. r.push(['elm2', element.__templateInfo, element]);
  814. }
  815. if (r.length >= 1) result[tag] = r;
  816. }
  817. const strCmp = (a, b) => {
  818. if (a === b) return 0;
  819. let u = [a, b].sort();
  820. return u[0] === a ? -1 : 1;
  821. }
  822. const counting1 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[0]))].join('|')]).sort((a, b) => {
  823. return strCmp(`${a[1]}.${a[0]}`, `${b[1]}.${b[0]}`);
  824. });
  825.  
  826. const counting2 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[1]))]]);
  827.  
  828. const counting3 = Object.entries(result).map(e => {
  829. const a = [...new Set(e[1].map(t => t[1]))];
  830. const b = [...new Set(a.map(e => e.nodeList || e))];
  831.  
  832. const r = [e[0], b];
  833. return r;
  834. });
  835.  
  836. return {result, counting1, counting2, counting3};
  837. };
  838.  
  839. window.showFrag00 = function(){
  840.  
  841. const result = {};
  842. const elements = document.querySelectorAll('*');
  843. for (const element of elements) {
  844. const tag = element.nodeName.toLocaleLowerCase();
  845. const r = result[tag] || [];
  846. const cnt = insp(element);
  847. if (cnt !== element) {
  848. if (cnt.templateInfo) {
  849. r.push(['cnt0', cnt.templateInfo, element]);
  850. }
  851. if (element._templateInfo) {
  852. r.push(['cnt1', cnt._templateInfo, element]);
  853. }
  854. if (element.__templateInfo) {
  855. r.push(['cnt2', cnt.__templateInfo, element]);
  856. }
  857. }
  858. if (element.templateInfo) {
  859. r.push(['elm0', element.templateInfo, element]);
  860. }
  861. if (element._templateInfo) {
  862. r.push(['elm1', element._templateInfo, element]);
  863. }
  864. if (element.__templateInfo) {
  865. r.push(['elm2', element.__templateInfo, element]);
  866. }
  867. if (r.length >= 1) result[tag] = r;
  868. }
  869. return result;
  870.  
  871. }
  872.  
  873. const detachShadyRef = (node) => {
  874.  
  875. const shadyArr = [...shadys];
  876. for (let shady of shadyArr) {
  877. shady = kRef(shady);
  878. if (!shady) continue;
  879. const keys = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  880. for (const p of keys) {
  881. const v = keys[p];
  882. if (!v) continue;
  883. if (v instanceof Node) {
  884. if (node === v || node.contains(v)) keys[p] = _emptyElement;
  885. } else if (typeof v === 'object' && v.splice && v.length > 0) {
  886. for (let i = v.length - 1; i >= 0; i--) {
  887. const t = v[i];
  888. if (t instanceof Node) {
  889. if (node === t || node.contains(t)) v.splice(i, 1);
  890. }
  891. }
  892. }
  893. }
  894. }
  895. shadyArr.length = 0;
  896.  
  897.  
  898. }
  899.  
  900. if (MEMORY_RELEASE_NF00) {
  901.  
  902. const __removedElements = new Set();
  903. __removedElements.add = __removedElements.addOriginal || __removedElements.add;
  904.  
  905. setInterval(() => {
  906. const nodesSet = new Set();
  907. nodesSet.add = nodesSet.addOriginal || nodesSet.add;
  908.  
  909. for (const nodeWr of __removedElements) {
  910. __removedElements.delete(nodeWr);
  911. const node = kRef(nodeWr);
  912. if (node && node.nodeType >= 1 && node.isConnected === false) {
  913. let rootNode;
  914. try {
  915. rootNode = node.getRootNode();
  916. } catch (e) { }
  917. if (rootNode && rootNode.nodeType >= 1 && rootNode.nodeType !== 9 && rootNode.isConnected === true) {
  918. // do nothing
  919. } else {
  920. nodesSet.add(node);
  921. if (node.querySelectorAll) {
  922. for (const p of node.querySelectorAll('*')) {
  923. nodesSet.add(p);
  924. }
  925. }
  926. }
  927. }
  928. }
  929. for (const nodeWr of _removedElements) {
  930. _removedElements.delete(nodeWr);
  931. const node = kRef(nodeWr);
  932. if (node && node.isConnected === false) {
  933. __removedElements.add(nodeWr);
  934. }
  935. }
  936.  
  937. if(nodesSet.size === 0) return;
  938.  
  939. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  940. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  941. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  942.  
  943. for (const node of nodesSet) {
  944. if (node === _emptyElement || node.__keepInstance038__ || node.t792) continue;
  945. const hasToolTips = !!((insp(node).$ || 0).tooltip);
  946.  
  947. if (node && node.__shady_getRootNode) {
  948. let k = null;
  949. try {
  950. k = node.__shady_getRootNode();
  951. } catch { }
  952. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  953. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  954. }
  955. if (node && node.getRootNode) {
  956. const k = node.getRootNode();
  957. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  958. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  959. }
  960.  
  961. if (node.__instances) {
  962. for (const k of node.__instances) {
  963. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  964. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  965. }
  966. // node.__instances.length = 0;
  967. }
  968. if (node && node.nodeType === 1) {
  969. if (typeof insp(node).__teardownInstance === 'function') {
  970. try {
  971. insp(node).__teardownInstance();
  972. } catch (e) { }
  973. } else if (typeof node.__teardownInstance === 'function') {
  974. try {
  975. node.__teardownInstance();
  976. } catch (e) { }
  977. }
  978. }
  979. if (node && node.nodeType === 1 && node.__detachAndRemoveInstance && (node.__instances || 0).length >= 1) {
  980. for (let i = node.__instances.length - 1; i >= 0; i--) {
  981. node.__detachAndRemoveInstance(i)
  982. }
  983. }
  984.  
  985. if (node && node.nodeType === 1 && node.is === void 0) {
  986. if (typeof insp(node).dispose === 'function') {
  987. insp(node).dispose();
  988. } else if (typeof node.dispose === 'function') {
  989. node.dispose();
  990. }
  991. }
  992.  
  993. if (node && node.nodeType === 1) {
  994. if (typeof insp(node).unobserve_ === 'function') {
  995. insp(node).unobserve_();
  996. } else if (typeof node.unobserve_ === 'function') {
  997. node.unobserve_();
  998. }
  999. }
  1000.  
  1001. if (node) {
  1002. if (typeof insp(node).unobserveNodes === 'function') {
  1003. insp(node).unobserveNodes();
  1004. } else if (typeof node.unobserveNodes === 'function') {
  1005. node.unobserveNodes();
  1006. }
  1007. }
  1008.  
  1009. // if (node && node.nodeType === 1) {
  1010. // const cnt = insp(node);
  1011. // const paths = cnt.__dataLinkedPaths;
  1012. // if (paths && paths.length >= 1 && typeof cnt.unlinkPaths === 'function') {
  1013. // for (let k in paths) {
  1014. // cnt.unlinkPaths(k);
  1015. // }
  1016. // }
  1017. // }
  1018.  
  1019. const visibilityMonitorKeys = insp(node).visibilityMonitorKeys || node.visibilityMonitorKeys;
  1020. if (visibilityMonitorKeys) {
  1021. for (const entry of visibilityMonitorKeys) {
  1022. if (entry.element) { entry.element = null }
  1023. }
  1024. visibilityMonitorKeys.length = 0;
  1025. }
  1026. const __instances = node.__instances;
  1027. if (__instances) {
  1028. for (const k of __instances) {
  1029. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  1030. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  1031. }
  1032. __instances.length = 0;
  1033. }
  1034. const sp = node.__shady_parentNode;
  1035. if (sp && sp.nodeType >= 1 && sp.isConnected === false) _removedElements.addNode(sp);
  1036. FULLY_REMOVE_ALL_EVENT_LISTENERS && node.removeAllEventListener001();
  1037. if (node && node.remove) node.remove();
  1038.  
  1039. /*
  1040. if (node._templateInfo && node._templateInfo.content) {
  1041. const templateInfoContent = node._templateInfo.content;
  1042. if (templateInfoContent.nodeType >= 1 && templateInfoContent.isConnected === false) {
  1043. _removedElements.addNode(templateInfoContent);
  1044. }
  1045. try{
  1046. node._templateInfo.content = null;
  1047. }catch(e){}
  1048. }
  1049. */
  1050. if (node.__domApi) {
  1051. node.__domApi = null;
  1052. }
  1053.  
  1054. const __shady = node.__shady;
  1055. if (__shady) {
  1056. delete node.__shady;
  1057. if (shadyKey) {
  1058. const shadyRootNode = __shady[shadyKey];
  1059. if (shadyRootNode) {
  1060. // console.log(shadyRootNode);
  1061. __shady[shadyKey] = null;
  1062. for (const key of [...Object.getOwnPropertyNames(__shady), ...Object.getOwnPropertySymbols(__shady)]) {
  1063. shadyRootNode[key] = null;
  1064. }
  1065. }
  1066. }
  1067. }
  1068.  
  1069.  
  1070. const ceRoot = node.__CE_shadowRoot;
  1071. if (ceRoot) {
  1072. node.__CE_shadowRoot = null;
  1073. if (ceRoot.nodeType >= 1 && ceRoot.isConnected === false) {
  1074. _removedElements.addNode(ceRoot);
  1075. }
  1076.  
  1077. }
  1078.  
  1079. // xTeardownTemplateInfo
  1080. const snChildNodes = node.__shady_native_childNodes;
  1081. if (snChildNodes.length > 0) {
  1082. for (const node of snChildNodes) {
  1083. if (node && node.nodeType >= 1 && node.isConnected === false) {
  1084. _removedElements.addNode(node);
  1085. }
  1086. }
  1087. snChildNodes.length = 0;
  1088. }
  1089. node.__shady_native_childNodes = null;
  1090.  
  1091.  
  1092. const __templateInfo = node.__templateInfo;
  1093. if (__templateInfo) {
  1094. node.__templateInfo = null;
  1095. // xTeardownTemplateInfo(__templateInfo);
  1096. }
  1097.  
  1098. if (hasToolTips && insp(node).$) {
  1099. insp(node).$.tooltip = _emptyTipsElement;
  1100. }
  1101.  
  1102. if (node && node.nodeType >= 1) {
  1103. const pd = Object.getOwnPropertyDescriptor(node, 'visibilityMonitorKeys');
  1104. if (pd && pd.value && pd.value.length >= 1) {
  1105. const arr = pd.value;
  1106. for (let i = 0; i < arr.length; i++) {
  1107. arr[i].element = _emptyVisibilityElement;
  1108. arr[i] = null;
  1109. }
  1110. }
  1111. }
  1112.  
  1113. if (node.__dataHost) {
  1114. try {
  1115. delete node.__dataHost
  1116. } catch (e) { }
  1117. try {
  1118. node.__dataHost = null;
  1119. } catch (e) { }
  1120. }
  1121.  
  1122. if (node.root) {
  1123. try {
  1124. delete node.root
  1125. } catch (e) { }
  1126. try {
  1127. node.root = null;
  1128. } catch (e) { }
  1129. }
  1130.  
  1131. if (node.children && node.children.splice) {
  1132. try {
  1133. delete node.children
  1134. } catch (e) { }
  1135. try {
  1136. node.children = null;
  1137. } catch (e) { }
  1138. }
  1139.  
  1140. if (node.__shady && typeof node.__shady === 'object') {
  1141. try {
  1142. node.__shady = null;
  1143. } catch (e) { }
  1144. }
  1145.  
  1146. if (node.nodeType === 1) Reflect.setPrototypeOf(node, PlainHTMLElement.prototype);
  1147.  
  1148. for (const prop of Object.getOwnPropertyNames(node)) {
  1149. if (prop === 'host' && typeof (node.host || 0) === 'object') {
  1150. if (node.nodeType === 11) {
  1151. const nodeHost = node.host;
  1152. if (nodeHost && nodeHost.nodeType >= 1) {
  1153. node.host = _emptyElement;
  1154. if (nodeHost.isConnected === false && nodeHost !== _emptyElement) {
  1155. _removedElements.addNode(nodeHost);
  1156. }
  1157. } else {
  1158. node.host = null;
  1159. }
  1160. } else {
  1161. node.host = null;
  1162. }
  1163. continue;
  1164. }
  1165. const pd = Object.getOwnPropertyDescriptor(node, prop);
  1166. if (pd.value) {
  1167. const v = pd.value;
  1168. if (typeof (v || 0) === 'object') node[prop] = null;
  1169. else if (typeof (v || 0) === 'function') delete node[prop];
  1170. }
  1171. }
  1172.  
  1173. for (const prop of Object.getOwnPropertySymbols(node)) {
  1174. const v = node[prop];
  1175. if (typeof (v || 0) === 'object' && !v.deref) node[prop] = null;
  1176. }
  1177.  
  1178. if (node.__shady_native_childNodes) {
  1179. node.__shady_native_childNodes = _emptyElement.childNodes;
  1180. }
  1181. if (node.__shady_children) {
  1182. node.__shady_children = _emptyElement.children;
  1183. }
  1184.  
  1185. for (const s of nmSet) s.delete(node);
  1186. for (const m of nmMap) m.delete(node);
  1187.  
  1188. mightTeardownShadyDomWrap(node);
  1189.  
  1190. detachShadyRef(node);
  1191.  
  1192. nf00.registerNode(node);
  1193.  
  1194.  
  1195.  
  1196. // console.log(1883001, node)
  1197. // console.log(3772001, node, node.countEvent767())
  1198. }
  1199.  
  1200. nodesSet.clear();
  1201.  
  1202. }, 400);
  1203.  
  1204. }
  1205.  
  1206.  
  1207. if (FULLY_REMOVE_ALL_EVENT_LISTENERS && !EventTarget.prototype.addEventListener828 && !EventTarget.prototype.removeAllEventListener001) {
  1208. const handlerMap = new WeakMap();
  1209. EventTarget.prototype.addEventListener828 = EventTarget.prototype.addEventListener;
  1210. EventTarget.prototype.addEventListener = function (type, handler, option = void 0) {
  1211. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1212. let hds = handlerMap.get(wr);
  1213. if (!hds) handlerMap.set(wr, (hds = new Set()));
  1214. hds.add([type, handler, option]);
  1215. return this.addEventListener828(type, handler, option);
  1216. }
  1217. EventTarget.prototype.removeEventListener828 = EventTarget.prototype.removeEventListener;
  1218. EventTarget.prototype.removeEventListener = function (type, handler, option = void 0) {
  1219. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1220. let hds = handlerMap.get(wr);
  1221. if (hds) {
  1222. for (const entry of hds) {
  1223. if (entry[0] === type && entry[1] === handler) {
  1224. if (entry[2] === option) {
  1225. hds.delete(entry);
  1226. // break;
  1227. } else if (FUZZY_EVENT_LISTENER_REMOVAL) {
  1228. hds.delete(entry);
  1229. this.removeEventListener828(type, handler, entry[2]);
  1230. }
  1231. }
  1232. }
  1233. }
  1234. return this.removeEventListener828(type, handler, option);
  1235. }
  1236. EventTarget.prototype.countEvent767 = function(){
  1237. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1238. return handlerMap.get(wr);
  1239. }
  1240. EventTarget.prototype.removeAllEventListener001 = function () {
  1241. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1242. let hds = handlerMap.get(wr);
  1243. if (hds) {
  1244. handlerMap.delete(wr);
  1245. for (const entry of hds) {
  1246. const [type, handler, option] = entry;
  1247. entry.length = 0;
  1248. this.removeEventListener828(type, handler, option);
  1249. }
  1250. hds.clear();
  1251. }
  1252. }
  1253. }
  1254.  
  1255. const globalSetup = (key, setup)=>{
  1256. let symb = Symbol();
  1257. Object.defineProperty(Object.prototype, key, {
  1258. get() {
  1259. return this[symb];
  1260. },
  1261. set(nv) {
  1262. if (typeof nv !== 'function') {
  1263. this[symb] = nv;
  1264. return true;
  1265. }
  1266. if (!(symb in this)) {
  1267. setup(this);
  1268. }
  1269. this[symb] = nv;
  1270. return true;
  1271. },
  1272. configurable: true,
  1273. enumerable: false
  1274. });
  1275. }
  1276.  
  1277. const toActualNode = (e) => {
  1278. return e && e.getNode592177 ? e.getNode592177() : e;
  1279. }
  1280.  
  1281. const removeAllChildNodes = (o)=>{
  1282. if ((o instanceof Node) && o.nodeType >= 1) {
  1283. let t, q = null;
  1284. while ((t = o.firstChild) && t !== q) {
  1285. try {
  1286. t.__keepInstance038__ = false;
  1287. t.remove();
  1288. _removedElements.addNode(t);
  1289. q = t;
  1290. } catch (e) { }
  1291. }
  1292. try {
  1293. o.__keepInstance038__ = false;
  1294. o.remove();
  1295. _removedElements.addNode(o);
  1296. } catch (e) { }
  1297. }
  1298. }
  1299.  
  1300. let shadyInited = false;
  1301. let shadyKey = '';
  1302. let shadyKeyX = '';
  1303. const setupShady = () => {
  1304. shadyInited = true;
  1305. let p = document.createComment('1');
  1306. const x = document.implementation.createHTMLDocument();
  1307. const y = x.firstElementChild;
  1308. y.appendChild(p);
  1309. let key = '';
  1310. p.__shady = new Proxy({}, {
  1311. get(target, prop) {
  1312. key = prop;
  1313. throw new Error();
  1314. },
  1315. set(target, prop, val) {
  1316. throw new Error();
  1317. }
  1318. })
  1319. try {
  1320. p.__shady_getRootNode()
  1321. } catch (e) { }
  1322. let __shady = null;
  1323. try {
  1324. p.__shady = null;
  1325. p.__shady_getRootNode()
  1326. __shady = p.__shady;
  1327. } catch (e) {
  1328.  
  1329. }
  1330. y.removeChild(p);
  1331.  
  1332.  
  1333. if (0 && key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1334. const sProto = Reflect.getPrototypeOf(__shady);
  1335. const symb = Symbol('__shady');
  1336. // const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1337. Object.defineProperty(sProto, key, {
  1338. get() {
  1339. if(!this[wk]) this[wk] = mWeakRef(this);
  1340. shadys.add(this[wk]);
  1341. return kRef(this[symb]);
  1342. },
  1343. set(nv) {
  1344. if(!this[wk]) this[wk] = mWeakRef(this);
  1345. shadys.add(this[wk]);
  1346. if (typeof (nv || 0) === 'object') {
  1347. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1348. this[symb] = nv[wk];
  1349. } else {
  1350. this[symb] = nv;
  1351. }
  1352. return true;
  1353. },
  1354. enumerable: false,
  1355. configurable: true
  1356. });
  1357. shadyKey = key;
  1358. console.log('[yt-js-engine-tamer] shadyKey', key);
  1359.  
  1360. }
  1361.  
  1362.  
  1363. if (0 && key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1364. const sProto = Reflect.getPrototypeOf(__shady);
  1365. const symb = Symbol('__shady');
  1366. const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1367. Object.defineProperty(sProto, key, {
  1368. get() {
  1369. if(!this[wk]) this[wk] = mWeakRef(this);
  1370. shadys.add(this[wk]);
  1371. return kRef(this[symb]);
  1372. },
  1373. set(nv) {
  1374. if(!this[wk]) this[wk] = mWeakRef(this);
  1375. shadys.add(this[wk]);
  1376. if (typeof (nv || 0) === 'object') {
  1377. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1378. this[symb] = nv[wk];
  1379. } else {
  1380. this[symb] = nv;
  1381. }
  1382. return true;
  1383. },
  1384. enumerable: false,
  1385. configurable: true
  1386. });
  1387. shadyKey = key;
  1388. console.log('[yt-js-engine-tamer] shadyKey', key);
  1389.  
  1390. let shadyKeyCached = new Set();
  1391. const fixLastShady = () => {
  1392. const shady = lastShady;
  1393. for (const key of Object.keys(shady)) {
  1394. if (shadyKeyCached.has(key)) continue;
  1395. shadyKeyCached.add(key);
  1396. if ((typeof shady[key] === 'object') && !(shady[key] || 0).deref) {
  1397. if (!shadyKeyX && shady[key] === shady.root) {
  1398. shadyKeyX = key;
  1399. const sProto = Reflect.getPrototypeOf(shady);
  1400. const symb = Symbol();
  1401. Object.defineProperty(sProto, shadyKeyX, {
  1402. get() {
  1403. return kRef(this[symb])
  1404. },
  1405. set(nv) {
  1406. if (typeof (nv || 0) === 'object') {
  1407. nv = kRef(nv);
  1408. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1409. this[symb] = nv[wk];
  1410. } else {
  1411. this[symb] = nv;
  1412. }
  1413. return true;
  1414. },
  1415. enumerable: false,
  1416. configurable: true,
  1417. });
  1418. delete shady[key];
  1419. shady[key] = shady.root;
  1420. };
  1421. // console.log(12883, shady[key], key);
  1422. // assignedNodes, assignedSlot, ja, K, childNodes, ... (keep strong ref)
  1423. }
  1424. }
  1425. }
  1426. let lastShady = null;
  1427.  
  1428. symbKeys.forEach(key => {
  1429. const symb = Symbol(key);
  1430.  
  1431. Object.defineProperty(sProto, key, {
  1432. get() {
  1433. if (this !== lastShady && lastShady) fixLastShady();
  1434. lastShady = this;
  1435. return kRef(this[symb]);
  1436. },
  1437. set(nv) {
  1438. if (this !== lastShady && lastShady) fixLastShady();
  1439. lastShady = this;
  1440. if (typeof (nv || 0) === 'object') {
  1441. nv = kRef(nv);
  1442. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1443. this[symb] = nv[wk];
  1444. } else {
  1445. this[symb] = nv;
  1446. }
  1447. return true;
  1448. },
  1449. enumerable: false,
  1450. configurable: true
  1451. });
  1452.  
  1453. });
  1454.  
  1455. }
  1456.  
  1457.  
  1458.  
  1459. }
  1460.  
  1461. const stampedNodes = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1462. stampedNodes.set = stampedNodes.setOriginal || stampedNodes.set;
  1463. const stampedFragment = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1464. stampedFragment.set = stampedFragment.setOriginal || stampedFragment.set;
  1465.  
  1466.  
  1467. class WeakNodeC extends Node {
  1468. constructor() {
  1469. }
  1470. addEventListener(type, listener, option = void 0) {
  1471. const nodeWr = stampedNodes.get(this.eid);
  1472. const node = kRef(nodeWr);
  1473. if (!node) return;
  1474. return node.addEventListener(type, listener, option);
  1475. }
  1476. removeEventListener(type, listener, option = void 0) {
  1477. const nodeWr = stampedNodes.get(this.eid);
  1478. const node = kRef(nodeWr);
  1479. if (!node) return;
  1480. return node.removeEventListener(type, listener, option);
  1481. }
  1482. getNode592177() {
  1483. const nodeWr = stampedNodes.get(this.eid);
  1484. const node = kRef(nodeWr);
  1485. return node;
  1486. }
  1487.  
  1488. set __dataHost(nv) {
  1489. const nodeWr = stampedNodes.get(this.eid);
  1490. const node = kRef(nodeWr);
  1491. if (!node) return;
  1492. node.__dataHost = nv;
  1493. return true;
  1494. }
  1495. get __dataHost() {
  1496. const nodeWr = stampedNodes.get(this.eid);
  1497. const node = kRef(nodeWr);
  1498. if (!node) return;
  1499. return node.__dataHost;
  1500. }
  1501.  
  1502. set __dataCompoundStorage(nv) {
  1503. const nodeWr = stampedNodes.get(this.eid);
  1504. const node = kRef(nodeWr);
  1505. if (!node) return;
  1506. node.__dataCompoundStorage = nv;
  1507. return true;
  1508. }
  1509. get __dataCompoundStorage() {
  1510. const nodeWr = stampedNodes.get(this.eid);
  1511. const node = kRef(nodeWr);
  1512. if (!node) return;
  1513. return node.__dataCompoundStorage;
  1514. }
  1515.  
  1516. set __shady_className(nv) {
  1517. const nodeWr = stampedNodes.get(this.eid);
  1518. const node = kRef(nodeWr);
  1519. if (!node) return;
  1520. node.__shady_className = nv;
  1521. // debugger;
  1522. return true;
  1523. }
  1524. get __shady_className() {
  1525. const nodeWr = stampedNodes.get(this.eid);
  1526. const node = kRef(nodeWr);
  1527. if (!node) return;
  1528. return node.__shady_className;
  1529. }
  1530. }
  1531.  
  1532. if (FIX_TEMPLATE_BINDING) {
  1533. const templateMap = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1534. templateMap.set = templateMap.setOriginal || templateMap.set;
  1535. // const parsedTemplate = new Map();
  1536.  
  1537.  
  1538. const it0 = Date.now() - 80000000000;
  1539. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  1540.  
  1541.  
  1542. /*
  1543.  
  1544. M.prototype._bindTemplate = function(N, R) {
  1545. var X = this.constructor._parseTemplate(N)
  1546. , A = this.__preBoundTemplateInfo == X;
  1547. if (!A)
  1548. for (var l in X.propertyEffects)
  1549. this._createPropertyAccessor(l);
  1550. R ? (X = Object.create(X),
  1551. X.wasPreBound = A,
  1552. this.__templateInfo ? (N = N._parentTemplateInfo || this.__templateInfo,
  1553. R = N.lastChild,
  1554. X.parent = N,
  1555. N.lastChild = X,
  1556. (X.previousSibling = R) ? R.nextSibling = X : N.firstChild = X) : this.__templateInfo = X) : this.__preBoundTemplateInfo = X;
  1557. return X
  1558. }
  1559. ;
  1560. */
  1561.  
  1562. /*
  1563. ** this.constructor._parseTemplate **
  1564. d._parseTemplate = function(N, R) {
  1565. if (!N._templateInfo) {
  1566. var X = N._templateInfo = {};
  1567. X.nodeInfoList = [];
  1568. X.nestedTemplate = !!R;
  1569. X.stripWhiteSpace = R && R.stripWhiteSpace || N.hasAttribute && N.hasAttribute("strip-whitespace");
  1570. this._parseTemplateContent(N, X, {
  1571. parent: null
  1572. })
  1573. }
  1574. return N._templateInfo
  1575. }
  1576.  
  1577. */
  1578.  
  1579.  
  1580. const exceptionTriggered = new Set();
  1581. const gxx = (window.gxxC572 || (window.gxxC572 = new Set()));
  1582.  
  1583. // let initied1 = false;
  1584. // let _parseTemplateByPass = false;
  1585. const setup1 = (qxx) => {
  1586. // if(initied1) return;
  1587. // initied1 = true;
  1588. const proto = qxx;
  1589. const constructor = proto.constructor;
  1590. const _bindTemplate = proto._bindTemplate;
  1591. // console.log(12883, proto, constructor)
  1592.  
  1593.  
  1594. const _parseTemplate = constructor._parseTemplate;
  1595. if (typeof _parseTemplate === 'function' && _parseTemplate.length === 2 && !constructor._parseTemplate322) {
  1596.  
  1597. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _parseTemplate', _parseTemplate);
  1598. constructor._parseTemplate322 = _parseTemplate;
  1599. const parsedResults = new WeakMap();
  1600.  
  1601. const _templateInfoPd = {
  1602. get() {
  1603. if (!this || !this[wk]) return undefined;
  1604. const r = parsedResults.get(this[wk]);
  1605. return r;
  1606. },
  1607. set(nv) {
  1608. delete this._templateInfo;
  1609. this._templateInfo = nv;
  1610. console.warn('_templateInfoPd set');
  1611. return true;
  1612. },
  1613. enumerable: true,
  1614. configurable: true
  1615. };
  1616. constructor._parseTemplate = function (N, R) {
  1617. if (!N) return _parseTemplate.call(this, N, R);
  1618. if (!N[wk]) N[wk] = mWeakRef(N);
  1619. let r = parsedResults.get(N[wk]);
  1620. if (r) return r;
  1621. r = _parseTemplate.call(this, N, R);
  1622. if (r && !parsedResults.has(N[wk])) {
  1623. parsedResults.set(N[wk], r);
  1624. r.iAm68 = '_templateInfo';
  1625. N.iHave68 = '_templateInfo';
  1626. if (N._templateInfo && N._templateInfo === r) {
  1627. delete N._templateInfo;
  1628. if (!N._templateInfo) {
  1629. Object.defineProperty(N, '_templateInfo', _templateInfoPd);
  1630. }
  1631. }
  1632. }
  1633. return r;
  1634. }
  1635. }
  1636. if (typeof _bindTemplate === 'function' && _bindTemplate.length === 2 && !proto._bindTemplate322) {
  1637.  
  1638. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _bindTemplate', _bindTemplate);
  1639. proto._bindTemplate322 = _bindTemplate;
  1640. proto._bindTemplate = function (N, R) {
  1641. // R = boolean true or undefined
  1642. // N = template elemenet
  1643. let M = N;
  1644. if (typeof (N || 0) === 'object' && N instanceof HTMLTemplateElement && (N.content || 0).nodeType === 11) {
  1645. let componentIs = '';
  1646. try {
  1647. componentIs = this ? this.is : '';
  1648. } catch (e) { }
  1649. if (typeof (componentIs || 0) === 'string') {
  1650. if (!templateMap.has(componentIs)) {
  1651. templateMap.set(componentIs, N);
  1652. // const parser = this.constructor;
  1653. // console.log(3882, parser._parseTemplate)
  1654. /*
  1655. if (parser._parseTemplate && !parser._parseTemplate477 && parser._parseTemplate.length === 2) {
  1656. parser._parseTemplate477 = parser._parseTemplate;
  1657. const _parseTemplate477 = parser._parseTemplate477;
  1658. parser._parseTemplate = function (N, R) {
  1659. if (!_parseTemplateByPass && N && N[wk]) {
  1660. const u = parsedTemplate.get(N[wk]);
  1661. if (u) {
  1662. console.log(1838, u)
  1663. return u;
  1664. }
  1665. }
  1666. return _parseTemplate477.call(this, N, R);
  1667. };
  1668. }
  1669. if (parser._parseTemplate && parser._parseTemplate477) {
  1670. if (N && !N[wk]) N[wk] = mWeakRef(N);
  1671. if (!parsedTemplate.has(N[wk])) {
  1672. _parseTemplateByPass = true;
  1673. parsedTemplate.set(N[wk], parser._parseTemplate477(N));
  1674. _parseTemplateByPass = false;
  1675. }
  1676. }
  1677. */
  1678. } else {
  1679. M = templateMap.get(componentIs);
  1680. }
  1681. }
  1682. }
  1683. let r_ = null;
  1684. // Promise.resolve(N).then((N) => {
  1685. // console.log(3488,N.templateInfo, N.templateInfo === r_);
  1686. // })
  1687. const r = _bindTemplate.call(this, M, R);
  1688. r_ = r;
  1689. return r;
  1690. }
  1691. }
  1692.  
  1693. const _runEffectsForTemplate = proto._runEffectsForTemplate;
  1694. if (typeof _runEffectsForTemplate === 'function' && _runEffectsForTemplate.length === 4 && !proto._runEffectsForTemplate322) {
  1695. proto._runEffectsForTemplate322 = _runEffectsForTemplate;
  1696.  
  1697. // note: fastDomIf does not work well with runEffects ...
  1698. // so no runEffects actaully?
  1699. const runner = (Tw, Nw, Rw, Xw, Aw) => {
  1700.  
  1701. try {
  1702.  
  1703.  
  1704. // console.log(988003)
  1705. const T = kRef(Tw); // this
  1706. const N = kRef(Nw); // __templateInfo
  1707. if (!T || !N) return;
  1708.  
  1709. // console.log(988004)
  1710. const R = kRef(Rw); // __data
  1711. const X = kRef(Xw); // temp Data ?
  1712. const A = kRef(Aw); // boolean ?
  1713. if (typeof (X || 0) === 'object') gxx.delete(X);
  1714. if (typeof (A || 0) === 'object') gxx.delete(A);
  1715.  
  1716. // console.log(988005)
  1717. const nodeList_ = N.nodeList;
  1718.  
  1719. // console.log(988006, nodeList_)
  1720. const nodeList = nodeList_ ? nodeList_.map(e => toActualNode(e)) : nodeList_;
  1721.  
  1722. // console.log(988007, nodeList)
  1723.  
  1724. const Nx = {
  1725. propertyEffects: N.propertyEffects,
  1726. nodeList: nodeList,
  1727. firstChild: kRef(N.firstChild)
  1728. };
  1729.  
  1730. // if (kRef(N.firstChild)) {
  1731. // console.log(977001, Nx)
  1732. // }
  1733.  
  1734. // console.log(988009, Nx, R, X, A)
  1735.  
  1736.  
  1737. {
  1738.  
  1739.  
  1740. const o = Nx;
  1741. const { propertyEffects, nodeList, firstChild } = o;
  1742. if (propertyEffects && nodeList && nodeList.length >= 0) {
  1743. for (const [effectKey, propertyEffectArr] of Object.entries(propertyEffects)) {
  1744. for (let i = propertyEffectArr.length - 1; i >= 0; i--) {
  1745. const propertyEffect = propertyEffectArr[i];
  1746. const info = (propertyEffect || 0).info;
  1747. if (info && typeof info.index === 'number' && !nodeList[info.index]) {
  1748. propertyEffectArr.splice(i, 1);
  1749. }
  1750. }
  1751. }
  1752. }
  1753.  
  1754. }
  1755.  
  1756.  
  1757. // console.log({T, Nx, R, X , A })
  1758.  
  1759. // console.log(1737001, T)
  1760. // console.log(1737002, Nx)
  1761.  
  1762. // console.log(1737003, R)
  1763. // console.log(1737004, X)
  1764. // console.log(1737005, A)
  1765.  
  1766. const hostElement = T.hostElement;
  1767. const pChildren = (hostElement instanceof Node && hostElement.isConnected === true) ? [...hostElement.childNodes] : null;
  1768. renderPathMake(pChildren);
  1769.  
  1770. try {
  1771. _runEffectsForTemplate.call(T, Nx, R, X, A);
  1772.  
  1773. } catch (err) {
  1774. // debugger;
  1775. const stack = err.stack;
  1776. if (!exceptionTriggered.has(stack)) {
  1777. exceptionTriggered.add(stack);
  1778. console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`+"\n\n", err);
  1779. }
  1780. }
  1781.  
  1782. (pChildren || 0).length >= 1 && Promise.resolve(pChildren).then((pChildren) => {
  1783. for (const node of pChildren) {
  1784. if (node.parentNode !== hostElement && node.__weakNodeCId57__) {
  1785. _removedElements.addNode(node); // rn54001b
  1786. }
  1787. // if (node.isConnected === false) {
  1788. // let tNode = node;
  1789. // let pNode;
  1790. // while ((pNode = tNode.parentNode) && pNode.nodeType >= 1) {
  1791. // tNode = pNode;
  1792. // }
  1793. // // _removedElements.addNode(tNode); // rn54001
  1794. // }
  1795. }
  1796. pChildren.length = 0;
  1797. pChildren = null;
  1798. });
  1799.  
  1800.  
  1801. } catch (err) {
  1802. // debugger;
  1803. // const stack = err.stack;
  1804. // if (!exceptionTriggered.has(stack)) {
  1805. // exceptionTriggered.add(stack);
  1806. // console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`, err);
  1807. console.error(err);
  1808. // }
  1809. }
  1810.  
  1811. };
  1812.  
  1813.  
  1814. proto._runEffectsForTemplate = function (N, R, X, A) {
  1815.  
  1816. // console.log(988001)
  1817. /*
  1818. N {wasPreBound: true, nodeList: Array(23)}
  1819.  
  1820. R {showInput: false, narrow: false, menuStrings: {…}, pageDarkTheme: true, theater: false, …}
  1821. X {showInput: undefined, narrow: undefined, menuStrings: undefined, pageDarkTheme: undefined, theater: undefined, …}
  1822. A false
  1823. */
  1824.  
  1825. const Nw = (!N || typeof N !== 'object') ? N : (N[wk] || (N[wk] = mWeakRef(N))); // __templateInfo
  1826. const Xw = (!X || typeof X !== 'object') ? X : (X[wk] || (X[wk] = mWeakRef(X)));
  1827.  
  1828. const Rw = (!R || typeof R !== 'object') ? R : (R[wk] || (R[wk] = mWeakRef(R))); // __data
  1829. const Aw = (!A || typeof A !== 'object') ? A : (A[wk] || (A[wk] = mWeakRef(A)));
  1830.  
  1831. if (typeof (X || 0) === 'object') gxx.add(X);
  1832. if (typeof (A || 0) === 'object') gxx.add(A);
  1833.  
  1834. const Tw = (!this || typeof this !== 'object') ? this : (this[wk] || (this[wk] = mWeakRef(this)));
  1835.  
  1836.  
  1837. if (N.runEffects) {
  1838. N.runEffects(() => {
  1839. runner(Tw, Nw, Rw, Xw, Aw);
  1840. }, R, A);
  1841. } else {
  1842. runner(Tw, Nw, Rw, Xw, Aw);
  1843. }
  1844.  
  1845. // console.log(988002)
  1846.  
  1847. // const N_ =
  1848.  
  1849. // var l = this
  1850. // , k = function (T, W) {
  1851. // XK(l, N.propertyEffects, T, X, W, N.nodeList);
  1852. // for (var w = N.firstChild; w; w = w.nextSibling)
  1853. // l._runEffectsForTemplate(w, T, X, W)
  1854. // };
  1855. // N.runEffects ? N.runEffects(k, R, A) : k(R, A)
  1856. }
  1857.  
  1858. }
  1859.  
  1860.  
  1861. const _registerHost = proto._registerHost;
  1862. if (_registerHost && !proto._registerHost322 && _registerHost.length === 0) {
  1863. proto._registerHost322 = _registerHost;
  1864. const map = new WeakMap();
  1865. map.set = map.setOriginal || map.set;
  1866. proto._registerHost = function () {
  1867. if (!map.has(this)) {
  1868. map.set(this, (this.__dataHost || null));
  1869. Object.defineProperty(this, '__dataHost', {
  1870. get() {
  1871. return kRef(map.get(this)) || null
  1872. },
  1873. set(nv) {
  1874. const w = kRef(nv);
  1875. if (!w) {
  1876. map.set(this, null);
  1877. } else {
  1878. if (!w[wk]) w[wk] = mWeakRef(w);
  1879. let byPass = false;
  1880. if (this.is === 'ytd-masthead') byPass = true;
  1881. if (byPass) {
  1882. map.set(this, w);
  1883. } else {
  1884. map.set(this, w[wk]);
  1885. }
  1886. }
  1887. return true;
  1888. },
  1889. enumerable: true,
  1890. configurable: true
  1891. });
  1892. }
  1893. let previousDataHost = this.__dataHost;
  1894. renderPathMake(previousDataHost)
  1895. let r = _registerHost.call(this);
  1896. let currentDataHost = this.__dataHost;
  1897. if (currentDataHost !== previousDataHost) { // future use only
  1898. if (previousDataHost && previousDataHost.nodeType >= 1 && previousDataHost.isConnected === false) {
  1899. _removedElements.addNode(previousDataHost); // rn54002
  1900. }
  1901. }
  1902. return r;
  1903. }
  1904. }
  1905.  
  1906. }
  1907. globalSetup('_removeBoundDom', setup1);
  1908.  
  1909.  
  1910. /*
  1911.  
  1912. M.prototype._stampTemplate = function(N, R) {
  1913. R = R || this._bindTemplate(N, !0);
  1914. aU.push(this);
  1915. N = d.prototype._stampTemplate.call(this, N, R);
  1916. aU.pop();
  1917. R.nodeList = N.nodeList;
  1918. if (!R.wasPreBound)
  1919. for (var X = R.childNodes = [], A = N.firstChild; A; A = A.nextSibling)
  1920. X.push(A);
  1921. N.templateInfo = R;
  1922. X = R.nodeList;
  1923. A = R.nodeInfoList;
  1924. if (A.length)
  1925. for (var l = 0; l < A.length; l++) {
  1926. var k = X[l]
  1927. , T = A[l].bindings;
  1928. if (T)
  1929. for (var W = 0; W < T.length; W++) {
  1930. var w = T[W]
  1931. , p = k
  1932. , h = w;
  1933. if (h.isCompound) {
  1934. for (var I = p.__dataCompoundStorage || (p.__dataCompoundStorage = {}), O = h.parts, y = Array(O.length), c = 0; c < O.length; c++)
  1935. y[c] = O[c].literal;
  1936. O = h.target;
  1937. I[O] = y;
  1938. h.literal && h.kind == "property" && (O === "className" && (p = (0,
  1939. _.FK)(p)),
  1940. p[O] = h.literal)
  1941. }
  1942. gM2(k, this, w)
  1943. }
  1944. k.__dataHost = this
  1945. }
  1946. this.__dataClientsReady && (this._runEffectsForTemplate(R, this.__data, null, !1),
  1947. this._flushClients());
  1948. return N
  1949. }
  1950. ;
  1951.  
  1952. */
  1953.  
  1954. const wnc = new Set();
  1955.  
  1956. const __listWeakNodeC__ = window.__listWeakNodeC__ = () => {
  1957. const result = __listWeakNodeC0__();
  1958. return [...result].sort();
  1959. }
  1960.  
  1961. const __listWeakNodeC0__ = () => {
  1962. let result = new Set();
  1963. for (const nodeC of wnc) {
  1964. for (const k of Object.getOwnPropertyNames(nodeC)) {
  1965. result.add(k)
  1966. }
  1967. }
  1968. return result;
  1969. }
  1970.  
  1971. setInterval(() => {
  1972. if (wnc.size > 0 && __listWeakNodeC0__().size !== 1) console.warn(`[yt-js-engine-tamer] WARNING 0xF04E: ${__listWeakNodeC__()}`);
  1973. }, 400);
  1974.  
  1975.  
  1976. const dollarStore = new Map();
  1977.  
  1978. const makeDollarClass = (idsJoined, ids) => {
  1979. const $ = class {};
  1980. const a = $.prototype;
  1981. ids.forEach(id => {
  1982. const p = `## ${id}`;
  1983. Object.defineProperty(a, id, {
  1984. get() {
  1985. return kRef(this[p]);
  1986. },
  1987. set(nv) {
  1988. if (nv instanceof Node) {
  1989. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1990. this[p] = nv[wk];
  1991. } else {
  1992. this[p] = nv;
  1993. }
  1994. return true;
  1995. },
  1996. enumerable: true,
  1997. configurable: true
  1998. });
  1999. });
  2000. a.__w646__ = true;
  2001. dollarStore.set(idsJoined, $);
  2002. return $;
  2003. }
  2004.  
  2005. // let initied2 = false;
  2006. const setup2 = (qxx) => {
  2007. // if(initied2) return;
  2008. // initied2 = true;
  2009. const proto = qxx;
  2010. const constructor = proto.constructor;
  2011. const _stampTemplate = proto._stampTemplate;
  2012. // console.log(12883, proto, constructor)
  2013. if (typeof _stampTemplate === 'function' && _stampTemplate.length === 2 && !proto._stampTemplate374) {
  2014. proto._stampTemplate374 = _stampTemplate;
  2015. proto._stampTemplate = function (N, R) {
  2016.  
  2017. if (!shadyInited) setupShady();
  2018.  
  2019. let e__ = null;
  2020. try {
  2021. // R = boolean true or binded template
  2022. // N = template elemenet
  2023. let M = N;
  2024. let r_ = null;
  2025. const r = _stampTemplate.call(this, M, R); // return the fragment created with nodeList
  2026. r_ = r;
  2027. // if (r && r.host) {
  2028. // console.log(2883, R.host)
  2029. // }
  2030. if (r && r.$ && !r.$.__w646__) {
  2031. const $ = r.$;
  2032. const ids = Object.getOwnPropertyNames($)
  2033. const idsJoined = ids.join(' ');
  2034. const C = dollarStore.get(idsJoined) || makeDollarClass(idsJoined, ids);
  2035. const objVals = { ...$ };
  2036. Reflect.setPrototypeOf($, C.prototype);
  2037. for (const id of ids) {
  2038. delete $[id];
  2039. $[id] = objVals[id];
  2040. }
  2041. }
  2042. if (r && r.nodeType === 11 && !r.__fragId57__) {
  2043.  
  2044. const fid = genId();
  2045.  
  2046. r.__fragId57__ = fid;
  2047. if (!r[wk]) r[wk] = mWeakRef(r);
  2048. stampedFragment.set(fid, r[wk]);
  2049.  
  2050. if (r.nodeList) {
  2051. const nl = r.nodeList;
  2052. nl.__belongFragId57__ = fid;
  2053. for (let i = 0, l = nl.length; i < l; i++) {
  2054. const t = nl[i];
  2055. if (t && t.nodeType >= 1 && !(t instanceof ShadowRoot)) {
  2056. if (!t[wk]) t[wk] = mWeakRef(t);
  2057. const eid = `${fid}::${i}`;
  2058. const wn = Object.create(WeakNodeC.prototype);
  2059. wn.eid = eid;
  2060. wnc.add(wn);
  2061. nl[i] = wn;
  2062. // we believe the stampedNodes shall be attached to the document DomTree
  2063. stampedNodes.set(eid, t[wk]);
  2064. t.__weakNodeCId57__ = eid;
  2065. } else {
  2066. if (t instanceof ShadowRoot) {
  2067. console.warn('[yt-js-engine-tamer]', 'ShadowRoot in _stampTemplate');
  2068. }
  2069. }
  2070. }
  2071. }
  2072.  
  2073. }
  2074.  
  2075. return r;
  2076. } catch (e) { console.error(e); e__ = e; }
  2077. throw e__;
  2078.  
  2079. }
  2080. }
  2081. }
  2082.  
  2083. globalSetup('_addMethodEventListenerToNode', setup2);
  2084.  
  2085. }
  2086.  
  2087.  
  2088. if (FIX_FRAGEMENT_HOST && !DocumentFragment.prototype.host577) {
  2089. DocumentFragment.prototype.host577 = true;
  2090. let propsOK = false;
  2091. const finalizer = new FinalizationRegistry_((frag) => {
  2092.  
  2093. if (!frag.hostCleared55) {
  2094. frag.hostCleared55 = true;
  2095. for (const p of [...Object.getOwnPropertyNames(frag), ...Object.getOwnPropertySymbols(frag)]) {
  2096. const v = frag[p] || 0;
  2097. if (typeof v === 'object') {
  2098. frag[p] = null;
  2099. if (v.length > 0) v.length = 0;
  2100. }
  2101. }
  2102. }
  2103.  
  2104. });
  2105. Object.defineProperty(DocumentFragment.prototype, 'host', {
  2106. get() {
  2107. const r = kRef(this.host677);
  2108. if (!propsOK && this.nodeType === 11 && r) setupProps(Reflect.getPrototypeOf(this));
  2109. return r;
  2110. },
  2111. set(nv) {
  2112. nv = kRef(nv);
  2113. if (typeof (nv || 0) === 'object' && nv.nodeType === 1) {
  2114. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2115. this.host677 = nv[wk];
  2116. finalizer.register(nv, this);
  2117. } else {
  2118. this.host677 = nv;
  2119. }
  2120. return true;
  2121. },
  2122. enumerable: true,
  2123. configurable: true
  2124. });
  2125.  
  2126.  
  2127. const setupProps = (fragProto) => {
  2128.  
  2129. propsOK = true;
  2130.  
  2131. ["ownerDocument", "baseURI", "isConnected"].forEach(function (b) {
  2132.  
  2133. const pd = Object.getOwnPropertyDescriptor(fragProto, b);
  2134. const pdn = Object.getOwnPropertyDescriptor(Node.prototype, b);
  2135. const get1 = pd && pd.get;
  2136. const get2 = pdn && pdn.get;
  2137. if (get1 && get2) {
  2138. delete fragProto[b];
  2139. Object.defineProperty(fragProto, b, {
  2140. get: function () {
  2141. return this.host ? get1.call(this) : get2.call(this);
  2142. },
  2143. configurable: !0
  2144. });
  2145.  
  2146. }
  2147.  
  2148. });
  2149. }
  2150.  
  2151. }
  2152.  
  2153.  
  2154. if (XFlag) {
  2155.  
  2156. const cMap = new Set();
  2157. cMap.add = cMap.addOriginal || cMap.add;
  2158. const yMap = new Set();
  2159. yMap.add = yMap.addOriginal || yMap.add;
  2160.  
  2161.  
  2162. const ydMap = new Set();
  2163. ydMap.add = ydMap.addOriginal || ydMap.add;
  2164.  
  2165. window.yMap = yMap;
  2166. window.cMap = cMap;
  2167. window.ydMap = ydMap;
  2168.  
  2169. const constructAts = new Set();
  2170. constructAts.add = constructAts.addOriginal || constructAts.add;
  2171. window.constructAts = constructAts;
  2172.  
  2173. const kMap = new WeakMap();
  2174.  
  2175. const kRefProp = (wr, prop)=>{
  2176. let o = kRef(wr);
  2177. return o ? o[prop] : null;
  2178. }
  2179.  
  2180. const wrObj = (objRef, props) => {
  2181. let wr = mWeakRef(objRef);
  2182. if (wr === objRef || !props || !props.length) return wr;
  2183. let properties = {};
  2184. props.forEach(k => {
  2185. properties[k] = {
  2186. get() {
  2187. return kRefProp(this, k)
  2188. },
  2189. enumerable: false,
  2190. configurable: true
  2191. };
  2192. });
  2193. Object.defineProperties(wr, properties);
  2194. return wr;
  2195. }
  2196.  
  2197. const sProtos = {};
  2198.  
  2199. const setupCProto = function (cProto) {
  2200.  
  2201. if(cProto === Object.prototype) return;
  2202.  
  2203. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2204. cProto[kMap.get(cProto)] = true;
  2205. // debugger;
  2206.  
  2207. if (FIX_SHADY_METHODS && cProto.appendChild && cProto.cloneNode && cProto.contains && cProto.getRootNode && cProto.insertBefore && cProto.querySelector && cProto.querySelectorAll && cProto.removeAttribute && cProto.removeChild && cProto.replaceChild && cProto.setAttribute && cProto.is === undefined && !(cProto instanceof Node)) {
  2208. if (!cProto.krmv757) {
  2209. cProto.krmv757 = true;
  2210. // const props = Object.entries(Object.getOwnPropertyDescriptors(cProto)).filter(a => {
  2211. // const e = a[1];
  2212. // return typeof e.value === 'function' && e.writable === true && e.enumerable === true && e.configurable === true
  2213. // });
  2214. // const keys = props.map(a => a[0]);
  2215. const keys = ['querySelector', 'querySelectorAll'];
  2216. keys.forEach(key => {
  2217. if (!(key in HTMLTitleElement.prototype)) return;
  2218. const bey = `${key}588`;
  2219. cProto[bey] = cProto[key];
  2220. const isDomChange = key === 'appendChild' || key === 'insertBefore' || key === 'removeChild' || key === 'replaceChild';
  2221. cProto[key] = function () {
  2222. const p = ((this || 0).root || 0).node;
  2223. if (!isDomChange && (p instanceof Element) && p.nodeType === 1) {
  2224. return p[key](...arguments);
  2225. } else {
  2226. return this[bey](...arguments);
  2227. }
  2228. }
  2229. });
  2230. }
  2231. }
  2232.  
  2233. const constructAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  2234. constructAts.add(constructAt)
  2235.  
  2236. if (MemoryFix_Flag002 & 32) {
  2237. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  2238. fixDetachFn(cProto);
  2239. }
  2240. }
  2241.  
  2242. if (MemoryFix_Flag002 & 2) {
  2243. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  2244. cProto.__setPropDX38__ = true;
  2245.  
  2246. if (cProto._setPendingProperty.length === 3) {
  2247. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  2248. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  2249. return () => {
  2250. const obj = kRef(wobj);
  2251. let u = Reflect.apply(this, obj, args);
  2252. args.length = 0;
  2253. wobj = null;
  2254. return u;
  2255. };
  2256. });
  2257. }
  2258.  
  2259. }
  2260. }
  2261.  
  2262.  
  2263. const cProtoConstructor = cProto.constructor;
  2264.  
  2265. if (MemoryFix_Flag002 & 8) {
  2266. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  2267. cProtoConstructor.__parseBindingsDX38__ = true;
  2268.  
  2269. ydMap.add(cProtoConstructor);
  2270.  
  2271. if (cProtoConstructor._parseBindings.length === 2) {
  2272.  
  2273. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  2274.  
  2275. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  2276. let p = this._parseBindings3858(c, d);
  2277. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  2278. if (p) this.__bindingsArrs__.push(p);
  2279. return p;
  2280. });
  2281.  
  2282. }
  2283. }
  2284. }
  2285.  
  2286. /*
  2287. a.prototype._initializeProperties = function() {
  2288. if (Em && this.hasAttribute("disable-upgrade"))
  2289. this.__isUpgradeDisabled = !0;
  2290. else {
  2291. var e = Object.getPrototypeOf(this);
  2292. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  2293. e.__hasRegisterFinished = !0);
  2294. b.prototype._initializeProperties.call(this);
  2295. this.root = this;
  2296. this.created();
  2297. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  2298. this._applyListeners()
  2299. }
  2300. }
  2301. */
  2302. /*
  2303. bOa = function(a, b, c) {
  2304. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  2305. d.prototype.is = b;
  2306. d.prototype.localName = b;
  2307. c && aOa(d, c);
  2308. return function(e) {
  2309. e && (d.prototype.hostElement = e);
  2310. var g = new d;
  2311. g.root = g;
  2312. g.hostElement = e;
  2313. return g
  2314. }
  2315. }
  2316. */
  2317.  
  2318.  
  2319. }
  2320. const symDH = Symbol();
  2321.  
  2322. const wfStore = new WeakMap();
  2323.  
  2324. const wrapF = function (f, key) {
  2325. if (wfStore.get(f)) return wfStore.get(f);
  2326.  
  2327. let g = function () {
  2328. const o = kRef(this);
  2329. if (!o) return;
  2330. const cnt = insp(o);
  2331. // if (cnt === o) return;
  2332. // if (!('ready' in cnt)) return;
  2333. return f.apply(o, arguments);
  2334. };
  2335. g.key38 = key;
  2336. g.originalFunc38 = f;
  2337. g.__wrapF84__ = true;
  2338. wfStore.set(f, g);
  2339. wfStore.set(g, g);
  2340. return g;
  2341. };
  2342.  
  2343. if (MemoryFix_Flag002 & 16) {
  2344. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  2345.  
  2346. Object.defineProperty(Node.prototype, key, {
  2347. get() {
  2348. return this[`__a0939${key}__`];
  2349. },
  2350. set(nv) {
  2351. if (typeof nv !== 'function') return;
  2352. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  2353. this[`__a0939${key}__`] = g;
  2354. return true;
  2355. }
  2356. });
  2357.  
  2358.  
  2359. });
  2360. }
  2361.  
  2362.  
  2363.  
  2364. // const wm = new WeakMap();
  2365.  
  2366. const fixDetachFn = (tpProto) => { // & 32
  2367.  
  2368. if (tpProto.dk322) return;
  2369. tpProto.dk322 = true;
  2370.  
  2371. window.__fixTemplateReuse1058__ = true;
  2372.  
  2373.  
  2374. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  2375. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  2376. tpProto.__ensureTemplatized = function () {
  2377. // console.log(18470001)
  2378. return this.__ensureTemplatized994();
  2379. }
  2380. }
  2381.  
  2382.  
  2383. tpProto.__updateInstances994 = tpProto.__updateInstances;
  2384. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  2385. let bypass= false;
  2386. tpProto.__updateInstances = function (a, b, c) {
  2387.  
  2388. // const a_ = [...a];
  2389. if(!bypass && a === this.items && (a||0).length >=1 ){
  2390.  
  2391. bypass = true;
  2392. // console.log(18470002, a, b,c)
  2393. let e;
  2394. for (e = 0; e < b; e++) {
  2395. let g = this.__instances[e]
  2396. , k = c[e]
  2397. , m = a[k];
  2398. if(g && typeof (m||0) === 'object'){
  2399. // const q = g._shouldPropertyChange;
  2400. // g._shouldPropertyChange = ()=>true;
  2401. // g[this.as] = {};
  2402. // a_[k]=a[k] = m;
  2403. // g[this.as] = m;
  2404.  
  2405. // use public interface notifyPath instead of internal interface _setPendingProperty
  2406. const m_ = a[k] = Object.assign({}, a[k]);
  2407. try {
  2408. g.notifyPath(this.as, {});
  2409. } catch (e) { }
  2410. try {
  2411. g.notifyPath(this.as, m_);
  2412. } catch (e) { }
  2413.  
  2414. // g._setPendingProperty(this.as, {});
  2415. // g._setPendingProperty(this.as, m);
  2416. // g._setPendingProperty(this.indexAs, e);
  2417. // g._setPendingProperty(this.itemsIndexAs, k);
  2418. // delete g._shouldPropertyChange;
  2419. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2420. }
  2421. }
  2422. bypass = false;
  2423.  
  2424. }
  2425. const r = this.__updateInstances994(a,b,c);
  2426.  
  2427. // for (e = 0; e < b; e++) {
  2428. // let g = this.__instances[e]
  2429. // , k = c[e]
  2430. // , m = a_[k];
  2431. // if(g){
  2432. // // const q = g._shouldPropertyChange;
  2433. // // g._shouldPropertyChange = ()=>true;
  2434. // // g[this.as] = m;
  2435. // // g._setPendingProperty(this.as, {});
  2436. // // g._setPendingProperty(this.as, m);
  2437. // // g._setPendingProperty(this.indexAs, e);
  2438. // // g._setPendingProperty(this.itemsIndexAs, k);
  2439. // // delete g._shouldPropertyChange;
  2440. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2441. // }
  2442. // }
  2443.  
  2444. return r;
  2445. }
  2446. }
  2447.  
  2448. tpProto.__detachInstance994 = tpProto.__detachInstance;
  2449. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  2450. tpProto.__detachInstance = function (a) {
  2451. const u = this.__instances[a];
  2452. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2453. const children = (u || 0).children;
  2454. if (children && children.length >= 1) {
  2455. const pp = document.createDocumentFragment();
  2456. for (const s of [...children]) {
  2457. pp.appendChild(s);
  2458. }
  2459. }
  2460. try {
  2461. return this.__detachInstance994(a);
  2462. } catch (e) { }
  2463. return u;
  2464. }
  2465. }
  2466.  
  2467. tpProto.__attachInstance994 = tpProto.__attachInstance;
  2468. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  2469. tpProto.__attachInstance = function (a, b) {
  2470. const u = this.__instances[a];
  2471. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2472. if (u && u.root && b) {
  2473. const root = u.root;
  2474. const pp = document.createDocumentFragment();
  2475. pp.appendChild(root);
  2476. root.appendChild(pp);
  2477. const r = this.__attachInstance994(a, b);
  2478. if (!this.__chunkingId) this.__chunkingId = 0.25;
  2479. return r;
  2480. }
  2481. }
  2482. }
  2483.  
  2484. }
  2485.  
  2486. const ytTemplateDomEntry = (tpProto) => {
  2487.  
  2488. console.log('ytTemplateDomEntry triggered')
  2489.  
  2490.  
  2491. const convertToWeakArr = (arr) => {
  2492.  
  2493. if (arr.isWeak) return;
  2494.  
  2495. for (let i = 0, l = arr.length; i < l; i++) {
  2496. const o = arr[i]
  2497. if (o) {
  2498. let p = kRef(o)
  2499. if (!p) arr[i] = null;
  2500. else {
  2501. if (!o[wk]) o[wk] = mWeakRef(o);
  2502. arr[i] = o[wk];
  2503. }
  2504. }
  2505. }
  2506. arr.isWeak = true;
  2507.  
  2508. }
  2509.  
  2510. const convertToNormalArr = (arr) => {
  2511.  
  2512. if (!arr.isWeak) return;
  2513.  
  2514. for (let i = 0, l = arr.length; i < l; i++) {
  2515. const o = arr[i]
  2516. if (o) {
  2517. let p = kRef(o)
  2518. arr[i] = p;
  2519. }
  2520. }
  2521. arr.isWeak = false;
  2522.  
  2523. }
  2524.  
  2525. if (MemoryFix_Flag002 & 256) {
  2526. Object.defineProperty(tpProto, '__instances', {
  2527. get() {
  2528. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2529. let arr = this.__instances_actual471__;
  2530. if (arr && arr.isWeak) {
  2531. convertToNormalArr(arr);
  2532. for (let i = arr.length - 1; i >= 0; i--) {
  2533. const t = arr[i];
  2534. if (!t) arr.splice(i, 1);
  2535. else if (!t.__keepInstance038__) t.__keepInstance038__ = true;
  2536. }
  2537. Promise.resolve(arr).then(convertToWeakArr);
  2538. }
  2539. return arr;
  2540. },
  2541. set(nv) {
  2542. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2543. this.__instances_actual471__ = nv;
  2544. if (nv && !nv.isWeak) {
  2545. Promise.resolve(nv).then(convertToWeakArr);
  2546. }
  2547. return true;
  2548. },
  2549. enumerable: false,
  2550. configurable: true
  2551. });
  2552. }
  2553.  
  2554. // console.log(91901, tpProto.__detachInstance)
  2555. if (MemoryFix_Flag002 & 32) {
  2556. if (tpProto.__detachInstance) {
  2557. fixDetachFn(tpProto);
  2558. } else {
  2559. Promise.resolve(tpProto).then((tpProto) => {
  2560. // console.log(91902, tpProto.__detachInstance)
  2561. fixDetachFn(tpProto);
  2562. })
  2563. }
  2564. }
  2565.  
  2566. }
  2567.  
  2568. if (MemoryFix_Flag002 & 32) {
  2569. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  2570. set(nv) {
  2571. if (nv === true) return false;
  2572. tpProto = this;
  2573. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  2574. tpProto.__domDX37__ = true;
  2575. ytTemplateDomEntry(tpProto);
  2576. }
  2577. this.__ensureTemplatized949__ = nv;
  2578. return true;
  2579. },
  2580. get() {
  2581. return this.__ensureTemplatized949__;
  2582. }
  2583. });
  2584. }
  2585.  
  2586.  
  2587. if (MemoryFix_Flag002 & 64) {
  2588. HTMLElement_.prototype.__dataHostBinding374 = true;
  2589. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  2590. get() {
  2591. return kRef(this.__dataHostWr413__);
  2592. },
  2593. set(nv) {
  2594. if (nv && typeof nv === 'object' && !nv.deref) {
  2595. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2596. nv = nv[wk];
  2597. }
  2598. this.__dataHostWr413__ = nv;
  2599. return true;
  2600. }
  2601. });
  2602. }
  2603.  
  2604.  
  2605. const setupYProto = function (yProto) {
  2606.  
  2607. if(yProto === Object.prototype) return;
  2608.  
  2609. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2610. yProto[kMap.get(yProto)] = true;
  2611.  
  2612. if (FIX_DOM_IF_DETACH && !yProto.disconnectedCallback277 && yProto.disconnectedCallback && typeof yProto._readyClients === 'function' && typeof yProto._canApplyPropertyDefault === 'function' && typeof yProto._attachDom === 'function' && !yProto.is && typeof yProto.constructor._finalizeTemplate === 'function') {
  2613. const disconnectedCallback277 = yProto.disconnectedCallback;
  2614. yProto.disconnectedCallback277 = true;
  2615. yProto.disconnectedCallback = function () {
  2616. disconnectedCallback277.call(this);
  2617. if (this.nodeName === 'DOM-IF' && this.__instance && typeof this.__teardownInstance === 'function') {
  2618. const shadyParent = (this.__shady_parentNode || 0);
  2619. const actualParent = (this.parentNode || 0);
  2620. if (shadyParent !== actualParent && shadyParent.nodeType === 11 && actualParent.nodeType === 11) {
  2621. // && (shadyParent.compareDocumentPosition(actualParent) & (1|8|16) === 1)
  2622. // if (!this.restamp && !this.id && this.__ctor && this.isConnected === false) {
  2623. const children = (this.__instance.children || 0).length;
  2624. if (children >= 1) {
  2625. try {
  2626. this.__teardownInstance();
  2627. } catch (e) { }
  2628. }
  2629. // }
  2630. }
  2631. }
  2632. }
  2633. }
  2634.  
  2635.  
  2636. if (MemoryFix_Flag002 & 32) {
  2637. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  2638. fixDetachFn(yProto);
  2639. }
  2640. }
  2641.  
  2642. if (MemoryFix_Flag002 & 128) {
  2643. if (!yProto.__dataHostBinding374) {
  2644. yProto.__dataHostBinding374 = true;
  2645. Object.defineProperty(yProto, '__dataHost', {
  2646. set(nv) {
  2647. let dh = nv;
  2648. if (dh && typeof dh === 'object' && !dh.deref) {
  2649. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  2650. dh = wr;
  2651. }
  2652. this[symDH] = dh;
  2653. return true;
  2654. },
  2655. get() {
  2656. let wr = this[symDH];
  2657. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  2658. return obj;
  2659. },
  2660. enumerable: false,
  2661. configurable: true
  2662. });
  2663. }
  2664.  
  2665.  
  2666.  
  2667. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  2668. yProto._registerHostDX38__ = true;
  2669.  
  2670. // yProto._registerHost7133 = yProto._registerHost;
  2671.  
  2672. yProto.__enableOrFlushClients = function () {
  2673. const c_ = this.__dataPendingClients;
  2674. if (c_) {
  2675. const c = c_.slice();
  2676. c_.length = 0;
  2677. for (let d = 0, l = c.length; d < l; d++) {
  2678. let e = kRef(c[d]);
  2679. if (e) {
  2680. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  2681. }
  2682. }
  2683. }
  2684. }
  2685.  
  2686. yProto._enqueueClient = function (c) {
  2687. if (c === this || !c || typeof c !== 'object') return;
  2688. if (c.deref) c = kRef(c);
  2689. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  2690. if (!c[wk]) c[wk] = mWeakRef(c);
  2691. m.push(c[wk]);
  2692. }
  2693.  
  2694. }
  2695. }
  2696.  
  2697.  
  2698.  
  2699. }
  2700. const setupRendering = function () {
  2701.  
  2702. const cnt = this;
  2703. const cProto = Reflect.getPrototypeOf(cnt);
  2704. let yProto = Reflect.getPrototypeOf(cProto);
  2705.  
  2706. const yProtos = new Set();
  2707.  
  2708. if (!yMap.has(yProto)) {
  2709. // capture all ancenstor constructors of a and b (non-specific component type)
  2710.  
  2711. do {
  2712. if (yProto === Object.prototype || yProto === null) break;
  2713. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  2714. yProtos.add(yProto);
  2715. yProto = Reflect.getPrototypeOf(yProto);
  2716. } while (!yProtos.has(yProto));
  2717.  
  2718. for (const yProto of yProtos) {
  2719. yMap.add(yProto);
  2720. setupYProto(yProto)
  2721. }
  2722.  
  2723. }
  2724.  
  2725.  
  2726. if (!cMap.has(cProto)) {
  2727. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  2728. setupCProto(cProto);
  2729. }
  2730.  
  2731. }
  2732.  
  2733. /*
  2734.  
  2735. jF = function(M) {
  2736. var d = YNV.call(this) || this;
  2737. d._configureProperties(M);
  2738. d.root = d._stampTemplate(d.__dataHost);
  2739. var N = [];
  2740. d.children = N;
  2741. for (var R = d.root.firstChild; R; R = R.nextSibling)
  2742. N.push(R),
  2743. R.__templatizeInstance = d;
  2744. d.__templatizeOwner && d.__templatizeOwner.__hideTemplateChildren__ && d._showHideChildren(!0);
  2745. N = d.__templatizeOptions;
  2746. (M && N.instanceProps || !N.instanceProps) && d._enableProperties();
  2747. return d
  2748. };
  2749. */
  2750.  
  2751. const sb1 = Symbol();
  2752. Object.defineProperty(Object.prototype, 'root', {
  2753. get() {
  2754. return this[sb1];
  2755. },
  2756. set(nv){
  2757. const p = this ? kRef(this) : null;
  2758. const mv = nv ? kRef(nv) : null;
  2759.  
  2760. // if (typeof (this.host || 0) === 'object' && !this.host6833) {
  2761. // const host = this.host;
  2762. // if (!host[wk]) host[wk] = mWeakRef(host);
  2763. // this.host6833 = host[wk];
  2764. // delete this.host;
  2765. // console.log(21883, host)
  2766. // Object.defineProperty(this, 'host', {
  2767. // get() {
  2768. // return kRef(this.host6833);
  2769. // },
  2770. // set(nv) {
  2771. // if (!nv) {
  2772. // this.host6833 = nv;
  2773. // } else {
  2774. // if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2775. // this.host6833 = nv[wk];
  2776. // }
  2777. // return true;
  2778. // }, enumerable: false, configurable: true
  2779. // });
  2780. // }
  2781.  
  2782. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2783. p.__setupRendered399__ = true;
  2784. setupRendering.call(p);
  2785. }
  2786. if (mv && mv.is && !mv.__setupRendered399__) {
  2787. mv.__setupRendered399__ = true;
  2788. setupRendering.call(mv);
  2789. }
  2790.  
  2791. this[sb1] = nv;
  2792. return true;
  2793. }
  2794. });
  2795.  
  2796.  
  2797. }
  2798.  
  2799. let _cssSheet = null;
  2800. const addNewCSS = typeof CSSStyleSheet !== 'undefined' && document.adoptedStyleSheets ? (css) => {
  2801. if (!_cssSheet) {
  2802. _cssSheet = new CSSStyleSheet();
  2803. document.adoptedStyleSheets.push(_cssSheet);
  2804. }
  2805. _cssSheet.insertRule(`${css}`);
  2806. } : (css) => {
  2807. let nonce = document.querySelector('style[nonce]');
  2808. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2809. const st = document.createElement('style');
  2810. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2811. st.textContent = `${css}`;
  2812. let parent;
  2813. if (parent = document.head) parent.appendChild(st);
  2814. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  2815. }
  2816.  
  2817. function getTranslate() {
  2818.  
  2819. pLoad.then(() => {
  2820. addNewCSS(".yt-formatted-string-block-line{display:block;}");
  2821. });
  2822.  
  2823. const snCache = new Map();
  2824.  
  2825. if (TRANSLATE_DEBUG) {
  2826. console.log(11)
  2827. }
  2828.  
  2829. /** @type {(str: string?) => string} */
  2830. function _snippetText(str) {
  2831. // str can be underfinded
  2832. if (!str || typeof str !== 'string') return '';
  2833. let res = snCache.get(str);
  2834. if (res === undefined) {
  2835. let b = false;
  2836. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  2837. b = true;
  2838. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  2839. });
  2840. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  2841. b = true;
  2842. return '';
  2843. });
  2844. if (b) {
  2845. snCache.set(str, res);
  2846. snCache.set(res, null);
  2847. } else {
  2848. res = null;
  2849. snCache.set(str, null);
  2850. }
  2851. }
  2852. return res === null ? str : res;
  2853. }
  2854.  
  2855. /** @type {(snippet: Object) => string} */
  2856. function snippetText(snippet) {
  2857. let runs = snippet.runs;
  2858. const n = runs.length;
  2859. if (n === 1) return _snippetText(runs[0].text);
  2860. let res = new Array(n);
  2861. let ci = 0;
  2862. for (const s of runs) {
  2863. res[ci++] = _snippetText(s.text);
  2864. }
  2865. return res.join('\n');
  2866. }
  2867.  
  2868. const _DEBUG_szz = (t) => t.map(x => {
  2869. const tsr = x.transcriptSegmentRenderer;
  2870. return ({
  2871. t: tsr.snippet.runs.map(x => x.text).join('//'),
  2872. a: tsr.startMs,
  2873. b: tsr.endMs
  2874. });
  2875. });
  2876.  
  2877. const fixRuns = (runs) => {
  2878. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  2879. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  2880. const text = runs[0].text;
  2881. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  2882. const s = text.split(nlc);
  2883. let bi = 0;
  2884. runs.length = s.length;
  2885. for (const text of s) {
  2886. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  2887. }
  2888. }
  2889. for (const s of runs) {
  2890. s.text = _snippetText(s.text);
  2891. }
  2892. }
  2893.  
  2894. function translate(initialSegments) {
  2895. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  2896.  
  2897. if (!initialSegments) return initialSegments;
  2898.  
  2899. if (TRANSLATE_DEBUG) {
  2900. console.log(12);
  2901. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  2902. let obj = JSON.parse(r);
  2903. console.log(7558, 1, obj)
  2904. return obj;
  2905. }).then(p => {
  2906. let obj = _DEBUG_szz(p)
  2907. console.log(7558, 2, obj)
  2908. })
  2909. }
  2910.  
  2911.  
  2912. //let mapRej = new WeakSet();
  2913.  
  2914. const n1 = initialSegments.length;
  2915. if (!n1) return fRes;
  2916. let n2 = 0;
  2917.  
  2918.  
  2919. const fRes = new Array(n1);
  2920. // -----------------------------------------------------------------------------------------
  2921.  
  2922. const s8 = Symbol();
  2923.  
  2924. {
  2925.  
  2926. /** @type {Map<String, Object>} */
  2927. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  2928.  
  2929. // /-* * @type {Map<String, number>} *-/
  2930. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  2931. // 1: ok
  2932. // 2: abandoned effect text
  2933.  
  2934. for (const initialSegment of initialSegments) {
  2935. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  2936. if (!transcript) {
  2937. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2938. fRes[n2++] = initialSegment;
  2939. continue;
  2940. }
  2941. const runs = transcript.snippet.runs
  2942. if (!runs || runs.length === 0) {
  2943. initialSegment[s8] = true;
  2944. continue;
  2945. }
  2946. let startMs = (+transcript.startMs || 0); //integer
  2947. let endMs = (+transcript.endMs || 0); //integer
  2948. if (startMs === endMs) {
  2949. // effect text
  2950. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2951. //mapRej.add(initialSegment)
  2952. continue;
  2953. }
  2954. if (endMs - startMs < 30) {
  2955. continue;
  2956. }
  2957. const text = snippetText(transcript.snippet);
  2958. const hEntry = cacheTexts.get(text);
  2959. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  2960. if (mh1e === 2) continue;
  2961. const entry = {
  2962. startMs,
  2963. endMs,
  2964. initialSegment,
  2965. text
  2966. };
  2967. if (mh1e === 0) {
  2968. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  2969. initialSegment[s8] = true;
  2970. cacheTexts.set(text, null);
  2971. //effect only
  2972. // https://www.youtube.com/watch?v=zLak0dxBKpM
  2973. //mapRej.add(initialSegment)
  2974. continue;
  2975. }
  2976. } else if (hEntry) {
  2977.  
  2978. const timeDiff = entry.startMs - hEntry.endMs;
  2979. let shouldMerge = false;
  2980.  
  2981. if (timeDiff >= 0) {
  2982.  
  2983. if (timeDiff < 25) {
  2984. shouldMerge = true;
  2985. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  2986. shouldMerge = true;
  2987. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  2988. shouldMerge = true;
  2989. }
  2990.  
  2991. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  2992. // abandon the current entry.
  2993. // absorbed by previous entry
  2994. hEntry.endMs = entry.endMs;
  2995. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2996. //mapRej.add(entry.initialSegment);
  2997. continue;
  2998. }
  2999.  
  3000. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  3001.  
  3002. // abandon the current entry.
  3003. // absorbed by previous entry
  3004. if (entry.endMs > hEntry.endMs) {
  3005. hEntry.endMs = entry.endMs;
  3006. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  3007. }
  3008. //mapRej.add(entry.initialSegment);
  3009. continue;
  3010.  
  3011. }
  3012.  
  3013. }
  3014. //if not abandoned
  3015. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  3016. // for (const s of runs) {
  3017. // s.text = _snippetText(s.text);
  3018. // }
  3019. fixRuns(runs);
  3020. fRes[n2++] = initialSegment;
  3021. }
  3022.  
  3023. // cacheTexts.clear(); // let GC do it.
  3024. cacheTexts = null;
  3025. // mh1.clear(); // let GC do it.
  3026. // mh1 = null;
  3027.  
  3028. }
  3029.  
  3030. const si_length = fRes.length = n2;
  3031. const sj_length = n1;
  3032.  
  3033. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  3034. // collect the abandon text to become second subtitle
  3035.  
  3036. let sj_start = 0;
  3037. let invalid_sj = -1;
  3038. for (let si = 0; si < si_length; si++) {
  3039. const segment = fRes[si];
  3040. let transcript = segment.transcriptSegmentRenderer;
  3041. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  3042. const runs = transcript.snippet.runs;
  3043. // fixRuns(runs);
  3044. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  3045. const main_startMs = (+transcript.startMs || 0);
  3046. const main_endMs = (+transcript.endMs || 0);
  3047. transcript = null;
  3048.  
  3049. /** @type {Map<string, number>} */
  3050. let tMap = new Map(); // avoid duplicate with javascript object properties
  3051.  
  3052. // assume that it is asc-ordered array of key startMs;
  3053. for (let sj = sj_start; sj < sj_length; sj++) {
  3054. const initialSegment = initialSegments[sj];
  3055.  
  3056. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  3057.  
  3058. const tSegment = initialSegment.transcriptSegmentRenderer;
  3059.  
  3060. if (!tSegment) {
  3061. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  3062. invalid_sj = sj; // should invalid_sj be set ?
  3063. continue;
  3064. }
  3065.  
  3066. const startMs = (+tSegment.startMs || 0)
  3067. const isStartValid = startMs >= main_startMs;
  3068. if (!isStartValid) {
  3069. invalid_sj = sj;
  3070. continue;
  3071. }
  3072. // isStartValid must be true
  3073. if (startMs > main_endMs) {
  3074. sj_start = invalid_sj + 1;
  3075. break;
  3076. }
  3077.  
  3078. const endMs = (+tSegment.endMs || 0)
  3079. if (endMs <= main_endMs) {
  3080. const mt = snippetText(tSegment.snippet);
  3081. const prev = tMap.get(mt);
  3082. if (endMs >= startMs) {
  3083. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  3084. }
  3085. }
  3086.  
  3087. }
  3088.  
  3089. if (tMap.size <= 1) continue; // no second line
  3090. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  3091. tMap = null;
  3092.  
  3093. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  3094.  
  3095. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  3096.  
  3097. let targetZ = rg[1][1];
  3098. if (targetZ > 4) {
  3099. let az = 0;
  3100. let fail = false;
  3101. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  3102. az += rg[idx][1];
  3103. if (az >= targetZ) {
  3104. fail = true;
  3105. break;
  3106. }
  3107. }
  3108. if (!fail) {
  3109. const rgA = rg[0][0];
  3110. const rgB = rg[1][0];
  3111. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  3112. if (isDiff && rgA === _snippetText(runs[0].text)) {
  3113. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  3114. runs.push({ text: rgB, blockLine: true });
  3115. }
  3116. }
  3117. }
  3118. rg = null;
  3119. }
  3120.  
  3121. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  3122.  
  3123. let obj = r;
  3124. console.log(7559, 1, obj)
  3125. return obj;
  3126. }).then(p => {
  3127. let obj = _DEBUG_szz(p)
  3128. console.log(7559, 2, obj)
  3129.  
  3130. });
  3131. }
  3132.  
  3133. // -----------------------------------------------------------------------------------------
  3134. snCache.clear();
  3135. return fRes;
  3136.  
  3137. }
  3138.  
  3139.  
  3140. return translate
  3141.  
  3142. }
  3143.  
  3144.  
  3145. let translateFn = null;
  3146.  
  3147. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  3148.  
  3149. const wmx = new WeakMap();
  3150.  
  3151. function fixSegments(ytObj) {
  3152. let a, b;
  3153. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  3154. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  3155. translateFn = translateFn || getTranslate();
  3156. let cSeg;
  3157. cSeg = wmx.get(seg);
  3158. if (!cSeg) {
  3159. let vSeg = null;
  3160. try {
  3161. vSeg = translateFn(seg);
  3162. } catch (e) {
  3163. }
  3164. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  3165. // console.log('translated', vSeg);
  3166. cSeg = vSeg;
  3167. wmx.set(seg, cSeg);
  3168. wmx.set(cSeg, cSeg);
  3169. }
  3170. }
  3171. if (cSeg && cSeg !== seg) {
  3172. a[b] = cSeg;
  3173. }
  3174. }
  3175.  
  3176. const dfn = Symbol();
  3177. const Object_ = Object;
  3178. Object_[dfn] = Object_.defineProperties;
  3179. let activation = true;
  3180. Object_.defineProperties = function (obj, pds) {
  3181. let segments, get_;
  3182. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  3183. activation = false;
  3184. segments.get = function () {
  3185. fixSegments(this);
  3186. return get_.call(this);
  3187. };
  3188. }
  3189. return Object_[dfn](obj, pds);
  3190. };
  3191.  
  3192. })();
  3193.  
  3194.  
  3195. let pf31 = new PromiseExternal();
  3196.  
  3197. // native RAF
  3198. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  3199.  
  3200. // 1st wrapped RAF
  3201. const baseRAF = (callback) => {
  3202. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  3203. pf31.then(() => {
  3204. callback(hRes);
  3205. });
  3206. });
  3207. };
  3208.  
  3209. // 2nd wrapped RAF
  3210. window.requestAnimationFrame = baseRAF;
  3211.  
  3212. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  3213. const indr = o => insp(o).$ || o.$ || 0;
  3214.  
  3215. const prototypeInherit = (d, b) => {
  3216. const m = Object.getOwnPropertyDescriptors(b);
  3217. for (const p in m) {
  3218. if (!Object.getOwnPropertyDescriptor(d, p)) {
  3219. Object.defineProperty(d, p, m[p]);
  3220. }
  3221. }
  3222. };
  3223.  
  3224.  
  3225. const firstObjectKey = (obj) => {
  3226. for (const key in obj) {
  3227. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  3228. }
  3229. return null;
  3230. };
  3231.  
  3232. function searchNestedObject(obj, predicate, maxDepth = 64) {
  3233. // normal case: depth until 36
  3234. const result = [];
  3235. const visited = new WeakSet();
  3236.  
  3237. function search(obj, depth) {
  3238. visited.add(obj);
  3239. for (const [key, value] of Object.entries(obj)) {
  3240. // Recursively search nested objects and arrays
  3241. if (value !== null && typeof value === 'object') {
  3242. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  3243. if (depth + 1 <= maxDepth && !visited.has(value)) {
  3244. search(value, depth + 1);
  3245. }
  3246. } else if (predicate(value)) {
  3247. result.push([obj, key]);
  3248. }
  3249. }
  3250. }
  3251.  
  3252. typeof (obj || 0) === 'object' && search(obj, 0);
  3253. return result;
  3254. }
  3255.  
  3256. /** @type {(o: Object | null) => WeakRef | null} */
  3257. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  3258.  
  3259. /** @type {(wr: Object | null) => Object | null} */
  3260. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  3261.  
  3262. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  3263.  
  3264. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  3265. if (DENY_requestStorageAccess) {
  3266. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  3267. Document.prototype.requestStorageAccessFor = undefined;
  3268. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  3269. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  3270. Document.prototype.requestStorageAccessFor = function () {
  3271. return new Promise((resolve, reject) => {
  3272. reject();
  3273. });
  3274. };
  3275. }
  3276. }
  3277.  
  3278. const traceStack = (stack) => {
  3279. let result = new Set();
  3280. let p = new Set();
  3281. let u = ''
  3282. for (const s of stack.split('\n')) {
  3283. if (s.split(':').length < 3) continue;
  3284. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  3285. if (!m) continue;
  3286. p.add(m[2]);
  3287. if (p.size >= 3) break;
  3288. if(!u) u = m[2];
  3289. else if(p.size === 2 && u && u=== m[2]) break;
  3290. result.add(s);
  3291. }
  3292. return [...result].join('\n');
  3293. }
  3294.  
  3295. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  3296. // window.m3bb = new Set();
  3297.  
  3298. // const smb = Symbol();
  3299. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  3300. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  3301. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  3302.  
  3303. const thisConversionFn = (thisArg) => {
  3304. if (!thisArg) return null;
  3305. const kThis = thisArg[vmb];
  3306. if (kThis) {
  3307. const ref = kThis.ref;
  3308. return (ref ? kRef(ref) : null) || null;
  3309. }
  3310. return thisArg;
  3311. }
  3312.  
  3313. const pFnHandler2 = {
  3314. get(target, prop) {
  3315. if (prop === vmc) return target;
  3316. return Reflect.get(target, prop);
  3317. },
  3318. apply(target, thisArg, argumentsList) {
  3319. thisArg = thisConversionFn(thisArg);
  3320. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  3321. }
  3322. }
  3323.  
  3324.  
  3325. const proxySelfHandler = {
  3326. get(target, prop) {
  3327. if(prop === vmb) return target;
  3328. const ref = target.ref;
  3329. const cnt = kRef(ref);
  3330. if (!cnt) return;
  3331. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  3332. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  3333. return cnt[prop][vmd];
  3334. }
  3335. return cnt[prop];
  3336. },
  3337. set(target, prop, value) {
  3338. const cnt = kRef(target.ref);
  3339. if (!cnt) return true;
  3340. if(value && (value[vmc] || value[vmb])){
  3341. cnt[prop] = value[vmc] || thisConversionFn(value);
  3342. return true;
  3343. }
  3344. cnt[prop] = value;
  3345. return true;
  3346. }
  3347. };
  3348.  
  3349. const weakWrap = (thisArg) => {
  3350. thisArg = thisConversionFn(thisArg);
  3351. if (!thisArg) {
  3352. console.error('thisArg is not found');
  3353. return null;
  3354. }
  3355. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  3356. }
  3357.  
  3358. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  3359. window.getComputedStyle533 = window.getComputedStyle;
  3360. window.getComputedStyle = function (a, ...args) {
  3361. a = thisConversionFn(a);
  3362. if (a) {
  3363. return getComputedStyle533(a, ...args);
  3364. }
  3365. return null;
  3366. }
  3367. }
  3368.  
  3369. Function._count_bind_00 = 0;
  3370. // Function._count_bind_01 = 0;
  3371.  
  3372. // let matchNativeCode = (Object+"");
  3373. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  3374. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  3375.  
  3376. // const matchConstructor = (thisArg) => {
  3377. // const f = `${(thisArg || 0).constructor}`;
  3378. // if (f.length > 45) return true;
  3379. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  3380. // if (f.includes('[native code]')){
  3381. // return false;
  3382. // }
  3383. // return true;
  3384. // }
  3385. // return false;
  3386. // }
  3387.  
  3388. // const acceptThis = (thisArg)=>{
  3389. // // if(!thisArg || typeof thisArg !=='object') return false;
  3390. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  3391. // // if(typeof thisArg.path === 'string') return true;
  3392. // // if(typeof thisArg.fn === 'function') return true;
  3393. // // if(typeof thisArg.id === 'string') return true;
  3394. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  3395. // return false;
  3396. // }
  3397.  
  3398. const patchFn = (fn) => {
  3399.  
  3400. let s = `${fn}`;
  3401. if (s.length < 11 || s.includes('\n')) return false;
  3402. if(s.includes('bind(this')) return true;
  3403. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  3404. // var a=this;
  3405. // f.bind(this)
  3406.  
  3407.  
  3408. return false;
  3409. }
  3410.  
  3411. Function.prototype.bind488 = Function.prototype.bind;
  3412. Function.prototype.bind = function(thisArg, ...args){
  3413.  
  3414. if (thisConversionFn(thisArg) !== thisArg) {
  3415. return this.bind488(thisArg, ...args);
  3416. }
  3417. if( thisArg && patchFn(this) ){
  3418.  
  3419. // console.log(599,`${this}`)
  3420.  
  3421. try {
  3422. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  3423. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  3424. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  3425. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  3426. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  3427. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  3428. // // let b4 = false;
  3429. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  3430.  
  3431. // // b3 = false;
  3432. // // b4 = false;
  3433. // // b5 = false;
  3434.  
  3435. // if (b1 || b2 || b3 ||b4 ) {
  3436. const f = this;
  3437. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  3438. if (ps && ps[vmb]) {
  3439. Function._count_bind_00++;
  3440. return f.bind488(ps, ...args)
  3441. }
  3442. // }
  3443. } catch (e) {
  3444. console.warn(e)
  3445. }
  3446. }
  3447. return this.bind488(thisArg, ...args);
  3448. }
  3449. Function.prototype.bind588 = 1;
  3450. }
  3451.  
  3452. const ytSchedulerMethods = {
  3453. addJob(a, b, c) {
  3454. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3455. if (instance) {
  3456. return instance.addJob(a, b, c);
  3457. } else {
  3458. return setTimeout(a, c);
  3459. }
  3460. },
  3461. addImmediateJob(a) {
  3462. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3463. if (instance) {
  3464. return instance.addImmediateJob(a);
  3465. } else {
  3466. a();
  3467. }
  3468. },
  3469. cancelJob(id) {
  3470. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3471. if (instance) {
  3472. return instance.cancelJob(id);
  3473. } else {
  3474. return clearTimeout(id);
  3475. }
  3476. }
  3477. };
  3478.  
  3479. if (FIX_ytScheduler) {
  3480.  
  3481. let ytSchedulerFixed = 0;
  3482. // let ytActioned = false;
  3483. // let pr = new PromiseExternal();
  3484.  
  3485. // const hn = function () {
  3486.  
  3487. // document.removeEventListener('yt-action', hn, true);
  3488. // nextBrowserTick_(() => {
  3489. // ytActioned = true;
  3490. // pr.resolve();
  3491. // });
  3492.  
  3493. // }
  3494. // document.addEventListener('yt-action', hn, true);
  3495.  
  3496. // let cancelStore = {}; // tbc
  3497.  
  3498. // yt.scheduler.instance.addJob
  3499. const fixAddJob = (nv) => {
  3500.  
  3501. /*
  3502. function Z() {
  3503. var a = w("ytglobal.schedulerInstanceInstance_");
  3504. if (!a || a.s)
  3505. a = new M(I("scheduler") || {}),
  3506. x("ytglobal.schedulerInstanceInstance_", a);
  3507. return a
  3508. }
  3509. */
  3510.  
  3511. /*
  3512. function R(a, b, c, d) {
  3513. ++a.D;
  3514. if (c === 10)
  3515. return P(a, b),
  3516. a.D;
  3517. var e = a.D;
  3518. a.h[e] = b;
  3519. a.l && !d ? a.u.push({
  3520. id: e,
  3521. priority: c
  3522. }) : (a.i[c].push(e),
  3523. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  3524. a.start()));
  3525. return e
  3526. }
  3527. */
  3528.  
  3529. /*
  3530. function sa(a, b, c) {
  3531. if (!c)
  3532. return c = c === void 0,
  3533. -R(Z(), a, b, c);
  3534. var d = window.setTimeout(function() {
  3535. var e = R(Z(), a, b);
  3536. W[d] = e
  3537. }, c);
  3538. return d
  3539. }
  3540. */
  3541. window.originalAddJob = nv;
  3542. // const q1 = new PromiseExternal();
  3543. // const q2 = new PromiseExternal();
  3544. // let uu = 0;
  3545. // let q3 = 0;
  3546. // let mof = null;
  3547. // const mo = new MutationObserver((mutation, observer) => {
  3548. // if (mof) {
  3549. // if (mof() === true) {
  3550. // observer.disconnect();
  3551. // mof = null;
  3552. // }
  3553. // }
  3554. // });
  3555.  
  3556. let lenSkip = -1;
  3557. let lastLen = null;
  3558. let fetchCommentJobTimerId = 0;
  3559. let requestFinish = false;
  3560.  
  3561. const fetchCommentJobDone = ()=>{
  3562. clearInterval(fetchCommentJobTimerId);
  3563. fetchCommentJobTimerId = 0;
  3564. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3565. }
  3566.  
  3567. const fetchCommentJob = (a, cid) => {
  3568.  
  3569. // if (cid && cancelStore[cid]) return; // tbc
  3570.  
  3571. if(fetchCommentJobTimerId > 0){
  3572. fetchCommentJobDone();
  3573. }
  3574.  
  3575. // if (mof) {
  3576. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3577. // mof = null;
  3578. // }
  3579.  
  3580. let f = a;
  3581.  
  3582. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  3583.  
  3584. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  3585.  
  3586. lastLen = -1;
  3587. let u = 0;
  3588. let g = () => {
  3589. if (requestFinish) lastLen = -1;
  3590. const lastLen_ = lastLen;
  3591. const len1 = lastLen = document.querySelectorAll(selector).length;
  3592. let mm = true;
  3593. let ff = false;
  3594. if (len1 !== lastLen_) {
  3595. u = 0;
  3596. f();
  3597. const len2 = lastLen = document.querySelectorAll(selector).length;
  3598. if (len2 !== len1) {
  3599. ff = true;
  3600. mm = false;
  3601. }
  3602. }
  3603. if (mm) {
  3604. ++u;
  3605. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  3606. ff = true;
  3607. }
  3608. }
  3609.  
  3610. if (requestFinish) {
  3611. requestFinish = false;
  3612. fetchCommentJobDone();
  3613. } else if (ff){
  3614. fetchCommentJobDone();
  3615. }
  3616.  
  3617. }
  3618.  
  3619.  
  3620. fetchCommentJobTimerId = setInterval(g, 80);
  3621. // g(9);
  3622. // if (lastLen === lenSkip) {
  3623. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3624. // g = f = null;
  3625. // return;
  3626. // }
  3627. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3628. // const q1 = lastLen;
  3629. // mof = () => {
  3630. // const q2 = document.querySelectorAll(selector).length;
  3631. // if (q1 === q2) return;
  3632. // fetchCommentJobTimerId = setTimeout(g, 80);
  3633. // g = null;
  3634. // return true;
  3635. // }
  3636. // mo.observe(document, { childList: true, subtree: true });
  3637.  
  3638. }
  3639.  
  3640. // let pr72 = Promise.resolve();
  3641.  
  3642.  
  3643. let qa = null;
  3644. let qasf = '';
  3645.  
  3646.  
  3647. document.addEventListener("fullscreenchange", (evt) => {
  3648. if (evt.isTrusted !== true) return;
  3649. if (qa) {
  3650. // qa();
  3651. nextBrowserTick_(qa);
  3652. }
  3653. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3654. // pr72 = pr72.then(() => {
  3655. // return pr
  3656. // });
  3657. }, true);
  3658.  
  3659. window.addEventListener("resize", (evt) => {
  3660. if (evt.isTrusted !== true) return;
  3661. if (qa) {
  3662. // qa();
  3663. nextBrowserTick_(qa);
  3664. }
  3665. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3666. // pr72 = pr72.then(() => {
  3667. // return pr
  3668. // });
  3669. }, true);
  3670.  
  3671.  
  3672. setInterval(() => {
  3673. const f = qa;
  3674. if (typeof f !== 'function') return;
  3675. qa = null;
  3676. // pr72 = pr72.then(() => {
  3677. // f();
  3678. // });
  3679. // nextBrowserTick_(()=>{
  3680. f();
  3681. // });
  3682. }, 475.25);
  3683.  
  3684.  
  3685.  
  3686. return function (a, b, c) {
  3687.  
  3688.  
  3689. const f = a;
  3690. // const g = ()=>{
  3691. // pr72 = pr72.then(()=>{
  3692. // f();
  3693. // });
  3694. // }
  3695.  
  3696. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  3697.  
  3698. const c_ = c;
  3699.  
  3700. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  3701.  
  3702. if (b === 1 && c_ === 500) {
  3703. const sf = `${a}`;
  3704. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  3705. qasf = sf;
  3706. qa = a;
  3707. // console.log(12883, a)
  3708. return nv(() => {
  3709. if (qa === a) {
  3710. qa = null;
  3711. a();
  3712. }
  3713. }, b, c);
  3714. }
  3715. }
  3716.  
  3717.  
  3718. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  3719. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  3720. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3721. // pr72 = pr72.then(() => {
  3722. // return pr
  3723. // });
  3724. // try {
  3725. // yt.scheduler.instance.cancelAllJobs();
  3726. // yt.scheduler.instance.dispose();
  3727. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  3728. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  3729. // } catch (e) { }
  3730. return nv(f, b, c);
  3731. }
  3732.  
  3733. // if(!b && c > 50) c = 50;
  3734. // console.log(58372,a,b,c)
  3735. // function(){xxx(xxx)}
  3736. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  3737.  
  3738. /*
  3739.  
  3740. V.setCommentsJobId = _.et(_.r0, function() {
  3741. F5V(V)
  3742. }, 1E3)
  3743.  
  3744. */
  3745.  
  3746. requestFinish = false;
  3747. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  3748.  
  3749. // lastLen = null;
  3750. fetchCommentJob(a, cid);
  3751.  
  3752. // queueMicrotask_(a);
  3753. // nextBrowserTick_(a);
  3754. // a(); // no need to delay
  3755. return cid
  3756.  
  3757. // return nv(a, b, 1.125);
  3758. // const cid = window.setTimeout(() => {
  3759. // nextBrowserTick_(() => {
  3760. // if (cancelStore[cid]) {
  3761. // console.log('task cancelled');
  3762. // return;
  3763. // }
  3764. // a();
  3765.  
  3766. // });
  3767. // }, 0.125);
  3768. // return cid;
  3769. } else {
  3770.  
  3771.  
  3772.  
  3773. return nv(f,b,c);
  3774.  
  3775.  
  3776. // if (c > 2400) c = 2400;
  3777. // else if (c > 800) c = 800;
  3778. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  3779. // if (0 && ytActioned && !b) {
  3780. // const cid = window.setTimeout(() => {
  3781. // nextBrowserTick_(() => {
  3782. // if (cancelStore[cid]) {
  3783. // console.log('task cancelled');
  3784. // return;
  3785. // }
  3786. // a();
  3787. // });
  3788. // }, c);
  3789. // return cid;
  3790. // } else {
  3791. // return nv(a, b, c);
  3792. // }
  3793.  
  3794. }
  3795. }
  3796. }
  3797.  
  3798. const fixCancelJob = (nv) => {
  3799.  
  3800.  
  3801. window.originalCancelJob = nv;
  3802. return function (a) {
  3803. if (a < 0) return nv(a);
  3804. // cancelStore[a] = true; // tbc
  3805. nv(a);
  3806. }
  3807. }
  3808.  
  3809. const sk44 = Symbol();
  3810. Object.defineProperty(Object.prototype, 'addJob', {
  3811. get() {
  3812. return this[sk44];
  3813. },
  3814. set(nv) {
  3815. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3816. ytSchedulerFixed |= 1;
  3817. nv = fixAddJob(nv);
  3818. }
  3819. this[sk44] = nv;
  3820. return true;
  3821. },
  3822. enumerable: false,
  3823. configurable: true
  3824. });
  3825.  
  3826.  
  3827.  
  3828. const sk45 = Symbol();
  3829. Object.defineProperty(Object.prototype, 'cancelJob', {
  3830. get() {
  3831. return this[sk45];
  3832. },
  3833. set(nv) {
  3834. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3835. ytSchedulerFixed |= 2;
  3836. nv = fixCancelJob(nv);
  3837. }
  3838. this[sk45] = nv;
  3839. return true;
  3840. },
  3841. enumerable: false,
  3842. configurable: true
  3843. });
  3844.  
  3845.  
  3846.  
  3847. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3848. const { addJob, cancelJob } = yt.scheduler.instance;
  3849. if (addJob) {
  3850. yt.scheduler.instance.addJob = null;
  3851. yt.scheduler.instance.addJob = addJob;
  3852. }
  3853. if (cancelJob) {
  3854. yt.scheduler.instance.cancelJob = null;
  3855. yt.scheduler.instance.cancelJob = cancelJob;
  3856. }
  3857. }
  3858.  
  3859.  
  3860. }
  3861.  
  3862. const isWatchPageURL = (url) => {
  3863. url = url || location;
  3864. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  3865. };
  3866.  
  3867. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3868.  
  3869. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  3870. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3871. if (typeof customElements === 'undefined') {
  3872. if (!('__CE_registry' in document)) {
  3873. // https://github.com/webcomponents/polyfills/
  3874. Object.defineProperty(document, '__CE_registry', {
  3875. get() {
  3876. // return undefined
  3877. },
  3878. set(nv) {
  3879. if (typeof nv == 'object') {
  3880. delete this.__CE_registry;
  3881. this.__CE_registry = nv;
  3882. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3883. }
  3884. return true;
  3885. },
  3886. enumerable: false,
  3887. configurable: true
  3888. })
  3889. }
  3890. let eventHandler = (evt) => {
  3891. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3892. const f = callback;
  3893. callback = null;
  3894. eventHandler = null;
  3895. f();
  3896. };
  3897. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3898. } else {
  3899. callback();
  3900. }
  3901. });
  3902.  
  3903. const whenCEDefined = isCustomElementsProvided
  3904. ? (nodeName) => customElements.whenDefined(nodeName)
  3905. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3906.  
  3907. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  3908. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  3909. const f = performance.now23 = Performance.prototype.now;
  3910.  
  3911. let k = 0; // 0 <= k < 9998m
  3912. let u = 0;
  3913. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  3914.  
  3915. // By definition, performance.now() is mono increasing.
  3916. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  3917. performance.now = performance.now16 = function () {
  3918. /**
  3919. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  3920. *
  3921. * If consecutive session history entries had history.state.entryTime set to same value,
  3922. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  3923. * and modifying its return value slightly to make sure two close consecutive calls don't
  3924. * get the same result helped with resolving the issue.
  3925. */
  3926. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  3927. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  3928.  
  3929. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  3930. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  3931. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  3932. else { // more than 9998 consecutive calls
  3933. /**
  3934. *
  3935. * max no. of consecutive calls
  3936. *
  3937. * Sample Size: 4800
  3938. * Sample Avg = 1565.375
  3939. * Sample Median = 1469.5
  3940. * Sample Max = 5660 << 7500 << 9999
  3941. *
  3942. *
  3943. * */
  3944. k = 0;
  3945. s += 1 / 7;
  3946. }
  3947. return v + k; // 0 < v - M < v - M + k < v
  3948. }
  3949.  
  3950. let loggerMsg = '';
  3951. if (`${performance.now()}` === `${performance.now()}`) {
  3952. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  3953. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  3954. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  3955. }
  3956. loggerMsg && console.warn(loggerMsg);
  3957. })();
  3958.  
  3959. // let __forceRemoveMode__ = false;
  3960. FIX_removeChild && (() => {
  3961. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  3962. let internalByPass = false;
  3963. const fragD = document.createDocumentFragment();
  3964. fragD.appendChild4201 = fragD.appendChild;
  3965. fragD.removeChild4201 = fragD.removeChild;
  3966. Node.prototype.removeChild062 = Node.prototype.removeChild;
  3967. Node.prototype.removeChild = function (child) {
  3968. try {
  3969. return this.removeChild062(child);
  3970. } catch (e) { }
  3971. if (internalByPass) return child;
  3972. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  3973. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3974. if (idx >= 0) {
  3975. internalByPass = true;
  3976. child.parentNode !== fragD && fragD.appendChild4201(child);
  3977. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3978. fragD.removeChild4201(child);
  3979. internalByPass = false;
  3980. return child;
  3981. }
  3982. }
  3983. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  3984. // // force removal
  3985. // internalByPass = true;
  3986. // child.parentNode !== fragD && fragD.appendChild4201(child);
  3987. // fragD.removeChild4201(child);
  3988. // internalByPass = false;
  3989. // return child;
  3990. // }
  3991. if (this && child) {
  3992. if (this.childNodes && this.childNodes.splice) { // tbc
  3993. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3994. if (idx >= 0) {
  3995. internalByPass = true;
  3996. child.parentNode !== fragD && fragD.appendChild4201(child);
  3997. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3998. fragD.removeChild4201(child);
  3999. internalByPass = false;
  4000. return child;
  4001. }
  4002. }
  4003.  
  4004. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  4005. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  4006. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  4007. return child;
  4008. }
  4009. }
  4010.  
  4011. if (child && child.is === 'tp-yt-paper-tooltip' && !child.parentNode && !child.__shady_parentNode) {
  4012. // skip
  4013. return child;
  4014. }
  4015.  
  4016. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  4017. parent: this, child: child,
  4018. isParent: child.parentNode === this,
  4019. isParentParent: (child.parentNode || 0).parentNode === this,
  4020. parentNode: child.parentNode,
  4021. shadyParent: child.__shady_parentNode,
  4022. isShadyParent: child.__shady_parentNode === this,
  4023. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  4024. });
  4025.  
  4026. }
  4027. return child;
  4028. }
  4029. }
  4030. })();
  4031.  
  4032.  
  4033. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  4034.  
  4035. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  4036.  
  4037. // let cid = 0;
  4038.  
  4039. let mousemoveFn = null;
  4040. let mousemoveDT = 0;
  4041. let mousemoveCount = 0;
  4042. // let qv = false;
  4043. const cif = () => {
  4044. if (!mousemoveFn) return;
  4045. const ct = Date.now();
  4046. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  4047. mousemoveFn && mousemoveFn();
  4048. }
  4049. mousemoveFn = null;
  4050. };
  4051. let mousemoveCId = 0;
  4052. let mouseoverFn = null;
  4053. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  4054. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  4055. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  4056. const bt = `${b}`;
  4057. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  4058. b[`__$$${a}$$1926__`] = true;
  4059. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  4060. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  4061. // console.log(3928, a, this[`__$$${a}$$1937__`])
  4062. if (!this[`__$$${a}$$1938__`]) {
  4063. this[`__$$${a}$$1938__`] = b;
  4064. if (a === 'mousemove') {
  4065. this.addEventListener4882('mouseenter', (evt) => {
  4066. if (mousemoveCId) return;
  4067. mousemoveCId = setIntervalX0(cif, 380);
  4068. });
  4069. this.addEventListener4882('mouseleave', (evt) => {
  4070. clearIntervalX0(mousemoveCId);
  4071. mousemoveCId = 0;
  4072. });
  4073. }
  4074. this.addEventListener4882(a, (evt) => {
  4075. const evt_ = evt;
  4076. if (!this[`__$$${a}$$1937__`]) return;
  4077. if (!this[`__$$${a}$$1938__`]) return;
  4078. if (a === 'mousemove') {
  4079. mouseoverFn && mouseoverFn();
  4080. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  4081. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  4082. } else {
  4083. mousemoveCount = 0;
  4084. }
  4085. const f = mousemoveFn = () => {
  4086. if (f !== mousemoveFn) return;
  4087. mousemoveFn = null;
  4088. this[`__$$${a}$$1938__`](evt_);
  4089. };
  4090. if (mousemoveCount <= 1) mousemoveFn();
  4091. } else {
  4092. if (a === 'mouseout' || a === 'mouseleave') {
  4093. mousemoveFn = null;
  4094. mousemoveDT = 0;
  4095. mousemoveCount = 0;
  4096. this[`__$$${a}$$1938__`](evt_);
  4097. mouseoverFn && mouseoverFn();
  4098. } else { // mouseover, mouseenter
  4099. mousemoveFn = null;
  4100. mousemoveDT = 0;
  4101. mousemoveCount = 0;
  4102. mouseoverFn && mouseoverFn(); // just in case
  4103. const f = mouseoverFn = () => {
  4104. if (f !== mouseoverFn) return;
  4105. mouseoverFn = null;
  4106. this[`__$$${a}$$1938__`](evt_);
  4107. }
  4108. nextBrowserTick_(mouseoverFn);
  4109. }
  4110. }
  4111. }, c);
  4112.  
  4113.  
  4114. return;
  4115. } else {
  4116.  
  4117. return;
  4118. }
  4119. }
  4120.  
  4121. }
  4122. return this.addEventListener4882(a, b, c)
  4123. }
  4124.  
  4125.  
  4126.  
  4127.  
  4128. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  4129. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  4130. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  4131.  
  4132. if (b[`__$$${a}$$1926__`]) {
  4133. b[`__$$${a}$$1926__`] = false;
  4134.  
  4135. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  4136.  
  4137. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  4138.  
  4139. return;
  4140.  
  4141. }
  4142.  
  4143. }
  4144. return this.removeEventListener4882(a, b, c)
  4145. }
  4146.  
  4147.  
  4148. })();
  4149.  
  4150.  
  4151. FIX_DOM_IF_REPEAT && (() => {
  4152. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4153. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  4154. // Be careful of the mixture of polymer functions and native Element functions
  4155. // Be careful of the coding design is different with the modern Yt elements
  4156.  
  4157.  
  4158. /*
  4159.  
  4160.  
  4161. function Ks(a, b, c) {
  4162. if (kj && !BOa(a))
  4163. throw Error("strictTemplatePolicy: template owner not trusted");
  4164. c = c || {};
  4165. if (a.__templatizeOwner)
  4166. throw Error("A <template> can only be templatized once");
  4167. a.__templatizeOwner = b;
  4168. var d = (b ? b.constructor : Js)._parseTemplate(a)
  4169. , e = d.templatizeInstanceClass;
  4170. e || (e = COa(a, d, c),
  4171. d.templatizeInstanceClass = e);
  4172. var g = BOa(a);
  4173. EOa(a, d, c, g);
  4174. c = function() {
  4175. return e.apply(this, arguments) || this
  4176. }
  4177. ;
  4178. h(c, e);
  4179. c.prototype._methodHost = g;
  4180. c.prototype.__dataHost = a;
  4181. c.prototype.__templatizeOwner = b;
  4182. c.prototype.__hostProps = d.hostProps;
  4183. return c
  4184. }
  4185.  
  4186. */
  4187.  
  4188. // Polymer.enqueueDebouncer
  4189.  
  4190. const s81 = Symbol();
  4191. const s83 = Symbol();
  4192. const s84 = Symbol();
  4193. const s85 = Symbol();
  4194. const s85b = Symbol();
  4195. const s85c = Symbol();
  4196.  
  4197. let renderDebounceTs = null;
  4198.  
  4199. let renderDebouncePromise = null;
  4200. let qp;
  4201.  
  4202. const shadyFlushMO = new MutationObserver(() => {
  4203.  
  4204. if (!renderDebounceTs) return;
  4205.  
  4206. if (renderDebounceTs.size > 0) {
  4207. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  4208. try {
  4209. Polymer.flush();
  4210. return;
  4211. } catch (e) { }
  4212. }
  4213.  
  4214. renderDebouncePromise && Promise.resolve().then(() => {
  4215.  
  4216. if (renderDebouncePromise) {
  4217. renderDebouncePromise && renderDebouncePromise.resolve();
  4218. renderDebouncePromise = null;
  4219. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  4220. }
  4221.  
  4222. });
  4223.  
  4224. // Polymer.flush
  4225.  
  4226. window.ShadyDOM && ShadyDOM.flush();
  4227. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  4228.  
  4229.  
  4230. });
  4231.  
  4232. const setupPolymerAdv = () => {
  4233. // here we can obtain the Polymer faster.
  4234. // reserved for future use.
  4235. }
  4236.  
  4237.  
  4238. if (USE_fastDomIf) {
  4239. // 0 = no effect. 1 = enable. 2 = disable
  4240. // fastDomIf because it delayed the rendering process?
  4241. Object.defineProperty(Object.prototype, 'fastDomIf', {
  4242. get() {
  4243. if (this === window.Polymer) {
  4244. const v = USE_fastDomIf === 1 ? true : false;
  4245. this.fastDomIf = v;
  4246. delete Object.prototype.fastDomIf;
  4247. setupPolymerAdv(this);
  4248. return v;
  4249. }
  4250. },
  4251. set(nv) {
  4252. return false;
  4253. }
  4254. });
  4255. }
  4256.  
  4257. let setupDomIfDone = false;
  4258. const setupDomIf = (DomIf)=>{
  4259. setupDomIfDone = true;
  4260. if(setupDomIfDone) return;
  4261.  
  4262. const fProto = DomIf.prototype;
  4263.  
  4264.  
  4265. // Polymer.DomIf
  4266. // Polymer.DomIf = Polymer.fastDomIf ? ZbL : ESz
  4267. // Assume ESz by default
  4268.  
  4269. // We don't need to store "root" in DOM-IF
  4270. if (ENHANCE_DOMIF_createAndInsertInstance && fProto.__createAndInsertInstance && !fProto.__createAndInsertInstance239 && fProto.__createAndInsertInstance.length === 1) {
  4271. fProto.__createAndInsertInstance239 = fProto.__createAndInsertInstance;
  4272. fProto.__createAndInsertInstance = function (M) {
  4273. const r = this.__createAndInsertInstance239(M);
  4274. const __instance = this.__instance;
  4275. const __ctor = this.__ctor;
  4276. if (__instance && __ctor && __instance instanceof __ctor) {
  4277. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4278. const o = __instance[sym];
  4279. if (o && o.nodeType === 11) {
  4280. __instance[sym] = null;
  4281. }
  4282. }
  4283. }
  4284. return r;
  4285. }
  4286.  
  4287. /*
  4288.  
  4289.  
  4290. sX = function(M, d, N) {
  4291. if (o_ && !vDv(M))
  4292. throw Error("Jd");
  4293. N = N || {};
  4294. if (M.__templatizeOwner)
  4295. throw Error("Kd");
  4296. M.__templatizeOwner = d;
  4297. var R = (d ? d.constructor : jF)._parseTemplate(M)
  4298. , X = R.templatizeInstanceClass;
  4299. X || (X = sfi(M, R, N),
  4300. R.templatizeInstanceClass = X);
  4301. var A = vDv(M);
  4302. y9Z(M, R, N, A);
  4303. N = function() {
  4304. return X.apply(this, arguments) || this
  4305. }
  4306. ;
  4307. _.v(N, X);
  4308. N.prototype._methodHost = A;
  4309. N.prototype.__dataHost = M;
  4310. N.prototype.__templatizeOwner = d;
  4311. N.prototype.__hostProps = R.hostProps;
  4312. return N
  4313. }
  4314.  
  4315. */
  4316. }
  4317.  
  4318. // Polymer.DomIf
  4319. // We can fully teardown the entire instance (including stampFrag and stampNodes), just keep ctor stamper
  4320. if (ENHANCE_DOMIF_TEARDOWN && fProto.__teardownInstance && !fProto.__teardownInstance239 && fProto.__teardownInstance.length === 0) {
  4321. fProto.__teardownInstance239 = fProto.__teardownInstance;
  4322. fProto.__teardownInstance = function () {
  4323. const { __instance, __invalidProps } = this;
  4324. let r, e_;
  4325. try {
  4326. r = this.__teardownInstance239();
  4327. } catch (e) { e_ = e }
  4328. if (!__instance) return r;
  4329.  
  4330. try {
  4331.  
  4332. //console.log(599901,this.countEvent767());
  4333. //console.log('__teardownInstance F', __instance, __invalidProps, this._removeEventListenerFromNode, __instance._removeEventListenerFromNode);
  4334. __instance.__data = null;
  4335. __instance.__dataClientsReady = __instance.__dataEnabled = __instance.__dataReady = false;
  4336. __instance.__dataInvalid = true;
  4337. __instance.__dataHost = __instance.__dataTemp = null;
  4338. __instance.__isPropertyEffectsClient = false;
  4339. __instance.__keepInstance038__ = false;
  4340.  
  4341.  
  4342. const __templateInfo = __instance.__templateInfo;
  4343.  
  4344. let stampFragId = null;
  4345. if (__templateInfo && __templateInfo.nodeList) {
  4346. stampFragId = __templateInfo.nodeList.__belongFragId57__;
  4347. for (const weakNodeC of __templateInfo.nodeList) {
  4348. const node = toActualNode(weakNodeC);
  4349. if (node && node.nodeType >= 1) {
  4350. renderPathMake(node)
  4351. node.__keepInstance038__ = false;
  4352. node.remove();
  4353. _removedElements.addNode(node); // rn54011
  4354. }
  4355. }
  4356. __templateInfo.nodeList.length = 0;
  4357. __templateInfo.nodeList = null;
  4358. }
  4359.  
  4360. const stampFrag = stampFragId ? kRef(stampedFragment.get(stampFragId)) : null;
  4361.  
  4362. if (stampFrag && stampFrag.nodeType === 11) {
  4363. stampFrag.__keepInstance038__ = false;
  4364. _removedElements.addNode(stampFrag); // rn54012
  4365. removeAllChildNodes(stampFrag);
  4366. try {
  4367. stampFrag.remove();
  4368. } catch (e) { }
  4369. stampFrag.__shady = null;
  4370. stampFrag.$ = null;
  4371. stampFrag.__fragTeardowned57__ = true;
  4372. stampFrag.nodeList = null;
  4373. stampFrag.templateInfo = null;
  4374.  
  4375. }
  4376.  
  4377. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4378. const o = __instance[sym];
  4379. if (o && o.nodeType === 11) {
  4380. __instance[sym] = null;
  4381. }
  4382. }
  4383.  
  4384. const children = (__instance || 0).children;
  4385. if (children && children.splice) {
  4386. __instance.children = null;
  4387. for (const n of children) {
  4388. if (n && n.nodeType >= 1) {
  4389. n.__keepInstance038__ = false;
  4390. _removedElements.addNode(n); // rn54013
  4391. }
  4392. }
  4393. children.length = 0;
  4394. }
  4395.  
  4396. if (__instance.__templateInfo) __instance.__templateInfo = null;
  4397.  
  4398. if (__instance.root) __instance.root = null;
  4399.  
  4400. } catch (e) {
  4401. console.error(e);
  4402. }
  4403.  
  4404. // console.log(3882)
  4405. if (e_) throw e_;
  4406. return r;
  4407. }
  4408. }
  4409.  
  4410. }
  4411.  
  4412. if (ENHANCE_DOMIF_createAndInsertInstance || ENHANCE_DOMIF_TEARDOWN) {
  4413.  
  4414. Object.defineProperty(Object.prototype, 'DomIf', {
  4415. get() {
  4416. return undefined;
  4417. },
  4418. set(nv) {
  4419. if (typeof (nv || 0) !== 'function') return false;
  4420. delete Object.prototype.DomIf;
  4421. this.DomIf = nv;
  4422. setupDomIf(nv);
  4423. return true;
  4424. },
  4425. enumerable: false,
  4426. configurable: true
  4427. });
  4428.  
  4429. }
  4430.  
  4431. Object.defineProperty(Object.prototype, '_lastIf', {
  4432. get() {
  4433. return this[s81];
  4434. },
  4435. set(nv) {
  4436. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  4437. // DOM-IF initialization
  4438. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  4439.  
  4440. this.__xiWB8__ = 2;
  4441. // this.restamp = true;
  4442.  
  4443. const cProto = this.__proto__;
  4444. if (cProto && !cProto.__xiWB7__) {
  4445. cProto.__xiWB7__ = 1;
  4446.  
  4447. // dom-if __template
  4448. // dom-repeat template
  4449. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  4450. cProto.__template847 = true;
  4451. try {
  4452. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  4453. Object.defineProperty(cProto, '__template', {
  4454. get() {
  4455. const v = this[s84];
  4456. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  4457. },
  4458. set(nv) {
  4459. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  4460. this[s84] = nv;
  4461. return true;
  4462. }
  4463. });
  4464. } catch (e) {
  4465. console.warn(e);
  4466. }
  4467.  
  4468. console.log('FIX_DOM_IF - __template')
  4469. }
  4470.  
  4471. // dom-if __ensureTemplate
  4472. // dom-repeat __ensureTemplatized
  4473. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  4474. // note that "_templateInfo" diffs the different version of DOM-IF
  4475.  
  4476. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  4477. cProto.__ensureTemplate = function () {
  4478. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  4479. if (!this.__template) {
  4480. let b;
  4481. if (this._templateInfo) {
  4482. b = this;
  4483. } else {
  4484. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  4485. b = this.__templateCollection011__[0];
  4486. if (!b) {
  4487. if (!this[wk]) this[wk] = mWeakRef(this);
  4488. let a = this[wk];
  4489. let c = new MutationObserver(function () {
  4490. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  4491. if (c && a) {
  4492. c.disconnect();
  4493. a = kRef(a);
  4494. a && a.__render();
  4495. a && (a.__templateCollection011__ = null);
  4496. }
  4497. c = null;
  4498. a = null;
  4499. });
  4500. c && c.observe(this, {
  4501. childList: !0
  4502. });
  4503. return !1
  4504. } else {
  4505. this.__templateCollection011__ = null;
  4506. }
  4507. }
  4508. this.__template = b
  4509. }
  4510. return !0
  4511. }
  4512.  
  4513. console.log('FIX_DOM_IF - __ensureTemplate')
  4514.  
  4515. }
  4516.  
  4517.  
  4518. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  4519. }
  4520.  
  4521.  
  4522. // need to fix __observeEffects
  4523. // this.__observeEffects.if[0].info.method === this.__debounceRender
  4524. const f = () => {
  4525.  
  4526. const __observeEffects = this.__observeEffects;
  4527.  
  4528. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  4529. for (const effect of __observeEffects.if) {
  4530. const info = effect.info;
  4531. if (info && typeof info.method === 'function') {
  4532.  
  4533. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4534. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4535. }
  4536.  
  4537. }
  4538. }
  4539. }
  4540.  
  4541.  
  4542. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  4543. for (const effect of __observeEffects.restamp) {
  4544. const info = effect.info;
  4545. if (info && typeof info.method === 'function') {
  4546.  
  4547. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4548. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4549. }
  4550.  
  4551. }
  4552. }
  4553. }
  4554.  
  4555. // console.log(5881, this.__observeEffects)
  4556. }
  4557.  
  4558. }
  4559. this[s81] = nv;
  4560. return true;
  4561. }
  4562. });
  4563.  
  4564.  
  4565. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  4566. get() {
  4567. return this[s85];
  4568. },
  4569. set(nv) {
  4570. if (nv === null && this[s85] === undefined) {
  4571. // DOM-IF / DOM-REPEAT initialization
  4572.  
  4573.  
  4574. const cProto = this.__proto__;
  4575. if (qp) {
  4576. qp.obtain();
  4577. qp = null;
  4578. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  4579. }
  4580.  
  4581. }
  4582. this[s85] = nv;
  4583. return true;
  4584. }
  4585. });
  4586.  
  4587. // PS-DOM-REPEAT
  4588.  
  4589. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  4590. get() {
  4591. return this[s85b];
  4592. },
  4593. set(nv) {
  4594.  
  4595. this[s85b] = nv;
  4596. return true;
  4597. }
  4598. })
  4599.  
  4600. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  4601. get() {
  4602. return this[s85c];
  4603. },
  4604. set(nv) {
  4605.  
  4606. this[s85c] = nv;
  4607. return true;
  4608. }
  4609. })
  4610.  
  4611.  
  4612. })();
  4613.  
  4614. const setupXdeadC = (cnt)=>{
  4615.  
  4616. let xdeadc = xdeadc00;
  4617. if(!xdeadc){
  4618. setupSDomWrapper(); // just in case
  4619. const hostElement = cnt.hostElement;
  4620. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4621. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4622. hostElement.lastChild.replaceWith(el);
  4623. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4624. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4625. el.firstElementChild.id = rid;
  4626. cnt.$[rid] = el.firstElementChild;
  4627. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4628.  
  4629. xdeadc = cnt.getStampContainer_(rid);
  4630. el.remove();
  4631. xdeadc00 = xdeadc;
  4632. // console.log(xdeadc.__domApi)
  4633. // debugger;
  4634. // const xdeadv = xdeadc.__domApi;
  4635. }
  4636.  
  4637. let xlivec = xlivec00;
  4638. if(!xlivec){
  4639. setupSDomWrapper(); // just in case
  4640. const hostElement = cnt.hostElement;
  4641. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4642. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4643. hostElement.lastChild.replaceWith(el);
  4644. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4645. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4646. el.firstElementChild.id = rid;
  4647. cnt.$[rid] = el.firstElementChild;
  4648. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4649.  
  4650. xlivec = cnt.getStampContainer_(rid);
  4651. xlivec00 = xlivec;
  4652. // console.log(xdeadc.__domApi)
  4653. // debugger;
  4654. // const xdeadv = xdeadc.__domApi;
  4655. }
  4656.  
  4657. return xdeadc00;
  4658. }
  4659.  
  4660. let standardWrap_ = null;
  4661.  
  4662. const setupSDomWrapper = () => {
  4663.  
  4664. const sdwProto = ShadyDOM.Wrapper.prototype;
  4665.  
  4666. if (sdwProto.__pseudo__isConnected__ !== null) {
  4667. sdwProto.__pseudo__isConnected__ = null;
  4668. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  4669. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  4670. const get = isConnectedPd.get;
  4671. isConnectedPd.get = function () {
  4672. const pseudoVal = this.__pseudo__isConnected__;
  4673. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  4674. }
  4675. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  4676. }
  4677.  
  4678. // debugger;
  4679. // new xdeadc.__domApi.constructor(document.createElement('div'));
  4680. }
  4681.  
  4682. }
  4683.  
  4684. let domApiConstructor = null;
  4685. const setupDomApi = (daProto) => {
  4686.  
  4687. daProto.__daHook377__ = true;
  4688.  
  4689. domApiConstructor = daProto.constructor; // TBC
  4690.  
  4691. // TBC
  4692.  
  4693. }
  4694.  
  4695.  
  4696. // WEAKREF_ShadyDOM
  4697.  
  4698. let mightTeardownShadyDomWrap = () => { };
  4699.  
  4700. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  4701.  
  4702. const setupPlainShadyDOM = (b) => {
  4703. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  4704. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  4705. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  4706. b.patchOnDemand = true;
  4707. b.preferPerformance = true;
  4708. b.noPatch = true;
  4709. }
  4710.  
  4711. const isPlainObject = (b, m) => {
  4712. if (!b || typeof b !== 'object') return false;
  4713. const e = Object.getOwnPropertyDescriptors(b);
  4714. if (e.length <= m) return false;
  4715. let pr = 0;
  4716. for (const k in e) {
  4717. const d = e[k];
  4718. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  4719. if (!('value' in d) || typeof d.value === 'function') return false;
  4720. pr++;
  4721. }
  4722. return pr > m;
  4723. }
  4724.  
  4725. let b;
  4726.  
  4727. let lz = 0;
  4728.  
  4729. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  4730. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  4731.  
  4732. // Brave - ShadyDOM exists before userscripting
  4733. b = sdp.value;
  4734.  
  4735. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  4736. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  4737. lz = 1;
  4738. }
  4739.  
  4740. }
  4741.  
  4742.  
  4743. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  4744. } else if (!sdp) {
  4745. } else {
  4746. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  4747. return;
  4748. }
  4749.  
  4750. const shadyDOMNodeWRM = new WeakMap();
  4751.  
  4752. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  4753.  
  4754. const weakWrapperNodeHandlerFn = () => ({
  4755. get() {
  4756. const wv = this[wk];
  4757. if (typeof wv === 'undefined') return undefined;
  4758. let node = kRef(wv);
  4759. if (!node) this[wk] = undefined;
  4760. return node || undefined;
  4761. },
  4762. set(nv) {
  4763. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  4764. this[wk] = wv;
  4765. return true;
  4766. },
  4767. enumerable: true,
  4768. configurable: true
  4769. });
  4770.  
  4771.  
  4772. function weakWrapper(_ShadyDOM) {
  4773. const ShadyDOM = _ShadyDOM;
  4774. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  4775. let nullElement = { node: null };
  4776. Object.setPrototypeOf(nullElement, Element.prototype);
  4777. let p = new ShadyDOM.Wrapper(nullElement);
  4778. let d = Object.getOwnPropertyDescriptor(p, 'node');
  4779. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  4780. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  4781. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  4782. }
  4783.  
  4784. }
  4785. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  4786. try {
  4787. setupSDomWrapper();
  4788. } catch (e) { }
  4789. }
  4790.  
  4791. }
  4792.  
  4793. let previousWrapStore = null;
  4794.  
  4795. mightTeardownShadyDomWrap = (node) => {
  4796. if (previousWrapStore) previousWrapStore.delete(node);
  4797. if (shadyDOMNodeWRM) shadyDOMNodeWRM.delete(node);
  4798. };
  4799.  
  4800. const standardWrap = function (a) {
  4801. if (a instanceof WeakNodeC) a = a.getNode592177();
  4802. // if(a && a.deref) a= a.deref();
  4803. if(!a) return a;
  4804. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  4805. if (previousWrapStore) {
  4806. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  4807. if (s) {
  4808. previousWrapStore.delete(a);
  4809. shadyDOMNodeWRM.set(a, mWeakRef(s));
  4810. }
  4811. }
  4812. let u = kRef(shadyDOMNodeWRM.get(a));
  4813. if (!u) {
  4814. u = new ShadyDOM.Wrapper(a);
  4815. shadyDOMNodeWRM.set(a, mWeakRef(u));
  4816. }
  4817. return u;
  4818. }
  4819.  
  4820. standardWrap_ = standardWrap;
  4821.  
  4822.  
  4823. function setupWrapFunc(_ShadyDOM) {
  4824. const ShadyDOM = _ShadyDOM;
  4825.  
  4826.  
  4827. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  4828. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  4829. return;
  4830. }
  4831. let mm = new Set();
  4832. const pget = wmPD.value;
  4833. WeakMap.prototype.get = function (a) {
  4834. mm.add(this);
  4835. return a;
  4836. }
  4837. try {
  4838. let nullElement = { node: null };
  4839. Object.setPrototypeOf(nullElement, Element.prototype);
  4840. ShadyDOM.wrapIfNeeded(nullElement)
  4841. ShadyDOM.wrap(nullElement)
  4842. } catch (e) { }
  4843. WeakMap.prototype.get = pget;
  4844. if (mm.size !== 1) {
  4845. mm.clear();
  4846. return;
  4847. }
  4848. const p = mm.values().next().value;
  4849. if (!(p instanceof WeakMap)) return;
  4850. // p.clear();
  4851. // p.get = function (a) { return a }
  4852. // p.set = function (a, b) { return this }
  4853. // console.log(188, window.n2n = mm, window.n2p = p)
  4854.  
  4855. // console.log(34929,p.size)
  4856. previousWrapStore = p;
  4857.  
  4858. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  4859. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  4860. }
  4861. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  4862. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  4863. }
  4864.  
  4865. }
  4866.  
  4867. function setupLZ3(nv) {
  4868.  
  4869. const ShadyDOM = nv;
  4870.  
  4871. const ShadyDOMSettings = ShadyDOM.settings;
  4872. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4873. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4874. return false;
  4875. }
  4876.  
  4877. weakWrapper(ShadyDOM);
  4878.  
  4879. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4880.  
  4881. setupPlainShadyDOM(ShadyDOMSettings);
  4882. setupPlainShadyDOM(ShadyDOM);
  4883.  
  4884. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  4885.  
  4886. setupWrapFunc(ShadyDOM);
  4887. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  4888. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  4889.  
  4890. // To be confirmed
  4891. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  4892. ShadyDOM.composedPath = function (e) {
  4893. const t = (e || 0).target || null;
  4894. if (!(t instanceof HTMLElement_)) {
  4895. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  4896. }
  4897. return t instanceof HTMLElement_ ? [t] : [];
  4898. };
  4899. }
  4900.  
  4901. }
  4902.  
  4903. }
  4904.  
  4905.  
  4906. function setupLZ6(nv) {
  4907.  
  4908. const ShadyDOM = nv;
  4909.  
  4910. const ShadyDOMSettings = ShadyDOM.settings;
  4911.  
  4912. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4913. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4914. return false;
  4915. }
  4916.  
  4917. weakWrapper(ShadyDOM);
  4918.  
  4919. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4920.  
  4921. setupPlainShadyDOM(ShadyDOMSettings);
  4922. setupPlainShadyDOM(ShadyDOM);
  4923.  
  4924. setupWrapFunc(ShadyDOM);
  4925.  
  4926. }
  4927.  
  4928. }
  4929.  
  4930. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  4931.  
  4932. const nv = b;
  4933.  
  4934. if (setupLZ6(nv) === false) return;
  4935.  
  4936. lz = 6;
  4937.  
  4938. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  4939.  
  4940. return;
  4941. }
  4942.  
  4943. delete window.ShadyDOM;
  4944.  
  4945. Object.defineProperty(window, 'ShadyDOM', {
  4946. get() {
  4947. return b;
  4948. },
  4949. set(nv) {
  4950. let ret = 0;
  4951. try {
  4952. do {
  4953. if (!nv || !nv.settings) {
  4954. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  4955. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  4956. lz = 1;
  4957. break;
  4958. } else {
  4959. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  4960. break;
  4961. }
  4962. }
  4963.  
  4964. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  4965. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  4966. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  4967. break;
  4968. }
  4969.  
  4970. if (setupLZ3(nv) === false) break;
  4971.  
  4972. lz = 3;
  4973.  
  4974. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  4975.  
  4976. ret = 1;
  4977.  
  4978. } while (0);
  4979. } catch (e) {
  4980. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  4981. }
  4982.  
  4983. if (!ret) b = nv;
  4984. else {
  4985. delete this.ShadyDOM;
  4986. this.ShadyDOM = nv;
  4987. }
  4988. return true;
  4989. },
  4990. enumerable: false,
  4991. configurable: true
  4992. });
  4993.  
  4994. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  4995.  
  4996. if (ENABLE_ASYNC_DISPATCHEVENT) {
  4997. const filter = new Set([
  4998. 'yt-action',
  4999. // 'iframe-src-replaced',
  5000. 'shown-items-changed',
  5001. 'can-show-more-changed', 'collapsed-changed',
  5002.  
  5003. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  5004. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  5005. 'yt-navigate-finish',
  5006.  
  5007. // 'data-changed','yt-watch-comments-ready'
  5008. ])
  5009. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  5010. EventTarget.prototype.dispatchEvent = function (event) {
  5011. const type = (event || 0).type;
  5012. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  5013. if (!filter.has(type) && !type.endsWith('-changed')) {
  5014. if (this instanceof Node || this instanceof Window) {
  5015. nextBrowserTick_(() => this.dispatchEvent938(event));
  5016. return true;
  5017. }
  5018. }
  5019. }
  5020. return this.dispatchEvent938(event);
  5021. }
  5022. }
  5023.  
  5024. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  5025. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  5026. // const xhr = new XMLHttpRequest;
  5027. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  5028. if (!pdOri || pdOri.configurable !== true) return;
  5029. let propNeedles = null;
  5030. const pdNew = {
  5031. configurable: true,
  5032. enumerable: true,
  5033. get: function () {
  5034. propNeedles = this;
  5035. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  5036. throw new Error();
  5037. }
  5038. }
  5039. Object.defineProperty(Map.prototype, 'size', pdNew);
  5040. try {
  5041. XMLHttpRequest.prototype.open.call(0);
  5042. // xhr.open.call(null)
  5043. } catch (e) { }
  5044. Object.defineProperty(Map.prototype, 'size', pdOri);
  5045. if (!propNeedles) return;
  5046. const entries = [...propNeedles.entries()];
  5047. propNeedles.clear();
  5048. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  5049. })();
  5050.  
  5051. if (FIX_XHR_REQUESTING) {
  5052.  
  5053. const URL = window.URL || new Function('return URL')();
  5054. const createObjectURL = URL.createObjectURL.bind(URL);
  5055.  
  5056. XMLHttpRequest = (() => {
  5057. const XMLHttpRequest_ = XMLHttpRequest;
  5058. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  5059. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  5060. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  5061. constructor(...args) {
  5062. super(...args);
  5063. }
  5064. open(method, url, ...args) {
  5065. let skip = false;
  5066. if (!url || typeof url !== 'string') skip = true;
  5067. else if (typeof url === 'string') {
  5068. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  5069. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  5070. skip = true;
  5071. } else if (turl.includes('.youtube.com/pagead/')) {
  5072. skip = true;
  5073. } else if (turl.includes('.youtube.com/ptracking')) {
  5074. skip = true;
  5075. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  5076. skip = true;
  5077. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  5078. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  5079. skip = true;
  5080. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  5081. skip = true;
  5082. } else {
  5083. // skip = true; // for user activity logging e.g. watched videos
  5084. }
  5085. } else if (turl.includes('play.google.com/log')) {
  5086. skip = true;
  5087. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  5088. skip = true;
  5089. }
  5090. }
  5091. if (!skip) {
  5092. this.__xmMc8__ = 1;
  5093. return super.open(method, url, ...args);
  5094. } else {
  5095. this.__xmMc8__ = 2;
  5096. return super.open('GET', url0);
  5097. }
  5098. }
  5099. send(...args) {
  5100. if (this.__xmMc8__ === 1) {
  5101. return super.send(...args);
  5102. } else if (this.__xmMc8__ === 2) {
  5103. return super.send();
  5104. } else {
  5105. console.log('[yt-js-engine-tamer]', 'xhr warning');
  5106. return super.send(...args);
  5107. }
  5108. }
  5109. }
  5110. c.prototype.__xmMc8__ = 0;
  5111. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  5112. return c;
  5113. })();
  5114. }
  5115.  
  5116. // Alternative HACK -> Tabview Youtube
  5117. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  5118.  
  5119. // ---- << this.overscrollConfig HACK >> -----
  5120.  
  5121. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  5122.  
  5123. /*
  5124.  
  5125. ;function gZb(a, b) {
  5126. b = void 0 === b ? !0 : b;
  5127. a.addEventListener("wheel", hZb);
  5128. a.overscrollConfig = {
  5129. cooldown: b
  5130. }
  5131. }
  5132. function iZb(a) {
  5133. a.overscrollConfig = void 0;
  5134. a.removeEventListener("wheel", hZb)
  5135. }
  5136. function hZb(a) {
  5137. var b = a.deltaY
  5138. , c = a.target
  5139. , d = null;
  5140. if (window.Polymer && window.Polymer.Element) {
  5141. if (c = a.path || a.composedPath && a.composedPath()) {
  5142. c = g(c);
  5143. for (var e = c.next(); !e.done && (e = e.value,
  5144. !jZb(e, b)); e = c.next())
  5145. if (e.overscrollConfig) {
  5146. d = e;
  5147. break
  5148. }
  5149. }
  5150. } else
  5151. for (; c && !jZb(c, b); ) {
  5152. if (c.overscrollConfig) {
  5153. d = c;
  5154. break
  5155. }
  5156. c = c.parentElement
  5157. }
  5158. d && (b = d.overscrollConfig,
  5159. b.cooldown ? (d = a.deltaY,
  5160. c = b.lastDeltaY || 0,
  5161. b.lastDeltaY = d,
  5162. e = b.lastStopped || 0,
  5163. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  5164. c = !1) : (d = e + 600,
  5165. c = !0) : (d = Date.now() + 600,
  5166. c = !0),
  5167. d > Date.now() && (a.preventDefault(),
  5168. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  5169. }
  5170. */
  5171.  
  5172. let wheelHandler = function (a) {
  5173. if (window.Polymer && window.Polymer.Element) {
  5174. let c;
  5175. if (c = a.path || a.composedPath && a.composedPath()) {
  5176. for (const e of c) {
  5177. const cnt = insp(e);
  5178. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5179. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5180. }
  5181. }
  5182. } else {
  5183. let e = a.target;
  5184. for (; e instanceof Element; e = e.parentElement) {
  5185. const cnt = insp(e);
  5186. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5187. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5188. }
  5189. }
  5190. };
  5191.  
  5192. let checkWheelListenerObjs = null;
  5193.  
  5194. let getObjsFn = () => {
  5195. let euyVal = 0;
  5196. const eukElm = {};
  5197. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  5198. const euzObj = new Proxy(eukElm, {
  5199. get(target, prop) {
  5200. throw `ErrorF31.get(${prop})`
  5201. },
  5202. set(target, prop, value) {
  5203. throw `ErrorF33.set(${prop}, ${value})`
  5204. }
  5205. });
  5206. const euxElm = new Proxy(eukElm, {
  5207. get(target, prop) {
  5208. if (prop === 'scrollTop') {
  5209. euyVal = euyVal | 8;
  5210. return 0;
  5211. }
  5212. if (prop === 'overscrollConfig') {
  5213. euyVal = euyVal | 16;
  5214. return void 0;
  5215. }
  5216. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  5217. return 640;
  5218. }
  5219. if (prop === 'scrollLeft') {
  5220. euyVal = euyVal | 8;
  5221. return 0;
  5222. }
  5223. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  5224. return 800;
  5225. }
  5226. throw `ErrorF45.get(${prop})`
  5227. },
  5228. set(target, prop, value) {
  5229. throw `ErrorF47.set(${prop}, ${value})`
  5230. }
  5231. });
  5232. const eukEvt = {};
  5233. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  5234. const euyEvt = new Proxy(eukEvt, {
  5235. get(target, prop) {
  5236. if (prop === 'deltaY' || prop === 'deltaX') {
  5237. euyVal = euyVal | 1;
  5238. return -999;
  5239. }
  5240. if (prop === 'target') {
  5241. euyVal = euyVal | 2;
  5242. return euxElm
  5243. }
  5244. if (prop === 'path' || prop === 'composedPath') {
  5245. euyVal = euyVal | 2;
  5246. return [euxElm]
  5247. }
  5248. throw `ErrorF51.get(${prop})`
  5249. },
  5250. set(target, prop, value) {
  5251. throw `ErrorF53.set(${prop}, ${value})`
  5252. }
  5253. });
  5254. const setVal = (v) => {
  5255. euyVal = v;
  5256. }
  5257. const getVal = () => {
  5258. return euyVal;
  5259. }
  5260. return { euzObj, euyEvt, setVal, getVal };
  5261. }
  5262.  
  5263. let checkWheelListener = (callback) => {
  5264.  
  5265. let callbackIdentifier = '';
  5266.  
  5267. let res = null;
  5268. try {
  5269. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  5270. setVal(0);
  5271. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  5272. throw `RESULT${getVal()}`;
  5273. } catch (e) {
  5274. res = e;
  5275. }
  5276.  
  5277. res = `${res}` || `${null}`;
  5278. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  5279.  
  5280. callbackIdentifier = res;
  5281. if (callbackIdentifier === 'RESULT27') 0;
  5282. else if (callbackIdentifier === 'RESULT0') {
  5283. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  5284. } else if (callbackIdentifier.startsWith('RESULT')) {
  5285. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  5286. }
  5287. return callbackIdentifier;
  5288.  
  5289. };
  5290.  
  5291. let callbackFound = false;
  5292. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  5293. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  5294. // M-youtube-js-engine-tamer.52178
  5295. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  5296. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  5297. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  5298. // RESULTXX / ErrorFXX / Other...
  5299. if (callbackIdentifier === 'RESULT27') {
  5300. this.overscrollConfigDisable = true;
  5301. if (!callbackFound) {
  5302. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  5303. getObjsFn = checkWheelListener = null;
  5304. checkWheelListenerObjs = null;
  5305. wheelHandler = null;
  5306. }
  5307. return void 0;
  5308. } else if (!callbackFound && !this.overscrollConfigDisable) {
  5309. this.overscrollConfigDisable = true;
  5310. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  5311. }
  5312. }
  5313. return this.addEventListener52178(type, callback, option);
  5314. };
  5315.  
  5316. // ---- << this.overscrollConfig HACK >> -----
  5317.  
  5318. }
  5319.  
  5320. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  5321.  
  5322. let p_a_objWR = null;
  5323. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  5324. let ytPageReady = 0;
  5325.  
  5326. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5327. let isGlobalSpaceControl = true;
  5328. let mediaPlayerElementWR = null;
  5329. let focusedElementAtSelection = null;
  5330.  
  5331. // let want_control_video = false;
  5332.  
  5333. let spaceBarControl_keyG = '';
  5334.  
  5335. let lastUserAction = 0;
  5336.  
  5337. const wmKeyControlPhase = new WeakMap();
  5338.  
  5339. let currentSelectionText = null;
  5340.  
  5341. const getCurrentSelectionText = () => {
  5342. if (currentSelectionText !== null) return currentSelectionText
  5343. return (currentSelectionText = `${getSelection()}`)
  5344. }
  5345.  
  5346. const pageMediaWatcher = () => {
  5347.  
  5348. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  5349. // want_control_video = false;
  5350. // }, { capture: true, passive: true });
  5351.  
  5352. document.addEventListener('yt-navigate', () => {
  5353. ytPageReady = 0;
  5354. });
  5355. document.addEventListener('yt-navigate-start', () => {
  5356. ytPageReady = 0;
  5357. });
  5358. document.addEventListener('yt-navigate-cache', () => {
  5359. ytPageReady = 0;
  5360. });
  5361.  
  5362. document.addEventListener('yt-navigate-finish', () => {
  5363. ytPageReady = 1;
  5364. });
  5365.  
  5366. document.addEventListener('durationchange', () => {
  5367. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  5368. if (elm.duration > 0.01) {
  5369. if (elm.closest('[hidden]')) continue;
  5370. mediaPlayerElementWR = mWeakRef(elm);
  5371. return;
  5372. }
  5373. }
  5374. }, { capture: true, passive: true });
  5375.  
  5376. document.addEventListener('selectionchange', (evt) => {
  5377. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  5378. currentSelectionText = null;
  5379. if (!(evt.target instanceof Node)) return;
  5380. focusedElementAtSelection = evt.target;
  5381. }, { capture: true, passive: true })
  5382.  
  5383. document.addEventListener('pointerdown', (evt) => {
  5384. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5385. }, { capture: true, passive: true });
  5386.  
  5387.  
  5388. document.addEventListener('pointerup', (evt) => {
  5389. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5390. }, { capture: true, passive: true });
  5391.  
  5392.  
  5393. document.addEventListener('keydown', (evt) => {
  5394. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5395. }, { capture: true, passive: true });
  5396.  
  5397. document.addEventListener('keyup', (evt) => {
  5398. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5399. }, { capture: true, passive: true });
  5400.  
  5401. };
  5402.  
  5403.  
  5404. const checkKeyB = (p_a_obj) => {
  5405.  
  5406. const boolList = new Set();
  5407. const p_a_obj_api = p_a_obj.api;
  5408.  
  5409. const nilFunc0 = function () {
  5410. return void 0
  5411. };
  5412. const mt = new Proxy({}, {
  5413. get(target, prop) {
  5414. if (prop === 'get') return nilFunc0;
  5415. return mt;
  5416. }
  5417. });
  5418. const nilFunc = function () {
  5419. return mt
  5420. };
  5421. const mw = new Proxy({}, {
  5422. get(target, prop) {
  5423. if (prop in p_a_obj_api) {
  5424. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  5425. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  5426. if (q && q.value) {
  5427. if (!q.writable) return q.value;
  5428. if (typeof q.value === 'string') return '';
  5429. if (typeof q.value === 'number') return 0;
  5430. if (typeof q.value === 'boolean') return false;
  5431. if (q.value && typeof q.value === 'object') return {};
  5432. }
  5433. }
  5434. return undefined;
  5435. },
  5436. set(target, prop) {
  5437. throw 'mwSet';
  5438. }
  5439. });
  5440.  
  5441. const mq = new Proxy({}, {
  5442. get(target, prop) {
  5443. if (prop === 'api') return mw;
  5444. if (prop in p_a_obj) {
  5445. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  5446. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  5447. if (q && q.value) {
  5448. if (!q.writable) return q.value;
  5449. if (typeof q.value === 'string') return '';
  5450. if (typeof q.value === 'number') return 0;
  5451. if (typeof q.value === 'boolean') return false;
  5452. if (q.value && typeof q.value === 'object') return {};
  5453. }
  5454. }
  5455. return undefined;
  5456. },
  5457. set(target, prop, val) {
  5458. if (typeof val === 'boolean') boolList.add(prop)
  5459. throw `mqSet(${prop},${val})`;
  5460. }
  5461. });
  5462.  
  5463. let res = ''
  5464. try {
  5465. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  5466. } catch (e) {
  5467. res = `ERROR::${e}`;
  5468. }
  5469.  
  5470. if (boolList.size === 1) {
  5471. const value = boolList.values().next().value;
  5472. if (res === `ERROR::mqSet(${value},${true})`) {
  5473. p_a_obj.__uZWaD__ = value;
  5474. }
  5475. }
  5476.  
  5477. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  5478.  
  5479. }
  5480.  
  5481.  
  5482. let pm_p_a = null;
  5483.  
  5484. const p_a_init = function () {
  5485. const r = this.init91();
  5486. const keyBw = this.__cPzfo__ || '__NIL__';
  5487. const p_a_obj = this[keyBw];
  5488. if (!p_a_obj) return;
  5489. try {
  5490. checkKeyB(p_a_obj);
  5491. } catch (e) { }
  5492. p_a_objWR = mWeakRef(p_a_obj);
  5493. if (FIX_SHORTCUTKEYS > 0) {
  5494. if (p_a_obj && !p_a_obj.hVhtg) {
  5495. p_a_obj.hVhtg = 1;
  5496.  
  5497. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  5498. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  5499. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  5500. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  5501. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  5502. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  5503.  
  5504. }
  5505. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  5506. // const api = p_a_obj.api
  5507. // api.hVhtg = 1;
  5508. // api.playVideo91 = api.playVideo;
  5509. // api.playVideo = p_a_jt.playVideo;
  5510. // api.pauseVideo91 = api.pauseVideo;
  5511. // api.pauseVideo = p_a_jt.pauseVideo;
  5512. // }
  5513. }
  5514. if (pm_p_a) {
  5515. pm_p_a.resolve();
  5516. pm_p_a = null;
  5517. }
  5518. return r;
  5519. };
  5520.  
  5521. const p_a_xt = {
  5522.  
  5523. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  5524.  
  5525. if (FIX_SHORTCUTKEYS === 2) {
  5526.  
  5527. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  5528.  
  5529. if (activeElement) {
  5530.  
  5531. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  5532.  
  5533. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  5534. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  5535. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  5536.  
  5537. }
  5538.  
  5539. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5540. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5541. // console.log(582, isDelayedSpaceBar)
  5542. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5543.  
  5544. if (activeElement && (h === 'Space' || h === 'Enter')) {
  5545. const controlPhase = wmKeyControlPhase.get(activeElement);
  5546. if (controlPhase === 4 || controlPhase === 5) return false;
  5547. }
  5548. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  5549. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  5550. // if (!isSpaceKeyImmediate) return false;
  5551. // }
  5552. }
  5553.  
  5554. },
  5555.  
  5556. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  5557.  
  5558. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  5559.  
  5560. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5561. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5562. // console.log(583, isDelayedSpaceBar)
  5563. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5564.  
  5565. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5566.  
  5567. let mediaWorking = false;
  5568. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  5569. mediaWorking = true;
  5570. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5571. mediaWorking = true;
  5572. }
  5573. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  5574. mediaWorking && Promise.resolve().then(() => {
  5575. if (activeElement === document.activeElement) {
  5576. return activeElement.blur()
  5577. } else {
  5578. return false
  5579. }
  5580. }).then((r) => {
  5581. r !== false && mediaPlayerElement.focus();
  5582. });
  5583. }
  5584. },
  5585.  
  5586.  
  5587. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  5588.  
  5589. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5590.  
  5591. const activeElement = document.activeElement;
  5592.  
  5593. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5594. if (allow === false) return false;
  5595.  
  5596. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5597. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  5598.  
  5599. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5600.  
  5601. return ret;
  5602. },
  5603. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  5604.  
  5605.  
  5606. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5607.  
  5608. const activeElement = document.activeElement;
  5609. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5610. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5611. // }
  5612. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5613. if (allow === false) return false;
  5614.  
  5615. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5616. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  5617.  
  5618. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5619.  
  5620. return ret;
  5621. }
  5622.  
  5623. };
  5624.  
  5625. let flagSpeedMaster = null;
  5626. const getSpeedMasterControlFlag = () => {
  5627.  
  5628. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5629. isSpeedMastSpacebarControlEnabled = false;
  5630. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  5631. isSpeedMastSpacebarControlEnabled = true;
  5632. }
  5633. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  5634. isSpeedMastSpacebarControlEnabled = true;
  5635. }
  5636.  
  5637. if (flagSpeedMaster === null) {
  5638. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  5639. if (!p) {
  5640. flagSpeedMaster = false;
  5641. } else {
  5642.  
  5643. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') /* && p.includes('web_speedmaster_updated_edu=true') */ );
  5644.  
  5645. }
  5646.  
  5647. }
  5648. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  5649.  
  5650. return isSpeedMastSpacebarControlEnabled;
  5651. }
  5652.  
  5653.  
  5654. const getGlobalSpacebarControlFlag = () => {
  5655.  
  5656. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5657. isGlobalSpaceControl = false;
  5658. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  5659. isGlobalSpaceControl = true;
  5660. }
  5661. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  5662. isGlobalSpaceControl = true;
  5663. }
  5664.  
  5665. return isGlobalSpaceControl;
  5666. }
  5667.  
  5668. const keyboardController = async (_yt_player) => {
  5669.  
  5670. const keyQT = getQT(_yt_player);
  5671. const keySV = getSV(_yt_player);
  5672. const keyDX = getDX(_yt_player);
  5673. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  5674.  
  5675. if (!keyDX) return;
  5676. if (keyDX === keyQT || keyDX === keySV) return;
  5677.  
  5678. if (typeof keyDX !== 'string') return;
  5679.  
  5680. let lastAccessKey = '';
  5681. let lastAccessKeyConfirmed = '';
  5682. const mb = new Proxy({}, {
  5683. get(target, prop) {
  5684. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  5685. throw 'mbGet'
  5686. },
  5687. set(target, prop, val) {
  5688. throw 'mbSet'
  5689. }
  5690. });
  5691. const ma = new Proxy({}, {
  5692. get(target, prop) {
  5693. lastAccessKey = prop;
  5694. return mb
  5695. },
  5696. set(target, prop, val) {
  5697. throw 'maSet'
  5698. }
  5699. });
  5700.  
  5701. let keyBw = '';
  5702. try {
  5703. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  5704. } catch (e) {
  5705. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  5706. keyBw = lastAccessKeyConfirmed;
  5707. }
  5708. }
  5709.  
  5710. if (!keyBw) return;
  5711.  
  5712. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  5713.  
  5714. pm_p_a = new PromiseExternal();
  5715.  
  5716. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  5717.  
  5718. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  5719.  
  5720. _yt_player[keyDX].prototype.init = p_a_init;
  5721.  
  5722. await pm_p_a.then();
  5723. const p_a_obj = kRef(p_a_objWR);
  5724.  
  5725. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  5726.  
  5727.  
  5728. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  5729.  
  5730. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  5731.  
  5732. if (!isSpeedMastSpacebarControlEnabled) {
  5733.  
  5734. if (config && config.EXPERIMENT_FLAGS) {
  5735. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  5736. }
  5737. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5738. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  5739. }
  5740.  
  5741. } else {
  5742.  
  5743. if (config && config.EXPERIMENT_FLAGS) {
  5744. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  5745. }
  5746. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5747. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  5748. }
  5749.  
  5750. }
  5751.  
  5752. }
  5753.  
  5754. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  5755.  
  5756.  
  5757.  
  5758.  
  5759. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  5760.  
  5761. // console.log(p_a_obj.handleGlobalKeyUp)
  5762. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  5763.  
  5764. // console.log(p_a_obj.api)
  5765.  
  5766.  
  5767. // QT -> DX(SV) -> p_a
  5768.  
  5769.  
  5770. /*
  5771. *
  5772. *
  5773. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5774. b = void 0 === b ? !1 : b;
  5775. c = void 0 === c ? !1 : c;
  5776. d = void 0 === d ? !1 : d;
  5777. e = void 0 === e ? !1 : e;
  5778. var l = g.PT(this);
  5779. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  5780. }
  5781.  
  5782. */
  5783.  
  5784. /*
  5785. *
  5786. *
  5787. *
  5788. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5789. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  5790. }
  5791.  
  5792. */
  5793.  
  5794.  
  5795. // if(!keyDX) return;
  5796.  
  5797. // console.log(4999, keyDX)
  5798.  
  5799. };
  5800.  
  5801.  
  5802. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  5803.  
  5804. const p_a_obj = kRef(p_a_objWR);
  5805. // const api = p_a_obj.api;
  5806.  
  5807.  
  5808. // console.log(540);
  5809.  
  5810. let boolList = null;
  5811. let ret;
  5812. isSpaceKeyImmediate = true;
  5813. try {
  5814.  
  5815. ret = 0;
  5816. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  5817. let p_a_objT;
  5818. if (!spaceBarControl_keyG) { // just in case
  5819. boolList = new Set();
  5820. p_a_objT = new Proxy(p_a_obj, {
  5821. get(target, prop, handler) {
  5822. const val = target[prop];
  5823. if (typeof val !== 'boolean') return val;
  5824. boolList.add(prop);
  5825. // console.log(555, prop, val);
  5826. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  5827. spaceBarControl_keyG = prop;
  5828. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5829. val = false;
  5830. }
  5831. return val;
  5832. }
  5833. });
  5834.  
  5835.  
  5836. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  5837. p_a_obj[spaceBarControl_keyG] = false;
  5838. p_a_objT = p_a_obj;
  5839. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  5840. } else {
  5841.  
  5842. p_a_objT = p_a_obj;
  5843. }
  5844.  
  5845. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  5846.  
  5847.  
  5848. } catch (e) {
  5849. console.log(e)
  5850. }
  5851. isSpaceKeyImmediate = false;
  5852.  
  5853. if (boolList && boolList.size === 1) {
  5854. const value = boolList.values().next().value;
  5855. spaceBarControl_keyG = value;
  5856. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5857.  
  5858. }
  5859.  
  5860. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5861.  
  5862. return ret;
  5863. }
  5864.  
  5865. const shortcutKeysFixer = () => {
  5866.  
  5867. let pausePromiseControlJ = 0;
  5868.  
  5869.  
  5870. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  5871.  
  5872. let controlPhase = 0;
  5873. const aElm = document.activeElement;
  5874.  
  5875. if (aElm) {
  5876.  
  5877. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  5878.  
  5879. if (typeof controlPhaseCache === 'number') {
  5880.  
  5881. controlPhase = controlPhaseCache;
  5882. } else {
  5883.  
  5884. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  5885. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  5886. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  5887. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  5888. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  5889. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  5890. else {
  5891. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  5892. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  5893. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  5894. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  5895. }
  5896.  
  5897. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  5898. controlPhase = 0;
  5899. }
  5900.  
  5901. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  5902. if (aElm.closest('[contenteditable], input, textarea')) {
  5903. controlPhase = 5;
  5904. } else if (aElm.closest('button')) {
  5905. controlPhase = 4;
  5906. }
  5907. }
  5908.  
  5909. if (aElm.closest('#movie_player')) controlPhase = 6;
  5910.  
  5911. wmKeyControlPhase.set(aElm, controlPhase);
  5912.  
  5913. }
  5914. }
  5915.  
  5916. return controlPhase;
  5917.  
  5918. }
  5919.  
  5920. const isStateControllable = (api) => {
  5921. let appState = null;
  5922. let playerState = null;
  5923. let adState = null;
  5924. try {
  5925. appState = api.getAppState();
  5926. playerState = api.getPlayerState();
  5927. adState = api.getAdState();
  5928. } catch (e) { }
  5929. // ignore playerState -1
  5930. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  5931. };
  5932.  
  5933.  
  5934. const keyEventListener = (evt) => {
  5935. if (BY_PASS_KEYBOARD_CONTROL) return;
  5936.  
  5937. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5938. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  5939. if (!ytPageReady) return;
  5940.  
  5941. if (evt.defaultPrevented === true) return;
  5942.  
  5943. const p_a_obj = kRef(p_a_objWR);
  5944.  
  5945. if (!p_a_obj) return;
  5946.  
  5947.  
  5948. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5949. if (!mediaPlayerElement) return;
  5950.  
  5951. // let focusBodyIfSuccess = false;
  5952.  
  5953. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  5954.  
  5955. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  5956. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  5957. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  5958.  
  5959.  
  5960. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  5961.  
  5962. // console.log(`${evt.type}::controlPhase`,controlPhase)
  5963.  
  5964. // if (controlPhase == 4) {
  5965. // focusBodyIfSuccess = true;
  5966. // }
  5967.  
  5968. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  5969. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5970.  
  5971. if (FIX_SHORTCUTKEYS < 2) return;
  5972. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  5973.  
  5974. let rr;
  5975. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  5976.  
  5977.  
  5978.  
  5979. let useImprovedPauseResume = false;
  5980.  
  5981. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5982.  
  5983. const api = p_a_obj.api;
  5984. const stateControllable = isStateControllable(api);
  5985. // console.log(2122, appState, playerState, adState)
  5986.  
  5987. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  5988.  
  5989. useImprovedPauseResume = true;
  5990.  
  5991. }
  5992.  
  5993.  
  5994. }
  5995.  
  5996.  
  5997. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5998. if (evt.type === 'keydown') {
  5999.  
  6000. if (useImprovedPauseResume) {
  6001.  
  6002. const isPaused = mediaPlayerElement.paused;
  6003.  
  6004. const cj = ++pausePromiseControlJ;
  6005. Promise.resolve().then(() => {
  6006.  
  6007. if (cj !== pausePromiseControlJ) return;
  6008.  
  6009. if (mediaPlayerElement.paused !== isPaused) return;
  6010.  
  6011. const ret = ytResumeFn();
  6012. if (!ret) { // fallback
  6013. isPaused ? api.playVideo() : api.pauseVideo();
  6014. }
  6015.  
  6016. /*
  6017. let a = void 0;
  6018. console.log('Rb', api.Rb())
  6019. a = !window._yt_player.nL(api.Rb());
  6020. p_a_obj.Wd.kG(a)
  6021. a ? api.playVideo() : api.pauseVideo();
  6022.  
  6023. */
  6024.  
  6025.  
  6026. });
  6027. rr = true;
  6028. } else {
  6029.  
  6030. isSpaceKeyImmediate = true;
  6031. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  6032. isSpaceKeyImmediate = false;
  6033. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6034.  
  6035. }
  6036.  
  6037.  
  6038. } else if (evt.type === 'keyup') {
  6039.  
  6040. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  6041.  
  6042. rr = true;
  6043. } else {
  6044.  
  6045. isSpaceKeyImmediate = true;
  6046. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  6047. isSpaceKeyImmediate = false;
  6048. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6049.  
  6050. }
  6051.  
  6052.  
  6053. /*
  6054.  
  6055. if (d)
  6056. switch (c) {
  6057. case 32:
  6058. case 13:
  6059. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  6060. b = !0,
  6061. e = !1;
  6062. else if (e) {
  6063. var m = d.getAttribute("role");
  6064. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  6065. d.click(),
  6066. f = !0)
  6067. }
  6068. break;
  6069. case 37:
  6070. case 39:
  6071. case 36:
  6072. case 35:
  6073. b = "slider" === d.getAttribute("role");
  6074. break;
  6075. case 38:
  6076. case 40:
  6077. m = d.getAttribute("role"),
  6078. d = 38 === c ? d.previousSibling : d.nextSibling,
  6079. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  6080. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  6081. f = b = !0))
  6082. }
  6083. if (e && !f)
  6084. switch (c) {
  6085. case 38:
  6086. f = Math.min(this.api.getVolume() + 5, 100);
  6087. XV(this.Wd, f, !1);
  6088. this.api.setVolume(f);
  6089. h = f = !0;
  6090. break;
  6091. case 40:
  6092. f = Math.max(this.api.getVolume() - 5, 0);
  6093. XV(this.Wd, f, !0);
  6094. this.api.setVolume(f);
  6095. h = f = !0;
  6096. break;
  6097. case 36:
  6098. this.api.Yh() && (this.api.startSeekCsiAction(),
  6099. this.api.seekTo(0, void 0, void 0, void 0, 79),
  6100. h = f = !0);
  6101. break;
  6102. case 35:
  6103. this.api.Yh() && (this.api.startSeekCsiAction(),
  6104. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  6105. h = f = !0)
  6106. }
  6107. */
  6108.  
  6109. }
  6110.  
  6111.  
  6112. if (rr) {
  6113.  
  6114. // focusBodyIfSuccess && Promise.resolve().then(() => {
  6115. // activeElement === document.activeElement && activeElement.blur();
  6116. // });
  6117.  
  6118. evt.preventDefault();
  6119. evt.stopImmediatePropagation();
  6120. evt.stopPropagation();
  6121.  
  6122. }
  6123.  
  6124. };
  6125.  
  6126. document.addEventListener('keydown', keyEventListener, { capture: true });
  6127.  
  6128.  
  6129. document.addEventListener('keyup', keyEventListener, { capture: true });
  6130.  
  6131. }
  6132.  
  6133. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  6134.  
  6135. })();
  6136.  
  6137.  
  6138. pageMediaWatcher();
  6139. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  6140.  
  6141.  
  6142. const check_for_set_key_order = (() => {
  6143.  
  6144. let mySet = new Set();
  6145.  
  6146. mySet.add("value1");
  6147. mySet.add("value2");
  6148. mySet.add("value3");
  6149.  
  6150. // Function to convert Set values to an array
  6151. function getSetValues(set) {
  6152. return Array.from(set.values());
  6153. }
  6154.  
  6155. // Function to test if the Set maintains insertion order
  6156. function testSetOrder(set, expectedOrder) {
  6157. let values = getSetValues(set);
  6158. return expectedOrder.join(',') === values.join(',');
  6159. }
  6160.  
  6161. // Test 1: Initial order
  6162. if (mySet.values().next().value !== "value1") return false;
  6163. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  6164.  
  6165. // Test 2: After deleting an element
  6166. mySet.delete("value2");
  6167. if (mySet.values().next().value !== "value1") return false;
  6168. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  6169.  
  6170. // Test 3: After re-adding a deleted element
  6171. mySet.add("value2");
  6172. if (mySet.values().next().value !== "value1") return false;
  6173. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  6174.  
  6175. // Test 4: After adding a new element
  6176. mySet.add("value4");
  6177. if (mySet.values().next().value !== "value1") return false;
  6178. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  6179.  
  6180. // Test 5: Delete+Add
  6181. mySet.delete("value1");
  6182. mySet.delete("value3");
  6183. mySet.add("value3");
  6184. mySet.add("value1");
  6185. if (mySet.values().next().value !== "value2") return false;
  6186. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  6187.  
  6188. return true;
  6189. })();
  6190.  
  6191.  
  6192. // const qm47 = Symbol();
  6193. // const qm57 = Symbol();
  6194. const qm53 = Symbol();
  6195. const qn53 = Symbol();
  6196.  
  6197.  
  6198. const ump3 = new WeakMap();
  6199.  
  6200. const stp = document.createElement('noscript');
  6201. stp.id = 'weakref-placeholder';
  6202.  
  6203. PROP_OverReInclusion_AVOID && (() => {
  6204.  
  6205.  
  6206. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  6207. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  6208. let byPassVal = null;
  6209. let byPassCount = 0;
  6210. let mmw = new Set();
  6211. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  6212. if (arguments.length !== 1) return f.apply(this, arguments);
  6213. if (byPassVal !== null && typeof prop === 'string') {
  6214.  
  6215. if (PROP_OverReInclusion_LIST.has(prop)) {
  6216. byPassCount++;
  6217. return byPassVal;
  6218. }
  6219. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  6220.  
  6221. }
  6222. return this.hasOwnProperty72(prop);
  6223. };
  6224.  
  6225.  
  6226. /*
  6227.  
  6228.  
  6229. z.prototype.forwardDynamicProps = function() {
  6230. var B = m(this.inst);
  6231. B = h(B);
  6232. for (var F = B.next(); !F.done; F = B.next()) {
  6233. var H = h(F.value);
  6234. F = H.next().value;
  6235. H = H.next().value;
  6236. my(this, F, H);
  6237. r(b) && !ly(F) && Wua(this.inst, F)
  6238. }
  6239. }
  6240.  
  6241. */
  6242.  
  6243.  
  6244.  
  6245. let byPassZeroShowed = false;
  6246. const forwardDynamicPropsGeneral = function () {
  6247. byPassVal = true;
  6248. byPassCount = 0;
  6249. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  6250. const ret = this.forwardDynamicProps72();
  6251. byPassVal = null;
  6252. if (byPassCount === 0 && !byPassZeroShowed) {
  6253. byPassZeroShowed = true;
  6254. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  6255. }
  6256. byPassCount = 0;
  6257. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  6258. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  6259. mmw.clear();
  6260. }
  6261. return ret;
  6262. };
  6263.  
  6264. const propCheck = (proto) => {
  6265. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  6266. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  6267. if (proto.forwardDynamicProps.length === 0) {
  6268. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  6269. }
  6270. }
  6271. };
  6272.  
  6273. const valMap = new WeakMap();
  6274. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  6275. get() {
  6276. propCheck(this.constructor.prototype);
  6277. return valMap.get(this);
  6278. },
  6279. set(nv) {
  6280. propCheck(this.constructor.prototype);
  6281. valMap.set(this, nv);
  6282. return true;
  6283. },
  6284. enumerable: false,
  6285. configurable: true
  6286.  
  6287. });
  6288.  
  6289. promiseForCustomYtElementsReady.then(() => {
  6290. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  6291. if (customElements.define.length !== 2) return;
  6292. customElements.define72 = customElements.define;
  6293. customElements.define = function (b, w) {
  6294. propCheck(w.prototype);
  6295. const ret = this.define72(b, w);
  6296. return ret;
  6297. }
  6298. });
  6299.  
  6300. })();
  6301.  
  6302. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  6303.  
  6304. const flexibleItemListMo = new MutationObserver((mutations) => {
  6305. // cnt.onStamperFinished
  6306. // cnt.maybeUpdateFlexibleMenu
  6307. const set = new Set();
  6308. for (const mutation of mutations) {
  6309. if (mutation && ((mutation.addedNodes || 0).length > 0 || (mutation.removedNodes || 0).length > 0)) {
  6310. set.add(mutation.target);
  6311. }
  6312. }
  6313. for (const s of set) {
  6314. const cnt = insp(s);
  6315. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  6316. cnt.maybeUpdateFlexibleMenuImpl();
  6317. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  6318. cnt.maybeUpdateFlexibleMenu();
  6319. } else if (typeof cnt.onStamperFinished === 'function') {
  6320. cnt.onStamperFinished();
  6321. }
  6322. }
  6323. set.clear();
  6324. });
  6325.  
  6326. let checkConfig = true;
  6327. const flexibleItemDocMo = new MutationObserver(() => {
  6328. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  6329. s.setAttribute('b289ad', '');
  6330. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  6331. s.appendChild(document.createComment('.')).remove();
  6332. }
  6333. if (checkConfig) {
  6334. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6335. if (config && config.EXPERIMENT_FLAGS) {
  6336. checkConfig = false;
  6337. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  6338. }
  6339. }
  6340. });
  6341. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  6342.  
  6343. }
  6344.  
  6345.  
  6346.  
  6347.  
  6348. const observablePromise = (proc, timeoutPromise) => {
  6349. let promise = null;
  6350. return {
  6351. obtain() {
  6352. if (!promise) {
  6353. promise = new Promise(resolve => {
  6354. let mo = null;
  6355. const f = () => {
  6356. let t = proc();
  6357. if (t) {
  6358. mo.disconnect();
  6359. mo.takeRecords();
  6360. mo = null;
  6361. resolve(t);
  6362. }
  6363. }
  6364. mo = new MutationObserver(f);
  6365. mo.observe(document, { subtree: true, childList: true })
  6366. f();
  6367. timeoutPromise && timeoutPromise.then(() => {
  6368. resolve(null)
  6369. });
  6370. });
  6371. }
  6372. return promise
  6373. }
  6374. }
  6375. }
  6376.  
  6377.  
  6378. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  6379. observablePromise(() => {
  6380. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6381. if (config && config.EXPERIMENT_FLAGS) {
  6382. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  6383. return true;
  6384. }
  6385. }).obtain();
  6386. }
  6387.  
  6388. if (FIX_ROLLING_NUMBER_UPDATE) {
  6389.  
  6390.  
  6391. observablePromise(() => {
  6392. if (typeof customElements === 'undefined') return;
  6393. const ce = customElements.get('yt-animated-rolling-number');
  6394. if (!ce) return;
  6395. return ce.prototype;
  6396. }).obtain().then(async (cProto) => {
  6397.  
  6398. const p = document.createElement('yt-animated-rolling-number');
  6399.  
  6400. const frag = document.createDocumentFragment();
  6401. frag.appendChild(p);
  6402. const pDoc = document.implementation.createHTMLDocument();
  6403. pDoc.body.appendChild(frag);
  6404.  
  6405. let p88 = p;
  6406.  
  6407. const __instance = await observablePromise(() => {
  6408. const __instance = (p88 || 0).__instance;
  6409. if (__instance && __instance.render) return __instance;
  6410. }).obtain();
  6411. p88 = null;
  6412.  
  6413. const itProto = Reflect.getPrototypeOf(__instance);
  6414.  
  6415. try {
  6416. p.remove();
  6417. } catch (e) { }
  6418.  
  6419. if (itProto.render && !itProto.render37 && itProto.render.length === 1) {
  6420.  
  6421. itProto.render37 = itProto.render;
  6422. itProto.render = function (t) {
  6423. // (this.xCounter = (this.xCounter & 1073741823)+1)
  6424. let c33 = '';
  6425. let r33 = null;
  6426. let kc = 0;
  6427.  
  6428. let dataType = 0;
  6429.  
  6430. if (t && (('data' in t) || ('buttonShapeOverrideables' in t))) {
  6431. dataType = 1;
  6432. } else if (t && ('heightPx' in t)) {
  6433. dataType = 2;
  6434. } else if (t) {
  6435. dataType = 3;
  6436. }
  6437.  
  6438. if (dataType === 3 && this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  6439. const el = this.el;
  6440. const ct = Date.now();
  6441. const lastFireTime = (el.__lastFireTime491__ || 0);
  6442.  
  6443. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  6444.  
  6445. if (fireTimeDiff < 80 && this.__previousRender61__) {
  6446. return this.__previousRender61__;
  6447. }
  6448.  
  6449. // console.log(3772, t);
  6450.  
  6451. const caseInt =
  6452. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  6453. (t && typeof t.character === 'string') ? (
  6454. (typeof t.previousCharacter === 'string') ? 6 : 2
  6455. ) : 0;
  6456.  
  6457. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender61__ && fireTimeDiff < 9400) {
  6458. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender61__) {
  6459. return this.__previousRender61__;
  6460. }
  6461. }
  6462. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender61__ && fireTimeDiff < 9400) {
  6463. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender61__) {
  6464. return this.__previousRender61__;
  6465. }
  6466. }
  6467.  
  6468. if (caseInt & 2) {
  6469.  
  6470. if (caseInt & 4) {
  6471.  
  6472. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  6473. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  6474. t.previousCharacter = t.character;
  6475. kc = 1;
  6476. }
  6477. }
  6478.  
  6479. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  6480. t.shouldAnimate = false;
  6481. }
  6482. }
  6483.  
  6484.  
  6485. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  6486.  
  6487. el.__lastCharacter353__ = t.character;
  6488.  
  6489. } else if (caseInt === 1) {
  6490.  
  6491. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  6492. t.shouldAnimate = false;
  6493. }
  6494. el.__lastNumberValue353__ = t.numberValue;
  6495.  
  6496. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  6497. t.shouldAnimate = false;
  6498. }
  6499. el.__lastNumberText353__ = t.numberText;
  6500.  
  6501. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  6502.  
  6503. }
  6504.  
  6505. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  6506.  
  6507. el.__lastFireTime491__ = ct;
  6508. } else if (dataType === 2 && this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  6509. const el = this.el;
  6510. const ct = Date.now();
  6511. const lastFireTime = (el.__lastFireTime493__ || 0);
  6512.  
  6513. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  6514.  
  6515. if (fireTimeDiff < 80 && this.__previousRender63__) {
  6516. return this.__previousRender63__;
  6517. }
  6518.  
  6519. // console.log(3772, t);
  6520.  
  6521. const caseInt =
  6522. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  6523. (t && typeof t.character === 'string') ? (
  6524. (typeof t.previousCharacter === 'string') ? 6 : 2
  6525. ) : 0;
  6526.  
  6527. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender63__ && fireTimeDiff < 9400) {
  6528. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender63__) {
  6529. return this.__previousRender63__;
  6530. }
  6531. }
  6532. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender63__ && fireTimeDiff < 9400) {
  6533. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender63__) {
  6534. return this.__previousRender63__;
  6535. }
  6536. }
  6537.  
  6538. if (caseInt & 2) {
  6539.  
  6540. if (caseInt & 4) {
  6541.  
  6542. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  6543. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  6544. t.previousCharacter = t.character;
  6545. kc = 1;
  6546. }
  6547. }
  6548.  
  6549. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  6550. t.shouldAnimate = false;
  6551. }
  6552. }
  6553.  
  6554.  
  6555. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  6556.  
  6557. el.__lastCharacter353__ = t.character;
  6558.  
  6559. } else if (caseInt === 1) {
  6560.  
  6561. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  6562. t.shouldAnimate = false;
  6563. }
  6564. el.__lastNumberValue353__ = t.numberValue;
  6565.  
  6566. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  6567. t.shouldAnimate = false;
  6568. }
  6569. el.__lastNumberText353__ = t.numberText;
  6570.  
  6571. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  6572.  
  6573. }
  6574.  
  6575. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  6576.  
  6577. el.__lastFireTime493__ = ct;
  6578. }
  6579.  
  6580. // // console.log(21399, t.character, t.previousCharacter, (t.xCounter = (t.xCounter & 1073741823)+1), t, (this.xCounter = (this.xCounter & 1073741823)+1) )
  6581. // // console.log(12883, this, t);
  6582. const r = r33 || this.render37(t);
  6583. if (dataType === 3) {
  6584. this.__previousRender61__ = r;
  6585. } else if (dataType === 2) {
  6586. this.__previousRender63__ = r;
  6587. }
  6588. if (c33) this[c33] = r;
  6589. return r
  6590. }
  6591.  
  6592. }
  6593.  
  6594. });
  6595.  
  6596. }
  6597.  
  6598. if (HOOK_ACTIVE_MODULES) {
  6599.  
  6600. let watchController;
  6601. const watchControllerObservable = observablePromise(() => {
  6602. const watchFlexy = document.querySelector('ytd-watch-flexy');
  6603. if (!watchFlexy) return;
  6604. return insp(watchFlexy).watchController;
  6605. }).obtain();
  6606. (async () => {
  6607. watchController = await watchControllerObservable;
  6608.  
  6609. const activeModules = watchController.activeModules;
  6610. if (!activeModules) return;
  6611.  
  6612. const checkFn = (activeModule) => {
  6613. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  6614. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  6615. }
  6616. }
  6617. if (!activeModules.push8792 && activeModules.push) {
  6618. activeModules.push8792 = activeModules.push;
  6619. activeModules.push = function (a, ...args) {
  6620. checkFn(a);
  6621. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  6622. return r;
  6623. }
  6624. }
  6625. activeModules.forEach(checkFn);
  6626.  
  6627. })();
  6628.  
  6629. let yieldResultWrappingByPass = false;
  6630. let asyncProto = null;
  6631. const yieldResultWrapping = (f) => {
  6632. if (yieldResultWrappingByPass) return [f(), null];
  6633. yieldResultWrappingByPass = true;
  6634. let D = null;
  6635. let promise, e_;
  6636. if (asyncProto) {
  6637. Object.defineProperty(asyncProto, 'yieldResult', {
  6638. get() {
  6639. return undefined;
  6640. },
  6641. set(nv) {
  6642. delete asyncProto.yieldResult;
  6643. this.yieldResult = nv;
  6644. D = this;
  6645. // console.log(122, this);
  6646. return true;
  6647. },
  6648. enumerable: false,
  6649. configurable: true
  6650. });
  6651. try {
  6652. promise = f();
  6653. } catch (e) { e_ = e }
  6654. delete asyncProto.yieldResult;
  6655. yieldResultWrappingByPass = false;
  6656. } else {
  6657. Object.defineProperty(Object.prototype, 'yieldResult', {
  6658. get() {
  6659. return undefined;
  6660. },
  6661. set(nv) {
  6662. delete Object.prototype.yieldResult;
  6663. this.yieldResult = nv;
  6664. D = this;
  6665. // console.log(122, this);
  6666. return true;
  6667. },
  6668. enumerable: false,
  6669. configurable: true
  6670. });
  6671. try {
  6672. promise = f();
  6673. } catch (e) { e_ = e }
  6674. delete Object.prototype.yieldResult;
  6675. yieldResultWrappingByPass = false;
  6676. if (D) {
  6677. asyncProto = Reflect.getPrototypeOf(D);
  6678. }
  6679. }
  6680. if (e_) throw e_;
  6681. return [promise, D];
  6682. }
  6683.  
  6684. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  6685.  
  6686. const aProto = Reflect.getPrototypeOf(activeModule);
  6687.  
  6688. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  6689.  
  6690. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  6691.  
  6692. // console.log(12885)
  6693. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  6694. // let qxt=false;
  6695. const renderLikeButtonViewModel = (likeButtonViewModel) => {
  6696. if (!likeButtonViewModel || likeButtonViewModel.isConnected !== true) return;
  6697. if (likeButtonViewModel.querySelector('yt-animated-rolling-number')) return; // no need to render
  6698. let likeModelInstance = null, t;
  6699. if ((t = likeButtonViewModel.__instance) && t.props) likeModelInstance = t;
  6700. else if ((t = likeButtonViewModel.instance) && t.props) likeModelInstance = t;
  6701. else if ((t = insp(likeButtonViewModel)) && t.props) likeModelInstance = t;
  6702. else if ((t = (likeButtonViewModel)) && t.props) likeModelInstance = t;
  6703. const props = (likeModelInstance || 0).props;
  6704. if (likeModelInstance && likeModelInstance.render && props) {
  6705. const data = (props || 0).data;
  6706. if (data && data.toggleButtonViewModel && props.likeCountEntity) {
  6707. likeModelInstance.render(props)
  6708. // likeModelInstance.functionComponent(props);
  6709. }
  6710. }
  6711. }
  6712. aProto.fetchUpdatedMetadata = function (t, P) {
  6713.  
  6714. // if (!qxt) {
  6715. // qxt = true;
  6716. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  6717. // console.log(199001,...args)
  6718. // });
  6719. // this.addOnDisposeCallback(function (...args) {
  6720.  
  6721. // console.log(199002,...args)
  6722. // watchController.unsubscribeByKey(y)
  6723. // qxt = false;
  6724. // });
  6725. // }
  6726. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  6727. if (D) promise.then(() => {
  6728. const yieldResult = D.yieldResult;
  6729. if (yieldResult) {
  6730. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  6731. const mutations_ = mutations.slice(); // array clone
  6732. if (mutations_ && mutations_.length >= 1) {
  6733. let likeCountEntity = null;
  6734. for (const mutation of mutations_) {
  6735. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  6736. break;
  6737. }
  6738. }
  6739. if (likeCountEntity) {
  6740. const modelElement = document.querySelector('segmented-like-dislike-button-view-model');
  6741. const model = insp(modelElement);
  6742. if (model && typeof model.update === 'function' && model.update.length === 0) {
  6743. const data = ((model || 0).props || 0).data;
  6744. if (data) {
  6745. if (typeof data.likeCountEntity !== 'object') data.likeCountEntity = {};
  6746. // console.log(12838, {...data.likeCountEntity}, {...likeCountEntity})
  6747. // const shouldModelUpdate = (data.likeCountEntity.key !== likeCountEntity.key); // to be reviewed
  6748. const shouldModelUpdate = true;
  6749. Object.assign(data.likeCountEntity, likeCountEntity);
  6750. // data.likeCountEntity = likeCountEntity;
  6751. // if (shouldModelupdate) model.update();
  6752. // else {
  6753. // if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  6754. // }
  6755. if (shouldModelUpdate) {
  6756. // if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  6757. // // console.log('kk1a enqueueUpdate')
  6758. // model.enqueueUpdate();
  6759. // // console.log('kk1b enqueueUpdate')
  6760. // } else if (typeof model.update === 'function' && model.update.length === 0) {
  6761. // // console.log('kk2a update')
  6762. // model.update();
  6763. // // console.log('kk2b update')
  6764. // } else {
  6765. // console.warn('[yt-js-engine-tamer] cannot do model update.')
  6766. // }
  6767.  
  6768. const likeButtonViewModel = modelElement.querySelector('like-button-view-model[class]');
  6769. if (likeButtonViewModel) {
  6770. renderLikeButtonViewModel(likeButtonViewModel);
  6771. // Promise.resolve(likeButtonViewModel).then(renderLikeButtonViewModel);
  6772. } else {
  6773. // seem not working. to be further reviewed with web_enable_sink_like_button_view_model
  6774. if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  6775. // console.log('kk1a enqueueUpdate')
  6776. model.enqueueUpdate();
  6777. // console.log('kk1b enqueueUpdate')
  6778. } else if (typeof model.update === 'function' && model.update.length === 0) {
  6779. // console.log('kk2a update')
  6780. model.update();
  6781. // console.log('kk2b update')
  6782. } else {
  6783. console.warn('[yt-js-engine-tamer] cannot do model update.')
  6784. }
  6785.  
  6786. }
  6787.  
  6788. }
  6789.  
  6790. }
  6791. }
  6792. }
  6793. }
  6794. }
  6795. }).catch(console.warn);
  6796. return promise;
  6797. };
  6798.  
  6799. }
  6800.  
  6801. }
  6802.  
  6803. // ----------------------------
  6804.  
  6805. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  6806.  
  6807. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  6808.  
  6809. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  6810.  
  6811.  
  6812. // const globalPromiseStack = {};
  6813.  
  6814. // let dummy;
  6815. // while(!dummy){
  6816.  
  6817. // dummy = document.querySelector('yt-icon');
  6818. // await new Promise(r=>setTimeout(r,0));
  6819. // }
  6820.  
  6821. dummy = document.createElement('yt-icon');
  6822.  
  6823. let cProto;
  6824. if (!(dummy instanceof Element)) return;
  6825. cProto = insp(dummy).constructor.prototype;
  6826.  
  6827. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  6828. cProto.determineIconSet671 = cProto.determineIconSet;
  6829. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  6830. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  6831. cProto.getIconManager671 = cProto.getIconManager;
  6832. cProto.getIconShapeData671 = cProto.getIconShapeData;
  6833. cProto.renderIcon671 = cProto.renderIcon;
  6834.  
  6835. // cProto.attached488 = cProto.attached;
  6836. // cProto.attached = function(){
  6837. // console.log('attached')
  6838. // return this.attached488(...arguments);
  6839. // }
  6840. // cProto.detached488 = cProto.detached;
  6841. // cProto.detached = function(){
  6842. // console.log('detached')
  6843. // return this.detached488(...arguments);
  6844. // }
  6845.  
  6846. if (cProto.__renderIconFix__) return;
  6847. cProto.__renderIconFix__ = true;
  6848.  
  6849. let taskStack = [];
  6850. const cmObs = new MutationObserver(() => {
  6851. const tasks = taskStack.slice();
  6852. taskStack.length = 0;
  6853. for (const task of tasks) {
  6854. task();
  6855. }
  6856. })
  6857. const cm = document.createComment('1');
  6858. const stackTask = (f) => {
  6859. taskStack.push(f);
  6860. cm.data = `${(cm.data & 7) + 1}`;
  6861. }
  6862. cmObs.observe(cm, { characterData: true });
  6863.  
  6864. // let iconManagers = {}; // assume shared
  6865.  
  6866. // window.iconManagers = () => iconManagers;
  6867.  
  6868.  
  6869. const setupYtIcon = (inst) => {
  6870.  
  6871. if (inst.__ytIconSetup588__) return;
  6872. const cProto = Reflect.getPrototypeOf(inst);
  6873. cProto.__ytIconSetup588__ = true;
  6874.  
  6875.  
  6876. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6877.  
  6878. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  6879. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  6880. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  6881. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  6882.  
  6883.  
  6884. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  6885. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  6886. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  6887. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  6888.  
  6889.  
  6890.  
  6891. }
  6892.  
  6893. cProto.handlePropertyChange = function (...a) { // 10+
  6894.  
  6895. const __data = this.__data;
  6896. if (FIX_GUIDE_ICON && this.id === 'guide-icon' && __data && !__data.icon && typeof this.set === 'function') {
  6897. this.set('icon', "yt-icons:menu")
  6898. }
  6899.  
  6900. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6901. this.__resolved__ = {
  6902.  
  6903. };
  6904. const a01 = this.isAttached;
  6905. let a02, a03;
  6906.  
  6907.  
  6908. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  6909.  
  6910. const stackFn = () => {
  6911. if (t !== this.__stackedKey3818__) {
  6912. return;
  6913. }
  6914. a03 = this.isAttached;
  6915.  
  6916. if (a01 === false && a02 === false && a03 === false) return;
  6917.  
  6918. if (a01 === true && a02 === true && a03 === true) {
  6919.  
  6920. } else {
  6921. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  6922. // unknown yt-icon#label-icon
  6923. return;
  6924. } else {
  6925. console.log('[yt-icon] debug', a01, a02, a03, this)
  6926. }
  6927. }
  6928.  
  6929. this.handlePropertyChange671(...arguments);
  6930.  
  6931. };
  6932.  
  6933.  
  6934.  
  6935. Promise.resolve().then(() => {
  6936. a02 = this.isAttached;
  6937. stackTask(stackFn);
  6938. });
  6939.  
  6940.  
  6941. }
  6942.  
  6943. cProto.determineIconSet = function (a, b, c, d) { // 10-
  6944.  
  6945. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6946. // string bool? bool=false int=24
  6947. // NOTIFICATIONS_NONE OR LIKE
  6948. // console.log('yt-icon.determineIconSet', ...arguments);
  6949.  
  6950. const r = this.determineIconSet671(...arguments);
  6951. return r;
  6952. }
  6953.  
  6954. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  6955.  
  6956. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6957. // same as determineIconSet
  6958. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  6959. return this.switchToYtSysIconset671(...arguments);
  6960. }
  6961.  
  6962. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  6963.  
  6964. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6965. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  6966. return this.useYtSysIconsetForMissingIcons671(...arguments);
  6967. }
  6968.  
  6969. cProto.getIconManager = function () { // 10+
  6970.  
  6971. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6972. if (!this.__resolved__) this.__resolved__ = {};
  6973. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  6974. const r = this.__resolved__.getIconManager;
  6975. return r;
  6976. }
  6977.  
  6978. cProto.getIconShapeData = function () { // 10+
  6979.  
  6980. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6981.  
  6982. // no argument
  6983. // console.log('yt-icon.getIconShapeData', ...arguments);
  6984. if (!this.__resolved__) this.__resolved__ = {};
  6985. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  6986. const r = this.__resolved__.getIconShapeData;
  6987. return r
  6988. }
  6989.  
  6990. cProto.renderIcon = function (a, b) { // X
  6991.  
  6992. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6993. // "" yt-icons:xxx
  6994. // console.log('yt-icon.renderIcon', ...arguments);
  6995. return this.renderIcon671(...arguments);
  6996. }
  6997.  
  6998. });
  6999.  
  7000.  
  7001. /**
  7002. * Compute the Longest Common Subsequence between two arrays.
  7003. * Returns an array of the LCS elements (in order).
  7004. */
  7005. function computeLCS(a, b) {
  7006. // Input validation
  7007. if (!Array.isArray(a) || !Array.isArray(b)) {
  7008. throw new Error('Inputs must be arrays');
  7009. }
  7010.  
  7011. const n = a.length, m = b.length;
  7012. // Early termination for trivial cases
  7013. if (n === 0 || m === 0) return [];
  7014. // Check for shallow equality
  7015. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  7016.  
  7017. // Use smaller dimension for space optimization
  7018. if (n > m) return computeLCS(b, a); // Ensure n <= m
  7019.  
  7020. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  7021. // Use Uint32Array for robustness with long sequences
  7022. const dp = [
  7023. new Uint32Array(m + 1),
  7024. new Uint32Array(m + 1),
  7025. ];
  7026. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  7027. // Optimize space by storing only necessary entries
  7028. const pred = new Uint8Array(n * m); // Single array for moves
  7029.  
  7030. for (let i = n - 1; i >= 0; i--) {
  7031. const curr = i % 2;
  7032. const next = 1 - curr;
  7033. // Clear current row for reuse
  7034. dp[curr].fill(0);
  7035.  
  7036. for (let j = m - 1; j >= 0; j--) {
  7037. const idx = i * m + j;
  7038. if (a[i] === b[j]) {
  7039. dp[curr][j] = dp[next][j + 1] + 1;
  7040. pred[idx] = 0; // Diagonal
  7041. } else if (dp[next][j] >= dp[curr][j + 1]) {
  7042. dp[curr][j] = dp[next][j];
  7043. pred[idx] = 1; // Down
  7044. } else {
  7045. dp[curr][j] = dp[curr][j + 1];
  7046. pred[idx] = 2; // Right
  7047. }
  7048. }
  7049. }
  7050.  
  7051. // Check for potential overflow
  7052. if (dp[0][0] > 0xFFFFFFFF) {
  7053. throw new Error('LCS length exceeds safe integer limit');
  7054. }
  7055.  
  7056. // Backtrack to build the actual LCS
  7057. const lcs = [];
  7058. let i = 0, j = 0;
  7059. while (i < n && j < m) {
  7060. const idx = i * m + j;
  7061. const p = pred[idx];
  7062. if (p === 0) {
  7063. lcs.push(a[i]);
  7064. i++; j++;
  7065. } else if (p === 1) {
  7066. i++;
  7067. } else {
  7068. j++;
  7069. }
  7070. }
  7071. return lcs;
  7072. }
  7073.  
  7074. /**
  7075. * Given original[] and modified[], produce an array of splice-ops:
  7076. * [ [start0, deleteCount0, addedItems0],
  7077. * [start1, deleteCount1, addedItems1],
  7078. * … ]
  7079. * When you do:
  7080. * let arr = original.slice();
  7081. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  7082. * arr will equal modified.
  7083. */
  7084. function diffSplices(original, modified) {
  7085. // Input validation
  7086. if (!Array.isArray(original) || !Array.isArray(modified)) {
  7087. throw new Error('Inputs must be arrays');
  7088. }
  7089.  
  7090. const origLen = original.length;
  7091. const modLen = modified.length;
  7092. // Early termination for trivial cases
  7093. if (origLen === 0 && modLen === 0) return [];
  7094. if (origLen === 0) return [[0, 0, modified.slice()]];
  7095. if (modLen === 0) return [[0, origLen, []]];
  7096.  
  7097. // Trim common prefix and suffix
  7098. let prefixLen = 0;
  7099. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  7100. prefixLen++;
  7101. }
  7102. let suffixLen = 0;
  7103. while (
  7104. suffixLen < origLen - prefixLen &&
  7105. suffixLen < modLen - prefixLen &&
  7106. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  7107. ) {
  7108. suffixLen++;
  7109. }
  7110.  
  7111. // Cache references for speed
  7112. const orig = original.slice(prefixLen, origLen - suffixLen);
  7113. const mod = modified.slice(prefixLen, modLen - suffixLen);
  7114. const lcs = computeLCS(orig, mod);
  7115. // Pre-allocate ops array, accounting for potential moves
  7116. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  7117. let opCount = 0;
  7118.  
  7119. let i = 0, j = 0, k = 0;
  7120. let curIndex = prefixLen;
  7121. const lcsLen = lcs.length;
  7122.  
  7123. while (k < lcsLen) {
  7124. const match = lcs[k];
  7125. let deleteCount = 0;
  7126. const deleted = [];
  7127. const added = [];
  7128.  
  7129. // 1) Collect deletions up to the next common element
  7130. while (i < orig.length && orig[i] !== match) {
  7131. deleted.push(orig[i]);
  7132. deleteCount++;
  7133. i++;
  7134. }
  7135.  
  7136. // 2) Collect insertions up to that same element
  7137. while (j < mod.length && mod[j] !== match) {
  7138. added.push(mod[j]);
  7139. j++;
  7140. }
  7141.  
  7142. // 3) Check for a move (deleted segment matches inserted segment)
  7143. let isMove = false;
  7144. if (deleteCount > 0 && deleteCount === added.length) {
  7145. isMove = deleted.every((x, idx) => x === added[idx]);
  7146. if (isMove) {
  7147. // If a move, split into delete and insert at different indices
  7148. if (deleteCount > 0) {
  7149. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  7150. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  7151. curIndex += added.length; // Advance past inserted items
  7152. }
  7153. }
  7154. }
  7155.  
  7156. // 4) Combine delete and insert into a single operation if not a move
  7157. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  7158. ops[opCount++] = [curIndex, deleteCount, added];
  7159. curIndex += added.length; // Advance past inserted items
  7160. }
  7161.  
  7162. // 5) Skip over the matching element itself
  7163. i++;
  7164. j++;
  7165. k++;
  7166. curIndex++;
  7167. }
  7168.  
  7169. // 6) Handle any trailing deletions and insertions as a single operation
  7170. const trailingDelete = orig.length - i;
  7171. const trailingAdd = mod.slice(j);
  7172. if (trailingDelete > 0 || trailingAdd.length > 0) {
  7173. // Check for trailing move
  7174. const trailingDeleted = orig.slice(i);
  7175. let isMove = false;
  7176. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  7177. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  7178. if (isMove) {
  7179. ops[opCount++] = [curIndex, trailingDelete, []];
  7180. ops[opCount++] = [curIndex, 0, trailingAdd];
  7181. }
  7182. }
  7183. if (!isMove) {
  7184. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  7185. }
  7186. }
  7187.  
  7188. // 7) Truncate ops array to actual size
  7189. ops.length = opCount;
  7190.  
  7191. return ops;
  7192. }
  7193. // class listPlaceholder {
  7194. // constructor(len){
  7195. // this.length = len;
  7196. // }
  7197. // }
  7198.  
  7199.  
  7200.  
  7201. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  7202. // var renderJob = this.renderJobsMap_[key],
  7203. // renderCallback = null;
  7204.  
  7205. // if (path === changeRecord.path) {
  7206. // let value = changeRecord.value;
  7207.  
  7208. // if (!_.v_(value)) {
  7209. // value = (value === void 0 || value === null) ? [] : [value];
  7210. // }
  7211.  
  7212. // let stampDomEntry = this.stampDom[path];
  7213.  
  7214. // if (stampDomEntry.mapping) {
  7215. // renderCallback = this.stampDomArray_.bind(
  7216. // this,
  7217. // value,
  7218. // key,
  7219. // stampDomEntry.mapping,
  7220. // stampDomEntry.reuseComponents,
  7221. // stampDomEntry.events,
  7222. // stampDomEntry.stamperStableList
  7223. // );
  7224. // }
  7225.  
  7226. // if (renderJob) renderJob.cancel();
  7227.  
  7228. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  7229.  
  7230. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  7231. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  7232. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  7233. // this.renderJobsMap_[key] = renderJob;
  7234. // }
  7235. // } else {
  7236. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  7237. // this.renderJobsMap_[key] = renderJob;
  7238. // renderCallback = function(callback, job) {
  7239. // callback();
  7240. // q4C(job, 10);
  7241. // }.bind(this, renderCallback, renderJob);
  7242. // }
  7243. // } else {
  7244. // renderCallback = (path + ".splices" === changeRecord.path)
  7245. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  7246. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  7247. // }
  7248.  
  7249. // if (renderJob) {
  7250. // _.vY(renderJob, renderCallback);
  7251. // } else {
  7252. // renderCallback();
  7253. // }
  7254. // }
  7255.  
  7256.  
  7257.  
  7258.  
  7259. const createStampDomFnsC_ = () => {
  7260.  
  7261. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  7262.  
  7263. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  7264. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  7265.  
  7266.  
  7267. // const rq0 = document.createElement('rp');
  7268. // rq0.setAttribute('yt-element-placholder', '');
  7269.  
  7270. const it0 = Date.now() - 80000000000;
  7271. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  7272.  
  7273.  
  7274. const getStampContainer_ = function (containerId) {
  7275.  
  7276. return this.getStampContainer7409_(containerId);
  7277.  
  7278. }
  7279.  
  7280.  
  7281.  
  7282.  
  7283. const createComponent_ = function (componentConfig, data, canReuse) {
  7284.  
  7285. return this.createComponent7409_(componentConfig, data, canReuse);
  7286.  
  7287. }
  7288.  
  7289.  
  7290. const s52 = Symbol();
  7291.  
  7292. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  7293.  
  7294. // if(component.querySelectorAll('dom-if').length > 0){
  7295.  
  7296. // // console.log(1233, component.isConnected, component.parentNode, component.querySelectorAll('dom-if'))
  7297. // if (component.isConnected === false) {
  7298. // for (const s of component.querySelectorAll('dom-if')) {
  7299. // try {
  7300. // console.log(1299);
  7301. // insp(s).__teardownInstance();
  7302. // } catch (e) { }
  7303. // }
  7304. // }
  7305.  
  7306. // }
  7307.  
  7308. if (typeof (data || 0) === 'object') {
  7309. if (!data[s52]) data[s52] = genId();
  7310. component[s52] = data[s52];
  7311. // console.log(component[s52], data);
  7312. } else {
  7313. component[s52] = null;
  7314. }
  7315.  
  7316. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7317.  
  7318. }
  7319.  
  7320. // let pr77 = Promise.resolve();
  7321.  
  7322. const flushRenderStamperComponentBindings_ = function () {
  7323. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  7324.  
  7325. if (this.deferredBindingTasks_.length >= 0) {
  7326.  
  7327. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  7328.  
  7329. const gid = this[`__$$stampFlushKey$$__`] = genId();
  7330. const g = (() => {
  7331. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  7332. // if (deferredBindingTasks_.length === 0) return;
  7333. // let q = this.deferredBindingTasks_;
  7334. // this.deferredBindingTasks_ = deferredBindingTasks_;
  7335. this.flushRenderStamperComponentBindings7409_();
  7336. // deferredBindingTasks_.length = 0;
  7337. // this.deferredBindingTasks_ = q;
  7338.  
  7339. const s = [...this.__lat457__];
  7340. this.__lat457__.clear();
  7341.  
  7342. for (const containerWr of s) {
  7343.  
  7344. const container = kRef(containerWr);
  7345. if (!container) continue;
  7346.  
  7347. // const s = new Set();
  7348. if (!container.querySelector('[ytx-flushing]')) {
  7349. if (container.hasAttribute('ytx-flushing')) {
  7350. const attrVal = container.getAttribute('ytx-flushing');
  7351. container.removeAttribute('ytx-flushing');
  7352. // s.add([container, attrVal]);
  7353. addTask(container, attrVal);
  7354. // addTaskIm(container, attrVal);
  7355. let ancestor = container.closest('[ytx-flushing]');
  7356. while (ancestor) {
  7357. if (ancestor.querySelector('[ytx-flushing]')) break;
  7358. const attrVal = ancestor.getAttribute('ytx-flushing');
  7359. ancestor.removeAttribute('ytx-flushing');
  7360. // s.add([ancestor, attrVal]);
  7361. addTask(ancestor, attrVal);
  7362. // addTaskIm(ancestor, attrVal);
  7363. ancestor = ancestor.closest('[ytx-flushing]');
  7364. }
  7365. }
  7366. }
  7367. }
  7368. executeTasks();
  7369.  
  7370.  
  7371. });
  7372. g();
  7373. // const useMicroTaskQueue = this.__qsd477__ === 2;
  7374. // useMicroTaskQueue ? addTask2(g) : g();
  7375. // executeTasks();
  7376.  
  7377. // addTask2(g);
  7378. // executeTasks();
  7379.  
  7380. }
  7381.  
  7382. throw new Error('e5bd8d2f');
  7383.  
  7384. }
  7385.  
  7386. let tasks = [];
  7387. let excuted = false;
  7388. const executeTasks = ()=>{
  7389. if(excuted || tasks.length === 0) return;
  7390. excuted = true;
  7391. let t0 = 0;
  7392. const perform = ()=>{
  7393. if(!t0) t0 = nativeNow();
  7394. const task = tasks.shift();
  7395. if(!task){
  7396. excuted = false;
  7397. return;
  7398. }
  7399. task.fn(task);
  7400. const t1 = nativeNow();
  7401. if(t1 - t0 > 10){
  7402. t0 = 0;
  7403. nextBrowserTick_(perform);
  7404. }else{
  7405. queueMicrotask_(perform);
  7406. }
  7407. }
  7408. queueMicrotask_(perform);
  7409. }
  7410.  
  7411. const taskFn = (task) => {
  7412.  
  7413. if(!task) return;
  7414. const { containerWr, attrVal } = task;
  7415. const container = kRef(containerWr);
  7416. if (!container) return;
  7417. if (attrVal === '0') return;
  7418. const bEventCb = attrVal === '2';
  7419. const producerWr = containerMapping.get(container);
  7420. const producer = kRef(producerWr);
  7421. if (!producer) return;
  7422. const hostElement = producer.hostElement;
  7423. if (!hostElement) return;
  7424. if (hostElement.isConnected !== true) return; // tbc
  7425. producer.markDirty && producer.markDirty();
  7426. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  7427. container
  7428. });
  7429.  
  7430. }
  7431.  
  7432. const addTask = (container, attrVal) => {
  7433. if (!container) return;
  7434. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7435. tasks.push({
  7436. fn: taskFn,
  7437. containerWr: containerWr,
  7438. attrVal
  7439. });
  7440. // pr77 = pr77.then(()=>{
  7441.  
  7442. // })
  7443. // taskFn({
  7444. // containerWr: containerWr,
  7445. // attrVal
  7446. // })
  7447.  
  7448. }
  7449.  
  7450. const addTaskIm = (container, attrVal) => {
  7451. if (!container) return;
  7452. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7453. taskFn({
  7454. fn: taskFn,
  7455. containerWr: containerWr,
  7456. attrVal
  7457. });
  7458.  
  7459. }
  7460.  
  7461.  
  7462. const addTask2 = (f) => {
  7463. // pr77 = pr77.then(f).catch(console.warn);
  7464. tasks.push({
  7465. fn: f
  7466. });
  7467.  
  7468. }
  7469.  
  7470. // const mo = new MutationObserver((mutations)=>{
  7471.  
  7472. // });
  7473. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  7474.  
  7475. const containerMapping = new WeakMap();
  7476.  
  7477. // let pr77 = Promise.resolve();
  7478. // let pr88 = Promise.resolve();
  7479. const uA4 = function (t, P) {
  7480. for (let y in t)
  7481. if (t.hasOwnProperty(y) && P[y])
  7482. return y;
  7483. return null
  7484. }
  7485.  
  7486. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  7487.  
  7488. const ax = ax_;
  7489. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  7490. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  7491. // const useMicroTaskQueue = false;
  7492. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  7493. ax[2].cancel();
  7494. useMicroTaskQueue2 = false;
  7495. }
  7496. // console.log(1992,containerId, this.hostElement.is)
  7497.  
  7498. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  7499. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  7500. // return false;
  7501.  
  7502. // }
  7503.  
  7504. if (producer.hasFlexibleItems === true) {
  7505. return false;
  7506. }
  7507.  
  7508. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  7509. return false;
  7510. }
  7511.  
  7512. const hostIs = hostIs_;
  7513.  
  7514. if (hostIs === 'ytd-masthead' || hostIs === 'ytd-button-renderer' || hostIs === 'yt-button-shape' || hostIs === 'yt-icon-button' || hostIs === 'ytd-notification-topbar-button-renderer' || containerId === 'buttons' || containerId === 'button' || containerId === 'icon' || hostIs === 'yt-interaction' || containerId === 'interaction') return false;
  7515.  
  7516. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  7517. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  7518. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  7519. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  7520. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  7521. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  7522. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  7523. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  7524. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  7525. else if (hostIs === 'ytd-feed-filter-chip-bar-renderer' || hostIs === 'yt-chip-cloud-renderer' || containerId==='filter' || containerId ==='chips' || containerId==='left-arrow-button' ||containerId==='right-arrow-button') useMicroTaskQueue2 =false;
  7526. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  7527. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  7528. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  7529. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  7530. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  7531. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  7532. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  7533. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  7534. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  7535.  
  7536.  
  7537. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  7538.  
  7539.  
  7540. // console.log(5992,stackAt)
  7541.  
  7542. // console.log(2883, this[`__quu477#${containerId}__`] )
  7543. // if (useMicroTaskQueue) {
  7544. // console.log(stackAt)
  7545. // }
  7546.  
  7547. // if (useMicroTaskQueue) {
  7548. // console.log(1120301)
  7549. // }
  7550.  
  7551. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  7552.  
  7553. return useMicroTaskQueue2;
  7554.  
  7555. }
  7556.  
  7557. const frag385 = document.createDocumentFragment();
  7558. frag385.appendChild4202 = frag385.appendChild;
  7559. frag385.removeChild4202 = frag385.removeChild;
  7560. const cm385 = document.createComment('.');
  7561.  
  7562. const doc385 = document.implementation.createHTMLDocument();
  7563. const html385 = doc385.firstElementChild;
  7564. const node385 = html385.appendChild(document.createElement('div'));
  7565.  
  7566. const fixContainerApi = (container) => {
  7567. if (container instanceof Node) {
  7568. const containerDomApi = container.__domApi;
  7569. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  7570. // console.log(123882, container)
  7571. containerDomApi.removeChild588 = containerDomApi.removeChild;
  7572. containerDomApi.removeChild = function (elem) {
  7573. let r;
  7574. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7575. s.setAttribute('ytx-flushing', '0');
  7576. }
  7577. try {
  7578. r = this.removeChild588(elem);
  7579. } catch (e) { }
  7580. if (!r) {
  7581. frag385.appendChild4202(elem);
  7582. frag385.removeChild4202(elem);
  7583. r = elem;
  7584. }
  7585. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7586. s.removeAttribute('ytx-flushing');
  7587. }
  7588. return r;
  7589. }
  7590. }
  7591. }
  7592. }
  7593.  
  7594. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7595.  
  7596. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7597. if (typeof sqq === 'function') sqq();
  7598.  
  7599. // trigger in rendererStamperApplyChangeRecord_
  7600.  
  7601. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  7602. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7603. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7604. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  7605.  
  7606. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7607. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7608.  
  7609.  
  7610. const ax = this[`__quu477#${containerId}__`];
  7611. const hostIs = (this.hostElement || 0).is;
  7612. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7613.  
  7614. const container = this.getStampContainer7409_(containerId);
  7615. const pChildren = (container instanceof Node && container.isConnected) ? [...container.children] : [];
  7616. renderPathMake(pChildren)
  7617.  
  7618. containerMapping.set(container,
  7619. (this[wk] || (this[wk] = mWeakRef(this)))
  7620. );
  7621.  
  7622. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7623. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7624.  
  7625. // let dataList_ = dataList;
  7626. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  7627.  
  7628. dataList = null;
  7629. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  7630. let fq = 0;
  7631. const f = (() => {
  7632. if(fq) return;
  7633. fq = 1;
  7634. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7635. this[`__$$stampSFn$$#${containerId}__`] = null;
  7636. const container = this.getStampContainer7409_(containerId);
  7637.  
  7638. this.__lat457__ = this.__lat457__ || new Set();
  7639. if(!container[wk]) container[wk] = mWeakRef(container);
  7640. this.__lat457__.add(container[wk]);
  7641. fixContainerApi(container);
  7642.  
  7643. // let q = this.deferredBindingTasks_;
  7644. // this.deferredBindingTasks_ = [];
  7645. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7646. let e_;
  7647. try {
  7648. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  7649. } catch (e) { e_ = e }
  7650. this.__qsd477__ = false;
  7651. dataList_ = typeOrConfig = null;
  7652. fixContainerApi(container);
  7653. // this.deferredBindingTasks_ = q;
  7654. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7655. if (!e_) {
  7656. // container.setAttribute('ytx-flushing', '0');
  7657. }
  7658. // if( container.childElementCount === 0 ){
  7659. // container.setAttribute('ytx-flushing', '0');
  7660. // this.markDirty && this.markDirty();
  7661. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  7662. // container
  7663. // });
  7664. // }
  7665.  
  7666.  
  7667.  
  7668.  
  7669. });
  7670. this[`__$$stampSFn$$#${containerId}__`] = f;
  7671. this[`__$$stampSqq$$#${containerId}__`] = f;
  7672. useMicroTaskQueue2 ? addTask2(f) : f();
  7673. executeTasks();
  7674.  
  7675. Promise.resolve(pChildren).then(pChildren => {
  7676. for (const node of pChildren) {
  7677. if (node.isConnected === false) {
  7678. _removedElements.addNode(node); // rn54006
  7679. }
  7680. }
  7681. pChildren.length = 0;
  7682. pChildren = null;
  7683. });
  7684.  
  7685. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  7686.  
  7687. return undefined;
  7688.  
  7689. }
  7690.  
  7691. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  7692.  
  7693.  
  7694. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7695. if (typeof sqq === 'function') sqq();
  7696.  
  7697. // trigger in rendererStamperApplyChangeRecord_
  7698.  
  7699. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7700. } else {
  7701. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7702. }
  7703.  
  7704.  
  7705. // trigger in rendererStamperApplyChangeRecord_
  7706.  
  7707. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  7708. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7709. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7710.  
  7711. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  7712.  
  7713. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7714. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7715. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  7716.  
  7717. const ax = this[`__quu477#${containerId}__`];
  7718. const hostIs = (this.hostElement || 0).is;
  7719. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7720.  
  7721.  
  7722. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  7723. // const useMicroTaskQueue = true;
  7724. const container = this.getStampContainer7409_(containerId);
  7725.  
  7726. containerMapping.set(container,
  7727. (this[wk] || (this[wk] = mWeakRef(this)))
  7728. );
  7729. const bEventCb = this.stampDom[stampKey].events;
  7730. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7731. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7732.  
  7733. // let indexSplicesObj_ = indexSplicesObj;
  7734. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7735. // indexSplicesObj_ = {
  7736. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  7737. // const { index, addedCount, removed, object, type } = slice;
  7738. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7739. // return { index, addedCount, removed, object, type };
  7740. // })
  7741. // };
  7742. // }
  7743.  
  7744.  
  7745. indexSplicesObj.indexSplices.forEach(slice => {
  7746. const object = slice.object;
  7747. if (!object || typeof object !== 'object') return;
  7748. // const { index, addedCount, removed, object, type } = slice;
  7749. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7750. // return { index, addedCount, removed, object, type };
  7751. });
  7752.  
  7753. // let indexSplicesObj_ = indexSplicesObj;
  7754.  
  7755. // console.log(128783, indexSplicesObj)
  7756.  
  7757. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  7758. // const { index, addedCount, removed, object, type } = slice;
  7759. // return { index, addedCount, removed, object, type };
  7760. // });
  7761.  
  7762. indexSplicesObj = null;
  7763.  
  7764. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  7765. const gid = this[`__$$stampSID$$#${containerId}__`];
  7766. let fq = 0;
  7767. const f = (() => {
  7768. if(fq) return;
  7769. fq = 1;
  7770. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7771. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  7772. const container = this.getStampContainer7409_(containerId);
  7773. if(!container) return;
  7774.  
  7775. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  7776.  
  7777. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  7778. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  7779. const mapping = this.stampDom[stampKey].mapping;
  7780.  
  7781. const map = new Map();
  7782.  
  7783. const currentObjKeys = object.map(objEntry => {
  7784. const mappingKey = uA4(mapping, objEntry);
  7785. if(!mappingKey) return null;
  7786. const data = objEntry[mappingKey];
  7787. if (!data[s52]) data[s52] = genId();
  7788. map.set(data[s52], objEntry);
  7789. // return ({
  7790. // objEntry,
  7791. // data: data,
  7792. // mappingKey: mappingKey,
  7793. // key: data[s52],
  7794. // exist: elementKeys.has(data[s52])
  7795. // });
  7796. return data[s52]
  7797.  
  7798. });
  7799.  
  7800. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  7801.  
  7802. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  7803.  
  7804. const splices = diffSplices(oldDomKeys, currentObjKeys);
  7805.  
  7806. // let myObject = object;
  7807. let indexSplicesObj_ = {
  7808. indexSplices: splices.map(splice => {
  7809. const index = splice[0];
  7810. const removedLen = splice[1];
  7811. const added = splice[2];
  7812. const addedCount = added.length;
  7813. const object = {};
  7814. object.length = index + addedCount;
  7815. for (let i = 0; i < addedCount; i++) {
  7816. object[index + i] = map.get(added[i]);
  7817. }
  7818. const removed = {};
  7819. removed.length = removedLen;
  7820.  
  7821. return { index, removed, object, addedCount }
  7822. })
  7823. };
  7824. map.clear();
  7825.  
  7826.  
  7827. this.__lat457__ = this.__lat457__ || new Set();
  7828. if(!container[wk]) container[wk] = mWeakRef(container);
  7829. this.__lat457__.add(container[wk]);
  7830. fixContainerApi(container);
  7831.  
  7832. // console.log(3882, indexSplicesObj_)
  7833. // let q = this.deferredBindingTasks_;
  7834. // this.deferredBindingTasks_ = [];
  7835. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7836. let e_;
  7837. try {
  7838. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  7839. } catch (e) { e_ = e; }
  7840. this.__qsd477__ = false;
  7841. indexSplicesObj_ = null;
  7842. stampKey = indexSplicesObj_ = null;
  7843. fixContainerApi(container);
  7844. // this.deferredBindingTasks_ = q;
  7845. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7846. if (!e_) {
  7847. // container.setAttribute('ytx-flushing', '0');
  7848. }
  7849.  
  7850.  
  7851. });
  7852. this[`__$$stampSqq$$#${containerId}__`] = f;
  7853. useMicroTaskQueue2 ? addTask2(f) : f();
  7854. executeTasks();
  7855.  
  7856. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  7857.  
  7858. return undefined;
  7859.  
  7860. }
  7861.  
  7862.  
  7863. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  7864. const dt0 = dt0a[0];
  7865. const dt1 = Date.now();
  7866. const obj = kRef(objWr);
  7867. if (!obj) return;
  7868. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7869. if (xxx !== xxx_) return;
  7870. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7871. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7872. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7873. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7874. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7875. const renderJob1 = obj.renderJobsMap_[containerId]
  7876. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  7877. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7878. let e_, r;
  7879. try {
  7880. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7881. } catch (e) {
  7882. e_ = e;
  7883. }
  7884. obj[`__quu477#${containerId}__`] = false;
  7885. if (e_) throw e_;
  7886. return r;
  7887. };
  7888.  
  7889.  
  7890. stampDomArray_.bind = function (obj, ...args) {
  7891. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7892. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7893. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7894. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  7895. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  7896. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7897. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7898. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7899. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7900.  
  7901.  
  7902. const renderJob = obj.renderJobsMap_[containerId];
  7903.  
  7904. const dt0a = [Date.now()];
  7905. queueMicrotask_(() => { dt0a[0] = 0 });
  7906. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  7907. };
  7908.  
  7909. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  7910. const dt0 = dt0a[0];
  7911. const dt1 = Date.now();
  7912. const obj = kRef(objWr);
  7913. if (!obj) return;
  7914. const renderJob1 = obj.renderJobsMap_[containerId];
  7915. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7916. let e_, r;
  7917. try {
  7918. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  7919. } catch (e) {
  7920. e_ = e;
  7921. }
  7922. obj[`__quu477#${containerId}__`] = false;
  7923. if (e_) throw e_;
  7924. return r;
  7925. };
  7926.  
  7927.  
  7928. stampDomArraySplices_.bind = function (obj, ...args) {
  7929. let [stampKey, containerId, indexSplicesObj] = args;
  7930. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7931.  
  7932. const renderJob = obj.renderJobsMap_[containerId];
  7933.  
  7934. const dt0a = [Date.now()];
  7935. queueMicrotask_(() => { dt0a[0] = 0 });
  7936. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  7937. };
  7938.  
  7939. const flushRenderStamperComponentBindings7419_ = function () {
  7940. const tasks = this.deferredBindingTasks_;
  7941. if (!(tasks || 0).length) return;
  7942. const hostElement = this.hostElement;
  7943. if ((hostElement instanceof Node) && hostElement.nodeType === 1) {
  7944. if (hostElement.isConnected === true) {
  7945. this.flushRenderStamperComponentBindings7409_();
  7946. }
  7947. } else if (hostElement) {
  7948. console.log('flushRenderStamperComponentBindings7419_ 002')
  7949. this.flushRenderStamperComponentBindings7409_();
  7950. } else {
  7951. console.log('flushRenderStamperComponentBindings7419_ 003')
  7952. tasks.length = 0;
  7953. }
  7954. }
  7955.  
  7956. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ , flushRenderStamperComponentBindings7419_};
  7957.  
  7958. }
  7959.  
  7960. const setupDiscreteTasks = (h, rb) => {
  7961.  
  7962. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7963. const f = h.onYtRendererstamperFinished;
  7964. const g = ump3.get(f) || function () {
  7965. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7966. return f.apply(this, arguments);
  7967. }
  7968. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7969. }
  7970. ump3.set(f, g);
  7971. g.km34 = 1;
  7972. h.onYtRendererstamperFinished = g;
  7973.  
  7974. }
  7975.  
  7976. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7977. const f = h.onYtUpdateDescriptionAction;
  7978. const g = ump3.get(f) || function (a) {
  7979. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7980. }
  7981. ump3.set(f, g);
  7982. g.km34 = 1;
  7983. h.onYtUpdateDescriptionAction = g;
  7984.  
  7985. }
  7986.  
  7987. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7988. const f = h.handleUpdateDescriptionAction;
  7989. const g = ump3.get(f) || function (a) {
  7990. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7991. }
  7992. ump3.set(f, g);
  7993. g.km34 = 1;
  7994. h.handleUpdateDescriptionAction = g;
  7995.  
  7996. }
  7997.  
  7998. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7999. const f = h.handleUpdateLiveChatPollAction;
  8000. const g = ump3.get(f) || function (a) {
  8001. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8002. }
  8003. ump3.set(f, g);
  8004. g.km34 = 1;
  8005. h.handleUpdateLiveChatPollAction = g;
  8006.  
  8007. }
  8008.  
  8009. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  8010. const f = h.onTextChanged;
  8011. const g = ump3.get(f) || function () {
  8012. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8013. }
  8014. ump3.set(f, g);
  8015. g.km34 = 1;
  8016. h.onTextChanged = g;
  8017.  
  8018. }
  8019.  
  8020. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  8021. const f = h.onVideoDataChange;
  8022. const g = ump3.get(f) || function (a) {
  8023. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8024. }
  8025. ump3.set(f, g);
  8026. g.km34 = 1;
  8027. h.onVideoDataChange = g;
  8028.  
  8029. }
  8030.  
  8031. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  8032. const f = h.onVideoDataChange_;
  8033. const g = ump3.get(f) || function () {
  8034. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8035. }
  8036. ump3.set(f, g);
  8037. g.km34 = 1;
  8038. h.onVideoDataChange_ = g;
  8039.  
  8040. }
  8041.  
  8042. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  8043.  
  8044. const f = h.addTooltips_;
  8045. const g = ump3.get(f) || function () {
  8046. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8047. }
  8048. ump3.set(f, g);
  8049. g.km34 = 1;
  8050. h.addTooltips_ = g;
  8051.  
  8052. }
  8053.  
  8054. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  8055.  
  8056. const f = h.updateRenderedElements;
  8057. const g = ump3.get(f) || function () {
  8058. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8059. }
  8060. ump3.set(f, g);
  8061. g.km34 = 1;
  8062. h.updateRenderedElements = g;
  8063.  
  8064. }
  8065.  
  8066. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  8067. const f = h.loadPage_;
  8068. const g = ump3.get(f) || function (a) {
  8069. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8070. }
  8071. ump3.set(f, g);
  8072. g.km34 = 1;
  8073. h.loadPage_ = g;
  8074.  
  8075. }
  8076. // updatePageData_ : possible conflict with Omit ShadyDOM
  8077. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  8078. const f = h.updatePageData_;
  8079. const g = ump3.get(f) || function (a) {
  8080. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8081. }
  8082. ump3.set(f, g);
  8083. g.km34 = 1;
  8084. h.updatePageData_ = g;
  8085.  
  8086. }
  8087.  
  8088.  
  8089. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  8090.  
  8091. const f = h.onFocus_;
  8092. const g = ump3.get(f) || function () {
  8093. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8094. }
  8095. ump3.set(f, g);
  8096. g.km34 = 1;
  8097. h.onFocus_ = g;
  8098.  
  8099. }
  8100.  
  8101. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  8102.  
  8103. const f = h.onBlur_;
  8104. const g = ump3.get(f) || function () {
  8105. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8106. }
  8107. ump3.set(f, g);
  8108. g.km34 = 1;
  8109. h.onBlur_ = g;
  8110.  
  8111. }
  8112.  
  8113.  
  8114. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  8115.  
  8116. const f = h.buttonClassChanged_;
  8117. const g = ump3.get(f) || function (a, b) {
  8118. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8119. }
  8120. ump3.set(f, g);
  8121. g.km34 = 1;
  8122. h.buttonClassChanged_ = g;
  8123.  
  8124. }
  8125.  
  8126. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  8127.  
  8128. const f = h.buttonIconChanged_;
  8129. const g = ump3.get(f) || function (a) {
  8130. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8131. }
  8132. ump3.set(f, g);
  8133. g.km34 = 1;
  8134. h.buttonIconChanged_ = g;
  8135.  
  8136. }
  8137.  
  8138. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  8139.  
  8140. const f = h.dataChangedInBehavior_;
  8141. const g = ump3.get(f) || function () {
  8142. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8143. }
  8144. ump3.set(f, g);
  8145. g.km34 = 1;
  8146. h.dataChangedInBehavior_ = g;
  8147.  
  8148. }
  8149.  
  8150. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  8151.  
  8152. const f = h.continuationsChanged_;
  8153. const g = ump3.get(f) || function () {
  8154. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8155. }
  8156. ump3.set(f, g);
  8157. g.km34 = 1;
  8158. h.continuationsChanged_ = g;
  8159.  
  8160. }
  8161.  
  8162.  
  8163. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  8164.  
  8165. const f = h.forceChatPoll_;
  8166. const g = ump3.get(f) || function (a) {
  8167. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8168. }
  8169. ump3.set(f, g);
  8170. g.km34 = 1;
  8171. h.forceChatPoll_ = g;
  8172.  
  8173. }
  8174.  
  8175. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  8176.  
  8177. const f = h.onEndpointClick_;
  8178. const g = ump3.get(f) || function (a) {
  8179. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8180. }
  8181. ump3.set(f, g);
  8182. g.km34 = 1;
  8183. h.onEndpointClick_ = g;
  8184.  
  8185. }
  8186.  
  8187. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  8188.  
  8189. const f = h.onEndpointTap_;
  8190. const g = ump3.get(f) || function (a) {
  8191. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8192. }
  8193. ump3.set(f, g);
  8194. g.km34 = 1;
  8195. h.onEndpointTap_ = g;
  8196.  
  8197. }
  8198.  
  8199. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  8200.  
  8201. const f = h.handleClick_;
  8202. const g = ump3.get(f) || function (a, b) {
  8203. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8204. }
  8205. ump3.set(f, g);
  8206. g.km34 = 1;
  8207. h.handleClick_ = g;
  8208.  
  8209. }
  8210.  
  8211. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  8212.  
  8213. const f = h.onReadyStateChange_;
  8214. const g = ump3.get(f) || function () {
  8215. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8216. }
  8217. ump3.set(f, g);
  8218. g.km34 = 1;
  8219. h.onReadyStateChange_ = g;
  8220.  
  8221. }
  8222.  
  8223. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  8224.  
  8225. const f = h.onReadyStateChangeEntryPoint_;
  8226. const g = ump3.get(f) || function () {
  8227. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8228. }
  8229. ump3.set(f, g);
  8230. g.km34 = 1;
  8231. h.onReadyStateChangeEntryPoint_ = g;
  8232.  
  8233. }
  8234.  
  8235. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  8236.  
  8237. const f = h.readyStateChangeHandler_;
  8238. const g = ump3.get(f) || function (a) {
  8239. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8240. }
  8241. ump3.set(f, g);
  8242. g.km34 = 1;
  8243. h.readyStateChangeHandler_ = g;
  8244.  
  8245. }
  8246.  
  8247. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  8248.  
  8249. const f = h.xmlHttpHandler_;
  8250. const g = ump3.get(f) || function (a) {
  8251. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8252. }
  8253. ump3.set(f, g);
  8254. g.km34 = 1;
  8255. h.xmlHttpHandler_ = g;
  8256.  
  8257. }
  8258.  
  8259. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  8260.  
  8261. const f = h.executeCallbacks_; // overloaded
  8262. const g = ump3.get(f) || function (a) {
  8263. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8264. }
  8265. ump3.set(f, g);
  8266. g.km34 = 1;
  8267. h.executeCallbacks_ = g;
  8268.  
  8269. }
  8270.  
  8271. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  8272.  
  8273. const f = h.handleInvalidationData_;
  8274. const g = ump3.get(f) || function (a, b) {
  8275. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8276. }
  8277. ump3.set(f, g);
  8278. g.km34 = 1;
  8279. h.handleInvalidationData_ = g;
  8280.  
  8281. }
  8282.  
  8283. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  8284.  
  8285. const f = h.onInput_;
  8286. const g = ump3.get(f) || function () {
  8287. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8288. }
  8289. ump3.set(f, g);
  8290. g.km34 = 1;
  8291. h.onInput_ = g;
  8292.  
  8293. }
  8294. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  8295.  
  8296. const f = h.trigger_;
  8297. const g = ump3.get(f) || function (a) {
  8298. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8299. }
  8300. ump3.set(f, g);
  8301. g.km34 = 1;
  8302. h.trigger_ = g;
  8303.  
  8304. }
  8305.  
  8306. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  8307.  
  8308. const f = h.requestData_;
  8309. const g = ump3.get(f) || function (a) {
  8310. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8311. }
  8312. ump3.set(f, g);
  8313. g.km34 = 1;
  8314. h.requestData_ = g;
  8315.  
  8316. }
  8317.  
  8318. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  8319.  
  8320. const f = h.onLoadReloadContinuation_;
  8321. const g = ump3.get(f) || function (a, b) {
  8322. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8323. }
  8324. ump3.set(f, g);
  8325. g.km34 = 1;
  8326. h.onLoadReloadContinuation_ = g;
  8327.  
  8328. }
  8329.  
  8330. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  8331.  
  8332. const f = h.onLoadIncrementalContinuation_;
  8333. const g = ump3.get(f) || function (a, b) {
  8334. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8335. }
  8336. ump3.set(f, g);
  8337. g.km34 = 1;
  8338. h.onLoadIncrementalContinuation_ = g;
  8339.  
  8340. }
  8341.  
  8342. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  8343.  
  8344. const f = h.onLoadSeekContinuation_;
  8345. const g = ump3.get(f) || function (a, b) {
  8346. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8347. }
  8348. ump3.set(f, g);
  8349. g.km34 = 1;
  8350. h.onLoadSeekContinuation_ = g;
  8351.  
  8352. }
  8353. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  8354.  
  8355. const f = h.onLoadReplayContinuation_;
  8356. const g = ump3.get(f) || function (a, b) {
  8357. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8358. }
  8359. ump3.set(f, g);
  8360. g.km34 = 1;
  8361. h.onLoadReplayContinuation_ = g;
  8362.  
  8363. }
  8364. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  8365.  
  8366. const f = h.onNavigate_;
  8367. const g = ump3.get(f) || function (a) {
  8368. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8369. }
  8370. ump3.set(f, g);
  8371. g.km34 = 1;
  8372. h.onNavigate_ = g;
  8373.  
  8374. }
  8375.  
  8376. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  8377.  
  8378. const f = h.ytRendererBehaviorDataObserver_;
  8379. const g = ump3.get(f) || function () {
  8380. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8381. }
  8382. ump3.set(f, g);
  8383. g.km34 = 1;
  8384. h.ytRendererBehaviorDataObserver_ = g;
  8385.  
  8386. }
  8387.  
  8388. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  8389.  
  8390. const f = h.ytRendererBehaviorTargetIdObserver_;
  8391. const g = ump3.get(f) || function () {
  8392. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8393. }
  8394. ump3.set(f, g);
  8395. g.km34 = 1;
  8396. h.ytRendererBehaviorTargetIdObserver_ = g;
  8397.  
  8398. }
  8399.  
  8400. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  8401.  
  8402. const f = h.unregisterRenderer_;
  8403. const g = ump3.get(f) || function (a) {
  8404. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8405. }
  8406. ump3.set(f, g);
  8407. g.km34 = 1;
  8408. h.unregisterRenderer_ = g;
  8409.  
  8410. }
  8411.  
  8412. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  8413.  
  8414. const f = h.textChanged_;
  8415. const g = ump3.get(f) || function (a) {
  8416. if (void 0 !== this.isAttached) {
  8417. const hostElement = this.hostElement;
  8418. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  8419. return;
  8420. }
  8421. }
  8422. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8423. }
  8424. ump3.set(f, g);
  8425. g.km34 = 1;
  8426. h.textChanged_ = g;
  8427.  
  8428. }
  8429.  
  8430.  
  8431.  
  8432. /**
  8433. *
  8434. * Neglect following
  8435. *
  8436. * h.onYtAction_
  8437. * h.startLoadingWatch [ buggy for yt-player-updated ]
  8438. * h.deferRenderStamperBinding_
  8439. *
  8440. * h.stampDomArray_
  8441. * h.stampDomArraySplices_
  8442. *
  8443. */
  8444.  
  8445.  
  8446. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  8447. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  8448. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  8449. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  8450. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  8451. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  8452.  
  8453. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  8454.  
  8455. const f = h.searchChanged_;
  8456. const g = ump3.get(f) || function () {
  8457. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8458. }
  8459. ump3.set(f, g);
  8460. g.km34 = 1;
  8461. h.searchChanged_ = g;
  8462.  
  8463. }
  8464.  
  8465. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  8466.  
  8467. const f = h.skinToneChanged_;
  8468. const g = ump3.get(f) || function (a) {
  8469. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8470. }
  8471. ump3.set(f, g);
  8472. g.km34 = 1;
  8473. h.skinToneChanged_ = g;
  8474.  
  8475. }
  8476.  
  8477. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  8478.  
  8479. const f = h.onEmojiHover_;
  8480. const g = ump3.get(f) || function (a) {
  8481. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8482. }
  8483. ump3.set(f, g);
  8484. g.km34 = 1;
  8485. h.onEmojiHover_ = g;
  8486.  
  8487. }
  8488.  
  8489. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  8490.  
  8491. const f = h.onSelectCategory_;
  8492. const g = ump3.get(f) || function (a) {
  8493. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8494. }
  8495. ump3.set(f, g);
  8496. g.km34 = 1;
  8497. h.onSelectCategory_ = g;
  8498.  
  8499. }
  8500.  
  8501. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  8502.  
  8503. const f = h.onShowEmojiVariantSelector;
  8504. const g = ump3.get(f) || function (a) {
  8505. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8506. }
  8507. ump3.set(f, g);
  8508. g.km34 = 1;
  8509. h.onShowEmojiVariantSelector = g;
  8510.  
  8511. }
  8512.  
  8513. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  8514.  
  8515. const f = h.updateCategoriesAndPlaceholder_;
  8516. const g = ump3.get(f) || function () {
  8517. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8518. }
  8519. ump3.set(f, g);
  8520. g.km34 = 1;
  8521. h.updateCategoriesAndPlaceholder_ = g;
  8522.  
  8523. }
  8524.  
  8525. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  8526.  
  8527. const f = h.watchPageActiveChanged_;
  8528. const g = ump3.get(f) || function () {
  8529. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8530. }
  8531. ump3.set(f, g);
  8532. g.km34 = 1;
  8533. h.watchPageActiveChanged_ = g;
  8534.  
  8535. }
  8536.  
  8537. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  8538.  
  8539. const f = h.activate_;
  8540. const g = ump3.get(f) || function () {
  8541. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8542. }
  8543. ump3.set(f, g);
  8544. g.km34 = 1;
  8545. h.activate_ = g;
  8546.  
  8547. }
  8548. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  8549.  
  8550. const f = h.onYtPlaylistDataUpdated_;
  8551. const g = ump3.get(f) || function () {
  8552. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8553. }
  8554. ump3.set(f, g);
  8555. g.km34 = 1;
  8556. h.onYtPlaylistDataUpdated_ = g;
  8557.  
  8558. }
  8559.  
  8560.  
  8561.  
  8562. /**
  8563. *
  8564. * Neglect following
  8565. *
  8566. * h.rendererStamperObserver_
  8567. * h.rendererStamperApplyChangeRecord_
  8568. * h.flushRenderStamperComponentBindings_
  8569. * h.forwardRendererStamperChanges_
  8570. *
  8571. */
  8572.  
  8573. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  8574.  
  8575. const f = h.tryRenderChunk_;
  8576. const g = ump3.get(f) || function () {
  8577. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8578. }
  8579. ump3.set(f, g);
  8580. g.km34 = 1;
  8581. h.tryRenderChunk_ = g;
  8582.  
  8583. }
  8584.  
  8585.  
  8586. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  8587.  
  8588. const f = h.renderChunk_;
  8589. const g = ump3.get(f) || function () {
  8590. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8591. }
  8592. ump3.set(f, g);
  8593. g.km34 = 1;
  8594. h.renderChunk_ = g;
  8595.  
  8596. }
  8597.  
  8598. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  8599.  
  8600. const f = h.deepLazyListObserver_;
  8601. const g = ump3.get(f) || function () {
  8602. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8603. }
  8604. ump3.set(f, g);
  8605. g.km34 = 1;
  8606. h.deepLazyListObserver_ = g;
  8607.  
  8608. }
  8609.  
  8610. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  8611.  
  8612. const f = h.onItemsUpdated_;
  8613. const g = ump3.get(f) || function () {
  8614. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8615. }
  8616. ump3.set(f, g);
  8617. g.km34 = 1;
  8618. h.onItemsUpdated_ = g;
  8619.  
  8620. }
  8621.  
  8622. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  8623.  
  8624. const f = h.requestRenderChunk_;
  8625. const g = ump3.get(f) || function () {
  8626. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8627. }
  8628. ump3.set(f, g);
  8629. g.km34 = 1;
  8630. h.requestRenderChunk_ = g;
  8631.  
  8632. }
  8633.  
  8634. /**
  8635. *
  8636. * Neglect following
  8637. *
  8638. * h.dataChanged_ [ buggy for page swtiching ]
  8639. *
  8640. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  8641. *
  8642. * h.cancelPendingTasks_
  8643. * h.fillRange_
  8644. * h.addTextNodes_
  8645. * h.updateText_
  8646. * h.stampTypeChanged_
  8647. *
  8648. */
  8649.  
  8650.  
  8651. }
  8652.  
  8653. const keyStConnectedCallback = Symbol(); // avoid copying the value
  8654.  
  8655. const dmf = new WeakMap();
  8656.  
  8657.  
  8658. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  8659.  
  8660. try {
  8661.  
  8662. const q = document.createElement('template');
  8663. q.innerHTML = '<ytz-null361></ytz-null361>';
  8664. nativeHTMLElement = q.content.firstChild.constructor
  8665.  
  8666. } catch (e) { }
  8667.  
  8668. if (!nativeHTMLElement.prototype.connectedCallback) {
  8669. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  8670. nativeHTMLElement.prototype.connectedCallback = function () {
  8671. let r;
  8672. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  8673. return r;
  8674. }
  8675. }
  8676. const pvr = Symbol()
  8677.  
  8678. let stampDomArrayFnStore = null;
  8679. const setupMap = new WeakSet();
  8680. const setupYtComponent = (cnt) => {
  8681. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  8682. if (!cProto || setupMap.has(cProto)) return;
  8683. setupMap.add(cProto);
  8684. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  8685. cProto[pvr] |= 1;
  8686.  
  8687.  
  8688.  
  8689. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  8690. const b = cProto.stampDomArray_.length === 6
  8691. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  8692. && cProto.createComponent_ && cProto.createComponent_.length === 3
  8693. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  8694. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  8695. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  8696. if (!b) {
  8697. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  8698. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  8699. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  8700. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_, flushRenderStamperComponentBindings7419_} = stampDomArrayFnStore;
  8701.  
  8702. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  8703. cProto.createComponent7409_ = cProto.createComponent_;
  8704. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  8705. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  8706. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  8707. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  8708.  
  8709. cProto.getStampContainer_ = getStampContainer_;
  8710. cProto.createComponent_ = createComponent_;
  8711. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  8712. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  8713. cProto.stampDomArray_ = stampDomArray_;
  8714. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  8715. cProto.flushRenderStamperComponentBindings7419_ = flushRenderStamperComponentBindings7419_;
  8716.  
  8717. }
  8718. }
  8719.  
  8720.  
  8721.  
  8722.  
  8723. // if(false && cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  8724. // cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  8725.  
  8726. // if(cProto._runEffectsForTemplate6344.length === 4){
  8727.  
  8728. // cProto._runEffectsForTemplate = function (c, d, e, g) {
  8729. // const cnt = this;
  8730. // const { propertyEffects, nodeList, firstChild } = c;
  8731. // cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  8732.  
  8733. // }
  8734.  
  8735. // }
  8736.  
  8737. // }
  8738.  
  8739. }
  8740. };
  8741.  
  8742. (FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  8743. get() {
  8744. const f = this[keyStConnectedCallback];
  8745. if (this.is) {
  8746. setupYtComponent(this);
  8747. }
  8748. return f;
  8749. },
  8750. set(nv) {
  8751. let gv = nv;
  8752. this[keyStConnectedCallback] = gv; // proto or object
  8753. return true;
  8754. },
  8755. enumerable: false,
  8756. configurable: true
  8757.  
  8758. });
  8759.  
  8760. const pLoad = new Promise(resolve => {
  8761. if (document.readyState !== 'loading') {
  8762. resolve();
  8763. } else {
  8764. window.addEventListener("DOMContentLoaded", resolve, false);
  8765. }
  8766. });
  8767.  
  8768. if (FIX_ACTIONS_TOOLTIPS) {
  8769. pLoad.then(() => {
  8770. addNewCSS("#actions .tp-yt-paper-tooltip{white-space:nowrap}");
  8771. });
  8772. }
  8773.  
  8774. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  8775. window.requestIdleCallback471 = window.requestIdleCallback;
  8776. window.requestIdleCallback = function (f, ...args) {
  8777. return (this || window).requestIdleCallback471(async function () {
  8778. await pLoad.then();
  8779. // await new Promise(nextBrowserTick_);
  8780. f.call(this, ...arguments)
  8781. }, ...args);
  8782. }
  8783. }
  8784.  
  8785. pLoad.then(() => {
  8786.  
  8787. let nonce = document.querySelector('style[nonce]');
  8788. nonce = nonce ? nonce.getAttribute('nonce') : null;
  8789. const st = document.createElement('style');
  8790. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  8791. st.textContent = "none-element-k47{order:0}";
  8792. st.addEventListener('load', () => {
  8793. pf31.resolve();
  8794. p59 = 1;
  8795. }, false);
  8796. (document.body || document.head || document.documentElement).appendChild(st);
  8797.  
  8798. });
  8799.  
  8800. const prepareLogs = [];
  8801.  
  8802. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  8803.  
  8804. let winError00 = window.onerror;
  8805.  
  8806. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  8807.  
  8808. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  8809.  
  8810. ; fix_error_many_stack_state === 1 && (() => {
  8811.  
  8812.  
  8813. let p1 = winError00;
  8814.  
  8815. let stackNeedleDetails = null;
  8816.  
  8817. Object.defineProperty(Object.prototype, 'matchAll', {
  8818. get() {
  8819. stackNeedleDetails = this;
  8820. return true;
  8821. },
  8822. enumerable: true,
  8823. configurable: true
  8824. });
  8825.  
  8826. try {
  8827. JSON.parse("{}");
  8828. } catch (e) {
  8829. console.warn(e)
  8830. fix_error_many_stack_state = 0;
  8831. }
  8832.  
  8833. delete Object.prototype['matchAll'];
  8834.  
  8835. let p2 = window.onerror;
  8836.  
  8837. window.onerror = p1;
  8838.  
  8839. if (fix_error_many_stack_state === 0) return;
  8840.  
  8841. if (stackNeedleDetails) {
  8842. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8843. stackNeedleDetails.matchAll = true;
  8844. }
  8845.  
  8846. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8847.  
  8848. // p1!==p2
  8849. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8850.  
  8851. })();
  8852.  
  8853. ; fix_error_many_stack_state === 2 && (() => {
  8854.  
  8855.  
  8856. let p1 = winError00;
  8857.  
  8858. let objectPrune = null;
  8859. let stackNeedleDetails = null;
  8860.  
  8861. Object.defineProperty(Function.prototype, 'findOwner', {
  8862. get() {
  8863. objectPrune = this;
  8864. return this._findOwner;
  8865. },
  8866. set(nv) {
  8867. this._findOwner = nv;
  8868. return true;
  8869. },
  8870. enumerable: true,
  8871. configurable: true
  8872. });
  8873.  
  8874. Object.defineProperty(Object.prototype, 'matchAll', {
  8875. get() {
  8876. stackNeedleDetails = this;
  8877. return true;
  8878. },
  8879. enumerable: true,
  8880. configurable: true
  8881. });
  8882.  
  8883. try {
  8884. JSON.parse("{}");
  8885. } catch (e) {
  8886. console.warn(e)
  8887. fix_error_many_stack_state = 0;
  8888. }
  8889.  
  8890. delete Function.prototype['findOwner'];
  8891. delete Object.prototype['matchAll'];
  8892.  
  8893. let p2 = window.onerror;
  8894.  
  8895. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8896.  
  8897. if (fix_error_many_stack_state == 0) return;
  8898.  
  8899. // the following will only execute when Brave's scriptlets.js is executed.
  8900.  
  8901. prepareLogs.push("fix_error_many_stack_state NB")
  8902.  
  8903. if (stackNeedleDetails) {
  8904. stackNeedleDetails.pattern = null;
  8905. stackNeedleDetails.re = null;
  8906. stackNeedleDetails.expect = null;
  8907. stackNeedleDetails.matchAll = true;
  8908. }
  8909.  
  8910. if (objectPrune) {
  8911. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8912. delete objectPrune._findOwner;
  8913. }
  8914.  
  8915. fix_error_many_stack_state = 3;
  8916. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8917. JSON.parse.objectPrune = objectPrune;
  8918.  
  8919. })();
  8920.  
  8921. ; fix_error_many_stack_state === 3 && (() => {
  8922.  
  8923.  
  8924. let p1 = winError00;
  8925.  
  8926. try {
  8927. JSON.parse("{}");
  8928. } catch (e) {
  8929. console.warn(e)
  8930. fix_error_many_stack_state = 0;
  8931. }
  8932.  
  8933. let p2 = window.onerror;
  8934.  
  8935. if (p1 === p2) return;
  8936.  
  8937. window.onerror = p1;
  8938.  
  8939. if (fix_error_many_stack_state === 0) return;
  8940.  
  8941. fix_error_many_stack_state = 4; // p1 != p2
  8942.  
  8943.  
  8944. })();
  8945.  
  8946. fix_error_many_stack_state === 4 && (() => {
  8947.  
  8948. // the following will only execute when Brave's scriptlets.js is executed.
  8949.  
  8950. prepareLogs.push("fix_error_many_stack_state AB")
  8951.  
  8952. JSON.parseProxy = JSON.parse;
  8953.  
  8954. JSON.parse = ((parse) => {
  8955.  
  8956. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8957. return function (text, reviver) {
  8958. const onerror = window.onerror;
  8959. window.onerror = null;
  8960. let r;
  8961. try {
  8962. r = parse(...arguments);
  8963. } catch (e) {
  8964. r = e;
  8965. }
  8966. window.onerror = onerror;
  8967. if (r instanceof Error) {
  8968. throw r;
  8969. }
  8970. return r;
  8971. }
  8972.  
  8973. })(JSON.parse);
  8974.  
  8975.  
  8976. })();
  8977.  
  8978.  
  8979. // << if FIX_yt_player >>
  8980.  
  8981. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  8982. const PERF_471489_ = true;
  8983. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8984. // This script uses a much gentle way to tamer the JS engine instead.
  8985.  
  8986. // << end >>
  8987.  
  8988. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8989.  
  8990.  
  8991.  
  8992. const nilFn = () => { };
  8993.  
  8994. let isMainWindow = false;
  8995. try {
  8996. isMainWindow = window.document === window.top.document
  8997. } catch (e) { }
  8998.  
  8999. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  9000. let headLinkCollection = null;
  9001.  
  9002.  
  9003. // const assertor = (f) => f() || console.assert(false, `${f}`);
  9004.  
  9005. const fnIntegrity = (f, d) => {
  9006. if (!f || typeof f !== 'function') {
  9007. console.warn('f is not a function', f);
  9008. return;
  9009. }
  9010. let p = `${f}`, s = 0, j = -1, w = 0;
  9011. for (let i = 0, l = p.length; i < l; i++) {
  9012. const t = p[i];
  9013. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  9014. if (j < i - 1) w++;
  9015. j = i;
  9016. } else {
  9017. s++;
  9018. }
  9019. }
  9020. let itz = `${f.length}.${s}.${w}`;
  9021. if (!d) {
  9022. return itz;
  9023. } else {
  9024. return itz === d;
  9025. }
  9026. };
  9027.  
  9028. const getZqOu = (_yt_player) => {
  9029.  
  9030. const w = 'ZqOu';
  9031.  
  9032. let arr = [];
  9033.  
  9034. for (const [k, v] of Object.entries(_yt_player)) {
  9035.  
  9036. const p = typeof v === 'function' ? v.prototype : 0;
  9037. if (p
  9038. && typeof p.start === 'function' && p.start.length === 0 // Ou
  9039. && typeof p.isActive === 'function' && p.isActive.length === 0
  9040. && typeof p.stop === 'function' && p.stop.length === 0
  9041. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  9042. && !p.send && !p.abort
  9043. && !p.sample && !p.initialize && !p.fail && !p.getName
  9044. // && !p.dispose && !p.isDisposed
  9045.  
  9046. ) {
  9047. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9048.  
  9049.  
  9050. }
  9051.  
  9052. }
  9053.  
  9054. if (arr.length === 0) {
  9055.  
  9056. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9057. } else {
  9058.  
  9059. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9060. return arr[0];
  9061. }
  9062.  
  9063. }
  9064.  
  9065. const getZqQu = (_yt_player) => {
  9066.  
  9067. const w = 'ZqQu';
  9068.  
  9069. let arr = [];
  9070.  
  9071.  
  9072. for (const [k, v] of Object.entries(_yt_player)) {
  9073.  
  9074. const p = typeof v === 'function' ? v.prototype : 0;
  9075. if (p
  9076. && typeof p.start === 'function' && p.start.length === 1 // Qu
  9077. && typeof p.isActive === 'function' && p.isActive.length === 0
  9078. && typeof p.stop === 'function' && p.stop.length === 0
  9079. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  9080. && !p.send && !p.abort
  9081. && !p.sample && !p.initialize && !p.fail && !p.getName
  9082. // && !p.dispose && !p.isDisposed
  9083.  
  9084. ) {
  9085. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9086.  
  9087.  
  9088. }
  9089.  
  9090. }
  9091.  
  9092. if (arr.length === 0) {
  9093.  
  9094. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9095. } else {
  9096.  
  9097. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9098. return arr[0];
  9099. }
  9100.  
  9101. }
  9102.  
  9103.  
  9104. const getVG = (_yt_player) => {
  9105. const w = 'VG';
  9106.  
  9107. let arr = [];
  9108.  
  9109. for (const [k, v] of Object.entries(_yt_player)) {
  9110.  
  9111. const p = typeof v === 'function' ? v.prototype : 0;
  9112. if (p
  9113. && typeof p.show === 'function' && p.show.length === 1
  9114. && typeof p.hide === 'function' && p.hide.length === 0
  9115. && typeof p.stop === 'function' && p.stop.length === 0) {
  9116.  
  9117. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9118.  
  9119. }
  9120.  
  9121. }
  9122.  
  9123.  
  9124. if (arr.length === 0) {
  9125.  
  9126. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9127. } else {
  9128.  
  9129. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9130. return arr[0];
  9131. }
  9132.  
  9133.  
  9134.  
  9135. }
  9136.  
  9137.  
  9138. const getzo = (_yt_player) => {
  9139. const w = 'zo';
  9140.  
  9141. let arr = [];
  9142.  
  9143. for (const [k, v] of Object.entries(_yt_player)) {
  9144.  
  9145. if (
  9146. typeof v === 'function' && v.length === 3 && k.length < 3
  9147. ) {
  9148. const vt = `${v}`;
  9149. if (vt.length >= 21 && vt.includes(".style[")) {
  9150. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  9151. arr.push(k);
  9152. } else {
  9153. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  9154. }
  9155. }
  9156. }
  9157.  
  9158. }
  9159.  
  9160. if (arr.length === 0) {
  9161.  
  9162. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9163. } else {
  9164.  
  9165. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9166. return arr[0];
  9167. }
  9168.  
  9169. }
  9170.  
  9171. const addProtoToArr = (parent, key, arr) => {
  9172.  
  9173.  
  9174. let isChildProto = false;
  9175. for (const sr of arr) {
  9176. if (parent[key].prototype instanceof parent[sr]) {
  9177. isChildProto = true;
  9178. break;
  9179. }
  9180. }
  9181.  
  9182. if (isChildProto) return;
  9183.  
  9184. arr = arr.filter(sr => {
  9185. if (parent[sr].prototype instanceof parent[key]) {
  9186. return false;
  9187. }
  9188. return true;
  9189. });
  9190.  
  9191. arr.push(key);
  9192.  
  9193. return arr;
  9194.  
  9195.  
  9196. }
  9197.  
  9198. const getuG = (_yt_player) => {
  9199.  
  9200. const w = 'uG';
  9201.  
  9202. let arr = [];
  9203.  
  9204. for (const [k, v] of Object.entries(_yt_player)) {
  9205.  
  9206.  
  9207. const p = typeof v === 'function' ? v.prototype : 0;
  9208.  
  9209. if (p
  9210. && typeof p.createElement === 'function' && p.createElement.length === 2
  9211. && typeof p.detach === 'function' && p.detach.length === 0
  9212. && typeof p.update === 'function' && p.update.length === 1
  9213. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  9214. ) {
  9215.  
  9216. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9217.  
  9218. }
  9219.  
  9220. }
  9221.  
  9222.  
  9223.  
  9224.  
  9225.  
  9226. if (arr.length === 0) {
  9227.  
  9228. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9229. } else {
  9230.  
  9231. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9232. return arr[0];
  9233. }
  9234.  
  9235. }
  9236.  
  9237.  
  9238. const getQT = (_yt_player) => {
  9239. const w = 'QT';
  9240.  
  9241. let arr = [];
  9242. let brr = new Map();
  9243.  
  9244. for (const [k, v] of Object.entries(_yt_player)) {
  9245.  
  9246. const p = typeof v === 'function' ? v.prototype : 0;
  9247. if (p) {
  9248. let q = 0;
  9249. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9250. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9251. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9252.  
  9253. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9254.  
  9255. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9256.  
  9257. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9258. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9259. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9260. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9261.  
  9262.  
  9263. // differentiate QT and DX
  9264.  
  9265. q += 280;
  9266. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  9267. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  9268. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  9269. if (typeof p.seekBy === 'function') q += 4;
  9270. if (typeof p.seekTo === 'function') q += 4;
  9271. if (typeof p.getStoryboardFormat === 'function') q += 4;
  9272. if (typeof p.getDuration === 'function') q += 4;
  9273. if (typeof p.loadModule === 'function') q += 4;
  9274. if (typeof p.unloadModule === 'function') q += 4;
  9275. if (typeof p.getOption === 'function') q += 4;
  9276. if (typeof p.getOptions === 'function') q += 4;
  9277. if (typeof p.setOption === 'function') q += 4;
  9278. if (typeof p.addCueRange === 'function') q += 4;
  9279. if (typeof p.getDebugText === 'function') q += 4;
  9280. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  9281. if (typeof p.setSizeStyle === 'function') q += 4;
  9282. if (typeof p.showControls === 'function') q += 4;
  9283. if (typeof p.hideControls === 'function') q += 4;
  9284. if (typeof p.getVideoContentRect === 'function') q += 4;
  9285. if (typeof p.toggleFullscreen === 'function') q += 4;
  9286. if (typeof p.isFullscreen === 'function') q += 4;
  9287. if (typeof p.cancelPlayback === 'function') q += 4;
  9288. if (typeof p.getProgressState === 'function') q += 4;
  9289. if (typeof p.isInline === 'function') q += 4;
  9290. if (typeof p.setInline === 'function') q += 4;
  9291. if (typeof p.toggleSubtitles === 'function') q += 4;
  9292. if (typeof p.getPlayerSize === 'function') q += 4;
  9293. if (typeof p.wakeUpControls === 'function') q += 4;
  9294. if (typeof p.setCenterCrop === 'function') q += 4;
  9295. if (typeof p.getLoopVideo === 'function') q += 4;
  9296. if (typeof p.setLoopVideo === 'function') q += 4;
  9297.  
  9298.  
  9299. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9300.  
  9301. if (q > 0) brr.set(k, q);
  9302.  
  9303. }
  9304.  
  9305. }
  9306.  
  9307. if (arr.length === 0) {
  9308.  
  9309. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9310. } else {
  9311.  
  9312. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9313.  
  9314. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9315.  
  9316. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9317. return arr[0][0];
  9318. }
  9319.  
  9320.  
  9321.  
  9322. }
  9323.  
  9324.  
  9325.  
  9326. const getSV = (_yt_player) => {
  9327. const w = 'SV';
  9328.  
  9329. let arr = [];
  9330. let brr = new Map();
  9331.  
  9332. for (const [k, v] of Object.entries(_yt_player)) {
  9333.  
  9334. const p = typeof v === 'function' ? v.prototype : 0;
  9335. if (p) {
  9336. let q = 0;
  9337. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9338. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9339. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9340.  
  9341. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  9342.  
  9343. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9344.  
  9345. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9346. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9347. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9348. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9349.  
  9350.  
  9351. // differentiate QT and DX
  9352.  
  9353.  
  9354. q += 280;
  9355.  
  9356. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9357. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9358. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9359. if (typeof p.seekBy === 'function') q -= 4;
  9360. if (typeof p.seekTo === 'function') q -= 4;
  9361. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9362. if (typeof p.getDuration === 'function') q -= 4;
  9363. if (typeof p.loadModule === 'function') q -= 4;
  9364. if (typeof p.unloadModule === 'function') q -= 4;
  9365. if (typeof p.getOption === 'function') q -= 4;
  9366. if (typeof p.getOptions === 'function') q -= 4;
  9367. if (typeof p.setOption === 'function') q -= 4;
  9368. if (typeof p.addCueRange === 'function') q -= 4;
  9369. if (typeof p.getDebugText === 'function') q -= 4;
  9370. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9371. if (typeof p.setSizeStyle === 'function') q -= 4;
  9372. if (typeof p.showControls === 'function') q -= 4;
  9373. if (typeof p.hideControls === 'function') q -= 4;
  9374. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9375. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9376. if (typeof p.isFullscreen === 'function') q -= 4;
  9377. if (typeof p.cancelPlayback === 'function') q -= 4;
  9378. if (typeof p.getProgressState === 'function') q -= 4;
  9379. if (typeof p.isInline === 'function') q -= 4;
  9380. if (typeof p.setInline === 'function') q -= 4;
  9381. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9382. if (typeof p.getPlayerSize === 'function') q -= 4;
  9383. if (typeof p.wakeUpControls === 'function') q -= 4;
  9384. if (typeof p.setCenterCrop === 'function') q -= 4;
  9385. if (typeof p.getLoopVideo === 'function') q -= 4;
  9386. if (typeof p.setLoopVideo === 'function') q -= 4;
  9387.  
  9388.  
  9389. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9390.  
  9391. if (q > 0) brr.set(k, q);
  9392.  
  9393. }
  9394.  
  9395. }
  9396.  
  9397. if (arr.length === 0) {
  9398.  
  9399. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9400. } else {
  9401.  
  9402. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9403.  
  9404. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9405.  
  9406. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9407. return arr[0][0];
  9408. }
  9409.  
  9410.  
  9411.  
  9412. }
  9413.  
  9414.  
  9415.  
  9416.  
  9417. const getDX = (_yt_player) => {
  9418. const w = 'DX';
  9419.  
  9420. let arr = [];
  9421. let brr = new Map();
  9422.  
  9423. for (const [k, v] of Object.entries(_yt_player)) {
  9424.  
  9425. const p = typeof v === 'function' ? v.prototype : 0;
  9426. if (p) {
  9427. let q = 0;
  9428. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9429. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9430. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9431.  
  9432. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9433.  
  9434.  
  9435. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  9436.  
  9437. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9438.  
  9439. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9440. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9441. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9442. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9443.  
  9444.  
  9445. // differentiate QT and DX
  9446.  
  9447.  
  9448. q += 280;
  9449.  
  9450. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9451. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9452. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9453. if (typeof p.seekBy === 'function') q -= 4;
  9454. if (typeof p.seekTo === 'function') q -= 4;
  9455. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9456. if (typeof p.getDuration === 'function') q -= 4;
  9457. if (typeof p.loadModule === 'function') q -= 4;
  9458. if (typeof p.unloadModule === 'function') q -= 4;
  9459. if (typeof p.getOption === 'function') q -= 4;
  9460. if (typeof p.getOptions === 'function') q -= 4;
  9461. if (typeof p.setOption === 'function') q -= 4;
  9462. if (typeof p.addCueRange === 'function') q -= 4;
  9463. if (typeof p.getDebugText === 'function') q -= 4;
  9464. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9465. if (typeof p.setSizeStyle === 'function') q -= 4;
  9466. if (typeof p.showControls === 'function') q -= 4;
  9467. if (typeof p.hideControls === 'function') q -= 4;
  9468. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9469. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9470. if (typeof p.isFullscreen === 'function') q -= 4;
  9471. if (typeof p.cancelPlayback === 'function') q -= 4;
  9472. if (typeof p.getProgressState === 'function') q -= 4;
  9473. if (typeof p.isInline === 'function') q -= 4;
  9474. if (typeof p.setInline === 'function') q -= 4;
  9475. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9476. if (typeof p.getPlayerSize === 'function') q -= 4;
  9477. if (typeof p.wakeUpControls === 'function') q -= 4;
  9478. if (typeof p.setCenterCrop === 'function') q -= 4;
  9479. if (typeof p.getLoopVideo === 'function') q -= 4;
  9480. if (typeof p.setLoopVideo === 'function') q -= 4;
  9481.  
  9482.  
  9483. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9484.  
  9485. if (q > 0) brr.set(k, q);
  9486.  
  9487. }
  9488.  
  9489. }
  9490.  
  9491. if (arr.length === 0) {
  9492.  
  9493. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9494. } else {
  9495.  
  9496. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9497.  
  9498. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9499.  
  9500. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9501. return arr[0][0];
  9502. }
  9503.  
  9504.  
  9505.  
  9506. }
  9507.  
  9508.  
  9509.  
  9510. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  9511.  
  9512. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  9513. let pageSetupState = 0;
  9514.  
  9515. isPrepareCachedV && (() => {
  9516.  
  9517. pageSetupVideoId = '';
  9518. const clearCachedV = () => {
  9519. pageSetupVideoId = '';
  9520. pageSetupState = 0;
  9521. }
  9522. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  9523. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  9524. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  9525. document.addEventListener('yt-navigate-finish', () => {
  9526. pageSetupState = 1;
  9527. try {
  9528. const url = new URL(location.href);
  9529. if (!url || !isWatchPageURL(url)) {
  9530. pageSetupVideoId = '';
  9531. } else {
  9532. pageSetupVideoId = url.searchParams.get('v') || '';
  9533. }
  9534. } catch (e) {
  9535. pageSetupVideoId = '';
  9536. }
  9537. }, false);
  9538.  
  9539. })();
  9540.  
  9541. let videoPlayingY = null;
  9542.  
  9543. isPrepareCachedV && (() => {
  9544.  
  9545. let getNext = true;
  9546. let videoPlayingX = {
  9547. get videoId() {
  9548. if (getNext) {
  9549. getNext = false;
  9550.  
  9551. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  9552. const arr = [];
  9553. for (const element of elements) {
  9554. if (!element.closest('[hidden]')) arr.push(element);
  9555. }
  9556. if (arr.length !== 1) this.__videoId__ = '';
  9557. else {
  9558. this.__videoId__ = arr[0].getAttribute('video-id');
  9559. }
  9560.  
  9561. }
  9562. return this.__videoId__ || '';
  9563. }
  9564. }
  9565.  
  9566. videoPlayingY = videoPlayingX;
  9567. const handler = (evt) => {
  9568. const target = (evt || 0).target;
  9569. if (target instanceof HTMLVideoElement) {
  9570. getNext = true;
  9571. }
  9572. }
  9573. document.addEventListener('loadedmetadata', handler, true);
  9574. document.addEventListener('durationchange', handler, true);
  9575.  
  9576. })();
  9577.  
  9578.  
  9579.  
  9580. const cleanContext = async (win) => {
  9581. const waitFn = requestAnimationFrame; // shall have been binded to window
  9582. try {
  9583. let mx = 16; // MAX TRIAL
  9584. const frameId = 'vanillajs-iframe-v1';
  9585. /** @type {HTMLIFrameElement | null} */
  9586. let frame = document.getElementById(frameId);
  9587. let removeIframeFn = null;
  9588. if (!frame) {
  9589. frame = document.createElement('iframe');
  9590. frame.id = frameId;
  9591. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  9592. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  9593. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  9594. n.appendChild(frame);
  9595. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  9596. const root = document.documentElement;
  9597. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  9598. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  9599.  
  9600. removeIframeFn = (setTimeout) => {
  9601. const removeIframeOnDocumentReady = (e) => {
  9602. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9603. e = n;
  9604. n = win = removeIframeFn = 0;
  9605. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  9606. }
  9607. if (!setTimeout || document.readyState !== 'loading') {
  9608. removeIframeOnDocumentReady();
  9609. } else {
  9610. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9611. }
  9612. }
  9613. }
  9614. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  9615. const fc = frame.contentWindow;
  9616. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  9617. try {
  9618. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  9619. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  9620. for (let k in res) res[k] = res[k].bind(win); // necessary
  9621. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  9622. res.animate = fc.HTMLElement.prototype.animate;
  9623. res.perfNow = fc.performance.now;
  9624. return res;
  9625. } catch (e) {
  9626. if (removeIframeFn) removeIframeFn();
  9627. return null;
  9628. }
  9629. } catch (e) {
  9630. console.warn(e);
  9631. return null;
  9632. }
  9633. };
  9634.  
  9635. const promiseForYtActionCalled = new Promise(resolve => {
  9636.  
  9637. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9638. if (typeof AbortSignal !== 'undefined') {
  9639. let hn = () => {
  9640. if (!hn) return;
  9641. hn = null;
  9642. resolve(document.querySelector(appTag));
  9643. };
  9644. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  9645. } else {
  9646. let hn = () => {
  9647. if (!hn) return;
  9648. document.removeEventListener('yt-action', hn, true);
  9649. hn = null;
  9650. resolve(document.querySelector(appTag));
  9651. };
  9652. document.addEventListener('yt-action', hn, true);
  9653. }
  9654. });
  9655.  
  9656. cleanContext(window).then(__CONTEXT__ => {
  9657. if (!__CONTEXT__) return null;
  9658.  
  9659. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  9660.  
  9661.  
  9662. performance.now17 = perfNow.bind(performance);
  9663.  
  9664.  
  9665.  
  9666. __requestAnimationFrame__ = requestAnimationFrame;
  9667.  
  9668.  
  9669. const isGPUAccelerationAvailable = (() => {
  9670. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  9671. try {
  9672. const canvas = document.createElement('canvas');
  9673. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  9674. } catch (e) {
  9675. return false;
  9676. }
  9677. })();
  9678.  
  9679. const foregroundPromiseFn_noGPU = (() => {
  9680.  
  9681. if (isGPUAccelerationAvailable) return null;
  9682.  
  9683. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  9684. if (!pd || typeof pd.get !== 'function') return null;
  9685. const pdGet = pd.get;
  9686.  
  9687. let pr = null;
  9688.  
  9689. let hState = pdGet.call(document) === 'hidden';
  9690. // let cid = 0;
  9691. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  9692. const newHState = pdGet.call(document) === 'hidden';
  9693. if (hState !== newHState) {
  9694. // if (cid > 0) cid = clearInterval(cid);
  9695. hState = newHState;
  9696. if (!hState && pr) pr = pr.resolve();
  9697. }
  9698. });
  9699.  
  9700. // cid = setInterval(() => {
  9701. // const newHState = document.visibilityState === 'hidden';
  9702. // if (hState !== newHState) {
  9703. // hState = newHState;
  9704. // if (!hState && pr) pr = pr.resolve();
  9705. // }
  9706. // }, 100);
  9707.  
  9708.  
  9709. return (() => {
  9710. if (pr) return pr;
  9711. const w = ((!hState && setTimeout(() => {
  9712. if (!hState && pr === w) pr = pr.resolve();
  9713. })), (pr = new PromiseExternal()));
  9714. return w;
  9715. });
  9716.  
  9717. })();
  9718.  
  9719.  
  9720. let rafPromise = null;
  9721. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  9722. requestAnimationFrame(hRes => {
  9723. rafPromise = null;
  9724. resolve(hRes);
  9725. });
  9726. }));
  9727.  
  9728. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  9729.  
  9730.  
  9731. const wmComputedStyle = new WeakMap();
  9732.  
  9733. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  9734. window.__native__getComputedStyle__ = getComputedStyle;
  9735. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  9736. window.__original__getComputedStyle__ = window.getComputedStyle;
  9737. window.getComputedStyle = function (elem) {
  9738. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  9739. return window.__original__getComputedStyle__(...arguments);
  9740. }
  9741. let cs = wmComputedStyle.get(elem);
  9742. if (!cs) {
  9743. cs = window.__native__getComputedStyle__(elem);
  9744. wmComputedStyle.set(elem, cs);
  9745. }
  9746. return cs;
  9747. };
  9748. } else {
  9749. window.__original__getComputedStyle__ = null;
  9750. }
  9751. window.__jst__getComputedStyle__ = window.getComputedStyle;
  9752. }
  9753.  
  9754. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  9755. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  9756. window.getComputedStyle = window.__jst__getComputedStyle__;
  9757. }
  9758. });
  9759.  
  9760. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  9761. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  9762.  
  9763. const promiseForTamerTimeout = new Promise(resolve => {
  9764. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9765. setTimeout(resolve, 480);
  9766. }, { capture: true, passive: true, once: true });
  9767. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9768. setTimeout(resolve, 1200);
  9769. });
  9770. setTimeout(resolve, 3000);
  9771. });
  9772.  
  9773. const promiseForPageInitied = new Promise(resolve => {
  9774. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9775. setTimeout(resolve, 450);
  9776. }, { capture: true, passive: true, once: true });
  9777. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9778. setTimeout(resolve, 900);
  9779. });
  9780. setTimeout(resolve, 1800);
  9781. });
  9782.  
  9783. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  9784. NO_PRELOAD_GENERATE_204_BYPASS = true;
  9785. headLinkCollection = null;
  9786. });
  9787.  
  9788.  
  9789. NATIVE_CANVAS_ANIMATION && (() => {
  9790.  
  9791. observablePromise(() => {
  9792. HTMLCanvasElement.prototype.animate = animate;
  9793. }, promiseForTamerTimeout).obtain();
  9794.  
  9795. })();
  9796.  
  9797.  
  9798.  
  9799.  
  9800. FIX_ytAction_ && (async () => {
  9801.  
  9802. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9803.  
  9804. const ytdApp = await new Promise(resolve => {
  9805.  
  9806. whenCEDefined(appTag).then(() => {
  9807. const ytdApp = document.querySelector(appTag);
  9808. if (ytdApp) {
  9809. resolve(ytdApp);
  9810. return;
  9811. }
  9812. let mo = new MutationObserver(() => {
  9813. const ytdApp = document.querySelector(appTag);
  9814. if (!ytdApp) return;
  9815. if (mo) {
  9816. mo.disconnect();
  9817. mo.takeRecords();
  9818. mo = null;
  9819. }
  9820. resolve(ytdApp);
  9821. });
  9822. mo.observe(document, { subtree: true, childList: true });
  9823. });
  9824.  
  9825. });
  9826.  
  9827. if (!ytdApp) return;
  9828. const cProto = insp(ytdApp).constructor.prototype;
  9829.  
  9830. if (!cProto) return;
  9831. let mbd = 0;
  9832.  
  9833. const fixer = (_ytdApp) => {
  9834. const ytdApp = insp(_ytdApp);
  9835. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9836. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9837. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9838. mbd++;
  9839. }
  9840. }
  9841.  
  9842. observablePromise(() => {
  9843.  
  9844. if (typeof cProto.created === 'function' && !cProto.created56) {
  9845. cProto.created56 = cProto.created;
  9846. cProto.created = function (...args) {
  9847. const r = this.created56(...args);
  9848. fixer(this);
  9849. return r;
  9850. };
  9851. mbd++;
  9852. }
  9853.  
  9854. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9855. cProto.onYtAction57_ = cProto.onYtAction_;
  9856. cProto.onYtAction_ = function (...args) {
  9857. Promise.resolve().then(() => this.onYtAction57_(...args));
  9858. };
  9859. mbd++;
  9860. }
  9861.  
  9862. if (ytdApp) fixer(ytdApp);
  9863.  
  9864. /*
  9865. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9866. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9867. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9868. actionRouter_.handleAction = function (...args) {
  9869. Promise.resolve().then(() => this.handleAction57(...args));
  9870. }
  9871. mbd++;
  9872. }
  9873. */
  9874.  
  9875. // if(mbd === 3) return 1;
  9876. if (mbd >= 3) return 1;
  9877.  
  9878. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9879.  
  9880. })();
  9881.  
  9882.  
  9883. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9884.  
  9885. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9886.  
  9887. const app = await observablePromise(() => {
  9888.  
  9889. return document.querySelector(appTag);
  9890.  
  9891. }).obtain();
  9892.  
  9893. if (!app) return;
  9894.  
  9895. const appCnt = insp(app);
  9896. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9897.  
  9898.  
  9899.  
  9900.  
  9901. });
  9902.  
  9903.  
  9904. // let _yt_player_promise = null;
  9905. /*
  9906. const getYtPlayerPromise = () => {
  9907. if (!_yt_player_promise) {
  9908. _yt_player_promise = new Promise(resolve => {
  9909. let cid = setInterval(() => {
  9910. let t = (((window || 0)._yt_player || 0) || 0);
  9911. if (t) {
  9912. clearInterval(cid);
  9913. resolve(t);
  9914. }
  9915. }, 1);
  9916. promiseForTamerTimeout.then(() => {
  9917. resolve(null)
  9918. });
  9919. });
  9920. }
  9921. return _yt_player_promise;
  9922. }
  9923. */
  9924. const _yt_player_observable = observablePromise(() => {
  9925. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9926. if (_yt_player) {
  9927. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9928. return _yt_player;
  9929. }
  9930. }, promiseForTamerTimeout);
  9931.  
  9932. const polymerObservable = observablePromise(() => {
  9933. const Polymer = window.Polymer;
  9934. if (typeof Polymer !== 'function') return;
  9935. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9936. return Polymer;
  9937. }, promiseForTamerTimeout);
  9938.  
  9939. const schedulerInstanceObservable = observablePromise(() => {
  9940. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9941. }, promiseForTamerTimeout);
  9942.  
  9943. const timelineObservable = observablePromise(() => {
  9944. let t = (((document || 0).timeline || 0) || 0);
  9945. if (t && typeof t._play === 'function') {
  9946. return t;
  9947. }
  9948. }, promiseForTamerTimeout);
  9949. const animationObservable = observablePromise(() => {
  9950. let t = (((window || 0).Animation || 0) || 0);
  9951. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9952. return t;
  9953. }
  9954. }, promiseForTamerTimeout);
  9955.  
  9956.  
  9957. const getScreenInfo = {
  9958. screenWidth: 0,
  9959. screenHeight: 0,
  9960. valueReady: false,
  9961. onResize: () => {
  9962. getScreenInfo.valueReady = false;
  9963. },
  9964. sizeProvided: () => {
  9965. if (getScreenInfo.valueReady) return true;
  9966. getScreenInfo.screenWidth = screen.width;
  9967. getScreenInfo.screenHeight = screen.height;
  9968. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9969. getScreenInfo.valueReady = true;
  9970. return true;
  9971. }
  9972. return false;
  9973. }
  9974. };
  9975.  
  9976. window.addEventListener('resize', getScreenInfo.onResize, true);
  9977.  
  9978.  
  9979. // const hookLeftPending = new WeakMap();
  9980.  
  9981. const isNaNx = Number.isNaN;
  9982.  
  9983. const hookLeftPD = {
  9984. get() {
  9985. const p = 'left';
  9986. // const o = hookLeftPending.get(this);
  9987. // if (o && o.key) {
  9988. // this.setProperty(p, o.value);
  9989. // o.key = null
  9990. // }
  9991. return this.getPropertyValue(p);
  9992. },
  9993. set(v) {
  9994.  
  9995. const p = 'left';
  9996. const cv = this.getPropertyValue(p);
  9997. const sv = v;
  9998.  
  9999. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  10000.  
  10001. // console.log(8380,did, cv, sv)
  10002. if (!cv && !sv) return true;
  10003. if (cv === sv) return true;
  10004.  
  10005. // skip 0~9px => L>=4
  10006.  
  10007. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  10008.  
  10009. if (!isNaNx(qsv)) {
  10010. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  10011.  
  10012. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  10013. const { screenWidth, screenHeight } = getScreenInfo;
  10014. let pWidth = screenWidth + 1024;
  10015. let pHeight = screenHeight + 768;
  10016. const minRatio = 0.003;
  10017. const dw = pWidth * 0.0003; // min dw = 0.3072
  10018. const dh = pHeight * 0.0003; // min dh = 0.2304
  10019. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  10020. if (Math.abs(qcv - qsv) < dw) return true;
  10021. }
  10022.  
  10023. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  10024. if (`${v}`.length > `${sv}`.length) v = sv;
  10025. // console.log(8382, did, sv, nv, cv, this)
  10026. }
  10027.  
  10028. // Promise.resolve().then(() => {
  10029. // const o = hookLeftPending.get(this);
  10030. // if (o && o.key === did) {
  10031. // this.setProperty(p, o.value);
  10032. // o.key = null;
  10033. // }
  10034. // });
  10035. // hookLeftPending.set(this, {
  10036. // key: did,
  10037. // value: nv
  10038. // });
  10039.  
  10040. // if (nv != v) {
  10041. // console.log(8387, v, nv);
  10042. // }
  10043.  
  10044. this.setProperty(p, v);
  10045. // console.log(8383, did, this.getPropertyValue(p))
  10046. return true;
  10047. },
  10048. enumerable: true,
  10049. configurable: true
  10050. };
  10051.  
  10052.  
  10053. if (HOOK_CSSPD_LEFT) {
  10054.  
  10055.  
  10056. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  10057.  
  10058. }
  10059.  
  10060.  
  10061.  
  10062.  
  10063.  
  10064. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  10065.  
  10066. const evKey = `${_evKey}`;
  10067. const fvKey = `${_fvKey}`;
  10068. const debug = !!_debug;
  10069.  
  10070. const _yt_player = await _yt_player_observable.obtain();
  10071.  
  10072.  
  10073. if (!_yt_player || typeof _yt_player !== 'object') return;
  10074.  
  10075.  
  10076. const getArr = (_yt_player) => {
  10077.  
  10078. let arr = [];
  10079.  
  10080. for (const [k, v] of Object.entries(_yt_player)) {
  10081.  
  10082. const p = typeof v === 'function' ? v.prototype : 0;
  10083. if (p
  10084. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  10085.  
  10086. ) {
  10087. arr = addProtoToArr(_yt_player, k, arr) || arr;
  10088.  
  10089. }
  10090.  
  10091. }
  10092.  
  10093. if (arr.length === 0) {
  10094.  
  10095. console.warn(`Key prop [${evKey}] does not exist.`);
  10096. } else {
  10097.  
  10098. return arr;
  10099. }
  10100.  
  10101. };
  10102.  
  10103. const arr = getArr(_yt_player);
  10104.  
  10105.  
  10106. if (!arr) return;
  10107.  
  10108. debug && console.log(`FIX_${evKey}`, arr);
  10109.  
  10110. const f = function (...args) {
  10111. Promise.resolve().then(() => this[fvKey](...args));
  10112. };
  10113.  
  10114.  
  10115. for (const k of arr) {
  10116.  
  10117. const g = _yt_player;
  10118. const gk = g[k];
  10119. const gkp = gk.prototype;
  10120.  
  10121. debug && console.log(237, k, gkp)
  10122.  
  10123. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  10124. gkp[fvKey] = gkp[evKey];
  10125. gkp[evKey] = f;
  10126. }
  10127. }
  10128.  
  10129.  
  10130.  
  10131.  
  10132. }
  10133.  
  10134. if (!isChatRoomURL) {
  10135.  
  10136. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  10137. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  10138. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  10139. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  10140. if (FIX_VideoEVENTS_v2) {
  10141. const FIX_VideoEVENTS_DEBUG = 0;
  10142. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  10143. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  10144. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  10145. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  10146. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  10147. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  10148. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  10149. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  10150. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  10151.  
  10152. }
  10153. // onMutedAutoplayChange
  10154. // onVolumeChange
  10155. // onPlaybackRateChange
  10156.  
  10157. // onAirPlayActiveChange
  10158. // onAirPlayAvailabilityChange
  10159. // onApiChange
  10160. // onAutoplayBlocked
  10161. // onDrmOutputRestricted
  10162. // onFullscreenChange
  10163. // onLoadProgress
  10164. // onLoadedMetadata
  10165. // onVideoDataChange
  10166. // onVideoProgress
  10167.  
  10168. }
  10169.  
  10170.  
  10171. let isAmended_Polymer_RenderStatus = false;
  10172.  
  10173. (FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  10174.  
  10175. const Polymer = await polymerObservable.obtain();
  10176. if (!Polymer) return;
  10177.  
  10178. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  10179. isAmended_Polymer_RenderStatus = true;
  10180.  
  10181. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  10182. let arrBefore = null, arrAfter = null;
  10183. const push = Array.prototype.push;
  10184. let arr = null;
  10185. Array.prototype.push = function () {
  10186. arr = this;
  10187. }
  10188. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  10189. if (arr) arrBefore = arr;
  10190. arr = null;
  10191. Polymer.RenderStatus.afterNextRender({}, {}, {});
  10192. if (arr) arrAfter = arr;
  10193. arr = null;
  10194. Array.prototype.push = push;
  10195. Polymer.RenderStatus.arrBefore = arrBefore;
  10196. Polymer.RenderStatus.arrAfter = arrAfter;
  10197.  
  10198. if (arrBefore && arrAfter) {
  10199.  
  10200. Function.prototype.call7900 = Function.prototype.call;
  10201. Function.prototype.apply7900 = Function.prototype.apply;
  10202. Function.prototype.apply7948 = function (obj, args) {
  10203. const f = this;
  10204. let m = kRef(obj);
  10205. if (!m) return;
  10206. if (m.is && !m.nodeName) {
  10207. if (!m.isAttached || !m.hostElement) {
  10208. return;
  10209. }
  10210. }
  10211. try {
  10212. return !args ? f.call7900(m) : f.apply7900(m, args);
  10213. } catch (e) {
  10214. console.warn(e);
  10215. }
  10216. return null;
  10217. }
  10218.  
  10219. arrBefore.push = arrAfter.push = function (a) {
  10220. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  10221. if (a[0].deref) a[0] = kRef(a[0]);
  10222. const f = a[1]
  10223. const obj = a[0]
  10224. const args = a[2];
  10225. f.apply = f.apply7948;
  10226. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  10227. a[0] = obj[wk]
  10228. // console.log(4992, a)
  10229. return push.call(this, a);
  10230. }
  10231.  
  10232. }
  10233.  
  10234.  
  10235. }
  10236. // Polymer.RenderStatus.beforeNextRender
  10237. }
  10238.  
  10239. if (FIX_Polymer_dom) {
  10240.  
  10241. const checkPDFuncValue = (pd) => {
  10242. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  10243. }
  10244. const checkPDFuncValue2 = (pd) => {
  10245. return pd && typeof pd.value == 'function'
  10246. }
  10247.  
  10248. const checkPDFuncGet = (pd) => {
  10249. return pd && typeof pd.get == 'function'
  10250. }
  10251.  
  10252. const domX = Polymer.dom(document.createElement('null'));
  10253. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  10254. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  10255. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  10256. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  10257. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  10258. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  10259. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  10260. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  10261. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  10262.  
  10263.  
  10264. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  10265.  
  10266. domXP.querySelector15 = domXP.querySelector;
  10267.  
  10268. const querySelectorFn = function (query) {
  10269. try {
  10270. const p = this.node;
  10271.  
  10272. if (p instanceof Document && p.isConnected === true) {
  10273. return pd4b.value.call(p, query);
  10274. }
  10275.  
  10276. } catch (e) { }
  10277. return this.querySelector15(query);
  10278. }
  10279.  
  10280. Object.defineProperty(domXP, 'querySelector', {
  10281. get() {
  10282. return querySelectorFn;
  10283. },
  10284. set(nv) {
  10285. if (nv === querySelectorFn) return true;
  10286. this.querySelector15 = nv;
  10287. return true;
  10288. },
  10289.  
  10290. enumerable: false,
  10291. configurable: true
  10292. });
  10293.  
  10294. Polymer.__fixedQuerySelector__ = 1;
  10295. }
  10296.  
  10297. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  10298.  
  10299. domXP.querySelectorAll15 = domXP.querySelectorAll;
  10300.  
  10301. const querySelectorAllFn = function (query) {
  10302.  
  10303. try {
  10304.  
  10305. const p = this.node;
  10306.  
  10307. if (p instanceof Document && p.isConnected === true) {
  10308. return pd6b.value.call(p, query);
  10309. }
  10310.  
  10311. } catch (e) {
  10312.  
  10313. }
  10314. return this.querySelectorAll15(query);
  10315. }
  10316.  
  10317. Object.defineProperty(domXP, 'querySelectorAll', {
  10318. get() {
  10319. return querySelectorAllFn;
  10320. },
  10321. set(nv) {
  10322. if (nv === querySelectorAllFn) return true;
  10323. this.querySelectorAll15 = nv;
  10324. return true;
  10325. },
  10326.  
  10327. enumerable: false,
  10328. configurable: true
  10329. });
  10330.  
  10331. Polymer.__fixedQuerySelectorAll__ = 1;
  10332. }
  10333. }
  10334.  
  10335.  
  10336. if (FIX_stampDomArray) {
  10337.  
  10338. Polymer.Base.__connInit__ = function () {
  10339. setupYtComponent(this);
  10340. }
  10341.  
  10342.  
  10343. /** @type {Function} */
  10344. const connectedCallbackK = function (...args) {
  10345. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10346. const r = this[qm53](...args);
  10347. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10348. this.mh35 = 1;
  10349. return r;
  10350. };
  10351.  
  10352. connectedCallbackK.m353 = 1;
  10353.  
  10354.  
  10355. const qt53 = Polymer.Base.connectedCallback;
  10356. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  10357.  
  10358. Polymer.Base.connectedCallback = connectedCallbackK;
  10359.  
  10360.  
  10361. /** @type {Function} */
  10362. const createdK = function (...args) {
  10363. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10364. const r = this[qn53](...args);
  10365. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10366. this.mh36 = 1;
  10367. return r;
  10368. };
  10369.  
  10370.  
  10371. createdK.m353 = 1;
  10372. Polymer.Base[qn53] = Polymer.Base.created;
  10373. Polymer.Base.created = createdK;
  10374.  
  10375.  
  10376.  
  10377.  
  10378.  
  10379.  
  10380.  
  10381.  
  10382.  
  10383.  
  10384.  
  10385. }
  10386.  
  10387. })();
  10388.  
  10389.  
  10390. /*
  10391.  
  10392. e.nativeAppendChild = d.prototype.appendChild,
  10393. d.prototype.appendChild = function(h) {
  10394. return function(l) {
  10395. if (l instanceof DocumentFragment) {
  10396. var m = Array.from(l.children);
  10397. l = h.nativeAppendChild.call(this, l);
  10398. if (this.isConnected) {
  10399. m = g(m);
  10400. for (var p = m.next(); !p.done; p = m.next())
  10401. YD(p.value)
  10402. }
  10403. return l
  10404. }
  10405. m = l instanceof Element && l.isConnected;
  10406. p = h.nativeAppendChild.call(this, l);
  10407. m && ZD(l);
  10408. this.isConnected && YD(l);
  10409. return p
  10410. }
  10411. }(e),
  10412.  
  10413. */
  10414.  
  10415. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  10416.  
  10417. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  10418. if (f) Node.prototype.appendChild = function (a) {
  10419. if (this instanceof Element) { // exclude DocumentFragment
  10420. try {
  10421. let checkFragmentA = (a instanceof DocumentFragment);
  10422. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  10423. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  10424. for (const node of headLinkCollection) {
  10425. if (node.rel === 'preload' && node.as === 'fetch') {
  10426. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  10427. }
  10428. }
  10429. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  10430. checkFragmentA = false;
  10431. }
  10432. if (checkFragmentA && a.firstElementChild === null) {
  10433. // no element in fragmentA
  10434. let doNormal = false;
  10435. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  10436. if (child.nodeType === 3) { doNormal = true; break; }
  10437. }
  10438. if (!doNormal) return a;
  10439. }
  10440. } catch (e) {
  10441. console.log(e);
  10442. }
  10443. }
  10444. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  10445. }
  10446.  
  10447. })();
  10448.  
  10449. if (FIX_Shady) {
  10450.  
  10451. observablePromise(() => {
  10452. const { ShadyDOM, ShadyCSS } = window;
  10453. if (ShadyDOM) {
  10454. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  10455. ShadyDOM.noPatch = true; // 1 of 10
  10456. ShadyDOM.patchOnDemand = false; // 1 of 10
  10457. ShadyDOM.preferPerformance = true; // 1 of 10
  10458. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  10459. }
  10460. if (ShadyCSS) {
  10461. ShadyCSS.nativeCss = true; // 1 of 10
  10462. ShadyCSS.nativeShadow = true; // 6 of 10
  10463. ShadyCSS.cssBuild = undefined; // 1 of 10
  10464. ShadyCSS.disableRuntime = true; // 1 of 10
  10465. }
  10466. if (ShadyDOM && ShadyCSS) return 1;
  10467. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  10468.  
  10469. }
  10470.  
  10471.  
  10472. // let schedulerInstancePropOfTimerType = '';
  10473. // let schedulerInstancePropOfTimerId = '';
  10474. (FIX_schedulerInstanceInstance & 2) && (async () => {
  10475.  
  10476. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  10477.  
  10478. if (!schedulerInstanceInstance_) return;
  10479.  
  10480. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  10481. if (checkOK) {
  10482.  
  10483. let resolveRendering = null;
  10484.  
  10485. let cmPr = new PromiseExternal();
  10486. const cm = document.createComment('0');
  10487. const cmObs = new MutationObserver(() => {
  10488. if (resolveRendering) {
  10489. resolveRendering();
  10490. resolveRendering = null;
  10491. }
  10492. cmPr.resolve();
  10493. cmPr = new PromiseExternal();
  10494. });
  10495. cmObs.observe(cm, {characterData: true})
  10496.  
  10497. let web_emulated_idle_callback_delay_val = null;
  10498.  
  10499. const getRenderIdleCallbackMs = () => {
  10500. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  10501. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  10502. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  10503. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  10504. return web_emulated_idle_callback_delay_val;
  10505. }
  10506. let isDelayRenderFn_firstCheck = true;
  10507. let isDelayRenderFn_key = null;
  10508. const isDelayRenderFn = (f) => {
  10509. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  10510. isDelayRenderFn_firstCheck = false;
  10511. if (typeof ytglobal === 'undefined') return false;
  10512. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  10513. if (!globalInstance) return false;
  10514. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  10515. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  10516. isDelayRenderFn_key = entry[0]
  10517. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  10518. return true;
  10519. }
  10520. }
  10521. return false;
  10522. }
  10523.  
  10524. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  10525.  
  10526. let requestingFn = null;
  10527. let requestingArgs = null;
  10528.  
  10529. const f = function () {
  10530. requestingFn = this.fn;
  10531. requestingArgs = [...arguments];
  10532. return 12373;
  10533. };
  10534.  
  10535. const fakeFns = [
  10536. f.bind({ fn: requestAnimationFrame }),
  10537. f.bind({ fn: setInterval }),
  10538. f.bind({ fn: setTimeout }),
  10539. f.bind({ fn: requestIdleCallback })
  10540. ];
  10541.  
  10542. let mzt = 0;
  10543.  
  10544. let _fnSelectorProp = null;
  10545. const mkFns = new Array(4);
  10546.  
  10547. /*
  10548. case 1:
  10549. var a = this.K;
  10550. this.g = this.I ? window.requestIdleCallback(a, {
  10551. timeout: 3E3
  10552. }) : window.setTimeout(a, ma);
  10553. break;
  10554. case 2:
  10555. this.g = window.setTimeout(this.M, this.N);
  10556. break;
  10557. case 3:
  10558. this.g = window.requestAnimationFrame(this.L);
  10559. break;
  10560. case 4:
  10561. this.g = window.setTimeout(this.J, 0)
  10562. }
  10563.  
  10564. */
  10565. const startFnHandler = {
  10566. get(target, prop, receiver) {
  10567. if (prop === '$$12377$$') return true;
  10568. if (prop === '$$12378$$') return target;
  10569.  
  10570. // console.log('get',prop)
  10571. return target[prop]
  10572. },
  10573. set(target, prop, value, receiver) {
  10574. // console.log('set', prop, value)
  10575.  
  10576.  
  10577. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  10578. if (value === 12373 && _fnSelectorProp) {
  10579.  
  10580. const schedulerTypeSelection = target[_fnSelectorProp];
  10581. const timerIdProp = prop;
  10582.  
  10583. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  10584. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  10585. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  10586. // schedulerInstancePropOfTimerId = timerIdProp || '';
  10587. // }
  10588.  
  10589. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  10590. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  10591. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  10592. // rare
  10593. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10594. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  10595. // often
  10596. if ((FIX_schedulerInstanceInstance & 4)) {
  10597. const f = requestingArgs[0];
  10598. const tir = ++mzt;
  10599. nextBrowserTick_(() => {
  10600. if (target[timerIdProp] === -tir) f();
  10601. });
  10602. target[_fnSelectorProp] = 940;
  10603. target[timerIdProp] = -tir;
  10604. } else {
  10605. const f = requestingArgs[0];
  10606. const tir = ++mzt;
  10607. Promise.resolve().then(() => {
  10608. if (target[timerIdProp] === -tir) f();
  10609. });
  10610. target[_fnSelectorProp] = 930;
  10611. target[timerIdProp] = -tir;
  10612. }
  10613. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  10614. // often
  10615. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  10616. cm.data = (cm.data & 7) + 1;
  10617. let renderFn = requestingArgs[0];
  10618. const resolveRendering_ = () => {
  10619. const renderFn_ = renderFn;
  10620. if (renderFn_) {
  10621. renderFn = null;
  10622. renderFn_();
  10623. }
  10624. };
  10625. resolveRendering = resolveRendering_;
  10626. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  10627. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  10628.  
  10629. // cm.data = (cm.data & 7) + 1;
  10630. // target[timerIdProp] = Math.random();
  10631.  
  10632. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  10633.  
  10634. cm.data = (cm.data & 7) + 1;
  10635.  
  10636. let renderFn = requestingArgs[0];
  10637. const resolveRendering_ = () => {
  10638. const renderFn_ = renderFn;
  10639. if (renderFn_) {
  10640. renderFn = null;
  10641. renderFn_();
  10642. }
  10643. };
  10644. resolveRendering = resolveRendering_;
  10645.  
  10646. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  10647.  
  10648.  
  10649. } else {
  10650. if (requestingFn === requestIdleCallback) {
  10651. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  10652. } else {
  10653. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10654. }
  10655. }
  10656. } else {
  10657. target[_fnSelectorProp] = 0;
  10658. target[timerIdProp] = 0;
  10659. }
  10660. } else {
  10661. target[prop] = value;
  10662. }
  10663. return true;
  10664. }
  10665. };
  10666.  
  10667. let startBusy = false;
  10668. schedulerInstanceInstance_.start = function () {
  10669. if (startBusy) return;
  10670. startBusy = true;
  10671. try {
  10672. mkFns[0] = window.requestAnimationFrame;
  10673. mkFns[1] = window.setInterval;
  10674. mkFns[2] = window.setTimeout;
  10675. mkFns[3] = window.requestIdleCallback;
  10676. const tThis = this['$$12378$$'] || this;
  10677. window.requestAnimationFrame = fakeFns[0]
  10678. window.setInterval = fakeFns[1]
  10679. window.setTimeout = fakeFns[2]
  10680. window.requestIdleCallback = fakeFns[3]
  10681. _fnSelectorProp = null;
  10682. tThis.start993.call(new Proxy(tThis, startFnHandler));
  10683. _fnSelectorProp = null;
  10684. window.requestAnimationFrame = mkFns[0];
  10685. window.setInterval = mkFns[1];
  10686. window.setTimeout = mkFns[2];
  10687. window.requestIdleCallback = mkFns[3];
  10688. } catch (e) {
  10689. console.warn(e);
  10690. }
  10691. startBusy = false;
  10692. }
  10693.  
  10694. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  10695.  
  10696. }
  10697. })();
  10698.  
  10699. FIX_yt_player && !isChatRoomURL && (async () => {
  10700.  
  10701. const fOption = 1 | 2 | 4;
  10702.  
  10703. const _yt_player = await _yt_player_observable.obtain();
  10704.  
  10705. if (!_yt_player || typeof _yt_player !== 'object') return;
  10706.  
  10707. const g = _yt_player;
  10708. let k;
  10709.  
  10710. if (fOption & 1) {
  10711.  
  10712. // rAf scheduling
  10713.  
  10714. const keyZqOu = getZqOu(_yt_player);
  10715. if (!keyZqOu) {
  10716. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  10717. return;
  10718. }
  10719. k = keyZqOu
  10720.  
  10721. const gk = g[k];
  10722. if (typeof gk !== 'function') {
  10723. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  10724. return;
  10725. }
  10726. const gkp = gk.prototype;
  10727.  
  10728. const dummyObject = new gk;
  10729. const nilFunc = () => { };
  10730.  
  10731. const nilObj = {};
  10732.  
  10733. // console.log(1111111111)
  10734.  
  10735. let keyBoolD = '';
  10736. let keyWindow = '';
  10737. let keyFuncC = '';
  10738. let keyCidj = '';
  10739.  
  10740. for (const [t, y] of Object.entries(dummyObject)) {
  10741. if (y instanceof Window) keyWindow = t;
  10742. }
  10743.  
  10744. const dummyObjectProxyHandler = {
  10745. get(target, prop) {
  10746. let v = target[prop]
  10747. if (v instanceof Window && !keyWindow) {
  10748. keyWindow = t;
  10749. }
  10750. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  10751. if (prop === keyWindow) y = {
  10752. requestAnimationFrame(f) {
  10753. return 3;
  10754. },
  10755. cancelAnimationFrame() {
  10756.  
  10757. }
  10758. }
  10759. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  10760. keyFuncC = prop;
  10761. }
  10762. // console.log('[get]', prop, typeof target[prop])
  10763.  
  10764.  
  10765. return y;
  10766. },
  10767. set(target, prop, value) {
  10768.  
  10769. if (typeof value === 'boolean' && !keyBoolD) {
  10770. keyBoolD = prop;
  10771. }
  10772. if (typeof value === 'number' && !keyCidj && value >= 2) {
  10773. keyCidj = prop;
  10774. }
  10775.  
  10776. // console.log('[set]', prop, value)
  10777. target[prop] = value;
  10778.  
  10779. return true;
  10780. }
  10781. };
  10782.  
  10783. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  10784.  
  10785. // console.log('gkp.start',gkp.start);
  10786. // console.log('gkp.stop',gkp.stop);
  10787. gkp._activation = false;
  10788.  
  10789. gkp.start = function () {
  10790. // p59 || console.log(12100)
  10791. if (!this._activation) {
  10792. this._activation = true;
  10793. foregroundPromiseFn().then(() => {
  10794. this._activation = false;
  10795. if (this[keyCidj]) {
  10796. Promise.resolve().then(this[keyFuncC]);
  10797. }
  10798. });
  10799. }
  10800. this[keyCidj] = 1;
  10801. this[keyBoolD] = true;
  10802. };
  10803.  
  10804. gkp.stop = function () {
  10805. this[keyCidj] = null;
  10806. };
  10807.  
  10808.  
  10809. /*
  10810. g[k].start = function() {
  10811. this.stop();
  10812. this.D = true;
  10813. var a = requestAnimationFrame
  10814. , b = cancelAnimationFrame;
  10815. this.j = a.call(this.B, this.C)
  10816. }
  10817. ;
  10818. g[k].stop = function() {
  10819. if (this.isActive()) {
  10820. var a = requestAnimationFrame
  10821. , b = cancelAnimationFrame;
  10822. b.call(this.B, this.j)
  10823. }
  10824. this.j = null
  10825. }
  10826. */
  10827. }
  10828.  
  10829. if (fOption & 2) {
  10830. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10831.  
  10832. if (keyzo) {
  10833.  
  10834. k = keyzo;
  10835.  
  10836. const attrUpdateFn = g[k];
  10837. // console.log(5992, attrUpdateFn)
  10838. g['$$original$$' + k] = attrUpdateFn;
  10839. const zoTransform = async (a, c) => {
  10840.  
  10841. let transformType = '';
  10842. let transformValue = 0;
  10843. let transformUnit = '';
  10844. let transformTypeI = 0;
  10845.  
  10846. const aStyle = a.style;
  10847.  
  10848. let cType = 0;
  10849.  
  10850. const cl = c.length;
  10851.  
  10852. if (cl >= 8) {
  10853. // scale(1)
  10854. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10855. cType = 1;
  10856. let t = c.charCodeAt(5);
  10857. if (t === 88 || t === 120) cType = 1 | 4;
  10858. if (t === 89 || t === 121) cType = 1 | 8;
  10859. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10860. cType = 2;
  10861. let t = c.charCodeAt(9);
  10862. if (t === 88 || t === 120) cType = 2 | 4;
  10863. if (t === 89 || t === 121) cType = 2 | 8;
  10864. }
  10865. let w = 0;
  10866. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10867. let p = c.substring(7, cl - 1);
  10868. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10869. if (typeof q === 'number' && !isNaNx(q)) {
  10870. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10871. transformValue = q;
  10872. transformUnit = '';
  10873. transformTypeI = 1;
  10874. } else {
  10875. cType = 256;
  10876. }
  10877. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10878. if (c.endsWith('px)')) {
  10879. let p = c.substring(11, cl - 3);
  10880. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10881. if (typeof q === 'number' && !isNaNx(q)) {
  10882. transformType = w === 1 ? 'translateX' : 'translateY';
  10883. transformValue = q;
  10884. transformUnit = 'px';
  10885. transformTypeI = 2;
  10886. } else if (p === 'NaN') {
  10887. return;
  10888. }
  10889. } else {
  10890. cType = 256;
  10891. }
  10892. } else if (cType > 0) {
  10893. cType = 256;
  10894. }
  10895. }
  10896.  
  10897.  
  10898. if (cType === 256) {
  10899. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10900. }
  10901.  
  10902. if (transformTypeI === 1) {
  10903. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10904. const vz = toFixed2(q, 3);
  10905. c = `${transformType}(${vz})`;
  10906. const cv = aStyle.transform;
  10907. if (c === cv) return;
  10908. aStyle.transform = c;
  10909. } else if (transformTypeI === 2) {
  10910. const q = transformValue;
  10911. const vz = toFixed2(q, 1);
  10912. c = `${transformType}(${vz}${transformUnit})`;
  10913. const cv = aStyle.transform;
  10914. if (c === cv) return;
  10915. aStyle.transform = c;
  10916. } else { // eg empty
  10917. const cv = aStyle.transform;
  10918. if (!c && !cv) return;
  10919. else if (c === cv) return;
  10920. aStyle.transform = c;
  10921. }
  10922.  
  10923. };
  10924.  
  10925. const elmTransformTemp = new WeakMap();
  10926. const elmPropTemps = {
  10927. 'display': new WeakMap(),
  10928. 'width': new WeakMap(),
  10929. 'height': new WeakMap(),
  10930. 'outlineWidth': new WeakMap(),
  10931. 'position': new WeakMap(),
  10932. 'padding': new WeakMap(),
  10933. "cssText": new WeakMap(),
  10934. "right": new WeakMap(),
  10935. "left": new WeakMap(),
  10936. "top": new WeakMap(),
  10937. "bottom": new WeakMap(),
  10938. "transitionDelay": new WeakMap(),
  10939. "marginLeft": new WeakMap(),
  10940. "marginTop": new WeakMap(),
  10941. "marginRight": new WeakMap(),
  10942. "marginBottom": new WeakMap(),
  10943. }
  10944.  
  10945. const ns5 = Symbol();
  10946. const nextModify = (a, c, m, f, immediate) => {
  10947. const a_ = a;
  10948. const m_ = m;
  10949. const noKey = !m_.has(a_);
  10950. if (immediate || noKey) {
  10951. m_.set(a_, ns5);
  10952. f(a_, c);
  10953. noKey && nextBrowserTick_(() => {
  10954. const d = m_.get(a_);
  10955. if (d === undefined) return;
  10956. m_.delete(a_);
  10957. if (d !== ns5) f(a_, d);
  10958. });
  10959. } else {
  10960. m_.set(a_, c);
  10961. }
  10962. };
  10963.  
  10964. const set66 = new Set();
  10965. const log77 = new Map();
  10966. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10967.  
  10968. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10969.  
  10970. // console.log(140000, a, b, c);
  10971. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10972. const num = c;
  10973. c = `${num}`;
  10974. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10975. }
  10976.  
  10977. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10978.  
  10979. let elmPropTemp = null;
  10980.  
  10981. if (b === "transform") {
  10982. // div.ytp-hover-progress.ytp-hover-progress-light
  10983. // div.ytp-play-progress.ytp-swatch-background-color
  10984.  
  10985. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10986. return;
  10987.  
  10988. } else if (elmPropTemp = elmPropTemps[b]) {
  10989.  
  10990. // if (c.length > 5 && c.includes('.')) {
  10991. // console.log(123213, c)
  10992. // }
  10993.  
  10994. const b_ = b;
  10995. nextModify(a, c, elmPropTemp, (a, c) => {
  10996. const style = a.style;
  10997. const cv = style[b_];
  10998. if (!cv && !c) return;
  10999. if (cv === c) return;
  11000. style[b_] = c;
  11001. }, immediateChange);
  11002. return;
  11003.  
  11004. } else if (b === "outline-width") {
  11005.  
  11006. const b_ = 'outlineWidth';
  11007. elmPropTemp = elmPropTemps[b_];
  11008. nextModify(a, c, elmPropTemp, (a, c) => {
  11009. const style = a.style;
  11010. const cv = style[b_];
  11011. if (!cv && !c) return;
  11012. if (cv === c) return;
  11013. style[b_] = c;
  11014. }, immediateChange);
  11015. return;
  11016.  
  11017. } else if (b === 'maxWidth' || b === 'maxHeight') {
  11018. // I think these can be directly assigned.
  11019.  
  11020. const b_ = b;
  11021. const style = a.style;
  11022. const cv = style[b_];
  11023. if (!cv && !c) return;
  11024. if (cv === c) return;
  11025. style[b_] = c;
  11026. return;
  11027.  
  11028. } else {
  11029. // if(immediate && elmPropTemps[b]){
  11030. // console.log(5191, b)
  11031. // }
  11032. // caption-window
  11033. // margin-left max-height max-width font-family fill color font-size background white-space margin
  11034. // text-align background-color
  11035. // console.log(27304, a, b, c)
  11036. if (!set66.has(b)) {
  11037. set66.add(b);
  11038. nextBrowserTick_(() => {
  11039. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  11040. console.log(27304, a, b, c)
  11041. }
  11042. })
  11043. }
  11044. }
  11045.  
  11046. attrUpdateFn.call(this, a, b, c);
  11047. return;
  11048. } else if (typeof (b || 0) === 'object') {
  11049.  
  11050. // this is to fix caption positioning
  11051. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  11052. const immediate = (a.id || 0).length > 14;
  11053. for (const [k, v] of Object.entries(b)) {
  11054. modifiedFn.call(this, a, k, v, immediate);
  11055. }
  11056.  
  11057. } else {
  11058.  
  11059. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  11060. // ytp-ad-timed-pie-countdown-inner
  11061.  
  11062. if (typeof b === 'string') {
  11063.  
  11064. let m = log77.get(b);
  11065. if (!m) {
  11066. m = [];
  11067. console.log('attrUpdateFn.debug.27304', m);
  11068. log77.set(b, m);
  11069. }
  11070. m.push([a, b, c]);
  11071.  
  11072. } else {
  11073. console.log('attrUpdateFn.debug.27306', a, b, c);
  11074. }
  11075.  
  11076. attrUpdateFn.call(this, a, b, c);
  11077. return;
  11078. }
  11079.  
  11080. // console.log(130000, a, b, c);
  11081.  
  11082. };
  11083. g[k] = modifiedFn;
  11084.  
  11085.  
  11086. /*
  11087.  
  11088. g.zo = function(a, b, c) {
  11089. if ("string" === typeof b)
  11090. (b = yo(a, b)) && (a.style[b] = c);
  11091. else
  11092. for (var d in b) {
  11093. c = a;
  11094. var e = b[d]
  11095. , f = yo(c, d);
  11096. f && (c.style[f] = e)
  11097. }
  11098. }
  11099.  
  11100.  
  11101. */
  11102.  
  11103.  
  11104. }
  11105. }
  11106.  
  11107. if (fOption & 4) {
  11108. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  11109.  
  11110. if (keyuG) {
  11111.  
  11112. k = keyuG;
  11113.  
  11114. const gk = g[k];
  11115. const gkp = gk.prototype;
  11116.  
  11117.  
  11118. /** @type { Map<string, WeakMap<any, any>> } */
  11119. const ntLogs = new Map();
  11120.  
  11121. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  11122.  
  11123. gkp.updateValue31 = gkp.updateValue;
  11124. gkp.updateValue = function (a, b) {
  11125. if (typeof a !== 'string') return this.updateValue31(a, b);
  11126.  
  11127. const element = this.element;
  11128. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  11129.  
  11130. let ntLog = ntLogs.get(a);
  11131. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  11132.  
  11133. let cache = ntLog.get(element);
  11134. if (cache && cache.value === b) {
  11135. return;
  11136. }
  11137. if (!cache) {
  11138. this.__oldValueByUpdateValue__ = null;
  11139. ntLog.set(element, cache = { value: b });
  11140. } else {
  11141. this.__oldValueByUpdateValue__ = cache.value;
  11142. cache.value = b;
  11143. }
  11144.  
  11145. return this.updateValue31(a, b);
  11146. }
  11147.  
  11148. /*
  11149. g.k.update = function(a) {
  11150. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  11151. c = c.value,
  11152. this.updateValue(c, a[c])
  11153. }
  11154. ;
  11155. g.k.updateValue = function(a, b) {
  11156. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  11157. }
  11158. */
  11159.  
  11160. }
  11161.  
  11162.  
  11163. }
  11164. }
  11165.  
  11166.  
  11167.  
  11168. })();
  11169.  
  11170.  
  11171. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  11172. // keyboard shortcut keys controller
  11173.  
  11174. const _yt_player = await _yt_player_observable.obtain();
  11175.  
  11176. if (!_yt_player || typeof _yt_player !== 'object') return;
  11177.  
  11178. keyboardController(_yt_player);
  11179.  
  11180. })();
  11181.  
  11182. FIX_yt_player && !isChatRoomURL && (async () => {
  11183. // timer scheduling
  11184.  
  11185. const _yt_player = await _yt_player_observable.obtain();
  11186.  
  11187. if (!_yt_player || typeof _yt_player !== 'object') return;
  11188.  
  11189. let keyZqQu = getZqQu(_yt_player);
  11190.  
  11191. if (!keyZqQu) return;
  11192.  
  11193. const g = _yt_player
  11194. let k = keyZqQu
  11195.  
  11196. const gk = g[k];
  11197. if (typeof gk !== 'function') return;
  11198. const gkp = gk.prototype;
  11199.  
  11200. const extractKeysZqQu = () => {
  11201.  
  11202.  
  11203. let _keyeC = '';
  11204. try {
  11205. gkp.stop.call(new Proxy({
  11206. isActive: () => { }
  11207. }, {
  11208. set(target, prop, value) {
  11209. if (value === 0) _keyeC = prop;
  11210. return true;
  11211. }
  11212. }));
  11213. } catch (e) { }
  11214. if (!_keyeC) return;
  11215. const keyeC = _keyeC;
  11216.  
  11217. let keyC = ''; // this.C = this.ST.bind(this)
  11218. let keyhj = ''; // 1000ms
  11219. try {
  11220. gkp.start.call(new Proxy({
  11221. stop: () => { },
  11222. [keyeC]: 0,
  11223. }, {
  11224. get(target, prop) {
  11225. if (prop in target) return target[prop];
  11226. if (!keyC) {
  11227. keyC = prop;
  11228. return null; // throw error
  11229. }
  11230. else if (!keyhj) {
  11231. keyhj = prop;
  11232. }
  11233.  
  11234. }
  11235. }));
  11236. } catch (e) {
  11237. if (!keyC || !keyhj) {
  11238. console.log(e)
  11239. }
  11240. }
  11241.  
  11242. if (!keyC || !keyhj) return;
  11243. let keyST = '';
  11244. let keyj = '';
  11245. let keyB = '';
  11246. let keyxa = '';
  11247.  
  11248. const possibleKs = new Set();
  11249.  
  11250. for (const [k, v] of Object.entries(gkp)) {
  11251. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  11252. continue;
  11253. }
  11254. if (typeof v === 'function') {
  11255. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  11256. if (m) {
  11257. keyST = k;
  11258. keyj = m[1];
  11259. keyB = m[2];
  11260. } else {
  11261. possibleKs.add(k);
  11262. }
  11263. }
  11264. }
  11265.  
  11266. if (!keyST || !keyj || !keyB) return;
  11267.  
  11268. for (const k of possibleKs) {
  11269. if (k === keyST || k === keyj || k === keyB) {
  11270. continue;
  11271. }
  11272. const v = gkp[k];
  11273. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  11274. keyxa = k;
  11275. }
  11276. }
  11277.  
  11278. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  11279.  
  11280. }
  11281.  
  11282. const keys = extractKeysZqQu();
  11283. if (!keys || !keys.length) return;
  11284. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  11285.  
  11286. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  11287.  
  11288. let disposeKeys = null;
  11289.  
  11290. gkp[keyxa] = function () {
  11291. // dispose
  11292. if (!disposeKeys) {
  11293. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  11294. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  11295. const t = typeof this[key];
  11296. return t === 'undefined' || t === 'object'
  11297. }
  11298. return false;
  11299. });
  11300. }
  11301. for (const key of disposeKeys) {
  11302. const v = this[key];
  11303. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  11304. }
  11305. if (this[keyeC] > 0) this.stop();
  11306. this[keyj] = null;
  11307. this[keyB] = null;
  11308. };
  11309.  
  11310. gkp.start = function (a) {
  11311. if (this[keyeC] > 0) this.stop();
  11312. const delay = void 0 !== a ? a : this[keyhj];
  11313. this[keyeC] = window.setTimeout(this[keyC], delay);
  11314. };
  11315. gkp.stop = function () {
  11316. if (this[keyeC] > 0) {
  11317. window.clearTimeout(this[keyeC]);
  11318. this[keyeC] = 0;
  11319. }
  11320. };
  11321.  
  11322. gkp.isActive = function () {
  11323. return this[keyeC] > 0;
  11324. };
  11325.  
  11326. gkp[keyST] = function () {
  11327. this.stop(); // this[keyeC] = 0;
  11328. const fn = this[keyj];
  11329. const obj = this[keyB];
  11330. let skip = false;
  11331. if (!fn) skip = true;
  11332. else if (IGNORE_bufferhealth_CHECK && obj) {
  11333. let m;
  11334. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  11335. if (m.has("bufferhealth")) skip = true;
  11336. }
  11337. }
  11338. if (!skip) {
  11339. fn.call(obj);
  11340. }
  11341. };
  11342.  
  11343.  
  11344.  
  11345.  
  11346. /*
  11347.  
  11348. g.k.eC = 0;
  11349. g.k.xa = function() {
  11350. g.Qu.Vf.xa.call(this);
  11351. this.stop();
  11352. delete this.j;
  11353. delete this.B
  11354. }
  11355. ;
  11356. g.k.start = function(a) {
  11357. this.stop();
  11358. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  11359. }
  11360. ;
  11361. g.k.stop = function() {
  11362. this.isActive() && g.Sa.clearTimeout(this.eC);
  11363. this.eC = 0
  11364. }
  11365. ;
  11366. g.k.isActive = function() {
  11367. return 0 != this.eC
  11368. }
  11369. ;
  11370. g.k.ST = function() {
  11371. this.eC = 0;
  11372. this.j && this.j.call(this.B)
  11373. }
  11374. ;
  11375. */
  11376.  
  11377.  
  11378.  
  11379.  
  11380. })();
  11381.  
  11382. FIX_Animation_n_timeline && (async () => {
  11383.  
  11384. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  11385.  
  11386. if (!timeline || !Animation) return;
  11387.  
  11388. const animationsFix = (timeline) => {
  11389. const animations = (timeline || 0)._animations || 0;
  11390. const c = animations[0];
  11391. if (c) {
  11392. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  11393. animations.shift(); // keep animating but no looping
  11394. // c.effect.remove();
  11395. }
  11396. }
  11397. }
  11398.  
  11399. const aniProto = Animation.prototype;
  11400. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  11401.  
  11402. const getXroto = (x) => {
  11403. try {
  11404. return x.__proto__;
  11405. } catch (e) { }
  11406. return null;
  11407. }
  11408. const timProto = getXroto(timeline);
  11409. if (!timProto) return;
  11410. if (
  11411. (
  11412. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  11413. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  11414. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  11415. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  11416. )
  11417.  
  11418. ) {
  11419.  
  11420. timProto.nofCQ = 1;
  11421. aniProto.nofYH = 1;
  11422.  
  11423. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  11424.  
  11425.  
  11426. /*
  11427. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11428. return c._updatePromises();
  11429. });
  11430. */
  11431.  
  11432. const p = Array.prototype.filter;
  11433.  
  11434. let res = null;
  11435. Array.prototype.filter = function () {
  11436.  
  11437. res = this;
  11438. return this;
  11439.  
  11440. };
  11441.  
  11442. _updateAnimationsPromises.call({});
  11443.  
  11444. Array.prototype.filter = p;
  11445.  
  11446. if (res && typeof res.length === 'number') {
  11447. /** @type {any[]} */
  11448. const _res = res;
  11449. return _res;
  11450. }
  11451.  
  11452.  
  11453. return null;
  11454.  
  11455.  
  11456.  
  11457.  
  11458. })(timProto._updateAnimationsPromises);
  11459.  
  11460. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  11461.  
  11462. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  11463.  
  11464. aniProto._updatePromises31 = aniProto._updatePromises;
  11465.  
  11466. /*
  11467. aniProto._updatePromises = function(){
  11468. console.log('eff',this._oldPlayState, this.playState)
  11469. return this._updatePromises31.apply(this, arguments)
  11470. }
  11471. */
  11472.  
  11473. aniProto._updatePromises = function () {
  11474. var oldPlayState = this._oldPlayState;
  11475. var newPlayState = this.playState;
  11476. // console.log('ett', oldPlayState, newPlayState)
  11477. if (newPlayState !== oldPlayState) {
  11478. this._oldPlayState = newPlayState;
  11479. if (this._readyPromise) {
  11480. if ("idle" == newPlayState) {
  11481. this._rejectReadyPromise();
  11482. this._readyPromise = void 0;
  11483. } else if ("pending" == oldPlayState) {
  11484. this._resolveReadyPromise();
  11485. } else if ("pending" == newPlayState) {
  11486. this._readyPromise = void 0;
  11487. }
  11488. }
  11489. if (this._finishedPromise) {
  11490. if ("idle" == newPlayState) {
  11491. this._rejectFinishedPromise();
  11492. this._finishedPromise = void 0;
  11493. } else if ("finished" == newPlayState) {
  11494. this._resolveFinishedPromise();
  11495. } else if ("finished" == oldPlayState) {
  11496. this._finishedPromise = void 0;
  11497. }
  11498. }
  11499. }
  11500. return this._readyPromise || this._finishedPromise;
  11501. };
  11502.  
  11503.  
  11504. let restartWebAnimationsNextTickFlag = false;
  11505.  
  11506. const looperMethodT = () => {
  11507.  
  11508. const runnerFn = (hRes) => {
  11509. var b = timeline;
  11510. b.currentTime = hRes;
  11511. b._discardAnimations();
  11512. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11513. if (0 == b._animations.length) {
  11514. restartWebAnimationsNextTickFlag = false;
  11515. } else {
  11516. getRafPromise().then(runnerFn);
  11517. }
  11518. }
  11519.  
  11520. const restartWebAnimationsNextTick = () => {
  11521. if (!restartWebAnimationsNextTickFlag) {
  11522. restartWebAnimationsNextTickFlag = true;
  11523. getRafPromise().then(runnerFn);
  11524. }
  11525. }
  11526.  
  11527. return { restartWebAnimationsNextTick }
  11528. };
  11529.  
  11530.  
  11531. const looperMethodN = () => {
  11532.  
  11533. const acs = document.createElement('a-f');
  11534. acs.id = 'a-f';
  11535.  
  11536. if (!document.getElementById('afscript')) {
  11537. const style = document.createElement('style');
  11538. style.id = 'afscript';
  11539. style.textContent = `
  11540. @keyFrames aF1 {
  11541. 0% {
  11542. order: 0;
  11543. }
  11544. 100% {
  11545. order: 1;
  11546. }
  11547. }
  11548. #a-f[id] {
  11549. visibility: collapse !important;
  11550. position: fixed !important;
  11551. display: block !important;
  11552. top: -100px !important;
  11553. left: -100px !important;
  11554. margin:0 !important;
  11555. padding:0 !important;
  11556. outline:0 !important;
  11557. border:0 !important;
  11558. z-index:-1 !important;
  11559. width: 0px !important;
  11560. height: 0px !important;
  11561. contain: strict !important;
  11562. pointer-events: none !important;
  11563. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  11564. }
  11565. `;
  11566. (document.head || document.documentElement).appendChild(style);
  11567. }
  11568.  
  11569. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  11570.  
  11571. const _onanimationiteration = function (evt) {
  11572. const hRes = evt.timeStamp;
  11573. var b = timeline;
  11574. b.currentTime = hRes;
  11575. b._discardAnimations();
  11576. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11577. if (0 == b._animations.length) {
  11578. restartWebAnimationsNextTickFlag = false;
  11579. acs.onanimationiteration = null;
  11580. } else {
  11581. acs.onanimationiteration = _onanimationiteration;
  11582. }
  11583.  
  11584. }
  11585.  
  11586.  
  11587.  
  11588. const restartWebAnimationsNextTick = () => {
  11589. if (!restartWebAnimationsNextTickFlag) {
  11590. restartWebAnimationsNextTickFlag = true;
  11591. acs.onanimationiteration = _onanimationiteration;
  11592.  
  11593. }
  11594. }
  11595.  
  11596. return { restartWebAnimationsNextTick }
  11597. };
  11598.  
  11599.  
  11600.  
  11601. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  11602.  
  11603.  
  11604. // console.log(571, timProto);
  11605. timProto._play = function (c) {
  11606. c = new Animation(c, this);
  11607. this._animations.push(c);
  11608. restartWebAnimationsNextTick();
  11609. c._updatePromises();
  11610. c._animation.play();
  11611. c._updatePromises();
  11612. return c
  11613. }
  11614.  
  11615. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  11616. originalAnimationsWithPromises.length = 0;
  11617. originalAnimationsWithPromises.push = null;
  11618. originalAnimationsWithPromises.splice = null;
  11619. originalAnimationsWithPromises.slice = null;
  11620. originalAnimationsWithPromises.indexOf = null;
  11621. originalAnimationsWithPromises.unshift = null;
  11622. originalAnimationsWithPromises.shift = null;
  11623. originalAnimationsWithPromises.pop = null;
  11624. originalAnimationsWithPromises.filter = null;
  11625. originalAnimationsWithPromises.forEach = null;
  11626. originalAnimationsWithPromises.map = null;
  11627.  
  11628.  
  11629. const _updateAnimationsPromises = () => {
  11630. animationsWithPromisesMap.forEach(c => {
  11631. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  11632. });
  11633. /*
  11634. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11635. return c._updatePromises();
  11636. });
  11637. */
  11638. }
  11639.  
  11640. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  11641.  
  11642. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  11643.  
  11644. delete timProto._updateAnimationsPromises;
  11645. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  11646. get() {
  11647. if (animationsWithPromisesMap.size === 0) return nilFn;
  11648. return _updateAnimationsPromises;
  11649. },
  11650. set(nv) {
  11651. delete this._updateAnimationsPromises;
  11652. this._updateAnimationsPromises = nv;
  11653. },
  11654. enumerable: true,
  11655. configurable: true,
  11656. });
  11657.  
  11658.  
  11659. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  11660. aniProto.__finished_native_get__ = pdFinished.get;
  11661. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  11662.  
  11663.  
  11664. Object.defineProperty(aniProto, 'finished', {
  11665. get() {
  11666. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11667. this._finishedPromise = new Promise((resolve, reject) => {
  11668. this._resolveFinishedPromise = function () {
  11669. resolve(this)
  11670. };
  11671. this._rejectFinishedPromise = function () {
  11672. reject({
  11673. type: DOMException.ABORT_ERR,
  11674. name: "AbortError"
  11675. })
  11676. };
  11677. }),
  11678. "finished" == this.playState && this._resolveFinishedPromise());
  11679. return this._finishedPromise
  11680. },
  11681. set: undefined,
  11682. enumerable: true,
  11683. configurable: true
  11684. });
  11685.  
  11686. }
  11687.  
  11688.  
  11689.  
  11690. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  11691. aniProto.__ready_native_get__ = pdReady.get;
  11692. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  11693.  
  11694. Object.defineProperty(aniProto, 'ready', {
  11695. get() {
  11696. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11697. this._readyPromise = new Promise((resolve, reject) => {
  11698. this._resolveReadyPromise = function () {
  11699. resolve(this)
  11700. };
  11701. this._rejectReadyPromise = function () {
  11702. reject({
  11703. type: DOMException.ABORT_ERR,
  11704. name: "AbortError"
  11705. })
  11706. };
  11707. }),
  11708. "pending" !== this.playState && this._resolveReadyPromise());
  11709. return this._readyPromise
  11710. },
  11711. set: undefined,
  11712. enumerable: true,
  11713. configurable: true
  11714. });
  11715.  
  11716. }
  11717.  
  11718.  
  11719. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  11720.  
  11721. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  11722. const _rebuildUnderlyingAnimation = function () {
  11723. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  11724. this.effect && this.effect._onsample && (this.effect._onsample = null);
  11725. return this._rebuildUnderlyingAnimation21();
  11726. }
  11727. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  11728. // delete aniProto._rebuildUnderlyingAnimation;
  11729. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  11730. // get() {
  11731. // if (isNaN(this._sequenceNumber)) return nilFn;
  11732. // return this._rebuildUnderlyingAnimation21;
  11733. // },
  11734. // set(nv) {
  11735. // delete this._rebuildUnderlyingAnimation;
  11736. // this._rebuildUnderlyingAnimation = nv;
  11737. // },
  11738. // enumerable: true,
  11739. // configurable: true
  11740. // });
  11741. }
  11742.  
  11743.  
  11744. /*
  11745.  
  11746.  
  11747. function f(c) {
  11748. var b = v.timeline;
  11749. b.currentTime = c;
  11750. b._discardAnimations();
  11751. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  11752. }
  11753. var h = window.requestAnimationFrame;
  11754. window.requestAnimationFrame = function(c) {
  11755. return h(function(b) {
  11756. v.timeline._updateAnimationsPromises();
  11757. c(b);
  11758. v.timeline._updateAnimationsPromises()
  11759. })
  11760. }
  11761. ;
  11762. v.AnimationTimeline = function() {
  11763. this._animations = [];
  11764. this.currentTime = void 0
  11765. }
  11766. ;
  11767. v.AnimationTimeline.prototype = {
  11768. getAnimations: function() {
  11769. this._discardAnimations();
  11770. return this._animations.slice()
  11771. },
  11772. _updateAnimationsPromises: function() {
  11773. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  11774. return c._updatePromises()
  11775. })
  11776. },
  11777. _discardAnimations: function() {
  11778. this._updateAnimationsPromises();
  11779. this._animations = this._animations.filter(function(c) {
  11780. return "finished" != c.playState && "idle" != c.playState
  11781. })
  11782. },
  11783. _play: function(c) {
  11784. c = new v.Animation(c,this);
  11785. this._animations.push(c);
  11786. v.restartWebAnimationsNextTick();
  11787. c._updatePromises();
  11788. c._animation.play();
  11789. c._updatePromises();
  11790. return c
  11791. },
  11792. play: function(c) {
  11793. c && c.remove();
  11794. return this._play(c)
  11795. }
  11796. };
  11797. var d = !1;
  11798. v.restartWebAnimationsNextTick = function() {
  11799. d || (d = !0,
  11800. requestAnimationFrame(f))
  11801. }
  11802. ;
  11803. var a = new v.AnimationTimeline;
  11804. v.timeline = a;
  11805. try {
  11806. Object.defineProperty(window.document, "timeline", {
  11807. configurable: !0,
  11808. get: function() {
  11809. return a
  11810. }
  11811. })
  11812. } catch (c) {}
  11813. try {
  11814. window.document.timeline = a
  11815. } catch (c) {}
  11816.  
  11817. */
  11818.  
  11819.  
  11820.  
  11821. /*
  11822.  
  11823. var g = window.getComputedStyle;
  11824. Object.defineProperty(window, "getComputedStyle", {
  11825. configurable: !0,
  11826. enumerable: !0,
  11827. value: function() {
  11828. v.timeline._updateAnimationsPromises();
  11829. var e = g.apply(this, arguments);
  11830. h() && (e = g.apply(this, arguments));
  11831. v.timeline._updateAnimationsPromises();
  11832. return e
  11833. }
  11834. });
  11835.  
  11836. */
  11837.  
  11838.  
  11839.  
  11840.  
  11841. }
  11842.  
  11843.  
  11844.  
  11845.  
  11846. })();
  11847.  
  11848. !isUrlInEmbed && Promise.resolve().then(() => {
  11849.  
  11850. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11851.  
  11852.  
  11853.  
  11854. class LimitedSizeSet extends Set {
  11855. constructor(n) {
  11856. super();
  11857. this.limit = n;
  11858. }
  11859.  
  11860. add(key) {
  11861. if (!super.has(key)) {
  11862. super.add(key);
  11863. let n = super.size - this.limit;
  11864. if (n > 0) {
  11865. const iterator = super.values();
  11866. do {
  11867. const firstKey = iterator.next().value; // Get the first (oldest) key
  11868. super.delete(firstKey); // Delete the oldest key
  11869. } while (--n > 0)
  11870. }
  11871. }
  11872. }
  11873.  
  11874. removeAdd(key) {
  11875. super.delete(key);
  11876. this.add(key);
  11877. }
  11878.  
  11879. }
  11880.  
  11881. // const wk3 = new WeakMap();
  11882.  
  11883. // let mtxVideoId = '';
  11884. // let aje3 = [];
  11885. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11886. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11887. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11888. let mtzCount = 0; // the key keeps unchanged
  11889. // let mjtNextMainKey = '';
  11890. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11891. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11892. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11893. // let allowNoDelay322=false;
  11894. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11895.  
  11896. let mpKey22 = ''; // last success continutation key & url pair
  11897. let mpUrl22 = ''; // last success continutation key & url pair
  11898. let mpKey21 = ''; // latest requested continutation key & url pair
  11899. let mpUrl21 = ''; // latest requested continutation key & url pair
  11900.  
  11901.  
  11902. async function sha1Hex(message) {
  11903. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11904. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11905. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11906. const hashHex = hashArray
  11907. .map((b) => b.toString(16).padStart(2, "0"))
  11908. .join(""); // convert bytes to hex string
  11909. return hashHex;
  11910. }
  11911.  
  11912. async function continuationLog(a, ...args) {
  11913. let b = a;
  11914. try {
  11915. if (advanceLogging) b = await sha1Hex(a);
  11916. let c = args.map(e => {
  11917. return e === a ? b : e
  11918. });
  11919. console.log(...c)
  11920. } catch (e) { console.warn(e) }
  11921. }
  11922.  
  11923. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11924.  
  11925.  
  11926. if (mfvContinuationRecorded.length > 0) {
  11927. for (const [e, d] of mfvContinuationRecorded) {
  11928. mfyContinuationIgnored.removeAdd(e);
  11929. }
  11930. toClearRecorded && mfvContinuationRecorded.clear();
  11931. }
  11932.  
  11933. }
  11934.  
  11935. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11936.  
  11937. const tmProto = taskMgr.constructor.prototype;
  11938. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11939.  
  11940. if (!tmProto.addJob714) {
  11941.  
  11942. tmProto.addJob714 = tmProto.addJob;
  11943.  
  11944. tmProto.addJob = function (a, b, c) {
  11945. const jobId = this.addJob714(a, b, c);
  11946. if (jobId > 0) {
  11947. // const ez = wk3.get(this);
  11948. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11949. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11950.  
  11951. this.__lastJobId863__ = jobId;
  11952. }
  11953. return jobId;
  11954. }
  11955.  
  11956. }
  11957.  
  11958. if (!tmProto.cancelJob714) {
  11959.  
  11960. tmProto.cancelJob714 = tmProto.cancelJob;
  11961.  
  11962. tmProto.cancelJob = function (a) {
  11963. const res = this.cancelJob714(a);
  11964. // if (a > 0) {
  11965. // for (const e of aje3) {
  11966. // if (e.jobId === a) e.cancelled = true;
  11967. // }
  11968. // }
  11969. return res;
  11970. }
  11971.  
  11972. }
  11973.  
  11974. }
  11975. }
  11976.  
  11977.  
  11978. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11979.  
  11980.  
  11981. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11982. let dummy;
  11983. let cProto;
  11984. // let mc = 4;
  11985. // dummy = await observablePromise(() => {
  11986. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11987. // if (!r) return;
  11988. // let cProto = insp(r).constructor.prototype;
  11989. // if (cProto.fetchUpdatedMetadata) return r;
  11990. // if (--mc < 0) return -1;
  11991. // return null;
  11992. // }).obtain();
  11993. dummy = document.createElement('ytd-video-primary-info-renderer');
  11994. if (!(dummy instanceof Element)) return;
  11995. // console.log(5022, dummy)
  11996. cProto = insp(dummy).constructor.prototype;
  11997.  
  11998. cProto.__getEmittorTaskMgr859__ = function () {
  11999. let taskMgr_ = null;
  12000. try {
  12001. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  12002. } catch (e) { }
  12003. return taskMgr_;
  12004. }
  12005. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  12006. // console.log(1234, cProto, cProto.is)
  12007. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  12008.  
  12009. let c_;
  12010. cProto.fetchUpdatedMetadata718 = function (a) {
  12011. // delay or immediate call the actual fetchUpdatedMetadata
  12012.  
  12013. let doImmediately = false;
  12014. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  12015.  
  12016. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  12017.  
  12018. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  12019.  
  12020. doImmediately = true;
  12021.  
  12022. }
  12023.  
  12024. if (mbCId322) {
  12025. clearTimeout(mbCId322);
  12026. mbCId322 = 0;
  12027. }
  12028.  
  12029. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  12030.  
  12031. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  12032.  
  12033. mbCId322 = setTimeout(() => {
  12034. this.fetchUpdatedMetadata717(a);
  12035. }, delay);
  12036.  
  12037. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  12038.  
  12039. }
  12040.  
  12041. cProto.fetchUpdatedMetadata = function (a) {
  12042.  
  12043. if (!pageSetupState) {
  12044. if (c_) clearTimeout(c_);
  12045. c_ = setTimeout(() => {
  12046. this.fetchUpdatedMetadata718(a);
  12047. }, 300);
  12048. return;
  12049. }
  12050.  
  12051. // pageSetupState == 0
  12052.  
  12053. try {
  12054.  
  12055. mbDelayBelowNCalls++;
  12056.  
  12057. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  12058. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  12059. }
  12060.  
  12061. // console.log('fum377', a)
  12062. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  12063. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  12064. return;
  12065. }
  12066.  
  12067. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  12068. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  12069. mjtLockPreviousKey = mjtRecordedPrevKey;
  12070. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  12071. }
  12072. // mjtNextMainKey = true;
  12073. mtzlastAllowedContinuation = '';
  12074. mtzCount = 0;
  12075. // allowNoDelay322 = false;
  12076. // fetch new metadata, cancel all previous continuations
  12077. copyPreviousContiuationToIgnored374(true);
  12078. } else if (typeof a === 'string') {
  12079. const videoPlayingId = videoPlayingY.videoId;
  12080.  
  12081. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  12082.  
  12083. let update21 = !!pageSetupVideoId;
  12084. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  12085. update21 = true;
  12086. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  12087. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  12088. return;
  12089. }
  12090. if (update21) {
  12091. mpKey21 = a;
  12092. mpUrl21 = pageSetupVideoId || videoPlayingId;
  12093. }
  12094.  
  12095. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  12096. }
  12097. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  12098. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  12099. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  12100. return this.fetchUpdatedMetadata718(a);
  12101.  
  12102. } catch (e) {
  12103. console.log('Code Error in fetchUpdatedMetadata', e);
  12104. }
  12105. return this.fetchUpdatedMetadata717(a)
  12106. }
  12107. }
  12108.  
  12109.  
  12110. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  12111. // console.log(1234, cProto, cProto.is)
  12112. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  12113. let mJob = null;
  12114.  
  12115. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  12116.  
  12117. try {
  12118.  
  12119. if (arguments.length > 0) {
  12120. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  12121. }
  12122. // mfy = mfv;
  12123.  
  12124. // mjtNextMainKey = '';
  12125. mtzlastAllowedContinuation = '';
  12126. mtzCount = 0;
  12127. if (mbCId322) {
  12128. clearTimeout(mbCId322);
  12129. mbCId322 = 0;
  12130. }
  12131. mbDelayBelowNCalls = 0;
  12132. // allowNoDelay322 = false;
  12133. copyPreviousContiuationToIgnored374(true);
  12134.  
  12135. const taskMgr = this.__getEmittorTaskMgr859__();
  12136. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  12137. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  12138. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  12139. }
  12140.  
  12141. // prevent depulicated schedule job by clearing previous JobId
  12142. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  12143.  
  12144. let res;
  12145.  
  12146. if (mJob) {
  12147. const job = mJob;
  12148. mJob = null;
  12149. console.log('cancelJob', job)
  12150. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  12151. // p.cancelJob(a,b);
  12152. }
  12153.  
  12154. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  12155.  
  12156. let pza = taskMgr.__lastJobId863__;
  12157. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  12158. let pzb = taskMgr.__lastJobId863__
  12159. if (pza !== pzb) {
  12160. mJob = pzb; // set [Interval Meta Update] jobId
  12161. }
  12162.  
  12163. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  12164. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  12165. // } else {
  12166. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  12167. // }
  12168.  
  12169. return res;
  12170.  
  12171. } else {
  12172. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  12173. }
  12174.  
  12175. } catch (e) {
  12176. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  12177. }
  12178.  
  12179.  
  12180. return this.scheduleInitialUpdatedMetadataRequest717();
  12181. }
  12182. }
  12183.  
  12184.  
  12185. });
  12186.  
  12187. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  12188. let dummy;
  12189. let cProto;
  12190. dummy = ytAppDom;
  12191. if (!(dummy instanceof Element)) return;
  12192. cProto = insp(dummy).constructor.prototype;
  12193. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  12194. // console.log(1234, cProto, cProto.is);
  12195. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  12196. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  12197. // console.log(123401, arguments);
  12198. // return this.handleServiceRequest717_(a, b, c, d);
  12199. // }
  12200.  
  12201. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  12202.  
  12203. // cProto.handleServiceRequest_ = function(a,b,c,d){
  12204. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  12205. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  12206. // console.log('mfv', c.continuation);
  12207. // mfv.add( c.continuation);
  12208. // }
  12209. // return this.handleServiceRequest717_(a,b,c,d);
  12210. // }
  12211.  
  12212. function extraArguments322(a, b, c) {
  12213. let is = (a || 0).is;
  12214. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  12215. let continuation = (c || 0).continuation;
  12216. if (typeof is !== 'string') is = null;
  12217. if (typeof videoId !== 'string') videoId = null;
  12218. if (typeof continuation !== 'string') continuation = null;
  12219. return { is, videoId, continuation };
  12220. }
  12221.  
  12222. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  12223. cProto.sendServiceAjax_ = function (a, b, c, d) {
  12224.  
  12225. // console.log(8001)
  12226. try {
  12227.  
  12228. const { is, videoId, continuation } = extraArguments322(a, b, c);
  12229.  
  12230. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12231. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  12232. }
  12233.  
  12234. if (pageSetupVideoId && videoId && continuation) {
  12235. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12236. mfyContinuationIgnored.removeAdd(continuation);
  12237. mfvContinuationRecorded.delete(continuation);
  12238. return;
  12239. }
  12240. }
  12241.  
  12242. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12243. copyPreviousContiuationToIgnored374(false);
  12244. mfyContinuationIgnored.delete(continuation);
  12245. mfvContinuationRecorded.removeAdd(continuation);
  12246. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12247. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12248. mjtLockPreviousKey = '';
  12249. }
  12250. // if (mjtNextMainKey === continuation) {
  12251. // copyPreviousContiuationToIgnored(false);
  12252. // mfyContinuationIgnored.delete(continuation);
  12253. // mfvContinuationRecorded.add(continuation);
  12254. // }
  12255.  
  12256.  
  12257. if (mfyContinuationIgnored && continuation) {
  12258. if (mfyContinuationIgnored.has(continuation)) {
  12259. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  12260. return;
  12261. }
  12262. }
  12263.  
  12264. // console.log(59902, a?.is, b,c,d)
  12265. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  12266. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  12267. // console.log('mfv377', continuation);
  12268. mfvContinuationRecorded.add(continuation);
  12269. }
  12270.  
  12271. // if (videoId) {
  12272. // if (!pageSetupVideoId) return; // ignore page not ready
  12273. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12274. // if (videoId !== pageSetupVideoId) {
  12275. // return;
  12276. // }
  12277. // }
  12278.  
  12279. } catch (e) {
  12280. console.log('Coding Error in sendServiceAjax_', e)
  12281. }
  12282. // console.log(8002)
  12283. // console.log(123402, arguments);
  12284. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  12285.  
  12286. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  12287. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  12288. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  12289. // get(target, prop, receiver){
  12290. // console.log('xxs99', target.videoId, mtx)
  12291. // if(prop ==='kdkw33') return 1;
  12292. // console.log(3322, prop, target)
  12293. // if(prop === 'initialDelayMs') {
  12294. // throw new Error("ABCC");
  12295. // }
  12296. // return target[prop];
  12297. // },
  12298. // set(target, prop, value, receiver){
  12299.  
  12300. // if(prop ==='kdkw33') return true;
  12301. // target[prop]=value;
  12302. // return true;
  12303. // }
  12304. // });
  12305. // }
  12306. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  12307. return this.sendServiceAjax717_(a, b, c, d);
  12308. }
  12309. }
  12310.  
  12311. function delayClearOtherKeys(lztContinuation) {
  12312. // // schedule delayed removal if mfyContinuationIgnored is not empty
  12313. // getRafPromise().then(() => {
  12314. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  12315. // // foreground page only
  12316.  
  12317. // });
  12318.  
  12319.  
  12320. if (lztContinuation !== mtzlastAllowedContinuation) return;
  12321. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  12322. if (!mfyContinuationIgnored.size) return;
  12323. if (mfyContinuationIgnored.size > 1) {
  12324. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  12325. }
  12326. mfyContinuationIgnored.forEach((value, key) => {
  12327. if (key !== lztContinuation) {
  12328. mfyContinuationIgnored.delete(key);
  12329. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  12330. }
  12331. });
  12332.  
  12333. }
  12334. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  12335. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  12336. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  12337.  
  12338. // console.log(8003)
  12339. try {
  12340.  
  12341.  
  12342. const { is, videoId, continuation } = extraArguments322(b, c, d);
  12343.  
  12344. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12345. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  12346. }
  12347.  
  12348. if (pageSetupVideoId && videoId && continuation) {
  12349. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12350. mfyContinuationIgnored.removeAdd(continuation);
  12351. mfvContinuationRecorded.delete(continuation);
  12352. return;
  12353. }
  12354. }
  12355.  
  12356. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12357. copyPreviousContiuationToIgnored374(false);
  12358. mfyContinuationIgnored.delete(continuation);
  12359. mfvContinuationRecorded.removeAdd(continuation);
  12360. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12361. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12362. mjtLockPreviousKey = '';
  12363. }
  12364.  
  12365. // if (mjtNextMainKey === continuation) {
  12366. // copyPreviousContiuationToIgnored(false);
  12367. // mfyContinuationIgnored.delete(continuation);
  12368. // mfvContinuationRecorded.add(continuation);
  12369. // }
  12370.  
  12371. const lztContinuation = continuation;
  12372.  
  12373. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  12374. if (mfyContinuationIgnored.has(lztContinuation)) {
  12375. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  12376. return;
  12377. }
  12378. }
  12379.  
  12380. // if (videoId) {
  12381. // if (!pageSetupVideoId) return; // ignore page not ready
  12382. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12383. // if (videoId !== pageSetupVideoId) {
  12384. // return;
  12385. // }
  12386. // }
  12387.  
  12388. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  12389. mtzlastAllowedContinuation = lztContinuation;
  12390. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  12391.  
  12392. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12393. mjtRecordedPrevKey = lztContinuation;
  12394. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  12395. // if (mfyContinuationIgnored.size > 0) {
  12396. // delayClearOtherKeys(lztContinuation);
  12397. // }
  12398. mtzCount = 0;
  12399. // allowNoDelay322 = false;
  12400. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  12401. // repeated
  12402. if (++mtzCount > 1e9) mtzCount = 1e4;
  12403. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12404.  
  12405. // if (mtzCount >= 3) allowNoDelay322 = true;
  12406. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  12407. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  12408. }
  12409. if (mtzCount === 5) {
  12410. mfvContinuationRecorded.clear();
  12411. mfvContinuationRecorded.add(lztContinuation);
  12412. }
  12413.  
  12414. }
  12415.  
  12416. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  12417. mpKey22 = lztContinuation;
  12418. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  12419. }
  12420.  
  12421. if (mbCId322) {
  12422. clearTimeout(mbCId322);
  12423. mbCId322 = 0;
  12424. }
  12425. } catch (e) {
  12426. console.log('Coding Error in getCancellableNetworkPromise_', e)
  12427. }
  12428.  
  12429. // console.log(8004)
  12430. // console.log(123403, arguments);
  12431. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  12432.  
  12433. // console.log(5163, a?.is,b,c,d,e);
  12434. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  12435. }
  12436. }
  12437. });
  12438.  
  12439. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  12440.  
  12441.  
  12442. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  12443.  
  12444. let dummy;
  12445. let cProto;
  12446.  
  12447. dummy = document.createElement('ytd-expander');
  12448. cProto = insp(dummy).constructor.prototype;
  12449.  
  12450. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  12451.  
  12452. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  12453. cProto.childrenChanged14 = cProto.childrenChanged;
  12454.  
  12455. cProto.initChildrenObserver = function () {
  12456. var a = this;
  12457. this.observer = new MutationObserver(function () {
  12458. a.childrenChanged()
  12459. }
  12460. );
  12461. this.observer.observe(this.content, {
  12462. subtree: !0,
  12463. childList: !0,
  12464. attributes: !0,
  12465. characterData: !0
  12466. });
  12467. this.childrenChanged()
  12468. }
  12469. ;
  12470. cProto.childrenChanged = function () {
  12471. if (this.alwaysToggleable) {
  12472. this.canToggle = this.alwaysToggleable;
  12473. } else if (!this.canToggleJobId) {
  12474. this.canToggleJobId = 1;
  12475. foregroundPromiseFn().then(() => {
  12476. this.canToggleJobId = 0;
  12477. this.calculateCanCollapse()
  12478. })
  12479. }
  12480. }
  12481.  
  12482. // console.log(cProto.initChildrenObserver)
  12483. console.debug('ytd-expander-fix-childrenChanged');
  12484.  
  12485. }
  12486.  
  12487. });
  12488.  
  12489.  
  12490. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  12491.  
  12492. let dummy;
  12493. let cProto;
  12494. dummy = document.createElement('paper-ripple');
  12495. cProto = insp(dummy).constructor.prototype;
  12496.  
  12497. if (fnIntegrity(cProto.animate, '0.74.5')) {
  12498.  
  12499.  
  12500. cProto.animate34 = cProto.animate;
  12501. cProto.animate = function () {
  12502. if (this._animating) {
  12503. var a;
  12504. const ripples = this.ripples;
  12505. for (a = 0; a < ripples.length; ++a) {
  12506. var b = ripples[a];
  12507. b.draw();
  12508. this.$.background.style.opacity = b.outerOpacity;
  12509. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  12510. }
  12511. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  12512. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  12513. foregroundPromiseFn().then(this._boundAnimate38);
  12514. } else {
  12515. this.onAnimationComplete();
  12516. }
  12517. }
  12518. }
  12519.  
  12520. console.debug('FIX_paper_ripple_animate')
  12521.  
  12522. // console.log(cProto.animate)
  12523.  
  12524. }
  12525.  
  12526. });
  12527.  
  12528. if (FIX_doIdomRender) {
  12529.  
  12530. const xsetTimeout = function (f, d) {
  12531. if (xsetTimeout.m511 === 1 && !d) {
  12532. xsetTimeout.m511 = 2;
  12533. xsetTimeout.m568 = f;
  12534. } else {
  12535. return setTimeout.apply(window, arguments)
  12536. }
  12537.  
  12538. }
  12539.  
  12540. /**
  12541. *
  12542. IGb = function(a) {
  12543. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  12544. c || (a.requestAninmationFrameResolver = new Vi,
  12545. c = a.requestAninmationFrameResolver.promise,
  12546. Da.requestAnimationFrame(function() {
  12547. var d;
  12548. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  12549. a.requestAninmationFrameResolver = null
  12550. }));
  12551. return c
  12552. }
  12553.  
  12554.  
  12555. */
  12556.  
  12557. const xrequestAnimationFrame = function (f) {
  12558. const h = `${f}`;
  12559. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  12560. let t = null;
  12561. xsetTimeout.m511 = 1;
  12562. f();
  12563. if (xsetTimeout.m511 === 2) {
  12564. t = xsetTimeout.m568;
  12565. xsetTimeout.m568 = null;
  12566. }
  12567. xsetTimeout.m511 = 0;
  12568. if (typeof t === 'function') {
  12569. foregroundPromiseFn().then(t);
  12570. }
  12571. } else if (h.includes("requestAninmationFrameResolver")) {
  12572. foregroundPromiseFn().then(f);
  12573. } else {
  12574. return requestAnimationFrame.apply(window, arguments);
  12575. }
  12576. }
  12577.  
  12578. let busy = false;
  12579. const doIdomRender = function () {
  12580.  
  12581. if (!this) return;
  12582. if (busy) {
  12583. return this.doIdomRender13(...arguments);
  12584. }
  12585. busy = true;
  12586. const { requestAnimationFrame, setTimeout } = window;
  12587. window.requestAnimationFrame = xrequestAnimationFrame;
  12588. window.setTimeout = xsetTimeout;
  12589. let r = this.doIdomRender13(...arguments);
  12590. window.requestAnimationFrame = requestAnimationFrame;
  12591. window.setTimeout = setTimeout;
  12592. busy = false;
  12593. return r;
  12594. };
  12595. 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']) {
  12596.  
  12597.  
  12598. whenCEDefined(ytTag).then(() => {
  12599.  
  12600. let dummy;
  12601. let cProto;
  12602. dummy = document.createElement(ytTag);
  12603. cProto = insp(dummy).constructor.prototype;
  12604.  
  12605. cProto.doIdomRender13 = cProto.doIdomRender;
  12606. cProto.doIdomRender = doIdomRender;
  12607.  
  12608. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  12609.  
  12610. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  12611.  
  12612.  
  12613.  
  12614. });
  12615.  
  12616. }
  12617.  
  12618. }
  12619.  
  12620.  
  12621.  
  12622.  
  12623. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  12624.  
  12625. const sMap = new Map();
  12626.  
  12627. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  12628. const ZT = function () {
  12629. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  12630. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  12631. c = b & 15,
  12632. b >>= 4,
  12633. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  12634. return a.join("")
  12635. };
  12636.  
  12637.  
  12638. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  12639.  
  12640. const popupContainer = await observablePromise(() => {
  12641. return popupContainerCollection[0];
  12642. }).obtain();
  12643.  
  12644.  
  12645. let cProto;
  12646. cProto = insp(popupContainer).constructor.prototype;
  12647.  
  12648.  
  12649. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  12650. console.log('FIX_POPUP_UNIQUE_ID NG')
  12651. return;
  12652. }
  12653. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  12654.  
  12655. cProto.handleOpenPopupAction = function (a, b) {
  12656.  
  12657. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  12658.  
  12659. a.__jOdQA__ = true;
  12660.  
  12661. try {
  12662.  
  12663. const h = this.hostElement;
  12664.  
  12665. if (h instanceof HTMLElement_) {
  12666.  
  12667. const map = h.__skme44__ = h.__skme44__ || new Map();
  12668.  
  12669. let mKey = '';
  12670. const wKey = firstObjectKey(a);
  12671. const wObj = wKey ? a[wKey] : null;
  12672. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  12673. const pKey = firstObjectKey(wObj.popup)
  12674. const pObj = pKey ? wObj.popup[pKey] : null;
  12675. let contentKey = '';
  12676. let headerKey = '';
  12677.  
  12678. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  12679. contentKey = firstObjectKey(pObj.content)
  12680. headerKey = firstObjectKey(pObj.header)
  12681. }
  12682. if (contentKey && headerKey) {
  12683.  
  12684. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  12685.  
  12686. if (mKey) {
  12687.  
  12688. if (!wObj.uniqueId) {
  12689. for (let i = 0; i < 8; i++) {
  12690. wObj.uniqueId = ZT();
  12691. if (!sMap.has(wObj.uniqueId)) break;
  12692. }
  12693. }
  12694. const oId = wObj.uniqueId
  12695.  
  12696. let nId_ = map.get(mKey);
  12697. if (!nId_) {
  12698. map.set(mKey, nId_ = oId);
  12699. }
  12700.  
  12701. wObj.uniqueId = nId_ || wObj.uniqueId;
  12702.  
  12703. const nId = wObj.uniqueId
  12704.  
  12705. sMap.set(oId, nId);
  12706. sMap.set(nId, nId);
  12707.  
  12708. wObj.uniqueId = nId;
  12709. pObj.targetId = nId;
  12710. pObj.identifier.tag = nId;
  12711.  
  12712. if (oId !== nId) {
  12713. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  12714. }
  12715.  
  12716. }
  12717.  
  12718. }
  12719. }
  12720.  
  12721. // console.log(12213, mKey, a, b, h)
  12722.  
  12723. }
  12724.  
  12725. } catch (e) {
  12726. console.warn(e)
  12727. }
  12728.  
  12729. try {
  12730.  
  12731. const results = searchNestedObject(a, (x) => {
  12732. if (typeof x === 'string' && x.length === 36) {
  12733. if (/[a-zA-Z\d]{8}-[a-zA-Z\d]{4}-[a-zA-Z\d]{4}-[a-zA-Z\d]{4}-[a-zA-Z\d]{12}/.test(x)) return true;
  12734. }
  12735. return false;
  12736. });
  12737. for (const [obj, key] of results) {
  12738. const oId = obj[key];
  12739. const nId = sMap.get(oId);
  12740. if (nId) obj[key] = nId;
  12741. }
  12742. } catch (e) {
  12743. console.warn(e)
  12744. }
  12745.  
  12746.  
  12747. }
  12748.  
  12749. return this.handleOpenPopupAction3868(...arguments)
  12750. }
  12751.  
  12752. console.log('FIX_POPUP_UNIQUE_ID OK')
  12753.  
  12754.  
  12755. });
  12756.  
  12757.  
  12758. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  12759.  
  12760. let dummy;
  12761. let cProto;
  12762. dummy = document.createElement('yt-formatted-string');
  12763. cProto = insp(dummy).constructor.prototype;
  12764.  
  12765. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  12766. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  12767. return;
  12768. }
  12769.  
  12770. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  12771. cProto.setNodeStyle_ = function (a, b) {
  12772. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  12773. return this.setNodeStyle17_(a, b);
  12774. }
  12775.  
  12776. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  12777. });
  12778.  
  12779. });
  12780.  
  12781. });
  12782.  
  12783.  
  12784.  
  12785.  
  12786. if (isMainWindow) {
  12787.  
  12788. console.groupCollapsed(
  12789. "%cYouTube JS Engine Tamer",
  12790. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  12791. );
  12792.  
  12793.  
  12794.  
  12795. console.log("Script is loaded.");
  12796. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  12797.  
  12798. console.log("This script is experimental and subject to further changes.");
  12799.  
  12800. console.log("This might boost your YouTube performance.");
  12801.  
  12802. console.log("CAUTION: This might break your YouTube.");
  12803.  
  12804.  
  12805. if (prepareLogs.length >= 1) {
  12806. console.log(" =========================================================================== ");
  12807.  
  12808. for (const msg of prepareLogs) {
  12809. console.log(msg)
  12810. }
  12811.  
  12812. console.log(" =========================================================================== ");
  12813. }
  12814.  
  12815. console.groupEnd();
  12816.  
  12817. }
  12818.  
  12819.  
  12820.  
  12821. })();