YouTube JS Engine Tamer

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

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

  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.9
  8. // @match https://www.youtube.com/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @match https://studio.youtube.com/live_chat*
  11. // @license MIT
  12. // @author CY Fung
  13. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  14. // @grant none
  15. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@c2b707e4977f77792042d4a5015fb188aae4772e/library/nextBrowserTick.min.js
  16. // @run-at document-start
  17. // @unwrap
  18. // @inject-into page
  19. // @allFrames true
  20. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  21. //
  22. // @description To enhance YouTube performance by modifying YouTube JS Engine
  23. // @description:ja YouTubeのJSエンジンを変更してパフォーマンスを向上させる
  24. // @description:zh-TW 修改 YouTube 的 JS 引擎以提升效能
  25. // @description:zh-CN 修改 YouTube 的 JS 引擎以提升性能
  26. //
  27. // ==/UserScript==
  28.  
  29. (() => {
  30.  
  31. /** @type {WeakMapConstructor} */
  32. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  33.  
  34. const HOOK_ACTIVE_MODULES = true; // added in 0.37.0
  35. const HOOK_ACTIVE_MODULES_fetchUpdatedMetadata = true; // added in 0.37.0 (make likeCount update)
  36. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  37. const FIX_schedulerInstanceInstance = 2 | 4;
  38. const FIX_yt_player = true; // DONT CHANGE
  39. const FIX_Animation_n_timeline = true;
  40. const FIX_Animation_n_timeline_cinematic = true;
  41. const FIX_ytScheduler = true;
  42. const NO_PRELOAD_GENERATE_204 = false;
  43. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  44. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  45. const CHANGE_appendChild = true; // discussions#236759
  46. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  47.  
  48. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  49.  
  50. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  51.  
  52. const FIX_ytdExpander_childrenChanged = true;
  53. const FIX_paper_ripple_animate = true;
  54. const FIX_avoid_incorrect_video_meta = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  55. const FIX_avoid_incorrect_video_meta_emitterBehavior = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  56.  
  57. const FIX_doIdomRender = true;
  58.  
  59. const FIX_Shady = true;
  60.  
  61. // [[ 2024.04.24 ]]
  62. const MODIFY_ShadyDOM_OBJ = true; // DON'T CHANGE. MUST BE TRUE
  63. // << if MODIFY_ShadyDOM_OBJ >>
  64. const WEAKREF_ShadyDOM = true;
  65. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  66. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  67. // << end >>
  68.  
  69. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  70.  
  71. const FIX_ytAction_ = true; // ytd-app
  72. const FIX_onVideoDataChange = false;
  73. // const FIX_onClick = true;
  74. const FIX_onStateChange = true;
  75. const FIX_onLoopRangeChange = true;
  76. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  77. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  78.  
  79. const FIX_stampDomArray_ = true; // v0.30.0
  80. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  81. // const stampDomArray_MemoryFix_Flag001 = false;
  82. const XFlag = true; // root issue tbc
  83. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  84. // 32 required for new stampDomArray
  85. // 128 to be tested
  86.  
  87. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  88. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  89.  
  90. const FIX_Polymer_dom = true;
  91. const FIX_Polymer_AF = true;
  92.  
  93. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  94. const DEBUG_removePrune = false; // true for DEBUG
  95.  
  96. const FIX_XHR_REQUESTING = true;
  97.  
  98. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  99.  
  100. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  101.  
  102. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  103. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  104.  
  105. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  106.  
  107. const FIX_removeChild = true;
  108. const FIX_fix_requestIdleCallback_timing = true;
  109.  
  110. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  111. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  112.  
  113. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  114.  
  115. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  116.  
  117. // ------------------------------------------------------------------
  118.  
  119. const MEMORY_RELEASE_NF00 = true;
  120. const MEMORY_RELEASE_NF00_SHOW_MESSAGE = false;
  121. const MEMORY_RELEASE_MAP_SET_REMOVE_NODE = true;
  122. const FULLY_REMOVE_ALL_EVENT_LISTENERS = true; // require MEMORY_RELEASE_NF00
  123. const FUZZY_EVENT_LISTENER_REMOVAL = true;
  124. const WEAK_CE_ROOT = true; // shadowRoot of the return value of attachShadow on the node
  125.  
  126. const FIX_TEMPLATE_BINDING = true;
  127. const FIX_TEMPLATE_BINDING_SHOW_MESSAGE = false;
  128.  
  129. const FIX_SHADY_METHODS = true;
  130. const FIX_FRAGEMENT_HOST = true;
  131.  
  132. const USE_fastDomIf = 2; // fastDomIf is seem to be experimental 0 = no change, 1 = enable, 2 = disable
  133. const ENHANCE_DOMIF_createAndInsertInstance = true; // root does not need to store in the instance
  134. const ENHANCE_DOMIF_TEARDOWN = true; // require MEMORY_RELEASE_NF00
  135.  
  136. const FIX_DOM_IF_DETACH = true;
  137. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  138. const FIX_DOM_IF_TEMPLATE = true;
  139. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  140.  
  141. const DEBUG_DBR847 = false;
  142. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  143.  
  144. const FIX_ICON_RENDER = true;
  145. const FIX_GUIDE_ICON = true;
  146. const FIX_ACTIONS_TOOLTIPS = true;
  147.  
  148. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  149.  
  150. const DISABLE_isLowLatencyLiveStream = false; // TBC
  151.  
  152. const FIX_FlexibleItemSizing = true;
  153. const FIX_ROLLING_NUMBER_UPDATE = true;
  154.  
  155.  
  156. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  157. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  158. // first tp-yt-paper-dialog: show once the page is loaded.
  159. // second tp-yt-paper-dialog: click "...more"
  160. // third tp-yt-paper-dialog: click "... and 3 more links"
  161. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  162. // currently, uniqueId is preassigned by the network resolveCommand.
  163. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  164. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  165.  
  166. // handleOpenPopupAction -> createCacheKey
  167. // handleClosePopupAction_ -> createCacheKey
  168. // handleGetPopupOpenedAction_ -> createCacheKey
  169. // getAndMaybeCreatePopup_ -> createCacheKey
  170. // closePopup -> createCacheKey
  171.  
  172. // yt-close-popup-command -> handleClosePopupCommand_
  173.  
  174. // ensurePopup_ -> getAndMaybeCreatePopup_
  175.  
  176. // yt-close-popup-action -> handleClosePopupAction_
  177. // closePopup -> handleClosePopupAction_
  178. // handleOpenPopupAction -> handleClosePopupAction_
  179. // handleClosePopupCommand_ -> handleClosePopupAction_
  180. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  181.  
  182. // yt-open-popup-action -> handleOpenPopupAction
  183.  
  184.  
  185. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  186. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  187.  
  188. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  189. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  190. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  191.  
  192.  
  193. // ----------------------------- Shortkey Keyboard Control -----------------------------
  194. // dependency: FIX_yt_player
  195.  
  196. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  197. // [0] no fix - not recommended
  198. // [1] basic fix - just fix the global focus detection variable
  199. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  200. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  201.  
  202. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  203. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  204.  
  205. const PROP_OverReInclusion_AVOID = true;
  206. const PROP_OverReInclusion_DEBUGLOG = false;
  207. const PROP_OverReInclusion_LIST = new Set([
  208. 'hostElement72',
  209. 'parentComponent72',
  210. 'localVisibilityObserver_72',
  211. 'cachedProviderNode_72',
  212. '__template72',
  213. '__templatizeOwner72',
  214. '__templateInfo72',
  215. '__dataHost72',
  216. '__CE_shadowRoot72',
  217. 'elements_72',
  218.  
  219. 'ky36',
  220. 'kz62',
  221. 'm822',
  222.  
  223.  
  224.  
  225. // To be reviewed.
  226.  
  227. // chat messages
  228. 'disabled', 'allowedProps',
  229. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  230.  
  231. 'dimension', 'loadTime', 'pendingPaint',
  232.  
  233. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  234.  
  235. 'respectLangDir', 'noEndpoints',
  236.  
  237.  
  238. 'objectURL',
  239. 'buttonOverrides', 'queuedMessages',
  240. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  241. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  242. 'hoverJobId', 'JSC$14573_touched',
  243.  
  244.  
  245. // tbc
  246. 'toggleable', 'isConnected',
  247. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  248. 'disableDeselectEvent',
  249. 'emojiSize',
  250.  
  251. 'buttonOverride',
  252. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  253.  
  254. // others
  255. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  256. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  257. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  258. // 'dimension', 'loadTime', 'pendingPaint',
  259. // 'disabled', 'allowedProps',
  260.  
  261.  
  262. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  263. // 'actionMap',
  264.  
  265. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  266.  
  267. 'clearTimeout',
  268. 'switchTemplateAtRegistration', 'hasUnmounted',
  269. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  270. 'tangoConfiguration',
  271. 'itemIdToDockDurationMap',
  272. 'actionMap',
  273.  
  274. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  275. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  276. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  277.  
  278. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  279. // 'stopKeyboardEventPropagation', 'emojiSize',
  280. // 'switchTemplateAtRegistration', 'hasUnmounted',
  281. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  282. // 'isReusable', 'tangoConfiguration',
  283. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  284. // */
  285.  
  286. ]);
  287.  
  288.  
  289. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  290.  
  291. // ----------------------------- Shortkey Keyboard Control -----------------------------
  292.  
  293. /*
  294. window.addEventListener('edm',()=>{
  295. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  296. });
  297.  
  298. window.addEventListener('edn',()=>{
  299. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  300. });
  301. window.addEventListener('edr',()=>{
  302. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  303. });
  304. */
  305.  
  306. // only for macOS with Chrome/Firefox 100+
  307. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  308.  
  309. const win = this instanceof Window ? this : window;
  310.  
  311. // Create a unique key for the script and check if it is already running
  312. const hkey_script = 'jswylcojvzts';
  313. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  314. win[hkey_script] = true;
  315.  
  316.  
  317.  
  318. const wk = Symbol();
  319.  
  320. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  321.  
  322. let BY_PASS_KEYBOARD_CONTROL = false;
  323.  
  324.  
  325. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  326. /** @type {(f: ()=>{})=>{}} */
  327. const nextBrowserTick_ = nextBrowserTick;
  328. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  329. console.log('nextBrowserTick is not found.');
  330. return;
  331. }
  332.  
  333. let p59 = 0;
  334.  
  335. const Promise = (async () => { })().constructor;
  336.  
  337. const PromiseExternal = ((resolve_, reject_) => {
  338. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  339. return class PromiseExternal extends Promise {
  340. constructor(cb = h) {
  341. super(cb);
  342. if (cb === h) {
  343. /** @type {(value: any) => void} */
  344. this.resolve = resolve_;
  345. /** @type {(reason?: any) => void} */
  346. this.reject = reject_;
  347. }
  348. }
  349. };
  350. })();
  351.  
  352. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  353. constructor(callback = undefined) {
  354.  
  355. }
  356. register(target, heldValue, unregisterToken = undefined) {
  357.  
  358. }
  359. unregister(unregisterToken) {
  360.  
  361. }
  362. }
  363.  
  364. let ttpHTML = (s) => {
  365. ttpHTML = s => s;
  366. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  367. let s = s => s;
  368. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  369. }
  370. return s;
  371. }
  372.  
  373.  
  374. /** @type { typeof HTMLElement } */
  375. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  376. const nativeAppendE = HTMLElement_.prototype.append;
  377. const nativeRemoveE = HTMLElement_.prototype.remove;
  378. const DocumentFragment_ = DocumentFragment;
  379. const nativeAppendD = DocumentFragment_.prototype.append;
  380. const Node_ = Node;
  381.  
  382. /**
  383. @param {number} x
  384. @param {number} d */
  385. const toFixed2 = (x, d) => {
  386. let t = x.toFixed(d);
  387. let y = `${+t}`;
  388. return y.length > t.length ? t : y;
  389. }
  390.  
  391.  
  392. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  393.  
  394.  
  395. const TRANSLATE_DEBUG = false;
  396.  
  397.  
  398. let xdeadc00 = null; // a deteched node with __domApi
  399. let xlivec00 = null; // a deteched node with __domApi
  400.  
  401. let removeTNodeRM = null;
  402. let removeTNodeBP = false;
  403.  
  404.  
  405. if (Node.isConnectedOverrided === undefined) {
  406. const pdConnected = Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected');
  407. if (pdConnected && pdConnected.get && pdConnected.configurable) {
  408. Node.isConnectedOverrided = null;
  409. const get_ = pdConnected.get;
  410. const get = function () {
  411. const overrided = Node.isConnectedOverrided;
  412. if (typeof overrided === 'boolean') return overrided;
  413. return get_.call(this);
  414. }
  415. Object.defineProperty(Node.prototype, 'isConnected', {
  416. ...pdConnected,
  417. get
  418. });
  419. }
  420. }
  421.  
  422. const _nmSet = new Set();
  423. _nmSet.add = _nmSet.addOriginal || _nmSet.add;
  424. const _nmMap = new Set();
  425. _nmMap.add = _nmMap.addOriginal || _nmMap.add;
  426. const _nmMapV = new Set();
  427. _nmMapV.add = _nmMapV.addOriginal || _nmMapV.add;
  428. if (MEMORY_RELEASE_MAP_SET_REMOVE_NODE && !Set.prototype.addOriginal && !Map.prototype.setOriginal) {
  429. const Node_ = Node;
  430. Set.prototype.addOriginal = Set.prototype.add;
  431. Set.prototype.add = function (n) {
  432. if (n instanceof Node_) {
  433. if (!this[wk]) this[wk] = mWeakRef(this);
  434. _nmSet.add(this[wk]);
  435. }
  436. return this.addOriginal(n);
  437. };
  438. Map.prototype.setOriginal = Map.prototype.set;
  439. Map.prototype.set = function (n, v) {
  440. if (n instanceof Node_) {
  441. if (!this[wk]) this[wk] = mWeakRef(this);
  442. _nmMap.add(this[wk]);
  443. }
  444. if (v instanceof Node_) {
  445. if (!this[wk]) this[wk] = mWeakRef(this);
  446. _nmMapV.add(this[wk]);
  447. }
  448. return this.setOriginal(n, v);
  449. };
  450. }
  451.  
  452. window.showNM00 = () => {
  453. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  454. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  455. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  456. return { nmSet, nmMap, nmMapV };
  457. };
  458.  
  459. window.testNM00 = (x) => {
  460. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  461. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  462. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  463. for (const s of nmSet) if (s.has(x)) return 1;
  464. for (const m of nmMap) if (m.has(x)) return 2;
  465. for (const m of nmMapV) {
  466. for (const [u, v] of m.entries()) {
  467. if (v === x) return 4;
  468. }
  469. }
  470. return 0;
  471. };
  472.  
  473. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  474.  
  475. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  476.  
  477. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  478.  
  479. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  480.  
  481. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  482. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  483. return;
  484. }
  485.  
  486. const mapGet = Map.prototype.get;
  487. const setHas = Set.prototype.has;
  488.  
  489. /** @type {Map | null} */
  490. let qcMap = null;
  491.  
  492. Set.prototype.has = function (a) {
  493. if (a === 'dummy-4718') return false; // false to allow re-use?
  494. return setHas.call(this, a);
  495. }
  496.  
  497. Map.prototype.get = function (a) {
  498. if (a === 'dummy-4718') qcMap = this;
  499. return mapGet.call(this, a);
  500. };
  501. let r;
  502. try {
  503. r = mainCnt.createComponent_('dummy-4718', {}, true);
  504. } catch (e) {
  505.  
  506. }
  507.  
  508. Map.prototype.get = mapGet;
  509. Set.prototype.has = setHas;
  510.  
  511. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  512.  
  513.  
  514. // clearInterval(ckId);
  515. // ckId = 0;
  516.  
  517. if (qcMap !== null && qcMap instanceof Map) {
  518.  
  519. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  520. qcMap.__qcMap8781__ = true;
  521.  
  522. const setArrayC = (c) => {
  523. if (c instanceof Array) {
  524. c.length = 0;
  525. c.push = function () { };
  526. c.pop = function () { };
  527. c.shift = function () { };
  528. c.unshift = function () { };
  529. c.splice = function () { };
  530. c.sort = function () { };
  531. c.reverse = function () { };
  532. }
  533. }
  534.  
  535. const cleaning = function (m) {
  536. m.forEach(setArrayC);
  537. m.clear();
  538. }
  539.  
  540. qcMap.set = function (b, c) {
  541. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  542.  
  543. setArrayC(c);
  544.  
  545. // console.log('qcMap.set', b, c);
  546.  
  547. if (this.size > 0) {
  548. // play safe
  549.  
  550. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  551. cleaning(this);
  552. }
  553.  
  554. }
  555. qcMap.get = function (b) {
  556. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  557.  
  558. // console.log('qcMap.get', b);
  559.  
  560. if (this.size > 0) {
  561. // play safe
  562.  
  563. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  564. cleaning(this);
  565. }
  566.  
  567. }
  568.  
  569.  
  570. if (qcMap.size > 0) {
  571.  
  572. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  573. cleaning(qcMap);
  574. }
  575.  
  576. }
  577.  
  578. }
  579.  
  580. r = null;
  581. qcMap = null;
  582.  
  583. }
  584.  
  585. const renderPathMake = (elements) => {
  586. if(!elements) return;
  587. if (!elements.length) elements = [elements];
  588. const s = new Set();
  589. s.add = s.addOriginal || s.add;
  590. for (const element of elements) {
  591. if (element && element.nodeType >= 1) {
  592. s.add(element);
  593. if (element.querySelectorAll) {
  594. for (const e of element.querySelectorAll('*')) {
  595. s.add(e);
  596. }
  597. }
  598. }
  599. }
  600. const y = [...s];
  601. s.clear();
  602.  
  603. const f = (elm) => {
  604. let x = elm.nodeName.toLowerCase();
  605. let y = elm.id;
  606. return y ? `${x}#${y}` : `${x}`;
  607. }
  608. for (const element of y) {
  609. if (element && (element.nodeType >= 1) && !element.__renderPath522__) {
  610. let t = element;
  611. let w = [f(t)];
  612. if (!element.is) {
  613. while (t = t.parentNode) {
  614. w.unshift(f(t))
  615. if (t.is) break;
  616. }
  617. }
  618. element.__renderPath522__ = w.join('/');
  619. }
  620. }
  621. }
  622.  
  623.  
  624. const dispatchYtEvent = function (a, b, c, d) {
  625. d || (d = {
  626. bubbles: !0,
  627. cancelable: !1,
  628. composed: !0
  629. });
  630. c !== null && c !== void 0 && (d.detail = c);
  631. b = new CustomEvent(b, d);
  632. a.dispatchEvent(b);
  633. return b
  634. };
  635.  
  636. if (DISABLE_isLowLatencyLiveStream) {
  637. const sm = Symbol();
  638. const f = () => {
  639. try {
  640. const videoDetails = ytInitialPlayerResponse.videoDetails;
  641. if (videoDetails && videoDetails.isLowLatencyLiveStream) {
  642. videoDetails.isLowLatencyLiveStream = false;
  643. }
  644. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW') {
  645. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  646. }
  647. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  648. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  649. }
  650. } catch (e) { }
  651. }
  652. Object.defineProperty(Object.prototype, 'isLowLatencyLiveStream', {
  653. get() {
  654. const v = this[sm];
  655. if (typeof v === 'undefined') return v;
  656. f();
  657. return v;
  658. },
  659. set(nv) {
  660. f();
  661. if (nv === true) nv = false;
  662. this[sm] = nv;
  663. },
  664. enumerable: false,
  665. configurable: true
  666. });
  667.  
  668. const sm3 = Symbol();
  669. Object.defineProperty(Object.prototype, 'latencyClass', {
  670. get() {
  671. const v = this[sm3];
  672. if (typeof v === 'undefined') return v;
  673. f();
  674. return v;
  675. },
  676. set(nv) {
  677. f();
  678. if (nv === 'ULTRALOW' || nv === 'LOW') {
  679. nv = 'NORMAL';
  680. } else if (nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW' || nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  681. nv = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  682. }
  683. this[sm3] = nv;
  684. },
  685. enumerable: false,
  686. configurable: true
  687. });
  688.  
  689. }
  690.  
  691. class PlainHTMLElement extends HTMLTitleElement {
  692.  
  693. }
  694.  
  695. const removeShady = function (shady) {
  696. if (!shady || typeof shady !== 'object') return;
  697. const props = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  698. for (const prop of props) {
  699. const node = shady[prop];
  700. if (typeof (node || 0) !== 'object') continue;
  701. if (node.nodeType >= 1 && node.isConnected === false) _removedElements.addNode(node);
  702. }
  703. }
  704.  
  705. const shadys = new Set();
  706. shadys.add = shadys.addOriginal || shadys.add;
  707.  
  708. // window.showShadys00 = ()=>[...shadys].map(e=>kRef(e));
  709.  
  710. const _removedElements = new Set();
  711. _removedElements.add = _removedElements.addOriginal || _removedElements.add;
  712. _removedElements.addNode_ = MEMORY_RELEASE_NF00 ? function (node) {
  713. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  714. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  715. if (!node[wk]) node[wk] = mWeakRef(node);
  716. return this.add(node[wk]);
  717. }
  718. } : () => { };
  719.  
  720. _removedElements.addNode = MEMORY_RELEASE_NF00 ? (node) => {
  721. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  722. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  723. try {
  724. const rootNode = node.getRootNode();
  725. if (rootNode && rootNode !== node) {
  726. if (rootNode.nodeType >= 1 && rootNode.nodeType !== 9) _removedElements.addNode_(rootNode);
  727. }
  728. } catch (e) { }
  729. _removedElements.addNode_(node);
  730. }
  731. } : () => { };
  732.  
  733. if (WEAK_CE_ROOT) {
  734. Object.defineProperty(Object.prototype, '__CE_shadowRoot', {
  735. get() {
  736. return kRef(this.__CE_shadowRoot366);
  737. },
  738. set(nv) {
  739. if (typeof nv !== 'object') { // null is okay
  740. if (this.__CE_shadowRoot366) this.__CE_shadowRoot366 = null;
  741. return false;
  742. }
  743. if (!nv || typeof nv !== 'object') {
  744. this.__CE_shadowRoot366 = nv;
  745. } else {
  746. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  747. this.__CE_shadowRoot366 = nv[wk];
  748. }
  749. return true;
  750. }
  751. });
  752. }
  753.  
  754. const _emptyElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  755. const _emptyTipsElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  756. const _emptyVisibilityElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  757. // const _emptyShady = new (class EmptyShady { });
  758.  
  759. const nf00 = new FinalizationRegistry_((x) => {
  760. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: node[${x}] fully removed`);
  761. });
  762. let ud00 = 0;
  763. const ng00 = new Set();
  764. nf00.registerNode = function (node) {
  765. if (node && node.nodeType >= 1) {
  766. if (!node.t792) {
  767. node.t792 = (ud00 = (ud00 & 1073741823) + 1);
  768. const x = `${node.nodeName.toLowerCase()}#${node.t792}`;
  769. this.register(node, x);
  770. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: try remove node[${x}]`);
  771. ng00.add(mWeakRef(node));
  772. }
  773. }
  774. }
  775. window.showNg00 = () => {
  776. const ng01 = new Set();
  777. ng01.add = ng01.addOriginal || ng01.add;
  778. for (const e of ng00) {
  779. const f = kRef(e);
  780. if (!f) continue;
  781. ng01.add(f);
  782. }
  783. const ng02 = [...ng01];
  784. ng01.clear();
  785. window.showNg01 = [...ng02];
  786. return window.showNg01;
  787. }
  788. window.showTemplates00 = () => {
  789. const result = {};
  790. const elements = document.querySelectorAll('*');
  791. for (const element of elements) {
  792. const tag = element.nodeName.toLocaleLowerCase();
  793. const r = result[tag] || [];
  794. const cnt = insp(element);
  795. if (cnt !== element) {
  796. if (cnt.templateInfo) {
  797. r.push(['cnt0', cnt.templateInfo, element]);
  798. }
  799. if (element._templateInfo) {
  800. r.push(['cnt1', cnt._templateInfo, element]);
  801. }
  802. if (element.__templateInfo) {
  803. r.push(['cnt2', cnt.__templateInfo, element]);
  804. }
  805. }
  806. if (element.templateInfo) {
  807. r.push(['elm0', element.templateInfo, element]);
  808. }
  809. if (element._templateInfo) {
  810. r.push(['elm1', element._templateInfo, element]);
  811. }
  812. if (element.__templateInfo) {
  813. r.push(['elm2', element.__templateInfo, element]);
  814. }
  815. if (r.length >= 1) result[tag] = r;
  816. }
  817. const strCmp = (a, b) => {
  818. if (a === b) return 0;
  819. let u = [a, b].sort();
  820. return u[0] === a ? -1 : 1;
  821. }
  822. const counting1 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[0]))].join('|')]).sort((a, b) => {
  823. return strCmp(`${a[1]}.${a[0]}`, `${b[1]}.${b[0]}`);
  824. });
  825.  
  826. const counting2 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[1]))]]);
  827.  
  828. const counting3 = Object.entries(result).map(e => {
  829. const a = [...new Set(e[1].map(t => t[1]))];
  830. const b = [...new Set(a.map(e => e.nodeList || e))];
  831.  
  832. const r = [e[0], b];
  833. return r;
  834. });
  835.  
  836. return {result, counting1, counting2, counting3};
  837. };
  838.  
  839. window.showFrag00 = function(){
  840.  
  841. const result = {};
  842. const elements = document.querySelectorAll('*');
  843. for (const element of elements) {
  844. const tag = element.nodeName.toLocaleLowerCase();
  845. const r = result[tag] || [];
  846. const cnt = insp(element);
  847. if (cnt !== element) {
  848. if (cnt.templateInfo) {
  849. r.push(['cnt0', cnt.templateInfo, element]);
  850. }
  851. if (element._templateInfo) {
  852. r.push(['cnt1', cnt._templateInfo, element]);
  853. }
  854. if (element.__templateInfo) {
  855. r.push(['cnt2', cnt.__templateInfo, element]);
  856. }
  857. }
  858. if (element.templateInfo) {
  859. r.push(['elm0', element.templateInfo, element]);
  860. }
  861. if (element._templateInfo) {
  862. r.push(['elm1', element._templateInfo, element]);
  863. }
  864. if (element.__templateInfo) {
  865. r.push(['elm2', element.__templateInfo, element]);
  866. }
  867. if (r.length >= 1) result[tag] = r;
  868. }
  869. return result;
  870.  
  871. }
  872.  
  873. const detachShadyRef = (node) => {
  874.  
  875. const shadyArr = [...shadys];
  876. for (let shady of shadyArr) {
  877. shady = kRef(shady);
  878. if (!shady) continue;
  879. const keys = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  880. for (const p of keys) {
  881. const v = keys[p];
  882. if (!v) continue;
  883. if (v instanceof Node) {
  884. if (node === v || node.contains(v)) keys[p] = _emptyElement;
  885. } else if (typeof v === 'object' && v.splice && v.length > 0) {
  886. for (let i = v.length - 1; i >= 0; i--) {
  887. const t = v[i];
  888. if (t instanceof Node) {
  889. if (node === t || node.contains(t)) v.splice(i, 1);
  890. }
  891. }
  892. }
  893. }
  894. }
  895. shadyArr.length = 0;
  896.  
  897.  
  898. }
  899.  
  900. if (MEMORY_RELEASE_NF00) {
  901.  
  902. const __removedElements = new Set();
  903. __removedElements.add = __removedElements.addOriginal || __removedElements.add;
  904.  
  905. setInterval(() => {
  906. const nodesSet = new Set();
  907. nodesSet.add = nodesSet.addOriginal || nodesSet.add;
  908.  
  909. for (const nodeWr of __removedElements) {
  910. __removedElements.delete(nodeWr);
  911. const node = kRef(nodeWr);
  912. if (node && node.nodeType >= 1 && node.isConnected === false) {
  913. let rootNode;
  914. try {
  915. rootNode = node.getRootNode();
  916. } catch (e) { }
  917. if (rootNode && rootNode.nodeType >= 1 && rootNode.nodeType !== 9 && rootNode.isConnected === true) {
  918. // do nothing
  919. } else {
  920. nodesSet.add(node);
  921. if (node.querySelectorAll) {
  922. for (const p of node.querySelectorAll('*')) {
  923. nodesSet.add(p);
  924. }
  925. }
  926. }
  927. }
  928. }
  929. for (const nodeWr of _removedElements) {
  930. _removedElements.delete(nodeWr);
  931. const node = kRef(nodeWr);
  932. if (node && node.isConnected === false) {
  933. __removedElements.add(nodeWr);
  934. }
  935. }
  936.  
  937. if(nodesSet.size === 0) return;
  938.  
  939. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  940. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  941. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  942.  
  943. for (const node of nodesSet) {
  944. if (node === _emptyElement || node.__keepInstance038__ || node.t792) continue;
  945. const hasToolTips = !!((insp(node).$ || 0).tooltip);
  946.  
  947. if (node && node.__shady_getRootNode) {
  948. let k = null;
  949. try {
  950. k = node.__shady_getRootNode();
  951. } catch { }
  952. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  953. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  954. }
  955. if (node && node.getRootNode) {
  956. const k = node.getRootNode();
  957. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  958. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  959. }
  960.  
  961. if (node.__instances) {
  962. for (const k of node.__instances) {
  963. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  964. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  965. }
  966. // node.__instances.length = 0;
  967. }
  968. if (node && node.nodeType === 1) {
  969. if (typeof insp(node).__teardownInstance === 'function') {
  970. try {
  971. insp(node).__teardownInstance();
  972. } catch (e) { }
  973. } else if (typeof node.__teardownInstance === 'function') {
  974. try {
  975. node.__teardownInstance();
  976. } catch (e) { }
  977. }
  978. }
  979. if (node && node.nodeType === 1 && node.__detachAndRemoveInstance && (node.__instances || 0).length >= 1) {
  980. for (let i = node.__instances.length - 1; i >= 0; i--) {
  981. node.__detachAndRemoveInstance(i)
  982. }
  983. }
  984.  
  985. if (node && node.nodeType === 1 && node.is === void 0) {
  986. if (typeof insp(node).dispose === 'function') {
  987. insp(node).dispose();
  988. } else if (typeof node.dispose === 'function') {
  989. node.dispose();
  990. }
  991. }
  992.  
  993. if (node && node.nodeType === 1) {
  994. if (typeof insp(node).unobserve_ === 'function') {
  995. insp(node).unobserve_();
  996. } else if (typeof node.unobserve_ === 'function') {
  997. node.unobserve_();
  998. }
  999. }
  1000.  
  1001. if (node) {
  1002. if (typeof insp(node).unobserveNodes === 'function') {
  1003. insp(node).unobserveNodes();
  1004. } else if (typeof node.unobserveNodes === 'function') {
  1005. node.unobserveNodes();
  1006. }
  1007. }
  1008.  
  1009. // if (node && node.nodeType === 1) {
  1010. // const cnt = insp(node);
  1011. // const paths = cnt.__dataLinkedPaths;
  1012. // if (paths && paths.length >= 1 && typeof cnt.unlinkPaths === 'function') {
  1013. // for (let k in paths) {
  1014. // cnt.unlinkPaths(k);
  1015. // }
  1016. // }
  1017. // }
  1018.  
  1019. const visibilityMonitorKeys = insp(node).visibilityMonitorKeys || node.visibilityMonitorKeys;
  1020. if (visibilityMonitorKeys) {
  1021. for (const entry of visibilityMonitorKeys) {
  1022. if (entry.element) { entry.element = null }
  1023. }
  1024. visibilityMonitorKeys.length = 0;
  1025. }
  1026. const __instances = node.__instances;
  1027. if (__instances) {
  1028. for (const k of __instances) {
  1029. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  1030. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  1031. }
  1032. __instances.length = 0;
  1033. }
  1034. const sp = node.__shady_parentNode;
  1035. if (sp && sp.nodeType >= 1 && sp.isConnected === false) _removedElements.addNode(sp);
  1036. FULLY_REMOVE_ALL_EVENT_LISTENERS && node.removeAllEventListener001();
  1037. if (node && node.remove) node.remove();
  1038.  
  1039. /*
  1040. if (node._templateInfo && node._templateInfo.content) {
  1041. const templateInfoContent = node._templateInfo.content;
  1042. if (templateInfoContent.nodeType >= 1 && templateInfoContent.isConnected === false) {
  1043. _removedElements.addNode(templateInfoContent);
  1044. }
  1045. try{
  1046. node._templateInfo.content = null;
  1047. }catch(e){}
  1048. }
  1049. */
  1050. if (node.__domApi) {
  1051. node.__domApi = null;
  1052. }
  1053.  
  1054. const __shady = node.__shady;
  1055. if (__shady) {
  1056. delete node.__shady;
  1057. if (shadyKey) {
  1058. const shadyRootNode = __shady[shadyKey];
  1059. if (shadyRootNode) {
  1060. // console.log(shadyRootNode);
  1061. __shady[shadyKey] = null;
  1062. for (const key of [...Object.getOwnPropertyNames(__shady), ...Object.getOwnPropertySymbols(__shady)]) {
  1063. shadyRootNode[key] = null;
  1064. }
  1065. }
  1066. }
  1067. }
  1068.  
  1069.  
  1070. const ceRoot = node.__CE_shadowRoot;
  1071. if (ceRoot) {
  1072. node.__CE_shadowRoot = null;
  1073. if (ceRoot.nodeType >= 1 && ceRoot.isConnected === false) {
  1074. _removedElements.addNode(ceRoot);
  1075. }
  1076.  
  1077. }
  1078.  
  1079. // xTeardownTemplateInfo
  1080. const snChildNodes = node.__shady_native_childNodes;
  1081. if (snChildNodes.length > 0) {
  1082. for (const node of snChildNodes) {
  1083. if (node && node.nodeType >= 1 && node.isConnected === false) {
  1084. _removedElements.addNode(node);
  1085. }
  1086. }
  1087. snChildNodes.length = 0;
  1088. }
  1089. node.__shady_native_childNodes = null;
  1090.  
  1091.  
  1092. const __templateInfo = node.__templateInfo;
  1093. if (__templateInfo) {
  1094. node.__templateInfo = null;
  1095. // xTeardownTemplateInfo(__templateInfo);
  1096. }
  1097.  
  1098. if (hasToolTips && insp(node).$) {
  1099. insp(node).$.tooltip = _emptyTipsElement;
  1100. }
  1101.  
  1102. if (node && node.nodeType >= 1) {
  1103. const pd = Object.getOwnPropertyDescriptor(node, 'visibilityMonitorKeys');
  1104. if (pd && pd.value && pd.value.length >= 1) {
  1105. const arr = pd.value;
  1106. for (let i = 0; i < arr.length; i++) {
  1107. arr[i].element = _emptyVisibilityElement;
  1108. arr[i] = null;
  1109. }
  1110. }
  1111. }
  1112.  
  1113. if (node.__dataHost) {
  1114. try {
  1115. delete node.__dataHost
  1116. } catch (e) { }
  1117. try {
  1118. node.__dataHost = null;
  1119. } catch (e) { }
  1120. }
  1121.  
  1122. if (node.root) {
  1123. try {
  1124. delete node.root
  1125. } catch (e) { }
  1126. try {
  1127. node.root = null;
  1128. } catch (e) { }
  1129. }
  1130.  
  1131. if (node.children && node.children.splice) {
  1132. try {
  1133. delete node.children
  1134. } catch (e) { }
  1135. try {
  1136. node.children = null;
  1137. } catch (e) { }
  1138. }
  1139.  
  1140. if (node.__shady && typeof node.__shady === 'object') {
  1141. try {
  1142. node.__shady = null;
  1143. } catch (e) { }
  1144. }
  1145.  
  1146. if (node.nodeType === 1) Reflect.setPrototypeOf(node, PlainHTMLElement.prototype);
  1147.  
  1148. for (const prop of Object.getOwnPropertyNames(node)) {
  1149. if (prop === 'host' && typeof (node.host || 0) === 'object') {
  1150. if (node.nodeType === 11) {
  1151. const nodeHost = node.host;
  1152. if (nodeHost && nodeHost.nodeType >= 1) {
  1153. node.host = _emptyElement;
  1154. if (nodeHost.isConnected === false && nodeHost !== _emptyElement) {
  1155. _removedElements.addNode(nodeHost);
  1156. }
  1157. } else {
  1158. node.host = null;
  1159. }
  1160. } else {
  1161. node.host = null;
  1162. }
  1163. continue;
  1164. }
  1165. const pd = Object.getOwnPropertyDescriptor(node, prop);
  1166. if (pd.value) {
  1167. const v = pd.value;
  1168. if (typeof (v || 0) === 'object') node[prop] = null;
  1169. else if (typeof (v || 0) === 'function') delete node[prop];
  1170. }
  1171. }
  1172.  
  1173. for (const prop of Object.getOwnPropertySymbols(node)) {
  1174. const v = node[prop];
  1175. if (typeof (v || 0) === 'object' && !v.deref) node[prop] = null;
  1176. }
  1177.  
  1178. if (node.__shady_native_childNodes) {
  1179. node.__shady_native_childNodes = _emptyElement.childNodes;
  1180. }
  1181. if (node.__shady_children) {
  1182. node.__shady_children = _emptyElement.children;
  1183. }
  1184.  
  1185. for (const s of nmSet) s.delete(node);
  1186. for (const m of nmMap) m.delete(node);
  1187.  
  1188. mightTeardownShadyDomWrap(node);
  1189.  
  1190. detachShadyRef(node);
  1191.  
  1192. nf00.registerNode(node);
  1193.  
  1194.  
  1195.  
  1196. // console.log(1883001, node)
  1197. // console.log(3772001, node, node.countEvent767())
  1198. }
  1199.  
  1200. nodesSet.clear();
  1201.  
  1202. }, 400);
  1203.  
  1204. }
  1205.  
  1206.  
  1207. if (FULLY_REMOVE_ALL_EVENT_LISTENERS && !EventTarget.prototype.addEventListener828 && !EventTarget.prototype.removeAllEventListener001) {
  1208. const handlerMap = new WeakMap();
  1209. EventTarget.prototype.addEventListener828 = EventTarget.prototype.addEventListener;
  1210. EventTarget.prototype.addEventListener = function (type, handler, option = void 0) {
  1211. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1212. let hds = handlerMap.get(wr);
  1213. if (!hds) handlerMap.set(wr, (hds = new Set()));
  1214. hds.add([type, handler, option]);
  1215. return this.addEventListener828(type, handler, option);
  1216. }
  1217. EventTarget.prototype.removeEventListener828 = EventTarget.prototype.removeEventListener;
  1218. EventTarget.prototype.removeEventListener = function (type, handler, option = void 0) {
  1219. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1220. let hds = handlerMap.get(wr);
  1221. if (hds) {
  1222. for (const entry of hds) {
  1223. if (entry[0] === type && entry[1] === handler) {
  1224. if (entry[2] === option) {
  1225. hds.delete(entry);
  1226. // break;
  1227. } else if (FUZZY_EVENT_LISTENER_REMOVAL) {
  1228. hds.delete(entry);
  1229. this.removeEventListener828(type, handler, entry[2]);
  1230. }
  1231. }
  1232. }
  1233. }
  1234. return this.removeEventListener828(type, handler, option);
  1235. }
  1236. EventTarget.prototype.countEvent767 = function(){
  1237. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1238. return handlerMap.get(wr);
  1239. }
  1240. EventTarget.prototype.removeAllEventListener001 = function () {
  1241. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1242. let hds = handlerMap.get(wr);
  1243. if (hds) {
  1244. handlerMap.delete(wr);
  1245. for (const entry of hds) {
  1246. const [type, handler, option] = entry;
  1247. entry.length = 0;
  1248. this.removeEventListener828(type, handler, option);
  1249. }
  1250. hds.clear();
  1251. }
  1252. }
  1253. }
  1254.  
  1255. const globalSetup = (key, setup)=>{
  1256. let symb = Symbol();
  1257. Object.defineProperty(Object.prototype, key, {
  1258. get() {
  1259. return this[symb];
  1260. },
  1261. set(nv) {
  1262. if (typeof nv !== 'function') {
  1263. this[symb] = nv;
  1264. return true;
  1265. }
  1266. if (!(symb in this)) {
  1267. setup(this);
  1268. }
  1269. this[symb] = nv;
  1270. return true;
  1271. },
  1272. configurable: true,
  1273. enumerable: false
  1274. });
  1275. }
  1276.  
  1277. const toActualNode = (e) => {
  1278. return e && e.getNode592177 ? e.getNode592177() : e;
  1279. }
  1280.  
  1281. const removeAllChildNodes = (o)=>{
  1282. if ((o instanceof Node) && o.nodeType >= 1) {
  1283. let t, q = null;
  1284. while ((t = o.firstChild) && t !== q) {
  1285. try {
  1286. t.__keepInstance038__ = false;
  1287. t.remove();
  1288. _removedElements.addNode(t);
  1289. q = t;
  1290. } catch (e) { }
  1291. }
  1292. try {
  1293. o.__keepInstance038__ = false;
  1294. o.remove();
  1295. _removedElements.addNode(o);
  1296. } catch (e) { }
  1297. }
  1298. }
  1299.  
  1300. let shadyInited = false;
  1301. let shadyKey = '';
  1302. let shadyKeyX = '';
  1303. const setupShady = () => {
  1304. shadyInited = true;
  1305. let p = document.createComment('1');
  1306. const x = document.implementation.createHTMLDocument();
  1307. const y = x.firstElementChild;
  1308. y.appendChild(p);
  1309. let key = '';
  1310. p.__shady = new Proxy({}, {
  1311. get(target, prop) {
  1312. key = prop;
  1313. throw new Error();
  1314. },
  1315. set(target, prop, val) {
  1316. throw new Error();
  1317. }
  1318. })
  1319. try {
  1320. p.__shady_getRootNode()
  1321. } catch (e) { }
  1322. let __shady = null;
  1323. try {
  1324. p.__shady = null;
  1325. p.__shady_getRootNode()
  1326. __shady = p.__shady;
  1327. } catch (e) {
  1328.  
  1329. }
  1330. y.removeChild(p);
  1331.  
  1332.  
  1333. if (key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1334. const sProto = Reflect.getPrototypeOf(__shady);
  1335. const symb = Symbol('__shady');
  1336. // const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1337. Object.defineProperty(sProto, key, {
  1338. get() {
  1339. if(!this[wk]) this[wk] = mWeakRef(this);
  1340. shadys.add(this[wk]);
  1341. return kRef(this[symb]);
  1342. },
  1343. set(nv) {
  1344. if(!this[wk]) this[wk] = mWeakRef(this);
  1345. shadys.add(this[wk]);
  1346. if (typeof (nv || 0) === 'object') {
  1347. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1348. this[symb] = nv[wk];
  1349. } else {
  1350. this[symb] = nv;
  1351. }
  1352. return true;
  1353. },
  1354. enumerable: false,
  1355. configurable: true
  1356. });
  1357. shadyKey = key;
  1358. console.log('[yt-js-engine-tamer] shadyKey', key);
  1359.  
  1360. }
  1361.  
  1362.  
  1363. if (0 && key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1364. const sProto = Reflect.getPrototypeOf(__shady);
  1365. const symb = Symbol('__shady');
  1366. const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1367. Object.defineProperty(sProto, key, {
  1368. get() {
  1369. if(!this[wk]) this[wk] = mWeakRef(this);
  1370. shadys.add(this[wk]);
  1371. return kRef(this[symb]);
  1372. },
  1373. set(nv) {
  1374. if(!this[wk]) this[wk] = mWeakRef(this);
  1375. shadys.add(this[wk]);
  1376. if (typeof (nv || 0) === 'object') {
  1377. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1378. this[symb] = nv[wk];
  1379. } else {
  1380. this[symb] = nv;
  1381. }
  1382. return true;
  1383. },
  1384. enumerable: false,
  1385. configurable: true
  1386. });
  1387. shadyKey = key;
  1388. console.log('[yt-js-engine-tamer] shadyKey', key);
  1389.  
  1390. let shadyKeyCached = new Set();
  1391. const fixLastShady = () => {
  1392. const shady = lastShady;
  1393. for (const key of Object.keys(shady)) {
  1394. if (shadyKeyCached.has(key)) continue;
  1395. shadyKeyCached.add(key);
  1396. if ((typeof shady[key] === 'object') && !(shady[key] || 0).deref) {
  1397. if (!shadyKeyX && shady[key] === shady.root) {
  1398. shadyKeyX = key;
  1399. const sProto = Reflect.getPrototypeOf(shady);
  1400. const symb = Symbol();
  1401. Object.defineProperty(sProto, shadyKeyX, {
  1402. get() {
  1403. return kRef(this[symb])
  1404. },
  1405. set(nv) {
  1406. if (typeof (nv || 0) === 'object') {
  1407. nv = kRef(nv);
  1408. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1409. this[symb] = nv[wk];
  1410. } else {
  1411. this[symb] = nv;
  1412. }
  1413. return true;
  1414. },
  1415. enumerable: false,
  1416. configurable: true,
  1417. });
  1418. delete shady[key];
  1419. shady[key] = shady.root;
  1420. };
  1421. // console.log(12883, shady[key], key);
  1422. // assignedNodes, assignedSlot, ja, K, childNodes, ... (keep strong ref)
  1423. }
  1424. }
  1425. }
  1426. let lastShady = null;
  1427.  
  1428. symbKeys.forEach(key => {
  1429. const symb = Symbol(key);
  1430.  
  1431. Object.defineProperty(sProto, key, {
  1432. get() {
  1433. if (this !== lastShady && lastShady) fixLastShady();
  1434. lastShady = this;
  1435. return kRef(this[symb]);
  1436. },
  1437. set(nv) {
  1438. if (this !== lastShady && lastShady) fixLastShady();
  1439. lastShady = this;
  1440. if (typeof (nv || 0) === 'object') {
  1441. nv = kRef(nv);
  1442. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1443. this[symb] = nv[wk];
  1444. } else {
  1445. this[symb] = nv;
  1446. }
  1447. return true;
  1448. },
  1449. enumerable: false,
  1450. configurable: true
  1451. });
  1452.  
  1453. });
  1454.  
  1455. }
  1456.  
  1457.  
  1458.  
  1459. }
  1460.  
  1461. const stampedNodes = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1462. stampedNodes.set = stampedNodes.setOriginal || stampedNodes.set;
  1463. const stampedFragment = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1464. stampedFragment.set = stampedFragment.setOriginal || stampedFragment.set;
  1465.  
  1466.  
  1467. class WeakNodeC extends Node {
  1468. constructor() {
  1469. }
  1470. addEventListener(type, listener, option = void 0) {
  1471. const nodeWr = stampedNodes.get(this.eid);
  1472. const node = kRef(nodeWr);
  1473. if (!node) return;
  1474. return node.addEventListener(type, listener, option);
  1475. }
  1476. removeEventListener(type, listener, option = void 0) {
  1477. const nodeWr = stampedNodes.get(this.eid);
  1478. const node = kRef(nodeWr);
  1479. if (!node) return;
  1480. return node.removeEventListener(type, listener, option);
  1481. }
  1482. getNode592177() {
  1483. const nodeWr = stampedNodes.get(this.eid);
  1484. const node = kRef(nodeWr);
  1485. return node;
  1486. }
  1487.  
  1488. set __dataHost(nv) {
  1489. const nodeWr = stampedNodes.get(this.eid);
  1490. const node = kRef(nodeWr);
  1491. if (!node) return;
  1492. node.__dataHost = nv;
  1493. return true;
  1494. }
  1495. get __dataHost() {
  1496. const nodeWr = stampedNodes.get(this.eid);
  1497. const node = kRef(nodeWr);
  1498. if (!node) return;
  1499. return node.__dataHost;
  1500. }
  1501.  
  1502. set __dataCompoundStorage(nv) {
  1503. const nodeWr = stampedNodes.get(this.eid);
  1504. const node = kRef(nodeWr);
  1505. if (!node) return;
  1506. node.__dataCompoundStorage = nv;
  1507. return true;
  1508. }
  1509. get __dataCompoundStorage() {
  1510. const nodeWr = stampedNodes.get(this.eid);
  1511. const node = kRef(nodeWr);
  1512. if (!node) return;
  1513. return node.__dataCompoundStorage;
  1514. }
  1515.  
  1516. set __shady_className(nv) {
  1517. const nodeWr = stampedNodes.get(this.eid);
  1518. const node = kRef(nodeWr);
  1519. if (!node) return;
  1520. node.__shady_className = nv;
  1521. // debugger;
  1522. return true;
  1523. }
  1524. get __shady_className() {
  1525. const nodeWr = stampedNodes.get(this.eid);
  1526. const node = kRef(nodeWr);
  1527. if (!node) return;
  1528. return node.__shady_className;
  1529. }
  1530. }
  1531.  
  1532. if (FIX_TEMPLATE_BINDING) {
  1533. const templateMap = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1534. templateMap.set = templateMap.setOriginal || templateMap.set;
  1535. // const parsedTemplate = new Map();
  1536.  
  1537.  
  1538. const it0 = Date.now() - 80000000000;
  1539. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  1540.  
  1541.  
  1542. /*
  1543.  
  1544. M.prototype._bindTemplate = function(N, R) {
  1545. var X = this.constructor._parseTemplate(N)
  1546. , A = this.__preBoundTemplateInfo == X;
  1547. if (!A)
  1548. for (var l in X.propertyEffects)
  1549. this._createPropertyAccessor(l);
  1550. R ? (X = Object.create(X),
  1551. X.wasPreBound = A,
  1552. this.__templateInfo ? (N = N._parentTemplateInfo || this.__templateInfo,
  1553. R = N.lastChild,
  1554. X.parent = N,
  1555. N.lastChild = X,
  1556. (X.previousSibling = R) ? R.nextSibling = X : N.firstChild = X) : this.__templateInfo = X) : this.__preBoundTemplateInfo = X;
  1557. return X
  1558. }
  1559. ;
  1560. */
  1561.  
  1562. /*
  1563. ** this.constructor._parseTemplate **
  1564. d._parseTemplate = function(N, R) {
  1565. if (!N._templateInfo) {
  1566. var X = N._templateInfo = {};
  1567. X.nodeInfoList = [];
  1568. X.nestedTemplate = !!R;
  1569. X.stripWhiteSpace = R && R.stripWhiteSpace || N.hasAttribute && N.hasAttribute("strip-whitespace");
  1570. this._parseTemplateContent(N, X, {
  1571. parent: null
  1572. })
  1573. }
  1574. return N._templateInfo
  1575. }
  1576.  
  1577. */
  1578.  
  1579.  
  1580. const exceptionTriggered = new Set();
  1581. const gxx = (window.gxxC572 || (window.gxxC572 = new Set()));
  1582.  
  1583. // let initied1 = false;
  1584. // let _parseTemplateByPass = false;
  1585. const setup1 = (qxx) => {
  1586. // if(initied1) return;
  1587. // initied1 = true;
  1588. const proto = qxx;
  1589. const constructor = proto.constructor;
  1590. const _bindTemplate = proto._bindTemplate;
  1591. // console.log(12883, proto, constructor)
  1592.  
  1593.  
  1594. const _parseTemplate = constructor._parseTemplate;
  1595. if (typeof _parseTemplate === 'function' && _parseTemplate.length === 2 && !constructor._parseTemplate322) {
  1596.  
  1597. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _parseTemplate', _parseTemplate);
  1598. constructor._parseTemplate322 = _parseTemplate;
  1599. const parsedResults = new WeakMap();
  1600.  
  1601. const _templateInfoPd = {
  1602. get() {
  1603. if (!this || !this[wk]) return undefined;
  1604. const r = parsedResults.get(this[wk]);
  1605. return r;
  1606. },
  1607. set(nv) {
  1608. delete this._templateInfo;
  1609. this._templateInfo = nv;
  1610. console.warn('_templateInfoPd set');
  1611. return true;
  1612. },
  1613. enumerable: true,
  1614. configurable: true
  1615. };
  1616. constructor._parseTemplate = function (N, R) {
  1617. if (!N) return _parseTemplate.call(this, N, R);
  1618. if (!N[wk]) N[wk] = mWeakRef(N);
  1619. let r = parsedResults.get(N[wk]);
  1620. if (r) return r;
  1621. r = _parseTemplate.call(this, N, R);
  1622. if (r && !parsedResults.has(N[wk])) {
  1623. parsedResults.set(N[wk], r);
  1624. r.iAm68 = '_templateInfo';
  1625. N.iHave68 = '_templateInfo';
  1626. if (N._templateInfo && N._templateInfo === r) {
  1627. delete N._templateInfo;
  1628. if (!N._templateInfo) {
  1629. Object.defineProperty(N, '_templateInfo', _templateInfoPd);
  1630. }
  1631. }
  1632. }
  1633. return r;
  1634. }
  1635. }
  1636. if (typeof _bindTemplate === 'function' && _bindTemplate.length === 2 && !proto._bindTemplate322) {
  1637.  
  1638. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _bindTemplate', _bindTemplate);
  1639. proto._bindTemplate322 = _bindTemplate;
  1640. proto._bindTemplate = function (N, R) {
  1641. // R = boolean true or undefined
  1642. // N = template elemenet
  1643. let M = N;
  1644. if (typeof (N || 0) === 'object' && N instanceof HTMLTemplateElement && (N.content || 0).nodeType === 11) {
  1645. let componentIs = '';
  1646. try {
  1647. componentIs = this ? this.is : '';
  1648. } catch (e) { }
  1649. if (typeof (componentIs || 0) === 'string') {
  1650. if (!templateMap.has(componentIs)) {
  1651. templateMap.set(componentIs, N);
  1652. // const parser = this.constructor;
  1653. // console.log(3882, parser._parseTemplate)
  1654. /*
  1655. if (parser._parseTemplate && !parser._parseTemplate477 && parser._parseTemplate.length === 2) {
  1656. parser._parseTemplate477 = parser._parseTemplate;
  1657. const _parseTemplate477 = parser._parseTemplate477;
  1658. parser._parseTemplate = function (N, R) {
  1659. if (!_parseTemplateByPass && N && N[wk]) {
  1660. const u = parsedTemplate.get(N[wk]);
  1661. if (u) {
  1662. console.log(1838, u)
  1663. return u;
  1664. }
  1665. }
  1666. return _parseTemplate477.call(this, N, R);
  1667. };
  1668. }
  1669. if (parser._parseTemplate && parser._parseTemplate477) {
  1670. if (N && !N[wk]) N[wk] = mWeakRef(N);
  1671. if (!parsedTemplate.has(N[wk])) {
  1672. _parseTemplateByPass = true;
  1673. parsedTemplate.set(N[wk], parser._parseTemplate477(N));
  1674. _parseTemplateByPass = false;
  1675. }
  1676. }
  1677. */
  1678. } else {
  1679. M = templateMap.get(componentIs);
  1680. }
  1681. }
  1682. }
  1683. let r_ = null;
  1684. // Promise.resolve(N).then((N) => {
  1685. // console.log(3488,N.templateInfo, N.templateInfo === r_);
  1686. // })
  1687. const r = _bindTemplate.call(this, M, R);
  1688. r_ = r;
  1689. return r;
  1690. }
  1691. }
  1692.  
  1693. const _runEffectsForTemplate = proto._runEffectsForTemplate;
  1694. if (typeof _runEffectsForTemplate === 'function' && _runEffectsForTemplate.length === 4 && !proto._runEffectsForTemplate322) {
  1695. proto._runEffectsForTemplate322 = _runEffectsForTemplate;
  1696.  
  1697. // note: fastDomIf does not work well with runEffects ...
  1698. // so no runEffects actaully?
  1699. const runner = (Tw, Nw, Rw, Xw, Aw) => {
  1700.  
  1701. try {
  1702.  
  1703.  
  1704. // console.log(988003)
  1705. const T = kRef(Tw); // this
  1706. const N = kRef(Nw); // __templateInfo
  1707. if (!T || !N) return;
  1708.  
  1709. // console.log(988004)
  1710. const R = kRef(Rw); // __data
  1711. const X = kRef(Xw); // temp Data ?
  1712. const A = kRef(Aw); // boolean ?
  1713. if (typeof (X || 0) === 'object') gxx.delete(X);
  1714. if (typeof (A || 0) === 'object') gxx.delete(A);
  1715.  
  1716. // console.log(988005)
  1717. const nodeList_ = N.nodeList;
  1718.  
  1719. // console.log(988006, nodeList_)
  1720. const nodeList = nodeList_ ? nodeList_.map(e => toActualNode(e)) : nodeList_;
  1721.  
  1722. // console.log(988007, nodeList)
  1723.  
  1724. const Nx = {
  1725. propertyEffects: N.propertyEffects,
  1726. nodeList: nodeList,
  1727. firstChild: kRef(N.firstChild)
  1728. };
  1729.  
  1730. // if (kRef(N.firstChild)) {
  1731. // console.log(977001, Nx)
  1732. // }
  1733.  
  1734. // console.log(988009, Nx, R, X, A)
  1735.  
  1736.  
  1737. {
  1738.  
  1739.  
  1740. const o = Nx;
  1741. const { propertyEffects, nodeList, firstChild } = o;
  1742. if (propertyEffects && nodeList && nodeList.length >= 0) {
  1743. for (const [effectKey, propertyEffectArr] of Object.entries(propertyEffects)) {
  1744. for (let i = propertyEffectArr.length - 1; i >= 0; i--) {
  1745. const propertyEffect = propertyEffectArr[i];
  1746. const info = (propertyEffect || 0).info;
  1747. if (info && typeof info.index === 'number' && !nodeList[info.index]) {
  1748. propertyEffectArr.splice(i, 1);
  1749. }
  1750. }
  1751. }
  1752. }
  1753.  
  1754. }
  1755.  
  1756.  
  1757. // console.log({T, Nx, R, X , A })
  1758.  
  1759. // console.log(1737001, T)
  1760. // console.log(1737002, Nx)
  1761.  
  1762. // console.log(1737003, R)
  1763. // console.log(1737004, X)
  1764. // console.log(1737005, A)
  1765.  
  1766. const hostElement = T.hostElement;
  1767. const pChildren = (hostElement instanceof Node && hostElement.isConnected === true) ? [...hostElement.childNodes] : null;
  1768. renderPathMake(pChildren);
  1769.  
  1770. try {
  1771. _runEffectsForTemplate.call(T, Nx, R, X, A);
  1772.  
  1773. } catch (err) {
  1774. // debugger;
  1775. const stack = err.stack;
  1776. if (!exceptionTriggered.has(stack)) {
  1777. exceptionTriggered.add(stack);
  1778. console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`+"\n\n", err);
  1779. }
  1780. }
  1781.  
  1782. (pChildren || 0).length >= 1 && Promise.resolve(pChildren).then((pChildren) => {
  1783. for (const node of pChildren) {
  1784. if (node.parentNode !== hostElement && node.__weakNodeCId57__) {
  1785. _removedElements.addNode(node); // rn54001b
  1786. }
  1787. // if (node.isConnected === false) {
  1788. // let tNode = node;
  1789. // let pNode;
  1790. // while ((pNode = tNode.parentNode) && pNode.nodeType >= 1) {
  1791. // tNode = pNode;
  1792. // }
  1793. // // _removedElements.addNode(tNode); // rn54001
  1794. // }
  1795. }
  1796. pChildren.length = 0;
  1797. pChildren = null;
  1798. });
  1799.  
  1800.  
  1801. } catch (err) {
  1802. // debugger;
  1803. // const stack = err.stack;
  1804. // if (!exceptionTriggered.has(stack)) {
  1805. // exceptionTriggered.add(stack);
  1806. // console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`, err);
  1807. console.error(err);
  1808. // }
  1809. }
  1810.  
  1811. };
  1812.  
  1813.  
  1814. proto._runEffectsForTemplate = function (N, R, X, A) {
  1815.  
  1816. // console.log(988001)
  1817. /*
  1818. N {wasPreBound: true, nodeList: Array(23)}
  1819.  
  1820. R {showInput: false, narrow: false, menuStrings: {…}, pageDarkTheme: true, theater: false, …}
  1821. X {showInput: undefined, narrow: undefined, menuStrings: undefined, pageDarkTheme: undefined, theater: undefined, …}
  1822. A false
  1823. */
  1824.  
  1825. const Nw = (!N || typeof N !== 'object') ? N : (N[wk] || (N[wk] = mWeakRef(N))); // __templateInfo
  1826. const Xw = (!X || typeof X !== 'object') ? X : (X[wk] || (X[wk] = mWeakRef(X)));
  1827.  
  1828. const Rw = (!R || typeof R !== 'object') ? R : (R[wk] || (R[wk] = mWeakRef(R))); // __data
  1829. const Aw = (!A || typeof A !== 'object') ? A : (A[wk] || (A[wk] = mWeakRef(A)));
  1830.  
  1831. if (typeof (X || 0) === 'object') gxx.add(X);
  1832. if (typeof (A || 0) === 'object') gxx.add(A);
  1833.  
  1834. const Tw = (!this || typeof this !== 'object') ? this : (this[wk] || (this[wk] = mWeakRef(this)));
  1835.  
  1836.  
  1837. if (N.runEffects) {
  1838. N.runEffects(() => {
  1839. runner(Tw, Nw, Rw, Xw, Aw);
  1840. }, R, A);
  1841. } else {
  1842. runner(Tw, Nw, Rw, Xw, Aw);
  1843. }
  1844.  
  1845. // console.log(988002)
  1846.  
  1847. // const N_ =
  1848.  
  1849. // var l = this
  1850. // , k = function (T, W) {
  1851. // XK(l, N.propertyEffects, T, X, W, N.nodeList);
  1852. // for (var w = N.firstChild; w; w = w.nextSibling)
  1853. // l._runEffectsForTemplate(w, T, X, W)
  1854. // };
  1855. // N.runEffects ? N.runEffects(k, R, A) : k(R, A)
  1856. }
  1857.  
  1858. }
  1859.  
  1860.  
  1861. const _registerHost = proto._registerHost;
  1862. if (_registerHost && !proto._registerHost322 && _registerHost.length === 0) {
  1863. proto._registerHost322 = _registerHost;
  1864. const map = new WeakMap();
  1865. map.set = map.setOriginal || map.set;
  1866. proto._registerHost = function () {
  1867. if (!map.has(this)) {
  1868. map.set(this, (this.__dataHost || null));
  1869. Object.defineProperty(this, '__dataHost', {
  1870. get() {
  1871. return kRef(map.get(this)) || null
  1872. },
  1873. set(nv) {
  1874. const w = kRef(nv);
  1875. if (!w) {
  1876. map.set(this, null);
  1877. } else {
  1878. if (!w[wk]) w[wk] = mWeakRef(w);
  1879. let byPass = false;
  1880. if (this.is === 'ytd-masthead') byPass = true;
  1881. if (byPass) {
  1882. map.set(this, w);
  1883. } else {
  1884. map.set(this, w[wk]);
  1885. }
  1886. }
  1887. return true;
  1888. },
  1889. enumerable: true,
  1890. configurable: true
  1891. });
  1892. }
  1893. let previousDataHost = this.__dataHost;
  1894. renderPathMake(previousDataHost)
  1895. let r = _registerHost.call(this);
  1896. let currentDataHost = this.__dataHost;
  1897. if (currentDataHost !== previousDataHost) { // future use only
  1898. if (previousDataHost && previousDataHost.nodeType >= 1 && previousDataHost.isConnected === false) {
  1899. _removedElements.addNode(previousDataHost); // rn54002
  1900. }
  1901. }
  1902. return r;
  1903. }
  1904. }
  1905.  
  1906. }
  1907. globalSetup('_removeBoundDom', setup1);
  1908.  
  1909.  
  1910. /*
  1911.  
  1912. M.prototype._stampTemplate = function(N, R) {
  1913. R = R || this._bindTemplate(N, !0);
  1914. aU.push(this);
  1915. N = d.prototype._stampTemplate.call(this, N, R);
  1916. aU.pop();
  1917. R.nodeList = N.nodeList;
  1918. if (!R.wasPreBound)
  1919. for (var X = R.childNodes = [], A = N.firstChild; A; A = A.nextSibling)
  1920. X.push(A);
  1921. N.templateInfo = R;
  1922. X = R.nodeList;
  1923. A = R.nodeInfoList;
  1924. if (A.length)
  1925. for (var l = 0; l < A.length; l++) {
  1926. var k = X[l]
  1927. , T = A[l].bindings;
  1928. if (T)
  1929. for (var W = 0; W < T.length; W++) {
  1930. var w = T[W]
  1931. , p = k
  1932. , h = w;
  1933. if (h.isCompound) {
  1934. for (var I = p.__dataCompoundStorage || (p.__dataCompoundStorage = {}), O = h.parts, y = Array(O.length), c = 0; c < O.length; c++)
  1935. y[c] = O[c].literal;
  1936. O = h.target;
  1937. I[O] = y;
  1938. h.literal && h.kind == "property" && (O === "className" && (p = (0,
  1939. _.FK)(p)),
  1940. p[O] = h.literal)
  1941. }
  1942. gM2(k, this, w)
  1943. }
  1944. k.__dataHost = this
  1945. }
  1946. this.__dataClientsReady && (this._runEffectsForTemplate(R, this.__data, null, !1),
  1947. this._flushClients());
  1948. return N
  1949. }
  1950. ;
  1951.  
  1952. */
  1953.  
  1954. const wnc = new Set();
  1955.  
  1956. const __listWeakNodeC__ = window.__listWeakNodeC__ = () => {
  1957. const result = __listWeakNodeC0__();
  1958. return [...result].sort();
  1959. }
  1960.  
  1961. const __listWeakNodeC0__ = () => {
  1962. let result = new Set();
  1963. for (const nodeC of wnc) {
  1964. for (const k of Object.getOwnPropertyNames(nodeC)) {
  1965. result.add(k)
  1966. }
  1967. }
  1968. return result;
  1969. }
  1970.  
  1971. setInterval(() => {
  1972. if (wnc.size > 0 && __listWeakNodeC0__().size !== 1) console.warn(`[yt-js-engine-tamer] WARNING 0xF04E: ${__listWeakNodeC__()}`);
  1973. }, 400);
  1974.  
  1975.  
  1976. const dollarStore = new Map();
  1977.  
  1978. const makeDollarClass = (idsJoined, ids) => {
  1979. const $ = class {};
  1980. const a = $.prototype;
  1981. ids.forEach(id => {
  1982. const p = `## ${id}`;
  1983. Object.defineProperty(a, id, {
  1984. get() {
  1985. return kRef(this[p]);
  1986. },
  1987. set(nv) {
  1988. if (nv instanceof Node) {
  1989. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1990. this[p] = nv[wk];
  1991. } else {
  1992. this[p] = nv;
  1993. }
  1994. return true;
  1995. },
  1996. enumerable: true,
  1997. configurable: true
  1998. });
  1999. });
  2000. a.__w646__ = true;
  2001. dollarStore.set(idsJoined, $);
  2002. return $;
  2003. }
  2004.  
  2005. // let initied2 = false;
  2006. const setup2 = (qxx) => {
  2007. // if(initied2) return;
  2008. // initied2 = true;
  2009. const proto = qxx;
  2010. const constructor = proto.constructor;
  2011. const _stampTemplate = proto._stampTemplate;
  2012. // console.log(12883, proto, constructor)
  2013. if (typeof _stampTemplate === 'function' && _stampTemplate.length === 2 && !proto._stampTemplate374) {
  2014. proto._stampTemplate374 = _stampTemplate;
  2015. proto._stampTemplate = function (N, R) {
  2016.  
  2017. if (!shadyInited) setupShady();
  2018.  
  2019. let e__ = null;
  2020. try {
  2021. // R = boolean true or binded template
  2022. // N = template elemenet
  2023. let M = N;
  2024. let r_ = null;
  2025. const r = _stampTemplate.call(this, M, R); // return the fragment created with nodeList
  2026. r_ = r;
  2027. // if (r && r.host) {
  2028. // console.log(2883, R.host)
  2029. // }
  2030. if (r && r.$ && !r.$.__w646__) {
  2031. const $ = r.$;
  2032. const ids = Object.getOwnPropertyNames($)
  2033. const idsJoined = ids.join(' ');
  2034. const C = dollarStore.get(idsJoined) || makeDollarClass(idsJoined, ids);
  2035. const objVals = { ...$ };
  2036. Reflect.setPrototypeOf($, C.prototype);
  2037. for (const id of ids) {
  2038. delete $[id];
  2039. $[id] = objVals[id];
  2040. }
  2041. }
  2042. if (r && r.nodeType === 11 && !r.__fragId57__) {
  2043.  
  2044. const fid = genId();
  2045.  
  2046. r.__fragId57__ = fid;
  2047. if (!r[wk]) r[wk] = mWeakRef(r);
  2048. stampedFragment.set(fid, r[wk]);
  2049.  
  2050. if (r.nodeList) {
  2051. const nl = r.nodeList;
  2052. nl.__belongFragId57__ = fid;
  2053. for (let i = 0, l = nl.length; i < l; i++) {
  2054. const t = nl[i];
  2055. if (t && t.nodeType >= 1 && !(t instanceof ShadowRoot)) {
  2056. if (!t[wk]) t[wk] = mWeakRef(t);
  2057. const eid = `${fid}::${i}`;
  2058. const wn = Object.create(WeakNodeC.prototype);
  2059. wn.eid = eid;
  2060. wnc.add(wn);
  2061. nl[i] = wn;
  2062. // we believe the stampedNodes shall be attached to the document DomTree
  2063. stampedNodes.set(eid, t[wk]);
  2064. t.__weakNodeCId57__ = eid;
  2065. } else {
  2066. if (t instanceof ShadowRoot) {
  2067. console.warn('[yt-js-engine-tamer]', 'ShadowRoot in _stampTemplate');
  2068. }
  2069. }
  2070. }
  2071. }
  2072.  
  2073. }
  2074.  
  2075. return r;
  2076. } catch (e) { console.error(e); e__ = e; }
  2077. throw e__;
  2078.  
  2079. }
  2080. }
  2081. }
  2082.  
  2083. globalSetup('_addMethodEventListenerToNode', setup2);
  2084.  
  2085. }
  2086.  
  2087.  
  2088. if (FIX_FRAGEMENT_HOST && !DocumentFragment.prototype.host577) {
  2089. DocumentFragment.prototype.host577 = true;
  2090. let propsOK = false;
  2091. Object.defineProperty(DocumentFragment.prototype, 'host', {
  2092. get() {
  2093. const r = kRef(this.host677);
  2094. if (!propsOK && this.nodeType === 11 && r) setupProps(Reflect.getPrototypeOf(this));
  2095. return r;
  2096. },
  2097. set(nv) {
  2098. if (typeof (nv || 0) === 'object' && nv.nodeType === 1) {
  2099. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2100. this.host677 = nv[wk];
  2101. } else {
  2102. this.host677 = nv;
  2103. }
  2104. return true;
  2105. },
  2106. enumerable: true,
  2107. configurable: true
  2108. });
  2109.  
  2110.  
  2111. const setupProps = (fragProto) => {
  2112.  
  2113. propsOK = true;
  2114.  
  2115. ["ownerDocument", "baseURI", "isConnected"].forEach(function (b) {
  2116.  
  2117. const pd = Object.getOwnPropertyDescriptor(fragProto, b);
  2118. const pdn = Object.getOwnPropertyDescriptor(Node.prototype, b);
  2119. const get1 = pd && pd.get;
  2120. const get2 = pdn && pdn.get;
  2121. if (get1 && get2) {
  2122. delete fragProto[b];
  2123. Object.defineProperty(fragProto, b, {
  2124. get: function () {
  2125. return this.host ? get1.call(this) : get2.call(this);
  2126. },
  2127. configurable: !0
  2128. });
  2129.  
  2130. }
  2131.  
  2132. });
  2133. }
  2134.  
  2135. }
  2136.  
  2137.  
  2138. if (XFlag) {
  2139.  
  2140. const cMap = new Set();
  2141. cMap.add = cMap.addOriginal || cMap.add;
  2142. const yMap = new Set();
  2143. yMap.add = yMap.addOriginal || yMap.add;
  2144.  
  2145.  
  2146. const ydMap = new Set();
  2147. ydMap.add = ydMap.addOriginal || ydMap.add;
  2148.  
  2149. window.yMap = yMap;
  2150. window.cMap = cMap;
  2151. window.ydMap = ydMap;
  2152.  
  2153. const constructAts = new Set();
  2154. constructAts.add = constructAts.addOriginal || constructAts.add;
  2155. window.constructAts = constructAts;
  2156.  
  2157. const kMap = new WeakMap();
  2158.  
  2159. const kRefProp = (wr, prop)=>{
  2160. let o = kRef(wr);
  2161. return o ? o[prop] : null;
  2162. }
  2163.  
  2164. const wrObj = (objRef, props) => {
  2165. let wr = mWeakRef(objRef);
  2166. if (wr === objRef || !props || !props.length) return wr;
  2167. let properties = {};
  2168. props.forEach(k => {
  2169. properties[k] = {
  2170. get() {
  2171. return kRefProp(this, k)
  2172. },
  2173. enumerable: false,
  2174. configurable: true
  2175. };
  2176. });
  2177. Object.defineProperties(wr, properties);
  2178. return wr;
  2179. }
  2180.  
  2181. const sProtos = {};
  2182.  
  2183. const setupCProto = function (cProto) {
  2184.  
  2185. if(cProto === Object.prototype) return;
  2186.  
  2187. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2188. cProto[kMap.get(cProto)] = true;
  2189. // debugger;
  2190.  
  2191. if (FIX_SHADY_METHODS && cProto.appendChild && cProto.cloneNode && cProto.contains && cProto.getRootNode && cProto.insertBefore && cProto.querySelector && cProto.querySelectorAll && cProto.removeAttribute && cProto.removeChild && cProto.replaceChild && cProto.setAttribute && cProto.is === undefined && !(cProto instanceof Node)) {
  2192. if (!cProto.krmv757) {
  2193. cProto.krmv757 = true;
  2194. // const props = Object.entries(Object.getOwnPropertyDescriptors(cProto)).filter(a => {
  2195. // const e = a[1];
  2196. // return typeof e.value === 'function' && e.writable === true && e.enumerable === true && e.configurable === true
  2197. // });
  2198. // const keys = props.map(a => a[0]);
  2199. const keys = ['querySelector', 'querySelectorAll'];
  2200. keys.forEach(key => {
  2201. if (!(key in HTMLTitleElement.prototype)) return;
  2202. const bey = `${key}588`;
  2203. cProto[bey] = cProto[key];
  2204. const isDomChange = key === 'appendChild' || key === 'insertBefore' || key === 'removeChild' || key === 'replaceChild';
  2205. cProto[key] = function () {
  2206. const p = ((this || 0).root || 0).node;
  2207. if (!isDomChange && (p instanceof Element) && p.nodeType === 1) {
  2208. return p[key](...arguments);
  2209. } else {
  2210. return this[bey](...arguments);
  2211. }
  2212. }
  2213. });
  2214. }
  2215. }
  2216.  
  2217. 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];
  2218. constructAts.add(constructAt)
  2219.  
  2220. if (MemoryFix_Flag002 & 32) {
  2221. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  2222. fixDetachFn(cProto);
  2223. }
  2224. }
  2225.  
  2226. if (MemoryFix_Flag002 & 2) {
  2227. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  2228. cProto.__setPropDX38__ = true;
  2229.  
  2230. if (cProto._setPendingProperty.length === 3) {
  2231. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  2232. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  2233. return () => {
  2234. const obj = kRef(wobj);
  2235. let u = Reflect.apply(this, obj, args);
  2236. args.length = 0;
  2237. wobj = null;
  2238. return u;
  2239. };
  2240. });
  2241. }
  2242.  
  2243. }
  2244. }
  2245.  
  2246.  
  2247. const cProtoConstructor = cProto.constructor;
  2248.  
  2249. if (MemoryFix_Flag002 & 8) {
  2250. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  2251. cProtoConstructor.__parseBindingsDX38__ = true;
  2252.  
  2253. ydMap.add(cProtoConstructor);
  2254.  
  2255. if (cProtoConstructor._parseBindings.length === 2) {
  2256.  
  2257. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  2258.  
  2259. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  2260. let p = this._parseBindings3858(c, d);
  2261. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  2262. if (p) this.__bindingsArrs__.push(p);
  2263. return p;
  2264. });
  2265.  
  2266. }
  2267. }
  2268. }
  2269.  
  2270. /*
  2271. a.prototype._initializeProperties = function() {
  2272. if (Em && this.hasAttribute("disable-upgrade"))
  2273. this.__isUpgradeDisabled = !0;
  2274. else {
  2275. var e = Object.getPrototypeOf(this);
  2276. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  2277. e.__hasRegisterFinished = !0);
  2278. b.prototype._initializeProperties.call(this);
  2279. this.root = this;
  2280. this.created();
  2281. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  2282. this._applyListeners()
  2283. }
  2284. }
  2285. */
  2286. /*
  2287. bOa = function(a, b, c) {
  2288. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  2289. d.prototype.is = b;
  2290. d.prototype.localName = b;
  2291. c && aOa(d, c);
  2292. return function(e) {
  2293. e && (d.prototype.hostElement = e);
  2294. var g = new d;
  2295. g.root = g;
  2296. g.hostElement = e;
  2297. return g
  2298. }
  2299. }
  2300. */
  2301.  
  2302.  
  2303. }
  2304. const symDH = Symbol();
  2305.  
  2306. const wfStore = new WeakMap();
  2307.  
  2308. const wrapF = function (f, key) {
  2309. if (wfStore.get(f)) return wfStore.get(f);
  2310.  
  2311. let g = function () {
  2312. const o = kRef(this);
  2313. if (!o) return;
  2314. const cnt = insp(o);
  2315. // if (cnt === o) return;
  2316. // if (!('ready' in cnt)) return;
  2317. return f.apply(o, arguments);
  2318. };
  2319. g.key38 = key;
  2320. g.originalFunc38 = f;
  2321. g.__wrapF84__ = true;
  2322. wfStore.set(f, g);
  2323. wfStore.set(g, g);
  2324. return g;
  2325. };
  2326.  
  2327. if (MemoryFix_Flag002 & 16) {
  2328. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  2329.  
  2330. Object.defineProperty(Node.prototype, key, {
  2331. get() {
  2332. return this[`__a0939${key}__`];
  2333. },
  2334. set(nv) {
  2335. if (typeof nv !== 'function') return;
  2336. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  2337. this[`__a0939${key}__`] = g;
  2338. return true;
  2339. }
  2340. });
  2341.  
  2342.  
  2343. });
  2344. }
  2345.  
  2346.  
  2347.  
  2348. // const wm = new WeakMap();
  2349.  
  2350. const fixDetachFn = (tpProto) => { // & 32
  2351.  
  2352. if (tpProto.dk322) return;
  2353. tpProto.dk322 = true;
  2354.  
  2355. window.__fixTemplateReuse1058__ = true;
  2356.  
  2357.  
  2358. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  2359. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  2360. tpProto.__ensureTemplatized = function () {
  2361. // console.log(18470001)
  2362. return this.__ensureTemplatized994();
  2363. }
  2364. }
  2365.  
  2366.  
  2367. tpProto.__updateInstances994 = tpProto.__updateInstances;
  2368. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  2369. let bypass= false;
  2370. tpProto.__updateInstances = function (a, b, c) {
  2371.  
  2372. // const a_ = [...a];
  2373. if(!bypass && a === this.items && (a||0).length >=1 ){
  2374.  
  2375. bypass = true;
  2376. // console.log(18470002, a, b,c)
  2377. let e;
  2378. for (e = 0; e < b; e++) {
  2379. let g = this.__instances[e]
  2380. , k = c[e]
  2381. , m = a[k];
  2382. if(g && typeof (m||0) === 'object'){
  2383. // const q = g._shouldPropertyChange;
  2384. // g._shouldPropertyChange = ()=>true;
  2385. // g[this.as] = {};
  2386. // a_[k]=a[k] = m;
  2387. // g[this.as] = m;
  2388.  
  2389. // use public interface notifyPath instead of internal interface _setPendingProperty
  2390. const m_ = a[k] = Object.assign({}, a[k]);
  2391. try {
  2392. g.notifyPath(this.as, {});
  2393. } catch (e) { }
  2394. try {
  2395. g.notifyPath(this.as, m_);
  2396. } catch (e) { }
  2397.  
  2398. // g._setPendingProperty(this.as, {});
  2399. // g._setPendingProperty(this.as, m);
  2400. // g._setPendingProperty(this.indexAs, e);
  2401. // g._setPendingProperty(this.itemsIndexAs, k);
  2402. // delete g._shouldPropertyChange;
  2403. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2404. }
  2405. }
  2406. bypass = false;
  2407.  
  2408. }
  2409. const r = this.__updateInstances994(a,b,c);
  2410.  
  2411. // for (e = 0; e < b; e++) {
  2412. // let g = this.__instances[e]
  2413. // , k = c[e]
  2414. // , m = a_[k];
  2415. // if(g){
  2416. // // const q = g._shouldPropertyChange;
  2417. // // g._shouldPropertyChange = ()=>true;
  2418. // // g[this.as] = m;
  2419. // // g._setPendingProperty(this.as, {});
  2420. // // g._setPendingProperty(this.as, m);
  2421. // // g._setPendingProperty(this.indexAs, e);
  2422. // // g._setPendingProperty(this.itemsIndexAs, k);
  2423. // // delete g._shouldPropertyChange;
  2424. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2425. // }
  2426. // }
  2427.  
  2428. return r;
  2429. }
  2430. }
  2431.  
  2432. tpProto.__detachInstance994 = tpProto.__detachInstance;
  2433. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  2434. tpProto.__detachInstance = function (a) {
  2435. const u = this.__instances[a];
  2436. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2437. const children = (u || 0).children;
  2438. if (children && children.length >= 1) {
  2439. const pp = document.createDocumentFragment();
  2440. for (const s of [...children]) {
  2441. pp.appendChild(s);
  2442. }
  2443. }
  2444. try {
  2445. return this.__detachInstance994(a);
  2446. } catch (e) { }
  2447. return u;
  2448. }
  2449. }
  2450.  
  2451. tpProto.__attachInstance994 = tpProto.__attachInstance;
  2452. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  2453. tpProto.__attachInstance = function (a, b) {
  2454. const u = this.__instances[a];
  2455. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2456. if (u && u.root && b) {
  2457. const root = u.root;
  2458. const pp = document.createDocumentFragment();
  2459. pp.appendChild(root);
  2460. root.appendChild(pp);
  2461. const r = this.__attachInstance994(a, b);
  2462. if (!this.__chunkingId) this.__chunkingId = 0.25;
  2463. return r;
  2464. }
  2465. }
  2466. }
  2467.  
  2468. }
  2469.  
  2470. const ytTemplateDomEntry = (tpProto) => {
  2471.  
  2472. console.log('ytTemplateDomEntry triggered')
  2473.  
  2474.  
  2475. const convertToWeakArr = (arr) => {
  2476.  
  2477. if (arr.isWeak) return;
  2478.  
  2479. for (let i = 0, l = arr.length; i < l; i++) {
  2480. const o = arr[i]
  2481. if (o) {
  2482. let p = kRef(o)
  2483. if (!p) arr[i] = null;
  2484. else {
  2485. if (!o[wk]) o[wk] = mWeakRef(o);
  2486. arr[i] = o[wk];
  2487. }
  2488. }
  2489. }
  2490. arr.isWeak = true;
  2491.  
  2492. }
  2493.  
  2494. const convertToNormalArr = (arr) => {
  2495.  
  2496. if (!arr.isWeak) return;
  2497.  
  2498. for (let i = 0, l = arr.length; i < l; i++) {
  2499. const o = arr[i]
  2500. if (o) {
  2501. let p = kRef(o)
  2502. arr[i] = p;
  2503. }
  2504. }
  2505. arr.isWeak = false;
  2506.  
  2507. }
  2508.  
  2509. if (MemoryFix_Flag002 & 256) {
  2510. Object.defineProperty(tpProto, '__instances', {
  2511. get() {
  2512. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2513. let arr = this.__instances_actual471__;
  2514. if (arr && arr.isWeak) {
  2515. convertToNormalArr(arr);
  2516. for (let i = arr.length - 1; i >= 0; i--) {
  2517. const t = arr[i];
  2518. if (!t) arr.splice(i, 1);
  2519. else if (!t.__keepInstance038__) t.__keepInstance038__ = true;
  2520. }
  2521. Promise.resolve(arr).then(convertToWeakArr);
  2522. }
  2523. return arr;
  2524. },
  2525. set(nv) {
  2526. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2527. this.__instances_actual471__ = nv;
  2528. if (nv && !nv.isWeak) {
  2529. Promise.resolve(nv).then(convertToWeakArr);
  2530. }
  2531. return true;
  2532. },
  2533. enumerable: false,
  2534. configurable: true
  2535. });
  2536. }
  2537.  
  2538. // console.log(91901, tpProto.__detachInstance)
  2539. if (MemoryFix_Flag002 & 32) {
  2540. if (tpProto.__detachInstance) {
  2541. fixDetachFn(tpProto);
  2542. } else {
  2543. Promise.resolve(tpProto).then((tpProto) => {
  2544. // console.log(91902, tpProto.__detachInstance)
  2545. fixDetachFn(tpProto);
  2546. })
  2547. }
  2548. }
  2549.  
  2550. }
  2551.  
  2552. if (MemoryFix_Flag002 & 32) {
  2553. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  2554. set(nv) {
  2555. if (nv === true) return false;
  2556. tpProto = this;
  2557. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  2558. tpProto.__domDX37__ = true;
  2559. ytTemplateDomEntry(tpProto);
  2560. }
  2561. this.__ensureTemplatized949__ = nv;
  2562. return true;
  2563. },
  2564. get() {
  2565. return this.__ensureTemplatized949__;
  2566. }
  2567. });
  2568. }
  2569.  
  2570.  
  2571. if (MemoryFix_Flag002 & 64) {
  2572. HTMLElement_.prototype.__dataHostBinding374 = true;
  2573. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  2574. get() {
  2575. return kRef(this.__dataHostWr413__);
  2576. },
  2577. set(nv) {
  2578. if (nv && typeof nv === 'object' && !nv.deref) {
  2579. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2580. nv = nv[wk];
  2581. }
  2582. this.__dataHostWr413__ = nv;
  2583. return true;
  2584. }
  2585. });
  2586. }
  2587.  
  2588.  
  2589. const setupYProto = function (yProto) {
  2590.  
  2591. if(yProto === Object.prototype) return;
  2592.  
  2593. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2594. yProto[kMap.get(yProto)] = true;
  2595.  
  2596. 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') {
  2597. const disconnectedCallback277 = yProto.disconnectedCallback;
  2598. yProto.disconnectedCallback277 = true;
  2599. yProto.disconnectedCallback = function () {
  2600. disconnectedCallback277.call(this);
  2601. if (this.nodeName === 'DOM-IF' && this.__instance && typeof this.__teardownInstance === 'function') {
  2602. const shadyParent = (this.__shady_parentNode || 0);
  2603. const actualParent = (this.parentNode || 0);
  2604. if (shadyParent !== actualParent && shadyParent.nodeType === 11 && actualParent.nodeType === 11) {
  2605. // && (shadyParent.compareDocumentPosition(actualParent) & (1|8|16) === 1)
  2606. // if (!this.restamp && !this.id && this.__ctor && this.isConnected === false) {
  2607. const children = (this.__instance.children || 0).length;
  2608. if (children >= 1) {
  2609. try {
  2610. this.__teardownInstance();
  2611. } catch (e) { }
  2612. }
  2613. // }
  2614. }
  2615. }
  2616. }
  2617. }
  2618.  
  2619.  
  2620. if (MemoryFix_Flag002 & 32) {
  2621. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  2622. fixDetachFn(yProto);
  2623. }
  2624. }
  2625.  
  2626. if (MemoryFix_Flag002 & 128) {
  2627. if (!yProto.__dataHostBinding374) {
  2628. yProto.__dataHostBinding374 = true;
  2629. Object.defineProperty(yProto, '__dataHost', {
  2630. set(nv) {
  2631. let dh = nv;
  2632. if (dh && typeof dh === 'object' && !dh.deref) {
  2633. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  2634. dh = wr;
  2635. }
  2636. this[symDH] = dh;
  2637. return true;
  2638. },
  2639. get() {
  2640. let wr = this[symDH];
  2641. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  2642. return obj;
  2643. },
  2644. enumerable: false,
  2645. configurable: true
  2646. });
  2647. }
  2648.  
  2649.  
  2650.  
  2651. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  2652. yProto._registerHostDX38__ = true;
  2653.  
  2654. // yProto._registerHost7133 = yProto._registerHost;
  2655.  
  2656. yProto.__enableOrFlushClients = function () {
  2657. const c_ = this.__dataPendingClients;
  2658. if (c_) {
  2659. const c = c_.slice();
  2660. c_.length = 0;
  2661. for (let d = 0, l = c.length; d < l; d++) {
  2662. let e = kRef(c[d]);
  2663. if (e) {
  2664. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  2665. }
  2666. }
  2667. }
  2668. }
  2669.  
  2670. yProto._enqueueClient = function (c) {
  2671. if (c === this || !c || typeof c !== 'object') return;
  2672. if (c.deref) c = kRef(c);
  2673. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  2674. if (!c[wk]) c[wk] = mWeakRef(c);
  2675. m.push(c[wk]);
  2676. }
  2677.  
  2678. }
  2679. }
  2680.  
  2681.  
  2682.  
  2683. }
  2684. const setupRendering = function () {
  2685.  
  2686. const cnt = this;
  2687. const cProto = Reflect.getPrototypeOf(cnt);
  2688. let yProto = Reflect.getPrototypeOf(cProto);
  2689.  
  2690. const yProtos = new Set();
  2691.  
  2692. if (!yMap.has(yProto)) {
  2693. // capture all ancenstor constructors of a and b (non-specific component type)
  2694.  
  2695. do {
  2696. if (yProto === Object.prototype || yProto === null) break;
  2697. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  2698. yProtos.add(yProto);
  2699. yProto = Reflect.getPrototypeOf(yProto);
  2700. } while (!yProtos.has(yProto));
  2701.  
  2702. for (const yProto of yProtos) {
  2703. yMap.add(yProto);
  2704. setupYProto(yProto)
  2705. }
  2706.  
  2707. }
  2708.  
  2709.  
  2710. if (!cMap.has(cProto)) {
  2711. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  2712. setupCProto(cProto);
  2713. }
  2714.  
  2715. }
  2716.  
  2717. /*
  2718.  
  2719. jF = function(M) {
  2720. var d = YNV.call(this) || this;
  2721. d._configureProperties(M);
  2722. d.root = d._stampTemplate(d.__dataHost);
  2723. var N = [];
  2724. d.children = N;
  2725. for (var R = d.root.firstChild; R; R = R.nextSibling)
  2726. N.push(R),
  2727. R.__templatizeInstance = d;
  2728. d.__templatizeOwner && d.__templatizeOwner.__hideTemplateChildren__ && d._showHideChildren(!0);
  2729. N = d.__templatizeOptions;
  2730. (M && N.instanceProps || !N.instanceProps) && d._enableProperties();
  2731. return d
  2732. };
  2733. */
  2734.  
  2735. const sb1 = Symbol();
  2736. Object.defineProperty(Object.prototype, 'root', {
  2737. get() {
  2738. return this[sb1];
  2739. },
  2740. set(nv){
  2741. const p = this ? kRef(this) : null;
  2742. const mv = nv ? kRef(nv) : null;
  2743.  
  2744. // if (typeof (this.host || 0) === 'object' && !this.host6833) {
  2745. // const host = this.host;
  2746. // if (!host[wk]) host[wk] = mWeakRef(host);
  2747. // this.host6833 = host[wk];
  2748. // delete this.host;
  2749. // console.log(21883, host)
  2750. // Object.defineProperty(this, 'host', {
  2751. // get() {
  2752. // return kRef(this.host6833);
  2753. // },
  2754. // set(nv) {
  2755. // if (!nv) {
  2756. // this.host6833 = nv;
  2757. // } else {
  2758. // if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2759. // this.host6833 = nv[wk];
  2760. // }
  2761. // return true;
  2762. // }, enumerable: false, configurable: true
  2763. // });
  2764. // }
  2765.  
  2766. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2767. p.__setupRendered399__ = true;
  2768. setupRendering.call(p);
  2769. }
  2770. if (mv && mv.is && !mv.__setupRendered399__) {
  2771. mv.__setupRendered399__ = true;
  2772. setupRendering.call(mv);
  2773. }
  2774.  
  2775. this[sb1] = nv;
  2776. return true;
  2777. }
  2778. });
  2779.  
  2780.  
  2781. }
  2782.  
  2783. let _cssSheet = null;
  2784. const addNewCSS = typeof CSSStyleSheet !== 'undefined' && document.adoptedStyleSheets ? (css) => {
  2785. if (!_cssSheet) {
  2786. _cssSheet = new CSSStyleSheet();
  2787. document.adoptedStyleSheets.push(_cssSheet);
  2788. }
  2789. _cssSheet.insertRule(`${css}`);
  2790. } : (css) => {
  2791. let nonce = document.querySelector('style[nonce]');
  2792. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2793. const st = document.createElement('style');
  2794. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2795. st.textContent = `${css}`;
  2796. let parent;
  2797. if (parent = document.head) parent.appendChild(st);
  2798. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  2799. }
  2800.  
  2801. function getTranslate() {
  2802.  
  2803. pLoad.then(() => {
  2804. addNewCSS(".yt-formatted-string-block-line{display:block;}");
  2805. });
  2806.  
  2807. const snCache = new Map();
  2808.  
  2809. if (TRANSLATE_DEBUG) {
  2810. console.log(11)
  2811. }
  2812.  
  2813. /** @type {(str: string?) => string} */
  2814. function _snippetText(str) {
  2815. // str can be underfinded
  2816. if (!str || typeof str !== 'string') return '';
  2817. let res = snCache.get(str);
  2818. if (res === undefined) {
  2819. let b = false;
  2820. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  2821. b = true;
  2822. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  2823. });
  2824. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  2825. b = true;
  2826. return '';
  2827. });
  2828. if (b) {
  2829. snCache.set(str, res);
  2830. snCache.set(res, null);
  2831. } else {
  2832. res = null;
  2833. snCache.set(str, null);
  2834. }
  2835. }
  2836. return res === null ? str : res;
  2837. }
  2838.  
  2839. /** @type {(snippet: Object) => string} */
  2840. function snippetText(snippet) {
  2841. let runs = snippet.runs;
  2842. const n = runs.length;
  2843. if (n === 1) return _snippetText(runs[0].text);
  2844. let res = new Array(n);
  2845. let ci = 0;
  2846. for (const s of runs) {
  2847. res[ci++] = _snippetText(s.text);
  2848. }
  2849. return res.join('\n');
  2850. }
  2851.  
  2852. const _DEBUG_szz = (t) => t.map(x => {
  2853. const tsr = x.transcriptSegmentRenderer;
  2854. return ({
  2855. t: tsr.snippet.runs.map(x => x.text).join('//'),
  2856. a: tsr.startMs,
  2857. b: tsr.endMs
  2858. });
  2859. });
  2860.  
  2861. const fixRuns = (runs) => {
  2862. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  2863. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  2864. const text = runs[0].text;
  2865. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  2866. const s = text.split(nlc);
  2867. let bi = 0;
  2868. runs.length = s.length;
  2869. for (const text of s) {
  2870. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  2871. }
  2872. }
  2873. for (const s of runs) {
  2874. s.text = _snippetText(s.text);
  2875. }
  2876. }
  2877.  
  2878. function translate(initialSegments) {
  2879. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  2880.  
  2881. if (!initialSegments) return initialSegments;
  2882.  
  2883. if (TRANSLATE_DEBUG) {
  2884. console.log(12);
  2885. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  2886. let obj = JSON.parse(r);
  2887. console.log(7558, 1, obj)
  2888. return obj;
  2889. }).then(p => {
  2890. let obj = _DEBUG_szz(p)
  2891. console.log(7558, 2, obj)
  2892. })
  2893. }
  2894.  
  2895.  
  2896. //let mapRej = new WeakSet();
  2897.  
  2898. const n1 = initialSegments.length;
  2899. if (!n1) return fRes;
  2900. let n2 = 0;
  2901.  
  2902.  
  2903. const fRes = new Array(n1);
  2904. // -----------------------------------------------------------------------------------------
  2905.  
  2906. const s8 = Symbol();
  2907.  
  2908. {
  2909.  
  2910. /** @type {Map<String, Object>} */
  2911. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  2912.  
  2913. // /-* * @type {Map<String, number>} *-/
  2914. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  2915. // 1: ok
  2916. // 2: abandoned effect text
  2917.  
  2918. for (const initialSegment of initialSegments) {
  2919. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  2920. if (!transcript) {
  2921. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2922. fRes[n2++] = initialSegment;
  2923. continue;
  2924. }
  2925. const runs = transcript.snippet.runs
  2926. if (!runs || runs.length === 0) {
  2927. initialSegment[s8] = true;
  2928. continue;
  2929. }
  2930. let startMs = (+transcript.startMs || 0); //integer
  2931. let endMs = (+transcript.endMs || 0); //integer
  2932. if (startMs === endMs) {
  2933. // effect text
  2934. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2935. //mapRej.add(initialSegment)
  2936. continue;
  2937. }
  2938. if (endMs - startMs < 30) {
  2939. continue;
  2940. }
  2941. const text = snippetText(transcript.snippet);
  2942. const hEntry = cacheTexts.get(text);
  2943. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  2944. if (mh1e === 2) continue;
  2945. const entry = {
  2946. startMs,
  2947. endMs,
  2948. initialSegment,
  2949. text
  2950. };
  2951. if (mh1e === 0) {
  2952. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  2953. initialSegment[s8] = true;
  2954. cacheTexts.set(text, null);
  2955. //effect only
  2956. // https://www.youtube.com/watch?v=zLak0dxBKpM
  2957. //mapRej.add(initialSegment)
  2958. continue;
  2959. }
  2960. } else if (hEntry) {
  2961.  
  2962. const timeDiff = entry.startMs - hEntry.endMs;
  2963. let shouldMerge = false;
  2964.  
  2965. if (timeDiff >= 0) {
  2966.  
  2967. if (timeDiff < 25) {
  2968. shouldMerge = true;
  2969. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  2970. shouldMerge = true;
  2971. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  2972. shouldMerge = true;
  2973. }
  2974.  
  2975. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  2976. // abandon the current entry.
  2977. // absorbed by previous entry
  2978. hEntry.endMs = entry.endMs;
  2979. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2980. //mapRej.add(entry.initialSegment);
  2981. continue;
  2982. }
  2983.  
  2984. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  2985.  
  2986. // abandon the current entry.
  2987. // absorbed by previous entry
  2988. if (entry.endMs > hEntry.endMs) {
  2989. hEntry.endMs = entry.endMs;
  2990. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2991. }
  2992. //mapRej.add(entry.initialSegment);
  2993. continue;
  2994.  
  2995. }
  2996.  
  2997. }
  2998. //if not abandoned
  2999. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  3000. // for (const s of runs) {
  3001. // s.text = _snippetText(s.text);
  3002. // }
  3003. fixRuns(runs);
  3004. fRes[n2++] = initialSegment;
  3005. }
  3006.  
  3007. // cacheTexts.clear(); // let GC do it.
  3008. cacheTexts = null;
  3009. // mh1.clear(); // let GC do it.
  3010. // mh1 = null;
  3011.  
  3012. }
  3013.  
  3014. const si_length = fRes.length = n2;
  3015. const sj_length = n1;
  3016.  
  3017. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  3018. // collect the abandon text to become second subtitle
  3019.  
  3020. let sj_start = 0;
  3021. let invalid_sj = -1;
  3022. for (let si = 0; si < si_length; si++) {
  3023. const segment = fRes[si];
  3024. let transcript = segment.transcriptSegmentRenderer;
  3025. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  3026. const runs = transcript.snippet.runs;
  3027. // fixRuns(runs);
  3028. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  3029. const main_startMs = (+transcript.startMs || 0);
  3030. const main_endMs = (+transcript.endMs || 0);
  3031. transcript = null;
  3032.  
  3033. /** @type {Map<string, number>} */
  3034. let tMap = new Map(); // avoid duplicate with javascript object properties
  3035.  
  3036. // assume that it is asc-ordered array of key startMs;
  3037. for (let sj = sj_start; sj < sj_length; sj++) {
  3038. const initialSegment = initialSegments[sj];
  3039.  
  3040. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  3041.  
  3042. const tSegment = initialSegment.transcriptSegmentRenderer;
  3043.  
  3044. if (!tSegment) {
  3045. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  3046. invalid_sj = sj; // should invalid_sj be set ?
  3047. continue;
  3048. }
  3049.  
  3050. const startMs = (+tSegment.startMs || 0)
  3051. const isStartValid = startMs >= main_startMs;
  3052. if (!isStartValid) {
  3053. invalid_sj = sj;
  3054. continue;
  3055. }
  3056. // isStartValid must be true
  3057. if (startMs > main_endMs) {
  3058. sj_start = invalid_sj + 1;
  3059. break;
  3060. }
  3061.  
  3062. const endMs = (+tSegment.endMs || 0)
  3063. if (endMs <= main_endMs) {
  3064. const mt = snippetText(tSegment.snippet);
  3065. const prev = tMap.get(mt);
  3066. if (endMs >= startMs) {
  3067. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  3068. }
  3069. }
  3070.  
  3071. }
  3072.  
  3073. if (tMap.size <= 1) continue; // no second line
  3074. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  3075. tMap = null;
  3076.  
  3077. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  3078.  
  3079. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  3080.  
  3081. let targetZ = rg[1][1];
  3082. if (targetZ > 4) {
  3083. let az = 0;
  3084. let fail = false;
  3085. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  3086. az += rg[idx][1];
  3087. if (az >= targetZ) {
  3088. fail = true;
  3089. break;
  3090. }
  3091. }
  3092. if (!fail) {
  3093. const rgA = rg[0][0];
  3094. const rgB = rg[1][0];
  3095. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  3096. if (isDiff && rgA === _snippetText(runs[0].text)) {
  3097. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  3098. runs.push({ text: rgB, blockLine: true });
  3099. }
  3100. }
  3101. }
  3102. rg = null;
  3103. }
  3104.  
  3105. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  3106.  
  3107. let obj = r;
  3108. console.log(7559, 1, obj)
  3109. return obj;
  3110. }).then(p => {
  3111. let obj = _DEBUG_szz(p)
  3112. console.log(7559, 2, obj)
  3113.  
  3114. });
  3115. }
  3116.  
  3117. // -----------------------------------------------------------------------------------------
  3118. snCache.clear();
  3119. return fRes;
  3120.  
  3121. }
  3122.  
  3123.  
  3124. return translate
  3125.  
  3126. }
  3127.  
  3128.  
  3129. let translateFn = null;
  3130.  
  3131. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  3132.  
  3133. const wmx = new WeakMap();
  3134.  
  3135. function fixSegments(ytObj) {
  3136. let a, b;
  3137. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  3138. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  3139. translateFn = translateFn || getTranslate();
  3140. let cSeg;
  3141. cSeg = wmx.get(seg);
  3142. if (!cSeg) {
  3143. let vSeg = null;
  3144. try {
  3145. vSeg = translateFn(seg);
  3146. } catch (e) {
  3147. }
  3148. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  3149. // console.log('translated', vSeg);
  3150. cSeg = vSeg;
  3151. wmx.set(seg, cSeg);
  3152. wmx.set(cSeg, cSeg);
  3153. }
  3154. }
  3155. if (cSeg && cSeg !== seg) {
  3156. a[b] = cSeg;
  3157. }
  3158. }
  3159.  
  3160. const dfn = Symbol();
  3161. const Object_ = Object;
  3162. Object_[dfn] = Object_.defineProperties;
  3163. let activation = true;
  3164. Object_.defineProperties = function (obj, pds) {
  3165. let segments, get_;
  3166. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  3167. activation = false;
  3168. segments.get = function () {
  3169. fixSegments(this);
  3170. return get_.call(this);
  3171. };
  3172. }
  3173. return Object_[dfn](obj, pds);
  3174. };
  3175.  
  3176. })();
  3177.  
  3178.  
  3179. let pf31 = new PromiseExternal();
  3180.  
  3181. // native RAF
  3182. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  3183.  
  3184. // 1st wrapped RAF
  3185. const baseRAF = (callback) => {
  3186. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  3187. pf31.then(() => {
  3188. callback(hRes);
  3189. });
  3190. });
  3191. };
  3192.  
  3193. // 2nd wrapped RAF
  3194. window.requestAnimationFrame = baseRAF;
  3195.  
  3196. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  3197. const indr = o => insp(o).$ || o.$ || 0;
  3198.  
  3199. const prototypeInherit = (d, b) => {
  3200. const m = Object.getOwnPropertyDescriptors(b);
  3201. for (const p in m) {
  3202. if (!Object.getOwnPropertyDescriptor(d, p)) {
  3203. Object.defineProperty(d, p, m[p]);
  3204. }
  3205. }
  3206. };
  3207.  
  3208.  
  3209. const firstObjectKey = (obj) => {
  3210. for (const key in obj) {
  3211. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  3212. }
  3213. return null;
  3214. };
  3215.  
  3216. function searchNestedObject(obj, predicate, maxDepth = 64) {
  3217. // normal case: depth until 36
  3218. const result = [];
  3219. const visited = new WeakSet();
  3220.  
  3221. function search(obj, depth) {
  3222. visited.add(obj);
  3223. for (const [key, value] of Object.entries(obj)) {
  3224. // Recursively search nested objects and arrays
  3225. if (value !== null && typeof value === 'object') {
  3226. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  3227. if (depth + 1 <= maxDepth && !visited.has(value)) {
  3228. search(value, depth + 1);
  3229. }
  3230. } else if (predicate(value)) {
  3231. result.push([obj, key]);
  3232. }
  3233. }
  3234. }
  3235.  
  3236. typeof (obj || 0) === 'object' && search(obj, 0);
  3237. return result;
  3238. }
  3239.  
  3240. /** @type {(o: Object | null) => WeakRef | null} */
  3241. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  3242.  
  3243. /** @type {(wr: Object | null) => Object | null} */
  3244. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  3245.  
  3246. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  3247.  
  3248. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  3249. if (DENY_requestStorageAccess) {
  3250. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  3251. Document.prototype.requestStorageAccessFor = undefined;
  3252. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  3253. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  3254. Document.prototype.requestStorageAccessFor = function () {
  3255. return new Promise((resolve, reject) => {
  3256. reject();
  3257. });
  3258. };
  3259. }
  3260. }
  3261.  
  3262. const traceStack = (stack) => {
  3263. let result = new Set();
  3264. let p = new Set();
  3265. let u = ''
  3266. for (const s of stack.split('\n')) {
  3267. if (s.split(':').length < 3) continue;
  3268. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  3269. if (!m) continue;
  3270. p.add(m[2]);
  3271. if (p.size >= 3) break;
  3272. if(!u) u = m[2];
  3273. else if(p.size === 2 && u && u=== m[2]) break;
  3274. result.add(s);
  3275. }
  3276. return [...result].join('\n');
  3277. }
  3278.  
  3279. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  3280. // window.m3bb = new Set();
  3281.  
  3282. // const smb = Symbol();
  3283. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  3284. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  3285. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  3286.  
  3287. const thisConversionFn = (thisArg) => {
  3288. if (!thisArg) return null;
  3289. const kThis = thisArg[vmb];
  3290. if (kThis) {
  3291. const ref = kThis.ref;
  3292. return (ref ? kRef(ref) : null) || null;
  3293. }
  3294. return thisArg;
  3295. }
  3296.  
  3297. const pFnHandler2 = {
  3298. get(target, prop) {
  3299. if (prop === vmc) return target;
  3300. return Reflect.get(target, prop);
  3301. },
  3302. apply(target, thisArg, argumentsList) {
  3303. thisArg = thisConversionFn(thisArg);
  3304. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  3305. }
  3306. }
  3307.  
  3308.  
  3309. const proxySelfHandler = {
  3310. get(target, prop) {
  3311. if(prop === vmb) return target;
  3312. const ref = target.ref;
  3313. const cnt = kRef(ref);
  3314. if (!cnt) return;
  3315. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  3316. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  3317. return cnt[prop][vmd];
  3318. }
  3319. return cnt[prop];
  3320. },
  3321. set(target, prop, value) {
  3322. const cnt = kRef(target.ref);
  3323. if (!cnt) return true;
  3324. if(value && (value[vmc] || value[vmb])){
  3325. cnt[prop] = value[vmc] || thisConversionFn(value);
  3326. return true;
  3327. }
  3328. cnt[prop] = value;
  3329. return true;
  3330. }
  3331. };
  3332.  
  3333. const weakWrap = (thisArg) => {
  3334. thisArg = thisConversionFn(thisArg);
  3335. if (!thisArg) {
  3336. console.error('thisArg is not found');
  3337. return null;
  3338. }
  3339. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  3340. }
  3341.  
  3342. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  3343. window.getComputedStyle533 = window.getComputedStyle;
  3344. window.getComputedStyle = function (a, ...args) {
  3345. a = thisConversionFn(a);
  3346. if (a) {
  3347. return getComputedStyle533(a, ...args);
  3348. }
  3349. return null;
  3350. }
  3351. }
  3352.  
  3353. Function._count_bind_00 = 0;
  3354. // Function._count_bind_01 = 0;
  3355.  
  3356. // let matchNativeCode = (Object+"");
  3357. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  3358. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  3359.  
  3360. // const matchConstructor = (thisArg) => {
  3361. // const f = `${(thisArg || 0).constructor}`;
  3362. // if (f.length > 45) return true;
  3363. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  3364. // if (f.includes('[native code]')){
  3365. // return false;
  3366. // }
  3367. // return true;
  3368. // }
  3369. // return false;
  3370. // }
  3371.  
  3372. // const acceptThis = (thisArg)=>{
  3373. // // if(!thisArg || typeof thisArg !=='object') return false;
  3374. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  3375. // // if(typeof thisArg.path === 'string') return true;
  3376. // // if(typeof thisArg.fn === 'function') return true;
  3377. // // if(typeof thisArg.id === 'string') return true;
  3378. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  3379. // return false;
  3380. // }
  3381.  
  3382. const patchFn = (fn) => {
  3383.  
  3384. let s = `${fn}`;
  3385. if (s.length < 11 || s.includes('\n')) return false;
  3386. if(s.includes('bind(this')) return true;
  3387. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  3388. // var a=this;
  3389. // f.bind(this)
  3390.  
  3391.  
  3392. return false;
  3393. }
  3394.  
  3395. Function.prototype.bind488 = Function.prototype.bind;
  3396. Function.prototype.bind = function(thisArg, ...args){
  3397.  
  3398. if (thisConversionFn(thisArg) !== thisArg) {
  3399. return this.bind488(thisArg, ...args);
  3400. }
  3401. if( thisArg && patchFn(this) ){
  3402.  
  3403. // console.log(599,`${this}`)
  3404.  
  3405. try {
  3406. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  3407. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  3408. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  3409. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  3410. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  3411. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  3412. // // let b4 = false;
  3413. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  3414.  
  3415. // // b3 = false;
  3416. // // b4 = false;
  3417. // // b5 = false;
  3418.  
  3419. // if (b1 || b2 || b3 ||b4 ) {
  3420. const f = this;
  3421. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  3422. if (ps && ps[vmb]) {
  3423. Function._count_bind_00++;
  3424. return f.bind488(ps, ...args)
  3425. }
  3426. // }
  3427. } catch (e) {
  3428. console.warn(e)
  3429. }
  3430. }
  3431. return this.bind488(thisArg, ...args);
  3432. }
  3433. Function.prototype.bind588 = 1;
  3434. }
  3435.  
  3436. const ytSchedulerMethods = {
  3437. addJob(a, b, c) {
  3438. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3439. if (instance) {
  3440. return instance.addJob(a, b, c);
  3441. } else {
  3442. return setTimeout(a, c);
  3443. }
  3444. },
  3445. addImmediateJob(a) {
  3446. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3447. if (instance) {
  3448. return instance.addImmediateJob(a);
  3449. } else {
  3450. a();
  3451. }
  3452. },
  3453. cancelJob(id) {
  3454. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3455. if (instance) {
  3456. return instance.cancelJob(id);
  3457. } else {
  3458. return clearTimeout(id);
  3459. }
  3460. }
  3461. };
  3462.  
  3463. if (FIX_ytScheduler) {
  3464.  
  3465. let ytSchedulerFixed = 0;
  3466. // let ytActioned = false;
  3467. // let pr = new PromiseExternal();
  3468.  
  3469. // const hn = function () {
  3470.  
  3471. // document.removeEventListener('yt-action', hn, true);
  3472. // nextBrowserTick_(() => {
  3473. // ytActioned = true;
  3474. // pr.resolve();
  3475. // });
  3476.  
  3477. // }
  3478. // document.addEventListener('yt-action', hn, true);
  3479.  
  3480. // let cancelStore = {}; // tbc
  3481.  
  3482. // yt.scheduler.instance.addJob
  3483. const fixAddJob = (nv) => {
  3484.  
  3485. /*
  3486. function Z() {
  3487. var a = w("ytglobal.schedulerInstanceInstance_");
  3488. if (!a || a.s)
  3489. a = new M(I("scheduler") || {}),
  3490. x("ytglobal.schedulerInstanceInstance_", a);
  3491. return a
  3492. }
  3493. */
  3494.  
  3495. /*
  3496. function R(a, b, c, d) {
  3497. ++a.D;
  3498. if (c === 10)
  3499. return P(a, b),
  3500. a.D;
  3501. var e = a.D;
  3502. a.h[e] = b;
  3503. a.l && !d ? a.u.push({
  3504. id: e,
  3505. priority: c
  3506. }) : (a.i[c].push(e),
  3507. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  3508. a.start()));
  3509. return e
  3510. }
  3511. */
  3512.  
  3513. /*
  3514. function sa(a, b, c) {
  3515. if (!c)
  3516. return c = c === void 0,
  3517. -R(Z(), a, b, c);
  3518. var d = window.setTimeout(function() {
  3519. var e = R(Z(), a, b);
  3520. W[d] = e
  3521. }, c);
  3522. return d
  3523. }
  3524. */
  3525. window.originalAddJob = nv;
  3526. // const q1 = new PromiseExternal();
  3527. // const q2 = new PromiseExternal();
  3528. // let uu = 0;
  3529. // let q3 = 0;
  3530. // let mof = null;
  3531. // const mo = new MutationObserver((mutation, observer) => {
  3532. // if (mof) {
  3533. // if (mof() === true) {
  3534. // observer.disconnect();
  3535. // mof = null;
  3536. // }
  3537. // }
  3538. // });
  3539.  
  3540. let lenSkip = -1;
  3541. let lastLen = null;
  3542. let fetchCommentJobTimerId = 0;
  3543. let requestFinish = false;
  3544.  
  3545. const fetchCommentJobDone = ()=>{
  3546. clearInterval(fetchCommentJobTimerId);
  3547. fetchCommentJobTimerId = 0;
  3548. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3549. }
  3550.  
  3551. const fetchCommentJob = (a, cid) => {
  3552.  
  3553. // if (cid && cancelStore[cid]) return; // tbc
  3554.  
  3555. if(fetchCommentJobTimerId > 0){
  3556. fetchCommentJobDone();
  3557. }
  3558.  
  3559. // if (mof) {
  3560. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3561. // mof = null;
  3562. // }
  3563.  
  3564. let f = a;
  3565.  
  3566. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  3567.  
  3568. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  3569.  
  3570. lastLen = -1;
  3571. let u = 0;
  3572. let g = () => {
  3573. if (requestFinish) lastLen = -1;
  3574. const lastLen_ = lastLen;
  3575. const len1 = lastLen = document.querySelectorAll(selector).length;
  3576. let mm = true;
  3577. let ff = false;
  3578. if (len1 !== lastLen_) {
  3579. u = 0;
  3580. f();
  3581. const len2 = lastLen = document.querySelectorAll(selector).length;
  3582. if (len2 !== len1) {
  3583. ff = true;
  3584. mm = false;
  3585. }
  3586. }
  3587. if (mm) {
  3588. ++u;
  3589. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  3590. ff = true;
  3591. }
  3592. }
  3593.  
  3594. if (requestFinish) {
  3595. requestFinish = false;
  3596. fetchCommentJobDone();
  3597. } else if (ff){
  3598. fetchCommentJobDone();
  3599. }
  3600.  
  3601. }
  3602.  
  3603.  
  3604. fetchCommentJobTimerId = setInterval(g, 80);
  3605. // g(9);
  3606. // if (lastLen === lenSkip) {
  3607. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3608. // g = f = null;
  3609. // return;
  3610. // }
  3611. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3612. // const q1 = lastLen;
  3613. // mof = () => {
  3614. // const q2 = document.querySelectorAll(selector).length;
  3615. // if (q1 === q2) return;
  3616. // fetchCommentJobTimerId = setTimeout(g, 80);
  3617. // g = null;
  3618. // return true;
  3619. // }
  3620. // mo.observe(document, { childList: true, subtree: true });
  3621.  
  3622. }
  3623.  
  3624. // let pr72 = Promise.resolve();
  3625.  
  3626.  
  3627. let qa = null;
  3628. let qasf = '';
  3629.  
  3630.  
  3631. document.addEventListener("fullscreenchange", (evt) => {
  3632. if (evt.isTrusted !== true) return;
  3633. if (qa) {
  3634. // qa();
  3635. nextBrowserTick_(qa);
  3636. }
  3637. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3638. // pr72 = pr72.then(() => {
  3639. // return pr
  3640. // });
  3641. }, true);
  3642.  
  3643. window.addEventListener("resize", (evt) => {
  3644. if (evt.isTrusted !== true) return;
  3645. if (qa) {
  3646. // qa();
  3647. nextBrowserTick_(qa);
  3648. }
  3649. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3650. // pr72 = pr72.then(() => {
  3651. // return pr
  3652. // });
  3653. }, true);
  3654.  
  3655.  
  3656. setInterval(() => {
  3657. const f = qa;
  3658. if (typeof f !== 'function') return;
  3659. qa = null;
  3660. // pr72 = pr72.then(() => {
  3661. // f();
  3662. // });
  3663. // nextBrowserTick_(()=>{
  3664. f();
  3665. // });
  3666. }, 475.25);
  3667.  
  3668.  
  3669.  
  3670. return function (a, b, c) {
  3671.  
  3672.  
  3673. const f = a;
  3674. // const g = ()=>{
  3675. // pr72 = pr72.then(()=>{
  3676. // f();
  3677. // });
  3678. // }
  3679.  
  3680. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  3681.  
  3682. const c_ = c;
  3683.  
  3684. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  3685.  
  3686. if (b === 1 && c_ === 500) {
  3687. const sf = `${a}`;
  3688. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  3689. qasf = sf;
  3690. qa = a;
  3691. // console.log(12883, a)
  3692. return nv(() => {
  3693. if (qa === a) {
  3694. qa = null;
  3695. a();
  3696. }
  3697. }, b, c);
  3698. }
  3699. }
  3700.  
  3701.  
  3702. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  3703. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  3704. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3705. // pr72 = pr72.then(() => {
  3706. // return pr
  3707. // });
  3708. // try {
  3709. // yt.scheduler.instance.cancelAllJobs();
  3710. // yt.scheduler.instance.dispose();
  3711. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  3712. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  3713. // } catch (e) { }
  3714. return nv(f, b, c);
  3715. }
  3716.  
  3717. // if(!b && c > 50) c = 50;
  3718. // console.log(58372,a,b,c)
  3719. // function(){xxx(xxx)}
  3720. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  3721.  
  3722. /*
  3723.  
  3724. V.setCommentsJobId = _.et(_.r0, function() {
  3725. F5V(V)
  3726. }, 1E3)
  3727.  
  3728. */
  3729.  
  3730. requestFinish = false;
  3731. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  3732.  
  3733. // lastLen = null;
  3734. fetchCommentJob(a, cid);
  3735.  
  3736. // queueMicrotask_(a);
  3737. // nextBrowserTick_(a);
  3738. // a(); // no need to delay
  3739. return cid
  3740.  
  3741. // return nv(a, b, 1.125);
  3742. // const cid = window.setTimeout(() => {
  3743. // nextBrowserTick_(() => {
  3744. // if (cancelStore[cid]) {
  3745. // console.log('task cancelled');
  3746. // return;
  3747. // }
  3748. // a();
  3749.  
  3750. // });
  3751. // }, 0.125);
  3752. // return cid;
  3753. } else {
  3754.  
  3755.  
  3756.  
  3757. return nv(f,b,c);
  3758.  
  3759.  
  3760. // if (c > 2400) c = 2400;
  3761. // else if (c > 800) c = 800;
  3762. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  3763. // if (0 && ytActioned && !b) {
  3764. // const cid = window.setTimeout(() => {
  3765. // nextBrowserTick_(() => {
  3766. // if (cancelStore[cid]) {
  3767. // console.log('task cancelled');
  3768. // return;
  3769. // }
  3770. // a();
  3771. // });
  3772. // }, c);
  3773. // return cid;
  3774. // } else {
  3775. // return nv(a, b, c);
  3776. // }
  3777.  
  3778. }
  3779. }
  3780. }
  3781.  
  3782. const fixCancelJob = (nv) => {
  3783.  
  3784.  
  3785. window.originalCancelJob = nv;
  3786. return function (a) {
  3787. if (a < 0) return nv(a);
  3788. // cancelStore[a] = true; // tbc
  3789. nv(a);
  3790. }
  3791. }
  3792.  
  3793. const sk44 = Symbol();
  3794. Object.defineProperty(Object.prototype, 'addJob', {
  3795. get() {
  3796. return this[sk44];
  3797. },
  3798. set(nv) {
  3799. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3800. ytSchedulerFixed |= 1;
  3801. nv = fixAddJob(nv);
  3802. }
  3803. this[sk44] = nv;
  3804. return true;
  3805. },
  3806. enumerable: false,
  3807. configurable: true
  3808. });
  3809.  
  3810.  
  3811.  
  3812. const sk45 = Symbol();
  3813. Object.defineProperty(Object.prototype, 'cancelJob', {
  3814. get() {
  3815. return this[sk45];
  3816. },
  3817. set(nv) {
  3818. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3819. ytSchedulerFixed |= 2;
  3820. nv = fixCancelJob(nv);
  3821. }
  3822. this[sk45] = nv;
  3823. return true;
  3824. },
  3825. enumerable: false,
  3826. configurable: true
  3827. });
  3828.  
  3829.  
  3830.  
  3831. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3832. const { addJob, cancelJob } = yt.scheduler.instance;
  3833. if (addJob) {
  3834. yt.scheduler.instance.addJob = null;
  3835. yt.scheduler.instance.addJob = addJob;
  3836. }
  3837. if (cancelJob) {
  3838. yt.scheduler.instance.cancelJob = null;
  3839. yt.scheduler.instance.cancelJob = cancelJob;
  3840. }
  3841. }
  3842.  
  3843.  
  3844. }
  3845.  
  3846. const isWatchPageURL = (url) => {
  3847. url = url || location;
  3848. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  3849. };
  3850.  
  3851. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3852.  
  3853. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  3854. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3855. if (typeof customElements === 'undefined') {
  3856. if (!('__CE_registry' in document)) {
  3857. // https://github.com/webcomponents/polyfills/
  3858. Object.defineProperty(document, '__CE_registry', {
  3859. get() {
  3860. // return undefined
  3861. },
  3862. set(nv) {
  3863. if (typeof nv == 'object') {
  3864. delete this.__CE_registry;
  3865. this.__CE_registry = nv;
  3866. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3867. }
  3868. return true;
  3869. },
  3870. enumerable: false,
  3871. configurable: true
  3872. })
  3873. }
  3874. let eventHandler = (evt) => {
  3875. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3876. const f = callback;
  3877. callback = null;
  3878. eventHandler = null;
  3879. f();
  3880. };
  3881. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3882. } else {
  3883. callback();
  3884. }
  3885. });
  3886.  
  3887. const whenCEDefined = isCustomElementsProvided
  3888. ? (nodeName) => customElements.whenDefined(nodeName)
  3889. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3890.  
  3891. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  3892. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  3893. const f = performance.now23 = Performance.prototype.now;
  3894.  
  3895. let k = 0; // 0 <= k < 9998m
  3896. let u = 0;
  3897. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  3898.  
  3899. // By definition, performance.now() is mono increasing.
  3900. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  3901. performance.now = performance.now16 = function () {
  3902. /**
  3903. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  3904. *
  3905. * If consecutive session history entries had history.state.entryTime set to same value,
  3906. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  3907. * and modifying its return value slightly to make sure two close consecutive calls don't
  3908. * get the same result helped with resolving the issue.
  3909. */
  3910. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  3911. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  3912.  
  3913. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  3914. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  3915. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  3916. else { // more than 9998 consecutive calls
  3917. /**
  3918. *
  3919. * max no. of consecutive calls
  3920. *
  3921. * Sample Size: 4800
  3922. * Sample Avg = 1565.375
  3923. * Sample Median = 1469.5
  3924. * Sample Max = 5660 << 7500 << 9999
  3925. *
  3926. *
  3927. * */
  3928. k = 0;
  3929. s += 1 / 7;
  3930. }
  3931. return v + k; // 0 < v - M < v - M + k < v
  3932. }
  3933.  
  3934. let loggerMsg = '';
  3935. if (`${performance.now()}` === `${performance.now()}`) {
  3936. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  3937. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  3938. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  3939. }
  3940. loggerMsg && console.warn(loggerMsg);
  3941. })();
  3942.  
  3943. // let __forceRemoveMode__ = false;
  3944. FIX_removeChild && (() => {
  3945. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  3946. let internalByPass = false;
  3947. const fragD = document.createDocumentFragment();
  3948. fragD.appendChild4201 = fragD.appendChild;
  3949. fragD.removeChild4201 = fragD.removeChild;
  3950. Node.prototype.removeChild062 = Node.prototype.removeChild;
  3951. Node.prototype.removeChild = function (child) {
  3952. try {
  3953. return this.removeChild062(child);
  3954. } catch (e) { }
  3955. if (internalByPass) return child;
  3956. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  3957. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3958. if (idx >= 0) {
  3959. internalByPass = true;
  3960. child.parentNode !== fragD && fragD.appendChild4201(child);
  3961. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3962. fragD.removeChild4201(child);
  3963. internalByPass = false;
  3964. return child;
  3965. }
  3966. }
  3967. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  3968. // // force removal
  3969. // internalByPass = true;
  3970. // child.parentNode !== fragD && fragD.appendChild4201(child);
  3971. // fragD.removeChild4201(child);
  3972. // internalByPass = false;
  3973. // return child;
  3974. // }
  3975. if (this && child) {
  3976. if (this.childNodes && this.childNodes.splice) { // tbc
  3977. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3978. if (idx >= 0) {
  3979. internalByPass = true;
  3980. child.parentNode !== fragD && fragD.appendChild4201(child);
  3981. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3982. fragD.removeChild4201(child);
  3983. internalByPass = false;
  3984. return child;
  3985. }
  3986. }
  3987.  
  3988. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  3989. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  3990. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  3991. return child;
  3992. }
  3993. }
  3994.  
  3995. if (child && child.is === 'tp-yt-paper-tooltip' && !child.parentNode && !child.__shady_parentNode) {
  3996. // skip
  3997. return child;
  3998. }
  3999.  
  4000. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  4001. parent: this, child: child,
  4002. isParent: child.parentNode === this,
  4003. isParentParent: (child.parentNode || 0).parentNode === this,
  4004. parentNode: child.parentNode,
  4005. shadyParent: child.__shady_parentNode,
  4006. isShadyParent: child.__shady_parentNode === this,
  4007. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  4008. });
  4009.  
  4010. }
  4011. return child;
  4012. }
  4013. }
  4014. })();
  4015.  
  4016.  
  4017. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  4018.  
  4019. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  4020.  
  4021. // let cid = 0;
  4022.  
  4023. let mousemoveFn = null;
  4024. let mousemoveDT = 0;
  4025. let mousemoveCount = 0;
  4026. // let qv = false;
  4027. const cif = () => {
  4028. if (!mousemoveFn) return;
  4029. const ct = Date.now();
  4030. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  4031. mousemoveFn && mousemoveFn();
  4032. }
  4033. mousemoveFn = null;
  4034. };
  4035. let mousemoveCId = 0;
  4036. let mouseoverFn = null;
  4037. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  4038. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  4039. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  4040. const bt = `${b}`;
  4041. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  4042. b[`__$$${a}$$1926__`] = true;
  4043. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  4044. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  4045. // console.log(3928, a, this[`__$$${a}$$1937__`])
  4046. if (!this[`__$$${a}$$1938__`]) {
  4047. this[`__$$${a}$$1938__`] = b;
  4048. if (a === 'mousemove') {
  4049. this.addEventListener4882('mouseenter', (evt) => {
  4050. if (mousemoveCId) return;
  4051. mousemoveCId = setIntervalX0(cif, 380);
  4052. });
  4053. this.addEventListener4882('mouseleave', (evt) => {
  4054. clearIntervalX0(mousemoveCId);
  4055. mousemoveCId = 0;
  4056. });
  4057. }
  4058. this.addEventListener4882(a, (evt) => {
  4059. const evt_ = evt;
  4060. if (!this[`__$$${a}$$1937__`]) return;
  4061. if (!this[`__$$${a}$$1938__`]) return;
  4062. if (a === 'mousemove') {
  4063. mouseoverFn && mouseoverFn();
  4064. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  4065. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  4066. } else {
  4067. mousemoveCount = 0;
  4068. }
  4069. const f = mousemoveFn = () => {
  4070. if (f !== mousemoveFn) return;
  4071. mousemoveFn = null;
  4072. this[`__$$${a}$$1938__`](evt_);
  4073. };
  4074. if (mousemoveCount <= 1) mousemoveFn();
  4075. } else {
  4076. if (a === 'mouseout' || a === 'mouseleave') {
  4077. mousemoveFn = null;
  4078. mousemoveDT = 0;
  4079. mousemoveCount = 0;
  4080. this[`__$$${a}$$1938__`](evt_);
  4081. mouseoverFn && mouseoverFn();
  4082. } else { // mouseover, mouseenter
  4083. mousemoveFn = null;
  4084. mousemoveDT = 0;
  4085. mousemoveCount = 0;
  4086. mouseoverFn && mouseoverFn(); // just in case
  4087. const f = mouseoverFn = () => {
  4088. if (f !== mouseoverFn) return;
  4089. mouseoverFn = null;
  4090. this[`__$$${a}$$1938__`](evt_);
  4091. }
  4092. nextBrowserTick_(mouseoverFn);
  4093. }
  4094. }
  4095. }, c);
  4096.  
  4097.  
  4098. return;
  4099. } else {
  4100.  
  4101. return;
  4102. }
  4103. }
  4104.  
  4105. }
  4106. return this.addEventListener4882(a, b, c)
  4107. }
  4108.  
  4109.  
  4110.  
  4111.  
  4112. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  4113. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  4114. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  4115.  
  4116. if (b[`__$$${a}$$1926__`]) {
  4117. b[`__$$${a}$$1926__`] = false;
  4118.  
  4119. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  4120.  
  4121. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  4122.  
  4123. return;
  4124.  
  4125. }
  4126.  
  4127. }
  4128. return this.removeEventListener4882(a, b, c)
  4129. }
  4130.  
  4131.  
  4132. })();
  4133.  
  4134.  
  4135. FIX_DOM_IF_REPEAT && (() => {
  4136. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4137. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  4138. // Be careful of the mixture of polymer functions and native Element functions
  4139. // Be careful of the coding design is different with the modern Yt elements
  4140.  
  4141.  
  4142. /*
  4143.  
  4144.  
  4145. function Ks(a, b, c) {
  4146. if (kj && !BOa(a))
  4147. throw Error("strictTemplatePolicy: template owner not trusted");
  4148. c = c || {};
  4149. if (a.__templatizeOwner)
  4150. throw Error("A <template> can only be templatized once");
  4151. a.__templatizeOwner = b;
  4152. var d = (b ? b.constructor : Js)._parseTemplate(a)
  4153. , e = d.templatizeInstanceClass;
  4154. e || (e = COa(a, d, c),
  4155. d.templatizeInstanceClass = e);
  4156. var g = BOa(a);
  4157. EOa(a, d, c, g);
  4158. c = function() {
  4159. return e.apply(this, arguments) || this
  4160. }
  4161. ;
  4162. h(c, e);
  4163. c.prototype._methodHost = g;
  4164. c.prototype.__dataHost = a;
  4165. c.prototype.__templatizeOwner = b;
  4166. c.prototype.__hostProps = d.hostProps;
  4167. return c
  4168. }
  4169.  
  4170. */
  4171.  
  4172. // Polymer.enqueueDebouncer
  4173.  
  4174. const s81 = Symbol();
  4175. const s83 = Symbol();
  4176. const s84 = Symbol();
  4177. const s85 = Symbol();
  4178. const s85b = Symbol();
  4179. const s85c = Symbol();
  4180.  
  4181. let renderDebounceTs = null;
  4182.  
  4183. let renderDebouncePromise = null;
  4184. let qp;
  4185.  
  4186. const shadyFlushMO = new MutationObserver(() => {
  4187.  
  4188. if (!renderDebounceTs) return;
  4189.  
  4190. if (renderDebounceTs.size > 0) {
  4191. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  4192. try {
  4193. Polymer.flush();
  4194. return;
  4195. } catch (e) { }
  4196. }
  4197.  
  4198. renderDebouncePromise && Promise.resolve().then(() => {
  4199.  
  4200. if (renderDebouncePromise) {
  4201. renderDebouncePromise && renderDebouncePromise.resolve();
  4202. renderDebouncePromise = null;
  4203. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  4204. }
  4205.  
  4206. });
  4207.  
  4208. // Polymer.flush
  4209.  
  4210. window.ShadyDOM && ShadyDOM.flush();
  4211. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  4212.  
  4213.  
  4214. });
  4215.  
  4216. const setupPolymerAdv = () => {
  4217. // here we can obtain the Polymer faster.
  4218. // reserved for future use.
  4219. }
  4220.  
  4221.  
  4222. if (USE_fastDomIf) {
  4223. // 0 = no effect. 1 = enable. 2 = disable
  4224. // fastDomIf because it delayed the rendering process?
  4225. Object.defineProperty(Object.prototype, 'fastDomIf', {
  4226. get() {
  4227. if (this === window.Polymer) {
  4228. const v = USE_fastDomIf === 1 ? true : false;
  4229. this.fastDomIf = v;
  4230. delete Object.prototype.fastDomIf;
  4231. setupPolymerAdv(this);
  4232. return v;
  4233. }
  4234. },
  4235. set(nv) {
  4236. return false;
  4237. }
  4238. });
  4239. }
  4240.  
  4241. let setupDomIfDone = false;
  4242. const setupDomIf = (DomIf)=>{
  4243. setupDomIfDone = true;
  4244. if(setupDomIfDone) return;
  4245.  
  4246. const fProto = DomIf.prototype;
  4247.  
  4248.  
  4249. // Polymer.DomIf
  4250. // Polymer.DomIf = Polymer.fastDomIf ? ZbL : ESz
  4251. // Assume ESz by default
  4252.  
  4253. // We don't need to store "root" in DOM-IF
  4254. if (ENHANCE_DOMIF_createAndInsertInstance && fProto.__createAndInsertInstance && !fProto.__createAndInsertInstance239 && fProto.__createAndInsertInstance.length === 1) {
  4255. fProto.__createAndInsertInstance239 = fProto.__createAndInsertInstance;
  4256. fProto.__createAndInsertInstance = function (M) {
  4257. const r = this.__createAndInsertInstance239(M);
  4258. const __instance = this.__instance;
  4259. const __ctor = this.__ctor;
  4260. if (__instance && __ctor && __instance instanceof __ctor) {
  4261. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4262. const o = __instance[sym];
  4263. if (o && o.nodeType === 11) {
  4264. __instance[sym] = null;
  4265. }
  4266. }
  4267. }
  4268. return r;
  4269. }
  4270.  
  4271. /*
  4272.  
  4273.  
  4274. sX = function(M, d, N) {
  4275. if (o_ && !vDv(M))
  4276. throw Error("Jd");
  4277. N = N || {};
  4278. if (M.__templatizeOwner)
  4279. throw Error("Kd");
  4280. M.__templatizeOwner = d;
  4281. var R = (d ? d.constructor : jF)._parseTemplate(M)
  4282. , X = R.templatizeInstanceClass;
  4283. X || (X = sfi(M, R, N),
  4284. R.templatizeInstanceClass = X);
  4285. var A = vDv(M);
  4286. y9Z(M, R, N, A);
  4287. N = function() {
  4288. return X.apply(this, arguments) || this
  4289. }
  4290. ;
  4291. _.v(N, X);
  4292. N.prototype._methodHost = A;
  4293. N.prototype.__dataHost = M;
  4294. N.prototype.__templatizeOwner = d;
  4295. N.prototype.__hostProps = R.hostProps;
  4296. return N
  4297. }
  4298.  
  4299. */
  4300. }
  4301.  
  4302. // Polymer.DomIf
  4303. // We can fully teardown the entire instance (including stampFrag and stampNodes), just keep ctor stamper
  4304. if (ENHANCE_DOMIF_TEARDOWN && fProto.__teardownInstance && !fProto.__teardownInstance239 && fProto.__teardownInstance.length === 0) {
  4305. fProto.__teardownInstance239 = fProto.__teardownInstance;
  4306. fProto.__teardownInstance = function () {
  4307. const { __instance, __invalidProps } = this;
  4308. let r, e_;
  4309. try {
  4310. r = this.__teardownInstance239();
  4311. } catch (e) { e_ = e }
  4312. if (!__instance) return r;
  4313.  
  4314. try {
  4315.  
  4316. //console.log(599901,this.countEvent767());
  4317. //console.log('__teardownInstance F', __instance, __invalidProps, this._removeEventListenerFromNode, __instance._removeEventListenerFromNode);
  4318. __instance.__data = null;
  4319. __instance.__dataClientsReady = __instance.__dataEnabled = __instance.__dataReady = false;
  4320. __instance.__dataInvalid = true;
  4321. __instance.__dataHost = __instance.__dataTemp = null;
  4322. __instance.__isPropertyEffectsClient = false;
  4323. __instance.__keepInstance038__ = false;
  4324.  
  4325.  
  4326. const __templateInfo = __instance.__templateInfo;
  4327.  
  4328. let stampFragId = null;
  4329. if (__templateInfo && __templateInfo.nodeList) {
  4330. stampFragId = __templateInfo.nodeList.__belongFragId57__;
  4331. for (const weakNodeC of __templateInfo.nodeList) {
  4332. const node = toActualNode(weakNodeC);
  4333. if (node && node.nodeType >= 1) {
  4334. renderPathMake(node)
  4335. node.__keepInstance038__ = false;
  4336. node.remove();
  4337. _removedElements.addNode(node); // rn54011
  4338. }
  4339. }
  4340. __templateInfo.nodeList.length = 0;
  4341. __templateInfo.nodeList = null;
  4342. }
  4343.  
  4344. const stampFrag = stampFragId ? kRef(stampedFragment.get(stampFragId)) : null;
  4345.  
  4346. if (stampFrag && stampFrag.nodeType === 11) {
  4347. stampFrag.__keepInstance038__ = false;
  4348. _removedElements.addNode(stampFrag); // rn54012
  4349. removeAllChildNodes(stampFrag);
  4350. try {
  4351. stampFrag.remove();
  4352. } catch (e) { }
  4353. stampFrag.__shady = null;
  4354. stampFrag.$ = null;
  4355. stampFrag.__fragTeardowned57__ = true;
  4356. stampFrag.nodeList = null;
  4357. stampFrag.templateInfo = null;
  4358.  
  4359. }
  4360.  
  4361. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4362. const o = __instance[sym];
  4363. if (o && o.nodeType === 11) {
  4364. __instance[sym] = null;
  4365. }
  4366. }
  4367.  
  4368. const children = (__instance || 0).children;
  4369. if (children && children.splice) {
  4370. __instance.children = null;
  4371. for (const n of children) {
  4372. if (n && n.nodeType >= 1) {
  4373. n.__keepInstance038__ = false;
  4374. _removedElements.addNode(n); // rn54013
  4375. }
  4376. }
  4377. children.length = 0;
  4378. }
  4379.  
  4380. if (__instance.__templateInfo) __instance.__templateInfo = null;
  4381.  
  4382. if (__instance.root) __instance.root = null;
  4383.  
  4384. } catch (e) {
  4385. console.error(e);
  4386. }
  4387.  
  4388. // console.log(3882)
  4389. if (e_) throw e_;
  4390. return r;
  4391. }
  4392. }
  4393.  
  4394. }
  4395.  
  4396. if (ENHANCE_DOMIF_createAndInsertInstance || ENHANCE_DOMIF_TEARDOWN) {
  4397.  
  4398. Object.defineProperty(Object.prototype, 'DomIf', {
  4399. get() {
  4400. return undefined;
  4401. },
  4402. set(nv) {
  4403. if (typeof (nv || 0) !== 'function') return false;
  4404. delete Object.prototype.DomIf;
  4405. this.DomIf = nv;
  4406. setupDomIf(nv);
  4407. return true;
  4408. },
  4409. enumerable: false,
  4410. configurable: true
  4411. });
  4412.  
  4413. }
  4414.  
  4415. Object.defineProperty(Object.prototype, '_lastIf', {
  4416. get() {
  4417. return this[s81];
  4418. },
  4419. set(nv) {
  4420. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  4421. // DOM-IF initialization
  4422. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  4423.  
  4424. this.__xiWB8__ = 2;
  4425. // this.restamp = true;
  4426.  
  4427. const cProto = this.__proto__;
  4428. if (cProto && !cProto.__xiWB7__) {
  4429. cProto.__xiWB7__ = 1;
  4430.  
  4431. // dom-if __template
  4432. // dom-repeat template
  4433. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  4434. cProto.__template847 = true;
  4435. try {
  4436. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  4437. Object.defineProperty(cProto, '__template', {
  4438. get() {
  4439. const v = this[s84];
  4440. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  4441. },
  4442. set(nv) {
  4443. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  4444. this[s84] = nv;
  4445. return true;
  4446. }
  4447. });
  4448. } catch (e) {
  4449. console.warn(e);
  4450. }
  4451.  
  4452. console.log('FIX_DOM_IF - __template')
  4453. }
  4454.  
  4455. // dom-if __ensureTemplate
  4456. // dom-repeat __ensureTemplatized
  4457. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  4458. // note that "_templateInfo" diffs the different version of DOM-IF
  4459.  
  4460. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  4461. cProto.__ensureTemplate = function () {
  4462. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  4463. if (!this.__template) {
  4464. let b;
  4465. if (this._templateInfo) {
  4466. b = this;
  4467. } else {
  4468. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  4469. b = this.__templateCollection011__[0];
  4470. if (!b) {
  4471. if (!this[wk]) this[wk] = mWeakRef(this);
  4472. let a = this[wk];
  4473. let c = new MutationObserver(function () {
  4474. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  4475. if (c && a) {
  4476. c.disconnect();
  4477. a = kRef(a);
  4478. a && a.__render();
  4479. a && (a.__templateCollection011__ = null);
  4480. }
  4481. c = null;
  4482. a = null;
  4483. });
  4484. c && c.observe(this, {
  4485. childList: !0
  4486. });
  4487. return !1
  4488. } else {
  4489. this.__templateCollection011__ = null;
  4490. }
  4491. }
  4492. this.__template = b
  4493. }
  4494. return !0
  4495. }
  4496.  
  4497. console.log('FIX_DOM_IF - __ensureTemplate')
  4498.  
  4499. }
  4500.  
  4501.  
  4502. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  4503. }
  4504.  
  4505.  
  4506. // need to fix __observeEffects
  4507. // this.__observeEffects.if[0].info.method === this.__debounceRender
  4508. const f = () => {
  4509.  
  4510. const __observeEffects = this.__observeEffects;
  4511.  
  4512. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  4513. for (const effect of __observeEffects.if) {
  4514. const info = effect.info;
  4515. if (info && typeof info.method === 'function') {
  4516.  
  4517. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4518. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4519. }
  4520.  
  4521. }
  4522. }
  4523. }
  4524.  
  4525.  
  4526. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  4527. for (const effect of __observeEffects.restamp) {
  4528. const info = effect.info;
  4529. if (info && typeof info.method === 'function') {
  4530.  
  4531. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4532. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4533. }
  4534.  
  4535. }
  4536. }
  4537. }
  4538.  
  4539. // console.log(5881, this.__observeEffects)
  4540. }
  4541.  
  4542. }
  4543. this[s81] = nv;
  4544. return true;
  4545. }
  4546. });
  4547.  
  4548.  
  4549. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  4550. get() {
  4551. return this[s85];
  4552. },
  4553. set(nv) {
  4554. if (nv === null && this[s85] === undefined) {
  4555. // DOM-IF / DOM-REPEAT initialization
  4556.  
  4557.  
  4558. const cProto = this.__proto__;
  4559. if (qp) {
  4560. qp.obtain();
  4561. qp = null;
  4562. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  4563. }
  4564.  
  4565. }
  4566. this[s85] = nv;
  4567. return true;
  4568. }
  4569. });
  4570.  
  4571. // PS-DOM-REPEAT
  4572.  
  4573. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  4574. get() {
  4575. return this[s85b];
  4576. },
  4577. set(nv) {
  4578.  
  4579. this[s85b] = nv;
  4580. return true;
  4581. }
  4582. })
  4583.  
  4584. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  4585. get() {
  4586. return this[s85c];
  4587. },
  4588. set(nv) {
  4589.  
  4590. this[s85c] = nv;
  4591. return true;
  4592. }
  4593. })
  4594.  
  4595.  
  4596. })();
  4597.  
  4598. const setupXdeadC = (cnt)=>{
  4599.  
  4600. let xdeadc = xdeadc00;
  4601. if(!xdeadc){
  4602. setupSDomWrapper(); // just in case
  4603. const hostElement = cnt.hostElement;
  4604. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4605. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4606. hostElement.lastChild.replaceWith(el);
  4607. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4608. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4609. el.firstElementChild.id = rid;
  4610. cnt.$[rid] = el.firstElementChild;
  4611. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4612.  
  4613. xdeadc = cnt.getStampContainer_(rid);
  4614. el.remove();
  4615. xdeadc00 = xdeadc;
  4616. // console.log(xdeadc.__domApi)
  4617. // debugger;
  4618. // const xdeadv = xdeadc.__domApi;
  4619. }
  4620.  
  4621. let xlivec = xlivec00;
  4622. if(!xlivec){
  4623. setupSDomWrapper(); // just in case
  4624. const hostElement = cnt.hostElement;
  4625. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4626. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4627. hostElement.lastChild.replaceWith(el);
  4628. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4629. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4630. el.firstElementChild.id = rid;
  4631. cnt.$[rid] = el.firstElementChild;
  4632. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4633.  
  4634. xlivec = cnt.getStampContainer_(rid);
  4635. xlivec00 = xlivec;
  4636. // console.log(xdeadc.__domApi)
  4637. // debugger;
  4638. // const xdeadv = xdeadc.__domApi;
  4639. }
  4640.  
  4641. return xdeadc00;
  4642. }
  4643.  
  4644. let standardWrap_ = null;
  4645.  
  4646. const setupSDomWrapper = () => {
  4647.  
  4648. const sdwProto = ShadyDOM.Wrapper.prototype;
  4649.  
  4650. if (sdwProto.__pseudo__isConnected__ !== null) {
  4651. sdwProto.__pseudo__isConnected__ = null;
  4652. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  4653. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  4654. const get = isConnectedPd.get;
  4655. isConnectedPd.get = function () {
  4656. const pseudoVal = this.__pseudo__isConnected__;
  4657. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  4658. }
  4659. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  4660. }
  4661.  
  4662. // debugger;
  4663. // new xdeadc.__domApi.constructor(document.createElement('div'));
  4664. }
  4665.  
  4666. }
  4667.  
  4668. let domApiConstructor = null;
  4669. const setupDomApi = (daProto) => {
  4670.  
  4671. daProto.__daHook377__ = true;
  4672.  
  4673. domApiConstructor = daProto.constructor; // TBC
  4674.  
  4675. // TBC
  4676.  
  4677. }
  4678.  
  4679.  
  4680. // WEAKREF_ShadyDOM
  4681.  
  4682. let mightTeardownShadyDomWrap = () => { };
  4683.  
  4684. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  4685.  
  4686. const setupPlainShadyDOM = (b) => {
  4687. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  4688. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  4689. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  4690. b.patchOnDemand = true;
  4691. b.preferPerformance = true;
  4692. b.noPatch = true;
  4693. }
  4694.  
  4695. const isPlainObject = (b, m) => {
  4696. if (!b || typeof b !== 'object') return false;
  4697. const e = Object.getOwnPropertyDescriptors(b);
  4698. if (e.length <= m) return false;
  4699. let pr = 0;
  4700. for (const k in e) {
  4701. const d = e[k];
  4702. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  4703. if (!('value' in d) || typeof d.value === 'function') return false;
  4704. pr++;
  4705. }
  4706. return pr > m;
  4707. }
  4708.  
  4709. let b;
  4710.  
  4711. let lz = 0;
  4712.  
  4713. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  4714. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  4715.  
  4716. // Brave - ShadyDOM exists before userscripting
  4717. b = sdp.value;
  4718.  
  4719. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  4720. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  4721. lz = 1;
  4722. }
  4723.  
  4724. }
  4725.  
  4726.  
  4727. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  4728. } else if (!sdp) {
  4729. } else {
  4730. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  4731. return;
  4732. }
  4733.  
  4734. const shadyDOMNodeWRM = new WeakMap();
  4735.  
  4736. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  4737.  
  4738. const weakWrapperNodeHandlerFn = () => ({
  4739. get() {
  4740. const wv = this[wk];
  4741. if (typeof wv === 'undefined') return undefined;
  4742. let node = kRef(wv);
  4743. if (!node) this[wk] = undefined;
  4744. return node || undefined;
  4745. },
  4746. set(nv) {
  4747. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  4748. this[wk] = wv;
  4749. return true;
  4750. },
  4751. enumerable: true,
  4752. configurable: true
  4753. });
  4754.  
  4755.  
  4756. function weakWrapper(_ShadyDOM) {
  4757. const ShadyDOM = _ShadyDOM;
  4758. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  4759. let nullElement = { node: null };
  4760. Object.setPrototypeOf(nullElement, Element.prototype);
  4761. let p = new ShadyDOM.Wrapper(nullElement);
  4762. let d = Object.getOwnPropertyDescriptor(p, 'node');
  4763. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  4764. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  4765. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  4766. }
  4767.  
  4768. }
  4769. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  4770. try {
  4771. setupSDomWrapper();
  4772. } catch (e) { }
  4773. }
  4774.  
  4775. }
  4776.  
  4777. let previousWrapStore = null;
  4778.  
  4779. mightTeardownShadyDomWrap = (node) => {
  4780. if (previousWrapStore) previousWrapStore.delete(node);
  4781. if (shadyDOMNodeWRM) shadyDOMNodeWRM.delete(node);
  4782. };
  4783.  
  4784. const standardWrap = function (a) {
  4785. if (a instanceof WeakNodeC) a = a.getNode592177();
  4786. // if(a && a.deref) a= a.deref();
  4787. if(!a) return a;
  4788. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  4789. if (previousWrapStore) {
  4790. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  4791. if (s) {
  4792. previousWrapStore.delete(a);
  4793. shadyDOMNodeWRM.set(a, mWeakRef(s));
  4794. }
  4795. }
  4796. let u = kRef(shadyDOMNodeWRM.get(a));
  4797. if (!u) {
  4798. u = new ShadyDOM.Wrapper(a);
  4799. shadyDOMNodeWRM.set(a, mWeakRef(u));
  4800. }
  4801. return u;
  4802. }
  4803.  
  4804. standardWrap_ = standardWrap;
  4805.  
  4806.  
  4807. function setupWrapFunc(_ShadyDOM) {
  4808. const ShadyDOM = _ShadyDOM;
  4809.  
  4810.  
  4811. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  4812. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  4813. return;
  4814. }
  4815. let mm = new Set();
  4816. const pget = wmPD.value;
  4817. WeakMap.prototype.get = function (a) {
  4818. mm.add(this);
  4819. return a;
  4820. }
  4821. try {
  4822. let nullElement = { node: null };
  4823. Object.setPrototypeOf(nullElement, Element.prototype);
  4824. ShadyDOM.wrapIfNeeded(nullElement)
  4825. ShadyDOM.wrap(nullElement)
  4826. } catch (e) { }
  4827. WeakMap.prototype.get = pget;
  4828. if (mm.size !== 1) {
  4829. mm.clear();
  4830. return;
  4831. }
  4832. const p = mm.values().next().value;
  4833. if (!(p instanceof WeakMap)) return;
  4834. // p.clear();
  4835. // p.get = function (a) { return a }
  4836. // p.set = function (a, b) { return this }
  4837. // console.log(188, window.n2n = mm, window.n2p = p)
  4838.  
  4839. // console.log(34929,p.size)
  4840. previousWrapStore = p;
  4841.  
  4842. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  4843. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  4844. }
  4845. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  4846. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  4847. }
  4848.  
  4849. }
  4850.  
  4851. function setupLZ3(nv) {
  4852.  
  4853. const ShadyDOM = nv;
  4854.  
  4855. const ShadyDOMSettings = ShadyDOM.settings;
  4856. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4857. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4858. return false;
  4859. }
  4860.  
  4861. weakWrapper(ShadyDOM);
  4862.  
  4863. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4864.  
  4865. setupPlainShadyDOM(ShadyDOMSettings);
  4866. setupPlainShadyDOM(ShadyDOM);
  4867.  
  4868. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  4869.  
  4870. setupWrapFunc(ShadyDOM);
  4871. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  4872. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  4873.  
  4874. // To be confirmed
  4875. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  4876. ShadyDOM.composedPath = function (e) {
  4877. const t = (e || 0).target || null;
  4878. if (!(t instanceof HTMLElement_)) {
  4879. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  4880. }
  4881. return t instanceof HTMLElement_ ? [t] : [];
  4882. };
  4883. }
  4884.  
  4885. }
  4886.  
  4887. }
  4888.  
  4889.  
  4890. function setupLZ6(nv) {
  4891.  
  4892. const ShadyDOM = nv;
  4893.  
  4894. const ShadyDOMSettings = ShadyDOM.settings;
  4895.  
  4896. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4897. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4898. return false;
  4899. }
  4900.  
  4901. weakWrapper(ShadyDOM);
  4902.  
  4903. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4904.  
  4905. setupPlainShadyDOM(ShadyDOMSettings);
  4906. setupPlainShadyDOM(ShadyDOM);
  4907.  
  4908. setupWrapFunc(ShadyDOM);
  4909.  
  4910. }
  4911.  
  4912. }
  4913.  
  4914. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  4915.  
  4916. const nv = b;
  4917.  
  4918. if (setupLZ6(nv) === false) return;
  4919.  
  4920. lz = 6;
  4921.  
  4922. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  4923.  
  4924. return;
  4925. }
  4926.  
  4927. delete window.ShadyDOM;
  4928.  
  4929. Object.defineProperty(window, 'ShadyDOM', {
  4930. get() {
  4931. return b;
  4932. },
  4933. set(nv) {
  4934. let ret = 0;
  4935. try {
  4936. do {
  4937. if (!nv || !nv.settings) {
  4938. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  4939. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  4940. lz = 1;
  4941. break;
  4942. } else {
  4943. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  4944. break;
  4945. }
  4946. }
  4947.  
  4948. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  4949. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  4950. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  4951. break;
  4952. }
  4953.  
  4954. if (setupLZ3(nv) === false) break;
  4955.  
  4956. lz = 3;
  4957.  
  4958. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  4959.  
  4960. ret = 1;
  4961.  
  4962. } while (0);
  4963. } catch (e) {
  4964. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  4965. }
  4966.  
  4967. if (!ret) b = nv;
  4968. else {
  4969. delete this.ShadyDOM;
  4970. this.ShadyDOM = nv;
  4971. }
  4972. return true;
  4973. },
  4974. enumerable: false,
  4975. configurable: true
  4976. });
  4977.  
  4978. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  4979.  
  4980. if (ENABLE_ASYNC_DISPATCHEVENT) {
  4981. const filter = new Set([
  4982. 'yt-action',
  4983. // 'iframe-src-replaced',
  4984. 'shown-items-changed',
  4985. 'can-show-more-changed', 'collapsed-changed',
  4986.  
  4987. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  4988. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  4989. 'yt-navigate-finish',
  4990.  
  4991. // 'data-changed','yt-watch-comments-ready'
  4992. ])
  4993. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  4994. EventTarget.prototype.dispatchEvent = function (event) {
  4995. const type = (event || 0).type;
  4996. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  4997. if (!filter.has(type) && !type.endsWith('-changed')) {
  4998. if (this instanceof Node || this instanceof Window) {
  4999. nextBrowserTick_(() => this.dispatchEvent938(event));
  5000. return true;
  5001. }
  5002. }
  5003. }
  5004. return this.dispatchEvent938(event);
  5005. }
  5006. }
  5007.  
  5008. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  5009. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  5010. // const xhr = new XMLHttpRequest;
  5011. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  5012. if (!pdOri || pdOri.configurable !== true) return;
  5013. let propNeedles = null;
  5014. const pdNew = {
  5015. configurable: true,
  5016. enumerable: true,
  5017. get: function () {
  5018. propNeedles = this;
  5019. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  5020. throw new Error();
  5021. }
  5022. }
  5023. Object.defineProperty(Map.prototype, 'size', pdNew);
  5024. try {
  5025. XMLHttpRequest.prototype.open.call(0);
  5026. // xhr.open.call(null)
  5027. } catch (e) { }
  5028. Object.defineProperty(Map.prototype, 'size', pdOri);
  5029. if (!propNeedles) return;
  5030. const entries = [...propNeedles.entries()];
  5031. propNeedles.clear();
  5032. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  5033. })();
  5034.  
  5035. if (FIX_XHR_REQUESTING) {
  5036.  
  5037. const URL = window.URL || new Function('return URL')();
  5038. const createObjectURL = URL.createObjectURL.bind(URL);
  5039.  
  5040. XMLHttpRequest = (() => {
  5041. const XMLHttpRequest_ = XMLHttpRequest;
  5042. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  5043. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  5044. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  5045. constructor(...args) {
  5046. super(...args);
  5047. }
  5048. open(method, url, ...args) {
  5049. let skip = false;
  5050. if (!url || typeof url !== 'string') skip = true;
  5051. else if (typeof url === 'string') {
  5052. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  5053. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  5054. skip = true;
  5055. } else if (turl.includes('.youtube.com/pagead/')) {
  5056. skip = true;
  5057. } else if (turl.includes('.youtube.com/ptracking')) {
  5058. skip = true;
  5059. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  5060. skip = true;
  5061. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  5062. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  5063. skip = true;
  5064. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  5065. skip = true;
  5066. } else {
  5067. // skip = true; // for user activity logging e.g. watched videos
  5068. }
  5069. } else if (turl.includes('play.google.com/log')) {
  5070. skip = true;
  5071. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  5072. skip = true;
  5073. }
  5074. }
  5075. if (!skip) {
  5076. this.__xmMc8__ = 1;
  5077. return super.open(method, url, ...args);
  5078. } else {
  5079. this.__xmMc8__ = 2;
  5080. return super.open('GET', url0);
  5081. }
  5082. }
  5083. send(...args) {
  5084. if (this.__xmMc8__ === 1) {
  5085. return super.send(...args);
  5086. } else if (this.__xmMc8__ === 2) {
  5087. return super.send();
  5088. } else {
  5089. console.log('[yt-js-engine-tamer]', 'xhr warning');
  5090. return super.send(...args);
  5091. }
  5092. }
  5093. }
  5094. c.prototype.__xmMc8__ = 0;
  5095. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  5096. return c;
  5097. })();
  5098. }
  5099.  
  5100. // Alternative HACK -> Tabview Youtube
  5101. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  5102.  
  5103. // ---- << this.overscrollConfig HACK >> -----
  5104.  
  5105. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  5106.  
  5107. /*
  5108.  
  5109. ;function gZb(a, b) {
  5110. b = void 0 === b ? !0 : b;
  5111. a.addEventListener("wheel", hZb);
  5112. a.overscrollConfig = {
  5113. cooldown: b
  5114. }
  5115. }
  5116. function iZb(a) {
  5117. a.overscrollConfig = void 0;
  5118. a.removeEventListener("wheel", hZb)
  5119. }
  5120. function hZb(a) {
  5121. var b = a.deltaY
  5122. , c = a.target
  5123. , d = null;
  5124. if (window.Polymer && window.Polymer.Element) {
  5125. if (c = a.path || a.composedPath && a.composedPath()) {
  5126. c = g(c);
  5127. for (var e = c.next(); !e.done && (e = e.value,
  5128. !jZb(e, b)); e = c.next())
  5129. if (e.overscrollConfig) {
  5130. d = e;
  5131. break
  5132. }
  5133. }
  5134. } else
  5135. for (; c && !jZb(c, b); ) {
  5136. if (c.overscrollConfig) {
  5137. d = c;
  5138. break
  5139. }
  5140. c = c.parentElement
  5141. }
  5142. d && (b = d.overscrollConfig,
  5143. b.cooldown ? (d = a.deltaY,
  5144. c = b.lastDeltaY || 0,
  5145. b.lastDeltaY = d,
  5146. e = b.lastStopped || 0,
  5147. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  5148. c = !1) : (d = e + 600,
  5149. c = !0) : (d = Date.now() + 600,
  5150. c = !0),
  5151. d > Date.now() && (a.preventDefault(),
  5152. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  5153. }
  5154. */
  5155.  
  5156. let wheelHandler = function (a) {
  5157. if (window.Polymer && window.Polymer.Element) {
  5158. let c;
  5159. if (c = a.path || a.composedPath && a.composedPath()) {
  5160. for (const e of c) {
  5161. const cnt = insp(e);
  5162. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5163. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5164. }
  5165. }
  5166. } else {
  5167. let e = a.target;
  5168. for (; e instanceof Element; e = e.parentElement) {
  5169. const cnt = insp(e);
  5170. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5171. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5172. }
  5173. }
  5174. };
  5175.  
  5176. let checkWheelListenerObjs = null;
  5177.  
  5178. let getObjsFn = () => {
  5179. let euyVal = 0;
  5180. const eukElm = {};
  5181. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  5182. const euzObj = new Proxy(eukElm, {
  5183. get(target, prop) {
  5184. throw `ErrorF31.get(${prop})`
  5185. },
  5186. set(target, prop, value) {
  5187. throw `ErrorF33.set(${prop}, ${value})`
  5188. }
  5189. });
  5190. const euxElm = new Proxy(eukElm, {
  5191. get(target, prop) {
  5192. if (prop === 'scrollTop') {
  5193. euyVal = euyVal | 8;
  5194. return 0;
  5195. }
  5196. if (prop === 'overscrollConfig') {
  5197. euyVal = euyVal | 16;
  5198. return void 0;
  5199. }
  5200. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  5201. return 640;
  5202. }
  5203. if (prop === 'scrollLeft') {
  5204. euyVal = euyVal | 8;
  5205. return 0;
  5206. }
  5207. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  5208. return 800;
  5209. }
  5210. throw `ErrorF45.get(${prop})`
  5211. },
  5212. set(target, prop, value) {
  5213. throw `ErrorF47.set(${prop}, ${value})`
  5214. }
  5215. });
  5216. const eukEvt = {};
  5217. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  5218. const euyEvt = new Proxy(eukEvt, {
  5219. get(target, prop) {
  5220. if (prop === 'deltaY' || prop === 'deltaX') {
  5221. euyVal = euyVal | 1;
  5222. return -999;
  5223. }
  5224. if (prop === 'target') {
  5225. euyVal = euyVal | 2;
  5226. return euxElm
  5227. }
  5228. if (prop === 'path' || prop === 'composedPath') {
  5229. euyVal = euyVal | 2;
  5230. return [euxElm]
  5231. }
  5232. throw `ErrorF51.get(${prop})`
  5233. },
  5234. set(target, prop, value) {
  5235. throw `ErrorF53.set(${prop}, ${value})`
  5236. }
  5237. });
  5238. const setVal = (v) => {
  5239. euyVal = v;
  5240. }
  5241. const getVal = () => {
  5242. return euyVal;
  5243. }
  5244. return { euzObj, euyEvt, setVal, getVal };
  5245. }
  5246.  
  5247. let checkWheelListener = (callback) => {
  5248.  
  5249. let callbackIdentifier = '';
  5250.  
  5251. let res = null;
  5252. try {
  5253. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  5254. setVal(0);
  5255. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  5256. throw `RESULT${getVal()}`;
  5257. } catch (e) {
  5258. res = e;
  5259. }
  5260.  
  5261. res = `${res}` || `${null}`;
  5262. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  5263.  
  5264. callbackIdentifier = res;
  5265. if (callbackIdentifier === 'RESULT27') 0;
  5266. else if (callbackIdentifier === 'RESULT0') {
  5267. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  5268. } else if (callbackIdentifier.startsWith('RESULT')) {
  5269. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  5270. }
  5271. return callbackIdentifier;
  5272.  
  5273. };
  5274.  
  5275. let callbackFound = false;
  5276. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  5277. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  5278. // M-youtube-js-engine-tamer.52178
  5279. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  5280. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  5281. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  5282. // RESULTXX / ErrorFXX / Other...
  5283. if (callbackIdentifier === 'RESULT27') {
  5284. this.overscrollConfigDisable = true;
  5285. if (!callbackFound) {
  5286. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  5287. getObjsFn = checkWheelListener = null;
  5288. checkWheelListenerObjs = null;
  5289. wheelHandler = null;
  5290. }
  5291. return void 0;
  5292. } else if (!callbackFound && !this.overscrollConfigDisable) {
  5293. this.overscrollConfigDisable = true;
  5294. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  5295. }
  5296. }
  5297. return this.addEventListener52178(type, callback, option);
  5298. };
  5299.  
  5300. // ---- << this.overscrollConfig HACK >> -----
  5301.  
  5302. }
  5303.  
  5304. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  5305.  
  5306. let p_a_objWR = null;
  5307. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  5308. let ytPageReady = 0;
  5309.  
  5310. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5311. let isGlobalSpaceControl = true;
  5312. let mediaPlayerElementWR = null;
  5313. let focusedElementAtSelection = null;
  5314.  
  5315. // let want_control_video = false;
  5316.  
  5317. let spaceBarControl_keyG = '';
  5318.  
  5319. let lastUserAction = 0;
  5320.  
  5321. const wmKeyControlPhase = new WeakMap();
  5322.  
  5323. let currentSelectionText = null;
  5324.  
  5325. const getCurrentSelectionText = () => {
  5326. if (currentSelectionText !== null) return currentSelectionText
  5327. return (currentSelectionText = `${getSelection()}`)
  5328. }
  5329.  
  5330. const pageMediaWatcher = () => {
  5331.  
  5332. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  5333. // want_control_video = false;
  5334. // }, { capture: true, passive: true });
  5335.  
  5336. document.addEventListener('yt-navigate', () => {
  5337. ytPageReady = 0;
  5338. });
  5339. document.addEventListener('yt-navigate-start', () => {
  5340. ytPageReady = 0;
  5341. });
  5342. document.addEventListener('yt-navigate-cache', () => {
  5343. ytPageReady = 0;
  5344. });
  5345.  
  5346. document.addEventListener('yt-navigate-finish', () => {
  5347. ytPageReady = 1;
  5348. });
  5349.  
  5350. document.addEventListener('durationchange', () => {
  5351. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  5352. if (elm.duration > 0.01) {
  5353. if (elm.closest('[hidden]')) continue;
  5354. mediaPlayerElementWR = mWeakRef(elm);
  5355. return;
  5356. }
  5357. }
  5358. }, { capture: true, passive: true });
  5359.  
  5360. document.addEventListener('selectionchange', (evt) => {
  5361. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  5362. currentSelectionText = null;
  5363. if (!(evt.target instanceof Node)) return;
  5364. focusedElementAtSelection = evt.target;
  5365. }, { capture: true, passive: true })
  5366.  
  5367. document.addEventListener('pointerdown', (evt) => {
  5368. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5369. }, { capture: true, passive: true });
  5370.  
  5371.  
  5372. document.addEventListener('pointerup', (evt) => {
  5373. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5374. }, { capture: true, passive: true });
  5375.  
  5376.  
  5377. document.addEventListener('keydown', (evt) => {
  5378. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5379. }, { capture: true, passive: true });
  5380.  
  5381. document.addEventListener('keyup', (evt) => {
  5382. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5383. }, { capture: true, passive: true });
  5384.  
  5385. };
  5386.  
  5387.  
  5388. const checkKeyB = (p_a_obj) => {
  5389.  
  5390. const boolList = new Set();
  5391. const p_a_obj_api = p_a_obj.api;
  5392.  
  5393. const nilFunc0 = function () {
  5394. return void 0
  5395. };
  5396. const mt = new Proxy({}, {
  5397. get(target, prop) {
  5398. if (prop === 'get') return nilFunc0;
  5399. return mt;
  5400. }
  5401. });
  5402. const nilFunc = function () {
  5403. return mt
  5404. };
  5405. const mw = new Proxy({}, {
  5406. get(target, prop) {
  5407. if (prop in p_a_obj_api) {
  5408. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  5409. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  5410. if (q && q.value) {
  5411. if (!q.writable) return q.value;
  5412. if (typeof q.value === 'string') return '';
  5413. if (typeof q.value === 'number') return 0;
  5414. if (typeof q.value === 'boolean') return false;
  5415. if (q.value && typeof q.value === 'object') return {};
  5416. }
  5417. }
  5418. return undefined;
  5419. },
  5420. set(target, prop) {
  5421. throw 'mwSet';
  5422. }
  5423. });
  5424.  
  5425. const mq = new Proxy({}, {
  5426. get(target, prop) {
  5427. if (prop === 'api') return mw;
  5428. if (prop in p_a_obj) {
  5429. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  5430. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  5431. if (q && q.value) {
  5432. if (!q.writable) return q.value;
  5433. if (typeof q.value === 'string') return '';
  5434. if (typeof q.value === 'number') return 0;
  5435. if (typeof q.value === 'boolean') return false;
  5436. if (q.value && typeof q.value === 'object') return {};
  5437. }
  5438. }
  5439. return undefined;
  5440. },
  5441. set(target, prop, val) {
  5442. if (typeof val === 'boolean') boolList.add(prop)
  5443. throw `mqSet(${prop},${val})`;
  5444. }
  5445. });
  5446.  
  5447. let res = ''
  5448. try {
  5449. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  5450. } catch (e) {
  5451. res = `ERROR::${e}`;
  5452. }
  5453.  
  5454. if (boolList.size === 1) {
  5455. const value = boolList.values().next().value;
  5456. if (res === `ERROR::mqSet(${value},${true})`) {
  5457. p_a_obj.__uZWaD__ = value;
  5458. }
  5459. }
  5460.  
  5461. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  5462.  
  5463. }
  5464.  
  5465.  
  5466. let pm_p_a = null;
  5467.  
  5468. const p_a_init = function () {
  5469. const r = this.init91();
  5470. const keyBw = this.__cPzfo__ || '__NIL__';
  5471. const p_a_obj = this[keyBw];
  5472. if (!p_a_obj) return;
  5473. try {
  5474. checkKeyB(p_a_obj);
  5475. } catch (e) { }
  5476. p_a_objWR = mWeakRef(p_a_obj);
  5477. if (FIX_SHORTCUTKEYS > 0) {
  5478. if (p_a_obj && !p_a_obj.hVhtg) {
  5479. p_a_obj.hVhtg = 1;
  5480.  
  5481. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  5482. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  5483. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  5484. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  5485. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  5486. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  5487.  
  5488. }
  5489. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  5490. // const api = p_a_obj.api
  5491. // api.hVhtg = 1;
  5492. // api.playVideo91 = api.playVideo;
  5493. // api.playVideo = p_a_jt.playVideo;
  5494. // api.pauseVideo91 = api.pauseVideo;
  5495. // api.pauseVideo = p_a_jt.pauseVideo;
  5496. // }
  5497. }
  5498. if (pm_p_a) {
  5499. pm_p_a.resolve();
  5500. pm_p_a = null;
  5501. }
  5502. return r;
  5503. };
  5504.  
  5505. const p_a_xt = {
  5506.  
  5507. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  5508.  
  5509. if (FIX_SHORTCUTKEYS === 2) {
  5510.  
  5511. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  5512.  
  5513. if (activeElement) {
  5514.  
  5515. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  5516.  
  5517. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  5518. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  5519. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  5520.  
  5521. }
  5522.  
  5523. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5524. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5525. // console.log(582, isDelayedSpaceBar)
  5526. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5527.  
  5528. if (activeElement && (h === 'Space' || h === 'Enter')) {
  5529. const controlPhase = wmKeyControlPhase.get(activeElement);
  5530. if (controlPhase === 4 || controlPhase === 5) return false;
  5531. }
  5532. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  5533. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  5534. // if (!isSpaceKeyImmediate) return false;
  5535. // }
  5536. }
  5537.  
  5538. },
  5539.  
  5540. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  5541.  
  5542. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  5543.  
  5544. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  5545. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  5546. // console.log(583, isDelayedSpaceBar)
  5547. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  5548.  
  5549. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5550.  
  5551. let mediaWorking = false;
  5552. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  5553. mediaWorking = true;
  5554. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  5555. mediaWorking = true;
  5556. }
  5557. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  5558. mediaWorking && Promise.resolve().then(() => {
  5559. if (activeElement === document.activeElement) {
  5560. return activeElement.blur()
  5561. } else {
  5562. return false
  5563. }
  5564. }).then((r) => {
  5565. r !== false && mediaPlayerElement.focus();
  5566. });
  5567. }
  5568. },
  5569.  
  5570.  
  5571. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  5572.  
  5573. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5574.  
  5575. const activeElement = document.activeElement;
  5576.  
  5577. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5578. if (allow === false) return false;
  5579.  
  5580. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  5581. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  5582.  
  5583. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5584.  
  5585. return ret;
  5586. },
  5587. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  5588.  
  5589.  
  5590. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5591.  
  5592. const activeElement = document.activeElement;
  5593. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5594. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5595. // }
  5596. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  5597. if (allow === false) return false;
  5598.  
  5599. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  5600. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  5601.  
  5602. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  5603.  
  5604. return ret;
  5605. }
  5606.  
  5607. };
  5608.  
  5609. let flagSpeedMaster = null;
  5610. const getSpeedMasterControlFlag = () => {
  5611.  
  5612. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5613. isSpeedMastSpacebarControlEnabled = false;
  5614. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  5615. isSpeedMastSpacebarControlEnabled = true;
  5616. }
  5617. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  5618. isSpeedMastSpacebarControlEnabled = true;
  5619. }
  5620.  
  5621. if (flagSpeedMaster === null) {
  5622. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  5623. if (!p) {
  5624. flagSpeedMaster = false;
  5625. } else {
  5626.  
  5627. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  5628.  
  5629. }
  5630.  
  5631. }
  5632. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  5633.  
  5634. return isSpeedMastSpacebarControlEnabled;
  5635. }
  5636.  
  5637.  
  5638. const getGlobalSpacebarControlFlag = () => {
  5639.  
  5640. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5641. isGlobalSpaceControl = false;
  5642. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  5643. isGlobalSpaceControl = true;
  5644. }
  5645. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  5646. isGlobalSpaceControl = true;
  5647. }
  5648.  
  5649. return isGlobalSpaceControl;
  5650. }
  5651.  
  5652. const keyboardController = async (_yt_player) => {
  5653.  
  5654. const keyQT = getQT(_yt_player);
  5655. const keySV = getSV(_yt_player);
  5656. const keyDX = getDX(_yt_player);
  5657. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  5658.  
  5659. if (!keyDX) return;
  5660. if (keyDX === keyQT || keyDX === keySV) return;
  5661.  
  5662. if (typeof keyDX !== 'string') return;
  5663.  
  5664. let lastAccessKey = '';
  5665. let lastAccessKeyConfirmed = '';
  5666. const mb = new Proxy({}, {
  5667. get(target, prop) {
  5668. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  5669. throw 'mbGet'
  5670. },
  5671. set(target, prop, val) {
  5672. throw 'mbSet'
  5673. }
  5674. });
  5675. const ma = new Proxy({}, {
  5676. get(target, prop) {
  5677. lastAccessKey = prop;
  5678. return mb
  5679. },
  5680. set(target, prop, val) {
  5681. throw 'maSet'
  5682. }
  5683. });
  5684.  
  5685. let keyBw = '';
  5686. try {
  5687. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  5688. } catch (e) {
  5689. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  5690. keyBw = lastAccessKeyConfirmed;
  5691. }
  5692. }
  5693.  
  5694. if (!keyBw) return;
  5695.  
  5696. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  5697.  
  5698. pm_p_a = new PromiseExternal();
  5699.  
  5700. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  5701.  
  5702. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  5703.  
  5704. _yt_player[keyDX].prototype.init = p_a_init;
  5705.  
  5706. await pm_p_a.then();
  5707. const p_a_obj = kRef(p_a_objWR);
  5708.  
  5709. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  5710.  
  5711.  
  5712. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  5713.  
  5714. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  5715.  
  5716. if (!isSpeedMastSpacebarControlEnabled) {
  5717.  
  5718. if (config && config.EXPERIMENT_FLAGS) {
  5719. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  5720. }
  5721. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5722. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  5723. }
  5724.  
  5725. } else {
  5726.  
  5727. if (config && config.EXPERIMENT_FLAGS) {
  5728. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  5729. }
  5730. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  5731. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  5732. }
  5733.  
  5734. }
  5735.  
  5736. }
  5737.  
  5738. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  5739.  
  5740.  
  5741.  
  5742.  
  5743. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  5744.  
  5745. // console.log(p_a_obj.handleGlobalKeyUp)
  5746. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  5747.  
  5748. // console.log(p_a_obj.api)
  5749.  
  5750.  
  5751. // QT -> DX(SV) -> p_a
  5752.  
  5753.  
  5754. /*
  5755. *
  5756. *
  5757. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5758. b = void 0 === b ? !1 : b;
  5759. c = void 0 === c ? !1 : c;
  5760. d = void 0 === d ? !1 : d;
  5761. e = void 0 === e ? !1 : e;
  5762. var l = g.PT(this);
  5763. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  5764. }
  5765.  
  5766. */
  5767.  
  5768. /*
  5769. *
  5770. *
  5771. *
  5772. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  5773. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  5774. }
  5775.  
  5776. */
  5777.  
  5778.  
  5779. // if(!keyDX) return;
  5780.  
  5781. // console.log(4999, keyDX)
  5782.  
  5783. };
  5784.  
  5785.  
  5786. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  5787.  
  5788. const p_a_obj = kRef(p_a_objWR);
  5789. // const api = p_a_obj.api;
  5790.  
  5791.  
  5792. // console.log(540);
  5793.  
  5794. let boolList = null;
  5795. let ret;
  5796. isSpaceKeyImmediate = true;
  5797. try {
  5798.  
  5799. ret = 0;
  5800. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  5801. let p_a_objT;
  5802. if (!spaceBarControl_keyG) { // just in case
  5803. boolList = new Set();
  5804. p_a_objT = new Proxy(p_a_obj, {
  5805. get(target, prop, handler) {
  5806. const val = target[prop];
  5807. if (typeof val !== 'boolean') return val;
  5808. boolList.add(prop);
  5809. // console.log(555, prop, val);
  5810. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  5811. spaceBarControl_keyG = prop;
  5812. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5813. val = false;
  5814. }
  5815. return val;
  5816. }
  5817. });
  5818.  
  5819.  
  5820. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  5821. p_a_obj[spaceBarControl_keyG] = false;
  5822. p_a_objT = p_a_obj;
  5823. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  5824. } else {
  5825.  
  5826. p_a_objT = p_a_obj;
  5827. }
  5828.  
  5829. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  5830.  
  5831.  
  5832. } catch (e) {
  5833. console.log(e)
  5834. }
  5835. isSpaceKeyImmediate = false;
  5836.  
  5837. if (boolList && boolList.size === 1) {
  5838. const value = boolList.values().next().value;
  5839. spaceBarControl_keyG = value;
  5840. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  5841.  
  5842. }
  5843.  
  5844. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5845.  
  5846. return ret;
  5847. }
  5848.  
  5849. const shortcutKeysFixer = () => {
  5850.  
  5851. let pausePromiseControlJ = 0;
  5852.  
  5853.  
  5854. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  5855.  
  5856. let controlPhase = 0;
  5857. const aElm = document.activeElement;
  5858.  
  5859. if (aElm) {
  5860.  
  5861. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  5862.  
  5863. if (typeof controlPhaseCache === 'number') {
  5864.  
  5865. controlPhase = controlPhaseCache;
  5866. } else {
  5867.  
  5868. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  5869. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  5870. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  5871. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  5872. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  5873. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  5874. else {
  5875. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  5876. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  5877. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  5878. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  5879. }
  5880.  
  5881. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  5882. controlPhase = 0;
  5883. }
  5884.  
  5885. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  5886. if (aElm.closest('[contenteditable], input, textarea')) {
  5887. controlPhase = 5;
  5888. } else if (aElm.closest('button')) {
  5889. controlPhase = 4;
  5890. }
  5891. }
  5892.  
  5893. if (aElm.closest('#movie_player')) controlPhase = 6;
  5894.  
  5895. wmKeyControlPhase.set(aElm, controlPhase);
  5896.  
  5897. }
  5898. }
  5899.  
  5900. return controlPhase;
  5901.  
  5902. }
  5903.  
  5904. const isStateControllable = (api) => {
  5905. let appState = null;
  5906. let playerState = null;
  5907. let adState = null;
  5908. try {
  5909. appState = api.getAppState();
  5910. playerState = api.getPlayerState();
  5911. adState = api.getAdState();
  5912. } catch (e) { }
  5913. // ignore playerState -1
  5914. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  5915. };
  5916.  
  5917.  
  5918. const keyEventListener = (evt) => {
  5919. if (BY_PASS_KEYBOARD_CONTROL) return;
  5920.  
  5921. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  5922. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  5923. if (!ytPageReady) return;
  5924.  
  5925. if (evt.defaultPrevented === true) return;
  5926.  
  5927. const p_a_obj = kRef(p_a_objWR);
  5928.  
  5929. if (!p_a_obj) return;
  5930.  
  5931.  
  5932. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  5933. if (!mediaPlayerElement) return;
  5934.  
  5935. // let focusBodyIfSuccess = false;
  5936.  
  5937. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  5938.  
  5939. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  5940. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  5941. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  5942.  
  5943.  
  5944. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  5945.  
  5946. // console.log(`${evt.type}::controlPhase`,controlPhase)
  5947.  
  5948. // if (controlPhase == 4) {
  5949. // focusBodyIfSuccess = true;
  5950. // }
  5951.  
  5952. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  5953. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  5954.  
  5955. if (FIX_SHORTCUTKEYS < 2) return;
  5956. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  5957.  
  5958. let rr;
  5959. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  5960.  
  5961.  
  5962.  
  5963. let useImprovedPauseResume = false;
  5964.  
  5965. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  5966.  
  5967. const api = p_a_obj.api;
  5968. const stateControllable = isStateControllable(api);
  5969. // console.log(2122, appState, playerState, adState)
  5970.  
  5971. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  5972.  
  5973. useImprovedPauseResume = true;
  5974.  
  5975. }
  5976.  
  5977.  
  5978. }
  5979.  
  5980.  
  5981. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  5982. if (evt.type === 'keydown') {
  5983.  
  5984. if (useImprovedPauseResume) {
  5985.  
  5986. const isPaused = mediaPlayerElement.paused;
  5987.  
  5988. const cj = ++pausePromiseControlJ;
  5989. Promise.resolve().then(() => {
  5990.  
  5991. if (cj !== pausePromiseControlJ) return;
  5992.  
  5993. if (mediaPlayerElement.paused !== isPaused) return;
  5994.  
  5995. const ret = ytResumeFn();
  5996. if (!ret) { // fallback
  5997. isPaused ? api.playVideo() : api.pauseVideo();
  5998. }
  5999.  
  6000. /*
  6001. let a = void 0;
  6002. console.log('Rb', api.Rb())
  6003. a = !window._yt_player.nL(api.Rb());
  6004. p_a_obj.Wd.kG(a)
  6005. a ? api.playVideo() : api.pauseVideo();
  6006.  
  6007. */
  6008.  
  6009.  
  6010. });
  6011. rr = true;
  6012. } else {
  6013.  
  6014. isSpaceKeyImmediate = true;
  6015. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  6016. isSpaceKeyImmediate = false;
  6017. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6018.  
  6019. }
  6020.  
  6021.  
  6022. } else if (evt.type === 'keyup') {
  6023.  
  6024. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  6025.  
  6026. rr = true;
  6027. } else {
  6028.  
  6029. isSpaceKeyImmediate = true;
  6030. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  6031. isSpaceKeyImmediate = false;
  6032. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  6033.  
  6034. }
  6035.  
  6036.  
  6037. /*
  6038.  
  6039. if (d)
  6040. switch (c) {
  6041. case 32:
  6042. case 13:
  6043. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  6044. b = !0,
  6045. e = !1;
  6046. else if (e) {
  6047. var m = d.getAttribute("role");
  6048. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  6049. d.click(),
  6050. f = !0)
  6051. }
  6052. break;
  6053. case 37:
  6054. case 39:
  6055. case 36:
  6056. case 35:
  6057. b = "slider" === d.getAttribute("role");
  6058. break;
  6059. case 38:
  6060. case 40:
  6061. m = d.getAttribute("role"),
  6062. d = 38 === c ? d.previousSibling : d.nextSibling,
  6063. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  6064. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  6065. f = b = !0))
  6066. }
  6067. if (e && !f)
  6068. switch (c) {
  6069. case 38:
  6070. f = Math.min(this.api.getVolume() + 5, 100);
  6071. XV(this.Wd, f, !1);
  6072. this.api.setVolume(f);
  6073. h = f = !0;
  6074. break;
  6075. case 40:
  6076. f = Math.max(this.api.getVolume() - 5, 0);
  6077. XV(this.Wd, f, !0);
  6078. this.api.setVolume(f);
  6079. h = f = !0;
  6080. break;
  6081. case 36:
  6082. this.api.Yh() && (this.api.startSeekCsiAction(),
  6083. this.api.seekTo(0, void 0, void 0, void 0, 79),
  6084. h = f = !0);
  6085. break;
  6086. case 35:
  6087. this.api.Yh() && (this.api.startSeekCsiAction(),
  6088. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  6089. h = f = !0)
  6090. }
  6091. */
  6092.  
  6093. }
  6094.  
  6095.  
  6096. if (rr) {
  6097.  
  6098. // focusBodyIfSuccess && Promise.resolve().then(() => {
  6099. // activeElement === document.activeElement && activeElement.blur();
  6100. // });
  6101.  
  6102. evt.preventDefault();
  6103. evt.stopImmediatePropagation();
  6104. evt.stopPropagation();
  6105.  
  6106. }
  6107.  
  6108. };
  6109.  
  6110. document.addEventListener('keydown', keyEventListener, { capture: true });
  6111.  
  6112.  
  6113. document.addEventListener('keyup', keyEventListener, { capture: true });
  6114.  
  6115. }
  6116.  
  6117. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  6118.  
  6119. })();
  6120.  
  6121.  
  6122. pageMediaWatcher();
  6123. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  6124.  
  6125.  
  6126. const check_for_set_key_order = (() => {
  6127.  
  6128. let mySet = new Set();
  6129.  
  6130. mySet.add("value1");
  6131. mySet.add("value2");
  6132. mySet.add("value3");
  6133.  
  6134. // Function to convert Set values to an array
  6135. function getSetValues(set) {
  6136. return Array.from(set.values());
  6137. }
  6138.  
  6139. // Function to test if the Set maintains insertion order
  6140. function testSetOrder(set, expectedOrder) {
  6141. let values = getSetValues(set);
  6142. return expectedOrder.join(',') === values.join(',');
  6143. }
  6144.  
  6145. // Test 1: Initial order
  6146. if (mySet.values().next().value !== "value1") return false;
  6147. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  6148.  
  6149. // Test 2: After deleting an element
  6150. mySet.delete("value2");
  6151. if (mySet.values().next().value !== "value1") return false;
  6152. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  6153.  
  6154. // Test 3: After re-adding a deleted element
  6155. mySet.add("value2");
  6156. if (mySet.values().next().value !== "value1") return false;
  6157. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  6158.  
  6159. // Test 4: After adding a new element
  6160. mySet.add("value4");
  6161. if (mySet.values().next().value !== "value1") return false;
  6162. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  6163.  
  6164. // Test 5: Delete+Add
  6165. mySet.delete("value1");
  6166. mySet.delete("value3");
  6167. mySet.add("value3");
  6168. mySet.add("value1");
  6169. if (mySet.values().next().value !== "value2") return false;
  6170. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  6171.  
  6172. return true;
  6173. })();
  6174.  
  6175.  
  6176. // const qm47 = Symbol();
  6177. // const qm57 = Symbol();
  6178. const qm53 = Symbol();
  6179. const qn53 = Symbol();
  6180.  
  6181.  
  6182. const ump3 = new WeakMap();
  6183.  
  6184. const stp = document.createElement('noscript');
  6185. stp.id = 'weakref-placeholder';
  6186.  
  6187. PROP_OverReInclusion_AVOID && (() => {
  6188.  
  6189.  
  6190. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  6191. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  6192. let byPassVal = null;
  6193. let byPassCount = 0;
  6194. let mmw = new Set();
  6195. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  6196. if (arguments.length !== 1) return f.apply(this, arguments);
  6197. if (byPassVal !== null && typeof prop === 'string') {
  6198.  
  6199. if (PROP_OverReInclusion_LIST.has(prop)) {
  6200. byPassCount++;
  6201. return byPassVal;
  6202. }
  6203. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  6204.  
  6205. }
  6206. return this.hasOwnProperty72(prop);
  6207. };
  6208.  
  6209.  
  6210. /*
  6211.  
  6212.  
  6213. z.prototype.forwardDynamicProps = function() {
  6214. var B = m(this.inst);
  6215. B = h(B);
  6216. for (var F = B.next(); !F.done; F = B.next()) {
  6217. var H = h(F.value);
  6218. F = H.next().value;
  6219. H = H.next().value;
  6220. my(this, F, H);
  6221. r(b) && !ly(F) && Wua(this.inst, F)
  6222. }
  6223. }
  6224.  
  6225. */
  6226.  
  6227.  
  6228.  
  6229. let byPassZeroShowed = false;
  6230. const forwardDynamicPropsGeneral = function () {
  6231. byPassVal = true;
  6232. byPassCount = 0;
  6233. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  6234. const ret = this.forwardDynamicProps72();
  6235. byPassVal = null;
  6236. if (byPassCount === 0 && !byPassZeroShowed) {
  6237. byPassZeroShowed = true;
  6238. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  6239. }
  6240. byPassCount = 0;
  6241. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  6242. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  6243. mmw.clear();
  6244. }
  6245. return ret;
  6246. };
  6247.  
  6248. const propCheck = (proto) => {
  6249. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  6250. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  6251. if (proto.forwardDynamicProps.length === 0) {
  6252. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  6253. }
  6254. }
  6255. };
  6256.  
  6257. const valMap = new WeakMap();
  6258. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  6259. get() {
  6260. propCheck(this.constructor.prototype);
  6261. return valMap.get(this);
  6262. },
  6263. set(nv) {
  6264. propCheck(this.constructor.prototype);
  6265. valMap.set(this, nv);
  6266. return true;
  6267. },
  6268. enumerable: false,
  6269. configurable: true
  6270.  
  6271. });
  6272.  
  6273. promiseForCustomYtElementsReady.then(() => {
  6274. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  6275. if (customElements.define.length !== 2) return;
  6276. customElements.define72 = customElements.define;
  6277. customElements.define = function (b, w) {
  6278. propCheck(w.prototype);
  6279. const ret = this.define72(b, w);
  6280. return ret;
  6281. }
  6282. });
  6283.  
  6284. })();
  6285.  
  6286. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  6287.  
  6288. const flexibleItemListMo = new MutationObserver((mutations) => {
  6289. // cnt.onStamperFinished
  6290. // cnt.maybeUpdateFlexibleMenu
  6291. const set = new Set();
  6292. for (const mutation of mutations) {
  6293. if (mutation && ((mutation.addedNodes || 0).length > 0 || (mutation.removedNodes || 0).length > 0)) {
  6294. set.add(mutation.target);
  6295. }
  6296. }
  6297. for (const s of set) {
  6298. const cnt = insp(s);
  6299. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  6300. cnt.maybeUpdateFlexibleMenuImpl();
  6301. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  6302. cnt.maybeUpdateFlexibleMenu();
  6303. } else if (typeof cnt.onStamperFinished === 'function') {
  6304. cnt.onStamperFinished();
  6305. }
  6306. }
  6307. set.clear();
  6308. });
  6309.  
  6310. let checkConfig = true;
  6311. const flexibleItemDocMo = new MutationObserver(() => {
  6312. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  6313. s.setAttribute('b289ad', '');
  6314. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  6315. s.appendChild(document.createComment('.')).remove();
  6316. }
  6317. if (checkConfig) {
  6318. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6319. if (config && config.EXPERIMENT_FLAGS) {
  6320. checkConfig = false;
  6321. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  6322. }
  6323. }
  6324. });
  6325. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  6326.  
  6327. }
  6328.  
  6329.  
  6330.  
  6331.  
  6332. const observablePromise = (proc, timeoutPromise) => {
  6333. let promise = null;
  6334. return {
  6335. obtain() {
  6336. if (!promise) {
  6337. promise = new Promise(resolve => {
  6338. let mo = null;
  6339. const f = () => {
  6340. let t = proc();
  6341. if (t) {
  6342. mo.disconnect();
  6343. mo.takeRecords();
  6344. mo = null;
  6345. resolve(t);
  6346. }
  6347. }
  6348. mo = new MutationObserver(f);
  6349. mo.observe(document, { subtree: true, childList: true })
  6350. f();
  6351. timeoutPromise && timeoutPromise.then(() => {
  6352. resolve(null)
  6353. });
  6354. });
  6355. }
  6356. return promise
  6357. }
  6358. }
  6359. }
  6360.  
  6361.  
  6362. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  6363. observablePromise(() => {
  6364. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6365. if (config && config.EXPERIMENT_FLAGS) {
  6366. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  6367. return true;
  6368. }
  6369. }).obtain();
  6370. }
  6371.  
  6372. if (FIX_ROLLING_NUMBER_UPDATE) {
  6373.  
  6374.  
  6375. observablePromise(() => {
  6376. if (typeof customElements === 'undefined') return;
  6377. const ce = customElements.get('yt-animated-rolling-number');
  6378. if (!ce) return;
  6379. return ce.prototype;
  6380. }).obtain().then(async (cProto) => {
  6381.  
  6382. const p = document.createElement('yt-animated-rolling-number');
  6383.  
  6384. const frag = document.createDocumentFragment();
  6385. frag.appendChild(p);
  6386. const pDoc = document.implementation.createHTMLDocument();
  6387. pDoc.body.appendChild(frag);
  6388.  
  6389. let p88 = p;
  6390.  
  6391. const __instance = await observablePromise(() => {
  6392. const __instance = (p88 || 0).__instance;
  6393. if (__instance && __instance.render) return __instance;
  6394. }).obtain();
  6395. p88 = null;
  6396.  
  6397. const itProto = Reflect.getPrototypeOf(__instance);
  6398.  
  6399. try {
  6400. p.remove();
  6401. } catch (e) { }
  6402.  
  6403. if (itProto.render && !itProto.render37 && itProto.render.length === 1) {
  6404.  
  6405. itProto.render37 = itProto.render;
  6406. itProto.render = function (t) {
  6407. // (this.xCounter = (this.xCounter & 1073741823)+1)
  6408. let c33 = '';
  6409. let r33 = null;
  6410. let kc = 0;
  6411.  
  6412. if (this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  6413. const el = this.el;
  6414. const ct = Date.now();
  6415. const lastFireTime = (el.__lastFireTime491__ || 0);
  6416.  
  6417. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  6418.  
  6419. if (fireTimeDiff < 80 && this.__previousRender61__) {
  6420. return this.__previousRender61__;
  6421. }
  6422.  
  6423. const caseInt =
  6424. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  6425. (t && typeof t.character === 'string') ? (
  6426. (typeof t.previousCharacter === 'string') ? 6 : 2
  6427. ) : 0;
  6428.  
  6429. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender61__ && fireTimeDiff < 9400) {
  6430. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender61__) {
  6431. return this.__previousRender61__;
  6432. }
  6433. }
  6434. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender61__ && fireTimeDiff < 9400) {
  6435. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender61__) {
  6436. return this.__previousRender61__;
  6437. }
  6438. }
  6439.  
  6440. if (caseInt & 2) {
  6441.  
  6442. if (caseInt & 4) {
  6443.  
  6444. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  6445. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  6446. t.previousCharacter = t.character;
  6447. kc = 1;
  6448. }
  6449. }
  6450.  
  6451. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  6452. t.shouldAnimate = false;
  6453. }
  6454. }
  6455.  
  6456.  
  6457. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  6458.  
  6459. el.__lastCharacter353__ = t.character;
  6460.  
  6461. } else if (caseInt === 1) {
  6462.  
  6463. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  6464. t.shouldAnimate = false;
  6465. }
  6466. el.__lastNumberValue353__ = t.numberValue;
  6467.  
  6468. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  6469. t.shouldAnimate = false;
  6470. }
  6471. el.__lastNumberText353__ = t.numberText;
  6472.  
  6473. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  6474.  
  6475. }
  6476.  
  6477. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  6478.  
  6479. el.__lastFireTime491__ = ct;
  6480. }
  6481.  
  6482. // // console.log(21399, t.character, t.previousCharacter, (t.xCounter = (t.xCounter & 1073741823)+1), t, (this.xCounter = (this.xCounter & 1073741823)+1) )
  6483. // // console.log(12883, this, t);
  6484. const r = r33 || this.render37(t);
  6485. this.__previousRender61__ = r;
  6486. if (c33) this[c33] = r;
  6487. return r
  6488. }
  6489.  
  6490. }
  6491.  
  6492. });
  6493.  
  6494. }
  6495.  
  6496. if (HOOK_ACTIVE_MODULES) {
  6497.  
  6498. let watchController;
  6499. const watchControllerObservable = observablePromise(() => {
  6500. const watchFlexy = document.querySelector('ytd-watch-flexy');
  6501. if (!watchFlexy) return;
  6502. return insp(watchFlexy).watchController;
  6503. }).obtain();
  6504. (async () => {
  6505. watchController = await watchControllerObservable;
  6506.  
  6507. const activeModules = watchController.activeModules;
  6508. if (!activeModules) return;
  6509.  
  6510. const checkFn = (activeModule) => {
  6511. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  6512. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  6513. }
  6514. }
  6515. if (!activeModules.push8792 && activeModules.push) {
  6516. activeModules.push8792 = activeModules.push;
  6517. activeModules.push = function (a, ...args) {
  6518. checkFn(a);
  6519. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  6520. return r;
  6521. }
  6522. }
  6523. activeModules.forEach(checkFn);
  6524.  
  6525. })();
  6526.  
  6527. let yieldResultWrappingByPass = false;
  6528. let asyncProto = null;
  6529. const yieldResultWrapping = (f) => {
  6530. if (yieldResultWrappingByPass) return [f(), null];
  6531. yieldResultWrappingByPass = true;
  6532. let D = null;
  6533. let promise, e_;
  6534. if (asyncProto) {
  6535. Object.defineProperty(asyncProto, 'yieldResult', {
  6536. get() {
  6537. return undefined;
  6538. },
  6539. set(nv) {
  6540. delete asyncProto.yieldResult;
  6541. this.yieldResult = nv;
  6542. D = this;
  6543. // console.log(122, this);
  6544. return true;
  6545. },
  6546. enumerable: false,
  6547. configurable: true
  6548. });
  6549. try {
  6550. promise = f();
  6551. } catch (e) { e_ = e }
  6552. delete asyncProto.yieldResult;
  6553. yieldResultWrappingByPass = false;
  6554. } else {
  6555. Object.defineProperty(Object.prototype, 'yieldResult', {
  6556. get() {
  6557. return undefined;
  6558. },
  6559. set(nv) {
  6560. delete Object.prototype.yieldResult;
  6561. this.yieldResult = nv;
  6562. D = this;
  6563. // console.log(122, this);
  6564. return true;
  6565. },
  6566. enumerable: false,
  6567. configurable: true
  6568. });
  6569. try {
  6570. promise = f();
  6571. } catch (e) { e_ = e }
  6572. delete Object.prototype.yieldResult;
  6573. yieldResultWrappingByPass = false;
  6574. if (D) {
  6575. asyncProto = Reflect.getPrototypeOf(D);
  6576. }
  6577. }
  6578. if (e_) throw e_;
  6579. return [promise, D];
  6580. }
  6581.  
  6582. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  6583.  
  6584. const aProto = Reflect.getPrototypeOf(activeModule);
  6585.  
  6586. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  6587.  
  6588. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  6589.  
  6590. // console.log(12885)
  6591. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  6592. // let qxt=false;
  6593. aProto.fetchUpdatedMetadata = function (t, P) {
  6594.  
  6595. // if (!qxt) {
  6596. // qxt = true;
  6597. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  6598. // console.log(199001,...args)
  6599. // });
  6600. // this.addOnDisposeCallback(function (...args) {
  6601.  
  6602. // console.log(199002,...args)
  6603. // watchController.unsubscribeByKey(y)
  6604. // qxt = false;
  6605. // });
  6606. // }
  6607. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  6608. if (D) promise.then(() => {
  6609. const yieldResult = D.yieldResult;
  6610. if (yieldResult) {
  6611. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  6612.  
  6613. if (mutations && mutations.length >= 1) {
  6614. let likeCountEntity = null;
  6615. for (const mutation of mutations) {
  6616. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  6617. break;
  6618. }
  6619. }
  6620. if (likeCountEntity) {
  6621. const model = insp(document.querySelector('segmented-like-dislike-button-view-model'));
  6622. if (model && typeof model.update === 'function' && model.update.length === 0) {
  6623. const data = ((model || 0).props || 0).data;
  6624. if (data) {
  6625. if (typeof data.likeCountEntity !== 'object') data.likeCountEntity = {};
  6626. // console.log(12838, {...data.likeCountEntity}, {...likeCountEntity})
  6627. // const shouldModelUpdate = (data.likeCountEntity.key !== likeCountEntity.key); // to be reviewed
  6628. const shouldModelUpdate = true;
  6629. Object.assign(data.likeCountEntity, likeCountEntity);
  6630. // data.likeCountEntity = likeCountEntity;
  6631. // if (shouldModelupdate) model.update();
  6632. // else {
  6633. // if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  6634. // }
  6635.  
  6636. if (shouldModelUpdate) {
  6637. if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  6638. // console.log('kk1a enqueueUpdate')
  6639. model.enqueueUpdate();
  6640. // console.log('kk1b enqueueUpdate')
  6641. } else if (typeof model.update === 'function' && model.update.length === 0) {
  6642. // console.log('kk2a update')
  6643. model.update();
  6644. // console.log('kk2b update')
  6645. } else {
  6646. console.warn('[yt-js-engine-tamer] cannot do model update.')
  6647. }
  6648. }
  6649.  
  6650. }
  6651. }
  6652. }
  6653. }
  6654. }
  6655. }).catch(console.warn);
  6656. return promise;
  6657. };
  6658.  
  6659. }
  6660.  
  6661. }
  6662.  
  6663. // ----------------------------
  6664.  
  6665. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  6666.  
  6667. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  6668.  
  6669. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  6670.  
  6671.  
  6672. // const globalPromiseStack = {};
  6673.  
  6674. // let dummy;
  6675. // while(!dummy){
  6676.  
  6677. // dummy = document.querySelector('yt-icon');
  6678. // await new Promise(r=>setTimeout(r,0));
  6679. // }
  6680.  
  6681. dummy = document.createElement('yt-icon');
  6682.  
  6683. let cProto;
  6684. if (!(dummy instanceof Element)) return;
  6685. cProto = insp(dummy).constructor.prototype;
  6686.  
  6687. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  6688. cProto.determineIconSet671 = cProto.determineIconSet;
  6689. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  6690. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  6691. cProto.getIconManager671 = cProto.getIconManager;
  6692. cProto.getIconShapeData671 = cProto.getIconShapeData;
  6693. cProto.renderIcon671 = cProto.renderIcon;
  6694.  
  6695. // cProto.attached488 = cProto.attached;
  6696. // cProto.attached = function(){
  6697. // console.log('attached')
  6698. // return this.attached488(...arguments);
  6699. // }
  6700. // cProto.detached488 = cProto.detached;
  6701. // cProto.detached = function(){
  6702. // console.log('detached')
  6703. // return this.detached488(...arguments);
  6704. // }
  6705.  
  6706. if (cProto.__renderIconFix__) return;
  6707. cProto.__renderIconFix__ = true;
  6708.  
  6709. let taskStack = [];
  6710. const cmObs = new MutationObserver(() => {
  6711. const tasks = taskStack.slice();
  6712. taskStack.length = 0;
  6713. for (const task of tasks) {
  6714. task();
  6715. }
  6716. })
  6717. const cm = document.createComment('1');
  6718. const stackTask = (f) => {
  6719. taskStack.push(f);
  6720. cm.data = `${(cm.data & 7) + 1}`;
  6721. }
  6722. cmObs.observe(cm, { characterData: true });
  6723.  
  6724. // let iconManagers = {}; // assume shared
  6725.  
  6726. // window.iconManagers = () => iconManagers;
  6727.  
  6728.  
  6729. const setupYtIcon = (inst) => {
  6730.  
  6731. if (inst.__ytIconSetup588__) return;
  6732. const cProto = Reflect.getPrototypeOf(inst);
  6733. cProto.__ytIconSetup588__ = true;
  6734.  
  6735.  
  6736. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6737.  
  6738. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  6739. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  6740. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  6741. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  6742.  
  6743.  
  6744. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  6745. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  6746. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  6747. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  6748.  
  6749.  
  6750.  
  6751. }
  6752.  
  6753. cProto.handlePropertyChange = function (...a) { // 10+
  6754.  
  6755. const __data = this.__data;
  6756. if (FIX_GUIDE_ICON && this.id === 'guide-icon' && __data && !__data.icon && typeof this.set === 'function') {
  6757. this.set('icon', "yt-icons:menu")
  6758. }
  6759.  
  6760. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6761. this.__resolved__ = {
  6762.  
  6763. };
  6764. const a01 = this.isAttached;
  6765. let a02, a03;
  6766.  
  6767.  
  6768. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  6769.  
  6770. const stackFn = () => {
  6771. if (t !== this.__stackedKey3818__) {
  6772. return;
  6773. }
  6774. a03 = this.isAttached;
  6775.  
  6776. if (a01 === false && a02 === false && a03 === false) return;
  6777.  
  6778. if (a01 === true && a02 === true && a03 === true) {
  6779.  
  6780. } else {
  6781. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  6782. // unknown yt-icon#label-icon
  6783. return;
  6784. } else {
  6785. console.log('[yt-icon] debug', a01, a02, a03, this)
  6786. }
  6787. }
  6788.  
  6789. this.handlePropertyChange671(...arguments);
  6790.  
  6791. };
  6792.  
  6793.  
  6794.  
  6795. Promise.resolve().then(() => {
  6796. a02 = this.isAttached;
  6797. stackTask(stackFn);
  6798. });
  6799.  
  6800.  
  6801. }
  6802.  
  6803. cProto.determineIconSet = function (a, b, c, d) { // 10-
  6804.  
  6805. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6806. // string bool? bool=false int=24
  6807. // NOTIFICATIONS_NONE OR LIKE
  6808. // console.log('yt-icon.determineIconSet', ...arguments);
  6809.  
  6810. const r = this.determineIconSet671(...arguments);
  6811. return r;
  6812. }
  6813.  
  6814. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  6815.  
  6816. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6817. // same as determineIconSet
  6818. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  6819. return this.switchToYtSysIconset671(...arguments);
  6820. }
  6821.  
  6822. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  6823.  
  6824. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6825. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  6826. return this.useYtSysIconsetForMissingIcons671(...arguments);
  6827. }
  6828.  
  6829. cProto.getIconManager = function () { // 10+
  6830.  
  6831. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6832. if (!this.__resolved__) this.__resolved__ = {};
  6833. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  6834. const r = this.__resolved__.getIconManager;
  6835. return r;
  6836. }
  6837.  
  6838. cProto.getIconShapeData = function () { // 10+
  6839.  
  6840. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6841.  
  6842. // no argument
  6843. // console.log('yt-icon.getIconShapeData', ...arguments);
  6844. if (!this.__resolved__) this.__resolved__ = {};
  6845. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  6846. const r = this.__resolved__.getIconShapeData;
  6847. return r
  6848. }
  6849.  
  6850. cProto.renderIcon = function (a, b) { // X
  6851.  
  6852. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6853. // "" yt-icons:xxx
  6854. // console.log('yt-icon.renderIcon', ...arguments);
  6855. return this.renderIcon671(...arguments);
  6856. }
  6857.  
  6858. });
  6859.  
  6860.  
  6861. /**
  6862. * Compute the Longest Common Subsequence between two arrays.
  6863. * Returns an array of the LCS elements (in order).
  6864. */
  6865. function computeLCS(a, b) {
  6866. // Input validation
  6867. if (!Array.isArray(a) || !Array.isArray(b)) {
  6868. throw new Error('Inputs must be arrays');
  6869. }
  6870.  
  6871. const n = a.length, m = b.length;
  6872. // Early termination for trivial cases
  6873. if (n === 0 || m === 0) return [];
  6874. // Check for shallow equality
  6875. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  6876.  
  6877. // Use smaller dimension for space optimization
  6878. if (n > m) return computeLCS(b, a); // Ensure n <= m
  6879.  
  6880. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  6881. // Use Uint32Array for robustness with long sequences
  6882. const dp = [
  6883. new Uint32Array(m + 1),
  6884. new Uint32Array(m + 1),
  6885. ];
  6886. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  6887. // Optimize space by storing only necessary entries
  6888. const pred = new Uint8Array(n * m); // Single array for moves
  6889.  
  6890. for (let i = n - 1; i >= 0; i--) {
  6891. const curr = i % 2;
  6892. const next = 1 - curr;
  6893. // Clear current row for reuse
  6894. dp[curr].fill(0);
  6895.  
  6896. for (let j = m - 1; j >= 0; j--) {
  6897. const idx = i * m + j;
  6898. if (a[i] === b[j]) {
  6899. dp[curr][j] = dp[next][j + 1] + 1;
  6900. pred[idx] = 0; // Diagonal
  6901. } else if (dp[next][j] >= dp[curr][j + 1]) {
  6902. dp[curr][j] = dp[next][j];
  6903. pred[idx] = 1; // Down
  6904. } else {
  6905. dp[curr][j] = dp[curr][j + 1];
  6906. pred[idx] = 2; // Right
  6907. }
  6908. }
  6909. }
  6910.  
  6911. // Check for potential overflow
  6912. if (dp[0][0] > 0xFFFFFFFF) {
  6913. throw new Error('LCS length exceeds safe integer limit');
  6914. }
  6915.  
  6916. // Backtrack to build the actual LCS
  6917. const lcs = [];
  6918. let i = 0, j = 0;
  6919. while (i < n && j < m) {
  6920. const idx = i * m + j;
  6921. const p = pred[idx];
  6922. if (p === 0) {
  6923. lcs.push(a[i]);
  6924. i++; j++;
  6925. } else if (p === 1) {
  6926. i++;
  6927. } else {
  6928. j++;
  6929. }
  6930. }
  6931. return lcs;
  6932. }
  6933.  
  6934. /**
  6935. * Given original[] and modified[], produce an array of splice-ops:
  6936. * [ [start0, deleteCount0, addedItems0],
  6937. * [start1, deleteCount1, addedItems1],
  6938. * … ]
  6939. * When you do:
  6940. * let arr = original.slice();
  6941. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  6942. * arr will equal modified.
  6943. */
  6944. function diffSplices(original, modified) {
  6945. // Input validation
  6946. if (!Array.isArray(original) || !Array.isArray(modified)) {
  6947. throw new Error('Inputs must be arrays');
  6948. }
  6949.  
  6950. const origLen = original.length;
  6951. const modLen = modified.length;
  6952. // Early termination for trivial cases
  6953. if (origLen === 0 && modLen === 0) return [];
  6954. if (origLen === 0) return [[0, 0, modified.slice()]];
  6955. if (modLen === 0) return [[0, origLen, []]];
  6956.  
  6957. // Trim common prefix and suffix
  6958. let prefixLen = 0;
  6959. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  6960. prefixLen++;
  6961. }
  6962. let suffixLen = 0;
  6963. while (
  6964. suffixLen < origLen - prefixLen &&
  6965. suffixLen < modLen - prefixLen &&
  6966. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  6967. ) {
  6968. suffixLen++;
  6969. }
  6970.  
  6971. // Cache references for speed
  6972. const orig = original.slice(prefixLen, origLen - suffixLen);
  6973. const mod = modified.slice(prefixLen, modLen - suffixLen);
  6974. const lcs = computeLCS(orig, mod);
  6975. // Pre-allocate ops array, accounting for potential moves
  6976. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  6977. let opCount = 0;
  6978.  
  6979. let i = 0, j = 0, k = 0;
  6980. let curIndex = prefixLen;
  6981. const lcsLen = lcs.length;
  6982.  
  6983. while (k < lcsLen) {
  6984. const match = lcs[k];
  6985. let deleteCount = 0;
  6986. const deleted = [];
  6987. const added = [];
  6988.  
  6989. // 1) Collect deletions up to the next common element
  6990. while (i < orig.length && orig[i] !== match) {
  6991. deleted.push(orig[i]);
  6992. deleteCount++;
  6993. i++;
  6994. }
  6995.  
  6996. // 2) Collect insertions up to that same element
  6997. while (j < mod.length && mod[j] !== match) {
  6998. added.push(mod[j]);
  6999. j++;
  7000. }
  7001.  
  7002. // 3) Check for a move (deleted segment matches inserted segment)
  7003. let isMove = false;
  7004. if (deleteCount > 0 && deleteCount === added.length) {
  7005. isMove = deleted.every((x, idx) => x === added[idx]);
  7006. if (isMove) {
  7007. // If a move, split into delete and insert at different indices
  7008. if (deleteCount > 0) {
  7009. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  7010. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  7011. curIndex += added.length; // Advance past inserted items
  7012. }
  7013. }
  7014. }
  7015.  
  7016. // 4) Combine delete and insert into a single operation if not a move
  7017. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  7018. ops[opCount++] = [curIndex, deleteCount, added];
  7019. curIndex += added.length; // Advance past inserted items
  7020. }
  7021.  
  7022. // 5) Skip over the matching element itself
  7023. i++;
  7024. j++;
  7025. k++;
  7026. curIndex++;
  7027. }
  7028.  
  7029. // 6) Handle any trailing deletions and insertions as a single operation
  7030. const trailingDelete = orig.length - i;
  7031. const trailingAdd = mod.slice(j);
  7032. if (trailingDelete > 0 || trailingAdd.length > 0) {
  7033. // Check for trailing move
  7034. const trailingDeleted = orig.slice(i);
  7035. let isMove = false;
  7036. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  7037. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  7038. if (isMove) {
  7039. ops[opCount++] = [curIndex, trailingDelete, []];
  7040. ops[opCount++] = [curIndex, 0, trailingAdd];
  7041. }
  7042. }
  7043. if (!isMove) {
  7044. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  7045. }
  7046. }
  7047.  
  7048. // 7) Truncate ops array to actual size
  7049. ops.length = opCount;
  7050.  
  7051. return ops;
  7052. }
  7053. // class listPlaceholder {
  7054. // constructor(len){
  7055. // this.length = len;
  7056. // }
  7057. // }
  7058.  
  7059.  
  7060.  
  7061. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  7062. // var renderJob = this.renderJobsMap_[key],
  7063. // renderCallback = null;
  7064.  
  7065. // if (path === changeRecord.path) {
  7066. // let value = changeRecord.value;
  7067.  
  7068. // if (!_.v_(value)) {
  7069. // value = (value === void 0 || value === null) ? [] : [value];
  7070. // }
  7071.  
  7072. // let stampDomEntry = this.stampDom[path];
  7073.  
  7074. // if (stampDomEntry.mapping) {
  7075. // renderCallback = this.stampDomArray_.bind(
  7076. // this,
  7077. // value,
  7078. // key,
  7079. // stampDomEntry.mapping,
  7080. // stampDomEntry.reuseComponents,
  7081. // stampDomEntry.events,
  7082. // stampDomEntry.stamperStableList
  7083. // );
  7084. // }
  7085.  
  7086. // if (renderJob) renderJob.cancel();
  7087.  
  7088. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  7089.  
  7090. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  7091. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  7092. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  7093. // this.renderJobsMap_[key] = renderJob;
  7094. // }
  7095. // } else {
  7096. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  7097. // this.renderJobsMap_[key] = renderJob;
  7098. // renderCallback = function(callback, job) {
  7099. // callback();
  7100. // q4C(job, 10);
  7101. // }.bind(this, renderCallback, renderJob);
  7102. // }
  7103. // } else {
  7104. // renderCallback = (path + ".splices" === changeRecord.path)
  7105. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  7106. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  7107. // }
  7108.  
  7109. // if (renderJob) {
  7110. // _.vY(renderJob, renderCallback);
  7111. // } else {
  7112. // renderCallback();
  7113. // }
  7114. // }
  7115.  
  7116.  
  7117.  
  7118.  
  7119. const createStampDomFnsC_ = () => {
  7120.  
  7121. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  7122.  
  7123. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  7124. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  7125.  
  7126.  
  7127. // const rq0 = document.createElement('rp');
  7128. // rq0.setAttribute('yt-element-placholder', '');
  7129.  
  7130. const it0 = Date.now() - 80000000000;
  7131. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  7132.  
  7133.  
  7134. const getStampContainer_ = function (containerId) {
  7135.  
  7136. return this.getStampContainer7409_(containerId);
  7137.  
  7138. }
  7139.  
  7140.  
  7141.  
  7142.  
  7143. const createComponent_ = function (componentConfig, data, canReuse) {
  7144.  
  7145. return this.createComponent7409_(componentConfig, data, canReuse);
  7146.  
  7147. }
  7148.  
  7149.  
  7150. const s52 = Symbol();
  7151.  
  7152. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  7153.  
  7154. // if(component.querySelectorAll('dom-if').length > 0){
  7155.  
  7156. // // console.log(1233, component.isConnected, component.parentNode, component.querySelectorAll('dom-if'))
  7157. // if (component.isConnected === false) {
  7158. // for (const s of component.querySelectorAll('dom-if')) {
  7159. // try {
  7160. // console.log(1299);
  7161. // insp(s).__teardownInstance();
  7162. // } catch (e) { }
  7163. // }
  7164. // }
  7165.  
  7166. // }
  7167.  
  7168. if (typeof (data || 0) === 'object') {
  7169. if (!data[s52]) data[s52] = genId();
  7170. component[s52] = data[s52];
  7171. // console.log(component[s52], data);
  7172. } else {
  7173. component[s52] = null;
  7174. }
  7175.  
  7176. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7177.  
  7178. }
  7179.  
  7180. // let pr77 = Promise.resolve();
  7181.  
  7182. const flushRenderStamperComponentBindings_ = function () {
  7183. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  7184.  
  7185. if (this.deferredBindingTasks_.length >= 0) {
  7186.  
  7187. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  7188.  
  7189. const gid = this[`__$$stampFlushKey$$__`] = genId();
  7190. const g = (() => {
  7191. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  7192. // if (deferredBindingTasks_.length === 0) return;
  7193. // let q = this.deferredBindingTasks_;
  7194. // this.deferredBindingTasks_ = deferredBindingTasks_;
  7195. this.flushRenderStamperComponentBindings7409_();
  7196. // deferredBindingTasks_.length = 0;
  7197. // this.deferredBindingTasks_ = q;
  7198.  
  7199. const s = [...this.__lat457__];
  7200. this.__lat457__.clear();
  7201.  
  7202. for (const containerWr of s) {
  7203.  
  7204. const container = kRef(containerWr);
  7205. if (!container) continue;
  7206.  
  7207. // const s = new Set();
  7208. if (!container.querySelector('[ytx-flushing]')) {
  7209. if (container.hasAttribute('ytx-flushing')) {
  7210. const attrVal = container.getAttribute('ytx-flushing');
  7211. container.removeAttribute('ytx-flushing');
  7212. // s.add([container, attrVal]);
  7213. addTask(container, attrVal);
  7214. // addTaskIm(container, attrVal);
  7215. let ancestor = container.closest('[ytx-flushing]');
  7216. while (ancestor) {
  7217. if (ancestor.querySelector('[ytx-flushing]')) break;
  7218. const attrVal = ancestor.getAttribute('ytx-flushing');
  7219. ancestor.removeAttribute('ytx-flushing');
  7220. // s.add([ancestor, attrVal]);
  7221. addTask(ancestor, attrVal);
  7222. // addTaskIm(ancestor, attrVal);
  7223. ancestor = ancestor.closest('[ytx-flushing]');
  7224. }
  7225. }
  7226. }
  7227. }
  7228. executeTasks();
  7229.  
  7230.  
  7231. });
  7232. g();
  7233. // const useMicroTaskQueue = this.__qsd477__ === 2;
  7234. // useMicroTaskQueue ? addTask2(g) : g();
  7235. // executeTasks();
  7236.  
  7237. // addTask2(g);
  7238. // executeTasks();
  7239.  
  7240. }
  7241.  
  7242. throw new Error('e5bd8d2f');
  7243.  
  7244. }
  7245.  
  7246. let tasks = [];
  7247. let excuted = false;
  7248. const executeTasks = ()=>{
  7249. if(excuted || tasks.length === 0) return;
  7250. excuted = true;
  7251. let t0 = 0;
  7252. const perform = ()=>{
  7253. if(!t0) t0 = nativeNow();
  7254. const task = tasks.shift();
  7255. if(!task){
  7256. excuted = false;
  7257. return;
  7258. }
  7259. task.fn(task);
  7260. const t1 = nativeNow();
  7261. if(t1 - t0 > 10){
  7262. t0 = 0;
  7263. nextBrowserTick_(perform);
  7264. }else{
  7265. queueMicrotask_(perform);
  7266. }
  7267. }
  7268. queueMicrotask_(perform);
  7269. }
  7270.  
  7271. const taskFn = (task) => {
  7272.  
  7273. if(!task) return;
  7274. const { containerWr, attrVal } = task;
  7275. const container = kRef(containerWr);
  7276. if (!container) return;
  7277. if (attrVal === '0') return;
  7278. const bEventCb = attrVal === '2';
  7279. const producerWr = containerMapping.get(container);
  7280. const producer = kRef(producerWr);
  7281. if (!producer) return;
  7282. const hostElement = producer.hostElement;
  7283. if (!hostElement) return;
  7284. if (hostElement.isConnected !== true) return; // tbc
  7285. producer.markDirty && producer.markDirty();
  7286. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  7287. container
  7288. });
  7289.  
  7290. }
  7291.  
  7292. const addTask = (container, attrVal) => {
  7293. if (!container) return;
  7294. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7295. tasks.push({
  7296. fn: taskFn,
  7297. containerWr: containerWr,
  7298. attrVal
  7299. });
  7300. // pr77 = pr77.then(()=>{
  7301.  
  7302. // })
  7303. // taskFn({
  7304. // containerWr: containerWr,
  7305. // attrVal
  7306. // })
  7307.  
  7308. }
  7309.  
  7310. const addTaskIm = (container, attrVal) => {
  7311. if (!container) return;
  7312. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  7313. taskFn({
  7314. fn: taskFn,
  7315. containerWr: containerWr,
  7316. attrVal
  7317. });
  7318.  
  7319. }
  7320.  
  7321.  
  7322. const addTask2 = (f) => {
  7323. // pr77 = pr77.then(f).catch(console.warn);
  7324. tasks.push({
  7325. fn: f
  7326. });
  7327.  
  7328. }
  7329.  
  7330. // const mo = new MutationObserver((mutations)=>{
  7331.  
  7332. // });
  7333. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  7334.  
  7335. const containerMapping = new WeakMap();
  7336.  
  7337. // let pr77 = Promise.resolve();
  7338. // let pr88 = Promise.resolve();
  7339. const uA4 = function (t, P) {
  7340. for (let y in t)
  7341. if (t.hasOwnProperty(y) && P[y])
  7342. return y;
  7343. return null
  7344. }
  7345.  
  7346. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  7347.  
  7348. const ax = ax_;
  7349. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  7350. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  7351. // const useMicroTaskQueue = false;
  7352. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  7353. ax[2].cancel();
  7354. useMicroTaskQueue2 = false;
  7355. }
  7356. // console.log(1992,containerId, this.hostElement.is)
  7357.  
  7358. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  7359. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  7360. // return false;
  7361.  
  7362. // }
  7363.  
  7364. if (producer.hasFlexibleItems === true) {
  7365. return false;
  7366. }
  7367.  
  7368. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  7369. return false;
  7370. }
  7371.  
  7372. const hostIs = hostIs_;
  7373.  
  7374. 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;
  7375.  
  7376. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  7377. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  7378. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  7379. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  7380. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  7381. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  7382. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  7383. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  7384. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  7385. 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;
  7386. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  7387. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  7388. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  7389. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  7390. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  7391. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  7392. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  7393. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  7394. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  7395.  
  7396.  
  7397. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  7398.  
  7399.  
  7400. // console.log(5992,stackAt)
  7401.  
  7402. // console.log(2883, this[`__quu477#${containerId}__`] )
  7403. // if (useMicroTaskQueue) {
  7404. // console.log(stackAt)
  7405. // }
  7406.  
  7407. // if (useMicroTaskQueue) {
  7408. // console.log(1120301)
  7409. // }
  7410.  
  7411. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  7412.  
  7413. return useMicroTaskQueue2;
  7414.  
  7415. }
  7416.  
  7417. const frag385 = document.createDocumentFragment();
  7418. frag385.appendChild4202 = frag385.appendChild;
  7419. frag385.removeChild4202 = frag385.removeChild;
  7420. const cm385 = document.createComment('.');
  7421.  
  7422. const doc385 = document.implementation.createHTMLDocument();
  7423. const html385 = doc385.firstElementChild;
  7424. const node385 = html385.appendChild(document.createElement('div'));
  7425.  
  7426. const fixContainerApi = (container) => {
  7427. if (container instanceof Node) {
  7428. const containerDomApi = container.__domApi;
  7429. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  7430. // console.log(123882, container)
  7431. containerDomApi.removeChild588 = containerDomApi.removeChild;
  7432. containerDomApi.removeChild = function (elem) {
  7433. let r;
  7434. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7435. s.setAttribute('ytx-flushing', '0');
  7436. }
  7437. try {
  7438. r = this.removeChild588(elem);
  7439. } catch (e) { }
  7440. if (!r) {
  7441. frag385.appendChild4202(elem);
  7442. frag385.removeChild4202(elem);
  7443. r = elem;
  7444. }
  7445. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  7446. s.removeAttribute('ytx-flushing');
  7447. }
  7448. return r;
  7449. }
  7450. }
  7451. }
  7452. }
  7453.  
  7454. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7455.  
  7456. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7457. if (typeof sqq === 'function') sqq();
  7458.  
  7459. // trigger in rendererStamperApplyChangeRecord_
  7460.  
  7461. // 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];
  7462. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7463. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7464. // 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];
  7465.  
  7466. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7467. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7468.  
  7469.  
  7470. const ax = this[`__quu477#${containerId}__`];
  7471. const hostIs = (this.hostElement || 0).is;
  7472. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7473.  
  7474. const container = this.getStampContainer7409_(containerId);
  7475. const pChildren = (container instanceof Node && container.isConnected) ? [...container.children] : [];
  7476. renderPathMake(pChildren)
  7477.  
  7478. containerMapping.set(container,
  7479. (this[wk] || (this[wk] = mWeakRef(this)))
  7480. );
  7481.  
  7482. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7483. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7484.  
  7485. // let dataList_ = dataList;
  7486. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  7487.  
  7488. dataList = null;
  7489. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  7490. let fq = 0;
  7491. const f = (() => {
  7492. if(fq) return;
  7493. fq = 1;
  7494. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7495. this[`__$$stampSFn$$#${containerId}__`] = null;
  7496. const container = this.getStampContainer7409_(containerId);
  7497.  
  7498. this.__lat457__ = this.__lat457__ || new Set();
  7499. if(!container[wk]) container[wk] = mWeakRef(container);
  7500. this.__lat457__.add(container[wk]);
  7501. fixContainerApi(container);
  7502.  
  7503. // let q = this.deferredBindingTasks_;
  7504. // this.deferredBindingTasks_ = [];
  7505. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7506. let e_;
  7507. try {
  7508. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  7509. } catch (e) { e_ = e }
  7510. this.__qsd477__ = false;
  7511. dataList_ = typeOrConfig = null;
  7512. fixContainerApi(container);
  7513. // this.deferredBindingTasks_ = q;
  7514. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7515. if (!e_) {
  7516. // container.setAttribute('ytx-flushing', '0');
  7517. }
  7518. // if( container.childElementCount === 0 ){
  7519. // container.setAttribute('ytx-flushing', '0');
  7520. // this.markDirty && this.markDirty();
  7521. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  7522. // container
  7523. // });
  7524. // }
  7525.  
  7526.  
  7527.  
  7528.  
  7529. });
  7530. this[`__$$stampSFn$$#${containerId}__`] = f;
  7531. this[`__$$stampSqq$$#${containerId}__`] = f;
  7532. useMicroTaskQueue2 ? addTask2(f) : f();
  7533. executeTasks();
  7534.  
  7535. Promise.resolve(pChildren).then(pChildren => {
  7536. for (const node of pChildren) {
  7537. if (node.isConnected === false) {
  7538. _removedElements.addNode(node); // rn54006
  7539. }
  7540. }
  7541. pChildren.length = 0;
  7542. pChildren = null;
  7543. });
  7544.  
  7545. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  7546.  
  7547. return undefined;
  7548.  
  7549. }
  7550.  
  7551. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  7552.  
  7553.  
  7554. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  7555. if (typeof sqq === 'function') sqq();
  7556.  
  7557. // trigger in rendererStamperApplyChangeRecord_
  7558.  
  7559. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7560. } else {
  7561. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7562. }
  7563.  
  7564.  
  7565. // trigger in rendererStamperApplyChangeRecord_
  7566.  
  7567. // 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];
  7568. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  7569. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  7570.  
  7571. // 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];
  7572.  
  7573. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  7574. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  7575. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  7576.  
  7577. const ax = this[`__quu477#${containerId}__`];
  7578. const hostIs = (this.hostElement || 0).is;
  7579. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  7580.  
  7581.  
  7582. // 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];
  7583. // const useMicroTaskQueue = true;
  7584. const container = this.getStampContainer7409_(containerId);
  7585.  
  7586. containerMapping.set(container,
  7587. (this[wk] || (this[wk] = mWeakRef(this)))
  7588. );
  7589. const bEventCb = this.stampDom[stampKey].events;
  7590. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  7591. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  7592.  
  7593. // let indexSplicesObj_ = indexSplicesObj;
  7594. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  7595. // indexSplicesObj_ = {
  7596. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  7597. // const { index, addedCount, removed, object, type } = slice;
  7598. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7599. // return { index, addedCount, removed, object, type };
  7600. // })
  7601. // };
  7602. // }
  7603.  
  7604.  
  7605. indexSplicesObj.indexSplices.forEach(slice => {
  7606. const object = slice.object;
  7607. if (!object || typeof object !== 'object') return;
  7608. // const { index, addedCount, removed, object, type } = slice;
  7609. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  7610. // return { index, addedCount, removed, object, type };
  7611. });
  7612.  
  7613. // let indexSplicesObj_ = indexSplicesObj;
  7614.  
  7615. // console.log(128783, indexSplicesObj)
  7616.  
  7617. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  7618. // const { index, addedCount, removed, object, type } = slice;
  7619. // return { index, addedCount, removed, object, type };
  7620. // });
  7621.  
  7622. indexSplicesObj = null;
  7623.  
  7624. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  7625. const gid = this[`__$$stampSID$$#${containerId}__`];
  7626. let fq = 0;
  7627. const f = (() => {
  7628. if(fq) return;
  7629. fq = 1;
  7630. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  7631. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  7632. const container = this.getStampContainer7409_(containerId);
  7633. if(!container) return;
  7634.  
  7635. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  7636.  
  7637. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  7638. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  7639. const mapping = this.stampDom[stampKey].mapping;
  7640.  
  7641. const map = new Map();
  7642.  
  7643. const currentObjKeys = object.map(objEntry => {
  7644. const mappingKey = uA4(mapping, objEntry);
  7645. if(!mappingKey) return null;
  7646. const data = objEntry[mappingKey];
  7647. if (!data[s52]) data[s52] = genId();
  7648. map.set(data[s52], objEntry);
  7649. // return ({
  7650. // objEntry,
  7651. // data: data,
  7652. // mappingKey: mappingKey,
  7653. // key: data[s52],
  7654. // exist: elementKeys.has(data[s52])
  7655. // });
  7656. return data[s52]
  7657.  
  7658. });
  7659.  
  7660. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  7661.  
  7662. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  7663.  
  7664. const splices = diffSplices(oldDomKeys, currentObjKeys);
  7665.  
  7666. // let myObject = object;
  7667. let indexSplicesObj_ = {
  7668. indexSplices: splices.map(splice => {
  7669. const index = splice[0];
  7670. const removedLen = splice[1];
  7671. const added = splice[2];
  7672. const addedCount = added.length;
  7673. const object = {};
  7674. object.length = index + addedCount;
  7675. for (let i = 0; i < addedCount; i++) {
  7676. object[index + i] = map.get(added[i]);
  7677. }
  7678. const removed = {};
  7679. removed.length = removedLen;
  7680.  
  7681. return { index, removed, object, addedCount }
  7682. })
  7683. };
  7684. map.clear();
  7685.  
  7686.  
  7687. this.__lat457__ = this.__lat457__ || new Set();
  7688. if(!container[wk]) container[wk] = mWeakRef(container);
  7689. this.__lat457__.add(container[wk]);
  7690. fixContainerApi(container);
  7691.  
  7692. // console.log(3882, indexSplicesObj_)
  7693. // let q = this.deferredBindingTasks_;
  7694. // this.deferredBindingTasks_ = [];
  7695. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  7696. let e_;
  7697. try {
  7698. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  7699. } catch (e) { e_ = e; }
  7700. this.__qsd477__ = false;
  7701. indexSplicesObj_ = null;
  7702. stampKey = indexSplicesObj_ = null;
  7703. fixContainerApi(container);
  7704. // this.deferredBindingTasks_ = q;
  7705. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7706. if (!e_) {
  7707. // container.setAttribute('ytx-flushing', '0');
  7708. }
  7709.  
  7710.  
  7711. });
  7712. this[`__$$stampSqq$$#${containerId}__`] = f;
  7713. useMicroTaskQueue2 ? addTask2(f) : f();
  7714. executeTasks();
  7715.  
  7716. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  7717.  
  7718. return undefined;
  7719.  
  7720. }
  7721.  
  7722.  
  7723. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  7724. const dt0 = dt0a[0];
  7725. const dt1 = Date.now();
  7726. const obj = kRef(objWr);
  7727. if (!obj) return;
  7728. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7729. if (xxx !== xxx_) return;
  7730. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7731. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7732. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7733. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7734. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7735. const renderJob1 = obj.renderJobsMap_[containerId]
  7736. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  7737. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7738. let e_, r;
  7739. try {
  7740. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7741. } catch (e) {
  7742. e_ = e;
  7743. }
  7744. obj[`__quu477#${containerId}__`] = false;
  7745. if (e_) throw e_;
  7746. return r;
  7747. };
  7748.  
  7749.  
  7750. stampDomArray_.bind = function (obj, ...args) {
  7751. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7752. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7753. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7754. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  7755. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  7756. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7757. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7758. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7759. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7760.  
  7761.  
  7762. const renderJob = obj.renderJobsMap_[containerId];
  7763.  
  7764. const dt0a = [Date.now()];
  7765. queueMicrotask_(() => { dt0a[0] = 0 });
  7766. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  7767. };
  7768.  
  7769. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  7770. const dt0 = dt0a[0];
  7771. const dt1 = Date.now();
  7772. const obj = kRef(objWr);
  7773. if (!obj) return;
  7774. const renderJob1 = obj.renderJobsMap_[containerId];
  7775. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7776. let e_, r;
  7777. try {
  7778. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  7779. } catch (e) {
  7780. e_ = e;
  7781. }
  7782. obj[`__quu477#${containerId}__`] = false;
  7783. if (e_) throw e_;
  7784. return r;
  7785. };
  7786.  
  7787.  
  7788. stampDomArraySplices_.bind = function (obj, ...args) {
  7789. let [stampKey, containerId, indexSplicesObj] = args;
  7790. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7791.  
  7792. const renderJob = obj.renderJobsMap_[containerId];
  7793.  
  7794. const dt0a = [Date.now()];
  7795. queueMicrotask_(() => { dt0a[0] = 0 });
  7796. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  7797. };
  7798.  
  7799. const flushRenderStamperComponentBindings7419_ = function () {
  7800. const tasks = this.deferredBindingTasks_;
  7801. if (!(tasks || 0).length) return;
  7802. const hostElement = this.hostElement;
  7803. if ((hostElement instanceof Node) && hostElement.nodeType === 1) {
  7804. if (hostElement.isConnected === true) {
  7805. this.flushRenderStamperComponentBindings7409_();
  7806. }
  7807. } else if (hostElement) {
  7808. console.log('flushRenderStamperComponentBindings7419_ 002')
  7809. this.flushRenderStamperComponentBindings7409_();
  7810. } else {
  7811. console.log('flushRenderStamperComponentBindings7419_ 003')
  7812. tasks.length = 0;
  7813. }
  7814. }
  7815.  
  7816. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ , flushRenderStamperComponentBindings7419_};
  7817.  
  7818. }
  7819.  
  7820. const setupDiscreteTasks = (h, rb) => {
  7821.  
  7822. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7823. const f = h.onYtRendererstamperFinished;
  7824. const g = ump3.get(f) || function () {
  7825. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7826. return f.apply(this, arguments);
  7827. }
  7828. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7829. }
  7830. ump3.set(f, g);
  7831. g.km34 = 1;
  7832. h.onYtRendererstamperFinished = g;
  7833.  
  7834. }
  7835.  
  7836. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7837. const f = h.onYtUpdateDescriptionAction;
  7838. const g = ump3.get(f) || function (a) {
  7839. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7840. }
  7841. ump3.set(f, g);
  7842. g.km34 = 1;
  7843. h.onYtUpdateDescriptionAction = g;
  7844.  
  7845. }
  7846.  
  7847. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7848. const f = h.handleUpdateDescriptionAction;
  7849. const g = ump3.get(f) || function (a) {
  7850. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7851. }
  7852. ump3.set(f, g);
  7853. g.km34 = 1;
  7854. h.handleUpdateDescriptionAction = g;
  7855.  
  7856. }
  7857.  
  7858. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7859. const f = h.handleUpdateLiveChatPollAction;
  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.handleUpdateLiveChatPollAction = g;
  7866.  
  7867. }
  7868.  
  7869. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  7870. const f = h.onTextChanged;
  7871. const g = ump3.get(f) || function () {
  7872. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7873. }
  7874. ump3.set(f, g);
  7875. g.km34 = 1;
  7876. h.onTextChanged = g;
  7877.  
  7878. }
  7879.  
  7880. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  7881. const f = h.onVideoDataChange;
  7882. const g = ump3.get(f) || function (a) {
  7883. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7884. }
  7885. ump3.set(f, g);
  7886. g.km34 = 1;
  7887. h.onVideoDataChange = g;
  7888.  
  7889. }
  7890.  
  7891. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  7892. const f = h.onVideoDataChange_;
  7893. const g = ump3.get(f) || function () {
  7894. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7895. }
  7896. ump3.set(f, g);
  7897. g.km34 = 1;
  7898. h.onVideoDataChange_ = g;
  7899.  
  7900. }
  7901.  
  7902. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  7903.  
  7904. const f = h.addTooltips_;
  7905. const g = ump3.get(f) || function () {
  7906. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7907. }
  7908. ump3.set(f, g);
  7909. g.km34 = 1;
  7910. h.addTooltips_ = g;
  7911.  
  7912. }
  7913.  
  7914. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  7915.  
  7916. const f = h.updateRenderedElements;
  7917. const g = ump3.get(f) || function () {
  7918. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7919. }
  7920. ump3.set(f, g);
  7921. g.km34 = 1;
  7922. h.updateRenderedElements = g;
  7923.  
  7924. }
  7925.  
  7926. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  7927. const f = h.loadPage_;
  7928. const g = ump3.get(f) || function (a) {
  7929. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7930. }
  7931. ump3.set(f, g);
  7932. g.km34 = 1;
  7933. h.loadPage_ = g;
  7934.  
  7935. }
  7936. // updatePageData_ : possible conflict with Omit ShadyDOM
  7937. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  7938. const f = h.updatePageData_;
  7939. const g = ump3.get(f) || function (a) {
  7940. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7941. }
  7942. ump3.set(f, g);
  7943. g.km34 = 1;
  7944. h.updatePageData_ = g;
  7945.  
  7946. }
  7947.  
  7948.  
  7949. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  7950.  
  7951. const f = h.onFocus_;
  7952. const g = ump3.get(f) || function () {
  7953. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7954. }
  7955. ump3.set(f, g);
  7956. g.km34 = 1;
  7957. h.onFocus_ = g;
  7958.  
  7959. }
  7960.  
  7961. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  7962.  
  7963. const f = h.onBlur_;
  7964. const g = ump3.get(f) || function () {
  7965. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7966. }
  7967. ump3.set(f, g);
  7968. g.km34 = 1;
  7969. h.onBlur_ = g;
  7970.  
  7971. }
  7972.  
  7973.  
  7974. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  7975.  
  7976. const f = h.buttonClassChanged_;
  7977. const g = ump3.get(f) || function (a, b) {
  7978. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7979. }
  7980. ump3.set(f, g);
  7981. g.km34 = 1;
  7982. h.buttonClassChanged_ = g;
  7983.  
  7984. }
  7985.  
  7986. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  7987.  
  7988. const f = h.buttonIconChanged_;
  7989. const g = ump3.get(f) || function (a) {
  7990. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7991. }
  7992. ump3.set(f, g);
  7993. g.km34 = 1;
  7994. h.buttonIconChanged_ = g;
  7995.  
  7996. }
  7997.  
  7998. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  7999.  
  8000. const f = h.dataChangedInBehavior_;
  8001. const g = ump3.get(f) || function () {
  8002. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8003. }
  8004. ump3.set(f, g);
  8005. g.km34 = 1;
  8006. h.dataChangedInBehavior_ = g;
  8007.  
  8008. }
  8009.  
  8010. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  8011.  
  8012. const f = h.continuationsChanged_;
  8013. const g = ump3.get(f) || function () {
  8014. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8015. }
  8016. ump3.set(f, g);
  8017. g.km34 = 1;
  8018. h.continuationsChanged_ = g;
  8019.  
  8020. }
  8021.  
  8022.  
  8023. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  8024.  
  8025. const f = h.forceChatPoll_;
  8026. const g = ump3.get(f) || function (a) {
  8027. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8028. }
  8029. ump3.set(f, g);
  8030. g.km34 = 1;
  8031. h.forceChatPoll_ = g;
  8032.  
  8033. }
  8034.  
  8035. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  8036.  
  8037. const f = h.onEndpointClick_;
  8038. const g = ump3.get(f) || function (a) {
  8039. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8040. }
  8041. ump3.set(f, g);
  8042. g.km34 = 1;
  8043. h.onEndpointClick_ = g;
  8044.  
  8045. }
  8046.  
  8047. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  8048.  
  8049. const f = h.onEndpointTap_;
  8050. const g = ump3.get(f) || function (a) {
  8051. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8052. }
  8053. ump3.set(f, g);
  8054. g.km34 = 1;
  8055. h.onEndpointTap_ = g;
  8056.  
  8057. }
  8058.  
  8059. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  8060.  
  8061. const f = h.handleClick_;
  8062. const g = ump3.get(f) || function (a, b) {
  8063. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8064. }
  8065. ump3.set(f, g);
  8066. g.km34 = 1;
  8067. h.handleClick_ = g;
  8068.  
  8069. }
  8070.  
  8071. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  8072.  
  8073. const f = h.onReadyStateChange_;
  8074. const g = ump3.get(f) || function () {
  8075. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8076. }
  8077. ump3.set(f, g);
  8078. g.km34 = 1;
  8079. h.onReadyStateChange_ = g;
  8080.  
  8081. }
  8082.  
  8083. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  8084.  
  8085. const f = h.onReadyStateChangeEntryPoint_;
  8086. const g = ump3.get(f) || function () {
  8087. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8088. }
  8089. ump3.set(f, g);
  8090. g.km34 = 1;
  8091. h.onReadyStateChangeEntryPoint_ = g;
  8092.  
  8093. }
  8094.  
  8095. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  8096.  
  8097. const f = h.readyStateChangeHandler_;
  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.readyStateChangeHandler_ = g;
  8104.  
  8105. }
  8106.  
  8107. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  8108.  
  8109. const f = h.xmlHttpHandler_;
  8110. const g = ump3.get(f) || function (a) {
  8111. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8112. }
  8113. ump3.set(f, g);
  8114. g.km34 = 1;
  8115. h.xmlHttpHandler_ = g;
  8116.  
  8117. }
  8118.  
  8119. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  8120.  
  8121. const f = h.executeCallbacks_; // overloaded
  8122. const g = ump3.get(f) || function (a) {
  8123. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8124. }
  8125. ump3.set(f, g);
  8126. g.km34 = 1;
  8127. h.executeCallbacks_ = g;
  8128.  
  8129. }
  8130.  
  8131. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  8132.  
  8133. const f = h.handleInvalidationData_;
  8134. const g = ump3.get(f) || function (a, b) {
  8135. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8136. }
  8137. ump3.set(f, g);
  8138. g.km34 = 1;
  8139. h.handleInvalidationData_ = g;
  8140.  
  8141. }
  8142.  
  8143. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  8144.  
  8145. const f = h.onInput_;
  8146. const g = ump3.get(f) || function () {
  8147. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8148. }
  8149. ump3.set(f, g);
  8150. g.km34 = 1;
  8151. h.onInput_ = g;
  8152.  
  8153. }
  8154. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  8155.  
  8156. const f = h.trigger_;
  8157. const g = ump3.get(f) || function (a) {
  8158. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8159. }
  8160. ump3.set(f, g);
  8161. g.km34 = 1;
  8162. h.trigger_ = g;
  8163.  
  8164. }
  8165.  
  8166. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  8167.  
  8168. const f = h.requestData_;
  8169. const g = ump3.get(f) || function (a) {
  8170. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8171. }
  8172. ump3.set(f, g);
  8173. g.km34 = 1;
  8174. h.requestData_ = g;
  8175.  
  8176. }
  8177.  
  8178. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  8179.  
  8180. const f = h.onLoadReloadContinuation_;
  8181. const g = ump3.get(f) || function (a, b) {
  8182. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8183. }
  8184. ump3.set(f, g);
  8185. g.km34 = 1;
  8186. h.onLoadReloadContinuation_ = g;
  8187.  
  8188. }
  8189.  
  8190. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  8191.  
  8192. const f = h.onLoadIncrementalContinuation_;
  8193. const g = ump3.get(f) || function (a, b) {
  8194. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8195. }
  8196. ump3.set(f, g);
  8197. g.km34 = 1;
  8198. h.onLoadIncrementalContinuation_ = g;
  8199.  
  8200. }
  8201.  
  8202. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  8203.  
  8204. const f = h.onLoadSeekContinuation_;
  8205. const g = ump3.get(f) || function (a, b) {
  8206. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8207. }
  8208. ump3.set(f, g);
  8209. g.km34 = 1;
  8210. h.onLoadSeekContinuation_ = g;
  8211.  
  8212. }
  8213. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  8214.  
  8215. const f = h.onLoadReplayContinuation_;
  8216. const g = ump3.get(f) || function (a, b) {
  8217. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8218. }
  8219. ump3.set(f, g);
  8220. g.km34 = 1;
  8221. h.onLoadReplayContinuation_ = g;
  8222.  
  8223. }
  8224. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  8225.  
  8226. const f = h.onNavigate_;
  8227. const g = ump3.get(f) || function (a) {
  8228. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8229. }
  8230. ump3.set(f, g);
  8231. g.km34 = 1;
  8232. h.onNavigate_ = g;
  8233.  
  8234. }
  8235.  
  8236. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  8237.  
  8238. const f = h.ytRendererBehaviorDataObserver_;
  8239. const g = ump3.get(f) || function () {
  8240. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8241. }
  8242. ump3.set(f, g);
  8243. g.km34 = 1;
  8244. h.ytRendererBehaviorDataObserver_ = g;
  8245.  
  8246. }
  8247.  
  8248. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  8249.  
  8250. const f = h.ytRendererBehaviorTargetIdObserver_;
  8251. const g = ump3.get(f) || function () {
  8252. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8253. }
  8254. ump3.set(f, g);
  8255. g.km34 = 1;
  8256. h.ytRendererBehaviorTargetIdObserver_ = g;
  8257.  
  8258. }
  8259.  
  8260. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  8261.  
  8262. const f = h.unregisterRenderer_;
  8263. const g = ump3.get(f) || function (a) {
  8264. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8265. }
  8266. ump3.set(f, g);
  8267. g.km34 = 1;
  8268. h.unregisterRenderer_ = g;
  8269.  
  8270. }
  8271.  
  8272. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  8273.  
  8274. const f = h.textChanged_;
  8275. const g = ump3.get(f) || function (a) {
  8276. if (void 0 !== this.isAttached) {
  8277. const hostElement = this.hostElement;
  8278. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  8279. return;
  8280. }
  8281. }
  8282. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8283. }
  8284. ump3.set(f, g);
  8285. g.km34 = 1;
  8286. h.textChanged_ = g;
  8287.  
  8288. }
  8289.  
  8290.  
  8291.  
  8292. /**
  8293. *
  8294. * Neglect following
  8295. *
  8296. * h.onYtAction_
  8297. * h.startLoadingWatch [ buggy for yt-player-updated ]
  8298. * h.deferRenderStamperBinding_
  8299. *
  8300. * h.stampDomArray_
  8301. * h.stampDomArraySplices_
  8302. *
  8303. */
  8304.  
  8305.  
  8306. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  8307. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  8308. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  8309. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  8310. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  8311. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  8312.  
  8313. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  8314.  
  8315. const f = h.searchChanged_;
  8316. const g = ump3.get(f) || function () {
  8317. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8318. }
  8319. ump3.set(f, g);
  8320. g.km34 = 1;
  8321. h.searchChanged_ = g;
  8322.  
  8323. }
  8324.  
  8325. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  8326.  
  8327. const f = h.skinToneChanged_;
  8328. const g = ump3.get(f) || function (a) {
  8329. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8330. }
  8331. ump3.set(f, g);
  8332. g.km34 = 1;
  8333. h.skinToneChanged_ = g;
  8334.  
  8335. }
  8336.  
  8337. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  8338.  
  8339. const f = h.onEmojiHover_;
  8340. const g = ump3.get(f) || function (a) {
  8341. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8342. }
  8343. ump3.set(f, g);
  8344. g.km34 = 1;
  8345. h.onEmojiHover_ = g;
  8346.  
  8347. }
  8348.  
  8349. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  8350.  
  8351. const f = h.onSelectCategory_;
  8352. const g = ump3.get(f) || function (a) {
  8353. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8354. }
  8355. ump3.set(f, g);
  8356. g.km34 = 1;
  8357. h.onSelectCategory_ = g;
  8358.  
  8359. }
  8360.  
  8361. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  8362.  
  8363. const f = h.onShowEmojiVariantSelector;
  8364. const g = ump3.get(f) || function (a) {
  8365. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8366. }
  8367. ump3.set(f, g);
  8368. g.km34 = 1;
  8369. h.onShowEmojiVariantSelector = g;
  8370.  
  8371. }
  8372.  
  8373. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  8374.  
  8375. const f = h.updateCategoriesAndPlaceholder_;
  8376. const g = ump3.get(f) || function () {
  8377. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8378. }
  8379. ump3.set(f, g);
  8380. g.km34 = 1;
  8381. h.updateCategoriesAndPlaceholder_ = g;
  8382.  
  8383. }
  8384.  
  8385. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  8386.  
  8387. const f = h.watchPageActiveChanged_;
  8388. const g = ump3.get(f) || function () {
  8389. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8390. }
  8391. ump3.set(f, g);
  8392. g.km34 = 1;
  8393. h.watchPageActiveChanged_ = g;
  8394.  
  8395. }
  8396.  
  8397. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  8398.  
  8399. const f = h.activate_;
  8400. const g = ump3.get(f) || function () {
  8401. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8402. }
  8403. ump3.set(f, g);
  8404. g.km34 = 1;
  8405. h.activate_ = g;
  8406.  
  8407. }
  8408. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  8409.  
  8410. const f = h.onYtPlaylistDataUpdated_;
  8411. const g = ump3.get(f) || function () {
  8412. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8413. }
  8414. ump3.set(f, g);
  8415. g.km34 = 1;
  8416. h.onYtPlaylistDataUpdated_ = g;
  8417.  
  8418. }
  8419.  
  8420.  
  8421.  
  8422. /**
  8423. *
  8424. * Neglect following
  8425. *
  8426. * h.rendererStamperObserver_
  8427. * h.rendererStamperApplyChangeRecord_
  8428. * h.flushRenderStamperComponentBindings_
  8429. * h.forwardRendererStamperChanges_
  8430. *
  8431. */
  8432.  
  8433. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  8434.  
  8435. const f = h.tryRenderChunk_;
  8436. const g = ump3.get(f) || function () {
  8437. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8438. }
  8439. ump3.set(f, g);
  8440. g.km34 = 1;
  8441. h.tryRenderChunk_ = g;
  8442.  
  8443. }
  8444.  
  8445.  
  8446. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  8447.  
  8448. const f = h.renderChunk_;
  8449. const g = ump3.get(f) || function () {
  8450. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8451. }
  8452. ump3.set(f, g);
  8453. g.km34 = 1;
  8454. h.renderChunk_ = g;
  8455.  
  8456. }
  8457.  
  8458. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  8459.  
  8460. const f = h.deepLazyListObserver_;
  8461. const g = ump3.get(f) || function () {
  8462. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8463. }
  8464. ump3.set(f, g);
  8465. g.km34 = 1;
  8466. h.deepLazyListObserver_ = g;
  8467.  
  8468. }
  8469.  
  8470. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  8471.  
  8472. const f = h.onItemsUpdated_;
  8473. const g = ump3.get(f) || function () {
  8474. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8475. }
  8476. ump3.set(f, g);
  8477. g.km34 = 1;
  8478. h.onItemsUpdated_ = g;
  8479.  
  8480. }
  8481.  
  8482. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  8483.  
  8484. const f = h.requestRenderChunk_;
  8485. const g = ump3.get(f) || function () {
  8486. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8487. }
  8488. ump3.set(f, g);
  8489. g.km34 = 1;
  8490. h.requestRenderChunk_ = g;
  8491.  
  8492. }
  8493.  
  8494. /**
  8495. *
  8496. * Neglect following
  8497. *
  8498. * h.dataChanged_ [ buggy for page swtiching ]
  8499. *
  8500. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  8501. *
  8502. * h.cancelPendingTasks_
  8503. * h.fillRange_
  8504. * h.addTextNodes_
  8505. * h.updateText_
  8506. * h.stampTypeChanged_
  8507. *
  8508. */
  8509.  
  8510.  
  8511. }
  8512.  
  8513. const keyStConnectedCallback = Symbol(); // avoid copying the value
  8514.  
  8515. const dmf = new WeakMap();
  8516.  
  8517.  
  8518. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  8519.  
  8520. try {
  8521.  
  8522. const q = document.createElement('template');
  8523. q.innerHTML = '<ytz-null361></ytz-null361>';
  8524. nativeHTMLElement = q.content.firstChild.constructor
  8525.  
  8526. } catch (e) { }
  8527.  
  8528. if (!nativeHTMLElement.prototype.connectedCallback) {
  8529. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  8530. nativeHTMLElement.prototype.connectedCallback = function () {
  8531. let r;
  8532. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  8533. return r;
  8534. }
  8535. }
  8536. const pvr = Symbol()
  8537.  
  8538. let stampDomArrayFnStore = null;
  8539. const setupMap = new WeakSet();
  8540. const setupYtComponent = (cnt) => {
  8541. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  8542. if (!cProto || setupMap.has(cProto)) return;
  8543. setupMap.add(cProto);
  8544. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  8545. cProto[pvr] |= 1;
  8546.  
  8547.  
  8548.  
  8549. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  8550. const b = cProto.stampDomArray_.length === 6
  8551. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  8552. && cProto.createComponent_ && cProto.createComponent_.length === 3
  8553. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  8554. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  8555. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  8556. if (!b) {
  8557. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  8558. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  8559. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  8560. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_, flushRenderStamperComponentBindings7419_} = stampDomArrayFnStore;
  8561.  
  8562. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  8563. cProto.createComponent7409_ = cProto.createComponent_;
  8564. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  8565. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  8566. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  8567. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  8568.  
  8569. cProto.getStampContainer_ = getStampContainer_;
  8570. cProto.createComponent_ = createComponent_;
  8571. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  8572. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  8573. cProto.stampDomArray_ = stampDomArray_;
  8574. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  8575. cProto.flushRenderStamperComponentBindings7419_ = flushRenderStamperComponentBindings7419_;
  8576.  
  8577. }
  8578. }
  8579.  
  8580.  
  8581.  
  8582.  
  8583. // if(false && cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  8584. // cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  8585.  
  8586. // if(cProto._runEffectsForTemplate6344.length === 4){
  8587.  
  8588. // cProto._runEffectsForTemplate = function (c, d, e, g) {
  8589. // const cnt = this;
  8590. // const { propertyEffects, nodeList, firstChild } = c;
  8591. // cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  8592.  
  8593. // }
  8594.  
  8595. // }
  8596.  
  8597. // }
  8598.  
  8599. }
  8600. };
  8601.  
  8602. (FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  8603. get() {
  8604. const f = this[keyStConnectedCallback];
  8605. if (this.is) {
  8606. setupYtComponent(this);
  8607. }
  8608. return f;
  8609. },
  8610. set(nv) {
  8611. let gv = nv;
  8612. this[keyStConnectedCallback] = gv; // proto or object
  8613. return true;
  8614. },
  8615. enumerable: false,
  8616. configurable: true
  8617.  
  8618. });
  8619.  
  8620. const pLoad = new Promise(resolve => {
  8621. if (document.readyState !== 'loading') {
  8622. resolve();
  8623. } else {
  8624. window.addEventListener("DOMContentLoaded", resolve, false);
  8625. }
  8626. });
  8627.  
  8628. if (FIX_ACTIONS_TOOLTIPS) {
  8629. pLoad.then(() => {
  8630. addNewCSS("#actions .tp-yt-paper-tooltip{white-space:nowrap}");
  8631. });
  8632. }
  8633.  
  8634. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  8635. window.requestIdleCallback471 = window.requestIdleCallback;
  8636. window.requestIdleCallback = function (f, ...args) {
  8637. return (this || window).requestIdleCallback471(async function () {
  8638. await pLoad.then();
  8639. // await new Promise(nextBrowserTick_);
  8640. f.call(this, ...arguments)
  8641. }, ...args);
  8642. }
  8643. }
  8644.  
  8645. pLoad.then(() => {
  8646.  
  8647. let nonce = document.querySelector('style[nonce]');
  8648. nonce = nonce ? nonce.getAttribute('nonce') : null;
  8649. const st = document.createElement('style');
  8650. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  8651. st.textContent = "none-element-k47{order:0}";
  8652. st.addEventListener('load', () => {
  8653. pf31.resolve();
  8654. p59 = 1;
  8655. }, false);
  8656. (document.body || document.head || document.documentElement).appendChild(st);
  8657.  
  8658. });
  8659.  
  8660. const prepareLogs = [];
  8661.  
  8662. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  8663.  
  8664. let winError00 = window.onerror;
  8665.  
  8666. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  8667.  
  8668. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  8669.  
  8670. ; fix_error_many_stack_state === 1 && (() => {
  8671.  
  8672.  
  8673. let p1 = winError00;
  8674.  
  8675. let stackNeedleDetails = null;
  8676.  
  8677. Object.defineProperty(Object.prototype, 'matchAll', {
  8678. get() {
  8679. stackNeedleDetails = this;
  8680. return true;
  8681. },
  8682. enumerable: true,
  8683. configurable: true
  8684. });
  8685.  
  8686. try {
  8687. JSON.parse("{}");
  8688. } catch (e) {
  8689. console.warn(e)
  8690. fix_error_many_stack_state = 0;
  8691. }
  8692.  
  8693. delete Object.prototype['matchAll'];
  8694.  
  8695. let p2 = window.onerror;
  8696.  
  8697. window.onerror = p1;
  8698.  
  8699. if (fix_error_many_stack_state === 0) return;
  8700.  
  8701. if (stackNeedleDetails) {
  8702. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8703. stackNeedleDetails.matchAll = true;
  8704. }
  8705.  
  8706. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8707.  
  8708. // p1!==p2
  8709. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8710.  
  8711. })();
  8712.  
  8713. ; fix_error_many_stack_state === 2 && (() => {
  8714.  
  8715.  
  8716. let p1 = winError00;
  8717.  
  8718. let objectPrune = null;
  8719. let stackNeedleDetails = null;
  8720.  
  8721. Object.defineProperty(Function.prototype, 'findOwner', {
  8722. get() {
  8723. objectPrune = this;
  8724. return this._findOwner;
  8725. },
  8726. set(nv) {
  8727. this._findOwner = nv;
  8728. return true;
  8729. },
  8730. enumerable: true,
  8731. configurable: true
  8732. });
  8733.  
  8734. Object.defineProperty(Object.prototype, 'matchAll', {
  8735. get() {
  8736. stackNeedleDetails = this;
  8737. return true;
  8738. },
  8739. enumerable: true,
  8740. configurable: true
  8741. });
  8742.  
  8743. try {
  8744. JSON.parse("{}");
  8745. } catch (e) {
  8746. console.warn(e)
  8747. fix_error_many_stack_state = 0;
  8748. }
  8749.  
  8750. delete Function.prototype['findOwner'];
  8751. delete Object.prototype['matchAll'];
  8752.  
  8753. let p2 = window.onerror;
  8754.  
  8755. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8756.  
  8757. if (fix_error_many_stack_state == 0) return;
  8758.  
  8759. // the following will only execute when Brave's scriptlets.js is executed.
  8760.  
  8761. prepareLogs.push("fix_error_many_stack_state NB")
  8762.  
  8763. if (stackNeedleDetails) {
  8764. stackNeedleDetails.pattern = null;
  8765. stackNeedleDetails.re = null;
  8766. stackNeedleDetails.expect = null;
  8767. stackNeedleDetails.matchAll = true;
  8768. }
  8769.  
  8770. if (objectPrune) {
  8771. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8772. delete objectPrune._findOwner;
  8773. }
  8774.  
  8775. fix_error_many_stack_state = 3;
  8776. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8777. JSON.parse.objectPrune = objectPrune;
  8778.  
  8779. })();
  8780.  
  8781. ; fix_error_many_stack_state === 3 && (() => {
  8782.  
  8783.  
  8784. let p1 = winError00;
  8785.  
  8786. try {
  8787. JSON.parse("{}");
  8788. } catch (e) {
  8789. console.warn(e)
  8790. fix_error_many_stack_state = 0;
  8791. }
  8792.  
  8793. let p2 = window.onerror;
  8794.  
  8795. if (p1 === p2) return;
  8796.  
  8797. window.onerror = p1;
  8798.  
  8799. if (fix_error_many_stack_state === 0) return;
  8800.  
  8801. fix_error_many_stack_state = 4; // p1 != p2
  8802.  
  8803.  
  8804. })();
  8805.  
  8806. fix_error_many_stack_state === 4 && (() => {
  8807.  
  8808. // the following will only execute when Brave's scriptlets.js is executed.
  8809.  
  8810. prepareLogs.push("fix_error_many_stack_state AB")
  8811.  
  8812. JSON.parseProxy = JSON.parse;
  8813.  
  8814. JSON.parse = ((parse) => {
  8815.  
  8816. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8817. return function (text, reviver) {
  8818. const onerror = window.onerror;
  8819. window.onerror = null;
  8820. let r;
  8821. try {
  8822. r = parse(...arguments);
  8823. } catch (e) {
  8824. r = e;
  8825. }
  8826. window.onerror = onerror;
  8827. if (r instanceof Error) {
  8828. throw r;
  8829. }
  8830. return r;
  8831. }
  8832.  
  8833. })(JSON.parse);
  8834.  
  8835.  
  8836. })();
  8837.  
  8838.  
  8839. // << if FIX_yt_player >>
  8840.  
  8841. // credit to @nopeless (https://gf.qytechs.cn/scripts/471489-youtube-player-perf/)
  8842. const PERF_471489_ = true;
  8843. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8844. // This script uses a much gentle way to tamer the JS engine instead.
  8845.  
  8846. // << end >>
  8847.  
  8848. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8849.  
  8850.  
  8851.  
  8852. const nilFn = () => { };
  8853.  
  8854. let isMainWindow = false;
  8855. try {
  8856. isMainWindow = window.document === window.top.document
  8857. } catch (e) { }
  8858.  
  8859. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  8860. let headLinkCollection = null;
  8861.  
  8862.  
  8863. // const assertor = (f) => f() || console.assert(false, `${f}`);
  8864.  
  8865. const fnIntegrity = (f, d) => {
  8866. if (!f || typeof f !== 'function') {
  8867. console.warn('f is not a function', f);
  8868. return;
  8869. }
  8870. let p = `${f}`, s = 0, j = -1, w = 0;
  8871. for (let i = 0, l = p.length; i < l; i++) {
  8872. const t = p[i];
  8873. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8874. if (j < i - 1) w++;
  8875. j = i;
  8876. } else {
  8877. s++;
  8878. }
  8879. }
  8880. let itz = `${f.length}.${s}.${w}`;
  8881. if (!d) {
  8882. return itz;
  8883. } else {
  8884. return itz === d;
  8885. }
  8886. };
  8887.  
  8888. const getZqOu = (_yt_player) => {
  8889.  
  8890. const w = 'ZqOu';
  8891.  
  8892. let arr = [];
  8893.  
  8894. for (const [k, v] of Object.entries(_yt_player)) {
  8895.  
  8896. const p = typeof v === 'function' ? v.prototype : 0;
  8897. if (p
  8898. && typeof p.start === 'function' && p.start.length === 0 // Ou
  8899. && typeof p.isActive === 'function' && p.isActive.length === 0
  8900. && typeof p.stop === 'function' && p.stop.length === 0
  8901. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8902. && !p.send && !p.abort
  8903. && !p.sample && !p.initialize && !p.fail && !p.getName
  8904. // && !p.dispose && !p.isDisposed
  8905.  
  8906. ) {
  8907. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8908.  
  8909.  
  8910. }
  8911.  
  8912. }
  8913.  
  8914. if (arr.length === 0) {
  8915.  
  8916. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8917. } else {
  8918.  
  8919. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8920. return arr[0];
  8921. }
  8922.  
  8923. }
  8924.  
  8925. const getZqQu = (_yt_player) => {
  8926.  
  8927. const w = 'ZqQu';
  8928.  
  8929. let arr = [];
  8930.  
  8931.  
  8932. for (const [k, v] of Object.entries(_yt_player)) {
  8933.  
  8934. const p = typeof v === 'function' ? v.prototype : 0;
  8935. if (p
  8936. && typeof p.start === 'function' && p.start.length === 1 // Qu
  8937. && typeof p.isActive === 'function' && p.isActive.length === 0
  8938. && typeof p.stop === 'function' && p.stop.length === 0
  8939. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8940. && !p.send && !p.abort
  8941. && !p.sample && !p.initialize && !p.fail && !p.getName
  8942. // && !p.dispose && !p.isDisposed
  8943.  
  8944. ) {
  8945. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8946.  
  8947.  
  8948. }
  8949.  
  8950. }
  8951.  
  8952. if (arr.length === 0) {
  8953.  
  8954. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8955. } else {
  8956.  
  8957. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8958. return arr[0];
  8959. }
  8960.  
  8961. }
  8962.  
  8963.  
  8964. const getVG = (_yt_player) => {
  8965. const w = 'VG';
  8966.  
  8967. let arr = [];
  8968.  
  8969. for (const [k, v] of Object.entries(_yt_player)) {
  8970.  
  8971. const p = typeof v === 'function' ? v.prototype : 0;
  8972. if (p
  8973. && typeof p.show === 'function' && p.show.length === 1
  8974. && typeof p.hide === 'function' && p.hide.length === 0
  8975. && typeof p.stop === 'function' && p.stop.length === 0) {
  8976.  
  8977. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8978.  
  8979. }
  8980.  
  8981. }
  8982.  
  8983.  
  8984. if (arr.length === 0) {
  8985.  
  8986. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8987. } else {
  8988.  
  8989. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8990. return arr[0];
  8991. }
  8992.  
  8993.  
  8994.  
  8995. }
  8996.  
  8997.  
  8998. const getzo = (_yt_player) => {
  8999. const w = 'zo';
  9000.  
  9001. let arr = [];
  9002.  
  9003. for (const [k, v] of Object.entries(_yt_player)) {
  9004.  
  9005. if (
  9006. typeof v === 'function' && v.length === 3 && k.length < 3
  9007. ) {
  9008. const vt = `${v}`;
  9009. if (vt.length >= 21 && vt.includes(".style[")) {
  9010. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  9011. arr.push(k);
  9012. } else {
  9013. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  9014. }
  9015. }
  9016. }
  9017.  
  9018. }
  9019.  
  9020. if (arr.length === 0) {
  9021.  
  9022. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9023. } else {
  9024.  
  9025. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9026. return arr[0];
  9027. }
  9028.  
  9029. }
  9030.  
  9031. const addProtoToArr = (parent, key, arr) => {
  9032.  
  9033.  
  9034. let isChildProto = false;
  9035. for (const sr of arr) {
  9036. if (parent[key].prototype instanceof parent[sr]) {
  9037. isChildProto = true;
  9038. break;
  9039. }
  9040. }
  9041.  
  9042. if (isChildProto) return;
  9043.  
  9044. arr = arr.filter(sr => {
  9045. if (parent[sr].prototype instanceof parent[key]) {
  9046. return false;
  9047. }
  9048. return true;
  9049. });
  9050.  
  9051. arr.push(key);
  9052.  
  9053. return arr;
  9054.  
  9055.  
  9056. }
  9057.  
  9058. const getuG = (_yt_player) => {
  9059.  
  9060. const w = 'uG';
  9061.  
  9062. let arr = [];
  9063.  
  9064. for (const [k, v] of Object.entries(_yt_player)) {
  9065.  
  9066.  
  9067. const p = typeof v === 'function' ? v.prototype : 0;
  9068.  
  9069. if (p
  9070. && typeof p.createElement === 'function' && p.createElement.length === 2
  9071. && typeof p.detach === 'function' && p.detach.length === 0
  9072. && typeof p.update === 'function' && p.update.length === 1
  9073. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  9074. ) {
  9075.  
  9076. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9077.  
  9078. }
  9079.  
  9080. }
  9081.  
  9082.  
  9083.  
  9084.  
  9085.  
  9086. if (arr.length === 0) {
  9087.  
  9088. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9089. } else {
  9090.  
  9091. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9092. return arr[0];
  9093. }
  9094.  
  9095. }
  9096.  
  9097.  
  9098. const getQT = (_yt_player) => {
  9099. const w = 'QT';
  9100.  
  9101. let arr = [];
  9102. let brr = new Map();
  9103.  
  9104. for (const [k, v] of Object.entries(_yt_player)) {
  9105.  
  9106. const p = typeof v === 'function' ? v.prototype : 0;
  9107. if (p) {
  9108. let q = 0;
  9109. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9110. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9111. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9112.  
  9113. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9114.  
  9115. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9116.  
  9117. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9118. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9119. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9120. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9121.  
  9122.  
  9123. // differentiate QT and DX
  9124.  
  9125. q += 280;
  9126. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  9127. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  9128. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  9129. if (typeof p.seekBy === 'function') q += 4;
  9130. if (typeof p.seekTo === 'function') q += 4;
  9131. if (typeof p.getStoryboardFormat === 'function') q += 4;
  9132. if (typeof p.getDuration === 'function') q += 4;
  9133. if (typeof p.loadModule === 'function') q += 4;
  9134. if (typeof p.unloadModule === 'function') q += 4;
  9135. if (typeof p.getOption === 'function') q += 4;
  9136. if (typeof p.getOptions === 'function') q += 4;
  9137. if (typeof p.setOption === 'function') q += 4;
  9138. if (typeof p.addCueRange === 'function') q += 4;
  9139. if (typeof p.getDebugText === 'function') q += 4;
  9140. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  9141. if (typeof p.setSizeStyle === 'function') q += 4;
  9142. if (typeof p.showControls === 'function') q += 4;
  9143. if (typeof p.hideControls === 'function') q += 4;
  9144. if (typeof p.getVideoContentRect === 'function') q += 4;
  9145. if (typeof p.toggleFullscreen === 'function') q += 4;
  9146. if (typeof p.isFullscreen === 'function') q += 4;
  9147. if (typeof p.cancelPlayback === 'function') q += 4;
  9148. if (typeof p.getProgressState === 'function') q += 4;
  9149. if (typeof p.isInline === 'function') q += 4;
  9150. if (typeof p.setInline === 'function') q += 4;
  9151. if (typeof p.toggleSubtitles === 'function') q += 4;
  9152. if (typeof p.getPlayerSize === 'function') q += 4;
  9153. if (typeof p.wakeUpControls === 'function') q += 4;
  9154. if (typeof p.setCenterCrop === 'function') q += 4;
  9155. if (typeof p.getLoopVideo === 'function') q += 4;
  9156. if (typeof p.setLoopVideo === 'function') q += 4;
  9157.  
  9158.  
  9159. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9160.  
  9161. if (q > 0) brr.set(k, q);
  9162.  
  9163. }
  9164.  
  9165. }
  9166.  
  9167. if (arr.length === 0) {
  9168.  
  9169. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9170. } else {
  9171.  
  9172. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9173.  
  9174. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9175.  
  9176. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9177. return arr[0][0];
  9178. }
  9179.  
  9180.  
  9181.  
  9182. }
  9183.  
  9184.  
  9185.  
  9186. const getSV = (_yt_player) => {
  9187. const w = 'SV';
  9188.  
  9189. let arr = [];
  9190. let brr = new Map();
  9191.  
  9192. for (const [k, v] of Object.entries(_yt_player)) {
  9193.  
  9194. const p = typeof v === 'function' ? v.prototype : 0;
  9195. if (p) {
  9196. let q = 0;
  9197. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9198. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9199. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9200.  
  9201. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  9202.  
  9203. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9204.  
  9205. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9206. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9207. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9208. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9209.  
  9210.  
  9211. // differentiate QT and DX
  9212.  
  9213.  
  9214. q += 280;
  9215.  
  9216. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9217. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9218. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9219. if (typeof p.seekBy === 'function') q -= 4;
  9220. if (typeof p.seekTo === 'function') q -= 4;
  9221. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9222. if (typeof p.getDuration === 'function') q -= 4;
  9223. if (typeof p.loadModule === 'function') q -= 4;
  9224. if (typeof p.unloadModule === 'function') q -= 4;
  9225. if (typeof p.getOption === 'function') q -= 4;
  9226. if (typeof p.getOptions === 'function') q -= 4;
  9227. if (typeof p.setOption === 'function') q -= 4;
  9228. if (typeof p.addCueRange === 'function') q -= 4;
  9229. if (typeof p.getDebugText === 'function') q -= 4;
  9230. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9231. if (typeof p.setSizeStyle === 'function') q -= 4;
  9232. if (typeof p.showControls === 'function') q -= 4;
  9233. if (typeof p.hideControls === 'function') q -= 4;
  9234. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9235. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9236. if (typeof p.isFullscreen === 'function') q -= 4;
  9237. if (typeof p.cancelPlayback === 'function') q -= 4;
  9238. if (typeof p.getProgressState === 'function') q -= 4;
  9239. if (typeof p.isInline === 'function') q -= 4;
  9240. if (typeof p.setInline === 'function') q -= 4;
  9241. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9242. if (typeof p.getPlayerSize === 'function') q -= 4;
  9243. if (typeof p.wakeUpControls === 'function') q -= 4;
  9244. if (typeof p.setCenterCrop === 'function') q -= 4;
  9245. if (typeof p.getLoopVideo === 'function') q -= 4;
  9246. if (typeof p.setLoopVideo === 'function') q -= 4;
  9247.  
  9248.  
  9249. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9250.  
  9251. if (q > 0) brr.set(k, q);
  9252.  
  9253. }
  9254.  
  9255. }
  9256.  
  9257. if (arr.length === 0) {
  9258.  
  9259. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9260. } else {
  9261.  
  9262. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9263.  
  9264. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9265.  
  9266. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9267. return arr[0][0];
  9268. }
  9269.  
  9270.  
  9271.  
  9272. }
  9273.  
  9274.  
  9275.  
  9276.  
  9277. const getDX = (_yt_player) => {
  9278. const w = 'DX';
  9279.  
  9280. let arr = [];
  9281. let brr = new Map();
  9282.  
  9283. for (const [k, v] of Object.entries(_yt_player)) {
  9284.  
  9285. const p = typeof v === 'function' ? v.prototype : 0;
  9286. if (p) {
  9287. let q = 0;
  9288. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9289. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9290. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9291.  
  9292. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9293.  
  9294.  
  9295. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  9296.  
  9297. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9298.  
  9299. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9300. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9301. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9302. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9303.  
  9304.  
  9305. // differentiate QT and DX
  9306.  
  9307.  
  9308. q += 280;
  9309.  
  9310. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9311. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9312. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9313. if (typeof p.seekBy === 'function') q -= 4;
  9314. if (typeof p.seekTo === 'function') q -= 4;
  9315. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9316. if (typeof p.getDuration === 'function') q -= 4;
  9317. if (typeof p.loadModule === 'function') q -= 4;
  9318. if (typeof p.unloadModule === 'function') q -= 4;
  9319. if (typeof p.getOption === 'function') q -= 4;
  9320. if (typeof p.getOptions === 'function') q -= 4;
  9321. if (typeof p.setOption === 'function') q -= 4;
  9322. if (typeof p.addCueRange === 'function') q -= 4;
  9323. if (typeof p.getDebugText === 'function') q -= 4;
  9324. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9325. if (typeof p.setSizeStyle === 'function') q -= 4;
  9326. if (typeof p.showControls === 'function') q -= 4;
  9327. if (typeof p.hideControls === 'function') q -= 4;
  9328. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9329. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9330. if (typeof p.isFullscreen === 'function') q -= 4;
  9331. if (typeof p.cancelPlayback === 'function') q -= 4;
  9332. if (typeof p.getProgressState === 'function') q -= 4;
  9333. if (typeof p.isInline === 'function') q -= 4;
  9334. if (typeof p.setInline === 'function') q -= 4;
  9335. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9336. if (typeof p.getPlayerSize === 'function') q -= 4;
  9337. if (typeof p.wakeUpControls === 'function') q -= 4;
  9338. if (typeof p.setCenterCrop === 'function') q -= 4;
  9339. if (typeof p.getLoopVideo === 'function') q -= 4;
  9340. if (typeof p.setLoopVideo === 'function') q -= 4;
  9341.  
  9342.  
  9343. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9344.  
  9345. if (q > 0) brr.set(k, q);
  9346.  
  9347. }
  9348.  
  9349. }
  9350.  
  9351. if (arr.length === 0) {
  9352.  
  9353. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9354. } else {
  9355.  
  9356. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9357.  
  9358. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9359.  
  9360. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9361. return arr[0][0];
  9362. }
  9363.  
  9364.  
  9365.  
  9366. }
  9367.  
  9368.  
  9369.  
  9370. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  9371.  
  9372. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  9373. let pageSetupState = 0;
  9374.  
  9375. isPrepareCachedV && (() => {
  9376.  
  9377. pageSetupVideoId = '';
  9378. const clearCachedV = () => {
  9379. pageSetupVideoId = '';
  9380. pageSetupState = 0;
  9381. }
  9382. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  9383. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  9384. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  9385. document.addEventListener('yt-navigate-finish', () => {
  9386. pageSetupState = 1;
  9387. try {
  9388. const url = new URL(location.href);
  9389. if (!url || !isWatchPageURL(url)) {
  9390. pageSetupVideoId = '';
  9391. } else {
  9392. pageSetupVideoId = url.searchParams.get('v') || '';
  9393. }
  9394. } catch (e) {
  9395. pageSetupVideoId = '';
  9396. }
  9397. }, false);
  9398.  
  9399. })();
  9400.  
  9401. let videoPlayingY = null;
  9402.  
  9403. isPrepareCachedV && (() => {
  9404.  
  9405. let getNext = true;
  9406. let videoPlayingX = {
  9407. get videoId() {
  9408. if (getNext) {
  9409. getNext = false;
  9410.  
  9411. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  9412. const arr = [];
  9413. for (const element of elements) {
  9414. if (!element.closest('[hidden]')) arr.push(element);
  9415. }
  9416. if (arr.length !== 1) this.__videoId__ = '';
  9417. else {
  9418. this.__videoId__ = arr[0].getAttribute('video-id');
  9419. }
  9420.  
  9421. }
  9422. return this.__videoId__ || '';
  9423. }
  9424. }
  9425.  
  9426. videoPlayingY = videoPlayingX;
  9427. const handler = (evt) => {
  9428. const target = (evt || 0).target;
  9429. if (target instanceof HTMLVideoElement) {
  9430. getNext = true;
  9431. }
  9432. }
  9433. document.addEventListener('loadedmetadata', handler, true);
  9434. document.addEventListener('durationchange', handler, true);
  9435.  
  9436. })();
  9437.  
  9438.  
  9439.  
  9440. const cleanContext = async (win) => {
  9441. const waitFn = requestAnimationFrame; // shall have been binded to window
  9442. try {
  9443. let mx = 16; // MAX TRIAL
  9444. const frameId = 'vanillajs-iframe-v1';
  9445. /** @type {HTMLIFrameElement | null} */
  9446. let frame = document.getElementById(frameId);
  9447. let removeIframeFn = null;
  9448. if (!frame) {
  9449. frame = document.createElement('iframe');
  9450. frame.id = frameId;
  9451. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  9452. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  9453. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  9454. n.appendChild(frame);
  9455. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  9456. const root = document.documentElement;
  9457. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  9458. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  9459.  
  9460. removeIframeFn = (setTimeout) => {
  9461. const removeIframeOnDocumentReady = (e) => {
  9462. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9463. e = n;
  9464. n = win = removeIframeFn = 0;
  9465. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  9466. }
  9467. if (!setTimeout || document.readyState !== 'loading') {
  9468. removeIframeOnDocumentReady();
  9469. } else {
  9470. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9471. }
  9472. }
  9473. }
  9474. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  9475. const fc = frame.contentWindow;
  9476. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  9477. try {
  9478. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  9479. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  9480. for (let k in res) res[k] = res[k].bind(win); // necessary
  9481. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  9482. res.animate = fc.HTMLElement.prototype.animate;
  9483. res.perfNow = fc.performance.now;
  9484. return res;
  9485. } catch (e) {
  9486. if (removeIframeFn) removeIframeFn();
  9487. return null;
  9488. }
  9489. } catch (e) {
  9490. console.warn(e);
  9491. return null;
  9492. }
  9493. };
  9494.  
  9495. const promiseForYtActionCalled = new Promise(resolve => {
  9496.  
  9497. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9498. if (typeof AbortSignal !== 'undefined') {
  9499. let hn = () => {
  9500. if (!hn) return;
  9501. hn = null;
  9502. resolve(document.querySelector(appTag));
  9503. };
  9504. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  9505. } else {
  9506. let hn = () => {
  9507. if (!hn) return;
  9508. document.removeEventListener('yt-action', hn, true);
  9509. hn = null;
  9510. resolve(document.querySelector(appTag));
  9511. };
  9512. document.addEventListener('yt-action', hn, true);
  9513. }
  9514. });
  9515.  
  9516. cleanContext(window).then(__CONTEXT__ => {
  9517. if (!__CONTEXT__) return null;
  9518.  
  9519. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  9520.  
  9521.  
  9522. performance.now17 = perfNow.bind(performance);
  9523.  
  9524.  
  9525.  
  9526. __requestAnimationFrame__ = requestAnimationFrame;
  9527.  
  9528.  
  9529. const isGPUAccelerationAvailable = (() => {
  9530. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  9531. try {
  9532. const canvas = document.createElement('canvas');
  9533. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  9534. } catch (e) {
  9535. return false;
  9536. }
  9537. })();
  9538.  
  9539. const foregroundPromiseFn_noGPU = (() => {
  9540.  
  9541. if (isGPUAccelerationAvailable) return null;
  9542.  
  9543. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  9544. if (!pd || typeof pd.get !== 'function') return null;
  9545. const pdGet = pd.get;
  9546.  
  9547. let pr = null;
  9548.  
  9549. let hState = pdGet.call(document) === 'hidden';
  9550. // let cid = 0;
  9551. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  9552. const newHState = pdGet.call(document) === 'hidden';
  9553. if (hState !== newHState) {
  9554. // if (cid > 0) cid = clearInterval(cid);
  9555. hState = newHState;
  9556. if (!hState && pr) pr = pr.resolve();
  9557. }
  9558. });
  9559.  
  9560. // cid = setInterval(() => {
  9561. // const newHState = document.visibilityState === 'hidden';
  9562. // if (hState !== newHState) {
  9563. // hState = newHState;
  9564. // if (!hState && pr) pr = pr.resolve();
  9565. // }
  9566. // }, 100);
  9567.  
  9568.  
  9569. return (() => {
  9570. if (pr) return pr;
  9571. const w = ((!hState && setTimeout(() => {
  9572. if (!hState && pr === w) pr = pr.resolve();
  9573. })), (pr = new PromiseExternal()));
  9574. return w;
  9575. });
  9576.  
  9577. })();
  9578.  
  9579.  
  9580. let rafPromise = null;
  9581. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  9582. requestAnimationFrame(hRes => {
  9583. rafPromise = null;
  9584. resolve(hRes);
  9585. });
  9586. }));
  9587.  
  9588. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  9589.  
  9590.  
  9591. const wmComputedStyle = new WeakMap();
  9592.  
  9593. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  9594. window.__native__getComputedStyle__ = getComputedStyle;
  9595. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  9596. window.__original__getComputedStyle__ = window.getComputedStyle;
  9597. window.getComputedStyle = function (elem) {
  9598. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  9599. return window.__original__getComputedStyle__(...arguments);
  9600. }
  9601. let cs = wmComputedStyle.get(elem);
  9602. if (!cs) {
  9603. cs = window.__native__getComputedStyle__(elem);
  9604. wmComputedStyle.set(elem, cs);
  9605. }
  9606. return cs;
  9607. };
  9608. } else {
  9609. window.__original__getComputedStyle__ = null;
  9610. }
  9611. window.__jst__getComputedStyle__ = window.getComputedStyle;
  9612. }
  9613.  
  9614. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  9615. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  9616. window.getComputedStyle = window.__jst__getComputedStyle__;
  9617. }
  9618. });
  9619.  
  9620. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  9621. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  9622.  
  9623. const promiseForTamerTimeout = new Promise(resolve => {
  9624. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9625. setTimeout(resolve, 480);
  9626. }, { capture: true, passive: true, once: true });
  9627. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9628. setTimeout(resolve, 1200);
  9629. });
  9630. setTimeout(resolve, 3000);
  9631. });
  9632.  
  9633. const promiseForPageInitied = new Promise(resolve => {
  9634. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9635. setTimeout(resolve, 450);
  9636. }, { capture: true, passive: true, once: true });
  9637. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9638. setTimeout(resolve, 900);
  9639. });
  9640. setTimeout(resolve, 1800);
  9641. });
  9642.  
  9643. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  9644. NO_PRELOAD_GENERATE_204_BYPASS = true;
  9645. headLinkCollection = null;
  9646. });
  9647.  
  9648.  
  9649. NATIVE_CANVAS_ANIMATION && (() => {
  9650.  
  9651. observablePromise(() => {
  9652. HTMLCanvasElement.prototype.animate = animate;
  9653. }, promiseForTamerTimeout).obtain();
  9654.  
  9655. })();
  9656.  
  9657.  
  9658.  
  9659.  
  9660. FIX_ytAction_ && (async () => {
  9661.  
  9662. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9663.  
  9664. const ytdApp = await new Promise(resolve => {
  9665.  
  9666. whenCEDefined(appTag).then(() => {
  9667. const ytdApp = document.querySelector(appTag);
  9668. if (ytdApp) {
  9669. resolve(ytdApp);
  9670. return;
  9671. }
  9672. let mo = new MutationObserver(() => {
  9673. const ytdApp = document.querySelector(appTag);
  9674. if (!ytdApp) return;
  9675. if (mo) {
  9676. mo.disconnect();
  9677. mo.takeRecords();
  9678. mo = null;
  9679. }
  9680. resolve(ytdApp);
  9681. });
  9682. mo.observe(document, { subtree: true, childList: true });
  9683. });
  9684.  
  9685. });
  9686.  
  9687. if (!ytdApp) return;
  9688. const cProto = insp(ytdApp).constructor.prototype;
  9689.  
  9690. if (!cProto) return;
  9691. let mbd = 0;
  9692.  
  9693. const fixer = (_ytdApp) => {
  9694. const ytdApp = insp(_ytdApp);
  9695. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9696. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9697. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9698. mbd++;
  9699. }
  9700. }
  9701.  
  9702. observablePromise(() => {
  9703.  
  9704. if (typeof cProto.created === 'function' && !cProto.created56) {
  9705. cProto.created56 = cProto.created;
  9706. cProto.created = function (...args) {
  9707. const r = this.created56(...args);
  9708. fixer(this);
  9709. return r;
  9710. };
  9711. mbd++;
  9712. }
  9713.  
  9714. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9715. cProto.onYtAction57_ = cProto.onYtAction_;
  9716. cProto.onYtAction_ = function (...args) {
  9717. Promise.resolve().then(() => this.onYtAction57_(...args));
  9718. };
  9719. mbd++;
  9720. }
  9721.  
  9722. if (ytdApp) fixer(ytdApp);
  9723.  
  9724. /*
  9725. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9726. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9727. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9728. actionRouter_.handleAction = function (...args) {
  9729. Promise.resolve().then(() => this.handleAction57(...args));
  9730. }
  9731. mbd++;
  9732. }
  9733. */
  9734.  
  9735. // if(mbd === 3) return 1;
  9736. if (mbd >= 3) return 1;
  9737.  
  9738. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9739.  
  9740. })();
  9741.  
  9742.  
  9743. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9744.  
  9745. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9746.  
  9747. const app = await observablePromise(() => {
  9748.  
  9749. return document.querySelector(appTag);
  9750.  
  9751. }).obtain();
  9752.  
  9753. if (!app) return;
  9754.  
  9755. const appCnt = insp(app);
  9756. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9757.  
  9758.  
  9759.  
  9760.  
  9761. });
  9762.  
  9763.  
  9764. // let _yt_player_promise = null;
  9765. /*
  9766. const getYtPlayerPromise = () => {
  9767. if (!_yt_player_promise) {
  9768. _yt_player_promise = new Promise(resolve => {
  9769. let cid = setInterval(() => {
  9770. let t = (((window || 0)._yt_player || 0) || 0);
  9771. if (t) {
  9772. clearInterval(cid);
  9773. resolve(t);
  9774. }
  9775. }, 1);
  9776. promiseForTamerTimeout.then(() => {
  9777. resolve(null)
  9778. });
  9779. });
  9780. }
  9781. return _yt_player_promise;
  9782. }
  9783. */
  9784. const _yt_player_observable = observablePromise(() => {
  9785. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9786. if (_yt_player) {
  9787. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9788. return _yt_player;
  9789. }
  9790. }, promiseForTamerTimeout);
  9791.  
  9792. const polymerObservable = observablePromise(() => {
  9793. const Polymer = window.Polymer;
  9794. if (typeof Polymer !== 'function') return;
  9795. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9796. return Polymer;
  9797. }, promiseForTamerTimeout);
  9798.  
  9799. const schedulerInstanceObservable = observablePromise(() => {
  9800. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9801. }, promiseForTamerTimeout);
  9802.  
  9803. const timelineObservable = observablePromise(() => {
  9804. let t = (((document || 0).timeline || 0) || 0);
  9805. if (t && typeof t._play === 'function') {
  9806. return t;
  9807. }
  9808. }, promiseForTamerTimeout);
  9809. const animationObservable = observablePromise(() => {
  9810. let t = (((window || 0).Animation || 0) || 0);
  9811. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9812. return t;
  9813. }
  9814. }, promiseForTamerTimeout);
  9815.  
  9816.  
  9817. const getScreenInfo = {
  9818. screenWidth: 0,
  9819. screenHeight: 0,
  9820. valueReady: false,
  9821. onResize: () => {
  9822. getScreenInfo.valueReady = false;
  9823. },
  9824. sizeProvided: () => {
  9825. if (getScreenInfo.valueReady) return true;
  9826. getScreenInfo.screenWidth = screen.width;
  9827. getScreenInfo.screenHeight = screen.height;
  9828. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9829. getScreenInfo.valueReady = true;
  9830. return true;
  9831. }
  9832. return false;
  9833. }
  9834. };
  9835.  
  9836. window.addEventListener('resize', getScreenInfo.onResize, true);
  9837.  
  9838.  
  9839. // const hookLeftPending = new WeakMap();
  9840.  
  9841. const isNaNx = Number.isNaN;
  9842.  
  9843. const hookLeftPD = {
  9844. get() {
  9845. const p = 'left';
  9846. // const o = hookLeftPending.get(this);
  9847. // if (o && o.key) {
  9848. // this.setProperty(p, o.value);
  9849. // o.key = null
  9850. // }
  9851. return this.getPropertyValue(p);
  9852. },
  9853. set(v) {
  9854.  
  9855. const p = 'left';
  9856. const cv = this.getPropertyValue(p);
  9857. const sv = v;
  9858.  
  9859. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  9860.  
  9861. // console.log(8380,did, cv, sv)
  9862. if (!cv && !sv) return true;
  9863. if (cv === sv) return true;
  9864.  
  9865. // skip 0~9px => L>=4
  9866.  
  9867. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  9868.  
  9869. if (!isNaNx(qsv)) {
  9870. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  9871.  
  9872. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  9873. const { screenWidth, screenHeight } = getScreenInfo;
  9874. let pWidth = screenWidth + 1024;
  9875. let pHeight = screenHeight + 768;
  9876. const minRatio = 0.003;
  9877. const dw = pWidth * 0.0003; // min dw = 0.3072
  9878. const dh = pHeight * 0.0003; // min dh = 0.2304
  9879. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  9880. if (Math.abs(qcv - qsv) < dw) return true;
  9881. }
  9882.  
  9883. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  9884. if (`${v}`.length > `${sv}`.length) v = sv;
  9885. // console.log(8382, did, sv, nv, cv, this)
  9886. }
  9887.  
  9888. // Promise.resolve().then(() => {
  9889. // const o = hookLeftPending.get(this);
  9890. // if (o && o.key === did) {
  9891. // this.setProperty(p, o.value);
  9892. // o.key = null;
  9893. // }
  9894. // });
  9895. // hookLeftPending.set(this, {
  9896. // key: did,
  9897. // value: nv
  9898. // });
  9899.  
  9900. // if (nv != v) {
  9901. // console.log(8387, v, nv);
  9902. // }
  9903.  
  9904. this.setProperty(p, v);
  9905. // console.log(8383, did, this.getPropertyValue(p))
  9906. return true;
  9907. },
  9908. enumerable: true,
  9909. configurable: true
  9910. };
  9911.  
  9912.  
  9913. if (HOOK_CSSPD_LEFT) {
  9914.  
  9915.  
  9916. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  9917.  
  9918. }
  9919.  
  9920.  
  9921.  
  9922.  
  9923.  
  9924. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  9925.  
  9926. const evKey = `${_evKey}`;
  9927. const fvKey = `${_fvKey}`;
  9928. const debug = !!_debug;
  9929.  
  9930. const _yt_player = await _yt_player_observable.obtain();
  9931.  
  9932.  
  9933. if (!_yt_player || typeof _yt_player !== 'object') return;
  9934.  
  9935.  
  9936. const getArr = (_yt_player) => {
  9937.  
  9938. let arr = [];
  9939.  
  9940. for (const [k, v] of Object.entries(_yt_player)) {
  9941.  
  9942. const p = typeof v === 'function' ? v.prototype : 0;
  9943. if (p
  9944. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  9945.  
  9946. ) {
  9947. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9948.  
  9949. }
  9950.  
  9951. }
  9952.  
  9953. if (arr.length === 0) {
  9954.  
  9955. console.warn(`Key prop [${evKey}] does not exist.`);
  9956. } else {
  9957.  
  9958. return arr;
  9959. }
  9960.  
  9961. };
  9962.  
  9963. const arr = getArr(_yt_player);
  9964.  
  9965.  
  9966. if (!arr) return;
  9967.  
  9968. debug && console.log(`FIX_${evKey}`, arr);
  9969.  
  9970. const f = function (...args) {
  9971. Promise.resolve().then(() => this[fvKey](...args));
  9972. };
  9973.  
  9974.  
  9975. for (const k of arr) {
  9976.  
  9977. const g = _yt_player;
  9978. const gk = g[k];
  9979. const gkp = gk.prototype;
  9980.  
  9981. debug && console.log(237, k, gkp)
  9982.  
  9983. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  9984. gkp[fvKey] = gkp[evKey];
  9985. gkp[evKey] = f;
  9986. }
  9987. }
  9988.  
  9989.  
  9990.  
  9991.  
  9992. }
  9993.  
  9994. if (!isChatRoomURL) {
  9995.  
  9996. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  9997. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  9998. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  9999. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  10000. if (FIX_VideoEVENTS_v2) {
  10001. const FIX_VideoEVENTS_DEBUG = 0;
  10002. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  10003. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  10004. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  10005. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  10006. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  10007. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  10008. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  10009. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  10010. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  10011.  
  10012. }
  10013. // onMutedAutoplayChange
  10014. // onVolumeChange
  10015. // onPlaybackRateChange
  10016.  
  10017. // onAirPlayActiveChange
  10018. // onAirPlayAvailabilityChange
  10019. // onApiChange
  10020. // onAutoplayBlocked
  10021. // onDrmOutputRestricted
  10022. // onFullscreenChange
  10023. // onLoadProgress
  10024. // onLoadedMetadata
  10025. // onVideoDataChange
  10026. // onVideoProgress
  10027.  
  10028. }
  10029.  
  10030.  
  10031. let isAmended_Polymer_RenderStatus = false;
  10032.  
  10033. (FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  10034.  
  10035. const Polymer = await polymerObservable.obtain();
  10036. if (!Polymer) return;
  10037.  
  10038. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  10039. isAmended_Polymer_RenderStatus = true;
  10040.  
  10041. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  10042. let arrBefore = null, arrAfter = null;
  10043. const push = Array.prototype.push;
  10044. let arr = null;
  10045. Array.prototype.push = function () {
  10046. arr = this;
  10047. }
  10048. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  10049. if (arr) arrBefore = arr;
  10050. arr = null;
  10051. Polymer.RenderStatus.afterNextRender({}, {}, {});
  10052. if (arr) arrAfter = arr;
  10053. arr = null;
  10054. Array.prototype.push = push;
  10055. Polymer.RenderStatus.arrBefore = arrBefore;
  10056. Polymer.RenderStatus.arrAfter = arrAfter;
  10057.  
  10058. if (arrBefore && arrAfter) {
  10059.  
  10060. Function.prototype.call7900 = Function.prototype.call;
  10061. Function.prototype.apply7900 = Function.prototype.apply;
  10062. Function.prototype.apply7948 = function (obj, args) {
  10063. const f = this;
  10064. let m = kRef(obj);
  10065. if (!m) return;
  10066. if (m.is && !m.nodeName) {
  10067. if (!m.isAttached || !m.hostElement) {
  10068. return;
  10069. }
  10070. }
  10071. try {
  10072. return !args ? f.call7900(m) : f.apply7900(m, args);
  10073. } catch (e) {
  10074. console.warn(e);
  10075. }
  10076. return null;
  10077. }
  10078.  
  10079. arrBefore.push = arrAfter.push = function (a) {
  10080. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  10081. if (a[0].deref) a[0] = kRef(a[0]);
  10082. const f = a[1]
  10083. const obj = a[0]
  10084. const args = a[2];
  10085. f.apply = f.apply7948;
  10086. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  10087. a[0] = obj[wk]
  10088. // console.log(4992, a)
  10089. return push.call(this, a);
  10090. }
  10091.  
  10092. }
  10093.  
  10094.  
  10095. }
  10096. // Polymer.RenderStatus.beforeNextRender
  10097. }
  10098.  
  10099. if (FIX_Polymer_dom) {
  10100.  
  10101. const checkPDFuncValue = (pd) => {
  10102. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  10103. }
  10104. const checkPDFuncValue2 = (pd) => {
  10105. return pd && typeof pd.value == 'function'
  10106. }
  10107.  
  10108. const checkPDFuncGet = (pd) => {
  10109. return pd && typeof pd.get == 'function'
  10110. }
  10111.  
  10112. const domX = Polymer.dom(document.createElement('null'));
  10113. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  10114. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  10115. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  10116. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  10117. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  10118. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  10119. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  10120. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  10121. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  10122.  
  10123.  
  10124. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  10125.  
  10126. domXP.querySelector15 = domXP.querySelector;
  10127.  
  10128. const querySelectorFn = function (query) {
  10129. try {
  10130. const p = this.node;
  10131.  
  10132. if (p instanceof Document && p.isConnected === true) {
  10133. return pd4b.value.call(p, query);
  10134. }
  10135.  
  10136. } catch (e) { }
  10137. return this.querySelector15(query);
  10138. }
  10139.  
  10140. Object.defineProperty(domXP, 'querySelector', {
  10141. get() {
  10142. return querySelectorFn;
  10143. },
  10144. set(nv) {
  10145. if (nv === querySelectorFn) return true;
  10146. this.querySelector15 = nv;
  10147. return true;
  10148. },
  10149.  
  10150. enumerable: false,
  10151. configurable: true
  10152. });
  10153.  
  10154. Polymer.__fixedQuerySelector__ = 1;
  10155. }
  10156.  
  10157. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  10158.  
  10159. domXP.querySelectorAll15 = domXP.querySelectorAll;
  10160.  
  10161. const querySelectorAllFn = function (query) {
  10162.  
  10163. try {
  10164.  
  10165. const p = this.node;
  10166.  
  10167. if (p instanceof Document && p.isConnected === true) {
  10168. return pd6b.value.call(p, query);
  10169. }
  10170.  
  10171. } catch (e) {
  10172.  
  10173. }
  10174. return this.querySelectorAll15(query);
  10175. }
  10176.  
  10177. Object.defineProperty(domXP, 'querySelectorAll', {
  10178. get() {
  10179. return querySelectorAllFn;
  10180. },
  10181. set(nv) {
  10182. if (nv === querySelectorAllFn) return true;
  10183. this.querySelectorAll15 = nv;
  10184. return true;
  10185. },
  10186.  
  10187. enumerable: false,
  10188. configurable: true
  10189. });
  10190.  
  10191. Polymer.__fixedQuerySelectorAll__ = 1;
  10192. }
  10193. }
  10194.  
  10195.  
  10196. if (FIX_stampDomArray) {
  10197.  
  10198. Polymer.Base.__connInit__ = function () {
  10199. setupYtComponent(this);
  10200. }
  10201.  
  10202.  
  10203. /** @type {Function} */
  10204. const connectedCallbackK = function (...args) {
  10205. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10206. const r = this[qm53](...args);
  10207. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10208. this.mh35 = 1;
  10209. return r;
  10210. };
  10211.  
  10212. connectedCallbackK.m353 = 1;
  10213.  
  10214.  
  10215. const qt53 = Polymer.Base.connectedCallback;
  10216. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  10217.  
  10218. Polymer.Base.connectedCallback = connectedCallbackK;
  10219.  
  10220.  
  10221. /** @type {Function} */
  10222. const createdK = function (...args) {
  10223. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10224. const r = this[qn53](...args);
  10225. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10226. this.mh36 = 1;
  10227. return r;
  10228. };
  10229.  
  10230.  
  10231. createdK.m353 = 1;
  10232. Polymer.Base[qn53] = Polymer.Base.created;
  10233. Polymer.Base.created = createdK;
  10234.  
  10235.  
  10236.  
  10237.  
  10238.  
  10239.  
  10240.  
  10241.  
  10242.  
  10243.  
  10244.  
  10245. }
  10246.  
  10247. })();
  10248.  
  10249.  
  10250. /*
  10251.  
  10252. e.nativeAppendChild = d.prototype.appendChild,
  10253. d.prototype.appendChild = function(h) {
  10254. return function(l) {
  10255. if (l instanceof DocumentFragment) {
  10256. var m = Array.from(l.children);
  10257. l = h.nativeAppendChild.call(this, l);
  10258. if (this.isConnected) {
  10259. m = g(m);
  10260. for (var p = m.next(); !p.done; p = m.next())
  10261. YD(p.value)
  10262. }
  10263. return l
  10264. }
  10265. m = l instanceof Element && l.isConnected;
  10266. p = h.nativeAppendChild.call(this, l);
  10267. m && ZD(l);
  10268. this.isConnected && YD(l);
  10269. return p
  10270. }
  10271. }(e),
  10272.  
  10273. */
  10274.  
  10275. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  10276.  
  10277. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  10278. if (f) Node.prototype.appendChild = function (a) {
  10279. if (this instanceof Element) { // exclude DocumentFragment
  10280. try {
  10281. let checkFragmentA = (a instanceof DocumentFragment);
  10282. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  10283. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  10284. for (const node of headLinkCollection) {
  10285. if (node.rel === 'preload' && node.as === 'fetch') {
  10286. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  10287. }
  10288. }
  10289. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  10290. checkFragmentA = false;
  10291. }
  10292. if (checkFragmentA && a.firstElementChild === null) {
  10293. // no element in fragmentA
  10294. let doNormal = false;
  10295. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  10296. if (child.nodeType === 3) { doNormal = true; break; }
  10297. }
  10298. if (!doNormal) return a;
  10299. }
  10300. } catch (e) {
  10301. console.log(e);
  10302. }
  10303. }
  10304. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  10305. }
  10306.  
  10307. })();
  10308.  
  10309. if (FIX_Shady) {
  10310.  
  10311. observablePromise(() => {
  10312. const { ShadyDOM, ShadyCSS } = window;
  10313. if (ShadyDOM) {
  10314. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  10315. ShadyDOM.noPatch = true; // 1 of 10
  10316. ShadyDOM.patchOnDemand = false; // 1 of 10
  10317. ShadyDOM.preferPerformance = true; // 1 of 10
  10318. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  10319. }
  10320. if (ShadyCSS) {
  10321. ShadyCSS.nativeCss = true; // 1 of 10
  10322. ShadyCSS.nativeShadow = true; // 6 of 10
  10323. ShadyCSS.cssBuild = undefined; // 1 of 10
  10324. ShadyCSS.disableRuntime = true; // 1 of 10
  10325. }
  10326. if (ShadyDOM && ShadyCSS) return 1;
  10327. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  10328.  
  10329. }
  10330.  
  10331.  
  10332. // let schedulerInstancePropOfTimerType = '';
  10333. // let schedulerInstancePropOfTimerId = '';
  10334. (FIX_schedulerInstanceInstance & 2) && (async () => {
  10335.  
  10336. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  10337.  
  10338. if (!schedulerInstanceInstance_) return;
  10339.  
  10340. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  10341. if (checkOK) {
  10342.  
  10343. let resolveRendering = null;
  10344.  
  10345. let cmPr = new PromiseExternal();
  10346. const cm = document.createComment('0');
  10347. const cmObs = new MutationObserver(() => {
  10348. if (resolveRendering) {
  10349. resolveRendering();
  10350. resolveRendering = null;
  10351. }
  10352. cmPr.resolve();
  10353. cmPr = new PromiseExternal();
  10354. });
  10355. cmObs.observe(cm, {characterData: true})
  10356.  
  10357. let web_emulated_idle_callback_delay_val = null;
  10358.  
  10359. const getRenderIdleCallbackMs = () => {
  10360. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  10361. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  10362. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  10363. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  10364. return web_emulated_idle_callback_delay_val;
  10365. }
  10366. let isDelayRenderFn_firstCheck = true;
  10367. let isDelayRenderFn_key = null;
  10368. const isDelayRenderFn = (f) => {
  10369. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  10370. isDelayRenderFn_firstCheck = false;
  10371. if (typeof ytglobal === 'undefined') return false;
  10372. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  10373. if (!globalInstance) return false;
  10374. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  10375. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  10376. isDelayRenderFn_key = entry[0]
  10377. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  10378. return true;
  10379. }
  10380. }
  10381. return false;
  10382. }
  10383.  
  10384. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  10385.  
  10386. let requestingFn = null;
  10387. let requestingArgs = null;
  10388.  
  10389. const f = function () {
  10390. requestingFn = this.fn;
  10391. requestingArgs = [...arguments];
  10392. return 12373;
  10393. };
  10394.  
  10395. const fakeFns = [
  10396. f.bind({ fn: requestAnimationFrame }),
  10397. f.bind({ fn: setInterval }),
  10398. f.bind({ fn: setTimeout }),
  10399. f.bind({ fn: requestIdleCallback })
  10400. ];
  10401.  
  10402. let mzt = 0;
  10403.  
  10404. let _fnSelectorProp = null;
  10405. const mkFns = new Array(4);
  10406.  
  10407. /*
  10408. case 1:
  10409. var a = this.K;
  10410. this.g = this.I ? window.requestIdleCallback(a, {
  10411. timeout: 3E3
  10412. }) : window.setTimeout(a, ma);
  10413. break;
  10414. case 2:
  10415. this.g = window.setTimeout(this.M, this.N);
  10416. break;
  10417. case 3:
  10418. this.g = window.requestAnimationFrame(this.L);
  10419. break;
  10420. case 4:
  10421. this.g = window.setTimeout(this.J, 0)
  10422. }
  10423.  
  10424. */
  10425. const startFnHandler = {
  10426. get(target, prop, receiver) {
  10427. if (prop === '$$12377$$') return true;
  10428. if (prop === '$$12378$$') return target;
  10429.  
  10430. // console.log('get',prop)
  10431. return target[prop]
  10432. },
  10433. set(target, prop, value, receiver) {
  10434. // console.log('set', prop, value)
  10435.  
  10436.  
  10437. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  10438. if (value === 12373 && _fnSelectorProp) {
  10439.  
  10440. const schedulerTypeSelection = target[_fnSelectorProp];
  10441. const timerIdProp = prop;
  10442.  
  10443. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  10444. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  10445. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  10446. // schedulerInstancePropOfTimerId = timerIdProp || '';
  10447. // }
  10448.  
  10449. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  10450. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  10451. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  10452. // rare
  10453. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10454. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  10455. // often
  10456. if ((FIX_schedulerInstanceInstance & 4)) {
  10457. const f = requestingArgs[0];
  10458. const tir = ++mzt;
  10459. nextBrowserTick_(() => {
  10460. if (target[timerIdProp] === -tir) f();
  10461. });
  10462. target[_fnSelectorProp] = 940;
  10463. target[timerIdProp] = -tir;
  10464. } else {
  10465. const f = requestingArgs[0];
  10466. const tir = ++mzt;
  10467. Promise.resolve().then(() => {
  10468. if (target[timerIdProp] === -tir) f();
  10469. });
  10470. target[_fnSelectorProp] = 930;
  10471. target[timerIdProp] = -tir;
  10472. }
  10473. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  10474. // often
  10475. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  10476. cm.data = (cm.data & 7) + 1;
  10477. let renderFn = requestingArgs[0];
  10478. const resolveRendering_ = () => {
  10479. const renderFn_ = renderFn;
  10480. if (renderFn_) {
  10481. renderFn = null;
  10482. renderFn_();
  10483. }
  10484. };
  10485. resolveRendering = resolveRendering_;
  10486. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  10487. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  10488.  
  10489. // cm.data = (cm.data & 7) + 1;
  10490. // target[timerIdProp] = Math.random();
  10491.  
  10492. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  10493.  
  10494. cm.data = (cm.data & 7) + 1;
  10495.  
  10496. let renderFn = requestingArgs[0];
  10497. const resolveRendering_ = () => {
  10498. const renderFn_ = renderFn;
  10499. if (renderFn_) {
  10500. renderFn = null;
  10501. renderFn_();
  10502. }
  10503. };
  10504. resolveRendering = resolveRendering_;
  10505.  
  10506. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  10507.  
  10508.  
  10509. } else {
  10510. if (requestingFn === requestIdleCallback) {
  10511. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  10512. } else {
  10513. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10514. }
  10515. }
  10516. } else {
  10517. target[_fnSelectorProp] = 0;
  10518. target[timerIdProp] = 0;
  10519. }
  10520. } else {
  10521. target[prop] = value;
  10522. }
  10523. return true;
  10524. }
  10525. };
  10526.  
  10527. let startBusy = false;
  10528. schedulerInstanceInstance_.start = function () {
  10529. if (startBusy) return;
  10530. startBusy = true;
  10531. try {
  10532. mkFns[0] = window.requestAnimationFrame;
  10533. mkFns[1] = window.setInterval;
  10534. mkFns[2] = window.setTimeout;
  10535. mkFns[3] = window.requestIdleCallback;
  10536. const tThis = this['$$12378$$'] || this;
  10537. window.requestAnimationFrame = fakeFns[0]
  10538. window.setInterval = fakeFns[1]
  10539. window.setTimeout = fakeFns[2]
  10540. window.requestIdleCallback = fakeFns[3]
  10541. _fnSelectorProp = null;
  10542. tThis.start993.call(new Proxy(tThis, startFnHandler));
  10543. _fnSelectorProp = null;
  10544. window.requestAnimationFrame = mkFns[0];
  10545. window.setInterval = mkFns[1];
  10546. window.setTimeout = mkFns[2];
  10547. window.requestIdleCallback = mkFns[3];
  10548. } catch (e) {
  10549. console.warn(e);
  10550. }
  10551. startBusy = false;
  10552. }
  10553.  
  10554. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  10555.  
  10556. }
  10557. })();
  10558.  
  10559. FIX_yt_player && !isChatRoomURL && (async () => {
  10560.  
  10561. const fOption = 1 | 2 | 4;
  10562.  
  10563. const _yt_player = await _yt_player_observable.obtain();
  10564.  
  10565. if (!_yt_player || typeof _yt_player !== 'object') return;
  10566.  
  10567. const g = _yt_player;
  10568. let k;
  10569.  
  10570. if (fOption & 1) {
  10571.  
  10572. // rAf scheduling
  10573.  
  10574. const keyZqOu = getZqOu(_yt_player);
  10575. if (!keyZqOu) {
  10576. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  10577. return;
  10578. }
  10579. k = keyZqOu
  10580.  
  10581. const gk = g[k];
  10582. if (typeof gk !== 'function') {
  10583. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  10584. return;
  10585. }
  10586. const gkp = gk.prototype;
  10587.  
  10588. const dummyObject = new gk;
  10589. const nilFunc = () => { };
  10590.  
  10591. const nilObj = {};
  10592.  
  10593. // console.log(1111111111)
  10594.  
  10595. let keyBoolD = '';
  10596. let keyWindow = '';
  10597. let keyFuncC = '';
  10598. let keyCidj = '';
  10599.  
  10600. for (const [t, y] of Object.entries(dummyObject)) {
  10601. if (y instanceof Window) keyWindow = t;
  10602. }
  10603.  
  10604. const dummyObjectProxyHandler = {
  10605. get(target, prop) {
  10606. let v = target[prop]
  10607. if (v instanceof Window && !keyWindow) {
  10608. keyWindow = t;
  10609. }
  10610. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  10611. if (prop === keyWindow) y = {
  10612. requestAnimationFrame(f) {
  10613. return 3;
  10614. },
  10615. cancelAnimationFrame() {
  10616.  
  10617. }
  10618. }
  10619. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  10620. keyFuncC = prop;
  10621. }
  10622. // console.log('[get]', prop, typeof target[prop])
  10623.  
  10624.  
  10625. return y;
  10626. },
  10627. set(target, prop, value) {
  10628.  
  10629. if (typeof value === 'boolean' && !keyBoolD) {
  10630. keyBoolD = prop;
  10631. }
  10632. if (typeof value === 'number' && !keyCidj && value >= 2) {
  10633. keyCidj = prop;
  10634. }
  10635.  
  10636. // console.log('[set]', prop, value)
  10637. target[prop] = value;
  10638.  
  10639. return true;
  10640. }
  10641. };
  10642.  
  10643. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  10644.  
  10645. // console.log('gkp.start',gkp.start);
  10646. // console.log('gkp.stop',gkp.stop);
  10647. gkp._activation = false;
  10648.  
  10649. gkp.start = function () {
  10650. // p59 || console.log(12100)
  10651. if (!this._activation) {
  10652. this._activation = true;
  10653. foregroundPromiseFn().then(() => {
  10654. this._activation = false;
  10655. if (this[keyCidj]) {
  10656. Promise.resolve().then(this[keyFuncC]);
  10657. }
  10658. });
  10659. }
  10660. this[keyCidj] = 1;
  10661. this[keyBoolD] = true;
  10662. };
  10663.  
  10664. gkp.stop = function () {
  10665. this[keyCidj] = null;
  10666. };
  10667.  
  10668.  
  10669. /*
  10670. g[k].start = function() {
  10671. this.stop();
  10672. this.D = true;
  10673. var a = requestAnimationFrame
  10674. , b = cancelAnimationFrame;
  10675. this.j = a.call(this.B, this.C)
  10676. }
  10677. ;
  10678. g[k].stop = function() {
  10679. if (this.isActive()) {
  10680. var a = requestAnimationFrame
  10681. , b = cancelAnimationFrame;
  10682. b.call(this.B, this.j)
  10683. }
  10684. this.j = null
  10685. }
  10686. */
  10687. }
  10688.  
  10689. if (fOption & 2) {
  10690. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10691.  
  10692. if (keyzo) {
  10693.  
  10694. k = keyzo;
  10695.  
  10696. const attrUpdateFn = g[k];
  10697. // console.log(5992, attrUpdateFn)
  10698. g['$$original$$' + k] = attrUpdateFn;
  10699. const zoTransform = async (a, c) => {
  10700.  
  10701. let transformType = '';
  10702. let transformValue = 0;
  10703. let transformUnit = '';
  10704. let transformTypeI = 0;
  10705.  
  10706. const aStyle = a.style;
  10707.  
  10708. let cType = 0;
  10709.  
  10710. const cl = c.length;
  10711.  
  10712. if (cl >= 8) {
  10713. // scale(1)
  10714. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10715. cType = 1;
  10716. let t = c.charCodeAt(5);
  10717. if (t === 88 || t === 120) cType = 1 | 4;
  10718. if (t === 89 || t === 121) cType = 1 | 8;
  10719. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10720. cType = 2;
  10721. let t = c.charCodeAt(9);
  10722. if (t === 88 || t === 120) cType = 2 | 4;
  10723. if (t === 89 || t === 121) cType = 2 | 8;
  10724. }
  10725. let w = 0;
  10726. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10727. let p = c.substring(7, cl - 1);
  10728. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10729. if (typeof q === 'number' && !isNaNx(q)) {
  10730. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10731. transformValue = q;
  10732. transformUnit = '';
  10733. transformTypeI = 1;
  10734. } else {
  10735. cType = 256;
  10736. }
  10737. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10738. if (c.endsWith('px)')) {
  10739. let p = c.substring(11, cl - 3);
  10740. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10741. if (typeof q === 'number' && !isNaNx(q)) {
  10742. transformType = w === 1 ? 'translateX' : 'translateY';
  10743. transformValue = q;
  10744. transformUnit = 'px';
  10745. transformTypeI = 2;
  10746. } else if (p === 'NaN') {
  10747. return;
  10748. }
  10749. } else {
  10750. cType = 256;
  10751. }
  10752. } else if (cType > 0) {
  10753. cType = 256;
  10754. }
  10755. }
  10756.  
  10757.  
  10758. if (cType === 256) {
  10759. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10760. }
  10761.  
  10762. if (transformTypeI === 1) {
  10763. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10764. const vz = toFixed2(q, 3);
  10765. c = `${transformType}(${vz})`;
  10766. const cv = aStyle.transform;
  10767. if (c === cv) return;
  10768. aStyle.transform = c;
  10769. } else if (transformTypeI === 2) {
  10770. const q = transformValue;
  10771. const vz = toFixed2(q, 1);
  10772. c = `${transformType}(${vz}${transformUnit})`;
  10773. const cv = aStyle.transform;
  10774. if (c === cv) return;
  10775. aStyle.transform = c;
  10776. } else { // eg empty
  10777. const cv = aStyle.transform;
  10778. if (!c && !cv) return;
  10779. else if (c === cv) return;
  10780. aStyle.transform = c;
  10781. }
  10782.  
  10783. };
  10784.  
  10785. const elmTransformTemp = new WeakMap();
  10786. const elmPropTemps = {
  10787. 'display': new WeakMap(),
  10788. 'width': new WeakMap(),
  10789. 'height': new WeakMap(),
  10790. 'outlineWidth': new WeakMap(),
  10791. 'position': new WeakMap(),
  10792. 'padding': new WeakMap(),
  10793. "cssText": new WeakMap(),
  10794. "right": new WeakMap(),
  10795. "left": new WeakMap(),
  10796. "top": new WeakMap(),
  10797. "bottom": new WeakMap(),
  10798. "transitionDelay": new WeakMap(),
  10799. "marginLeft": new WeakMap(),
  10800. "marginTop": new WeakMap(),
  10801. "marginRight": new WeakMap(),
  10802. "marginBottom": new WeakMap(),
  10803. }
  10804.  
  10805. const ns5 = Symbol();
  10806. const nextModify = (a, c, m, f, immediate) => {
  10807. const a_ = a;
  10808. const m_ = m;
  10809. const noKey = !m_.has(a_);
  10810. if (immediate || noKey) {
  10811. m_.set(a_, ns5);
  10812. f(a_, c);
  10813. noKey && nextBrowserTick_(() => {
  10814. const d = m_.get(a_);
  10815. if (d === undefined) return;
  10816. m_.delete(a_);
  10817. if (d !== ns5) f(a_, d);
  10818. });
  10819. } else {
  10820. m_.set(a_, c);
  10821. }
  10822. };
  10823.  
  10824. const set66 = new Set();
  10825. const log77 = new Map();
  10826. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10827.  
  10828. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10829.  
  10830. // console.log(140000, a, b, c);
  10831. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10832. const num = c;
  10833. c = `${num}`;
  10834. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10835. }
  10836.  
  10837. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10838.  
  10839. let elmPropTemp = null;
  10840.  
  10841. if (b === "transform") {
  10842. // div.ytp-hover-progress.ytp-hover-progress-light
  10843. // div.ytp-play-progress.ytp-swatch-background-color
  10844.  
  10845. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10846. return;
  10847.  
  10848. } else if (elmPropTemp = elmPropTemps[b]) {
  10849.  
  10850. // if (c.length > 5 && c.includes('.')) {
  10851. // console.log(123213, c)
  10852. // }
  10853.  
  10854. const b_ = b;
  10855. nextModify(a, c, elmPropTemp, (a, c) => {
  10856. const style = a.style;
  10857. const cv = style[b_];
  10858. if (!cv && !c) return;
  10859. if (cv === c) return;
  10860. style[b_] = c;
  10861. }, immediateChange);
  10862. return;
  10863.  
  10864. } else if (b === "outline-width") {
  10865.  
  10866. const b_ = 'outlineWidth';
  10867. elmPropTemp = elmPropTemps[b_];
  10868. nextModify(a, c, elmPropTemp, (a, c) => {
  10869. const style = a.style;
  10870. const cv = style[b_];
  10871. if (!cv && !c) return;
  10872. if (cv === c) return;
  10873. style[b_] = c;
  10874. }, immediateChange);
  10875. return;
  10876.  
  10877. } else if (b === 'maxWidth' || b === 'maxHeight') {
  10878. // I think these can be directly assigned.
  10879.  
  10880. const b_ = b;
  10881. const style = a.style;
  10882. const cv = style[b_];
  10883. if (!cv && !c) return;
  10884. if (cv === c) return;
  10885. style[b_] = c;
  10886. return;
  10887.  
  10888. } else {
  10889. // if(immediate && elmPropTemps[b]){
  10890. // console.log(5191, b)
  10891. // }
  10892. // caption-window
  10893. // margin-left max-height max-width font-family fill color font-size background white-space margin
  10894. // text-align background-color
  10895. // console.log(27304, a, b, c)
  10896. if (!set66.has(b)) {
  10897. set66.add(b);
  10898. nextBrowserTick_(() => {
  10899. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  10900. console.log(27304, a, b, c)
  10901. }
  10902. })
  10903. }
  10904. }
  10905.  
  10906. attrUpdateFn.call(this, a, b, c);
  10907. return;
  10908. } else if (typeof (b || 0) === 'object') {
  10909.  
  10910. // this is to fix caption positioning
  10911. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  10912. const immediate = (a.id || 0).length > 14;
  10913. for (const [k, v] of Object.entries(b)) {
  10914. modifiedFn.call(this, a, k, v, immediate);
  10915. }
  10916.  
  10917. } else {
  10918.  
  10919. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  10920. // ytp-ad-timed-pie-countdown-inner
  10921.  
  10922. if (typeof b === 'string') {
  10923.  
  10924. let m = log77.get(b);
  10925. if (!m) {
  10926. m = [];
  10927. console.log('attrUpdateFn.debug.27304', m);
  10928. log77.set(b, m);
  10929. }
  10930. m.push([a, b, c]);
  10931.  
  10932. } else {
  10933. console.log('attrUpdateFn.debug.27306', a, b, c);
  10934. }
  10935.  
  10936. attrUpdateFn.call(this, a, b, c);
  10937. return;
  10938. }
  10939.  
  10940. // console.log(130000, a, b, c);
  10941.  
  10942. };
  10943. g[k] = modifiedFn;
  10944.  
  10945.  
  10946. /*
  10947.  
  10948. g.zo = function(a, b, c) {
  10949. if ("string" === typeof b)
  10950. (b = yo(a, b)) && (a.style[b] = c);
  10951. else
  10952. for (var d in b) {
  10953. c = a;
  10954. var e = b[d]
  10955. , f = yo(c, d);
  10956. f && (c.style[f] = e)
  10957. }
  10958. }
  10959.  
  10960.  
  10961. */
  10962.  
  10963.  
  10964. }
  10965. }
  10966.  
  10967. if (fOption & 4) {
  10968. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  10969.  
  10970. if (keyuG) {
  10971.  
  10972. k = keyuG;
  10973.  
  10974. const gk = g[k];
  10975. const gkp = gk.prototype;
  10976.  
  10977.  
  10978. /** @type { Map<string, WeakMap<any, any>> } */
  10979. const ntLogs = new Map();
  10980.  
  10981. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  10982.  
  10983. gkp.updateValue31 = gkp.updateValue;
  10984. gkp.updateValue = function (a, b) {
  10985. if (typeof a !== 'string') return this.updateValue31(a, b);
  10986.  
  10987. const element = this.element;
  10988. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  10989.  
  10990. let ntLog = ntLogs.get(a);
  10991. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  10992.  
  10993. let cache = ntLog.get(element);
  10994. if (cache && cache.value === b) {
  10995. return;
  10996. }
  10997. if (!cache) {
  10998. this.__oldValueByUpdateValue__ = null;
  10999. ntLog.set(element, cache = { value: b });
  11000. } else {
  11001. this.__oldValueByUpdateValue__ = cache.value;
  11002. cache.value = b;
  11003. }
  11004.  
  11005. return this.updateValue31(a, b);
  11006. }
  11007.  
  11008. /*
  11009. g.k.update = function(a) {
  11010. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  11011. c = c.value,
  11012. this.updateValue(c, a[c])
  11013. }
  11014. ;
  11015. g.k.updateValue = function(a, b) {
  11016. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  11017. }
  11018. */
  11019.  
  11020. }
  11021.  
  11022.  
  11023. }
  11024. }
  11025.  
  11026.  
  11027.  
  11028. })();
  11029.  
  11030.  
  11031. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  11032. // keyboard shortcut keys controller
  11033.  
  11034. const _yt_player = await _yt_player_observable.obtain();
  11035.  
  11036. if (!_yt_player || typeof _yt_player !== 'object') return;
  11037.  
  11038. keyboardController(_yt_player);
  11039.  
  11040. })();
  11041.  
  11042. FIX_yt_player && !isChatRoomURL && (async () => {
  11043. // timer scheduling
  11044.  
  11045. const _yt_player = await _yt_player_observable.obtain();
  11046.  
  11047. if (!_yt_player || typeof _yt_player !== 'object') return;
  11048.  
  11049. let keyZqQu = getZqQu(_yt_player);
  11050.  
  11051. if (!keyZqQu) return;
  11052.  
  11053. const g = _yt_player
  11054. let k = keyZqQu
  11055.  
  11056. const gk = g[k];
  11057. if (typeof gk !== 'function') return;
  11058. const gkp = gk.prototype;
  11059.  
  11060. const extractKeysZqQu = () => {
  11061.  
  11062.  
  11063. let _keyeC = '';
  11064. try {
  11065. gkp.stop.call(new Proxy({
  11066. isActive: () => { }
  11067. }, {
  11068. set(target, prop, value) {
  11069. if (value === 0) _keyeC = prop;
  11070. return true;
  11071. }
  11072. }));
  11073. } catch (e) { }
  11074. if (!_keyeC) return;
  11075. const keyeC = _keyeC;
  11076.  
  11077. let keyC = ''; // this.C = this.ST.bind(this)
  11078. let keyhj = ''; // 1000ms
  11079. try {
  11080. gkp.start.call(new Proxy({
  11081. stop: () => { },
  11082. [keyeC]: 0,
  11083. }, {
  11084. get(target, prop) {
  11085. if (prop in target) return target[prop];
  11086. if (!keyC) {
  11087. keyC = prop;
  11088. return null; // throw error
  11089. }
  11090. else if (!keyhj) {
  11091. keyhj = prop;
  11092. }
  11093.  
  11094. }
  11095. }));
  11096. } catch (e) {
  11097. if (!keyC || !keyhj) {
  11098. console.log(e)
  11099. }
  11100. }
  11101.  
  11102. if (!keyC || !keyhj) return;
  11103. let keyST = '';
  11104. let keyj = '';
  11105. let keyB = '';
  11106. let keyxa = '';
  11107.  
  11108. const possibleKs = new Set();
  11109.  
  11110. for (const [k, v] of Object.entries(gkp)) {
  11111. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  11112. continue;
  11113. }
  11114. if (typeof v === 'function') {
  11115. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  11116. if (m) {
  11117. keyST = k;
  11118. keyj = m[1];
  11119. keyB = m[2];
  11120. } else {
  11121. possibleKs.add(k);
  11122. }
  11123. }
  11124. }
  11125.  
  11126. if (!keyST || !keyj || !keyB) return;
  11127.  
  11128. for (const k of possibleKs) {
  11129. if (k === keyST || k === keyj || k === keyB) {
  11130. continue;
  11131. }
  11132. const v = gkp[k];
  11133. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  11134. keyxa = k;
  11135. }
  11136. }
  11137.  
  11138. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  11139.  
  11140. }
  11141.  
  11142. const keys = extractKeysZqQu();
  11143. if (!keys || !keys.length) return;
  11144. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  11145.  
  11146. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  11147.  
  11148. let disposeKeys = null;
  11149.  
  11150. gkp[keyxa] = function () {
  11151. // dispose
  11152. if (!disposeKeys) {
  11153. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  11154. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  11155. const t = typeof this[key];
  11156. return t === 'undefined' || t === 'object'
  11157. }
  11158. return false;
  11159. });
  11160. }
  11161. for (const key of disposeKeys) {
  11162. const v = this[key];
  11163. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  11164. }
  11165. if (this[keyeC] > 0) this.stop();
  11166. this[keyj] = null;
  11167. this[keyB] = null;
  11168. };
  11169.  
  11170. gkp.start = function (a) {
  11171. if (this[keyeC] > 0) this.stop();
  11172. const delay = void 0 !== a ? a : this[keyhj];
  11173. this[keyeC] = window.setTimeout(this[keyC], delay);
  11174. };
  11175. gkp.stop = function () {
  11176. if (this[keyeC] > 0) {
  11177. window.clearTimeout(this[keyeC]);
  11178. this[keyeC] = 0;
  11179. }
  11180. };
  11181.  
  11182. gkp.isActive = function () {
  11183. return this[keyeC] > 0;
  11184. };
  11185.  
  11186. gkp[keyST] = function () {
  11187. this.stop(); // this[keyeC] = 0;
  11188. const fn = this[keyj];
  11189. const obj = this[keyB];
  11190. let skip = false;
  11191. if (!fn) skip = true;
  11192. else if (IGNORE_bufferhealth_CHECK && obj) {
  11193. let m;
  11194. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  11195. if (m.has("bufferhealth")) skip = true;
  11196. }
  11197. }
  11198. if (!skip) {
  11199. fn.call(obj);
  11200. }
  11201. };
  11202.  
  11203.  
  11204.  
  11205.  
  11206. /*
  11207.  
  11208. g.k.eC = 0;
  11209. g.k.xa = function() {
  11210. g.Qu.Vf.xa.call(this);
  11211. this.stop();
  11212. delete this.j;
  11213. delete this.B
  11214. }
  11215. ;
  11216. g.k.start = function(a) {
  11217. this.stop();
  11218. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  11219. }
  11220. ;
  11221. g.k.stop = function() {
  11222. this.isActive() && g.Sa.clearTimeout(this.eC);
  11223. this.eC = 0
  11224. }
  11225. ;
  11226. g.k.isActive = function() {
  11227. return 0 != this.eC
  11228. }
  11229. ;
  11230. g.k.ST = function() {
  11231. this.eC = 0;
  11232. this.j && this.j.call(this.B)
  11233. }
  11234. ;
  11235. */
  11236.  
  11237.  
  11238.  
  11239.  
  11240. })();
  11241.  
  11242. FIX_Animation_n_timeline && (async () => {
  11243.  
  11244. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  11245.  
  11246. if (!timeline || !Animation) return;
  11247.  
  11248. const animationsFix = (timeline) => {
  11249. const animations = (timeline || 0)._animations || 0;
  11250. const c = animations[0];
  11251. if (c) {
  11252. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  11253. animations.shift(); // keep animating but no looping
  11254. // c.effect.remove();
  11255. }
  11256. }
  11257. }
  11258.  
  11259. const aniProto = Animation.prototype;
  11260. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  11261.  
  11262. const getXroto = (x) => {
  11263. try {
  11264. return x.__proto__;
  11265. } catch (e) { }
  11266. return null;
  11267. }
  11268. const timProto = getXroto(timeline);
  11269. if (!timProto) return;
  11270. if (
  11271. (
  11272. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  11273. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  11274. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  11275. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  11276. )
  11277.  
  11278. ) {
  11279.  
  11280. timProto.nofCQ = 1;
  11281. aniProto.nofYH = 1;
  11282.  
  11283. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  11284.  
  11285.  
  11286. /*
  11287. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11288. return c._updatePromises();
  11289. });
  11290. */
  11291.  
  11292. const p = Array.prototype.filter;
  11293.  
  11294. let res = null;
  11295. Array.prototype.filter = function () {
  11296.  
  11297. res = this;
  11298. return this;
  11299.  
  11300. };
  11301.  
  11302. _updateAnimationsPromises.call({});
  11303.  
  11304. Array.prototype.filter = p;
  11305.  
  11306. if (res && typeof res.length === 'number') {
  11307. /** @type {any[]} */
  11308. const _res = res;
  11309. return _res;
  11310. }
  11311.  
  11312.  
  11313. return null;
  11314.  
  11315.  
  11316.  
  11317.  
  11318. })(timProto._updateAnimationsPromises);
  11319.  
  11320. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  11321.  
  11322. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  11323.  
  11324. aniProto._updatePromises31 = aniProto._updatePromises;
  11325.  
  11326. /*
  11327. aniProto._updatePromises = function(){
  11328. console.log('eff',this._oldPlayState, this.playState)
  11329. return this._updatePromises31.apply(this, arguments)
  11330. }
  11331. */
  11332.  
  11333. aniProto._updatePromises = function () {
  11334. var oldPlayState = this._oldPlayState;
  11335. var newPlayState = this.playState;
  11336. // console.log('ett', oldPlayState, newPlayState)
  11337. if (newPlayState !== oldPlayState) {
  11338. this._oldPlayState = newPlayState;
  11339. if (this._readyPromise) {
  11340. if ("idle" == newPlayState) {
  11341. this._rejectReadyPromise();
  11342. this._readyPromise = void 0;
  11343. } else if ("pending" == oldPlayState) {
  11344. this._resolveReadyPromise();
  11345. } else if ("pending" == newPlayState) {
  11346. this._readyPromise = void 0;
  11347. }
  11348. }
  11349. if (this._finishedPromise) {
  11350. if ("idle" == newPlayState) {
  11351. this._rejectFinishedPromise();
  11352. this._finishedPromise = void 0;
  11353. } else if ("finished" == newPlayState) {
  11354. this._resolveFinishedPromise();
  11355. } else if ("finished" == oldPlayState) {
  11356. this._finishedPromise = void 0;
  11357. }
  11358. }
  11359. }
  11360. return this._readyPromise || this._finishedPromise;
  11361. };
  11362.  
  11363.  
  11364. let restartWebAnimationsNextTickFlag = false;
  11365.  
  11366. const looperMethodT = () => {
  11367.  
  11368. const runnerFn = (hRes) => {
  11369. var b = timeline;
  11370. b.currentTime = hRes;
  11371. b._discardAnimations();
  11372. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11373. if (0 == b._animations.length) {
  11374. restartWebAnimationsNextTickFlag = false;
  11375. } else {
  11376. getRafPromise().then(runnerFn);
  11377. }
  11378. }
  11379.  
  11380. const restartWebAnimationsNextTick = () => {
  11381. if (!restartWebAnimationsNextTickFlag) {
  11382. restartWebAnimationsNextTickFlag = true;
  11383. getRafPromise().then(runnerFn);
  11384. }
  11385. }
  11386.  
  11387. return { restartWebAnimationsNextTick }
  11388. };
  11389.  
  11390.  
  11391. const looperMethodN = () => {
  11392.  
  11393. const acs = document.createElement('a-f');
  11394. acs.id = 'a-f';
  11395.  
  11396. if (!document.getElementById('afscript')) {
  11397. const style = document.createElement('style');
  11398. style.id = 'afscript';
  11399. style.textContent = `
  11400. @keyFrames aF1 {
  11401. 0% {
  11402. order: 0;
  11403. }
  11404. 100% {
  11405. order: 1;
  11406. }
  11407. }
  11408. #a-f[id] {
  11409. visibility: collapse !important;
  11410. position: fixed !important;
  11411. display: block !important;
  11412. top: -100px !important;
  11413. left: -100px !important;
  11414. margin:0 !important;
  11415. padding:0 !important;
  11416. outline:0 !important;
  11417. border:0 !important;
  11418. z-index:-1 !important;
  11419. width: 0px !important;
  11420. height: 0px !important;
  11421. contain: strict !important;
  11422. pointer-events: none !important;
  11423. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  11424. }
  11425. `;
  11426. (document.head || document.documentElement).appendChild(style);
  11427. }
  11428.  
  11429. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  11430.  
  11431. const _onanimationiteration = function (evt) {
  11432. const hRes = evt.timeStamp;
  11433. var b = timeline;
  11434. b.currentTime = hRes;
  11435. b._discardAnimations();
  11436. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11437. if (0 == b._animations.length) {
  11438. restartWebAnimationsNextTickFlag = false;
  11439. acs.onanimationiteration = null;
  11440. } else {
  11441. acs.onanimationiteration = _onanimationiteration;
  11442. }
  11443.  
  11444. }
  11445.  
  11446.  
  11447.  
  11448. const restartWebAnimationsNextTick = () => {
  11449. if (!restartWebAnimationsNextTickFlag) {
  11450. restartWebAnimationsNextTickFlag = true;
  11451. acs.onanimationiteration = _onanimationiteration;
  11452.  
  11453. }
  11454. }
  11455.  
  11456. return { restartWebAnimationsNextTick }
  11457. };
  11458.  
  11459.  
  11460.  
  11461. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  11462.  
  11463.  
  11464. // console.log(571, timProto);
  11465. timProto._play = function (c) {
  11466. c = new Animation(c, this);
  11467. this._animations.push(c);
  11468. restartWebAnimationsNextTick();
  11469. c._updatePromises();
  11470. c._animation.play();
  11471. c._updatePromises();
  11472. return c
  11473. }
  11474.  
  11475. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  11476. originalAnimationsWithPromises.length = 0;
  11477. originalAnimationsWithPromises.push = null;
  11478. originalAnimationsWithPromises.splice = null;
  11479. originalAnimationsWithPromises.slice = null;
  11480. originalAnimationsWithPromises.indexOf = null;
  11481. originalAnimationsWithPromises.unshift = null;
  11482. originalAnimationsWithPromises.shift = null;
  11483. originalAnimationsWithPromises.pop = null;
  11484. originalAnimationsWithPromises.filter = null;
  11485. originalAnimationsWithPromises.forEach = null;
  11486. originalAnimationsWithPromises.map = null;
  11487.  
  11488.  
  11489. const _updateAnimationsPromises = () => {
  11490. animationsWithPromisesMap.forEach(c => {
  11491. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  11492. });
  11493. /*
  11494. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11495. return c._updatePromises();
  11496. });
  11497. */
  11498. }
  11499.  
  11500. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  11501.  
  11502. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  11503.  
  11504. delete timProto._updateAnimationsPromises;
  11505. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  11506. get() {
  11507. if (animationsWithPromisesMap.size === 0) return nilFn;
  11508. return _updateAnimationsPromises;
  11509. },
  11510. set(nv) {
  11511. delete this._updateAnimationsPromises;
  11512. this._updateAnimationsPromises = nv;
  11513. },
  11514. enumerable: true,
  11515. configurable: true,
  11516. });
  11517.  
  11518.  
  11519. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  11520. aniProto.__finished_native_get__ = pdFinished.get;
  11521. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  11522.  
  11523.  
  11524. Object.defineProperty(aniProto, 'finished', {
  11525. get() {
  11526. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11527. this._finishedPromise = new Promise((resolve, reject) => {
  11528. this._resolveFinishedPromise = function () {
  11529. resolve(this)
  11530. };
  11531. this._rejectFinishedPromise = function () {
  11532. reject({
  11533. type: DOMException.ABORT_ERR,
  11534. name: "AbortError"
  11535. })
  11536. };
  11537. }),
  11538. "finished" == this.playState && this._resolveFinishedPromise());
  11539. return this._finishedPromise
  11540. },
  11541. set: undefined,
  11542. enumerable: true,
  11543. configurable: true
  11544. });
  11545.  
  11546. }
  11547.  
  11548.  
  11549.  
  11550. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  11551. aniProto.__ready_native_get__ = pdReady.get;
  11552. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  11553.  
  11554. Object.defineProperty(aniProto, 'ready', {
  11555. get() {
  11556. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11557. this._readyPromise = new Promise((resolve, reject) => {
  11558. this._resolveReadyPromise = function () {
  11559. resolve(this)
  11560. };
  11561. this._rejectReadyPromise = function () {
  11562. reject({
  11563. type: DOMException.ABORT_ERR,
  11564. name: "AbortError"
  11565. })
  11566. };
  11567. }),
  11568. "pending" !== this.playState && this._resolveReadyPromise());
  11569. return this._readyPromise
  11570. },
  11571. set: undefined,
  11572. enumerable: true,
  11573. configurable: true
  11574. });
  11575.  
  11576. }
  11577.  
  11578.  
  11579. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  11580.  
  11581. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  11582. const _rebuildUnderlyingAnimation = function () {
  11583. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  11584. this.effect && this.effect._onsample && (this.effect._onsample = null);
  11585. return this._rebuildUnderlyingAnimation21();
  11586. }
  11587. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  11588. // delete aniProto._rebuildUnderlyingAnimation;
  11589. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  11590. // get() {
  11591. // if (isNaN(this._sequenceNumber)) return nilFn;
  11592. // return this._rebuildUnderlyingAnimation21;
  11593. // },
  11594. // set(nv) {
  11595. // delete this._rebuildUnderlyingAnimation;
  11596. // this._rebuildUnderlyingAnimation = nv;
  11597. // },
  11598. // enumerable: true,
  11599. // configurable: true
  11600. // });
  11601. }
  11602.  
  11603.  
  11604. /*
  11605.  
  11606.  
  11607. function f(c) {
  11608. var b = v.timeline;
  11609. b.currentTime = c;
  11610. b._discardAnimations();
  11611. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  11612. }
  11613. var h = window.requestAnimationFrame;
  11614. window.requestAnimationFrame = function(c) {
  11615. return h(function(b) {
  11616. v.timeline._updateAnimationsPromises();
  11617. c(b);
  11618. v.timeline._updateAnimationsPromises()
  11619. })
  11620. }
  11621. ;
  11622. v.AnimationTimeline = function() {
  11623. this._animations = [];
  11624. this.currentTime = void 0
  11625. }
  11626. ;
  11627. v.AnimationTimeline.prototype = {
  11628. getAnimations: function() {
  11629. this._discardAnimations();
  11630. return this._animations.slice()
  11631. },
  11632. _updateAnimationsPromises: function() {
  11633. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  11634. return c._updatePromises()
  11635. })
  11636. },
  11637. _discardAnimations: function() {
  11638. this._updateAnimationsPromises();
  11639. this._animations = this._animations.filter(function(c) {
  11640. return "finished" != c.playState && "idle" != c.playState
  11641. })
  11642. },
  11643. _play: function(c) {
  11644. c = new v.Animation(c,this);
  11645. this._animations.push(c);
  11646. v.restartWebAnimationsNextTick();
  11647. c._updatePromises();
  11648. c._animation.play();
  11649. c._updatePromises();
  11650. return c
  11651. },
  11652. play: function(c) {
  11653. c && c.remove();
  11654. return this._play(c)
  11655. }
  11656. };
  11657. var d = !1;
  11658. v.restartWebAnimationsNextTick = function() {
  11659. d || (d = !0,
  11660. requestAnimationFrame(f))
  11661. }
  11662. ;
  11663. var a = new v.AnimationTimeline;
  11664. v.timeline = a;
  11665. try {
  11666. Object.defineProperty(window.document, "timeline", {
  11667. configurable: !0,
  11668. get: function() {
  11669. return a
  11670. }
  11671. })
  11672. } catch (c) {}
  11673. try {
  11674. window.document.timeline = a
  11675. } catch (c) {}
  11676.  
  11677. */
  11678.  
  11679.  
  11680.  
  11681. /*
  11682.  
  11683. var g = window.getComputedStyle;
  11684. Object.defineProperty(window, "getComputedStyle", {
  11685. configurable: !0,
  11686. enumerable: !0,
  11687. value: function() {
  11688. v.timeline._updateAnimationsPromises();
  11689. var e = g.apply(this, arguments);
  11690. h() && (e = g.apply(this, arguments));
  11691. v.timeline._updateAnimationsPromises();
  11692. return e
  11693. }
  11694. });
  11695.  
  11696. */
  11697.  
  11698.  
  11699.  
  11700.  
  11701. }
  11702.  
  11703.  
  11704.  
  11705.  
  11706. })();
  11707.  
  11708. !isUrlInEmbed && Promise.resolve().then(() => {
  11709.  
  11710. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11711.  
  11712.  
  11713.  
  11714. class LimitedSizeSet extends Set {
  11715. constructor(n) {
  11716. super();
  11717. this.limit = n;
  11718. }
  11719.  
  11720. add(key) {
  11721. if (!super.has(key)) {
  11722. super.add(key);
  11723. let n = super.size - this.limit;
  11724. if (n > 0) {
  11725. const iterator = super.values();
  11726. do {
  11727. const firstKey = iterator.next().value; // Get the first (oldest) key
  11728. super.delete(firstKey); // Delete the oldest key
  11729. } while (--n > 0)
  11730. }
  11731. }
  11732. }
  11733.  
  11734. removeAdd(key) {
  11735. super.delete(key);
  11736. this.add(key);
  11737. }
  11738.  
  11739. }
  11740.  
  11741. // const wk3 = new WeakMap();
  11742.  
  11743. // let mtxVideoId = '';
  11744. // let aje3 = [];
  11745. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11746. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11747. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11748. let mtzCount = 0; // the key keeps unchanged
  11749. // let mjtNextMainKey = '';
  11750. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11751. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11752. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11753. // let allowNoDelay322=false;
  11754. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11755.  
  11756. let mpKey22 = ''; // last success continutation key & url pair
  11757. let mpUrl22 = ''; // last success continutation key & url pair
  11758. let mpKey21 = ''; // latest requested continutation key & url pair
  11759. let mpUrl21 = ''; // latest requested continutation key & url pair
  11760.  
  11761.  
  11762. async function sha1Hex(message) {
  11763. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11764. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11765. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11766. const hashHex = hashArray
  11767. .map((b) => b.toString(16).padStart(2, "0"))
  11768. .join(""); // convert bytes to hex string
  11769. return hashHex;
  11770. }
  11771.  
  11772. async function continuationLog(a, ...args) {
  11773. let b = a;
  11774. try {
  11775. if (advanceLogging) b = await sha1Hex(a);
  11776. let c = args.map(e => {
  11777. return e === a ? b : e
  11778. });
  11779. console.log(...c)
  11780. } catch (e) { console.warn(e) }
  11781. }
  11782.  
  11783. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11784.  
  11785.  
  11786. if (mfvContinuationRecorded.length > 0) {
  11787. for (const [e, d] of mfvContinuationRecorded) {
  11788. mfyContinuationIgnored.removeAdd(e);
  11789. }
  11790. toClearRecorded && mfvContinuationRecorded.clear();
  11791. }
  11792.  
  11793. }
  11794.  
  11795. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11796.  
  11797. const tmProto = taskMgr.constructor.prototype;
  11798. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11799.  
  11800. if (!tmProto.addJob714) {
  11801.  
  11802. tmProto.addJob714 = tmProto.addJob;
  11803.  
  11804. tmProto.addJob = function (a, b, c) {
  11805. const jobId = this.addJob714(a, b, c);
  11806. if (jobId > 0) {
  11807. // const ez = wk3.get(this);
  11808. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11809. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11810.  
  11811. this.__lastJobId863__ = jobId;
  11812. }
  11813. return jobId;
  11814. }
  11815.  
  11816. }
  11817.  
  11818. if (!tmProto.cancelJob714) {
  11819.  
  11820. tmProto.cancelJob714 = tmProto.cancelJob;
  11821.  
  11822. tmProto.cancelJob = function (a) {
  11823. const res = this.cancelJob714(a);
  11824. // if (a > 0) {
  11825. // for (const e of aje3) {
  11826. // if (e.jobId === a) e.cancelled = true;
  11827. // }
  11828. // }
  11829. return res;
  11830. }
  11831.  
  11832. }
  11833.  
  11834. }
  11835. }
  11836.  
  11837.  
  11838. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11839.  
  11840.  
  11841. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11842. let dummy;
  11843. let cProto;
  11844. // let mc = 4;
  11845. // dummy = await observablePromise(() => {
  11846. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11847. // if (!r) return;
  11848. // let cProto = insp(r).constructor.prototype;
  11849. // if (cProto.fetchUpdatedMetadata) return r;
  11850. // if (--mc < 0) return -1;
  11851. // return null;
  11852. // }).obtain();
  11853. dummy = document.createElement('ytd-video-primary-info-renderer');
  11854. if (!(dummy instanceof Element)) return;
  11855. // console.log(5022, dummy)
  11856. cProto = insp(dummy).constructor.prototype;
  11857.  
  11858. cProto.__getEmittorTaskMgr859__ = function () {
  11859. let taskMgr_ = null;
  11860. try {
  11861. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  11862. } catch (e) { }
  11863. return taskMgr_;
  11864. }
  11865. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  11866. // console.log(1234, cProto, cProto.is)
  11867. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  11868.  
  11869. let c_;
  11870. cProto.fetchUpdatedMetadata718 = function (a) {
  11871. // delay or immediate call the actual fetchUpdatedMetadata
  11872.  
  11873. let doImmediately = false;
  11874. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  11875.  
  11876. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  11877.  
  11878. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  11879.  
  11880. doImmediately = true;
  11881.  
  11882. }
  11883.  
  11884. if (mbCId322) {
  11885. clearTimeout(mbCId322);
  11886. mbCId322 = 0;
  11887. }
  11888.  
  11889. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  11890.  
  11891. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  11892.  
  11893. mbCId322 = setTimeout(() => {
  11894. this.fetchUpdatedMetadata717(a);
  11895. }, delay);
  11896.  
  11897. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  11898.  
  11899. }
  11900.  
  11901. cProto.fetchUpdatedMetadata = function (a) {
  11902.  
  11903. if (!pageSetupState) {
  11904. if (c_) clearTimeout(c_);
  11905. c_ = setTimeout(() => {
  11906. this.fetchUpdatedMetadata718(a);
  11907. }, 300);
  11908. return;
  11909. }
  11910.  
  11911. // pageSetupState == 0
  11912.  
  11913. try {
  11914.  
  11915. mbDelayBelowNCalls++;
  11916.  
  11917. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  11918. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  11919. }
  11920.  
  11921. // console.log('fum377', a)
  11922. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  11923. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  11924. return;
  11925. }
  11926.  
  11927. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  11928. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  11929. mjtLockPreviousKey = mjtRecordedPrevKey;
  11930. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  11931. }
  11932. // mjtNextMainKey = true;
  11933. mtzlastAllowedContinuation = '';
  11934. mtzCount = 0;
  11935. // allowNoDelay322 = false;
  11936. // fetch new metadata, cancel all previous continuations
  11937. copyPreviousContiuationToIgnored374(true);
  11938. } else if (typeof a === 'string') {
  11939. const videoPlayingId = videoPlayingY.videoId;
  11940.  
  11941. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  11942.  
  11943. let update21 = !!pageSetupVideoId;
  11944. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  11945. update21 = true;
  11946. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  11947. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  11948. return;
  11949. }
  11950. if (update21) {
  11951. mpKey21 = a;
  11952. mpUrl21 = pageSetupVideoId || videoPlayingId;
  11953. }
  11954.  
  11955. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  11956. }
  11957. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  11958. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  11959. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  11960. return this.fetchUpdatedMetadata718(a);
  11961.  
  11962. } catch (e) {
  11963. console.log('Code Error in fetchUpdatedMetadata', e);
  11964. }
  11965. return this.fetchUpdatedMetadata717(a)
  11966. }
  11967. }
  11968.  
  11969.  
  11970. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  11971. // console.log(1234, cProto, cProto.is)
  11972. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  11973. let mJob = null;
  11974.  
  11975. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  11976.  
  11977. try {
  11978.  
  11979. if (arguments.length > 0) {
  11980. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  11981. }
  11982. // mfy = mfv;
  11983.  
  11984. // mjtNextMainKey = '';
  11985. mtzlastAllowedContinuation = '';
  11986. mtzCount = 0;
  11987. if (mbCId322) {
  11988. clearTimeout(mbCId322);
  11989. mbCId322 = 0;
  11990. }
  11991. mbDelayBelowNCalls = 0;
  11992. // allowNoDelay322 = false;
  11993. copyPreviousContiuationToIgnored374(true);
  11994.  
  11995. const taskMgr = this.__getEmittorTaskMgr859__();
  11996. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  11997. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  11998. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  11999. }
  12000.  
  12001. // prevent depulicated schedule job by clearing previous JobId
  12002. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  12003.  
  12004. let res;
  12005.  
  12006. if (mJob) {
  12007. const job = mJob;
  12008. mJob = null;
  12009. console.log('cancelJob', job)
  12010. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  12011. // p.cancelJob(a,b);
  12012. }
  12013.  
  12014. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  12015.  
  12016. let pza = taskMgr.__lastJobId863__;
  12017. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  12018. let pzb = taskMgr.__lastJobId863__
  12019. if (pza !== pzb) {
  12020. mJob = pzb; // set [Interval Meta Update] jobId
  12021. }
  12022.  
  12023. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  12024. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  12025. // } else {
  12026. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  12027. // }
  12028.  
  12029. return res;
  12030.  
  12031. } else {
  12032. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  12033. }
  12034.  
  12035. } catch (e) {
  12036. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  12037. }
  12038.  
  12039.  
  12040. return this.scheduleInitialUpdatedMetadataRequest717();
  12041. }
  12042. }
  12043.  
  12044.  
  12045. });
  12046.  
  12047. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  12048. let dummy;
  12049. let cProto;
  12050. dummy = ytAppDom;
  12051. if (!(dummy instanceof Element)) return;
  12052. cProto = insp(dummy).constructor.prototype;
  12053. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  12054. // console.log(1234, cProto, cProto.is);
  12055. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  12056. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  12057. // console.log(123401, arguments);
  12058. // return this.handleServiceRequest717_(a, b, c, d);
  12059. // }
  12060.  
  12061. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  12062.  
  12063. // cProto.handleServiceRequest_ = function(a,b,c,d){
  12064. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  12065. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  12066. // console.log('mfv', c.continuation);
  12067. // mfv.add( c.continuation);
  12068. // }
  12069. // return this.handleServiceRequest717_(a,b,c,d);
  12070. // }
  12071.  
  12072. function extraArguments322(a, b, c) {
  12073. let is = (a || 0).is;
  12074. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  12075. let continuation = (c || 0).continuation;
  12076. if (typeof is !== 'string') is = null;
  12077. if (typeof videoId !== 'string') videoId = null;
  12078. if (typeof continuation !== 'string') continuation = null;
  12079. return { is, videoId, continuation };
  12080. }
  12081.  
  12082. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  12083. cProto.sendServiceAjax_ = function (a, b, c, d) {
  12084.  
  12085. // console.log(8001)
  12086. try {
  12087.  
  12088. const { is, videoId, continuation } = extraArguments322(a, b, c);
  12089.  
  12090. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12091. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  12092. }
  12093.  
  12094. if (pageSetupVideoId && videoId && continuation) {
  12095. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12096. mfyContinuationIgnored.removeAdd(continuation);
  12097. mfvContinuationRecorded.delete(continuation);
  12098. return;
  12099. }
  12100. }
  12101.  
  12102. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12103. copyPreviousContiuationToIgnored374(false);
  12104. mfyContinuationIgnored.delete(continuation);
  12105. mfvContinuationRecorded.removeAdd(continuation);
  12106. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12107. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12108. mjtLockPreviousKey = '';
  12109. }
  12110. // if (mjtNextMainKey === continuation) {
  12111. // copyPreviousContiuationToIgnored(false);
  12112. // mfyContinuationIgnored.delete(continuation);
  12113. // mfvContinuationRecorded.add(continuation);
  12114. // }
  12115.  
  12116.  
  12117. if (mfyContinuationIgnored && continuation) {
  12118. if (mfyContinuationIgnored.has(continuation)) {
  12119. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  12120. return;
  12121. }
  12122. }
  12123.  
  12124. // console.log(59902, a?.is, b,c,d)
  12125. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  12126. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  12127. // console.log('mfv377', continuation);
  12128. mfvContinuationRecorded.add(continuation);
  12129. }
  12130.  
  12131. // if (videoId) {
  12132. // if (!pageSetupVideoId) return; // ignore page not ready
  12133. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12134. // if (videoId !== pageSetupVideoId) {
  12135. // return;
  12136. // }
  12137. // }
  12138.  
  12139. } catch (e) {
  12140. console.log('Coding Error in sendServiceAjax_', e)
  12141. }
  12142. // console.log(8002)
  12143. // console.log(123402, arguments);
  12144. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  12145.  
  12146. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  12147. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  12148. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  12149. // get(target, prop, receiver){
  12150. // console.log('xxs99', target.videoId, mtx)
  12151. // if(prop ==='kdkw33') return 1;
  12152. // console.log(3322, prop, target)
  12153. // if(prop === 'initialDelayMs') {
  12154. // throw new Error("ABCC");
  12155. // }
  12156. // return target[prop];
  12157. // },
  12158. // set(target, prop, value, receiver){
  12159.  
  12160. // if(prop ==='kdkw33') return true;
  12161. // target[prop]=value;
  12162. // return true;
  12163. // }
  12164. // });
  12165. // }
  12166. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  12167. return this.sendServiceAjax717_(a, b, c, d);
  12168. }
  12169. }
  12170.  
  12171. function delayClearOtherKeys(lztContinuation) {
  12172. // // schedule delayed removal if mfyContinuationIgnored is not empty
  12173. // getRafPromise().then(() => {
  12174. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  12175. // // foreground page only
  12176.  
  12177. // });
  12178.  
  12179.  
  12180. if (lztContinuation !== mtzlastAllowedContinuation) return;
  12181. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  12182. if (!mfyContinuationIgnored.size) return;
  12183. if (mfyContinuationIgnored.size > 1) {
  12184. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  12185. }
  12186. mfyContinuationIgnored.forEach((value, key) => {
  12187. if (key !== lztContinuation) {
  12188. mfyContinuationIgnored.delete(key);
  12189. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  12190. }
  12191. });
  12192.  
  12193. }
  12194. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  12195. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  12196. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  12197.  
  12198. // console.log(8003)
  12199. try {
  12200.  
  12201.  
  12202. const { is, videoId, continuation } = extraArguments322(b, c, d);
  12203.  
  12204. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12205. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  12206. }
  12207.  
  12208. if (pageSetupVideoId && videoId && continuation) {
  12209. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12210. mfyContinuationIgnored.removeAdd(continuation);
  12211. mfvContinuationRecorded.delete(continuation);
  12212. return;
  12213. }
  12214. }
  12215.  
  12216. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12217. copyPreviousContiuationToIgnored374(false);
  12218. mfyContinuationIgnored.delete(continuation);
  12219. mfvContinuationRecorded.removeAdd(continuation);
  12220. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12221. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12222. mjtLockPreviousKey = '';
  12223. }
  12224.  
  12225. // if (mjtNextMainKey === continuation) {
  12226. // copyPreviousContiuationToIgnored(false);
  12227. // mfyContinuationIgnored.delete(continuation);
  12228. // mfvContinuationRecorded.add(continuation);
  12229. // }
  12230.  
  12231. const lztContinuation = continuation;
  12232.  
  12233. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  12234. if (mfyContinuationIgnored.has(lztContinuation)) {
  12235. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  12236. return;
  12237. }
  12238. }
  12239.  
  12240. // if (videoId) {
  12241. // if (!pageSetupVideoId) return; // ignore page not ready
  12242. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12243. // if (videoId !== pageSetupVideoId) {
  12244. // return;
  12245. // }
  12246. // }
  12247.  
  12248. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  12249. mtzlastAllowedContinuation = lztContinuation;
  12250. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  12251.  
  12252. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12253. mjtRecordedPrevKey = lztContinuation;
  12254. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  12255. // if (mfyContinuationIgnored.size > 0) {
  12256. // delayClearOtherKeys(lztContinuation);
  12257. // }
  12258. mtzCount = 0;
  12259. // allowNoDelay322 = false;
  12260. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  12261. // repeated
  12262. if (++mtzCount > 1e9) mtzCount = 1e4;
  12263. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12264.  
  12265. // if (mtzCount >= 3) allowNoDelay322 = true;
  12266. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  12267. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  12268. }
  12269. if (mtzCount === 5) {
  12270. mfvContinuationRecorded.clear();
  12271. mfvContinuationRecorded.add(lztContinuation);
  12272. }
  12273.  
  12274. }
  12275.  
  12276. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  12277. mpKey22 = lztContinuation;
  12278. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  12279. }
  12280.  
  12281. if (mbCId322) {
  12282. clearTimeout(mbCId322);
  12283. mbCId322 = 0;
  12284. }
  12285. } catch (e) {
  12286. console.log('Coding Error in getCancellableNetworkPromise_', e)
  12287. }
  12288.  
  12289. // console.log(8004)
  12290. // console.log(123403, arguments);
  12291. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  12292.  
  12293. // console.log(5163, a?.is,b,c,d,e);
  12294. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  12295. }
  12296. }
  12297. });
  12298.  
  12299. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  12300.  
  12301.  
  12302. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  12303.  
  12304. let dummy;
  12305. let cProto;
  12306.  
  12307. dummy = document.createElement('ytd-expander');
  12308. cProto = insp(dummy).constructor.prototype;
  12309.  
  12310. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  12311.  
  12312. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  12313. cProto.childrenChanged14 = cProto.childrenChanged;
  12314.  
  12315. cProto.initChildrenObserver = function () {
  12316. var a = this;
  12317. this.observer = new MutationObserver(function () {
  12318. a.childrenChanged()
  12319. }
  12320. );
  12321. this.observer.observe(this.content, {
  12322. subtree: !0,
  12323. childList: !0,
  12324. attributes: !0,
  12325. characterData: !0
  12326. });
  12327. this.childrenChanged()
  12328. }
  12329. ;
  12330. cProto.childrenChanged = function () {
  12331. if (this.alwaysToggleable) {
  12332. this.canToggle = this.alwaysToggleable;
  12333. } else if (!this.canToggleJobId) {
  12334. this.canToggleJobId = 1;
  12335. foregroundPromiseFn().then(() => {
  12336. this.canToggleJobId = 0;
  12337. this.calculateCanCollapse()
  12338. })
  12339. }
  12340. }
  12341.  
  12342. // console.log(cProto.initChildrenObserver)
  12343. console.debug('ytd-expander-fix-childrenChanged');
  12344.  
  12345. }
  12346.  
  12347. });
  12348.  
  12349.  
  12350. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  12351.  
  12352. let dummy;
  12353. let cProto;
  12354. dummy = document.createElement('paper-ripple');
  12355. cProto = insp(dummy).constructor.prototype;
  12356.  
  12357. if (fnIntegrity(cProto.animate, '0.74.5')) {
  12358.  
  12359.  
  12360. cProto.animate34 = cProto.animate;
  12361. cProto.animate = function () {
  12362. if (this._animating) {
  12363. var a;
  12364. const ripples = this.ripples;
  12365. for (a = 0; a < ripples.length; ++a) {
  12366. var b = ripples[a];
  12367. b.draw();
  12368. this.$.background.style.opacity = b.outerOpacity;
  12369. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  12370. }
  12371. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  12372. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  12373. foregroundPromiseFn().then(this._boundAnimate38);
  12374. } else {
  12375. this.onAnimationComplete();
  12376. }
  12377. }
  12378. }
  12379.  
  12380. console.debug('FIX_paper_ripple_animate')
  12381.  
  12382. // console.log(cProto.animate)
  12383.  
  12384. }
  12385.  
  12386. });
  12387.  
  12388. if (FIX_doIdomRender) {
  12389.  
  12390. const xsetTimeout = function (f, d) {
  12391. if (xsetTimeout.m511 === 1 && !d) {
  12392. xsetTimeout.m511 = 2;
  12393. xsetTimeout.m568 = f;
  12394. } else {
  12395. return setTimeout.apply(window, arguments)
  12396. }
  12397.  
  12398. }
  12399.  
  12400. /**
  12401. *
  12402. IGb = function(a) {
  12403. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  12404. c || (a.requestAninmationFrameResolver = new Vi,
  12405. c = a.requestAninmationFrameResolver.promise,
  12406. Da.requestAnimationFrame(function() {
  12407. var d;
  12408. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  12409. a.requestAninmationFrameResolver = null
  12410. }));
  12411. return c
  12412. }
  12413.  
  12414.  
  12415. */
  12416.  
  12417. const xrequestAnimationFrame = function (f) {
  12418. const h = `${f}`;
  12419. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  12420. let t = null;
  12421. xsetTimeout.m511 = 1;
  12422. f();
  12423. if (xsetTimeout.m511 === 2) {
  12424. t = xsetTimeout.m568;
  12425. xsetTimeout.m568 = null;
  12426. }
  12427. xsetTimeout.m511 = 0;
  12428. if (typeof t === 'function') {
  12429. foregroundPromiseFn().then(t);
  12430. }
  12431. } else if (h.includes("requestAninmationFrameResolver")) {
  12432. foregroundPromiseFn().then(f);
  12433. } else {
  12434. return requestAnimationFrame.apply(window, arguments);
  12435. }
  12436. }
  12437.  
  12438. let busy = false;
  12439. const doIdomRender = function () {
  12440.  
  12441. if (!this) return;
  12442. if (busy) {
  12443. return this.doIdomRender13(...arguments);
  12444. }
  12445. busy = true;
  12446. const { requestAnimationFrame, setTimeout } = window;
  12447. window.requestAnimationFrame = xrequestAnimationFrame;
  12448. window.setTimeout = xsetTimeout;
  12449. let r = this.doIdomRender13(...arguments);
  12450. window.requestAnimationFrame = requestAnimationFrame;
  12451. window.setTimeout = setTimeout;
  12452. busy = false;
  12453. return r;
  12454. };
  12455. 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']) {
  12456.  
  12457.  
  12458. whenCEDefined(ytTag).then(() => {
  12459.  
  12460. let dummy;
  12461. let cProto;
  12462. dummy = document.createElement(ytTag);
  12463. cProto = insp(dummy).constructor.prototype;
  12464.  
  12465. cProto.doIdomRender13 = cProto.doIdomRender;
  12466. cProto.doIdomRender = doIdomRender;
  12467.  
  12468. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  12469.  
  12470. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  12471.  
  12472.  
  12473.  
  12474. });
  12475.  
  12476. }
  12477.  
  12478. }
  12479.  
  12480.  
  12481.  
  12482.  
  12483. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  12484.  
  12485. const sMap = new Map();
  12486.  
  12487. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  12488. const ZT = function () {
  12489. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  12490. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  12491. c = b & 15,
  12492. b >>= 4,
  12493. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  12494. return a.join("")
  12495. };
  12496.  
  12497.  
  12498. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  12499.  
  12500. const popupContainer = await observablePromise(() => {
  12501. return popupContainerCollection[0];
  12502. }).obtain();
  12503.  
  12504.  
  12505. let cProto;
  12506. cProto = insp(popupContainer).constructor.prototype;
  12507.  
  12508.  
  12509. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  12510. console.log('FIX_POPUP_UNIQUE_ID NG')
  12511. return;
  12512. }
  12513. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  12514.  
  12515. cProto.handleOpenPopupAction = function (a, b) {
  12516.  
  12517. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  12518.  
  12519. a.__jOdQA__ = true;
  12520.  
  12521. try {
  12522.  
  12523. const h = this.hostElement;
  12524.  
  12525. if (h instanceof HTMLElement_) {
  12526.  
  12527. const map = h.__skme44__ = h.__skme44__ || new Map();
  12528.  
  12529. let mKey = '';
  12530. const wKey = firstObjectKey(a);
  12531. const wObj = wKey ? a[wKey] : null;
  12532. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  12533. const pKey = firstObjectKey(wObj.popup)
  12534. const pObj = pKey ? wObj.popup[pKey] : null;
  12535. let contentKey = '';
  12536. let headerKey = '';
  12537.  
  12538. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  12539. contentKey = firstObjectKey(pObj.content)
  12540. headerKey = firstObjectKey(pObj.header)
  12541. }
  12542. if (contentKey && headerKey) {
  12543.  
  12544. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  12545.  
  12546. if (mKey) {
  12547.  
  12548. if (!wObj.uniqueId) {
  12549. for (let i = 0; i < 8; i++) {
  12550. wObj.uniqueId = ZT();
  12551. if (!sMap.has(wObj.uniqueId)) break;
  12552. }
  12553. }
  12554. const oId = wObj.uniqueId
  12555.  
  12556. let nId_ = map.get(mKey);
  12557. if (!nId_) {
  12558. map.set(mKey, nId_ = oId);
  12559. }
  12560.  
  12561. wObj.uniqueId = nId_ || wObj.uniqueId;
  12562.  
  12563. const nId = wObj.uniqueId
  12564.  
  12565. sMap.set(oId, nId);
  12566. sMap.set(nId, nId);
  12567.  
  12568. wObj.uniqueId = nId;
  12569. pObj.targetId = nId;
  12570. pObj.identifier.tag = nId;
  12571.  
  12572. if (oId !== nId) {
  12573. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  12574. }
  12575.  
  12576. }
  12577.  
  12578. }
  12579. }
  12580.  
  12581. // console.log(12213, mKey, a, b, h)
  12582.  
  12583. }
  12584.  
  12585. } catch (e) {
  12586. console.warn(e)
  12587. }
  12588.  
  12589. try {
  12590.  
  12591. const results = searchNestedObject(a, (x) => {
  12592. if (typeof x === 'string' && x.length === 36) {
  12593. 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;
  12594. }
  12595. return false;
  12596. });
  12597. for (const [obj, key] of results) {
  12598. const oId = obj[key];
  12599. const nId = sMap.get(oId);
  12600. if (nId) obj[key] = nId;
  12601. }
  12602. } catch (e) {
  12603. console.warn(e)
  12604. }
  12605.  
  12606.  
  12607. }
  12608.  
  12609. return this.handleOpenPopupAction3868(...arguments)
  12610. }
  12611.  
  12612. console.log('FIX_POPUP_UNIQUE_ID OK')
  12613.  
  12614.  
  12615. });
  12616.  
  12617.  
  12618. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  12619.  
  12620. let dummy;
  12621. let cProto;
  12622. dummy = document.createElement('yt-formatted-string');
  12623. cProto = insp(dummy).constructor.prototype;
  12624.  
  12625. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  12626. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  12627. return;
  12628. }
  12629.  
  12630. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  12631. cProto.setNodeStyle_ = function (a, b) {
  12632. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  12633. return this.setNodeStyle17_(a, b);
  12634. }
  12635.  
  12636. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  12637. });
  12638.  
  12639. });
  12640.  
  12641. });
  12642.  
  12643.  
  12644.  
  12645.  
  12646. if (isMainWindow) {
  12647.  
  12648. console.groupCollapsed(
  12649. "%cYouTube JS Engine Tamer",
  12650. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  12651. );
  12652.  
  12653.  
  12654.  
  12655. console.log("Script is loaded.");
  12656. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  12657.  
  12658. console.log("This script is experimental and subject to further changes.");
  12659.  
  12660. console.log("This might boost your YouTube performance.");
  12661.  
  12662. console.log("CAUTION: This might break your YouTube.");
  12663.  
  12664.  
  12665. if (prepareLogs.length >= 1) {
  12666. console.log(" =========================================================================== ");
  12667.  
  12668. for (const msg of prepareLogs) {
  12669. console.log(msg)
  12670. }
  12671.  
  12672. console.log(" =========================================================================== ");
  12673. }
  12674.  
  12675. console.groupEnd();
  12676.  
  12677. }
  12678.  
  12679.  
  12680.  
  12681. })();

QingJ © 2025

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