YouTube JS Engine Tamer

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

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

  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.36.4
  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 NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  35. const FIX_schedulerInstanceInstance = 2 | 4;
  36. const FIX_yt_player = true; // DONT CHANGE
  37. const FIX_Animation_n_timeline = true;
  38. const FIX_Animation_n_timeline_cinematic = true;
  39. const FIX_ytScheduler = true;
  40. const NO_PRELOAD_GENERATE_204 = false;
  41. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  42. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  43. const CHANGE_appendChild = true; // discussions#236759
  44. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  45. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  46.  
  47. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  48. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  49. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  50.  
  51. const FIX_Iframe_NULL_SRC = false;
  52.  
  53. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  54.  
  55. const FIX_ytdExpander_childrenChanged = true;
  56. const FIX_paper_ripple_animate = true;
  57. const FIX_avoid_incorrect_video_meta = false; // omit the incorrect yt-animated-rolling-number // 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  58. const FIX_avoid_incorrect_video_meta_emitterBehavior = false; // 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  59.  
  60. const FIX_doIdomRender = true;
  61.  
  62. const FIX_Shady = true;
  63.  
  64. // [[ 2024.04.24 ]]
  65. const MODIFY_ShadyDOM_OBJ = true;
  66. // << if MODIFY_ShadyDOM_OBJ >>
  67. const WEAKREF_ShadyDOM = true;
  68. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  69. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  70. // << end >>
  71.  
  72. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  73.  
  74. const FIX_ytAction_ = true; // ytd-app
  75. const FIX_onVideoDataChange = false;
  76. // const FIX_onClick = true;
  77. const FIX_onStateChange = true;
  78. const FIX_onLoopRangeChange = true;
  79. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  80. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  81.  
  82. const ENABLE_discreteTasking = false; // removed since 0.20.0
  83. const FIX_stampDomArray_ = true; // v0.30.0
  84. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  85. // const stampDomArray_MemoryFix_Flag001 = false;
  86. const XFlag = true; // root issue tbc
  87. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  88. // 32 required for new stampDomArray
  89. // 128 to be tested
  90.  
  91. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  92. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  93.  
  94. const FIX_Polymer_dom = true;
  95. const FIX_Polymer_AF = true;
  96.  
  97. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  98. const DEBUG_removePrune = false; // true for DEBUG
  99.  
  100. const FIX_XHR_REQUESTING = true;
  101.  
  102. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  103.  
  104. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  105.  
  106. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  107. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  108.  
  109. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  110.  
  111. const FIX_removeChild = true;
  112. const FIX_fix_requestIdleCallback_timing = true;
  113.  
  114. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  115. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  116.  
  117. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  118.  
  119. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  120.  
  121. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  122. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  123. // first tp-yt-paper-dialog: show once the page is loaded.
  124. // second tp-yt-paper-dialog: click "...more"
  125. // third tp-yt-paper-dialog: click "... and 3 more links"
  126. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  127. // currently, uniqueId is preassigned by the network resolveCommand.
  128. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  129. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  130.  
  131. // handleOpenPopupAction -> createCacheKey
  132. // handleClosePopupAction_ -> createCacheKey
  133. // handleGetPopupOpenedAction_ -> createCacheKey
  134. // getAndMaybeCreatePopup_ -> createCacheKey
  135. // closePopup -> createCacheKey
  136.  
  137. // yt-close-popup-command -> handleClosePopupCommand_
  138.  
  139. // ensurePopup_ -> getAndMaybeCreatePopup_
  140.  
  141. // yt-close-popup-action -> handleClosePopupAction_
  142. // closePopup -> handleClosePopupAction_
  143. // handleOpenPopupAction -> handleClosePopupAction_
  144. // handleClosePopupCommand_ -> handleClosePopupAction_
  145. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  146.  
  147. // yt-open-popup-action -> handleOpenPopupAction
  148.  
  149.  
  150. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  151. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  152.  
  153. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  154. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  155. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  156.  
  157.  
  158. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  159. const FIX_DOM_IF_TEMPLATE = true;
  160. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  161. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  162. const DEBUG_DBR847 = false;
  163. const DEBUG_xx847 = false;
  164. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  165. const DEBUG_renderDebounceTs = false;
  166.  
  167. const FIX_ICON_RENDER = true;
  168.  
  169. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  170.  
  171. /*
  172.  
  173. FIX_DOM_IFREPEAT_RenderDebouncerChange
  174.  
  175. avoid Polymer.flush
  176. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  177.  
  178. var Is = function() {
  179. do {
  180. var a = window.ShadyDOM && ShadyDOM.flush();
  181. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  182. var b = NNa()
  183. } while (a || b)
  184. };
  185.  
  186. , NNa = function() {
  187. var a = !!ts.size;
  188. ts.forEach(function(b) {
  189. try {
  190. b.flush()
  191. } catch (c) {
  192. setTimeout(function() {
  193. throw c
  194. })
  195. }
  196. });
  197. return a
  198. };
  199.  
  200. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  201. // this coding logic should be incorrect (mistake).
  202.  
  203. */
  204.  
  205.  
  206.  
  207. // ----------------------------- Shortkey Keyboard Control -----------------------------
  208. // dependency: FIX_yt_player
  209.  
  210. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  211. // [0] no fix - not recommended
  212. // [1] basic fix - just fix the global focus detection variable
  213. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  214. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  215.  
  216. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  217. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  218.  
  219. const PROP_OverReInclusion_AVOID = true;
  220. const PROP_OverReInclusion_DEBUGLOG = false;
  221. const PROP_OverReInclusion_LIST = new Set([
  222. 'hostElement72',
  223. 'parentComponent72',
  224. 'localVisibilityObserver_72',
  225. 'cachedProviderNode_72',
  226. '__template72',
  227. '__templatizeOwner72',
  228. '__templateInfo72',
  229. '__dataHost72',
  230. '__CE_shadowRoot72',
  231. 'elements_72',
  232.  
  233. 'ky36',
  234. 'kz62',
  235. 'm822',
  236.  
  237.  
  238.  
  239. // To be reviewed.
  240.  
  241. // chat messages
  242. 'disabled', 'allowedProps',
  243. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  244.  
  245. 'dimension', 'loadTime', 'pendingPaint',
  246.  
  247. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  248.  
  249. 'respectLangDir', 'noEndpoints',
  250.  
  251.  
  252. 'objectURL',
  253. 'buttonOverrides', 'queuedMessages',
  254. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  255. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  256. 'hoverJobId', 'JSC$14573_touched',
  257.  
  258.  
  259. // tbc
  260. 'toggleable', 'isConnected',
  261. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  262. 'disableDeselectEvent',
  263. 'emojiSize',
  264.  
  265. 'buttonOverride',
  266. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  267.  
  268. // others
  269. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  270. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  271. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  272. // 'dimension', 'loadTime', 'pendingPaint',
  273. // 'disabled', 'allowedProps',
  274.  
  275.  
  276. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  277. // 'actionMap',
  278.  
  279. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  280.  
  281. 'clearTimeout',
  282. 'switchTemplateAtRegistration', 'hasUnmounted',
  283. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  284. 'tangoConfiguration',
  285. 'itemIdToDockDurationMap',
  286. 'actionMap',
  287.  
  288. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  289. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  290. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  291.  
  292. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  293. // 'stopKeyboardEventPropagation', 'emojiSize',
  294. // 'switchTemplateAtRegistration', 'hasUnmounted',
  295. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  296. // 'isReusable', 'tangoConfiguration',
  297. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  298. // */
  299.  
  300. ]);
  301.  
  302.  
  303. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  304.  
  305. // ----------------------------- Shortkey Keyboard Control -----------------------------
  306.  
  307. /*
  308. window.addEventListener('edm',()=>{
  309. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  310. });
  311.  
  312. window.addEventListener('edn',()=>{
  313. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  314. });
  315. window.addEventListener('edr',()=>{
  316. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  317. });
  318. */
  319.  
  320. // only for macOS with Chrome/Firefox 100+
  321. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  322.  
  323. const win = this instanceof Window ? this : window;
  324.  
  325. // Create a unique key for the script and check if it is already running
  326. const hkey_script = 'jswylcojvzts';
  327. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  328. win[hkey_script] = true;
  329.  
  330.  
  331.  
  332. const wk = Symbol();
  333.  
  334. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  335.  
  336. let BY_PASS_KEYBOARD_CONTROL = false;
  337.  
  338.  
  339. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  340. /** @type {(f: ()=>{})=>{}} */
  341. const nextBrowserTick_ = nextBrowserTick;
  342. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  343. console.log('nextBrowserTick is not found.');
  344. return;
  345. }
  346.  
  347. let p59 = 0;
  348.  
  349. const Promise = (async () => { })().constructor;
  350.  
  351. const PromiseExternal = ((resolve_, reject_) => {
  352. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  353. return class PromiseExternal extends Promise {
  354. constructor(cb = h) {
  355. super(cb);
  356. if (cb === h) {
  357. /** @type {(value: any) => void} */
  358. this.resolve = resolve_;
  359. /** @type {(reason?: any) => void} */
  360. this.reject = reject_;
  361. }
  362. }
  363. };
  364. })();
  365.  
  366. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  367. constructor(callback = undefined) {
  368.  
  369. }
  370. register(target, heldValue, unregisterToken = undefined) {
  371.  
  372. }
  373. unregister(unregisterToken) {
  374.  
  375. }
  376. }
  377.  
  378. let ttpHTML = (s) => {
  379. ttpHTML = s => s;
  380. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  381. let s = s => s;
  382. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  383. }
  384. return s;
  385. }
  386.  
  387.  
  388. /** @type { typeof HTMLElement } */
  389. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  390. const nativeAppendE = HTMLElement_.prototype.append;
  391. const nativeRemoveE = HTMLElement_.prototype.remove;
  392. const DocumentFragment_ = DocumentFragment;
  393. const nativeAppendD = DocumentFragment_.prototype.append;
  394. const Node_ = Node;
  395.  
  396. /**
  397. @param {number} x
  398. @param {number} d */
  399. const toFixed2 = (x, d) => {
  400. let t = x.toFixed(d);
  401. let y = `${+t}`;
  402. return y.length > t.length ? t : y;
  403. }
  404.  
  405.  
  406. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  407.  
  408.  
  409. const TRANSLATE_DEBUG = false;
  410.  
  411.  
  412. let xdeadc00 = null; // a deteched node with __domApi
  413. let xlivec00 = null; // a deteched node with __domApi
  414.  
  415. let removeTNodeRM = null;
  416. let removeTNodeBP = false;
  417.  
  418.  
  419.  
  420.  
  421. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  422.  
  423. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  424.  
  425. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  426.  
  427. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  428.  
  429.  
  430. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  431. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  432. return;
  433. }
  434.  
  435.  
  436. const mapGet = Map.prototype.get;
  437. const setHas = Set.prototype.has;
  438.  
  439.  
  440. /** @type {Map | null} */
  441. let qcMap = null;
  442.  
  443. Set.prototype.has = function (a) {
  444. if (a === 'dummy-4718') return false; // false to allow re-use?
  445. return setHas.call(this, a);
  446. }
  447.  
  448. Map.prototype.get = function (a) {
  449. if (a === 'dummy-4718') qcMap = this;
  450. return mapGet.call(this, a);
  451. };
  452. let r;
  453. try {
  454. r = mainCnt.createComponent_('dummy-4718', {}, true);
  455. } catch (e) {
  456.  
  457. }
  458.  
  459. Map.prototype.get = mapGet;
  460. Set.prototype.has = setHas;
  461.  
  462. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  463.  
  464.  
  465. // clearInterval(ckId);
  466. // ckId = 0;
  467.  
  468. if (qcMap !== null && qcMap instanceof Map) {
  469.  
  470. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  471. qcMap.__qcMap8781__ = true;
  472.  
  473. const setArrayC = (c) => {
  474. if (c instanceof Array) {
  475. c.length = 0;
  476. c.push = function () { };
  477. c.pop = function () { };
  478. c.shift = function () { };
  479. c.unshift = function () { };
  480. c.splice = function () { };
  481. c.sort = function () { };
  482. c.reverse = function () { };
  483. }
  484. }
  485.  
  486. const cleaning = function (m) {
  487. m.forEach(setArrayC);
  488. m.clear();
  489. }
  490.  
  491. qcMap.set = function (b, c) {
  492. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  493.  
  494. setArrayC(c);
  495.  
  496. // console.log('qcMap.set', b, c);
  497.  
  498. if (this.size > 0) {
  499. // play safe
  500.  
  501. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  502. cleaning(this);
  503. }
  504.  
  505. }
  506. qcMap.get = function (b) {
  507. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  508.  
  509. // console.log('qcMap.get', b);
  510.  
  511. if (this.size > 0) {
  512. // play safe
  513.  
  514. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  515. cleaning(this);
  516. }
  517.  
  518. }
  519.  
  520.  
  521. if (qcMap.size > 0) {
  522.  
  523. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  524. cleaning(qcMap);
  525. }
  526.  
  527. }
  528.  
  529. }
  530.  
  531. r = null;
  532. qcMap = null;
  533.  
  534. }
  535.  
  536.  
  537. const dispatchYtEvent = function (a, b, c, d) {
  538. d || (d = {
  539. bubbles: !0,
  540. cancelable: !1,
  541. composed: !0
  542. });
  543. c !== null && c !== void 0 && (d.detail = c);
  544. b = new CustomEvent(b, d);
  545. a.dispatchEvent(b);
  546. return b
  547. };
  548.  
  549.  
  550. if (XFlag) {
  551.  
  552. const cMap = new Set();
  553. cMap.add = cMap.addOriginal || cMap.add;
  554. const yMap = new Set();
  555. yMap.add = yMap.addOriginal || yMap.add;
  556.  
  557.  
  558. const ydMap = new Set();
  559. ydMap.add = ydMap.addOriginal || ydMap.add;
  560.  
  561. window.yMap = yMap;
  562. window.cMap = cMap;
  563. window.ydMap = ydMap;
  564.  
  565. const constructAts = new Set();
  566. constructAts.add = constructAts.addOriginal || constructAts.add;
  567. window.constructAts = constructAts;
  568.  
  569. const kMap = new WeakMap();
  570.  
  571. const kRefProp = (wr, prop)=>{
  572. let o = kRef(wr);
  573. return o ? o[prop] : null;
  574. }
  575.  
  576. const wrObj = (objRef, props) => {
  577. let wr = mWeakRef(objRef);
  578. if (wr === objRef || !props || !props.length) return wr;
  579. let properties = {};
  580. props.forEach(k => {
  581. properties[k] = {
  582. get() {
  583. return kRefProp(this, k)
  584. },
  585. enumerable: false,
  586. configurable: true
  587. };
  588. });
  589. Object.defineProperties(wr, properties);
  590. return wr;
  591. }
  592.  
  593. const sProtos = {};
  594.  
  595. const setupCProto = function (cProto) {
  596.  
  597. if(cProto === Object.prototype) return;
  598.  
  599. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  600. cProto[kMap.get(cProto)] = true;
  601. // debugger;
  602.  
  603. 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];
  604. constructAts.add(constructAt)
  605.  
  606. if (MemoryFix_Flag002 & 32) {
  607. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  608. fixDetachFn(cProto);
  609. }
  610. }
  611.  
  612. if (MemoryFix_Flag002 & 2) {
  613. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  614. cProto.__setPropDX38__ = true;
  615.  
  616. if (cProto._setPendingProperty.length === 3) {
  617. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  618. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  619. return () => {
  620. const obj = kRef(wobj);
  621. let u = Reflect.apply(this, obj, args);
  622. args.length = 0;
  623. wobj = null;
  624. return u;
  625. };
  626. });
  627. }
  628.  
  629. }
  630. }
  631.  
  632. if (MemoryFix_Flag002 & 4) {
  633. if (cProto._runEffectsForTemplate && !cProto.__runEffectDX38__) {
  634. cProto.__runEffectDX38__ = true;
  635.  
  636. if (cProto._runEffectsForTemplate.length === 4) {
  637. cProto._runEffectsForTemplate3858 = cProto._runEffectsForTemplate;
  638. cProto._runEffectsForTemplate = sProtos._runEffectsForTemplate || (sProtos._runEffectsForTemplate = function (c, d, e, g) {
  639. if (c && c.runEffects) {
  640. let wr = wrObj(c, ['propertyEffects', 'nodeList', 'firstChild']);
  641. // console.log(12837)
  642. if (!this[wk]) this[wk] = mWeakRef(this);
  643. if ((typeof (e || 0) === "object") && !e[wk]) e[wk] = mWeakRef(e);
  644. let cntWr = this[wk];
  645. let eWr = (typeof (e || 0) === "object") ? e[wk] : e;
  646. c.runEffects((n, r) => {
  647. // console.log(12838)
  648. const cnt = kRef(cntWr);
  649. const e = kRef(eWr);
  650. if (cnt) {
  651. cnt._runEffectsForTemplate3858(wr, n, e, r);
  652. }
  653. wr = cntWr = d = e = g = null;
  654. }, d, g);
  655. } else {
  656. let { propertyEffects, nodeList, firstChild } = c;
  657. let o = { propertyEffects, nodeList, firstChild }
  658. this._runEffectsForTemplate3858(o, d, e, g);
  659. o.propertyEffects = o.nodeList = o.firstChild = null;
  660. propertyEffects = nodeList = firstChild = null;
  661. o = null;
  662. }
  663.  
  664. });
  665.  
  666. cProto._runEffectsForTemplate.bind = sProtos._runEffectsForTemplate$bind || (sProtos._runEffectsForTemplate$bind = function (obj, ...args) {
  667. // console.log(12993, args)
  668. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  669. return () => {
  670. const obj = kRef(wobj);
  671. let u = Reflect.apply(this, obj, args);
  672. args.length = 0;
  673. wobj = null;
  674. return u;
  675. };
  676. });
  677. }
  678.  
  679. }
  680. }
  681.  
  682.  
  683.  
  684.  
  685.  
  686. const cProtoConstructor = cProto.constructor;
  687.  
  688. if (MemoryFix_Flag002 & 8) {
  689. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  690. cProtoConstructor.__parseBindingsDX38__ = true;
  691.  
  692. ydMap.add(cProtoConstructor);
  693.  
  694. if (cProtoConstructor._parseBindings.length === 2) {
  695.  
  696. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  697.  
  698. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  699. let p = this._parseBindings3858(c, d);
  700. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  701. if (p) this.__bindingsArrs__.push(p);
  702. return p;
  703. });
  704.  
  705. }
  706. }
  707. }
  708.  
  709. /*
  710. a.prototype._initializeProperties = function() {
  711. if (Em && this.hasAttribute("disable-upgrade"))
  712. this.__isUpgradeDisabled = !0;
  713. else {
  714. var e = Object.getPrototypeOf(this);
  715. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  716. e.__hasRegisterFinished = !0);
  717. b.prototype._initializeProperties.call(this);
  718. this.root = this;
  719. this.created();
  720. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  721. this._applyListeners()
  722. }
  723. }
  724. */
  725. /*
  726. bOa = function(a, b, c) {
  727. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  728. d.prototype.is = b;
  729. d.prototype.localName = b;
  730. c && aOa(d, c);
  731. return function(e) {
  732. e && (d.prototype.hostElement = e);
  733. var g = new d;
  734. g.root = g;
  735. g.hostElement = e;
  736. return g
  737. }
  738. }
  739. */
  740.  
  741.  
  742. }
  743. const symDH = Symbol();
  744.  
  745. const wfStore = new WeakMap();
  746.  
  747. const wrapF = function (f, key) {
  748. if (wfStore.get(f)) return wfStore.get(f);
  749.  
  750. let g = function () {
  751. const o = kRef(this);
  752. if (!o) return;
  753. const cnt = insp(o);
  754. // if (cnt === o) return;
  755. // if (!('ready' in cnt)) return;
  756. return f.apply(o, arguments);
  757. };
  758. g.key38 = key;
  759. g.originalFunc38 = f;
  760. g.__wrapF84__ = true;
  761. wfStore.set(f, g);
  762. wfStore.set(g, g);
  763. return g;
  764. };
  765.  
  766. if (MemoryFix_Flag002 & 16) {
  767. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  768.  
  769. Object.defineProperty(Node.prototype, key, {
  770. get() {
  771. return this[`__a0939${key}__`];
  772. },
  773. set(nv) {
  774. if (typeof nv !== 'function') return;
  775. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  776. this[`__a0939${key}__`] = g;
  777. return true;
  778. }
  779. });
  780.  
  781.  
  782. });
  783. }
  784.  
  785.  
  786. const fragQ = document.createDocumentFragment(); // for cleaup removal
  787.  
  788. const wm = new WeakMap();
  789.  
  790. const fixDetachFn = (tpProto) => { // & 32
  791.  
  792. if (tpProto.dk322) return;
  793. tpProto.dk322 = true;
  794.  
  795. tpProto.__detachInstance994 = tpProto.__detachInstance;
  796. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  797. tpProto.__detachInstance = function (a) {
  798. const u = this.__instances[a];
  799. if (!u.root) {
  800. const uRoot = kRef(wm.get(u));
  801. if (uRoot) u.root = uRoot;
  802. }
  803. let P, ok = false;
  804. try {
  805. this.__detachInstance994(a);
  806. ok = true;
  807. } catch (e) { }
  808. return u;
  809. }
  810. }
  811.  
  812. tpProto.__attachInstance994 = tpProto.__attachInstance;
  813. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  814. tpProto.__attachInstance = function (a, b) {
  815. const u = this.__instances[a];
  816. if (u && u.root && b) {
  817. const root = u.root;
  818. if (!root[wk]) root[wk] = mWeakRef(root);
  819. wm.set(u, root[wk]);
  820. fragQ.appendChild(root); // for cleanup
  821. return this.__attachInstance994(a, b);
  822. }
  823. }
  824. }
  825.  
  826. }
  827. // const fixDetachFn = (tpProto) => { // & 32
  828.  
  829. // if (tpProto.dk322) return;
  830. // tpProto.dk322 = true;
  831.  
  832. // tpProto.__detachInstance994 = tpProto.__detachInstance;
  833. // if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  834. // tpProto.__detachInstance = function (a) {
  835. // const u = this.__instances[a];
  836. // if (u && u.root) {
  837. // const children = u ? u.children : null;
  838. // if (children && children.length >= 1) {
  839. // this.__detachInstance994(a);
  840. // }
  841. // } else if (u && !u.root) {
  842. // const children = u ? u.children : null;
  843. // if (children && children.length >= 1) {
  844. // for (let i = 0, l = children.length; i < l; i++) {
  845. // const node = children[i];
  846. // fragQ.appendChild(node); // for cleanup
  847. // Promise.resolve(node).then(node => (node.parentNode === fragQ) && !!node.remove());
  848. // }
  849. // }
  850. // }
  851. // return u;
  852. // }
  853. // }
  854.  
  855.  
  856.  
  857. // tpProto.__attachInstance994 = tpProto.__attachInstance;
  858. // if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  859. // tpProto.__attachInstance = function (a, b) {
  860. // const u = this.__instances[a];
  861. // if (u && u.root && b) {
  862. // fragQ.appendChild(u.root); // for cleanup
  863. // return this.__attachInstance994(a, b);
  864. // }
  865. // }
  866. // }
  867.  
  868. // }
  869. const ytTemplateDomEntry = (tpProto) => {
  870.  
  871. console.log('ytTemplateDomEntry triggered')
  872.  
  873.  
  874. const convertToWeakArr = (arr) => {
  875.  
  876.  
  877. if (arr.isWeak) return;
  878.  
  879. for (let i = 0, l = arr.length; i < l; i++) {
  880. const o = arr[i]
  881. if (o) {
  882. let p = kRef(o)
  883. if (!p) arr[i] = null;
  884. else {
  885. if (!o[wk]) o[wk] = mWeakRef(o);
  886. arr[i] = o[wk];
  887. }
  888. }
  889. }
  890. arr.isWeak = true;
  891.  
  892. }
  893.  
  894. const convertToNormalArr = (arr) => {
  895.  
  896. if (!arr.isWeak) return;
  897.  
  898. for (let i = 0, l = arr.length; i < l; i++) {
  899. const o = arr[i]
  900. if (o) {
  901. let p = kRef(o)
  902. arr[i] = p;
  903. }
  904. }
  905. arr.isWeak = false;
  906.  
  907. }
  908.  
  909. if (MemoryFix_Flag002 & 256) {
  910. Object.defineProperty(tpProto, '__instances', {
  911. get() {
  912. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  913. let arr = this.__instances_actual471__;
  914. convertToNormalArr(arr);
  915. Promise.resolve(arr).then(convertToWeakArr);
  916. return arr;
  917. },
  918. set(nv) {
  919. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  920. this.__instances_actual471__ = nv;
  921. Promise.resolve(nv).then(convertToWeakArr);
  922. return true;
  923. },
  924. enumerable: false,
  925. configurable: true
  926. });
  927. }
  928.  
  929. // console.log(91901, tpProto.__detachInstance)
  930. if (MemoryFix_Flag002 & 32) {
  931. if (tpProto.__detachInstance) {
  932. fixDetachFn(tpProto);
  933. } else {
  934. Promise.resolve(tpProto).then((tpProto) => {
  935. // console.log(91902, tpProto.__detachInstance)
  936. fixDetachFn(tpProto);
  937. })
  938. }
  939. }
  940.  
  941. }
  942.  
  943. if (MemoryFix_Flag002 & 32) {
  944. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  945. set(nv) {
  946. if (nv === true) return false;
  947. tpProto = this;
  948. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  949. tpProto.__domDX37__ = true;
  950. ytTemplateDomEntry(tpProto);
  951. }
  952. this.__ensureTemplatized949__ = nv;
  953. return true;
  954. },
  955. get() {
  956. return this.__ensureTemplatized949__;
  957. }
  958. });
  959. }
  960.  
  961.  
  962. if (MemoryFix_Flag002 & 64) {
  963. HTMLElement_.prototype.__dataHostBinding374 = true;
  964. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  965. get() {
  966. return kRef(this.__dataHostWr413__);
  967. },
  968. set(nv) {
  969. if (nv && typeof nv === 'object' && !nv.deref) {
  970. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  971. nv = nv[wk];
  972. }
  973. this.__dataHostWr413__ = nv;
  974. return true;
  975. }
  976. });
  977. }
  978.  
  979.  
  980. const setupYProto = function (yProto) {
  981.  
  982. if(yProto === Object.prototype) return;
  983.  
  984. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  985. yProto[kMap.get(yProto)] = true;
  986.  
  987. if (MemoryFix_Flag002 & 32) {
  988. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  989. fixDetachFn(yProto);
  990. }
  991. }
  992.  
  993. if (MemoryFix_Flag002 & 128) {
  994. if (!yProto.__dataHostBinding374) {
  995. yProto.__dataHostBinding374 = true;
  996. Object.defineProperty(yProto, '__dataHost', {
  997. set(nv) {
  998. let dh = nv;
  999. if (dh && typeof dh === 'object' && !dh.deref) {
  1000. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  1001. dh = wr;
  1002. }
  1003. this[symDH] = dh;
  1004. return true;
  1005. },
  1006. get() {
  1007. let wr = this[symDH];
  1008. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  1009. return obj;
  1010. },
  1011. enumerable: false,
  1012. configurable: true
  1013. });
  1014. }
  1015.  
  1016.  
  1017.  
  1018. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  1019. yProto._registerHostDX38__ = true;
  1020.  
  1021. // yProto._registerHost7133 = yProto._registerHost;
  1022.  
  1023. yProto.__enableOrFlushClients = function () {
  1024. const c_ = this.__dataPendingClients;
  1025. if (c_) {
  1026. const c = c_.slice();
  1027. c_.length = 0;
  1028. for (let d = 0, l = c.length; d < l; d++) {
  1029. let e = kRef(c[d]);
  1030. if (e) {
  1031. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  1032. }
  1033. }
  1034. }
  1035. }
  1036.  
  1037. yProto._enqueueClient = function (c) {
  1038. if (c === this || !c || typeof c !== 'object') return;
  1039. if (c.deref) c = kRef(c);
  1040. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  1041. if (!c[wk]) c[wk] = mWeakRef(c);
  1042. m.push(c[wk]);
  1043. }
  1044.  
  1045. }
  1046. }
  1047.  
  1048.  
  1049.  
  1050. }
  1051. const setupRendering = function () {
  1052.  
  1053. const cnt = this;
  1054. const cProto = Reflect.getPrototypeOf(cnt);
  1055. let yProto = Reflect.getPrototypeOf(cProto);
  1056.  
  1057. const yProtos = new Set();
  1058.  
  1059. if (!yMap.has(yProto)) {
  1060. // capture all ancenstor constructors of a and b (non-specific component type)
  1061.  
  1062. do {
  1063. if (yProto === Object.prototype || yProto === null) break;
  1064. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  1065. yProtos.add(yProto);
  1066. yProto = Reflect.getPrototypeOf(yProto);
  1067. } while (!yProtos.has(yProto));
  1068.  
  1069. for (const yProto of yProtos) {
  1070. yMap.add(yProto);
  1071. setupYProto(yProto)
  1072. }
  1073.  
  1074. }
  1075.  
  1076.  
  1077. if (!cMap.has(cProto)) {
  1078. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  1079. setupCProto(cProto);
  1080. }
  1081.  
  1082. }
  1083.  
  1084. const selfRef = {}; // no change. just key
  1085.  
  1086.  
  1087. const sb1 = Symbol();
  1088. Object.defineProperty(Object.prototype, 'root', {
  1089. get() {
  1090. return this[sb1];
  1091. },
  1092. set(nv){
  1093. const p = this ? kRef(this) : null;
  1094. const mv = nv ? kRef(nv) : null;
  1095.  
  1096. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  1097. p.__setupRendered399__ = true;
  1098. setupRendering.call(p);
  1099. }
  1100. if (mv && mv.is && !mv.__setupRendered399__) {
  1101. mv.__setupRendered399__ = true;
  1102. setupRendering.call(mv);
  1103. }
  1104.  
  1105. this[sb1] = nv;
  1106. return true;
  1107. }
  1108. });
  1109.  
  1110.  
  1111. /*
  1112. let wm3 = new WeakMap();
  1113.  
  1114. Object.defineProperty(Object.prototype, 'root', {
  1115. get() {
  1116. const p = this ? kRef(this) : null;
  1117. const r = p ? wm3.get(p) : null;
  1118. const r2 = r ? kRef(r) : null;
  1119. if (r === selfRef) return p;
  1120. return r2;
  1121. },
  1122. set(nv) {
  1123. const p = this ? kRef(this) : null;
  1124. const mv = nv ? kRef(nv) : null;
  1125. if (typeof mv !== 'object') return;
  1126. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  1127. p.__setupRendered399__ = true;
  1128. setupRendering.call(p);
  1129. }
  1130. if (mv && mv.is && !mv.__setupRendered399__) {
  1131. mv.__setupRendered399__ = true;
  1132. setupRendering.call(mv);
  1133. }
  1134. if (mv === p) {
  1135. wm3.set(p, selfRef)
  1136. return true;
  1137. }
  1138. let gv = nv;
  1139. if (nv && !nv[wk]) {
  1140. gv = nv[wk] = mWeakRef(nv);
  1141. }
  1142. if (p) {
  1143. wm3.set(p, gv);
  1144. }
  1145. return true;
  1146. },
  1147. enumerable: false,
  1148. configurable: true
  1149. });
  1150. */
  1151.  
  1152.  
  1153. }
  1154.  
  1155. function getTranslate() {
  1156.  
  1157. pLoad.then(() => {
  1158.  
  1159. let nonce = document.querySelector('style[nonce]');
  1160. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1161. const st = document.createElement('style');
  1162. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1163. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  1164. let parent;
  1165. if (parent = document.head) parent.appendChild(st);
  1166. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  1167.  
  1168. });
  1169.  
  1170. const snCache = new Map();
  1171.  
  1172. if (TRANSLATE_DEBUG) {
  1173. console.log(11)
  1174. }
  1175.  
  1176. /** @type {(str: string?) => string} */
  1177. function _snippetText(str) {
  1178. // str can be underfinded
  1179. if (!str || typeof str !== 'string') return '';
  1180. let res = snCache.get(str);
  1181. if (res === undefined) {
  1182. let b = false;
  1183. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  1184. b = true;
  1185. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  1186. });
  1187. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  1188. b = true;
  1189. return '';
  1190. });
  1191. if (b) {
  1192. snCache.set(str, res);
  1193. snCache.set(res, null);
  1194. } else {
  1195. res = null;
  1196. snCache.set(str, null);
  1197. }
  1198. }
  1199. return res === null ? str : res;
  1200. }
  1201.  
  1202. /** @type {(snippet: Object) => string} */
  1203. function snippetText(snippet) {
  1204. let runs = snippet.runs;
  1205. const n = runs.length;
  1206. if (n === 1) return _snippetText(runs[0].text);
  1207. let res = new Array(n);
  1208. let ci = 0;
  1209. for (const s of runs) {
  1210. res[ci++] = _snippetText(s.text);
  1211. }
  1212. return res.join('\n');
  1213. }
  1214.  
  1215. const _DEBUG_szz = (t) => t.map(x => {
  1216. const tsr = x.transcriptSegmentRenderer;
  1217. return ({
  1218. t: tsr.snippet.runs.map(x => x.text).join('//'),
  1219. a: tsr.startMs,
  1220. b: tsr.endMs
  1221. });
  1222. });
  1223.  
  1224. const fixRuns = (runs) => {
  1225. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  1226. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  1227. const text = runs[0].text;
  1228. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  1229. const s = text.split(nlc);
  1230. let bi = 0;
  1231. runs.length = s.length;
  1232. for (const text of s) {
  1233. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  1234. }
  1235. }
  1236. for (const s of runs) {
  1237. s.text = _snippetText(s.text);
  1238. }
  1239. }
  1240.  
  1241. function translate(initialSegments) {
  1242. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  1243.  
  1244. if (!initialSegments) return initialSegments;
  1245.  
  1246. if (TRANSLATE_DEBUG) {
  1247. console.log(12);
  1248. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  1249. let obj = JSON.parse(r);
  1250. console.log(7558, 1, obj)
  1251. return obj;
  1252. }).then(p => {
  1253. let obj = _DEBUG_szz(p)
  1254. console.log(7558, 2, obj)
  1255. })
  1256. }
  1257.  
  1258.  
  1259. //let mapRej = new WeakSet();
  1260.  
  1261. const n1 = initialSegments.length;
  1262. if (!n1) return fRes;
  1263. let n2 = 0;
  1264.  
  1265.  
  1266. const fRes = new Array(n1);
  1267. // -----------------------------------------------------------------------------------------
  1268.  
  1269. const s8 = Symbol();
  1270.  
  1271. {
  1272.  
  1273. /** @type {Map<String, Object>} */
  1274. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  1275.  
  1276. // /-* * @type {Map<String, number>} *-/
  1277. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  1278. // 1: ok
  1279. // 2: abandoned effect text
  1280.  
  1281. for (const initialSegment of initialSegments) {
  1282. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  1283. if (!transcript) {
  1284. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1285. fRes[n2++] = initialSegment;
  1286. continue;
  1287. }
  1288. const runs = transcript.snippet.runs
  1289. if (!runs || runs.length === 0) {
  1290. initialSegment[s8] = true;
  1291. continue;
  1292. }
  1293. let startMs = (+transcript.startMs || 0); //integer
  1294. let endMs = (+transcript.endMs || 0); //integer
  1295. if (startMs === endMs) {
  1296. // effect text
  1297. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1298. //mapRej.add(initialSegment)
  1299. continue;
  1300. }
  1301. if (endMs - startMs < 30) {
  1302. continue;
  1303. }
  1304. const text = snippetText(transcript.snippet);
  1305. const hEntry = cacheTexts.get(text);
  1306. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  1307. if (mh1e === 2) continue;
  1308. const entry = {
  1309. startMs,
  1310. endMs,
  1311. initialSegment,
  1312. text
  1313. };
  1314. if (mh1e === 0) {
  1315. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  1316. initialSegment[s8] = true;
  1317. cacheTexts.set(text, null);
  1318. //effect only
  1319. // https://www.youtube.com/watch?v=zLak0dxBKpM
  1320. //mapRej.add(initialSegment)
  1321. continue;
  1322. }
  1323. } else if (hEntry) {
  1324.  
  1325. const timeDiff = entry.startMs - hEntry.endMs;
  1326. let shouldMerge = false;
  1327.  
  1328. if (timeDiff >= 0) {
  1329.  
  1330. if (timeDiff < 25) {
  1331. shouldMerge = true;
  1332. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  1333. shouldMerge = true;
  1334. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  1335. shouldMerge = true;
  1336. }
  1337.  
  1338. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  1339. // abandon the current entry.
  1340. // absorbed by previous entry
  1341. hEntry.endMs = entry.endMs;
  1342. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1343. //mapRej.add(entry.initialSegment);
  1344. continue;
  1345. }
  1346.  
  1347. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  1348.  
  1349. // abandon the current entry.
  1350. // absorbed by previous entry
  1351. if (entry.endMs > hEntry.endMs) {
  1352. hEntry.endMs = entry.endMs;
  1353. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1354. }
  1355. //mapRej.add(entry.initialSegment);
  1356. continue;
  1357.  
  1358. }
  1359.  
  1360. }
  1361. //if not abandoned
  1362. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  1363. // for (const s of runs) {
  1364. // s.text = _snippetText(s.text);
  1365. // }
  1366. fixRuns(runs);
  1367. fRes[n2++] = initialSegment;
  1368. }
  1369.  
  1370. // cacheTexts.clear(); // let GC do it.
  1371. cacheTexts = null;
  1372. // mh1.clear(); // let GC do it.
  1373. // mh1 = null;
  1374.  
  1375. }
  1376.  
  1377. const si_length = fRes.length = n2;
  1378. const sj_length = n1;
  1379.  
  1380. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  1381. // collect the abandon text to become second subtitle
  1382.  
  1383. let sj_start = 0;
  1384. let invalid_sj = -1;
  1385. for (let si = 0; si < si_length; si++) {
  1386. const segment = fRes[si];
  1387. let transcript = segment.transcriptSegmentRenderer;
  1388. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  1389. const runs = transcript.snippet.runs;
  1390. // fixRuns(runs);
  1391. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  1392. const main_startMs = (+transcript.startMs || 0);
  1393. const main_endMs = (+transcript.endMs || 0);
  1394. transcript = null;
  1395.  
  1396. /** @type {Map<string, number>} */
  1397. let tMap = new Map(); // avoid duplicate with javascript object properties
  1398.  
  1399. // assume that it is asc-ordered array of key startMs;
  1400. for (let sj = sj_start; sj < sj_length; sj++) {
  1401. const initialSegment = initialSegments[sj];
  1402.  
  1403. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  1404.  
  1405. const tSegment = initialSegment.transcriptSegmentRenderer;
  1406.  
  1407. if (!tSegment) {
  1408. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1409. invalid_sj = sj; // should invalid_sj be set ?
  1410. continue;
  1411. }
  1412.  
  1413. const startMs = (+tSegment.startMs || 0)
  1414. const isStartValid = startMs >= main_startMs;
  1415. if (!isStartValid) {
  1416. invalid_sj = sj;
  1417. continue;
  1418. }
  1419. // isStartValid must be true
  1420. if (startMs > main_endMs) {
  1421. sj_start = invalid_sj + 1;
  1422. break;
  1423. }
  1424.  
  1425. const endMs = (+tSegment.endMs || 0)
  1426. if (endMs <= main_endMs) {
  1427. const mt = snippetText(tSegment.snippet);
  1428. const prev = tMap.get(mt);
  1429. if (endMs >= startMs) {
  1430. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  1431. }
  1432. }
  1433.  
  1434. }
  1435.  
  1436. if (tMap.size <= 1) continue; // no second line
  1437. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  1438. tMap = null;
  1439.  
  1440. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1441.  
  1442. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  1443.  
  1444. let targetZ = rg[1][1];
  1445. if (targetZ > 4) {
  1446. let az = 0;
  1447. let fail = false;
  1448. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  1449. az += rg[idx][1];
  1450. if (az >= targetZ) {
  1451. fail = true;
  1452. break;
  1453. }
  1454. }
  1455. if (!fail) {
  1456. const rgA = rg[0][0];
  1457. const rgB = rg[1][0];
  1458. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  1459. if (isDiff && rgA === _snippetText(runs[0].text)) {
  1460. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  1461. runs.push({ text: rgB, blockLine: true });
  1462. }
  1463. }
  1464. }
  1465. rg = null;
  1466. }
  1467.  
  1468. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  1469.  
  1470. let obj = r;
  1471. console.log(7559, 1, obj)
  1472. return obj;
  1473. }).then(p => {
  1474. let obj = _DEBUG_szz(p)
  1475. console.log(7559, 2, obj)
  1476.  
  1477. });
  1478. }
  1479.  
  1480. // -----------------------------------------------------------------------------------------
  1481. snCache.clear();
  1482. return fRes;
  1483.  
  1484. }
  1485.  
  1486.  
  1487. return translate
  1488.  
  1489. }
  1490.  
  1491.  
  1492. let translateFn = null;
  1493.  
  1494. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  1495.  
  1496. const wmx = new WeakMap();
  1497.  
  1498. function fixSegments(ytObj) {
  1499. let a, b;
  1500. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  1501. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  1502. translateFn = translateFn || getTranslate();
  1503. let cSeg;
  1504. cSeg = wmx.get(seg);
  1505. if (!cSeg) {
  1506. let vSeg = null;
  1507. try {
  1508. vSeg = translateFn(seg);
  1509. } catch (e) {
  1510. }
  1511. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  1512. // console.log('translated', vSeg);
  1513. cSeg = vSeg;
  1514. wmx.set(seg, cSeg);
  1515. wmx.set(cSeg, cSeg);
  1516. }
  1517. }
  1518. if (cSeg && cSeg !== seg) {
  1519. a[b] = cSeg;
  1520. }
  1521. }
  1522.  
  1523. const dfn = Symbol();
  1524. const Object_ = Object;
  1525. Object_[dfn] = Object_.defineProperties;
  1526. let activation = true;
  1527. Object_.defineProperties = function (obj, pds) {
  1528. let segments, get_;
  1529. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  1530. activation = false;
  1531. segments.get = function () {
  1532. fixSegments(this);
  1533. return get_.call(this);
  1534. };
  1535. }
  1536. return Object_[dfn](obj, pds);
  1537. };
  1538.  
  1539. })();
  1540.  
  1541.  
  1542. let pf31 = new PromiseExternal();
  1543.  
  1544. // native RAF
  1545. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  1546.  
  1547. // 1st wrapped RAF
  1548. const baseRAF = (callback) => {
  1549. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  1550. pf31.then(() => {
  1551. callback(hRes);
  1552. });
  1553. });
  1554. };
  1555.  
  1556. // 2nd wrapped RAF
  1557. window.requestAnimationFrame = baseRAF;
  1558.  
  1559. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1560. const indr = o => insp(o).$ || o.$ || 0;
  1561.  
  1562. const prototypeInherit = (d, b) => {
  1563. const m = Object.getOwnPropertyDescriptors(b);
  1564. for (const p in m) {
  1565. if (!Object.getOwnPropertyDescriptor(d, p)) {
  1566. Object.defineProperty(d, p, m[p]);
  1567. }
  1568. }
  1569. };
  1570.  
  1571.  
  1572. const firstObjectKey = (obj) => {
  1573. for (const key in obj) {
  1574. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1575. }
  1576. return null;
  1577. };
  1578.  
  1579. function searchNestedObject(obj, predicate, maxDepth = 64) {
  1580. // normal case: depth until 36
  1581. const result = [];
  1582. const visited = new WeakSet();
  1583.  
  1584. function search(obj, depth) {
  1585. visited.add(obj);
  1586. for (const [key, value] of Object.entries(obj)) {
  1587. // Recursively search nested objects and arrays
  1588. if (value !== null && typeof value === 'object') {
  1589. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  1590. if (depth + 1 <= maxDepth && !visited.has(value)) {
  1591. search(value, depth + 1);
  1592. }
  1593. } else if (predicate(value)) {
  1594. result.push([obj, key]);
  1595. }
  1596. }
  1597. }
  1598.  
  1599. typeof (obj || 0) === 'object' && search(obj, 0);
  1600. return result;
  1601. }
  1602.  
  1603. /** @type {(o: Object | null) => WeakRef | null} */
  1604. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1605.  
  1606. /** @type {(wr: Object | null) => Object | null} */
  1607. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1608.  
  1609. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  1610.  
  1611. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  1612. if (DENY_requestStorageAccess) {
  1613. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  1614. Document.prototype.requestStorageAccessFor = undefined;
  1615. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  1616. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  1617. Document.prototype.requestStorageAccessFor = function () {
  1618. return new Promise((resolve, reject) => {
  1619. reject();
  1620. });
  1621. };
  1622. }
  1623. }
  1624.  
  1625. const traceStack = (stack) => {
  1626. let result = new Set();
  1627. let p = new Set();
  1628. let u = ''
  1629. for (const s of stack.split('\n')) {
  1630. if (s.split(':').length < 3) continue;
  1631. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  1632. if (!m) continue;
  1633. p.add(m[2]);
  1634. if (p.size >= 3) break;
  1635. if(!u) u = m[2];
  1636. else if(p.size === 2 && u && u=== m[2]) break;
  1637. result.add(s);
  1638. }
  1639. return [...result].join('\n');
  1640. }
  1641.  
  1642. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  1643. // window.m3bb = new Set();
  1644.  
  1645. // const smb = Symbol();
  1646. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  1647. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  1648. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  1649.  
  1650. const thisConversionFn = (thisArg) => {
  1651. if (!thisArg) return null;
  1652. const kThis = thisArg[vmb];
  1653. if (kThis) {
  1654. const ref = kThis.ref;
  1655. return (ref ? kRef(ref) : null) || null;
  1656. }
  1657. return thisArg;
  1658. }
  1659.  
  1660. const pFnHandler2 = {
  1661. get(target, prop) {
  1662. if (prop === vmc) return target;
  1663. return Reflect.get(target, prop);
  1664. },
  1665. apply(target, thisArg, argumentsList) {
  1666. thisArg = thisConversionFn(thisArg);
  1667. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  1668. }
  1669. }
  1670.  
  1671.  
  1672. const proxySelfHandler = {
  1673. get(target, prop) {
  1674. if(prop === vmb) return target;
  1675. const ref = target.ref;
  1676. const cnt = kRef(ref);
  1677. if (!cnt) return;
  1678. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  1679. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  1680. return cnt[prop][vmd];
  1681. }
  1682. return cnt[prop];
  1683. },
  1684. set(target, prop, value) {
  1685. const cnt = kRef(target.ref);
  1686. if (!cnt) return true;
  1687. if(value && (value[vmc] || value[vmb])){
  1688. cnt[prop] = value[vmc] || thisConversionFn(value);
  1689. return true;
  1690. }
  1691. cnt[prop] = value;
  1692. return true;
  1693. }
  1694. };
  1695.  
  1696. const weakWrap = (thisArg) => {
  1697. thisArg = thisConversionFn(thisArg);
  1698. if (!thisArg) {
  1699. console.error('thisArg is not found');
  1700. return null;
  1701. }
  1702. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  1703. }
  1704.  
  1705. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  1706. window.getComputedStyle533 = window.getComputedStyle;
  1707. window.getComputedStyle = function (a, ...args) {
  1708. a = thisConversionFn(a);
  1709. if (a) {
  1710. return getComputedStyle533(a, ...args);
  1711. }
  1712. return null;
  1713. }
  1714. }
  1715.  
  1716. Function._count_bind_00 = 0;
  1717. // Function._count_bind_01 = 0;
  1718.  
  1719. // let matchNativeCode = (Object+"");
  1720. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1721. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1722.  
  1723. // const matchConstructor = (thisArg) => {
  1724. // const f = `${(thisArg || 0).constructor}`;
  1725. // if (f.length > 45) return true;
  1726. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1727. // if (f.includes('[native code]')){
  1728. // return false;
  1729. // }
  1730. // return true;
  1731. // }
  1732. // return false;
  1733. // }
  1734.  
  1735. // const acceptThis = (thisArg)=>{
  1736. // // if(!thisArg || typeof thisArg !=='object') return false;
  1737. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1738. // // if(typeof thisArg.path === 'string') return true;
  1739. // // if(typeof thisArg.fn === 'function') return true;
  1740. // // if(typeof thisArg.id === 'string') return true;
  1741. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1742. // return false;
  1743. // }
  1744.  
  1745. const patchFn = (fn) => {
  1746.  
  1747. let s = `${fn}`;
  1748. if (s.length < 11 || s.includes('\n')) return false;
  1749. if(s.includes('bind(this')) return true;
  1750. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1751. // var a=this;
  1752. // f.bind(this)
  1753.  
  1754.  
  1755. return false;
  1756. }
  1757.  
  1758. Function.prototype.bind488 = Function.prototype.bind;
  1759. Function.prototype.bind = function(thisArg, ...args){
  1760.  
  1761. if (thisConversionFn(thisArg) !== thisArg) {
  1762. return this.bind488(thisArg, ...args);
  1763. }
  1764. if( thisArg && patchFn(this) ){
  1765.  
  1766. // console.log(599,`${this}`)
  1767.  
  1768. try {
  1769. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1770. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1771. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1772. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1773. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1774. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1775. // // let b4 = false;
  1776. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1777.  
  1778. // // b3 = false;
  1779. // // b4 = false;
  1780. // // b5 = false;
  1781.  
  1782. // if (b1 || b2 || b3 ||b4 ) {
  1783. const f = this;
  1784. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1785. if (ps && ps[vmb]) {
  1786. Function._count_bind_00++;
  1787. return f.bind488(ps, ...args)
  1788. }
  1789. // }
  1790. } catch (e) {
  1791. console.warn(e)
  1792. }
  1793. }
  1794. return this.bind488(thisArg, ...args);
  1795. }
  1796. Function.prototype.bind588 = 1;
  1797. }
  1798.  
  1799. const ytSchedulerMethods = {
  1800. addJob(a, b, c) {
  1801. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1802. if (instance) {
  1803. return instance.addJob(a, b, c);
  1804. } else {
  1805. return setTimeout(a, c);
  1806. }
  1807. },
  1808. addImmediateJob(a) {
  1809. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1810. if (instance) {
  1811. return instance.addImmediateJob(a);
  1812. } else {
  1813. a();
  1814. }
  1815. },
  1816. cancelJob(id) {
  1817. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1818. if (instance) {
  1819. return instance.cancelJob(id);
  1820. } else {
  1821. return clearTimeout(id);
  1822. }
  1823. }
  1824. };
  1825.  
  1826. if (FIX_ytScheduler) {
  1827.  
  1828. let ytSchedulerFixed = 0;
  1829. // let ytActioned = false;
  1830. // let pr = new PromiseExternal();
  1831.  
  1832. // const hn = function () {
  1833.  
  1834. // document.removeEventListener('yt-action', hn, true);
  1835. // nextBrowserTick_(() => {
  1836. // ytActioned = true;
  1837. // pr.resolve();
  1838. // });
  1839.  
  1840. // }
  1841. // document.addEventListener('yt-action', hn, true);
  1842.  
  1843. // let cancelStore = {}; // tbc
  1844.  
  1845. // yt.scheduler.instance.addJob
  1846. const fixAddJob = (nv) => {
  1847.  
  1848. /*
  1849. function Z() {
  1850. var a = w("ytglobal.schedulerInstanceInstance_");
  1851. if (!a || a.s)
  1852. a = new M(I("scheduler") || {}),
  1853. x("ytglobal.schedulerInstanceInstance_", a);
  1854. return a
  1855. }
  1856. */
  1857.  
  1858. /*
  1859. function R(a, b, c, d) {
  1860. ++a.D;
  1861. if (c === 10)
  1862. return P(a, b),
  1863. a.D;
  1864. var e = a.D;
  1865. a.h[e] = b;
  1866. a.l && !d ? a.u.push({
  1867. id: e,
  1868. priority: c
  1869. }) : (a.i[c].push(e),
  1870. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  1871. a.start()));
  1872. return e
  1873. }
  1874. */
  1875.  
  1876. /*
  1877. function sa(a, b, c) {
  1878. if (!c)
  1879. return c = c === void 0,
  1880. -R(Z(), a, b, c);
  1881. var d = window.setTimeout(function() {
  1882. var e = R(Z(), a, b);
  1883. W[d] = e
  1884. }, c);
  1885. return d
  1886. }
  1887. */
  1888. window.originalAddJob = nv;
  1889. // const q1 = new PromiseExternal();
  1890. // const q2 = new PromiseExternal();
  1891. // let uu = 0;
  1892. // let q3 = 0;
  1893. // let mof = null;
  1894. // const mo = new MutationObserver((mutation, observer) => {
  1895. // if (mof) {
  1896. // if (mof() === true) {
  1897. // observer.disconnect();
  1898. // mof = null;
  1899. // }
  1900. // }
  1901. // });
  1902.  
  1903. let lenSkip = -1;
  1904. let lastLen = null;
  1905. let fetchCommentJobTimerId = 0;
  1906. let requestFinish = false;
  1907.  
  1908. const fetchCommentJobDone = ()=>{
  1909. clearInterval(fetchCommentJobTimerId);
  1910. fetchCommentJobTimerId = 0;
  1911. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1912. }
  1913.  
  1914. const fetchCommentJob = (a, cid) => {
  1915.  
  1916. // if (cid && cancelStore[cid]) return; // tbc
  1917.  
  1918. if(fetchCommentJobTimerId > 0){
  1919. fetchCommentJobDone();
  1920. }
  1921.  
  1922. // if (mof) {
  1923. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1924. // mof = null;
  1925. // }
  1926.  
  1927. let f = a;
  1928.  
  1929. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  1930.  
  1931. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  1932.  
  1933. lastLen = -1;
  1934. let u = 0;
  1935. let g = () => {
  1936. if (requestFinish) lastLen = -1;
  1937. const lastLen_ = lastLen;
  1938. const len1 = lastLen = document.querySelectorAll(selector).length;
  1939. let mm = true;
  1940. let ff = false;
  1941. if (len1 !== lastLen_) {
  1942. u = 0;
  1943. f();
  1944. const len2 = lastLen = document.querySelectorAll(selector).length;
  1945. if (len2 !== len1) {
  1946. ff = true;
  1947. mm = false;
  1948. }
  1949. }
  1950. if (mm) {
  1951. ++u;
  1952. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  1953. ff = true;
  1954. }
  1955. }
  1956.  
  1957. if (requestFinish) {
  1958. requestFinish = false;
  1959. fetchCommentJobDone();
  1960. } else if (ff){
  1961. fetchCommentJobDone();
  1962. }
  1963.  
  1964. }
  1965.  
  1966.  
  1967. fetchCommentJobTimerId = setInterval(g, 80);
  1968. // g(9);
  1969. // if (lastLen === lenSkip) {
  1970. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1971. // g = f = null;
  1972. // return;
  1973. // }
  1974. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1975. // const q1 = lastLen;
  1976. // mof = () => {
  1977. // const q2 = document.querySelectorAll(selector).length;
  1978. // if (q1 === q2) return;
  1979. // fetchCommentJobTimerId = setTimeout(g, 80);
  1980. // g = null;
  1981. // return true;
  1982. // }
  1983. // mo.observe(document, { childList: true, subtree: true });
  1984.  
  1985. }
  1986.  
  1987. let pr72 = Promise.resolve();
  1988.  
  1989.  
  1990. let qa = null;
  1991. let qasf = '';
  1992.  
  1993.  
  1994. document.addEventListener("fullscreenchange", (evt) => {
  1995. if (evt.isTrusted !== true) return;
  1996. if (qa) {
  1997. // qa();
  1998. nextBrowserTick_(qa);
  1999. }
  2000. const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  2001. pr72 = pr72.then(() => {
  2002. return pr
  2003. });
  2004. }, true);
  2005.  
  2006. window.addEventListener("resize", (evt) => {
  2007. if (evt.isTrusted !== true) return;
  2008. if (qa) {
  2009. // qa();
  2010. nextBrowserTick_(qa);
  2011. }
  2012. const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  2013. pr72 = pr72.then(() => {
  2014. return pr
  2015. });
  2016. }, true);
  2017.  
  2018.  
  2019. setInterval(() => {
  2020. const f = qa;
  2021. if (typeof f !== 'function') return;
  2022. // qa = null;
  2023. pr72 = pr72.then(() => {
  2024. f();
  2025. });
  2026. // nextBrowserTick_(()=>{
  2027. // });
  2028. }, 475.25);
  2029.  
  2030.  
  2031.  
  2032. return function (a, b, c) {
  2033.  
  2034.  
  2035. const f = a;
  2036. const g = ()=>{
  2037. pr72 = pr72.then(()=>{
  2038. f();
  2039. });
  2040. }
  2041.  
  2042. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  2043.  
  2044. const c_ = c;
  2045.  
  2046. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  2047.  
  2048. if (b === 1 && c_ === 500) {
  2049. const sf = `${a}`;
  2050. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  2051. qasf = sf;
  2052. qa = a;
  2053. // console.log(12883, a)
  2054. return nv(() => {
  2055. if (qa === a) {
  2056. qa();
  2057. qa = null;
  2058. }
  2059. }, b, c);
  2060. }
  2061. }
  2062.  
  2063.  
  2064. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  2065. console.log('[yt-js-engine-tamer] cleanupJob 01');
  2066. const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  2067. pr72 = pr72.then(() => {
  2068. return pr
  2069. });
  2070. try {
  2071. yt.scheduler.instance.cancelAllJobs();
  2072. yt.scheduler.instance.dispose();
  2073. if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  2074. console.log('[yt-js-engine-tamer] cleanupJob 02');
  2075. } catch (e) { }
  2076. return nv(g, b, c);
  2077. }
  2078.  
  2079. // if(!b && c > 50) c = 50;
  2080. // console.log(58372,a,b,c)
  2081. // function(){xxx(xxx)}
  2082. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  2083.  
  2084. /*
  2085.  
  2086. V.setCommentsJobId = _.et(_.r0, function() {
  2087. F5V(V)
  2088. }, 1E3)
  2089.  
  2090. */
  2091.  
  2092. requestFinish = false;
  2093. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  2094.  
  2095. // lastLen = null;
  2096. fetchCommentJob(a, cid);
  2097.  
  2098. // queueMicrotask_(a);
  2099. // nextBrowserTick_(a);
  2100. // a(); // no need to delay
  2101. return cid
  2102.  
  2103. // return nv(a, b, 1.125);
  2104. // const cid = window.setTimeout(() => {
  2105. // nextBrowserTick_(() => {
  2106. // if (cancelStore[cid]) {
  2107. // console.log('task cancelled');
  2108. // return;
  2109. // }
  2110. // a();
  2111.  
  2112. // });
  2113. // }, 0.125);
  2114. // return cid;
  2115. } else {
  2116.  
  2117.  
  2118.  
  2119. return nv(g,b,c);
  2120.  
  2121.  
  2122. // if (c > 2400) c = 2400;
  2123. // else if (c > 800) c = 800;
  2124. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  2125. // if (0 && ytActioned && !b) {
  2126. // const cid = window.setTimeout(() => {
  2127. // nextBrowserTick_(() => {
  2128. // if (cancelStore[cid]) {
  2129. // console.log('task cancelled');
  2130. // return;
  2131. // }
  2132. // a();
  2133. // });
  2134. // }, c);
  2135. // return cid;
  2136. // } else {
  2137. // return nv(a, b, c);
  2138. // }
  2139.  
  2140. }
  2141. }
  2142. }
  2143.  
  2144. const fixCancelJob = (nv) => {
  2145.  
  2146.  
  2147. window.originalCancelJob = nv;
  2148. return function (a) {
  2149. if (a < 0) return nv(a);
  2150. // cancelStore[a] = true; // tbc
  2151. nv(a);
  2152. }
  2153. }
  2154.  
  2155. const sk44 = Symbol();
  2156. Object.defineProperty(Object.prototype, 'addJob', {
  2157. get() {
  2158. return this[sk44];
  2159. },
  2160. set(nv) {
  2161. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2162. ytSchedulerFixed |= 1;
  2163. nv = fixAddJob(nv);
  2164. }
  2165. this[sk44] = nv;
  2166. return true;
  2167. },
  2168. enumerable: false,
  2169. configurable: true
  2170. });
  2171.  
  2172.  
  2173.  
  2174. const sk45 = Symbol();
  2175. Object.defineProperty(Object.prototype, 'cancelJob', {
  2176. get() {
  2177. return this[sk45];
  2178. },
  2179. set(nv) {
  2180. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2181. ytSchedulerFixed |= 2;
  2182. nv = fixCancelJob(nv);
  2183. }
  2184. this[sk45] = nv;
  2185. return true;
  2186. },
  2187. enumerable: false,
  2188. configurable: true
  2189. });
  2190.  
  2191.  
  2192.  
  2193. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2194. const { addJob, cancelJob } = yt.scheduler.instance;
  2195. if (addJob) {
  2196. yt.scheduler.instance.addJob = null;
  2197. yt.scheduler.instance.addJob = addJob;
  2198. }
  2199. if (cancelJob) {
  2200. yt.scheduler.instance.cancelJob = null;
  2201. yt.scheduler.instance.cancelJob = cancelJob;
  2202. }
  2203. }
  2204.  
  2205.  
  2206. }
  2207.  
  2208.  
  2209. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  2210. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  2211. const wm6 = new WeakMapOriginal();
  2212.  
  2213. const skipW = new WeakSet();
  2214.  
  2215.  
  2216. window.WeakMap = class WeakMap extends WeakMapOriginal {
  2217. constructor(iterable = undefined) {
  2218. super();
  2219. if (iterable && iterable[Symbol.iterator]) {
  2220. for (const entry of iterable) {
  2221. entry && this.set(entry[0], entry[1]);
  2222. }
  2223. }
  2224. }
  2225. delete(a) {
  2226. if (!this.has(a)) return false;
  2227. super.delete(a);
  2228. return true;
  2229. }
  2230. get(a) {
  2231. const p = super.get(a);
  2232. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  2233. let v = kRef(p);
  2234. if (!v) {
  2235. super.delete(a);
  2236. }
  2237. return v || undefined;
  2238. }
  2239. return p;
  2240. }
  2241. has(a) {
  2242. if (!super.has(a)) return false;
  2243. const p = super.get(a);
  2244. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  2245. if (!kRef(p)) {
  2246. super.delete(a);
  2247. return false;
  2248. }
  2249. }
  2250. return true;
  2251. }
  2252. set(a, b) {
  2253. let wq = b;
  2254. if (b && (typeof b === 'function' || typeof b === 'object')) {
  2255. if (b.deref) {
  2256. skipW.add(b);
  2257. wq = b;
  2258. } else {
  2259. wq = wm6.get(b);
  2260. if (!wq) {
  2261. wq = mWeakRef(b);
  2262. wm6.set(b, wq);
  2263. }
  2264. }
  2265. }
  2266. super.set(a, wq);
  2267. return this;
  2268. }
  2269. }
  2270. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  2271. configurable: true,
  2272. enumerable: false,
  2273. value: "WeakMap",
  2274. writable: false
  2275. });
  2276. }
  2277.  
  2278. const isWatchPageURL = (url) => {
  2279. url = url || location;
  2280. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  2281. };
  2282.  
  2283. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  2284.  
  2285. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  2286. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  2287. if (typeof customElements === 'undefined') {
  2288. if (!('__CE_registry' in document)) {
  2289. // https://github.com/webcomponents/polyfills/
  2290. Object.defineProperty(document, '__CE_registry', {
  2291. get() {
  2292. // return undefined
  2293. },
  2294. set(nv) {
  2295. if (typeof nv == 'object') {
  2296. delete this.__CE_registry;
  2297. this.__CE_registry = nv;
  2298. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2299. }
  2300. return true;
  2301. },
  2302. enumerable: false,
  2303. configurable: true
  2304. })
  2305. }
  2306. let eventHandler = (evt) => {
  2307. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2308. const f = callback;
  2309. callback = null;
  2310. eventHandler = null;
  2311. f();
  2312. };
  2313. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2314. } else {
  2315. callback();
  2316. }
  2317. });
  2318.  
  2319. const whenCEDefined = isCustomElementsProvided
  2320. ? (nodeName) => customElements.whenDefined(nodeName)
  2321. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  2322.  
  2323. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  2324. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  2325. const f = performance.now23 = Performance.prototype.now;
  2326.  
  2327. let k = 0; // 0 <= k < 9998m
  2328. let u = 0;
  2329. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  2330.  
  2331. // By definition, performance.now() is mono increasing.
  2332. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  2333. performance.now = performance.now16 = function () {
  2334. /**
  2335. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  2336. *
  2337. * If consecutive session history entries had history.state.entryTime set to same value,
  2338. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  2339. * and modifying its return value slightly to make sure two close consecutive calls don't
  2340. * get the same result helped with resolving the issue.
  2341. */
  2342. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  2343. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  2344.  
  2345. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  2346. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  2347. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  2348. else { // more than 9998 consecutive calls
  2349. /**
  2350. *
  2351. * max no. of consecutive calls
  2352. *
  2353. * Sample Size: 4800
  2354. * Sample Avg = 1565.375
  2355. * Sample Median = 1469.5
  2356. * Sample Max = 5660 << 7500 << 9999
  2357. *
  2358. *
  2359. * */
  2360. k = 0;
  2361. s += 1 / 7;
  2362. }
  2363. return v + k; // 0 < v - M < v - M + k < v
  2364. }
  2365.  
  2366. let loggerMsg = '';
  2367. if (`${performance.now()}` === `${performance.now()}`) {
  2368. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  2369. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  2370. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  2371. }
  2372. loggerMsg && console.warn(loggerMsg);
  2373. })();
  2374.  
  2375. let __forceRemoveMode__ = false;
  2376. FIX_removeChild && (() => {
  2377. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  2378. const fragD = document.createDocumentFragment();
  2379. Node.prototype.removeChild062 = Node.prototype.removeChild;
  2380. Node.prototype.removeChild = function (child) {
  2381. if (__forceRemoveMode__ || typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  2382. let ok = false;
  2383. try {
  2384. this.removeChild062(child);
  2385. ok = true;
  2386. } catch (e) {
  2387.  
  2388. }
  2389. if (!ok) {
  2390. try {
  2391. fragD.appendChild(child)
  2392. } catch (e) {
  2393. console.warn(e);
  2394. }
  2395. try {
  2396. child.remove();
  2397. } catch (e) {
  2398. console.warn(e);
  2399. }
  2400. }
  2401. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  2402. // tooltip bug
  2403. } else {
  2404. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  2405. }
  2406. return child;
  2407. }
  2408. }
  2409. })();
  2410.  
  2411.  
  2412. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  2413.  
  2414. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  2415.  
  2416. // let cid = 0;
  2417.  
  2418. let mousemoveFn = null;
  2419. let mousemoveDT = 0;
  2420. let mousemoveCount = 0;
  2421. // let qv = false;
  2422. const cif = () => {
  2423. if (!mousemoveFn) return;
  2424. const ct = Date.now();
  2425. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  2426. mousemoveFn && mousemoveFn();
  2427. }
  2428. mousemoveFn = null;
  2429. };
  2430. let mousemoveCId = 0;
  2431. let mouseoverFn = null;
  2432. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  2433. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  2434. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2435. const bt = `${b}`;
  2436. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  2437. b[`__$$${a}$$1926__`] = true;
  2438. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  2439. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  2440. // console.log(3928, a, this[`__$$${a}$$1937__`])
  2441. if (!this[`__$$${a}$$1938__`]) {
  2442. this[`__$$${a}$$1938__`] = b;
  2443. if (a === 'mousemove') {
  2444. this.addEventListener4882('mouseenter', (evt) => {
  2445. if (mousemoveCId) return;
  2446. mousemoveCId = setIntervalX0(cif, 380);
  2447. });
  2448. this.addEventListener4882('mouseleave', (evt) => {
  2449. clearIntervalX0(mousemoveCId);
  2450. mousemoveCId = 0;
  2451. });
  2452. }
  2453. this.addEventListener4882(a, (evt) => {
  2454. const evt_ = evt;
  2455. if (!this[`__$$${a}$$1937__`]) return;
  2456. if (!this[`__$$${a}$$1938__`]) return;
  2457. if (a === 'mousemove') {
  2458. mouseoverFn && mouseoverFn();
  2459. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  2460. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  2461. } else {
  2462. mousemoveCount = 0;
  2463. }
  2464. const f = mousemoveFn = () => {
  2465. if (f !== mousemoveFn) return;
  2466. mousemoveFn = null;
  2467. this[`__$$${a}$$1938__`](evt_);
  2468. };
  2469. if (mousemoveCount <= 1) mousemoveFn();
  2470. } else {
  2471. if (a === 'mouseout' || a === 'mouseleave') {
  2472. mousemoveFn = null;
  2473. mousemoveDT = 0;
  2474. mousemoveCount = 0;
  2475. this[`__$$${a}$$1938__`](evt_);
  2476. mouseoverFn && mouseoverFn();
  2477. } else { // mouseover, mouseenter
  2478. mousemoveFn = null;
  2479. mousemoveDT = 0;
  2480. mousemoveCount = 0;
  2481. mouseoverFn && mouseoverFn(); // just in case
  2482. const f = mouseoverFn = () => {
  2483. if (f !== mouseoverFn) return;
  2484. mouseoverFn = null;
  2485. this[`__$$${a}$$1938__`](evt_);
  2486. }
  2487. nextBrowserTick_(mouseoverFn);
  2488. }
  2489. }
  2490. }, c);
  2491.  
  2492.  
  2493. return;
  2494. } else {
  2495.  
  2496. return;
  2497. }
  2498. }
  2499.  
  2500. }
  2501. return this.addEventListener4882(a, b, c)
  2502. }
  2503.  
  2504.  
  2505.  
  2506.  
  2507. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  2508. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  2509. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2510.  
  2511. if (b[`__$$${a}$$1926__`]) {
  2512. b[`__$$${a}$$1926__`] = false;
  2513.  
  2514. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  2515.  
  2516. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  2517.  
  2518. return;
  2519.  
  2520. }
  2521.  
  2522. }
  2523. return this.removeEventListener4882(a, b, c)
  2524. }
  2525.  
  2526.  
  2527. })();
  2528.  
  2529.  
  2530. FIX_DOM_IF_REPEAT && (() => {
  2531. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  2532. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  2533. // Be careful of the mixture of polymer functions and native Element functions
  2534. // Be careful of the coding design is different with the modern Yt elements
  2535.  
  2536.  
  2537. /*
  2538.  
  2539.  
  2540. function Ks(a, b, c) {
  2541. if (kj && !BOa(a))
  2542. throw Error("strictTemplatePolicy: template owner not trusted");
  2543. c = c || {};
  2544. if (a.__templatizeOwner)
  2545. throw Error("A <template> can only be templatized once");
  2546. a.__templatizeOwner = b;
  2547. var d = (b ? b.constructor : Js)._parseTemplate(a)
  2548. , e = d.templatizeInstanceClass;
  2549. e || (e = COa(a, d, c),
  2550. d.templatizeInstanceClass = e);
  2551. var g = BOa(a);
  2552. EOa(a, d, c, g);
  2553. c = function() {
  2554. return e.apply(this, arguments) || this
  2555. }
  2556. ;
  2557. h(c, e);
  2558. c.prototype._methodHost = g;
  2559. c.prototype.__dataHost = a;
  2560. c.prototype.__templatizeOwner = b;
  2561. c.prototype.__hostProps = d.hostProps;
  2562. return c
  2563. }
  2564.  
  2565. */
  2566.  
  2567. // Polymer.enqueueDebouncer
  2568.  
  2569. const s81 = Symbol();
  2570. const s83 = Symbol();
  2571. const s84 = Symbol();
  2572. const s85 = Symbol();
  2573. const s85b = Symbol();
  2574. const s85c = Symbol();
  2575.  
  2576. let renderDebounceTs = null;
  2577.  
  2578. let renderDebouncePromise = null;
  2579. let qp;
  2580.  
  2581. let cme = 0;
  2582.  
  2583. const shadyFlushMO = new MutationObserver(() => {
  2584.  
  2585. if (!renderDebounceTs) return;
  2586.  
  2587. if (renderDebounceTs.size > 0) {
  2588. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  2589. try {
  2590. Polymer.flush();
  2591. return;
  2592. } catch (e) { }
  2593. }
  2594.  
  2595. renderDebouncePromise && Promise.resolve().then(() => {
  2596.  
  2597. if (renderDebouncePromise) {
  2598. renderDebouncePromise && renderDebouncePromise.resolve();
  2599. renderDebouncePromise = null;
  2600. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  2601. }
  2602.  
  2603. });
  2604.  
  2605. // Polymer.flush
  2606.  
  2607. window.ShadyDOM && ShadyDOM.flush();
  2608. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  2609.  
  2610.  
  2611. });
  2612.  
  2613. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2614.  
  2615. const observablePromise = (proc, timeoutPromise) => {
  2616. let promise = null;
  2617. return {
  2618. obtain() {
  2619. if (!promise) {
  2620. promise = new Promise(resolve => {
  2621. let mo = null;
  2622. const f = () => {
  2623. let t = proc();
  2624. if (t) {
  2625. mo.disconnect();
  2626. mo.takeRecords();
  2627. mo = null;
  2628. resolve(t);
  2629. }
  2630. }
  2631. mo = new MutationObserver(f);
  2632. mo.observe(document, { subtree: true, childList: true })
  2633. f();
  2634. timeoutPromise && timeoutPromise.then(() => {
  2635. resolve(null)
  2636. });
  2637. });
  2638. }
  2639. return promise
  2640. }
  2641. }
  2642. }
  2643.  
  2644.  
  2645. let p = 0;
  2646. qp = observablePromise(() => {
  2647. if (!(p & 1)) {
  2648.  
  2649. if (window.ShadyDOM && ShadyDOM.flush) {
  2650. p |= 1;
  2651. if (!ShadyDOM.flush847) {
  2652.  
  2653. ShadyDOM.flush847 = ShadyDOM.flush;
  2654. ShadyDOM.flush = function () {
  2655.  
  2656. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  2657. renderDebouncePromise && Promise.resolve().then(() => {
  2658. if (renderDebouncePromise) {
  2659.  
  2660. renderDebouncePromise && renderDebouncePromise.resolve();
  2661. renderDebouncePromise = null;
  2662.  
  2663. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  2664.  
  2665. }
  2666.  
  2667. });
  2668. let r = this.flush847(...arguments);
  2669. if (r) {
  2670. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2671. }
  2672. return r
  2673. }
  2674.  
  2675. }
  2676. }
  2677. }
  2678.  
  2679. if (!(p & 2)) {
  2680.  
  2681. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  2682. p |= 2;
  2683. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  2684. if (!ScopingShim.flush848) {
  2685.  
  2686. ScopingShim.flush848 = ScopingShim.flush;
  2687. ScopingShim.flush = function () {
  2688.  
  2689. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  2690.  
  2691. renderDebouncePromise && Promise.resolve().then(() => {
  2692.  
  2693. if (renderDebouncePromise) {
  2694.  
  2695. renderDebouncePromise && renderDebouncePromise.resolve();
  2696. renderDebouncePromise = null;
  2697.  
  2698. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  2699.  
  2700.  
  2701.  
  2702. }
  2703.  
  2704. });
  2705. return this.flush848(...arguments);
  2706. }
  2707.  
  2708. }
  2709. }
  2710. }
  2711. if (p === 3) {
  2712. p |= 8;
  2713.  
  2714. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  2715. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  2716. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  2717.  
  2718. if (r) {
  2719. let w = Set.prototype.add;
  2720. let u = null;
  2721. Set.prototype.add = function () {
  2722. u = this;
  2723. throw new Error();
  2724. }
  2725. try {
  2726. Polymer.enqueueDebouncer()
  2727. } catch (e) { }
  2728. Set.prototype.add = w;
  2729. if (u !== null) {
  2730. renderDebounceTs = u;
  2731. if (DEBUG_renderDebounceTs) {
  2732. renderDebounceTs.add58438 = renderDebounceTs.add;
  2733. renderDebounceTs.add = function () {
  2734. console.log('renderDebounceTs.add')
  2735. console.log(traceStack((new Error()).stack))
  2736. // debugger;
  2737. return this.add58438(...arguments)
  2738. }
  2739.  
  2740. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  2741. renderDebounceTs.delete = function () {
  2742. console.log('renderDebounceTs.delete')
  2743. const stack = `${(new Error()).stack}`
  2744. let isCallbackRemoval = false;
  2745. if (stack) {
  2746. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  2747. const s = t.split(':');
  2748. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  2749. isCallbackRemoval = true;
  2750. }
  2751. }
  2752. if (isCallbackRemoval) {
  2753. return this.delete58438(...arguments)
  2754. }
  2755. console.log(traceStack((new Error()).stack))
  2756. // debugger;
  2757. return this.delete58438(...arguments)
  2758. }
  2759. }
  2760. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  2761. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  2762. }
  2763. }
  2764.  
  2765. return true;
  2766. }
  2767. })
  2768.  
  2769. // if(window.ShadyDOM && ShadyDOM.flush){
  2770. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  2771.  
  2772. // }
  2773. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  2774.  
  2775. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  2776. // }
  2777.  
  2778. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  2779.  
  2780. }
  2781.  
  2782. Object.defineProperty(Object.prototype, '_lastIf', {
  2783. get() {
  2784. return this[s81];
  2785. },
  2786. set(nv) {
  2787. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  2788. // DOM-IF initialization
  2789. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  2790.  
  2791. this.__xiWB8__ = 2;
  2792.  
  2793. const cProto = this.__proto__;
  2794. if (cProto && !cProto.__xiWB7__) {
  2795. cProto.__xiWB7__ = 1;
  2796.  
  2797. // dom-if __template
  2798. // dom-repeat template
  2799. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  2800. cProto.__template847 = true;
  2801. try {
  2802. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  2803. Object.defineProperty(cProto, '__template', {
  2804. get() {
  2805. const v = this[s84];
  2806. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  2807. },
  2808. set(nv) {
  2809. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  2810. this[s84] = nv;
  2811. return true;
  2812. }
  2813. });
  2814. } catch (e) {
  2815. console.warn(e);
  2816. }
  2817.  
  2818. console.log('FIX_DOM_IF - __template')
  2819. }
  2820.  
  2821. // dom-if __ensureTemplate
  2822. // dom-repeat __ensureTemplatized
  2823. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  2824. // note that "_templateInfo" diffs the different version of DOM-IF
  2825.  
  2826. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  2827. cProto.__ensureTemplate = function () {
  2828. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  2829. if (!this.__template) {
  2830. let b;
  2831. if (this._templateInfo) {
  2832. b = this;
  2833. } else {
  2834. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  2835. b = this.__templateCollection011__[0];
  2836. if (!b) {
  2837. if (!this[wk]) this[wk] = mWeakRef(this);
  2838. let a = this[wk];
  2839. let c = new MutationObserver(function () {
  2840. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  2841. if (c && a) {
  2842. c.disconnect();
  2843. a = kRef(a);
  2844. a && a.__render();
  2845. a && (a.__templateCollection011__ = null);
  2846. }
  2847. c = null;
  2848. a = null;
  2849. });
  2850. c && c.observe(this, {
  2851. childList: !0
  2852. });
  2853. return !1
  2854. } else {
  2855. this.__templateCollection011__ = null;
  2856. }
  2857. }
  2858. this.__template = b
  2859. }
  2860. return !0
  2861. }
  2862.  
  2863. console.log('FIX_DOM_IF - __ensureTemplate')
  2864.  
  2865. }
  2866.  
  2867.  
  2868. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  2869.  
  2870. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  2871.  
  2872. // cProto.__createAndInsertInstance = function (a) {
  2873. // Promise.resolve().then(()=>{
  2874. // console.log('__createAndInsertInstance')
  2875. // window.lm5 = window.lm5 || [];
  2876. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  2877. // });
  2878. // return this.__createAndInsertInstance847(a);
  2879. // }
  2880.  
  2881. // }
  2882.  
  2883.  
  2884. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  2885.  
  2886. // cProto._bindTemplate847 = cProto._bindTemplate;
  2887.  
  2888. // cProto._bindTemplate = function (a, b) {
  2889. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  2890. // }
  2891.  
  2892. // }
  2893. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  2894.  
  2895. // cProto._stampTemplate847 = cProto._stampTemplate;
  2896.  
  2897. // cProto._stampTemplate = function (a, b) {
  2898. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  2899. // }
  2900.  
  2901. // }
  2902. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  2903. }
  2904.  
  2905.  
  2906. // need to fix __observeEffects
  2907. // this.__observeEffects.if[0].info.method === this.__debounceRender
  2908. const f = () => {
  2909.  
  2910. const __observeEffects = this.__observeEffects;
  2911.  
  2912. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  2913. for (const effect of __observeEffects.if) {
  2914. const info = effect.info;
  2915. if (info && typeof info.method === 'function') {
  2916.  
  2917. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  2918. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  2919. }
  2920.  
  2921. }
  2922. }
  2923. }
  2924.  
  2925.  
  2926. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  2927. for (const effect of __observeEffects.restamp) {
  2928. const info = effect.info;
  2929. if (info && typeof info.method === 'function') {
  2930.  
  2931. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  2932. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  2933. }
  2934.  
  2935. }
  2936. }
  2937. }
  2938.  
  2939. // console.log(5881, this.__observeEffects)
  2940. }
  2941. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2942. f();
  2943. Promise.resolve().then(f);
  2944. // afterward, don't care adding fn directly (the fn is already modified)
  2945. }
  2946.  
  2947. }
  2948. this[s81] = nv;
  2949. return true;
  2950. }
  2951. });
  2952.  
  2953.  
  2954. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  2955. get() {
  2956. return this[s85];
  2957. },
  2958. set(nv) {
  2959. if (nv === null && this[s85] === undefined) {
  2960. // DOM-IF / DOM-REPEAT initialization
  2961.  
  2962.  
  2963. const cProto = this.__proto__;
  2964. if (qp) {
  2965. qp.obtain();
  2966. qp = null;
  2967. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  2968. }
  2969. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  2970.  
  2971. cProto.__debounceRender847 = cProto.__debounceRender;
  2972.  
  2973. if (cProto.__debounceRender.length === 2) {
  2974.  
  2975. cProto.__debounceRender = function (a, b) {
  2976.  
  2977. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  2978.  
  2979. b = b === void 0 ? 0 : b;
  2980.  
  2981. /*
  2982. b = b === void 0 ? 0 : b;
  2983. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  2984. vs(this.__renderDebouncer)
  2985. */
  2986.  
  2987. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2988.  
  2989. if (!renderDebouncePromise) {
  2990. renderDebouncePromise = new PromiseExternal();
  2991. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2992. }
  2993.  
  2994. renderDebouncePromise.then(async () => {
  2995. if (b > 0) await delayPn(b);
  2996.  
  2997. const f = this.__dsIRYqw1__;
  2998. if (f === cme) return;
  2999. this.__dsIRYqw1__ = cme;
  3000. a.call(this);
  3001. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  3002.  
  3003. });
  3004.  
  3005. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  3006. }
  3007.  
  3008. } else if (cProto.__debounceRender.length === 0) {
  3009.  
  3010.  
  3011. cProto.__debounceRender = function () {
  3012.  
  3013. if (!renderDebounceTs) return this.__debounceRender847();
  3014.  
  3015. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3016. /*
  3017. var a = this;
  3018. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  3019. return a.__render()
  3020. });
  3021. vs(this.__renderDebouncer)
  3022. */
  3023.  
  3024. if (!renderDebouncePromise) {
  3025. renderDebouncePromise = new PromiseExternal();
  3026. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  3027. }
  3028. renderDebouncePromise.then(() => {
  3029. const f = this.__dsIRYqw1__;
  3030. if (f === cme) return;
  3031. this.__dsIRYqw1__ = cme;
  3032. this.__render()
  3033. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  3034. });
  3035. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  3036.  
  3037.  
  3038. }
  3039. }
  3040. }
  3041.  
  3042.  
  3043.  
  3044. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  3045. // cProto.render847 = cProto.render;
  3046. // cProto.render = function(){
  3047.  
  3048. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3049. // try{
  3050. // this.render847();
  3051. // }catch(e){}
  3052. // // if(this.__DBR847__){
  3053. // // this.__DBR847__.resolve();
  3054. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  3055. // // }
  3056.  
  3057. // // renderDebouncePromise && renderDebouncePromise.resolve()
  3058. // // renderDebouncePromise = null;
  3059. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  3060.  
  3061. // }
  3062. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  3063. // }
  3064.  
  3065. }
  3066. this[s85] = nv;
  3067. return true;
  3068. }
  3069. });
  3070.  
  3071. // PS-DOM-REPEAT
  3072.  
  3073. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  3074. get() {
  3075. return this[s85b];
  3076. },
  3077. set(nv) {
  3078.  
  3079. this[s85b] = nv;
  3080. return true;
  3081. }
  3082. })
  3083.  
  3084. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  3085. get() {
  3086. return this[s85c];
  3087. },
  3088. set(nv) {
  3089.  
  3090. this[s85c] = nv;
  3091. return true;
  3092. }
  3093. })
  3094.  
  3095.  
  3096. })();
  3097.  
  3098. const setupXdeadC = (cnt)=>{
  3099.  
  3100. let xdeadc = xdeadc00;
  3101. if(!xdeadc){
  3102. setupSDomWrapper(); // just in case
  3103. const hostElement = cnt.hostElement;
  3104. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3105. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  3106. hostElement.lastChild.replaceWith(el);
  3107. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  3108. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3109. el.firstElementChild.id = rid;
  3110. cnt.$[rid] = el.firstElementChild;
  3111. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  3112.  
  3113. xdeadc = cnt.getStampContainer_(rid);
  3114. el.remove();
  3115. xdeadc00 = xdeadc;
  3116. // console.log(xdeadc.__domApi)
  3117. // debugger;
  3118. // const xdeadv = xdeadc.__domApi;
  3119. }
  3120.  
  3121. let xlivec = xlivec00;
  3122. if(!xlivec){
  3123. setupSDomWrapper(); // just in case
  3124. const hostElement = cnt.hostElement;
  3125. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3126. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  3127. hostElement.lastChild.replaceWith(el);
  3128. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  3129. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  3130. el.firstElementChild.id = rid;
  3131. cnt.$[rid] = el.firstElementChild;
  3132. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  3133.  
  3134. xlivec = cnt.getStampContainer_(rid);
  3135. xlivec00 = xlivec;
  3136. // console.log(xdeadc.__domApi)
  3137. // debugger;
  3138. // const xdeadv = xdeadc.__domApi;
  3139. }
  3140.  
  3141. return xdeadc00;
  3142. }
  3143.  
  3144. let standardWrap_ = null;
  3145.  
  3146. const setupSDomWrapper = () => {
  3147.  
  3148. const sdwProto = ShadyDOM.Wrapper.prototype;
  3149.  
  3150. if (sdwProto.__pseudo__isConnected__ !== null) {
  3151. sdwProto.__pseudo__isConnected__ = null;
  3152. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  3153. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  3154. const get = isConnectedPd.get;
  3155. isConnectedPd.get = function () {
  3156. const pseudoVal = this.__pseudo__isConnected__;
  3157. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  3158. }
  3159. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  3160. }
  3161.  
  3162. // debugger;
  3163. // new xdeadc.__domApi.constructor(document.createElement('div'));
  3164. }
  3165.  
  3166. }
  3167.  
  3168. let domApiConstructor = null;
  3169. const setupDomApi = (daProto) => {
  3170.  
  3171. daProto.__daHook377__ = true;
  3172.  
  3173. domApiConstructor = daProto.constructor; // TBC
  3174.  
  3175. // TBC
  3176.  
  3177. }
  3178.  
  3179.  
  3180. // WEAKREF_ShadyDOM
  3181.  
  3182. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  3183.  
  3184. const setupPlainShadyDOM = (b) => {
  3185. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  3186. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  3187. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  3188. b.patchOnDemand = true;
  3189. b.preferPerformance = true;
  3190. b.noPatch = true;
  3191. }
  3192.  
  3193. const isPlainObject = (b, m) => {
  3194. if (!b || typeof b !== 'object') return false;
  3195. const e = Object.getOwnPropertyDescriptors(b);
  3196. if (e.length <= m) return false;
  3197. let pr = 0;
  3198. for (const k in e) {
  3199. const d = e[k];
  3200. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  3201. if (!('value' in d) || typeof d.value === 'function') return false;
  3202. pr++;
  3203. }
  3204. return pr > m;
  3205. }
  3206.  
  3207. let b;
  3208.  
  3209. let lz = 0;
  3210.  
  3211. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  3212. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  3213.  
  3214. // Brave - ShadyDOM exists before userscripting
  3215. b = sdp.value;
  3216.  
  3217. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  3218. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  3219. lz = 1;
  3220. }
  3221.  
  3222. }
  3223.  
  3224.  
  3225. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  3226. } else if (!sdp) {
  3227. } else {
  3228. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  3229. return;
  3230. }
  3231.  
  3232. const shadyDOMNodeWRM = new WeakMap();
  3233.  
  3234. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  3235.  
  3236. const weakWrapperNodeHandlerFn = () => ({
  3237. get() {
  3238. const wv = this[wk];
  3239. if (typeof wv === 'undefined') return undefined;
  3240. let node = kRef(wv);
  3241. if (!node) this[wk] = undefined;
  3242. return node || undefined;
  3243. },
  3244. set(nv) {
  3245. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  3246. this[wk] = wv;
  3247. return true;
  3248. },
  3249. enumerable: true,
  3250. configurable: true
  3251. });
  3252.  
  3253.  
  3254. function weakWrapper(_ShadyDOM) {
  3255. const ShadyDOM = _ShadyDOM;
  3256. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  3257. let nullElement = { node: null };
  3258. Object.setPrototypeOf(nullElement, Element.prototype);
  3259. let p = new ShadyDOM.Wrapper(nullElement);
  3260. let d = Object.getOwnPropertyDescriptor(p, 'node');
  3261. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  3262. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  3263. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  3264. }
  3265.  
  3266. }
  3267. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  3268. try {
  3269. setupSDomWrapper();
  3270. } catch (e) { }
  3271. }
  3272.  
  3273. }
  3274.  
  3275. let previousWrapStore = null;
  3276.  
  3277. const standardWrap = function (a) {
  3278. // if(a && a.deref) a= a.deref();
  3279. if(!a) return a;
  3280. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  3281. if (previousWrapStore) {
  3282. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  3283. if (s) {
  3284. previousWrapStore.delete(a);
  3285. shadyDOMNodeWRM.set(a, mWeakRef(s));
  3286. }
  3287. }
  3288. let u = kRef(shadyDOMNodeWRM.get(a));
  3289. if (!u) {
  3290. u = new ShadyDOM.Wrapper(a);
  3291. shadyDOMNodeWRM.set(a, mWeakRef(u));
  3292. }
  3293. return u;
  3294. }
  3295.  
  3296. standardWrap_ = standardWrap;
  3297.  
  3298.  
  3299. function setupWrapFunc(_ShadyDOM) {
  3300. const ShadyDOM = _ShadyDOM;
  3301.  
  3302.  
  3303. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  3304. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  3305. return;
  3306. }
  3307. let mm = new Set();
  3308. const pget = wmPD.value;
  3309. WeakMap.prototype.get = function (a) {
  3310. mm.add(this);
  3311. return a;
  3312. }
  3313. try {
  3314. let nullElement = { node: null };
  3315. Object.setPrototypeOf(nullElement, Element.prototype);
  3316. ShadyDOM.wrapIfNeeded(nullElement)
  3317. ShadyDOM.wrap(nullElement)
  3318. } catch (e) { }
  3319. WeakMap.prototype.get = pget;
  3320. if (mm.size !== 1) {
  3321. mm.clear();
  3322. return;
  3323. }
  3324. const p = mm.values().next().value;
  3325. if (!(p instanceof WeakMap)) return;
  3326. // p.clear();
  3327. // p.get = function (a) { return a }
  3328. // p.set = function (a, b) { return this }
  3329. // console.log(188, window.n2n = mm, window.n2p = p)
  3330.  
  3331. // console.log(34929,p.size)
  3332. previousWrapStore = p;
  3333.  
  3334. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  3335. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  3336. }
  3337. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  3338. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  3339. }
  3340.  
  3341. }
  3342.  
  3343. function setupLZ3(nv) {
  3344.  
  3345. const ShadyDOM = nv;
  3346.  
  3347. const ShadyDOMSettings = ShadyDOM.settings;
  3348. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3349. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3350. return false;
  3351. }
  3352.  
  3353. weakWrapper(ShadyDOM);
  3354.  
  3355. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3356.  
  3357. setupPlainShadyDOM(ShadyDOMSettings);
  3358. setupPlainShadyDOM(ShadyDOM);
  3359.  
  3360. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  3361.  
  3362. setupWrapFunc(ShadyDOM);
  3363. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  3364. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  3365.  
  3366. // To be confirmed
  3367. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  3368. ShadyDOM.composedPath = function (e) {
  3369. const t = (e || 0).target || null;
  3370. if (!(t instanceof HTMLElement_)) {
  3371. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  3372. }
  3373. return t instanceof HTMLElement_ ? [t] : [];
  3374. };
  3375. }
  3376.  
  3377. }
  3378.  
  3379. }
  3380.  
  3381.  
  3382. function setupLZ6(nv) {
  3383.  
  3384. const ShadyDOM = nv;
  3385.  
  3386. const ShadyDOMSettings = ShadyDOM.settings;
  3387.  
  3388. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3389. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3390. return false;
  3391. }
  3392.  
  3393. weakWrapper(ShadyDOM);
  3394.  
  3395. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3396.  
  3397. setupPlainShadyDOM(ShadyDOMSettings);
  3398. setupPlainShadyDOM(ShadyDOM);
  3399.  
  3400. setupWrapFunc(ShadyDOM);
  3401.  
  3402. }
  3403.  
  3404. }
  3405.  
  3406. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  3407.  
  3408. const nv = b;
  3409.  
  3410. if (setupLZ6(nv) === false) return;
  3411.  
  3412. lz = 6;
  3413.  
  3414. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  3415.  
  3416. return;
  3417. }
  3418.  
  3419. delete window.ShadyDOM;
  3420.  
  3421. Object.defineProperty(window, 'ShadyDOM', {
  3422. get() {
  3423. return b;
  3424. },
  3425. set(nv) {
  3426. let ret = 0;
  3427. try {
  3428. do {
  3429. if (!nv || !nv.settings) {
  3430. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  3431. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  3432. lz = 1;
  3433. break;
  3434. } else {
  3435. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  3436. break;
  3437. }
  3438. }
  3439.  
  3440. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  3441. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  3442. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  3443. break;
  3444. }
  3445.  
  3446. if (setupLZ3(nv) === false) break;
  3447.  
  3448. lz = 3;
  3449.  
  3450. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  3451.  
  3452. ret = 1;
  3453.  
  3454. } while (0);
  3455. } catch (e) {
  3456. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  3457. }
  3458.  
  3459. if (!ret) b = nv;
  3460. else {
  3461. delete this.ShadyDOM;
  3462. this.ShadyDOM = nv;
  3463. }
  3464. return true;
  3465. },
  3466. enumerable: false,
  3467. configurable: true
  3468. });
  3469.  
  3470. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  3471.  
  3472. if (ENABLE_ASYNC_DISPATCHEVENT) {
  3473. const filter = new Set([
  3474. 'yt-action',
  3475. // 'iframe-src-replaced',
  3476. 'shown-items-changed',
  3477. 'can-show-more-changed', 'collapsed-changed',
  3478.  
  3479. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  3480. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  3481. 'yt-navigate-finish',
  3482.  
  3483. // 'data-changed','yt-watch-comments-ready'
  3484. ])
  3485. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  3486. EventTarget.prototype.dispatchEvent = function (event) {
  3487. const type = (event || 0).type;
  3488. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  3489. if (!filter.has(type) && !type.endsWith('-changed')) {
  3490. if (this instanceof Node || this instanceof Window) {
  3491. nextBrowserTick_(() => this.dispatchEvent938(event));
  3492. return true;
  3493. }
  3494. }
  3495. }
  3496. return this.dispatchEvent938(event);
  3497. }
  3498. }
  3499.  
  3500. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  3501. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  3502. // const xhr = new XMLHttpRequest;
  3503. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  3504. if (!pdOri || pdOri.configurable !== true) return;
  3505. let propNeedles = null;
  3506. const pdNew = {
  3507. configurable: true,
  3508. enumerable: true,
  3509. get: function () {
  3510. propNeedles = this;
  3511. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  3512. throw new Error();
  3513. }
  3514. }
  3515. Object.defineProperty(Map.prototype, 'size', pdNew);
  3516. try {
  3517. XMLHttpRequest.prototype.open.call(0);
  3518. // xhr.open.call(null)
  3519. } catch (e) { }
  3520. Object.defineProperty(Map.prototype, 'size', pdOri);
  3521. if (!propNeedles) return;
  3522. const entries = [...propNeedles.entries()];
  3523. propNeedles.clear();
  3524. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  3525. })();
  3526.  
  3527. if (FIX_XHR_REQUESTING) {
  3528.  
  3529. const URL = window.URL || new Function('return URL')();
  3530. const createObjectURL = URL.createObjectURL.bind(URL);
  3531.  
  3532. XMLHttpRequest = (() => {
  3533. const XMLHttpRequest_ = XMLHttpRequest;
  3534. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  3535. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  3536. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  3537. constructor(...args) {
  3538. super(...args);
  3539. }
  3540. open(method, url, ...args) {
  3541. let skip = false;
  3542. if (!url || typeof url !== 'string') skip = true;
  3543. else if (typeof url === 'string') {
  3544. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  3545. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  3546. skip = true;
  3547. } else if (turl.includes('.youtube.com/pagead/')) {
  3548. skip = true;
  3549. } else if (turl.includes('.youtube.com/ptracking')) {
  3550. skip = true;
  3551. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  3552. skip = true;
  3553. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  3554. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  3555. skip = true;
  3556. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  3557. skip = true;
  3558. } else {
  3559. // skip = true; // for user activity logging e.g. watched videos
  3560. }
  3561. } else if (turl.includes('play.google.com/log')) {
  3562. skip = true;
  3563. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  3564. skip = true;
  3565. }
  3566. }
  3567. if (!skip) {
  3568. this.__xmMc8__ = 1;
  3569. return super.open(method, url, ...args);
  3570. } else {
  3571. this.__xmMc8__ = 2;
  3572. return super.open('GET', url0);
  3573. }
  3574. }
  3575. send(...args) {
  3576. if (this.__xmMc8__ === 1) {
  3577. return super.send(...args);
  3578. } else if (this.__xmMc8__ === 2) {
  3579. return super.send();
  3580. } else {
  3581. console.log('[yt-js-engine-tamer]', 'xhr warning');
  3582. return super.send(...args);
  3583. }
  3584. }
  3585. }
  3586. c.prototype.__xmMc8__ = 0;
  3587. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  3588. return c;
  3589. })();
  3590. }
  3591.  
  3592. // Alternative HACK -> Tabview Youtube
  3593. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  3594.  
  3595. // ---- << this.overscrollConfig HACK >> -----
  3596.  
  3597. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  3598.  
  3599. /*
  3600.  
  3601. ;function gZb(a, b) {
  3602. b = void 0 === b ? !0 : b;
  3603. a.addEventListener("wheel", hZb);
  3604. a.overscrollConfig = {
  3605. cooldown: b
  3606. }
  3607. }
  3608. function iZb(a) {
  3609. a.overscrollConfig = void 0;
  3610. a.removeEventListener("wheel", hZb)
  3611. }
  3612. function hZb(a) {
  3613. var b = a.deltaY
  3614. , c = a.target
  3615. , d = null;
  3616. if (window.Polymer && window.Polymer.Element) {
  3617. if (c = a.path || a.composedPath && a.composedPath()) {
  3618. c = g(c);
  3619. for (var e = c.next(); !e.done && (e = e.value,
  3620. !jZb(e, b)); e = c.next())
  3621. if (e.overscrollConfig) {
  3622. d = e;
  3623. break
  3624. }
  3625. }
  3626. } else
  3627. for (; c && !jZb(c, b); ) {
  3628. if (c.overscrollConfig) {
  3629. d = c;
  3630. break
  3631. }
  3632. c = c.parentElement
  3633. }
  3634. d && (b = d.overscrollConfig,
  3635. b.cooldown ? (d = a.deltaY,
  3636. c = b.lastDeltaY || 0,
  3637. b.lastDeltaY = d,
  3638. e = b.lastStopped || 0,
  3639. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  3640. c = !1) : (d = e + 600,
  3641. c = !0) : (d = Date.now() + 600,
  3642. c = !0),
  3643. d > Date.now() && (a.preventDefault(),
  3644. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  3645. }
  3646. */
  3647.  
  3648. let wheelHandler = function (a) {
  3649. if (window.Polymer && window.Polymer.Element) {
  3650. let c;
  3651. if (c = a.path || a.composedPath && a.composedPath()) {
  3652. for (const e of c) {
  3653. const cnt = insp(e);
  3654. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3655. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3656. }
  3657. }
  3658. } else {
  3659. let e = a.target;
  3660. for (; e instanceof Element; e = e.parentElement) {
  3661. const cnt = insp(e);
  3662. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3663. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3664. }
  3665. }
  3666. };
  3667.  
  3668. let checkWheelListenerObjs = null;
  3669.  
  3670. let getObjsFn = () => {
  3671. let euyVal = 0;
  3672. const eukElm = {};
  3673. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  3674. const euzObj = new Proxy(eukElm, {
  3675. get(target, prop) {
  3676. throw `ErrorF31.get(${prop})`
  3677. },
  3678. set(target, prop, value) {
  3679. throw `ErrorF33.set(${prop}, ${value})`
  3680. }
  3681. });
  3682. const euxElm = new Proxy(eukElm, {
  3683. get(target, prop) {
  3684. if (prop === 'scrollTop') {
  3685. euyVal = euyVal | 8;
  3686. return 0;
  3687. }
  3688. if (prop === 'overscrollConfig') {
  3689. euyVal = euyVal | 16;
  3690. return void 0;
  3691. }
  3692. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  3693. return 640;
  3694. }
  3695. if (prop === 'scrollLeft') {
  3696. euyVal = euyVal | 8;
  3697. return 0;
  3698. }
  3699. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  3700. return 800;
  3701. }
  3702. throw `ErrorF45.get(${prop})`
  3703. },
  3704. set(target, prop, value) {
  3705. throw `ErrorF47.set(${prop}, ${value})`
  3706. }
  3707. });
  3708. const eukEvt = {};
  3709. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  3710. const euyEvt = new Proxy(eukEvt, {
  3711. get(target, prop) {
  3712. if (prop === 'deltaY' || prop === 'deltaX') {
  3713. euyVal = euyVal | 1;
  3714. return -999;
  3715. }
  3716. if (prop === 'target') {
  3717. euyVal = euyVal | 2;
  3718. return euxElm
  3719. }
  3720. if (prop === 'path' || prop === 'composedPath') {
  3721. euyVal = euyVal | 2;
  3722. return [euxElm]
  3723. }
  3724. throw `ErrorF51.get(${prop})`
  3725. },
  3726. set(target, prop, value) {
  3727. throw `ErrorF53.set(${prop}, ${value})`
  3728. }
  3729. });
  3730. const setVal = (v) => {
  3731. euyVal = v;
  3732. }
  3733. const getVal = () => {
  3734. return euyVal;
  3735. }
  3736. return { euzObj, euyEvt, setVal, getVal };
  3737. }
  3738.  
  3739. let checkWheelListener = (callback) => {
  3740.  
  3741. let callbackIdentifier = '';
  3742.  
  3743. let res = null;
  3744. try {
  3745. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  3746. setVal(0);
  3747. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  3748. throw `RESULT${getVal()}`;
  3749. } catch (e) {
  3750. res = e;
  3751. }
  3752.  
  3753. res = `${res}` || `${null}`;
  3754. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  3755.  
  3756. callbackIdentifier = res;
  3757. if (callbackIdentifier === 'RESULT27') 0;
  3758. else if (callbackIdentifier === 'RESULT0') {
  3759. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  3760. } else if (callbackIdentifier.startsWith('RESULT')) {
  3761. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  3762. }
  3763. return callbackIdentifier;
  3764.  
  3765. };
  3766.  
  3767. let callbackFound = false;
  3768. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  3769. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  3770. // M-youtube-js-engine-tamer.52178
  3771. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  3772. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  3773. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  3774. // RESULTXX / ErrorFXX / Other...
  3775. if (callbackIdentifier === 'RESULT27') {
  3776. this.overscrollConfigDisable = true;
  3777. if (!callbackFound) {
  3778. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  3779. getObjsFn = checkWheelListener = null;
  3780. checkWheelListenerObjs = null;
  3781. wheelHandler = null;
  3782. }
  3783. return void 0;
  3784. } else if (!callbackFound && !this.overscrollConfigDisable) {
  3785. this.overscrollConfigDisable = true;
  3786. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  3787. }
  3788. }
  3789. return this.addEventListener52178(type, callback, option);
  3790. };
  3791.  
  3792. // ---- << this.overscrollConfig HACK >> -----
  3793.  
  3794. }
  3795.  
  3796. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  3797.  
  3798. let p_a_objWR = null;
  3799. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  3800. let ytPageReady = 0;
  3801.  
  3802. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  3803. let isGlobalSpaceControl = true;
  3804. let mediaPlayerElementWR = null;
  3805. let focusedElementAtSelection = null;
  3806.  
  3807. // let want_control_video = false;
  3808.  
  3809. let spaceBarControl_keyG = '';
  3810.  
  3811. let lastUserAction = 0;
  3812.  
  3813. const wmKeyControlPhase = new WeakMap();
  3814.  
  3815. let currentSelectionText = null;
  3816.  
  3817. const getCurrentSelectionText = () => {
  3818. if (currentSelectionText !== null) return currentSelectionText
  3819. return (currentSelectionText = `${getSelection()}`)
  3820. }
  3821.  
  3822. const pageMediaWatcher = () => {
  3823.  
  3824. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  3825. // want_control_video = false;
  3826. // }, { capture: true, passive: true });
  3827.  
  3828. document.addEventListener('yt-navigate', () => {
  3829. ytPageReady = 0;
  3830. });
  3831. document.addEventListener('yt-navigate-start', () => {
  3832. ytPageReady = 0;
  3833. });
  3834. document.addEventListener('yt-navigate-cache', () => {
  3835. ytPageReady = 0;
  3836. });
  3837.  
  3838. document.addEventListener('yt-navigate-finish', () => {
  3839. ytPageReady = 1;
  3840. });
  3841.  
  3842. document.addEventListener('durationchange', () => {
  3843. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  3844. if (elm.duration > 0.01) {
  3845. if (elm.closest('[hidden]')) continue;
  3846. mediaPlayerElementWR = mWeakRef(elm);
  3847. return;
  3848. }
  3849. }
  3850. }, { capture: true, passive: true });
  3851.  
  3852. document.addEventListener('selectionchange', (evt) => {
  3853. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  3854. currentSelectionText = null;
  3855. if (!(evt.target instanceof Node)) return;
  3856. focusedElementAtSelection = evt.target;
  3857. }, { capture: true, passive: true })
  3858.  
  3859. document.addEventListener('pointerdown', (evt) => {
  3860. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3861. }, { capture: true, passive: true });
  3862.  
  3863.  
  3864. document.addEventListener('pointerup', (evt) => {
  3865. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3866. }, { capture: true, passive: true });
  3867.  
  3868.  
  3869. document.addEventListener('keydown', (evt) => {
  3870. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3871. }, { capture: true, passive: true });
  3872.  
  3873. document.addEventListener('keyup', (evt) => {
  3874. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3875. }, { capture: true, passive: true });
  3876.  
  3877. };
  3878.  
  3879.  
  3880. const checkKeyB = (p_a_obj) => {
  3881.  
  3882. const boolList = new Set();
  3883. const p_a_obj_api = p_a_obj.api;
  3884.  
  3885. const nilFunc0 = function () {
  3886. return void 0
  3887. };
  3888. const mt = new Proxy({}, {
  3889. get(target, prop) {
  3890. if (prop === 'get') return nilFunc0;
  3891. return mt;
  3892. }
  3893. });
  3894. const nilFunc = function () {
  3895. return mt
  3896. };
  3897. const mw = new Proxy({}, {
  3898. get(target, prop) {
  3899. if (prop in p_a_obj_api) {
  3900. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  3901. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  3902. if (q && q.value) {
  3903. if (!q.writable) return q.value;
  3904. if (typeof q.value === 'string') return '';
  3905. if (typeof q.value === 'number') return 0;
  3906. if (typeof q.value === 'boolean') return false;
  3907. if (q.value && typeof q.value === 'object') return {};
  3908. }
  3909. }
  3910. return undefined;
  3911. },
  3912. set(target, prop) {
  3913. throw 'mwSet';
  3914. }
  3915. });
  3916.  
  3917. const mq = new Proxy({}, {
  3918. get(target, prop) {
  3919. if (prop === 'api') return mw;
  3920. if (prop in p_a_obj) {
  3921. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  3922. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  3923. if (q && q.value) {
  3924. if (!q.writable) return q.value;
  3925. if (typeof q.value === 'string') return '';
  3926. if (typeof q.value === 'number') return 0;
  3927. if (typeof q.value === 'boolean') return false;
  3928. if (q.value && typeof q.value === 'object') return {};
  3929. }
  3930. }
  3931. return undefined;
  3932. },
  3933. set(target, prop, val) {
  3934. if (typeof val === 'boolean') boolList.add(prop)
  3935. throw `mqSet(${prop},${val})`;
  3936. }
  3937. });
  3938.  
  3939. let res = ''
  3940. try {
  3941. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  3942. } catch (e) {
  3943. res = `ERROR::${e}`;
  3944. }
  3945.  
  3946. if (boolList.size === 1) {
  3947. const value = boolList.values().next().value;
  3948. if (res === `ERROR::mqSet(${value},${true})`) {
  3949. p_a_obj.__uZWaD__ = value;
  3950. }
  3951. }
  3952.  
  3953. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  3954.  
  3955. }
  3956.  
  3957.  
  3958. let pm_p_a = null;
  3959.  
  3960. const p_a_init = function () {
  3961. const r = this.init91();
  3962. const keyBw = this.__cPzfo__ || '__NIL__';
  3963. const p_a_obj = this[keyBw];
  3964. if (!p_a_obj) return;
  3965. try {
  3966. checkKeyB(p_a_obj);
  3967. } catch (e) { }
  3968. p_a_objWR = mWeakRef(p_a_obj);
  3969. if (FIX_SHORTCUTKEYS > 0) {
  3970. if (p_a_obj && !p_a_obj.hVhtg) {
  3971. p_a_obj.hVhtg = 1;
  3972.  
  3973. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  3974. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  3975. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  3976. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  3977. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  3978. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  3979.  
  3980. }
  3981. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  3982. // const api = p_a_obj.api
  3983. // api.hVhtg = 1;
  3984. // api.playVideo91 = api.playVideo;
  3985. // api.playVideo = p_a_jt.playVideo;
  3986. // api.pauseVideo91 = api.pauseVideo;
  3987. // api.pauseVideo = p_a_jt.pauseVideo;
  3988. // }
  3989. }
  3990. if (pm_p_a) {
  3991. pm_p_a.resolve();
  3992. pm_p_a = null;
  3993. }
  3994. return r;
  3995. };
  3996.  
  3997. const p_a_xt = {
  3998.  
  3999. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  4000.  
  4001. if (FIX_SHORTCUTKEYS === 2) {
  4002.  
  4003. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  4004.  
  4005. if (activeElement) {
  4006.  
  4007. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  4008.  
  4009. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  4010. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  4011. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  4012.  
  4013. }
  4014.  
  4015. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  4016. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  4017. // console.log(582, isDelayedSpaceBar)
  4018. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  4019.  
  4020. if (activeElement && (h === 'Space' || h === 'Enter')) {
  4021. const controlPhase = wmKeyControlPhase.get(activeElement);
  4022. if (controlPhase === 4 || controlPhase === 5) return false;
  4023. }
  4024. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  4025. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  4026. // if (!isSpaceKeyImmediate) return false;
  4027. // }
  4028. }
  4029.  
  4030. },
  4031.  
  4032. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  4033.  
  4034. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  4035.  
  4036. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  4037. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  4038. // console.log(583, isDelayedSpaceBar)
  4039. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  4040.  
  4041. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4042.  
  4043. let mediaWorking = false;
  4044. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  4045. mediaWorking = true;
  4046. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  4047. mediaWorking = true;
  4048. }
  4049. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  4050. mediaWorking && Promise.resolve().then(() => {
  4051. if (activeElement === document.activeElement) {
  4052. return activeElement.blur()
  4053. } else {
  4054. return false
  4055. }
  4056. }).then((r) => {
  4057. r !== false && mediaPlayerElement.focus();
  4058. });
  4059. }
  4060. },
  4061.  
  4062.  
  4063. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  4064.  
  4065. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  4066.  
  4067. const activeElement = document.activeElement;
  4068.  
  4069. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  4070. if (allow === false) return false;
  4071.  
  4072. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  4073. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  4074.  
  4075. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  4076.  
  4077. return ret;
  4078. },
  4079. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  4080.  
  4081.  
  4082. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  4083.  
  4084. const activeElement = document.activeElement;
  4085. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4086. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  4087. // }
  4088. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  4089. if (allow === false) return false;
  4090.  
  4091. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  4092. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  4093.  
  4094. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  4095.  
  4096. return ret;
  4097. }
  4098.  
  4099. };
  4100.  
  4101. // const p_a_jt = { // API
  4102.  
  4103. // playVideo(a) { // without spinner effect
  4104.  
  4105. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  4106.  
  4107. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4108. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  4109. // want_control_video = true;
  4110. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  4111. // }
  4112.  
  4113. // }
  4114. // return this.playVideo91(a);
  4115.  
  4116. // },
  4117.  
  4118. // pauseVideo(a) { // without spinner effect
  4119.  
  4120. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  4121.  
  4122. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4123. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  4124. // want_control_video = true;
  4125. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  4126. // }
  4127.  
  4128. // }
  4129. // return this.pauseVideo91(a);
  4130.  
  4131. // }
  4132. // };
  4133.  
  4134. let flagSpeedMaster = null;
  4135. const getSpeedMasterControlFlag = () => {
  4136.  
  4137. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4138. isSpeedMastSpacebarControlEnabled = false;
  4139. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  4140. isSpeedMastSpacebarControlEnabled = true;
  4141. }
  4142. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  4143. isSpeedMastSpacebarControlEnabled = true;
  4144. }
  4145.  
  4146. if (flagSpeedMaster === null) {
  4147. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  4148. if (!p) {
  4149. flagSpeedMaster = false;
  4150. } else {
  4151.  
  4152. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  4153.  
  4154. }
  4155.  
  4156. }
  4157. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  4158.  
  4159. return isSpeedMastSpacebarControlEnabled;
  4160. }
  4161.  
  4162.  
  4163. const getGlobalSpacebarControlFlag = () => {
  4164.  
  4165. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4166. isGlobalSpaceControl = false;
  4167. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  4168. isGlobalSpaceControl = true;
  4169. }
  4170. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  4171. isGlobalSpaceControl = true;
  4172. }
  4173.  
  4174. return isGlobalSpaceControl;
  4175. }
  4176.  
  4177. const keyboardController = async (_yt_player) => {
  4178.  
  4179. const keyQT = getQT(_yt_player);
  4180. const keySV = getSV(_yt_player);
  4181. const keyDX = getDX(_yt_player);
  4182. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  4183.  
  4184. if (!keyDX) return;
  4185. if (keyDX === keyQT || keyDX === keySV) return;
  4186.  
  4187. if (typeof keyDX !== 'string') return;
  4188.  
  4189. let lastAccessKey = '';
  4190. let lastAccessKeyConfirmed = '';
  4191. const mb = new Proxy({}, {
  4192. get(target, prop) {
  4193. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  4194. throw 'mbGet'
  4195. },
  4196. set(target, prop, val) {
  4197. throw 'mbSet'
  4198. }
  4199. });
  4200. const ma = new Proxy({}, {
  4201. get(target, prop) {
  4202. lastAccessKey = prop;
  4203. return mb
  4204. },
  4205. set(target, prop, val) {
  4206. throw 'maSet'
  4207. }
  4208. });
  4209.  
  4210. let keyBw = '';
  4211. try {
  4212. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  4213. } catch (e) {
  4214. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  4215. keyBw = lastAccessKeyConfirmed;
  4216. }
  4217. }
  4218.  
  4219. if (!keyBw) return;
  4220.  
  4221. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  4222.  
  4223. pm_p_a = new PromiseExternal();
  4224.  
  4225. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  4226.  
  4227. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  4228.  
  4229. _yt_player[keyDX].prototype.init = p_a_init;
  4230.  
  4231. await pm_p_a.then();
  4232. const p_a_obj = kRef(p_a_objWR);
  4233.  
  4234. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  4235.  
  4236.  
  4237. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  4238.  
  4239. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  4240.  
  4241. if (!isSpeedMastSpacebarControlEnabled) {
  4242.  
  4243. if (config && config.EXPERIMENT_FLAGS) {
  4244. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  4245. }
  4246. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  4247. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  4248. }
  4249.  
  4250. } else {
  4251.  
  4252. if (config && config.EXPERIMENT_FLAGS) {
  4253. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  4254. }
  4255. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  4256. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  4257. }
  4258.  
  4259. }
  4260.  
  4261. }
  4262.  
  4263. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  4264.  
  4265.  
  4266.  
  4267.  
  4268. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  4269.  
  4270. // console.log(p_a_obj.handleGlobalKeyUp)
  4271. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  4272.  
  4273. // console.log(p_a_obj.api)
  4274.  
  4275.  
  4276. // QT -> DX(SV) -> p_a
  4277.  
  4278.  
  4279. /*
  4280. *
  4281. *
  4282. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  4283. b = void 0 === b ? !1 : b;
  4284. c = void 0 === c ? !1 : c;
  4285. d = void 0 === d ? !1 : d;
  4286. e = void 0 === e ? !1 : e;
  4287. var l = g.PT(this);
  4288. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  4289. }
  4290.  
  4291. */
  4292.  
  4293. /*
  4294. *
  4295. *
  4296. *
  4297. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  4298. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  4299. }
  4300.  
  4301. */
  4302.  
  4303.  
  4304. // if(!keyDX) return;
  4305.  
  4306. // console.log(4999, keyDX)
  4307.  
  4308. };
  4309.  
  4310.  
  4311. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  4312.  
  4313. const p_a_obj = kRef(p_a_objWR);
  4314. // const api = p_a_obj.api;
  4315.  
  4316.  
  4317. // console.log(540);
  4318.  
  4319. let boolList = null;
  4320. let ret;
  4321. isSpaceKeyImmediate = true;
  4322. try {
  4323.  
  4324. ret = 0;
  4325. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  4326. let p_a_objT;
  4327. if (!spaceBarControl_keyG) { // just in case
  4328. boolList = new Set();
  4329. p_a_objT = new Proxy(p_a_obj, {
  4330. get(target, prop, handler) {
  4331. const val = target[prop];
  4332. if (typeof val !== 'boolean') return val;
  4333. boolList.add(prop);
  4334. // console.log(555, prop, val);
  4335. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  4336. spaceBarControl_keyG = prop;
  4337. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4338. val = false;
  4339. }
  4340. return val;
  4341. }
  4342. });
  4343.  
  4344.  
  4345. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  4346. p_a_obj[spaceBarControl_keyG] = false;
  4347. p_a_objT = p_a_obj;
  4348. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  4349. } else {
  4350.  
  4351. p_a_objT = p_a_obj;
  4352. }
  4353.  
  4354. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  4355.  
  4356.  
  4357. } catch (e) {
  4358. console.log(e)
  4359. }
  4360. isSpaceKeyImmediate = false;
  4361.  
  4362. if (boolList && boolList.size === 1) {
  4363. const value = boolList.values().next().value;
  4364. spaceBarControl_keyG = value;
  4365. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4366.  
  4367. }
  4368.  
  4369. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4370.  
  4371. return ret;
  4372. }
  4373.  
  4374. const shortcutKeysFixer = () => {
  4375.  
  4376. let pausePromiseControlJ = 0;
  4377.  
  4378.  
  4379. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  4380.  
  4381. let controlPhase = 0;
  4382. const aElm = document.activeElement;
  4383.  
  4384. if (aElm) {
  4385.  
  4386. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  4387.  
  4388. if (typeof controlPhaseCache === 'number') {
  4389.  
  4390. controlPhase = controlPhaseCache;
  4391. } else {
  4392.  
  4393. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  4394. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  4395. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  4396. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  4397. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  4398. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  4399. else {
  4400. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  4401. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  4402. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  4403. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  4404. }
  4405.  
  4406. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  4407. controlPhase = 0;
  4408. }
  4409.  
  4410. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  4411. if (aElm.closest('[contenteditable], input, textarea')) {
  4412. controlPhase = 5;
  4413. } else if (aElm.closest('button')) {
  4414. controlPhase = 4;
  4415. }
  4416. }
  4417.  
  4418. if (aElm.closest('#movie_player')) controlPhase = 6;
  4419.  
  4420. wmKeyControlPhase.set(aElm, controlPhase);
  4421.  
  4422. }
  4423. }
  4424.  
  4425. return controlPhase;
  4426.  
  4427. }
  4428.  
  4429. const isStateControllable = (api) => {
  4430. let appState = null;
  4431. let playerState = null;
  4432. let adState = null;
  4433. try {
  4434. appState = api.getAppState();
  4435. playerState = api.getPlayerState();
  4436. adState = api.getAdState();
  4437. } catch (e) { }
  4438. // ignore playerState -1
  4439. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  4440. };
  4441.  
  4442.  
  4443. const keyEventListener = (evt) => {
  4444. if (BY_PASS_KEYBOARD_CONTROL) return;
  4445.  
  4446. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4447. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  4448. if (!ytPageReady) return;
  4449.  
  4450. if (evt.defaultPrevented === true) return;
  4451.  
  4452. const p_a_obj = kRef(p_a_objWR);
  4453.  
  4454. if (!p_a_obj) return;
  4455.  
  4456.  
  4457. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4458. if (!mediaPlayerElement) return;
  4459.  
  4460. // let focusBodyIfSuccess = false;
  4461.  
  4462. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  4463.  
  4464. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  4465. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  4466. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  4467.  
  4468.  
  4469. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  4470.  
  4471. // console.log(`${evt.type}::controlPhase`,controlPhase)
  4472.  
  4473. // if (controlPhase == 4) {
  4474. // focusBodyIfSuccess = true;
  4475. // }
  4476.  
  4477. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  4478. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4479.  
  4480. if (FIX_SHORTCUTKEYS < 2) return;
  4481. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  4482.  
  4483. let rr;
  4484. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  4485.  
  4486.  
  4487.  
  4488. let useImprovedPauseResume = false;
  4489.  
  4490. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4491.  
  4492. const api = p_a_obj.api;
  4493. const stateControllable = isStateControllable(api);
  4494. // console.log(2122, appState, playerState, adState)
  4495.  
  4496. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  4497.  
  4498. useImprovedPauseResume = true;
  4499.  
  4500. }
  4501.  
  4502.  
  4503. }
  4504.  
  4505.  
  4506. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  4507. if (evt.type === 'keydown') {
  4508.  
  4509. if (useImprovedPauseResume) {
  4510.  
  4511. const isPaused = mediaPlayerElement.paused;
  4512.  
  4513. const cj = ++pausePromiseControlJ;
  4514. Promise.resolve().then(() => {
  4515.  
  4516. if (cj !== pausePromiseControlJ) return;
  4517.  
  4518. if (mediaPlayerElement.paused !== isPaused) return;
  4519.  
  4520. const ret = ytResumeFn();
  4521. if (!ret) { // fallback
  4522. isPaused ? api.playVideo() : api.pauseVideo();
  4523. }
  4524.  
  4525. /*
  4526. let a = void 0;
  4527. console.log('Rb', api.Rb())
  4528. a = !window._yt_player.nL(api.Rb());
  4529. p_a_obj.Wd.kG(a)
  4530. a ? api.playVideo() : api.pauseVideo();
  4531.  
  4532. */
  4533.  
  4534.  
  4535. });
  4536. rr = true;
  4537. } else {
  4538.  
  4539. isSpaceKeyImmediate = true;
  4540. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  4541. isSpaceKeyImmediate = false;
  4542. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4543.  
  4544. }
  4545.  
  4546.  
  4547. } else if (evt.type === 'keyup') {
  4548.  
  4549. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4550.  
  4551. rr = true;
  4552. } else {
  4553.  
  4554. isSpaceKeyImmediate = true;
  4555. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  4556. isSpaceKeyImmediate = false;
  4557. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4558.  
  4559. }
  4560.  
  4561.  
  4562. /*
  4563.  
  4564. if (d)
  4565. switch (c) {
  4566. case 32:
  4567. case 13:
  4568. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  4569. b = !0,
  4570. e = !1;
  4571. else if (e) {
  4572. var m = d.getAttribute("role");
  4573. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  4574. d.click(),
  4575. f = !0)
  4576. }
  4577. break;
  4578. case 37:
  4579. case 39:
  4580. case 36:
  4581. case 35:
  4582. b = "slider" === d.getAttribute("role");
  4583. break;
  4584. case 38:
  4585. case 40:
  4586. m = d.getAttribute("role"),
  4587. d = 38 === c ? d.previousSibling : d.nextSibling,
  4588. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  4589. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  4590. f = b = !0))
  4591. }
  4592. if (e && !f)
  4593. switch (c) {
  4594. case 38:
  4595. f = Math.min(this.api.getVolume() + 5, 100);
  4596. XV(this.Wd, f, !1);
  4597. this.api.setVolume(f);
  4598. h = f = !0;
  4599. break;
  4600. case 40:
  4601. f = Math.max(this.api.getVolume() - 5, 0);
  4602. XV(this.Wd, f, !0);
  4603. this.api.setVolume(f);
  4604. h = f = !0;
  4605. break;
  4606. case 36:
  4607. this.api.Yh() && (this.api.startSeekCsiAction(),
  4608. this.api.seekTo(0, void 0, void 0, void 0, 79),
  4609. h = f = !0);
  4610. break;
  4611. case 35:
  4612. this.api.Yh() && (this.api.startSeekCsiAction(),
  4613. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  4614. h = f = !0)
  4615. }
  4616. */
  4617.  
  4618. }
  4619.  
  4620.  
  4621. if (rr) {
  4622.  
  4623. // focusBodyIfSuccess && Promise.resolve().then(() => {
  4624. // activeElement === document.activeElement && activeElement.blur();
  4625. // });
  4626.  
  4627. evt.preventDefault();
  4628. evt.stopImmediatePropagation();
  4629. evt.stopPropagation();
  4630.  
  4631. }
  4632.  
  4633. };
  4634.  
  4635. document.addEventListener('keydown', keyEventListener, { capture: true });
  4636.  
  4637.  
  4638. document.addEventListener('keyup', keyEventListener, { capture: true });
  4639.  
  4640. }
  4641.  
  4642. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  4643.  
  4644. })();
  4645.  
  4646.  
  4647. pageMediaWatcher();
  4648. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  4649.  
  4650.  
  4651. const check_for_set_key_order = (() => {
  4652.  
  4653. let mySet = new Set();
  4654.  
  4655. mySet.add("value1");
  4656. mySet.add("value2");
  4657. mySet.add("value3");
  4658.  
  4659. // Function to convert Set values to an array
  4660. function getSetValues(set) {
  4661. return Array.from(set.values());
  4662. }
  4663.  
  4664. // Function to test if the Set maintains insertion order
  4665. function testSetOrder(set, expectedOrder) {
  4666. let values = getSetValues(set);
  4667. return expectedOrder.join(',') === values.join(',');
  4668. }
  4669.  
  4670. // Test 1: Initial order
  4671. if (mySet.values().next().value !== "value1") return false;
  4672. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  4673.  
  4674. // Test 2: After deleting an element
  4675. mySet.delete("value2");
  4676. if (mySet.values().next().value !== "value1") return false;
  4677. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  4678.  
  4679. // Test 3: After re-adding a deleted element
  4680. mySet.add("value2");
  4681. if (mySet.values().next().value !== "value1") return false;
  4682. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  4683.  
  4684. // Test 4: After adding a new element
  4685. mySet.add("value4");
  4686. if (mySet.values().next().value !== "value1") return false;
  4687. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  4688.  
  4689. // Test 5: Delete+Add
  4690. mySet.delete("value1");
  4691. mySet.delete("value3");
  4692. mySet.add("value3");
  4693. mySet.add("value1");
  4694. if (mySet.values().next().value !== "value2") return false;
  4695. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  4696.  
  4697. return true;
  4698. })();
  4699.  
  4700.  
  4701. // const qm47 = Symbol();
  4702. const qm57 = Symbol();
  4703. const qm53 = Symbol();
  4704. const qn53 = Symbol();
  4705.  
  4706.  
  4707. const ump3 = new WeakMap();
  4708.  
  4709. const stp = document.createElement('noscript');
  4710. stp.id = 'weakref-placeholder';
  4711.  
  4712. PROP_OverReInclusion_AVOID && (() => {
  4713.  
  4714.  
  4715. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  4716. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  4717. let byPassVal = null;
  4718. let byPassCount = 0;
  4719. let mmw = new Set();
  4720. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  4721. if (arguments.length !== 1) return f.apply(this, arguments);
  4722. if (byPassVal !== null && typeof prop === 'string') {
  4723.  
  4724. if (PROP_OverReInclusion_LIST.has(prop)) {
  4725. byPassCount++;
  4726. return byPassVal;
  4727. }
  4728. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  4729.  
  4730. }
  4731. return this.hasOwnProperty72(prop);
  4732. };
  4733.  
  4734.  
  4735. /*
  4736.  
  4737.  
  4738. z.prototype.forwardDynamicProps = function() {
  4739. var B = m(this.inst);
  4740. B = h(B);
  4741. for (var F = B.next(); !F.done; F = B.next()) {
  4742. var H = h(F.value);
  4743. F = H.next().value;
  4744. H = H.next().value;
  4745. my(this, F, H);
  4746. r(b) && !ly(F) && Wua(this.inst, F)
  4747. }
  4748. }
  4749.  
  4750. */
  4751.  
  4752.  
  4753.  
  4754. let byPassZeroShowed = false;
  4755. const forwardDynamicPropsGeneral = function () {
  4756. byPassVal = true;
  4757. byPassCount = 0;
  4758. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  4759. const ret = this.forwardDynamicProps72();
  4760. byPassVal = null;
  4761. if (byPassCount === 0 && !byPassZeroShowed) {
  4762. byPassZeroShowed = true;
  4763. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  4764. }
  4765. byPassCount = 0;
  4766. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  4767. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  4768. mmw.clear();
  4769. }
  4770. return ret;
  4771. };
  4772.  
  4773. const propCheck = (proto) => {
  4774. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  4775. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  4776. if (proto.forwardDynamicProps.length === 0) {
  4777. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  4778. }
  4779. }
  4780. };
  4781.  
  4782. const valMap = new WeakMap();
  4783. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  4784. get() {
  4785. propCheck(this.constructor.prototype);
  4786. return valMap.get(this);
  4787. },
  4788. set(nv) {
  4789. propCheck(this.constructor.prototype);
  4790. valMap.set(this, nv);
  4791. return true;
  4792. },
  4793. enumerable: false,
  4794. configurable: true
  4795.  
  4796. });
  4797.  
  4798. promiseForCustomYtElementsReady.then(() => {
  4799. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  4800. if (customElements.define.length !== 2) return;
  4801. customElements.define72 = customElements.define;
  4802. customElements.define = function (b, w) {
  4803. propCheck(w.prototype);
  4804. const ret = this.define72(b, w);
  4805. return ret;
  4806. }
  4807. });
  4808.  
  4809. })();
  4810.  
  4811.  
  4812. let marcoPr = new PromiseExternal();
  4813. const trackMarcoCm = document.createComment('1');
  4814. const trackMarcoCmObs = new MutationObserver(() => {
  4815. marcoPr.resolve();
  4816. marcoPr = new PromiseExternal();
  4817. });
  4818. trackMarcoCmObs.observe(trackMarcoCm, { characterData: true });
  4819.  
  4820.  
  4821. // ----------------------------
  4822.  
  4823.  
  4824. // const pendingStampFlushs = [];
  4825.  
  4826. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  4827.  
  4828. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  4829.  
  4830. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  4831.  
  4832.  
  4833. // const globalPromiseStack = {};
  4834.  
  4835. // let dummy;
  4836. // while(!dummy){
  4837.  
  4838. // dummy = document.querySelector('yt-icon');
  4839. // await new Promise(r=>setTimeout(r,0));
  4840. // }
  4841.  
  4842. dummy = document.createElement('yt-icon');
  4843.  
  4844. let cProto;
  4845. if (!(dummy instanceof Element)) return;
  4846. cProto = insp(dummy).constructor.prototype;
  4847.  
  4848. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  4849. cProto.determineIconSet671 = cProto.determineIconSet;
  4850. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  4851. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  4852. cProto.getIconManager671 = cProto.getIconManager;
  4853. cProto.getIconShapeData671 = cProto.getIconShapeData;
  4854. cProto.renderIcon671 = cProto.renderIcon;
  4855.  
  4856. // cProto.attached488 = cProto.attached;
  4857. // cProto.attached = function(){
  4858. // console.log('attached')
  4859. // return this.attached488(...arguments);
  4860. // }
  4861. // cProto.detached488 = cProto.detached;
  4862. // cProto.detached = function(){
  4863. // console.log('detached')
  4864. // return this.detached488(...arguments);
  4865. // }
  4866.  
  4867. if (cProto.__renderIconFix__) return;
  4868. cProto.__renderIconFix__ = true;
  4869.  
  4870. let taskStack = [];
  4871. const cmObs = new MutationObserver(() => {
  4872. const tasks = taskStack.slice();
  4873. taskStack.length = 0;
  4874. for (const task of tasks) {
  4875. task();
  4876. }
  4877. })
  4878. const cm = document.createComment('1');
  4879. const stackTask = (f) => {
  4880. taskStack.push(f);
  4881. cm.data = `${(cm.data & 7) + 1}`;
  4882. }
  4883. cmObs.observe(cm, { characterData: true });
  4884.  
  4885. // let iconManagers = {}; // assume shared
  4886.  
  4887. // window.iconManagers = () => iconManagers;
  4888.  
  4889.  
  4890. const setupYtIcon = (inst) => {
  4891.  
  4892. if (inst.__ytIconSetup588__) return;
  4893. const cProto = Reflect.getPrototypeOf(inst);
  4894. cProto.__ytIconSetup588__ = true;
  4895.  
  4896.  
  4897. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4898.  
  4899. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  4900. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  4901. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  4902. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  4903.  
  4904.  
  4905. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  4906. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  4907. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  4908. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  4909.  
  4910.  
  4911.  
  4912. }
  4913.  
  4914. cProto.handlePropertyChange = function (...a) { // 10+
  4915.  
  4916. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4917. this.__resolved__ = {
  4918.  
  4919. };
  4920. const a01 = this.isAttached;
  4921. let a02, a03;
  4922.  
  4923.  
  4924. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  4925.  
  4926. const stackFn = () => {
  4927. if (t !== this.__stackedKey3818__) {
  4928. return;
  4929. }
  4930. a03 = this.isAttached;
  4931.  
  4932. if (a01 === false && a02 === false && a03 === false) return;
  4933.  
  4934. if (a01 === true && a02 === true && a03 === true) {
  4935.  
  4936. } else {
  4937. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  4938. // unknown yt-icon#label-icon
  4939. return;
  4940. } else {
  4941. console.log('[yt-icon] debug', a01, a02, a03, this)
  4942. }
  4943. }
  4944.  
  4945. this.handlePropertyChange671(...arguments);
  4946.  
  4947. };
  4948.  
  4949.  
  4950.  
  4951. Promise.resolve().then(() => {
  4952. a02 = this.isAttached;
  4953. stackTask(stackFn);
  4954. });
  4955.  
  4956.  
  4957. }
  4958.  
  4959. cProto.determineIconSet = function (a, b, c, d) { // 10-
  4960.  
  4961. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4962. // string bool? bool=false int=24
  4963. // NOTIFICATIONS_NONE OR LIKE
  4964. // console.log('yt-icon.determineIconSet', ...arguments);
  4965.  
  4966. const r = this.determineIconSet671(...arguments);
  4967. return r;
  4968. }
  4969.  
  4970. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  4971.  
  4972. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4973. // same as determineIconSet
  4974. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  4975. return this.switchToYtSysIconset671(...arguments);
  4976. }
  4977.  
  4978. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  4979.  
  4980. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4981. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  4982. return this.useYtSysIconsetForMissingIcons671(...arguments);
  4983. }
  4984.  
  4985. cProto.getIconManager = function () { // 10+
  4986.  
  4987. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4988. if (!this.__resolved__) this.__resolved__ = {};
  4989. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  4990. const r = this.__resolved__.getIconManager;
  4991. return r;
  4992. }
  4993.  
  4994. cProto.getIconShapeData = function () { // 10+
  4995.  
  4996. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4997.  
  4998. // no argument
  4999. // console.log('yt-icon.getIconShapeData', ...arguments);
  5000. if (!this.__resolved__) this.__resolved__ = {};
  5001. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  5002. const r = this.__resolved__.getIconShapeData;
  5003. return r
  5004. }
  5005.  
  5006. cProto.renderIcon = function (a, b) { // X
  5007.  
  5008. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5009. // "" yt-icons:xxx
  5010. // console.log('yt-icon.renderIcon', ...arguments);
  5011. return this.renderIcon671(...arguments);
  5012. }
  5013.  
  5014. });
  5015.  
  5016.  
  5017. /**
  5018. * Compute the Longest Common Subsequence between two arrays.
  5019. * Returns an array of the LCS elements (in order).
  5020. */
  5021. function computeLCS(a, b) {
  5022. // Input validation
  5023. if (!Array.isArray(a) || !Array.isArray(b)) {
  5024. throw new Error('Inputs must be arrays');
  5025. }
  5026.  
  5027. const n = a.length, m = b.length;
  5028. // Early termination for trivial cases
  5029. if (n === 0 || m === 0) return [];
  5030. // Check for shallow equality
  5031. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  5032.  
  5033. // Use smaller dimension for space optimization
  5034. if (n > m) return computeLCS(b, a); // Ensure n <= m
  5035.  
  5036. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  5037. // Use Uint32Array for robustness with long sequences
  5038. const dp = [
  5039. new Uint32Array(m + 1),
  5040. new Uint32Array(m + 1),
  5041. ];
  5042. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  5043. // Optimize space by storing only necessary entries
  5044. const pred = new Uint8Array(n * m); // Single array for moves
  5045.  
  5046. for (let i = n - 1; i >= 0; i--) {
  5047. const curr = i % 2;
  5048. const next = 1 - curr;
  5049. // Clear current row for reuse
  5050. dp[curr].fill(0);
  5051.  
  5052. for (let j = m - 1; j >= 0; j--) {
  5053. const idx = i * m + j;
  5054. if (a[i] === b[j]) {
  5055. dp[curr][j] = dp[next][j + 1] + 1;
  5056. pred[idx] = 0; // Diagonal
  5057. } else if (dp[next][j] >= dp[curr][j + 1]) {
  5058. dp[curr][j] = dp[next][j];
  5059. pred[idx] = 1; // Down
  5060. } else {
  5061. dp[curr][j] = dp[curr][j + 1];
  5062. pred[idx] = 2; // Right
  5063. }
  5064. }
  5065. }
  5066.  
  5067. // Check for potential overflow
  5068. if (dp[0][0] > 0xFFFFFFFF) {
  5069. throw new Error('LCS length exceeds safe integer limit');
  5070. }
  5071.  
  5072. // Backtrack to build the actual LCS
  5073. const lcs = [];
  5074. let i = 0, j = 0;
  5075. while (i < n && j < m) {
  5076. const idx = i * m + j;
  5077. const p = pred[idx];
  5078. if (p === 0) {
  5079. lcs.push(a[i]);
  5080. i++; j++;
  5081. } else if (p === 1) {
  5082. i++;
  5083. } else {
  5084. j++;
  5085. }
  5086. }
  5087. return lcs;
  5088. }
  5089.  
  5090. /**
  5091. * Given original[] and modified[], produce an array of splice-ops:
  5092. * [ [start0, deleteCount0, addedItems0],
  5093. * [start1, deleteCount1, addedItems1],
  5094. * … ]
  5095. * When you do:
  5096. * let arr = original.slice();
  5097. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  5098. * arr will equal modified.
  5099. */
  5100. function diffSplices(original, modified) {
  5101. // Input validation
  5102. if (!Array.isArray(original) || !Array.isArray(modified)) {
  5103. throw new Error('Inputs must be arrays');
  5104. }
  5105.  
  5106. const origLen = original.length;
  5107. const modLen = modified.length;
  5108. // Early termination for trivial cases
  5109. if (origLen === 0 && modLen === 0) return [];
  5110. if (origLen === 0) return [[0, 0, modified.slice()]];
  5111. if (modLen === 0) return [[0, origLen, []]];
  5112.  
  5113. // Trim common prefix and suffix
  5114. let prefixLen = 0;
  5115. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  5116. prefixLen++;
  5117. }
  5118. let suffixLen = 0;
  5119. while (
  5120. suffixLen < origLen - prefixLen &&
  5121. suffixLen < modLen - prefixLen &&
  5122. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  5123. ) {
  5124. suffixLen++;
  5125. }
  5126.  
  5127. // Cache references for speed
  5128. const orig = original.slice(prefixLen, origLen - suffixLen);
  5129. const mod = modified.slice(prefixLen, modLen - suffixLen);
  5130. const lcs = computeLCS(orig, mod);
  5131. // Pre-allocate ops array, accounting for potential moves
  5132. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  5133. let opCount = 0;
  5134.  
  5135. let i = 0, j = 0, k = 0;
  5136. let curIndex = prefixLen;
  5137. const lcsLen = lcs.length;
  5138.  
  5139. while (k < lcsLen) {
  5140. const match = lcs[k];
  5141. let deleteCount = 0;
  5142. const deleted = [];
  5143. const added = [];
  5144.  
  5145. // 1) Collect deletions up to the next common element
  5146. while (i < orig.length && orig[i] !== match) {
  5147. deleted.push(orig[i]);
  5148. deleteCount++;
  5149. i++;
  5150. }
  5151.  
  5152. // 2) Collect insertions up to that same element
  5153. while (j < mod.length && mod[j] !== match) {
  5154. added.push(mod[j]);
  5155. j++;
  5156. }
  5157.  
  5158. // 3) Check for a move (deleted segment matches inserted segment)
  5159. let isMove = false;
  5160. if (deleteCount > 0 && deleteCount === added.length) {
  5161. isMove = deleted.every((x, idx) => x === added[idx]);
  5162. if (isMove) {
  5163. // If a move, split into delete and insert at different indices
  5164. if (deleteCount > 0) {
  5165. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  5166. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  5167. curIndex += added.length; // Advance past inserted items
  5168. }
  5169. }
  5170. }
  5171.  
  5172. // 4) Combine delete and insert into a single operation if not a move
  5173. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  5174. ops[opCount++] = [curIndex, deleteCount, added];
  5175. curIndex += added.length; // Advance past inserted items
  5176. }
  5177.  
  5178. // 5) Skip over the matching element itself
  5179. i++;
  5180. j++;
  5181. k++;
  5182. curIndex++;
  5183. }
  5184.  
  5185. // 6) Handle any trailing deletions and insertions as a single operation
  5186. const trailingDelete = orig.length - i;
  5187. const trailingAdd = mod.slice(j);
  5188. if (trailingDelete > 0 || trailingAdd.length > 0) {
  5189. // Check for trailing move
  5190. const trailingDeleted = orig.slice(i);
  5191. let isMove = false;
  5192. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  5193. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  5194. if (isMove) {
  5195. ops[opCount++] = [curIndex, trailingDelete, []];
  5196. ops[opCount++] = [curIndex, 0, trailingAdd];
  5197. }
  5198. }
  5199. if (!isMove) {
  5200. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  5201. }
  5202. }
  5203.  
  5204. // 7) Truncate ops array to actual size
  5205. ops.length = opCount;
  5206.  
  5207. return ops;
  5208. }
  5209. // class listPlaceholder {
  5210. // constructor(len){
  5211. // this.length = len;
  5212. // }
  5213. // }
  5214.  
  5215.  
  5216.  
  5217. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  5218. // var renderJob = this.renderJobsMap_[key],
  5219. // renderCallback = null;
  5220.  
  5221. // if (path === changeRecord.path) {
  5222. // let value = changeRecord.value;
  5223.  
  5224. // if (!_.v_(value)) {
  5225. // value = (value === void 0 || value === null) ? [] : [value];
  5226. // }
  5227.  
  5228. // let stampDomEntry = this.stampDom[path];
  5229.  
  5230. // if (stampDomEntry.mapping) {
  5231. // renderCallback = this.stampDomArray_.bind(
  5232. // this,
  5233. // value,
  5234. // key,
  5235. // stampDomEntry.mapping,
  5236. // stampDomEntry.reuseComponents,
  5237. // stampDomEntry.events,
  5238. // stampDomEntry.stamperStableList
  5239. // );
  5240. // }
  5241.  
  5242. // if (renderJob) renderJob.cancel();
  5243.  
  5244. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  5245.  
  5246. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  5247. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  5248. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  5249. // this.renderJobsMap_[key] = renderJob;
  5250. // }
  5251. // } else {
  5252. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  5253. // this.renderJobsMap_[key] = renderJob;
  5254. // renderCallback = function(callback, job) {
  5255. // callback();
  5256. // q4C(job, 10);
  5257. // }.bind(this, renderCallback, renderJob);
  5258. // }
  5259. // } else {
  5260. // renderCallback = (path + ".splices" === changeRecord.path)
  5261. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  5262. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  5263. // }
  5264.  
  5265. // if (renderJob) {
  5266. // _.vY(renderJob, renderCallback);
  5267. // } else {
  5268. // renderCallback();
  5269. // }
  5270. // }
  5271.  
  5272.  
  5273.  
  5274.  
  5275. const createStampDomFnsC_ = () => {
  5276.  
  5277. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  5278.  
  5279. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  5280. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  5281.  
  5282.  
  5283. // const rq0 = document.createElement('rp');
  5284. // rq0.setAttribute('yt-element-placholder', '');
  5285.  
  5286. const it0 = Date.now() - 80000000000;
  5287. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  5288.  
  5289.  
  5290. const getStampContainer_ = function (containerId) {
  5291.  
  5292. return this.getStampContainer7409_(containerId);
  5293.  
  5294. }
  5295.  
  5296.  
  5297.  
  5298.  
  5299. const createComponent_ = function (componentConfig, data, canReuse) {
  5300.  
  5301. return this.createComponent7409_(componentConfig, data, canReuse);
  5302.  
  5303. }
  5304.  
  5305.  
  5306. const s52 = Symbol();
  5307.  
  5308. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  5309.  
  5310. if (typeof (data || 0) === 'object') {
  5311. if (!data[s52]) data[s52] = genId();
  5312. component[s52] = data[s52];
  5313. // console.log(component[s52], data);
  5314. } else {
  5315. component[s52] = null;
  5316. }
  5317.  
  5318. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  5319.  
  5320. }
  5321.  
  5322. // let pr77 = Promise.resolve();
  5323.  
  5324. const flushRenderStamperComponentBindings_ = function () {
  5325. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  5326.  
  5327. if (this.deferredBindingTasks_.length >= 0) {
  5328.  
  5329. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  5330.  
  5331. const gid = this[`__$$stampFlushKey$$__`] = genId();
  5332. const g = (() => {
  5333. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  5334. // if (deferredBindingTasks_.length === 0) return;
  5335. // let q = this.deferredBindingTasks_;
  5336. // this.deferredBindingTasks_ = deferredBindingTasks_;
  5337. this.flushRenderStamperComponentBindings7409_();
  5338. // deferredBindingTasks_.length = 0;
  5339. // this.deferredBindingTasks_ = q;
  5340.  
  5341. const s = [...this.__lat457__];
  5342. this.__lat457__.clear();
  5343.  
  5344. for (const containerWr of s) {
  5345.  
  5346. const container = kRef(containerWr);
  5347. if (!container) continue;
  5348.  
  5349. // const s = new Set();
  5350. if (!container.querySelector('[ytx-flushing]')) {
  5351. if (container.hasAttribute('ytx-flushing')) {
  5352. const attrVal = container.getAttribute('ytx-flushing');
  5353. container.removeAttribute('ytx-flushing');
  5354. // s.add([container, attrVal]);
  5355. addTask(container, attrVal);
  5356. // addTaskIm(container, attrVal);
  5357. let ancestor = container.closest('[ytx-flushing]');
  5358. while (ancestor) {
  5359. if (ancestor.querySelector('[ytx-flushing]')) break;
  5360. const attrVal = ancestor.getAttribute('ytx-flushing');
  5361. ancestor.removeAttribute('ytx-flushing');
  5362. // s.add([ancestor, attrVal]);
  5363. addTask(ancestor, attrVal);
  5364. // addTaskIm(ancestor, attrVal);
  5365. ancestor = ancestor.closest('[ytx-flushing]');
  5366. }
  5367. }
  5368. }
  5369. }
  5370. executeTasks();
  5371.  
  5372.  
  5373. });
  5374. g();
  5375. // const useMicroTaskQueue = this.__qsd477__ === 2;
  5376. // useMicroTaskQueue ? addTask2(g) : g();
  5377. // executeTasks();
  5378.  
  5379. // addTask2(g);
  5380. // executeTasks();
  5381.  
  5382. }
  5383.  
  5384. throw new Error('e5bd8d2f');
  5385.  
  5386. }
  5387.  
  5388. let tasks = [];
  5389. let excuted = false;
  5390. const executeTasks = ()=>{
  5391. if(excuted || tasks.length === 0) return;
  5392. excuted = true;
  5393. let t0 = 0;
  5394. const perform = ()=>{
  5395. if(!t0) t0 = nativeNow();
  5396. const task = tasks.shift();
  5397. if(!task){
  5398. excuted = false;
  5399. return;
  5400. }
  5401. task.fn(task);
  5402. const t1 = nativeNow();
  5403. if(t1 - t0 > 10){
  5404. t0 = 0;
  5405. nextBrowserTick_(perform);
  5406. }else{
  5407. queueMicrotask_(perform);
  5408. }
  5409. }
  5410. queueMicrotask_(perform);
  5411. }
  5412.  
  5413. const taskFn = (task) => {
  5414.  
  5415. if(!task) return;
  5416. const { containerWr, attrVal } = task;
  5417. const container = kRef(containerWr);
  5418. if (!container) return;
  5419. if (attrVal === '0') return;
  5420. const bEventCb = attrVal === '2';
  5421. const producerWr = containerMapping.get(container);
  5422. const producer = kRef(producerWr);
  5423. if (!producer) return;
  5424. const hostElement = producer.hostElement;
  5425. if (!hostElement) return;
  5426. producer.markDirty && producer.markDirty();
  5427. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  5428. container
  5429. });
  5430.  
  5431. }
  5432.  
  5433. const addTask = (container, attrVal) => {
  5434. if (!container) return;
  5435. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  5436. tasks.push({
  5437. fn: taskFn,
  5438. containerWr: containerWr,
  5439. attrVal
  5440. });
  5441. // pr77 = pr77.then(()=>{
  5442.  
  5443. // })
  5444. // taskFn({
  5445. // containerWr: containerWr,
  5446. // attrVal
  5447. // })
  5448.  
  5449. }
  5450.  
  5451. const addTaskIm = (container, attrVal) => {
  5452. if (!container) return;
  5453. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  5454. taskFn({
  5455. fn: taskFn,
  5456. containerWr: containerWr,
  5457. attrVal
  5458. });
  5459.  
  5460. }
  5461.  
  5462.  
  5463. const addTask2 = (f) => {
  5464. // pr77 = pr77.then(f).catch(console.warn);
  5465. tasks.push({
  5466. fn: f
  5467. });
  5468.  
  5469. }
  5470.  
  5471. // const mo = new MutationObserver((mutations)=>{
  5472.  
  5473. // });
  5474. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  5475.  
  5476. const containerMapping = new WeakMap();
  5477.  
  5478. // let pr77 = Promise.resolve();
  5479. // let pr88 = Promise.resolve();
  5480. const uA4 = function (t, P) {
  5481. for (let y in t)
  5482. if (t.hasOwnProperty(y) && P[y])
  5483. return y;
  5484. return null
  5485. }
  5486.  
  5487. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  5488.  
  5489.  
  5490. const ax = ax_;
  5491. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  5492. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  5493. // const useMicroTaskQueue = false;
  5494. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  5495. ax[2].cancel();
  5496. useMicroTaskQueue2 = false;
  5497. }
  5498. // console.log(1992,containerId, this.hostElement.is)
  5499.  
  5500. const hostIs = hostIs_;
  5501.  
  5502. 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;
  5503.  
  5504. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  5505. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  5506. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  5507. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  5508. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  5509. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  5510. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  5511. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  5512. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  5513. 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;
  5514. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  5515. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  5516. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  5517. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  5518. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  5519. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  5520. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  5521. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  5522. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  5523.  
  5524.  
  5525. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  5526.  
  5527.  
  5528. // console.log(5992,stackAt)
  5529.  
  5530. // console.log(2883, this[`__quu477#${containerId}__`] )
  5531. // if (useMicroTaskQueue) {
  5532. // console.log(stackAt)
  5533. // }
  5534.  
  5535. // if (useMicroTaskQueue) {
  5536. // console.log(1120301)
  5537. // }
  5538.  
  5539. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  5540.  
  5541. return useMicroTaskQueue2;
  5542.  
  5543. }
  5544.  
  5545. const frag385 = document.createDocumentFragment();
  5546. const cm385 = document.createComment('.');
  5547.  
  5548. const doc385 = document.implementation.createHTMLDocument();
  5549. const html385 = doc385.firstElementChild;
  5550. const node385 = html385.appendChild(document.createElement('div'));
  5551.  
  5552. const fixContainerApi = (container) => {
  5553. if (container instanceof Node) {
  5554. const containerDomApi = container.__domApi;
  5555. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  5556. // console.log(123882, container)
  5557. containerDomApi.removeChild588 = containerDomApi.removeChild;
  5558. containerDomApi.removeChild = function (elem) {
  5559. if (elem.parentNode === (this.node || this)) {
  5560. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  5561. s.setAttribute('ytx-flushing', '0');
  5562. }
  5563. __forceRemoveMode__ = true;
  5564. node385.appendChild(cm385);
  5565. cm385.replaceWith(elem);
  5566. node385.textContent = '';
  5567. __forceRemoveMode__ = false;
  5568. }
  5569. }
  5570. }
  5571. }
  5572. }
  5573.  
  5574. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  5575.  
  5576. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  5577. if (typeof sqq === 'function') sqq();
  5578.  
  5579. // trigger in rendererStamperApplyChangeRecord_
  5580.  
  5581. // 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];
  5582. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  5583. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  5584. // 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];
  5585.  
  5586. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  5587. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  5588.  
  5589.  
  5590. const ax = this[`__quu477#${containerId}__`];
  5591. const hostIs = (this.hostElement || 0).is;
  5592. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  5593.  
  5594. const container = this.getStampContainer7409_(containerId);
  5595.  
  5596. containerMapping.set(container,
  5597. (this[wk] || (this[wk] = mWeakRef(this)))
  5598. );
  5599.  
  5600. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  5601. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  5602.  
  5603. // let dataList_ = dataList;
  5604. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  5605.  
  5606. dataList = null;
  5607. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  5608. let fq = 0;
  5609. const f = (() => {
  5610. if(fq) return;
  5611. fq = 1;
  5612. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  5613. this[`__$$stampSFn$$#${containerId}__`] = null;
  5614. const container = this.getStampContainer7409_(containerId);
  5615.  
  5616. this.__lat457__ = this.__lat457__ || new Set();
  5617. if(!container[wk]) container[wk] = mWeakRef(container);
  5618. this.__lat457__.add(container[wk]);
  5619. fixContainerApi(container);
  5620.  
  5621. // let q = this.deferredBindingTasks_;
  5622. // this.deferredBindingTasks_ = [];
  5623. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  5624. let e_;
  5625. try {
  5626. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  5627. } catch (e) { e_ = e }
  5628. this.__qsd477__ = false;
  5629. dataList_ = typeOrConfig = null;
  5630. fixContainerApi(container);
  5631. // this.deferredBindingTasks_ = q;
  5632. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  5633. if (!e_) {
  5634. // container.setAttribute('ytx-flushing', '0');
  5635. }
  5636. // if( container.childElementCount === 0 ){
  5637. // container.setAttribute('ytx-flushing', '0');
  5638. // this.markDirty && this.markDirty();
  5639. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  5640. // container
  5641. // });
  5642. // }
  5643.  
  5644.  
  5645.  
  5646.  
  5647. });
  5648. this[`__$$stampSFn$$#${containerId}__`] = f;
  5649. this[`__$$stampSqq$$#${containerId}__`] = f;
  5650. useMicroTaskQueue2 ? addTask2(f) : f();
  5651. executeTasks();
  5652.  
  5653. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  5654.  
  5655. return undefined;
  5656.  
  5657. }
  5658.  
  5659. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  5660.  
  5661.  
  5662. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  5663. if (typeof sqq === 'function') sqq();
  5664.  
  5665. // trigger in rendererStamperApplyChangeRecord_
  5666.  
  5667. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  5668. } else {
  5669. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  5670. }
  5671.  
  5672.  
  5673. // trigger in rendererStamperApplyChangeRecord_
  5674.  
  5675. // 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];
  5676. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  5677. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  5678.  
  5679. // 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];
  5680.  
  5681. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  5682. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  5683. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  5684.  
  5685. const ax = this[`__quu477#${containerId}__`];
  5686. const hostIs = (this.hostElement || 0).is;
  5687. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  5688.  
  5689.  
  5690. // 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];
  5691. // const useMicroTaskQueue = true;
  5692. const container = this.getStampContainer7409_(containerId);
  5693.  
  5694. containerMapping.set(container,
  5695. (this[wk] || (this[wk] = mWeakRef(this)))
  5696. );
  5697. const bEventCb = this.stampDom[stampKey].events;
  5698. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  5699. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  5700.  
  5701. // let indexSplicesObj_ = indexSplicesObj;
  5702. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  5703. // indexSplicesObj_ = {
  5704. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  5705. // const { index, addedCount, removed, object, type } = slice;
  5706. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  5707. // return { index, addedCount, removed, object, type };
  5708. // })
  5709. // };
  5710. // }
  5711.  
  5712.  
  5713. indexSplicesObj.indexSplices.forEach(slice => {
  5714. const object = slice.object;
  5715. if (!object || typeof object !== 'object') return;
  5716. // const { index, addedCount, removed, object, type } = slice;
  5717. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  5718. // return { index, addedCount, removed, object, type };
  5719. });
  5720.  
  5721. // let indexSplicesObj_ = indexSplicesObj;
  5722.  
  5723. // console.log(128783, indexSplicesObj)
  5724.  
  5725. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  5726. // const { index, addedCount, removed, object, type } = slice;
  5727. // return { index, addedCount, removed, object, type };
  5728. // });
  5729.  
  5730. indexSplicesObj = null;
  5731.  
  5732. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  5733. const gid = this[`__$$stampSID$$#${containerId}__`];
  5734. let fq = 0;
  5735. const f = (() => {
  5736. if(fq) return;
  5737. fq = 1;
  5738. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  5739. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  5740. const container = this.getStampContainer7409_(containerId);
  5741. if(!container) return;
  5742.  
  5743. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  5744.  
  5745. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  5746. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  5747. const mapping = this.stampDom[stampKey].mapping;
  5748.  
  5749. const map = new Map();
  5750.  
  5751. const currentObjKeys = object.map(objEntry => {
  5752. const mappingKey = uA4(mapping, objEntry);
  5753. if(!mappingKey) return null;
  5754. const data = objEntry[mappingKey];
  5755. if (!data[s52]) data[s52] = genId();
  5756. map.set(data[s52], objEntry);
  5757. // return ({
  5758. // objEntry,
  5759. // data: data,
  5760. // mappingKey: mappingKey,
  5761. // key: data[s52],
  5762. // exist: elementKeys.has(data[s52])
  5763. // });
  5764. return data[s52]
  5765.  
  5766. });
  5767.  
  5768. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  5769.  
  5770. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  5771.  
  5772. const splices = diffSplices(oldDomKeys, currentObjKeys);
  5773.  
  5774. // let myObject = object;
  5775. let indexSplicesObj_ = {
  5776. indexSplices: splices.map(splice => {
  5777. const index = splice[0];
  5778. const removedLen = splice[1];
  5779. const added = splice[2];
  5780. const addedCount = added.length;
  5781. const object = {};
  5782. object.length = index + addedCount;
  5783. for (let i = 0; i < addedCount; i++) {
  5784. object[index + i] = map.get(added[i]);
  5785. }
  5786. const removed = {};
  5787. removed.length = removedLen;
  5788.  
  5789. return { index, removed, object, addedCount }
  5790. })
  5791. };
  5792. map.clear();
  5793.  
  5794.  
  5795. this.__lat457__ = this.__lat457__ || new Set();
  5796. if(!container[wk]) container[wk] = mWeakRef(container);
  5797. this.__lat457__.add(container[wk]);
  5798. fixContainerApi(container);
  5799.  
  5800. // console.log(3882, indexSplicesObj_)
  5801. // let q = this.deferredBindingTasks_;
  5802. // this.deferredBindingTasks_ = [];
  5803. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  5804. let e_;
  5805. try {
  5806. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  5807. } catch (e) { e_ = e; }
  5808. this.__qsd477__ = false;
  5809. indexSplicesObj_ = null;
  5810. stampKey = indexSplicesObj_ = null;
  5811. fixContainerApi(container);
  5812. // this.deferredBindingTasks_ = q;
  5813. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  5814. if (!e_) {
  5815. // container.setAttribute('ytx-flushing', '0');
  5816. }
  5817.  
  5818.  
  5819. });
  5820. this[`__$$stampSqq$$#${containerId}__`] = f;
  5821. useMicroTaskQueue2 ? addTask2(f) : f();
  5822. executeTasks();
  5823.  
  5824. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  5825.  
  5826. return undefined;
  5827.  
  5828. }
  5829.  
  5830.  
  5831. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  5832. const dt0 = dt0a[0];
  5833. const dt1 = Date.now();
  5834. const obj = kRef(objWr);
  5835. if (!obj) return;
  5836. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  5837. if (xxx !== xxx_) return;
  5838. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  5839. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  5840. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  5841. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  5842. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  5843. const renderJob1 = obj.renderJobsMap_[containerId]
  5844. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  5845. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  5846. let e_, r;
  5847. try {
  5848. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  5849. } catch (e) {
  5850. e_ = e;
  5851. }
  5852. obj[`__quu477#${containerId}__`] = false;
  5853. if (e_) throw e_;
  5854. return r;
  5855. };
  5856.  
  5857.  
  5858. stampDomArray_.bind = function (obj, ...args) {
  5859. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  5860. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  5861. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  5862. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  5863. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  5864. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  5865. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  5866. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  5867. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  5868.  
  5869.  
  5870. const renderJob = obj.renderJobsMap_[containerId];
  5871.  
  5872. const dt0a = [Date.now()];
  5873. queueMicrotask_(() => { dt0a[0] = 0 });
  5874. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  5875. };
  5876.  
  5877. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  5878. const dt0 = dt0a[0];
  5879. const dt1 = Date.now();
  5880. const obj = kRef(objWr);
  5881. if (!obj) return;
  5882. const renderJob1 = obj.renderJobsMap_[containerId];
  5883. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  5884. let e_, r;
  5885. try {
  5886. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  5887. } catch (e) {
  5888. e_ = e;
  5889. }
  5890. obj[`__quu477#${containerId}__`] = false;
  5891. if (e_) throw e_;
  5892. return r;
  5893. };
  5894.  
  5895.  
  5896. stampDomArraySplices_.bind = function (obj, ...args) {
  5897. let [stampKey, containerId, indexSplicesObj] = args;
  5898. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  5899.  
  5900. const renderJob = obj.renderJobsMap_[containerId];
  5901.  
  5902. const dt0a = [Date.now()];
  5903. queueMicrotask_(() => { dt0a[0] = 0 });
  5904. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  5905. };
  5906.  
  5907.  
  5908. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  5909.  
  5910. }
  5911.  
  5912.  
  5913. const createStampDomFnsB_ = () => {
  5914.  
  5915. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  5916.  
  5917. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  5918. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  5919.  
  5920.  
  5921. const rq0 = document.createElement('rp');
  5922. rq0.setAttribute('yt-element-placholder', '');
  5923.  
  5924. let activeStampContainerId = '';
  5925.  
  5926. const componentBasedTaskPool = new WeakMap();
  5927.  
  5928.  
  5929. Node.prototype.checkFF = function () {
  5930. const pTask = componentBasedTaskPool.get(this);
  5931. if (!pTask) return null;
  5932. return [pTask, taskList.filter(e => e.taskId === pTask.taskId), taskList.filter(e => e.componentWr === this[wk])];
  5933. }
  5934.  
  5935. Node.prototype.checkGG = function () {
  5936. window.me849 = this;
  5937. const pTask = componentBasedTaskPool.get(this);
  5938. if (!pTask) return null;
  5939. window.me848 = pTask.taskId;
  5940. debugger;
  5941. loopTask();
  5942. }
  5943.  
  5944. NodeList.prototype.last = function () {
  5945. return this[this.length - 1];
  5946. }
  5947.  
  5948. const getStampContainer_ = function (containerId) {
  5949.  
  5950. // if(this.__byPass828__) return this.getStampContainer7409_(containerId);
  5951.  
  5952. this.__activeContainerId929__ = containerId;
  5953.  
  5954. return this.getStampContainer7409_(containerId);
  5955.  
  5956. }
  5957.  
  5958.  
  5959.  
  5960. const it0 = Date.now() - 80000000000;
  5961. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  5962.  
  5963.  
  5964. const createComponent_ = function (componentConfig, data, canReuse) {
  5965.  
  5966. this.___lastCreate3311__ = data;
  5967.  
  5968.  
  5969.  
  5970. if (this.__directProduction533__) {
  5971. const cName = this.getComponentName_(componentConfig, data);
  5972.  
  5973. return document.createElement(cName);
  5974. }
  5975.  
  5976. if (this.__byPass828__ || !this.__byPass348__) {
  5977.  
  5978. // console.log(39829004)
  5979. // console.log(new Error().stack)
  5980. return this.createComponent7409_(componentConfig, data, false);
  5981. }
  5982.  
  5983.  
  5984. const containerId = this.__activeContainerId929__;
  5985.  
  5986. // console.log(2883007, componentConfig, data, canReuse)
  5987.  
  5988. const r = rq0.cloneNode(false);
  5989.  
  5990. r.is = 'aa-bb-cc-dd';
  5991.  
  5992. return r;
  5993.  
  5994.  
  5995. }
  5996.  
  5997.  
  5998. const childrenObs = new MutationObserver((mutations) => {
  5999. loopTask();
  6000. });
  6001.  
  6002.  
  6003. class CTaskList {
  6004. constructor() {
  6005. this.head = this.tail = null;
  6006.  
  6007. // ref → {prev, next, level}
  6008. this.nodes = new Map();
  6009.  
  6010. // Per‑level sentinels
  6011. this.levelHead = [];
  6012. this.levelTail = [];
  6013.  
  6014. // Sorted list of non‑empty levels for O(log L) neighbour lookup
  6015. this.nonEmptyLevels = [];
  6016. this.counter = 0;
  6017. }
  6018.  
  6019. _ensure(level) {
  6020. while (this.levelTail.length <= level) {
  6021. this.levelTail.push(null);
  6022. this.levelHead.push(null);
  6023. }
  6024. }
  6025.  
  6026. // Binary‑search index inside nonEmptyLevels
  6027. _indexOfLevel(level) {
  6028. let lo = 0, hi = this.nonEmptyLevels.length;
  6029. while (lo < hi) {
  6030. const mid = (lo + hi) >> 1;
  6031. if (this.nonEmptyLevels[mid] < level) lo = mid + 1;
  6032. else hi = mid;
  6033. }
  6034. return lo;
  6035. }
  6036.  
  6037. _link(ref, prev, next, level) {
  6038.  
  6039.  
  6040. this.nodes.set(ref, { prev, next, level });
  6041.  
  6042. if (prev) this.nodes.get(prev).next = ref;
  6043. else this.head = ref;
  6044.  
  6045. if (next) this.nodes.get(next).prev = ref;
  6046. else this.tail = ref;
  6047.  
  6048. this.levelTail[level] = ref;
  6049. if (!this.levelHead[level]) this.levelHead[level] = ref;
  6050. }
  6051.  
  6052. _detach(ref) {
  6053. if (!ref || !this.nodes.has(ref)) return;
  6054.  
  6055.  
  6056. const { prev, next, level } = this.nodes.get(ref);
  6057.  
  6058. if (prev) this.nodes.get(prev).next = next;
  6059. else this.head = next;
  6060.  
  6061. if (next) this.nodes.get(next).prev = prev;
  6062. else this.tail = prev;
  6063.  
  6064. if (this.levelTail[level] === ref) {
  6065. this.levelTail[level] = prev && this.nodes.get(prev)?.level === level ? prev : null;
  6066. }
  6067. if (this.levelHead[level] === ref) {
  6068. this.levelHead[level] = next && this.nodes.get(next)?.level === level ? next : null;
  6069. }
  6070.  
  6071. if (this.levelTail[level] === null) {
  6072. const idx = this.nonEmptyLevels.indexOf(level);
  6073. if (idx !== -1) this.nonEmptyLevels.splice(idx, 1);
  6074. }
  6075.  
  6076. this.nodes.delete(ref);
  6077.  
  6078. }
  6079.  
  6080. push(component, level) {
  6081. if (!component) return;
  6082.  
  6083. // this.checkIntegrity();
  6084.  
  6085. const ref = component[wk] || (component[wk] = new WeakRef(component));
  6086.  
  6087. if (this.nodes.has(ref)) this._detach(ref);
  6088.  
  6089. this._ensure(level);
  6090.  
  6091. if (!this.levelTail[level]) {
  6092. // First node on this level
  6093. const idx = this._indexOfLevel(level);
  6094. const prevLvl = idx ? this.nonEmptyLevels[idx - 1] : null;
  6095. const nextLvl = idx < this.nonEmptyLevels.length ? this.nonEmptyLevels[idx] : null;
  6096.  
  6097. const prevRef = prevLvl !== null ? this.levelTail[prevLvl] : null;
  6098. const nextRef = nextLvl !== null ? this.levelHead[nextLvl] : null;
  6099.  
  6100. this._link(ref, prevRef, nextRef, level);
  6101. this.nonEmptyLevels.splice(idx, 0, level);
  6102. } else {
  6103. // Append to existing level
  6104. const prevRef = this.levelTail[level];
  6105. const nextRef = this.nodes.get(prevRef).next;
  6106. this._link(ref, prevRef, nextRef, level);
  6107. }
  6108.  
  6109. this.counter++;
  6110. // this.checkIntegrity();
  6111. }
  6112.  
  6113. remove(component) {
  6114. const ref = component && component.deref ? component : (component || 0)[wk];
  6115.  
  6116. // this.checkIntegrity();
  6117. this._detach(ref);
  6118.  
  6119. // this.checkIntegrity();
  6120. }
  6121.  
  6122. replace(componentOld, componentNew) {
  6123. if (!componentOld || !componentNew) {
  6124. throw new Error('replace failed: missing component');
  6125. }
  6126.  
  6127. if (componentOld === componentNew) {
  6128. return;
  6129. }
  6130.  
  6131. const refOld = componentOld[wk];
  6132. // ensure New has a weak‐ref
  6133. const refNew = componentNew[wk] || (componentNew[wk] = mWeakRef(componentNew));
  6134.  
  6135.  
  6136. if (refOld === refNew) {
  6137. return;
  6138. }
  6139.  
  6140. if (!refOld || !this.nodes.has(refOld)) {
  6141. throw new Error('replace failed: old component not found');
  6142. }
  6143.  
  6144. // this.checkIntegrity();
  6145.  
  6146. // If new is already in the list somewhere, detach it first
  6147. if (this.nodes.has(refNew)) {
  6148. this._detach(refNew);
  6149. }
  6150.  
  6151. // Pull out old pointers
  6152. const { prev, next, level } = this.nodes.get(refOld);
  6153.  
  6154. // Link into the main list
  6155. if (prev) {
  6156. this.nodes.get(prev).next = refNew;
  6157. } else {
  6158. this.head = refNew;
  6159. }
  6160.  
  6161. if (next) {
  6162. this.nodes.get(next).prev = refNew;
  6163. } else {
  6164. this.tail = refNew;
  6165. }
  6166.  
  6167. // Link into the per‐level sentinels
  6168. if (this.levelHead[level] === refOld) {
  6169. this.levelHead[level] = refNew;
  6170. }
  6171. if (this.levelTail[level] === refOld) {
  6172. this.levelTail[level] = refNew;
  6173. }
  6174.  
  6175. // Finally re‐key the Map entry
  6176. this.nodes.set(refNew, { prev, next, level });
  6177. this.nodes.delete(refOld);
  6178.  
  6179. // this.checkIntegrity();
  6180. }
  6181.  
  6182. _walk(ref, dir) {
  6183. if (!ref || !this.nodes.has(ref)) return null;
  6184.  
  6185. let cur = this.nodes.get(ref)[dir];
  6186. while (cur) {
  6187. if (cur.deref()) return cur;
  6188.  
  6189. // Clean up collected node
  6190. const nxt = this.nodes.get(cur)[dir];
  6191. this._detach(cur);
  6192. cur = nxt;
  6193. }
  6194. return null;
  6195. }
  6196.  
  6197. nextComp(component) {
  6198. const ref = component && component.deref ? component : (component || 0)[wk];
  6199. return this._walk(ref, 'next');
  6200. }
  6201.  
  6202. prevComp(component) {
  6203. const ref = component && component.deref ? component : (component || 0)[wk];
  6204. return this._walk(ref, 'prev');
  6205. }
  6206.  
  6207. hasComp(component) {
  6208. const ref = component && component.deref ? component : (component || 0)[wk];
  6209. return !!(ref && this.nodes.has(ref))
  6210. }
  6211.  
  6212. count() {
  6213. return this.counter;
  6214. }
  6215.  
  6216. countLevels() {
  6217. const r = [];
  6218. for (let i = 0; ; i++) {
  6219. if (!this.levelHead[i] || !this.levelTail[i]) break;
  6220. let cur = this.levelHead[i];
  6221. let curs = [];
  6222. while (cur && this.nodes.get(cur).level === i) {
  6223. curs.push((cur));
  6224. cur = taskListP.nextComp(cur);
  6225. }
  6226.  
  6227. if (curs[0] !== this.levelHead[i]) debugger;
  6228. if (curs[curs.length - 1] !== this.levelTail[i]) debugger;
  6229. r.push({
  6230. head: this.levelHead[i],
  6231. tail: this.levelTail[i],
  6232. curs: curs,
  6233. set: new Set(curs),
  6234. arrSize: curs.length,
  6235. setSize: (new Set(curs)).size
  6236.  
  6237. });
  6238. }
  6239. return r;
  6240. }
  6241.  
  6242.  
  6243. // // Integrity checker helper
  6244. // checkIntegrity() {
  6245. // const list = this;
  6246. // // Global head/tail pointers
  6247. // if (list.head !== null) {
  6248. // const headNode = list.nodes.get(list.head);
  6249. // assert(headNode.prev === null, "Integrity: head.prev must be null");
  6250. // }
  6251. // if (list.tail !== null) {
  6252. // const tailNode = list.nodes.get(list.tail);
  6253. // assert(tailNode.next === null, "Integrity: tail.next must be null");
  6254. // }
  6255.  
  6256. // // Per-level head/tail and level consistency
  6257. // list.nonEmptyLevels.forEach(level => {
  6258. // assert(list.levelHead[level] != null, `Integrity: levelHead[${level}] should not be null`);
  6259. // assert(list.levelTail[level] != null, `Integrity: levelTail[${level}] should not be null`);
  6260. // const headRef = list.levelHead[level];
  6261. // const tailRef = list.levelTail[level];
  6262. // const headNode = list.nodes.get(headRef);
  6263. // const tailNode = list.nodes.get(tailRef);
  6264. // assert(headNode.level === level, `Integrity: levelHead[${level}].level mismatch`);
  6265. // assert(tailNode.level === level, `Integrity: levelTail[${level}].level mismatch`);
  6266. // });
  6267.  
  6268. // // nonEmptyLevels sorted ascending
  6269. // for (let i = 1; i < list.nonEmptyLevels.length; i++) {
  6270. // assert(
  6271. // list.nonEmptyLevels[i] > list.nonEmptyLevels[i - 1],
  6272. // "Integrity: nonEmptyLevels must be sorted ascending"
  6273. // );
  6274. // }
  6275.  
  6276. // this.countLevels();
  6277. // }
  6278.  
  6279. }
  6280.  
  6281.  
  6282. const taskListP = new CTaskList();
  6283. const taskList = [];
  6284. let taskCounter = 0;
  6285. window.me55 = ()=>taskListP;
  6286.  
  6287. const taskPush = (component, pTask0, pTask1, deferred = false) => {
  6288. component = kRef(component);
  6289. if (!component) return;
  6290. if (!pTask0) pTask0 = pTask1; else Object.assign(pTask0, pTask1);
  6291. componentBasedTaskPool.set(component, pTask0);
  6292. const id = taskCounter = (taskCounter & 1073741823) + 1;
  6293. pTask0.taskId = id;
  6294. if (!pTask1.byPass) pTask0.byPass = false;
  6295. taskListP.push(component, 0);
  6296. if (!deferred) nonDeferredTask = component[wk];
  6297. // taskList.push({
  6298. // taskId: id,
  6299. // componentWr: component[wk]
  6300. // })
  6301. return pTask0;
  6302. }
  6303.  
  6304. const domComment_ = document.createComment('y');
  6305. const triggerDomChange = (node) => {
  6306. node.appendChild(domComment_).remove();
  6307. }
  6308.  
  6309.  
  6310. const performTask = (component, pTask = undefined) => {
  6311.  
  6312. if (pTask === undefined) pTask = componentBasedTaskPool.get(component);
  6313. if (!pTask || !component) return;
  6314. let { step, producer, containerId, typeOrConfig, data, flushing, selfProducer } = pTask;
  6315. producer = kRef(producer);
  6316. selfProducer = kRef(selfProducer);
  6317.  
  6318. const resolveSelf = () => {
  6319.  
  6320. const node = component;
  6321.  
  6322. const prevCur = taskListP.prevComp(node);
  6323.  
  6324. node.removeAttribute('ytx-flushing');
  6325.  
  6326. // if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement && selfProducer.hostElement.isConnected) {
  6327.  
  6328. if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement) {
  6329. const node = component;
  6330.  
  6331. let shouldMarkDirty = false;
  6332.  
  6333. const m = new Set();
  6334.  
  6335. const producer = selfProducer;
  6336.  
  6337. for (const [containerId, bEvent, hasData] of flushing) {
  6338. if (hasData || hasData === null) {
  6339. shouldMarkDirty = true;
  6340. if (bEvent) {
  6341. const container = producer.getStampContainer7409_(containerId);
  6342. // console.log(644221499, container)
  6343. m.add(container);
  6344. }
  6345. }
  6346. }
  6347. flushing.length = 0;
  6348.  
  6349. if (shouldMarkDirty) {
  6350. producer.markDirty && producer.markDirty();
  6351. let q = true;
  6352. for (const container of m) {
  6353. if (!q) producer.markDirty && producer.markDirty();
  6354. q = false;
  6355. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  6356. container
  6357. });
  6358. }
  6359. }
  6360.  
  6361. }
  6362.  
  6363.  
  6364.  
  6365. const s = new Set();
  6366.  
  6367. const parentComponent = node.closest('[ytx-flushing]');
  6368. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  6369. if (!s.has(parentComponent[wk])) {
  6370. s.add(parentComponent[wk]);
  6371. }
  6372. }
  6373.  
  6374. const producerElement = producer ? producer.hostElement : null;
  6375.  
  6376. if (parentComponent && parentComponent !== producerElement) {
  6377.  
  6378. const parentComponent = producerElement;
  6379. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  6380. if (!s.has(parentComponent[wk])) {
  6381. s.add(parentComponent[wk])
  6382. }
  6383. }
  6384.  
  6385. }
  6386.  
  6387. for (const p of s) {
  6388. const node = kRef(p);
  6389. triggerDomChange(node);
  6390. }
  6391.  
  6392. if (!node.hasAttribute('ytx-flushing') && (!pTask.flushing || !pTask.flushing.length) && !pTask.typeOrConfig && !pTask.data) {
  6393. componentBasedTaskPool.delete(node);
  6394. taskListP.remove(node);
  6395. }
  6396.  
  6397.  
  6398. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head), parents: [...s]};
  6399.  
  6400. }
  6401.  
  6402. if (pTask.step === 'creation') {
  6403.  
  6404. if (flushing) debugger;
  6405. if (!producer || !typeOrConfig) return;
  6406. if (component.parentNode && component.parentNode.id === containerId && component.parentNode === producer.getStampContainer7409_(containerId)) {
  6407. pTask.step = 'flushStamper'; pTask.pq33 = 3;
  6408.  
  6409. // const aNode = producer.createComponent7409_(typeOrConfig, data, false);
  6410.  
  6411. const prevCur = taskListP.prevComp(component);
  6412.  
  6413. const pTaskId = pTask.taskId;
  6414. const cName = producer.getComponentName_(typeOrConfig, data);
  6415. const aNode = document.createElement(cName);
  6416. const qNode = component;
  6417.  
  6418. aNode.setAttribute('ytx-stamp', 'flusher');
  6419. aNode.setAttribute('ytx-flushing', '2');
  6420. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  6421.  
  6422. taskListP.replace(qNode, aNode);
  6423.  
  6424. componentBasedTaskPool.delete(qNode);
  6425. componentBasedTaskPool.set(aNode, pTask); // pTask will be obtained and proceeded during "dom change" in the same micro task
  6426.  
  6427.  
  6428. const container = component.parentNode;
  6429. const containerApi = container.__domApi || container;
  6430.  
  6431. const frag = document.createDocumentFragment();
  6432. frag.appendChild(aNode);
  6433. containerApi.insertBefore(frag, qNode);
  6434. containerApi.removeChild(qNode);
  6435. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  6436.  
  6437. }
  6438. } else if (pTask.step === 'flushStamper') {
  6439.  
  6440. if (flushing) debugger;
  6441.  
  6442. if (!producer || !typeOrConfig) return;
  6443. pTask.step = 'flushStamperWait';
  6444. pTask.typeOrConfig = null;
  6445. pTask.data = null;
  6446.  
  6447. const prevCur = taskListP.prevComp(component);
  6448.  
  6449. const node = component;
  6450. node.setAttribute('ytx-flushing', '3');
  6451.  
  6452. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  6453. // flushedObserver.observe(node, { subtree: true, childList: true });
  6454. producer.deferredBindingTasks_.push(taskB);
  6455. producer.flushRenderStamperComponentBindings7409_();
  6456. // try{Polymer.flush()}catch(e){}
  6457. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  6458.  
  6459. } else if (pTask.step === 'flushStamperWait') {
  6460.  
  6461. if (flushing) debugger;
  6462. if (!producer) return;
  6463.  
  6464. // producer undetermined
  6465.  
  6466. const node = component;
  6467.  
  6468. if (!node.querySelector('[ytx-flushing]')) {
  6469.  
  6470. pTask.step = 'idleContainer';
  6471.  
  6472. return resolveSelf();
  6473.  
  6474.  
  6475. }
  6476.  
  6477. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish') {
  6478.  
  6479. if (producer && typeOrConfig) {
  6480.  
  6481. pTask.typeOrConfig = null;
  6482. pTask.data = null;
  6483.  
  6484. const prevCur = taskListP.prevComp(component);
  6485.  
  6486. const node = component;
  6487. node.setAttribute('ytx-flushing', '3');
  6488.  
  6489. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  6490. // flushedObserver.observe(node, { subtree: true, childList: true });
  6491. producer.deferredBindingTasks_.push(taskB);
  6492. producer.flushRenderStamperComponentBindings7409_();
  6493. // try{Polymer.flush()}catch(e){}
  6494. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  6495. }
  6496.  
  6497. const node = component;
  6498.  
  6499. if (!node.querySelector('[ytx-flushing]')) {
  6500. pTask.step = 'idleProducer';
  6501. return resolveSelf();
  6502. }
  6503. // const selfProducer = kRef(pTask.selfProducer);
  6504.  
  6505. }
  6506.  
  6507. };
  6508.  
  6509. const performTaskQueued = (component)=>{
  6510. queueMicrotask_(()=>{
  6511. performTask(component);
  6512. });
  6513. };
  6514.  
  6515. let isLooping = false;
  6516. let nonDeferredTask = null;
  6517. let loopTaskQ = 0;
  6518. const loopTask = () => {
  6519. if (isLooping) return ++loopTaskQ;
  6520. isLooping = true;
  6521. loopTaskQ = 0;
  6522. let t0 = 0;
  6523. let cur = taskListP.head;
  6524. let nextCur = cur;
  6525. const taskExec = () => {
  6526.  
  6527. if (!t0) {
  6528. t0 = nativeNow();
  6529. }
  6530.  
  6531. if (nonDeferredTask && nextCur && taskListP.nodes.has(nextCur) && taskListP.nodes.get(nextCur).level === 1) {
  6532. nextCur = nonDeferredTask
  6533. }
  6534.  
  6535. nonDeferredTask = null;
  6536.  
  6537. for (;cur = nextCur; ) {
  6538.  
  6539. nextCur = taskListP.nextComp(cur);
  6540. const nextCur0 = nextCur;
  6541.  
  6542. const taskComponent = kRef(cur);
  6543. if (taskComponent) {
  6544. if(taskComponent === window.me849) debugger;
  6545. const pTask = componentBasedTaskPool.get(taskComponent);
  6546. if (pTask) {
  6547. if (pTask.taskId > 0 && !pTask.byPass) {
  6548. if (pTask.taskId === window.me848) debugger;
  6549.  
  6550. let shouldPerformTask = false;
  6551. if (pTask.step === 'creation' && pTask.typeOrConfig) {
  6552. shouldPerformTask = true;
  6553. } else if (pTask.step === 'flushStamper' && pTask.typeOrConfig) {
  6554. shouldPerformTask = true;
  6555. } else if (pTask.step === 'flushStamperWait' && !taskComponent.querySelector('[ytx-flushing]')) {
  6556. shouldPerformTask = true;
  6557. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish' && (pTask.typeOrConfig || !taskComponent.querySelector('[ytx-flushing]'))) {
  6558. shouldPerformTask = true;
  6559. }
  6560.  
  6561. let b = shouldPerformTask && taskComponent.parentNode;
  6562. if (b) {
  6563.  
  6564. const result = performTask(taskComponent, pTask);
  6565. let kbb = false;
  6566. if(typeof result ==='object' && result.nextCur === nextCur0){
  6567.  
  6568. } else if(taskListP.nextComp(cur) === null && taskListP.nextComp(cur) !== nextCur0) {
  6569. kbb = true;
  6570. }
  6571. if (typeof result === 'object' && result.parents instanceof Array) {
  6572.  
  6573. const nextCur_ = result.nextCur;
  6574. nextCur = nextCur_;
  6575. const parents = result.parents;
  6576. if (parents.length >= 1) {
  6577. const eSet = new Set(parents); // weak refs
  6578. eSet.add(nextCur_)
  6579. for (let cur_ = taskListP.head; cur_; cur_ = taskListP.nextComp(cur_)) {
  6580. if (eSet.has(cur_)) {
  6581. nextCur = cur_;
  6582. break;
  6583. }
  6584. }
  6585. }
  6586.  
  6587.  
  6588. } else if(typeof result === 'object' && result.nextCur){
  6589. nextCur = result.nextCur;
  6590. }
  6591.  
  6592.  
  6593. if (nativeNow() - t0 > 10) {
  6594. t0 = 0;
  6595. nextBrowserTick_(taskExec);
  6596. } else {
  6597. queueMicrotask_(taskExec);
  6598. }
  6599.  
  6600. return;
  6601.  
  6602. }
  6603.  
  6604. }
  6605.  
  6606. }
  6607.  
  6608. }
  6609.  
  6610. }
  6611.  
  6612. isLooping = false;
  6613.  
  6614. if(loopTaskQ > 0) nextBrowserTick_(loopTask);
  6615.  
  6616. };
  6617.  
  6618. queueMicrotask_(taskExec);
  6619.  
  6620. };
  6621.  
  6622.  
  6623. let q244 = new PromiseExternal();
  6624. let q248a = [];
  6625. let q248b = [];
  6626. let q248c = [];
  6627. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  6628.  
  6629. if(this.__byPass828__) {
  6630.  
  6631. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  6632. }
  6633.  
  6634. const isLastCreate = this.___lastCreate3311__ === data; // false for native element. true for RP or native element
  6635.  
  6636. this.___lastCreate3311__ = -0.125;
  6637.  
  6638.  
  6639. const containerId = this.__activeContainerId929__;
  6640. if (!component[wk]) component[wk] = mWeakRef(component);
  6641. if (!this[wk]) this[wk] = mWeakRef(this);
  6642.  
  6643. const pTask = componentBasedTaskPool.get(component);
  6644.  
  6645. const isSelfProducer = (pTask && pTask.selfProducer && pTask.flushing);
  6646.  
  6647.  
  6648. const abandonUnreadySubtree = () => {
  6649. for (const e of component.querySelectorAll('[ytx-flushing]')) {
  6650. const pTask = componentBasedTaskPool.get(e);
  6651. if (pTask) {
  6652. pTask.step = 'abandon';
  6653. pTask.taskId = 0;
  6654. if (pTask.flushing) pTask.flushing.length = 0;
  6655. pTask.flushing = null;
  6656.  
  6657. pTask.typeOrConfig = null
  6658. pTask.data = null
  6659.  
  6660. componentBasedTaskPool.delete(e);
  6661. taskListP.remove(e);
  6662. }
  6663. e.removeAttribute('ytx-flushing');
  6664. if (e.nodeName === 'RP') e.remove();
  6665. }
  6666. }
  6667.  
  6668. const flushNowTask = (componentWr, pTaskId, flag) => {
  6669. const component = kRef(componentWr);
  6670. if (!component) return;
  6671. const pTaskNew = componentBasedTaskPool.get(component);
  6672. if (!pTaskNew) return;
  6673. if (pTaskId !== pTaskNew.taskId) return;
  6674. pTaskNew.byPass = false;
  6675. if (flag & 1) {
  6676. performTaskQueued(component);
  6677. performTaskQueued(component);
  6678. performTaskQueued(component);
  6679. } else {
  6680. performTask(component);
  6681. performTask(component);
  6682. performTask(component);
  6683. }
  6684. return true;
  6685. }
  6686.  
  6687. const flushNow = (component) => {
  6688.  
  6689.  
  6690.  
  6691. const cName = this.getComponentName_(typeOrConfig, data);
  6692. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  6693. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  6694.  
  6695. if(mDeferred) {
  6696. component.setAttribute('ytx-defer-stamp','');
  6697. this.hostElement.setAttribute('ytx-defer-stamp','');
  6698. }
  6699.  
  6700. const pTaskNew = taskPush(component, pTask, {
  6701. step: isSelfProducer ? 'mightFlushAndWaitContainersRenderFinish' : 'flushStamper',
  6702. producer: this[wk],
  6703. containerId: containerId,
  6704. typeOrConfig: typeOrConfig,
  6705. data: data,
  6706. byPass: true,
  6707. pq33: 7
  6708. }, mDeferred ? 1 : 0);
  6709.  
  6710. const pTaskId = pTaskNew.taskId;
  6711.  
  6712. const componentWr = component[wk];
  6713.  
  6714.  
  6715. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2w');
  6716.  
  6717. if (mDeferred ) {
  6718.  
  6719. q248a.push([componentWr, pTaskId]);
  6720.  
  6721. setTimeout(() => {
  6722. const q248 = q248a;
  6723.  
  6724. if (!q248.length) return;
  6725. let q246 = q248.slice();
  6726. q248.length = 0;
  6727.  
  6728. let doLoop = false;
  6729. for (const [componentWr, pTaskId] of q246) {
  6730. // if(!)
  6731. // console.log(2188, kRef(componentWr).parentNode)
  6732. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  6733. }
  6734. q246.length = 0;
  6735. q246 = null;
  6736. if (doLoop) loopTask();
  6737.  
  6738. }, 0);
  6739.  
  6740.  
  6741. } else {
  6742.  
  6743. if(!component.parentNode){
  6744.  
  6745. q248b.push([componentWr, pTaskId]);
  6746.  
  6747. (() => {
  6748.  
  6749. const q248 = q248b;
  6750.  
  6751. if (!q248.length) return;
  6752. let q246 = q248.slice();
  6753. q248.length = 0;
  6754. let doLoop = false;
  6755. for (const [componentWr, pTaskId] of q246) {
  6756. if (flushNowTask(componentWr, pTaskId, 0) === true) doLoop = true;
  6757. }
  6758. q246.length = 0;
  6759. q246 = null;
  6760. if (doLoop) loopTask();
  6761. })();
  6762.  
  6763. } else {
  6764.  
  6765.  
  6766. q248c.push([componentWr, pTaskId]);
  6767.  
  6768. nextBrowserTick_(() => {
  6769. const q248 = q248c;
  6770.  
  6771. if (!q248.length) return;
  6772. let q246 = q248.slice();
  6773. q248.length = 0;
  6774.  
  6775. let doLoop = false;
  6776. for (const [componentWr, pTaskId] of q246) {
  6777. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  6778. }
  6779. q246.length = 0;
  6780. q246 = null;
  6781. if (doLoop) loopTask();
  6782.  
  6783. });
  6784.  
  6785. }
  6786.  
  6787. }
  6788.  
  6789.  
  6790.  
  6791. loopTask();
  6792.  
  6793. };
  6794.  
  6795. if (!isLastCreate) {
  6796.  
  6797. abandonUnreadySubtree();
  6798.  
  6799. flushNow(component);
  6800. return;
  6801.  
  6802. } else {
  6803. if (pTask) pTask.taskId = 0;
  6804. }
  6805.  
  6806. if (this.__byPass828__ || !this.__byPass348__) {
  6807. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  6808. }
  6809.  
  6810. if (pTask && pTask.step !== 'creation') {
  6811.  
  6812. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2c');
  6813.  
  6814. abandonUnreadySubtree();
  6815.  
  6816. flushNow(component);
  6817.  
  6818. return;
  6819.  
  6820. } else {
  6821.  
  6822. if (component.nodeName === "RP") {
  6823.  
  6824. component.setAttribute('ytx-stamp', 'flusher');
  6825.  
  6826. component.setAttribute('ytx-flushing', '1');
  6827.  
  6828. const cName = this.getComponentName_(typeOrConfig, data);
  6829. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  6830. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  6831.  
  6832. if(mDeferred) {
  6833. component.setAttribute('ytx-defer-stamp','');
  6834. this.hostElement.setAttribute('ytx-defer-stamp','');
  6835. }
  6836.  
  6837. taskPush(component, pTask, {
  6838. step: 'creation',
  6839. producer: this[wk],
  6840. containerId: containerId,
  6841. typeOrConfig: typeOrConfig,
  6842. data: data
  6843. }, mDeferred ? 1 : 0);
  6844. loopTask();
  6845.  
  6846. } else {
  6847.  
  6848.  
  6849. const aNode = component;
  6850. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  6851.  
  6852. aNode.setAttribute('ytx-stamp', 'flusher');
  6853. aNode.setAttribute('ytx-flushing', '2');
  6854.  
  6855. flushNow(component);
  6856.  
  6857. }
  6858.  
  6859. }
  6860.  
  6861.  
  6862. }
  6863. flushRenderStamperComponentBindings_ = function () {
  6864.  
  6865. if (!this.__byPass348__) {
  6866. return this.flushRenderStamperComponentBindings7409_();
  6867. }
  6868. if (this.__byPass828__) {
  6869. const wr = this[wk] || (this[wk] = mWeakRef(this));
  6870. queueMicrotask_(() => {
  6871. const producer = kRef(wr);
  6872. if (!producer) return;
  6873. producer.flushRenderStamperComponentBindings7409_();
  6874. });
  6875. throw new Error('5ii48');
  6876. }
  6877. throw new Error('5ii48')
  6878. }
  6879.  
  6880.  
  6881. const directComponentList = new Set([
  6882. // for YouTube Tabview Totara
  6883. "YTD-STRUCTURED-DESCRIPTION-CONTENT-RENDERER",
  6884. "YTD-VIDEO-DESCRIPTION-HEADER-RENDERER",
  6885. "YTD-ENGAGEMENT-PANEL-SECTION-LIST-RENDERER",
  6886. ]);
  6887.  
  6888.  
  6889. let kf33;
  6890. let kf3b = 0;
  6891.  
  6892. const sb88 = Symbol();
  6893.  
  6894. const onStampDone = (producer) =>{
  6895.  
  6896.  
  6897. const flushing_ = producer[sb88];
  6898.  
  6899. const flushing = flushing_.slice();
  6900. flushing_.length = 0;
  6901.  
  6902. if (flushing && flushing.length > 0) {
  6903.  
  6904. let shouldMarkDirty = false;
  6905.  
  6906. const m = new Set();
  6907.  
  6908. for (const [containerId, bEvent, hasData] of flushing) {
  6909. if (hasData || hasData === null) {
  6910. shouldMarkDirty = true;
  6911. if (bEvent) {
  6912. const container = producer.getStampContainer7409_(containerId);
  6913. // console.log(644221499, container)
  6914. m.add(container);
  6915. }
  6916. }
  6917. }
  6918. flushing.length = 0;
  6919.  
  6920. if (shouldMarkDirty) {
  6921. producer.markDirty && producer.markDirty();
  6922. let q = true;
  6923. for (const container of m) {
  6924. if (!q) producer.markDirty && producer.markDirty();
  6925. q = false;
  6926. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  6927. container
  6928. });
  6929. }
  6930. }
  6931.  
  6932. }
  6933.  
  6934.  
  6935. }
  6936.  
  6937. stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  6938. // this.__byPass828__ = true;
  6939.  
  6940. // return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  6941.  
  6942. const producer = this;
  6943. const hostElement = producer.hostElement;
  6944.  
  6945. let kf = false;
  6946. const kf3t = nativeNow();
  6947. const kf34 = Math.floor((kf3t - kf3b) / 8);
  6948.  
  6949. if (!kf33 || kf34 !== kf33) {
  6950. kf33 = kf34;
  6951. kf3b = kf3t - kf34 * 8;
  6952. kf = true;
  6953. }
  6954.  
  6955. const container = this.getStampContainer7409_(containerId);
  6956. if (container && !container.__rk75401__) {
  6957. container.__rk75401__ = true;
  6958. childrenObs.observe(container, { subtree: false, childList: true });
  6959. }
  6960.  
  6961. if (kf) this.__directProduction533__ = true;
  6962. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  6963. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  6964. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  6965. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  6966. else this.__directProduction533__ = false;
  6967.  
  6968. this.__directProduction533__ = true;
  6969.  
  6970. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  6971.  
  6972. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  6973.  
  6974. const bEventCb = this.stampDom[stampKey].events;
  6975.  
  6976. this.__activeContainerId929__ = containerId;
  6977.  
  6978. if (!this[wk]) this[wk] = mWeakRef(this);
  6979. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  6980. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  6981. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  6982. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  6983. hostElement.setAttribute('ytx-stamp', 'producer');
  6984. }
  6985.  
  6986.  
  6987. if (this.__byPass828__) {
  6988.  
  6989. const flushing = this[sb88] || (this[sb88] = []);
  6990. flushing.push([containerId, bEventCb, null]);
  6991. let r, e_
  6992. try {
  6993. this.__byPass348__ = true;
  6994. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  6995. } catch (e) {
  6996. e_ = e;
  6997. }
  6998. this.__byPass348__ = false;
  6999.  
  7000. nextBrowserTick_(() => {
  7001. onStampDone(this);
  7002. });
  7003.  
  7004. if (e_ && e_.message !== '5ii48') throw e_;
  7005. return;
  7006.  
  7007. }
  7008.  
  7009.  
  7010. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  7011.  
  7012. const flushing = pTask ? (pTask.flushing || []) : [];
  7013. flushing.push([containerId, bEventCb, null]);
  7014. hostElement.setAttribute('ytx-flushing', 's-1');
  7015.  
  7016. if (pTask) {
  7017. // pTask.taskId = -1;
  7018. pTask.byPass = true;
  7019. }
  7020. if (hostElement && !hostElement.__rk75401__) {
  7021. hostElement.__rk75401__ = true;
  7022. childrenObs.observe(hostElement, { subtree: false, childList: true });
  7023. }
  7024.  
  7025. let r, e_
  7026. try {
  7027. this.__byPass348__ = true;
  7028. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  7029. } catch (e) {
  7030. e_ = e;
  7031. }
  7032. this.__byPass348__ = false;
  7033.  
  7034. taskPush(hostElement, pTask, {
  7035. step: 'mightFlushAndWaitContainersRenderFinish',
  7036. selfProducer: this[wk],
  7037. flushing
  7038. });
  7039. loopTask();
  7040.  
  7041. triggerDomChange(container);
  7042. triggerDomChange(hostElement);
  7043.  
  7044. if (e_ && e_.message !== '5ii48') throw e_;
  7045.  
  7046. };
  7047.  
  7048. stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  7049. // this.__byPass828__ = true;
  7050.  
  7051.  
  7052.  
  7053. // return this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7054.  
  7055. const producer = this;
  7056. const hostElement = producer.hostElement;
  7057.  
  7058. let kf = false;
  7059. const kf3t = nativeNow();
  7060. const kf34 = Math.floor((kf3t - kf3b) / 8);
  7061.  
  7062. if (!kf33 || kf34 !== kf33) {
  7063. kf33 = kf34;
  7064. kf3b = kf3t - kf34 * 8;
  7065. kf = true;
  7066. }
  7067.  
  7068. const container = this.getStampContainer7409_(containerId);
  7069. if (container && !container.__rk75401__) {
  7070. container.__rk75401__ = true;
  7071. childrenObs.observe(container, { subtree: false, childList: true });
  7072. }
  7073.  
  7074. if (kf) this.__directProduction533__ = true;
  7075. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  7076. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  7077. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  7078. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  7079. else this.__directProduction533__ = false;
  7080.  
  7081. bReuse = false;
  7082.  
  7083. this.__directProduction533__ = true;
  7084.  
  7085. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  7086. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  7087.  
  7088. this.__activeContainerId929__ = containerId;
  7089.  
  7090. if (!this[wk]) this[wk] = mWeakRef(this);
  7091. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  7092. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  7093. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  7094. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  7095. hostElement.setAttribute('ytx-stamp', 'producer');
  7096. }
  7097.  
  7098.  
  7099. if (this.__byPass828__) {
  7100.  
  7101. const flushing = this[sb88] || (this[sb88] = []);
  7102. flushing.push([containerId, bEventCb, !!dataList]);
  7103. let r, e_
  7104. try {
  7105. this.__byPass348__ = true;
  7106. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7107. } catch (e) {
  7108. e_ = e;
  7109. }
  7110. this.__byPass348__ = false;
  7111.  
  7112. nextBrowserTick_(() => {
  7113. onStampDone(this);
  7114. });
  7115.  
  7116. if (e_ && e_.message !== '5ii48') throw e_;
  7117. return;
  7118.  
  7119. }
  7120.  
  7121.  
  7122. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  7123.  
  7124. const flushing = pTask ? (pTask.flushing || []) : [];
  7125. flushing.push([containerId, bEventCb, !!dataList]);
  7126. hostElement.setAttribute('ytx-flushing', 's-1');
  7127.  
  7128. if (pTask) {
  7129. pTask.byPass = true;
  7130. // pTask.taskId = -1;
  7131. }
  7132.  
  7133. if (hostElement && !hostElement.__rk75401__) {
  7134. hostElement.__rk75401__ = true;
  7135. childrenObs.observe(hostElement, { subtree: false, childList: true });
  7136. }
  7137.  
  7138. let r, e_
  7139. try {
  7140. this.__byPass348__ = true;
  7141. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7142. } catch (e) {
  7143. e_ = e;
  7144. }
  7145. this.__byPass348__ = false;
  7146.  
  7147. taskPush(hostElement, pTask, {
  7148. step: 'mightFlushAndWaitContainersRenderFinish',
  7149. selfProducer: this[wk],
  7150. flushing
  7151. });
  7152. loopTask();
  7153.  
  7154. triggerDomChange(container);
  7155. triggerDomChange(hostElement);
  7156.  
  7157. if (e_ && e_.message !== '5ii48') throw e_;
  7158.  
  7159. };
  7160.  
  7161. const stampDomArrayWB_ = function (objWr, containerId, xxx_) {
  7162.  
  7163. const obj = kRef(objWr);
  7164. if (!obj) return;
  7165. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7166. if (xxx !== xxx_) return;
  7167. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7168. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7169. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7170. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7171. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7172. // console.log(12388002, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  7173. return obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7174. };
  7175.  
  7176.  
  7177. stampDomArray_.bind = function (obj, ...args) {
  7178. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7179. // console.log(12388001, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  7180. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7181. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7182. if (!typeOrConfig[wk]) typeOrConfig[wk] = mWeakRef(typeOrConfig);
  7183. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig[wk];
  7184. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7185. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7186. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7187.  
  7188. // if (!obj[`__stampDomArrayBoundFn__#${containerId}__`]) obj[`__stampDomArrayBoundFn__#${containerId}__`] = stampDomArrayWB_.bind(null, obj[wk], containerId);
  7189. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7190. // const p = obj[wk];
  7191. // queueMicrotask_(()=>{
  7192. // const obj = kRef(p);
  7193. // if(!obj) return;
  7194. // if(!obj.hostElement) return;
  7195. // triggerDomChange(obj.hostElement);
  7196. // const container = obj.getStampContainer7409_(containerId);
  7197. // if(container instanceof Node) triggerDomChange(container);
  7198. // });
  7199. // return obj[`__stampDomArrayBoundFn__#${containerId}__`];
  7200.  
  7201. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx);
  7202. };
  7203.  
  7204. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  7205.  
  7206. }
  7207.  
  7208. const setupDiscreteTasks = (h, rb) => {
  7209.  
  7210. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7211. const f = h.onYtRendererstamperFinished;
  7212. const g = ump3.get(f) || function () {
  7213. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7214. return f.apply(this, arguments);
  7215. }
  7216. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7217. }
  7218. ump3.set(f, g);
  7219. g.km34 = 1;
  7220. h.onYtRendererstamperFinished = g;
  7221.  
  7222. }
  7223.  
  7224. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7225. const f = h.onYtUpdateDescriptionAction;
  7226. const g = ump3.get(f) || function (a) {
  7227. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7228. }
  7229. ump3.set(f, g);
  7230. g.km34 = 1;
  7231. h.onYtUpdateDescriptionAction = g;
  7232.  
  7233. }
  7234.  
  7235. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7236. const f = h.handleUpdateDescriptionAction;
  7237. const g = ump3.get(f) || function (a) {
  7238. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7239. }
  7240. ump3.set(f, g);
  7241. g.km34 = 1;
  7242. h.handleUpdateDescriptionAction = g;
  7243.  
  7244. }
  7245.  
  7246. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7247. const f = h.handleUpdateLiveChatPollAction;
  7248. const g = ump3.get(f) || function (a) {
  7249. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7250. }
  7251. ump3.set(f, g);
  7252. g.km34 = 1;
  7253. h.handleUpdateLiveChatPollAction = g;
  7254.  
  7255. }
  7256.  
  7257. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  7258. const f = h.onTextChanged;
  7259. const g = ump3.get(f) || function () {
  7260. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7261. }
  7262. ump3.set(f, g);
  7263. g.km34 = 1;
  7264. h.onTextChanged = g;
  7265.  
  7266. }
  7267.  
  7268. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  7269. const f = h.onVideoDataChange;
  7270. const g = ump3.get(f) || function (a) {
  7271. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7272. }
  7273. ump3.set(f, g);
  7274. g.km34 = 1;
  7275. h.onVideoDataChange = g;
  7276.  
  7277. }
  7278.  
  7279. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  7280. const f = h.onVideoDataChange_;
  7281. const g = ump3.get(f) || function () {
  7282. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7283. }
  7284. ump3.set(f, g);
  7285. g.km34 = 1;
  7286. h.onVideoDataChange_ = g;
  7287.  
  7288. }
  7289.  
  7290. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  7291.  
  7292. const f = h.addTooltips_;
  7293. const g = ump3.get(f) || function () {
  7294. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7295. }
  7296. ump3.set(f, g);
  7297. g.km34 = 1;
  7298. h.addTooltips_ = g;
  7299.  
  7300. }
  7301.  
  7302. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  7303.  
  7304. const f = h.updateRenderedElements;
  7305. const g = ump3.get(f) || function () {
  7306. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7307. }
  7308. ump3.set(f, g);
  7309. g.km34 = 1;
  7310. h.updateRenderedElements = g;
  7311.  
  7312. }
  7313.  
  7314. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  7315. const f = h.loadPage_;
  7316. const g = ump3.get(f) || function (a) {
  7317. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7318. }
  7319. ump3.set(f, g);
  7320. g.km34 = 1;
  7321. h.loadPage_ = g;
  7322.  
  7323. }
  7324. // updatePageData_ : possible conflict with Omit ShadyDOM
  7325. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  7326. const f = h.updatePageData_;
  7327. const g = ump3.get(f) || function (a) {
  7328. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7329. }
  7330. ump3.set(f, g);
  7331. g.km34 = 1;
  7332. h.updatePageData_ = g;
  7333.  
  7334. }
  7335.  
  7336.  
  7337. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  7338.  
  7339. const f = h.onFocus_;
  7340. const g = ump3.get(f) || function () {
  7341. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7342. }
  7343. ump3.set(f, g);
  7344. g.km34 = 1;
  7345. h.onFocus_ = g;
  7346.  
  7347. }
  7348.  
  7349. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  7350.  
  7351. const f = h.onBlur_;
  7352. const g = ump3.get(f) || function () {
  7353. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7354. }
  7355. ump3.set(f, g);
  7356. g.km34 = 1;
  7357. h.onBlur_ = g;
  7358.  
  7359. }
  7360.  
  7361.  
  7362. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  7363.  
  7364. const f = h.buttonClassChanged_;
  7365. const g = ump3.get(f) || function (a, b) {
  7366. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7367. }
  7368. ump3.set(f, g);
  7369. g.km34 = 1;
  7370. h.buttonClassChanged_ = g;
  7371.  
  7372. }
  7373.  
  7374. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  7375.  
  7376. const f = h.buttonIconChanged_;
  7377. const g = ump3.get(f) || function (a) {
  7378. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7379. }
  7380. ump3.set(f, g);
  7381. g.km34 = 1;
  7382. h.buttonIconChanged_ = g;
  7383.  
  7384. }
  7385.  
  7386. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  7387.  
  7388. const f = h.dataChangedInBehavior_;
  7389. const g = ump3.get(f) || function () {
  7390. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7391. }
  7392. ump3.set(f, g);
  7393. g.km34 = 1;
  7394. h.dataChangedInBehavior_ = g;
  7395.  
  7396. }
  7397.  
  7398. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  7399.  
  7400. const f = h.continuationsChanged_;
  7401. const g = ump3.get(f) || function () {
  7402. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7403. }
  7404. ump3.set(f, g);
  7405. g.km34 = 1;
  7406. h.continuationsChanged_ = g;
  7407.  
  7408. }
  7409.  
  7410.  
  7411. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  7412.  
  7413. const f = h.forceChatPoll_;
  7414. const g = ump3.get(f) || function (a) {
  7415. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7416. }
  7417. ump3.set(f, g);
  7418. g.km34 = 1;
  7419. h.forceChatPoll_ = g;
  7420.  
  7421. }
  7422.  
  7423. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  7424.  
  7425. const f = h.onEndpointClick_;
  7426. const g = ump3.get(f) || function (a) {
  7427. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7428. }
  7429. ump3.set(f, g);
  7430. g.km34 = 1;
  7431. h.onEndpointClick_ = g;
  7432.  
  7433. }
  7434.  
  7435. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  7436.  
  7437. const f = h.onEndpointTap_;
  7438. const g = ump3.get(f) || function (a) {
  7439. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7440. }
  7441. ump3.set(f, g);
  7442. g.km34 = 1;
  7443. h.onEndpointTap_ = g;
  7444.  
  7445. }
  7446.  
  7447. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  7448.  
  7449. const f = h.handleClick_;
  7450. const g = ump3.get(f) || function (a, b) {
  7451. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7452. }
  7453. ump3.set(f, g);
  7454. g.km34 = 1;
  7455. h.handleClick_ = g;
  7456.  
  7457. }
  7458.  
  7459. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  7460.  
  7461. const f = h.onReadyStateChange_;
  7462. const g = ump3.get(f) || function () {
  7463. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7464. }
  7465. ump3.set(f, g);
  7466. g.km34 = 1;
  7467. h.onReadyStateChange_ = g;
  7468.  
  7469. }
  7470.  
  7471. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  7472.  
  7473. const f = h.onReadyStateChangeEntryPoint_;
  7474. const g = ump3.get(f) || function () {
  7475. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7476. }
  7477. ump3.set(f, g);
  7478. g.km34 = 1;
  7479. h.onReadyStateChangeEntryPoint_ = g;
  7480.  
  7481. }
  7482.  
  7483. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  7484.  
  7485. const f = h.readyStateChangeHandler_;
  7486. const g = ump3.get(f) || function (a) {
  7487. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7488. }
  7489. ump3.set(f, g);
  7490. g.km34 = 1;
  7491. h.readyStateChangeHandler_ = g;
  7492.  
  7493. }
  7494.  
  7495. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  7496.  
  7497. const f = h.xmlHttpHandler_;
  7498. const g = ump3.get(f) || function (a) {
  7499. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7500. }
  7501. ump3.set(f, g);
  7502. g.km34 = 1;
  7503. h.xmlHttpHandler_ = g;
  7504.  
  7505. }
  7506.  
  7507. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  7508.  
  7509. const f = h.executeCallbacks_; // overloaded
  7510. const g = ump3.get(f) || function (a) {
  7511. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7512. }
  7513. ump3.set(f, g);
  7514. g.km34 = 1;
  7515. h.executeCallbacks_ = g;
  7516.  
  7517. }
  7518.  
  7519. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  7520.  
  7521. const f = h.handleInvalidationData_;
  7522. const g = ump3.get(f) || function (a, b) {
  7523. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7524. }
  7525. ump3.set(f, g);
  7526. g.km34 = 1;
  7527. h.handleInvalidationData_ = g;
  7528.  
  7529. }
  7530.  
  7531. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  7532.  
  7533. const f = h.onInput_;
  7534. const g = ump3.get(f) || function () {
  7535. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7536. }
  7537. ump3.set(f, g);
  7538. g.km34 = 1;
  7539. h.onInput_ = g;
  7540.  
  7541. }
  7542. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  7543.  
  7544. const f = h.trigger_;
  7545. const g = ump3.get(f) || function (a) {
  7546. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7547. }
  7548. ump3.set(f, g);
  7549. g.km34 = 1;
  7550. h.trigger_ = g;
  7551.  
  7552. }
  7553.  
  7554. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  7555.  
  7556. const f = h.requestData_;
  7557. const g = ump3.get(f) || function (a) {
  7558. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7559. }
  7560. ump3.set(f, g);
  7561. g.km34 = 1;
  7562. h.requestData_ = g;
  7563.  
  7564. }
  7565.  
  7566. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  7567.  
  7568. const f = h.onLoadReloadContinuation_;
  7569. const g = ump3.get(f) || function (a, b) {
  7570. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7571. }
  7572. ump3.set(f, g);
  7573. g.km34 = 1;
  7574. h.onLoadReloadContinuation_ = g;
  7575.  
  7576. }
  7577.  
  7578. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  7579.  
  7580. const f = h.onLoadIncrementalContinuation_;
  7581. const g = ump3.get(f) || function (a, b) {
  7582. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7583. }
  7584. ump3.set(f, g);
  7585. g.km34 = 1;
  7586. h.onLoadIncrementalContinuation_ = g;
  7587.  
  7588. }
  7589.  
  7590. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  7591.  
  7592. const f = h.onLoadSeekContinuation_;
  7593. const g = ump3.get(f) || function (a, b) {
  7594. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7595. }
  7596. ump3.set(f, g);
  7597. g.km34 = 1;
  7598. h.onLoadSeekContinuation_ = g;
  7599.  
  7600. }
  7601. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  7602.  
  7603. const f = h.onLoadReplayContinuation_;
  7604. const g = ump3.get(f) || function (a, b) {
  7605. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7606. }
  7607. ump3.set(f, g);
  7608. g.km34 = 1;
  7609. h.onLoadReplayContinuation_ = g;
  7610.  
  7611. }
  7612. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  7613.  
  7614. const f = h.onNavigate_;
  7615. const g = ump3.get(f) || function (a) {
  7616. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7617. }
  7618. ump3.set(f, g);
  7619. g.km34 = 1;
  7620. h.onNavigate_ = g;
  7621.  
  7622. }
  7623.  
  7624. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  7625.  
  7626. const f = h.ytRendererBehaviorDataObserver_;
  7627. const g = ump3.get(f) || function () {
  7628. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7629. }
  7630. ump3.set(f, g);
  7631. g.km34 = 1;
  7632. h.ytRendererBehaviorDataObserver_ = g;
  7633.  
  7634. }
  7635.  
  7636. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  7637.  
  7638. const f = h.ytRendererBehaviorTargetIdObserver_;
  7639. const g = ump3.get(f) || function () {
  7640. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7641. }
  7642. ump3.set(f, g);
  7643. g.km34 = 1;
  7644. h.ytRendererBehaviorTargetIdObserver_ = g;
  7645.  
  7646. }
  7647.  
  7648. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  7649.  
  7650. const f = h.unregisterRenderer_;
  7651. const g = ump3.get(f) || function (a) {
  7652. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7653. }
  7654. ump3.set(f, g);
  7655. g.km34 = 1;
  7656. h.unregisterRenderer_ = g;
  7657.  
  7658. }
  7659.  
  7660. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  7661.  
  7662. const f = h.textChanged_;
  7663. const g = ump3.get(f) || function (a) {
  7664. if (void 0 !== this.isAttached) {
  7665. const hostElement = this.hostElement;
  7666. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  7667. return;
  7668. }
  7669. }
  7670. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7671. }
  7672. ump3.set(f, g);
  7673. g.km34 = 1;
  7674. h.textChanged_ = g;
  7675.  
  7676. }
  7677.  
  7678.  
  7679.  
  7680. /**
  7681. *
  7682. * Neglect following
  7683. *
  7684. * h.onYtAction_
  7685. * h.startLoadingWatch [ buggy for yt-player-updated ]
  7686. * h.deferRenderStamperBinding_
  7687. *
  7688. * h.stampDomArray_
  7689. * h.stampDomArraySplices_
  7690. *
  7691. */
  7692.  
  7693.  
  7694. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  7695. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  7696. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  7697. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  7698. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  7699. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  7700.  
  7701. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  7702.  
  7703. const f = h.searchChanged_;
  7704. const g = ump3.get(f) || function () {
  7705. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7706. }
  7707. ump3.set(f, g);
  7708. g.km34 = 1;
  7709. h.searchChanged_ = g;
  7710.  
  7711. }
  7712.  
  7713. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  7714.  
  7715. const f = h.skinToneChanged_;
  7716. const g = ump3.get(f) || function (a) {
  7717. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7718. }
  7719. ump3.set(f, g);
  7720. g.km34 = 1;
  7721. h.skinToneChanged_ = g;
  7722.  
  7723. }
  7724.  
  7725. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  7726.  
  7727. const f = h.onEmojiHover_;
  7728. const g = ump3.get(f) || function (a) {
  7729. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7730. }
  7731. ump3.set(f, g);
  7732. g.km34 = 1;
  7733. h.onEmojiHover_ = g;
  7734.  
  7735. }
  7736.  
  7737. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  7738.  
  7739. const f = h.onSelectCategory_;
  7740. const g = ump3.get(f) || function (a) {
  7741. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7742. }
  7743. ump3.set(f, g);
  7744. g.km34 = 1;
  7745. h.onSelectCategory_ = g;
  7746.  
  7747. }
  7748.  
  7749. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  7750.  
  7751. const f = h.onShowEmojiVariantSelector;
  7752. const g = ump3.get(f) || function (a) {
  7753. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7754. }
  7755. ump3.set(f, g);
  7756. g.km34 = 1;
  7757. h.onShowEmojiVariantSelector = g;
  7758.  
  7759. }
  7760.  
  7761. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  7762.  
  7763. const f = h.updateCategoriesAndPlaceholder_;
  7764. const g = ump3.get(f) || function () {
  7765. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7766. }
  7767. ump3.set(f, g);
  7768. g.km34 = 1;
  7769. h.updateCategoriesAndPlaceholder_ = g;
  7770.  
  7771. }
  7772.  
  7773. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  7774.  
  7775. const f = h.watchPageActiveChanged_;
  7776. const g = ump3.get(f) || function () {
  7777. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7778. }
  7779. ump3.set(f, g);
  7780. g.km34 = 1;
  7781. h.watchPageActiveChanged_ = g;
  7782.  
  7783. }
  7784.  
  7785. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  7786.  
  7787. const f = h.activate_;
  7788. const g = ump3.get(f) || function () {
  7789. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7790. }
  7791. ump3.set(f, g);
  7792. g.km34 = 1;
  7793. h.activate_ = g;
  7794.  
  7795. }
  7796. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  7797.  
  7798. const f = h.onYtPlaylistDataUpdated_;
  7799. const g = ump3.get(f) || function () {
  7800. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7801. }
  7802. ump3.set(f, g);
  7803. g.km34 = 1;
  7804. h.onYtPlaylistDataUpdated_ = g;
  7805.  
  7806. }
  7807.  
  7808.  
  7809.  
  7810. /**
  7811. *
  7812. * Neglect following
  7813. *
  7814. * h.rendererStamperObserver_
  7815. * h.rendererStamperApplyChangeRecord_
  7816. * h.flushRenderStamperComponentBindings_
  7817. * h.forwardRendererStamperChanges_
  7818. *
  7819. */
  7820.  
  7821. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  7822.  
  7823. const f = h.tryRenderChunk_;
  7824. const g = ump3.get(f) || function () {
  7825. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7826. }
  7827. ump3.set(f, g);
  7828. g.km34 = 1;
  7829. h.tryRenderChunk_ = g;
  7830.  
  7831. }
  7832.  
  7833.  
  7834. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  7835.  
  7836. const f = h.renderChunk_;
  7837. const g = ump3.get(f) || function () {
  7838. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7839. }
  7840. ump3.set(f, g);
  7841. g.km34 = 1;
  7842. h.renderChunk_ = g;
  7843.  
  7844. }
  7845.  
  7846. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  7847.  
  7848. const f = h.deepLazyListObserver_;
  7849. const g = ump3.get(f) || function () {
  7850. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7851. }
  7852. ump3.set(f, g);
  7853. g.km34 = 1;
  7854. h.deepLazyListObserver_ = g;
  7855.  
  7856. }
  7857.  
  7858. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  7859.  
  7860. const f = h.onItemsUpdated_;
  7861. const g = ump3.get(f) || function () {
  7862. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7863. }
  7864. ump3.set(f, g);
  7865. g.km34 = 1;
  7866. h.onItemsUpdated_ = g;
  7867.  
  7868. }
  7869.  
  7870. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  7871.  
  7872. const f = h.requestRenderChunk_;
  7873. const g = ump3.get(f) || function () {
  7874. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7875. }
  7876. ump3.set(f, g);
  7877. g.km34 = 1;
  7878. h.requestRenderChunk_ = g;
  7879.  
  7880. }
  7881.  
  7882. /**
  7883. *
  7884. * Neglect following
  7885. *
  7886. * h.dataChanged_ [ buggy for page swtiching ]
  7887. *
  7888. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  7889. *
  7890. * h.cancelPendingTasks_
  7891. * h.fillRange_
  7892. * h.addTextNodes_
  7893. * h.updateText_
  7894. * h.stampTypeChanged_
  7895. *
  7896. */
  7897.  
  7898.  
  7899. }
  7900.  
  7901. const keyStConnectedCallback = Symbol(); // avoid copying the value
  7902.  
  7903. const dmf = new WeakMap();
  7904.  
  7905.  
  7906. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  7907.  
  7908. try {
  7909.  
  7910. const q = document.createElement('template');
  7911. q.innerHTML = '<ytz-null361></ytz-null361>';
  7912. nativeHTMLElement = q.content.firstChild.constructor
  7913.  
  7914. } catch (e) { }
  7915.  
  7916. if (!nativeHTMLElement.prototype.connectedCallback) {
  7917. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  7918. nativeHTMLElement.prototype.connectedCallback = function () {
  7919. let r;
  7920. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  7921. return r;
  7922. }
  7923. }
  7924. const pvr = Symbol()
  7925.  
  7926. let stampDomArrayFnStore = null;
  7927. const setupMap = new WeakSet();
  7928. const setupYtComponent = (cnt) => {
  7929. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  7930. if (!cProto || setupMap.has(cProto)) return;
  7931. setupMap.add(cProto);
  7932. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  7933. cProto[pvr] |= 1;
  7934.  
  7935.  
  7936.  
  7937. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  7938. const b = cProto.stampDomArray_.length === 6
  7939. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  7940. && cProto.createComponent_ && cProto.createComponent_.length === 3
  7941. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  7942. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  7943. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  7944. if (!b) {
  7945. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  7946. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  7947. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  7948. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_} = stampDomArrayFnStore;
  7949.  
  7950. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  7951. cProto.createComponent7409_ = cProto.createComponent_;
  7952. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  7953. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  7954. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  7955. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  7956.  
  7957. cProto.getStampContainer_ = getStampContainer_;
  7958. cProto.createComponent_ = createComponent_;
  7959. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  7960. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  7961. cProto.stampDomArray_ = stampDomArray_;
  7962. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  7963.  
  7964. }
  7965. }
  7966.  
  7967.  
  7968.  
  7969.  
  7970. if(cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  7971. cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  7972.  
  7973. if(cProto._runEffectsForTemplate6344.length === 4){
  7974.  
  7975. cProto._runEffectsForTemplate = function (c, d, e, g) {
  7976. const cnt = this;
  7977. const { propertyEffects, nodeList, firstChild } = c;
  7978. cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  7979.  
  7980. }
  7981.  
  7982. }
  7983.  
  7984. }
  7985.  
  7986. }
  7987. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  7988. cProto[pvr] |= 2;
  7989. setupDiscreteTasks(cProto);
  7990. }
  7991. };
  7992.  
  7993. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  7994. get() {
  7995. const f = this[keyStConnectedCallback];
  7996. if (this.is) {
  7997. setupYtComponent(this);
  7998. }
  7999. return f;
  8000. },
  8001. set(nv) {
  8002. let gv = nv;
  8003. this[keyStConnectedCallback] = gv; // proto or object
  8004. return true;
  8005. },
  8006. enumerable: false,
  8007. configurable: true
  8008.  
  8009. });
  8010.  
  8011. const pLoad = new Promise(resolve => {
  8012. if (document.readyState !== 'loading') {
  8013. resolve();
  8014. } else {
  8015. window.addEventListener("DOMContentLoaded", resolve, false);
  8016. }
  8017. });
  8018.  
  8019. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  8020. window.requestIdleCallback471 = window.requestIdleCallback;
  8021. window.requestIdleCallback = function (f, ...args) {
  8022. return (this || window).requestIdleCallback471(async function () {
  8023. await pLoad.then();
  8024. // await new Promise(nextBrowserTick_);
  8025. f.call(this, ...arguments)
  8026. }, ...args);
  8027. }
  8028. }
  8029.  
  8030. pLoad.then(() => {
  8031.  
  8032. let nonce = document.querySelector('style[nonce]');
  8033. nonce = nonce ? nonce.getAttribute('nonce') : null;
  8034. const st = document.createElement('style');
  8035. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  8036. st.textContent = "none-element-k47{order:0}";
  8037. st.addEventListener('load', () => {
  8038. pf31.resolve();
  8039. p59 = 1;
  8040. }, false);
  8041. (document.body || document.head || document.documentElement).appendChild(st);
  8042.  
  8043. });
  8044.  
  8045. const prepareLogs = [];
  8046.  
  8047. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  8048.  
  8049. let winError00 = window.onerror;
  8050.  
  8051. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  8052.  
  8053. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  8054.  
  8055. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  8056.  
  8057. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  8058. const lcOpt = { sensitivity: 'base' };
  8059. document.createElement24 = document.createElement;
  8060. document.createElement = function (t) {
  8061. if (typeof t === 'string' && t.length === 6) {
  8062. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  8063. const p = this.createElement24(t);
  8064. try {
  8065. const stack = new Error().stack;
  8066. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  8067. if (!isSearchbox) {
  8068. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  8069. }
  8070. } catch (e) { }
  8071. return p;
  8072. }
  8073. }
  8074. return this.createElement24.apply(this, arguments);
  8075. };
  8076.  
  8077. })();
  8078.  
  8079. ; fix_error_many_stack_state === 1 && (() => {
  8080.  
  8081.  
  8082. let p1 = winError00;
  8083.  
  8084. let stackNeedleDetails = null;
  8085.  
  8086. Object.defineProperty(Object.prototype, 'matchAll', {
  8087. get() {
  8088. stackNeedleDetails = this;
  8089. return true;
  8090. },
  8091. enumerable: true,
  8092. configurable: true
  8093. });
  8094.  
  8095. try {
  8096. JSON.parse("{}");
  8097. } catch (e) {
  8098. console.warn(e)
  8099. fix_error_many_stack_state = 0;
  8100. }
  8101.  
  8102. delete Object.prototype['matchAll'];
  8103.  
  8104. let p2 = window.onerror;
  8105.  
  8106. window.onerror = p1;
  8107.  
  8108. if (fix_error_many_stack_state === 0) return;
  8109.  
  8110. if (stackNeedleDetails) {
  8111. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8112. stackNeedleDetails.matchAll = true;
  8113. }
  8114.  
  8115. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8116.  
  8117. // p1!==p2
  8118. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8119.  
  8120. })();
  8121.  
  8122. ; fix_error_many_stack_state === 2 && (() => {
  8123.  
  8124.  
  8125. let p1 = winError00;
  8126.  
  8127. let objectPrune = null;
  8128. let stackNeedleDetails = null;
  8129.  
  8130. Object.defineProperty(Function.prototype, 'findOwner', {
  8131. get() {
  8132. objectPrune = this;
  8133. return this._findOwner;
  8134. },
  8135. set(nv) {
  8136. this._findOwner = nv;
  8137. return true;
  8138. },
  8139. enumerable: true,
  8140. configurable: true
  8141. });
  8142.  
  8143. Object.defineProperty(Object.prototype, 'matchAll', {
  8144. get() {
  8145. stackNeedleDetails = this;
  8146. return true;
  8147. },
  8148. enumerable: true,
  8149. configurable: true
  8150. });
  8151.  
  8152. try {
  8153. JSON.parse("{}");
  8154. } catch (e) {
  8155. console.warn(e)
  8156. fix_error_many_stack_state = 0;
  8157. }
  8158.  
  8159. delete Function.prototype['findOwner'];
  8160. delete Object.prototype['matchAll'];
  8161.  
  8162. let p2 = window.onerror;
  8163.  
  8164. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8165.  
  8166. if (fix_error_many_stack_state == 0) return;
  8167.  
  8168. // the following will only execute when Brave's scriptlets.js is executed.
  8169.  
  8170. prepareLogs.push("fix_error_many_stack_state NB")
  8171.  
  8172. if (stackNeedleDetails) {
  8173. stackNeedleDetails.pattern = null;
  8174. stackNeedleDetails.re = null;
  8175. stackNeedleDetails.expect = null;
  8176. stackNeedleDetails.matchAll = true;
  8177. }
  8178.  
  8179. if (objectPrune) {
  8180. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8181. delete objectPrune._findOwner;
  8182. }
  8183.  
  8184. fix_error_many_stack_state = 3;
  8185. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8186. JSON.parse.objectPrune = objectPrune;
  8187.  
  8188. })();
  8189.  
  8190. ; fix_error_many_stack_state === 3 && (() => {
  8191.  
  8192.  
  8193. let p1 = winError00;
  8194.  
  8195. try {
  8196. JSON.parse("{}");
  8197. } catch (e) {
  8198. console.warn(e)
  8199. fix_error_many_stack_state = 0;
  8200. }
  8201.  
  8202. let p2 = window.onerror;
  8203.  
  8204. if (p1 === p2) return;
  8205.  
  8206. window.onerror = p1;
  8207.  
  8208. if (fix_error_many_stack_state === 0) return;
  8209.  
  8210. fix_error_many_stack_state = 4; // p1 != p2
  8211.  
  8212.  
  8213. })();
  8214.  
  8215. fix_error_many_stack_state === 4 && (() => {
  8216.  
  8217. // the following will only execute when Brave's scriptlets.js is executed.
  8218.  
  8219. prepareLogs.push("fix_error_many_stack_state AB")
  8220.  
  8221. JSON.parseProxy = JSON.parse;
  8222.  
  8223. JSON.parse = ((parse) => {
  8224.  
  8225. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8226. return function (text, reviver) {
  8227. const onerror = window.onerror;
  8228. window.onerror = null;
  8229. let r;
  8230. try {
  8231. r = parse(...arguments);
  8232. } catch (e) {
  8233. r = e;
  8234. }
  8235. window.onerror = onerror;
  8236. if (r instanceof Error) {
  8237. throw r;
  8238. }
  8239. return r;
  8240. }
  8241.  
  8242. })(JSON.parse);
  8243.  
  8244.  
  8245. })();
  8246.  
  8247.  
  8248. // << if FIX_yt_player >>
  8249.  
  8250. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  8251. const PERF_471489_ = true;
  8252. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8253. // This script uses a much gentle way to tamer the JS engine instead.
  8254.  
  8255. // << end >>
  8256.  
  8257. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8258.  
  8259.  
  8260.  
  8261. const nilFn = () => { };
  8262.  
  8263. let isMainWindow = false;
  8264. try {
  8265. isMainWindow = window.document === window.top.document
  8266. } catch (e) { }
  8267.  
  8268. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  8269. let headLinkCollection = null;
  8270.  
  8271.  
  8272. // const assertor = (f) => f() || console.assert(false, `${f}`);
  8273.  
  8274. const fnIntegrity = (f, d) => {
  8275. if (!f || typeof f !== 'function') {
  8276. console.warn('f is not a function', f);
  8277. return;
  8278. }
  8279. let p = `${f}`, s = 0, j = -1, w = 0;
  8280. for (let i = 0, l = p.length; i < l; i++) {
  8281. const t = p[i];
  8282. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8283. if (j < i - 1) w++;
  8284. j = i;
  8285. } else {
  8286. s++;
  8287. }
  8288. }
  8289. let itz = `${f.length}.${s}.${w}`;
  8290. if (!d) {
  8291. return itz;
  8292. } else {
  8293. return itz === d;
  8294. }
  8295. };
  8296.  
  8297. const getZqOu = (_yt_player) => {
  8298.  
  8299. const w = 'ZqOu';
  8300.  
  8301. let arr = [];
  8302.  
  8303. for (const [k, v] of Object.entries(_yt_player)) {
  8304.  
  8305. const p = typeof v === 'function' ? v.prototype : 0;
  8306. if (p
  8307. && typeof p.start === 'function' && p.start.length === 0 // Ou
  8308. && typeof p.isActive === 'function' && p.isActive.length === 0
  8309. && typeof p.stop === 'function' && p.stop.length === 0
  8310. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8311. && !p.send && !p.abort
  8312. && !p.sample && !p.initialize && !p.fail && !p.getName
  8313. // && !p.dispose && !p.isDisposed
  8314.  
  8315. ) {
  8316. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8317.  
  8318.  
  8319. }
  8320.  
  8321. }
  8322.  
  8323. if (arr.length === 0) {
  8324.  
  8325. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8326. } else {
  8327.  
  8328. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8329. return arr[0];
  8330. }
  8331.  
  8332. }
  8333.  
  8334. const getZqQu = (_yt_player) => {
  8335.  
  8336. const w = 'ZqQu';
  8337.  
  8338. let arr = [];
  8339.  
  8340.  
  8341. for (const [k, v] of Object.entries(_yt_player)) {
  8342.  
  8343. const p = typeof v === 'function' ? v.prototype : 0;
  8344. if (p
  8345. && typeof p.start === 'function' && p.start.length === 1 // Qu
  8346. && typeof p.isActive === 'function' && p.isActive.length === 0
  8347. && typeof p.stop === 'function' && p.stop.length === 0
  8348. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8349. && !p.send && !p.abort
  8350. && !p.sample && !p.initialize && !p.fail && !p.getName
  8351. // && !p.dispose && !p.isDisposed
  8352.  
  8353. ) {
  8354. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8355.  
  8356.  
  8357. }
  8358.  
  8359. }
  8360.  
  8361. if (arr.length === 0) {
  8362.  
  8363. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8364. } else {
  8365.  
  8366. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8367. return arr[0];
  8368. }
  8369.  
  8370. }
  8371.  
  8372.  
  8373. const getVG = (_yt_player) => {
  8374. const w = 'VG';
  8375.  
  8376. let arr = [];
  8377.  
  8378. for (const [k, v] of Object.entries(_yt_player)) {
  8379.  
  8380. const p = typeof v === 'function' ? v.prototype : 0;
  8381. if (p
  8382. && typeof p.show === 'function' && p.show.length === 1
  8383. && typeof p.hide === 'function' && p.hide.length === 0
  8384. && typeof p.stop === 'function' && p.stop.length === 0) {
  8385.  
  8386. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8387.  
  8388. }
  8389.  
  8390. }
  8391.  
  8392.  
  8393. if (arr.length === 0) {
  8394.  
  8395. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8396. } else {
  8397.  
  8398. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8399. return arr[0];
  8400. }
  8401.  
  8402.  
  8403.  
  8404. }
  8405.  
  8406.  
  8407. const getzo = (_yt_player) => {
  8408. const w = 'zo';
  8409.  
  8410. let arr = [];
  8411.  
  8412. for (const [k, v] of Object.entries(_yt_player)) {
  8413.  
  8414. if (
  8415. typeof v === 'function' && v.length === 3 && k.length < 3
  8416. ) {
  8417. const vt = `${v}`;
  8418. if (vt.length >= 21 && vt.includes(".style[")) {
  8419. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  8420. arr.push(k);
  8421. } else {
  8422. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  8423. }
  8424. }
  8425. }
  8426.  
  8427. }
  8428.  
  8429. if (arr.length === 0) {
  8430.  
  8431. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8432. } else {
  8433.  
  8434. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8435. return arr[0];
  8436. }
  8437.  
  8438. }
  8439.  
  8440. const addProtoToArr = (parent, key, arr) => {
  8441.  
  8442.  
  8443. let isChildProto = false;
  8444. for (const sr of arr) {
  8445. if (parent[key].prototype instanceof parent[sr]) {
  8446. isChildProto = true;
  8447. break;
  8448. }
  8449. }
  8450.  
  8451. if (isChildProto) return;
  8452.  
  8453. arr = arr.filter(sr => {
  8454. if (parent[sr].prototype instanceof parent[key]) {
  8455. return false;
  8456. }
  8457. return true;
  8458. });
  8459.  
  8460. arr.push(key);
  8461.  
  8462. return arr;
  8463.  
  8464.  
  8465. }
  8466.  
  8467. const getuG = (_yt_player) => {
  8468.  
  8469. const w = 'uG';
  8470.  
  8471. let arr = [];
  8472.  
  8473. for (const [k, v] of Object.entries(_yt_player)) {
  8474.  
  8475.  
  8476. const p = typeof v === 'function' ? v.prototype : 0;
  8477.  
  8478. if (p
  8479. && typeof p.createElement === 'function' && p.createElement.length === 2
  8480. && typeof p.detach === 'function' && p.detach.length === 0
  8481. && typeof p.update === 'function' && p.update.length === 1
  8482. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  8483. ) {
  8484.  
  8485. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8486.  
  8487. }
  8488.  
  8489. }
  8490.  
  8491.  
  8492.  
  8493.  
  8494.  
  8495. if (arr.length === 0) {
  8496.  
  8497. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8498. } else {
  8499.  
  8500. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8501. return arr[0];
  8502. }
  8503.  
  8504. }
  8505.  
  8506.  
  8507. const getQT = (_yt_player) => {
  8508. const w = 'QT';
  8509.  
  8510. let arr = [];
  8511. let brr = new Map();
  8512.  
  8513. for (const [k, v] of Object.entries(_yt_player)) {
  8514.  
  8515. const p = typeof v === 'function' ? v.prototype : 0;
  8516. if (p) {
  8517. let q = 0;
  8518. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8519. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8520. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8521.  
  8522. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8523.  
  8524. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8525.  
  8526. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8527. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8528. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8529. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8530.  
  8531.  
  8532. // differentiate QT and DX
  8533.  
  8534. q += 280;
  8535. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  8536. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  8537. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  8538. if (typeof p.seekBy === 'function') q += 4;
  8539. if (typeof p.seekTo === 'function') q += 4;
  8540. if (typeof p.getStoryboardFormat === 'function') q += 4;
  8541. if (typeof p.getDuration === 'function') q += 4;
  8542. if (typeof p.loadModule === 'function') q += 4;
  8543. if (typeof p.unloadModule === 'function') q += 4;
  8544. if (typeof p.getOption === 'function') q += 4;
  8545. if (typeof p.getOptions === 'function') q += 4;
  8546. if (typeof p.setOption === 'function') q += 4;
  8547. if (typeof p.addCueRange === 'function') q += 4;
  8548. if (typeof p.getDebugText === 'function') q += 4;
  8549. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  8550. if (typeof p.setSizeStyle === 'function') q += 4;
  8551. if (typeof p.showControls === 'function') q += 4;
  8552. if (typeof p.hideControls === 'function') q += 4;
  8553. if (typeof p.getVideoContentRect === 'function') q += 4;
  8554. if (typeof p.toggleFullscreen === 'function') q += 4;
  8555. if (typeof p.isFullscreen === 'function') q += 4;
  8556. if (typeof p.cancelPlayback === 'function') q += 4;
  8557. if (typeof p.getProgressState === 'function') q += 4;
  8558. if (typeof p.isInline === 'function') q += 4;
  8559. if (typeof p.setInline === 'function') q += 4;
  8560. if (typeof p.toggleSubtitles === 'function') q += 4;
  8561. if (typeof p.getPlayerSize === 'function') q += 4;
  8562. if (typeof p.wakeUpControls === 'function') q += 4;
  8563. if (typeof p.setCenterCrop === 'function') q += 4;
  8564. if (typeof p.getLoopVideo === 'function') q += 4;
  8565. if (typeof p.setLoopVideo === 'function') q += 4;
  8566.  
  8567.  
  8568. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8569.  
  8570. if (q > 0) brr.set(k, q);
  8571.  
  8572. }
  8573.  
  8574. }
  8575.  
  8576. if (arr.length === 0) {
  8577.  
  8578. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8579. } else {
  8580.  
  8581. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8582.  
  8583. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8584.  
  8585. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8586. return arr[0][0];
  8587. }
  8588.  
  8589.  
  8590.  
  8591. }
  8592.  
  8593.  
  8594.  
  8595. const getSV = (_yt_player) => {
  8596. const w = 'SV';
  8597.  
  8598. let arr = [];
  8599. let brr = new Map();
  8600.  
  8601. for (const [k, v] of Object.entries(_yt_player)) {
  8602.  
  8603. const p = typeof v === 'function' ? v.prototype : 0;
  8604. if (p) {
  8605. let q = 0;
  8606. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8607. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8608. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8609.  
  8610. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  8611.  
  8612. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8613.  
  8614. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8615. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8616. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8617. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8618.  
  8619.  
  8620. // differentiate QT and DX
  8621.  
  8622.  
  8623. q += 280;
  8624.  
  8625. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  8626. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  8627. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  8628. if (typeof p.seekBy === 'function') q -= 4;
  8629. if (typeof p.seekTo === 'function') q -= 4;
  8630. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  8631. if (typeof p.getDuration === 'function') q -= 4;
  8632. if (typeof p.loadModule === 'function') q -= 4;
  8633. if (typeof p.unloadModule === 'function') q -= 4;
  8634. if (typeof p.getOption === 'function') q -= 4;
  8635. if (typeof p.getOptions === 'function') q -= 4;
  8636. if (typeof p.setOption === 'function') q -= 4;
  8637. if (typeof p.addCueRange === 'function') q -= 4;
  8638. if (typeof p.getDebugText === 'function') q -= 4;
  8639. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  8640. if (typeof p.setSizeStyle === 'function') q -= 4;
  8641. if (typeof p.showControls === 'function') q -= 4;
  8642. if (typeof p.hideControls === 'function') q -= 4;
  8643. if (typeof p.getVideoContentRect === 'function') q -= 4;
  8644. if (typeof p.toggleFullscreen === 'function') q -= 4;
  8645. if (typeof p.isFullscreen === 'function') q -= 4;
  8646. if (typeof p.cancelPlayback === 'function') q -= 4;
  8647. if (typeof p.getProgressState === 'function') q -= 4;
  8648. if (typeof p.isInline === 'function') q -= 4;
  8649. if (typeof p.setInline === 'function') q -= 4;
  8650. if (typeof p.toggleSubtitles === 'function') q -= 4;
  8651. if (typeof p.getPlayerSize === 'function') q -= 4;
  8652. if (typeof p.wakeUpControls === 'function') q -= 4;
  8653. if (typeof p.setCenterCrop === 'function') q -= 4;
  8654. if (typeof p.getLoopVideo === 'function') q -= 4;
  8655. if (typeof p.setLoopVideo === 'function') q -= 4;
  8656.  
  8657.  
  8658. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8659.  
  8660. if (q > 0) brr.set(k, q);
  8661.  
  8662. }
  8663.  
  8664. }
  8665.  
  8666. if (arr.length === 0) {
  8667.  
  8668. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8669. } else {
  8670.  
  8671. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8672.  
  8673. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8674.  
  8675. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8676. return arr[0][0];
  8677. }
  8678.  
  8679.  
  8680.  
  8681. }
  8682.  
  8683.  
  8684.  
  8685.  
  8686. const getDX = (_yt_player) => {
  8687. const w = 'DX';
  8688.  
  8689. let arr = [];
  8690. let brr = new Map();
  8691.  
  8692. for (const [k, v] of Object.entries(_yt_player)) {
  8693.  
  8694. const p = typeof v === 'function' ? v.prototype : 0;
  8695. if (p) {
  8696. let q = 0;
  8697. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8698. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8699. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8700.  
  8701. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8702.  
  8703.  
  8704. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  8705.  
  8706. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8707.  
  8708. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8709. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8710. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8711. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8712.  
  8713.  
  8714. // differentiate QT and DX
  8715.  
  8716.  
  8717. q += 280;
  8718.  
  8719. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  8720. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  8721. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  8722. if (typeof p.seekBy === 'function') q -= 4;
  8723. if (typeof p.seekTo === 'function') q -= 4;
  8724. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  8725. if (typeof p.getDuration === 'function') q -= 4;
  8726. if (typeof p.loadModule === 'function') q -= 4;
  8727. if (typeof p.unloadModule === 'function') q -= 4;
  8728. if (typeof p.getOption === 'function') q -= 4;
  8729. if (typeof p.getOptions === 'function') q -= 4;
  8730. if (typeof p.setOption === 'function') q -= 4;
  8731. if (typeof p.addCueRange === 'function') q -= 4;
  8732. if (typeof p.getDebugText === 'function') q -= 4;
  8733. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  8734. if (typeof p.setSizeStyle === 'function') q -= 4;
  8735. if (typeof p.showControls === 'function') q -= 4;
  8736. if (typeof p.hideControls === 'function') q -= 4;
  8737. if (typeof p.getVideoContentRect === 'function') q -= 4;
  8738. if (typeof p.toggleFullscreen === 'function') q -= 4;
  8739. if (typeof p.isFullscreen === 'function') q -= 4;
  8740. if (typeof p.cancelPlayback === 'function') q -= 4;
  8741. if (typeof p.getProgressState === 'function') q -= 4;
  8742. if (typeof p.isInline === 'function') q -= 4;
  8743. if (typeof p.setInline === 'function') q -= 4;
  8744. if (typeof p.toggleSubtitles === 'function') q -= 4;
  8745. if (typeof p.getPlayerSize === 'function') q -= 4;
  8746. if (typeof p.wakeUpControls === 'function') q -= 4;
  8747. if (typeof p.setCenterCrop === 'function') q -= 4;
  8748. if (typeof p.getLoopVideo === 'function') q -= 4;
  8749. if (typeof p.setLoopVideo === 'function') q -= 4;
  8750.  
  8751.  
  8752. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8753.  
  8754. if (q > 0) brr.set(k, q);
  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. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8766.  
  8767. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8768.  
  8769. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8770. return arr[0][0];
  8771. }
  8772.  
  8773.  
  8774.  
  8775. }
  8776.  
  8777.  
  8778.  
  8779. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  8780.  
  8781. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  8782. let pageSetupState = 0;
  8783.  
  8784. isPrepareCachedV && (() => {
  8785.  
  8786. pageSetupVideoId = '';
  8787. const clearCachedV = () => {
  8788. pageSetupVideoId = '';
  8789. pageSetupState = 0;
  8790. }
  8791. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  8792. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  8793. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  8794. document.addEventListener('yt-navigate-finish', () => {
  8795. pageSetupState = 1;
  8796. try {
  8797. const url = new URL(location.href);
  8798. if (!url || !isWatchPageURL(url)) {
  8799. pageSetupVideoId = '';
  8800. } else {
  8801. pageSetupVideoId = url.searchParams.get('v') || '';
  8802. }
  8803. } catch (e) {
  8804. pageSetupVideoId = '';
  8805. }
  8806. }, false);
  8807.  
  8808. })();
  8809.  
  8810. let videoPlayingY = null;
  8811.  
  8812. isPrepareCachedV && (() => {
  8813.  
  8814. let getNext = true;
  8815. let videoPlayingX = {
  8816. get videoId() {
  8817. if (getNext) {
  8818. getNext = false;
  8819.  
  8820. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  8821. const arr = [];
  8822. for (const element of elements) {
  8823. if (!element.closest('[hidden]')) arr.push(element);
  8824. }
  8825. if (arr.length !== 1) this.__videoId__ = '';
  8826. else {
  8827. this.__videoId__ = arr[0].getAttribute('video-id');
  8828. }
  8829.  
  8830. }
  8831. return this.__videoId__ || '';
  8832. }
  8833. }
  8834.  
  8835. videoPlayingY = videoPlayingX;
  8836. const handler = (evt) => {
  8837. const target = (evt || 0).target;
  8838. if (target instanceof HTMLVideoElement) {
  8839. getNext = true;
  8840. }
  8841. }
  8842. document.addEventListener('loadedmetadata', handler, true);
  8843. document.addEventListener('durationchange', handler, true);
  8844.  
  8845. })();
  8846.  
  8847.  
  8848.  
  8849. const cleanContext = async (win) => {
  8850. const waitFn = requestAnimationFrame; // shall have been binded to window
  8851. try {
  8852. let mx = 16; // MAX TRIAL
  8853. const frameId = 'vanillajs-iframe-v1';
  8854. /** @type {HTMLIFrameElement | null} */
  8855. let frame = document.getElementById(frameId);
  8856. let removeIframeFn = null;
  8857. if (!frame) {
  8858. frame = document.createElement('iframe');
  8859. frame.id = frameId;
  8860. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  8861. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  8862. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  8863. n.appendChild(frame);
  8864. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  8865. const root = document.documentElement;
  8866. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  8867. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  8868.  
  8869. removeIframeFn = (setTimeout) => {
  8870. const removeIframeOnDocumentReady = (e) => {
  8871. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  8872. e = n;
  8873. n = win = removeIframeFn = 0;
  8874. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  8875. }
  8876. if (!setTimeout || document.readyState !== 'loading') {
  8877. removeIframeOnDocumentReady();
  8878. } else {
  8879. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  8880. }
  8881. }
  8882. }
  8883. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  8884. const fc = frame.contentWindow;
  8885. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  8886. try {
  8887. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  8888. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  8889. for (let k in res) res[k] = res[k].bind(win); // necessary
  8890. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  8891. res.animate = fc.HTMLElement.prototype.animate;
  8892. res.perfNow = fc.performance.now;
  8893. return res;
  8894. } catch (e) {
  8895. if (removeIframeFn) removeIframeFn();
  8896. return null;
  8897. }
  8898. } catch (e) {
  8899. console.warn(e);
  8900. return null;
  8901. }
  8902. };
  8903.  
  8904. const promiseForYtActionCalled = new Promise(resolve => {
  8905.  
  8906. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8907. if (typeof AbortSignal !== 'undefined') {
  8908. let hn = () => {
  8909. if (!hn) return;
  8910. hn = null;
  8911. resolve(document.querySelector(appTag));
  8912. };
  8913. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  8914. } else {
  8915. let hn = () => {
  8916. if (!hn) return;
  8917. document.removeEventListener('yt-action', hn, true);
  8918. hn = null;
  8919. resolve(document.querySelector(appTag));
  8920. };
  8921. document.addEventListener('yt-action', hn, true);
  8922. }
  8923. });
  8924.  
  8925. cleanContext(window).then(__CONTEXT__ => {
  8926. if (!__CONTEXT__) return null;
  8927.  
  8928. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  8929.  
  8930.  
  8931. performance.now17 = perfNow.bind(performance);
  8932.  
  8933.  
  8934.  
  8935. __requestAnimationFrame__ = requestAnimationFrame;
  8936.  
  8937.  
  8938. const isGPUAccelerationAvailable = (() => {
  8939. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  8940. try {
  8941. const canvas = document.createElement('canvas');
  8942. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  8943. } catch (e) {
  8944. return false;
  8945. }
  8946. })();
  8947.  
  8948. const foregroundPromiseFn_noGPU = (() => {
  8949.  
  8950. if (isGPUAccelerationAvailable) return null;
  8951.  
  8952. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  8953. if (!pd || typeof pd.get !== 'function') return null;
  8954. const pdGet = pd.get;
  8955.  
  8956. let pr = null;
  8957.  
  8958. let hState = pdGet.call(document) === 'hidden';
  8959. // let cid = 0;
  8960. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  8961. const newHState = pdGet.call(document) === 'hidden';
  8962. if (hState !== newHState) {
  8963. // if (cid > 0) cid = clearInterval(cid);
  8964. hState = newHState;
  8965. if (!hState && pr) pr = pr.resolve();
  8966. }
  8967. });
  8968.  
  8969. // cid = setInterval(() => {
  8970. // const newHState = document.visibilityState === 'hidden';
  8971. // if (hState !== newHState) {
  8972. // hState = newHState;
  8973. // if (!hState && pr) pr = pr.resolve();
  8974. // }
  8975. // }, 100);
  8976.  
  8977.  
  8978. return (() => {
  8979. if (pr) return pr;
  8980. const w = ((!hState && setTimeout(() => {
  8981. if (!hState && pr === w) pr = pr.resolve();
  8982. })), (pr = new PromiseExternal()));
  8983. return w;
  8984. });
  8985.  
  8986. })();
  8987.  
  8988.  
  8989. let rafPromise = null;
  8990. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  8991. requestAnimationFrame(hRes => {
  8992. rafPromise = null;
  8993. resolve(hRes);
  8994. });
  8995. }));
  8996.  
  8997. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  8998.  
  8999.  
  9000. const wmComputedStyle = new WeakMap();
  9001.  
  9002. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  9003. window.__native__getComputedStyle__ = getComputedStyle;
  9004. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  9005. window.__original__getComputedStyle__ = window.getComputedStyle;
  9006. window.getComputedStyle = function (elem) {
  9007. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  9008. return window.__original__getComputedStyle__(...arguments);
  9009. }
  9010. let cs = wmComputedStyle.get(elem);
  9011. if (!cs) {
  9012. cs = window.__native__getComputedStyle__(elem);
  9013. wmComputedStyle.set(elem, cs);
  9014. }
  9015. return cs;
  9016. };
  9017. } else {
  9018. window.__original__getComputedStyle__ = null;
  9019. }
  9020. window.__jst__getComputedStyle__ = window.getComputedStyle;
  9021. }
  9022.  
  9023. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  9024. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  9025. window.getComputedStyle = window.__jst__getComputedStyle__;
  9026. }
  9027. });
  9028.  
  9029. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  9030. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  9031.  
  9032. const promiseForTamerTimeout = new Promise(resolve => {
  9033. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9034. setTimeout(resolve, 480);
  9035. }, { capture: true, passive: true, once: true });
  9036. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9037. setTimeout(resolve, 1200);
  9038. });
  9039. setTimeout(resolve, 3000);
  9040. });
  9041.  
  9042. const promiseForPageInitied = new Promise(resolve => {
  9043. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  9044. setTimeout(resolve, 450);
  9045. }, { capture: true, passive: true, once: true });
  9046. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  9047. setTimeout(resolve, 900);
  9048. });
  9049. setTimeout(resolve, 1800);
  9050. });
  9051.  
  9052. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  9053. NO_PRELOAD_GENERATE_204_BYPASS = true;
  9054. headLinkCollection = null;
  9055. });
  9056.  
  9057.  
  9058. NATIVE_CANVAS_ANIMATION && (() => {
  9059.  
  9060. observablePromise(() => {
  9061. HTMLCanvasElement.prototype.animate = animate;
  9062. }, promiseForTamerTimeout).obtain();
  9063.  
  9064. })();
  9065.  
  9066.  
  9067.  
  9068.  
  9069. FIX_ytAction_ && (async () => {
  9070.  
  9071. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  9072.  
  9073. const ytdApp = await new Promise(resolve => {
  9074.  
  9075. whenCEDefined(appTag).then(() => {
  9076. const ytdApp = document.querySelector(appTag);
  9077. if (ytdApp) {
  9078. resolve(ytdApp);
  9079. return;
  9080. }
  9081. let mo = new MutationObserver(() => {
  9082. const ytdApp = document.querySelector(appTag);
  9083. if (!ytdApp) return;
  9084. if (mo) {
  9085. mo.disconnect();
  9086. mo.takeRecords();
  9087. mo = null;
  9088. }
  9089. resolve(ytdApp);
  9090. });
  9091. mo.observe(document, { subtree: true, childList: true });
  9092. });
  9093.  
  9094. });
  9095.  
  9096. if (!ytdApp) return;
  9097. const cProto = insp(ytdApp).constructor.prototype;
  9098.  
  9099. if (!cProto) return;
  9100. let mbd = 0;
  9101.  
  9102. const fixer = (_ytdApp) => {
  9103. const ytdApp = insp(_ytdApp);
  9104. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9105. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9106. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9107. mbd++;
  9108. }
  9109. }
  9110.  
  9111. observablePromise(() => {
  9112.  
  9113. if (typeof cProto.created === 'function' && !cProto.created56) {
  9114. cProto.created56 = cProto.created;
  9115. cProto.created = function (...args) {
  9116. const r = this.created56(...args);
  9117. fixer(this);
  9118. return r;
  9119. };
  9120. mbd++;
  9121. }
  9122.  
  9123. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9124. cProto.onYtAction57_ = cProto.onYtAction_;
  9125. cProto.onYtAction_ = function (...args) {
  9126. Promise.resolve().then(() => this.onYtAction57_(...args));
  9127. };
  9128. mbd++;
  9129. }
  9130.  
  9131. if (ytdApp) fixer(ytdApp);
  9132.  
  9133. /*
  9134. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9135. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9136. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9137. actionRouter_.handleAction = function (...args) {
  9138. Promise.resolve().then(() => this.handleAction57(...args));
  9139. }
  9140. mbd++;
  9141. }
  9142. */
  9143.  
  9144. // if(mbd === 3) return 1;
  9145. if (mbd >= 3) return 1;
  9146.  
  9147. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9148.  
  9149. })();
  9150.  
  9151.  
  9152. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9153.  
  9154. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9155.  
  9156. const app = await observablePromise(() => {
  9157.  
  9158. return document.querySelector(appTag);
  9159.  
  9160. }).obtain();
  9161.  
  9162. if (!app) return;
  9163.  
  9164. const appCnt = insp(app);
  9165. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9166.  
  9167.  
  9168.  
  9169.  
  9170. });
  9171.  
  9172. const observablePromise = (proc, timeoutPromise) => {
  9173. let promise = null;
  9174. return {
  9175. obtain() {
  9176. if (!promise) {
  9177. promise = new Promise(resolve => {
  9178. let mo = null;
  9179. const f = () => {
  9180. let t = proc();
  9181. if (t) {
  9182. mo.disconnect();
  9183. mo.takeRecords();
  9184. mo = null;
  9185. resolve(t);
  9186. }
  9187. }
  9188. mo = new MutationObserver(f);
  9189. mo.observe(document, { subtree: true, childList: true })
  9190. f();
  9191. timeoutPromise && timeoutPromise.then(() => {
  9192. resolve(null)
  9193. });
  9194. });
  9195. }
  9196. return promise
  9197. }
  9198. }
  9199. }
  9200.  
  9201. // let _yt_player_promise = null;
  9202. /*
  9203. const getYtPlayerPromise = () => {
  9204. if (!_yt_player_promise) {
  9205. _yt_player_promise = new Promise(resolve => {
  9206. let cid = setInterval(() => {
  9207. let t = (((window || 0)._yt_player || 0) || 0);
  9208. if (t) {
  9209. clearInterval(cid);
  9210. resolve(t);
  9211. }
  9212. }, 1);
  9213. promiseForTamerTimeout.then(() => {
  9214. resolve(null)
  9215. });
  9216. });
  9217. }
  9218. return _yt_player_promise;
  9219. }
  9220. */
  9221. const _yt_player_observable = observablePromise(() => {
  9222. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9223. if (_yt_player) {
  9224. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9225. return _yt_player;
  9226. }
  9227. }, promiseForTamerTimeout);
  9228.  
  9229. const polymerObservable = observablePromise(() => {
  9230. const Polymer = window.Polymer;
  9231. if (typeof Polymer !== 'function') return;
  9232. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9233. return Polymer;
  9234. }, promiseForTamerTimeout);
  9235.  
  9236. const schedulerInstanceObservable = observablePromise(() => {
  9237. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9238. }, promiseForTamerTimeout);
  9239.  
  9240. const timelineObservable = observablePromise(() => {
  9241. let t = (((document || 0).timeline || 0) || 0);
  9242. if (t && typeof t._play === 'function') {
  9243. return t;
  9244. }
  9245. }, promiseForTamerTimeout);
  9246. const animationObservable = observablePromise(() => {
  9247. let t = (((window || 0).Animation || 0) || 0);
  9248. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9249. return t;
  9250. }
  9251. }, promiseForTamerTimeout);
  9252.  
  9253.  
  9254. const getScreenInfo = {
  9255. screenWidth: 0,
  9256. screenHeight: 0,
  9257. valueReady: false,
  9258. onResize: () => {
  9259. getScreenInfo.valueReady = false;
  9260. },
  9261. sizeProvided: () => {
  9262. if (getScreenInfo.valueReady) return true;
  9263. getScreenInfo.screenWidth = screen.width;
  9264. getScreenInfo.screenHeight = screen.height;
  9265. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9266. getScreenInfo.valueReady = true;
  9267. return true;
  9268. }
  9269. return false;
  9270. }
  9271. };
  9272.  
  9273. window.addEventListener('resize', getScreenInfo.onResize, true);
  9274.  
  9275.  
  9276. // const hookLeftPending = new WeakMap();
  9277.  
  9278. const isNaNx = Number.isNaN;
  9279.  
  9280. const hookLeftPD = {
  9281. get() {
  9282. const p = 'left';
  9283. // const o = hookLeftPending.get(this);
  9284. // if (o && o.key) {
  9285. // this.setProperty(p, o.value);
  9286. // o.key = null
  9287. // }
  9288. return this.getPropertyValue(p);
  9289. },
  9290. set(v) {
  9291.  
  9292. const p = 'left';
  9293. const cv = this.getPropertyValue(p);
  9294. const sv = v;
  9295.  
  9296. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  9297.  
  9298. // console.log(8380,did, cv, sv)
  9299. if (!cv && !sv) return true;
  9300. if (cv === sv) return true;
  9301.  
  9302. // skip 0~9px => L>=4
  9303.  
  9304. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  9305.  
  9306. if (!isNaNx(qsv)) {
  9307. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  9308.  
  9309. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  9310. const { screenWidth, screenHeight } = getScreenInfo;
  9311. let pWidth = screenWidth + 1024;
  9312. let pHeight = screenHeight + 768;
  9313. const minRatio = 0.003;
  9314. const dw = pWidth * 0.0003; // min dw = 0.3072
  9315. const dh = pHeight * 0.0003; // min dh = 0.2304
  9316. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  9317. if (Math.abs(qcv - qsv) < dw) return true;
  9318. }
  9319.  
  9320. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  9321. if (`${v}`.length > `${sv}`.length) v = sv;
  9322. // console.log(8382, did, sv, nv, cv, this)
  9323. }
  9324.  
  9325. // Promise.resolve().then(() => {
  9326. // const o = hookLeftPending.get(this);
  9327. // if (o && o.key === did) {
  9328. // this.setProperty(p, o.value);
  9329. // o.key = null;
  9330. // }
  9331. // });
  9332. // hookLeftPending.set(this, {
  9333. // key: did,
  9334. // value: nv
  9335. // });
  9336.  
  9337. // if (nv != v) {
  9338. // console.log(8387, v, nv);
  9339. // }
  9340.  
  9341. this.setProperty(p, v);
  9342. // console.log(8383, did, this.getPropertyValue(p))
  9343. return true;
  9344. },
  9345. enumerable: true,
  9346. configurable: true
  9347. };
  9348.  
  9349.  
  9350. if (HOOK_CSSPD_LEFT) {
  9351.  
  9352.  
  9353. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  9354.  
  9355. }
  9356.  
  9357.  
  9358.  
  9359.  
  9360.  
  9361. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  9362.  
  9363. const evKey = `${_evKey}`;
  9364. const fvKey = `${_fvKey}`;
  9365. const debug = !!_debug;
  9366.  
  9367. const _yt_player = await _yt_player_observable.obtain();
  9368.  
  9369.  
  9370. if (!_yt_player || typeof _yt_player !== 'object') return;
  9371.  
  9372.  
  9373. const getArr = (_yt_player) => {
  9374.  
  9375. let arr = [];
  9376.  
  9377. for (const [k, v] of Object.entries(_yt_player)) {
  9378.  
  9379. const p = typeof v === 'function' ? v.prototype : 0;
  9380. if (p
  9381. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  9382.  
  9383. ) {
  9384. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9385.  
  9386. }
  9387.  
  9388. }
  9389.  
  9390. if (arr.length === 0) {
  9391.  
  9392. console.warn(`Key prop [${evKey}] does not exist.`);
  9393. } else {
  9394.  
  9395. return arr;
  9396. }
  9397.  
  9398. };
  9399.  
  9400. const arr = getArr(_yt_player);
  9401.  
  9402.  
  9403. if (!arr) return;
  9404.  
  9405. debug && console.log(`FIX_${evKey}`, arr);
  9406.  
  9407. const f = function (...args) {
  9408. Promise.resolve().then(() => this[fvKey](...args));
  9409. };
  9410.  
  9411.  
  9412. for (const k of arr) {
  9413.  
  9414. const g = _yt_player;
  9415. const gk = g[k];
  9416. const gkp = gk.prototype;
  9417.  
  9418. debug && console.log(237, k, gkp)
  9419.  
  9420. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  9421. gkp[fvKey] = gkp[evKey];
  9422. gkp[evKey] = f;
  9423. }
  9424. }
  9425.  
  9426.  
  9427.  
  9428.  
  9429. }
  9430.  
  9431. if (!isChatRoomURL) {
  9432.  
  9433. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  9434. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  9435. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  9436. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  9437. if (FIX_VideoEVENTS_v2) {
  9438. const FIX_VideoEVENTS_DEBUG = 0;
  9439. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  9440. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  9441. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  9442. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  9443. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  9444. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  9445. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  9446. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  9447. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  9448.  
  9449. }
  9450. // onMutedAutoplayChange
  9451. // onVolumeChange
  9452. // onPlaybackRateChange
  9453.  
  9454. // onAirPlayActiveChange
  9455. // onAirPlayAvailabilityChange
  9456. // onApiChange
  9457. // onAutoplayBlocked
  9458. // onDrmOutputRestricted
  9459. // onFullscreenChange
  9460. // onLoadProgress
  9461. // onLoadedMetadata
  9462. // onVideoDataChange
  9463. // onVideoProgress
  9464.  
  9465. }
  9466.  
  9467.  
  9468. let isAmended_Polymer_RenderStatus = false;
  9469.  
  9470. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  9471.  
  9472. const Polymer = await polymerObservable.obtain();
  9473. if (!Polymer) return;
  9474.  
  9475. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  9476. isAmended_Polymer_RenderStatus = true;
  9477.  
  9478. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  9479. let arrBefore = null, arrAfter = null;
  9480. const push = Array.prototype.push;
  9481. let arr = null;
  9482. Array.prototype.push = function () {
  9483. arr = this;
  9484. }
  9485. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  9486. if (arr) arrBefore = arr;
  9487. arr = null;
  9488. Polymer.RenderStatus.afterNextRender({}, {}, {});
  9489. if (arr) arrAfter = arr;
  9490. arr = null;
  9491. Array.prototype.push = push;
  9492. Polymer.RenderStatus.arrBefore = arrBefore;
  9493. Polymer.RenderStatus.arrAfter = arrAfter;
  9494.  
  9495. if (arrBefore && arrAfter) {
  9496.  
  9497. Function.prototype.call7900 = Function.prototype.call;
  9498. Function.prototype.apply7900 = Function.prototype.apply;
  9499. Function.prototype.apply7948 = function (obj, args) {
  9500. const f = this;
  9501. let m = kRef(obj);
  9502. if (!m) return;
  9503. if (m.is && !m.nodeName) {
  9504. if (!m.isAttached || !m.hostElement) {
  9505. return;
  9506. }
  9507. }
  9508. try {
  9509. return !args ? f.call7900(m) : f.apply7900(m, args);
  9510. } catch (e) {
  9511. console.warn(e);
  9512. }
  9513. return null;
  9514. }
  9515.  
  9516. arrBefore.push = arrAfter.push = function (a) {
  9517. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  9518. if (a[0].deref) a[0] = kRef(a[0]);
  9519. const f = a[1]
  9520. const obj = a[0]
  9521. const args = a[2];
  9522. f.apply = f.apply7948;
  9523. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  9524. a[0] = obj[wk]
  9525. // console.log(4992, a)
  9526. return push.call(this, a);
  9527. }
  9528.  
  9529. }
  9530.  
  9531.  
  9532. }
  9533. // Polymer.RenderStatus.beforeNextRender
  9534. }
  9535.  
  9536. if (FIX_Polymer_dom) {
  9537.  
  9538. const checkPDFuncValue = (pd) => {
  9539. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  9540. }
  9541. const checkPDFuncValue2 = (pd) => {
  9542. return pd && typeof pd.value == 'function'
  9543. }
  9544.  
  9545. const checkPDFuncGet = (pd) => {
  9546. return pd && typeof pd.get == 'function'
  9547. }
  9548.  
  9549. const domX = Polymer.dom(document.createElement('null'));
  9550. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  9551. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  9552. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  9553. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  9554. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  9555. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  9556. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  9557. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  9558. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  9559.  
  9560.  
  9561. // getOwnerRoot - to be reviewed
  9562. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  9563.  
  9564. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  9565. domXP.getOwnerRoot = function () {
  9566. try {
  9567. const p = this.node;
  9568.  
  9569. if (p instanceof HTMLElement_) {
  9570. const pp = pd2.get.call(p);
  9571. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  9572. return pp.getRootNode();
  9573. }
  9574.  
  9575. }
  9576. } catch (e) { }
  9577. return this.getOwnerRoot15();
  9578. }
  9579.  
  9580. Polymer.__fixedGetOwnerRoot__ = 1;
  9581. }
  9582.  
  9583.  
  9584.  
  9585.  
  9586. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  9587.  
  9588. domXP.querySelector15 = domXP.querySelector;
  9589.  
  9590. const querySelectorFn = function (query) {
  9591. try {
  9592. const p = this.node;
  9593.  
  9594. if (p instanceof Document && p.isConnected === true) {
  9595. return pd4b.value.call(p, query);
  9596. }
  9597.  
  9598. } catch (e) { }
  9599. return this.querySelector15(query);
  9600. }
  9601.  
  9602. Object.defineProperty(domXP, 'querySelector', {
  9603. get() {
  9604. return querySelectorFn;
  9605. },
  9606. set(nv) {
  9607. if (nv === querySelectorFn) return true;
  9608. this.querySelector15 = nv;
  9609. return true;
  9610. },
  9611.  
  9612. enumerable: false,
  9613. configurable: true
  9614. });
  9615.  
  9616. Polymer.__fixedQuerySelector__ = 1;
  9617. }
  9618.  
  9619. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  9620.  
  9621. domXP.querySelectorAll15 = domXP.querySelectorAll;
  9622.  
  9623. const querySelectorAllFn = function (query) {
  9624.  
  9625. try {
  9626.  
  9627. const p = this.node;
  9628.  
  9629. if (p instanceof Document && p.isConnected === true) {
  9630. return pd6b.value.call(p, query);
  9631. }
  9632.  
  9633. } catch (e) {
  9634.  
  9635. }
  9636. return this.querySelectorAll15(query);
  9637. }
  9638.  
  9639. Object.defineProperty(domXP, 'querySelectorAll', {
  9640. get() {
  9641. return querySelectorAllFn;
  9642. },
  9643. set(nv) {
  9644. if (nv === querySelectorAllFn) return true;
  9645. this.querySelectorAll15 = nv;
  9646. return true;
  9647. },
  9648.  
  9649. enumerable: false,
  9650. configurable: true
  9651. });
  9652.  
  9653. Polymer.__fixedQuerySelectorAll__ = 1;
  9654. }
  9655. }
  9656.  
  9657.  
  9658. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  9659.  
  9660. Polymer.Base.__connInit__ = function () {
  9661. setupYtComponent(this);
  9662. }
  9663.  
  9664.  
  9665. /** @type {Function} */
  9666. const connectedCallbackK = function (...args) {
  9667. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9668. const r = this[qm53](...args);
  9669. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9670. this.mh35 = 1;
  9671. return r;
  9672. };
  9673.  
  9674. connectedCallbackK.m353 = 1;
  9675.  
  9676.  
  9677. const qt53 = Polymer.Base.connectedCallback;
  9678. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  9679.  
  9680. Polymer.Base.connectedCallback = connectedCallbackK;
  9681.  
  9682.  
  9683. /** @type {Function} */
  9684. const createdK = function (...args) {
  9685. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9686. const r = this[qn53](...args);
  9687. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9688. this.mh36 = 1;
  9689. return r;
  9690. };
  9691.  
  9692.  
  9693. createdK.m353 = 1;
  9694. Polymer.Base[qn53] = Polymer.Base.created;
  9695. Polymer.Base.created = createdK;
  9696.  
  9697.  
  9698.  
  9699.  
  9700.  
  9701.  
  9702.  
  9703.  
  9704.  
  9705.  
  9706.  
  9707. }
  9708.  
  9709. })();
  9710.  
  9711.  
  9712. /*
  9713.  
  9714. e.nativeAppendChild = d.prototype.appendChild,
  9715. d.prototype.appendChild = function(h) {
  9716. return function(l) {
  9717. if (l instanceof DocumentFragment) {
  9718. var m = Array.from(l.children);
  9719. l = h.nativeAppendChild.call(this, l);
  9720. if (this.isConnected) {
  9721. m = g(m);
  9722. for (var p = m.next(); !p.done; p = m.next())
  9723. YD(p.value)
  9724. }
  9725. return l
  9726. }
  9727. m = l instanceof Element && l.isConnected;
  9728. p = h.nativeAppendChild.call(this, l);
  9729. m && ZD(l);
  9730. this.isConnected && YD(l);
  9731. return p
  9732. }
  9733. }(e),
  9734.  
  9735. */
  9736.  
  9737. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  9738.  
  9739. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  9740. if (f) Node.prototype.appendChild = function (a) {
  9741. if (this instanceof Element) { // exclude DocumentFragment
  9742. try {
  9743. let checkFragmentA = (a instanceof DocumentFragment);
  9744. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  9745. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  9746. for (const node of headLinkCollection) {
  9747. if (node.rel === 'preload' && node.as === 'fetch') {
  9748. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  9749. }
  9750. }
  9751. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  9752. checkFragmentA = false;
  9753. }
  9754. if (checkFragmentA && a.firstElementChild === null) {
  9755. // no element in fragmentA
  9756. let doNormal = false;
  9757. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  9758. if (child.nodeType === 3) { doNormal = true; break; }
  9759. }
  9760. if (!doNormal) return a;
  9761. }
  9762. } catch (e) {
  9763. console.log(e);
  9764. }
  9765. }
  9766. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  9767. }
  9768.  
  9769. })();
  9770.  
  9771. if (FIX_Shady) {
  9772.  
  9773. observablePromise(() => {
  9774. const { ShadyDOM, ShadyCSS } = window;
  9775. if (ShadyDOM) {
  9776. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  9777. ShadyDOM.noPatch = true; // 1 of 10
  9778. ShadyDOM.patchOnDemand = false; // 1 of 10
  9779. ShadyDOM.preferPerformance = true; // 1 of 10
  9780. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  9781. }
  9782. if (ShadyCSS) {
  9783. ShadyCSS.nativeCss = true; // 1 of 10
  9784. ShadyCSS.nativeShadow = true; // 6 of 10
  9785. ShadyCSS.cssBuild = undefined; // 1 of 10
  9786. ShadyCSS.disableRuntime = true; // 1 of 10
  9787. }
  9788. if (ShadyDOM && ShadyCSS) return 1;
  9789. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  9790.  
  9791. }
  9792.  
  9793.  
  9794. // let schedulerInstancePropOfTimerType = '';
  9795. // let schedulerInstancePropOfTimerId = '';
  9796. (FIX_schedulerInstanceInstance & 2) && (async () => {
  9797.  
  9798. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  9799.  
  9800. if (!schedulerInstanceInstance_) return;
  9801.  
  9802. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  9803. if (checkOK) {
  9804.  
  9805. let resolveRendering = null;
  9806.  
  9807. let cmPr = new PromiseExternal();
  9808. const cm = document.createComment('0');
  9809. const cmObs = new MutationObserver(() => {
  9810. if (resolveRendering) {
  9811. resolveRendering();
  9812. resolveRendering = null;
  9813. }
  9814. cmPr.resolve();
  9815. cmPr = new PromiseExternal();
  9816. });
  9817. cmObs.observe(cm, {characterData: true})
  9818.  
  9819. let web_emulated_idle_callback_delay_val = null;
  9820.  
  9821. const getRenderIdleCallbackMs = () => {
  9822. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  9823. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  9824. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  9825. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  9826. return web_emulated_idle_callback_delay_val;
  9827. }
  9828. let isDelayRenderFn_firstCheck = true;
  9829. let isDelayRenderFn_key = null;
  9830. const isDelayRenderFn = (f) => {
  9831. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  9832. isDelayRenderFn_firstCheck = false;
  9833. if (typeof ytglobal === 'undefined') return false;
  9834. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  9835. if (!globalInstance) return false;
  9836. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  9837. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  9838. isDelayRenderFn_key = entry[0]
  9839. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  9840. return true;
  9841. }
  9842. }
  9843. return false;
  9844. }
  9845.  
  9846. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  9847.  
  9848. let requestingFn = null;
  9849. let requestingArgs = null;
  9850.  
  9851. const f = function () {
  9852. requestingFn = this.fn;
  9853. requestingArgs = [...arguments];
  9854. return 12373;
  9855. };
  9856.  
  9857. const fakeFns = [
  9858. f.bind({ fn: requestAnimationFrame }),
  9859. f.bind({ fn: setInterval }),
  9860. f.bind({ fn: setTimeout }),
  9861. f.bind({ fn: requestIdleCallback })
  9862. ];
  9863.  
  9864. let mzt = 0;
  9865.  
  9866. let _fnSelectorProp = null;
  9867. const mkFns = new Array(4);
  9868.  
  9869. /*
  9870. case 1:
  9871. var a = this.K;
  9872. this.g = this.I ? window.requestIdleCallback(a, {
  9873. timeout: 3E3
  9874. }) : window.setTimeout(a, ma);
  9875. break;
  9876. case 2:
  9877. this.g = window.setTimeout(this.M, this.N);
  9878. break;
  9879. case 3:
  9880. this.g = window.requestAnimationFrame(this.L);
  9881. break;
  9882. case 4:
  9883. this.g = window.setTimeout(this.J, 0)
  9884. }
  9885.  
  9886. */
  9887. const startFnHandler = {
  9888. get(target, prop, receiver) {
  9889. if (prop === '$$12377$$') return true;
  9890. if (prop === '$$12378$$') return target;
  9891.  
  9892. // console.log('get',prop)
  9893. return target[prop]
  9894. },
  9895. set(target, prop, value, receiver) {
  9896. // console.log('set', prop, value)
  9897.  
  9898.  
  9899. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  9900. if (value === 12373 && _fnSelectorProp) {
  9901.  
  9902. const schedulerTypeSelection = target[_fnSelectorProp];
  9903. const timerIdProp = prop;
  9904.  
  9905. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  9906. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  9907. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  9908. // schedulerInstancePropOfTimerId = timerIdProp || '';
  9909. // }
  9910.  
  9911. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  9912. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  9913. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  9914. // rare
  9915. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9916. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  9917. // often
  9918. if ((FIX_schedulerInstanceInstance & 4)) {
  9919. const f = requestingArgs[0];
  9920. const tir = ++mzt;
  9921. nextBrowserTick_(() => {
  9922. if (target[timerIdProp] === -tir) f();
  9923. });
  9924. target[_fnSelectorProp] = 940;
  9925. target[timerIdProp] = -tir;
  9926. } else {
  9927. const f = requestingArgs[0];
  9928. const tir = ++mzt;
  9929. Promise.resolve().then(() => {
  9930. if (target[timerIdProp] === -tir) f();
  9931. });
  9932. target[_fnSelectorProp] = 930;
  9933. target[timerIdProp] = -tir;
  9934. }
  9935. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  9936. // often
  9937. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  9938. cm.data = (cm.data & 7) + 1;
  9939. let renderFn = requestingArgs[0];
  9940. const resolveRendering_ = () => {
  9941. const renderFn_ = renderFn;
  9942. if (renderFn_) {
  9943. renderFn = null;
  9944. renderFn_();
  9945. }
  9946. };
  9947. resolveRendering = resolveRendering_;
  9948. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  9949. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  9950.  
  9951. // cm.data = (cm.data & 7) + 1;
  9952. // target[timerIdProp] = Math.random();
  9953.  
  9954. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  9955.  
  9956. cm.data = (cm.data & 7) + 1;
  9957.  
  9958. let renderFn = requestingArgs[0];
  9959. const resolveRendering_ = () => {
  9960. const renderFn_ = renderFn;
  9961. if (renderFn_) {
  9962. renderFn = null;
  9963. renderFn_();
  9964. }
  9965. };
  9966. resolveRendering = resolveRendering_;
  9967.  
  9968. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  9969.  
  9970.  
  9971. } else {
  9972. if (requestingFn === requestIdleCallback) {
  9973. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  9974. } else {
  9975. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9976. }
  9977. }
  9978. } else {
  9979. target[_fnSelectorProp] = 0;
  9980. target[timerIdProp] = 0;
  9981. }
  9982. } else {
  9983. target[prop] = value;
  9984. }
  9985. return true;
  9986. }
  9987. };
  9988.  
  9989. let startBusy = false;
  9990. schedulerInstanceInstance_.start = function () {
  9991. if (startBusy) return;
  9992. startBusy = true;
  9993. try {
  9994. mkFns[0] = window.requestAnimationFrame;
  9995. mkFns[1] = window.setInterval;
  9996. mkFns[2] = window.setTimeout;
  9997. mkFns[3] = window.requestIdleCallback;
  9998. const tThis = this['$$12378$$'] || this;
  9999. window.requestAnimationFrame = fakeFns[0]
  10000. window.setInterval = fakeFns[1]
  10001. window.setTimeout = fakeFns[2]
  10002. window.requestIdleCallback = fakeFns[3]
  10003. _fnSelectorProp = null;
  10004. tThis.start993.call(new Proxy(tThis, startFnHandler));
  10005. _fnSelectorProp = null;
  10006. window.requestAnimationFrame = mkFns[0];
  10007. window.setInterval = mkFns[1];
  10008. window.setTimeout = mkFns[2];
  10009. window.requestIdleCallback = mkFns[3];
  10010. } catch (e) {
  10011. console.warn(e);
  10012. }
  10013. startBusy = false;
  10014. }
  10015.  
  10016. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  10017.  
  10018. }
  10019. })();
  10020.  
  10021. FIX_yt_player && !isChatRoomURL && (async () => {
  10022.  
  10023. const fOption = 1 | 2 | 4;
  10024.  
  10025. const _yt_player = await _yt_player_observable.obtain();
  10026.  
  10027. if (!_yt_player || typeof _yt_player !== 'object') return;
  10028.  
  10029. const g = _yt_player;
  10030. let k;
  10031.  
  10032. if (fOption & 1) {
  10033.  
  10034. // rAf scheduling
  10035.  
  10036. const keyZqOu = getZqOu(_yt_player);
  10037. if (!keyZqOu) {
  10038. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  10039. return;
  10040. }
  10041. k = keyZqOu
  10042.  
  10043. const gk = g[k];
  10044. if (typeof gk !== 'function') {
  10045. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  10046. return;
  10047. }
  10048. const gkp = gk.prototype;
  10049.  
  10050. const dummyObject = new gk;
  10051. const nilFunc = () => { };
  10052.  
  10053. const nilObj = {};
  10054.  
  10055. // console.log(1111111111)
  10056.  
  10057. let keyBoolD = '';
  10058. let keyWindow = '';
  10059. let keyFuncC = '';
  10060. let keyCidj = '';
  10061.  
  10062. for (const [t, y] of Object.entries(dummyObject)) {
  10063. if (y instanceof Window) keyWindow = t;
  10064. }
  10065.  
  10066. const dummyObjectProxyHandler = {
  10067. get(target, prop) {
  10068. let v = target[prop]
  10069. if (v instanceof Window && !keyWindow) {
  10070. keyWindow = t;
  10071. }
  10072. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  10073. if (prop === keyWindow) y = {
  10074. requestAnimationFrame(f) {
  10075. return 3;
  10076. },
  10077. cancelAnimationFrame() {
  10078.  
  10079. }
  10080. }
  10081. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  10082. keyFuncC = prop;
  10083. }
  10084. // console.log('[get]', prop, typeof target[prop])
  10085.  
  10086.  
  10087. return y;
  10088. },
  10089. set(target, prop, value) {
  10090.  
  10091. if (typeof value === 'boolean' && !keyBoolD) {
  10092. keyBoolD = prop;
  10093. }
  10094. if (typeof value === 'number' && !keyCidj && value >= 2) {
  10095. keyCidj = prop;
  10096. }
  10097.  
  10098. // console.log('[set]', prop, value)
  10099. target[prop] = value;
  10100.  
  10101. return true;
  10102. }
  10103. };
  10104.  
  10105. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  10106.  
  10107. // console.log('gkp.start',gkp.start);
  10108. // console.log('gkp.stop',gkp.stop);
  10109. gkp._activation = false;
  10110.  
  10111. gkp.start = function () {
  10112. // p59 || console.log(12100)
  10113. if (!this._activation) {
  10114. this._activation = true;
  10115. foregroundPromiseFn().then(() => {
  10116. this._activation = false;
  10117. if (this[keyCidj]) {
  10118. Promise.resolve().then(this[keyFuncC]);
  10119. }
  10120. });
  10121. }
  10122. this[keyCidj] = 1;
  10123. this[keyBoolD] = true;
  10124. };
  10125.  
  10126. gkp.stop = function () {
  10127. this[keyCidj] = null;
  10128. };
  10129.  
  10130.  
  10131. /*
  10132. g[k].start = function() {
  10133. this.stop();
  10134. this.D = true;
  10135. var a = requestAnimationFrame
  10136. , b = cancelAnimationFrame;
  10137. this.j = a.call(this.B, this.C)
  10138. }
  10139. ;
  10140. g[k].stop = function() {
  10141. if (this.isActive()) {
  10142. var a = requestAnimationFrame
  10143. , b = cancelAnimationFrame;
  10144. b.call(this.B, this.j)
  10145. }
  10146. this.j = null
  10147. }
  10148. */
  10149. }
  10150.  
  10151. if (fOption & 2) {
  10152. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10153.  
  10154. if (keyzo) {
  10155.  
  10156. k = keyzo;
  10157.  
  10158. const attrUpdateFn = g[k];
  10159. // console.log(5992, attrUpdateFn)
  10160. g['$$original$$' + k] = attrUpdateFn;
  10161. const zoTransform = async (a, c) => {
  10162.  
  10163. let transformType = '';
  10164. let transformValue = 0;
  10165. let transformUnit = '';
  10166. let transformTypeI = 0;
  10167.  
  10168. const aStyle = a.style;
  10169.  
  10170. let cType = 0;
  10171.  
  10172. const cl = c.length;
  10173.  
  10174. if (cl >= 8) {
  10175. // scale(1)
  10176. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10177. cType = 1;
  10178. let t = c.charCodeAt(5);
  10179. if (t === 88 || t === 120) cType = 1 | 4;
  10180. if (t === 89 || t === 121) cType = 1 | 8;
  10181. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10182. cType = 2;
  10183. let t = c.charCodeAt(9);
  10184. if (t === 88 || t === 120) cType = 2 | 4;
  10185. if (t === 89 || t === 121) cType = 2 | 8;
  10186. }
  10187. let w = 0;
  10188. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10189. let p = c.substring(7, cl - 1);
  10190. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10191. if (typeof q === 'number' && !isNaNx(q)) {
  10192. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10193. transformValue = q;
  10194. transformUnit = '';
  10195. transformTypeI = 1;
  10196. } else {
  10197. cType = 256;
  10198. }
  10199. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10200. if (c.endsWith('px)')) {
  10201. let p = c.substring(11, cl - 3);
  10202. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10203. if (typeof q === 'number' && !isNaNx(q)) {
  10204. transformType = w === 1 ? 'translateX' : 'translateY';
  10205. transformValue = q;
  10206. transformUnit = 'px';
  10207. transformTypeI = 2;
  10208. } else if (p === 'NaN') {
  10209. return;
  10210. }
  10211. } else {
  10212. cType = 256;
  10213. }
  10214. } else if (cType > 0) {
  10215. cType = 256;
  10216. }
  10217. }
  10218.  
  10219.  
  10220. if (cType === 256) {
  10221. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10222. }
  10223.  
  10224. if (transformTypeI === 1) {
  10225. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10226. const vz = toFixed2(q, 3);
  10227. c = `${transformType}(${vz})`;
  10228. const cv = aStyle.transform;
  10229. if (c === cv) return;
  10230. aStyle.transform = c;
  10231. } else if (transformTypeI === 2) {
  10232. const q = transformValue;
  10233. const vz = toFixed2(q, 1);
  10234. c = `${transformType}(${vz}${transformUnit})`;
  10235. const cv = aStyle.transform;
  10236. if (c === cv) return;
  10237. aStyle.transform = c;
  10238. } else { // eg empty
  10239. const cv = aStyle.transform;
  10240. if (!c && !cv) return;
  10241. else if (c === cv) return;
  10242. aStyle.transform = c;
  10243. }
  10244.  
  10245. };
  10246.  
  10247. const elmTransformTemp = new WeakMap();
  10248. const elmPropTemps = {
  10249. 'display': new WeakMap(),
  10250. 'width': new WeakMap(),
  10251. 'height': new WeakMap(),
  10252. 'outlineWidth': new WeakMap(),
  10253. 'position': new WeakMap(),
  10254. 'padding': new WeakMap(),
  10255. "cssText": new WeakMap(),
  10256. "right": new WeakMap(),
  10257. "left": new WeakMap(),
  10258. "top": new WeakMap(),
  10259. "bottom": new WeakMap(),
  10260. "transitionDelay": new WeakMap(),
  10261. "marginLeft": new WeakMap(),
  10262. "marginTop": new WeakMap(),
  10263. "marginRight": new WeakMap(),
  10264. "marginBottom": new WeakMap(),
  10265. }
  10266.  
  10267. const ns5 = Symbol();
  10268. const nextModify = (a, c, m, f, immediate) => {
  10269. const a_ = a;
  10270. const m_ = m;
  10271. const noKey = !m_.has(a_);
  10272. if (immediate || noKey) {
  10273. m_.set(a_, ns5);
  10274. f(a_, c);
  10275. noKey && nextBrowserTick_(() => {
  10276. const d = m_.get(a_);
  10277. if (d === undefined) return;
  10278. m_.delete(a_);
  10279. if (d !== ns5) f(a_, d);
  10280. });
  10281. } else {
  10282. m_.set(a_, c);
  10283. }
  10284. };
  10285.  
  10286. const set66 = new Set();
  10287. const log77 = new Map();
  10288. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10289.  
  10290. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10291.  
  10292. // console.log(140000, a, b, c);
  10293. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10294. const num = c;
  10295. c = `${num}`;
  10296. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10297. }
  10298.  
  10299. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10300.  
  10301. let elmPropTemp = null;
  10302.  
  10303. if (b === "transform") {
  10304. // div.ytp-hover-progress.ytp-hover-progress-light
  10305. // div.ytp-play-progress.ytp-swatch-background-color
  10306.  
  10307. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10308. return;
  10309.  
  10310. } else if (elmPropTemp = elmPropTemps[b]) {
  10311.  
  10312. // if (c.length > 5 && c.includes('.')) {
  10313. // console.log(123213, c)
  10314. // }
  10315.  
  10316. const b_ = b;
  10317. nextModify(a, c, elmPropTemp, (a, c) => {
  10318. const style = a.style;
  10319. const cv = style[b_];
  10320. if (!cv && !c) return;
  10321. if (cv === c) return;
  10322. style[b_] = c;
  10323. }, immediateChange);
  10324. return;
  10325.  
  10326. } else if (b === "outline-width") {
  10327.  
  10328. const b_ = 'outlineWidth';
  10329. elmPropTemp = elmPropTemps[b_];
  10330. nextModify(a, c, elmPropTemp, (a, c) => {
  10331. const style = a.style;
  10332. const cv = style[b_];
  10333. if (!cv && !c) return;
  10334. if (cv === c) return;
  10335. style[b_] = c;
  10336. }, immediateChange);
  10337. return;
  10338.  
  10339. } else if (b === 'maxWidth' || b === 'maxHeight') {
  10340. // I think these can be directly assigned.
  10341.  
  10342. const b_ = b;
  10343. const style = a.style;
  10344. const cv = style[b_];
  10345. if (!cv && !c) return;
  10346. if (cv === c) return;
  10347. style[b_] = c;
  10348. return;
  10349.  
  10350. } else {
  10351. // if(immediate && elmPropTemps[b]){
  10352. // console.log(5191, b)
  10353. // }
  10354. // caption-window
  10355. // margin-left max-height max-width font-family fill color font-size background white-space margin
  10356. // text-align background-color
  10357. // console.log(27304, a, b, c)
  10358. if (!set66.has(b)) {
  10359. set66.add(b);
  10360. nextBrowserTick_(() => {
  10361. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  10362. console.log(27304, a, b, c)
  10363. }
  10364. })
  10365. }
  10366. }
  10367.  
  10368. attrUpdateFn.call(this, a, b, c);
  10369. return;
  10370. } else if (typeof (b || 0) === 'object') {
  10371.  
  10372. // this is to fix caption positioning
  10373. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  10374. const immediate = (a.id || 0).length > 14;
  10375. for (const [k, v] of Object.entries(b)) {
  10376. modifiedFn.call(this, a, k, v, immediate);
  10377. }
  10378.  
  10379. } else {
  10380.  
  10381. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  10382. // ytp-ad-timed-pie-countdown-inner
  10383.  
  10384. if (typeof b === 'string') {
  10385.  
  10386. let m = log77.get(b);
  10387. if (!m) {
  10388. m = [];
  10389. console.log('attrUpdateFn.debug.27304', m);
  10390. log77.set(b, m);
  10391. }
  10392. m.push([a, b, c]);
  10393.  
  10394. } else {
  10395. console.log('attrUpdateFn.debug.27306', a, b, c);
  10396. }
  10397.  
  10398. attrUpdateFn.call(this, a, b, c);
  10399. return;
  10400. }
  10401.  
  10402. // console.log(130000, a, b, c);
  10403.  
  10404. };
  10405. g[k] = modifiedFn;
  10406.  
  10407.  
  10408. /*
  10409.  
  10410. g.zo = function(a, b, c) {
  10411. if ("string" === typeof b)
  10412. (b = yo(a, b)) && (a.style[b] = c);
  10413. else
  10414. for (var d in b) {
  10415. c = a;
  10416. var e = b[d]
  10417. , f = yo(c, d);
  10418. f && (c.style[f] = e)
  10419. }
  10420. }
  10421.  
  10422.  
  10423. */
  10424.  
  10425.  
  10426. }
  10427. }
  10428.  
  10429. if (fOption & 4) {
  10430. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  10431.  
  10432. if (keyuG) {
  10433.  
  10434. k = keyuG;
  10435.  
  10436. const gk = g[k];
  10437. const gkp = gk.prototype;
  10438.  
  10439.  
  10440. /** @type { Map<string, WeakMap<any, any>> } */
  10441. const ntLogs = new Map();
  10442.  
  10443. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  10444.  
  10445. gkp.updateValue31 = gkp.updateValue;
  10446. gkp.updateValue = function (a, b) {
  10447. if (typeof a !== 'string') return this.updateValue31(a, b);
  10448.  
  10449. const element = this.element;
  10450. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  10451.  
  10452. let ntLog = ntLogs.get(a);
  10453. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  10454.  
  10455. let cache = ntLog.get(element);
  10456. if (cache && cache.value === b) {
  10457. return;
  10458. }
  10459. if (!cache) {
  10460. this.__oldValueByUpdateValue__ = null;
  10461. ntLog.set(element, cache = { value: b });
  10462. } else {
  10463. this.__oldValueByUpdateValue__ = cache.value;
  10464. cache.value = b;
  10465. }
  10466.  
  10467. return this.updateValue31(a, b);
  10468. }
  10469.  
  10470. /*
  10471. g.k.update = function(a) {
  10472. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  10473. c = c.value,
  10474. this.updateValue(c, a[c])
  10475. }
  10476. ;
  10477. g.k.updateValue = function(a, b) {
  10478. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  10479. }
  10480. */
  10481.  
  10482. }
  10483.  
  10484.  
  10485. }
  10486. }
  10487.  
  10488.  
  10489.  
  10490. })();
  10491.  
  10492.  
  10493. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  10494. // keyboard shortcut keys controller
  10495.  
  10496. const _yt_player = await _yt_player_observable.obtain();
  10497.  
  10498. if (!_yt_player || typeof _yt_player !== 'object') return;
  10499.  
  10500. keyboardController(_yt_player);
  10501.  
  10502. })();
  10503.  
  10504. FIX_yt_player && !isChatRoomURL && (async () => {
  10505. // timer scheduling
  10506.  
  10507. const _yt_player = await _yt_player_observable.obtain();
  10508.  
  10509. if (!_yt_player || typeof _yt_player !== 'object') return;
  10510.  
  10511. let keyZqQu = getZqQu(_yt_player);
  10512.  
  10513. if (!keyZqQu) return;
  10514.  
  10515. const g = _yt_player
  10516. let k = keyZqQu
  10517.  
  10518. const gk = g[k];
  10519. if (typeof gk !== 'function') return;
  10520. const gkp = gk.prototype;
  10521.  
  10522. const extractKeysZqQu = () => {
  10523.  
  10524.  
  10525. let _keyeC = '';
  10526. try {
  10527. gkp.stop.call(new Proxy({
  10528. isActive: () => { }
  10529. }, {
  10530. set(target, prop, value) {
  10531. if (value === 0) _keyeC = prop;
  10532. return true;
  10533. }
  10534. }));
  10535. } catch (e) { }
  10536. if (!_keyeC) return;
  10537. const keyeC = _keyeC;
  10538.  
  10539. let keyC = ''; // this.C = this.ST.bind(this)
  10540. let keyhj = ''; // 1000ms
  10541. try {
  10542. gkp.start.call(new Proxy({
  10543. stop: () => { },
  10544. [keyeC]: 0,
  10545. }, {
  10546. get(target, prop) {
  10547. if (prop in target) return target[prop];
  10548. if (!keyC) {
  10549. keyC = prop;
  10550. return null; // throw error
  10551. }
  10552. else if (!keyhj) {
  10553. keyhj = prop;
  10554. }
  10555.  
  10556. }
  10557. }));
  10558. } catch (e) {
  10559. if (!keyC || !keyhj) {
  10560. console.log(e)
  10561. }
  10562. }
  10563.  
  10564. if (!keyC || !keyhj) return;
  10565. let keyST = '';
  10566. let keyj = '';
  10567. let keyB = '';
  10568. let keyxa = '';
  10569.  
  10570. const possibleKs = new Set();
  10571.  
  10572. for (const [k, v] of Object.entries(gkp)) {
  10573. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  10574. continue;
  10575. }
  10576. if (typeof v === 'function') {
  10577. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  10578. if (m) {
  10579. keyST = k;
  10580. keyj = m[1];
  10581. keyB = m[2];
  10582. } else {
  10583. possibleKs.add(k);
  10584. }
  10585. }
  10586. }
  10587.  
  10588. if (!keyST || !keyj || !keyB) return;
  10589.  
  10590. for (const k of possibleKs) {
  10591. if (k === keyST || k === keyj || k === keyB) {
  10592. continue;
  10593. }
  10594. const v = gkp[k];
  10595. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  10596. keyxa = k;
  10597. }
  10598. }
  10599.  
  10600. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  10601.  
  10602. }
  10603.  
  10604. const keys = extractKeysZqQu();
  10605. if (!keys || !keys.length) return;
  10606. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  10607.  
  10608. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  10609.  
  10610. let disposeKeys = null;
  10611.  
  10612. gkp[keyxa] = function () {
  10613. // dispose
  10614. if (!disposeKeys) {
  10615. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  10616. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  10617. const t = typeof this[key];
  10618. return t === 'undefined' || t === 'object'
  10619. }
  10620. return false;
  10621. });
  10622. }
  10623. for (const key of disposeKeys) {
  10624. const v = this[key];
  10625. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  10626. }
  10627. if (this[keyeC] > 0) this.stop();
  10628. this[keyj] = null;
  10629. this[keyB] = null;
  10630. };
  10631.  
  10632. gkp.start = function (a) {
  10633. if (this[keyeC] > 0) this.stop();
  10634. const delay = void 0 !== a ? a : this[keyhj];
  10635. this[keyeC] = window.setTimeout(this[keyC], delay);
  10636. };
  10637. gkp.stop = function () {
  10638. if (this[keyeC] > 0) {
  10639. window.clearTimeout(this[keyeC]);
  10640. this[keyeC] = 0;
  10641. }
  10642. };
  10643.  
  10644. gkp.isActive = function () {
  10645. return this[keyeC] > 0;
  10646. };
  10647.  
  10648. gkp[keyST] = function () {
  10649. this.stop(); // this[keyeC] = 0;
  10650. const fn = this[keyj];
  10651. const obj = this[keyB];
  10652. let skip = false;
  10653. if (!fn) skip = true;
  10654. else if (IGNORE_bufferhealth_CHECK && obj) {
  10655. let m;
  10656. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  10657. if (m.has("bufferhealth")) skip = true;
  10658. }
  10659. }
  10660. if (!skip) {
  10661. fn.call(obj);
  10662. }
  10663. };
  10664.  
  10665.  
  10666.  
  10667.  
  10668. /*
  10669.  
  10670. g.k.eC = 0;
  10671. g.k.xa = function() {
  10672. g.Qu.Vf.xa.call(this);
  10673. this.stop();
  10674. delete this.j;
  10675. delete this.B
  10676. }
  10677. ;
  10678. g.k.start = function(a) {
  10679. this.stop();
  10680. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  10681. }
  10682. ;
  10683. g.k.stop = function() {
  10684. this.isActive() && g.Sa.clearTimeout(this.eC);
  10685. this.eC = 0
  10686. }
  10687. ;
  10688. g.k.isActive = function() {
  10689. return 0 != this.eC
  10690. }
  10691. ;
  10692. g.k.ST = function() {
  10693. this.eC = 0;
  10694. this.j && this.j.call(this.B)
  10695. }
  10696. ;
  10697. */
  10698.  
  10699.  
  10700.  
  10701.  
  10702. })();
  10703.  
  10704. FIX_Animation_n_timeline && (async () => {
  10705.  
  10706. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  10707.  
  10708. if (!timeline || !Animation) return;
  10709.  
  10710. const animationsFix = (timeline) => {
  10711. const animations = (timeline || 0)._animations || 0;
  10712. const c = animations[0];
  10713. if (c) {
  10714. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  10715. animations.shift(); // keep animating but no looping
  10716. // c.effect.remove();
  10717. }
  10718. }
  10719. }
  10720.  
  10721. const aniProto = Animation.prototype;
  10722. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  10723.  
  10724. const getXroto = (x) => {
  10725. try {
  10726. return x.__proto__;
  10727. } catch (e) { }
  10728. return null;
  10729. }
  10730. const timProto = getXroto(timeline);
  10731. if (!timProto) return;
  10732. if (
  10733. (
  10734. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  10735. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  10736. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  10737. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  10738. )
  10739.  
  10740. ) {
  10741.  
  10742. timProto.nofCQ = 1;
  10743. aniProto.nofYH = 1;
  10744.  
  10745. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  10746.  
  10747.  
  10748. /*
  10749. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10750. return c._updatePromises();
  10751. });
  10752. */
  10753.  
  10754. const p = Array.prototype.filter;
  10755.  
  10756. let res = null;
  10757. Array.prototype.filter = function () {
  10758.  
  10759. res = this;
  10760. return this;
  10761.  
  10762. };
  10763.  
  10764. _updateAnimationsPromises.call({});
  10765.  
  10766. Array.prototype.filter = p;
  10767.  
  10768. if (res && typeof res.length === 'number') {
  10769. /** @type {any[]} */
  10770. const _res = res;
  10771. return _res;
  10772. }
  10773.  
  10774.  
  10775. return null;
  10776.  
  10777.  
  10778.  
  10779.  
  10780. })(timProto._updateAnimationsPromises);
  10781.  
  10782. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  10783.  
  10784. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  10785.  
  10786. aniProto._updatePromises31 = aniProto._updatePromises;
  10787.  
  10788. /*
  10789. aniProto._updatePromises = function(){
  10790. console.log('eff',this._oldPlayState, this.playState)
  10791. return this._updatePromises31.apply(this, arguments)
  10792. }
  10793. */
  10794.  
  10795. aniProto._updatePromises = function () {
  10796. var oldPlayState = this._oldPlayState;
  10797. var newPlayState = this.playState;
  10798. // console.log('ett', oldPlayState, newPlayState)
  10799. if (newPlayState !== oldPlayState) {
  10800. this._oldPlayState = newPlayState;
  10801. if (this._readyPromise) {
  10802. if ("idle" == newPlayState) {
  10803. this._rejectReadyPromise();
  10804. this._readyPromise = void 0;
  10805. } else if ("pending" == oldPlayState) {
  10806. this._resolveReadyPromise();
  10807. } else if ("pending" == newPlayState) {
  10808. this._readyPromise = void 0;
  10809. }
  10810. }
  10811. if (this._finishedPromise) {
  10812. if ("idle" == newPlayState) {
  10813. this._rejectFinishedPromise();
  10814. this._finishedPromise = void 0;
  10815. } else if ("finished" == newPlayState) {
  10816. this._resolveFinishedPromise();
  10817. } else if ("finished" == oldPlayState) {
  10818. this._finishedPromise = void 0;
  10819. }
  10820. }
  10821. }
  10822. return this._readyPromise || this._finishedPromise;
  10823. };
  10824.  
  10825.  
  10826. let restartWebAnimationsNextTickFlag = false;
  10827.  
  10828. const looperMethodT = () => {
  10829.  
  10830. const runnerFn = (hRes) => {
  10831. var b = timeline;
  10832. b.currentTime = hRes;
  10833. b._discardAnimations();
  10834. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  10835. if (0 == b._animations.length) {
  10836. restartWebAnimationsNextTickFlag = false;
  10837. } else {
  10838. getRafPromise().then(runnerFn);
  10839. }
  10840. }
  10841.  
  10842. const restartWebAnimationsNextTick = () => {
  10843. if (!restartWebAnimationsNextTickFlag) {
  10844. restartWebAnimationsNextTickFlag = true;
  10845. getRafPromise().then(runnerFn);
  10846. }
  10847. }
  10848.  
  10849. return { restartWebAnimationsNextTick }
  10850. };
  10851.  
  10852.  
  10853. const looperMethodN = () => {
  10854.  
  10855. const acs = document.createElement('a-f');
  10856. acs.id = 'a-f';
  10857.  
  10858. if (!document.getElementById('afscript')) {
  10859. const style = document.createElement('style');
  10860. style.id = 'afscript';
  10861. style.textContent = `
  10862. @keyFrames aF1 {
  10863. 0% {
  10864. order: 0;
  10865. }
  10866. 100% {
  10867. order: 1;
  10868. }
  10869. }
  10870. #a-f[id] {
  10871. visibility: collapse !important;
  10872. position: fixed !important;
  10873. display: block !important;
  10874. top: -100px !important;
  10875. left: -100px !important;
  10876. margin:0 !important;
  10877. padding:0 !important;
  10878. outline:0 !important;
  10879. border:0 !important;
  10880. z-index:-1 !important;
  10881. width: 0px !important;
  10882. height: 0px !important;
  10883. contain: strict !important;
  10884. pointer-events: none !important;
  10885. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  10886. }
  10887. `;
  10888. (document.head || document.documentElement).appendChild(style);
  10889. }
  10890.  
  10891. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  10892.  
  10893. const _onanimationiteration = function (evt) {
  10894. const hRes = evt.timeStamp;
  10895. var b = timeline;
  10896. b.currentTime = hRes;
  10897. b._discardAnimations();
  10898. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  10899. if (0 == b._animations.length) {
  10900. restartWebAnimationsNextTickFlag = false;
  10901. acs.onanimationiteration = null;
  10902. } else {
  10903. acs.onanimationiteration = _onanimationiteration;
  10904. }
  10905.  
  10906. }
  10907.  
  10908.  
  10909.  
  10910. const restartWebAnimationsNextTick = () => {
  10911. if (!restartWebAnimationsNextTickFlag) {
  10912. restartWebAnimationsNextTickFlag = true;
  10913. acs.onanimationiteration = _onanimationiteration;
  10914.  
  10915. }
  10916. }
  10917.  
  10918. return { restartWebAnimationsNextTick }
  10919. };
  10920.  
  10921.  
  10922.  
  10923. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  10924.  
  10925.  
  10926. // console.log(571, timProto);
  10927. timProto._play = function (c) {
  10928. c = new Animation(c, this);
  10929. this._animations.push(c);
  10930. restartWebAnimationsNextTick();
  10931. c._updatePromises();
  10932. c._animation.play();
  10933. c._updatePromises();
  10934. return c
  10935. }
  10936.  
  10937. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  10938. originalAnimationsWithPromises.length = 0;
  10939. originalAnimationsWithPromises.push = null;
  10940. originalAnimationsWithPromises.splice = null;
  10941. originalAnimationsWithPromises.slice = null;
  10942. originalAnimationsWithPromises.indexOf = null;
  10943. originalAnimationsWithPromises.unshift = null;
  10944. originalAnimationsWithPromises.shift = null;
  10945. originalAnimationsWithPromises.pop = null;
  10946. originalAnimationsWithPromises.filter = null;
  10947. originalAnimationsWithPromises.forEach = null;
  10948. originalAnimationsWithPromises.map = null;
  10949.  
  10950.  
  10951. const _updateAnimationsPromises = () => {
  10952. animationsWithPromisesMap.forEach(c => {
  10953. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  10954. });
  10955. /*
  10956. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10957. return c._updatePromises();
  10958. });
  10959. */
  10960. }
  10961.  
  10962. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  10963.  
  10964. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  10965.  
  10966. delete timProto._updateAnimationsPromises;
  10967. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  10968. get() {
  10969. if (animationsWithPromisesMap.size === 0) return nilFn;
  10970. return _updateAnimationsPromises;
  10971. },
  10972. set(nv) {
  10973. delete this._updateAnimationsPromises;
  10974. this._updateAnimationsPromises = nv;
  10975. },
  10976. enumerable: true,
  10977. configurable: true,
  10978. });
  10979.  
  10980.  
  10981. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  10982. aniProto.__finished_native_get__ = pdFinished.get;
  10983. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  10984.  
  10985.  
  10986. Object.defineProperty(aniProto, 'finished', {
  10987. get() {
  10988. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10989. this._finishedPromise = new Promise((resolve, reject) => {
  10990. this._resolveFinishedPromise = function () {
  10991. resolve(this)
  10992. };
  10993. this._rejectFinishedPromise = function () {
  10994. reject({
  10995. type: DOMException.ABORT_ERR,
  10996. name: "AbortError"
  10997. })
  10998. };
  10999. }),
  11000. "finished" == this.playState && this._resolveFinishedPromise());
  11001. return this._finishedPromise
  11002. },
  11003. set: undefined,
  11004. enumerable: true,
  11005. configurable: true
  11006. });
  11007.  
  11008. }
  11009.  
  11010.  
  11011.  
  11012. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  11013. aniProto.__ready_native_get__ = pdReady.get;
  11014. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  11015.  
  11016. Object.defineProperty(aniProto, 'ready', {
  11017. get() {
  11018. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  11019. this._readyPromise = new Promise((resolve, reject) => {
  11020. this._resolveReadyPromise = function () {
  11021. resolve(this)
  11022. };
  11023. this._rejectReadyPromise = function () {
  11024. reject({
  11025. type: DOMException.ABORT_ERR,
  11026. name: "AbortError"
  11027. })
  11028. };
  11029. }),
  11030. "pending" !== this.playState && this._resolveReadyPromise());
  11031. return this._readyPromise
  11032. },
  11033. set: undefined,
  11034. enumerable: true,
  11035. configurable: true
  11036. });
  11037.  
  11038. }
  11039.  
  11040.  
  11041. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  11042.  
  11043. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  11044. const _rebuildUnderlyingAnimation = function () {
  11045. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  11046. this.effect && this.effect._onsample && (this.effect._onsample = null);
  11047. return this._rebuildUnderlyingAnimation21();
  11048. }
  11049. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  11050. // delete aniProto._rebuildUnderlyingAnimation;
  11051. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  11052. // get() {
  11053. // if (isNaN(this._sequenceNumber)) return nilFn;
  11054. // return this._rebuildUnderlyingAnimation21;
  11055. // },
  11056. // set(nv) {
  11057. // delete this._rebuildUnderlyingAnimation;
  11058. // this._rebuildUnderlyingAnimation = nv;
  11059. // },
  11060. // enumerable: true,
  11061. // configurable: true
  11062. // });
  11063. }
  11064.  
  11065.  
  11066. /*
  11067.  
  11068.  
  11069. function f(c) {
  11070. var b = v.timeline;
  11071. b.currentTime = c;
  11072. b._discardAnimations();
  11073. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  11074. }
  11075. var h = window.requestAnimationFrame;
  11076. window.requestAnimationFrame = function(c) {
  11077. return h(function(b) {
  11078. v.timeline._updateAnimationsPromises();
  11079. c(b);
  11080. v.timeline._updateAnimationsPromises()
  11081. })
  11082. }
  11083. ;
  11084. v.AnimationTimeline = function() {
  11085. this._animations = [];
  11086. this.currentTime = void 0
  11087. }
  11088. ;
  11089. v.AnimationTimeline.prototype = {
  11090. getAnimations: function() {
  11091. this._discardAnimations();
  11092. return this._animations.slice()
  11093. },
  11094. _updateAnimationsPromises: function() {
  11095. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  11096. return c._updatePromises()
  11097. })
  11098. },
  11099. _discardAnimations: function() {
  11100. this._updateAnimationsPromises();
  11101. this._animations = this._animations.filter(function(c) {
  11102. return "finished" != c.playState && "idle" != c.playState
  11103. })
  11104. },
  11105. _play: function(c) {
  11106. c = new v.Animation(c,this);
  11107. this._animations.push(c);
  11108. v.restartWebAnimationsNextTick();
  11109. c._updatePromises();
  11110. c._animation.play();
  11111. c._updatePromises();
  11112. return c
  11113. },
  11114. play: function(c) {
  11115. c && c.remove();
  11116. return this._play(c)
  11117. }
  11118. };
  11119. var d = !1;
  11120. v.restartWebAnimationsNextTick = function() {
  11121. d || (d = !0,
  11122. requestAnimationFrame(f))
  11123. }
  11124. ;
  11125. var a = new v.AnimationTimeline;
  11126. v.timeline = a;
  11127. try {
  11128. Object.defineProperty(window.document, "timeline", {
  11129. configurable: !0,
  11130. get: function() {
  11131. return a
  11132. }
  11133. })
  11134. } catch (c) {}
  11135. try {
  11136. window.document.timeline = a
  11137. } catch (c) {}
  11138.  
  11139. */
  11140.  
  11141.  
  11142.  
  11143. /*
  11144.  
  11145. var g = window.getComputedStyle;
  11146. Object.defineProperty(window, "getComputedStyle", {
  11147. configurable: !0,
  11148. enumerable: !0,
  11149. value: function() {
  11150. v.timeline._updateAnimationsPromises();
  11151. var e = g.apply(this, arguments);
  11152. h() && (e = g.apply(this, arguments));
  11153. v.timeline._updateAnimationsPromises();
  11154. return e
  11155. }
  11156. });
  11157.  
  11158. */
  11159.  
  11160.  
  11161.  
  11162.  
  11163. }
  11164.  
  11165.  
  11166.  
  11167.  
  11168. })();
  11169.  
  11170. !isUrlInEmbed && Promise.resolve().then(() => {
  11171.  
  11172. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11173.  
  11174.  
  11175.  
  11176. class LimitedSizeSet extends Set {
  11177. constructor(n) {
  11178. super();
  11179. this.limit = n;
  11180. }
  11181.  
  11182. add(key) {
  11183. if (!super.has(key)) {
  11184. super.add(key);
  11185. let n = super.size - this.limit;
  11186. if (n > 0) {
  11187. const iterator = super.values();
  11188. do {
  11189. const firstKey = iterator.next().value; // Get the first (oldest) key
  11190. super.delete(firstKey); // Delete the oldest key
  11191. } while (--n > 0)
  11192. }
  11193. }
  11194. }
  11195.  
  11196. removeAdd(key) {
  11197. super.delete(key);
  11198. this.add(key);
  11199. }
  11200.  
  11201. }
  11202.  
  11203. // const wk3 = new WeakMap();
  11204.  
  11205. // let mtxVideoId = '';
  11206. // let aje3 = [];
  11207. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11208. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11209. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11210. let mtzCount = 0; // the key keeps unchanged
  11211. // let mjtNextMainKey = '';
  11212. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11213. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11214. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11215. // let allowNoDelay322=false;
  11216. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11217.  
  11218. let mpKey22 = ''; // last success continutation key & url pair
  11219. let mpUrl22 = ''; // last success continutation key & url pair
  11220. let mpKey21 = ''; // latest requested continutation key & url pair
  11221. let mpUrl21 = ''; // latest requested continutation key & url pair
  11222.  
  11223.  
  11224. async function sha1Hex(message) {
  11225. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11226. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11227. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11228. const hashHex = hashArray
  11229. .map((b) => b.toString(16).padStart(2, "0"))
  11230. .join(""); // convert bytes to hex string
  11231. return hashHex;
  11232. }
  11233.  
  11234. async function continuationLog(a, ...args) {
  11235. let b = a;
  11236. try {
  11237. if (advanceLogging) b = await sha1Hex(a);
  11238. let c = args.map(e => {
  11239. return e === a ? b : e
  11240. });
  11241. console.log(...c)
  11242. } catch (e) { console.warn(e) }
  11243. }
  11244.  
  11245. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11246.  
  11247.  
  11248. if (mfvContinuationRecorded.length > 0) {
  11249. for (const [e, d] of mfvContinuationRecorded) {
  11250. mfyContinuationIgnored.removeAdd(e);
  11251. }
  11252. toClearRecorded && mfvContinuationRecorded.clear();
  11253. }
  11254.  
  11255. }
  11256.  
  11257. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11258.  
  11259. const tmProto = taskMgr.constructor.prototype;
  11260. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11261.  
  11262. if (!tmProto.addJob714) {
  11263.  
  11264. tmProto.addJob714 = tmProto.addJob;
  11265.  
  11266. tmProto.addJob = function (a, b, c) {
  11267. const jobId = this.addJob714(a, b, c);
  11268. if (jobId > 0) {
  11269. // const ez = wk3.get(this);
  11270. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11271. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11272.  
  11273. this.__lastJobId863__ = jobId;
  11274. }
  11275. return jobId;
  11276. }
  11277.  
  11278. }
  11279.  
  11280. if (!tmProto.cancelJob714) {
  11281.  
  11282. tmProto.cancelJob714 = tmProto.cancelJob;
  11283.  
  11284. tmProto.cancelJob = function (a) {
  11285. const res = this.cancelJob714(a);
  11286. // if (a > 0) {
  11287. // for (const e of aje3) {
  11288. // if (e.jobId === a) e.cancelled = true;
  11289. // }
  11290. // }
  11291. return res;
  11292. }
  11293.  
  11294. }
  11295.  
  11296. }
  11297. }
  11298.  
  11299.  
  11300. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11301.  
  11302.  
  11303. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11304. let dummy;
  11305. let cProto;
  11306. // let mc = 4;
  11307. // dummy = await observablePromise(() => {
  11308. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11309. // if (!r) return;
  11310. // let cProto = insp(r).constructor.prototype;
  11311. // if (cProto.fetchUpdatedMetadata) return r;
  11312. // if (--mc < 0) return -1;
  11313. // return null;
  11314. // }).obtain();
  11315. dummy = document.createElement('ytd-video-primary-info-renderer');
  11316. if (!(dummy instanceof Element)) return;
  11317. // console.log(5022, dummy)
  11318. cProto = insp(dummy).constructor.prototype;
  11319.  
  11320. cProto.__getEmittorTaskMgr859__ = function () {
  11321. let taskMgr_ = null;
  11322. try {
  11323. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  11324. } catch (e) { }
  11325. return taskMgr_;
  11326. }
  11327. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  11328. // console.log(1234, cProto, cProto.is)
  11329. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  11330.  
  11331. let c_;
  11332. cProto.fetchUpdatedMetadata718 = function (a) {
  11333. // delay or immediate call the actual fetchUpdatedMetadata
  11334.  
  11335. let doImmediately = false;
  11336. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  11337.  
  11338. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  11339.  
  11340. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  11341.  
  11342. doImmediately = true;
  11343.  
  11344. }
  11345.  
  11346. if (mbCId322) {
  11347. clearTimeout(mbCId322);
  11348. mbCId322 = 0;
  11349. }
  11350.  
  11351. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  11352.  
  11353. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  11354.  
  11355. mbCId322 = setTimeout(() => {
  11356. this.fetchUpdatedMetadata717(a);
  11357. }, delay);
  11358.  
  11359. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  11360.  
  11361. }
  11362.  
  11363. cProto.fetchUpdatedMetadata = function (a) {
  11364.  
  11365. if (!pageSetupState) {
  11366. if (c_) clearTimeout(c_);
  11367. c_ = setTimeout(() => {
  11368. this.fetchUpdatedMetadata718(a);
  11369. }, 300);
  11370. return;
  11371. }
  11372.  
  11373. // pageSetupState == 0
  11374.  
  11375. try {
  11376.  
  11377. mbDelayBelowNCalls++;
  11378.  
  11379. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  11380. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  11381. }
  11382.  
  11383. // console.log('fum377', a)
  11384. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  11385. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  11386. return;
  11387. }
  11388.  
  11389. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  11390. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  11391. mjtLockPreviousKey = mjtRecordedPrevKey;
  11392. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  11393. }
  11394. // mjtNextMainKey = true;
  11395. mtzlastAllowedContinuation = '';
  11396. mtzCount = 0;
  11397. // allowNoDelay322 = false;
  11398. // fetch new metadata, cancel all previous continuations
  11399. copyPreviousContiuationToIgnored374(true);
  11400. } else if (typeof a === 'string') {
  11401. const videoPlayingId = videoPlayingY.videoId;
  11402.  
  11403. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  11404.  
  11405. let update21 = !!pageSetupVideoId;
  11406. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  11407. update21 = true;
  11408. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  11409. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  11410. return;
  11411. }
  11412. if (update21) {
  11413. mpKey21 = a;
  11414. mpUrl21 = pageSetupVideoId || videoPlayingId;
  11415. }
  11416.  
  11417. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  11418. }
  11419. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  11420. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  11421. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  11422. return this.fetchUpdatedMetadata718(a);
  11423.  
  11424. } catch (e) {
  11425. console.log('Code Error in fetchUpdatedMetadata', e);
  11426. }
  11427. return this.fetchUpdatedMetadata717(a)
  11428. }
  11429. }
  11430.  
  11431.  
  11432. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  11433. // console.log(1234, cProto, cProto.is)
  11434. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  11435. let mJob = null;
  11436.  
  11437. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  11438.  
  11439. try {
  11440.  
  11441. if (arguments.length > 0) {
  11442. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  11443. }
  11444. // mfy = mfv;
  11445.  
  11446. // mjtNextMainKey = '';
  11447. mtzlastAllowedContinuation = '';
  11448. mtzCount = 0;
  11449. if (mbCId322) {
  11450. clearTimeout(mbCId322);
  11451. mbCId322 = 0;
  11452. }
  11453. mbDelayBelowNCalls = 0;
  11454. // allowNoDelay322 = false;
  11455. copyPreviousContiuationToIgnored374(true);
  11456.  
  11457. const taskMgr = this.__getEmittorTaskMgr859__();
  11458. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  11459. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  11460. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  11461. }
  11462.  
  11463. // prevent depulicated schedule job by clearing previous JobId
  11464. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  11465.  
  11466. let res;
  11467.  
  11468. if (mJob) {
  11469. const job = mJob;
  11470. mJob = null;
  11471. console.log('cancelJob', job)
  11472. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  11473. // p.cancelJob(a,b);
  11474. }
  11475.  
  11476. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  11477.  
  11478. let pza = taskMgr.__lastJobId863__;
  11479. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  11480. let pzb = taskMgr.__lastJobId863__
  11481. if (pza !== pzb) {
  11482. mJob = pzb; // set [Interval Meta Update] jobId
  11483. }
  11484.  
  11485. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  11486. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  11487. // } else {
  11488. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  11489. // }
  11490.  
  11491. return res;
  11492.  
  11493. } else {
  11494. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  11495. }
  11496.  
  11497. } catch (e) {
  11498. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  11499. }
  11500.  
  11501.  
  11502. return this.scheduleInitialUpdatedMetadataRequest717();
  11503. }
  11504. }
  11505.  
  11506.  
  11507. });
  11508.  
  11509. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  11510. let dummy;
  11511. let cProto;
  11512. dummy = ytAppDom;
  11513. if (!(dummy instanceof Element)) return;
  11514. cProto = insp(dummy).constructor.prototype;
  11515. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  11516. // console.log(1234, cProto, cProto.is);
  11517. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11518. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  11519. // console.log(123401, arguments);
  11520. // return this.handleServiceRequest717_(a, b, c, d);
  11521. // }
  11522.  
  11523. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11524.  
  11525. // cProto.handleServiceRequest_ = function(a,b,c,d){
  11526. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11527. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  11528. // console.log('mfv', c.continuation);
  11529. // mfv.add( c.continuation);
  11530. // }
  11531. // return this.handleServiceRequest717_(a,b,c,d);
  11532. // }
  11533.  
  11534. function extraArguments322(a, b, c) {
  11535. let is = (a || 0).is;
  11536. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  11537. let continuation = (c || 0).continuation;
  11538. if (typeof is !== 'string') is = null;
  11539. if (typeof videoId !== 'string') videoId = null;
  11540. if (typeof continuation !== 'string') continuation = null;
  11541. return { is, videoId, continuation };
  11542. }
  11543.  
  11544. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  11545. cProto.sendServiceAjax_ = function (a, b, c, d) {
  11546.  
  11547. // console.log(8001)
  11548. try {
  11549.  
  11550. const { is, videoId, continuation } = extraArguments322(a, b, c);
  11551.  
  11552. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11553. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  11554. }
  11555.  
  11556. if (pageSetupVideoId && videoId && continuation) {
  11557. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11558. mfyContinuationIgnored.removeAdd(continuation);
  11559. mfvContinuationRecorded.delete(continuation);
  11560. return;
  11561. }
  11562. }
  11563.  
  11564. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11565. copyPreviousContiuationToIgnored374(false);
  11566. mfyContinuationIgnored.delete(continuation);
  11567. mfvContinuationRecorded.removeAdd(continuation);
  11568. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11569. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11570. mjtLockPreviousKey = '';
  11571. }
  11572. // if (mjtNextMainKey === continuation) {
  11573. // copyPreviousContiuationToIgnored(false);
  11574. // mfyContinuationIgnored.delete(continuation);
  11575. // mfvContinuationRecorded.add(continuation);
  11576. // }
  11577.  
  11578.  
  11579. if (mfyContinuationIgnored && continuation) {
  11580. if (mfyContinuationIgnored.has(continuation)) {
  11581. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  11582. return;
  11583. }
  11584. }
  11585.  
  11586. // console.log(59902, a?.is, b,c,d)
  11587. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11588. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  11589. // console.log('mfv377', continuation);
  11590. mfvContinuationRecorded.add(continuation);
  11591. }
  11592.  
  11593. // if (videoId) {
  11594. // if (!pageSetupVideoId) return; // ignore page not ready
  11595. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  11596. // if (videoId !== pageSetupVideoId) {
  11597. // return;
  11598. // }
  11599. // }
  11600.  
  11601. } catch (e) {
  11602. console.log('Coding Error in sendServiceAjax_', e)
  11603. }
  11604. // console.log(8002)
  11605. // console.log(123402, arguments);
  11606. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  11607.  
  11608. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  11609. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  11610. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  11611. // get(target, prop, receiver){
  11612. // console.log('xxs99', target.videoId, mtx)
  11613. // if(prop ==='kdkw33') return 1;
  11614. // console.log(3322, prop, target)
  11615. // if(prop === 'initialDelayMs') {
  11616. // throw new Error("ABCC");
  11617. // }
  11618. // return target[prop];
  11619. // },
  11620. // set(target, prop, value, receiver){
  11621.  
  11622. // if(prop ==='kdkw33') return true;
  11623. // target[prop]=value;
  11624. // return true;
  11625. // }
  11626. // });
  11627. // }
  11628. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  11629. return this.sendServiceAjax717_(a, b, c, d);
  11630. }
  11631. }
  11632.  
  11633. function delayClearOtherKeys(lztContinuation) {
  11634. // // schedule delayed removal if mfyContinuationIgnored is not empty
  11635. // getRafPromise().then(() => {
  11636. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  11637. // // foreground page only
  11638.  
  11639. // });
  11640.  
  11641.  
  11642. if (lztContinuation !== mtzlastAllowedContinuation) return;
  11643. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  11644. if (!mfyContinuationIgnored.size) return;
  11645. if (mfyContinuationIgnored.size > 1) {
  11646. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  11647. }
  11648. mfyContinuationIgnored.forEach((value, key) => {
  11649. if (key !== lztContinuation) {
  11650. mfyContinuationIgnored.delete(key);
  11651. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  11652. }
  11653. });
  11654.  
  11655. }
  11656. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  11657. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  11658. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  11659.  
  11660. // console.log(8003)
  11661. try {
  11662.  
  11663.  
  11664. const { is, videoId, continuation } = extraArguments322(b, c, d);
  11665.  
  11666. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11667. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  11668. }
  11669.  
  11670. if (pageSetupVideoId && videoId && continuation) {
  11671. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11672. mfyContinuationIgnored.removeAdd(continuation);
  11673. mfvContinuationRecorded.delete(continuation);
  11674. return;
  11675. }
  11676. }
  11677.  
  11678. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11679. copyPreviousContiuationToIgnored374(false);
  11680. mfyContinuationIgnored.delete(continuation);
  11681. mfvContinuationRecorded.removeAdd(continuation);
  11682. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11683. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11684. mjtLockPreviousKey = '';
  11685. }
  11686.  
  11687. // if (mjtNextMainKey === continuation) {
  11688. // copyPreviousContiuationToIgnored(false);
  11689. // mfyContinuationIgnored.delete(continuation);
  11690. // mfvContinuationRecorded.add(continuation);
  11691. // }
  11692.  
  11693. const lztContinuation = continuation;
  11694.  
  11695. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  11696. if (mfyContinuationIgnored.has(lztContinuation)) {
  11697. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  11698. return;
  11699. }
  11700. }
  11701.  
  11702. // if (videoId) {
  11703. // if (!pageSetupVideoId) return; // ignore page not ready
  11704. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  11705. // if (videoId !== pageSetupVideoId) {
  11706. // return;
  11707. // }
  11708. // }
  11709.  
  11710. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  11711. mtzlastAllowedContinuation = lztContinuation;
  11712. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  11713.  
  11714. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  11715. mjtRecordedPrevKey = lztContinuation;
  11716. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  11717. // if (mfyContinuationIgnored.size > 0) {
  11718. // delayClearOtherKeys(lztContinuation);
  11719. // }
  11720. mtzCount = 0;
  11721. // allowNoDelay322 = false;
  11722. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  11723. // repeated
  11724. if (++mtzCount > 1e9) mtzCount = 1e4;
  11725. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  11726.  
  11727. // if (mtzCount >= 3) allowNoDelay322 = true;
  11728. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  11729. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  11730. }
  11731. if (mtzCount === 5) {
  11732. mfvContinuationRecorded.clear();
  11733. mfvContinuationRecorded.add(lztContinuation);
  11734. }
  11735.  
  11736. }
  11737.  
  11738. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  11739. mpKey22 = lztContinuation;
  11740. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  11741. }
  11742.  
  11743. if (mbCId322) {
  11744. clearTimeout(mbCId322);
  11745. mbCId322 = 0;
  11746. }
  11747. } catch (e) {
  11748. console.log('Coding Error in getCancellableNetworkPromise_', e)
  11749. }
  11750.  
  11751. // console.log(8004)
  11752. // console.log(123403, arguments);
  11753. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  11754.  
  11755. // console.log(5163, a?.is,b,c,d,e);
  11756. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  11757. }
  11758. }
  11759. });
  11760.  
  11761. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11762.  
  11763.  
  11764. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  11765.  
  11766. let dummy;
  11767. let cProto;
  11768.  
  11769. dummy = document.createElement('ytd-expander');
  11770. cProto = insp(dummy).constructor.prototype;
  11771.  
  11772. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  11773.  
  11774. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  11775. cProto.childrenChanged14 = cProto.childrenChanged;
  11776.  
  11777. cProto.initChildrenObserver = function () {
  11778. var a = this;
  11779. this.observer = new MutationObserver(function () {
  11780. a.childrenChanged()
  11781. }
  11782. );
  11783. this.observer.observe(this.content, {
  11784. subtree: !0,
  11785. childList: !0,
  11786. attributes: !0,
  11787. characterData: !0
  11788. });
  11789. this.childrenChanged()
  11790. }
  11791. ;
  11792. cProto.childrenChanged = function () {
  11793. if (this.alwaysToggleable) {
  11794. this.canToggle = this.alwaysToggleable;
  11795. } else if (!this.canToggleJobId) {
  11796. this.canToggleJobId = 1;
  11797. foregroundPromiseFn().then(() => {
  11798. this.canToggleJobId = 0;
  11799. this.calculateCanCollapse()
  11800. })
  11801. }
  11802. }
  11803.  
  11804. // console.log(cProto.initChildrenObserver)
  11805. console.debug('ytd-expander-fix-childrenChanged');
  11806.  
  11807. }
  11808.  
  11809. });
  11810.  
  11811.  
  11812. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  11813.  
  11814. let dummy;
  11815. let cProto;
  11816. dummy = document.createElement('paper-ripple');
  11817. cProto = insp(dummy).constructor.prototype;
  11818.  
  11819. if (fnIntegrity(cProto.animate, '0.74.5')) {
  11820.  
  11821.  
  11822. cProto.animate34 = cProto.animate;
  11823. cProto.animate = function () {
  11824. if (this._animating) {
  11825. var a;
  11826. const ripples = this.ripples;
  11827. for (a = 0; a < ripples.length; ++a) {
  11828. var b = ripples[a];
  11829. b.draw();
  11830. this.$.background.style.opacity = b.outerOpacity;
  11831. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  11832. }
  11833. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  11834. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  11835. foregroundPromiseFn().then(this._boundAnimate38);
  11836. } else {
  11837. this.onAnimationComplete();
  11838. }
  11839. }
  11840. }
  11841.  
  11842. console.debug('FIX_paper_ripple_animate')
  11843.  
  11844. // console.log(cProto.animate)
  11845.  
  11846. }
  11847.  
  11848. });
  11849.  
  11850. if (FIX_doIdomRender) {
  11851.  
  11852. const xsetTimeout = function (f, d) {
  11853. if (xsetTimeout.m511 === 1 && !d) {
  11854. xsetTimeout.m511 = 2;
  11855. xsetTimeout.m568 = f;
  11856. } else {
  11857. return setTimeout.apply(window, arguments)
  11858. }
  11859.  
  11860. }
  11861.  
  11862. /**
  11863. *
  11864. IGb = function(a) {
  11865. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  11866. c || (a.requestAninmationFrameResolver = new Vi,
  11867. c = a.requestAninmationFrameResolver.promise,
  11868. Da.requestAnimationFrame(function() {
  11869. var d;
  11870. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  11871. a.requestAninmationFrameResolver = null
  11872. }));
  11873. return c
  11874. }
  11875.  
  11876.  
  11877. */
  11878.  
  11879. const xrequestAnimationFrame = function (f) {
  11880. const h = `${f}`;
  11881. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  11882. let t = null;
  11883. xsetTimeout.m511 = 1;
  11884. f();
  11885. if (xsetTimeout.m511 === 2) {
  11886. t = xsetTimeout.m568;
  11887. xsetTimeout.m568 = null;
  11888. }
  11889. xsetTimeout.m511 = 0;
  11890. if (typeof t === 'function') {
  11891. foregroundPromiseFn().then(t);
  11892. }
  11893. } else if (h.includes("requestAninmationFrameResolver")) {
  11894. foregroundPromiseFn().then(f);
  11895. } else {
  11896. return requestAnimationFrame.apply(window, arguments);
  11897. }
  11898. }
  11899.  
  11900. let busy = false;
  11901. const doIdomRender = function () {
  11902.  
  11903. if (!this) return;
  11904. if (busy) {
  11905. return this.doIdomRender13(...arguments);
  11906. }
  11907. busy = true;
  11908. const { requestAnimationFrame, setTimeout } = window;
  11909. window.requestAnimationFrame = xrequestAnimationFrame;
  11910. window.setTimeout = xsetTimeout;
  11911. let r = this.doIdomRender13(...arguments);
  11912. window.requestAnimationFrame = requestAnimationFrame;
  11913. window.setTimeout = setTimeout;
  11914. busy = false;
  11915. return r;
  11916. };
  11917. 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']) {
  11918.  
  11919.  
  11920. whenCEDefined(ytTag).then(() => {
  11921.  
  11922. let dummy;
  11923. let cProto;
  11924. dummy = document.createElement(ytTag);
  11925. cProto = insp(dummy).constructor.prototype;
  11926.  
  11927. cProto.doIdomRender13 = cProto.doIdomRender;
  11928. cProto.doIdomRender = doIdomRender;
  11929.  
  11930. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  11931.  
  11932. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  11933.  
  11934.  
  11935.  
  11936. });
  11937.  
  11938. }
  11939.  
  11940. }
  11941.  
  11942.  
  11943.  
  11944.  
  11945. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  11946.  
  11947. const sMap = new Map();
  11948.  
  11949. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  11950. const ZT = function () {
  11951. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  11952. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  11953. c = b & 15,
  11954. b >>= 4,
  11955. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  11956. return a.join("")
  11957. };
  11958.  
  11959.  
  11960. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  11961.  
  11962. const popupContainer = await observablePromise(() => {
  11963. return popupContainerCollection[0];
  11964. }).obtain();
  11965.  
  11966.  
  11967. let cProto;
  11968. cProto = insp(popupContainer).constructor.prototype;
  11969.  
  11970.  
  11971. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  11972. console.log('FIX_POPUP_UNIQUE_ID NG')
  11973. return;
  11974. }
  11975. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  11976.  
  11977. cProto.handleOpenPopupAction = function (a, b) {
  11978.  
  11979. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  11980.  
  11981. a.__jOdQA__ = true;
  11982.  
  11983. try {
  11984.  
  11985. const h = this.hostElement;
  11986.  
  11987. if (h instanceof HTMLElement_) {
  11988.  
  11989. const map = h.__skme44__ = h.__skme44__ || new Map();
  11990.  
  11991. let mKey = '';
  11992. const wKey = firstObjectKey(a);
  11993. const wObj = wKey ? a[wKey] : null;
  11994. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  11995. const pKey = firstObjectKey(wObj.popup)
  11996. const pObj = pKey ? wObj.popup[pKey] : null;
  11997. let contentKey = '';
  11998. let headerKey = '';
  11999.  
  12000. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  12001. contentKey = firstObjectKey(pObj.content)
  12002. headerKey = firstObjectKey(pObj.header)
  12003. }
  12004. if (contentKey && headerKey) {
  12005.  
  12006. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  12007.  
  12008. if (mKey) {
  12009.  
  12010. if (!wObj.uniqueId) {
  12011. for (let i = 0; i < 8; i++) {
  12012. wObj.uniqueId = ZT();
  12013. if (!sMap.has(wObj.uniqueId)) break;
  12014. }
  12015. }
  12016. const oId = wObj.uniqueId
  12017.  
  12018. let nId_ = map.get(mKey);
  12019. if (!nId_) {
  12020. map.set(mKey, nId_ = oId);
  12021. }
  12022.  
  12023. wObj.uniqueId = nId_ || wObj.uniqueId;
  12024.  
  12025. const nId = wObj.uniqueId
  12026.  
  12027. sMap.set(oId, nId);
  12028. sMap.set(nId, nId);
  12029.  
  12030. wObj.uniqueId = nId;
  12031. pObj.targetId = nId;
  12032. pObj.identifier.tag = nId;
  12033.  
  12034. if (oId !== nId) {
  12035. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  12036. }
  12037.  
  12038. }
  12039.  
  12040. }
  12041. }
  12042.  
  12043. // console.log(12213, mKey, a, b, h)
  12044.  
  12045. }
  12046.  
  12047. } catch (e) {
  12048. console.warn(e)
  12049. }
  12050.  
  12051. try {
  12052.  
  12053. const results = searchNestedObject(a, (x) => {
  12054. if (typeof x === 'string' && x.length === 36) {
  12055. 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;
  12056. }
  12057. return false;
  12058. });
  12059. for (const [obj, key] of results) {
  12060. const oId = obj[key];
  12061. const nId = sMap.get(oId);
  12062. if (nId) obj[key] = nId;
  12063. }
  12064. } catch (e) {
  12065. console.warn(e)
  12066. }
  12067.  
  12068.  
  12069. }
  12070.  
  12071. return this.handleOpenPopupAction3868(...arguments)
  12072. }
  12073.  
  12074. console.log('FIX_POPUP_UNIQUE_ID OK')
  12075.  
  12076.  
  12077. });
  12078.  
  12079.  
  12080. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  12081.  
  12082. let dummy;
  12083. let cProto;
  12084. dummy = document.createElement('yt-formatted-string');
  12085. cProto = insp(dummy).constructor.prototype;
  12086.  
  12087. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  12088. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  12089. return;
  12090. }
  12091.  
  12092. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  12093. cProto.setNodeStyle_ = function (a, b) {
  12094. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  12095. return this.setNodeStyle17_(a, b);
  12096. }
  12097.  
  12098. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  12099. });
  12100.  
  12101. });
  12102.  
  12103. });
  12104.  
  12105.  
  12106.  
  12107.  
  12108. if (isMainWindow) {
  12109.  
  12110. console.groupCollapsed(
  12111. "%cYouTube JS Engine Tamer",
  12112. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  12113. );
  12114.  
  12115.  
  12116.  
  12117. console.log("Script is loaded.");
  12118. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  12119.  
  12120. console.log("This script is experimental and subject to further changes.");
  12121.  
  12122. console.log("This might boost your YouTube performance.");
  12123.  
  12124. console.log("CAUTION: This might break your YouTube.");
  12125.  
  12126.  
  12127. if (prepareLogs.length >= 1) {
  12128. console.log(" =========================================================================== ");
  12129.  
  12130. for (const msg of prepareLogs) {
  12131. console.log(msg)
  12132. }
  12133.  
  12134. console.log(" =========================================================================== ");
  12135. }
  12136.  
  12137. console.groupEnd();
  12138.  
  12139. }
  12140.  
  12141.  
  12142.  
  12143. })();