YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

Versione datata 23/04/2025. Vedi la nuova versione l'ultima versione.

  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.20.14
  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 NO_PRELOAD_GENERATE_204 = false;
  39. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  40. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  41. const CHANGE_appendChild = true; // discussions#236759
  42. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  43. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  44.  
  45. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  46. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  47. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  48.  
  49. const FIX_Iframe_NULL_SRC = false;
  50.  
  51. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  52.  
  53. const FIX_ytdExpander_childrenChanged = true;
  54. const FIX_paper_ripple_animate = true;
  55. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  56. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  57.  
  58. const FIX_doIdomRender = true;
  59.  
  60. const FIX_Shady = true;
  61.  
  62. // [[ 2024.04.24 ]]
  63. const MODIFY_ShadyDOM_OBJ = true;
  64. // << if MODIFY_ShadyDOM_OBJ >>
  65. const WEAKREF_ShadyDOM = true;
  66. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  67. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  68. // << end >>
  69.  
  70. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  71.  
  72. const FIX_ytAction_ = true; // ytd-app
  73. const FIX_onVideoDataChange = false;
  74. // const FIX_onClick = true;
  75. const FIX_onStateChange = true;
  76. const FIX_onLoopRangeChange = true;
  77. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  78. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  79.  
  80. const ENABLE_discreteTasking = false; // removed since 0.20.0
  81. const FIX_stampDomArray_ = true; // changed since 0.20.0
  82. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  83.  
  84. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  85. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  86.  
  87. const FIX_Polymer_dom = true;
  88.  
  89. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  90. const DEBUG_removePrune = false; // true for DEBUG
  91.  
  92. const FIX_XHR_REQUESTING = true;
  93.  
  94. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  95.  
  96. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  97.  
  98. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  99. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  100.  
  101. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  102.  
  103. const FIX_removeChild = true;
  104. const FIX_fix_requestIdleCallback_timing = true;
  105.  
  106. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  107. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  108.  
  109. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  110.  
  111. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  112.  
  113. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  114. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  115. // first tp-yt-paper-dialog: show once the page is loaded.
  116. // second tp-yt-paper-dialog: click "...more"
  117. // third tp-yt-paper-dialog: click "... and 3 more links"
  118. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  119. // currently, uniqueId is preassigned by the network resolveCommand.
  120. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  121. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  122.  
  123. // handleOpenPopupAction -> createCacheKey
  124. // handleClosePopupAction_ -> createCacheKey
  125. // handleGetPopupOpenedAction_ -> createCacheKey
  126. // getAndMaybeCreatePopup_ -> createCacheKey
  127. // closePopup -> createCacheKey
  128.  
  129. // yt-close-popup-command -> handleClosePopupCommand_
  130.  
  131. // ensurePopup_ -> getAndMaybeCreatePopup_
  132.  
  133. // yt-close-popup-action -> handleClosePopupAction_
  134. // closePopup -> handleClosePopupAction_
  135. // handleOpenPopupAction -> handleClosePopupAction_
  136. // handleClosePopupCommand_ -> handleClosePopupAction_
  137. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  138.  
  139. // yt-open-popup-action -> handleOpenPopupAction
  140.  
  141.  
  142. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  143. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  144.  
  145. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  146. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  147. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  148.  
  149.  
  150. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  151. const FIX_DOM_IF_TEMPLATE = true;
  152. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  153. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  154. const DEBUG_DBR847 = false;
  155. const DEBUG_xx847 = false;
  156. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  157. const DEBUG_renderDebounceTs = false;
  158.  
  159. const FIX_ICON_RENDER = true;
  160.  
  161. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  162.  
  163. /*
  164.  
  165. FIX_DOM_IFREPEAT_RenderDebouncerChange
  166.  
  167. avoid Polymer.flush
  168. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  169.  
  170. var Is = function() {
  171. do {
  172. var a = window.ShadyDOM && ShadyDOM.flush();
  173. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  174. var b = NNa()
  175. } while (a || b)
  176. };
  177.  
  178. , NNa = function() {
  179. var a = !!ts.size;
  180. ts.forEach(function(b) {
  181. try {
  182. b.flush()
  183. } catch (c) {
  184. setTimeout(function() {
  185. throw c
  186. })
  187. }
  188. });
  189. return a
  190. };
  191.  
  192. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  193. // this coding logic should be incorrect (mistake).
  194.  
  195. */
  196.  
  197.  
  198.  
  199. // ----------------------------- Shortkey Keyboard Control -----------------------------
  200. // dependency: FIX_yt_player
  201.  
  202. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  203. // [0] no fix - not recommended
  204. // [1] basic fix - just fix the global focus detection variable
  205. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  206. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  207.  
  208. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  209. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  210.  
  211. const PROP_OverReInclusion_AVOID = true;
  212. const PROP_OverReInclusion_DEBUGLOG = false;
  213. const PROP_OverReInclusion_LIST = new Set([
  214. 'hostElement72',
  215. 'parentComponent72',
  216. 'localVisibilityObserver_72',
  217. 'cachedProviderNode_72',
  218. '__template72',
  219. '__templatizeOwner72',
  220. '__templateInfo72',
  221. '__dataHost72',
  222. '__CE_shadowRoot72',
  223. 'elements_72',
  224.  
  225. 'ky36',
  226. 'kz62',
  227. 'm822',
  228.  
  229.  
  230.  
  231. // To be reviewed.
  232.  
  233. // chat messages
  234. 'disabled', 'allowedProps',
  235. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  236.  
  237. 'dimension', 'loadTime', 'pendingPaint',
  238.  
  239. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  240.  
  241. 'respectLangDir', 'noEndpoints',
  242.  
  243.  
  244. 'objectURL',
  245. 'buttonOverrides', 'queuedMessages',
  246. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  247. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  248. 'hoverJobId', 'JSC$14573_touched',
  249.  
  250.  
  251. // tbc
  252. 'toggleable', 'isConnected',
  253. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  254. 'disableDeselectEvent',
  255. 'emojiSize',
  256.  
  257. 'buttonOverride',
  258. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  259.  
  260. // others
  261. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  262. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  263. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  264. // 'dimension', 'loadTime', 'pendingPaint',
  265. // 'disabled', 'allowedProps',
  266.  
  267.  
  268. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  269. // 'actionMap',
  270.  
  271. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  272.  
  273. 'clearTimeout',
  274. 'switchTemplateAtRegistration', 'hasUnmounted',
  275. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  276. 'tangoConfiguration',
  277. 'itemIdToDockDurationMap',
  278. 'actionMap',
  279.  
  280. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  281. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  282. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  283.  
  284. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  285. // 'stopKeyboardEventPropagation', 'emojiSize',
  286. // 'switchTemplateAtRegistration', 'hasUnmounted',
  287. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  288. // 'isReusable', 'tangoConfiguration',
  289. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  290. // */
  291.  
  292. ]);
  293.  
  294.  
  295. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  296.  
  297. // ----------------------------- Shortkey Keyboard Control -----------------------------
  298.  
  299. /*
  300. window.addEventListener('edm',()=>{
  301. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  302. });
  303.  
  304. window.addEventListener('edn',()=>{
  305. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  306. });
  307. window.addEventListener('edr',()=>{
  308. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  309. });
  310. */
  311.  
  312. // only for macOS with Chrome/Firefox 100+
  313. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  314.  
  315. const win = this instanceof Window ? this : window;
  316.  
  317. // Create a unique key for the script and check if it is already running
  318. const hkey_script = 'jswylcojvzts';
  319. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  320. win[hkey_script] = true;
  321.  
  322.  
  323. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  324.  
  325. let BY_PASS_KEYBOARD_CONTROL = false;
  326.  
  327.  
  328. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  329. /** @type {(f: ()=>{})=>{}} */
  330. const nextBrowserTick_ = nextBrowserTick;
  331. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  332. console.log('nextBrowserTick is not found.');
  333. return;
  334. }
  335.  
  336. let p59 = 0;
  337.  
  338. const Promise = (async () => { })().constructor;
  339.  
  340. const PromiseExternal = ((resolve_, reject_) => {
  341. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  342. return class PromiseExternal extends Promise {
  343. constructor(cb = h) {
  344. super(cb);
  345. if (cb === h) {
  346. /** @type {(value: any) => void} */
  347. this.resolve = resolve_;
  348. /** @type {(reason?: any) => void} */
  349. this.reject = reject_;
  350. }
  351. }
  352. };
  353. })();
  354.  
  355. let ttpHTML = (s) => {
  356. ttpHTML = s => s;
  357. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  358. let s = s => s;
  359. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  360. }
  361. return s;
  362. }
  363.  
  364.  
  365. /** @type { typeof HTMLElement } */
  366. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  367. const nativeAppendE = HTMLElement_.prototype.append;
  368. const nativeRemoveE = HTMLElement_.prototype.remove;
  369. const DocumentFragment_ = DocumentFragment;
  370. const nativeAppendD = DocumentFragment_.prototype.append;
  371. const Node_ = Node;
  372.  
  373. /**
  374. @param {number} x
  375. @param {number} d */
  376. const toFixed2 = (x, d) => {
  377. let t = x.toFixed(d);
  378. let y = `${+t}`;
  379. return y.length > t.length ? t : y;
  380. }
  381.  
  382.  
  383. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  384.  
  385.  
  386. const TRANSLATE_DEBUG = false;
  387.  
  388.  
  389. let xdeadc00 = null; // a deteched node with __domApi
  390. let xlivec00 = null; // a deteched node with __domApi
  391.  
  392. let removeTNodeRM = null;
  393. let removeTNodeBP = false;
  394.  
  395.  
  396.  
  397.  
  398. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  399.  
  400. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  401.  
  402. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  403.  
  404. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  405.  
  406.  
  407. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  408. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  409. return;
  410. }
  411.  
  412.  
  413. const mapGet = Map.prototype.get;
  414. const setHas = Set.prototype.has;
  415.  
  416.  
  417. /** @type {Map | null} */
  418. let qcMap = null;
  419.  
  420. Set.prototype.has = function (a) {
  421. if (a === 'dummy-4718') return false; // false to allow re-use?
  422. return setHas.call(this, a);
  423. }
  424.  
  425. Map.prototype.get = function (a) {
  426. if (a === 'dummy-4718') qcMap = this;
  427. return mapGet.call(this, a);
  428. };
  429. let r;
  430. try {
  431. r = mainCnt.createComponent_('dummy-4718', {}, true);
  432. } catch (e) {
  433.  
  434. }
  435.  
  436. Map.prototype.get = mapGet;
  437. Set.prototype.has = setHas;
  438.  
  439. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  440.  
  441.  
  442. // clearInterval(ckId);
  443. // ckId = 0;
  444.  
  445. if (qcMap !== null && qcMap instanceof Map) {
  446.  
  447. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  448. qcMap.__qcMap8781__ = true;
  449.  
  450. const setArrayC = (c) => {
  451. if (c instanceof Array) {
  452. c.length = 0;
  453. c.push = function () { };
  454. c.pop = function () { };
  455. c.shift = function () { };
  456. c.unshift = function () { };
  457. c.splice = function () { };
  458. c.sort = function () { };
  459. c.reverse = function () { };
  460. }
  461. }
  462.  
  463. const cleaning = function (m) {
  464. m.forEach(setArrayC);
  465. m.clear();
  466. }
  467.  
  468. qcMap.set = function (b, c) {
  469. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  470.  
  471. setArrayC(c);
  472.  
  473. // console.log('qcMap.set', b, c);
  474.  
  475. if (this.size > 0) {
  476. // play safe
  477.  
  478. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  479. cleaning(this);
  480. }
  481.  
  482. }
  483. qcMap.get = function (b) {
  484. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  485.  
  486. // console.log('qcMap.get', b);
  487.  
  488. if (this.size > 0) {
  489. // play safe
  490.  
  491. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  492. cleaning(this);
  493. }
  494.  
  495. }
  496.  
  497.  
  498. if (qcMap.size > 0) {
  499.  
  500. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  501. cleaning(qcMap);
  502. }
  503.  
  504. }
  505.  
  506. }
  507.  
  508. r = null;
  509. qcMap = null;
  510.  
  511. }
  512.  
  513. function getTranslate() {
  514.  
  515. pLoad.then(() => {
  516.  
  517. let nonce = document.querySelector('style[nonce]');
  518. nonce = nonce ? nonce.getAttribute('nonce') : null;
  519. const st = document.createElement('style');
  520. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  521. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  522. let parent;
  523. if (parent = document.head) parent.appendChild(st);
  524. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  525.  
  526. });
  527.  
  528. const snCache = new Map();
  529.  
  530. if (TRANSLATE_DEBUG) {
  531. console.log(11)
  532. }
  533.  
  534. /** @type {(str: string?) => string} */
  535. function _snippetText(str) {
  536. // str can be underfinded
  537. if (!str || typeof str !== 'string') return '';
  538. let res = snCache.get(str);
  539. if (res === undefined) {
  540. let b = false;
  541. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  542. b = true;
  543. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  544. });
  545. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  546. b = true;
  547. return '';
  548. });
  549. if (b) {
  550. snCache.set(str, res);
  551. snCache.set(res, null);
  552. } else {
  553. res = null;
  554. snCache.set(str, null);
  555. }
  556. }
  557. return res === null ? str : res;
  558. }
  559.  
  560. /** @type {(snippet: Object) => string} */
  561. function snippetText(snippet) {
  562. let runs = snippet.runs;
  563. const n = runs.length;
  564. if (n === 1) return _snippetText(runs[0].text);
  565. let res = new Array(n);
  566. let ci = 0;
  567. for (const s of runs) {
  568. res[ci++] = _snippetText(s.text);
  569. }
  570. return res.join('\n');
  571. }
  572.  
  573. const _DEBUG_szz = (t) => t.map(x => {
  574. const tsr = x.transcriptSegmentRenderer;
  575. return ({
  576. t: tsr.snippet.runs.map(x => x.text).join('//'),
  577. a: tsr.startMs,
  578. b: tsr.endMs
  579. });
  580. });
  581.  
  582. const fixRuns = (runs) => {
  583. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  584. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  585. const text = runs[0].text;
  586. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  587. const s = text.split(nlc);
  588. let bi = 0;
  589. runs.length = s.length;
  590. for (const text of s) {
  591. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  592. }
  593. }
  594. for (const s of runs) {
  595. s.text = _snippetText(s.text);
  596. }
  597. }
  598.  
  599. function translate(initialSegments) {
  600. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  601.  
  602. if (!initialSegments) return initialSegments;
  603.  
  604. if (TRANSLATE_DEBUG) {
  605. console.log(12);
  606. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  607. let obj = JSON.parse(r);
  608. console.log(7558, 1, obj)
  609. return obj;
  610. }).then(p => {
  611. let obj = _DEBUG_szz(p)
  612. console.log(7558, 2, obj)
  613. })
  614. }
  615.  
  616.  
  617. //let mapRej = new WeakSet();
  618.  
  619. const n1 = initialSegments.length;
  620. if (!n1) return fRes;
  621. let n2 = 0;
  622.  
  623.  
  624. const fRes = new Array(n1);
  625. // -----------------------------------------------------------------------------------------
  626.  
  627. const s8 = Symbol();
  628.  
  629. {
  630.  
  631. /** @type {Map<String, Object>} */
  632. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  633.  
  634. // /-* * @type {Map<String, number>} *-/
  635. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  636. // 1: ok
  637. // 2: abandoned effect text
  638.  
  639. for (const initialSegment of initialSegments) {
  640. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  641. if (!transcript) {
  642. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  643. fRes[n2++] = initialSegment;
  644. continue;
  645. }
  646. const runs = transcript.snippet.runs
  647. if (!runs || runs.length === 0) {
  648. initialSegment[s8] = true;
  649. continue;
  650. }
  651. let startMs = (+transcript.startMs || 0); //integer
  652. let endMs = (+transcript.endMs || 0); //integer
  653. if (startMs === endMs) {
  654. // effect text
  655. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  656. //mapRej.add(initialSegment)
  657. continue;
  658. }
  659. if (endMs - startMs < 30) {
  660. continue;
  661. }
  662. const text = snippetText(transcript.snippet);
  663. const hEntry = cacheTexts.get(text);
  664. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  665. if (mh1e === 2) continue;
  666. const entry = {
  667. startMs,
  668. endMs,
  669. initialSegment,
  670. text
  671. };
  672. if (mh1e === 0) {
  673. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  674. initialSegment[s8] = true;
  675. cacheTexts.set(text, null);
  676. //effect only
  677. // https://www.youtube.com/watch?v=zLak0dxBKpM
  678. //mapRej.add(initialSegment)
  679. continue;
  680. }
  681. } else if (hEntry) {
  682.  
  683. const timeDiff = entry.startMs - hEntry.endMs;
  684. let shouldMerge = false;
  685.  
  686. if (timeDiff >= 0) {
  687.  
  688. if (timeDiff < 25) {
  689. shouldMerge = true;
  690. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  691. shouldMerge = true;
  692. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  693. shouldMerge = true;
  694. }
  695.  
  696. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  697. // abandon the current entry.
  698. // absorbed by previous entry
  699. hEntry.endMs = entry.endMs;
  700. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  701. //mapRej.add(entry.initialSegment);
  702. continue;
  703. }
  704.  
  705. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  706.  
  707. // abandon the current entry.
  708. // absorbed by previous entry
  709. if (entry.endMs > hEntry.endMs) {
  710. hEntry.endMs = entry.endMs;
  711. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  712. }
  713. //mapRej.add(entry.initialSegment);
  714. continue;
  715.  
  716. }
  717.  
  718. }
  719. //if not abandoned
  720. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  721. // for (const s of runs) {
  722. // s.text = _snippetText(s.text);
  723. // }
  724. fixRuns(runs);
  725. fRes[n2++] = initialSegment;
  726. }
  727.  
  728. // cacheTexts.clear(); // let GC do it.
  729. cacheTexts = null;
  730. // mh1.clear(); // let GC do it.
  731. // mh1 = null;
  732.  
  733. }
  734.  
  735. const si_length = fRes.length = n2;
  736. const sj_length = n1;
  737.  
  738. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  739. // collect the abandon text to become second subtitle
  740.  
  741. let sj_start = 0;
  742. let invalid_sj = -1;
  743. for (let si = 0; si < si_length; si++) {
  744. const segment = fRes[si];
  745. let transcript = segment.transcriptSegmentRenderer;
  746. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  747. const runs = transcript.snippet.runs;
  748. // fixRuns(runs);
  749. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  750. const main_startMs = (+transcript.startMs || 0);
  751. const main_endMs = (+transcript.endMs || 0);
  752. transcript = null;
  753.  
  754. /** @type {Map<string, number>} */
  755. let tMap = new Map(); // avoid duplicate with javascript object properties
  756.  
  757. // assume that it is asc-ordered array of key startMs;
  758. for (let sj = sj_start; sj < sj_length; sj++) {
  759. const initialSegment = initialSegments[sj];
  760.  
  761. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  762.  
  763. const tSegment = initialSegment.transcriptSegmentRenderer;
  764.  
  765. if (!tSegment) {
  766. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  767. invalid_sj = sj; // should invalid_sj be set ?
  768. continue;
  769. }
  770.  
  771. const startMs = (+tSegment.startMs || 0)
  772. const isStartValid = startMs >= main_startMs;
  773. if (!isStartValid) {
  774. invalid_sj = sj;
  775. continue;
  776. }
  777. // isStartValid must be true
  778. if (startMs > main_endMs) {
  779. sj_start = invalid_sj + 1;
  780. break;
  781. }
  782.  
  783. const endMs = (+tSegment.endMs || 0)
  784. if (endMs <= main_endMs) {
  785. const mt = snippetText(tSegment.snippet);
  786. const prev = tMap.get(mt);
  787. if (endMs >= startMs) {
  788. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  789. }
  790. }
  791.  
  792. }
  793.  
  794. if (tMap.size <= 1) continue; // no second line
  795. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  796. tMap = null;
  797.  
  798. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  799.  
  800. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  801.  
  802. let targetZ = rg[1][1];
  803. if (targetZ > 4) {
  804. let az = 0;
  805. let fail = false;
  806. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  807. az += rg[idx][1];
  808. if (az >= targetZ) {
  809. fail = true;
  810. break;
  811. }
  812. }
  813. if (!fail) {
  814. const rgA = rg[0][0];
  815. const rgB = rg[1][0];
  816. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  817. if (isDiff && rgA === _snippetText(runs[0].text)) {
  818. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  819. runs.push({ text: rgB, blockLine: true });
  820. }
  821. }
  822. }
  823. rg = null;
  824. }
  825.  
  826. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  827.  
  828. let obj = r;
  829. console.log(7559, 1, obj)
  830. return obj;
  831. }).then(p => {
  832. let obj = _DEBUG_szz(p)
  833. console.log(7559, 2, obj)
  834.  
  835. });
  836. }
  837.  
  838. // -----------------------------------------------------------------------------------------
  839. snCache.clear();
  840. return fRes;
  841.  
  842. }
  843.  
  844.  
  845. return translate
  846.  
  847. }
  848.  
  849.  
  850. let translateFn = null;
  851.  
  852. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  853.  
  854. const wmx = new WeakMap();
  855.  
  856. function fixSegments(ytObj) {
  857. let a, b;
  858. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  859. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  860. translateFn = translateFn || getTranslate();
  861. let cSeg;
  862. cSeg = wmx.get(seg);
  863. if (!cSeg) {
  864. let vSeg = null;
  865. try {
  866. vSeg = translateFn(seg);
  867. } catch (e) {
  868. }
  869. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  870. // console.log('translated', vSeg);
  871. cSeg = vSeg;
  872. wmx.set(seg, cSeg);
  873. wmx.set(cSeg, cSeg);
  874. }
  875. }
  876. if (cSeg && cSeg !== seg) {
  877. a[b] = cSeg;
  878. }
  879. }
  880.  
  881. const dfn = Symbol();
  882. const Object_ = Object;
  883. Object_[dfn] = Object_.defineProperties;
  884. let activation = true;
  885. Object_.defineProperties = function (obj, pds) {
  886. let segments, get_;
  887. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  888. activation = false;
  889. segments.get = function () {
  890. fixSegments(this);
  891. return get_.call(this);
  892. };
  893. }
  894. return Object_[dfn](obj, pds);
  895. };
  896.  
  897. })();
  898.  
  899.  
  900. let pf31 = new PromiseExternal();
  901.  
  902. // native RAF
  903. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  904.  
  905. // 1st wrapped RAF
  906. const baseRAF = (callback) => {
  907. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  908. pf31.then(() => {
  909. callback(hRes);
  910. });
  911. });
  912. };
  913.  
  914. // 2nd wrapped RAF
  915. window.requestAnimationFrame = baseRAF;
  916.  
  917. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  918. const indr = o => insp(o).$ || o.$ || 0;
  919.  
  920. const prototypeInherit = (d, b) => {
  921. const m = Object.getOwnPropertyDescriptors(b);
  922. for (const p in m) {
  923. if (!Object.getOwnPropertyDescriptor(d, p)) {
  924. Object.defineProperty(d, p, m[p]);
  925. }
  926. }
  927. };
  928.  
  929.  
  930. const firstObjectKey = (obj) => {
  931. for (const key in obj) {
  932. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  933. }
  934. return null;
  935. };
  936.  
  937. function searchNestedObject(obj, predicate, maxDepth = 64) {
  938. // normal case: depth until 36
  939. const result = [];
  940. const visited = new WeakSet();
  941.  
  942. function search(obj, depth) {
  943. visited.add(obj);
  944. for (const [key, value] of Object.entries(obj)) {
  945. // Recursively search nested objects and arrays
  946. if (value !== null && typeof value === 'object') {
  947. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  948. if (depth + 1 <= maxDepth && !visited.has(value)) {
  949. search(value, depth + 1);
  950. }
  951. } else if (predicate(value)) {
  952. result.push([obj, key]);
  953. }
  954. }
  955. }
  956.  
  957. typeof (obj || 0) === 'object' && search(obj, 0);
  958. return result;
  959. }
  960.  
  961. /** @type {(o: Object | null) => WeakRef | null} */
  962. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  963.  
  964. /** @type {(wr: Object | null) => Object | null} */
  965. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  966.  
  967. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  968.  
  969. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  970. if (DENY_requestStorageAccess) {
  971. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  972. Document.prototype.requestStorageAccessFor = undefined;
  973. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  974. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  975. Document.prototype.requestStorageAccessFor = function () {
  976. return new Promise((resolve, reject) => {
  977. reject();
  978. });
  979. };
  980. }
  981. }
  982.  
  983. const traceStack = (stack) => {
  984. let result = new Set();
  985. let p = new Set();
  986. let u = ''
  987. for (const s of stack.split('\n')) {
  988. if (s.split(':').length < 3) continue;
  989. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  990. if (!m) continue;
  991. p.add(m[2]);
  992. if (p.size >= 3) break;
  993. if(!u) u = m[2];
  994. else if(p.size === 2 && u && u=== m[2]) break;
  995. result.add(s);
  996. }
  997. return [...result].join('\n');
  998. }
  999.  
  1000. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  1001. // window.m3bb = new Set();
  1002.  
  1003. // const smb = Symbol();
  1004. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  1005. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  1006. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  1007.  
  1008. const thisConversionFn = (thisArg) => {
  1009. if (!thisArg) return null;
  1010. const kThis = thisArg[vmb];
  1011. if (kThis) {
  1012. const ref = kThis.ref;
  1013. return (ref ? kRef(ref) : null) || null;
  1014. }
  1015. return thisArg;
  1016. }
  1017.  
  1018. const pFnHandler2 = {
  1019. get(target, prop) {
  1020. if (prop === vmc) return target;
  1021. return Reflect.get(target, prop);
  1022. },
  1023. apply(target, thisArg, argumentsList) {
  1024. thisArg = thisConversionFn(thisArg);
  1025. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  1026. }
  1027. }
  1028.  
  1029.  
  1030. const proxySelfHandler = {
  1031. get(target, prop) {
  1032. if(prop === vmb) return target;
  1033. const ref = target.ref;
  1034. const cnt = kRef(ref);
  1035. if (!cnt) return;
  1036. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  1037. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  1038. return cnt[prop][vmd];
  1039. }
  1040. return cnt[prop];
  1041. },
  1042. set(target, prop, value) {
  1043. const cnt = kRef(target.ref);
  1044. if (!cnt) return true;
  1045. if(value && (value[vmc] || value[vmb])){
  1046. cnt[prop] = value[vmc] || thisConversionFn(value);
  1047. return true;
  1048. }
  1049. cnt[prop] = value;
  1050. return true;
  1051. }
  1052. };
  1053.  
  1054. const weakWrap = (thisArg) => {
  1055. thisArg = thisConversionFn(thisArg);
  1056. if (!thisArg) {
  1057. console.error('thisArg is not found');
  1058. return null;
  1059. }
  1060. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  1061. }
  1062.  
  1063. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  1064. window.getComputedStyle533 = window.getComputedStyle;
  1065. window.getComputedStyle = function (a, ...args) {
  1066. a = thisConversionFn(a);
  1067. if (a) {
  1068. return getComputedStyle533(a, ...args);
  1069. }
  1070. return null;
  1071. }
  1072. }
  1073.  
  1074. Function._count_bind_00 = 0;
  1075. // Function._count_bind_01 = 0;
  1076.  
  1077. // let matchNativeCode = (Object+"");
  1078. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1079. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1080.  
  1081. // const matchConstructor = (thisArg) => {
  1082. // const f = `${(thisArg || 0).constructor}`;
  1083. // if (f.length > 45) return true;
  1084. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1085. // if (f.includes('[native code]')){
  1086. // return false;
  1087. // }
  1088. // return true;
  1089. // }
  1090. // return false;
  1091. // }
  1092.  
  1093. // const acceptThis = (thisArg)=>{
  1094. // // if(!thisArg || typeof thisArg !=='object') return false;
  1095. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1096. // // if(typeof thisArg.path === 'string') return true;
  1097. // // if(typeof thisArg.fn === 'function') return true;
  1098. // // if(typeof thisArg.id === 'string') return true;
  1099. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1100. // return false;
  1101. // }
  1102.  
  1103. const patchFn = (fn) => {
  1104.  
  1105. let s = `${fn}`;
  1106. if (s.length < 11 || s.includes('\n')) return false;
  1107. if(s.includes('bind(this')) return true;
  1108. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1109. // var a=this;
  1110. // f.bind(this)
  1111.  
  1112.  
  1113. return false;
  1114. }
  1115.  
  1116. Function.prototype.bind488 = Function.prototype.bind;
  1117. Function.prototype.bind = function(thisArg, ...args){
  1118.  
  1119. if (thisConversionFn(thisArg) !== thisArg) {
  1120. return this.bind488(thisArg, ...args);
  1121. }
  1122. if( thisArg && patchFn(this) ){
  1123.  
  1124. // console.log(599,`${this}`)
  1125.  
  1126. try {
  1127. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1128. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1129. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1130. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1131. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1132. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1133. // // let b4 = false;
  1134. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1135.  
  1136. // // b3 = false;
  1137. // // b4 = false;
  1138. // // b5 = false;
  1139.  
  1140. // if (b1 || b2 || b3 ||b4 ) {
  1141. const f = this;
  1142. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1143. if (ps && ps[vmb]) {
  1144. Function._count_bind_00++;
  1145. return f.bind488(ps, ...args)
  1146. }
  1147. // }
  1148. } catch (e) {
  1149. console.warn(e)
  1150. }
  1151. }
  1152. return this.bind488(thisArg, ...args);
  1153. }
  1154. Function.prototype.bind588 = 1;
  1155. }
  1156.  
  1157.  
  1158. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  1159. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  1160. const wm6 = new WeakMapOriginal();
  1161.  
  1162. const skipW = new WeakSet();
  1163.  
  1164.  
  1165. window.WeakMap = class WeakMap extends WeakMapOriginal {
  1166. constructor(iterable = undefined) {
  1167. super();
  1168. if (iterable && iterable[Symbol.iterator]) {
  1169. for (const entry of iterable) {
  1170. entry && this.set(entry[0], entry[1]);
  1171. }
  1172. }
  1173. }
  1174. delete(a) {
  1175. if (!this.has(a)) return false;
  1176. super.delete(a);
  1177. return true;
  1178. }
  1179. get(a) {
  1180. const p = super.get(a);
  1181. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1182. let v = kRef(p);
  1183. if (!v) {
  1184. super.delete(a);
  1185. }
  1186. return v || undefined;
  1187. }
  1188. return p;
  1189. }
  1190. has(a) {
  1191. if (!super.has(a)) return false;
  1192. const p = super.get(a);
  1193. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1194. if (!kRef(p)) {
  1195. super.delete(a);
  1196. return false;
  1197. }
  1198. }
  1199. return true;
  1200. }
  1201. set(a, b) {
  1202. let wq = b;
  1203. if (b && (typeof b === 'function' || typeof b === 'object')) {
  1204. if (b.deref) {
  1205. skipW.add(b);
  1206. wq = b;
  1207. } else {
  1208. wq = wm6.get(b);
  1209. if (!wq) {
  1210. wq = mWeakRef(b);
  1211. wm6.set(b, wq);
  1212. }
  1213. }
  1214. }
  1215. super.set(a, wq);
  1216. return this;
  1217. }
  1218. }
  1219. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  1220. configurable: true,
  1221. enumerable: false,
  1222. value: "WeakMap",
  1223. writable: false
  1224. });
  1225. }
  1226.  
  1227. const isWatchPageURL = (url) => {
  1228. url = url || location;
  1229. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  1230. };
  1231.  
  1232. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  1233.  
  1234. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  1235. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1236. if (typeof customElements === 'undefined') {
  1237. if (!('__CE_registry' in document)) {
  1238. // https://github.com/webcomponents/polyfills/
  1239. Object.defineProperty(document, '__CE_registry', {
  1240. get() {
  1241. // return undefined
  1242. },
  1243. set(nv) {
  1244. if (typeof nv == 'object') {
  1245. delete this.__CE_registry;
  1246. this.__CE_registry = nv;
  1247. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1248. }
  1249. return true;
  1250. },
  1251. enumerable: false,
  1252. configurable: true
  1253. })
  1254. }
  1255. let eventHandler = (evt) => {
  1256. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1257. const f = callback;
  1258. callback = null;
  1259. eventHandler = null;
  1260. f();
  1261. };
  1262. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1263. } else {
  1264. callback();
  1265. }
  1266. });
  1267.  
  1268. const whenCEDefined = isCustomElementsProvided
  1269. ? (nodeName) => customElements.whenDefined(nodeName)
  1270. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  1271.  
  1272. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  1273. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  1274. const f = performance.now23 = Performance.prototype.now;
  1275.  
  1276. let k = 0; // 0 <= k < 9998m
  1277. let u = 0;
  1278. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  1279.  
  1280. // By definition, performance.now() is mono increasing.
  1281. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  1282. performance.now = performance.now16 = function () {
  1283. /**
  1284. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  1285. *
  1286. * If consecutive session history entries had history.state.entryTime set to same value,
  1287. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  1288. * and modifying its return value slightly to make sure two close consecutive calls don't
  1289. * get the same result helped with resolving the issue.
  1290. */
  1291. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  1292. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  1293.  
  1294. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  1295. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  1296. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  1297. else { // more than 9998 consecutive calls
  1298. /**
  1299. *
  1300. * max no. of consecutive calls
  1301. *
  1302. * Sample Size: 4800
  1303. * Sample Avg = 1565.375
  1304. * Sample Median = 1469.5
  1305. * Sample Max = 5660 << 7500 << 9999
  1306. *
  1307. *
  1308. * */
  1309. k = 0;
  1310. s += 1 / 7;
  1311. }
  1312. return v + k; // 0 < v - M < v - M + k < v
  1313. }
  1314.  
  1315. let loggerMsg = '';
  1316. if (`${performance.now()}` === `${performance.now()}`) {
  1317. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  1318. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  1319. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  1320. }
  1321. loggerMsg && console.warn(loggerMsg);
  1322. })();
  1323.  
  1324. FIX_removeChild && (() => {
  1325. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  1326. Node.prototype.removeChild062 = Node.prototype.removeChild;
  1327. Node.prototype.removeChild = function (child) {
  1328. if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  1329. this.removeChild062(child);
  1330. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  1331. // tooltip bug
  1332. } else {
  1333. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  1334. }
  1335. return child;
  1336. }
  1337. }
  1338. })();
  1339.  
  1340.  
  1341. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  1342.  
  1343. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  1344.  
  1345. // let cid = 0;
  1346.  
  1347. let mousemoveFn = null;
  1348. let mousemoveDT = 0;
  1349. let mousemoveCount = 0;
  1350. // let qv = false;
  1351. const cif = () => {
  1352. if (!mousemoveFn) return;
  1353. const ct = Date.now();
  1354. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  1355. mousemoveFn && mousemoveFn();
  1356. }
  1357. mousemoveFn = null;
  1358. };
  1359. let mousemoveCId = 0;
  1360. let mouseoverFn = null;
  1361. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  1362. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  1363. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  1364. const bt = `${b}`;
  1365. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  1366. b[`__$$${a}$$1926__`] = true;
  1367. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  1368. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  1369. // console.log(3928, a, this[`__$$${a}$$1937__`])
  1370. if (!this[`__$$${a}$$1938__`]) {
  1371. this[`__$$${a}$$1938__`] = b;
  1372. if (a === 'mousemove') {
  1373. this.addEventListener4882('mouseenter', (evt) => {
  1374. if (mousemoveCId) return;
  1375. mousemoveCId = setIntervalX0(cif, 380);
  1376. });
  1377. this.addEventListener4882('mouseleave', (evt) => {
  1378. clearIntervalX0(mousemoveCId);
  1379. mousemoveCId = 0;
  1380. });
  1381. }
  1382. this.addEventListener4882(a, (evt) => {
  1383. const evt_ = evt;
  1384. if (!this[`__$$${a}$$1937__`]) return;
  1385. if (!this[`__$$${a}$$1938__`]) return;
  1386. if (a === 'mousemove') {
  1387. mouseoverFn && mouseoverFn();
  1388. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  1389. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  1390. } else {
  1391. mousemoveCount = 0;
  1392. }
  1393. const f = mousemoveFn = () => {
  1394. if (f !== mousemoveFn) return;
  1395. mousemoveFn = null;
  1396. this[`__$$${a}$$1938__`](evt_);
  1397. };
  1398. if (mousemoveCount <= 1) mousemoveFn();
  1399. } else {
  1400. if (a === 'mouseout' || a === 'mouseleave') {
  1401. mousemoveFn = null;
  1402. mousemoveDT = 0;
  1403. mousemoveCount = 0;
  1404. this[`__$$${a}$$1938__`](evt_);
  1405. mouseoverFn && mouseoverFn();
  1406. } else { // mouseover, mouseenter
  1407. mousemoveFn = null;
  1408. mousemoveDT = 0;
  1409. mousemoveCount = 0;
  1410. mouseoverFn && mouseoverFn(); // just in case
  1411. const f = mouseoverFn = () => {
  1412. if (f !== mouseoverFn) return;
  1413. mouseoverFn = null;
  1414. this[`__$$${a}$$1938__`](evt_);
  1415. }
  1416. nextBrowserTick_(mouseoverFn);
  1417. }
  1418. }
  1419. }, c);
  1420.  
  1421.  
  1422. return;
  1423. } else {
  1424.  
  1425. return;
  1426. }
  1427. }
  1428.  
  1429. }
  1430. return this.addEventListener4882(a, b, c)
  1431. }
  1432.  
  1433.  
  1434.  
  1435.  
  1436. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  1437. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  1438. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  1439.  
  1440. if (b[`__$$${a}$$1926__`]) {
  1441. b[`__$$${a}$$1926__`] = false;
  1442.  
  1443. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  1444.  
  1445. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  1446.  
  1447. return;
  1448.  
  1449. }
  1450.  
  1451. }
  1452. return this.removeEventListener4882(a, b, c)
  1453. }
  1454.  
  1455.  
  1456. })();
  1457.  
  1458.  
  1459. FIX_DOM_IF_REPEAT && (() => {
  1460. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  1461. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  1462. // Be careful of the mixture of polymer functions and native Element functions
  1463. // Be careful of the coding design is different with the modern Yt elements
  1464.  
  1465.  
  1466. /*
  1467.  
  1468.  
  1469. function Ks(a, b, c) {
  1470. if (kj && !BOa(a))
  1471. throw Error("strictTemplatePolicy: template owner not trusted");
  1472. c = c || {};
  1473. if (a.__templatizeOwner)
  1474. throw Error("A <template> can only be templatized once");
  1475. a.__templatizeOwner = b;
  1476. var d = (b ? b.constructor : Js)._parseTemplate(a)
  1477. , e = d.templatizeInstanceClass;
  1478. e || (e = COa(a, d, c),
  1479. d.templatizeInstanceClass = e);
  1480. var g = BOa(a);
  1481. EOa(a, d, c, g);
  1482. c = function() {
  1483. return e.apply(this, arguments) || this
  1484. }
  1485. ;
  1486. h(c, e);
  1487. c.prototype._methodHost = g;
  1488. c.prototype.__dataHost = a;
  1489. c.prototype.__templatizeOwner = b;
  1490. c.prototype.__hostProps = d.hostProps;
  1491. return c
  1492. }
  1493.  
  1494. */
  1495.  
  1496. // Polymer.enqueueDebouncer
  1497.  
  1498. const s81 = Symbol();
  1499. const s83 = Symbol();
  1500. const s84 = Symbol();
  1501. const s85 = Symbol();
  1502. const s85b = Symbol();
  1503. const s85c = Symbol();
  1504.  
  1505. let renderDebounceTs = null;
  1506.  
  1507. let renderDebouncePromise = null;
  1508. let qp;
  1509.  
  1510. let cme = 0;
  1511.  
  1512. const shadyFlushMO = new MutationObserver(() => {
  1513.  
  1514. if (!renderDebounceTs) return;
  1515.  
  1516. if (renderDebounceTs.size > 0) {
  1517. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  1518. try {
  1519. Polymer.flush();
  1520. return;
  1521. } catch (e) { }
  1522. }
  1523.  
  1524. renderDebouncePromise && Promise.resolve().then(() => {
  1525.  
  1526. if (renderDebouncePromise) {
  1527. renderDebouncePromise && renderDebouncePromise.resolve();
  1528. renderDebouncePromise = null;
  1529. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  1530. }
  1531.  
  1532. });
  1533.  
  1534. // Polymer.flush
  1535.  
  1536. window.ShadyDOM && ShadyDOM.flush();
  1537. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  1538.  
  1539.  
  1540. });
  1541.  
  1542. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  1543.  
  1544. const observablePromise = (proc, timeoutPromise) => {
  1545. let promise = null;
  1546. return {
  1547. obtain() {
  1548. if (!promise) {
  1549. promise = new Promise(resolve => {
  1550. let mo = null;
  1551. const f = () => {
  1552. let t = proc();
  1553. if (t) {
  1554. mo.disconnect();
  1555. mo.takeRecords();
  1556. mo = null;
  1557. resolve(t);
  1558. }
  1559. }
  1560. mo = new MutationObserver(f);
  1561. mo.observe(document, { subtree: true, childList: true })
  1562. f();
  1563. timeoutPromise && timeoutPromise.then(() => {
  1564. resolve(null)
  1565. });
  1566. });
  1567. }
  1568. return promise
  1569. }
  1570. }
  1571. }
  1572.  
  1573.  
  1574. let p = 0;
  1575. qp = observablePromise(() => {
  1576. if (!(p & 1)) {
  1577.  
  1578. if (window.ShadyDOM && ShadyDOM.flush) {
  1579. p |= 1;
  1580. if (!ShadyDOM.flush847) {
  1581.  
  1582. ShadyDOM.flush847 = ShadyDOM.flush;
  1583. ShadyDOM.flush = function () {
  1584.  
  1585. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  1586. renderDebouncePromise && Promise.resolve().then(() => {
  1587. if (renderDebouncePromise) {
  1588.  
  1589. renderDebouncePromise && renderDebouncePromise.resolve();
  1590. renderDebouncePromise = null;
  1591.  
  1592. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  1593.  
  1594. }
  1595.  
  1596. });
  1597. let r = this.flush847(...arguments);
  1598. if (r) {
  1599. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1600. }
  1601. return r
  1602. }
  1603.  
  1604. }
  1605. }
  1606. }
  1607.  
  1608. if (!(p & 2)) {
  1609.  
  1610. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  1611. p |= 2;
  1612. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  1613. if (!ScopingShim.flush848) {
  1614.  
  1615. ScopingShim.flush848 = ScopingShim.flush;
  1616. ScopingShim.flush = function () {
  1617.  
  1618. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  1619.  
  1620. renderDebouncePromise && Promise.resolve().then(() => {
  1621.  
  1622. if (renderDebouncePromise) {
  1623.  
  1624. renderDebouncePromise && renderDebouncePromise.resolve();
  1625. renderDebouncePromise = null;
  1626.  
  1627. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  1628.  
  1629.  
  1630.  
  1631. }
  1632.  
  1633. });
  1634. return this.flush848(...arguments);
  1635. }
  1636.  
  1637. }
  1638. }
  1639. }
  1640. if (p === 3) {
  1641. p |= 8;
  1642.  
  1643. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  1644. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  1645. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  1646.  
  1647. if (r) {
  1648. let w = Set.prototype.add;
  1649. let u = null;
  1650. Set.prototype.add = function () {
  1651. u = this;
  1652. throw new Error();
  1653. }
  1654. try {
  1655. Polymer.enqueueDebouncer()
  1656. } catch (e) { }
  1657. Set.prototype.add = w;
  1658. if (u !== null) {
  1659. renderDebounceTs = u;
  1660. if (DEBUG_renderDebounceTs) {
  1661. renderDebounceTs.add58438 = renderDebounceTs.add;
  1662. renderDebounceTs.add = function () {
  1663. console.log('renderDebounceTs.add')
  1664. console.log(traceStack((new Error()).stack))
  1665. // debugger;
  1666. return this.add58438(...arguments)
  1667. }
  1668.  
  1669. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  1670. renderDebounceTs.delete = function () {
  1671. console.log('renderDebounceTs.delete')
  1672. const stack = `${(new Error()).stack}`
  1673. let isCallbackRemoval = false;
  1674. if (stack) {
  1675. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  1676. const s = t.split(':');
  1677. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  1678. isCallbackRemoval = true;
  1679. }
  1680. }
  1681. if (isCallbackRemoval) {
  1682. return this.delete58438(...arguments)
  1683. }
  1684. console.log(traceStack((new Error()).stack))
  1685. // debugger;
  1686. return this.delete58438(...arguments)
  1687. }
  1688. }
  1689. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  1690. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  1691. }
  1692. }
  1693.  
  1694. return true;
  1695. }
  1696. })
  1697.  
  1698. // if(window.ShadyDOM && ShadyDOM.flush){
  1699. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  1700.  
  1701. // }
  1702. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  1703.  
  1704. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  1705. // }
  1706.  
  1707. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  1708.  
  1709. }
  1710.  
  1711. Object.defineProperty(Object.prototype, '_lastIf', {
  1712. get() {
  1713. return this[s81];
  1714. },
  1715. set(nv) {
  1716. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  1717. // DOM-IF initialization
  1718. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  1719.  
  1720. this.__xiWB8__ = 2;
  1721.  
  1722. const cProto = this.__proto__;
  1723. if (cProto && !cProto.__xiWB7__) {
  1724. cProto.__xiWB7__ = 1;
  1725.  
  1726. // dom-if __template
  1727. // dom-repeat template
  1728. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  1729. cProto.__template847 = true;
  1730. try {
  1731. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  1732. Object.defineProperty(cProto, '__template', {
  1733. get() {
  1734. const v = this[s84];
  1735. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  1736. },
  1737. set(nv) {
  1738. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  1739. this[s84] = nv;
  1740. return true;
  1741. }
  1742. });
  1743. } catch (e) {
  1744. console.warn(e);
  1745. }
  1746.  
  1747. console.log('FIX_DOM_IF - __template')
  1748. }
  1749.  
  1750. // dom-if __ensureTemplate
  1751. // dom-repeat __ensureTemplatized
  1752. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  1753. // note that "_templateInfo" diffs the different version of DOM-IF
  1754.  
  1755. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  1756. cProto.__ensureTemplate = function () {
  1757. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  1758. if (!this.__template) {
  1759. let b;
  1760. if (this._templateInfo) {
  1761. b = this;
  1762. } else {
  1763. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  1764. b = this.__templateCollection011__[0];
  1765. if (!b) {
  1766. let a = mWeakRef(this);
  1767. let c = new MutationObserver(function () {
  1768. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  1769. if (c && a) {
  1770. c.disconnect();
  1771. a = kRef(a);
  1772. a && a.__render();
  1773. a && (a.__templateCollection011__ = null);
  1774. }
  1775. c = null;
  1776. a = null;
  1777. });
  1778. c && c.observe(this, {
  1779. childList: !0
  1780. });
  1781. return !1
  1782. } else {
  1783. this.__templateCollection011__ = null;
  1784. }
  1785. }
  1786. this.__template = b
  1787. }
  1788. return !0
  1789. }
  1790.  
  1791. console.log('FIX_DOM_IF - __ensureTemplate')
  1792.  
  1793. }
  1794.  
  1795.  
  1796. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  1797.  
  1798. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  1799.  
  1800. // cProto.__createAndInsertInstance = function (a) {
  1801. // Promise.resolve().then(()=>{
  1802. // console.log('__createAndInsertInstance')
  1803. // window.lm5 = window.lm5 || [];
  1804. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  1805. // });
  1806. // return this.__createAndInsertInstance847(a);
  1807. // }
  1808.  
  1809. // }
  1810.  
  1811.  
  1812. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  1813.  
  1814. // cProto._bindTemplate847 = cProto._bindTemplate;
  1815.  
  1816. // cProto._bindTemplate = function (a, b) {
  1817. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  1818. // }
  1819.  
  1820. // }
  1821. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  1822.  
  1823. // cProto._stampTemplate847 = cProto._stampTemplate;
  1824.  
  1825. // cProto._stampTemplate = function (a, b) {
  1826. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  1827. // }
  1828.  
  1829. // }
  1830. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  1831. }
  1832.  
  1833.  
  1834. // need to fix __observeEffects
  1835. // this.__observeEffects.if[0].info.method === this.__debounceRender
  1836. const f = () => {
  1837.  
  1838. const __observeEffects = this.__observeEffects;
  1839.  
  1840. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  1841. for (const effect of __observeEffects.if) {
  1842. const info = effect.info;
  1843. if (info && typeof info.method === 'function') {
  1844.  
  1845. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  1846. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  1847. }
  1848.  
  1849. }
  1850. }
  1851. }
  1852.  
  1853.  
  1854. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  1855. for (const effect of __observeEffects.restamp) {
  1856. const info = effect.info;
  1857. if (info && typeof info.method === 'function') {
  1858.  
  1859. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  1860. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  1861. }
  1862.  
  1863. }
  1864. }
  1865. }
  1866.  
  1867. // console.log(5881, this.__observeEffects)
  1868. }
  1869. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  1870. f();
  1871. Promise.resolve().then(f);
  1872. // afterward, don't care adding fn directly (the fn is already modified)
  1873. }
  1874.  
  1875. }
  1876. this[s81] = nv;
  1877. return true;
  1878. }
  1879. });
  1880.  
  1881.  
  1882. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  1883. get() {
  1884. return this[s85];
  1885. },
  1886. set(nv) {
  1887. if (nv === null && this[s85] === undefined) {
  1888. // DOM-IF / DOM-REPEAT initialization
  1889.  
  1890.  
  1891. const cProto = this.__proto__;
  1892. if (qp) {
  1893. qp.obtain();
  1894. qp = null;
  1895. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  1896. }
  1897. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  1898.  
  1899. cProto.__debounceRender847 = cProto.__debounceRender;
  1900.  
  1901. if (cProto.__debounceRender.length === 2) {
  1902.  
  1903. cProto.__debounceRender = function (a, b) {
  1904.  
  1905. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  1906.  
  1907. b = b === void 0 ? 0 : b;
  1908.  
  1909. /*
  1910. b = b === void 0 ? 0 : b;
  1911. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  1912. vs(this.__renderDebouncer)
  1913. */
  1914.  
  1915. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1916.  
  1917. if (!renderDebouncePromise) {
  1918. renderDebouncePromise = new PromiseExternal();
  1919. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1920. }
  1921.  
  1922. renderDebouncePromise.then(async () => {
  1923. if (b > 0) await delayPn(b);
  1924.  
  1925. const f = this.__dsIRYqw1__;
  1926. if (f === cme) return;
  1927. this.__dsIRYqw1__ = cme;
  1928. a.call(this);
  1929. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  1930.  
  1931. });
  1932.  
  1933. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  1934. }
  1935.  
  1936. } else if (cProto.__debounceRender.length === 0) {
  1937.  
  1938.  
  1939. cProto.__debounceRender = function () {
  1940.  
  1941. if (!renderDebounceTs) return this.__debounceRender847();
  1942.  
  1943. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1944. /*
  1945. var a = this;
  1946. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  1947. return a.__render()
  1948. });
  1949. vs(this.__renderDebouncer)
  1950. */
  1951.  
  1952. if (!renderDebouncePromise) {
  1953. renderDebouncePromise = new PromiseExternal();
  1954. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1955. }
  1956. renderDebouncePromise.then(() => {
  1957. const f = this.__dsIRYqw1__;
  1958. if (f === cme) return;
  1959. this.__dsIRYqw1__ = cme;
  1960. this.__render()
  1961. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  1962. });
  1963. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  1964.  
  1965.  
  1966. }
  1967. }
  1968. }
  1969.  
  1970.  
  1971.  
  1972. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  1973. // cProto.render847 = cProto.render;
  1974. // cProto.render = function(){
  1975.  
  1976. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1977. // try{
  1978. // this.render847();
  1979. // }catch(e){}
  1980. // // if(this.__DBR847__){
  1981. // // this.__DBR847__.resolve();
  1982. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  1983. // // }
  1984.  
  1985. // // renderDebouncePromise && renderDebouncePromise.resolve()
  1986. // // renderDebouncePromise = null;
  1987. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  1988.  
  1989. // }
  1990. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  1991. // }
  1992.  
  1993. }
  1994. this[s85] = nv;
  1995. return true;
  1996. }
  1997. });
  1998.  
  1999. // PS-DOM-REPEAT
  2000.  
  2001. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  2002. get() {
  2003. return this[s85b];
  2004. },
  2005. set(nv) {
  2006.  
  2007. this[s85b] = nv;
  2008. return true;
  2009. }
  2010. })
  2011.  
  2012. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  2013. get() {
  2014. return this[s85c];
  2015. },
  2016. set(nv) {
  2017.  
  2018. this[s85c] = nv;
  2019. return true;
  2020. }
  2021. })
  2022.  
  2023.  
  2024. })();
  2025.  
  2026. const setupXdeadC = (cnt)=>{
  2027.  
  2028. let xdeadc = xdeadc00;
  2029. if(!xdeadc){
  2030. setupSDomWrapper(); // just in case
  2031. const hostElement = cnt.hostElement;
  2032. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2033. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2034. hostElement.lastChild.replaceWith(el);
  2035. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2036. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2037. el.firstElementChild.id = rid;
  2038. cnt.$[rid] = el.firstElementChild;
  2039. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2040.  
  2041. xdeadc = cnt.getStampContainer_(rid);
  2042. el.remove();
  2043. xdeadc00 = xdeadc;
  2044. // console.log(xdeadc.__domApi)
  2045. // debugger;
  2046. // const xdeadv = xdeadc.__domApi;
  2047. }
  2048.  
  2049. let xlivec = xlivec00;
  2050. if(!xlivec){
  2051. setupSDomWrapper(); // just in case
  2052. const hostElement = cnt.hostElement;
  2053. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2054. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2055. hostElement.lastChild.replaceWith(el);
  2056. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2057. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2058. el.firstElementChild.id = rid;
  2059. cnt.$[rid] = el.firstElementChild;
  2060. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2061.  
  2062. xlivec = cnt.getStampContainer_(rid);
  2063. xlivec00 = xlivec;
  2064. // console.log(xdeadc.__domApi)
  2065. // debugger;
  2066. // const xdeadv = xdeadc.__domApi;
  2067. }
  2068.  
  2069. return xdeadc00;
  2070. }
  2071.  
  2072. let standardWrap_ = null;
  2073.  
  2074. const setupSDomWrapper = () => {
  2075.  
  2076. const sdwProto = ShadyDOM.Wrapper.prototype;
  2077.  
  2078. if (sdwProto.__pseudo__isConnected__ !== null) {
  2079. sdwProto.__pseudo__isConnected__ = null;
  2080. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  2081. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  2082. const get = isConnectedPd.get;
  2083. isConnectedPd.get = function () {
  2084. const pseudoVal = this.__pseudo__isConnected__;
  2085. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  2086. }
  2087. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  2088. }
  2089.  
  2090. // debugger;
  2091. // new xdeadc.__domApi.constructor(document.createElement('div'));
  2092. }
  2093.  
  2094. }
  2095.  
  2096. let domApiConstructor = null;
  2097. const setupDomApi = (daProto) => {
  2098.  
  2099. daProto.__daHook377__ = true;
  2100.  
  2101. domApiConstructor = daProto.constructor; // TBC
  2102.  
  2103. // TBC
  2104.  
  2105. }
  2106.  
  2107.  
  2108. // WEAKREF_ShadyDOM
  2109.  
  2110. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  2111.  
  2112. const setupPlainShadyDOM = (b) => {
  2113. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  2114. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  2115. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  2116. b.patchOnDemand = true;
  2117. b.preferPerformance = true;
  2118. b.noPatch = true;
  2119. }
  2120.  
  2121. const isPlainObject = (b, m) => {
  2122. if (!b || typeof b !== 'object') return false;
  2123. const e = Object.getOwnPropertyDescriptors(b);
  2124. if (e.length <= m) return false;
  2125. let pr = 0;
  2126. for (const k in e) {
  2127. const d = e[k];
  2128. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  2129. if (!('value' in d) || typeof d.value === 'function') return false;
  2130. pr++;
  2131. }
  2132. return pr > m;
  2133. }
  2134.  
  2135. let b;
  2136.  
  2137. let lz = 0;
  2138.  
  2139. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  2140. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  2141.  
  2142. // Brave - ShadyDOM exists before userscripting
  2143. b = sdp.value;
  2144.  
  2145. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  2146. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  2147. lz = 1;
  2148. }
  2149.  
  2150. }
  2151.  
  2152.  
  2153. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  2154. } else if (!sdp) {
  2155. } else {
  2156. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  2157. return;
  2158. }
  2159.  
  2160. const shadyDOMNodeWRM = new WeakMap();
  2161.  
  2162. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  2163.  
  2164. const selfWrKey = Symbol();
  2165.  
  2166. const weakWrapperNodeHandlerFn = () => ({
  2167. get() {
  2168. const wv = this[selfWrKey];
  2169. if (typeof wv === 'undefined') return undefined;
  2170. let node = kRef(wv);
  2171. if (!node) this[selfWrKey] = undefined;
  2172. return node || undefined;
  2173. },
  2174. set(nv) {
  2175. const wv = (nv[selfWrKey] || (nv[selfWrKey] = mWeakRef(nv)));
  2176. this[selfWrKey] = wv;
  2177. return true;
  2178. },
  2179. enumerable: true,
  2180. configurable: true
  2181. });
  2182.  
  2183.  
  2184. function weakWrapper(_ShadyDOM) {
  2185. const ShadyDOM = _ShadyDOM;
  2186. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  2187. let nullElement = { node: null };
  2188. Object.setPrototypeOf(nullElement, Element.prototype);
  2189. let p = new ShadyDOM.Wrapper(nullElement);
  2190. let d = Object.getOwnPropertyDescriptor(p, 'node');
  2191. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  2192. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  2193. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  2194. }
  2195.  
  2196. }
  2197. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  2198. try {
  2199. setupSDomWrapper();
  2200. } catch (e) { }
  2201. }
  2202.  
  2203. }
  2204.  
  2205. let previousWrapStore = null;
  2206.  
  2207. const standardWrap = function (a) {
  2208. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  2209. if (previousWrapStore) {
  2210. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  2211. if (s) {
  2212. previousWrapStore.delete(a);
  2213. shadyDOMNodeWRM.set(a, mWeakRef(s));
  2214. }
  2215. }
  2216. let u = kRef(shadyDOMNodeWRM.get(a));
  2217. if (!u) {
  2218. u = new ShadyDOM.Wrapper(a);
  2219. shadyDOMNodeWRM.set(a, mWeakRef(u));
  2220. }
  2221. return u;
  2222. }
  2223.  
  2224. standardWrap_ = standardWrap;
  2225.  
  2226.  
  2227. function setupWrapFunc(_ShadyDOM) {
  2228. const ShadyDOM = _ShadyDOM;
  2229.  
  2230.  
  2231. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  2232. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  2233. return;
  2234. }
  2235. let mm = new Set();
  2236. const pget = wmPD.value;
  2237. WeakMap.prototype.get = function (a) {
  2238. mm.add(this);
  2239. return a;
  2240. }
  2241. try {
  2242. let nullElement = { node: null };
  2243. Object.setPrototypeOf(nullElement, Element.prototype);
  2244. ShadyDOM.wrapIfNeeded(nullElement)
  2245. ShadyDOM.wrap(nullElement)
  2246. } catch (e) { }
  2247. WeakMap.prototype.get = pget;
  2248. if (mm.size !== 1) {
  2249. mm.clear();
  2250. return;
  2251. }
  2252. const p = mm.values().next().value;
  2253. if (!(p instanceof WeakMap)) return;
  2254. // p.clear();
  2255. // p.get = function (a) { return a }
  2256. // p.set = function (a, b) { return this }
  2257. // console.log(188, window.n2n = mm, window.n2p = p)
  2258.  
  2259. // console.log(34929,p.size)
  2260. previousWrapStore = p;
  2261.  
  2262. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  2263. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  2264. }
  2265. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  2266. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  2267. }
  2268.  
  2269. }
  2270.  
  2271. function setupLZ3(nv) {
  2272.  
  2273. const ShadyDOM = nv;
  2274.  
  2275. const ShadyDOMSettings = ShadyDOM.settings;
  2276. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2277. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2278. return false;
  2279. }
  2280.  
  2281. weakWrapper(ShadyDOM);
  2282.  
  2283. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  2284.  
  2285. setupPlainShadyDOM(ShadyDOMSettings);
  2286. setupPlainShadyDOM(ShadyDOM);
  2287.  
  2288. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  2289.  
  2290. setupWrapFunc(ShadyDOM);
  2291. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  2292. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  2293.  
  2294. // To be confirmed
  2295. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  2296. ShadyDOM.composedPath = function (e) {
  2297. const t = (e || 0).target || null;
  2298. if (!(t instanceof HTMLElement_)) {
  2299. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  2300. }
  2301. return t instanceof HTMLElement_ ? [t] : [];
  2302. };
  2303. }
  2304.  
  2305. }
  2306.  
  2307. }
  2308.  
  2309.  
  2310. function setupLZ6(nv) {
  2311.  
  2312. const ShadyDOM = nv;
  2313.  
  2314. const ShadyDOMSettings = ShadyDOM.settings;
  2315.  
  2316. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2317. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2318. return false;
  2319. }
  2320.  
  2321. weakWrapper(ShadyDOM);
  2322.  
  2323. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  2324.  
  2325. setupPlainShadyDOM(ShadyDOMSettings);
  2326. setupPlainShadyDOM(ShadyDOM);
  2327.  
  2328. setupWrapFunc(ShadyDOM);
  2329.  
  2330. }
  2331.  
  2332. }
  2333.  
  2334. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  2335.  
  2336. const nv = b;
  2337.  
  2338. if (setupLZ6(nv) === false) return;
  2339.  
  2340. lz = 6;
  2341.  
  2342. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  2343.  
  2344. return;
  2345. }
  2346.  
  2347. delete window.ShadyDOM;
  2348.  
  2349. Object.defineProperty(window, 'ShadyDOM', {
  2350. get() {
  2351. return b;
  2352. },
  2353. set(nv) {
  2354. let ret = 0;
  2355. try {
  2356. do {
  2357. if (!nv || !nv.settings) {
  2358. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  2359. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  2360. lz = 1;
  2361. break;
  2362. } else {
  2363. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  2364. break;
  2365. }
  2366. }
  2367.  
  2368. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  2369. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  2370. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  2371. break;
  2372. }
  2373.  
  2374. if (setupLZ3(nv) === false) break;
  2375.  
  2376. lz = 3;
  2377.  
  2378. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  2379.  
  2380. ret = 1;
  2381.  
  2382. } while (0);
  2383. } catch (e) {
  2384. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  2385. }
  2386.  
  2387. if (!ret) b = nv;
  2388. else {
  2389. delete this.ShadyDOM;
  2390. this.ShadyDOM = nv;
  2391. }
  2392. return true;
  2393. },
  2394. enumerable: false,
  2395. configurable: true
  2396. });
  2397.  
  2398. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  2399.  
  2400. if (ENABLE_ASYNC_DISPATCHEVENT) {
  2401. const filter = new Set([
  2402. 'yt-action',
  2403. // 'iframe-src-replaced',
  2404. 'shown-items-changed',
  2405. 'can-show-more-changed', 'collapsed-changed',
  2406.  
  2407. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  2408. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  2409. 'yt-navigate-finish',
  2410.  
  2411. // 'data-changed','yt-watch-comments-ready'
  2412. ])
  2413. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  2414. EventTarget.prototype.dispatchEvent = function (event) {
  2415. const type = (event || 0).type;
  2416. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  2417. if (!filter.has(type) && !type.endsWith('-changed')) {
  2418. if (this instanceof Node || this instanceof Window) {
  2419. nextBrowserTick_(() => this.dispatchEvent938(event));
  2420. return true;
  2421. }
  2422. }
  2423. }
  2424. return this.dispatchEvent938(event);
  2425. }
  2426. }
  2427.  
  2428. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  2429. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  2430. // const xhr = new XMLHttpRequest;
  2431. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  2432. if (!pdOri || pdOri.configurable !== true) return;
  2433. let propNeedles = null;
  2434. const pdNew = {
  2435. configurable: true,
  2436. enumerable: true,
  2437. get: function () {
  2438. propNeedles = this;
  2439. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  2440. throw new Error();
  2441. }
  2442. }
  2443. Object.defineProperty(Map.prototype, 'size', pdNew);
  2444. try {
  2445. XMLHttpRequest.prototype.open.call(0);
  2446. // xhr.open.call(null)
  2447. } catch (e) { }
  2448. Object.defineProperty(Map.prototype, 'size', pdOri);
  2449. if (!propNeedles) return;
  2450. const entries = [...propNeedles.entries()];
  2451. propNeedles.clear();
  2452. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  2453. })();
  2454.  
  2455. if (FIX_XHR_REQUESTING) {
  2456.  
  2457. const URL = window.URL || new Function('return URL')();
  2458. const createObjectURL = URL.createObjectURL.bind(URL);
  2459.  
  2460. XMLHttpRequest = (() => {
  2461. const XMLHttpRequest_ = XMLHttpRequest;
  2462. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  2463. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  2464. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  2465. constructor(...args) {
  2466. super(...args);
  2467. }
  2468. open(method, url, ...args) {
  2469. let skip = false;
  2470. if (!url || typeof url !== 'string') skip = true;
  2471. else if (typeof url === 'string') {
  2472. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  2473. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  2474. skip = true;
  2475. } else if (turl.includes('.youtube.com/pagead/')) {
  2476. skip = true;
  2477. } else if (turl.includes('.youtube.com/ptracking')) {
  2478. skip = true;
  2479. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  2480. skip = true;
  2481. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  2482. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  2483. skip = true;
  2484. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  2485. skip = true;
  2486. } else {
  2487. // skip = true; // for user activity logging e.g. watched videos
  2488. }
  2489. } else if (turl.includes('play.google.com/log')) {
  2490. skip = true;
  2491. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  2492. skip = true;
  2493. }
  2494. }
  2495. if (!skip) {
  2496. this.__xmMc8__ = 1;
  2497. return super.open(method, url, ...args);
  2498. } else {
  2499. this.__xmMc8__ = 2;
  2500. return super.open('GET', url0);
  2501. }
  2502. }
  2503. send(...args) {
  2504. if (this.__xmMc8__ === 1) {
  2505. return super.send(...args);
  2506. } else if (this.__xmMc8__ === 2) {
  2507. return super.send();
  2508. } else {
  2509. console.log('[yt-js-engine-tamer]', 'xhr warning');
  2510. return super.send(...args);
  2511. }
  2512. }
  2513. }
  2514. c.prototype.__xmMc8__ = 0;
  2515. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  2516. return c;
  2517. })();
  2518. }
  2519.  
  2520. // Alternative HACK -> Tabview Youtube
  2521. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  2522.  
  2523. // ---- << this.overscrollConfig HACK >> -----
  2524.  
  2525. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  2526.  
  2527. /*
  2528.  
  2529. ;function gZb(a, b) {
  2530. b = void 0 === b ? !0 : b;
  2531. a.addEventListener("wheel", hZb);
  2532. a.overscrollConfig = {
  2533. cooldown: b
  2534. }
  2535. }
  2536. function iZb(a) {
  2537. a.overscrollConfig = void 0;
  2538. a.removeEventListener("wheel", hZb)
  2539. }
  2540. function hZb(a) {
  2541. var b = a.deltaY
  2542. , c = a.target
  2543. , d = null;
  2544. if (window.Polymer && window.Polymer.Element) {
  2545. if (c = a.path || a.composedPath && a.composedPath()) {
  2546. c = g(c);
  2547. for (var e = c.next(); !e.done && (e = e.value,
  2548. !jZb(e, b)); e = c.next())
  2549. if (e.overscrollConfig) {
  2550. d = e;
  2551. break
  2552. }
  2553. }
  2554. } else
  2555. for (; c && !jZb(c, b); ) {
  2556. if (c.overscrollConfig) {
  2557. d = c;
  2558. break
  2559. }
  2560. c = c.parentElement
  2561. }
  2562. d && (b = d.overscrollConfig,
  2563. b.cooldown ? (d = a.deltaY,
  2564. c = b.lastDeltaY || 0,
  2565. b.lastDeltaY = d,
  2566. e = b.lastStopped || 0,
  2567. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  2568. c = !1) : (d = e + 600,
  2569. c = !0) : (d = Date.now() + 600,
  2570. c = !0),
  2571. d > Date.now() && (a.preventDefault(),
  2572. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  2573. }
  2574. */
  2575.  
  2576. let wheelHandler = function (a) {
  2577. if (window.Polymer && window.Polymer.Element) {
  2578. let c;
  2579. if (c = a.path || a.composedPath && a.composedPath()) {
  2580. for (const e of c) {
  2581. const cnt = insp(e);
  2582. if (e.overscrollConfig) e.overscrollConfig = void 0;
  2583. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  2584. }
  2585. }
  2586. } else {
  2587. let e = a.target;
  2588. for (; e instanceof Element; e = e.parentElement) {
  2589. const cnt = insp(e);
  2590. if (e.overscrollConfig) e.overscrollConfig = void 0;
  2591. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  2592. }
  2593. }
  2594. };
  2595.  
  2596. let checkWheelListenerObjs = null;
  2597.  
  2598. let getObjsFn = () => {
  2599. let euyVal = 0;
  2600. const eukElm = {};
  2601. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  2602. const euzObj = new Proxy(eukElm, {
  2603. get(target, prop) {
  2604. throw `ErrorF31.get(${prop})`
  2605. },
  2606. set(target, prop, value) {
  2607. throw `ErrorF33.set(${prop}, ${value})`
  2608. }
  2609. });
  2610. const euxElm = new Proxy(eukElm, {
  2611. get(target, prop) {
  2612. if (prop === 'scrollTop') {
  2613. euyVal = euyVal | 8;
  2614. return 0;
  2615. }
  2616. if (prop === 'overscrollConfig') {
  2617. euyVal = euyVal | 16;
  2618. return void 0;
  2619. }
  2620. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  2621. return 640;
  2622. }
  2623. if (prop === 'scrollLeft') {
  2624. euyVal = euyVal | 8;
  2625. return 0;
  2626. }
  2627. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  2628. return 800;
  2629. }
  2630. throw `ErrorF45.get(${prop})`
  2631. },
  2632. set(target, prop, value) {
  2633. throw `ErrorF47.set(${prop}, ${value})`
  2634. }
  2635. });
  2636. const eukEvt = {};
  2637. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  2638. const euyEvt = new Proxy(eukEvt, {
  2639. get(target, prop) {
  2640. if (prop === 'deltaY' || prop === 'deltaX') {
  2641. euyVal = euyVal | 1;
  2642. return -999;
  2643. }
  2644. if (prop === 'target') {
  2645. euyVal = euyVal | 2;
  2646. return euxElm
  2647. }
  2648. if (prop === 'path' || prop === 'composedPath') {
  2649. euyVal = euyVal | 2;
  2650. return [euxElm]
  2651. }
  2652. throw `ErrorF51.get(${prop})`
  2653. },
  2654. set(target, prop, value) {
  2655. throw `ErrorF53.set(${prop}, ${value})`
  2656. }
  2657. });
  2658. const setVal = (v) => {
  2659. euyVal = v;
  2660. }
  2661. const getVal = () => {
  2662. return euyVal;
  2663. }
  2664. return { euzObj, euyEvt, setVal, getVal };
  2665. }
  2666.  
  2667. let checkWheelListener = (callback) => {
  2668.  
  2669. let callbackIdentifier = '';
  2670.  
  2671. let res = null;
  2672. try {
  2673. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  2674. setVal(0);
  2675. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  2676. throw `RESULT${getVal()}`;
  2677. } catch (e) {
  2678. res = e;
  2679. }
  2680.  
  2681. res = `${res}` || `${null}`;
  2682. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  2683.  
  2684. callbackIdentifier = res;
  2685. if (callbackIdentifier === 'RESULT27') 0;
  2686. else if (callbackIdentifier === 'RESULT0') {
  2687. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  2688. } else if (callbackIdentifier.startsWith('RESULT')) {
  2689. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  2690. }
  2691. return callbackIdentifier;
  2692.  
  2693. };
  2694.  
  2695. let callbackFound = false;
  2696. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  2697. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  2698. // M-youtube-js-engine-tamer.52178
  2699. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  2700. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  2701. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  2702. // RESULTXX / ErrorFXX / Other...
  2703. if (callbackIdentifier === 'RESULT27') {
  2704. this.overscrollConfigDisable = true;
  2705. if (!callbackFound) {
  2706. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  2707. getObjsFn = checkWheelListener = null;
  2708. checkWheelListenerObjs = null;
  2709. wheelHandler = null;
  2710. }
  2711. return void 0;
  2712. } else if (!callbackFound && !this.overscrollConfigDisable) {
  2713. this.overscrollConfigDisable = true;
  2714. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  2715. }
  2716. }
  2717. return this.addEventListener52178(type, callback, option);
  2718. };
  2719.  
  2720. // ---- << this.overscrollConfig HACK >> -----
  2721.  
  2722. }
  2723.  
  2724. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  2725.  
  2726. let p_a_objWR = null;
  2727. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  2728. let ytPageReady = 0;
  2729.  
  2730. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  2731. let isGlobalSpaceControl = true;
  2732. let mediaPlayerElementWR = null;
  2733. let focusedElementAtSelection = null;
  2734.  
  2735. // let want_control_video = false;
  2736.  
  2737. let spaceBarControl_keyG = '';
  2738.  
  2739. let lastUserAction = 0;
  2740.  
  2741. const wmKeyControlPhase = new WeakMap();
  2742.  
  2743. let currentSelectionText = null;
  2744.  
  2745. const getCurrentSelectionText = () => {
  2746. if (currentSelectionText !== null) return currentSelectionText
  2747. return (currentSelectionText = `${getSelection()}`)
  2748. }
  2749.  
  2750. const pageMediaWatcher = () => {
  2751.  
  2752. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  2753. // want_control_video = false;
  2754. // }, { capture: true, passive: true });
  2755.  
  2756. document.addEventListener('yt-navigate', () => {
  2757. ytPageReady = 0;
  2758. });
  2759. document.addEventListener('yt-navigate-start', () => {
  2760. ytPageReady = 0;
  2761. });
  2762. document.addEventListener('yt-navigate-cache', () => {
  2763. ytPageReady = 0;
  2764. });
  2765.  
  2766. document.addEventListener('yt-navigate-finish', () => {
  2767. ytPageReady = 1;
  2768. });
  2769.  
  2770. document.addEventListener('durationchange', () => {
  2771. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  2772. if (elm.duration > 0.01) {
  2773. if (elm.closest('[hidden]')) continue;
  2774. mediaPlayerElementWR = mWeakRef(elm);
  2775. return;
  2776. }
  2777. }
  2778. }, { capture: true, passive: true });
  2779.  
  2780. document.addEventListener('selectionchange', (evt) => {
  2781. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  2782. currentSelectionText = null;
  2783. if (!(evt.target instanceof Node)) return;
  2784. focusedElementAtSelection = evt.target;
  2785. }, { capture: true, passive: true })
  2786.  
  2787. document.addEventListener('pointerdown', (evt) => {
  2788. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2789. }, { capture: true, passive: true });
  2790.  
  2791.  
  2792. document.addEventListener('pointerup', (evt) => {
  2793. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2794. }, { capture: true, passive: true });
  2795.  
  2796.  
  2797. document.addEventListener('keydown', (evt) => {
  2798. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2799. }, { capture: true, passive: true });
  2800.  
  2801. document.addEventListener('keyup', (evt) => {
  2802. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2803. }, { capture: true, passive: true });
  2804.  
  2805. };
  2806.  
  2807.  
  2808. const checkKeyB = (p_a_obj) => {
  2809.  
  2810. const boolList = new Set();
  2811. const p_a_obj_api = p_a_obj.api;
  2812.  
  2813. const nilFunc0 = function () {
  2814. return void 0
  2815. };
  2816. const mt = new Proxy({}, {
  2817. get(target, prop) {
  2818. if (prop === 'get') return nilFunc0;
  2819. return mt;
  2820. }
  2821. });
  2822. const nilFunc = function () {
  2823. return mt
  2824. };
  2825. const mw = new Proxy({}, {
  2826. get(target, prop) {
  2827. if (prop in p_a_obj_api) {
  2828. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  2829. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  2830. if (q && q.value) {
  2831. if (!q.writable) return q.value;
  2832. if (typeof q.value === 'string') return '';
  2833. if (typeof q.value === 'number') return 0;
  2834. if (typeof q.value === 'boolean') return false;
  2835. if (q.value && typeof q.value === 'object') return {};
  2836. }
  2837. }
  2838. return undefined;
  2839. },
  2840. set(target, prop) {
  2841. throw 'mwSet';
  2842. }
  2843. });
  2844.  
  2845. const mq = new Proxy({}, {
  2846. get(target, prop) {
  2847. if (prop === 'api') return mw;
  2848. if (prop in p_a_obj) {
  2849. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  2850. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  2851. if (q && q.value) {
  2852. if (!q.writable) return q.value;
  2853. if (typeof q.value === 'string') return '';
  2854. if (typeof q.value === 'number') return 0;
  2855. if (typeof q.value === 'boolean') return false;
  2856. if (q.value && typeof q.value === 'object') return {};
  2857. }
  2858. }
  2859. return undefined;
  2860. },
  2861. set(target, prop, val) {
  2862. if (typeof val === 'boolean') boolList.add(prop)
  2863. throw `mqSet(${prop},${val})`;
  2864. }
  2865. });
  2866.  
  2867. let res = ''
  2868. try {
  2869. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  2870. } catch (e) {
  2871. res = `ERROR::${e}`;
  2872. }
  2873.  
  2874. if (boolList.size === 1) {
  2875. const value = boolList.values().next().value;
  2876. if (res === `ERROR::mqSet(${value},${true})`) {
  2877. p_a_obj.__uZWaD__ = value;
  2878. }
  2879. }
  2880.  
  2881. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  2882.  
  2883. }
  2884.  
  2885.  
  2886. let pm_p_a = null;
  2887.  
  2888. const p_a_init = function () {
  2889. const r = this.init91();
  2890. const keyBw = this.__cPzfo__ || '__NIL__';
  2891. const p_a_obj = this[keyBw];
  2892. if (!p_a_obj) return;
  2893. try {
  2894. checkKeyB(p_a_obj);
  2895. } catch (e) { }
  2896. p_a_objWR = mWeakRef(p_a_obj);
  2897. if (FIX_SHORTCUTKEYS > 0) {
  2898. if (p_a_obj && !p_a_obj.hVhtg) {
  2899. p_a_obj.hVhtg = 1;
  2900.  
  2901. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  2902. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  2903. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  2904. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  2905. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  2906. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  2907.  
  2908. }
  2909. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  2910. // const api = p_a_obj.api
  2911. // api.hVhtg = 1;
  2912. // api.playVideo91 = api.playVideo;
  2913. // api.playVideo = p_a_jt.playVideo;
  2914. // api.pauseVideo91 = api.pauseVideo;
  2915. // api.pauseVideo = p_a_jt.pauseVideo;
  2916. // }
  2917. }
  2918. if (pm_p_a) {
  2919. pm_p_a.resolve();
  2920. pm_p_a = null;
  2921. }
  2922. return r;
  2923. };
  2924.  
  2925. const p_a_xt = {
  2926.  
  2927. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  2928.  
  2929. if (FIX_SHORTCUTKEYS === 2) {
  2930.  
  2931. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  2932.  
  2933. if (activeElement) {
  2934.  
  2935. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  2936.  
  2937. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  2938. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  2939. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  2940.  
  2941. }
  2942.  
  2943. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  2944. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  2945. // console.log(582, isDelayedSpaceBar)
  2946. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  2947.  
  2948. if (activeElement && (h === 'Space' || h === 'Enter')) {
  2949. const controlPhase = wmKeyControlPhase.get(activeElement);
  2950. if (controlPhase === 4 || controlPhase === 5) return false;
  2951. }
  2952. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  2953. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  2954. // if (!isSpaceKeyImmediate) return false;
  2955. // }
  2956. }
  2957.  
  2958. },
  2959.  
  2960. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  2961.  
  2962. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  2963.  
  2964. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  2965. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  2966. // console.log(583, isDelayedSpaceBar)
  2967. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  2968.  
  2969. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  2970.  
  2971. let mediaWorking = false;
  2972. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  2973. mediaWorking = true;
  2974. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  2975. mediaWorking = true;
  2976. }
  2977. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  2978. mediaWorking && Promise.resolve().then(() => {
  2979. if (activeElement === document.activeElement) {
  2980. return activeElement.blur()
  2981. } else {
  2982. return false
  2983. }
  2984. }).then((r) => {
  2985. r !== false && mediaPlayerElement.focus();
  2986. });
  2987. }
  2988. },
  2989.  
  2990.  
  2991. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  2992.  
  2993. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  2994.  
  2995. const activeElement = document.activeElement;
  2996.  
  2997. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  2998. if (allow === false) return false;
  2999.  
  3000. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3001. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  3002.  
  3003. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3004.  
  3005. return ret;
  3006. },
  3007. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  3008.  
  3009.  
  3010. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3011.  
  3012. const activeElement = document.activeElement;
  3013. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3014. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3015. // }
  3016. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3017. if (allow === false) return false;
  3018.  
  3019. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3020. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  3021.  
  3022. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3023.  
  3024. return ret;
  3025. }
  3026.  
  3027. };
  3028.  
  3029. // const p_a_jt = { // API
  3030.  
  3031. // playVideo(a) { // without spinner effect
  3032.  
  3033. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3034.  
  3035. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3036. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3037. // want_control_video = true;
  3038. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3039. // }
  3040.  
  3041. // }
  3042. // return this.playVideo91(a);
  3043.  
  3044. // },
  3045.  
  3046. // pauseVideo(a) { // without spinner effect
  3047.  
  3048. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3049.  
  3050. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3051. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3052. // want_control_video = true;
  3053. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3054. // }
  3055.  
  3056. // }
  3057. // return this.pauseVideo91(a);
  3058.  
  3059. // }
  3060. // };
  3061.  
  3062. let flagSpeedMaster = null;
  3063. const getSpeedMasterControlFlag = () => {
  3064.  
  3065. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3066. isSpeedMastSpacebarControlEnabled = false;
  3067. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  3068. isSpeedMastSpacebarControlEnabled = true;
  3069. }
  3070. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  3071. isSpeedMastSpacebarControlEnabled = true;
  3072. }
  3073.  
  3074. if (flagSpeedMaster === null) {
  3075. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  3076. if (!p) {
  3077. flagSpeedMaster = false;
  3078. } else {
  3079.  
  3080. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  3081.  
  3082. }
  3083.  
  3084. }
  3085. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  3086.  
  3087. return isSpeedMastSpacebarControlEnabled;
  3088. }
  3089.  
  3090.  
  3091. const getGlobalSpacebarControlFlag = () => {
  3092.  
  3093. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3094. isGlobalSpaceControl = false;
  3095. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  3096. isGlobalSpaceControl = true;
  3097. }
  3098. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  3099. isGlobalSpaceControl = true;
  3100. }
  3101.  
  3102. return isGlobalSpaceControl;
  3103. }
  3104.  
  3105. const keyboardController = async (_yt_player) => {
  3106.  
  3107. const keyQT = getQT(_yt_player);
  3108. const keySV = getSV(_yt_player);
  3109. const keyDX = getDX(_yt_player);
  3110. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  3111.  
  3112. if (!keyDX) return;
  3113. if (keyDX === keyQT || keyDX === keySV) return;
  3114.  
  3115. if (typeof keyDX !== 'string') return;
  3116.  
  3117. let lastAccessKey = '';
  3118. let lastAccessKeyConfirmed = '';
  3119. const mb = new Proxy({}, {
  3120. get(target, prop) {
  3121. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  3122. throw 'mbGet'
  3123. },
  3124. set(target, prop, val) {
  3125. throw 'mbSet'
  3126. }
  3127. });
  3128. const ma = new Proxy({}, {
  3129. get(target, prop) {
  3130. lastAccessKey = prop;
  3131. return mb
  3132. },
  3133. set(target, prop, val) {
  3134. throw 'maSet'
  3135. }
  3136. });
  3137.  
  3138. let keyBw = '';
  3139. try {
  3140. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  3141. } catch (e) {
  3142. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  3143. keyBw = lastAccessKeyConfirmed;
  3144. }
  3145. }
  3146.  
  3147. if (!keyBw) return;
  3148.  
  3149. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  3150.  
  3151. pm_p_a = new PromiseExternal();
  3152.  
  3153. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  3154.  
  3155. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  3156.  
  3157. _yt_player[keyDX].prototype.init = p_a_init;
  3158.  
  3159. await pm_p_a.then();
  3160. const p_a_obj = kRef(p_a_objWR);
  3161.  
  3162. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  3163.  
  3164.  
  3165. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  3166.  
  3167. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  3168.  
  3169. if (!isSpeedMastSpacebarControlEnabled) {
  3170.  
  3171. if (config && config.EXPERIMENT_FLAGS) {
  3172. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  3173. }
  3174. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3175. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  3176. }
  3177.  
  3178. } else {
  3179.  
  3180. if (config && config.EXPERIMENT_FLAGS) {
  3181. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  3182. }
  3183. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3184. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  3185. }
  3186.  
  3187. }
  3188.  
  3189. }
  3190.  
  3191. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  3192.  
  3193.  
  3194.  
  3195.  
  3196. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  3197.  
  3198. // console.log(p_a_obj.handleGlobalKeyUp)
  3199. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  3200.  
  3201. // console.log(p_a_obj.api)
  3202.  
  3203.  
  3204. // QT -> DX(SV) -> p_a
  3205.  
  3206.  
  3207. /*
  3208. *
  3209. *
  3210. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3211. b = void 0 === b ? !1 : b;
  3212. c = void 0 === c ? !1 : c;
  3213. d = void 0 === d ? !1 : d;
  3214. e = void 0 === e ? !1 : e;
  3215. var l = g.PT(this);
  3216. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  3217. }
  3218.  
  3219. */
  3220.  
  3221. /*
  3222. *
  3223. *
  3224. *
  3225. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3226. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  3227. }
  3228.  
  3229. */
  3230.  
  3231.  
  3232. // if(!keyDX) return;
  3233.  
  3234. // console.log(4999, keyDX)
  3235.  
  3236. };
  3237.  
  3238.  
  3239. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  3240.  
  3241. const p_a_obj = kRef(p_a_objWR);
  3242. // const api = p_a_obj.api;
  3243.  
  3244.  
  3245. // console.log(540);
  3246.  
  3247. let boolList = null;
  3248. let ret;
  3249. isSpaceKeyImmediate = true;
  3250. try {
  3251.  
  3252. ret = 0;
  3253. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  3254. let p_a_objT;
  3255. if (!spaceBarControl_keyG) { // just in case
  3256. boolList = new Set();
  3257. p_a_objT = new Proxy(p_a_obj, {
  3258. get(target, prop, handler) {
  3259. const val = target[prop];
  3260. if (typeof val !== 'boolean') return val;
  3261. boolList.add(prop);
  3262. // console.log(555, prop, val);
  3263. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  3264. spaceBarControl_keyG = prop;
  3265. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3266. val = false;
  3267. }
  3268. return val;
  3269. }
  3270. });
  3271.  
  3272.  
  3273. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  3274. p_a_obj[spaceBarControl_keyG] = false;
  3275. p_a_objT = p_a_obj;
  3276. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  3277. } else {
  3278.  
  3279. p_a_objT = p_a_obj;
  3280. }
  3281.  
  3282. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  3283.  
  3284.  
  3285. } catch (e) {
  3286. console.log(e)
  3287. }
  3288. isSpaceKeyImmediate = false;
  3289.  
  3290. if (boolList && boolList.size === 1) {
  3291. const value = boolList.values().next().value;
  3292. spaceBarControl_keyG = value;
  3293. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3294.  
  3295. }
  3296.  
  3297. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3298.  
  3299. return ret;
  3300. }
  3301.  
  3302. const shortcutKeysFixer = () => {
  3303.  
  3304. let pausePromiseControlJ = 0;
  3305.  
  3306.  
  3307. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  3308.  
  3309. let controlPhase = 0;
  3310. const aElm = document.activeElement;
  3311.  
  3312. if (aElm) {
  3313.  
  3314. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  3315.  
  3316. if (typeof controlPhaseCache === 'number') {
  3317.  
  3318. controlPhase = controlPhaseCache;
  3319. } else {
  3320.  
  3321. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  3322. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  3323. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  3324. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  3325. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  3326. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  3327. else {
  3328. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  3329. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  3330. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  3331. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  3332. }
  3333.  
  3334. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  3335. controlPhase = 0;
  3336. }
  3337.  
  3338. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  3339. if (aElm.closest('[contenteditable], input, textarea')) {
  3340. controlPhase = 5;
  3341. } else if (aElm.closest('button')) {
  3342. controlPhase = 4;
  3343. }
  3344. }
  3345.  
  3346. if (aElm.closest('#movie_player')) controlPhase = 6;
  3347.  
  3348. wmKeyControlPhase.set(aElm, controlPhase);
  3349.  
  3350. }
  3351. }
  3352.  
  3353. return controlPhase;
  3354.  
  3355. }
  3356.  
  3357. const isStateControllable = (api) => {
  3358. let appState = null;
  3359. let playerState = null;
  3360. let adState = null;
  3361. try {
  3362. appState = api.getAppState();
  3363. playerState = api.getPlayerState();
  3364. adState = api.getAdState();
  3365. } catch (e) { }
  3366. // ignore playerState -1
  3367. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  3368. };
  3369.  
  3370.  
  3371. const keyEventListener = (evt) => {
  3372. if (BY_PASS_KEYBOARD_CONTROL) return;
  3373.  
  3374. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3375. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  3376. if (!ytPageReady) return;
  3377.  
  3378. if (evt.defaultPrevented === true) return;
  3379.  
  3380. const p_a_obj = kRef(p_a_objWR);
  3381.  
  3382. if (!p_a_obj) return;
  3383.  
  3384.  
  3385. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3386. if (!mediaPlayerElement) return;
  3387.  
  3388. // let focusBodyIfSuccess = false;
  3389.  
  3390. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  3391.  
  3392. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  3393. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  3394. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  3395.  
  3396.  
  3397. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  3398.  
  3399. // console.log(`${evt.type}::controlPhase`,controlPhase)
  3400.  
  3401. // if (controlPhase == 4) {
  3402. // focusBodyIfSuccess = true;
  3403. // }
  3404.  
  3405. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  3406. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3407.  
  3408. if (FIX_SHORTCUTKEYS < 2) return;
  3409. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  3410.  
  3411. let rr;
  3412. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  3413.  
  3414.  
  3415.  
  3416. let useImprovedPauseResume = false;
  3417.  
  3418. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3419.  
  3420. const api = p_a_obj.api;
  3421. const stateControllable = isStateControllable(api);
  3422. // console.log(2122, appState, playerState, adState)
  3423.  
  3424. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  3425.  
  3426. useImprovedPauseResume = true;
  3427.  
  3428. }
  3429.  
  3430.  
  3431. }
  3432.  
  3433.  
  3434. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  3435. if (evt.type === 'keydown') {
  3436.  
  3437. if (useImprovedPauseResume) {
  3438.  
  3439. const isPaused = mediaPlayerElement.paused;
  3440.  
  3441. const cj = ++pausePromiseControlJ;
  3442. Promise.resolve().then(() => {
  3443.  
  3444. if (cj !== pausePromiseControlJ) return;
  3445.  
  3446. if (mediaPlayerElement.paused !== isPaused) return;
  3447.  
  3448. const ret = ytResumeFn();
  3449. if (!ret) { // fallback
  3450. isPaused ? api.playVideo() : api.pauseVideo();
  3451. }
  3452.  
  3453. /*
  3454. let a = void 0;
  3455. console.log('Rb', api.Rb())
  3456. a = !window._yt_player.nL(api.Rb());
  3457. p_a_obj.Wd.kG(a)
  3458. a ? api.playVideo() : api.pauseVideo();
  3459.  
  3460. */
  3461.  
  3462.  
  3463. });
  3464. rr = true;
  3465. } else {
  3466.  
  3467. isSpaceKeyImmediate = true;
  3468. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  3469. isSpaceKeyImmediate = false;
  3470. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3471.  
  3472. }
  3473.  
  3474.  
  3475. } else if (evt.type === 'keyup') {
  3476.  
  3477. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3478.  
  3479. rr = true;
  3480. } else {
  3481.  
  3482. isSpaceKeyImmediate = true;
  3483. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  3484. isSpaceKeyImmediate = false;
  3485. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3486.  
  3487. }
  3488.  
  3489.  
  3490. /*
  3491.  
  3492. if (d)
  3493. switch (c) {
  3494. case 32:
  3495. case 13:
  3496. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  3497. b = !0,
  3498. e = !1;
  3499. else if (e) {
  3500. var m = d.getAttribute("role");
  3501. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  3502. d.click(),
  3503. f = !0)
  3504. }
  3505. break;
  3506. case 37:
  3507. case 39:
  3508. case 36:
  3509. case 35:
  3510. b = "slider" === d.getAttribute("role");
  3511. break;
  3512. case 38:
  3513. case 40:
  3514. m = d.getAttribute("role"),
  3515. d = 38 === c ? d.previousSibling : d.nextSibling,
  3516. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  3517. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  3518. f = b = !0))
  3519. }
  3520. if (e && !f)
  3521. switch (c) {
  3522. case 38:
  3523. f = Math.min(this.api.getVolume() + 5, 100);
  3524. XV(this.Wd, f, !1);
  3525. this.api.setVolume(f);
  3526. h = f = !0;
  3527. break;
  3528. case 40:
  3529. f = Math.max(this.api.getVolume() - 5, 0);
  3530. XV(this.Wd, f, !0);
  3531. this.api.setVolume(f);
  3532. h = f = !0;
  3533. break;
  3534. case 36:
  3535. this.api.Yh() && (this.api.startSeekCsiAction(),
  3536. this.api.seekTo(0, void 0, void 0, void 0, 79),
  3537. h = f = !0);
  3538. break;
  3539. case 35:
  3540. this.api.Yh() && (this.api.startSeekCsiAction(),
  3541. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  3542. h = f = !0)
  3543. }
  3544. */
  3545.  
  3546. }
  3547.  
  3548.  
  3549. if (rr) {
  3550.  
  3551. // focusBodyIfSuccess && Promise.resolve().then(() => {
  3552. // activeElement === document.activeElement && activeElement.blur();
  3553. // });
  3554.  
  3555. evt.preventDefault();
  3556. evt.stopImmediatePropagation();
  3557. evt.stopPropagation();
  3558.  
  3559. }
  3560.  
  3561. };
  3562.  
  3563. document.addEventListener('keydown', keyEventListener, { capture: true });
  3564.  
  3565.  
  3566. document.addEventListener('keyup', keyEventListener, { capture: true });
  3567.  
  3568. }
  3569.  
  3570. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  3571.  
  3572. })();
  3573.  
  3574.  
  3575. pageMediaWatcher();
  3576. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  3577.  
  3578.  
  3579. const check_for_set_key_order = (() => {
  3580.  
  3581. let mySet = new Set();
  3582.  
  3583. mySet.add("value1");
  3584. mySet.add("value2");
  3585. mySet.add("value3");
  3586.  
  3587. // Function to convert Set values to an array
  3588. function getSetValues(set) {
  3589. return Array.from(set.values());
  3590. }
  3591.  
  3592. // Function to test if the Set maintains insertion order
  3593. function testSetOrder(set, expectedOrder) {
  3594. let values = getSetValues(set);
  3595. return expectedOrder.join(',') === values.join(',');
  3596. }
  3597.  
  3598. // Test 1: Initial order
  3599. if (mySet.values().next().value !== "value1") return false;
  3600. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  3601.  
  3602. // Test 2: After deleting an element
  3603. mySet.delete("value2");
  3604. if (mySet.values().next().value !== "value1") return false;
  3605. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  3606.  
  3607. // Test 3: After re-adding a deleted element
  3608. mySet.add("value2");
  3609. if (mySet.values().next().value !== "value1") return false;
  3610. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  3611.  
  3612. // Test 4: After adding a new element
  3613. mySet.add("value4");
  3614. if (mySet.values().next().value !== "value1") return false;
  3615. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  3616.  
  3617. // Test 5: Delete+Add
  3618. mySet.delete("value1");
  3619. mySet.delete("value3");
  3620. mySet.add("value3");
  3621. mySet.add("value1");
  3622. if (mySet.values().next().value !== "value2") return false;
  3623. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  3624.  
  3625. return true;
  3626. })();
  3627.  
  3628.  
  3629. // const qm47 = Symbol();
  3630. const qm57 = Symbol();
  3631. const qm53 = Symbol();
  3632. const qn53 = Symbol();
  3633.  
  3634.  
  3635. const ump3 = new WeakMap();
  3636.  
  3637. const stp = document.createElement('noscript');
  3638. stp.id = 'weakref-placeholder';
  3639.  
  3640. PROP_OverReInclusion_AVOID && (() => {
  3641.  
  3642.  
  3643. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  3644. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  3645. let byPassVal = null;
  3646. let byPassCount = 0;
  3647. let mmw = new Set();
  3648. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  3649. if (arguments.length !== 1) return f.apply(this, arguments);
  3650. if (byPassVal !== null && typeof prop === 'string') {
  3651.  
  3652. if (PROP_OverReInclusion_LIST.has(prop)) {
  3653. byPassCount++;
  3654. return byPassVal;
  3655. }
  3656. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  3657.  
  3658. }
  3659. return this.hasOwnProperty72(prop);
  3660. };
  3661.  
  3662.  
  3663. /*
  3664.  
  3665.  
  3666. z.prototype.forwardDynamicProps = function() {
  3667. var B = m(this.inst);
  3668. B = h(B);
  3669. for (var F = B.next(); !F.done; F = B.next()) {
  3670. var H = h(F.value);
  3671. F = H.next().value;
  3672. H = H.next().value;
  3673. my(this, F, H);
  3674. r(b) && !ly(F) && Wua(this.inst, F)
  3675. }
  3676. }
  3677.  
  3678. */
  3679.  
  3680.  
  3681.  
  3682. let byPassZeroShowed = false;
  3683. const forwardDynamicPropsGeneral = function () {
  3684. byPassVal = true;
  3685. byPassCount = 0;
  3686. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  3687. const ret = this.forwardDynamicProps72();
  3688. byPassVal = null;
  3689. if (byPassCount === 0 && !byPassZeroShowed) {
  3690. byPassZeroShowed = true;
  3691. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  3692. }
  3693. byPassCount = 0;
  3694. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  3695. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  3696. mmw.clear();
  3697. }
  3698. return ret;
  3699. };
  3700.  
  3701. const propCheck = (proto) => {
  3702. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  3703. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  3704. if (proto.forwardDynamicProps.length === 0) {
  3705. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  3706. }
  3707. }
  3708. };
  3709.  
  3710. const valMap = new WeakMap();
  3711. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  3712. get() {
  3713. propCheck(this.constructor.prototype);
  3714. return valMap.get(this);
  3715. },
  3716. set(nv) {
  3717. propCheck(this.constructor.prototype);
  3718. valMap.set(this, nv);
  3719. return true;
  3720. },
  3721. enumerable: false,
  3722. configurable: true
  3723.  
  3724. });
  3725.  
  3726. promiseForCustomYtElementsReady.then(() => {
  3727. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  3728. if (customElements.define.length !== 2) return;
  3729. customElements.define72 = customElements.define;
  3730. customElements.define = function (b, w) {
  3731. propCheck(w.prototype);
  3732. const ret = this.define72(b, w);
  3733. return ret;
  3734. }
  3735. });
  3736.  
  3737. })();
  3738.  
  3739.  
  3740. let marcoPr = new PromiseExternal();
  3741. const trackMarcoCm = document.createComment('1');
  3742. const trackMarcoCmObs = new MutationObserver(()=>{
  3743. marcoPr.resolve();
  3744. marcoPr = new PromiseExternal();
  3745. });
  3746. trackMarcoCmObs.observe(trackMarcoCm, {characterData: true});
  3747.  
  3748.  
  3749. // ----------------------------
  3750.  
  3751.  
  3752.  
  3753. const __refreshData938o__ = {};
  3754. const __refreshData938__ = function (prop, opt) {
  3755. const d = this[prop];
  3756. if (d) {
  3757. this._setPendingProperty(prop, __refreshData938o__, opt);
  3758. this._setPendingProperty(prop, d, opt);
  3759. this._invalidateProperties();
  3760. }
  3761. };
  3762.  
  3763. const __refreshData933__ = function (prop, opt) {
  3764. const d = this[prop];
  3765. if (d) {
  3766. this.signalProxy.setWithPath([prop], d);
  3767. }
  3768. }
  3769.  
  3770. const setupRefreshData930 = (cnt) => {
  3771. if (cnt.__refreshData930__ !== undefined) return;
  3772. const cProto = Reflect.getPrototypeOf(cnt);
  3773. let r = null;
  3774. let flag = 0;
  3775. if (typeof cnt._setPendingProperty === 'function' && typeof cnt._invalidateProperties === 'function' && cnt._setPendingProperty.length === 3 && cnt._invalidateProperties.length === 0) {
  3776. flag |= 1;
  3777. }
  3778. if (typeof cnt.signalProxy !== "undefined") {
  3779. flag |= 2;
  3780. }
  3781. if (typeof (cnt.signalProxy || 0).setWithPath === 'function' && cnt.signalProxy.setWithPath.length === 2) {
  3782. flag |= 4;
  3783. }
  3784. if (r === 1) r = __refreshData938__;
  3785. // else if (r === 6) r = __refreshData933__;
  3786. cProto.__refreshData930__ = r;
  3787. // ytd-comments-header-renderer : no _invalidateProperties (cnt.signalProxy.setWithPath)
  3788. }
  3789.  
  3790. // const pendingStampFlushs = [];
  3791.  
  3792. const nativeNow = performance.constructor.prototype.now.bind(performance);
  3793.  
  3794. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  3795.  
  3796. const executeTaskBatch = function (taskArr, firstMarco = true) {
  3797. if (!(taskArr || 0).length) throw new TypeError(`Illegal invocation`);
  3798. return new Promise(resolveFinal => {
  3799. let resolveFn = null;
  3800. const len = taskArr.length;
  3801. const results = new Array(len);
  3802. const makePromise = () => new Promise(resolve => { resolveFn = resolve });
  3803. let firedCount = 0;
  3804. const executor = () => {
  3805. if (taskArr.length !== len) throw new TypeError(`Illegal invocation`);
  3806. const resolveFn_ = resolveFn;
  3807. let t0 = 0;
  3808. let next = 0;
  3809. taskArr.forEach((task, idx) => {
  3810. if (typeof (task || 0) !== 'object') throw new TypeError(`Illegal invocation`);
  3811. if (!task.fired) {
  3812. queueMicrotask_(() => {
  3813. if (next || task.fired) return;
  3814. task.fired = true;
  3815. const { fn } = task;
  3816. task.fn = null;
  3817. if (++firedCount === len) next |= 2;
  3818. if (!t0) t0 = nativeNow() + 10;
  3819. results[idx] = fn(task); // sync task only
  3820. if (nativeNow() > t0) next |= 1;
  3821. });
  3822. }
  3823. });
  3824. queueMicrotask_(() => resolveFn_(next))
  3825. }
  3826. const looper = (next) => {
  3827. if (!next) throw new TypeError(`Illegal invocation`);
  3828. if (next & 2) {
  3829. taskArr.length = 0;
  3830. if (next & 1) {
  3831. nextBrowserTick_(() => resolveFinal(results))
  3832. } else {
  3833. resolveFinal(results);
  3834. }
  3835. } else {
  3836. const p = makePromise();
  3837. nextBrowserTick_(executor);
  3838. p.then(looper);
  3839. }
  3840. }
  3841. const p = makePromise();
  3842. firstMarco ? nextBrowserTick_(executor) : executor();
  3843. p.then(looper);
  3844.  
  3845. })
  3846.  
  3847. }
  3848.  
  3849.  
  3850. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  3851.  
  3852.  
  3853. // const globalPromiseStack = {};
  3854.  
  3855. // let dummy;
  3856. // while(!dummy){
  3857.  
  3858. // dummy = document.querySelector('yt-icon');
  3859. // await new Promise(r=>setTimeout(r,0));
  3860. // }
  3861.  
  3862. dummy = document.createElement('yt-icon');
  3863.  
  3864. let cProto;
  3865. if (!(dummy instanceof Element)) return;
  3866. cProto = insp(dummy).constructor.prototype;
  3867.  
  3868. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  3869. cProto.determineIconSet671 = cProto.determineIconSet;
  3870. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  3871. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  3872. cProto.getIconManager671 = cProto.getIconManager;
  3873. cProto.getIconShapeData671 = cProto.getIconShapeData;
  3874. cProto.renderIcon671 = cProto.renderIcon;
  3875.  
  3876. // cProto.attached488 = cProto.attached;
  3877. // cProto.attached = function(){
  3878. // console.log('attached')
  3879. // return this.attached488(...arguments);
  3880. // }
  3881. // cProto.detached488 = cProto.detached;
  3882. // cProto.detached = function(){
  3883. // console.log('detached')
  3884. // return this.detached488(...arguments);
  3885. // }
  3886.  
  3887. if(cProto.__renderIconFix__) return;
  3888. cProto.__renderIconFix__ = true;
  3889.  
  3890. let taskStack = [];
  3891. const cmObs = new MutationObserver(()=>{
  3892. const tasks = taskStack.slice();
  3893. taskStack.length = 0;
  3894. for(const task of tasks){
  3895. task();
  3896. }
  3897. })
  3898. const cm = document.createComment('1');
  3899. const stackTask = (f) => {
  3900. taskStack.push(f);
  3901. cm.data = `${(cm.data & 7) + 1}`;
  3902. }
  3903. cmObs.observe(cm, { characterData: true });
  3904.  
  3905. // let iconManagers = {}; // assume shared
  3906.  
  3907. // window.iconManagers = () => iconManagers;
  3908.  
  3909.  
  3910. const setupYtIcon = (inst) => {
  3911.  
  3912. if (inst.__ytIconSetup588__) return;
  3913. const cProto = Reflect.getPrototypeOf(inst);
  3914. cProto.__ytIconSetup588__ = true;
  3915.  
  3916.  
  3917. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3918.  
  3919. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  3920. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  3921. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  3922. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  3923.  
  3924.  
  3925. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  3926. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  3927. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  3928. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  3929.  
  3930.  
  3931.  
  3932. }
  3933.  
  3934. cProto.handlePropertyChange = function (...a) { // 10+
  3935.  
  3936. if (!this.__ytIconSetup588__) setupYtIcon(this);
  3937. this.__resolved__ = {
  3938.  
  3939. };
  3940. const a01 = this.isAttached;
  3941. let a02, a03;
  3942.  
  3943.  
  3944. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  3945.  
  3946. const stackFn = () => {
  3947. if (t !== this.__stackedKey3818__) {
  3948. return;
  3949. }
  3950. a03 = this.isAttached;
  3951.  
  3952. if (a01 === false && a02 === false && a03 === false) return;
  3953.  
  3954. if (a01 === true && a02 === true && a03 === true) {
  3955.  
  3956. } else {
  3957. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  3958. // unknown yt-icon#label-icon
  3959. return;
  3960. } else {
  3961. console.log('[yt-icon] debug', a01, a02, a03, this)
  3962. }
  3963. }
  3964.  
  3965. this.handlePropertyChange671(...arguments);
  3966.  
  3967. };
  3968.  
  3969.  
  3970.  
  3971. Promise.resolve().then(() => {
  3972. a02 = this.isAttached;
  3973. stackTask(stackFn);
  3974. });
  3975.  
  3976.  
  3977. }
  3978.  
  3979. cProto.determineIconSet = function (a, b, c, d) { // 10-
  3980.  
  3981. if (!this.__ytIconSetup588__) setupYtIcon(this);
  3982. // string bool? bool=false int=24
  3983. // NOTIFICATIONS_NONE OR LIKE
  3984. // console.log('yt-icon.determineIconSet', ...arguments);
  3985.  
  3986. const r = this.determineIconSet671(...arguments);
  3987. return r;
  3988. }
  3989.  
  3990. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  3991.  
  3992. if (!this.__ytIconSetup588__) setupYtIcon(this);
  3993. // same as determineIconSet
  3994. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  3995. return this.switchToYtSysIconset671(...arguments);
  3996. }
  3997.  
  3998. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  3999.  
  4000. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4001. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  4002. return this.useYtSysIconsetForMissingIcons671(...arguments);
  4003. }
  4004.  
  4005. cProto.getIconManager = function () { // 10+
  4006.  
  4007. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4008. if (!this.__resolved__) this.__resolved__ = {};
  4009. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  4010. const r = this.__resolved__.getIconManager;
  4011. return r;
  4012. }
  4013.  
  4014. cProto.getIconShapeData = function () { // 10+
  4015.  
  4016. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4017.  
  4018. // no argument
  4019. // console.log('yt-icon.getIconShapeData', ...arguments);
  4020. if (!this.__resolved__) this.__resolved__ = {};
  4021. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  4022. const r = this.__resolved__.getIconShapeData;
  4023. return r
  4024. }
  4025.  
  4026. cProto.renderIcon = function (a, b) { // X
  4027.  
  4028. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4029. // "" yt-icons:xxx
  4030. // console.log('yt-icon.renderIcon', ...arguments);
  4031. return this.renderIcon671(...arguments);
  4032. }
  4033.  
  4034. });
  4035.  
  4036. // stampDomArray_
  4037. const createStampDomArrayFn_ = () => {
  4038. // if (val_kevlar_should_maintain_stable_list === null) {
  4039. // const config_ = ((window.yt || 0).config_ || 0);
  4040. // val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true;
  4041. // }
  4042.  
  4043. // if(true){
  4044.  
  4045.  
  4046. const pSpace = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4047. document.documentElement.insertAdjacentElement('beforeend', pSpace);
  4048. const pNode = document.createElement('ns-538');
  4049. pSpace.insertAdjacentElement('beforeend', pNode);
  4050.  
  4051. const pDiv = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4052. if (typeof pNode.attachShadow === 'function') {
  4053. const pShadow = pNode.attachShadow({ mode: "open" });
  4054. pShadow.replaceChildren(pDiv);
  4055. } else {
  4056. pNode.insertAdjacentElement('beforeend', pDiv);
  4057. }
  4058.  
  4059. const pDivTempRemoval = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4060. pDiv.insertAdjacentElement('beforeend', pDivTempRemoval);
  4061. pDivTempRemoval.setAttribute('attm', 'pDivTempRemoval');
  4062.  
  4063. const pDivDeletion = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4064. pDiv.insertAdjacentElement('beforeend', pDivDeletion);
  4065. pDivDeletion.setAttribute('attm', 'pDivDeletion');
  4066. const pDivKeep = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4067. pDiv.insertAdjacentElement('beforeend', pDivKeep);
  4068. pDivKeep.setAttribute('attm', 'pDivKeep');
  4069.  
  4070.  
  4071. const pDivDeletionObs = new MutationObserver(() => {
  4072. let node = pDivDeletion.firstElementChild;
  4073. while (node) {
  4074. let nextNode = node.nextElementSibling;
  4075. if (node.__delayRemoved__) {
  4076. removeTNode_(node)
  4077. // } else {
  4078. // node.remove();
  4079. }
  4080. node = nextNode;
  4081. }
  4082. if (pDivDeletion.firstChild) pDivDeletion.textContent = '';
  4083. });
  4084. pDivDeletionObs.observe(pDivDeletion, { childList: true, subtree: false });
  4085.  
  4086. // const URa = function (a, b) {
  4087. // for (var c in a)
  4088. // if (a.hasOwnProperty(c) && b[c])
  4089. // return c;
  4090. // return null
  4091. // }
  4092.  
  4093. const syta = Symbol(); // container uid
  4094. // const sytb = Symbol();
  4095. const sytc = Symbol(); // data & parent relationship
  4096. const sytd = Symbol(); // bind data and component (in case not .data relationship -- to be reviewed)
  4097. const syte = Symbol(); // data uid
  4098.  
  4099. // const tmpElementNode = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4100.  
  4101. let fallbackToDefault00 = false; // full by-pass mode enabled as incorrect calling was found
  4102.  
  4103. const attributeMutationObserver = new MutationObserver((mutations) => {
  4104. const targets = new Set();
  4105. for (const mutation of mutations) {
  4106. targets.add(mutation.target);
  4107. }
  4108. for (const container of targets) {
  4109. const tag = container.__closestYtTag388__;
  4110. if (tag) {
  4111. const hostElement = container.closest(tag);
  4112. if (hostElement && hostElement.is === tag) {
  4113. const detail = {
  4114. container
  4115. };
  4116. hostElement.dispatchEvent(new CustomEvent("yt-rendererstamper-finished", {
  4117. bubbles: !0,
  4118. cancelable: !1,
  4119. composed: !0,
  4120. detail
  4121. }));
  4122. detail.container = null;
  4123. }
  4124. }
  4125. }
  4126. });
  4127.  
  4128. const stamperTasksA = {};
  4129.  
  4130. const YRa = (a, b) => {
  4131. for (const c in a)
  4132. if (a.hasOwnProperty(c) && b[c])
  4133. return c;
  4134. return null
  4135. }
  4136.  
  4137. // let lastClickX33 = 0;
  4138. // let minusX33 = 0;
  4139. // document.addEventListener('pointerdown', ()=>{
  4140. // nextBrowserTick_(()=>{
  4141. // minusX33 = 10000;
  4142. // });
  4143. // minusX33 = 0;
  4144. // lastClickX33 = Date.now();
  4145. // },true);
  4146. // document.addEventListener('keydown', ()=>{
  4147. // nextBrowserTick_(()=>{
  4148. // minusX33 = 10000;
  4149. // });
  4150. // minusX33 = 0;
  4151. // lastClickX33 = Date.now();
  4152. // },true);
  4153. // document.addEventListener('keyup', ()=>{
  4154. // nextBrowserTick_(()=>{
  4155. // minusX33 = 10000;
  4156. // });
  4157. // minusX33 = 0;
  4158. // lastClickX33 = Date.now();
  4159. // },true);
  4160. // document.addEventListener('pointerup', ()=>{
  4161. // nextBrowserTick_(()=>{
  4162. // minusX33 = 10000;
  4163. // });
  4164. // minusX33 = 0;
  4165. // lastClickX33 = Date.now();
  4166. // },true);
  4167.  
  4168. // document.addEventListener('pointercancel', ()=>{
  4169. // nextBrowserTick_(()=>{
  4170. // minusX33 = 10000;
  4171. // });
  4172. // minusX33 = 0;
  4173. // lastClickX33 = Date.now();
  4174. // },true);
  4175.  
  4176. let pageFirstDom = '';
  4177.  
  4178. // let emComponents = new Set();
  4179. let withStampDomExx = false;
  4180.  
  4181. const DEBUG_STAMP_CHANGE = false;
  4182. const DEBUG_FINALIZATION = false;
  4183.  
  4184.  
  4185. const reuseStore = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? new Map() : null;
  4186. const registry = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? new FinalizationRegistry((heldValue) => {
  4187. DEBUG_FINALIZATION && console.log(`Object(${heldValue}) has been released`);
  4188. }) : null;
  4189.  
  4190. const registerFn = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? (node, heldValue) => {
  4191. Promise.resolve(node).then((node) => {
  4192. registry.register(node, heldValue);
  4193. });
  4194. } : () => { }
  4195.  
  4196.  
  4197. const go = function (a, b, c, d) {
  4198. d || (d = {
  4199. bubbles: !0,
  4200. cancelable: !1,
  4201. composed: !0
  4202. });
  4203. c !== null && c !== void 0 && (d.detail = c);
  4204. b = new CustomEvent(b, d);
  4205. a.dispatchEvent(b);
  4206. return b
  4207. };
  4208.  
  4209. const __rd481o__ = {}
  4210.  
  4211. const tryDirectDataSet = (cnt, data) => {
  4212. if (typeof (cnt.__data || 0).data === 'object' && cnt.__data.data === cnt.data) {
  4213. if (cnt.data !== data) {
  4214. if (typeof cnt.set === 'function' && cnt.set.length >= 2) {
  4215. try {
  4216. cnt.set('data', data);
  4217. } catch (e) { }
  4218. return cnt.data === data;
  4219. } else {
  4220. cnt.data = data;
  4221. return cnt.data === data;
  4222. }
  4223. } else if (typeof cnt._setPendingProperty === 'function' && cnt._setPendingProperty.length === 3
  4224. && typeof cnt._invalidateProperties === 'function' && cnt._invalidateProperties.length === 0) {
  4225. try {
  4226. cnt._setPendingProperty('data', __rd481o__, !0);
  4227. cnt._setPendingProperty('data', data, !0);
  4228. cnt._invalidateProperties();
  4229. return true;
  4230. } catch (e) {
  4231. }
  4232. }
  4233. }
  4234. };
  4235.  
  4236. const removeTNode__ = (node) => { // need trigger removal of its parent component
  4237. const xlivev = xlivec00.__domApi;
  4238. if (node.isConnected === true) {
  4239. xlivev.appendChild(node); // attached -> detached
  4240. // xlivev.removeChild(node); // detached -> detached
  4241. } else {
  4242. xlivev.appendChild(node); // detached -> detached
  4243. // xlivev.removeChild(node); // detached -> detached
  4244. }
  4245. }
  4246. // window.removeTNode__ = removeTNode__;
  4247.  
  4248. const removeTNode_ = (node) => { // need trigger removal of its parent component
  4249. const xdeadv = xdeadc00.__domApi;
  4250. removeTNodeBP = true;
  4251. // if (node.isConnected === true) {
  4252. xdeadv.appendChild(node); // attached -> detached
  4253. xdeadv.removeChild(node); // detached -> detached
  4254. // } else {
  4255. // xdeadv.appendChild(node); // detached -> detached
  4256. // xdeadv.removeChild(node); // detached -> detached
  4257. // }
  4258. removeTNodeBP = false;
  4259. }
  4260. window.removeTNode_ = removeTNode_;
  4261. removeTNodeRM = removeTNode_;
  4262.  
  4263. const removeTNode = (node) => { // need trigger removal of its parent component
  4264. const xdeadv = xdeadc00.__domApi;
  4265. if (node.isConnected === true) {
  4266. if (node.parentNode !== pDivDeletion) {
  4267. pDivDeletion.insertAdjacentHTML('afterbegin', ttpHTML('<!---->'));
  4268. pDivDeletion.lastChild.replaceWith(node); // attached -> attached
  4269. }
  4270.  
  4271. // xdeadv.appendChild(node); // attached -> detached
  4272. // xdeadv.removeChild(node); // detached -> detached
  4273.  
  4274. node.remove(); // attached -> detached
  4275. xdeadv.appendChild(node); // detached -> detached
  4276. xdeadv.removeChild(node); // detached -> detached
  4277. } else {
  4278.  
  4279. node.remove(); // detached -> detached
  4280. xdeadv.appendChild(node); // detached -> detached
  4281. xdeadv.removeChild(node); // detached -> detached
  4282.  
  4283. // xdeadv.appendChild(node); // detached -> detached
  4284. // xdeadv.removeChild(node); // detached -> detached
  4285. }
  4286. }
  4287. // window.removeTNode = removeTNode;
  4288.  
  4289.  
  4290. const removeTNodeDelayed = (node) => {
  4291. if (node.isConnected === true) {
  4292. node.__delayRemoved__ = true;
  4293. pDivDeletion.insertAdjacentHTML('afterbegin', ttpHTML('<!---->'));
  4294. pDivDeletion.lastChild.replaceWith(node); // attached -> attached
  4295. } else {
  4296. const xdeadv = xdeadc00.__domApi;
  4297. xdeadv.appendChild(node); // detached -> detached
  4298. xdeadv.removeChild(node); // detached -> detached
  4299. }
  4300. }
  4301. // window.removeTNodeDelayed = removeTNodeDelayed;
  4302.  
  4303. let config00 = null;
  4304.  
  4305. let appendFrag00 = null;
  4306.  
  4307. let safeActionCount = 0;
  4308.  
  4309.  
  4310. const safeAction = function (f) {
  4311.  
  4312. if (safeActionCount > 0) return f();
  4313.  
  4314. safeActionCount++;
  4315.  
  4316. const config = config00;
  4317. let err, result;
  4318.  
  4319. const qv1 = config.DEFERRED_DETACH;
  4320. const qv2 = config.REUSE_COMPONENTS;
  4321. // const qv3 = config.STAMPER_STABLE_LIST;
  4322. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  4323. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  4324. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  4325.  
  4326. try {
  4327. result = f();
  4328. } catch (e) {
  4329. err = e;
  4330. }
  4331.  
  4332. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  4333. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  4334. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  4335.  
  4336. safeActionCount--;
  4337.  
  4338. if (err) throw err;
  4339.  
  4340. return result;
  4341.  
  4342.  
  4343. };
  4344.  
  4345. const safeAppend = function (items, containerId, componentConfig, bEventCallback, removeExisting, finishState) {
  4346.  
  4347. return safeAction(()=>{
  4348.  
  4349.  
  4350. if (removeExisting) this.stampDomArray9682_(null, containerId, null, false, null, null);
  4351. const c = componentConfig;
  4352. const k = this.getStampContainer_(containerId);
  4353. const b = k.__domApi || k;
  4354. /*
  4355. const g = document.createDocumentFragment();
  4356. let r;
  4357. for(let i = 0, l =items.length; i<l;i++){
  4358. const u = items[i];
  4359. const w = YRa(c, u);
  4360. if (w) {
  4361. r = this.createComponent_(c[w], u[w], false);
  4362. this.deferRenderStamperBinding_(r, c[w], u[w]);
  4363. g.appendChild(r);
  4364. }
  4365. }
  4366. b.appendChild(g)
  4367. */
  4368.  
  4369. const g = appendFrag00 || (appendFrag00 = document.createDocumentFragment());
  4370. let r;
  4371. for (let i = 0, l = items.length; i < l; i++) {
  4372. const u = items[i];
  4373. const w = YRa(c, u);
  4374. if (w) {
  4375. r = this.createComponent_(c[w], u[w], false);
  4376. this.deferRenderStamperBinding_(r, c[w], u[w]);
  4377. g.appendChild(r);
  4378. }
  4379. }
  4380. b.appendChild(g)
  4381.  
  4382. if (finishState & 1) {
  4383. this.flushRenderStamperComponentBindings_();
  4384. }
  4385. if (finishState & 2) {
  4386. this.markDirty && this.markDirty();
  4387. }
  4388. if (finishState & 4) {
  4389. bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  4390. container: k
  4391. });
  4392. }
  4393.  
  4394. })
  4395.  
  4396.  
  4397. };
  4398.  
  4399.  
  4400. const safeFinish = function (containerId, bEventCallback) {
  4401.  
  4402. return safeAction(()=>{
  4403.  
  4404.  
  4405. const k = this.getStampContainer_(containerId);
  4406.  
  4407. this.flushRenderStamperComponentBindings_();
  4408. this.markDirty && this.markDirty();
  4409. bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  4410. container: k
  4411. });
  4412.  
  4413. })
  4414.  
  4415. };
  4416.  
  4417.  
  4418. const reuseRefreshMode = 1;
  4419.  
  4420. const setupComponent = function (data, component, containerElement, refNode, deferredBindingTask, reused = false) {
  4421.  
  4422. let noRenderTaskForResuedComponent = false;
  4423. if (component instanceof Node) {
  4424.  
  4425.  
  4426. if (data && data[syte] && component[syte] !== data[syte]) {
  4427. // component[sytb] = data[sytb]
  4428. component[sytc] = data[sytc]
  4429. component[syte] = data[syte];
  4430. // containerElement[sytd].set(data, mWeakRef(component));
  4431. containerElement[sytd].set(component, mWeakRef(data));
  4432. if(reuseStore) reuseStore.set(data[syte], mWeakRef(component));
  4433. }
  4434.  
  4435. const cnt = insp(component);
  4436.  
  4437.  
  4438. if (reused && reuseRefreshMode >= 1 && cnt.data) { // in case cnt.data no change. force re-render
  4439. setupRefreshData930(cnt);
  4440. if (cnt.__refreshData930__) {
  4441. try {
  4442. cnt.__refreshData930__('data', !0);
  4443. if (reuseRefreshMode >= 2) noRenderTaskForResuedComponent = true;
  4444. } catch (e) {
  4445. console.warn(e)
  4446. }
  4447. }
  4448. }
  4449.  
  4450. if (refNode !== undefined) {
  4451. const componentX = component;
  4452. if (componentX instanceof Node) {
  4453. if (refNode !== componentX) {
  4454. if (!refNode) {
  4455. containerElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4456. containerElement.lastChild.replaceWith(componentX);
  4457. } else {
  4458. refNode.insertAdjacentHTML('beforebegin', ttpHTML('<!---->'));
  4459. refNode.previousSibling.replaceWith(componentX);
  4460. }
  4461. }
  4462. }
  4463.  
  4464. }
  4465.  
  4466. if (noRenderTaskForResuedComponent) {
  4467.  
  4468. } else if (deferredBindingTask && deferredBindingTask.typeOrConfig) {
  4469. this.deferredBindingTasks_.push(deferredBindingTask);
  4470. this.flushRenderStamperComponentBindings_();
  4471. if (this.deferredBindingTasks_.length >= 1) this.deferredBindingTasks_.length = 0;
  4472. }
  4473.  
  4474. return true;
  4475.  
  4476. }
  4477. return false;
  4478.  
  4479. }
  4480.  
  4481.  
  4482. let triggerCountWithinMicro = 0;
  4483.  
  4484. let firstExecuted = false;
  4485.  
  4486. const gn = function (items__, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList) {
  4487. const config = config00 || (config00 = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0));
  4488. if (!firstExecuted) {
  4489. firstExecuted = true;
  4490. if (!xdeadc00) setupXdeadC(this);
  4491. if (FORCE_NO_REUSEABLE_ELEMENT_POOL && typeof this.createComponent_ === 'function' && this.createComponent_.length === 3) {
  4492. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(this);
  4493. }
  4494. }
  4495.  
  4496.  
  4497. let useSyncE = false; // essential components
  4498. let disableTaskSkip = false;
  4499.  
  4500. triggerCountWithinMicro++;
  4501. const triggerCountWithinMicro_ = triggerCountWithinMicro;
  4502. Promise.resolve().then(() => {
  4503. triggerCountWithinMicro--;
  4504. });
  4505.  
  4506. // const stack = new Error().stack;
  4507.  
  4508.  
  4509. if (!this.__rendererStamperConfig5422__) {
  4510. const cProto = Reflect.getPrototypeOf(this);
  4511. cProto.__rendererStamperConfig5422__ = 1;
  4512. if (!cProto.__safeAppend8382__) cProto.__safeAppend8382__ = safeAppend;
  4513. if (!cProto.__safeFinish8382__) cProto.__safeFinish8382__ = safeFinish;
  4514. if (!cProto.__setupComponent8382__) cProto.__setupComponent8382__ = setupComponent;
  4515. }
  4516.  
  4517. const stamperTasksKey = `${this.is}::${containerId}`;
  4518. const stamperTasks = stamperTasksA[stamperTasksKey] || (stamperTasksA[stamperTasksKey] = []);
  4519.  
  4520. let renderJob = this.renderJobsMap_ && containerId ? this.renderJobsMap_[containerId] : null;
  4521. const items_ = items__;
  4522. const hasRunningTasks = stamperTasks.length >= 1;
  4523. const container = typeof this.getStampContainer_ === 'function' ? this.getStampContainer_(containerId) : (this.$ || 0)[containerId];
  4524.  
  4525. let fallbackToDefault = fallbackToDefault00;
  4526. if (!config) {
  4527. console.warn('stampDomArray_ fallback: no config');
  4528. fallbackToDefault = fallbackToDefault00 = true;
  4529. } else if (!this.deferredBindingTasks_ || this.deferredBindingTasks_.length !== 0) {
  4530. console.warn('stampDomArray_ fallback: no deferredBindingTasks_');
  4531. fallbackToDefault = fallbackToDefault00 = true;
  4532. } else if (!container) {
  4533. console.warn('stampDomArray_ fallback: no container');
  4534. fallbackToDefault = fallbackToDefault00 = true;
  4535. } else {
  4536. if (container.__xnHookE93__ !== null) {
  4537. if (container.firstElementChild !== null) {
  4538. if (!container.__xnHookE93__) container.__xnHookE93__ = new Set();
  4539. container.__xnHookE93__.add(containerId);
  4540. } else if (container.__xnHookE93__) {
  4541. container.__xnHookE93__.delete(containerId);
  4542. if (container.__xnHookE93__.size === 0) {
  4543. container.__xnHookE93__ = null;
  4544. }
  4545. } else {
  4546. container.__xnHookE93__ = null;
  4547. }
  4548. if (container.__xnHookE93__ !== null) {
  4549. fallbackToDefault = true; // skip handling weird element. wait until container become clean
  4550. } else {
  4551. container.__xnHookE93__ = null;
  4552. try {
  4553. this.stampDomArray9682_(null, containerId, null, false, false, false); // bind the yt dom api
  4554. } catch (e) { }
  4555. if (container.__domApi && !container.__domApi.__daHook377__) {
  4556. setupDomApi(Reflect.getPrototypeOf(container.__domApi));
  4557. setupSDomWrapper();
  4558. }
  4559. }
  4560. }
  4561. }
  4562.  
  4563. if (fallbackToDefault || true) {
  4564. return this.stampDomArray9682_(...arguments);
  4565. }
  4566.  
  4567.  
  4568. const bStableListA = bStableList !== undefined ? Boolean(bStableList) : (typeof config.STAMPER_STABLE_LIST !== "undefined" ? !!config.STAMPER_STABLE_LIST : false);
  4569.  
  4570. const containerDomApi = (container || 0).__domApi || container;
  4571. const containerElement = containerDomApi instanceof Node ? containerDomApi : insp(container).hostElement instanceof Node ? insp(container).hostElement : container;
  4572.  
  4573. const keyRequireAsync = `__stamperRequireAsync#${containerId}__`;
  4574. const key5993 = `__stamperCounter5993#${containerId}__`;
  4575. const key5996 = `__stamperCounter5996#${containerId}__`;
  4576. const keyNative4772 = `__stamperNative4772#${containerId}__`;
  4577. // const keyOnSync = `__stamperOnSync#${containerId}__`;
  4578.  
  4579.  
  4580.  
  4581. let hasKey = false;
  4582. if (items_ && items_.length >= 1) {
  4583.  
  4584. hasKey = items_.some((v) => (typeof YRa(componentConfig, v) === 'string'));
  4585.  
  4586. }
  4587.  
  4588. if (bEventCallback) {
  4589. if (!container.__rendererStamperEventCallback388__) {
  4590. container.__rendererStamperEventCallback388__ = true;
  4591. container.__closestYtTag388__ = this.is;
  4592. attributeMutationObserver.observe(container, { attributes: ['ytxx-stamper-finished'] });
  4593. }
  4594. }
  4595.  
  4596.  
  4597. // if (!this.__rendererStamperFinishFn588__) {
  4598. // this.__rendererStamperFinishFn588__ = () => {
  4599. // if (this.deferredBindingTasks_ && this.deferredBindingTasks_.length >= 1) {
  4600. // this.flushRenderStamperComponentBindings_();
  4601. // }
  4602. // this.markDirty && this.markDirty();
  4603. // };
  4604.  
  4605. // }
  4606.  
  4607.  
  4608.  
  4609.  
  4610. const items = hasKey ? items_.slice() : []; // avoid memory leakge
  4611.  
  4612. this[key5993] = (this[key5993] & 1073741823) + 1;
  4613.  
  4614. let leaveWithNoChange = false;
  4615.  
  4616.  
  4617. if (!hasRunningTasks && !this[keyRequireAsync]) {
  4618. if (!pageFirstDom) { // initial stamp action
  4619. pageFirstDom = this.is;
  4620. useSyncE = true;
  4621. this.__stampDomExx__ = true;
  4622. } else if (this.__stampDomExx__) { // essential component
  4623. useSyncE = true;
  4624. } else if (!withStampDomExx) { // not ready
  4625. useSyncE = true;
  4626. } else if (triggerCountWithinMicro_ === 1) { // first stamp action (user action)
  4627. useSyncE = true;
  4628. }
  4629. if (!hasKey) { // noChange
  4630. leaveWithNoChange = true;
  4631. useSyncE = true;
  4632. }
  4633. }
  4634. // console.log(18480, useSyncE, triggerCountWithinMicro_, hasKey)
  4635.  
  4636. const useSync_ = useSyncE;
  4637. const tryBatchUpdate_ = !useSync_ && (renderJob || hasRunningTasks || this[keyRequireAsync]);
  4638.  
  4639. const skey = stamperTasks.__skey__ = `${Date.now()}`;
  4640.  
  4641. let taskFinish = false;
  4642.  
  4643. let result;
  4644.  
  4645. let skipToNextTask = false;
  4646.  
  4647. let nativeMode_ = false;
  4648. if (this[keyNative4772]) {
  4649. nativeMode_ = true;
  4650. } else if (hasKey && (containerId.length == 7 || (containerId.length === 14) || (containerId.length > 5 && containerId.length < 8))) {
  4651. // if(this.is != 'ytd-comment-simplebox-renderer'){
  4652.  
  4653. // if (hasKey) {
  4654.  
  4655. if (this.is === 'ytd-masthead' || this.is === 'ytd-watch-flexy' || this.is === 'ytd-watch-engagement-panels' || this.is === 'ytd-rich-grid-renderer' || this.is === 'ytd-comment-simplebox-renderer') {
  4656.  
  4657.  
  4658. } else if (this.is === 'ytd-engagement-panel-section-list-renderer' && (containerId.length === 14)) {
  4659.  
  4660.  
  4661. } else {
  4662.  
  4663. console.log(containerId.length, 391992, this.is)
  4664.  
  4665. // console.log(391921, this.is, containerId)
  4666. nativeMode_ = true;
  4667. }
  4668. // }
  4669. // }
  4670. }
  4671. const nativeMode = nativeMode_;
  4672. // let nativeModeProceeded = false;
  4673.  
  4674. stamperTasks.push(() => {
  4675. if (skey !== stamperTasks.__skey__ && !disableTaskSkip ) {
  4676.  
  4677. if(nativeMode && bStableListA && items.length > 0 && hasKey && !leaveWithNoChange){
  4678.  
  4679. // console.log(2949011, containerElement.childElementCount)
  4680.  
  4681. } else {
  4682.  
  4683. skipToNextTask = true;
  4684. }
  4685. // taskFinish = true;
  4686. }
  4687. });
  4688.  
  4689. if (leaveWithNoChange) {
  4690. if (container.__rendererStamperEventCallback388__) {
  4691. stamperTasks.push(() => {
  4692. if (taskFinish) return;
  4693. if(skipToNextTask) return;
  4694. if (container.__rendererStamperEventCallback388__) {
  4695. taskFinish = true;
  4696. container.setAttribute('ytxx-stamper-finished', (container.getAttribute('ytxx-stamper-finished') & 7) + 1);
  4697. return;
  4698. }
  4699. });
  4700. }
  4701. } else {
  4702.  
  4703. this[key5996] = (this[key5996] & 1073741823) + 1;
  4704. }
  4705.  
  4706. // this[key5996] = (this[key5996] & 1073741823) + 1;
  4707.  
  4708.  
  4709.  
  4710.  
  4711.  
  4712. containerElement[syta] = containerElement[syta] || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  4713. containerElement[sytd] = containerElement[sytd] || new WeakMap();
  4714.  
  4715. const mkData = new Set();
  4716.  
  4717. const pneItems = items.map(eq => {
  4718. const dataKey = firstObjectKey(eq);
  4719. const dataKey2 = YRa(componentConfig, eq)
  4720. if (dataKey && dataKey2 === dataKey) {
  4721. const targetComponentName = this.getComponentName_(componentConfig[dataKey], eq[dataKey]);
  4722. const data = eq[dataKey];
  4723. // if (data) data[sytb] = (data[sytb] & 1073741823) + 1;
  4724. if (data) {
  4725. data[syte] = data[syte] || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  4726. const arr = new Set((data[sytc] || '').split(','));
  4727. arr.delete('');
  4728. arr.add(containerElement[syta]);
  4729. data[sytc] = [...arr].join(',');
  4730. // addData.add(data);
  4731. mkData.add(data[syte]);
  4732. const dte = data[syte];
  4733. return {
  4734. targetComponentName,
  4735. dataKey,
  4736. data,
  4737. item: eq,
  4738. dte
  4739. }
  4740. }
  4741. }
  4742. return {
  4743. data: void 0,
  4744. item: eq,
  4745. dte: ''
  4746. };
  4747. }).filter(e=>!!e.dte);
  4748.  
  4749.  
  4750. let elementIter = containerElement.firstElementChild;
  4751. const uneElements = !elementIter ? [] : new Array(containerElement.childElementCount);
  4752. for (let i = 0, l = uneElements.length; i < l; i++) {
  4753. const pageElement = elementIter;
  4754. if (!pageElement) {
  4755. uneElements.length = i;
  4756. break;
  4757. }
  4758. const pageElementData = kRef(containerElement[sytd].get(pageElement));
  4759. const dte_ = pageElement[syte];
  4760. const dte = pageElementData && dte_ && pageElementData[syte] === dte_ && (insp(pageElement).data || 0)[syte] === dte_ ? dte_ : '';
  4761.  
  4762. uneElements[i] = {
  4763. pageElement: pageElement,
  4764. pageElementData: pageElementData,
  4765. dte
  4766. }
  4767. elementIter = elementIter.nextElementSibling;
  4768. }
  4769.  
  4770.  
  4771. const reuseKey = `${containerElement[syta]}**${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`
  4772.  
  4773. let modeSelection = 0;
  4774.  
  4775. stamperTasks.push(() => {
  4776.  
  4777. if (taskFinish) return;
  4778. if (skipToNextTask) return;
  4779.  
  4780.  
  4781. if (this[keyNative4772]) {
  4782. modeSelection = 9;
  4783. return;
  4784. }
  4785.  
  4786. if (nativeMode) {
  4787.  
  4788.  
  4789.  
  4790.  
  4791. // const container = this.getStampContainer_(containerId);
  4792. // const containerElement = this.
  4793.  
  4794.  
  4795.  
  4796.  
  4797.  
  4798.  
  4799. // if (b = _.yn(k),
  4800. // d = kSa(d),
  4801. // a) {
  4802. // var m = 0, n = 0, r;
  4803. // if (g = g === void 0 ? _.Gi("STAMPER_STABLE_LIST", !1) : g || !1)
  4804. // for (r = b.firstElementChild; r && !$s.has(r) && a.length > n; ) {
  4805. // g = a[n];
  4806. // var t = hSa(c, g);
  4807. // if (t) {
  4808. // if (this.getComponentName_(c[t], g[t]) != r.is) {
  4809. // var u = this.createComponent_(c[t], g[t], d)
  4810. // , x = _.yn(r).nextElementSibling;
  4811. // x ? b.insertBefore(u, x) : b.appendChild(u);
  4812. // oSa(this.is, b, r, d);
  4813. // r = u
  4814. // } else
  4815. // this.telemetry_.reuse++;
  4816. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  4817. // m++;
  4818. // n++;
  4819. // r = _.yn(r).nextElementSibling
  4820. // } else
  4821. // n++
  4822. // }
  4823. // pSa(this.is, b, m, d);
  4824. // m = r;
  4825. // if (a.length > n) {
  4826. // g = document.createDocumentFragment();
  4827. // for (t = a.length; n < t; n++)
  4828. // if (u = a[n],
  4829. // x = hSa(c, u))
  4830. // r = this.createComponent_(c[x], u[x], d),
  4831. // this.deferRenderStamperBinding_(r, c[x], u[x]),
  4832. // g.appendChild(r);
  4833. // m && _.yn(m).parentNode && r && !$s.has(r) ? b.insertBefore(g, m) : b.appendChild(g)
  4834. // }
  4835. // this.flushRenderStamperComponentBindings_();
  4836. // this.markDirty && this.markDirty();
  4837. // e && _.jo(this.hostElement, "yt-rendererstamper-finished", {
  4838. // container: k
  4839. // })
  4840. // } else
  4841. // pSa(this.is, b, 0, d);
  4842.  
  4843. const items = pneItems.map(e=>e.item);
  4844.  
  4845.  
  4846.  
  4847.  
  4848. // const container = this.getStampContainer_(containerId);
  4849. // const containerElement = container.__domApi || container;
  4850. const a = items;
  4851. const c = componentConfig;
  4852.  
  4853. // console.log(2949012, containerElement.childElementCount);
  4854.  
  4855. {
  4856.  
  4857. const container = typeof this.getStampContainer_ === 'function' ? this.getStampContainer_(containerId) : (this.$ || 0)[containerId];
  4858.  
  4859.  
  4860. const containerDomApi = (container || 0).__domApi || container;
  4861. const containerElement = containerDomApi instanceof Node ? containerDomApi : insp(container).hostElement instanceof Node ? insp(container).hostElement : container;
  4862.  
  4863. // console.log(2949013, containerElement.childElementCount);
  4864. }
  4865.  
  4866. if(a){
  4867.  
  4868. const bStableListA = bStableList !== undefined ? Boolean(bStableList) : (typeof config.STAMPER_STABLE_LIST !== "undefined" ? !!config.STAMPER_STABLE_LIST : false);
  4869.  
  4870.  
  4871.  
  4872. // let m = 0, n = 0, r;
  4873. // const bStableListA = bStableList !== undefined ? Boolean(bStableList) : (typeof config.STAMPER_STABLE_LIST !== "undefined" ? !!config.STAMPER_STABLE_LIST : false);
  4874.  
  4875. // if(bStableListA){
  4876. // for (r = containerElement.firstElementChild; r && a.length > n; ) {
  4877. // const item = items[n];
  4878. // let t = YRa(c, item);
  4879. // if (t) {
  4880. // if (this.getComponentName_(c[t], item[t]) != r.is) {
  4881. // let component = this.createComponent_(c[t], g[t], false)
  4882. // , x = standardWrap_(r).nextElementSibling;
  4883. // x ? b.insertBefore(component, x) : b.appendChild(component);
  4884. // // oSa(this.is, b, r, d);
  4885. // r = u
  4886. // } else
  4887. // this.telemetry_.reuse++;
  4888. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  4889. // m++;
  4890. // n++;
  4891. // r = standardWrap_(r).nextElementSibling
  4892. // } else
  4893. // n++
  4894. // }
  4895. // }
  4896. // let child;
  4897. // if (containerElement && containerElement.children && (child = containerElement.children[m])){
  4898. // let k;
  4899. // for (; (k = containerElement.lastElementChild) && (containerElement.removeChild(k),
  4900. // nSa(a, k, d),
  4901. // k != child); )
  4902. // }
  4903.  
  4904. if (bStableListA && containerElement.firstElementChild && items.length > 0 && hasKey) {
  4905.  
  4906.  
  4907.  
  4908. let needNativeCall01 = false;
  4909. let needNativeCall02 = false;
  4910. let node;
  4911. {
  4912. let m =0, n=0;
  4913. node = containerElement.firstElementChild;
  4914. while(node && items.length > n){
  4915. const item = items[n];
  4916. const t = YRa(c, item);
  4917. if(t){
  4918. if (this.getComponentName_(c[t], item[t]) != node.is) {
  4919. needNativeCall01 =true;
  4920. break;
  4921. }
  4922. m++;
  4923. n++;
  4924. node = node.nextElementSibling;
  4925. } else {
  4926. n++;
  4927. }
  4928. }
  4929. if(containerDomApi.children[m]){
  4930. needNativeCall02 = true;
  4931. }
  4932. }
  4933.  
  4934.  
  4935. if(!needNativeCall01 && !needNativeCall02){
  4936.  
  4937. modeSelection = 5;
  4938.  
  4939.  
  4940. } else {
  4941.  
  4942. modeSelection = 9;
  4943.  
  4944.  
  4945. }
  4946.  
  4947.  
  4948. // nativeModeProceeded = true;
  4949.  
  4950.  
  4951. }
  4952.  
  4953.  
  4954. }
  4955.  
  4956.  
  4957.  
  4958.  
  4959. // if (b = _.yn(k),
  4960. // d = kSa(d),
  4961. // a) {
  4962. // var m = 0, n = 0, r;
  4963. // if (g = g === void 0 ? _.Gi("STAMPER_STABLE_LIST", !1) : g || !1)
  4964. // for (r = b.firstElementChild; r && !$s.has(r) && a.length > n; ) {
  4965. // g = a[n];
  4966. // var t = hSa(c, g);
  4967. // if (t) {
  4968. // if (this.getComponentName_(c[t], g[t]) != r.is) {
  4969. // var u = this.createComponent_(c[t], g[t], d)
  4970. // , x = _.yn(r).nextElementSibling;
  4971. // x ? b.insertBefore(u, x) : b.appendChild(u);
  4972. // oSa(this.is, b, r, d);
  4973. // r = u
  4974. // } else
  4975. // this.telemetry_.reuse++;
  4976. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  4977. // m++;
  4978. // n++;
  4979. // r = _.yn(r).nextElementSibling
  4980. // } else
  4981. // n++
  4982. // }
  4983. // pSa(this.is, b, m, d);
  4984. // m = r;
  4985. // if (a.length > n) {
  4986. // g = document.createDocumentFragment();
  4987. // for (t = a.length; n < t; n++)
  4988. // if (u = a[n],
  4989. // x = hSa(c, u))
  4990. // r = this.createComponent_(c[x], u[x], d),
  4991. // this.deferRenderStamperBinding_(r, c[x], u[x]),
  4992. // g.appendChild(r);
  4993. // m && _.yn(m).parentNode && r && !$s.has(r) ? b.insertBefore(g, m) : b.appendChild(g)
  4994. // }
  4995. // this.flushRenderStamperComponentBindings_();
  4996. // this.markDirty && this.markDirty();
  4997. // e && _.jo(this.hostElement, "yt-rendererstamper-finished", {
  4998. // container: k
  4999. // })
  5000. // } else
  5001. // pSa(this.is, b, 0, d);
  5002.  
  5003.  
  5004. // this.stampDomArray9682_(items, containerId, componentConfig, false, bEventCallback, bStableList);
  5005.  
  5006.  
  5007.  
  5008.  
  5009. // this.stampDomArray9682_(...arguments);
  5010. }
  5011. });
  5012.  
  5013.  
  5014. stamperTasks.push(() => {
  5015.  
  5016. if (taskFinish) return;
  5017. if (skipToNextTask) return;
  5018.  
  5019.  
  5020.  
  5021. if (modeSelection === 9) {
  5022.  
  5023.  
  5024.  
  5025. const key = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  5026. console.log(2949071, key, this.is, containerId, containerElement.childElementCount, items.length, [...containerElement.children].map(e=>e.nodeName.toLowerCase()).join('|'))
  5027. safeAction(() => {
  5028. window.p3mk = 1;
  5029. this.stampDomArray9682_(items, containerId, componentConfig, false, bEventCallback, bStableList);
  5030. window.p3mk = 0;
  5031. });
  5032.  
  5033. console.log(2949072, key, this.is, containerId, containerElement.childElementCount, items.length, [...containerElement.children].map(e=>e.nodeName.toLowerCase()).join('|'))
  5034.  
  5035.  
  5036. this[keyNative4772] = true;
  5037.  
  5038. }
  5039. });
  5040.  
  5041. const reuseExistingStableElement = (component, dte, config, data) =>{
  5042.  
  5043. const oldDte = component[syte];
  5044.  
  5045. if (this.telemetry_ && this.telemetry_.reuse >= 0) this.telemetry_.reuse++;
  5046.  
  5047. // console.log(123992, node, componentConfig[dataKey], data, cnt.data, oldDte, dte )
  5048.  
  5049. // play safe
  5050. // component[sytb] = null;
  5051. component[sytc] = null;
  5052. component[syte] = null;
  5053. containerElement[sytd].delete(component);
  5054. // play safe
  5055.  
  5056. if (reuseStore) reuseStore.delete(oldDte);
  5057. component[syte] = dte;
  5058. component.___reuseFor__ = reuseKey; // once only
  5059.  
  5060.  
  5061.  
  5062. // cnt.data = data;
  5063. const deferredBindingTaskX = { component: component, typeOrConfig: config, data: data }
  5064. this.__setupComponent8382__(data, component, containerElement, undefined, deferredBindingTaskX, true);
  5065.  
  5066.  
  5067. }
  5068.  
  5069. let newItemStartElm = null;
  5070. let newItemStartIdx = 0;
  5071.  
  5072. stamperTasks.push(() => {
  5073.  
  5074. if (taskFinish) return;
  5075. if (skipToNextTask) return;
  5076.  
  5077. if (this[keyNative4772]) return;
  5078.  
  5079. if(modeSelection === 5){
  5080.  
  5081. // console.log('modeSelection 5b')
  5082.  
  5083. const itemsCount = pneItems.length;
  5084.  
  5085. let m = 0, n = 0, elementNode;
  5086. for (elementNode = containerElement.firstElementChild; elementNode && itemsCount > n; ) {
  5087. const {item, dte, data, dataKey} = pneItems[n];
  5088. const componentKey = YRa(componentConfig, item);
  5089. if (componentKey) {
  5090.  
  5091. reuseExistingStableElement(elementNode, dte, componentConfig[dataKey], data);
  5092. m++;
  5093. n++;
  5094. elementNode = elementNode.nextElementSibling
  5095. } else
  5096. n++
  5097. }
  5098. m = elementNode;
  5099. newItemStartElm = m;
  5100. newItemStartIdx = n;
  5101.  
  5102. // this.flushRenderStamperComponentBindings_();
  5103. // this.markDirty && this.markDirty();
  5104. // e && go(this.hostElement, "yt-rendererstamper-finished", {
  5105. // container: k
  5106. // })
  5107.  
  5108. }
  5109.  
  5110.  
  5111. });
  5112.  
  5113. /*
  5114. stamperTasks.push(() => {
  5115.  
  5116.  
  5117. if (taskFinish) return;
  5118. if (skipToNextTask) return;
  5119.  
  5120. if (this[keyNative4772]) return;
  5121.  
  5122. if (modeSelection === 5) {
  5123.  
  5124. const itemsCount = pneItems.length;
  5125. let m = newItemStartElm;
  5126. let n = newItemStartIdx;
  5127.  
  5128. if (itemsCount > n) {
  5129. const g = appendFrag00 || (appendFrag00 = document.createDocumentFragment());
  5130. for (; n < itemsCount; n++) {
  5131. const { item } = pneItems[n];
  5132. const componentKey = YRa(componentConfig, item);
  5133.  
  5134. if (componentKey) {
  5135.  
  5136. const component = this.createComponent_(componentConfig[componentKey], item[componentKey], false);
  5137. this.deferRenderStamperBinding_(component, componentConfig[componentKey], item[componentKey]);
  5138. g.appendChild(component);
  5139. m && m.parentNode && component ? containerDomApi.insertBefore(g, m) : containerDomApi.appendChild(g)
  5140.  
  5141. }
  5142.  
  5143. }
  5144.  
  5145. }
  5146.  
  5147.  
  5148.  
  5149. }
  5150.  
  5151.  
  5152.  
  5153.  
  5154. });
  5155. */
  5156.  
  5157. pneItems.forEach((pneItem, idx) => {
  5158.  
  5159. stamperTasks.push(() => {
  5160.  
  5161.  
  5162. if (taskFinish) return;
  5163. if (skipToNextTask) return;
  5164. if (this[keyNative4772]) return;
  5165.  
  5166. const itemsCount = pneItems.length;
  5167. if (modeSelection === 5 && itemsCount > newItemStartIdx && idx>=newItemStartIdx) {
  5168.  
  5169.  
  5170. let m = newItemStartElm;
  5171. const n = idx;
  5172. // const g = appendFrag00 || (appendFrag00 = document.createDocumentFragment());
  5173. // for (; n < itemsCount; n++) {
  5174. const { item } = pneItems[n];
  5175. const componentKey = YRa(componentConfig, item);
  5176. if (componentKey) {
  5177. // const component = this.createComponent_(componentConfig[componentKey], item[componentKey], false);
  5178. // this.deferRenderStamperBinding_(component, componentConfig[componentKey], item[componentKey]);
  5179. // g.appendChild(component);
  5180. // m && m.parentNode && component ? containerDomApi.insertBefore(g, m) : containerDomApi.appendChild(g)
  5181.  
  5182. safeAppend([item], containerId, componentConfig[componentKey], item[componentKey], false, 0)
  5183.  
  5184. }
  5185. // }
  5186.  
  5187.  
  5188.  
  5189.  
  5190.  
  5191. }
  5192.  
  5193.  
  5194.  
  5195.  
  5196.  
  5197. })
  5198. });
  5199.  
  5200.  
  5201. stamperTasks.push(() => {
  5202.  
  5203. if (taskFinish) return;
  5204. if (skipToNextTask) return;
  5205.  
  5206. if (this[keyNative4772]) return;
  5207.  
  5208. if(modeSelection !== 0) return;
  5209.  
  5210. // if(skipToNextTask) return;
  5211.  
  5212. let tryStable = null;
  5213. if (bStableListA) {
  5214. tryStable = {};
  5215.  
  5216. pneItems.forEach(pneItem => {
  5217.  
  5218.  
  5219. const { item, dte, data, dataKey, targetComponentName } = pneItem;
  5220.  
  5221.  
  5222. const q_ = reuseStore ? kRef(reuseStore.get(dte)) : null; // no rendered dom for the item
  5223.  
  5224. if (!q_) {
  5225.  
  5226. if (!tryStable[targetComponentName]) tryStable[targetComponentName] = new Set();
  5227.  
  5228. tryStable[targetComponentName].add((node) => {
  5229.  
  5230. const component = node;
  5231. const oldDte = node[syte];
  5232. // const cnt = insp(node);
  5233. if (oldDte && oldDte !== dte && node.parentNode === containerElement && data && data[syte] && data[syte] === dte) {
  5234.  
  5235. reuseExistingStableElement(component, dte, componentConfig[dataKey], data);
  5236.  
  5237. return true;
  5238.  
  5239.  
  5240. }
  5241.  
  5242. return false;
  5243.  
  5244. });
  5245.  
  5246. }
  5247.  
  5248. })
  5249.  
  5250. }
  5251.  
  5252.  
  5253. const removes = [];
  5254.  
  5255.  
  5256. let node = containerElement.firstElementChild;
  5257. while (node !== null) {
  5258.  
  5259. const dte = node[syte];
  5260. const nextNode = node.nextElementSibling;
  5261.  
  5262.  
  5263. const tryStableCur = tryStable ? tryStable[node.is] : null;
  5264.  
  5265. if (tryStableCur && dte && !mkData.has(dte) && tryStableCur.size >= 1) {
  5266. // to be removed as no equal entry, but try to make it for tryStable
  5267.  
  5268. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  5269. const fn = tryStableCur.values().next().value;
  5270. tryStableCur.delete(fn) && fn(node);
  5271. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  5272.  
  5273. }
  5274.  
  5275. if (node.___reuseFor__ === reuseKey) {
  5276.  
  5277.  
  5278. } else if (!(typeof (dte || 0) === 'string' && mkData.has(dte))) {
  5279.  
  5280. // console.log(insp(node).data);
  5281. // console.log(items)
  5282. removes.push(node);
  5283. // q30 = true;
  5284. // u.removeChild(node)
  5285. // try{
  5286. // v.removeChild(node); // just to trigger some internal removal
  5287. // }catch(e){
  5288. // }
  5289. }
  5290. node = nextNode;
  5291.  
  5292. }
  5293.  
  5294. tryStable = null;
  5295.  
  5296. if (removes.length === 0) return;
  5297.  
  5298. // let xdeadc = xdeadc00;
  5299. if (!xdeadc00) setupXdeadC(this);
  5300. // const xdeadv = xdeadc.__domApi;
  5301.  
  5302. for (const node of removes) {
  5303. removeTNode_(node);
  5304. registerFn(node, '01');
  5305. }
  5306.  
  5307. // safeClear(containerId, null, 2 | 4)
  5308.  
  5309. });
  5310.  
  5311.  
  5312.  
  5313. let refNode = null;
  5314. let refNodeIdx = -1;
  5315.  
  5316. const taskPerPneItem = (pneItem) => {
  5317.  
  5318.  
  5319. let reused = false;
  5320.  
  5321. const { item, dte, data, dataKey, targetComponentName } = pneItem;
  5322. refNode = ++refNodeIdx === 0 ? containerElement.firstElementChild : refNode && refNode.nextElementSibling;
  5323.  
  5324.  
  5325. const q_ = reuseStore ? kRef(reuseStore.get(dte)) : null;
  5326. // q_.___reuseFor__ === reuseKey -> tryStable
  5327. // q_.closest('defs') -> removed so reuse
  5328. const reuseCase = !q_ ? 0 : q_.___reuseFor__ === reuseKey ? 1 : q_.closest('defs') ? 2 : q_[syte] === dte ? 3 : -1;
  5329.  
  5330. let deferredBindingTaskX = null;
  5331. let component = null;
  5332. if (reuseCase < 0) {
  5333. console.log(`reuse ${reuseCase}... ${this.is} ... ${containerId}`);
  5334. }
  5335. if (reuseCase >= 0 && q_ && q_.is === targetComponentName) {
  5336.  
  5337. component = q_;
  5338. const cnt = insp(q_);
  5339.  
  5340. let dataSetOK = false && tryDirectDataSet(cnt, data);
  5341. if (dataSetOK) {
  5342. deferredBindingTaskX = { component: q_, data: data }
  5343. reused = true;
  5344. DEBUG_STAMP_CHANGE && console.log('reuse X0')
  5345. } else {
  5346. deferredBindingTaskX = { component: q_, typeOrConfig: componentConfig[dataKey], data: data }
  5347. reused = true;
  5348. DEBUG_STAMP_CHANGE && console.log('reuse S0')
  5349. }
  5350.  
  5351. /*
  5352. if (q_.closest('defs')) {
  5353.  
  5354. const node = component = q;
  5355. const cnt = insp(node);
  5356. if ('data' in cnt) cnt.data = data;
  5357. deferredBindingTaskX = { component: q, data: data }
  5358. // listX.push(deferredBindingTaskX);
  5359.  
  5360. DEBUG_STAMP_CHANGE && console.log('reuse X0')
  5361. reused = true;
  5362.  
  5363. } else {
  5364.  
  5365. const node = component = q;
  5366. const cnt = insp(node);
  5367. // cnt.data = data;
  5368. deferredBindingTaskX = { component: q, typeOrConfig: componentConfig[dataKey], data: data }
  5369. // listX.push(deferredBindingTaskX);
  5370.  
  5371. reused = true;
  5372.  
  5373. DEBUG_STAMP_CHANGE && console.log('reuse S0')
  5374.  
  5375. }
  5376. */
  5377.  
  5378. } else {
  5379.  
  5380. // console.log('new')
  5381.  
  5382. // const qf2 = this.deferRenderStamperBinding_;
  5383. // let deferredBindingTaskX = null;
  5384. this.deferRenderStamperBinding_ = function (a, b, c) {
  5385. deferredBindingTaskX = {
  5386. component: a,
  5387. typeOrConfig: b,
  5388. data: c
  5389. };
  5390. }
  5391.  
  5392. // console.log(23400, containerElement.childElementCount)
  5393. this.__safeAppend8382__([item], containerId, componentConfig, bEventCallback, false, 0 | 2 | 4);
  5394.  
  5395. // console.log(23401, containerElement.childElementCount)
  5396.  
  5397. // safeFn([item], containerId, componentConfig, false, bEventCallback, false);
  5398.  
  5399. delete this.deferRenderStamperBinding_;
  5400. // this.deferRenderStamperBinding_ = qf2;
  5401. // console.log(deferredBindingTaskX)
  5402. // listX.push(deferredBindingTaskX);
  5403.  
  5404. component = deferredBindingTaskX.component;
  5405.  
  5406. }
  5407.  
  5408.  
  5409. if (this.__setupComponent8382__(data, component, containerElement, refNode, deferredBindingTaskX, reused)) {
  5410.  
  5411. refNode = component;
  5412. }
  5413.  
  5414.  
  5415.  
  5416.  
  5417. }
  5418.  
  5419. pneItems.forEach((pneItem, idx) => {
  5420.  
  5421. stamperTasks.push(() => {
  5422. if (taskFinish) return;
  5423. if (skipToNextTask) return;
  5424.  
  5425. if(this[keyNative4772]) return;
  5426.  
  5427. if(modeSelection !== 0) return;
  5428. // if (skipToNextTask) {
  5429.  
  5430. // if (idx === 0) {
  5431.  
  5432. // for (const pneItem of pneItems) {
  5433.  
  5434. // taskPerPneItem(pneItem);
  5435. // }
  5436. // } else {
  5437. // // skip
  5438.  
  5439. // }
  5440. // } else {
  5441.  
  5442.  
  5443. taskPerPneItem(pneItem);
  5444.  
  5445. // }
  5446.  
  5447. });
  5448.  
  5449.  
  5450. });
  5451.  
  5452.  
  5453. stamperTasks.push(() => {
  5454. if (taskFinish) return;
  5455. if (skipToNextTask) return;
  5456. if(this[keyNative4772]) return;
  5457.  
  5458. if(modeSelection !== 0) return;
  5459. let node = refNode;
  5460. if (!node) return;
  5461. node = node.nextElementSibling;
  5462. while (node) {
  5463. let nextNode = node.nextElementSibling;
  5464. removeTNode_(node);
  5465. registerFn(node, '02');
  5466. node = nextNode;
  5467. }
  5468. });
  5469.  
  5470.  
  5471.  
  5472.  
  5473. this[keyRequireAsync] = (this[keyRequireAsync] || 0) + 1;
  5474.  
  5475. stamperTasks.push(() => {
  5476.  
  5477. if (!skipToNextTask && !this[keyNative4772]) {
  5478. this.__safeFinish8382__(containerId, bEventCallback);
  5479. // this.__rendererStamperFinishFn588__();
  5480. }
  5481. this[keyRequireAsync] = (this[keyRequireAsync] || 0) - 1;
  5482. });
  5483.  
  5484. // if(!leaveWithNoChange) {
  5485. // // disableTaskSkip = true;
  5486. // // const tasks = stamperTasks.slice();
  5487. // // stamperTasks.length = 0;
  5488. // // for (const task of tasks) {
  5489. // // task();
  5490. // // }
  5491. // // return;
  5492. // }
  5493.  
  5494. if (useSync_) {
  5495.  
  5496. disableTaskSkip = true;
  5497.  
  5498. // [[ FOR CRITICAL TASK ]]
  5499.  
  5500. // if (!this[keyOnSync]) this[keyOnSync] = 0;
  5501. // this[keyOnSync]++;
  5502.  
  5503. // const pr = marcoPr;
  5504. // console.log(2992, pr, trackMarcoCm.data)
  5505. // trackMarcoCm.data = `${(trackMarcoCm.data & 7) + 1}`;
  5506. // pr.then(() => {
  5507. // this[keyOnSync]--;
  5508. // // console.log(3992, this.is);
  5509. // });
  5510.  
  5511. const tasks = stamperTasks.slice();
  5512. stamperTasks.length = 0;
  5513.  
  5514. for (const task of tasks) {
  5515. task();
  5516. }
  5517.  
  5518. if (!withStampDomExx && useSync_ && this.is === pageFirstDom) {
  5519. // we treat the components generated by initial stampDom as important
  5520.  
  5521. for (const elm of document.getElementsByTagName('*')) {
  5522. if (elm.is) {
  5523. insp(elm).__stampDomExx__ = true;
  5524. // emComponents.add(elm.is);
  5525. }
  5526. }
  5527. withStampDomExx = true;
  5528. }
  5529.  
  5530. } else {
  5531.  
  5532. if (!hasRunningTasks) {
  5533.  
  5534. const f = () => {
  5535. if (!stamperTasks.length) return;
  5536. const tasks = stamperTasks.slice();
  5537. stamperTasks.length = 0;
  5538. executeTaskBatch(tasks.map(fn => ({ fn })), false);
  5539. }
  5540.  
  5541. if (tryBatchUpdate_) {
  5542. nextBrowserTick_(f);// collecting all tasks (after reflow)
  5543. } else {
  5544. queueMicrotask_(f); // collecting some tasks (before reflow)
  5545. }
  5546.  
  5547. }
  5548.  
  5549. }
  5550.  
  5551. return;
  5552.  
  5553.  
  5554.  
  5555.  
  5556.  
  5557. }
  5558.  
  5559. return gn;
  5560.  
  5561. };
  5562.  
  5563.  
  5564. const setupDiscreteTasks = (h, rb) => {
  5565.  
  5566.  
  5567.  
  5568. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  5569. const f = h.onYtRendererstamperFinished;
  5570. const g = ump3.get(f) || function () {
  5571. if (this.updateChildVisibilityProperties && !this.markDirty) {
  5572. return f.apply(this, arguments);
  5573. }
  5574. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5575. }
  5576. ump3.set(f, g);
  5577. g.km34 = 1;
  5578. h.onYtRendererstamperFinished = g;
  5579.  
  5580. }
  5581.  
  5582. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  5583. const f = h.onYtUpdateDescriptionAction;
  5584. const g = ump3.get(f) || function (a) {
  5585. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5586. }
  5587. ump3.set(f, g);
  5588. g.km34 = 1;
  5589. h.onYtUpdateDescriptionAction = g;
  5590.  
  5591. }
  5592.  
  5593. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  5594. const f = h.handleUpdateDescriptionAction;
  5595. const g = ump3.get(f) || function (a) {
  5596. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5597. }
  5598. ump3.set(f, g);
  5599. g.km34 = 1;
  5600. h.handleUpdateDescriptionAction = g;
  5601.  
  5602. }
  5603.  
  5604. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  5605. const f = h.handleUpdateLiveChatPollAction;
  5606. const g = ump3.get(f) || function (a) {
  5607. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5608. }
  5609. ump3.set(f, g);
  5610. g.km34 = 1;
  5611. h.handleUpdateLiveChatPollAction = g;
  5612.  
  5613. }
  5614.  
  5615. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  5616. const f = h.onTextChanged;
  5617. const g = ump3.get(f) || function () {
  5618. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5619. }
  5620. ump3.set(f, g);
  5621. g.km34 = 1;
  5622. h.onTextChanged = g;
  5623.  
  5624. }
  5625.  
  5626. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  5627. const f = h.onVideoDataChange;
  5628. const g = ump3.get(f) || function (a) {
  5629. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5630. }
  5631. ump3.set(f, g);
  5632. g.km34 = 1;
  5633. h.onVideoDataChange = g;
  5634.  
  5635. }
  5636.  
  5637. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  5638. const f = h.onVideoDataChange_;
  5639. const g = ump3.get(f) || function () {
  5640. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5641. }
  5642. ump3.set(f, g);
  5643. g.km34 = 1;
  5644. h.onVideoDataChange_ = g;
  5645.  
  5646. }
  5647.  
  5648. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  5649.  
  5650. const f = h.addTooltips_;
  5651. const g = ump3.get(f) || function () {
  5652. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5653. }
  5654. ump3.set(f, g);
  5655. g.km34 = 1;
  5656. h.addTooltips_ = g;
  5657.  
  5658. }
  5659.  
  5660. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  5661.  
  5662. const f = h.updateRenderedElements;
  5663. const g = ump3.get(f) || function () {
  5664. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5665. }
  5666. ump3.set(f, g);
  5667. g.km34 = 1;
  5668. h.updateRenderedElements = g;
  5669.  
  5670. }
  5671.  
  5672. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  5673. const f = h.loadPage_;
  5674. const g = ump3.get(f) || function (a) {
  5675. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5676. }
  5677. ump3.set(f, g);
  5678. g.km34 = 1;
  5679. h.loadPage_ = g;
  5680.  
  5681. }
  5682. // updatePageData_ : possible conflict with Omit ShadyDOM
  5683. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  5684. const f = h.updatePageData_;
  5685. const g = ump3.get(f) || function (a) {
  5686. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5687. }
  5688. ump3.set(f, g);
  5689. g.km34 = 1;
  5690. h.updatePageData_ = g;
  5691.  
  5692. }
  5693.  
  5694.  
  5695. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  5696.  
  5697. const f = h.onFocus_;
  5698. const g = ump3.get(f) || function () {
  5699. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5700. }
  5701. ump3.set(f, g);
  5702. g.km34 = 1;
  5703. h.onFocus_ = g;
  5704.  
  5705. }
  5706.  
  5707. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  5708.  
  5709. const f = h.onBlur_;
  5710. const g = ump3.get(f) || function () {
  5711. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5712. }
  5713. ump3.set(f, g);
  5714. g.km34 = 1;
  5715. h.onBlur_ = g;
  5716.  
  5717. }
  5718.  
  5719.  
  5720. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  5721.  
  5722. const f = h.buttonClassChanged_;
  5723. const g = ump3.get(f) || function (a, b) {
  5724. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5725. }
  5726. ump3.set(f, g);
  5727. g.km34 = 1;
  5728. h.buttonClassChanged_ = g;
  5729.  
  5730. }
  5731.  
  5732. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  5733.  
  5734. const f = h.buttonIconChanged_;
  5735. const g = ump3.get(f) || function (a) {
  5736. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5737. }
  5738. ump3.set(f, g);
  5739. g.km34 = 1;
  5740. h.buttonIconChanged_ = g;
  5741.  
  5742. }
  5743.  
  5744. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  5745.  
  5746. const f = h.dataChangedInBehavior_;
  5747. const g = ump3.get(f) || function () {
  5748. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5749. }
  5750. ump3.set(f, g);
  5751. g.km34 = 1;
  5752. h.dataChangedInBehavior_ = g;
  5753.  
  5754. }
  5755.  
  5756. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  5757.  
  5758. const f = h.continuationsChanged_;
  5759. const g = ump3.get(f) || function () {
  5760. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5761. }
  5762. ump3.set(f, g);
  5763. g.km34 = 1;
  5764. h.continuationsChanged_ = g;
  5765.  
  5766. }
  5767.  
  5768.  
  5769. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  5770.  
  5771. const f = h.forceChatPoll_;
  5772. const g = ump3.get(f) || function (a) {
  5773. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5774. }
  5775. ump3.set(f, g);
  5776. g.km34 = 1;
  5777. h.forceChatPoll_ = g;
  5778.  
  5779. }
  5780.  
  5781. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  5782.  
  5783. const f = h.onEndpointClick_;
  5784. const g = ump3.get(f) || function (a) {
  5785. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5786. }
  5787. ump3.set(f, g);
  5788. g.km34 = 1;
  5789. h.onEndpointClick_ = g;
  5790.  
  5791. }
  5792.  
  5793. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  5794.  
  5795. const f = h.onEndpointTap_;
  5796. const g = ump3.get(f) || function (a) {
  5797. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5798. }
  5799. ump3.set(f, g);
  5800. g.km34 = 1;
  5801. h.onEndpointTap_ = g;
  5802.  
  5803. }
  5804.  
  5805. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  5806.  
  5807. const f = h.handleClick_;
  5808. const g = ump3.get(f) || function (a, b) {
  5809. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5810. }
  5811. ump3.set(f, g);
  5812. g.km34 = 1;
  5813. h.handleClick_ = g;
  5814.  
  5815. }
  5816.  
  5817. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  5818.  
  5819. const f = h.onReadyStateChange_;
  5820. const g = ump3.get(f) || function () {
  5821. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5822. }
  5823. ump3.set(f, g);
  5824. g.km34 = 1;
  5825. h.onReadyStateChange_ = g;
  5826.  
  5827. }
  5828.  
  5829. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  5830.  
  5831. const f = h.onReadyStateChangeEntryPoint_;
  5832. const g = ump3.get(f) || function () {
  5833. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5834. }
  5835. ump3.set(f, g);
  5836. g.km34 = 1;
  5837. h.onReadyStateChangeEntryPoint_ = g;
  5838.  
  5839. }
  5840.  
  5841. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  5842.  
  5843. const f = h.readyStateChangeHandler_;
  5844. const g = ump3.get(f) || function (a) {
  5845. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5846. }
  5847. ump3.set(f, g);
  5848. g.km34 = 1;
  5849. h.readyStateChangeHandler_ = g;
  5850.  
  5851. }
  5852.  
  5853. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  5854.  
  5855. const f = h.xmlHttpHandler_;
  5856. const g = ump3.get(f) || function (a) {
  5857. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5858. }
  5859. ump3.set(f, g);
  5860. g.km34 = 1;
  5861. h.xmlHttpHandler_ = g;
  5862.  
  5863. }
  5864.  
  5865. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  5866.  
  5867. const f = h.executeCallbacks_; // overloaded
  5868. const g = ump3.get(f) || function (a) {
  5869. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5870. }
  5871. ump3.set(f, g);
  5872. g.km34 = 1;
  5873. h.executeCallbacks_ = g;
  5874.  
  5875. }
  5876.  
  5877. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  5878.  
  5879. const f = h.handleInvalidationData_;
  5880. const g = ump3.get(f) || function (a, b) {
  5881. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5882. }
  5883. ump3.set(f, g);
  5884. g.km34 = 1;
  5885. h.handleInvalidationData_ = g;
  5886.  
  5887. }
  5888.  
  5889. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  5890.  
  5891. const f = h.onInput_;
  5892. const g = ump3.get(f) || function () {
  5893. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5894. }
  5895. ump3.set(f, g);
  5896. g.km34 = 1;
  5897. h.onInput_ = g;
  5898.  
  5899. }
  5900. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  5901.  
  5902. const f = h.trigger_;
  5903. const g = ump3.get(f) || function (a) {
  5904. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5905. }
  5906. ump3.set(f, g);
  5907. g.km34 = 1;
  5908. h.trigger_ = g;
  5909.  
  5910. }
  5911.  
  5912. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  5913.  
  5914. const f = h.requestData_;
  5915. const g = ump3.get(f) || function (a) {
  5916. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5917. }
  5918. ump3.set(f, g);
  5919. g.km34 = 1;
  5920. h.requestData_ = g;
  5921.  
  5922. }
  5923.  
  5924. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  5925.  
  5926. const f = h.onLoadReloadContinuation_;
  5927. const g = ump3.get(f) || function (a, b) {
  5928. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5929. }
  5930. ump3.set(f, g);
  5931. g.km34 = 1;
  5932. h.onLoadReloadContinuation_ = g;
  5933.  
  5934. }
  5935.  
  5936. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  5937.  
  5938. const f = h.onLoadIncrementalContinuation_;
  5939. const g = ump3.get(f) || function (a, b) {
  5940. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5941. }
  5942. ump3.set(f, g);
  5943. g.km34 = 1;
  5944. h.onLoadIncrementalContinuation_ = g;
  5945.  
  5946. }
  5947.  
  5948. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  5949.  
  5950. const f = h.onLoadSeekContinuation_;
  5951. const g = ump3.get(f) || function (a, b) {
  5952. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5953. }
  5954. ump3.set(f, g);
  5955. g.km34 = 1;
  5956. h.onLoadSeekContinuation_ = g;
  5957.  
  5958. }
  5959. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  5960.  
  5961. const f = h.onLoadReplayContinuation_;
  5962. const g = ump3.get(f) || function (a, b) {
  5963. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5964. }
  5965. ump3.set(f, g);
  5966. g.km34 = 1;
  5967. h.onLoadReplayContinuation_ = g;
  5968.  
  5969. }
  5970. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  5971.  
  5972. const f = h.onNavigate_;
  5973. const g = ump3.get(f) || function (a) {
  5974. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5975. }
  5976. ump3.set(f, g);
  5977. g.km34 = 1;
  5978. h.onNavigate_ = g;
  5979.  
  5980. }
  5981.  
  5982. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  5983.  
  5984. const f = h.ytRendererBehaviorDataObserver_;
  5985. const g = ump3.get(f) || function () {
  5986. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5987. }
  5988. ump3.set(f, g);
  5989. g.km34 = 1;
  5990. h.ytRendererBehaviorDataObserver_ = g;
  5991.  
  5992. }
  5993.  
  5994. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  5995.  
  5996. const f = h.ytRendererBehaviorTargetIdObserver_;
  5997. const g = ump3.get(f) || function () {
  5998. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  5999. }
  6000. ump3.set(f, g);
  6001. g.km34 = 1;
  6002. h.ytRendererBehaviorTargetIdObserver_ = g;
  6003.  
  6004. }
  6005.  
  6006. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  6007.  
  6008. const f = h.unregisterRenderer_;
  6009. const g = ump3.get(f) || function (a) {
  6010. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6011. }
  6012. ump3.set(f, g);
  6013. g.km34 = 1;
  6014. h.unregisterRenderer_ = g;
  6015.  
  6016. }
  6017.  
  6018. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  6019.  
  6020. const f = h.textChanged_;
  6021. const g = ump3.get(f) || function (a) {
  6022. if (void 0 !== this.isAttached) {
  6023. const hostElement = this.hostElement;
  6024. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  6025. return;
  6026. }
  6027. }
  6028. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6029. }
  6030. ump3.set(f, g);
  6031. g.km34 = 1;
  6032. h.textChanged_ = g;
  6033.  
  6034. }
  6035.  
  6036.  
  6037.  
  6038. /**
  6039. *
  6040. * Neglect following
  6041. *
  6042. * h.onYtAction_
  6043. * h.startLoadingWatch [ buggy for yt-player-updated ]
  6044. * h.deferRenderStamperBinding_
  6045. *
  6046. * h.stampDomArray_
  6047. * h.stampDomArraySplices_
  6048. *
  6049. */
  6050.  
  6051.  
  6052. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  6053. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  6054. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  6055. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  6056. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  6057. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  6058.  
  6059. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  6060.  
  6061. const f = h.searchChanged_;
  6062. const g = ump3.get(f) || function () {
  6063. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6064. }
  6065. ump3.set(f, g);
  6066. g.km34 = 1;
  6067. h.searchChanged_ = g;
  6068.  
  6069. }
  6070.  
  6071. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  6072.  
  6073. const f = h.skinToneChanged_;
  6074. const g = ump3.get(f) || function (a) {
  6075. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6076. }
  6077. ump3.set(f, g);
  6078. g.km34 = 1;
  6079. h.skinToneChanged_ = g;
  6080.  
  6081. }
  6082.  
  6083. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  6084.  
  6085. const f = h.onEmojiHover_;
  6086. const g = ump3.get(f) || function (a) {
  6087. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6088. }
  6089. ump3.set(f, g);
  6090. g.km34 = 1;
  6091. h.onEmojiHover_ = g;
  6092.  
  6093. }
  6094.  
  6095. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  6096.  
  6097. const f = h.onSelectCategory_;
  6098. const g = ump3.get(f) || function (a) {
  6099. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6100. }
  6101. ump3.set(f, g);
  6102. g.km34 = 1;
  6103. h.onSelectCategory_ = g;
  6104.  
  6105. }
  6106.  
  6107. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  6108.  
  6109. const f = h.onShowEmojiVariantSelector;
  6110. const g = ump3.get(f) || function (a) {
  6111. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6112. }
  6113. ump3.set(f, g);
  6114. g.km34 = 1;
  6115. h.onShowEmojiVariantSelector = g;
  6116.  
  6117. }
  6118.  
  6119. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  6120.  
  6121. const f = h.updateCategoriesAndPlaceholder_;
  6122. const g = ump3.get(f) || function () {
  6123. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6124. }
  6125. ump3.set(f, g);
  6126. g.km34 = 1;
  6127. h.updateCategoriesAndPlaceholder_ = g;
  6128.  
  6129. }
  6130.  
  6131. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  6132.  
  6133. const f = h.watchPageActiveChanged_;
  6134. const g = ump3.get(f) || function () {
  6135. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6136. }
  6137. ump3.set(f, g);
  6138. g.km34 = 1;
  6139. h.watchPageActiveChanged_ = g;
  6140.  
  6141. }
  6142.  
  6143. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  6144.  
  6145. const f = h.activate_;
  6146. const g = ump3.get(f) || function () {
  6147. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6148. }
  6149. ump3.set(f, g);
  6150. g.km34 = 1;
  6151. h.activate_ = g;
  6152.  
  6153. }
  6154. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  6155.  
  6156. const f = h.onYtPlaylistDataUpdated_;
  6157. const g = ump3.get(f) || function () {
  6158. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6159. }
  6160. ump3.set(f, g);
  6161. g.km34 = 1;
  6162. h.onYtPlaylistDataUpdated_ = g;
  6163.  
  6164. }
  6165.  
  6166.  
  6167.  
  6168. /**
  6169. *
  6170. * Neglect following
  6171. *
  6172. * h.rendererStamperObserver_
  6173. * h.rendererStamperApplyChangeRecord_
  6174. * h.flushRenderStamperComponentBindings_
  6175. * h.forwardRendererStamperChanges_
  6176. *
  6177. */
  6178.  
  6179. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  6180.  
  6181. const f = h.tryRenderChunk_;
  6182. const g = ump3.get(f) || function () {
  6183. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6184. }
  6185. ump3.set(f, g);
  6186. g.km34 = 1;
  6187. h.tryRenderChunk_ = g;
  6188.  
  6189. }
  6190.  
  6191.  
  6192. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  6193.  
  6194. const f = h.renderChunk_;
  6195. const g = ump3.get(f) || function () {
  6196. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6197. }
  6198. ump3.set(f, g);
  6199. g.km34 = 1;
  6200. h.renderChunk_ = g;
  6201.  
  6202. }
  6203.  
  6204. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  6205.  
  6206. const f = h.deepLazyListObserver_;
  6207. const g = ump3.get(f) || function () {
  6208. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6209. }
  6210. ump3.set(f, g);
  6211. g.km34 = 1;
  6212. h.deepLazyListObserver_ = g;
  6213.  
  6214. }
  6215.  
  6216. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  6217.  
  6218. const f = h.onItemsUpdated_;
  6219. const g = ump3.get(f) || function () {
  6220. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6221. }
  6222. ump3.set(f, g);
  6223. g.km34 = 1;
  6224. h.onItemsUpdated_ = g;
  6225.  
  6226. }
  6227.  
  6228. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  6229.  
  6230. const f = h.requestRenderChunk_;
  6231. const g = ump3.get(f) || function () {
  6232. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6233. }
  6234. ump3.set(f, g);
  6235. g.km34 = 1;
  6236. h.requestRenderChunk_ = g;
  6237.  
  6238. }
  6239.  
  6240. /**
  6241. *
  6242. * Neglect following
  6243. *
  6244. * h.dataChanged_ [ buggy for page swtiching ]
  6245. *
  6246. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  6247. *
  6248. * h.cancelPendingTasks_
  6249. * h.fillRange_
  6250. * h.addTextNodes_
  6251. * h.updateText_
  6252. * h.stampTypeChanged_
  6253. *
  6254. */
  6255.  
  6256.  
  6257. }
  6258.  
  6259. const keyStConnectedCallback = Symbol(); // avoid copying the value
  6260.  
  6261. // const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  6262. const cmf = new WeakMap();
  6263. const dmf = new WeakMap();
  6264.  
  6265. const gvGenerator = (nv) => {
  6266. return function () {
  6267. const cnt = insp(this);
  6268. const hostElement = cnt.hostElement || 0;
  6269. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  6270. let p = (hostElement instanceof HTMLElement_) && (dollar || !this.is);
  6271. if (p && (!dollar && !this.is)) {
  6272. const nodeName = hostElement.nodeName;
  6273. if (typeof nodeName !== 'string') {
  6274. // just in case
  6275. } else if (nodeName.startsWith("DOM-")) {
  6276. // dom-if, dom-repeat, etc
  6277. } else {
  6278. // yt element - new model, yt-xxxx, anixxxxxx
  6279. p = false;
  6280. }
  6281. }
  6282. if (p) {
  6283. if (typeof cnt.markDirty === 'function') {
  6284. // the yt element might call markDirty (occasionally)
  6285. p = false;
  6286. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  6287. // see https://github.com/cyfung1031/userscript-supports/issues/20
  6288. p = false;
  6289. }
  6290. }
  6291. if (p) {
  6292.  
  6293. // << dom-repeat & dom-if >>
  6294.  
  6295. // sequence on the same instance
  6296. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  6297. } else {
  6298. nv.apply(this, arguments);
  6299. }
  6300. };
  6301. }
  6302.  
  6303. // const assignedHolderWS = new WeakSet();
  6304.  
  6305. const setupWeakRef = (h) => {
  6306.  
  6307.  
  6308. }
  6309.  
  6310.  
  6311. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  6312.  
  6313. try {
  6314.  
  6315. const q = document.createElement('template');
  6316. q.innerHTML = '<ytz-null361></ytz-null361>';
  6317. nativeHTMLElement = q.content.firstChild.constructor
  6318.  
  6319. } catch (e) { }
  6320.  
  6321. if (!nativeHTMLElement.prototype.connectedCallback) {
  6322. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  6323. nativeHTMLElement.prototype.connectedCallback = function () {
  6324. let r;
  6325. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  6326. return r;
  6327. }
  6328. }
  6329. const pvr = Symbol()
  6330.  
  6331. let stampDomArrayMethod = null;
  6332. const setupMap = new WeakSet();
  6333.  
  6334. // const ENABLE_weakenStampReferencesQ = ENABLE_weakenStampReferences && typeof DocumentTimeline !== 'undefined' && typeof WeakRef !== 'undefined';
  6335. const setupYtComponent = (cnt) => {
  6336. const cProto = (cnt || 0).__proto__ || 0;
  6337. if (!cProto || setupMap.has(cProto)) return;
  6338. setupMap.add(cProto);
  6339. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  6340. cProto[pvr] |= 1;
  6341. if (FIX_stampDomArray && cProto.stampDomArray_ && !cProto.stampDomArray9682_) {
  6342. const b = cProto.stampDomArray_.length === 6
  6343. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  6344. && cProto.createComponent_ && cProto.createComponent_.length === 3
  6345. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  6346. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  6347. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  6348. if (!b) {
  6349. console.warn("YouTube Coding Changed. createStampDomArrayFn_() is not applied")
  6350. } else {
  6351. if (!stampDomArrayMethod) stampDomArrayMethod = createStampDomArrayFn_();
  6352. if (stampDomArrayMethod && typeof stampDomArrayMethod === 'function' && stampDomArrayMethod.length === 6) {
  6353. cProto.stampDomArray9682_ = cProto.stampDomArray_;
  6354. cProto.stampDomArray_ = stampDomArrayMethod;
  6355. } else {
  6356. console.warn("createStampDomArrayFn_() failed")
  6357. }
  6358. }
  6359. }
  6360. }
  6361. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  6362. cProto[pvr] |= 2;
  6363. setupDiscreteTasks(cProto);
  6364. }
  6365. };
  6366.  
  6367. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  6368. get() {
  6369. const f = this[keyStConnectedCallback];
  6370. if (this.is) {
  6371. setupYtComponent(this);
  6372. }
  6373. /*
  6374. if (this.is) {
  6375. setupDiscreteTasks(this, true);
  6376. if (f) this.ky36 = 1;
  6377. }
  6378. */
  6379. return f;
  6380. },
  6381. set(nv) {
  6382. let gv = nv;
  6383. /*
  6384. if (typeof nv === 'function') {
  6385.  
  6386. gv = cmf.get(nv) || gvGenerator(nv);
  6387. if (gv !== nv) {
  6388. cmf.set(nv, gv);
  6389. cmf.set(gv, gv);
  6390. dmf.set(gv, nv);
  6391. }
  6392.  
  6393. } else {
  6394. gv = nv;
  6395. }
  6396. */
  6397. this[keyStConnectedCallback] = gv; // proto or object
  6398. /*
  6399. if (this.is) {
  6400. setupDiscreteTasks(this);
  6401. }
  6402. */
  6403. return true;
  6404. },
  6405. enumerable: false,
  6406. configurable: true
  6407.  
  6408. });
  6409.  
  6410. const pLoad = new Promise(resolve => {
  6411. if (document.readyState !== 'loading') {
  6412. resolve();
  6413. } else {
  6414. window.addEventListener("DOMContentLoaded", resolve, false);
  6415. }
  6416. });
  6417.  
  6418. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  6419. window.requestIdleCallback471 = window.requestIdleCallback;
  6420. window.requestIdleCallback = function (f, ...args) {
  6421. return (this || window).requestIdleCallback471(async function () {
  6422. await pLoad.then();
  6423. // await new Promise(nextBrowserTick_);
  6424. f.call(this, ...arguments)
  6425. }, ...args);
  6426. }
  6427. }
  6428.  
  6429. pLoad.then(() => {
  6430.  
  6431. let nonce = document.querySelector('style[nonce]');
  6432. nonce = nonce ? nonce.getAttribute('nonce') : null;
  6433. const st = document.createElement('style');
  6434. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  6435. st.textContent = "none-element-k47{order:0}";
  6436. st.addEventListener('load', () => {
  6437. pf31.resolve();
  6438. p59 = 1;
  6439. }, false);
  6440. (document.body || document.head || document.documentElement).appendChild(st);
  6441.  
  6442. });
  6443.  
  6444. const prepareLogs = [];
  6445.  
  6446. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  6447.  
  6448. let winError00 = window.onerror;
  6449.  
  6450. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  6451.  
  6452. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  6453.  
  6454. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  6455.  
  6456. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  6457. const lcOpt = { sensitivity: 'base' };
  6458. document.createElement24 = document.createElement;
  6459. document.createElement = function (t) {
  6460. if (typeof t === 'string' && t.length === 6) {
  6461. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  6462. const p = this.createElement24(t);
  6463. try {
  6464. const stack = new Error().stack;
  6465. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greatest.deepsurf.us/scripts/473972-youtube-js-engine-tamer/discussions/217084
  6466. if (!isSearchbox) {
  6467. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  6468. }
  6469. } catch (e) { }
  6470. return p;
  6471. }
  6472. }
  6473. return this.createElement24.apply(this, arguments);
  6474. };
  6475.  
  6476. })();
  6477.  
  6478. ; fix_error_many_stack_state === 1 && (() => {
  6479.  
  6480.  
  6481. let p1 = winError00;
  6482.  
  6483. let stackNeedleDetails = null;
  6484.  
  6485. Object.defineProperty(Object.prototype, 'matchAll', {
  6486. get() {
  6487. stackNeedleDetails = this;
  6488. return true;
  6489. },
  6490. enumerable: true,
  6491. configurable: true
  6492. });
  6493.  
  6494. try {
  6495. JSON.parse("{}");
  6496. } catch (e) {
  6497. console.warn(e)
  6498. fix_error_many_stack_state = 0;
  6499. }
  6500.  
  6501. delete Object.prototype['matchAll'];
  6502.  
  6503. let p2 = window.onerror;
  6504.  
  6505. window.onerror = p1;
  6506.  
  6507. if (fix_error_many_stack_state === 0) return;
  6508.  
  6509. if (stackNeedleDetails) {
  6510. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  6511. stackNeedleDetails.matchAll = true;
  6512. }
  6513.  
  6514. if (p1 === p2) return (fix_error_many_stack_state = 0);
  6515.  
  6516. // p1!==p2
  6517. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  6518.  
  6519. })();
  6520.  
  6521. ; fix_error_many_stack_state === 2 && (() => {
  6522.  
  6523.  
  6524. let p1 = winError00;
  6525.  
  6526. let objectPrune = null;
  6527. let stackNeedleDetails = null;
  6528.  
  6529. Object.defineProperty(Function.prototype, 'findOwner', {
  6530. get() {
  6531. objectPrune = this;
  6532. return this._findOwner;
  6533. },
  6534. set(nv) {
  6535. this._findOwner = nv;
  6536. return true;
  6537. },
  6538. enumerable: true,
  6539. configurable: true
  6540. });
  6541.  
  6542. Object.defineProperty(Object.prototype, 'matchAll', {
  6543. get() {
  6544. stackNeedleDetails = this;
  6545. return true;
  6546. },
  6547. enumerable: true,
  6548. configurable: true
  6549. });
  6550.  
  6551. try {
  6552. JSON.parse("{}");
  6553. } catch (e) {
  6554. console.warn(e)
  6555. fix_error_many_stack_state = 0;
  6556. }
  6557.  
  6558. delete Function.prototype['findOwner'];
  6559. delete Object.prototype['matchAll'];
  6560.  
  6561. let p2 = window.onerror;
  6562.  
  6563. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  6564.  
  6565. if (fix_error_many_stack_state == 0) return;
  6566.  
  6567. // the following will only execute when Brave's scriptlets.js is executed.
  6568.  
  6569. prepareLogs.push("fix_error_many_stack_state NB")
  6570.  
  6571. if (stackNeedleDetails) {
  6572. stackNeedleDetails.pattern = null;
  6573. stackNeedleDetails.re = null;
  6574. stackNeedleDetails.expect = null;
  6575. stackNeedleDetails.matchAll = true;
  6576. }
  6577.  
  6578. if (objectPrune) {
  6579. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  6580. delete objectPrune._findOwner;
  6581. }
  6582.  
  6583. fix_error_many_stack_state = 3;
  6584. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  6585. JSON.parse.objectPrune = objectPrune;
  6586.  
  6587. })();
  6588.  
  6589. ; fix_error_many_stack_state === 3 && (() => {
  6590.  
  6591.  
  6592. let p1 = winError00;
  6593.  
  6594. try {
  6595. JSON.parse("{}");
  6596. } catch (e) {
  6597. console.warn(e)
  6598. fix_error_many_stack_state = 0;
  6599. }
  6600.  
  6601. let p2 = window.onerror;
  6602.  
  6603. if (p1 === p2) return;
  6604.  
  6605. window.onerror = p1;
  6606.  
  6607. if (fix_error_many_stack_state === 0) return;
  6608.  
  6609. fix_error_many_stack_state = 4; // p1 != p2
  6610.  
  6611.  
  6612. })();
  6613.  
  6614. fix_error_many_stack_state === 4 && (() => {
  6615.  
  6616. // the following will only execute when Brave's scriptlets.js is executed.
  6617.  
  6618. prepareLogs.push("fix_error_many_stack_state AB")
  6619.  
  6620. JSON.parseProxy = JSON.parse;
  6621.  
  6622. JSON.parse = ((parse) => {
  6623.  
  6624. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  6625. return function (text, reviver) {
  6626. const onerror = window.onerror;
  6627. window.onerror = null;
  6628. let r;
  6629. try {
  6630. r = parse(...arguments);
  6631. } catch (e) {
  6632. r = e;
  6633. }
  6634. window.onerror = onerror;
  6635. if (r instanceof Error) {
  6636. throw r;
  6637. }
  6638. return r;
  6639. }
  6640.  
  6641. })(JSON.parse);
  6642.  
  6643.  
  6644. })();
  6645.  
  6646.  
  6647. // << if FIX_yt_player >>
  6648.  
  6649. // credit to @nopeless (https://greatest.deepsurf.us/scripts/471489-youtube-player-perf/)
  6650. const PERF_471489_ = true;
  6651. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  6652. // This script uses a much gentle way to tamer the JS engine instead.
  6653.  
  6654. // << end >>
  6655.  
  6656. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  6657.  
  6658.  
  6659.  
  6660. const nilFn = () => { };
  6661.  
  6662. let isMainWindow = false;
  6663. try {
  6664. isMainWindow = window.document === window.top.document
  6665. } catch (e) { }
  6666.  
  6667. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  6668. let headLinkCollection = null;
  6669.  
  6670.  
  6671. // const assertor = (f) => f() || console.assert(false, `${f}`);
  6672.  
  6673. const fnIntegrity = (f, d) => {
  6674. if (!f || typeof f !== 'function') {
  6675. console.warn('f is not a function', f);
  6676. return;
  6677. }
  6678. let p = `${f}`, s = 0, j = -1, w = 0;
  6679. for (let i = 0, l = p.length; i < l; i++) {
  6680. const t = p[i];
  6681. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  6682. if (j < i - 1) w++;
  6683. j = i;
  6684. } else {
  6685. s++;
  6686. }
  6687. }
  6688. let itz = `${f.length}.${s}.${w}`;
  6689. if (!d) {
  6690. return itz;
  6691. } else {
  6692. return itz === d;
  6693. }
  6694. };
  6695.  
  6696. const getZqOu = (_yt_player) => {
  6697.  
  6698. const w = 'ZqOu';
  6699.  
  6700. let arr = [];
  6701.  
  6702. for (const [k, v] of Object.entries(_yt_player)) {
  6703.  
  6704. const p = typeof v === 'function' ? v.prototype : 0;
  6705. if (p
  6706. && typeof p.start === 'function' && p.start.length === 0 // Ou
  6707. && typeof p.isActive === 'function' && p.isActive.length === 0
  6708. && typeof p.stop === 'function' && p.stop.length === 0
  6709. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  6710. && !p.send && !p.abort
  6711. && !p.sample && !p.initialize && !p.fail && !p.getName
  6712. // && !p.dispose && !p.isDisposed
  6713.  
  6714. ) {
  6715. arr = addProtoToArr(_yt_player, k, arr) || arr;
  6716.  
  6717.  
  6718. }
  6719.  
  6720. }
  6721.  
  6722. if (arr.length === 0) {
  6723.  
  6724. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  6725. } else {
  6726.  
  6727. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  6728. return arr[0];
  6729. }
  6730.  
  6731. }
  6732.  
  6733. const getZqQu = (_yt_player) => {
  6734.  
  6735. const w = 'ZqQu';
  6736.  
  6737. let arr = [];
  6738.  
  6739.  
  6740. for (const [k, v] of Object.entries(_yt_player)) {
  6741.  
  6742. const p = typeof v === 'function' ? v.prototype : 0;
  6743. if (p
  6744. && typeof p.start === 'function' && p.start.length === 1 // Qu
  6745. && typeof p.isActive === 'function' && p.isActive.length === 0
  6746. && typeof p.stop === 'function' && p.stop.length === 0
  6747. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  6748. && !p.send && !p.abort
  6749. && !p.sample && !p.initialize && !p.fail && !p.getName
  6750. // && !p.dispose && !p.isDisposed
  6751.  
  6752. ) {
  6753. arr = addProtoToArr(_yt_player, k, arr) || arr;
  6754.  
  6755.  
  6756. }
  6757.  
  6758. }
  6759.  
  6760. if (arr.length === 0) {
  6761.  
  6762. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  6763. } else {
  6764.  
  6765. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  6766. return arr[0];
  6767. }
  6768.  
  6769. }
  6770.  
  6771.  
  6772. const getVG = (_yt_player) => {
  6773. const w = 'VG';
  6774.  
  6775. let arr = [];
  6776.  
  6777. for (const [k, v] of Object.entries(_yt_player)) {
  6778.  
  6779. const p = typeof v === 'function' ? v.prototype : 0;
  6780. if (p
  6781. && typeof p.show === 'function' && p.show.length === 1
  6782. && typeof p.hide === 'function' && p.hide.length === 0
  6783. && typeof p.stop === 'function' && p.stop.length === 0) {
  6784.  
  6785. arr = addProtoToArr(_yt_player, k, arr) || arr;
  6786.  
  6787. }
  6788.  
  6789. }
  6790.  
  6791.  
  6792. if (arr.length === 0) {
  6793.  
  6794. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  6795. } else {
  6796.  
  6797. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  6798. return arr[0];
  6799. }
  6800.  
  6801.  
  6802.  
  6803. }
  6804.  
  6805.  
  6806. const getzo = (_yt_player) => {
  6807. const w = 'zo';
  6808.  
  6809. let arr = [];
  6810.  
  6811. for (const [k, v] of Object.entries(_yt_player)) {
  6812.  
  6813. if (
  6814. typeof v === 'function' && v.length === 3 && k.length < 3
  6815. ) {
  6816. const vt = `${v}`;
  6817. if (vt.length >= 21 && vt.includes(".style[")) {
  6818. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  6819. arr.push(k);
  6820. } else {
  6821. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  6822. }
  6823. }
  6824. }
  6825.  
  6826. }
  6827.  
  6828. if (arr.length === 0) {
  6829.  
  6830. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  6831. } else {
  6832.  
  6833. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  6834. return arr[0];
  6835. }
  6836.  
  6837. }
  6838.  
  6839. const addProtoToArr = (parent, key, arr) => {
  6840.  
  6841.  
  6842. let isChildProto = false;
  6843. for (const sr of arr) {
  6844. if (parent[key].prototype instanceof parent[sr]) {
  6845. isChildProto = true;
  6846. break;
  6847. }
  6848. }
  6849.  
  6850. if (isChildProto) return;
  6851.  
  6852. arr = arr.filter(sr => {
  6853. if (parent[sr].prototype instanceof parent[key]) {
  6854. return false;
  6855. }
  6856. return true;
  6857. });
  6858.  
  6859. arr.push(key);
  6860.  
  6861. return arr;
  6862.  
  6863.  
  6864. }
  6865.  
  6866. const getuG = (_yt_player) => {
  6867.  
  6868. const w = 'uG';
  6869.  
  6870. let arr = [];
  6871.  
  6872. for (const [k, v] of Object.entries(_yt_player)) {
  6873.  
  6874.  
  6875. const p = typeof v === 'function' ? v.prototype : 0;
  6876.  
  6877. if (p
  6878. && typeof p.createElement === 'function' && p.createElement.length === 2
  6879. && typeof p.detach === 'function' && p.detach.length === 0
  6880. && typeof p.update === 'function' && p.update.length === 1
  6881. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  6882. ) {
  6883.  
  6884. arr = addProtoToArr(_yt_player, k, arr) || arr;
  6885.  
  6886. }
  6887.  
  6888. }
  6889.  
  6890.  
  6891.  
  6892.  
  6893.  
  6894. if (arr.length === 0) {
  6895.  
  6896. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  6897. } else {
  6898.  
  6899. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  6900. return arr[0];
  6901. }
  6902.  
  6903. }
  6904.  
  6905.  
  6906. const getQT = (_yt_player) => {
  6907. const w = 'QT';
  6908.  
  6909. let arr = [];
  6910. let brr = new Map();
  6911.  
  6912. for (const [k, v] of Object.entries(_yt_player)) {
  6913.  
  6914. const p = typeof v === 'function' ? v.prototype : 0;
  6915. if (p) {
  6916. let q = 0;
  6917. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  6918. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  6919. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  6920.  
  6921. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  6922.  
  6923. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  6924.  
  6925. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  6926. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  6927. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  6928. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  6929.  
  6930.  
  6931. // differentiate QT and DX
  6932.  
  6933. q += 280;
  6934. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  6935. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  6936. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  6937. if (typeof p.seekBy === 'function') q += 4;
  6938. if (typeof p.seekTo === 'function') q += 4;
  6939. if (typeof p.getStoryboardFormat === 'function') q += 4;
  6940. if (typeof p.getDuration === 'function') q += 4;
  6941. if (typeof p.loadModule === 'function') q += 4;
  6942. if (typeof p.unloadModule === 'function') q += 4;
  6943. if (typeof p.getOption === 'function') q += 4;
  6944. if (typeof p.getOptions === 'function') q += 4;
  6945. if (typeof p.setOption === 'function') q += 4;
  6946. if (typeof p.addCueRange === 'function') q += 4;
  6947. if (typeof p.getDebugText === 'function') q += 4;
  6948. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  6949. if (typeof p.setSizeStyle === 'function') q += 4;
  6950. if (typeof p.showControls === 'function') q += 4;
  6951. if (typeof p.hideControls === 'function') q += 4;
  6952. if (typeof p.getVideoContentRect === 'function') q += 4;
  6953. if (typeof p.toggleFullscreen === 'function') q += 4;
  6954. if (typeof p.isFullscreen === 'function') q += 4;
  6955. if (typeof p.cancelPlayback === 'function') q += 4;
  6956. if (typeof p.getProgressState === 'function') q += 4;
  6957. if (typeof p.isInline === 'function') q += 4;
  6958. if (typeof p.setInline === 'function') q += 4;
  6959. if (typeof p.toggleSubtitles === 'function') q += 4;
  6960. if (typeof p.getPlayerSize === 'function') q += 4;
  6961. if (typeof p.wakeUpControls === 'function') q += 4;
  6962. if (typeof p.setCenterCrop === 'function') q += 4;
  6963. if (typeof p.getLoopVideo === 'function') q += 4;
  6964. if (typeof p.setLoopVideo === 'function') q += 4;
  6965.  
  6966.  
  6967. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  6968.  
  6969. if (q > 0) brr.set(k, q);
  6970.  
  6971. }
  6972.  
  6973. }
  6974.  
  6975. if (arr.length === 0) {
  6976.  
  6977. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  6978. } else {
  6979.  
  6980. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  6981.  
  6982. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  6983.  
  6984. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  6985. return arr[0][0];
  6986. }
  6987.  
  6988.  
  6989.  
  6990. }
  6991.  
  6992.  
  6993.  
  6994. const getSV = (_yt_player) => {
  6995. const w = 'SV';
  6996.  
  6997. let arr = [];
  6998. let brr = new Map();
  6999.  
  7000. for (const [k, v] of Object.entries(_yt_player)) {
  7001.  
  7002. const p = typeof v === 'function' ? v.prototype : 0;
  7003. if (p) {
  7004. let q = 0;
  7005. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7006. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7007. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7008.  
  7009. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  7010.  
  7011. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7012.  
  7013. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7014. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7015. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7016. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7017.  
  7018.  
  7019. // differentiate QT and DX
  7020.  
  7021.  
  7022. q += 280;
  7023.  
  7024. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7025. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7026. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7027. if (typeof p.seekBy === 'function') q -= 4;
  7028. if (typeof p.seekTo === 'function') q -= 4;
  7029. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7030. if (typeof p.getDuration === 'function') q -= 4;
  7031. if (typeof p.loadModule === 'function') q -= 4;
  7032. if (typeof p.unloadModule === 'function') q -= 4;
  7033. if (typeof p.getOption === 'function') q -= 4;
  7034. if (typeof p.getOptions === 'function') q -= 4;
  7035. if (typeof p.setOption === 'function') q -= 4;
  7036. if (typeof p.addCueRange === 'function') q -= 4;
  7037. if (typeof p.getDebugText === 'function') q -= 4;
  7038. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7039. if (typeof p.setSizeStyle === 'function') q -= 4;
  7040. if (typeof p.showControls === 'function') q -= 4;
  7041. if (typeof p.hideControls === 'function') q -= 4;
  7042. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7043. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7044. if (typeof p.isFullscreen === 'function') q -= 4;
  7045. if (typeof p.cancelPlayback === 'function') q -= 4;
  7046. if (typeof p.getProgressState === 'function') q -= 4;
  7047. if (typeof p.isInline === 'function') q -= 4;
  7048. if (typeof p.setInline === 'function') q -= 4;
  7049. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7050. if (typeof p.getPlayerSize === 'function') q -= 4;
  7051. if (typeof p.wakeUpControls === 'function') q -= 4;
  7052. if (typeof p.setCenterCrop === 'function') q -= 4;
  7053. if (typeof p.getLoopVideo === 'function') q -= 4;
  7054. if (typeof p.setLoopVideo === 'function') q -= 4;
  7055.  
  7056.  
  7057. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7058.  
  7059. if (q > 0) brr.set(k, q);
  7060.  
  7061. }
  7062.  
  7063. }
  7064.  
  7065. if (arr.length === 0) {
  7066.  
  7067. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7068. } else {
  7069.  
  7070. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7071.  
  7072. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7073.  
  7074. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7075. return arr[0][0];
  7076. }
  7077.  
  7078.  
  7079.  
  7080. }
  7081.  
  7082.  
  7083.  
  7084.  
  7085. const getDX = (_yt_player) => {
  7086. const w = 'DX';
  7087.  
  7088. let arr = [];
  7089. let brr = new Map();
  7090.  
  7091. for (const [k, v] of Object.entries(_yt_player)) {
  7092.  
  7093. const p = typeof v === 'function' ? v.prototype : 0;
  7094. if (p) {
  7095. let q = 0;
  7096. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7097. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7098. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7099.  
  7100. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7101.  
  7102.  
  7103. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  7104.  
  7105. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7106.  
  7107. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7108. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7109. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7110. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7111.  
  7112.  
  7113. // differentiate QT and DX
  7114.  
  7115.  
  7116. q += 280;
  7117.  
  7118. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7119. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7120. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7121. if (typeof p.seekBy === 'function') q -= 4;
  7122. if (typeof p.seekTo === 'function') q -= 4;
  7123. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7124. if (typeof p.getDuration === 'function') q -= 4;
  7125. if (typeof p.loadModule === 'function') q -= 4;
  7126. if (typeof p.unloadModule === 'function') q -= 4;
  7127. if (typeof p.getOption === 'function') q -= 4;
  7128. if (typeof p.getOptions === 'function') q -= 4;
  7129. if (typeof p.setOption === 'function') q -= 4;
  7130. if (typeof p.addCueRange === 'function') q -= 4;
  7131. if (typeof p.getDebugText === 'function') q -= 4;
  7132. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7133. if (typeof p.setSizeStyle === 'function') q -= 4;
  7134. if (typeof p.showControls === 'function') q -= 4;
  7135. if (typeof p.hideControls === 'function') q -= 4;
  7136. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7137. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7138. if (typeof p.isFullscreen === 'function') q -= 4;
  7139. if (typeof p.cancelPlayback === 'function') q -= 4;
  7140. if (typeof p.getProgressState === 'function') q -= 4;
  7141. if (typeof p.isInline === 'function') q -= 4;
  7142. if (typeof p.setInline === 'function') q -= 4;
  7143. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7144. if (typeof p.getPlayerSize === 'function') q -= 4;
  7145. if (typeof p.wakeUpControls === 'function') q -= 4;
  7146. if (typeof p.setCenterCrop === 'function') q -= 4;
  7147. if (typeof p.getLoopVideo === 'function') q -= 4;
  7148. if (typeof p.setLoopVideo === 'function') q -= 4;
  7149.  
  7150.  
  7151. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7152.  
  7153. if (q > 0) brr.set(k, q);
  7154.  
  7155. }
  7156.  
  7157. }
  7158.  
  7159. if (arr.length === 0) {
  7160.  
  7161. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7162. } else {
  7163.  
  7164. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7165.  
  7166. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7167.  
  7168. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7169. return arr[0][0];
  7170. }
  7171.  
  7172.  
  7173.  
  7174. }
  7175.  
  7176.  
  7177.  
  7178. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  7179.  
  7180. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  7181. let pageSetupState = 0;
  7182.  
  7183. isPrepareCachedV && (() => {
  7184.  
  7185. pageSetupVideoId = '';
  7186. const clearCachedV = () => {
  7187. pageSetupVideoId = '';
  7188. pageSetupState = 0;
  7189. }
  7190. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  7191. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  7192. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  7193. document.addEventListener('yt-navigate-finish', () => {
  7194. pageSetupState = 1;
  7195. try {
  7196. const url = new URL(location.href);
  7197. if (!url || !isWatchPageURL(url)) {
  7198. pageSetupVideoId = '';
  7199. } else {
  7200. pageSetupVideoId = url.searchParams.get('v') || '';
  7201. }
  7202. } catch (e) {
  7203. pageSetupVideoId = '';
  7204. }
  7205. }, false);
  7206.  
  7207. })();
  7208.  
  7209. let videoPlayingY = null;
  7210.  
  7211. isPrepareCachedV && (() => {
  7212.  
  7213. let getNext = true;
  7214. let videoPlayingX = {
  7215. get videoId() {
  7216. if (getNext) {
  7217. getNext = false;
  7218.  
  7219. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  7220. const arr = [];
  7221. for (const element of elements) {
  7222. if (!element.closest('[hidden]')) arr.push(element);
  7223. }
  7224. if (arr.length !== 1) this.__videoId__ = '';
  7225. else {
  7226. this.__videoId__ = arr[0].getAttribute('video-id');
  7227. }
  7228.  
  7229. }
  7230. return this.__videoId__ || '';
  7231. }
  7232. }
  7233.  
  7234. videoPlayingY = videoPlayingX;
  7235. const handler = (evt) => {
  7236. const target = (evt || 0).target;
  7237. if (target instanceof HTMLVideoElement) {
  7238. getNext = true;
  7239. }
  7240. }
  7241. document.addEventListener('loadedmetadata', handler, true);
  7242. document.addEventListener('durationchange', handler, true);
  7243.  
  7244. })();
  7245.  
  7246.  
  7247.  
  7248. const cleanContext = async (win) => {
  7249. const waitFn = requestAnimationFrame; // shall have been binded to window
  7250. try {
  7251. let mx = 16; // MAX TRIAL
  7252. const frameId = 'vanillajs-iframe-v1';
  7253. /** @type {HTMLIFrameElement | null} */
  7254. let frame = document.getElementById(frameId);
  7255. let removeIframeFn = null;
  7256. if (!frame) {
  7257. frame = document.createElement('iframe');
  7258. frame.id = frameId;
  7259. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  7260. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  7261. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  7262. n.appendChild(frame);
  7263. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  7264. const root = document.documentElement;
  7265. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  7266. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  7267.  
  7268. removeIframeFn = (setTimeout) => {
  7269. const removeIframeOnDocumentReady = (e) => {
  7270. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7271. e = n;
  7272. n = win = removeIframeFn = 0;
  7273. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  7274. }
  7275. if (!setTimeout || document.readyState !== 'loading') {
  7276. removeIframeOnDocumentReady();
  7277. } else {
  7278. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7279. }
  7280. }
  7281. }
  7282. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  7283. const fc = frame.contentWindow;
  7284. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  7285. try {
  7286. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  7287. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  7288. for (let k in res) res[k] = res[k].bind(win); // necessary
  7289. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  7290. res.animate = fc.HTMLElement.prototype.animate;
  7291. res.perfNow = fc.performance.now;
  7292. return res;
  7293. } catch (e) {
  7294. if (removeIframeFn) removeIframeFn();
  7295. return null;
  7296. }
  7297. } catch (e) {
  7298. console.warn(e);
  7299. return null;
  7300. }
  7301. };
  7302.  
  7303. const promiseForYtActionCalled = new Promise(resolve => {
  7304.  
  7305. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  7306. if (typeof AbortSignal !== 'undefined') {
  7307. let hn = () => {
  7308. if (!hn) return;
  7309. hn = null;
  7310. resolve(document.querySelector(appTag));
  7311. };
  7312. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  7313. } else {
  7314. let hn = () => {
  7315. if (!hn) return;
  7316. document.removeEventListener('yt-action', hn, true);
  7317. hn = null;
  7318. resolve(document.querySelector(appTag));
  7319. };
  7320. document.addEventListener('yt-action', hn, true);
  7321. }
  7322. });
  7323.  
  7324. cleanContext(window).then(__CONTEXT__ => {
  7325. if (!__CONTEXT__) return null;
  7326.  
  7327. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  7328.  
  7329.  
  7330. performance.now17 = perfNow.bind(performance);
  7331.  
  7332.  
  7333.  
  7334. __requestAnimationFrame__ = requestAnimationFrame;
  7335.  
  7336.  
  7337. const isGPUAccelerationAvailable = (() => {
  7338. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  7339. try {
  7340. const canvas = document.createElement('canvas');
  7341. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  7342. } catch (e) {
  7343. return false;
  7344. }
  7345. })();
  7346.  
  7347. const foregroundPromiseFn_noGPU = (() => {
  7348.  
  7349. if (isGPUAccelerationAvailable) return null;
  7350.  
  7351. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  7352. if (!pd || typeof pd.get !== 'function') return null;
  7353. const pdGet = pd.get;
  7354.  
  7355. let pr = null;
  7356.  
  7357. let hState = pdGet.call(document) === 'hidden';
  7358. // let cid = 0;
  7359. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  7360. const newHState = pdGet.call(document) === 'hidden';
  7361. if (hState !== newHState) {
  7362. // if (cid > 0) cid = clearInterval(cid);
  7363. hState = newHState;
  7364. if (!hState && pr) pr = pr.resolve();
  7365. }
  7366. });
  7367.  
  7368. // cid = setInterval(() => {
  7369. // const newHState = document.visibilityState === 'hidden';
  7370. // if (hState !== newHState) {
  7371. // hState = newHState;
  7372. // if (!hState && pr) pr = pr.resolve();
  7373. // }
  7374. // }, 100);
  7375.  
  7376.  
  7377. return (() => {
  7378. if (pr) return pr;
  7379. const w = ((!hState && setTimeout(() => {
  7380. if (!hState && pr === w) pr = pr.resolve();
  7381. })), (pr = new PromiseExternal()));
  7382. return w;
  7383. });
  7384.  
  7385. })();
  7386.  
  7387.  
  7388. let rafPromise = null;
  7389. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  7390. requestAnimationFrame(hRes => {
  7391. rafPromise = null;
  7392. resolve(hRes);
  7393. });
  7394. }));
  7395.  
  7396. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  7397.  
  7398.  
  7399. const wmComputedStyle = new WeakMap();
  7400.  
  7401. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  7402. window.__native__getComputedStyle__ = getComputedStyle;
  7403. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  7404. window.__original__getComputedStyle__ = window.getComputedStyle;
  7405. window.getComputedStyle = function (elem) {
  7406. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  7407. return window.__original__getComputedStyle__(...arguments);
  7408. }
  7409. let cs = wmComputedStyle.get(elem);
  7410. if (!cs) {
  7411. cs = window.__native__getComputedStyle__(elem);
  7412. wmComputedStyle.set(elem, cs);
  7413. }
  7414. return cs;
  7415. };
  7416. } else {
  7417. window.__original__getComputedStyle__ = null;
  7418. }
  7419. window.__jst__getComputedStyle__ = window.getComputedStyle;
  7420. }
  7421.  
  7422. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  7423. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  7424. window.getComputedStyle = window.__jst__getComputedStyle__;
  7425. }
  7426. });
  7427.  
  7428. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  7429. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  7430.  
  7431. const promiseForTamerTimeout = new Promise(resolve => {
  7432. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  7433. setTimeout(resolve, 480);
  7434. }, { capture: true, passive: true, once: true });
  7435. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  7436. setTimeout(resolve, 1200);
  7437. });
  7438. setTimeout(resolve, 3000);
  7439. });
  7440.  
  7441. const promiseForPageInitied = new Promise(resolve => {
  7442. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  7443. setTimeout(resolve, 450);
  7444. }, { capture: true, passive: true, once: true });
  7445. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  7446. setTimeout(resolve, 900);
  7447. });
  7448. setTimeout(resolve, 1800);
  7449. });
  7450.  
  7451. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  7452. NO_PRELOAD_GENERATE_204_BYPASS = true;
  7453. headLinkCollection = null;
  7454. });
  7455.  
  7456.  
  7457. NATIVE_CANVAS_ANIMATION && (() => {
  7458.  
  7459. observablePromise(() => {
  7460. HTMLCanvasElement.prototype.animate = animate;
  7461. }, promiseForTamerTimeout).obtain();
  7462.  
  7463. })();
  7464.  
  7465.  
  7466.  
  7467.  
  7468. FIX_ytAction_ && (async () => {
  7469.  
  7470. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  7471.  
  7472. const ytdApp = await new Promise(resolve => {
  7473.  
  7474. whenCEDefined(appTag).then(() => {
  7475. const ytdApp = document.querySelector(appTag);
  7476. if (ytdApp) {
  7477. resolve(ytdApp);
  7478. return;
  7479. }
  7480. let mo = new MutationObserver(() => {
  7481. const ytdApp = document.querySelector(appTag);
  7482. if (!ytdApp) return;
  7483. if (mo) {
  7484. mo.disconnect();
  7485. mo.takeRecords();
  7486. mo = null;
  7487. }
  7488. resolve(ytdApp);
  7489. });
  7490. mo.observe(document, { subtree: true, childList: true });
  7491. });
  7492.  
  7493. });
  7494.  
  7495. if (!ytdApp) return;
  7496. const cProto = insp(ytdApp).constructor.prototype;
  7497.  
  7498. if (!cProto) return;
  7499. let mbd = 0;
  7500.  
  7501. const fixer = (_ytdApp) => {
  7502. const ytdApp = insp(_ytdApp);
  7503. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  7504. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  7505. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  7506. mbd++;
  7507. }
  7508. }
  7509.  
  7510. observablePromise(() => {
  7511.  
  7512. if (typeof cProto.created === 'function' && !cProto.created56) {
  7513. cProto.created56 = cProto.created;
  7514. cProto.created = function (...args) {
  7515. const r = this.created56(...args);
  7516. fixer(this);
  7517. return r;
  7518. };
  7519. mbd++;
  7520. }
  7521.  
  7522. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  7523. cProto.onYtAction57_ = cProto.onYtAction_;
  7524. cProto.onYtAction_ = function (...args) {
  7525. Promise.resolve().then(() => this.onYtAction57_(...args));
  7526. };
  7527. mbd++;
  7528. }
  7529.  
  7530. if (ytdApp) fixer(ytdApp);
  7531.  
  7532. /*
  7533. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  7534. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  7535. actionRouter_.handleAction57 = actionRouter_.handleAction;
  7536. actionRouter_.handleAction = function (...args) {
  7537. Promise.resolve().then(() => this.handleAction57(...args));
  7538. }
  7539. mbd++;
  7540. }
  7541. */
  7542.  
  7543. // if(mbd === 3) return 1;
  7544. if (mbd >= 3) return 1;
  7545.  
  7546. }, new Promise(r => setTimeout(r, 1000))).obtain();
  7547.  
  7548. })();
  7549.  
  7550.  
  7551. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  7552.  
  7553. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  7554.  
  7555. const app = await observablePromise(() => {
  7556.  
  7557. return document.querySelector(appTag);
  7558.  
  7559. }).obtain();
  7560.  
  7561. if (!app) return;
  7562.  
  7563. const appCnt = insp(app);
  7564. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  7565.  
  7566.  
  7567.  
  7568.  
  7569. });
  7570.  
  7571. const observablePromise = (proc, timeoutPromise) => {
  7572. let promise = null;
  7573. return {
  7574. obtain() {
  7575. if (!promise) {
  7576. promise = new Promise(resolve => {
  7577. let mo = null;
  7578. const f = () => {
  7579. let t = proc();
  7580. if (t) {
  7581. mo.disconnect();
  7582. mo.takeRecords();
  7583. mo = null;
  7584. resolve(t);
  7585. }
  7586. }
  7587. mo = new MutationObserver(f);
  7588. mo.observe(document, { subtree: true, childList: true })
  7589. f();
  7590. timeoutPromise && timeoutPromise.then(() => {
  7591. resolve(null)
  7592. });
  7593. });
  7594. }
  7595. return promise
  7596. }
  7597. }
  7598. }
  7599.  
  7600. // let _yt_player_promise = null;
  7601. /*
  7602. const getYtPlayerPromise = () => {
  7603. if (!_yt_player_promise) {
  7604. _yt_player_promise = new Promise(resolve => {
  7605. let cid = setInterval(() => {
  7606. let t = (((window || 0)._yt_player || 0) || 0);
  7607. if (t) {
  7608. clearInterval(cid);
  7609. resolve(t);
  7610. }
  7611. }, 1);
  7612. promiseForTamerTimeout.then(() => {
  7613. resolve(null)
  7614. });
  7615. });
  7616. }
  7617. return _yt_player_promise;
  7618. }
  7619. */
  7620. const _yt_player_observable = observablePromise(() => {
  7621. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  7622. if (_yt_player) {
  7623. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  7624. return _yt_player;
  7625. }
  7626. }, promiseForTamerTimeout);
  7627.  
  7628. const polymerObservable = observablePromise(() => {
  7629. const Polymer = window.Polymer;
  7630. if (typeof Polymer !== 'function') return;
  7631. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  7632. return Polymer;
  7633. }, promiseForTamerTimeout);
  7634.  
  7635. const schedulerInstanceObservable = observablePromise(() => {
  7636. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  7637. }, promiseForTamerTimeout);
  7638.  
  7639. const timelineObservable = observablePromise(() => {
  7640. let t = (((document || 0).timeline || 0) || 0);
  7641. if (t && typeof t._play === 'function') {
  7642. return t;
  7643. }
  7644. }, promiseForTamerTimeout);
  7645. const animationObservable = observablePromise(() => {
  7646. let t = (((window || 0).Animation || 0) || 0);
  7647. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  7648. return t;
  7649. }
  7650. }, promiseForTamerTimeout);
  7651.  
  7652.  
  7653. const getScreenInfo = {
  7654. screenWidth: 0,
  7655. screenHeight: 0,
  7656. valueReady: false,
  7657. onResize: () => {
  7658. getScreenInfo.valueReady = false;
  7659. },
  7660. sizeProvided: () => {
  7661. if (getScreenInfo.valueReady) return true;
  7662. getScreenInfo.screenWidth = screen.width;
  7663. getScreenInfo.screenHeight = screen.height;
  7664. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  7665. getScreenInfo.valueReady = true;
  7666. return true;
  7667. }
  7668. return false;
  7669. }
  7670. };
  7671.  
  7672. window.addEventListener('resize', getScreenInfo.onResize, true);
  7673.  
  7674.  
  7675. // const hookLeftPending = new WeakMap();
  7676.  
  7677. const isNaNx = Number.isNaN;
  7678.  
  7679. const hookLeftPD = {
  7680. get() {
  7681. const p = 'left';
  7682. // const o = hookLeftPending.get(this);
  7683. // if (o && o.key) {
  7684. // this.setProperty(p, o.value);
  7685. // o.key = null
  7686. // }
  7687. return this.getPropertyValue(p);
  7688. },
  7689. set(v) {
  7690.  
  7691. const p = 'left';
  7692. const cv = this.getPropertyValue(p);
  7693. const sv = v;
  7694.  
  7695. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  7696.  
  7697. // console.log(8380,did, cv, sv)
  7698. if (!cv && !sv) return true;
  7699. if (cv === sv) return true;
  7700.  
  7701. // skip 0~9px => L>=4
  7702.  
  7703. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  7704.  
  7705. if (!isNaNx(qsv)) {
  7706. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  7707.  
  7708. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  7709. const { screenWidth, screenHeight } = getScreenInfo;
  7710. let pWidth = screenWidth + 1024;
  7711. let pHeight = screenHeight + 768;
  7712. const minRatio = 0.003;
  7713. const dw = pWidth * 0.0003; // min dw = 0.3072
  7714. const dh = pHeight * 0.0003; // min dh = 0.2304
  7715. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  7716. if (Math.abs(qcv - qsv) < dw) return true;
  7717. }
  7718.  
  7719. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  7720. if (`${v}`.length > `${sv}`.length) v = sv;
  7721. // console.log(8382, did, sv, nv, cv, this)
  7722. }
  7723.  
  7724. // Promise.resolve().then(() => {
  7725. // const o = hookLeftPending.get(this);
  7726. // if (o && o.key === did) {
  7727. // this.setProperty(p, o.value);
  7728. // o.key = null;
  7729. // }
  7730. // });
  7731. // hookLeftPending.set(this, {
  7732. // key: did,
  7733. // value: nv
  7734. // });
  7735.  
  7736. // if (nv != v) {
  7737. // console.log(8387, v, nv);
  7738. // }
  7739.  
  7740. this.setProperty(p, v);
  7741. // console.log(8383, did, this.getPropertyValue(p))
  7742. return true;
  7743. },
  7744. enumerable: true,
  7745. configurable: true
  7746. };
  7747.  
  7748.  
  7749. if (HOOK_CSSPD_LEFT) {
  7750.  
  7751.  
  7752. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  7753.  
  7754. }
  7755.  
  7756.  
  7757.  
  7758.  
  7759.  
  7760. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  7761.  
  7762. const evKey = `${_evKey}`;
  7763. const fvKey = `${_fvKey}`;
  7764. const debug = !!_debug;
  7765.  
  7766. const _yt_player = await _yt_player_observable.obtain();
  7767.  
  7768.  
  7769. if (!_yt_player || typeof _yt_player !== 'object') return;
  7770.  
  7771.  
  7772. const getArr = (_yt_player) => {
  7773.  
  7774. let arr = [];
  7775.  
  7776. for (const [k, v] of Object.entries(_yt_player)) {
  7777.  
  7778. const p = typeof v === 'function' ? v.prototype : 0;
  7779. if (p
  7780. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  7781.  
  7782. ) {
  7783. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7784.  
  7785. }
  7786.  
  7787. }
  7788.  
  7789. if (arr.length === 0) {
  7790.  
  7791. console.warn(`Key prop [${evKey}] does not exist.`);
  7792. } else {
  7793.  
  7794. return arr;
  7795. }
  7796.  
  7797. };
  7798.  
  7799. const arr = getArr(_yt_player);
  7800.  
  7801.  
  7802. if (!arr) return;
  7803.  
  7804. debug && console.log(`FIX_${evKey}`, arr);
  7805.  
  7806. const f = function (...args) {
  7807. Promise.resolve().then(() => this[fvKey](...args));
  7808. };
  7809.  
  7810.  
  7811. for (const k of arr) {
  7812.  
  7813. const g = _yt_player;
  7814. const gk = g[k];
  7815. const gkp = gk.prototype;
  7816.  
  7817. debug && console.log(237, k, gkp)
  7818.  
  7819. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  7820. gkp[fvKey] = gkp[evKey];
  7821. gkp[evKey] = f;
  7822. }
  7823. }
  7824.  
  7825.  
  7826.  
  7827.  
  7828. }
  7829.  
  7830. if (!isChatRoomURL) {
  7831.  
  7832. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  7833. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  7834. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  7835. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  7836. if (FIX_VideoEVENTS_v2) {
  7837. const FIX_VideoEVENTS_DEBUG = 0;
  7838. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  7839. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  7840. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  7841. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  7842. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  7843. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  7844. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  7845. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  7846. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  7847.  
  7848. }
  7849. // onMutedAutoplayChange
  7850. // onVolumeChange
  7851. // onPlaybackRateChange
  7852.  
  7853. // onAirPlayActiveChange
  7854. // onAirPlayAvailabilityChange
  7855. // onApiChange
  7856. // onAutoplayBlocked
  7857. // onDrmOutputRestricted
  7858. // onFullscreenChange
  7859. // onLoadProgress
  7860. // onLoadedMetadata
  7861. // onVideoDataChange
  7862. // onVideoProgress
  7863.  
  7864. }
  7865.  
  7866.  
  7867.  
  7868. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_stampDomArray ) && (async () => {
  7869.  
  7870. const Polymer = await polymerObservable.obtain();
  7871. if (!Polymer) return;
  7872.  
  7873. if (FIX_Polymer_dom) {
  7874.  
  7875. const checkPDFuncValue = (pd) => {
  7876. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  7877. }
  7878. const checkPDFuncValue2 = (pd) => {
  7879. return pd && typeof pd.value == 'function'
  7880. }
  7881.  
  7882. const checkPDFuncGet = (pd) => {
  7883. return pd && typeof pd.get == 'function'
  7884. }
  7885.  
  7886. const domX = Polymer.dom(document.createElement('null'));
  7887. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  7888. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  7889. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  7890. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  7891. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  7892. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  7893. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  7894. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  7895. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  7896.  
  7897.  
  7898. // getOwnerRoot - to be reviewed
  7899. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  7900.  
  7901. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  7902. domXP.getOwnerRoot = function () {
  7903. try {
  7904. const p = this.node;
  7905.  
  7906. if (p instanceof HTMLElement_) {
  7907. const pp = pd2.get.call(p);
  7908. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  7909. return pp.getRootNode();
  7910. }
  7911.  
  7912. }
  7913. } catch (e) { }
  7914. return this.getOwnerRoot15();
  7915. }
  7916.  
  7917. Polymer.__fixedGetOwnerRoot__ = 1;
  7918. }
  7919.  
  7920.  
  7921.  
  7922.  
  7923. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  7924.  
  7925. domXP.querySelector15 = domXP.querySelector;
  7926.  
  7927. const querySelectorFn = function (query) {
  7928. try {
  7929. const p = this.node;
  7930.  
  7931. if (p instanceof Document && p.isConnected === true) {
  7932. return pd4b.value.call(p, query);
  7933. }
  7934.  
  7935. } catch (e) { }
  7936. return this.querySelector15(query);
  7937. }
  7938.  
  7939. Object.defineProperty(domXP, 'querySelector', {
  7940. get() {
  7941. return querySelectorFn;
  7942. },
  7943. set(nv) {
  7944. if (nv === querySelectorFn) return true;
  7945. this.querySelector15 = nv;
  7946. return true;
  7947. },
  7948.  
  7949. enumerable: false,
  7950. configurable: true
  7951. });
  7952.  
  7953. Polymer.__fixedQuerySelector__ = 1;
  7954. }
  7955.  
  7956. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  7957.  
  7958. domXP.querySelectorAll15 = domXP.querySelectorAll;
  7959.  
  7960. const querySelectorAllFn = function (query) {
  7961.  
  7962. try {
  7963.  
  7964. const p = this.node;
  7965.  
  7966. if (p instanceof Document && p.isConnected === true) {
  7967. return pd6b.value.call(p, query);
  7968. }
  7969.  
  7970. } catch (e) {
  7971.  
  7972. }
  7973. return this.querySelectorAll15(query);
  7974. }
  7975.  
  7976. Object.defineProperty(domXP, 'querySelectorAll', {
  7977. get() {
  7978. return querySelectorAllFn;
  7979. },
  7980. set(nv) {
  7981. if (nv === querySelectorAllFn) return true;
  7982. this.querySelectorAll15 = nv;
  7983. return true;
  7984. },
  7985.  
  7986. enumerable: false,
  7987. configurable: true
  7988. });
  7989.  
  7990. Polymer.__fixedQuerySelectorAll__ = 1;
  7991. }
  7992. }
  7993.  
  7994.  
  7995. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  7996.  
  7997. Polymer.Base.__connInit__ = function () {
  7998. setupYtComponent(this);
  7999. }
  8000.  
  8001.  
  8002. /** @type {Function} */
  8003. const connectedCallbackK = function (...args) {
  8004. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8005. const r = this[qm53](...args);
  8006. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8007. this.mh35 = 1;
  8008. return r;
  8009. };
  8010.  
  8011. connectedCallbackK.m353 = 1;
  8012.  
  8013.  
  8014. const qt53 = Polymer.Base.connectedCallback;
  8015. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  8016.  
  8017. Polymer.Base.connectedCallback = connectedCallbackK;
  8018.  
  8019.  
  8020. /** @type {Function} */
  8021. const createdK = function (...args) {
  8022. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8023. const r = this[qn53](...args);
  8024. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8025. this.mh36 = 1;
  8026. return r;
  8027. };
  8028.  
  8029.  
  8030. createdK.m353 = 1;
  8031. Polymer.Base[qn53] = Polymer.Base.created;
  8032. Polymer.Base.created = createdK;
  8033.  
  8034. }
  8035.  
  8036. })();
  8037.  
  8038.  
  8039. /*
  8040.  
  8041. e.nativeAppendChild = d.prototype.appendChild,
  8042. d.prototype.appendChild = function(h) {
  8043. return function(l) {
  8044. if (l instanceof DocumentFragment) {
  8045. var m = Array.from(l.children);
  8046. l = h.nativeAppendChild.call(this, l);
  8047. if (this.isConnected) {
  8048. m = g(m);
  8049. for (var p = m.next(); !p.done; p = m.next())
  8050. YD(p.value)
  8051. }
  8052. return l
  8053. }
  8054. m = l instanceof Element && l.isConnected;
  8055. p = h.nativeAppendChild.call(this, l);
  8056. m && ZD(l);
  8057. this.isConnected && YD(l);
  8058. return p
  8059. }
  8060. }(e),
  8061.  
  8062. */
  8063.  
  8064. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  8065.  
  8066. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  8067. if (f) Node.prototype.appendChild = function (a) {
  8068. if (this instanceof Element) { // exclude DocumentFragment
  8069. try {
  8070. let checkFragmentA = (a instanceof DocumentFragment);
  8071. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  8072. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  8073. for (const node of headLinkCollection) {
  8074. if (node.rel === 'preload' && node.as === 'fetch') {
  8075. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  8076. }
  8077. }
  8078. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  8079. checkFragmentA = false;
  8080. }
  8081. if (checkFragmentA && a.firstElementChild === null) {
  8082. // no element in fragmentA
  8083. let doNormal = false;
  8084. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  8085. if (child.nodeType === 3) { doNormal = true; break; }
  8086. }
  8087. if (!doNormal) return a;
  8088. }
  8089. } catch (e) {
  8090. console.log(e);
  8091. }
  8092. }
  8093. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  8094. }
  8095.  
  8096. })();
  8097.  
  8098. if (FIX_Shady) {
  8099.  
  8100. observablePromise(() => {
  8101. const { ShadyDOM, ShadyCSS } = window;
  8102. if (ShadyDOM) {
  8103. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  8104. ShadyDOM.noPatch = true; // 1 of 10
  8105. ShadyDOM.patchOnDemand = false; // 1 of 10
  8106. ShadyDOM.preferPerformance = true; // 1 of 10
  8107. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  8108. }
  8109. if (ShadyCSS) {
  8110. ShadyCSS.nativeCss = true; // 1 of 10
  8111. ShadyCSS.nativeShadow = true; // 6 of 10
  8112. ShadyCSS.cssBuild = undefined; // 1 of 10
  8113. ShadyCSS.disableRuntime = true; // 1 of 10
  8114. }
  8115. if (ShadyDOM && ShadyCSS) return 1;
  8116. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  8117.  
  8118. }
  8119.  
  8120.  
  8121. // let schedulerInstancePropOfTimerType = '';
  8122. // let schedulerInstancePropOfTimerId = '';
  8123. (FIX_schedulerInstanceInstance & 2) && (async () => {
  8124.  
  8125. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  8126.  
  8127. if (!schedulerInstanceInstance_) return;
  8128.  
  8129. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  8130. if (checkOK) {
  8131.  
  8132. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  8133.  
  8134. let requestingFn = null;
  8135. let requestingArgs = null;
  8136.  
  8137. const f = function () {
  8138. requestingFn = this.fn;
  8139. requestingArgs = [...arguments];
  8140. return 12373;
  8141. };
  8142.  
  8143. const fakeFns = [
  8144. f.bind({ fn: requestAnimationFrame }),
  8145. f.bind({ fn: setInterval }),
  8146. f.bind({ fn: setTimeout }),
  8147. f.bind({ fn: requestIdleCallback })
  8148. ];
  8149.  
  8150. let mzt = 0;
  8151.  
  8152. let _fnSelectorProp = null;
  8153. const mkFns = new Array(4);
  8154.  
  8155. /*
  8156. case 1:
  8157. var a = this.K;
  8158. this.g = this.I ? window.requestIdleCallback(a, {
  8159. timeout: 3E3
  8160. }) : window.setTimeout(a, ma);
  8161. break;
  8162. case 2:
  8163. this.g = window.setTimeout(this.M, this.N);
  8164. break;
  8165. case 3:
  8166. this.g = window.requestAnimationFrame(this.L);
  8167. break;
  8168. case 4:
  8169. this.g = window.setTimeout(this.J, 0)
  8170. }
  8171.  
  8172. */
  8173. const startFnHandler = {
  8174. get(target, prop, receiver) {
  8175. if (prop === '$$12377$$') return true;
  8176. if (prop === '$$12378$$') return target;
  8177.  
  8178. // console.log('get',prop)
  8179. return target[prop]
  8180. },
  8181. set(target, prop, value, receiver) {
  8182. // console.log('set', prop, value)
  8183.  
  8184. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  8185. if (value === 12373 && _fnSelectorProp) {
  8186.  
  8187. const schedulerTypeSelection = target[_fnSelectorProp];
  8188. const timerIdProp = prop;
  8189.  
  8190. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  8191. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  8192. // schedulerInstancePropOfTimerId = timerIdProp || '';
  8193. // }
  8194.  
  8195. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  8196. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  8197. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  8198. // rare
  8199. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  8200. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  8201. // often
  8202. if ((FIX_schedulerInstanceInstance & 4)) {
  8203. const f = requestingArgs[0];
  8204. const tir = ++mzt;
  8205. nextBrowserTick_(() => {
  8206. if (target[timerIdProp] === -tir) f();
  8207. });
  8208. target[_fnSelectorProp] = 940;
  8209. target[timerIdProp] = -tir;
  8210. } else {
  8211. const f = requestingArgs[0];
  8212. const tir = ++mzt;
  8213. Promise.resolve().then(() => {
  8214. if (target[timerIdProp] === -tir) f();
  8215. });
  8216. target[_fnSelectorProp] = 930;
  8217. target[timerIdProp] = -tir;
  8218. }
  8219. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  8220. // often
  8221. if (requestingFn === requestIdleCallback) {
  8222. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  8223. } else {
  8224. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  8225. }
  8226. } else {
  8227. target[_fnSelectorProp] = 0;
  8228. target[timerIdProp] = 0;
  8229. }
  8230. } else {
  8231. target[prop] = value;
  8232. }
  8233. return true;
  8234. }
  8235. };
  8236.  
  8237. let startBusy = false;
  8238. schedulerInstanceInstance_.start = function () {
  8239. if (startBusy) return;
  8240. startBusy = true;
  8241. try {
  8242. mkFns[0] = window.requestAnimationFrame;
  8243. mkFns[1] = window.setInterval;
  8244. mkFns[2] = window.setTimeout;
  8245. mkFns[3] = window.requestIdleCallback;
  8246. const tThis = this['$$12378$$'] || this;
  8247. window.requestAnimationFrame = fakeFns[0]
  8248. window.setInterval = fakeFns[1]
  8249. window.setTimeout = fakeFns[2]
  8250. window.requestIdleCallback = fakeFns[3]
  8251. _fnSelectorProp = null;
  8252. tThis.start993.call(new Proxy(tThis, startFnHandler));
  8253. _fnSelectorProp = null;
  8254. window.requestAnimationFrame = mkFns[0];
  8255. window.setInterval = mkFns[1];
  8256. window.setTimeout = mkFns[2];
  8257. window.requestIdleCallback = mkFns[3];
  8258. } catch (e) {
  8259. console.warn(e);
  8260. }
  8261. startBusy = false;
  8262. }
  8263.  
  8264. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  8265.  
  8266. }
  8267. })();
  8268.  
  8269. FIX_yt_player && !isChatRoomURL && (async () => {
  8270.  
  8271. const fOption = 1 | 2 | 4;
  8272.  
  8273. const _yt_player = await _yt_player_observable.obtain();
  8274.  
  8275. if (!_yt_player || typeof _yt_player !== 'object') return;
  8276.  
  8277. const g = _yt_player;
  8278. let k;
  8279.  
  8280. if (fOption & 1) {
  8281.  
  8282. // rAf scheduling
  8283.  
  8284. const keyZqOu = getZqOu(_yt_player);
  8285. if (!keyZqOu) {
  8286. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  8287. return;
  8288. }
  8289. k = keyZqOu
  8290.  
  8291. const gk = g[k];
  8292. if (typeof gk !== 'function') {
  8293. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  8294. return;
  8295. }
  8296. const gkp = gk.prototype;
  8297.  
  8298. const dummyObject = new gk;
  8299. const nilFunc = () => { };
  8300.  
  8301. const nilObj = {};
  8302.  
  8303. // console.log(1111111111)
  8304.  
  8305. let keyBoolD = '';
  8306. let keyWindow = '';
  8307. let keyFuncC = '';
  8308. let keyCidj = '';
  8309.  
  8310. for (const [t, y] of Object.entries(dummyObject)) {
  8311. if (y instanceof Window) keyWindow = t;
  8312. }
  8313.  
  8314. const dummyObjectProxyHandler = {
  8315. get(target, prop) {
  8316. let v = target[prop]
  8317. if (v instanceof Window && !keyWindow) {
  8318. keyWindow = t;
  8319. }
  8320. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  8321. if (prop === keyWindow) y = {
  8322. requestAnimationFrame(f) {
  8323. return 3;
  8324. },
  8325. cancelAnimationFrame() {
  8326.  
  8327. }
  8328. }
  8329. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  8330. keyFuncC = prop;
  8331. }
  8332. // console.log('[get]', prop, typeof target[prop])
  8333.  
  8334.  
  8335. return y;
  8336. },
  8337. set(target, prop, value) {
  8338.  
  8339. if (typeof value === 'boolean' && !keyBoolD) {
  8340. keyBoolD = prop;
  8341. }
  8342. if (typeof value === 'number' && !keyCidj && value >= 2) {
  8343. keyCidj = prop;
  8344. }
  8345.  
  8346. // console.log('[set]', prop, value)
  8347. target[prop] = value;
  8348.  
  8349. return true;
  8350. }
  8351. };
  8352.  
  8353. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  8354.  
  8355. // console.log('gkp.start',gkp.start);
  8356. // console.log('gkp.stop',gkp.stop);
  8357. gkp._activation = false;
  8358.  
  8359. gkp.start = function () {
  8360. // p59 || console.log(12100)
  8361. if (!this._activation) {
  8362. this._activation = true;
  8363. foregroundPromiseFn().then(() => {
  8364. this._activation = false;
  8365. if (this[keyCidj]) {
  8366. Promise.resolve().then(this[keyFuncC]);
  8367. }
  8368. });
  8369. }
  8370. this[keyCidj] = 1;
  8371. this[keyBoolD] = true;
  8372. };
  8373.  
  8374. gkp.stop = function () {
  8375. this[keyCidj] = null;
  8376. };
  8377.  
  8378.  
  8379. /*
  8380. g[k].start = function() {
  8381. this.stop();
  8382. this.D = true;
  8383. var a = requestAnimationFrame
  8384. , b = cancelAnimationFrame;
  8385. this.j = a.call(this.B, this.C)
  8386. }
  8387. ;
  8388. g[k].stop = function() {
  8389. if (this.isActive()) {
  8390. var a = requestAnimationFrame
  8391. , b = cancelAnimationFrame;
  8392. b.call(this.B, this.j)
  8393. }
  8394. this.j = null
  8395. }
  8396. */
  8397. }
  8398.  
  8399. if (fOption & 2) {
  8400. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  8401.  
  8402. if (keyzo) {
  8403.  
  8404. k = keyzo;
  8405.  
  8406. const attrUpdateFn = g[k];
  8407. // console.log(5992, attrUpdateFn)
  8408. g['$$original$$' + k] = attrUpdateFn;
  8409. const zoTransform = async (a, c) => {
  8410.  
  8411. let transformType = '';
  8412. let transformValue = 0;
  8413. let transformUnit = '';
  8414. let transformTypeI = 0;
  8415.  
  8416. const aStyle = a.style;
  8417.  
  8418. let cType = 0;
  8419.  
  8420. const cl = c.length;
  8421.  
  8422. if (cl >= 8) {
  8423. // scale(1)
  8424. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  8425. cType = 1;
  8426. let t = c.charCodeAt(5);
  8427. if (t === 88 || t === 120) cType = 1 | 4;
  8428. if (t === 89 || t === 121) cType = 1 | 8;
  8429. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  8430. cType = 2;
  8431. let t = c.charCodeAt(9);
  8432. if (t === 88 || t === 120) cType = 2 | 4;
  8433. if (t === 89 || t === 121) cType = 2 | 8;
  8434. }
  8435. let w = 0;
  8436. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  8437. let p = c.substring(7, cl - 1);
  8438. let q = p.length >= 1 ? parseFloat(p) : NaN;
  8439. if (typeof q === 'number' && !isNaNx(q)) {
  8440. transformType = w === 1 ? 'scaleX' : 'scaleY';
  8441. transformValue = q;
  8442. transformUnit = '';
  8443. transformTypeI = 1;
  8444. } else {
  8445. cType = 256;
  8446. }
  8447. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  8448. if (c.endsWith('px)')) {
  8449. let p = c.substring(11, cl - 3);
  8450. let q = p.length >= 1 ? parseFloat(p) : NaN;
  8451. if (typeof q === 'number' && !isNaNx(q)) {
  8452. transformType = w === 1 ? 'translateX' : 'translateY';
  8453. transformValue = q;
  8454. transformUnit = 'px';
  8455. transformTypeI = 2;
  8456. } else if (p === 'NaN') {
  8457. return;
  8458. }
  8459. } else {
  8460. cType = 256;
  8461. }
  8462. } else if (cType > 0) {
  8463. cType = 256;
  8464. }
  8465. }
  8466.  
  8467.  
  8468. if (cType === 256) {
  8469. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  8470. }
  8471.  
  8472. if (transformTypeI === 1) {
  8473. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  8474. const vz = toFixed2(q, 3);
  8475. c = `${transformType}(${vz})`;
  8476. const cv = aStyle.transform;
  8477. if (c === cv) return;
  8478. aStyle.transform = c;
  8479. } else if (transformTypeI === 2) {
  8480. const q = transformValue;
  8481. const vz = toFixed2(q, 1);
  8482. c = `${transformType}(${vz}${transformUnit})`;
  8483. const cv = aStyle.transform;
  8484. if (c === cv) return;
  8485. aStyle.transform = c;
  8486. } else { // eg empty
  8487. const cv = aStyle.transform;
  8488. if (!c && !cv) return;
  8489. else if (c === cv) return;
  8490. aStyle.transform = c;
  8491. }
  8492.  
  8493. };
  8494.  
  8495. const elmTransformTemp = new WeakMap();
  8496. const elmPropTemps = {
  8497. 'display': new WeakMap(),
  8498. 'width': new WeakMap(),
  8499. 'height': new WeakMap(),
  8500. 'outlineWidth': new WeakMap(),
  8501. 'position': new WeakMap(),
  8502. 'padding': new WeakMap(),
  8503. "cssText": new WeakMap(),
  8504. "right": new WeakMap(),
  8505. "left": new WeakMap(),
  8506. "top": new WeakMap(),
  8507. "bottom": new WeakMap(),
  8508. "transitionDelay": new WeakMap(),
  8509. "marginLeft": new WeakMap(),
  8510. "marginTop": new WeakMap(),
  8511. "marginRight": new WeakMap(),
  8512. "marginBottom": new WeakMap(),
  8513. }
  8514.  
  8515. const ns5 = Symbol();
  8516. const nextModify = (a, c, m, f, immediate) => {
  8517. const a_ = a;
  8518. const m_ = m;
  8519. const noKey = !m_.has(a_);
  8520. if (immediate || noKey) {
  8521. m_.set(a_, ns5);
  8522. f(a_, c);
  8523. noKey && nextBrowserTick_(() => {
  8524. const d = m_.get(a_);
  8525. if (d === undefined) return;
  8526. m_.delete(a_);
  8527. if (d !== ns5) f(a_, d);
  8528. });
  8529. } else {
  8530. m_.set(a_, c);
  8531. }
  8532. };
  8533.  
  8534. const set66 = new Set();
  8535. const log77 = new Map();
  8536. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  8537.  
  8538. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  8539.  
  8540. // console.log(140000, a, b, c);
  8541. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  8542. const num = c;
  8543. c = `${num}`;
  8544. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  8545. }
  8546.  
  8547. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  8548.  
  8549. let elmPropTemp = null;
  8550.  
  8551. if (b === "transform") {
  8552. // div.ytp-hover-progress.ytp-hover-progress-light
  8553. // div.ytp-play-progress.ytp-swatch-background-color
  8554.  
  8555. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  8556. return;
  8557.  
  8558. } else if (elmPropTemp = elmPropTemps[b]) {
  8559.  
  8560. // if (c.length > 5 && c.includes('.')) {
  8561. // console.log(123213, c)
  8562. // }
  8563.  
  8564. const b_ = b;
  8565. nextModify(a, c, elmPropTemp, (a, c) => {
  8566. const style = a.style;
  8567. const cv = style[b_];
  8568. if (!cv && !c) return;
  8569. if (cv === c) return;
  8570. style[b_] = c;
  8571. }, immediateChange);
  8572. return;
  8573.  
  8574. } else if (b === "outline-width") {
  8575.  
  8576. const b_ = 'outlineWidth';
  8577. elmPropTemp = elmPropTemps[b_];
  8578. nextModify(a, c, elmPropTemp, (a, c) => {
  8579. const style = a.style;
  8580. const cv = style[b_];
  8581. if (!cv && !c) return;
  8582. if (cv === c) return;
  8583. style[b_] = c;
  8584. }, immediateChange);
  8585. return;
  8586.  
  8587. } else if (b === 'maxWidth' || b === 'maxHeight') {
  8588. // I think these can be directly assigned.
  8589.  
  8590. const b_ = b;
  8591. const style = a.style;
  8592. const cv = style[b_];
  8593. if (!cv && !c) return;
  8594. if (cv === c) return;
  8595. style[b_] = c;
  8596. return;
  8597.  
  8598. } else {
  8599. // if(immediate && elmPropTemps[b]){
  8600. // console.log(5191, b)
  8601. // }
  8602. // caption-window
  8603. // margin-left max-height max-width font-family fill color font-size background white-space margin
  8604. // text-align background-color
  8605. // console.log(27304, a, b, c)
  8606. if (!set66.has(b)) {
  8607. set66.add(b);
  8608. nextBrowserTick_(() => {
  8609. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  8610. console.log(27304, a, b, c)
  8611. }
  8612. })
  8613. }
  8614. }
  8615.  
  8616. attrUpdateFn.call(this, a, b, c);
  8617. return;
  8618. } else if (typeof (b || 0) === 'object') {
  8619.  
  8620. // this is to fix caption positioning
  8621. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  8622. const immediate = (a.id || 0).length > 14;
  8623. for (const [k, v] of Object.entries(b)) {
  8624. modifiedFn.call(this, a, k, v, immediate);
  8625. }
  8626.  
  8627. } else {
  8628.  
  8629. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  8630. // ytp-ad-timed-pie-countdown-inner
  8631.  
  8632. if (typeof b === 'string') {
  8633.  
  8634. let m = log77.get(b);
  8635. if (!m) {
  8636. m = [];
  8637. console.log('attrUpdateFn.debug.27304', m);
  8638. log77.set(b, m);
  8639. }
  8640. m.push([a, b, c]);
  8641.  
  8642. } else {
  8643. console.log('attrUpdateFn.debug.27306', a, b, c);
  8644. }
  8645.  
  8646. attrUpdateFn.call(this, a, b, c);
  8647. return;
  8648. }
  8649.  
  8650. // console.log(130000, a, b, c);
  8651.  
  8652. };
  8653. g[k] = modifiedFn;
  8654.  
  8655.  
  8656. /*
  8657.  
  8658. g.zo = function(a, b, c) {
  8659. if ("string" === typeof b)
  8660. (b = yo(a, b)) && (a.style[b] = c);
  8661. else
  8662. for (var d in b) {
  8663. c = a;
  8664. var e = b[d]
  8665. , f = yo(c, d);
  8666. f && (c.style[f] = e)
  8667. }
  8668. }
  8669.  
  8670.  
  8671. */
  8672.  
  8673.  
  8674. }
  8675. }
  8676.  
  8677. if (fOption & 4) {
  8678. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  8679.  
  8680. if (keyuG) {
  8681.  
  8682. k = keyuG;
  8683.  
  8684. const gk = g[k];
  8685. const gkp = gk.prototype;
  8686.  
  8687.  
  8688. /** @type { Map<string, WeakMap<any, any>> } */
  8689. const ntLogs = new Map();
  8690.  
  8691. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  8692.  
  8693. gkp.updateValue31 = gkp.updateValue;
  8694. gkp.updateValue = function (a, b) {
  8695. if (typeof a !== 'string') return this.updateValue31(a, b);
  8696.  
  8697. const element = this.element;
  8698. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  8699.  
  8700. let ntLog = ntLogs.get(a);
  8701. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  8702.  
  8703. let cache = ntLog.get(element);
  8704. if (cache && cache.value === b) {
  8705. return;
  8706. }
  8707. if (!cache) {
  8708. this.__oldValueByUpdateValue__ = null;
  8709. ntLog.set(element, cache = { value: b });
  8710. } else {
  8711. this.__oldValueByUpdateValue__ = cache.value;
  8712. cache.value = b;
  8713. }
  8714.  
  8715. return this.updateValue31(a, b);
  8716. }
  8717.  
  8718. /*
  8719. g.k.update = function(a) {
  8720. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  8721. c = c.value,
  8722. this.updateValue(c, a[c])
  8723. }
  8724. ;
  8725. g.k.updateValue = function(a, b) {
  8726. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  8727. }
  8728. */
  8729.  
  8730. }
  8731.  
  8732.  
  8733. }
  8734. }
  8735.  
  8736.  
  8737.  
  8738. })();
  8739.  
  8740.  
  8741. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  8742. // keyboard shortcut keys controller
  8743.  
  8744. const _yt_player = await _yt_player_observable.obtain();
  8745.  
  8746. if (!_yt_player || typeof _yt_player !== 'object') return;
  8747.  
  8748. keyboardController(_yt_player);
  8749.  
  8750. })();
  8751.  
  8752. FIX_yt_player && !isChatRoomURL && (async () => {
  8753. // timer scheduling
  8754.  
  8755. const _yt_player = await _yt_player_observable.obtain();
  8756.  
  8757. if (!_yt_player || typeof _yt_player !== 'object') return;
  8758.  
  8759. let keyZqQu = getZqQu(_yt_player);
  8760.  
  8761. if (!keyZqQu) return;
  8762.  
  8763. const g = _yt_player
  8764. let k = keyZqQu
  8765.  
  8766. const gk = g[k];
  8767. if (typeof gk !== 'function') return;
  8768. const gkp = gk.prototype;
  8769.  
  8770. const extractKeysZqQu = () => {
  8771.  
  8772.  
  8773. let _keyeC = '';
  8774. try {
  8775. gkp.stop.call(new Proxy({
  8776. isActive: () => { }
  8777. }, {
  8778. set(target, prop, value) {
  8779. if (value === 0) _keyeC = prop;
  8780. return true;
  8781. }
  8782. }));
  8783. } catch (e) { }
  8784. if (!_keyeC) return;
  8785. const keyeC = _keyeC;
  8786.  
  8787. let keyC = ''; // this.C = this.ST.bind(this)
  8788. let keyhj = ''; // 1000ms
  8789. try {
  8790. gkp.start.call(new Proxy({
  8791. stop: () => { },
  8792. [keyeC]: 0,
  8793. }, {
  8794. get(target, prop) {
  8795. if (prop in target) return target[prop];
  8796. if (!keyC) {
  8797. keyC = prop;
  8798. return null; // throw error
  8799. }
  8800. else if (!keyhj) {
  8801. keyhj = prop;
  8802. }
  8803.  
  8804. }
  8805. }));
  8806. } catch (e) {
  8807. if (!keyC || !keyhj) {
  8808. console.log(e)
  8809. }
  8810. }
  8811.  
  8812. if (!keyC || !keyhj) return;
  8813. let keyST = '';
  8814. let keyj = '';
  8815. let keyB = '';
  8816. let keyxa = '';
  8817.  
  8818. const possibleKs = new Set();
  8819.  
  8820. for (const [k, v] of Object.entries(gkp)) {
  8821. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  8822. continue;
  8823. }
  8824. if (typeof v === 'function') {
  8825. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  8826. if (m) {
  8827. keyST = k;
  8828. keyj = m[1];
  8829. keyB = m[2];
  8830. } else {
  8831. possibleKs.add(k);
  8832. }
  8833. }
  8834. }
  8835.  
  8836. if (!keyST || !keyj || !keyB) return;
  8837.  
  8838. for (const k of possibleKs) {
  8839. if (k === keyST || k === keyj || k === keyB) {
  8840. continue;
  8841. }
  8842. const v = gkp[k];
  8843. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  8844. keyxa = k;
  8845. }
  8846. }
  8847.  
  8848. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  8849.  
  8850. }
  8851.  
  8852. const keys = extractKeysZqQu();
  8853. if (!keys || !keys.length) return;
  8854. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  8855.  
  8856. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  8857.  
  8858. let disposeKeys = null;
  8859.  
  8860. gkp[keyxa] = function () {
  8861. // dispose
  8862. if (!disposeKeys) {
  8863. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  8864. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  8865. const t = typeof this[key];
  8866. return t === 'undefined' || t === 'object'
  8867. }
  8868. return false;
  8869. });
  8870. }
  8871. for (const key of disposeKeys) {
  8872. const v = this[key];
  8873. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  8874. }
  8875. if (this[keyeC] > 0) this.stop();
  8876. this[keyj] = null;
  8877. this[keyB] = null;
  8878. };
  8879.  
  8880. gkp.start = function (a) {
  8881. if (this[keyeC] > 0) this.stop();
  8882. const delay = void 0 !== a ? a : this[keyhj];
  8883. this[keyeC] = window.setTimeout(this[keyC], delay);
  8884. };
  8885. gkp.stop = function () {
  8886. if (this[keyeC] > 0) {
  8887. window.clearTimeout(this[keyeC]);
  8888. this[keyeC] = 0;
  8889. }
  8890. };
  8891.  
  8892. gkp.isActive = function () {
  8893. return this[keyeC] > 0;
  8894. };
  8895.  
  8896. gkp[keyST] = function () {
  8897. this.stop(); // this[keyeC] = 0;
  8898. const fn = this[keyj];
  8899. const obj = this[keyB];
  8900. let skip = false;
  8901. if (!fn) skip = true;
  8902. else if (IGNORE_bufferhealth_CHECK && obj) {
  8903. let m;
  8904. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  8905. if (m.has("bufferhealth")) skip = true;
  8906. }
  8907. }
  8908. if (!skip) {
  8909. fn.call(obj);
  8910. }
  8911. };
  8912.  
  8913.  
  8914.  
  8915.  
  8916. /*
  8917.  
  8918. g.k.eC = 0;
  8919. g.k.xa = function() {
  8920. g.Qu.Vf.xa.call(this);
  8921. this.stop();
  8922. delete this.j;
  8923. delete this.B
  8924. }
  8925. ;
  8926. g.k.start = function(a) {
  8927. this.stop();
  8928. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  8929. }
  8930. ;
  8931. g.k.stop = function() {
  8932. this.isActive() && g.Sa.clearTimeout(this.eC);
  8933. this.eC = 0
  8934. }
  8935. ;
  8936. g.k.isActive = function() {
  8937. return 0 != this.eC
  8938. }
  8939. ;
  8940. g.k.ST = function() {
  8941. this.eC = 0;
  8942. this.j && this.j.call(this.B)
  8943. }
  8944. ;
  8945. */
  8946.  
  8947.  
  8948.  
  8949.  
  8950. })();
  8951.  
  8952. FIX_Animation_n_timeline && (async () => {
  8953.  
  8954. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  8955.  
  8956. if (!timeline || !Animation) return;
  8957.  
  8958. const aniProto = Animation.prototype;
  8959. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  8960.  
  8961. const getXroto = (x) => {
  8962. try {
  8963. return x.__proto__;
  8964. } catch (e) { }
  8965. return null;
  8966. }
  8967. const timProto = getXroto(timeline);
  8968. if (!timProto) return;
  8969. if (
  8970. (
  8971. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  8972. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  8973. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  8974. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  8975. )
  8976.  
  8977. ) {
  8978.  
  8979. timProto.nofCQ = 1;
  8980. aniProto.nofYH = 1;
  8981.  
  8982. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  8983.  
  8984.  
  8985. /*
  8986. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  8987. return c._updatePromises();
  8988. });
  8989. */
  8990.  
  8991. const p = Array.prototype.filter;
  8992.  
  8993. let res = null;
  8994. Array.prototype.filter = function () {
  8995.  
  8996. res = this;
  8997. return this;
  8998.  
  8999. };
  9000.  
  9001. _updateAnimationsPromises.call({});
  9002.  
  9003. Array.prototype.filter = p;
  9004.  
  9005. if (res && typeof res.length === 'number') {
  9006. /** @type {any[]} */
  9007. const _res = res;
  9008. return _res;
  9009. }
  9010.  
  9011.  
  9012. return null;
  9013.  
  9014.  
  9015.  
  9016.  
  9017. })(timProto._updateAnimationsPromises);
  9018.  
  9019. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  9020.  
  9021. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  9022.  
  9023. aniProto._updatePromises31 = aniProto._updatePromises;
  9024.  
  9025. /*
  9026. aniProto._updatePromises = function(){
  9027. console.log('eff',this._oldPlayState, this.playState)
  9028. return this._updatePromises31.apply(this, arguments)
  9029. }
  9030. */
  9031.  
  9032. aniProto._updatePromises = function () {
  9033. var oldPlayState = this._oldPlayState;
  9034. var newPlayState = this.playState;
  9035. // console.log('ett', oldPlayState, newPlayState)
  9036. if (newPlayState !== oldPlayState) {
  9037. this._oldPlayState = newPlayState;
  9038. if (this._readyPromise) {
  9039. if ("idle" == newPlayState) {
  9040. this._rejectReadyPromise();
  9041. this._readyPromise = void 0;
  9042. } else if ("pending" == oldPlayState) {
  9043. this._resolveReadyPromise();
  9044. } else if ("pending" == newPlayState) {
  9045. this._readyPromise = void 0;
  9046. }
  9047. }
  9048. if (this._finishedPromise) {
  9049. if ("idle" == newPlayState) {
  9050. this._rejectFinishedPromise();
  9051. this._finishedPromise = void 0;
  9052. } else if ("finished" == newPlayState) {
  9053. this._resolveFinishedPromise();
  9054. } else if ("finished" == oldPlayState) {
  9055. this._finishedPromise = void 0;
  9056. }
  9057. }
  9058. }
  9059. return this._readyPromise || this._finishedPromise;
  9060. };
  9061.  
  9062.  
  9063. let restartWebAnimationsNextTickFlag = false;
  9064.  
  9065. const looperMethodT = () => {
  9066.  
  9067. const runnerFn = (hRes) => {
  9068. var b = timeline;
  9069. b.currentTime = hRes;
  9070. b._discardAnimations();
  9071. if (0 == b._animations.length) {
  9072. restartWebAnimationsNextTickFlag = false;
  9073. } else {
  9074. getRafPromise().then(runnerFn);
  9075. }
  9076. }
  9077.  
  9078. const restartWebAnimationsNextTick = () => {
  9079. if (!restartWebAnimationsNextTickFlag) {
  9080. restartWebAnimationsNextTickFlag = true;
  9081. getRafPromise().then(runnerFn);
  9082. }
  9083. }
  9084.  
  9085. return { restartWebAnimationsNextTick }
  9086. };
  9087.  
  9088.  
  9089. const looperMethodN = () => {
  9090.  
  9091. const acs = document.createElement('a-f');
  9092. acs.id = 'a-f';
  9093.  
  9094. if (!document.getElementById('afscript')) {
  9095. const style = document.createElement('style');
  9096. style.id = 'afscript';
  9097. style.textContent = `
  9098. @keyFrames aF1 {
  9099. 0% {
  9100. order: 0;
  9101. }
  9102. 100% {
  9103. order: 1;
  9104. }
  9105. }
  9106. #a-f[id] {
  9107. visibility: collapse !important;
  9108. position: fixed !important;
  9109. display: block !important;
  9110. top: -100px !important;
  9111. left: -100px !important;
  9112. margin:0 !important;
  9113. padding:0 !important;
  9114. outline:0 !important;
  9115. border:0 !important;
  9116. z-index:-1 !important;
  9117. width: 0px !important;
  9118. height: 0px !important;
  9119. contain: strict !important;
  9120. pointer-events: none !important;
  9121. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  9122. }
  9123. `;
  9124. (document.head || document.documentElement).appendChild(style);
  9125. }
  9126.  
  9127. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  9128.  
  9129. const _onanimationiteration = function (evt) {
  9130. const hRes = evt.timeStamp;
  9131. var b = timeline;
  9132. b.currentTime = hRes;
  9133. b._discardAnimations();
  9134. if (0 == b._animations.length) {
  9135. restartWebAnimationsNextTickFlag = false;
  9136. acs.onanimationiteration = null;
  9137. } else {
  9138. acs.onanimationiteration = _onanimationiteration;
  9139. }
  9140.  
  9141. }
  9142.  
  9143.  
  9144.  
  9145. const restartWebAnimationsNextTick = () => {
  9146. if (!restartWebAnimationsNextTickFlag) {
  9147. restartWebAnimationsNextTickFlag = true;
  9148. acs.onanimationiteration = _onanimationiteration;
  9149.  
  9150. }
  9151. }
  9152.  
  9153. return { restartWebAnimationsNextTick }
  9154. };
  9155.  
  9156.  
  9157.  
  9158. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  9159.  
  9160.  
  9161. // console.log(571, timProto);
  9162. timProto._play = function (c) {
  9163. c = new Animation(c, this);
  9164. this._animations.push(c);
  9165. restartWebAnimationsNextTick();
  9166. c._updatePromises();
  9167. c._animation.play();
  9168. c._updatePromises();
  9169. return c
  9170. }
  9171.  
  9172. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  9173. originalAnimationsWithPromises.length = 0;
  9174. originalAnimationsWithPromises.push = null;
  9175. originalAnimationsWithPromises.splice = null;
  9176. originalAnimationsWithPromises.slice = null;
  9177. originalAnimationsWithPromises.indexOf = null;
  9178. originalAnimationsWithPromises.unshift = null;
  9179. originalAnimationsWithPromises.shift = null;
  9180. originalAnimationsWithPromises.pop = null;
  9181. originalAnimationsWithPromises.filter = null;
  9182. originalAnimationsWithPromises.forEach = null;
  9183. originalAnimationsWithPromises.map = null;
  9184.  
  9185.  
  9186. const _updateAnimationsPromises = () => {
  9187. animationsWithPromisesMap.forEach(c => {
  9188. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  9189. });
  9190. /*
  9191. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  9192. return c._updatePromises();
  9193. });
  9194. */
  9195. }
  9196.  
  9197. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  9198.  
  9199. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  9200.  
  9201. delete timProto._updateAnimationsPromises;
  9202. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  9203. get() {
  9204. if (animationsWithPromisesMap.size === 0) return nilFn;
  9205. return _updateAnimationsPromises;
  9206. },
  9207. set(nv) {
  9208. delete this._updateAnimationsPromises;
  9209. this._updateAnimationsPromises = nv;
  9210. },
  9211. enumerable: true,
  9212. configurable: true,
  9213. });
  9214.  
  9215.  
  9216. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  9217. aniProto.__finished_native_get__ = pdFinished.get;
  9218. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  9219.  
  9220.  
  9221. Object.defineProperty(aniProto, 'finished', {
  9222. get() {
  9223. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  9224. this._finishedPromise = new Promise((resolve, reject) => {
  9225. this._resolveFinishedPromise = function () {
  9226. resolve(this)
  9227. };
  9228. this._rejectFinishedPromise = function () {
  9229. reject({
  9230. type: DOMException.ABORT_ERR,
  9231. name: "AbortError"
  9232. })
  9233. };
  9234. }),
  9235. "finished" == this.playState && this._resolveFinishedPromise());
  9236. return this._finishedPromise
  9237. },
  9238. set: undefined,
  9239. enumerable: true,
  9240. configurable: true
  9241. });
  9242.  
  9243. }
  9244.  
  9245.  
  9246.  
  9247. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  9248. aniProto.__ready_native_get__ = pdReady.get;
  9249. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  9250.  
  9251. Object.defineProperty(aniProto, 'ready', {
  9252. get() {
  9253. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  9254. this._readyPromise = new Promise((resolve, reject) => {
  9255. this._resolveReadyPromise = function () {
  9256. resolve(this)
  9257. };
  9258. this._rejectReadyPromise = function () {
  9259. reject({
  9260. type: DOMException.ABORT_ERR,
  9261. name: "AbortError"
  9262. })
  9263. };
  9264. }),
  9265. "pending" !== this.playState && this._resolveReadyPromise());
  9266. return this._readyPromise
  9267. },
  9268. set: undefined,
  9269. enumerable: true,
  9270. configurable: true
  9271. });
  9272.  
  9273. }
  9274.  
  9275.  
  9276. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  9277.  
  9278. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  9279. const _rebuildUnderlyingAnimation = function () {
  9280. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  9281. this.effect && this.effect._onsample && (this.effect._onsample = null);
  9282. return this._rebuildUnderlyingAnimation21();
  9283. }
  9284. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  9285. // delete aniProto._rebuildUnderlyingAnimation;
  9286. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  9287. // get() {
  9288. // if (isNaN(this._sequenceNumber)) return nilFn;
  9289. // return this._rebuildUnderlyingAnimation21;
  9290. // },
  9291. // set(nv) {
  9292. // delete this._rebuildUnderlyingAnimation;
  9293. // this._rebuildUnderlyingAnimation = nv;
  9294. // },
  9295. // enumerable: true,
  9296. // configurable: true
  9297. // });
  9298. }
  9299.  
  9300.  
  9301. /*
  9302.  
  9303.  
  9304. function f(c) {
  9305. var b = v.timeline;
  9306. b.currentTime = c;
  9307. b._discardAnimations();
  9308. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  9309. }
  9310. var h = window.requestAnimationFrame;
  9311. window.requestAnimationFrame = function(c) {
  9312. return h(function(b) {
  9313. v.timeline._updateAnimationsPromises();
  9314. c(b);
  9315. v.timeline._updateAnimationsPromises()
  9316. })
  9317. }
  9318. ;
  9319. v.AnimationTimeline = function() {
  9320. this._animations = [];
  9321. this.currentTime = void 0
  9322. }
  9323. ;
  9324. v.AnimationTimeline.prototype = {
  9325. getAnimations: function() {
  9326. this._discardAnimations();
  9327. return this._animations.slice()
  9328. },
  9329. _updateAnimationsPromises: function() {
  9330. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  9331. return c._updatePromises()
  9332. })
  9333. },
  9334. _discardAnimations: function() {
  9335. this._updateAnimationsPromises();
  9336. this._animations = this._animations.filter(function(c) {
  9337. return "finished" != c.playState && "idle" != c.playState
  9338. })
  9339. },
  9340. _play: function(c) {
  9341. c = new v.Animation(c,this);
  9342. this._animations.push(c);
  9343. v.restartWebAnimationsNextTick();
  9344. c._updatePromises();
  9345. c._animation.play();
  9346. c._updatePromises();
  9347. return c
  9348. },
  9349. play: function(c) {
  9350. c && c.remove();
  9351. return this._play(c)
  9352. }
  9353. };
  9354. var d = !1;
  9355. v.restartWebAnimationsNextTick = function() {
  9356. d || (d = !0,
  9357. requestAnimationFrame(f))
  9358. }
  9359. ;
  9360. var a = new v.AnimationTimeline;
  9361. v.timeline = a;
  9362. try {
  9363. Object.defineProperty(window.document, "timeline", {
  9364. configurable: !0,
  9365. get: function() {
  9366. return a
  9367. }
  9368. })
  9369. } catch (c) {}
  9370. try {
  9371. window.document.timeline = a
  9372. } catch (c) {}
  9373.  
  9374. */
  9375.  
  9376.  
  9377.  
  9378. /*
  9379.  
  9380. var g = window.getComputedStyle;
  9381. Object.defineProperty(window, "getComputedStyle", {
  9382. configurable: !0,
  9383. enumerable: !0,
  9384. value: function() {
  9385. v.timeline._updateAnimationsPromises();
  9386. var e = g.apply(this, arguments);
  9387. h() && (e = g.apply(this, arguments));
  9388. v.timeline._updateAnimationsPromises();
  9389. return e
  9390. }
  9391. });
  9392.  
  9393. */
  9394.  
  9395.  
  9396.  
  9397.  
  9398. }
  9399.  
  9400.  
  9401.  
  9402.  
  9403. })();
  9404.  
  9405. !isUrlInEmbed && Promise.resolve().then(() => {
  9406.  
  9407. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  9408.  
  9409.  
  9410.  
  9411. class LimitedSizeSet extends Set {
  9412. constructor(n) {
  9413. super();
  9414. this.limit = n;
  9415. }
  9416.  
  9417. add(key) {
  9418. if (!super.has(key)) {
  9419. super.add(key);
  9420. let n = super.size - this.limit;
  9421. if (n > 0) {
  9422. const iterator = super.values();
  9423. do {
  9424. const firstKey = iterator.next().value; // Get the first (oldest) key
  9425. super.delete(firstKey); // Delete the oldest key
  9426. } while (--n > 0)
  9427. }
  9428. }
  9429. }
  9430.  
  9431. removeAdd(key) {
  9432. super.delete(key);
  9433. this.add(key);
  9434. }
  9435.  
  9436. }
  9437.  
  9438. // const wk3 = new WeakMap();
  9439.  
  9440. // let mtxVideoId = '';
  9441. // let aje3 = [];
  9442. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  9443. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  9444. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  9445. let mtzCount = 0; // the key keeps unchanged
  9446. // let mjtNextMainKey = '';
  9447. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  9448. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  9449. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  9450. // let allowNoDelay322=false;
  9451. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  9452.  
  9453. let mpKey22 = ''; // last success continutation key & url pair
  9454. let mpUrl22 = ''; // last success continutation key & url pair
  9455. let mpKey21 = ''; // latest requested continutation key & url pair
  9456. let mpUrl21 = ''; // latest requested continutation key & url pair
  9457.  
  9458.  
  9459. async function sha1Hex(message) {
  9460. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  9461. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  9462. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  9463. const hashHex = hashArray
  9464. .map((b) => b.toString(16).padStart(2, "0"))
  9465. .join(""); // convert bytes to hex string
  9466. return hashHex;
  9467. }
  9468.  
  9469. async function continuationLog(a, ...args) {
  9470. let b = a;
  9471. try {
  9472. if (advanceLogging) b = await sha1Hex(a);
  9473. let c = args.map(e => {
  9474. return e === a ? b : e
  9475. });
  9476. console.log(...c)
  9477. } catch (e) { console.warn(e) }
  9478. }
  9479.  
  9480. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  9481.  
  9482.  
  9483. if (mfvContinuationRecorded.length > 0) {
  9484. for (const [e, d] of mfvContinuationRecorded) {
  9485. mfyContinuationIgnored.removeAdd(e);
  9486. }
  9487. toClearRecorded && mfvContinuationRecorded.clear();
  9488. }
  9489.  
  9490. }
  9491.  
  9492. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  9493.  
  9494. const tmProto = taskMgr.constructor.prototype;
  9495. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  9496.  
  9497. if (!tmProto.addJob714) {
  9498.  
  9499. tmProto.addJob714 = tmProto.addJob;
  9500.  
  9501. tmProto.addJob = function (a, b, c) {
  9502. const jobId = this.addJob714(a, b, c);
  9503. if (jobId > 0) {
  9504. // const ez = wk3.get(this);
  9505. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  9506. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  9507.  
  9508. this.__lastJobId863__ = jobId;
  9509. }
  9510. return jobId;
  9511. }
  9512.  
  9513. }
  9514.  
  9515. if (!tmProto.cancelJob714) {
  9516.  
  9517. tmProto.cancelJob714 = tmProto.cancelJob;
  9518.  
  9519. tmProto.cancelJob = function (a) {
  9520. const res = this.cancelJob714(a);
  9521. // if (a > 0) {
  9522. // for (const e of aje3) {
  9523. // if (e.jobId === a) e.cancelled = true;
  9524. // }
  9525. // }
  9526. return res;
  9527. }
  9528.  
  9529. }
  9530.  
  9531. }
  9532. }
  9533.  
  9534.  
  9535. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  9536.  
  9537.  
  9538. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  9539. let dummy;
  9540. let cProto;
  9541. // let mc = 4;
  9542. // dummy = await observablePromise(() => {
  9543. // const r = document.querySelector('ytd-video-primary-info-renderer');
  9544. // if (!r) return;
  9545. // let cProto = insp(r).constructor.prototype;
  9546. // if (cProto.fetchUpdatedMetadata) return r;
  9547. // if (--mc < 0) return -1;
  9548. // return null;
  9549. // }).obtain();
  9550. dummy = document.createElement('ytd-video-primary-info-renderer');
  9551. if (!(dummy instanceof Element)) return;
  9552. // console.log(5022, dummy)
  9553. cProto = insp(dummy).constructor.prototype;
  9554.  
  9555. cProto.__getEmittorTaskMgr859__ = function () {
  9556. let taskMgr_ = null;
  9557. try {
  9558. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  9559. } catch (e) { }
  9560. return taskMgr_;
  9561. }
  9562. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  9563. // console.log(1234, cProto, cProto.is)
  9564. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  9565.  
  9566. let c_;
  9567. cProto.fetchUpdatedMetadata718 = function (a) {
  9568. // delay or immediate call the actual fetchUpdatedMetadata
  9569.  
  9570. let doImmediately = false;
  9571. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  9572.  
  9573. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  9574.  
  9575. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  9576.  
  9577. doImmediately = true;
  9578.  
  9579. }
  9580.  
  9581. if (mbCId322) {
  9582. clearTimeout(mbCId322);
  9583. mbCId322 = 0;
  9584. }
  9585.  
  9586. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  9587.  
  9588. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  9589.  
  9590. mbCId322 = setTimeout(() => {
  9591. this.fetchUpdatedMetadata717(a);
  9592. }, delay);
  9593.  
  9594. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  9595.  
  9596. }
  9597.  
  9598. cProto.fetchUpdatedMetadata = function (a) {
  9599.  
  9600. if (!pageSetupState) {
  9601. if (c_) clearTimeout(c_);
  9602. c_ = setTimeout(() => {
  9603. this.fetchUpdatedMetadata718(a);
  9604. }, 300);
  9605. return;
  9606. }
  9607.  
  9608. // pageSetupState == 0
  9609.  
  9610. try {
  9611.  
  9612. mbDelayBelowNCalls++;
  9613.  
  9614. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  9615. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  9616. }
  9617.  
  9618. // console.log('fum377', a)
  9619. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  9620. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  9621. return;
  9622. }
  9623.  
  9624. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  9625. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  9626. mjtLockPreviousKey = mjtRecordedPrevKey;
  9627. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  9628. }
  9629. // mjtNextMainKey = true;
  9630. mtzlastAllowedContinuation = '';
  9631. mtzCount = 0;
  9632. // allowNoDelay322 = false;
  9633. // fetch new metadata, cancel all previous continuations
  9634. copyPreviousContiuationToIgnored374(true);
  9635. } else if (typeof a === 'string') {
  9636. const videoPlayingId = videoPlayingY.videoId;
  9637.  
  9638. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  9639.  
  9640. let update21 = !!pageSetupVideoId;
  9641. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  9642. update21 = true;
  9643. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  9644. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  9645. return;
  9646. }
  9647. if (update21) {
  9648. mpKey21 = a;
  9649. mpUrl21 = pageSetupVideoId || videoPlayingId;
  9650. }
  9651.  
  9652. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  9653. }
  9654. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  9655. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  9656. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  9657. return this.fetchUpdatedMetadata718(a);
  9658.  
  9659. } catch (e) {
  9660. console.log('Code Error in fetchUpdatedMetadata', e);
  9661. }
  9662. return this.fetchUpdatedMetadata717(a)
  9663. }
  9664. }
  9665.  
  9666.  
  9667. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  9668. // console.log(1234, cProto, cProto.is)
  9669. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  9670. let mJob = null;
  9671.  
  9672. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  9673.  
  9674. try {
  9675.  
  9676. if (arguments.length > 0) {
  9677. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  9678. }
  9679. // mfy = mfv;
  9680.  
  9681. // mjtNextMainKey = '';
  9682. mtzlastAllowedContinuation = '';
  9683. mtzCount = 0;
  9684. if (mbCId322) {
  9685. clearTimeout(mbCId322);
  9686. mbCId322 = 0;
  9687. }
  9688. mbDelayBelowNCalls = 0;
  9689. // allowNoDelay322 = false;
  9690. copyPreviousContiuationToIgnored374(true);
  9691.  
  9692. const taskMgr = this.__getEmittorTaskMgr859__();
  9693. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  9694. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  9695. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  9696. }
  9697.  
  9698. // prevent depulicated schedule job by clearing previous JobId
  9699. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  9700.  
  9701. let res;
  9702.  
  9703. if (mJob) {
  9704. const job = mJob;
  9705. mJob = null;
  9706. console.log('cancelJob', job)
  9707. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  9708. // p.cancelJob(a,b);
  9709. }
  9710.  
  9711. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  9712.  
  9713. let pza = taskMgr.__lastJobId863__;
  9714. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  9715. let pzb = taskMgr.__lastJobId863__
  9716. if (pza !== pzb) {
  9717. mJob = pzb; // set [Interval Meta Update] jobId
  9718. }
  9719.  
  9720. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  9721. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  9722. // } else {
  9723. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  9724. // }
  9725.  
  9726. return res;
  9727.  
  9728. } else {
  9729. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  9730. }
  9731.  
  9732. } catch (e) {
  9733. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  9734. }
  9735.  
  9736.  
  9737. return this.scheduleInitialUpdatedMetadataRequest717();
  9738. }
  9739. }
  9740.  
  9741.  
  9742. });
  9743.  
  9744. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  9745. let dummy;
  9746. let cProto;
  9747. dummy = ytAppDom;
  9748. if (!(dummy instanceof Element)) return;
  9749. cProto = insp(dummy).constructor.prototype;
  9750. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  9751. // console.log(1234, cProto, cProto.is);
  9752. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  9753. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  9754. // console.log(123401, arguments);
  9755. // return this.handleServiceRequest717_(a, b, c, d);
  9756. // }
  9757.  
  9758. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  9759.  
  9760. // cProto.handleServiceRequest_ = function(a,b,c,d){
  9761. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  9762. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  9763. // console.log('mfv', c.continuation);
  9764. // mfv.add( c.continuation);
  9765. // }
  9766. // return this.handleServiceRequest717_(a,b,c,d);
  9767. // }
  9768.  
  9769. function extraArguments322(a, b, c) {
  9770. let is = (a || 0).is;
  9771. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  9772. let continuation = (c || 0).continuation;
  9773. if (typeof is !== 'string') is = null;
  9774. if (typeof videoId !== 'string') videoId = null;
  9775. if (typeof continuation !== 'string') continuation = null;
  9776. return { is, videoId, continuation };
  9777. }
  9778.  
  9779. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  9780. cProto.sendServiceAjax_ = function (a, b, c, d) {
  9781.  
  9782. // console.log(8001)
  9783. try {
  9784.  
  9785. const { is, videoId, continuation } = extraArguments322(a, b, c);
  9786.  
  9787. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  9788. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  9789. }
  9790.  
  9791. if (pageSetupVideoId && videoId && continuation) {
  9792. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  9793. mfyContinuationIgnored.removeAdd(continuation);
  9794. mfvContinuationRecorded.delete(continuation);
  9795. return;
  9796. }
  9797. }
  9798.  
  9799. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  9800. copyPreviousContiuationToIgnored374(false);
  9801. mfyContinuationIgnored.delete(continuation);
  9802. mfvContinuationRecorded.removeAdd(continuation);
  9803. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  9804. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  9805. mjtLockPreviousKey = '';
  9806. }
  9807. // if (mjtNextMainKey === continuation) {
  9808. // copyPreviousContiuationToIgnored(false);
  9809. // mfyContinuationIgnored.delete(continuation);
  9810. // mfvContinuationRecorded.add(continuation);
  9811. // }
  9812.  
  9813.  
  9814. if (mfyContinuationIgnored && continuation) {
  9815. if (mfyContinuationIgnored.has(continuation)) {
  9816. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  9817. return;
  9818. }
  9819. }
  9820.  
  9821. // console.log(59902, a?.is, b,c,d)
  9822. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  9823. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  9824. // console.log('mfv377', continuation);
  9825. mfvContinuationRecorded.add(continuation);
  9826. }
  9827.  
  9828. // if (videoId) {
  9829. // if (!pageSetupVideoId) return; // ignore page not ready
  9830. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  9831. // if (videoId !== pageSetupVideoId) {
  9832. // return;
  9833. // }
  9834. // }
  9835.  
  9836. } catch (e) {
  9837. console.log('Coding Error in sendServiceAjax_', e)
  9838. }
  9839. // console.log(8002)
  9840. // console.log(123402, arguments);
  9841. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  9842.  
  9843. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  9844. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  9845. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  9846. // get(target, prop, receiver){
  9847. // console.log('xxs99', target.videoId, mtx)
  9848. // if(prop ==='kdkw33') return 1;
  9849. // console.log(3322, prop, target)
  9850. // if(prop === 'initialDelayMs') {
  9851. // throw new Error("ABCC");
  9852. // }
  9853. // return target[prop];
  9854. // },
  9855. // set(target, prop, value, receiver){
  9856.  
  9857. // if(prop ==='kdkw33') return true;
  9858. // target[prop]=value;
  9859. // return true;
  9860. // }
  9861. // });
  9862. // }
  9863. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  9864. return this.sendServiceAjax717_(a, b, c, d);
  9865. }
  9866. }
  9867.  
  9868. function delayClearOtherKeys(lztContinuation) {
  9869. // // schedule delayed removal if mfyContinuationIgnored is not empty
  9870. // getRafPromise().then(() => {
  9871. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  9872. // // foreground page only
  9873.  
  9874. // });
  9875.  
  9876.  
  9877. if (lztContinuation !== mtzlastAllowedContinuation) return;
  9878. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  9879. if (!mfyContinuationIgnored.size) return;
  9880. if (mfyContinuationIgnored.size > 1) {
  9881. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  9882. }
  9883. mfyContinuationIgnored.forEach((value, key) => {
  9884. if (key !== lztContinuation) {
  9885. mfyContinuationIgnored.delete(key);
  9886. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  9887. }
  9888. });
  9889.  
  9890. }
  9891. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  9892. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  9893. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  9894.  
  9895. // console.log(8003)
  9896. try {
  9897.  
  9898.  
  9899. const { is, videoId, continuation } = extraArguments322(b, c, d);
  9900.  
  9901. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  9902. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  9903. }
  9904.  
  9905. if (pageSetupVideoId && videoId && continuation) {
  9906. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  9907. mfyContinuationIgnored.removeAdd(continuation);
  9908. mfvContinuationRecorded.delete(continuation);
  9909. return;
  9910. }
  9911. }
  9912.  
  9913. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  9914. copyPreviousContiuationToIgnored374(false);
  9915. mfyContinuationIgnored.delete(continuation);
  9916. mfvContinuationRecorded.removeAdd(continuation);
  9917. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  9918. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  9919. mjtLockPreviousKey = '';
  9920. }
  9921.  
  9922. // if (mjtNextMainKey === continuation) {
  9923. // copyPreviousContiuationToIgnored(false);
  9924. // mfyContinuationIgnored.delete(continuation);
  9925. // mfvContinuationRecorded.add(continuation);
  9926. // }
  9927.  
  9928. const lztContinuation = continuation;
  9929.  
  9930. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  9931. if (mfyContinuationIgnored.has(lztContinuation)) {
  9932. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  9933. return;
  9934. }
  9935. }
  9936.  
  9937. // if (videoId) {
  9938. // if (!pageSetupVideoId) return; // ignore page not ready
  9939. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  9940. // if (videoId !== pageSetupVideoId) {
  9941. // return;
  9942. // }
  9943. // }
  9944.  
  9945. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  9946. mtzlastAllowedContinuation = lztContinuation;
  9947. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  9948.  
  9949. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  9950. mjtRecordedPrevKey = lztContinuation;
  9951. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  9952. // if (mfyContinuationIgnored.size > 0) {
  9953. // delayClearOtherKeys(lztContinuation);
  9954. // }
  9955. mtzCount = 0;
  9956. // allowNoDelay322 = false;
  9957. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  9958. // repeated
  9959. if (++mtzCount > 1e9) mtzCount = 1e4;
  9960. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  9961.  
  9962. // if (mtzCount >= 3) allowNoDelay322 = true;
  9963. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  9964. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  9965. }
  9966. if (mtzCount === 5) {
  9967. mfvContinuationRecorded.clear();
  9968. mfvContinuationRecorded.add(lztContinuation);
  9969. }
  9970.  
  9971. }
  9972.  
  9973. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  9974. mpKey22 = lztContinuation;
  9975. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  9976. }
  9977.  
  9978. if (mbCId322) {
  9979. clearTimeout(mbCId322);
  9980. mbCId322 = 0;
  9981. }
  9982. } catch (e) {
  9983. console.log('Coding Error in getCancellableNetworkPromise_', e)
  9984. }
  9985.  
  9986. // console.log(8004)
  9987. // console.log(123403, arguments);
  9988. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  9989.  
  9990. // console.log(5163, a?.is,b,c,d,e);
  9991. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  9992. }
  9993. }
  9994. });
  9995.  
  9996. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  9997.  
  9998.  
  9999. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  10000.  
  10001. let dummy;
  10002. let cProto;
  10003.  
  10004. dummy = document.createElement('ytd-expander');
  10005. cProto = insp(dummy).constructor.prototype;
  10006.  
  10007. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  10008.  
  10009. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  10010. cProto.childrenChanged14 = cProto.childrenChanged;
  10011.  
  10012. cProto.initChildrenObserver = function () {
  10013. var a = this;
  10014. this.observer = new MutationObserver(function () {
  10015. a.childrenChanged()
  10016. }
  10017. );
  10018. this.observer.observe(this.content, {
  10019. subtree: !0,
  10020. childList: !0,
  10021. attributes: !0,
  10022. characterData: !0
  10023. });
  10024. this.childrenChanged()
  10025. }
  10026. ;
  10027. cProto.childrenChanged = function () {
  10028. if (this.alwaysToggleable) {
  10029. this.canToggle = this.alwaysToggleable;
  10030. } else if (!this.canToggleJobId) {
  10031. this.canToggleJobId = 1;
  10032. foregroundPromiseFn().then(() => {
  10033. this.canToggleJobId = 0;
  10034. this.calculateCanCollapse()
  10035. })
  10036. }
  10037. }
  10038.  
  10039. // console.log(cProto.initChildrenObserver)
  10040. console.debug('ytd-expander-fix-childrenChanged');
  10041.  
  10042. }
  10043.  
  10044. });
  10045.  
  10046.  
  10047. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  10048.  
  10049. let dummy;
  10050. let cProto;
  10051. dummy = document.createElement('paper-ripple');
  10052. cProto = insp(dummy).constructor.prototype;
  10053.  
  10054. if (fnIntegrity(cProto.animate, '0.74.5')) {
  10055.  
  10056.  
  10057. cProto.animate34 = cProto.animate;
  10058. cProto.animate = function () {
  10059. if (this._animating) {
  10060. var a;
  10061. const ripples = this.ripples;
  10062. for (a = 0; a < ripples.length; ++a) {
  10063. var b = ripples[a];
  10064. b.draw();
  10065. this.$.background.style.opacity = b.outerOpacity;
  10066. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  10067. }
  10068. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  10069. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  10070. foregroundPromiseFn().then(this._boundAnimate38);
  10071. } else {
  10072. this.onAnimationComplete();
  10073. }
  10074. }
  10075. }
  10076.  
  10077. console.debug('FIX_paper_ripple_animate')
  10078.  
  10079. // console.log(cProto.animate)
  10080.  
  10081. }
  10082.  
  10083. });
  10084.  
  10085. if (FIX_doIdomRender) {
  10086.  
  10087. const xsetTimeout = function (f, d) {
  10088. if (xsetTimeout.m511 === 1 && !d) {
  10089. xsetTimeout.m511 = 2;
  10090. xsetTimeout.m568 = f;
  10091. } else {
  10092. return setTimeout.apply(window, arguments)
  10093. }
  10094.  
  10095. }
  10096.  
  10097. /**
  10098. *
  10099. IGb = function(a) {
  10100. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  10101. c || (a.requestAninmationFrameResolver = new Vi,
  10102. c = a.requestAninmationFrameResolver.promise,
  10103. Da.requestAnimationFrame(function() {
  10104. var d;
  10105. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  10106. a.requestAninmationFrameResolver = null
  10107. }));
  10108. return c
  10109. }
  10110.  
  10111.  
  10112. */
  10113.  
  10114. const xrequestAnimationFrame = function (f) {
  10115. const h = `${f}`;
  10116. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  10117. let t = null;
  10118. xsetTimeout.m511 = 1;
  10119. f();
  10120. if (xsetTimeout.m511 === 2) {
  10121. t = xsetTimeout.m568;
  10122. xsetTimeout.m568 = null;
  10123. }
  10124. xsetTimeout.m511 = 0;
  10125. if (typeof t === 'function') {
  10126. foregroundPromiseFn().then(t);
  10127. }
  10128. } else if (h.includes("requestAninmationFrameResolver")) {
  10129. foregroundPromiseFn().then(f);
  10130. } else {
  10131. return requestAnimationFrame.apply(window, arguments);
  10132. }
  10133. }
  10134.  
  10135. let busy = false;
  10136. const doIdomRender = function () {
  10137.  
  10138. if (!this) return;
  10139. if (busy) {
  10140. return this.doIdomRender13(...arguments);
  10141. }
  10142. busy = true;
  10143. const { requestAnimationFrame, setTimeout } = window;
  10144. window.requestAnimationFrame = xrequestAnimationFrame;
  10145. window.setTimeout = xsetTimeout;
  10146. let r = this.doIdomRender13(...arguments);
  10147. window.requestAnimationFrame = requestAnimationFrame;
  10148. window.setTimeout = setTimeout;
  10149. busy = false;
  10150. return r;
  10151. };
  10152. 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']) {
  10153.  
  10154.  
  10155. whenCEDefined(ytTag).then(() => {
  10156.  
  10157. let dummy;
  10158. let cProto;
  10159. dummy = document.createElement(ytTag);
  10160. cProto = insp(dummy).constructor.prototype;
  10161.  
  10162. cProto.doIdomRender13 = cProto.doIdomRender;
  10163. cProto.doIdomRender = doIdomRender;
  10164.  
  10165. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  10166.  
  10167. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  10168.  
  10169.  
  10170.  
  10171. });
  10172.  
  10173. }
  10174.  
  10175. }
  10176.  
  10177.  
  10178.  
  10179.  
  10180. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  10181.  
  10182. const sMap = new Map();
  10183.  
  10184. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  10185. const ZT = function () {
  10186. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  10187. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  10188. c = b & 15,
  10189. b >>= 4,
  10190. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  10191. return a.join("")
  10192. };
  10193.  
  10194.  
  10195. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  10196.  
  10197. const popupContainer = await observablePromise(() => {
  10198. return popupContainerCollection[0];
  10199. }).obtain();
  10200.  
  10201.  
  10202. let cProto;
  10203. cProto = insp(popupContainer).constructor.prototype;
  10204.  
  10205.  
  10206. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  10207. console.log('FIX_POPUP_UNIQUE_ID NG')
  10208. return;
  10209. }
  10210. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  10211.  
  10212. cProto.handleOpenPopupAction = function (a, b) {
  10213.  
  10214. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  10215.  
  10216. a.__jOdQA__ = true;
  10217.  
  10218. try {
  10219.  
  10220. const h = this.hostElement;
  10221.  
  10222. if (h instanceof HTMLElement_) {
  10223.  
  10224. const map = h.__skme44__ = h.__skme44__ || new Map();
  10225.  
  10226. let mKey = '';
  10227. const wKey = firstObjectKey(a);
  10228. const wObj = wKey ? a[wKey] : null;
  10229. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  10230. const pKey = firstObjectKey(wObj.popup)
  10231. const pObj = pKey ? wObj.popup[pKey] : null;
  10232. let contentKey = '';
  10233. let headerKey = '';
  10234.  
  10235. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  10236. contentKey = firstObjectKey(pObj.content)
  10237. headerKey = firstObjectKey(pObj.header)
  10238. }
  10239. if (contentKey && headerKey) {
  10240.  
  10241. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  10242.  
  10243. if (mKey) {
  10244.  
  10245. if (!wObj.uniqueId) {
  10246. for (let i = 0; i < 8; i++) {
  10247. wObj.uniqueId = ZT();
  10248. if (!sMap.has(wObj.uniqueId)) break;
  10249. }
  10250. }
  10251. const oId = wObj.uniqueId
  10252.  
  10253. let nId_ = map.get(mKey);
  10254. if (!nId_) {
  10255. map.set(mKey, nId_ = oId);
  10256. }
  10257.  
  10258. wObj.uniqueId = nId_ || wObj.uniqueId;
  10259.  
  10260. const nId = wObj.uniqueId
  10261.  
  10262. sMap.set(oId, nId);
  10263. sMap.set(nId, nId);
  10264.  
  10265. wObj.uniqueId = nId;
  10266. pObj.targetId = nId;
  10267. pObj.identifier.tag = nId;
  10268.  
  10269. if (oId !== nId) {
  10270. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  10271. }
  10272.  
  10273. }
  10274.  
  10275. }
  10276. }
  10277.  
  10278. // console.log(12213, mKey, a, b, h)
  10279.  
  10280. }
  10281.  
  10282. } catch (e) {
  10283. console.warn(e)
  10284. }
  10285.  
  10286. try {
  10287.  
  10288. const results = searchNestedObject(a, (x) => {
  10289. if (typeof x === 'string' && x.length === 36) {
  10290. 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;
  10291. }
  10292. return false;
  10293. });
  10294. for (const [obj, key] of results) {
  10295. const oId = obj[key];
  10296. const nId = sMap.get(oId);
  10297. if (nId) obj[key] = nId;
  10298. }
  10299. } catch (e) {
  10300. console.warn(e)
  10301. }
  10302.  
  10303.  
  10304. }
  10305.  
  10306. return this.handleOpenPopupAction3868(...arguments)
  10307. }
  10308.  
  10309. console.log('FIX_POPUP_UNIQUE_ID OK')
  10310.  
  10311.  
  10312. });
  10313.  
  10314.  
  10315. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  10316.  
  10317. let dummy;
  10318. let cProto;
  10319. dummy = document.createElement('yt-formatted-string');
  10320. cProto = insp(dummy).constructor.prototype;
  10321.  
  10322. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  10323. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  10324. return;
  10325. }
  10326.  
  10327. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  10328. cProto.setNodeStyle_ = function (a, b) {
  10329. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  10330. return this.setNodeStyle17_(a, b);
  10331. }
  10332.  
  10333. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  10334. });
  10335.  
  10336. });
  10337.  
  10338. });
  10339.  
  10340.  
  10341.  
  10342.  
  10343. if (isMainWindow) {
  10344.  
  10345. console.groupCollapsed(
  10346. "%cYouTube JS Engine Tamer",
  10347. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  10348. );
  10349.  
  10350.  
  10351.  
  10352. console.log("Script is loaded.");
  10353. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  10354.  
  10355. console.log("This script is experimental and subject to further changes.");
  10356.  
  10357. console.log("This might boost your YouTube performance.");
  10358.  
  10359. console.log("CAUTION: This might break your YouTube.");
  10360.  
  10361.  
  10362. if (prepareLogs.length >= 1) {
  10363. console.log(" =========================================================================== ");
  10364.  
  10365. for (const msg of prepareLogs) {
  10366. console.log(msg)
  10367. }
  10368.  
  10369. console.log(" =========================================================================== ");
  10370. }
  10371.  
  10372. console.groupEnd();
  10373.  
  10374. }
  10375.  
  10376.  
  10377.  
  10378. })();