YouTube JS Engine Tamer

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

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

  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.40.0
  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. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  48.  
  49. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  50. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  51. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  52.  
  53. const FIX_Iframe_NULL_SRC = false;
  54.  
  55. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  56.  
  57. const FIX_ytdExpander_childrenChanged = true;
  58. const FIX_paper_ripple_animate = true;
  59. const FIX_avoid_incorrect_video_meta = false; // omit the incorrect yt-animated-rolling-number // 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  60. const FIX_avoid_incorrect_video_meta_emitterBehavior = false; // 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  61.  
  62. const FIX_doIdomRender = true;
  63.  
  64. const FIX_Shady = true;
  65.  
  66. // [[ 2024.04.24 ]]
  67. const MODIFY_ShadyDOM_OBJ = true;
  68. // << if MODIFY_ShadyDOM_OBJ >>
  69. const WEAKREF_ShadyDOM = true;
  70. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  71. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  72. // << end >>
  73.  
  74. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  75.  
  76. const FIX_ytAction_ = true; // ytd-app
  77. const FIX_onVideoDataChange = false;
  78. // const FIX_onClick = true;
  79. const FIX_onStateChange = true;
  80. const FIX_onLoopRangeChange = true;
  81. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  82. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  83.  
  84. const ENABLE_discreteTasking = false; // removed since 0.20.0
  85. const FIX_stampDomArray_ = true; // v0.30.0
  86. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  87. // const stampDomArray_MemoryFix_Flag001 = false;
  88. const XFlag = true; // root issue tbc
  89. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  90. // 32 required for new stampDomArray
  91. // 128 to be tested
  92.  
  93. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  94. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  95.  
  96. const FIX_Polymer_dom = true;
  97. const FIX_Polymer_AF = true;
  98.  
  99. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  100. const DEBUG_removePrune = false; // true for DEBUG
  101.  
  102. const FIX_XHR_REQUESTING = true;
  103.  
  104. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  105.  
  106. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  107.  
  108. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  109. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  110.  
  111. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  112.  
  113. const FIX_removeChild = true;
  114. const FIX_fix_requestIdleCallback_timing = true;
  115.  
  116. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  117. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  118.  
  119. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  120.  
  121. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  122.  
  123. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  124. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  125. // first tp-yt-paper-dialog: show once the page is loaded.
  126. // second tp-yt-paper-dialog: click "...more"
  127. // third tp-yt-paper-dialog: click "... and 3 more links"
  128. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  129. // currently, uniqueId is preassigned by the network resolveCommand.
  130. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  131. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  132.  
  133. // handleOpenPopupAction -> createCacheKey
  134. // handleClosePopupAction_ -> createCacheKey
  135. // handleGetPopupOpenedAction_ -> createCacheKey
  136. // getAndMaybeCreatePopup_ -> createCacheKey
  137. // closePopup -> createCacheKey
  138.  
  139. // yt-close-popup-command -> handleClosePopupCommand_
  140.  
  141. // ensurePopup_ -> getAndMaybeCreatePopup_
  142.  
  143. // yt-close-popup-action -> handleClosePopupAction_
  144. // closePopup -> handleClosePopupAction_
  145. // handleOpenPopupAction -> handleClosePopupAction_
  146. // handleClosePopupCommand_ -> handleClosePopupAction_
  147. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  148.  
  149. // yt-open-popup-action -> handleOpenPopupAction
  150.  
  151.  
  152. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  153. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  154.  
  155. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  156. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  157. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  158.  
  159. const MEMORY_RELEASE_NF00 = true;
  160. const MEMORY_RELEASE_NF00_SHOW_MESSAGE = false;
  161. const MEMORY_RELEASE_MAP_SET_REMOVE_NODE = true;
  162. const FULLY_REMOVE_ALL_EVENT_LISTENERS = true; // require MEMORY_RELEASE_NF00
  163. // const FIX_MEMORY_RELEASE_RUNEFFECT_TEMPLATE = true; // require MEMORY_RELEASE_NF00
  164. const FIX_TEMPLATE_BINDING = true;
  165. const FIX_TEMPLATE_BINDING_SHOW_MESSAGE = false;
  166.  
  167. const USE_fastDomIf = 2; // fastDomIf is seem to be experimental 0 = no change, 1 = enable, 2 = disable
  168. const ENHANCE_DOMIF_createAndInsertInstance = true; // root does not need to store in the instance
  169. const ENHANCE_DOMIF_TEARDOWN = true; // require MEMORY_RELEASE_NF00
  170.  
  171. const FIX_DOM_IF_DETACH = true;
  172. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  173. const FIX_DOM_IF_TEMPLATE = true;
  174. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  175. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  176. const DEBUG_DBR847 = false;
  177. const DEBUG_xx847 = false;
  178. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  179. const DEBUG_renderDebounceTs = false;
  180.  
  181. const FIX_ICON_RENDER = true;
  182.  
  183. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  184.  
  185. const DISABLE_isLowLatencyLiveStream = false; // TBC
  186.  
  187. const FIX_FlexibleItemSizing = true;
  188. const FIX_ROLLING_NUMBER_UPDATE = true;
  189.  
  190. /*
  191.  
  192. FIX_DOM_IFREPEAT_RenderDebouncerChange
  193.  
  194. avoid Polymer.flush
  195. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  196.  
  197. var Is = function() {
  198. do {
  199. var a = window.ShadyDOM && ShadyDOM.flush();
  200. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  201. var b = NNa()
  202. } while (a || b)
  203. };
  204.  
  205. , NNa = function() {
  206. var a = !!ts.size;
  207. ts.forEach(function(b) {
  208. try {
  209. b.flush()
  210. } catch (c) {
  211. setTimeout(function() {
  212. throw c
  213. })
  214. }
  215. });
  216. return a
  217. };
  218.  
  219. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  220. // this coding logic should be incorrect (mistake).
  221.  
  222. */
  223.  
  224.  
  225.  
  226. // ----------------------------- Shortkey Keyboard Control -----------------------------
  227. // dependency: FIX_yt_player
  228.  
  229. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  230. // [0] no fix - not recommended
  231. // [1] basic fix - just fix the global focus detection variable
  232. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  233. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  234.  
  235. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  236. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  237.  
  238. const PROP_OverReInclusion_AVOID = true;
  239. const PROP_OverReInclusion_DEBUGLOG = false;
  240. const PROP_OverReInclusion_LIST = new Set([
  241. 'hostElement72',
  242. 'parentComponent72',
  243. 'localVisibilityObserver_72',
  244. 'cachedProviderNode_72',
  245. '__template72',
  246. '__templatizeOwner72',
  247. '__templateInfo72',
  248. '__dataHost72',
  249. '__CE_shadowRoot72',
  250. 'elements_72',
  251.  
  252. 'ky36',
  253. 'kz62',
  254. 'm822',
  255.  
  256.  
  257.  
  258. // To be reviewed.
  259.  
  260. // chat messages
  261. 'disabled', 'allowedProps',
  262. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  263.  
  264. 'dimension', 'loadTime', 'pendingPaint',
  265.  
  266. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  267.  
  268. 'respectLangDir', 'noEndpoints',
  269.  
  270.  
  271. 'objectURL',
  272. 'buttonOverrides', 'queuedMessages',
  273. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  274. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  275. 'hoverJobId', 'JSC$14573_touched',
  276.  
  277.  
  278. // tbc
  279. 'toggleable', 'isConnected',
  280. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  281. 'disableDeselectEvent',
  282. 'emojiSize',
  283.  
  284. 'buttonOverride',
  285. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  286.  
  287. // others
  288. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  289. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  290. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  291. // 'dimension', 'loadTime', 'pendingPaint',
  292. // 'disabled', 'allowedProps',
  293.  
  294.  
  295. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  296. // 'actionMap',
  297.  
  298. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  299.  
  300. 'clearTimeout',
  301. 'switchTemplateAtRegistration', 'hasUnmounted',
  302. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  303. 'tangoConfiguration',
  304. 'itemIdToDockDurationMap',
  305. 'actionMap',
  306.  
  307. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  308. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  309. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  310.  
  311. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  312. // 'stopKeyboardEventPropagation', 'emojiSize',
  313. // 'switchTemplateAtRegistration', 'hasUnmounted',
  314. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  315. // 'isReusable', 'tangoConfiguration',
  316. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  317. // */
  318.  
  319. ]);
  320.  
  321.  
  322. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  323.  
  324. // ----------------------------- Shortkey Keyboard Control -----------------------------
  325.  
  326. /*
  327. window.addEventListener('edm',()=>{
  328. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  329. });
  330.  
  331. window.addEventListener('edn',()=>{
  332. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  333. });
  334. window.addEventListener('edr',()=>{
  335. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  336. });
  337. */
  338.  
  339. // only for macOS with Chrome/Firefox 100+
  340. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  341.  
  342. const win = this instanceof Window ? this : window;
  343.  
  344. // Create a unique key for the script and check if it is already running
  345. const hkey_script = 'jswylcojvzts';
  346. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  347. win[hkey_script] = true;
  348.  
  349.  
  350.  
  351. const wk = Symbol();
  352.  
  353. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  354.  
  355. let BY_PASS_KEYBOARD_CONTROL = false;
  356.  
  357.  
  358. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  359. /** @type {(f: ()=>{})=>{}} */
  360. const nextBrowserTick_ = nextBrowserTick;
  361. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  362. console.log('nextBrowserTick is not found.');
  363. return;
  364. }
  365.  
  366. let p59 = 0;
  367.  
  368. const Promise = (async () => { })().constructor;
  369.  
  370. const PromiseExternal = ((resolve_, reject_) => {
  371. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  372. return class PromiseExternal extends Promise {
  373. constructor(cb = h) {
  374. super(cb);
  375. if (cb === h) {
  376. /** @type {(value: any) => void} */
  377. this.resolve = resolve_;
  378. /** @type {(reason?: any) => void} */
  379. this.reject = reject_;
  380. }
  381. }
  382. };
  383. })();
  384.  
  385. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  386. constructor(callback = undefined) {
  387.  
  388. }
  389. register(target, heldValue, unregisterToken = undefined) {
  390.  
  391. }
  392. unregister(unregisterToken) {
  393.  
  394. }
  395. }
  396.  
  397. let ttpHTML = (s) => {
  398. ttpHTML = s => s;
  399. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  400. let s = s => s;
  401. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  402. }
  403. return s;
  404. }
  405.  
  406.  
  407. /** @type { typeof HTMLElement } */
  408. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  409. const nativeAppendE = HTMLElement_.prototype.append;
  410. const nativeRemoveE = HTMLElement_.prototype.remove;
  411. const DocumentFragment_ = DocumentFragment;
  412. const nativeAppendD = DocumentFragment_.prototype.append;
  413. const Node_ = Node;
  414.  
  415. /**
  416. @param {number} x
  417. @param {number} d */
  418. const toFixed2 = (x, d) => {
  419. let t = x.toFixed(d);
  420. let y = `${+t}`;
  421. return y.length > t.length ? t : y;
  422. }
  423.  
  424.  
  425. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  426.  
  427.  
  428. const TRANSLATE_DEBUG = false;
  429.  
  430.  
  431. let xdeadc00 = null; // a deteched node with __domApi
  432. let xlivec00 = null; // a deteched node with __domApi
  433.  
  434. let removeTNodeRM = null;
  435. let removeTNodeBP = false;
  436.  
  437.  
  438. if (Node.isConnectedOverrided === undefined) {
  439. const pdConnected = Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected');
  440. if (pdConnected && pdConnected.get && pdConnected.configurable) {
  441. Node.isConnectedOverrided = null;
  442. const get_ = pdConnected.get;
  443. const get = function () {
  444. const overrided = Node.isConnectedOverrided;
  445. if (typeof overrided === 'boolean') return overrided;
  446. return get_.call(this);
  447. }
  448. Object.defineProperty(Node.prototype, 'isConnected', {
  449. ...pdConnected,
  450. get
  451. });
  452. }
  453. }
  454.  
  455. const _nmSet = new Set();
  456. _nmSet.add = _nmSet.addOriginal || _nmSet.add;
  457. const _nmMap = new Set();
  458. _nmMap.add = _nmMap.addOriginal || _nmMap.add;
  459. const _nmMapV = new Set();
  460. _nmMapV.add = _nmMapV.addOriginal || _nmMapV.add;
  461. if (MEMORY_RELEASE_MAP_SET_REMOVE_NODE && !Set.prototype.addOriginal && !Map.prototype.setOriginal) {
  462. const Node_ = Node;
  463. Set.prototype.addOriginal = Set.prototype.add;
  464. Set.prototype.add = function (n) {
  465. if (n instanceof Node_) {
  466. if (!this[wk]) this[wk] = mWeakRef(this);
  467. _nmSet.add(this[wk]);
  468. }
  469. return this.addOriginal(n);
  470. };
  471. Map.prototype.setOriginal = Map.prototype.set;
  472. Map.prototype.set = function (n, v) {
  473. if (n instanceof Node_) {
  474. if (!this[wk]) this[wk] = mWeakRef(this);
  475. _nmMap.add(this[wk]);
  476. }
  477. if (v instanceof Node_) {
  478. if (!this[wk]) this[wk] = mWeakRef(this);
  479. _nmMapV.add(this[wk]);
  480. }
  481. return this.setOriginal(n, v);
  482. };
  483. }
  484.  
  485. window.showNM00 = () => {
  486. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  487. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  488. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  489. return { nmSet, nmMap, nmMapV };
  490. };
  491.  
  492. window.testNM00 = (x) => {
  493. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  494. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  495. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  496. for (const s of nmSet) if (s.has(x)) return 1;
  497. for (const m of nmMap) if (m.has(x)) return 2;
  498. for (const m of nmMapV) {
  499. for (const [u, v] of m.entries()) {
  500. if (v === x) return 4;
  501. }
  502. }
  503. return 0;
  504. };
  505.  
  506. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  507.  
  508. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  509.  
  510. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  511.  
  512. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  513.  
  514. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  515. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  516. return;
  517. }
  518.  
  519. const mapGet = Map.prototype.get;
  520. const setHas = Set.prototype.has;
  521.  
  522. /** @type {Map | null} */
  523. let qcMap = null;
  524.  
  525. Set.prototype.has = function (a) {
  526. if (a === 'dummy-4718') return false; // false to allow re-use?
  527. return setHas.call(this, a);
  528. }
  529.  
  530. Map.prototype.get = function (a) {
  531. if (a === 'dummy-4718') qcMap = this;
  532. return mapGet.call(this, a);
  533. };
  534. let r;
  535. try {
  536. r = mainCnt.createComponent_('dummy-4718', {}, true);
  537. } catch (e) {
  538.  
  539. }
  540.  
  541. Map.prototype.get = mapGet;
  542. Set.prototype.has = setHas;
  543.  
  544. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  545.  
  546.  
  547. // clearInterval(ckId);
  548. // ckId = 0;
  549.  
  550. if (qcMap !== null && qcMap instanceof Map) {
  551.  
  552. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  553. qcMap.__qcMap8781__ = true;
  554.  
  555. const setArrayC = (c) => {
  556. if (c instanceof Array) {
  557. c.length = 0;
  558. c.push = function () { };
  559. c.pop = function () { };
  560. c.shift = function () { };
  561. c.unshift = function () { };
  562. c.splice = function () { };
  563. c.sort = function () { };
  564. c.reverse = function () { };
  565. }
  566. }
  567.  
  568. const cleaning = function (m) {
  569. m.forEach(setArrayC);
  570. m.clear();
  571. }
  572.  
  573. qcMap.set = function (b, c) {
  574. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  575.  
  576. setArrayC(c);
  577.  
  578. // console.log('qcMap.set', b, c);
  579.  
  580. if (this.size > 0) {
  581. // play safe
  582.  
  583. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  584. cleaning(this);
  585. }
  586.  
  587. }
  588. qcMap.get = function (b) {
  589. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  590.  
  591. // console.log('qcMap.get', b);
  592.  
  593. if (this.size > 0) {
  594. // play safe
  595.  
  596. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  597. cleaning(this);
  598. }
  599.  
  600. }
  601.  
  602.  
  603. if (qcMap.size > 0) {
  604.  
  605. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  606. cleaning(qcMap);
  607. }
  608.  
  609. }
  610.  
  611. }
  612.  
  613. r = null;
  614. qcMap = null;
  615.  
  616. }
  617.  
  618.  
  619. const dispatchYtEvent = function (a, b, c, d) {
  620. d || (d = {
  621. bubbles: !0,
  622. cancelable: !1,
  623. composed: !0
  624. });
  625. c !== null && c !== void 0 && (d.detail = c);
  626. b = new CustomEvent(b, d);
  627. a.dispatchEvent(b);
  628. return b
  629. };
  630.  
  631. if (DISABLE_isLowLatencyLiveStream) {
  632. const sm = Symbol();
  633. const f = () => {
  634. try {
  635. const videoDetails = ytInitialPlayerResponse.videoDetails;
  636. if (videoDetails && videoDetails.isLowLatencyLiveStream) {
  637. videoDetails.isLowLatencyLiveStream = false;
  638. }
  639. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW') {
  640. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  641. }
  642. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  643. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  644. }
  645. } catch (e) { }
  646. }
  647. Object.defineProperty(Object.prototype, 'isLowLatencyLiveStream', {
  648. get() {
  649. const v = this[sm];
  650. if (typeof v === 'undefined') return v;
  651. f();
  652. return v;
  653. },
  654. set(nv) {
  655. f();
  656. if (nv === true) nv = false;
  657. this[sm] = nv;
  658. },
  659. enumerable: false,
  660. configurable: true
  661. });
  662.  
  663. const sm3 = Symbol();
  664. Object.defineProperty(Object.prototype, 'latencyClass', {
  665. get() {
  666. const v = this[sm3];
  667. if (typeof v === 'undefined') return v;
  668. f();
  669. return v;
  670. },
  671. set(nv) {
  672. f();
  673. if (nv === 'ULTRALOW' || nv === 'LOW') {
  674. nv = 'NORMAL';
  675. } else if (nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW' || nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  676. nv = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  677. }
  678. this[sm3] = nv;
  679. },
  680. enumerable: false,
  681. configurable: true
  682. });
  683.  
  684. }
  685.  
  686. class PlainHTMLElement extends HTMLTitleElement {
  687.  
  688. }
  689.  
  690. const removeShady = function (shady) {
  691. if (!shady || typeof shady !== 'object') return;
  692. const props = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  693. for (const prop of props) {
  694. const node = shady[prop];
  695. if (typeof (node || 0) !== 'object') continue;
  696. if (node.nodeType >= 1 && node.isConnected === false) _removedElements.addNode(node);
  697. }
  698. }
  699.  
  700. let _removedElements = new Set();
  701. _removedElements.add = _removedElements.addOriginal || _removedElements.add;
  702. _removedElements.addNode = MEMORY_RELEASE_NF00 ? function (node) {
  703. if (!node || node === _emptyElement || node.__keepInstance038__) return;
  704. if (!node[wk]) node[wk] = mWeakRef(node);
  705. return this.add(node[wk]);
  706. } : () => { };
  707.  
  708. let __removedElements = new Set();
  709. __removedElements.add = __removedElements.addOriginal || __removedElements.add;
  710. __removedElements.addNode = MEMORY_RELEASE_NF00 ? function (node) {
  711. if (!node || node === _emptyElement || node.__keepInstance038__) return;
  712. if (!node[wk]) node[wk] = mWeakRef(node);
  713. return this.add(node[wk]);
  714. } : () => { };
  715.  
  716. const _emptyElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  717. const _emptyTipsElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  718. const _emptyVisibilityElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  719.  
  720. const nf00 = new FinalizationRegistry_((x) => {
  721. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: node[${x}] fully removed`);
  722. });
  723. let ud00 = 0;
  724. const ng00 = new Set();
  725. nf00.registerNode = function (node) {
  726. if (node && node.nodeType >= 1) {
  727. if (!node.t792) {
  728. node.t792 = (ud00 = (ud00 & 1073741823) + 1);
  729. const x = `${node.nodeName.toLowerCase()}#${node.t792}`;
  730. this.register(node, x);
  731. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: try remove node[${x}]`);
  732. ng00.add(mWeakRef(node));
  733. }
  734. }
  735. }
  736. window.showNg00 = () => {
  737. const ng01 = new Set();
  738. ng01.add = ng01.addOriginal || ng01.add;
  739. for (const e of ng00) {
  740. const f = kRef(e);
  741. if (!f) continue;
  742. ng01.add(f);
  743. }
  744. const ng02 = [...ng01];
  745. ng01.clear();
  746. console.log(ng02);
  747. window.showNg01 = [...ng02];
  748. }
  749. window.showTemplates00 = () => {
  750. const result = {};
  751. const elements = document.querySelectorAll('*');
  752. for (const element of elements) {
  753. const tag = element.nodeName.toLocaleLowerCase();
  754. const r = result[tag] || [];
  755. const cnt = insp(element);
  756. if (cnt !== element) {
  757. if (cnt.templateInfo) {
  758. r.push(['cnt0', cnt.templateInfo, element]);
  759. }
  760. if (element._templateInfo) {
  761. r.push(['cnt1', cnt._templateInfo, element]);
  762. }
  763. if (element.__templateInfo) {
  764. r.push(['cnt2', cnt.__templateInfo, element]);
  765. }
  766. }
  767. if (element.templateInfo) {
  768. r.push(['elm0', element.templateInfo, element]);
  769. }
  770. if (element._templateInfo) {
  771. r.push(['elm1', element._templateInfo, element]);
  772. }
  773. if (element.__templateInfo) {
  774. r.push(['elm2', element.__templateInfo, element]);
  775. }
  776. if (r.length >= 1) result[tag] = r;
  777. }
  778. const strCmp = (a, b) => {
  779. if (a === b) return 0;
  780. let u = [a, b].sort();
  781. return u[0] === a ? -1 : 1;
  782. }
  783. const counting1 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[0]))].join('|')]).sort((a, b) => {
  784. return strCmp(`${a[1]}.${a[0]}`, `${b[1]}.${b[0]}`);
  785. });
  786.  
  787. const counting2 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[1]))]]);
  788.  
  789. const counting3 = Object.entries(result).map(e => {
  790. const a = [...new Set(e[1].map(t => t[1]))];
  791. const b = [...new Set(a.map(e => e.nodeList || e))];
  792.  
  793. const r = [e[0], b];
  794. return r;
  795. });
  796.  
  797. return {result, counting1, counting2, counting3};
  798. };
  799.  
  800. window.showFrag00 = function(){
  801.  
  802. const result = {};
  803. const elements = document.querySelectorAll('*');
  804. for (const element of elements) {
  805. const tag = element.nodeName.toLocaleLowerCase();
  806. const r = result[tag] || [];
  807. const cnt = insp(element);
  808. if (cnt !== element) {
  809. if (cnt.templateInfo) {
  810. r.push(['cnt0', cnt.templateInfo, element]);
  811. }
  812. if (element._templateInfo) {
  813. r.push(['cnt1', cnt._templateInfo, element]);
  814. }
  815. if (element.__templateInfo) {
  816. r.push(['cnt2', cnt.__templateInfo, element]);
  817. }
  818. }
  819. if (element.templateInfo) {
  820. r.push(['elm0', element.templateInfo, element]);
  821. }
  822. if (element._templateInfo) {
  823. r.push(['elm1', element._templateInfo, element]);
  824. }
  825. if (element.__templateInfo) {
  826. r.push(['elm2', element.__templateInfo, element]);
  827. }
  828. if (r.length >= 1) result[tag] = r;
  829. }
  830. return result;
  831.  
  832. }
  833.  
  834. if (MEMORY_RELEASE_NF00) {
  835.  
  836. setInterval(() => {
  837. const nodesSet = new Set();
  838. nodesSet.add = nodesSet.addOriginal || nodesSet.add;
  839.  
  840. for (const nodeWr of __removedElements) {
  841. __removedElements.delete(nodeWr);
  842. const node = kRef(nodeWr);
  843. if (node && node.nodeType >= 1 && node.isConnected === false) {
  844. nodesSet.add(node);
  845. if (node.querySelectorAll) {
  846. for (const p of node.querySelectorAll('*')) {
  847. nodesSet.add(p);
  848. }
  849. }
  850. }
  851. }
  852. for (const nodeWr of _removedElements) {
  853. _removedElements.delete(nodeWr);
  854. const node = kRef(nodeWr);
  855. if (node && node.isConnected === false) {
  856. __removedElements.add(nodeWr);
  857. }
  858. }
  859.  
  860. if(nodesSet.size === 0) return;
  861.  
  862. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  863. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  864. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  865.  
  866. for (const node of nodesSet) {
  867. if (node === _emptyElement || node.__keepInstance038__ || node.t792) continue;
  868. const hasToolTips = !!((insp(node).$ || 0).tooltip);
  869.  
  870. if (node && node.__shady_getRootNode) {
  871. const k = node.__shady_getRootNode();
  872. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  873. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  874. }
  875. if (node && node.getRootNode) {
  876. const k = node.getRootNode();
  877. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  878. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  879. }
  880.  
  881. if (node.__instances) {
  882. for (const k of node.__instances) {
  883. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  884. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  885. }
  886. // node.__instances.length = 0;
  887. }
  888. if (node && node.nodeType === 1 && insp(node).__teardownInstance) {
  889. try {
  890. insp(node).__teardownInstance();
  891. } catch (e) { }
  892. } else if (node && node.nodeType === 1 && node.__teardownInstance) {
  893. try {
  894. (node).__teardownInstance();
  895. } catch (e) { }
  896. }
  897. if (node && node.nodeType === 1 && node.__detachAndRemoveInstance && (node.__instances || 0).length >= 1) {
  898. for (let i = node.__instances.length - 1; i >= 0; i--) {
  899. node.__detachAndRemoveInstance(i)
  900. }
  901. }
  902. if (node && insp(node).unobserveNodes) {
  903. insp(node).unobserveNodes();
  904. }
  905. if (node && (node).unobserveNodes) {
  906. (node).unobserveNodes();
  907. }
  908. if (node && node.nodeType === 1 && node.is === void 0 && typeof node.dispose === 'function') {
  909. node.dispose();
  910. }
  911. if (node && node.nodeType === 1 && typeof node.unobserve_ === 'function') {
  912. node.unobserve_();
  913. }
  914.  
  915. if (node && node.nodeType === 1 && node.is === void 0 && typeof insp(node).dispose === 'function') {
  916. insp(node).dispose();
  917. }
  918. if (node && node.nodeType === 1 && typeof insp(node).unobserve_ === 'function') {
  919. insp(node).unobserve_();
  920. }
  921.  
  922. if (node && node.nodeType === 1 && typeof insp(node).unlinkPaths === 'function' && insp(node).__dataLinkedPaths) {
  923. for (let k in __dataLinkedPaths) {
  924. insp(node).unlinkPaths(k);
  925. }
  926. }
  927. const visibilityMonitorKeys = insp(node).visibilityMonitorKeys || node.visibilityMonitorKeys;
  928. if (visibilityMonitorKeys) {
  929. for (const entry of visibilityMonitorKeys) {
  930. if (entry.element) { entry.element = null }
  931. }
  932. visibilityMonitorKeys.length = 0;
  933. }
  934. if (node.__instances) {
  935. for (const k of node.__instances) {
  936. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  937. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  938. }
  939. node.__instances.length = 0;
  940. }
  941. const sp = node.__shady_parentNode;
  942. if (sp && sp.nodeType >= 1 && sp.isConnected === false) _removedElements.addNode(sp);
  943. FULLY_REMOVE_ALL_EVENT_LISTENERS && node.removeAllEventListener001();
  944. if (node && node.remove) node.remove();
  945.  
  946. /*
  947. if (node._templateInfo && node._templateInfo.content) {
  948. const templateInfoContent = node._templateInfo.content;
  949. if (templateInfoContent.nodeType >= 1 && templateInfoContent.isConnected === false) {
  950. _removedElements.addNode(templateInfoContent);
  951. }
  952. try{
  953. node._templateInfo.content = null;
  954. }catch(e){}
  955. }
  956. */
  957. if (node.__domApi) {
  958. node.__domApi = null;
  959. }
  960. if (node.__shady) {
  961. const shady = node.__shady;
  962. node.__shady = null;
  963. removeShady(shady);
  964. }
  965.  
  966.  
  967. const ceRoot = node.__CE_shadowRoot;
  968. if (ceRoot) {
  969.  
  970. node.__CE_shadowRoot = null;
  971. if (ceRoot.nodeType >= 1 && ceRoot.isConnected === false) {
  972. _removedElements.addNode(ceRoot);
  973. }
  974.  
  975. }
  976.  
  977. // xTeardownTemplateInfo
  978. const snChildNodes = node.__shady_native_childNodes;
  979. if (snChildNodes.length > 0) {
  980. for (const node of snChildNodes) {
  981. if (node && node.nodeType >= 1 && node.isConnected === false) {
  982. _removedElements.addNode(node);
  983. }
  984. }
  985. snChildNodes.length = 0;
  986. }
  987. node.__shady_native_childNodes = null;
  988.  
  989.  
  990. const __templateInfo = node.__templateInfo;
  991. if (__templateInfo) {
  992. node.__templateInfo = null;
  993. // xTeardownTemplateInfo(__templateInfo);
  994. }
  995.  
  996. if (hasToolTips && insp(node).$) {
  997. insp(node).$.tooltip = _emptyTipsElement;
  998. }
  999.  
  1000. if (node && node.nodeType >= 1) {
  1001. const pd = Object.getOwnPropertyDescriptor(node, 'visibilityMonitorKeys');
  1002. if (pd && pd.value && pd.value.length >= 1) {
  1003. const arr = pd.value;
  1004. for (let i = 0; i < arr.length; i++) {
  1005. arr[i].element = _emptyVisibilityElement;
  1006. arr[i] = null;
  1007. }
  1008. }
  1009. }
  1010.  
  1011. if (node.__dataHost) {
  1012. try {
  1013. delete node.__dataHost
  1014. } catch (e) { }
  1015. try {
  1016. node.__dataHost = null;
  1017. } catch (e) { }
  1018. }
  1019.  
  1020. if (node.root) {
  1021. try {
  1022. delete node.root
  1023. } catch (e) { }
  1024. try {
  1025. node.root = null;
  1026. } catch (e) { }
  1027. }
  1028.  
  1029. if (node.children && node.children.splice) {
  1030. try {
  1031. delete node.children
  1032. } catch (e) { }
  1033. try {
  1034. node.children = null;
  1035. } catch (e) { }
  1036. }
  1037.  
  1038. if (node.__shady && typeof node.__shady === 'object') {
  1039. try {
  1040. node.__shady = null;
  1041. } catch (e) { }
  1042. }
  1043.  
  1044. if (node.nodeType === 1) Reflect.setPrototypeOf(node, PlainHTMLElement.prototype);
  1045.  
  1046. for (const prop of Object.getOwnPropertyNames(node)) {
  1047. if (prop === 'host' && typeof (node.host || 0) === 'object') {
  1048. if (node.nodeType === 11) {
  1049. const nodeHost = node.host;
  1050. if (nodeHost && nodeHost.nodeType >= 1) {
  1051. node.host = _emptyElement;
  1052. if (nodeHost.isConnected === false && nodeHost !== _emptyElement) {
  1053. _removedElements.addNode(nodeHost);
  1054. }
  1055. } else {
  1056. node.host = null;
  1057. }
  1058. } else {
  1059. node.host = null;
  1060. }
  1061. continue;
  1062. }
  1063. const pd = Object.getOwnPropertyDescriptor(node, prop);
  1064. if (pd.value) {
  1065. const v = pd.value;
  1066. if (typeof (v || 0) === 'object') node[prop] = null;
  1067. else if (typeof (v || 0) === 'function') delete node[prop];
  1068. }
  1069. }
  1070.  
  1071. for (const prop of Object.getOwnPropertySymbols(node)) {
  1072. const v = node[prop];
  1073. if (typeof (v || 0) === 'object' && !v.deref) node[prop] = null;
  1074. }
  1075.  
  1076. if (node.__shady_native_childNodes) {
  1077. node.__shady_native_childNodes = _emptyElement.childNodes;
  1078. }
  1079. if (node.__shady_children) {
  1080. node.__shady_children = _emptyElement.children;
  1081. }
  1082.  
  1083. for (const s of nmSet) s.delete(node);
  1084. for (const m of nmMap) m.delete(node);
  1085.  
  1086. nf00.registerNode(node);
  1087.  
  1088.  
  1089.  
  1090. // console.log(1883001, node)
  1091. // console.log(3772001, node, node.countEvent767())
  1092. }
  1093.  
  1094. nodesSet.clear();
  1095.  
  1096. }, 400);
  1097.  
  1098. }
  1099.  
  1100.  
  1101. if (FULLY_REMOVE_ALL_EVENT_LISTENERS && !EventTarget.prototype.addEventListener828 && !EventTarget.prototype.removeAllEventListener001) {
  1102. const handlerMap = new WeakMap();
  1103. EventTarget.prototype.addEventListener828 = EventTarget.prototype.addEventListener;
  1104. EventTarget.prototype.addEventListener = function (type, handler, option = void 0) {
  1105. let hds = handlerMap.get(this);
  1106. if (!hds) handlerMap.set(this, (hds = new Set()));
  1107. hds.add([type, handler, option]);
  1108. return this.addEventListener828(type, handler, option);
  1109. }
  1110. EventTarget.prototype.removeEventListener828 = EventTarget.prototype.removeEventListener;
  1111. EventTarget.prototype.removeEventListener = function (type, handler, option = void 0) {
  1112. let hds = handlerMap.get(this);
  1113. if (hds) {
  1114. for (const entry of hds) {
  1115. if (entry[0] === type && entry[1] === handler && entry[2] === option) {
  1116. hds.delete(entry);
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. return this.removeEventListener828(type, handler, option);
  1122. }
  1123. EventTarget.prototype.countEvent767 = function(){
  1124. return handlerMap.get(this);
  1125. }
  1126. EventTarget.prototype.removeAllEventListener001 = function(){
  1127. let hds = handlerMap.get(this);
  1128. if (hds) {
  1129. handlerMap.delete(this);
  1130. for (const [type, handler, option] of hds) {
  1131. this.removeEventListener828(type, handler, option);
  1132. }
  1133. hds.clear();
  1134. }
  1135. }
  1136. }
  1137.  
  1138. const globalSetup = (key, setup)=>{
  1139. let symb = Symbol();
  1140. Object.defineProperty(Object.prototype, key, {
  1141. get() {
  1142. return this[symb];
  1143. },
  1144. set(nv) {
  1145. if (typeof nv !== 'function') {
  1146. this[symb] = nv;
  1147. return true;
  1148. }
  1149. if (!(symb in this)) {
  1150. setup(this);
  1151. }
  1152. this[symb] = nv;
  1153. return true;
  1154. },
  1155. configurable: true,
  1156. enumerable: false
  1157. });
  1158. }
  1159.  
  1160. const toActualNode = (e) => {
  1161. return e && e.getNode592177 ? e.getNode592177() : e;
  1162. }
  1163.  
  1164. const removeAllChildNodes = (o)=>{
  1165. if ((o instanceof Node) && o.nodeType >= 1) {
  1166. let t, q = null;
  1167. while ((t = o.firstChild) && t !== q) {
  1168. try {
  1169. _removedElements.addNode(t);
  1170. t.__keepInstance038__ = false;
  1171. t.remove();
  1172. q = t;
  1173. } catch (e) { }
  1174. }
  1175. try {
  1176. _removedElements.addNode(o);
  1177. o.__keepInstance038__ = false;
  1178. o.remove();
  1179. } catch (e) { }
  1180. }
  1181. }
  1182.  
  1183. const stampedNodes = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1184. stampedNodes.set = stampedNodes.setOriginal || stampedNodes.set;
  1185. const stampedFragment = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1186. stampedFragment.set = stampedFragment.setOriginal || stampedFragment.set;
  1187.  
  1188. if (FIX_TEMPLATE_BINDING) {
  1189. const templateMap = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1190. templateMap.set = templateMap.setOriginal || templateMap.set;
  1191. // const parsedTemplate = new Map();
  1192.  
  1193.  
  1194. const it0 = Date.now() - 80000000000;
  1195. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  1196.  
  1197.  
  1198. /*
  1199.  
  1200. M.prototype._bindTemplate = function(N, R) {
  1201. var X = this.constructor._parseTemplate(N)
  1202. , A = this.__preBoundTemplateInfo == X;
  1203. if (!A)
  1204. for (var l in X.propertyEffects)
  1205. this._createPropertyAccessor(l);
  1206. R ? (X = Object.create(X),
  1207. X.wasPreBound = A,
  1208. this.__templateInfo ? (N = N._parentTemplateInfo || this.__templateInfo,
  1209. R = N.lastChild,
  1210. X.parent = N,
  1211. N.lastChild = X,
  1212. (X.previousSibling = R) ? R.nextSibling = X : N.firstChild = X) : this.__templateInfo = X) : this.__preBoundTemplateInfo = X;
  1213. return X
  1214. }
  1215. ;
  1216. */
  1217.  
  1218. /*
  1219. ** this.constructor._parseTemplate **
  1220. d._parseTemplate = function(N, R) {
  1221. if (!N._templateInfo) {
  1222. var X = N._templateInfo = {};
  1223. X.nodeInfoList = [];
  1224. X.nestedTemplate = !!R;
  1225. X.stripWhiteSpace = R && R.stripWhiteSpace || N.hasAttribute && N.hasAttribute("strip-whitespace");
  1226. this._parseTemplateContent(N, X, {
  1227. parent: null
  1228. })
  1229. }
  1230. return N._templateInfo
  1231. }
  1232.  
  1233. */
  1234.  
  1235. // let initied1 = false;
  1236. // let _parseTemplateByPass = false;
  1237. const setup1 = (qxx) => {
  1238. // if(initied1) return;
  1239. // initied1 = true;
  1240. const proto = qxx;
  1241. const constructor = proto.constructor;
  1242. const _bindTemplate = proto._bindTemplate;
  1243. // console.log(12883, proto, constructor)
  1244.  
  1245.  
  1246. const _parseTemplate = constructor._parseTemplate;
  1247. if (typeof _parseTemplate === 'function' && _parseTemplate.length === 2 && !constructor._parseTemplate322) {
  1248.  
  1249. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _parseTemplate', _parseTemplate);
  1250. constructor._parseTemplate322 = _parseTemplate;
  1251. const parsedResults = new WeakMap();
  1252.  
  1253. const _templateInfoPd = {
  1254. get() {
  1255. if (!this || !this[wk]) return undefined;
  1256. const r = parsedResults.get(this[wk]);
  1257. return r;
  1258. },
  1259. set(nv) {
  1260. delete this._templateInfo;
  1261. this._templateInfo = nv;
  1262. console.warn('_templateInfoPd set');
  1263. return true;
  1264. },
  1265. enumerable: true,
  1266. configurable: true
  1267. };
  1268. constructor._parseTemplate = function (N, R) {
  1269. if (!N) return _parseTemplate.call(this, N, R);
  1270. if (!N[wk]) N[wk] = mWeakRef(N);
  1271. let r = parsedResults.get(N[wk]);
  1272. if (r) return r;
  1273. r = _parseTemplate.call(this, N, R);
  1274. if (r && !parsedResults.has(N[wk])) {
  1275. parsedResults.set(N[wk], r);
  1276. r.iAm68 = '_templateInfo';
  1277. N.iHave68 = '_templateInfo';
  1278. if (N._templateInfo && N._templateInfo === r) {
  1279. delete N._templateInfo;
  1280. if (!N._templateInfo) {
  1281. Object.defineProperty(N, '_templateInfo', _templateInfoPd);
  1282. }
  1283. }
  1284. }
  1285. return r;
  1286. }
  1287. }
  1288. if (typeof _bindTemplate === 'function' && _bindTemplate.length === 2 && !proto._bindTemplate322) {
  1289.  
  1290. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _bindTemplate', _bindTemplate);
  1291. proto._bindTemplate322 = _bindTemplate;
  1292. proto._bindTemplate = function (N, R) {
  1293. // R = boolean true or undefined
  1294. // N = template elemenet
  1295. let M = N;
  1296. if (typeof (N || 0) === 'object' && N instanceof HTMLTemplateElement && (N.content || 0).nodeType === 11) {
  1297. let componentIs = '';
  1298. try {
  1299. componentIs = this ? this.is : '';
  1300. } catch (e) { }
  1301. if (typeof (componentIs || 0) === 'string') {
  1302. if (!templateMap.has(componentIs)) {
  1303. templateMap.set(componentIs, N);
  1304. // const parser = this.constructor;
  1305. // console.log(3882, parser._parseTemplate)
  1306. /*
  1307. if (parser._parseTemplate && !parser._parseTemplate477 && parser._parseTemplate.length === 2) {
  1308. parser._parseTemplate477 = parser._parseTemplate;
  1309. const _parseTemplate477 = parser._parseTemplate477;
  1310. parser._parseTemplate = function (N, R) {
  1311. if (!_parseTemplateByPass && N && N[wk]) {
  1312. const u = parsedTemplate.get(N[wk]);
  1313. if (u) {
  1314. console.log(1838, u)
  1315. return u;
  1316. }
  1317. }
  1318. return _parseTemplate477.call(this, N, R);
  1319. };
  1320. }
  1321. if (parser._parseTemplate && parser._parseTemplate477) {
  1322. if (N && !N[wk]) N[wk] = mWeakRef(N);
  1323. if (!parsedTemplate.has(N[wk])) {
  1324. _parseTemplateByPass = true;
  1325. parsedTemplate.set(N[wk], parser._parseTemplate477(N));
  1326. _parseTemplateByPass = false;
  1327. }
  1328. }
  1329. */
  1330. } else {
  1331. M = templateMap.get(componentIs);
  1332. }
  1333. }
  1334. }
  1335. let r_ = null;
  1336. // Promise.resolve(N).then((N) => {
  1337. // console.log(3488,N.templateInfo, N.templateInfo === r_);
  1338. // })
  1339. const r = _bindTemplate.call(this, M, R);
  1340. r_ = r;
  1341. return r;
  1342. }
  1343. }
  1344.  
  1345. const _runEffectsForTemplate = proto._runEffectsForTemplate;
  1346. const gxx = (window.gxxC572 || (window.gxxC572 = new Set()));
  1347. if (typeof _runEffectsForTemplate === 'function' && _runEffectsForTemplate.length === 4 && !proto._runEffectsForTemplate322) {
  1348. proto._runEffectsForTemplate322 = _runEffectsForTemplate;
  1349.  
  1350. // note: fastDomIf does not work well with runEffects ...
  1351. // so no runEffects actaully?
  1352. const runner = (Tw, Nw, Rw, Xw, Aw) => {
  1353.  
  1354. try {
  1355.  
  1356.  
  1357. // console.log(988003)
  1358. const T = kRef(Tw); // this
  1359. const N = kRef(Nw); // __templateInfo
  1360. if (!T || !N) return;
  1361.  
  1362. // console.log(988004)
  1363. const R = kRef(Rw); // __data
  1364. const X = kRef(Xw); // temp Data ?
  1365. const A = kRef(Aw); // boolean ?
  1366. if (typeof (X || 0) === 'object') gxx.delete(X);
  1367. if (typeof (A || 0) === 'object') gxx.delete(A);
  1368.  
  1369. // console.log(988005)
  1370. const nodeList_ = N.nodeList;
  1371.  
  1372. // console.log(988006, nodeList_)
  1373. const nodeList = nodeList_ ? nodeList_.map(e => toActualNode(e)) : nodeList_;
  1374.  
  1375. // console.log(988007, nodeList)
  1376.  
  1377. const Nx = {
  1378. propertyEffects: N.propertyEffects,
  1379. nodeList: nodeList,
  1380. firstChild: kRef(N.firstChild)
  1381. };
  1382.  
  1383. // if (kRef(N.firstChild)) {
  1384. // console.log(977001, Nx)
  1385. // }
  1386.  
  1387. // console.log(988009, Nx, R, X, A)
  1388.  
  1389.  
  1390. {
  1391.  
  1392.  
  1393. const o = Nx;
  1394. const { propertyEffects, nodeList, firstChild } = o;
  1395. if (propertyEffects && nodeList && nodeList.length >= 0) {
  1396. for (const [effectKey, propertyEffectArr] of Object.entries(propertyEffects)) {
  1397. for (let i = propertyEffectArr.length - 1; i >= 0; i--) {
  1398. const propertyEffect = propertyEffectArr[i];
  1399. const info = (propertyEffect || 0).info;
  1400. if (info && typeof info.index === 'number' && !nodeList[info.index]) {
  1401. propertyEffectArr.splice(i, 1);
  1402. }
  1403. }
  1404. }
  1405. }
  1406.  
  1407. }
  1408.  
  1409.  
  1410. // console.log({T, Nx, R, X , A })
  1411.  
  1412. _runEffectsForTemplate.call(T, Nx, R, X, A);
  1413.  
  1414.  
  1415. } catch (err) {
  1416. debugger;
  1417. console.warn(err);
  1418. }
  1419.  
  1420. };
  1421.  
  1422.  
  1423. proto._runEffectsForTemplate = function (N, R, X, A) {
  1424.  
  1425. // console.log(988001)
  1426. /*
  1427. N {wasPreBound: true, nodeList: Array(23)}
  1428.  
  1429. R {showInput: false, narrow: false, menuStrings: {…}, pageDarkTheme: true, theater: false, …}
  1430. X {showInput: undefined, narrow: undefined, menuStrings: undefined, pageDarkTheme: undefined, theater: undefined, …}
  1431. A false
  1432. */
  1433.  
  1434. const Nw = (!N || typeof N !== 'object') ? N : (N[wk] || (N[wk] = mWeakRef(N))); // __templateInfo
  1435. const Xw = (!X || typeof X !== 'object') ? X : (X[wk] || (X[wk] = mWeakRef(X)));
  1436.  
  1437. const Rw = (!R || typeof R !== 'object') ? R : (R[wk] || (R[wk] = mWeakRef(R))); // __data
  1438. const Aw = (!A || typeof A !== 'object') ? A : (A[wk] || (A[wk] = mWeakRef(A)));
  1439.  
  1440. if (typeof (X || 0) === 'object') gxx.add(X);
  1441. if (typeof (A || 0) === 'object') gxx.add(A);
  1442.  
  1443. const Tw = (!this || typeof this !== 'object') ? this : (this[wk] || (this[wk] = mWeakRef(this)));
  1444.  
  1445.  
  1446. if (N.runEffects) {
  1447. N.runEffects(() => {
  1448. runner(Tw, Nw, Rw, Xw, Aw);
  1449. }, R, A);
  1450. } else {
  1451. runner(Tw, Nw, Rw, Xw, Aw);
  1452. }
  1453.  
  1454. // console.log(988002)
  1455.  
  1456. // const N_ =
  1457.  
  1458. // var l = this
  1459. // , k = function (T, W) {
  1460. // XK(l, N.propertyEffects, T, X, W, N.nodeList);
  1461. // for (var w = N.firstChild; w; w = w.nextSibling)
  1462. // l._runEffectsForTemplate(w, T, X, W)
  1463. // };
  1464. // N.runEffects ? N.runEffects(k, R, A) : k(R, A)
  1465. }
  1466.  
  1467. }
  1468.  
  1469. }
  1470. globalSetup('_removeBoundDom', setup1);
  1471.  
  1472.  
  1473. /*
  1474.  
  1475. M.prototype._stampTemplate = function(N, R) {
  1476. R = R || this._bindTemplate(N, !0);
  1477. aU.push(this);
  1478. N = d.prototype._stampTemplate.call(this, N, R);
  1479. aU.pop();
  1480. R.nodeList = N.nodeList;
  1481. if (!R.wasPreBound)
  1482. for (var X = R.childNodes = [], A = N.firstChild; A; A = A.nextSibling)
  1483. X.push(A);
  1484. N.templateInfo = R;
  1485. X = R.nodeList;
  1486. A = R.nodeInfoList;
  1487. if (A.length)
  1488. for (var l = 0; l < A.length; l++) {
  1489. var k = X[l]
  1490. , T = A[l].bindings;
  1491. if (T)
  1492. for (var W = 0; W < T.length; W++) {
  1493. var w = T[W]
  1494. , p = k
  1495. , h = w;
  1496. if (h.isCompound) {
  1497. for (var I = p.__dataCompoundStorage || (p.__dataCompoundStorage = {}), O = h.parts, y = Array(O.length), c = 0; c < O.length; c++)
  1498. y[c] = O[c].literal;
  1499. O = h.target;
  1500. I[O] = y;
  1501. h.literal && h.kind == "property" && (O === "className" && (p = (0,
  1502. _.FK)(p)),
  1503. p[O] = h.literal)
  1504. }
  1505. gM2(k, this, w)
  1506. }
  1507. k.__dataHost = this
  1508. }
  1509. this.__dataClientsReady && (this._runEffectsForTemplate(R, this.__data, null, !1),
  1510. this._flushClients());
  1511. return N
  1512. }
  1513. ;
  1514.  
  1515. */
  1516.  
  1517.  
  1518.  
  1519. class WeakNodeC {
  1520. constructor(eid) {
  1521. this.eid = eid;
  1522. }
  1523. addEventListener(type, listener, option = void 0) {
  1524. const nodeWr = stampedNodes.get(this.eid);
  1525. const node = kRef(nodeWr);
  1526. if (!node) return;
  1527. return node.addEventListener(type, listener, option);
  1528. }
  1529. removeEventListener(type, listener, option = void 0) {
  1530. const nodeWr = stampedNodes.get(this.eid);
  1531. const node = kRef(nodeWr);
  1532. if (!node) return;
  1533. return node.removeEventListener(type, listener, option);
  1534. }
  1535. getNode592177() {
  1536. const nodeWr = stampedNodes.get(this.eid);
  1537. const node = kRef(nodeWr);
  1538. return node;
  1539. }
  1540. set __dataHost(nv) {
  1541. const nodeWr = stampedNodes.get(this.eid);
  1542. const node = kRef(nodeWr);
  1543. if (!node) return;
  1544. node.__dataHost = nv;
  1545. return true;
  1546. }
  1547. get __dataHost() {
  1548. const nodeWr = stampedNodes.get(this.eid);
  1549. const node = kRef(nodeWr);
  1550. if (!node) return;
  1551. return node.__dataHost;
  1552. }
  1553.  
  1554. set __dataCompoundStorage(nv) {
  1555. const nodeWr = stampedNodes.get(this.eid);
  1556. const node = kRef(nodeWr);
  1557. if (!node) return;
  1558. node.__dataCompoundStorage = nv;
  1559. return true;
  1560.  
  1561. }
  1562. get __dataCompoundStorage() {
  1563. const nodeWr = stampedNodes.get(this.eid);
  1564. const node = kRef(nodeWr);
  1565. if (!node) return;
  1566. return node.__dataCompoundStorage;
  1567.  
  1568. }
  1569. }
  1570.  
  1571. // let initied2 = false;
  1572. const setup2 = (qxx) => {
  1573. // if(initied2) return;
  1574. // initied2 = true;
  1575. const proto = qxx;
  1576. const constructor = proto.constructor;
  1577. const _stampTemplate = proto._stampTemplate;
  1578. // console.log(12883, proto, constructor)
  1579. if (typeof _stampTemplate === 'function' && _stampTemplate.length === 2 && !proto._stampTemplate374) {
  1580. proto._stampTemplate374 = _stampTemplate;
  1581. proto._stampTemplate = function (N, R) {
  1582. // R = boolean true or binded template
  1583. // N = template elemenet
  1584. let M = N;
  1585. if (typeof (N || 0) === 'object' && N instanceof HTMLTemplateElement && (N.content || 0).nodeType === 11) {
  1586. let componentIs = '';
  1587. try {
  1588. componentIs = this ? this.is : '';
  1589. } catch (e) { }
  1590. if (typeof (componentIs || 0) === 'string') {
  1591. // if (!templateMap.has(componentIs)) {
  1592. // templateMap.set(componentIs, N);
  1593. // } else {
  1594. // M = templateMap.get(componentIs);
  1595. // }
  1596. }
  1597. }
  1598. let r_ = null;
  1599. // Promise.resolve(N).then((N) => {
  1600. // console.log(3488,N.templateInfo, N.templateInfo === r_);
  1601. // })
  1602. const r = _stampTemplate.call(this, M, R); // return the fragment created with nodeList
  1603. r_ = r;
  1604.  
  1605. if (r && r.nodeType === 11) {
  1606.  
  1607. const fid = genId();
  1608.  
  1609. r.__fragId57__ = fid;
  1610. if (!r[wk]) r[wk] = mWeakRef(r);
  1611. stampedFragment.set(fid, r[wk]);
  1612.  
  1613. if (r.nodeList) {
  1614. const nl = r.nodeList;
  1615. nl.__belongFragId57__ = fid;
  1616. for (let i = 0, l = nl.length; i < l; i++) {
  1617. const t = nl[i];
  1618. if (t && t.nodeType >= 1) {
  1619. if (!t[wk]) t[wk] = mWeakRef(t);
  1620. const eid = `${fid}::${i}`;
  1621. nl[i] = new WeakNodeC(eid);
  1622. stampedNodes.set(eid, t[wk]);
  1623. t.__weakNodeCId57__ = eid;
  1624. }
  1625. }
  1626. }
  1627.  
  1628. }
  1629.  
  1630. return r;
  1631. }
  1632. }
  1633. }
  1634.  
  1635. globalSetup('_addMethodEventListenerToNode', setup2);
  1636.  
  1637. }
  1638.  
  1639. if (XFlag) {
  1640.  
  1641. const cMap = new Set();
  1642. cMap.add = cMap.addOriginal || cMap.add;
  1643. const yMap = new Set();
  1644. yMap.add = yMap.addOriginal || yMap.add;
  1645.  
  1646.  
  1647. const ydMap = new Set();
  1648. ydMap.add = ydMap.addOriginal || ydMap.add;
  1649.  
  1650. window.yMap = yMap;
  1651. window.cMap = cMap;
  1652. window.ydMap = ydMap;
  1653.  
  1654. const constructAts = new Set();
  1655. constructAts.add = constructAts.addOriginal || constructAts.add;
  1656. window.constructAts = constructAts;
  1657.  
  1658. const kMap = new WeakMap();
  1659.  
  1660. const kRefProp = (wr, prop)=>{
  1661. let o = kRef(wr);
  1662. return o ? o[prop] : null;
  1663. }
  1664.  
  1665. const wrObj = (objRef, props) => {
  1666. let wr = mWeakRef(objRef);
  1667. if (wr === objRef || !props || !props.length) return wr;
  1668. let properties = {};
  1669. props.forEach(k => {
  1670. properties[k] = {
  1671. get() {
  1672. return kRefProp(this, k)
  1673. },
  1674. enumerable: false,
  1675. configurable: true
  1676. };
  1677. });
  1678. Object.defineProperties(wr, properties);
  1679. return wr;
  1680. }
  1681.  
  1682. const sProtos = {};
  1683.  
  1684. const setupCProto = function (cProto) {
  1685.  
  1686. if(cProto === Object.prototype) return;
  1687.  
  1688. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  1689. cProto[kMap.get(cProto)] = true;
  1690. // debugger;
  1691.  
  1692. 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];
  1693. constructAts.add(constructAt)
  1694.  
  1695. if (MemoryFix_Flag002 & 32) {
  1696. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  1697. fixDetachFn(cProto);
  1698. }
  1699. }
  1700.  
  1701. if (MemoryFix_Flag002 & 2) {
  1702. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  1703. cProto.__setPropDX38__ = true;
  1704.  
  1705. if (cProto._setPendingProperty.length === 3) {
  1706. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  1707. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  1708. return () => {
  1709. const obj = kRef(wobj);
  1710. let u = Reflect.apply(this, obj, args);
  1711. args.length = 0;
  1712. wobj = null;
  1713. return u;
  1714. };
  1715. });
  1716. }
  1717.  
  1718. }
  1719. }
  1720.  
  1721. // if (false && (MemoryFix_Flag002 & 4)) {
  1722. // if (cProto._runEffectsForTemplate && !cProto.__runEffectDX38__ && !cProto._runEffectsForTemplate3858 && !cProto._runEffectsForTemplate3857) {
  1723. // cProto.__runEffectDX38__ = true;
  1724.  
  1725. // if (cProto._runEffectsForTemplate.length === 4) {
  1726. // cProto._runEffectsForTemplate3858 = cProto._runEffectsForTemplate;
  1727. // if (FIX_MEMORY_RELEASE_RUNEFFECT_TEMPLATE) {
  1728. // cProto._runEffectsForTemplate3857 = function (o, d, e, g) {
  1729. // const { propertyEffects, nodeList, firstChild } = o;
  1730. // if (propertyEffects && nodeList && nodeList.length >= 0) {
  1731. // for (const [effectKey, propertyEffectArr] of Object.entries(propertyEffects)) {
  1732. // for (let i = propertyEffectArr.length - 1; i >= 0; i--) {
  1733. // const propertyEffect = propertyEffectArr[i];
  1734. // const info = (propertyEffect || 0).info;
  1735. // if (info && typeof info.index === 'number' && !nodeList[info.index]) {
  1736. // propertyEffectArr.splice(i, 1);
  1737. // }
  1738. // }
  1739. // }
  1740. // }
  1741. // return this._runEffectsForTemplate3858(o, d, e, g);
  1742. // }
  1743. // } else {
  1744. // cProto._runEffectsForTemplate3857 = cProto._runEffectsForTemplate3858;
  1745. // }
  1746. // cProto._runEffectsForTemplate = sProtos._runEffectsForTemplate || (sProtos._runEffectsForTemplate = function (c, d, e, g) {
  1747. // if (c && c.runEffects) {
  1748. // // const kNodeList = [...c.nodeList].map(e=>{
  1749. // // if(e && e.nodeType >= 1){
  1750. // // return e[wk] || (e[wk] = mWeakRef(e));
  1751. // // }else{
  1752. // // return e;
  1753. // // }
  1754. // // });
  1755. // let wr = wrObj(c, ['propertyEffects', 'nodeList', 'firstChild']);
  1756. // // console.log(12837)
  1757. // if (!this[wk]) this[wk] = mWeakRef(this);
  1758. // if ((typeof (e || 0) === "object") && !e[wk]) e[wk] = mWeakRef(e);
  1759. // let cntWr = this[wk];
  1760. // let eWr = (typeof (e || 0) === "object") ? e[wk] : e;
  1761. // c.runEffects((n, r) => {
  1762. // // console.log(12838)
  1763. // const cnt = kRef(cntWr);
  1764. // const e = kRef(eWr);
  1765. // if (cnt) {
  1766. // cnt._runEffectsForTemplate3857(wr, n, e, r);
  1767. // }
  1768. // wr = cntWr = d = e = g = null;
  1769. // }, d, g);
  1770. // } else if (typeof (c || 0) === 'object') {
  1771. // let { propertyEffects, nodeList, firstChild } = c;
  1772. // let o = { propertyEffects, nodeList, firstChild }
  1773. // // console.log(37271, propertyEffects, nodeList, firstChild);
  1774. // this._runEffectsForTemplate3857(o, d, e, g);
  1775. // o.propertyEffects = o.nodeList = o.firstChild = null;
  1776. // propertyEffects = nodeList = firstChild = null;
  1777. // o = null;
  1778. // }
  1779.  
  1780. // /*
  1781. // B5A = function(M, d, N, R, X, A, l) {
  1782. // l = l[X.index];
  1783.  
  1784.  
  1785. // !(l[X.index])
  1786.  
  1787.  
  1788. // m.fn(M, T, N, R, m.info, X, A),
  1789.  
  1790. // !(A[m.info.index])
  1791.  
  1792. // */
  1793. // });
  1794.  
  1795. // cProto._runEffectsForTemplate.bind = sProtos._runEffectsForTemplate$bind || (sProtos._runEffectsForTemplate$bind = function (obj, ...args) {
  1796. // // console.log(12993, args)
  1797. // let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  1798. // return () => {
  1799. // const obj = kRef(wobj);
  1800. // let u = Reflect.apply(this, obj, args);
  1801. // args.length = 0;
  1802. // wobj = null;
  1803. // return u;
  1804. // };
  1805. // });
  1806. // }
  1807.  
  1808. // }
  1809. // }
  1810.  
  1811.  
  1812.  
  1813. const cProtoConstructor = cProto.constructor;
  1814.  
  1815. if (MemoryFix_Flag002 & 8) {
  1816. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  1817. cProtoConstructor.__parseBindingsDX38__ = true;
  1818.  
  1819. ydMap.add(cProtoConstructor);
  1820.  
  1821. if (cProtoConstructor._parseBindings.length === 2) {
  1822.  
  1823. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  1824.  
  1825. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  1826. let p = this._parseBindings3858(c, d);
  1827. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  1828. if (p) this.__bindingsArrs__.push(p);
  1829. return p;
  1830. });
  1831.  
  1832. }
  1833. }
  1834. }
  1835.  
  1836. /*
  1837. a.prototype._initializeProperties = function() {
  1838. if (Em && this.hasAttribute("disable-upgrade"))
  1839. this.__isUpgradeDisabled = !0;
  1840. else {
  1841. var e = Object.getPrototypeOf(this);
  1842. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  1843. e.__hasRegisterFinished = !0);
  1844. b.prototype._initializeProperties.call(this);
  1845. this.root = this;
  1846. this.created();
  1847. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  1848. this._applyListeners()
  1849. }
  1850. }
  1851. */
  1852. /*
  1853. bOa = function(a, b, c) {
  1854. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  1855. d.prototype.is = b;
  1856. d.prototype.localName = b;
  1857. c && aOa(d, c);
  1858. return function(e) {
  1859. e && (d.prototype.hostElement = e);
  1860. var g = new d;
  1861. g.root = g;
  1862. g.hostElement = e;
  1863. return g
  1864. }
  1865. }
  1866. */
  1867.  
  1868.  
  1869. }
  1870. const symDH = Symbol();
  1871.  
  1872. const wfStore = new WeakMap();
  1873.  
  1874. const wrapF = function (f, key) {
  1875. if (wfStore.get(f)) return wfStore.get(f);
  1876.  
  1877. let g = function () {
  1878. const o = kRef(this);
  1879. if (!o) return;
  1880. const cnt = insp(o);
  1881. // if (cnt === o) return;
  1882. // if (!('ready' in cnt)) return;
  1883. return f.apply(o, arguments);
  1884. };
  1885. g.key38 = key;
  1886. g.originalFunc38 = f;
  1887. g.__wrapF84__ = true;
  1888. wfStore.set(f, g);
  1889. wfStore.set(g, g);
  1890. return g;
  1891. };
  1892.  
  1893. if (MemoryFix_Flag002 & 16) {
  1894. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  1895.  
  1896. Object.defineProperty(Node.prototype, key, {
  1897. get() {
  1898. return this[`__a0939${key}__`];
  1899. },
  1900. set(nv) {
  1901. if (typeof nv !== 'function') return;
  1902. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  1903. this[`__a0939${key}__`] = g;
  1904. return true;
  1905. }
  1906. });
  1907.  
  1908.  
  1909. });
  1910. }
  1911.  
  1912.  
  1913.  
  1914. // const wm = new WeakMap();
  1915.  
  1916. const fixDetachFn = (tpProto) => { // & 32
  1917.  
  1918. if (tpProto.dk322) return;
  1919. tpProto.dk322 = true;
  1920.  
  1921. window.__fixTemplateReuse1058__ = true;
  1922.  
  1923.  
  1924. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  1925. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  1926. tpProto.__ensureTemplatized = function () {
  1927. // console.log(18470001)
  1928. return this.__ensureTemplatized994();
  1929. }
  1930. }
  1931.  
  1932.  
  1933. tpProto.__updateInstances994 = tpProto.__updateInstances;
  1934. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  1935. let bypass= false;
  1936. // tpProto._stampTemplate994 = tpProto._stampTemplate;
  1937. // tpProto._stampTemplate = function(N,R){
  1938. // console.log(3882, [...N.nodeList])
  1939. // return this._stampTemplate994(N,R);
  1940. // }
  1941. tpProto.__updateInstances = function (a, b, c) {
  1942.  
  1943. // const a_ = [...a];
  1944. if(!bypass && a === this.items && (a||0).length >=1 ){
  1945.  
  1946. bypass = true;
  1947. // console.log(18470002, a, b,c)
  1948. let e;
  1949. for (e = 0; e < b; e++) {
  1950. let g = this.__instances[e]
  1951. , k = c[e]
  1952. , m = a[k];
  1953. if(g && typeof (m||0) === 'object'){
  1954. // const q = g._shouldPropertyChange;
  1955. // g._shouldPropertyChange = ()=>true;
  1956. // g[this.as] = {};
  1957. // a_[k]=a[k] = m;
  1958. // g[this.as] = m;
  1959.  
  1960. // use public interface notifyPath instead of internal interface _setPendingProperty
  1961. const m_ = a[k] = Object.assign({}, a[k]);
  1962. try {
  1963. g.notifyPath(this.as, {});
  1964. } catch (e) { }
  1965. try {
  1966. g.notifyPath(this.as, m_);
  1967. } catch (e) { }
  1968.  
  1969. // g._setPendingProperty(this.as, {});
  1970. // g._setPendingProperty(this.as, m);
  1971. // g._setPendingProperty(this.indexAs, e);
  1972. // g._setPendingProperty(this.itemsIndexAs, k);
  1973. // delete g._shouldPropertyChange;
  1974. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  1975. }
  1976. }
  1977. bypass = false;
  1978.  
  1979. }
  1980. const r = this.__updateInstances994(a,b,c);
  1981.  
  1982. // for (e = 0; e < b; e++) {
  1983. // let g = this.__instances[e]
  1984. // , k = c[e]
  1985. // , m = a_[k];
  1986. // if(g){
  1987. // // const q = g._shouldPropertyChange;
  1988. // // g._shouldPropertyChange = ()=>true;
  1989. // // g[this.as] = m;
  1990. // // g._setPendingProperty(this.as, {});
  1991. // // g._setPendingProperty(this.as, m);
  1992. // // g._setPendingProperty(this.indexAs, e);
  1993. // // g._setPendingProperty(this.itemsIndexAs, k);
  1994. // // delete g._shouldPropertyChange;
  1995. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  1996. // }
  1997. // }
  1998.  
  1999. return r;
  2000. }
  2001. }
  2002.  
  2003. /*
  2004.  
  2005. tpProto.__updateInstances = function (a, b, c) {
  2006.  
  2007. let renew = this.__wasInstanceDetached001 === true;
  2008. if(renew){
  2009.  
  2010. this.__wasInstanceDetached001 = false;
  2011. }
  2012.  
  2013. // const a_ = [...a];
  2014. // if(a === this.items && (a||0).length >=1 ){
  2015.  
  2016. // // console.log(18470002, a, b,c)
  2017. // let e;
  2018. // for (e = 0; e < b; e++) {
  2019. // let g = this.__instances[e]
  2020. // , k = c[e]
  2021. // , m = a[k];
  2022. // if(g && typeof (m||0) === 'object'){
  2023. // // const q = g._shouldPropertyChange;
  2024. // // g._shouldPropertyChange = ()=>true;
  2025. // // g[this.as] = {};
  2026. // // a_[k]=a[k] = m;
  2027. // // g[this.as] = m;
  2028.  
  2029. // // use public interface notifyPath instead of internal interface _setPendingProperty
  2030. // try {
  2031. // g.notifyPath(this.as, {});
  2032. // } catch (e) { }
  2033. // try {
  2034. // g.notifyPath(this.as, m);
  2035. // } catch (e) { }
  2036.  
  2037. // // g._setPendingProperty(this.as, {});
  2038. // // g._setPendingProperty(this.as, m);
  2039. // // g._setPendingProperty(this.indexAs, e);
  2040. // // g._setPendingProperty(this.itemsIndexAs, k);
  2041. // // delete g._shouldPropertyChange;
  2042. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2043. // }
  2044. // }
  2045.  
  2046. // }
  2047. const r = this.__updateInstances994(a,b,c);
  2048.  
  2049. // for (e = 0; e < b; e++) {
  2050. // let g = this.__instances[e]
  2051. // , k = c[e]
  2052. // , m = a_[k];
  2053. // if(g){
  2054. // // const q = g._shouldPropertyChange;
  2055. // // g._shouldPropertyChange = ()=>true;
  2056. // // g[this.as] = m;
  2057. // // g._setPendingProperty(this.as, {});
  2058. // // g._setPendingProperty(this.as, m);
  2059. // // g._setPendingProperty(this.indexAs, e);
  2060. // // g._setPendingProperty(this.itemsIndexAs, k);
  2061. // // delete g._shouldPropertyChange;
  2062. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2063. // }
  2064. // }
  2065. if (renew) {
  2066.  
  2067. const q = [...this.items];
  2068. this.items = [];
  2069. this.items = q;
  2070. console.log(129992)
  2071. // this.items.splice(0, 1, Object.assign({}, this.items[0]));
  2072. }
  2073. return r;
  2074. }
  2075.  
  2076. */
  2077.  
  2078. tpProto.__detachInstance994 = tpProto.__detachInstance;
  2079. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  2080. tpProto.__detachInstance = function (a) {
  2081. const u = this.__instances[a];
  2082. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2083. const children = (u || 0).children;
  2084. if (children && children.length >= 1) {
  2085. const pp = document.createDocumentFragment();
  2086. for (const s of [...children]) {
  2087. pp.appendChild(s);
  2088. }
  2089. }
  2090. try {
  2091. return this.__detachInstance994(a);
  2092. } catch (e) { }
  2093. return u;
  2094. }
  2095. }
  2096.  
  2097. tpProto.__attachInstance994 = tpProto.__attachInstance;
  2098. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  2099. tpProto.__attachInstance = function (a, b) {
  2100. const u = this.__instances[a];
  2101. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2102. if (u && u.root && b) {
  2103. const root = u.root;
  2104. const pp = document.createDocumentFragment();
  2105. pp.appendChild(root);
  2106. root.appendChild(pp);
  2107. const r = this.__attachInstance994(a, b);
  2108. if (!this.__chunkingId) this.__chunkingId = 0.25;
  2109. return r;
  2110. }
  2111. }
  2112. }
  2113.  
  2114. }
  2115.  
  2116. const ytTemplateDomEntry = (tpProto) => {
  2117.  
  2118. console.log('ytTemplateDomEntry triggered')
  2119.  
  2120.  
  2121. const convertToWeakArr = (arr) => {
  2122.  
  2123. if (arr.isWeak) return;
  2124.  
  2125. for (let i = 0, l = arr.length; i < l; i++) {
  2126. const o = arr[i]
  2127. if (o) {
  2128. let p = kRef(o)
  2129. if (!p) arr[i] = null;
  2130. else {
  2131. if (!o[wk]) o[wk] = mWeakRef(o);
  2132. arr[i] = o[wk];
  2133. }
  2134. }
  2135. }
  2136. arr.isWeak = true;
  2137.  
  2138. }
  2139.  
  2140. const convertToNormalArr = (arr) => {
  2141.  
  2142. if (!arr.isWeak) return;
  2143.  
  2144. for (let i = 0, l = arr.length; i < l; i++) {
  2145. const o = arr[i]
  2146. if (o) {
  2147. let p = kRef(o)
  2148. arr[i] = p;
  2149. }
  2150. }
  2151. arr.isWeak = false;
  2152.  
  2153. }
  2154.  
  2155. if (MemoryFix_Flag002 & 256) {
  2156. Object.defineProperty(tpProto, '__instances', {
  2157. get() {
  2158. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2159. let arr = this.__instances_actual471__;
  2160. if (arr && arr.isWeak) {
  2161. convertToNormalArr(arr);
  2162. for (let i = arr.length - 1; i >= 0; i--) {
  2163. const t = arr[i];
  2164. if (!t) arr.splice(i, 1);
  2165. else if (!t.__keepInstance038__) t.__keepInstance038__ = true;
  2166. }
  2167. Promise.resolve(arr).then(convertToWeakArr);
  2168. }
  2169. return arr;
  2170. },
  2171. set(nv) {
  2172. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2173. this.__instances_actual471__ = nv;
  2174. if (nv && !nv.isWeak) {
  2175. Promise.resolve(nv).then(convertToWeakArr);
  2176. }
  2177. return true;
  2178. },
  2179. enumerable: false,
  2180. configurable: true
  2181. });
  2182. }
  2183.  
  2184. // console.log(91901, tpProto.__detachInstance)
  2185. if (MemoryFix_Flag002 & 32) {
  2186. if (tpProto.__detachInstance) {
  2187. fixDetachFn(tpProto);
  2188. } else {
  2189. Promise.resolve(tpProto).then((tpProto) => {
  2190. // console.log(91902, tpProto.__detachInstance)
  2191. fixDetachFn(tpProto);
  2192. })
  2193. }
  2194. }
  2195.  
  2196. }
  2197.  
  2198. if (MemoryFix_Flag002 & 32) {
  2199. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  2200. set(nv) {
  2201. if (nv === true) return false;
  2202. tpProto = this;
  2203. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  2204. tpProto.__domDX37__ = true;
  2205. ytTemplateDomEntry(tpProto);
  2206. }
  2207. this.__ensureTemplatized949__ = nv;
  2208. return true;
  2209. },
  2210. get() {
  2211. return this.__ensureTemplatized949__;
  2212. }
  2213. });
  2214. }
  2215.  
  2216.  
  2217. if (MemoryFix_Flag002 & 64) {
  2218. HTMLElement_.prototype.__dataHostBinding374 = true;
  2219. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  2220. get() {
  2221. return kRef(this.__dataHostWr413__);
  2222. },
  2223. set(nv) {
  2224. if (nv && typeof nv === 'object' && !nv.deref) {
  2225. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2226. nv = nv[wk];
  2227. }
  2228. this.__dataHostWr413__ = nv;
  2229. return true;
  2230. }
  2231. });
  2232. }
  2233.  
  2234.  
  2235. const setupYProto = function (yProto) {
  2236.  
  2237. if(yProto === Object.prototype) return;
  2238.  
  2239. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2240. yProto[kMap.get(yProto)] = true;
  2241.  
  2242. 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') {
  2243. const disconnectedCallback277 = yProto.disconnectedCallback;
  2244. yProto.disconnectedCallback277 = true;
  2245. yProto.disconnectedCallback = function () {
  2246. disconnectedCallback277.call(this);
  2247. if (this.nodeName === 'DOM-IF' && this.__instance && typeof this.__teardownInstance === 'function') {
  2248. const shadyParent = (this.__shady_parentNode || 0);
  2249. const actualParent = (this.parentNode || 0);
  2250. if (shadyParent !== actualParent && shadyParent.nodeType === 11 && actualParent.nodeType === 11) {
  2251. // && (shadyParent.compareDocumentPosition(actualParent) & (1|8|16) === 1)
  2252. // if (!this.restamp && !this.id && this.__ctor && this.isConnected === false) {
  2253. const children = (this.__instance.children || 0).length;
  2254. if (children >= 1) {
  2255. try {
  2256. this.__teardownInstance();
  2257. } catch (e) { }
  2258. }
  2259. // }
  2260. }
  2261. }
  2262. }
  2263. }
  2264.  
  2265.  
  2266. // if(yProto.constructor._contentForTemplate && yProto.constructor._parseTemplateNodeAttribute && yProto.constructor._parseTemplateNestedTemplate && !yProto.constructor.y366){
  2267.  
  2268. // yProto.constructor.y366 = 1;
  2269.  
  2270. // const _stampTemplate366 = yProto._stampTemplate;
  2271. // yProto._stampTemplate = function(N, R){
  2272. // console.log(12773, N, R);
  2273. // return _stampTemplate366.call(this, N, R);
  2274. // }
  2275.  
  2276. // }
  2277. /*
  2278. if(yProto._bindTemplate && !yProto._bindTemplate371) {
  2279. yProto._bindTemplate371 = true;
  2280. const _bindTemplate371 = yProto._bindTemplate;
  2281. yProto._bindTemplate = function(a, b){
  2282. const R = _bindTemplate371.call(this, a, b);
  2283. const X = R.nodeList || 0;
  2284. const A = R.nodeInfoList || 0;
  2285. // if(X && A && X.length === A.length){
  2286. // for(let i =0, l=A.length;i<l; i++){
  2287. // if()
  2288. // }
  2289. // }
  2290. const l = Math.max((X.length || 0), (A.length || 0));
  2291. const e = {};
  2292. for (let i = 0; i < l; i++) {
  2293. if (X && !X[i]) X[i] = e;
  2294. if (A && !A[i]) A[i] = e;
  2295. }
  2296.  
  2297.  
  2298. return R;
  2299. }
  2300. }
  2301.  
  2302. if(yProto._stampTemplate && !yProto._stampTemplate371) {
  2303. yProto._stampTemplate371 = true;
  2304. const _stampTemplate371 = yProto._stampTemplate;
  2305. yProto._stampTemplate = function(a, b){
  2306. const R = _stampTemplate371.call(this, a, b);
  2307. const X = R.nodeList || 0;
  2308. const A = R.nodeInfoList || 0;
  2309. // if(X && A && X.length === A.length){
  2310. // for(let i =0, l=A.length;i<l; i++){
  2311. // if()
  2312. // }
  2313. // }
  2314. const l = Math.max((X.length || 0), (A.length || 0));
  2315. const e = {};
  2316. for (let i = 0; i < l; i++) {
  2317. if (X && !X[i]) X[i] = e;
  2318. if (A && !A[i]) A[i] = e;
  2319. }
  2320. return R;
  2321. }
  2322. }
  2323. */
  2324.  
  2325.  
  2326. if (MemoryFix_Flag002 & 32) {
  2327. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  2328. fixDetachFn(yProto);
  2329. }
  2330. }
  2331.  
  2332. if (MemoryFix_Flag002 & 128) {
  2333. if (!yProto.__dataHostBinding374) {
  2334. yProto.__dataHostBinding374 = true;
  2335. Object.defineProperty(yProto, '__dataHost', {
  2336. set(nv) {
  2337. let dh = nv;
  2338. if (dh && typeof dh === 'object' && !dh.deref) {
  2339. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  2340. dh = wr;
  2341. }
  2342. this[symDH] = dh;
  2343. return true;
  2344. },
  2345. get() {
  2346. let wr = this[symDH];
  2347. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  2348. return obj;
  2349. },
  2350. enumerable: false,
  2351. configurable: true
  2352. });
  2353. }
  2354.  
  2355.  
  2356.  
  2357. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  2358. yProto._registerHostDX38__ = true;
  2359.  
  2360. // yProto._registerHost7133 = yProto._registerHost;
  2361.  
  2362. yProto.__enableOrFlushClients = function () {
  2363. const c_ = this.__dataPendingClients;
  2364. if (c_) {
  2365. const c = c_.slice();
  2366. c_.length = 0;
  2367. for (let d = 0, l = c.length; d < l; d++) {
  2368. let e = kRef(c[d]);
  2369. if (e) {
  2370. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  2371. }
  2372. }
  2373. }
  2374. }
  2375.  
  2376. yProto._enqueueClient = function (c) {
  2377. if (c === this || !c || typeof c !== 'object') return;
  2378. if (c.deref) c = kRef(c);
  2379. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  2380. if (!c[wk]) c[wk] = mWeakRef(c);
  2381. m.push(c[wk]);
  2382. }
  2383.  
  2384. }
  2385. }
  2386.  
  2387.  
  2388.  
  2389. }
  2390. const setupRendering = function () {
  2391.  
  2392. const cnt = this;
  2393. const cProto = Reflect.getPrototypeOf(cnt);
  2394. let yProto = Reflect.getPrototypeOf(cProto);
  2395.  
  2396. const yProtos = new Set();
  2397.  
  2398. if (!yMap.has(yProto)) {
  2399. // capture all ancenstor constructors of a and b (non-specific component type)
  2400.  
  2401. do {
  2402. if (yProto === Object.prototype || yProto === null) break;
  2403. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  2404. yProtos.add(yProto);
  2405. yProto = Reflect.getPrototypeOf(yProto);
  2406. } while (!yProtos.has(yProto));
  2407.  
  2408. for (const yProto of yProtos) {
  2409. yMap.add(yProto);
  2410. setupYProto(yProto)
  2411. }
  2412.  
  2413. }
  2414.  
  2415.  
  2416. if (!cMap.has(cProto)) {
  2417. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  2418. setupCProto(cProto);
  2419. }
  2420.  
  2421. }
  2422.  
  2423. // const selfRef = {}; // no change. just key
  2424.  
  2425. /*
  2426.  
  2427. jF = function(M) {
  2428. var d = YNV.call(this) || this;
  2429. d._configureProperties(M);
  2430. d.root = d._stampTemplate(d.__dataHost);
  2431. var N = [];
  2432. d.children = N;
  2433. for (var R = d.root.firstChild; R; R = R.nextSibling)
  2434. N.push(R),
  2435. R.__templatizeInstance = d;
  2436. d.__templatizeOwner && d.__templatizeOwner.__hideTemplateChildren__ && d._showHideChildren(!0);
  2437. N = d.__templatizeOptions;
  2438. (M && N.instanceProps || !N.instanceProps) && d._enableProperties();
  2439. return d
  2440. };
  2441. */
  2442.  
  2443. const sb1 = Symbol();
  2444. Object.defineProperty(Object.prototype, 'root', {
  2445. get() {
  2446. return this[sb1];
  2447. },
  2448. set(nv){
  2449. const p = this ? kRef(this) : null;
  2450. const mv = nv ? kRef(nv) : null;
  2451.  
  2452. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2453. p.__setupRendered399__ = true;
  2454. setupRendering.call(p);
  2455. }
  2456. if (mv && mv.is && !mv.__setupRendered399__) {
  2457. mv.__setupRendered399__ = true;
  2458. setupRendering.call(mv);
  2459. }
  2460.  
  2461. this[sb1] = nv;
  2462. return true;
  2463. }
  2464. });
  2465.  
  2466.  
  2467. /*
  2468. let wm3 = new WeakMap();
  2469.  
  2470. Object.defineProperty(Object.prototype, 'root', {
  2471. get() {
  2472. const p = this ? kRef(this) : null;
  2473. const r = p ? wm3.get(p) : null;
  2474. const r2 = r ? kRef(r) : null;
  2475. if (r === selfRef) return p;
  2476. return r2;
  2477. },
  2478. set(nv) {
  2479. const p = this ? kRef(this) : null;
  2480. const mv = nv ? kRef(nv) : null;
  2481. if (typeof mv !== 'object') return;
  2482. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2483. p.__setupRendered399__ = true;
  2484. setupRendering.call(p);
  2485. }
  2486. if (mv && mv.is && !mv.__setupRendered399__) {
  2487. mv.__setupRendered399__ = true;
  2488. setupRendering.call(mv);
  2489. }
  2490. if (mv === p) {
  2491. wm3.set(p, selfRef)
  2492. return true;
  2493. }
  2494. let gv = nv;
  2495. if (nv && !nv[wk]) {
  2496. gv = nv[wk] = mWeakRef(nv);
  2497. }
  2498. if (p) {
  2499. wm3.set(p, gv);
  2500. }
  2501. return true;
  2502. },
  2503. enumerable: false,
  2504. configurable: true
  2505. });
  2506. */
  2507.  
  2508.  
  2509. }
  2510.  
  2511. function getTranslate() {
  2512.  
  2513. pLoad.then(() => {
  2514.  
  2515. let nonce = document.querySelector('style[nonce]');
  2516. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2517. const st = document.createElement('style');
  2518. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2519. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  2520. let parent;
  2521. if (parent = document.head) parent.appendChild(st);
  2522. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  2523.  
  2524. });
  2525.  
  2526. const snCache = new Map();
  2527.  
  2528. if (TRANSLATE_DEBUG) {
  2529. console.log(11)
  2530. }
  2531.  
  2532. /** @type {(str: string?) => string} */
  2533. function _snippetText(str) {
  2534. // str can be underfinded
  2535. if (!str || typeof str !== 'string') return '';
  2536. let res = snCache.get(str);
  2537. if (res === undefined) {
  2538. let b = false;
  2539. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  2540. b = true;
  2541. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  2542. });
  2543. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  2544. b = true;
  2545. return '';
  2546. });
  2547. if (b) {
  2548. snCache.set(str, res);
  2549. snCache.set(res, null);
  2550. } else {
  2551. res = null;
  2552. snCache.set(str, null);
  2553. }
  2554. }
  2555. return res === null ? str : res;
  2556. }
  2557.  
  2558. /** @type {(snippet: Object) => string} */
  2559. function snippetText(snippet) {
  2560. let runs = snippet.runs;
  2561. const n = runs.length;
  2562. if (n === 1) return _snippetText(runs[0].text);
  2563. let res = new Array(n);
  2564. let ci = 0;
  2565. for (const s of runs) {
  2566. res[ci++] = _snippetText(s.text);
  2567. }
  2568. return res.join('\n');
  2569. }
  2570.  
  2571. const _DEBUG_szz = (t) => t.map(x => {
  2572. const tsr = x.transcriptSegmentRenderer;
  2573. return ({
  2574. t: tsr.snippet.runs.map(x => x.text).join('//'),
  2575. a: tsr.startMs,
  2576. b: tsr.endMs
  2577. });
  2578. });
  2579.  
  2580. const fixRuns = (runs) => {
  2581. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  2582. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  2583. const text = runs[0].text;
  2584. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  2585. const s = text.split(nlc);
  2586. let bi = 0;
  2587. runs.length = s.length;
  2588. for (const text of s) {
  2589. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  2590. }
  2591. }
  2592. for (const s of runs) {
  2593. s.text = _snippetText(s.text);
  2594. }
  2595. }
  2596.  
  2597. function translate(initialSegments) {
  2598. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  2599.  
  2600. if (!initialSegments) return initialSegments;
  2601.  
  2602. if (TRANSLATE_DEBUG) {
  2603. console.log(12);
  2604. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  2605. let obj = JSON.parse(r);
  2606. console.log(7558, 1, obj)
  2607. return obj;
  2608. }).then(p => {
  2609. let obj = _DEBUG_szz(p)
  2610. console.log(7558, 2, obj)
  2611. })
  2612. }
  2613.  
  2614.  
  2615. //let mapRej = new WeakSet();
  2616.  
  2617. const n1 = initialSegments.length;
  2618. if (!n1) return fRes;
  2619. let n2 = 0;
  2620.  
  2621.  
  2622. const fRes = new Array(n1);
  2623. // -----------------------------------------------------------------------------------------
  2624.  
  2625. const s8 = Symbol();
  2626.  
  2627. {
  2628.  
  2629. /** @type {Map<String, Object>} */
  2630. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  2631.  
  2632. // /-* * @type {Map<String, number>} *-/
  2633. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  2634. // 1: ok
  2635. // 2: abandoned effect text
  2636.  
  2637. for (const initialSegment of initialSegments) {
  2638. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  2639. if (!transcript) {
  2640. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2641. fRes[n2++] = initialSegment;
  2642. continue;
  2643. }
  2644. const runs = transcript.snippet.runs
  2645. if (!runs || runs.length === 0) {
  2646. initialSegment[s8] = true;
  2647. continue;
  2648. }
  2649. let startMs = (+transcript.startMs || 0); //integer
  2650. let endMs = (+transcript.endMs || 0); //integer
  2651. if (startMs === endMs) {
  2652. // effect text
  2653. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2654. //mapRej.add(initialSegment)
  2655. continue;
  2656. }
  2657. if (endMs - startMs < 30) {
  2658. continue;
  2659. }
  2660. const text = snippetText(transcript.snippet);
  2661. const hEntry = cacheTexts.get(text);
  2662. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  2663. if (mh1e === 2) continue;
  2664. const entry = {
  2665. startMs,
  2666. endMs,
  2667. initialSegment,
  2668. text
  2669. };
  2670. if (mh1e === 0) {
  2671. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  2672. initialSegment[s8] = true;
  2673. cacheTexts.set(text, null);
  2674. //effect only
  2675. // https://www.youtube.com/watch?v=zLak0dxBKpM
  2676. //mapRej.add(initialSegment)
  2677. continue;
  2678. }
  2679. } else if (hEntry) {
  2680.  
  2681. const timeDiff = entry.startMs - hEntry.endMs;
  2682. let shouldMerge = false;
  2683.  
  2684. if (timeDiff >= 0) {
  2685.  
  2686. if (timeDiff < 25) {
  2687. shouldMerge = true;
  2688. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  2689. shouldMerge = true;
  2690. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  2691. shouldMerge = true;
  2692. }
  2693.  
  2694. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  2695. // abandon the current entry.
  2696. // absorbed by previous entry
  2697. hEntry.endMs = entry.endMs;
  2698. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2699. //mapRej.add(entry.initialSegment);
  2700. continue;
  2701. }
  2702.  
  2703. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  2704.  
  2705. // abandon the current entry.
  2706. // absorbed by previous entry
  2707. if (entry.endMs > hEntry.endMs) {
  2708. hEntry.endMs = entry.endMs;
  2709. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2710. }
  2711. //mapRej.add(entry.initialSegment);
  2712. continue;
  2713.  
  2714. }
  2715.  
  2716. }
  2717. //if not abandoned
  2718. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  2719. // for (const s of runs) {
  2720. // s.text = _snippetText(s.text);
  2721. // }
  2722. fixRuns(runs);
  2723. fRes[n2++] = initialSegment;
  2724. }
  2725.  
  2726. // cacheTexts.clear(); // let GC do it.
  2727. cacheTexts = null;
  2728. // mh1.clear(); // let GC do it.
  2729. // mh1 = null;
  2730.  
  2731. }
  2732.  
  2733. const si_length = fRes.length = n2;
  2734. const sj_length = n1;
  2735.  
  2736. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  2737. // collect the abandon text to become second subtitle
  2738.  
  2739. let sj_start = 0;
  2740. let invalid_sj = -1;
  2741. for (let si = 0; si < si_length; si++) {
  2742. const segment = fRes[si];
  2743. let transcript = segment.transcriptSegmentRenderer;
  2744. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  2745. const runs = transcript.snippet.runs;
  2746. // fixRuns(runs);
  2747. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  2748. const main_startMs = (+transcript.startMs || 0);
  2749. const main_endMs = (+transcript.endMs || 0);
  2750. transcript = null;
  2751.  
  2752. /** @type {Map<string, number>} */
  2753. let tMap = new Map(); // avoid duplicate with javascript object properties
  2754.  
  2755. // assume that it is asc-ordered array of key startMs;
  2756. for (let sj = sj_start; sj < sj_length; sj++) {
  2757. const initialSegment = initialSegments[sj];
  2758.  
  2759. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  2760.  
  2761. const tSegment = initialSegment.transcriptSegmentRenderer;
  2762.  
  2763. if (!tSegment) {
  2764. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2765. invalid_sj = sj; // should invalid_sj be set ?
  2766. continue;
  2767. }
  2768.  
  2769. const startMs = (+tSegment.startMs || 0)
  2770. const isStartValid = startMs >= main_startMs;
  2771. if (!isStartValid) {
  2772. invalid_sj = sj;
  2773. continue;
  2774. }
  2775. // isStartValid must be true
  2776. if (startMs > main_endMs) {
  2777. sj_start = invalid_sj + 1;
  2778. break;
  2779. }
  2780.  
  2781. const endMs = (+tSegment.endMs || 0)
  2782. if (endMs <= main_endMs) {
  2783. const mt = snippetText(tSegment.snippet);
  2784. const prev = tMap.get(mt);
  2785. if (endMs >= startMs) {
  2786. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  2787. }
  2788. }
  2789.  
  2790. }
  2791.  
  2792. if (tMap.size <= 1) continue; // no second line
  2793. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  2794. tMap = null;
  2795.  
  2796. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2797.  
  2798. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  2799.  
  2800. let targetZ = rg[1][1];
  2801. if (targetZ > 4) {
  2802. let az = 0;
  2803. let fail = false;
  2804. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  2805. az += rg[idx][1];
  2806. if (az >= targetZ) {
  2807. fail = true;
  2808. break;
  2809. }
  2810. }
  2811. if (!fail) {
  2812. const rgA = rg[0][0];
  2813. const rgB = rg[1][0];
  2814. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  2815. if (isDiff && rgA === _snippetText(runs[0].text)) {
  2816. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  2817. runs.push({ text: rgB, blockLine: true });
  2818. }
  2819. }
  2820. }
  2821. rg = null;
  2822. }
  2823.  
  2824. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  2825.  
  2826. let obj = r;
  2827. console.log(7559, 1, obj)
  2828. return obj;
  2829. }).then(p => {
  2830. let obj = _DEBUG_szz(p)
  2831. console.log(7559, 2, obj)
  2832.  
  2833. });
  2834. }
  2835.  
  2836. // -----------------------------------------------------------------------------------------
  2837. snCache.clear();
  2838. return fRes;
  2839.  
  2840. }
  2841.  
  2842.  
  2843. return translate
  2844.  
  2845. }
  2846.  
  2847.  
  2848. let translateFn = null;
  2849.  
  2850. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  2851.  
  2852. const wmx = new WeakMap();
  2853.  
  2854. function fixSegments(ytObj) {
  2855. let a, b;
  2856. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  2857. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  2858. translateFn = translateFn || getTranslate();
  2859. let cSeg;
  2860. cSeg = wmx.get(seg);
  2861. if (!cSeg) {
  2862. let vSeg = null;
  2863. try {
  2864. vSeg = translateFn(seg);
  2865. } catch (e) {
  2866. }
  2867. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  2868. // console.log('translated', vSeg);
  2869. cSeg = vSeg;
  2870. wmx.set(seg, cSeg);
  2871. wmx.set(cSeg, cSeg);
  2872. }
  2873. }
  2874. if (cSeg && cSeg !== seg) {
  2875. a[b] = cSeg;
  2876. }
  2877. }
  2878.  
  2879. const dfn = Symbol();
  2880. const Object_ = Object;
  2881. Object_[dfn] = Object_.defineProperties;
  2882. let activation = true;
  2883. Object_.defineProperties = function (obj, pds) {
  2884. let segments, get_;
  2885. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  2886. activation = false;
  2887. segments.get = function () {
  2888. fixSegments(this);
  2889. return get_.call(this);
  2890. };
  2891. }
  2892. return Object_[dfn](obj, pds);
  2893. };
  2894.  
  2895. })();
  2896.  
  2897.  
  2898. let pf31 = new PromiseExternal();
  2899.  
  2900. // native RAF
  2901. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  2902.  
  2903. // 1st wrapped RAF
  2904. const baseRAF = (callback) => {
  2905. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  2906. pf31.then(() => {
  2907. callback(hRes);
  2908. });
  2909. });
  2910. };
  2911.  
  2912. // 2nd wrapped RAF
  2913. window.requestAnimationFrame = baseRAF;
  2914.  
  2915. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  2916. const indr = o => insp(o).$ || o.$ || 0;
  2917.  
  2918. const prototypeInherit = (d, b) => {
  2919. const m = Object.getOwnPropertyDescriptors(b);
  2920. for (const p in m) {
  2921. if (!Object.getOwnPropertyDescriptor(d, p)) {
  2922. Object.defineProperty(d, p, m[p]);
  2923. }
  2924. }
  2925. };
  2926.  
  2927.  
  2928. const firstObjectKey = (obj) => {
  2929. for (const key in obj) {
  2930. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  2931. }
  2932. return null;
  2933. };
  2934.  
  2935. function searchNestedObject(obj, predicate, maxDepth = 64) {
  2936. // normal case: depth until 36
  2937. const result = [];
  2938. const visited = new WeakSet();
  2939.  
  2940. function search(obj, depth) {
  2941. visited.add(obj);
  2942. for (const [key, value] of Object.entries(obj)) {
  2943. // Recursively search nested objects and arrays
  2944. if (value !== null && typeof value === 'object') {
  2945. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  2946. if (depth + 1 <= maxDepth && !visited.has(value)) {
  2947. search(value, depth + 1);
  2948. }
  2949. } else if (predicate(value)) {
  2950. result.push([obj, key]);
  2951. }
  2952. }
  2953. }
  2954.  
  2955. typeof (obj || 0) === 'object' && search(obj, 0);
  2956. return result;
  2957. }
  2958.  
  2959. /** @type {(o: Object | null) => WeakRef | null} */
  2960. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  2961.  
  2962. /** @type {(wr: Object | null) => Object | null} */
  2963. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  2964.  
  2965. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  2966.  
  2967. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  2968. if (DENY_requestStorageAccess) {
  2969. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  2970. Document.prototype.requestStorageAccessFor = undefined;
  2971. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  2972. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  2973. Document.prototype.requestStorageAccessFor = function () {
  2974. return new Promise((resolve, reject) => {
  2975. reject();
  2976. });
  2977. };
  2978. }
  2979. }
  2980.  
  2981. const traceStack = (stack) => {
  2982. let result = new Set();
  2983. let p = new Set();
  2984. let u = ''
  2985. for (const s of stack.split('\n')) {
  2986. if (s.split(':').length < 3) continue;
  2987. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  2988. if (!m) continue;
  2989. p.add(m[2]);
  2990. if (p.size >= 3) break;
  2991. if(!u) u = m[2];
  2992. else if(p.size === 2 && u && u=== m[2]) break;
  2993. result.add(s);
  2994. }
  2995. return [...result].join('\n');
  2996. }
  2997.  
  2998. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  2999. // window.m3bb = new Set();
  3000.  
  3001. // const smb = Symbol();
  3002. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  3003. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  3004. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  3005.  
  3006. const thisConversionFn = (thisArg) => {
  3007. if (!thisArg) return null;
  3008. const kThis = thisArg[vmb];
  3009. if (kThis) {
  3010. const ref = kThis.ref;
  3011. return (ref ? kRef(ref) : null) || null;
  3012. }
  3013. return thisArg;
  3014. }
  3015.  
  3016. const pFnHandler2 = {
  3017. get(target, prop) {
  3018. if (prop === vmc) return target;
  3019. return Reflect.get(target, prop);
  3020. },
  3021. apply(target, thisArg, argumentsList) {
  3022. thisArg = thisConversionFn(thisArg);
  3023. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  3024. }
  3025. }
  3026.  
  3027.  
  3028. const proxySelfHandler = {
  3029. get(target, prop) {
  3030. if(prop === vmb) return target;
  3031. const ref = target.ref;
  3032. const cnt = kRef(ref);
  3033. if (!cnt) return;
  3034. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  3035. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  3036. return cnt[prop][vmd];
  3037. }
  3038. return cnt[prop];
  3039. },
  3040. set(target, prop, value) {
  3041. const cnt = kRef(target.ref);
  3042. if (!cnt) return true;
  3043. if(value && (value[vmc] || value[vmb])){
  3044. cnt[prop] = value[vmc] || thisConversionFn(value);
  3045. return true;
  3046. }
  3047. cnt[prop] = value;
  3048. return true;
  3049. }
  3050. };
  3051.  
  3052. const weakWrap = (thisArg) => {
  3053. thisArg = thisConversionFn(thisArg);
  3054. if (!thisArg) {
  3055. console.error('thisArg is not found');
  3056. return null;
  3057. }
  3058. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  3059. }
  3060.  
  3061. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  3062. window.getComputedStyle533 = window.getComputedStyle;
  3063. window.getComputedStyle = function (a, ...args) {
  3064. a = thisConversionFn(a);
  3065. if (a) {
  3066. return getComputedStyle533(a, ...args);
  3067. }
  3068. return null;
  3069. }
  3070. }
  3071.  
  3072. Function._count_bind_00 = 0;
  3073. // Function._count_bind_01 = 0;
  3074.  
  3075. // let matchNativeCode = (Object+"");
  3076. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  3077. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  3078.  
  3079. // const matchConstructor = (thisArg) => {
  3080. // const f = `${(thisArg || 0).constructor}`;
  3081. // if (f.length > 45) return true;
  3082. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  3083. // if (f.includes('[native code]')){
  3084. // return false;
  3085. // }
  3086. // return true;
  3087. // }
  3088. // return false;
  3089. // }
  3090.  
  3091. // const acceptThis = (thisArg)=>{
  3092. // // if(!thisArg || typeof thisArg !=='object') return false;
  3093. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  3094. // // if(typeof thisArg.path === 'string') return true;
  3095. // // if(typeof thisArg.fn === 'function') return true;
  3096. // // if(typeof thisArg.id === 'string') return true;
  3097. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  3098. // return false;
  3099. // }
  3100.  
  3101. const patchFn = (fn) => {
  3102.  
  3103. let s = `${fn}`;
  3104. if (s.length < 11 || s.includes('\n')) return false;
  3105. if(s.includes('bind(this')) return true;
  3106. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  3107. // var a=this;
  3108. // f.bind(this)
  3109.  
  3110.  
  3111. return false;
  3112. }
  3113.  
  3114. Function.prototype.bind488 = Function.prototype.bind;
  3115. Function.prototype.bind = function(thisArg, ...args){
  3116.  
  3117. if (thisConversionFn(thisArg) !== thisArg) {
  3118. return this.bind488(thisArg, ...args);
  3119. }
  3120. if( thisArg && patchFn(this) ){
  3121.  
  3122. // console.log(599,`${this}`)
  3123.  
  3124. try {
  3125. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  3126. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  3127. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  3128. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  3129. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  3130. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  3131. // // let b4 = false;
  3132. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  3133.  
  3134. // // b3 = false;
  3135. // // b4 = false;
  3136. // // b5 = false;
  3137.  
  3138. // if (b1 || b2 || b3 ||b4 ) {
  3139. const f = this;
  3140. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  3141. if (ps && ps[vmb]) {
  3142. Function._count_bind_00++;
  3143. return f.bind488(ps, ...args)
  3144. }
  3145. // }
  3146. } catch (e) {
  3147. console.warn(e)
  3148. }
  3149. }
  3150. return this.bind488(thisArg, ...args);
  3151. }
  3152. Function.prototype.bind588 = 1;
  3153. }
  3154.  
  3155. const ytSchedulerMethods = {
  3156. addJob(a, b, c) {
  3157. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3158. if (instance) {
  3159. return instance.addJob(a, b, c);
  3160. } else {
  3161. return setTimeout(a, c);
  3162. }
  3163. },
  3164. addImmediateJob(a) {
  3165. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3166. if (instance) {
  3167. return instance.addImmediateJob(a);
  3168. } else {
  3169. a();
  3170. }
  3171. },
  3172. cancelJob(id) {
  3173. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3174. if (instance) {
  3175. return instance.cancelJob(id);
  3176. } else {
  3177. return clearTimeout(id);
  3178. }
  3179. }
  3180. };
  3181.  
  3182. if (FIX_ytScheduler) {
  3183.  
  3184. let ytSchedulerFixed = 0;
  3185. // let ytActioned = false;
  3186. // let pr = new PromiseExternal();
  3187.  
  3188. // const hn = function () {
  3189.  
  3190. // document.removeEventListener('yt-action', hn, true);
  3191. // nextBrowserTick_(() => {
  3192. // ytActioned = true;
  3193. // pr.resolve();
  3194. // });
  3195.  
  3196. // }
  3197. // document.addEventListener('yt-action', hn, true);
  3198.  
  3199. // let cancelStore = {}; // tbc
  3200.  
  3201. // yt.scheduler.instance.addJob
  3202. const fixAddJob = (nv) => {
  3203.  
  3204. /*
  3205. function Z() {
  3206. var a = w("ytglobal.schedulerInstanceInstance_");
  3207. if (!a || a.s)
  3208. a = new M(I("scheduler") || {}),
  3209. x("ytglobal.schedulerInstanceInstance_", a);
  3210. return a
  3211. }
  3212. */
  3213.  
  3214. /*
  3215. function R(a, b, c, d) {
  3216. ++a.D;
  3217. if (c === 10)
  3218. return P(a, b),
  3219. a.D;
  3220. var e = a.D;
  3221. a.h[e] = b;
  3222. a.l && !d ? a.u.push({
  3223. id: e,
  3224. priority: c
  3225. }) : (a.i[c].push(e),
  3226. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  3227. a.start()));
  3228. return e
  3229. }
  3230. */
  3231.  
  3232. /*
  3233. function sa(a, b, c) {
  3234. if (!c)
  3235. return c = c === void 0,
  3236. -R(Z(), a, b, c);
  3237. var d = window.setTimeout(function() {
  3238. var e = R(Z(), a, b);
  3239. W[d] = e
  3240. }, c);
  3241. return d
  3242. }
  3243. */
  3244. window.originalAddJob = nv;
  3245. // const q1 = new PromiseExternal();
  3246. // const q2 = new PromiseExternal();
  3247. // let uu = 0;
  3248. // let q3 = 0;
  3249. // let mof = null;
  3250. // const mo = new MutationObserver((mutation, observer) => {
  3251. // if (mof) {
  3252. // if (mof() === true) {
  3253. // observer.disconnect();
  3254. // mof = null;
  3255. // }
  3256. // }
  3257. // });
  3258.  
  3259. let lenSkip = -1;
  3260. let lastLen = null;
  3261. let fetchCommentJobTimerId = 0;
  3262. let requestFinish = false;
  3263.  
  3264. const fetchCommentJobDone = ()=>{
  3265. clearInterval(fetchCommentJobTimerId);
  3266. fetchCommentJobTimerId = 0;
  3267. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3268. }
  3269.  
  3270. const fetchCommentJob = (a, cid) => {
  3271.  
  3272. // if (cid && cancelStore[cid]) return; // tbc
  3273.  
  3274. if(fetchCommentJobTimerId > 0){
  3275. fetchCommentJobDone();
  3276. }
  3277.  
  3278. // if (mof) {
  3279. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3280. // mof = null;
  3281. // }
  3282.  
  3283. let f = a;
  3284.  
  3285. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  3286.  
  3287. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  3288.  
  3289. lastLen = -1;
  3290. let u = 0;
  3291. let g = () => {
  3292. if (requestFinish) lastLen = -1;
  3293. const lastLen_ = lastLen;
  3294. const len1 = lastLen = document.querySelectorAll(selector).length;
  3295. let mm = true;
  3296. let ff = false;
  3297. if (len1 !== lastLen_) {
  3298. u = 0;
  3299. f();
  3300. const len2 = lastLen = document.querySelectorAll(selector).length;
  3301. if (len2 !== len1) {
  3302. ff = true;
  3303. mm = false;
  3304. }
  3305. }
  3306. if (mm) {
  3307. ++u;
  3308. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  3309. ff = true;
  3310. }
  3311. }
  3312.  
  3313. if (requestFinish) {
  3314. requestFinish = false;
  3315. fetchCommentJobDone();
  3316. } else if (ff){
  3317. fetchCommentJobDone();
  3318. }
  3319.  
  3320. }
  3321.  
  3322.  
  3323. fetchCommentJobTimerId = setInterval(g, 80);
  3324. // g(9);
  3325. // if (lastLen === lenSkip) {
  3326. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3327. // g = f = null;
  3328. // return;
  3329. // }
  3330. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3331. // const q1 = lastLen;
  3332. // mof = () => {
  3333. // const q2 = document.querySelectorAll(selector).length;
  3334. // if (q1 === q2) return;
  3335. // fetchCommentJobTimerId = setTimeout(g, 80);
  3336. // g = null;
  3337. // return true;
  3338. // }
  3339. // mo.observe(document, { childList: true, subtree: true });
  3340.  
  3341. }
  3342.  
  3343. // let pr72 = Promise.resolve();
  3344.  
  3345.  
  3346. let qa = null;
  3347. let qasf = '';
  3348.  
  3349.  
  3350. document.addEventListener("fullscreenchange", (evt) => {
  3351. if (evt.isTrusted !== true) return;
  3352. if (qa) {
  3353. // qa();
  3354. nextBrowserTick_(qa);
  3355. }
  3356. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3357. // pr72 = pr72.then(() => {
  3358. // return pr
  3359. // });
  3360. }, true);
  3361.  
  3362. window.addEventListener("resize", (evt) => {
  3363. if (evt.isTrusted !== true) return;
  3364. if (qa) {
  3365. // qa();
  3366. nextBrowserTick_(qa);
  3367. }
  3368. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3369. // pr72 = pr72.then(() => {
  3370. // return pr
  3371. // });
  3372. }, true);
  3373.  
  3374.  
  3375. setInterval(() => {
  3376. const f = qa;
  3377. if (typeof f !== 'function') return;
  3378. qa = null;
  3379. // pr72 = pr72.then(() => {
  3380. // f();
  3381. // });
  3382. // nextBrowserTick_(()=>{
  3383. f();
  3384. // });
  3385. }, 475.25);
  3386.  
  3387.  
  3388.  
  3389. return function (a, b, c) {
  3390.  
  3391.  
  3392. const f = a;
  3393. // const g = ()=>{
  3394. // pr72 = pr72.then(()=>{
  3395. // f();
  3396. // });
  3397. // }
  3398.  
  3399. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  3400.  
  3401. const c_ = c;
  3402.  
  3403. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  3404.  
  3405. if (b === 1 && c_ === 500) {
  3406. const sf = `${a}`;
  3407. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  3408. qasf = sf;
  3409. qa = a;
  3410. // console.log(12883, a)
  3411. return nv(() => {
  3412. if (qa === a) {
  3413. qa = null;
  3414. a();
  3415. }
  3416. }, b, c);
  3417. }
  3418. }
  3419.  
  3420.  
  3421. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  3422. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  3423. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3424. // pr72 = pr72.then(() => {
  3425. // return pr
  3426. // });
  3427. // try {
  3428. // yt.scheduler.instance.cancelAllJobs();
  3429. // yt.scheduler.instance.dispose();
  3430. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  3431. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  3432. // } catch (e) { }
  3433. return nv(f, b, c);
  3434. }
  3435.  
  3436. // if(!b && c > 50) c = 50;
  3437. // console.log(58372,a,b,c)
  3438. // function(){xxx(xxx)}
  3439. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  3440.  
  3441. /*
  3442.  
  3443. V.setCommentsJobId = _.et(_.r0, function() {
  3444. F5V(V)
  3445. }, 1E3)
  3446.  
  3447. */
  3448.  
  3449. requestFinish = false;
  3450. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  3451.  
  3452. // lastLen = null;
  3453. fetchCommentJob(a, cid);
  3454.  
  3455. // queueMicrotask_(a);
  3456. // nextBrowserTick_(a);
  3457. // a(); // no need to delay
  3458. return cid
  3459.  
  3460. // return nv(a, b, 1.125);
  3461. // const cid = window.setTimeout(() => {
  3462. // nextBrowserTick_(() => {
  3463. // if (cancelStore[cid]) {
  3464. // console.log('task cancelled');
  3465. // return;
  3466. // }
  3467. // a();
  3468.  
  3469. // });
  3470. // }, 0.125);
  3471. // return cid;
  3472. } else {
  3473.  
  3474.  
  3475.  
  3476. return nv(f,b,c);
  3477.  
  3478.  
  3479. // if (c > 2400) c = 2400;
  3480. // else if (c > 800) c = 800;
  3481. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  3482. // if (0 && ytActioned && !b) {
  3483. // const cid = window.setTimeout(() => {
  3484. // nextBrowserTick_(() => {
  3485. // if (cancelStore[cid]) {
  3486. // console.log('task cancelled');
  3487. // return;
  3488. // }
  3489. // a();
  3490. // });
  3491. // }, c);
  3492. // return cid;
  3493. // } else {
  3494. // return nv(a, b, c);
  3495. // }
  3496.  
  3497. }
  3498. }
  3499. }
  3500.  
  3501. const fixCancelJob = (nv) => {
  3502.  
  3503.  
  3504. window.originalCancelJob = nv;
  3505. return function (a) {
  3506. if (a < 0) return nv(a);
  3507. // cancelStore[a] = true; // tbc
  3508. nv(a);
  3509. }
  3510. }
  3511.  
  3512. const sk44 = Symbol();
  3513. Object.defineProperty(Object.prototype, 'addJob', {
  3514. get() {
  3515. return this[sk44];
  3516. },
  3517. set(nv) {
  3518. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3519. ytSchedulerFixed |= 1;
  3520. nv = fixAddJob(nv);
  3521. }
  3522. this[sk44] = nv;
  3523. return true;
  3524. },
  3525. enumerable: false,
  3526. configurable: true
  3527. });
  3528.  
  3529.  
  3530.  
  3531. const sk45 = Symbol();
  3532. Object.defineProperty(Object.prototype, 'cancelJob', {
  3533. get() {
  3534. return this[sk45];
  3535. },
  3536. set(nv) {
  3537. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3538. ytSchedulerFixed |= 2;
  3539. nv = fixCancelJob(nv);
  3540. }
  3541. this[sk45] = nv;
  3542. return true;
  3543. },
  3544. enumerable: false,
  3545. configurable: true
  3546. });
  3547.  
  3548.  
  3549.  
  3550. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3551. const { addJob, cancelJob } = yt.scheduler.instance;
  3552. if (addJob) {
  3553. yt.scheduler.instance.addJob = null;
  3554. yt.scheduler.instance.addJob = addJob;
  3555. }
  3556. if (cancelJob) {
  3557. yt.scheduler.instance.cancelJob = null;
  3558. yt.scheduler.instance.cancelJob = cancelJob;
  3559. }
  3560. }
  3561.  
  3562.  
  3563. }
  3564.  
  3565.  
  3566. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  3567. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  3568. const wm6 = new WeakMapOriginal();
  3569.  
  3570. const skipW = new WeakSet();
  3571.  
  3572.  
  3573. window.WeakMap = class WeakMap extends WeakMapOriginal {
  3574. constructor(iterable = undefined) {
  3575. super();
  3576. if (iterable && iterable[Symbol.iterator]) {
  3577. for (const entry of iterable) {
  3578. entry && this.set(entry[0], entry[1]);
  3579. }
  3580. }
  3581. }
  3582. delete(a) {
  3583. if (!this.has(a)) return false;
  3584. super.delete(a);
  3585. return true;
  3586. }
  3587. get(a) {
  3588. const p = super.get(a);
  3589. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  3590. let v = kRef(p);
  3591. if (!v) {
  3592. super.delete(a);
  3593. }
  3594. return v || undefined;
  3595. }
  3596. return p;
  3597. }
  3598. has(a) {
  3599. if (!super.has(a)) return false;
  3600. const p = super.get(a);
  3601. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  3602. if (!kRef(p)) {
  3603. super.delete(a);
  3604. return false;
  3605. }
  3606. }
  3607. return true;
  3608. }
  3609. set(a, b) {
  3610. let wq = b;
  3611. if (b && (typeof b === 'function' || typeof b === 'object')) {
  3612. if (b.deref) {
  3613. skipW.add(b);
  3614. wq = b;
  3615. } else {
  3616. wq = wm6.get(b);
  3617. if (!wq) {
  3618. wq = mWeakRef(b);
  3619. wm6.set(b, wq);
  3620. }
  3621. }
  3622. }
  3623. super.set(a, wq);
  3624. return this;
  3625. }
  3626. }
  3627. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  3628. configurable: true,
  3629. enumerable: false,
  3630. value: "WeakMap",
  3631. writable: false
  3632. });
  3633. }
  3634.  
  3635. const isWatchPageURL = (url) => {
  3636. url = url || location;
  3637. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  3638. };
  3639.  
  3640. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3641.  
  3642. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  3643. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3644. if (typeof customElements === 'undefined') {
  3645. if (!('__CE_registry' in document)) {
  3646. // https://github.com/webcomponents/polyfills/
  3647. Object.defineProperty(document, '__CE_registry', {
  3648. get() {
  3649. // return undefined
  3650. },
  3651. set(nv) {
  3652. if (typeof nv == 'object') {
  3653. delete this.__CE_registry;
  3654. this.__CE_registry = nv;
  3655. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3656. }
  3657. return true;
  3658. },
  3659. enumerable: false,
  3660. configurable: true
  3661. })
  3662. }
  3663. let eventHandler = (evt) => {
  3664. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3665. const f = callback;
  3666. callback = null;
  3667. eventHandler = null;
  3668. f();
  3669. };
  3670. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3671. } else {
  3672. callback();
  3673. }
  3674. });
  3675.  
  3676. const whenCEDefined = isCustomElementsProvided
  3677. ? (nodeName) => customElements.whenDefined(nodeName)
  3678. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3679.  
  3680. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  3681. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  3682. const f = performance.now23 = Performance.prototype.now;
  3683.  
  3684. let k = 0; // 0 <= k < 9998m
  3685. let u = 0;
  3686. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  3687.  
  3688. // By definition, performance.now() is mono increasing.
  3689. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  3690. performance.now = performance.now16 = function () {
  3691. /**
  3692. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  3693. *
  3694. * If consecutive session history entries had history.state.entryTime set to same value,
  3695. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  3696. * and modifying its return value slightly to make sure two close consecutive calls don't
  3697. * get the same result helped with resolving the issue.
  3698. */
  3699. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  3700. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  3701.  
  3702. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  3703. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  3704. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  3705. else { // more than 9998 consecutive calls
  3706. /**
  3707. *
  3708. * max no. of consecutive calls
  3709. *
  3710. * Sample Size: 4800
  3711. * Sample Avg = 1565.375
  3712. * Sample Median = 1469.5
  3713. * Sample Max = 5660 << 7500 << 9999
  3714. *
  3715. *
  3716. * */
  3717. k = 0;
  3718. s += 1 / 7;
  3719. }
  3720. return v + k; // 0 < v - M < v - M + k < v
  3721. }
  3722.  
  3723. let loggerMsg = '';
  3724. if (`${performance.now()}` === `${performance.now()}`) {
  3725. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  3726. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  3727. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  3728. }
  3729. loggerMsg && console.warn(loggerMsg);
  3730. })();
  3731.  
  3732. // let __forceRemoveMode__ = false;
  3733. FIX_removeChild && (() => {
  3734. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  3735. let internalByPass = false;
  3736. const fragD = document.createDocumentFragment();
  3737. fragD.appendChild4201 = fragD.appendChild;
  3738. fragD.removeChild4201 = fragD.removeChild;
  3739. Node.prototype.removeChild062 = Node.prototype.removeChild;
  3740. Node.prototype.removeChild = function (child) {
  3741. try {
  3742. return this.removeChild062(child);
  3743. } catch (e) { }
  3744. if (internalByPass) return child;
  3745. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  3746. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3747. if (idx >= 0) {
  3748. internalByPass = true;
  3749. child.parentNode !== fragD && fragD.appendChild4201(child);
  3750. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3751. fragD.removeChild4201(child);
  3752. internalByPass = false;
  3753. return child;
  3754. }
  3755. }
  3756. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  3757. // // force removal
  3758. // internalByPass = true;
  3759. // child.parentNode !== fragD && fragD.appendChild4201(child);
  3760. // fragD.removeChild4201(child);
  3761. // internalByPass = false;
  3762. // return child;
  3763. // }
  3764. if (this && child) {
  3765. if (this.childNodes && this.childNodes.splice) { // tbc
  3766. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3767. if (idx >= 0) {
  3768. internalByPass = true;
  3769. child.parentNode !== fragD && fragD.appendChild4201(child);
  3770. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3771. fragD.removeChild4201(child);
  3772. internalByPass = false;
  3773. return child;
  3774. }
  3775. }
  3776.  
  3777. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  3778. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  3779. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  3780. return child;
  3781. }
  3782. }
  3783.  
  3784. if (child && child.is === 'tp-yt-paper-tooltip' && !child.parentNode && !child.__shady_parentNode) {
  3785. // skip
  3786. return child;
  3787. }
  3788.  
  3789. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  3790. parent: this, child: child,
  3791. isParent: child.parentNode === this,
  3792. isParentParent: (child.parentNode || 0).parentNode === this,
  3793. parentNode: child.parentNode,
  3794. shadyParent: child.__shady_parentNode,
  3795. isShadyParent: child.__shady_parentNode === this,
  3796. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  3797. });
  3798.  
  3799. }
  3800. return child;
  3801. }
  3802. }
  3803. })();
  3804.  
  3805.  
  3806. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  3807.  
  3808. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  3809.  
  3810. // let cid = 0;
  3811.  
  3812. let mousemoveFn = null;
  3813. let mousemoveDT = 0;
  3814. let mousemoveCount = 0;
  3815. // let qv = false;
  3816. const cif = () => {
  3817. if (!mousemoveFn) return;
  3818. const ct = Date.now();
  3819. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  3820. mousemoveFn && mousemoveFn();
  3821. }
  3822. mousemoveFn = null;
  3823. };
  3824. let mousemoveCId = 0;
  3825. let mouseoverFn = null;
  3826. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  3827. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  3828. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  3829. const bt = `${b}`;
  3830. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  3831. b[`__$$${a}$$1926__`] = true;
  3832. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  3833. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  3834. // console.log(3928, a, this[`__$$${a}$$1937__`])
  3835. if (!this[`__$$${a}$$1938__`]) {
  3836. this[`__$$${a}$$1938__`] = b;
  3837. if (a === 'mousemove') {
  3838. this.addEventListener4882('mouseenter', (evt) => {
  3839. if (mousemoveCId) return;
  3840. mousemoveCId = setIntervalX0(cif, 380);
  3841. });
  3842. this.addEventListener4882('mouseleave', (evt) => {
  3843. clearIntervalX0(mousemoveCId);
  3844. mousemoveCId = 0;
  3845. });
  3846. }
  3847. this.addEventListener4882(a, (evt) => {
  3848. const evt_ = evt;
  3849. if (!this[`__$$${a}$$1937__`]) return;
  3850. if (!this[`__$$${a}$$1938__`]) return;
  3851. if (a === 'mousemove') {
  3852. mouseoverFn && mouseoverFn();
  3853. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  3854. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  3855. } else {
  3856. mousemoveCount = 0;
  3857. }
  3858. const f = mousemoveFn = () => {
  3859. if (f !== mousemoveFn) return;
  3860. mousemoveFn = null;
  3861. this[`__$$${a}$$1938__`](evt_);
  3862. };
  3863. if (mousemoveCount <= 1) mousemoveFn();
  3864. } else {
  3865. if (a === 'mouseout' || a === 'mouseleave') {
  3866. mousemoveFn = null;
  3867. mousemoveDT = 0;
  3868. mousemoveCount = 0;
  3869. this[`__$$${a}$$1938__`](evt_);
  3870. mouseoverFn && mouseoverFn();
  3871. } else { // mouseover, mouseenter
  3872. mousemoveFn = null;
  3873. mousemoveDT = 0;
  3874. mousemoveCount = 0;
  3875. mouseoverFn && mouseoverFn(); // just in case
  3876. const f = mouseoverFn = () => {
  3877. if (f !== mouseoverFn) return;
  3878. mouseoverFn = null;
  3879. this[`__$$${a}$$1938__`](evt_);
  3880. }
  3881. nextBrowserTick_(mouseoverFn);
  3882. }
  3883. }
  3884. }, c);
  3885.  
  3886.  
  3887. return;
  3888. } else {
  3889.  
  3890. return;
  3891. }
  3892. }
  3893.  
  3894. }
  3895. return this.addEventListener4882(a, b, c)
  3896. }
  3897.  
  3898.  
  3899.  
  3900.  
  3901. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  3902. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  3903. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  3904.  
  3905. if (b[`__$$${a}$$1926__`]) {
  3906. b[`__$$${a}$$1926__`] = false;
  3907.  
  3908. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  3909.  
  3910. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  3911.  
  3912. return;
  3913.  
  3914. }
  3915.  
  3916. }
  3917. return this.removeEventListener4882(a, b, c)
  3918. }
  3919.  
  3920.  
  3921. })();
  3922.  
  3923.  
  3924. FIX_DOM_IF_REPEAT && (() => {
  3925. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  3926. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  3927. // Be careful of the mixture of polymer functions and native Element functions
  3928. // Be careful of the coding design is different with the modern Yt elements
  3929.  
  3930.  
  3931. /*
  3932.  
  3933.  
  3934. function Ks(a, b, c) {
  3935. if (kj && !BOa(a))
  3936. throw Error("strictTemplatePolicy: template owner not trusted");
  3937. c = c || {};
  3938. if (a.__templatizeOwner)
  3939. throw Error("A <template> can only be templatized once");
  3940. a.__templatizeOwner = b;
  3941. var d = (b ? b.constructor : Js)._parseTemplate(a)
  3942. , e = d.templatizeInstanceClass;
  3943. e || (e = COa(a, d, c),
  3944. d.templatizeInstanceClass = e);
  3945. var g = BOa(a);
  3946. EOa(a, d, c, g);
  3947. c = function() {
  3948. return e.apply(this, arguments) || this
  3949. }
  3950. ;
  3951. h(c, e);
  3952. c.prototype._methodHost = g;
  3953. c.prototype.__dataHost = a;
  3954. c.prototype.__templatizeOwner = b;
  3955. c.prototype.__hostProps = d.hostProps;
  3956. return c
  3957. }
  3958.  
  3959. */
  3960.  
  3961. // Polymer.enqueueDebouncer
  3962.  
  3963. const s81 = Symbol();
  3964. const s83 = Symbol();
  3965. const s84 = Symbol();
  3966. const s85 = Symbol();
  3967. const s85b = Symbol();
  3968. const s85c = Symbol();
  3969.  
  3970. let renderDebounceTs = null;
  3971.  
  3972. let renderDebouncePromise = null;
  3973. let qp;
  3974.  
  3975. let cme = 0;
  3976.  
  3977. const shadyFlushMO = new MutationObserver(() => {
  3978.  
  3979. if (!renderDebounceTs) return;
  3980.  
  3981. if (renderDebounceTs.size > 0) {
  3982. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  3983. try {
  3984. Polymer.flush();
  3985. return;
  3986. } catch (e) { }
  3987. }
  3988.  
  3989. renderDebouncePromise && Promise.resolve().then(() => {
  3990.  
  3991. if (renderDebouncePromise) {
  3992. renderDebouncePromise && renderDebouncePromise.resolve();
  3993. renderDebouncePromise = null;
  3994. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  3995. }
  3996.  
  3997. });
  3998.  
  3999. // Polymer.flush
  4000.  
  4001. window.ShadyDOM && ShadyDOM.flush();
  4002. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  4003.  
  4004.  
  4005. });
  4006.  
  4007. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  4008.  
  4009.  
  4010. let p = 0;
  4011. qp = observablePromise(() => {
  4012. if (!(p & 1)) {
  4013.  
  4014. if (window.ShadyDOM && ShadyDOM.flush) {
  4015. p |= 1;
  4016. if (!ShadyDOM.flush847) {
  4017.  
  4018. ShadyDOM.flush847 = ShadyDOM.flush;
  4019. ShadyDOM.flush = function () {
  4020.  
  4021. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  4022. renderDebouncePromise && Promise.resolve().then(() => {
  4023. if (renderDebouncePromise) {
  4024.  
  4025. renderDebouncePromise && renderDebouncePromise.resolve();
  4026. renderDebouncePromise = null;
  4027.  
  4028. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  4029.  
  4030. }
  4031.  
  4032. });
  4033. let r = this.flush847(...arguments);
  4034. if (r) {
  4035. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  4036. }
  4037. return r
  4038. }
  4039.  
  4040. }
  4041. }
  4042. }
  4043.  
  4044. if (!(p & 2)) {
  4045.  
  4046. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  4047. p |= 2;
  4048. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  4049. if (!ScopingShim.flush848) {
  4050.  
  4051. ScopingShim.flush848 = ScopingShim.flush;
  4052. ScopingShim.flush = function () {
  4053.  
  4054. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  4055.  
  4056. renderDebouncePromise && Promise.resolve().then(() => {
  4057.  
  4058. if (renderDebouncePromise) {
  4059.  
  4060. renderDebouncePromise && renderDebouncePromise.resolve();
  4061. renderDebouncePromise = null;
  4062.  
  4063. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  4064.  
  4065.  
  4066.  
  4067. }
  4068.  
  4069. });
  4070. return this.flush848(...arguments);
  4071. }
  4072.  
  4073. }
  4074. }
  4075. }
  4076. if (p === 3) {
  4077. p |= 8;
  4078.  
  4079. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  4080. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  4081. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  4082.  
  4083. if (r) {
  4084. let w = Set.prototype.add;
  4085. let u = null;
  4086. Set.prototype.add = function () {
  4087. u = this;
  4088. throw new Error();
  4089. }
  4090. try {
  4091. Polymer.enqueueDebouncer()
  4092. } catch (e) { }
  4093. Set.prototype.add = w;
  4094. if (u !== null) {
  4095. renderDebounceTs = u;
  4096. if (DEBUG_renderDebounceTs) {
  4097. renderDebounceTs.add58438 = renderDebounceTs.add;
  4098. renderDebounceTs.add = function () {
  4099. console.log('renderDebounceTs.add')
  4100. console.log(traceStack((new Error()).stack))
  4101. // debugger;
  4102. return this.add58438(...arguments)
  4103. }
  4104.  
  4105. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  4106. renderDebounceTs.delete = function () {
  4107. console.log('renderDebounceTs.delete')
  4108. const stack = `${(new Error()).stack}`
  4109. let isCallbackRemoval = false;
  4110. if (stack) {
  4111. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  4112. const s = t.split(':');
  4113. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  4114. isCallbackRemoval = true;
  4115. }
  4116. }
  4117. if (isCallbackRemoval) {
  4118. return this.delete58438(...arguments)
  4119. }
  4120. console.log(traceStack((new Error()).stack))
  4121. // debugger;
  4122. return this.delete58438(...arguments)
  4123. }
  4124. }
  4125. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  4126. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  4127. }
  4128. }
  4129.  
  4130. return true;
  4131. }
  4132. })
  4133.  
  4134. // if(window.ShadyDOM && ShadyDOM.flush){
  4135. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  4136.  
  4137. // }
  4138. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  4139.  
  4140. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  4141. // }
  4142.  
  4143. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  4144.  
  4145. }
  4146.  
  4147. const setupPolymerAdv = () => {
  4148. // here we can obtain the Polymer faster.
  4149. // reserved for future use.
  4150. }
  4151.  
  4152.  
  4153. if (USE_fastDomIf) {
  4154. // 0 = no effect. 1 = enable. 2 = disable
  4155. // fastDomIf because it delayed the rendering process?
  4156. Object.defineProperty(Object.prototype, 'fastDomIf', {
  4157. get() {
  4158. if (this === window.Polymer) {
  4159. const v = USE_fastDomIf === 1 ? true : false;
  4160. this.fastDomIf = v;
  4161. delete Object.prototype.fastDomIf;
  4162. setupPolymerAdv(this);
  4163. return v;
  4164. }
  4165. },
  4166. set(nv) {
  4167. return false;
  4168. }
  4169. });
  4170. }
  4171.  
  4172. let setupDomIfDone = false;
  4173. const setupDomIf = (DomIf)=>{
  4174. setupDomIfDone = true;
  4175. if(setupDomIfDone) return;
  4176.  
  4177. const fProto = DomIf.prototype;
  4178.  
  4179.  
  4180. // Polymer.DomIf
  4181. // Polymer.DomIf = Polymer.fastDomIf ? ZbL : ESz
  4182. // Assume ESz by default
  4183.  
  4184. // We don't need to store "root" in DOM-IF
  4185. if (ENHANCE_DOMIF_createAndInsertInstance && fProto.__createAndInsertInstance && !fProto.__createAndInsertInstance239 && fProto.__createAndInsertInstance.length === 1) {
  4186. fProto.__createAndInsertInstance239 = fProto.__createAndInsertInstance;
  4187. fProto.__createAndInsertInstance = function (M) {
  4188. const r = this.__createAndInsertInstance239(M);
  4189. const __instance = this.__instance;
  4190. const __ctor = this.__ctor;
  4191. if (__instance && __ctor && __instance instanceof __ctor) {
  4192. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4193. const o = __instance[sym];
  4194. if (o && o.nodeType === 11) {
  4195. __instance[sym] = null;
  4196. }
  4197. }
  4198. }
  4199. return r;
  4200. }
  4201.  
  4202. /*
  4203.  
  4204.  
  4205. sX = function(M, d, N) {
  4206. if (o_ && !vDv(M))
  4207. throw Error("Jd");
  4208. N = N || {};
  4209. if (M.__templatizeOwner)
  4210. throw Error("Kd");
  4211. M.__templatizeOwner = d;
  4212. var R = (d ? d.constructor : jF)._parseTemplate(M)
  4213. , X = R.templatizeInstanceClass;
  4214. X || (X = sfi(M, R, N),
  4215. R.templatizeInstanceClass = X);
  4216. var A = vDv(M);
  4217. y9Z(M, R, N, A);
  4218. N = function() {
  4219. return X.apply(this, arguments) || this
  4220. }
  4221. ;
  4222. _.v(N, X);
  4223. N.prototype._methodHost = A;
  4224. N.prototype.__dataHost = M;
  4225. N.prototype.__templatizeOwner = d;
  4226. N.prototype.__hostProps = R.hostProps;
  4227. return N
  4228. }
  4229.  
  4230. */
  4231. }
  4232.  
  4233. // Polymer.DomIf
  4234. // We can fully teardown the entire instance (including stampFrag and stampNodes), just keep ctor stamper
  4235. if (ENHANCE_DOMIF_TEARDOWN && fProto.__teardownInstance && !fProto.__teardownInstance239 && fProto.__teardownInstance.length === 0) {
  4236. fProto.__teardownInstance239 = fProto.__teardownInstance;
  4237. fProto.__teardownInstance = function () {
  4238. const { __instance, __invalidProps } = this;
  4239. let r, e_;
  4240. try {
  4241. r = this.__teardownInstance239();
  4242. } catch (e) { e_ = e }
  4243. if (!__instance) return r;
  4244.  
  4245. try {
  4246.  
  4247. //console.log(599901,this.countEvent767());
  4248. //console.log('__teardownInstance F', __instance, __invalidProps, this._removeEventListenerFromNode, __instance._removeEventListenerFromNode);
  4249. __instance.__data = null;
  4250. __instance.__dataClientsReady = __instance.__dataEnabled = __instance.__dataReady = false;
  4251. __instance.__dataInvalid = true;
  4252. __instance.__dataHost = __instance.__dataTemp = null;
  4253. __instance.__isPropertyEffectsClient = false;
  4254. __instance.__keepInstance038__ = false;
  4255.  
  4256.  
  4257. const __templateInfo = __instance.__templateInfo;
  4258.  
  4259. let stampFragId = null;
  4260. if (__templateInfo && __templateInfo.nodeList) {
  4261. stampFragId = __templateInfo.nodeList.__belongFragId57__;
  4262. for (const weakNodeC of __templateInfo.nodeList) {
  4263. const node = toActualNode(weakNodeC);
  4264. if (node && node.nodeType >= 1) {
  4265. _removedElements.addNode(node);
  4266. node.__keepInstance038__ = false;
  4267. node.remove();
  4268. }
  4269. }
  4270. __templateInfo.nodeList.length = 0;
  4271. __templateInfo.nodeList = null;
  4272. }
  4273.  
  4274. const stampFrag = stampFragId ? kRef(stampedFragment.get(stampFragId)) : null;
  4275.  
  4276. if (stampFrag && stampFrag.nodeType === 11) {
  4277. _removedElements.addNode(stampFrag);
  4278. removeAllChildNodes(stampFrag);
  4279. try {
  4280. stampFrag.__keepInstance038__ = false;
  4281. stampFrag.remove();
  4282. } catch (e) { }
  4283. stampFrag.__shady = null;
  4284. stampFrag.$ = null;
  4285. stampFrag.__fragTeardowned57__ = true;
  4286. stampFrag.nodeList = null;
  4287. stampFrag.templateInfo = null;
  4288.  
  4289. }
  4290.  
  4291. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4292. const o = __instance[sym];
  4293. if (o && o.nodeType === 11) {
  4294. __instance[sym] = null;
  4295. }
  4296. }
  4297.  
  4298. const children = (__instance || 0).children;
  4299. if (children && children.splice) {
  4300. __instance.children = null;
  4301. for (const n of children) {
  4302. if (n && n.nodeType >= 1) {
  4303. n.__keepInstance038__ = false;
  4304. _removedElements.addNode(n);
  4305. }
  4306. }
  4307. children.length = 0;
  4308. }
  4309.  
  4310. if (__instance.__templateInfo) __instance.__templateInfo = null;
  4311.  
  4312. if (__instance.root) __instance.root = null;
  4313.  
  4314. } catch (e) {
  4315. console.error(e);
  4316. }
  4317.  
  4318. // console.log(3882)
  4319. if (e_) throw e_;
  4320. return r;
  4321. }
  4322. }
  4323.  
  4324. }
  4325.  
  4326. if (ENHANCE_DOMIF_createAndInsertInstance || ENHANCE_DOMIF_TEARDOWN) {
  4327.  
  4328. Object.defineProperty(Object.prototype, 'DomIf', {
  4329. get() {
  4330. return undefined;
  4331. },
  4332. set(nv) {
  4333. if (typeof (nv || 0) !== 'function') return false;
  4334. delete Object.prototype.DomIf;
  4335. this.DomIf = nv;
  4336. setupDomIf(nv);
  4337. return true;
  4338. },
  4339. enumerable: false,
  4340. configurable: true
  4341. });
  4342.  
  4343. }
  4344.  
  4345. Object.defineProperty(Object.prototype, '_lastIf', {
  4346. get() {
  4347. return this[s81];
  4348. },
  4349. set(nv) {
  4350. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  4351. // DOM-IF initialization
  4352. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  4353.  
  4354. this.__xiWB8__ = 2;
  4355. // this.restamp = true;
  4356.  
  4357. const cProto = this.__proto__;
  4358. if (cProto && !cProto.__xiWB7__) {
  4359. cProto.__xiWB7__ = 1;
  4360.  
  4361. // dom-if __template
  4362. // dom-repeat template
  4363. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  4364. cProto.__template847 = true;
  4365. try {
  4366. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  4367. Object.defineProperty(cProto, '__template', {
  4368. get() {
  4369. const v = this[s84];
  4370. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  4371. },
  4372. set(nv) {
  4373. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  4374. this[s84] = nv;
  4375. return true;
  4376. }
  4377. });
  4378. } catch (e) {
  4379. console.warn(e);
  4380. }
  4381.  
  4382. console.log('FIX_DOM_IF - __template')
  4383. }
  4384.  
  4385. // dom-if __ensureTemplate
  4386. // dom-repeat __ensureTemplatized
  4387. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  4388. // note that "_templateInfo" diffs the different version of DOM-IF
  4389.  
  4390. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  4391. cProto.__ensureTemplate = function () {
  4392. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  4393. if (!this.__template) {
  4394. let b;
  4395. if (this._templateInfo) {
  4396. b = this;
  4397. } else {
  4398. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  4399. b = this.__templateCollection011__[0];
  4400. if (!b) {
  4401. if (!this[wk]) this[wk] = mWeakRef(this);
  4402. let a = this[wk];
  4403. let c = new MutationObserver(function () {
  4404. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  4405. if (c && a) {
  4406. c.disconnect();
  4407. a = kRef(a);
  4408. a && a.__render();
  4409. a && (a.__templateCollection011__ = null);
  4410. }
  4411. c = null;
  4412. a = null;
  4413. });
  4414. c && c.observe(this, {
  4415. childList: !0
  4416. });
  4417. return !1
  4418. } else {
  4419. this.__templateCollection011__ = null;
  4420. }
  4421. }
  4422. this.__template = b
  4423. }
  4424. return !0
  4425. }
  4426.  
  4427. console.log('FIX_DOM_IF - __ensureTemplate')
  4428.  
  4429. }
  4430. /*
  4431.  
  4432. if (FIX_DOM_IF_TEMPLATE && !cProto.disconnectedCallback847 && cProto.disconnectedCallback && cProto.__teardownInstance) {
  4433. cProto.disconnectedCallback847 = cProto.disconnectedCallback;
  4434. cProto.disconnectedCallback = function () {
  4435.  
  4436. console.log(1949001, 'disconnectedCallback')
  4437. this.disconnectedCallback847();
  4438. try {
  4439. this.__teardownInstance();
  4440. console.log(1949002, '__teardownInstance 00D')
  4441. } catch (e) { }
  4442. }
  4443. }
  4444.  
  4445. if (FIX_DOM_IF_TEMPLATE && !cProto.connectedCallback847 && cProto.connectedCallback && cProto.__teardownInstance) {
  4446. cProto.connectedCallback847 = cProto.connectedCallback;
  4447. cProto.connectedCallback = function () {
  4448.  
  4449. console.log(1949003, 'connectedCallback')
  4450. try {
  4451. this.__teardownInstance();
  4452. console.log(1949004, '__teardownInstance 00C')
  4453. } catch (e) { }
  4454. this.connectedCallback847();
  4455. }
  4456. }
  4457. */
  4458.  
  4459.  
  4460. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  4461.  
  4462. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  4463.  
  4464. // cProto.__createAndInsertInstance = function (a) {
  4465. // Promise.resolve().then(()=>{
  4466. // console.log('__createAndInsertInstance')
  4467. // window.lm5 = window.lm5 || [];
  4468. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  4469. // });
  4470. // return this.__createAndInsertInstance847(a);
  4471. // }
  4472.  
  4473. // }
  4474.  
  4475.  
  4476. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  4477.  
  4478. // cProto._bindTemplate847 = cProto._bindTemplate;
  4479.  
  4480. // cProto._bindTemplate = function (a, b) {
  4481. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  4482. // }
  4483.  
  4484. // }
  4485. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  4486.  
  4487. // cProto._stampTemplate847 = cProto._stampTemplate;
  4488.  
  4489. // cProto._stampTemplate = function (a, b) {
  4490. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  4491. // }
  4492.  
  4493. // }
  4494. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  4495. }
  4496.  
  4497.  
  4498. // need to fix __observeEffects
  4499. // this.__observeEffects.if[0].info.method === this.__debounceRender
  4500. const f = () => {
  4501.  
  4502. const __observeEffects = this.__observeEffects;
  4503.  
  4504. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  4505. for (const effect of __observeEffects.if) {
  4506. const info = effect.info;
  4507. if (info && typeof info.method === 'function') {
  4508.  
  4509. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4510. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4511. }
  4512.  
  4513. }
  4514. }
  4515. }
  4516.  
  4517.  
  4518. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  4519. for (const effect of __observeEffects.restamp) {
  4520. const info = effect.info;
  4521. if (info && typeof info.method === 'function') {
  4522.  
  4523. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4524. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4525. }
  4526.  
  4527. }
  4528. }
  4529. }
  4530.  
  4531. // console.log(5881, this.__observeEffects)
  4532. }
  4533. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  4534. f();
  4535. Promise.resolve().then(f);
  4536. // afterward, don't care adding fn directly (the fn is already modified)
  4537. }
  4538.  
  4539. }
  4540. this[s81] = nv;
  4541. return true;
  4542. }
  4543. });
  4544.  
  4545.  
  4546. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  4547. get() {
  4548. return this[s85];
  4549. },
  4550. set(nv) {
  4551. if (nv === null && this[s85] === undefined) {
  4552. // DOM-IF / DOM-REPEAT initialization
  4553.  
  4554.  
  4555. const cProto = this.__proto__;
  4556. if (qp) {
  4557. qp.obtain();
  4558. qp = null;
  4559. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  4560. }
  4561. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  4562.  
  4563. cProto.__debounceRender847 = cProto.__debounceRender;
  4564.  
  4565. if (cProto.__debounceRender.length === 2) {
  4566.  
  4567. cProto.__debounceRender = function (a, b) {
  4568.  
  4569. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  4570.  
  4571. b = b === void 0 ? 0 : b;
  4572.  
  4573. /*
  4574. b = b === void 0 ? 0 : b;
  4575. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  4576. vs(this.__renderDebouncer)
  4577. */
  4578.  
  4579. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4580.  
  4581. if (!renderDebouncePromise) {
  4582. renderDebouncePromise = new PromiseExternal();
  4583. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  4584. }
  4585.  
  4586. renderDebouncePromise.then(async () => {
  4587. if (b > 0) await delayPn(b);
  4588.  
  4589. const f = this.__dsIRYqw1__;
  4590. if (f === cme) return;
  4591. this.__dsIRYqw1__ = cme;
  4592. a.call(this);
  4593. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  4594.  
  4595. });
  4596.  
  4597. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  4598. }
  4599.  
  4600. } else if (cProto.__debounceRender.length === 0) {
  4601.  
  4602.  
  4603. cProto.__debounceRender = function () {
  4604.  
  4605. if (!renderDebounceTs) return this.__debounceRender847();
  4606.  
  4607. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4608. /*
  4609. var a = this;
  4610. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  4611. return a.__render()
  4612. });
  4613. vs(this.__renderDebouncer)
  4614. */
  4615.  
  4616. if (!renderDebouncePromise) {
  4617. renderDebouncePromise = new PromiseExternal();
  4618. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  4619. }
  4620. renderDebouncePromise.then(() => {
  4621. const f = this.__dsIRYqw1__;
  4622. if (f === cme) return;
  4623. this.__dsIRYqw1__ = cme;
  4624. this.__render()
  4625. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  4626. });
  4627. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  4628.  
  4629.  
  4630. }
  4631. }
  4632. }
  4633.  
  4634.  
  4635.  
  4636. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  4637. // cProto.render847 = cProto.render;
  4638. // cProto.render = function(){
  4639.  
  4640. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4641. // try{
  4642. // this.render847();
  4643. // }catch(e){}
  4644. // // if(this.__DBR847__){
  4645. // // this.__DBR847__.resolve();
  4646. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  4647. // // }
  4648.  
  4649. // // renderDebouncePromise && renderDebouncePromise.resolve()
  4650. // // renderDebouncePromise = null;
  4651. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  4652.  
  4653. // }
  4654. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  4655. // }
  4656.  
  4657. }
  4658. this[s85] = nv;
  4659. return true;
  4660. }
  4661. });
  4662.  
  4663. // PS-DOM-REPEAT
  4664.  
  4665. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  4666. get() {
  4667. return this[s85b];
  4668. },
  4669. set(nv) {
  4670.  
  4671. this[s85b] = nv;
  4672. return true;
  4673. }
  4674. })
  4675.  
  4676. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  4677. get() {
  4678. return this[s85c];
  4679. },
  4680. set(nv) {
  4681.  
  4682. this[s85c] = nv;
  4683. return true;
  4684. }
  4685. })
  4686.  
  4687.  
  4688. })();
  4689.  
  4690. const setupXdeadC = (cnt)=>{
  4691.  
  4692. let xdeadc = xdeadc00;
  4693. if(!xdeadc){
  4694. setupSDomWrapper(); // just in case
  4695. const hostElement = cnt.hostElement;
  4696. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4697. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4698. hostElement.lastChild.replaceWith(el);
  4699. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4700. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4701. el.firstElementChild.id = rid;
  4702. cnt.$[rid] = el.firstElementChild;
  4703. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4704.  
  4705. xdeadc = cnt.getStampContainer_(rid);
  4706. el.remove();
  4707. xdeadc00 = xdeadc;
  4708. // console.log(xdeadc.__domApi)
  4709. // debugger;
  4710. // const xdeadv = xdeadc.__domApi;
  4711. }
  4712.  
  4713. let xlivec = xlivec00;
  4714. if(!xlivec){
  4715. setupSDomWrapper(); // just in case
  4716. const hostElement = cnt.hostElement;
  4717. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4718. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4719. hostElement.lastChild.replaceWith(el);
  4720. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4721. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4722. el.firstElementChild.id = rid;
  4723. cnt.$[rid] = el.firstElementChild;
  4724. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4725.  
  4726. xlivec = cnt.getStampContainer_(rid);
  4727. xlivec00 = xlivec;
  4728. // console.log(xdeadc.__domApi)
  4729. // debugger;
  4730. // const xdeadv = xdeadc.__domApi;
  4731. }
  4732.  
  4733. return xdeadc00;
  4734. }
  4735.  
  4736. let standardWrap_ = null;
  4737.  
  4738. const setupSDomWrapper = () => {
  4739.  
  4740. const sdwProto = ShadyDOM.Wrapper.prototype;
  4741.  
  4742. if (sdwProto.__pseudo__isConnected__ !== null) {
  4743. sdwProto.__pseudo__isConnected__ = null;
  4744. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  4745. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  4746. const get = isConnectedPd.get;
  4747. isConnectedPd.get = function () {
  4748. const pseudoVal = this.__pseudo__isConnected__;
  4749. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  4750. }
  4751. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  4752. }
  4753.  
  4754. // debugger;
  4755. // new xdeadc.__domApi.constructor(document.createElement('div'));
  4756. }
  4757.  
  4758. }
  4759.  
  4760. let domApiConstructor = null;
  4761. const setupDomApi = (daProto) => {
  4762.  
  4763. daProto.__daHook377__ = true;
  4764.  
  4765. domApiConstructor = daProto.constructor; // TBC
  4766.  
  4767. // TBC
  4768.  
  4769. }
  4770.  
  4771.  
  4772. // WEAKREF_ShadyDOM
  4773.  
  4774. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  4775.  
  4776. const setupPlainShadyDOM = (b) => {
  4777. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  4778. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  4779. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  4780. b.patchOnDemand = true;
  4781. b.preferPerformance = true;
  4782. b.noPatch = true;
  4783. }
  4784.  
  4785. const isPlainObject = (b, m) => {
  4786. if (!b || typeof b !== 'object') return false;
  4787. const e = Object.getOwnPropertyDescriptors(b);
  4788. if (e.length <= m) return false;
  4789. let pr = 0;
  4790. for (const k in e) {
  4791. const d = e[k];
  4792. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  4793. if (!('value' in d) || typeof d.value === 'function') return false;
  4794. pr++;
  4795. }
  4796. return pr > m;
  4797. }
  4798.  
  4799. let b;
  4800.  
  4801. let lz = 0;
  4802.  
  4803. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  4804. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  4805.  
  4806. // Brave - ShadyDOM exists before userscripting
  4807. b = sdp.value;
  4808.  
  4809. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  4810. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  4811. lz = 1;
  4812. }
  4813.  
  4814. }
  4815.  
  4816.  
  4817. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  4818. } else if (!sdp) {
  4819. } else {
  4820. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  4821. return;
  4822. }
  4823.  
  4824. const shadyDOMNodeWRM = new WeakMap();
  4825.  
  4826. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  4827.  
  4828. const weakWrapperNodeHandlerFn = () => ({
  4829. get() {
  4830. const wv = this[wk];
  4831. if (typeof wv === 'undefined') return undefined;
  4832. let node = kRef(wv);
  4833. if (!node) this[wk] = undefined;
  4834. return node || undefined;
  4835. },
  4836. set(nv) {
  4837. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  4838. this[wk] = wv;
  4839. return true;
  4840. },
  4841. enumerable: true,
  4842. configurable: true
  4843. });
  4844.  
  4845.  
  4846. function weakWrapper(_ShadyDOM) {
  4847. const ShadyDOM = _ShadyDOM;
  4848. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  4849. let nullElement = { node: null };
  4850. Object.setPrototypeOf(nullElement, Element.prototype);
  4851. let p = new ShadyDOM.Wrapper(nullElement);
  4852. let d = Object.getOwnPropertyDescriptor(p, 'node');
  4853. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  4854. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  4855. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  4856. }
  4857.  
  4858. }
  4859. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  4860. try {
  4861. setupSDomWrapper();
  4862. } catch (e) { }
  4863. }
  4864.  
  4865. }
  4866.  
  4867. let previousWrapStore = null;
  4868.  
  4869. const standardWrap = function (a) {
  4870. // if(a && a.deref) a= a.deref();
  4871. if(!a) return a;
  4872. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  4873. if (previousWrapStore) {
  4874. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  4875. if (s) {
  4876. previousWrapStore.delete(a);
  4877. shadyDOMNodeWRM.set(a, mWeakRef(s));
  4878. }
  4879. }
  4880. let u = kRef(shadyDOMNodeWRM.get(a));
  4881. if (!u) {
  4882. u = new ShadyDOM.Wrapper(a);
  4883. shadyDOMNodeWRM.set(a, mWeakRef(u));
  4884. }
  4885. return u;
  4886. }
  4887.  
  4888. standardWrap_ = standardWrap;
  4889.  
  4890.  
  4891. function setupWrapFunc(_ShadyDOM) {
  4892. const ShadyDOM = _ShadyDOM;
  4893.  
  4894.  
  4895. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  4896. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  4897. return;
  4898. }
  4899. let mm = new Set();
  4900. const pget = wmPD.value;
  4901. WeakMap.prototype.get = function (a) {
  4902. mm.add(this);
  4903. return a;
  4904. }
  4905. try {
  4906. let nullElement = { node: null };
  4907. Object.setPrototypeOf(nullElement, Element.prototype);
  4908. ShadyDOM.wrapIfNeeded(nullElement)
  4909. ShadyDOM.wrap(nullElement)
  4910. } catch (e) { }
  4911. WeakMap.prototype.get = pget;
  4912. if (mm.size !== 1) {
  4913. mm.clear();
  4914. return;
  4915. }
  4916. const p = mm.values().next().value;
  4917. if (!(p instanceof WeakMap)) return;
  4918. // p.clear();
  4919. // p.get = function (a) { return a }
  4920. // p.set = function (a, b) { return this }
  4921. // console.log(188, window.n2n = mm, window.n2p = p)
  4922.  
  4923. // console.log(34929,p.size)
  4924. previousWrapStore = p;
  4925.  
  4926. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  4927. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  4928. }
  4929. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  4930. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  4931. }
  4932.  
  4933. }
  4934.  
  4935. function setupLZ3(nv) {
  4936.  
  4937. const ShadyDOM = nv;
  4938.  
  4939. const ShadyDOMSettings = ShadyDOM.settings;
  4940. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4941. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4942. return false;
  4943. }
  4944.  
  4945. weakWrapper(ShadyDOM);
  4946.  
  4947. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4948.  
  4949. setupPlainShadyDOM(ShadyDOMSettings);
  4950. setupPlainShadyDOM(ShadyDOM);
  4951.  
  4952. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  4953.  
  4954. setupWrapFunc(ShadyDOM);
  4955. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  4956. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  4957.  
  4958. // To be confirmed
  4959. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  4960. ShadyDOM.composedPath = function (e) {
  4961. const t = (e || 0).target || null;
  4962. if (!(t instanceof HTMLElement_)) {
  4963. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  4964. }
  4965. return t instanceof HTMLElement_ ? [t] : [];
  4966. };
  4967. }
  4968.  
  4969. }
  4970.  
  4971. }
  4972.  
  4973.  
  4974. function setupLZ6(nv) {
  4975.  
  4976. const ShadyDOM = nv;
  4977.  
  4978. const ShadyDOMSettings = ShadyDOM.settings;
  4979.  
  4980. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4981. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4982. return false;
  4983. }
  4984.  
  4985. weakWrapper(ShadyDOM);
  4986.  
  4987. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4988.  
  4989. setupPlainShadyDOM(ShadyDOMSettings);
  4990. setupPlainShadyDOM(ShadyDOM);
  4991.  
  4992. setupWrapFunc(ShadyDOM);
  4993.  
  4994. }
  4995.  
  4996. }
  4997.  
  4998. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  4999.  
  5000. const nv = b;
  5001.  
  5002. if (setupLZ6(nv) === false) return;
  5003.  
  5004. lz = 6;
  5005.  
  5006. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  5007.  
  5008. return;
  5009. }
  5010.  
  5011. delete window.ShadyDOM;
  5012.  
  5013. Object.defineProperty(window, 'ShadyDOM', {
  5014. get() {
  5015. return b;
  5016. },
  5017. set(nv) {
  5018. let ret = 0;
  5019. try {
  5020. do {
  5021. if (!nv || !nv.settings) {
  5022. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  5023. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  5024. lz = 1;
  5025. break;
  5026. } else {
  5027. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  5028. break;
  5029. }
  5030. }
  5031.  
  5032. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  5033. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  5034. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  5035. break;
  5036. }
  5037.  
  5038. if (setupLZ3(nv) === false) break;
  5039.  
  5040. lz = 3;
  5041.  
  5042. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  5043.  
  5044. ret = 1;
  5045.  
  5046. } while (0);
  5047. } catch (e) {
  5048. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  5049. }
  5050.  
  5051. if (!ret) b = nv;
  5052. else {
  5053. delete this.ShadyDOM;
  5054. this.ShadyDOM = nv;
  5055. }
  5056. return true;
  5057. },
  5058. enumerable: false,
  5059. configurable: true
  5060. });
  5061.  
  5062. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  5063.  
  5064. if (ENABLE_ASYNC_DISPATCHEVENT) {
  5065. const filter = new Set([
  5066. 'yt-action',
  5067. // 'iframe-src-replaced',
  5068. 'shown-items-changed',
  5069. 'can-show-more-changed', 'collapsed-changed',
  5070.  
  5071. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  5072. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  5073. 'yt-navigate-finish',
  5074.  
  5075. // 'data-changed','yt-watch-comments-ready'
  5076. ])
  5077. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  5078. EventTarget.prototype.dispatchEvent = function (event) {
  5079. const type = (event || 0).type;
  5080. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  5081. if (!filter.has(type) && !type.endsWith('-changed')) {
  5082. if (this instanceof Node || this instanceof Window) {
  5083. nextBrowserTick_(() => this.dispatchEvent938(event));
  5084. return true;
  5085. }
  5086. }
  5087. }
  5088. return this.dispatchEvent938(event);
  5089. }
  5090. }
  5091.  
  5092. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  5093. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  5094. // const xhr = new XMLHttpRequest;
  5095. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  5096. if (!pdOri || pdOri.configurable !== true) return;
  5097. let propNeedles = null;
  5098. const pdNew = {
  5099. configurable: true,
  5100. enumerable: true,
  5101. get: function () {
  5102. propNeedles = this;
  5103. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  5104. throw new Error();
  5105. }
  5106. }
  5107. Object.defineProperty(Map.prototype, 'size', pdNew);
  5108. try {
  5109. XMLHttpRequest.prototype.open.call(0);
  5110. // xhr.open.call(null)
  5111. } catch (e) { }
  5112. Object.defineProperty(Map.prototype, 'size', pdOri);
  5113. if (!propNeedles) return;
  5114. const entries = [...propNeedles.entries()];
  5115. propNeedles.clear();
  5116. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  5117. })();
  5118.  
  5119. if (FIX_XHR_REQUESTING) {
  5120.  
  5121. const URL = window.URL || new Function('return URL')();
  5122. const createObjectURL = URL.createObjectURL.bind(URL);
  5123.  
  5124. XMLHttpRequest = (() => {
  5125. const XMLHttpRequest_ = XMLHttpRequest;
  5126. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  5127. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  5128. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  5129. constructor(...args) {
  5130. super(...args);
  5131. }
  5132. open(method, url, ...args) {
  5133. let skip = false;
  5134. if (!url || typeof url !== 'string') skip = true;
  5135. else if (typeof url === 'string') {
  5136. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  5137. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  5138. skip = true;
  5139. } else if (turl.includes('.youtube.com/pagead/')) {
  5140. skip = true;
  5141. } else if (turl.includes('.youtube.com/ptracking')) {
  5142. skip = true;
  5143. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  5144. skip = true;
  5145. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  5146. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  5147. skip = true;
  5148. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  5149. skip = true;
  5150. } else {
  5151. // skip = true; // for user activity logging e.g. watched videos
  5152. }
  5153. } else if (turl.includes('play.google.com/log')) {
  5154. skip = true;
  5155. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  5156. skip = true;
  5157. }
  5158. }
  5159. if (!skip) {
  5160. this.__xmMc8__ = 1;
  5161. return super.open(method, url, ...args);
  5162. } else {
  5163. this.__xmMc8__ = 2;
  5164. return super.open('GET', url0);
  5165. }
  5166. }
  5167. send(...args) {
  5168. if (this.__xmMc8__ === 1) {
  5169. return super.send(...args);
  5170. } else if (this.__xmMc8__ === 2) {
  5171. return super.send();
  5172. } else {
  5173. console.log('[yt-js-engine-tamer]', 'xhr warning');
  5174. return super.send(...args);
  5175. }
  5176. }
  5177. }
  5178. c.prototype.__xmMc8__ = 0;
  5179. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  5180. return c;
  5181. })();
  5182. }
  5183.  
  5184. // Alternative HACK -> Tabview Youtube
  5185. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  5186.  
  5187. // ---- << this.overscrollConfig HACK >> -----
  5188.  
  5189. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  5190.  
  5191. /*
  5192.  
  5193. ;function gZb(a, b) {
  5194. b = void 0 === b ? !0 : b;
  5195. a.addEventListener("wheel", hZb);
  5196. a.overscrollConfig = {
  5197. cooldown: b
  5198. }
  5199. }
  5200. function iZb(a) {
  5201. a.overscrollConfig = void 0;
  5202. a.removeEventListener("wheel", hZb)
  5203. }
  5204. function hZb(a) {
  5205. var b = a.deltaY
  5206. , c = a.target
  5207. , d = null;
  5208. if (window.Polymer && window.Polymer.Element) {
  5209. if (c = a.path || a.composedPath && a.composedPath()) {
  5210. c = g(c);
  5211. for (var e = c.next(); !e.done && (e = e.value,
  5212. !jZb(e, b)); e = c.next())
  5213. if (e.overscrollConfig) {
  5214. d = e;
  5215. break
  5216. }
  5217. }
  5218. } else
  5219. for (; c && !jZb(c, b); ) {
  5220. if (c.overscrollConfig) {
  5221. d = c;
  5222. break
  5223. }
  5224. c = c.parentElement
  5225. }
  5226. d && (b = d.overscrollConfig,
  5227. b.cooldown ? (d = a.deltaY,
  5228. c = b.lastDeltaY || 0,
  5229. b.lastDeltaY = d,
  5230. e = b.lastStopped || 0,
  5231. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  5232. c = !1) : (d = e + 600,
  5233. c = !0) : (d = Date.now() + 600,
  5234. c = !0),
  5235. d > Date.now() && (a.preventDefault(),
  5236. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  5237. }
  5238. */
  5239.  
  5240. let wheelHandler = function (a) {
  5241. if (window.Polymer && window.Polymer.Element) {
  5242. let c;
  5243. if (c = a.path || a.composedPath && a.composedPath()) {
  5244. for (const e of c) {
  5245. const cnt = insp(e);
  5246. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5247. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5248. }
  5249. }
  5250. } else {
  5251. let e = a.target;
  5252. for (; e instanceof Element; e = e.parentElement) {
  5253. const cnt = insp(e);
  5254. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5255. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5256. }
  5257. }
  5258. };
  5259.  
  5260. let checkWheelListenerObjs = null;
  5261.  
  5262. let getObjsFn = () => {
  5263. let euyVal = 0;
  5264. const eukElm = {};
  5265. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  5266. const euzObj = new Proxy(eukElm, {
  5267. get(target, prop) {
  5268. throw `ErrorF31.get(${prop})`
  5269. },
  5270. set(target, prop, value) {
  5271. throw `ErrorF33.set(${prop}, ${value})`
  5272. }
  5273. });
  5274. const euxElm = new Proxy(eukElm, {
  5275. get(target, prop) {
  5276. if (prop === 'scrollTop') {
  5277. euyVal = euyVal | 8;
  5278. return 0;
  5279. }
  5280. if (prop === 'overscrollConfig') {
  5281. euyVal = euyVal | 16;
  5282. return void 0;
  5283. }
  5284. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  5285. return 640;
  5286. }
  5287. if (prop === 'scrollLeft') {
  5288. euyVal = euyVal | 8;
  5289. return 0;
  5290. }
  5291. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  5292. return 800;
  5293. }
  5294. throw `ErrorF45.get(${prop})`
  5295. },
  5296. set(target, prop, value) {
  5297. throw `ErrorF47.set(${prop}, ${value})`
  5298. }
  5299. });
  5300. const eukEvt = {};
  5301. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  5302. const euyEvt = new Proxy(eukEvt, {
  5303. get(target, prop) {
  5304. if (prop === 'deltaY' || prop === 'deltaX') {
  5305. euyVal = euyVal | 1;
  5306. return -999;
  5307. }
  5308. if (prop === 'target') {
  5309. euyVal = euyVal | 2;
  5310. return euxElm
  5311. }
  5312. if (prop === 'path' || prop === 'composedPath') {
  5313. euyVal = euyVal | 2;
  5314. return [euxElm]
  5315. }
  5316. throw `ErrorF51.get(${prop})`
  5317. },
  5318. set(target, prop, value) {
  5319. throw `ErrorF53.set(${prop}, ${value})`
  5320. }
  5321. });
  5322. const setVal = (v) => {
  5323. euyVal = v;
  5324. }
  5325. const getVal = () => {
  5326. return euyVal;
  5327. }
  5328. return { euzObj, euyEvt, setVal, getVal };
  5329. }
  5330.  
  5331. let checkWheelListener = (callback) => {
  5332.  
  5333. let callbackIdentifier = '';
  5334.  
  5335. let res = null;
  5336. try {
  5337. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  5338. setVal(0);
  5339. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  5340. throw `RESULT${getVal()}`;
  5341. } catch (e) {
  5342. res = e;
  5343. }
  5344.  
  5345. res = `${res}` || `${null}`;
  5346. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  5347.  
  5348. callbackIdentifier = res;
  5349. if (callbackIdentifier === 'RESULT27') 0;
  5350. else if (callbackIdentifier === 'RESULT0') {
  5351. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  5352. } else if (callbackIdentifier.startsWith('RESULT')) {
  5353. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  5354. }
  5355. return callbackIdentifier;
  5356.  
  5357. };
  5358.  
  5359. let callbackFound = false;
  5360. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  5361. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  5362. // M-youtube-js-engine-tamer.52178
  5363. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  5364. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  5365. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  5366. // RESULTXX / ErrorFXX / Other...
  5367. if (callbackIdentifier === 'RESULT27') {
  5368. this.overscrollConfigDisable = true;
  5369. if (!callbackFound) {
  5370. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  5371. getObjsFn = checkWheelListener = null;
  5372. checkWheelListenerObjs = null;
  5373. wheelHandler = null;
  5374. }
  5375. return void 0;
  5376. } else if (!callbackFound && !this.overscrollConfigDisable) {
  5377. this.overscrollConfigDisable = true;
  5378. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  5379. }
  5380. }
  5381. return this.addEventListener52178(type, callback, option);
  5382. };
  5383.  
  5384. // ---- << this.overscrollConfig HACK >> -----
  5385.  
  5386. }
  5387.  
  5388. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  5389.  
  5390. let p_a_objWR = null;
  5391. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  5392. let ytPageReady = 0;
  5393.  
  5394. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5395. let isGlobalSpaceControl = true;
  5396. let mediaPlayerElementWR = null;
  5397. let focusedElementAtSelection = null;
  5398.  
  5399. // let want_control_video = false;
  5400.  
  5401. let spaceBarControl_keyG = '';
  5402.  
  5403. let lastUserAction = 0;
  5404.  
  5405. const wmKeyControlPhase = new WeakMap();
  5406.  
  5407. let currentSelectionText = null;
  5408.  
  5409. const getCurrentSelectionText = () => {
  5410. if (currentSelectionText !== null) return currentSelectionText
  5411. return (currentSelectionText = `${getSelection()}`)
  5412. }
  5413.  
  5414. const pageMediaWatcher = () => {
  5415.  
  5416. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  5417. // want_control_video = false;
  5418. // }, { capture: true, passive: true });
  5419.  
  5420. document.addEventListener('yt-navigate', () => {
  5421. ytPageReady = 0;
  5422. });
  5423. document.addEventListener('yt-navigate-start', () => {
  5424. ytPageReady = 0;
  5425. });
  5426. document.addEventListener('yt-navigate-cache', () => {
  5427. ytPageReady = 0;
  5428. });
  5429.  
  5430. document.addEventListener('yt-navigate-finish', () => {
  5431. ytPageReady = 1;
  5432. });
  5433.  
  5434. document.addEventListener('durationchange', () => {
  5435. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  5436. if (elm.duration > 0.01) {
  5437. if (elm.closest('[hidden]')) continue;
  5438. mediaPlayerElementWR = mWeakRef(elm);
  5439. return;
  5440. }
  5441. }
  5442. }, { capture: true, passive: true });
  5443.  
  5444. document.addEventListener('selectionchange', (evt) => {
  5445. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  5446. currentSelectionText = null;
  5447. if (!(evt.target instanceof Node)) return;
  5448. focusedElementAtSelection = evt.target;
  5449. }, { capture: true, passive: true })
  5450.  
  5451. document.addEventListener('pointerdown', (evt) => {
  5452. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5453. }, { capture: true, passive: true });
  5454.  
  5455.  
  5456. document.addEventListener('pointerup', (evt) => {
  5457. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5458. }, { capture: true, passive: true });
  5459.  
  5460.  
  5461. document.addEventListener('keydown', (evt) => {
  5462. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5463. }, { capture: true, passive: true });
  5464.  
  5465. document.addEventListener('keyup', (evt) => {
  5466. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5467. }, { capture: true, passive: true });
  5468.  
  5469. };
  5470.  
  5471.  
  5472. const checkKeyB = (p_a_obj) => {
  5473.  
  5474. const boolList = new Set();
  5475. const p_a_obj_api = p_a_obj.api;
  5476.  
  5477. const nilFunc0 = function () {
  5478. return void 0
  5479. };
  5480. const mt = new Proxy({}, {
  5481. get(target, prop) {
  5482. if (prop === 'get') return nilFunc0;
  5483. return mt;
  5484. }
  5485. });
  5486. const nilFunc = function () {
  5487. return mt
  5488. };
  5489. const mw = new Proxy({}, {
  5490. get(target, prop) {
  5491. if (prop in p_a_obj_api) {
  5492. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  5493. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  5494. if (q && q.value) {
  5495. if (!q.writable) return q.value;
  5496. if (typeof q.value === 'string') return '';
  5497. if (typeof q.value === 'number') return 0;
  5498. if (typeof q.value === 'boolean') return false;
  5499. if (q.value && typeof q.value === 'object') return {};
  5500. }
  5501. }
  5502. return undefined;
  5503. },
  5504. set(target, prop) {
  5505. throw 'mwSet';
  5506. }
  5507. });
  5508.  
  5509. const mq = new Proxy({}, {
  5510. get(target, prop) {
  5511. if (prop === 'api') return mw;
  5512. if (prop in p_a_obj) {
  5513. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  5514. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  5515. if (q && q.value) {
  5516. if (!q.writable) return q.value;
  5517. if (typeof q.value === 'string') return '';
  5518. if (typeof q.value === 'number') return 0;
  5519. if (typeof q.value === 'boolean') return false;
  5520. if (q.value && typeof q.value === 'object') return {};
  5521. }
  5522. }
  5523. return undefined;
  5524. },
  5525. set(target, prop, val) {
  5526. if (typeof val === 'boolean') boolList.add(prop)
  5527. throw `mqSet(${prop},${val})`;
  5528. }
  5529. });
  5530.  
  5531. let res = ''
  5532. try {
  5533. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  5534. } catch (e) {
  5535. res = `ERROR::${e}`;
  5536. }
  5537.  
  5538. if (boolList.size === 1) {
  5539. const value = boolList.values().next().value;
  5540. if (res === `ERROR::mqSet(${value},${true})`) {
  5541. p_a_obj.__uZWaD__ = value;
  5542. }
  5543. }
  5544.  
  5545. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  5546.  
  5547. }
  5548.  
  5549.  
  5550. let pm_p_a = null;
  5551.  
  5552. const p_a_init = function () {
  5553. const r = this.init91();
  5554. const keyBw = this.__cPzfo__ || '__NIL__';
  5555. const p_a_obj = this[keyBw];
  5556. if (!p_a_obj) return;
  5557. try {
  5558. checkKeyB(p_a_obj);
  5559. } catch (e) { }
  5560. p_a_objWR = mWeakRef(p_a_obj);
  5561. if (FIX_SHORTCUTKEYS > 0) {
  5562. if (p_a_obj && !p_a_obj.hVhtg) {
  5563. p_a_obj.hVhtg = 1;
  5564.  
  5565. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  5566. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  5567. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  5568. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  5569. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  5570. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  5571.  
  5572. }
  5573. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  5574. // const api = p_a_obj.api
  5575. // api.hVhtg = 1;
  5576. // api.playVideo91 = api.playVideo;
  5577. // api.playVideo = p_a_jt.playVideo;
  5578. // api.pauseVideo91 = api.pauseVideo;
  5579. // api.pauseVideo = p_a_jt.pauseVideo;
  5580. // }
  5581. }
  5582. if (pm_p_a) {
  5583. pm_p_a.resolve();
  5584. pm_p_a = null;
  5585. }
  5586. return r;
  5587. };
  5588.  
  5589. const p_a_xt = {
  5590.  
  5591. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  5592.  
  5593. if (FIX_SHORTCUTKEYS === 2) {
  5594.  
  5595. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  5596.  
  5597. if (activeElement) {
  5598.  
  5599. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  5600.  
  5601. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  5602. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  5603. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  5604.  
  5605. }
  5606.  
  5607. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5608. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5609. // console.log(582, isDelayedSpaceBar)
  5610. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5611.  
  5612. if (activeElement && (h === 'Space' || h === 'Enter')) {
  5613. const controlPhase = wmKeyControlPhase.get(activeElement);
  5614. if (controlPhase === 4 || controlPhase === 5) return false;
  5615. }
  5616. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  5617. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  5618. // if (!isSpaceKeyImmediate) return false;
  5619. // }
  5620. }
  5621.  
  5622. },
  5623.  
  5624. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  5625.  
  5626. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  5627.  
  5628. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5629. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5630. // console.log(583, isDelayedSpaceBar)
  5631. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5632.  
  5633. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5634.  
  5635. let mediaWorking = false;
  5636. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  5637. mediaWorking = true;
  5638. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5639. mediaWorking = true;
  5640. }
  5641. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  5642. mediaWorking && Promise.resolve().then(() => {
  5643. if (activeElement === document.activeElement) {
  5644. return activeElement.blur()
  5645. } else {
  5646. return false
  5647. }
  5648. }).then((r) => {
  5649. r !== false && mediaPlayerElement.focus();
  5650. });
  5651. }
  5652. },
  5653.  
  5654.  
  5655. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  5656.  
  5657. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5658.  
  5659. const activeElement = document.activeElement;
  5660.  
  5661. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5662. if (allow === false) return false;
  5663.  
  5664. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5665. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  5666.  
  5667. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5668.  
  5669. return ret;
  5670. },
  5671. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  5672.  
  5673.  
  5674. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5675.  
  5676. const activeElement = document.activeElement;
  5677. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5678. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5679. // }
  5680. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5681. if (allow === false) return false;
  5682.  
  5683. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5684. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  5685.  
  5686. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5687.  
  5688. return ret;
  5689. }
  5690.  
  5691. };
  5692.  
  5693. // const p_a_jt = { // API
  5694.  
  5695. // playVideo(a) { // without spinner effect
  5696.  
  5697. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  5698.  
  5699. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5700. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5701. // want_control_video = true;
  5702. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  5703. // }
  5704.  
  5705. // }
  5706. // return this.playVideo91(a);
  5707.  
  5708. // },
  5709.  
  5710. // pauseVideo(a) { // without spinner effect
  5711.  
  5712. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  5713.  
  5714. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5715. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5716. // want_control_video = true;
  5717. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  5718. // }
  5719.  
  5720. // }
  5721. // return this.pauseVideo91(a);
  5722.  
  5723. // }
  5724. // };
  5725.  
  5726. let flagSpeedMaster = null;
  5727. const getSpeedMasterControlFlag = () => {
  5728.  
  5729. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5730. isSpeedMastSpacebarControlEnabled = false;
  5731. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  5732. isSpeedMastSpacebarControlEnabled = true;
  5733. }
  5734. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  5735. isSpeedMastSpacebarControlEnabled = true;
  5736. }
  5737.  
  5738. if (flagSpeedMaster === null) {
  5739. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  5740. if (!p) {
  5741. flagSpeedMaster = false;
  5742. } else {
  5743.  
  5744. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  5745.  
  5746. }
  5747.  
  5748. }
  5749. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  5750.  
  5751. return isSpeedMastSpacebarControlEnabled;
  5752. }
  5753.  
  5754.  
  5755. const getGlobalSpacebarControlFlag = () => {
  5756.  
  5757. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5758. isGlobalSpaceControl = false;
  5759. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  5760. isGlobalSpaceControl = true;
  5761. }
  5762. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  5763. isGlobalSpaceControl = true;
  5764. }
  5765.  
  5766. return isGlobalSpaceControl;
  5767. }
  5768.  
  5769. const keyboardController = async (_yt_player) => {
  5770.  
  5771. const keyQT = getQT(_yt_player);
  5772. const keySV = getSV(_yt_player);
  5773. const keyDX = getDX(_yt_player);
  5774. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  5775.  
  5776. if (!keyDX) return;
  5777. if (keyDX === keyQT || keyDX === keySV) return;
  5778.  
  5779. if (typeof keyDX !== 'string') return;
  5780.  
  5781. let lastAccessKey = '';
  5782. let lastAccessKeyConfirmed = '';
  5783. const mb = new Proxy({}, {
  5784. get(target, prop) {
  5785. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  5786. throw 'mbGet'
  5787. },
  5788. set(target, prop, val) {
  5789. throw 'mbSet'
  5790. }
  5791. });
  5792. const ma = new Proxy({}, {
  5793. get(target, prop) {
  5794. lastAccessKey = prop;
  5795. return mb
  5796. },
  5797. set(target, prop, val) {
  5798. throw 'maSet'
  5799. }
  5800. });
  5801.  
  5802. let keyBw = '';
  5803. try {
  5804. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  5805. } catch (e) {
  5806. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  5807. keyBw = lastAccessKeyConfirmed;
  5808. }
  5809. }
  5810.  
  5811. if (!keyBw) return;
  5812.  
  5813. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  5814.  
  5815. pm_p_a = new PromiseExternal();
  5816.  
  5817. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  5818.  
  5819. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  5820.  
  5821. _yt_player[keyDX].prototype.init = p_a_init;
  5822.  
  5823. await pm_p_a.then();
  5824. const p_a_obj = kRef(p_a_objWR);
  5825.  
  5826. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  5827.  
  5828.  
  5829. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  5830.  
  5831. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  5832.  
  5833. if (!isSpeedMastSpacebarControlEnabled) {
  5834.  
  5835. if (config && config.EXPERIMENT_FLAGS) {
  5836. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  5837. }
  5838. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5839. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  5840. }
  5841.  
  5842. } else {
  5843.  
  5844. if (config && config.EXPERIMENT_FLAGS) {
  5845. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  5846. }
  5847. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5848. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  5849. }
  5850.  
  5851. }
  5852.  
  5853. }
  5854.  
  5855. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  5856.  
  5857.  
  5858.  
  5859.  
  5860. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  5861.  
  5862. // console.log(p_a_obj.handleGlobalKeyUp)
  5863. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  5864.  
  5865. // console.log(p_a_obj.api)
  5866.  
  5867.  
  5868. // QT -> DX(SV) -> p_a
  5869.  
  5870.  
  5871. /*
  5872. *
  5873. *
  5874. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5875. b = void 0 === b ? !1 : b;
  5876. c = void 0 === c ? !1 : c;
  5877. d = void 0 === d ? !1 : d;
  5878. e = void 0 === e ? !1 : e;
  5879. var l = g.PT(this);
  5880. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  5881. }
  5882.  
  5883. */
  5884.  
  5885. /*
  5886. *
  5887. *
  5888. *
  5889. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5890. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  5891. }
  5892.  
  5893. */
  5894.  
  5895.  
  5896. // if(!keyDX) return;
  5897.  
  5898. // console.log(4999, keyDX)
  5899.  
  5900. };
  5901.  
  5902.  
  5903. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  5904.  
  5905. const p_a_obj = kRef(p_a_objWR);
  5906. // const api = p_a_obj.api;
  5907.  
  5908.  
  5909. // console.log(540);
  5910.  
  5911. let boolList = null;
  5912. let ret;
  5913. isSpaceKeyImmediate = true;
  5914. try {
  5915.  
  5916. ret = 0;
  5917. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  5918. let p_a_objT;
  5919. if (!spaceBarControl_keyG) { // just in case
  5920. boolList = new Set();
  5921. p_a_objT = new Proxy(p_a_obj, {
  5922. get(target, prop, handler) {
  5923. const val = target[prop];
  5924. if (typeof val !== 'boolean') return val;
  5925. boolList.add(prop);
  5926. // console.log(555, prop, val);
  5927. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  5928. spaceBarControl_keyG = prop;
  5929. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5930. val = false;
  5931. }
  5932. return val;
  5933. }
  5934. });
  5935.  
  5936.  
  5937. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  5938. p_a_obj[spaceBarControl_keyG] = false;
  5939. p_a_objT = p_a_obj;
  5940. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  5941. } else {
  5942.  
  5943. p_a_objT = p_a_obj;
  5944. }
  5945.  
  5946. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  5947.  
  5948.  
  5949. } catch (e) {
  5950. console.log(e)
  5951. }
  5952. isSpaceKeyImmediate = false;
  5953.  
  5954. if (boolList && boolList.size === 1) {
  5955. const value = boolList.values().next().value;
  5956. spaceBarControl_keyG = value;
  5957. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5958.  
  5959. }
  5960.  
  5961. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5962.  
  5963. return ret;
  5964. }
  5965.  
  5966. const shortcutKeysFixer = () => {
  5967.  
  5968. let pausePromiseControlJ = 0;
  5969.  
  5970.  
  5971. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  5972.  
  5973. let controlPhase = 0;
  5974. const aElm = document.activeElement;
  5975.  
  5976. if (aElm) {
  5977.  
  5978. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  5979.  
  5980. if (typeof controlPhaseCache === 'number') {
  5981.  
  5982. controlPhase = controlPhaseCache;
  5983. } else {
  5984.  
  5985. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  5986. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  5987. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  5988. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  5989. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  5990. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  5991. else {
  5992. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  5993. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  5994. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  5995. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  5996. }
  5997.  
  5998. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  5999. controlPhase = 0;
  6000. }
  6001.  
  6002. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  6003. if (aElm.closest('[contenteditable], input, textarea')) {
  6004. controlPhase = 5;
  6005. } else if (aElm.closest('button')) {
  6006. controlPhase = 4;
  6007. }
  6008. }
  6009.  
  6010. if (aElm.closest('#movie_player')) controlPhase = 6;
  6011.  
  6012. wmKeyControlPhase.set(aElm, controlPhase);
  6013.  
  6014. }
  6015. }
  6016.  
  6017. return controlPhase;
  6018.  
  6019. }
  6020.  
  6021. const isStateControllable = (api) => {
  6022. let appState = null;
  6023. let playerState = null;
  6024. let adState = null;
  6025. try {
  6026. appState = api.getAppState();
  6027. playerState = api.getPlayerState();
  6028. adState = api.getAdState();
  6029. } catch (e) { }
  6030. // ignore playerState -1
  6031. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  6032. };
  6033.  
  6034.  
  6035. const keyEventListener = (evt) => {
  6036. if (BY_PASS_KEYBOARD_CONTROL) return;
  6037.  
  6038. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  6039. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  6040. if (!ytPageReady) return;
  6041.  
  6042. if (evt.defaultPrevented === true) return;
  6043.  
  6044. const p_a_obj = kRef(p_a_objWR);
  6045.  
  6046. if (!p_a_obj) return;
  6047.  
  6048.  
  6049. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  6050. if (!mediaPlayerElement) return;
  6051.  
  6052. // let focusBodyIfSuccess = false;
  6053.  
  6054. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  6055.  
  6056. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  6057. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  6058. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  6059.  
  6060.  
  6061. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  6062.  
  6063. // console.log(`${evt.type}::controlPhase`,controlPhase)
  6064.  
  6065. // if (controlPhase == 4) {
  6066. // focusBodyIfSuccess = true;
  6067. // }
  6068.  
  6069. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  6070. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6071.  
  6072. if (FIX_SHORTCUTKEYS < 2) return;
  6073. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  6074.  
  6075. let rr;
  6076. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  6077.  
  6078.  
  6079.  
  6080. let useImprovedPauseResume = false;
  6081.  
  6082. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  6083.  
  6084. const api = p_a_obj.api;
  6085. const stateControllable = isStateControllable(api);
  6086. // console.log(2122, appState, playerState, adState)
  6087.  
  6088. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  6089.  
  6090. useImprovedPauseResume = true;
  6091.  
  6092. }
  6093.  
  6094.  
  6095. }
  6096.  
  6097.  
  6098. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  6099. if (evt.type === 'keydown') {
  6100.  
  6101. if (useImprovedPauseResume) {
  6102.  
  6103. const isPaused = mediaPlayerElement.paused;
  6104.  
  6105. const cj = ++pausePromiseControlJ;
  6106. Promise.resolve().then(() => {
  6107.  
  6108. if (cj !== pausePromiseControlJ) return;
  6109.  
  6110. if (mediaPlayerElement.paused !== isPaused) return;
  6111.  
  6112. const ret = ytResumeFn();
  6113. if (!ret) { // fallback
  6114. isPaused ? api.playVideo() : api.pauseVideo();
  6115. }
  6116.  
  6117. /*
  6118. let a = void 0;
  6119. console.log('Rb', api.Rb())
  6120. a = !window._yt_player.nL(api.Rb());
  6121. p_a_obj.Wd.kG(a)
  6122. a ? api.playVideo() : api.pauseVideo();
  6123.  
  6124. */
  6125.  
  6126.  
  6127. });
  6128. rr = true;
  6129. } else {
  6130.  
  6131. isSpaceKeyImmediate = true;
  6132. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  6133. isSpaceKeyImmediate = false;
  6134. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6135.  
  6136. }
  6137.  
  6138.  
  6139. } else if (evt.type === 'keyup') {
  6140.  
  6141. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  6142.  
  6143. rr = true;
  6144. } else {
  6145.  
  6146. isSpaceKeyImmediate = true;
  6147. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  6148. isSpaceKeyImmediate = false;
  6149. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6150.  
  6151. }
  6152.  
  6153.  
  6154. /*
  6155.  
  6156. if (d)
  6157. switch (c) {
  6158. case 32:
  6159. case 13:
  6160. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  6161. b = !0,
  6162. e = !1;
  6163. else if (e) {
  6164. var m = d.getAttribute("role");
  6165. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  6166. d.click(),
  6167. f = !0)
  6168. }
  6169. break;
  6170. case 37:
  6171. case 39:
  6172. case 36:
  6173. case 35:
  6174. b = "slider" === d.getAttribute("role");
  6175. break;
  6176. case 38:
  6177. case 40:
  6178. m = d.getAttribute("role"),
  6179. d = 38 === c ? d.previousSibling : d.nextSibling,
  6180. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  6181. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  6182. f = b = !0))
  6183. }
  6184. if (e && !f)
  6185. switch (c) {
  6186. case 38:
  6187. f = Math.min(this.api.getVolume() + 5, 100);
  6188. XV(this.Wd, f, !1);
  6189. this.api.setVolume(f);
  6190. h = f = !0;
  6191. break;
  6192. case 40:
  6193. f = Math.max(this.api.getVolume() - 5, 0);
  6194. XV(this.Wd, f, !0);
  6195. this.api.setVolume(f);
  6196. h = f = !0;
  6197. break;
  6198. case 36:
  6199. this.api.Yh() && (this.api.startSeekCsiAction(),
  6200. this.api.seekTo(0, void 0, void 0, void 0, 79),
  6201. h = f = !0);
  6202. break;
  6203. case 35:
  6204. this.api.Yh() && (this.api.startSeekCsiAction(),
  6205. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  6206. h = f = !0)
  6207. }
  6208. */
  6209.  
  6210. }
  6211.  
  6212.  
  6213. if (rr) {
  6214.  
  6215. // focusBodyIfSuccess && Promise.resolve().then(() => {
  6216. // activeElement === document.activeElement && activeElement.blur();
  6217. // });
  6218.  
  6219. evt.preventDefault();
  6220. evt.stopImmediatePropagation();
  6221. evt.stopPropagation();
  6222.  
  6223. }
  6224.  
  6225. };
  6226.  
  6227. document.addEventListener('keydown', keyEventListener, { capture: true });
  6228.  
  6229.  
  6230. document.addEventListener('keyup', keyEventListener, { capture: true });
  6231.  
  6232. }
  6233.  
  6234. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  6235.  
  6236. })();
  6237.  
  6238.  
  6239. pageMediaWatcher();
  6240. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  6241.  
  6242.  
  6243. const check_for_set_key_order = (() => {
  6244.  
  6245. let mySet = new Set();
  6246.  
  6247. mySet.add("value1");
  6248. mySet.add("value2");
  6249. mySet.add("value3");
  6250.  
  6251. // Function to convert Set values to an array
  6252. function getSetValues(set) {
  6253. return Array.from(set.values());
  6254. }
  6255.  
  6256. // Function to test if the Set maintains insertion order
  6257. function testSetOrder(set, expectedOrder) {
  6258. let values = getSetValues(set);
  6259. return expectedOrder.join(',') === values.join(',');
  6260. }
  6261.  
  6262. // Test 1: Initial order
  6263. if (mySet.values().next().value !== "value1") return false;
  6264. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  6265.  
  6266. // Test 2: After deleting an element
  6267. mySet.delete("value2");
  6268. if (mySet.values().next().value !== "value1") return false;
  6269. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  6270.  
  6271. // Test 3: After re-adding a deleted element
  6272. mySet.add("value2");
  6273. if (mySet.values().next().value !== "value1") return false;
  6274. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  6275.  
  6276. // Test 4: After adding a new element
  6277. mySet.add("value4");
  6278. if (mySet.values().next().value !== "value1") return false;
  6279. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  6280.  
  6281. // Test 5: Delete+Add
  6282. mySet.delete("value1");
  6283. mySet.delete("value3");
  6284. mySet.add("value3");
  6285. mySet.add("value1");
  6286. if (mySet.values().next().value !== "value2") return false;
  6287. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  6288.  
  6289. return true;
  6290. })();
  6291.  
  6292.  
  6293. // const qm47 = Symbol();
  6294. const qm57 = Symbol();
  6295. const qm53 = Symbol();
  6296. const qn53 = Symbol();
  6297.  
  6298.  
  6299. const ump3 = new WeakMap();
  6300.  
  6301. const stp = document.createElement('noscript');
  6302. stp.id = 'weakref-placeholder';
  6303.  
  6304. PROP_OverReInclusion_AVOID && (() => {
  6305.  
  6306.  
  6307. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  6308. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  6309. let byPassVal = null;
  6310. let byPassCount = 0;
  6311. let mmw = new Set();
  6312. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  6313. if (arguments.length !== 1) return f.apply(this, arguments);
  6314. if (byPassVal !== null && typeof prop === 'string') {
  6315.  
  6316. if (PROP_OverReInclusion_LIST.has(prop)) {
  6317. byPassCount++;
  6318. return byPassVal;
  6319. }
  6320. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  6321.  
  6322. }
  6323. return this.hasOwnProperty72(prop);
  6324. };
  6325.  
  6326.  
  6327. /*
  6328.  
  6329.  
  6330. z.prototype.forwardDynamicProps = function() {
  6331. var B = m(this.inst);
  6332. B = h(B);
  6333. for (var F = B.next(); !F.done; F = B.next()) {
  6334. var H = h(F.value);
  6335. F = H.next().value;
  6336. H = H.next().value;
  6337. my(this, F, H);
  6338. r(b) && !ly(F) && Wua(this.inst, F)
  6339. }
  6340. }
  6341.  
  6342. */
  6343.  
  6344.  
  6345.  
  6346. let byPassZeroShowed = false;
  6347. const forwardDynamicPropsGeneral = function () {
  6348. byPassVal = true;
  6349. byPassCount = 0;
  6350. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  6351. const ret = this.forwardDynamicProps72();
  6352. byPassVal = null;
  6353. if (byPassCount === 0 && !byPassZeroShowed) {
  6354. byPassZeroShowed = true;
  6355. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  6356. }
  6357. byPassCount = 0;
  6358. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  6359. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  6360. mmw.clear();
  6361. }
  6362. return ret;
  6363. };
  6364.  
  6365. const propCheck = (proto) => {
  6366. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  6367. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  6368. if (proto.forwardDynamicProps.length === 0) {
  6369. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  6370. }
  6371. }
  6372. };
  6373.  
  6374. const valMap = new WeakMap();
  6375. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  6376. get() {
  6377. propCheck(this.constructor.prototype);
  6378. return valMap.get(this);
  6379. },
  6380. set(nv) {
  6381. propCheck(this.constructor.prototype);
  6382. valMap.set(this, nv);
  6383. return true;
  6384. },
  6385. enumerable: false,
  6386. configurable: true
  6387.  
  6388. });
  6389.  
  6390. promiseForCustomYtElementsReady.then(() => {
  6391. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  6392. if (customElements.define.length !== 2) return;
  6393. customElements.define72 = customElements.define;
  6394. customElements.define = function (b, w) {
  6395. propCheck(w.prototype);
  6396. const ret = this.define72(b, w);
  6397. return ret;
  6398. }
  6399. });
  6400.  
  6401. })();
  6402.  
  6403. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  6404.  
  6405. const flexibleItemListMo = new MutationObserver((mutations) => {
  6406. // cnt.onStamperFinished
  6407. // cnt.maybeUpdateFlexibleMenu
  6408. const set = new Set();
  6409. for (const mutation of mutations) {
  6410. if (mutation && ((mutation.addedNodes || 0).length > 0 || (mutation.removedNodes || 0).length > 0)) {
  6411. set.add(mutation.target);
  6412. }
  6413. }
  6414. for (const s of set) {
  6415. const cnt = insp(s);
  6416. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  6417. cnt.maybeUpdateFlexibleMenuImpl();
  6418. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  6419. cnt.maybeUpdateFlexibleMenu();
  6420. } else if (typeof cnt.onStamperFinished === 'function') {
  6421. cnt.onStamperFinished();
  6422. }
  6423. }
  6424. set.clear();
  6425. });
  6426.  
  6427. let checkConfig = true;
  6428. const flexibleItemDocMo = new MutationObserver(() => {
  6429. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  6430. s.setAttribute('b289ad', '');
  6431. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  6432. s.appendChild(document.createComment('.')).remove();
  6433. }
  6434. if (checkConfig) {
  6435. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6436. if (config && config.EXPERIMENT_FLAGS) {
  6437. checkConfig = false;
  6438. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  6439. }
  6440. }
  6441. });
  6442. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  6443.  
  6444. }
  6445.  
  6446.  
  6447.  
  6448.  
  6449. const observablePromise = (proc, timeoutPromise) => {
  6450. let promise = null;
  6451. return {
  6452. obtain() {
  6453. if (!promise) {
  6454. promise = new Promise(resolve => {
  6455. let mo = null;
  6456. const f = () => {
  6457. let t = proc();
  6458. if (t) {
  6459. mo.disconnect();
  6460. mo.takeRecords();
  6461. mo = null;
  6462. resolve(t);
  6463. }
  6464. }
  6465. mo = new MutationObserver(f);
  6466. mo.observe(document, { subtree: true, childList: true })
  6467. f();
  6468. timeoutPromise && timeoutPromise.then(() => {
  6469. resolve(null)
  6470. });
  6471. });
  6472. }
  6473. return promise
  6474. }
  6475. }
  6476. }
  6477.  
  6478.  
  6479. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  6480. observablePromise(() => {
  6481. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6482. if (config && config.EXPERIMENT_FLAGS) {
  6483. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  6484. return true;
  6485. }
  6486. }).obtain();
  6487. }
  6488.  
  6489. if (FIX_ROLLING_NUMBER_UPDATE) {
  6490.  
  6491.  
  6492. observablePromise(() => {
  6493. if (typeof customElements === 'undefined') return;
  6494. const ce = customElements.get('yt-animated-rolling-number');
  6495. if (!ce) return;
  6496. return ce.prototype;
  6497. }).obtain().then(async (cProto) => {
  6498.  
  6499. const p = document.createElement('yt-animated-rolling-number');
  6500.  
  6501. const frag = document.createDocumentFragment();
  6502. frag.appendChild(p);
  6503. const pDoc = document.implementation.createHTMLDocument();
  6504. pDoc.body.appendChild(frag);
  6505.  
  6506. let p88 = p;
  6507.  
  6508. const __instance = await observablePromise(() => {
  6509. const __instance = (p88 || 0).__instance;
  6510. if (__instance && __instance.render) return __instance;
  6511. }).obtain();
  6512. p88 = null;
  6513.  
  6514. const itProto = Reflect.getPrototypeOf(__instance);
  6515.  
  6516. try {
  6517. p.remove();
  6518. } catch (e) { }
  6519.  
  6520. if (itProto.render && !itProto.render37 && itProto.render.length === 1) {
  6521.  
  6522. itProto.render37 = itProto.render;
  6523. itProto.render = function (t) {
  6524. // (this.xCounter = (this.xCounter & 1073741823)+1)
  6525. let c33 = '';
  6526. let r33 = null;
  6527. let kc = 0;
  6528.  
  6529. if (this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  6530. const el = this.el;
  6531. const ct = Date.now();
  6532. const lastFireTime = (el.__lastFireTime491__ || 0);
  6533.  
  6534. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  6535.  
  6536. if (fireTimeDiff < 80 && this.__previousRender61__) {
  6537. return this.__previousRender61__;
  6538. }
  6539.  
  6540. const caseInt =
  6541. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  6542. (t && typeof t.character === 'string') ? (
  6543. (typeof t.previousCharacter === 'string') ? 6 : 2
  6544. ) : 0;
  6545.  
  6546. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender61__ && fireTimeDiff < 9400) {
  6547. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender61__) {
  6548. return this.__previousRender61__;
  6549. }
  6550. }
  6551. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender61__ && fireTimeDiff < 9400) {
  6552. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender61__) {
  6553. return this.__previousRender61__;
  6554. }
  6555. }
  6556.  
  6557. if (caseInt & 2) {
  6558.  
  6559. if (caseInt & 4) {
  6560.  
  6561. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  6562. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  6563. t.previousCharacter = t.character;
  6564. kc = 1;
  6565. }
  6566. }
  6567.  
  6568. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  6569. t.shouldAnimate = false;
  6570. }
  6571. }
  6572.  
  6573.  
  6574. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  6575.  
  6576. el.__lastCharacter353__ = t.character;
  6577.  
  6578. } else if (caseInt === 1) {
  6579.  
  6580. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  6581. t.shouldAnimate = false;
  6582. }
  6583. el.__lastNumberValue353__ = t.numberValue;
  6584.  
  6585. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  6586. t.shouldAnimate = false;
  6587. }
  6588. el.__lastNumberText353__ = t.numberText;
  6589.  
  6590. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  6591.  
  6592. }
  6593.  
  6594. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  6595.  
  6596. el.__lastFireTime491__ = ct;
  6597. }
  6598.  
  6599. // // console.log(21399, t.character, t.previousCharacter, (t.xCounter = (t.xCounter & 1073741823)+1), t, (this.xCounter = (this.xCounter & 1073741823)+1) )
  6600. // // console.log(12883, this, t);
  6601. const r = r33 || this.render37(t);
  6602. this.__previousRender61__ = r;
  6603. if (c33) this[c33] = r;
  6604. return r
  6605. }
  6606.  
  6607. }
  6608.  
  6609.  
  6610. /*
  6611.  
  6612. let jArr = null;
  6613. Array.prototype.push781 = null;
  6614. Array.prototype.push782 = function(...args){
  6615. if(args.length === 1 && typeof (args[0]||0) ==='object' && 'rollUp' in args[0] && Array.prototype.push781){
  6616.  
  6617. jArr= this;
  6618. // debugger;
  6619. const f = Array.prototype.push = Array.prototype.push781;
  6620. Array.prototype.push781 = null;
  6621. jArr.push381 = jArr.push;
  6622. jArr.push = Array.prototype.push783;
  6623. return Array.prototype.push783.call(this, ...args);
  6624.  
  6625. }
  6626. return Array.prototype.push781.call(this, ...args);
  6627. }
  6628. Array.prototype.push783 = function(...args){
  6629. if(args.length === 1){
  6630. const o = args[0];
  6631. if(o.character === o.previousCharacter){
  6632. o.rollUp = false;
  6633. o.shouldAnimate = false;
  6634. }
  6635. console.log(12399, o)
  6636. }
  6637. return this.push381(...args);
  6638. }
  6639.  
  6640. console.log(123001)
  6641.  
  6642. cProto.update192 = cProto.update;
  6643.  
  6644. cProto.update = function () {
  6645. Object.assign192 = Object.assign;
  6646. let targetObject = null;
  6647. let kThis = this;
  6648. Object.assign = function (...args) {
  6649. let r = Object.assign192(...args);;
  6650. if (args[1] === kThis.props) {
  6651. targetObject = args[0];
  6652. fixObject();
  6653. }
  6654. return r;
  6655. }
  6656. const fixObject = () => {
  6657.  
  6658. console.log(1929, fixObject, this)
  6659.  
  6660. const t = targetObject.forceRollUp;
  6661. targetObject.forceRollUp919 = t;
  6662. Object.defineProperty(targetObject, 'forceRollUp', {
  6663. get() {
  6664.  
  6665.  
  6666. if (Array.prototype.push782 !== Array.prototype.push && !Array.prototype.push781) {
  6667.  
  6668. Array.prototype.push781 = Array.prototype.push;
  6669. Array.prototype.push = Array.prototype.push782;
  6670. Promise.resolve().then(() => {
  6671. if (Array.prototype.push782 === Array.prototype.push && Array.prototype.push781) {
  6672.  
  6673. Array.prototype.push = Array.prototype.push781;
  6674.  
  6675. Array.prototype.push781 = null;;
  6676. }
  6677. })
  6678. }
  6679. console.log(1233001);
  6680. // debugger;
  6681. return this.forceRollUp919
  6682. },
  6683. set(nv) {
  6684. this.forceRollUp919 = nv;
  6685. console.log(1233002, nv);
  6686. return true;
  6687. }
  6688. });
  6689. }
  6690. console.log(1949, this)
  6691. let r, e_;
  6692. try {
  6693. r = this.update192();
  6694. } catch (e) { e_ = e }
  6695. Object.assign = Object.assign192;
  6696. kThis = null;
  6697. if (e_) throw e_;
  6698. return r;
  6699. };
  6700.  
  6701.  
  6702.  
  6703. cProto.enqueueUpdate192 = cProto.enqueueUpdate;
  6704.  
  6705. cProto.enqueueUpdate = function () {
  6706. console.log(1948, this);
  6707. return this.enqueueUpdate192();
  6708. }
  6709.  
  6710.  
  6711. */
  6712.  
  6713.  
  6714.  
  6715. });
  6716.  
  6717.  
  6718. /*
  6719.  
  6720. observablePromise(() => {
  6721. if(typeof customElements==='undefined')return;
  6722. const ce = customElements.get('segmented-like-dislike-button-view-model');
  6723. if(!ce) return;
  6724. return ce.prototype;
  6725. }).obtain().then((cProto) => {
  6726.  
  6727.  
  6728. cProto.update192 = cProto.update;
  6729. cProto.update = function () {
  6730.  
  6731. const rolNumNode = this.querySelector('yt-animated-rolling-number');
  6732. if(rolNumNode && rolNumNode.__instance && rolNumNode.__instance.props){
  6733. rolNumNode.props = rolNumNode.__instance.props;
  6734.  
  6735. if(!rolNumNode.props.forceRollUp848){
  6736. rolNumNode.props.forceRollUp848 = true;
  6737. rolNumNode.props.forceRollUp833= rolNumNode.props.forceRollUp;
  6738. Object.defineProperty(rolNumNode.props, 'forceRollUp', {
  6739. get(){
  6740. debugger;
  6741. return this.forceRollUp833;
  6742. },
  6743. set(nv){
  6744. this.forceRollUp833 = nv;
  6745. return true;
  6746. },
  6747. enumerable: false,
  6748. configurable: true
  6749. });
  6750.  
  6751. Object.defineProperty(rolNumNode.props, 'numberValue', {
  6752. get(){
  6753. debugger;
  6754. return this.numberValue8833;
  6755. },
  6756. set(nv){
  6757. debugger;
  6758. this.numberValue8833 = nv;
  6759. return true;
  6760. },
  6761. enumerable: false,
  6762. configurable: true
  6763. });
  6764.  
  6765. }
  6766. // rolNumNode.update();
  6767. return;
  6768. }
  6769.  
  6770. return this.update192();
  6771. };
  6772.  
  6773.  
  6774.  
  6775.  
  6776. });
  6777. */
  6778. }
  6779.  
  6780. if (HOOK_ACTIVE_MODULES) {
  6781.  
  6782. let watchController;
  6783. const watchControllerObservable = observablePromise(() => {
  6784. const watchFlexy = document.querySelector('ytd-watch-flexy');
  6785. if (!watchFlexy) return;
  6786. return insp(watchFlexy).watchController;
  6787. }).obtain();
  6788. (async () => {
  6789. watchController = await watchControllerObservable;
  6790.  
  6791. const activeModules = watchController.activeModules;
  6792. if (!activeModules) return;
  6793.  
  6794. const checkFn = (activeModule) => {
  6795. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  6796. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  6797. }
  6798. }
  6799. if (!activeModules.push8792 && activeModules.push) {
  6800. activeModules.push8792 = activeModules.push;
  6801. activeModules.push = function (a, ...args) {
  6802. checkFn(a);
  6803. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  6804. return r;
  6805. }
  6806. }
  6807. activeModules.forEach(checkFn);
  6808.  
  6809. })();
  6810.  
  6811. let yieldResultWrappingByPass = false;
  6812. let asyncProto = null;
  6813. const yieldResultWrapping = (f) => {
  6814. if (yieldResultWrappingByPass) return [f(), null];
  6815. yieldResultWrappingByPass = true;
  6816. let D = null;
  6817. let promise, e_;
  6818. if (asyncProto) {
  6819. Object.defineProperty(asyncProto, 'yieldResult', {
  6820. get() {
  6821. return undefined;
  6822. },
  6823. set(nv) {
  6824. delete asyncProto.yieldResult;
  6825. this.yieldResult = nv;
  6826. D = this;
  6827. // console.log(122, this);
  6828. return true;
  6829. },
  6830. enumerable: false,
  6831. configurable: true
  6832. });
  6833. try {
  6834. promise = f();
  6835. } catch (e) { e_ = e }
  6836. delete asyncProto.yieldResult;
  6837. yieldResultWrappingByPass = false;
  6838. } else {
  6839. Object.defineProperty(Object.prototype, 'yieldResult', {
  6840. get() {
  6841. return undefined;
  6842. },
  6843. set(nv) {
  6844. delete Object.prototype.yieldResult;
  6845. this.yieldResult = nv;
  6846. D = this;
  6847. // console.log(122, this);
  6848. return true;
  6849. },
  6850. enumerable: false,
  6851. configurable: true
  6852. });
  6853. try {
  6854. promise = f();
  6855. } catch (e) { e_ = e }
  6856. delete Object.prototype.yieldResult;
  6857. yieldResultWrappingByPass = false;
  6858. if (D) {
  6859. asyncProto = Reflect.getPrototypeOf(D);
  6860. }
  6861. }
  6862. if (e_) throw e_;
  6863. return [promise, D];
  6864. }
  6865.  
  6866. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  6867.  
  6868. const aProto = Reflect.getPrototypeOf(activeModule);
  6869.  
  6870. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  6871.  
  6872. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  6873.  
  6874. // console.log(12885)
  6875. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  6876. // let qxt=false;
  6877. aProto.fetchUpdatedMetadata = function (t, P) {
  6878.  
  6879. // if (!qxt) {
  6880. // qxt = true;
  6881. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  6882. // console.log(199001,...args)
  6883. // });
  6884. // this.addOnDisposeCallback(function (...args) {
  6885.  
  6886. // console.log(199002,...args)
  6887. // watchController.unsubscribeByKey(y)
  6888. // qxt = false;
  6889. // });
  6890. // }
  6891. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  6892. if (D) promise.then(() => {
  6893. const yieldResult = D.yieldResult;
  6894. if (yieldResult) {
  6895. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  6896.  
  6897. if (mutations && mutations.length >= 1) {
  6898. let likeCountEntity = null;
  6899. for (const mutation of mutations) {
  6900. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  6901. break;
  6902. }
  6903. }
  6904. if (likeCountEntity) {
  6905. const model = insp(document.querySelector('segmented-like-dislike-button-view-model'));
  6906. if (model && typeof model.update === 'function' && model.update.length === 0) {
  6907. const data = ((model || 0).props || 0).data;
  6908. if (data) {
  6909. if (typeof data.likeCountEntity !== 'object') data.likeCountEntity = {};
  6910. // console.log(12838, {...data.likeCountEntity}, {...likeCountEntity})
  6911. // const shouldModelUpdate = (data.likeCountEntity.key !== likeCountEntity.key); // to be reviewed
  6912. const shouldModelUpdate = true;
  6913. Object.assign(data.likeCountEntity, likeCountEntity);
  6914. // data.likeCountEntity = likeCountEntity;
  6915. // if (shouldModelupdate) model.update();
  6916. // else {
  6917. // if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  6918. // }
  6919.  
  6920. if (shouldModelUpdate) {
  6921. if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  6922. // console.log('kk1a enqueueUpdate')
  6923. model.enqueueUpdate();
  6924. // console.log('kk1b enqueueUpdate')
  6925. } else if (typeof model.update === 'function' && model.update.length === 0) {
  6926. // console.log('kk2a update')
  6927. model.update();
  6928. // console.log('kk2b update')
  6929. } else {
  6930. console.warn('[yt-js-engine-tamer] cannot do model update.')
  6931. }
  6932. }
  6933.  
  6934. }
  6935. }
  6936. }
  6937. }
  6938. }
  6939. }).catch(console.warn);
  6940. return promise;
  6941. };
  6942.  
  6943. }
  6944.  
  6945. }
  6946.  
  6947. /*
  6948. let cid = 0;
  6949.  
  6950. document.addEventListener('transitionrun', function(evt){
  6951.  
  6952. if(!evt || !evt.isTrusted || evt.propertyName !== 'margin-top' || !evt.target) return;
  6953.  
  6954. if (evt.target.nodeName !== 'ANIMATED-ROLLING-CHARACTER') return;
  6955.  
  6956.  
  6957.  
  6958.  
  6959. const target = evt.target;
  6960. let finish = false;
  6961. if (target.getAttribute('style-old126') === target.getAttribute('style')) finish = true;
  6962. else target.setAttribute('style-old126', target.getAttribute('style'));
  6963.  
  6964. target.setAttribute('should-finish', finish ? 'true' : 'false');
  6965.  
  6966.  
  6967. const animations = (document.timeline || 0)._animations;
  6968. if (!animations || !animations.length) return;
  6969.  
  6970. let aa = [...animations].filter(e => e.effect.target.hasAttribute('a85j2'));
  6971. if (!aa.length) return;
  6972.  
  6973. for (const a of aa) {
  6974.  
  6975. const s = a.effect.target;
  6976. if (s !== evt.target) continue;
  6977. if (a.eut33 && Date.now() - a.eut33 < 600) continue;
  6978. a.eut33 = Date.now();
  6979.  
  6980. if (finish) a.finish();
  6981.  
  6982.  
  6983. }
  6984.  
  6985. // console.log(1848);
  6986. }, true);
  6987. */
  6988.  
  6989.  
  6990. /*
  6991. let rnf33 = 0;
  6992.  
  6993. const rollingNumberFindMo = new MutationObserver(()=>{
  6994. for(const s of document.querySelectorAll('animated-rolling-character[style]:not([a85j2])')){
  6995.  
  6996. if(rnf33===0) {
  6997. rnf33= 1;
  6998.  
  6999.  
  7000. if (!document.getElementById('rnf33_script')) {
  7001. const style = document.createElement('style');
  7002. style.id = 'rnf33_script';
  7003. style.textContent = `
  7004. .rolling-no-move{
  7005. transition-duration: 0.0001s !important;
  7006. animation-duration: 0.0001s !important;
  7007. }
  7008. `;
  7009. (document.head || document.documentElement).appendChild(style);
  7010. }
  7011.  
  7012. }
  7013.  
  7014. s.setAttribute('a85j2','');
  7015. s.classList.add('rolling-no-move');
  7016. s.setAttribute('style-old126', s.getAttribute('style'));
  7017. }
  7018.  
  7019. });
  7020. rollingNumberFindMo.observe(document, {subtree: true, childList: true})
  7021. */
  7022.  
  7023. // ----------------------------
  7024.  
  7025.  
  7026. // const pendingStampFlushs = [];
  7027.  
  7028. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  7029.  
  7030. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  7031.  
  7032. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  7033.  
  7034.  
  7035. // const globalPromiseStack = {};
  7036.  
  7037. // let dummy;
  7038. // while(!dummy){
  7039.  
  7040. // dummy = document.querySelector('yt-icon');
  7041. // await new Promise(r=>setTimeout(r,0));
  7042. // }
  7043.  
  7044. dummy = document.createElement('yt-icon');
  7045.  
  7046. let cProto;
  7047. if (!(dummy instanceof Element)) return;
  7048. cProto = insp(dummy).constructor.prototype;
  7049.  
  7050. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  7051. cProto.determineIconSet671 = cProto.determineIconSet;
  7052. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  7053. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  7054. cProto.getIconManager671 = cProto.getIconManager;
  7055. cProto.getIconShapeData671 = cProto.getIconShapeData;
  7056. cProto.renderIcon671 = cProto.renderIcon;
  7057.  
  7058. // cProto.attached488 = cProto.attached;
  7059. // cProto.attached = function(){
  7060. // console.log('attached')
  7061. // return this.attached488(...arguments);
  7062. // }
  7063. // cProto.detached488 = cProto.detached;
  7064. // cProto.detached = function(){
  7065. // console.log('detached')
  7066. // return this.detached488(...arguments);
  7067. // }
  7068.  
  7069. if (cProto.__renderIconFix__) return;
  7070. cProto.__renderIconFix__ = true;
  7071.  
  7072. let taskStack = [];
  7073. const cmObs = new MutationObserver(() => {
  7074. const tasks = taskStack.slice();
  7075. taskStack.length = 0;
  7076. for (const task of tasks) {
  7077. task();
  7078. }
  7079. })
  7080. const cm = document.createComment('1');
  7081. const stackTask = (f) => {
  7082. taskStack.push(f);
  7083. cm.data = `${(cm.data & 7) + 1}`;
  7084. }
  7085. cmObs.observe(cm, { characterData: true });
  7086.  
  7087. // let iconManagers = {}; // assume shared
  7088.  
  7089. // window.iconManagers = () => iconManagers;
  7090.  
  7091.  
  7092. const setupYtIcon = (inst) => {
  7093.  
  7094. if (inst.__ytIconSetup588__) return;
  7095. const cProto = Reflect.getPrototypeOf(inst);
  7096. cProto.__ytIconSetup588__ = true;
  7097.  
  7098.  
  7099. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  7100.  
  7101. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  7102. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  7103. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  7104. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  7105.  
  7106.  
  7107. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  7108. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  7109. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  7110. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  7111.  
  7112.  
  7113.  
  7114. }
  7115.  
  7116. cProto.handlePropertyChange = function (...a) { // 10+
  7117.  
  7118. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7119. this.__resolved__ = {
  7120.  
  7121. };
  7122. const a01 = this.isAttached;
  7123. let a02, a03;
  7124.  
  7125.  
  7126. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  7127.  
  7128. const stackFn = () => {
  7129. if (t !== this.__stackedKey3818__) {
  7130. return;
  7131. }
  7132. a03 = this.isAttached;
  7133.  
  7134. if (a01 === false && a02 === false && a03 === false) return;
  7135.  
  7136. if (a01 === true && a02 === true && a03 === true) {
  7137.  
  7138. } else {
  7139. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  7140. // unknown yt-icon#label-icon
  7141. return;
  7142. } else {
  7143. console.log('[yt-icon] debug', a01, a02, a03, this)
  7144. }
  7145. }
  7146.  
  7147. this.handlePropertyChange671(...arguments);
  7148.  
  7149. };
  7150.  
  7151.  
  7152.  
  7153. Promise.resolve().then(() => {
  7154. a02 = this.isAttached;
  7155. stackTask(stackFn);
  7156. });
  7157.  
  7158.  
  7159. }
  7160.  
  7161. cProto.determineIconSet = function (a, b, c, d) { // 10-
  7162.  
  7163. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7164. // string bool? bool=false int=24
  7165. // NOTIFICATIONS_NONE OR LIKE
  7166. // console.log('yt-icon.determineIconSet', ...arguments);
  7167.  
  7168. const r = this.determineIconSet671(...arguments);
  7169. return r;
  7170. }
  7171.  
  7172. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  7173.  
  7174. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7175. // same as determineIconSet
  7176. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  7177. return this.switchToYtSysIconset671(...arguments);
  7178. }
  7179.  
  7180. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  7181.  
  7182. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7183. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  7184. return this.useYtSysIconsetForMissingIcons671(...arguments);
  7185. }
  7186.  
  7187. cProto.getIconManager = function () { // 10+
  7188.  
  7189. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7190. if (!this.__resolved__) this.__resolved__ = {};
  7191. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  7192. const r = this.__resolved__.getIconManager;
  7193. return r;
  7194. }
  7195.  
  7196. cProto.getIconShapeData = function () { // 10+
  7197.  
  7198. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7199.  
  7200. // no argument
  7201. // console.log('yt-icon.getIconShapeData', ...arguments);
  7202. if (!this.__resolved__) this.__resolved__ = {};
  7203. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  7204. const r = this.__resolved__.getIconShapeData;
  7205. return r
  7206. }
  7207.  
  7208. cProto.renderIcon = function (a, b) { // X
  7209.  
  7210. if (!this.__ytIconSetup588__) setupYtIcon(this);
  7211. // "" yt-icons:xxx
  7212. // console.log('yt-icon.renderIcon', ...arguments);
  7213. return this.renderIcon671(...arguments);
  7214. }
  7215.  
  7216. });
  7217.  
  7218.  
  7219. /**
  7220. * Compute the Longest Common Subsequence between two arrays.
  7221. * Returns an array of the LCS elements (in order).
  7222. */
  7223. function computeLCS(a, b) {
  7224. // Input validation
  7225. if (!Array.isArray(a) || !Array.isArray(b)) {
  7226. throw new Error('Inputs must be arrays');
  7227. }
  7228.  
  7229. const n = a.length, m = b.length;
  7230. // Early termination for trivial cases
  7231. if (n === 0 || m === 0) return [];
  7232. // Check for shallow equality
  7233. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  7234.  
  7235. // Use smaller dimension for space optimization
  7236. if (n > m) return computeLCS(b, a); // Ensure n <= m
  7237.  
  7238. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  7239. // Use Uint32Array for robustness with long sequences
  7240. const dp = [
  7241. new Uint32Array(m + 1),
  7242. new Uint32Array(m + 1),
  7243. ];
  7244. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  7245. // Optimize space by storing only necessary entries
  7246. const pred = new Uint8Array(n * m); // Single array for moves
  7247.  
  7248. for (let i = n - 1; i >= 0; i--) {
  7249. const curr = i % 2;
  7250. const next = 1 - curr;
  7251. // Clear current row for reuse
  7252. dp[curr].fill(0);
  7253.  
  7254. for (let j = m - 1; j >= 0; j--) {
  7255. const idx = i * m + j;
  7256. if (a[i] === b[j]) {
  7257. dp[curr][j] = dp[next][j + 1] + 1;
  7258. pred[idx] = 0; // Diagonal
  7259. } else if (dp[next][j] >= dp[curr][j + 1]) {
  7260. dp[curr][j] = dp[next][j];
  7261. pred[idx] = 1; // Down
  7262. } else {
  7263. dp[curr][j] = dp[curr][j + 1];
  7264. pred[idx] = 2; // Right
  7265. }
  7266. }
  7267. }
  7268.  
  7269. // Check for potential overflow
  7270. if (dp[0][0] > 0xFFFFFFFF) {
  7271. throw new Error('LCS length exceeds safe integer limit');
  7272. }
  7273.  
  7274. // Backtrack to build the actual LCS
  7275. const lcs = [];
  7276. let i = 0, j = 0;
  7277. while (i < n && j < m) {
  7278. const idx = i * m + j;
  7279. const p = pred[idx];
  7280. if (p === 0) {
  7281. lcs.push(a[i]);
  7282. i++; j++;
  7283. } else if (p === 1) {
  7284. i++;
  7285. } else {
  7286. j++;
  7287. }
  7288. }
  7289. return lcs;
  7290. }
  7291.  
  7292. /**
  7293. * Given original[] and modified[], produce an array of splice-ops:
  7294. * [ [start0, deleteCount0, addedItems0],
  7295. * [start1, deleteCount1, addedItems1],
  7296. * … ]
  7297. * When you do:
  7298. * let arr = original.slice();
  7299. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  7300. * arr will equal modified.
  7301. */
  7302. function diffSplices(original, modified) {
  7303. // Input validation
  7304. if (!Array.isArray(original) || !Array.isArray(modified)) {
  7305. throw new Error('Inputs must be arrays');
  7306. }
  7307.  
  7308. const origLen = original.length;
  7309. const modLen = modified.length;
  7310. // Early termination for trivial cases
  7311. if (origLen === 0 && modLen === 0) return [];
  7312. if (origLen === 0) return [[0, 0, modified.slice()]];
  7313. if (modLen === 0) return [[0, origLen, []]];
  7314.  
  7315. // Trim common prefix and suffix
  7316. let prefixLen = 0;
  7317. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  7318. prefixLen++;
  7319. }
  7320. let suffixLen = 0;
  7321. while (
  7322. suffixLen < origLen - prefixLen &&
  7323. suffixLen < modLen - prefixLen &&
  7324. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  7325. ) {
  7326. suffixLen++;
  7327. }
  7328.  
  7329. // Cache references for speed
  7330. const orig = original.slice(prefixLen, origLen - suffixLen);
  7331. const mod = modified.slice(prefixLen, modLen - suffixLen);
  7332. const lcs = computeLCS(orig, mod);
  7333. // Pre-allocate ops array, accounting for potential moves
  7334. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  7335. let opCount = 0;
  7336.  
  7337. let i = 0, j = 0, k = 0;
  7338. let curIndex = prefixLen;
  7339. const lcsLen = lcs.length;
  7340.  
  7341. while (k < lcsLen) {
  7342. const match = lcs[k];
  7343. let deleteCount = 0;
  7344. const deleted = [];
  7345. const added = [];
  7346.  
  7347. // 1) Collect deletions up to the next common element
  7348. while (i < orig.length && orig[i] !== match) {
  7349. deleted.push(orig[i]);
  7350. deleteCount++;
  7351. i++;
  7352. }
  7353.  
  7354. // 2) Collect insertions up to that same element
  7355. while (j < mod.length && mod[j] !== match) {
  7356. added.push(mod[j]);
  7357. j++;
  7358. }
  7359.  
  7360. // 3) Check for a move (deleted segment matches inserted segment)
  7361. let isMove = false;
  7362. if (deleteCount > 0 && deleteCount === added.length) {
  7363. isMove = deleted.every((x, idx) => x === added[idx]);
  7364. if (isMove) {
  7365. // If a move, split into delete and insert at different indices
  7366. if (deleteCount > 0) {
  7367. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  7368. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  7369. curIndex += added.length; // Advance past inserted items
  7370. }
  7371. }
  7372. }
  7373.  
  7374. // 4) Combine delete and insert into a single operation if not a move
  7375. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  7376. ops[opCount++] = [curIndex, deleteCount, added];
  7377. curIndex += added.length; // Advance past inserted items
  7378. }
  7379.  
  7380. // 5) Skip over the matching element itself
  7381. i++;
  7382. j++;
  7383. k++;
  7384. curIndex++;
  7385. }
  7386.  
  7387. // 6) Handle any trailing deletions and insertions as a single operation
  7388. const trailingDelete = orig.length - i;
  7389. const trailingAdd = mod.slice(j);
  7390. if (trailingDelete > 0 || trailingAdd.length > 0) {
  7391. // Check for trailing move
  7392. const trailingDeleted = orig.slice(i);
  7393. let isMove = false;
  7394. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  7395. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  7396. if (isMove) {
  7397. ops[opCount++] = [curIndex, trailingDelete, []];
  7398. ops[opCount++] = [curIndex, 0, trailingAdd];
  7399. }
  7400. }
  7401. if (!isMove) {
  7402. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  7403. }
  7404. }
  7405.  
  7406. // 7) Truncate ops array to actual size
  7407. ops.length = opCount;
  7408.  
  7409. return ops;
  7410. }
  7411. // class listPlaceholder {
  7412. // constructor(len){
  7413. // this.length = len;
  7414. // }
  7415. // }
  7416.  
  7417.  
  7418.  
  7419. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  7420. // var renderJob = this.renderJobsMap_[key],
  7421. // renderCallback = null;
  7422.  
  7423. // if (path === changeRecord.path) {
  7424. // let value = changeRecord.value;
  7425.  
  7426. // if (!_.v_(value)) {
  7427. // value = (value === void 0 || value === null) ? [] : [value];
  7428. // }
  7429.  
  7430. // let stampDomEntry = this.stampDom[path];
  7431.  
  7432. // if (stampDomEntry.mapping) {
  7433. // renderCallback = this.stampDomArray_.bind(
  7434. // this,
  7435. // value,
  7436. // key,
  7437. // stampDomEntry.mapping,
  7438. // stampDomEntry.reuseComponents,
  7439. // stampDomEntry.events,
  7440. // stampDomEntry.stamperStableList
  7441. // );
  7442. // }
  7443.  
  7444. // if (renderJob) renderJob.cancel();
  7445.  
  7446. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  7447.  
  7448. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  7449. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  7450. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  7451. // this.renderJobsMap_[key] = renderJob;
  7452. // }
  7453. // } else {
  7454. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  7455. // this.renderJobsMap_[key] = renderJob;
  7456. // renderCallback = function(callback, job) {
  7457. // callback();
  7458. // q4C(job, 10);
  7459. // }.bind(this, renderCallback, renderJob);
  7460. // }
  7461. // } else {
  7462. // renderCallback = (path + ".splices" === changeRecord.path)
  7463. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  7464. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  7465. // }
  7466.  
  7467. // if (renderJob) {
  7468. // _.vY(renderJob, renderCallback);
  7469. // } else {
  7470. // renderCallback();
  7471. // }
  7472. // }
  7473.  
  7474.  
  7475.  
  7476.  
  7477. const createStampDomFnsC_ = () => {
  7478.  
  7479. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  7480.  
  7481. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  7482. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  7483.  
  7484.  
  7485. // const rq0 = document.createElement('rp');
  7486. // rq0.setAttribute('yt-element-placholder', '');
  7487.  
  7488. const it0 = Date.now() - 80000000000;
  7489. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  7490.  
  7491.  
  7492. const getStampContainer_ = function (containerId) {
  7493.  
  7494. return this.getStampContainer7409_(containerId);
  7495.  
  7496. }
  7497.  
  7498.  
  7499.  
  7500.  
  7501. const createComponent_ = function (componentConfig, data, canReuse) {
  7502.  
  7503. return this.createComponent7409_(componentConfig, data, canReuse);
  7504.  
  7505. }
  7506.  
  7507.  
  7508. const s52 = Symbol();
  7509.  
  7510. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  7511.  
  7512. // if(component.querySelectorAll('dom-if').length > 0){
  7513.  
  7514. // // console.log(1233, component.isConnected, component.parentNode, component.querySelectorAll('dom-if'))
  7515. // if (component.isConnected === false) {
  7516. // for (const s of component.querySelectorAll('dom-if')) {
  7517. // try {
  7518. // console.log(1299);
  7519. // insp(s).__teardownInstance();
  7520. // } catch (e) { }
  7521. // }
  7522. // }
  7523.  
  7524. // }
  7525.  
  7526. if (typeof (data || 0) === 'object') {
  7527. if (!data[s52]) data[s52] = genId();
  7528. component[s52] = data[s52];
  7529. // console.log(component[s52], data);
  7530. } else {
  7531. component[s52] = null;
  7532. }
  7533.  
  7534. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7535.  
  7536. }
  7537.  
  7538. // let pr77 = Promise.resolve();
  7539.  
  7540. const flushRenderStamperComponentBindings_ = function () {
  7541. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  7542.  
  7543. if (this.deferredBindingTasks_.length >= 0) {
  7544.  
  7545. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  7546.  
  7547. const gid = this[`__$$stampFlushKey$$__`] = genId();
  7548. const g = (() => {
  7549. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  7550. // if (deferredBindingTasks_.length === 0) return;
  7551. // let q = this.deferredBindingTasks_;
  7552. // this.deferredBindingTasks_ = deferredBindingTasks_;
  7553. this.flushRenderStamperComponentBindings7409_();
  7554. // deferredBindingTasks_.length = 0;
  7555. // this.deferredBindingTasks_ = q;
  7556.  
  7557. const s = [...this.__lat457__];
  7558. this.__lat457__.clear();
  7559.  
  7560. for (const containerWr of s) {
  7561.  
  7562. const container = kRef(containerWr);
  7563. if (!container) continue;
  7564.  
  7565. // const s = new Set();
  7566. if (!container.querySelector('[ytx-flushing]')) {
  7567. if (container.hasAttribute('ytx-flushing')) {
  7568. const attrVal = container.getAttribute('ytx-flushing');
  7569. container.removeAttribute('ytx-flushing');
  7570. // s.add([container, attrVal]);
  7571. addTask(container, attrVal);
  7572. // addTaskIm(container, attrVal);
  7573. let ancestor = container.closest('[ytx-flushing]');
  7574. while (ancestor) {
  7575. if (ancestor.querySelector('[ytx-flushing]')) break;
  7576. const attrVal = ancestor.getAttribute('ytx-flushing');
  7577. ancestor.removeAttribute('ytx-flushing');
  7578. // s.add([ancestor, attrVal]);
  7579. addTask(ancestor, attrVal);
  7580. // addTaskIm(ancestor, attrVal);
  7581. ancestor = ancestor.closest('[ytx-flushing]');
  7582. }
  7583. }
  7584. }
  7585. }
  7586. executeTasks();
  7587.  
  7588.  
  7589. });
  7590. g();
  7591. // const useMicroTaskQueue = this.__qsd477__ === 2;
  7592. // useMicroTaskQueue ? addTask2(g) : g();
  7593. // executeTasks();
  7594.  
  7595. // addTask2(g);
  7596. // executeTasks();
  7597.  
  7598. }
  7599.  
  7600. throw new Error('e5bd8d2f');
  7601.  
  7602. }
  7603.  
  7604. let tasks = [];
  7605. let excuted = false;
  7606. const executeTasks = ()=>{
  7607. if(excuted || tasks.length === 0) return;
  7608. excuted = true;
  7609. let t0 = 0;
  7610. const perform = ()=>{
  7611. if(!t0) t0 = nativeNow();
  7612. const task = tasks.shift();
  7613. if(!task){
  7614. excuted = false;
  7615. return;
  7616. }
  7617. task.fn(task);
  7618. const t1 = nativeNow();
  7619. if(t1 - t0 > 10){
  7620. t0 = 0;
  7621. nextBrowserTick_(perform);
  7622. }else{
  7623. queueMicrotask_(perform);
  7624. }
  7625. }
  7626. queueMicrotask_(perform);
  7627. }
  7628.  
  7629. const taskFn = (task) => {
  7630.  
  7631. if(!task) return;
  7632. const { containerWr, attrVal } = task;
  7633. const container = kRef(containerWr);
  7634. if (!container) return;
  7635. if (attrVal === '0') return;
  7636. const bEventCb = attrVal === '2';
  7637. const producerWr = containerMapping.get(container);
  7638. const producer = kRef(producerWr);
  7639. if (!producer) return;
  7640. const hostElement = producer.hostElement;
  7641. if (!hostElement) return;
  7642. if (hostElement.isConnected !== true) return; // tbc
  7643. producer.markDirty && producer.markDirty();
  7644. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  7645. container
  7646. });
  7647.  
  7648. }
  7649.  
  7650. const addTask = (container, attrVal) => {
  7651. if (!container) return;
  7652. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7653. tasks.push({
  7654. fn: taskFn,
  7655. containerWr: containerWr,
  7656. attrVal
  7657. });
  7658. // pr77 = pr77.then(()=>{
  7659.  
  7660. // })
  7661. // taskFn({
  7662. // containerWr: containerWr,
  7663. // attrVal
  7664. // })
  7665.  
  7666. }
  7667.  
  7668. const addTaskIm = (container, attrVal) => {
  7669. if (!container) return;
  7670. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7671. taskFn({
  7672. fn: taskFn,
  7673. containerWr: containerWr,
  7674. attrVal
  7675. });
  7676.  
  7677. }
  7678.  
  7679.  
  7680. const addTask2 = (f) => {
  7681. // pr77 = pr77.then(f).catch(console.warn);
  7682. tasks.push({
  7683. fn: f
  7684. });
  7685.  
  7686. }
  7687.  
  7688. // const mo = new MutationObserver((mutations)=>{
  7689.  
  7690. // });
  7691. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  7692.  
  7693. const containerMapping = new WeakMap();
  7694.  
  7695. // let pr77 = Promise.resolve();
  7696. // let pr88 = Promise.resolve();
  7697. const uA4 = function (t, P) {
  7698. for (let y in t)
  7699. if (t.hasOwnProperty(y) && P[y])
  7700. return y;
  7701. return null
  7702. }
  7703.  
  7704. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  7705.  
  7706. const ax = ax_;
  7707. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  7708. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  7709. // const useMicroTaskQueue = false;
  7710. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  7711. ax[2].cancel();
  7712. useMicroTaskQueue2 = false;
  7713. }
  7714. // console.log(1992,containerId, this.hostElement.is)
  7715.  
  7716. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  7717. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  7718. // return false;
  7719.  
  7720. // }
  7721.  
  7722. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  7723. return false;
  7724. }
  7725.  
  7726. const hostIs = hostIs_;
  7727.  
  7728. 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;
  7729.  
  7730. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  7731. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  7732. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  7733. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  7734. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  7735. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  7736. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  7737. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  7738. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  7739. 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;
  7740. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  7741. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  7742. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  7743. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  7744. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  7745. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  7746. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  7747. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  7748. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  7749.  
  7750.  
  7751. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  7752.  
  7753.  
  7754. // console.log(5992,stackAt)
  7755.  
  7756. // console.log(2883, this[`__quu477#${containerId}__`] )
  7757. // if (useMicroTaskQueue) {
  7758. // console.log(stackAt)
  7759. // }
  7760.  
  7761. // if (useMicroTaskQueue) {
  7762. // console.log(1120301)
  7763. // }
  7764.  
  7765. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  7766.  
  7767. return useMicroTaskQueue2;
  7768.  
  7769. }
  7770.  
  7771. const frag385 = document.createDocumentFragment();
  7772. frag385.appendChild4202 = frag385.appendChild;
  7773. frag385.removeChild4202 = frag385.removeChild;
  7774. const cm385 = document.createComment('.');
  7775.  
  7776. const doc385 = document.implementation.createHTMLDocument();
  7777. const html385 = doc385.firstElementChild;
  7778. const node385 = html385.appendChild(document.createElement('div'));
  7779.  
  7780. const fixContainerApi = (container) => {
  7781. if (container instanceof Node) {
  7782. const containerDomApi = container.__domApi;
  7783. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  7784. // console.log(123882, container)
  7785. containerDomApi.removeChild588 = containerDomApi.removeChild;
  7786. containerDomApi.removeChild = function (elem) {
  7787. let r;
  7788. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7789. s.setAttribute('ytx-flushing', '0');
  7790. }
  7791. try {
  7792. r = this.removeChild588(elem);
  7793. } catch (e) { }
  7794. if (!r) {
  7795. frag385.appendChild4202(elem);
  7796. frag385.removeChild4202(elem);
  7797. r = elem;
  7798. }
  7799. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7800. s.removeAttribute('ytx-flushing');
  7801. }
  7802. return r;
  7803. }
  7804. }
  7805. }
  7806. }
  7807.  
  7808. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7809.  
  7810. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7811. if (typeof sqq === 'function') sqq();
  7812.  
  7813. // trigger in rendererStamperApplyChangeRecord_
  7814.  
  7815. // 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];
  7816. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7817. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7818. // 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];
  7819.  
  7820. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7821. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7822.  
  7823.  
  7824. const ax = this[`__quu477#${containerId}__`];
  7825. const hostIs = (this.hostElement || 0).is;
  7826. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7827.  
  7828. const container = this.getStampContainer7409_(containerId);
  7829. const pChildren = [...container.children];
  7830.  
  7831. containerMapping.set(container,
  7832. (this[wk] || (this[wk] = mWeakRef(this)))
  7833. );
  7834.  
  7835. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7836. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7837.  
  7838. // let dataList_ = dataList;
  7839. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  7840.  
  7841. dataList = null;
  7842. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  7843. let fq = 0;
  7844. const f = (() => {
  7845. if(fq) return;
  7846. fq = 1;
  7847. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7848. this[`__$$stampSFn$$#${containerId}__`] = null;
  7849. const container = this.getStampContainer7409_(containerId);
  7850.  
  7851. this.__lat457__ = this.__lat457__ || new Set();
  7852. if(!container[wk]) container[wk] = mWeakRef(container);
  7853. this.__lat457__.add(container[wk]);
  7854. fixContainerApi(container);
  7855.  
  7856. // let q = this.deferredBindingTasks_;
  7857. // this.deferredBindingTasks_ = [];
  7858. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7859. let e_;
  7860. try {
  7861. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  7862. } catch (e) { e_ = e }
  7863. this.__qsd477__ = false;
  7864. dataList_ = typeOrConfig = null;
  7865. fixContainerApi(container);
  7866. // this.deferredBindingTasks_ = q;
  7867. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7868. if (!e_) {
  7869. // container.setAttribute('ytx-flushing', '0');
  7870. }
  7871. // if( container.childElementCount === 0 ){
  7872. // container.setAttribute('ytx-flushing', '0');
  7873. // this.markDirty && this.markDirty();
  7874. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  7875. // container
  7876. // });
  7877. // }
  7878.  
  7879.  
  7880.  
  7881.  
  7882. });
  7883. this[`__$$stampSFn$$#${containerId}__`] = f;
  7884. this[`__$$stampSqq$$#${containerId}__`] = f;
  7885. useMicroTaskQueue2 ? addTask2(f) : f();
  7886. executeTasks();
  7887.  
  7888. for (const node of pChildren) {
  7889. if (node.isConnected === false) {
  7890. _removedElements.addNode(node);
  7891. }
  7892. }
  7893.  
  7894. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  7895.  
  7896. return undefined;
  7897.  
  7898. }
  7899.  
  7900. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  7901.  
  7902.  
  7903. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7904. if (typeof sqq === 'function') sqq();
  7905.  
  7906. // trigger in rendererStamperApplyChangeRecord_
  7907.  
  7908. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7909. } else {
  7910. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7911. }
  7912.  
  7913.  
  7914. // trigger in rendererStamperApplyChangeRecord_
  7915.  
  7916. // 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];
  7917. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7918. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7919.  
  7920. // 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];
  7921.  
  7922. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7923. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7924. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  7925.  
  7926. const ax = this[`__quu477#${containerId}__`];
  7927. const hostIs = (this.hostElement || 0).is;
  7928. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7929.  
  7930.  
  7931. // 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];
  7932. // const useMicroTaskQueue = true;
  7933. const container = this.getStampContainer7409_(containerId);
  7934.  
  7935. containerMapping.set(container,
  7936. (this[wk] || (this[wk] = mWeakRef(this)))
  7937. );
  7938. const bEventCb = this.stampDom[stampKey].events;
  7939. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7940. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7941.  
  7942. // let indexSplicesObj_ = indexSplicesObj;
  7943. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7944. // indexSplicesObj_ = {
  7945. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  7946. // const { index, addedCount, removed, object, type } = slice;
  7947. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7948. // return { index, addedCount, removed, object, type };
  7949. // })
  7950. // };
  7951. // }
  7952.  
  7953.  
  7954. indexSplicesObj.indexSplices.forEach(slice => {
  7955. const object = slice.object;
  7956. if (!object || typeof object !== 'object') return;
  7957. // const { index, addedCount, removed, object, type } = slice;
  7958. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7959. // return { index, addedCount, removed, object, type };
  7960. });
  7961.  
  7962. // let indexSplicesObj_ = indexSplicesObj;
  7963.  
  7964. // console.log(128783, indexSplicesObj)
  7965.  
  7966. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  7967. // const { index, addedCount, removed, object, type } = slice;
  7968. // return { index, addedCount, removed, object, type };
  7969. // });
  7970.  
  7971. indexSplicesObj = null;
  7972.  
  7973. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  7974. const gid = this[`__$$stampSID$$#${containerId}__`];
  7975. let fq = 0;
  7976. const f = (() => {
  7977. if(fq) return;
  7978. fq = 1;
  7979. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7980. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  7981. const container = this.getStampContainer7409_(containerId);
  7982. if(!container) return;
  7983.  
  7984. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  7985.  
  7986. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  7987. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  7988. const mapping = this.stampDom[stampKey].mapping;
  7989.  
  7990. const map = new Map();
  7991.  
  7992. const currentObjKeys = object.map(objEntry => {
  7993. const mappingKey = uA4(mapping, objEntry);
  7994. if(!mappingKey) return null;
  7995. const data = objEntry[mappingKey];
  7996. if (!data[s52]) data[s52] = genId();
  7997. map.set(data[s52], objEntry);
  7998. // return ({
  7999. // objEntry,
  8000. // data: data,
  8001. // mappingKey: mappingKey,
  8002. // key: data[s52],
  8003. // exist: elementKeys.has(data[s52])
  8004. // });
  8005. return data[s52]
  8006.  
  8007. });
  8008.  
  8009. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  8010.  
  8011. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  8012.  
  8013. const splices = diffSplices(oldDomKeys, currentObjKeys);
  8014.  
  8015. // let myObject = object;
  8016. let indexSplicesObj_ = {
  8017. indexSplices: splices.map(splice => {
  8018. const index = splice[0];
  8019. const removedLen = splice[1];
  8020. const added = splice[2];
  8021. const addedCount = added.length;
  8022. const object = {};
  8023. object.length = index + addedCount;
  8024. for (let i = 0; i < addedCount; i++) {
  8025. object[index + i] = map.get(added[i]);
  8026. }
  8027. const removed = {};
  8028. removed.length = removedLen;
  8029.  
  8030. return { index, removed, object, addedCount }
  8031. })
  8032. };
  8033. map.clear();
  8034.  
  8035.  
  8036. this.__lat457__ = this.__lat457__ || new Set();
  8037. if(!container[wk]) container[wk] = mWeakRef(container);
  8038. this.__lat457__.add(container[wk]);
  8039. fixContainerApi(container);
  8040.  
  8041. // console.log(3882, indexSplicesObj_)
  8042. // let q = this.deferredBindingTasks_;
  8043. // this.deferredBindingTasks_ = [];
  8044. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  8045. let e_;
  8046. try {
  8047. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  8048. } catch (e) { e_ = e; }
  8049. this.__qsd477__ = false;
  8050. indexSplicesObj_ = null;
  8051. stampKey = indexSplicesObj_ = null;
  8052. fixContainerApi(container);
  8053. // this.deferredBindingTasks_ = q;
  8054. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  8055. if (!e_) {
  8056. // container.setAttribute('ytx-flushing', '0');
  8057. }
  8058.  
  8059.  
  8060. });
  8061. this[`__$$stampSqq$$#${containerId}__`] = f;
  8062. useMicroTaskQueue2 ? addTask2(f) : f();
  8063. executeTasks();
  8064.  
  8065. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  8066.  
  8067. return undefined;
  8068.  
  8069. }
  8070.  
  8071.  
  8072. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  8073. const dt0 = dt0a[0];
  8074. const dt1 = Date.now();
  8075. const obj = kRef(objWr);
  8076. if (!obj) return;
  8077. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  8078. if (xxx !== xxx_) return;
  8079. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  8080. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  8081. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  8082. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  8083. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  8084. const renderJob1 = obj.renderJobsMap_[containerId]
  8085. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  8086. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  8087. let e_, r;
  8088. try {
  8089. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  8090. } catch (e) {
  8091. e_ = e;
  8092. }
  8093. obj[`__quu477#${containerId}__`] = false;
  8094. if (e_) throw e_;
  8095. return r;
  8096. };
  8097.  
  8098.  
  8099. stampDomArray_.bind = function (obj, ...args) {
  8100. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  8101. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  8102. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  8103. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  8104. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  8105. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  8106. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  8107. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  8108. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  8109.  
  8110.  
  8111. const renderJob = obj.renderJobsMap_[containerId];
  8112.  
  8113. const dt0a = [Date.now()];
  8114. queueMicrotask_(() => { dt0a[0] = 0 });
  8115. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  8116. };
  8117.  
  8118. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  8119. const dt0 = dt0a[0];
  8120. const dt1 = Date.now();
  8121. const obj = kRef(objWr);
  8122. if (!obj) return;
  8123. const renderJob1 = obj.renderJobsMap_[containerId];
  8124. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  8125. let e_, r;
  8126. try {
  8127. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  8128. } catch (e) {
  8129. e_ = e;
  8130. }
  8131. obj[`__quu477#${containerId}__`] = false;
  8132. if (e_) throw e_;
  8133. return r;
  8134. };
  8135.  
  8136.  
  8137. stampDomArraySplices_.bind = function (obj, ...args) {
  8138. let [stampKey, containerId, indexSplicesObj] = args;
  8139. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  8140.  
  8141. const renderJob = obj.renderJobsMap_[containerId];
  8142.  
  8143. const dt0a = [Date.now()];
  8144. queueMicrotask_(() => { dt0a[0] = 0 });
  8145. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  8146. };
  8147.  
  8148.  
  8149. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  8150.  
  8151. }
  8152.  
  8153.  
  8154. const createStampDomFnsB_ = () => {
  8155.  
  8156. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  8157.  
  8158. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  8159. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  8160.  
  8161.  
  8162. const rq0 = document.createElement('rp');
  8163. rq0.setAttribute('yt-element-placholder', '');
  8164.  
  8165. let activeStampContainerId = '';
  8166.  
  8167. const componentBasedTaskPool = new WeakMap();
  8168.  
  8169.  
  8170. Node.prototype.checkFF = function () {
  8171. const pTask = componentBasedTaskPool.get(this);
  8172. if (!pTask) return null;
  8173. return [pTask, taskList.filter(e => e.taskId === pTask.taskId), taskList.filter(e => e.componentWr === this[wk])];
  8174. }
  8175.  
  8176. Node.prototype.checkGG = function () {
  8177. window.me849 = this;
  8178. const pTask = componentBasedTaskPool.get(this);
  8179. if (!pTask) return null;
  8180. window.me848 = pTask.taskId;
  8181. debugger;
  8182. loopTask();
  8183. }
  8184.  
  8185. NodeList.prototype.last = function () {
  8186. return this[this.length - 1];
  8187. }
  8188.  
  8189. const getStampContainer_ = function (containerId) {
  8190.  
  8191. // if(this.__byPass828__) return this.getStampContainer7409_(containerId);
  8192.  
  8193. this.__activeContainerId929__ = containerId;
  8194.  
  8195. return this.getStampContainer7409_(containerId);
  8196.  
  8197. }
  8198.  
  8199.  
  8200.  
  8201. const it0 = Date.now() - 80000000000;
  8202. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  8203.  
  8204.  
  8205. const createComponent_ = function (componentConfig, data, canReuse) {
  8206.  
  8207. this.___lastCreate3311__ = data;
  8208.  
  8209.  
  8210.  
  8211. if (this.__directProduction533__) {
  8212. const cName = this.getComponentName_(componentConfig, data);
  8213.  
  8214. return document.createElement(cName);
  8215. }
  8216.  
  8217. if (this.__byPass828__ || !this.__byPass348__) {
  8218.  
  8219. // console.log(39829004)
  8220. // console.log(new Error().stack)
  8221. return this.createComponent7409_(componentConfig, data, false);
  8222. }
  8223.  
  8224.  
  8225. const containerId = this.__activeContainerId929__;
  8226.  
  8227. // console.log(2883007, componentConfig, data, canReuse)
  8228.  
  8229. const r = rq0.cloneNode(false);
  8230.  
  8231. r.is = 'aa-bb-cc-dd';
  8232.  
  8233. return r;
  8234.  
  8235.  
  8236. }
  8237.  
  8238.  
  8239. const childrenObs = new MutationObserver((mutations) => {
  8240. loopTask();
  8241. });
  8242.  
  8243.  
  8244. class CTaskList {
  8245. constructor() {
  8246. this.head = this.tail = null;
  8247.  
  8248. // ref → {prev, next, level}
  8249. this.nodes = new Map();
  8250.  
  8251. // Per‑level sentinels
  8252. this.levelHead = [];
  8253. this.levelTail = [];
  8254.  
  8255. // Sorted list of non‑empty levels for O(log L) neighbour lookup
  8256. this.nonEmptyLevels = [];
  8257. this.counter = 0;
  8258. }
  8259.  
  8260. _ensure(level) {
  8261. while (this.levelTail.length <= level) {
  8262. this.levelTail.push(null);
  8263. this.levelHead.push(null);
  8264. }
  8265. }
  8266.  
  8267. // Binary‑search index inside nonEmptyLevels
  8268. _indexOfLevel(level) {
  8269. let lo = 0, hi = this.nonEmptyLevels.length;
  8270. while (lo < hi) {
  8271. const mid = (lo + hi) >> 1;
  8272. if (this.nonEmptyLevels[mid] < level) lo = mid + 1;
  8273. else hi = mid;
  8274. }
  8275. return lo;
  8276. }
  8277.  
  8278. _link(ref, prev, next, level) {
  8279.  
  8280.  
  8281. this.nodes.set(ref, { prev, next, level });
  8282.  
  8283. if (prev) this.nodes.get(prev).next = ref;
  8284. else this.head = ref;
  8285.  
  8286. if (next) this.nodes.get(next).prev = ref;
  8287. else this.tail = ref;
  8288.  
  8289. this.levelTail[level] = ref;
  8290. if (!this.levelHead[level]) this.levelHead[level] = ref;
  8291. }
  8292.  
  8293. _detach(ref) {
  8294. if (!ref || !this.nodes.has(ref)) return;
  8295.  
  8296.  
  8297. const { prev, next, level } = this.nodes.get(ref);
  8298.  
  8299. if (prev) this.nodes.get(prev).next = next;
  8300. else this.head = next;
  8301.  
  8302. if (next) this.nodes.get(next).prev = prev;
  8303. else this.tail = prev;
  8304.  
  8305. if (this.levelTail[level] === ref) {
  8306. this.levelTail[level] = prev && this.nodes.get(prev)?.level === level ? prev : null;
  8307. }
  8308. if (this.levelHead[level] === ref) {
  8309. this.levelHead[level] = next && this.nodes.get(next)?.level === level ? next : null;
  8310. }
  8311.  
  8312. if (this.levelTail[level] === null) {
  8313. const idx = this.nonEmptyLevels.indexOf(level);
  8314. if (idx !== -1) this.nonEmptyLevels.splice(idx, 1);
  8315. }
  8316.  
  8317. this.nodes.delete(ref);
  8318.  
  8319. }
  8320.  
  8321. push(component, level) {
  8322. if (!component) return;
  8323.  
  8324. // this.checkIntegrity();
  8325.  
  8326. const ref = component[wk] || (component[wk] = new WeakRef(component));
  8327.  
  8328. if (this.nodes.has(ref)) this._detach(ref);
  8329.  
  8330. this._ensure(level);
  8331.  
  8332. if (!this.levelTail[level]) {
  8333. // First node on this level
  8334. const idx = this._indexOfLevel(level);
  8335. const prevLvl = idx ? this.nonEmptyLevels[idx - 1] : null;
  8336. const nextLvl = idx < this.nonEmptyLevels.length ? this.nonEmptyLevels[idx] : null;
  8337.  
  8338. const prevRef = prevLvl !== null ? this.levelTail[prevLvl] : null;
  8339. const nextRef = nextLvl !== null ? this.levelHead[nextLvl] : null;
  8340.  
  8341. this._link(ref, prevRef, nextRef, level);
  8342. this.nonEmptyLevels.splice(idx, 0, level);
  8343. } else {
  8344. // Append to existing level
  8345. const prevRef = this.levelTail[level];
  8346. const nextRef = this.nodes.get(prevRef).next;
  8347. this._link(ref, prevRef, nextRef, level);
  8348. }
  8349.  
  8350. this.counter++;
  8351. // this.checkIntegrity();
  8352. }
  8353.  
  8354. remove(component) {
  8355. const ref = component && component.deref ? component : (component || 0)[wk];
  8356.  
  8357. // this.checkIntegrity();
  8358. this._detach(ref);
  8359.  
  8360. // this.checkIntegrity();
  8361. }
  8362.  
  8363. replace(componentOld, componentNew) {
  8364. if (!componentOld || !componentNew) {
  8365. throw new Error('replace failed: missing component');
  8366. }
  8367.  
  8368. if (componentOld === componentNew) {
  8369. return;
  8370. }
  8371.  
  8372. const refOld = componentOld[wk];
  8373. // ensure New has a weak‐ref
  8374. const refNew = componentNew[wk] || (componentNew[wk] = mWeakRef(componentNew));
  8375.  
  8376.  
  8377. if (refOld === refNew) {
  8378. return;
  8379. }
  8380.  
  8381. if (!refOld || !this.nodes.has(refOld)) {
  8382. throw new Error('replace failed: old component not found');
  8383. }
  8384.  
  8385. // this.checkIntegrity();
  8386.  
  8387. // If new is already in the list somewhere, detach it first
  8388. if (this.nodes.has(refNew)) {
  8389. this._detach(refNew);
  8390. }
  8391.  
  8392. // Pull out old pointers
  8393. const { prev, next, level } = this.nodes.get(refOld);
  8394.  
  8395. // Link into the main list
  8396. if (prev) {
  8397. this.nodes.get(prev).next = refNew;
  8398. } else {
  8399. this.head = refNew;
  8400. }
  8401.  
  8402. if (next) {
  8403. this.nodes.get(next).prev = refNew;
  8404. } else {
  8405. this.tail = refNew;
  8406. }
  8407.  
  8408. // Link into the per‐level sentinels
  8409. if (this.levelHead[level] === refOld) {
  8410. this.levelHead[level] = refNew;
  8411. }
  8412. if (this.levelTail[level] === refOld) {
  8413. this.levelTail[level] = refNew;
  8414. }
  8415.  
  8416. // Finally re‐key the Map entry
  8417. this.nodes.set(refNew, { prev, next, level });
  8418. this.nodes.delete(refOld);
  8419.  
  8420. // this.checkIntegrity();
  8421. }
  8422.  
  8423. _walk(ref, dir) {
  8424. if (!ref || !this.nodes.has(ref)) return null;
  8425.  
  8426. let cur = this.nodes.get(ref)[dir];
  8427. while (cur) {
  8428. if (cur.deref()) return cur;
  8429.  
  8430. // Clean up collected node
  8431. const nxt = this.nodes.get(cur)[dir];
  8432. this._detach(cur);
  8433. cur = nxt;
  8434. }
  8435. return null;
  8436. }
  8437.  
  8438. nextComp(component) {
  8439. const ref = component && component.deref ? component : (component || 0)[wk];
  8440. return this._walk(ref, 'next');
  8441. }
  8442.  
  8443. prevComp(component) {
  8444. const ref = component && component.deref ? component : (component || 0)[wk];
  8445. return this._walk(ref, 'prev');
  8446. }
  8447.  
  8448. hasComp(component) {
  8449. const ref = component && component.deref ? component : (component || 0)[wk];
  8450. return !!(ref && this.nodes.has(ref))
  8451. }
  8452.  
  8453. count() {
  8454. return this.counter;
  8455. }
  8456.  
  8457. countLevels() {
  8458. const r = [];
  8459. for (let i = 0; ; i++) {
  8460. if (!this.levelHead[i] || !this.levelTail[i]) break;
  8461. let cur = this.levelHead[i];
  8462. let curs = [];
  8463. while (cur && this.nodes.get(cur).level === i) {
  8464. curs.push((cur));
  8465. cur = taskListP.nextComp(cur);
  8466. }
  8467.  
  8468. if (curs[0] !== this.levelHead[i]) debugger;
  8469. if (curs[curs.length - 1] !== this.levelTail[i]) debugger;
  8470. r.push({
  8471. head: this.levelHead[i],
  8472. tail: this.levelTail[i],
  8473. curs: curs,
  8474. set: new Set(curs),
  8475. arrSize: curs.length,
  8476. setSize: (new Set(curs)).size
  8477.  
  8478. });
  8479. }
  8480. return r;
  8481. }
  8482.  
  8483.  
  8484. // // Integrity checker helper
  8485. // checkIntegrity() {
  8486. // const list = this;
  8487. // // Global head/tail pointers
  8488. // if (list.head !== null) {
  8489. // const headNode = list.nodes.get(list.head);
  8490. // assert(headNode.prev === null, "Integrity: head.prev must be null");
  8491. // }
  8492. // if (list.tail !== null) {
  8493. // const tailNode = list.nodes.get(list.tail);
  8494. // assert(tailNode.next === null, "Integrity: tail.next must be null");
  8495. // }
  8496.  
  8497. // // Per-level head/tail and level consistency
  8498. // list.nonEmptyLevels.forEach(level => {
  8499. // assert(list.levelHead[level] != null, `Integrity: levelHead[${level}] should not be null`);
  8500. // assert(list.levelTail[level] != null, `Integrity: levelTail[${level}] should not be null`);
  8501. // const headRef = list.levelHead[level];
  8502. // const tailRef = list.levelTail[level];
  8503. // const headNode = list.nodes.get(headRef);
  8504. // const tailNode = list.nodes.get(tailRef);
  8505. // assert(headNode.level === level, `Integrity: levelHead[${level}].level mismatch`);
  8506. // assert(tailNode.level === level, `Integrity: levelTail[${level}].level mismatch`);
  8507. // });
  8508.  
  8509. // // nonEmptyLevels sorted ascending
  8510. // for (let i = 1; i < list.nonEmptyLevels.length; i++) {
  8511. // assert(
  8512. // list.nonEmptyLevels[i] > list.nonEmptyLevels[i - 1],
  8513. // "Integrity: nonEmptyLevels must be sorted ascending"
  8514. // );
  8515. // }
  8516.  
  8517. // this.countLevels();
  8518. // }
  8519.  
  8520. }
  8521.  
  8522.  
  8523. const taskListP = new CTaskList();
  8524. const taskList = [];
  8525. let taskCounter = 0;
  8526. window.me55 = ()=>taskListP;
  8527.  
  8528. const taskPush = (component, pTask0, pTask1, deferred = false) => {
  8529. component = kRef(component);
  8530. if (!component) return;
  8531. if (!pTask0) pTask0 = pTask1; else Object.assign(pTask0, pTask1);
  8532. componentBasedTaskPool.set(component, pTask0);
  8533. const id = taskCounter = (taskCounter & 1073741823) + 1;
  8534. pTask0.taskId = id;
  8535. if (!pTask1.byPass) pTask0.byPass = false;
  8536. taskListP.push(component, 0);
  8537. if (!deferred) nonDeferredTask = component[wk];
  8538. // taskList.push({
  8539. // taskId: id,
  8540. // componentWr: component[wk]
  8541. // })
  8542. return pTask0;
  8543. }
  8544.  
  8545. const domComment_ = document.createComment('y');
  8546. const triggerDomChange = (node) => {
  8547. node.appendChild(domComment_).remove();
  8548. }
  8549.  
  8550.  
  8551. const performTask = (component, pTask = undefined) => {
  8552.  
  8553. if (pTask === undefined) pTask = componentBasedTaskPool.get(component);
  8554. if (!pTask || !component) return;
  8555. let { step, producer, containerId, typeOrConfig, data, flushing, selfProducer } = pTask;
  8556. producer = kRef(producer);
  8557. selfProducer = kRef(selfProducer);
  8558.  
  8559. const resolveSelf = () => {
  8560.  
  8561. const node = component;
  8562.  
  8563. const prevCur = taskListP.prevComp(node);
  8564.  
  8565. node.removeAttribute('ytx-flushing');
  8566.  
  8567. // if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement && selfProducer.hostElement.isConnected) {
  8568.  
  8569. if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement) {
  8570. const node = component;
  8571.  
  8572. let shouldMarkDirty = false;
  8573.  
  8574. const m = new Set();
  8575.  
  8576. const producer = selfProducer;
  8577.  
  8578. for (const [containerId, bEvent, hasData] of flushing) {
  8579. if (hasData || hasData === null) {
  8580. shouldMarkDirty = true;
  8581. if (bEvent) {
  8582. const container = producer.getStampContainer7409_(containerId);
  8583. // console.log(644221499, container)
  8584. m.add(container);
  8585. }
  8586. }
  8587. }
  8588. flushing.length = 0;
  8589.  
  8590. if (shouldMarkDirty) {
  8591. producer.markDirty && producer.markDirty();
  8592. let q = true;
  8593. for (const container of m) {
  8594. if (!q) producer.markDirty && producer.markDirty();
  8595. q = false;
  8596. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  8597. container
  8598. });
  8599. }
  8600. }
  8601.  
  8602. }
  8603.  
  8604.  
  8605.  
  8606. const s = new Set();
  8607.  
  8608. const parentComponent = node.closest('[ytx-flushing]');
  8609. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  8610. if (!s.has(parentComponent[wk])) {
  8611. s.add(parentComponent[wk]);
  8612. }
  8613. }
  8614.  
  8615. const producerElement = producer ? producer.hostElement : null;
  8616.  
  8617. if (parentComponent && parentComponent !== producerElement) {
  8618.  
  8619. const parentComponent = producerElement;
  8620. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  8621. if (!s.has(parentComponent[wk])) {
  8622. s.add(parentComponent[wk])
  8623. }
  8624. }
  8625.  
  8626. }
  8627.  
  8628. for (const p of s) {
  8629. const node = kRef(p);
  8630. triggerDomChange(node);
  8631. }
  8632.  
  8633. if (!node.hasAttribute('ytx-flushing') && (!pTask.flushing || !pTask.flushing.length) && !pTask.typeOrConfig && !pTask.data) {
  8634. componentBasedTaskPool.delete(node);
  8635. taskListP.remove(node);
  8636. }
  8637.  
  8638.  
  8639. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head), parents: [...s]};
  8640.  
  8641. }
  8642.  
  8643. if (pTask.step === 'creation') {
  8644.  
  8645. if (flushing) debugger;
  8646. if (!producer || !typeOrConfig) return;
  8647. if (component.parentNode && component.parentNode.id === containerId && component.parentNode === producer.getStampContainer7409_(containerId)) {
  8648. pTask.step = 'flushStamper'; pTask.pq33 = 3;
  8649.  
  8650. // const aNode = producer.createComponent7409_(typeOrConfig, data, false);
  8651.  
  8652. const prevCur = taskListP.prevComp(component);
  8653.  
  8654. const pTaskId = pTask.taskId;
  8655. const cName = producer.getComponentName_(typeOrConfig, data);
  8656. const aNode = document.createElement(cName);
  8657. const qNode = component;
  8658.  
  8659. aNode.setAttribute('ytx-stamp', 'flusher');
  8660. aNode.setAttribute('ytx-flushing', '2');
  8661. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  8662.  
  8663. taskListP.replace(qNode, aNode);
  8664.  
  8665. componentBasedTaskPool.delete(qNode);
  8666. componentBasedTaskPool.set(aNode, pTask); // pTask will be obtained and proceeded during "dom change" in the same micro task
  8667.  
  8668.  
  8669. const container = component.parentNode;
  8670. const containerApi = container.__domApi || container;
  8671.  
  8672. const frag = document.createDocumentFragment();
  8673. frag.appendChild(aNode);
  8674. containerApi.insertBefore(frag, qNode);
  8675. containerApi.removeChild(qNode);
  8676. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  8677.  
  8678. }
  8679. } else if (pTask.step === 'flushStamper') {
  8680.  
  8681. if (flushing) debugger;
  8682.  
  8683. if (!producer || !typeOrConfig) return;
  8684. pTask.step = 'flushStamperWait';
  8685. pTask.typeOrConfig = null;
  8686. pTask.data = null;
  8687.  
  8688. const prevCur = taskListP.prevComp(component);
  8689.  
  8690. const node = component;
  8691. node.setAttribute('ytx-flushing', '3');
  8692.  
  8693. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  8694. // flushedObserver.observe(node, { subtree: true, childList: true });
  8695. producer.deferredBindingTasks_.push(taskB);
  8696. producer.flushRenderStamperComponentBindings7409_();
  8697. // try{Polymer.flush()}catch(e){}
  8698. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  8699.  
  8700. } else if (pTask.step === 'flushStamperWait') {
  8701.  
  8702. if (flushing) debugger;
  8703. if (!producer) return;
  8704.  
  8705. // producer undetermined
  8706.  
  8707. const node = component;
  8708.  
  8709. if (!node.querySelector('[ytx-flushing]')) {
  8710.  
  8711. pTask.step = 'idleContainer';
  8712.  
  8713. return resolveSelf();
  8714.  
  8715.  
  8716. }
  8717.  
  8718. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish') {
  8719.  
  8720. if (producer && typeOrConfig) {
  8721.  
  8722. pTask.typeOrConfig = null;
  8723. pTask.data = null;
  8724.  
  8725. const prevCur = taskListP.prevComp(component);
  8726.  
  8727. const node = component;
  8728. node.setAttribute('ytx-flushing', '3');
  8729.  
  8730. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  8731. // flushedObserver.observe(node, { subtree: true, childList: true });
  8732. producer.deferredBindingTasks_.push(taskB);
  8733. producer.flushRenderStamperComponentBindings7409_();
  8734. // try{Polymer.flush()}catch(e){}
  8735. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  8736. }
  8737.  
  8738. const node = component;
  8739.  
  8740. if (!node.querySelector('[ytx-flushing]')) {
  8741. pTask.step = 'idleProducer';
  8742. return resolveSelf();
  8743. }
  8744. // const selfProducer = kRef(pTask.selfProducer);
  8745.  
  8746. }
  8747.  
  8748. };
  8749.  
  8750. const performTaskQueued = (component)=>{
  8751. queueMicrotask_(()=>{
  8752. performTask(component);
  8753. });
  8754. };
  8755.  
  8756. let isLooping = false;
  8757. let nonDeferredTask = null;
  8758. let loopTaskQ = 0;
  8759. const loopTask = () => {
  8760. if (isLooping) return ++loopTaskQ;
  8761. isLooping = true;
  8762. loopTaskQ = 0;
  8763. let t0 = 0;
  8764. let cur = taskListP.head;
  8765. let nextCur = cur;
  8766. const taskExec = () => {
  8767.  
  8768. if (!t0) {
  8769. t0 = nativeNow();
  8770. }
  8771.  
  8772. if (nonDeferredTask && nextCur && taskListP.nodes.has(nextCur) && taskListP.nodes.get(nextCur).level === 1) {
  8773. nextCur = nonDeferredTask
  8774. }
  8775.  
  8776. nonDeferredTask = null;
  8777.  
  8778. for (;cur = nextCur; ) {
  8779.  
  8780. nextCur = taskListP.nextComp(cur);
  8781. const nextCur0 = nextCur;
  8782.  
  8783. const taskComponent = kRef(cur);
  8784. if (taskComponent) {
  8785. if(taskComponent === window.me849) debugger;
  8786. const pTask = componentBasedTaskPool.get(taskComponent);
  8787. if (pTask) {
  8788. if (pTask.taskId > 0 && !pTask.byPass) {
  8789. if (pTask.taskId === window.me848) debugger;
  8790.  
  8791. let shouldPerformTask = false;
  8792. if (pTask.step === 'creation' && pTask.typeOrConfig) {
  8793. shouldPerformTask = true;
  8794. } else if (pTask.step === 'flushStamper' && pTask.typeOrConfig) {
  8795. shouldPerformTask = true;
  8796. } else if (pTask.step === 'flushStamperWait' && !taskComponent.querySelector('[ytx-flushing]')) {
  8797. shouldPerformTask = true;
  8798. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish' && (pTask.typeOrConfig || !taskComponent.querySelector('[ytx-flushing]'))) {
  8799. shouldPerformTask = true;
  8800. }
  8801.  
  8802. let b = shouldPerformTask && taskComponent.parentNode;
  8803. if (b) {
  8804.  
  8805. const result = performTask(taskComponent, pTask);
  8806. let kbb = false;
  8807. if(typeof result ==='object' && result.nextCur === nextCur0){
  8808.  
  8809. } else if(taskListP.nextComp(cur) === null && taskListP.nextComp(cur) !== nextCur0) {
  8810. kbb = true;
  8811. }
  8812. if (typeof result === 'object' && result.parents instanceof Array) {
  8813.  
  8814. const nextCur_ = result.nextCur;
  8815. nextCur = nextCur_;
  8816. const parents = result.parents;
  8817. if (parents.length >= 1) {
  8818. const eSet = new Set(parents); // weak refs
  8819. eSet.add(nextCur_)
  8820. for (let cur_ = taskListP.head; cur_; cur_ = taskListP.nextComp(cur_)) {
  8821. if (eSet.has(cur_)) {
  8822. nextCur = cur_;
  8823. break;
  8824. }
  8825. }
  8826. }
  8827.  
  8828.  
  8829. } else if(typeof result === 'object' && result.nextCur){
  8830. nextCur = result.nextCur;
  8831. }
  8832.  
  8833.  
  8834. if (nativeNow() - t0 > 10) {
  8835. t0 = 0;
  8836. nextBrowserTick_(taskExec);
  8837. } else {
  8838. queueMicrotask_(taskExec);
  8839. }
  8840.  
  8841. return;
  8842.  
  8843. }
  8844.  
  8845. }
  8846.  
  8847. }
  8848.  
  8849. }
  8850.  
  8851. }
  8852.  
  8853. isLooping = false;
  8854.  
  8855. if(loopTaskQ > 0) nextBrowserTick_(loopTask);
  8856.  
  8857. };
  8858.  
  8859. queueMicrotask_(taskExec);
  8860.  
  8861. };
  8862.  
  8863.  
  8864. let q244 = new PromiseExternal();
  8865. let q248a = [];
  8866. let q248b = [];
  8867. let q248c = [];
  8868. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  8869.  
  8870. if(this.__byPass828__) {
  8871.  
  8872. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  8873. }
  8874.  
  8875. const isLastCreate = this.___lastCreate3311__ === data; // false for native element. true for RP or native element
  8876.  
  8877. this.___lastCreate3311__ = -0.125;
  8878.  
  8879.  
  8880. const containerId = this.__activeContainerId929__;
  8881. if (!component[wk]) component[wk] = mWeakRef(component);
  8882. if (!this[wk]) this[wk] = mWeakRef(this);
  8883.  
  8884. const pTask = componentBasedTaskPool.get(component);
  8885.  
  8886. const isSelfProducer = (pTask && pTask.selfProducer && pTask.flushing);
  8887.  
  8888.  
  8889. const abandonUnreadySubtree = () => {
  8890. for (const e of component.querySelectorAll('[ytx-flushing]')) {
  8891. const pTask = componentBasedTaskPool.get(e);
  8892. if (pTask) {
  8893. pTask.step = 'abandon';
  8894. pTask.taskId = 0;
  8895. if (pTask.flushing) pTask.flushing.length = 0;
  8896. pTask.flushing = null;
  8897.  
  8898. pTask.typeOrConfig = null
  8899. pTask.data = null
  8900.  
  8901. componentBasedTaskPool.delete(e);
  8902. taskListP.remove(e);
  8903. }
  8904. e.removeAttribute('ytx-flushing');
  8905. if (e.nodeName === 'RP') e.remove();
  8906. }
  8907. }
  8908.  
  8909. const flushNowTask = (componentWr, pTaskId, flag) => {
  8910. const component = kRef(componentWr);
  8911. if (!component) return;
  8912. const pTaskNew = componentBasedTaskPool.get(component);
  8913. if (!pTaskNew) return;
  8914. if (pTaskId !== pTaskNew.taskId) return;
  8915. pTaskNew.byPass = false;
  8916. if (flag & 1) {
  8917. performTaskQueued(component);
  8918. performTaskQueued(component);
  8919. performTaskQueued(component);
  8920. } else {
  8921. performTask(component);
  8922. performTask(component);
  8923. performTask(component);
  8924. }
  8925. return true;
  8926. }
  8927.  
  8928. const flushNow = (component) => {
  8929.  
  8930.  
  8931.  
  8932. const cName = this.getComponentName_(typeOrConfig, data);
  8933. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  8934. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  8935.  
  8936. if(mDeferred) {
  8937. component.setAttribute('ytx-defer-stamp','');
  8938. this.hostElement.setAttribute('ytx-defer-stamp','');
  8939. }
  8940.  
  8941. const pTaskNew = taskPush(component, pTask, {
  8942. step: isSelfProducer ? 'mightFlushAndWaitContainersRenderFinish' : 'flushStamper',
  8943. producer: this[wk],
  8944. containerId: containerId,
  8945. typeOrConfig: typeOrConfig,
  8946. data: data,
  8947. byPass: true,
  8948. pq33: 7
  8949. }, mDeferred ? 1 : 0);
  8950.  
  8951. const pTaskId = pTaskNew.taskId;
  8952.  
  8953. const componentWr = component[wk];
  8954.  
  8955.  
  8956. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2w');
  8957.  
  8958. if (mDeferred ) {
  8959.  
  8960. q248a.push([componentWr, pTaskId]);
  8961.  
  8962. setTimeout(() => {
  8963. const q248 = q248a;
  8964.  
  8965. if (!q248.length) return;
  8966. let q246 = q248.slice();
  8967. q248.length = 0;
  8968.  
  8969. let doLoop = false;
  8970. for (const [componentWr, pTaskId] of q246) {
  8971. // if(!)
  8972. // console.log(2188, kRef(componentWr).parentNode)
  8973. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  8974. }
  8975. q246.length = 0;
  8976. q246 = null;
  8977. if (doLoop) loopTask();
  8978.  
  8979. }, 0);
  8980.  
  8981.  
  8982. } else {
  8983.  
  8984. if(!component.parentNode){
  8985.  
  8986. q248b.push([componentWr, pTaskId]);
  8987.  
  8988. (() => {
  8989.  
  8990. const q248 = q248b;
  8991.  
  8992. if (!q248.length) return;
  8993. let q246 = q248.slice();
  8994. q248.length = 0;
  8995. let doLoop = false;
  8996. for (const [componentWr, pTaskId] of q246) {
  8997. if (flushNowTask(componentWr, pTaskId, 0) === true) doLoop = true;
  8998. }
  8999. q246.length = 0;
  9000. q246 = null;
  9001. if (doLoop) loopTask();
  9002. })();
  9003.  
  9004. } else {
  9005.  
  9006.  
  9007. q248c.push([componentWr, pTaskId]);
  9008.  
  9009. nextBrowserTick_(() => {
  9010. const q248 = q248c;
  9011.  
  9012. if (!q248.length) return;
  9013. let q246 = q248.slice();
  9014. q248.length = 0;
  9015.  
  9016. let doLoop = false;
  9017. for (const [componentWr, pTaskId] of q246) {
  9018. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  9019. }
  9020. q246.length = 0;
  9021. q246 = null;
  9022. if (doLoop) loopTask();
  9023.  
  9024. });
  9025.  
  9026. }
  9027.  
  9028. }
  9029.  
  9030.  
  9031.  
  9032. loopTask();
  9033.  
  9034. };
  9035.  
  9036. if (!isLastCreate) {
  9037.  
  9038. abandonUnreadySubtree();
  9039.  
  9040. flushNow(component);
  9041. return;
  9042.  
  9043. } else {
  9044. if (pTask) pTask.taskId = 0;
  9045. }
  9046.  
  9047. if (this.__byPass828__ || !this.__byPass348__) {
  9048. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  9049. }
  9050.  
  9051. if (pTask && pTask.step !== 'creation') {
  9052.  
  9053. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2c');
  9054.  
  9055. abandonUnreadySubtree();
  9056.  
  9057. flushNow(component);
  9058.  
  9059. return;
  9060.  
  9061. } else {
  9062.  
  9063. if (component.nodeName === "RP") {
  9064.  
  9065. component.setAttribute('ytx-stamp', 'flusher');
  9066.  
  9067. component.setAttribute('ytx-flushing', '1');
  9068.  
  9069. const cName = this.getComponentName_(typeOrConfig, data);
  9070. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  9071. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  9072.  
  9073. if(mDeferred) {
  9074. component.setAttribute('ytx-defer-stamp','');
  9075. this.hostElement.setAttribute('ytx-defer-stamp','');
  9076. }
  9077.  
  9078. taskPush(component, pTask, {
  9079. step: 'creation',
  9080. producer: this[wk],
  9081. containerId: containerId,
  9082. typeOrConfig: typeOrConfig,
  9083. data: data
  9084. }, mDeferred ? 1 : 0);
  9085. loopTask();
  9086.  
  9087. } else {
  9088.  
  9089.  
  9090. const aNode = component;
  9091. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  9092.  
  9093. aNode.setAttribute('ytx-stamp', 'flusher');
  9094. aNode.setAttribute('ytx-flushing', '2');
  9095.  
  9096. flushNow(component);
  9097.  
  9098. }
  9099.  
  9100. }
  9101.  
  9102.  
  9103. }
  9104. flushRenderStamperComponentBindings_ = function () {
  9105.  
  9106. if (!this.__byPass348__) {
  9107. return this.flushRenderStamperComponentBindings7409_();
  9108. }
  9109. if (this.__byPass828__) {
  9110. const wr = this[wk] || (this[wk] = mWeakRef(this));
  9111. queueMicrotask_(() => {
  9112. const producer = kRef(wr);
  9113. if (!producer) return;
  9114. producer.flushRenderStamperComponentBindings7409_();
  9115. });
  9116. throw new Error('5ii48');
  9117. }
  9118. throw new Error('5ii48')
  9119. }
  9120.  
  9121.  
  9122. const directComponentList = new Set([
  9123. // for YouTube Tabview Totara
  9124. "YTD-STRUCTURED-DESCRIPTION-CONTENT-RENDERER",
  9125. "YTD-VIDEO-DESCRIPTION-HEADER-RENDERER",
  9126. "YTD-ENGAGEMENT-PANEL-SECTION-LIST-RENDERER",
  9127. ]);
  9128.  
  9129.  
  9130. let kf33;
  9131. let kf3b = 0;
  9132.  
  9133. const sb88 = Symbol();
  9134.  
  9135. const onStampDone = (producer) =>{
  9136.  
  9137.  
  9138. const flushing_ = producer[sb88];
  9139.  
  9140. const flushing = flushing_.slice();
  9141. flushing_.length = 0;
  9142.  
  9143. if (flushing && flushing.length > 0) {
  9144.  
  9145. let shouldMarkDirty = false;
  9146.  
  9147. const m = new Set();
  9148.  
  9149. for (const [containerId, bEvent, hasData] of flushing) {
  9150. if (hasData || hasData === null) {
  9151. shouldMarkDirty = true;
  9152. if (bEvent) {
  9153. const container = producer.getStampContainer7409_(containerId);
  9154. // console.log(644221499, container)
  9155. m.add(container);
  9156. }
  9157. }
  9158. }
  9159. flushing.length = 0;
  9160.  
  9161. if (shouldMarkDirty) {
  9162. producer.markDirty && producer.markDirty();
  9163. let q = true;
  9164. for (const container of m) {
  9165. if (!q) producer.markDirty && producer.markDirty();
  9166. q = false;
  9167. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  9168. container
  9169. });
  9170. }
  9171. }
  9172.  
  9173. }
  9174.  
  9175.  
  9176. }
  9177.  
  9178. stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  9179. // this.__byPass828__ = true;
  9180.  
  9181. // return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  9182.  
  9183. const producer = this;
  9184. const hostElement = producer.hostElement;
  9185.  
  9186. let kf = false;
  9187. const kf3t = nativeNow();
  9188. const kf34 = Math.floor((kf3t - kf3b) / 8);
  9189.  
  9190. if (!kf33 || kf34 !== kf33) {
  9191. kf33 = kf34;
  9192. kf3b = kf3t - kf34 * 8;
  9193. kf = true;
  9194. }
  9195.  
  9196. const container = this.getStampContainer7409_(containerId);
  9197. if (container && !container.__rk75401__) {
  9198. container.__rk75401__ = true;
  9199. childrenObs.observe(container, { subtree: false, childList: true });
  9200. }
  9201.  
  9202. if (kf) this.__directProduction533__ = true;
  9203. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  9204. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  9205. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  9206. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  9207. else this.__directProduction533__ = false;
  9208.  
  9209. this.__directProduction533__ = true;
  9210.  
  9211. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  9212.  
  9213. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  9214.  
  9215. const bEventCb = this.stampDom[stampKey].events;
  9216.  
  9217. this.__activeContainerId929__ = containerId;
  9218.  
  9219. if (!this[wk]) this[wk] = mWeakRef(this);
  9220. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  9221. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  9222. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  9223. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  9224. hostElement.setAttribute('ytx-stamp', 'producer');
  9225. }
  9226.  
  9227.  
  9228. if (this.__byPass828__) {
  9229.  
  9230. const flushing = this[sb88] || (this[sb88] = []);
  9231. flushing.push([containerId, bEventCb, null]);
  9232. let r, e_
  9233. try {
  9234. this.__byPass348__ = true;
  9235. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  9236. } catch (e) {
  9237. e_ = e;
  9238. }
  9239. this.__byPass348__ = false;
  9240.  
  9241. nextBrowserTick_(() => {
  9242. onStampDone(this);
  9243. });
  9244.  
  9245. if (e_ && e_.message !== '5ii48') throw e_;
  9246. return;
  9247.  
  9248. }
  9249.  
  9250.  
  9251. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  9252.  
  9253. const flushing = pTask ? (pTask.flushing || []) : [];
  9254. flushing.push([containerId, bEventCb, null]);
  9255. hostElement.setAttribute('ytx-flushing', 's-1');
  9256.  
  9257. if (pTask) {
  9258. // pTask.taskId = -1;
  9259. pTask.byPass = true;
  9260. }
  9261. if (hostElement && !hostElement.__rk75401__) {
  9262. hostElement.__rk75401__ = true;
  9263. childrenObs.observe(hostElement, { subtree: false, childList: true });
  9264. }
  9265.  
  9266. let r, e_
  9267. try {
  9268. this.__byPass348__ = true;
  9269. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  9270. } catch (e) {
  9271. e_ = e;
  9272. }
  9273. this.__byPass348__ = false;
  9274.  
  9275. taskPush(hostElement, pTask, {
  9276. step: 'mightFlushAndWaitContainersRenderFinish',
  9277. selfProducer: this[wk],
  9278. flushing
  9279. });
  9280. loopTask();
  9281.  
  9282. triggerDomChange(container);
  9283. triggerDomChange(hostElement);
  9284.  
  9285. if (e_ && e_.message !== '5ii48') throw e_;
  9286.  
  9287. };
  9288.  
  9289. stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  9290. // this.__byPass828__ = true;
  9291.  
  9292.  
  9293.  
  9294. // return this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  9295.  
  9296. const producer = this;
  9297. const hostElement = producer.hostElement;
  9298.  
  9299. let kf = false;
  9300. const kf3t = nativeNow();
  9301. const kf34 = Math.floor((kf3t - kf3b) / 8);
  9302.  
  9303. if (!kf33 || kf34 !== kf33) {
  9304. kf33 = kf34;
  9305. kf3b = kf3t - kf34 * 8;
  9306. kf = true;
  9307. }
  9308.  
  9309. const container = this.getStampContainer7409_(containerId);
  9310. if (container && !container.__rk75401__) {
  9311. container.__rk75401__ = true;
  9312. childrenObs.observe(container, { subtree: false, childList: true });
  9313. }
  9314.  
  9315. if (kf) this.__directProduction533__ = true;
  9316. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  9317. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  9318. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  9319. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  9320. else this.__directProduction533__ = false;
  9321.  
  9322. bReuse = false;
  9323.  
  9324. this.__directProduction533__ = true;
  9325.  
  9326. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  9327. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  9328.  
  9329. this.__activeContainerId929__ = containerId;
  9330.  
  9331. if (!this[wk]) this[wk] = mWeakRef(this);
  9332. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  9333. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  9334. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  9335. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  9336. hostElement.setAttribute('ytx-stamp', 'producer');
  9337. }
  9338.  
  9339.  
  9340. if (this.__byPass828__) {
  9341.  
  9342. const flushing = this[sb88] || (this[sb88] = []);
  9343. flushing.push([containerId, bEventCb, !!dataList]);
  9344. let r, e_
  9345. try {
  9346. this.__byPass348__ = true;
  9347. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  9348. } catch (e) {
  9349. e_ = e;
  9350. }
  9351. this.__byPass348__ = false;
  9352.  
  9353. nextBrowserTick_(() => {
  9354. onStampDone(this);
  9355. });
  9356.  
  9357. if (e_ && e_.message !== '5ii48') throw e_;
  9358. return;
  9359.  
  9360. }
  9361.  
  9362.  
  9363. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  9364.  
  9365. const flushing = pTask ? (pTask.flushing || []) : [];
  9366. flushing.push([containerId, bEventCb, !!dataList]);
  9367. hostElement.setAttribute('ytx-flushing', 's-1');
  9368.  
  9369. if (pTask) {
  9370. pTask.byPass = true;
  9371. // pTask.taskId = -1;
  9372. }
  9373.  
  9374. if (hostElement && !hostElement.__rk75401__) {
  9375. hostElement.__rk75401__ = true;
  9376. childrenObs.observe(hostElement, { subtree: false, childList: true });
  9377. }
  9378.  
  9379. let r, e_
  9380. try {
  9381. this.__byPass348__ = true;
  9382. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  9383. } catch (e) {
  9384. e_ = e;
  9385. }
  9386. this.__byPass348__ = false;
  9387.  
  9388. taskPush(hostElement, pTask, {
  9389. step: 'mightFlushAndWaitContainersRenderFinish',
  9390. selfProducer: this[wk],
  9391. flushing
  9392. });
  9393. loopTask();
  9394.  
  9395. triggerDomChange(container);
  9396. triggerDomChange(hostElement);
  9397.  
  9398. if (e_ && e_.message !== '5ii48') throw e_;
  9399.  
  9400. };
  9401.  
  9402. const stampDomArrayWB_ = function (objWr, containerId, xxx_) {
  9403.  
  9404. const obj = kRef(objWr);
  9405. if (!obj) return;
  9406. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  9407. if (xxx !== xxx_) return;
  9408. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  9409. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  9410. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  9411. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  9412. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  9413. // console.log(12388002, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  9414. return obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  9415. };
  9416.  
  9417.  
  9418. stampDomArray_.bind = function (obj, ...args) {
  9419. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  9420. // console.log(12388001, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  9421. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  9422. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  9423. if (!typeOrConfig[wk]) typeOrConfig[wk] = mWeakRef(typeOrConfig);
  9424. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig[wk];
  9425. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  9426. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  9427. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  9428.  
  9429. // if (!obj[`__stampDomArrayBoundFn__#${containerId}__`]) obj[`__stampDomArrayBoundFn__#${containerId}__`] = stampDomArrayWB_.bind(null, obj[wk], containerId);
  9430. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  9431. // const p = obj[wk];
  9432. // queueMicrotask_(()=>{
  9433. // const obj = kRef(p);
  9434. // if(!obj) return;
  9435. // if(!obj.hostElement) return;
  9436. // triggerDomChange(obj.hostElement);
  9437. // const container = obj.getStampContainer7409_(containerId);
  9438. // if(container instanceof Node) triggerDomChange(container);
  9439. // });
  9440. // return obj[`__stampDomArrayBoundFn__#${containerId}__`];
  9441.  
  9442. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx);
  9443. };
  9444.  
  9445. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  9446.  
  9447. }
  9448.  
  9449. const setupDiscreteTasks = (h, rb) => {
  9450.  
  9451. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  9452. const f = h.onYtRendererstamperFinished;
  9453. const g = ump3.get(f) || function () {
  9454. if (this.updateChildVisibilityProperties && !this.markDirty) {
  9455. return f.apply(this, arguments);
  9456. }
  9457. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9458. }
  9459. ump3.set(f, g);
  9460. g.km34 = 1;
  9461. h.onYtRendererstamperFinished = g;
  9462.  
  9463. }
  9464.  
  9465. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  9466. const f = h.onYtUpdateDescriptionAction;
  9467. const g = ump3.get(f) || function (a) {
  9468. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9469. }
  9470. ump3.set(f, g);
  9471. g.km34 = 1;
  9472. h.onYtUpdateDescriptionAction = g;
  9473.  
  9474. }
  9475.  
  9476. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  9477. const f = h.handleUpdateDescriptionAction;
  9478. const g = ump3.get(f) || function (a) {
  9479. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9480. }
  9481. ump3.set(f, g);
  9482. g.km34 = 1;
  9483. h.handleUpdateDescriptionAction = g;
  9484.  
  9485. }
  9486.  
  9487. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  9488. const f = h.handleUpdateLiveChatPollAction;
  9489. const g = ump3.get(f) || function (a) {
  9490. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9491. }
  9492. ump3.set(f, g);
  9493. g.km34 = 1;
  9494. h.handleUpdateLiveChatPollAction = g;
  9495.  
  9496. }
  9497.  
  9498. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  9499. const f = h.onTextChanged;
  9500. const g = ump3.get(f) || function () {
  9501. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9502. }
  9503. ump3.set(f, g);
  9504. g.km34 = 1;
  9505. h.onTextChanged = g;
  9506.  
  9507. }
  9508.  
  9509. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  9510. const f = h.onVideoDataChange;
  9511. const g = ump3.get(f) || function (a) {
  9512. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9513. }
  9514. ump3.set(f, g);
  9515. g.km34 = 1;
  9516. h.onVideoDataChange = g;
  9517.  
  9518. }
  9519.  
  9520. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  9521. const f = h.onVideoDataChange_;
  9522. const g = ump3.get(f) || function () {
  9523. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9524. }
  9525. ump3.set(f, g);
  9526. g.km34 = 1;
  9527. h.onVideoDataChange_ = g;
  9528.  
  9529. }
  9530.  
  9531. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  9532.  
  9533. const f = h.addTooltips_;
  9534. const g = ump3.get(f) || function () {
  9535. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9536. }
  9537. ump3.set(f, g);
  9538. g.km34 = 1;
  9539. h.addTooltips_ = g;
  9540.  
  9541. }
  9542.  
  9543. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  9544.  
  9545. const f = h.updateRenderedElements;
  9546. const g = ump3.get(f) || function () {
  9547. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9548. }
  9549. ump3.set(f, g);
  9550. g.km34 = 1;
  9551. h.updateRenderedElements = g;
  9552.  
  9553. }
  9554.  
  9555. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  9556. const f = h.loadPage_;
  9557. const g = ump3.get(f) || function (a) {
  9558. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9559. }
  9560. ump3.set(f, g);
  9561. g.km34 = 1;
  9562. h.loadPage_ = g;
  9563.  
  9564. }
  9565. // updatePageData_ : possible conflict with Omit ShadyDOM
  9566. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  9567. const f = h.updatePageData_;
  9568. const g = ump3.get(f) || function (a) {
  9569. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9570. }
  9571. ump3.set(f, g);
  9572. g.km34 = 1;
  9573. h.updatePageData_ = g;
  9574.  
  9575. }
  9576.  
  9577.  
  9578. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  9579.  
  9580. const f = h.onFocus_;
  9581. const g = ump3.get(f) || function () {
  9582. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9583. }
  9584. ump3.set(f, g);
  9585. g.km34 = 1;
  9586. h.onFocus_ = g;
  9587.  
  9588. }
  9589.  
  9590. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  9591.  
  9592. const f = h.onBlur_;
  9593. const g = ump3.get(f) || function () {
  9594. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9595. }
  9596. ump3.set(f, g);
  9597. g.km34 = 1;
  9598. h.onBlur_ = g;
  9599.  
  9600. }
  9601.  
  9602.  
  9603. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  9604.  
  9605. const f = h.buttonClassChanged_;
  9606. const g = ump3.get(f) || function (a, b) {
  9607. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9608. }
  9609. ump3.set(f, g);
  9610. g.km34 = 1;
  9611. h.buttonClassChanged_ = g;
  9612.  
  9613. }
  9614.  
  9615. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  9616.  
  9617. const f = h.buttonIconChanged_;
  9618. const g = ump3.get(f) || function (a) {
  9619. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9620. }
  9621. ump3.set(f, g);
  9622. g.km34 = 1;
  9623. h.buttonIconChanged_ = g;
  9624.  
  9625. }
  9626.  
  9627. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  9628.  
  9629. const f = h.dataChangedInBehavior_;
  9630. const g = ump3.get(f) || function () {
  9631. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9632. }
  9633. ump3.set(f, g);
  9634. g.km34 = 1;
  9635. h.dataChangedInBehavior_ = g;
  9636.  
  9637. }
  9638.  
  9639. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  9640.  
  9641. const f = h.continuationsChanged_;
  9642. const g = ump3.get(f) || function () {
  9643. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9644. }
  9645. ump3.set(f, g);
  9646. g.km34 = 1;
  9647. h.continuationsChanged_ = g;
  9648.  
  9649. }
  9650.  
  9651.  
  9652. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  9653.  
  9654. const f = h.forceChatPoll_;
  9655. const g = ump3.get(f) || function (a) {
  9656. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9657. }
  9658. ump3.set(f, g);
  9659. g.km34 = 1;
  9660. h.forceChatPoll_ = g;
  9661.  
  9662. }
  9663.  
  9664. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  9665.  
  9666. const f = h.onEndpointClick_;
  9667. const g = ump3.get(f) || function (a) {
  9668. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9669. }
  9670. ump3.set(f, g);
  9671. g.km34 = 1;
  9672. h.onEndpointClick_ = g;
  9673.  
  9674. }
  9675.  
  9676. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  9677.  
  9678. const f = h.onEndpointTap_;
  9679. const g = ump3.get(f) || function (a) {
  9680. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9681. }
  9682. ump3.set(f, g);
  9683. g.km34 = 1;
  9684. h.onEndpointTap_ = g;
  9685.  
  9686. }
  9687.  
  9688. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  9689.  
  9690. const f = h.handleClick_;
  9691. const g = ump3.get(f) || function (a, b) {
  9692. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9693. }
  9694. ump3.set(f, g);
  9695. g.km34 = 1;
  9696. h.handleClick_ = g;
  9697.  
  9698. }
  9699.  
  9700. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  9701.  
  9702. const f = h.onReadyStateChange_;
  9703. const g = ump3.get(f) || function () {
  9704. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9705. }
  9706. ump3.set(f, g);
  9707. g.km34 = 1;
  9708. h.onReadyStateChange_ = g;
  9709.  
  9710. }
  9711.  
  9712. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  9713.  
  9714. const f = h.onReadyStateChangeEntryPoint_;
  9715. const g = ump3.get(f) || function () {
  9716. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9717. }
  9718. ump3.set(f, g);
  9719. g.km34 = 1;
  9720. h.onReadyStateChangeEntryPoint_ = g;
  9721.  
  9722. }
  9723.  
  9724. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  9725.  
  9726. const f = h.readyStateChangeHandler_;
  9727. const g = ump3.get(f) || function (a) {
  9728. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9729. }
  9730. ump3.set(f, g);
  9731. g.km34 = 1;
  9732. h.readyStateChangeHandler_ = g;
  9733.  
  9734. }
  9735.  
  9736. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  9737.  
  9738. const f = h.xmlHttpHandler_;
  9739. const g = ump3.get(f) || function (a) {
  9740. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9741. }
  9742. ump3.set(f, g);
  9743. g.km34 = 1;
  9744. h.xmlHttpHandler_ = g;
  9745.  
  9746. }
  9747.  
  9748. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  9749.  
  9750. const f = h.executeCallbacks_; // overloaded
  9751. const g = ump3.get(f) || function (a) {
  9752. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9753. }
  9754. ump3.set(f, g);
  9755. g.km34 = 1;
  9756. h.executeCallbacks_ = g;
  9757.  
  9758. }
  9759.  
  9760. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  9761.  
  9762. const f = h.handleInvalidationData_;
  9763. const g = ump3.get(f) || function (a, b) {
  9764. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9765. }
  9766. ump3.set(f, g);
  9767. g.km34 = 1;
  9768. h.handleInvalidationData_ = g;
  9769.  
  9770. }
  9771.  
  9772. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  9773.  
  9774. const f = h.onInput_;
  9775. const g = ump3.get(f) || function () {
  9776. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9777. }
  9778. ump3.set(f, g);
  9779. g.km34 = 1;
  9780. h.onInput_ = g;
  9781.  
  9782. }
  9783. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  9784.  
  9785. const f = h.trigger_;
  9786. const g = ump3.get(f) || function (a) {
  9787. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9788. }
  9789. ump3.set(f, g);
  9790. g.km34 = 1;
  9791. h.trigger_ = g;
  9792.  
  9793. }
  9794.  
  9795. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  9796.  
  9797. const f = h.requestData_;
  9798. const g = ump3.get(f) || function (a) {
  9799. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9800. }
  9801. ump3.set(f, g);
  9802. g.km34 = 1;
  9803. h.requestData_ = g;
  9804.  
  9805. }
  9806.  
  9807. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  9808.  
  9809. const f = h.onLoadReloadContinuation_;
  9810. const g = ump3.get(f) || function (a, b) {
  9811. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9812. }
  9813. ump3.set(f, g);
  9814. g.km34 = 1;
  9815. h.onLoadReloadContinuation_ = g;
  9816.  
  9817. }
  9818.  
  9819. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  9820.  
  9821. const f = h.onLoadIncrementalContinuation_;
  9822. const g = ump3.get(f) || function (a, b) {
  9823. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9824. }
  9825. ump3.set(f, g);
  9826. g.km34 = 1;
  9827. h.onLoadIncrementalContinuation_ = g;
  9828.  
  9829. }
  9830.  
  9831. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  9832.  
  9833. const f = h.onLoadSeekContinuation_;
  9834. const g = ump3.get(f) || function (a, b) {
  9835. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9836. }
  9837. ump3.set(f, g);
  9838. g.km34 = 1;
  9839. h.onLoadSeekContinuation_ = g;
  9840.  
  9841. }
  9842. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  9843.  
  9844. const f = h.onLoadReplayContinuation_;
  9845. const g = ump3.get(f) || function (a, b) {
  9846. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9847. }
  9848. ump3.set(f, g);
  9849. g.km34 = 1;
  9850. h.onLoadReplayContinuation_ = g;
  9851.  
  9852. }
  9853. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  9854.  
  9855. const f = h.onNavigate_;
  9856. const g = ump3.get(f) || function (a) {
  9857. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9858. }
  9859. ump3.set(f, g);
  9860. g.km34 = 1;
  9861. h.onNavigate_ = g;
  9862.  
  9863. }
  9864.  
  9865. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  9866.  
  9867. const f = h.ytRendererBehaviorDataObserver_;
  9868. const g = ump3.get(f) || function () {
  9869. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9870. }
  9871. ump3.set(f, g);
  9872. g.km34 = 1;
  9873. h.ytRendererBehaviorDataObserver_ = g;
  9874.  
  9875. }
  9876.  
  9877. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  9878.  
  9879. const f = h.ytRendererBehaviorTargetIdObserver_;
  9880. const g = ump3.get(f) || function () {
  9881. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9882. }
  9883. ump3.set(f, g);
  9884. g.km34 = 1;
  9885. h.ytRendererBehaviorTargetIdObserver_ = g;
  9886.  
  9887. }
  9888.  
  9889. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  9890.  
  9891. const f = h.unregisterRenderer_;
  9892. const g = ump3.get(f) || function (a) {
  9893. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9894. }
  9895. ump3.set(f, g);
  9896. g.km34 = 1;
  9897. h.unregisterRenderer_ = g;
  9898.  
  9899. }
  9900.  
  9901. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  9902.  
  9903. const f = h.textChanged_;
  9904. const g = ump3.get(f) || function (a) {
  9905. if (void 0 !== this.isAttached) {
  9906. const hostElement = this.hostElement;
  9907. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  9908. return;
  9909. }
  9910. }
  9911. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9912. }
  9913. ump3.set(f, g);
  9914. g.km34 = 1;
  9915. h.textChanged_ = g;
  9916.  
  9917. }
  9918.  
  9919.  
  9920.  
  9921. /**
  9922. *
  9923. * Neglect following
  9924. *
  9925. * h.onYtAction_
  9926. * h.startLoadingWatch [ buggy for yt-player-updated ]
  9927. * h.deferRenderStamperBinding_
  9928. *
  9929. * h.stampDomArray_
  9930. * h.stampDomArraySplices_
  9931. *
  9932. */
  9933.  
  9934.  
  9935. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  9936. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  9937. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  9938. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  9939. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  9940. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  9941.  
  9942. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  9943.  
  9944. const f = h.searchChanged_;
  9945. const g = ump3.get(f) || function () {
  9946. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9947. }
  9948. ump3.set(f, g);
  9949. g.km34 = 1;
  9950. h.searchChanged_ = g;
  9951.  
  9952. }
  9953.  
  9954. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  9955.  
  9956. const f = h.skinToneChanged_;
  9957. const g = ump3.get(f) || function (a) {
  9958. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9959. }
  9960. ump3.set(f, g);
  9961. g.km34 = 1;
  9962. h.skinToneChanged_ = g;
  9963.  
  9964. }
  9965.  
  9966. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  9967.  
  9968. const f = h.onEmojiHover_;
  9969. const g = ump3.get(f) || function (a) {
  9970. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9971. }
  9972. ump3.set(f, g);
  9973. g.km34 = 1;
  9974. h.onEmojiHover_ = g;
  9975.  
  9976. }
  9977.  
  9978. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  9979.  
  9980. const f = h.onSelectCategory_;
  9981. const g = ump3.get(f) || function (a) {
  9982. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9983. }
  9984. ump3.set(f, g);
  9985. g.km34 = 1;
  9986. h.onSelectCategory_ = g;
  9987.  
  9988. }
  9989.  
  9990. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  9991.  
  9992. const f = h.onShowEmojiVariantSelector;
  9993. const g = ump3.get(f) || function (a) {
  9994. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  9995. }
  9996. ump3.set(f, g);
  9997. g.km34 = 1;
  9998. h.onShowEmojiVariantSelector = g;
  9999.  
  10000. }
  10001.  
  10002. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  10003.  
  10004. const f = h.updateCategoriesAndPlaceholder_;
  10005. const g = ump3.get(f) || function () {
  10006. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10007. }
  10008. ump3.set(f, g);
  10009. g.km34 = 1;
  10010. h.updateCategoriesAndPlaceholder_ = g;
  10011.  
  10012. }
  10013.  
  10014. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  10015.  
  10016. const f = h.watchPageActiveChanged_;
  10017. const g = ump3.get(f) || function () {
  10018. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10019. }
  10020. ump3.set(f, g);
  10021. g.km34 = 1;
  10022. h.watchPageActiveChanged_ = g;
  10023.  
  10024. }
  10025.  
  10026. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  10027.  
  10028. const f = h.activate_;
  10029. const g = ump3.get(f) || function () {
  10030. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10031. }
  10032. ump3.set(f, g);
  10033. g.km34 = 1;
  10034. h.activate_ = g;
  10035.  
  10036. }
  10037. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  10038.  
  10039. const f = h.onYtPlaylistDataUpdated_;
  10040. const g = ump3.get(f) || function () {
  10041. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10042. }
  10043. ump3.set(f, g);
  10044. g.km34 = 1;
  10045. h.onYtPlaylistDataUpdated_ = g;
  10046.  
  10047. }
  10048.  
  10049.  
  10050.  
  10051. /**
  10052. *
  10053. * Neglect following
  10054. *
  10055. * h.rendererStamperObserver_
  10056. * h.rendererStamperApplyChangeRecord_
  10057. * h.flushRenderStamperComponentBindings_
  10058. * h.forwardRendererStamperChanges_
  10059. *
  10060. */
  10061.  
  10062. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  10063.  
  10064. const f = h.tryRenderChunk_;
  10065. const g = ump3.get(f) || function () {
  10066. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10067. }
  10068. ump3.set(f, g);
  10069. g.km34 = 1;
  10070. h.tryRenderChunk_ = g;
  10071.  
  10072. }
  10073.  
  10074.  
  10075. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  10076.  
  10077. const f = h.renderChunk_;
  10078. const g = ump3.get(f) || function () {
  10079. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10080. }
  10081. ump3.set(f, g);
  10082. g.km34 = 1;
  10083. h.renderChunk_ = g;
  10084.  
  10085. }
  10086.  
  10087. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  10088.  
  10089. const f = h.deepLazyListObserver_;
  10090. const g = ump3.get(f) || function () {
  10091. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10092. }
  10093. ump3.set(f, g);
  10094. g.km34 = 1;
  10095. h.deepLazyListObserver_ = g;
  10096.  
  10097. }
  10098.  
  10099. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  10100.  
  10101. const f = h.onItemsUpdated_;
  10102. const g = ump3.get(f) || function () {
  10103. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10104. }
  10105. ump3.set(f, g);
  10106. g.km34 = 1;
  10107. h.onItemsUpdated_ = g;
  10108.  
  10109. }
  10110.  
  10111. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  10112.  
  10113. const f = h.requestRenderChunk_;
  10114. const g = ump3.get(f) || function () {
  10115. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  10116. }
  10117. ump3.set(f, g);
  10118. g.km34 = 1;
  10119. h.requestRenderChunk_ = g;
  10120.  
  10121. }
  10122.  
  10123. /**
  10124. *
  10125. * Neglect following
  10126. *
  10127. * h.dataChanged_ [ buggy for page swtiching ]
  10128. *
  10129. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  10130. *
  10131. * h.cancelPendingTasks_
  10132. * h.fillRange_
  10133. * h.addTextNodes_
  10134. * h.updateText_
  10135. * h.stampTypeChanged_
  10136. *
  10137. */
  10138.  
  10139.  
  10140. }
  10141.  
  10142. const keyStConnectedCallback = Symbol(); // avoid copying the value
  10143.  
  10144. const dmf = new WeakMap();
  10145.  
  10146.  
  10147. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  10148.  
  10149. try {
  10150.  
  10151. const q = document.createElement('template');
  10152. q.innerHTML = '<ytz-null361></ytz-null361>';
  10153. nativeHTMLElement = q.content.firstChild.constructor
  10154.  
  10155. } catch (e) { }
  10156.  
  10157. if (!nativeHTMLElement.prototype.connectedCallback) {
  10158. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  10159. nativeHTMLElement.prototype.connectedCallback = function () {
  10160. let r;
  10161. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  10162. return r;
  10163. }
  10164. }
  10165. const pvr = Symbol()
  10166.  
  10167. let stampDomArrayFnStore = null;
  10168. const setupMap = new WeakSet();
  10169. const setupYtComponent = (cnt) => {
  10170. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  10171. if (!cProto || setupMap.has(cProto)) return;
  10172. setupMap.add(cProto);
  10173. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  10174. cProto[pvr] |= 1;
  10175.  
  10176.  
  10177.  
  10178. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  10179. const b = cProto.stampDomArray_.length === 6
  10180. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  10181. && cProto.createComponent_ && cProto.createComponent_.length === 3
  10182. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  10183. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  10184. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  10185. if (!b) {
  10186. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  10187. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  10188. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  10189. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_} = stampDomArrayFnStore;
  10190.  
  10191. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  10192. cProto.createComponent7409_ = cProto.createComponent_;
  10193. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  10194. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  10195. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  10196. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  10197.  
  10198. cProto.getStampContainer_ = getStampContainer_;
  10199. cProto.createComponent_ = createComponent_;
  10200. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  10201. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  10202. cProto.stampDomArray_ = stampDomArray_;
  10203. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  10204.  
  10205. }
  10206. }
  10207.  
  10208.  
  10209.  
  10210.  
  10211. // if(false && cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  10212. // cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  10213.  
  10214. // if(cProto._runEffectsForTemplate6344.length === 4){
  10215.  
  10216. // cProto._runEffectsForTemplate = function (c, d, e, g) {
  10217. // const cnt = this;
  10218. // const { propertyEffects, nodeList, firstChild } = c;
  10219. // cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  10220.  
  10221. // }
  10222.  
  10223. // }
  10224.  
  10225. // }
  10226.  
  10227. }
  10228. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  10229. cProto[pvr] |= 2;
  10230. setupDiscreteTasks(cProto);
  10231. }
  10232. };
  10233.  
  10234. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  10235. get() {
  10236. const f = this[keyStConnectedCallback];
  10237. if (this.is) {
  10238. setupYtComponent(this);
  10239. }
  10240. return f;
  10241. },
  10242. set(nv) {
  10243. let gv = nv;
  10244. this[keyStConnectedCallback] = gv; // proto or object
  10245. return true;
  10246. },
  10247. enumerable: false,
  10248. configurable: true
  10249.  
  10250. });
  10251.  
  10252. const pLoad = new Promise(resolve => {
  10253. if (document.readyState !== 'loading') {
  10254. resolve();
  10255. } else {
  10256. window.addEventListener("DOMContentLoaded", resolve, false);
  10257. }
  10258. });
  10259.  
  10260. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  10261. window.requestIdleCallback471 = window.requestIdleCallback;
  10262. window.requestIdleCallback = function (f, ...args) {
  10263. return (this || window).requestIdleCallback471(async function () {
  10264. await pLoad.then();
  10265. // await new Promise(nextBrowserTick_);
  10266. f.call(this, ...arguments)
  10267. }, ...args);
  10268. }
  10269. }
  10270.  
  10271. pLoad.then(() => {
  10272.  
  10273. let nonce = document.querySelector('style[nonce]');
  10274. nonce = nonce ? nonce.getAttribute('nonce') : null;
  10275. const st = document.createElement('style');
  10276. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  10277. st.textContent = "none-element-k47{order:0}";
  10278. st.addEventListener('load', () => {
  10279. pf31.resolve();
  10280. p59 = 1;
  10281. }, false);
  10282. (document.body || document.head || document.documentElement).appendChild(st);
  10283.  
  10284. });
  10285.  
  10286. const prepareLogs = [];
  10287.  
  10288. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  10289.  
  10290. let winError00 = window.onerror;
  10291.  
  10292. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  10293.  
  10294. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  10295.  
  10296. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  10297.  
  10298. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  10299. const lcOpt = { sensitivity: 'base' };
  10300. document.createElement24 = document.createElement;
  10301. document.createElement = function (t) {
  10302. if (typeof t === 'string' && t.length === 6) {
  10303. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  10304. const p = this.createElement24(t);
  10305. try {
  10306. const stack = new Error().stack;
  10307. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  10308. if (!isSearchbox) {
  10309. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  10310. }
  10311. } catch (e) { }
  10312. return p;
  10313. }
  10314. }
  10315. return this.createElement24.apply(this, arguments);
  10316. };
  10317.  
  10318. })();
  10319.  
  10320. ; fix_error_many_stack_state === 1 && (() => {
  10321.  
  10322.  
  10323. let p1 = winError00;
  10324.  
  10325. let stackNeedleDetails = null;
  10326.  
  10327. Object.defineProperty(Object.prototype, 'matchAll', {
  10328. get() {
  10329. stackNeedleDetails = this;
  10330. return true;
  10331. },
  10332. enumerable: true,
  10333. configurable: true
  10334. });
  10335.  
  10336. try {
  10337. JSON.parse("{}");
  10338. } catch (e) {
  10339. console.warn(e)
  10340. fix_error_many_stack_state = 0;
  10341. }
  10342.  
  10343. delete Object.prototype['matchAll'];
  10344.  
  10345. let p2 = window.onerror;
  10346.  
  10347. window.onerror = p1;
  10348.  
  10349. if (fix_error_many_stack_state === 0) return;
  10350.  
  10351. if (stackNeedleDetails) {
  10352. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  10353. stackNeedleDetails.matchAll = true;
  10354. }
  10355.  
  10356. if (p1 === p2) return (fix_error_many_stack_state = 0);
  10357.  
  10358. // p1!==p2
  10359. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  10360.  
  10361. })();
  10362.  
  10363. ; fix_error_many_stack_state === 2 && (() => {
  10364.  
  10365.  
  10366. let p1 = winError00;
  10367.  
  10368. let objectPrune = null;
  10369. let stackNeedleDetails = null;
  10370.  
  10371. Object.defineProperty(Function.prototype, 'findOwner', {
  10372. get() {
  10373. objectPrune = this;
  10374. return this._findOwner;
  10375. },
  10376. set(nv) {
  10377. this._findOwner = nv;
  10378. return true;
  10379. },
  10380. enumerable: true,
  10381. configurable: true
  10382. });
  10383.  
  10384. Object.defineProperty(Object.prototype, 'matchAll', {
  10385. get() {
  10386. stackNeedleDetails = this;
  10387. return true;
  10388. },
  10389. enumerable: true,
  10390. configurable: true
  10391. });
  10392.  
  10393. try {
  10394. JSON.parse("{}");
  10395. } catch (e) {
  10396. console.warn(e)
  10397. fix_error_many_stack_state = 0;
  10398. }
  10399.  
  10400. delete Function.prototype['findOwner'];
  10401. delete Object.prototype['matchAll'];
  10402.  
  10403. let p2 = window.onerror;
  10404.  
  10405. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  10406.  
  10407. if (fix_error_many_stack_state == 0) return;
  10408.  
  10409. // the following will only execute when Brave's scriptlets.js is executed.
  10410.  
  10411. prepareLogs.push("fix_error_many_stack_state NB")
  10412.  
  10413. if (stackNeedleDetails) {
  10414. stackNeedleDetails.pattern = null;
  10415. stackNeedleDetails.re = null;
  10416. stackNeedleDetails.expect = null;
  10417. stackNeedleDetails.matchAll = true;
  10418. }
  10419.  
  10420. if (objectPrune) {
  10421. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  10422. delete objectPrune._findOwner;
  10423. }
  10424.  
  10425. fix_error_many_stack_state = 3;
  10426. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  10427. JSON.parse.objectPrune = objectPrune;
  10428.  
  10429. })();
  10430.  
  10431. ; fix_error_many_stack_state === 3 && (() => {
  10432.  
  10433.  
  10434. let p1 = winError00;
  10435.  
  10436. try {
  10437. JSON.parse("{}");
  10438. } catch (e) {
  10439. console.warn(e)
  10440. fix_error_many_stack_state = 0;
  10441. }
  10442.  
  10443. let p2 = window.onerror;
  10444.  
  10445. if (p1 === p2) return;
  10446.  
  10447. window.onerror = p1;
  10448.  
  10449. if (fix_error_many_stack_state === 0) return;
  10450.  
  10451. fix_error_many_stack_state = 4; // p1 != p2
  10452.  
  10453.  
  10454. })();
  10455.  
  10456. fix_error_many_stack_state === 4 && (() => {
  10457.  
  10458. // the following will only execute when Brave's scriptlets.js is executed.
  10459.  
  10460. prepareLogs.push("fix_error_many_stack_state AB")
  10461.  
  10462. JSON.parseProxy = JSON.parse;
  10463.  
  10464. JSON.parse = ((parse) => {
  10465.  
  10466. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  10467. return function (text, reviver) {
  10468. const onerror = window.onerror;
  10469. window.onerror = null;
  10470. let r;
  10471. try {
  10472. r = parse(...arguments);
  10473. } catch (e) {
  10474. r = e;
  10475. }
  10476. window.onerror = onerror;
  10477. if (r instanceof Error) {
  10478. throw r;
  10479. }
  10480. return r;
  10481. }
  10482.  
  10483. })(JSON.parse);
  10484.  
  10485.  
  10486. })();
  10487.  
  10488.  
  10489. // << if FIX_yt_player >>
  10490.  
  10491. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  10492. const PERF_471489_ = true;
  10493. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  10494. // This script uses a much gentle way to tamer the JS engine instead.
  10495.  
  10496. // << end >>
  10497.  
  10498. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  10499.  
  10500.  
  10501.  
  10502. const nilFn = () => { };
  10503.  
  10504. let isMainWindow = false;
  10505. try {
  10506. isMainWindow = window.document === window.top.document
  10507. } catch (e) { }
  10508.  
  10509. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  10510. let headLinkCollection = null;
  10511.  
  10512.  
  10513. // const assertor = (f) => f() || console.assert(false, `${f}`);
  10514.  
  10515. const fnIntegrity = (f, d) => {
  10516. if (!f || typeof f !== 'function') {
  10517. console.warn('f is not a function', f);
  10518. return;
  10519. }
  10520. let p = `${f}`, s = 0, j = -1, w = 0;
  10521. for (let i = 0, l = p.length; i < l; i++) {
  10522. const t = p[i];
  10523. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  10524. if (j < i - 1) w++;
  10525. j = i;
  10526. } else {
  10527. s++;
  10528. }
  10529. }
  10530. let itz = `${f.length}.${s}.${w}`;
  10531. if (!d) {
  10532. return itz;
  10533. } else {
  10534. return itz === d;
  10535. }
  10536. };
  10537.  
  10538. const getZqOu = (_yt_player) => {
  10539.  
  10540. const w = 'ZqOu';
  10541.  
  10542. let arr = [];
  10543.  
  10544. for (const [k, v] of Object.entries(_yt_player)) {
  10545.  
  10546. const p = typeof v === 'function' ? v.prototype : 0;
  10547. if (p
  10548. && typeof p.start === 'function' && p.start.length === 0 // Ou
  10549. && typeof p.isActive === 'function' && p.isActive.length === 0
  10550. && typeof p.stop === 'function' && p.stop.length === 0
  10551. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  10552. && !p.send && !p.abort
  10553. && !p.sample && !p.initialize && !p.fail && !p.getName
  10554. // && !p.dispose && !p.isDisposed
  10555.  
  10556. ) {
  10557. arr = addProtoToArr(_yt_player, k, arr) || arr;
  10558.  
  10559.  
  10560. }
  10561.  
  10562. }
  10563.  
  10564. if (arr.length === 0) {
  10565.  
  10566. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10567. } else {
  10568.  
  10569. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10570. return arr[0];
  10571. }
  10572.  
  10573. }
  10574.  
  10575. const getZqQu = (_yt_player) => {
  10576.  
  10577. const w = 'ZqQu';
  10578.  
  10579. let arr = [];
  10580.  
  10581.  
  10582. for (const [k, v] of Object.entries(_yt_player)) {
  10583.  
  10584. const p = typeof v === 'function' ? v.prototype : 0;
  10585. if (p
  10586. && typeof p.start === 'function' && p.start.length === 1 // Qu
  10587. && typeof p.isActive === 'function' && p.isActive.length === 0
  10588. && typeof p.stop === 'function' && p.stop.length === 0
  10589. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  10590. && !p.send && !p.abort
  10591. && !p.sample && !p.initialize && !p.fail && !p.getName
  10592. // && !p.dispose && !p.isDisposed
  10593.  
  10594. ) {
  10595. arr = addProtoToArr(_yt_player, k, arr) || arr;
  10596.  
  10597.  
  10598. }
  10599.  
  10600. }
  10601.  
  10602. if (arr.length === 0) {
  10603.  
  10604. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10605. } else {
  10606.  
  10607. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10608. return arr[0];
  10609. }
  10610.  
  10611. }
  10612.  
  10613.  
  10614. const getVG = (_yt_player) => {
  10615. const w = 'VG';
  10616.  
  10617. let arr = [];
  10618.  
  10619. for (const [k, v] of Object.entries(_yt_player)) {
  10620.  
  10621. const p = typeof v === 'function' ? v.prototype : 0;
  10622. if (p
  10623. && typeof p.show === 'function' && p.show.length === 1
  10624. && typeof p.hide === 'function' && p.hide.length === 0
  10625. && typeof p.stop === 'function' && p.stop.length === 0) {
  10626.  
  10627. arr = addProtoToArr(_yt_player, k, arr) || arr;
  10628.  
  10629. }
  10630.  
  10631. }
  10632.  
  10633.  
  10634. if (arr.length === 0) {
  10635.  
  10636. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10637. } else {
  10638.  
  10639. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10640. return arr[0];
  10641. }
  10642.  
  10643.  
  10644.  
  10645. }
  10646.  
  10647.  
  10648. const getzo = (_yt_player) => {
  10649. const w = 'zo';
  10650.  
  10651. let arr = [];
  10652.  
  10653. for (const [k, v] of Object.entries(_yt_player)) {
  10654.  
  10655. if (
  10656. typeof v === 'function' && v.length === 3 && k.length < 3
  10657. ) {
  10658. const vt = `${v}`;
  10659. if (vt.length >= 21 && vt.includes(".style[")) {
  10660. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  10661. arr.push(k);
  10662. } else {
  10663. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  10664. }
  10665. }
  10666. }
  10667.  
  10668. }
  10669.  
  10670. if (arr.length === 0) {
  10671.  
  10672. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10673. } else {
  10674.  
  10675. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10676. return arr[0];
  10677. }
  10678.  
  10679. }
  10680.  
  10681. const addProtoToArr = (parent, key, arr) => {
  10682.  
  10683.  
  10684. let isChildProto = false;
  10685. for (const sr of arr) {
  10686. if (parent[key].prototype instanceof parent[sr]) {
  10687. isChildProto = true;
  10688. break;
  10689. }
  10690. }
  10691.  
  10692. if (isChildProto) return;
  10693.  
  10694. arr = arr.filter(sr => {
  10695. if (parent[sr].prototype instanceof parent[key]) {
  10696. return false;
  10697. }
  10698. return true;
  10699. });
  10700.  
  10701. arr.push(key);
  10702.  
  10703. return arr;
  10704.  
  10705.  
  10706. }
  10707.  
  10708. const getuG = (_yt_player) => {
  10709.  
  10710. const w = 'uG';
  10711.  
  10712. let arr = [];
  10713.  
  10714. for (const [k, v] of Object.entries(_yt_player)) {
  10715.  
  10716.  
  10717. const p = typeof v === 'function' ? v.prototype : 0;
  10718.  
  10719. if (p
  10720. && typeof p.createElement === 'function' && p.createElement.length === 2
  10721. && typeof p.detach === 'function' && p.detach.length === 0
  10722. && typeof p.update === 'function' && p.update.length === 1
  10723. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  10724. ) {
  10725.  
  10726. arr = addProtoToArr(_yt_player, k, arr) || arr;
  10727.  
  10728. }
  10729.  
  10730. }
  10731.  
  10732.  
  10733.  
  10734.  
  10735.  
  10736. if (arr.length === 0) {
  10737.  
  10738. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10739. } else {
  10740.  
  10741. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10742. return arr[0];
  10743. }
  10744.  
  10745. }
  10746.  
  10747.  
  10748. const getQT = (_yt_player) => {
  10749. const w = 'QT';
  10750.  
  10751. let arr = [];
  10752. let brr = new Map();
  10753.  
  10754. for (const [k, v] of Object.entries(_yt_player)) {
  10755.  
  10756. const p = typeof v === 'function' ? v.prototype : 0;
  10757. if (p) {
  10758. let q = 0;
  10759. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  10760. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  10761. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  10762.  
  10763. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  10764.  
  10765. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  10766.  
  10767. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  10768. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  10769. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  10770. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  10771.  
  10772.  
  10773. // differentiate QT and DX
  10774.  
  10775. q += 280;
  10776. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  10777. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  10778. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  10779. if (typeof p.seekBy === 'function') q += 4;
  10780. if (typeof p.seekTo === 'function') q += 4;
  10781. if (typeof p.getStoryboardFormat === 'function') q += 4;
  10782. if (typeof p.getDuration === 'function') q += 4;
  10783. if (typeof p.loadModule === 'function') q += 4;
  10784. if (typeof p.unloadModule === 'function') q += 4;
  10785. if (typeof p.getOption === 'function') q += 4;
  10786. if (typeof p.getOptions === 'function') q += 4;
  10787. if (typeof p.setOption === 'function') q += 4;
  10788. if (typeof p.addCueRange === 'function') q += 4;
  10789. if (typeof p.getDebugText === 'function') q += 4;
  10790. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  10791. if (typeof p.setSizeStyle === 'function') q += 4;
  10792. if (typeof p.showControls === 'function') q += 4;
  10793. if (typeof p.hideControls === 'function') q += 4;
  10794. if (typeof p.getVideoContentRect === 'function') q += 4;
  10795. if (typeof p.toggleFullscreen === 'function') q += 4;
  10796. if (typeof p.isFullscreen === 'function') q += 4;
  10797. if (typeof p.cancelPlayback === 'function') q += 4;
  10798. if (typeof p.getProgressState === 'function') q += 4;
  10799. if (typeof p.isInline === 'function') q += 4;
  10800. if (typeof p.setInline === 'function') q += 4;
  10801. if (typeof p.toggleSubtitles === 'function') q += 4;
  10802. if (typeof p.getPlayerSize === 'function') q += 4;
  10803. if (typeof p.wakeUpControls === 'function') q += 4;
  10804. if (typeof p.setCenterCrop === 'function') q += 4;
  10805. if (typeof p.getLoopVideo === 'function') q += 4;
  10806. if (typeof p.setLoopVideo === 'function') q += 4;
  10807.  
  10808.  
  10809. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  10810.  
  10811. if (q > 0) brr.set(k, q);
  10812.  
  10813. }
  10814.  
  10815. }
  10816.  
  10817. if (arr.length === 0) {
  10818.  
  10819. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10820. } else {
  10821.  
  10822. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  10823.  
  10824. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  10825.  
  10826. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10827. return arr[0][0];
  10828. }
  10829.  
  10830.  
  10831.  
  10832. }
  10833.  
  10834.  
  10835.  
  10836. const getSV = (_yt_player) => {
  10837. const w = 'SV';
  10838.  
  10839. let arr = [];
  10840. let brr = new Map();
  10841.  
  10842. for (const [k, v] of Object.entries(_yt_player)) {
  10843.  
  10844. const p = typeof v === 'function' ? v.prototype : 0;
  10845. if (p) {
  10846. let q = 0;
  10847. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  10848. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  10849. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  10850.  
  10851. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  10852.  
  10853. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  10854.  
  10855. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  10856. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  10857. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  10858. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  10859.  
  10860.  
  10861. // differentiate QT and DX
  10862.  
  10863.  
  10864. q += 280;
  10865.  
  10866. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  10867. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  10868. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  10869. if (typeof p.seekBy === 'function') q -= 4;
  10870. if (typeof p.seekTo === 'function') q -= 4;
  10871. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  10872. if (typeof p.getDuration === 'function') q -= 4;
  10873. if (typeof p.loadModule === 'function') q -= 4;
  10874. if (typeof p.unloadModule === 'function') q -= 4;
  10875. if (typeof p.getOption === 'function') q -= 4;
  10876. if (typeof p.getOptions === 'function') q -= 4;
  10877. if (typeof p.setOption === 'function') q -= 4;
  10878. if (typeof p.addCueRange === 'function') q -= 4;
  10879. if (typeof p.getDebugText === 'function') q -= 4;
  10880. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  10881. if (typeof p.setSizeStyle === 'function') q -= 4;
  10882. if (typeof p.showControls === 'function') q -= 4;
  10883. if (typeof p.hideControls === 'function') q -= 4;
  10884. if (typeof p.getVideoContentRect === 'function') q -= 4;
  10885. if (typeof p.toggleFullscreen === 'function') q -= 4;
  10886. if (typeof p.isFullscreen === 'function') q -= 4;
  10887. if (typeof p.cancelPlayback === 'function') q -= 4;
  10888. if (typeof p.getProgressState === 'function') q -= 4;
  10889. if (typeof p.isInline === 'function') q -= 4;
  10890. if (typeof p.setInline === 'function') q -= 4;
  10891. if (typeof p.toggleSubtitles === 'function') q -= 4;
  10892. if (typeof p.getPlayerSize === 'function') q -= 4;
  10893. if (typeof p.wakeUpControls === 'function') q -= 4;
  10894. if (typeof p.setCenterCrop === 'function') q -= 4;
  10895. if (typeof p.getLoopVideo === 'function') q -= 4;
  10896. if (typeof p.setLoopVideo === 'function') q -= 4;
  10897.  
  10898.  
  10899. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  10900.  
  10901. if (q > 0) brr.set(k, q);
  10902.  
  10903. }
  10904.  
  10905. }
  10906.  
  10907. if (arr.length === 0) {
  10908.  
  10909. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  10910. } else {
  10911.  
  10912. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  10913.  
  10914. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  10915.  
  10916. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  10917. return arr[0][0];
  10918. }
  10919.  
  10920.  
  10921.  
  10922. }
  10923.  
  10924.  
  10925.  
  10926.  
  10927. const getDX = (_yt_player) => {
  10928. const w = 'DX';
  10929.  
  10930. let arr = [];
  10931. let brr = new Map();
  10932.  
  10933. for (const [k, v] of Object.entries(_yt_player)) {
  10934.  
  10935. const p = typeof v === 'function' ? v.prototype : 0;
  10936. if (p) {
  10937. let q = 0;
  10938. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  10939. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  10940. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  10941.  
  10942. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  10943.  
  10944.  
  10945. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  10946.  
  10947. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  10948.  
  10949. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  10950. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  10951. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  10952. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  10953.  
  10954.  
  10955. // differentiate QT and DX
  10956.  
  10957.  
  10958. q += 280;
  10959.  
  10960. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  10961. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  10962. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  10963. if (typeof p.seekBy === 'function') q -= 4;
  10964. if (typeof p.seekTo === 'function') q -= 4;
  10965. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  10966. if (typeof p.getDuration === 'function') q -= 4;
  10967. if (typeof p.loadModule === 'function') q -= 4;
  10968. if (typeof p.unloadModule === 'function') q -= 4;
  10969. if (typeof p.getOption === 'function') q -= 4;
  10970. if (typeof p.getOptions === 'function') q -= 4;
  10971. if (typeof p.setOption === 'function') q -= 4;
  10972. if (typeof p.addCueRange === 'function') q -= 4;
  10973. if (typeof p.getDebugText === 'function') q -= 4;
  10974. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  10975. if (typeof p.setSizeStyle === 'function') q -= 4;
  10976. if (typeof p.showControls === 'function') q -= 4;
  10977. if (typeof p.hideControls === 'function') q -= 4;
  10978. if (typeof p.getVideoContentRect === 'function') q -= 4;
  10979. if (typeof p.toggleFullscreen === 'function') q -= 4;
  10980. if (typeof p.isFullscreen === 'function') q -= 4;
  10981. if (typeof p.cancelPlayback === 'function') q -= 4;
  10982. if (typeof p.getProgressState === 'function') q -= 4;
  10983. if (typeof p.isInline === 'function') q -= 4;
  10984. if (typeof p.setInline === 'function') q -= 4;
  10985. if (typeof p.toggleSubtitles === 'function') q -= 4;
  10986. if (typeof p.getPlayerSize === 'function') q -= 4;
  10987. if (typeof p.wakeUpControls === 'function') q -= 4;
  10988. if (typeof p.setCenterCrop === 'function') q -= 4;
  10989. if (typeof p.getLoopVideo === 'function') q -= 4;
  10990. if (typeof p.setLoopVideo === 'function') q -= 4;
  10991.  
  10992.  
  10993. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  10994.  
  10995. if (q > 0) brr.set(k, q);
  10996.  
  10997. }
  10998.  
  10999. }
  11000.  
  11001. if (arr.length === 0) {
  11002.  
  11003. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  11004. } else {
  11005.  
  11006. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  11007.  
  11008. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  11009.  
  11010. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  11011. return arr[0][0];
  11012. }
  11013.  
  11014.  
  11015.  
  11016. }
  11017.  
  11018.  
  11019.  
  11020. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  11021.  
  11022. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  11023. let pageSetupState = 0;
  11024.  
  11025. isPrepareCachedV && (() => {
  11026.  
  11027. pageSetupVideoId = '';
  11028. const clearCachedV = () => {
  11029. pageSetupVideoId = '';
  11030. pageSetupState = 0;
  11031. }
  11032. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  11033. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  11034. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  11035. document.addEventListener('yt-navigate-finish', () => {
  11036. pageSetupState = 1;
  11037. try {
  11038. const url = new URL(location.href);
  11039. if (!url || !isWatchPageURL(url)) {
  11040. pageSetupVideoId = '';
  11041. } else {
  11042. pageSetupVideoId = url.searchParams.get('v') || '';
  11043. }
  11044. } catch (e) {
  11045. pageSetupVideoId = '';
  11046. }
  11047. }, false);
  11048.  
  11049. })();
  11050.  
  11051. let videoPlayingY = null;
  11052.  
  11053. isPrepareCachedV && (() => {
  11054.  
  11055. let getNext = true;
  11056. let videoPlayingX = {
  11057. get videoId() {
  11058. if (getNext) {
  11059. getNext = false;
  11060.  
  11061. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  11062. const arr = [];
  11063. for (const element of elements) {
  11064. if (!element.closest('[hidden]')) arr.push(element);
  11065. }
  11066. if (arr.length !== 1) this.__videoId__ = '';
  11067. else {
  11068. this.__videoId__ = arr[0].getAttribute('video-id');
  11069. }
  11070.  
  11071. }
  11072. return this.__videoId__ || '';
  11073. }
  11074. }
  11075.  
  11076. videoPlayingY = videoPlayingX;
  11077. const handler = (evt) => {
  11078. const target = (evt || 0).target;
  11079. if (target instanceof HTMLVideoElement) {
  11080. getNext = true;
  11081. }
  11082. }
  11083. document.addEventListener('loadedmetadata', handler, true);
  11084. document.addEventListener('durationchange', handler, true);
  11085.  
  11086. })();
  11087.  
  11088.  
  11089.  
  11090. const cleanContext = async (win) => {
  11091. const waitFn = requestAnimationFrame; // shall have been binded to window
  11092. try {
  11093. let mx = 16; // MAX TRIAL
  11094. const frameId = 'vanillajs-iframe-v1';
  11095. /** @type {HTMLIFrameElement | null} */
  11096. let frame = document.getElementById(frameId);
  11097. let removeIframeFn = null;
  11098. if (!frame) {
  11099. frame = document.createElement('iframe');
  11100. frame.id = frameId;
  11101. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  11102. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  11103. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  11104. n.appendChild(frame);
  11105. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  11106. const root = document.documentElement;
  11107. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  11108. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  11109.  
  11110. removeIframeFn = (setTimeout) => {
  11111. const removeIframeOnDocumentReady = (e) => {
  11112. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  11113. e = n;
  11114. n = win = removeIframeFn = 0;
  11115. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  11116. }
  11117. if (!setTimeout || document.readyState !== 'loading') {
  11118. removeIframeOnDocumentReady();
  11119. } else {
  11120. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  11121. }
  11122. }
  11123. }
  11124. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  11125. const fc = frame.contentWindow;
  11126. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  11127. try {
  11128. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  11129. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  11130. for (let k in res) res[k] = res[k].bind(win); // necessary
  11131. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  11132. res.animate = fc.HTMLElement.prototype.animate;
  11133. res.perfNow = fc.performance.now;
  11134. return res;
  11135. } catch (e) {
  11136. if (removeIframeFn) removeIframeFn();
  11137. return null;
  11138. }
  11139. } catch (e) {
  11140. console.warn(e);
  11141. return null;
  11142. }
  11143. };
  11144.  
  11145. const promiseForYtActionCalled = new Promise(resolve => {
  11146.  
  11147. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  11148. if (typeof AbortSignal !== 'undefined') {
  11149. let hn = () => {
  11150. if (!hn) return;
  11151. hn = null;
  11152. resolve(document.querySelector(appTag));
  11153. };
  11154. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  11155. } else {
  11156. let hn = () => {
  11157. if (!hn) return;
  11158. document.removeEventListener('yt-action', hn, true);
  11159. hn = null;
  11160. resolve(document.querySelector(appTag));
  11161. };
  11162. document.addEventListener('yt-action', hn, true);
  11163. }
  11164. });
  11165.  
  11166. cleanContext(window).then(__CONTEXT__ => {
  11167. if (!__CONTEXT__) return null;
  11168.  
  11169. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  11170.  
  11171.  
  11172. performance.now17 = perfNow.bind(performance);
  11173.  
  11174.  
  11175.  
  11176. __requestAnimationFrame__ = requestAnimationFrame;
  11177.  
  11178.  
  11179. const isGPUAccelerationAvailable = (() => {
  11180. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  11181. try {
  11182. const canvas = document.createElement('canvas');
  11183. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  11184. } catch (e) {
  11185. return false;
  11186. }
  11187. })();
  11188.  
  11189. const foregroundPromiseFn_noGPU = (() => {
  11190.  
  11191. if (isGPUAccelerationAvailable) return null;
  11192.  
  11193. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  11194. if (!pd || typeof pd.get !== 'function') return null;
  11195. const pdGet = pd.get;
  11196.  
  11197. let pr = null;
  11198.  
  11199. let hState = pdGet.call(document) === 'hidden';
  11200. // let cid = 0;
  11201. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  11202. const newHState = pdGet.call(document) === 'hidden';
  11203. if (hState !== newHState) {
  11204. // if (cid > 0) cid = clearInterval(cid);
  11205. hState = newHState;
  11206. if (!hState && pr) pr = pr.resolve();
  11207. }
  11208. });
  11209.  
  11210. // cid = setInterval(() => {
  11211. // const newHState = document.visibilityState === 'hidden';
  11212. // if (hState !== newHState) {
  11213. // hState = newHState;
  11214. // if (!hState && pr) pr = pr.resolve();
  11215. // }
  11216. // }, 100);
  11217.  
  11218.  
  11219. return (() => {
  11220. if (pr) return pr;
  11221. const w = ((!hState && setTimeout(() => {
  11222. if (!hState && pr === w) pr = pr.resolve();
  11223. })), (pr = new PromiseExternal()));
  11224. return w;
  11225. });
  11226.  
  11227. })();
  11228.  
  11229.  
  11230. let rafPromise = null;
  11231. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  11232. requestAnimationFrame(hRes => {
  11233. rafPromise = null;
  11234. resolve(hRes);
  11235. });
  11236. }));
  11237.  
  11238. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  11239.  
  11240.  
  11241. const wmComputedStyle = new WeakMap();
  11242.  
  11243. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  11244. window.__native__getComputedStyle__ = getComputedStyle;
  11245. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  11246. window.__original__getComputedStyle__ = window.getComputedStyle;
  11247. window.getComputedStyle = function (elem) {
  11248. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  11249. return window.__original__getComputedStyle__(...arguments);
  11250. }
  11251. let cs = wmComputedStyle.get(elem);
  11252. if (!cs) {
  11253. cs = window.__native__getComputedStyle__(elem);
  11254. wmComputedStyle.set(elem, cs);
  11255. }
  11256. return cs;
  11257. };
  11258. } else {
  11259. window.__original__getComputedStyle__ = null;
  11260. }
  11261. window.__jst__getComputedStyle__ = window.getComputedStyle;
  11262. }
  11263.  
  11264. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  11265. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  11266. window.getComputedStyle = window.__jst__getComputedStyle__;
  11267. }
  11268. });
  11269.  
  11270. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  11271. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  11272.  
  11273. const promiseForTamerTimeout = new Promise(resolve => {
  11274. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  11275. setTimeout(resolve, 480);
  11276. }, { capture: true, passive: true, once: true });
  11277. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  11278. setTimeout(resolve, 1200);
  11279. });
  11280. setTimeout(resolve, 3000);
  11281. });
  11282.  
  11283. const promiseForPageInitied = new Promise(resolve => {
  11284. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  11285. setTimeout(resolve, 450);
  11286. }, { capture: true, passive: true, once: true });
  11287. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  11288. setTimeout(resolve, 900);
  11289. });
  11290. setTimeout(resolve, 1800);
  11291. });
  11292.  
  11293. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  11294. NO_PRELOAD_GENERATE_204_BYPASS = true;
  11295. headLinkCollection = null;
  11296. });
  11297.  
  11298.  
  11299. NATIVE_CANVAS_ANIMATION && (() => {
  11300.  
  11301. observablePromise(() => {
  11302. HTMLCanvasElement.prototype.animate = animate;
  11303. }, promiseForTamerTimeout).obtain();
  11304.  
  11305. })();
  11306.  
  11307.  
  11308.  
  11309.  
  11310. FIX_ytAction_ && (async () => {
  11311.  
  11312. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  11313.  
  11314. const ytdApp = await new Promise(resolve => {
  11315.  
  11316. whenCEDefined(appTag).then(() => {
  11317. const ytdApp = document.querySelector(appTag);
  11318. if (ytdApp) {
  11319. resolve(ytdApp);
  11320. return;
  11321. }
  11322. let mo = new MutationObserver(() => {
  11323. const ytdApp = document.querySelector(appTag);
  11324. if (!ytdApp) return;
  11325. if (mo) {
  11326. mo.disconnect();
  11327. mo.takeRecords();
  11328. mo = null;
  11329. }
  11330. resolve(ytdApp);
  11331. });
  11332. mo.observe(document, { subtree: true, childList: true });
  11333. });
  11334.  
  11335. });
  11336.  
  11337. if (!ytdApp) return;
  11338. const cProto = insp(ytdApp).constructor.prototype;
  11339.  
  11340. if (!cProto) return;
  11341. let mbd = 0;
  11342.  
  11343. const fixer = (_ytdApp) => {
  11344. const ytdApp = insp(_ytdApp);
  11345. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  11346. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  11347. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  11348. mbd++;
  11349. }
  11350. }
  11351.  
  11352. observablePromise(() => {
  11353.  
  11354. if (typeof cProto.created === 'function' && !cProto.created56) {
  11355. cProto.created56 = cProto.created;
  11356. cProto.created = function (...args) {
  11357. const r = this.created56(...args);
  11358. fixer(this);
  11359. return r;
  11360. };
  11361. mbd++;
  11362. }
  11363.  
  11364. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  11365. cProto.onYtAction57_ = cProto.onYtAction_;
  11366. cProto.onYtAction_ = function (...args) {
  11367. Promise.resolve().then(() => this.onYtAction57_(...args));
  11368. };
  11369. mbd++;
  11370. }
  11371.  
  11372. if (ytdApp) fixer(ytdApp);
  11373.  
  11374. /*
  11375. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  11376. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  11377. actionRouter_.handleAction57 = actionRouter_.handleAction;
  11378. actionRouter_.handleAction = function (...args) {
  11379. Promise.resolve().then(() => this.handleAction57(...args));
  11380. }
  11381. mbd++;
  11382. }
  11383. */
  11384.  
  11385. // if(mbd === 3) return 1;
  11386. if (mbd >= 3) return 1;
  11387.  
  11388. }, new Promise(r => setTimeout(r, 1000))).obtain();
  11389.  
  11390. })();
  11391.  
  11392.  
  11393. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  11394.  
  11395. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  11396.  
  11397. const app = await observablePromise(() => {
  11398.  
  11399. return document.querySelector(appTag);
  11400.  
  11401. }).obtain();
  11402.  
  11403. if (!app) return;
  11404.  
  11405. const appCnt = insp(app);
  11406. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  11407.  
  11408.  
  11409.  
  11410.  
  11411. });
  11412.  
  11413.  
  11414. // let _yt_player_promise = null;
  11415. /*
  11416. const getYtPlayerPromise = () => {
  11417. if (!_yt_player_promise) {
  11418. _yt_player_promise = new Promise(resolve => {
  11419. let cid = setInterval(() => {
  11420. let t = (((window || 0)._yt_player || 0) || 0);
  11421. if (t) {
  11422. clearInterval(cid);
  11423. resolve(t);
  11424. }
  11425. }, 1);
  11426. promiseForTamerTimeout.then(() => {
  11427. resolve(null)
  11428. });
  11429. });
  11430. }
  11431. return _yt_player_promise;
  11432. }
  11433. */
  11434. const _yt_player_observable = observablePromise(() => {
  11435. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  11436. if (_yt_player) {
  11437. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  11438. return _yt_player;
  11439. }
  11440. }, promiseForTamerTimeout);
  11441.  
  11442. const polymerObservable = observablePromise(() => {
  11443. const Polymer = window.Polymer;
  11444. if (typeof Polymer !== 'function') return;
  11445. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  11446. return Polymer;
  11447. }, promiseForTamerTimeout);
  11448.  
  11449. const schedulerInstanceObservable = observablePromise(() => {
  11450. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  11451. }, promiseForTamerTimeout);
  11452.  
  11453. const timelineObservable = observablePromise(() => {
  11454. let t = (((document || 0).timeline || 0) || 0);
  11455. if (t && typeof t._play === 'function') {
  11456. return t;
  11457. }
  11458. }, promiseForTamerTimeout);
  11459. const animationObservable = observablePromise(() => {
  11460. let t = (((window || 0).Animation || 0) || 0);
  11461. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  11462. return t;
  11463. }
  11464. }, promiseForTamerTimeout);
  11465.  
  11466.  
  11467. const getScreenInfo = {
  11468. screenWidth: 0,
  11469. screenHeight: 0,
  11470. valueReady: false,
  11471. onResize: () => {
  11472. getScreenInfo.valueReady = false;
  11473. },
  11474. sizeProvided: () => {
  11475. if (getScreenInfo.valueReady) return true;
  11476. getScreenInfo.screenWidth = screen.width;
  11477. getScreenInfo.screenHeight = screen.height;
  11478. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  11479. getScreenInfo.valueReady = true;
  11480. return true;
  11481. }
  11482. return false;
  11483. }
  11484. };
  11485.  
  11486. window.addEventListener('resize', getScreenInfo.onResize, true);
  11487.  
  11488.  
  11489. // const hookLeftPending = new WeakMap();
  11490.  
  11491. const isNaNx = Number.isNaN;
  11492.  
  11493. const hookLeftPD = {
  11494. get() {
  11495. const p = 'left';
  11496. // const o = hookLeftPending.get(this);
  11497. // if (o && o.key) {
  11498. // this.setProperty(p, o.value);
  11499. // o.key = null
  11500. // }
  11501. return this.getPropertyValue(p);
  11502. },
  11503. set(v) {
  11504.  
  11505. const p = 'left';
  11506. const cv = this.getPropertyValue(p);
  11507. const sv = v;
  11508.  
  11509. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  11510.  
  11511. // console.log(8380,did, cv, sv)
  11512. if (!cv && !sv) return true;
  11513. if (cv === sv) return true;
  11514.  
  11515. // skip 0~9px => L>=4
  11516.  
  11517. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  11518.  
  11519. if (!isNaNx(qsv)) {
  11520. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  11521.  
  11522. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  11523. const { screenWidth, screenHeight } = getScreenInfo;
  11524. let pWidth = screenWidth + 1024;
  11525. let pHeight = screenHeight + 768;
  11526. const minRatio = 0.003;
  11527. const dw = pWidth * 0.0003; // min dw = 0.3072
  11528. const dh = pHeight * 0.0003; // min dh = 0.2304
  11529. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  11530. if (Math.abs(qcv - qsv) < dw) return true;
  11531. }
  11532.  
  11533. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  11534. if (`${v}`.length > `${sv}`.length) v = sv;
  11535. // console.log(8382, did, sv, nv, cv, this)
  11536. }
  11537.  
  11538. // Promise.resolve().then(() => {
  11539. // const o = hookLeftPending.get(this);
  11540. // if (o && o.key === did) {
  11541. // this.setProperty(p, o.value);
  11542. // o.key = null;
  11543. // }
  11544. // });
  11545. // hookLeftPending.set(this, {
  11546. // key: did,
  11547. // value: nv
  11548. // });
  11549.  
  11550. // if (nv != v) {
  11551. // console.log(8387, v, nv);
  11552. // }
  11553.  
  11554. this.setProperty(p, v);
  11555. // console.log(8383, did, this.getPropertyValue(p))
  11556. return true;
  11557. },
  11558. enumerable: true,
  11559. configurable: true
  11560. };
  11561.  
  11562.  
  11563. if (HOOK_CSSPD_LEFT) {
  11564.  
  11565.  
  11566. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  11567.  
  11568. }
  11569.  
  11570.  
  11571.  
  11572.  
  11573.  
  11574. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  11575.  
  11576. const evKey = `${_evKey}`;
  11577. const fvKey = `${_fvKey}`;
  11578. const debug = !!_debug;
  11579.  
  11580. const _yt_player = await _yt_player_observable.obtain();
  11581.  
  11582.  
  11583. if (!_yt_player || typeof _yt_player !== 'object') return;
  11584.  
  11585.  
  11586. const getArr = (_yt_player) => {
  11587.  
  11588. let arr = [];
  11589.  
  11590. for (const [k, v] of Object.entries(_yt_player)) {
  11591.  
  11592. const p = typeof v === 'function' ? v.prototype : 0;
  11593. if (p
  11594. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  11595.  
  11596. ) {
  11597. arr = addProtoToArr(_yt_player, k, arr) || arr;
  11598.  
  11599. }
  11600.  
  11601. }
  11602.  
  11603. if (arr.length === 0) {
  11604.  
  11605. console.warn(`Key prop [${evKey}] does not exist.`);
  11606. } else {
  11607.  
  11608. return arr;
  11609. }
  11610.  
  11611. };
  11612.  
  11613. const arr = getArr(_yt_player);
  11614.  
  11615.  
  11616. if (!arr) return;
  11617.  
  11618. debug && console.log(`FIX_${evKey}`, arr);
  11619.  
  11620. const f = function (...args) {
  11621. Promise.resolve().then(() => this[fvKey](...args));
  11622. };
  11623.  
  11624.  
  11625. for (const k of arr) {
  11626.  
  11627. const g = _yt_player;
  11628. const gk = g[k];
  11629. const gkp = gk.prototype;
  11630.  
  11631. debug && console.log(237, k, gkp)
  11632.  
  11633. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  11634. gkp[fvKey] = gkp[evKey];
  11635. gkp[evKey] = f;
  11636. }
  11637. }
  11638.  
  11639.  
  11640.  
  11641.  
  11642. }
  11643.  
  11644. if (!isChatRoomURL) {
  11645.  
  11646. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  11647. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  11648. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  11649. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  11650. if (FIX_VideoEVENTS_v2) {
  11651. const FIX_VideoEVENTS_DEBUG = 0;
  11652. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  11653. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  11654. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  11655. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  11656. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  11657. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  11658. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  11659. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  11660. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  11661.  
  11662. }
  11663. // onMutedAutoplayChange
  11664. // onVolumeChange
  11665. // onPlaybackRateChange
  11666.  
  11667. // onAirPlayActiveChange
  11668. // onAirPlayAvailabilityChange
  11669. // onApiChange
  11670. // onAutoplayBlocked
  11671. // onDrmOutputRestricted
  11672. // onFullscreenChange
  11673. // onLoadProgress
  11674. // onLoadedMetadata
  11675. // onVideoDataChange
  11676. // onVideoProgress
  11677.  
  11678. }
  11679.  
  11680.  
  11681. let isAmended_Polymer_RenderStatus = false;
  11682.  
  11683. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  11684.  
  11685. const Polymer = await polymerObservable.obtain();
  11686. if (!Polymer) return;
  11687.  
  11688. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  11689. isAmended_Polymer_RenderStatus = true;
  11690.  
  11691. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  11692. let arrBefore = null, arrAfter = null;
  11693. const push = Array.prototype.push;
  11694. let arr = null;
  11695. Array.prototype.push = function () {
  11696. arr = this;
  11697. }
  11698. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  11699. if (arr) arrBefore = arr;
  11700. arr = null;
  11701. Polymer.RenderStatus.afterNextRender({}, {}, {});
  11702. if (arr) arrAfter = arr;
  11703. arr = null;
  11704. Array.prototype.push = push;
  11705. Polymer.RenderStatus.arrBefore = arrBefore;
  11706. Polymer.RenderStatus.arrAfter = arrAfter;
  11707.  
  11708. if (arrBefore && arrAfter) {
  11709.  
  11710. Function.prototype.call7900 = Function.prototype.call;
  11711. Function.prototype.apply7900 = Function.prototype.apply;
  11712. Function.prototype.apply7948 = function (obj, args) {
  11713. const f = this;
  11714. let m = kRef(obj);
  11715. if (!m) return;
  11716. if (m.is && !m.nodeName) {
  11717. if (!m.isAttached || !m.hostElement) {
  11718. return;
  11719. }
  11720. }
  11721. try {
  11722. return !args ? f.call7900(m) : f.apply7900(m, args);
  11723. } catch (e) {
  11724. console.warn(e);
  11725. }
  11726. return null;
  11727. }
  11728.  
  11729. arrBefore.push = arrAfter.push = function (a) {
  11730. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  11731. if (a[0].deref) a[0] = kRef(a[0]);
  11732. const f = a[1]
  11733. const obj = a[0]
  11734. const args = a[2];
  11735. f.apply = f.apply7948;
  11736. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  11737. a[0] = obj[wk]
  11738. // console.log(4992, a)
  11739. return push.call(this, a);
  11740. }
  11741.  
  11742. }
  11743.  
  11744.  
  11745. }
  11746. // Polymer.RenderStatus.beforeNextRender
  11747. }
  11748.  
  11749. if (FIX_Polymer_dom) {
  11750.  
  11751. const checkPDFuncValue = (pd) => {
  11752. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  11753. }
  11754. const checkPDFuncValue2 = (pd) => {
  11755. return pd && typeof pd.value == 'function'
  11756. }
  11757.  
  11758. const checkPDFuncGet = (pd) => {
  11759. return pd && typeof pd.get == 'function'
  11760. }
  11761.  
  11762. const domX = Polymer.dom(document.createElement('null'));
  11763. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  11764. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  11765. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  11766. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  11767. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  11768. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  11769. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  11770. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  11771. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  11772.  
  11773.  
  11774. // getOwnerRoot - to be reviewed
  11775. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  11776.  
  11777. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  11778. domXP.getOwnerRoot = function () {
  11779. try {
  11780. const p = this.node;
  11781.  
  11782. if (p instanceof HTMLElement_) {
  11783. const pp = pd2.get.call(p);
  11784. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  11785. return pp.getRootNode();
  11786. }
  11787.  
  11788. }
  11789. } catch (e) { }
  11790. return this.getOwnerRoot15();
  11791. }
  11792.  
  11793. Polymer.__fixedGetOwnerRoot__ = 1;
  11794. }
  11795.  
  11796.  
  11797.  
  11798.  
  11799. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  11800.  
  11801. domXP.querySelector15 = domXP.querySelector;
  11802.  
  11803. const querySelectorFn = function (query) {
  11804. try {
  11805. const p = this.node;
  11806.  
  11807. if (p instanceof Document && p.isConnected === true) {
  11808. return pd4b.value.call(p, query);
  11809. }
  11810.  
  11811. } catch (e) { }
  11812. return this.querySelector15(query);
  11813. }
  11814.  
  11815. Object.defineProperty(domXP, 'querySelector', {
  11816. get() {
  11817. return querySelectorFn;
  11818. },
  11819. set(nv) {
  11820. if (nv === querySelectorFn) return true;
  11821. this.querySelector15 = nv;
  11822. return true;
  11823. },
  11824.  
  11825. enumerable: false,
  11826. configurable: true
  11827. });
  11828.  
  11829. Polymer.__fixedQuerySelector__ = 1;
  11830. }
  11831.  
  11832. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  11833.  
  11834. domXP.querySelectorAll15 = domXP.querySelectorAll;
  11835.  
  11836. const querySelectorAllFn = function (query) {
  11837.  
  11838. try {
  11839.  
  11840. const p = this.node;
  11841.  
  11842. if (p instanceof Document && p.isConnected === true) {
  11843. return pd6b.value.call(p, query);
  11844. }
  11845.  
  11846. } catch (e) {
  11847.  
  11848. }
  11849. return this.querySelectorAll15(query);
  11850. }
  11851.  
  11852. Object.defineProperty(domXP, 'querySelectorAll', {
  11853. get() {
  11854. return querySelectorAllFn;
  11855. },
  11856. set(nv) {
  11857. if (nv === querySelectorAllFn) return true;
  11858. this.querySelectorAll15 = nv;
  11859. return true;
  11860. },
  11861.  
  11862. enumerable: false,
  11863. configurable: true
  11864. });
  11865.  
  11866. Polymer.__fixedQuerySelectorAll__ = 1;
  11867. }
  11868. }
  11869.  
  11870.  
  11871. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  11872.  
  11873. Polymer.Base.__connInit__ = function () {
  11874. setupYtComponent(this);
  11875. }
  11876.  
  11877.  
  11878. /** @type {Function} */
  11879. const connectedCallbackK = function (...args) {
  11880. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  11881. const r = this[qm53](...args);
  11882. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  11883. this.mh35 = 1;
  11884. return r;
  11885. };
  11886.  
  11887. connectedCallbackK.m353 = 1;
  11888.  
  11889.  
  11890. const qt53 = Polymer.Base.connectedCallback;
  11891. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  11892.  
  11893. Polymer.Base.connectedCallback = connectedCallbackK;
  11894.  
  11895.  
  11896. /** @type {Function} */
  11897. const createdK = function (...args) {
  11898. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  11899. const r = this[qn53](...args);
  11900. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  11901. this.mh36 = 1;
  11902. return r;
  11903. };
  11904.  
  11905.  
  11906. createdK.m353 = 1;
  11907. Polymer.Base[qn53] = Polymer.Base.created;
  11908. Polymer.Base.created = createdK;
  11909.  
  11910.  
  11911.  
  11912.  
  11913.  
  11914.  
  11915.  
  11916.  
  11917.  
  11918.  
  11919.  
  11920. }
  11921.  
  11922. })();
  11923.  
  11924.  
  11925. /*
  11926.  
  11927. e.nativeAppendChild = d.prototype.appendChild,
  11928. d.prototype.appendChild = function(h) {
  11929. return function(l) {
  11930. if (l instanceof DocumentFragment) {
  11931. var m = Array.from(l.children);
  11932. l = h.nativeAppendChild.call(this, l);
  11933. if (this.isConnected) {
  11934. m = g(m);
  11935. for (var p = m.next(); !p.done; p = m.next())
  11936. YD(p.value)
  11937. }
  11938. return l
  11939. }
  11940. m = l instanceof Element && l.isConnected;
  11941. p = h.nativeAppendChild.call(this, l);
  11942. m && ZD(l);
  11943. this.isConnected && YD(l);
  11944. return p
  11945. }
  11946. }(e),
  11947.  
  11948. */
  11949.  
  11950. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  11951.  
  11952. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  11953. if (f) Node.prototype.appendChild = function (a) {
  11954. if (this instanceof Element) { // exclude DocumentFragment
  11955. try {
  11956. let checkFragmentA = (a instanceof DocumentFragment);
  11957. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  11958. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  11959. for (const node of headLinkCollection) {
  11960. if (node.rel === 'preload' && node.as === 'fetch') {
  11961. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  11962. }
  11963. }
  11964. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  11965. checkFragmentA = false;
  11966. }
  11967. if (checkFragmentA && a.firstElementChild === null) {
  11968. // no element in fragmentA
  11969. let doNormal = false;
  11970. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  11971. if (child.nodeType === 3) { doNormal = true; break; }
  11972. }
  11973. if (!doNormal) return a;
  11974. }
  11975. } catch (e) {
  11976. console.log(e);
  11977. }
  11978. }
  11979. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  11980. }
  11981.  
  11982. })();
  11983.  
  11984. if (FIX_Shady) {
  11985.  
  11986. observablePromise(() => {
  11987. const { ShadyDOM, ShadyCSS } = window;
  11988. if (ShadyDOM) {
  11989. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  11990. ShadyDOM.noPatch = true; // 1 of 10
  11991. ShadyDOM.patchOnDemand = false; // 1 of 10
  11992. ShadyDOM.preferPerformance = true; // 1 of 10
  11993. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  11994. }
  11995. if (ShadyCSS) {
  11996. ShadyCSS.nativeCss = true; // 1 of 10
  11997. ShadyCSS.nativeShadow = true; // 6 of 10
  11998. ShadyCSS.cssBuild = undefined; // 1 of 10
  11999. ShadyCSS.disableRuntime = true; // 1 of 10
  12000. }
  12001. if (ShadyDOM && ShadyCSS) return 1;
  12002. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  12003.  
  12004. }
  12005.  
  12006.  
  12007. // let schedulerInstancePropOfTimerType = '';
  12008. // let schedulerInstancePropOfTimerId = '';
  12009. (FIX_schedulerInstanceInstance & 2) && (async () => {
  12010.  
  12011. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  12012.  
  12013. if (!schedulerInstanceInstance_) return;
  12014.  
  12015. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  12016. if (checkOK) {
  12017.  
  12018. let resolveRendering = null;
  12019.  
  12020. let cmPr = new PromiseExternal();
  12021. const cm = document.createComment('0');
  12022. const cmObs = new MutationObserver(() => {
  12023. if (resolveRendering) {
  12024. resolveRendering();
  12025. resolveRendering = null;
  12026. }
  12027. cmPr.resolve();
  12028. cmPr = new PromiseExternal();
  12029. });
  12030. cmObs.observe(cm, {characterData: true})
  12031.  
  12032. let web_emulated_idle_callback_delay_val = null;
  12033.  
  12034. const getRenderIdleCallbackMs = () => {
  12035. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  12036. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  12037. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  12038. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  12039. return web_emulated_idle_callback_delay_val;
  12040. }
  12041. let isDelayRenderFn_firstCheck = true;
  12042. let isDelayRenderFn_key = null;
  12043. const isDelayRenderFn = (f) => {
  12044. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  12045. isDelayRenderFn_firstCheck = false;
  12046. if (typeof ytglobal === 'undefined') return false;
  12047. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  12048. if (!globalInstance) return false;
  12049. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  12050. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  12051. isDelayRenderFn_key = entry[0]
  12052. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  12053. return true;
  12054. }
  12055. }
  12056. return false;
  12057. }
  12058.  
  12059. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  12060.  
  12061. let requestingFn = null;
  12062. let requestingArgs = null;
  12063.  
  12064. const f = function () {
  12065. requestingFn = this.fn;
  12066. requestingArgs = [...arguments];
  12067. return 12373;
  12068. };
  12069.  
  12070. const fakeFns = [
  12071. f.bind({ fn: requestAnimationFrame }),
  12072. f.bind({ fn: setInterval }),
  12073. f.bind({ fn: setTimeout }),
  12074. f.bind({ fn: requestIdleCallback })
  12075. ];
  12076.  
  12077. let mzt = 0;
  12078.  
  12079. let _fnSelectorProp = null;
  12080. const mkFns = new Array(4);
  12081.  
  12082. /*
  12083. case 1:
  12084. var a = this.K;
  12085. this.g = this.I ? window.requestIdleCallback(a, {
  12086. timeout: 3E3
  12087. }) : window.setTimeout(a, ma);
  12088. break;
  12089. case 2:
  12090. this.g = window.setTimeout(this.M, this.N);
  12091. break;
  12092. case 3:
  12093. this.g = window.requestAnimationFrame(this.L);
  12094. break;
  12095. case 4:
  12096. this.g = window.setTimeout(this.J, 0)
  12097. }
  12098.  
  12099. */
  12100. const startFnHandler = {
  12101. get(target, prop, receiver) {
  12102. if (prop === '$$12377$$') return true;
  12103. if (prop === '$$12378$$') return target;
  12104.  
  12105. // console.log('get',prop)
  12106. return target[prop]
  12107. },
  12108. set(target, prop, value, receiver) {
  12109. // console.log('set', prop, value)
  12110.  
  12111.  
  12112. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  12113. if (value === 12373 && _fnSelectorProp) {
  12114.  
  12115. const schedulerTypeSelection = target[_fnSelectorProp];
  12116. const timerIdProp = prop;
  12117.  
  12118. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  12119. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  12120. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  12121. // schedulerInstancePropOfTimerId = timerIdProp || '';
  12122. // }
  12123.  
  12124. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  12125. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  12126. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  12127. // rare
  12128. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  12129. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  12130. // often
  12131. if ((FIX_schedulerInstanceInstance & 4)) {
  12132. const f = requestingArgs[0];
  12133. const tir = ++mzt;
  12134. nextBrowserTick_(() => {
  12135. if (target[timerIdProp] === -tir) f();
  12136. });
  12137. target[_fnSelectorProp] = 940;
  12138. target[timerIdProp] = -tir;
  12139. } else {
  12140. const f = requestingArgs[0];
  12141. const tir = ++mzt;
  12142. Promise.resolve().then(() => {
  12143. if (target[timerIdProp] === -tir) f();
  12144. });
  12145. target[_fnSelectorProp] = 930;
  12146. target[timerIdProp] = -tir;
  12147. }
  12148. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  12149. // often
  12150. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  12151. cm.data = (cm.data & 7) + 1;
  12152. let renderFn = requestingArgs[0];
  12153. const resolveRendering_ = () => {
  12154. const renderFn_ = renderFn;
  12155. if (renderFn_) {
  12156. renderFn = null;
  12157. renderFn_();
  12158. }
  12159. };
  12160. resolveRendering = resolveRendering_;
  12161. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  12162. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  12163.  
  12164. // cm.data = (cm.data & 7) + 1;
  12165. // target[timerIdProp] = Math.random();
  12166.  
  12167. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  12168.  
  12169. cm.data = (cm.data & 7) + 1;
  12170.  
  12171. let renderFn = requestingArgs[0];
  12172. const resolveRendering_ = () => {
  12173. const renderFn_ = renderFn;
  12174. if (renderFn_) {
  12175. renderFn = null;
  12176. renderFn_();
  12177. }
  12178. };
  12179. resolveRendering = resolveRendering_;
  12180.  
  12181. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  12182.  
  12183.  
  12184. } else {
  12185. if (requestingFn === requestIdleCallback) {
  12186. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  12187. } else {
  12188. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  12189. }
  12190. }
  12191. } else {
  12192. target[_fnSelectorProp] = 0;
  12193. target[timerIdProp] = 0;
  12194. }
  12195. } else {
  12196. target[prop] = value;
  12197. }
  12198. return true;
  12199. }
  12200. };
  12201.  
  12202. let startBusy = false;
  12203. schedulerInstanceInstance_.start = function () {
  12204. if (startBusy) return;
  12205. startBusy = true;
  12206. try {
  12207. mkFns[0] = window.requestAnimationFrame;
  12208. mkFns[1] = window.setInterval;
  12209. mkFns[2] = window.setTimeout;
  12210. mkFns[3] = window.requestIdleCallback;
  12211. const tThis = this['$$12378$$'] || this;
  12212. window.requestAnimationFrame = fakeFns[0]
  12213. window.setInterval = fakeFns[1]
  12214. window.setTimeout = fakeFns[2]
  12215. window.requestIdleCallback = fakeFns[3]
  12216. _fnSelectorProp = null;
  12217. tThis.start993.call(new Proxy(tThis, startFnHandler));
  12218. _fnSelectorProp = null;
  12219. window.requestAnimationFrame = mkFns[0];
  12220. window.setInterval = mkFns[1];
  12221. window.setTimeout = mkFns[2];
  12222. window.requestIdleCallback = mkFns[3];
  12223. } catch (e) {
  12224. console.warn(e);
  12225. }
  12226. startBusy = false;
  12227. }
  12228.  
  12229. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  12230.  
  12231. }
  12232. })();
  12233.  
  12234. FIX_yt_player && !isChatRoomURL && (async () => {
  12235.  
  12236. const fOption = 1 | 2 | 4;
  12237.  
  12238. const _yt_player = await _yt_player_observable.obtain();
  12239.  
  12240. if (!_yt_player || typeof _yt_player !== 'object') return;
  12241.  
  12242. const g = _yt_player;
  12243. let k;
  12244.  
  12245. if (fOption & 1) {
  12246.  
  12247. // rAf scheduling
  12248.  
  12249. const keyZqOu = getZqOu(_yt_player);
  12250. if (!keyZqOu) {
  12251. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  12252. return;
  12253. }
  12254. k = keyZqOu
  12255.  
  12256. const gk = g[k];
  12257. if (typeof gk !== 'function') {
  12258. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  12259. return;
  12260. }
  12261. const gkp = gk.prototype;
  12262.  
  12263. const dummyObject = new gk;
  12264. const nilFunc = () => { };
  12265.  
  12266. const nilObj = {};
  12267.  
  12268. // console.log(1111111111)
  12269.  
  12270. let keyBoolD = '';
  12271. let keyWindow = '';
  12272. let keyFuncC = '';
  12273. let keyCidj = '';
  12274.  
  12275. for (const [t, y] of Object.entries(dummyObject)) {
  12276. if (y instanceof Window) keyWindow = t;
  12277. }
  12278.  
  12279. const dummyObjectProxyHandler = {
  12280. get(target, prop) {
  12281. let v = target[prop]
  12282. if (v instanceof Window && !keyWindow) {
  12283. keyWindow = t;
  12284. }
  12285. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  12286. if (prop === keyWindow) y = {
  12287. requestAnimationFrame(f) {
  12288. return 3;
  12289. },
  12290. cancelAnimationFrame() {
  12291.  
  12292. }
  12293. }
  12294. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  12295. keyFuncC = prop;
  12296. }
  12297. // console.log('[get]', prop, typeof target[prop])
  12298.  
  12299.  
  12300. return y;
  12301. },
  12302. set(target, prop, value) {
  12303.  
  12304. if (typeof value === 'boolean' && !keyBoolD) {
  12305. keyBoolD = prop;
  12306. }
  12307. if (typeof value === 'number' && !keyCidj && value >= 2) {
  12308. keyCidj = prop;
  12309. }
  12310.  
  12311. // console.log('[set]', prop, value)
  12312. target[prop] = value;
  12313.  
  12314. return true;
  12315. }
  12316. };
  12317.  
  12318. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  12319.  
  12320. // console.log('gkp.start',gkp.start);
  12321. // console.log('gkp.stop',gkp.stop);
  12322. gkp._activation = false;
  12323.  
  12324. gkp.start = function () {
  12325. // p59 || console.log(12100)
  12326. if (!this._activation) {
  12327. this._activation = true;
  12328. foregroundPromiseFn().then(() => {
  12329. this._activation = false;
  12330. if (this[keyCidj]) {
  12331. Promise.resolve().then(this[keyFuncC]);
  12332. }
  12333. });
  12334. }
  12335. this[keyCidj] = 1;
  12336. this[keyBoolD] = true;
  12337. };
  12338.  
  12339. gkp.stop = function () {
  12340. this[keyCidj] = null;
  12341. };
  12342.  
  12343.  
  12344. /*
  12345. g[k].start = function() {
  12346. this.stop();
  12347. this.D = true;
  12348. var a = requestAnimationFrame
  12349. , b = cancelAnimationFrame;
  12350. this.j = a.call(this.B, this.C)
  12351. }
  12352. ;
  12353. g[k].stop = function() {
  12354. if (this.isActive()) {
  12355. var a = requestAnimationFrame
  12356. , b = cancelAnimationFrame;
  12357. b.call(this.B, this.j)
  12358. }
  12359. this.j = null
  12360. }
  12361. */
  12362. }
  12363.  
  12364. if (fOption & 2) {
  12365. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  12366.  
  12367. if (keyzo) {
  12368.  
  12369. k = keyzo;
  12370.  
  12371. const attrUpdateFn = g[k];
  12372. // console.log(5992, attrUpdateFn)
  12373. g['$$original$$' + k] = attrUpdateFn;
  12374. const zoTransform = async (a, c) => {
  12375.  
  12376. let transformType = '';
  12377. let transformValue = 0;
  12378. let transformUnit = '';
  12379. let transformTypeI = 0;
  12380.  
  12381. const aStyle = a.style;
  12382.  
  12383. let cType = 0;
  12384.  
  12385. const cl = c.length;
  12386.  
  12387. if (cl >= 8) {
  12388. // scale(1)
  12389. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  12390. cType = 1;
  12391. let t = c.charCodeAt(5);
  12392. if (t === 88 || t === 120) cType = 1 | 4;
  12393. if (t === 89 || t === 121) cType = 1 | 8;
  12394. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  12395. cType = 2;
  12396. let t = c.charCodeAt(9);
  12397. if (t === 88 || t === 120) cType = 2 | 4;
  12398. if (t === 89 || t === 121) cType = 2 | 8;
  12399. }
  12400. let w = 0;
  12401. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  12402. let p = c.substring(7, cl - 1);
  12403. let q = p.length >= 1 ? parseFloat(p) : NaN;
  12404. if (typeof q === 'number' && !isNaNx(q)) {
  12405. transformType = w === 1 ? 'scaleX' : 'scaleY';
  12406. transformValue = q;
  12407. transformUnit = '';
  12408. transformTypeI = 1;
  12409. } else {
  12410. cType = 256;
  12411. }
  12412. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  12413. if (c.endsWith('px)')) {
  12414. let p = c.substring(11, cl - 3);
  12415. let q = p.length >= 1 ? parseFloat(p) : NaN;
  12416. if (typeof q === 'number' && !isNaNx(q)) {
  12417. transformType = w === 1 ? 'translateX' : 'translateY';
  12418. transformValue = q;
  12419. transformUnit = 'px';
  12420. transformTypeI = 2;
  12421. } else if (p === 'NaN') {
  12422. return;
  12423. }
  12424. } else {
  12425. cType = 256;
  12426. }
  12427. } else if (cType > 0) {
  12428. cType = 256;
  12429. }
  12430. }
  12431.  
  12432.  
  12433. if (cType === 256) {
  12434. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  12435. }
  12436.  
  12437. if (transformTypeI === 1) {
  12438. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  12439. const vz = toFixed2(q, 3);
  12440. c = `${transformType}(${vz})`;
  12441. const cv = aStyle.transform;
  12442. if (c === cv) return;
  12443. aStyle.transform = c;
  12444. } else if (transformTypeI === 2) {
  12445. const q = transformValue;
  12446. const vz = toFixed2(q, 1);
  12447. c = `${transformType}(${vz}${transformUnit})`;
  12448. const cv = aStyle.transform;
  12449. if (c === cv) return;
  12450. aStyle.transform = c;
  12451. } else { // eg empty
  12452. const cv = aStyle.transform;
  12453. if (!c && !cv) return;
  12454. else if (c === cv) return;
  12455. aStyle.transform = c;
  12456. }
  12457.  
  12458. };
  12459.  
  12460. const elmTransformTemp = new WeakMap();
  12461. const elmPropTemps = {
  12462. 'display': new WeakMap(),
  12463. 'width': new WeakMap(),
  12464. 'height': new WeakMap(),
  12465. 'outlineWidth': new WeakMap(),
  12466. 'position': new WeakMap(),
  12467. 'padding': new WeakMap(),
  12468. "cssText": new WeakMap(),
  12469. "right": new WeakMap(),
  12470. "left": new WeakMap(),
  12471. "top": new WeakMap(),
  12472. "bottom": new WeakMap(),
  12473. "transitionDelay": new WeakMap(),
  12474. "marginLeft": new WeakMap(),
  12475. "marginTop": new WeakMap(),
  12476. "marginRight": new WeakMap(),
  12477. "marginBottom": new WeakMap(),
  12478. }
  12479.  
  12480. const ns5 = Symbol();
  12481. const nextModify = (a, c, m, f, immediate) => {
  12482. const a_ = a;
  12483. const m_ = m;
  12484. const noKey = !m_.has(a_);
  12485. if (immediate || noKey) {
  12486. m_.set(a_, ns5);
  12487. f(a_, c);
  12488. noKey && nextBrowserTick_(() => {
  12489. const d = m_.get(a_);
  12490. if (d === undefined) return;
  12491. m_.delete(a_);
  12492. if (d !== ns5) f(a_, d);
  12493. });
  12494. } else {
  12495. m_.set(a_, c);
  12496. }
  12497. };
  12498.  
  12499. const set66 = new Set();
  12500. const log77 = new Map();
  12501. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  12502.  
  12503. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  12504.  
  12505. // console.log(140000, a, b, c);
  12506. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  12507. const num = c;
  12508. c = `${num}`;
  12509. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  12510. }
  12511.  
  12512. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  12513.  
  12514. let elmPropTemp = null;
  12515.  
  12516. if (b === "transform") {
  12517. // div.ytp-hover-progress.ytp-hover-progress-light
  12518. // div.ytp-play-progress.ytp-swatch-background-color
  12519.  
  12520. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  12521. return;
  12522.  
  12523. } else if (elmPropTemp = elmPropTemps[b]) {
  12524.  
  12525. // if (c.length > 5 && c.includes('.')) {
  12526. // console.log(123213, c)
  12527. // }
  12528.  
  12529. const b_ = b;
  12530. nextModify(a, c, elmPropTemp, (a, c) => {
  12531. const style = a.style;
  12532. const cv = style[b_];
  12533. if (!cv && !c) return;
  12534. if (cv === c) return;
  12535. style[b_] = c;
  12536. }, immediateChange);
  12537. return;
  12538.  
  12539. } else if (b === "outline-width") {
  12540.  
  12541. const b_ = 'outlineWidth';
  12542. elmPropTemp = elmPropTemps[b_];
  12543. nextModify(a, c, elmPropTemp, (a, c) => {
  12544. const style = a.style;
  12545. const cv = style[b_];
  12546. if (!cv && !c) return;
  12547. if (cv === c) return;
  12548. style[b_] = c;
  12549. }, immediateChange);
  12550. return;
  12551.  
  12552. } else if (b === 'maxWidth' || b === 'maxHeight') {
  12553. // I think these can be directly assigned.
  12554.  
  12555. const b_ = b;
  12556. const style = a.style;
  12557. const cv = style[b_];
  12558. if (!cv && !c) return;
  12559. if (cv === c) return;
  12560. style[b_] = c;
  12561. return;
  12562.  
  12563. } else {
  12564. // if(immediate && elmPropTemps[b]){
  12565. // console.log(5191, b)
  12566. // }
  12567. // caption-window
  12568. // margin-left max-height max-width font-family fill color font-size background white-space margin
  12569. // text-align background-color
  12570. // console.log(27304, a, b, c)
  12571. if (!set66.has(b)) {
  12572. set66.add(b);
  12573. nextBrowserTick_(() => {
  12574. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  12575. console.log(27304, a, b, c)
  12576. }
  12577. })
  12578. }
  12579. }
  12580.  
  12581. attrUpdateFn.call(this, a, b, c);
  12582. return;
  12583. } else if (typeof (b || 0) === 'object') {
  12584.  
  12585. // this is to fix caption positioning
  12586. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  12587. const immediate = (a.id || 0).length > 14;
  12588. for (const [k, v] of Object.entries(b)) {
  12589. modifiedFn.call(this, a, k, v, immediate);
  12590. }
  12591.  
  12592. } else {
  12593.  
  12594. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  12595. // ytp-ad-timed-pie-countdown-inner
  12596.  
  12597. if (typeof b === 'string') {
  12598.  
  12599. let m = log77.get(b);
  12600. if (!m) {
  12601. m = [];
  12602. console.log('attrUpdateFn.debug.27304', m);
  12603. log77.set(b, m);
  12604. }
  12605. m.push([a, b, c]);
  12606.  
  12607. } else {
  12608. console.log('attrUpdateFn.debug.27306', a, b, c);
  12609. }
  12610.  
  12611. attrUpdateFn.call(this, a, b, c);
  12612. return;
  12613. }
  12614.  
  12615. // console.log(130000, a, b, c);
  12616.  
  12617. };
  12618. g[k] = modifiedFn;
  12619.  
  12620.  
  12621. /*
  12622.  
  12623. g.zo = function(a, b, c) {
  12624. if ("string" === typeof b)
  12625. (b = yo(a, b)) && (a.style[b] = c);
  12626. else
  12627. for (var d in b) {
  12628. c = a;
  12629. var e = b[d]
  12630. , f = yo(c, d);
  12631. f && (c.style[f] = e)
  12632. }
  12633. }
  12634.  
  12635.  
  12636. */
  12637.  
  12638.  
  12639. }
  12640. }
  12641.  
  12642. if (fOption & 4) {
  12643. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  12644.  
  12645. if (keyuG) {
  12646.  
  12647. k = keyuG;
  12648.  
  12649. const gk = g[k];
  12650. const gkp = gk.prototype;
  12651.  
  12652.  
  12653. /** @type { Map<string, WeakMap<any, any>> } */
  12654. const ntLogs = new Map();
  12655.  
  12656. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  12657.  
  12658. gkp.updateValue31 = gkp.updateValue;
  12659. gkp.updateValue = function (a, b) {
  12660. if (typeof a !== 'string') return this.updateValue31(a, b);
  12661.  
  12662. const element = this.element;
  12663. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  12664.  
  12665. let ntLog = ntLogs.get(a);
  12666. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  12667.  
  12668. let cache = ntLog.get(element);
  12669. if (cache && cache.value === b) {
  12670. return;
  12671. }
  12672. if (!cache) {
  12673. this.__oldValueByUpdateValue__ = null;
  12674. ntLog.set(element, cache = { value: b });
  12675. } else {
  12676. this.__oldValueByUpdateValue__ = cache.value;
  12677. cache.value = b;
  12678. }
  12679.  
  12680. return this.updateValue31(a, b);
  12681. }
  12682.  
  12683. /*
  12684. g.k.update = function(a) {
  12685. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  12686. c = c.value,
  12687. this.updateValue(c, a[c])
  12688. }
  12689. ;
  12690. g.k.updateValue = function(a, b) {
  12691. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  12692. }
  12693. */
  12694.  
  12695. }
  12696.  
  12697.  
  12698. }
  12699. }
  12700.  
  12701.  
  12702.  
  12703. })();
  12704.  
  12705.  
  12706. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  12707. // keyboard shortcut keys controller
  12708.  
  12709. const _yt_player = await _yt_player_observable.obtain();
  12710.  
  12711. if (!_yt_player || typeof _yt_player !== 'object') return;
  12712.  
  12713. keyboardController(_yt_player);
  12714.  
  12715. })();
  12716.  
  12717. FIX_yt_player && !isChatRoomURL && (async () => {
  12718. // timer scheduling
  12719.  
  12720. const _yt_player = await _yt_player_observable.obtain();
  12721.  
  12722. if (!_yt_player || typeof _yt_player !== 'object') return;
  12723.  
  12724. let keyZqQu = getZqQu(_yt_player);
  12725.  
  12726. if (!keyZqQu) return;
  12727.  
  12728. const g = _yt_player
  12729. let k = keyZqQu
  12730.  
  12731. const gk = g[k];
  12732. if (typeof gk !== 'function') return;
  12733. const gkp = gk.prototype;
  12734.  
  12735. const extractKeysZqQu = () => {
  12736.  
  12737.  
  12738. let _keyeC = '';
  12739. try {
  12740. gkp.stop.call(new Proxy({
  12741. isActive: () => { }
  12742. }, {
  12743. set(target, prop, value) {
  12744. if (value === 0) _keyeC = prop;
  12745. return true;
  12746. }
  12747. }));
  12748. } catch (e) { }
  12749. if (!_keyeC) return;
  12750. const keyeC = _keyeC;
  12751.  
  12752. let keyC = ''; // this.C = this.ST.bind(this)
  12753. let keyhj = ''; // 1000ms
  12754. try {
  12755. gkp.start.call(new Proxy({
  12756. stop: () => { },
  12757. [keyeC]: 0,
  12758. }, {
  12759. get(target, prop) {
  12760. if (prop in target) return target[prop];
  12761. if (!keyC) {
  12762. keyC = prop;
  12763. return null; // throw error
  12764. }
  12765. else if (!keyhj) {
  12766. keyhj = prop;
  12767. }
  12768.  
  12769. }
  12770. }));
  12771. } catch (e) {
  12772. if (!keyC || !keyhj) {
  12773. console.log(e)
  12774. }
  12775. }
  12776.  
  12777. if (!keyC || !keyhj) return;
  12778. let keyST = '';
  12779. let keyj = '';
  12780. let keyB = '';
  12781. let keyxa = '';
  12782.  
  12783. const possibleKs = new Set();
  12784.  
  12785. for (const [k, v] of Object.entries(gkp)) {
  12786. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  12787. continue;
  12788. }
  12789. if (typeof v === 'function') {
  12790. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  12791. if (m) {
  12792. keyST = k;
  12793. keyj = m[1];
  12794. keyB = m[2];
  12795. } else {
  12796. possibleKs.add(k);
  12797. }
  12798. }
  12799. }
  12800.  
  12801. if (!keyST || !keyj || !keyB) return;
  12802.  
  12803. for (const k of possibleKs) {
  12804. if (k === keyST || k === keyj || k === keyB) {
  12805. continue;
  12806. }
  12807. const v = gkp[k];
  12808. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  12809. keyxa = k;
  12810. }
  12811. }
  12812.  
  12813. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  12814.  
  12815. }
  12816.  
  12817. const keys = extractKeysZqQu();
  12818. if (!keys || !keys.length) return;
  12819. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  12820.  
  12821. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  12822.  
  12823. let disposeKeys = null;
  12824.  
  12825. gkp[keyxa] = function () {
  12826. // dispose
  12827. if (!disposeKeys) {
  12828. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  12829. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  12830. const t = typeof this[key];
  12831. return t === 'undefined' || t === 'object'
  12832. }
  12833. return false;
  12834. });
  12835. }
  12836. for (const key of disposeKeys) {
  12837. const v = this[key];
  12838. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  12839. }
  12840. if (this[keyeC] > 0) this.stop();
  12841. this[keyj] = null;
  12842. this[keyB] = null;
  12843. };
  12844.  
  12845. gkp.start = function (a) {
  12846. if (this[keyeC] > 0) this.stop();
  12847. const delay = void 0 !== a ? a : this[keyhj];
  12848. this[keyeC] = window.setTimeout(this[keyC], delay);
  12849. };
  12850. gkp.stop = function () {
  12851. if (this[keyeC] > 0) {
  12852. window.clearTimeout(this[keyeC]);
  12853. this[keyeC] = 0;
  12854. }
  12855. };
  12856.  
  12857. gkp.isActive = function () {
  12858. return this[keyeC] > 0;
  12859. };
  12860.  
  12861. gkp[keyST] = function () {
  12862. this.stop(); // this[keyeC] = 0;
  12863. const fn = this[keyj];
  12864. const obj = this[keyB];
  12865. let skip = false;
  12866. if (!fn) skip = true;
  12867. else if (IGNORE_bufferhealth_CHECK && obj) {
  12868. let m;
  12869. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  12870. if (m.has("bufferhealth")) skip = true;
  12871. }
  12872. }
  12873. if (!skip) {
  12874. fn.call(obj);
  12875. }
  12876. };
  12877.  
  12878.  
  12879.  
  12880.  
  12881. /*
  12882.  
  12883. g.k.eC = 0;
  12884. g.k.xa = function() {
  12885. g.Qu.Vf.xa.call(this);
  12886. this.stop();
  12887. delete this.j;
  12888. delete this.B
  12889. }
  12890. ;
  12891. g.k.start = function(a) {
  12892. this.stop();
  12893. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  12894. }
  12895. ;
  12896. g.k.stop = function() {
  12897. this.isActive() && g.Sa.clearTimeout(this.eC);
  12898. this.eC = 0
  12899. }
  12900. ;
  12901. g.k.isActive = function() {
  12902. return 0 != this.eC
  12903. }
  12904. ;
  12905. g.k.ST = function() {
  12906. this.eC = 0;
  12907. this.j && this.j.call(this.B)
  12908. }
  12909. ;
  12910. */
  12911.  
  12912.  
  12913.  
  12914.  
  12915. })();
  12916.  
  12917. FIX_Animation_n_timeline && (async () => {
  12918.  
  12919. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  12920.  
  12921. if (!timeline || !Animation) return;
  12922.  
  12923. const animationsFix = (timeline) => {
  12924. const animations = (timeline || 0)._animations || 0;
  12925. const c = animations[0];
  12926. if (c) {
  12927. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  12928. animations.shift(); // keep animating but no looping
  12929. // c.effect.remove();
  12930. }
  12931. }
  12932. }
  12933.  
  12934. const aniProto = Animation.prototype;
  12935. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  12936.  
  12937. const getXroto = (x) => {
  12938. try {
  12939. return x.__proto__;
  12940. } catch (e) { }
  12941. return null;
  12942. }
  12943. const timProto = getXroto(timeline);
  12944. if (!timProto) return;
  12945. if (
  12946. (
  12947. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  12948. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  12949. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  12950. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  12951. )
  12952.  
  12953. ) {
  12954.  
  12955. timProto.nofCQ = 1;
  12956. aniProto.nofYH = 1;
  12957.  
  12958. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  12959.  
  12960.  
  12961. /*
  12962. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  12963. return c._updatePromises();
  12964. });
  12965. */
  12966.  
  12967. const p = Array.prototype.filter;
  12968.  
  12969. let res = null;
  12970. Array.prototype.filter = function () {
  12971.  
  12972. res = this;
  12973. return this;
  12974.  
  12975. };
  12976.  
  12977. _updateAnimationsPromises.call({});
  12978.  
  12979. Array.prototype.filter = p;
  12980.  
  12981. if (res && typeof res.length === 'number') {
  12982. /** @type {any[]} */
  12983. const _res = res;
  12984. return _res;
  12985. }
  12986.  
  12987.  
  12988. return null;
  12989.  
  12990.  
  12991.  
  12992.  
  12993. })(timProto._updateAnimationsPromises);
  12994.  
  12995. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  12996.  
  12997. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  12998.  
  12999. aniProto._updatePromises31 = aniProto._updatePromises;
  13000.  
  13001. /*
  13002. aniProto._updatePromises = function(){
  13003. console.log('eff',this._oldPlayState, this.playState)
  13004. return this._updatePromises31.apply(this, arguments)
  13005. }
  13006. */
  13007.  
  13008. aniProto._updatePromises = function () {
  13009. var oldPlayState = this._oldPlayState;
  13010. var newPlayState = this.playState;
  13011. // console.log('ett', oldPlayState, newPlayState)
  13012. if (newPlayState !== oldPlayState) {
  13013. this._oldPlayState = newPlayState;
  13014. if (this._readyPromise) {
  13015. if ("idle" == newPlayState) {
  13016. this._rejectReadyPromise();
  13017. this._readyPromise = void 0;
  13018. } else if ("pending" == oldPlayState) {
  13019. this._resolveReadyPromise();
  13020. } else if ("pending" == newPlayState) {
  13021. this._readyPromise = void 0;
  13022. }
  13023. }
  13024. if (this._finishedPromise) {
  13025. if ("idle" == newPlayState) {
  13026. this._rejectFinishedPromise();
  13027. this._finishedPromise = void 0;
  13028. } else if ("finished" == newPlayState) {
  13029. this._resolveFinishedPromise();
  13030. } else if ("finished" == oldPlayState) {
  13031. this._finishedPromise = void 0;
  13032. }
  13033. }
  13034. }
  13035. return this._readyPromise || this._finishedPromise;
  13036. };
  13037.  
  13038.  
  13039. let restartWebAnimationsNextTickFlag = false;
  13040.  
  13041. const looperMethodT = () => {
  13042.  
  13043. const runnerFn = (hRes) => {
  13044. var b = timeline;
  13045. b.currentTime = hRes;
  13046. b._discardAnimations();
  13047. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  13048. if (0 == b._animations.length) {
  13049. restartWebAnimationsNextTickFlag = false;
  13050. } else {
  13051. getRafPromise().then(runnerFn);
  13052. }
  13053. }
  13054.  
  13055. const restartWebAnimationsNextTick = () => {
  13056. if (!restartWebAnimationsNextTickFlag) {
  13057. restartWebAnimationsNextTickFlag = true;
  13058. getRafPromise().then(runnerFn);
  13059. }
  13060. }
  13061.  
  13062. return { restartWebAnimationsNextTick }
  13063. };
  13064.  
  13065.  
  13066. const looperMethodN = () => {
  13067.  
  13068. const acs = document.createElement('a-f');
  13069. acs.id = 'a-f';
  13070.  
  13071. if (!document.getElementById('afscript')) {
  13072. const style = document.createElement('style');
  13073. style.id = 'afscript';
  13074. style.textContent = `
  13075. @keyFrames aF1 {
  13076. 0% {
  13077. order: 0;
  13078. }
  13079. 100% {
  13080. order: 1;
  13081. }
  13082. }
  13083. #a-f[id] {
  13084. visibility: collapse !important;
  13085. position: fixed !important;
  13086. display: block !important;
  13087. top: -100px !important;
  13088. left: -100px !important;
  13089. margin:0 !important;
  13090. padding:0 !important;
  13091. outline:0 !important;
  13092. border:0 !important;
  13093. z-index:-1 !important;
  13094. width: 0px !important;
  13095. height: 0px !important;
  13096. contain: strict !important;
  13097. pointer-events: none !important;
  13098. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  13099. }
  13100. `;
  13101. (document.head || document.documentElement).appendChild(style);
  13102. }
  13103.  
  13104. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  13105.  
  13106. const _onanimationiteration = function (evt) {
  13107. const hRes = evt.timeStamp;
  13108. var b = timeline;
  13109. b.currentTime = hRes;
  13110. b._discardAnimations();
  13111. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  13112. if (0 == b._animations.length) {
  13113. restartWebAnimationsNextTickFlag = false;
  13114. acs.onanimationiteration = null;
  13115. } else {
  13116. acs.onanimationiteration = _onanimationiteration;
  13117. }
  13118.  
  13119. }
  13120.  
  13121.  
  13122.  
  13123. const restartWebAnimationsNextTick = () => {
  13124. if (!restartWebAnimationsNextTickFlag) {
  13125. restartWebAnimationsNextTickFlag = true;
  13126. acs.onanimationiteration = _onanimationiteration;
  13127.  
  13128. }
  13129. }
  13130.  
  13131. return { restartWebAnimationsNextTick }
  13132. };
  13133.  
  13134.  
  13135.  
  13136. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  13137.  
  13138.  
  13139. // console.log(571, timProto);
  13140. timProto._play = function (c) {
  13141. c = new Animation(c, this);
  13142. this._animations.push(c);
  13143. restartWebAnimationsNextTick();
  13144. c._updatePromises();
  13145. c._animation.play();
  13146. c._updatePromises();
  13147. return c
  13148. }
  13149.  
  13150. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  13151. originalAnimationsWithPromises.length = 0;
  13152. originalAnimationsWithPromises.push = null;
  13153. originalAnimationsWithPromises.splice = null;
  13154. originalAnimationsWithPromises.slice = null;
  13155. originalAnimationsWithPromises.indexOf = null;
  13156. originalAnimationsWithPromises.unshift = null;
  13157. originalAnimationsWithPromises.shift = null;
  13158. originalAnimationsWithPromises.pop = null;
  13159. originalAnimationsWithPromises.filter = null;
  13160. originalAnimationsWithPromises.forEach = null;
  13161. originalAnimationsWithPromises.map = null;
  13162.  
  13163.  
  13164. const _updateAnimationsPromises = () => {
  13165. animationsWithPromisesMap.forEach(c => {
  13166. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  13167. });
  13168. /*
  13169. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  13170. return c._updatePromises();
  13171. });
  13172. */
  13173. }
  13174.  
  13175. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  13176.  
  13177. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  13178.  
  13179. delete timProto._updateAnimationsPromises;
  13180. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  13181. get() {
  13182. if (animationsWithPromisesMap.size === 0) return nilFn;
  13183. return _updateAnimationsPromises;
  13184. },
  13185. set(nv) {
  13186. delete this._updateAnimationsPromises;
  13187. this._updateAnimationsPromises = nv;
  13188. },
  13189. enumerable: true,
  13190. configurable: true,
  13191. });
  13192.  
  13193.  
  13194. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  13195. aniProto.__finished_native_get__ = pdFinished.get;
  13196. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  13197.  
  13198.  
  13199. Object.defineProperty(aniProto, 'finished', {
  13200. get() {
  13201. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  13202. this._finishedPromise = new Promise((resolve, reject) => {
  13203. this._resolveFinishedPromise = function () {
  13204. resolve(this)
  13205. };
  13206. this._rejectFinishedPromise = function () {
  13207. reject({
  13208. type: DOMException.ABORT_ERR,
  13209. name: "AbortError"
  13210. })
  13211. };
  13212. }),
  13213. "finished" == this.playState && this._resolveFinishedPromise());
  13214. return this._finishedPromise
  13215. },
  13216. set: undefined,
  13217. enumerable: true,
  13218. configurable: true
  13219. });
  13220.  
  13221. }
  13222.  
  13223.  
  13224.  
  13225. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  13226. aniProto.__ready_native_get__ = pdReady.get;
  13227. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  13228.  
  13229. Object.defineProperty(aniProto, 'ready', {
  13230. get() {
  13231. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  13232. this._readyPromise = new Promise((resolve, reject) => {
  13233. this._resolveReadyPromise = function () {
  13234. resolve(this)
  13235. };
  13236. this._rejectReadyPromise = function () {
  13237. reject({
  13238. type: DOMException.ABORT_ERR,
  13239. name: "AbortError"
  13240. })
  13241. };
  13242. }),
  13243. "pending" !== this.playState && this._resolveReadyPromise());
  13244. return this._readyPromise
  13245. },
  13246. set: undefined,
  13247. enumerable: true,
  13248. configurable: true
  13249. });
  13250.  
  13251. }
  13252.  
  13253.  
  13254. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  13255.  
  13256. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  13257. const _rebuildUnderlyingAnimation = function () {
  13258. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  13259. this.effect && this.effect._onsample && (this.effect._onsample = null);
  13260. return this._rebuildUnderlyingAnimation21();
  13261. }
  13262. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  13263. // delete aniProto._rebuildUnderlyingAnimation;
  13264. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  13265. // get() {
  13266. // if (isNaN(this._sequenceNumber)) return nilFn;
  13267. // return this._rebuildUnderlyingAnimation21;
  13268. // },
  13269. // set(nv) {
  13270. // delete this._rebuildUnderlyingAnimation;
  13271. // this._rebuildUnderlyingAnimation = nv;
  13272. // },
  13273. // enumerable: true,
  13274. // configurable: true
  13275. // });
  13276. }
  13277.  
  13278.  
  13279. /*
  13280.  
  13281.  
  13282. function f(c) {
  13283. var b = v.timeline;
  13284. b.currentTime = c;
  13285. b._discardAnimations();
  13286. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  13287. }
  13288. var h = window.requestAnimationFrame;
  13289. window.requestAnimationFrame = function(c) {
  13290. return h(function(b) {
  13291. v.timeline._updateAnimationsPromises();
  13292. c(b);
  13293. v.timeline._updateAnimationsPromises()
  13294. })
  13295. }
  13296. ;
  13297. v.AnimationTimeline = function() {
  13298. this._animations = [];
  13299. this.currentTime = void 0
  13300. }
  13301. ;
  13302. v.AnimationTimeline.prototype = {
  13303. getAnimations: function() {
  13304. this._discardAnimations();
  13305. return this._animations.slice()
  13306. },
  13307. _updateAnimationsPromises: function() {
  13308. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  13309. return c._updatePromises()
  13310. })
  13311. },
  13312. _discardAnimations: function() {
  13313. this._updateAnimationsPromises();
  13314. this._animations = this._animations.filter(function(c) {
  13315. return "finished" != c.playState && "idle" != c.playState
  13316. })
  13317. },
  13318. _play: function(c) {
  13319. c = new v.Animation(c,this);
  13320. this._animations.push(c);
  13321. v.restartWebAnimationsNextTick();
  13322. c._updatePromises();
  13323. c._animation.play();
  13324. c._updatePromises();
  13325. return c
  13326. },
  13327. play: function(c) {
  13328. c && c.remove();
  13329. return this._play(c)
  13330. }
  13331. };
  13332. var d = !1;
  13333. v.restartWebAnimationsNextTick = function() {
  13334. d || (d = !0,
  13335. requestAnimationFrame(f))
  13336. }
  13337. ;
  13338. var a = new v.AnimationTimeline;
  13339. v.timeline = a;
  13340. try {
  13341. Object.defineProperty(window.document, "timeline", {
  13342. configurable: !0,
  13343. get: function() {
  13344. return a
  13345. }
  13346. })
  13347. } catch (c) {}
  13348. try {
  13349. window.document.timeline = a
  13350. } catch (c) {}
  13351.  
  13352. */
  13353.  
  13354.  
  13355.  
  13356. /*
  13357.  
  13358. var g = window.getComputedStyle;
  13359. Object.defineProperty(window, "getComputedStyle", {
  13360. configurable: !0,
  13361. enumerable: !0,
  13362. value: function() {
  13363. v.timeline._updateAnimationsPromises();
  13364. var e = g.apply(this, arguments);
  13365. h() && (e = g.apply(this, arguments));
  13366. v.timeline._updateAnimationsPromises();
  13367. return e
  13368. }
  13369. });
  13370.  
  13371. */
  13372.  
  13373.  
  13374.  
  13375.  
  13376. }
  13377.  
  13378.  
  13379.  
  13380.  
  13381. })();
  13382.  
  13383. !isUrlInEmbed && Promise.resolve().then(() => {
  13384.  
  13385. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  13386.  
  13387.  
  13388.  
  13389. class LimitedSizeSet extends Set {
  13390. constructor(n) {
  13391. super();
  13392. this.limit = n;
  13393. }
  13394.  
  13395. add(key) {
  13396. if (!super.has(key)) {
  13397. super.add(key);
  13398. let n = super.size - this.limit;
  13399. if (n > 0) {
  13400. const iterator = super.values();
  13401. do {
  13402. const firstKey = iterator.next().value; // Get the first (oldest) key
  13403. super.delete(firstKey); // Delete the oldest key
  13404. } while (--n > 0)
  13405. }
  13406. }
  13407. }
  13408.  
  13409. removeAdd(key) {
  13410. super.delete(key);
  13411. this.add(key);
  13412. }
  13413.  
  13414. }
  13415.  
  13416. // const wk3 = new WeakMap();
  13417.  
  13418. // let mtxVideoId = '';
  13419. // let aje3 = [];
  13420. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  13421. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  13422. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  13423. let mtzCount = 0; // the key keeps unchanged
  13424. // let mjtNextMainKey = '';
  13425. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  13426. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  13427. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  13428. // let allowNoDelay322=false;
  13429. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  13430.  
  13431. let mpKey22 = ''; // last success continutation key & url pair
  13432. let mpUrl22 = ''; // last success continutation key & url pair
  13433. let mpKey21 = ''; // latest requested continutation key & url pair
  13434. let mpUrl21 = ''; // latest requested continutation key & url pair
  13435.  
  13436.  
  13437. async function sha1Hex(message) {
  13438. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  13439. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  13440. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  13441. const hashHex = hashArray
  13442. .map((b) => b.toString(16).padStart(2, "0"))
  13443. .join(""); // convert bytes to hex string
  13444. return hashHex;
  13445. }
  13446.  
  13447. async function continuationLog(a, ...args) {
  13448. let b = a;
  13449. try {
  13450. if (advanceLogging) b = await sha1Hex(a);
  13451. let c = args.map(e => {
  13452. return e === a ? b : e
  13453. });
  13454. console.log(...c)
  13455. } catch (e) { console.warn(e) }
  13456. }
  13457.  
  13458. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  13459.  
  13460.  
  13461. if (mfvContinuationRecorded.length > 0) {
  13462. for (const [e, d] of mfvContinuationRecorded) {
  13463. mfyContinuationIgnored.removeAdd(e);
  13464. }
  13465. toClearRecorded && mfvContinuationRecorded.clear();
  13466. }
  13467.  
  13468. }
  13469.  
  13470. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  13471.  
  13472. const tmProto = taskMgr.constructor.prototype;
  13473. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  13474.  
  13475. if (!tmProto.addJob714) {
  13476.  
  13477. tmProto.addJob714 = tmProto.addJob;
  13478.  
  13479. tmProto.addJob = function (a, b, c) {
  13480. const jobId = this.addJob714(a, b, c);
  13481. if (jobId > 0) {
  13482. // const ez = wk3.get(this);
  13483. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  13484. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  13485.  
  13486. this.__lastJobId863__ = jobId;
  13487. }
  13488. return jobId;
  13489. }
  13490.  
  13491. }
  13492.  
  13493. if (!tmProto.cancelJob714) {
  13494.  
  13495. tmProto.cancelJob714 = tmProto.cancelJob;
  13496.  
  13497. tmProto.cancelJob = function (a) {
  13498. const res = this.cancelJob714(a);
  13499. // if (a > 0) {
  13500. // for (const e of aje3) {
  13501. // if (e.jobId === a) e.cancelled = true;
  13502. // }
  13503. // }
  13504. return res;
  13505. }
  13506.  
  13507. }
  13508.  
  13509. }
  13510. }
  13511.  
  13512.  
  13513. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  13514.  
  13515.  
  13516. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  13517. let dummy;
  13518. let cProto;
  13519. // let mc = 4;
  13520. // dummy = await observablePromise(() => {
  13521. // const r = document.querySelector('ytd-video-primary-info-renderer');
  13522. // if (!r) return;
  13523. // let cProto = insp(r).constructor.prototype;
  13524. // if (cProto.fetchUpdatedMetadata) return r;
  13525. // if (--mc < 0) return -1;
  13526. // return null;
  13527. // }).obtain();
  13528. dummy = document.createElement('ytd-video-primary-info-renderer');
  13529. if (!(dummy instanceof Element)) return;
  13530. // console.log(5022, dummy)
  13531. cProto = insp(dummy).constructor.prototype;
  13532.  
  13533. cProto.__getEmittorTaskMgr859__ = function () {
  13534. let taskMgr_ = null;
  13535. try {
  13536. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  13537. } catch (e) { }
  13538. return taskMgr_;
  13539. }
  13540. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  13541. // console.log(1234, cProto, cProto.is)
  13542. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  13543.  
  13544. let c_;
  13545. cProto.fetchUpdatedMetadata718 = function (a) {
  13546. // delay or immediate call the actual fetchUpdatedMetadata
  13547.  
  13548. let doImmediately = false;
  13549. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  13550.  
  13551. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  13552.  
  13553. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  13554.  
  13555. doImmediately = true;
  13556.  
  13557. }
  13558.  
  13559. if (mbCId322) {
  13560. clearTimeout(mbCId322);
  13561. mbCId322 = 0;
  13562. }
  13563.  
  13564. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  13565.  
  13566. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  13567.  
  13568. mbCId322 = setTimeout(() => {
  13569. this.fetchUpdatedMetadata717(a);
  13570. }, delay);
  13571.  
  13572. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  13573.  
  13574. }
  13575.  
  13576. cProto.fetchUpdatedMetadata = function (a) {
  13577.  
  13578. if (!pageSetupState) {
  13579. if (c_) clearTimeout(c_);
  13580. c_ = setTimeout(() => {
  13581. this.fetchUpdatedMetadata718(a);
  13582. }, 300);
  13583. return;
  13584. }
  13585.  
  13586. // pageSetupState == 0
  13587.  
  13588. try {
  13589.  
  13590. mbDelayBelowNCalls++;
  13591.  
  13592. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  13593. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  13594. }
  13595.  
  13596. // console.log('fum377', a)
  13597. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  13598. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  13599. return;
  13600. }
  13601.  
  13602. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  13603. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  13604. mjtLockPreviousKey = mjtRecordedPrevKey;
  13605. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  13606. }
  13607. // mjtNextMainKey = true;
  13608. mtzlastAllowedContinuation = '';
  13609. mtzCount = 0;
  13610. // allowNoDelay322 = false;
  13611. // fetch new metadata, cancel all previous continuations
  13612. copyPreviousContiuationToIgnored374(true);
  13613. } else if (typeof a === 'string') {
  13614. const videoPlayingId = videoPlayingY.videoId;
  13615.  
  13616. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  13617.  
  13618. let update21 = !!pageSetupVideoId;
  13619. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  13620. update21 = true;
  13621. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  13622. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  13623. return;
  13624. }
  13625. if (update21) {
  13626. mpKey21 = a;
  13627. mpUrl21 = pageSetupVideoId || videoPlayingId;
  13628. }
  13629.  
  13630. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  13631. }
  13632. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  13633. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  13634. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  13635. return this.fetchUpdatedMetadata718(a);
  13636.  
  13637. } catch (e) {
  13638. console.log('Code Error in fetchUpdatedMetadata', e);
  13639. }
  13640. return this.fetchUpdatedMetadata717(a)
  13641. }
  13642. }
  13643.  
  13644.  
  13645. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  13646. // console.log(1234, cProto, cProto.is)
  13647. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  13648. let mJob = null;
  13649.  
  13650. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  13651.  
  13652. try {
  13653.  
  13654. if (arguments.length > 0) {
  13655. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  13656. }
  13657. // mfy = mfv;
  13658.  
  13659. // mjtNextMainKey = '';
  13660. mtzlastAllowedContinuation = '';
  13661. mtzCount = 0;
  13662. if (mbCId322) {
  13663. clearTimeout(mbCId322);
  13664. mbCId322 = 0;
  13665. }
  13666. mbDelayBelowNCalls = 0;
  13667. // allowNoDelay322 = false;
  13668. copyPreviousContiuationToIgnored374(true);
  13669.  
  13670. const taskMgr = this.__getEmittorTaskMgr859__();
  13671. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  13672. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  13673. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  13674. }
  13675.  
  13676. // prevent depulicated schedule job by clearing previous JobId
  13677. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  13678.  
  13679. let res;
  13680.  
  13681. if (mJob) {
  13682. const job = mJob;
  13683. mJob = null;
  13684. console.log('cancelJob', job)
  13685. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  13686. // p.cancelJob(a,b);
  13687. }
  13688.  
  13689. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  13690.  
  13691. let pza = taskMgr.__lastJobId863__;
  13692. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  13693. let pzb = taskMgr.__lastJobId863__
  13694. if (pza !== pzb) {
  13695. mJob = pzb; // set [Interval Meta Update] jobId
  13696. }
  13697.  
  13698. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  13699. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  13700. // } else {
  13701. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  13702. // }
  13703.  
  13704. return res;
  13705.  
  13706. } else {
  13707. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  13708. }
  13709.  
  13710. } catch (e) {
  13711. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  13712. }
  13713.  
  13714.  
  13715. return this.scheduleInitialUpdatedMetadataRequest717();
  13716. }
  13717. }
  13718.  
  13719.  
  13720. });
  13721.  
  13722. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  13723. let dummy;
  13724. let cProto;
  13725. dummy = ytAppDom;
  13726. if (!(dummy instanceof Element)) return;
  13727. cProto = insp(dummy).constructor.prototype;
  13728. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  13729. // console.log(1234, cProto, cProto.is);
  13730. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  13731. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  13732. // console.log(123401, arguments);
  13733. // return this.handleServiceRequest717_(a, b, c, d);
  13734. // }
  13735.  
  13736. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  13737.  
  13738. // cProto.handleServiceRequest_ = function(a,b,c,d){
  13739. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  13740. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  13741. // console.log('mfv', c.continuation);
  13742. // mfv.add( c.continuation);
  13743. // }
  13744. // return this.handleServiceRequest717_(a,b,c,d);
  13745. // }
  13746.  
  13747. function extraArguments322(a, b, c) {
  13748. let is = (a || 0).is;
  13749. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  13750. let continuation = (c || 0).continuation;
  13751. if (typeof is !== 'string') is = null;
  13752. if (typeof videoId !== 'string') videoId = null;
  13753. if (typeof continuation !== 'string') continuation = null;
  13754. return { is, videoId, continuation };
  13755. }
  13756.  
  13757. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  13758. cProto.sendServiceAjax_ = function (a, b, c, d) {
  13759.  
  13760. // console.log(8001)
  13761. try {
  13762.  
  13763. const { is, videoId, continuation } = extraArguments322(a, b, c);
  13764.  
  13765. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  13766. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  13767. }
  13768.  
  13769. if (pageSetupVideoId && videoId && continuation) {
  13770. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  13771. mfyContinuationIgnored.removeAdd(continuation);
  13772. mfvContinuationRecorded.delete(continuation);
  13773. return;
  13774. }
  13775. }
  13776.  
  13777. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  13778. copyPreviousContiuationToIgnored374(false);
  13779. mfyContinuationIgnored.delete(continuation);
  13780. mfvContinuationRecorded.removeAdd(continuation);
  13781. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  13782. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  13783. mjtLockPreviousKey = '';
  13784. }
  13785. // if (mjtNextMainKey === continuation) {
  13786. // copyPreviousContiuationToIgnored(false);
  13787. // mfyContinuationIgnored.delete(continuation);
  13788. // mfvContinuationRecorded.add(continuation);
  13789. // }
  13790.  
  13791.  
  13792. if (mfyContinuationIgnored && continuation) {
  13793. if (mfyContinuationIgnored.has(continuation)) {
  13794. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  13795. return;
  13796. }
  13797. }
  13798.  
  13799. // console.log(59902, a?.is, b,c,d)
  13800. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  13801. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  13802. // console.log('mfv377', continuation);
  13803. mfvContinuationRecorded.add(continuation);
  13804. }
  13805.  
  13806. // if (videoId) {
  13807. // if (!pageSetupVideoId) return; // ignore page not ready
  13808. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  13809. // if (videoId !== pageSetupVideoId) {
  13810. // return;
  13811. // }
  13812. // }
  13813.  
  13814. } catch (e) {
  13815. console.log('Coding Error in sendServiceAjax_', e)
  13816. }
  13817. // console.log(8002)
  13818. // console.log(123402, arguments);
  13819. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  13820.  
  13821. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  13822. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  13823. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  13824. // get(target, prop, receiver){
  13825. // console.log('xxs99', target.videoId, mtx)
  13826. // if(prop ==='kdkw33') return 1;
  13827. // console.log(3322, prop, target)
  13828. // if(prop === 'initialDelayMs') {
  13829. // throw new Error("ABCC");
  13830. // }
  13831. // return target[prop];
  13832. // },
  13833. // set(target, prop, value, receiver){
  13834.  
  13835. // if(prop ==='kdkw33') return true;
  13836. // target[prop]=value;
  13837. // return true;
  13838. // }
  13839. // });
  13840. // }
  13841. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  13842. return this.sendServiceAjax717_(a, b, c, d);
  13843. }
  13844. }
  13845.  
  13846. function delayClearOtherKeys(lztContinuation) {
  13847. // // schedule delayed removal if mfyContinuationIgnored is not empty
  13848. // getRafPromise().then(() => {
  13849. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  13850. // // foreground page only
  13851.  
  13852. // });
  13853.  
  13854.  
  13855. if (lztContinuation !== mtzlastAllowedContinuation) return;
  13856. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  13857. if (!mfyContinuationIgnored.size) return;
  13858. if (mfyContinuationIgnored.size > 1) {
  13859. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  13860. }
  13861. mfyContinuationIgnored.forEach((value, key) => {
  13862. if (key !== lztContinuation) {
  13863. mfyContinuationIgnored.delete(key);
  13864. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  13865. }
  13866. });
  13867.  
  13868. }
  13869. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  13870. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  13871. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  13872.  
  13873. // console.log(8003)
  13874. try {
  13875.  
  13876.  
  13877. const { is, videoId, continuation } = extraArguments322(b, c, d);
  13878.  
  13879. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  13880. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  13881. }
  13882.  
  13883. if (pageSetupVideoId && videoId && continuation) {
  13884. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  13885. mfyContinuationIgnored.removeAdd(continuation);
  13886. mfvContinuationRecorded.delete(continuation);
  13887. return;
  13888. }
  13889. }
  13890.  
  13891. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  13892. copyPreviousContiuationToIgnored374(false);
  13893. mfyContinuationIgnored.delete(continuation);
  13894. mfvContinuationRecorded.removeAdd(continuation);
  13895. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  13896. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  13897. mjtLockPreviousKey = '';
  13898. }
  13899.  
  13900. // if (mjtNextMainKey === continuation) {
  13901. // copyPreviousContiuationToIgnored(false);
  13902. // mfyContinuationIgnored.delete(continuation);
  13903. // mfvContinuationRecorded.add(continuation);
  13904. // }
  13905.  
  13906. const lztContinuation = continuation;
  13907.  
  13908. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  13909. if (mfyContinuationIgnored.has(lztContinuation)) {
  13910. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  13911. return;
  13912. }
  13913. }
  13914.  
  13915. // if (videoId) {
  13916. // if (!pageSetupVideoId) return; // ignore page not ready
  13917. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  13918. // if (videoId !== pageSetupVideoId) {
  13919. // return;
  13920. // }
  13921. // }
  13922.  
  13923. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  13924. mtzlastAllowedContinuation = lztContinuation;
  13925. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  13926.  
  13927. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  13928. mjtRecordedPrevKey = lztContinuation;
  13929. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  13930. // if (mfyContinuationIgnored.size > 0) {
  13931. // delayClearOtherKeys(lztContinuation);
  13932. // }
  13933. mtzCount = 0;
  13934. // allowNoDelay322 = false;
  13935. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  13936. // repeated
  13937. if (++mtzCount > 1e9) mtzCount = 1e4;
  13938. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  13939.  
  13940. // if (mtzCount >= 3) allowNoDelay322 = true;
  13941. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  13942. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  13943. }
  13944. if (mtzCount === 5) {
  13945. mfvContinuationRecorded.clear();
  13946. mfvContinuationRecorded.add(lztContinuation);
  13947. }
  13948.  
  13949. }
  13950.  
  13951. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  13952. mpKey22 = lztContinuation;
  13953. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  13954. }
  13955.  
  13956. if (mbCId322) {
  13957. clearTimeout(mbCId322);
  13958. mbCId322 = 0;
  13959. }
  13960. } catch (e) {
  13961. console.log('Coding Error in getCancellableNetworkPromise_', e)
  13962. }
  13963.  
  13964. // console.log(8004)
  13965. // console.log(123403, arguments);
  13966. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  13967.  
  13968. // console.log(5163, a?.is,b,c,d,e);
  13969. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  13970. }
  13971. }
  13972. });
  13973.  
  13974. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  13975.  
  13976.  
  13977. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  13978.  
  13979. let dummy;
  13980. let cProto;
  13981.  
  13982. dummy = document.createElement('ytd-expander');
  13983. cProto = insp(dummy).constructor.prototype;
  13984.  
  13985. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  13986.  
  13987. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  13988. cProto.childrenChanged14 = cProto.childrenChanged;
  13989.  
  13990. cProto.initChildrenObserver = function () {
  13991. var a = this;
  13992. this.observer = new MutationObserver(function () {
  13993. a.childrenChanged()
  13994. }
  13995. );
  13996. this.observer.observe(this.content, {
  13997. subtree: !0,
  13998. childList: !0,
  13999. attributes: !0,
  14000. characterData: !0
  14001. });
  14002. this.childrenChanged()
  14003. }
  14004. ;
  14005. cProto.childrenChanged = function () {
  14006. if (this.alwaysToggleable) {
  14007. this.canToggle = this.alwaysToggleable;
  14008. } else if (!this.canToggleJobId) {
  14009. this.canToggleJobId = 1;
  14010. foregroundPromiseFn().then(() => {
  14011. this.canToggleJobId = 0;
  14012. this.calculateCanCollapse()
  14013. })
  14014. }
  14015. }
  14016.  
  14017. // console.log(cProto.initChildrenObserver)
  14018. console.debug('ytd-expander-fix-childrenChanged');
  14019.  
  14020. }
  14021.  
  14022. });
  14023.  
  14024.  
  14025. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  14026.  
  14027. let dummy;
  14028. let cProto;
  14029. dummy = document.createElement('paper-ripple');
  14030. cProto = insp(dummy).constructor.prototype;
  14031.  
  14032. if (fnIntegrity(cProto.animate, '0.74.5')) {
  14033.  
  14034.  
  14035. cProto.animate34 = cProto.animate;
  14036. cProto.animate = function () {
  14037. if (this._animating) {
  14038. var a;
  14039. const ripples = this.ripples;
  14040. for (a = 0; a < ripples.length; ++a) {
  14041. var b = ripples[a];
  14042. b.draw();
  14043. this.$.background.style.opacity = b.outerOpacity;
  14044. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  14045. }
  14046. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  14047. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  14048. foregroundPromiseFn().then(this._boundAnimate38);
  14049. } else {
  14050. this.onAnimationComplete();
  14051. }
  14052. }
  14053. }
  14054.  
  14055. console.debug('FIX_paper_ripple_animate')
  14056.  
  14057. // console.log(cProto.animate)
  14058.  
  14059. }
  14060.  
  14061. });
  14062.  
  14063. if (FIX_doIdomRender) {
  14064.  
  14065. const xsetTimeout = function (f, d) {
  14066. if (xsetTimeout.m511 === 1 && !d) {
  14067. xsetTimeout.m511 = 2;
  14068. xsetTimeout.m568 = f;
  14069. } else {
  14070. return setTimeout.apply(window, arguments)
  14071. }
  14072.  
  14073. }
  14074.  
  14075. /**
  14076. *
  14077. IGb = function(a) {
  14078. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  14079. c || (a.requestAninmationFrameResolver = new Vi,
  14080. c = a.requestAninmationFrameResolver.promise,
  14081. Da.requestAnimationFrame(function() {
  14082. var d;
  14083. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  14084. a.requestAninmationFrameResolver = null
  14085. }));
  14086. return c
  14087. }
  14088.  
  14089.  
  14090. */
  14091.  
  14092. const xrequestAnimationFrame = function (f) {
  14093. const h = `${f}`;
  14094. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  14095. let t = null;
  14096. xsetTimeout.m511 = 1;
  14097. f();
  14098. if (xsetTimeout.m511 === 2) {
  14099. t = xsetTimeout.m568;
  14100. xsetTimeout.m568 = null;
  14101. }
  14102. xsetTimeout.m511 = 0;
  14103. if (typeof t === 'function') {
  14104. foregroundPromiseFn().then(t);
  14105. }
  14106. } else if (h.includes("requestAninmationFrameResolver")) {
  14107. foregroundPromiseFn().then(f);
  14108. } else {
  14109. return requestAnimationFrame.apply(window, arguments);
  14110. }
  14111. }
  14112.  
  14113. let busy = false;
  14114. const doIdomRender = function () {
  14115.  
  14116. if (!this) return;
  14117. if (busy) {
  14118. return this.doIdomRender13(...arguments);
  14119. }
  14120. busy = true;
  14121. const { requestAnimationFrame, setTimeout } = window;
  14122. window.requestAnimationFrame = xrequestAnimationFrame;
  14123. window.setTimeout = xsetTimeout;
  14124. let r = this.doIdomRender13(...arguments);
  14125. window.requestAnimationFrame = requestAnimationFrame;
  14126. window.setTimeout = setTimeout;
  14127. busy = false;
  14128. return r;
  14129. };
  14130. 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']) {
  14131.  
  14132.  
  14133. whenCEDefined(ytTag).then(() => {
  14134.  
  14135. let dummy;
  14136. let cProto;
  14137. dummy = document.createElement(ytTag);
  14138. cProto = insp(dummy).constructor.prototype;
  14139.  
  14140. cProto.doIdomRender13 = cProto.doIdomRender;
  14141. cProto.doIdomRender = doIdomRender;
  14142.  
  14143. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  14144.  
  14145. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  14146.  
  14147.  
  14148.  
  14149. });
  14150.  
  14151. }
  14152.  
  14153. }
  14154.  
  14155.  
  14156.  
  14157.  
  14158. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  14159.  
  14160. const sMap = new Map();
  14161.  
  14162. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  14163. const ZT = function () {
  14164. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  14165. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  14166. c = b & 15,
  14167. b >>= 4,
  14168. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  14169. return a.join("")
  14170. };
  14171.  
  14172.  
  14173. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  14174.  
  14175. const popupContainer = await observablePromise(() => {
  14176. return popupContainerCollection[0];
  14177. }).obtain();
  14178.  
  14179.  
  14180. let cProto;
  14181. cProto = insp(popupContainer).constructor.prototype;
  14182.  
  14183.  
  14184. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  14185. console.log('FIX_POPUP_UNIQUE_ID NG')
  14186. return;
  14187. }
  14188. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  14189.  
  14190. cProto.handleOpenPopupAction = function (a, b) {
  14191.  
  14192. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  14193.  
  14194. a.__jOdQA__ = true;
  14195.  
  14196. try {
  14197.  
  14198. const h = this.hostElement;
  14199.  
  14200. if (h instanceof HTMLElement_) {
  14201.  
  14202. const map = h.__skme44__ = h.__skme44__ || new Map();
  14203.  
  14204. let mKey = '';
  14205. const wKey = firstObjectKey(a);
  14206. const wObj = wKey ? a[wKey] : null;
  14207. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  14208. const pKey = firstObjectKey(wObj.popup)
  14209. const pObj = pKey ? wObj.popup[pKey] : null;
  14210. let contentKey = '';
  14211. let headerKey = '';
  14212.  
  14213. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  14214. contentKey = firstObjectKey(pObj.content)
  14215. headerKey = firstObjectKey(pObj.header)
  14216. }
  14217. if (contentKey && headerKey) {
  14218.  
  14219. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  14220.  
  14221. if (mKey) {
  14222.  
  14223. if (!wObj.uniqueId) {
  14224. for (let i = 0; i < 8; i++) {
  14225. wObj.uniqueId = ZT();
  14226. if (!sMap.has(wObj.uniqueId)) break;
  14227. }
  14228. }
  14229. const oId = wObj.uniqueId
  14230.  
  14231. let nId_ = map.get(mKey);
  14232. if (!nId_) {
  14233. map.set(mKey, nId_ = oId);
  14234. }
  14235.  
  14236. wObj.uniqueId = nId_ || wObj.uniqueId;
  14237.  
  14238. const nId = wObj.uniqueId
  14239.  
  14240. sMap.set(oId, nId);
  14241. sMap.set(nId, nId);
  14242.  
  14243. wObj.uniqueId = nId;
  14244. pObj.targetId = nId;
  14245. pObj.identifier.tag = nId;
  14246.  
  14247. if (oId !== nId) {
  14248. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  14249. }
  14250.  
  14251. }
  14252.  
  14253. }
  14254. }
  14255.  
  14256. // console.log(12213, mKey, a, b, h)
  14257.  
  14258. }
  14259.  
  14260. } catch (e) {
  14261. console.warn(e)
  14262. }
  14263.  
  14264. try {
  14265.  
  14266. const results = searchNestedObject(a, (x) => {
  14267. if (typeof x === 'string' && x.length === 36) {
  14268. 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;
  14269. }
  14270. return false;
  14271. });
  14272. for (const [obj, key] of results) {
  14273. const oId = obj[key];
  14274. const nId = sMap.get(oId);
  14275. if (nId) obj[key] = nId;
  14276. }
  14277. } catch (e) {
  14278. console.warn(e)
  14279. }
  14280.  
  14281.  
  14282. }
  14283.  
  14284. return this.handleOpenPopupAction3868(...arguments)
  14285. }
  14286.  
  14287. console.log('FIX_POPUP_UNIQUE_ID OK')
  14288.  
  14289.  
  14290. });
  14291.  
  14292.  
  14293. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  14294.  
  14295. let dummy;
  14296. let cProto;
  14297. dummy = document.createElement('yt-formatted-string');
  14298. cProto = insp(dummy).constructor.prototype;
  14299.  
  14300. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  14301. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  14302. return;
  14303. }
  14304.  
  14305. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  14306. cProto.setNodeStyle_ = function (a, b) {
  14307. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  14308. return this.setNodeStyle17_(a, b);
  14309. }
  14310.  
  14311. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  14312. });
  14313.  
  14314. });
  14315.  
  14316. });
  14317.  
  14318.  
  14319.  
  14320.  
  14321. if (isMainWindow) {
  14322.  
  14323. console.groupCollapsed(
  14324. "%cYouTube JS Engine Tamer",
  14325. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  14326. );
  14327.  
  14328.  
  14329.  
  14330. console.log("Script is loaded.");
  14331. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  14332.  
  14333. console.log("This script is experimental and subject to further changes.");
  14334.  
  14335. console.log("This might boost your YouTube performance.");
  14336.  
  14337. console.log("CAUTION: This might break your YouTube.");
  14338.  
  14339.  
  14340. if (prepareLogs.length >= 1) {
  14341. console.log(" =========================================================================== ");
  14342.  
  14343. for (const msg of prepareLogs) {
  14344. console.log(msg)
  14345. }
  14346.  
  14347. console.log(" =========================================================================== ");
  14348. }
  14349.  
  14350. console.groupEnd();
  14351.  
  14352. }
  14353.  
  14354.  
  14355.  
  14356. })();