YouTube JS Engine Tamer

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

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

  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.37.1
  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.  
  37. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  38. const FIX_schedulerInstanceInstance = 2 | 4;
  39. const FIX_yt_player = true; // DONT CHANGE
  40. const FIX_Animation_n_timeline = true;
  41. const FIX_Animation_n_timeline_cinematic = true;
  42. const FIX_ytScheduler = true;
  43. const NO_PRELOAD_GENERATE_204 = false;
  44. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  45. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  46. const CHANGE_appendChild = true; // discussions#236759
  47. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  48. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  49.  
  50. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  51. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  52. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  53.  
  54. const FIX_Iframe_NULL_SRC = false;
  55.  
  56. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  57.  
  58. const FIX_ytdExpander_childrenChanged = true;
  59. const FIX_paper_ripple_animate = true;
  60. const FIX_avoid_incorrect_video_meta = false; // omit the incorrect yt-animated-rolling-number // 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  61. const FIX_avoid_incorrect_video_meta_emitterBehavior = false; // 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  62.  
  63. const FIX_doIdomRender = true;
  64.  
  65. const FIX_Shady = true;
  66.  
  67. // [[ 2024.04.24 ]]
  68. const MODIFY_ShadyDOM_OBJ = true;
  69. // << if MODIFY_ShadyDOM_OBJ >>
  70. const WEAKREF_ShadyDOM = true;
  71. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  72. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  73. // << end >>
  74.  
  75. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  76.  
  77. const FIX_ytAction_ = true; // ytd-app
  78. const FIX_onVideoDataChange = false;
  79. // const FIX_onClick = true;
  80. const FIX_onStateChange = true;
  81. const FIX_onLoopRangeChange = true;
  82. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  83. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  84.  
  85. const ENABLE_discreteTasking = false; // removed since 0.20.0
  86. const FIX_stampDomArray_ = true; // v0.30.0
  87. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  88. // const stampDomArray_MemoryFix_Flag001 = false;
  89. const XFlag = true; // root issue tbc
  90. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  91. // 32 required for new stampDomArray
  92. // 128 to be tested
  93.  
  94. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  95. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  96.  
  97. const FIX_Polymer_dom = true;
  98. const FIX_Polymer_AF = true;
  99.  
  100. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  101. const DEBUG_removePrune = false; // true for DEBUG
  102.  
  103. const FIX_XHR_REQUESTING = true;
  104.  
  105. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  106.  
  107. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  108.  
  109. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  110. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  111.  
  112. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  113.  
  114. const FIX_removeChild = true;
  115. const FIX_fix_requestIdleCallback_timing = true;
  116.  
  117. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  118. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  119.  
  120. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  121.  
  122. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  123.  
  124. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  125. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  126. // first tp-yt-paper-dialog: show once the page is loaded.
  127. // second tp-yt-paper-dialog: click "...more"
  128. // third tp-yt-paper-dialog: click "... and 3 more links"
  129. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  130. // currently, uniqueId is preassigned by the network resolveCommand.
  131. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  132. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  133.  
  134. // handleOpenPopupAction -> createCacheKey
  135. // handleClosePopupAction_ -> createCacheKey
  136. // handleGetPopupOpenedAction_ -> createCacheKey
  137. // getAndMaybeCreatePopup_ -> createCacheKey
  138. // closePopup -> createCacheKey
  139.  
  140. // yt-close-popup-command -> handleClosePopupCommand_
  141.  
  142. // ensurePopup_ -> getAndMaybeCreatePopup_
  143.  
  144. // yt-close-popup-action -> handleClosePopupAction_
  145. // closePopup -> handleClosePopupAction_
  146. // handleOpenPopupAction -> handleClosePopupAction_
  147. // handleClosePopupCommand_ -> handleClosePopupAction_
  148. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  149.  
  150. // yt-open-popup-action -> handleOpenPopupAction
  151.  
  152.  
  153. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  154. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  155.  
  156. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  157. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  158. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  159.  
  160.  
  161. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  162. const FIX_DOM_IF_TEMPLATE = true;
  163. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  164. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  165. const DEBUG_DBR847 = false;
  166. const DEBUG_xx847 = false;
  167. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  168. const DEBUG_renderDebounceTs = false;
  169.  
  170. const FIX_ICON_RENDER = true;
  171.  
  172. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  173.  
  174. const DISABLE_isLowLatencyLiveStream = false; // TBC
  175.  
  176. const FIX_FlexibleItemSizing = true;
  177.  
  178. /*
  179.  
  180. FIX_DOM_IFREPEAT_RenderDebouncerChange
  181.  
  182. avoid Polymer.flush
  183. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  184.  
  185. var Is = function() {
  186. do {
  187. var a = window.ShadyDOM && ShadyDOM.flush();
  188. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  189. var b = NNa()
  190. } while (a || b)
  191. };
  192.  
  193. , NNa = function() {
  194. var a = !!ts.size;
  195. ts.forEach(function(b) {
  196. try {
  197. b.flush()
  198. } catch (c) {
  199. setTimeout(function() {
  200. throw c
  201. })
  202. }
  203. });
  204. return a
  205. };
  206.  
  207. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  208. // this coding logic should be incorrect (mistake).
  209.  
  210. */
  211.  
  212.  
  213.  
  214. // ----------------------------- Shortkey Keyboard Control -----------------------------
  215. // dependency: FIX_yt_player
  216.  
  217. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  218. // [0] no fix - not recommended
  219. // [1] basic fix - just fix the global focus detection variable
  220. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  221. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  222.  
  223. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  224. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  225.  
  226. const PROP_OverReInclusion_AVOID = true;
  227. const PROP_OverReInclusion_DEBUGLOG = false;
  228. const PROP_OverReInclusion_LIST = new Set([
  229. 'hostElement72',
  230. 'parentComponent72',
  231. 'localVisibilityObserver_72',
  232. 'cachedProviderNode_72',
  233. '__template72',
  234. '__templatizeOwner72',
  235. '__templateInfo72',
  236. '__dataHost72',
  237. '__CE_shadowRoot72',
  238. 'elements_72',
  239.  
  240. 'ky36',
  241. 'kz62',
  242. 'm822',
  243.  
  244.  
  245.  
  246. // To be reviewed.
  247.  
  248. // chat messages
  249. 'disabled', 'allowedProps',
  250. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  251.  
  252. 'dimension', 'loadTime', 'pendingPaint',
  253.  
  254. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  255.  
  256. 'respectLangDir', 'noEndpoints',
  257.  
  258.  
  259. 'objectURL',
  260. 'buttonOverrides', 'queuedMessages',
  261. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  262. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  263. 'hoverJobId', 'JSC$14573_touched',
  264.  
  265.  
  266. // tbc
  267. 'toggleable', 'isConnected',
  268. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  269. 'disableDeselectEvent',
  270. 'emojiSize',
  271.  
  272. 'buttonOverride',
  273. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  274.  
  275. // others
  276. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  277. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  278. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  279. // 'dimension', 'loadTime', 'pendingPaint',
  280. // 'disabled', 'allowedProps',
  281.  
  282.  
  283. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  284. // 'actionMap',
  285.  
  286. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  287.  
  288. 'clearTimeout',
  289. 'switchTemplateAtRegistration', 'hasUnmounted',
  290. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  291. 'tangoConfiguration',
  292. 'itemIdToDockDurationMap',
  293. 'actionMap',
  294.  
  295. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  296. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  297. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  298.  
  299. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  300. // 'stopKeyboardEventPropagation', 'emojiSize',
  301. // 'switchTemplateAtRegistration', 'hasUnmounted',
  302. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  303. // 'isReusable', 'tangoConfiguration',
  304. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  305. // */
  306.  
  307. ]);
  308.  
  309.  
  310. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  311.  
  312. // ----------------------------- Shortkey Keyboard Control -----------------------------
  313.  
  314. /*
  315. window.addEventListener('edm',()=>{
  316. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  317. });
  318.  
  319. window.addEventListener('edn',()=>{
  320. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  321. });
  322. window.addEventListener('edr',()=>{
  323. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  324. });
  325. */
  326.  
  327. // only for macOS with Chrome/Firefox 100+
  328. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  329.  
  330. const win = this instanceof Window ? this : window;
  331.  
  332. // Create a unique key for the script and check if it is already running
  333. const hkey_script = 'jswylcojvzts';
  334. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  335. win[hkey_script] = true;
  336.  
  337.  
  338.  
  339. const wk = Symbol();
  340.  
  341. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  342.  
  343. let BY_PASS_KEYBOARD_CONTROL = false;
  344.  
  345.  
  346. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  347. /** @type {(f: ()=>{})=>{}} */
  348. const nextBrowserTick_ = nextBrowserTick;
  349. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  350. console.log('nextBrowserTick is not found.');
  351. return;
  352. }
  353.  
  354. let p59 = 0;
  355.  
  356. const Promise = (async () => { })().constructor;
  357.  
  358. const PromiseExternal = ((resolve_, reject_) => {
  359. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  360. return class PromiseExternal extends Promise {
  361. constructor(cb = h) {
  362. super(cb);
  363. if (cb === h) {
  364. /** @type {(value: any) => void} */
  365. this.resolve = resolve_;
  366. /** @type {(reason?: any) => void} */
  367. this.reject = reject_;
  368. }
  369. }
  370. };
  371. })();
  372.  
  373. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  374. constructor(callback = undefined) {
  375.  
  376. }
  377. register(target, heldValue, unregisterToken = undefined) {
  378.  
  379. }
  380. unregister(unregisterToken) {
  381.  
  382. }
  383. }
  384.  
  385. let ttpHTML = (s) => {
  386. ttpHTML = s => s;
  387. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  388. let s = s => s;
  389. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  390. }
  391. return s;
  392. }
  393.  
  394.  
  395. /** @type { typeof HTMLElement } */
  396. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  397. const nativeAppendE = HTMLElement_.prototype.append;
  398. const nativeRemoveE = HTMLElement_.prototype.remove;
  399. const DocumentFragment_ = DocumentFragment;
  400. const nativeAppendD = DocumentFragment_.prototype.append;
  401. const Node_ = Node;
  402.  
  403. /**
  404. @param {number} x
  405. @param {number} d */
  406. const toFixed2 = (x, d) => {
  407. let t = x.toFixed(d);
  408. let y = `${+t}`;
  409. return y.length > t.length ? t : y;
  410. }
  411.  
  412.  
  413. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  414.  
  415.  
  416. const TRANSLATE_DEBUG = false;
  417.  
  418.  
  419. let xdeadc00 = null; // a deteched node with __domApi
  420. let xlivec00 = null; // a deteched node with __domApi
  421.  
  422. let removeTNodeRM = null;
  423. let removeTNodeBP = false;
  424.  
  425.  
  426. if (Node.isConnectedOverrided === undefined) {
  427. const pdConnected = Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected');
  428. if (pdConnected && pdConnected.get && pdConnected.configurable) {
  429. Node.isConnectedOverrided = null;
  430. const get_ = pdConnected.get;
  431. const get = function () {
  432. const overrided = Node.isConnectedOverrided;
  433. if (typeof overrided === 'boolean') return overrided;
  434. return get_.call(this);
  435. }
  436. Object.defineProperty(Node.prototype, 'isConnected', {
  437. ...pdConnected,
  438. get
  439. });
  440. }
  441. }
  442.  
  443.  
  444. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  445.  
  446. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  447.  
  448. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  449.  
  450. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  451.  
  452.  
  453. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  454. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  455. return;
  456. }
  457.  
  458.  
  459. const mapGet = Map.prototype.get;
  460. const setHas = Set.prototype.has;
  461.  
  462.  
  463. /** @type {Map | null} */
  464. let qcMap = null;
  465.  
  466. Set.prototype.has = function (a) {
  467. if (a === 'dummy-4718') return false; // false to allow re-use?
  468. return setHas.call(this, a);
  469. }
  470.  
  471. Map.prototype.get = function (a) {
  472. if (a === 'dummy-4718') qcMap = this;
  473. return mapGet.call(this, a);
  474. };
  475. let r;
  476. try {
  477. r = mainCnt.createComponent_('dummy-4718', {}, true);
  478. } catch (e) {
  479.  
  480. }
  481.  
  482. Map.prototype.get = mapGet;
  483. Set.prototype.has = setHas;
  484.  
  485. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  486.  
  487.  
  488. // clearInterval(ckId);
  489. // ckId = 0;
  490.  
  491. if (qcMap !== null && qcMap instanceof Map) {
  492.  
  493. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  494. qcMap.__qcMap8781__ = true;
  495.  
  496. const setArrayC = (c) => {
  497. if (c instanceof Array) {
  498. c.length = 0;
  499. c.push = function () { };
  500. c.pop = function () { };
  501. c.shift = function () { };
  502. c.unshift = function () { };
  503. c.splice = function () { };
  504. c.sort = function () { };
  505. c.reverse = function () { };
  506. }
  507. }
  508.  
  509. const cleaning = function (m) {
  510. m.forEach(setArrayC);
  511. m.clear();
  512. }
  513.  
  514. qcMap.set = function (b, c) {
  515. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  516.  
  517. setArrayC(c);
  518.  
  519. // console.log('qcMap.set', b, c);
  520.  
  521. if (this.size > 0) {
  522. // play safe
  523.  
  524. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  525. cleaning(this);
  526. }
  527.  
  528. }
  529. qcMap.get = function (b) {
  530. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  531.  
  532. // console.log('qcMap.get', b);
  533.  
  534. if (this.size > 0) {
  535. // play safe
  536.  
  537. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  538. cleaning(this);
  539. }
  540.  
  541. }
  542.  
  543.  
  544. if (qcMap.size > 0) {
  545.  
  546. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  547. cleaning(qcMap);
  548. }
  549.  
  550. }
  551.  
  552. }
  553.  
  554. r = null;
  555. qcMap = null;
  556.  
  557. }
  558.  
  559.  
  560. const dispatchYtEvent = function (a, b, c, d) {
  561. d || (d = {
  562. bubbles: !0,
  563. cancelable: !1,
  564. composed: !0
  565. });
  566. c !== null && c !== void 0 && (d.detail = c);
  567. b = new CustomEvent(b, d);
  568. a.dispatchEvent(b);
  569. return b
  570. };
  571.  
  572. if (DISABLE_isLowLatencyLiveStream) {
  573. const sm = Symbol();
  574. const f = () => {
  575. try {
  576. const videoDetails = ytInitialPlayerResponse.videoDetails;
  577. if (videoDetails && videoDetails.isLowLatencyLiveStream) {
  578. videoDetails.isLowLatencyLiveStream = false;
  579. }
  580. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW') {
  581. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  582. }
  583. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  584. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  585. }
  586. } catch (e) { }
  587. }
  588. Object.defineProperty(Object.prototype, 'isLowLatencyLiveStream', {
  589. get() {
  590. const v = this[sm];
  591. if (typeof v === 'undefined') return v;
  592. f();
  593. return v;
  594. },
  595. set(nv) {
  596. f();
  597. if (nv === true) nv = false;
  598. this[sm] = nv;
  599. },
  600. enumerable: false,
  601. configurable: true
  602. });
  603.  
  604. const sm3 = Symbol();
  605. Object.defineProperty(Object.prototype, 'latencyClass', {
  606. get() {
  607. const v = this[sm3];
  608. if (typeof v === 'undefined') return v;
  609. f();
  610. return v;
  611. },
  612. set(nv) {
  613. f();
  614. if (nv === 'ULTRALOW' || nv === 'LOW') {
  615. nv = 'NORMAL';
  616. } else if (nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW' || nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  617. nv = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  618. }
  619. this[sm3] = nv;
  620. },
  621. enumerable: false,
  622. configurable: true
  623. });
  624.  
  625. }
  626.  
  627. if (XFlag) {
  628.  
  629. const cMap = new Set();
  630. cMap.add = cMap.addOriginal || cMap.add;
  631. const yMap = new Set();
  632. yMap.add = yMap.addOriginal || yMap.add;
  633.  
  634.  
  635. const ydMap = new Set();
  636. ydMap.add = ydMap.addOriginal || ydMap.add;
  637.  
  638. window.yMap = yMap;
  639. window.cMap = cMap;
  640. window.ydMap = ydMap;
  641.  
  642. const constructAts = new Set();
  643. constructAts.add = constructAts.addOriginal || constructAts.add;
  644. window.constructAts = constructAts;
  645.  
  646. const kMap = new WeakMap();
  647.  
  648. const kRefProp = (wr, prop)=>{
  649. let o = kRef(wr);
  650. return o ? o[prop] : null;
  651. }
  652.  
  653. const wrObj = (objRef, props) => {
  654. let wr = mWeakRef(objRef);
  655. if (wr === objRef || !props || !props.length) return wr;
  656. let properties = {};
  657. props.forEach(k => {
  658. properties[k] = {
  659. get() {
  660. return kRefProp(this, k)
  661. },
  662. enumerable: false,
  663. configurable: true
  664. };
  665. });
  666. Object.defineProperties(wr, properties);
  667. return wr;
  668. }
  669.  
  670. const sProtos = {};
  671.  
  672. const setupCProto = function (cProto) {
  673.  
  674. if(cProto === Object.prototype) return;
  675.  
  676. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  677. cProto[kMap.get(cProto)] = true;
  678. // debugger;
  679.  
  680. 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];
  681. constructAts.add(constructAt)
  682.  
  683. if (MemoryFix_Flag002 & 32) {
  684. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  685. fixDetachFn(cProto);
  686. }
  687. }
  688.  
  689. if (MemoryFix_Flag002 & 2) {
  690. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  691. cProto.__setPropDX38__ = true;
  692.  
  693. if (cProto._setPendingProperty.length === 3) {
  694. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  695. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  696. return () => {
  697. const obj = kRef(wobj);
  698. let u = Reflect.apply(this, obj, args);
  699. args.length = 0;
  700. wobj = null;
  701. return u;
  702. };
  703. });
  704. }
  705.  
  706. }
  707. }
  708.  
  709. if (MemoryFix_Flag002 & 4) {
  710. if (cProto._runEffectsForTemplate && !cProto.__runEffectDX38__) {
  711. cProto.__runEffectDX38__ = true;
  712.  
  713. if (cProto._runEffectsForTemplate.length === 4) {
  714. cProto._runEffectsForTemplate3858 = cProto._runEffectsForTemplate;
  715. cProto._runEffectsForTemplate = sProtos._runEffectsForTemplate || (sProtos._runEffectsForTemplate = function (c, d, e, g) {
  716. if (c && c.runEffects) {
  717. let wr = wrObj(c, ['propertyEffects', 'nodeList', 'firstChild']);
  718. // console.log(12837)
  719. if (!this[wk]) this[wk] = mWeakRef(this);
  720. if ((typeof (e || 0) === "object") && !e[wk]) e[wk] = mWeakRef(e);
  721. let cntWr = this[wk];
  722. let eWr = (typeof (e || 0) === "object") ? e[wk] : e;
  723. c.runEffects((n, r) => {
  724. // console.log(12838)
  725. const cnt = kRef(cntWr);
  726. const e = kRef(eWr);
  727. if (cnt) {
  728. cnt._runEffectsForTemplate3858(wr, n, e, r);
  729. }
  730. wr = cntWr = d = e = g = null;
  731. }, d, g);
  732. } else {
  733. let { propertyEffects, nodeList, firstChild } = c;
  734. let o = { propertyEffects, nodeList, firstChild }
  735. this._runEffectsForTemplate3858(o, d, e, g);
  736. o.propertyEffects = o.nodeList = o.firstChild = null;
  737. propertyEffects = nodeList = firstChild = null;
  738. o = null;
  739. }
  740.  
  741. });
  742.  
  743. cProto._runEffectsForTemplate.bind = sProtos._runEffectsForTemplate$bind || (sProtos._runEffectsForTemplate$bind = function (obj, ...args) {
  744. // console.log(12993, args)
  745. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  746. return () => {
  747. const obj = kRef(wobj);
  748. let u = Reflect.apply(this, obj, args);
  749. args.length = 0;
  750. wobj = null;
  751. return u;
  752. };
  753. });
  754. }
  755.  
  756. }
  757. }
  758.  
  759.  
  760.  
  761.  
  762.  
  763. const cProtoConstructor = cProto.constructor;
  764.  
  765. if (MemoryFix_Flag002 & 8) {
  766. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  767. cProtoConstructor.__parseBindingsDX38__ = true;
  768.  
  769. ydMap.add(cProtoConstructor);
  770.  
  771. if (cProtoConstructor._parseBindings.length === 2) {
  772.  
  773. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  774.  
  775. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  776. let p = this._parseBindings3858(c, d);
  777. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  778. if (p) this.__bindingsArrs__.push(p);
  779. return p;
  780. });
  781.  
  782. }
  783. }
  784. }
  785.  
  786. /*
  787. a.prototype._initializeProperties = function() {
  788. if (Em && this.hasAttribute("disable-upgrade"))
  789. this.__isUpgradeDisabled = !0;
  790. else {
  791. var e = Object.getPrototypeOf(this);
  792. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  793. e.__hasRegisterFinished = !0);
  794. b.prototype._initializeProperties.call(this);
  795. this.root = this;
  796. this.created();
  797. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  798. this._applyListeners()
  799. }
  800. }
  801. */
  802. /*
  803. bOa = function(a, b, c) {
  804. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  805. d.prototype.is = b;
  806. d.prototype.localName = b;
  807. c && aOa(d, c);
  808. return function(e) {
  809. e && (d.prototype.hostElement = e);
  810. var g = new d;
  811. g.root = g;
  812. g.hostElement = e;
  813. return g
  814. }
  815. }
  816. */
  817.  
  818.  
  819. }
  820. const symDH = Symbol();
  821.  
  822. const wfStore = new WeakMap();
  823.  
  824. const wrapF = function (f, key) {
  825. if (wfStore.get(f)) return wfStore.get(f);
  826.  
  827. let g = function () {
  828. const o = kRef(this);
  829. if (!o) return;
  830. const cnt = insp(o);
  831. // if (cnt === o) return;
  832. // if (!('ready' in cnt)) return;
  833. return f.apply(o, arguments);
  834. };
  835. g.key38 = key;
  836. g.originalFunc38 = f;
  837. g.__wrapF84__ = true;
  838. wfStore.set(f, g);
  839. wfStore.set(g, g);
  840. return g;
  841. };
  842.  
  843. if (MemoryFix_Flag002 & 16) {
  844. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  845.  
  846. Object.defineProperty(Node.prototype, key, {
  847. get() {
  848. return this[`__a0939${key}__`];
  849. },
  850. set(nv) {
  851. if (typeof nv !== 'function') return;
  852. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  853. this[`__a0939${key}__`] = g;
  854. return true;
  855. }
  856. });
  857.  
  858.  
  859. });
  860. }
  861.  
  862.  
  863.  
  864. const wm = new WeakMap();
  865.  
  866. const fixDetachFn = (tpProto) => { // & 32
  867.  
  868. if (tpProto.dk322) return;
  869. tpProto.dk322 = true;
  870.  
  871. window.__fixTemplateReuse1058__ = true;
  872.  
  873.  
  874. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  875. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  876. tpProto.__ensureTemplatized = function () {
  877. // console.log(18470001)
  878. return this.__ensureTemplatized994();
  879. }
  880. }
  881.  
  882.  
  883. tpProto.__updateInstances994 = tpProto.__updateInstances;
  884. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  885. let bypass= false;
  886. tpProto.__updateInstances = function (a, b, c) {
  887.  
  888. // const a_ = [...a];
  889. if(!bypass && a === this.items && (a||0).length >=1 ){
  890.  
  891. bypass = true;
  892. // console.log(18470002, a, b,c)
  893. let e;
  894. for (e = 0; e < b; e++) {
  895. let g = this.__instances[e]
  896. , k = c[e]
  897. , m = a[k];
  898. if(g && typeof (m||0) === 'object'){
  899. // const q = g._shouldPropertyChange;
  900. // g._shouldPropertyChange = ()=>true;
  901. // g[this.as] = {};
  902. // a_[k]=a[k] = m;
  903. // g[this.as] = m;
  904.  
  905. // use public interface notifyPath instead of internal interface _setPendingProperty
  906. const m_ = a[k] = Object.assign({}, a[k]);
  907. try {
  908. g.notifyPath(this.as, {});
  909. } catch (e) { }
  910. try {
  911. g.notifyPath(this.as, m_);
  912. } catch (e) { }
  913.  
  914. // g._setPendingProperty(this.as, {});
  915. // g._setPendingProperty(this.as, m);
  916. // g._setPendingProperty(this.indexAs, e);
  917. // g._setPendingProperty(this.itemsIndexAs, k);
  918. // delete g._shouldPropertyChange;
  919. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  920. }
  921. }
  922. bypass = false;
  923.  
  924. }
  925. const r = this.__updateInstances994(a,b,c);
  926.  
  927. // for (e = 0; e < b; e++) {
  928. // let g = this.__instances[e]
  929. // , k = c[e]
  930. // , m = a_[k];
  931. // if(g){
  932. // // const q = g._shouldPropertyChange;
  933. // // g._shouldPropertyChange = ()=>true;
  934. // // g[this.as] = m;
  935. // // g._setPendingProperty(this.as, {});
  936. // // g._setPendingProperty(this.as, m);
  937. // // g._setPendingProperty(this.indexAs, e);
  938. // // g._setPendingProperty(this.itemsIndexAs, k);
  939. // // delete g._shouldPropertyChange;
  940. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  941. // }
  942. // }
  943.  
  944. return r;
  945. }
  946. }
  947.  
  948. /*
  949.  
  950. tpProto.__updateInstances = function (a, b, c) {
  951.  
  952. let renew = this.__wasInstanceDetached001 === true;
  953. if(renew){
  954.  
  955. this.__wasInstanceDetached001 = false;
  956. }
  957.  
  958. // const a_ = [...a];
  959. // if(a === this.items && (a||0).length >=1 ){
  960.  
  961. // // console.log(18470002, a, b,c)
  962. // let e;
  963. // for (e = 0; e < b; e++) {
  964. // let g = this.__instances[e]
  965. // , k = c[e]
  966. // , m = a[k];
  967. // if(g && typeof (m||0) === 'object'){
  968. // // const q = g._shouldPropertyChange;
  969. // // g._shouldPropertyChange = ()=>true;
  970. // // g[this.as] = {};
  971. // // a_[k]=a[k] = m;
  972. // // g[this.as] = m;
  973.  
  974. // // use public interface notifyPath instead of internal interface _setPendingProperty
  975. // try {
  976. // g.notifyPath(this.as, {});
  977. // } catch (e) { }
  978. // try {
  979. // g.notifyPath(this.as, m);
  980. // } catch (e) { }
  981.  
  982. // // g._setPendingProperty(this.as, {});
  983. // // g._setPendingProperty(this.as, m);
  984. // // g._setPendingProperty(this.indexAs, e);
  985. // // g._setPendingProperty(this.itemsIndexAs, k);
  986. // // delete g._shouldPropertyChange;
  987. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  988. // }
  989. // }
  990.  
  991. // }
  992. const r = this.__updateInstances994(a,b,c);
  993.  
  994. // for (e = 0; e < b; e++) {
  995. // let g = this.__instances[e]
  996. // , k = c[e]
  997. // , m = a_[k];
  998. // if(g){
  999. // // const q = g._shouldPropertyChange;
  1000. // // g._shouldPropertyChange = ()=>true;
  1001. // // g[this.as] = m;
  1002. // // g._setPendingProperty(this.as, {});
  1003. // // g._setPendingProperty(this.as, m);
  1004. // // g._setPendingProperty(this.indexAs, e);
  1005. // // g._setPendingProperty(this.itemsIndexAs, k);
  1006. // // delete g._shouldPropertyChange;
  1007. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  1008. // }
  1009. // }
  1010. if (renew) {
  1011.  
  1012. const q = [...this.items];
  1013. this.items = [];
  1014. this.items = q;
  1015. console.log(129992)
  1016. // this.items.splice(0, 1, Object.assign({}, this.items[0]));
  1017. }
  1018. return r;
  1019. }
  1020.  
  1021. */
  1022.  
  1023. tpProto.__detachInstance994 = tpProto.__detachInstance;
  1024. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  1025. tpProto.__detachInstance = function (a) {
  1026. const u = this.__instances[a];
  1027. const children = (u || 0).children;
  1028. if (children && children.length >= 1) {
  1029. const pp = document.createDocumentFragment();
  1030. for (const s of [...children]) {
  1031. pp.appendChild(s);
  1032. }
  1033. }
  1034. try {
  1035. return this.__detachInstance994(a);
  1036. } catch (e) { }
  1037. return u;
  1038. }
  1039. }
  1040.  
  1041. tpProto.__attachInstance994 = tpProto.__attachInstance;
  1042. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  1043. tpProto.__attachInstance = function (a, b) {
  1044. const u = this.__instances[a];
  1045. if (u && u.root && b) {
  1046. const root = u.root;
  1047. const pp = document.createDocumentFragment();
  1048. pp.appendChild(root);
  1049. root.appendChild(pp);
  1050. const r = this.__attachInstance994(a, b);
  1051. if (!this.__chunkingId) this.__chunkingId = 0.25;
  1052. return r;
  1053. }
  1054. }
  1055. }
  1056.  
  1057. }
  1058.  
  1059. const ytTemplateDomEntry = (tpProto) => {
  1060.  
  1061. console.log('ytTemplateDomEntry triggered')
  1062.  
  1063.  
  1064. const convertToWeakArr = (arr) => {
  1065.  
  1066. if (arr.isWeak) return;
  1067.  
  1068. for (let i = 0, l = arr.length; i < l; i++) {
  1069. const o = arr[i]
  1070. if (o) {
  1071. let p = kRef(o)
  1072. if (!p) arr[i] = null;
  1073. else {
  1074. if (!o[wk]) o[wk] = mWeakRef(o);
  1075. arr[i] = o[wk];
  1076. }
  1077. }
  1078. }
  1079. arr.isWeak = true;
  1080.  
  1081. }
  1082.  
  1083. const convertToNormalArr = (arr) => {
  1084.  
  1085. if (!arr.isWeak) return;
  1086.  
  1087. for (let i = 0, l = arr.length; i < l; i++) {
  1088. const o = arr[i]
  1089. if (o) {
  1090. let p = kRef(o)
  1091. arr[i] = p;
  1092. }
  1093. }
  1094. arr.isWeak = false;
  1095.  
  1096. }
  1097.  
  1098. if (MemoryFix_Flag002 & 256) {
  1099. Object.defineProperty(tpProto, '__instances', {
  1100. get() {
  1101. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  1102. let arr = this.__instances_actual471__;
  1103. if (arr && arr.isWeak) {
  1104. convertToNormalArr(arr);
  1105. for (let i = arr.length - 1; i >= 0; i--) {
  1106. if (!arr[i]) arr.splice(i, 1);
  1107. }
  1108. Promise.resolve(arr).then(convertToWeakArr);
  1109. }
  1110. return arr;
  1111. },
  1112. set(nv) {
  1113. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  1114. this.__instances_actual471__ = nv;
  1115. if (nv && !nv.isWeak) {
  1116. Promise.resolve(nv).then(convertToWeakArr);
  1117. }
  1118. return true;
  1119. },
  1120. enumerable: false,
  1121. configurable: true
  1122. });
  1123. }
  1124.  
  1125. // console.log(91901, tpProto.__detachInstance)
  1126. if (MemoryFix_Flag002 & 32) {
  1127. if (tpProto.__detachInstance) {
  1128. fixDetachFn(tpProto);
  1129. } else {
  1130. Promise.resolve(tpProto).then((tpProto) => {
  1131. // console.log(91902, tpProto.__detachInstance)
  1132. fixDetachFn(tpProto);
  1133. })
  1134. }
  1135. }
  1136.  
  1137. }
  1138.  
  1139. if (MemoryFix_Flag002 & 32) {
  1140. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  1141. set(nv) {
  1142. if (nv === true) return false;
  1143. tpProto = this;
  1144. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  1145. tpProto.__domDX37__ = true;
  1146. ytTemplateDomEntry(tpProto);
  1147. }
  1148. this.__ensureTemplatized949__ = nv;
  1149. return true;
  1150. },
  1151. get() {
  1152. return this.__ensureTemplatized949__;
  1153. }
  1154. });
  1155. }
  1156.  
  1157.  
  1158. if (MemoryFix_Flag002 & 64) {
  1159. HTMLElement_.prototype.__dataHostBinding374 = true;
  1160. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  1161. get() {
  1162. return kRef(this.__dataHostWr413__);
  1163. },
  1164. set(nv) {
  1165. if (nv && typeof nv === 'object' && !nv.deref) {
  1166. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1167. nv = nv[wk];
  1168. }
  1169. this.__dataHostWr413__ = nv;
  1170. return true;
  1171. }
  1172. });
  1173. }
  1174.  
  1175.  
  1176. const setupYProto = function (yProto) {
  1177.  
  1178. if(yProto === Object.prototype) return;
  1179.  
  1180. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  1181. yProto[kMap.get(yProto)] = true;
  1182.  
  1183. if (MemoryFix_Flag002 & 32) {
  1184. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  1185. fixDetachFn(yProto);
  1186. }
  1187. }
  1188.  
  1189. if (MemoryFix_Flag002 & 128) {
  1190. if (!yProto.__dataHostBinding374) {
  1191. yProto.__dataHostBinding374 = true;
  1192. Object.defineProperty(yProto, '__dataHost', {
  1193. set(nv) {
  1194. let dh = nv;
  1195. if (dh && typeof dh === 'object' && !dh.deref) {
  1196. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  1197. dh = wr;
  1198. }
  1199. this[symDH] = dh;
  1200. return true;
  1201. },
  1202. get() {
  1203. let wr = this[symDH];
  1204. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  1205. return obj;
  1206. },
  1207. enumerable: false,
  1208. configurable: true
  1209. });
  1210. }
  1211.  
  1212.  
  1213.  
  1214. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  1215. yProto._registerHostDX38__ = true;
  1216.  
  1217. // yProto._registerHost7133 = yProto._registerHost;
  1218.  
  1219. yProto.__enableOrFlushClients = function () {
  1220. const c_ = this.__dataPendingClients;
  1221. if (c_) {
  1222. const c = c_.slice();
  1223. c_.length = 0;
  1224. for (let d = 0, l = c.length; d < l; d++) {
  1225. let e = kRef(c[d]);
  1226. if (e) {
  1227. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  1228. }
  1229. }
  1230. }
  1231. }
  1232.  
  1233. yProto._enqueueClient = function (c) {
  1234. if (c === this || !c || typeof c !== 'object') return;
  1235. if (c.deref) c = kRef(c);
  1236. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  1237. if (!c[wk]) c[wk] = mWeakRef(c);
  1238. m.push(c[wk]);
  1239. }
  1240.  
  1241. }
  1242. }
  1243.  
  1244.  
  1245.  
  1246. }
  1247. const setupRendering = function () {
  1248.  
  1249. const cnt = this;
  1250. const cProto = Reflect.getPrototypeOf(cnt);
  1251. let yProto = Reflect.getPrototypeOf(cProto);
  1252.  
  1253. const yProtos = new Set();
  1254.  
  1255. if (!yMap.has(yProto)) {
  1256. // capture all ancenstor constructors of a and b (non-specific component type)
  1257.  
  1258. do {
  1259. if (yProto === Object.prototype || yProto === null) break;
  1260. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  1261. yProtos.add(yProto);
  1262. yProto = Reflect.getPrototypeOf(yProto);
  1263. } while (!yProtos.has(yProto));
  1264.  
  1265. for (const yProto of yProtos) {
  1266. yMap.add(yProto);
  1267. setupYProto(yProto)
  1268. }
  1269.  
  1270. }
  1271.  
  1272.  
  1273. if (!cMap.has(cProto)) {
  1274. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  1275. setupCProto(cProto);
  1276. }
  1277.  
  1278. }
  1279.  
  1280. const selfRef = {}; // no change. just key
  1281.  
  1282.  
  1283. const sb1 = Symbol();
  1284. Object.defineProperty(Object.prototype, 'root', {
  1285. get() {
  1286. return this[sb1];
  1287. },
  1288. set(nv){
  1289. const p = this ? kRef(this) : null;
  1290. const mv = nv ? kRef(nv) : null;
  1291.  
  1292. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  1293. p.__setupRendered399__ = true;
  1294. setupRendering.call(p);
  1295. }
  1296. if (mv && mv.is && !mv.__setupRendered399__) {
  1297. mv.__setupRendered399__ = true;
  1298. setupRendering.call(mv);
  1299. }
  1300.  
  1301. this[sb1] = nv;
  1302. return true;
  1303. }
  1304. });
  1305.  
  1306.  
  1307. /*
  1308. let wm3 = new WeakMap();
  1309.  
  1310. Object.defineProperty(Object.prototype, 'root', {
  1311. get() {
  1312. const p = this ? kRef(this) : null;
  1313. const r = p ? wm3.get(p) : null;
  1314. const r2 = r ? kRef(r) : null;
  1315. if (r === selfRef) return p;
  1316. return r2;
  1317. },
  1318. set(nv) {
  1319. const p = this ? kRef(this) : null;
  1320. const mv = nv ? kRef(nv) : null;
  1321. if (typeof mv !== 'object') return;
  1322. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  1323. p.__setupRendered399__ = true;
  1324. setupRendering.call(p);
  1325. }
  1326. if (mv && mv.is && !mv.__setupRendered399__) {
  1327. mv.__setupRendered399__ = true;
  1328. setupRendering.call(mv);
  1329. }
  1330. if (mv === p) {
  1331. wm3.set(p, selfRef)
  1332. return true;
  1333. }
  1334. let gv = nv;
  1335. if (nv && !nv[wk]) {
  1336. gv = nv[wk] = mWeakRef(nv);
  1337. }
  1338. if (p) {
  1339. wm3.set(p, gv);
  1340. }
  1341. return true;
  1342. },
  1343. enumerable: false,
  1344. configurable: true
  1345. });
  1346. */
  1347.  
  1348.  
  1349. }
  1350.  
  1351. function getTranslate() {
  1352.  
  1353. pLoad.then(() => {
  1354.  
  1355. let nonce = document.querySelector('style[nonce]');
  1356. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1357. const st = document.createElement('style');
  1358. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1359. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  1360. let parent;
  1361. if (parent = document.head) parent.appendChild(st);
  1362. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  1363.  
  1364. });
  1365.  
  1366. const snCache = new Map();
  1367.  
  1368. if (TRANSLATE_DEBUG) {
  1369. console.log(11)
  1370. }
  1371.  
  1372. /** @type {(str: string?) => string} */
  1373. function _snippetText(str) {
  1374. // str can be underfinded
  1375. if (!str || typeof str !== 'string') return '';
  1376. let res = snCache.get(str);
  1377. if (res === undefined) {
  1378. let b = false;
  1379. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  1380. b = true;
  1381. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  1382. });
  1383. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  1384. b = true;
  1385. return '';
  1386. });
  1387. if (b) {
  1388. snCache.set(str, res);
  1389. snCache.set(res, null);
  1390. } else {
  1391. res = null;
  1392. snCache.set(str, null);
  1393. }
  1394. }
  1395. return res === null ? str : res;
  1396. }
  1397.  
  1398. /** @type {(snippet: Object) => string} */
  1399. function snippetText(snippet) {
  1400. let runs = snippet.runs;
  1401. const n = runs.length;
  1402. if (n === 1) return _snippetText(runs[0].text);
  1403. let res = new Array(n);
  1404. let ci = 0;
  1405. for (const s of runs) {
  1406. res[ci++] = _snippetText(s.text);
  1407. }
  1408. return res.join('\n');
  1409. }
  1410.  
  1411. const _DEBUG_szz = (t) => t.map(x => {
  1412. const tsr = x.transcriptSegmentRenderer;
  1413. return ({
  1414. t: tsr.snippet.runs.map(x => x.text).join('//'),
  1415. a: tsr.startMs,
  1416. b: tsr.endMs
  1417. });
  1418. });
  1419.  
  1420. const fixRuns = (runs) => {
  1421. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  1422. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  1423. const text = runs[0].text;
  1424. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  1425. const s = text.split(nlc);
  1426. let bi = 0;
  1427. runs.length = s.length;
  1428. for (const text of s) {
  1429. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  1430. }
  1431. }
  1432. for (const s of runs) {
  1433. s.text = _snippetText(s.text);
  1434. }
  1435. }
  1436.  
  1437. function translate(initialSegments) {
  1438. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  1439.  
  1440. if (!initialSegments) return initialSegments;
  1441.  
  1442. if (TRANSLATE_DEBUG) {
  1443. console.log(12);
  1444. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  1445. let obj = JSON.parse(r);
  1446. console.log(7558, 1, obj)
  1447. return obj;
  1448. }).then(p => {
  1449. let obj = _DEBUG_szz(p)
  1450. console.log(7558, 2, obj)
  1451. })
  1452. }
  1453.  
  1454.  
  1455. //let mapRej = new WeakSet();
  1456.  
  1457. const n1 = initialSegments.length;
  1458. if (!n1) return fRes;
  1459. let n2 = 0;
  1460.  
  1461.  
  1462. const fRes = new Array(n1);
  1463. // -----------------------------------------------------------------------------------------
  1464.  
  1465. const s8 = Symbol();
  1466.  
  1467. {
  1468.  
  1469. /** @type {Map<String, Object>} */
  1470. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  1471.  
  1472. // /-* * @type {Map<String, number>} *-/
  1473. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  1474. // 1: ok
  1475. // 2: abandoned effect text
  1476.  
  1477. for (const initialSegment of initialSegments) {
  1478. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  1479. if (!transcript) {
  1480. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1481. fRes[n2++] = initialSegment;
  1482. continue;
  1483. }
  1484. const runs = transcript.snippet.runs
  1485. if (!runs || runs.length === 0) {
  1486. initialSegment[s8] = true;
  1487. continue;
  1488. }
  1489. let startMs = (+transcript.startMs || 0); //integer
  1490. let endMs = (+transcript.endMs || 0); //integer
  1491. if (startMs === endMs) {
  1492. // effect text
  1493. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1494. //mapRej.add(initialSegment)
  1495. continue;
  1496. }
  1497. if (endMs - startMs < 30) {
  1498. continue;
  1499. }
  1500. const text = snippetText(transcript.snippet);
  1501. const hEntry = cacheTexts.get(text);
  1502. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  1503. if (mh1e === 2) continue;
  1504. const entry = {
  1505. startMs,
  1506. endMs,
  1507. initialSegment,
  1508. text
  1509. };
  1510. if (mh1e === 0) {
  1511. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  1512. initialSegment[s8] = true;
  1513. cacheTexts.set(text, null);
  1514. //effect only
  1515. // https://www.youtube.com/watch?v=zLak0dxBKpM
  1516. //mapRej.add(initialSegment)
  1517. continue;
  1518. }
  1519. } else if (hEntry) {
  1520.  
  1521. const timeDiff = entry.startMs - hEntry.endMs;
  1522. let shouldMerge = false;
  1523.  
  1524. if (timeDiff >= 0) {
  1525.  
  1526. if (timeDiff < 25) {
  1527. shouldMerge = true;
  1528. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  1529. shouldMerge = true;
  1530. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  1531. shouldMerge = true;
  1532. }
  1533.  
  1534. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  1535. // abandon the current entry.
  1536. // absorbed by previous entry
  1537. hEntry.endMs = entry.endMs;
  1538. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1539. //mapRej.add(entry.initialSegment);
  1540. continue;
  1541. }
  1542.  
  1543. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  1544.  
  1545. // abandon the current entry.
  1546. // absorbed by previous entry
  1547. if (entry.endMs > hEntry.endMs) {
  1548. hEntry.endMs = entry.endMs;
  1549. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1550. }
  1551. //mapRej.add(entry.initialSegment);
  1552. continue;
  1553.  
  1554. }
  1555.  
  1556. }
  1557. //if not abandoned
  1558. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  1559. // for (const s of runs) {
  1560. // s.text = _snippetText(s.text);
  1561. // }
  1562. fixRuns(runs);
  1563. fRes[n2++] = initialSegment;
  1564. }
  1565.  
  1566. // cacheTexts.clear(); // let GC do it.
  1567. cacheTexts = null;
  1568. // mh1.clear(); // let GC do it.
  1569. // mh1 = null;
  1570.  
  1571. }
  1572.  
  1573. const si_length = fRes.length = n2;
  1574. const sj_length = n1;
  1575.  
  1576. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  1577. // collect the abandon text to become second subtitle
  1578.  
  1579. let sj_start = 0;
  1580. let invalid_sj = -1;
  1581. for (let si = 0; si < si_length; si++) {
  1582. const segment = fRes[si];
  1583. let transcript = segment.transcriptSegmentRenderer;
  1584. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  1585. const runs = transcript.snippet.runs;
  1586. // fixRuns(runs);
  1587. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  1588. const main_startMs = (+transcript.startMs || 0);
  1589. const main_endMs = (+transcript.endMs || 0);
  1590. transcript = null;
  1591.  
  1592. /** @type {Map<string, number>} */
  1593. let tMap = new Map(); // avoid duplicate with javascript object properties
  1594.  
  1595. // assume that it is asc-ordered array of key startMs;
  1596. for (let sj = sj_start; sj < sj_length; sj++) {
  1597. const initialSegment = initialSegments[sj];
  1598.  
  1599. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  1600.  
  1601. const tSegment = initialSegment.transcriptSegmentRenderer;
  1602.  
  1603. if (!tSegment) {
  1604. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1605. invalid_sj = sj; // should invalid_sj be set ?
  1606. continue;
  1607. }
  1608.  
  1609. const startMs = (+tSegment.startMs || 0)
  1610. const isStartValid = startMs >= main_startMs;
  1611. if (!isStartValid) {
  1612. invalid_sj = sj;
  1613. continue;
  1614. }
  1615. // isStartValid must be true
  1616. if (startMs > main_endMs) {
  1617. sj_start = invalid_sj + 1;
  1618. break;
  1619. }
  1620.  
  1621. const endMs = (+tSegment.endMs || 0)
  1622. if (endMs <= main_endMs) {
  1623. const mt = snippetText(tSegment.snippet);
  1624. const prev = tMap.get(mt);
  1625. if (endMs >= startMs) {
  1626. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  1627. }
  1628. }
  1629.  
  1630. }
  1631.  
  1632. if (tMap.size <= 1) continue; // no second line
  1633. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  1634. tMap = null;
  1635.  
  1636. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1637.  
  1638. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  1639.  
  1640. let targetZ = rg[1][1];
  1641. if (targetZ > 4) {
  1642. let az = 0;
  1643. let fail = false;
  1644. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  1645. az += rg[idx][1];
  1646. if (az >= targetZ) {
  1647. fail = true;
  1648. break;
  1649. }
  1650. }
  1651. if (!fail) {
  1652. const rgA = rg[0][0];
  1653. const rgB = rg[1][0];
  1654. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  1655. if (isDiff && rgA === _snippetText(runs[0].text)) {
  1656. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  1657. runs.push({ text: rgB, blockLine: true });
  1658. }
  1659. }
  1660. }
  1661. rg = null;
  1662. }
  1663.  
  1664. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  1665.  
  1666. let obj = r;
  1667. console.log(7559, 1, obj)
  1668. return obj;
  1669. }).then(p => {
  1670. let obj = _DEBUG_szz(p)
  1671. console.log(7559, 2, obj)
  1672.  
  1673. });
  1674. }
  1675.  
  1676. // -----------------------------------------------------------------------------------------
  1677. snCache.clear();
  1678. return fRes;
  1679.  
  1680. }
  1681.  
  1682.  
  1683. return translate
  1684.  
  1685. }
  1686.  
  1687.  
  1688. let translateFn = null;
  1689.  
  1690. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  1691.  
  1692. const wmx = new WeakMap();
  1693.  
  1694. function fixSegments(ytObj) {
  1695. let a, b;
  1696. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  1697. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  1698. translateFn = translateFn || getTranslate();
  1699. let cSeg;
  1700. cSeg = wmx.get(seg);
  1701. if (!cSeg) {
  1702. let vSeg = null;
  1703. try {
  1704. vSeg = translateFn(seg);
  1705. } catch (e) {
  1706. }
  1707. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  1708. // console.log('translated', vSeg);
  1709. cSeg = vSeg;
  1710. wmx.set(seg, cSeg);
  1711. wmx.set(cSeg, cSeg);
  1712. }
  1713. }
  1714. if (cSeg && cSeg !== seg) {
  1715. a[b] = cSeg;
  1716. }
  1717. }
  1718.  
  1719. const dfn = Symbol();
  1720. const Object_ = Object;
  1721. Object_[dfn] = Object_.defineProperties;
  1722. let activation = true;
  1723. Object_.defineProperties = function (obj, pds) {
  1724. let segments, get_;
  1725. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  1726. activation = false;
  1727. segments.get = function () {
  1728. fixSegments(this);
  1729. return get_.call(this);
  1730. };
  1731. }
  1732. return Object_[dfn](obj, pds);
  1733. };
  1734.  
  1735. })();
  1736.  
  1737.  
  1738. let pf31 = new PromiseExternal();
  1739.  
  1740. // native RAF
  1741. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  1742.  
  1743. // 1st wrapped RAF
  1744. const baseRAF = (callback) => {
  1745. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  1746. pf31.then(() => {
  1747. callback(hRes);
  1748. });
  1749. });
  1750. };
  1751.  
  1752. // 2nd wrapped RAF
  1753. window.requestAnimationFrame = baseRAF;
  1754.  
  1755. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1756. const indr = o => insp(o).$ || o.$ || 0;
  1757.  
  1758. const prototypeInherit = (d, b) => {
  1759. const m = Object.getOwnPropertyDescriptors(b);
  1760. for (const p in m) {
  1761. if (!Object.getOwnPropertyDescriptor(d, p)) {
  1762. Object.defineProperty(d, p, m[p]);
  1763. }
  1764. }
  1765. };
  1766.  
  1767.  
  1768. const firstObjectKey = (obj) => {
  1769. for (const key in obj) {
  1770. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1771. }
  1772. return null;
  1773. };
  1774.  
  1775. function searchNestedObject(obj, predicate, maxDepth = 64) {
  1776. // normal case: depth until 36
  1777. const result = [];
  1778. const visited = new WeakSet();
  1779.  
  1780. function search(obj, depth) {
  1781. visited.add(obj);
  1782. for (const [key, value] of Object.entries(obj)) {
  1783. // Recursively search nested objects and arrays
  1784. if (value !== null && typeof value === 'object') {
  1785. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  1786. if (depth + 1 <= maxDepth && !visited.has(value)) {
  1787. search(value, depth + 1);
  1788. }
  1789. } else if (predicate(value)) {
  1790. result.push([obj, key]);
  1791. }
  1792. }
  1793. }
  1794.  
  1795. typeof (obj || 0) === 'object' && search(obj, 0);
  1796. return result;
  1797. }
  1798.  
  1799. /** @type {(o: Object | null) => WeakRef | null} */
  1800. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1801.  
  1802. /** @type {(wr: Object | null) => Object | null} */
  1803. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1804.  
  1805. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  1806.  
  1807. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  1808. if (DENY_requestStorageAccess) {
  1809. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  1810. Document.prototype.requestStorageAccessFor = undefined;
  1811. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  1812. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  1813. Document.prototype.requestStorageAccessFor = function () {
  1814. return new Promise((resolve, reject) => {
  1815. reject();
  1816. });
  1817. };
  1818. }
  1819. }
  1820.  
  1821. const traceStack = (stack) => {
  1822. let result = new Set();
  1823. let p = new Set();
  1824. let u = ''
  1825. for (const s of stack.split('\n')) {
  1826. if (s.split(':').length < 3) continue;
  1827. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  1828. if (!m) continue;
  1829. p.add(m[2]);
  1830. if (p.size >= 3) break;
  1831. if(!u) u = m[2];
  1832. else if(p.size === 2 && u && u=== m[2]) break;
  1833. result.add(s);
  1834. }
  1835. return [...result].join('\n');
  1836. }
  1837.  
  1838. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  1839. // window.m3bb = new Set();
  1840.  
  1841. // const smb = Symbol();
  1842. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  1843. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  1844. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  1845.  
  1846. const thisConversionFn = (thisArg) => {
  1847. if (!thisArg) return null;
  1848. const kThis = thisArg[vmb];
  1849. if (kThis) {
  1850. const ref = kThis.ref;
  1851. return (ref ? kRef(ref) : null) || null;
  1852. }
  1853. return thisArg;
  1854. }
  1855.  
  1856. const pFnHandler2 = {
  1857. get(target, prop) {
  1858. if (prop === vmc) return target;
  1859. return Reflect.get(target, prop);
  1860. },
  1861. apply(target, thisArg, argumentsList) {
  1862. thisArg = thisConversionFn(thisArg);
  1863. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  1864. }
  1865. }
  1866.  
  1867.  
  1868. const proxySelfHandler = {
  1869. get(target, prop) {
  1870. if(prop === vmb) return target;
  1871. const ref = target.ref;
  1872. const cnt = kRef(ref);
  1873. if (!cnt) return;
  1874. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  1875. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  1876. return cnt[prop][vmd];
  1877. }
  1878. return cnt[prop];
  1879. },
  1880. set(target, prop, value) {
  1881. const cnt = kRef(target.ref);
  1882. if (!cnt) return true;
  1883. if(value && (value[vmc] || value[vmb])){
  1884. cnt[prop] = value[vmc] || thisConversionFn(value);
  1885. return true;
  1886. }
  1887. cnt[prop] = value;
  1888. return true;
  1889. }
  1890. };
  1891.  
  1892. const weakWrap = (thisArg) => {
  1893. thisArg = thisConversionFn(thisArg);
  1894. if (!thisArg) {
  1895. console.error('thisArg is not found');
  1896. return null;
  1897. }
  1898. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  1899. }
  1900.  
  1901. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  1902. window.getComputedStyle533 = window.getComputedStyle;
  1903. window.getComputedStyle = function (a, ...args) {
  1904. a = thisConversionFn(a);
  1905. if (a) {
  1906. return getComputedStyle533(a, ...args);
  1907. }
  1908. return null;
  1909. }
  1910. }
  1911.  
  1912. Function._count_bind_00 = 0;
  1913. // Function._count_bind_01 = 0;
  1914.  
  1915. // let matchNativeCode = (Object+"");
  1916. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1917. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1918.  
  1919. // const matchConstructor = (thisArg) => {
  1920. // const f = `${(thisArg || 0).constructor}`;
  1921. // if (f.length > 45) return true;
  1922. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1923. // if (f.includes('[native code]')){
  1924. // return false;
  1925. // }
  1926. // return true;
  1927. // }
  1928. // return false;
  1929. // }
  1930.  
  1931. // const acceptThis = (thisArg)=>{
  1932. // // if(!thisArg || typeof thisArg !=='object') return false;
  1933. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1934. // // if(typeof thisArg.path === 'string') return true;
  1935. // // if(typeof thisArg.fn === 'function') return true;
  1936. // // if(typeof thisArg.id === 'string') return true;
  1937. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1938. // return false;
  1939. // }
  1940.  
  1941. const patchFn = (fn) => {
  1942.  
  1943. let s = `${fn}`;
  1944. if (s.length < 11 || s.includes('\n')) return false;
  1945. if(s.includes('bind(this')) return true;
  1946. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1947. // var a=this;
  1948. // f.bind(this)
  1949.  
  1950.  
  1951. return false;
  1952. }
  1953.  
  1954. Function.prototype.bind488 = Function.prototype.bind;
  1955. Function.prototype.bind = function(thisArg, ...args){
  1956.  
  1957. if (thisConversionFn(thisArg) !== thisArg) {
  1958. return this.bind488(thisArg, ...args);
  1959. }
  1960. if( thisArg && patchFn(this) ){
  1961.  
  1962. // console.log(599,`${this}`)
  1963.  
  1964. try {
  1965. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1966. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1967. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1968. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1969. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1970. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1971. // // let b4 = false;
  1972. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1973.  
  1974. // // b3 = false;
  1975. // // b4 = false;
  1976. // // b5 = false;
  1977.  
  1978. // if (b1 || b2 || b3 ||b4 ) {
  1979. const f = this;
  1980. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1981. if (ps && ps[vmb]) {
  1982. Function._count_bind_00++;
  1983. return f.bind488(ps, ...args)
  1984. }
  1985. // }
  1986. } catch (e) {
  1987. console.warn(e)
  1988. }
  1989. }
  1990. return this.bind488(thisArg, ...args);
  1991. }
  1992. Function.prototype.bind588 = 1;
  1993. }
  1994.  
  1995. const ytSchedulerMethods = {
  1996. addJob(a, b, c) {
  1997. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1998. if (instance) {
  1999. return instance.addJob(a, b, c);
  2000. } else {
  2001. return setTimeout(a, c);
  2002. }
  2003. },
  2004. addImmediateJob(a) {
  2005. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  2006. if (instance) {
  2007. return instance.addImmediateJob(a);
  2008. } else {
  2009. a();
  2010. }
  2011. },
  2012. cancelJob(id) {
  2013. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  2014. if (instance) {
  2015. return instance.cancelJob(id);
  2016. } else {
  2017. return clearTimeout(id);
  2018. }
  2019. }
  2020. };
  2021.  
  2022. if (FIX_ytScheduler) {
  2023.  
  2024. let ytSchedulerFixed = 0;
  2025. // let ytActioned = false;
  2026. // let pr = new PromiseExternal();
  2027.  
  2028. // const hn = function () {
  2029.  
  2030. // document.removeEventListener('yt-action', hn, true);
  2031. // nextBrowserTick_(() => {
  2032. // ytActioned = true;
  2033. // pr.resolve();
  2034. // });
  2035.  
  2036. // }
  2037. // document.addEventListener('yt-action', hn, true);
  2038.  
  2039. // let cancelStore = {}; // tbc
  2040.  
  2041. // yt.scheduler.instance.addJob
  2042. const fixAddJob = (nv) => {
  2043.  
  2044. /*
  2045. function Z() {
  2046. var a = w("ytglobal.schedulerInstanceInstance_");
  2047. if (!a || a.s)
  2048. a = new M(I("scheduler") || {}),
  2049. x("ytglobal.schedulerInstanceInstance_", a);
  2050. return a
  2051. }
  2052. */
  2053.  
  2054. /*
  2055. function R(a, b, c, d) {
  2056. ++a.D;
  2057. if (c === 10)
  2058. return P(a, b),
  2059. a.D;
  2060. var e = a.D;
  2061. a.h[e] = b;
  2062. a.l && !d ? a.u.push({
  2063. id: e,
  2064. priority: c
  2065. }) : (a.i[c].push(e),
  2066. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  2067. a.start()));
  2068. return e
  2069. }
  2070. */
  2071.  
  2072. /*
  2073. function sa(a, b, c) {
  2074. if (!c)
  2075. return c = c === void 0,
  2076. -R(Z(), a, b, c);
  2077. var d = window.setTimeout(function() {
  2078. var e = R(Z(), a, b);
  2079. W[d] = e
  2080. }, c);
  2081. return d
  2082. }
  2083. */
  2084. window.originalAddJob = nv;
  2085. // const q1 = new PromiseExternal();
  2086. // const q2 = new PromiseExternal();
  2087. // let uu = 0;
  2088. // let q3 = 0;
  2089. // let mof = null;
  2090. // const mo = new MutationObserver((mutation, observer) => {
  2091. // if (mof) {
  2092. // if (mof() === true) {
  2093. // observer.disconnect();
  2094. // mof = null;
  2095. // }
  2096. // }
  2097. // });
  2098.  
  2099. let lenSkip = -1;
  2100. let lastLen = null;
  2101. let fetchCommentJobTimerId = 0;
  2102. let requestFinish = false;
  2103.  
  2104. const fetchCommentJobDone = ()=>{
  2105. clearInterval(fetchCommentJobTimerId);
  2106. fetchCommentJobTimerId = 0;
  2107. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  2108. }
  2109.  
  2110. const fetchCommentJob = (a, cid) => {
  2111.  
  2112. // if (cid && cancelStore[cid]) return; // tbc
  2113.  
  2114. if(fetchCommentJobTimerId > 0){
  2115. fetchCommentJobDone();
  2116. }
  2117.  
  2118. // if (mof) {
  2119. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  2120. // mof = null;
  2121. // }
  2122.  
  2123. let f = a;
  2124.  
  2125. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  2126.  
  2127. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  2128.  
  2129. lastLen = -1;
  2130. let u = 0;
  2131. let g = () => {
  2132. if (requestFinish) lastLen = -1;
  2133. const lastLen_ = lastLen;
  2134. const len1 = lastLen = document.querySelectorAll(selector).length;
  2135. let mm = true;
  2136. let ff = false;
  2137. if (len1 !== lastLen_) {
  2138. u = 0;
  2139. f();
  2140. const len2 = lastLen = document.querySelectorAll(selector).length;
  2141. if (len2 !== len1) {
  2142. ff = true;
  2143. mm = false;
  2144. }
  2145. }
  2146. if (mm) {
  2147. ++u;
  2148. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  2149. ff = true;
  2150. }
  2151. }
  2152.  
  2153. if (requestFinish) {
  2154. requestFinish = false;
  2155. fetchCommentJobDone();
  2156. } else if (ff){
  2157. fetchCommentJobDone();
  2158. }
  2159.  
  2160. }
  2161.  
  2162.  
  2163. fetchCommentJobTimerId = setInterval(g, 80);
  2164. // g(9);
  2165. // if (lastLen === lenSkip) {
  2166. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  2167. // g = f = null;
  2168. // return;
  2169. // }
  2170. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  2171. // const q1 = lastLen;
  2172. // mof = () => {
  2173. // const q2 = document.querySelectorAll(selector).length;
  2174. // if (q1 === q2) return;
  2175. // fetchCommentJobTimerId = setTimeout(g, 80);
  2176. // g = null;
  2177. // return true;
  2178. // }
  2179. // mo.observe(document, { childList: true, subtree: true });
  2180.  
  2181. }
  2182.  
  2183. // let pr72 = Promise.resolve();
  2184.  
  2185.  
  2186. let qa = null;
  2187. let qasf = '';
  2188.  
  2189.  
  2190. document.addEventListener("fullscreenchange", (evt) => {
  2191. if (evt.isTrusted !== true) return;
  2192. if (qa) {
  2193. // qa();
  2194. nextBrowserTick_(qa);
  2195. }
  2196. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  2197. // pr72 = pr72.then(() => {
  2198. // return pr
  2199. // });
  2200. }, true);
  2201.  
  2202. window.addEventListener("resize", (evt) => {
  2203. if (evt.isTrusted !== true) return;
  2204. if (qa) {
  2205. // qa();
  2206. nextBrowserTick_(qa);
  2207. }
  2208. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  2209. // pr72 = pr72.then(() => {
  2210. // return pr
  2211. // });
  2212. }, true);
  2213.  
  2214.  
  2215. setInterval(() => {
  2216. const f = qa;
  2217. if (typeof f !== 'function') return;
  2218. qa = null;
  2219. // pr72 = pr72.then(() => {
  2220. // f();
  2221. // });
  2222. // nextBrowserTick_(()=>{
  2223. f();
  2224. // });
  2225. }, 475.25);
  2226.  
  2227.  
  2228.  
  2229. return function (a, b, c) {
  2230.  
  2231.  
  2232. const f = a;
  2233. // const g = ()=>{
  2234. // pr72 = pr72.then(()=>{
  2235. // f();
  2236. // });
  2237. // }
  2238.  
  2239. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  2240.  
  2241. const c_ = c;
  2242.  
  2243. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  2244.  
  2245. if (b === 1 && c_ === 500) {
  2246. const sf = `${a}`;
  2247. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  2248. qasf = sf;
  2249. qa = a;
  2250. // console.log(12883, a)
  2251. return nv(() => {
  2252. if (qa === a) {
  2253. qa = null;
  2254. a();
  2255. }
  2256. }, b, c);
  2257. }
  2258. }
  2259.  
  2260.  
  2261. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  2262. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  2263. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  2264. // pr72 = pr72.then(() => {
  2265. // return pr
  2266. // });
  2267. // try {
  2268. // yt.scheduler.instance.cancelAllJobs();
  2269. // yt.scheduler.instance.dispose();
  2270. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  2271. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  2272. // } catch (e) { }
  2273. return nv(f, b, c);
  2274. }
  2275.  
  2276. // if(!b && c > 50) c = 50;
  2277. // console.log(58372,a,b,c)
  2278. // function(){xxx(xxx)}
  2279. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  2280.  
  2281. /*
  2282.  
  2283. V.setCommentsJobId = _.et(_.r0, function() {
  2284. F5V(V)
  2285. }, 1E3)
  2286.  
  2287. */
  2288.  
  2289. requestFinish = false;
  2290. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  2291.  
  2292. // lastLen = null;
  2293. fetchCommentJob(a, cid);
  2294.  
  2295. // queueMicrotask_(a);
  2296. // nextBrowserTick_(a);
  2297. // a(); // no need to delay
  2298. return cid
  2299.  
  2300. // return nv(a, b, 1.125);
  2301. // const cid = window.setTimeout(() => {
  2302. // nextBrowserTick_(() => {
  2303. // if (cancelStore[cid]) {
  2304. // console.log('task cancelled');
  2305. // return;
  2306. // }
  2307. // a();
  2308.  
  2309. // });
  2310. // }, 0.125);
  2311. // return cid;
  2312. } else {
  2313.  
  2314.  
  2315.  
  2316. return nv(f,b,c);
  2317.  
  2318.  
  2319. // if (c > 2400) c = 2400;
  2320. // else if (c > 800) c = 800;
  2321. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  2322. // if (0 && ytActioned && !b) {
  2323. // const cid = window.setTimeout(() => {
  2324. // nextBrowserTick_(() => {
  2325. // if (cancelStore[cid]) {
  2326. // console.log('task cancelled');
  2327. // return;
  2328. // }
  2329. // a();
  2330. // });
  2331. // }, c);
  2332. // return cid;
  2333. // } else {
  2334. // return nv(a, b, c);
  2335. // }
  2336.  
  2337. }
  2338. }
  2339. }
  2340.  
  2341. const fixCancelJob = (nv) => {
  2342.  
  2343.  
  2344. window.originalCancelJob = nv;
  2345. return function (a) {
  2346. if (a < 0) return nv(a);
  2347. // cancelStore[a] = true; // tbc
  2348. nv(a);
  2349. }
  2350. }
  2351.  
  2352. const sk44 = Symbol();
  2353. Object.defineProperty(Object.prototype, 'addJob', {
  2354. get() {
  2355. return this[sk44];
  2356. },
  2357. set(nv) {
  2358. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2359. ytSchedulerFixed |= 1;
  2360. nv = fixAddJob(nv);
  2361. }
  2362. this[sk44] = nv;
  2363. return true;
  2364. },
  2365. enumerable: false,
  2366. configurable: true
  2367. });
  2368.  
  2369.  
  2370.  
  2371. const sk45 = Symbol();
  2372. Object.defineProperty(Object.prototype, 'cancelJob', {
  2373. get() {
  2374. return this[sk45];
  2375. },
  2376. set(nv) {
  2377. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2378. ytSchedulerFixed |= 2;
  2379. nv = fixCancelJob(nv);
  2380. }
  2381. this[sk45] = nv;
  2382. return true;
  2383. },
  2384. enumerable: false,
  2385. configurable: true
  2386. });
  2387.  
  2388.  
  2389.  
  2390. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2391. const { addJob, cancelJob } = yt.scheduler.instance;
  2392. if (addJob) {
  2393. yt.scheduler.instance.addJob = null;
  2394. yt.scheduler.instance.addJob = addJob;
  2395. }
  2396. if (cancelJob) {
  2397. yt.scheduler.instance.cancelJob = null;
  2398. yt.scheduler.instance.cancelJob = cancelJob;
  2399. }
  2400. }
  2401.  
  2402.  
  2403. }
  2404.  
  2405.  
  2406. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  2407. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  2408. const wm6 = new WeakMapOriginal();
  2409.  
  2410. const skipW = new WeakSet();
  2411.  
  2412.  
  2413. window.WeakMap = class WeakMap extends WeakMapOriginal {
  2414. constructor(iterable = undefined) {
  2415. super();
  2416. if (iterable && iterable[Symbol.iterator]) {
  2417. for (const entry of iterable) {
  2418. entry && this.set(entry[0], entry[1]);
  2419. }
  2420. }
  2421. }
  2422. delete(a) {
  2423. if (!this.has(a)) return false;
  2424. super.delete(a);
  2425. return true;
  2426. }
  2427. get(a) {
  2428. const p = super.get(a);
  2429. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  2430. let v = kRef(p);
  2431. if (!v) {
  2432. super.delete(a);
  2433. }
  2434. return v || undefined;
  2435. }
  2436. return p;
  2437. }
  2438. has(a) {
  2439. if (!super.has(a)) return false;
  2440. const p = super.get(a);
  2441. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  2442. if (!kRef(p)) {
  2443. super.delete(a);
  2444. return false;
  2445. }
  2446. }
  2447. return true;
  2448. }
  2449. set(a, b) {
  2450. let wq = b;
  2451. if (b && (typeof b === 'function' || typeof b === 'object')) {
  2452. if (b.deref) {
  2453. skipW.add(b);
  2454. wq = b;
  2455. } else {
  2456. wq = wm6.get(b);
  2457. if (!wq) {
  2458. wq = mWeakRef(b);
  2459. wm6.set(b, wq);
  2460. }
  2461. }
  2462. }
  2463. super.set(a, wq);
  2464. return this;
  2465. }
  2466. }
  2467. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  2468. configurable: true,
  2469. enumerable: false,
  2470. value: "WeakMap",
  2471. writable: false
  2472. });
  2473. }
  2474.  
  2475. const isWatchPageURL = (url) => {
  2476. url = url || location;
  2477. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  2478. };
  2479.  
  2480. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  2481.  
  2482. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  2483. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  2484. if (typeof customElements === 'undefined') {
  2485. if (!('__CE_registry' in document)) {
  2486. // https://github.com/webcomponents/polyfills/
  2487. Object.defineProperty(document, '__CE_registry', {
  2488. get() {
  2489. // return undefined
  2490. },
  2491. set(nv) {
  2492. if (typeof nv == 'object') {
  2493. delete this.__CE_registry;
  2494. this.__CE_registry = nv;
  2495. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2496. }
  2497. return true;
  2498. },
  2499. enumerable: false,
  2500. configurable: true
  2501. })
  2502. }
  2503. let eventHandler = (evt) => {
  2504. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2505. const f = callback;
  2506. callback = null;
  2507. eventHandler = null;
  2508. f();
  2509. };
  2510. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2511. } else {
  2512. callback();
  2513. }
  2514. });
  2515.  
  2516. const whenCEDefined = isCustomElementsProvided
  2517. ? (nodeName) => customElements.whenDefined(nodeName)
  2518. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  2519.  
  2520. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  2521. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  2522. const f = performance.now23 = Performance.prototype.now;
  2523.  
  2524. let k = 0; // 0 <= k < 9998m
  2525. let u = 0;
  2526. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  2527.  
  2528. // By definition, performance.now() is mono increasing.
  2529. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  2530. performance.now = performance.now16 = function () {
  2531. /**
  2532. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  2533. *
  2534. * If consecutive session history entries had history.state.entryTime set to same value,
  2535. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  2536. * and modifying its return value slightly to make sure two close consecutive calls don't
  2537. * get the same result helped with resolving the issue.
  2538. */
  2539. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  2540. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  2541.  
  2542. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  2543. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  2544. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  2545. else { // more than 9998 consecutive calls
  2546. /**
  2547. *
  2548. * max no. of consecutive calls
  2549. *
  2550. * Sample Size: 4800
  2551. * Sample Avg = 1565.375
  2552. * Sample Median = 1469.5
  2553. * Sample Max = 5660 << 7500 << 9999
  2554. *
  2555. *
  2556. * */
  2557. k = 0;
  2558. s += 1 / 7;
  2559. }
  2560. return v + k; // 0 < v - M < v - M + k < v
  2561. }
  2562.  
  2563. let loggerMsg = '';
  2564. if (`${performance.now()}` === `${performance.now()}`) {
  2565. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  2566. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  2567. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  2568. }
  2569. loggerMsg && console.warn(loggerMsg);
  2570. })();
  2571.  
  2572. // let __forceRemoveMode__ = false;
  2573. FIX_removeChild && (() => {
  2574. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  2575. let internalByPass = false;
  2576. const fragD = document.createDocumentFragment();
  2577. fragD.appendChild4201 = fragD.appendChild;
  2578. fragD.removeChild4201 = fragD.removeChild;
  2579. Node.prototype.removeChild062 = Node.prototype.removeChild;
  2580. Node.prototype.removeChild = function (child) {
  2581. try {
  2582. return this.removeChild062(child);
  2583. } catch (e) { }
  2584. if (internalByPass) return child;
  2585. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  2586. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  2587. if (idx >= 0) {
  2588. internalByPass = true;
  2589. child.parentNode !== fragD && fragD.appendChild4201(child);
  2590. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  2591. fragD.removeChild4201(child);
  2592. internalByPass = false;
  2593. return child;
  2594. }
  2595. }
  2596. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  2597. // // force removal
  2598. // internalByPass = true;
  2599. // child.parentNode !== fragD && fragD.appendChild4201(child);
  2600. // fragD.removeChild4201(child);
  2601. // internalByPass = false;
  2602. // return child;
  2603. // }
  2604. if (this && child) {
  2605. if (this.childNodes && this.childNodes.splice) { // tbc
  2606. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  2607. if (idx >= 0) {
  2608. internalByPass = true;
  2609. child.parentNode !== fragD && fragD.appendChild4201(child);
  2610. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  2611. fragD.removeChild4201(child);
  2612. internalByPass = false;
  2613. return child;
  2614. }
  2615. }
  2616.  
  2617. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  2618. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  2619. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  2620. return child;
  2621. }
  2622. }
  2623.  
  2624. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  2625. parent: this, child: child,
  2626. isParent: child.parentNode === this,
  2627. isParentParent: (child.parentNode || 0).parentNode === this,
  2628. parentNode: child.parentNode,
  2629. shadyParent: child.__shady_parentNode,
  2630. isShadyParent: child.__shady_parentNode === this,
  2631. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  2632. });
  2633.  
  2634. }
  2635. return child;
  2636. }
  2637. }
  2638. })();
  2639.  
  2640.  
  2641. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  2642.  
  2643. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  2644.  
  2645. // let cid = 0;
  2646.  
  2647. let mousemoveFn = null;
  2648. let mousemoveDT = 0;
  2649. let mousemoveCount = 0;
  2650. // let qv = false;
  2651. const cif = () => {
  2652. if (!mousemoveFn) return;
  2653. const ct = Date.now();
  2654. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  2655. mousemoveFn && mousemoveFn();
  2656. }
  2657. mousemoveFn = null;
  2658. };
  2659. let mousemoveCId = 0;
  2660. let mouseoverFn = null;
  2661. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  2662. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  2663. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2664. const bt = `${b}`;
  2665. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  2666. b[`__$$${a}$$1926__`] = true;
  2667. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  2668. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  2669. // console.log(3928, a, this[`__$$${a}$$1937__`])
  2670. if (!this[`__$$${a}$$1938__`]) {
  2671. this[`__$$${a}$$1938__`] = b;
  2672. if (a === 'mousemove') {
  2673. this.addEventListener4882('mouseenter', (evt) => {
  2674. if (mousemoveCId) return;
  2675. mousemoveCId = setIntervalX0(cif, 380);
  2676. });
  2677. this.addEventListener4882('mouseleave', (evt) => {
  2678. clearIntervalX0(mousemoveCId);
  2679. mousemoveCId = 0;
  2680. });
  2681. }
  2682. this.addEventListener4882(a, (evt) => {
  2683. const evt_ = evt;
  2684. if (!this[`__$$${a}$$1937__`]) return;
  2685. if (!this[`__$$${a}$$1938__`]) return;
  2686. if (a === 'mousemove') {
  2687. mouseoverFn && mouseoverFn();
  2688. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  2689. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  2690. } else {
  2691. mousemoveCount = 0;
  2692. }
  2693. const f = mousemoveFn = () => {
  2694. if (f !== mousemoveFn) return;
  2695. mousemoveFn = null;
  2696. this[`__$$${a}$$1938__`](evt_);
  2697. };
  2698. if (mousemoveCount <= 1) mousemoveFn();
  2699. } else {
  2700. if (a === 'mouseout' || a === 'mouseleave') {
  2701. mousemoveFn = null;
  2702. mousemoveDT = 0;
  2703. mousemoveCount = 0;
  2704. this[`__$$${a}$$1938__`](evt_);
  2705. mouseoverFn && mouseoverFn();
  2706. } else { // mouseover, mouseenter
  2707. mousemoveFn = null;
  2708. mousemoveDT = 0;
  2709. mousemoveCount = 0;
  2710. mouseoverFn && mouseoverFn(); // just in case
  2711. const f = mouseoverFn = () => {
  2712. if (f !== mouseoverFn) return;
  2713. mouseoverFn = null;
  2714. this[`__$$${a}$$1938__`](evt_);
  2715. }
  2716. nextBrowserTick_(mouseoverFn);
  2717. }
  2718. }
  2719. }, c);
  2720.  
  2721.  
  2722. return;
  2723. } else {
  2724.  
  2725. return;
  2726. }
  2727. }
  2728.  
  2729. }
  2730. return this.addEventListener4882(a, b, c)
  2731. }
  2732.  
  2733.  
  2734.  
  2735.  
  2736. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  2737. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  2738. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2739.  
  2740. if (b[`__$$${a}$$1926__`]) {
  2741. b[`__$$${a}$$1926__`] = false;
  2742.  
  2743. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  2744.  
  2745. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  2746.  
  2747. return;
  2748.  
  2749. }
  2750.  
  2751. }
  2752. return this.removeEventListener4882(a, b, c)
  2753. }
  2754.  
  2755.  
  2756. })();
  2757.  
  2758.  
  2759. FIX_DOM_IF_REPEAT && (() => {
  2760. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  2761. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  2762. // Be careful of the mixture of polymer functions and native Element functions
  2763. // Be careful of the coding design is different with the modern Yt elements
  2764.  
  2765.  
  2766. /*
  2767.  
  2768.  
  2769. function Ks(a, b, c) {
  2770. if (kj && !BOa(a))
  2771. throw Error("strictTemplatePolicy: template owner not trusted");
  2772. c = c || {};
  2773. if (a.__templatizeOwner)
  2774. throw Error("A <template> can only be templatized once");
  2775. a.__templatizeOwner = b;
  2776. var d = (b ? b.constructor : Js)._parseTemplate(a)
  2777. , e = d.templatizeInstanceClass;
  2778. e || (e = COa(a, d, c),
  2779. d.templatizeInstanceClass = e);
  2780. var g = BOa(a);
  2781. EOa(a, d, c, g);
  2782. c = function() {
  2783. return e.apply(this, arguments) || this
  2784. }
  2785. ;
  2786. h(c, e);
  2787. c.prototype._methodHost = g;
  2788. c.prototype.__dataHost = a;
  2789. c.prototype.__templatizeOwner = b;
  2790. c.prototype.__hostProps = d.hostProps;
  2791. return c
  2792. }
  2793.  
  2794. */
  2795.  
  2796. // Polymer.enqueueDebouncer
  2797.  
  2798. const s81 = Symbol();
  2799. const s83 = Symbol();
  2800. const s84 = Symbol();
  2801. const s85 = Symbol();
  2802. const s85b = Symbol();
  2803. const s85c = Symbol();
  2804.  
  2805. let renderDebounceTs = null;
  2806.  
  2807. let renderDebouncePromise = null;
  2808. let qp;
  2809.  
  2810. let cme = 0;
  2811.  
  2812. const shadyFlushMO = new MutationObserver(() => {
  2813.  
  2814. if (!renderDebounceTs) return;
  2815.  
  2816. if (renderDebounceTs.size > 0) {
  2817. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  2818. try {
  2819. Polymer.flush();
  2820. return;
  2821. } catch (e) { }
  2822. }
  2823.  
  2824. renderDebouncePromise && Promise.resolve().then(() => {
  2825.  
  2826. if (renderDebouncePromise) {
  2827. renderDebouncePromise && renderDebouncePromise.resolve();
  2828. renderDebouncePromise = null;
  2829. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  2830. }
  2831.  
  2832. });
  2833.  
  2834. // Polymer.flush
  2835.  
  2836. window.ShadyDOM && ShadyDOM.flush();
  2837. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  2838.  
  2839.  
  2840. });
  2841.  
  2842. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2843.  
  2844.  
  2845. let p = 0;
  2846. qp = observablePromise(() => {
  2847. if (!(p & 1)) {
  2848.  
  2849. if (window.ShadyDOM && ShadyDOM.flush) {
  2850. p |= 1;
  2851. if (!ShadyDOM.flush847) {
  2852.  
  2853. ShadyDOM.flush847 = ShadyDOM.flush;
  2854. ShadyDOM.flush = function () {
  2855.  
  2856. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  2857. renderDebouncePromise && Promise.resolve().then(() => {
  2858. if (renderDebouncePromise) {
  2859.  
  2860. renderDebouncePromise && renderDebouncePromise.resolve();
  2861. renderDebouncePromise = null;
  2862.  
  2863. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  2864.  
  2865. }
  2866.  
  2867. });
  2868. let r = this.flush847(...arguments);
  2869. if (r) {
  2870. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2871. }
  2872. return r
  2873. }
  2874.  
  2875. }
  2876. }
  2877. }
  2878.  
  2879. if (!(p & 2)) {
  2880.  
  2881. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  2882. p |= 2;
  2883. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  2884. if (!ScopingShim.flush848) {
  2885.  
  2886. ScopingShim.flush848 = ScopingShim.flush;
  2887. ScopingShim.flush = function () {
  2888.  
  2889. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  2890.  
  2891. renderDebouncePromise && Promise.resolve().then(() => {
  2892.  
  2893. if (renderDebouncePromise) {
  2894.  
  2895. renderDebouncePromise && renderDebouncePromise.resolve();
  2896. renderDebouncePromise = null;
  2897.  
  2898. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  2899.  
  2900.  
  2901.  
  2902. }
  2903.  
  2904. });
  2905. return this.flush848(...arguments);
  2906. }
  2907.  
  2908. }
  2909. }
  2910. }
  2911. if (p === 3) {
  2912. p |= 8;
  2913.  
  2914. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  2915. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  2916. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  2917.  
  2918. if (r) {
  2919. let w = Set.prototype.add;
  2920. let u = null;
  2921. Set.prototype.add = function () {
  2922. u = this;
  2923. throw new Error();
  2924. }
  2925. try {
  2926. Polymer.enqueueDebouncer()
  2927. } catch (e) { }
  2928. Set.prototype.add = w;
  2929. if (u !== null) {
  2930. renderDebounceTs = u;
  2931. if (DEBUG_renderDebounceTs) {
  2932. renderDebounceTs.add58438 = renderDebounceTs.add;
  2933. renderDebounceTs.add = function () {
  2934. console.log('renderDebounceTs.add')
  2935. console.log(traceStack((new Error()).stack))
  2936. // debugger;
  2937. return this.add58438(...arguments)
  2938. }
  2939.  
  2940. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  2941. renderDebounceTs.delete = function () {
  2942. console.log('renderDebounceTs.delete')
  2943. const stack = `${(new Error()).stack}`
  2944. let isCallbackRemoval = false;
  2945. if (stack) {
  2946. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  2947. const s = t.split(':');
  2948. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  2949. isCallbackRemoval = true;
  2950. }
  2951. }
  2952. if (isCallbackRemoval) {
  2953. return this.delete58438(...arguments)
  2954. }
  2955. console.log(traceStack((new Error()).stack))
  2956. // debugger;
  2957. return this.delete58438(...arguments)
  2958. }
  2959. }
  2960. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  2961. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  2962. }
  2963. }
  2964.  
  2965. return true;
  2966. }
  2967. })
  2968.  
  2969. // if(window.ShadyDOM && ShadyDOM.flush){
  2970. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  2971.  
  2972. // }
  2973. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  2974.  
  2975. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  2976. // }
  2977.  
  2978. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  2979.  
  2980. }
  2981.  
  2982. Object.defineProperty(Object.prototype, '_lastIf', {
  2983. get() {
  2984. return this[s81];
  2985. },
  2986. set(nv) {
  2987. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  2988. // DOM-IF initialization
  2989. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  2990.  
  2991. this.__xiWB8__ = 2;
  2992.  
  2993. const cProto = this.__proto__;
  2994. if (cProto && !cProto.__xiWB7__) {
  2995. cProto.__xiWB7__ = 1;
  2996.  
  2997. // dom-if __template
  2998. // dom-repeat template
  2999. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  3000. cProto.__template847 = true;
  3001. try {
  3002. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  3003. Object.defineProperty(cProto, '__template', {
  3004. get() {
  3005. const v = this[s84];
  3006. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  3007. },
  3008. set(nv) {
  3009. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  3010. this[s84] = nv;
  3011. return true;
  3012. }
  3013. });
  3014. } catch (e) {
  3015. console.warn(e);
  3016. }
  3017.  
  3018. console.log('FIX_DOM_IF - __template')
  3019. }
  3020.  
  3021. // dom-if __ensureTemplate
  3022. // dom-repeat __ensureTemplatized
  3023. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  3024. // note that "_templateInfo" diffs the different version of DOM-IF
  3025.  
  3026. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  3027. cProto.__ensureTemplate = function () {
  3028. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  3029. if (!this.__template) {
  3030. let b;
  3031. if (this._templateInfo) {
  3032. b = this;
  3033. } else {
  3034. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  3035. b = this.__templateCollection011__[0];
  3036. if (!b) {
  3037. if (!this[wk]) this[wk] = mWeakRef(this);
  3038. let a = this[wk];
  3039. let c = new MutationObserver(function () {
  3040. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  3041. if (c && a) {
  3042. c.disconnect();
  3043. a = kRef(a);
  3044. a && a.__render();
  3045. a && (a.__templateCollection011__ = null);
  3046. }
  3047. c = null;
  3048. a = null;
  3049. });
  3050. c && c.observe(this, {
  3051. childList: !0
  3052. });
  3053. return !1
  3054. } else {
  3055. this.__templateCollection011__ = null;
  3056. }
  3057. }
  3058. this.__template = b
  3059. }
  3060. return !0
  3061. }
  3062.  
  3063. console.log('FIX_DOM_IF - __ensureTemplate')
  3064.  
  3065. }
  3066.  
  3067.  
  3068. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  3069.  
  3070. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  3071.  
  3072. // cProto.__createAndInsertInstance = function (a) {
  3073. // Promise.resolve().then(()=>{
  3074. // console.log('__createAndInsertInstance')
  3075. // window.lm5 = window.lm5 || [];
  3076. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  3077. // });
  3078. // return this.__createAndInsertInstance847(a);
  3079. // }
  3080.  
  3081. // }
  3082.  
  3083.  
  3084. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  3085.  
  3086. // cProto._bindTemplate847 = cProto._bindTemplate;
  3087.  
  3088. // cProto._bindTemplate = function (a, b) {
  3089. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  3090. // }
  3091.  
  3092. // }
  3093. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  3094.  
  3095. // cProto._stampTemplate847 = cProto._stampTemplate;
  3096.  
  3097. // cProto._stampTemplate = function (a, b) {
  3098. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  3099. // }
  3100.  
  3101. // }
  3102. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  3103. }
  3104.  
  3105.  
  3106. // need to fix __observeEffects
  3107. // this.__observeEffects.if[0].info.method === this.__debounceRender
  3108. const f = () => {
  3109.  
  3110. const __observeEffects = this.__observeEffects;
  3111.  
  3112. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  3113. for (const effect of __observeEffects.if) {
  3114. const info = effect.info;
  3115. if (info && typeof info.method === 'function') {
  3116.  
  3117. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  3118. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  3119. }
  3120.  
  3121. }
  3122. }
  3123. }
  3124.  
  3125.  
  3126. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  3127. for (const effect of __observeEffects.restamp) {
  3128. const info = effect.info;
  3129. if (info && typeof info.method === 'function') {
  3130.  
  3131. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  3132. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  3133. }
  3134.  
  3135. }
  3136. }
  3137. }
  3138.  
  3139. // console.log(5881, this.__observeEffects)
  3140. }
  3141. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  3142. f();
  3143. Promise.resolve().then(f);
  3144. // afterward, don't care adding fn directly (the fn is already modified)
  3145. }
  3146.  
  3147. }
  3148. this[s81] = nv;
  3149. return true;
  3150. }
  3151. });
  3152.  
  3153.  
  3154. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  3155. get() {
  3156. return this[s85];
  3157. },
  3158. set(nv) {
  3159. if (nv === null && this[s85] === undefined) {
  3160. // DOM-IF / DOM-REPEAT initialization
  3161.  
  3162.  
  3163. const cProto = this.__proto__;
  3164. if (qp) {
  3165. qp.obtain();
  3166. qp = null;
  3167. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  3168. }
  3169. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  3170.  
  3171. cProto.__debounceRender847 = cProto.__debounceRender;
  3172.  
  3173. if (cProto.__debounceRender.length === 2) {
  3174.  
  3175. cProto.__debounceRender = function (a, b) {
  3176.  
  3177. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  3178.  
  3179. b = b === void 0 ? 0 : b;
  3180.  
  3181. /*
  3182. b = b === void 0 ? 0 : b;
  3183. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  3184. vs(this.__renderDebouncer)
  3185. */
  3186.  
  3187. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3188.  
  3189. if (!renderDebouncePromise) {
  3190. renderDebouncePromise = new PromiseExternal();
  3191. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  3192. }
  3193.  
  3194. renderDebouncePromise.then(async () => {
  3195. if (b > 0) await delayPn(b);
  3196.  
  3197. const f = this.__dsIRYqw1__;
  3198. if (f === cme) return;
  3199. this.__dsIRYqw1__ = cme;
  3200. a.call(this);
  3201. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  3202.  
  3203. });
  3204.  
  3205. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  3206. }
  3207.  
  3208. } else if (cProto.__debounceRender.length === 0) {
  3209.  
  3210.  
  3211. cProto.__debounceRender = function () {
  3212.  
  3213. if (!renderDebounceTs) return this.__debounceRender847();
  3214.  
  3215. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3216. /*
  3217. var a = this;
  3218. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  3219. return a.__render()
  3220. });
  3221. vs(this.__renderDebouncer)
  3222. */
  3223.  
  3224. if (!renderDebouncePromise) {
  3225. renderDebouncePromise = new PromiseExternal();
  3226. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  3227. }
  3228. renderDebouncePromise.then(() => {
  3229. const f = this.__dsIRYqw1__;
  3230. if (f === cme) return;
  3231. this.__dsIRYqw1__ = cme;
  3232. this.__render()
  3233. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  3234. });
  3235. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  3236.  
  3237.  
  3238. }
  3239. }
  3240. }
  3241.  
  3242.  
  3243.  
  3244. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  3245. // cProto.render847 = cProto.render;
  3246. // cProto.render = function(){
  3247.  
  3248. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3249. // try{
  3250. // this.render847();
  3251. // }catch(e){}
  3252. // // if(this.__DBR847__){
  3253. // // this.__DBR847__.resolve();
  3254. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  3255. // // }
  3256.  
  3257. // // renderDebouncePromise && renderDebouncePromise.resolve()
  3258. // // renderDebouncePromise = null;
  3259. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  3260.  
  3261. // }
  3262. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  3263. // }
  3264.  
  3265. }
  3266. this[s85] = nv;
  3267. return true;
  3268. }
  3269. });
  3270.  
  3271. // PS-DOM-REPEAT
  3272.  
  3273. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  3274. get() {
  3275. return this[s85b];
  3276. },
  3277. set(nv) {
  3278.  
  3279. this[s85b] = nv;
  3280. return true;
  3281. }
  3282. })
  3283.  
  3284. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  3285. get() {
  3286. return this[s85c];
  3287. },
  3288. set(nv) {
  3289.  
  3290. this[s85c] = nv;
  3291. return true;
  3292. }
  3293. })
  3294.  
  3295.  
  3296. })();
  3297.  
  3298. const setupXdeadC = (cnt)=>{
  3299.  
  3300. let xdeadc = xdeadc00;
  3301. if(!xdeadc){
  3302. setupSDomWrapper(); // just in case
  3303. const hostElement = cnt.hostElement;
  3304. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3305. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  3306. hostElement.lastChild.replaceWith(el);
  3307. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  3308. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3309. el.firstElementChild.id = rid;
  3310. cnt.$[rid] = el.firstElementChild;
  3311. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  3312.  
  3313. xdeadc = cnt.getStampContainer_(rid);
  3314. el.remove();
  3315. xdeadc00 = xdeadc;
  3316. // console.log(xdeadc.__domApi)
  3317. // debugger;
  3318. // const xdeadv = xdeadc.__domApi;
  3319. }
  3320.  
  3321. let xlivec = xlivec00;
  3322. if(!xlivec){
  3323. setupSDomWrapper(); // just in case
  3324. const hostElement = cnt.hostElement;
  3325. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3326. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  3327. hostElement.lastChild.replaceWith(el);
  3328. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  3329. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3330. el.firstElementChild.id = rid;
  3331. cnt.$[rid] = el.firstElementChild;
  3332. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  3333.  
  3334. xlivec = cnt.getStampContainer_(rid);
  3335. xlivec00 = xlivec;
  3336. // console.log(xdeadc.__domApi)
  3337. // debugger;
  3338. // const xdeadv = xdeadc.__domApi;
  3339. }
  3340.  
  3341. return xdeadc00;
  3342. }
  3343.  
  3344. let standardWrap_ = null;
  3345.  
  3346. const setupSDomWrapper = () => {
  3347.  
  3348. const sdwProto = ShadyDOM.Wrapper.prototype;
  3349.  
  3350. if (sdwProto.__pseudo__isConnected__ !== null) {
  3351. sdwProto.__pseudo__isConnected__ = null;
  3352. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  3353. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  3354. const get = isConnectedPd.get;
  3355. isConnectedPd.get = function () {
  3356. const pseudoVal = this.__pseudo__isConnected__;
  3357. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  3358. }
  3359. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  3360. }
  3361.  
  3362. // debugger;
  3363. // new xdeadc.__domApi.constructor(document.createElement('div'));
  3364. }
  3365.  
  3366. }
  3367.  
  3368. let domApiConstructor = null;
  3369. const setupDomApi = (daProto) => {
  3370.  
  3371. daProto.__daHook377__ = true;
  3372.  
  3373. domApiConstructor = daProto.constructor; // TBC
  3374.  
  3375. // TBC
  3376.  
  3377. }
  3378.  
  3379.  
  3380. // WEAKREF_ShadyDOM
  3381.  
  3382. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  3383.  
  3384. const setupPlainShadyDOM = (b) => {
  3385. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  3386. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  3387. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  3388. b.patchOnDemand = true;
  3389. b.preferPerformance = true;
  3390. b.noPatch = true;
  3391. }
  3392.  
  3393. const isPlainObject = (b, m) => {
  3394. if (!b || typeof b !== 'object') return false;
  3395. const e = Object.getOwnPropertyDescriptors(b);
  3396. if (e.length <= m) return false;
  3397. let pr = 0;
  3398. for (const k in e) {
  3399. const d = e[k];
  3400. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  3401. if (!('value' in d) || typeof d.value === 'function') return false;
  3402. pr++;
  3403. }
  3404. return pr > m;
  3405. }
  3406.  
  3407. let b;
  3408.  
  3409. let lz = 0;
  3410.  
  3411. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  3412. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  3413.  
  3414. // Brave - ShadyDOM exists before userscripting
  3415. b = sdp.value;
  3416.  
  3417. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  3418. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  3419. lz = 1;
  3420. }
  3421.  
  3422. }
  3423.  
  3424.  
  3425. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  3426. } else if (!sdp) {
  3427. } else {
  3428. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  3429. return;
  3430. }
  3431.  
  3432. const shadyDOMNodeWRM = new WeakMap();
  3433.  
  3434. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  3435.  
  3436. const weakWrapperNodeHandlerFn = () => ({
  3437. get() {
  3438. const wv = this[wk];
  3439. if (typeof wv === 'undefined') return undefined;
  3440. let node = kRef(wv);
  3441. if (!node) this[wk] = undefined;
  3442. return node || undefined;
  3443. },
  3444. set(nv) {
  3445. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  3446. this[wk] = wv;
  3447. return true;
  3448. },
  3449. enumerable: true,
  3450. configurable: true
  3451. });
  3452.  
  3453.  
  3454. function weakWrapper(_ShadyDOM) {
  3455. const ShadyDOM = _ShadyDOM;
  3456. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  3457. let nullElement = { node: null };
  3458. Object.setPrototypeOf(nullElement, Element.prototype);
  3459. let p = new ShadyDOM.Wrapper(nullElement);
  3460. let d = Object.getOwnPropertyDescriptor(p, 'node');
  3461. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  3462. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  3463. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  3464. }
  3465.  
  3466. }
  3467. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  3468. try {
  3469. setupSDomWrapper();
  3470. } catch (e) { }
  3471. }
  3472.  
  3473. }
  3474.  
  3475. let previousWrapStore = null;
  3476.  
  3477. const standardWrap = function (a) {
  3478. // if(a && a.deref) a= a.deref();
  3479. if(!a) return a;
  3480. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  3481. if (previousWrapStore) {
  3482. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  3483. if (s) {
  3484. previousWrapStore.delete(a);
  3485. shadyDOMNodeWRM.set(a, mWeakRef(s));
  3486. }
  3487. }
  3488. let u = kRef(shadyDOMNodeWRM.get(a));
  3489. if (!u) {
  3490. u = new ShadyDOM.Wrapper(a);
  3491. shadyDOMNodeWRM.set(a, mWeakRef(u));
  3492. }
  3493. return u;
  3494. }
  3495.  
  3496. standardWrap_ = standardWrap;
  3497.  
  3498.  
  3499. function setupWrapFunc(_ShadyDOM) {
  3500. const ShadyDOM = _ShadyDOM;
  3501.  
  3502.  
  3503. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  3504. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  3505. return;
  3506. }
  3507. let mm = new Set();
  3508. const pget = wmPD.value;
  3509. WeakMap.prototype.get = function (a) {
  3510. mm.add(this);
  3511. return a;
  3512. }
  3513. try {
  3514. let nullElement = { node: null };
  3515. Object.setPrototypeOf(nullElement, Element.prototype);
  3516. ShadyDOM.wrapIfNeeded(nullElement)
  3517. ShadyDOM.wrap(nullElement)
  3518. } catch (e) { }
  3519. WeakMap.prototype.get = pget;
  3520. if (mm.size !== 1) {
  3521. mm.clear();
  3522. return;
  3523. }
  3524. const p = mm.values().next().value;
  3525. if (!(p instanceof WeakMap)) return;
  3526. // p.clear();
  3527. // p.get = function (a) { return a }
  3528. // p.set = function (a, b) { return this }
  3529. // console.log(188, window.n2n = mm, window.n2p = p)
  3530.  
  3531. // console.log(34929,p.size)
  3532. previousWrapStore = p;
  3533.  
  3534. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  3535. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  3536. }
  3537. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  3538. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  3539. }
  3540.  
  3541. }
  3542.  
  3543. function setupLZ3(nv) {
  3544.  
  3545. const ShadyDOM = nv;
  3546.  
  3547. const ShadyDOMSettings = ShadyDOM.settings;
  3548. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3549. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3550. return false;
  3551. }
  3552.  
  3553. weakWrapper(ShadyDOM);
  3554.  
  3555. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3556.  
  3557. setupPlainShadyDOM(ShadyDOMSettings);
  3558. setupPlainShadyDOM(ShadyDOM);
  3559.  
  3560. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  3561.  
  3562. setupWrapFunc(ShadyDOM);
  3563. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  3564. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  3565.  
  3566. // To be confirmed
  3567. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  3568. ShadyDOM.composedPath = function (e) {
  3569. const t = (e || 0).target || null;
  3570. if (!(t instanceof HTMLElement_)) {
  3571. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  3572. }
  3573. return t instanceof HTMLElement_ ? [t] : [];
  3574. };
  3575. }
  3576.  
  3577. }
  3578.  
  3579. }
  3580.  
  3581.  
  3582. function setupLZ6(nv) {
  3583.  
  3584. const ShadyDOM = nv;
  3585.  
  3586. const ShadyDOMSettings = ShadyDOM.settings;
  3587.  
  3588. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3589. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3590. return false;
  3591. }
  3592.  
  3593. weakWrapper(ShadyDOM);
  3594.  
  3595. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3596.  
  3597. setupPlainShadyDOM(ShadyDOMSettings);
  3598. setupPlainShadyDOM(ShadyDOM);
  3599.  
  3600. setupWrapFunc(ShadyDOM);
  3601.  
  3602. }
  3603.  
  3604. }
  3605.  
  3606. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  3607.  
  3608. const nv = b;
  3609.  
  3610. if (setupLZ6(nv) === false) return;
  3611.  
  3612. lz = 6;
  3613.  
  3614. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  3615.  
  3616. return;
  3617. }
  3618.  
  3619. delete window.ShadyDOM;
  3620.  
  3621. Object.defineProperty(window, 'ShadyDOM', {
  3622. get() {
  3623. return b;
  3624. },
  3625. set(nv) {
  3626. let ret = 0;
  3627. try {
  3628. do {
  3629. if (!nv || !nv.settings) {
  3630. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  3631. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  3632. lz = 1;
  3633. break;
  3634. } else {
  3635. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  3636. break;
  3637. }
  3638. }
  3639.  
  3640. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  3641. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  3642. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  3643. break;
  3644. }
  3645.  
  3646. if (setupLZ3(nv) === false) break;
  3647.  
  3648. lz = 3;
  3649.  
  3650. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  3651.  
  3652. ret = 1;
  3653.  
  3654. } while (0);
  3655. } catch (e) {
  3656. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  3657. }
  3658.  
  3659. if (!ret) b = nv;
  3660. else {
  3661. delete this.ShadyDOM;
  3662. this.ShadyDOM = nv;
  3663. }
  3664. return true;
  3665. },
  3666. enumerable: false,
  3667. configurable: true
  3668. });
  3669.  
  3670. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  3671.  
  3672. if (ENABLE_ASYNC_DISPATCHEVENT) {
  3673. const filter = new Set([
  3674. 'yt-action',
  3675. // 'iframe-src-replaced',
  3676. 'shown-items-changed',
  3677. 'can-show-more-changed', 'collapsed-changed',
  3678.  
  3679. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  3680. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  3681. 'yt-navigate-finish',
  3682.  
  3683. // 'data-changed','yt-watch-comments-ready'
  3684. ])
  3685. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  3686. EventTarget.prototype.dispatchEvent = function (event) {
  3687. const type = (event || 0).type;
  3688. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  3689. if (!filter.has(type) && !type.endsWith('-changed')) {
  3690. if (this instanceof Node || this instanceof Window) {
  3691. nextBrowserTick_(() => this.dispatchEvent938(event));
  3692. return true;
  3693. }
  3694. }
  3695. }
  3696. return this.dispatchEvent938(event);
  3697. }
  3698. }
  3699.  
  3700. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  3701. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  3702. // const xhr = new XMLHttpRequest;
  3703. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  3704. if (!pdOri || pdOri.configurable !== true) return;
  3705. let propNeedles = null;
  3706. const pdNew = {
  3707. configurable: true,
  3708. enumerable: true,
  3709. get: function () {
  3710. propNeedles = this;
  3711. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  3712. throw new Error();
  3713. }
  3714. }
  3715. Object.defineProperty(Map.prototype, 'size', pdNew);
  3716. try {
  3717. XMLHttpRequest.prototype.open.call(0);
  3718. // xhr.open.call(null)
  3719. } catch (e) { }
  3720. Object.defineProperty(Map.prototype, 'size', pdOri);
  3721. if (!propNeedles) return;
  3722. const entries = [...propNeedles.entries()];
  3723. propNeedles.clear();
  3724. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  3725. })();
  3726.  
  3727. if (FIX_XHR_REQUESTING) {
  3728.  
  3729. const URL = window.URL || new Function('return URL')();
  3730. const createObjectURL = URL.createObjectURL.bind(URL);
  3731.  
  3732. XMLHttpRequest = (() => {
  3733. const XMLHttpRequest_ = XMLHttpRequest;
  3734. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  3735. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  3736. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  3737. constructor(...args) {
  3738. super(...args);
  3739. }
  3740. open(method, url, ...args) {
  3741. let skip = false;
  3742. if (!url || typeof url !== 'string') skip = true;
  3743. else if (typeof url === 'string') {
  3744. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  3745. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  3746. skip = true;
  3747. } else if (turl.includes('.youtube.com/pagead/')) {
  3748. skip = true;
  3749. } else if (turl.includes('.youtube.com/ptracking')) {
  3750. skip = true;
  3751. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  3752. skip = true;
  3753. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  3754. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  3755. skip = true;
  3756. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  3757. skip = true;
  3758. } else {
  3759. // skip = true; // for user activity logging e.g. watched videos
  3760. }
  3761. } else if (turl.includes('play.google.com/log')) {
  3762. skip = true;
  3763. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  3764. skip = true;
  3765. }
  3766. }
  3767. if (!skip) {
  3768. this.__xmMc8__ = 1;
  3769. return super.open(method, url, ...args);
  3770. } else {
  3771. this.__xmMc8__ = 2;
  3772. return super.open('GET', url0);
  3773. }
  3774. }
  3775. send(...args) {
  3776. if (this.__xmMc8__ === 1) {
  3777. return super.send(...args);
  3778. } else if (this.__xmMc8__ === 2) {
  3779. return super.send();
  3780. } else {
  3781. console.log('[yt-js-engine-tamer]', 'xhr warning');
  3782. return super.send(...args);
  3783. }
  3784. }
  3785. }
  3786. c.prototype.__xmMc8__ = 0;
  3787. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  3788. return c;
  3789. })();
  3790. }
  3791.  
  3792. // Alternative HACK -> Tabview Youtube
  3793. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  3794.  
  3795. // ---- << this.overscrollConfig HACK >> -----
  3796.  
  3797. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  3798.  
  3799. /*
  3800.  
  3801. ;function gZb(a, b) {
  3802. b = void 0 === b ? !0 : b;
  3803. a.addEventListener("wheel", hZb);
  3804. a.overscrollConfig = {
  3805. cooldown: b
  3806. }
  3807. }
  3808. function iZb(a) {
  3809. a.overscrollConfig = void 0;
  3810. a.removeEventListener("wheel", hZb)
  3811. }
  3812. function hZb(a) {
  3813. var b = a.deltaY
  3814. , c = a.target
  3815. , d = null;
  3816. if (window.Polymer && window.Polymer.Element) {
  3817. if (c = a.path || a.composedPath && a.composedPath()) {
  3818. c = g(c);
  3819. for (var e = c.next(); !e.done && (e = e.value,
  3820. !jZb(e, b)); e = c.next())
  3821. if (e.overscrollConfig) {
  3822. d = e;
  3823. break
  3824. }
  3825. }
  3826. } else
  3827. for (; c && !jZb(c, b); ) {
  3828. if (c.overscrollConfig) {
  3829. d = c;
  3830. break
  3831. }
  3832. c = c.parentElement
  3833. }
  3834. d && (b = d.overscrollConfig,
  3835. b.cooldown ? (d = a.deltaY,
  3836. c = b.lastDeltaY || 0,
  3837. b.lastDeltaY = d,
  3838. e = b.lastStopped || 0,
  3839. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  3840. c = !1) : (d = e + 600,
  3841. c = !0) : (d = Date.now() + 600,
  3842. c = !0),
  3843. d > Date.now() && (a.preventDefault(),
  3844. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  3845. }
  3846. */
  3847.  
  3848. let wheelHandler = function (a) {
  3849. if (window.Polymer && window.Polymer.Element) {
  3850. let c;
  3851. if (c = a.path || a.composedPath && a.composedPath()) {
  3852. for (const e of c) {
  3853. const cnt = insp(e);
  3854. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3855. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3856. }
  3857. }
  3858. } else {
  3859. let e = a.target;
  3860. for (; e instanceof Element; e = e.parentElement) {
  3861. const cnt = insp(e);
  3862. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3863. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3864. }
  3865. }
  3866. };
  3867.  
  3868. let checkWheelListenerObjs = null;
  3869.  
  3870. let getObjsFn = () => {
  3871. let euyVal = 0;
  3872. const eukElm = {};
  3873. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  3874. const euzObj = new Proxy(eukElm, {
  3875. get(target, prop) {
  3876. throw `ErrorF31.get(${prop})`
  3877. },
  3878. set(target, prop, value) {
  3879. throw `ErrorF33.set(${prop}, ${value})`
  3880. }
  3881. });
  3882. const euxElm = new Proxy(eukElm, {
  3883. get(target, prop) {
  3884. if (prop === 'scrollTop') {
  3885. euyVal = euyVal | 8;
  3886. return 0;
  3887. }
  3888. if (prop === 'overscrollConfig') {
  3889. euyVal = euyVal | 16;
  3890. return void 0;
  3891. }
  3892. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  3893. return 640;
  3894. }
  3895. if (prop === 'scrollLeft') {
  3896. euyVal = euyVal | 8;
  3897. return 0;
  3898. }
  3899. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  3900. return 800;
  3901. }
  3902. throw `ErrorF45.get(${prop})`
  3903. },
  3904. set(target, prop, value) {
  3905. throw `ErrorF47.set(${prop}, ${value})`
  3906. }
  3907. });
  3908. const eukEvt = {};
  3909. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  3910. const euyEvt = new Proxy(eukEvt, {
  3911. get(target, prop) {
  3912. if (prop === 'deltaY' || prop === 'deltaX') {
  3913. euyVal = euyVal | 1;
  3914. return -999;
  3915. }
  3916. if (prop === 'target') {
  3917. euyVal = euyVal | 2;
  3918. return euxElm
  3919. }
  3920. if (prop === 'path' || prop === 'composedPath') {
  3921. euyVal = euyVal | 2;
  3922. return [euxElm]
  3923. }
  3924. throw `ErrorF51.get(${prop})`
  3925. },
  3926. set(target, prop, value) {
  3927. throw `ErrorF53.set(${prop}, ${value})`
  3928. }
  3929. });
  3930. const setVal = (v) => {
  3931. euyVal = v;
  3932. }
  3933. const getVal = () => {
  3934. return euyVal;
  3935. }
  3936. return { euzObj, euyEvt, setVal, getVal };
  3937. }
  3938.  
  3939. let checkWheelListener = (callback) => {
  3940.  
  3941. let callbackIdentifier = '';
  3942.  
  3943. let res = null;
  3944. try {
  3945. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  3946. setVal(0);
  3947. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  3948. throw `RESULT${getVal()}`;
  3949. } catch (e) {
  3950. res = e;
  3951. }
  3952.  
  3953. res = `${res}` || `${null}`;
  3954. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  3955.  
  3956. callbackIdentifier = res;
  3957. if (callbackIdentifier === 'RESULT27') 0;
  3958. else if (callbackIdentifier === 'RESULT0') {
  3959. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  3960. } else if (callbackIdentifier.startsWith('RESULT')) {
  3961. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  3962. }
  3963. return callbackIdentifier;
  3964.  
  3965. };
  3966.  
  3967. let callbackFound = false;
  3968. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  3969. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  3970. // M-youtube-js-engine-tamer.52178
  3971. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  3972. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  3973. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  3974. // RESULTXX / ErrorFXX / Other...
  3975. if (callbackIdentifier === 'RESULT27') {
  3976. this.overscrollConfigDisable = true;
  3977. if (!callbackFound) {
  3978. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  3979. getObjsFn = checkWheelListener = null;
  3980. checkWheelListenerObjs = null;
  3981. wheelHandler = null;
  3982. }
  3983. return void 0;
  3984. } else if (!callbackFound && !this.overscrollConfigDisable) {
  3985. this.overscrollConfigDisable = true;
  3986. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  3987. }
  3988. }
  3989. return this.addEventListener52178(type, callback, option);
  3990. };
  3991.  
  3992. // ---- << this.overscrollConfig HACK >> -----
  3993.  
  3994. }
  3995.  
  3996. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  3997.  
  3998. let p_a_objWR = null;
  3999. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  4000. let ytPageReady = 0;
  4001.  
  4002. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  4003. let isGlobalSpaceControl = true;
  4004. let mediaPlayerElementWR = null;
  4005. let focusedElementAtSelection = null;
  4006.  
  4007. // let want_control_video = false;
  4008.  
  4009. let spaceBarControl_keyG = '';
  4010.  
  4011. let lastUserAction = 0;
  4012.  
  4013. const wmKeyControlPhase = new WeakMap();
  4014.  
  4015. let currentSelectionText = null;
  4016.  
  4017. const getCurrentSelectionText = () => {
  4018. if (currentSelectionText !== null) return currentSelectionText
  4019. return (currentSelectionText = `${getSelection()}`)
  4020. }
  4021.  
  4022. const pageMediaWatcher = () => {
  4023.  
  4024. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  4025. // want_control_video = false;
  4026. // }, { capture: true, passive: true });
  4027.  
  4028. document.addEventListener('yt-navigate', () => {
  4029. ytPageReady = 0;
  4030. });
  4031. document.addEventListener('yt-navigate-start', () => {
  4032. ytPageReady = 0;
  4033. });
  4034. document.addEventListener('yt-navigate-cache', () => {
  4035. ytPageReady = 0;
  4036. });
  4037.  
  4038. document.addEventListener('yt-navigate-finish', () => {
  4039. ytPageReady = 1;
  4040. });
  4041.  
  4042. document.addEventListener('durationchange', () => {
  4043. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  4044. if (elm.duration > 0.01) {
  4045. if (elm.closest('[hidden]')) continue;
  4046. mediaPlayerElementWR = mWeakRef(elm);
  4047. return;
  4048. }
  4049. }
  4050. }, { capture: true, passive: true });
  4051.  
  4052. document.addEventListener('selectionchange', (evt) => {
  4053. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  4054. currentSelectionText = null;
  4055. if (!(evt.target instanceof Node)) return;
  4056. focusedElementAtSelection = evt.target;
  4057. }, { capture: true, passive: true })
  4058.  
  4059. document.addEventListener('pointerdown', (evt) => {
  4060. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4061. }, { capture: true, passive: true });
  4062.  
  4063.  
  4064. document.addEventListener('pointerup', (evt) => {
  4065. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4066. }, { capture: true, passive: true });
  4067.  
  4068.  
  4069. document.addEventListener('keydown', (evt) => {
  4070. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4071. }, { capture: true, passive: true });
  4072.  
  4073. document.addEventListener('keyup', (evt) => {
  4074. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4075. }, { capture: true, passive: true });
  4076.  
  4077. };
  4078.  
  4079.  
  4080. const checkKeyB = (p_a_obj) => {
  4081.  
  4082. const boolList = new Set();
  4083. const p_a_obj_api = p_a_obj.api;
  4084.  
  4085. const nilFunc0 = function () {
  4086. return void 0
  4087. };
  4088. const mt = new Proxy({}, {
  4089. get(target, prop) {
  4090. if (prop === 'get') return nilFunc0;
  4091. return mt;
  4092. }
  4093. });
  4094. const nilFunc = function () {
  4095. return mt
  4096. };
  4097. const mw = new Proxy({}, {
  4098. get(target, prop) {
  4099. if (prop in p_a_obj_api) {
  4100. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  4101. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  4102. if (q && q.value) {
  4103. if (!q.writable) return q.value;
  4104. if (typeof q.value === 'string') return '';
  4105. if (typeof q.value === 'number') return 0;
  4106. if (typeof q.value === 'boolean') return false;
  4107. if (q.value && typeof q.value === 'object') return {};
  4108. }
  4109. }
  4110. return undefined;
  4111. },
  4112. set(target, prop) {
  4113. throw 'mwSet';
  4114. }
  4115. });
  4116.  
  4117. const mq = new Proxy({}, {
  4118. get(target, prop) {
  4119. if (prop === 'api') return mw;
  4120. if (prop in p_a_obj) {
  4121. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  4122. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  4123. if (q && q.value) {
  4124. if (!q.writable) return q.value;
  4125. if (typeof q.value === 'string') return '';
  4126. if (typeof q.value === 'number') return 0;
  4127. if (typeof q.value === 'boolean') return false;
  4128. if (q.value && typeof q.value === 'object') return {};
  4129. }
  4130. }
  4131. return undefined;
  4132. },
  4133. set(target, prop, val) {
  4134. if (typeof val === 'boolean') boolList.add(prop)
  4135. throw `mqSet(${prop},${val})`;
  4136. }
  4137. });
  4138.  
  4139. let res = ''
  4140. try {
  4141. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  4142. } catch (e) {
  4143. res = `ERROR::${e}`;
  4144. }
  4145.  
  4146. if (boolList.size === 1) {
  4147. const value = boolList.values().next().value;
  4148. if (res === `ERROR::mqSet(${value},${true})`) {
  4149. p_a_obj.__uZWaD__ = value;
  4150. }
  4151. }
  4152.  
  4153. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  4154.  
  4155. }
  4156.  
  4157.  
  4158. let pm_p_a = null;
  4159.  
  4160. const p_a_init = function () {
  4161. const r = this.init91();
  4162. const keyBw = this.__cPzfo__ || '__NIL__';
  4163. const p_a_obj = this[keyBw];
  4164. if (!p_a_obj) return;
  4165. try {
  4166. checkKeyB(p_a_obj);
  4167. } catch (e) { }
  4168. p_a_objWR = mWeakRef(p_a_obj);
  4169. if (FIX_SHORTCUTKEYS > 0) {
  4170. if (p_a_obj && !p_a_obj.hVhtg) {
  4171. p_a_obj.hVhtg = 1;
  4172.  
  4173. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  4174. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  4175. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  4176. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  4177. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  4178. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  4179.  
  4180. }
  4181. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  4182. // const api = p_a_obj.api
  4183. // api.hVhtg = 1;
  4184. // api.playVideo91 = api.playVideo;
  4185. // api.playVideo = p_a_jt.playVideo;
  4186. // api.pauseVideo91 = api.pauseVideo;
  4187. // api.pauseVideo = p_a_jt.pauseVideo;
  4188. // }
  4189. }
  4190. if (pm_p_a) {
  4191. pm_p_a.resolve();
  4192. pm_p_a = null;
  4193. }
  4194. return r;
  4195. };
  4196.  
  4197. const p_a_xt = {
  4198.  
  4199. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  4200.  
  4201. if (FIX_SHORTCUTKEYS === 2) {
  4202.  
  4203. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  4204.  
  4205. if (activeElement) {
  4206.  
  4207. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  4208.  
  4209. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  4210. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  4211. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  4212.  
  4213. }
  4214.  
  4215. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  4216. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  4217. // console.log(582, isDelayedSpaceBar)
  4218. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  4219.  
  4220. if (activeElement && (h === 'Space' || h === 'Enter')) {
  4221. const controlPhase = wmKeyControlPhase.get(activeElement);
  4222. if (controlPhase === 4 || controlPhase === 5) return false;
  4223. }
  4224. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  4225. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  4226. // if (!isSpaceKeyImmediate) return false;
  4227. // }
  4228. }
  4229.  
  4230. },
  4231.  
  4232. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  4233.  
  4234. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  4235.  
  4236. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  4237. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  4238. // console.log(583, isDelayedSpaceBar)
  4239. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  4240.  
  4241. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4242.  
  4243. let mediaWorking = false;
  4244. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  4245. mediaWorking = true;
  4246. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  4247. mediaWorking = true;
  4248. }
  4249. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  4250. mediaWorking && Promise.resolve().then(() => {
  4251. if (activeElement === document.activeElement) {
  4252. return activeElement.blur()
  4253. } else {
  4254. return false
  4255. }
  4256. }).then((r) => {
  4257. r !== false && mediaPlayerElement.focus();
  4258. });
  4259. }
  4260. },
  4261.  
  4262.  
  4263. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  4264.  
  4265. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  4266.  
  4267. const activeElement = document.activeElement;
  4268.  
  4269. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  4270. if (allow === false) return false;
  4271.  
  4272. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  4273. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  4274.  
  4275. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  4276.  
  4277. return ret;
  4278. },
  4279. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  4280.  
  4281.  
  4282. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  4283.  
  4284. const activeElement = document.activeElement;
  4285. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4286. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  4287. // }
  4288. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  4289. if (allow === false) return false;
  4290.  
  4291. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  4292. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  4293.  
  4294. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  4295.  
  4296. return ret;
  4297. }
  4298.  
  4299. };
  4300.  
  4301. // const p_a_jt = { // API
  4302.  
  4303. // playVideo(a) { // without spinner effect
  4304.  
  4305. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  4306.  
  4307. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4308. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  4309. // want_control_video = true;
  4310. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  4311. // }
  4312.  
  4313. // }
  4314. // return this.playVideo91(a);
  4315.  
  4316. // },
  4317.  
  4318. // pauseVideo(a) { // without spinner effect
  4319.  
  4320. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  4321.  
  4322. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4323. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  4324. // want_control_video = true;
  4325. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  4326. // }
  4327.  
  4328. // }
  4329. // return this.pauseVideo91(a);
  4330.  
  4331. // }
  4332. // };
  4333.  
  4334. let flagSpeedMaster = null;
  4335. const getSpeedMasterControlFlag = () => {
  4336.  
  4337. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4338. isSpeedMastSpacebarControlEnabled = false;
  4339. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  4340. isSpeedMastSpacebarControlEnabled = true;
  4341. }
  4342. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  4343. isSpeedMastSpacebarControlEnabled = true;
  4344. }
  4345.  
  4346. if (flagSpeedMaster === null) {
  4347. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  4348. if (!p) {
  4349. flagSpeedMaster = false;
  4350. } else {
  4351.  
  4352. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  4353.  
  4354. }
  4355.  
  4356. }
  4357. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  4358.  
  4359. return isSpeedMastSpacebarControlEnabled;
  4360. }
  4361.  
  4362.  
  4363. const getGlobalSpacebarControlFlag = () => {
  4364.  
  4365. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4366. isGlobalSpaceControl = false;
  4367. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  4368. isGlobalSpaceControl = true;
  4369. }
  4370. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  4371. isGlobalSpaceControl = true;
  4372. }
  4373.  
  4374. return isGlobalSpaceControl;
  4375. }
  4376.  
  4377. const keyboardController = async (_yt_player) => {
  4378.  
  4379. const keyQT = getQT(_yt_player);
  4380. const keySV = getSV(_yt_player);
  4381. const keyDX = getDX(_yt_player);
  4382. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  4383.  
  4384. if (!keyDX) return;
  4385. if (keyDX === keyQT || keyDX === keySV) return;
  4386.  
  4387. if (typeof keyDX !== 'string') return;
  4388.  
  4389. let lastAccessKey = '';
  4390. let lastAccessKeyConfirmed = '';
  4391. const mb = new Proxy({}, {
  4392. get(target, prop) {
  4393. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  4394. throw 'mbGet'
  4395. },
  4396. set(target, prop, val) {
  4397. throw 'mbSet'
  4398. }
  4399. });
  4400. const ma = new Proxy({}, {
  4401. get(target, prop) {
  4402. lastAccessKey = prop;
  4403. return mb
  4404. },
  4405. set(target, prop, val) {
  4406. throw 'maSet'
  4407. }
  4408. });
  4409.  
  4410. let keyBw = '';
  4411. try {
  4412. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  4413. } catch (e) {
  4414. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  4415. keyBw = lastAccessKeyConfirmed;
  4416. }
  4417. }
  4418.  
  4419. if (!keyBw) return;
  4420.  
  4421. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  4422.  
  4423. pm_p_a = new PromiseExternal();
  4424.  
  4425. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  4426.  
  4427. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  4428.  
  4429. _yt_player[keyDX].prototype.init = p_a_init;
  4430.  
  4431. await pm_p_a.then();
  4432. const p_a_obj = kRef(p_a_objWR);
  4433.  
  4434. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  4435.  
  4436.  
  4437. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  4438.  
  4439. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  4440.  
  4441. if (!isSpeedMastSpacebarControlEnabled) {
  4442.  
  4443. if (config && config.EXPERIMENT_FLAGS) {
  4444. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  4445. }
  4446. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  4447. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  4448. }
  4449.  
  4450. } else {
  4451.  
  4452. if (config && config.EXPERIMENT_FLAGS) {
  4453. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  4454. }
  4455. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  4456. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  4457. }
  4458.  
  4459. }
  4460.  
  4461. }
  4462.  
  4463. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  4464.  
  4465.  
  4466.  
  4467.  
  4468. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  4469.  
  4470. // console.log(p_a_obj.handleGlobalKeyUp)
  4471. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  4472.  
  4473. // console.log(p_a_obj.api)
  4474.  
  4475.  
  4476. // QT -> DX(SV) -> p_a
  4477.  
  4478.  
  4479. /*
  4480. *
  4481. *
  4482. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  4483. b = void 0 === b ? !1 : b;
  4484. c = void 0 === c ? !1 : c;
  4485. d = void 0 === d ? !1 : d;
  4486. e = void 0 === e ? !1 : e;
  4487. var l = g.PT(this);
  4488. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  4489. }
  4490.  
  4491. */
  4492.  
  4493. /*
  4494. *
  4495. *
  4496. *
  4497. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  4498. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  4499. }
  4500.  
  4501. */
  4502.  
  4503.  
  4504. // if(!keyDX) return;
  4505.  
  4506. // console.log(4999, keyDX)
  4507.  
  4508. };
  4509.  
  4510.  
  4511. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  4512.  
  4513. const p_a_obj = kRef(p_a_objWR);
  4514. // const api = p_a_obj.api;
  4515.  
  4516.  
  4517. // console.log(540);
  4518.  
  4519. let boolList = null;
  4520. let ret;
  4521. isSpaceKeyImmediate = true;
  4522. try {
  4523.  
  4524. ret = 0;
  4525. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  4526. let p_a_objT;
  4527. if (!spaceBarControl_keyG) { // just in case
  4528. boolList = new Set();
  4529. p_a_objT = new Proxy(p_a_obj, {
  4530. get(target, prop, handler) {
  4531. const val = target[prop];
  4532. if (typeof val !== 'boolean') return val;
  4533. boolList.add(prop);
  4534. // console.log(555, prop, val);
  4535. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  4536. spaceBarControl_keyG = prop;
  4537. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4538. val = false;
  4539. }
  4540. return val;
  4541. }
  4542. });
  4543.  
  4544.  
  4545. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  4546. p_a_obj[spaceBarControl_keyG] = false;
  4547. p_a_objT = p_a_obj;
  4548. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  4549. } else {
  4550.  
  4551. p_a_objT = p_a_obj;
  4552. }
  4553.  
  4554. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  4555.  
  4556.  
  4557. } catch (e) {
  4558. console.log(e)
  4559. }
  4560. isSpaceKeyImmediate = false;
  4561.  
  4562. if (boolList && boolList.size === 1) {
  4563. const value = boolList.values().next().value;
  4564. spaceBarControl_keyG = value;
  4565. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4566.  
  4567. }
  4568.  
  4569. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4570.  
  4571. return ret;
  4572. }
  4573.  
  4574. const shortcutKeysFixer = () => {
  4575.  
  4576. let pausePromiseControlJ = 0;
  4577.  
  4578.  
  4579. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  4580.  
  4581. let controlPhase = 0;
  4582. const aElm = document.activeElement;
  4583.  
  4584. if (aElm) {
  4585.  
  4586. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  4587.  
  4588. if (typeof controlPhaseCache === 'number') {
  4589.  
  4590. controlPhase = controlPhaseCache;
  4591. } else {
  4592.  
  4593. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  4594. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  4595. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  4596. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  4597. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  4598. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  4599. else {
  4600. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  4601. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  4602. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  4603. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  4604. }
  4605.  
  4606. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  4607. controlPhase = 0;
  4608. }
  4609.  
  4610. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  4611. if (aElm.closest('[contenteditable], input, textarea')) {
  4612. controlPhase = 5;
  4613. } else if (aElm.closest('button')) {
  4614. controlPhase = 4;
  4615. }
  4616. }
  4617.  
  4618. if (aElm.closest('#movie_player')) controlPhase = 6;
  4619.  
  4620. wmKeyControlPhase.set(aElm, controlPhase);
  4621.  
  4622. }
  4623. }
  4624.  
  4625. return controlPhase;
  4626.  
  4627. }
  4628.  
  4629. const isStateControllable = (api) => {
  4630. let appState = null;
  4631. let playerState = null;
  4632. let adState = null;
  4633. try {
  4634. appState = api.getAppState();
  4635. playerState = api.getPlayerState();
  4636. adState = api.getAdState();
  4637. } catch (e) { }
  4638. // ignore playerState -1
  4639. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  4640. };
  4641.  
  4642.  
  4643. const keyEventListener = (evt) => {
  4644. if (BY_PASS_KEYBOARD_CONTROL) return;
  4645.  
  4646. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4647. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  4648. if (!ytPageReady) return;
  4649.  
  4650. if (evt.defaultPrevented === true) return;
  4651.  
  4652. const p_a_obj = kRef(p_a_objWR);
  4653.  
  4654. if (!p_a_obj) return;
  4655.  
  4656.  
  4657. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4658. if (!mediaPlayerElement) return;
  4659.  
  4660. // let focusBodyIfSuccess = false;
  4661.  
  4662. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  4663.  
  4664. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  4665. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  4666. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  4667.  
  4668.  
  4669. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  4670.  
  4671. // console.log(`${evt.type}::controlPhase`,controlPhase)
  4672.  
  4673. // if (controlPhase == 4) {
  4674. // focusBodyIfSuccess = true;
  4675. // }
  4676.  
  4677. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  4678. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4679.  
  4680. if (FIX_SHORTCUTKEYS < 2) return;
  4681. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  4682.  
  4683. let rr;
  4684. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  4685.  
  4686.  
  4687.  
  4688. let useImprovedPauseResume = false;
  4689.  
  4690. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4691.  
  4692. const api = p_a_obj.api;
  4693. const stateControllable = isStateControllable(api);
  4694. // console.log(2122, appState, playerState, adState)
  4695.  
  4696. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  4697.  
  4698. useImprovedPauseResume = true;
  4699.  
  4700. }
  4701.  
  4702.  
  4703. }
  4704.  
  4705.  
  4706. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  4707. if (evt.type === 'keydown') {
  4708.  
  4709. if (useImprovedPauseResume) {
  4710.  
  4711. const isPaused = mediaPlayerElement.paused;
  4712.  
  4713. const cj = ++pausePromiseControlJ;
  4714. Promise.resolve().then(() => {
  4715.  
  4716. if (cj !== pausePromiseControlJ) return;
  4717.  
  4718. if (mediaPlayerElement.paused !== isPaused) return;
  4719.  
  4720. const ret = ytResumeFn();
  4721. if (!ret) { // fallback
  4722. isPaused ? api.playVideo() : api.pauseVideo();
  4723. }
  4724.  
  4725. /*
  4726. let a = void 0;
  4727. console.log('Rb', api.Rb())
  4728. a = !window._yt_player.nL(api.Rb());
  4729. p_a_obj.Wd.kG(a)
  4730. a ? api.playVideo() : api.pauseVideo();
  4731.  
  4732. */
  4733.  
  4734.  
  4735. });
  4736. rr = true;
  4737. } else {
  4738.  
  4739. isSpaceKeyImmediate = true;
  4740. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  4741. isSpaceKeyImmediate = false;
  4742. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4743.  
  4744. }
  4745.  
  4746.  
  4747. } else if (evt.type === 'keyup') {
  4748.  
  4749. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4750.  
  4751. rr = true;
  4752. } else {
  4753.  
  4754. isSpaceKeyImmediate = true;
  4755. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  4756. isSpaceKeyImmediate = false;
  4757. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4758.  
  4759. }
  4760.  
  4761.  
  4762. /*
  4763.  
  4764. if (d)
  4765. switch (c) {
  4766. case 32:
  4767. case 13:
  4768. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  4769. b = !0,
  4770. e = !1;
  4771. else if (e) {
  4772. var m = d.getAttribute("role");
  4773. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  4774. d.click(),
  4775. f = !0)
  4776. }
  4777. break;
  4778. case 37:
  4779. case 39:
  4780. case 36:
  4781. case 35:
  4782. b = "slider" === d.getAttribute("role");
  4783. break;
  4784. case 38:
  4785. case 40:
  4786. m = d.getAttribute("role"),
  4787. d = 38 === c ? d.previousSibling : d.nextSibling,
  4788. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  4789. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  4790. f = b = !0))
  4791. }
  4792. if (e && !f)
  4793. switch (c) {
  4794. case 38:
  4795. f = Math.min(this.api.getVolume() + 5, 100);
  4796. XV(this.Wd, f, !1);
  4797. this.api.setVolume(f);
  4798. h = f = !0;
  4799. break;
  4800. case 40:
  4801. f = Math.max(this.api.getVolume() - 5, 0);
  4802. XV(this.Wd, f, !0);
  4803. this.api.setVolume(f);
  4804. h = f = !0;
  4805. break;
  4806. case 36:
  4807. this.api.Yh() && (this.api.startSeekCsiAction(),
  4808. this.api.seekTo(0, void 0, void 0, void 0, 79),
  4809. h = f = !0);
  4810. break;
  4811. case 35:
  4812. this.api.Yh() && (this.api.startSeekCsiAction(),
  4813. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  4814. h = f = !0)
  4815. }
  4816. */
  4817.  
  4818. }
  4819.  
  4820.  
  4821. if (rr) {
  4822.  
  4823. // focusBodyIfSuccess && Promise.resolve().then(() => {
  4824. // activeElement === document.activeElement && activeElement.blur();
  4825. // });
  4826.  
  4827. evt.preventDefault();
  4828. evt.stopImmediatePropagation();
  4829. evt.stopPropagation();
  4830.  
  4831. }
  4832.  
  4833. };
  4834.  
  4835. document.addEventListener('keydown', keyEventListener, { capture: true });
  4836.  
  4837.  
  4838. document.addEventListener('keyup', keyEventListener, { capture: true });
  4839.  
  4840. }
  4841.  
  4842. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  4843.  
  4844. })();
  4845.  
  4846.  
  4847. pageMediaWatcher();
  4848. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  4849.  
  4850.  
  4851. const check_for_set_key_order = (() => {
  4852.  
  4853. let mySet = new Set();
  4854.  
  4855. mySet.add("value1");
  4856. mySet.add("value2");
  4857. mySet.add("value3");
  4858.  
  4859. // Function to convert Set values to an array
  4860. function getSetValues(set) {
  4861. return Array.from(set.values());
  4862. }
  4863.  
  4864. // Function to test if the Set maintains insertion order
  4865. function testSetOrder(set, expectedOrder) {
  4866. let values = getSetValues(set);
  4867. return expectedOrder.join(',') === values.join(',');
  4868. }
  4869.  
  4870. // Test 1: Initial order
  4871. if (mySet.values().next().value !== "value1") return false;
  4872. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  4873.  
  4874. // Test 2: After deleting an element
  4875. mySet.delete("value2");
  4876. if (mySet.values().next().value !== "value1") return false;
  4877. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  4878.  
  4879. // Test 3: After re-adding a deleted element
  4880. mySet.add("value2");
  4881. if (mySet.values().next().value !== "value1") return false;
  4882. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  4883.  
  4884. // Test 4: After adding a new element
  4885. mySet.add("value4");
  4886. if (mySet.values().next().value !== "value1") return false;
  4887. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  4888.  
  4889. // Test 5: Delete+Add
  4890. mySet.delete("value1");
  4891. mySet.delete("value3");
  4892. mySet.add("value3");
  4893. mySet.add("value1");
  4894. if (mySet.values().next().value !== "value2") return false;
  4895. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  4896.  
  4897. return true;
  4898. })();
  4899.  
  4900.  
  4901. // const qm47 = Symbol();
  4902. const qm57 = Symbol();
  4903. const qm53 = Symbol();
  4904. const qn53 = Symbol();
  4905.  
  4906.  
  4907. const ump3 = new WeakMap();
  4908.  
  4909. const stp = document.createElement('noscript');
  4910. stp.id = 'weakref-placeholder';
  4911.  
  4912. PROP_OverReInclusion_AVOID && (() => {
  4913.  
  4914.  
  4915. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  4916. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  4917. let byPassVal = null;
  4918. let byPassCount = 0;
  4919. let mmw = new Set();
  4920. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  4921. if (arguments.length !== 1) return f.apply(this, arguments);
  4922. if (byPassVal !== null && typeof prop === 'string') {
  4923.  
  4924. if (PROP_OverReInclusion_LIST.has(prop)) {
  4925. byPassCount++;
  4926. return byPassVal;
  4927. }
  4928. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  4929.  
  4930. }
  4931. return this.hasOwnProperty72(prop);
  4932. };
  4933.  
  4934.  
  4935. /*
  4936.  
  4937.  
  4938. z.prototype.forwardDynamicProps = function() {
  4939. var B = m(this.inst);
  4940. B = h(B);
  4941. for (var F = B.next(); !F.done; F = B.next()) {
  4942. var H = h(F.value);
  4943. F = H.next().value;
  4944. H = H.next().value;
  4945. my(this, F, H);
  4946. r(b) && !ly(F) && Wua(this.inst, F)
  4947. }
  4948. }
  4949.  
  4950. */
  4951.  
  4952.  
  4953.  
  4954. let byPassZeroShowed = false;
  4955. const forwardDynamicPropsGeneral = function () {
  4956. byPassVal = true;
  4957. byPassCount = 0;
  4958. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  4959. const ret = this.forwardDynamicProps72();
  4960. byPassVal = null;
  4961. if (byPassCount === 0 && !byPassZeroShowed) {
  4962. byPassZeroShowed = true;
  4963. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  4964. }
  4965. byPassCount = 0;
  4966. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  4967. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  4968. mmw.clear();
  4969. }
  4970. return ret;
  4971. };
  4972.  
  4973. const propCheck = (proto) => {
  4974. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  4975. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  4976. if (proto.forwardDynamicProps.length === 0) {
  4977. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  4978. }
  4979. }
  4980. };
  4981.  
  4982. const valMap = new WeakMap();
  4983. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  4984. get() {
  4985. propCheck(this.constructor.prototype);
  4986. return valMap.get(this);
  4987. },
  4988. set(nv) {
  4989. propCheck(this.constructor.prototype);
  4990. valMap.set(this, nv);
  4991. return true;
  4992. },
  4993. enumerable: false,
  4994. configurable: true
  4995.  
  4996. });
  4997.  
  4998. promiseForCustomYtElementsReady.then(() => {
  4999. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  5000. if (customElements.define.length !== 2) return;
  5001. customElements.define72 = customElements.define;
  5002. customElements.define = function (b, w) {
  5003. propCheck(w.prototype);
  5004. const ret = this.define72(b, w);
  5005. return ret;
  5006. }
  5007. });
  5008.  
  5009. })();
  5010.  
  5011. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  5012.  
  5013. const flexibleItemListMo = new MutationObserver((mutations) => {
  5014. // cnt.onStamperFinished
  5015. // cnt.maybeUpdateFlexibleMenu
  5016. const set = new Set();
  5017. for (const mutation of mutations) {
  5018. set.add(mutation.target);
  5019. }
  5020. for (const s of set) {
  5021. const cnt = insp(s);
  5022. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  5023. cnt.maybeUpdateFlexibleMenuImpl();
  5024. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  5025. cnt.maybeUpdateFlexibleMenu();
  5026. } else if (typeof cnt.onStamperFinished === 'function') {
  5027. cnt.onStamperFinished();
  5028. }
  5029. }
  5030. });
  5031.  
  5032. let checkConfig = true;
  5033. const flexibleItemDocMo = new MutationObserver(() => {
  5034. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  5035. s.setAttribute('b289ad', '');
  5036. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  5037. s.appendChild(document.createComment('.')).remove();
  5038. }
  5039. if (checkConfig) {
  5040. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5041. if (config && config.EXPERIMENT_FLAGS) {
  5042. checkConfig = false;
  5043. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  5044. }
  5045. }
  5046. });
  5047. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  5048.  
  5049. }
  5050.  
  5051.  
  5052.  
  5053.  
  5054. const observablePromise = (proc, timeoutPromise) => {
  5055. let promise = null;
  5056. return {
  5057. obtain() {
  5058. if (!promise) {
  5059. promise = new Promise(resolve => {
  5060. let mo = null;
  5061. const f = () => {
  5062. let t = proc();
  5063. if (t) {
  5064. mo.disconnect();
  5065. mo.takeRecords();
  5066. mo = null;
  5067. resolve(t);
  5068. }
  5069. }
  5070. mo = new MutationObserver(f);
  5071. mo.observe(document, { subtree: true, childList: true })
  5072. f();
  5073. timeoutPromise && timeoutPromise.then(() => {
  5074. resolve(null)
  5075. });
  5076. });
  5077. }
  5078. return promise
  5079. }
  5080. }
  5081. }
  5082.  
  5083.  
  5084. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  5085. observablePromise(() => {
  5086. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5087. if (config && config.EXPERIMENT_FLAGS) {
  5088. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  5089. return true;
  5090. }
  5091. }).obtain();
  5092. }
  5093.  
  5094. if (HOOK_ACTIVE_MODULES) {
  5095.  
  5096. let watchController;
  5097. const watchControllerObservable = observablePromise(() => {
  5098. const watchFlexy = document.querySelector('ytd-watch-flexy');
  5099. if (!watchFlexy) return;
  5100. return insp(watchFlexy).watchController;
  5101. }).obtain();
  5102. (async () => {
  5103. watchController = await watchControllerObservable;
  5104.  
  5105. const activeModules = watchController.activeModules;
  5106. if (!activeModules) return;
  5107.  
  5108. const checkFn = (activeModule) => {
  5109. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  5110. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  5111. }
  5112. }
  5113. if (!activeModules.push8792 && activeModules.push) {
  5114. activeModules.push8792 = activeModules.push;
  5115. activeModules.push = function (a, ...args) {
  5116. checkFn(a);
  5117. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  5118. return r;
  5119. }
  5120. }
  5121. activeModules.forEach(checkFn);
  5122.  
  5123. })();
  5124.  
  5125. let yieldResultWrappingByPass = false;
  5126. let asyncProto = null;
  5127. const yieldResultWrapping = (f) => {
  5128. if (yieldResultWrappingByPass) return [f(), null];
  5129. yieldResultWrappingByPass = true;
  5130. let D = null;
  5131. let promise, e_;
  5132. if (asyncProto) {
  5133. Object.defineProperty(asyncProto, 'yieldResult', {
  5134. get() {
  5135. return undefined;
  5136. },
  5137. set(nv) {
  5138. delete asyncProto.yieldResult;
  5139. this.yieldResult = nv;
  5140. D = this;
  5141. // console.log(122, this);
  5142. return true;
  5143. },
  5144. enumerable: false,
  5145. configurable: true
  5146. });
  5147. try {
  5148. promise = f();
  5149. } catch (e) { e_ = e }
  5150. delete asyncProto.yieldResult;
  5151. yieldResultWrappingByPass = false;
  5152. } else {
  5153. Object.defineProperty(Object.prototype, 'yieldResult', {
  5154. get() {
  5155. return undefined;
  5156. },
  5157. set(nv) {
  5158. delete Object.prototype.yieldResult;
  5159. this.yieldResult = nv;
  5160. D = this;
  5161. // console.log(122, this);
  5162. return true;
  5163. },
  5164. enumerable: false,
  5165. configurable: true
  5166. });
  5167. try {
  5168. promise = f();
  5169. } catch (e) { e_ = e }
  5170. delete Object.prototype.yieldResult;
  5171. yieldResultWrappingByPass = false;
  5172. if (D) {
  5173. asyncProto = Reflect.getPrototypeOf(D);
  5174. }
  5175. }
  5176. if (e_) throw e_;
  5177. return [promise, D];
  5178. }
  5179.  
  5180. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  5181.  
  5182. const aProto = Reflect.getPrototypeOf(activeModule);
  5183.  
  5184. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  5185.  
  5186. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  5187.  
  5188. // console.log(12885)
  5189. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  5190. // let qxt=false;
  5191. aProto.fetchUpdatedMetadata = function (t, P) {
  5192.  
  5193. // if (!qxt) {
  5194. // qxt = true;
  5195. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  5196. // console.log(199001,...args)
  5197. // });
  5198. // this.addOnDisposeCallback(function (...args) {
  5199.  
  5200. // console.log(199002,...args)
  5201. // watchController.unsubscribeByKey(y)
  5202. // qxt = false;
  5203. // });
  5204. // }
  5205. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  5206. if (D) promise.then(() => {
  5207. const yieldResult = D.yieldResult;
  5208. if (yieldResult) {
  5209. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  5210.  
  5211. if (mutations && mutations.length >= 1) {
  5212. let likeCountEntity = null;
  5213. for (const mutation of mutations) {
  5214. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  5215. break;
  5216. }
  5217. }
  5218. if (likeCountEntity) {
  5219. const model = insp(document.querySelector('segmented-like-dislike-button-view-model'));
  5220. if (model && typeof model.update === 'function' && model.update.length === 0) {
  5221. const data = ((model || 0).props || 0).data;
  5222. if (data) {
  5223. data.likeCountEntity = likeCountEntity;
  5224. if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  5225. model.update();
  5226. }
  5227. }
  5228. }
  5229. }
  5230. }
  5231. }).catch(console.warn);
  5232. return promise;
  5233. };
  5234.  
  5235. }
  5236.  
  5237. }
  5238.  
  5239.  
  5240. // ----------------------------
  5241.  
  5242.  
  5243. // const pendingStampFlushs = [];
  5244.  
  5245. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  5246.  
  5247. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  5248.  
  5249. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  5250.  
  5251.  
  5252. // const globalPromiseStack = {};
  5253.  
  5254. // let dummy;
  5255. // while(!dummy){
  5256.  
  5257. // dummy = document.querySelector('yt-icon');
  5258. // await new Promise(r=>setTimeout(r,0));
  5259. // }
  5260.  
  5261. dummy = document.createElement('yt-icon');
  5262.  
  5263. let cProto;
  5264. if (!(dummy instanceof Element)) return;
  5265. cProto = insp(dummy).constructor.prototype;
  5266.  
  5267. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  5268. cProto.determineIconSet671 = cProto.determineIconSet;
  5269. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  5270. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  5271. cProto.getIconManager671 = cProto.getIconManager;
  5272. cProto.getIconShapeData671 = cProto.getIconShapeData;
  5273. cProto.renderIcon671 = cProto.renderIcon;
  5274.  
  5275. // cProto.attached488 = cProto.attached;
  5276. // cProto.attached = function(){
  5277. // console.log('attached')
  5278. // return this.attached488(...arguments);
  5279. // }
  5280. // cProto.detached488 = cProto.detached;
  5281. // cProto.detached = function(){
  5282. // console.log('detached')
  5283. // return this.detached488(...arguments);
  5284. // }
  5285.  
  5286. if (cProto.__renderIconFix__) return;
  5287. cProto.__renderIconFix__ = true;
  5288.  
  5289. let taskStack = [];
  5290. const cmObs = new MutationObserver(() => {
  5291. const tasks = taskStack.slice();
  5292. taskStack.length = 0;
  5293. for (const task of tasks) {
  5294. task();
  5295. }
  5296. })
  5297. const cm = document.createComment('1');
  5298. const stackTask = (f) => {
  5299. taskStack.push(f);
  5300. cm.data = `${(cm.data & 7) + 1}`;
  5301. }
  5302. cmObs.observe(cm, { characterData: true });
  5303.  
  5304. // let iconManagers = {}; // assume shared
  5305.  
  5306. // window.iconManagers = () => iconManagers;
  5307.  
  5308.  
  5309. const setupYtIcon = (inst) => {
  5310.  
  5311. if (inst.__ytIconSetup588__) return;
  5312. const cProto = Reflect.getPrototypeOf(inst);
  5313. cProto.__ytIconSetup588__ = true;
  5314.  
  5315.  
  5316. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5317.  
  5318. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  5319. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  5320. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  5321. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  5322.  
  5323.  
  5324. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  5325. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  5326. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  5327. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  5328.  
  5329.  
  5330.  
  5331. }
  5332.  
  5333. cProto.handlePropertyChange = function (...a) { // 10+
  5334.  
  5335. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5336. this.__resolved__ = {
  5337.  
  5338. };
  5339. const a01 = this.isAttached;
  5340. let a02, a03;
  5341.  
  5342.  
  5343. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  5344.  
  5345. const stackFn = () => {
  5346. if (t !== this.__stackedKey3818__) {
  5347. return;
  5348. }
  5349. a03 = this.isAttached;
  5350.  
  5351. if (a01 === false && a02 === false && a03 === false) return;
  5352.  
  5353. if (a01 === true && a02 === true && a03 === true) {
  5354.  
  5355. } else {
  5356. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  5357. // unknown yt-icon#label-icon
  5358. return;
  5359. } else {
  5360. console.log('[yt-icon] debug', a01, a02, a03, this)
  5361. }
  5362. }
  5363.  
  5364. this.handlePropertyChange671(...arguments);
  5365.  
  5366. };
  5367.  
  5368.  
  5369.  
  5370. Promise.resolve().then(() => {
  5371. a02 = this.isAttached;
  5372. stackTask(stackFn);
  5373. });
  5374.  
  5375.  
  5376. }
  5377.  
  5378. cProto.determineIconSet = function (a, b, c, d) { // 10-
  5379.  
  5380. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5381. // string bool? bool=false int=24
  5382. // NOTIFICATIONS_NONE OR LIKE
  5383. // console.log('yt-icon.determineIconSet', ...arguments);
  5384.  
  5385. const r = this.determineIconSet671(...arguments);
  5386. return r;
  5387. }
  5388.  
  5389. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  5390.  
  5391. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5392. // same as determineIconSet
  5393. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  5394. return this.switchToYtSysIconset671(...arguments);
  5395. }
  5396.  
  5397. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  5398.  
  5399. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5400. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  5401. return this.useYtSysIconsetForMissingIcons671(...arguments);
  5402. }
  5403.  
  5404. cProto.getIconManager = function () { // 10+
  5405.  
  5406. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5407. if (!this.__resolved__) this.__resolved__ = {};
  5408. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  5409. const r = this.__resolved__.getIconManager;
  5410. return r;
  5411. }
  5412.  
  5413. cProto.getIconShapeData = function () { // 10+
  5414.  
  5415. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5416.  
  5417. // no argument
  5418. // console.log('yt-icon.getIconShapeData', ...arguments);
  5419. if (!this.__resolved__) this.__resolved__ = {};
  5420. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  5421. const r = this.__resolved__.getIconShapeData;
  5422. return r
  5423. }
  5424.  
  5425. cProto.renderIcon = function (a, b) { // X
  5426.  
  5427. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5428. // "" yt-icons:xxx
  5429. // console.log('yt-icon.renderIcon', ...arguments);
  5430. return this.renderIcon671(...arguments);
  5431. }
  5432.  
  5433. });
  5434.  
  5435.  
  5436. /**
  5437. * Compute the Longest Common Subsequence between two arrays.
  5438. * Returns an array of the LCS elements (in order).
  5439. */
  5440. function computeLCS(a, b) {
  5441. // Input validation
  5442. if (!Array.isArray(a) || !Array.isArray(b)) {
  5443. throw new Error('Inputs must be arrays');
  5444. }
  5445.  
  5446. const n = a.length, m = b.length;
  5447. // Early termination for trivial cases
  5448. if (n === 0 || m === 0) return [];
  5449. // Check for shallow equality
  5450. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  5451.  
  5452. // Use smaller dimension for space optimization
  5453. if (n > m) return computeLCS(b, a); // Ensure n <= m
  5454.  
  5455. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  5456. // Use Uint32Array for robustness with long sequences
  5457. const dp = [
  5458. new Uint32Array(m + 1),
  5459. new Uint32Array(m + 1),
  5460. ];
  5461. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  5462. // Optimize space by storing only necessary entries
  5463. const pred = new Uint8Array(n * m); // Single array for moves
  5464.  
  5465. for (let i = n - 1; i >= 0; i--) {
  5466. const curr = i % 2;
  5467. const next = 1 - curr;
  5468. // Clear current row for reuse
  5469. dp[curr].fill(0);
  5470.  
  5471. for (let j = m - 1; j >= 0; j--) {
  5472. const idx = i * m + j;
  5473. if (a[i] === b[j]) {
  5474. dp[curr][j] = dp[next][j + 1] + 1;
  5475. pred[idx] = 0; // Diagonal
  5476. } else if (dp[next][j] >= dp[curr][j + 1]) {
  5477. dp[curr][j] = dp[next][j];
  5478. pred[idx] = 1; // Down
  5479. } else {
  5480. dp[curr][j] = dp[curr][j + 1];
  5481. pred[idx] = 2; // Right
  5482. }
  5483. }
  5484. }
  5485.  
  5486. // Check for potential overflow
  5487. if (dp[0][0] > 0xFFFFFFFF) {
  5488. throw new Error('LCS length exceeds safe integer limit');
  5489. }
  5490.  
  5491. // Backtrack to build the actual LCS
  5492. const lcs = [];
  5493. let i = 0, j = 0;
  5494. while (i < n && j < m) {
  5495. const idx = i * m + j;
  5496. const p = pred[idx];
  5497. if (p === 0) {
  5498. lcs.push(a[i]);
  5499. i++; j++;
  5500. } else if (p === 1) {
  5501. i++;
  5502. } else {
  5503. j++;
  5504. }
  5505. }
  5506. return lcs;
  5507. }
  5508.  
  5509. /**
  5510. * Given original[] and modified[], produce an array of splice-ops:
  5511. * [ [start0, deleteCount0, addedItems0],
  5512. * [start1, deleteCount1, addedItems1],
  5513. * … ]
  5514. * When you do:
  5515. * let arr = original.slice();
  5516. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  5517. * arr will equal modified.
  5518. */
  5519. function diffSplices(original, modified) {
  5520. // Input validation
  5521. if (!Array.isArray(original) || !Array.isArray(modified)) {
  5522. throw new Error('Inputs must be arrays');
  5523. }
  5524.  
  5525. const origLen = original.length;
  5526. const modLen = modified.length;
  5527. // Early termination for trivial cases
  5528. if (origLen === 0 && modLen === 0) return [];
  5529. if (origLen === 0) return [[0, 0, modified.slice()]];
  5530. if (modLen === 0) return [[0, origLen, []]];
  5531.  
  5532. // Trim common prefix and suffix
  5533. let prefixLen = 0;
  5534. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  5535. prefixLen++;
  5536. }
  5537. let suffixLen = 0;
  5538. while (
  5539. suffixLen < origLen - prefixLen &&
  5540. suffixLen < modLen - prefixLen &&
  5541. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  5542. ) {
  5543. suffixLen++;
  5544. }
  5545.  
  5546. // Cache references for speed
  5547. const orig = original.slice(prefixLen, origLen - suffixLen);
  5548. const mod = modified.slice(prefixLen, modLen - suffixLen);
  5549. const lcs = computeLCS(orig, mod);
  5550. // Pre-allocate ops array, accounting for potential moves
  5551. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  5552. let opCount = 0;
  5553.  
  5554. let i = 0, j = 0, k = 0;
  5555. let curIndex = prefixLen;
  5556. const lcsLen = lcs.length;
  5557.  
  5558. while (k < lcsLen) {
  5559. const match = lcs[k];
  5560. let deleteCount = 0;
  5561. const deleted = [];
  5562. const added = [];
  5563.  
  5564. // 1) Collect deletions up to the next common element
  5565. while (i < orig.length && orig[i] !== match) {
  5566. deleted.push(orig[i]);
  5567. deleteCount++;
  5568. i++;
  5569. }
  5570.  
  5571. // 2) Collect insertions up to that same element
  5572. while (j < mod.length && mod[j] !== match) {
  5573. added.push(mod[j]);
  5574. j++;
  5575. }
  5576.  
  5577. // 3) Check for a move (deleted segment matches inserted segment)
  5578. let isMove = false;
  5579. if (deleteCount > 0 && deleteCount === added.length) {
  5580. isMove = deleted.every((x, idx) => x === added[idx]);
  5581. if (isMove) {
  5582. // If a move, split into delete and insert at different indices
  5583. if (deleteCount > 0) {
  5584. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  5585. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  5586. curIndex += added.length; // Advance past inserted items
  5587. }
  5588. }
  5589. }
  5590.  
  5591. // 4) Combine delete and insert into a single operation if not a move
  5592. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  5593. ops[opCount++] = [curIndex, deleteCount, added];
  5594. curIndex += added.length; // Advance past inserted items
  5595. }
  5596.  
  5597. // 5) Skip over the matching element itself
  5598. i++;
  5599. j++;
  5600. k++;
  5601. curIndex++;
  5602. }
  5603.  
  5604. // 6) Handle any trailing deletions and insertions as a single operation
  5605. const trailingDelete = orig.length - i;
  5606. const trailingAdd = mod.slice(j);
  5607. if (trailingDelete > 0 || trailingAdd.length > 0) {
  5608. // Check for trailing move
  5609. const trailingDeleted = orig.slice(i);
  5610. let isMove = false;
  5611. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  5612. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  5613. if (isMove) {
  5614. ops[opCount++] = [curIndex, trailingDelete, []];
  5615. ops[opCount++] = [curIndex, 0, trailingAdd];
  5616. }
  5617. }
  5618. if (!isMove) {
  5619. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  5620. }
  5621. }
  5622.  
  5623. // 7) Truncate ops array to actual size
  5624. ops.length = opCount;
  5625.  
  5626. return ops;
  5627. }
  5628. // class listPlaceholder {
  5629. // constructor(len){
  5630. // this.length = len;
  5631. // }
  5632. // }
  5633.  
  5634.  
  5635.  
  5636. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  5637. // var renderJob = this.renderJobsMap_[key],
  5638. // renderCallback = null;
  5639.  
  5640. // if (path === changeRecord.path) {
  5641. // let value = changeRecord.value;
  5642.  
  5643. // if (!_.v_(value)) {
  5644. // value = (value === void 0 || value === null) ? [] : [value];
  5645. // }
  5646.  
  5647. // let stampDomEntry = this.stampDom[path];
  5648.  
  5649. // if (stampDomEntry.mapping) {
  5650. // renderCallback = this.stampDomArray_.bind(
  5651. // this,
  5652. // value,
  5653. // key,
  5654. // stampDomEntry.mapping,
  5655. // stampDomEntry.reuseComponents,
  5656. // stampDomEntry.events,
  5657. // stampDomEntry.stamperStableList
  5658. // );
  5659. // }
  5660.  
  5661. // if (renderJob) renderJob.cancel();
  5662.  
  5663. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  5664.  
  5665. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  5666. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  5667. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  5668. // this.renderJobsMap_[key] = renderJob;
  5669. // }
  5670. // } else {
  5671. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  5672. // this.renderJobsMap_[key] = renderJob;
  5673. // renderCallback = function(callback, job) {
  5674. // callback();
  5675. // q4C(job, 10);
  5676. // }.bind(this, renderCallback, renderJob);
  5677. // }
  5678. // } else {
  5679. // renderCallback = (path + ".splices" === changeRecord.path)
  5680. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  5681. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  5682. // }
  5683.  
  5684. // if (renderJob) {
  5685. // _.vY(renderJob, renderCallback);
  5686. // } else {
  5687. // renderCallback();
  5688. // }
  5689. // }
  5690.  
  5691.  
  5692.  
  5693.  
  5694. const createStampDomFnsC_ = () => {
  5695.  
  5696. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  5697.  
  5698. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  5699. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  5700.  
  5701.  
  5702. // const rq0 = document.createElement('rp');
  5703. // rq0.setAttribute('yt-element-placholder', '');
  5704.  
  5705. const it0 = Date.now() - 80000000000;
  5706. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  5707.  
  5708.  
  5709. const getStampContainer_ = function (containerId) {
  5710.  
  5711. return this.getStampContainer7409_(containerId);
  5712.  
  5713. }
  5714.  
  5715.  
  5716.  
  5717.  
  5718. const createComponent_ = function (componentConfig, data, canReuse) {
  5719.  
  5720. return this.createComponent7409_(componentConfig, data, canReuse);
  5721.  
  5722. }
  5723.  
  5724.  
  5725. const s52 = Symbol();
  5726.  
  5727. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  5728.  
  5729. if (typeof (data || 0) === 'object') {
  5730. if (!data[s52]) data[s52] = genId();
  5731. component[s52] = data[s52];
  5732. // console.log(component[s52], data);
  5733. } else {
  5734. component[s52] = null;
  5735. }
  5736.  
  5737. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  5738.  
  5739. }
  5740.  
  5741. // let pr77 = Promise.resolve();
  5742.  
  5743. const flushRenderStamperComponentBindings_ = function () {
  5744. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  5745.  
  5746. if (this.deferredBindingTasks_.length >= 0) {
  5747.  
  5748. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  5749.  
  5750. const gid = this[`__$$stampFlushKey$$__`] = genId();
  5751. const g = (() => {
  5752. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  5753. // if (deferredBindingTasks_.length === 0) return;
  5754. // let q = this.deferredBindingTasks_;
  5755. // this.deferredBindingTasks_ = deferredBindingTasks_;
  5756. this.flushRenderStamperComponentBindings7409_();
  5757. // deferredBindingTasks_.length = 0;
  5758. // this.deferredBindingTasks_ = q;
  5759.  
  5760. const s = [...this.__lat457__];
  5761. this.__lat457__.clear();
  5762.  
  5763. for (const containerWr of s) {
  5764.  
  5765. const container = kRef(containerWr);
  5766. if (!container) continue;
  5767.  
  5768. // const s = new Set();
  5769. if (!container.querySelector('[ytx-flushing]')) {
  5770. if (container.hasAttribute('ytx-flushing')) {
  5771. const attrVal = container.getAttribute('ytx-flushing');
  5772. container.removeAttribute('ytx-flushing');
  5773. // s.add([container, attrVal]);
  5774. addTask(container, attrVal);
  5775. // addTaskIm(container, attrVal);
  5776. let ancestor = container.closest('[ytx-flushing]');
  5777. while (ancestor) {
  5778. if (ancestor.querySelector('[ytx-flushing]')) break;
  5779. const attrVal = ancestor.getAttribute('ytx-flushing');
  5780. ancestor.removeAttribute('ytx-flushing');
  5781. // s.add([ancestor, attrVal]);
  5782. addTask(ancestor, attrVal);
  5783. // addTaskIm(ancestor, attrVal);
  5784. ancestor = ancestor.closest('[ytx-flushing]');
  5785. }
  5786. }
  5787. }
  5788. }
  5789. executeTasks();
  5790.  
  5791.  
  5792. });
  5793. g();
  5794. // const useMicroTaskQueue = this.__qsd477__ === 2;
  5795. // useMicroTaskQueue ? addTask2(g) : g();
  5796. // executeTasks();
  5797.  
  5798. // addTask2(g);
  5799. // executeTasks();
  5800.  
  5801. }
  5802.  
  5803. throw new Error('e5bd8d2f');
  5804.  
  5805. }
  5806.  
  5807. let tasks = [];
  5808. let excuted = false;
  5809. const executeTasks = ()=>{
  5810. if(excuted || tasks.length === 0) return;
  5811. excuted = true;
  5812. let t0 = 0;
  5813. const perform = ()=>{
  5814. if(!t0) t0 = nativeNow();
  5815. const task = tasks.shift();
  5816. if(!task){
  5817. excuted = false;
  5818. return;
  5819. }
  5820. task.fn(task);
  5821. const t1 = nativeNow();
  5822. if(t1 - t0 > 10){
  5823. t0 = 0;
  5824. nextBrowserTick_(perform);
  5825. }else{
  5826. queueMicrotask_(perform);
  5827. }
  5828. }
  5829. queueMicrotask_(perform);
  5830. }
  5831.  
  5832. const taskFn = (task) => {
  5833.  
  5834. if(!task) return;
  5835. const { containerWr, attrVal } = task;
  5836. const container = kRef(containerWr);
  5837. if (!container) return;
  5838. if (attrVal === '0') return;
  5839. const bEventCb = attrVal === '2';
  5840. const producerWr = containerMapping.get(container);
  5841. const producer = kRef(producerWr);
  5842. if (!producer) return;
  5843. const hostElement = producer.hostElement;
  5844. if (!hostElement) return;
  5845. if (hostElement.isConnected !== true) return; // tbc
  5846. producer.markDirty && producer.markDirty();
  5847. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  5848. container
  5849. });
  5850.  
  5851. }
  5852.  
  5853. const addTask = (container, attrVal) => {
  5854. if (!container) return;
  5855. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  5856. tasks.push({
  5857. fn: taskFn,
  5858. containerWr: containerWr,
  5859. attrVal
  5860. });
  5861. // pr77 = pr77.then(()=>{
  5862.  
  5863. // })
  5864. // taskFn({
  5865. // containerWr: containerWr,
  5866. // attrVal
  5867. // })
  5868.  
  5869. }
  5870.  
  5871. const addTaskIm = (container, attrVal) => {
  5872. if (!container) return;
  5873. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  5874. taskFn({
  5875. fn: taskFn,
  5876. containerWr: containerWr,
  5877. attrVal
  5878. });
  5879.  
  5880. }
  5881.  
  5882.  
  5883. const addTask2 = (f) => {
  5884. // pr77 = pr77.then(f).catch(console.warn);
  5885. tasks.push({
  5886. fn: f
  5887. });
  5888.  
  5889. }
  5890.  
  5891. // const mo = new MutationObserver((mutations)=>{
  5892.  
  5893. // });
  5894. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  5895.  
  5896. const containerMapping = new WeakMap();
  5897.  
  5898. // let pr77 = Promise.resolve();
  5899. // let pr88 = Promise.resolve();
  5900. const uA4 = function (t, P) {
  5901. for (let y in t)
  5902. if (t.hasOwnProperty(y) && P[y])
  5903. return y;
  5904. return null
  5905. }
  5906.  
  5907. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  5908.  
  5909. const ax = ax_;
  5910. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  5911. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  5912. // const useMicroTaskQueue = false;
  5913. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  5914. ax[2].cancel();
  5915. useMicroTaskQueue2 = false;
  5916. }
  5917. // console.log(1992,containerId, this.hostElement.is)
  5918.  
  5919. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  5920. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  5921. // return false;
  5922.  
  5923. // }
  5924.  
  5925. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  5926. return false;
  5927. }
  5928.  
  5929. const hostIs = hostIs_;
  5930.  
  5931. 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;
  5932.  
  5933. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  5934. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  5935. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  5936. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  5937. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  5938. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  5939. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  5940. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  5941. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  5942. 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;
  5943. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  5944. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  5945. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  5946. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  5947. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  5948. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  5949. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  5950. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  5951. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  5952.  
  5953.  
  5954. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  5955.  
  5956.  
  5957. // console.log(5992,stackAt)
  5958.  
  5959. // console.log(2883, this[`__quu477#${containerId}__`] )
  5960. // if (useMicroTaskQueue) {
  5961. // console.log(stackAt)
  5962. // }
  5963.  
  5964. // if (useMicroTaskQueue) {
  5965. // console.log(1120301)
  5966. // }
  5967.  
  5968. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  5969.  
  5970. return useMicroTaskQueue2;
  5971.  
  5972. }
  5973.  
  5974. const frag385 = document.createDocumentFragment();
  5975. frag385.appendChild4202 = frag385.appendChild;
  5976. frag385.removeChild4202 = frag385.removeChild;
  5977. const cm385 = document.createComment('.');
  5978.  
  5979. const doc385 = document.implementation.createHTMLDocument();
  5980. const html385 = doc385.firstElementChild;
  5981. const node385 = html385.appendChild(document.createElement('div'));
  5982.  
  5983. const fixContainerApi = (container) => {
  5984. if (container instanceof Node) {
  5985. const containerDomApi = container.__domApi;
  5986. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  5987. // console.log(123882, container)
  5988. containerDomApi.removeChild588 = containerDomApi.removeChild;
  5989. containerDomApi.removeChild = function (elem) {
  5990. let r;
  5991. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  5992. s.setAttribute('ytx-flushing', '0');
  5993. }
  5994. try {
  5995. r = this.removeChild588(elem);
  5996. } catch (e) { }
  5997. if (!r) {
  5998. frag385.appendChild4202(elem);
  5999. frag385.removeChild4202(elem);
  6000. r = elem;
  6001. }
  6002. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  6003. s.removeAttribute('ytx-flushing');
  6004. }
  6005. return r;
  6006. }
  6007. }
  6008. }
  6009. }
  6010.  
  6011. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  6012.  
  6013. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  6014. if (typeof sqq === 'function') sqq();
  6015.  
  6016. // trigger in rendererStamperApplyChangeRecord_
  6017.  
  6018. // 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];
  6019. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  6020. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  6021. // 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];
  6022.  
  6023. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  6024. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  6025.  
  6026.  
  6027. const ax = this[`__quu477#${containerId}__`];
  6028. const hostIs = (this.hostElement || 0).is;
  6029. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  6030.  
  6031. const container = this.getStampContainer7409_(containerId);
  6032.  
  6033. containerMapping.set(container,
  6034. (this[wk] || (this[wk] = mWeakRef(this)))
  6035. );
  6036.  
  6037. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  6038. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  6039.  
  6040. // let dataList_ = dataList;
  6041. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  6042.  
  6043. dataList = null;
  6044. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  6045. let fq = 0;
  6046. const f = (() => {
  6047. if(fq) return;
  6048. fq = 1;
  6049. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  6050. this[`__$$stampSFn$$#${containerId}__`] = null;
  6051. const container = this.getStampContainer7409_(containerId);
  6052.  
  6053. this.__lat457__ = this.__lat457__ || new Set();
  6054. if(!container[wk]) container[wk] = mWeakRef(container);
  6055. this.__lat457__.add(container[wk]);
  6056. fixContainerApi(container);
  6057.  
  6058. // let q = this.deferredBindingTasks_;
  6059. // this.deferredBindingTasks_ = [];
  6060. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  6061. let e_;
  6062. try {
  6063. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  6064. } catch (e) { e_ = e }
  6065. this.__qsd477__ = false;
  6066. dataList_ = typeOrConfig = null;
  6067. fixContainerApi(container);
  6068. // this.deferredBindingTasks_ = q;
  6069. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  6070. if (!e_) {
  6071. // container.setAttribute('ytx-flushing', '0');
  6072. }
  6073. // if( container.childElementCount === 0 ){
  6074. // container.setAttribute('ytx-flushing', '0');
  6075. // this.markDirty && this.markDirty();
  6076. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  6077. // container
  6078. // });
  6079. // }
  6080.  
  6081.  
  6082.  
  6083.  
  6084. });
  6085. this[`__$$stampSFn$$#${containerId}__`] = f;
  6086. this[`__$$stampSqq$$#${containerId}__`] = f;
  6087. useMicroTaskQueue2 ? addTask2(f) : f();
  6088. executeTasks();
  6089.  
  6090. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  6091.  
  6092. return undefined;
  6093.  
  6094. }
  6095.  
  6096. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  6097.  
  6098.  
  6099. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  6100. if (typeof sqq === 'function') sqq();
  6101.  
  6102. // trigger in rendererStamperApplyChangeRecord_
  6103.  
  6104. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  6105. } else {
  6106. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  6107. }
  6108.  
  6109.  
  6110. // trigger in rendererStamperApplyChangeRecord_
  6111.  
  6112. // 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];
  6113. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  6114. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  6115.  
  6116. // 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];
  6117.  
  6118. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  6119. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  6120. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  6121.  
  6122. const ax = this[`__quu477#${containerId}__`];
  6123. const hostIs = (this.hostElement || 0).is;
  6124. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  6125.  
  6126.  
  6127. // 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];
  6128. // const useMicroTaskQueue = true;
  6129. const container = this.getStampContainer7409_(containerId);
  6130.  
  6131. containerMapping.set(container,
  6132. (this[wk] || (this[wk] = mWeakRef(this)))
  6133. );
  6134. const bEventCb = this.stampDom[stampKey].events;
  6135. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  6136. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  6137.  
  6138. // let indexSplicesObj_ = indexSplicesObj;
  6139. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  6140. // indexSplicesObj_ = {
  6141. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  6142. // const { index, addedCount, removed, object, type } = slice;
  6143. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  6144. // return { index, addedCount, removed, object, type };
  6145. // })
  6146. // };
  6147. // }
  6148.  
  6149.  
  6150. indexSplicesObj.indexSplices.forEach(slice => {
  6151. const object = slice.object;
  6152. if (!object || typeof object !== 'object') return;
  6153. // const { index, addedCount, removed, object, type } = slice;
  6154. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  6155. // return { index, addedCount, removed, object, type };
  6156. });
  6157.  
  6158. // let indexSplicesObj_ = indexSplicesObj;
  6159.  
  6160. // console.log(128783, indexSplicesObj)
  6161.  
  6162. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  6163. // const { index, addedCount, removed, object, type } = slice;
  6164. // return { index, addedCount, removed, object, type };
  6165. // });
  6166.  
  6167. indexSplicesObj = null;
  6168.  
  6169. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  6170. const gid = this[`__$$stampSID$$#${containerId}__`];
  6171. let fq = 0;
  6172. const f = (() => {
  6173. if(fq) return;
  6174. fq = 1;
  6175. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  6176. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  6177. const container = this.getStampContainer7409_(containerId);
  6178. if(!container) return;
  6179.  
  6180. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  6181.  
  6182. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  6183. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  6184. const mapping = this.stampDom[stampKey].mapping;
  6185.  
  6186. const map = new Map();
  6187.  
  6188. const currentObjKeys = object.map(objEntry => {
  6189. const mappingKey = uA4(mapping, objEntry);
  6190. if(!mappingKey) return null;
  6191. const data = objEntry[mappingKey];
  6192. if (!data[s52]) data[s52] = genId();
  6193. map.set(data[s52], objEntry);
  6194. // return ({
  6195. // objEntry,
  6196. // data: data,
  6197. // mappingKey: mappingKey,
  6198. // key: data[s52],
  6199. // exist: elementKeys.has(data[s52])
  6200. // });
  6201. return data[s52]
  6202.  
  6203. });
  6204.  
  6205. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  6206.  
  6207. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  6208.  
  6209. const splices = diffSplices(oldDomKeys, currentObjKeys);
  6210.  
  6211. // let myObject = object;
  6212. let indexSplicesObj_ = {
  6213. indexSplices: splices.map(splice => {
  6214. const index = splice[0];
  6215. const removedLen = splice[1];
  6216. const added = splice[2];
  6217. const addedCount = added.length;
  6218. const object = {};
  6219. object.length = index + addedCount;
  6220. for (let i = 0; i < addedCount; i++) {
  6221. object[index + i] = map.get(added[i]);
  6222. }
  6223. const removed = {};
  6224. removed.length = removedLen;
  6225.  
  6226. return { index, removed, object, addedCount }
  6227. })
  6228. };
  6229. map.clear();
  6230.  
  6231.  
  6232. this.__lat457__ = this.__lat457__ || new Set();
  6233. if(!container[wk]) container[wk] = mWeakRef(container);
  6234. this.__lat457__.add(container[wk]);
  6235. fixContainerApi(container);
  6236.  
  6237. // console.log(3882, indexSplicesObj_)
  6238. // let q = this.deferredBindingTasks_;
  6239. // this.deferredBindingTasks_ = [];
  6240. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  6241. let e_;
  6242. try {
  6243. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  6244. } catch (e) { e_ = e; }
  6245. this.__qsd477__ = false;
  6246. indexSplicesObj_ = null;
  6247. stampKey = indexSplicesObj_ = null;
  6248. fixContainerApi(container);
  6249. // this.deferredBindingTasks_ = q;
  6250. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  6251. if (!e_) {
  6252. // container.setAttribute('ytx-flushing', '0');
  6253. }
  6254.  
  6255.  
  6256. });
  6257. this[`__$$stampSqq$$#${containerId}__`] = f;
  6258. useMicroTaskQueue2 ? addTask2(f) : f();
  6259. executeTasks();
  6260.  
  6261. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  6262.  
  6263. return undefined;
  6264.  
  6265. }
  6266.  
  6267.  
  6268. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  6269. const dt0 = dt0a[0];
  6270. const dt1 = Date.now();
  6271. const obj = kRef(objWr);
  6272. if (!obj) return;
  6273. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  6274. if (xxx !== xxx_) return;
  6275. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  6276. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  6277. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  6278. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  6279. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  6280. const renderJob1 = obj.renderJobsMap_[containerId]
  6281. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  6282. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  6283. let e_, r;
  6284. try {
  6285. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  6286. } catch (e) {
  6287. e_ = e;
  6288. }
  6289. obj[`__quu477#${containerId}__`] = false;
  6290. if (e_) throw e_;
  6291. return r;
  6292. };
  6293.  
  6294.  
  6295. stampDomArray_.bind = function (obj, ...args) {
  6296. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  6297. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  6298. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  6299. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  6300. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  6301. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  6302. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  6303. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  6304. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  6305.  
  6306.  
  6307. const renderJob = obj.renderJobsMap_[containerId];
  6308.  
  6309. const dt0a = [Date.now()];
  6310. queueMicrotask_(() => { dt0a[0] = 0 });
  6311. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  6312. };
  6313.  
  6314. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  6315. const dt0 = dt0a[0];
  6316. const dt1 = Date.now();
  6317. const obj = kRef(objWr);
  6318. if (!obj) return;
  6319. const renderJob1 = obj.renderJobsMap_[containerId];
  6320. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  6321. let e_, r;
  6322. try {
  6323. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  6324. } catch (e) {
  6325. e_ = e;
  6326. }
  6327. obj[`__quu477#${containerId}__`] = false;
  6328. if (e_) throw e_;
  6329. return r;
  6330. };
  6331.  
  6332.  
  6333. stampDomArraySplices_.bind = function (obj, ...args) {
  6334. let [stampKey, containerId, indexSplicesObj] = args;
  6335. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  6336.  
  6337. const renderJob = obj.renderJobsMap_[containerId];
  6338.  
  6339. const dt0a = [Date.now()];
  6340. queueMicrotask_(() => { dt0a[0] = 0 });
  6341. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  6342. };
  6343.  
  6344.  
  6345. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  6346.  
  6347. }
  6348.  
  6349.  
  6350. const createStampDomFnsB_ = () => {
  6351.  
  6352. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  6353.  
  6354. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  6355. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  6356.  
  6357.  
  6358. const rq0 = document.createElement('rp');
  6359. rq0.setAttribute('yt-element-placholder', '');
  6360.  
  6361. let activeStampContainerId = '';
  6362.  
  6363. const componentBasedTaskPool = new WeakMap();
  6364.  
  6365.  
  6366. Node.prototype.checkFF = function () {
  6367. const pTask = componentBasedTaskPool.get(this);
  6368. if (!pTask) return null;
  6369. return [pTask, taskList.filter(e => e.taskId === pTask.taskId), taskList.filter(e => e.componentWr === this[wk])];
  6370. }
  6371.  
  6372. Node.prototype.checkGG = function () {
  6373. window.me849 = this;
  6374. const pTask = componentBasedTaskPool.get(this);
  6375. if (!pTask) return null;
  6376. window.me848 = pTask.taskId;
  6377. debugger;
  6378. loopTask();
  6379. }
  6380.  
  6381. NodeList.prototype.last = function () {
  6382. return this[this.length - 1];
  6383. }
  6384.  
  6385. const getStampContainer_ = function (containerId) {
  6386.  
  6387. // if(this.__byPass828__) return this.getStampContainer7409_(containerId);
  6388.  
  6389. this.__activeContainerId929__ = containerId;
  6390.  
  6391. return this.getStampContainer7409_(containerId);
  6392.  
  6393. }
  6394.  
  6395.  
  6396.  
  6397. const it0 = Date.now() - 80000000000;
  6398. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  6399.  
  6400.  
  6401. const createComponent_ = function (componentConfig, data, canReuse) {
  6402.  
  6403. this.___lastCreate3311__ = data;
  6404.  
  6405.  
  6406.  
  6407. if (this.__directProduction533__) {
  6408. const cName = this.getComponentName_(componentConfig, data);
  6409.  
  6410. return document.createElement(cName);
  6411. }
  6412.  
  6413. if (this.__byPass828__ || !this.__byPass348__) {
  6414.  
  6415. // console.log(39829004)
  6416. // console.log(new Error().stack)
  6417. return this.createComponent7409_(componentConfig, data, false);
  6418. }
  6419.  
  6420.  
  6421. const containerId = this.__activeContainerId929__;
  6422.  
  6423. // console.log(2883007, componentConfig, data, canReuse)
  6424.  
  6425. const r = rq0.cloneNode(false);
  6426.  
  6427. r.is = 'aa-bb-cc-dd';
  6428.  
  6429. return r;
  6430.  
  6431.  
  6432. }
  6433.  
  6434.  
  6435. const childrenObs = new MutationObserver((mutations) => {
  6436. loopTask();
  6437. });
  6438.  
  6439.  
  6440. class CTaskList {
  6441. constructor() {
  6442. this.head = this.tail = null;
  6443.  
  6444. // ref → {prev, next, level}
  6445. this.nodes = new Map();
  6446.  
  6447. // Per‑level sentinels
  6448. this.levelHead = [];
  6449. this.levelTail = [];
  6450.  
  6451. // Sorted list of non‑empty levels for O(log L) neighbour lookup
  6452. this.nonEmptyLevels = [];
  6453. this.counter = 0;
  6454. }
  6455.  
  6456. _ensure(level) {
  6457. while (this.levelTail.length <= level) {
  6458. this.levelTail.push(null);
  6459. this.levelHead.push(null);
  6460. }
  6461. }
  6462.  
  6463. // Binary‑search index inside nonEmptyLevels
  6464. _indexOfLevel(level) {
  6465. let lo = 0, hi = this.nonEmptyLevels.length;
  6466. while (lo < hi) {
  6467. const mid = (lo + hi) >> 1;
  6468. if (this.nonEmptyLevels[mid] < level) lo = mid + 1;
  6469. else hi = mid;
  6470. }
  6471. return lo;
  6472. }
  6473.  
  6474. _link(ref, prev, next, level) {
  6475.  
  6476.  
  6477. this.nodes.set(ref, { prev, next, level });
  6478.  
  6479. if (prev) this.nodes.get(prev).next = ref;
  6480. else this.head = ref;
  6481.  
  6482. if (next) this.nodes.get(next).prev = ref;
  6483. else this.tail = ref;
  6484.  
  6485. this.levelTail[level] = ref;
  6486. if (!this.levelHead[level]) this.levelHead[level] = ref;
  6487. }
  6488.  
  6489. _detach(ref) {
  6490. if (!ref || !this.nodes.has(ref)) return;
  6491.  
  6492.  
  6493. const { prev, next, level } = this.nodes.get(ref);
  6494.  
  6495. if (prev) this.nodes.get(prev).next = next;
  6496. else this.head = next;
  6497.  
  6498. if (next) this.nodes.get(next).prev = prev;
  6499. else this.tail = prev;
  6500.  
  6501. if (this.levelTail[level] === ref) {
  6502. this.levelTail[level] = prev && this.nodes.get(prev)?.level === level ? prev : null;
  6503. }
  6504. if (this.levelHead[level] === ref) {
  6505. this.levelHead[level] = next && this.nodes.get(next)?.level === level ? next : null;
  6506. }
  6507.  
  6508. if (this.levelTail[level] === null) {
  6509. const idx = this.nonEmptyLevels.indexOf(level);
  6510. if (idx !== -1) this.nonEmptyLevels.splice(idx, 1);
  6511. }
  6512.  
  6513. this.nodes.delete(ref);
  6514.  
  6515. }
  6516.  
  6517. push(component, level) {
  6518. if (!component) return;
  6519.  
  6520. // this.checkIntegrity();
  6521.  
  6522. const ref = component[wk] || (component[wk] = new WeakRef(component));
  6523.  
  6524. if (this.nodes.has(ref)) this._detach(ref);
  6525.  
  6526. this._ensure(level);
  6527.  
  6528. if (!this.levelTail[level]) {
  6529. // First node on this level
  6530. const idx = this._indexOfLevel(level);
  6531. const prevLvl = idx ? this.nonEmptyLevels[idx - 1] : null;
  6532. const nextLvl = idx < this.nonEmptyLevels.length ? this.nonEmptyLevels[idx] : null;
  6533.  
  6534. const prevRef = prevLvl !== null ? this.levelTail[prevLvl] : null;
  6535. const nextRef = nextLvl !== null ? this.levelHead[nextLvl] : null;
  6536.  
  6537. this._link(ref, prevRef, nextRef, level);
  6538. this.nonEmptyLevels.splice(idx, 0, level);
  6539. } else {
  6540. // Append to existing level
  6541. const prevRef = this.levelTail[level];
  6542. const nextRef = this.nodes.get(prevRef).next;
  6543. this._link(ref, prevRef, nextRef, level);
  6544. }
  6545.  
  6546. this.counter++;
  6547. // this.checkIntegrity();
  6548. }
  6549.  
  6550. remove(component) {
  6551. const ref = component && component.deref ? component : (component || 0)[wk];
  6552.  
  6553. // this.checkIntegrity();
  6554. this._detach(ref);
  6555.  
  6556. // this.checkIntegrity();
  6557. }
  6558.  
  6559. replace(componentOld, componentNew) {
  6560. if (!componentOld || !componentNew) {
  6561. throw new Error('replace failed: missing component');
  6562. }
  6563.  
  6564. if (componentOld === componentNew) {
  6565. return;
  6566. }
  6567.  
  6568. const refOld = componentOld[wk];
  6569. // ensure New has a weak‐ref
  6570. const refNew = componentNew[wk] || (componentNew[wk] = mWeakRef(componentNew));
  6571.  
  6572.  
  6573. if (refOld === refNew) {
  6574. return;
  6575. }
  6576.  
  6577. if (!refOld || !this.nodes.has(refOld)) {
  6578. throw new Error('replace failed: old component not found');
  6579. }
  6580.  
  6581. // this.checkIntegrity();
  6582.  
  6583. // If new is already in the list somewhere, detach it first
  6584. if (this.nodes.has(refNew)) {
  6585. this._detach(refNew);
  6586. }
  6587.  
  6588. // Pull out old pointers
  6589. const { prev, next, level } = this.nodes.get(refOld);
  6590.  
  6591. // Link into the main list
  6592. if (prev) {
  6593. this.nodes.get(prev).next = refNew;
  6594. } else {
  6595. this.head = refNew;
  6596. }
  6597.  
  6598. if (next) {
  6599. this.nodes.get(next).prev = refNew;
  6600. } else {
  6601. this.tail = refNew;
  6602. }
  6603.  
  6604. // Link into the per‐level sentinels
  6605. if (this.levelHead[level] === refOld) {
  6606. this.levelHead[level] = refNew;
  6607. }
  6608. if (this.levelTail[level] === refOld) {
  6609. this.levelTail[level] = refNew;
  6610. }
  6611.  
  6612. // Finally re‐key the Map entry
  6613. this.nodes.set(refNew, { prev, next, level });
  6614. this.nodes.delete(refOld);
  6615.  
  6616. // this.checkIntegrity();
  6617. }
  6618.  
  6619. _walk(ref, dir) {
  6620. if (!ref || !this.nodes.has(ref)) return null;
  6621.  
  6622. let cur = this.nodes.get(ref)[dir];
  6623. while (cur) {
  6624. if (cur.deref()) return cur;
  6625.  
  6626. // Clean up collected node
  6627. const nxt = this.nodes.get(cur)[dir];
  6628. this._detach(cur);
  6629. cur = nxt;
  6630. }
  6631. return null;
  6632. }
  6633.  
  6634. nextComp(component) {
  6635. const ref = component && component.deref ? component : (component || 0)[wk];
  6636. return this._walk(ref, 'next');
  6637. }
  6638.  
  6639. prevComp(component) {
  6640. const ref = component && component.deref ? component : (component || 0)[wk];
  6641. return this._walk(ref, 'prev');
  6642. }
  6643.  
  6644. hasComp(component) {
  6645. const ref = component && component.deref ? component : (component || 0)[wk];
  6646. return !!(ref && this.nodes.has(ref))
  6647. }
  6648.  
  6649. count() {
  6650. return this.counter;
  6651. }
  6652.  
  6653. countLevels() {
  6654. const r = [];
  6655. for (let i = 0; ; i++) {
  6656. if (!this.levelHead[i] || !this.levelTail[i]) break;
  6657. let cur = this.levelHead[i];
  6658. let curs = [];
  6659. while (cur && this.nodes.get(cur).level === i) {
  6660. curs.push((cur));
  6661. cur = taskListP.nextComp(cur);
  6662. }
  6663.  
  6664. if (curs[0] !== this.levelHead[i]) debugger;
  6665. if (curs[curs.length - 1] !== this.levelTail[i]) debugger;
  6666. r.push({
  6667. head: this.levelHead[i],
  6668. tail: this.levelTail[i],
  6669. curs: curs,
  6670. set: new Set(curs),
  6671. arrSize: curs.length,
  6672. setSize: (new Set(curs)).size
  6673.  
  6674. });
  6675. }
  6676. return r;
  6677. }
  6678.  
  6679.  
  6680. // // Integrity checker helper
  6681. // checkIntegrity() {
  6682. // const list = this;
  6683. // // Global head/tail pointers
  6684. // if (list.head !== null) {
  6685. // const headNode = list.nodes.get(list.head);
  6686. // assert(headNode.prev === null, "Integrity: head.prev must be null");
  6687. // }
  6688. // if (list.tail !== null) {
  6689. // const tailNode = list.nodes.get(list.tail);
  6690. // assert(tailNode.next === null, "Integrity: tail.next must be null");
  6691. // }
  6692.  
  6693. // // Per-level head/tail and level consistency
  6694. // list.nonEmptyLevels.forEach(level => {
  6695. // assert(list.levelHead[level] != null, `Integrity: levelHead[${level}] should not be null`);
  6696. // assert(list.levelTail[level] != null, `Integrity: levelTail[${level}] should not be null`);
  6697. // const headRef = list.levelHead[level];
  6698. // const tailRef = list.levelTail[level];
  6699. // const headNode = list.nodes.get(headRef);
  6700. // const tailNode = list.nodes.get(tailRef);
  6701. // assert(headNode.level === level, `Integrity: levelHead[${level}].level mismatch`);
  6702. // assert(tailNode.level === level, `Integrity: levelTail[${level}].level mismatch`);
  6703. // });
  6704.  
  6705. // // nonEmptyLevels sorted ascending
  6706. // for (let i = 1; i < list.nonEmptyLevels.length; i++) {
  6707. // assert(
  6708. // list.nonEmptyLevels[i] > list.nonEmptyLevels[i - 1],
  6709. // "Integrity: nonEmptyLevels must be sorted ascending"
  6710. // );
  6711. // }
  6712.  
  6713. // this.countLevels();
  6714. // }
  6715.  
  6716. }
  6717.  
  6718.  
  6719. const taskListP = new CTaskList();
  6720. const taskList = [];
  6721. let taskCounter = 0;
  6722. window.me55 = ()=>taskListP;
  6723.  
  6724. const taskPush = (component, pTask0, pTask1, deferred = false) => {
  6725. component = kRef(component);
  6726. if (!component) return;
  6727. if (!pTask0) pTask0 = pTask1; else Object.assign(pTask0, pTask1);
  6728. componentBasedTaskPool.set(component, pTask0);
  6729. const id = taskCounter = (taskCounter & 1073741823) + 1;
  6730. pTask0.taskId = id;
  6731. if (!pTask1.byPass) pTask0.byPass = false;
  6732. taskListP.push(component, 0);
  6733. if (!deferred) nonDeferredTask = component[wk];
  6734. // taskList.push({
  6735. // taskId: id,
  6736. // componentWr: component[wk]
  6737. // })
  6738. return pTask0;
  6739. }
  6740.  
  6741. const domComment_ = document.createComment('y');
  6742. const triggerDomChange = (node) => {
  6743. node.appendChild(domComment_).remove();
  6744. }
  6745.  
  6746.  
  6747. const performTask = (component, pTask = undefined) => {
  6748.  
  6749. if (pTask === undefined) pTask = componentBasedTaskPool.get(component);
  6750. if (!pTask || !component) return;
  6751. let { step, producer, containerId, typeOrConfig, data, flushing, selfProducer } = pTask;
  6752. producer = kRef(producer);
  6753. selfProducer = kRef(selfProducer);
  6754.  
  6755. const resolveSelf = () => {
  6756.  
  6757. const node = component;
  6758.  
  6759. const prevCur = taskListP.prevComp(node);
  6760.  
  6761. node.removeAttribute('ytx-flushing');
  6762.  
  6763. // if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement && selfProducer.hostElement.isConnected) {
  6764.  
  6765. if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement) {
  6766. const node = component;
  6767.  
  6768. let shouldMarkDirty = false;
  6769.  
  6770. const m = new Set();
  6771.  
  6772. const producer = selfProducer;
  6773.  
  6774. for (const [containerId, bEvent, hasData] of flushing) {
  6775. if (hasData || hasData === null) {
  6776. shouldMarkDirty = true;
  6777. if (bEvent) {
  6778. const container = producer.getStampContainer7409_(containerId);
  6779. // console.log(644221499, container)
  6780. m.add(container);
  6781. }
  6782. }
  6783. }
  6784. flushing.length = 0;
  6785.  
  6786. if (shouldMarkDirty) {
  6787. producer.markDirty && producer.markDirty();
  6788. let q = true;
  6789. for (const container of m) {
  6790. if (!q) producer.markDirty && producer.markDirty();
  6791. q = false;
  6792. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  6793. container
  6794. });
  6795. }
  6796. }
  6797.  
  6798. }
  6799.  
  6800.  
  6801.  
  6802. const s = new Set();
  6803.  
  6804. const parentComponent = node.closest('[ytx-flushing]');
  6805. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  6806. if (!s.has(parentComponent[wk])) {
  6807. s.add(parentComponent[wk]);
  6808. }
  6809. }
  6810.  
  6811. const producerElement = producer ? producer.hostElement : null;
  6812.  
  6813. if (parentComponent && parentComponent !== producerElement) {
  6814.  
  6815. const parentComponent = producerElement;
  6816. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  6817. if (!s.has(parentComponent[wk])) {
  6818. s.add(parentComponent[wk])
  6819. }
  6820. }
  6821.  
  6822. }
  6823.  
  6824. for (const p of s) {
  6825. const node = kRef(p);
  6826. triggerDomChange(node);
  6827. }
  6828.  
  6829. if (!node.hasAttribute('ytx-flushing') && (!pTask.flushing || !pTask.flushing.length) && !pTask.typeOrConfig && !pTask.data) {
  6830. componentBasedTaskPool.delete(node);
  6831. taskListP.remove(node);
  6832. }
  6833.  
  6834.  
  6835. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head), parents: [...s]};
  6836.  
  6837. }
  6838.  
  6839. if (pTask.step === 'creation') {
  6840.  
  6841. if (flushing) debugger;
  6842. if (!producer || !typeOrConfig) return;
  6843. if (component.parentNode && component.parentNode.id === containerId && component.parentNode === producer.getStampContainer7409_(containerId)) {
  6844. pTask.step = 'flushStamper'; pTask.pq33 = 3;
  6845.  
  6846. // const aNode = producer.createComponent7409_(typeOrConfig, data, false);
  6847.  
  6848. const prevCur = taskListP.prevComp(component);
  6849.  
  6850. const pTaskId = pTask.taskId;
  6851. const cName = producer.getComponentName_(typeOrConfig, data);
  6852. const aNode = document.createElement(cName);
  6853. const qNode = component;
  6854.  
  6855. aNode.setAttribute('ytx-stamp', 'flusher');
  6856. aNode.setAttribute('ytx-flushing', '2');
  6857. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  6858.  
  6859. taskListP.replace(qNode, aNode);
  6860.  
  6861. componentBasedTaskPool.delete(qNode);
  6862. componentBasedTaskPool.set(aNode, pTask); // pTask will be obtained and proceeded during "dom change" in the same micro task
  6863.  
  6864.  
  6865. const container = component.parentNode;
  6866. const containerApi = container.__domApi || container;
  6867.  
  6868. const frag = document.createDocumentFragment();
  6869. frag.appendChild(aNode);
  6870. containerApi.insertBefore(frag, qNode);
  6871. containerApi.removeChild(qNode);
  6872. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  6873.  
  6874. }
  6875. } else if (pTask.step === 'flushStamper') {
  6876.  
  6877. if (flushing) debugger;
  6878.  
  6879. if (!producer || !typeOrConfig) return;
  6880. pTask.step = 'flushStamperWait';
  6881. pTask.typeOrConfig = null;
  6882. pTask.data = null;
  6883.  
  6884. const prevCur = taskListP.prevComp(component);
  6885.  
  6886. const node = component;
  6887. node.setAttribute('ytx-flushing', '3');
  6888.  
  6889. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  6890. // flushedObserver.observe(node, { subtree: true, childList: true });
  6891. producer.deferredBindingTasks_.push(taskB);
  6892. producer.flushRenderStamperComponentBindings7409_();
  6893. // try{Polymer.flush()}catch(e){}
  6894. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  6895.  
  6896. } else if (pTask.step === 'flushStamperWait') {
  6897.  
  6898. if (flushing) debugger;
  6899. if (!producer) return;
  6900.  
  6901. // producer undetermined
  6902.  
  6903. const node = component;
  6904.  
  6905. if (!node.querySelector('[ytx-flushing]')) {
  6906.  
  6907. pTask.step = 'idleContainer';
  6908.  
  6909. return resolveSelf();
  6910.  
  6911.  
  6912. }
  6913.  
  6914. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish') {
  6915.  
  6916. if (producer && typeOrConfig) {
  6917.  
  6918. pTask.typeOrConfig = null;
  6919. pTask.data = null;
  6920.  
  6921. const prevCur = taskListP.prevComp(component);
  6922.  
  6923. const node = component;
  6924. node.setAttribute('ytx-flushing', '3');
  6925.  
  6926. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  6927. // flushedObserver.observe(node, { subtree: true, childList: true });
  6928. producer.deferredBindingTasks_.push(taskB);
  6929. producer.flushRenderStamperComponentBindings7409_();
  6930. // try{Polymer.flush()}catch(e){}
  6931. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  6932. }
  6933.  
  6934. const node = component;
  6935.  
  6936. if (!node.querySelector('[ytx-flushing]')) {
  6937. pTask.step = 'idleProducer';
  6938. return resolveSelf();
  6939. }
  6940. // const selfProducer = kRef(pTask.selfProducer);
  6941.  
  6942. }
  6943.  
  6944. };
  6945.  
  6946. const performTaskQueued = (component)=>{
  6947. queueMicrotask_(()=>{
  6948. performTask(component);
  6949. });
  6950. };
  6951.  
  6952. let isLooping = false;
  6953. let nonDeferredTask = null;
  6954. let loopTaskQ = 0;
  6955. const loopTask = () => {
  6956. if (isLooping) return ++loopTaskQ;
  6957. isLooping = true;
  6958. loopTaskQ = 0;
  6959. let t0 = 0;
  6960. let cur = taskListP.head;
  6961. let nextCur = cur;
  6962. const taskExec = () => {
  6963.  
  6964. if (!t0) {
  6965. t0 = nativeNow();
  6966. }
  6967.  
  6968. if (nonDeferredTask && nextCur && taskListP.nodes.has(nextCur) && taskListP.nodes.get(nextCur).level === 1) {
  6969. nextCur = nonDeferredTask
  6970. }
  6971.  
  6972. nonDeferredTask = null;
  6973.  
  6974. for (;cur = nextCur; ) {
  6975.  
  6976. nextCur = taskListP.nextComp(cur);
  6977. const nextCur0 = nextCur;
  6978.  
  6979. const taskComponent = kRef(cur);
  6980. if (taskComponent) {
  6981. if(taskComponent === window.me849) debugger;
  6982. const pTask = componentBasedTaskPool.get(taskComponent);
  6983. if (pTask) {
  6984. if (pTask.taskId > 0 && !pTask.byPass) {
  6985. if (pTask.taskId === window.me848) debugger;
  6986.  
  6987. let shouldPerformTask = false;
  6988. if (pTask.step === 'creation' && pTask.typeOrConfig) {
  6989. shouldPerformTask = true;
  6990. } else if (pTask.step === 'flushStamper' && pTask.typeOrConfig) {
  6991. shouldPerformTask = true;
  6992. } else if (pTask.step === 'flushStamperWait' && !taskComponent.querySelector('[ytx-flushing]')) {
  6993. shouldPerformTask = true;
  6994. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish' && (pTask.typeOrConfig || !taskComponent.querySelector('[ytx-flushing]'))) {
  6995. shouldPerformTask = true;
  6996. }
  6997.  
  6998. let b = shouldPerformTask && taskComponent.parentNode;
  6999. if (b) {
  7000.  
  7001. const result = performTask(taskComponent, pTask);
  7002. let kbb = false;
  7003. if(typeof result ==='object' && result.nextCur === nextCur0){
  7004.  
  7005. } else if(taskListP.nextComp(cur) === null && taskListP.nextComp(cur) !== nextCur0) {
  7006. kbb = true;
  7007. }
  7008. if (typeof result === 'object' && result.parents instanceof Array) {
  7009.  
  7010. const nextCur_ = result.nextCur;
  7011. nextCur = nextCur_;
  7012. const parents = result.parents;
  7013. if (parents.length >= 1) {
  7014. const eSet = new Set(parents); // weak refs
  7015. eSet.add(nextCur_)
  7016. for (let cur_ = taskListP.head; cur_; cur_ = taskListP.nextComp(cur_)) {
  7017. if (eSet.has(cur_)) {
  7018. nextCur = cur_;
  7019. break;
  7020. }
  7021. }
  7022. }
  7023.  
  7024.  
  7025. } else if(typeof result === 'object' && result.nextCur){
  7026. nextCur = result.nextCur;
  7027. }
  7028.  
  7029.  
  7030. if (nativeNow() - t0 > 10) {
  7031. t0 = 0;
  7032. nextBrowserTick_(taskExec);
  7033. } else {
  7034. queueMicrotask_(taskExec);
  7035. }
  7036.  
  7037. return;
  7038.  
  7039. }
  7040.  
  7041. }
  7042.  
  7043. }
  7044.  
  7045. }
  7046.  
  7047. }
  7048.  
  7049. isLooping = false;
  7050.  
  7051. if(loopTaskQ > 0) nextBrowserTick_(loopTask);
  7052.  
  7053. };
  7054.  
  7055. queueMicrotask_(taskExec);
  7056.  
  7057. };
  7058.  
  7059.  
  7060. let q244 = new PromiseExternal();
  7061. let q248a = [];
  7062. let q248b = [];
  7063. let q248c = [];
  7064. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  7065.  
  7066. if(this.__byPass828__) {
  7067.  
  7068. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7069. }
  7070.  
  7071. const isLastCreate = this.___lastCreate3311__ === data; // false for native element. true for RP or native element
  7072.  
  7073. this.___lastCreate3311__ = -0.125;
  7074.  
  7075.  
  7076. const containerId = this.__activeContainerId929__;
  7077. if (!component[wk]) component[wk] = mWeakRef(component);
  7078. if (!this[wk]) this[wk] = mWeakRef(this);
  7079.  
  7080. const pTask = componentBasedTaskPool.get(component);
  7081.  
  7082. const isSelfProducer = (pTask && pTask.selfProducer && pTask.flushing);
  7083.  
  7084.  
  7085. const abandonUnreadySubtree = () => {
  7086. for (const e of component.querySelectorAll('[ytx-flushing]')) {
  7087. const pTask = componentBasedTaskPool.get(e);
  7088. if (pTask) {
  7089. pTask.step = 'abandon';
  7090. pTask.taskId = 0;
  7091. if (pTask.flushing) pTask.flushing.length = 0;
  7092. pTask.flushing = null;
  7093.  
  7094. pTask.typeOrConfig = null
  7095. pTask.data = null
  7096.  
  7097. componentBasedTaskPool.delete(e);
  7098. taskListP.remove(e);
  7099. }
  7100. e.removeAttribute('ytx-flushing');
  7101. if (e.nodeName === 'RP') e.remove();
  7102. }
  7103. }
  7104.  
  7105. const flushNowTask = (componentWr, pTaskId, flag) => {
  7106. const component = kRef(componentWr);
  7107. if (!component) return;
  7108. const pTaskNew = componentBasedTaskPool.get(component);
  7109. if (!pTaskNew) return;
  7110. if (pTaskId !== pTaskNew.taskId) return;
  7111. pTaskNew.byPass = false;
  7112. if (flag & 1) {
  7113. performTaskQueued(component);
  7114. performTaskQueued(component);
  7115. performTaskQueued(component);
  7116. } else {
  7117. performTask(component);
  7118. performTask(component);
  7119. performTask(component);
  7120. }
  7121. return true;
  7122. }
  7123.  
  7124. const flushNow = (component) => {
  7125.  
  7126.  
  7127.  
  7128. const cName = this.getComponentName_(typeOrConfig, data);
  7129. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  7130. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  7131.  
  7132. if(mDeferred) {
  7133. component.setAttribute('ytx-defer-stamp','');
  7134. this.hostElement.setAttribute('ytx-defer-stamp','');
  7135. }
  7136.  
  7137. const pTaskNew = taskPush(component, pTask, {
  7138. step: isSelfProducer ? 'mightFlushAndWaitContainersRenderFinish' : 'flushStamper',
  7139. producer: this[wk],
  7140. containerId: containerId,
  7141. typeOrConfig: typeOrConfig,
  7142. data: data,
  7143. byPass: true,
  7144. pq33: 7
  7145. }, mDeferred ? 1 : 0);
  7146.  
  7147. const pTaskId = pTaskNew.taskId;
  7148.  
  7149. const componentWr = component[wk];
  7150.  
  7151.  
  7152. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2w');
  7153.  
  7154. if (mDeferred ) {
  7155.  
  7156. q248a.push([componentWr, pTaskId]);
  7157.  
  7158. setTimeout(() => {
  7159. const q248 = q248a;
  7160.  
  7161. if (!q248.length) return;
  7162. let q246 = q248.slice();
  7163. q248.length = 0;
  7164.  
  7165. let doLoop = false;
  7166. for (const [componentWr, pTaskId] of q246) {
  7167. // if(!)
  7168. // console.log(2188, kRef(componentWr).parentNode)
  7169. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  7170. }
  7171. q246.length = 0;
  7172. q246 = null;
  7173. if (doLoop) loopTask();
  7174.  
  7175. }, 0);
  7176.  
  7177.  
  7178. } else {
  7179.  
  7180. if(!component.parentNode){
  7181.  
  7182. q248b.push([componentWr, pTaskId]);
  7183.  
  7184. (() => {
  7185.  
  7186. const q248 = q248b;
  7187.  
  7188. if (!q248.length) return;
  7189. let q246 = q248.slice();
  7190. q248.length = 0;
  7191. let doLoop = false;
  7192. for (const [componentWr, pTaskId] of q246) {
  7193. if (flushNowTask(componentWr, pTaskId, 0) === true) doLoop = true;
  7194. }
  7195. q246.length = 0;
  7196. q246 = null;
  7197. if (doLoop) loopTask();
  7198. })();
  7199.  
  7200. } else {
  7201.  
  7202.  
  7203. q248c.push([componentWr, pTaskId]);
  7204.  
  7205. nextBrowserTick_(() => {
  7206. const q248 = q248c;
  7207.  
  7208. if (!q248.length) return;
  7209. let q246 = q248.slice();
  7210. q248.length = 0;
  7211.  
  7212. let doLoop = false;
  7213. for (const [componentWr, pTaskId] of q246) {
  7214. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  7215. }
  7216. q246.length = 0;
  7217. q246 = null;
  7218. if (doLoop) loopTask();
  7219.  
  7220. });
  7221.  
  7222. }
  7223.  
  7224. }
  7225.  
  7226.  
  7227.  
  7228. loopTask();
  7229.  
  7230. };
  7231.  
  7232. if (!isLastCreate) {
  7233.  
  7234. abandonUnreadySubtree();
  7235.  
  7236. flushNow(component);
  7237. return;
  7238.  
  7239. } else {
  7240. if (pTask) pTask.taskId = 0;
  7241. }
  7242.  
  7243. if (this.__byPass828__ || !this.__byPass348__) {
  7244. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  7245. }
  7246.  
  7247. if (pTask && pTask.step !== 'creation') {
  7248.  
  7249. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2c');
  7250.  
  7251. abandonUnreadySubtree();
  7252.  
  7253. flushNow(component);
  7254.  
  7255. return;
  7256.  
  7257. } else {
  7258.  
  7259. if (component.nodeName === "RP") {
  7260.  
  7261. component.setAttribute('ytx-stamp', 'flusher');
  7262.  
  7263. component.setAttribute('ytx-flushing', '1');
  7264.  
  7265. const cName = this.getComponentName_(typeOrConfig, data);
  7266. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  7267. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  7268.  
  7269. if(mDeferred) {
  7270. component.setAttribute('ytx-defer-stamp','');
  7271. this.hostElement.setAttribute('ytx-defer-stamp','');
  7272. }
  7273.  
  7274. taskPush(component, pTask, {
  7275. step: 'creation',
  7276. producer: this[wk],
  7277. containerId: containerId,
  7278. typeOrConfig: typeOrConfig,
  7279. data: data
  7280. }, mDeferred ? 1 : 0);
  7281. loopTask();
  7282.  
  7283. } else {
  7284.  
  7285.  
  7286. const aNode = component;
  7287. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  7288.  
  7289. aNode.setAttribute('ytx-stamp', 'flusher');
  7290. aNode.setAttribute('ytx-flushing', '2');
  7291.  
  7292. flushNow(component);
  7293.  
  7294. }
  7295.  
  7296. }
  7297.  
  7298.  
  7299. }
  7300. flushRenderStamperComponentBindings_ = function () {
  7301.  
  7302. if (!this.__byPass348__) {
  7303. return this.flushRenderStamperComponentBindings7409_();
  7304. }
  7305. if (this.__byPass828__) {
  7306. const wr = this[wk] || (this[wk] = mWeakRef(this));
  7307. queueMicrotask_(() => {
  7308. const producer = kRef(wr);
  7309. if (!producer) return;
  7310. producer.flushRenderStamperComponentBindings7409_();
  7311. });
  7312. throw new Error('5ii48');
  7313. }
  7314. throw new Error('5ii48')
  7315. }
  7316.  
  7317.  
  7318. const directComponentList = new Set([
  7319. // for YouTube Tabview Totara
  7320. "YTD-STRUCTURED-DESCRIPTION-CONTENT-RENDERER",
  7321. "YTD-VIDEO-DESCRIPTION-HEADER-RENDERER",
  7322. "YTD-ENGAGEMENT-PANEL-SECTION-LIST-RENDERER",
  7323. ]);
  7324.  
  7325.  
  7326. let kf33;
  7327. let kf3b = 0;
  7328.  
  7329. const sb88 = Symbol();
  7330.  
  7331. const onStampDone = (producer) =>{
  7332.  
  7333.  
  7334. const flushing_ = producer[sb88];
  7335.  
  7336. const flushing = flushing_.slice();
  7337. flushing_.length = 0;
  7338.  
  7339. if (flushing && flushing.length > 0) {
  7340.  
  7341. let shouldMarkDirty = false;
  7342.  
  7343. const m = new Set();
  7344.  
  7345. for (const [containerId, bEvent, hasData] of flushing) {
  7346. if (hasData || hasData === null) {
  7347. shouldMarkDirty = true;
  7348. if (bEvent) {
  7349. const container = producer.getStampContainer7409_(containerId);
  7350. // console.log(644221499, container)
  7351. m.add(container);
  7352. }
  7353. }
  7354. }
  7355. flushing.length = 0;
  7356.  
  7357. if (shouldMarkDirty) {
  7358. producer.markDirty && producer.markDirty();
  7359. let q = true;
  7360. for (const container of m) {
  7361. if (!q) producer.markDirty && producer.markDirty();
  7362. q = false;
  7363. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  7364. container
  7365. });
  7366. }
  7367. }
  7368.  
  7369. }
  7370.  
  7371.  
  7372. }
  7373.  
  7374. stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  7375. // this.__byPass828__ = true;
  7376.  
  7377. // return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7378.  
  7379. const producer = this;
  7380. const hostElement = producer.hostElement;
  7381.  
  7382. let kf = false;
  7383. const kf3t = nativeNow();
  7384. const kf34 = Math.floor((kf3t - kf3b) / 8);
  7385.  
  7386. if (!kf33 || kf34 !== kf33) {
  7387. kf33 = kf34;
  7388. kf3b = kf3t - kf34 * 8;
  7389. kf = true;
  7390. }
  7391.  
  7392. const container = this.getStampContainer7409_(containerId);
  7393. if (container && !container.__rk75401__) {
  7394. container.__rk75401__ = true;
  7395. childrenObs.observe(container, { subtree: false, childList: true });
  7396. }
  7397.  
  7398. if (kf) this.__directProduction533__ = true;
  7399. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  7400. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  7401. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  7402. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  7403. else this.__directProduction533__ = false;
  7404.  
  7405. this.__directProduction533__ = true;
  7406.  
  7407. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  7408.  
  7409. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  7410.  
  7411. const bEventCb = this.stampDom[stampKey].events;
  7412.  
  7413. this.__activeContainerId929__ = containerId;
  7414.  
  7415. if (!this[wk]) this[wk] = mWeakRef(this);
  7416. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  7417. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  7418. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  7419. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  7420. hostElement.setAttribute('ytx-stamp', 'producer');
  7421. }
  7422.  
  7423.  
  7424. if (this.__byPass828__) {
  7425.  
  7426. const flushing = this[sb88] || (this[sb88] = []);
  7427. flushing.push([containerId, bEventCb, null]);
  7428. let r, e_
  7429. try {
  7430. this.__byPass348__ = true;
  7431. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7432. } catch (e) {
  7433. e_ = e;
  7434. }
  7435. this.__byPass348__ = false;
  7436.  
  7437. nextBrowserTick_(() => {
  7438. onStampDone(this);
  7439. });
  7440.  
  7441. if (e_ && e_.message !== '5ii48') throw e_;
  7442. return;
  7443.  
  7444. }
  7445.  
  7446.  
  7447. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  7448.  
  7449. const flushing = pTask ? (pTask.flushing || []) : [];
  7450. flushing.push([containerId, bEventCb, null]);
  7451. hostElement.setAttribute('ytx-flushing', 's-1');
  7452.  
  7453. if (pTask) {
  7454. // pTask.taskId = -1;
  7455. pTask.byPass = true;
  7456. }
  7457. if (hostElement && !hostElement.__rk75401__) {
  7458. hostElement.__rk75401__ = true;
  7459. childrenObs.observe(hostElement, { subtree: false, childList: true });
  7460. }
  7461.  
  7462. let r, e_
  7463. try {
  7464. this.__byPass348__ = true;
  7465. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7466. } catch (e) {
  7467. e_ = e;
  7468. }
  7469. this.__byPass348__ = false;
  7470.  
  7471. taskPush(hostElement, pTask, {
  7472. step: 'mightFlushAndWaitContainersRenderFinish',
  7473. selfProducer: this[wk],
  7474. flushing
  7475. });
  7476. loopTask();
  7477.  
  7478. triggerDomChange(container);
  7479. triggerDomChange(hostElement);
  7480.  
  7481. if (e_ && e_.message !== '5ii48') throw e_;
  7482.  
  7483. };
  7484.  
  7485. stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7486. // this.__byPass828__ = true;
  7487.  
  7488.  
  7489.  
  7490. // return this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7491.  
  7492. const producer = this;
  7493. const hostElement = producer.hostElement;
  7494.  
  7495. let kf = false;
  7496. const kf3t = nativeNow();
  7497. const kf34 = Math.floor((kf3t - kf3b) / 8);
  7498.  
  7499. if (!kf33 || kf34 !== kf33) {
  7500. kf33 = kf34;
  7501. kf3b = kf3t - kf34 * 8;
  7502. kf = true;
  7503. }
  7504.  
  7505. const container = this.getStampContainer7409_(containerId);
  7506. if (container && !container.__rk75401__) {
  7507. container.__rk75401__ = true;
  7508. childrenObs.observe(container, { subtree: false, childList: true });
  7509. }
  7510.  
  7511. if (kf) this.__directProduction533__ = true;
  7512. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  7513. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  7514. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  7515. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  7516. else this.__directProduction533__ = false;
  7517.  
  7518. bReuse = false;
  7519.  
  7520. this.__directProduction533__ = true;
  7521.  
  7522. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  7523. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  7524.  
  7525. this.__activeContainerId929__ = containerId;
  7526.  
  7527. if (!this[wk]) this[wk] = mWeakRef(this);
  7528. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  7529. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  7530. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  7531. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  7532. hostElement.setAttribute('ytx-stamp', 'producer');
  7533. }
  7534.  
  7535.  
  7536. if (this.__byPass828__) {
  7537.  
  7538. const flushing = this[sb88] || (this[sb88] = []);
  7539. flushing.push([containerId, bEventCb, !!dataList]);
  7540. let r, e_
  7541. try {
  7542. this.__byPass348__ = true;
  7543. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7544. } catch (e) {
  7545. e_ = e;
  7546. }
  7547. this.__byPass348__ = false;
  7548.  
  7549. nextBrowserTick_(() => {
  7550. onStampDone(this);
  7551. });
  7552.  
  7553. if (e_ && e_.message !== '5ii48') throw e_;
  7554. return;
  7555.  
  7556. }
  7557.  
  7558.  
  7559. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  7560.  
  7561. const flushing = pTask ? (pTask.flushing || []) : [];
  7562. flushing.push([containerId, bEventCb, !!dataList]);
  7563. hostElement.setAttribute('ytx-flushing', 's-1');
  7564.  
  7565. if (pTask) {
  7566. pTask.byPass = true;
  7567. // pTask.taskId = -1;
  7568. }
  7569.  
  7570. if (hostElement && !hostElement.__rk75401__) {
  7571. hostElement.__rk75401__ = true;
  7572. childrenObs.observe(hostElement, { subtree: false, childList: true });
  7573. }
  7574.  
  7575. let r, e_
  7576. try {
  7577. this.__byPass348__ = true;
  7578. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7579. } catch (e) {
  7580. e_ = e;
  7581. }
  7582. this.__byPass348__ = false;
  7583.  
  7584. taskPush(hostElement, pTask, {
  7585. step: 'mightFlushAndWaitContainersRenderFinish',
  7586. selfProducer: this[wk],
  7587. flushing
  7588. });
  7589. loopTask();
  7590.  
  7591. triggerDomChange(container);
  7592. triggerDomChange(hostElement);
  7593.  
  7594. if (e_ && e_.message !== '5ii48') throw e_;
  7595.  
  7596. };
  7597.  
  7598. const stampDomArrayWB_ = function (objWr, containerId, xxx_) {
  7599.  
  7600. const obj = kRef(objWr);
  7601. if (!obj) return;
  7602. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7603. if (xxx !== xxx_) return;
  7604. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7605. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7606. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7607. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7608. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7609. // console.log(12388002, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  7610. return obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7611. };
  7612.  
  7613.  
  7614. stampDomArray_.bind = function (obj, ...args) {
  7615. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7616. // console.log(12388001, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  7617. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7618. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7619. if (!typeOrConfig[wk]) typeOrConfig[wk] = mWeakRef(typeOrConfig);
  7620. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig[wk];
  7621. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7622. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7623. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7624.  
  7625. // if (!obj[`__stampDomArrayBoundFn__#${containerId}__`]) obj[`__stampDomArrayBoundFn__#${containerId}__`] = stampDomArrayWB_.bind(null, obj[wk], containerId);
  7626. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7627. // const p = obj[wk];
  7628. // queueMicrotask_(()=>{
  7629. // const obj = kRef(p);
  7630. // if(!obj) return;
  7631. // if(!obj.hostElement) return;
  7632. // triggerDomChange(obj.hostElement);
  7633. // const container = obj.getStampContainer7409_(containerId);
  7634. // if(container instanceof Node) triggerDomChange(container);
  7635. // });
  7636. // return obj[`__stampDomArrayBoundFn__#${containerId}__`];
  7637.  
  7638. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx);
  7639. };
  7640.  
  7641. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  7642.  
  7643. }
  7644.  
  7645. const setupDiscreteTasks = (h, rb) => {
  7646.  
  7647. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7648. const f = h.onYtRendererstamperFinished;
  7649. const g = ump3.get(f) || function () {
  7650. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7651. return f.apply(this, arguments);
  7652. }
  7653. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7654. }
  7655. ump3.set(f, g);
  7656. g.km34 = 1;
  7657. h.onYtRendererstamperFinished = g;
  7658.  
  7659. }
  7660.  
  7661. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7662. const f = h.onYtUpdateDescriptionAction;
  7663. const g = ump3.get(f) || function (a) {
  7664. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7665. }
  7666. ump3.set(f, g);
  7667. g.km34 = 1;
  7668. h.onYtUpdateDescriptionAction = g;
  7669.  
  7670. }
  7671.  
  7672. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7673. const f = h.handleUpdateDescriptionAction;
  7674. const g = ump3.get(f) || function (a) {
  7675. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7676. }
  7677. ump3.set(f, g);
  7678. g.km34 = 1;
  7679. h.handleUpdateDescriptionAction = g;
  7680.  
  7681. }
  7682.  
  7683. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7684. const f = h.handleUpdateLiveChatPollAction;
  7685. const g = ump3.get(f) || function (a) {
  7686. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7687. }
  7688. ump3.set(f, g);
  7689. g.km34 = 1;
  7690. h.handleUpdateLiveChatPollAction = g;
  7691.  
  7692. }
  7693.  
  7694. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  7695. const f = h.onTextChanged;
  7696. const g = ump3.get(f) || function () {
  7697. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7698. }
  7699. ump3.set(f, g);
  7700. g.km34 = 1;
  7701. h.onTextChanged = g;
  7702.  
  7703. }
  7704.  
  7705. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  7706. const f = h.onVideoDataChange;
  7707. const g = ump3.get(f) || function (a) {
  7708. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7709. }
  7710. ump3.set(f, g);
  7711. g.km34 = 1;
  7712. h.onVideoDataChange = g;
  7713.  
  7714. }
  7715.  
  7716. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  7717. const f = h.onVideoDataChange_;
  7718. const g = ump3.get(f) || function () {
  7719. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7720. }
  7721. ump3.set(f, g);
  7722. g.km34 = 1;
  7723. h.onVideoDataChange_ = g;
  7724.  
  7725. }
  7726.  
  7727. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  7728.  
  7729. const f = h.addTooltips_;
  7730. const g = ump3.get(f) || function () {
  7731. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7732. }
  7733. ump3.set(f, g);
  7734. g.km34 = 1;
  7735. h.addTooltips_ = g;
  7736.  
  7737. }
  7738.  
  7739. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  7740.  
  7741. const f = h.updateRenderedElements;
  7742. const g = ump3.get(f) || function () {
  7743. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7744. }
  7745. ump3.set(f, g);
  7746. g.km34 = 1;
  7747. h.updateRenderedElements = g;
  7748.  
  7749. }
  7750.  
  7751. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  7752. const f = h.loadPage_;
  7753. const g = ump3.get(f) || function (a) {
  7754. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7755. }
  7756. ump3.set(f, g);
  7757. g.km34 = 1;
  7758. h.loadPage_ = g;
  7759.  
  7760. }
  7761. // updatePageData_ : possible conflict with Omit ShadyDOM
  7762. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  7763. const f = h.updatePageData_;
  7764. const g = ump3.get(f) || function (a) {
  7765. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7766. }
  7767. ump3.set(f, g);
  7768. g.km34 = 1;
  7769. h.updatePageData_ = g;
  7770.  
  7771. }
  7772.  
  7773.  
  7774. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  7775.  
  7776. const f = h.onFocus_;
  7777. const g = ump3.get(f) || function () {
  7778. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7779. }
  7780. ump3.set(f, g);
  7781. g.km34 = 1;
  7782. h.onFocus_ = g;
  7783.  
  7784. }
  7785.  
  7786. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  7787.  
  7788. const f = h.onBlur_;
  7789. const g = ump3.get(f) || function () {
  7790. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7791. }
  7792. ump3.set(f, g);
  7793. g.km34 = 1;
  7794. h.onBlur_ = g;
  7795.  
  7796. }
  7797.  
  7798.  
  7799. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  7800.  
  7801. const f = h.buttonClassChanged_;
  7802. const g = ump3.get(f) || function (a, b) {
  7803. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7804. }
  7805. ump3.set(f, g);
  7806. g.km34 = 1;
  7807. h.buttonClassChanged_ = g;
  7808.  
  7809. }
  7810.  
  7811. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  7812.  
  7813. const f = h.buttonIconChanged_;
  7814. const g = ump3.get(f) || function (a) {
  7815. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7816. }
  7817. ump3.set(f, g);
  7818. g.km34 = 1;
  7819. h.buttonIconChanged_ = g;
  7820.  
  7821. }
  7822.  
  7823. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  7824.  
  7825. const f = h.dataChangedInBehavior_;
  7826. const g = ump3.get(f) || function () {
  7827. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7828. }
  7829. ump3.set(f, g);
  7830. g.km34 = 1;
  7831. h.dataChangedInBehavior_ = g;
  7832.  
  7833. }
  7834.  
  7835. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  7836.  
  7837. const f = h.continuationsChanged_;
  7838. const g = ump3.get(f) || function () {
  7839. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7840. }
  7841. ump3.set(f, g);
  7842. g.km34 = 1;
  7843. h.continuationsChanged_ = g;
  7844.  
  7845. }
  7846.  
  7847.  
  7848. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  7849.  
  7850. const f = h.forceChatPoll_;
  7851. const g = ump3.get(f) || function (a) {
  7852. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7853. }
  7854. ump3.set(f, g);
  7855. g.km34 = 1;
  7856. h.forceChatPoll_ = g;
  7857.  
  7858. }
  7859.  
  7860. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  7861.  
  7862. const f = h.onEndpointClick_;
  7863. const g = ump3.get(f) || function (a) {
  7864. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7865. }
  7866. ump3.set(f, g);
  7867. g.km34 = 1;
  7868. h.onEndpointClick_ = g;
  7869.  
  7870. }
  7871.  
  7872. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  7873.  
  7874. const f = h.onEndpointTap_;
  7875. const g = ump3.get(f) || function (a) {
  7876. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7877. }
  7878. ump3.set(f, g);
  7879. g.km34 = 1;
  7880. h.onEndpointTap_ = g;
  7881.  
  7882. }
  7883.  
  7884. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  7885.  
  7886. const f = h.handleClick_;
  7887. const g = ump3.get(f) || function (a, b) {
  7888. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7889. }
  7890. ump3.set(f, g);
  7891. g.km34 = 1;
  7892. h.handleClick_ = g;
  7893.  
  7894. }
  7895.  
  7896. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  7897.  
  7898. const f = h.onReadyStateChange_;
  7899. const g = ump3.get(f) || function () {
  7900. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7901. }
  7902. ump3.set(f, g);
  7903. g.km34 = 1;
  7904. h.onReadyStateChange_ = g;
  7905.  
  7906. }
  7907.  
  7908. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  7909.  
  7910. const f = h.onReadyStateChangeEntryPoint_;
  7911. const g = ump3.get(f) || function () {
  7912. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7913. }
  7914. ump3.set(f, g);
  7915. g.km34 = 1;
  7916. h.onReadyStateChangeEntryPoint_ = g;
  7917.  
  7918. }
  7919.  
  7920. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  7921.  
  7922. const f = h.readyStateChangeHandler_;
  7923. const g = ump3.get(f) || function (a) {
  7924. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7925. }
  7926. ump3.set(f, g);
  7927. g.km34 = 1;
  7928. h.readyStateChangeHandler_ = g;
  7929.  
  7930. }
  7931.  
  7932. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  7933.  
  7934. const f = h.xmlHttpHandler_;
  7935. const g = ump3.get(f) || function (a) {
  7936. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7937. }
  7938. ump3.set(f, g);
  7939. g.km34 = 1;
  7940. h.xmlHttpHandler_ = g;
  7941.  
  7942. }
  7943.  
  7944. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  7945.  
  7946. const f = h.executeCallbacks_; // overloaded
  7947. const g = ump3.get(f) || function (a) {
  7948. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7949. }
  7950. ump3.set(f, g);
  7951. g.km34 = 1;
  7952. h.executeCallbacks_ = g;
  7953.  
  7954. }
  7955.  
  7956. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  7957.  
  7958. const f = h.handleInvalidationData_;
  7959. const g = ump3.get(f) || function (a, b) {
  7960. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7961. }
  7962. ump3.set(f, g);
  7963. g.km34 = 1;
  7964. h.handleInvalidationData_ = g;
  7965.  
  7966. }
  7967.  
  7968. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  7969.  
  7970. const f = h.onInput_;
  7971. const g = ump3.get(f) || function () {
  7972. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7973. }
  7974. ump3.set(f, g);
  7975. g.km34 = 1;
  7976. h.onInput_ = g;
  7977.  
  7978. }
  7979. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  7980.  
  7981. const f = h.trigger_;
  7982. const g = ump3.get(f) || function (a) {
  7983. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7984. }
  7985. ump3.set(f, g);
  7986. g.km34 = 1;
  7987. h.trigger_ = g;
  7988.  
  7989. }
  7990.  
  7991. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  7992.  
  7993. const f = h.requestData_;
  7994. const g = ump3.get(f) || function (a) {
  7995. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7996. }
  7997. ump3.set(f, g);
  7998. g.km34 = 1;
  7999. h.requestData_ = g;
  8000.  
  8001. }
  8002.  
  8003. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  8004.  
  8005. const f = h.onLoadReloadContinuation_;
  8006. const g = ump3.get(f) || function (a, b) {
  8007. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8008. }
  8009. ump3.set(f, g);
  8010. g.km34 = 1;
  8011. h.onLoadReloadContinuation_ = g;
  8012.  
  8013. }
  8014.  
  8015. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  8016.  
  8017. const f = h.onLoadIncrementalContinuation_;
  8018. const g = ump3.get(f) || function (a, b) {
  8019. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8020. }
  8021. ump3.set(f, g);
  8022. g.km34 = 1;
  8023. h.onLoadIncrementalContinuation_ = g;
  8024.  
  8025. }
  8026.  
  8027. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  8028.  
  8029. const f = h.onLoadSeekContinuation_;
  8030. const g = ump3.get(f) || function (a, b) {
  8031. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8032. }
  8033. ump3.set(f, g);
  8034. g.km34 = 1;
  8035. h.onLoadSeekContinuation_ = g;
  8036.  
  8037. }
  8038. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  8039.  
  8040. const f = h.onLoadReplayContinuation_;
  8041. const g = ump3.get(f) || function (a, b) {
  8042. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8043. }
  8044. ump3.set(f, g);
  8045. g.km34 = 1;
  8046. h.onLoadReplayContinuation_ = g;
  8047.  
  8048. }
  8049. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  8050.  
  8051. const f = h.onNavigate_;
  8052. const g = ump3.get(f) || function (a) {
  8053. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8054. }
  8055. ump3.set(f, g);
  8056. g.km34 = 1;
  8057. h.onNavigate_ = g;
  8058.  
  8059. }
  8060.  
  8061. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  8062.  
  8063. const f = h.ytRendererBehaviorDataObserver_;
  8064. const g = ump3.get(f) || function () {
  8065. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8066. }
  8067. ump3.set(f, g);
  8068. g.km34 = 1;
  8069. h.ytRendererBehaviorDataObserver_ = g;
  8070.  
  8071. }
  8072.  
  8073. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  8074.  
  8075. const f = h.ytRendererBehaviorTargetIdObserver_;
  8076. const g = ump3.get(f) || function () {
  8077. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8078. }
  8079. ump3.set(f, g);
  8080. g.km34 = 1;
  8081. h.ytRendererBehaviorTargetIdObserver_ = g;
  8082.  
  8083. }
  8084.  
  8085. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  8086.  
  8087. const f = h.unregisterRenderer_;
  8088. const g = ump3.get(f) || function (a) {
  8089. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8090. }
  8091. ump3.set(f, g);
  8092. g.km34 = 1;
  8093. h.unregisterRenderer_ = g;
  8094.  
  8095. }
  8096.  
  8097. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  8098.  
  8099. const f = h.textChanged_;
  8100. const g = ump3.get(f) || function (a) {
  8101. if (void 0 !== this.isAttached) {
  8102. const hostElement = this.hostElement;
  8103. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  8104. return;
  8105. }
  8106. }
  8107. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8108. }
  8109. ump3.set(f, g);
  8110. g.km34 = 1;
  8111. h.textChanged_ = g;
  8112.  
  8113. }
  8114.  
  8115.  
  8116.  
  8117. /**
  8118. *
  8119. * Neglect following
  8120. *
  8121. * h.onYtAction_
  8122. * h.startLoadingWatch [ buggy for yt-player-updated ]
  8123. * h.deferRenderStamperBinding_
  8124. *
  8125. * h.stampDomArray_
  8126. * h.stampDomArraySplices_
  8127. *
  8128. */
  8129.  
  8130.  
  8131. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  8132. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  8133. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  8134. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  8135. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  8136. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  8137.  
  8138. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  8139.  
  8140. const f = h.searchChanged_;
  8141. const g = ump3.get(f) || function () {
  8142. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8143. }
  8144. ump3.set(f, g);
  8145. g.km34 = 1;
  8146. h.searchChanged_ = g;
  8147.  
  8148. }
  8149.  
  8150. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  8151.  
  8152. const f = h.skinToneChanged_;
  8153. const g = ump3.get(f) || function (a) {
  8154. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8155. }
  8156. ump3.set(f, g);
  8157. g.km34 = 1;
  8158. h.skinToneChanged_ = g;
  8159.  
  8160. }
  8161.  
  8162. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  8163.  
  8164. const f = h.onEmojiHover_;
  8165. const g = ump3.get(f) || function (a) {
  8166. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8167. }
  8168. ump3.set(f, g);
  8169. g.km34 = 1;
  8170. h.onEmojiHover_ = g;
  8171.  
  8172. }
  8173.  
  8174. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  8175.  
  8176. const f = h.onSelectCategory_;
  8177. const g = ump3.get(f) || function (a) {
  8178. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8179. }
  8180. ump3.set(f, g);
  8181. g.km34 = 1;
  8182. h.onSelectCategory_ = g;
  8183.  
  8184. }
  8185.  
  8186. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  8187.  
  8188. const f = h.onShowEmojiVariantSelector;
  8189. const g = ump3.get(f) || function (a) {
  8190. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8191. }
  8192. ump3.set(f, g);
  8193. g.km34 = 1;
  8194. h.onShowEmojiVariantSelector = g;
  8195.  
  8196. }
  8197.  
  8198. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  8199.  
  8200. const f = h.updateCategoriesAndPlaceholder_;
  8201. const g = ump3.get(f) || function () {
  8202. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8203. }
  8204. ump3.set(f, g);
  8205. g.km34 = 1;
  8206. h.updateCategoriesAndPlaceholder_ = g;
  8207.  
  8208. }
  8209.  
  8210. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  8211.  
  8212. const f = h.watchPageActiveChanged_;
  8213. const g = ump3.get(f) || function () {
  8214. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8215. }
  8216. ump3.set(f, g);
  8217. g.km34 = 1;
  8218. h.watchPageActiveChanged_ = g;
  8219.  
  8220. }
  8221.  
  8222. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  8223.  
  8224. const f = h.activate_;
  8225. const g = ump3.get(f) || function () {
  8226. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8227. }
  8228. ump3.set(f, g);
  8229. g.km34 = 1;
  8230. h.activate_ = g;
  8231.  
  8232. }
  8233. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  8234.  
  8235. const f = h.onYtPlaylistDataUpdated_;
  8236. const g = ump3.get(f) || function () {
  8237. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8238. }
  8239. ump3.set(f, g);
  8240. g.km34 = 1;
  8241. h.onYtPlaylistDataUpdated_ = g;
  8242.  
  8243. }
  8244.  
  8245.  
  8246.  
  8247. /**
  8248. *
  8249. * Neglect following
  8250. *
  8251. * h.rendererStamperObserver_
  8252. * h.rendererStamperApplyChangeRecord_
  8253. * h.flushRenderStamperComponentBindings_
  8254. * h.forwardRendererStamperChanges_
  8255. *
  8256. */
  8257.  
  8258. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  8259.  
  8260. const f = h.tryRenderChunk_;
  8261. const g = ump3.get(f) || function () {
  8262. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8263. }
  8264. ump3.set(f, g);
  8265. g.km34 = 1;
  8266. h.tryRenderChunk_ = g;
  8267.  
  8268. }
  8269.  
  8270.  
  8271. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  8272.  
  8273. const f = h.renderChunk_;
  8274. const g = ump3.get(f) || function () {
  8275. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8276. }
  8277. ump3.set(f, g);
  8278. g.km34 = 1;
  8279. h.renderChunk_ = g;
  8280.  
  8281. }
  8282.  
  8283. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  8284.  
  8285. const f = h.deepLazyListObserver_;
  8286. const g = ump3.get(f) || function () {
  8287. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8288. }
  8289. ump3.set(f, g);
  8290. g.km34 = 1;
  8291. h.deepLazyListObserver_ = g;
  8292.  
  8293. }
  8294.  
  8295. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  8296.  
  8297. const f = h.onItemsUpdated_;
  8298. const g = ump3.get(f) || function () {
  8299. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8300. }
  8301. ump3.set(f, g);
  8302. g.km34 = 1;
  8303. h.onItemsUpdated_ = g;
  8304.  
  8305. }
  8306.  
  8307. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  8308.  
  8309. const f = h.requestRenderChunk_;
  8310. const g = ump3.get(f) || function () {
  8311. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  8312. }
  8313. ump3.set(f, g);
  8314. g.km34 = 1;
  8315. h.requestRenderChunk_ = g;
  8316.  
  8317. }
  8318.  
  8319. /**
  8320. *
  8321. * Neglect following
  8322. *
  8323. * h.dataChanged_ [ buggy for page swtiching ]
  8324. *
  8325. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  8326. *
  8327. * h.cancelPendingTasks_
  8328. * h.fillRange_
  8329. * h.addTextNodes_
  8330. * h.updateText_
  8331. * h.stampTypeChanged_
  8332. *
  8333. */
  8334.  
  8335.  
  8336. }
  8337.  
  8338. const keyStConnectedCallback = Symbol(); // avoid copying the value
  8339.  
  8340. const dmf = new WeakMap();
  8341.  
  8342.  
  8343. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  8344.  
  8345. try {
  8346.  
  8347. const q = document.createElement('template');
  8348. q.innerHTML = '<ytz-null361></ytz-null361>';
  8349. nativeHTMLElement = q.content.firstChild.constructor
  8350.  
  8351. } catch (e) { }
  8352.  
  8353. if (!nativeHTMLElement.prototype.connectedCallback) {
  8354. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  8355. nativeHTMLElement.prototype.connectedCallback = function () {
  8356. let r;
  8357. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  8358. return r;
  8359. }
  8360. }
  8361. const pvr = Symbol()
  8362.  
  8363. let stampDomArrayFnStore = null;
  8364. const setupMap = new WeakSet();
  8365. const setupYtComponent = (cnt) => {
  8366. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  8367. if (!cProto || setupMap.has(cProto)) return;
  8368. setupMap.add(cProto);
  8369. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  8370. cProto[pvr] |= 1;
  8371.  
  8372.  
  8373.  
  8374. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  8375. const b = cProto.stampDomArray_.length === 6
  8376. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  8377. && cProto.createComponent_ && cProto.createComponent_.length === 3
  8378. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  8379. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  8380. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  8381. if (!b) {
  8382. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  8383. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  8384. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  8385. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_} = stampDomArrayFnStore;
  8386.  
  8387. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  8388. cProto.createComponent7409_ = cProto.createComponent_;
  8389. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  8390. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  8391. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  8392. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  8393.  
  8394. cProto.getStampContainer_ = getStampContainer_;
  8395. cProto.createComponent_ = createComponent_;
  8396. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  8397. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  8398. cProto.stampDomArray_ = stampDomArray_;
  8399. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  8400.  
  8401. }
  8402. }
  8403.  
  8404.  
  8405.  
  8406.  
  8407. if(cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  8408. cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  8409.  
  8410. if(cProto._runEffectsForTemplate6344.length === 4){
  8411.  
  8412. cProto._runEffectsForTemplate = function (c, d, e, g) {
  8413. const cnt = this;
  8414. const { propertyEffects, nodeList, firstChild } = c;
  8415. cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  8416.  
  8417. }
  8418.  
  8419. }
  8420.  
  8421. }
  8422.  
  8423. }
  8424. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  8425. cProto[pvr] |= 2;
  8426. setupDiscreteTasks(cProto);
  8427. }
  8428. };
  8429.  
  8430. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  8431. get() {
  8432. const f = this[keyStConnectedCallback];
  8433. if (this.is) {
  8434. setupYtComponent(this);
  8435. }
  8436. return f;
  8437. },
  8438. set(nv) {
  8439. let gv = nv;
  8440. this[keyStConnectedCallback] = gv; // proto or object
  8441. return true;
  8442. },
  8443. enumerable: false,
  8444. configurable: true
  8445.  
  8446. });
  8447.  
  8448. const pLoad = new Promise(resolve => {
  8449. if (document.readyState !== 'loading') {
  8450. resolve();
  8451. } else {
  8452. window.addEventListener("DOMContentLoaded", resolve, false);
  8453. }
  8454. });
  8455.  
  8456. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  8457. window.requestIdleCallback471 = window.requestIdleCallback;
  8458. window.requestIdleCallback = function (f, ...args) {
  8459. return (this || window).requestIdleCallback471(async function () {
  8460. await pLoad.then();
  8461. // await new Promise(nextBrowserTick_);
  8462. f.call(this, ...arguments)
  8463. }, ...args);
  8464. }
  8465. }
  8466.  
  8467. pLoad.then(() => {
  8468.  
  8469. let nonce = document.querySelector('style[nonce]');
  8470. nonce = nonce ? nonce.getAttribute('nonce') : null;
  8471. const st = document.createElement('style');
  8472. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  8473. st.textContent = "none-element-k47{order:0}";
  8474. st.addEventListener('load', () => {
  8475. pf31.resolve();
  8476. p59 = 1;
  8477. }, false);
  8478. (document.body || document.head || document.documentElement).appendChild(st);
  8479.  
  8480. });
  8481.  
  8482. const prepareLogs = [];
  8483.  
  8484. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  8485.  
  8486. let winError00 = window.onerror;
  8487.  
  8488. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  8489.  
  8490. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  8491.  
  8492. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  8493.  
  8494. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  8495. const lcOpt = { sensitivity: 'base' };
  8496. document.createElement24 = document.createElement;
  8497. document.createElement = function (t) {
  8498. if (typeof t === 'string' && t.length === 6) {
  8499. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  8500. const p = this.createElement24(t);
  8501. try {
  8502. const stack = new Error().stack;
  8503. const isSearchbox = stack.includes('initializeSearchbox'); // see https://gf.qytechs.cn/scripts/473972-youtube-js-engine-tamer/discussions/217084
  8504. if (!isSearchbox) {
  8505. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  8506. }
  8507. } catch (e) { }
  8508. return p;
  8509. }
  8510. }
  8511. return this.createElement24.apply(this, arguments);
  8512. };
  8513.  
  8514. })();
  8515.  
  8516. ; fix_error_many_stack_state === 1 && (() => {
  8517.  
  8518.  
  8519. let p1 = winError00;
  8520.  
  8521. let stackNeedleDetails = null;
  8522.  
  8523. Object.defineProperty(Object.prototype, 'matchAll', {
  8524. get() {
  8525. stackNeedleDetails = this;
  8526. return true;
  8527. },
  8528. enumerable: true,
  8529. configurable: true
  8530. });
  8531.  
  8532. try {
  8533. JSON.parse("{}");
  8534. } catch (e) {
  8535. console.warn(e)
  8536. fix_error_many_stack_state = 0;
  8537. }
  8538.  
  8539. delete Object.prototype['matchAll'];
  8540.  
  8541. let p2 = window.onerror;
  8542.  
  8543. window.onerror = p1;
  8544.  
  8545. if (fix_error_many_stack_state === 0) return;
  8546.  
  8547. if (stackNeedleDetails) {
  8548. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8549. stackNeedleDetails.matchAll = true;
  8550. }
  8551.  
  8552. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8553.  
  8554. // p1!==p2
  8555. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8556.  
  8557. })();
  8558.  
  8559. ; fix_error_many_stack_state === 2 && (() => {
  8560.  
  8561.  
  8562. let p1 = winError00;
  8563.  
  8564. let objectPrune = null;
  8565. let stackNeedleDetails = null;
  8566.  
  8567. Object.defineProperty(Function.prototype, 'findOwner', {
  8568. get() {
  8569. objectPrune = this;
  8570. return this._findOwner;
  8571. },
  8572. set(nv) {
  8573. this._findOwner = nv;
  8574. return true;
  8575. },
  8576. enumerable: true,
  8577. configurable: true
  8578. });
  8579.  
  8580. Object.defineProperty(Object.prototype, 'matchAll', {
  8581. get() {
  8582. stackNeedleDetails = this;
  8583. return true;
  8584. },
  8585. enumerable: true,
  8586. configurable: true
  8587. });
  8588.  
  8589. try {
  8590. JSON.parse("{}");
  8591. } catch (e) {
  8592. console.warn(e)
  8593. fix_error_many_stack_state = 0;
  8594. }
  8595.  
  8596. delete Function.prototype['findOwner'];
  8597. delete Object.prototype['matchAll'];
  8598.  
  8599. let p2 = window.onerror;
  8600.  
  8601. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8602.  
  8603. if (fix_error_many_stack_state == 0) return;
  8604.  
  8605. // the following will only execute when Brave's scriptlets.js is executed.
  8606.  
  8607. prepareLogs.push("fix_error_many_stack_state NB")
  8608.  
  8609. if (stackNeedleDetails) {
  8610. stackNeedleDetails.pattern = null;
  8611. stackNeedleDetails.re = null;
  8612. stackNeedleDetails.expect = null;
  8613. stackNeedleDetails.matchAll = true;
  8614. }
  8615.  
  8616. if (objectPrune) {
  8617. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8618. delete objectPrune._findOwner;
  8619. }
  8620.  
  8621. fix_error_many_stack_state = 3;
  8622. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8623. JSON.parse.objectPrune = objectPrune;
  8624.  
  8625. })();
  8626.  
  8627. ; fix_error_many_stack_state === 3 && (() => {
  8628.  
  8629.  
  8630. let p1 = winError00;
  8631.  
  8632. try {
  8633. JSON.parse("{}");
  8634. } catch (e) {
  8635. console.warn(e)
  8636. fix_error_many_stack_state = 0;
  8637. }
  8638.  
  8639. let p2 = window.onerror;
  8640.  
  8641. if (p1 === p2) return;
  8642.  
  8643. window.onerror = p1;
  8644.  
  8645. if (fix_error_many_stack_state === 0) return;
  8646.  
  8647. fix_error_many_stack_state = 4; // p1 != p2
  8648.  
  8649.  
  8650. })();
  8651.  
  8652. fix_error_many_stack_state === 4 && (() => {
  8653.  
  8654. // the following will only execute when Brave's scriptlets.js is executed.
  8655.  
  8656. prepareLogs.push("fix_error_many_stack_state AB")
  8657.  
  8658. JSON.parseProxy = JSON.parse;
  8659.  
  8660. JSON.parse = ((parse) => {
  8661.  
  8662. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8663. return function (text, reviver) {
  8664. const onerror = window.onerror;
  8665. window.onerror = null;
  8666. let r;
  8667. try {
  8668. r = parse(...arguments);
  8669. } catch (e) {
  8670. r = e;
  8671. }
  8672. window.onerror = onerror;
  8673. if (r instanceof Error) {
  8674. throw r;
  8675. }
  8676. return r;
  8677. }
  8678.  
  8679. })(JSON.parse);
  8680.  
  8681.  
  8682. })();
  8683.  
  8684.  
  8685. // << if FIX_yt_player >>
  8686.  
  8687. // credit to @nopeless (https://gf.qytechs.cn/scripts/471489-youtube-player-perf/)
  8688. const PERF_471489_ = true;
  8689. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8690. // This script uses a much gentle way to tamer the JS engine instead.
  8691.  
  8692. // << end >>
  8693.  
  8694. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8695.  
  8696.  
  8697.  
  8698. const nilFn = () => { };
  8699.  
  8700. let isMainWindow = false;
  8701. try {
  8702. isMainWindow = window.document === window.top.document
  8703. } catch (e) { }
  8704.  
  8705. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  8706. let headLinkCollection = null;
  8707.  
  8708.  
  8709. // const assertor = (f) => f() || console.assert(false, `${f}`);
  8710.  
  8711. const fnIntegrity = (f, d) => {
  8712. if (!f || typeof f !== 'function') {
  8713. console.warn('f is not a function', f);
  8714. return;
  8715. }
  8716. let p = `${f}`, s = 0, j = -1, w = 0;
  8717. for (let i = 0, l = p.length; i < l; i++) {
  8718. const t = p[i];
  8719. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8720. if (j < i - 1) w++;
  8721. j = i;
  8722. } else {
  8723. s++;
  8724. }
  8725. }
  8726. let itz = `${f.length}.${s}.${w}`;
  8727. if (!d) {
  8728. return itz;
  8729. } else {
  8730. return itz === d;
  8731. }
  8732. };
  8733.  
  8734. const getZqOu = (_yt_player) => {
  8735.  
  8736. const w = 'ZqOu';
  8737.  
  8738. let arr = [];
  8739.  
  8740. for (const [k, v] of Object.entries(_yt_player)) {
  8741.  
  8742. const p = typeof v === 'function' ? v.prototype : 0;
  8743. if (p
  8744. && typeof p.start === 'function' && p.start.length === 0 // Ou
  8745. && typeof p.isActive === 'function' && p.isActive.length === 0
  8746. && typeof p.stop === 'function' && p.stop.length === 0
  8747. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8748. && !p.send && !p.abort
  8749. && !p.sample && !p.initialize && !p.fail && !p.getName
  8750. // && !p.dispose && !p.isDisposed
  8751.  
  8752. ) {
  8753. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8754.  
  8755.  
  8756. }
  8757.  
  8758. }
  8759.  
  8760. if (arr.length === 0) {
  8761.  
  8762. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8763. } else {
  8764.  
  8765. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8766. return arr[0];
  8767. }
  8768.  
  8769. }
  8770.  
  8771. const getZqQu = (_yt_player) => {
  8772.  
  8773. const w = 'ZqQu';
  8774.  
  8775. let arr = [];
  8776.  
  8777.  
  8778. for (const [k, v] of Object.entries(_yt_player)) {
  8779.  
  8780. const p = typeof v === 'function' ? v.prototype : 0;
  8781. if (p
  8782. && typeof p.start === 'function' && p.start.length === 1 // Qu
  8783. && typeof p.isActive === 'function' && p.isActive.length === 0
  8784. && typeof p.stop === 'function' && p.stop.length === 0
  8785. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8786. && !p.send && !p.abort
  8787. && !p.sample && !p.initialize && !p.fail && !p.getName
  8788. // && !p.dispose && !p.isDisposed
  8789.  
  8790. ) {
  8791. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8792.  
  8793.  
  8794. }
  8795.  
  8796. }
  8797.  
  8798. if (arr.length === 0) {
  8799.  
  8800. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8801. } else {
  8802.  
  8803. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8804. return arr[0];
  8805. }
  8806.  
  8807. }
  8808.  
  8809.  
  8810. const getVG = (_yt_player) => {
  8811. const w = 'VG';
  8812.  
  8813. let arr = [];
  8814.  
  8815. for (const [k, v] of Object.entries(_yt_player)) {
  8816.  
  8817. const p = typeof v === 'function' ? v.prototype : 0;
  8818. if (p
  8819. && typeof p.show === 'function' && p.show.length === 1
  8820. && typeof p.hide === 'function' && p.hide.length === 0
  8821. && typeof p.stop === 'function' && p.stop.length === 0) {
  8822.  
  8823. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8824.  
  8825. }
  8826.  
  8827. }
  8828.  
  8829.  
  8830. if (arr.length === 0) {
  8831.  
  8832. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8833. } else {
  8834.  
  8835. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8836. return arr[0];
  8837. }
  8838.  
  8839.  
  8840.  
  8841. }
  8842.  
  8843.  
  8844. const getzo = (_yt_player) => {
  8845. const w = 'zo';
  8846.  
  8847. let arr = [];
  8848.  
  8849. for (const [k, v] of Object.entries(_yt_player)) {
  8850.  
  8851. if (
  8852. typeof v === 'function' && v.length === 3 && k.length < 3
  8853. ) {
  8854. const vt = `${v}`;
  8855. if (vt.length >= 21 && vt.includes(".style[")) {
  8856. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  8857. arr.push(k);
  8858. } else {
  8859. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  8860. }
  8861. }
  8862. }
  8863.  
  8864. }
  8865.  
  8866. if (arr.length === 0) {
  8867.  
  8868. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8869. } else {
  8870.  
  8871. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8872. return arr[0];
  8873. }
  8874.  
  8875. }
  8876.  
  8877. const addProtoToArr = (parent, key, arr) => {
  8878.  
  8879.  
  8880. let isChildProto = false;
  8881. for (const sr of arr) {
  8882. if (parent[key].prototype instanceof parent[sr]) {
  8883. isChildProto = true;
  8884. break;
  8885. }
  8886. }
  8887.  
  8888. if (isChildProto) return;
  8889.  
  8890. arr = arr.filter(sr => {
  8891. if (parent[sr].prototype instanceof parent[key]) {
  8892. return false;
  8893. }
  8894. return true;
  8895. });
  8896.  
  8897. arr.push(key);
  8898.  
  8899. return arr;
  8900.  
  8901.  
  8902. }
  8903.  
  8904. const getuG = (_yt_player) => {
  8905.  
  8906. const w = 'uG';
  8907.  
  8908. let arr = [];
  8909.  
  8910. for (const [k, v] of Object.entries(_yt_player)) {
  8911.  
  8912.  
  8913. const p = typeof v === 'function' ? v.prototype : 0;
  8914.  
  8915. if (p
  8916. && typeof p.createElement === 'function' && p.createElement.length === 2
  8917. && typeof p.detach === 'function' && p.detach.length === 0
  8918. && typeof p.update === 'function' && p.update.length === 1
  8919. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  8920. ) {
  8921.  
  8922. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8923.  
  8924. }
  8925.  
  8926. }
  8927.  
  8928.  
  8929.  
  8930.  
  8931.  
  8932. if (arr.length === 0) {
  8933.  
  8934. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8935. } else {
  8936.  
  8937. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8938. return arr[0];
  8939. }
  8940.  
  8941. }
  8942.  
  8943.  
  8944. const getQT = (_yt_player) => {
  8945. const w = 'QT';
  8946.  
  8947. let arr = [];
  8948. let brr = new Map();
  8949.  
  8950. for (const [k, v] of Object.entries(_yt_player)) {
  8951.  
  8952. const p = typeof v === 'function' ? v.prototype : 0;
  8953. if (p) {
  8954. let q = 0;
  8955. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8956. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8957. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8958.  
  8959. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8960.  
  8961. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8962.  
  8963. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8964. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8965. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8966. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8967.  
  8968.  
  8969. // differentiate QT and DX
  8970.  
  8971. q += 280;
  8972. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  8973. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  8974. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  8975. if (typeof p.seekBy === 'function') q += 4;
  8976. if (typeof p.seekTo === 'function') q += 4;
  8977. if (typeof p.getStoryboardFormat === 'function') q += 4;
  8978. if (typeof p.getDuration === 'function') q += 4;
  8979. if (typeof p.loadModule === 'function') q += 4;
  8980. if (typeof p.unloadModule === 'function') q += 4;
  8981. if (typeof p.getOption === 'function') q += 4;
  8982. if (typeof p.getOptions === 'function') q += 4;
  8983. if (typeof p.setOption === 'function') q += 4;
  8984. if (typeof p.addCueRange === 'function') q += 4;
  8985. if (typeof p.getDebugText === 'function') q += 4;
  8986. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  8987. if (typeof p.setSizeStyle === 'function') q += 4;
  8988. if (typeof p.showControls === 'function') q += 4;
  8989. if (typeof p.hideControls === 'function') q += 4;
  8990. if (typeof p.getVideoContentRect === 'function') q += 4;
  8991. if (typeof p.toggleFullscreen === 'function') q += 4;
  8992. if (typeof p.isFullscreen === 'function') q += 4;
  8993. if (typeof p.cancelPlayback === 'function') q += 4;
  8994. if (typeof p.getProgressState === 'function') q += 4;
  8995. if (typeof p.isInline === 'function') q += 4;
  8996. if (typeof p.setInline === 'function') q += 4;
  8997. if (typeof p.toggleSubtitles === 'function') q += 4;
  8998. if (typeof p.getPlayerSize === 'function') q += 4;
  8999. if (typeof p.wakeUpControls === 'function') q += 4;
  9000. if (typeof p.setCenterCrop === 'function') q += 4;
  9001. if (typeof p.getLoopVideo === 'function') q += 4;
  9002. if (typeof p.setLoopVideo === 'function') q += 4;
  9003.  
  9004.  
  9005. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9006.  
  9007. if (q > 0) brr.set(k, q);
  9008.  
  9009. }
  9010.  
  9011. }
  9012.  
  9013. if (arr.length === 0) {
  9014.  
  9015. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9016. } else {
  9017.  
  9018. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9019.  
  9020. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9021.  
  9022. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9023. return arr[0][0];
  9024. }
  9025.  
  9026.  
  9027.  
  9028. }
  9029.  
  9030.  
  9031.  
  9032. const getSV = (_yt_player) => {
  9033. const w = 'SV';
  9034.  
  9035. let arr = [];
  9036. let brr = new Map();
  9037.  
  9038. for (const [k, v] of Object.entries(_yt_player)) {
  9039.  
  9040. const p = typeof v === 'function' ? v.prototype : 0;
  9041. if (p) {
  9042. let q = 0;
  9043. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9044. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9045. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9046.  
  9047. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  9048.  
  9049. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9050.  
  9051. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9052. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9053. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9054. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9055.  
  9056.  
  9057. // differentiate QT and DX
  9058.  
  9059.  
  9060. q += 280;
  9061.  
  9062. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9063. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9064. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9065. if (typeof p.seekBy === 'function') q -= 4;
  9066. if (typeof p.seekTo === 'function') q -= 4;
  9067. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9068. if (typeof p.getDuration === 'function') q -= 4;
  9069. if (typeof p.loadModule === 'function') q -= 4;
  9070. if (typeof p.unloadModule === 'function') q -= 4;
  9071. if (typeof p.getOption === 'function') q -= 4;
  9072. if (typeof p.getOptions === 'function') q -= 4;
  9073. if (typeof p.setOption === 'function') q -= 4;
  9074. if (typeof p.addCueRange === 'function') q -= 4;
  9075. if (typeof p.getDebugText === 'function') q -= 4;
  9076. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9077. if (typeof p.setSizeStyle === 'function') q -= 4;
  9078. if (typeof p.showControls === 'function') q -= 4;
  9079. if (typeof p.hideControls === 'function') q -= 4;
  9080. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9081. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9082. if (typeof p.isFullscreen === 'function') q -= 4;
  9083. if (typeof p.cancelPlayback === 'function') q -= 4;
  9084. if (typeof p.getProgressState === 'function') q -= 4;
  9085. if (typeof p.isInline === 'function') q -= 4;
  9086. if (typeof p.setInline === 'function') q -= 4;
  9087. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9088. if (typeof p.getPlayerSize === 'function') q -= 4;
  9089. if (typeof p.wakeUpControls === 'function') q -= 4;
  9090. if (typeof p.setCenterCrop === 'function') q -= 4;
  9091. if (typeof p.getLoopVideo === 'function') q -= 4;
  9092. if (typeof p.setLoopVideo === 'function') q -= 4;
  9093.  
  9094.  
  9095. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9096.  
  9097. if (q > 0) brr.set(k, q);
  9098.  
  9099. }
  9100.  
  9101. }
  9102.  
  9103. if (arr.length === 0) {
  9104.  
  9105. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9106. } else {
  9107.  
  9108. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9109.  
  9110. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9111.  
  9112. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9113. return arr[0][0];
  9114. }
  9115.  
  9116.  
  9117.  
  9118. }
  9119.  
  9120.  
  9121.  
  9122.  
  9123. const getDX = (_yt_player) => {
  9124. const w = 'DX';
  9125.  
  9126. let arr = [];
  9127. let brr = new Map();
  9128.  
  9129. for (const [k, v] of Object.entries(_yt_player)) {
  9130.  
  9131. const p = typeof v === 'function' ? v.prototype : 0;
  9132. if (p) {
  9133. let q = 0;
  9134. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  9135. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  9136. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  9137.  
  9138. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  9139.  
  9140.  
  9141. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  9142.  
  9143. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  9144.  
  9145. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  9146. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  9147. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  9148. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  9149.  
  9150.  
  9151. // differentiate QT and DX
  9152.  
  9153.  
  9154. q += 280;
  9155.  
  9156. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  9157. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  9158. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  9159. if (typeof p.seekBy === 'function') q -= 4;
  9160. if (typeof p.seekTo === 'function') q -= 4;
  9161. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  9162. if (typeof p.getDuration === 'function') q -= 4;
  9163. if (typeof p.loadModule === 'function') q -= 4;
  9164. if (typeof p.unloadModule === 'function') q -= 4;
  9165. if (typeof p.getOption === 'function') q -= 4;
  9166. if (typeof p.getOptions === 'function') q -= 4;
  9167. if (typeof p.setOption === 'function') q -= 4;
  9168. if (typeof p.addCueRange === 'function') q -= 4;
  9169. if (typeof p.getDebugText === 'function') q -= 4;
  9170. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  9171. if (typeof p.setSizeStyle === 'function') q -= 4;
  9172. if (typeof p.showControls === 'function') q -= 4;
  9173. if (typeof p.hideControls === 'function') q -= 4;
  9174. if (typeof p.getVideoContentRect === 'function') q -= 4;
  9175. if (typeof p.toggleFullscreen === 'function') q -= 4;
  9176. if (typeof p.isFullscreen === 'function') q -= 4;
  9177. if (typeof p.cancelPlayback === 'function') q -= 4;
  9178. if (typeof p.getProgressState === 'function') q -= 4;
  9179. if (typeof p.isInline === 'function') q -= 4;
  9180. if (typeof p.setInline === 'function') q -= 4;
  9181. if (typeof p.toggleSubtitles === 'function') q -= 4;
  9182. if (typeof p.getPlayerSize === 'function') q -= 4;
  9183. if (typeof p.wakeUpControls === 'function') q -= 4;
  9184. if (typeof p.setCenterCrop === 'function') q -= 4;
  9185. if (typeof p.getLoopVideo === 'function') q -= 4;
  9186. if (typeof p.setLoopVideo === 'function') q -= 4;
  9187.  
  9188.  
  9189. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  9190.  
  9191. if (q > 0) brr.set(k, q);
  9192.  
  9193. }
  9194.  
  9195. }
  9196.  
  9197. if (arr.length === 0) {
  9198.  
  9199. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  9200. } else {
  9201.  
  9202. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  9203.  
  9204. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  9205.  
  9206. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  9207. return arr[0][0];
  9208. }
  9209.  
  9210.  
  9211.  
  9212. }
  9213.  
  9214.  
  9215.  
  9216. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  9217.  
  9218. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  9219. let pageSetupState = 0;
  9220.  
  9221. isPrepareCachedV && (() => {
  9222.  
  9223. pageSetupVideoId = '';
  9224. const clearCachedV = () => {
  9225. pageSetupVideoId = '';
  9226. pageSetupState = 0;
  9227. }
  9228. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  9229. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  9230. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  9231. document.addEventListener('yt-navigate-finish', () => {
  9232. pageSetupState = 1;
  9233. try {
  9234. const url = new URL(location.href);
  9235. if (!url || !isWatchPageURL(url)) {
  9236. pageSetupVideoId = '';
  9237. } else {
  9238. pageSetupVideoId = url.searchParams.get('v') || '';
  9239. }
  9240. } catch (e) {
  9241. pageSetupVideoId = '';
  9242. }
  9243. }, false);
  9244.  
  9245. })();
  9246.  
  9247. let videoPlayingY = null;
  9248.  
  9249. isPrepareCachedV && (() => {
  9250.  
  9251. let getNext = true;
  9252. let videoPlayingX = {
  9253. get videoId() {
  9254. if (getNext) {
  9255. getNext = false;
  9256.  
  9257. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  9258. const arr = [];
  9259. for (const element of elements) {
  9260. if (!element.closest('[hidden]')) arr.push(element);
  9261. }
  9262. if (arr.length !== 1) this.__videoId__ = '';
  9263. else {
  9264. this.__videoId__ = arr[0].getAttribute('video-id');
  9265. }
  9266.  
  9267. }
  9268. return this.__videoId__ || '';
  9269. }
  9270. }
  9271.  
  9272. videoPlayingY = videoPlayingX;
  9273. const handler = (evt) => {
  9274. const target = (evt || 0).target;
  9275. if (target instanceof HTMLVideoElement) {
  9276. getNext = true;
  9277. }
  9278. }
  9279. document.addEventListener('loadedmetadata', handler, true);
  9280. document.addEventListener('durationchange', handler, true);
  9281.  
  9282. })();
  9283.  
  9284.  
  9285.  
  9286. const cleanContext = async (win) => {
  9287. const waitFn = requestAnimationFrame; // shall have been binded to window
  9288. try {
  9289. let mx = 16; // MAX TRIAL
  9290. const frameId = 'vanillajs-iframe-v1';
  9291. /** @type {HTMLIFrameElement | null} */
  9292. let frame = document.getElementById(frameId);
  9293. let removeIframeFn = null;
  9294. if (!frame) {
  9295. frame = document.createElement('iframe');
  9296. frame.id = frameId;
  9297. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  9298. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  9299. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  9300. n.appendChild(frame);
  9301. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  9302. const root = document.documentElement;
  9303. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  9304. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  9305.  
  9306. removeIframeFn = (setTimeout) => {
  9307. const removeIframeOnDocumentReady = (e) => {
  9308. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9309. e = n;
  9310. n = win = removeIframeFn = 0;
  9311. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  9312. }
  9313. if (!setTimeout || document.readyState !== 'loading') {
  9314. removeIframeOnDocumentReady();
  9315. } else {
  9316. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  9317. }
  9318. }
  9319. }
  9320. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  9321. const fc = frame.contentWindow;
  9322. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  9323. try {
  9324. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  9325. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  9326. for (let k in res) res[k] = res[k].bind(win); // necessary
  9327. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  9328. res.animate = fc.HTMLElement.prototype.animate;
  9329. res.perfNow = fc.performance.now;
  9330. return res;
  9331. } catch (e) {
  9332. if (removeIframeFn) removeIframeFn();
  9333. return null;
  9334. }
  9335. } catch (e) {
  9336. console.warn(e);
  9337. return null;
  9338. }
  9339. };
  9340.  
  9341. const promiseForYtActionCalled = new Promise(resolve => {
  9342.  
  9343. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9344. if (typeof AbortSignal !== 'undefined') {
  9345. let hn = () => {
  9346. if (!hn) return;
  9347. hn = null;
  9348. resolve(document.querySelector(appTag));
  9349. };
  9350. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  9351. } else {
  9352. let hn = () => {
  9353. if (!hn) return;
  9354. document.removeEventListener('yt-action', hn, true);
  9355. hn = null;
  9356. resolve(document.querySelector(appTag));
  9357. };
  9358. document.addEventListener('yt-action', hn, true);
  9359. }
  9360. });
  9361.  
  9362. cleanContext(window).then(__CONTEXT__ => {
  9363. if (!__CONTEXT__) return null;
  9364.  
  9365. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  9366.  
  9367.  
  9368. performance.now17 = perfNow.bind(performance);
  9369.  
  9370.  
  9371.  
  9372. __requestAnimationFrame__ = requestAnimationFrame;
  9373.  
  9374.  
  9375. const isGPUAccelerationAvailable = (() => {
  9376. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  9377. try {
  9378. const canvas = document.createElement('canvas');
  9379. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  9380. } catch (e) {
  9381. return false;
  9382. }
  9383. })();
  9384.  
  9385. const foregroundPromiseFn_noGPU = (() => {
  9386.  
  9387. if (isGPUAccelerationAvailable) return null;
  9388.  
  9389. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  9390. if (!pd || typeof pd.get !== 'function') return null;
  9391. const pdGet = pd.get;
  9392.  
  9393. let pr = null;
  9394.  
  9395. let hState = pdGet.call(document) === 'hidden';
  9396. // let cid = 0;
  9397. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  9398. const newHState = pdGet.call(document) === 'hidden';
  9399. if (hState !== newHState) {
  9400. // if (cid > 0) cid = clearInterval(cid);
  9401. hState = newHState;
  9402. if (!hState && pr) pr = pr.resolve();
  9403. }
  9404. });
  9405.  
  9406. // cid = setInterval(() => {
  9407. // const newHState = document.visibilityState === 'hidden';
  9408. // if (hState !== newHState) {
  9409. // hState = newHState;
  9410. // if (!hState && pr) pr = pr.resolve();
  9411. // }
  9412. // }, 100);
  9413.  
  9414.  
  9415. return (() => {
  9416. if (pr) return pr;
  9417. const w = ((!hState && setTimeout(() => {
  9418. if (!hState && pr === w) pr = pr.resolve();
  9419. })), (pr = new PromiseExternal()));
  9420. return w;
  9421. });
  9422.  
  9423. })();
  9424.  
  9425.  
  9426. let rafPromise = null;
  9427. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  9428. requestAnimationFrame(hRes => {
  9429. rafPromise = null;
  9430. resolve(hRes);
  9431. });
  9432. }));
  9433.  
  9434. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  9435.  
  9436.  
  9437. const wmComputedStyle = new WeakMap();
  9438.  
  9439. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  9440. window.__native__getComputedStyle__ = getComputedStyle;
  9441. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  9442. window.__original__getComputedStyle__ = window.getComputedStyle;
  9443. window.getComputedStyle = function (elem) {
  9444. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  9445. return window.__original__getComputedStyle__(...arguments);
  9446. }
  9447. let cs = wmComputedStyle.get(elem);
  9448. if (!cs) {
  9449. cs = window.__native__getComputedStyle__(elem);
  9450. wmComputedStyle.set(elem, cs);
  9451. }
  9452. return cs;
  9453. };
  9454. } else {
  9455. window.__original__getComputedStyle__ = null;
  9456. }
  9457. window.__jst__getComputedStyle__ = window.getComputedStyle;
  9458. }
  9459.  
  9460. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  9461. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  9462. window.getComputedStyle = window.__jst__getComputedStyle__;
  9463. }
  9464. });
  9465.  
  9466. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  9467. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  9468.  
  9469. const promiseForTamerTimeout = new Promise(resolve => {
  9470. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9471. setTimeout(resolve, 480);
  9472. }, { capture: true, passive: true, once: true });
  9473. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9474. setTimeout(resolve, 1200);
  9475. });
  9476. setTimeout(resolve, 3000);
  9477. });
  9478.  
  9479. const promiseForPageInitied = new Promise(resolve => {
  9480. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9481. setTimeout(resolve, 450);
  9482. }, { capture: true, passive: true, once: true });
  9483. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9484. setTimeout(resolve, 900);
  9485. });
  9486. setTimeout(resolve, 1800);
  9487. });
  9488.  
  9489. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  9490. NO_PRELOAD_GENERATE_204_BYPASS = true;
  9491. headLinkCollection = null;
  9492. });
  9493.  
  9494.  
  9495. NATIVE_CANVAS_ANIMATION && (() => {
  9496.  
  9497. observablePromise(() => {
  9498. HTMLCanvasElement.prototype.animate = animate;
  9499. }, promiseForTamerTimeout).obtain();
  9500.  
  9501. })();
  9502.  
  9503.  
  9504.  
  9505.  
  9506. FIX_ytAction_ && (async () => {
  9507.  
  9508. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9509.  
  9510. const ytdApp = await new Promise(resolve => {
  9511.  
  9512. whenCEDefined(appTag).then(() => {
  9513. const ytdApp = document.querySelector(appTag);
  9514. if (ytdApp) {
  9515. resolve(ytdApp);
  9516. return;
  9517. }
  9518. let mo = new MutationObserver(() => {
  9519. const ytdApp = document.querySelector(appTag);
  9520. if (!ytdApp) return;
  9521. if (mo) {
  9522. mo.disconnect();
  9523. mo.takeRecords();
  9524. mo = null;
  9525. }
  9526. resolve(ytdApp);
  9527. });
  9528. mo.observe(document, { subtree: true, childList: true });
  9529. });
  9530.  
  9531. });
  9532.  
  9533. if (!ytdApp) return;
  9534. const cProto = insp(ytdApp).constructor.prototype;
  9535.  
  9536. if (!cProto) return;
  9537. let mbd = 0;
  9538.  
  9539. const fixer = (_ytdApp) => {
  9540. const ytdApp = insp(_ytdApp);
  9541. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9542. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9543. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9544. mbd++;
  9545. }
  9546. }
  9547.  
  9548. observablePromise(() => {
  9549.  
  9550. if (typeof cProto.created === 'function' && !cProto.created56) {
  9551. cProto.created56 = cProto.created;
  9552. cProto.created = function (...args) {
  9553. const r = this.created56(...args);
  9554. fixer(this);
  9555. return r;
  9556. };
  9557. mbd++;
  9558. }
  9559.  
  9560. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9561. cProto.onYtAction57_ = cProto.onYtAction_;
  9562. cProto.onYtAction_ = function (...args) {
  9563. Promise.resolve().then(() => this.onYtAction57_(...args));
  9564. };
  9565. mbd++;
  9566. }
  9567.  
  9568. if (ytdApp) fixer(ytdApp);
  9569.  
  9570. /*
  9571. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9572. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9573. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9574. actionRouter_.handleAction = function (...args) {
  9575. Promise.resolve().then(() => this.handleAction57(...args));
  9576. }
  9577. mbd++;
  9578. }
  9579. */
  9580.  
  9581. // if(mbd === 3) return 1;
  9582. if (mbd >= 3) return 1;
  9583.  
  9584. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9585.  
  9586. })();
  9587.  
  9588.  
  9589. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9590.  
  9591. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9592.  
  9593. const app = await observablePromise(() => {
  9594.  
  9595. return document.querySelector(appTag);
  9596.  
  9597. }).obtain();
  9598.  
  9599. if (!app) return;
  9600.  
  9601. const appCnt = insp(app);
  9602. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9603.  
  9604.  
  9605.  
  9606.  
  9607. });
  9608.  
  9609.  
  9610. // let _yt_player_promise = null;
  9611. /*
  9612. const getYtPlayerPromise = () => {
  9613. if (!_yt_player_promise) {
  9614. _yt_player_promise = new Promise(resolve => {
  9615. let cid = setInterval(() => {
  9616. let t = (((window || 0)._yt_player || 0) || 0);
  9617. if (t) {
  9618. clearInterval(cid);
  9619. resolve(t);
  9620. }
  9621. }, 1);
  9622. promiseForTamerTimeout.then(() => {
  9623. resolve(null)
  9624. });
  9625. });
  9626. }
  9627. return _yt_player_promise;
  9628. }
  9629. */
  9630. const _yt_player_observable = observablePromise(() => {
  9631. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9632. if (_yt_player) {
  9633. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9634. return _yt_player;
  9635. }
  9636. }, promiseForTamerTimeout);
  9637.  
  9638. const polymerObservable = observablePromise(() => {
  9639. const Polymer = window.Polymer;
  9640. if (typeof Polymer !== 'function') return;
  9641. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9642. return Polymer;
  9643. }, promiseForTamerTimeout);
  9644.  
  9645. const schedulerInstanceObservable = observablePromise(() => {
  9646. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9647. }, promiseForTamerTimeout);
  9648.  
  9649. const timelineObservable = observablePromise(() => {
  9650. let t = (((document || 0).timeline || 0) || 0);
  9651. if (t && typeof t._play === 'function') {
  9652. return t;
  9653. }
  9654. }, promiseForTamerTimeout);
  9655. const animationObservable = observablePromise(() => {
  9656. let t = (((window || 0).Animation || 0) || 0);
  9657. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9658. return t;
  9659. }
  9660. }, promiseForTamerTimeout);
  9661.  
  9662.  
  9663. const getScreenInfo = {
  9664. screenWidth: 0,
  9665. screenHeight: 0,
  9666. valueReady: false,
  9667. onResize: () => {
  9668. getScreenInfo.valueReady = false;
  9669. },
  9670. sizeProvided: () => {
  9671. if (getScreenInfo.valueReady) return true;
  9672. getScreenInfo.screenWidth = screen.width;
  9673. getScreenInfo.screenHeight = screen.height;
  9674. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9675. getScreenInfo.valueReady = true;
  9676. return true;
  9677. }
  9678. return false;
  9679. }
  9680. };
  9681.  
  9682. window.addEventListener('resize', getScreenInfo.onResize, true);
  9683.  
  9684.  
  9685. // const hookLeftPending = new WeakMap();
  9686.  
  9687. const isNaNx = Number.isNaN;
  9688.  
  9689. const hookLeftPD = {
  9690. get() {
  9691. const p = 'left';
  9692. // const o = hookLeftPending.get(this);
  9693. // if (o && o.key) {
  9694. // this.setProperty(p, o.value);
  9695. // o.key = null
  9696. // }
  9697. return this.getPropertyValue(p);
  9698. },
  9699. set(v) {
  9700.  
  9701. const p = 'left';
  9702. const cv = this.getPropertyValue(p);
  9703. const sv = v;
  9704.  
  9705. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  9706.  
  9707. // console.log(8380,did, cv, sv)
  9708. if (!cv && !sv) return true;
  9709. if (cv === sv) return true;
  9710.  
  9711. // skip 0~9px => L>=4
  9712.  
  9713. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  9714.  
  9715. if (!isNaNx(qsv)) {
  9716. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  9717.  
  9718. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  9719. const { screenWidth, screenHeight } = getScreenInfo;
  9720. let pWidth = screenWidth + 1024;
  9721. let pHeight = screenHeight + 768;
  9722. const minRatio = 0.003;
  9723. const dw = pWidth * 0.0003; // min dw = 0.3072
  9724. const dh = pHeight * 0.0003; // min dh = 0.2304
  9725. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  9726. if (Math.abs(qcv - qsv) < dw) return true;
  9727. }
  9728.  
  9729. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  9730. if (`${v}`.length > `${sv}`.length) v = sv;
  9731. // console.log(8382, did, sv, nv, cv, this)
  9732. }
  9733.  
  9734. // Promise.resolve().then(() => {
  9735. // const o = hookLeftPending.get(this);
  9736. // if (o && o.key === did) {
  9737. // this.setProperty(p, o.value);
  9738. // o.key = null;
  9739. // }
  9740. // });
  9741. // hookLeftPending.set(this, {
  9742. // key: did,
  9743. // value: nv
  9744. // });
  9745.  
  9746. // if (nv != v) {
  9747. // console.log(8387, v, nv);
  9748. // }
  9749.  
  9750. this.setProperty(p, v);
  9751. // console.log(8383, did, this.getPropertyValue(p))
  9752. return true;
  9753. },
  9754. enumerable: true,
  9755. configurable: true
  9756. };
  9757.  
  9758.  
  9759. if (HOOK_CSSPD_LEFT) {
  9760.  
  9761.  
  9762. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  9763.  
  9764. }
  9765.  
  9766.  
  9767.  
  9768.  
  9769.  
  9770. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  9771.  
  9772. const evKey = `${_evKey}`;
  9773. const fvKey = `${_fvKey}`;
  9774. const debug = !!_debug;
  9775.  
  9776. const _yt_player = await _yt_player_observable.obtain();
  9777.  
  9778.  
  9779. if (!_yt_player || typeof _yt_player !== 'object') return;
  9780.  
  9781.  
  9782. const getArr = (_yt_player) => {
  9783.  
  9784. let arr = [];
  9785.  
  9786. for (const [k, v] of Object.entries(_yt_player)) {
  9787.  
  9788. const p = typeof v === 'function' ? v.prototype : 0;
  9789. if (p
  9790. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  9791.  
  9792. ) {
  9793. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9794.  
  9795. }
  9796.  
  9797. }
  9798.  
  9799. if (arr.length === 0) {
  9800.  
  9801. console.warn(`Key prop [${evKey}] does not exist.`);
  9802. } else {
  9803.  
  9804. return arr;
  9805. }
  9806.  
  9807. };
  9808.  
  9809. const arr = getArr(_yt_player);
  9810.  
  9811.  
  9812. if (!arr) return;
  9813.  
  9814. debug && console.log(`FIX_${evKey}`, arr);
  9815.  
  9816. const f = function (...args) {
  9817. Promise.resolve().then(() => this[fvKey](...args));
  9818. };
  9819.  
  9820.  
  9821. for (const k of arr) {
  9822.  
  9823. const g = _yt_player;
  9824. const gk = g[k];
  9825. const gkp = gk.prototype;
  9826.  
  9827. debug && console.log(237, k, gkp)
  9828.  
  9829. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  9830. gkp[fvKey] = gkp[evKey];
  9831. gkp[evKey] = f;
  9832. }
  9833. }
  9834.  
  9835.  
  9836.  
  9837.  
  9838. }
  9839.  
  9840. if (!isChatRoomURL) {
  9841.  
  9842. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  9843. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  9844. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  9845. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  9846. if (FIX_VideoEVENTS_v2) {
  9847. const FIX_VideoEVENTS_DEBUG = 0;
  9848. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  9849. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  9850. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  9851. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  9852. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  9853. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  9854. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  9855. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  9856. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  9857.  
  9858. }
  9859. // onMutedAutoplayChange
  9860. // onVolumeChange
  9861. // onPlaybackRateChange
  9862.  
  9863. // onAirPlayActiveChange
  9864. // onAirPlayAvailabilityChange
  9865. // onApiChange
  9866. // onAutoplayBlocked
  9867. // onDrmOutputRestricted
  9868. // onFullscreenChange
  9869. // onLoadProgress
  9870. // onLoadedMetadata
  9871. // onVideoDataChange
  9872. // onVideoProgress
  9873.  
  9874. }
  9875.  
  9876.  
  9877. let isAmended_Polymer_RenderStatus = false;
  9878.  
  9879. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  9880.  
  9881. const Polymer = await polymerObservable.obtain();
  9882. if (!Polymer) return;
  9883.  
  9884. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  9885. isAmended_Polymer_RenderStatus = true;
  9886.  
  9887. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  9888. let arrBefore = null, arrAfter = null;
  9889. const push = Array.prototype.push;
  9890. let arr = null;
  9891. Array.prototype.push = function () {
  9892. arr = this;
  9893. }
  9894. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  9895. if (arr) arrBefore = arr;
  9896. arr = null;
  9897. Polymer.RenderStatus.afterNextRender({}, {}, {});
  9898. if (arr) arrAfter = arr;
  9899. arr = null;
  9900. Array.prototype.push = push;
  9901. Polymer.RenderStatus.arrBefore = arrBefore;
  9902. Polymer.RenderStatus.arrAfter = arrAfter;
  9903.  
  9904. if (arrBefore && arrAfter) {
  9905.  
  9906. Function.prototype.call7900 = Function.prototype.call;
  9907. Function.prototype.apply7900 = Function.prototype.apply;
  9908. Function.prototype.apply7948 = function (obj, args) {
  9909. const f = this;
  9910. let m = kRef(obj);
  9911. if (!m) return;
  9912. if (m.is && !m.nodeName) {
  9913. if (!m.isAttached || !m.hostElement) {
  9914. return;
  9915. }
  9916. }
  9917. try {
  9918. return !args ? f.call7900(m) : f.apply7900(m, args);
  9919. } catch (e) {
  9920. console.warn(e);
  9921. }
  9922. return null;
  9923. }
  9924.  
  9925. arrBefore.push = arrAfter.push = function (a) {
  9926. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  9927. if (a[0].deref) a[0] = kRef(a[0]);
  9928. const f = a[1]
  9929. const obj = a[0]
  9930. const args = a[2];
  9931. f.apply = f.apply7948;
  9932. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  9933. a[0] = obj[wk]
  9934. // console.log(4992, a)
  9935. return push.call(this, a);
  9936. }
  9937.  
  9938. }
  9939.  
  9940.  
  9941. }
  9942. // Polymer.RenderStatus.beforeNextRender
  9943. }
  9944.  
  9945. if (FIX_Polymer_dom) {
  9946.  
  9947. const checkPDFuncValue = (pd) => {
  9948. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  9949. }
  9950. const checkPDFuncValue2 = (pd) => {
  9951. return pd && typeof pd.value == 'function'
  9952. }
  9953.  
  9954. const checkPDFuncGet = (pd) => {
  9955. return pd && typeof pd.get == 'function'
  9956. }
  9957.  
  9958. const domX = Polymer.dom(document.createElement('null'));
  9959. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  9960. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  9961. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  9962. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  9963. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  9964. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  9965. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  9966. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  9967. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  9968.  
  9969.  
  9970. // getOwnerRoot - to be reviewed
  9971. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  9972.  
  9973. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  9974. domXP.getOwnerRoot = function () {
  9975. try {
  9976. const p = this.node;
  9977.  
  9978. if (p instanceof HTMLElement_) {
  9979. const pp = pd2.get.call(p);
  9980. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  9981. return pp.getRootNode();
  9982. }
  9983.  
  9984. }
  9985. } catch (e) { }
  9986. return this.getOwnerRoot15();
  9987. }
  9988.  
  9989. Polymer.__fixedGetOwnerRoot__ = 1;
  9990. }
  9991.  
  9992.  
  9993.  
  9994.  
  9995. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  9996.  
  9997. domXP.querySelector15 = domXP.querySelector;
  9998.  
  9999. const querySelectorFn = function (query) {
  10000. try {
  10001. const p = this.node;
  10002.  
  10003. if (p instanceof Document && p.isConnected === true) {
  10004. return pd4b.value.call(p, query);
  10005. }
  10006.  
  10007. } catch (e) { }
  10008. return this.querySelector15(query);
  10009. }
  10010.  
  10011. Object.defineProperty(domXP, 'querySelector', {
  10012. get() {
  10013. return querySelectorFn;
  10014. },
  10015. set(nv) {
  10016. if (nv === querySelectorFn) return true;
  10017. this.querySelector15 = nv;
  10018. return true;
  10019. },
  10020.  
  10021. enumerable: false,
  10022. configurable: true
  10023. });
  10024.  
  10025. Polymer.__fixedQuerySelector__ = 1;
  10026. }
  10027.  
  10028. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  10029.  
  10030. domXP.querySelectorAll15 = domXP.querySelectorAll;
  10031.  
  10032. const querySelectorAllFn = function (query) {
  10033.  
  10034. try {
  10035.  
  10036. const p = this.node;
  10037.  
  10038. if (p instanceof Document && p.isConnected === true) {
  10039. return pd6b.value.call(p, query);
  10040. }
  10041.  
  10042. } catch (e) {
  10043.  
  10044. }
  10045. return this.querySelectorAll15(query);
  10046. }
  10047.  
  10048. Object.defineProperty(domXP, 'querySelectorAll', {
  10049. get() {
  10050. return querySelectorAllFn;
  10051. },
  10052. set(nv) {
  10053. if (nv === querySelectorAllFn) return true;
  10054. this.querySelectorAll15 = nv;
  10055. return true;
  10056. },
  10057.  
  10058. enumerable: false,
  10059. configurable: true
  10060. });
  10061.  
  10062. Polymer.__fixedQuerySelectorAll__ = 1;
  10063. }
  10064. }
  10065.  
  10066.  
  10067. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  10068.  
  10069. Polymer.Base.__connInit__ = function () {
  10070. setupYtComponent(this);
  10071. }
  10072.  
  10073.  
  10074. /** @type {Function} */
  10075. const connectedCallbackK = function (...args) {
  10076. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10077. const r = this[qm53](...args);
  10078. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10079. this.mh35 = 1;
  10080. return r;
  10081. };
  10082.  
  10083. connectedCallbackK.m353 = 1;
  10084.  
  10085.  
  10086. const qt53 = Polymer.Base.connectedCallback;
  10087. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  10088.  
  10089. Polymer.Base.connectedCallback = connectedCallbackK;
  10090.  
  10091.  
  10092. /** @type {Function} */
  10093. const createdK = function (...args) {
  10094. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10095. const r = this[qn53](...args);
  10096. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  10097. this.mh36 = 1;
  10098. return r;
  10099. };
  10100.  
  10101.  
  10102. createdK.m353 = 1;
  10103. Polymer.Base[qn53] = Polymer.Base.created;
  10104. Polymer.Base.created = createdK;
  10105.  
  10106.  
  10107.  
  10108.  
  10109.  
  10110.  
  10111.  
  10112.  
  10113.  
  10114.  
  10115.  
  10116. }
  10117.  
  10118. })();
  10119.  
  10120.  
  10121. /*
  10122.  
  10123. e.nativeAppendChild = d.prototype.appendChild,
  10124. d.prototype.appendChild = function(h) {
  10125. return function(l) {
  10126. if (l instanceof DocumentFragment) {
  10127. var m = Array.from(l.children);
  10128. l = h.nativeAppendChild.call(this, l);
  10129. if (this.isConnected) {
  10130. m = g(m);
  10131. for (var p = m.next(); !p.done; p = m.next())
  10132. YD(p.value)
  10133. }
  10134. return l
  10135. }
  10136. m = l instanceof Element && l.isConnected;
  10137. p = h.nativeAppendChild.call(this, l);
  10138. m && ZD(l);
  10139. this.isConnected && YD(l);
  10140. return p
  10141. }
  10142. }(e),
  10143.  
  10144. */
  10145.  
  10146. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  10147.  
  10148. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  10149. if (f) Node.prototype.appendChild = function (a) {
  10150. if (this instanceof Element) { // exclude DocumentFragment
  10151. try {
  10152. let checkFragmentA = (a instanceof DocumentFragment);
  10153. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  10154. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  10155. for (const node of headLinkCollection) {
  10156. if (node.rel === 'preload' && node.as === 'fetch') {
  10157. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  10158. }
  10159. }
  10160. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  10161. checkFragmentA = false;
  10162. }
  10163. if (checkFragmentA && a.firstElementChild === null) {
  10164. // no element in fragmentA
  10165. let doNormal = false;
  10166. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  10167. if (child.nodeType === 3) { doNormal = true; break; }
  10168. }
  10169. if (!doNormal) return a;
  10170. }
  10171. } catch (e) {
  10172. console.log(e);
  10173. }
  10174. }
  10175. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  10176. }
  10177.  
  10178. })();
  10179.  
  10180. if (FIX_Shady) {
  10181.  
  10182. observablePromise(() => {
  10183. const { ShadyDOM, ShadyCSS } = window;
  10184. if (ShadyDOM) {
  10185. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  10186. ShadyDOM.noPatch = true; // 1 of 10
  10187. ShadyDOM.patchOnDemand = false; // 1 of 10
  10188. ShadyDOM.preferPerformance = true; // 1 of 10
  10189. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  10190. }
  10191. if (ShadyCSS) {
  10192. ShadyCSS.nativeCss = true; // 1 of 10
  10193. ShadyCSS.nativeShadow = true; // 6 of 10
  10194. ShadyCSS.cssBuild = undefined; // 1 of 10
  10195. ShadyCSS.disableRuntime = true; // 1 of 10
  10196. }
  10197. if (ShadyDOM && ShadyCSS) return 1;
  10198. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  10199.  
  10200. }
  10201.  
  10202.  
  10203. // let schedulerInstancePropOfTimerType = '';
  10204. // let schedulerInstancePropOfTimerId = '';
  10205. (FIX_schedulerInstanceInstance & 2) && (async () => {
  10206.  
  10207. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  10208.  
  10209. if (!schedulerInstanceInstance_) return;
  10210.  
  10211. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  10212. if (checkOK) {
  10213.  
  10214. let resolveRendering = null;
  10215.  
  10216. let cmPr = new PromiseExternal();
  10217. const cm = document.createComment('0');
  10218. const cmObs = new MutationObserver(() => {
  10219. if (resolveRendering) {
  10220. resolveRendering();
  10221. resolveRendering = null;
  10222. }
  10223. cmPr.resolve();
  10224. cmPr = new PromiseExternal();
  10225. });
  10226. cmObs.observe(cm, {characterData: true})
  10227.  
  10228. let web_emulated_idle_callback_delay_val = null;
  10229.  
  10230. const getRenderIdleCallbackMs = () => {
  10231. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  10232. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  10233. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  10234. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  10235. return web_emulated_idle_callback_delay_val;
  10236. }
  10237. let isDelayRenderFn_firstCheck = true;
  10238. let isDelayRenderFn_key = null;
  10239. const isDelayRenderFn = (f) => {
  10240. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  10241. isDelayRenderFn_firstCheck = false;
  10242. if (typeof ytglobal === 'undefined') return false;
  10243. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  10244. if (!globalInstance) return false;
  10245. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  10246. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  10247. isDelayRenderFn_key = entry[0]
  10248. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  10249. return true;
  10250. }
  10251. }
  10252. return false;
  10253. }
  10254.  
  10255. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  10256.  
  10257. let requestingFn = null;
  10258. let requestingArgs = null;
  10259.  
  10260. const f = function () {
  10261. requestingFn = this.fn;
  10262. requestingArgs = [...arguments];
  10263. return 12373;
  10264. };
  10265.  
  10266. const fakeFns = [
  10267. f.bind({ fn: requestAnimationFrame }),
  10268. f.bind({ fn: setInterval }),
  10269. f.bind({ fn: setTimeout }),
  10270. f.bind({ fn: requestIdleCallback })
  10271. ];
  10272.  
  10273. let mzt = 0;
  10274.  
  10275. let _fnSelectorProp = null;
  10276. const mkFns = new Array(4);
  10277.  
  10278. /*
  10279. case 1:
  10280. var a = this.K;
  10281. this.g = this.I ? window.requestIdleCallback(a, {
  10282. timeout: 3E3
  10283. }) : window.setTimeout(a, ma);
  10284. break;
  10285. case 2:
  10286. this.g = window.setTimeout(this.M, this.N);
  10287. break;
  10288. case 3:
  10289. this.g = window.requestAnimationFrame(this.L);
  10290. break;
  10291. case 4:
  10292. this.g = window.setTimeout(this.J, 0)
  10293. }
  10294.  
  10295. */
  10296. const startFnHandler = {
  10297. get(target, prop, receiver) {
  10298. if (prop === '$$12377$$') return true;
  10299. if (prop === '$$12378$$') return target;
  10300.  
  10301. // console.log('get',prop)
  10302. return target[prop]
  10303. },
  10304. set(target, prop, value, receiver) {
  10305. // console.log('set', prop, value)
  10306.  
  10307.  
  10308. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  10309. if (value === 12373 && _fnSelectorProp) {
  10310.  
  10311. const schedulerTypeSelection = target[_fnSelectorProp];
  10312. const timerIdProp = prop;
  10313.  
  10314. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  10315. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  10316. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  10317. // schedulerInstancePropOfTimerId = timerIdProp || '';
  10318. // }
  10319.  
  10320. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  10321. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  10322. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  10323. // rare
  10324. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10325. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  10326. // often
  10327. if ((FIX_schedulerInstanceInstance & 4)) {
  10328. const f = requestingArgs[0];
  10329. const tir = ++mzt;
  10330. nextBrowserTick_(() => {
  10331. if (target[timerIdProp] === -tir) f();
  10332. });
  10333. target[_fnSelectorProp] = 940;
  10334. target[timerIdProp] = -tir;
  10335. } else {
  10336. const f = requestingArgs[0];
  10337. const tir = ++mzt;
  10338. Promise.resolve().then(() => {
  10339. if (target[timerIdProp] === -tir) f();
  10340. });
  10341. target[_fnSelectorProp] = 930;
  10342. target[timerIdProp] = -tir;
  10343. }
  10344. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  10345. // often
  10346. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  10347. cm.data = (cm.data & 7) + 1;
  10348. let renderFn = requestingArgs[0];
  10349. const resolveRendering_ = () => {
  10350. const renderFn_ = renderFn;
  10351. if (renderFn_) {
  10352. renderFn = null;
  10353. renderFn_();
  10354. }
  10355. };
  10356. resolveRendering = resolveRendering_;
  10357. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  10358. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  10359.  
  10360. // cm.data = (cm.data & 7) + 1;
  10361. // target[timerIdProp] = Math.random();
  10362.  
  10363. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  10364.  
  10365. cm.data = (cm.data & 7) + 1;
  10366.  
  10367. let renderFn = requestingArgs[0];
  10368. const resolveRendering_ = () => {
  10369. const renderFn_ = renderFn;
  10370. if (renderFn_) {
  10371. renderFn = null;
  10372. renderFn_();
  10373. }
  10374. };
  10375. resolveRendering = resolveRendering_;
  10376.  
  10377. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  10378.  
  10379.  
  10380. } else {
  10381. if (requestingFn === requestIdleCallback) {
  10382. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  10383. } else {
  10384. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  10385. }
  10386. }
  10387. } else {
  10388. target[_fnSelectorProp] = 0;
  10389. target[timerIdProp] = 0;
  10390. }
  10391. } else {
  10392. target[prop] = value;
  10393. }
  10394. return true;
  10395. }
  10396. };
  10397.  
  10398. let startBusy = false;
  10399. schedulerInstanceInstance_.start = function () {
  10400. if (startBusy) return;
  10401. startBusy = true;
  10402. try {
  10403. mkFns[0] = window.requestAnimationFrame;
  10404. mkFns[1] = window.setInterval;
  10405. mkFns[2] = window.setTimeout;
  10406. mkFns[3] = window.requestIdleCallback;
  10407. const tThis = this['$$12378$$'] || this;
  10408. window.requestAnimationFrame = fakeFns[0]
  10409. window.setInterval = fakeFns[1]
  10410. window.setTimeout = fakeFns[2]
  10411. window.requestIdleCallback = fakeFns[3]
  10412. _fnSelectorProp = null;
  10413. tThis.start993.call(new Proxy(tThis, startFnHandler));
  10414. _fnSelectorProp = null;
  10415. window.requestAnimationFrame = mkFns[0];
  10416. window.setInterval = mkFns[1];
  10417. window.setTimeout = mkFns[2];
  10418. window.requestIdleCallback = mkFns[3];
  10419. } catch (e) {
  10420. console.warn(e);
  10421. }
  10422. startBusy = false;
  10423. }
  10424.  
  10425. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  10426.  
  10427. }
  10428. })();
  10429.  
  10430. FIX_yt_player && !isChatRoomURL && (async () => {
  10431.  
  10432. const fOption = 1 | 2 | 4;
  10433.  
  10434. const _yt_player = await _yt_player_observable.obtain();
  10435.  
  10436. if (!_yt_player || typeof _yt_player !== 'object') return;
  10437.  
  10438. const g = _yt_player;
  10439. let k;
  10440.  
  10441. if (fOption & 1) {
  10442.  
  10443. // rAf scheduling
  10444.  
  10445. const keyZqOu = getZqOu(_yt_player);
  10446. if (!keyZqOu) {
  10447. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  10448. return;
  10449. }
  10450. k = keyZqOu
  10451.  
  10452. const gk = g[k];
  10453. if (typeof gk !== 'function') {
  10454. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  10455. return;
  10456. }
  10457. const gkp = gk.prototype;
  10458.  
  10459. const dummyObject = new gk;
  10460. const nilFunc = () => { };
  10461.  
  10462. const nilObj = {};
  10463.  
  10464. // console.log(1111111111)
  10465.  
  10466. let keyBoolD = '';
  10467. let keyWindow = '';
  10468. let keyFuncC = '';
  10469. let keyCidj = '';
  10470.  
  10471. for (const [t, y] of Object.entries(dummyObject)) {
  10472. if (y instanceof Window) keyWindow = t;
  10473. }
  10474.  
  10475. const dummyObjectProxyHandler = {
  10476. get(target, prop) {
  10477. let v = target[prop]
  10478. if (v instanceof Window && !keyWindow) {
  10479. keyWindow = t;
  10480. }
  10481. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  10482. if (prop === keyWindow) y = {
  10483. requestAnimationFrame(f) {
  10484. return 3;
  10485. },
  10486. cancelAnimationFrame() {
  10487.  
  10488. }
  10489. }
  10490. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  10491. keyFuncC = prop;
  10492. }
  10493. // console.log('[get]', prop, typeof target[prop])
  10494.  
  10495.  
  10496. return y;
  10497. },
  10498. set(target, prop, value) {
  10499.  
  10500. if (typeof value === 'boolean' && !keyBoolD) {
  10501. keyBoolD = prop;
  10502. }
  10503. if (typeof value === 'number' && !keyCidj && value >= 2) {
  10504. keyCidj = prop;
  10505. }
  10506.  
  10507. // console.log('[set]', prop, value)
  10508. target[prop] = value;
  10509.  
  10510. return true;
  10511. }
  10512. };
  10513.  
  10514. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  10515.  
  10516. // console.log('gkp.start',gkp.start);
  10517. // console.log('gkp.stop',gkp.stop);
  10518. gkp._activation = false;
  10519.  
  10520. gkp.start = function () {
  10521. // p59 || console.log(12100)
  10522. if (!this._activation) {
  10523. this._activation = true;
  10524. foregroundPromiseFn().then(() => {
  10525. this._activation = false;
  10526. if (this[keyCidj]) {
  10527. Promise.resolve().then(this[keyFuncC]);
  10528. }
  10529. });
  10530. }
  10531. this[keyCidj] = 1;
  10532. this[keyBoolD] = true;
  10533. };
  10534.  
  10535. gkp.stop = function () {
  10536. this[keyCidj] = null;
  10537. };
  10538.  
  10539.  
  10540. /*
  10541. g[k].start = function() {
  10542. this.stop();
  10543. this.D = true;
  10544. var a = requestAnimationFrame
  10545. , b = cancelAnimationFrame;
  10546. this.j = a.call(this.B, this.C)
  10547. }
  10548. ;
  10549. g[k].stop = function() {
  10550. if (this.isActive()) {
  10551. var a = requestAnimationFrame
  10552. , b = cancelAnimationFrame;
  10553. b.call(this.B, this.j)
  10554. }
  10555. this.j = null
  10556. }
  10557. */
  10558. }
  10559.  
  10560. if (fOption & 2) {
  10561. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10562.  
  10563. if (keyzo) {
  10564.  
  10565. k = keyzo;
  10566.  
  10567. const attrUpdateFn = g[k];
  10568. // console.log(5992, attrUpdateFn)
  10569. g['$$original$$' + k] = attrUpdateFn;
  10570. const zoTransform = async (a, c) => {
  10571.  
  10572. let transformType = '';
  10573. let transformValue = 0;
  10574. let transformUnit = '';
  10575. let transformTypeI = 0;
  10576.  
  10577. const aStyle = a.style;
  10578.  
  10579. let cType = 0;
  10580.  
  10581. const cl = c.length;
  10582.  
  10583. if (cl >= 8) {
  10584. // scale(1)
  10585. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10586. cType = 1;
  10587. let t = c.charCodeAt(5);
  10588. if (t === 88 || t === 120) cType = 1 | 4;
  10589. if (t === 89 || t === 121) cType = 1 | 8;
  10590. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10591. cType = 2;
  10592. let t = c.charCodeAt(9);
  10593. if (t === 88 || t === 120) cType = 2 | 4;
  10594. if (t === 89 || t === 121) cType = 2 | 8;
  10595. }
  10596. let w = 0;
  10597. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10598. let p = c.substring(7, cl - 1);
  10599. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10600. if (typeof q === 'number' && !isNaNx(q)) {
  10601. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10602. transformValue = q;
  10603. transformUnit = '';
  10604. transformTypeI = 1;
  10605. } else {
  10606. cType = 256;
  10607. }
  10608. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10609. if (c.endsWith('px)')) {
  10610. let p = c.substring(11, cl - 3);
  10611. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10612. if (typeof q === 'number' && !isNaNx(q)) {
  10613. transformType = w === 1 ? 'translateX' : 'translateY';
  10614. transformValue = q;
  10615. transformUnit = 'px';
  10616. transformTypeI = 2;
  10617. } else if (p === 'NaN') {
  10618. return;
  10619. }
  10620. } else {
  10621. cType = 256;
  10622. }
  10623. } else if (cType > 0) {
  10624. cType = 256;
  10625. }
  10626. }
  10627.  
  10628.  
  10629. if (cType === 256) {
  10630. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10631. }
  10632.  
  10633. if (transformTypeI === 1) {
  10634. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10635. const vz = toFixed2(q, 3);
  10636. c = `${transformType}(${vz})`;
  10637. const cv = aStyle.transform;
  10638. if (c === cv) return;
  10639. aStyle.transform = c;
  10640. } else if (transformTypeI === 2) {
  10641. const q = transformValue;
  10642. const vz = toFixed2(q, 1);
  10643. c = `${transformType}(${vz}${transformUnit})`;
  10644. const cv = aStyle.transform;
  10645. if (c === cv) return;
  10646. aStyle.transform = c;
  10647. } else { // eg empty
  10648. const cv = aStyle.transform;
  10649. if (!c && !cv) return;
  10650. else if (c === cv) return;
  10651. aStyle.transform = c;
  10652. }
  10653.  
  10654. };
  10655.  
  10656. const elmTransformTemp = new WeakMap();
  10657. const elmPropTemps = {
  10658. 'display': new WeakMap(),
  10659. 'width': new WeakMap(),
  10660. 'height': new WeakMap(),
  10661. 'outlineWidth': new WeakMap(),
  10662. 'position': new WeakMap(),
  10663. 'padding': new WeakMap(),
  10664. "cssText": new WeakMap(),
  10665. "right": new WeakMap(),
  10666. "left": new WeakMap(),
  10667. "top": new WeakMap(),
  10668. "bottom": new WeakMap(),
  10669. "transitionDelay": new WeakMap(),
  10670. "marginLeft": new WeakMap(),
  10671. "marginTop": new WeakMap(),
  10672. "marginRight": new WeakMap(),
  10673. "marginBottom": new WeakMap(),
  10674. }
  10675.  
  10676. const ns5 = Symbol();
  10677. const nextModify = (a, c, m, f, immediate) => {
  10678. const a_ = a;
  10679. const m_ = m;
  10680. const noKey = !m_.has(a_);
  10681. if (immediate || noKey) {
  10682. m_.set(a_, ns5);
  10683. f(a_, c);
  10684. noKey && nextBrowserTick_(() => {
  10685. const d = m_.get(a_);
  10686. if (d === undefined) return;
  10687. m_.delete(a_);
  10688. if (d !== ns5) f(a_, d);
  10689. });
  10690. } else {
  10691. m_.set(a_, c);
  10692. }
  10693. };
  10694.  
  10695. const set66 = new Set();
  10696. const log77 = new Map();
  10697. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10698.  
  10699. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10700.  
  10701. // console.log(140000, a, b, c);
  10702. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10703. const num = c;
  10704. c = `${num}`;
  10705. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10706. }
  10707.  
  10708. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10709.  
  10710. let elmPropTemp = null;
  10711.  
  10712. if (b === "transform") {
  10713. // div.ytp-hover-progress.ytp-hover-progress-light
  10714. // div.ytp-play-progress.ytp-swatch-background-color
  10715.  
  10716. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10717. return;
  10718.  
  10719. } else if (elmPropTemp = elmPropTemps[b]) {
  10720.  
  10721. // if (c.length > 5 && c.includes('.')) {
  10722. // console.log(123213, c)
  10723. // }
  10724.  
  10725. const b_ = b;
  10726. nextModify(a, c, elmPropTemp, (a, c) => {
  10727. const style = a.style;
  10728. const cv = style[b_];
  10729. if (!cv && !c) return;
  10730. if (cv === c) return;
  10731. style[b_] = c;
  10732. }, immediateChange);
  10733. return;
  10734.  
  10735. } else if (b === "outline-width") {
  10736.  
  10737. const b_ = 'outlineWidth';
  10738. elmPropTemp = elmPropTemps[b_];
  10739. nextModify(a, c, elmPropTemp, (a, c) => {
  10740. const style = a.style;
  10741. const cv = style[b_];
  10742. if (!cv && !c) return;
  10743. if (cv === c) return;
  10744. style[b_] = c;
  10745. }, immediateChange);
  10746. return;
  10747.  
  10748. } else if (b === 'maxWidth' || b === 'maxHeight') {
  10749. // I think these can be directly assigned.
  10750.  
  10751. const b_ = b;
  10752. const style = a.style;
  10753. const cv = style[b_];
  10754. if (!cv && !c) return;
  10755. if (cv === c) return;
  10756. style[b_] = c;
  10757. return;
  10758.  
  10759. } else {
  10760. // if(immediate && elmPropTemps[b]){
  10761. // console.log(5191, b)
  10762. // }
  10763. // caption-window
  10764. // margin-left max-height max-width font-family fill color font-size background white-space margin
  10765. // text-align background-color
  10766. // console.log(27304, a, b, c)
  10767. if (!set66.has(b)) {
  10768. set66.add(b);
  10769. nextBrowserTick_(() => {
  10770. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  10771. console.log(27304, a, b, c)
  10772. }
  10773. })
  10774. }
  10775. }
  10776.  
  10777. attrUpdateFn.call(this, a, b, c);
  10778. return;
  10779. } else if (typeof (b || 0) === 'object') {
  10780.  
  10781. // this is to fix caption positioning
  10782. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  10783. const immediate = (a.id || 0).length > 14;
  10784. for (const [k, v] of Object.entries(b)) {
  10785. modifiedFn.call(this, a, k, v, immediate);
  10786. }
  10787.  
  10788. } else {
  10789.  
  10790. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  10791. // ytp-ad-timed-pie-countdown-inner
  10792.  
  10793. if (typeof b === 'string') {
  10794.  
  10795. let m = log77.get(b);
  10796. if (!m) {
  10797. m = [];
  10798. console.log('attrUpdateFn.debug.27304', m);
  10799. log77.set(b, m);
  10800. }
  10801. m.push([a, b, c]);
  10802.  
  10803. } else {
  10804. console.log('attrUpdateFn.debug.27306', a, b, c);
  10805. }
  10806.  
  10807. attrUpdateFn.call(this, a, b, c);
  10808. return;
  10809. }
  10810.  
  10811. // console.log(130000, a, b, c);
  10812.  
  10813. };
  10814. g[k] = modifiedFn;
  10815.  
  10816.  
  10817. /*
  10818.  
  10819. g.zo = function(a, b, c) {
  10820. if ("string" === typeof b)
  10821. (b = yo(a, b)) && (a.style[b] = c);
  10822. else
  10823. for (var d in b) {
  10824. c = a;
  10825. var e = b[d]
  10826. , f = yo(c, d);
  10827. f && (c.style[f] = e)
  10828. }
  10829. }
  10830.  
  10831.  
  10832. */
  10833.  
  10834.  
  10835. }
  10836. }
  10837.  
  10838. if (fOption & 4) {
  10839. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  10840.  
  10841. if (keyuG) {
  10842.  
  10843. k = keyuG;
  10844.  
  10845. const gk = g[k];
  10846. const gkp = gk.prototype;
  10847.  
  10848.  
  10849. /** @type { Map<string, WeakMap<any, any>> } */
  10850. const ntLogs = new Map();
  10851.  
  10852. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  10853.  
  10854. gkp.updateValue31 = gkp.updateValue;
  10855. gkp.updateValue = function (a, b) {
  10856. if (typeof a !== 'string') return this.updateValue31(a, b);
  10857.  
  10858. const element = this.element;
  10859. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  10860.  
  10861. let ntLog = ntLogs.get(a);
  10862. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  10863.  
  10864. let cache = ntLog.get(element);
  10865. if (cache && cache.value === b) {
  10866. return;
  10867. }
  10868. if (!cache) {
  10869. this.__oldValueByUpdateValue__ = null;
  10870. ntLog.set(element, cache = { value: b });
  10871. } else {
  10872. this.__oldValueByUpdateValue__ = cache.value;
  10873. cache.value = b;
  10874. }
  10875.  
  10876. return this.updateValue31(a, b);
  10877. }
  10878.  
  10879. /*
  10880. g.k.update = function(a) {
  10881. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  10882. c = c.value,
  10883. this.updateValue(c, a[c])
  10884. }
  10885. ;
  10886. g.k.updateValue = function(a, b) {
  10887. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  10888. }
  10889. */
  10890.  
  10891. }
  10892.  
  10893.  
  10894. }
  10895. }
  10896.  
  10897.  
  10898.  
  10899. })();
  10900.  
  10901.  
  10902. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  10903. // keyboard shortcut keys controller
  10904.  
  10905. const _yt_player = await _yt_player_observable.obtain();
  10906.  
  10907. if (!_yt_player || typeof _yt_player !== 'object') return;
  10908.  
  10909. keyboardController(_yt_player);
  10910.  
  10911. })();
  10912.  
  10913. FIX_yt_player && !isChatRoomURL && (async () => {
  10914. // timer scheduling
  10915.  
  10916. const _yt_player = await _yt_player_observable.obtain();
  10917.  
  10918. if (!_yt_player || typeof _yt_player !== 'object') return;
  10919.  
  10920. let keyZqQu = getZqQu(_yt_player);
  10921.  
  10922. if (!keyZqQu) return;
  10923.  
  10924. const g = _yt_player
  10925. let k = keyZqQu
  10926.  
  10927. const gk = g[k];
  10928. if (typeof gk !== 'function') return;
  10929. const gkp = gk.prototype;
  10930.  
  10931. const extractKeysZqQu = () => {
  10932.  
  10933.  
  10934. let _keyeC = '';
  10935. try {
  10936. gkp.stop.call(new Proxy({
  10937. isActive: () => { }
  10938. }, {
  10939. set(target, prop, value) {
  10940. if (value === 0) _keyeC = prop;
  10941. return true;
  10942. }
  10943. }));
  10944. } catch (e) { }
  10945. if (!_keyeC) return;
  10946. const keyeC = _keyeC;
  10947.  
  10948. let keyC = ''; // this.C = this.ST.bind(this)
  10949. let keyhj = ''; // 1000ms
  10950. try {
  10951. gkp.start.call(new Proxy({
  10952. stop: () => { },
  10953. [keyeC]: 0,
  10954. }, {
  10955. get(target, prop) {
  10956. if (prop in target) return target[prop];
  10957. if (!keyC) {
  10958. keyC = prop;
  10959. return null; // throw error
  10960. }
  10961. else if (!keyhj) {
  10962. keyhj = prop;
  10963. }
  10964.  
  10965. }
  10966. }));
  10967. } catch (e) {
  10968. if (!keyC || !keyhj) {
  10969. console.log(e)
  10970. }
  10971. }
  10972.  
  10973. if (!keyC || !keyhj) return;
  10974. let keyST = '';
  10975. let keyj = '';
  10976. let keyB = '';
  10977. let keyxa = '';
  10978.  
  10979. const possibleKs = new Set();
  10980.  
  10981. for (const [k, v] of Object.entries(gkp)) {
  10982. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  10983. continue;
  10984. }
  10985. if (typeof v === 'function') {
  10986. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  10987. if (m) {
  10988. keyST = k;
  10989. keyj = m[1];
  10990. keyB = m[2];
  10991. } else {
  10992. possibleKs.add(k);
  10993. }
  10994. }
  10995. }
  10996.  
  10997. if (!keyST || !keyj || !keyB) return;
  10998.  
  10999. for (const k of possibleKs) {
  11000. if (k === keyST || k === keyj || k === keyB) {
  11001. continue;
  11002. }
  11003. const v = gkp[k];
  11004. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  11005. keyxa = k;
  11006. }
  11007. }
  11008.  
  11009. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  11010.  
  11011. }
  11012.  
  11013. const keys = extractKeysZqQu();
  11014. if (!keys || !keys.length) return;
  11015. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  11016.  
  11017. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  11018.  
  11019. let disposeKeys = null;
  11020.  
  11021. gkp[keyxa] = function () {
  11022. // dispose
  11023. if (!disposeKeys) {
  11024. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  11025. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  11026. const t = typeof this[key];
  11027. return t === 'undefined' || t === 'object'
  11028. }
  11029. return false;
  11030. });
  11031. }
  11032. for (const key of disposeKeys) {
  11033. const v = this[key];
  11034. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  11035. }
  11036. if (this[keyeC] > 0) this.stop();
  11037. this[keyj] = null;
  11038. this[keyB] = null;
  11039. };
  11040.  
  11041. gkp.start = function (a) {
  11042. if (this[keyeC] > 0) this.stop();
  11043. const delay = void 0 !== a ? a : this[keyhj];
  11044. this[keyeC] = window.setTimeout(this[keyC], delay);
  11045. };
  11046. gkp.stop = function () {
  11047. if (this[keyeC] > 0) {
  11048. window.clearTimeout(this[keyeC]);
  11049. this[keyeC] = 0;
  11050. }
  11051. };
  11052.  
  11053. gkp.isActive = function () {
  11054. return this[keyeC] > 0;
  11055. };
  11056.  
  11057. gkp[keyST] = function () {
  11058. this.stop(); // this[keyeC] = 0;
  11059. const fn = this[keyj];
  11060. const obj = this[keyB];
  11061. let skip = false;
  11062. if (!fn) skip = true;
  11063. else if (IGNORE_bufferhealth_CHECK && obj) {
  11064. let m;
  11065. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  11066. if (m.has("bufferhealth")) skip = true;
  11067. }
  11068. }
  11069. if (!skip) {
  11070. fn.call(obj);
  11071. }
  11072. };
  11073.  
  11074.  
  11075.  
  11076.  
  11077. /*
  11078.  
  11079. g.k.eC = 0;
  11080. g.k.xa = function() {
  11081. g.Qu.Vf.xa.call(this);
  11082. this.stop();
  11083. delete this.j;
  11084. delete this.B
  11085. }
  11086. ;
  11087. g.k.start = function(a) {
  11088. this.stop();
  11089. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  11090. }
  11091. ;
  11092. g.k.stop = function() {
  11093. this.isActive() && g.Sa.clearTimeout(this.eC);
  11094. this.eC = 0
  11095. }
  11096. ;
  11097. g.k.isActive = function() {
  11098. return 0 != this.eC
  11099. }
  11100. ;
  11101. g.k.ST = function() {
  11102. this.eC = 0;
  11103. this.j && this.j.call(this.B)
  11104. }
  11105. ;
  11106. */
  11107.  
  11108.  
  11109.  
  11110.  
  11111. })();
  11112.  
  11113. FIX_Animation_n_timeline && (async () => {
  11114.  
  11115. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  11116.  
  11117. if (!timeline || !Animation) return;
  11118.  
  11119. const animationsFix = (timeline) => {
  11120. const animations = (timeline || 0)._animations || 0;
  11121. const c = animations[0];
  11122. if (c) {
  11123. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  11124. animations.shift(); // keep animating but no looping
  11125. // c.effect.remove();
  11126. }
  11127. }
  11128. }
  11129.  
  11130. const aniProto = Animation.prototype;
  11131. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  11132.  
  11133. const getXroto = (x) => {
  11134. try {
  11135. return x.__proto__;
  11136. } catch (e) { }
  11137. return null;
  11138. }
  11139. const timProto = getXroto(timeline);
  11140. if (!timProto) return;
  11141. if (
  11142. (
  11143. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  11144. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  11145. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  11146. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  11147. )
  11148.  
  11149. ) {
  11150.  
  11151. timProto.nofCQ = 1;
  11152. aniProto.nofYH = 1;
  11153.  
  11154. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  11155.  
  11156.  
  11157. /*
  11158. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11159. return c._updatePromises();
  11160. });
  11161. */
  11162.  
  11163. const p = Array.prototype.filter;
  11164.  
  11165. let res = null;
  11166. Array.prototype.filter = function () {
  11167.  
  11168. res = this;
  11169. return this;
  11170.  
  11171. };
  11172.  
  11173. _updateAnimationsPromises.call({});
  11174.  
  11175. Array.prototype.filter = p;
  11176.  
  11177. if (res && typeof res.length === 'number') {
  11178. /** @type {any[]} */
  11179. const _res = res;
  11180. return _res;
  11181. }
  11182.  
  11183.  
  11184. return null;
  11185.  
  11186.  
  11187.  
  11188.  
  11189. })(timProto._updateAnimationsPromises);
  11190.  
  11191. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  11192.  
  11193. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  11194.  
  11195. aniProto._updatePromises31 = aniProto._updatePromises;
  11196.  
  11197. /*
  11198. aniProto._updatePromises = function(){
  11199. console.log('eff',this._oldPlayState, this.playState)
  11200. return this._updatePromises31.apply(this, arguments)
  11201. }
  11202. */
  11203.  
  11204. aniProto._updatePromises = function () {
  11205. var oldPlayState = this._oldPlayState;
  11206. var newPlayState = this.playState;
  11207. // console.log('ett', oldPlayState, newPlayState)
  11208. if (newPlayState !== oldPlayState) {
  11209. this._oldPlayState = newPlayState;
  11210. if (this._readyPromise) {
  11211. if ("idle" == newPlayState) {
  11212. this._rejectReadyPromise();
  11213. this._readyPromise = void 0;
  11214. } else if ("pending" == oldPlayState) {
  11215. this._resolveReadyPromise();
  11216. } else if ("pending" == newPlayState) {
  11217. this._readyPromise = void 0;
  11218. }
  11219. }
  11220. if (this._finishedPromise) {
  11221. if ("idle" == newPlayState) {
  11222. this._rejectFinishedPromise();
  11223. this._finishedPromise = void 0;
  11224. } else if ("finished" == newPlayState) {
  11225. this._resolveFinishedPromise();
  11226. } else if ("finished" == oldPlayState) {
  11227. this._finishedPromise = void 0;
  11228. }
  11229. }
  11230. }
  11231. return this._readyPromise || this._finishedPromise;
  11232. };
  11233.  
  11234.  
  11235. let restartWebAnimationsNextTickFlag = false;
  11236.  
  11237. const looperMethodT = () => {
  11238.  
  11239. const runnerFn = (hRes) => {
  11240. var b = timeline;
  11241. b.currentTime = hRes;
  11242. b._discardAnimations();
  11243. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11244. if (0 == b._animations.length) {
  11245. restartWebAnimationsNextTickFlag = false;
  11246. } else {
  11247. getRafPromise().then(runnerFn);
  11248. }
  11249. }
  11250.  
  11251. const restartWebAnimationsNextTick = () => {
  11252. if (!restartWebAnimationsNextTickFlag) {
  11253. restartWebAnimationsNextTickFlag = true;
  11254. getRafPromise().then(runnerFn);
  11255. }
  11256. }
  11257.  
  11258. return { restartWebAnimationsNextTick }
  11259. };
  11260.  
  11261.  
  11262. const looperMethodN = () => {
  11263.  
  11264. const acs = document.createElement('a-f');
  11265. acs.id = 'a-f';
  11266.  
  11267. if (!document.getElementById('afscript')) {
  11268. const style = document.createElement('style');
  11269. style.id = 'afscript';
  11270. style.textContent = `
  11271. @keyFrames aF1 {
  11272. 0% {
  11273. order: 0;
  11274. }
  11275. 100% {
  11276. order: 1;
  11277. }
  11278. }
  11279. #a-f[id] {
  11280. visibility: collapse !important;
  11281. position: fixed !important;
  11282. display: block !important;
  11283. top: -100px !important;
  11284. left: -100px !important;
  11285. margin:0 !important;
  11286. padding:0 !important;
  11287. outline:0 !important;
  11288. border:0 !important;
  11289. z-index:-1 !important;
  11290. width: 0px !important;
  11291. height: 0px !important;
  11292. contain: strict !important;
  11293. pointer-events: none !important;
  11294. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  11295. }
  11296. `;
  11297. (document.head || document.documentElement).appendChild(style);
  11298. }
  11299.  
  11300. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  11301.  
  11302. const _onanimationiteration = function (evt) {
  11303. const hRes = evt.timeStamp;
  11304. var b = timeline;
  11305. b.currentTime = hRes;
  11306. b._discardAnimations();
  11307. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  11308. if (0 == b._animations.length) {
  11309. restartWebAnimationsNextTickFlag = false;
  11310. acs.onanimationiteration = null;
  11311. } else {
  11312. acs.onanimationiteration = _onanimationiteration;
  11313. }
  11314.  
  11315. }
  11316.  
  11317.  
  11318.  
  11319. const restartWebAnimationsNextTick = () => {
  11320. if (!restartWebAnimationsNextTickFlag) {
  11321. restartWebAnimationsNextTickFlag = true;
  11322. acs.onanimationiteration = _onanimationiteration;
  11323.  
  11324. }
  11325. }
  11326.  
  11327. return { restartWebAnimationsNextTick }
  11328. };
  11329.  
  11330.  
  11331.  
  11332. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  11333.  
  11334.  
  11335. // console.log(571, timProto);
  11336. timProto._play = function (c) {
  11337. c = new Animation(c, this);
  11338. this._animations.push(c);
  11339. restartWebAnimationsNextTick();
  11340. c._updatePromises();
  11341. c._animation.play();
  11342. c._updatePromises();
  11343. return c
  11344. }
  11345.  
  11346. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  11347. originalAnimationsWithPromises.length = 0;
  11348. originalAnimationsWithPromises.push = null;
  11349. originalAnimationsWithPromises.splice = null;
  11350. originalAnimationsWithPromises.slice = null;
  11351. originalAnimationsWithPromises.indexOf = null;
  11352. originalAnimationsWithPromises.unshift = null;
  11353. originalAnimationsWithPromises.shift = null;
  11354. originalAnimationsWithPromises.pop = null;
  11355. originalAnimationsWithPromises.filter = null;
  11356. originalAnimationsWithPromises.forEach = null;
  11357. originalAnimationsWithPromises.map = null;
  11358.  
  11359.  
  11360. const _updateAnimationsPromises = () => {
  11361. animationsWithPromisesMap.forEach(c => {
  11362. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  11363. });
  11364. /*
  11365. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  11366. return c._updatePromises();
  11367. });
  11368. */
  11369. }
  11370.  
  11371. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  11372.  
  11373. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  11374.  
  11375. delete timProto._updateAnimationsPromises;
  11376. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  11377. get() {
  11378. if (animationsWithPromisesMap.size === 0) return nilFn;
  11379. return _updateAnimationsPromises;
  11380. },
  11381. set(nv) {
  11382. delete this._updateAnimationsPromises;
  11383. this._updateAnimationsPromises = nv;
  11384. },
  11385. enumerable: true,
  11386. configurable: true,
  11387. });
  11388.  
  11389.  
  11390. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  11391. aniProto.__finished_native_get__ = pdFinished.get;
  11392. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  11393.  
  11394.  
  11395. Object.defineProperty(aniProto, 'finished', {
  11396. get() {
  11397. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11398. this._finishedPromise = new Promise((resolve, reject) => {
  11399. this._resolveFinishedPromise = function () {
  11400. resolve(this)
  11401. };
  11402. this._rejectFinishedPromise = function () {
  11403. reject({
  11404. type: DOMException.ABORT_ERR,
  11405. name: "AbortError"
  11406. })
  11407. };
  11408. }),
  11409. "finished" == this.playState && this._resolveFinishedPromise());
  11410. return this._finishedPromise
  11411. },
  11412. set: undefined,
  11413. enumerable: true,
  11414. configurable: true
  11415. });
  11416.  
  11417. }
  11418.  
  11419.  
  11420.  
  11421. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  11422. aniProto.__ready_native_get__ = pdReady.get;
  11423. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  11424.  
  11425. Object.defineProperty(aniProto, 'ready', {
  11426. get() {
  11427. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11428. this._readyPromise = new Promise((resolve, reject) => {
  11429. this._resolveReadyPromise = function () {
  11430. resolve(this)
  11431. };
  11432. this._rejectReadyPromise = function () {
  11433. reject({
  11434. type: DOMException.ABORT_ERR,
  11435. name: "AbortError"
  11436. })
  11437. };
  11438. }),
  11439. "pending" !== this.playState && this._resolveReadyPromise());
  11440. return this._readyPromise
  11441. },
  11442. set: undefined,
  11443. enumerable: true,
  11444. configurable: true
  11445. });
  11446.  
  11447. }
  11448.  
  11449.  
  11450. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  11451.  
  11452. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  11453. const _rebuildUnderlyingAnimation = function () {
  11454. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  11455. this.effect && this.effect._onsample && (this.effect._onsample = null);
  11456. return this._rebuildUnderlyingAnimation21();
  11457. }
  11458. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  11459. // delete aniProto._rebuildUnderlyingAnimation;
  11460. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  11461. // get() {
  11462. // if (isNaN(this._sequenceNumber)) return nilFn;
  11463. // return this._rebuildUnderlyingAnimation21;
  11464. // },
  11465. // set(nv) {
  11466. // delete this._rebuildUnderlyingAnimation;
  11467. // this._rebuildUnderlyingAnimation = nv;
  11468. // },
  11469. // enumerable: true,
  11470. // configurable: true
  11471. // });
  11472. }
  11473.  
  11474.  
  11475. /*
  11476.  
  11477.  
  11478. function f(c) {
  11479. var b = v.timeline;
  11480. b.currentTime = c;
  11481. b._discardAnimations();
  11482. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  11483. }
  11484. var h = window.requestAnimationFrame;
  11485. window.requestAnimationFrame = function(c) {
  11486. return h(function(b) {
  11487. v.timeline._updateAnimationsPromises();
  11488. c(b);
  11489. v.timeline._updateAnimationsPromises()
  11490. })
  11491. }
  11492. ;
  11493. v.AnimationTimeline = function() {
  11494. this._animations = [];
  11495. this.currentTime = void 0
  11496. }
  11497. ;
  11498. v.AnimationTimeline.prototype = {
  11499. getAnimations: function() {
  11500. this._discardAnimations();
  11501. return this._animations.slice()
  11502. },
  11503. _updateAnimationsPromises: function() {
  11504. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  11505. return c._updatePromises()
  11506. })
  11507. },
  11508. _discardAnimations: function() {
  11509. this._updateAnimationsPromises();
  11510. this._animations = this._animations.filter(function(c) {
  11511. return "finished" != c.playState && "idle" != c.playState
  11512. })
  11513. },
  11514. _play: function(c) {
  11515. c = new v.Animation(c,this);
  11516. this._animations.push(c);
  11517. v.restartWebAnimationsNextTick();
  11518. c._updatePromises();
  11519. c._animation.play();
  11520. c._updatePromises();
  11521. return c
  11522. },
  11523. play: function(c) {
  11524. c && c.remove();
  11525. return this._play(c)
  11526. }
  11527. };
  11528. var d = !1;
  11529. v.restartWebAnimationsNextTick = function() {
  11530. d || (d = !0,
  11531. requestAnimationFrame(f))
  11532. }
  11533. ;
  11534. var a = new v.AnimationTimeline;
  11535. v.timeline = a;
  11536. try {
  11537. Object.defineProperty(window.document, "timeline", {
  11538. configurable: !0,
  11539. get: function() {
  11540. return a
  11541. }
  11542. })
  11543. } catch (c) {}
  11544. try {
  11545. window.document.timeline = a
  11546. } catch (c) {}
  11547.  
  11548. */
  11549.  
  11550.  
  11551.  
  11552. /*
  11553.  
  11554. var g = window.getComputedStyle;
  11555. Object.defineProperty(window, "getComputedStyle", {
  11556. configurable: !0,
  11557. enumerable: !0,
  11558. value: function() {
  11559. v.timeline._updateAnimationsPromises();
  11560. var e = g.apply(this, arguments);
  11561. h() && (e = g.apply(this, arguments));
  11562. v.timeline._updateAnimationsPromises();
  11563. return e
  11564. }
  11565. });
  11566.  
  11567. */
  11568.  
  11569.  
  11570.  
  11571.  
  11572. }
  11573.  
  11574.  
  11575.  
  11576.  
  11577. })();
  11578.  
  11579. !isUrlInEmbed && Promise.resolve().then(() => {
  11580.  
  11581. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11582.  
  11583.  
  11584.  
  11585. class LimitedSizeSet extends Set {
  11586. constructor(n) {
  11587. super();
  11588. this.limit = n;
  11589. }
  11590.  
  11591. add(key) {
  11592. if (!super.has(key)) {
  11593. super.add(key);
  11594. let n = super.size - this.limit;
  11595. if (n > 0) {
  11596. const iterator = super.values();
  11597. do {
  11598. const firstKey = iterator.next().value; // Get the first (oldest) key
  11599. super.delete(firstKey); // Delete the oldest key
  11600. } while (--n > 0)
  11601. }
  11602. }
  11603. }
  11604.  
  11605. removeAdd(key) {
  11606. super.delete(key);
  11607. this.add(key);
  11608. }
  11609.  
  11610. }
  11611.  
  11612. // const wk3 = new WeakMap();
  11613.  
  11614. // let mtxVideoId = '';
  11615. // let aje3 = [];
  11616. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11617. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11618. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11619. let mtzCount = 0; // the key keeps unchanged
  11620. // let mjtNextMainKey = '';
  11621. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11622. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11623. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11624. // let allowNoDelay322=false;
  11625. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11626.  
  11627. let mpKey22 = ''; // last success continutation key & url pair
  11628. let mpUrl22 = ''; // last success continutation key & url pair
  11629. let mpKey21 = ''; // latest requested continutation key & url pair
  11630. let mpUrl21 = ''; // latest requested continutation key & url pair
  11631.  
  11632.  
  11633. async function sha1Hex(message) {
  11634. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11635. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11636. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11637. const hashHex = hashArray
  11638. .map((b) => b.toString(16).padStart(2, "0"))
  11639. .join(""); // convert bytes to hex string
  11640. return hashHex;
  11641. }
  11642.  
  11643. async function continuationLog(a, ...args) {
  11644. let b = a;
  11645. try {
  11646. if (advanceLogging) b = await sha1Hex(a);
  11647. let c = args.map(e => {
  11648. return e === a ? b : e
  11649. });
  11650. console.log(...c)
  11651. } catch (e) { console.warn(e) }
  11652. }
  11653.  
  11654. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11655.  
  11656.  
  11657. if (mfvContinuationRecorded.length > 0) {
  11658. for (const [e, d] of mfvContinuationRecorded) {
  11659. mfyContinuationIgnored.removeAdd(e);
  11660. }
  11661. toClearRecorded && mfvContinuationRecorded.clear();
  11662. }
  11663.  
  11664. }
  11665.  
  11666. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11667.  
  11668. const tmProto = taskMgr.constructor.prototype;
  11669. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11670.  
  11671. if (!tmProto.addJob714) {
  11672.  
  11673. tmProto.addJob714 = tmProto.addJob;
  11674.  
  11675. tmProto.addJob = function (a, b, c) {
  11676. const jobId = this.addJob714(a, b, c);
  11677. if (jobId > 0) {
  11678. // const ez = wk3.get(this);
  11679. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11680. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11681.  
  11682. this.__lastJobId863__ = jobId;
  11683. }
  11684. return jobId;
  11685. }
  11686.  
  11687. }
  11688.  
  11689. if (!tmProto.cancelJob714) {
  11690.  
  11691. tmProto.cancelJob714 = tmProto.cancelJob;
  11692.  
  11693. tmProto.cancelJob = function (a) {
  11694. const res = this.cancelJob714(a);
  11695. // if (a > 0) {
  11696. // for (const e of aje3) {
  11697. // if (e.jobId === a) e.cancelled = true;
  11698. // }
  11699. // }
  11700. return res;
  11701. }
  11702.  
  11703. }
  11704.  
  11705. }
  11706. }
  11707.  
  11708.  
  11709. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11710.  
  11711.  
  11712. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11713. let dummy;
  11714. let cProto;
  11715. // let mc = 4;
  11716. // dummy = await observablePromise(() => {
  11717. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11718. // if (!r) return;
  11719. // let cProto = insp(r).constructor.prototype;
  11720. // if (cProto.fetchUpdatedMetadata) return r;
  11721. // if (--mc < 0) return -1;
  11722. // return null;
  11723. // }).obtain();
  11724. dummy = document.createElement('ytd-video-primary-info-renderer');
  11725. if (!(dummy instanceof Element)) return;
  11726. // console.log(5022, dummy)
  11727. cProto = insp(dummy).constructor.prototype;
  11728.  
  11729. cProto.__getEmittorTaskMgr859__ = function () {
  11730. let taskMgr_ = null;
  11731. try {
  11732. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  11733. } catch (e) { }
  11734. return taskMgr_;
  11735. }
  11736. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  11737. // console.log(1234, cProto, cProto.is)
  11738. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  11739.  
  11740. let c_;
  11741. cProto.fetchUpdatedMetadata718 = function (a) {
  11742. // delay or immediate call the actual fetchUpdatedMetadata
  11743.  
  11744. let doImmediately = false;
  11745. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  11746.  
  11747. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  11748.  
  11749. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  11750.  
  11751. doImmediately = true;
  11752.  
  11753. }
  11754.  
  11755. if (mbCId322) {
  11756. clearTimeout(mbCId322);
  11757. mbCId322 = 0;
  11758. }
  11759.  
  11760. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  11761.  
  11762. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  11763.  
  11764. mbCId322 = setTimeout(() => {
  11765. this.fetchUpdatedMetadata717(a);
  11766. }, delay);
  11767.  
  11768. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  11769.  
  11770. }
  11771.  
  11772. cProto.fetchUpdatedMetadata = function (a) {
  11773.  
  11774. if (!pageSetupState) {
  11775. if (c_) clearTimeout(c_);
  11776. c_ = setTimeout(() => {
  11777. this.fetchUpdatedMetadata718(a);
  11778. }, 300);
  11779. return;
  11780. }
  11781.  
  11782. // pageSetupState == 0
  11783.  
  11784. try {
  11785.  
  11786. mbDelayBelowNCalls++;
  11787.  
  11788. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  11789. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  11790. }
  11791.  
  11792. // console.log('fum377', a)
  11793. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  11794. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  11795. return;
  11796. }
  11797.  
  11798. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  11799. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  11800. mjtLockPreviousKey = mjtRecordedPrevKey;
  11801. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  11802. }
  11803. // mjtNextMainKey = true;
  11804. mtzlastAllowedContinuation = '';
  11805. mtzCount = 0;
  11806. // allowNoDelay322 = false;
  11807. // fetch new metadata, cancel all previous continuations
  11808. copyPreviousContiuationToIgnored374(true);
  11809. } else if (typeof a === 'string') {
  11810. const videoPlayingId = videoPlayingY.videoId;
  11811.  
  11812. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  11813.  
  11814. let update21 = !!pageSetupVideoId;
  11815. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  11816. update21 = true;
  11817. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  11818. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  11819. return;
  11820. }
  11821. if (update21) {
  11822. mpKey21 = a;
  11823. mpUrl21 = pageSetupVideoId || videoPlayingId;
  11824. }
  11825.  
  11826. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  11827. }
  11828. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  11829. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  11830. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  11831. return this.fetchUpdatedMetadata718(a);
  11832.  
  11833. } catch (e) {
  11834. console.log('Code Error in fetchUpdatedMetadata', e);
  11835. }
  11836. return this.fetchUpdatedMetadata717(a)
  11837. }
  11838. }
  11839.  
  11840.  
  11841. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  11842. // console.log(1234, cProto, cProto.is)
  11843. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  11844. let mJob = null;
  11845.  
  11846. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  11847.  
  11848. try {
  11849.  
  11850. if (arguments.length > 0) {
  11851. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  11852. }
  11853. // mfy = mfv;
  11854.  
  11855. // mjtNextMainKey = '';
  11856. mtzlastAllowedContinuation = '';
  11857. mtzCount = 0;
  11858. if (mbCId322) {
  11859. clearTimeout(mbCId322);
  11860. mbCId322 = 0;
  11861. }
  11862. mbDelayBelowNCalls = 0;
  11863. // allowNoDelay322 = false;
  11864. copyPreviousContiuationToIgnored374(true);
  11865.  
  11866. const taskMgr = this.__getEmittorTaskMgr859__();
  11867. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  11868. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  11869. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  11870. }
  11871.  
  11872. // prevent depulicated schedule job by clearing previous JobId
  11873. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  11874.  
  11875. let res;
  11876.  
  11877. if (mJob) {
  11878. const job = mJob;
  11879. mJob = null;
  11880. console.log('cancelJob', job)
  11881. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  11882. // p.cancelJob(a,b);
  11883. }
  11884.  
  11885. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  11886.  
  11887. let pza = taskMgr.__lastJobId863__;
  11888. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  11889. let pzb = taskMgr.__lastJobId863__
  11890. if (pza !== pzb) {
  11891. mJob = pzb; // set [Interval Meta Update] jobId
  11892. }
  11893.  
  11894. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  11895. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  11896. // } else {
  11897. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  11898. // }
  11899.  
  11900. return res;
  11901.  
  11902. } else {
  11903. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  11904. }
  11905.  
  11906. } catch (e) {
  11907. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  11908. }
  11909.  
  11910.  
  11911. return this.scheduleInitialUpdatedMetadataRequest717();
  11912. }
  11913. }
  11914.  
  11915.  
  11916. });
  11917.  
  11918. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  11919. let dummy;
  11920. let cProto;
  11921. dummy = ytAppDom;
  11922. if (!(dummy instanceof Element)) return;
  11923. cProto = insp(dummy).constructor.prototype;
  11924. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  11925. // console.log(1234, cProto, cProto.is);
  11926. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11927. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  11928. // console.log(123401, arguments);
  11929. // return this.handleServiceRequest717_(a, b, c, d);
  11930. // }
  11931.  
  11932. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11933.  
  11934. // cProto.handleServiceRequest_ = function(a,b,c,d){
  11935. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11936. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  11937. // console.log('mfv', c.continuation);
  11938. // mfv.add( c.continuation);
  11939. // }
  11940. // return this.handleServiceRequest717_(a,b,c,d);
  11941. // }
  11942.  
  11943. function extraArguments322(a, b, c) {
  11944. let is = (a || 0).is;
  11945. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  11946. let continuation = (c || 0).continuation;
  11947. if (typeof is !== 'string') is = null;
  11948. if (typeof videoId !== 'string') videoId = null;
  11949. if (typeof continuation !== 'string') continuation = null;
  11950. return { is, videoId, continuation };
  11951. }
  11952.  
  11953. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  11954. cProto.sendServiceAjax_ = function (a, b, c, d) {
  11955.  
  11956. // console.log(8001)
  11957. try {
  11958.  
  11959. const { is, videoId, continuation } = extraArguments322(a, b, c);
  11960.  
  11961. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11962. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  11963. }
  11964.  
  11965. if (pageSetupVideoId && videoId && continuation) {
  11966. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11967. mfyContinuationIgnored.removeAdd(continuation);
  11968. mfvContinuationRecorded.delete(continuation);
  11969. return;
  11970. }
  11971. }
  11972.  
  11973. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11974. copyPreviousContiuationToIgnored374(false);
  11975. mfyContinuationIgnored.delete(continuation);
  11976. mfvContinuationRecorded.removeAdd(continuation);
  11977. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11978. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11979. mjtLockPreviousKey = '';
  11980. }
  11981. // if (mjtNextMainKey === continuation) {
  11982. // copyPreviousContiuationToIgnored(false);
  11983. // mfyContinuationIgnored.delete(continuation);
  11984. // mfvContinuationRecorded.add(continuation);
  11985. // }
  11986.  
  11987.  
  11988. if (mfyContinuationIgnored && continuation) {
  11989. if (mfyContinuationIgnored.has(continuation)) {
  11990. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  11991. return;
  11992. }
  11993. }
  11994.  
  11995. // console.log(59902, a?.is, b,c,d)
  11996. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11997. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  11998. // console.log('mfv377', continuation);
  11999. mfvContinuationRecorded.add(continuation);
  12000. }
  12001.  
  12002. // if (videoId) {
  12003. // if (!pageSetupVideoId) return; // ignore page not ready
  12004. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12005. // if (videoId !== pageSetupVideoId) {
  12006. // return;
  12007. // }
  12008. // }
  12009.  
  12010. } catch (e) {
  12011. console.log('Coding Error in sendServiceAjax_', e)
  12012. }
  12013. // console.log(8002)
  12014. // console.log(123402, arguments);
  12015. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  12016.  
  12017. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  12018. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  12019. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  12020. // get(target, prop, receiver){
  12021. // console.log('xxs99', target.videoId, mtx)
  12022. // if(prop ==='kdkw33') return 1;
  12023. // console.log(3322, prop, target)
  12024. // if(prop === 'initialDelayMs') {
  12025. // throw new Error("ABCC");
  12026. // }
  12027. // return target[prop];
  12028. // },
  12029. // set(target, prop, value, receiver){
  12030.  
  12031. // if(prop ==='kdkw33') return true;
  12032. // target[prop]=value;
  12033. // return true;
  12034. // }
  12035. // });
  12036. // }
  12037. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  12038. return this.sendServiceAjax717_(a, b, c, d);
  12039. }
  12040. }
  12041.  
  12042. function delayClearOtherKeys(lztContinuation) {
  12043. // // schedule delayed removal if mfyContinuationIgnored is not empty
  12044. // getRafPromise().then(() => {
  12045. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  12046. // // foreground page only
  12047.  
  12048. // });
  12049.  
  12050.  
  12051. if (lztContinuation !== mtzlastAllowedContinuation) return;
  12052. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  12053. if (!mfyContinuationIgnored.size) return;
  12054. if (mfyContinuationIgnored.size > 1) {
  12055. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  12056. }
  12057. mfyContinuationIgnored.forEach((value, key) => {
  12058. if (key !== lztContinuation) {
  12059. mfyContinuationIgnored.delete(key);
  12060. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  12061. }
  12062. });
  12063.  
  12064. }
  12065. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  12066. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  12067. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  12068.  
  12069. // console.log(8003)
  12070. try {
  12071.  
  12072.  
  12073. const { is, videoId, continuation } = extraArguments322(b, c, d);
  12074.  
  12075. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  12076. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  12077. }
  12078.  
  12079. if (pageSetupVideoId && videoId && continuation) {
  12080. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  12081. mfyContinuationIgnored.removeAdd(continuation);
  12082. mfvContinuationRecorded.delete(continuation);
  12083. return;
  12084. }
  12085. }
  12086.  
  12087. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  12088. copyPreviousContiuationToIgnored374(false);
  12089. mfyContinuationIgnored.delete(continuation);
  12090. mfvContinuationRecorded.removeAdd(continuation);
  12091. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  12092. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  12093. mjtLockPreviousKey = '';
  12094. }
  12095.  
  12096. // if (mjtNextMainKey === continuation) {
  12097. // copyPreviousContiuationToIgnored(false);
  12098. // mfyContinuationIgnored.delete(continuation);
  12099. // mfvContinuationRecorded.add(continuation);
  12100. // }
  12101.  
  12102. const lztContinuation = continuation;
  12103.  
  12104. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  12105. if (mfyContinuationIgnored.has(lztContinuation)) {
  12106. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  12107. return;
  12108. }
  12109. }
  12110.  
  12111. // if (videoId) {
  12112. // if (!pageSetupVideoId) return; // ignore page not ready
  12113. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  12114. // if (videoId !== pageSetupVideoId) {
  12115. // return;
  12116. // }
  12117. // }
  12118.  
  12119. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  12120. mtzlastAllowedContinuation = lztContinuation;
  12121. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  12122.  
  12123. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12124. mjtRecordedPrevKey = lztContinuation;
  12125. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  12126. // if (mfyContinuationIgnored.size > 0) {
  12127. // delayClearOtherKeys(lztContinuation);
  12128. // }
  12129. mtzCount = 0;
  12130. // allowNoDelay322 = false;
  12131. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  12132. // repeated
  12133. if (++mtzCount > 1e9) mtzCount = 1e4;
  12134. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  12135.  
  12136. // if (mtzCount >= 3) allowNoDelay322 = true;
  12137. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  12138. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  12139. }
  12140. if (mtzCount === 5) {
  12141. mfvContinuationRecorded.clear();
  12142. mfvContinuationRecorded.add(lztContinuation);
  12143. }
  12144.  
  12145. }
  12146.  
  12147. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  12148. mpKey22 = lztContinuation;
  12149. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  12150. }
  12151.  
  12152. if (mbCId322) {
  12153. clearTimeout(mbCId322);
  12154. mbCId322 = 0;
  12155. }
  12156. } catch (e) {
  12157. console.log('Coding Error in getCancellableNetworkPromise_', e)
  12158. }
  12159.  
  12160. // console.log(8004)
  12161. // console.log(123403, arguments);
  12162. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  12163.  
  12164. // console.log(5163, a?.is,b,c,d,e);
  12165. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  12166. }
  12167. }
  12168. });
  12169.  
  12170. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  12171.  
  12172.  
  12173. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  12174.  
  12175. let dummy;
  12176. let cProto;
  12177.  
  12178. dummy = document.createElement('ytd-expander');
  12179. cProto = insp(dummy).constructor.prototype;
  12180.  
  12181. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  12182.  
  12183. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  12184. cProto.childrenChanged14 = cProto.childrenChanged;
  12185.  
  12186. cProto.initChildrenObserver = function () {
  12187. var a = this;
  12188. this.observer = new MutationObserver(function () {
  12189. a.childrenChanged()
  12190. }
  12191. );
  12192. this.observer.observe(this.content, {
  12193. subtree: !0,
  12194. childList: !0,
  12195. attributes: !0,
  12196. characterData: !0
  12197. });
  12198. this.childrenChanged()
  12199. }
  12200. ;
  12201. cProto.childrenChanged = function () {
  12202. if (this.alwaysToggleable) {
  12203. this.canToggle = this.alwaysToggleable;
  12204. } else if (!this.canToggleJobId) {
  12205. this.canToggleJobId = 1;
  12206. foregroundPromiseFn().then(() => {
  12207. this.canToggleJobId = 0;
  12208. this.calculateCanCollapse()
  12209. })
  12210. }
  12211. }
  12212.  
  12213. // console.log(cProto.initChildrenObserver)
  12214. console.debug('ytd-expander-fix-childrenChanged');
  12215.  
  12216. }
  12217.  
  12218. });
  12219.  
  12220.  
  12221. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  12222.  
  12223. let dummy;
  12224. let cProto;
  12225. dummy = document.createElement('paper-ripple');
  12226. cProto = insp(dummy).constructor.prototype;
  12227.  
  12228. if (fnIntegrity(cProto.animate, '0.74.5')) {
  12229.  
  12230.  
  12231. cProto.animate34 = cProto.animate;
  12232. cProto.animate = function () {
  12233. if (this._animating) {
  12234. var a;
  12235. const ripples = this.ripples;
  12236. for (a = 0; a < ripples.length; ++a) {
  12237. var b = ripples[a];
  12238. b.draw();
  12239. this.$.background.style.opacity = b.outerOpacity;
  12240. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  12241. }
  12242. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  12243. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  12244. foregroundPromiseFn().then(this._boundAnimate38);
  12245. } else {
  12246. this.onAnimationComplete();
  12247. }
  12248. }
  12249. }
  12250.  
  12251. console.debug('FIX_paper_ripple_animate')
  12252.  
  12253. // console.log(cProto.animate)
  12254.  
  12255. }
  12256.  
  12257. });
  12258.  
  12259. if (FIX_doIdomRender) {
  12260.  
  12261. const xsetTimeout = function (f, d) {
  12262. if (xsetTimeout.m511 === 1 && !d) {
  12263. xsetTimeout.m511 = 2;
  12264. xsetTimeout.m568 = f;
  12265. } else {
  12266. return setTimeout.apply(window, arguments)
  12267. }
  12268.  
  12269. }
  12270.  
  12271. /**
  12272. *
  12273. IGb = function(a) {
  12274. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  12275. c || (a.requestAninmationFrameResolver = new Vi,
  12276. c = a.requestAninmationFrameResolver.promise,
  12277. Da.requestAnimationFrame(function() {
  12278. var d;
  12279. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  12280. a.requestAninmationFrameResolver = null
  12281. }));
  12282. return c
  12283. }
  12284.  
  12285.  
  12286. */
  12287.  
  12288. const xrequestAnimationFrame = function (f) {
  12289. const h = `${f}`;
  12290. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  12291. let t = null;
  12292. xsetTimeout.m511 = 1;
  12293. f();
  12294. if (xsetTimeout.m511 === 2) {
  12295. t = xsetTimeout.m568;
  12296. xsetTimeout.m568 = null;
  12297. }
  12298. xsetTimeout.m511 = 0;
  12299. if (typeof t === 'function') {
  12300. foregroundPromiseFn().then(t);
  12301. }
  12302. } else if (h.includes("requestAninmationFrameResolver")) {
  12303. foregroundPromiseFn().then(f);
  12304. } else {
  12305. return requestAnimationFrame.apply(window, arguments);
  12306. }
  12307. }
  12308.  
  12309. let busy = false;
  12310. const doIdomRender = function () {
  12311.  
  12312. if (!this) return;
  12313. if (busy) {
  12314. return this.doIdomRender13(...arguments);
  12315. }
  12316. busy = true;
  12317. const { requestAnimationFrame, setTimeout } = window;
  12318. window.requestAnimationFrame = xrequestAnimationFrame;
  12319. window.setTimeout = xsetTimeout;
  12320. let r = this.doIdomRender13(...arguments);
  12321. window.requestAnimationFrame = requestAnimationFrame;
  12322. window.setTimeout = setTimeout;
  12323. busy = false;
  12324. return r;
  12325. };
  12326. for (const ytTag of ['ytd-lottie-player', 'yt-attributed-string', 'yt-image', 'yt-icon-shape', 'yt-button-shape', 'yt-button-view-model', 'yt-icon-badge-shape']) {
  12327.  
  12328.  
  12329. whenCEDefined(ytTag).then(() => {
  12330.  
  12331. let dummy;
  12332. let cProto;
  12333. dummy = document.createElement(ytTag);
  12334. cProto = insp(dummy).constructor.prototype;
  12335.  
  12336. cProto.doIdomRender13 = cProto.doIdomRender;
  12337. cProto.doIdomRender = doIdomRender;
  12338.  
  12339. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  12340.  
  12341. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  12342.  
  12343.  
  12344.  
  12345. });
  12346.  
  12347. }
  12348.  
  12349. }
  12350.  
  12351.  
  12352.  
  12353.  
  12354. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  12355.  
  12356. const sMap = new Map();
  12357.  
  12358. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  12359. const ZT = function () {
  12360. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  12361. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  12362. c = b & 15,
  12363. b >>= 4,
  12364. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  12365. return a.join("")
  12366. };
  12367.  
  12368.  
  12369. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  12370.  
  12371. const popupContainer = await observablePromise(() => {
  12372. return popupContainerCollection[0];
  12373. }).obtain();
  12374.  
  12375.  
  12376. let cProto;
  12377. cProto = insp(popupContainer).constructor.prototype;
  12378.  
  12379.  
  12380. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  12381. console.log('FIX_POPUP_UNIQUE_ID NG')
  12382. return;
  12383. }
  12384. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  12385.  
  12386. cProto.handleOpenPopupAction = function (a, b) {
  12387.  
  12388. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  12389.  
  12390. a.__jOdQA__ = true;
  12391.  
  12392. try {
  12393.  
  12394. const h = this.hostElement;
  12395.  
  12396. if (h instanceof HTMLElement_) {
  12397.  
  12398. const map = h.__skme44__ = h.__skme44__ || new Map();
  12399.  
  12400. let mKey = '';
  12401. const wKey = firstObjectKey(a);
  12402. const wObj = wKey ? a[wKey] : null;
  12403. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  12404. const pKey = firstObjectKey(wObj.popup)
  12405. const pObj = pKey ? wObj.popup[pKey] : null;
  12406. let contentKey = '';
  12407. let headerKey = '';
  12408.  
  12409. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  12410. contentKey = firstObjectKey(pObj.content)
  12411. headerKey = firstObjectKey(pObj.header)
  12412. }
  12413. if (contentKey && headerKey) {
  12414.  
  12415. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  12416.  
  12417. if (mKey) {
  12418.  
  12419. if (!wObj.uniqueId) {
  12420. for (let i = 0; i < 8; i++) {
  12421. wObj.uniqueId = ZT();
  12422. if (!sMap.has(wObj.uniqueId)) break;
  12423. }
  12424. }
  12425. const oId = wObj.uniqueId
  12426.  
  12427. let nId_ = map.get(mKey);
  12428. if (!nId_) {
  12429. map.set(mKey, nId_ = oId);
  12430. }
  12431.  
  12432. wObj.uniqueId = nId_ || wObj.uniqueId;
  12433.  
  12434. const nId = wObj.uniqueId
  12435.  
  12436. sMap.set(oId, nId);
  12437. sMap.set(nId, nId);
  12438.  
  12439. wObj.uniqueId = nId;
  12440. pObj.targetId = nId;
  12441. pObj.identifier.tag = nId;
  12442.  
  12443. if (oId !== nId) {
  12444. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  12445. }
  12446.  
  12447. }
  12448.  
  12449. }
  12450. }
  12451.  
  12452. // console.log(12213, mKey, a, b, h)
  12453.  
  12454. }
  12455.  
  12456. } catch (e) {
  12457. console.warn(e)
  12458. }
  12459.  
  12460. try {
  12461.  
  12462. const results = searchNestedObject(a, (x) => {
  12463. if (typeof x === 'string' && x.length === 36) {
  12464. if (/[a-zA-Z\d]{8}-[a-zA-Z\d]{4}-[a-zA-Z\d]{4}-[a-zA-Z\d]{4}-[a-zA-Z\d]{12}/.test(x)) return true;
  12465. }
  12466. return false;
  12467. });
  12468. for (const [obj, key] of results) {
  12469. const oId = obj[key];
  12470. const nId = sMap.get(oId);
  12471. if (nId) obj[key] = nId;
  12472. }
  12473. } catch (e) {
  12474. console.warn(e)
  12475. }
  12476.  
  12477.  
  12478. }
  12479.  
  12480. return this.handleOpenPopupAction3868(...arguments)
  12481. }
  12482.  
  12483. console.log('FIX_POPUP_UNIQUE_ID OK')
  12484.  
  12485.  
  12486. });
  12487.  
  12488.  
  12489. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  12490.  
  12491. let dummy;
  12492. let cProto;
  12493. dummy = document.createElement('yt-formatted-string');
  12494. cProto = insp(dummy).constructor.prototype;
  12495.  
  12496. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  12497. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  12498. return;
  12499. }
  12500.  
  12501. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  12502. cProto.setNodeStyle_ = function (a, b) {
  12503. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  12504. return this.setNodeStyle17_(a, b);
  12505. }
  12506.  
  12507. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  12508. });
  12509.  
  12510. });
  12511.  
  12512. });
  12513.  
  12514.  
  12515.  
  12516.  
  12517. if (isMainWindow) {
  12518.  
  12519. console.groupCollapsed(
  12520. "%cYouTube JS Engine Tamer",
  12521. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  12522. );
  12523.  
  12524.  
  12525.  
  12526. console.log("Script is loaded.");
  12527. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  12528.  
  12529. console.log("This script is experimental and subject to further changes.");
  12530.  
  12531. console.log("This might boost your YouTube performance.");
  12532.  
  12533. console.log("CAUTION: This might break your YouTube.");
  12534.  
  12535.  
  12536. if (prepareLogs.length >= 1) {
  12537. console.log(" =========================================================================== ");
  12538.  
  12539. for (const msg of prepareLogs) {
  12540. console.log(msg)
  12541. }
  12542.  
  12543. console.log(" =========================================================================== ");
  12544. }
  12545.  
  12546. console.groupEnd();
  12547.  
  12548. }
  12549.  
  12550.  
  12551.  
  12552. })();

QingJ © 2025

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