YouTube JS Engine Tamer

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

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

  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.7
  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. cProto[key] = function () {
  2077. // const p = ((this || 0).root || 0).node;
  2078. // if ((p instanceof Element) && p.nodeType === 1) {
  2079. // return p[key](...arguments);
  2080. // } else {
  2081. return this[bey](...arguments);
  2082. // }
  2083. }
  2084. });
  2085. }
  2086. }
  2087.  
  2088. 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];
  2089. constructAts.add(constructAt)
  2090.  
  2091. if (MemoryFix_Flag002 & 32) {
  2092. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  2093. fixDetachFn(cProto);
  2094. }
  2095. }
  2096.  
  2097. if (MemoryFix_Flag002 & 2) {
  2098. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  2099. cProto.__setPropDX38__ = true;
  2100.  
  2101. if (cProto._setPendingProperty.length === 3) {
  2102. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  2103. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  2104. return () => {
  2105. const obj = kRef(wobj);
  2106. let u = Reflect.apply(this, obj, args);
  2107. args.length = 0;
  2108. wobj = null;
  2109. return u;
  2110. };
  2111. });
  2112. }
  2113.  
  2114. }
  2115. }
  2116.  
  2117.  
  2118. const cProtoConstructor = cProto.constructor;
  2119.  
  2120. if (MemoryFix_Flag002 & 8) {
  2121. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  2122. cProtoConstructor.__parseBindingsDX38__ = true;
  2123.  
  2124. ydMap.add(cProtoConstructor);
  2125.  
  2126. if (cProtoConstructor._parseBindings.length === 2) {
  2127.  
  2128. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  2129.  
  2130. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  2131. let p = this._parseBindings3858(c, d);
  2132. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  2133. if (p) this.__bindingsArrs__.push(p);
  2134. return p;
  2135. });
  2136.  
  2137. }
  2138. }
  2139. }
  2140.  
  2141. /*
  2142. a.prototype._initializeProperties = function() {
  2143. if (Em && this.hasAttribute("disable-upgrade"))
  2144. this.__isUpgradeDisabled = !0;
  2145. else {
  2146. var e = Object.getPrototypeOf(this);
  2147. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  2148. e.__hasRegisterFinished = !0);
  2149. b.prototype._initializeProperties.call(this);
  2150. this.root = this;
  2151. this.created();
  2152. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  2153. this._applyListeners()
  2154. }
  2155. }
  2156. */
  2157. /*
  2158. bOa = function(a, b, c) {
  2159. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  2160. d.prototype.is = b;
  2161. d.prototype.localName = b;
  2162. c && aOa(d, c);
  2163. return function(e) {
  2164. e && (d.prototype.hostElement = e);
  2165. var g = new d;
  2166. g.root = g;
  2167. g.hostElement = e;
  2168. return g
  2169. }
  2170. }
  2171. */
  2172.  
  2173.  
  2174. }
  2175. const symDH = Symbol();
  2176.  
  2177. const wfStore = new WeakMap();
  2178.  
  2179. const wrapF = function (f, key) {
  2180. if (wfStore.get(f)) return wfStore.get(f);
  2181.  
  2182. let g = function () {
  2183. const o = kRef(this);
  2184. if (!o) return;
  2185. const cnt = insp(o);
  2186. // if (cnt === o) return;
  2187. // if (!('ready' in cnt)) return;
  2188. return f.apply(o, arguments);
  2189. };
  2190. g.key38 = key;
  2191. g.originalFunc38 = f;
  2192. g.__wrapF84__ = true;
  2193. wfStore.set(f, g);
  2194. wfStore.set(g, g);
  2195. return g;
  2196. };
  2197.  
  2198. if (MemoryFix_Flag002 & 16) {
  2199. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  2200.  
  2201. Object.defineProperty(Node.prototype, key, {
  2202. get() {
  2203. return this[`__a0939${key}__`];
  2204. },
  2205. set(nv) {
  2206. if (typeof nv !== 'function') return;
  2207. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  2208. this[`__a0939${key}__`] = g;
  2209. return true;
  2210. }
  2211. });
  2212.  
  2213.  
  2214. });
  2215. }
  2216.  
  2217.  
  2218.  
  2219. // const wm = new WeakMap();
  2220.  
  2221. const fixDetachFn = (tpProto) => { // & 32
  2222.  
  2223. if (tpProto.dk322) return;
  2224. tpProto.dk322 = true;
  2225.  
  2226. window.__fixTemplateReuse1058__ = true;
  2227.  
  2228.  
  2229. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  2230. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  2231. tpProto.__ensureTemplatized = function () {
  2232. // console.log(18470001)
  2233. return this.__ensureTemplatized994();
  2234. }
  2235. }
  2236.  
  2237.  
  2238. tpProto.__updateInstances994 = tpProto.__updateInstances;
  2239. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  2240. let bypass= false;
  2241. tpProto.__updateInstances = function (a, b, c) {
  2242.  
  2243. // const a_ = [...a];
  2244. if(!bypass && a === this.items && (a||0).length >=1 ){
  2245.  
  2246. bypass = true;
  2247. // console.log(18470002, a, b,c)
  2248. let e;
  2249. for (e = 0; e < b; e++) {
  2250. let g = this.__instances[e]
  2251. , k = c[e]
  2252. , m = a[k];
  2253. if(g && typeof (m||0) === 'object'){
  2254. // const q = g._shouldPropertyChange;
  2255. // g._shouldPropertyChange = ()=>true;
  2256. // g[this.as] = {};
  2257. // a_[k]=a[k] = m;
  2258. // g[this.as] = m;
  2259.  
  2260. // use public interface notifyPath instead of internal interface _setPendingProperty
  2261. const m_ = a[k] = Object.assign({}, a[k]);
  2262. try {
  2263. g.notifyPath(this.as, {});
  2264. } catch (e) { }
  2265. try {
  2266. g.notifyPath(this.as, m_);
  2267. } catch (e) { }
  2268.  
  2269. // g._setPendingProperty(this.as, {});
  2270. // g._setPendingProperty(this.as, m);
  2271. // g._setPendingProperty(this.indexAs, e);
  2272. // g._setPendingProperty(this.itemsIndexAs, k);
  2273. // delete g._shouldPropertyChange;
  2274. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2275. }
  2276. }
  2277. bypass = false;
  2278.  
  2279. }
  2280. const r = this.__updateInstances994(a,b,c);
  2281.  
  2282. // for (e = 0; e < b; e++) {
  2283. // let g = this.__instances[e]
  2284. // , k = c[e]
  2285. // , m = a_[k];
  2286. // if(g){
  2287. // // const q = g._shouldPropertyChange;
  2288. // // g._shouldPropertyChange = ()=>true;
  2289. // // g[this.as] = m;
  2290. // // g._setPendingProperty(this.as, {});
  2291. // // g._setPendingProperty(this.as, m);
  2292. // // g._setPendingProperty(this.indexAs, e);
  2293. // // g._setPendingProperty(this.itemsIndexAs, k);
  2294. // // delete g._shouldPropertyChange;
  2295. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2296. // }
  2297. // }
  2298.  
  2299. return r;
  2300. }
  2301. }
  2302.  
  2303. tpProto.__detachInstance994 = tpProto.__detachInstance;
  2304. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  2305. tpProto.__detachInstance = function (a) {
  2306. const u = this.__instances[a];
  2307. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2308. const children = (u || 0).children;
  2309. if (children && children.length >= 1) {
  2310. const pp = document.createDocumentFragment();
  2311. for (const s of [...children]) {
  2312. pp.appendChild(s);
  2313. }
  2314. }
  2315. try {
  2316. return this.__detachInstance994(a);
  2317. } catch (e) { }
  2318. return u;
  2319. }
  2320. }
  2321.  
  2322. tpProto.__attachInstance994 = tpProto.__attachInstance;
  2323. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  2324. tpProto.__attachInstance = function (a, b) {
  2325. const u = this.__instances[a];
  2326. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2327. if (u && u.root && b) {
  2328. const root = u.root;
  2329. const pp = document.createDocumentFragment();
  2330. pp.appendChild(root);
  2331. root.appendChild(pp);
  2332. const r = this.__attachInstance994(a, b);
  2333. if (!this.__chunkingId) this.__chunkingId = 0.25;
  2334. return r;
  2335. }
  2336. }
  2337. }
  2338.  
  2339. }
  2340.  
  2341. const ytTemplateDomEntry = (tpProto) => {
  2342.  
  2343. console.log('ytTemplateDomEntry triggered')
  2344.  
  2345.  
  2346. const convertToWeakArr = (arr) => {
  2347.  
  2348. if (arr.isWeak) return;
  2349.  
  2350. for (let i = 0, l = arr.length; i < l; i++) {
  2351. const o = arr[i]
  2352. if (o) {
  2353. let p = kRef(o)
  2354. if (!p) arr[i] = null;
  2355. else {
  2356. if (!o[wk]) o[wk] = mWeakRef(o);
  2357. arr[i] = o[wk];
  2358. }
  2359. }
  2360. }
  2361. arr.isWeak = true;
  2362.  
  2363. }
  2364.  
  2365. const convertToNormalArr = (arr) => {
  2366.  
  2367. if (!arr.isWeak) return;
  2368.  
  2369. for (let i = 0, l = arr.length; i < l; i++) {
  2370. const o = arr[i]
  2371. if (o) {
  2372. let p = kRef(o)
  2373. arr[i] = p;
  2374. }
  2375. }
  2376. arr.isWeak = false;
  2377.  
  2378. }
  2379.  
  2380. if (MemoryFix_Flag002 & 256) {
  2381. Object.defineProperty(tpProto, '__instances', {
  2382. get() {
  2383. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2384. let arr = this.__instances_actual471__;
  2385. if (arr && arr.isWeak) {
  2386. convertToNormalArr(arr);
  2387. for (let i = arr.length - 1; i >= 0; i--) {
  2388. const t = arr[i];
  2389. if (!t) arr.splice(i, 1);
  2390. else if (!t.__keepInstance038__) t.__keepInstance038__ = true;
  2391. }
  2392. Promise.resolve(arr).then(convertToWeakArr);
  2393. }
  2394. return arr;
  2395. },
  2396. set(nv) {
  2397. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2398. this.__instances_actual471__ = nv;
  2399. if (nv && !nv.isWeak) {
  2400. Promise.resolve(nv).then(convertToWeakArr);
  2401. }
  2402. return true;
  2403. },
  2404. enumerable: false,
  2405. configurable: true
  2406. });
  2407. }
  2408.  
  2409. // console.log(91901, tpProto.__detachInstance)
  2410. if (MemoryFix_Flag002 & 32) {
  2411. if (tpProto.__detachInstance) {
  2412. fixDetachFn(tpProto);
  2413. } else {
  2414. Promise.resolve(tpProto).then((tpProto) => {
  2415. // console.log(91902, tpProto.__detachInstance)
  2416. fixDetachFn(tpProto);
  2417. })
  2418. }
  2419. }
  2420.  
  2421. }
  2422.  
  2423. if (MemoryFix_Flag002 & 32) {
  2424. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  2425. set(nv) {
  2426. if (nv === true) return false;
  2427. tpProto = this;
  2428. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  2429. tpProto.__domDX37__ = true;
  2430. ytTemplateDomEntry(tpProto);
  2431. }
  2432. this.__ensureTemplatized949__ = nv;
  2433. return true;
  2434. },
  2435. get() {
  2436. return this.__ensureTemplatized949__;
  2437. }
  2438. });
  2439. }
  2440.  
  2441.  
  2442. if (MemoryFix_Flag002 & 64) {
  2443. HTMLElement_.prototype.__dataHostBinding374 = true;
  2444. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  2445. get() {
  2446. return kRef(this.__dataHostWr413__);
  2447. },
  2448. set(nv) {
  2449. if (nv && typeof nv === 'object' && !nv.deref) {
  2450. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2451. nv = nv[wk];
  2452. }
  2453. this.__dataHostWr413__ = nv;
  2454. return true;
  2455. }
  2456. });
  2457. }
  2458.  
  2459.  
  2460. const setupYProto = function (yProto) {
  2461.  
  2462. if(yProto === Object.prototype) return;
  2463.  
  2464. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2465. yProto[kMap.get(yProto)] = true;
  2466.  
  2467. 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') {
  2468. const disconnectedCallback277 = yProto.disconnectedCallback;
  2469. yProto.disconnectedCallback277 = true;
  2470. yProto.disconnectedCallback = function () {
  2471. disconnectedCallback277.call(this);
  2472. if (this.nodeName === 'DOM-IF' && this.__instance && typeof this.__teardownInstance === 'function') {
  2473. const shadyParent = (this.__shady_parentNode || 0);
  2474. const actualParent = (this.parentNode || 0);
  2475. if (shadyParent !== actualParent && shadyParent.nodeType === 11 && actualParent.nodeType === 11) {
  2476. // && (shadyParent.compareDocumentPosition(actualParent) & (1|8|16) === 1)
  2477. // if (!this.restamp && !this.id && this.__ctor && this.isConnected === false) {
  2478. const children = (this.__instance.children || 0).length;
  2479. if (children >= 1) {
  2480. try {
  2481. this.__teardownInstance();
  2482. } catch (e) { }
  2483. }
  2484. // }
  2485. }
  2486. }
  2487. }
  2488. }
  2489.  
  2490.  
  2491. if (MemoryFix_Flag002 & 32) {
  2492. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  2493. fixDetachFn(yProto);
  2494. }
  2495. }
  2496.  
  2497. if (MemoryFix_Flag002 & 128) {
  2498. if (!yProto.__dataHostBinding374) {
  2499. yProto.__dataHostBinding374 = true;
  2500. Object.defineProperty(yProto, '__dataHost', {
  2501. set(nv) {
  2502. let dh = nv;
  2503. if (dh && typeof dh === 'object' && !dh.deref) {
  2504. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  2505. dh = wr;
  2506. }
  2507. this[symDH] = dh;
  2508. return true;
  2509. },
  2510. get() {
  2511. let wr = this[symDH];
  2512. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  2513. return obj;
  2514. },
  2515. enumerable: false,
  2516. configurable: true
  2517. });
  2518. }
  2519.  
  2520.  
  2521.  
  2522. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  2523. yProto._registerHostDX38__ = true;
  2524.  
  2525. // yProto._registerHost7133 = yProto._registerHost;
  2526.  
  2527. yProto.__enableOrFlushClients = function () {
  2528. const c_ = this.__dataPendingClients;
  2529. if (c_) {
  2530. const c = c_.slice();
  2531. c_.length = 0;
  2532. for (let d = 0, l = c.length; d < l; d++) {
  2533. let e = kRef(c[d]);
  2534. if (e) {
  2535. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  2536. }
  2537. }
  2538. }
  2539. }
  2540.  
  2541. yProto._enqueueClient = function (c) {
  2542. if (c === this || !c || typeof c !== 'object') return;
  2543. if (c.deref) c = kRef(c);
  2544. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  2545. if (!c[wk]) c[wk] = mWeakRef(c);
  2546. m.push(c[wk]);
  2547. }
  2548.  
  2549. }
  2550. }
  2551.  
  2552.  
  2553.  
  2554. }
  2555. const setupRendering = function () {
  2556.  
  2557. const cnt = this;
  2558. const cProto = Reflect.getPrototypeOf(cnt);
  2559. let yProto = Reflect.getPrototypeOf(cProto);
  2560.  
  2561. const yProtos = new Set();
  2562.  
  2563. if (!yMap.has(yProto)) {
  2564. // capture all ancenstor constructors of a and b (non-specific component type)
  2565.  
  2566. do {
  2567. if (yProto === Object.prototype || yProto === null) break;
  2568. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  2569. yProtos.add(yProto);
  2570. yProto = Reflect.getPrototypeOf(yProto);
  2571. } while (!yProtos.has(yProto));
  2572.  
  2573. for (const yProto of yProtos) {
  2574. yMap.add(yProto);
  2575. setupYProto(yProto)
  2576. }
  2577.  
  2578. }
  2579.  
  2580.  
  2581. if (!cMap.has(cProto)) {
  2582. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  2583. setupCProto(cProto);
  2584. }
  2585.  
  2586. }
  2587.  
  2588. /*
  2589.  
  2590. jF = function(M) {
  2591. var d = YNV.call(this) || this;
  2592. d._configureProperties(M);
  2593. d.root = d._stampTemplate(d.__dataHost);
  2594. var N = [];
  2595. d.children = N;
  2596. for (var R = d.root.firstChild; R; R = R.nextSibling)
  2597. N.push(R),
  2598. R.__templatizeInstance = d;
  2599. d.__templatizeOwner && d.__templatizeOwner.__hideTemplateChildren__ && d._showHideChildren(!0);
  2600. N = d.__templatizeOptions;
  2601. (M && N.instanceProps || !N.instanceProps) && d._enableProperties();
  2602. return d
  2603. };
  2604. */
  2605.  
  2606. const sb1 = Symbol();
  2607. Object.defineProperty(Object.prototype, 'root', {
  2608. get() {
  2609. return this[sb1];
  2610. },
  2611. set(nv){
  2612. const p = this ? kRef(this) : null;
  2613. const mv = nv ? kRef(nv) : null;
  2614.  
  2615. // if (typeof (this.host || 0) === 'object' && !this.host6833) {
  2616. // const host = this.host;
  2617. // if (!host[wk]) host[wk] = mWeakRef(host);
  2618. // this.host6833 = host[wk];
  2619. // delete this.host;
  2620. // console.log(21883, host)
  2621. // Object.defineProperty(this, 'host', {
  2622. // get() {
  2623. // return kRef(this.host6833);
  2624. // },
  2625. // set(nv) {
  2626. // if (!nv) {
  2627. // this.host6833 = nv;
  2628. // } else {
  2629. // if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2630. // this.host6833 = nv[wk];
  2631. // }
  2632. // return true;
  2633. // }, enumerable: false, configurable: true
  2634. // });
  2635. // }
  2636.  
  2637. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2638. p.__setupRendered399__ = true;
  2639. setupRendering.call(p);
  2640. }
  2641. if (mv && mv.is && !mv.__setupRendered399__) {
  2642. mv.__setupRendered399__ = true;
  2643. setupRendering.call(mv);
  2644. }
  2645.  
  2646. this[sb1] = nv;
  2647. return true;
  2648. }
  2649. });
  2650.  
  2651.  
  2652. }
  2653.  
  2654. let _cssSheet = null;
  2655. const addNewCSS = typeof CSSStyleSheet !== 'undefined' && document.adoptedStyleSheets ? (css) => {
  2656. if (!_cssSheet) {
  2657. _cssSheet = new CSSStyleSheet();
  2658. document.adoptedStyleSheets.push(_cssSheet);
  2659. }
  2660. _cssSheet.insertRule(`${css}`);
  2661. } : (css) => {
  2662. let nonce = document.querySelector('style[nonce]');
  2663. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2664. const st = document.createElement('style');
  2665. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2666. st.textContent = `${css}`;
  2667. let parent;
  2668. if (parent = document.head) parent.appendChild(st);
  2669. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  2670. }
  2671.  
  2672. function getTranslate() {
  2673.  
  2674. pLoad.then(() => {
  2675. addNewCSS(".yt-formatted-string-block-line{display:block;}");
  2676. });
  2677.  
  2678. const snCache = new Map();
  2679.  
  2680. if (TRANSLATE_DEBUG) {
  2681. console.log(11)
  2682. }
  2683.  
  2684. /** @type {(str: string?) => string} */
  2685. function _snippetText(str) {
  2686. // str can be underfinded
  2687. if (!str || typeof str !== 'string') return '';
  2688. let res = snCache.get(str);
  2689. if (res === undefined) {
  2690. let b = false;
  2691. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  2692. b = true;
  2693. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  2694. });
  2695. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  2696. b = true;
  2697. return '';
  2698. });
  2699. if (b) {
  2700. snCache.set(str, res);
  2701. snCache.set(res, null);
  2702. } else {
  2703. res = null;
  2704. snCache.set(str, null);
  2705. }
  2706. }
  2707. return res === null ? str : res;
  2708. }
  2709.  
  2710. /** @type {(snippet: Object) => string} */
  2711. function snippetText(snippet) {
  2712. let runs = snippet.runs;
  2713. const n = runs.length;
  2714. if (n === 1) return _snippetText(runs[0].text);
  2715. let res = new Array(n);
  2716. let ci = 0;
  2717. for (const s of runs) {
  2718. res[ci++] = _snippetText(s.text);
  2719. }
  2720. return res.join('\n');
  2721. }
  2722.  
  2723. const _DEBUG_szz = (t) => t.map(x => {
  2724. const tsr = x.transcriptSegmentRenderer;
  2725. return ({
  2726. t: tsr.snippet.runs.map(x => x.text).join('//'),
  2727. a: tsr.startMs,
  2728. b: tsr.endMs
  2729. });
  2730. });
  2731.  
  2732. const fixRuns = (runs) => {
  2733. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  2734. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  2735. const text = runs[0].text;
  2736. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  2737. const s = text.split(nlc);
  2738. let bi = 0;
  2739. runs.length = s.length;
  2740. for (const text of s) {
  2741. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  2742. }
  2743. }
  2744. for (const s of runs) {
  2745. s.text = _snippetText(s.text);
  2746. }
  2747. }
  2748.  
  2749. function translate(initialSegments) {
  2750. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  2751.  
  2752. if (!initialSegments) return initialSegments;
  2753.  
  2754. if (TRANSLATE_DEBUG) {
  2755. console.log(12);
  2756. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  2757. let obj = JSON.parse(r);
  2758. console.log(7558, 1, obj)
  2759. return obj;
  2760. }).then(p => {
  2761. let obj = _DEBUG_szz(p)
  2762. console.log(7558, 2, obj)
  2763. })
  2764. }
  2765.  
  2766.  
  2767. //let mapRej = new WeakSet();
  2768.  
  2769. const n1 = initialSegments.length;
  2770. if (!n1) return fRes;
  2771. let n2 = 0;
  2772.  
  2773.  
  2774. const fRes = new Array(n1);
  2775. // -----------------------------------------------------------------------------------------
  2776.  
  2777. const s8 = Symbol();
  2778.  
  2779. {
  2780.  
  2781. /** @type {Map<String, Object>} */
  2782. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  2783.  
  2784. // /-* * @type {Map<String, number>} *-/
  2785. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  2786. // 1: ok
  2787. // 2: abandoned effect text
  2788.  
  2789. for (const initialSegment of initialSegments) {
  2790. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  2791. if (!transcript) {
  2792. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2793. fRes[n2++] = initialSegment;
  2794. continue;
  2795. }
  2796. const runs = transcript.snippet.runs
  2797. if (!runs || runs.length === 0) {
  2798. initialSegment[s8] = true;
  2799. continue;
  2800. }
  2801. let startMs = (+transcript.startMs || 0); //integer
  2802. let endMs = (+transcript.endMs || 0); //integer
  2803. if (startMs === endMs) {
  2804. // effect text
  2805. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2806. //mapRej.add(initialSegment)
  2807. continue;
  2808. }
  2809. if (endMs - startMs < 30) {
  2810. continue;
  2811. }
  2812. const text = snippetText(transcript.snippet);
  2813. const hEntry = cacheTexts.get(text);
  2814. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  2815. if (mh1e === 2) continue;
  2816. const entry = {
  2817. startMs,
  2818. endMs,
  2819. initialSegment,
  2820. text
  2821. };
  2822. if (mh1e === 0) {
  2823. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  2824. initialSegment[s8] = true;
  2825. cacheTexts.set(text, null);
  2826. //effect only
  2827. // https://www.youtube.com/watch?v=zLak0dxBKpM
  2828. //mapRej.add(initialSegment)
  2829. continue;
  2830. }
  2831. } else if (hEntry) {
  2832.  
  2833. const timeDiff = entry.startMs - hEntry.endMs;
  2834. let shouldMerge = false;
  2835.  
  2836. if (timeDiff >= 0) {
  2837.  
  2838. if (timeDiff < 25) {
  2839. shouldMerge = true;
  2840. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  2841. shouldMerge = true;
  2842. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  2843. shouldMerge = true;
  2844. }
  2845.  
  2846. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  2847. // abandon the current entry.
  2848. // absorbed by previous entry
  2849. hEntry.endMs = entry.endMs;
  2850. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2851. //mapRej.add(entry.initialSegment);
  2852. continue;
  2853. }
  2854.  
  2855. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  2856.  
  2857. // abandon the current entry.
  2858. // absorbed by previous entry
  2859. if (entry.endMs > hEntry.endMs) {
  2860. hEntry.endMs = entry.endMs;
  2861. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2862. }
  2863. //mapRej.add(entry.initialSegment);
  2864. continue;
  2865.  
  2866. }
  2867.  
  2868. }
  2869. //if not abandoned
  2870. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  2871. // for (const s of runs) {
  2872. // s.text = _snippetText(s.text);
  2873. // }
  2874. fixRuns(runs);
  2875. fRes[n2++] = initialSegment;
  2876. }
  2877.  
  2878. // cacheTexts.clear(); // let GC do it.
  2879. cacheTexts = null;
  2880. // mh1.clear(); // let GC do it.
  2881. // mh1 = null;
  2882.  
  2883. }
  2884.  
  2885. const si_length = fRes.length = n2;
  2886. const sj_length = n1;
  2887.  
  2888. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  2889. // collect the abandon text to become second subtitle
  2890.  
  2891. let sj_start = 0;
  2892. let invalid_sj = -1;
  2893. for (let si = 0; si < si_length; si++) {
  2894. const segment = fRes[si];
  2895. let transcript = segment.transcriptSegmentRenderer;
  2896. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  2897. const runs = transcript.snippet.runs;
  2898. // fixRuns(runs);
  2899. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  2900. const main_startMs = (+transcript.startMs || 0);
  2901. const main_endMs = (+transcript.endMs || 0);
  2902. transcript = null;
  2903.  
  2904. /** @type {Map<string, number>} */
  2905. let tMap = new Map(); // avoid duplicate with javascript object properties
  2906.  
  2907. // assume that it is asc-ordered array of key startMs;
  2908. for (let sj = sj_start; sj < sj_length; sj++) {
  2909. const initialSegment = initialSegments[sj];
  2910.  
  2911. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  2912.  
  2913. const tSegment = initialSegment.transcriptSegmentRenderer;
  2914.  
  2915. if (!tSegment) {
  2916. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2917. invalid_sj = sj; // should invalid_sj be set ?
  2918. continue;
  2919. }
  2920.  
  2921. const startMs = (+tSegment.startMs || 0)
  2922. const isStartValid = startMs >= main_startMs;
  2923. if (!isStartValid) {
  2924. invalid_sj = sj;
  2925. continue;
  2926. }
  2927. // isStartValid must be true
  2928. if (startMs > main_endMs) {
  2929. sj_start = invalid_sj + 1;
  2930. break;
  2931. }
  2932.  
  2933. const endMs = (+tSegment.endMs || 0)
  2934. if (endMs <= main_endMs) {
  2935. const mt = snippetText(tSegment.snippet);
  2936. const prev = tMap.get(mt);
  2937. if (endMs >= startMs) {
  2938. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  2939. }
  2940. }
  2941.  
  2942. }
  2943.  
  2944. if (tMap.size <= 1) continue; // no second line
  2945. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  2946. tMap = null;
  2947.  
  2948. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2949.  
  2950. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  2951.  
  2952. let targetZ = rg[1][1];
  2953. if (targetZ > 4) {
  2954. let az = 0;
  2955. let fail = false;
  2956. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  2957. az += rg[idx][1];
  2958. if (az >= targetZ) {
  2959. fail = true;
  2960. break;
  2961. }
  2962. }
  2963. if (!fail) {
  2964. const rgA = rg[0][0];
  2965. const rgB = rg[1][0];
  2966. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  2967. if (isDiff && rgA === _snippetText(runs[0].text)) {
  2968. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  2969. runs.push({ text: rgB, blockLine: true });
  2970. }
  2971. }
  2972. }
  2973. rg = null;
  2974. }
  2975.  
  2976. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  2977.  
  2978. let obj = r;
  2979. console.log(7559, 1, obj)
  2980. return obj;
  2981. }).then(p => {
  2982. let obj = _DEBUG_szz(p)
  2983. console.log(7559, 2, obj)
  2984.  
  2985. });
  2986. }
  2987.  
  2988. // -----------------------------------------------------------------------------------------
  2989. snCache.clear();
  2990. return fRes;
  2991.  
  2992. }
  2993.  
  2994.  
  2995. return translate
  2996.  
  2997. }
  2998.  
  2999.  
  3000. let translateFn = null;
  3001.  
  3002. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  3003.  
  3004. const wmx = new WeakMap();
  3005.  
  3006. function fixSegments(ytObj) {
  3007. let a, b;
  3008. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  3009. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  3010. translateFn = translateFn || getTranslate();
  3011. let cSeg;
  3012. cSeg = wmx.get(seg);
  3013. if (!cSeg) {
  3014. let vSeg = null;
  3015. try {
  3016. vSeg = translateFn(seg);
  3017. } catch (e) {
  3018. }
  3019. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  3020. // console.log('translated', vSeg);
  3021. cSeg = vSeg;
  3022. wmx.set(seg, cSeg);
  3023. wmx.set(cSeg, cSeg);
  3024. }
  3025. }
  3026. if (cSeg && cSeg !== seg) {
  3027. a[b] = cSeg;
  3028. }
  3029. }
  3030.  
  3031. const dfn = Symbol();
  3032. const Object_ = Object;
  3033. Object_[dfn] = Object_.defineProperties;
  3034. let activation = true;
  3035. Object_.defineProperties = function (obj, pds) {
  3036. let segments, get_;
  3037. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  3038. activation = false;
  3039. segments.get = function () {
  3040. fixSegments(this);
  3041. return get_.call(this);
  3042. };
  3043. }
  3044. return Object_[dfn](obj, pds);
  3045. };
  3046.  
  3047. })();
  3048.  
  3049.  
  3050. let pf31 = new PromiseExternal();
  3051.  
  3052. // native RAF
  3053. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  3054.  
  3055. // 1st wrapped RAF
  3056. const baseRAF = (callback) => {
  3057. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  3058. pf31.then(() => {
  3059. callback(hRes);
  3060. });
  3061. });
  3062. };
  3063.  
  3064. // 2nd wrapped RAF
  3065. window.requestAnimationFrame = baseRAF;
  3066.  
  3067. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  3068. const indr = o => insp(o).$ || o.$ || 0;
  3069.  
  3070. const prototypeInherit = (d, b) => {
  3071. const m = Object.getOwnPropertyDescriptors(b);
  3072. for (const p in m) {
  3073. if (!Object.getOwnPropertyDescriptor(d, p)) {
  3074. Object.defineProperty(d, p, m[p]);
  3075. }
  3076. }
  3077. };
  3078.  
  3079.  
  3080. const firstObjectKey = (obj) => {
  3081. for (const key in obj) {
  3082. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  3083. }
  3084. return null;
  3085. };
  3086.  
  3087. function searchNestedObject(obj, predicate, maxDepth = 64) {
  3088. // normal case: depth until 36
  3089. const result = [];
  3090. const visited = new WeakSet();
  3091.  
  3092. function search(obj, depth) {
  3093. visited.add(obj);
  3094. for (const [key, value] of Object.entries(obj)) {
  3095. // Recursively search nested objects and arrays
  3096. if (value !== null && typeof value === 'object') {
  3097. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  3098. if (depth + 1 <= maxDepth && !visited.has(value)) {
  3099. search(value, depth + 1);
  3100. }
  3101. } else if (predicate(value)) {
  3102. result.push([obj, key]);
  3103. }
  3104. }
  3105. }
  3106.  
  3107. typeof (obj || 0) === 'object' && search(obj, 0);
  3108. return result;
  3109. }
  3110.  
  3111. /** @type {(o: Object | null) => WeakRef | null} */
  3112. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  3113.  
  3114. /** @type {(wr: Object | null) => Object | null} */
  3115. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  3116.  
  3117. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  3118.  
  3119. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  3120. if (DENY_requestStorageAccess) {
  3121. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  3122. Document.prototype.requestStorageAccessFor = undefined;
  3123. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  3124. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  3125. Document.prototype.requestStorageAccessFor = function () {
  3126. return new Promise((resolve, reject) => {
  3127. reject();
  3128. });
  3129. };
  3130. }
  3131. }
  3132.  
  3133. const traceStack = (stack) => {
  3134. let result = new Set();
  3135. let p = new Set();
  3136. let u = ''
  3137. for (const s of stack.split('\n')) {
  3138. if (s.split(':').length < 3) continue;
  3139. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  3140. if (!m) continue;
  3141. p.add(m[2]);
  3142. if (p.size >= 3) break;
  3143. if(!u) u = m[2];
  3144. else if(p.size === 2 && u && u=== m[2]) break;
  3145. result.add(s);
  3146. }
  3147. return [...result].join('\n');
  3148. }
  3149.  
  3150. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  3151. // window.m3bb = new Set();
  3152.  
  3153. // const smb = Symbol();
  3154. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  3155. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  3156. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  3157.  
  3158. const thisConversionFn = (thisArg) => {
  3159. if (!thisArg) return null;
  3160. const kThis = thisArg[vmb];
  3161. if (kThis) {
  3162. const ref = kThis.ref;
  3163. return (ref ? kRef(ref) : null) || null;
  3164. }
  3165. return thisArg;
  3166. }
  3167.  
  3168. const pFnHandler2 = {
  3169. get(target, prop) {
  3170. if (prop === vmc) return target;
  3171. return Reflect.get(target, prop);
  3172. },
  3173. apply(target, thisArg, argumentsList) {
  3174. thisArg = thisConversionFn(thisArg);
  3175. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  3176. }
  3177. }
  3178.  
  3179.  
  3180. const proxySelfHandler = {
  3181. get(target, prop) {
  3182. if(prop === vmb) return target;
  3183. const ref = target.ref;
  3184. const cnt = kRef(ref);
  3185. if (!cnt) return;
  3186. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  3187. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  3188. return cnt[prop][vmd];
  3189. }
  3190. return cnt[prop];
  3191. },
  3192. set(target, prop, value) {
  3193. const cnt = kRef(target.ref);
  3194. if (!cnt) return true;
  3195. if(value && (value[vmc] || value[vmb])){
  3196. cnt[prop] = value[vmc] || thisConversionFn(value);
  3197. return true;
  3198. }
  3199. cnt[prop] = value;
  3200. return true;
  3201. }
  3202. };
  3203.  
  3204. const weakWrap = (thisArg) => {
  3205. thisArg = thisConversionFn(thisArg);
  3206. if (!thisArg) {
  3207. console.error('thisArg is not found');
  3208. return null;
  3209. }
  3210. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  3211. }
  3212.  
  3213. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  3214. window.getComputedStyle533 = window.getComputedStyle;
  3215. window.getComputedStyle = function (a, ...args) {
  3216. a = thisConversionFn(a);
  3217. if (a) {
  3218. return getComputedStyle533(a, ...args);
  3219. }
  3220. return null;
  3221. }
  3222. }
  3223.  
  3224. Function._count_bind_00 = 0;
  3225. // Function._count_bind_01 = 0;
  3226.  
  3227. // let matchNativeCode = (Object+"");
  3228. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  3229. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  3230.  
  3231. // const matchConstructor = (thisArg) => {
  3232. // const f = `${(thisArg || 0).constructor}`;
  3233. // if (f.length > 45) return true;
  3234. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  3235. // if (f.includes('[native code]')){
  3236. // return false;
  3237. // }
  3238. // return true;
  3239. // }
  3240. // return false;
  3241. // }
  3242.  
  3243. // const acceptThis = (thisArg)=>{
  3244. // // if(!thisArg || typeof thisArg !=='object') return false;
  3245. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  3246. // // if(typeof thisArg.path === 'string') return true;
  3247. // // if(typeof thisArg.fn === 'function') return true;
  3248. // // if(typeof thisArg.id === 'string') return true;
  3249. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  3250. // return false;
  3251. // }
  3252.  
  3253. const patchFn = (fn) => {
  3254.  
  3255. let s = `${fn}`;
  3256. if (s.length < 11 || s.includes('\n')) return false;
  3257. if(s.includes('bind(this')) return true;
  3258. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  3259. // var a=this;
  3260. // f.bind(this)
  3261.  
  3262.  
  3263. return false;
  3264. }
  3265.  
  3266. Function.prototype.bind488 = Function.prototype.bind;
  3267. Function.prototype.bind = function(thisArg, ...args){
  3268.  
  3269. if (thisConversionFn(thisArg) !== thisArg) {
  3270. return this.bind488(thisArg, ...args);
  3271. }
  3272. if( thisArg && patchFn(this) ){
  3273.  
  3274. // console.log(599,`${this}`)
  3275.  
  3276. try {
  3277. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  3278. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  3279. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  3280. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  3281. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  3282. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  3283. // // let b4 = false;
  3284. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  3285.  
  3286. // // b3 = false;
  3287. // // b4 = false;
  3288. // // b5 = false;
  3289.  
  3290. // if (b1 || b2 || b3 ||b4 ) {
  3291. const f = this;
  3292. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  3293. if (ps && ps[vmb]) {
  3294. Function._count_bind_00++;
  3295. return f.bind488(ps, ...args)
  3296. }
  3297. // }
  3298. } catch (e) {
  3299. console.warn(e)
  3300. }
  3301. }
  3302. return this.bind488(thisArg, ...args);
  3303. }
  3304. Function.prototype.bind588 = 1;
  3305. }
  3306.  
  3307. const ytSchedulerMethods = {
  3308. addJob(a, b, c) {
  3309. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3310. if (instance) {
  3311. return instance.addJob(a, b, c);
  3312. } else {
  3313. return setTimeout(a, c);
  3314. }
  3315. },
  3316. addImmediateJob(a) {
  3317. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3318. if (instance) {
  3319. return instance.addImmediateJob(a);
  3320. } else {
  3321. a();
  3322. }
  3323. },
  3324. cancelJob(id) {
  3325. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3326. if (instance) {
  3327. return instance.cancelJob(id);
  3328. } else {
  3329. return clearTimeout(id);
  3330. }
  3331. }
  3332. };
  3333.  
  3334. if (FIX_ytScheduler) {
  3335.  
  3336. let ytSchedulerFixed = 0;
  3337. // let ytActioned = false;
  3338. // let pr = new PromiseExternal();
  3339.  
  3340. // const hn = function () {
  3341.  
  3342. // document.removeEventListener('yt-action', hn, true);
  3343. // nextBrowserTick_(() => {
  3344. // ytActioned = true;
  3345. // pr.resolve();
  3346. // });
  3347.  
  3348. // }
  3349. // document.addEventListener('yt-action', hn, true);
  3350.  
  3351. // let cancelStore = {}; // tbc
  3352.  
  3353. // yt.scheduler.instance.addJob
  3354. const fixAddJob = (nv) => {
  3355.  
  3356. /*
  3357. function Z() {
  3358. var a = w("ytglobal.schedulerInstanceInstance_");
  3359. if (!a || a.s)
  3360. a = new M(I("scheduler") || {}),
  3361. x("ytglobal.schedulerInstanceInstance_", a);
  3362. return a
  3363. }
  3364. */
  3365.  
  3366. /*
  3367. function R(a, b, c, d) {
  3368. ++a.D;
  3369. if (c === 10)
  3370. return P(a, b),
  3371. a.D;
  3372. var e = a.D;
  3373. a.h[e] = b;
  3374. a.l && !d ? a.u.push({
  3375. id: e,
  3376. priority: c
  3377. }) : (a.i[c].push(e),
  3378. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  3379. a.start()));
  3380. return e
  3381. }
  3382. */
  3383.  
  3384. /*
  3385. function sa(a, b, c) {
  3386. if (!c)
  3387. return c = c === void 0,
  3388. -R(Z(), a, b, c);
  3389. var d = window.setTimeout(function() {
  3390. var e = R(Z(), a, b);
  3391. W[d] = e
  3392. }, c);
  3393. return d
  3394. }
  3395. */
  3396. window.originalAddJob = nv;
  3397. // const q1 = new PromiseExternal();
  3398. // const q2 = new PromiseExternal();
  3399. // let uu = 0;
  3400. // let q3 = 0;
  3401. // let mof = null;
  3402. // const mo = new MutationObserver((mutation, observer) => {
  3403. // if (mof) {
  3404. // if (mof() === true) {
  3405. // observer.disconnect();
  3406. // mof = null;
  3407. // }
  3408. // }
  3409. // });
  3410.  
  3411. let lenSkip = -1;
  3412. let lastLen = null;
  3413. let fetchCommentJobTimerId = 0;
  3414. let requestFinish = false;
  3415.  
  3416. const fetchCommentJobDone = ()=>{
  3417. clearInterval(fetchCommentJobTimerId);
  3418. fetchCommentJobTimerId = 0;
  3419. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3420. }
  3421.  
  3422. const fetchCommentJob = (a, cid) => {
  3423.  
  3424. // if (cid && cancelStore[cid]) return; // tbc
  3425.  
  3426. if(fetchCommentJobTimerId > 0){
  3427. fetchCommentJobDone();
  3428. }
  3429.  
  3430. // if (mof) {
  3431. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3432. // mof = null;
  3433. // }
  3434.  
  3435. let f = a;
  3436.  
  3437. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  3438.  
  3439. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  3440.  
  3441. lastLen = -1;
  3442. let u = 0;
  3443. let g = () => {
  3444. if (requestFinish) lastLen = -1;
  3445. const lastLen_ = lastLen;
  3446. const len1 = lastLen = document.querySelectorAll(selector).length;
  3447. let mm = true;
  3448. let ff = false;
  3449. if (len1 !== lastLen_) {
  3450. u = 0;
  3451. f();
  3452. const len2 = lastLen = document.querySelectorAll(selector).length;
  3453. if (len2 !== len1) {
  3454. ff = true;
  3455. mm = false;
  3456. }
  3457. }
  3458. if (mm) {
  3459. ++u;
  3460. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  3461. ff = true;
  3462. }
  3463. }
  3464.  
  3465. if (requestFinish) {
  3466. requestFinish = false;
  3467. fetchCommentJobDone();
  3468. } else if (ff){
  3469. fetchCommentJobDone();
  3470. }
  3471.  
  3472. }
  3473.  
  3474.  
  3475. fetchCommentJobTimerId = setInterval(g, 80);
  3476. // g(9);
  3477. // if (lastLen === lenSkip) {
  3478. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3479. // g = f = null;
  3480. // return;
  3481. // }
  3482. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3483. // const q1 = lastLen;
  3484. // mof = () => {
  3485. // const q2 = document.querySelectorAll(selector).length;
  3486. // if (q1 === q2) return;
  3487. // fetchCommentJobTimerId = setTimeout(g, 80);
  3488. // g = null;
  3489. // return true;
  3490. // }
  3491. // mo.observe(document, { childList: true, subtree: true });
  3492.  
  3493. }
  3494.  
  3495. // let pr72 = Promise.resolve();
  3496.  
  3497.  
  3498. let qa = null;
  3499. let qasf = '';
  3500.  
  3501.  
  3502. document.addEventListener("fullscreenchange", (evt) => {
  3503. if (evt.isTrusted !== true) return;
  3504. if (qa) {
  3505. // qa();
  3506. nextBrowserTick_(qa);
  3507. }
  3508. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3509. // pr72 = pr72.then(() => {
  3510. // return pr
  3511. // });
  3512. }, true);
  3513.  
  3514. window.addEventListener("resize", (evt) => {
  3515. if (evt.isTrusted !== true) return;
  3516. if (qa) {
  3517. // qa();
  3518. nextBrowserTick_(qa);
  3519. }
  3520. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3521. // pr72 = pr72.then(() => {
  3522. // return pr
  3523. // });
  3524. }, true);
  3525.  
  3526.  
  3527. setInterval(() => {
  3528. const f = qa;
  3529. if (typeof f !== 'function') return;
  3530. qa = null;
  3531. // pr72 = pr72.then(() => {
  3532. // f();
  3533. // });
  3534. // nextBrowserTick_(()=>{
  3535. f();
  3536. // });
  3537. }, 475.25);
  3538.  
  3539.  
  3540.  
  3541. return function (a, b, c) {
  3542.  
  3543.  
  3544. const f = a;
  3545. // const g = ()=>{
  3546. // pr72 = pr72.then(()=>{
  3547. // f();
  3548. // });
  3549. // }
  3550.  
  3551. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  3552.  
  3553. const c_ = c;
  3554.  
  3555. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  3556.  
  3557. if (b === 1 && c_ === 500) {
  3558. const sf = `${a}`;
  3559. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  3560. qasf = sf;
  3561. qa = a;
  3562. // console.log(12883, a)
  3563. return nv(() => {
  3564. if (qa === a) {
  3565. qa = null;
  3566. a();
  3567. }
  3568. }, b, c);
  3569. }
  3570. }
  3571.  
  3572.  
  3573. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  3574. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  3575. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3576. // pr72 = pr72.then(() => {
  3577. // return pr
  3578. // });
  3579. // try {
  3580. // yt.scheduler.instance.cancelAllJobs();
  3581. // yt.scheduler.instance.dispose();
  3582. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  3583. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  3584. // } catch (e) { }
  3585. return nv(f, b, c);
  3586. }
  3587.  
  3588. // if(!b && c > 50) c = 50;
  3589. // console.log(58372,a,b,c)
  3590. // function(){xxx(xxx)}
  3591. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  3592.  
  3593. /*
  3594.  
  3595. V.setCommentsJobId = _.et(_.r0, function() {
  3596. F5V(V)
  3597. }, 1E3)
  3598.  
  3599. */
  3600.  
  3601. requestFinish = false;
  3602. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  3603.  
  3604. // lastLen = null;
  3605. fetchCommentJob(a, cid);
  3606.  
  3607. // queueMicrotask_(a);
  3608. // nextBrowserTick_(a);
  3609. // a(); // no need to delay
  3610. return cid
  3611.  
  3612. // return nv(a, b, 1.125);
  3613. // const cid = window.setTimeout(() => {
  3614. // nextBrowserTick_(() => {
  3615. // if (cancelStore[cid]) {
  3616. // console.log('task cancelled');
  3617. // return;
  3618. // }
  3619. // a();
  3620.  
  3621. // });
  3622. // }, 0.125);
  3623. // return cid;
  3624. } else {
  3625.  
  3626.  
  3627.  
  3628. return nv(f,b,c);
  3629.  
  3630.  
  3631. // if (c > 2400) c = 2400;
  3632. // else if (c > 800) c = 800;
  3633. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  3634. // if (0 && ytActioned && !b) {
  3635. // const cid = window.setTimeout(() => {
  3636. // nextBrowserTick_(() => {
  3637. // if (cancelStore[cid]) {
  3638. // console.log('task cancelled');
  3639. // return;
  3640. // }
  3641. // a();
  3642. // });
  3643. // }, c);
  3644. // return cid;
  3645. // } else {
  3646. // return nv(a, b, c);
  3647. // }
  3648.  
  3649. }
  3650. }
  3651. }
  3652.  
  3653. const fixCancelJob = (nv) => {
  3654.  
  3655.  
  3656. window.originalCancelJob = nv;
  3657. return function (a) {
  3658. if (a < 0) return nv(a);
  3659. // cancelStore[a] = true; // tbc
  3660. nv(a);
  3661. }
  3662. }
  3663.  
  3664. const sk44 = Symbol();
  3665. Object.defineProperty(Object.prototype, 'addJob', {
  3666. get() {
  3667. return this[sk44];
  3668. },
  3669. set(nv) {
  3670. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3671. ytSchedulerFixed |= 1;
  3672. nv = fixAddJob(nv);
  3673. }
  3674. this[sk44] = nv;
  3675. return true;
  3676. },
  3677. enumerable: false,
  3678. configurable: true
  3679. });
  3680.  
  3681.  
  3682.  
  3683. const sk45 = Symbol();
  3684. Object.defineProperty(Object.prototype, 'cancelJob', {
  3685. get() {
  3686. return this[sk45];
  3687. },
  3688. set(nv) {
  3689. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3690. ytSchedulerFixed |= 2;
  3691. nv = fixCancelJob(nv);
  3692. }
  3693. this[sk45] = nv;
  3694. return true;
  3695. },
  3696. enumerable: false,
  3697. configurable: true
  3698. });
  3699.  
  3700.  
  3701.  
  3702. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3703. const { addJob, cancelJob } = yt.scheduler.instance;
  3704. if (addJob) {
  3705. yt.scheduler.instance.addJob = null;
  3706. yt.scheduler.instance.addJob = addJob;
  3707. }
  3708. if (cancelJob) {
  3709. yt.scheduler.instance.cancelJob = null;
  3710. yt.scheduler.instance.cancelJob = cancelJob;
  3711. }
  3712. }
  3713.  
  3714.  
  3715. }
  3716.  
  3717. const isWatchPageURL = (url) => {
  3718. url = url || location;
  3719. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  3720. };
  3721.  
  3722. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3723.  
  3724. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  3725. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3726. if (typeof customElements === 'undefined') {
  3727. if (!('__CE_registry' in document)) {
  3728. // https://github.com/webcomponents/polyfills/
  3729. Object.defineProperty(document, '__CE_registry', {
  3730. get() {
  3731. // return undefined
  3732. },
  3733. set(nv) {
  3734. if (typeof nv == 'object') {
  3735. delete this.__CE_registry;
  3736. this.__CE_registry = nv;
  3737. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3738. }
  3739. return true;
  3740. },
  3741. enumerable: false,
  3742. configurable: true
  3743. })
  3744. }
  3745. let eventHandler = (evt) => {
  3746. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3747. const f = callback;
  3748. callback = null;
  3749. eventHandler = null;
  3750. f();
  3751. };
  3752. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3753. } else {
  3754. callback();
  3755. }
  3756. });
  3757.  
  3758. const whenCEDefined = isCustomElementsProvided
  3759. ? (nodeName) => customElements.whenDefined(nodeName)
  3760. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3761.  
  3762. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  3763. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  3764. const f = performance.now23 = Performance.prototype.now;
  3765.  
  3766. let k = 0; // 0 <= k < 9998m
  3767. let u = 0;
  3768. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  3769.  
  3770. // By definition, performance.now() is mono increasing.
  3771. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  3772. performance.now = performance.now16 = function () {
  3773. /**
  3774. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  3775. *
  3776. * If consecutive session history entries had history.state.entryTime set to same value,
  3777. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  3778. * and modifying its return value slightly to make sure two close consecutive calls don't
  3779. * get the same result helped with resolving the issue.
  3780. */
  3781. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  3782. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  3783.  
  3784. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  3785. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  3786. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  3787. else { // more than 9998 consecutive calls
  3788. /**
  3789. *
  3790. * max no. of consecutive calls
  3791. *
  3792. * Sample Size: 4800
  3793. * Sample Avg = 1565.375
  3794. * Sample Median = 1469.5
  3795. * Sample Max = 5660 << 7500 << 9999
  3796. *
  3797. *
  3798. * */
  3799. k = 0;
  3800. s += 1 / 7;
  3801. }
  3802. return v + k; // 0 < v - M < v - M + k < v
  3803. }
  3804.  
  3805. let loggerMsg = '';
  3806. if (`${performance.now()}` === `${performance.now()}`) {
  3807. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  3808. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  3809. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  3810. }
  3811. loggerMsg && console.warn(loggerMsg);
  3812. })();
  3813.  
  3814. // let __forceRemoveMode__ = false;
  3815. FIX_removeChild && (() => {
  3816. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  3817. let internalByPass = false;
  3818. const fragD = document.createDocumentFragment();
  3819. fragD.appendChild4201 = fragD.appendChild;
  3820. fragD.removeChild4201 = fragD.removeChild;
  3821. Node.prototype.removeChild062 = Node.prototype.removeChild;
  3822. Node.prototype.removeChild = function (child) {
  3823. try {
  3824. return this.removeChild062(child);
  3825. } catch (e) { }
  3826. if (internalByPass) return child;
  3827. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  3828. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3829. if (idx >= 0) {
  3830. internalByPass = true;
  3831. child.parentNode !== fragD && fragD.appendChild4201(child);
  3832. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3833. fragD.removeChild4201(child);
  3834. internalByPass = false;
  3835. return child;
  3836. }
  3837. }
  3838. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  3839. // // force removal
  3840. // internalByPass = true;
  3841. // child.parentNode !== fragD && fragD.appendChild4201(child);
  3842. // fragD.removeChild4201(child);
  3843. // internalByPass = false;
  3844. // return child;
  3845. // }
  3846. if (this && child) {
  3847. if (this.childNodes && this.childNodes.splice) { // tbc
  3848. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3849. if (idx >= 0) {
  3850. internalByPass = true;
  3851. child.parentNode !== fragD && fragD.appendChild4201(child);
  3852. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3853. fragD.removeChild4201(child);
  3854. internalByPass = false;
  3855. return child;
  3856. }
  3857. }
  3858.  
  3859. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  3860. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  3861. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  3862. return child;
  3863. }
  3864. }
  3865.  
  3866. if (child && child.is === 'tp-yt-paper-tooltip' && !child.parentNode && !child.__shady_parentNode) {
  3867. // skip
  3868. return child;
  3869. }
  3870.  
  3871. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  3872. parent: this, child: child,
  3873. isParent: child.parentNode === this,
  3874. isParentParent: (child.parentNode || 0).parentNode === this,
  3875. parentNode: child.parentNode,
  3876. shadyParent: child.__shady_parentNode,
  3877. isShadyParent: child.__shady_parentNode === this,
  3878. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  3879. });
  3880.  
  3881. }
  3882. return child;
  3883. }
  3884. }
  3885. })();
  3886.  
  3887.  
  3888. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  3889.  
  3890. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  3891.  
  3892. // let cid = 0;
  3893.  
  3894. let mousemoveFn = null;
  3895. let mousemoveDT = 0;
  3896. let mousemoveCount = 0;
  3897. // let qv = false;
  3898. const cif = () => {
  3899. if (!mousemoveFn) return;
  3900. const ct = Date.now();
  3901. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  3902. mousemoveFn && mousemoveFn();
  3903. }
  3904. mousemoveFn = null;
  3905. };
  3906. let mousemoveCId = 0;
  3907. let mouseoverFn = null;
  3908. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  3909. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  3910. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  3911. const bt = `${b}`;
  3912. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  3913. b[`__$$${a}$$1926__`] = true;
  3914. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  3915. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  3916. // console.log(3928, a, this[`__$$${a}$$1937__`])
  3917. if (!this[`__$$${a}$$1938__`]) {
  3918. this[`__$$${a}$$1938__`] = b;
  3919. if (a === 'mousemove') {
  3920. this.addEventListener4882('mouseenter', (evt) => {
  3921. if (mousemoveCId) return;
  3922. mousemoveCId = setIntervalX0(cif, 380);
  3923. });
  3924. this.addEventListener4882('mouseleave', (evt) => {
  3925. clearIntervalX0(mousemoveCId);
  3926. mousemoveCId = 0;
  3927. });
  3928. }
  3929. this.addEventListener4882(a, (evt) => {
  3930. const evt_ = evt;
  3931. if (!this[`__$$${a}$$1937__`]) return;
  3932. if (!this[`__$$${a}$$1938__`]) return;
  3933. if (a === 'mousemove') {
  3934. mouseoverFn && mouseoverFn();
  3935. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  3936. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  3937. } else {
  3938. mousemoveCount = 0;
  3939. }
  3940. const f = mousemoveFn = () => {
  3941. if (f !== mousemoveFn) return;
  3942. mousemoveFn = null;
  3943. this[`__$$${a}$$1938__`](evt_);
  3944. };
  3945. if (mousemoveCount <= 1) mousemoveFn();
  3946. } else {
  3947. if (a === 'mouseout' || a === 'mouseleave') {
  3948. mousemoveFn = null;
  3949. mousemoveDT = 0;
  3950. mousemoveCount = 0;
  3951. this[`__$$${a}$$1938__`](evt_);
  3952. mouseoverFn && mouseoverFn();
  3953. } else { // mouseover, mouseenter
  3954. mousemoveFn = null;
  3955. mousemoveDT = 0;
  3956. mousemoveCount = 0;
  3957. mouseoverFn && mouseoverFn(); // just in case
  3958. const f = mouseoverFn = () => {
  3959. if (f !== mouseoverFn) return;
  3960. mouseoverFn = null;
  3961. this[`__$$${a}$$1938__`](evt_);
  3962. }
  3963. nextBrowserTick_(mouseoverFn);
  3964. }
  3965. }
  3966. }, c);
  3967.  
  3968.  
  3969. return;
  3970. } else {
  3971.  
  3972. return;
  3973. }
  3974. }
  3975.  
  3976. }
  3977. return this.addEventListener4882(a, b, c)
  3978. }
  3979.  
  3980.  
  3981.  
  3982.  
  3983. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  3984. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  3985. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  3986.  
  3987. if (b[`__$$${a}$$1926__`]) {
  3988. b[`__$$${a}$$1926__`] = false;
  3989.  
  3990. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  3991.  
  3992. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  3993.  
  3994. return;
  3995.  
  3996. }
  3997.  
  3998. }
  3999. return this.removeEventListener4882(a, b, c)
  4000. }
  4001.  
  4002.  
  4003. })();
  4004.  
  4005.  
  4006. FIX_DOM_IF_REPEAT && (() => {
  4007. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4008. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  4009. // Be careful of the mixture of polymer functions and native Element functions
  4010. // Be careful of the coding design is different with the modern Yt elements
  4011.  
  4012.  
  4013. /*
  4014.  
  4015.  
  4016. function Ks(a, b, c) {
  4017. if (kj && !BOa(a))
  4018. throw Error("strictTemplatePolicy: template owner not trusted");
  4019. c = c || {};
  4020. if (a.__templatizeOwner)
  4021. throw Error("A <template> can only be templatized once");
  4022. a.__templatizeOwner = b;
  4023. var d = (b ? b.constructor : Js)._parseTemplate(a)
  4024. , e = d.templatizeInstanceClass;
  4025. e || (e = COa(a, d, c),
  4026. d.templatizeInstanceClass = e);
  4027. var g = BOa(a);
  4028. EOa(a, d, c, g);
  4029. c = function() {
  4030. return e.apply(this, arguments) || this
  4031. }
  4032. ;
  4033. h(c, e);
  4034. c.prototype._methodHost = g;
  4035. c.prototype.__dataHost = a;
  4036. c.prototype.__templatizeOwner = b;
  4037. c.prototype.__hostProps = d.hostProps;
  4038. return c
  4039. }
  4040.  
  4041. */
  4042.  
  4043. // Polymer.enqueueDebouncer
  4044.  
  4045. const s81 = Symbol();
  4046. const s83 = Symbol();
  4047. const s84 = Symbol();
  4048. const s85 = Symbol();
  4049. const s85b = Symbol();
  4050. const s85c = Symbol();
  4051.  
  4052. let renderDebounceTs = null;
  4053.  
  4054. let renderDebouncePromise = null;
  4055. let qp;
  4056.  
  4057. const shadyFlushMO = new MutationObserver(() => {
  4058.  
  4059. if (!renderDebounceTs) return;
  4060.  
  4061. if (renderDebounceTs.size > 0) {
  4062. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  4063. try {
  4064. Polymer.flush();
  4065. return;
  4066. } catch (e) { }
  4067. }
  4068.  
  4069. renderDebouncePromise && Promise.resolve().then(() => {
  4070.  
  4071. if (renderDebouncePromise) {
  4072. renderDebouncePromise && renderDebouncePromise.resolve();
  4073. renderDebouncePromise = null;
  4074. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  4075. }
  4076.  
  4077. });
  4078.  
  4079. // Polymer.flush
  4080.  
  4081. window.ShadyDOM && ShadyDOM.flush();
  4082. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  4083.  
  4084.  
  4085. });
  4086.  
  4087. const setupPolymerAdv = () => {
  4088. // here we can obtain the Polymer faster.
  4089. // reserved for future use.
  4090. }
  4091.  
  4092.  
  4093. if (USE_fastDomIf) {
  4094. // 0 = no effect. 1 = enable. 2 = disable
  4095. // fastDomIf because it delayed the rendering process?
  4096. Object.defineProperty(Object.prototype, 'fastDomIf', {
  4097. get() {
  4098. if (this === window.Polymer) {
  4099. const v = USE_fastDomIf === 1 ? true : false;
  4100. this.fastDomIf = v;
  4101. delete Object.prototype.fastDomIf;
  4102. setupPolymerAdv(this);
  4103. return v;
  4104. }
  4105. },
  4106. set(nv) {
  4107. return false;
  4108. }
  4109. });
  4110. }
  4111.  
  4112. let setupDomIfDone = false;
  4113. const setupDomIf = (DomIf)=>{
  4114. setupDomIfDone = true;
  4115. if(setupDomIfDone) return;
  4116.  
  4117. const fProto = DomIf.prototype;
  4118.  
  4119.  
  4120. // Polymer.DomIf
  4121. // Polymer.DomIf = Polymer.fastDomIf ? ZbL : ESz
  4122. // Assume ESz by default
  4123.  
  4124. // We don't need to store "root" in DOM-IF
  4125. if (ENHANCE_DOMIF_createAndInsertInstance && fProto.__createAndInsertInstance && !fProto.__createAndInsertInstance239 && fProto.__createAndInsertInstance.length === 1) {
  4126. fProto.__createAndInsertInstance239 = fProto.__createAndInsertInstance;
  4127. fProto.__createAndInsertInstance = function (M) {
  4128. const r = this.__createAndInsertInstance239(M);
  4129. const __instance = this.__instance;
  4130. const __ctor = this.__ctor;
  4131. if (__instance && __ctor && __instance instanceof __ctor) {
  4132. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4133. const o = __instance[sym];
  4134. if (o && o.nodeType === 11) {
  4135. __instance[sym] = null;
  4136. }
  4137. }
  4138. }
  4139. return r;
  4140. }
  4141.  
  4142. /*
  4143.  
  4144.  
  4145. sX = function(M, d, N) {
  4146. if (o_ && !vDv(M))
  4147. throw Error("Jd");
  4148. N = N || {};
  4149. if (M.__templatizeOwner)
  4150. throw Error("Kd");
  4151. M.__templatizeOwner = d;
  4152. var R = (d ? d.constructor : jF)._parseTemplate(M)
  4153. , X = R.templatizeInstanceClass;
  4154. X || (X = sfi(M, R, N),
  4155. R.templatizeInstanceClass = X);
  4156. var A = vDv(M);
  4157. y9Z(M, R, N, A);
  4158. N = function() {
  4159. return X.apply(this, arguments) || this
  4160. }
  4161. ;
  4162. _.v(N, X);
  4163. N.prototype._methodHost = A;
  4164. N.prototype.__dataHost = M;
  4165. N.prototype.__templatizeOwner = d;
  4166. N.prototype.__hostProps = R.hostProps;
  4167. return N
  4168. }
  4169.  
  4170. */
  4171. }
  4172.  
  4173. // Polymer.DomIf
  4174. // We can fully teardown the entire instance (including stampFrag and stampNodes), just keep ctor stamper
  4175. if (ENHANCE_DOMIF_TEARDOWN && fProto.__teardownInstance && !fProto.__teardownInstance239 && fProto.__teardownInstance.length === 0) {
  4176. fProto.__teardownInstance239 = fProto.__teardownInstance;
  4177. fProto.__teardownInstance = function () {
  4178. const { __instance, __invalidProps } = this;
  4179. let r, e_;
  4180. try {
  4181. r = this.__teardownInstance239();
  4182. } catch (e) { e_ = e }
  4183. if (!__instance) return r;
  4184.  
  4185. try {
  4186.  
  4187. //console.log(599901,this.countEvent767());
  4188. //console.log('__teardownInstance F', __instance, __invalidProps, this._removeEventListenerFromNode, __instance._removeEventListenerFromNode);
  4189. __instance.__data = null;
  4190. __instance.__dataClientsReady = __instance.__dataEnabled = __instance.__dataReady = false;
  4191. __instance.__dataInvalid = true;
  4192. __instance.__dataHost = __instance.__dataTemp = null;
  4193. __instance.__isPropertyEffectsClient = false;
  4194. __instance.__keepInstance038__ = false;
  4195.  
  4196.  
  4197. const __templateInfo = __instance.__templateInfo;
  4198.  
  4199. let stampFragId = null;
  4200. if (__templateInfo && __templateInfo.nodeList) {
  4201. stampFragId = __templateInfo.nodeList.__belongFragId57__;
  4202. for (const weakNodeC of __templateInfo.nodeList) {
  4203. const node = toActualNode(weakNodeC);
  4204. if (node && node.nodeType >= 1) {
  4205. renderPathMake(node)
  4206. node.__keepInstance038__ = false;
  4207. node.remove();
  4208. _removedElements.addNode(node); // rn54011
  4209. }
  4210. }
  4211. __templateInfo.nodeList.length = 0;
  4212. __templateInfo.nodeList = null;
  4213. }
  4214.  
  4215. const stampFrag = stampFragId ? kRef(stampedFragment.get(stampFragId)) : null;
  4216.  
  4217. if (stampFrag && stampFrag.nodeType === 11) {
  4218. stampFrag.__keepInstance038__ = false;
  4219. _removedElements.addNode(stampFrag); // rn54012
  4220. removeAllChildNodes(stampFrag);
  4221. try {
  4222. stampFrag.remove();
  4223. } catch (e) { }
  4224. stampFrag.__shady = null;
  4225. stampFrag.$ = null;
  4226. stampFrag.__fragTeardowned57__ = true;
  4227. stampFrag.nodeList = null;
  4228. stampFrag.templateInfo = null;
  4229.  
  4230. }
  4231.  
  4232. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4233. const o = __instance[sym];
  4234. if (o && o.nodeType === 11) {
  4235. __instance[sym] = null;
  4236. }
  4237. }
  4238.  
  4239. const children = (__instance || 0).children;
  4240. if (children && children.splice) {
  4241. __instance.children = null;
  4242. for (const n of children) {
  4243. if (n && n.nodeType >= 1) {
  4244. n.__keepInstance038__ = false;
  4245. _removedElements.addNode(n); // rn54013
  4246. }
  4247. }
  4248. children.length = 0;
  4249. }
  4250.  
  4251. if (__instance.__templateInfo) __instance.__templateInfo = null;
  4252.  
  4253. if (__instance.root) __instance.root = null;
  4254.  
  4255. } catch (e) {
  4256. console.error(e);
  4257. }
  4258.  
  4259. // console.log(3882)
  4260. if (e_) throw e_;
  4261. return r;
  4262. }
  4263. }
  4264.  
  4265. }
  4266.  
  4267. if (ENHANCE_DOMIF_createAndInsertInstance || ENHANCE_DOMIF_TEARDOWN) {
  4268.  
  4269. Object.defineProperty(Object.prototype, 'DomIf', {
  4270. get() {
  4271. return undefined;
  4272. },
  4273. set(nv) {
  4274. if (typeof (nv || 0) !== 'function') return false;
  4275. delete Object.prototype.DomIf;
  4276. this.DomIf = nv;
  4277. setupDomIf(nv);
  4278. return true;
  4279. },
  4280. enumerable: false,
  4281. configurable: true
  4282. });
  4283.  
  4284. }
  4285.  
  4286. Object.defineProperty(Object.prototype, '_lastIf', {
  4287. get() {
  4288. return this[s81];
  4289. },
  4290. set(nv) {
  4291. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  4292. // DOM-IF initialization
  4293. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  4294.  
  4295. this.__xiWB8__ = 2;
  4296. // this.restamp = true;
  4297.  
  4298. const cProto = this.__proto__;
  4299. if (cProto && !cProto.__xiWB7__) {
  4300. cProto.__xiWB7__ = 1;
  4301.  
  4302. // dom-if __template
  4303. // dom-repeat template
  4304. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  4305. cProto.__template847 = true;
  4306. try {
  4307. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  4308. Object.defineProperty(cProto, '__template', {
  4309. get() {
  4310. const v = this[s84];
  4311. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  4312. },
  4313. set(nv) {
  4314. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  4315. this[s84] = nv;
  4316. return true;
  4317. }
  4318. });
  4319. } catch (e) {
  4320. console.warn(e);
  4321. }
  4322.  
  4323. console.log('FIX_DOM_IF - __template')
  4324. }
  4325.  
  4326. // dom-if __ensureTemplate
  4327. // dom-repeat __ensureTemplatized
  4328. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  4329. // note that "_templateInfo" diffs the different version of DOM-IF
  4330.  
  4331. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  4332. cProto.__ensureTemplate = function () {
  4333. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  4334. if (!this.__template) {
  4335. let b;
  4336. if (this._templateInfo) {
  4337. b = this;
  4338. } else {
  4339. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  4340. b = this.__templateCollection011__[0];
  4341. if (!b) {
  4342. if (!this[wk]) this[wk] = mWeakRef(this);
  4343. let a = this[wk];
  4344. let c = new MutationObserver(function () {
  4345. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  4346. if (c && a) {
  4347. c.disconnect();
  4348. a = kRef(a);
  4349. a && a.__render();
  4350. a && (a.__templateCollection011__ = null);
  4351. }
  4352. c = null;
  4353. a = null;
  4354. });
  4355. c && c.observe(this, {
  4356. childList: !0
  4357. });
  4358. return !1
  4359. } else {
  4360. this.__templateCollection011__ = null;
  4361. }
  4362. }
  4363. this.__template = b
  4364. }
  4365. return !0
  4366. }
  4367.  
  4368. console.log('FIX_DOM_IF - __ensureTemplate')
  4369.  
  4370. }
  4371.  
  4372.  
  4373. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  4374. }
  4375.  
  4376.  
  4377. // need to fix __observeEffects
  4378. // this.__observeEffects.if[0].info.method === this.__debounceRender
  4379. const f = () => {
  4380.  
  4381. const __observeEffects = this.__observeEffects;
  4382.  
  4383. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  4384. for (const effect of __observeEffects.if) {
  4385. const info = effect.info;
  4386. if (info && typeof info.method === 'function') {
  4387.  
  4388. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4389. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4390. }
  4391.  
  4392. }
  4393. }
  4394. }
  4395.  
  4396.  
  4397. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  4398. for (const effect of __observeEffects.restamp) {
  4399. const info = effect.info;
  4400. if (info && typeof info.method === 'function') {
  4401.  
  4402. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4403. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4404. }
  4405.  
  4406. }
  4407. }
  4408. }
  4409.  
  4410. // console.log(5881, this.__observeEffects)
  4411. }
  4412.  
  4413. }
  4414. this[s81] = nv;
  4415. return true;
  4416. }
  4417. });
  4418.  
  4419.  
  4420. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  4421. get() {
  4422. return this[s85];
  4423. },
  4424. set(nv) {
  4425. if (nv === null && this[s85] === undefined) {
  4426. // DOM-IF / DOM-REPEAT initialization
  4427.  
  4428.  
  4429. const cProto = this.__proto__;
  4430. if (qp) {
  4431. qp.obtain();
  4432. qp = null;
  4433. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  4434. }
  4435.  
  4436. }
  4437. this[s85] = nv;
  4438. return true;
  4439. }
  4440. });
  4441.  
  4442. // PS-DOM-REPEAT
  4443.  
  4444. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  4445. get() {
  4446. return this[s85b];
  4447. },
  4448. set(nv) {
  4449.  
  4450. this[s85b] = nv;
  4451. return true;
  4452. }
  4453. })
  4454.  
  4455. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  4456. get() {
  4457. return this[s85c];
  4458. },
  4459. set(nv) {
  4460.  
  4461. this[s85c] = nv;
  4462. return true;
  4463. }
  4464. })
  4465.  
  4466.  
  4467. })();
  4468.  
  4469. const setupXdeadC = (cnt)=>{
  4470.  
  4471. let xdeadc = xdeadc00;
  4472. if(!xdeadc){
  4473. setupSDomWrapper(); // just in case
  4474. const hostElement = cnt.hostElement;
  4475. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4476. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4477. hostElement.lastChild.replaceWith(el);
  4478. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4479. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4480. el.firstElementChild.id = rid;
  4481. cnt.$[rid] = el.firstElementChild;
  4482. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4483.  
  4484. xdeadc = cnt.getStampContainer_(rid);
  4485. el.remove();
  4486. xdeadc00 = xdeadc;
  4487. // console.log(xdeadc.__domApi)
  4488. // debugger;
  4489. // const xdeadv = xdeadc.__domApi;
  4490. }
  4491.  
  4492. let xlivec = xlivec00;
  4493. if(!xlivec){
  4494. setupSDomWrapper(); // just in case
  4495. const hostElement = cnt.hostElement;
  4496. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4497. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4498. hostElement.lastChild.replaceWith(el);
  4499. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4500. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4501. el.firstElementChild.id = rid;
  4502. cnt.$[rid] = el.firstElementChild;
  4503. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4504.  
  4505. xlivec = cnt.getStampContainer_(rid);
  4506. xlivec00 = xlivec;
  4507. // console.log(xdeadc.__domApi)
  4508. // debugger;
  4509. // const xdeadv = xdeadc.__domApi;
  4510. }
  4511.  
  4512. return xdeadc00;
  4513. }
  4514.  
  4515. let standardWrap_ = null;
  4516.  
  4517. const setupSDomWrapper = () => {
  4518.  
  4519. const sdwProto = ShadyDOM.Wrapper.prototype;
  4520.  
  4521. if (sdwProto.__pseudo__isConnected__ !== null) {
  4522. sdwProto.__pseudo__isConnected__ = null;
  4523. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  4524. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  4525. const get = isConnectedPd.get;
  4526. isConnectedPd.get = function () {
  4527. const pseudoVal = this.__pseudo__isConnected__;
  4528. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  4529. }
  4530. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  4531. }
  4532.  
  4533. // debugger;
  4534. // new xdeadc.__domApi.constructor(document.createElement('div'));
  4535. }
  4536.  
  4537. }
  4538.  
  4539. let domApiConstructor = null;
  4540. const setupDomApi = (daProto) => {
  4541.  
  4542. daProto.__daHook377__ = true;
  4543.  
  4544. domApiConstructor = daProto.constructor; // TBC
  4545.  
  4546. // TBC
  4547.  
  4548. }
  4549.  
  4550.  
  4551. // WEAKREF_ShadyDOM
  4552.  
  4553. let mightTeardownShadyDomWrap = () => { };
  4554.  
  4555. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  4556.  
  4557. const setupPlainShadyDOM = (b) => {
  4558. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  4559. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  4560. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  4561. b.patchOnDemand = true;
  4562. b.preferPerformance = true;
  4563. b.noPatch = true;
  4564. }
  4565.  
  4566. const isPlainObject = (b, m) => {
  4567. if (!b || typeof b !== 'object') return false;
  4568. const e = Object.getOwnPropertyDescriptors(b);
  4569. if (e.length <= m) return false;
  4570. let pr = 0;
  4571. for (const k in e) {
  4572. const d = e[k];
  4573. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  4574. if (!('value' in d) || typeof d.value === 'function') return false;
  4575. pr++;
  4576. }
  4577. return pr > m;
  4578. }
  4579.  
  4580. let b;
  4581.  
  4582. let lz = 0;
  4583.  
  4584. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  4585. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  4586.  
  4587. // Brave - ShadyDOM exists before userscripting
  4588. b = sdp.value;
  4589.  
  4590. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  4591. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  4592. lz = 1;
  4593. }
  4594.  
  4595. }
  4596.  
  4597.  
  4598. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  4599. } else if (!sdp) {
  4600. } else {
  4601. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  4602. return;
  4603. }
  4604.  
  4605. const shadyDOMNodeWRM = new WeakMap();
  4606.  
  4607. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  4608.  
  4609. const weakWrapperNodeHandlerFn = () => ({
  4610. get() {
  4611. const wv = this[wk];
  4612. if (typeof wv === 'undefined') return undefined;
  4613. let node = kRef(wv);
  4614. if (!node) this[wk] = undefined;
  4615. return node || undefined;
  4616. },
  4617. set(nv) {
  4618. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  4619. this[wk] = wv;
  4620. return true;
  4621. },
  4622. enumerable: true,
  4623. configurable: true
  4624. });
  4625.  
  4626.  
  4627. function weakWrapper(_ShadyDOM) {
  4628. const ShadyDOM = _ShadyDOM;
  4629. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  4630. let nullElement = { node: null };
  4631. Object.setPrototypeOf(nullElement, Element.prototype);
  4632. let p = new ShadyDOM.Wrapper(nullElement);
  4633. let d = Object.getOwnPropertyDescriptor(p, 'node');
  4634. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  4635. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  4636. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  4637. }
  4638.  
  4639. }
  4640. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  4641. try {
  4642. setupSDomWrapper();
  4643. } catch (e) { }
  4644. }
  4645.  
  4646. }
  4647.  
  4648. let previousWrapStore = null;
  4649.  
  4650. mightTeardownShadyDomWrap = (node) => {
  4651. if (previousWrapStore) previousWrapStore.delete(node);
  4652. if (shadyDOMNodeWRM) shadyDOMNodeWRM.delete(node);
  4653. };
  4654.  
  4655. const standardWrap = function (a) {
  4656. if (a instanceof WeakNodeC) a = a.getNode592177();
  4657. // if(a && a.deref) a= a.deref();
  4658. if(!a) return a;
  4659. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  4660. if (previousWrapStore) {
  4661. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  4662. if (s) {
  4663. previousWrapStore.delete(a);
  4664. shadyDOMNodeWRM.set(a, mWeakRef(s));
  4665. }
  4666. }
  4667. let u = kRef(shadyDOMNodeWRM.get(a));
  4668. if (!u) {
  4669. u = new ShadyDOM.Wrapper(a);
  4670. shadyDOMNodeWRM.set(a, mWeakRef(u));
  4671. }
  4672. return u;
  4673. }
  4674.  
  4675. standardWrap_ = standardWrap;
  4676.  
  4677.  
  4678. function setupWrapFunc(_ShadyDOM) {
  4679. const ShadyDOM = _ShadyDOM;
  4680.  
  4681.  
  4682. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  4683. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  4684. return;
  4685. }
  4686. let mm = new Set();
  4687. const pget = wmPD.value;
  4688. WeakMap.prototype.get = function (a) {
  4689. mm.add(this);
  4690. return a;
  4691. }
  4692. try {
  4693. let nullElement = { node: null };
  4694. Object.setPrototypeOf(nullElement, Element.prototype);
  4695. ShadyDOM.wrapIfNeeded(nullElement)
  4696. ShadyDOM.wrap(nullElement)
  4697. } catch (e) { }
  4698. WeakMap.prototype.get = pget;
  4699. if (mm.size !== 1) {
  4700. mm.clear();
  4701. return;
  4702. }
  4703. const p = mm.values().next().value;
  4704. if (!(p instanceof WeakMap)) return;
  4705. // p.clear();
  4706. // p.get = function (a) { return a }
  4707. // p.set = function (a, b) { return this }
  4708. // console.log(188, window.n2n = mm, window.n2p = p)
  4709.  
  4710. // console.log(34929,p.size)
  4711. previousWrapStore = p;
  4712.  
  4713. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  4714. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  4715. }
  4716. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  4717. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  4718. }
  4719.  
  4720. }
  4721.  
  4722. function setupLZ3(nv) {
  4723.  
  4724. const ShadyDOM = nv;
  4725.  
  4726. const ShadyDOMSettings = ShadyDOM.settings;
  4727. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4728. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4729. return false;
  4730. }
  4731.  
  4732. weakWrapper(ShadyDOM);
  4733.  
  4734. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4735.  
  4736. setupPlainShadyDOM(ShadyDOMSettings);
  4737. setupPlainShadyDOM(ShadyDOM);
  4738.  
  4739. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  4740.  
  4741. setupWrapFunc(ShadyDOM);
  4742. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  4743. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  4744.  
  4745. // To be confirmed
  4746. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  4747. ShadyDOM.composedPath = function (e) {
  4748. const t = (e || 0).target || null;
  4749. if (!(t instanceof HTMLElement_)) {
  4750. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  4751. }
  4752. return t instanceof HTMLElement_ ? [t] : [];
  4753. };
  4754. }
  4755.  
  4756. }
  4757.  
  4758. }
  4759.  
  4760.  
  4761. function setupLZ6(nv) {
  4762.  
  4763. const ShadyDOM = nv;
  4764.  
  4765. const ShadyDOMSettings = ShadyDOM.settings;
  4766.  
  4767. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4768. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4769. return false;
  4770. }
  4771.  
  4772. weakWrapper(ShadyDOM);
  4773.  
  4774. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4775.  
  4776. setupPlainShadyDOM(ShadyDOMSettings);
  4777. setupPlainShadyDOM(ShadyDOM);
  4778.  
  4779. setupWrapFunc(ShadyDOM);
  4780.  
  4781. }
  4782.  
  4783. }
  4784.  
  4785. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  4786.  
  4787. const nv = b;
  4788.  
  4789. if (setupLZ6(nv) === false) return;
  4790.  
  4791. lz = 6;
  4792.  
  4793. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  4794.  
  4795. return;
  4796. }
  4797.  
  4798. delete window.ShadyDOM;
  4799.  
  4800. Object.defineProperty(window, 'ShadyDOM', {
  4801. get() {
  4802. return b;
  4803. },
  4804. set(nv) {
  4805. let ret = 0;
  4806. try {
  4807. do {
  4808. if (!nv || !nv.settings) {
  4809. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  4810. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  4811. lz = 1;
  4812. break;
  4813. } else {
  4814. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  4815. break;
  4816. }
  4817. }
  4818.  
  4819. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  4820. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  4821. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  4822. break;
  4823. }
  4824.  
  4825. if (setupLZ3(nv) === false) break;
  4826.  
  4827. lz = 3;
  4828.  
  4829. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  4830.  
  4831. ret = 1;
  4832.  
  4833. } while (0);
  4834. } catch (e) {
  4835. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  4836. }
  4837.  
  4838. if (!ret) b = nv;
  4839. else {
  4840. delete this.ShadyDOM;
  4841. this.ShadyDOM = nv;
  4842. }
  4843. return true;
  4844. },
  4845. enumerable: false,
  4846. configurable: true
  4847. });
  4848.  
  4849. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  4850.  
  4851. if (ENABLE_ASYNC_DISPATCHEVENT) {
  4852. const filter = new Set([
  4853. 'yt-action',
  4854. // 'iframe-src-replaced',
  4855. 'shown-items-changed',
  4856. 'can-show-more-changed', 'collapsed-changed',
  4857.  
  4858. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  4859. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  4860. 'yt-navigate-finish',
  4861.  
  4862. // 'data-changed','yt-watch-comments-ready'
  4863. ])
  4864. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  4865. EventTarget.prototype.dispatchEvent = function (event) {
  4866. const type = (event || 0).type;
  4867. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  4868. if (!filter.has(type) && !type.endsWith('-changed')) {
  4869. if (this instanceof Node || this instanceof Window) {
  4870. nextBrowserTick_(() => this.dispatchEvent938(event));
  4871. return true;
  4872. }
  4873. }
  4874. }
  4875. return this.dispatchEvent938(event);
  4876. }
  4877. }
  4878.  
  4879. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  4880. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  4881. // const xhr = new XMLHttpRequest;
  4882. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  4883. if (!pdOri || pdOri.configurable !== true) return;
  4884. let propNeedles = null;
  4885. const pdNew = {
  4886. configurable: true,
  4887. enumerable: true,
  4888. get: function () {
  4889. propNeedles = this;
  4890. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  4891. throw new Error();
  4892. }
  4893. }
  4894. Object.defineProperty(Map.prototype, 'size', pdNew);
  4895. try {
  4896. XMLHttpRequest.prototype.open.call(0);
  4897. // xhr.open.call(null)
  4898. } catch (e) { }
  4899. Object.defineProperty(Map.prototype, 'size', pdOri);
  4900. if (!propNeedles) return;
  4901. const entries = [...propNeedles.entries()];
  4902. propNeedles.clear();
  4903. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  4904. })();
  4905.  
  4906. if (FIX_XHR_REQUESTING) {
  4907.  
  4908. const URL = window.URL || new Function('return URL')();
  4909. const createObjectURL = URL.createObjectURL.bind(URL);
  4910.  
  4911. XMLHttpRequest = (() => {
  4912. const XMLHttpRequest_ = XMLHttpRequest;
  4913. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  4914. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  4915. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  4916. constructor(...args) {
  4917. super(...args);
  4918. }
  4919. open(method, url, ...args) {
  4920. let skip = false;
  4921. if (!url || typeof url !== 'string') skip = true;
  4922. else if (typeof url === 'string') {
  4923. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  4924. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  4925. skip = true;
  4926. } else if (turl.includes('.youtube.com/pagead/')) {
  4927. skip = true;
  4928. } else if (turl.includes('.youtube.com/ptracking')) {
  4929. skip = true;
  4930. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  4931. skip = true;
  4932. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  4933. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  4934. skip = true;
  4935. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  4936. skip = true;
  4937. } else {
  4938. // skip = true; // for user activity logging e.g. watched videos
  4939. }
  4940. } else if (turl.includes('play.google.com/log')) {
  4941. skip = true;
  4942. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  4943. skip = true;
  4944. }
  4945. }
  4946. if (!skip) {
  4947. this.__xmMc8__ = 1;
  4948. return super.open(method, url, ...args);
  4949. } else {
  4950. this.__xmMc8__ = 2;
  4951. return super.open('GET', url0);
  4952. }
  4953. }
  4954. send(...args) {
  4955. if (this.__xmMc8__ === 1) {
  4956. return super.send(...args);
  4957. } else if (this.__xmMc8__ === 2) {
  4958. return super.send();
  4959. } else {
  4960. console.log('[yt-js-engine-tamer]', 'xhr warning');
  4961. return super.send(...args);
  4962. }
  4963. }
  4964. }
  4965. c.prototype.__xmMc8__ = 0;
  4966. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  4967. return c;
  4968. })();
  4969. }
  4970.  
  4971. // Alternative HACK -> Tabview Youtube
  4972. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  4973.  
  4974. // ---- << this.overscrollConfig HACK >> -----
  4975.  
  4976. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  4977.  
  4978. /*
  4979.  
  4980. ;function gZb(a, b) {
  4981. b = void 0 === b ? !0 : b;
  4982. a.addEventListener("wheel", hZb);
  4983. a.overscrollConfig = {
  4984. cooldown: b
  4985. }
  4986. }
  4987. function iZb(a) {
  4988. a.overscrollConfig = void 0;
  4989. a.removeEventListener("wheel", hZb)
  4990. }
  4991. function hZb(a) {
  4992. var b = a.deltaY
  4993. , c = a.target
  4994. , d = null;
  4995. if (window.Polymer && window.Polymer.Element) {
  4996. if (c = a.path || a.composedPath && a.composedPath()) {
  4997. c = g(c);
  4998. for (var e = c.next(); !e.done && (e = e.value,
  4999. !jZb(e, b)); e = c.next())
  5000. if (e.overscrollConfig) {
  5001. d = e;
  5002. break
  5003. }
  5004. }
  5005. } else
  5006. for (; c && !jZb(c, b); ) {
  5007. if (c.overscrollConfig) {
  5008. d = c;
  5009. break
  5010. }
  5011. c = c.parentElement
  5012. }
  5013. d && (b = d.overscrollConfig,
  5014. b.cooldown ? (d = a.deltaY,
  5015. c = b.lastDeltaY || 0,
  5016. b.lastDeltaY = d,
  5017. e = b.lastStopped || 0,
  5018. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  5019. c = !1) : (d = e + 600,
  5020. c = !0) : (d = Date.now() + 600,
  5021. c = !0),
  5022. d > Date.now() && (a.preventDefault(),
  5023. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  5024. }
  5025. */
  5026.  
  5027. let wheelHandler = function (a) {
  5028. if (window.Polymer && window.Polymer.Element) {
  5029. let c;
  5030. if (c = a.path || a.composedPath && a.composedPath()) {
  5031. for (const e of c) {
  5032. const cnt = insp(e);
  5033. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5034. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5035. }
  5036. }
  5037. } else {
  5038. let e = a.target;
  5039. for (; e instanceof Element; e = e.parentElement) {
  5040. const cnt = insp(e);
  5041. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5042. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5043. }
  5044. }
  5045. };
  5046.  
  5047. let checkWheelListenerObjs = null;
  5048.  
  5049. let getObjsFn = () => {
  5050. let euyVal = 0;
  5051. const eukElm = {};
  5052. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  5053. const euzObj = new Proxy(eukElm, {
  5054. get(target, prop) {
  5055. throw `ErrorF31.get(${prop})`
  5056. },
  5057. set(target, prop, value) {
  5058. throw `ErrorF33.set(${prop}, ${value})`
  5059. }
  5060. });
  5061. const euxElm = new Proxy(eukElm, {
  5062. get(target, prop) {
  5063. if (prop === 'scrollTop') {
  5064. euyVal = euyVal | 8;
  5065. return 0;
  5066. }
  5067. if (prop === 'overscrollConfig') {
  5068. euyVal = euyVal | 16;
  5069. return void 0;
  5070. }
  5071. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  5072. return 640;
  5073. }
  5074. if (prop === 'scrollLeft') {
  5075. euyVal = euyVal | 8;
  5076. return 0;
  5077. }
  5078. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  5079. return 800;
  5080. }
  5081. throw `ErrorF45.get(${prop})`
  5082. },
  5083. set(target, prop, value) {
  5084. throw `ErrorF47.set(${prop}, ${value})`
  5085. }
  5086. });
  5087. const eukEvt = {};
  5088. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  5089. const euyEvt = new Proxy(eukEvt, {
  5090. get(target, prop) {
  5091. if (prop === 'deltaY' || prop === 'deltaX') {
  5092. euyVal = euyVal | 1;
  5093. return -999;
  5094. }
  5095. if (prop === 'target') {
  5096. euyVal = euyVal | 2;
  5097. return euxElm
  5098. }
  5099. if (prop === 'path' || prop === 'composedPath') {
  5100. euyVal = euyVal | 2;
  5101. return [euxElm]
  5102. }
  5103. throw `ErrorF51.get(${prop})`
  5104. },
  5105. set(target, prop, value) {
  5106. throw `ErrorF53.set(${prop}, ${value})`
  5107. }
  5108. });
  5109. const setVal = (v) => {
  5110. euyVal = v;
  5111. }
  5112. const getVal = () => {
  5113. return euyVal;
  5114. }
  5115. return { euzObj, euyEvt, setVal, getVal };
  5116. }
  5117.  
  5118. let checkWheelListener = (callback) => {
  5119.  
  5120. let callbackIdentifier = '';
  5121.  
  5122. let res = null;
  5123. try {
  5124. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  5125. setVal(0);
  5126. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  5127. throw `RESULT${getVal()}`;
  5128. } catch (e) {
  5129. res = e;
  5130. }
  5131.  
  5132. res = `${res}` || `${null}`;
  5133. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  5134.  
  5135. callbackIdentifier = res;
  5136. if (callbackIdentifier === 'RESULT27') 0;
  5137. else if (callbackIdentifier === 'RESULT0') {
  5138. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  5139. } else if (callbackIdentifier.startsWith('RESULT')) {
  5140. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  5141. }
  5142. return callbackIdentifier;
  5143.  
  5144. };
  5145.  
  5146. let callbackFound = false;
  5147. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  5148. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  5149. // M-youtube-js-engine-tamer.52178
  5150. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  5151. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  5152. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  5153. // RESULTXX / ErrorFXX / Other...
  5154. if (callbackIdentifier === 'RESULT27') {
  5155. this.overscrollConfigDisable = true;
  5156. if (!callbackFound) {
  5157. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  5158. getObjsFn = checkWheelListener = null;
  5159. checkWheelListenerObjs = null;
  5160. wheelHandler = null;
  5161. }
  5162. return void 0;
  5163. } else if (!callbackFound && !this.overscrollConfigDisable) {
  5164. this.overscrollConfigDisable = true;
  5165. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  5166. }
  5167. }
  5168. return this.addEventListener52178(type, callback, option);
  5169. };
  5170.  
  5171. // ---- << this.overscrollConfig HACK >> -----
  5172.  
  5173. }
  5174.  
  5175. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  5176.  
  5177. let p_a_objWR = null;
  5178. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  5179. let ytPageReady = 0;
  5180.  
  5181. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5182. let isGlobalSpaceControl = true;
  5183. let mediaPlayerElementWR = null;
  5184. let focusedElementAtSelection = null;
  5185.  
  5186. // let want_control_video = false;
  5187.  
  5188. let spaceBarControl_keyG = '';
  5189.  
  5190. let lastUserAction = 0;
  5191.  
  5192. const wmKeyControlPhase = new WeakMap();
  5193.  
  5194. let currentSelectionText = null;
  5195.  
  5196. const getCurrentSelectionText = () => {
  5197. if (currentSelectionText !== null) return currentSelectionText
  5198. return (currentSelectionText = `${getSelection()}`)
  5199. }
  5200.  
  5201. const pageMediaWatcher = () => {
  5202.  
  5203. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  5204. // want_control_video = false;
  5205. // }, { capture: true, passive: true });
  5206.  
  5207. document.addEventListener('yt-navigate', () => {
  5208. ytPageReady = 0;
  5209. });
  5210. document.addEventListener('yt-navigate-start', () => {
  5211. ytPageReady = 0;
  5212. });
  5213. document.addEventListener('yt-navigate-cache', () => {
  5214. ytPageReady = 0;
  5215. });
  5216.  
  5217. document.addEventListener('yt-navigate-finish', () => {
  5218. ytPageReady = 1;
  5219. });
  5220.  
  5221. document.addEventListener('durationchange', () => {
  5222. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  5223. if (elm.duration > 0.01) {
  5224. if (elm.closest('[hidden]')) continue;
  5225. mediaPlayerElementWR = mWeakRef(elm);
  5226. return;
  5227. }
  5228. }
  5229. }, { capture: true, passive: true });
  5230.  
  5231. document.addEventListener('selectionchange', (evt) => {
  5232. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  5233. currentSelectionText = null;
  5234. if (!(evt.target instanceof Node)) return;
  5235. focusedElementAtSelection = evt.target;
  5236. }, { capture: true, passive: true })
  5237.  
  5238. document.addEventListener('pointerdown', (evt) => {
  5239. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5240. }, { capture: true, passive: true });
  5241.  
  5242.  
  5243. document.addEventListener('pointerup', (evt) => {
  5244. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5245. }, { capture: true, passive: true });
  5246.  
  5247.  
  5248. document.addEventListener('keydown', (evt) => {
  5249. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5250. }, { capture: true, passive: true });
  5251.  
  5252. document.addEventListener('keyup', (evt) => {
  5253. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5254. }, { capture: true, passive: true });
  5255.  
  5256. };
  5257.  
  5258.  
  5259. const checkKeyB = (p_a_obj) => {
  5260.  
  5261. const boolList = new Set();
  5262. const p_a_obj_api = p_a_obj.api;
  5263.  
  5264. const nilFunc0 = function () {
  5265. return void 0
  5266. };
  5267. const mt = new Proxy({}, {
  5268. get(target, prop) {
  5269. if (prop === 'get') return nilFunc0;
  5270. return mt;
  5271. }
  5272. });
  5273. const nilFunc = function () {
  5274. return mt
  5275. };
  5276. const mw = new Proxy({}, {
  5277. get(target, prop) {
  5278. if (prop in p_a_obj_api) {
  5279. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  5280. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  5281. if (q && q.value) {
  5282. if (!q.writable) return q.value;
  5283. if (typeof q.value === 'string') return '';
  5284. if (typeof q.value === 'number') return 0;
  5285. if (typeof q.value === 'boolean') return false;
  5286. if (q.value && typeof q.value === 'object') return {};
  5287. }
  5288. }
  5289. return undefined;
  5290. },
  5291. set(target, prop) {
  5292. throw 'mwSet';
  5293. }
  5294. });
  5295.  
  5296. const mq = new Proxy({}, {
  5297. get(target, prop) {
  5298. if (prop === 'api') return mw;
  5299. if (prop in p_a_obj) {
  5300. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  5301. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  5302. if (q && q.value) {
  5303. if (!q.writable) return q.value;
  5304. if (typeof q.value === 'string') return '';
  5305. if (typeof q.value === 'number') return 0;
  5306. if (typeof q.value === 'boolean') return false;
  5307. if (q.value && typeof q.value === 'object') return {};
  5308. }
  5309. }
  5310. return undefined;
  5311. },
  5312. set(target, prop, val) {
  5313. if (typeof val === 'boolean') boolList.add(prop)
  5314. throw `mqSet(${prop},${val})`;
  5315. }
  5316. });
  5317.  
  5318. let res = ''
  5319. try {
  5320. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  5321. } catch (e) {
  5322. res = `ERROR::${e}`;
  5323. }
  5324.  
  5325. if (boolList.size === 1) {
  5326. const value = boolList.values().next().value;
  5327. if (res === `ERROR::mqSet(${value},${true})`) {
  5328. p_a_obj.__uZWaD__ = value;
  5329. }
  5330. }
  5331.  
  5332. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  5333.  
  5334. }
  5335.  
  5336.  
  5337. let pm_p_a = null;
  5338.  
  5339. const p_a_init = function () {
  5340. const r = this.init91();
  5341. const keyBw = this.__cPzfo__ || '__NIL__';
  5342. const p_a_obj = this[keyBw];
  5343. if (!p_a_obj) return;
  5344. try {
  5345. checkKeyB(p_a_obj);
  5346. } catch (e) { }
  5347. p_a_objWR = mWeakRef(p_a_obj);
  5348. if (FIX_SHORTCUTKEYS > 0) {
  5349. if (p_a_obj && !p_a_obj.hVhtg) {
  5350. p_a_obj.hVhtg = 1;
  5351.  
  5352. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  5353. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  5354. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  5355. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  5356. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  5357. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  5358.  
  5359. }
  5360. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  5361. // const api = p_a_obj.api
  5362. // api.hVhtg = 1;
  5363. // api.playVideo91 = api.playVideo;
  5364. // api.playVideo = p_a_jt.playVideo;
  5365. // api.pauseVideo91 = api.pauseVideo;
  5366. // api.pauseVideo = p_a_jt.pauseVideo;
  5367. // }
  5368. }
  5369. if (pm_p_a) {
  5370. pm_p_a.resolve();
  5371. pm_p_a = null;
  5372. }
  5373. return r;
  5374. };
  5375.  
  5376. const p_a_xt = {
  5377.  
  5378. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  5379.  
  5380. if (FIX_SHORTCUTKEYS === 2) {
  5381.  
  5382. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  5383.  
  5384. if (activeElement) {
  5385.  
  5386. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  5387.  
  5388. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  5389. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  5390. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  5391.  
  5392. }
  5393.  
  5394. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5395. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5396. // console.log(582, isDelayedSpaceBar)
  5397. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5398.  
  5399. if (activeElement && (h === 'Space' || h === 'Enter')) {
  5400. const controlPhase = wmKeyControlPhase.get(activeElement);
  5401. if (controlPhase === 4 || controlPhase === 5) return false;
  5402. }
  5403. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  5404. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  5405. // if (!isSpaceKeyImmediate) return false;
  5406. // }
  5407. }
  5408.  
  5409. },
  5410.  
  5411. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  5412.  
  5413. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  5414.  
  5415. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5416. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5417. // console.log(583, isDelayedSpaceBar)
  5418. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5419.  
  5420. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5421.  
  5422. let mediaWorking = false;
  5423. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  5424. mediaWorking = true;
  5425. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5426. mediaWorking = true;
  5427. }
  5428. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  5429. mediaWorking && Promise.resolve().then(() => {
  5430. if (activeElement === document.activeElement) {
  5431. return activeElement.blur()
  5432. } else {
  5433. return false
  5434. }
  5435. }).then((r) => {
  5436. r !== false && mediaPlayerElement.focus();
  5437. });
  5438. }
  5439. },
  5440.  
  5441.  
  5442. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  5443.  
  5444. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5445.  
  5446. const activeElement = document.activeElement;
  5447.  
  5448. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5449. if (allow === false) return false;
  5450.  
  5451. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5452. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  5453.  
  5454. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5455.  
  5456. return ret;
  5457. },
  5458. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  5459.  
  5460.  
  5461. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5462.  
  5463. const activeElement = document.activeElement;
  5464. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5465. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5466. // }
  5467. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5468. if (allow === false) return false;
  5469.  
  5470. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5471. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  5472.  
  5473. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5474.  
  5475. return ret;
  5476. }
  5477.  
  5478. };
  5479.  
  5480. let flagSpeedMaster = null;
  5481. const getSpeedMasterControlFlag = () => {
  5482.  
  5483. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5484. isSpeedMastSpacebarControlEnabled = false;
  5485. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  5486. isSpeedMastSpacebarControlEnabled = true;
  5487. }
  5488. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  5489. isSpeedMastSpacebarControlEnabled = true;
  5490. }
  5491.  
  5492. if (flagSpeedMaster === null) {
  5493. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  5494. if (!p) {
  5495. flagSpeedMaster = false;
  5496. } else {
  5497.  
  5498. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  5499.  
  5500. }
  5501.  
  5502. }
  5503. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  5504.  
  5505. return isSpeedMastSpacebarControlEnabled;
  5506. }
  5507.  
  5508.  
  5509. const getGlobalSpacebarControlFlag = () => {
  5510.  
  5511. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5512. isGlobalSpaceControl = false;
  5513. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  5514. isGlobalSpaceControl = true;
  5515. }
  5516. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  5517. isGlobalSpaceControl = true;
  5518. }
  5519.  
  5520. return isGlobalSpaceControl;
  5521. }
  5522.  
  5523. const keyboardController = async (_yt_player) => {
  5524.  
  5525. const keyQT = getQT(_yt_player);
  5526. const keySV = getSV(_yt_player);
  5527. const keyDX = getDX(_yt_player);
  5528. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  5529.  
  5530. if (!keyDX) return;
  5531. if (keyDX === keyQT || keyDX === keySV) return;
  5532.  
  5533. if (typeof keyDX !== 'string') return;
  5534.  
  5535. let lastAccessKey = '';
  5536. let lastAccessKeyConfirmed = '';
  5537. const mb = new Proxy({}, {
  5538. get(target, prop) {
  5539. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  5540. throw 'mbGet'
  5541. },
  5542. set(target, prop, val) {
  5543. throw 'mbSet'
  5544. }
  5545. });
  5546. const ma = new Proxy({}, {
  5547. get(target, prop) {
  5548. lastAccessKey = prop;
  5549. return mb
  5550. },
  5551. set(target, prop, val) {
  5552. throw 'maSet'
  5553. }
  5554. });
  5555.  
  5556. let keyBw = '';
  5557. try {
  5558. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  5559. } catch (e) {
  5560. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  5561. keyBw = lastAccessKeyConfirmed;
  5562. }
  5563. }
  5564.  
  5565. if (!keyBw) return;
  5566.  
  5567. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  5568.  
  5569. pm_p_a = new PromiseExternal();
  5570.  
  5571. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  5572.  
  5573. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  5574.  
  5575. _yt_player[keyDX].prototype.init = p_a_init;
  5576.  
  5577. await pm_p_a.then();
  5578. const p_a_obj = kRef(p_a_objWR);
  5579.  
  5580. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  5581.  
  5582.  
  5583. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  5584.  
  5585. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  5586.  
  5587. if (!isSpeedMastSpacebarControlEnabled) {
  5588.  
  5589. if (config && config.EXPERIMENT_FLAGS) {
  5590. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  5591. }
  5592. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5593. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  5594. }
  5595.  
  5596. } else {
  5597.  
  5598. if (config && config.EXPERIMENT_FLAGS) {
  5599. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  5600. }
  5601. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5602. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  5603. }
  5604.  
  5605. }
  5606.  
  5607. }
  5608.  
  5609. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  5610.  
  5611.  
  5612.  
  5613.  
  5614. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  5615.  
  5616. // console.log(p_a_obj.handleGlobalKeyUp)
  5617. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  5618.  
  5619. // console.log(p_a_obj.api)
  5620.  
  5621.  
  5622. // QT -> DX(SV) -> p_a
  5623.  
  5624.  
  5625. /*
  5626. *
  5627. *
  5628. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5629. b = void 0 === b ? !1 : b;
  5630. c = void 0 === c ? !1 : c;
  5631. d = void 0 === d ? !1 : d;
  5632. e = void 0 === e ? !1 : e;
  5633. var l = g.PT(this);
  5634. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  5635. }
  5636.  
  5637. */
  5638.  
  5639. /*
  5640. *
  5641. *
  5642. *
  5643. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5644. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  5645. }
  5646.  
  5647. */
  5648.  
  5649.  
  5650. // if(!keyDX) return;
  5651.  
  5652. // console.log(4999, keyDX)
  5653.  
  5654. };
  5655.  
  5656.  
  5657. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  5658.  
  5659. const p_a_obj = kRef(p_a_objWR);
  5660. // const api = p_a_obj.api;
  5661.  
  5662.  
  5663. // console.log(540);
  5664.  
  5665. let boolList = null;
  5666. let ret;
  5667. isSpaceKeyImmediate = true;
  5668. try {
  5669.  
  5670. ret = 0;
  5671. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  5672. let p_a_objT;
  5673. if (!spaceBarControl_keyG) { // just in case
  5674. boolList = new Set();
  5675. p_a_objT = new Proxy(p_a_obj, {
  5676. get(target, prop, handler) {
  5677. const val = target[prop];
  5678. if (typeof val !== 'boolean') return val;
  5679. boolList.add(prop);
  5680. // console.log(555, prop, val);
  5681. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  5682. spaceBarControl_keyG = prop;
  5683. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5684. val = false;
  5685. }
  5686. return val;
  5687. }
  5688. });
  5689.  
  5690.  
  5691. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  5692. p_a_obj[spaceBarControl_keyG] = false;
  5693. p_a_objT = p_a_obj;
  5694. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  5695. } else {
  5696.  
  5697. p_a_objT = p_a_obj;
  5698. }
  5699.  
  5700. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  5701.  
  5702.  
  5703. } catch (e) {
  5704. console.log(e)
  5705. }
  5706. isSpaceKeyImmediate = false;
  5707.  
  5708. if (boolList && boolList.size === 1) {
  5709. const value = boolList.values().next().value;
  5710. spaceBarControl_keyG = value;
  5711. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5712.  
  5713. }
  5714.  
  5715. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5716.  
  5717. return ret;
  5718. }
  5719.  
  5720. const shortcutKeysFixer = () => {
  5721.  
  5722. let pausePromiseControlJ = 0;
  5723.  
  5724.  
  5725. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  5726.  
  5727. let controlPhase = 0;
  5728. const aElm = document.activeElement;
  5729.  
  5730. if (aElm) {
  5731.  
  5732. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  5733.  
  5734. if (typeof controlPhaseCache === 'number') {
  5735.  
  5736. controlPhase = controlPhaseCache;
  5737. } else {
  5738.  
  5739. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  5740. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  5741. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  5742. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  5743. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  5744. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  5745. else {
  5746. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  5747. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  5748. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  5749. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  5750. }
  5751.  
  5752. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  5753. controlPhase = 0;
  5754. }
  5755.  
  5756. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  5757. if (aElm.closest('[contenteditable], input, textarea')) {
  5758. controlPhase = 5;
  5759. } else if (aElm.closest('button')) {
  5760. controlPhase = 4;
  5761. }
  5762. }
  5763.  
  5764. if (aElm.closest('#movie_player')) controlPhase = 6;
  5765.  
  5766. wmKeyControlPhase.set(aElm, controlPhase);
  5767.  
  5768. }
  5769. }
  5770.  
  5771. return controlPhase;
  5772.  
  5773. }
  5774.  
  5775. const isStateControllable = (api) => {
  5776. let appState = null;
  5777. let playerState = null;
  5778. let adState = null;
  5779. try {
  5780. appState = api.getAppState();
  5781. playerState = api.getPlayerState();
  5782. adState = api.getAdState();
  5783. } catch (e) { }
  5784. // ignore playerState -1
  5785. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  5786. };
  5787.  
  5788.  
  5789. const keyEventListener = (evt) => {
  5790. if (BY_PASS_KEYBOARD_CONTROL) return;
  5791.  
  5792. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5793. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  5794. if (!ytPageReady) return;
  5795.  
  5796. if (evt.defaultPrevented === true) return;
  5797.  
  5798. const p_a_obj = kRef(p_a_objWR);
  5799.  
  5800. if (!p_a_obj) return;
  5801.  
  5802.  
  5803. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5804. if (!mediaPlayerElement) return;
  5805.  
  5806. // let focusBodyIfSuccess = false;
  5807.  
  5808. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  5809.  
  5810. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  5811. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  5812. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  5813.  
  5814.  
  5815. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  5816.  
  5817. // console.log(`${evt.type}::controlPhase`,controlPhase)
  5818.  
  5819. // if (controlPhase == 4) {
  5820. // focusBodyIfSuccess = true;
  5821. // }
  5822.  
  5823. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  5824. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5825.  
  5826. if (FIX_SHORTCUTKEYS < 2) return;
  5827. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  5828.  
  5829. let rr;
  5830. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  5831.  
  5832.  
  5833.  
  5834. let useImprovedPauseResume = false;
  5835.  
  5836. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5837.  
  5838. const api = p_a_obj.api;
  5839. const stateControllable = isStateControllable(api);
  5840. // console.log(2122, appState, playerState, adState)
  5841.  
  5842. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  5843.  
  5844. useImprovedPauseResume = true;
  5845.  
  5846. }
  5847.  
  5848.  
  5849. }
  5850.  
  5851.  
  5852. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5853. if (evt.type === 'keydown') {
  5854.  
  5855. if (useImprovedPauseResume) {
  5856.  
  5857. const isPaused = mediaPlayerElement.paused;
  5858.  
  5859. const cj = ++pausePromiseControlJ;
  5860. Promise.resolve().then(() => {
  5861.  
  5862. if (cj !== pausePromiseControlJ) return;
  5863.  
  5864. if (mediaPlayerElement.paused !== isPaused) return;
  5865.  
  5866. const ret = ytResumeFn();
  5867. if (!ret) { // fallback
  5868. isPaused ? api.playVideo() : api.pauseVideo();
  5869. }
  5870.  
  5871. /*
  5872. let a = void 0;
  5873. console.log('Rb', api.Rb())
  5874. a = !window._yt_player.nL(api.Rb());
  5875. p_a_obj.Wd.kG(a)
  5876. a ? api.playVideo() : api.pauseVideo();
  5877.  
  5878. */
  5879.  
  5880.  
  5881. });
  5882. rr = true;
  5883. } else {
  5884.  
  5885. isSpaceKeyImmediate = true;
  5886. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  5887. isSpaceKeyImmediate = false;
  5888. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5889.  
  5890. }
  5891.  
  5892.  
  5893. } else if (evt.type === 'keyup') {
  5894.  
  5895. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5896.  
  5897. rr = true;
  5898. } else {
  5899.  
  5900. isSpaceKeyImmediate = true;
  5901. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  5902. isSpaceKeyImmediate = false;
  5903. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5904.  
  5905. }
  5906.  
  5907.  
  5908. /*
  5909.  
  5910. if (d)
  5911. switch (c) {
  5912. case 32:
  5913. case 13:
  5914. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  5915. b = !0,
  5916. e = !1;
  5917. else if (e) {
  5918. var m = d.getAttribute("role");
  5919. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  5920. d.click(),
  5921. f = !0)
  5922. }
  5923. break;
  5924. case 37:
  5925. case 39:
  5926. case 36:
  5927. case 35:
  5928. b = "slider" === d.getAttribute("role");
  5929. break;
  5930. case 38:
  5931. case 40:
  5932. m = d.getAttribute("role"),
  5933. d = 38 === c ? d.previousSibling : d.nextSibling,
  5934. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  5935. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  5936. f = b = !0))
  5937. }
  5938. if (e && !f)
  5939. switch (c) {
  5940. case 38:
  5941. f = Math.min(this.api.getVolume() + 5, 100);
  5942. XV(this.Wd, f, !1);
  5943. this.api.setVolume(f);
  5944. h = f = !0;
  5945. break;
  5946. case 40:
  5947. f = Math.max(this.api.getVolume() - 5, 0);
  5948. XV(this.Wd, f, !0);
  5949. this.api.setVolume(f);
  5950. h = f = !0;
  5951. break;
  5952. case 36:
  5953. this.api.Yh() && (this.api.startSeekCsiAction(),
  5954. this.api.seekTo(0, void 0, void 0, void 0, 79),
  5955. h = f = !0);
  5956. break;
  5957. case 35:
  5958. this.api.Yh() && (this.api.startSeekCsiAction(),
  5959. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  5960. h = f = !0)
  5961. }
  5962. */
  5963.  
  5964. }
  5965.  
  5966.  
  5967. if (rr) {
  5968.  
  5969. // focusBodyIfSuccess && Promise.resolve().then(() => {
  5970. // activeElement === document.activeElement && activeElement.blur();
  5971. // });
  5972.  
  5973. evt.preventDefault();
  5974. evt.stopImmediatePropagation();
  5975. evt.stopPropagation();
  5976.  
  5977. }
  5978.  
  5979. };
  5980.  
  5981. document.addEventListener('keydown', keyEventListener, { capture: true });
  5982.  
  5983.  
  5984. document.addEventListener('keyup', keyEventListener, { capture: true });
  5985.  
  5986. }
  5987.  
  5988. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  5989.  
  5990. })();
  5991.  
  5992.  
  5993. pageMediaWatcher();
  5994. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  5995.  
  5996.  
  5997. const check_for_set_key_order = (() => {
  5998.  
  5999. let mySet = new Set();
  6000.  
  6001. mySet.add("value1");
  6002. mySet.add("value2");
  6003. mySet.add("value3");
  6004.  
  6005. // Function to convert Set values to an array
  6006. function getSetValues(set) {
  6007. return Array.from(set.values());
  6008. }
  6009.  
  6010. // Function to test if the Set maintains insertion order
  6011. function testSetOrder(set, expectedOrder) {
  6012. let values = getSetValues(set);
  6013. return expectedOrder.join(',') === values.join(',');
  6014. }
  6015.  
  6016. // Test 1: Initial order
  6017. if (mySet.values().next().value !== "value1") return false;
  6018. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  6019.  
  6020. // Test 2: After deleting an element
  6021. mySet.delete("value2");
  6022. if (mySet.values().next().value !== "value1") return false;
  6023. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  6024.  
  6025. // Test 3: After re-adding a deleted element
  6026. mySet.add("value2");
  6027. if (mySet.values().next().value !== "value1") return false;
  6028. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  6029.  
  6030. // Test 4: After adding a new element
  6031. mySet.add("value4");
  6032. if (mySet.values().next().value !== "value1") return false;
  6033. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  6034.  
  6035. // Test 5: Delete+Add
  6036. mySet.delete("value1");
  6037. mySet.delete("value3");
  6038. mySet.add("value3");
  6039. mySet.add("value1");
  6040. if (mySet.values().next().value !== "value2") return false;
  6041. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  6042.  
  6043. return true;
  6044. })();
  6045.  
  6046.  
  6047. // const qm47 = Symbol();
  6048. // const qm57 = Symbol();
  6049. const qm53 = Symbol();
  6050. const qn53 = Symbol();
  6051.  
  6052.  
  6053. const ump3 = new WeakMap();
  6054.  
  6055. const stp = document.createElement('noscript');
  6056. stp.id = 'weakref-placeholder';
  6057.  
  6058. PROP_OverReInclusion_AVOID && (() => {
  6059.  
  6060.  
  6061. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  6062. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  6063. let byPassVal = null;
  6064. let byPassCount = 0;
  6065. let mmw = new Set();
  6066. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  6067. if (arguments.length !== 1) return f.apply(this, arguments);
  6068. if (byPassVal !== null && typeof prop === 'string') {
  6069.  
  6070. if (PROP_OverReInclusion_LIST.has(prop)) {
  6071. byPassCount++;
  6072. return byPassVal;
  6073. }
  6074. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  6075.  
  6076. }
  6077. return this.hasOwnProperty72(prop);
  6078. };
  6079.  
  6080.  
  6081. /*
  6082.  
  6083.  
  6084. z.prototype.forwardDynamicProps = function() {
  6085. var B = m(this.inst);
  6086. B = h(B);
  6087. for (var F = B.next(); !F.done; F = B.next()) {
  6088. var H = h(F.value);
  6089. F = H.next().value;
  6090. H = H.next().value;
  6091. my(this, F, H);
  6092. r(b) && !ly(F) && Wua(this.inst, F)
  6093. }
  6094. }
  6095.  
  6096. */
  6097.  
  6098.  
  6099.  
  6100. let byPassZeroShowed = false;
  6101. const forwardDynamicPropsGeneral = function () {
  6102. byPassVal = true;
  6103. byPassCount = 0;
  6104. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  6105. const ret = this.forwardDynamicProps72();
  6106. byPassVal = null;
  6107. if (byPassCount === 0 && !byPassZeroShowed) {
  6108. byPassZeroShowed = true;
  6109. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  6110. }
  6111. byPassCount = 0;
  6112. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  6113. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  6114. mmw.clear();
  6115. }
  6116. return ret;
  6117. };
  6118.  
  6119. const propCheck = (proto) => {
  6120. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  6121. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  6122. if (proto.forwardDynamicProps.length === 0) {
  6123. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  6124. }
  6125. }
  6126. };
  6127.  
  6128. const valMap = new WeakMap();
  6129. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  6130. get() {
  6131. propCheck(this.constructor.prototype);
  6132. return valMap.get(this);
  6133. },
  6134. set(nv) {
  6135. propCheck(this.constructor.prototype);
  6136. valMap.set(this, nv);
  6137. return true;
  6138. },
  6139. enumerable: false,
  6140. configurable: true
  6141.  
  6142. });
  6143.  
  6144. promiseForCustomYtElementsReady.then(() => {
  6145. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  6146. if (customElements.define.length !== 2) return;
  6147. customElements.define72 = customElements.define;
  6148. customElements.define = function (b, w) {
  6149. propCheck(w.prototype);
  6150. const ret = this.define72(b, w);
  6151. return ret;
  6152. }
  6153. });
  6154.  
  6155. })();
  6156.  
  6157. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  6158.  
  6159. const flexibleItemListMo = new MutationObserver((mutations) => {
  6160. // cnt.onStamperFinished
  6161. // cnt.maybeUpdateFlexibleMenu
  6162. const set = new Set();
  6163. for (const mutation of mutations) {
  6164. if (mutation && ((mutation.addedNodes || 0).length > 0 || (mutation.removedNodes || 0).length > 0)) {
  6165. set.add(mutation.target);
  6166. }
  6167. }
  6168. for (const s of set) {
  6169. const cnt = insp(s);
  6170. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  6171. cnt.maybeUpdateFlexibleMenuImpl();
  6172. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  6173. cnt.maybeUpdateFlexibleMenu();
  6174. } else if (typeof cnt.onStamperFinished === 'function') {
  6175. cnt.onStamperFinished();
  6176. }
  6177. }
  6178. set.clear();
  6179. });
  6180.  
  6181. let checkConfig = true;
  6182. const flexibleItemDocMo = new MutationObserver(() => {
  6183. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  6184. s.setAttribute('b289ad', '');
  6185. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  6186. s.appendChild(document.createComment('.')).remove();
  6187. }
  6188. if (checkConfig) {
  6189. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6190. if (config && config.EXPERIMENT_FLAGS) {
  6191. checkConfig = false;
  6192. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  6193. }
  6194. }
  6195. });
  6196. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  6197.  
  6198. }
  6199.  
  6200.  
  6201.  
  6202.  
  6203. const observablePromise = (proc, timeoutPromise) => {
  6204. let promise = null;
  6205. return {
  6206. obtain() {
  6207. if (!promise) {
  6208. promise = new Promise(resolve => {
  6209. let mo = null;
  6210. const f = () => {
  6211. let t = proc();
  6212. if (t) {
  6213. mo.disconnect();
  6214. mo.takeRecords();
  6215. mo = null;
  6216. resolve(t);
  6217. }
  6218. }
  6219. mo = new MutationObserver(f);
  6220. mo.observe(document, { subtree: true, childList: true })
  6221. f();
  6222. timeoutPromise && timeoutPromise.then(() => {
  6223. resolve(null)
  6224. });
  6225. });
  6226. }
  6227. return promise
  6228. }
  6229. }
  6230. }
  6231.  
  6232.  
  6233. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  6234. observablePromise(() => {
  6235. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6236. if (config && config.EXPERIMENT_FLAGS) {
  6237. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  6238. return true;
  6239. }
  6240. }).obtain();
  6241. }
  6242.  
  6243. if (FIX_ROLLING_NUMBER_UPDATE) {
  6244.  
  6245.  
  6246. observablePromise(() => {
  6247. if (typeof customElements === 'undefined') return;
  6248. const ce = customElements.get('yt-animated-rolling-number');
  6249. if (!ce) return;
  6250. return ce.prototype;
  6251. }).obtain().then(async (cProto) => {
  6252.  
  6253. const p = document.createElement('yt-animated-rolling-number');
  6254.  
  6255. const frag = document.createDocumentFragment();
  6256. frag.appendChild(p);
  6257. const pDoc = document.implementation.createHTMLDocument();
  6258. pDoc.body.appendChild(frag);
  6259.  
  6260. let p88 = p;
  6261.  
  6262. const __instance = await observablePromise(() => {
  6263. const __instance = (p88 || 0).__instance;
  6264. if (__instance && __instance.render) return __instance;
  6265. }).obtain();
  6266. p88 = null;
  6267.  
  6268. const itProto = Reflect.getPrototypeOf(__instance);
  6269.  
  6270. try {
  6271. p.remove();
  6272. } catch (e) { }
  6273.  
  6274. if (itProto.render && !itProto.render37 && itProto.render.length === 1) {
  6275.  
  6276. itProto.render37 = itProto.render;
  6277. itProto.render = function (t) {
  6278. // (this.xCounter = (this.xCounter & 1073741823)+1)
  6279. let c33 = '';
  6280. let r33 = null;
  6281. let kc = 0;
  6282.  
  6283. if (this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  6284. const el = this.el;
  6285. const ct = Date.now();
  6286. const lastFireTime = (el.__lastFireTime491__ || 0);
  6287.  
  6288. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  6289.  
  6290. if (fireTimeDiff < 80 && this.__previousRender61__) {
  6291. return this.__previousRender61__;
  6292. }
  6293.  
  6294. const caseInt =
  6295. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  6296. (t && typeof t.character === 'string') ? (
  6297. (typeof t.previousCharacter === 'string') ? 6 : 2
  6298. ) : 0;
  6299.  
  6300. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender61__ && fireTimeDiff < 9400) {
  6301. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender61__) {
  6302. return this.__previousRender61__;
  6303. }
  6304. }
  6305. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender61__ && fireTimeDiff < 9400) {
  6306. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender61__) {
  6307. return this.__previousRender61__;
  6308. }
  6309. }
  6310.  
  6311. if (caseInt & 2) {
  6312.  
  6313. if (caseInt & 4) {
  6314.  
  6315. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  6316. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  6317. t.previousCharacter = t.character;
  6318. kc = 1;
  6319. }
  6320. }
  6321.  
  6322. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  6323. t.shouldAnimate = false;
  6324. }
  6325. }
  6326.  
  6327.  
  6328. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  6329.  
  6330. el.__lastCharacter353__ = t.character;
  6331.  
  6332. } else if (caseInt === 1) {
  6333.  
  6334. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  6335. t.shouldAnimate = false;
  6336. }
  6337. el.__lastNumberValue353__ = t.numberValue;
  6338.  
  6339. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  6340. t.shouldAnimate = false;
  6341. }
  6342. el.__lastNumberText353__ = t.numberText;
  6343.  
  6344. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  6345.  
  6346. }
  6347.  
  6348. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  6349.  
  6350. el.__lastFireTime491__ = ct;
  6351. }
  6352.  
  6353. // // console.log(21399, t.character, t.previousCharacter, (t.xCounter = (t.xCounter & 1073741823)+1), t, (this.xCounter = (this.xCounter & 1073741823)+1) )
  6354. // // console.log(12883, this, t);
  6355. const r = r33 || this.render37(t);
  6356. this.__previousRender61__ = r;
  6357. if (c33) this[c33] = r;
  6358. return r
  6359. }
  6360.  
  6361. }
  6362.  
  6363. });
  6364.  
  6365. }
  6366.  
  6367. if (HOOK_ACTIVE_MODULES) {
  6368.  
  6369. let watchController;
  6370. const watchControllerObservable = observablePromise(() => {
  6371. const watchFlexy = document.querySelector('ytd-watch-flexy');
  6372. if (!watchFlexy) return;
  6373. return insp(watchFlexy).watchController;
  6374. }).obtain();
  6375. (async () => {
  6376. watchController = await watchControllerObservable;
  6377.  
  6378. const activeModules = watchController.activeModules;
  6379. if (!activeModules) return;
  6380.  
  6381. const checkFn = (activeModule) => {
  6382. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  6383. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  6384. }
  6385. }
  6386. if (!activeModules.push8792 && activeModules.push) {
  6387. activeModules.push8792 = activeModules.push;
  6388. activeModules.push = function (a, ...args) {
  6389. checkFn(a);
  6390. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  6391. return r;
  6392. }
  6393. }
  6394. activeModules.forEach(checkFn);
  6395.  
  6396. })();
  6397.  
  6398. let yieldResultWrappingByPass = false;
  6399. let asyncProto = null;
  6400. const yieldResultWrapping = (f) => {
  6401. if (yieldResultWrappingByPass) return [f(), null];
  6402. yieldResultWrappingByPass = true;
  6403. let D = null;
  6404. let promise, e_;
  6405. if (asyncProto) {
  6406. Object.defineProperty(asyncProto, 'yieldResult', {
  6407. get() {
  6408. return undefined;
  6409. },
  6410. set(nv) {
  6411. delete asyncProto.yieldResult;
  6412. this.yieldResult = nv;
  6413. D = this;
  6414. // console.log(122, this);
  6415. return true;
  6416. },
  6417. enumerable: false,
  6418. configurable: true
  6419. });
  6420. try {
  6421. promise = f();
  6422. } catch (e) { e_ = e }
  6423. delete asyncProto.yieldResult;
  6424. yieldResultWrappingByPass = false;
  6425. } else {
  6426. Object.defineProperty(Object.prototype, 'yieldResult', {
  6427. get() {
  6428. return undefined;
  6429. },
  6430. set(nv) {
  6431. delete Object.prototype.yieldResult;
  6432. this.yieldResult = nv;
  6433. D = this;
  6434. // console.log(122, this);
  6435. return true;
  6436. },
  6437. enumerable: false,
  6438. configurable: true
  6439. });
  6440. try {
  6441. promise = f();
  6442. } catch (e) { e_ = e }
  6443. delete Object.prototype.yieldResult;
  6444. yieldResultWrappingByPass = false;
  6445. if (D) {
  6446. asyncProto = Reflect.getPrototypeOf(D);
  6447. }
  6448. }
  6449. if (e_) throw e_;
  6450. return [promise, D];
  6451. }
  6452.  
  6453. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  6454.  
  6455. const aProto = Reflect.getPrototypeOf(activeModule);
  6456.  
  6457. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  6458.  
  6459. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  6460.  
  6461. // console.log(12885)
  6462. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  6463. // let qxt=false;
  6464. aProto.fetchUpdatedMetadata = function (t, P) {
  6465.  
  6466. // if (!qxt) {
  6467. // qxt = true;
  6468. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  6469. // console.log(199001,...args)
  6470. // });
  6471. // this.addOnDisposeCallback(function (...args) {
  6472.  
  6473. // console.log(199002,...args)
  6474. // watchController.unsubscribeByKey(y)
  6475. // qxt = false;
  6476. // });
  6477. // }
  6478. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  6479. if (D) promise.then(() => {
  6480. const yieldResult = D.yieldResult;
  6481. if (yieldResult) {
  6482. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  6483.  
  6484. if (mutations && mutations.length >= 1) {
  6485. let likeCountEntity = null;
  6486. for (const mutation of mutations) {
  6487. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  6488. break;
  6489. }
  6490. }
  6491. if (likeCountEntity) {
  6492. const model = insp(document.querySelector('segmented-like-dislike-button-view-model'));
  6493. if (model && typeof model.update === 'function' && model.update.length === 0) {
  6494. const data = ((model || 0).props || 0).data;
  6495. if (data) {
  6496. if (typeof data.likeCountEntity !== 'object') data.likeCountEntity = {};
  6497. // console.log(12838, {...data.likeCountEntity}, {...likeCountEntity})
  6498. // const shouldModelUpdate = (data.likeCountEntity.key !== likeCountEntity.key); // to be reviewed
  6499. const shouldModelUpdate = true;
  6500. Object.assign(data.likeCountEntity, likeCountEntity);
  6501. // data.likeCountEntity = likeCountEntity;
  6502. // if (shouldModelupdate) model.update();
  6503. // else {
  6504. // if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  6505. // }
  6506.  
  6507. if (shouldModelUpdate) {
  6508. if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  6509. // console.log('kk1a enqueueUpdate')
  6510. model.enqueueUpdate();
  6511. // console.log('kk1b enqueueUpdate')
  6512. } else if (typeof model.update === 'function' && model.update.length === 0) {
  6513. // console.log('kk2a update')
  6514. model.update();
  6515. // console.log('kk2b update')
  6516. } else {
  6517. console.warn('[yt-js-engine-tamer] cannot do model update.')
  6518. }
  6519. }
  6520.  
  6521. }
  6522. }
  6523. }
  6524. }
  6525. }
  6526. }).catch(console.warn);
  6527. return promise;
  6528. };
  6529.  
  6530. }
  6531.  
  6532. }
  6533.  
  6534. // ----------------------------
  6535.  
  6536. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  6537.  
  6538. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  6539.  
  6540. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  6541.  
  6542.  
  6543. // const globalPromiseStack = {};
  6544.  
  6545. // let dummy;
  6546. // while(!dummy){
  6547.  
  6548. // dummy = document.querySelector('yt-icon');
  6549. // await new Promise(r=>setTimeout(r,0));
  6550. // }
  6551.  
  6552. dummy = document.createElement('yt-icon');
  6553.  
  6554. let cProto;
  6555. if (!(dummy instanceof Element)) return;
  6556. cProto = insp(dummy).constructor.prototype;
  6557.  
  6558. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  6559. cProto.determineIconSet671 = cProto.determineIconSet;
  6560. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  6561. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  6562. cProto.getIconManager671 = cProto.getIconManager;
  6563. cProto.getIconShapeData671 = cProto.getIconShapeData;
  6564. cProto.renderIcon671 = cProto.renderIcon;
  6565.  
  6566. // cProto.attached488 = cProto.attached;
  6567. // cProto.attached = function(){
  6568. // console.log('attached')
  6569. // return this.attached488(...arguments);
  6570. // }
  6571. // cProto.detached488 = cProto.detached;
  6572. // cProto.detached = function(){
  6573. // console.log('detached')
  6574. // return this.detached488(...arguments);
  6575. // }
  6576.  
  6577. if (cProto.__renderIconFix__) return;
  6578. cProto.__renderIconFix__ = true;
  6579.  
  6580. let taskStack = [];
  6581. const cmObs = new MutationObserver(() => {
  6582. const tasks = taskStack.slice();
  6583. taskStack.length = 0;
  6584. for (const task of tasks) {
  6585. task();
  6586. }
  6587. })
  6588. const cm = document.createComment('1');
  6589. const stackTask = (f) => {
  6590. taskStack.push(f);
  6591. cm.data = `${(cm.data & 7) + 1}`;
  6592. }
  6593. cmObs.observe(cm, { characterData: true });
  6594.  
  6595. // let iconManagers = {}; // assume shared
  6596.  
  6597. // window.iconManagers = () => iconManagers;
  6598.  
  6599.  
  6600. const setupYtIcon = (inst) => {
  6601.  
  6602. if (inst.__ytIconSetup588__) return;
  6603. const cProto = Reflect.getPrototypeOf(inst);
  6604. cProto.__ytIconSetup588__ = true;
  6605.  
  6606.  
  6607. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6608.  
  6609. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  6610. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  6611. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  6612. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  6613.  
  6614.  
  6615. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  6616. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  6617. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  6618. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  6619.  
  6620.  
  6621.  
  6622. }
  6623.  
  6624. cProto.handlePropertyChange = function (...a) { // 10+
  6625.  
  6626. const __data = this.__data;
  6627. if (FIX_GUIDE_ICON && this.id === 'guide-icon' && __data && !__data.icon && typeof this.set === 'function') {
  6628. this.set('icon', "yt-icons:menu")
  6629. }
  6630.  
  6631. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6632. this.__resolved__ = {
  6633.  
  6634. };
  6635. const a01 = this.isAttached;
  6636. let a02, a03;
  6637.  
  6638.  
  6639. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  6640.  
  6641. const stackFn = () => {
  6642. if (t !== this.__stackedKey3818__) {
  6643. return;
  6644. }
  6645. a03 = this.isAttached;
  6646.  
  6647. if (a01 === false && a02 === false && a03 === false) return;
  6648.  
  6649. if (a01 === true && a02 === true && a03 === true) {
  6650.  
  6651. } else {
  6652. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  6653. // unknown yt-icon#label-icon
  6654. return;
  6655. } else {
  6656. console.log('[yt-icon] debug', a01, a02, a03, this)
  6657. }
  6658. }
  6659.  
  6660. this.handlePropertyChange671(...arguments);
  6661.  
  6662. };
  6663.  
  6664.  
  6665.  
  6666. Promise.resolve().then(() => {
  6667. a02 = this.isAttached;
  6668. stackTask(stackFn);
  6669. });
  6670.  
  6671.  
  6672. }
  6673.  
  6674. cProto.determineIconSet = function (a, b, c, d) { // 10-
  6675.  
  6676. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6677. // string bool? bool=false int=24
  6678. // NOTIFICATIONS_NONE OR LIKE
  6679. // console.log('yt-icon.determineIconSet', ...arguments);
  6680.  
  6681. const r = this.determineIconSet671(...arguments);
  6682. return r;
  6683. }
  6684.  
  6685. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  6686.  
  6687. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6688. // same as determineIconSet
  6689. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  6690. return this.switchToYtSysIconset671(...arguments);
  6691. }
  6692.  
  6693. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  6694.  
  6695. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6696. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  6697. return this.useYtSysIconsetForMissingIcons671(...arguments);
  6698. }
  6699.  
  6700. cProto.getIconManager = function () { // 10+
  6701.  
  6702. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6703. if (!this.__resolved__) this.__resolved__ = {};
  6704. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  6705. const r = this.__resolved__.getIconManager;
  6706. return r;
  6707. }
  6708.  
  6709. cProto.getIconShapeData = function () { // 10+
  6710.  
  6711. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6712.  
  6713. // no argument
  6714. // console.log('yt-icon.getIconShapeData', ...arguments);
  6715. if (!this.__resolved__) this.__resolved__ = {};
  6716. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  6717. const r = this.__resolved__.getIconShapeData;
  6718. return r
  6719. }
  6720.  
  6721. cProto.renderIcon = function (a, b) { // X
  6722.  
  6723. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6724. // "" yt-icons:xxx
  6725. // console.log('yt-icon.renderIcon', ...arguments);
  6726. return this.renderIcon671(...arguments);
  6727. }
  6728.  
  6729. });
  6730.  
  6731.  
  6732. /**
  6733. * Compute the Longest Common Subsequence between two arrays.
  6734. * Returns an array of the LCS elements (in order).
  6735. */
  6736. function computeLCS(a, b) {
  6737. // Input validation
  6738. if (!Array.isArray(a) || !Array.isArray(b)) {
  6739. throw new Error('Inputs must be arrays');
  6740. }
  6741.  
  6742. const n = a.length, m = b.length;
  6743. // Early termination for trivial cases
  6744. if (n === 0 || m === 0) return [];
  6745. // Check for shallow equality
  6746. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  6747.  
  6748. // Use smaller dimension for space optimization
  6749. if (n > m) return computeLCS(b, a); // Ensure n <= m
  6750.  
  6751. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  6752. // Use Uint32Array for robustness with long sequences
  6753. const dp = [
  6754. new Uint32Array(m + 1),
  6755. new Uint32Array(m + 1),
  6756. ];
  6757. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  6758. // Optimize space by storing only necessary entries
  6759. const pred = new Uint8Array(n * m); // Single array for moves
  6760.  
  6761. for (let i = n - 1; i >= 0; i--) {
  6762. const curr = i % 2;
  6763. const next = 1 - curr;
  6764. // Clear current row for reuse
  6765. dp[curr].fill(0);
  6766.  
  6767. for (let j = m - 1; j >= 0; j--) {
  6768. const idx = i * m + j;
  6769. if (a[i] === b[j]) {
  6770. dp[curr][j] = dp[next][j + 1] + 1;
  6771. pred[idx] = 0; // Diagonal
  6772. } else if (dp[next][j] >= dp[curr][j + 1]) {
  6773. dp[curr][j] = dp[next][j];
  6774. pred[idx] = 1; // Down
  6775. } else {
  6776. dp[curr][j] = dp[curr][j + 1];
  6777. pred[idx] = 2; // Right
  6778. }
  6779. }
  6780. }
  6781.  
  6782. // Check for potential overflow
  6783. if (dp[0][0] > 0xFFFFFFFF) {
  6784. throw new Error('LCS length exceeds safe integer limit');
  6785. }
  6786.  
  6787. // Backtrack to build the actual LCS
  6788. const lcs = [];
  6789. let i = 0, j = 0;
  6790. while (i < n && j < m) {
  6791. const idx = i * m + j;
  6792. const p = pred[idx];
  6793. if (p === 0) {
  6794. lcs.push(a[i]);
  6795. i++; j++;
  6796. } else if (p === 1) {
  6797. i++;
  6798. } else {
  6799. j++;
  6800. }
  6801. }
  6802. return lcs;
  6803. }
  6804.  
  6805. /**
  6806. * Given original[] and modified[], produce an array of splice-ops:
  6807. * [ [start0, deleteCount0, addedItems0],
  6808. * [start1, deleteCount1, addedItems1],
  6809. * … ]
  6810. * When you do:
  6811. * let arr = original.slice();
  6812. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  6813. * arr will equal modified.
  6814. */
  6815. function diffSplices(original, modified) {
  6816. // Input validation
  6817. if (!Array.isArray(original) || !Array.isArray(modified)) {
  6818. throw new Error('Inputs must be arrays');
  6819. }
  6820.  
  6821. const origLen = original.length;
  6822. const modLen = modified.length;
  6823. // Early termination for trivial cases
  6824. if (origLen === 0 && modLen === 0) return [];
  6825. if (origLen === 0) return [[0, 0, modified.slice()]];
  6826. if (modLen === 0) return [[0, origLen, []]];
  6827.  
  6828. // Trim common prefix and suffix
  6829. let prefixLen = 0;
  6830. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  6831. prefixLen++;
  6832. }
  6833. let suffixLen = 0;
  6834. while (
  6835. suffixLen < origLen - prefixLen &&
  6836. suffixLen < modLen - prefixLen &&
  6837. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  6838. ) {
  6839. suffixLen++;
  6840. }
  6841.  
  6842. // Cache references for speed
  6843. const orig = original.slice(prefixLen, origLen - suffixLen);
  6844. const mod = modified.slice(prefixLen, modLen - suffixLen);
  6845. const lcs = computeLCS(orig, mod);
  6846. // Pre-allocate ops array, accounting for potential moves
  6847. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  6848. let opCount = 0;
  6849.  
  6850. let i = 0, j = 0, k = 0;
  6851. let curIndex = prefixLen;
  6852. const lcsLen = lcs.length;
  6853.  
  6854. while (k < lcsLen) {
  6855. const match = lcs[k];
  6856. let deleteCount = 0;
  6857. const deleted = [];
  6858. const added = [];
  6859.  
  6860. // 1) Collect deletions up to the next common element
  6861. while (i < orig.length && orig[i] !== match) {
  6862. deleted.push(orig[i]);
  6863. deleteCount++;
  6864. i++;
  6865. }
  6866.  
  6867. // 2) Collect insertions up to that same element
  6868. while (j < mod.length && mod[j] !== match) {
  6869. added.push(mod[j]);
  6870. j++;
  6871. }
  6872.  
  6873. // 3) Check for a move (deleted segment matches inserted segment)
  6874. let isMove = false;
  6875. if (deleteCount > 0 && deleteCount === added.length) {
  6876. isMove = deleted.every((x, idx) => x === added[idx]);
  6877. if (isMove) {
  6878. // If a move, split into delete and insert at different indices
  6879. if (deleteCount > 0) {
  6880. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  6881. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  6882. curIndex += added.length; // Advance past inserted items
  6883. }
  6884. }
  6885. }
  6886.  
  6887. // 4) Combine delete and insert into a single operation if not a move
  6888. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  6889. ops[opCount++] = [curIndex, deleteCount, added];
  6890. curIndex += added.length; // Advance past inserted items
  6891. }
  6892.  
  6893. // 5) Skip over the matching element itself
  6894. i++;
  6895. j++;
  6896. k++;
  6897. curIndex++;
  6898. }
  6899.  
  6900. // 6) Handle any trailing deletions and insertions as a single operation
  6901. const trailingDelete = orig.length - i;
  6902. const trailingAdd = mod.slice(j);
  6903. if (trailingDelete > 0 || trailingAdd.length > 0) {
  6904. // Check for trailing move
  6905. const trailingDeleted = orig.slice(i);
  6906. let isMove = false;
  6907. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  6908. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  6909. if (isMove) {
  6910. ops[opCount++] = [curIndex, trailingDelete, []];
  6911. ops[opCount++] = [curIndex, 0, trailingAdd];
  6912. }
  6913. }
  6914. if (!isMove) {
  6915. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  6916. }
  6917. }
  6918.  
  6919. // 7) Truncate ops array to actual size
  6920. ops.length = opCount;
  6921.  
  6922. return ops;
  6923. }
  6924. // class listPlaceholder {
  6925. // constructor(len){
  6926. // this.length = len;
  6927. // }
  6928. // }
  6929.  
  6930.  
  6931.  
  6932. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  6933. // var renderJob = this.renderJobsMap_[key],
  6934. // renderCallback = null;
  6935.  
  6936. // if (path === changeRecord.path) {
  6937. // let value = changeRecord.value;
  6938.  
  6939. // if (!_.v_(value)) {
  6940. // value = (value === void 0 || value === null) ? [] : [value];
  6941. // }
  6942.  
  6943. // let stampDomEntry = this.stampDom[path];
  6944.  
  6945. // if (stampDomEntry.mapping) {
  6946. // renderCallback = this.stampDomArray_.bind(
  6947. // this,
  6948. // value,
  6949. // key,
  6950. // stampDomEntry.mapping,
  6951. // stampDomEntry.reuseComponents,
  6952. // stampDomEntry.events,
  6953. // stampDomEntry.stamperStableList
  6954. // );
  6955. // }
  6956.  
  6957. // if (renderJob) renderJob.cancel();
  6958.  
  6959. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  6960.  
  6961. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  6962. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  6963. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  6964. // this.renderJobsMap_[key] = renderJob;
  6965. // }
  6966. // } else {
  6967. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  6968. // this.renderJobsMap_[key] = renderJob;
  6969. // renderCallback = function(callback, job) {
  6970. // callback();
  6971. // q4C(job, 10);
  6972. // }.bind(this, renderCallback, renderJob);
  6973. // }
  6974. // } else {
  6975. // renderCallback = (path + ".splices" === changeRecord.path)
  6976. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  6977. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  6978. // }
  6979.  
  6980. // if (renderJob) {
  6981. // _.vY(renderJob, renderCallback);
  6982. // } else {
  6983. // renderCallback();
  6984. // }
  6985. // }
  6986.  
  6987.  
  6988.  
  6989.  
  6990. const createStampDomFnsC_ = () => {
  6991.  
  6992. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  6993.  
  6994. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  6995. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  6996.  
  6997.  
  6998. // const rq0 = document.createElement('rp');
  6999. // rq0.setAttribute('yt-element-placholder', '');
  7000.  
  7001. const it0 = Date.now() - 80000000000;
  7002. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  7003.  
  7004.  
  7005. const getStampContainer_ = function (containerId) {
  7006.  
  7007. return this.getStampContainer7409_(containerId);
  7008.  
  7009. }
  7010.  
  7011.  
  7012.  
  7013.  
  7014. const createComponent_ = function (componentConfig, data, canReuse) {
  7015.  
  7016. return this.createComponent7409_(componentConfig, data, canReuse);
  7017.  
  7018. }
  7019.  
  7020.  
  7021. const s52 = Symbol();
  7022.  
  7023. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  7024.  
  7025. // if(component.querySelectorAll('dom-if').length > 0){
  7026.  
  7027. // // console.log(1233, component.isConnected, component.parentNode, component.querySelectorAll('dom-if'))
  7028. // if (component.isConnected === false) {
  7029. // for (const s of component.querySelectorAll('dom-if')) {
  7030. // try {
  7031. // console.log(1299);
  7032. // insp(s).__teardownInstance();
  7033. // } catch (e) { }
  7034. // }
  7035. // }
  7036.  
  7037. // }
  7038.  
  7039. if (typeof (data || 0) === 'object') {
  7040. if (!data[s52]) data[s52] = genId();
  7041. component[s52] = data[s52];
  7042. // console.log(component[s52], data);
  7043. } else {
  7044. component[s52] = null;
  7045. }
  7046.  
  7047. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7048.  
  7049. }
  7050.  
  7051. // let pr77 = Promise.resolve();
  7052.  
  7053. const flushRenderStamperComponentBindings_ = function () {
  7054. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  7055.  
  7056. if (this.deferredBindingTasks_.length >= 0) {
  7057.  
  7058. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  7059.  
  7060. const gid = this[`__$$stampFlushKey$$__`] = genId();
  7061. const g = (() => {
  7062. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  7063. // if (deferredBindingTasks_.length === 0) return;
  7064. // let q = this.deferredBindingTasks_;
  7065. // this.deferredBindingTasks_ = deferredBindingTasks_;
  7066. this.flushRenderStamperComponentBindings7409_();
  7067. // deferredBindingTasks_.length = 0;
  7068. // this.deferredBindingTasks_ = q;
  7069.  
  7070. const s = [...this.__lat457__];
  7071. this.__lat457__.clear();
  7072.  
  7073. for (const containerWr of s) {
  7074.  
  7075. const container = kRef(containerWr);
  7076. if (!container) continue;
  7077.  
  7078. // const s = new Set();
  7079. if (!container.querySelector('[ytx-flushing]')) {
  7080. if (container.hasAttribute('ytx-flushing')) {
  7081. const attrVal = container.getAttribute('ytx-flushing');
  7082. container.removeAttribute('ytx-flushing');
  7083. // s.add([container, attrVal]);
  7084. addTask(container, attrVal);
  7085. // addTaskIm(container, attrVal);
  7086. let ancestor = container.closest('[ytx-flushing]');
  7087. while (ancestor) {
  7088. if (ancestor.querySelector('[ytx-flushing]')) break;
  7089. const attrVal = ancestor.getAttribute('ytx-flushing');
  7090. ancestor.removeAttribute('ytx-flushing');
  7091. // s.add([ancestor, attrVal]);
  7092. addTask(ancestor, attrVal);
  7093. // addTaskIm(ancestor, attrVal);
  7094. ancestor = ancestor.closest('[ytx-flushing]');
  7095. }
  7096. }
  7097. }
  7098. }
  7099. executeTasks();
  7100.  
  7101.  
  7102. });
  7103. g();
  7104. // const useMicroTaskQueue = this.__qsd477__ === 2;
  7105. // useMicroTaskQueue ? addTask2(g) : g();
  7106. // executeTasks();
  7107.  
  7108. // addTask2(g);
  7109. // executeTasks();
  7110.  
  7111. }
  7112.  
  7113. throw new Error('e5bd8d2f');
  7114.  
  7115. }
  7116.  
  7117. let tasks = [];
  7118. let excuted = false;
  7119. const executeTasks = ()=>{
  7120. if(excuted || tasks.length === 0) return;
  7121. excuted = true;
  7122. let t0 = 0;
  7123. const perform = ()=>{
  7124. if(!t0) t0 = nativeNow();
  7125. const task = tasks.shift();
  7126. if(!task){
  7127. excuted = false;
  7128. return;
  7129. }
  7130. task.fn(task);
  7131. const t1 = nativeNow();
  7132. if(t1 - t0 > 10){
  7133. t0 = 0;
  7134. nextBrowserTick_(perform);
  7135. }else{
  7136. queueMicrotask_(perform);
  7137. }
  7138. }
  7139. queueMicrotask_(perform);
  7140. }
  7141.  
  7142. const taskFn = (task) => {
  7143.  
  7144. if(!task) return;
  7145. const { containerWr, attrVal } = task;
  7146. const container = kRef(containerWr);
  7147. if (!container) return;
  7148. if (attrVal === '0') return;
  7149. const bEventCb = attrVal === '2';
  7150. const producerWr = containerMapping.get(container);
  7151. const producer = kRef(producerWr);
  7152. if (!producer) return;
  7153. const hostElement = producer.hostElement;
  7154. if (!hostElement) return;
  7155. if (hostElement.isConnected !== true) return; // tbc
  7156. producer.markDirty && producer.markDirty();
  7157. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  7158. container
  7159. });
  7160.  
  7161. }
  7162.  
  7163. const addTask = (container, attrVal) => {
  7164. if (!container) return;
  7165. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7166. tasks.push({
  7167. fn: taskFn,
  7168. containerWr: containerWr,
  7169. attrVal
  7170. });
  7171. // pr77 = pr77.then(()=>{
  7172.  
  7173. // })
  7174. // taskFn({
  7175. // containerWr: containerWr,
  7176. // attrVal
  7177. // })
  7178.  
  7179. }
  7180.  
  7181. const addTaskIm = (container, attrVal) => {
  7182. if (!container) return;
  7183. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7184. taskFn({
  7185. fn: taskFn,
  7186. containerWr: containerWr,
  7187. attrVal
  7188. });
  7189.  
  7190. }
  7191.  
  7192.  
  7193. const addTask2 = (f) => {
  7194. // pr77 = pr77.then(f).catch(console.warn);
  7195. tasks.push({
  7196. fn: f
  7197. });
  7198.  
  7199. }
  7200.  
  7201. // const mo = new MutationObserver((mutations)=>{
  7202.  
  7203. // });
  7204. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  7205.  
  7206. const containerMapping = new WeakMap();
  7207.  
  7208. // let pr77 = Promise.resolve();
  7209. // let pr88 = Promise.resolve();
  7210. const uA4 = function (t, P) {
  7211. for (let y in t)
  7212. if (t.hasOwnProperty(y) && P[y])
  7213. return y;
  7214. return null
  7215. }
  7216.  
  7217. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  7218.  
  7219. const ax = ax_;
  7220. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  7221. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  7222. // const useMicroTaskQueue = false;
  7223. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  7224. ax[2].cancel();
  7225. useMicroTaskQueue2 = false;
  7226. }
  7227. // console.log(1992,containerId, this.hostElement.is)
  7228.  
  7229. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  7230. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  7231. // return false;
  7232.  
  7233. // }
  7234.  
  7235. if (producer.hasFlexibleItems === true) {
  7236. return false;
  7237. }
  7238.  
  7239. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  7240. return false;
  7241. }
  7242.  
  7243. const hostIs = hostIs_;
  7244.  
  7245. 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;
  7246.  
  7247. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  7248. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  7249. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  7250. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  7251. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  7252. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  7253. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  7254. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  7255. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  7256. 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;
  7257. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  7258. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  7259. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  7260. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  7261. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  7262. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  7263. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  7264. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  7265. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  7266.  
  7267.  
  7268. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  7269.  
  7270.  
  7271. // console.log(5992,stackAt)
  7272.  
  7273. // console.log(2883, this[`__quu477#${containerId}__`] )
  7274. // if (useMicroTaskQueue) {
  7275. // console.log(stackAt)
  7276. // }
  7277.  
  7278. // if (useMicroTaskQueue) {
  7279. // console.log(1120301)
  7280. // }
  7281.  
  7282. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  7283.  
  7284. return useMicroTaskQueue2;
  7285.  
  7286. }
  7287.  
  7288. const frag385 = document.createDocumentFragment();
  7289. frag385.appendChild4202 = frag385.appendChild;
  7290. frag385.removeChild4202 = frag385.removeChild;
  7291. const cm385 = document.createComment('.');
  7292.  
  7293. const doc385 = document.implementation.createHTMLDocument();
  7294. const html385 = doc385.firstElementChild;
  7295. const node385 = html385.appendChild(document.createElement('div'));
  7296.  
  7297. const fixContainerApi = (container) => {
  7298. if (container instanceof Node) {
  7299. const containerDomApi = container.__domApi;
  7300. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  7301. // console.log(123882, container)
  7302. containerDomApi.removeChild588 = containerDomApi.removeChild;
  7303. containerDomApi.removeChild = function (elem) {
  7304. let r;
  7305. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7306. s.setAttribute('ytx-flushing', '0');
  7307. }
  7308. try {
  7309. r = this.removeChild588(elem);
  7310. } catch (e) { }
  7311. if (!r) {
  7312. frag385.appendChild4202(elem);
  7313. frag385.removeChild4202(elem);
  7314. r = elem;
  7315. }
  7316. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7317. s.removeAttribute('ytx-flushing');
  7318. }
  7319. return r;
  7320. }
  7321. }
  7322. }
  7323. }
  7324.  
  7325. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7326.  
  7327. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7328. if (typeof sqq === 'function') sqq();
  7329.  
  7330. // trigger in rendererStamperApplyChangeRecord_
  7331.  
  7332. // 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];
  7333. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7334. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7335. // 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];
  7336.  
  7337. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7338. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7339.  
  7340.  
  7341. const ax = this[`__quu477#${containerId}__`];
  7342. const hostIs = (this.hostElement || 0).is;
  7343. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7344.  
  7345. const container = this.getStampContainer7409_(containerId);
  7346. const pChildren = (container instanceof Node && container.isConnected) ? [...container.children] : [];
  7347. renderPathMake(pChildren)
  7348.  
  7349. containerMapping.set(container,
  7350. (this[wk] || (this[wk] = mWeakRef(this)))
  7351. );
  7352.  
  7353. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7354. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7355.  
  7356. // let dataList_ = dataList;
  7357. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  7358.  
  7359. dataList = null;
  7360. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  7361. let fq = 0;
  7362. const f = (() => {
  7363. if(fq) return;
  7364. fq = 1;
  7365. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7366. this[`__$$stampSFn$$#${containerId}__`] = null;
  7367. const container = this.getStampContainer7409_(containerId);
  7368.  
  7369. this.__lat457__ = this.__lat457__ || new Set();
  7370. if(!container[wk]) container[wk] = mWeakRef(container);
  7371. this.__lat457__.add(container[wk]);
  7372. fixContainerApi(container);
  7373.  
  7374. // let q = this.deferredBindingTasks_;
  7375. // this.deferredBindingTasks_ = [];
  7376. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7377. let e_;
  7378. try {
  7379. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  7380. } catch (e) { e_ = e }
  7381. this.__qsd477__ = false;
  7382. dataList_ = typeOrConfig = null;
  7383. fixContainerApi(container);
  7384. // this.deferredBindingTasks_ = q;
  7385. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7386. if (!e_) {
  7387. // container.setAttribute('ytx-flushing', '0');
  7388. }
  7389. // if( container.childElementCount === 0 ){
  7390. // container.setAttribute('ytx-flushing', '0');
  7391. // this.markDirty && this.markDirty();
  7392. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  7393. // container
  7394. // });
  7395. // }
  7396.  
  7397.  
  7398.  
  7399.  
  7400. });
  7401. this[`__$$stampSFn$$#${containerId}__`] = f;
  7402. this[`__$$stampSqq$$#${containerId}__`] = f;
  7403. useMicroTaskQueue2 ? addTask2(f) : f();
  7404. executeTasks();
  7405.  
  7406. Promise.resolve(pChildren).then(pChildren => {
  7407. for (const node of pChildren) {
  7408. if (node.isConnected === false) {
  7409. _removedElements.addNode(node); // rn54006
  7410. }
  7411. }
  7412. pChildren.length = 0;
  7413. pChildren = null;
  7414. });
  7415.  
  7416. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  7417.  
  7418. return undefined;
  7419.  
  7420. }
  7421.  
  7422. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  7423.  
  7424.  
  7425. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7426. if (typeof sqq === 'function') sqq();
  7427.  
  7428. // trigger in rendererStamperApplyChangeRecord_
  7429.  
  7430. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7431. } else {
  7432. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7433. }
  7434.  
  7435.  
  7436. // trigger in rendererStamperApplyChangeRecord_
  7437.  
  7438. // 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];
  7439. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7440. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7441.  
  7442. // 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];
  7443.  
  7444. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7445. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7446. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  7447.  
  7448. const ax = this[`__quu477#${containerId}__`];
  7449. const hostIs = (this.hostElement || 0).is;
  7450. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7451.  
  7452.  
  7453. // 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];
  7454. // const useMicroTaskQueue = true;
  7455. const container = this.getStampContainer7409_(containerId);
  7456.  
  7457. containerMapping.set(container,
  7458. (this[wk] || (this[wk] = mWeakRef(this)))
  7459. );
  7460. const bEventCb = this.stampDom[stampKey].events;
  7461. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7462. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7463.  
  7464. // let indexSplicesObj_ = indexSplicesObj;
  7465. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7466. // indexSplicesObj_ = {
  7467. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  7468. // const { index, addedCount, removed, object, type } = slice;
  7469. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7470. // return { index, addedCount, removed, object, type };
  7471. // })
  7472. // };
  7473. // }
  7474.  
  7475.  
  7476. indexSplicesObj.indexSplices.forEach(slice => {
  7477. const object = slice.object;
  7478. if (!object || typeof object !== 'object') return;
  7479. // const { index, addedCount, removed, object, type } = slice;
  7480. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7481. // return { index, addedCount, removed, object, type };
  7482. });
  7483.  
  7484. // let indexSplicesObj_ = indexSplicesObj;
  7485.  
  7486. // console.log(128783, indexSplicesObj)
  7487.  
  7488. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  7489. // const { index, addedCount, removed, object, type } = slice;
  7490. // return { index, addedCount, removed, object, type };
  7491. // });
  7492.  
  7493. indexSplicesObj = null;
  7494.  
  7495. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  7496. const gid = this[`__$$stampSID$$#${containerId}__`];
  7497. let fq = 0;
  7498. const f = (() => {
  7499. if(fq) return;
  7500. fq = 1;
  7501. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7502. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  7503. const container = this.getStampContainer7409_(containerId);
  7504. if(!container) return;
  7505.  
  7506. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  7507.  
  7508. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  7509. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  7510. const mapping = this.stampDom[stampKey].mapping;
  7511.  
  7512. const map = new Map();
  7513.  
  7514. const currentObjKeys = object.map(objEntry => {
  7515. const mappingKey = uA4(mapping, objEntry);
  7516. if(!mappingKey) return null;
  7517. const data = objEntry[mappingKey];
  7518. if (!data[s52]) data[s52] = genId();
  7519. map.set(data[s52], objEntry);
  7520. // return ({
  7521. // objEntry,
  7522. // data: data,
  7523. // mappingKey: mappingKey,
  7524. // key: data[s52],
  7525. // exist: elementKeys.has(data[s52])
  7526. // });
  7527. return data[s52]
  7528.  
  7529. });
  7530.  
  7531. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  7532.  
  7533. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  7534.  
  7535. const splices = diffSplices(oldDomKeys, currentObjKeys);
  7536.  
  7537. // let myObject = object;
  7538. let indexSplicesObj_ = {
  7539. indexSplices: splices.map(splice => {
  7540. const index = splice[0];
  7541. const removedLen = splice[1];
  7542. const added = splice[2];
  7543. const addedCount = added.length;
  7544. const object = {};
  7545. object.length = index + addedCount;
  7546. for (let i = 0; i < addedCount; i++) {
  7547. object[index + i] = map.get(added[i]);
  7548. }
  7549. const removed = {};
  7550. removed.length = removedLen;
  7551.  
  7552. return { index, removed, object, addedCount }
  7553. })
  7554. };
  7555. map.clear();
  7556.  
  7557.  
  7558. this.__lat457__ = this.__lat457__ || new Set();
  7559. if(!container[wk]) container[wk] = mWeakRef(container);
  7560. this.__lat457__.add(container[wk]);
  7561. fixContainerApi(container);
  7562.  
  7563. // console.log(3882, indexSplicesObj_)
  7564. // let q = this.deferredBindingTasks_;
  7565. // this.deferredBindingTasks_ = [];
  7566. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7567. let e_;
  7568. try {
  7569. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  7570. } catch (e) { e_ = e; }
  7571. this.__qsd477__ = false;
  7572. indexSplicesObj_ = null;
  7573. stampKey = indexSplicesObj_ = null;
  7574. fixContainerApi(container);
  7575. // this.deferredBindingTasks_ = q;
  7576. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7577. if (!e_) {
  7578. // container.setAttribute('ytx-flushing', '0');
  7579. }
  7580.  
  7581.  
  7582. });
  7583. this[`__$$stampSqq$$#${containerId}__`] = f;
  7584. useMicroTaskQueue2 ? addTask2(f) : f();
  7585. executeTasks();
  7586.  
  7587. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  7588.  
  7589. return undefined;
  7590.  
  7591. }
  7592.  
  7593.  
  7594. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  7595. const dt0 = dt0a[0];
  7596. const dt1 = Date.now();
  7597. const obj = kRef(objWr);
  7598. if (!obj) return;
  7599. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7600. if (xxx !== xxx_) return;
  7601. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7602. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7603. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7604. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7605. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7606. const renderJob1 = obj.renderJobsMap_[containerId]
  7607. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  7608. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7609. let e_, r;
  7610. try {
  7611. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7612. } catch (e) {
  7613. e_ = e;
  7614. }
  7615. obj[`__quu477#${containerId}__`] = false;
  7616. if (e_) throw e_;
  7617. return r;
  7618. };
  7619.  
  7620.  
  7621. stampDomArray_.bind = function (obj, ...args) {
  7622. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7623. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7624. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7625. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  7626. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  7627. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7628. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7629. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7630. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7631.  
  7632.  
  7633. const renderJob = obj.renderJobsMap_[containerId];
  7634.  
  7635. const dt0a = [Date.now()];
  7636. queueMicrotask_(() => { dt0a[0] = 0 });
  7637. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  7638. };
  7639.  
  7640. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  7641. const dt0 = dt0a[0];
  7642. const dt1 = Date.now();
  7643. const obj = kRef(objWr);
  7644. if (!obj) return;
  7645. const renderJob1 = obj.renderJobsMap_[containerId];
  7646. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7647. let e_, r;
  7648. try {
  7649. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  7650. } catch (e) {
  7651. e_ = e;
  7652. }
  7653. obj[`__quu477#${containerId}__`] = false;
  7654. if (e_) throw e_;
  7655. return r;
  7656. };
  7657.  
  7658.  
  7659. stampDomArraySplices_.bind = function (obj, ...args) {
  7660. let [stampKey, containerId, indexSplicesObj] = args;
  7661. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7662.  
  7663. const renderJob = obj.renderJobsMap_[containerId];
  7664.  
  7665. const dt0a = [Date.now()];
  7666. queueMicrotask_(() => { dt0a[0] = 0 });
  7667. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  7668. };
  7669.  
  7670. const flushRenderStamperComponentBindings7419_ = function () {
  7671. const tasks = this.deferredBindingTasks_;
  7672. if (!(tasks || 0).length) return;
  7673. const hostElement = this.hostElement;
  7674. if ((hostElement instanceof Node) && hostElement.nodeType === 1) {
  7675. if (hostElement.isConnected === true) {
  7676. this.flushRenderStamperComponentBindings7409_();
  7677. }
  7678. } else if (hostElement) {
  7679. console.log('flushRenderStamperComponentBindings7419_ 002')
  7680. this.flushRenderStamperComponentBindings7409_();
  7681. } else {
  7682. console.log('flushRenderStamperComponentBindings7419_ 003')
  7683. tasks.length = 0;
  7684. }
  7685. }
  7686.  
  7687. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ , flushRenderStamperComponentBindings7419_};
  7688.  
  7689. }
  7690.  
  7691. const setupDiscreteTasks = (h, rb) => {
  7692.  
  7693. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7694. const f = h.onYtRendererstamperFinished;
  7695. const g = ump3.get(f) || function () {
  7696. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7697. return f.apply(this, arguments);
  7698. }
  7699. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7700. }
  7701. ump3.set(f, g);
  7702. g.km34 = 1;
  7703. h.onYtRendererstamperFinished = g;
  7704.  
  7705. }
  7706.  
  7707. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7708. const f = h.onYtUpdateDescriptionAction;
  7709. const g = ump3.get(f) || function (a) {
  7710. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7711. }
  7712. ump3.set(f, g);
  7713. g.km34 = 1;
  7714. h.onYtUpdateDescriptionAction = g;
  7715.  
  7716. }
  7717.  
  7718. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7719. const f = h.handleUpdateDescriptionAction;
  7720. const g = ump3.get(f) || function (a) {
  7721. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7722. }
  7723. ump3.set(f, g);
  7724. g.km34 = 1;
  7725. h.handleUpdateDescriptionAction = g;
  7726.  
  7727. }
  7728.  
  7729. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7730. const f = h.handleUpdateLiveChatPollAction;
  7731. const g = ump3.get(f) || function (a) {
  7732. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7733. }
  7734. ump3.set(f, g);
  7735. g.km34 = 1;
  7736. h.handleUpdateLiveChatPollAction = g;
  7737.  
  7738. }
  7739.  
  7740. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  7741. const f = h.onTextChanged;
  7742. const g = ump3.get(f) || function () {
  7743. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7744. }
  7745. ump3.set(f, g);
  7746. g.km34 = 1;
  7747. h.onTextChanged = g;
  7748.  
  7749. }
  7750.  
  7751. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  7752. const f = h.onVideoDataChange;
  7753. const g = ump3.get(f) || function (a) {
  7754. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7755. }
  7756. ump3.set(f, g);
  7757. g.km34 = 1;
  7758. h.onVideoDataChange = g;
  7759.  
  7760. }
  7761.  
  7762. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  7763. const f = h.onVideoDataChange_;
  7764. const g = ump3.get(f) || function () {
  7765. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7766. }
  7767. ump3.set(f, g);
  7768. g.km34 = 1;
  7769. h.onVideoDataChange_ = g;
  7770.  
  7771. }
  7772.  
  7773. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  7774.  
  7775. const f = h.addTooltips_;
  7776. const g = ump3.get(f) || function () {
  7777. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7778. }
  7779. ump3.set(f, g);
  7780. g.km34 = 1;
  7781. h.addTooltips_ = g;
  7782.  
  7783. }
  7784.  
  7785. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  7786.  
  7787. const f = h.updateRenderedElements;
  7788. const g = ump3.get(f) || function () {
  7789. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7790. }
  7791. ump3.set(f, g);
  7792. g.km34 = 1;
  7793. h.updateRenderedElements = g;
  7794.  
  7795. }
  7796.  
  7797. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  7798. const f = h.loadPage_;
  7799. const g = ump3.get(f) || function (a) {
  7800. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7801. }
  7802. ump3.set(f, g);
  7803. g.km34 = 1;
  7804. h.loadPage_ = g;
  7805.  
  7806. }
  7807. // updatePageData_ : possible conflict with Omit ShadyDOM
  7808. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  7809. const f = h.updatePageData_;
  7810. const g = ump3.get(f) || function (a) {
  7811. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7812. }
  7813. ump3.set(f, g);
  7814. g.km34 = 1;
  7815. h.updatePageData_ = g;
  7816.  
  7817. }
  7818.  
  7819.  
  7820. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  7821.  
  7822. const f = h.onFocus_;
  7823. const g = ump3.get(f) || function () {
  7824. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7825. }
  7826. ump3.set(f, g);
  7827. g.km34 = 1;
  7828. h.onFocus_ = g;
  7829.  
  7830. }
  7831.  
  7832. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  7833.  
  7834. const f = h.onBlur_;
  7835. const g = ump3.get(f) || function () {
  7836. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7837. }
  7838. ump3.set(f, g);
  7839. g.km34 = 1;
  7840. h.onBlur_ = g;
  7841.  
  7842. }
  7843.  
  7844.  
  7845. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  7846.  
  7847. const f = h.buttonClassChanged_;
  7848. const g = ump3.get(f) || function (a, b) {
  7849. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7850. }
  7851. ump3.set(f, g);
  7852. g.km34 = 1;
  7853. h.buttonClassChanged_ = g;
  7854.  
  7855. }
  7856.  
  7857. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  7858.  
  7859. const f = h.buttonIconChanged_;
  7860. const g = ump3.get(f) || function (a) {
  7861. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7862. }
  7863. ump3.set(f, g);
  7864. g.km34 = 1;
  7865. h.buttonIconChanged_ = g;
  7866.  
  7867. }
  7868.  
  7869. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  7870.  
  7871. const f = h.dataChangedInBehavior_;
  7872. const g = ump3.get(f) || function () {
  7873. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7874. }
  7875. ump3.set(f, g);
  7876. g.km34 = 1;
  7877. h.dataChangedInBehavior_ = g;
  7878.  
  7879. }
  7880.  
  7881. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  7882.  
  7883. const f = h.continuationsChanged_;
  7884. const g = ump3.get(f) || function () {
  7885. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7886. }
  7887. ump3.set(f, g);
  7888. g.km34 = 1;
  7889. h.continuationsChanged_ = g;
  7890.  
  7891. }
  7892.  
  7893.  
  7894. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  7895.  
  7896. const f = h.forceChatPoll_;
  7897. const g = ump3.get(f) || function (a) {
  7898. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7899. }
  7900. ump3.set(f, g);
  7901. g.km34 = 1;
  7902. h.forceChatPoll_ = g;
  7903.  
  7904. }
  7905.  
  7906. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  7907.  
  7908. const f = h.onEndpointClick_;
  7909. const g = ump3.get(f) || function (a) {
  7910. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7911. }
  7912. ump3.set(f, g);
  7913. g.km34 = 1;
  7914. h.onEndpointClick_ = g;
  7915.  
  7916. }
  7917.  
  7918. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  7919.  
  7920. const f = h.onEndpointTap_;
  7921. const g = ump3.get(f) || function (a) {
  7922. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7923. }
  7924. ump3.set(f, g);
  7925. g.km34 = 1;
  7926. h.onEndpointTap_ = g;
  7927.  
  7928. }
  7929.  
  7930. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  7931.  
  7932. const f = h.handleClick_;
  7933. const g = ump3.get(f) || function (a, b) {
  7934. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7935. }
  7936. ump3.set(f, g);
  7937. g.km34 = 1;
  7938. h.handleClick_ = g;
  7939.  
  7940. }
  7941.  
  7942. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  7943.  
  7944. const f = h.onReadyStateChange_;
  7945. const g = ump3.get(f) || function () {
  7946. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7947. }
  7948. ump3.set(f, g);
  7949. g.km34 = 1;
  7950. h.onReadyStateChange_ = g;
  7951.  
  7952. }
  7953.  
  7954. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  7955.  
  7956. const f = h.onReadyStateChangeEntryPoint_;
  7957. const g = ump3.get(f) || function () {
  7958. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7959. }
  7960. ump3.set(f, g);
  7961. g.km34 = 1;
  7962. h.onReadyStateChangeEntryPoint_ = g;
  7963.  
  7964. }
  7965.  
  7966. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  7967.  
  7968. const f = h.readyStateChangeHandler_;
  7969. const g = ump3.get(f) || function (a) {
  7970. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7971. }
  7972. ump3.set(f, g);
  7973. g.km34 = 1;
  7974. h.readyStateChangeHandler_ = g;
  7975.  
  7976. }
  7977.  
  7978. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  7979.  
  7980. const f = h.xmlHttpHandler_;
  7981. const g = ump3.get(f) || function (a) {
  7982. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7983. }
  7984. ump3.set(f, g);
  7985. g.km34 = 1;
  7986. h.xmlHttpHandler_ = g;
  7987.  
  7988. }
  7989.  
  7990. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  7991.  
  7992. const f = h.executeCallbacks_; // overloaded
  7993. const g = ump3.get(f) || function (a) {
  7994. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7995. }
  7996. ump3.set(f, g);
  7997. g.km34 = 1;
  7998. h.executeCallbacks_ = g;
  7999.  
  8000. }
  8001.  
  8002. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  8003.  
  8004. const f = h.handleInvalidationData_;
  8005. const g = ump3.get(f) || function (a, b) {
  8006. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8007. }
  8008. ump3.set(f, g);
  8009. g.km34 = 1;
  8010. h.handleInvalidationData_ = g;
  8011.  
  8012. }
  8013.  
  8014. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  8015.  
  8016. const f = h.onInput_;
  8017. const g = ump3.get(f) || function () {
  8018. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8019. }
  8020. ump3.set(f, g);
  8021. g.km34 = 1;
  8022. h.onInput_ = g;
  8023.  
  8024. }
  8025. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  8026.  
  8027. const f = h.trigger_;
  8028. const g = ump3.get(f) || function (a) {
  8029. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8030. }
  8031. ump3.set(f, g);
  8032. g.km34 = 1;
  8033. h.trigger_ = g;
  8034.  
  8035. }
  8036.  
  8037. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  8038.  
  8039. const f = h.requestData_;
  8040. const g = ump3.get(f) || function (a) {
  8041. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8042. }
  8043. ump3.set(f, g);
  8044. g.km34 = 1;
  8045. h.requestData_ = g;
  8046.  
  8047. }
  8048.  
  8049. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  8050.  
  8051. const f = h.onLoadReloadContinuation_;
  8052. const g = ump3.get(f) || function (a, b) {
  8053. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8054. }
  8055. ump3.set(f, g);
  8056. g.km34 = 1;
  8057. h.onLoadReloadContinuation_ = g;
  8058.  
  8059. }
  8060.  
  8061. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  8062.  
  8063. const f = h.onLoadIncrementalContinuation_;
  8064. const g = ump3.get(f) || function (a, b) {
  8065. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8066. }
  8067. ump3.set(f, g);
  8068. g.km34 = 1;
  8069. h.onLoadIncrementalContinuation_ = g;
  8070.  
  8071. }
  8072.  
  8073. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  8074.  
  8075. const f = h.onLoadSeekContinuation_;
  8076. const g = ump3.get(f) || function (a, b) {
  8077. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8078. }
  8079. ump3.set(f, g);
  8080. g.km34 = 1;
  8081. h.onLoadSeekContinuation_ = g;
  8082.  
  8083. }
  8084. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  8085.  
  8086. const f = h.onLoadReplayContinuation_;
  8087. const g = ump3.get(f) || function (a, b) {
  8088. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8089. }
  8090. ump3.set(f, g);
  8091. g.km34 = 1;
  8092. h.onLoadReplayContinuation_ = g;
  8093.  
  8094. }
  8095. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  8096.  
  8097. const f = h.onNavigate_;
  8098. const g = ump3.get(f) || function (a) {
  8099. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8100. }
  8101. ump3.set(f, g);
  8102. g.km34 = 1;
  8103. h.onNavigate_ = g;
  8104.  
  8105. }
  8106.  
  8107. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  8108.  
  8109. const f = h.ytRendererBehaviorDataObserver_;
  8110. const g = ump3.get(f) || function () {
  8111. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8112. }
  8113. ump3.set(f, g);
  8114. g.km34 = 1;
  8115. h.ytRendererBehaviorDataObserver_ = g;
  8116.  
  8117. }
  8118.  
  8119. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  8120.  
  8121. const f = h.ytRendererBehaviorTargetIdObserver_;
  8122. const g = ump3.get(f) || function () {
  8123. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8124. }
  8125. ump3.set(f, g);
  8126. g.km34 = 1;
  8127. h.ytRendererBehaviorTargetIdObserver_ = g;
  8128.  
  8129. }
  8130.  
  8131. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  8132.  
  8133. const f = h.unregisterRenderer_;
  8134. const g = ump3.get(f) || function (a) {
  8135. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8136. }
  8137. ump3.set(f, g);
  8138. g.km34 = 1;
  8139. h.unregisterRenderer_ = g;
  8140.  
  8141. }
  8142.  
  8143. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  8144.  
  8145. const f = h.textChanged_;
  8146. const g = ump3.get(f) || function (a) {
  8147. if (void 0 !== this.isAttached) {
  8148. const hostElement = this.hostElement;
  8149. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  8150. return;
  8151. }
  8152. }
  8153. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8154. }
  8155. ump3.set(f, g);
  8156. g.km34 = 1;
  8157. h.textChanged_ = g;
  8158.  
  8159. }
  8160.  
  8161.  
  8162.  
  8163. /**
  8164. *
  8165. * Neglect following
  8166. *
  8167. * h.onYtAction_
  8168. * h.startLoadingWatch [ buggy for yt-player-updated ]
  8169. * h.deferRenderStamperBinding_
  8170. *
  8171. * h.stampDomArray_
  8172. * h.stampDomArraySplices_
  8173. *
  8174. */
  8175.  
  8176.  
  8177. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  8178. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  8179. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  8180. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  8181. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  8182. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  8183.  
  8184. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  8185.  
  8186. const f = h.searchChanged_;
  8187. const g = ump3.get(f) || function () {
  8188. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8189. }
  8190. ump3.set(f, g);
  8191. g.km34 = 1;
  8192. h.searchChanged_ = g;
  8193.  
  8194. }
  8195.  
  8196. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  8197.  
  8198. const f = h.skinToneChanged_;
  8199. const g = ump3.get(f) || function (a) {
  8200. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8201. }
  8202. ump3.set(f, g);
  8203. g.km34 = 1;
  8204. h.skinToneChanged_ = g;
  8205.  
  8206. }
  8207.  
  8208. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  8209.  
  8210. const f = h.onEmojiHover_;
  8211. const g = ump3.get(f) || function (a) {
  8212. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8213. }
  8214. ump3.set(f, g);
  8215. g.km34 = 1;
  8216. h.onEmojiHover_ = g;
  8217.  
  8218. }
  8219.  
  8220. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  8221.  
  8222. const f = h.onSelectCategory_;
  8223. const g = ump3.get(f) || function (a) {
  8224. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8225. }
  8226. ump3.set(f, g);
  8227. g.km34 = 1;
  8228. h.onSelectCategory_ = g;
  8229.  
  8230. }
  8231.  
  8232. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  8233.  
  8234. const f = h.onShowEmojiVariantSelector;
  8235. const g = ump3.get(f) || function (a) {
  8236. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8237. }
  8238. ump3.set(f, g);
  8239. g.km34 = 1;
  8240. h.onShowEmojiVariantSelector = g;
  8241.  
  8242. }
  8243.  
  8244. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  8245.  
  8246. const f = h.updateCategoriesAndPlaceholder_;
  8247. const g = ump3.get(f) || function () {
  8248. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8249. }
  8250. ump3.set(f, g);
  8251. g.km34 = 1;
  8252. h.updateCategoriesAndPlaceholder_ = g;
  8253.  
  8254. }
  8255.  
  8256. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  8257.  
  8258. const f = h.watchPageActiveChanged_;
  8259. const g = ump3.get(f) || function () {
  8260. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8261. }
  8262. ump3.set(f, g);
  8263. g.km34 = 1;
  8264. h.watchPageActiveChanged_ = g;
  8265.  
  8266. }
  8267.  
  8268. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  8269.  
  8270. const f = h.activate_;
  8271. const g = ump3.get(f) || function () {
  8272. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8273. }
  8274. ump3.set(f, g);
  8275. g.km34 = 1;
  8276. h.activate_ = g;
  8277.  
  8278. }
  8279. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  8280.  
  8281. const f = h.onYtPlaylistDataUpdated_;
  8282. const g = ump3.get(f) || function () {
  8283. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8284. }
  8285. ump3.set(f, g);
  8286. g.km34 = 1;
  8287. h.onYtPlaylistDataUpdated_ = g;
  8288.  
  8289. }
  8290.  
  8291.  
  8292.  
  8293. /**
  8294. *
  8295. * Neglect following
  8296. *
  8297. * h.rendererStamperObserver_
  8298. * h.rendererStamperApplyChangeRecord_
  8299. * h.flushRenderStamperComponentBindings_
  8300. * h.forwardRendererStamperChanges_
  8301. *
  8302. */
  8303.  
  8304. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  8305.  
  8306. const f = h.tryRenderChunk_;
  8307. const g = ump3.get(f) || function () {
  8308. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8309. }
  8310. ump3.set(f, g);
  8311. g.km34 = 1;
  8312. h.tryRenderChunk_ = g;
  8313.  
  8314. }
  8315.  
  8316.  
  8317. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  8318.  
  8319. const f = h.renderChunk_;
  8320. const g = ump3.get(f) || function () {
  8321. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8322. }
  8323. ump3.set(f, g);
  8324. g.km34 = 1;
  8325. h.renderChunk_ = g;
  8326.  
  8327. }
  8328.  
  8329. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  8330.  
  8331. const f = h.deepLazyListObserver_;
  8332. const g = ump3.get(f) || function () {
  8333. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8334. }
  8335. ump3.set(f, g);
  8336. g.km34 = 1;
  8337. h.deepLazyListObserver_ = g;
  8338.  
  8339. }
  8340.  
  8341. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  8342.  
  8343. const f = h.onItemsUpdated_;
  8344. const g = ump3.get(f) || function () {
  8345. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8346. }
  8347. ump3.set(f, g);
  8348. g.km34 = 1;
  8349. h.onItemsUpdated_ = g;
  8350.  
  8351. }
  8352.  
  8353. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  8354.  
  8355. const f = h.requestRenderChunk_;
  8356. const g = ump3.get(f) || function () {
  8357. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8358. }
  8359. ump3.set(f, g);
  8360. g.km34 = 1;
  8361. h.requestRenderChunk_ = g;
  8362.  
  8363. }
  8364.  
  8365. /**
  8366. *
  8367. * Neglect following
  8368. *
  8369. * h.dataChanged_ [ buggy for page swtiching ]
  8370. *
  8371. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  8372. *
  8373. * h.cancelPendingTasks_
  8374. * h.fillRange_
  8375. * h.addTextNodes_
  8376. * h.updateText_
  8377. * h.stampTypeChanged_
  8378. *
  8379. */
  8380.  
  8381.  
  8382. }
  8383.  
  8384. const keyStConnectedCallback = Symbol(); // avoid copying the value
  8385.  
  8386. const dmf = new WeakMap();
  8387.  
  8388.  
  8389. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  8390.  
  8391. try {
  8392.  
  8393. const q = document.createElement('template');
  8394. q.innerHTML = '<ytz-null361></ytz-null361>';
  8395. nativeHTMLElement = q.content.firstChild.constructor
  8396.  
  8397. } catch (e) { }
  8398.  
  8399. if (!nativeHTMLElement.prototype.connectedCallback) {
  8400. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  8401. nativeHTMLElement.prototype.connectedCallback = function () {
  8402. let r;
  8403. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  8404. return r;
  8405. }
  8406. }
  8407. const pvr = Symbol()
  8408.  
  8409. let stampDomArrayFnStore = null;
  8410. const setupMap = new WeakSet();
  8411. const setupYtComponent = (cnt) => {
  8412. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  8413. if (!cProto || setupMap.has(cProto)) return;
  8414. setupMap.add(cProto);
  8415. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  8416. cProto[pvr] |= 1;
  8417.  
  8418.  
  8419.  
  8420. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  8421. const b = cProto.stampDomArray_.length === 6
  8422. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  8423. && cProto.createComponent_ && cProto.createComponent_.length === 3
  8424. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  8425. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  8426. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  8427. if (!b) {
  8428. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  8429. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  8430. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  8431. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_, flushRenderStamperComponentBindings7419_} = stampDomArrayFnStore;
  8432.  
  8433. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  8434. cProto.createComponent7409_ = cProto.createComponent_;
  8435. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  8436. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  8437. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  8438. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  8439.  
  8440. cProto.getStampContainer_ = getStampContainer_;
  8441. cProto.createComponent_ = createComponent_;
  8442. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  8443. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  8444. cProto.stampDomArray_ = stampDomArray_;
  8445. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  8446. cProto.flushRenderStamperComponentBindings7419_ = flushRenderStamperComponentBindings7419_;
  8447.  
  8448. }
  8449. }
  8450.  
  8451.  
  8452.  
  8453.  
  8454. // if(false && cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  8455. // cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  8456.  
  8457. // if(cProto._runEffectsForTemplate6344.length === 4){
  8458.  
  8459. // cProto._runEffectsForTemplate = function (c, d, e, g) {
  8460. // const cnt = this;
  8461. // const { propertyEffects, nodeList, firstChild } = c;
  8462. // cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  8463.  
  8464. // }
  8465.  
  8466. // }
  8467.  
  8468. // }
  8469.  
  8470. }
  8471. };
  8472.  
  8473. (FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  8474. get() {
  8475. const f = this[keyStConnectedCallback];
  8476. if (this.is) {
  8477. setupYtComponent(this);
  8478. }
  8479. return f;
  8480. },
  8481. set(nv) {
  8482. let gv = nv;
  8483. this[keyStConnectedCallback] = gv; // proto or object
  8484. return true;
  8485. },
  8486. enumerable: false,
  8487. configurable: true
  8488.  
  8489. });
  8490.  
  8491. const pLoad = new Promise(resolve => {
  8492. if (document.readyState !== 'loading') {
  8493. resolve();
  8494. } else {
  8495. window.addEventListener("DOMContentLoaded", resolve, false);
  8496. }
  8497. });
  8498.  
  8499. if (FIX_ACTIONS_TOOLTIPS) {
  8500. pLoad.then(() => {
  8501. addNewCSS("#actions .tp-yt-paper-tooltip{white-space:nowrap}");
  8502. });
  8503. }
  8504.  
  8505. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  8506. window.requestIdleCallback471 = window.requestIdleCallback;
  8507. window.requestIdleCallback = function (f, ...args) {
  8508. return (this || window).requestIdleCallback471(async function () {
  8509. await pLoad.then();
  8510. // await new Promise(nextBrowserTick_);
  8511. f.call(this, ...arguments)
  8512. }, ...args);
  8513. }
  8514. }
  8515.  
  8516. pLoad.then(() => {
  8517.  
  8518. let nonce = document.querySelector('style[nonce]');
  8519. nonce = nonce ? nonce.getAttribute('nonce') : null;
  8520. const st = document.createElement('style');
  8521. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  8522. st.textContent = "none-element-k47{order:0}";
  8523. st.addEventListener('load', () => {
  8524. pf31.resolve();
  8525. p59 = 1;
  8526. }, false);
  8527. (document.body || document.head || document.documentElement).appendChild(st);
  8528.  
  8529. });
  8530.  
  8531. const prepareLogs = [];
  8532.  
  8533. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  8534.  
  8535. let winError00 = window.onerror;
  8536.  
  8537. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  8538.  
  8539. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  8540.  
  8541. ; fix_error_many_stack_state === 1 && (() => {
  8542.  
  8543.  
  8544. let p1 = winError00;
  8545.  
  8546. let stackNeedleDetails = null;
  8547.  
  8548. Object.defineProperty(Object.prototype, 'matchAll', {
  8549. get() {
  8550. stackNeedleDetails = this;
  8551. return true;
  8552. },
  8553. enumerable: true,
  8554. configurable: true
  8555. });
  8556.  
  8557. try {
  8558. JSON.parse("{}");
  8559. } catch (e) {
  8560. console.warn(e)
  8561. fix_error_many_stack_state = 0;
  8562. }
  8563.  
  8564. delete Object.prototype['matchAll'];
  8565.  
  8566. let p2 = window.onerror;
  8567.  
  8568. window.onerror = p1;
  8569.  
  8570. if (fix_error_many_stack_state === 0) return;
  8571.  
  8572. if (stackNeedleDetails) {
  8573. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8574. stackNeedleDetails.matchAll = true;
  8575. }
  8576.  
  8577. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8578.  
  8579. // p1!==p2
  8580. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8581.  
  8582. })();
  8583.  
  8584. ; fix_error_many_stack_state === 2 && (() => {
  8585.  
  8586.  
  8587. let p1 = winError00;
  8588.  
  8589. let objectPrune = null;
  8590. let stackNeedleDetails = null;
  8591.  
  8592. Object.defineProperty(Function.prototype, 'findOwner', {
  8593. get() {
  8594. objectPrune = this;
  8595. return this._findOwner;
  8596. },
  8597. set(nv) {
  8598. this._findOwner = nv;
  8599. return true;
  8600. },
  8601. enumerable: true,
  8602. configurable: true
  8603. });
  8604.  
  8605. Object.defineProperty(Object.prototype, 'matchAll', {
  8606. get() {
  8607. stackNeedleDetails = this;
  8608. return true;
  8609. },
  8610. enumerable: true,
  8611. configurable: true
  8612. });
  8613.  
  8614. try {
  8615. JSON.parse("{}");
  8616. } catch (e) {
  8617. console.warn(e)
  8618. fix_error_many_stack_state = 0;
  8619. }
  8620.  
  8621. delete Function.prototype['findOwner'];
  8622. delete Object.prototype['matchAll'];
  8623.  
  8624. let p2 = window.onerror;
  8625.  
  8626. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8627.  
  8628. if (fix_error_many_stack_state == 0) return;
  8629.  
  8630. // the following will only execute when Brave's scriptlets.js is executed.
  8631.  
  8632. prepareLogs.push("fix_error_many_stack_state NB")
  8633.  
  8634. if (stackNeedleDetails) {
  8635. stackNeedleDetails.pattern = null;
  8636. stackNeedleDetails.re = null;
  8637. stackNeedleDetails.expect = null;
  8638. stackNeedleDetails.matchAll = true;
  8639. }
  8640.  
  8641. if (objectPrune) {
  8642. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8643. delete objectPrune._findOwner;
  8644. }
  8645.  
  8646. fix_error_many_stack_state = 3;
  8647. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8648. JSON.parse.objectPrune = objectPrune;
  8649.  
  8650. })();
  8651.  
  8652. ; fix_error_many_stack_state === 3 && (() => {
  8653.  
  8654.  
  8655. let p1 = winError00;
  8656.  
  8657. try {
  8658. JSON.parse("{}");
  8659. } catch (e) {
  8660. console.warn(e)
  8661. fix_error_many_stack_state = 0;
  8662. }
  8663.  
  8664. let p2 = window.onerror;
  8665.  
  8666. if (p1 === p2) return;
  8667.  
  8668. window.onerror = p1;
  8669.  
  8670. if (fix_error_many_stack_state === 0) return;
  8671.  
  8672. fix_error_many_stack_state = 4; // p1 != p2
  8673.  
  8674.  
  8675. })();
  8676.  
  8677. fix_error_many_stack_state === 4 && (() => {
  8678.  
  8679. // the following will only execute when Brave's scriptlets.js is executed.
  8680.  
  8681. prepareLogs.push("fix_error_many_stack_state AB")
  8682.  
  8683. JSON.parseProxy = JSON.parse;
  8684.  
  8685. JSON.parse = ((parse) => {
  8686.  
  8687. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8688. return function (text, reviver) {
  8689. const onerror = window.onerror;
  8690. window.onerror = null;
  8691. let r;
  8692. try {
  8693. r = parse(...arguments);
  8694. } catch (e) {
  8695. r = e;
  8696. }
  8697. window.onerror = onerror;
  8698. if (r instanceof Error) {
  8699. throw r;
  8700. }
  8701. return r;
  8702. }
  8703.  
  8704. })(JSON.parse);
  8705.  
  8706.  
  8707. })();
  8708.  
  8709.  
  8710. // << if FIX_yt_player >>
  8711.  
  8712. // credit to @nopeless (https://gf.qytechs.cn/scripts/471489-youtube-player-perf/)
  8713. const PERF_471489_ = true;
  8714. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8715. // This script uses a much gentle way to tamer the JS engine instead.
  8716.  
  8717. // << end >>
  8718.  
  8719. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8720.  
  8721.  
  8722.  
  8723. const nilFn = () => { };
  8724.  
  8725. let isMainWindow = false;
  8726. try {
  8727. isMainWindow = window.document === window.top.document
  8728. } catch (e) { }
  8729.  
  8730. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  8731. let headLinkCollection = null;
  8732.  
  8733.  
  8734. // const assertor = (f) => f() || console.assert(false, `${f}`);
  8735.  
  8736. const fnIntegrity = (f, d) => {
  8737. if (!f || typeof f !== 'function') {
  8738. console.warn('f is not a function', f);
  8739. return;
  8740. }
  8741. let p = `${f}`, s = 0, j = -1, w = 0;
  8742. for (let i = 0, l = p.length; i < l; i++) {
  8743. const t = p[i];
  8744. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8745. if (j < i - 1) w++;
  8746. j = i;
  8747. } else {
  8748. s++;
  8749. }
  8750. }
  8751. let itz = `${f.length}.${s}.${w}`;
  8752. if (!d) {
  8753. return itz;
  8754. } else {
  8755. return itz === d;
  8756. }
  8757. };
  8758.  
  8759. const getZqOu = (_yt_player) => {
  8760.  
  8761. const w = 'ZqOu';
  8762.  
  8763. let arr = [];
  8764.  
  8765. for (const [k, v] of Object.entries(_yt_player)) {
  8766.  
  8767. const p = typeof v === 'function' ? v.prototype : 0;
  8768. if (p
  8769. && typeof p.start === 'function' && p.start.length === 0 // Ou
  8770. && typeof p.isActive === 'function' && p.isActive.length === 0
  8771. && typeof p.stop === 'function' && p.stop.length === 0
  8772. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8773. && !p.send && !p.abort
  8774. && !p.sample && !p.initialize && !p.fail && !p.getName
  8775. // && !p.dispose && !p.isDisposed
  8776.  
  8777. ) {
  8778. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8779.  
  8780.  
  8781. }
  8782.  
  8783. }
  8784.  
  8785. if (arr.length === 0) {
  8786.  
  8787. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8788. } else {
  8789.  
  8790. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8791. return arr[0];
  8792. }
  8793.  
  8794. }
  8795.  
  8796. const getZqQu = (_yt_player) => {
  8797.  
  8798. const w = 'ZqQu';
  8799.  
  8800. let arr = [];
  8801.  
  8802.  
  8803. for (const [k, v] of Object.entries(_yt_player)) {
  8804.  
  8805. const p = typeof v === 'function' ? v.prototype : 0;
  8806. if (p
  8807. && typeof p.start === 'function' && p.start.length === 1 // Qu
  8808. && typeof p.isActive === 'function' && p.isActive.length === 0
  8809. && typeof p.stop === 'function' && p.stop.length === 0
  8810. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8811. && !p.send && !p.abort
  8812. && !p.sample && !p.initialize && !p.fail && !p.getName
  8813. // && !p.dispose && !p.isDisposed
  8814.  
  8815. ) {
  8816. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8817.  
  8818.  
  8819. }
  8820.  
  8821. }
  8822.  
  8823. if (arr.length === 0) {
  8824.  
  8825. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8826. } else {
  8827.  
  8828. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8829. return arr[0];
  8830. }
  8831.  
  8832. }
  8833.  
  8834.  
  8835. const getVG = (_yt_player) => {
  8836. const w = 'VG';
  8837.  
  8838. let arr = [];
  8839.  
  8840. for (const [k, v] of Object.entries(_yt_player)) {
  8841.  
  8842. const p = typeof v === 'function' ? v.prototype : 0;
  8843. if (p
  8844. && typeof p.show === 'function' && p.show.length === 1
  8845. && typeof p.hide === 'function' && p.hide.length === 0
  8846. && typeof p.stop === 'function' && p.stop.length === 0) {
  8847.  
  8848. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8849.  
  8850. }
  8851.  
  8852. }
  8853.  
  8854.  
  8855. if (arr.length === 0) {
  8856.  
  8857. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8858. } else {
  8859.  
  8860. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8861. return arr[0];
  8862. }
  8863.  
  8864.  
  8865.  
  8866. }
  8867.  
  8868.  
  8869. const getzo = (_yt_player) => {
  8870. const w = 'zo';
  8871.  
  8872. let arr = [];
  8873.  
  8874. for (const [k, v] of Object.entries(_yt_player)) {
  8875.  
  8876. if (
  8877. typeof v === 'function' && v.length === 3 && k.length < 3
  8878. ) {
  8879. const vt = `${v}`;
  8880. if (vt.length >= 21 && vt.includes(".style[")) {
  8881. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  8882. arr.push(k);
  8883. } else {
  8884. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  8885. }
  8886. }
  8887. }
  8888.  
  8889. }
  8890.  
  8891. if (arr.length === 0) {
  8892.  
  8893. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8894. } else {
  8895.  
  8896. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8897. return arr[0];
  8898. }
  8899.  
  8900. }
  8901.  
  8902. const addProtoToArr = (parent, key, arr) => {
  8903.  
  8904.  
  8905. let isChildProto = false;
  8906. for (const sr of arr) {
  8907. if (parent[key].prototype instanceof parent[sr]) {
  8908. isChildProto = true;
  8909. break;
  8910. }
  8911. }
  8912.  
  8913. if (isChildProto) return;
  8914.  
  8915. arr = arr.filter(sr => {
  8916. if (parent[sr].prototype instanceof parent[key]) {
  8917. return false;
  8918. }
  8919. return true;
  8920. });
  8921.  
  8922. arr.push(key);
  8923.  
  8924. return arr;
  8925.  
  8926.  
  8927. }
  8928.  
  8929. const getuG = (_yt_player) => {
  8930.  
  8931. const w = 'uG';
  8932.  
  8933. let arr = [];
  8934.  
  8935. for (const [k, v] of Object.entries(_yt_player)) {
  8936.  
  8937.  
  8938. const p = typeof v === 'function' ? v.prototype : 0;
  8939.  
  8940. if (p
  8941. && typeof p.createElement === 'function' && p.createElement.length === 2
  8942. && typeof p.detach === 'function' && p.detach.length === 0
  8943. && typeof p.update === 'function' && p.update.length === 1
  8944. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  8945. ) {
  8946.  
  8947. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8948.  
  8949. }
  8950.  
  8951. }
  8952.  
  8953.  
  8954.  
  8955.  
  8956.  
  8957. if (arr.length === 0) {
  8958.  
  8959. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8960. } else {
  8961.  
  8962. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8963. return arr[0];
  8964. }
  8965.  
  8966. }
  8967.  
  8968.  
  8969. const getQT = (_yt_player) => {
  8970. const w = 'QT';
  8971.  
  8972. let arr = [];
  8973. let brr = new Map();
  8974.  
  8975. for (const [k, v] of Object.entries(_yt_player)) {
  8976.  
  8977. const p = typeof v === 'function' ? v.prototype : 0;
  8978. if (p) {
  8979. let q = 0;
  8980. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8981. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8982. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8983.  
  8984. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8985.  
  8986. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8987.  
  8988. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8989. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8990. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8991. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8992.  
  8993.  
  8994. // differentiate QT and DX
  8995.  
  8996. q += 280;
  8997. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  8998. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  8999. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  9000. if (typeof p.seekBy === 'function') q += 4;
  9001. if (typeof p.seekTo === 'function') q += 4;
  9002. if (typeof p.getStoryboardFormat === 'function') q += 4;
  9003. if (typeof p.getDuration === 'function') q += 4;
  9004. if (typeof p.loadModule === 'function') q += 4;
  9005. if (typeof p.unloadModule === 'function') q += 4;
  9006. if (typeof p.getOption === 'function') q += 4;
  9007. if (typeof p.getOptions === 'function') q += 4;
  9008. if (typeof p.setOption === 'function') q += 4;
  9009. if (typeof p.addCueRange === 'function') q += 4;
  9010. if (typeof p.getDebugText === 'function') q += 4;
  9011. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  9012. if (typeof p.setSizeStyle === 'function') q += 4;
  9013. if (typeof p.showControls === 'function') q += 4;
  9014. if (typeof p.hideControls === 'function') q += 4;
  9015. if (typeof p.getVideoContentRect === 'function') q += 4;
  9016. if (typeof p.toggleFullscreen === 'function') q += 4;
  9017. if (typeof p.isFullscreen === 'function') q += 4;
  9018. if (typeof p.cancelPlayback === 'function') q += 4;
  9019. if (typeof p.getProgressState === 'function') q += 4;
  9020. if (typeof p.isInline === 'function') q += 4;
  9021. if (typeof p.setInline === 'function') q += 4;
  9022. if (typeof p.toggleSubtitles === 'function') q += 4;
  9023. if (typeof p.getPlayerSize === 'function') q += 4;
  9024. if (typeof p.wakeUpControls === 'function') q += 4;
  9025. if (typeof p.setCenterCrop === 'function') q += 4;
  9026. if (typeof p.getLoopVideo === 'function') q += 4;
  9027. if (typeof p.setLoopVideo === 'function') q += 4;
  9028.  
  9029.  
  9030. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9031.  
  9032. if (q > 0) brr.set(k, q);
  9033.  
  9034. }
  9035.  
  9036. }
  9037.  
  9038. if (arr.length === 0) {
  9039.  
  9040. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9041. } else {
  9042.  
  9043. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9044.  
  9045. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9046.  
  9047. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9048. return arr[0][0];
  9049. }
  9050.  
  9051.  
  9052.  
  9053. }
  9054.  
  9055.  
  9056.  
  9057. const getSV = (_yt_player) => {
  9058. const w = 'SV';
  9059.  
  9060. let arr = [];
  9061. let brr = new Map();
  9062.  
  9063. for (const [k, v] of Object.entries(_yt_player)) {
  9064.  
  9065. const p = typeof v === 'function' ? v.prototype : 0;
  9066. if (p) {
  9067. let q = 0;
  9068. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9069. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9070. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9071.  
  9072. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  9073.  
  9074. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9075.  
  9076. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9077. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9078. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9079. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9080.  
  9081.  
  9082. // differentiate QT and DX
  9083.  
  9084.  
  9085. q += 280;
  9086.  
  9087. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9088. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9089. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9090. if (typeof p.seekBy === 'function') q -= 4;
  9091. if (typeof p.seekTo === 'function') q -= 4;
  9092. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9093. if (typeof p.getDuration === 'function') q -= 4;
  9094. if (typeof p.loadModule === 'function') q -= 4;
  9095. if (typeof p.unloadModule === 'function') q -= 4;
  9096. if (typeof p.getOption === 'function') q -= 4;
  9097. if (typeof p.getOptions === 'function') q -= 4;
  9098. if (typeof p.setOption === 'function') q -= 4;
  9099. if (typeof p.addCueRange === 'function') q -= 4;
  9100. if (typeof p.getDebugText === 'function') q -= 4;
  9101. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9102. if (typeof p.setSizeStyle === 'function') q -= 4;
  9103. if (typeof p.showControls === 'function') q -= 4;
  9104. if (typeof p.hideControls === 'function') q -= 4;
  9105. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9106. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9107. if (typeof p.isFullscreen === 'function') q -= 4;
  9108. if (typeof p.cancelPlayback === 'function') q -= 4;
  9109. if (typeof p.getProgressState === 'function') q -= 4;
  9110. if (typeof p.isInline === 'function') q -= 4;
  9111. if (typeof p.setInline === 'function') q -= 4;
  9112. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9113. if (typeof p.getPlayerSize === 'function') q -= 4;
  9114. if (typeof p.wakeUpControls === 'function') q -= 4;
  9115. if (typeof p.setCenterCrop === 'function') q -= 4;
  9116. if (typeof p.getLoopVideo === 'function') q -= 4;
  9117. if (typeof p.setLoopVideo === 'function') q -= 4;
  9118.  
  9119.  
  9120. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9121.  
  9122. if (q > 0) brr.set(k, q);
  9123.  
  9124. }
  9125.  
  9126. }
  9127.  
  9128. if (arr.length === 0) {
  9129.  
  9130. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9131. } else {
  9132.  
  9133. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9134.  
  9135. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9136.  
  9137. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9138. return arr[0][0];
  9139. }
  9140.  
  9141.  
  9142.  
  9143. }
  9144.  
  9145.  
  9146.  
  9147.  
  9148. const getDX = (_yt_player) => {
  9149. const w = 'DX';
  9150.  
  9151. let arr = [];
  9152. let brr = new Map();
  9153.  
  9154. for (const [k, v] of Object.entries(_yt_player)) {
  9155.  
  9156. const p = typeof v === 'function' ? v.prototype : 0;
  9157. if (p) {
  9158. let q = 0;
  9159. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9160. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9161. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9162.  
  9163. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9164.  
  9165.  
  9166. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  9167.  
  9168. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9169.  
  9170. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9171. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9172. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9173. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9174.  
  9175.  
  9176. // differentiate QT and DX
  9177.  
  9178.  
  9179. q += 280;
  9180.  
  9181. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9182. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9183. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9184. if (typeof p.seekBy === 'function') q -= 4;
  9185. if (typeof p.seekTo === 'function') q -= 4;
  9186. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9187. if (typeof p.getDuration === 'function') q -= 4;
  9188. if (typeof p.loadModule === 'function') q -= 4;
  9189. if (typeof p.unloadModule === 'function') q -= 4;
  9190. if (typeof p.getOption === 'function') q -= 4;
  9191. if (typeof p.getOptions === 'function') q -= 4;
  9192. if (typeof p.setOption === 'function') q -= 4;
  9193. if (typeof p.addCueRange === 'function') q -= 4;
  9194. if (typeof p.getDebugText === 'function') q -= 4;
  9195. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9196. if (typeof p.setSizeStyle === 'function') q -= 4;
  9197. if (typeof p.showControls === 'function') q -= 4;
  9198. if (typeof p.hideControls === 'function') q -= 4;
  9199. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9200. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9201. if (typeof p.isFullscreen === 'function') q -= 4;
  9202. if (typeof p.cancelPlayback === 'function') q -= 4;
  9203. if (typeof p.getProgressState === 'function') q -= 4;
  9204. if (typeof p.isInline === 'function') q -= 4;
  9205. if (typeof p.setInline === 'function') q -= 4;
  9206. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9207. if (typeof p.getPlayerSize === 'function') q -= 4;
  9208. if (typeof p.wakeUpControls === 'function') q -= 4;
  9209. if (typeof p.setCenterCrop === 'function') q -= 4;
  9210. if (typeof p.getLoopVideo === 'function') q -= 4;
  9211. if (typeof p.setLoopVideo === 'function') q -= 4;
  9212.  
  9213.  
  9214. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9215.  
  9216. if (q > 0) brr.set(k, q);
  9217.  
  9218. }
  9219.  
  9220. }
  9221.  
  9222. if (arr.length === 0) {
  9223.  
  9224. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9225. } else {
  9226.  
  9227. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9228.  
  9229. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9230.  
  9231. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9232. return arr[0][0];
  9233. }
  9234.  
  9235.  
  9236.  
  9237. }
  9238.  
  9239.  
  9240.  
  9241. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  9242.  
  9243. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  9244. let pageSetupState = 0;
  9245.  
  9246. isPrepareCachedV && (() => {
  9247.  
  9248. pageSetupVideoId = '';
  9249. const clearCachedV = () => {
  9250. pageSetupVideoId = '';
  9251. pageSetupState = 0;
  9252. }
  9253. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  9254. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  9255. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  9256. document.addEventListener('yt-navigate-finish', () => {
  9257. pageSetupState = 1;
  9258. try {
  9259. const url = new URL(location.href);
  9260. if (!url || !isWatchPageURL(url)) {
  9261. pageSetupVideoId = '';
  9262. } else {
  9263. pageSetupVideoId = url.searchParams.get('v') || '';
  9264. }
  9265. } catch (e) {
  9266. pageSetupVideoId = '';
  9267. }
  9268. }, false);
  9269.  
  9270. })();
  9271.  
  9272. let videoPlayingY = null;
  9273.  
  9274. isPrepareCachedV && (() => {
  9275.  
  9276. let getNext = true;
  9277. let videoPlayingX = {
  9278. get videoId() {
  9279. if (getNext) {
  9280. getNext = false;
  9281.  
  9282. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  9283. const arr = [];
  9284. for (const element of elements) {
  9285. if (!element.closest('[hidden]')) arr.push(element);
  9286. }
  9287. if (arr.length !== 1) this.__videoId__ = '';
  9288. else {
  9289. this.__videoId__ = arr[0].getAttribute('video-id');
  9290. }
  9291.  
  9292. }
  9293. return this.__videoId__ || '';
  9294. }
  9295. }
  9296.  
  9297. videoPlayingY = videoPlayingX;
  9298. const handler = (evt) => {
  9299. const target = (evt || 0).target;
  9300. if (target instanceof HTMLVideoElement) {
  9301. getNext = true;
  9302. }
  9303. }
  9304. document.addEventListener('loadedmetadata', handler, true);
  9305. document.addEventListener('durationchange', handler, true);
  9306.  
  9307. })();
  9308.  
  9309.  
  9310.  
  9311. const cleanContext = async (win) => {
  9312. const waitFn = requestAnimationFrame; // shall have been binded to window
  9313. try {
  9314. let mx = 16; // MAX TRIAL
  9315. const frameId = 'vanillajs-iframe-v1';
  9316. /** @type {HTMLIFrameElement | null} */
  9317. let frame = document.getElementById(frameId);
  9318. let removeIframeFn = null;
  9319. if (!frame) {
  9320. frame = document.createElement('iframe');
  9321. frame.id = frameId;
  9322. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  9323. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  9324. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  9325. n.appendChild(frame);
  9326. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  9327. const root = document.documentElement;
  9328. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  9329. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  9330.  
  9331. removeIframeFn = (setTimeout) => {
  9332. const removeIframeOnDocumentReady = (e) => {
  9333. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9334. e = n;
  9335. n = win = removeIframeFn = 0;
  9336. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  9337. }
  9338. if (!setTimeout || document.readyState !== 'loading') {
  9339. removeIframeOnDocumentReady();
  9340. } else {
  9341. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9342. }
  9343. }
  9344. }
  9345. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  9346. const fc = frame.contentWindow;
  9347. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  9348. try {
  9349. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  9350. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  9351. for (let k in res) res[k] = res[k].bind(win); // necessary
  9352. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  9353. res.animate = fc.HTMLElement.prototype.animate;
  9354. res.perfNow = fc.performance.now;
  9355. return res;
  9356. } catch (e) {
  9357. if (removeIframeFn) removeIframeFn();
  9358. return null;
  9359. }
  9360. } catch (e) {
  9361. console.warn(e);
  9362. return null;
  9363. }
  9364. };
  9365.  
  9366. const promiseForYtActionCalled = new Promise(resolve => {
  9367.  
  9368. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9369. if (typeof AbortSignal !== 'undefined') {
  9370. let hn = () => {
  9371. if (!hn) return;
  9372. hn = null;
  9373. resolve(document.querySelector(appTag));
  9374. };
  9375. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  9376. } else {
  9377. let hn = () => {
  9378. if (!hn) return;
  9379. document.removeEventListener('yt-action', hn, true);
  9380. hn = null;
  9381. resolve(document.querySelector(appTag));
  9382. };
  9383. document.addEventListener('yt-action', hn, true);
  9384. }
  9385. });
  9386.  
  9387. cleanContext(window).then(__CONTEXT__ => {
  9388. if (!__CONTEXT__) return null;
  9389.  
  9390. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  9391.  
  9392.  
  9393. performance.now17 = perfNow.bind(performance);
  9394.  
  9395.  
  9396.  
  9397. __requestAnimationFrame__ = requestAnimationFrame;
  9398.  
  9399.  
  9400. const isGPUAccelerationAvailable = (() => {
  9401. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  9402. try {
  9403. const canvas = document.createElement('canvas');
  9404. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  9405. } catch (e) {
  9406. return false;
  9407. }
  9408. })();
  9409.  
  9410. const foregroundPromiseFn_noGPU = (() => {
  9411.  
  9412. if (isGPUAccelerationAvailable) return null;
  9413.  
  9414. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  9415. if (!pd || typeof pd.get !== 'function') return null;
  9416. const pdGet = pd.get;
  9417.  
  9418. let pr = null;
  9419.  
  9420. let hState = pdGet.call(document) === 'hidden';
  9421. // let cid = 0;
  9422. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  9423. const newHState = pdGet.call(document) === 'hidden';
  9424. if (hState !== newHState) {
  9425. // if (cid > 0) cid = clearInterval(cid);
  9426. hState = newHState;
  9427. if (!hState && pr) pr = pr.resolve();
  9428. }
  9429. });
  9430.  
  9431. // cid = setInterval(() => {
  9432. // const newHState = document.visibilityState === 'hidden';
  9433. // if (hState !== newHState) {
  9434. // hState = newHState;
  9435. // if (!hState && pr) pr = pr.resolve();
  9436. // }
  9437. // }, 100);
  9438.  
  9439.  
  9440. return (() => {
  9441. if (pr) return pr;
  9442. const w = ((!hState && setTimeout(() => {
  9443. if (!hState && pr === w) pr = pr.resolve();
  9444. })), (pr = new PromiseExternal()));
  9445. return w;
  9446. });
  9447.  
  9448. })();
  9449.  
  9450.  
  9451. let rafPromise = null;
  9452. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  9453. requestAnimationFrame(hRes => {
  9454. rafPromise = null;
  9455. resolve(hRes);
  9456. });
  9457. }));
  9458.  
  9459. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  9460.  
  9461.  
  9462. const wmComputedStyle = new WeakMap();
  9463.  
  9464. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  9465. window.__native__getComputedStyle__ = getComputedStyle;
  9466. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  9467. window.__original__getComputedStyle__ = window.getComputedStyle;
  9468. window.getComputedStyle = function (elem) {
  9469. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  9470. return window.__original__getComputedStyle__(...arguments);
  9471. }
  9472. let cs = wmComputedStyle.get(elem);
  9473. if (!cs) {
  9474. cs = window.__native__getComputedStyle__(elem);
  9475. wmComputedStyle.set(elem, cs);
  9476. }
  9477. return cs;
  9478. };
  9479. } else {
  9480. window.__original__getComputedStyle__ = null;
  9481. }
  9482. window.__jst__getComputedStyle__ = window.getComputedStyle;
  9483. }
  9484.  
  9485. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  9486. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  9487. window.getComputedStyle = window.__jst__getComputedStyle__;
  9488. }
  9489. });
  9490.  
  9491. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  9492. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  9493.  
  9494. const promiseForTamerTimeout = new Promise(resolve => {
  9495. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9496. setTimeout(resolve, 480);
  9497. }, { capture: true, passive: true, once: true });
  9498. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9499. setTimeout(resolve, 1200);
  9500. });
  9501. setTimeout(resolve, 3000);
  9502. });
  9503.  
  9504. const promiseForPageInitied = new Promise(resolve => {
  9505. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9506. setTimeout(resolve, 450);
  9507. }, { capture: true, passive: true, once: true });
  9508. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9509. setTimeout(resolve, 900);
  9510. });
  9511. setTimeout(resolve, 1800);
  9512. });
  9513.  
  9514. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  9515. NO_PRELOAD_GENERATE_204_BYPASS = true;
  9516. headLinkCollection = null;
  9517. });
  9518.  
  9519.  
  9520. NATIVE_CANVAS_ANIMATION && (() => {
  9521.  
  9522. observablePromise(() => {
  9523. HTMLCanvasElement.prototype.animate = animate;
  9524. }, promiseForTamerTimeout).obtain();
  9525.  
  9526. })();
  9527.  
  9528.  
  9529.  
  9530.  
  9531. FIX_ytAction_ && (async () => {
  9532.  
  9533. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9534.  
  9535. const ytdApp = await new Promise(resolve => {
  9536.  
  9537. whenCEDefined(appTag).then(() => {
  9538. const ytdApp = document.querySelector(appTag);
  9539. if (ytdApp) {
  9540. resolve(ytdApp);
  9541. return;
  9542. }
  9543. let mo = new MutationObserver(() => {
  9544. const ytdApp = document.querySelector(appTag);
  9545. if (!ytdApp) return;
  9546. if (mo) {
  9547. mo.disconnect();
  9548. mo.takeRecords();
  9549. mo = null;
  9550. }
  9551. resolve(ytdApp);
  9552. });
  9553. mo.observe(document, { subtree: true, childList: true });
  9554. });
  9555.  
  9556. });
  9557.  
  9558. if (!ytdApp) return;
  9559. const cProto = insp(ytdApp).constructor.prototype;
  9560.  
  9561. if (!cProto) return;
  9562. let mbd = 0;
  9563.  
  9564. const fixer = (_ytdApp) => {
  9565. const ytdApp = insp(_ytdApp);
  9566. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9567. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9568. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9569. mbd++;
  9570. }
  9571. }
  9572.  
  9573. observablePromise(() => {
  9574.  
  9575. if (typeof cProto.created === 'function' && !cProto.created56) {
  9576. cProto.created56 = cProto.created;
  9577. cProto.created = function (...args) {
  9578. const r = this.created56(...args);
  9579. fixer(this);
  9580. return r;
  9581. };
  9582. mbd++;
  9583. }
  9584.  
  9585. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9586. cProto.onYtAction57_ = cProto.onYtAction_;
  9587. cProto.onYtAction_ = function (...args) {
  9588. Promise.resolve().then(() => this.onYtAction57_(...args));
  9589. };
  9590. mbd++;
  9591. }
  9592.  
  9593. if (ytdApp) fixer(ytdApp);
  9594.  
  9595. /*
  9596. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9597. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9598. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9599. actionRouter_.handleAction = function (...args) {
  9600. Promise.resolve().then(() => this.handleAction57(...args));
  9601. }
  9602. mbd++;
  9603. }
  9604. */
  9605.  
  9606. // if(mbd === 3) return 1;
  9607. if (mbd >= 3) return 1;
  9608.  
  9609. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9610.  
  9611. })();
  9612.  
  9613.  
  9614. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9615.  
  9616. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9617.  
  9618. const app = await observablePromise(() => {
  9619.  
  9620. return document.querySelector(appTag);
  9621.  
  9622. }).obtain();
  9623.  
  9624. if (!app) return;
  9625.  
  9626. const appCnt = insp(app);
  9627. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9628.  
  9629.  
  9630.  
  9631.  
  9632. });
  9633.  
  9634.  
  9635. // let _yt_player_promise = null;
  9636. /*
  9637. const getYtPlayerPromise = () => {
  9638. if (!_yt_player_promise) {
  9639. _yt_player_promise = new Promise(resolve => {
  9640. let cid = setInterval(() => {
  9641. let t = (((window || 0)._yt_player || 0) || 0);
  9642. if (t) {
  9643. clearInterval(cid);
  9644. resolve(t);
  9645. }
  9646. }, 1);
  9647. promiseForTamerTimeout.then(() => {
  9648. resolve(null)
  9649. });
  9650. });
  9651. }
  9652. return _yt_player_promise;
  9653. }
  9654. */
  9655. const _yt_player_observable = observablePromise(() => {
  9656. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9657. if (_yt_player) {
  9658. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9659. return _yt_player;
  9660. }
  9661. }, promiseForTamerTimeout);
  9662.  
  9663. const polymerObservable = observablePromise(() => {
  9664. const Polymer = window.Polymer;
  9665. if (typeof Polymer !== 'function') return;
  9666. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9667. return Polymer;
  9668. }, promiseForTamerTimeout);
  9669.  
  9670. const schedulerInstanceObservable = observablePromise(() => {
  9671. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9672. }, promiseForTamerTimeout);
  9673.  
  9674. const timelineObservable = observablePromise(() => {
  9675. let t = (((document || 0).timeline || 0) || 0);
  9676. if (t && typeof t._play === 'function') {
  9677. return t;
  9678. }
  9679. }, promiseForTamerTimeout);
  9680. const animationObservable = observablePromise(() => {
  9681. let t = (((window || 0).Animation || 0) || 0);
  9682. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9683. return t;
  9684. }
  9685. }, promiseForTamerTimeout);
  9686.  
  9687.  
  9688. const getScreenInfo = {
  9689. screenWidth: 0,
  9690. screenHeight: 0,
  9691. valueReady: false,
  9692. onResize: () => {
  9693. getScreenInfo.valueReady = false;
  9694. },
  9695. sizeProvided: () => {
  9696. if (getScreenInfo.valueReady) return true;
  9697. getScreenInfo.screenWidth = screen.width;
  9698. getScreenInfo.screenHeight = screen.height;
  9699. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9700. getScreenInfo.valueReady = true;
  9701. return true;
  9702. }
  9703. return false;
  9704. }
  9705. };
  9706.  
  9707. window.addEventListener('resize', getScreenInfo.onResize, true);
  9708.  
  9709.  
  9710. // const hookLeftPending = new WeakMap();
  9711.  
  9712. const isNaNx = Number.isNaN;
  9713.  
  9714. const hookLeftPD = {
  9715. get() {
  9716. const p = 'left';
  9717. // const o = hookLeftPending.get(this);
  9718. // if (o && o.key) {
  9719. // this.setProperty(p, o.value);
  9720. // o.key = null
  9721. // }
  9722. return this.getPropertyValue(p);
  9723. },
  9724. set(v) {
  9725.  
  9726. const p = 'left';
  9727. const cv = this.getPropertyValue(p);
  9728. const sv = v;
  9729.  
  9730. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  9731.  
  9732. // console.log(8380,did, cv, sv)
  9733. if (!cv && !sv) return true;
  9734. if (cv === sv) return true;
  9735.  
  9736. // skip 0~9px => L>=4
  9737.  
  9738. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  9739.  
  9740. if (!isNaNx(qsv)) {
  9741. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  9742.  
  9743. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  9744. const { screenWidth, screenHeight } = getScreenInfo;
  9745. let pWidth = screenWidth + 1024;
  9746. let pHeight = screenHeight + 768;
  9747. const minRatio = 0.003;
  9748. const dw = pWidth * 0.0003; // min dw = 0.3072
  9749. const dh = pHeight * 0.0003; // min dh = 0.2304
  9750. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  9751. if (Math.abs(qcv - qsv) < dw) return true;
  9752. }
  9753.  
  9754. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  9755. if (`${v}`.length > `${sv}`.length) v = sv;
  9756. // console.log(8382, did, sv, nv, cv, this)
  9757. }
  9758.  
  9759. // Promise.resolve().then(() => {
  9760. // const o = hookLeftPending.get(this);
  9761. // if (o && o.key === did) {
  9762. // this.setProperty(p, o.value);
  9763. // o.key = null;
  9764. // }
  9765. // });
  9766. // hookLeftPending.set(this, {
  9767. // key: did,
  9768. // value: nv
  9769. // });
  9770.  
  9771. // if (nv != v) {
  9772. // console.log(8387, v, nv);
  9773. // }
  9774.  
  9775. this.setProperty(p, v);
  9776. // console.log(8383, did, this.getPropertyValue(p))
  9777. return true;
  9778. },
  9779. enumerable: true,
  9780. configurable: true
  9781. };
  9782.  
  9783.  
  9784. if (HOOK_CSSPD_LEFT) {
  9785.  
  9786.  
  9787. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  9788.  
  9789. }
  9790.  
  9791.  
  9792.  
  9793.  
  9794.  
  9795. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  9796.  
  9797. const evKey = `${_evKey}`;
  9798. const fvKey = `${_fvKey}`;
  9799. const debug = !!_debug;
  9800.  
  9801. const _yt_player = await _yt_player_observable.obtain();
  9802.  
  9803.  
  9804. if (!_yt_player || typeof _yt_player !== 'object') return;
  9805.  
  9806.  
  9807. const getArr = (_yt_player) => {
  9808.  
  9809. let arr = [];
  9810.  
  9811. for (const [k, v] of Object.entries(_yt_player)) {
  9812.  
  9813. const p = typeof v === 'function' ? v.prototype : 0;
  9814. if (p
  9815. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  9816.  
  9817. ) {
  9818. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9819.  
  9820. }
  9821.  
  9822. }
  9823.  
  9824. if (arr.length === 0) {
  9825.  
  9826. console.warn(`Key prop [${evKey}] does not exist.`);
  9827. } else {
  9828.  
  9829. return arr;
  9830. }
  9831.  
  9832. };
  9833.  
  9834. const arr = getArr(_yt_player);
  9835.  
  9836.  
  9837. if (!arr) return;
  9838.  
  9839. debug && console.log(`FIX_${evKey}`, arr);
  9840.  
  9841. const f = function (...args) {
  9842. Promise.resolve().then(() => this[fvKey](...args));
  9843. };
  9844.  
  9845.  
  9846. for (const k of arr) {
  9847.  
  9848. const g = _yt_player;
  9849. const gk = g[k];
  9850. const gkp = gk.prototype;
  9851.  
  9852. debug && console.log(237, k, gkp)
  9853.  
  9854. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  9855. gkp[fvKey] = gkp[evKey];
  9856. gkp[evKey] = f;
  9857. }
  9858. }
  9859.  
  9860.  
  9861.  
  9862.  
  9863. }
  9864.  
  9865. if (!isChatRoomURL) {
  9866.  
  9867. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  9868. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  9869. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  9870. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  9871. if (FIX_VideoEVENTS_v2) {
  9872. const FIX_VideoEVENTS_DEBUG = 0;
  9873. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  9874. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  9875. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  9876. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  9877. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  9878. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  9879. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  9880. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  9881. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  9882.  
  9883. }
  9884. // onMutedAutoplayChange
  9885. // onVolumeChange
  9886. // onPlaybackRateChange
  9887.  
  9888. // onAirPlayActiveChange
  9889. // onAirPlayAvailabilityChange
  9890. // onApiChange
  9891. // onAutoplayBlocked
  9892. // onDrmOutputRestricted
  9893. // onFullscreenChange
  9894. // onLoadProgress
  9895. // onLoadedMetadata
  9896. // onVideoDataChange
  9897. // onVideoProgress
  9898.  
  9899. }
  9900.  
  9901.  
  9902. let isAmended_Polymer_RenderStatus = false;
  9903.  
  9904. (FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  9905.  
  9906. const Polymer = await polymerObservable.obtain();
  9907. if (!Polymer) return;
  9908.  
  9909. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  9910. isAmended_Polymer_RenderStatus = true;
  9911.  
  9912. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  9913. let arrBefore = null, arrAfter = null;
  9914. const push = Array.prototype.push;
  9915. let arr = null;
  9916. Array.prototype.push = function () {
  9917. arr = this;
  9918. }
  9919. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  9920. if (arr) arrBefore = arr;
  9921. arr = null;
  9922. Polymer.RenderStatus.afterNextRender({}, {}, {});
  9923. if (arr) arrAfter = arr;
  9924. arr = null;
  9925. Array.prototype.push = push;
  9926. Polymer.RenderStatus.arrBefore = arrBefore;
  9927. Polymer.RenderStatus.arrAfter = arrAfter;
  9928.  
  9929. if (arrBefore && arrAfter) {
  9930.  
  9931. Function.prototype.call7900 = Function.prototype.call;
  9932. Function.prototype.apply7900 = Function.prototype.apply;
  9933. Function.prototype.apply7948 = function (obj, args) {
  9934. const f = this;
  9935. let m = kRef(obj);
  9936. if (!m) return;
  9937. if (m.is && !m.nodeName) {
  9938. if (!m.isAttached || !m.hostElement) {
  9939. return;
  9940. }
  9941. }
  9942. try {
  9943. return !args ? f.call7900(m) : f.apply7900(m, args);
  9944. } catch (e) {
  9945. console.warn(e);
  9946. }
  9947. return null;
  9948. }
  9949.  
  9950. arrBefore.push = arrAfter.push = function (a) {
  9951. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  9952. if (a[0].deref) a[0] = kRef(a[0]);
  9953. const f = a[1]
  9954. const obj = a[0]
  9955. const args = a[2];
  9956. f.apply = f.apply7948;
  9957. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  9958. a[0] = obj[wk]
  9959. // console.log(4992, a)
  9960. return push.call(this, a);
  9961. }
  9962.  
  9963. }
  9964.  
  9965.  
  9966. }
  9967. // Polymer.RenderStatus.beforeNextRender
  9968. }
  9969.  
  9970. if (FIX_Polymer_dom) {
  9971.  
  9972. const checkPDFuncValue = (pd) => {
  9973. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  9974. }
  9975. const checkPDFuncValue2 = (pd) => {
  9976. return pd && typeof pd.value == 'function'
  9977. }
  9978.  
  9979. const checkPDFuncGet = (pd) => {
  9980. return pd && typeof pd.get == 'function'
  9981. }
  9982.  
  9983. const domX = Polymer.dom(document.createElement('null'));
  9984. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  9985. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  9986. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  9987. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  9988. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  9989. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  9990. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  9991. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  9992. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  9993.  
  9994.  
  9995. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  9996.  
  9997. domXP.querySelector15 = domXP.querySelector;
  9998.  
  9999. const querySelectorFn = function (query) {
  10000. try {
  10001. const p = this.node;
  10002.  
  10003. if (p instanceof Document && p.isConnected === true) {
  10004. return pd4b.value.call(p, query);
  10005. }
  10006.  
  10007. } catch (e) { }
  10008. return this.querySelector15(query);
  10009. }
  10010.  
  10011. Object.defineProperty(domXP, 'querySelector', {
  10012. get() {
  10013. return querySelectorFn;
  10014. },
  10015. set(nv) {
  10016. if (nv === querySelectorFn) return true;
  10017. this.querySelector15 = nv;
  10018. return true;
  10019. },
  10020.  
  10021. enumerable: false,
  10022. configurable: true
  10023. });
  10024.  
  10025. Polymer.__fixedQuerySelector__ = 1;
  10026. }
  10027.  
  10028. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  10029.  
  10030. domXP.querySelectorAll15 = domXP.querySelectorAll;
  10031.  
  10032. const querySelectorAllFn = function (query) {
  10033.  
  10034. try {
  10035.  
  10036. const p = this.node;
  10037.  
  10038. if (p instanceof Document && p.isConnected === true) {
  10039. return pd6b.value.call(p, query);
  10040. }
  10041.  
  10042. } catch (e) {
  10043.  
  10044. }
  10045. return this.querySelectorAll15(query);
  10046. }
  10047.  
  10048. Object.defineProperty(domXP, 'querySelectorAll', {
  10049. get() {
  10050. return querySelectorAllFn;
  10051. },
  10052. set(nv) {
  10053. if (nv === querySelectorAllFn) return true;
  10054. this.querySelectorAll15 = nv;
  10055. return true;
  10056. },
  10057.  
  10058. enumerable: false,
  10059. configurable: true
  10060. });
  10061.  
  10062. Polymer.__fixedQuerySelectorAll__ = 1;
  10063. }
  10064. }
  10065.  
  10066.  
  10067. if (FIX_stampDomArray) {
  10068.  
  10069. Polymer.Base.__connInit__ = function () {
  10070. setupYtComponent(this);
  10071. }
  10072.  
  10073.  
  10074. /** @type {Function} */
  10075. const connectedCallbackK = function (...args) {
  10076. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10077. const r = this[qm53](...args);
  10078. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10079. this.mh35 = 1;
  10080. return r;
  10081. };
  10082.  
  10083. connectedCallbackK.m353 = 1;
  10084.  
  10085.  
  10086. const qt53 = Polymer.Base.connectedCallback;
  10087. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  10088.  
  10089. Polymer.Base.connectedCallback = connectedCallbackK;
  10090.  
  10091.  
  10092. /** @type {Function} */
  10093. const createdK = function (...args) {
  10094. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10095. const r = this[qn53](...args);
  10096. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10097. this.mh36 = 1;
  10098. return r;
  10099. };
  10100.  
  10101.  
  10102. createdK.m353 = 1;
  10103. Polymer.Base[qn53] = Polymer.Base.created;
  10104. Polymer.Base.created = createdK;
  10105.  
  10106.  
  10107.  
  10108.  
  10109.  
  10110.  
  10111.  
  10112.  
  10113.  
  10114.  
  10115.  
  10116. }
  10117.  
  10118. })();
  10119.  
  10120.  
  10121. /*
  10122.  
  10123. e.nativeAppendChild = d.prototype.appendChild,
  10124. d.prototype.appendChild = function(h) {
  10125. return function(l) {
  10126. if (l instanceof DocumentFragment) {
  10127. var m = Array.from(l.children);
  10128. l = h.nativeAppendChild.call(this, l);
  10129. if (this.isConnected) {
  10130. m = g(m);
  10131. for (var p = m.next(); !p.done; p = m.next())
  10132. YD(p.value)
  10133. }
  10134. return l
  10135. }
  10136. m = l instanceof Element && l.isConnected;
  10137. p = h.nativeAppendChild.call(this, l);
  10138. m && ZD(l);
  10139. this.isConnected && YD(l);
  10140. return p
  10141. }
  10142. }(e),
  10143.  
  10144. */
  10145.  
  10146. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  10147.  
  10148. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  10149. if (f) Node.prototype.appendChild = function (a) {
  10150. if (this instanceof Element) { // exclude DocumentFragment
  10151. try {
  10152. let checkFragmentA = (a instanceof DocumentFragment);
  10153. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  10154. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  10155. for (const node of headLinkCollection) {
  10156. if (node.rel === 'preload' && node.as === 'fetch') {
  10157. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  10158. }
  10159. }
  10160. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  10161. checkFragmentA = false;
  10162. }
  10163. if (checkFragmentA && a.firstElementChild === null) {
  10164. // no element in fragmentA
  10165. let doNormal = false;
  10166. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  10167. if (child.nodeType === 3) { doNormal = true; break; }
  10168. }
  10169. if (!doNormal) return a;
  10170. }
  10171. } catch (e) {
  10172. console.log(e);
  10173. }
  10174. }
  10175. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  10176. }
  10177.  
  10178. })();
  10179.  
  10180. if (FIX_Shady) {
  10181.  
  10182. observablePromise(() => {
  10183. const { ShadyDOM, ShadyCSS } = window;
  10184. if (ShadyDOM) {
  10185. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  10186. ShadyDOM.noPatch = true; // 1 of 10
  10187. ShadyDOM.patchOnDemand = false; // 1 of 10
  10188. ShadyDOM.preferPerformance = true; // 1 of 10
  10189. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  10190. }
  10191. if (ShadyCSS) {
  10192. ShadyCSS.nativeCss = true; // 1 of 10
  10193. ShadyCSS.nativeShadow = true; // 6 of 10
  10194. ShadyCSS.cssBuild = undefined; // 1 of 10
  10195. ShadyCSS.disableRuntime = true; // 1 of 10
  10196. }
  10197. if (ShadyDOM && ShadyCSS) return 1;
  10198. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  10199.  
  10200. }
  10201.  
  10202.  
  10203. // let schedulerInstancePropOfTimerType = '';
  10204. // let schedulerInstancePropOfTimerId = '';
  10205. (FIX_schedulerInstanceInstance & 2) && (async () => {
  10206.  
  10207. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  10208.  
  10209. if (!schedulerInstanceInstance_) return;
  10210.  
  10211. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  10212. if (checkOK) {
  10213.  
  10214. let resolveRendering = null;
  10215.  
  10216. let cmPr = new PromiseExternal();
  10217. const cm = document.createComment('0');
  10218. const cmObs = new MutationObserver(() => {
  10219. if (resolveRendering) {
  10220. resolveRendering();
  10221. resolveRendering = null;
  10222. }
  10223. cmPr.resolve();
  10224. cmPr = new PromiseExternal();
  10225. });
  10226. cmObs.observe(cm, {characterData: true})
  10227.  
  10228. let web_emulated_idle_callback_delay_val = null;
  10229.  
  10230. const getRenderIdleCallbackMs = () => {
  10231. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  10232. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  10233. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  10234. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  10235. return web_emulated_idle_callback_delay_val;
  10236. }
  10237. let isDelayRenderFn_firstCheck = true;
  10238. let isDelayRenderFn_key = null;
  10239. const isDelayRenderFn = (f) => {
  10240. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  10241. isDelayRenderFn_firstCheck = false;
  10242. if (typeof ytglobal === 'undefined') return false;
  10243. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  10244. if (!globalInstance) return false;
  10245. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  10246. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  10247. isDelayRenderFn_key = entry[0]
  10248. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  10249. return true;
  10250. }
  10251. }
  10252. return false;
  10253. }
  10254.  
  10255. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  10256.  
  10257. let requestingFn = null;
  10258. let requestingArgs = null;
  10259.  
  10260. const f = function () {
  10261. requestingFn = this.fn;
  10262. requestingArgs = [...arguments];
  10263. return 12373;
  10264. };
  10265.  
  10266. const fakeFns = [
  10267. f.bind({ fn: requestAnimationFrame }),
  10268. f.bind({ fn: setInterval }),
  10269. f.bind({ fn: setTimeout }),
  10270. f.bind({ fn: requestIdleCallback })
  10271. ];
  10272.  
  10273. let mzt = 0;
  10274.  
  10275. let _fnSelectorProp = null;
  10276. const mkFns = new Array(4);
  10277.  
  10278. /*
  10279. case 1:
  10280. var a = this.K;
  10281. this.g = this.I ? window.requestIdleCallback(a, {
  10282. timeout: 3E3
  10283. }) : window.setTimeout(a, ma);
  10284. break;
  10285. case 2:
  10286. this.g = window.setTimeout(this.M, this.N);
  10287. break;
  10288. case 3:
  10289. this.g = window.requestAnimationFrame(this.L);
  10290. break;
  10291. case 4:
  10292. this.g = window.setTimeout(this.J, 0)
  10293. }
  10294.  
  10295. */
  10296. const startFnHandler = {
  10297. get(target, prop, receiver) {
  10298. if (prop === '$$12377$$') return true;
  10299. if (prop === '$$12378$$') return target;
  10300.  
  10301. // console.log('get',prop)
  10302. return target[prop]
  10303. },
  10304. set(target, prop, value, receiver) {
  10305. // console.log('set', prop, value)
  10306.  
  10307.  
  10308. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  10309. if (value === 12373 && _fnSelectorProp) {
  10310.  
  10311. const schedulerTypeSelection = target[_fnSelectorProp];
  10312. const timerIdProp = prop;
  10313.  
  10314. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  10315. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  10316. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  10317. // schedulerInstancePropOfTimerId = timerIdProp || '';
  10318. // }
  10319.  
  10320. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  10321. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  10322. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  10323. // rare
  10324. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10325. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  10326. // often
  10327. if ((FIX_schedulerInstanceInstance & 4)) {
  10328. const f = requestingArgs[0];
  10329. const tir = ++mzt;
  10330. nextBrowserTick_(() => {
  10331. if (target[timerIdProp] === -tir) f();
  10332. });
  10333. target[_fnSelectorProp] = 940;
  10334. target[timerIdProp] = -tir;
  10335. } else {
  10336. const f = requestingArgs[0];
  10337. const tir = ++mzt;
  10338. Promise.resolve().then(() => {
  10339. if (target[timerIdProp] === -tir) f();
  10340. });
  10341. target[_fnSelectorProp] = 930;
  10342. target[timerIdProp] = -tir;
  10343. }
  10344. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  10345. // often
  10346. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  10347. cm.data = (cm.data & 7) + 1;
  10348. let renderFn = requestingArgs[0];
  10349. const resolveRendering_ = () => {
  10350. const renderFn_ = renderFn;
  10351. if (renderFn_) {
  10352. renderFn = null;
  10353. renderFn_();
  10354. }
  10355. };
  10356. resolveRendering = resolveRendering_;
  10357. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  10358. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  10359.  
  10360. // cm.data = (cm.data & 7) + 1;
  10361. // target[timerIdProp] = Math.random();
  10362.  
  10363. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  10364.  
  10365. cm.data = (cm.data & 7) + 1;
  10366.  
  10367. let renderFn = requestingArgs[0];
  10368. const resolveRendering_ = () => {
  10369. const renderFn_ = renderFn;
  10370. if (renderFn_) {
  10371. renderFn = null;
  10372. renderFn_();
  10373. }
  10374. };
  10375. resolveRendering = resolveRendering_;
  10376.  
  10377. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  10378.  
  10379.  
  10380. } else {
  10381. if (requestingFn === requestIdleCallback) {
  10382. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  10383. } else {
  10384. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10385. }
  10386. }
  10387. } else {
  10388. target[_fnSelectorProp] = 0;
  10389. target[timerIdProp] = 0;
  10390. }
  10391. } else {
  10392. target[prop] = value;
  10393. }
  10394. return true;
  10395. }
  10396. };
  10397.  
  10398. let startBusy = false;
  10399. schedulerInstanceInstance_.start = function () {
  10400. if (startBusy) return;
  10401. startBusy = true;
  10402. try {
  10403. mkFns[0] = window.requestAnimationFrame;
  10404. mkFns[1] = window.setInterval;
  10405. mkFns[2] = window.setTimeout;
  10406. mkFns[3] = window.requestIdleCallback;
  10407. const tThis = this['$$12378$$'] || this;
  10408. window.requestAnimationFrame = fakeFns[0]
  10409. window.setInterval = fakeFns[1]
  10410. window.setTimeout = fakeFns[2]
  10411. window.requestIdleCallback = fakeFns[3]
  10412. _fnSelectorProp = null;
  10413. tThis.start993.call(new Proxy(tThis, startFnHandler));
  10414. _fnSelectorProp = null;
  10415. window.requestAnimationFrame = mkFns[0];
  10416. window.setInterval = mkFns[1];
  10417. window.setTimeout = mkFns[2];
  10418. window.requestIdleCallback = mkFns[3];
  10419. } catch (e) {
  10420. console.warn(e);
  10421. }
  10422. startBusy = false;
  10423. }
  10424.  
  10425. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  10426.  
  10427. }
  10428. })();
  10429.  
  10430. FIX_yt_player && !isChatRoomURL && (async () => {
  10431.  
  10432. const fOption = 1 | 2 | 4;
  10433.  
  10434. const _yt_player = await _yt_player_observable.obtain();
  10435.  
  10436. if (!_yt_player || typeof _yt_player !== 'object') return;
  10437.  
  10438. const g = _yt_player;
  10439. let k;
  10440.  
  10441. if (fOption & 1) {
  10442.  
  10443. // rAf scheduling
  10444.  
  10445. const keyZqOu = getZqOu(_yt_player);
  10446. if (!keyZqOu) {
  10447. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  10448. return;
  10449. }
  10450. k = keyZqOu
  10451.  
  10452. const gk = g[k];
  10453. if (typeof gk !== 'function') {
  10454. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  10455. return;
  10456. }
  10457. const gkp = gk.prototype;
  10458.  
  10459. const dummyObject = new gk;
  10460. const nilFunc = () => { };
  10461.  
  10462. const nilObj = {};
  10463.  
  10464. // console.log(1111111111)
  10465.  
  10466. let keyBoolD = '';
  10467. let keyWindow = '';
  10468. let keyFuncC = '';
  10469. let keyCidj = '';
  10470.  
  10471. for (const [t, y] of Object.entries(dummyObject)) {
  10472. if (y instanceof Window) keyWindow = t;
  10473. }
  10474.  
  10475. const dummyObjectProxyHandler = {
  10476. get(target, prop) {
  10477. let v = target[prop]
  10478. if (v instanceof Window && !keyWindow) {
  10479. keyWindow = t;
  10480. }
  10481. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  10482. if (prop === keyWindow) y = {
  10483. requestAnimationFrame(f) {
  10484. return 3;
  10485. },
  10486. cancelAnimationFrame() {
  10487.  
  10488. }
  10489. }
  10490. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  10491. keyFuncC = prop;
  10492. }
  10493. // console.log('[get]', prop, typeof target[prop])
  10494.  
  10495.  
  10496. return y;
  10497. },
  10498. set(target, prop, value) {
  10499.  
  10500. if (typeof value === 'boolean' && !keyBoolD) {
  10501. keyBoolD = prop;
  10502. }
  10503. if (typeof value === 'number' && !keyCidj && value >= 2) {
  10504. keyCidj = prop;
  10505. }
  10506.  
  10507. // console.log('[set]', prop, value)
  10508. target[prop] = value;
  10509.  
  10510. return true;
  10511. }
  10512. };
  10513.  
  10514. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  10515.  
  10516. // console.log('gkp.start',gkp.start);
  10517. // console.log('gkp.stop',gkp.stop);
  10518. gkp._activation = false;
  10519.  
  10520. gkp.start = function () {
  10521. // p59 || console.log(12100)
  10522. if (!this._activation) {
  10523. this._activation = true;
  10524. foregroundPromiseFn().then(() => {
  10525. this._activation = false;
  10526. if (this[keyCidj]) {
  10527. Promise.resolve().then(this[keyFuncC]);
  10528. }
  10529. });
  10530. }
  10531. this[keyCidj] = 1;
  10532. this[keyBoolD] = true;
  10533. };
  10534.  
  10535. gkp.stop = function () {
  10536. this[keyCidj] = null;
  10537. };
  10538.  
  10539.  
  10540. /*
  10541. g[k].start = function() {
  10542. this.stop();
  10543. this.D = true;
  10544. var a = requestAnimationFrame
  10545. , b = cancelAnimationFrame;
  10546. this.j = a.call(this.B, this.C)
  10547. }
  10548. ;
  10549. g[k].stop = function() {
  10550. if (this.isActive()) {
  10551. var a = requestAnimationFrame
  10552. , b = cancelAnimationFrame;
  10553. b.call(this.B, this.j)
  10554. }
  10555. this.j = null
  10556. }
  10557. */
  10558. }
  10559.  
  10560. if (fOption & 2) {
  10561. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10562.  
  10563. if (keyzo) {
  10564.  
  10565. k = keyzo;
  10566.  
  10567. const attrUpdateFn = g[k];
  10568. // console.log(5992, attrUpdateFn)
  10569. g['$$original$$' + k] = attrUpdateFn;
  10570. const zoTransform = async (a, c) => {
  10571.  
  10572. let transformType = '';
  10573. let transformValue = 0;
  10574. let transformUnit = '';
  10575. let transformTypeI = 0;
  10576.  
  10577. const aStyle = a.style;
  10578.  
  10579. let cType = 0;
  10580.  
  10581. const cl = c.length;
  10582.  
  10583. if (cl >= 8) {
  10584. // scale(1)
  10585. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10586. cType = 1;
  10587. let t = c.charCodeAt(5);
  10588. if (t === 88 || t === 120) cType = 1 | 4;
  10589. if (t === 89 || t === 121) cType = 1 | 8;
  10590. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10591. cType = 2;
  10592. let t = c.charCodeAt(9);
  10593. if (t === 88 || t === 120) cType = 2 | 4;
  10594. if (t === 89 || t === 121) cType = 2 | 8;
  10595. }
  10596. let w = 0;
  10597. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10598. let p = c.substring(7, cl - 1);
  10599. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10600. if (typeof q === 'number' && !isNaNx(q)) {
  10601. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10602. transformValue = q;
  10603. transformUnit = '';
  10604. transformTypeI = 1;
  10605. } else {
  10606. cType = 256;
  10607. }
  10608. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10609. if (c.endsWith('px)')) {
  10610. let p = c.substring(11, cl - 3);
  10611. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10612. if (typeof q === 'number' && !isNaNx(q)) {
  10613. transformType = w === 1 ? 'translateX' : 'translateY';
  10614. transformValue = q;
  10615. transformUnit = 'px';
  10616. transformTypeI = 2;
  10617. } else if (p === 'NaN') {
  10618. return;
  10619. }
  10620. } else {
  10621. cType = 256;
  10622. }
  10623. } else if (cType > 0) {
  10624. cType = 256;
  10625. }
  10626. }
  10627.  
  10628.  
  10629. if (cType === 256) {
  10630. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10631. }
  10632.  
  10633. if (transformTypeI === 1) {
  10634. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10635. const vz = toFixed2(q, 3);
  10636. c = `${transformType}(${vz})`;
  10637. const cv = aStyle.transform;
  10638. if (c === cv) return;
  10639. aStyle.transform = c;
  10640. } else if (transformTypeI === 2) {
  10641. const q = transformValue;
  10642. const vz = toFixed2(q, 1);
  10643. c = `${transformType}(${vz}${transformUnit})`;
  10644. const cv = aStyle.transform;
  10645. if (c === cv) return;
  10646. aStyle.transform = c;
  10647. } else { // eg empty
  10648. const cv = aStyle.transform;
  10649. if (!c && !cv) return;
  10650. else if (c === cv) return;
  10651. aStyle.transform = c;
  10652. }
  10653.  
  10654. };
  10655.  
  10656. const elmTransformTemp = new WeakMap();
  10657. const elmPropTemps = {
  10658. 'display': new WeakMap(),
  10659. 'width': new WeakMap(),
  10660. 'height': new WeakMap(),
  10661. 'outlineWidth': new WeakMap(),
  10662. 'position': new WeakMap(),
  10663. 'padding': new WeakMap(),
  10664. "cssText": new WeakMap(),
  10665. "right": new WeakMap(),
  10666. "left": new WeakMap(),
  10667. "top": new WeakMap(),
  10668. "bottom": new WeakMap(),
  10669. "transitionDelay": new WeakMap(),
  10670. "marginLeft": new WeakMap(),
  10671. "marginTop": new WeakMap(),
  10672. "marginRight": new WeakMap(),
  10673. "marginBottom": new WeakMap(),
  10674. }
  10675.  
  10676. const ns5 = Symbol();
  10677. const nextModify = (a, c, m, f, immediate) => {
  10678. const a_ = a;
  10679. const m_ = m;
  10680. const noKey = !m_.has(a_);
  10681. if (immediate || noKey) {
  10682. m_.set(a_, ns5);
  10683. f(a_, c);
  10684. noKey && nextBrowserTick_(() => {
  10685. const d = m_.get(a_);
  10686. if (d === undefined) return;
  10687. m_.delete(a_);
  10688. if (d !== ns5) f(a_, d);
  10689. });
  10690. } else {
  10691. m_.set(a_, c);
  10692. }
  10693. };
  10694.  
  10695. const set66 = new Set();
  10696. const log77 = new Map();
  10697. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10698.  
  10699. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10700.  
  10701. // console.log(140000, a, b, c);
  10702. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10703. const num = c;
  10704. c = `${num}`;
  10705. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10706. }
  10707.  
  10708. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10709.  
  10710. let elmPropTemp = null;
  10711.  
  10712. if (b === "transform") {
  10713. // div.ytp-hover-progress.ytp-hover-progress-light
  10714. // div.ytp-play-progress.ytp-swatch-background-color
  10715.  
  10716. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10717. return;
  10718.  
  10719. } else if (elmPropTemp = elmPropTemps[b]) {
  10720.  
  10721. // if (c.length > 5 && c.includes('.')) {
  10722. // console.log(123213, c)
  10723. // }
  10724.  
  10725. const b_ = b;
  10726. nextModify(a, c, elmPropTemp, (a, c) => {
  10727. const style = a.style;
  10728. const cv = style[b_];
  10729. if (!cv && !c) return;
  10730. if (cv === c) return;
  10731. style[b_] = c;
  10732. }, immediateChange);
  10733. return;
  10734.  
  10735. } else if (b === "outline-width") {
  10736.  
  10737. const b_ = 'outlineWidth';
  10738. elmPropTemp = elmPropTemps[b_];
  10739. nextModify(a, c, elmPropTemp, (a, c) => {
  10740. const style = a.style;
  10741. const cv = style[b_];
  10742. if (!cv && !c) return;
  10743. if (cv === c) return;
  10744. style[b_] = c;
  10745. }, immediateChange);
  10746. return;
  10747.  
  10748. } else if (b === 'maxWidth' || b === 'maxHeight') {
  10749. // I think these can be directly assigned.
  10750.  
  10751. const b_ = b;
  10752. const style = a.style;
  10753. const cv = style[b_];
  10754. if (!cv && !c) return;
  10755. if (cv === c) return;
  10756. style[b_] = c;
  10757. return;
  10758.  
  10759. } else {
  10760. // if(immediate && elmPropTemps[b]){
  10761. // console.log(5191, b)
  10762. // }
  10763. // caption-window
  10764. // margin-left max-height max-width font-family fill color font-size background white-space margin
  10765. // text-align background-color
  10766. // console.log(27304, a, b, c)
  10767. if (!set66.has(b)) {
  10768. set66.add(b);
  10769. nextBrowserTick_(() => {
  10770. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  10771. console.log(27304, a, b, c)
  10772. }
  10773. })
  10774. }
  10775. }
  10776.  
  10777. attrUpdateFn.call(this, a, b, c);
  10778. return;
  10779. } else if (typeof (b || 0) === 'object') {
  10780.  
  10781. // this is to fix caption positioning
  10782. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  10783. const immediate = (a.id || 0).length > 14;
  10784. for (const [k, v] of Object.entries(b)) {
  10785. modifiedFn.call(this, a, k, v, immediate);
  10786. }
  10787.  
  10788. } else {
  10789.  
  10790. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  10791. // ytp-ad-timed-pie-countdown-inner
  10792.  
  10793. if (typeof b === 'string') {
  10794.  
  10795. let m = log77.get(b);
  10796. if (!m) {
  10797. m = [];
  10798. console.log('attrUpdateFn.debug.27304', m);
  10799. log77.set(b, m);
  10800. }
  10801. m.push([a, b, c]);
  10802.  
  10803. } else {
  10804. console.log('attrUpdateFn.debug.27306', a, b, c);
  10805. }
  10806.  
  10807. attrUpdateFn.call(this, a, b, c);
  10808. return;
  10809. }
  10810.  
  10811. // console.log(130000, a, b, c);
  10812.  
  10813. };
  10814. g[k] = modifiedFn;
  10815.  
  10816.  
  10817. /*
  10818.  
  10819. g.zo = function(a, b, c) {
  10820. if ("string" === typeof b)
  10821. (b = yo(a, b)) && (a.style[b] = c);
  10822. else
  10823. for (var d in b) {
  10824. c = a;
  10825. var e = b[d]
  10826. , f = yo(c, d);
  10827. f && (c.style[f] = e)
  10828. }
  10829. }
  10830.  
  10831.  
  10832. */
  10833.  
  10834.  
  10835. }
  10836. }
  10837.  
  10838. if (fOption & 4) {
  10839. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  10840.  
  10841. if (keyuG) {
  10842.  
  10843. k = keyuG;
  10844.  
  10845. const gk = g[k];
  10846. const gkp = gk.prototype;
  10847.  
  10848.  
  10849. /** @type { Map<string, WeakMap<any, any>> } */
  10850. const ntLogs = new Map();
  10851.  
  10852. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  10853.  
  10854. gkp.updateValue31 = gkp.updateValue;
  10855. gkp.updateValue = function (a, b) {
  10856. if (typeof a !== 'string') return this.updateValue31(a, b);
  10857.  
  10858. const element = this.element;
  10859. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  10860.  
  10861. let ntLog = ntLogs.get(a);
  10862. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  10863.  
  10864. let cache = ntLog.get(element);
  10865. if (cache && cache.value === b) {
  10866. return;
  10867. }
  10868. if (!cache) {
  10869. this.__oldValueByUpdateValue__ = null;
  10870. ntLog.set(element, cache = { value: b });
  10871. } else {
  10872. this.__oldValueByUpdateValue__ = cache.value;
  10873. cache.value = b;
  10874. }
  10875.  
  10876. return this.updateValue31(a, b);
  10877. }
  10878.  
  10879. /*
  10880. g.k.update = function(a) {
  10881. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  10882. c = c.value,
  10883. this.updateValue(c, a[c])
  10884. }
  10885. ;
  10886. g.k.updateValue = function(a, b) {
  10887. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  10888. }
  10889. */
  10890.  
  10891. }
  10892.  
  10893.  
  10894. }
  10895. }
  10896.  
  10897.  
  10898.  
  10899. })();
  10900.  
  10901.  
  10902. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  10903. // keyboard shortcut keys controller
  10904.  
  10905. const _yt_player = await _yt_player_observable.obtain();
  10906.  
  10907. if (!_yt_player || typeof _yt_player !== 'object') return;
  10908.  
  10909. keyboardController(_yt_player);
  10910.  
  10911. })();
  10912.  
  10913. FIX_yt_player && !isChatRoomURL && (async () => {
  10914. // timer scheduling
  10915.  
  10916. const _yt_player = await _yt_player_observable.obtain();
  10917.  
  10918. if (!_yt_player || typeof _yt_player !== 'object') return;
  10919.  
  10920. let keyZqQu = getZqQu(_yt_player);
  10921.  
  10922. if (!keyZqQu) return;
  10923.  
  10924. const g = _yt_player
  10925. let k = keyZqQu
  10926.  
  10927. const gk = g[k];
  10928. if (typeof gk !== 'function') return;
  10929. const gkp = gk.prototype;
  10930.  
  10931. const extractKeysZqQu = () => {
  10932.  
  10933.  
  10934. let _keyeC = '';
  10935. try {
  10936. gkp.stop.call(new Proxy({
  10937. isActive: () => { }
  10938. }, {
  10939. set(target, prop, value) {
  10940. if (value === 0) _keyeC = prop;
  10941. return true;
  10942. }
  10943. }));
  10944. } catch (e) { }
  10945. if (!_keyeC) return;
  10946. const keyeC = _keyeC;
  10947.  
  10948. let keyC = ''; // this.C = this.ST.bind(this)
  10949. let keyhj = ''; // 1000ms
  10950. try {
  10951. gkp.start.call(new Proxy({
  10952. stop: () => { },
  10953. [keyeC]: 0,
  10954. }, {
  10955. get(target, prop) {
  10956. if (prop in target) return target[prop];
  10957. if (!keyC) {
  10958. keyC = prop;
  10959. return null; // throw error
  10960. }
  10961. else if (!keyhj) {
  10962. keyhj = prop;
  10963. }
  10964.  
  10965. }
  10966. }));
  10967. } catch (e) {
  10968. if (!keyC || !keyhj) {
  10969. console.log(e)
  10970. }
  10971. }
  10972.  
  10973. if (!keyC || !keyhj) return;
  10974. let keyST = '';
  10975. let keyj = '';
  10976. let keyB = '';
  10977. let keyxa = '';
  10978.  
  10979. const possibleKs = new Set();
  10980.  
  10981. for (const [k, v] of Object.entries(gkp)) {
  10982. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  10983. continue;
  10984. }
  10985. if (typeof v === 'function') {
  10986. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  10987. if (m) {
  10988. keyST = k;
  10989. keyj = m[1];
  10990. keyB = m[2];
  10991. } else {
  10992. possibleKs.add(k);
  10993. }
  10994. }
  10995. }
  10996.  
  10997. if (!keyST || !keyj || !keyB) return;
  10998.  
  10999. for (const k of possibleKs) {
  11000. if (k === keyST || k === keyj || k === keyB) {
  11001. continue;
  11002. }
  11003. const v = gkp[k];
  11004. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  11005. keyxa = k;
  11006. }
  11007. }
  11008.  
  11009. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  11010.  
  11011. }
  11012.  
  11013. const keys = extractKeysZqQu();
  11014. if (!keys || !keys.length) return;
  11015. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  11016.  
  11017. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  11018.  
  11019. let disposeKeys = null;
  11020.  
  11021. gkp[keyxa] = function () {
  11022. // dispose
  11023. if (!disposeKeys) {
  11024. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  11025. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  11026. const t = typeof this[key];
  11027. return t === 'undefined' || t === 'object'
  11028. }
  11029. return false;
  11030. });
  11031. }
  11032. for (const key of disposeKeys) {
  11033. const v = this[key];
  11034. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  11035. }
  11036. if (this[keyeC] > 0) this.stop();
  11037. this[keyj] = null;
  11038. this[keyB] = null;
  11039. };
  11040.  
  11041. gkp.start = function (a) {
  11042. if (this[keyeC] > 0) this.stop();
  11043. const delay = void 0 !== a ? a : this[keyhj];
  11044. this[keyeC] = window.setTimeout(this[keyC], delay);
  11045. };
  11046. gkp.stop = function () {
  11047. if (this[keyeC] > 0) {
  11048. window.clearTimeout(this[keyeC]);
  11049. this[keyeC] = 0;
  11050. }
  11051. };
  11052.  
  11053. gkp.isActive = function () {
  11054. return this[keyeC] > 0;
  11055. };
  11056.  
  11057. gkp[keyST] = function () {
  11058. this.stop(); // this[keyeC] = 0;
  11059. const fn = this[keyj];
  11060. const obj = this[keyB];
  11061. let skip = false;
  11062. if (!fn) skip = true;
  11063. else if (IGNORE_bufferhealth_CHECK && obj) {
  11064. let m;
  11065. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  11066. if (m.has("bufferhealth")) skip = true;
  11067. }
  11068. }
  11069. if (!skip) {
  11070. fn.call(obj);
  11071. }
  11072. };
  11073.  
  11074.  
  11075.  
  11076.  
  11077. /*
  11078.  
  11079. g.k.eC = 0;
  11080. g.k.xa = function() {
  11081. g.Qu.Vf.xa.call(this);
  11082. this.stop();
  11083. delete this.j;
  11084. delete this.B
  11085. }
  11086. ;
  11087. g.k.start = function(a) {
  11088. this.stop();
  11089. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  11090. }
  11091. ;
  11092. g.k.stop = function() {
  11093. this.isActive() && g.Sa.clearTimeout(this.eC);
  11094. this.eC = 0
  11095. }
  11096. ;
  11097. g.k.isActive = function() {
  11098. return 0 != this.eC
  11099. }
  11100. ;
  11101. g.k.ST = function() {
  11102. this.eC = 0;
  11103. this.j && this.j.call(this.B)
  11104. }
  11105. ;
  11106. */
  11107.  
  11108.  
  11109.  
  11110.  
  11111. })();
  11112.  
  11113. FIX_Animation_n_timeline && (async () => {
  11114.  
  11115. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  11116.  
  11117. if (!timeline || !Animation) return;
  11118.  
  11119. const animationsFix = (timeline) => {
  11120. const animations = (timeline || 0)._animations || 0;
  11121. const c = animations[0];
  11122. if (c) {
  11123. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  11124. animations.shift(); // keep animating but no looping
  11125. // c.effect.remove();
  11126. }
  11127. }
  11128. }
  11129.  
  11130. const aniProto = Animation.prototype;
  11131. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  11132.  
  11133. const getXroto = (x) => {
  11134. try {
  11135. return x.__proto__;
  11136. } catch (e) { }
  11137. return null;
  11138. }
  11139. const timProto = getXroto(timeline);
  11140. if (!timProto) return;
  11141. if (
  11142. (
  11143. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  11144. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  11145. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  11146. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  11147. )
  11148.  
  11149. ) {
  11150.  
  11151. timProto.nofCQ = 1;
  11152. aniProto.nofYH = 1;
  11153.  
  11154. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  11155.  
  11156.  
  11157. /*
  11158. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11159. return c._updatePromises();
  11160. });
  11161. */
  11162.  
  11163. const p = Array.prototype.filter;
  11164.  
  11165. let res = null;
  11166. Array.prototype.filter = function () {
  11167.  
  11168. res = this;
  11169. return this;
  11170.  
  11171. };
  11172.  
  11173. _updateAnimationsPromises.call({});
  11174.  
  11175. Array.prototype.filter = p;
  11176.  
  11177. if (res && typeof res.length === 'number') {
  11178. /** @type {any[]} */
  11179. const _res = res;
  11180. return _res;
  11181. }
  11182.  
  11183.  
  11184. return null;
  11185.  
  11186.  
  11187.  
  11188.  
  11189. })(timProto._updateAnimationsPromises);
  11190.  
  11191. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  11192.  
  11193. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  11194.  
  11195. aniProto._updatePromises31 = aniProto._updatePromises;
  11196.  
  11197. /*
  11198. aniProto._updatePromises = function(){
  11199. console.log('eff',this._oldPlayState, this.playState)
  11200. return this._updatePromises31.apply(this, arguments)
  11201. }
  11202. */
  11203.  
  11204. aniProto._updatePromises = function () {
  11205. var oldPlayState = this._oldPlayState;
  11206. var newPlayState = this.playState;
  11207. // console.log('ett', oldPlayState, newPlayState)
  11208. if (newPlayState !== oldPlayState) {
  11209. this._oldPlayState = newPlayState;
  11210. if (this._readyPromise) {
  11211. if ("idle" == newPlayState) {
  11212. this._rejectReadyPromise();
  11213. this._readyPromise = void 0;
  11214. } else if ("pending" == oldPlayState) {
  11215. this._resolveReadyPromise();
  11216. } else if ("pending" == newPlayState) {
  11217. this._readyPromise = void 0;
  11218. }
  11219. }
  11220. if (this._finishedPromise) {
  11221. if ("idle" == newPlayState) {
  11222. this._rejectFinishedPromise();
  11223. this._finishedPromise = void 0;
  11224. } else if ("finished" == newPlayState) {
  11225. this._resolveFinishedPromise();
  11226. } else if ("finished" == oldPlayState) {
  11227. this._finishedPromise = void 0;
  11228. }
  11229. }
  11230. }
  11231. return this._readyPromise || this._finishedPromise;
  11232. };
  11233.  
  11234.  
  11235. let restartWebAnimationsNextTickFlag = false;
  11236.  
  11237. const looperMethodT = () => {
  11238.  
  11239. const runnerFn = (hRes) => {
  11240. var b = timeline;
  11241. b.currentTime = hRes;
  11242. b._discardAnimations();
  11243. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11244. if (0 == b._animations.length) {
  11245. restartWebAnimationsNextTickFlag = false;
  11246. } else {
  11247. getRafPromise().then(runnerFn);
  11248. }
  11249. }
  11250.  
  11251. const restartWebAnimationsNextTick = () => {
  11252. if (!restartWebAnimationsNextTickFlag) {
  11253. restartWebAnimationsNextTickFlag = true;
  11254. getRafPromise().then(runnerFn);
  11255. }
  11256. }
  11257.  
  11258. return { restartWebAnimationsNextTick }
  11259. };
  11260.  
  11261.  
  11262. const looperMethodN = () => {
  11263.  
  11264. const acs = document.createElement('a-f');
  11265. acs.id = 'a-f';
  11266.  
  11267. if (!document.getElementById('afscript')) {
  11268. const style = document.createElement('style');
  11269. style.id = 'afscript';
  11270. style.textContent = `
  11271. @keyFrames aF1 {
  11272. 0% {
  11273. order: 0;
  11274. }
  11275. 100% {
  11276. order: 1;
  11277. }
  11278. }
  11279. #a-f[id] {
  11280. visibility: collapse !important;
  11281. position: fixed !important;
  11282. display: block !important;
  11283. top: -100px !important;
  11284. left: -100px !important;
  11285. margin:0 !important;
  11286. padding:0 !important;
  11287. outline:0 !important;
  11288. border:0 !important;
  11289. z-index:-1 !important;
  11290. width: 0px !important;
  11291. height: 0px !important;
  11292. contain: strict !important;
  11293. pointer-events: none !important;
  11294. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  11295. }
  11296. `;
  11297. (document.head || document.documentElement).appendChild(style);
  11298. }
  11299.  
  11300. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  11301.  
  11302. const _onanimationiteration = function (evt) {
  11303. const hRes = evt.timeStamp;
  11304. var b = timeline;
  11305. b.currentTime = hRes;
  11306. b._discardAnimations();
  11307. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11308. if (0 == b._animations.length) {
  11309. restartWebAnimationsNextTickFlag = false;
  11310. acs.onanimationiteration = null;
  11311. } else {
  11312. acs.onanimationiteration = _onanimationiteration;
  11313. }
  11314.  
  11315. }
  11316.  
  11317.  
  11318.  
  11319. const restartWebAnimationsNextTick = () => {
  11320. if (!restartWebAnimationsNextTickFlag) {
  11321. restartWebAnimationsNextTickFlag = true;
  11322. acs.onanimationiteration = _onanimationiteration;
  11323.  
  11324. }
  11325. }
  11326.  
  11327. return { restartWebAnimationsNextTick }
  11328. };
  11329.  
  11330.  
  11331.  
  11332. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  11333.  
  11334.  
  11335. // console.log(571, timProto);
  11336. timProto._play = function (c) {
  11337. c = new Animation(c, this);
  11338. this._animations.push(c);
  11339. restartWebAnimationsNextTick();
  11340. c._updatePromises();
  11341. c._animation.play();
  11342. c._updatePromises();
  11343. return c
  11344. }
  11345.  
  11346. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  11347. originalAnimationsWithPromises.length = 0;
  11348. originalAnimationsWithPromises.push = null;
  11349. originalAnimationsWithPromises.splice = null;
  11350. originalAnimationsWithPromises.slice = null;
  11351. originalAnimationsWithPromises.indexOf = null;
  11352. originalAnimationsWithPromises.unshift = null;
  11353. originalAnimationsWithPromises.shift = null;
  11354. originalAnimationsWithPromises.pop = null;
  11355. originalAnimationsWithPromises.filter = null;
  11356. originalAnimationsWithPromises.forEach = null;
  11357. originalAnimationsWithPromises.map = null;
  11358.  
  11359.  
  11360. const _updateAnimationsPromises = () => {
  11361. animationsWithPromisesMap.forEach(c => {
  11362. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  11363. });
  11364. /*
  11365. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11366. return c._updatePromises();
  11367. });
  11368. */
  11369. }
  11370.  
  11371. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  11372.  
  11373. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  11374.  
  11375. delete timProto._updateAnimationsPromises;
  11376. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  11377. get() {
  11378. if (animationsWithPromisesMap.size === 0) return nilFn;
  11379. return _updateAnimationsPromises;
  11380. },
  11381. set(nv) {
  11382. delete this._updateAnimationsPromises;
  11383. this._updateAnimationsPromises = nv;
  11384. },
  11385. enumerable: true,
  11386. configurable: true,
  11387. });
  11388.  
  11389.  
  11390. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  11391. aniProto.__finished_native_get__ = pdFinished.get;
  11392. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  11393.  
  11394.  
  11395. Object.defineProperty(aniProto, 'finished', {
  11396. get() {
  11397. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11398. this._finishedPromise = new Promise((resolve, reject) => {
  11399. this._resolveFinishedPromise = function () {
  11400. resolve(this)
  11401. };
  11402. this._rejectFinishedPromise = function () {
  11403. reject({
  11404. type: DOMException.ABORT_ERR,
  11405. name: "AbortError"
  11406. })
  11407. };
  11408. }),
  11409. "finished" == this.playState && this._resolveFinishedPromise());
  11410. return this._finishedPromise
  11411. },
  11412. set: undefined,
  11413. enumerable: true,
  11414. configurable: true
  11415. });
  11416.  
  11417. }
  11418.  
  11419.  
  11420.  
  11421. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  11422. aniProto.__ready_native_get__ = pdReady.get;
  11423. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  11424.  
  11425. Object.defineProperty(aniProto, 'ready', {
  11426. get() {
  11427. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11428. this._readyPromise = new Promise((resolve, reject) => {
  11429. this._resolveReadyPromise = function () {
  11430. resolve(this)
  11431. };
  11432. this._rejectReadyPromise = function () {
  11433. reject({
  11434. type: DOMException.ABORT_ERR,
  11435. name: "AbortError"
  11436. })
  11437. };
  11438. }),
  11439. "pending" !== this.playState && this._resolveReadyPromise());
  11440. return this._readyPromise
  11441. },
  11442. set: undefined,
  11443. enumerable: true,
  11444. configurable: true
  11445. });
  11446.  
  11447. }
  11448.  
  11449.  
  11450. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  11451.  
  11452. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  11453. const _rebuildUnderlyingAnimation = function () {
  11454. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  11455. this.effect && this.effect._onsample && (this.effect._onsample = null);
  11456. return this._rebuildUnderlyingAnimation21();
  11457. }
  11458. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  11459. // delete aniProto._rebuildUnderlyingAnimation;
  11460. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  11461. // get() {
  11462. // if (isNaN(this._sequenceNumber)) return nilFn;
  11463. // return this._rebuildUnderlyingAnimation21;
  11464. // },
  11465. // set(nv) {
  11466. // delete this._rebuildUnderlyingAnimation;
  11467. // this._rebuildUnderlyingAnimation = nv;
  11468. // },
  11469. // enumerable: true,
  11470. // configurable: true
  11471. // });
  11472. }
  11473.  
  11474.  
  11475. /*
  11476.  
  11477.  
  11478. function f(c) {
  11479. var b = v.timeline;
  11480. b.currentTime = c;
  11481. b._discardAnimations();
  11482. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  11483. }
  11484. var h = window.requestAnimationFrame;
  11485. window.requestAnimationFrame = function(c) {
  11486. return h(function(b) {
  11487. v.timeline._updateAnimationsPromises();
  11488. c(b);
  11489. v.timeline._updateAnimationsPromises()
  11490. })
  11491. }
  11492. ;
  11493. v.AnimationTimeline = function() {
  11494. this._animations = [];
  11495. this.currentTime = void 0
  11496. }
  11497. ;
  11498. v.AnimationTimeline.prototype = {
  11499. getAnimations: function() {
  11500. this._discardAnimations();
  11501. return this._animations.slice()
  11502. },
  11503. _updateAnimationsPromises: function() {
  11504. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  11505. return c._updatePromises()
  11506. })
  11507. },
  11508. _discardAnimations: function() {
  11509. this._updateAnimationsPromises();
  11510. this._animations = this._animations.filter(function(c) {
  11511. return "finished" != c.playState && "idle" != c.playState
  11512. })
  11513. },
  11514. _play: function(c) {
  11515. c = new v.Animation(c,this);
  11516. this._animations.push(c);
  11517. v.restartWebAnimationsNextTick();
  11518. c._updatePromises();
  11519. c._animation.play();
  11520. c._updatePromises();
  11521. return c
  11522. },
  11523. play: function(c) {
  11524. c && c.remove();
  11525. return this._play(c)
  11526. }
  11527. };
  11528. var d = !1;
  11529. v.restartWebAnimationsNextTick = function() {
  11530. d || (d = !0,
  11531. requestAnimationFrame(f))
  11532. }
  11533. ;
  11534. var a = new v.AnimationTimeline;
  11535. v.timeline = a;
  11536. try {
  11537. Object.defineProperty(window.document, "timeline", {
  11538. configurable: !0,
  11539. get: function() {
  11540. return a
  11541. }
  11542. })
  11543. } catch (c) {}
  11544. try {
  11545. window.document.timeline = a
  11546. } catch (c) {}
  11547.  
  11548. */
  11549.  
  11550.  
  11551.  
  11552. /*
  11553.  
  11554. var g = window.getComputedStyle;
  11555. Object.defineProperty(window, "getComputedStyle", {
  11556. configurable: !0,
  11557. enumerable: !0,
  11558. value: function() {
  11559. v.timeline._updateAnimationsPromises();
  11560. var e = g.apply(this, arguments);
  11561. h() && (e = g.apply(this, arguments));
  11562. v.timeline._updateAnimationsPromises();
  11563. return e
  11564. }
  11565. });
  11566.  
  11567. */
  11568.  
  11569.  
  11570.  
  11571.  
  11572. }
  11573.  
  11574.  
  11575.  
  11576.  
  11577. })();
  11578.  
  11579. !isUrlInEmbed && Promise.resolve().then(() => {
  11580.  
  11581. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11582.  
  11583.  
  11584.  
  11585. class LimitedSizeSet extends Set {
  11586. constructor(n) {
  11587. super();
  11588. this.limit = n;
  11589. }
  11590.  
  11591. add(key) {
  11592. if (!super.has(key)) {
  11593. super.add(key);
  11594. let n = super.size - this.limit;
  11595. if (n > 0) {
  11596. const iterator = super.values();
  11597. do {
  11598. const firstKey = iterator.next().value; // Get the first (oldest) key
  11599. super.delete(firstKey); // Delete the oldest key
  11600. } while (--n > 0)
  11601. }
  11602. }
  11603. }
  11604.  
  11605. removeAdd(key) {
  11606. super.delete(key);
  11607. this.add(key);
  11608. }
  11609.  
  11610. }
  11611.  
  11612. // const wk3 = new WeakMap();
  11613.  
  11614. // let mtxVideoId = '';
  11615. // let aje3 = [];
  11616. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11617. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11618. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11619. let mtzCount = 0; // the key keeps unchanged
  11620. // let mjtNextMainKey = '';
  11621. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11622. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11623. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11624. // let allowNoDelay322=false;
  11625. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11626.  
  11627. let mpKey22 = ''; // last success continutation key & url pair
  11628. let mpUrl22 = ''; // last success continutation key & url pair
  11629. let mpKey21 = ''; // latest requested continutation key & url pair
  11630. let mpUrl21 = ''; // latest requested continutation key & url pair
  11631.  
  11632.  
  11633. async function sha1Hex(message) {
  11634. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11635. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11636. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11637. const hashHex = hashArray
  11638. .map((b) => b.toString(16).padStart(2, "0"))
  11639. .join(""); // convert bytes to hex string
  11640. return hashHex;
  11641. }
  11642.  
  11643. async function continuationLog(a, ...args) {
  11644. let b = a;
  11645. try {
  11646. if (advanceLogging) b = await sha1Hex(a);
  11647. let c = args.map(e => {
  11648. return e === a ? b : e
  11649. });
  11650. console.log(...c)
  11651. } catch (e) { console.warn(e) }
  11652. }
  11653.  
  11654. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11655.  
  11656.  
  11657. if (mfvContinuationRecorded.length > 0) {
  11658. for (const [e, d] of mfvContinuationRecorded) {
  11659. mfyContinuationIgnored.removeAdd(e);
  11660. }
  11661. toClearRecorded && mfvContinuationRecorded.clear();
  11662. }
  11663.  
  11664. }
  11665.  
  11666. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11667.  
  11668. const tmProto = taskMgr.constructor.prototype;
  11669. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11670.  
  11671. if (!tmProto.addJob714) {
  11672.  
  11673. tmProto.addJob714 = tmProto.addJob;
  11674.  
  11675. tmProto.addJob = function (a, b, c) {
  11676. const jobId = this.addJob714(a, b, c);
  11677. if (jobId > 0) {
  11678. // const ez = wk3.get(this);
  11679. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11680. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11681.  
  11682. this.__lastJobId863__ = jobId;
  11683. }
  11684. return jobId;
  11685. }
  11686.  
  11687. }
  11688.  
  11689. if (!tmProto.cancelJob714) {
  11690.  
  11691. tmProto.cancelJob714 = tmProto.cancelJob;
  11692.  
  11693. tmProto.cancelJob = function (a) {
  11694. const res = this.cancelJob714(a);
  11695. // if (a > 0) {
  11696. // for (const e of aje3) {
  11697. // if (e.jobId === a) e.cancelled = true;
  11698. // }
  11699. // }
  11700. return res;
  11701. }
  11702.  
  11703. }
  11704.  
  11705. }
  11706. }
  11707.  
  11708.  
  11709. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11710.  
  11711.  
  11712. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11713. let dummy;
  11714. let cProto;
  11715. // let mc = 4;
  11716. // dummy = await observablePromise(() => {
  11717. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11718. // if (!r) return;
  11719. // let cProto = insp(r).constructor.prototype;
  11720. // if (cProto.fetchUpdatedMetadata) return r;
  11721. // if (--mc < 0) return -1;
  11722. // return null;
  11723. // }).obtain();
  11724. dummy = document.createElement('ytd-video-primary-info-renderer');
  11725. if (!(dummy instanceof Element)) return;
  11726. // console.log(5022, dummy)
  11727. cProto = insp(dummy).constructor.prototype;
  11728.  
  11729. cProto.__getEmittorTaskMgr859__ = function () {
  11730. let taskMgr_ = null;
  11731. try {
  11732. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  11733. } catch (e) { }
  11734. return taskMgr_;
  11735. }
  11736. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  11737. // console.log(1234, cProto, cProto.is)
  11738. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  11739.  
  11740. let c_;
  11741. cProto.fetchUpdatedMetadata718 = function (a) {
  11742. // delay or immediate call the actual fetchUpdatedMetadata
  11743.  
  11744. let doImmediately = false;
  11745. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  11746.  
  11747. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  11748.  
  11749. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  11750.  
  11751. doImmediately = true;
  11752.  
  11753. }
  11754.  
  11755. if (mbCId322) {
  11756. clearTimeout(mbCId322);
  11757. mbCId322 = 0;
  11758. }
  11759.  
  11760. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  11761.  
  11762. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  11763.  
  11764. mbCId322 = setTimeout(() => {
  11765. this.fetchUpdatedMetadata717(a);
  11766. }, delay);
  11767.  
  11768. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  11769.  
  11770. }
  11771.  
  11772. cProto.fetchUpdatedMetadata = function (a) {
  11773.  
  11774. if (!pageSetupState) {
  11775. if (c_) clearTimeout(c_);
  11776. c_ = setTimeout(() => {
  11777. this.fetchUpdatedMetadata718(a);
  11778. }, 300);
  11779. return;
  11780. }
  11781.  
  11782. // pageSetupState == 0
  11783.  
  11784. try {
  11785.  
  11786. mbDelayBelowNCalls++;
  11787.  
  11788. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  11789. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  11790. }
  11791.  
  11792. // console.log('fum377', a)
  11793. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  11794. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  11795. return;
  11796. }
  11797.  
  11798. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  11799. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  11800. mjtLockPreviousKey = mjtRecordedPrevKey;
  11801. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  11802. }
  11803. // mjtNextMainKey = true;
  11804. mtzlastAllowedContinuation = '';
  11805. mtzCount = 0;
  11806. // allowNoDelay322 = false;
  11807. // fetch new metadata, cancel all previous continuations
  11808. copyPreviousContiuationToIgnored374(true);
  11809. } else if (typeof a === 'string') {
  11810. const videoPlayingId = videoPlayingY.videoId;
  11811.  
  11812. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  11813.  
  11814. let update21 = !!pageSetupVideoId;
  11815. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  11816. update21 = true;
  11817. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  11818. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  11819. return;
  11820. }
  11821. if (update21) {
  11822. mpKey21 = a;
  11823. mpUrl21 = pageSetupVideoId || videoPlayingId;
  11824. }
  11825.  
  11826. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  11827. }
  11828. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  11829. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  11830. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  11831. return this.fetchUpdatedMetadata718(a);
  11832.  
  11833. } catch (e) {
  11834. console.log('Code Error in fetchUpdatedMetadata', e);
  11835. }
  11836. return this.fetchUpdatedMetadata717(a)
  11837. }
  11838. }
  11839.  
  11840.  
  11841. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  11842. // console.log(1234, cProto, cProto.is)
  11843. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  11844. let mJob = null;
  11845.  
  11846. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  11847.  
  11848. try {
  11849.  
  11850. if (arguments.length > 0) {
  11851. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  11852. }
  11853. // mfy = mfv;
  11854.  
  11855. // mjtNextMainKey = '';
  11856. mtzlastAllowedContinuation = '';
  11857. mtzCount = 0;
  11858. if (mbCId322) {
  11859. clearTimeout(mbCId322);
  11860. mbCId322 = 0;
  11861. }
  11862. mbDelayBelowNCalls = 0;
  11863. // allowNoDelay322 = false;
  11864. copyPreviousContiuationToIgnored374(true);
  11865.  
  11866. const taskMgr = this.__getEmittorTaskMgr859__();
  11867. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  11868. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  11869. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  11870. }
  11871.  
  11872. // prevent depulicated schedule job by clearing previous JobId
  11873. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  11874.  
  11875. let res;
  11876.  
  11877. if (mJob) {
  11878. const job = mJob;
  11879. mJob = null;
  11880. console.log('cancelJob', job)
  11881. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  11882. // p.cancelJob(a,b);
  11883. }
  11884.  
  11885. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  11886.  
  11887. let pza = taskMgr.__lastJobId863__;
  11888. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  11889. let pzb = taskMgr.__lastJobId863__
  11890. if (pza !== pzb) {
  11891. mJob = pzb; // set [Interval Meta Update] jobId
  11892. }
  11893.  
  11894. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  11895. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  11896. // } else {
  11897. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  11898. // }
  11899.  
  11900. return res;
  11901.  
  11902. } else {
  11903. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  11904. }
  11905.  
  11906. } catch (e) {
  11907. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  11908. }
  11909.  
  11910.  
  11911. return this.scheduleInitialUpdatedMetadataRequest717();
  11912. }
  11913. }
  11914.  
  11915.  
  11916. });
  11917.  
  11918. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  11919. let dummy;
  11920. let cProto;
  11921. dummy = ytAppDom;
  11922. if (!(dummy instanceof Element)) return;
  11923. cProto = insp(dummy).constructor.prototype;
  11924. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  11925. // console.log(1234, cProto, cProto.is);
  11926. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11927. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  11928. // console.log(123401, arguments);
  11929. // return this.handleServiceRequest717_(a, b, c, d);
  11930. // }
  11931.  
  11932. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11933.  
  11934. // cProto.handleServiceRequest_ = function(a,b,c,d){
  11935. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11936. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  11937. // console.log('mfv', c.continuation);
  11938. // mfv.add( c.continuation);
  11939. // }
  11940. // return this.handleServiceRequest717_(a,b,c,d);
  11941. // }
  11942.  
  11943. function extraArguments322(a, b, c) {
  11944. let is = (a || 0).is;
  11945. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  11946. let continuation = (c || 0).continuation;
  11947. if (typeof is !== 'string') is = null;
  11948. if (typeof videoId !== 'string') videoId = null;
  11949. if (typeof continuation !== 'string') continuation = null;
  11950. return { is, videoId, continuation };
  11951. }
  11952.  
  11953. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  11954. cProto.sendServiceAjax_ = function (a, b, c, d) {
  11955.  
  11956. // console.log(8001)
  11957. try {
  11958.  
  11959. const { is, videoId, continuation } = extraArguments322(a, b, c);
  11960.  
  11961. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11962. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  11963. }
  11964.  
  11965. if (pageSetupVideoId && videoId && continuation) {
  11966. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11967. mfyContinuationIgnored.removeAdd(continuation);
  11968. mfvContinuationRecorded.delete(continuation);
  11969. return;
  11970. }
  11971. }
  11972.  
  11973. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11974. copyPreviousContiuationToIgnored374(false);
  11975. mfyContinuationIgnored.delete(continuation);
  11976. mfvContinuationRecorded.removeAdd(continuation);
  11977. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11978. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11979. mjtLockPreviousKey = '';
  11980. }
  11981. // if (mjtNextMainKey === continuation) {
  11982. // copyPreviousContiuationToIgnored(false);
  11983. // mfyContinuationIgnored.delete(continuation);
  11984. // mfvContinuationRecorded.add(continuation);
  11985. // }
  11986.  
  11987.  
  11988. if (mfyContinuationIgnored && continuation) {
  11989. if (mfyContinuationIgnored.has(continuation)) {
  11990. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  11991. return;
  11992. }
  11993. }
  11994.  
  11995. // console.log(59902, a?.is, b,c,d)
  11996. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11997. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  11998. // console.log('mfv377', continuation);
  11999. mfvContinuationRecorded.add(continuation);
  12000. }
  12001.  
  12002. // if (videoId) {
  12003. // if (!pageSetupVideoId) return; // ignore page not ready
  12004. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12005. // if (videoId !== pageSetupVideoId) {
  12006. // return;
  12007. // }
  12008. // }
  12009.  
  12010. } catch (e) {
  12011. console.log('Coding Error in sendServiceAjax_', e)
  12012. }
  12013. // console.log(8002)
  12014. // console.log(123402, arguments);
  12015. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  12016.  
  12017. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  12018. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  12019. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  12020. // get(target, prop, receiver){
  12021. // console.log('xxs99', target.videoId, mtx)
  12022. // if(prop ==='kdkw33') return 1;
  12023. // console.log(3322, prop, target)
  12024. // if(prop === 'initialDelayMs') {
  12025. // throw new Error("ABCC");
  12026. // }
  12027. // return target[prop];
  12028. // },
  12029. // set(target, prop, value, receiver){
  12030.  
  12031. // if(prop ==='kdkw33') return true;
  12032. // target[prop]=value;
  12033. // return true;
  12034. // }
  12035. // });
  12036. // }
  12037. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  12038. return this.sendServiceAjax717_(a, b, c, d);
  12039. }
  12040. }
  12041.  
  12042. function delayClearOtherKeys(lztContinuation) {
  12043. // // schedule delayed removal if mfyContinuationIgnored is not empty
  12044. // getRafPromise().then(() => {
  12045. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  12046. // // foreground page only
  12047.  
  12048. // });
  12049.  
  12050.  
  12051. if (lztContinuation !== mtzlastAllowedContinuation) return;
  12052. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  12053. if (!mfyContinuationIgnored.size) return;
  12054. if (mfyContinuationIgnored.size > 1) {
  12055. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  12056. }
  12057. mfyContinuationIgnored.forEach((value, key) => {
  12058. if (key !== lztContinuation) {
  12059. mfyContinuationIgnored.delete(key);
  12060. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  12061. }
  12062. });
  12063.  
  12064. }
  12065. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  12066. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  12067. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  12068.  
  12069. // console.log(8003)
  12070. try {
  12071.  
  12072.  
  12073. const { is, videoId, continuation } = extraArguments322(b, c, d);
  12074.  
  12075. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12076. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  12077. }
  12078.  
  12079. if (pageSetupVideoId && videoId && continuation) {
  12080. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12081. mfyContinuationIgnored.removeAdd(continuation);
  12082. mfvContinuationRecorded.delete(continuation);
  12083. return;
  12084. }
  12085. }
  12086.  
  12087. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12088. copyPreviousContiuationToIgnored374(false);
  12089. mfyContinuationIgnored.delete(continuation);
  12090. mfvContinuationRecorded.removeAdd(continuation);
  12091. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12092. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12093. mjtLockPreviousKey = '';
  12094. }
  12095.  
  12096. // if (mjtNextMainKey === continuation) {
  12097. // copyPreviousContiuationToIgnored(false);
  12098. // mfyContinuationIgnored.delete(continuation);
  12099. // mfvContinuationRecorded.add(continuation);
  12100. // }
  12101.  
  12102. const lztContinuation = continuation;
  12103.  
  12104. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  12105. if (mfyContinuationIgnored.has(lztContinuation)) {
  12106. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  12107. return;
  12108. }
  12109. }
  12110.  
  12111. // if (videoId) {
  12112. // if (!pageSetupVideoId) return; // ignore page not ready
  12113. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12114. // if (videoId !== pageSetupVideoId) {
  12115. // return;
  12116. // }
  12117. // }
  12118.  
  12119. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  12120. mtzlastAllowedContinuation = lztContinuation;
  12121. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  12122.  
  12123. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12124. mjtRecordedPrevKey = lztContinuation;
  12125. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  12126. // if (mfyContinuationIgnored.size > 0) {
  12127. // delayClearOtherKeys(lztContinuation);
  12128. // }
  12129. mtzCount = 0;
  12130. // allowNoDelay322 = false;
  12131. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  12132. // repeated
  12133. if (++mtzCount > 1e9) mtzCount = 1e4;
  12134. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12135.  
  12136. // if (mtzCount >= 3) allowNoDelay322 = true;
  12137. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  12138. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  12139. }
  12140. if (mtzCount === 5) {
  12141. mfvContinuationRecorded.clear();
  12142. mfvContinuationRecorded.add(lztContinuation);
  12143. }
  12144.  
  12145. }
  12146.  
  12147. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  12148. mpKey22 = lztContinuation;
  12149. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  12150. }
  12151.  
  12152. if (mbCId322) {
  12153. clearTimeout(mbCId322);
  12154. mbCId322 = 0;
  12155. }
  12156. } catch (e) {
  12157. console.log('Coding Error in getCancellableNetworkPromise_', e)
  12158. }
  12159.  
  12160. // console.log(8004)
  12161. // console.log(123403, arguments);
  12162. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  12163.  
  12164. // console.log(5163, a?.is,b,c,d,e);
  12165. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  12166. }
  12167. }
  12168. });
  12169.  
  12170. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  12171.  
  12172.  
  12173. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  12174.  
  12175. let dummy;
  12176. let cProto;
  12177.  
  12178. dummy = document.createElement('ytd-expander');
  12179. cProto = insp(dummy).constructor.prototype;
  12180.  
  12181. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  12182.  
  12183. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  12184. cProto.childrenChanged14 = cProto.childrenChanged;
  12185.  
  12186. cProto.initChildrenObserver = function () {
  12187. var a = this;
  12188. this.observer = new MutationObserver(function () {
  12189. a.childrenChanged()
  12190. }
  12191. );
  12192. this.observer.observe(this.content, {
  12193. subtree: !0,
  12194. childList: !0,
  12195. attributes: !0,
  12196. characterData: !0
  12197. });
  12198. this.childrenChanged()
  12199. }
  12200. ;
  12201. cProto.childrenChanged = function () {
  12202. if (this.alwaysToggleable) {
  12203. this.canToggle = this.alwaysToggleable;
  12204. } else if (!this.canToggleJobId) {
  12205. this.canToggleJobId = 1;
  12206. foregroundPromiseFn().then(() => {
  12207. this.canToggleJobId = 0;
  12208. this.calculateCanCollapse()
  12209. })
  12210. }
  12211. }
  12212.  
  12213. // console.log(cProto.initChildrenObserver)
  12214. console.debug('ytd-expander-fix-childrenChanged');
  12215.  
  12216. }
  12217.  
  12218. });
  12219.  
  12220.  
  12221. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  12222.  
  12223. let dummy;
  12224. let cProto;
  12225. dummy = document.createElement('paper-ripple');
  12226. cProto = insp(dummy).constructor.prototype;
  12227.  
  12228. if (fnIntegrity(cProto.animate, '0.74.5')) {
  12229.  
  12230.  
  12231. cProto.animate34 = cProto.animate;
  12232. cProto.animate = function () {
  12233. if (this._animating) {
  12234. var a;
  12235. const ripples = this.ripples;
  12236. for (a = 0; a < ripples.length; ++a) {
  12237. var b = ripples[a];
  12238. b.draw();
  12239. this.$.background.style.opacity = b.outerOpacity;
  12240. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  12241. }
  12242. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  12243. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  12244. foregroundPromiseFn().then(this._boundAnimate38);
  12245. } else {
  12246. this.onAnimationComplete();
  12247. }
  12248. }
  12249. }
  12250.  
  12251. console.debug('FIX_paper_ripple_animate')
  12252.  
  12253. // console.log(cProto.animate)
  12254.  
  12255. }
  12256.  
  12257. });
  12258.  
  12259. if (FIX_doIdomRender) {
  12260.  
  12261. const xsetTimeout = function (f, d) {
  12262. if (xsetTimeout.m511 === 1 && !d) {
  12263. xsetTimeout.m511 = 2;
  12264. xsetTimeout.m568 = f;
  12265. } else {
  12266. return setTimeout.apply(window, arguments)
  12267. }
  12268.  
  12269. }
  12270.  
  12271. /**
  12272. *
  12273. IGb = function(a) {
  12274. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  12275. c || (a.requestAninmationFrameResolver = new Vi,
  12276. c = a.requestAninmationFrameResolver.promise,
  12277. Da.requestAnimationFrame(function() {
  12278. var d;
  12279. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  12280. a.requestAninmationFrameResolver = null
  12281. }));
  12282. return c
  12283. }
  12284.  
  12285.  
  12286. */
  12287.  
  12288. const xrequestAnimationFrame = function (f) {
  12289. const h = `${f}`;
  12290. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  12291. let t = null;
  12292. xsetTimeout.m511 = 1;
  12293. f();
  12294. if (xsetTimeout.m511 === 2) {
  12295. t = xsetTimeout.m568;
  12296. xsetTimeout.m568 = null;
  12297. }
  12298. xsetTimeout.m511 = 0;
  12299. if (typeof t === 'function') {
  12300. foregroundPromiseFn().then(t);
  12301. }
  12302. } else if (h.includes("requestAninmationFrameResolver")) {
  12303. foregroundPromiseFn().then(f);
  12304. } else {
  12305. return requestAnimationFrame.apply(window, arguments);
  12306. }
  12307. }
  12308.  
  12309. let busy = false;
  12310. const doIdomRender = function () {
  12311.  
  12312. if (!this) return;
  12313. if (busy) {
  12314. return this.doIdomRender13(...arguments);
  12315. }
  12316. busy = true;
  12317. const { requestAnimationFrame, setTimeout } = window;
  12318. window.requestAnimationFrame = xrequestAnimationFrame;
  12319. window.setTimeout = xsetTimeout;
  12320. let r = this.doIdomRender13(...arguments);
  12321. window.requestAnimationFrame = requestAnimationFrame;
  12322. window.setTimeout = setTimeout;
  12323. busy = false;
  12324. return r;
  12325. };
  12326. 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']) {
  12327.  
  12328.  
  12329. whenCEDefined(ytTag).then(() => {
  12330.  
  12331. let dummy;
  12332. let cProto;
  12333. dummy = document.createElement(ytTag);
  12334. cProto = insp(dummy).constructor.prototype;
  12335.  
  12336. cProto.doIdomRender13 = cProto.doIdomRender;
  12337. cProto.doIdomRender = doIdomRender;
  12338.  
  12339. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  12340.  
  12341. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  12342.  
  12343.  
  12344.  
  12345. });
  12346.  
  12347. }
  12348.  
  12349. }
  12350.  
  12351.  
  12352.  
  12353.  
  12354. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  12355.  
  12356. const sMap = new Map();
  12357.  
  12358. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  12359. const ZT = function () {
  12360. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  12361. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  12362. c = b & 15,
  12363. b >>= 4,
  12364. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  12365. return a.join("")
  12366. };
  12367.  
  12368.  
  12369. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  12370.  
  12371. const popupContainer = await observablePromise(() => {
  12372. return popupContainerCollection[0];
  12373. }).obtain();
  12374.  
  12375.  
  12376. let cProto;
  12377. cProto = insp(popupContainer).constructor.prototype;
  12378.  
  12379.  
  12380. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  12381. console.log('FIX_POPUP_UNIQUE_ID NG')
  12382. return;
  12383. }
  12384. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  12385.  
  12386. cProto.handleOpenPopupAction = function (a, b) {
  12387.  
  12388. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  12389.  
  12390. a.__jOdQA__ = true;
  12391.  
  12392. try {
  12393.  
  12394. const h = this.hostElement;
  12395.  
  12396. if (h instanceof HTMLElement_) {
  12397.  
  12398. const map = h.__skme44__ = h.__skme44__ || new Map();
  12399.  
  12400. let mKey = '';
  12401. const wKey = firstObjectKey(a);
  12402. const wObj = wKey ? a[wKey] : null;
  12403. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  12404. const pKey = firstObjectKey(wObj.popup)
  12405. const pObj = pKey ? wObj.popup[pKey] : null;
  12406. let contentKey = '';
  12407. let headerKey = '';
  12408.  
  12409. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  12410. contentKey = firstObjectKey(pObj.content)
  12411. headerKey = firstObjectKey(pObj.header)
  12412. }
  12413. if (contentKey && headerKey) {
  12414.  
  12415. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  12416.  
  12417. if (mKey) {
  12418.  
  12419. if (!wObj.uniqueId) {
  12420. for (let i = 0; i < 8; i++) {
  12421. wObj.uniqueId = ZT();
  12422. if (!sMap.has(wObj.uniqueId)) break;
  12423. }
  12424. }
  12425. const oId = wObj.uniqueId
  12426.  
  12427. let nId_ = map.get(mKey);
  12428. if (!nId_) {
  12429. map.set(mKey, nId_ = oId);
  12430. }
  12431.  
  12432. wObj.uniqueId = nId_ || wObj.uniqueId;
  12433.  
  12434. const nId = wObj.uniqueId
  12435.  
  12436. sMap.set(oId, nId);
  12437. sMap.set(nId, nId);
  12438.  
  12439. wObj.uniqueId = nId;
  12440. pObj.targetId = nId;
  12441. pObj.identifier.tag = nId;
  12442.  
  12443. if (oId !== nId) {
  12444. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  12445. }
  12446.  
  12447. }
  12448.  
  12449. }
  12450. }
  12451.  
  12452. // console.log(12213, mKey, a, b, h)
  12453.  
  12454. }
  12455.  
  12456. } catch (e) {
  12457. console.warn(e)
  12458. }
  12459.  
  12460. try {
  12461.  
  12462. const results = searchNestedObject(a, (x) => {
  12463. if (typeof x === 'string' && x.length === 36) {
  12464. 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;
  12465. }
  12466. return false;
  12467. });
  12468. for (const [obj, key] of results) {
  12469. const oId = obj[key];
  12470. const nId = sMap.get(oId);
  12471. if (nId) obj[key] = nId;
  12472. }
  12473. } catch (e) {
  12474. console.warn(e)
  12475. }
  12476.  
  12477.  
  12478. }
  12479.  
  12480. return this.handleOpenPopupAction3868(...arguments)
  12481. }
  12482.  
  12483. console.log('FIX_POPUP_UNIQUE_ID OK')
  12484.  
  12485.  
  12486. });
  12487.  
  12488.  
  12489. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  12490.  
  12491. let dummy;
  12492. let cProto;
  12493. dummy = document.createElement('yt-formatted-string');
  12494. cProto = insp(dummy).constructor.prototype;
  12495.  
  12496. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  12497. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  12498. return;
  12499. }
  12500.  
  12501. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  12502. cProto.setNodeStyle_ = function (a, b) {
  12503. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  12504. return this.setNodeStyle17_(a, b);
  12505. }
  12506.  
  12507. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  12508. });
  12509.  
  12510. });
  12511.  
  12512. });
  12513.  
  12514.  
  12515.  
  12516.  
  12517. if (isMainWindow) {
  12518.  
  12519. console.groupCollapsed(
  12520. "%cYouTube JS Engine Tamer",
  12521. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  12522. );
  12523.  
  12524.  
  12525.  
  12526. console.log("Script is loaded.");
  12527. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  12528.  
  12529. console.log("This script is experimental and subject to further changes.");
  12530.  
  12531. console.log("This might boost your YouTube performance.");
  12532.  
  12533. console.log("CAUTION: This might break your YouTube.");
  12534.  
  12535.  
  12536. if (prepareLogs.length >= 1) {
  12537. console.log(" =========================================================================== ");
  12538.  
  12539. for (const msg of prepareLogs) {
  12540. console.log(msg)
  12541. }
  12542.  
  12543. console.log(" =========================================================================== ");
  12544. }
  12545.  
  12546. console.groupEnd();
  12547.  
  12548. }
  12549.  
  12550.  
  12551.  
  12552. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址