YouTube JS Engine Tamer

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

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @name:ja YouTube JS Engine Tamer
  4. // @name:zh-TW YouTube JS Engine Tamer
  5. // @name:zh-CN YouTube JS Engine Tamer
  6. // @namespace UserScripts
  7. // @version 0.41.8
  8. // @match https://www.youtube.com/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @match https://studio.youtube.com/live_chat*
  11. // @license MIT
  12. // @author CY Fung
  13. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  14. // @grant none
  15. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@c2b707e4977f77792042d4a5015fb188aae4772e/library/nextBrowserTick.min.js
  16. // @run-at document-start
  17. // @unwrap
  18. // @inject-into page
  19. // @allFrames true
  20. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  21. //
  22. // @description To enhance YouTube performance by modifying YouTube JS Engine
  23. // @description:ja YouTubeのJSエンジンを変更してパフォーマンスを向上させる
  24. // @description:zh-TW 修改 YouTube 的 JS 引擎以提升效能
  25. // @description:zh-CN 修改 YouTube 的 JS 引擎以提升性能
  26. //
  27. // ==/UserScript==
  28.  
  29. (() => {
  30.  
  31. /** @type {WeakMapConstructor} */
  32. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  33.  
  34. const HOOK_ACTIVE_MODULES = true; // added in 0.37.0
  35. const HOOK_ACTIVE_MODULES_fetchUpdatedMetadata = true; // added in 0.37.0 (make likeCount update)
  36. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  37. const FIX_schedulerInstanceInstance = 2 | 4;
  38. const FIX_yt_player = true; // DONT CHANGE
  39. const FIX_Animation_n_timeline = true;
  40. const FIX_Animation_n_timeline_cinematic = true;
  41. const FIX_ytScheduler = true;
  42. const NO_PRELOAD_GENERATE_204 = false;
  43. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  44. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  45. const CHANGE_appendChild = true; // discussions#236759
  46. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  47.  
  48. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  49.  
  50. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  51.  
  52. const FIX_ytdExpander_childrenChanged = true;
  53. const FIX_paper_ripple_animate = true;
  54. const FIX_avoid_incorrect_video_meta = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  55. const FIX_avoid_incorrect_video_meta_emitterBehavior = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  56.  
  57. const FIX_doIdomRender = true;
  58.  
  59. const FIX_Shady = true;
  60.  
  61. // [[ 2024.04.24 ]]
  62. const MODIFY_ShadyDOM_OBJ = true; // DON'T CHANGE. MUST BE TRUE
  63. // << if MODIFY_ShadyDOM_OBJ >>
  64. const WEAKREF_ShadyDOM = true;
  65. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  66. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  67. // << end >>
  68.  
  69. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  70.  
  71. const FIX_ytAction_ = true; // ytd-app
  72. const FIX_onVideoDataChange = false;
  73. // const FIX_onClick = true;
  74. const FIX_onStateChange = true;
  75. const FIX_onLoopRangeChange = true;
  76. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  77. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  78.  
  79. const FIX_stampDomArray_ = true; // v0.30.0
  80. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  81. // const stampDomArray_MemoryFix_Flag001 = false;
  82. const XFlag = true; // root issue tbc
  83. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  84. // 32 required for new stampDomArray
  85. // 128 to be tested
  86.  
  87. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  88. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  89.  
  90. const FIX_Polymer_dom = true;
  91. const FIX_Polymer_AF = true;
  92.  
  93. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  94. const DEBUG_removePrune = false; // true for DEBUG
  95.  
  96. const FIX_XHR_REQUESTING = true;
  97.  
  98. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  99.  
  100. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  101.  
  102. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  103. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  104.  
  105. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  106.  
  107. const FIX_removeChild = true;
  108. const FIX_fix_requestIdleCallback_timing = true;
  109.  
  110. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  111. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  112.  
  113. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  114.  
  115. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  116.  
  117. // ------------------------------------------------------------------
  118.  
  119. const MEMORY_RELEASE_NF00 = true;
  120. const MEMORY_RELEASE_NF00_SHOW_MESSAGE = false;
  121. const MEMORY_RELEASE_MAP_SET_REMOVE_NODE = true;
  122. const FULLY_REMOVE_ALL_EVENT_LISTENERS = true; // require MEMORY_RELEASE_NF00
  123. const FUZZY_EVENT_LISTENER_REMOVAL = true;
  124. const WEAK_CE_ROOT = true; // shadowRoot of the return value of attachShadow on the node
  125.  
  126. const FIX_TEMPLATE_BINDING = true;
  127. const FIX_TEMPLATE_BINDING_SHOW_MESSAGE = false;
  128.  
  129. const FIX_SHADY_METHODS = true;
  130.  
  131. const USE_fastDomIf = 2; // fastDomIf is seem to be experimental 0 = no change, 1 = enable, 2 = disable
  132. const ENHANCE_DOMIF_createAndInsertInstance = true; // root does not need to store in the instance
  133. const ENHANCE_DOMIF_TEARDOWN = true; // require MEMORY_RELEASE_NF00
  134.  
  135. const FIX_DOM_IF_DETACH = true;
  136. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  137. const FIX_DOM_IF_TEMPLATE = true;
  138. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  139.  
  140. const DEBUG_DBR847 = false;
  141. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  142.  
  143. const FIX_ICON_RENDER = true;
  144. const FIX_GUIDE_ICON = true;
  145. const FIX_ACTIONS_TOOLTIPS = true;
  146.  
  147. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  148.  
  149. const DISABLE_isLowLatencyLiveStream = false; // TBC
  150.  
  151. const FIX_FlexibleItemSizing = true;
  152. const FIX_ROLLING_NUMBER_UPDATE = true;
  153.  
  154.  
  155. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  156. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  157. // first tp-yt-paper-dialog: show once the page is loaded.
  158. // second tp-yt-paper-dialog: click "...more"
  159. // third tp-yt-paper-dialog: click "... and 3 more links"
  160. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  161. // currently, uniqueId is preassigned by the network resolveCommand.
  162. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  163. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  164.  
  165. // handleOpenPopupAction -> createCacheKey
  166. // handleClosePopupAction_ -> createCacheKey
  167. // handleGetPopupOpenedAction_ -> createCacheKey
  168. // getAndMaybeCreatePopup_ -> createCacheKey
  169. // closePopup -> createCacheKey
  170.  
  171. // yt-close-popup-command -> handleClosePopupCommand_
  172.  
  173. // ensurePopup_ -> getAndMaybeCreatePopup_
  174.  
  175. // yt-close-popup-action -> handleClosePopupAction_
  176. // closePopup -> handleClosePopupAction_
  177. // handleOpenPopupAction -> handleClosePopupAction_
  178. // handleClosePopupCommand_ -> handleClosePopupAction_
  179. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  180.  
  181. // yt-open-popup-action -> handleOpenPopupAction
  182.  
  183.  
  184. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  185. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  186.  
  187. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  188. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  189. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  190.  
  191.  
  192. // ----------------------------- Shortkey Keyboard Control -----------------------------
  193. // dependency: FIX_yt_player
  194.  
  195. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  196. // [0] no fix - not recommended
  197. // [1] basic fix - just fix the global focus detection variable
  198. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  199. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  200.  
  201. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  202. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  203.  
  204. const PROP_OverReInclusion_AVOID = true;
  205. const PROP_OverReInclusion_DEBUGLOG = false;
  206. const PROP_OverReInclusion_LIST = new Set([
  207. 'hostElement72',
  208. 'parentComponent72',
  209. 'localVisibilityObserver_72',
  210. 'cachedProviderNode_72',
  211. '__template72',
  212. '__templatizeOwner72',
  213. '__templateInfo72',
  214. '__dataHost72',
  215. '__CE_shadowRoot72',
  216. 'elements_72',
  217.  
  218. 'ky36',
  219. 'kz62',
  220. 'm822',
  221.  
  222.  
  223.  
  224. // To be reviewed.
  225.  
  226. // chat messages
  227. 'disabled', 'allowedProps',
  228. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  229.  
  230. 'dimension', 'loadTime', 'pendingPaint',
  231.  
  232. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  233.  
  234. 'respectLangDir', 'noEndpoints',
  235.  
  236.  
  237. 'objectURL',
  238. 'buttonOverrides', 'queuedMessages',
  239. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  240. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  241. 'hoverJobId', 'JSC$14573_touched',
  242.  
  243.  
  244. // tbc
  245. 'toggleable', 'isConnected',
  246. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  247. 'disableDeselectEvent',
  248. 'emojiSize',
  249.  
  250. 'buttonOverride',
  251. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  252.  
  253. // others
  254. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  255. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  256. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  257. // 'dimension', 'loadTime', 'pendingPaint',
  258. // 'disabled', 'allowedProps',
  259.  
  260.  
  261. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  262. // 'actionMap',
  263.  
  264. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  265.  
  266. 'clearTimeout',
  267. 'switchTemplateAtRegistration', 'hasUnmounted',
  268. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  269. 'tangoConfiguration',
  270. 'itemIdToDockDurationMap',
  271. 'actionMap',
  272.  
  273. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  274. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  275. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  276.  
  277. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  278. // 'stopKeyboardEventPropagation', 'emojiSize',
  279. // 'switchTemplateAtRegistration', 'hasUnmounted',
  280. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  281. // 'isReusable', 'tangoConfiguration',
  282. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  283. // */
  284.  
  285. ]);
  286.  
  287.  
  288. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  289.  
  290. // ----------------------------- Shortkey Keyboard Control -----------------------------
  291.  
  292. /*
  293. window.addEventListener('edm',()=>{
  294. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  295. });
  296.  
  297. window.addEventListener('edn',()=>{
  298. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  299. });
  300. window.addEventListener('edr',()=>{
  301. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  302. });
  303. */
  304.  
  305. // only for macOS with Chrome/Firefox 100+
  306. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  307.  
  308. const win = this instanceof Window ? this : window;
  309.  
  310. // Create a unique key for the script and check if it is already running
  311. const hkey_script = 'jswylcojvzts';
  312. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  313. win[hkey_script] = true;
  314.  
  315.  
  316.  
  317. const wk = Symbol();
  318.  
  319. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  320.  
  321. let BY_PASS_KEYBOARD_CONTROL = false;
  322.  
  323.  
  324. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  325. /** @type {(f: ()=>{})=>{}} */
  326. const nextBrowserTick_ = nextBrowserTick;
  327. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  328. console.log('nextBrowserTick is not found.');
  329. return;
  330. }
  331.  
  332. let p59 = 0;
  333.  
  334. const Promise = (async () => { })().constructor;
  335.  
  336. const PromiseExternal = ((resolve_, reject_) => {
  337. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  338. return class PromiseExternal extends Promise {
  339. constructor(cb = h) {
  340. super(cb);
  341. if (cb === h) {
  342. /** @type {(value: any) => void} */
  343. this.resolve = resolve_;
  344. /** @type {(reason?: any) => void} */
  345. this.reject = reject_;
  346. }
  347. }
  348. };
  349. })();
  350.  
  351. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  352. constructor(callback = undefined) {
  353.  
  354. }
  355. register(target, heldValue, unregisterToken = undefined) {
  356.  
  357. }
  358. unregister(unregisterToken) {
  359.  
  360. }
  361. }
  362.  
  363. let ttpHTML = (s) => {
  364. ttpHTML = s => s;
  365. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  366. let s = s => s;
  367. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  368. }
  369. return s;
  370. }
  371.  
  372.  
  373. /** @type { typeof HTMLElement } */
  374. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  375. const nativeAppendE = HTMLElement_.prototype.append;
  376. const nativeRemoveE = HTMLElement_.prototype.remove;
  377. const DocumentFragment_ = DocumentFragment;
  378. const nativeAppendD = DocumentFragment_.prototype.append;
  379. const Node_ = Node;
  380.  
  381. /**
  382. @param {number} x
  383. @param {number} d */
  384. const toFixed2 = (x, d) => {
  385. let t = x.toFixed(d);
  386. let y = `${+t}`;
  387. return y.length > t.length ? t : y;
  388. }
  389.  
  390.  
  391. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  392.  
  393.  
  394. const TRANSLATE_DEBUG = false;
  395.  
  396.  
  397. let xdeadc00 = null; // a deteched node with __domApi
  398. let xlivec00 = null; // a deteched node with __domApi
  399.  
  400. let removeTNodeRM = null;
  401. let removeTNodeBP = false;
  402.  
  403.  
  404. if (Node.isConnectedOverrided === undefined) {
  405. const pdConnected = Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected');
  406. if (pdConnected && pdConnected.get && pdConnected.configurable) {
  407. Node.isConnectedOverrided = null;
  408. const get_ = pdConnected.get;
  409. const get = function () {
  410. const overrided = Node.isConnectedOverrided;
  411. if (typeof overrided === 'boolean') return overrided;
  412. return get_.call(this);
  413. }
  414. Object.defineProperty(Node.prototype, 'isConnected', {
  415. ...pdConnected,
  416. get
  417. });
  418. }
  419. }
  420.  
  421. const _nmSet = new Set();
  422. _nmSet.add = _nmSet.addOriginal || _nmSet.add;
  423. const _nmMap = new Set();
  424. _nmMap.add = _nmMap.addOriginal || _nmMap.add;
  425. const _nmMapV = new Set();
  426. _nmMapV.add = _nmMapV.addOriginal || _nmMapV.add;
  427. if (MEMORY_RELEASE_MAP_SET_REMOVE_NODE && !Set.prototype.addOriginal && !Map.prototype.setOriginal) {
  428. const Node_ = Node;
  429. Set.prototype.addOriginal = Set.prototype.add;
  430. Set.prototype.add = function (n) {
  431. if (n instanceof Node_) {
  432. if (!this[wk]) this[wk] = mWeakRef(this);
  433. _nmSet.add(this[wk]);
  434. }
  435. return this.addOriginal(n);
  436. };
  437. Map.prototype.setOriginal = Map.prototype.set;
  438. Map.prototype.set = function (n, v) {
  439. if (n instanceof Node_) {
  440. if (!this[wk]) this[wk] = mWeakRef(this);
  441. _nmMap.add(this[wk]);
  442. }
  443. if (v instanceof Node_) {
  444. if (!this[wk]) this[wk] = mWeakRef(this);
  445. _nmMapV.add(this[wk]);
  446. }
  447. return this.setOriginal(n, v);
  448. };
  449. }
  450.  
  451. window.showNM00 = () => {
  452. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  453. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  454. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  455. return { nmSet, nmMap, nmMapV };
  456. };
  457.  
  458. window.testNM00 = (x) => {
  459. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  460. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  461. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  462. for (const s of nmSet) if (s.has(x)) return 1;
  463. for (const m of nmMap) if (m.has(x)) return 2;
  464. for (const m of nmMapV) {
  465. for (const [u, v] of m.entries()) {
  466. if (v === x) return 4;
  467. }
  468. }
  469. return 0;
  470. };
  471.  
  472. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  473.  
  474. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  475.  
  476. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  477.  
  478. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  479.  
  480. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  481. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  482. return;
  483. }
  484.  
  485. const mapGet = Map.prototype.get;
  486. const setHas = Set.prototype.has;
  487.  
  488. /** @type {Map | null} */
  489. let qcMap = null;
  490.  
  491. Set.prototype.has = function (a) {
  492. if (a === 'dummy-4718') return false; // false to allow re-use?
  493. return setHas.call(this, a);
  494. }
  495.  
  496. Map.prototype.get = function (a) {
  497. if (a === 'dummy-4718') qcMap = this;
  498. return mapGet.call(this, a);
  499. };
  500. let r;
  501. try {
  502. r = mainCnt.createComponent_('dummy-4718', {}, true);
  503. } catch (e) {
  504.  
  505. }
  506.  
  507. Map.prototype.get = mapGet;
  508. Set.prototype.has = setHas;
  509.  
  510. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  511.  
  512.  
  513. // clearInterval(ckId);
  514. // ckId = 0;
  515.  
  516. if (qcMap !== null && qcMap instanceof Map) {
  517.  
  518. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  519. qcMap.__qcMap8781__ = true;
  520.  
  521. const setArrayC = (c) => {
  522. if (c instanceof Array) {
  523. c.length = 0;
  524. c.push = function () { };
  525. c.pop = function () { };
  526. c.shift = function () { };
  527. c.unshift = function () { };
  528. c.splice = function () { };
  529. c.sort = function () { };
  530. c.reverse = function () { };
  531. }
  532. }
  533.  
  534. const cleaning = function (m) {
  535. m.forEach(setArrayC);
  536. m.clear();
  537. }
  538.  
  539. qcMap.set = function (b, c) {
  540. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  541.  
  542. setArrayC(c);
  543.  
  544. // console.log('qcMap.set', b, c);
  545.  
  546. if (this.size > 0) {
  547. // play safe
  548.  
  549. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  550. cleaning(this);
  551. }
  552.  
  553. }
  554. qcMap.get = function (b) {
  555. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  556.  
  557. // console.log('qcMap.get', b);
  558.  
  559. if (this.size > 0) {
  560. // play safe
  561.  
  562. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  563. cleaning(this);
  564. }
  565.  
  566. }
  567.  
  568.  
  569. if (qcMap.size > 0) {
  570.  
  571. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  572. cleaning(qcMap);
  573. }
  574.  
  575. }
  576.  
  577. }
  578.  
  579. r = null;
  580. qcMap = null;
  581.  
  582. }
  583.  
  584. const renderPathMake = (elements) => {
  585. if(!elements) return;
  586. if (!elements.length) elements = [elements];
  587. const s = new Set();
  588. s.add = s.addOriginal || s.add;
  589. for (const element of elements) {
  590. if (element && element.nodeType >= 1) {
  591. s.add(element);
  592. if (element.querySelectorAll) {
  593. for (const e of element.querySelectorAll('*')) {
  594. s.add(e);
  595. }
  596. }
  597. }
  598. }
  599. const y = [...s];
  600. s.clear();
  601.  
  602. const f = (elm) => {
  603. let x = elm.nodeName.toLowerCase();
  604. let y = elm.id;
  605. return y ? `${x}#${y}` : `${x}`;
  606. }
  607. for (const element of y) {
  608. if (element && (element.nodeType >= 1) && !element.__renderPath522__) {
  609. let t = element;
  610. let w = [f(t)];
  611. if (!element.is) {
  612. while (t = t.parentNode) {
  613. w.unshift(f(t))
  614. if (t.is) break;
  615. }
  616. }
  617. element.__renderPath522__ = w.join('/');
  618. }
  619. }
  620. }
  621.  
  622.  
  623. const dispatchYtEvent = function (a, b, c, d) {
  624. d || (d = {
  625. bubbles: !0,
  626. cancelable: !1,
  627. composed: !0
  628. });
  629. c !== null && c !== void 0 && (d.detail = c);
  630. b = new CustomEvent(b, d);
  631. a.dispatchEvent(b);
  632. return b
  633. };
  634.  
  635. if (DISABLE_isLowLatencyLiveStream) {
  636. const sm = Symbol();
  637. const f = () => {
  638. try {
  639. const videoDetails = ytInitialPlayerResponse.videoDetails;
  640. if (videoDetails && videoDetails.isLowLatencyLiveStream) {
  641. videoDetails.isLowLatencyLiveStream = false;
  642. }
  643. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW') {
  644. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  645. }
  646. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  647. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  648. }
  649. } catch (e) { }
  650. }
  651. Object.defineProperty(Object.prototype, 'isLowLatencyLiveStream', {
  652. get() {
  653. const v = this[sm];
  654. if (typeof v === 'undefined') return v;
  655. f();
  656. return v;
  657. },
  658. set(nv) {
  659. f();
  660. if (nv === true) nv = false;
  661. this[sm] = nv;
  662. },
  663. enumerable: false,
  664. configurable: true
  665. });
  666.  
  667. const sm3 = Symbol();
  668. Object.defineProperty(Object.prototype, 'latencyClass', {
  669. get() {
  670. const v = this[sm3];
  671. if (typeof v === 'undefined') return v;
  672. f();
  673. return v;
  674. },
  675. set(nv) {
  676. f();
  677. if (nv === 'ULTRALOW' || nv === 'LOW') {
  678. nv = 'NORMAL';
  679. } else if (nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW' || nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  680. nv = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  681. }
  682. this[sm3] = nv;
  683. },
  684. enumerable: false,
  685. configurable: true
  686. });
  687.  
  688. }
  689.  
  690. class PlainHTMLElement extends HTMLTitleElement {
  691.  
  692. }
  693.  
  694. const removeShady = function (shady) {
  695. if (!shady || typeof shady !== 'object') return;
  696. const props = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  697. for (const prop of props) {
  698. const node = shady[prop];
  699. if (typeof (node || 0) !== 'object') continue;
  700. if (node.nodeType >= 1 && node.isConnected === false) _removedElements.addNode(node);
  701. }
  702. }
  703.  
  704. const _removedElements = new Set();
  705. _removedElements.add = _removedElements.addOriginal || _removedElements.add;
  706. _removedElements.addNode_ = MEMORY_RELEASE_NF00 ? function (node) {
  707. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  708. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  709. if (!node[wk]) node[wk] = mWeakRef(node);
  710. return this.add(node[wk]);
  711. }
  712. } : () => { };
  713.  
  714. _removedElements.addNode = MEMORY_RELEASE_NF00 ? (node) => {
  715. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  716. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  717. const rootNode = node.getRootNode();
  718. if (rootNode && rootNode !== node) {
  719. if (rootNode.nodeType >= 1 && rootNode.nodeType !== 9) _removedElements.addNode_(rootNode);
  720. }
  721. _removedElements.addNode_(node);
  722. }
  723. } : () => { };
  724.  
  725. if (WEAK_CE_ROOT) {
  726. Object.defineProperty(Object.prototype, '__CE_shadowRoot', {
  727. get() {
  728. return kRef(this.__CE_shadowRoot366);
  729. },
  730. set(nv) {
  731. if (typeof nv !== 'object') { // null is okay
  732. if (this.__CE_shadowRoot366) this.__CE_shadowRoot366 = null;
  733. return false;
  734. }
  735. if (!nv || typeof nv !== 'object') {
  736. this.__CE_shadowRoot366 = nv;
  737. } else {
  738. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  739. this.__CE_shadowRoot366 = nv[wk];
  740. }
  741. return true;
  742. }
  743. });
  744. }
  745.  
  746. const _emptyElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  747. const _emptyTipsElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  748. const _emptyVisibilityElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  749. // const _emptyShady = new (class EmptyShady { });
  750.  
  751. const nf00 = new FinalizationRegistry_((x) => {
  752. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: node[${x}] fully removed`);
  753. });
  754. let ud00 = 0;
  755. const ng00 = new Set();
  756. nf00.registerNode = function (node) {
  757. if (node && node.nodeType >= 1) {
  758. if (!node.t792) {
  759. node.t792 = (ud00 = (ud00 & 1073741823) + 1);
  760. const x = `${node.nodeName.toLowerCase()}#${node.t792}`;
  761. this.register(node, x);
  762. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: try remove node[${x}]`);
  763. ng00.add(mWeakRef(node));
  764. }
  765. }
  766. }
  767. window.showNg00 = () => {
  768. const ng01 = new Set();
  769. ng01.add = ng01.addOriginal || ng01.add;
  770. for (const e of ng00) {
  771. const f = kRef(e);
  772. if (!f) continue;
  773. ng01.add(f);
  774. }
  775. const ng02 = [...ng01];
  776. ng01.clear();
  777. window.showNg01 = [...ng02];
  778. return window.showNg01;
  779. }
  780. window.showTemplates00 = () => {
  781. const result = {};
  782. const elements = document.querySelectorAll('*');
  783. for (const element of elements) {
  784. const tag = element.nodeName.toLocaleLowerCase();
  785. const r = result[tag] || [];
  786. const cnt = insp(element);
  787. if (cnt !== element) {
  788. if (cnt.templateInfo) {
  789. r.push(['cnt0', cnt.templateInfo, element]);
  790. }
  791. if (element._templateInfo) {
  792. r.push(['cnt1', cnt._templateInfo, element]);
  793. }
  794. if (element.__templateInfo) {
  795. r.push(['cnt2', cnt.__templateInfo, element]);
  796. }
  797. }
  798. if (element.templateInfo) {
  799. r.push(['elm0', element.templateInfo, element]);
  800. }
  801. if (element._templateInfo) {
  802. r.push(['elm1', element._templateInfo, element]);
  803. }
  804. if (element.__templateInfo) {
  805. r.push(['elm2', element.__templateInfo, element]);
  806. }
  807. if (r.length >= 1) result[tag] = r;
  808. }
  809. const strCmp = (a, b) => {
  810. if (a === b) return 0;
  811. let u = [a, b].sort();
  812. return u[0] === a ? -1 : 1;
  813. }
  814. const counting1 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[0]))].join('|')]).sort((a, b) => {
  815. return strCmp(`${a[1]}.${a[0]}`, `${b[1]}.${b[0]}`);
  816. });
  817.  
  818. const counting2 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[1]))]]);
  819.  
  820. const counting3 = Object.entries(result).map(e => {
  821. const a = [...new Set(e[1].map(t => t[1]))];
  822. const b = [...new Set(a.map(e => e.nodeList || e))];
  823.  
  824. const r = [e[0], b];
  825. return r;
  826. });
  827.  
  828. return {result, counting1, counting2, counting3};
  829. };
  830.  
  831. window.showFrag00 = function(){
  832.  
  833. const result = {};
  834. const elements = document.querySelectorAll('*');
  835. for (const element of elements) {
  836. const tag = element.nodeName.toLocaleLowerCase();
  837. const r = result[tag] || [];
  838. const cnt = insp(element);
  839. if (cnt !== element) {
  840. if (cnt.templateInfo) {
  841. r.push(['cnt0', cnt.templateInfo, element]);
  842. }
  843. if (element._templateInfo) {
  844. r.push(['cnt1', cnt._templateInfo, element]);
  845. }
  846. if (element.__templateInfo) {
  847. r.push(['cnt2', cnt.__templateInfo, element]);
  848. }
  849. }
  850. if (element.templateInfo) {
  851. r.push(['elm0', element.templateInfo, element]);
  852. }
  853. if (element._templateInfo) {
  854. r.push(['elm1', element._templateInfo, element]);
  855. }
  856. if (element.__templateInfo) {
  857. r.push(['elm2', element.__templateInfo, element]);
  858. }
  859. if (r.length >= 1) result[tag] = r;
  860. }
  861. return result;
  862.  
  863. }
  864.  
  865. if (MEMORY_RELEASE_NF00) {
  866.  
  867. const __removedElements = new Set();
  868. __removedElements.add = __removedElements.addOriginal || __removedElements.add;
  869.  
  870. setInterval(() => {
  871. const nodesSet = new Set();
  872. nodesSet.add = nodesSet.addOriginal || nodesSet.add;
  873.  
  874. for (const nodeWr of __removedElements) {
  875. __removedElements.delete(nodeWr);
  876. const node = kRef(nodeWr);
  877. if (node && node.nodeType >= 1 && node.isConnected === false) {
  878. const rootNode = node.getRootNode();
  879. if (rootNode && rootNode.nodeType >= 1 && rootNode.nodeType !== 9 && rootNode.isConnected === true) {
  880. // do nothing
  881. } else {
  882. nodesSet.add(node);
  883. if (node.querySelectorAll) {
  884. for (const p of node.querySelectorAll('*')) {
  885. nodesSet.add(p);
  886. }
  887. }
  888. }
  889. }
  890. }
  891. for (const nodeWr of _removedElements) {
  892. _removedElements.delete(nodeWr);
  893. const node = kRef(nodeWr);
  894. if (node && node.isConnected === false) {
  895. __removedElements.add(nodeWr);
  896. }
  897. }
  898.  
  899. if(nodesSet.size === 0) return;
  900.  
  901. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  902. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  903. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  904.  
  905. for (const node of nodesSet) {
  906. if (node === _emptyElement || node.__keepInstance038__ || node.t792) continue;
  907. const hasToolTips = !!((insp(node).$ || 0).tooltip);
  908.  
  909. if (node && node.__shady_getRootNode) {
  910. let k = null;
  911. try {
  912. k = node.__shady_getRootNode();
  913. } catch { }
  914. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  915. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  916. }
  917. if (node && node.getRootNode) {
  918. const k = node.getRootNode();
  919. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  920. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  921. }
  922.  
  923. if (node.__instances) {
  924. for (const k of node.__instances) {
  925. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  926. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  927. }
  928. // node.__instances.length = 0;
  929. }
  930. if (node && node.nodeType === 1) {
  931. if (typeof insp(node).__teardownInstance === 'function') {
  932. try {
  933. insp(node).__teardownInstance();
  934. } catch (e) { }
  935. } else if (typeof node.__teardownInstance === 'function') {
  936. try {
  937. node.__teardownInstance();
  938. } catch (e) { }
  939. }
  940. }
  941. if (node && node.nodeType === 1 && node.__detachAndRemoveInstance && (node.__instances || 0).length >= 1) {
  942. for (let i = node.__instances.length - 1; i >= 0; i--) {
  943. node.__detachAndRemoveInstance(i)
  944. }
  945. }
  946.  
  947. if (node && node.nodeType === 1 && node.is === void 0) {
  948. if (typeof insp(node).dispose === 'function') {
  949. insp(node).dispose();
  950. } else if (typeof node.dispose === 'function') {
  951. node.dispose();
  952. }
  953. }
  954.  
  955. if (node && node.nodeType === 1) {
  956. if (typeof insp(node).unobserve_ === 'function') {
  957. insp(node).unobserve_();
  958. } else if (typeof node.unobserve_ === 'function') {
  959. node.unobserve_();
  960. }
  961. }
  962.  
  963. if (node) {
  964. if (typeof insp(node).unobserveNodes === 'function') {
  965. insp(node).unobserveNodes();
  966. } else if (typeof node.unobserveNodes === 'function') {
  967. node.unobserveNodes();
  968. }
  969. }
  970.  
  971. // if (node && node.nodeType === 1) {
  972. // const cnt = insp(node);
  973. // const paths = cnt.__dataLinkedPaths;
  974. // if (paths && paths.length >= 1 && typeof cnt.unlinkPaths === 'function') {
  975. // for (let k in paths) {
  976. // cnt.unlinkPaths(k);
  977. // }
  978. // }
  979. // }
  980.  
  981. const visibilityMonitorKeys = insp(node).visibilityMonitorKeys || node.visibilityMonitorKeys;
  982. if (visibilityMonitorKeys) {
  983. for (const entry of visibilityMonitorKeys) {
  984. if (entry.element) { entry.element = null }
  985. }
  986. visibilityMonitorKeys.length = 0;
  987. }
  988. const __instances = node.__instances;
  989. if (__instances) {
  990. for (const k of __instances) {
  991. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  992. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  993. }
  994. __instances.length = 0;
  995. }
  996. const sp = node.__shady_parentNode;
  997. if (sp && sp.nodeType >= 1 && sp.isConnected === false) _removedElements.addNode(sp);
  998. FULLY_REMOVE_ALL_EVENT_LISTENERS && node.removeAllEventListener001();
  999. if (node && node.remove) node.remove();
  1000.  
  1001. /*
  1002. if (node._templateInfo && node._templateInfo.content) {
  1003. const templateInfoContent = node._templateInfo.content;
  1004. if (templateInfoContent.nodeType >= 1 && templateInfoContent.isConnected === false) {
  1005. _removedElements.addNode(templateInfoContent);
  1006. }
  1007. try{
  1008. node._templateInfo.content = null;
  1009. }catch(e){}
  1010. }
  1011. */
  1012. if (node.__domApi) {
  1013. node.__domApi = null;
  1014. }
  1015.  
  1016. const __shady = node.__shady;
  1017. if (__shady) {
  1018. delete node.__shady;
  1019. if (shadyKey) {
  1020. const shadyRootNode = __shady[shadyKey];
  1021. if (shadyRootNode) {
  1022. // console.log(shadyRootNode);
  1023. __shady[shadyKey] = null;
  1024. for (const key of [...Object.getOwnPropertyNames(__shady), ...Object.getOwnPropertySymbols(__shady)]) {
  1025. shadyRootNode[key] = null;
  1026. }
  1027. }
  1028. }
  1029. }
  1030.  
  1031.  
  1032. const ceRoot = node.__CE_shadowRoot;
  1033. if (ceRoot) {
  1034. node.__CE_shadowRoot = null;
  1035. if (ceRoot.nodeType >= 1 && ceRoot.isConnected === false) {
  1036. _removedElements.addNode(ceRoot);
  1037. }
  1038.  
  1039. }
  1040.  
  1041. // xTeardownTemplateInfo
  1042. const snChildNodes = node.__shady_native_childNodes;
  1043. if (snChildNodes.length > 0) {
  1044. for (const node of snChildNodes) {
  1045. if (node && node.nodeType >= 1 && node.isConnected === false) {
  1046. _removedElements.addNode(node);
  1047. }
  1048. }
  1049. snChildNodes.length = 0;
  1050. }
  1051. node.__shady_native_childNodes = null;
  1052.  
  1053.  
  1054. const __templateInfo = node.__templateInfo;
  1055. if (__templateInfo) {
  1056. node.__templateInfo = null;
  1057. // xTeardownTemplateInfo(__templateInfo);
  1058. }
  1059.  
  1060. if (hasToolTips && insp(node).$) {
  1061. insp(node).$.tooltip = _emptyTipsElement;
  1062. }
  1063.  
  1064. if (node && node.nodeType >= 1) {
  1065. const pd = Object.getOwnPropertyDescriptor(node, 'visibilityMonitorKeys');
  1066. if (pd && pd.value && pd.value.length >= 1) {
  1067. const arr = pd.value;
  1068. for (let i = 0; i < arr.length; i++) {
  1069. arr[i].element = _emptyVisibilityElement;
  1070. arr[i] = null;
  1071. }
  1072. }
  1073. }
  1074.  
  1075. if (node.__dataHost) {
  1076. try {
  1077. delete node.__dataHost
  1078. } catch (e) { }
  1079. try {
  1080. node.__dataHost = null;
  1081. } catch (e) { }
  1082. }
  1083.  
  1084. if (node.root) {
  1085. try {
  1086. delete node.root
  1087. } catch (e) { }
  1088. try {
  1089. node.root = null;
  1090. } catch (e) { }
  1091. }
  1092.  
  1093. if (node.children && node.children.splice) {
  1094. try {
  1095. delete node.children
  1096. } catch (e) { }
  1097. try {
  1098. node.children = null;
  1099. } catch (e) { }
  1100. }
  1101.  
  1102. if (node.__shady && typeof node.__shady === 'object') {
  1103. try {
  1104. node.__shady = null;
  1105. } catch (e) { }
  1106. }
  1107.  
  1108. if (node.nodeType === 1) Reflect.setPrototypeOf(node, PlainHTMLElement.prototype);
  1109.  
  1110. for (const prop of Object.getOwnPropertyNames(node)) {
  1111. if (prop === 'host' && typeof (node.host || 0) === 'object') {
  1112. if (node.nodeType === 11) {
  1113. const nodeHost = node.host;
  1114. if (nodeHost && nodeHost.nodeType >= 1) {
  1115. node.host = _emptyElement;
  1116. if (nodeHost.isConnected === false && nodeHost !== _emptyElement) {
  1117. _removedElements.addNode(nodeHost);
  1118. }
  1119. } else {
  1120. node.host = null;
  1121. }
  1122. } else {
  1123. node.host = null;
  1124. }
  1125. continue;
  1126. }
  1127. const pd = Object.getOwnPropertyDescriptor(node, prop);
  1128. if (pd.value) {
  1129. const v = pd.value;
  1130. if (typeof (v || 0) === 'object') node[prop] = null;
  1131. else if (typeof (v || 0) === 'function') delete node[prop];
  1132. }
  1133. }
  1134.  
  1135. for (const prop of Object.getOwnPropertySymbols(node)) {
  1136. const v = node[prop];
  1137. if (typeof (v || 0) === 'object' && !v.deref) node[prop] = null;
  1138. }
  1139.  
  1140. if (node.__shady_native_childNodes) {
  1141. node.__shady_native_childNodes = _emptyElement.childNodes;
  1142. }
  1143. if (node.__shady_children) {
  1144. node.__shady_children = _emptyElement.children;
  1145. }
  1146.  
  1147. for (const s of nmSet) s.delete(node);
  1148. for (const m of nmMap) m.delete(node);
  1149.  
  1150. mightTeardownShadyDomWrap(node);
  1151.  
  1152. nf00.registerNode(node);
  1153.  
  1154.  
  1155.  
  1156. // console.log(1883001, node)
  1157. // console.log(3772001, node, node.countEvent767())
  1158. }
  1159.  
  1160. nodesSet.clear();
  1161.  
  1162. }, 400);
  1163.  
  1164. }
  1165.  
  1166.  
  1167. if (FULLY_REMOVE_ALL_EVENT_LISTENERS && !EventTarget.prototype.addEventListener828 && !EventTarget.prototype.removeAllEventListener001) {
  1168. const handlerMap = new WeakMap();
  1169. EventTarget.prototype.addEventListener828 = EventTarget.prototype.addEventListener;
  1170. EventTarget.prototype.addEventListener = function (type, handler, option = void 0) {
  1171. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1172. let hds = handlerMap.get(wr);
  1173. if (!hds) handlerMap.set(wr, (hds = new Set()));
  1174. hds.add([type, handler, option]);
  1175. return this.addEventListener828(type, handler, option);
  1176. }
  1177. EventTarget.prototype.removeEventListener828 = EventTarget.prototype.removeEventListener;
  1178. EventTarget.prototype.removeEventListener = function (type, handler, option = void 0) {
  1179. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1180. let hds = handlerMap.get(wr);
  1181. if (hds) {
  1182. for (const entry of hds) {
  1183. if (entry[0] === type && entry[1] === handler) {
  1184. if (entry[2] === option) {
  1185. hds.delete(entry);
  1186. // break;
  1187. } else if (FUZZY_EVENT_LISTENER_REMOVAL) {
  1188. hds.delete(entry);
  1189. this.removeEventListener828(type, handler, entry[2]);
  1190. }
  1191. }
  1192. }
  1193. }
  1194. return this.removeEventListener828(type, handler, option);
  1195. }
  1196. EventTarget.prototype.countEvent767 = function(){
  1197. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1198. return handlerMap.get(wr);
  1199. }
  1200. EventTarget.prototype.removeAllEventListener001 = function () {
  1201. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1202. let hds = handlerMap.get(wr);
  1203. if (hds) {
  1204. handlerMap.delete(wr);
  1205. for (const entry of hds) {
  1206. const [type, handler, option] = entry;
  1207. entry.length = 0;
  1208. this.removeEventListener828(type, handler, option);
  1209. }
  1210. hds.clear();
  1211. }
  1212. }
  1213. }
  1214.  
  1215. const globalSetup = (key, setup)=>{
  1216. let symb = Symbol();
  1217. Object.defineProperty(Object.prototype, key, {
  1218. get() {
  1219. return this[symb];
  1220. },
  1221. set(nv) {
  1222. if (typeof nv !== 'function') {
  1223. this[symb] = nv;
  1224. return true;
  1225. }
  1226. if (!(symb in this)) {
  1227. setup(this);
  1228. }
  1229. this[symb] = nv;
  1230. return true;
  1231. },
  1232. configurable: true,
  1233. enumerable: false
  1234. });
  1235. }
  1236.  
  1237. const toActualNode = (e) => {
  1238. return e && e.getNode592177 ? e.getNode592177() : e;
  1239. }
  1240.  
  1241. const removeAllChildNodes = (o)=>{
  1242. if ((o instanceof Node) && o.nodeType >= 1) {
  1243. let t, q = null;
  1244. while ((t = o.firstChild) && t !== q) {
  1245. try {
  1246. t.__keepInstance038__ = false;
  1247. t.remove();
  1248. _removedElements.addNode(t);
  1249. q = t;
  1250. } catch (e) { }
  1251. }
  1252. try {
  1253. o.__keepInstance038__ = false;
  1254. o.remove();
  1255. _removedElements.addNode(o);
  1256. } catch (e) { }
  1257. }
  1258. }
  1259.  
  1260. let shadyInited = false;
  1261. let shadyKey = '';
  1262. let shadyKeyX = '';
  1263. const setupShady = () => {
  1264. shadyInited = true;
  1265. let p = document.createComment('1');
  1266. const x = document.implementation.createHTMLDocument();
  1267. const y = x.firstElementChild;
  1268. y.appendChild(p);
  1269. let key = '';
  1270. p.__shady = new Proxy({}, {
  1271. get(target, prop) {
  1272. key = prop;
  1273. throw new Error();
  1274. },
  1275. set(target, prop, val) {
  1276. throw new Error();
  1277. }
  1278. })
  1279. try {
  1280. p.__shady_getRootNode()
  1281. } catch (e) { }
  1282. let __shady = null;
  1283. try {
  1284. p.__shady = null;
  1285. p.__shady_getRootNode()
  1286. __shady = p.__shady;
  1287. } catch (e) {
  1288.  
  1289. }
  1290. y.removeChild(p);
  1291.  
  1292. if (0 && key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1293. const sProto = Reflect.getPrototypeOf(__shady);
  1294. const symb = Symbol('__shady');
  1295. const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1296. Object.defineProperty(sProto, key, {
  1297. get() {
  1298. return kRef(this[symb]);
  1299. },
  1300. set(nv) {
  1301. if (typeof (nv || 0) === 'object') {
  1302. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1303. this[symb] = nv[wk];
  1304. } else {
  1305. this[symb] = nv;
  1306. }
  1307. return true;
  1308. },
  1309. enumerable: false,
  1310. configurable: true
  1311. });
  1312. shadyKey = key;
  1313. console.log('[yt-js-engine-tamer] shadyKey', key);
  1314.  
  1315. let shadyKeyCached = new Set();
  1316. const fixLastShady = () => {
  1317. const shady = lastShady;
  1318. for (const key of Object.keys(shady)) {
  1319. if (shadyKeyCached.has(key)) continue;
  1320. shadyKeyCached.add(key);
  1321. if ((typeof shady[key] === 'object') && !(shady[key] || 0).deref) {
  1322. if (!shadyKeyX && shady[key] === shady.root) {
  1323. shadyKeyX = key;
  1324. const sProto = Reflect.getPrototypeOf(shady);
  1325. const symb = Symbol();
  1326. Object.defineProperty(sProto, shadyKeyX, {
  1327. get() {
  1328. return kRef(this[symb])
  1329. },
  1330. set(nv) {
  1331. if (typeof (nv || 0) === 'object') {
  1332. nv = kRef(nv);
  1333. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1334. this[symb] = nv[wk];
  1335. } else {
  1336. this[symb] = nv;
  1337. }
  1338. return true;
  1339. },
  1340. enumerable: false,
  1341. configurable: true,
  1342. });
  1343. delete shady[key];
  1344. shady[key] = shady.root;
  1345. };
  1346. // console.log(12883, shady[key], key);
  1347. // assignedNodes, assignedSlot, ja, K, childNodes, ... (keep strong ref)
  1348. }
  1349. }
  1350. }
  1351. let lastShady = null;
  1352.  
  1353. symbKeys.forEach(key => {
  1354. const symb = Symbol(key);
  1355.  
  1356. Object.defineProperty(sProto, key, {
  1357. get() {
  1358. if (this !== lastShady && lastShady) fixLastShady();
  1359. lastShady = this;
  1360. return kRef(this[symb]);
  1361. },
  1362. set(nv) {
  1363. if (this !== lastShady && lastShady) fixLastShady();
  1364. lastShady = this;
  1365. if (typeof (nv || 0) === 'object') {
  1366. nv = kRef(nv);
  1367. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1368. this[symb] = nv[wk];
  1369. } else {
  1370. this[symb] = nv;
  1371. }
  1372. return true;
  1373. },
  1374. enumerable: false,
  1375. configurable: true
  1376. });
  1377.  
  1378. });
  1379.  
  1380. }
  1381.  
  1382.  
  1383. }
  1384.  
  1385. const stampedNodes = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1386. stampedNodes.set = stampedNodes.setOriginal || stampedNodes.set;
  1387. const stampedFragment = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1388. stampedFragment.set = stampedFragment.setOriginal || stampedFragment.set;
  1389.  
  1390.  
  1391. class WeakNodeC extends Node {
  1392. constructor() {
  1393. }
  1394. addEventListener(type, listener, option = void 0) {
  1395. const nodeWr = stampedNodes.get(this.eid);
  1396. const node = kRef(nodeWr);
  1397. if (!node) return;
  1398. return node.addEventListener(type, listener, option);
  1399. }
  1400. removeEventListener(type, listener, option = void 0) {
  1401. const nodeWr = stampedNodes.get(this.eid);
  1402. const node = kRef(nodeWr);
  1403. if (!node) return;
  1404. return node.removeEventListener(type, listener, option);
  1405. }
  1406. getNode592177() {
  1407. const nodeWr = stampedNodes.get(this.eid);
  1408. const node = kRef(nodeWr);
  1409. return node;
  1410. }
  1411.  
  1412. set __dataHost(nv) {
  1413. const nodeWr = stampedNodes.get(this.eid);
  1414. const node = kRef(nodeWr);
  1415. if (!node) return;
  1416. node.__dataHost = nv;
  1417. return true;
  1418. }
  1419. get __dataHost() {
  1420. const nodeWr = stampedNodes.get(this.eid);
  1421. const node = kRef(nodeWr);
  1422. if (!node) return;
  1423. return node.__dataHost;
  1424. }
  1425.  
  1426. set __dataCompoundStorage(nv) {
  1427. const nodeWr = stampedNodes.get(this.eid);
  1428. const node = kRef(nodeWr);
  1429. if (!node) return;
  1430. node.__dataCompoundStorage = nv;
  1431. return true;
  1432. }
  1433. get __dataCompoundStorage() {
  1434. const nodeWr = stampedNodes.get(this.eid);
  1435. const node = kRef(nodeWr);
  1436. if (!node) return;
  1437. return node.__dataCompoundStorage;
  1438. }
  1439.  
  1440. set __shady_className(nv) {
  1441. const nodeWr = stampedNodes.get(this.eid);
  1442. const node = kRef(nodeWr);
  1443. if (!node) return;
  1444. node.__shady_className = nv;
  1445. // debugger;
  1446. return true;
  1447. }
  1448. get __shady_className() {
  1449. const nodeWr = stampedNodes.get(this.eid);
  1450. const node = kRef(nodeWr);
  1451. if (!node) return;
  1452. return node.__shady_className;
  1453. }
  1454. }
  1455.  
  1456. if (FIX_TEMPLATE_BINDING) {
  1457. const templateMap = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1458. templateMap.set = templateMap.setOriginal || templateMap.set;
  1459. // const parsedTemplate = new Map();
  1460.  
  1461.  
  1462. const it0 = Date.now() - 80000000000;
  1463. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  1464.  
  1465.  
  1466. /*
  1467.  
  1468. M.prototype._bindTemplate = function(N, R) {
  1469. var X = this.constructor._parseTemplate(N)
  1470. , A = this.__preBoundTemplateInfo == X;
  1471. if (!A)
  1472. for (var l in X.propertyEffects)
  1473. this._createPropertyAccessor(l);
  1474. R ? (X = Object.create(X),
  1475. X.wasPreBound = A,
  1476. this.__templateInfo ? (N = N._parentTemplateInfo || this.__templateInfo,
  1477. R = N.lastChild,
  1478. X.parent = N,
  1479. N.lastChild = X,
  1480. (X.previousSibling = R) ? R.nextSibling = X : N.firstChild = X) : this.__templateInfo = X) : this.__preBoundTemplateInfo = X;
  1481. return X
  1482. }
  1483. ;
  1484. */
  1485.  
  1486. /*
  1487. ** this.constructor._parseTemplate **
  1488. d._parseTemplate = function(N, R) {
  1489. if (!N._templateInfo) {
  1490. var X = N._templateInfo = {};
  1491. X.nodeInfoList = [];
  1492. X.nestedTemplate = !!R;
  1493. X.stripWhiteSpace = R && R.stripWhiteSpace || N.hasAttribute && N.hasAttribute("strip-whitespace");
  1494. this._parseTemplateContent(N, X, {
  1495. parent: null
  1496. })
  1497. }
  1498. return N._templateInfo
  1499. }
  1500.  
  1501. */
  1502.  
  1503.  
  1504. const exceptionTriggered = new Set();
  1505. const gxx = (window.gxxC572 || (window.gxxC572 = new Set()));
  1506.  
  1507. // let initied1 = false;
  1508. // let _parseTemplateByPass = false;
  1509. const setup1 = (qxx) => {
  1510. // if(initied1) return;
  1511. // initied1 = true;
  1512. const proto = qxx;
  1513. const constructor = proto.constructor;
  1514. const _bindTemplate = proto._bindTemplate;
  1515. // console.log(12883, proto, constructor)
  1516.  
  1517.  
  1518. const _parseTemplate = constructor._parseTemplate;
  1519. if (typeof _parseTemplate === 'function' && _parseTemplate.length === 2 && !constructor._parseTemplate322) {
  1520.  
  1521. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _parseTemplate', _parseTemplate);
  1522. constructor._parseTemplate322 = _parseTemplate;
  1523. const parsedResults = new WeakMap();
  1524.  
  1525. const _templateInfoPd = {
  1526. get() {
  1527. if (!this || !this[wk]) return undefined;
  1528. const r = parsedResults.get(this[wk]);
  1529. return r;
  1530. },
  1531. set(nv) {
  1532. delete this._templateInfo;
  1533. this._templateInfo = nv;
  1534. console.warn('_templateInfoPd set');
  1535. return true;
  1536. },
  1537. enumerable: true,
  1538. configurable: true
  1539. };
  1540. constructor._parseTemplate = function (N, R) {
  1541. if (!N) return _parseTemplate.call(this, N, R);
  1542. if (!N[wk]) N[wk] = mWeakRef(N);
  1543. let r = parsedResults.get(N[wk]);
  1544. if (r) return r;
  1545. r = _parseTemplate.call(this, N, R);
  1546. if (r && !parsedResults.has(N[wk])) {
  1547. parsedResults.set(N[wk], r);
  1548. r.iAm68 = '_templateInfo';
  1549. N.iHave68 = '_templateInfo';
  1550. if (N._templateInfo && N._templateInfo === r) {
  1551. delete N._templateInfo;
  1552. if (!N._templateInfo) {
  1553. Object.defineProperty(N, '_templateInfo', _templateInfoPd);
  1554. }
  1555. }
  1556. }
  1557. return r;
  1558. }
  1559. }
  1560. if (typeof _bindTemplate === 'function' && _bindTemplate.length === 2 && !proto._bindTemplate322) {
  1561.  
  1562. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _bindTemplate', _bindTemplate);
  1563. proto._bindTemplate322 = _bindTemplate;
  1564. proto._bindTemplate = function (N, R) {
  1565. // R = boolean true or undefined
  1566. // N = template elemenet
  1567. let M = N;
  1568. if (typeof (N || 0) === 'object' && N instanceof HTMLTemplateElement && (N.content || 0).nodeType === 11) {
  1569. let componentIs = '';
  1570. try {
  1571. componentIs = this ? this.is : '';
  1572. } catch (e) { }
  1573. if (typeof (componentIs || 0) === 'string') {
  1574. if (!templateMap.has(componentIs)) {
  1575. templateMap.set(componentIs, N);
  1576. // const parser = this.constructor;
  1577. // console.log(3882, parser._parseTemplate)
  1578. /*
  1579. if (parser._parseTemplate && !parser._parseTemplate477 && parser._parseTemplate.length === 2) {
  1580. parser._parseTemplate477 = parser._parseTemplate;
  1581. const _parseTemplate477 = parser._parseTemplate477;
  1582. parser._parseTemplate = function (N, R) {
  1583. if (!_parseTemplateByPass && N && N[wk]) {
  1584. const u = parsedTemplate.get(N[wk]);
  1585. if (u) {
  1586. console.log(1838, u)
  1587. return u;
  1588. }
  1589. }
  1590. return _parseTemplate477.call(this, N, R);
  1591. };
  1592. }
  1593. if (parser._parseTemplate && parser._parseTemplate477) {
  1594. if (N && !N[wk]) N[wk] = mWeakRef(N);
  1595. if (!parsedTemplate.has(N[wk])) {
  1596. _parseTemplateByPass = true;
  1597. parsedTemplate.set(N[wk], parser._parseTemplate477(N));
  1598. _parseTemplateByPass = false;
  1599. }
  1600. }
  1601. */
  1602. } else {
  1603. M = templateMap.get(componentIs);
  1604. }
  1605. }
  1606. }
  1607. let r_ = null;
  1608. // Promise.resolve(N).then((N) => {
  1609. // console.log(3488,N.templateInfo, N.templateInfo === r_);
  1610. // })
  1611. const r = _bindTemplate.call(this, M, R);
  1612. r_ = r;
  1613. return r;
  1614. }
  1615. }
  1616.  
  1617. const _runEffectsForTemplate = proto._runEffectsForTemplate;
  1618. if (typeof _runEffectsForTemplate === 'function' && _runEffectsForTemplate.length === 4 && !proto._runEffectsForTemplate322) {
  1619. proto._runEffectsForTemplate322 = _runEffectsForTemplate;
  1620.  
  1621. // note: fastDomIf does not work well with runEffects ...
  1622. // so no runEffects actaully?
  1623. const runner = (Tw, Nw, Rw, Xw, Aw) => {
  1624.  
  1625. try {
  1626.  
  1627.  
  1628. // console.log(988003)
  1629. const T = kRef(Tw); // this
  1630. const N = kRef(Nw); // __templateInfo
  1631. if (!T || !N) return;
  1632.  
  1633. // console.log(988004)
  1634. const R = kRef(Rw); // __data
  1635. const X = kRef(Xw); // temp Data ?
  1636. const A = kRef(Aw); // boolean ?
  1637. if (typeof (X || 0) === 'object') gxx.delete(X);
  1638. if (typeof (A || 0) === 'object') gxx.delete(A);
  1639.  
  1640. // console.log(988005)
  1641. const nodeList_ = N.nodeList;
  1642.  
  1643. // console.log(988006, nodeList_)
  1644. const nodeList = nodeList_ ? nodeList_.map(e => toActualNode(e)) : nodeList_;
  1645.  
  1646. // console.log(988007, nodeList)
  1647.  
  1648. const Nx = {
  1649. propertyEffects: N.propertyEffects,
  1650. nodeList: nodeList,
  1651. firstChild: kRef(N.firstChild)
  1652. };
  1653.  
  1654. // if (kRef(N.firstChild)) {
  1655. // console.log(977001, Nx)
  1656. // }
  1657.  
  1658. // console.log(988009, Nx, R, X, A)
  1659.  
  1660.  
  1661. {
  1662.  
  1663.  
  1664. const o = Nx;
  1665. const { propertyEffects, nodeList, firstChild } = o;
  1666. if (propertyEffects && nodeList && nodeList.length >= 0) {
  1667. for (const [effectKey, propertyEffectArr] of Object.entries(propertyEffects)) {
  1668. for (let i = propertyEffectArr.length - 1; i >= 0; i--) {
  1669. const propertyEffect = propertyEffectArr[i];
  1670. const info = (propertyEffect || 0).info;
  1671. if (info && typeof info.index === 'number' && !nodeList[info.index]) {
  1672. propertyEffectArr.splice(i, 1);
  1673. }
  1674. }
  1675. }
  1676. }
  1677.  
  1678. }
  1679.  
  1680.  
  1681. // console.log({T, Nx, R, X , A })
  1682.  
  1683. // console.log(1737001, T)
  1684. // console.log(1737002, Nx)
  1685.  
  1686. // console.log(1737003, R)
  1687. // console.log(1737004, X)
  1688. // console.log(1737005, A)
  1689.  
  1690. const hostElement = T.hostElement;
  1691. const pChildren = (hostElement instanceof Node && hostElement.isConnected === true) ? [...hostElement.childNodes] : null;
  1692. renderPathMake(pChildren);
  1693.  
  1694. try {
  1695. _runEffectsForTemplate.call(T, Nx, R, X, A);
  1696.  
  1697. } catch (err) {
  1698. // debugger;
  1699. const stack = err.stack;
  1700. if (!exceptionTriggered.has(stack)) {
  1701. exceptionTriggered.add(stack);
  1702. console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`+"\n\n", err);
  1703. }
  1704. }
  1705.  
  1706. (pChildren || 0).length >= 1 && Promise.resolve(pChildren).then((pChildren) => {
  1707. for (const node of pChildren) {
  1708. if (node.parentNode !== hostElement && node.__weakNodeCId57__) {
  1709. _removedElements.addNode(node); // rn54001b
  1710. }
  1711. // if (node.isConnected === false) {
  1712. // let tNode = node;
  1713. // let pNode;
  1714. // while ((pNode = tNode.parentNode) && pNode.nodeType >= 1) {
  1715. // tNode = pNode;
  1716. // }
  1717. // // _removedElements.addNode(tNode); // rn54001
  1718. // }
  1719. }
  1720. pChildren.length = 0;
  1721. pChildren = null;
  1722. });
  1723.  
  1724.  
  1725. } catch (err) {
  1726. // debugger;
  1727. // const stack = err.stack;
  1728. // if (!exceptionTriggered.has(stack)) {
  1729. // exceptionTriggered.add(stack);
  1730. // console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`, err);
  1731. console.error(err);
  1732. // }
  1733. }
  1734.  
  1735. };
  1736.  
  1737.  
  1738. proto._runEffectsForTemplate = function (N, R, X, A) {
  1739.  
  1740. // console.log(988001)
  1741. /*
  1742. N {wasPreBound: true, nodeList: Array(23)}
  1743.  
  1744. R {showInput: false, narrow: false, menuStrings: {…}, pageDarkTheme: true, theater: false, …}
  1745. X {showInput: undefined, narrow: undefined, menuStrings: undefined, pageDarkTheme: undefined, theater: undefined, …}
  1746. A false
  1747. */
  1748.  
  1749. const Nw = (!N || typeof N !== 'object') ? N : (N[wk] || (N[wk] = mWeakRef(N))); // __templateInfo
  1750. const Xw = (!X || typeof X !== 'object') ? X : (X[wk] || (X[wk] = mWeakRef(X)));
  1751.  
  1752. const Rw = (!R || typeof R !== 'object') ? R : (R[wk] || (R[wk] = mWeakRef(R))); // __data
  1753. const Aw = (!A || typeof A !== 'object') ? A : (A[wk] || (A[wk] = mWeakRef(A)));
  1754.  
  1755. if (typeof (X || 0) === 'object') gxx.add(X);
  1756. if (typeof (A || 0) === 'object') gxx.add(A);
  1757.  
  1758. const Tw = (!this || typeof this !== 'object') ? this : (this[wk] || (this[wk] = mWeakRef(this)));
  1759.  
  1760.  
  1761. if (N.runEffects) {
  1762. N.runEffects(() => {
  1763. runner(Tw, Nw, Rw, Xw, Aw);
  1764. }, R, A);
  1765. } else {
  1766. runner(Tw, Nw, Rw, Xw, Aw);
  1767. }
  1768.  
  1769. // console.log(988002)
  1770.  
  1771. // const N_ =
  1772.  
  1773. // var l = this
  1774. // , k = function (T, W) {
  1775. // XK(l, N.propertyEffects, T, X, W, N.nodeList);
  1776. // for (var w = N.firstChild; w; w = w.nextSibling)
  1777. // l._runEffectsForTemplate(w, T, X, W)
  1778. // };
  1779. // N.runEffects ? N.runEffects(k, R, A) : k(R, A)
  1780. }
  1781.  
  1782. }
  1783.  
  1784.  
  1785. const _registerHost = proto._registerHost;
  1786. if (_registerHost && !proto._registerHost322 && _registerHost.length === 0) {
  1787. proto._registerHost322 = _registerHost;
  1788. const map = new WeakMap();
  1789. map.set = map.setOriginal || map.set;
  1790. proto._registerHost = function () {
  1791. if (!map.has(this)) {
  1792. map.set(this, (this.__dataHost || null));
  1793. Object.defineProperty(this, '__dataHost', {
  1794. get() {
  1795. return kRef(map.get(this)) || null
  1796. },
  1797. set(nv) {
  1798. const w = kRef(nv);
  1799. if (!w) {
  1800. map.set(this, null);
  1801. } else {
  1802. if (!w[wk]) w[wk] = mWeakRef(w);
  1803. let byPass = false;
  1804. if (this.is === 'ytd-masthead') byPass = true;
  1805. if (byPass) {
  1806. map.set(this, w);
  1807. } else {
  1808. map.set(this, w[wk]);
  1809. }
  1810. }
  1811. return true;
  1812. },
  1813. enumerable: true,
  1814. configurable: true
  1815. });
  1816. }
  1817. let previousDataHost = this.__dataHost;
  1818. renderPathMake(previousDataHost)
  1819. let r = _registerHost.call(this);
  1820. let currentDataHost = this.__dataHost;
  1821. if (currentDataHost !== previousDataHost) { // future use only
  1822. if (previousDataHost && previousDataHost.nodeType >= 1 && previousDataHost.isConnected === false) {
  1823. _removedElements.addNode(previousDataHost); // rn54002
  1824. }
  1825. }
  1826. return r;
  1827. }
  1828. }
  1829.  
  1830. }
  1831. globalSetup('_removeBoundDom', setup1);
  1832.  
  1833.  
  1834. /*
  1835.  
  1836. M.prototype._stampTemplate = function(N, R) {
  1837. R = R || this._bindTemplate(N, !0);
  1838. aU.push(this);
  1839. N = d.prototype._stampTemplate.call(this, N, R);
  1840. aU.pop();
  1841. R.nodeList = N.nodeList;
  1842. if (!R.wasPreBound)
  1843. for (var X = R.childNodes = [], A = N.firstChild; A; A = A.nextSibling)
  1844. X.push(A);
  1845. N.templateInfo = R;
  1846. X = R.nodeList;
  1847. A = R.nodeInfoList;
  1848. if (A.length)
  1849. for (var l = 0; l < A.length; l++) {
  1850. var k = X[l]
  1851. , T = A[l].bindings;
  1852. if (T)
  1853. for (var W = 0; W < T.length; W++) {
  1854. var w = T[W]
  1855. , p = k
  1856. , h = w;
  1857. if (h.isCompound) {
  1858. for (var I = p.__dataCompoundStorage || (p.__dataCompoundStorage = {}), O = h.parts, y = Array(O.length), c = 0; c < O.length; c++)
  1859. y[c] = O[c].literal;
  1860. O = h.target;
  1861. I[O] = y;
  1862. h.literal && h.kind == "property" && (O === "className" && (p = (0,
  1863. _.FK)(p)),
  1864. p[O] = h.literal)
  1865. }
  1866. gM2(k, this, w)
  1867. }
  1868. k.__dataHost = this
  1869. }
  1870. this.__dataClientsReady && (this._runEffectsForTemplate(R, this.__data, null, !1),
  1871. this._flushClients());
  1872. return N
  1873. }
  1874. ;
  1875.  
  1876. */
  1877.  
  1878. const wnc = new Set();
  1879.  
  1880. const __listWeakNodeC__ = window.__listWeakNodeC__ = () => {
  1881. const result = __listWeakNodeC0__();
  1882. return [...result].sort();
  1883. }
  1884.  
  1885. const __listWeakNodeC0__ = () => {
  1886. let result = new Set();
  1887. for (const nodeC of wnc) {
  1888. for (const k of Object.getOwnPropertyNames(nodeC)) {
  1889. result.add(k)
  1890. }
  1891. }
  1892. return result;
  1893. }
  1894.  
  1895. setInterval(() => {
  1896. if (wnc.size > 0 && __listWeakNodeC0__().size !== 1) console.warn(`[yt-js-engine-tamer] WARNING 0xF04E: ${__listWeakNodeC__()}`);
  1897. }, 400);
  1898.  
  1899.  
  1900. const dollarStore = new Map();
  1901.  
  1902. const makeDollarClass = (idsJoined, ids) => {
  1903. const $ = class {};
  1904. const a = $.prototype;
  1905. ids.forEach(id => {
  1906. const p = `## ${id}`;
  1907. Object.defineProperty(a, id, {
  1908. get() {
  1909. return kRef(this[p]);
  1910. },
  1911. set(nv) {
  1912. if (nv instanceof Node) {
  1913. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1914. this[p] = nv[wk];
  1915. } else {
  1916. this[p] = nv;
  1917. }
  1918. return true;
  1919. },
  1920. enumerable: true,
  1921. configurable: true
  1922. });
  1923. });
  1924. a.__w646__ = true;
  1925. dollarStore.set(idsJoined, $);
  1926. return $;
  1927. }
  1928.  
  1929. // let initied2 = false;
  1930. const setup2 = (qxx) => {
  1931. // if(initied2) return;
  1932. // initied2 = true;
  1933. const proto = qxx;
  1934. const constructor = proto.constructor;
  1935. const _stampTemplate = proto._stampTemplate;
  1936. // console.log(12883, proto, constructor)
  1937. if (typeof _stampTemplate === 'function' && _stampTemplate.length === 2 && !proto._stampTemplate374) {
  1938. proto._stampTemplate374 = _stampTemplate;
  1939. proto._stampTemplate = function (N, R) {
  1940.  
  1941. if (!shadyInited) setupShady();
  1942.  
  1943. let e__ = null;
  1944. try {
  1945. // R = boolean true or binded template
  1946. // N = template elemenet
  1947. let M = N;
  1948. let r_ = null;
  1949. const r = _stampTemplate.call(this, M, R); // return the fragment created with nodeList
  1950. r_ = r;
  1951. // if (r && r.host) {
  1952. // console.log(2883, R.host)
  1953. // }
  1954. if (r && r.$ && !r.$.__w646__) {
  1955. const $ = r.$;
  1956. const ids = Object.getOwnPropertyNames($)
  1957. const idsJoined = ids.join(' ');
  1958. const C = dollarStore.get(idsJoined) || makeDollarClass(idsJoined, ids);
  1959. const objVals = { ...$ };
  1960. Reflect.setPrototypeOf($, C.prototype);
  1961. for (const id of ids) {
  1962. delete $[id];
  1963. $[id] = objVals[id];
  1964. }
  1965. }
  1966. if (r && r.nodeType === 11 && !r.__fragId57__) {
  1967.  
  1968. const fid = genId();
  1969.  
  1970. r.__fragId57__ = fid;
  1971. if (!r[wk]) r[wk] = mWeakRef(r);
  1972. stampedFragment.set(fid, r[wk]);
  1973.  
  1974. if (r.nodeList) {
  1975. const nl = r.nodeList;
  1976. nl.__belongFragId57__ = fid;
  1977. for (let i = 0, l = nl.length; i < l; i++) {
  1978. const t = nl[i];
  1979. if (t && t.nodeType >= 1 && !(t instanceof ShadowRoot)) {
  1980. if (!t[wk]) t[wk] = mWeakRef(t);
  1981. const eid = `${fid}::${i}`;
  1982. const wn = Object.create(WeakNodeC.prototype);
  1983. wn.eid = eid;
  1984. wnc.add(wn);
  1985. nl[i] = wn;
  1986. // we believe the stampedNodes shall be attached to the document DomTree
  1987. stampedNodes.set(eid, t[wk]);
  1988. t.__weakNodeCId57__ = eid;
  1989. } else {
  1990. if (t instanceof ShadowRoot) {
  1991. console.warn('[yt-js-engine-tamer]', 'ShadowRoot in _stampTemplate');
  1992. }
  1993. }
  1994. }
  1995. }
  1996.  
  1997. }
  1998.  
  1999. return r;
  2000. } catch (e) { console.error(e); e__ = e; }
  2001. throw e__;
  2002.  
  2003. }
  2004. }
  2005. }
  2006.  
  2007. globalSetup('_addMethodEventListenerToNode', setup2);
  2008.  
  2009. }
  2010.  
  2011. if (XFlag) {
  2012.  
  2013. const cMap = new Set();
  2014. cMap.add = cMap.addOriginal || cMap.add;
  2015. const yMap = new Set();
  2016. yMap.add = yMap.addOriginal || yMap.add;
  2017.  
  2018.  
  2019. const ydMap = new Set();
  2020. ydMap.add = ydMap.addOriginal || ydMap.add;
  2021.  
  2022. window.yMap = yMap;
  2023. window.cMap = cMap;
  2024. window.ydMap = ydMap;
  2025.  
  2026. const constructAts = new Set();
  2027. constructAts.add = constructAts.addOriginal || constructAts.add;
  2028. window.constructAts = constructAts;
  2029.  
  2030. const kMap = new WeakMap();
  2031.  
  2032. const kRefProp = (wr, prop)=>{
  2033. let o = kRef(wr);
  2034. return o ? o[prop] : null;
  2035. }
  2036.  
  2037. const wrObj = (objRef, props) => {
  2038. let wr = mWeakRef(objRef);
  2039. if (wr === objRef || !props || !props.length) return wr;
  2040. let properties = {};
  2041. props.forEach(k => {
  2042. properties[k] = {
  2043. get() {
  2044. return kRefProp(this, k)
  2045. },
  2046. enumerable: false,
  2047. configurable: true
  2048. };
  2049. });
  2050. Object.defineProperties(wr, properties);
  2051. return wr;
  2052. }
  2053.  
  2054. const sProtos = {};
  2055.  
  2056. const setupCProto = function (cProto) {
  2057.  
  2058. if(cProto === Object.prototype) return;
  2059.  
  2060. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2061. cProto[kMap.get(cProto)] = true;
  2062. // debugger;
  2063.  
  2064. if (FIX_SHADY_METHODS && cProto.appendChild && cProto.cloneNode && cProto.contains && cProto.getRootNode && cProto.insertBefore && cProto.querySelector && cProto.querySelectorAll && cProto.querySelectorAll && cProto.removeAttribute && cProto.removeChild && cProto.replaceChild && cProto.setAttribute && cProto.is === undefined && !(cProto instanceof Node)) {
  2065. if (!cProto.krmv757) {
  2066. cProto.krmv757 = true;
  2067. const props = Object.entries(Object.getOwnPropertyDescriptors(cProto)).filter(a => {
  2068. const e = a[1];
  2069. return typeof e.value === 'function' && e.writable === true && e.enumerable === true && e.configurable === true
  2070. });
  2071. const keys = props.map(a => a[0]);
  2072. keys.forEach(key => {
  2073. if (!(key in HTMLTitleElement.prototype)) return;
  2074. const bey = `${key}588`;
  2075. cProto[bey] = cProto[key];
  2076. const isDomChange = key === 'appendChild' || key === 'insertBefore' || key === 'removeChild' || key === 'replaceChild';
  2077. cProto[key] = function () {
  2078. const p = ((this || 0).root || 0).node;
  2079. if (!isDomChange && (p instanceof Element) && p.nodeType === 1) {
  2080. return p[key](...arguments);
  2081. } else {
  2082. return this[bey](...arguments);
  2083. }
  2084. }
  2085. });
  2086. }
  2087. }
  2088.  
  2089. 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];
  2090. constructAts.add(constructAt)
  2091.  
  2092. if (MemoryFix_Flag002 & 32) {
  2093. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  2094. fixDetachFn(cProto);
  2095. }
  2096. }
  2097.  
  2098. if (MemoryFix_Flag002 & 2) {
  2099. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  2100. cProto.__setPropDX38__ = true;
  2101.  
  2102. if (cProto._setPendingProperty.length === 3) {
  2103. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  2104. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  2105. return () => {
  2106. const obj = kRef(wobj);
  2107. let u = Reflect.apply(this, obj, args);
  2108. args.length = 0;
  2109. wobj = null;
  2110. return u;
  2111. };
  2112. });
  2113. }
  2114.  
  2115. }
  2116. }
  2117.  
  2118.  
  2119. const cProtoConstructor = cProto.constructor;
  2120.  
  2121. if (MemoryFix_Flag002 & 8) {
  2122. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  2123. cProtoConstructor.__parseBindingsDX38__ = true;
  2124.  
  2125. ydMap.add(cProtoConstructor);
  2126.  
  2127. if (cProtoConstructor._parseBindings.length === 2) {
  2128.  
  2129. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  2130.  
  2131. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  2132. let p = this._parseBindings3858(c, d);
  2133. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  2134. if (p) this.__bindingsArrs__.push(p);
  2135. return p;
  2136. });
  2137.  
  2138. }
  2139. }
  2140. }
  2141.  
  2142. /*
  2143. a.prototype._initializeProperties = function() {
  2144. if (Em && this.hasAttribute("disable-upgrade"))
  2145. this.__isUpgradeDisabled = !0;
  2146. else {
  2147. var e = Object.getPrototypeOf(this);
  2148. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  2149. e.__hasRegisterFinished = !0);
  2150. b.prototype._initializeProperties.call(this);
  2151. this.root = this;
  2152. this.created();
  2153. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  2154. this._applyListeners()
  2155. }
  2156. }
  2157. */
  2158. /*
  2159. bOa = function(a, b, c) {
  2160. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  2161. d.prototype.is = b;
  2162. d.prototype.localName = b;
  2163. c && aOa(d, c);
  2164. return function(e) {
  2165. e && (d.prototype.hostElement = e);
  2166. var g = new d;
  2167. g.root = g;
  2168. g.hostElement = e;
  2169. return g
  2170. }
  2171. }
  2172. */
  2173.  
  2174.  
  2175. }
  2176. const symDH = Symbol();
  2177.  
  2178. const wfStore = new WeakMap();
  2179.  
  2180. const wrapF = function (f, key) {
  2181. if (wfStore.get(f)) return wfStore.get(f);
  2182.  
  2183. let g = function () {
  2184. const o = kRef(this);
  2185. if (!o) return;
  2186. const cnt = insp(o);
  2187. // if (cnt === o) return;
  2188. // if (!('ready' in cnt)) return;
  2189. return f.apply(o, arguments);
  2190. };
  2191. g.key38 = key;
  2192. g.originalFunc38 = f;
  2193. g.__wrapF84__ = true;
  2194. wfStore.set(f, g);
  2195. wfStore.set(g, g);
  2196. return g;
  2197. };
  2198.  
  2199. if (MemoryFix_Flag002 & 16) {
  2200. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  2201.  
  2202. Object.defineProperty(Node.prototype, key, {
  2203. get() {
  2204. return this[`__a0939${key}__`];
  2205. },
  2206. set(nv) {
  2207. if (typeof nv !== 'function') return;
  2208. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  2209. this[`__a0939${key}__`] = g;
  2210. return true;
  2211. }
  2212. });
  2213.  
  2214.  
  2215. });
  2216. }
  2217.  
  2218.  
  2219.  
  2220. // const wm = new WeakMap();
  2221.  
  2222. const fixDetachFn = (tpProto) => { // & 32
  2223.  
  2224. if (tpProto.dk322) return;
  2225. tpProto.dk322 = true;
  2226.  
  2227. window.__fixTemplateReuse1058__ = true;
  2228.  
  2229.  
  2230. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  2231. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  2232. tpProto.__ensureTemplatized = function () {
  2233. // console.log(18470001)
  2234. return this.__ensureTemplatized994();
  2235. }
  2236. }
  2237.  
  2238.  
  2239. tpProto.__updateInstances994 = tpProto.__updateInstances;
  2240. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  2241. let bypass= false;
  2242. tpProto.__updateInstances = function (a, b, c) {
  2243.  
  2244. // const a_ = [...a];
  2245. if(!bypass && a === this.items && (a||0).length >=1 ){
  2246.  
  2247. bypass = true;
  2248. // console.log(18470002, a, b,c)
  2249. let e;
  2250. for (e = 0; e < b; e++) {
  2251. let g = this.__instances[e]
  2252. , k = c[e]
  2253. , m = a[k];
  2254. if(g && typeof (m||0) === 'object'){
  2255. // const q = g._shouldPropertyChange;
  2256. // g._shouldPropertyChange = ()=>true;
  2257. // g[this.as] = {};
  2258. // a_[k]=a[k] = m;
  2259. // g[this.as] = m;
  2260.  
  2261. // use public interface notifyPath instead of internal interface _setPendingProperty
  2262. const m_ = a[k] = Object.assign({}, a[k]);
  2263. try {
  2264. g.notifyPath(this.as, {});
  2265. } catch (e) { }
  2266. try {
  2267. g.notifyPath(this.as, m_);
  2268. } catch (e) { }
  2269.  
  2270. // g._setPendingProperty(this.as, {});
  2271. // g._setPendingProperty(this.as, m);
  2272. // g._setPendingProperty(this.indexAs, e);
  2273. // g._setPendingProperty(this.itemsIndexAs, k);
  2274. // delete g._shouldPropertyChange;
  2275. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2276. }
  2277. }
  2278. bypass = false;
  2279.  
  2280. }
  2281. const r = this.__updateInstances994(a,b,c);
  2282.  
  2283. // for (e = 0; e < b; e++) {
  2284. // let g = this.__instances[e]
  2285. // , k = c[e]
  2286. // , m = a_[k];
  2287. // if(g){
  2288. // // const q = g._shouldPropertyChange;
  2289. // // g._shouldPropertyChange = ()=>true;
  2290. // // g[this.as] = m;
  2291. // // g._setPendingProperty(this.as, {});
  2292. // // g._setPendingProperty(this.as, m);
  2293. // // g._setPendingProperty(this.indexAs, e);
  2294. // // g._setPendingProperty(this.itemsIndexAs, k);
  2295. // // delete g._shouldPropertyChange;
  2296. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2297. // }
  2298. // }
  2299.  
  2300. return r;
  2301. }
  2302. }
  2303.  
  2304. tpProto.__detachInstance994 = tpProto.__detachInstance;
  2305. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  2306. tpProto.__detachInstance = function (a) {
  2307. const u = this.__instances[a];
  2308. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2309. const children = (u || 0).children;
  2310. if (children && children.length >= 1) {
  2311. const pp = document.createDocumentFragment();
  2312. for (const s of [...children]) {
  2313. pp.appendChild(s);
  2314. }
  2315. }
  2316. try {
  2317. return this.__detachInstance994(a);
  2318. } catch (e) { }
  2319. return u;
  2320. }
  2321. }
  2322.  
  2323. tpProto.__attachInstance994 = tpProto.__attachInstance;
  2324. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  2325. tpProto.__attachInstance = function (a, b) {
  2326. const u = this.__instances[a];
  2327. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2328. if (u && u.root && b) {
  2329. const root = u.root;
  2330. const pp = document.createDocumentFragment();
  2331. pp.appendChild(root);
  2332. root.appendChild(pp);
  2333. const r = this.__attachInstance994(a, b);
  2334. if (!this.__chunkingId) this.__chunkingId = 0.25;
  2335. return r;
  2336. }
  2337. }
  2338. }
  2339.  
  2340. }
  2341.  
  2342. const ytTemplateDomEntry = (tpProto) => {
  2343.  
  2344. console.log('ytTemplateDomEntry triggered')
  2345.  
  2346.  
  2347. const convertToWeakArr = (arr) => {
  2348.  
  2349. if (arr.isWeak) return;
  2350.  
  2351. for (let i = 0, l = arr.length; i < l; i++) {
  2352. const o = arr[i]
  2353. if (o) {
  2354. let p = kRef(o)
  2355. if (!p) arr[i] = null;
  2356. else {
  2357. if (!o[wk]) o[wk] = mWeakRef(o);
  2358. arr[i] = o[wk];
  2359. }
  2360. }
  2361. }
  2362. arr.isWeak = true;
  2363.  
  2364. }
  2365.  
  2366. const convertToNormalArr = (arr) => {
  2367.  
  2368. if (!arr.isWeak) return;
  2369.  
  2370. for (let i = 0, l = arr.length; i < l; i++) {
  2371. const o = arr[i]
  2372. if (o) {
  2373. let p = kRef(o)
  2374. arr[i] = p;
  2375. }
  2376. }
  2377. arr.isWeak = false;
  2378.  
  2379. }
  2380.  
  2381. if (MemoryFix_Flag002 & 256) {
  2382. Object.defineProperty(tpProto, '__instances', {
  2383. get() {
  2384. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2385. let arr = this.__instances_actual471__;
  2386. if (arr && arr.isWeak) {
  2387. convertToNormalArr(arr);
  2388. for (let i = arr.length - 1; i >= 0; i--) {
  2389. const t = arr[i];
  2390. if (!t) arr.splice(i, 1);
  2391. else if (!t.__keepInstance038__) t.__keepInstance038__ = true;
  2392. }
  2393. Promise.resolve(arr).then(convertToWeakArr);
  2394. }
  2395. return arr;
  2396. },
  2397. set(nv) {
  2398. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2399. this.__instances_actual471__ = nv;
  2400. if (nv && !nv.isWeak) {
  2401. Promise.resolve(nv).then(convertToWeakArr);
  2402. }
  2403. return true;
  2404. },
  2405. enumerable: false,
  2406. configurable: true
  2407. });
  2408. }
  2409.  
  2410. // console.log(91901, tpProto.__detachInstance)
  2411. if (MemoryFix_Flag002 & 32) {
  2412. if (tpProto.__detachInstance) {
  2413. fixDetachFn(tpProto);
  2414. } else {
  2415. Promise.resolve(tpProto).then((tpProto) => {
  2416. // console.log(91902, tpProto.__detachInstance)
  2417. fixDetachFn(tpProto);
  2418. })
  2419. }
  2420. }
  2421.  
  2422. }
  2423.  
  2424. if (MemoryFix_Flag002 & 32) {
  2425. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  2426. set(nv) {
  2427. if (nv === true) return false;
  2428. tpProto = this;
  2429. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  2430. tpProto.__domDX37__ = true;
  2431. ytTemplateDomEntry(tpProto);
  2432. }
  2433. this.__ensureTemplatized949__ = nv;
  2434. return true;
  2435. },
  2436. get() {
  2437. return this.__ensureTemplatized949__;
  2438. }
  2439. });
  2440. }
  2441.  
  2442.  
  2443. if (MemoryFix_Flag002 & 64) {
  2444. HTMLElement_.prototype.__dataHostBinding374 = true;
  2445. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  2446. get() {
  2447. return kRef(this.__dataHostWr413__);
  2448. },
  2449. set(nv) {
  2450. if (nv && typeof nv === 'object' && !nv.deref) {
  2451. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2452. nv = nv[wk];
  2453. }
  2454. this.__dataHostWr413__ = nv;
  2455. return true;
  2456. }
  2457. });
  2458. }
  2459.  
  2460.  
  2461. const setupYProto = function (yProto) {
  2462.  
  2463. if(yProto === Object.prototype) return;
  2464.  
  2465. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2466. yProto[kMap.get(yProto)] = true;
  2467.  
  2468. 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') {
  2469. const disconnectedCallback277 = yProto.disconnectedCallback;
  2470. yProto.disconnectedCallback277 = true;
  2471. yProto.disconnectedCallback = function () {
  2472. disconnectedCallback277.call(this);
  2473. if (this.nodeName === 'DOM-IF' && this.__instance && typeof this.__teardownInstance === 'function') {
  2474. const shadyParent = (this.__shady_parentNode || 0);
  2475. const actualParent = (this.parentNode || 0);
  2476. if (shadyParent !== actualParent && shadyParent.nodeType === 11 && actualParent.nodeType === 11) {
  2477. // && (shadyParent.compareDocumentPosition(actualParent) & (1|8|16) === 1)
  2478. // if (!this.restamp && !this.id && this.__ctor && this.isConnected === false) {
  2479. const children = (this.__instance.children || 0).length;
  2480. if (children >= 1) {
  2481. try {
  2482. this.__teardownInstance();
  2483. } catch (e) { }
  2484. }
  2485. // }
  2486. }
  2487. }
  2488. }
  2489. }
  2490.  
  2491.  
  2492. if (MemoryFix_Flag002 & 32) {
  2493. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  2494. fixDetachFn(yProto);
  2495. }
  2496. }
  2497.  
  2498. if (MemoryFix_Flag002 & 128) {
  2499. if (!yProto.__dataHostBinding374) {
  2500. yProto.__dataHostBinding374 = true;
  2501. Object.defineProperty(yProto, '__dataHost', {
  2502. set(nv) {
  2503. let dh = nv;
  2504. if (dh && typeof dh === 'object' && !dh.deref) {
  2505. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  2506. dh = wr;
  2507. }
  2508. this[symDH] = dh;
  2509. return true;
  2510. },
  2511. get() {
  2512. let wr = this[symDH];
  2513. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  2514. return obj;
  2515. },
  2516. enumerable: false,
  2517. configurable: true
  2518. });
  2519. }
  2520.  
  2521.  
  2522.  
  2523. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  2524. yProto._registerHostDX38__ = true;
  2525.  
  2526. // yProto._registerHost7133 = yProto._registerHost;
  2527.  
  2528. yProto.__enableOrFlushClients = function () {
  2529. const c_ = this.__dataPendingClients;
  2530. if (c_) {
  2531. const c = c_.slice();
  2532. c_.length = 0;
  2533. for (let d = 0, l = c.length; d < l; d++) {
  2534. let e = kRef(c[d]);
  2535. if (e) {
  2536. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  2537. }
  2538. }
  2539. }
  2540. }
  2541.  
  2542. yProto._enqueueClient = function (c) {
  2543. if (c === this || !c || typeof c !== 'object') return;
  2544. if (c.deref) c = kRef(c);
  2545. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  2546. if (!c[wk]) c[wk] = mWeakRef(c);
  2547. m.push(c[wk]);
  2548. }
  2549.  
  2550. }
  2551. }
  2552.  
  2553.  
  2554.  
  2555. }
  2556. const setupRendering = function () {
  2557.  
  2558. const cnt = this;
  2559. const cProto = Reflect.getPrototypeOf(cnt);
  2560. let yProto = Reflect.getPrototypeOf(cProto);
  2561.  
  2562. const yProtos = new Set();
  2563.  
  2564. if (!yMap.has(yProto)) {
  2565. // capture all ancenstor constructors of a and b (non-specific component type)
  2566.  
  2567. do {
  2568. if (yProto === Object.prototype || yProto === null) break;
  2569. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  2570. yProtos.add(yProto);
  2571. yProto = Reflect.getPrototypeOf(yProto);
  2572. } while (!yProtos.has(yProto));
  2573.  
  2574. for (const yProto of yProtos) {
  2575. yMap.add(yProto);
  2576. setupYProto(yProto)
  2577. }
  2578.  
  2579. }
  2580.  
  2581.  
  2582. if (!cMap.has(cProto)) {
  2583. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  2584. setupCProto(cProto);
  2585. }
  2586.  
  2587. }
  2588.  
  2589. /*
  2590.  
  2591. jF = function(M) {
  2592. var d = YNV.call(this) || this;
  2593. d._configureProperties(M);
  2594. d.root = d._stampTemplate(d.__dataHost);
  2595. var N = [];
  2596. d.children = N;
  2597. for (var R = d.root.firstChild; R; R = R.nextSibling)
  2598. N.push(R),
  2599. R.__templatizeInstance = d;
  2600. d.__templatizeOwner && d.__templatizeOwner.__hideTemplateChildren__ && d._showHideChildren(!0);
  2601. N = d.__templatizeOptions;
  2602. (M && N.instanceProps || !N.instanceProps) && d._enableProperties();
  2603. return d
  2604. };
  2605. */
  2606.  
  2607. const sb1 = Symbol();
  2608. Object.defineProperty(Object.prototype, 'root', {
  2609. get() {
  2610. return this[sb1];
  2611. },
  2612. set(nv){
  2613. const p = this ? kRef(this) : null;
  2614. const mv = nv ? kRef(nv) : null;
  2615.  
  2616. // if (typeof (this.host || 0) === 'object' && !this.host6833) {
  2617. // const host = this.host;
  2618. // if (!host[wk]) host[wk] = mWeakRef(host);
  2619. // this.host6833 = host[wk];
  2620. // delete this.host;
  2621. // console.log(21883, host)
  2622. // Object.defineProperty(this, 'host', {
  2623. // get() {
  2624. // return kRef(this.host6833);
  2625. // },
  2626. // set(nv) {
  2627. // if (!nv) {
  2628. // this.host6833 = nv;
  2629. // } else {
  2630. // if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2631. // this.host6833 = nv[wk];
  2632. // }
  2633. // return true;
  2634. // }, enumerable: false, configurable: true
  2635. // });
  2636. // }
  2637.  
  2638. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2639. p.__setupRendered399__ = true;
  2640. setupRendering.call(p);
  2641. }
  2642. if (mv && mv.is && !mv.__setupRendered399__) {
  2643. mv.__setupRendered399__ = true;
  2644. setupRendering.call(mv);
  2645. }
  2646.  
  2647. this[sb1] = nv;
  2648. return true;
  2649. }
  2650. });
  2651.  
  2652.  
  2653. }
  2654.  
  2655. let _cssSheet = null;
  2656. const addNewCSS = typeof CSSStyleSheet !== 'undefined' && document.adoptedStyleSheets ? (css) => {
  2657. if (!_cssSheet) {
  2658. _cssSheet = new CSSStyleSheet();
  2659. document.adoptedStyleSheets.push(_cssSheet);
  2660. }
  2661. _cssSheet.insertRule(`${css}`);
  2662. } : (css) => {
  2663. let nonce = document.querySelector('style[nonce]');
  2664. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2665. const st = document.createElement('style');
  2666. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2667. st.textContent = `${css}`;
  2668. let parent;
  2669. if (parent = document.head) parent.appendChild(st);
  2670. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  2671. }
  2672.  
  2673. function getTranslate() {
  2674.  
  2675. pLoad.then(() => {
  2676. addNewCSS(".yt-formatted-string-block-line{display:block;}");
  2677. });
  2678.  
  2679. const snCache = new Map();
  2680.  
  2681. if (TRANSLATE_DEBUG) {
  2682. console.log(11)
  2683. }
  2684.  
  2685. /** @type {(str: string?) => string} */
  2686. function _snippetText(str) {
  2687. // str can be underfinded
  2688. if (!str || typeof str !== 'string') return '';
  2689. let res = snCache.get(str);
  2690. if (res === undefined) {
  2691. let b = false;
  2692. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  2693. b = true;
  2694. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  2695. });
  2696. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  2697. b = true;
  2698. return '';
  2699. });
  2700. if (b) {
  2701. snCache.set(str, res);
  2702. snCache.set(res, null);
  2703. } else {
  2704. res = null;
  2705. snCache.set(str, null);
  2706. }
  2707. }
  2708. return res === null ? str : res;
  2709. }
  2710.  
  2711. /** @type {(snippet: Object) => string} */
  2712. function snippetText(snippet) {
  2713. let runs = snippet.runs;
  2714. const n = runs.length;
  2715. if (n === 1) return _snippetText(runs[0].text);
  2716. let res = new Array(n);
  2717. let ci = 0;
  2718. for (const s of runs) {
  2719. res[ci++] = _snippetText(s.text);
  2720. }
  2721. return res.join('\n');
  2722. }
  2723.  
  2724. const _DEBUG_szz = (t) => t.map(x => {
  2725. const tsr = x.transcriptSegmentRenderer;
  2726. return ({
  2727. t: tsr.snippet.runs.map(x => x.text).join('//'),
  2728. a: tsr.startMs,
  2729. b: tsr.endMs
  2730. });
  2731. });
  2732.  
  2733. const fixRuns = (runs) => {
  2734. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  2735. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  2736. const text = runs[0].text;
  2737. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  2738. const s = text.split(nlc);
  2739. let bi = 0;
  2740. runs.length = s.length;
  2741. for (const text of s) {
  2742. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  2743. }
  2744. }
  2745. for (const s of runs) {
  2746. s.text = _snippetText(s.text);
  2747. }
  2748. }
  2749.  
  2750. function translate(initialSegments) {
  2751. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  2752.  
  2753. if (!initialSegments) return initialSegments;
  2754.  
  2755. if (TRANSLATE_DEBUG) {
  2756. console.log(12);
  2757. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  2758. let obj = JSON.parse(r);
  2759. console.log(7558, 1, obj)
  2760. return obj;
  2761. }).then(p => {
  2762. let obj = _DEBUG_szz(p)
  2763. console.log(7558, 2, obj)
  2764. })
  2765. }
  2766.  
  2767.  
  2768. //let mapRej = new WeakSet();
  2769.  
  2770. const n1 = initialSegments.length;
  2771. if (!n1) return fRes;
  2772. let n2 = 0;
  2773.  
  2774.  
  2775. const fRes = new Array(n1);
  2776. // -----------------------------------------------------------------------------------------
  2777.  
  2778. const s8 = Symbol();
  2779.  
  2780. {
  2781.  
  2782. /** @type {Map<String, Object>} */
  2783. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  2784.  
  2785. // /-* * @type {Map<String, number>} *-/
  2786. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  2787. // 1: ok
  2788. // 2: abandoned effect text
  2789.  
  2790. for (const initialSegment of initialSegments) {
  2791. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  2792. if (!transcript) {
  2793. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2794. fRes[n2++] = initialSegment;
  2795. continue;
  2796. }
  2797. const runs = transcript.snippet.runs
  2798. if (!runs || runs.length === 0) {
  2799. initialSegment[s8] = true;
  2800. continue;
  2801. }
  2802. let startMs = (+transcript.startMs || 0); //integer
  2803. let endMs = (+transcript.endMs || 0); //integer
  2804. if (startMs === endMs) {
  2805. // effect text
  2806. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2807. //mapRej.add(initialSegment)
  2808. continue;
  2809. }
  2810. if (endMs - startMs < 30) {
  2811. continue;
  2812. }
  2813. const text = snippetText(transcript.snippet);
  2814. const hEntry = cacheTexts.get(text);
  2815. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  2816. if (mh1e === 2) continue;
  2817. const entry = {
  2818. startMs,
  2819. endMs,
  2820. initialSegment,
  2821. text
  2822. };
  2823. if (mh1e === 0) {
  2824. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  2825. initialSegment[s8] = true;
  2826. cacheTexts.set(text, null);
  2827. //effect only
  2828. // https://www.youtube.com/watch?v=zLak0dxBKpM
  2829. //mapRej.add(initialSegment)
  2830. continue;
  2831. }
  2832. } else if (hEntry) {
  2833.  
  2834. const timeDiff = entry.startMs - hEntry.endMs;
  2835. let shouldMerge = false;
  2836.  
  2837. if (timeDiff >= 0) {
  2838.  
  2839. if (timeDiff < 25) {
  2840. shouldMerge = true;
  2841. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  2842. shouldMerge = true;
  2843. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  2844. shouldMerge = true;
  2845. }
  2846.  
  2847. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  2848. // abandon the current entry.
  2849. // absorbed by previous entry
  2850. hEntry.endMs = entry.endMs;
  2851. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2852. //mapRej.add(entry.initialSegment);
  2853. continue;
  2854. }
  2855.  
  2856. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  2857.  
  2858. // abandon the current entry.
  2859. // absorbed by previous entry
  2860. if (entry.endMs > hEntry.endMs) {
  2861. hEntry.endMs = entry.endMs;
  2862. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2863. }
  2864. //mapRej.add(entry.initialSegment);
  2865. continue;
  2866.  
  2867. }
  2868.  
  2869. }
  2870. //if not abandoned
  2871. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  2872. // for (const s of runs) {
  2873. // s.text = _snippetText(s.text);
  2874. // }
  2875. fixRuns(runs);
  2876. fRes[n2++] = initialSegment;
  2877. }
  2878.  
  2879. // cacheTexts.clear(); // let GC do it.
  2880. cacheTexts = null;
  2881. // mh1.clear(); // let GC do it.
  2882. // mh1 = null;
  2883.  
  2884. }
  2885.  
  2886. const si_length = fRes.length = n2;
  2887. const sj_length = n1;
  2888.  
  2889. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  2890. // collect the abandon text to become second subtitle
  2891.  
  2892. let sj_start = 0;
  2893. let invalid_sj = -1;
  2894. for (let si = 0; si < si_length; si++) {
  2895. const segment = fRes[si];
  2896. let transcript = segment.transcriptSegmentRenderer;
  2897. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  2898. const runs = transcript.snippet.runs;
  2899. // fixRuns(runs);
  2900. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  2901. const main_startMs = (+transcript.startMs || 0);
  2902. const main_endMs = (+transcript.endMs || 0);
  2903. transcript = null;
  2904.  
  2905. /** @type {Map<string, number>} */
  2906. let tMap = new Map(); // avoid duplicate with javascript object properties
  2907.  
  2908. // assume that it is asc-ordered array of key startMs;
  2909. for (let sj = sj_start; sj < sj_length; sj++) {
  2910. const initialSegment = initialSegments[sj];
  2911.  
  2912. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  2913.  
  2914. const tSegment = initialSegment.transcriptSegmentRenderer;
  2915.  
  2916. if (!tSegment) {
  2917. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2918. invalid_sj = sj; // should invalid_sj be set ?
  2919. continue;
  2920. }
  2921.  
  2922. const startMs = (+tSegment.startMs || 0)
  2923. const isStartValid = startMs >= main_startMs;
  2924. if (!isStartValid) {
  2925. invalid_sj = sj;
  2926. continue;
  2927. }
  2928. // isStartValid must be true
  2929. if (startMs > main_endMs) {
  2930. sj_start = invalid_sj + 1;
  2931. break;
  2932. }
  2933.  
  2934. const endMs = (+tSegment.endMs || 0)
  2935. if (endMs <= main_endMs) {
  2936. const mt = snippetText(tSegment.snippet);
  2937. const prev = tMap.get(mt);
  2938. if (endMs >= startMs) {
  2939. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  2940. }
  2941. }
  2942.  
  2943. }
  2944.  
  2945. if (tMap.size <= 1) continue; // no second line
  2946. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  2947. tMap = null;
  2948.  
  2949. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2950.  
  2951. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  2952.  
  2953. let targetZ = rg[1][1];
  2954. if (targetZ > 4) {
  2955. let az = 0;
  2956. let fail = false;
  2957. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  2958. az += rg[idx][1];
  2959. if (az >= targetZ) {
  2960. fail = true;
  2961. break;
  2962. }
  2963. }
  2964. if (!fail) {
  2965. const rgA = rg[0][0];
  2966. const rgB = rg[1][0];
  2967. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  2968. if (isDiff && rgA === _snippetText(runs[0].text)) {
  2969. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  2970. runs.push({ text: rgB, blockLine: true });
  2971. }
  2972. }
  2973. }
  2974. rg = null;
  2975. }
  2976.  
  2977. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  2978.  
  2979. let obj = r;
  2980. console.log(7559, 1, obj)
  2981. return obj;
  2982. }).then(p => {
  2983. let obj = _DEBUG_szz(p)
  2984. console.log(7559, 2, obj)
  2985.  
  2986. });
  2987. }
  2988.  
  2989. // -----------------------------------------------------------------------------------------
  2990. snCache.clear();
  2991. return fRes;
  2992.  
  2993. }
  2994.  
  2995.  
  2996. return translate
  2997.  
  2998. }
  2999.  
  3000.  
  3001. let translateFn = null;
  3002.  
  3003. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  3004.  
  3005. const wmx = new WeakMap();
  3006.  
  3007. function fixSegments(ytObj) {
  3008. let a, b;
  3009. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  3010. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  3011. translateFn = translateFn || getTranslate();
  3012. let cSeg;
  3013. cSeg = wmx.get(seg);
  3014. if (!cSeg) {
  3015. let vSeg = null;
  3016. try {
  3017. vSeg = translateFn(seg);
  3018. } catch (e) {
  3019. }
  3020. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  3021. // console.log('translated', vSeg);
  3022. cSeg = vSeg;
  3023. wmx.set(seg, cSeg);
  3024. wmx.set(cSeg, cSeg);
  3025. }
  3026. }
  3027. if (cSeg && cSeg !== seg) {
  3028. a[b] = cSeg;
  3029. }
  3030. }
  3031.  
  3032. const dfn = Symbol();
  3033. const Object_ = Object;
  3034. Object_[dfn] = Object_.defineProperties;
  3035. let activation = true;
  3036. Object_.defineProperties = function (obj, pds) {
  3037. let segments, get_;
  3038. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  3039. activation = false;
  3040. segments.get = function () {
  3041. fixSegments(this);
  3042. return get_.call(this);
  3043. };
  3044. }
  3045. return Object_[dfn](obj, pds);
  3046. };
  3047.  
  3048. })();
  3049.  
  3050.  
  3051. let pf31 = new PromiseExternal();
  3052.  
  3053. // native RAF
  3054. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  3055.  
  3056. // 1st wrapped RAF
  3057. const baseRAF = (callback) => {
  3058. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  3059. pf31.then(() => {
  3060. callback(hRes);
  3061. });
  3062. });
  3063. };
  3064.  
  3065. // 2nd wrapped RAF
  3066. window.requestAnimationFrame = baseRAF;
  3067.  
  3068. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  3069. const indr = o => insp(o).$ || o.$ || 0;
  3070.  
  3071. const prototypeInherit = (d, b) => {
  3072. const m = Object.getOwnPropertyDescriptors(b);
  3073. for (const p in m) {
  3074. if (!Object.getOwnPropertyDescriptor(d, p)) {
  3075. Object.defineProperty(d, p, m[p]);
  3076. }
  3077. }
  3078. };
  3079.  
  3080.  
  3081. const firstObjectKey = (obj) => {
  3082. for (const key in obj) {
  3083. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  3084. }
  3085. return null;
  3086. };
  3087.  
  3088. function searchNestedObject(obj, predicate, maxDepth = 64) {
  3089. // normal case: depth until 36
  3090. const result = [];
  3091. const visited = new WeakSet();
  3092.  
  3093. function search(obj, depth) {
  3094. visited.add(obj);
  3095. for (const [key, value] of Object.entries(obj)) {
  3096. // Recursively search nested objects and arrays
  3097. if (value !== null && typeof value === 'object') {
  3098. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  3099. if (depth + 1 <= maxDepth && !visited.has(value)) {
  3100. search(value, depth + 1);
  3101. }
  3102. } else if (predicate(value)) {
  3103. result.push([obj, key]);
  3104. }
  3105. }
  3106. }
  3107.  
  3108. typeof (obj || 0) === 'object' && search(obj, 0);
  3109. return result;
  3110. }
  3111.  
  3112. /** @type {(o: Object | null) => WeakRef | null} */
  3113. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  3114.  
  3115. /** @type {(wr: Object | null) => Object | null} */
  3116. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  3117.  
  3118. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  3119.  
  3120. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  3121. if (DENY_requestStorageAccess) {
  3122. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  3123. Document.prototype.requestStorageAccessFor = undefined;
  3124. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  3125. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  3126. Document.prototype.requestStorageAccessFor = function () {
  3127. return new Promise((resolve, reject) => {
  3128. reject();
  3129. });
  3130. };
  3131. }
  3132. }
  3133.  
  3134. const traceStack = (stack) => {
  3135. let result = new Set();
  3136. let p = new Set();
  3137. let u = ''
  3138. for (const s of stack.split('\n')) {
  3139. if (s.split(':').length < 3) continue;
  3140. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  3141. if (!m) continue;
  3142. p.add(m[2]);
  3143. if (p.size >= 3) break;
  3144. if(!u) u = m[2];
  3145. else if(p.size === 2 && u && u=== m[2]) break;
  3146. result.add(s);
  3147. }
  3148. return [...result].join('\n');
  3149. }
  3150.  
  3151. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  3152. // window.m3bb = new Set();
  3153.  
  3154. // const smb = Symbol();
  3155. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  3156. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  3157. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  3158.  
  3159. const thisConversionFn = (thisArg) => {
  3160. if (!thisArg) return null;
  3161. const kThis = thisArg[vmb];
  3162. if (kThis) {
  3163. const ref = kThis.ref;
  3164. return (ref ? kRef(ref) : null) || null;
  3165. }
  3166. return thisArg;
  3167. }
  3168.  
  3169. const pFnHandler2 = {
  3170. get(target, prop) {
  3171. if (prop === vmc) return target;
  3172. return Reflect.get(target, prop);
  3173. },
  3174. apply(target, thisArg, argumentsList) {
  3175. thisArg = thisConversionFn(thisArg);
  3176. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  3177. }
  3178. }
  3179.  
  3180.  
  3181. const proxySelfHandler = {
  3182. get(target, prop) {
  3183. if(prop === vmb) return target;
  3184. const ref = target.ref;
  3185. const cnt = kRef(ref);
  3186. if (!cnt) return;
  3187. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  3188. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  3189. return cnt[prop][vmd];
  3190. }
  3191. return cnt[prop];
  3192. },
  3193. set(target, prop, value) {
  3194. const cnt = kRef(target.ref);
  3195. if (!cnt) return true;
  3196. if(value && (value[vmc] || value[vmb])){
  3197. cnt[prop] = value[vmc] || thisConversionFn(value);
  3198. return true;
  3199. }
  3200. cnt[prop] = value;
  3201. return true;
  3202. }
  3203. };
  3204.  
  3205. const weakWrap = (thisArg) => {
  3206. thisArg = thisConversionFn(thisArg);
  3207. if (!thisArg) {
  3208. console.error('thisArg is not found');
  3209. return null;
  3210. }
  3211. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  3212. }
  3213.  
  3214. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  3215. window.getComputedStyle533 = window.getComputedStyle;
  3216. window.getComputedStyle = function (a, ...args) {
  3217. a = thisConversionFn(a);
  3218. if (a) {
  3219. return getComputedStyle533(a, ...args);
  3220. }
  3221. return null;
  3222. }
  3223. }
  3224.  
  3225. Function._count_bind_00 = 0;
  3226. // Function._count_bind_01 = 0;
  3227.  
  3228. // let matchNativeCode = (Object+"");
  3229. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  3230. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  3231.  
  3232. // const matchConstructor = (thisArg) => {
  3233. // const f = `${(thisArg || 0).constructor}`;
  3234. // if (f.length > 45) return true;
  3235. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  3236. // if (f.includes('[native code]')){
  3237. // return false;
  3238. // }
  3239. // return true;
  3240. // }
  3241. // return false;
  3242. // }
  3243.  
  3244. // const acceptThis = (thisArg)=>{
  3245. // // if(!thisArg || typeof thisArg !=='object') return false;
  3246. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  3247. // // if(typeof thisArg.path === 'string') return true;
  3248. // // if(typeof thisArg.fn === 'function') return true;
  3249. // // if(typeof thisArg.id === 'string') return true;
  3250. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  3251. // return false;
  3252. // }
  3253.  
  3254. const patchFn = (fn) => {
  3255.  
  3256. let s = `${fn}`;
  3257. if (s.length < 11 || s.includes('\n')) return false;
  3258. if(s.includes('bind(this')) return true;
  3259. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  3260. // var a=this;
  3261. // f.bind(this)
  3262.  
  3263.  
  3264. return false;
  3265. }
  3266.  
  3267. Function.prototype.bind488 = Function.prototype.bind;
  3268. Function.prototype.bind = function(thisArg, ...args){
  3269.  
  3270. if (thisConversionFn(thisArg) !== thisArg) {
  3271. return this.bind488(thisArg, ...args);
  3272. }
  3273. if( thisArg && patchFn(this) ){
  3274.  
  3275. // console.log(599,`${this}`)
  3276.  
  3277. try {
  3278. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  3279. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  3280. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  3281. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  3282. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  3283. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  3284. // // let b4 = false;
  3285. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  3286.  
  3287. // // b3 = false;
  3288. // // b4 = false;
  3289. // // b5 = false;
  3290.  
  3291. // if (b1 || b2 || b3 ||b4 ) {
  3292. const f = this;
  3293. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  3294. if (ps && ps[vmb]) {
  3295. Function._count_bind_00++;
  3296. return f.bind488(ps, ...args)
  3297. }
  3298. // }
  3299. } catch (e) {
  3300. console.warn(e)
  3301. }
  3302. }
  3303. return this.bind488(thisArg, ...args);
  3304. }
  3305. Function.prototype.bind588 = 1;
  3306. }
  3307.  
  3308. const ytSchedulerMethods = {
  3309. addJob(a, b, c) {
  3310. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3311. if (instance) {
  3312. return instance.addJob(a, b, c);
  3313. } else {
  3314. return setTimeout(a, c);
  3315. }
  3316. },
  3317. addImmediateJob(a) {
  3318. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3319. if (instance) {
  3320. return instance.addImmediateJob(a);
  3321. } else {
  3322. a();
  3323. }
  3324. },
  3325. cancelJob(id) {
  3326. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3327. if (instance) {
  3328. return instance.cancelJob(id);
  3329. } else {
  3330. return clearTimeout(id);
  3331. }
  3332. }
  3333. };
  3334.  
  3335. if (FIX_ytScheduler) {
  3336.  
  3337. let ytSchedulerFixed = 0;
  3338. // let ytActioned = false;
  3339. // let pr = new PromiseExternal();
  3340.  
  3341. // const hn = function () {
  3342.  
  3343. // document.removeEventListener('yt-action', hn, true);
  3344. // nextBrowserTick_(() => {
  3345. // ytActioned = true;
  3346. // pr.resolve();
  3347. // });
  3348.  
  3349. // }
  3350. // document.addEventListener('yt-action', hn, true);
  3351.  
  3352. // let cancelStore = {}; // tbc
  3353.  
  3354. // yt.scheduler.instance.addJob
  3355. const fixAddJob = (nv) => {
  3356.  
  3357. /*
  3358. function Z() {
  3359. var a = w("ytglobal.schedulerInstanceInstance_");
  3360. if (!a || a.s)
  3361. a = new M(I("scheduler") || {}),
  3362. x("ytglobal.schedulerInstanceInstance_", a);
  3363. return a
  3364. }
  3365. */
  3366.  
  3367. /*
  3368. function R(a, b, c, d) {
  3369. ++a.D;
  3370. if (c === 10)
  3371. return P(a, b),
  3372. a.D;
  3373. var e = a.D;
  3374. a.h[e] = b;
  3375. a.l && !d ? a.u.push({
  3376. id: e,
  3377. priority: c
  3378. }) : (a.i[c].push(e),
  3379. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  3380. a.start()));
  3381. return e
  3382. }
  3383. */
  3384.  
  3385. /*
  3386. function sa(a, b, c) {
  3387. if (!c)
  3388. return c = c === void 0,
  3389. -R(Z(), a, b, c);
  3390. var d = window.setTimeout(function() {
  3391. var e = R(Z(), a, b);
  3392. W[d] = e
  3393. }, c);
  3394. return d
  3395. }
  3396. */
  3397. window.originalAddJob = nv;
  3398. // const q1 = new PromiseExternal();
  3399. // const q2 = new PromiseExternal();
  3400. // let uu = 0;
  3401. // let q3 = 0;
  3402. // let mof = null;
  3403. // const mo = new MutationObserver((mutation, observer) => {
  3404. // if (mof) {
  3405. // if (mof() === true) {
  3406. // observer.disconnect();
  3407. // mof = null;
  3408. // }
  3409. // }
  3410. // });
  3411.  
  3412. let lenSkip = -1;
  3413. let lastLen = null;
  3414. let fetchCommentJobTimerId = 0;
  3415. let requestFinish = false;
  3416.  
  3417. const fetchCommentJobDone = ()=>{
  3418. clearInterval(fetchCommentJobTimerId);
  3419. fetchCommentJobTimerId = 0;
  3420. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3421. }
  3422.  
  3423. const fetchCommentJob = (a, cid) => {
  3424.  
  3425. // if (cid && cancelStore[cid]) return; // tbc
  3426.  
  3427. if(fetchCommentJobTimerId > 0){
  3428. fetchCommentJobDone();
  3429. }
  3430.  
  3431. // if (mof) {
  3432. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3433. // mof = null;
  3434. // }
  3435.  
  3436. let f = a;
  3437.  
  3438. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  3439.  
  3440. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  3441.  
  3442. lastLen = -1;
  3443. let u = 0;
  3444. let g = () => {
  3445. if (requestFinish) lastLen = -1;
  3446. const lastLen_ = lastLen;
  3447. const len1 = lastLen = document.querySelectorAll(selector).length;
  3448. let mm = true;
  3449. let ff = false;
  3450. if (len1 !== lastLen_) {
  3451. u = 0;
  3452. f();
  3453. const len2 = lastLen = document.querySelectorAll(selector).length;
  3454. if (len2 !== len1) {
  3455. ff = true;
  3456. mm = false;
  3457. }
  3458. }
  3459. if (mm) {
  3460. ++u;
  3461. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  3462. ff = true;
  3463. }
  3464. }
  3465.  
  3466. if (requestFinish) {
  3467. requestFinish = false;
  3468. fetchCommentJobDone();
  3469. } else if (ff){
  3470. fetchCommentJobDone();
  3471. }
  3472.  
  3473. }
  3474.  
  3475.  
  3476. fetchCommentJobTimerId = setInterval(g, 80);
  3477. // g(9);
  3478. // if (lastLen === lenSkip) {
  3479. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3480. // g = f = null;
  3481. // return;
  3482. // }
  3483. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3484. // const q1 = lastLen;
  3485. // mof = () => {
  3486. // const q2 = document.querySelectorAll(selector).length;
  3487. // if (q1 === q2) return;
  3488. // fetchCommentJobTimerId = setTimeout(g, 80);
  3489. // g = null;
  3490. // return true;
  3491. // }
  3492. // mo.observe(document, { childList: true, subtree: true });
  3493.  
  3494. }
  3495.  
  3496. // let pr72 = Promise.resolve();
  3497.  
  3498.  
  3499. let qa = null;
  3500. let qasf = '';
  3501.  
  3502.  
  3503. document.addEventListener("fullscreenchange", (evt) => {
  3504. if (evt.isTrusted !== true) return;
  3505. if (qa) {
  3506. // qa();
  3507. nextBrowserTick_(qa);
  3508. }
  3509. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3510. // pr72 = pr72.then(() => {
  3511. // return pr
  3512. // });
  3513. }, true);
  3514.  
  3515. window.addEventListener("resize", (evt) => {
  3516. if (evt.isTrusted !== true) return;
  3517. if (qa) {
  3518. // qa();
  3519. nextBrowserTick_(qa);
  3520. }
  3521. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3522. // pr72 = pr72.then(() => {
  3523. // return pr
  3524. // });
  3525. }, true);
  3526.  
  3527.  
  3528. setInterval(() => {
  3529. const f = qa;
  3530. if (typeof f !== 'function') return;
  3531. qa = null;
  3532. // pr72 = pr72.then(() => {
  3533. // f();
  3534. // });
  3535. // nextBrowserTick_(()=>{
  3536. f();
  3537. // });
  3538. }, 475.25);
  3539.  
  3540.  
  3541.  
  3542. return function (a, b, c) {
  3543.  
  3544.  
  3545. const f = a;
  3546. // const g = ()=>{
  3547. // pr72 = pr72.then(()=>{
  3548. // f();
  3549. // });
  3550. // }
  3551.  
  3552. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  3553.  
  3554. const c_ = c;
  3555.  
  3556. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  3557.  
  3558. if (b === 1 && c_ === 500) {
  3559. const sf = `${a}`;
  3560. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  3561. qasf = sf;
  3562. qa = a;
  3563. // console.log(12883, a)
  3564. return nv(() => {
  3565. if (qa === a) {
  3566. qa = null;
  3567. a();
  3568. }
  3569. }, b, c);
  3570. }
  3571. }
  3572.  
  3573.  
  3574. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  3575. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  3576. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3577. // pr72 = pr72.then(() => {
  3578. // return pr
  3579. // });
  3580. // try {
  3581. // yt.scheduler.instance.cancelAllJobs();
  3582. // yt.scheduler.instance.dispose();
  3583. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  3584. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  3585. // } catch (e) { }
  3586. return nv(f, b, c);
  3587. }
  3588.  
  3589. // if(!b && c > 50) c = 50;
  3590. // console.log(58372,a,b,c)
  3591. // function(){xxx(xxx)}
  3592. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  3593.  
  3594. /*
  3595.  
  3596. V.setCommentsJobId = _.et(_.r0, function() {
  3597. F5V(V)
  3598. }, 1E3)
  3599.  
  3600. */
  3601.  
  3602. requestFinish = false;
  3603. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  3604.  
  3605. // lastLen = null;
  3606. fetchCommentJob(a, cid);
  3607.  
  3608. // queueMicrotask_(a);
  3609. // nextBrowserTick_(a);
  3610. // a(); // no need to delay
  3611. return cid
  3612.  
  3613. // return nv(a, b, 1.125);
  3614. // const cid = window.setTimeout(() => {
  3615. // nextBrowserTick_(() => {
  3616. // if (cancelStore[cid]) {
  3617. // console.log('task cancelled');
  3618. // return;
  3619. // }
  3620. // a();
  3621.  
  3622. // });
  3623. // }, 0.125);
  3624. // return cid;
  3625. } else {
  3626.  
  3627.  
  3628.  
  3629. return nv(f,b,c);
  3630.  
  3631.  
  3632. // if (c > 2400) c = 2400;
  3633. // else if (c > 800) c = 800;
  3634. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  3635. // if (0 && ytActioned && !b) {
  3636. // const cid = window.setTimeout(() => {
  3637. // nextBrowserTick_(() => {
  3638. // if (cancelStore[cid]) {
  3639. // console.log('task cancelled');
  3640. // return;
  3641. // }
  3642. // a();
  3643. // });
  3644. // }, c);
  3645. // return cid;
  3646. // } else {
  3647. // return nv(a, b, c);
  3648. // }
  3649.  
  3650. }
  3651. }
  3652. }
  3653.  
  3654. const fixCancelJob = (nv) => {
  3655.  
  3656.  
  3657. window.originalCancelJob = nv;
  3658. return function (a) {
  3659. if (a < 0) return nv(a);
  3660. // cancelStore[a] = true; // tbc
  3661. nv(a);
  3662. }
  3663. }
  3664.  
  3665. const sk44 = Symbol();
  3666. Object.defineProperty(Object.prototype, 'addJob', {
  3667. get() {
  3668. return this[sk44];
  3669. },
  3670. set(nv) {
  3671. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3672. ytSchedulerFixed |= 1;
  3673. nv = fixAddJob(nv);
  3674. }
  3675. this[sk44] = nv;
  3676. return true;
  3677. },
  3678. enumerable: false,
  3679. configurable: true
  3680. });
  3681.  
  3682.  
  3683.  
  3684. const sk45 = Symbol();
  3685. Object.defineProperty(Object.prototype, 'cancelJob', {
  3686. get() {
  3687. return this[sk45];
  3688. },
  3689. set(nv) {
  3690. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3691. ytSchedulerFixed |= 2;
  3692. nv = fixCancelJob(nv);
  3693. }
  3694. this[sk45] = nv;
  3695. return true;
  3696. },
  3697. enumerable: false,
  3698. configurable: true
  3699. });
  3700.  
  3701.  
  3702.  
  3703. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3704. const { addJob, cancelJob } = yt.scheduler.instance;
  3705. if (addJob) {
  3706. yt.scheduler.instance.addJob = null;
  3707. yt.scheduler.instance.addJob = addJob;
  3708. }
  3709. if (cancelJob) {
  3710. yt.scheduler.instance.cancelJob = null;
  3711. yt.scheduler.instance.cancelJob = cancelJob;
  3712. }
  3713. }
  3714.  
  3715.  
  3716. }
  3717.  
  3718. const isWatchPageURL = (url) => {
  3719. url = url || location;
  3720. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  3721. };
  3722.  
  3723. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3724.  
  3725. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  3726. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3727. if (typeof customElements === 'undefined') {
  3728. if (!('__CE_registry' in document)) {
  3729. // https://github.com/webcomponents/polyfills/
  3730. Object.defineProperty(document, '__CE_registry', {
  3731. get() {
  3732. // return undefined
  3733. },
  3734. set(nv) {
  3735. if (typeof nv == 'object') {
  3736. delete this.__CE_registry;
  3737. this.__CE_registry = nv;
  3738. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3739. }
  3740. return true;
  3741. },
  3742. enumerable: false,
  3743. configurable: true
  3744. })
  3745. }
  3746. let eventHandler = (evt) => {
  3747. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3748. const f = callback;
  3749. callback = null;
  3750. eventHandler = null;
  3751. f();
  3752. };
  3753. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3754. } else {
  3755. callback();
  3756. }
  3757. });
  3758.  
  3759. const whenCEDefined = isCustomElementsProvided
  3760. ? (nodeName) => customElements.whenDefined(nodeName)
  3761. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3762.  
  3763. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  3764. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  3765. const f = performance.now23 = Performance.prototype.now;
  3766.  
  3767. let k = 0; // 0 <= k < 9998m
  3768. let u = 0;
  3769. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  3770.  
  3771. // By definition, performance.now() is mono increasing.
  3772. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  3773. performance.now = performance.now16 = function () {
  3774. /**
  3775. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  3776. *
  3777. * If consecutive session history entries had history.state.entryTime set to same value,
  3778. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  3779. * and modifying its return value slightly to make sure two close consecutive calls don't
  3780. * get the same result helped with resolving the issue.
  3781. */
  3782. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  3783. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  3784.  
  3785. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  3786. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  3787. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  3788. else { // more than 9998 consecutive calls
  3789. /**
  3790. *
  3791. * max no. of consecutive calls
  3792. *
  3793. * Sample Size: 4800
  3794. * Sample Avg = 1565.375
  3795. * Sample Median = 1469.5
  3796. * Sample Max = 5660 << 7500 << 9999
  3797. *
  3798. *
  3799. * */
  3800. k = 0;
  3801. s += 1 / 7;
  3802. }
  3803. return v + k; // 0 < v - M < v - M + k < v
  3804. }
  3805.  
  3806. let loggerMsg = '';
  3807. if (`${performance.now()}` === `${performance.now()}`) {
  3808. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  3809. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  3810. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  3811. }
  3812. loggerMsg && console.warn(loggerMsg);
  3813. })();
  3814.  
  3815. // let __forceRemoveMode__ = false;
  3816. FIX_removeChild && (() => {
  3817. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  3818. let internalByPass = false;
  3819. const fragD = document.createDocumentFragment();
  3820. fragD.appendChild4201 = fragD.appendChild;
  3821. fragD.removeChild4201 = fragD.removeChild;
  3822. Node.prototype.removeChild062 = Node.prototype.removeChild;
  3823. Node.prototype.removeChild = function (child) {
  3824. try {
  3825. return this.removeChild062(child);
  3826. } catch (e) { }
  3827. if (internalByPass) return child;
  3828. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  3829. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3830. if (idx >= 0) {
  3831. internalByPass = true;
  3832. child.parentNode !== fragD && fragD.appendChild4201(child);
  3833. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3834. fragD.removeChild4201(child);
  3835. internalByPass = false;
  3836. return child;
  3837. }
  3838. }
  3839. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  3840. // // force removal
  3841. // internalByPass = true;
  3842. // child.parentNode !== fragD && fragD.appendChild4201(child);
  3843. // fragD.removeChild4201(child);
  3844. // internalByPass = false;
  3845. // return child;
  3846. // }
  3847. if (this && child) {
  3848. if (this.childNodes && this.childNodes.splice) { // tbc
  3849. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3850. if (idx >= 0) {
  3851. internalByPass = true;
  3852. child.parentNode !== fragD && fragD.appendChild4201(child);
  3853. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3854. fragD.removeChild4201(child);
  3855. internalByPass = false;
  3856. return child;
  3857. }
  3858. }
  3859.  
  3860. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  3861. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  3862. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  3863. return child;
  3864. }
  3865. }
  3866.  
  3867. if (child && child.is === 'tp-yt-paper-tooltip' && !child.parentNode && !child.__shady_parentNode) {
  3868. // skip
  3869. return child;
  3870. }
  3871.  
  3872. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  3873. parent: this, child: child,
  3874. isParent: child.parentNode === this,
  3875. isParentParent: (child.parentNode || 0).parentNode === this,
  3876. parentNode: child.parentNode,
  3877. shadyParent: child.__shady_parentNode,
  3878. isShadyParent: child.__shady_parentNode === this,
  3879. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  3880. });
  3881.  
  3882. }
  3883. return child;
  3884. }
  3885. }
  3886. })();
  3887.  
  3888.  
  3889. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  3890.  
  3891. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  3892.  
  3893. // let cid = 0;
  3894.  
  3895. let mousemoveFn = null;
  3896. let mousemoveDT = 0;
  3897. let mousemoveCount = 0;
  3898. // let qv = false;
  3899. const cif = () => {
  3900. if (!mousemoveFn) return;
  3901. const ct = Date.now();
  3902. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  3903. mousemoveFn && mousemoveFn();
  3904. }
  3905. mousemoveFn = null;
  3906. };
  3907. let mousemoveCId = 0;
  3908. let mouseoverFn = null;
  3909. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  3910. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  3911. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  3912. const bt = `${b}`;
  3913. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  3914. b[`__$$${a}$$1926__`] = true;
  3915. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  3916. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  3917. // console.log(3928, a, this[`__$$${a}$$1937__`])
  3918. if (!this[`__$$${a}$$1938__`]) {
  3919. this[`__$$${a}$$1938__`] = b;
  3920. if (a === 'mousemove') {
  3921. this.addEventListener4882('mouseenter', (evt) => {
  3922. if (mousemoveCId) return;
  3923. mousemoveCId = setIntervalX0(cif, 380);
  3924. });
  3925. this.addEventListener4882('mouseleave', (evt) => {
  3926. clearIntervalX0(mousemoveCId);
  3927. mousemoveCId = 0;
  3928. });
  3929. }
  3930. this.addEventListener4882(a, (evt) => {
  3931. const evt_ = evt;
  3932. if (!this[`__$$${a}$$1937__`]) return;
  3933. if (!this[`__$$${a}$$1938__`]) return;
  3934. if (a === 'mousemove') {
  3935. mouseoverFn && mouseoverFn();
  3936. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  3937. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  3938. } else {
  3939. mousemoveCount = 0;
  3940. }
  3941. const f = mousemoveFn = () => {
  3942. if (f !== mousemoveFn) return;
  3943. mousemoveFn = null;
  3944. this[`__$$${a}$$1938__`](evt_);
  3945. };
  3946. if (mousemoveCount <= 1) mousemoveFn();
  3947. } else {
  3948. if (a === 'mouseout' || a === 'mouseleave') {
  3949. mousemoveFn = null;
  3950. mousemoveDT = 0;
  3951. mousemoveCount = 0;
  3952. this[`__$$${a}$$1938__`](evt_);
  3953. mouseoverFn && mouseoverFn();
  3954. } else { // mouseover, mouseenter
  3955. mousemoveFn = null;
  3956. mousemoveDT = 0;
  3957. mousemoveCount = 0;
  3958. mouseoverFn && mouseoverFn(); // just in case
  3959. const f = mouseoverFn = () => {
  3960. if (f !== mouseoverFn) return;
  3961. mouseoverFn = null;
  3962. this[`__$$${a}$$1938__`](evt_);
  3963. }
  3964. nextBrowserTick_(mouseoverFn);
  3965. }
  3966. }
  3967. }, c);
  3968.  
  3969.  
  3970. return;
  3971. } else {
  3972.  
  3973. return;
  3974. }
  3975. }
  3976.  
  3977. }
  3978. return this.addEventListener4882(a, b, c)
  3979. }
  3980.  
  3981.  
  3982.  
  3983.  
  3984. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  3985. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  3986. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  3987.  
  3988. if (b[`__$$${a}$$1926__`]) {
  3989. b[`__$$${a}$$1926__`] = false;
  3990.  
  3991. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  3992.  
  3993. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  3994.  
  3995. return;
  3996.  
  3997. }
  3998.  
  3999. }
  4000. return this.removeEventListener4882(a, b, c)
  4001. }
  4002.  
  4003.  
  4004. })();
  4005.  
  4006.  
  4007. FIX_DOM_IF_REPEAT && (() => {
  4008. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4009. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  4010. // Be careful of the mixture of polymer functions and native Element functions
  4011. // Be careful of the coding design is different with the modern Yt elements
  4012.  
  4013.  
  4014. /*
  4015.  
  4016.  
  4017. function Ks(a, b, c) {
  4018. if (kj && !BOa(a))
  4019. throw Error("strictTemplatePolicy: template owner not trusted");
  4020. c = c || {};
  4021. if (a.__templatizeOwner)
  4022. throw Error("A <template> can only be templatized once");
  4023. a.__templatizeOwner = b;
  4024. var d = (b ? b.constructor : Js)._parseTemplate(a)
  4025. , e = d.templatizeInstanceClass;
  4026. e || (e = COa(a, d, c),
  4027. d.templatizeInstanceClass = e);
  4028. var g = BOa(a);
  4029. EOa(a, d, c, g);
  4030. c = function() {
  4031. return e.apply(this, arguments) || this
  4032. }
  4033. ;
  4034. h(c, e);
  4035. c.prototype._methodHost = g;
  4036. c.prototype.__dataHost = a;
  4037. c.prototype.__templatizeOwner = b;
  4038. c.prototype.__hostProps = d.hostProps;
  4039. return c
  4040. }
  4041.  
  4042. */
  4043.  
  4044. // Polymer.enqueueDebouncer
  4045.  
  4046. const s81 = Symbol();
  4047. const s83 = Symbol();
  4048. const s84 = Symbol();
  4049. const s85 = Symbol();
  4050. const s85b = Symbol();
  4051. const s85c = Symbol();
  4052.  
  4053. let renderDebounceTs = null;
  4054.  
  4055. let renderDebouncePromise = null;
  4056. let qp;
  4057.  
  4058. const shadyFlushMO = new MutationObserver(() => {
  4059.  
  4060. if (!renderDebounceTs) return;
  4061.  
  4062. if (renderDebounceTs.size > 0) {
  4063. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  4064. try {
  4065. Polymer.flush();
  4066. return;
  4067. } catch (e) { }
  4068. }
  4069.  
  4070. renderDebouncePromise && Promise.resolve().then(() => {
  4071.  
  4072. if (renderDebouncePromise) {
  4073. renderDebouncePromise && renderDebouncePromise.resolve();
  4074. renderDebouncePromise = null;
  4075. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  4076. }
  4077.  
  4078. });
  4079.  
  4080. // Polymer.flush
  4081.  
  4082. window.ShadyDOM && ShadyDOM.flush();
  4083. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  4084.  
  4085.  
  4086. });
  4087.  
  4088. const setupPolymerAdv = () => {
  4089. // here we can obtain the Polymer faster.
  4090. // reserved for future use.
  4091. }
  4092.  
  4093.  
  4094. if (USE_fastDomIf) {
  4095. // 0 = no effect. 1 = enable. 2 = disable
  4096. // fastDomIf because it delayed the rendering process?
  4097. Object.defineProperty(Object.prototype, 'fastDomIf', {
  4098. get() {
  4099. if (this === window.Polymer) {
  4100. const v = USE_fastDomIf === 1 ? true : false;
  4101. this.fastDomIf = v;
  4102. delete Object.prototype.fastDomIf;
  4103. setupPolymerAdv(this);
  4104. return v;
  4105. }
  4106. },
  4107. set(nv) {
  4108. return false;
  4109. }
  4110. });
  4111. }
  4112.  
  4113. let setupDomIfDone = false;
  4114. const setupDomIf = (DomIf)=>{
  4115. setupDomIfDone = true;
  4116. if(setupDomIfDone) return;
  4117.  
  4118. const fProto = DomIf.prototype;
  4119.  
  4120.  
  4121. // Polymer.DomIf
  4122. // Polymer.DomIf = Polymer.fastDomIf ? ZbL : ESz
  4123. // Assume ESz by default
  4124.  
  4125. // We don't need to store "root" in DOM-IF
  4126. if (ENHANCE_DOMIF_createAndInsertInstance && fProto.__createAndInsertInstance && !fProto.__createAndInsertInstance239 && fProto.__createAndInsertInstance.length === 1) {
  4127. fProto.__createAndInsertInstance239 = fProto.__createAndInsertInstance;
  4128. fProto.__createAndInsertInstance = function (M) {
  4129. const r = this.__createAndInsertInstance239(M);
  4130. const __instance = this.__instance;
  4131. const __ctor = this.__ctor;
  4132. if (__instance && __ctor && __instance instanceof __ctor) {
  4133. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4134. const o = __instance[sym];
  4135. if (o && o.nodeType === 11) {
  4136. __instance[sym] = null;
  4137. }
  4138. }
  4139. }
  4140. return r;
  4141. }
  4142.  
  4143. /*
  4144.  
  4145.  
  4146. sX = function(M, d, N) {
  4147. if (o_ && !vDv(M))
  4148. throw Error("Jd");
  4149. N = N || {};
  4150. if (M.__templatizeOwner)
  4151. throw Error("Kd");
  4152. M.__templatizeOwner = d;
  4153. var R = (d ? d.constructor : jF)._parseTemplate(M)
  4154. , X = R.templatizeInstanceClass;
  4155. X || (X = sfi(M, R, N),
  4156. R.templatizeInstanceClass = X);
  4157. var A = vDv(M);
  4158. y9Z(M, R, N, A);
  4159. N = function() {
  4160. return X.apply(this, arguments) || this
  4161. }
  4162. ;
  4163. _.v(N, X);
  4164. N.prototype._methodHost = A;
  4165. N.prototype.__dataHost = M;
  4166. N.prototype.__templatizeOwner = d;
  4167. N.prototype.__hostProps = R.hostProps;
  4168. return N
  4169. }
  4170.  
  4171. */
  4172. }
  4173.  
  4174. // Polymer.DomIf
  4175. // We can fully teardown the entire instance (including stampFrag and stampNodes), just keep ctor stamper
  4176. if (ENHANCE_DOMIF_TEARDOWN && fProto.__teardownInstance && !fProto.__teardownInstance239 && fProto.__teardownInstance.length === 0) {
  4177. fProto.__teardownInstance239 = fProto.__teardownInstance;
  4178. fProto.__teardownInstance = function () {
  4179. const { __instance, __invalidProps } = this;
  4180. let r, e_;
  4181. try {
  4182. r = this.__teardownInstance239();
  4183. } catch (e) { e_ = e }
  4184. if (!__instance) return r;
  4185.  
  4186. try {
  4187.  
  4188. //console.log(599901,this.countEvent767());
  4189. //console.log('__teardownInstance F', __instance, __invalidProps, this._removeEventListenerFromNode, __instance._removeEventListenerFromNode);
  4190. __instance.__data = null;
  4191. __instance.__dataClientsReady = __instance.__dataEnabled = __instance.__dataReady = false;
  4192. __instance.__dataInvalid = true;
  4193. __instance.__dataHost = __instance.__dataTemp = null;
  4194. __instance.__isPropertyEffectsClient = false;
  4195. __instance.__keepInstance038__ = false;
  4196.  
  4197.  
  4198. const __templateInfo = __instance.__templateInfo;
  4199.  
  4200. let stampFragId = null;
  4201. if (__templateInfo && __templateInfo.nodeList) {
  4202. stampFragId = __templateInfo.nodeList.__belongFragId57__;
  4203. for (const weakNodeC of __templateInfo.nodeList) {
  4204. const node = toActualNode(weakNodeC);
  4205. if (node && node.nodeType >= 1) {
  4206. renderPathMake(node)
  4207. node.__keepInstance038__ = false;
  4208. node.remove();
  4209. _removedElements.addNode(node); // rn54011
  4210. }
  4211. }
  4212. __templateInfo.nodeList.length = 0;
  4213. __templateInfo.nodeList = null;
  4214. }
  4215.  
  4216. const stampFrag = stampFragId ? kRef(stampedFragment.get(stampFragId)) : null;
  4217.  
  4218. if (stampFrag && stampFrag.nodeType === 11) {
  4219. stampFrag.__keepInstance038__ = false;
  4220. _removedElements.addNode(stampFrag); // rn54012
  4221. removeAllChildNodes(stampFrag);
  4222. try {
  4223. stampFrag.remove();
  4224. } catch (e) { }
  4225. stampFrag.__shady = null;
  4226. stampFrag.$ = null;
  4227. stampFrag.__fragTeardowned57__ = true;
  4228. stampFrag.nodeList = null;
  4229. stampFrag.templateInfo = null;
  4230.  
  4231. }
  4232.  
  4233. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4234. const o = __instance[sym];
  4235. if (o && o.nodeType === 11) {
  4236. __instance[sym] = null;
  4237. }
  4238. }
  4239.  
  4240. const children = (__instance || 0).children;
  4241. if (children && children.splice) {
  4242. __instance.children = null;
  4243. for (const n of children) {
  4244. if (n && n.nodeType >= 1) {
  4245. n.__keepInstance038__ = false;
  4246. _removedElements.addNode(n); // rn54013
  4247. }
  4248. }
  4249. children.length = 0;
  4250. }
  4251.  
  4252. if (__instance.__templateInfo) __instance.__templateInfo = null;
  4253.  
  4254. if (__instance.root) __instance.root = null;
  4255.  
  4256. } catch (e) {
  4257. console.error(e);
  4258. }
  4259.  
  4260. // console.log(3882)
  4261. if (e_) throw e_;
  4262. return r;
  4263. }
  4264. }
  4265.  
  4266. }
  4267.  
  4268. if (ENHANCE_DOMIF_createAndInsertInstance || ENHANCE_DOMIF_TEARDOWN) {
  4269.  
  4270. Object.defineProperty(Object.prototype, 'DomIf', {
  4271. get() {
  4272. return undefined;
  4273. },
  4274. set(nv) {
  4275. if (typeof (nv || 0) !== 'function') return false;
  4276. delete Object.prototype.DomIf;
  4277. this.DomIf = nv;
  4278. setupDomIf(nv);
  4279. return true;
  4280. },
  4281. enumerable: false,
  4282. configurable: true
  4283. });
  4284.  
  4285. }
  4286.  
  4287. Object.defineProperty(Object.prototype, '_lastIf', {
  4288. get() {
  4289. return this[s81];
  4290. },
  4291. set(nv) {
  4292. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  4293. // DOM-IF initialization
  4294. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  4295.  
  4296. this.__xiWB8__ = 2;
  4297. // this.restamp = true;
  4298.  
  4299. const cProto = this.__proto__;
  4300. if (cProto && !cProto.__xiWB7__) {
  4301. cProto.__xiWB7__ = 1;
  4302.  
  4303. // dom-if __template
  4304. // dom-repeat template
  4305. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  4306. cProto.__template847 = true;
  4307. try {
  4308. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  4309. Object.defineProperty(cProto, '__template', {
  4310. get() {
  4311. const v = this[s84];
  4312. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  4313. },
  4314. set(nv) {
  4315. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  4316. this[s84] = nv;
  4317. return true;
  4318. }
  4319. });
  4320. } catch (e) {
  4321. console.warn(e);
  4322. }
  4323.  
  4324. console.log('FIX_DOM_IF - __template')
  4325. }
  4326.  
  4327. // dom-if __ensureTemplate
  4328. // dom-repeat __ensureTemplatized
  4329. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  4330. // note that "_templateInfo" diffs the different version of DOM-IF
  4331.  
  4332. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  4333. cProto.__ensureTemplate = function () {
  4334. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  4335. if (!this.__template) {
  4336. let b;
  4337. if (this._templateInfo) {
  4338. b = this;
  4339. } else {
  4340. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  4341. b = this.__templateCollection011__[0];
  4342. if (!b) {
  4343. if (!this[wk]) this[wk] = mWeakRef(this);
  4344. let a = this[wk];
  4345. let c = new MutationObserver(function () {
  4346. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  4347. if (c && a) {
  4348. c.disconnect();
  4349. a = kRef(a);
  4350. a && a.__render();
  4351. a && (a.__templateCollection011__ = null);
  4352. }
  4353. c = null;
  4354. a = null;
  4355. });
  4356. c && c.observe(this, {
  4357. childList: !0
  4358. });
  4359. return !1
  4360. } else {
  4361. this.__templateCollection011__ = null;
  4362. }
  4363. }
  4364. this.__template = b
  4365. }
  4366. return !0
  4367. }
  4368.  
  4369. console.log('FIX_DOM_IF - __ensureTemplate')
  4370.  
  4371. }
  4372.  
  4373.  
  4374. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  4375. }
  4376.  
  4377.  
  4378. // need to fix __observeEffects
  4379. // this.__observeEffects.if[0].info.method === this.__debounceRender
  4380. const f = () => {
  4381.  
  4382. const __observeEffects = this.__observeEffects;
  4383.  
  4384. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  4385. for (const effect of __observeEffects.if) {
  4386. const info = effect.info;
  4387. if (info && typeof info.method === 'function') {
  4388.  
  4389. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4390. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4391. }
  4392.  
  4393. }
  4394. }
  4395. }
  4396.  
  4397.  
  4398. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  4399. for (const effect of __observeEffects.restamp) {
  4400. const info = effect.info;
  4401. if (info && typeof info.method === 'function') {
  4402.  
  4403. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4404. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4405. }
  4406.  
  4407. }
  4408. }
  4409. }
  4410.  
  4411. // console.log(5881, this.__observeEffects)
  4412. }
  4413.  
  4414. }
  4415. this[s81] = nv;
  4416. return true;
  4417. }
  4418. });
  4419.  
  4420.  
  4421. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  4422. get() {
  4423. return this[s85];
  4424. },
  4425. set(nv) {
  4426. if (nv === null && this[s85] === undefined) {
  4427. // DOM-IF / DOM-REPEAT initialization
  4428.  
  4429.  
  4430. const cProto = this.__proto__;
  4431. if (qp) {
  4432. qp.obtain();
  4433. qp = null;
  4434. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  4435. }
  4436.  
  4437. }
  4438. this[s85] = nv;
  4439. return true;
  4440. }
  4441. });
  4442.  
  4443. // PS-DOM-REPEAT
  4444.  
  4445. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  4446. get() {
  4447. return this[s85b];
  4448. },
  4449. set(nv) {
  4450.  
  4451. this[s85b] = nv;
  4452. return true;
  4453. }
  4454. })
  4455.  
  4456. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  4457. get() {
  4458. return this[s85c];
  4459. },
  4460. set(nv) {
  4461.  
  4462. this[s85c] = nv;
  4463. return true;
  4464. }
  4465. })
  4466.  
  4467.  
  4468. })();
  4469.  
  4470. const setupXdeadC = (cnt)=>{
  4471.  
  4472. let xdeadc = xdeadc00;
  4473. if(!xdeadc){
  4474. setupSDomWrapper(); // just in case
  4475. const hostElement = cnt.hostElement;
  4476. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4477. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4478. hostElement.lastChild.replaceWith(el);
  4479. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4480. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4481. el.firstElementChild.id = rid;
  4482. cnt.$[rid] = el.firstElementChild;
  4483. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4484.  
  4485. xdeadc = cnt.getStampContainer_(rid);
  4486. el.remove();
  4487. xdeadc00 = xdeadc;
  4488. // console.log(xdeadc.__domApi)
  4489. // debugger;
  4490. // const xdeadv = xdeadc.__domApi;
  4491. }
  4492.  
  4493. let xlivec = xlivec00;
  4494. if(!xlivec){
  4495. setupSDomWrapper(); // just in case
  4496. const hostElement = cnt.hostElement;
  4497. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4498. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4499. hostElement.lastChild.replaceWith(el);
  4500. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4501. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4502. el.firstElementChild.id = rid;
  4503. cnt.$[rid] = el.firstElementChild;
  4504. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4505.  
  4506. xlivec = cnt.getStampContainer_(rid);
  4507. xlivec00 = xlivec;
  4508. // console.log(xdeadc.__domApi)
  4509. // debugger;
  4510. // const xdeadv = xdeadc.__domApi;
  4511. }
  4512.  
  4513. return xdeadc00;
  4514. }
  4515.  
  4516. let standardWrap_ = null;
  4517.  
  4518. const setupSDomWrapper = () => {
  4519.  
  4520. const sdwProto = ShadyDOM.Wrapper.prototype;
  4521.  
  4522. if (sdwProto.__pseudo__isConnected__ !== null) {
  4523. sdwProto.__pseudo__isConnected__ = null;
  4524. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  4525. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  4526. const get = isConnectedPd.get;
  4527. isConnectedPd.get = function () {
  4528. const pseudoVal = this.__pseudo__isConnected__;
  4529. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  4530. }
  4531. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  4532. }
  4533.  
  4534. // debugger;
  4535. // new xdeadc.__domApi.constructor(document.createElement('div'));
  4536. }
  4537.  
  4538. }
  4539.  
  4540. let domApiConstructor = null;
  4541. const setupDomApi = (daProto) => {
  4542.  
  4543. daProto.__daHook377__ = true;
  4544.  
  4545. domApiConstructor = daProto.constructor; // TBC
  4546.  
  4547. // TBC
  4548.  
  4549. }
  4550.  
  4551.  
  4552. // WEAKREF_ShadyDOM
  4553.  
  4554. let mightTeardownShadyDomWrap = () => { };
  4555.  
  4556. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  4557.  
  4558. const setupPlainShadyDOM = (b) => {
  4559. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  4560. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  4561. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  4562. b.patchOnDemand = true;
  4563. b.preferPerformance = true;
  4564. b.noPatch = true;
  4565. }
  4566.  
  4567. const isPlainObject = (b, m) => {
  4568. if (!b || typeof b !== 'object') return false;
  4569. const e = Object.getOwnPropertyDescriptors(b);
  4570. if (e.length <= m) return false;
  4571. let pr = 0;
  4572. for (const k in e) {
  4573. const d = e[k];
  4574. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  4575. if (!('value' in d) || typeof d.value === 'function') return false;
  4576. pr++;
  4577. }
  4578. return pr > m;
  4579. }
  4580.  
  4581. let b;
  4582.  
  4583. let lz = 0;
  4584.  
  4585. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  4586. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  4587.  
  4588. // Brave - ShadyDOM exists before userscripting
  4589. b = sdp.value;
  4590.  
  4591. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  4592. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  4593. lz = 1;
  4594. }
  4595.  
  4596. }
  4597.  
  4598.  
  4599. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  4600. } else if (!sdp) {
  4601. } else {
  4602. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  4603. return;
  4604. }
  4605.  
  4606. const shadyDOMNodeWRM = new WeakMap();
  4607.  
  4608. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  4609.  
  4610. const weakWrapperNodeHandlerFn = () => ({
  4611. get() {
  4612. const wv = this[wk];
  4613. if (typeof wv === 'undefined') return undefined;
  4614. let node = kRef(wv);
  4615. if (!node) this[wk] = undefined;
  4616. return node || undefined;
  4617. },
  4618. set(nv) {
  4619. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  4620. this[wk] = wv;
  4621. return true;
  4622. },
  4623. enumerable: true,
  4624. configurable: true
  4625. });
  4626.  
  4627.  
  4628. function weakWrapper(_ShadyDOM) {
  4629. const ShadyDOM = _ShadyDOM;
  4630. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  4631. let nullElement = { node: null };
  4632. Object.setPrototypeOf(nullElement, Element.prototype);
  4633. let p = new ShadyDOM.Wrapper(nullElement);
  4634. let d = Object.getOwnPropertyDescriptor(p, 'node');
  4635. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  4636. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  4637. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  4638. }
  4639.  
  4640. }
  4641. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  4642. try {
  4643. setupSDomWrapper();
  4644. } catch (e) { }
  4645. }
  4646.  
  4647. }
  4648.  
  4649. let previousWrapStore = null;
  4650.  
  4651. mightTeardownShadyDomWrap = (node) => {
  4652. if (previousWrapStore) previousWrapStore.delete(node);
  4653. if (shadyDOMNodeWRM) shadyDOMNodeWRM.delete(node);
  4654. };
  4655.  
  4656. const standardWrap = function (a) {
  4657. if (a instanceof WeakNodeC) a = a.getNode592177();
  4658. // if(a && a.deref) a= a.deref();
  4659. if(!a) return a;
  4660. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  4661. if (previousWrapStore) {
  4662. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  4663. if (s) {
  4664. previousWrapStore.delete(a);
  4665. shadyDOMNodeWRM.set(a, mWeakRef(s));
  4666. }
  4667. }
  4668. let u = kRef(shadyDOMNodeWRM.get(a));
  4669. if (!u) {
  4670. u = new ShadyDOM.Wrapper(a);
  4671. shadyDOMNodeWRM.set(a, mWeakRef(u));
  4672. }
  4673. return u;
  4674. }
  4675.  
  4676. standardWrap_ = standardWrap;
  4677.  
  4678.  
  4679. function setupWrapFunc(_ShadyDOM) {
  4680. const ShadyDOM = _ShadyDOM;
  4681.  
  4682.  
  4683. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  4684. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  4685. return;
  4686. }
  4687. let mm = new Set();
  4688. const pget = wmPD.value;
  4689. WeakMap.prototype.get = function (a) {
  4690. mm.add(this);
  4691. return a;
  4692. }
  4693. try {
  4694. let nullElement = { node: null };
  4695. Object.setPrototypeOf(nullElement, Element.prototype);
  4696. ShadyDOM.wrapIfNeeded(nullElement)
  4697. ShadyDOM.wrap(nullElement)
  4698. } catch (e) { }
  4699. WeakMap.prototype.get = pget;
  4700. if (mm.size !== 1) {
  4701. mm.clear();
  4702. return;
  4703. }
  4704. const p = mm.values().next().value;
  4705. if (!(p instanceof WeakMap)) return;
  4706. // p.clear();
  4707. // p.get = function (a) { return a }
  4708. // p.set = function (a, b) { return this }
  4709. // console.log(188, window.n2n = mm, window.n2p = p)
  4710.  
  4711. // console.log(34929,p.size)
  4712. previousWrapStore = p;
  4713.  
  4714. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  4715. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  4716. }
  4717. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  4718. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  4719. }
  4720.  
  4721. }
  4722.  
  4723. function setupLZ3(nv) {
  4724.  
  4725. const ShadyDOM = nv;
  4726.  
  4727. const ShadyDOMSettings = ShadyDOM.settings;
  4728. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4729. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4730. return false;
  4731. }
  4732.  
  4733. weakWrapper(ShadyDOM);
  4734.  
  4735. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4736.  
  4737. setupPlainShadyDOM(ShadyDOMSettings);
  4738. setupPlainShadyDOM(ShadyDOM);
  4739.  
  4740. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  4741.  
  4742. setupWrapFunc(ShadyDOM);
  4743. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  4744. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  4745.  
  4746. // To be confirmed
  4747. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  4748. ShadyDOM.composedPath = function (e) {
  4749. const t = (e || 0).target || null;
  4750. if (!(t instanceof HTMLElement_)) {
  4751. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  4752. }
  4753. return t instanceof HTMLElement_ ? [t] : [];
  4754. };
  4755. }
  4756.  
  4757. }
  4758.  
  4759. }
  4760.  
  4761.  
  4762. function setupLZ6(nv) {
  4763.  
  4764. const ShadyDOM = nv;
  4765.  
  4766. const ShadyDOMSettings = ShadyDOM.settings;
  4767.  
  4768. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4769. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4770. return false;
  4771. }
  4772.  
  4773. weakWrapper(ShadyDOM);
  4774.  
  4775. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4776.  
  4777. setupPlainShadyDOM(ShadyDOMSettings);
  4778. setupPlainShadyDOM(ShadyDOM);
  4779.  
  4780. setupWrapFunc(ShadyDOM);
  4781.  
  4782. }
  4783.  
  4784. }
  4785.  
  4786. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  4787.  
  4788. const nv = b;
  4789.  
  4790. if (setupLZ6(nv) === false) return;
  4791.  
  4792. lz = 6;
  4793.  
  4794. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  4795.  
  4796. return;
  4797. }
  4798.  
  4799. delete window.ShadyDOM;
  4800.  
  4801. Object.defineProperty(window, 'ShadyDOM', {
  4802. get() {
  4803. return b;
  4804. },
  4805. set(nv) {
  4806. let ret = 0;
  4807. try {
  4808. do {
  4809. if (!nv || !nv.settings) {
  4810. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  4811. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  4812. lz = 1;
  4813. break;
  4814. } else {
  4815. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  4816. break;
  4817. }
  4818. }
  4819.  
  4820. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  4821. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  4822. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  4823. break;
  4824. }
  4825.  
  4826. if (setupLZ3(nv) === false) break;
  4827.  
  4828. lz = 3;
  4829.  
  4830. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  4831.  
  4832. ret = 1;
  4833.  
  4834. } while (0);
  4835. } catch (e) {
  4836. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  4837. }
  4838.  
  4839. if (!ret) b = nv;
  4840. else {
  4841. delete this.ShadyDOM;
  4842. this.ShadyDOM = nv;
  4843. }
  4844. return true;
  4845. },
  4846. enumerable: false,
  4847. configurable: true
  4848. });
  4849.  
  4850. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  4851.  
  4852. if (ENABLE_ASYNC_DISPATCHEVENT) {
  4853. const filter = new Set([
  4854. 'yt-action',
  4855. // 'iframe-src-replaced',
  4856. 'shown-items-changed',
  4857. 'can-show-more-changed', 'collapsed-changed',
  4858.  
  4859. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  4860. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  4861. 'yt-navigate-finish',
  4862.  
  4863. // 'data-changed','yt-watch-comments-ready'
  4864. ])
  4865. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  4866. EventTarget.prototype.dispatchEvent = function (event) {
  4867. const type = (event || 0).type;
  4868. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  4869. if (!filter.has(type) && !type.endsWith('-changed')) {
  4870. if (this instanceof Node || this instanceof Window) {
  4871. nextBrowserTick_(() => this.dispatchEvent938(event));
  4872. return true;
  4873. }
  4874. }
  4875. }
  4876. return this.dispatchEvent938(event);
  4877. }
  4878. }
  4879.  
  4880. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  4881. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  4882. // const xhr = new XMLHttpRequest;
  4883. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  4884. if (!pdOri || pdOri.configurable !== true) return;
  4885. let propNeedles = null;
  4886. const pdNew = {
  4887. configurable: true,
  4888. enumerable: true,
  4889. get: function () {
  4890. propNeedles = this;
  4891. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  4892. throw new Error();
  4893. }
  4894. }
  4895. Object.defineProperty(Map.prototype, 'size', pdNew);
  4896. try {
  4897. XMLHttpRequest.prototype.open.call(0);
  4898. // xhr.open.call(null)
  4899. } catch (e) { }
  4900. Object.defineProperty(Map.prototype, 'size', pdOri);
  4901. if (!propNeedles) return;
  4902. const entries = [...propNeedles.entries()];
  4903. propNeedles.clear();
  4904. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  4905. })();
  4906.  
  4907. if (FIX_XHR_REQUESTING) {
  4908.  
  4909. const URL = window.URL || new Function('return URL')();
  4910. const createObjectURL = URL.createObjectURL.bind(URL);
  4911.  
  4912. XMLHttpRequest = (() => {
  4913. const XMLHttpRequest_ = XMLHttpRequest;
  4914. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  4915. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  4916. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  4917. constructor(...args) {
  4918. super(...args);
  4919. }
  4920. open(method, url, ...args) {
  4921. let skip = false;
  4922. if (!url || typeof url !== 'string') skip = true;
  4923. else if (typeof url === 'string') {
  4924. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  4925. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  4926. skip = true;
  4927. } else if (turl.includes('.youtube.com/pagead/')) {
  4928. skip = true;
  4929. } else if (turl.includes('.youtube.com/ptracking')) {
  4930. skip = true;
  4931. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  4932. skip = true;
  4933. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  4934. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  4935. skip = true;
  4936. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  4937. skip = true;
  4938. } else {
  4939. // skip = true; // for user activity logging e.g. watched videos
  4940. }
  4941. } else if (turl.includes('play.google.com/log')) {
  4942. skip = true;
  4943. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  4944. skip = true;
  4945. }
  4946. }
  4947. if (!skip) {
  4948. this.__xmMc8__ = 1;
  4949. return super.open(method, url, ...args);
  4950. } else {
  4951. this.__xmMc8__ = 2;
  4952. return super.open('GET', url0);
  4953. }
  4954. }
  4955. send(...args) {
  4956. if (this.__xmMc8__ === 1) {
  4957. return super.send(...args);
  4958. } else if (this.__xmMc8__ === 2) {
  4959. return super.send();
  4960. } else {
  4961. console.log('[yt-js-engine-tamer]', 'xhr warning');
  4962. return super.send(...args);
  4963. }
  4964. }
  4965. }
  4966. c.prototype.__xmMc8__ = 0;
  4967. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  4968. return c;
  4969. })();
  4970. }
  4971.  
  4972. // Alternative HACK -> Tabview Youtube
  4973. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  4974.  
  4975. // ---- << this.overscrollConfig HACK >> -----
  4976.  
  4977. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  4978.  
  4979. /*
  4980.  
  4981. ;function gZb(a, b) {
  4982. b = void 0 === b ? !0 : b;
  4983. a.addEventListener("wheel", hZb);
  4984. a.overscrollConfig = {
  4985. cooldown: b
  4986. }
  4987. }
  4988. function iZb(a) {
  4989. a.overscrollConfig = void 0;
  4990. a.removeEventListener("wheel", hZb)
  4991. }
  4992. function hZb(a) {
  4993. var b = a.deltaY
  4994. , c = a.target
  4995. , d = null;
  4996. if (window.Polymer && window.Polymer.Element) {
  4997. if (c = a.path || a.composedPath && a.composedPath()) {
  4998. c = g(c);
  4999. for (var e = c.next(); !e.done && (e = e.value,
  5000. !jZb(e, b)); e = c.next())
  5001. if (e.overscrollConfig) {
  5002. d = e;
  5003. break
  5004. }
  5005. }
  5006. } else
  5007. for (; c && !jZb(c, b); ) {
  5008. if (c.overscrollConfig) {
  5009. d = c;
  5010. break
  5011. }
  5012. c = c.parentElement
  5013. }
  5014. d && (b = d.overscrollConfig,
  5015. b.cooldown ? (d = a.deltaY,
  5016. c = b.lastDeltaY || 0,
  5017. b.lastDeltaY = d,
  5018. e = b.lastStopped || 0,
  5019. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  5020. c = !1) : (d = e + 600,
  5021. c = !0) : (d = Date.now() + 600,
  5022. c = !0),
  5023. d > Date.now() && (a.preventDefault(),
  5024. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  5025. }
  5026. */
  5027.  
  5028. let wheelHandler = function (a) {
  5029. if (window.Polymer && window.Polymer.Element) {
  5030. let c;
  5031. if (c = a.path || a.composedPath && a.composedPath()) {
  5032. for (const e of c) {
  5033. const cnt = insp(e);
  5034. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5035. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5036. }
  5037. }
  5038. } else {
  5039. let e = a.target;
  5040. for (; e instanceof Element; e = e.parentElement) {
  5041. const cnt = insp(e);
  5042. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5043. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5044. }
  5045. }
  5046. };
  5047.  
  5048. let checkWheelListenerObjs = null;
  5049.  
  5050. let getObjsFn = () => {
  5051. let euyVal = 0;
  5052. const eukElm = {};
  5053. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  5054. const euzObj = new Proxy(eukElm, {
  5055. get(target, prop) {
  5056. throw `ErrorF31.get(${prop})`
  5057. },
  5058. set(target, prop, value) {
  5059. throw `ErrorF33.set(${prop}, ${value})`
  5060. }
  5061. });
  5062. const euxElm = new Proxy(eukElm, {
  5063. get(target, prop) {
  5064. if (prop === 'scrollTop') {
  5065. euyVal = euyVal | 8;
  5066. return 0;
  5067. }
  5068. if (prop === 'overscrollConfig') {
  5069. euyVal = euyVal | 16;
  5070. return void 0;
  5071. }
  5072. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  5073. return 640;
  5074. }
  5075. if (prop === 'scrollLeft') {
  5076. euyVal = euyVal | 8;
  5077. return 0;
  5078. }
  5079. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  5080. return 800;
  5081. }
  5082. throw `ErrorF45.get(${prop})`
  5083. },
  5084. set(target, prop, value) {
  5085. throw `ErrorF47.set(${prop}, ${value})`
  5086. }
  5087. });
  5088. const eukEvt = {};
  5089. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  5090. const euyEvt = new Proxy(eukEvt, {
  5091. get(target, prop) {
  5092. if (prop === 'deltaY' || prop === 'deltaX') {
  5093. euyVal = euyVal | 1;
  5094. return -999;
  5095. }
  5096. if (prop === 'target') {
  5097. euyVal = euyVal | 2;
  5098. return euxElm
  5099. }
  5100. if (prop === 'path' || prop === 'composedPath') {
  5101. euyVal = euyVal | 2;
  5102. return [euxElm]
  5103. }
  5104. throw `ErrorF51.get(${prop})`
  5105. },
  5106. set(target, prop, value) {
  5107. throw `ErrorF53.set(${prop}, ${value})`
  5108. }
  5109. });
  5110. const setVal = (v) => {
  5111. euyVal = v;
  5112. }
  5113. const getVal = () => {
  5114. return euyVal;
  5115. }
  5116. return { euzObj, euyEvt, setVal, getVal };
  5117. }
  5118.  
  5119. let checkWheelListener = (callback) => {
  5120.  
  5121. let callbackIdentifier = '';
  5122.  
  5123. let res = null;
  5124. try {
  5125. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  5126. setVal(0);
  5127. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  5128. throw `RESULT${getVal()}`;
  5129. } catch (e) {
  5130. res = e;
  5131. }
  5132.  
  5133. res = `${res}` || `${null}`;
  5134. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  5135.  
  5136. callbackIdentifier = res;
  5137. if (callbackIdentifier === 'RESULT27') 0;
  5138. else if (callbackIdentifier === 'RESULT0') {
  5139. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  5140. } else if (callbackIdentifier.startsWith('RESULT')) {
  5141. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  5142. }
  5143. return callbackIdentifier;
  5144.  
  5145. };
  5146.  
  5147. let callbackFound = false;
  5148. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  5149. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  5150. // M-youtube-js-engine-tamer.52178
  5151. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  5152. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  5153. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  5154. // RESULTXX / ErrorFXX / Other...
  5155. if (callbackIdentifier === 'RESULT27') {
  5156. this.overscrollConfigDisable = true;
  5157. if (!callbackFound) {
  5158. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  5159. getObjsFn = checkWheelListener = null;
  5160. checkWheelListenerObjs = null;
  5161. wheelHandler = null;
  5162. }
  5163. return void 0;
  5164. } else if (!callbackFound && !this.overscrollConfigDisable) {
  5165. this.overscrollConfigDisable = true;
  5166. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  5167. }
  5168. }
  5169. return this.addEventListener52178(type, callback, option);
  5170. };
  5171.  
  5172. // ---- << this.overscrollConfig HACK >> -----
  5173.  
  5174. }
  5175.  
  5176. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  5177.  
  5178. let p_a_objWR = null;
  5179. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  5180. let ytPageReady = 0;
  5181.  
  5182. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5183. let isGlobalSpaceControl = true;
  5184. let mediaPlayerElementWR = null;
  5185. let focusedElementAtSelection = null;
  5186.  
  5187. // let want_control_video = false;
  5188.  
  5189. let spaceBarControl_keyG = '';
  5190.  
  5191. let lastUserAction = 0;
  5192.  
  5193. const wmKeyControlPhase = new WeakMap();
  5194.  
  5195. let currentSelectionText = null;
  5196.  
  5197. const getCurrentSelectionText = () => {
  5198. if (currentSelectionText !== null) return currentSelectionText
  5199. return (currentSelectionText = `${getSelection()}`)
  5200. }
  5201.  
  5202. const pageMediaWatcher = () => {
  5203.  
  5204. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  5205. // want_control_video = false;
  5206. // }, { capture: true, passive: true });
  5207.  
  5208. document.addEventListener('yt-navigate', () => {
  5209. ytPageReady = 0;
  5210. });
  5211. document.addEventListener('yt-navigate-start', () => {
  5212. ytPageReady = 0;
  5213. });
  5214. document.addEventListener('yt-navigate-cache', () => {
  5215. ytPageReady = 0;
  5216. });
  5217.  
  5218. document.addEventListener('yt-navigate-finish', () => {
  5219. ytPageReady = 1;
  5220. });
  5221.  
  5222. document.addEventListener('durationchange', () => {
  5223. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  5224. if (elm.duration > 0.01) {
  5225. if (elm.closest('[hidden]')) continue;
  5226. mediaPlayerElementWR = mWeakRef(elm);
  5227. return;
  5228. }
  5229. }
  5230. }, { capture: true, passive: true });
  5231.  
  5232. document.addEventListener('selectionchange', (evt) => {
  5233. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  5234. currentSelectionText = null;
  5235. if (!(evt.target instanceof Node)) return;
  5236. focusedElementAtSelection = evt.target;
  5237. }, { capture: true, passive: true })
  5238.  
  5239. document.addEventListener('pointerdown', (evt) => {
  5240. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5241. }, { capture: true, passive: true });
  5242.  
  5243.  
  5244. document.addEventListener('pointerup', (evt) => {
  5245. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5246. }, { capture: true, passive: true });
  5247.  
  5248.  
  5249. document.addEventListener('keydown', (evt) => {
  5250. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5251. }, { capture: true, passive: true });
  5252.  
  5253. document.addEventListener('keyup', (evt) => {
  5254. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5255. }, { capture: true, passive: true });
  5256.  
  5257. };
  5258.  
  5259.  
  5260. const checkKeyB = (p_a_obj) => {
  5261.  
  5262. const boolList = new Set();
  5263. const p_a_obj_api = p_a_obj.api;
  5264.  
  5265. const nilFunc0 = function () {
  5266. return void 0
  5267. };
  5268. const mt = new Proxy({}, {
  5269. get(target, prop) {
  5270. if (prop === 'get') return nilFunc0;
  5271. return mt;
  5272. }
  5273. });
  5274. const nilFunc = function () {
  5275. return mt
  5276. };
  5277. const mw = new Proxy({}, {
  5278. get(target, prop) {
  5279. if (prop in p_a_obj_api) {
  5280. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  5281. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  5282. if (q && q.value) {
  5283. if (!q.writable) return q.value;
  5284. if (typeof q.value === 'string') return '';
  5285. if (typeof q.value === 'number') return 0;
  5286. if (typeof q.value === 'boolean') return false;
  5287. if (q.value && typeof q.value === 'object') return {};
  5288. }
  5289. }
  5290. return undefined;
  5291. },
  5292. set(target, prop) {
  5293. throw 'mwSet';
  5294. }
  5295. });
  5296.  
  5297. const mq = new Proxy({}, {
  5298. get(target, prop) {
  5299. if (prop === 'api') return mw;
  5300. if (prop in p_a_obj) {
  5301. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  5302. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  5303. if (q && q.value) {
  5304. if (!q.writable) return q.value;
  5305. if (typeof q.value === 'string') return '';
  5306. if (typeof q.value === 'number') return 0;
  5307. if (typeof q.value === 'boolean') return false;
  5308. if (q.value && typeof q.value === 'object') return {};
  5309. }
  5310. }
  5311. return undefined;
  5312. },
  5313. set(target, prop, val) {
  5314. if (typeof val === 'boolean') boolList.add(prop)
  5315. throw `mqSet(${prop},${val})`;
  5316. }
  5317. });
  5318.  
  5319. let res = ''
  5320. try {
  5321. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  5322. } catch (e) {
  5323. res = `ERROR::${e}`;
  5324. }
  5325.  
  5326. if (boolList.size === 1) {
  5327. const value = boolList.values().next().value;
  5328. if (res === `ERROR::mqSet(${value},${true})`) {
  5329. p_a_obj.__uZWaD__ = value;
  5330. }
  5331. }
  5332.  
  5333. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  5334.  
  5335. }
  5336.  
  5337.  
  5338. let pm_p_a = null;
  5339.  
  5340. const p_a_init = function () {
  5341. const r = this.init91();
  5342. const keyBw = this.__cPzfo__ || '__NIL__';
  5343. const p_a_obj = this[keyBw];
  5344. if (!p_a_obj) return;
  5345. try {
  5346. checkKeyB(p_a_obj);
  5347. } catch (e) { }
  5348. p_a_objWR = mWeakRef(p_a_obj);
  5349. if (FIX_SHORTCUTKEYS > 0) {
  5350. if (p_a_obj && !p_a_obj.hVhtg) {
  5351. p_a_obj.hVhtg = 1;
  5352.  
  5353. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  5354. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  5355. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  5356. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  5357. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  5358. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  5359.  
  5360. }
  5361. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  5362. // const api = p_a_obj.api
  5363. // api.hVhtg = 1;
  5364. // api.playVideo91 = api.playVideo;
  5365. // api.playVideo = p_a_jt.playVideo;
  5366. // api.pauseVideo91 = api.pauseVideo;
  5367. // api.pauseVideo = p_a_jt.pauseVideo;
  5368. // }
  5369. }
  5370. if (pm_p_a) {
  5371. pm_p_a.resolve();
  5372. pm_p_a = null;
  5373. }
  5374. return r;
  5375. };
  5376.  
  5377. const p_a_xt = {
  5378.  
  5379. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  5380.  
  5381. if (FIX_SHORTCUTKEYS === 2) {
  5382.  
  5383. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  5384.  
  5385. if (activeElement) {
  5386.  
  5387. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  5388.  
  5389. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  5390. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  5391. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  5392.  
  5393. }
  5394.  
  5395. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5396. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5397. // console.log(582, isDelayedSpaceBar)
  5398. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5399.  
  5400. if (activeElement && (h === 'Space' || h === 'Enter')) {
  5401. const controlPhase = wmKeyControlPhase.get(activeElement);
  5402. if (controlPhase === 4 || controlPhase === 5) return false;
  5403. }
  5404. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  5405. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  5406. // if (!isSpaceKeyImmediate) return false;
  5407. // }
  5408. }
  5409.  
  5410. },
  5411.  
  5412. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  5413.  
  5414. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  5415.  
  5416. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5417. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5418. // console.log(583, isDelayedSpaceBar)
  5419. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5420.  
  5421. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5422.  
  5423. let mediaWorking = false;
  5424. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  5425. mediaWorking = true;
  5426. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5427. mediaWorking = true;
  5428. }
  5429. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  5430. mediaWorking && Promise.resolve().then(() => {
  5431. if (activeElement === document.activeElement) {
  5432. return activeElement.blur()
  5433. } else {
  5434. return false
  5435. }
  5436. }).then((r) => {
  5437. r !== false && mediaPlayerElement.focus();
  5438. });
  5439. }
  5440. },
  5441.  
  5442.  
  5443. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  5444.  
  5445. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5446.  
  5447. const activeElement = document.activeElement;
  5448.  
  5449. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5450. if (allow === false) return false;
  5451.  
  5452. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5453. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  5454.  
  5455. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5456.  
  5457. return ret;
  5458. },
  5459. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  5460.  
  5461.  
  5462. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5463.  
  5464. const activeElement = document.activeElement;
  5465. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5466. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5467. // }
  5468. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5469. if (allow === false) return false;
  5470.  
  5471. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5472. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  5473.  
  5474. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5475.  
  5476. return ret;
  5477. }
  5478.  
  5479. };
  5480.  
  5481. let flagSpeedMaster = null;
  5482. const getSpeedMasterControlFlag = () => {
  5483.  
  5484. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5485. isSpeedMastSpacebarControlEnabled = false;
  5486. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  5487. isSpeedMastSpacebarControlEnabled = true;
  5488. }
  5489. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  5490. isSpeedMastSpacebarControlEnabled = true;
  5491. }
  5492.  
  5493. if (flagSpeedMaster === null) {
  5494. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  5495. if (!p) {
  5496. flagSpeedMaster = false;
  5497. } else {
  5498.  
  5499. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  5500.  
  5501. }
  5502.  
  5503. }
  5504. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  5505.  
  5506. return isSpeedMastSpacebarControlEnabled;
  5507. }
  5508.  
  5509.  
  5510. const getGlobalSpacebarControlFlag = () => {
  5511.  
  5512. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5513. isGlobalSpaceControl = false;
  5514. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  5515. isGlobalSpaceControl = true;
  5516. }
  5517. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  5518. isGlobalSpaceControl = true;
  5519. }
  5520.  
  5521. return isGlobalSpaceControl;
  5522. }
  5523.  
  5524. const keyboardController = async (_yt_player) => {
  5525.  
  5526. const keyQT = getQT(_yt_player);
  5527. const keySV = getSV(_yt_player);
  5528. const keyDX = getDX(_yt_player);
  5529. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  5530.  
  5531. if (!keyDX) return;
  5532. if (keyDX === keyQT || keyDX === keySV) return;
  5533.  
  5534. if (typeof keyDX !== 'string') return;
  5535.  
  5536. let lastAccessKey = '';
  5537. let lastAccessKeyConfirmed = '';
  5538. const mb = new Proxy({}, {
  5539. get(target, prop) {
  5540. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  5541. throw 'mbGet'
  5542. },
  5543. set(target, prop, val) {
  5544. throw 'mbSet'
  5545. }
  5546. });
  5547. const ma = new Proxy({}, {
  5548. get(target, prop) {
  5549. lastAccessKey = prop;
  5550. return mb
  5551. },
  5552. set(target, prop, val) {
  5553. throw 'maSet'
  5554. }
  5555. });
  5556.  
  5557. let keyBw = '';
  5558. try {
  5559. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  5560. } catch (e) {
  5561. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  5562. keyBw = lastAccessKeyConfirmed;
  5563. }
  5564. }
  5565.  
  5566. if (!keyBw) return;
  5567.  
  5568. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  5569.  
  5570. pm_p_a = new PromiseExternal();
  5571.  
  5572. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  5573.  
  5574. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  5575.  
  5576. _yt_player[keyDX].prototype.init = p_a_init;
  5577.  
  5578. await pm_p_a.then();
  5579. const p_a_obj = kRef(p_a_objWR);
  5580.  
  5581. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  5582.  
  5583.  
  5584. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  5585.  
  5586. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  5587.  
  5588. if (!isSpeedMastSpacebarControlEnabled) {
  5589.  
  5590. if (config && config.EXPERIMENT_FLAGS) {
  5591. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  5592. }
  5593. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5594. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  5595. }
  5596.  
  5597. } else {
  5598.  
  5599. if (config && config.EXPERIMENT_FLAGS) {
  5600. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  5601. }
  5602. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5603. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  5604. }
  5605.  
  5606. }
  5607.  
  5608. }
  5609.  
  5610. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  5611.  
  5612.  
  5613.  
  5614.  
  5615. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  5616.  
  5617. // console.log(p_a_obj.handleGlobalKeyUp)
  5618. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  5619.  
  5620. // console.log(p_a_obj.api)
  5621.  
  5622.  
  5623. // QT -> DX(SV) -> p_a
  5624.  
  5625.  
  5626. /*
  5627. *
  5628. *
  5629. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5630. b = void 0 === b ? !1 : b;
  5631. c = void 0 === c ? !1 : c;
  5632. d = void 0 === d ? !1 : d;
  5633. e = void 0 === e ? !1 : e;
  5634. var l = g.PT(this);
  5635. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  5636. }
  5637.  
  5638. */
  5639.  
  5640. /*
  5641. *
  5642. *
  5643. *
  5644. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5645. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  5646. }
  5647.  
  5648. */
  5649.  
  5650.  
  5651. // if(!keyDX) return;
  5652.  
  5653. // console.log(4999, keyDX)
  5654.  
  5655. };
  5656.  
  5657.  
  5658. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  5659.  
  5660. const p_a_obj = kRef(p_a_objWR);
  5661. // const api = p_a_obj.api;
  5662.  
  5663.  
  5664. // console.log(540);
  5665.  
  5666. let boolList = null;
  5667. let ret;
  5668. isSpaceKeyImmediate = true;
  5669. try {
  5670.  
  5671. ret = 0;
  5672. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  5673. let p_a_objT;
  5674. if (!spaceBarControl_keyG) { // just in case
  5675. boolList = new Set();
  5676. p_a_objT = new Proxy(p_a_obj, {
  5677. get(target, prop, handler) {
  5678. const val = target[prop];
  5679. if (typeof val !== 'boolean') return val;
  5680. boolList.add(prop);
  5681. // console.log(555, prop, val);
  5682. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  5683. spaceBarControl_keyG = prop;
  5684. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5685. val = false;
  5686. }
  5687. return val;
  5688. }
  5689. });
  5690.  
  5691.  
  5692. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  5693. p_a_obj[spaceBarControl_keyG] = false;
  5694. p_a_objT = p_a_obj;
  5695. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  5696. } else {
  5697.  
  5698. p_a_objT = p_a_obj;
  5699. }
  5700.  
  5701. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  5702.  
  5703.  
  5704. } catch (e) {
  5705. console.log(e)
  5706. }
  5707. isSpaceKeyImmediate = false;
  5708.  
  5709. if (boolList && boolList.size === 1) {
  5710. const value = boolList.values().next().value;
  5711. spaceBarControl_keyG = value;
  5712. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5713.  
  5714. }
  5715.  
  5716. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5717.  
  5718. return ret;
  5719. }
  5720.  
  5721. const shortcutKeysFixer = () => {
  5722.  
  5723. let pausePromiseControlJ = 0;
  5724.  
  5725.  
  5726. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  5727.  
  5728. let controlPhase = 0;
  5729. const aElm = document.activeElement;
  5730.  
  5731. if (aElm) {
  5732.  
  5733. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  5734.  
  5735. if (typeof controlPhaseCache === 'number') {
  5736.  
  5737. controlPhase = controlPhaseCache;
  5738. } else {
  5739.  
  5740. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  5741. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  5742. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  5743. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  5744. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  5745. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  5746. else {
  5747. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  5748. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  5749. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  5750. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  5751. }
  5752.  
  5753. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  5754. controlPhase = 0;
  5755. }
  5756.  
  5757. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  5758. if (aElm.closest('[contenteditable], input, textarea')) {
  5759. controlPhase = 5;
  5760. } else if (aElm.closest('button')) {
  5761. controlPhase = 4;
  5762. }
  5763. }
  5764.  
  5765. if (aElm.closest('#movie_player')) controlPhase = 6;
  5766.  
  5767. wmKeyControlPhase.set(aElm, controlPhase);
  5768.  
  5769. }
  5770. }
  5771.  
  5772. return controlPhase;
  5773.  
  5774. }
  5775.  
  5776. const isStateControllable = (api) => {
  5777. let appState = null;
  5778. let playerState = null;
  5779. let adState = null;
  5780. try {
  5781. appState = api.getAppState();
  5782. playerState = api.getPlayerState();
  5783. adState = api.getAdState();
  5784. } catch (e) { }
  5785. // ignore playerState -1
  5786. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  5787. };
  5788.  
  5789.  
  5790. const keyEventListener = (evt) => {
  5791. if (BY_PASS_KEYBOARD_CONTROL) return;
  5792.  
  5793. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5794. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  5795. if (!ytPageReady) return;
  5796.  
  5797. if (evt.defaultPrevented === true) return;
  5798.  
  5799. const p_a_obj = kRef(p_a_objWR);
  5800.  
  5801. if (!p_a_obj) return;
  5802.  
  5803.  
  5804. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5805. if (!mediaPlayerElement) return;
  5806.  
  5807. // let focusBodyIfSuccess = false;
  5808.  
  5809. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  5810.  
  5811. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  5812. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  5813. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  5814.  
  5815.  
  5816. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  5817.  
  5818. // console.log(`${evt.type}::controlPhase`,controlPhase)
  5819.  
  5820. // if (controlPhase == 4) {
  5821. // focusBodyIfSuccess = true;
  5822. // }
  5823.  
  5824. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  5825. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5826.  
  5827. if (FIX_SHORTCUTKEYS < 2) return;
  5828. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  5829.  
  5830. let rr;
  5831. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  5832.  
  5833.  
  5834.  
  5835. let useImprovedPauseResume = false;
  5836.  
  5837. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5838.  
  5839. const api = p_a_obj.api;
  5840. const stateControllable = isStateControllable(api);
  5841. // console.log(2122, appState, playerState, adState)
  5842.  
  5843. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  5844.  
  5845. useImprovedPauseResume = true;
  5846.  
  5847. }
  5848.  
  5849.  
  5850. }
  5851.  
  5852.  
  5853. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5854. if (evt.type === 'keydown') {
  5855.  
  5856. if (useImprovedPauseResume) {
  5857.  
  5858. const isPaused = mediaPlayerElement.paused;
  5859.  
  5860. const cj = ++pausePromiseControlJ;
  5861. Promise.resolve().then(() => {
  5862.  
  5863. if (cj !== pausePromiseControlJ) return;
  5864.  
  5865. if (mediaPlayerElement.paused !== isPaused) return;
  5866.  
  5867. const ret = ytResumeFn();
  5868. if (!ret) { // fallback
  5869. isPaused ? api.playVideo() : api.pauseVideo();
  5870. }
  5871.  
  5872. /*
  5873. let a = void 0;
  5874. console.log('Rb', api.Rb())
  5875. a = !window._yt_player.nL(api.Rb());
  5876. p_a_obj.Wd.kG(a)
  5877. a ? api.playVideo() : api.pauseVideo();
  5878.  
  5879. */
  5880.  
  5881.  
  5882. });
  5883. rr = true;
  5884. } else {
  5885.  
  5886. isSpaceKeyImmediate = true;
  5887. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  5888. isSpaceKeyImmediate = false;
  5889. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5890.  
  5891. }
  5892.  
  5893.  
  5894. } else if (evt.type === 'keyup') {
  5895.  
  5896. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5897.  
  5898. rr = true;
  5899. } else {
  5900.  
  5901. isSpaceKeyImmediate = true;
  5902. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  5903. isSpaceKeyImmediate = false;
  5904. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5905.  
  5906. }
  5907.  
  5908.  
  5909. /*
  5910.  
  5911. if (d)
  5912. switch (c) {
  5913. case 32:
  5914. case 13:
  5915. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  5916. b = !0,
  5917. e = !1;
  5918. else if (e) {
  5919. var m = d.getAttribute("role");
  5920. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  5921. d.click(),
  5922. f = !0)
  5923. }
  5924. break;
  5925. case 37:
  5926. case 39:
  5927. case 36:
  5928. case 35:
  5929. b = "slider" === d.getAttribute("role");
  5930. break;
  5931. case 38:
  5932. case 40:
  5933. m = d.getAttribute("role"),
  5934. d = 38 === c ? d.previousSibling : d.nextSibling,
  5935. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  5936. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  5937. f = b = !0))
  5938. }
  5939. if (e && !f)
  5940. switch (c) {
  5941. case 38:
  5942. f = Math.min(this.api.getVolume() + 5, 100);
  5943. XV(this.Wd, f, !1);
  5944. this.api.setVolume(f);
  5945. h = f = !0;
  5946. break;
  5947. case 40:
  5948. f = Math.max(this.api.getVolume() - 5, 0);
  5949. XV(this.Wd, f, !0);
  5950. this.api.setVolume(f);
  5951. h = f = !0;
  5952. break;
  5953. case 36:
  5954. this.api.Yh() && (this.api.startSeekCsiAction(),
  5955. this.api.seekTo(0, void 0, void 0, void 0, 79),
  5956. h = f = !0);
  5957. break;
  5958. case 35:
  5959. this.api.Yh() && (this.api.startSeekCsiAction(),
  5960. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  5961. h = f = !0)
  5962. }
  5963. */
  5964.  
  5965. }
  5966.  
  5967.  
  5968. if (rr) {
  5969.  
  5970. // focusBodyIfSuccess && Promise.resolve().then(() => {
  5971. // activeElement === document.activeElement && activeElement.blur();
  5972. // });
  5973.  
  5974. evt.preventDefault();
  5975. evt.stopImmediatePropagation();
  5976. evt.stopPropagation();
  5977.  
  5978. }
  5979.  
  5980. };
  5981.  
  5982. document.addEventListener('keydown', keyEventListener, { capture: true });
  5983.  
  5984.  
  5985. document.addEventListener('keyup', keyEventListener, { capture: true });
  5986.  
  5987. }
  5988.  
  5989. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  5990.  
  5991. })();
  5992.  
  5993.  
  5994. pageMediaWatcher();
  5995. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  5996.  
  5997.  
  5998. const check_for_set_key_order = (() => {
  5999.  
  6000. let mySet = new Set();
  6001.  
  6002. mySet.add("value1");
  6003. mySet.add("value2");
  6004. mySet.add("value3");
  6005.  
  6006. // Function to convert Set values to an array
  6007. function getSetValues(set) {
  6008. return Array.from(set.values());
  6009. }
  6010.  
  6011. // Function to test if the Set maintains insertion order
  6012. function testSetOrder(set, expectedOrder) {
  6013. let values = getSetValues(set);
  6014. return expectedOrder.join(',') === values.join(',');
  6015. }
  6016.  
  6017. // Test 1: Initial order
  6018. if (mySet.values().next().value !== "value1") return false;
  6019. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  6020.  
  6021. // Test 2: After deleting an element
  6022. mySet.delete("value2");
  6023. if (mySet.values().next().value !== "value1") return false;
  6024. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  6025.  
  6026. // Test 3: After re-adding a deleted element
  6027. mySet.add("value2");
  6028. if (mySet.values().next().value !== "value1") return false;
  6029. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  6030.  
  6031. // Test 4: After adding a new element
  6032. mySet.add("value4");
  6033. if (mySet.values().next().value !== "value1") return false;
  6034. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  6035.  
  6036. // Test 5: Delete+Add
  6037. mySet.delete("value1");
  6038. mySet.delete("value3");
  6039. mySet.add("value3");
  6040. mySet.add("value1");
  6041. if (mySet.values().next().value !== "value2") return false;
  6042. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  6043.  
  6044. return true;
  6045. })();
  6046.  
  6047.  
  6048. // const qm47 = Symbol();
  6049. // const qm57 = Symbol();
  6050. const qm53 = Symbol();
  6051. const qn53 = Symbol();
  6052.  
  6053.  
  6054. const ump3 = new WeakMap();
  6055.  
  6056. const stp = document.createElement('noscript');
  6057. stp.id = 'weakref-placeholder';
  6058.  
  6059. PROP_OverReInclusion_AVOID && (() => {
  6060.  
  6061.  
  6062. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  6063. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  6064. let byPassVal = null;
  6065. let byPassCount = 0;
  6066. let mmw = new Set();
  6067. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  6068. if (arguments.length !== 1) return f.apply(this, arguments);
  6069. if (byPassVal !== null && typeof prop === 'string') {
  6070.  
  6071. if (PROP_OverReInclusion_LIST.has(prop)) {
  6072. byPassCount++;
  6073. return byPassVal;
  6074. }
  6075. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  6076.  
  6077. }
  6078. return this.hasOwnProperty72(prop);
  6079. };
  6080.  
  6081.  
  6082. /*
  6083.  
  6084.  
  6085. z.prototype.forwardDynamicProps = function() {
  6086. var B = m(this.inst);
  6087. B = h(B);
  6088. for (var F = B.next(); !F.done; F = B.next()) {
  6089. var H = h(F.value);
  6090. F = H.next().value;
  6091. H = H.next().value;
  6092. my(this, F, H);
  6093. r(b) && !ly(F) && Wua(this.inst, F)
  6094. }
  6095. }
  6096.  
  6097. */
  6098.  
  6099.  
  6100.  
  6101. let byPassZeroShowed = false;
  6102. const forwardDynamicPropsGeneral = function () {
  6103. byPassVal = true;
  6104. byPassCount = 0;
  6105. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  6106. const ret = this.forwardDynamicProps72();
  6107. byPassVal = null;
  6108. if (byPassCount === 0 && !byPassZeroShowed) {
  6109. byPassZeroShowed = true;
  6110. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  6111. }
  6112. byPassCount = 0;
  6113. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  6114. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  6115. mmw.clear();
  6116. }
  6117. return ret;
  6118. };
  6119.  
  6120. const propCheck = (proto) => {
  6121. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  6122. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  6123. if (proto.forwardDynamicProps.length === 0) {
  6124. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  6125. }
  6126. }
  6127. };
  6128.  
  6129. const valMap = new WeakMap();
  6130. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  6131. get() {
  6132. propCheck(this.constructor.prototype);
  6133. return valMap.get(this);
  6134. },
  6135. set(nv) {
  6136. propCheck(this.constructor.prototype);
  6137. valMap.set(this, nv);
  6138. return true;
  6139. },
  6140. enumerable: false,
  6141. configurable: true
  6142.  
  6143. });
  6144.  
  6145. promiseForCustomYtElementsReady.then(() => {
  6146. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  6147. if (customElements.define.length !== 2) return;
  6148. customElements.define72 = customElements.define;
  6149. customElements.define = function (b, w) {
  6150. propCheck(w.prototype);
  6151. const ret = this.define72(b, w);
  6152. return ret;
  6153. }
  6154. });
  6155.  
  6156. })();
  6157.  
  6158. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  6159.  
  6160. const flexibleItemListMo = new MutationObserver((mutations) => {
  6161. // cnt.onStamperFinished
  6162. // cnt.maybeUpdateFlexibleMenu
  6163. const set = new Set();
  6164. for (const mutation of mutations) {
  6165. if (mutation && ((mutation.addedNodes || 0).length > 0 || (mutation.removedNodes || 0).length > 0)) {
  6166. set.add(mutation.target);
  6167. }
  6168. }
  6169. for (const s of set) {
  6170. const cnt = insp(s);
  6171. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  6172. cnt.maybeUpdateFlexibleMenuImpl();
  6173. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  6174. cnt.maybeUpdateFlexibleMenu();
  6175. } else if (typeof cnt.onStamperFinished === 'function') {
  6176. cnt.onStamperFinished();
  6177. }
  6178. }
  6179. set.clear();
  6180. });
  6181.  
  6182. let checkConfig = true;
  6183. const flexibleItemDocMo = new MutationObserver(() => {
  6184. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  6185. s.setAttribute('b289ad', '');
  6186. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  6187. s.appendChild(document.createComment('.')).remove();
  6188. }
  6189. if (checkConfig) {
  6190. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6191. if (config && config.EXPERIMENT_FLAGS) {
  6192. checkConfig = false;
  6193. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  6194. }
  6195. }
  6196. });
  6197. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  6198.  
  6199. }
  6200.  
  6201.  
  6202.  
  6203.  
  6204. const observablePromise = (proc, timeoutPromise) => {
  6205. let promise = null;
  6206. return {
  6207. obtain() {
  6208. if (!promise) {
  6209. promise = new Promise(resolve => {
  6210. let mo = null;
  6211. const f = () => {
  6212. let t = proc();
  6213. if (t) {
  6214. mo.disconnect();
  6215. mo.takeRecords();
  6216. mo = null;
  6217. resolve(t);
  6218. }
  6219. }
  6220. mo = new MutationObserver(f);
  6221. mo.observe(document, { subtree: true, childList: true })
  6222. f();
  6223. timeoutPromise && timeoutPromise.then(() => {
  6224. resolve(null)
  6225. });
  6226. });
  6227. }
  6228. return promise
  6229. }
  6230. }
  6231. }
  6232.  
  6233.  
  6234. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  6235. observablePromise(() => {
  6236. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6237. if (config && config.EXPERIMENT_FLAGS) {
  6238. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  6239. return true;
  6240. }
  6241. }).obtain();
  6242. }
  6243.  
  6244. if (FIX_ROLLING_NUMBER_UPDATE) {
  6245.  
  6246.  
  6247. observablePromise(() => {
  6248. if (typeof customElements === 'undefined') return;
  6249. const ce = customElements.get('yt-animated-rolling-number');
  6250. if (!ce) return;
  6251. return ce.prototype;
  6252. }).obtain().then(async (cProto) => {
  6253.  
  6254. const p = document.createElement('yt-animated-rolling-number');
  6255.  
  6256. const frag = document.createDocumentFragment();
  6257. frag.appendChild(p);
  6258. const pDoc = document.implementation.createHTMLDocument();
  6259. pDoc.body.appendChild(frag);
  6260.  
  6261. let p88 = p;
  6262.  
  6263. const __instance = await observablePromise(() => {
  6264. const __instance = (p88 || 0).__instance;
  6265. if (__instance && __instance.render) return __instance;
  6266. }).obtain();
  6267. p88 = null;
  6268.  
  6269. const itProto = Reflect.getPrototypeOf(__instance);
  6270.  
  6271. try {
  6272. p.remove();
  6273. } catch (e) { }
  6274.  
  6275. if (itProto.render && !itProto.render37 && itProto.render.length === 1) {
  6276.  
  6277. itProto.render37 = itProto.render;
  6278. itProto.render = function (t) {
  6279. // (this.xCounter = (this.xCounter & 1073741823)+1)
  6280. let c33 = '';
  6281. let r33 = null;
  6282. let kc = 0;
  6283.  
  6284. if (this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  6285. const el = this.el;
  6286. const ct = Date.now();
  6287. const lastFireTime = (el.__lastFireTime491__ || 0);
  6288.  
  6289. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  6290.  
  6291. if (fireTimeDiff < 80 && this.__previousRender61__) {
  6292. return this.__previousRender61__;
  6293. }
  6294.  
  6295. const caseInt =
  6296. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  6297. (t && typeof t.character === 'string') ? (
  6298. (typeof t.previousCharacter === 'string') ? 6 : 2
  6299. ) : 0;
  6300.  
  6301. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender61__ && fireTimeDiff < 9400) {
  6302. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender61__) {
  6303. return this.__previousRender61__;
  6304. }
  6305. }
  6306. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender61__ && fireTimeDiff < 9400) {
  6307. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender61__) {
  6308. return this.__previousRender61__;
  6309. }
  6310. }
  6311.  
  6312. if (caseInt & 2) {
  6313.  
  6314. if (caseInt & 4) {
  6315.  
  6316. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  6317. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  6318. t.previousCharacter = t.character;
  6319. kc = 1;
  6320. }
  6321. }
  6322.  
  6323. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  6324. t.shouldAnimate = false;
  6325. }
  6326. }
  6327.  
  6328.  
  6329. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  6330.  
  6331. el.__lastCharacter353__ = t.character;
  6332.  
  6333. } else if (caseInt === 1) {
  6334.  
  6335. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  6336. t.shouldAnimate = false;
  6337. }
  6338. el.__lastNumberValue353__ = t.numberValue;
  6339.  
  6340. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  6341. t.shouldAnimate = false;
  6342. }
  6343. el.__lastNumberText353__ = t.numberText;
  6344.  
  6345. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  6346.  
  6347. }
  6348.  
  6349. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  6350.  
  6351. el.__lastFireTime491__ = ct;
  6352. }
  6353.  
  6354. // // console.log(21399, t.character, t.previousCharacter, (t.xCounter = (t.xCounter & 1073741823)+1), t, (this.xCounter = (this.xCounter & 1073741823)+1) )
  6355. // // console.log(12883, this, t);
  6356. const r = r33 || this.render37(t);
  6357. this.__previousRender61__ = r;
  6358. if (c33) this[c33] = r;
  6359. return r
  6360. }
  6361.  
  6362. }
  6363.  
  6364. });
  6365.  
  6366. }
  6367.  
  6368. if (HOOK_ACTIVE_MODULES) {
  6369.  
  6370. let watchController;
  6371. const watchControllerObservable = observablePromise(() => {
  6372. const watchFlexy = document.querySelector('ytd-watch-flexy');
  6373. if (!watchFlexy) return;
  6374. return insp(watchFlexy).watchController;
  6375. }).obtain();
  6376. (async () => {
  6377. watchController = await watchControllerObservable;
  6378.  
  6379. const activeModules = watchController.activeModules;
  6380. if (!activeModules) return;
  6381.  
  6382. const checkFn = (activeModule) => {
  6383. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  6384. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  6385. }
  6386. }
  6387. if (!activeModules.push8792 && activeModules.push) {
  6388. activeModules.push8792 = activeModules.push;
  6389. activeModules.push = function (a, ...args) {
  6390. checkFn(a);
  6391. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  6392. return r;
  6393. }
  6394. }
  6395. activeModules.forEach(checkFn);
  6396.  
  6397. })();
  6398.  
  6399. let yieldResultWrappingByPass = false;
  6400. let asyncProto = null;
  6401. const yieldResultWrapping = (f) => {
  6402. if (yieldResultWrappingByPass) return [f(), null];
  6403. yieldResultWrappingByPass = true;
  6404. let D = null;
  6405. let promise, e_;
  6406. if (asyncProto) {
  6407. Object.defineProperty(asyncProto, 'yieldResult', {
  6408. get() {
  6409. return undefined;
  6410. },
  6411. set(nv) {
  6412. delete asyncProto.yieldResult;
  6413. this.yieldResult = nv;
  6414. D = this;
  6415. // console.log(122, this);
  6416. return true;
  6417. },
  6418. enumerable: false,
  6419. configurable: true
  6420. });
  6421. try {
  6422. promise = f();
  6423. } catch (e) { e_ = e }
  6424. delete asyncProto.yieldResult;
  6425. yieldResultWrappingByPass = false;
  6426. } else {
  6427. Object.defineProperty(Object.prototype, 'yieldResult', {
  6428. get() {
  6429. return undefined;
  6430. },
  6431. set(nv) {
  6432. delete Object.prototype.yieldResult;
  6433. this.yieldResult = nv;
  6434. D = this;
  6435. // console.log(122, this);
  6436. return true;
  6437. },
  6438. enumerable: false,
  6439. configurable: true
  6440. });
  6441. try {
  6442. promise = f();
  6443. } catch (e) { e_ = e }
  6444. delete Object.prototype.yieldResult;
  6445. yieldResultWrappingByPass = false;
  6446. if (D) {
  6447. asyncProto = Reflect.getPrototypeOf(D);
  6448. }
  6449. }
  6450. if (e_) throw e_;
  6451. return [promise, D];
  6452. }
  6453.  
  6454. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  6455.  
  6456. const aProto = Reflect.getPrototypeOf(activeModule);
  6457.  
  6458. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  6459.  
  6460. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  6461.  
  6462. // console.log(12885)
  6463. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  6464. // let qxt=false;
  6465. aProto.fetchUpdatedMetadata = function (t, P) {
  6466.  
  6467. // if (!qxt) {
  6468. // qxt = true;
  6469. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  6470. // console.log(199001,...args)
  6471. // });
  6472. // this.addOnDisposeCallback(function (...args) {
  6473.  
  6474. // console.log(199002,...args)
  6475. // watchController.unsubscribeByKey(y)
  6476. // qxt = false;
  6477. // });
  6478. // }
  6479. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  6480. if (D) promise.then(() => {
  6481. const yieldResult = D.yieldResult;
  6482. if (yieldResult) {
  6483. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  6484.  
  6485. if (mutations && mutations.length >= 1) {
  6486. let likeCountEntity = null;
  6487. for (const mutation of mutations) {
  6488. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  6489. break;
  6490. }
  6491. }
  6492. if (likeCountEntity) {
  6493. const model = insp(document.querySelector('segmented-like-dislike-button-view-model'));
  6494. if (model && typeof model.update === 'function' && model.update.length === 0) {
  6495. const data = ((model || 0).props || 0).data;
  6496. if (data) {
  6497. if (typeof data.likeCountEntity !== 'object') data.likeCountEntity = {};
  6498. // console.log(12838, {...data.likeCountEntity}, {...likeCountEntity})
  6499. // const shouldModelUpdate = (data.likeCountEntity.key !== likeCountEntity.key); // to be reviewed
  6500. const shouldModelUpdate = true;
  6501. Object.assign(data.likeCountEntity, likeCountEntity);
  6502. // data.likeCountEntity = likeCountEntity;
  6503. // if (shouldModelupdate) model.update();
  6504. // else {
  6505. // if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  6506. // }
  6507.  
  6508. if (shouldModelUpdate) {
  6509. if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  6510. // console.log('kk1a enqueueUpdate')
  6511. model.enqueueUpdate();
  6512. // console.log('kk1b enqueueUpdate')
  6513. } else if (typeof model.update === 'function' && model.update.length === 0) {
  6514. // console.log('kk2a update')
  6515. model.update();
  6516. // console.log('kk2b update')
  6517. } else {
  6518. console.warn('[yt-js-engine-tamer] cannot do model update.')
  6519. }
  6520. }
  6521.  
  6522. }
  6523. }
  6524. }
  6525. }
  6526. }
  6527. }).catch(console.warn);
  6528. return promise;
  6529. };
  6530.  
  6531. }
  6532.  
  6533. }
  6534.  
  6535. // ----------------------------
  6536.  
  6537. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  6538.  
  6539. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  6540.  
  6541. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  6542.  
  6543.  
  6544. // const globalPromiseStack = {};
  6545.  
  6546. // let dummy;
  6547. // while(!dummy){
  6548.  
  6549. // dummy = document.querySelector('yt-icon');
  6550. // await new Promise(r=>setTimeout(r,0));
  6551. // }
  6552.  
  6553. dummy = document.createElement('yt-icon');
  6554.  
  6555. let cProto;
  6556. if (!(dummy instanceof Element)) return;
  6557. cProto = insp(dummy).constructor.prototype;
  6558.  
  6559. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  6560. cProto.determineIconSet671 = cProto.determineIconSet;
  6561. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  6562. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  6563. cProto.getIconManager671 = cProto.getIconManager;
  6564. cProto.getIconShapeData671 = cProto.getIconShapeData;
  6565. cProto.renderIcon671 = cProto.renderIcon;
  6566.  
  6567. // cProto.attached488 = cProto.attached;
  6568. // cProto.attached = function(){
  6569. // console.log('attached')
  6570. // return this.attached488(...arguments);
  6571. // }
  6572. // cProto.detached488 = cProto.detached;
  6573. // cProto.detached = function(){
  6574. // console.log('detached')
  6575. // return this.detached488(...arguments);
  6576. // }
  6577.  
  6578. if (cProto.__renderIconFix__) return;
  6579. cProto.__renderIconFix__ = true;
  6580.  
  6581. let taskStack = [];
  6582. const cmObs = new MutationObserver(() => {
  6583. const tasks = taskStack.slice();
  6584. taskStack.length = 0;
  6585. for (const task of tasks) {
  6586. task();
  6587. }
  6588. })
  6589. const cm = document.createComment('1');
  6590. const stackTask = (f) => {
  6591. taskStack.push(f);
  6592. cm.data = `${(cm.data & 7) + 1}`;
  6593. }
  6594. cmObs.observe(cm, { characterData: true });
  6595.  
  6596. // let iconManagers = {}; // assume shared
  6597.  
  6598. // window.iconManagers = () => iconManagers;
  6599.  
  6600.  
  6601. const setupYtIcon = (inst) => {
  6602.  
  6603. if (inst.__ytIconSetup588__) return;
  6604. const cProto = Reflect.getPrototypeOf(inst);
  6605. cProto.__ytIconSetup588__ = true;
  6606.  
  6607.  
  6608. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6609.  
  6610. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  6611. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  6612. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  6613. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  6614.  
  6615.  
  6616. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  6617. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  6618. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  6619. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  6620.  
  6621.  
  6622.  
  6623. }
  6624.  
  6625. cProto.handlePropertyChange = function (...a) { // 10+
  6626.  
  6627. const __data = this.__data;
  6628. if (FIX_GUIDE_ICON && this.id === 'guide-icon' && __data && !__data.icon && typeof this.set === 'function') {
  6629. this.set('icon', "yt-icons:menu")
  6630. }
  6631.  
  6632. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6633. this.__resolved__ = {
  6634.  
  6635. };
  6636. const a01 = this.isAttached;
  6637. let a02, a03;
  6638.  
  6639.  
  6640. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  6641.  
  6642. const stackFn = () => {
  6643. if (t !== this.__stackedKey3818__) {
  6644. return;
  6645. }
  6646. a03 = this.isAttached;
  6647.  
  6648. if (a01 === false && a02 === false && a03 === false) return;
  6649.  
  6650. if (a01 === true && a02 === true && a03 === true) {
  6651.  
  6652. } else {
  6653. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  6654. // unknown yt-icon#label-icon
  6655. return;
  6656. } else {
  6657. console.log('[yt-icon] debug', a01, a02, a03, this)
  6658. }
  6659. }
  6660.  
  6661. this.handlePropertyChange671(...arguments);
  6662.  
  6663. };
  6664.  
  6665.  
  6666.  
  6667. Promise.resolve().then(() => {
  6668. a02 = this.isAttached;
  6669. stackTask(stackFn);
  6670. });
  6671.  
  6672.  
  6673. }
  6674.  
  6675. cProto.determineIconSet = function (a, b, c, d) { // 10-
  6676.  
  6677. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6678. // string bool? bool=false int=24
  6679. // NOTIFICATIONS_NONE OR LIKE
  6680. // console.log('yt-icon.determineIconSet', ...arguments);
  6681.  
  6682. const r = this.determineIconSet671(...arguments);
  6683. return r;
  6684. }
  6685.  
  6686. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  6687.  
  6688. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6689. // same as determineIconSet
  6690. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  6691. return this.switchToYtSysIconset671(...arguments);
  6692. }
  6693.  
  6694. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  6695.  
  6696. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6697. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  6698. return this.useYtSysIconsetForMissingIcons671(...arguments);
  6699. }
  6700.  
  6701. cProto.getIconManager = function () { // 10+
  6702.  
  6703. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6704. if (!this.__resolved__) this.__resolved__ = {};
  6705. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  6706. const r = this.__resolved__.getIconManager;
  6707. return r;
  6708. }
  6709.  
  6710. cProto.getIconShapeData = function () { // 10+
  6711.  
  6712. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6713.  
  6714. // no argument
  6715. // console.log('yt-icon.getIconShapeData', ...arguments);
  6716. if (!this.__resolved__) this.__resolved__ = {};
  6717. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  6718. const r = this.__resolved__.getIconShapeData;
  6719. return r
  6720. }
  6721.  
  6722. cProto.renderIcon = function (a, b) { // X
  6723.  
  6724. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6725. // "" yt-icons:xxx
  6726. // console.log('yt-icon.renderIcon', ...arguments);
  6727. return this.renderIcon671(...arguments);
  6728. }
  6729.  
  6730. });
  6731.  
  6732.  
  6733. /**
  6734. * Compute the Longest Common Subsequence between two arrays.
  6735. * Returns an array of the LCS elements (in order).
  6736. */
  6737. function computeLCS(a, b) {
  6738. // Input validation
  6739. if (!Array.isArray(a) || !Array.isArray(b)) {
  6740. throw new Error('Inputs must be arrays');
  6741. }
  6742.  
  6743. const n = a.length, m = b.length;
  6744. // Early termination for trivial cases
  6745. if (n === 0 || m === 0) return [];
  6746. // Check for shallow equality
  6747. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  6748.  
  6749. // Use smaller dimension for space optimization
  6750. if (n > m) return computeLCS(b, a); // Ensure n <= m
  6751.  
  6752. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  6753. // Use Uint32Array for robustness with long sequences
  6754. const dp = [
  6755. new Uint32Array(m + 1),
  6756. new Uint32Array(m + 1),
  6757. ];
  6758. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  6759. // Optimize space by storing only necessary entries
  6760. const pred = new Uint8Array(n * m); // Single array for moves
  6761.  
  6762. for (let i = n - 1; i >= 0; i--) {
  6763. const curr = i % 2;
  6764. const next = 1 - curr;
  6765. // Clear current row for reuse
  6766. dp[curr].fill(0);
  6767.  
  6768. for (let j = m - 1; j >= 0; j--) {
  6769. const idx = i * m + j;
  6770. if (a[i] === b[j]) {
  6771. dp[curr][j] = dp[next][j + 1] + 1;
  6772. pred[idx] = 0; // Diagonal
  6773. } else if (dp[next][j] >= dp[curr][j + 1]) {
  6774. dp[curr][j] = dp[next][j];
  6775. pred[idx] = 1; // Down
  6776. } else {
  6777. dp[curr][j] = dp[curr][j + 1];
  6778. pred[idx] = 2; // Right
  6779. }
  6780. }
  6781. }
  6782.  
  6783. // Check for potential overflow
  6784. if (dp[0][0] > 0xFFFFFFFF) {
  6785. throw new Error('LCS length exceeds safe integer limit');
  6786. }
  6787.  
  6788. // Backtrack to build the actual LCS
  6789. const lcs = [];
  6790. let i = 0, j = 0;
  6791. while (i < n && j < m) {
  6792. const idx = i * m + j;
  6793. const p = pred[idx];
  6794. if (p === 0) {
  6795. lcs.push(a[i]);
  6796. i++; j++;
  6797. } else if (p === 1) {
  6798. i++;
  6799. } else {
  6800. j++;
  6801. }
  6802. }
  6803. return lcs;
  6804. }
  6805.  
  6806. /**
  6807. * Given original[] and modified[], produce an array of splice-ops:
  6808. * [ [start0, deleteCount0, addedItems0],
  6809. * [start1, deleteCount1, addedItems1],
  6810. * … ]
  6811. * When you do:
  6812. * let arr = original.slice();
  6813. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  6814. * arr will equal modified.
  6815. */
  6816. function diffSplices(original, modified) {
  6817. // Input validation
  6818. if (!Array.isArray(original) || !Array.isArray(modified)) {
  6819. throw new Error('Inputs must be arrays');
  6820. }
  6821.  
  6822. const origLen = original.length;
  6823. const modLen = modified.length;
  6824. // Early termination for trivial cases
  6825. if (origLen === 0 && modLen === 0) return [];
  6826. if (origLen === 0) return [[0, 0, modified.slice()]];
  6827. if (modLen === 0) return [[0, origLen, []]];
  6828.  
  6829. // Trim common prefix and suffix
  6830. let prefixLen = 0;
  6831. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  6832. prefixLen++;
  6833. }
  6834. let suffixLen = 0;
  6835. while (
  6836. suffixLen < origLen - prefixLen &&
  6837. suffixLen < modLen - prefixLen &&
  6838. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  6839. ) {
  6840. suffixLen++;
  6841. }
  6842.  
  6843. // Cache references for speed
  6844. const orig = original.slice(prefixLen, origLen - suffixLen);
  6845. const mod = modified.slice(prefixLen, modLen - suffixLen);
  6846. const lcs = computeLCS(orig, mod);
  6847. // Pre-allocate ops array, accounting for potential moves
  6848. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  6849. let opCount = 0;
  6850.  
  6851. let i = 0, j = 0, k = 0;
  6852. let curIndex = prefixLen;
  6853. const lcsLen = lcs.length;
  6854.  
  6855. while (k < lcsLen) {
  6856. const match = lcs[k];
  6857. let deleteCount = 0;
  6858. const deleted = [];
  6859. const added = [];
  6860.  
  6861. // 1) Collect deletions up to the next common element
  6862. while (i < orig.length && orig[i] !== match) {
  6863. deleted.push(orig[i]);
  6864. deleteCount++;
  6865. i++;
  6866. }
  6867.  
  6868. // 2) Collect insertions up to that same element
  6869. while (j < mod.length && mod[j] !== match) {
  6870. added.push(mod[j]);
  6871. j++;
  6872. }
  6873.  
  6874. // 3) Check for a move (deleted segment matches inserted segment)
  6875. let isMove = false;
  6876. if (deleteCount > 0 && deleteCount === added.length) {
  6877. isMove = deleted.every((x, idx) => x === added[idx]);
  6878. if (isMove) {
  6879. // If a move, split into delete and insert at different indices
  6880. if (deleteCount > 0) {
  6881. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  6882. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  6883. curIndex += added.length; // Advance past inserted items
  6884. }
  6885. }
  6886. }
  6887.  
  6888. // 4) Combine delete and insert into a single operation if not a move
  6889. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  6890. ops[opCount++] = [curIndex, deleteCount, added];
  6891. curIndex += added.length; // Advance past inserted items
  6892. }
  6893.  
  6894. // 5) Skip over the matching element itself
  6895. i++;
  6896. j++;
  6897. k++;
  6898. curIndex++;
  6899. }
  6900.  
  6901. // 6) Handle any trailing deletions and insertions as a single operation
  6902. const trailingDelete = orig.length - i;
  6903. const trailingAdd = mod.slice(j);
  6904. if (trailingDelete > 0 || trailingAdd.length > 0) {
  6905. // Check for trailing move
  6906. const trailingDeleted = orig.slice(i);
  6907. let isMove = false;
  6908. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  6909. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  6910. if (isMove) {
  6911. ops[opCount++] = [curIndex, trailingDelete, []];
  6912. ops[opCount++] = [curIndex, 0, trailingAdd];
  6913. }
  6914. }
  6915. if (!isMove) {
  6916. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  6917. }
  6918. }
  6919.  
  6920. // 7) Truncate ops array to actual size
  6921. ops.length = opCount;
  6922.  
  6923. return ops;
  6924. }
  6925. // class listPlaceholder {
  6926. // constructor(len){
  6927. // this.length = len;
  6928. // }
  6929. // }
  6930.  
  6931.  
  6932.  
  6933. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  6934. // var renderJob = this.renderJobsMap_[key],
  6935. // renderCallback = null;
  6936.  
  6937. // if (path === changeRecord.path) {
  6938. // let value = changeRecord.value;
  6939.  
  6940. // if (!_.v_(value)) {
  6941. // value = (value === void 0 || value === null) ? [] : [value];
  6942. // }
  6943.  
  6944. // let stampDomEntry = this.stampDom[path];
  6945.  
  6946. // if (stampDomEntry.mapping) {
  6947. // renderCallback = this.stampDomArray_.bind(
  6948. // this,
  6949. // value,
  6950. // key,
  6951. // stampDomEntry.mapping,
  6952. // stampDomEntry.reuseComponents,
  6953. // stampDomEntry.events,
  6954. // stampDomEntry.stamperStableList
  6955. // );
  6956. // }
  6957.  
  6958. // if (renderJob) renderJob.cancel();
  6959.  
  6960. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  6961.  
  6962. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  6963. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  6964. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  6965. // this.renderJobsMap_[key] = renderJob;
  6966. // }
  6967. // } else {
  6968. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  6969. // this.renderJobsMap_[key] = renderJob;
  6970. // renderCallback = function(callback, job) {
  6971. // callback();
  6972. // q4C(job, 10);
  6973. // }.bind(this, renderCallback, renderJob);
  6974. // }
  6975. // } else {
  6976. // renderCallback = (path + ".splices" === changeRecord.path)
  6977. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  6978. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  6979. // }
  6980.  
  6981. // if (renderJob) {
  6982. // _.vY(renderJob, renderCallback);
  6983. // } else {
  6984. // renderCallback();
  6985. // }
  6986. // }
  6987.  
  6988.  
  6989.  
  6990.  
  6991. const createStampDomFnsC_ = () => {
  6992.  
  6993. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  6994.  
  6995. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  6996. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  6997.  
  6998.  
  6999. // const rq0 = document.createElement('rp');
  7000. // rq0.setAttribute('yt-element-placholder', '');
  7001.  
  7002. const it0 = Date.now() - 80000000000;
  7003. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  7004.  
  7005.  
  7006. const getStampContainer_ = function (containerId) {
  7007.  
  7008. return this.getStampContainer7409_(containerId);
  7009.  
  7010. }
  7011.  
  7012.  
  7013.  
  7014.  
  7015. const createComponent_ = function (componentConfig, data, canReuse) {
  7016.  
  7017. return this.createComponent7409_(componentConfig, data, canReuse);
  7018.  
  7019. }
  7020.  
  7021.  
  7022. const s52 = Symbol();
  7023.  
  7024. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  7025.  
  7026. // if(component.querySelectorAll('dom-if').length > 0){
  7027.  
  7028. // // console.log(1233, component.isConnected, component.parentNode, component.querySelectorAll('dom-if'))
  7029. // if (component.isConnected === false) {
  7030. // for (const s of component.querySelectorAll('dom-if')) {
  7031. // try {
  7032. // console.log(1299);
  7033. // insp(s).__teardownInstance();
  7034. // } catch (e) { }
  7035. // }
  7036. // }
  7037.  
  7038. // }
  7039.  
  7040. if (typeof (data || 0) === 'object') {
  7041. if (!data[s52]) data[s52] = genId();
  7042. component[s52] = data[s52];
  7043. // console.log(component[s52], data);
  7044. } else {
  7045. component[s52] = null;
  7046. }
  7047.  
  7048. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7049.  
  7050. }
  7051.  
  7052. // let pr77 = Promise.resolve();
  7053.  
  7054. const flushRenderStamperComponentBindings_ = function () {
  7055. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  7056.  
  7057. if (this.deferredBindingTasks_.length >= 0) {
  7058.  
  7059. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  7060.  
  7061. const gid = this[`__$$stampFlushKey$$__`] = genId();
  7062. const g = (() => {
  7063. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  7064. // if (deferredBindingTasks_.length === 0) return;
  7065. // let q = this.deferredBindingTasks_;
  7066. // this.deferredBindingTasks_ = deferredBindingTasks_;
  7067. this.flushRenderStamperComponentBindings7409_();
  7068. // deferredBindingTasks_.length = 0;
  7069. // this.deferredBindingTasks_ = q;
  7070.  
  7071. const s = [...this.__lat457__];
  7072. this.__lat457__.clear();
  7073.  
  7074. for (const containerWr of s) {
  7075.  
  7076. const container = kRef(containerWr);
  7077. if (!container) continue;
  7078.  
  7079. // const s = new Set();
  7080. if (!container.querySelector('[ytx-flushing]')) {
  7081. if (container.hasAttribute('ytx-flushing')) {
  7082. const attrVal = container.getAttribute('ytx-flushing');
  7083. container.removeAttribute('ytx-flushing');
  7084. // s.add([container, attrVal]);
  7085. addTask(container, attrVal);
  7086. // addTaskIm(container, attrVal);
  7087. let ancestor = container.closest('[ytx-flushing]');
  7088. while (ancestor) {
  7089. if (ancestor.querySelector('[ytx-flushing]')) break;
  7090. const attrVal = ancestor.getAttribute('ytx-flushing');
  7091. ancestor.removeAttribute('ytx-flushing');
  7092. // s.add([ancestor, attrVal]);
  7093. addTask(ancestor, attrVal);
  7094. // addTaskIm(ancestor, attrVal);
  7095. ancestor = ancestor.closest('[ytx-flushing]');
  7096. }
  7097. }
  7098. }
  7099. }
  7100. executeTasks();
  7101.  
  7102.  
  7103. });
  7104. g();
  7105. // const useMicroTaskQueue = this.__qsd477__ === 2;
  7106. // useMicroTaskQueue ? addTask2(g) : g();
  7107. // executeTasks();
  7108.  
  7109. // addTask2(g);
  7110. // executeTasks();
  7111.  
  7112. }
  7113.  
  7114. throw new Error('e5bd8d2f');
  7115.  
  7116. }
  7117.  
  7118. let tasks = [];
  7119. let excuted = false;
  7120. const executeTasks = ()=>{
  7121. if(excuted || tasks.length === 0) return;
  7122. excuted = true;
  7123. let t0 = 0;
  7124. const perform = ()=>{
  7125. if(!t0) t0 = nativeNow();
  7126. const task = tasks.shift();
  7127. if(!task){
  7128. excuted = false;
  7129. return;
  7130. }
  7131. task.fn(task);
  7132. const t1 = nativeNow();
  7133. if(t1 - t0 > 10){
  7134. t0 = 0;
  7135. nextBrowserTick_(perform);
  7136. }else{
  7137. queueMicrotask_(perform);
  7138. }
  7139. }
  7140. queueMicrotask_(perform);
  7141. }
  7142.  
  7143. const taskFn = (task) => {
  7144.  
  7145. if(!task) return;
  7146. const { containerWr, attrVal } = task;
  7147. const container = kRef(containerWr);
  7148. if (!container) return;
  7149. if (attrVal === '0') return;
  7150. const bEventCb = attrVal === '2';
  7151. const producerWr = containerMapping.get(container);
  7152. const producer = kRef(producerWr);
  7153. if (!producer) return;
  7154. const hostElement = producer.hostElement;
  7155. if (!hostElement) return;
  7156. if (hostElement.isConnected !== true) return; // tbc
  7157. producer.markDirty && producer.markDirty();
  7158. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  7159. container
  7160. });
  7161.  
  7162. }
  7163.  
  7164. const addTask = (container, attrVal) => {
  7165. if (!container) return;
  7166. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7167. tasks.push({
  7168. fn: taskFn,
  7169. containerWr: containerWr,
  7170. attrVal
  7171. });
  7172. // pr77 = pr77.then(()=>{
  7173.  
  7174. // })
  7175. // taskFn({
  7176. // containerWr: containerWr,
  7177. // attrVal
  7178. // })
  7179.  
  7180. }
  7181.  
  7182. const addTaskIm = (container, attrVal) => {
  7183. if (!container) return;
  7184. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7185. taskFn({
  7186. fn: taskFn,
  7187. containerWr: containerWr,
  7188. attrVal
  7189. });
  7190.  
  7191. }
  7192.  
  7193.  
  7194. const addTask2 = (f) => {
  7195. // pr77 = pr77.then(f).catch(console.warn);
  7196. tasks.push({
  7197. fn: f
  7198. });
  7199.  
  7200. }
  7201.  
  7202. // const mo = new MutationObserver((mutations)=>{
  7203.  
  7204. // });
  7205. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  7206.  
  7207. const containerMapping = new WeakMap();
  7208.  
  7209. // let pr77 = Promise.resolve();
  7210. // let pr88 = Promise.resolve();
  7211. const uA4 = function (t, P) {
  7212. for (let y in t)
  7213. if (t.hasOwnProperty(y) && P[y])
  7214. return y;
  7215. return null
  7216. }
  7217.  
  7218. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  7219.  
  7220. const ax = ax_;
  7221. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  7222. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  7223. // const useMicroTaskQueue = false;
  7224. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  7225. ax[2].cancel();
  7226. useMicroTaskQueue2 = false;
  7227. }
  7228. // console.log(1992,containerId, this.hostElement.is)
  7229.  
  7230. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  7231. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  7232. // return false;
  7233.  
  7234. // }
  7235.  
  7236. if (producer.hasFlexibleItems === true) {
  7237. return false;
  7238. }
  7239.  
  7240. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  7241. return false;
  7242. }
  7243.  
  7244. const hostIs = hostIs_;
  7245.  
  7246. 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;
  7247.  
  7248. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  7249. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  7250. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  7251. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  7252. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  7253. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  7254. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  7255. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  7256. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  7257. 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;
  7258. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  7259. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  7260. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  7261. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  7262. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  7263. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  7264. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  7265. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  7266. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  7267.  
  7268.  
  7269. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  7270.  
  7271.  
  7272. // console.log(5992,stackAt)
  7273.  
  7274. // console.log(2883, this[`__quu477#${containerId}__`] )
  7275. // if (useMicroTaskQueue) {
  7276. // console.log(stackAt)
  7277. // }
  7278.  
  7279. // if (useMicroTaskQueue) {
  7280. // console.log(1120301)
  7281. // }
  7282.  
  7283. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  7284.  
  7285. return useMicroTaskQueue2;
  7286.  
  7287. }
  7288.  
  7289. const frag385 = document.createDocumentFragment();
  7290. frag385.appendChild4202 = frag385.appendChild;
  7291. frag385.removeChild4202 = frag385.removeChild;
  7292. const cm385 = document.createComment('.');
  7293.  
  7294. const doc385 = document.implementation.createHTMLDocument();
  7295. const html385 = doc385.firstElementChild;
  7296. const node385 = html385.appendChild(document.createElement('div'));
  7297.  
  7298. const fixContainerApi = (container) => {
  7299. if (container instanceof Node) {
  7300. const containerDomApi = container.__domApi;
  7301. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  7302. // console.log(123882, container)
  7303. containerDomApi.removeChild588 = containerDomApi.removeChild;
  7304. containerDomApi.removeChild = function (elem) {
  7305. let r;
  7306. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7307. s.setAttribute('ytx-flushing', '0');
  7308. }
  7309. try {
  7310. r = this.removeChild588(elem);
  7311. } catch (e) { }
  7312. if (!r) {
  7313. frag385.appendChild4202(elem);
  7314. frag385.removeChild4202(elem);
  7315. r = elem;
  7316. }
  7317. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7318. s.removeAttribute('ytx-flushing');
  7319. }
  7320. return r;
  7321. }
  7322. }
  7323. }
  7324. }
  7325.  
  7326. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7327.  
  7328. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7329. if (typeof sqq === 'function') sqq();
  7330.  
  7331. // trigger in rendererStamperApplyChangeRecord_
  7332.  
  7333. // 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];
  7334. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7335. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7336. // 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];
  7337.  
  7338. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7339. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7340.  
  7341.  
  7342. const ax = this[`__quu477#${containerId}__`];
  7343. const hostIs = (this.hostElement || 0).is;
  7344. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7345.  
  7346. const container = this.getStampContainer7409_(containerId);
  7347. const pChildren = (container instanceof Node && container.isConnected) ? [...container.children] : [];
  7348. renderPathMake(pChildren)
  7349.  
  7350. containerMapping.set(container,
  7351. (this[wk] || (this[wk] = mWeakRef(this)))
  7352. );
  7353.  
  7354. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7355. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7356.  
  7357. // let dataList_ = dataList;
  7358. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  7359.  
  7360. dataList = null;
  7361. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  7362. let fq = 0;
  7363. const f = (() => {
  7364. if(fq) return;
  7365. fq = 1;
  7366. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7367. this[`__$$stampSFn$$#${containerId}__`] = null;
  7368. const container = this.getStampContainer7409_(containerId);
  7369.  
  7370. this.__lat457__ = this.__lat457__ || new Set();
  7371. if(!container[wk]) container[wk] = mWeakRef(container);
  7372. this.__lat457__.add(container[wk]);
  7373. fixContainerApi(container);
  7374.  
  7375. // let q = this.deferredBindingTasks_;
  7376. // this.deferredBindingTasks_ = [];
  7377. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7378. let e_;
  7379. try {
  7380. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  7381. } catch (e) { e_ = e }
  7382. this.__qsd477__ = false;
  7383. dataList_ = typeOrConfig = null;
  7384. fixContainerApi(container);
  7385. // this.deferredBindingTasks_ = q;
  7386. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7387. if (!e_) {
  7388. // container.setAttribute('ytx-flushing', '0');
  7389. }
  7390. // if( container.childElementCount === 0 ){
  7391. // container.setAttribute('ytx-flushing', '0');
  7392. // this.markDirty && this.markDirty();
  7393. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  7394. // container
  7395. // });
  7396. // }
  7397.  
  7398.  
  7399.  
  7400.  
  7401. });
  7402. this[`__$$stampSFn$$#${containerId}__`] = f;
  7403. this[`__$$stampSqq$$#${containerId}__`] = f;
  7404. useMicroTaskQueue2 ? addTask2(f) : f();
  7405. executeTasks();
  7406.  
  7407. Promise.resolve(pChildren).then(pChildren => {
  7408. for (const node of pChildren) {
  7409. if (node.isConnected === false) {
  7410. _removedElements.addNode(node); // rn54006
  7411. }
  7412. }
  7413. pChildren.length = 0;
  7414. pChildren = null;
  7415. });
  7416.  
  7417. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  7418.  
  7419. return undefined;
  7420.  
  7421. }
  7422.  
  7423. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  7424.  
  7425.  
  7426. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7427. if (typeof sqq === 'function') sqq();
  7428.  
  7429. // trigger in rendererStamperApplyChangeRecord_
  7430.  
  7431. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7432. } else {
  7433. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7434. }
  7435.  
  7436.  
  7437. // trigger in rendererStamperApplyChangeRecord_
  7438.  
  7439. // 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];
  7440. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7441. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7442.  
  7443. // 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];
  7444.  
  7445. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7446. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7447. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  7448.  
  7449. const ax = this[`__quu477#${containerId}__`];
  7450. const hostIs = (this.hostElement || 0).is;
  7451. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7452.  
  7453.  
  7454. // 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];
  7455. // const useMicroTaskQueue = true;
  7456. const container = this.getStampContainer7409_(containerId);
  7457.  
  7458. containerMapping.set(container,
  7459. (this[wk] || (this[wk] = mWeakRef(this)))
  7460. );
  7461. const bEventCb = this.stampDom[stampKey].events;
  7462. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7463. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7464.  
  7465. // let indexSplicesObj_ = indexSplicesObj;
  7466. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7467. // indexSplicesObj_ = {
  7468. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  7469. // const { index, addedCount, removed, object, type } = slice;
  7470. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7471. // return { index, addedCount, removed, object, type };
  7472. // })
  7473. // };
  7474. // }
  7475.  
  7476.  
  7477. indexSplicesObj.indexSplices.forEach(slice => {
  7478. const object = slice.object;
  7479. if (!object || typeof object !== 'object') return;
  7480. // const { index, addedCount, removed, object, type } = slice;
  7481. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7482. // return { index, addedCount, removed, object, type };
  7483. });
  7484.  
  7485. // let indexSplicesObj_ = indexSplicesObj;
  7486.  
  7487. // console.log(128783, indexSplicesObj)
  7488.  
  7489. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  7490. // const { index, addedCount, removed, object, type } = slice;
  7491. // return { index, addedCount, removed, object, type };
  7492. // });
  7493.  
  7494. indexSplicesObj = null;
  7495.  
  7496. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  7497. const gid = this[`__$$stampSID$$#${containerId}__`];
  7498. let fq = 0;
  7499. const f = (() => {
  7500. if(fq) return;
  7501. fq = 1;
  7502. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7503. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  7504. const container = this.getStampContainer7409_(containerId);
  7505. if(!container) return;
  7506.  
  7507. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  7508.  
  7509. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  7510. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  7511. const mapping = this.stampDom[stampKey].mapping;
  7512.  
  7513. const map = new Map();
  7514.  
  7515. const currentObjKeys = object.map(objEntry => {
  7516. const mappingKey = uA4(mapping, objEntry);
  7517. if(!mappingKey) return null;
  7518. const data = objEntry[mappingKey];
  7519. if (!data[s52]) data[s52] = genId();
  7520. map.set(data[s52], objEntry);
  7521. // return ({
  7522. // objEntry,
  7523. // data: data,
  7524. // mappingKey: mappingKey,
  7525. // key: data[s52],
  7526. // exist: elementKeys.has(data[s52])
  7527. // });
  7528. return data[s52]
  7529.  
  7530. });
  7531.  
  7532. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  7533.  
  7534. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  7535.  
  7536. const splices = diffSplices(oldDomKeys, currentObjKeys);
  7537.  
  7538. // let myObject = object;
  7539. let indexSplicesObj_ = {
  7540. indexSplices: splices.map(splice => {
  7541. const index = splice[0];
  7542. const removedLen = splice[1];
  7543. const added = splice[2];
  7544. const addedCount = added.length;
  7545. const object = {};
  7546. object.length = index + addedCount;
  7547. for (let i = 0; i < addedCount; i++) {
  7548. object[index + i] = map.get(added[i]);
  7549. }
  7550. const removed = {};
  7551. removed.length = removedLen;
  7552.  
  7553. return { index, removed, object, addedCount }
  7554. })
  7555. };
  7556. map.clear();
  7557.  
  7558.  
  7559. this.__lat457__ = this.__lat457__ || new Set();
  7560. if(!container[wk]) container[wk] = mWeakRef(container);
  7561. this.__lat457__.add(container[wk]);
  7562. fixContainerApi(container);
  7563.  
  7564. // console.log(3882, indexSplicesObj_)
  7565. // let q = this.deferredBindingTasks_;
  7566. // this.deferredBindingTasks_ = [];
  7567. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7568. let e_;
  7569. try {
  7570. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  7571. } catch (e) { e_ = e; }
  7572. this.__qsd477__ = false;
  7573. indexSplicesObj_ = null;
  7574. stampKey = indexSplicesObj_ = null;
  7575. fixContainerApi(container);
  7576. // this.deferredBindingTasks_ = q;
  7577. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7578. if (!e_) {
  7579. // container.setAttribute('ytx-flushing', '0');
  7580. }
  7581.  
  7582.  
  7583. });
  7584. this[`__$$stampSqq$$#${containerId}__`] = f;
  7585. useMicroTaskQueue2 ? addTask2(f) : f();
  7586. executeTasks();
  7587.  
  7588. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  7589.  
  7590. return undefined;
  7591.  
  7592. }
  7593.  
  7594.  
  7595. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  7596. const dt0 = dt0a[0];
  7597. const dt1 = Date.now();
  7598. const obj = kRef(objWr);
  7599. if (!obj) return;
  7600. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7601. if (xxx !== xxx_) return;
  7602. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7603. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7604. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7605. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7606. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7607. const renderJob1 = obj.renderJobsMap_[containerId]
  7608. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  7609. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7610. let e_, r;
  7611. try {
  7612. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7613. } catch (e) {
  7614. e_ = e;
  7615. }
  7616. obj[`__quu477#${containerId}__`] = false;
  7617. if (e_) throw e_;
  7618. return r;
  7619. };
  7620.  
  7621.  
  7622. stampDomArray_.bind = function (obj, ...args) {
  7623. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7624. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7625. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7626. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  7627. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  7628. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7629. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7630. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7631. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7632.  
  7633.  
  7634. const renderJob = obj.renderJobsMap_[containerId];
  7635.  
  7636. const dt0a = [Date.now()];
  7637. queueMicrotask_(() => { dt0a[0] = 0 });
  7638. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  7639. };
  7640.  
  7641. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  7642. const dt0 = dt0a[0];
  7643. const dt1 = Date.now();
  7644. const obj = kRef(objWr);
  7645. if (!obj) return;
  7646. const renderJob1 = obj.renderJobsMap_[containerId];
  7647. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7648. let e_, r;
  7649. try {
  7650. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  7651. } catch (e) {
  7652. e_ = e;
  7653. }
  7654. obj[`__quu477#${containerId}__`] = false;
  7655. if (e_) throw e_;
  7656. return r;
  7657. };
  7658.  
  7659.  
  7660. stampDomArraySplices_.bind = function (obj, ...args) {
  7661. let [stampKey, containerId, indexSplicesObj] = args;
  7662. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7663.  
  7664. const renderJob = obj.renderJobsMap_[containerId];
  7665.  
  7666. const dt0a = [Date.now()];
  7667. queueMicrotask_(() => { dt0a[0] = 0 });
  7668. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  7669. };
  7670.  
  7671. const flushRenderStamperComponentBindings7419_ = function () {
  7672. const tasks = this.deferredBindingTasks_;
  7673. if (!(tasks || 0).length) return;
  7674. const hostElement = this.hostElement;
  7675. if ((hostElement instanceof Node) && hostElement.nodeType === 1) {
  7676. if (hostElement.isConnected === true) {
  7677. this.flushRenderStamperComponentBindings7409_();
  7678. }
  7679. } else if (hostElement) {
  7680. console.log('flushRenderStamperComponentBindings7419_ 002')
  7681. this.flushRenderStamperComponentBindings7409_();
  7682. } else {
  7683. console.log('flushRenderStamperComponentBindings7419_ 003')
  7684. tasks.length = 0;
  7685. }
  7686. }
  7687.  
  7688. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ , flushRenderStamperComponentBindings7419_};
  7689.  
  7690. }
  7691.  
  7692. const setupDiscreteTasks = (h, rb) => {
  7693.  
  7694. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7695. const f = h.onYtRendererstamperFinished;
  7696. const g = ump3.get(f) || function () {
  7697. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7698. return f.apply(this, arguments);
  7699. }
  7700. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7701. }
  7702. ump3.set(f, g);
  7703. g.km34 = 1;
  7704. h.onYtRendererstamperFinished = g;
  7705.  
  7706. }
  7707.  
  7708. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7709. const f = h.onYtUpdateDescriptionAction;
  7710. const g = ump3.get(f) || function (a) {
  7711. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7712. }
  7713. ump3.set(f, g);
  7714. g.km34 = 1;
  7715. h.onYtUpdateDescriptionAction = g;
  7716.  
  7717. }
  7718.  
  7719. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7720. const f = h.handleUpdateDescriptionAction;
  7721. const g = ump3.get(f) || function (a) {
  7722. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7723. }
  7724. ump3.set(f, g);
  7725. g.km34 = 1;
  7726. h.handleUpdateDescriptionAction = g;
  7727.  
  7728. }
  7729.  
  7730. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7731. const f = h.handleUpdateLiveChatPollAction;
  7732. const g = ump3.get(f) || function (a) {
  7733. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7734. }
  7735. ump3.set(f, g);
  7736. g.km34 = 1;
  7737. h.handleUpdateLiveChatPollAction = g;
  7738.  
  7739. }
  7740.  
  7741. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  7742. const f = h.onTextChanged;
  7743. const g = ump3.get(f) || function () {
  7744. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7745. }
  7746. ump3.set(f, g);
  7747. g.km34 = 1;
  7748. h.onTextChanged = g;
  7749.  
  7750. }
  7751.  
  7752. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  7753. const f = h.onVideoDataChange;
  7754. const g = ump3.get(f) || function (a) {
  7755. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7756. }
  7757. ump3.set(f, g);
  7758. g.km34 = 1;
  7759. h.onVideoDataChange = g;
  7760.  
  7761. }
  7762.  
  7763. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  7764. const f = h.onVideoDataChange_;
  7765. const g = ump3.get(f) || function () {
  7766. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7767. }
  7768. ump3.set(f, g);
  7769. g.km34 = 1;
  7770. h.onVideoDataChange_ = g;
  7771.  
  7772. }
  7773.  
  7774. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  7775.  
  7776. const f = h.addTooltips_;
  7777. const g = ump3.get(f) || function () {
  7778. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7779. }
  7780. ump3.set(f, g);
  7781. g.km34 = 1;
  7782. h.addTooltips_ = g;
  7783.  
  7784. }
  7785.  
  7786. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  7787.  
  7788. const f = h.updateRenderedElements;
  7789. const g = ump3.get(f) || function () {
  7790. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7791. }
  7792. ump3.set(f, g);
  7793. g.km34 = 1;
  7794. h.updateRenderedElements = g;
  7795.  
  7796. }
  7797.  
  7798. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  7799. const f = h.loadPage_;
  7800. const g = ump3.get(f) || function (a) {
  7801. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7802. }
  7803. ump3.set(f, g);
  7804. g.km34 = 1;
  7805. h.loadPage_ = g;
  7806.  
  7807. }
  7808. // updatePageData_ : possible conflict with Omit ShadyDOM
  7809. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  7810. const f = h.updatePageData_;
  7811. const g = ump3.get(f) || function (a) {
  7812. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7813. }
  7814. ump3.set(f, g);
  7815. g.km34 = 1;
  7816. h.updatePageData_ = g;
  7817.  
  7818. }
  7819.  
  7820.  
  7821. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  7822.  
  7823. const f = h.onFocus_;
  7824. const g = ump3.get(f) || function () {
  7825. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7826. }
  7827. ump3.set(f, g);
  7828. g.km34 = 1;
  7829. h.onFocus_ = g;
  7830.  
  7831. }
  7832.  
  7833. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  7834.  
  7835. const f = h.onBlur_;
  7836. const g = ump3.get(f) || function () {
  7837. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7838. }
  7839. ump3.set(f, g);
  7840. g.km34 = 1;
  7841. h.onBlur_ = g;
  7842.  
  7843. }
  7844.  
  7845.  
  7846. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  7847.  
  7848. const f = h.buttonClassChanged_;
  7849. const g = ump3.get(f) || function (a, b) {
  7850. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7851. }
  7852. ump3.set(f, g);
  7853. g.km34 = 1;
  7854. h.buttonClassChanged_ = g;
  7855.  
  7856. }
  7857.  
  7858. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  7859.  
  7860. const f = h.buttonIconChanged_;
  7861. const g = ump3.get(f) || function (a) {
  7862. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7863. }
  7864. ump3.set(f, g);
  7865. g.km34 = 1;
  7866. h.buttonIconChanged_ = g;
  7867.  
  7868. }
  7869.  
  7870. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  7871.  
  7872. const f = h.dataChangedInBehavior_;
  7873. const g = ump3.get(f) || function () {
  7874. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7875. }
  7876. ump3.set(f, g);
  7877. g.km34 = 1;
  7878. h.dataChangedInBehavior_ = g;
  7879.  
  7880. }
  7881.  
  7882. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  7883.  
  7884. const f = h.continuationsChanged_;
  7885. const g = ump3.get(f) || function () {
  7886. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7887. }
  7888. ump3.set(f, g);
  7889. g.km34 = 1;
  7890. h.continuationsChanged_ = g;
  7891.  
  7892. }
  7893.  
  7894.  
  7895. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  7896.  
  7897. const f = h.forceChatPoll_;
  7898. const g = ump3.get(f) || function (a) {
  7899. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7900. }
  7901. ump3.set(f, g);
  7902. g.km34 = 1;
  7903. h.forceChatPoll_ = g;
  7904.  
  7905. }
  7906.  
  7907. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  7908.  
  7909. const f = h.onEndpointClick_;
  7910. const g = ump3.get(f) || function (a) {
  7911. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7912. }
  7913. ump3.set(f, g);
  7914. g.km34 = 1;
  7915. h.onEndpointClick_ = g;
  7916.  
  7917. }
  7918.  
  7919. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  7920.  
  7921. const f = h.onEndpointTap_;
  7922. const g = ump3.get(f) || function (a) {
  7923. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7924. }
  7925. ump3.set(f, g);
  7926. g.km34 = 1;
  7927. h.onEndpointTap_ = g;
  7928.  
  7929. }
  7930.  
  7931. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  7932.  
  7933. const f = h.handleClick_;
  7934. const g = ump3.get(f) || function (a, b) {
  7935. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7936. }
  7937. ump3.set(f, g);
  7938. g.km34 = 1;
  7939. h.handleClick_ = g;
  7940.  
  7941. }
  7942.  
  7943. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  7944.  
  7945. const f = h.onReadyStateChange_;
  7946. const g = ump3.get(f) || function () {
  7947. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7948. }
  7949. ump3.set(f, g);
  7950. g.km34 = 1;
  7951. h.onReadyStateChange_ = g;
  7952.  
  7953. }
  7954.  
  7955. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  7956.  
  7957. const f = h.onReadyStateChangeEntryPoint_;
  7958. const g = ump3.get(f) || function () {
  7959. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7960. }
  7961. ump3.set(f, g);
  7962. g.km34 = 1;
  7963. h.onReadyStateChangeEntryPoint_ = g;
  7964.  
  7965. }
  7966.  
  7967. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  7968.  
  7969. const f = h.readyStateChangeHandler_;
  7970. const g = ump3.get(f) || function (a) {
  7971. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7972. }
  7973. ump3.set(f, g);
  7974. g.km34 = 1;
  7975. h.readyStateChangeHandler_ = g;
  7976.  
  7977. }
  7978.  
  7979. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  7980.  
  7981. const f = h.xmlHttpHandler_;
  7982. const g = ump3.get(f) || function (a) {
  7983. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7984. }
  7985. ump3.set(f, g);
  7986. g.km34 = 1;
  7987. h.xmlHttpHandler_ = g;
  7988.  
  7989. }
  7990.  
  7991. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  7992.  
  7993. const f = h.executeCallbacks_; // overloaded
  7994. const g = ump3.get(f) || function (a) {
  7995. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7996. }
  7997. ump3.set(f, g);
  7998. g.km34 = 1;
  7999. h.executeCallbacks_ = g;
  8000.  
  8001. }
  8002.  
  8003. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  8004.  
  8005. const f = h.handleInvalidationData_;
  8006. const g = ump3.get(f) || function (a, b) {
  8007. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8008. }
  8009. ump3.set(f, g);
  8010. g.km34 = 1;
  8011. h.handleInvalidationData_ = g;
  8012.  
  8013. }
  8014.  
  8015. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  8016.  
  8017. const f = h.onInput_;
  8018. const g = ump3.get(f) || function () {
  8019. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8020. }
  8021. ump3.set(f, g);
  8022. g.km34 = 1;
  8023. h.onInput_ = g;
  8024.  
  8025. }
  8026. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  8027.  
  8028. const f = h.trigger_;
  8029. const g = ump3.get(f) || function (a) {
  8030. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8031. }
  8032. ump3.set(f, g);
  8033. g.km34 = 1;
  8034. h.trigger_ = g;
  8035.  
  8036. }
  8037.  
  8038. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  8039.  
  8040. const f = h.requestData_;
  8041. const g = ump3.get(f) || function (a) {
  8042. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8043. }
  8044. ump3.set(f, g);
  8045. g.km34 = 1;
  8046. h.requestData_ = g;
  8047.  
  8048. }
  8049.  
  8050. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  8051.  
  8052. const f = h.onLoadReloadContinuation_;
  8053. const g = ump3.get(f) || function (a, b) {
  8054. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8055. }
  8056. ump3.set(f, g);
  8057. g.km34 = 1;
  8058. h.onLoadReloadContinuation_ = g;
  8059.  
  8060. }
  8061.  
  8062. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  8063.  
  8064. const f = h.onLoadIncrementalContinuation_;
  8065. const g = ump3.get(f) || function (a, b) {
  8066. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8067. }
  8068. ump3.set(f, g);
  8069. g.km34 = 1;
  8070. h.onLoadIncrementalContinuation_ = g;
  8071.  
  8072. }
  8073.  
  8074. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  8075.  
  8076. const f = h.onLoadSeekContinuation_;
  8077. const g = ump3.get(f) || function (a, b) {
  8078. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8079. }
  8080. ump3.set(f, g);
  8081. g.km34 = 1;
  8082. h.onLoadSeekContinuation_ = g;
  8083.  
  8084. }
  8085. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  8086.  
  8087. const f = h.onLoadReplayContinuation_;
  8088. const g = ump3.get(f) || function (a, b) {
  8089. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8090. }
  8091. ump3.set(f, g);
  8092. g.km34 = 1;
  8093. h.onLoadReplayContinuation_ = g;
  8094.  
  8095. }
  8096. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  8097.  
  8098. const f = h.onNavigate_;
  8099. const g = ump3.get(f) || function (a) {
  8100. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8101. }
  8102. ump3.set(f, g);
  8103. g.km34 = 1;
  8104. h.onNavigate_ = g;
  8105.  
  8106. }
  8107.  
  8108. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  8109.  
  8110. const f = h.ytRendererBehaviorDataObserver_;
  8111. const g = ump3.get(f) || function () {
  8112. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8113. }
  8114. ump3.set(f, g);
  8115. g.km34 = 1;
  8116. h.ytRendererBehaviorDataObserver_ = g;
  8117.  
  8118. }
  8119.  
  8120. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  8121.  
  8122. const f = h.ytRendererBehaviorTargetIdObserver_;
  8123. const g = ump3.get(f) || function () {
  8124. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8125. }
  8126. ump3.set(f, g);
  8127. g.km34 = 1;
  8128. h.ytRendererBehaviorTargetIdObserver_ = g;
  8129.  
  8130. }
  8131.  
  8132. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  8133.  
  8134. const f = h.unregisterRenderer_;
  8135. const g = ump3.get(f) || function (a) {
  8136. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8137. }
  8138. ump3.set(f, g);
  8139. g.km34 = 1;
  8140. h.unregisterRenderer_ = g;
  8141.  
  8142. }
  8143.  
  8144. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  8145.  
  8146. const f = h.textChanged_;
  8147. const g = ump3.get(f) || function (a) {
  8148. if (void 0 !== this.isAttached) {
  8149. const hostElement = this.hostElement;
  8150. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  8151. return;
  8152. }
  8153. }
  8154. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8155. }
  8156. ump3.set(f, g);
  8157. g.km34 = 1;
  8158. h.textChanged_ = g;
  8159.  
  8160. }
  8161.  
  8162.  
  8163.  
  8164. /**
  8165. *
  8166. * Neglect following
  8167. *
  8168. * h.onYtAction_
  8169. * h.startLoadingWatch [ buggy for yt-player-updated ]
  8170. * h.deferRenderStamperBinding_
  8171. *
  8172. * h.stampDomArray_
  8173. * h.stampDomArraySplices_
  8174. *
  8175. */
  8176.  
  8177.  
  8178. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  8179. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  8180. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  8181. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  8182. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  8183. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  8184.  
  8185. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  8186.  
  8187. const f = h.searchChanged_;
  8188. const g = ump3.get(f) || function () {
  8189. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8190. }
  8191. ump3.set(f, g);
  8192. g.km34 = 1;
  8193. h.searchChanged_ = g;
  8194.  
  8195. }
  8196.  
  8197. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  8198.  
  8199. const f = h.skinToneChanged_;
  8200. const g = ump3.get(f) || function (a) {
  8201. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8202. }
  8203. ump3.set(f, g);
  8204. g.km34 = 1;
  8205. h.skinToneChanged_ = g;
  8206.  
  8207. }
  8208.  
  8209. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  8210.  
  8211. const f = h.onEmojiHover_;
  8212. const g = ump3.get(f) || function (a) {
  8213. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8214. }
  8215. ump3.set(f, g);
  8216. g.km34 = 1;
  8217. h.onEmojiHover_ = g;
  8218.  
  8219. }
  8220.  
  8221. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  8222.  
  8223. const f = h.onSelectCategory_;
  8224. const g = ump3.get(f) || function (a) {
  8225. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8226. }
  8227. ump3.set(f, g);
  8228. g.km34 = 1;
  8229. h.onSelectCategory_ = g;
  8230.  
  8231. }
  8232.  
  8233. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  8234.  
  8235. const f = h.onShowEmojiVariantSelector;
  8236. const g = ump3.get(f) || function (a) {
  8237. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8238. }
  8239. ump3.set(f, g);
  8240. g.km34 = 1;
  8241. h.onShowEmojiVariantSelector = g;
  8242.  
  8243. }
  8244.  
  8245. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  8246.  
  8247. const f = h.updateCategoriesAndPlaceholder_;
  8248. const g = ump3.get(f) || function () {
  8249. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8250. }
  8251. ump3.set(f, g);
  8252. g.km34 = 1;
  8253. h.updateCategoriesAndPlaceholder_ = g;
  8254.  
  8255. }
  8256.  
  8257. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  8258.  
  8259. const f = h.watchPageActiveChanged_;
  8260. const g = ump3.get(f) || function () {
  8261. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8262. }
  8263. ump3.set(f, g);
  8264. g.km34 = 1;
  8265. h.watchPageActiveChanged_ = g;
  8266.  
  8267. }
  8268.  
  8269. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  8270.  
  8271. const f = h.activate_;
  8272. const g = ump3.get(f) || function () {
  8273. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8274. }
  8275. ump3.set(f, g);
  8276. g.km34 = 1;
  8277. h.activate_ = g;
  8278.  
  8279. }
  8280. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  8281.  
  8282. const f = h.onYtPlaylistDataUpdated_;
  8283. const g = ump3.get(f) || function () {
  8284. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8285. }
  8286. ump3.set(f, g);
  8287. g.km34 = 1;
  8288. h.onYtPlaylistDataUpdated_ = g;
  8289.  
  8290. }
  8291.  
  8292.  
  8293.  
  8294. /**
  8295. *
  8296. * Neglect following
  8297. *
  8298. * h.rendererStamperObserver_
  8299. * h.rendererStamperApplyChangeRecord_
  8300. * h.flushRenderStamperComponentBindings_
  8301. * h.forwardRendererStamperChanges_
  8302. *
  8303. */
  8304.  
  8305. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  8306.  
  8307. const f = h.tryRenderChunk_;
  8308. const g = ump3.get(f) || function () {
  8309. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8310. }
  8311. ump3.set(f, g);
  8312. g.km34 = 1;
  8313. h.tryRenderChunk_ = g;
  8314.  
  8315. }
  8316.  
  8317.  
  8318. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  8319.  
  8320. const f = h.renderChunk_;
  8321. const g = ump3.get(f) || function () {
  8322. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8323. }
  8324. ump3.set(f, g);
  8325. g.km34 = 1;
  8326. h.renderChunk_ = g;
  8327.  
  8328. }
  8329.  
  8330. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  8331.  
  8332. const f = h.deepLazyListObserver_;
  8333. const g = ump3.get(f) || function () {
  8334. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8335. }
  8336. ump3.set(f, g);
  8337. g.km34 = 1;
  8338. h.deepLazyListObserver_ = g;
  8339.  
  8340. }
  8341.  
  8342. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  8343.  
  8344. const f = h.onItemsUpdated_;
  8345. const g = ump3.get(f) || function () {
  8346. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8347. }
  8348. ump3.set(f, g);
  8349. g.km34 = 1;
  8350. h.onItemsUpdated_ = g;
  8351.  
  8352. }
  8353.  
  8354. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  8355.  
  8356. const f = h.requestRenderChunk_;
  8357. const g = ump3.get(f) || function () {
  8358. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8359. }
  8360. ump3.set(f, g);
  8361. g.km34 = 1;
  8362. h.requestRenderChunk_ = g;
  8363.  
  8364. }
  8365.  
  8366. /**
  8367. *
  8368. * Neglect following
  8369. *
  8370. * h.dataChanged_ [ buggy for page swtiching ]
  8371. *
  8372. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  8373. *
  8374. * h.cancelPendingTasks_
  8375. * h.fillRange_
  8376. * h.addTextNodes_
  8377. * h.updateText_
  8378. * h.stampTypeChanged_
  8379. *
  8380. */
  8381.  
  8382.  
  8383. }
  8384.  
  8385. const keyStConnectedCallback = Symbol(); // avoid copying the value
  8386.  
  8387. const dmf = new WeakMap();
  8388.  
  8389.  
  8390. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  8391.  
  8392. try {
  8393.  
  8394. const q = document.createElement('template');
  8395. q.innerHTML = '<ytz-null361></ytz-null361>';
  8396. nativeHTMLElement = q.content.firstChild.constructor
  8397.  
  8398. } catch (e) { }
  8399.  
  8400. if (!nativeHTMLElement.prototype.connectedCallback) {
  8401. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  8402. nativeHTMLElement.prototype.connectedCallback = function () {
  8403. let r;
  8404. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  8405. return r;
  8406. }
  8407. }
  8408. const pvr = Symbol()
  8409.  
  8410. let stampDomArrayFnStore = null;
  8411. const setupMap = new WeakSet();
  8412. const setupYtComponent = (cnt) => {
  8413. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  8414. if (!cProto || setupMap.has(cProto)) return;
  8415. setupMap.add(cProto);
  8416. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  8417. cProto[pvr] |= 1;
  8418.  
  8419.  
  8420.  
  8421. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  8422. const b = cProto.stampDomArray_.length === 6
  8423. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  8424. && cProto.createComponent_ && cProto.createComponent_.length === 3
  8425. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  8426. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  8427. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  8428. if (!b) {
  8429. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  8430. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  8431. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  8432. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_, flushRenderStamperComponentBindings7419_} = stampDomArrayFnStore;
  8433.  
  8434. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  8435. cProto.createComponent7409_ = cProto.createComponent_;
  8436. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  8437. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  8438. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  8439. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  8440.  
  8441. cProto.getStampContainer_ = getStampContainer_;
  8442. cProto.createComponent_ = createComponent_;
  8443. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  8444. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  8445. cProto.stampDomArray_ = stampDomArray_;
  8446. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  8447. cProto.flushRenderStamperComponentBindings7419_ = flushRenderStamperComponentBindings7419_;
  8448.  
  8449. }
  8450. }
  8451.  
  8452.  
  8453.  
  8454.  
  8455. // if(false && cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  8456. // cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  8457.  
  8458. // if(cProto._runEffectsForTemplate6344.length === 4){
  8459.  
  8460. // cProto._runEffectsForTemplate = function (c, d, e, g) {
  8461. // const cnt = this;
  8462. // const { propertyEffects, nodeList, firstChild } = c;
  8463. // cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  8464.  
  8465. // }
  8466.  
  8467. // }
  8468.  
  8469. // }
  8470.  
  8471. }
  8472. };
  8473.  
  8474. (FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  8475. get() {
  8476. const f = this[keyStConnectedCallback];
  8477. if (this.is) {
  8478. setupYtComponent(this);
  8479. }
  8480. return f;
  8481. },
  8482. set(nv) {
  8483. let gv = nv;
  8484. this[keyStConnectedCallback] = gv; // proto or object
  8485. return true;
  8486. },
  8487. enumerable: false,
  8488. configurable: true
  8489.  
  8490. });
  8491.  
  8492. const pLoad = new Promise(resolve => {
  8493. if (document.readyState !== 'loading') {
  8494. resolve();
  8495. } else {
  8496. window.addEventListener("DOMContentLoaded", resolve, false);
  8497. }
  8498. });
  8499.  
  8500. if (FIX_ACTIONS_TOOLTIPS) {
  8501. pLoad.then(() => {
  8502. addNewCSS("#actions .tp-yt-paper-tooltip{white-space:nowrap}");
  8503. });
  8504. }
  8505.  
  8506. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  8507. window.requestIdleCallback471 = window.requestIdleCallback;
  8508. window.requestIdleCallback = function (f, ...args) {
  8509. return (this || window).requestIdleCallback471(async function () {
  8510. await pLoad.then();
  8511. // await new Promise(nextBrowserTick_);
  8512. f.call(this, ...arguments)
  8513. }, ...args);
  8514. }
  8515. }
  8516.  
  8517. pLoad.then(() => {
  8518.  
  8519. let nonce = document.querySelector('style[nonce]');
  8520. nonce = nonce ? nonce.getAttribute('nonce') : null;
  8521. const st = document.createElement('style');
  8522. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  8523. st.textContent = "none-element-k47{order:0}";
  8524. st.addEventListener('load', () => {
  8525. pf31.resolve();
  8526. p59 = 1;
  8527. }, false);
  8528. (document.body || document.head || document.documentElement).appendChild(st);
  8529.  
  8530. });
  8531.  
  8532. const prepareLogs = [];
  8533.  
  8534. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  8535.  
  8536. let winError00 = window.onerror;
  8537.  
  8538. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  8539.  
  8540. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  8541.  
  8542. ; fix_error_many_stack_state === 1 && (() => {
  8543.  
  8544.  
  8545. let p1 = winError00;
  8546.  
  8547. let stackNeedleDetails = null;
  8548.  
  8549. Object.defineProperty(Object.prototype, 'matchAll', {
  8550. get() {
  8551. stackNeedleDetails = this;
  8552. return true;
  8553. },
  8554. enumerable: true,
  8555. configurable: true
  8556. });
  8557.  
  8558. try {
  8559. JSON.parse("{}");
  8560. } catch (e) {
  8561. console.warn(e)
  8562. fix_error_many_stack_state = 0;
  8563. }
  8564.  
  8565. delete Object.prototype['matchAll'];
  8566.  
  8567. let p2 = window.onerror;
  8568.  
  8569. window.onerror = p1;
  8570.  
  8571. if (fix_error_many_stack_state === 0) return;
  8572.  
  8573. if (stackNeedleDetails) {
  8574. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8575. stackNeedleDetails.matchAll = true;
  8576. }
  8577.  
  8578. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8579.  
  8580. // p1!==p2
  8581. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8582.  
  8583. })();
  8584.  
  8585. ; fix_error_many_stack_state === 2 && (() => {
  8586.  
  8587.  
  8588. let p1 = winError00;
  8589.  
  8590. let objectPrune = null;
  8591. let stackNeedleDetails = null;
  8592.  
  8593. Object.defineProperty(Function.prototype, 'findOwner', {
  8594. get() {
  8595. objectPrune = this;
  8596. return this._findOwner;
  8597. },
  8598. set(nv) {
  8599. this._findOwner = nv;
  8600. return true;
  8601. },
  8602. enumerable: true,
  8603. configurable: true
  8604. });
  8605.  
  8606. Object.defineProperty(Object.prototype, 'matchAll', {
  8607. get() {
  8608. stackNeedleDetails = this;
  8609. return true;
  8610. },
  8611. enumerable: true,
  8612. configurable: true
  8613. });
  8614.  
  8615. try {
  8616. JSON.parse("{}");
  8617. } catch (e) {
  8618. console.warn(e)
  8619. fix_error_many_stack_state = 0;
  8620. }
  8621.  
  8622. delete Function.prototype['findOwner'];
  8623. delete Object.prototype['matchAll'];
  8624.  
  8625. let p2 = window.onerror;
  8626.  
  8627. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8628.  
  8629. if (fix_error_many_stack_state == 0) return;
  8630.  
  8631. // the following will only execute when Brave's scriptlets.js is executed.
  8632.  
  8633. prepareLogs.push("fix_error_many_stack_state NB")
  8634.  
  8635. if (stackNeedleDetails) {
  8636. stackNeedleDetails.pattern = null;
  8637. stackNeedleDetails.re = null;
  8638. stackNeedleDetails.expect = null;
  8639. stackNeedleDetails.matchAll = true;
  8640. }
  8641.  
  8642. if (objectPrune) {
  8643. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8644. delete objectPrune._findOwner;
  8645. }
  8646.  
  8647. fix_error_many_stack_state = 3;
  8648. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8649. JSON.parse.objectPrune = objectPrune;
  8650.  
  8651. })();
  8652.  
  8653. ; fix_error_many_stack_state === 3 && (() => {
  8654.  
  8655.  
  8656. let p1 = winError00;
  8657.  
  8658. try {
  8659. JSON.parse("{}");
  8660. } catch (e) {
  8661. console.warn(e)
  8662. fix_error_many_stack_state = 0;
  8663. }
  8664.  
  8665. let p2 = window.onerror;
  8666.  
  8667. if (p1 === p2) return;
  8668.  
  8669. window.onerror = p1;
  8670.  
  8671. if (fix_error_many_stack_state === 0) return;
  8672.  
  8673. fix_error_many_stack_state = 4; // p1 != p2
  8674.  
  8675.  
  8676. })();
  8677.  
  8678. fix_error_many_stack_state === 4 && (() => {
  8679.  
  8680. // the following will only execute when Brave's scriptlets.js is executed.
  8681.  
  8682. prepareLogs.push("fix_error_many_stack_state AB")
  8683.  
  8684. JSON.parseProxy = JSON.parse;
  8685.  
  8686. JSON.parse = ((parse) => {
  8687.  
  8688. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8689. return function (text, reviver) {
  8690. const onerror = window.onerror;
  8691. window.onerror = null;
  8692. let r;
  8693. try {
  8694. r = parse(...arguments);
  8695. } catch (e) {
  8696. r = e;
  8697. }
  8698. window.onerror = onerror;
  8699. if (r instanceof Error) {
  8700. throw r;
  8701. }
  8702. return r;
  8703. }
  8704.  
  8705. })(JSON.parse);
  8706.  
  8707.  
  8708. })();
  8709.  
  8710.  
  8711. // << if FIX_yt_player >>
  8712.  
  8713. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  8714. const PERF_471489_ = true;
  8715. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8716. // This script uses a much gentle way to tamer the JS engine instead.
  8717.  
  8718. // << end >>
  8719.  
  8720. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8721.  
  8722.  
  8723.  
  8724. const nilFn = () => { };
  8725.  
  8726. let isMainWindow = false;
  8727. try {
  8728. isMainWindow = window.document === window.top.document
  8729. } catch (e) { }
  8730.  
  8731. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  8732. let headLinkCollection = null;
  8733.  
  8734.  
  8735. // const assertor = (f) => f() || console.assert(false, `${f}`);
  8736.  
  8737. const fnIntegrity = (f, d) => {
  8738. if (!f || typeof f !== 'function') {
  8739. console.warn('f is not a function', f);
  8740. return;
  8741. }
  8742. let p = `${f}`, s = 0, j = -1, w = 0;
  8743. for (let i = 0, l = p.length; i < l; i++) {
  8744. const t = p[i];
  8745. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8746. if (j < i - 1) w++;
  8747. j = i;
  8748. } else {
  8749. s++;
  8750. }
  8751. }
  8752. let itz = `${f.length}.${s}.${w}`;
  8753. if (!d) {
  8754. return itz;
  8755. } else {
  8756. return itz === d;
  8757. }
  8758. };
  8759.  
  8760. const getZqOu = (_yt_player) => {
  8761.  
  8762. const w = 'ZqOu';
  8763.  
  8764. let arr = [];
  8765.  
  8766. for (const [k, v] of Object.entries(_yt_player)) {
  8767.  
  8768. const p = typeof v === 'function' ? v.prototype : 0;
  8769. if (p
  8770. && typeof p.start === 'function' && p.start.length === 0 // Ou
  8771. && typeof p.isActive === 'function' && p.isActive.length === 0
  8772. && typeof p.stop === 'function' && p.stop.length === 0
  8773. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8774. && !p.send && !p.abort
  8775. && !p.sample && !p.initialize && !p.fail && !p.getName
  8776. // && !p.dispose && !p.isDisposed
  8777.  
  8778. ) {
  8779. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8780.  
  8781.  
  8782. }
  8783.  
  8784. }
  8785.  
  8786. if (arr.length === 0) {
  8787.  
  8788. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8789. } else {
  8790.  
  8791. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8792. return arr[0];
  8793. }
  8794.  
  8795. }
  8796.  
  8797. const getZqQu = (_yt_player) => {
  8798.  
  8799. const w = 'ZqQu';
  8800.  
  8801. let arr = [];
  8802.  
  8803.  
  8804. for (const [k, v] of Object.entries(_yt_player)) {
  8805.  
  8806. const p = typeof v === 'function' ? v.prototype : 0;
  8807. if (p
  8808. && typeof p.start === 'function' && p.start.length === 1 // Qu
  8809. && typeof p.isActive === 'function' && p.isActive.length === 0
  8810. && typeof p.stop === 'function' && p.stop.length === 0
  8811. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8812. && !p.send && !p.abort
  8813. && !p.sample && !p.initialize && !p.fail && !p.getName
  8814. // && !p.dispose && !p.isDisposed
  8815.  
  8816. ) {
  8817. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8818.  
  8819.  
  8820. }
  8821.  
  8822. }
  8823.  
  8824. if (arr.length === 0) {
  8825.  
  8826. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8827. } else {
  8828.  
  8829. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8830. return arr[0];
  8831. }
  8832.  
  8833. }
  8834.  
  8835.  
  8836. const getVG = (_yt_player) => {
  8837. const w = 'VG';
  8838.  
  8839. let arr = [];
  8840.  
  8841. for (const [k, v] of Object.entries(_yt_player)) {
  8842.  
  8843. const p = typeof v === 'function' ? v.prototype : 0;
  8844. if (p
  8845. && typeof p.show === 'function' && p.show.length === 1
  8846. && typeof p.hide === 'function' && p.hide.length === 0
  8847. && typeof p.stop === 'function' && p.stop.length === 0) {
  8848.  
  8849. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8850.  
  8851. }
  8852.  
  8853. }
  8854.  
  8855.  
  8856. if (arr.length === 0) {
  8857.  
  8858. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8859. } else {
  8860.  
  8861. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8862. return arr[0];
  8863. }
  8864.  
  8865.  
  8866.  
  8867. }
  8868.  
  8869.  
  8870. const getzo = (_yt_player) => {
  8871. const w = 'zo';
  8872.  
  8873. let arr = [];
  8874.  
  8875. for (const [k, v] of Object.entries(_yt_player)) {
  8876.  
  8877. if (
  8878. typeof v === 'function' && v.length === 3 && k.length < 3
  8879. ) {
  8880. const vt = `${v}`;
  8881. if (vt.length >= 21 && vt.includes(".style[")) {
  8882. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  8883. arr.push(k);
  8884. } else {
  8885. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  8886. }
  8887. }
  8888. }
  8889.  
  8890. }
  8891.  
  8892. if (arr.length === 0) {
  8893.  
  8894. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8895. } else {
  8896.  
  8897. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8898. return arr[0];
  8899. }
  8900.  
  8901. }
  8902.  
  8903. const addProtoToArr = (parent, key, arr) => {
  8904.  
  8905.  
  8906. let isChildProto = false;
  8907. for (const sr of arr) {
  8908. if (parent[key].prototype instanceof parent[sr]) {
  8909. isChildProto = true;
  8910. break;
  8911. }
  8912. }
  8913.  
  8914. if (isChildProto) return;
  8915.  
  8916. arr = arr.filter(sr => {
  8917. if (parent[sr].prototype instanceof parent[key]) {
  8918. return false;
  8919. }
  8920. return true;
  8921. });
  8922.  
  8923. arr.push(key);
  8924.  
  8925. return arr;
  8926.  
  8927.  
  8928. }
  8929.  
  8930. const getuG = (_yt_player) => {
  8931.  
  8932. const w = 'uG';
  8933.  
  8934. let arr = [];
  8935.  
  8936. for (const [k, v] of Object.entries(_yt_player)) {
  8937.  
  8938.  
  8939. const p = typeof v === 'function' ? v.prototype : 0;
  8940.  
  8941. if (p
  8942. && typeof p.createElement === 'function' && p.createElement.length === 2
  8943. && typeof p.detach === 'function' && p.detach.length === 0
  8944. && typeof p.update === 'function' && p.update.length === 1
  8945. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  8946. ) {
  8947.  
  8948. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8949.  
  8950. }
  8951.  
  8952. }
  8953.  
  8954.  
  8955.  
  8956.  
  8957.  
  8958. if (arr.length === 0) {
  8959.  
  8960. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8961. } else {
  8962.  
  8963. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8964. return arr[0];
  8965. }
  8966.  
  8967. }
  8968.  
  8969.  
  8970. const getQT = (_yt_player) => {
  8971. const w = 'QT';
  8972.  
  8973. let arr = [];
  8974. let brr = new Map();
  8975.  
  8976. for (const [k, v] of Object.entries(_yt_player)) {
  8977.  
  8978. const p = typeof v === 'function' ? v.prototype : 0;
  8979. if (p) {
  8980. let q = 0;
  8981. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8982. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8983. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8984.  
  8985. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8986.  
  8987. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8988.  
  8989. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8990. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8991. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8992. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8993.  
  8994.  
  8995. // differentiate QT and DX
  8996.  
  8997. q += 280;
  8998. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  8999. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  9000. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  9001. if (typeof p.seekBy === 'function') q += 4;
  9002. if (typeof p.seekTo === 'function') q += 4;
  9003. if (typeof p.getStoryboardFormat === 'function') q += 4;
  9004. if (typeof p.getDuration === 'function') q += 4;
  9005. if (typeof p.loadModule === 'function') q += 4;
  9006. if (typeof p.unloadModule === 'function') q += 4;
  9007. if (typeof p.getOption === 'function') q += 4;
  9008. if (typeof p.getOptions === 'function') q += 4;
  9009. if (typeof p.setOption === 'function') q += 4;
  9010. if (typeof p.addCueRange === 'function') q += 4;
  9011. if (typeof p.getDebugText === 'function') q += 4;
  9012. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  9013. if (typeof p.setSizeStyle === 'function') q += 4;
  9014. if (typeof p.showControls === 'function') q += 4;
  9015. if (typeof p.hideControls === 'function') q += 4;
  9016. if (typeof p.getVideoContentRect === 'function') q += 4;
  9017. if (typeof p.toggleFullscreen === 'function') q += 4;
  9018. if (typeof p.isFullscreen === 'function') q += 4;
  9019. if (typeof p.cancelPlayback === 'function') q += 4;
  9020. if (typeof p.getProgressState === 'function') q += 4;
  9021. if (typeof p.isInline === 'function') q += 4;
  9022. if (typeof p.setInline === 'function') q += 4;
  9023. if (typeof p.toggleSubtitles === 'function') q += 4;
  9024. if (typeof p.getPlayerSize === 'function') q += 4;
  9025. if (typeof p.wakeUpControls === 'function') q += 4;
  9026. if (typeof p.setCenterCrop === 'function') q += 4;
  9027. if (typeof p.getLoopVideo === 'function') q += 4;
  9028. if (typeof p.setLoopVideo === 'function') q += 4;
  9029.  
  9030.  
  9031. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9032.  
  9033. if (q > 0) brr.set(k, q);
  9034.  
  9035. }
  9036.  
  9037. }
  9038.  
  9039. if (arr.length === 0) {
  9040.  
  9041. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9042. } else {
  9043.  
  9044. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9045.  
  9046. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9047.  
  9048. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9049. return arr[0][0];
  9050. }
  9051.  
  9052.  
  9053.  
  9054. }
  9055.  
  9056.  
  9057.  
  9058. const getSV = (_yt_player) => {
  9059. const w = 'SV';
  9060.  
  9061. let arr = [];
  9062. let brr = new Map();
  9063.  
  9064. for (const [k, v] of Object.entries(_yt_player)) {
  9065.  
  9066. const p = typeof v === 'function' ? v.prototype : 0;
  9067. if (p) {
  9068. let q = 0;
  9069. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9070. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9071. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9072.  
  9073. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  9074.  
  9075. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9076.  
  9077. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9078. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9079. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9080. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9081.  
  9082.  
  9083. // differentiate QT and DX
  9084.  
  9085.  
  9086. q += 280;
  9087.  
  9088. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9089. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9090. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9091. if (typeof p.seekBy === 'function') q -= 4;
  9092. if (typeof p.seekTo === 'function') q -= 4;
  9093. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9094. if (typeof p.getDuration === 'function') q -= 4;
  9095. if (typeof p.loadModule === 'function') q -= 4;
  9096. if (typeof p.unloadModule === 'function') q -= 4;
  9097. if (typeof p.getOption === 'function') q -= 4;
  9098. if (typeof p.getOptions === 'function') q -= 4;
  9099. if (typeof p.setOption === 'function') q -= 4;
  9100. if (typeof p.addCueRange === 'function') q -= 4;
  9101. if (typeof p.getDebugText === 'function') q -= 4;
  9102. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9103. if (typeof p.setSizeStyle === 'function') q -= 4;
  9104. if (typeof p.showControls === 'function') q -= 4;
  9105. if (typeof p.hideControls === 'function') q -= 4;
  9106. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9107. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9108. if (typeof p.isFullscreen === 'function') q -= 4;
  9109. if (typeof p.cancelPlayback === 'function') q -= 4;
  9110. if (typeof p.getProgressState === 'function') q -= 4;
  9111. if (typeof p.isInline === 'function') q -= 4;
  9112. if (typeof p.setInline === 'function') q -= 4;
  9113. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9114. if (typeof p.getPlayerSize === 'function') q -= 4;
  9115. if (typeof p.wakeUpControls === 'function') q -= 4;
  9116. if (typeof p.setCenterCrop === 'function') q -= 4;
  9117. if (typeof p.getLoopVideo === 'function') q -= 4;
  9118. if (typeof p.setLoopVideo === 'function') q -= 4;
  9119.  
  9120.  
  9121. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9122.  
  9123. if (q > 0) brr.set(k, q);
  9124.  
  9125. }
  9126.  
  9127. }
  9128.  
  9129. if (arr.length === 0) {
  9130.  
  9131. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9132. } else {
  9133.  
  9134. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9135.  
  9136. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9137.  
  9138. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9139. return arr[0][0];
  9140. }
  9141.  
  9142.  
  9143.  
  9144. }
  9145.  
  9146.  
  9147.  
  9148.  
  9149. const getDX = (_yt_player) => {
  9150. const w = 'DX';
  9151.  
  9152. let arr = [];
  9153. let brr = new Map();
  9154.  
  9155. for (const [k, v] of Object.entries(_yt_player)) {
  9156.  
  9157. const p = typeof v === 'function' ? v.prototype : 0;
  9158. if (p) {
  9159. let q = 0;
  9160. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9161. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9162. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9163.  
  9164. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9165.  
  9166.  
  9167. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  9168.  
  9169. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9170.  
  9171. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9172. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9173. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9174. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9175.  
  9176.  
  9177. // differentiate QT and DX
  9178.  
  9179.  
  9180. q += 280;
  9181.  
  9182. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9183. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9184. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9185. if (typeof p.seekBy === 'function') q -= 4;
  9186. if (typeof p.seekTo === 'function') q -= 4;
  9187. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9188. if (typeof p.getDuration === 'function') q -= 4;
  9189. if (typeof p.loadModule === 'function') q -= 4;
  9190. if (typeof p.unloadModule === 'function') q -= 4;
  9191. if (typeof p.getOption === 'function') q -= 4;
  9192. if (typeof p.getOptions === 'function') q -= 4;
  9193. if (typeof p.setOption === 'function') q -= 4;
  9194. if (typeof p.addCueRange === 'function') q -= 4;
  9195. if (typeof p.getDebugText === 'function') q -= 4;
  9196. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9197. if (typeof p.setSizeStyle === 'function') q -= 4;
  9198. if (typeof p.showControls === 'function') q -= 4;
  9199. if (typeof p.hideControls === 'function') q -= 4;
  9200. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9201. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9202. if (typeof p.isFullscreen === 'function') q -= 4;
  9203. if (typeof p.cancelPlayback === 'function') q -= 4;
  9204. if (typeof p.getProgressState === 'function') q -= 4;
  9205. if (typeof p.isInline === 'function') q -= 4;
  9206. if (typeof p.setInline === 'function') q -= 4;
  9207. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9208. if (typeof p.getPlayerSize === 'function') q -= 4;
  9209. if (typeof p.wakeUpControls === 'function') q -= 4;
  9210. if (typeof p.setCenterCrop === 'function') q -= 4;
  9211. if (typeof p.getLoopVideo === 'function') q -= 4;
  9212. if (typeof p.setLoopVideo === 'function') q -= 4;
  9213.  
  9214.  
  9215. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9216.  
  9217. if (q > 0) brr.set(k, q);
  9218.  
  9219. }
  9220.  
  9221. }
  9222.  
  9223. if (arr.length === 0) {
  9224.  
  9225. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9226. } else {
  9227.  
  9228. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9229.  
  9230. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9231.  
  9232. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9233. return arr[0][0];
  9234. }
  9235.  
  9236.  
  9237.  
  9238. }
  9239.  
  9240.  
  9241.  
  9242. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  9243.  
  9244. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  9245. let pageSetupState = 0;
  9246.  
  9247. isPrepareCachedV && (() => {
  9248.  
  9249. pageSetupVideoId = '';
  9250. const clearCachedV = () => {
  9251. pageSetupVideoId = '';
  9252. pageSetupState = 0;
  9253. }
  9254. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  9255. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  9256. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  9257. document.addEventListener('yt-navigate-finish', () => {
  9258. pageSetupState = 1;
  9259. try {
  9260. const url = new URL(location.href);
  9261. if (!url || !isWatchPageURL(url)) {
  9262. pageSetupVideoId = '';
  9263. } else {
  9264. pageSetupVideoId = url.searchParams.get('v') || '';
  9265. }
  9266. } catch (e) {
  9267. pageSetupVideoId = '';
  9268. }
  9269. }, false);
  9270.  
  9271. })();
  9272.  
  9273. let videoPlayingY = null;
  9274.  
  9275. isPrepareCachedV && (() => {
  9276.  
  9277. let getNext = true;
  9278. let videoPlayingX = {
  9279. get videoId() {
  9280. if (getNext) {
  9281. getNext = false;
  9282.  
  9283. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  9284. const arr = [];
  9285. for (const element of elements) {
  9286. if (!element.closest('[hidden]')) arr.push(element);
  9287. }
  9288. if (arr.length !== 1) this.__videoId__ = '';
  9289. else {
  9290. this.__videoId__ = arr[0].getAttribute('video-id');
  9291. }
  9292.  
  9293. }
  9294. return this.__videoId__ || '';
  9295. }
  9296. }
  9297.  
  9298. videoPlayingY = videoPlayingX;
  9299. const handler = (evt) => {
  9300. const target = (evt || 0).target;
  9301. if (target instanceof HTMLVideoElement) {
  9302. getNext = true;
  9303. }
  9304. }
  9305. document.addEventListener('loadedmetadata', handler, true);
  9306. document.addEventListener('durationchange', handler, true);
  9307.  
  9308. })();
  9309.  
  9310.  
  9311.  
  9312. const cleanContext = async (win) => {
  9313. const waitFn = requestAnimationFrame; // shall have been binded to window
  9314. try {
  9315. let mx = 16; // MAX TRIAL
  9316. const frameId = 'vanillajs-iframe-v1';
  9317. /** @type {HTMLIFrameElement | null} */
  9318. let frame = document.getElementById(frameId);
  9319. let removeIframeFn = null;
  9320. if (!frame) {
  9321. frame = document.createElement('iframe');
  9322. frame.id = frameId;
  9323. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  9324. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  9325. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  9326. n.appendChild(frame);
  9327. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  9328. const root = document.documentElement;
  9329. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  9330. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  9331.  
  9332. removeIframeFn = (setTimeout) => {
  9333. const removeIframeOnDocumentReady = (e) => {
  9334. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9335. e = n;
  9336. n = win = removeIframeFn = 0;
  9337. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  9338. }
  9339. if (!setTimeout || document.readyState !== 'loading') {
  9340. removeIframeOnDocumentReady();
  9341. } else {
  9342. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9343. }
  9344. }
  9345. }
  9346. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  9347. const fc = frame.contentWindow;
  9348. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  9349. try {
  9350. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  9351. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  9352. for (let k in res) res[k] = res[k].bind(win); // necessary
  9353. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  9354. res.animate = fc.HTMLElement.prototype.animate;
  9355. res.perfNow = fc.performance.now;
  9356. return res;
  9357. } catch (e) {
  9358. if (removeIframeFn) removeIframeFn();
  9359. return null;
  9360. }
  9361. } catch (e) {
  9362. console.warn(e);
  9363. return null;
  9364. }
  9365. };
  9366.  
  9367. const promiseForYtActionCalled = new Promise(resolve => {
  9368.  
  9369. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9370. if (typeof AbortSignal !== 'undefined') {
  9371. let hn = () => {
  9372. if (!hn) return;
  9373. hn = null;
  9374. resolve(document.querySelector(appTag));
  9375. };
  9376. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  9377. } else {
  9378. let hn = () => {
  9379. if (!hn) return;
  9380. document.removeEventListener('yt-action', hn, true);
  9381. hn = null;
  9382. resolve(document.querySelector(appTag));
  9383. };
  9384. document.addEventListener('yt-action', hn, true);
  9385. }
  9386. });
  9387.  
  9388. cleanContext(window).then(__CONTEXT__ => {
  9389. if (!__CONTEXT__) return null;
  9390.  
  9391. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  9392.  
  9393.  
  9394. performance.now17 = perfNow.bind(performance);
  9395.  
  9396.  
  9397.  
  9398. __requestAnimationFrame__ = requestAnimationFrame;
  9399.  
  9400.  
  9401. const isGPUAccelerationAvailable = (() => {
  9402. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  9403. try {
  9404. const canvas = document.createElement('canvas');
  9405. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  9406. } catch (e) {
  9407. return false;
  9408. }
  9409. })();
  9410.  
  9411. const foregroundPromiseFn_noGPU = (() => {
  9412.  
  9413. if (isGPUAccelerationAvailable) return null;
  9414.  
  9415. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  9416. if (!pd || typeof pd.get !== 'function') return null;
  9417. const pdGet = pd.get;
  9418.  
  9419. let pr = null;
  9420.  
  9421. let hState = pdGet.call(document) === 'hidden';
  9422. // let cid = 0;
  9423. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  9424. const newHState = pdGet.call(document) === 'hidden';
  9425. if (hState !== newHState) {
  9426. // if (cid > 0) cid = clearInterval(cid);
  9427. hState = newHState;
  9428. if (!hState && pr) pr = pr.resolve();
  9429. }
  9430. });
  9431.  
  9432. // cid = setInterval(() => {
  9433. // const newHState = document.visibilityState === 'hidden';
  9434. // if (hState !== newHState) {
  9435. // hState = newHState;
  9436. // if (!hState && pr) pr = pr.resolve();
  9437. // }
  9438. // }, 100);
  9439.  
  9440.  
  9441. return (() => {
  9442. if (pr) return pr;
  9443. const w = ((!hState && setTimeout(() => {
  9444. if (!hState && pr === w) pr = pr.resolve();
  9445. })), (pr = new PromiseExternal()));
  9446. return w;
  9447. });
  9448.  
  9449. })();
  9450.  
  9451.  
  9452. let rafPromise = null;
  9453. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  9454. requestAnimationFrame(hRes => {
  9455. rafPromise = null;
  9456. resolve(hRes);
  9457. });
  9458. }));
  9459.  
  9460. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  9461.  
  9462.  
  9463. const wmComputedStyle = new WeakMap();
  9464.  
  9465. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  9466. window.__native__getComputedStyle__ = getComputedStyle;
  9467. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  9468. window.__original__getComputedStyle__ = window.getComputedStyle;
  9469. window.getComputedStyle = function (elem) {
  9470. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  9471. return window.__original__getComputedStyle__(...arguments);
  9472. }
  9473. let cs = wmComputedStyle.get(elem);
  9474. if (!cs) {
  9475. cs = window.__native__getComputedStyle__(elem);
  9476. wmComputedStyle.set(elem, cs);
  9477. }
  9478. return cs;
  9479. };
  9480. } else {
  9481. window.__original__getComputedStyle__ = null;
  9482. }
  9483. window.__jst__getComputedStyle__ = window.getComputedStyle;
  9484. }
  9485.  
  9486. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  9487. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  9488. window.getComputedStyle = window.__jst__getComputedStyle__;
  9489. }
  9490. });
  9491.  
  9492. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  9493. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  9494.  
  9495. const promiseForTamerTimeout = new Promise(resolve => {
  9496. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9497. setTimeout(resolve, 480);
  9498. }, { capture: true, passive: true, once: true });
  9499. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9500. setTimeout(resolve, 1200);
  9501. });
  9502. setTimeout(resolve, 3000);
  9503. });
  9504.  
  9505. const promiseForPageInitied = new Promise(resolve => {
  9506. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9507. setTimeout(resolve, 450);
  9508. }, { capture: true, passive: true, once: true });
  9509. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9510. setTimeout(resolve, 900);
  9511. });
  9512. setTimeout(resolve, 1800);
  9513. });
  9514.  
  9515. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  9516. NO_PRELOAD_GENERATE_204_BYPASS = true;
  9517. headLinkCollection = null;
  9518. });
  9519.  
  9520.  
  9521. NATIVE_CANVAS_ANIMATION && (() => {
  9522.  
  9523. observablePromise(() => {
  9524. HTMLCanvasElement.prototype.animate = animate;
  9525. }, promiseForTamerTimeout).obtain();
  9526.  
  9527. })();
  9528.  
  9529.  
  9530.  
  9531.  
  9532. FIX_ytAction_ && (async () => {
  9533.  
  9534. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9535.  
  9536. const ytdApp = await new Promise(resolve => {
  9537.  
  9538. whenCEDefined(appTag).then(() => {
  9539. const ytdApp = document.querySelector(appTag);
  9540. if (ytdApp) {
  9541. resolve(ytdApp);
  9542. return;
  9543. }
  9544. let mo = new MutationObserver(() => {
  9545. const ytdApp = document.querySelector(appTag);
  9546. if (!ytdApp) return;
  9547. if (mo) {
  9548. mo.disconnect();
  9549. mo.takeRecords();
  9550. mo = null;
  9551. }
  9552. resolve(ytdApp);
  9553. });
  9554. mo.observe(document, { subtree: true, childList: true });
  9555. });
  9556.  
  9557. });
  9558.  
  9559. if (!ytdApp) return;
  9560. const cProto = insp(ytdApp).constructor.prototype;
  9561.  
  9562. if (!cProto) return;
  9563. let mbd = 0;
  9564.  
  9565. const fixer = (_ytdApp) => {
  9566. const ytdApp = insp(_ytdApp);
  9567. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9568. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9569. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9570. mbd++;
  9571. }
  9572. }
  9573.  
  9574. observablePromise(() => {
  9575.  
  9576. if (typeof cProto.created === 'function' && !cProto.created56) {
  9577. cProto.created56 = cProto.created;
  9578. cProto.created = function (...args) {
  9579. const r = this.created56(...args);
  9580. fixer(this);
  9581. return r;
  9582. };
  9583. mbd++;
  9584. }
  9585.  
  9586. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9587. cProto.onYtAction57_ = cProto.onYtAction_;
  9588. cProto.onYtAction_ = function (...args) {
  9589. Promise.resolve().then(() => this.onYtAction57_(...args));
  9590. };
  9591. mbd++;
  9592. }
  9593.  
  9594. if (ytdApp) fixer(ytdApp);
  9595.  
  9596. /*
  9597. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9598. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9599. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9600. actionRouter_.handleAction = function (...args) {
  9601. Promise.resolve().then(() => this.handleAction57(...args));
  9602. }
  9603. mbd++;
  9604. }
  9605. */
  9606.  
  9607. // if(mbd === 3) return 1;
  9608. if (mbd >= 3) return 1;
  9609.  
  9610. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9611.  
  9612. })();
  9613.  
  9614.  
  9615. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9616.  
  9617. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9618.  
  9619. const app = await observablePromise(() => {
  9620.  
  9621. return document.querySelector(appTag);
  9622.  
  9623. }).obtain();
  9624.  
  9625. if (!app) return;
  9626.  
  9627. const appCnt = insp(app);
  9628. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9629.  
  9630.  
  9631.  
  9632.  
  9633. });
  9634.  
  9635.  
  9636. // let _yt_player_promise = null;
  9637. /*
  9638. const getYtPlayerPromise = () => {
  9639. if (!_yt_player_promise) {
  9640. _yt_player_promise = new Promise(resolve => {
  9641. let cid = setInterval(() => {
  9642. let t = (((window || 0)._yt_player || 0) || 0);
  9643. if (t) {
  9644. clearInterval(cid);
  9645. resolve(t);
  9646. }
  9647. }, 1);
  9648. promiseForTamerTimeout.then(() => {
  9649. resolve(null)
  9650. });
  9651. });
  9652. }
  9653. return _yt_player_promise;
  9654. }
  9655. */
  9656. const _yt_player_observable = observablePromise(() => {
  9657. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9658. if (_yt_player) {
  9659. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9660. return _yt_player;
  9661. }
  9662. }, promiseForTamerTimeout);
  9663.  
  9664. const polymerObservable = observablePromise(() => {
  9665. const Polymer = window.Polymer;
  9666. if (typeof Polymer !== 'function') return;
  9667. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9668. return Polymer;
  9669. }, promiseForTamerTimeout);
  9670.  
  9671. const schedulerInstanceObservable = observablePromise(() => {
  9672. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9673. }, promiseForTamerTimeout);
  9674.  
  9675. const timelineObservable = observablePromise(() => {
  9676. let t = (((document || 0).timeline || 0) || 0);
  9677. if (t && typeof t._play === 'function') {
  9678. return t;
  9679. }
  9680. }, promiseForTamerTimeout);
  9681. const animationObservable = observablePromise(() => {
  9682. let t = (((window || 0).Animation || 0) || 0);
  9683. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9684. return t;
  9685. }
  9686. }, promiseForTamerTimeout);
  9687.  
  9688.  
  9689. const getScreenInfo = {
  9690. screenWidth: 0,
  9691. screenHeight: 0,
  9692. valueReady: false,
  9693. onResize: () => {
  9694. getScreenInfo.valueReady = false;
  9695. },
  9696. sizeProvided: () => {
  9697. if (getScreenInfo.valueReady) return true;
  9698. getScreenInfo.screenWidth = screen.width;
  9699. getScreenInfo.screenHeight = screen.height;
  9700. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9701. getScreenInfo.valueReady = true;
  9702. return true;
  9703. }
  9704. return false;
  9705. }
  9706. };
  9707.  
  9708. window.addEventListener('resize', getScreenInfo.onResize, true);
  9709.  
  9710.  
  9711. // const hookLeftPending = new WeakMap();
  9712.  
  9713. const isNaNx = Number.isNaN;
  9714.  
  9715. const hookLeftPD = {
  9716. get() {
  9717. const p = 'left';
  9718. // const o = hookLeftPending.get(this);
  9719. // if (o && o.key) {
  9720. // this.setProperty(p, o.value);
  9721. // o.key = null
  9722. // }
  9723. return this.getPropertyValue(p);
  9724. },
  9725. set(v) {
  9726.  
  9727. const p = 'left';
  9728. const cv = this.getPropertyValue(p);
  9729. const sv = v;
  9730.  
  9731. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  9732.  
  9733. // console.log(8380,did, cv, sv)
  9734. if (!cv && !sv) return true;
  9735. if (cv === sv) return true;
  9736.  
  9737. // skip 0~9px => L>=4
  9738.  
  9739. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  9740.  
  9741. if (!isNaNx(qsv)) {
  9742. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  9743.  
  9744. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  9745. const { screenWidth, screenHeight } = getScreenInfo;
  9746. let pWidth = screenWidth + 1024;
  9747. let pHeight = screenHeight + 768;
  9748. const minRatio = 0.003;
  9749. const dw = pWidth * 0.0003; // min dw = 0.3072
  9750. const dh = pHeight * 0.0003; // min dh = 0.2304
  9751. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  9752. if (Math.abs(qcv - qsv) < dw) return true;
  9753. }
  9754.  
  9755. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  9756. if (`${v}`.length > `${sv}`.length) v = sv;
  9757. // console.log(8382, did, sv, nv, cv, this)
  9758. }
  9759.  
  9760. // Promise.resolve().then(() => {
  9761. // const o = hookLeftPending.get(this);
  9762. // if (o && o.key === did) {
  9763. // this.setProperty(p, o.value);
  9764. // o.key = null;
  9765. // }
  9766. // });
  9767. // hookLeftPending.set(this, {
  9768. // key: did,
  9769. // value: nv
  9770. // });
  9771.  
  9772. // if (nv != v) {
  9773. // console.log(8387, v, nv);
  9774. // }
  9775.  
  9776. this.setProperty(p, v);
  9777. // console.log(8383, did, this.getPropertyValue(p))
  9778. return true;
  9779. },
  9780. enumerable: true,
  9781. configurable: true
  9782. };
  9783.  
  9784.  
  9785. if (HOOK_CSSPD_LEFT) {
  9786.  
  9787.  
  9788. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  9789.  
  9790. }
  9791.  
  9792.  
  9793.  
  9794.  
  9795.  
  9796. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  9797.  
  9798. const evKey = `${_evKey}`;
  9799. const fvKey = `${_fvKey}`;
  9800. const debug = !!_debug;
  9801.  
  9802. const _yt_player = await _yt_player_observable.obtain();
  9803.  
  9804.  
  9805. if (!_yt_player || typeof _yt_player !== 'object') return;
  9806.  
  9807.  
  9808. const getArr = (_yt_player) => {
  9809.  
  9810. let arr = [];
  9811.  
  9812. for (const [k, v] of Object.entries(_yt_player)) {
  9813.  
  9814. const p = typeof v === 'function' ? v.prototype : 0;
  9815. if (p
  9816. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  9817.  
  9818. ) {
  9819. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9820.  
  9821. }
  9822.  
  9823. }
  9824.  
  9825. if (arr.length === 0) {
  9826.  
  9827. console.warn(`Key prop [${evKey}] does not exist.`);
  9828. } else {
  9829.  
  9830. return arr;
  9831. }
  9832.  
  9833. };
  9834.  
  9835. const arr = getArr(_yt_player);
  9836.  
  9837.  
  9838. if (!arr) return;
  9839.  
  9840. debug && console.log(`FIX_${evKey}`, arr);
  9841.  
  9842. const f = function (...args) {
  9843. Promise.resolve().then(() => this[fvKey](...args));
  9844. };
  9845.  
  9846.  
  9847. for (const k of arr) {
  9848.  
  9849. const g = _yt_player;
  9850. const gk = g[k];
  9851. const gkp = gk.prototype;
  9852.  
  9853. debug && console.log(237, k, gkp)
  9854.  
  9855. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  9856. gkp[fvKey] = gkp[evKey];
  9857. gkp[evKey] = f;
  9858. }
  9859. }
  9860.  
  9861.  
  9862.  
  9863.  
  9864. }
  9865.  
  9866. if (!isChatRoomURL) {
  9867.  
  9868. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  9869. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  9870. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  9871. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  9872. if (FIX_VideoEVENTS_v2) {
  9873. const FIX_VideoEVENTS_DEBUG = 0;
  9874. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  9875. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  9876. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  9877. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  9878. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  9879. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  9880. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  9881. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  9882. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  9883.  
  9884. }
  9885. // onMutedAutoplayChange
  9886. // onVolumeChange
  9887. // onPlaybackRateChange
  9888.  
  9889. // onAirPlayActiveChange
  9890. // onAirPlayAvailabilityChange
  9891. // onApiChange
  9892. // onAutoplayBlocked
  9893. // onDrmOutputRestricted
  9894. // onFullscreenChange
  9895. // onLoadProgress
  9896. // onLoadedMetadata
  9897. // onVideoDataChange
  9898. // onVideoProgress
  9899.  
  9900. }
  9901.  
  9902.  
  9903. let isAmended_Polymer_RenderStatus = false;
  9904.  
  9905. (FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  9906.  
  9907. const Polymer = await polymerObservable.obtain();
  9908. if (!Polymer) return;
  9909.  
  9910. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  9911. isAmended_Polymer_RenderStatus = true;
  9912.  
  9913. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  9914. let arrBefore = null, arrAfter = null;
  9915. const push = Array.prototype.push;
  9916. let arr = null;
  9917. Array.prototype.push = function () {
  9918. arr = this;
  9919. }
  9920. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  9921. if (arr) arrBefore = arr;
  9922. arr = null;
  9923. Polymer.RenderStatus.afterNextRender({}, {}, {});
  9924. if (arr) arrAfter = arr;
  9925. arr = null;
  9926. Array.prototype.push = push;
  9927. Polymer.RenderStatus.arrBefore = arrBefore;
  9928. Polymer.RenderStatus.arrAfter = arrAfter;
  9929.  
  9930. if (arrBefore && arrAfter) {
  9931.  
  9932. Function.prototype.call7900 = Function.prototype.call;
  9933. Function.prototype.apply7900 = Function.prototype.apply;
  9934. Function.prototype.apply7948 = function (obj, args) {
  9935. const f = this;
  9936. let m = kRef(obj);
  9937. if (!m) return;
  9938. if (m.is && !m.nodeName) {
  9939. if (!m.isAttached || !m.hostElement) {
  9940. return;
  9941. }
  9942. }
  9943. try {
  9944. return !args ? f.call7900(m) : f.apply7900(m, args);
  9945. } catch (e) {
  9946. console.warn(e);
  9947. }
  9948. return null;
  9949. }
  9950.  
  9951. arrBefore.push = arrAfter.push = function (a) {
  9952. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  9953. if (a[0].deref) a[0] = kRef(a[0]);
  9954. const f = a[1]
  9955. const obj = a[0]
  9956. const args = a[2];
  9957. f.apply = f.apply7948;
  9958. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  9959. a[0] = obj[wk]
  9960. // console.log(4992, a)
  9961. return push.call(this, a);
  9962. }
  9963.  
  9964. }
  9965.  
  9966.  
  9967. }
  9968. // Polymer.RenderStatus.beforeNextRender
  9969. }
  9970.  
  9971. if (FIX_Polymer_dom) {
  9972.  
  9973. const checkPDFuncValue = (pd) => {
  9974. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  9975. }
  9976. const checkPDFuncValue2 = (pd) => {
  9977. return pd && typeof pd.value == 'function'
  9978. }
  9979.  
  9980. const checkPDFuncGet = (pd) => {
  9981. return pd && typeof pd.get == 'function'
  9982. }
  9983.  
  9984. const domX = Polymer.dom(document.createElement('null'));
  9985. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  9986. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  9987. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  9988. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  9989. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  9990. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  9991. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  9992. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  9993. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  9994.  
  9995.  
  9996. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  9997.  
  9998. domXP.querySelector15 = domXP.querySelector;
  9999.  
  10000. const querySelectorFn = function (query) {
  10001. try {
  10002. const p = this.node;
  10003.  
  10004. if (p instanceof Document && p.isConnected === true) {
  10005. return pd4b.value.call(p, query);
  10006. }
  10007.  
  10008. } catch (e) { }
  10009. return this.querySelector15(query);
  10010. }
  10011.  
  10012. Object.defineProperty(domXP, 'querySelector', {
  10013. get() {
  10014. return querySelectorFn;
  10015. },
  10016. set(nv) {
  10017. if (nv === querySelectorFn) return true;
  10018. this.querySelector15 = nv;
  10019. return true;
  10020. },
  10021.  
  10022. enumerable: false,
  10023. configurable: true
  10024. });
  10025.  
  10026. Polymer.__fixedQuerySelector__ = 1;
  10027. }
  10028.  
  10029. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  10030.  
  10031. domXP.querySelectorAll15 = domXP.querySelectorAll;
  10032.  
  10033. const querySelectorAllFn = function (query) {
  10034.  
  10035. try {
  10036.  
  10037. const p = this.node;
  10038.  
  10039. if (p instanceof Document && p.isConnected === true) {
  10040. return pd6b.value.call(p, query);
  10041. }
  10042.  
  10043. } catch (e) {
  10044.  
  10045. }
  10046. return this.querySelectorAll15(query);
  10047. }
  10048.  
  10049. Object.defineProperty(domXP, 'querySelectorAll', {
  10050. get() {
  10051. return querySelectorAllFn;
  10052. },
  10053. set(nv) {
  10054. if (nv === querySelectorAllFn) return true;
  10055. this.querySelectorAll15 = nv;
  10056. return true;
  10057. },
  10058.  
  10059. enumerable: false,
  10060. configurable: true
  10061. });
  10062.  
  10063. Polymer.__fixedQuerySelectorAll__ = 1;
  10064. }
  10065. }
  10066.  
  10067.  
  10068. if (FIX_stampDomArray) {
  10069.  
  10070. Polymer.Base.__connInit__ = function () {
  10071. setupYtComponent(this);
  10072. }
  10073.  
  10074.  
  10075. /** @type {Function} */
  10076. const connectedCallbackK = function (...args) {
  10077. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10078. const r = this[qm53](...args);
  10079. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10080. this.mh35 = 1;
  10081. return r;
  10082. };
  10083.  
  10084. connectedCallbackK.m353 = 1;
  10085.  
  10086.  
  10087. const qt53 = Polymer.Base.connectedCallback;
  10088. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  10089.  
  10090. Polymer.Base.connectedCallback = connectedCallbackK;
  10091.  
  10092.  
  10093. /** @type {Function} */
  10094. const createdK = function (...args) {
  10095. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10096. const r = this[qn53](...args);
  10097. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10098. this.mh36 = 1;
  10099. return r;
  10100. };
  10101.  
  10102.  
  10103. createdK.m353 = 1;
  10104. Polymer.Base[qn53] = Polymer.Base.created;
  10105. Polymer.Base.created = createdK;
  10106.  
  10107.  
  10108.  
  10109.  
  10110.  
  10111.  
  10112.  
  10113.  
  10114.  
  10115.  
  10116.  
  10117. }
  10118.  
  10119. })();
  10120.  
  10121.  
  10122. /*
  10123.  
  10124. e.nativeAppendChild = d.prototype.appendChild,
  10125. d.prototype.appendChild = function(h) {
  10126. return function(l) {
  10127. if (l instanceof DocumentFragment) {
  10128. var m = Array.from(l.children);
  10129. l = h.nativeAppendChild.call(this, l);
  10130. if (this.isConnected) {
  10131. m = g(m);
  10132. for (var p = m.next(); !p.done; p = m.next())
  10133. YD(p.value)
  10134. }
  10135. return l
  10136. }
  10137. m = l instanceof Element && l.isConnected;
  10138. p = h.nativeAppendChild.call(this, l);
  10139. m && ZD(l);
  10140. this.isConnected && YD(l);
  10141. return p
  10142. }
  10143. }(e),
  10144.  
  10145. */
  10146.  
  10147. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  10148.  
  10149. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  10150. if (f) Node.prototype.appendChild = function (a) {
  10151. if (this instanceof Element) { // exclude DocumentFragment
  10152. try {
  10153. let checkFragmentA = (a instanceof DocumentFragment);
  10154. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  10155. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  10156. for (const node of headLinkCollection) {
  10157. if (node.rel === 'preload' && node.as === 'fetch') {
  10158. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  10159. }
  10160. }
  10161. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  10162. checkFragmentA = false;
  10163. }
  10164. if (checkFragmentA && a.firstElementChild === null) {
  10165. // no element in fragmentA
  10166. let doNormal = false;
  10167. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  10168. if (child.nodeType === 3) { doNormal = true; break; }
  10169. }
  10170. if (!doNormal) return a;
  10171. }
  10172. } catch (e) {
  10173. console.log(e);
  10174. }
  10175. }
  10176. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  10177. }
  10178.  
  10179. })();
  10180.  
  10181. if (FIX_Shady) {
  10182.  
  10183. observablePromise(() => {
  10184. const { ShadyDOM, ShadyCSS } = window;
  10185. if (ShadyDOM) {
  10186. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  10187. ShadyDOM.noPatch = true; // 1 of 10
  10188. ShadyDOM.patchOnDemand = false; // 1 of 10
  10189. ShadyDOM.preferPerformance = true; // 1 of 10
  10190. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  10191. }
  10192. if (ShadyCSS) {
  10193. ShadyCSS.nativeCss = true; // 1 of 10
  10194. ShadyCSS.nativeShadow = true; // 6 of 10
  10195. ShadyCSS.cssBuild = undefined; // 1 of 10
  10196. ShadyCSS.disableRuntime = true; // 1 of 10
  10197. }
  10198. if (ShadyDOM && ShadyCSS) return 1;
  10199. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  10200.  
  10201. }
  10202.  
  10203.  
  10204. // let schedulerInstancePropOfTimerType = '';
  10205. // let schedulerInstancePropOfTimerId = '';
  10206. (FIX_schedulerInstanceInstance & 2) && (async () => {
  10207.  
  10208. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  10209.  
  10210. if (!schedulerInstanceInstance_) return;
  10211.  
  10212. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  10213. if (checkOK) {
  10214.  
  10215. let resolveRendering = null;
  10216.  
  10217. let cmPr = new PromiseExternal();
  10218. const cm = document.createComment('0');
  10219. const cmObs = new MutationObserver(() => {
  10220. if (resolveRendering) {
  10221. resolveRendering();
  10222. resolveRendering = null;
  10223. }
  10224. cmPr.resolve();
  10225. cmPr = new PromiseExternal();
  10226. });
  10227. cmObs.observe(cm, {characterData: true})
  10228.  
  10229. let web_emulated_idle_callback_delay_val = null;
  10230.  
  10231. const getRenderIdleCallbackMs = () => {
  10232. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  10233. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  10234. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  10235. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  10236. return web_emulated_idle_callback_delay_val;
  10237. }
  10238. let isDelayRenderFn_firstCheck = true;
  10239. let isDelayRenderFn_key = null;
  10240. const isDelayRenderFn = (f) => {
  10241. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  10242. isDelayRenderFn_firstCheck = false;
  10243. if (typeof ytglobal === 'undefined') return false;
  10244. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  10245. if (!globalInstance) return false;
  10246. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  10247. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  10248. isDelayRenderFn_key = entry[0]
  10249. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  10250. return true;
  10251. }
  10252. }
  10253. return false;
  10254. }
  10255.  
  10256. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  10257.  
  10258. let requestingFn = null;
  10259. let requestingArgs = null;
  10260.  
  10261. const f = function () {
  10262. requestingFn = this.fn;
  10263. requestingArgs = [...arguments];
  10264. return 12373;
  10265. };
  10266.  
  10267. const fakeFns = [
  10268. f.bind({ fn: requestAnimationFrame }),
  10269. f.bind({ fn: setInterval }),
  10270. f.bind({ fn: setTimeout }),
  10271. f.bind({ fn: requestIdleCallback })
  10272. ];
  10273.  
  10274. let mzt = 0;
  10275.  
  10276. let _fnSelectorProp = null;
  10277. const mkFns = new Array(4);
  10278.  
  10279. /*
  10280. case 1:
  10281. var a = this.K;
  10282. this.g = this.I ? window.requestIdleCallback(a, {
  10283. timeout: 3E3
  10284. }) : window.setTimeout(a, ma);
  10285. break;
  10286. case 2:
  10287. this.g = window.setTimeout(this.M, this.N);
  10288. break;
  10289. case 3:
  10290. this.g = window.requestAnimationFrame(this.L);
  10291. break;
  10292. case 4:
  10293. this.g = window.setTimeout(this.J, 0)
  10294. }
  10295.  
  10296. */
  10297. const startFnHandler = {
  10298. get(target, prop, receiver) {
  10299. if (prop === '$$12377$$') return true;
  10300. if (prop === '$$12378$$') return target;
  10301.  
  10302. // console.log('get',prop)
  10303. return target[prop]
  10304. },
  10305. set(target, prop, value, receiver) {
  10306. // console.log('set', prop, value)
  10307.  
  10308.  
  10309. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  10310. if (value === 12373 && _fnSelectorProp) {
  10311.  
  10312. const schedulerTypeSelection = target[_fnSelectorProp];
  10313. const timerIdProp = prop;
  10314.  
  10315. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  10316. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  10317. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  10318. // schedulerInstancePropOfTimerId = timerIdProp || '';
  10319. // }
  10320.  
  10321. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  10322. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  10323. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  10324. // rare
  10325. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10326. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  10327. // often
  10328. if ((FIX_schedulerInstanceInstance & 4)) {
  10329. const f = requestingArgs[0];
  10330. const tir = ++mzt;
  10331. nextBrowserTick_(() => {
  10332. if (target[timerIdProp] === -tir) f();
  10333. });
  10334. target[_fnSelectorProp] = 940;
  10335. target[timerIdProp] = -tir;
  10336. } else {
  10337. const f = requestingArgs[0];
  10338. const tir = ++mzt;
  10339. Promise.resolve().then(() => {
  10340. if (target[timerIdProp] === -tir) f();
  10341. });
  10342. target[_fnSelectorProp] = 930;
  10343. target[timerIdProp] = -tir;
  10344. }
  10345. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  10346. // often
  10347. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  10348. cm.data = (cm.data & 7) + 1;
  10349. let renderFn = requestingArgs[0];
  10350. const resolveRendering_ = () => {
  10351. const renderFn_ = renderFn;
  10352. if (renderFn_) {
  10353. renderFn = null;
  10354. renderFn_();
  10355. }
  10356. };
  10357. resolveRendering = resolveRendering_;
  10358. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  10359. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  10360.  
  10361. // cm.data = (cm.data & 7) + 1;
  10362. // target[timerIdProp] = Math.random();
  10363.  
  10364. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  10365.  
  10366. cm.data = (cm.data & 7) + 1;
  10367.  
  10368. let renderFn = requestingArgs[0];
  10369. const resolveRendering_ = () => {
  10370. const renderFn_ = renderFn;
  10371. if (renderFn_) {
  10372. renderFn = null;
  10373. renderFn_();
  10374. }
  10375. };
  10376. resolveRendering = resolveRendering_;
  10377.  
  10378. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  10379.  
  10380.  
  10381. } else {
  10382. if (requestingFn === requestIdleCallback) {
  10383. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  10384. } else {
  10385. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10386. }
  10387. }
  10388. } else {
  10389. target[_fnSelectorProp] = 0;
  10390. target[timerIdProp] = 0;
  10391. }
  10392. } else {
  10393. target[prop] = value;
  10394. }
  10395. return true;
  10396. }
  10397. };
  10398.  
  10399. let startBusy = false;
  10400. schedulerInstanceInstance_.start = function () {
  10401. if (startBusy) return;
  10402. startBusy = true;
  10403. try {
  10404. mkFns[0] = window.requestAnimationFrame;
  10405. mkFns[1] = window.setInterval;
  10406. mkFns[2] = window.setTimeout;
  10407. mkFns[3] = window.requestIdleCallback;
  10408. const tThis = this['$$12378$$'] || this;
  10409. window.requestAnimationFrame = fakeFns[0]
  10410. window.setInterval = fakeFns[1]
  10411. window.setTimeout = fakeFns[2]
  10412. window.requestIdleCallback = fakeFns[3]
  10413. _fnSelectorProp = null;
  10414. tThis.start993.call(new Proxy(tThis, startFnHandler));
  10415. _fnSelectorProp = null;
  10416. window.requestAnimationFrame = mkFns[0];
  10417. window.setInterval = mkFns[1];
  10418. window.setTimeout = mkFns[2];
  10419. window.requestIdleCallback = mkFns[3];
  10420. } catch (e) {
  10421. console.warn(e);
  10422. }
  10423. startBusy = false;
  10424. }
  10425.  
  10426. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  10427.  
  10428. }
  10429. })();
  10430.  
  10431. FIX_yt_player && !isChatRoomURL && (async () => {
  10432.  
  10433. const fOption = 1 | 2 | 4;
  10434.  
  10435. const _yt_player = await _yt_player_observable.obtain();
  10436.  
  10437. if (!_yt_player || typeof _yt_player !== 'object') return;
  10438.  
  10439. const g = _yt_player;
  10440. let k;
  10441.  
  10442. if (fOption & 1) {
  10443.  
  10444. // rAf scheduling
  10445.  
  10446. const keyZqOu = getZqOu(_yt_player);
  10447. if (!keyZqOu) {
  10448. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  10449. return;
  10450. }
  10451. k = keyZqOu
  10452.  
  10453. const gk = g[k];
  10454. if (typeof gk !== 'function') {
  10455. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  10456. return;
  10457. }
  10458. const gkp = gk.prototype;
  10459.  
  10460. const dummyObject = new gk;
  10461. const nilFunc = () => { };
  10462.  
  10463. const nilObj = {};
  10464.  
  10465. // console.log(1111111111)
  10466.  
  10467. let keyBoolD = '';
  10468. let keyWindow = '';
  10469. let keyFuncC = '';
  10470. let keyCidj = '';
  10471.  
  10472. for (const [t, y] of Object.entries(dummyObject)) {
  10473. if (y instanceof Window) keyWindow = t;
  10474. }
  10475.  
  10476. const dummyObjectProxyHandler = {
  10477. get(target, prop) {
  10478. let v = target[prop]
  10479. if (v instanceof Window && !keyWindow) {
  10480. keyWindow = t;
  10481. }
  10482. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  10483. if (prop === keyWindow) y = {
  10484. requestAnimationFrame(f) {
  10485. return 3;
  10486. },
  10487. cancelAnimationFrame() {
  10488.  
  10489. }
  10490. }
  10491. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  10492. keyFuncC = prop;
  10493. }
  10494. // console.log('[get]', prop, typeof target[prop])
  10495.  
  10496.  
  10497. return y;
  10498. },
  10499. set(target, prop, value) {
  10500.  
  10501. if (typeof value === 'boolean' && !keyBoolD) {
  10502. keyBoolD = prop;
  10503. }
  10504. if (typeof value === 'number' && !keyCidj && value >= 2) {
  10505. keyCidj = prop;
  10506. }
  10507.  
  10508. // console.log('[set]', prop, value)
  10509. target[prop] = value;
  10510.  
  10511. return true;
  10512. }
  10513. };
  10514.  
  10515. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  10516.  
  10517. // console.log('gkp.start',gkp.start);
  10518. // console.log('gkp.stop',gkp.stop);
  10519. gkp._activation = false;
  10520.  
  10521. gkp.start = function () {
  10522. // p59 || console.log(12100)
  10523. if (!this._activation) {
  10524. this._activation = true;
  10525. foregroundPromiseFn().then(() => {
  10526. this._activation = false;
  10527. if (this[keyCidj]) {
  10528. Promise.resolve().then(this[keyFuncC]);
  10529. }
  10530. });
  10531. }
  10532. this[keyCidj] = 1;
  10533. this[keyBoolD] = true;
  10534. };
  10535.  
  10536. gkp.stop = function () {
  10537. this[keyCidj] = null;
  10538. };
  10539.  
  10540.  
  10541. /*
  10542. g[k].start = function() {
  10543. this.stop();
  10544. this.D = true;
  10545. var a = requestAnimationFrame
  10546. , b = cancelAnimationFrame;
  10547. this.j = a.call(this.B, this.C)
  10548. }
  10549. ;
  10550. g[k].stop = function() {
  10551. if (this.isActive()) {
  10552. var a = requestAnimationFrame
  10553. , b = cancelAnimationFrame;
  10554. b.call(this.B, this.j)
  10555. }
  10556. this.j = null
  10557. }
  10558. */
  10559. }
  10560.  
  10561. if (fOption & 2) {
  10562. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10563.  
  10564. if (keyzo) {
  10565.  
  10566. k = keyzo;
  10567.  
  10568. const attrUpdateFn = g[k];
  10569. // console.log(5992, attrUpdateFn)
  10570. g['$$original$$' + k] = attrUpdateFn;
  10571. const zoTransform = async (a, c) => {
  10572.  
  10573. let transformType = '';
  10574. let transformValue = 0;
  10575. let transformUnit = '';
  10576. let transformTypeI = 0;
  10577.  
  10578. const aStyle = a.style;
  10579.  
  10580. let cType = 0;
  10581.  
  10582. const cl = c.length;
  10583.  
  10584. if (cl >= 8) {
  10585. // scale(1)
  10586. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10587. cType = 1;
  10588. let t = c.charCodeAt(5);
  10589. if (t === 88 || t === 120) cType = 1 | 4;
  10590. if (t === 89 || t === 121) cType = 1 | 8;
  10591. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10592. cType = 2;
  10593. let t = c.charCodeAt(9);
  10594. if (t === 88 || t === 120) cType = 2 | 4;
  10595. if (t === 89 || t === 121) cType = 2 | 8;
  10596. }
  10597. let w = 0;
  10598. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10599. let p = c.substring(7, cl - 1);
  10600. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10601. if (typeof q === 'number' && !isNaNx(q)) {
  10602. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10603. transformValue = q;
  10604. transformUnit = '';
  10605. transformTypeI = 1;
  10606. } else {
  10607. cType = 256;
  10608. }
  10609. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10610. if (c.endsWith('px)')) {
  10611. let p = c.substring(11, cl - 3);
  10612. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10613. if (typeof q === 'number' && !isNaNx(q)) {
  10614. transformType = w === 1 ? 'translateX' : 'translateY';
  10615. transformValue = q;
  10616. transformUnit = 'px';
  10617. transformTypeI = 2;
  10618. } else if (p === 'NaN') {
  10619. return;
  10620. }
  10621. } else {
  10622. cType = 256;
  10623. }
  10624. } else if (cType > 0) {
  10625. cType = 256;
  10626. }
  10627. }
  10628.  
  10629.  
  10630. if (cType === 256) {
  10631. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10632. }
  10633.  
  10634. if (transformTypeI === 1) {
  10635. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10636. const vz = toFixed2(q, 3);
  10637. c = `${transformType}(${vz})`;
  10638. const cv = aStyle.transform;
  10639. if (c === cv) return;
  10640. aStyle.transform = c;
  10641. } else if (transformTypeI === 2) {
  10642. const q = transformValue;
  10643. const vz = toFixed2(q, 1);
  10644. c = `${transformType}(${vz}${transformUnit})`;
  10645. const cv = aStyle.transform;
  10646. if (c === cv) return;
  10647. aStyle.transform = c;
  10648. } else { // eg empty
  10649. const cv = aStyle.transform;
  10650. if (!c && !cv) return;
  10651. else if (c === cv) return;
  10652. aStyle.transform = c;
  10653. }
  10654.  
  10655. };
  10656.  
  10657. const elmTransformTemp = new WeakMap();
  10658. const elmPropTemps = {
  10659. 'display': new WeakMap(),
  10660. 'width': new WeakMap(),
  10661. 'height': new WeakMap(),
  10662. 'outlineWidth': new WeakMap(),
  10663. 'position': new WeakMap(),
  10664. 'padding': new WeakMap(),
  10665. "cssText": new WeakMap(),
  10666. "right": new WeakMap(),
  10667. "left": new WeakMap(),
  10668. "top": new WeakMap(),
  10669. "bottom": new WeakMap(),
  10670. "transitionDelay": new WeakMap(),
  10671. "marginLeft": new WeakMap(),
  10672. "marginTop": new WeakMap(),
  10673. "marginRight": new WeakMap(),
  10674. "marginBottom": new WeakMap(),
  10675. }
  10676.  
  10677. const ns5 = Symbol();
  10678. const nextModify = (a, c, m, f, immediate) => {
  10679. const a_ = a;
  10680. const m_ = m;
  10681. const noKey = !m_.has(a_);
  10682. if (immediate || noKey) {
  10683. m_.set(a_, ns5);
  10684. f(a_, c);
  10685. noKey && nextBrowserTick_(() => {
  10686. const d = m_.get(a_);
  10687. if (d === undefined) return;
  10688. m_.delete(a_);
  10689. if (d !== ns5) f(a_, d);
  10690. });
  10691. } else {
  10692. m_.set(a_, c);
  10693. }
  10694. };
  10695.  
  10696. const set66 = new Set();
  10697. const log77 = new Map();
  10698. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10699.  
  10700. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10701.  
  10702. // console.log(140000, a, b, c);
  10703. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10704. const num = c;
  10705. c = `${num}`;
  10706. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10707. }
  10708.  
  10709. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10710.  
  10711. let elmPropTemp = null;
  10712.  
  10713. if (b === "transform") {
  10714. // div.ytp-hover-progress.ytp-hover-progress-light
  10715. // div.ytp-play-progress.ytp-swatch-background-color
  10716.  
  10717. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10718. return;
  10719.  
  10720. } else if (elmPropTemp = elmPropTemps[b]) {
  10721.  
  10722. // if (c.length > 5 && c.includes('.')) {
  10723. // console.log(123213, c)
  10724. // }
  10725.  
  10726. const b_ = b;
  10727. nextModify(a, c, elmPropTemp, (a, c) => {
  10728. const style = a.style;
  10729. const cv = style[b_];
  10730. if (!cv && !c) return;
  10731. if (cv === c) return;
  10732. style[b_] = c;
  10733. }, immediateChange);
  10734. return;
  10735.  
  10736. } else if (b === "outline-width") {
  10737.  
  10738. const b_ = 'outlineWidth';
  10739. elmPropTemp = elmPropTemps[b_];
  10740. nextModify(a, c, elmPropTemp, (a, c) => {
  10741. const style = a.style;
  10742. const cv = style[b_];
  10743. if (!cv && !c) return;
  10744. if (cv === c) return;
  10745. style[b_] = c;
  10746. }, immediateChange);
  10747. return;
  10748.  
  10749. } else if (b === 'maxWidth' || b === 'maxHeight') {
  10750. // I think these can be directly assigned.
  10751.  
  10752. const b_ = b;
  10753. const style = a.style;
  10754. const cv = style[b_];
  10755. if (!cv && !c) return;
  10756. if (cv === c) return;
  10757. style[b_] = c;
  10758. return;
  10759.  
  10760. } else {
  10761. // if(immediate && elmPropTemps[b]){
  10762. // console.log(5191, b)
  10763. // }
  10764. // caption-window
  10765. // margin-left max-height max-width font-family fill color font-size background white-space margin
  10766. // text-align background-color
  10767. // console.log(27304, a, b, c)
  10768. if (!set66.has(b)) {
  10769. set66.add(b);
  10770. nextBrowserTick_(() => {
  10771. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  10772. console.log(27304, a, b, c)
  10773. }
  10774. })
  10775. }
  10776. }
  10777.  
  10778. attrUpdateFn.call(this, a, b, c);
  10779. return;
  10780. } else if (typeof (b || 0) === 'object') {
  10781.  
  10782. // this is to fix caption positioning
  10783. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  10784. const immediate = (a.id || 0).length > 14;
  10785. for (const [k, v] of Object.entries(b)) {
  10786. modifiedFn.call(this, a, k, v, immediate);
  10787. }
  10788.  
  10789. } else {
  10790.  
  10791. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  10792. // ytp-ad-timed-pie-countdown-inner
  10793.  
  10794. if (typeof b === 'string') {
  10795.  
  10796. let m = log77.get(b);
  10797. if (!m) {
  10798. m = [];
  10799. console.log('attrUpdateFn.debug.27304', m);
  10800. log77.set(b, m);
  10801. }
  10802. m.push([a, b, c]);
  10803.  
  10804. } else {
  10805. console.log('attrUpdateFn.debug.27306', a, b, c);
  10806. }
  10807.  
  10808. attrUpdateFn.call(this, a, b, c);
  10809. return;
  10810. }
  10811.  
  10812. // console.log(130000, a, b, c);
  10813.  
  10814. };
  10815. g[k] = modifiedFn;
  10816.  
  10817.  
  10818. /*
  10819.  
  10820. g.zo = function(a, b, c) {
  10821. if ("string" === typeof b)
  10822. (b = yo(a, b)) && (a.style[b] = c);
  10823. else
  10824. for (var d in b) {
  10825. c = a;
  10826. var e = b[d]
  10827. , f = yo(c, d);
  10828. f && (c.style[f] = e)
  10829. }
  10830. }
  10831.  
  10832.  
  10833. */
  10834.  
  10835.  
  10836. }
  10837. }
  10838.  
  10839. if (fOption & 4) {
  10840. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  10841.  
  10842. if (keyuG) {
  10843.  
  10844. k = keyuG;
  10845.  
  10846. const gk = g[k];
  10847. const gkp = gk.prototype;
  10848.  
  10849.  
  10850. /** @type { Map<string, WeakMap<any, any>> } */
  10851. const ntLogs = new Map();
  10852.  
  10853. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  10854.  
  10855. gkp.updateValue31 = gkp.updateValue;
  10856. gkp.updateValue = function (a, b) {
  10857. if (typeof a !== 'string') return this.updateValue31(a, b);
  10858.  
  10859. const element = this.element;
  10860. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  10861.  
  10862. let ntLog = ntLogs.get(a);
  10863. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  10864.  
  10865. let cache = ntLog.get(element);
  10866. if (cache && cache.value === b) {
  10867. return;
  10868. }
  10869. if (!cache) {
  10870. this.__oldValueByUpdateValue__ = null;
  10871. ntLog.set(element, cache = { value: b });
  10872. } else {
  10873. this.__oldValueByUpdateValue__ = cache.value;
  10874. cache.value = b;
  10875. }
  10876.  
  10877. return this.updateValue31(a, b);
  10878. }
  10879.  
  10880. /*
  10881. g.k.update = function(a) {
  10882. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  10883. c = c.value,
  10884. this.updateValue(c, a[c])
  10885. }
  10886. ;
  10887. g.k.updateValue = function(a, b) {
  10888. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  10889. }
  10890. */
  10891.  
  10892. }
  10893.  
  10894.  
  10895. }
  10896. }
  10897.  
  10898.  
  10899.  
  10900. })();
  10901.  
  10902.  
  10903. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  10904. // keyboard shortcut keys controller
  10905.  
  10906. const _yt_player = await _yt_player_observable.obtain();
  10907.  
  10908. if (!_yt_player || typeof _yt_player !== 'object') return;
  10909.  
  10910. keyboardController(_yt_player);
  10911.  
  10912. })();
  10913.  
  10914. FIX_yt_player && !isChatRoomURL && (async () => {
  10915. // timer scheduling
  10916.  
  10917. const _yt_player = await _yt_player_observable.obtain();
  10918.  
  10919. if (!_yt_player || typeof _yt_player !== 'object') return;
  10920.  
  10921. let keyZqQu = getZqQu(_yt_player);
  10922.  
  10923. if (!keyZqQu) return;
  10924.  
  10925. const g = _yt_player
  10926. let k = keyZqQu
  10927.  
  10928. const gk = g[k];
  10929. if (typeof gk !== 'function') return;
  10930. const gkp = gk.prototype;
  10931.  
  10932. const extractKeysZqQu = () => {
  10933.  
  10934.  
  10935. let _keyeC = '';
  10936. try {
  10937. gkp.stop.call(new Proxy({
  10938. isActive: () => { }
  10939. }, {
  10940. set(target, prop, value) {
  10941. if (value === 0) _keyeC = prop;
  10942. return true;
  10943. }
  10944. }));
  10945. } catch (e) { }
  10946. if (!_keyeC) return;
  10947. const keyeC = _keyeC;
  10948.  
  10949. let keyC = ''; // this.C = this.ST.bind(this)
  10950. let keyhj = ''; // 1000ms
  10951. try {
  10952. gkp.start.call(new Proxy({
  10953. stop: () => { },
  10954. [keyeC]: 0,
  10955. }, {
  10956. get(target, prop) {
  10957. if (prop in target) return target[prop];
  10958. if (!keyC) {
  10959. keyC = prop;
  10960. return null; // throw error
  10961. }
  10962. else if (!keyhj) {
  10963. keyhj = prop;
  10964. }
  10965.  
  10966. }
  10967. }));
  10968. } catch (e) {
  10969. if (!keyC || !keyhj) {
  10970. console.log(e)
  10971. }
  10972. }
  10973.  
  10974. if (!keyC || !keyhj) return;
  10975. let keyST = '';
  10976. let keyj = '';
  10977. let keyB = '';
  10978. let keyxa = '';
  10979.  
  10980. const possibleKs = new Set();
  10981.  
  10982. for (const [k, v] of Object.entries(gkp)) {
  10983. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  10984. continue;
  10985. }
  10986. if (typeof v === 'function') {
  10987. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  10988. if (m) {
  10989. keyST = k;
  10990. keyj = m[1];
  10991. keyB = m[2];
  10992. } else {
  10993. possibleKs.add(k);
  10994. }
  10995. }
  10996. }
  10997.  
  10998. if (!keyST || !keyj || !keyB) return;
  10999.  
  11000. for (const k of possibleKs) {
  11001. if (k === keyST || k === keyj || k === keyB) {
  11002. continue;
  11003. }
  11004. const v = gkp[k];
  11005. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  11006. keyxa = k;
  11007. }
  11008. }
  11009.  
  11010. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  11011.  
  11012. }
  11013.  
  11014. const keys = extractKeysZqQu();
  11015. if (!keys || !keys.length) return;
  11016. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  11017.  
  11018. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  11019.  
  11020. let disposeKeys = null;
  11021.  
  11022. gkp[keyxa] = function () {
  11023. // dispose
  11024. if (!disposeKeys) {
  11025. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  11026. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  11027. const t = typeof this[key];
  11028. return t === 'undefined' || t === 'object'
  11029. }
  11030. return false;
  11031. });
  11032. }
  11033. for (const key of disposeKeys) {
  11034. const v = this[key];
  11035. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  11036. }
  11037. if (this[keyeC] > 0) this.stop();
  11038. this[keyj] = null;
  11039. this[keyB] = null;
  11040. };
  11041.  
  11042. gkp.start = function (a) {
  11043. if (this[keyeC] > 0) this.stop();
  11044. const delay = void 0 !== a ? a : this[keyhj];
  11045. this[keyeC] = window.setTimeout(this[keyC], delay);
  11046. };
  11047. gkp.stop = function () {
  11048. if (this[keyeC] > 0) {
  11049. window.clearTimeout(this[keyeC]);
  11050. this[keyeC] = 0;
  11051. }
  11052. };
  11053.  
  11054. gkp.isActive = function () {
  11055. return this[keyeC] > 0;
  11056. };
  11057.  
  11058. gkp[keyST] = function () {
  11059. this.stop(); // this[keyeC] = 0;
  11060. const fn = this[keyj];
  11061. const obj = this[keyB];
  11062. let skip = false;
  11063. if (!fn) skip = true;
  11064. else if (IGNORE_bufferhealth_CHECK && obj) {
  11065. let m;
  11066. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  11067. if (m.has("bufferhealth")) skip = true;
  11068. }
  11069. }
  11070. if (!skip) {
  11071. fn.call(obj);
  11072. }
  11073. };
  11074.  
  11075.  
  11076.  
  11077.  
  11078. /*
  11079.  
  11080. g.k.eC = 0;
  11081. g.k.xa = function() {
  11082. g.Qu.Vf.xa.call(this);
  11083. this.stop();
  11084. delete this.j;
  11085. delete this.B
  11086. }
  11087. ;
  11088. g.k.start = function(a) {
  11089. this.stop();
  11090. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  11091. }
  11092. ;
  11093. g.k.stop = function() {
  11094. this.isActive() && g.Sa.clearTimeout(this.eC);
  11095. this.eC = 0
  11096. }
  11097. ;
  11098. g.k.isActive = function() {
  11099. return 0 != this.eC
  11100. }
  11101. ;
  11102. g.k.ST = function() {
  11103. this.eC = 0;
  11104. this.j && this.j.call(this.B)
  11105. }
  11106. ;
  11107. */
  11108.  
  11109.  
  11110.  
  11111.  
  11112. })();
  11113.  
  11114. FIX_Animation_n_timeline && (async () => {
  11115.  
  11116. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  11117.  
  11118. if (!timeline || !Animation) return;
  11119.  
  11120. const animationsFix = (timeline) => {
  11121. const animations = (timeline || 0)._animations || 0;
  11122. const c = animations[0];
  11123. if (c) {
  11124. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  11125. animations.shift(); // keep animating but no looping
  11126. // c.effect.remove();
  11127. }
  11128. }
  11129. }
  11130.  
  11131. const aniProto = Animation.prototype;
  11132. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  11133.  
  11134. const getXroto = (x) => {
  11135. try {
  11136. return x.__proto__;
  11137. } catch (e) { }
  11138. return null;
  11139. }
  11140. const timProto = getXroto(timeline);
  11141. if (!timProto) return;
  11142. if (
  11143. (
  11144. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  11145. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  11146. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  11147. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  11148. )
  11149.  
  11150. ) {
  11151.  
  11152. timProto.nofCQ = 1;
  11153. aniProto.nofYH = 1;
  11154.  
  11155. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  11156.  
  11157.  
  11158. /*
  11159. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11160. return c._updatePromises();
  11161. });
  11162. */
  11163.  
  11164. const p = Array.prototype.filter;
  11165.  
  11166. let res = null;
  11167. Array.prototype.filter = function () {
  11168.  
  11169. res = this;
  11170. return this;
  11171.  
  11172. };
  11173.  
  11174. _updateAnimationsPromises.call({});
  11175.  
  11176. Array.prototype.filter = p;
  11177.  
  11178. if (res && typeof res.length === 'number') {
  11179. /** @type {any[]} */
  11180. const _res = res;
  11181. return _res;
  11182. }
  11183.  
  11184.  
  11185. return null;
  11186.  
  11187.  
  11188.  
  11189.  
  11190. })(timProto._updateAnimationsPromises);
  11191.  
  11192. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  11193.  
  11194. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  11195.  
  11196. aniProto._updatePromises31 = aniProto._updatePromises;
  11197.  
  11198. /*
  11199. aniProto._updatePromises = function(){
  11200. console.log('eff',this._oldPlayState, this.playState)
  11201. return this._updatePromises31.apply(this, arguments)
  11202. }
  11203. */
  11204.  
  11205. aniProto._updatePromises = function () {
  11206. var oldPlayState = this._oldPlayState;
  11207. var newPlayState = this.playState;
  11208. // console.log('ett', oldPlayState, newPlayState)
  11209. if (newPlayState !== oldPlayState) {
  11210. this._oldPlayState = newPlayState;
  11211. if (this._readyPromise) {
  11212. if ("idle" == newPlayState) {
  11213. this._rejectReadyPromise();
  11214. this._readyPromise = void 0;
  11215. } else if ("pending" == oldPlayState) {
  11216. this._resolveReadyPromise();
  11217. } else if ("pending" == newPlayState) {
  11218. this._readyPromise = void 0;
  11219. }
  11220. }
  11221. if (this._finishedPromise) {
  11222. if ("idle" == newPlayState) {
  11223. this._rejectFinishedPromise();
  11224. this._finishedPromise = void 0;
  11225. } else if ("finished" == newPlayState) {
  11226. this._resolveFinishedPromise();
  11227. } else if ("finished" == oldPlayState) {
  11228. this._finishedPromise = void 0;
  11229. }
  11230. }
  11231. }
  11232. return this._readyPromise || this._finishedPromise;
  11233. };
  11234.  
  11235.  
  11236. let restartWebAnimationsNextTickFlag = false;
  11237.  
  11238. const looperMethodT = () => {
  11239.  
  11240. const runnerFn = (hRes) => {
  11241. var b = timeline;
  11242. b.currentTime = hRes;
  11243. b._discardAnimations();
  11244. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11245. if (0 == b._animations.length) {
  11246. restartWebAnimationsNextTickFlag = false;
  11247. } else {
  11248. getRafPromise().then(runnerFn);
  11249. }
  11250. }
  11251.  
  11252. const restartWebAnimationsNextTick = () => {
  11253. if (!restartWebAnimationsNextTickFlag) {
  11254. restartWebAnimationsNextTickFlag = true;
  11255. getRafPromise().then(runnerFn);
  11256. }
  11257. }
  11258.  
  11259. return { restartWebAnimationsNextTick }
  11260. };
  11261.  
  11262.  
  11263. const looperMethodN = () => {
  11264.  
  11265. const acs = document.createElement('a-f');
  11266. acs.id = 'a-f';
  11267.  
  11268. if (!document.getElementById('afscript')) {
  11269. const style = document.createElement('style');
  11270. style.id = 'afscript';
  11271. style.textContent = `
  11272. @keyFrames aF1 {
  11273. 0% {
  11274. order: 0;
  11275. }
  11276. 100% {
  11277. order: 1;
  11278. }
  11279. }
  11280. #a-f[id] {
  11281. visibility: collapse !important;
  11282. position: fixed !important;
  11283. display: block !important;
  11284. top: -100px !important;
  11285. left: -100px !important;
  11286. margin:0 !important;
  11287. padding:0 !important;
  11288. outline:0 !important;
  11289. border:0 !important;
  11290. z-index:-1 !important;
  11291. width: 0px !important;
  11292. height: 0px !important;
  11293. contain: strict !important;
  11294. pointer-events: none !important;
  11295. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  11296. }
  11297. `;
  11298. (document.head || document.documentElement).appendChild(style);
  11299. }
  11300.  
  11301. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  11302.  
  11303. const _onanimationiteration = function (evt) {
  11304. const hRes = evt.timeStamp;
  11305. var b = timeline;
  11306. b.currentTime = hRes;
  11307. b._discardAnimations();
  11308. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11309. if (0 == b._animations.length) {
  11310. restartWebAnimationsNextTickFlag = false;
  11311. acs.onanimationiteration = null;
  11312. } else {
  11313. acs.onanimationiteration = _onanimationiteration;
  11314. }
  11315.  
  11316. }
  11317.  
  11318.  
  11319.  
  11320. const restartWebAnimationsNextTick = () => {
  11321. if (!restartWebAnimationsNextTickFlag) {
  11322. restartWebAnimationsNextTickFlag = true;
  11323. acs.onanimationiteration = _onanimationiteration;
  11324.  
  11325. }
  11326. }
  11327.  
  11328. return { restartWebAnimationsNextTick }
  11329. };
  11330.  
  11331.  
  11332.  
  11333. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  11334.  
  11335.  
  11336. // console.log(571, timProto);
  11337. timProto._play = function (c) {
  11338. c = new Animation(c, this);
  11339. this._animations.push(c);
  11340. restartWebAnimationsNextTick();
  11341. c._updatePromises();
  11342. c._animation.play();
  11343. c._updatePromises();
  11344. return c
  11345. }
  11346.  
  11347. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  11348. originalAnimationsWithPromises.length = 0;
  11349. originalAnimationsWithPromises.push = null;
  11350. originalAnimationsWithPromises.splice = null;
  11351. originalAnimationsWithPromises.slice = null;
  11352. originalAnimationsWithPromises.indexOf = null;
  11353. originalAnimationsWithPromises.unshift = null;
  11354. originalAnimationsWithPromises.shift = null;
  11355. originalAnimationsWithPromises.pop = null;
  11356. originalAnimationsWithPromises.filter = null;
  11357. originalAnimationsWithPromises.forEach = null;
  11358. originalAnimationsWithPromises.map = null;
  11359.  
  11360.  
  11361. const _updateAnimationsPromises = () => {
  11362. animationsWithPromisesMap.forEach(c => {
  11363. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  11364. });
  11365. /*
  11366. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11367. return c._updatePromises();
  11368. });
  11369. */
  11370. }
  11371.  
  11372. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  11373.  
  11374. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  11375.  
  11376. delete timProto._updateAnimationsPromises;
  11377. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  11378. get() {
  11379. if (animationsWithPromisesMap.size === 0) return nilFn;
  11380. return _updateAnimationsPromises;
  11381. },
  11382. set(nv) {
  11383. delete this._updateAnimationsPromises;
  11384. this._updateAnimationsPromises = nv;
  11385. },
  11386. enumerable: true,
  11387. configurable: true,
  11388. });
  11389.  
  11390.  
  11391. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  11392. aniProto.__finished_native_get__ = pdFinished.get;
  11393. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  11394.  
  11395.  
  11396. Object.defineProperty(aniProto, 'finished', {
  11397. get() {
  11398. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11399. this._finishedPromise = new Promise((resolve, reject) => {
  11400. this._resolveFinishedPromise = function () {
  11401. resolve(this)
  11402. };
  11403. this._rejectFinishedPromise = function () {
  11404. reject({
  11405. type: DOMException.ABORT_ERR,
  11406. name: "AbortError"
  11407. })
  11408. };
  11409. }),
  11410. "finished" == this.playState && this._resolveFinishedPromise());
  11411. return this._finishedPromise
  11412. },
  11413. set: undefined,
  11414. enumerable: true,
  11415. configurable: true
  11416. });
  11417.  
  11418. }
  11419.  
  11420.  
  11421.  
  11422. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  11423. aniProto.__ready_native_get__ = pdReady.get;
  11424. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  11425.  
  11426. Object.defineProperty(aniProto, 'ready', {
  11427. get() {
  11428. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11429. this._readyPromise = new Promise((resolve, reject) => {
  11430. this._resolveReadyPromise = function () {
  11431. resolve(this)
  11432. };
  11433. this._rejectReadyPromise = function () {
  11434. reject({
  11435. type: DOMException.ABORT_ERR,
  11436. name: "AbortError"
  11437. })
  11438. };
  11439. }),
  11440. "pending" !== this.playState && this._resolveReadyPromise());
  11441. return this._readyPromise
  11442. },
  11443. set: undefined,
  11444. enumerable: true,
  11445. configurable: true
  11446. });
  11447.  
  11448. }
  11449.  
  11450.  
  11451. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  11452.  
  11453. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  11454. const _rebuildUnderlyingAnimation = function () {
  11455. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  11456. this.effect && this.effect._onsample && (this.effect._onsample = null);
  11457. return this._rebuildUnderlyingAnimation21();
  11458. }
  11459. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  11460. // delete aniProto._rebuildUnderlyingAnimation;
  11461. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  11462. // get() {
  11463. // if (isNaN(this._sequenceNumber)) return nilFn;
  11464. // return this._rebuildUnderlyingAnimation21;
  11465. // },
  11466. // set(nv) {
  11467. // delete this._rebuildUnderlyingAnimation;
  11468. // this._rebuildUnderlyingAnimation = nv;
  11469. // },
  11470. // enumerable: true,
  11471. // configurable: true
  11472. // });
  11473. }
  11474.  
  11475.  
  11476. /*
  11477.  
  11478.  
  11479. function f(c) {
  11480. var b = v.timeline;
  11481. b.currentTime = c;
  11482. b._discardAnimations();
  11483. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  11484. }
  11485. var h = window.requestAnimationFrame;
  11486. window.requestAnimationFrame = function(c) {
  11487. return h(function(b) {
  11488. v.timeline._updateAnimationsPromises();
  11489. c(b);
  11490. v.timeline._updateAnimationsPromises()
  11491. })
  11492. }
  11493. ;
  11494. v.AnimationTimeline = function() {
  11495. this._animations = [];
  11496. this.currentTime = void 0
  11497. }
  11498. ;
  11499. v.AnimationTimeline.prototype = {
  11500. getAnimations: function() {
  11501. this._discardAnimations();
  11502. return this._animations.slice()
  11503. },
  11504. _updateAnimationsPromises: function() {
  11505. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  11506. return c._updatePromises()
  11507. })
  11508. },
  11509. _discardAnimations: function() {
  11510. this._updateAnimationsPromises();
  11511. this._animations = this._animations.filter(function(c) {
  11512. return "finished" != c.playState && "idle" != c.playState
  11513. })
  11514. },
  11515. _play: function(c) {
  11516. c = new v.Animation(c,this);
  11517. this._animations.push(c);
  11518. v.restartWebAnimationsNextTick();
  11519. c._updatePromises();
  11520. c._animation.play();
  11521. c._updatePromises();
  11522. return c
  11523. },
  11524. play: function(c) {
  11525. c && c.remove();
  11526. return this._play(c)
  11527. }
  11528. };
  11529. var d = !1;
  11530. v.restartWebAnimationsNextTick = function() {
  11531. d || (d = !0,
  11532. requestAnimationFrame(f))
  11533. }
  11534. ;
  11535. var a = new v.AnimationTimeline;
  11536. v.timeline = a;
  11537. try {
  11538. Object.defineProperty(window.document, "timeline", {
  11539. configurable: !0,
  11540. get: function() {
  11541. return a
  11542. }
  11543. })
  11544. } catch (c) {}
  11545. try {
  11546. window.document.timeline = a
  11547. } catch (c) {}
  11548.  
  11549. */
  11550.  
  11551.  
  11552.  
  11553. /*
  11554.  
  11555. var g = window.getComputedStyle;
  11556. Object.defineProperty(window, "getComputedStyle", {
  11557. configurable: !0,
  11558. enumerable: !0,
  11559. value: function() {
  11560. v.timeline._updateAnimationsPromises();
  11561. var e = g.apply(this, arguments);
  11562. h() && (e = g.apply(this, arguments));
  11563. v.timeline._updateAnimationsPromises();
  11564. return e
  11565. }
  11566. });
  11567.  
  11568. */
  11569.  
  11570.  
  11571.  
  11572.  
  11573. }
  11574.  
  11575.  
  11576.  
  11577.  
  11578. })();
  11579.  
  11580. !isUrlInEmbed && Promise.resolve().then(() => {
  11581.  
  11582. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11583.  
  11584.  
  11585.  
  11586. class LimitedSizeSet extends Set {
  11587. constructor(n) {
  11588. super();
  11589. this.limit = n;
  11590. }
  11591.  
  11592. add(key) {
  11593. if (!super.has(key)) {
  11594. super.add(key);
  11595. let n = super.size - this.limit;
  11596. if (n > 0) {
  11597. const iterator = super.values();
  11598. do {
  11599. const firstKey = iterator.next().value; // Get the first (oldest) key
  11600. super.delete(firstKey); // Delete the oldest key
  11601. } while (--n > 0)
  11602. }
  11603. }
  11604. }
  11605.  
  11606. removeAdd(key) {
  11607. super.delete(key);
  11608. this.add(key);
  11609. }
  11610.  
  11611. }
  11612.  
  11613. // const wk3 = new WeakMap();
  11614.  
  11615. // let mtxVideoId = '';
  11616. // let aje3 = [];
  11617. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11618. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11619. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11620. let mtzCount = 0; // the key keeps unchanged
  11621. // let mjtNextMainKey = '';
  11622. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11623. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11624. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11625. // let allowNoDelay322=false;
  11626. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11627.  
  11628. let mpKey22 = ''; // last success continutation key & url pair
  11629. let mpUrl22 = ''; // last success continutation key & url pair
  11630. let mpKey21 = ''; // latest requested continutation key & url pair
  11631. let mpUrl21 = ''; // latest requested continutation key & url pair
  11632.  
  11633.  
  11634. async function sha1Hex(message) {
  11635. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11636. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11637. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11638. const hashHex = hashArray
  11639. .map((b) => b.toString(16).padStart(2, "0"))
  11640. .join(""); // convert bytes to hex string
  11641. return hashHex;
  11642. }
  11643.  
  11644. async function continuationLog(a, ...args) {
  11645. let b = a;
  11646. try {
  11647. if (advanceLogging) b = await sha1Hex(a);
  11648. let c = args.map(e => {
  11649. return e === a ? b : e
  11650. });
  11651. console.log(...c)
  11652. } catch (e) { console.warn(e) }
  11653. }
  11654.  
  11655. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11656.  
  11657.  
  11658. if (mfvContinuationRecorded.length > 0) {
  11659. for (const [e, d] of mfvContinuationRecorded) {
  11660. mfyContinuationIgnored.removeAdd(e);
  11661. }
  11662. toClearRecorded && mfvContinuationRecorded.clear();
  11663. }
  11664.  
  11665. }
  11666.  
  11667. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11668.  
  11669. const tmProto = taskMgr.constructor.prototype;
  11670. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11671.  
  11672. if (!tmProto.addJob714) {
  11673.  
  11674. tmProto.addJob714 = tmProto.addJob;
  11675.  
  11676. tmProto.addJob = function (a, b, c) {
  11677. const jobId = this.addJob714(a, b, c);
  11678. if (jobId > 0) {
  11679. // const ez = wk3.get(this);
  11680. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11681. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11682.  
  11683. this.__lastJobId863__ = jobId;
  11684. }
  11685. return jobId;
  11686. }
  11687.  
  11688. }
  11689.  
  11690. if (!tmProto.cancelJob714) {
  11691.  
  11692. tmProto.cancelJob714 = tmProto.cancelJob;
  11693.  
  11694. tmProto.cancelJob = function (a) {
  11695. const res = this.cancelJob714(a);
  11696. // if (a > 0) {
  11697. // for (const e of aje3) {
  11698. // if (e.jobId === a) e.cancelled = true;
  11699. // }
  11700. // }
  11701. return res;
  11702. }
  11703.  
  11704. }
  11705.  
  11706. }
  11707. }
  11708.  
  11709.  
  11710. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11711.  
  11712.  
  11713. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11714. let dummy;
  11715. let cProto;
  11716. // let mc = 4;
  11717. // dummy = await observablePromise(() => {
  11718. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11719. // if (!r) return;
  11720. // let cProto = insp(r).constructor.prototype;
  11721. // if (cProto.fetchUpdatedMetadata) return r;
  11722. // if (--mc < 0) return -1;
  11723. // return null;
  11724. // }).obtain();
  11725. dummy = document.createElement('ytd-video-primary-info-renderer');
  11726. if (!(dummy instanceof Element)) return;
  11727. // console.log(5022, dummy)
  11728. cProto = insp(dummy).constructor.prototype;
  11729.  
  11730. cProto.__getEmittorTaskMgr859__ = function () {
  11731. let taskMgr_ = null;
  11732. try {
  11733. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  11734. } catch (e) { }
  11735. return taskMgr_;
  11736. }
  11737. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  11738. // console.log(1234, cProto, cProto.is)
  11739. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  11740.  
  11741. let c_;
  11742. cProto.fetchUpdatedMetadata718 = function (a) {
  11743. // delay or immediate call the actual fetchUpdatedMetadata
  11744.  
  11745. let doImmediately = false;
  11746. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  11747.  
  11748. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  11749.  
  11750. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  11751.  
  11752. doImmediately = true;
  11753.  
  11754. }
  11755.  
  11756. if (mbCId322) {
  11757. clearTimeout(mbCId322);
  11758. mbCId322 = 0;
  11759. }
  11760.  
  11761. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  11762.  
  11763. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  11764.  
  11765. mbCId322 = setTimeout(() => {
  11766. this.fetchUpdatedMetadata717(a);
  11767. }, delay);
  11768.  
  11769. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  11770.  
  11771. }
  11772.  
  11773. cProto.fetchUpdatedMetadata = function (a) {
  11774.  
  11775. if (!pageSetupState) {
  11776. if (c_) clearTimeout(c_);
  11777. c_ = setTimeout(() => {
  11778. this.fetchUpdatedMetadata718(a);
  11779. }, 300);
  11780. return;
  11781. }
  11782.  
  11783. // pageSetupState == 0
  11784.  
  11785. try {
  11786.  
  11787. mbDelayBelowNCalls++;
  11788.  
  11789. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  11790. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  11791. }
  11792.  
  11793. // console.log('fum377', a)
  11794. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  11795. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  11796. return;
  11797. }
  11798.  
  11799. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  11800. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  11801. mjtLockPreviousKey = mjtRecordedPrevKey;
  11802. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  11803. }
  11804. // mjtNextMainKey = true;
  11805. mtzlastAllowedContinuation = '';
  11806. mtzCount = 0;
  11807. // allowNoDelay322 = false;
  11808. // fetch new metadata, cancel all previous continuations
  11809. copyPreviousContiuationToIgnored374(true);
  11810. } else if (typeof a === 'string') {
  11811. const videoPlayingId = videoPlayingY.videoId;
  11812.  
  11813. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  11814.  
  11815. let update21 = !!pageSetupVideoId;
  11816. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  11817. update21 = true;
  11818. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  11819. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  11820. return;
  11821. }
  11822. if (update21) {
  11823. mpKey21 = a;
  11824. mpUrl21 = pageSetupVideoId || videoPlayingId;
  11825. }
  11826.  
  11827. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  11828. }
  11829. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  11830. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  11831. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  11832. return this.fetchUpdatedMetadata718(a);
  11833.  
  11834. } catch (e) {
  11835. console.log('Code Error in fetchUpdatedMetadata', e);
  11836. }
  11837. return this.fetchUpdatedMetadata717(a)
  11838. }
  11839. }
  11840.  
  11841.  
  11842. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  11843. // console.log(1234, cProto, cProto.is)
  11844. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  11845. let mJob = null;
  11846.  
  11847. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  11848.  
  11849. try {
  11850.  
  11851. if (arguments.length > 0) {
  11852. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  11853. }
  11854. // mfy = mfv;
  11855.  
  11856. // mjtNextMainKey = '';
  11857. mtzlastAllowedContinuation = '';
  11858. mtzCount = 0;
  11859. if (mbCId322) {
  11860. clearTimeout(mbCId322);
  11861. mbCId322 = 0;
  11862. }
  11863. mbDelayBelowNCalls = 0;
  11864. // allowNoDelay322 = false;
  11865. copyPreviousContiuationToIgnored374(true);
  11866.  
  11867. const taskMgr = this.__getEmittorTaskMgr859__();
  11868. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  11869. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  11870. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  11871. }
  11872.  
  11873. // prevent depulicated schedule job by clearing previous JobId
  11874. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  11875.  
  11876. let res;
  11877.  
  11878. if (mJob) {
  11879. const job = mJob;
  11880. mJob = null;
  11881. console.log('cancelJob', job)
  11882. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  11883. // p.cancelJob(a,b);
  11884. }
  11885.  
  11886. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  11887.  
  11888. let pza = taskMgr.__lastJobId863__;
  11889. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  11890. let pzb = taskMgr.__lastJobId863__
  11891. if (pza !== pzb) {
  11892. mJob = pzb; // set [Interval Meta Update] jobId
  11893. }
  11894.  
  11895. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  11896. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  11897. // } else {
  11898. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  11899. // }
  11900.  
  11901. return res;
  11902.  
  11903. } else {
  11904. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  11905. }
  11906.  
  11907. } catch (e) {
  11908. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  11909. }
  11910.  
  11911.  
  11912. return this.scheduleInitialUpdatedMetadataRequest717();
  11913. }
  11914. }
  11915.  
  11916.  
  11917. });
  11918.  
  11919. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  11920. let dummy;
  11921. let cProto;
  11922. dummy = ytAppDom;
  11923. if (!(dummy instanceof Element)) return;
  11924. cProto = insp(dummy).constructor.prototype;
  11925. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  11926. // console.log(1234, cProto, cProto.is);
  11927. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11928. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  11929. // console.log(123401, arguments);
  11930. // return this.handleServiceRequest717_(a, b, c, d);
  11931. // }
  11932.  
  11933. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11934.  
  11935. // cProto.handleServiceRequest_ = function(a,b,c,d){
  11936. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11937. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  11938. // console.log('mfv', c.continuation);
  11939. // mfv.add( c.continuation);
  11940. // }
  11941. // return this.handleServiceRequest717_(a,b,c,d);
  11942. // }
  11943.  
  11944. function extraArguments322(a, b, c) {
  11945. let is = (a || 0).is;
  11946. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  11947. let continuation = (c || 0).continuation;
  11948. if (typeof is !== 'string') is = null;
  11949. if (typeof videoId !== 'string') videoId = null;
  11950. if (typeof continuation !== 'string') continuation = null;
  11951. return { is, videoId, continuation };
  11952. }
  11953.  
  11954. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  11955. cProto.sendServiceAjax_ = function (a, b, c, d) {
  11956.  
  11957. // console.log(8001)
  11958. try {
  11959.  
  11960. const { is, videoId, continuation } = extraArguments322(a, b, c);
  11961.  
  11962. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11963. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  11964. }
  11965.  
  11966. if (pageSetupVideoId && videoId && continuation) {
  11967. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11968. mfyContinuationIgnored.removeAdd(continuation);
  11969. mfvContinuationRecorded.delete(continuation);
  11970. return;
  11971. }
  11972. }
  11973.  
  11974. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11975. copyPreviousContiuationToIgnored374(false);
  11976. mfyContinuationIgnored.delete(continuation);
  11977. mfvContinuationRecorded.removeAdd(continuation);
  11978. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11979. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11980. mjtLockPreviousKey = '';
  11981. }
  11982. // if (mjtNextMainKey === continuation) {
  11983. // copyPreviousContiuationToIgnored(false);
  11984. // mfyContinuationIgnored.delete(continuation);
  11985. // mfvContinuationRecorded.add(continuation);
  11986. // }
  11987.  
  11988.  
  11989. if (mfyContinuationIgnored && continuation) {
  11990. if (mfyContinuationIgnored.has(continuation)) {
  11991. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  11992. return;
  11993. }
  11994. }
  11995.  
  11996. // console.log(59902, a?.is, b,c,d)
  11997. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11998. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  11999. // console.log('mfv377', continuation);
  12000. mfvContinuationRecorded.add(continuation);
  12001. }
  12002.  
  12003. // if (videoId) {
  12004. // if (!pageSetupVideoId) return; // ignore page not ready
  12005. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12006. // if (videoId !== pageSetupVideoId) {
  12007. // return;
  12008. // }
  12009. // }
  12010.  
  12011. } catch (e) {
  12012. console.log('Coding Error in sendServiceAjax_', e)
  12013. }
  12014. // console.log(8002)
  12015. // console.log(123402, arguments);
  12016. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  12017.  
  12018. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  12019. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  12020. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  12021. // get(target, prop, receiver){
  12022. // console.log('xxs99', target.videoId, mtx)
  12023. // if(prop ==='kdkw33') return 1;
  12024. // console.log(3322, prop, target)
  12025. // if(prop === 'initialDelayMs') {
  12026. // throw new Error("ABCC");
  12027. // }
  12028. // return target[prop];
  12029. // },
  12030. // set(target, prop, value, receiver){
  12031.  
  12032. // if(prop ==='kdkw33') return true;
  12033. // target[prop]=value;
  12034. // return true;
  12035. // }
  12036. // });
  12037. // }
  12038. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  12039. return this.sendServiceAjax717_(a, b, c, d);
  12040. }
  12041. }
  12042.  
  12043. function delayClearOtherKeys(lztContinuation) {
  12044. // // schedule delayed removal if mfyContinuationIgnored is not empty
  12045. // getRafPromise().then(() => {
  12046. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  12047. // // foreground page only
  12048.  
  12049. // });
  12050.  
  12051.  
  12052. if (lztContinuation !== mtzlastAllowedContinuation) return;
  12053. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  12054. if (!mfyContinuationIgnored.size) return;
  12055. if (mfyContinuationIgnored.size > 1) {
  12056. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  12057. }
  12058. mfyContinuationIgnored.forEach((value, key) => {
  12059. if (key !== lztContinuation) {
  12060. mfyContinuationIgnored.delete(key);
  12061. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  12062. }
  12063. });
  12064.  
  12065. }
  12066. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  12067. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  12068. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  12069.  
  12070. // console.log(8003)
  12071. try {
  12072.  
  12073.  
  12074. const { is, videoId, continuation } = extraArguments322(b, c, d);
  12075.  
  12076. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12077. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  12078. }
  12079.  
  12080. if (pageSetupVideoId && videoId && continuation) {
  12081. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12082. mfyContinuationIgnored.removeAdd(continuation);
  12083. mfvContinuationRecorded.delete(continuation);
  12084. return;
  12085. }
  12086. }
  12087.  
  12088. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12089. copyPreviousContiuationToIgnored374(false);
  12090. mfyContinuationIgnored.delete(continuation);
  12091. mfvContinuationRecorded.removeAdd(continuation);
  12092. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12093. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12094. mjtLockPreviousKey = '';
  12095. }
  12096.  
  12097. // if (mjtNextMainKey === continuation) {
  12098. // copyPreviousContiuationToIgnored(false);
  12099. // mfyContinuationIgnored.delete(continuation);
  12100. // mfvContinuationRecorded.add(continuation);
  12101. // }
  12102.  
  12103. const lztContinuation = continuation;
  12104.  
  12105. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  12106. if (mfyContinuationIgnored.has(lztContinuation)) {
  12107. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  12108. return;
  12109. }
  12110. }
  12111.  
  12112. // if (videoId) {
  12113. // if (!pageSetupVideoId) return; // ignore page not ready
  12114. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12115. // if (videoId !== pageSetupVideoId) {
  12116. // return;
  12117. // }
  12118. // }
  12119.  
  12120. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  12121. mtzlastAllowedContinuation = lztContinuation;
  12122. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  12123.  
  12124. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12125. mjtRecordedPrevKey = lztContinuation;
  12126. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  12127. // if (mfyContinuationIgnored.size > 0) {
  12128. // delayClearOtherKeys(lztContinuation);
  12129. // }
  12130. mtzCount = 0;
  12131. // allowNoDelay322 = false;
  12132. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  12133. // repeated
  12134. if (++mtzCount > 1e9) mtzCount = 1e4;
  12135. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12136.  
  12137. // if (mtzCount >= 3) allowNoDelay322 = true;
  12138. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  12139. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  12140. }
  12141. if (mtzCount === 5) {
  12142. mfvContinuationRecorded.clear();
  12143. mfvContinuationRecorded.add(lztContinuation);
  12144. }
  12145.  
  12146. }
  12147.  
  12148. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  12149. mpKey22 = lztContinuation;
  12150. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  12151. }
  12152.  
  12153. if (mbCId322) {
  12154. clearTimeout(mbCId322);
  12155. mbCId322 = 0;
  12156. }
  12157. } catch (e) {
  12158. console.log('Coding Error in getCancellableNetworkPromise_', e)
  12159. }
  12160.  
  12161. // console.log(8004)
  12162. // console.log(123403, arguments);
  12163. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  12164.  
  12165. // console.log(5163, a?.is,b,c,d,e);
  12166. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  12167. }
  12168. }
  12169. });
  12170.  
  12171. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  12172.  
  12173.  
  12174. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  12175.  
  12176. let dummy;
  12177. let cProto;
  12178.  
  12179. dummy = document.createElement('ytd-expander');
  12180. cProto = insp(dummy).constructor.prototype;
  12181.  
  12182. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  12183.  
  12184. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  12185. cProto.childrenChanged14 = cProto.childrenChanged;
  12186.  
  12187. cProto.initChildrenObserver = function () {
  12188. var a = this;
  12189. this.observer = new MutationObserver(function () {
  12190. a.childrenChanged()
  12191. }
  12192. );
  12193. this.observer.observe(this.content, {
  12194. subtree: !0,
  12195. childList: !0,
  12196. attributes: !0,
  12197. characterData: !0
  12198. });
  12199. this.childrenChanged()
  12200. }
  12201. ;
  12202. cProto.childrenChanged = function () {
  12203. if (this.alwaysToggleable) {
  12204. this.canToggle = this.alwaysToggleable;
  12205. } else if (!this.canToggleJobId) {
  12206. this.canToggleJobId = 1;
  12207. foregroundPromiseFn().then(() => {
  12208. this.canToggleJobId = 0;
  12209. this.calculateCanCollapse()
  12210. })
  12211. }
  12212. }
  12213.  
  12214. // console.log(cProto.initChildrenObserver)
  12215. console.debug('ytd-expander-fix-childrenChanged');
  12216.  
  12217. }
  12218.  
  12219. });
  12220.  
  12221.  
  12222. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  12223.  
  12224. let dummy;
  12225. let cProto;
  12226. dummy = document.createElement('paper-ripple');
  12227. cProto = insp(dummy).constructor.prototype;
  12228.  
  12229. if (fnIntegrity(cProto.animate, '0.74.5')) {
  12230.  
  12231.  
  12232. cProto.animate34 = cProto.animate;
  12233. cProto.animate = function () {
  12234. if (this._animating) {
  12235. var a;
  12236. const ripples = this.ripples;
  12237. for (a = 0; a < ripples.length; ++a) {
  12238. var b = ripples[a];
  12239. b.draw();
  12240. this.$.background.style.opacity = b.outerOpacity;
  12241. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  12242. }
  12243. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  12244. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  12245. foregroundPromiseFn().then(this._boundAnimate38);
  12246. } else {
  12247. this.onAnimationComplete();
  12248. }
  12249. }
  12250. }
  12251.  
  12252. console.debug('FIX_paper_ripple_animate')
  12253.  
  12254. // console.log(cProto.animate)
  12255.  
  12256. }
  12257.  
  12258. });
  12259.  
  12260. if (FIX_doIdomRender) {
  12261.  
  12262. const xsetTimeout = function (f, d) {
  12263. if (xsetTimeout.m511 === 1 && !d) {
  12264. xsetTimeout.m511 = 2;
  12265. xsetTimeout.m568 = f;
  12266. } else {
  12267. return setTimeout.apply(window, arguments)
  12268. }
  12269.  
  12270. }
  12271.  
  12272. /**
  12273. *
  12274. IGb = function(a) {
  12275. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  12276. c || (a.requestAninmationFrameResolver = new Vi,
  12277. c = a.requestAninmationFrameResolver.promise,
  12278. Da.requestAnimationFrame(function() {
  12279. var d;
  12280. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  12281. a.requestAninmationFrameResolver = null
  12282. }));
  12283. return c
  12284. }
  12285.  
  12286.  
  12287. */
  12288.  
  12289. const xrequestAnimationFrame = function (f) {
  12290. const h = `${f}`;
  12291. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  12292. let t = null;
  12293. xsetTimeout.m511 = 1;
  12294. f();
  12295. if (xsetTimeout.m511 === 2) {
  12296. t = xsetTimeout.m568;
  12297. xsetTimeout.m568 = null;
  12298. }
  12299. xsetTimeout.m511 = 0;
  12300. if (typeof t === 'function') {
  12301. foregroundPromiseFn().then(t);
  12302. }
  12303. } else if (h.includes("requestAninmationFrameResolver")) {
  12304. foregroundPromiseFn().then(f);
  12305. } else {
  12306. return requestAnimationFrame.apply(window, arguments);
  12307. }
  12308. }
  12309.  
  12310. let busy = false;
  12311. const doIdomRender = function () {
  12312.  
  12313. if (!this) return;
  12314. if (busy) {
  12315. return this.doIdomRender13(...arguments);
  12316. }
  12317. busy = true;
  12318. const { requestAnimationFrame, setTimeout } = window;
  12319. window.requestAnimationFrame = xrequestAnimationFrame;
  12320. window.setTimeout = xsetTimeout;
  12321. let r = this.doIdomRender13(...arguments);
  12322. window.requestAnimationFrame = requestAnimationFrame;
  12323. window.setTimeout = setTimeout;
  12324. busy = false;
  12325. return r;
  12326. };
  12327. 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']) {
  12328.  
  12329.  
  12330. whenCEDefined(ytTag).then(() => {
  12331.  
  12332. let dummy;
  12333. let cProto;
  12334. dummy = document.createElement(ytTag);
  12335. cProto = insp(dummy).constructor.prototype;
  12336.  
  12337. cProto.doIdomRender13 = cProto.doIdomRender;
  12338. cProto.doIdomRender = doIdomRender;
  12339.  
  12340. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  12341.  
  12342. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  12343.  
  12344.  
  12345.  
  12346. });
  12347.  
  12348. }
  12349.  
  12350. }
  12351.  
  12352.  
  12353.  
  12354.  
  12355. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  12356.  
  12357. const sMap = new Map();
  12358.  
  12359. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  12360. const ZT = function () {
  12361. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  12362. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  12363. c = b & 15,
  12364. b >>= 4,
  12365. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  12366. return a.join("")
  12367. };
  12368.  
  12369.  
  12370. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  12371.  
  12372. const popupContainer = await observablePromise(() => {
  12373. return popupContainerCollection[0];
  12374. }).obtain();
  12375.  
  12376.  
  12377. let cProto;
  12378. cProto = insp(popupContainer).constructor.prototype;
  12379.  
  12380.  
  12381. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  12382. console.log('FIX_POPUP_UNIQUE_ID NG')
  12383. return;
  12384. }
  12385. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  12386.  
  12387. cProto.handleOpenPopupAction = function (a, b) {
  12388.  
  12389. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  12390.  
  12391. a.__jOdQA__ = true;
  12392.  
  12393. try {
  12394.  
  12395. const h = this.hostElement;
  12396.  
  12397. if (h instanceof HTMLElement_) {
  12398.  
  12399. const map = h.__skme44__ = h.__skme44__ || new Map();
  12400.  
  12401. let mKey = '';
  12402. const wKey = firstObjectKey(a);
  12403. const wObj = wKey ? a[wKey] : null;
  12404. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  12405. const pKey = firstObjectKey(wObj.popup)
  12406. const pObj = pKey ? wObj.popup[pKey] : null;
  12407. let contentKey = '';
  12408. let headerKey = '';
  12409.  
  12410. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  12411. contentKey = firstObjectKey(pObj.content)
  12412. headerKey = firstObjectKey(pObj.header)
  12413. }
  12414. if (contentKey && headerKey) {
  12415.  
  12416. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  12417.  
  12418. if (mKey) {
  12419.  
  12420. if (!wObj.uniqueId) {
  12421. for (let i = 0; i < 8; i++) {
  12422. wObj.uniqueId = ZT();
  12423. if (!sMap.has(wObj.uniqueId)) break;
  12424. }
  12425. }
  12426. const oId = wObj.uniqueId
  12427.  
  12428. let nId_ = map.get(mKey);
  12429. if (!nId_) {
  12430. map.set(mKey, nId_ = oId);
  12431. }
  12432.  
  12433. wObj.uniqueId = nId_ || wObj.uniqueId;
  12434.  
  12435. const nId = wObj.uniqueId
  12436.  
  12437. sMap.set(oId, nId);
  12438. sMap.set(nId, nId);
  12439.  
  12440. wObj.uniqueId = nId;
  12441. pObj.targetId = nId;
  12442. pObj.identifier.tag = nId;
  12443.  
  12444. if (oId !== nId) {
  12445. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  12446. }
  12447.  
  12448. }
  12449.  
  12450. }
  12451. }
  12452.  
  12453. // console.log(12213, mKey, a, b, h)
  12454.  
  12455. }
  12456.  
  12457. } catch (e) {
  12458. console.warn(e)
  12459. }
  12460.  
  12461. try {
  12462.  
  12463. const results = searchNestedObject(a, (x) => {
  12464. if (typeof x === 'string' && x.length === 36) {
  12465. 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;
  12466. }
  12467. return false;
  12468. });
  12469. for (const [obj, key] of results) {
  12470. const oId = obj[key];
  12471. const nId = sMap.get(oId);
  12472. if (nId) obj[key] = nId;
  12473. }
  12474. } catch (e) {
  12475. console.warn(e)
  12476. }
  12477.  
  12478.  
  12479. }
  12480.  
  12481. return this.handleOpenPopupAction3868(...arguments)
  12482. }
  12483.  
  12484. console.log('FIX_POPUP_UNIQUE_ID OK')
  12485.  
  12486.  
  12487. });
  12488.  
  12489.  
  12490. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  12491.  
  12492. let dummy;
  12493. let cProto;
  12494. dummy = document.createElement('yt-formatted-string');
  12495. cProto = insp(dummy).constructor.prototype;
  12496.  
  12497. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  12498. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  12499. return;
  12500. }
  12501.  
  12502. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  12503. cProto.setNodeStyle_ = function (a, b) {
  12504. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  12505. return this.setNodeStyle17_(a, b);
  12506. }
  12507.  
  12508. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  12509. });
  12510.  
  12511. });
  12512.  
  12513. });
  12514.  
  12515.  
  12516.  
  12517.  
  12518. if (isMainWindow) {
  12519.  
  12520. console.groupCollapsed(
  12521. "%cYouTube JS Engine Tamer",
  12522. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  12523. );
  12524.  
  12525.  
  12526.  
  12527. console.log("Script is loaded.");
  12528. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  12529.  
  12530. console.log("This script is experimental and subject to further changes.");
  12531.  
  12532. console.log("This might boost your YouTube performance.");
  12533.  
  12534. console.log("CAUTION: This might break your YouTube.");
  12535.  
  12536.  
  12537. if (prepareLogs.length >= 1) {
  12538. console.log(" =========================================================================== ");
  12539.  
  12540. for (const msg of prepareLogs) {
  12541. console.log(msg)
  12542. }
  12543.  
  12544. console.log(" =========================================================================== ");
  12545. }
  12546.  
  12547. console.groupEnd();
  12548.  
  12549. }
  12550.  
  12551.  
  12552.  
  12553. })();