YouTube JS Engine Tamer

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

当前为 2025-04-22 提交的版本,查看 最新版本

  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.12
  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. // const DO_createStampDomArrayFnE1_ = true; // added in 2025.02.11 - to improve stampDom responsiveness
  111. // const DO_createStampDomArrayFnE1_noConstraintE = true;
  112. // const DO_createStampDomArrayFnE1_nativeAppendD = true;
  113. // const DO_createStampDomArrayFnF1_ = true;
  114. // const DO_createStampDomArray_STRICT_FULFILLMENT = true; // avoid issues; can be changed to false
  115. // const DO_createStampDomArray_DEBUG = false;
  116.  
  117. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  118.  
  119. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  120. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  121. // first tp-yt-paper-dialog: show once the page is loaded.
  122. // second tp-yt-paper-dialog: click "...more"
  123. // third tp-yt-paper-dialog: click "... and 3 more links"
  124. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  125. // currently, uniqueId is preassigned by the network resolveCommand.
  126. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  127. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  128.  
  129. // handleOpenPopupAction -> createCacheKey
  130. // handleClosePopupAction_ -> createCacheKey
  131. // handleGetPopupOpenedAction_ -> createCacheKey
  132. // getAndMaybeCreatePopup_ -> createCacheKey
  133. // closePopup -> createCacheKey
  134.  
  135. // yt-close-popup-command -> handleClosePopupCommand_
  136.  
  137. // ensurePopup_ -> getAndMaybeCreatePopup_
  138.  
  139. // yt-close-popup-action -> handleClosePopupAction_
  140. // closePopup -> handleClosePopupAction_
  141. // handleOpenPopupAction -> handleClosePopupAction_
  142. // handleClosePopupCommand_ -> handleClosePopupAction_
  143. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  144.  
  145. // yt-open-popup-action -> handleOpenPopupAction
  146.  
  147.  
  148. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  149. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  150.  
  151. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  152. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  153. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  154.  
  155.  
  156. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  157. const FIX_DOM_IF_TEMPLATE = true;
  158. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  159. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  160. const DEBUG_DBR847 = false;
  161. const DEBUG_xx847 = false;
  162. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  163. const DEBUG_renderDebounceTs = false;
  164.  
  165. const FIX_ICON_RENDER = true;
  166.  
  167. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  168.  
  169. /*
  170.  
  171. FIX_DOM_IFREPEAT_RenderDebouncerChange
  172.  
  173. avoid Polymer.flush
  174. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  175.  
  176. var Is = function() {
  177. do {
  178. var a = window.ShadyDOM && ShadyDOM.flush();
  179. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  180. var b = NNa()
  181. } while (a || b)
  182. };
  183.  
  184. , NNa = function() {
  185. var a = !!ts.size;
  186. ts.forEach(function(b) {
  187. try {
  188. b.flush()
  189. } catch (c) {
  190. setTimeout(function() {
  191. throw c
  192. })
  193. }
  194. });
  195. return a
  196. };
  197.  
  198. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  199. // this coding logic should be incorrect (mistake).
  200.  
  201. */
  202.  
  203.  
  204.  
  205. // ----------------------------- Shortkey Keyboard Control -----------------------------
  206. // dependency: FIX_yt_player
  207.  
  208. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  209. // [0] no fix - not recommended
  210. // [1] basic fix - just fix the global focus detection variable
  211. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  212. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  213.  
  214. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  215. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  216.  
  217. const PROP_OverReInclusion_AVOID = true;
  218. const PROP_OverReInclusion_DEBUGLOG = false;
  219. const PROP_OverReInclusion_LIST = new Set([
  220. 'hostElement72',
  221. 'parentComponent72',
  222. 'localVisibilityObserver_72',
  223. 'cachedProviderNode_72',
  224. '__template72',
  225. '__templatizeOwner72',
  226. '__templateInfo72',
  227. '__dataHost72',
  228. '__CE_shadowRoot72',
  229. 'elements_72',
  230.  
  231. 'ky36',
  232. 'kz62',
  233. 'm822',
  234.  
  235.  
  236.  
  237. // To be reviewed.
  238.  
  239. // chat messages
  240. 'disabled', 'allowedProps',
  241. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  242.  
  243. 'dimension', 'loadTime', 'pendingPaint',
  244.  
  245. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  246.  
  247. 'respectLangDir', 'noEndpoints',
  248.  
  249.  
  250. 'objectURL',
  251. 'buttonOverrides', 'queuedMessages',
  252. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  253. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  254. 'hoverJobId', 'JSC$14573_touched',
  255.  
  256.  
  257. // tbc
  258. 'toggleable', 'isConnected',
  259. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  260. 'disableDeselectEvent',
  261. 'emojiSize',
  262.  
  263. 'buttonOverride',
  264. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  265.  
  266. // others
  267. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  268. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  269. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  270. // 'dimension', 'loadTime', 'pendingPaint',
  271. // 'disabled', 'allowedProps',
  272.  
  273.  
  274. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  275. // 'actionMap',
  276.  
  277. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  278.  
  279. 'clearTimeout',
  280. 'switchTemplateAtRegistration', 'hasUnmounted',
  281. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  282. 'tangoConfiguration',
  283. 'itemIdToDockDurationMap',
  284. 'actionMap',
  285.  
  286. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  287. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  288. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  289.  
  290. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  291. // 'stopKeyboardEventPropagation', 'emojiSize',
  292. // 'switchTemplateAtRegistration', 'hasUnmounted',
  293. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  294. // 'isReusable', 'tangoConfiguration',
  295. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  296. // */
  297.  
  298. ]);
  299.  
  300.  
  301. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  302.  
  303. // ----------------------------- Shortkey Keyboard Control -----------------------------
  304.  
  305. /*
  306. window.addEventListener('edm',()=>{
  307. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  308. });
  309.  
  310. window.addEventListener('edn',()=>{
  311. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  312. });
  313. window.addEventListener('edr',()=>{
  314. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  315. });
  316. */
  317.  
  318. // only for macOS with Chrome/Firefox 100+
  319. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  320.  
  321. const win = this instanceof Window ? this : window;
  322.  
  323. // Create a unique key for the script and check if it is already running
  324. const hkey_script = 'jswylcojvzts';
  325. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  326. win[hkey_script] = true;
  327.  
  328.  
  329. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  330.  
  331. let BY_PASS_KEYBOARD_CONTROL = false;
  332.  
  333.  
  334. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  335. /** @type {(f: ()=>{})=>{}} */
  336. const nextBrowserTick_ = nextBrowserTick;
  337. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  338. console.log('nextBrowserTick is not found.');
  339. return;
  340. }
  341.  
  342. let p59 = 0;
  343.  
  344. const Promise = (async () => { })().constructor;
  345.  
  346. const PromiseExternal = ((resolve_, reject_) => {
  347. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  348. return class PromiseExternal extends Promise {
  349. constructor(cb = h) {
  350. super(cb);
  351. if (cb === h) {
  352. /** @type {(value: any) => void} */
  353. this.resolve = resolve_;
  354. /** @type {(reason?: any) => void} */
  355. this.reject = reject_;
  356. }
  357. }
  358. };
  359. })();
  360.  
  361. let ttpHTML = (s) => {
  362. ttpHTML = s => s;
  363. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  364. let s = s => s;
  365. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  366. }
  367. return s;
  368. }
  369.  
  370.  
  371. /** @type { typeof HTMLElement } */
  372. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  373. const nativeAppendE = HTMLElement_.prototype.append;
  374. const nativeRemoveE = HTMLElement_.prototype.remove;
  375. const DocumentFragment_ = DocumentFragment;
  376. const nativeAppendD = DocumentFragment_.prototype.append;
  377. const Node_ = Node;
  378.  
  379. /**
  380. @param {number} x
  381. @param {number} d */
  382. const toFixed2 = (x, d) => {
  383. let t = x.toFixed(d);
  384. let y = `${+t}`;
  385. return y.length > t.length ? t : y;
  386. }
  387.  
  388.  
  389. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  390.  
  391.  
  392. const TRANSLATE_DEBUG = false;
  393.  
  394.  
  395. let xdeadc00 = null; // a deteched node with __domApi
  396. let xlivec00 = null; // a deteched node with __domApi
  397.  
  398. let removeTNodeRM = null;
  399. let removeTNodeBP = false;
  400.  
  401.  
  402.  
  403.  
  404. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  405.  
  406. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  407.  
  408. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  409.  
  410. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  411.  
  412.  
  413. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  414. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  415. return;
  416. }
  417.  
  418.  
  419. const mapGet = Map.prototype.get;
  420. const setHas = Set.prototype.has;
  421.  
  422.  
  423. /** @type {Map | null} */
  424. let qcMap = null;
  425.  
  426. Set.prototype.has = function (a) {
  427. if (a === 'dummy-4718') return false; // false to allow re-use?
  428. return setHas.call(this, a);
  429. }
  430.  
  431. Map.prototype.get = function (a) {
  432. if (a === 'dummy-4718') qcMap = this;
  433. return mapGet.call(this, a);
  434. };
  435. let r;
  436. try {
  437. r = mainCnt.createComponent_('dummy-4718', {}, true);
  438. } catch (e) {
  439.  
  440. }
  441.  
  442. Map.prototype.get = mapGet;
  443. Set.prototype.has = setHas;
  444.  
  445. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  446.  
  447.  
  448. // clearInterval(ckId);
  449. // ckId = 0;
  450.  
  451. if (qcMap !== null && qcMap instanceof Map) {
  452.  
  453. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  454. qcMap.__qcMap8781__ = true;
  455.  
  456. const setArrayC = (c) => {
  457. if (c instanceof Array) {
  458. c.length = 0;
  459. c.push = function () { };
  460. c.pop = function () { };
  461. c.shift = function () { };
  462. c.unshift = function () { };
  463. c.splice = function () { };
  464. c.sort = function () { };
  465. c.reverse = function () { };
  466. }
  467. }
  468.  
  469. const cleaning = function (m) {
  470. m.forEach(setArrayC);
  471. m.clear();
  472. }
  473.  
  474. qcMap.set = function (b, c) {
  475. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  476.  
  477. setArrayC(c);
  478.  
  479. // console.log('qcMap.set', b, c);
  480.  
  481. if (this.size > 0) {
  482. // play safe
  483.  
  484. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  485. cleaning(this);
  486. }
  487.  
  488. }
  489. qcMap.get = function (b) {
  490. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  491.  
  492. // console.log('qcMap.get', b);
  493.  
  494. if (this.size > 0) {
  495. // play safe
  496.  
  497. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  498. cleaning(this);
  499. }
  500.  
  501. }
  502.  
  503.  
  504. if (qcMap.size > 0) {
  505.  
  506. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  507. cleaning(qcMap);
  508. }
  509.  
  510. }
  511.  
  512. }
  513.  
  514. r = null;
  515. qcMap = null;
  516.  
  517. }
  518.  
  519. function getTranslate() {
  520.  
  521. pLoad.then(() => {
  522.  
  523. let nonce = document.querySelector('style[nonce]');
  524. nonce = nonce ? nonce.getAttribute('nonce') : null;
  525. const st = document.createElement('style');
  526. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  527. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  528. let parent;
  529. if (parent = document.head) parent.appendChild(st);
  530. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  531.  
  532. });
  533.  
  534. const snCache = new Map();
  535.  
  536. if (TRANSLATE_DEBUG) {
  537. console.log(11)
  538. }
  539.  
  540. /** @type {(str: string?) => string} */
  541. function _snippetText(str) {
  542. // str can be underfinded
  543. if (!str || typeof str !== 'string') return '';
  544. let res = snCache.get(str);
  545. if (res === undefined) {
  546. let b = false;
  547. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  548. b = true;
  549. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  550. });
  551. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  552. b = true;
  553. return '';
  554. });
  555. if (b) {
  556. snCache.set(str, res);
  557. snCache.set(res, null);
  558. } else {
  559. res = null;
  560. snCache.set(str, null);
  561. }
  562. }
  563. return res === null ? str : res;
  564. }
  565.  
  566. /** @type {(snippet: Object) => string} */
  567. function snippetText(snippet) {
  568. let runs = snippet.runs;
  569. const n = runs.length;
  570. if (n === 1) return _snippetText(runs[0].text);
  571. let res = new Array(n);
  572. let ci = 0;
  573. for (const s of runs) {
  574. res[ci++] = _snippetText(s.text);
  575. }
  576. return res.join('\n');
  577. }
  578.  
  579. const _DEBUG_szz = (t) => t.map(x => {
  580. const tsr = x.transcriptSegmentRenderer;
  581. return ({
  582. t: tsr.snippet.runs.map(x => x.text).join('//'),
  583. a: tsr.startMs,
  584. b: tsr.endMs
  585. });
  586. });
  587.  
  588. const fixRuns = (runs) => {
  589. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  590. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  591. const text = runs[0].text;
  592. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  593. const s = text.split(nlc);
  594. let bi = 0;
  595. runs.length = s.length;
  596. for (const text of s) {
  597. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  598. }
  599. }
  600. for (const s of runs) {
  601. s.text = _snippetText(s.text);
  602. }
  603. }
  604.  
  605. function translate(initialSegments) {
  606. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  607.  
  608. if (!initialSegments) return initialSegments;
  609.  
  610. if (TRANSLATE_DEBUG) {
  611. console.log(12);
  612. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  613. let obj = JSON.parse(r);
  614. console.log(7558, 1, obj)
  615. return obj;
  616. }).then(p => {
  617. let obj = _DEBUG_szz(p)
  618. console.log(7558, 2, obj)
  619. })
  620. }
  621.  
  622.  
  623. //let mapRej = new WeakSet();
  624.  
  625. const n1 = initialSegments.length;
  626. if (!n1) return fRes;
  627. let n2 = 0;
  628.  
  629.  
  630. const fRes = new Array(n1);
  631. // -----------------------------------------------------------------------------------------
  632.  
  633. const s8 = Symbol();
  634.  
  635. {
  636.  
  637. /** @type {Map<String, Object>} */
  638. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  639.  
  640. // /-* * @type {Map<String, number>} *-/
  641. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  642. // 1: ok
  643. // 2: abandoned effect text
  644.  
  645. for (const initialSegment of initialSegments) {
  646. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  647. if (!transcript) {
  648. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  649. fRes[n2++] = initialSegment;
  650. continue;
  651. }
  652. const runs = transcript.snippet.runs
  653. if (!runs || runs.length === 0) {
  654. initialSegment[s8] = true;
  655. continue;
  656. }
  657. let startMs = (+transcript.startMs || 0); //integer
  658. let endMs = (+transcript.endMs || 0); //integer
  659. if (startMs === endMs) {
  660. // effect text
  661. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  662. //mapRej.add(initialSegment)
  663. continue;
  664. }
  665. if (endMs - startMs < 30) {
  666. continue;
  667. }
  668. const text = snippetText(transcript.snippet);
  669. const hEntry = cacheTexts.get(text);
  670. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  671. if (mh1e === 2) continue;
  672. const entry = {
  673. startMs,
  674. endMs,
  675. initialSegment,
  676. text
  677. };
  678. if (mh1e === 0) {
  679. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  680. initialSegment[s8] = true;
  681. cacheTexts.set(text, null);
  682. //effect only
  683. // https://www.youtube.com/watch?v=zLak0dxBKpM
  684. //mapRej.add(initialSegment)
  685. continue;
  686. }
  687. } else if (hEntry) {
  688.  
  689. const timeDiff = entry.startMs - hEntry.endMs;
  690. let shouldMerge = false;
  691.  
  692. if (timeDiff >= 0) {
  693.  
  694. if (timeDiff < 25) {
  695. shouldMerge = true;
  696. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  697. shouldMerge = true;
  698. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  699. shouldMerge = true;
  700. }
  701.  
  702. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  703. // abandon the current entry.
  704. // absorbed by previous entry
  705. hEntry.endMs = entry.endMs;
  706. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  707. //mapRej.add(entry.initialSegment);
  708. continue;
  709. }
  710.  
  711. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  712.  
  713. // abandon the current entry.
  714. // absorbed by previous entry
  715. if (entry.endMs > hEntry.endMs) {
  716. hEntry.endMs = entry.endMs;
  717. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  718. }
  719. //mapRej.add(entry.initialSegment);
  720. continue;
  721.  
  722. }
  723.  
  724. }
  725. //if not abandoned
  726. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  727. // for (const s of runs) {
  728. // s.text = _snippetText(s.text);
  729. // }
  730. fixRuns(runs);
  731. fRes[n2++] = initialSegment;
  732. }
  733.  
  734. // cacheTexts.clear(); // let GC do it.
  735. cacheTexts = null;
  736. // mh1.clear(); // let GC do it.
  737. // mh1 = null;
  738.  
  739. }
  740.  
  741. const si_length = fRes.length = n2;
  742. const sj_length = n1;
  743.  
  744. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  745. // collect the abandon text to become second subtitle
  746.  
  747. let sj_start = 0;
  748. let invalid_sj = -1;
  749. for (let si = 0; si < si_length; si++) {
  750. const segment = fRes[si];
  751. let transcript = segment.transcriptSegmentRenderer;
  752. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  753. const runs = transcript.snippet.runs;
  754. // fixRuns(runs);
  755. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  756. const main_startMs = (+transcript.startMs || 0);
  757. const main_endMs = (+transcript.endMs || 0);
  758. transcript = null;
  759.  
  760. /** @type {Map<string, number>} */
  761. let tMap = new Map(); // avoid duplicate with javascript object properties
  762.  
  763. // assume that it is asc-ordered array of key startMs;
  764. for (let sj = sj_start; sj < sj_length; sj++) {
  765. const initialSegment = initialSegments[sj];
  766.  
  767. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  768.  
  769. const tSegment = initialSegment.transcriptSegmentRenderer;
  770.  
  771. if (!tSegment) {
  772. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  773. invalid_sj = sj; // should invalid_sj be set ?
  774. continue;
  775. }
  776.  
  777. const startMs = (+tSegment.startMs || 0)
  778. const isStartValid = startMs >= main_startMs;
  779. if (!isStartValid) {
  780. invalid_sj = sj;
  781. continue;
  782. }
  783. // isStartValid must be true
  784. if (startMs > main_endMs) {
  785. sj_start = invalid_sj + 1;
  786. break;
  787. }
  788.  
  789. const endMs = (+tSegment.endMs || 0)
  790. if (endMs <= main_endMs) {
  791. const mt = snippetText(tSegment.snippet);
  792. const prev = tMap.get(mt);
  793. if (endMs >= startMs) {
  794. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  795. }
  796. }
  797.  
  798. }
  799.  
  800. if (tMap.size <= 1) continue; // no second line
  801. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  802. tMap = null;
  803.  
  804. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  805.  
  806. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  807.  
  808. let targetZ = rg[1][1];
  809. if (targetZ > 4) {
  810. let az = 0;
  811. let fail = false;
  812. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  813. az += rg[idx][1];
  814. if (az >= targetZ) {
  815. fail = true;
  816. break;
  817. }
  818. }
  819. if (!fail) {
  820. const rgA = rg[0][0];
  821. const rgB = rg[1][0];
  822. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  823. if (isDiff && rgA === _snippetText(runs[0].text)) {
  824. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  825. runs.push({ text: rgB, blockLine: true });
  826. }
  827. }
  828. }
  829. rg = null;
  830. }
  831.  
  832. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  833.  
  834. let obj = r;
  835. console.log(7559, 1, obj)
  836. return obj;
  837. }).then(p => {
  838. let obj = _DEBUG_szz(p)
  839. console.log(7559, 2, obj)
  840.  
  841. });
  842. }
  843.  
  844. // -----------------------------------------------------------------------------------------
  845. snCache.clear();
  846. return fRes;
  847.  
  848. }
  849.  
  850.  
  851. return translate
  852.  
  853. }
  854.  
  855.  
  856. let translateFn = null;
  857.  
  858. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  859.  
  860. const wmx = new WeakMap();
  861.  
  862. function fixSegments(ytObj) {
  863. let a, b;
  864. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  865. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  866. translateFn = translateFn || getTranslate();
  867. let cSeg;
  868. cSeg = wmx.get(seg);
  869. if (!cSeg) {
  870. let vSeg = null;
  871. try {
  872. vSeg = translateFn(seg);
  873. } catch (e) {
  874. }
  875. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  876. // console.log('translated', vSeg);
  877. cSeg = vSeg;
  878. wmx.set(seg, cSeg);
  879. wmx.set(cSeg, cSeg);
  880. }
  881. }
  882. if (cSeg && cSeg !== seg) {
  883. a[b] = cSeg;
  884. }
  885. }
  886.  
  887. const dfn = Symbol();
  888. const Object_ = Object;
  889. Object_[dfn] = Object_.defineProperties;
  890. let activation = true;
  891. Object_.defineProperties = function (obj, pds) {
  892. let segments, get_;
  893. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  894. activation = false;
  895. segments.get = function () {
  896. fixSegments(this);
  897. return get_.call(this);
  898. };
  899. }
  900. return Object_[dfn](obj, pds);
  901. };
  902.  
  903. })();
  904.  
  905.  
  906. let pf31 = new PromiseExternal();
  907.  
  908. // native RAF
  909. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  910.  
  911. // 1st wrapped RAF
  912. const baseRAF = (callback) => {
  913. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  914. pf31.then(() => {
  915. callback(hRes);
  916. });
  917. });
  918. };
  919.  
  920. // 2nd wrapped RAF
  921. window.requestAnimationFrame = baseRAF;
  922.  
  923. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  924. const indr = o => insp(o).$ || o.$ || 0;
  925.  
  926. const prototypeInherit = (d, b) => {
  927. const m = Object.getOwnPropertyDescriptors(b);
  928. for (const p in m) {
  929. if (!Object.getOwnPropertyDescriptor(d, p)) {
  930. Object.defineProperty(d, p, m[p]);
  931. }
  932. }
  933. };
  934.  
  935.  
  936. const firstObjectKey = (obj) => {
  937. for (const key in obj) {
  938. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  939. }
  940. return null;
  941. };
  942.  
  943. function searchNestedObject(obj, predicate, maxDepth = 64) {
  944. // normal case: depth until 36
  945. const result = [];
  946. const visited = new WeakSet();
  947.  
  948. function search(obj, depth) {
  949. visited.add(obj);
  950. for (const [key, value] of Object.entries(obj)) {
  951. // Recursively search nested objects and arrays
  952. if (value !== null && typeof value === 'object') {
  953. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  954. if (depth + 1 <= maxDepth && !visited.has(value)) {
  955. search(value, depth + 1);
  956. }
  957. } else if (predicate(value)) {
  958. result.push([obj, key]);
  959. }
  960. }
  961. }
  962.  
  963. typeof (obj || 0) === 'object' && search(obj, 0);
  964. return result;
  965. }
  966.  
  967. /** @type {(o: Object | null) => WeakRef | null} */
  968. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  969.  
  970. /** @type {(wr: Object | null) => Object | null} */
  971. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  972.  
  973. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  974.  
  975. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  976. if (DENY_requestStorageAccess) {
  977. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  978. Document.prototype.requestStorageAccessFor = undefined;
  979. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  980. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  981. Document.prototype.requestStorageAccessFor = function () {
  982. return new Promise((resolve, reject) => {
  983. reject();
  984. });
  985. };
  986. }
  987. }
  988.  
  989. const traceStack = (stack) => {
  990. let result = new Set();
  991. let p = new Set();
  992. let u = ''
  993. for (const s of stack.split('\n')) {
  994. if (s.split(':').length < 3) continue;
  995. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  996. if (!m) continue;
  997. p.add(m[2]);
  998. if (p.size >= 3) break;
  999. if(!u) u = m[2];
  1000. else if(p.size === 2 && u && u=== m[2]) break;
  1001. result.add(s);
  1002. }
  1003. return [...result].join('\n');
  1004. }
  1005.  
  1006. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  1007. // window.m3bb = new Set();
  1008.  
  1009. // const smb = Symbol();
  1010. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  1011. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  1012. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  1013.  
  1014. // const fnProxySelf = function (...args) {
  1015. // if (args[0] === smb) return this;
  1016. // const cnt = kRef(this.ref);
  1017. // if (cnt) {
  1018. // if (typeof cnt[this.prop] !== 'function') console.error(`this.${this.prop} is not a function. [${cnt.is || 'nil'}]`)
  1019. // return cnt[this.prop](...args); // might throw error
  1020. // }
  1021. // }
  1022. // fnProxySelf.bind588 = fnProxySelf.bind;
  1023. // const pFnHandler = {
  1024. // get(target, prop){
  1025. // if(prop === 'bind588') return 2;
  1026. // const fnThis = target(smb);
  1027. // if (fnThis && fnThis.prop && fnThis.ref) {
  1028. // const cnt = kRef(fnThis.ref || null) || null;
  1029. // if (cnt) {
  1030. // const h = cnt[fnThis.prop];
  1031. // const v = h[prop];
  1032. // if (typeof v === 'function'){
  1033. // if(typeof h === 'function'){
  1034. // if (prop === 'call' || prop === 'bind' || prop === 'bind588' || prop === 'bind488' || prop === 'apply') {
  1035. // if(h.bind588 === 1){
  1036. // const g = function(...args){
  1037. // console.log(1288, this)
  1038. // return h.call(this, ...args);
  1039. // };
  1040. // console.log(399, g)
  1041. // return g[prop];
  1042. // // console.log(12778)
  1043. // // console.log(target, target.call)
  1044. // // return target[prop];
  1045. // }
  1046. // // independent of this
  1047. // return v; // function.bind, function.call, function.apply
  1048. // }
  1049. // }
  1050. // console.warn('cnt[fnThis.prop][prop] is function; might rely on this', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
  1051.  
  1052. // // return new Proxy(fnProxySelf.bind588({ prop: prop, ref: new WeakRef(cnt[fnThis.prop]) }), pFnHandler);
  1053. // }
  1054. // return v;
  1055. // }
  1056. // }
  1057. // },
  1058. // set(target, prop, value) {
  1059. // const fnThis = target(smb);
  1060. // if (fnThis && fnThis.prop && fnThis.ref) {
  1061. // const cnt = kRef(fnThis.ref || null) || null;
  1062. // if (cnt) {
  1063. // const h = cnt[fnThis.prop];
  1064. // if (h) {
  1065. // h[prop] = value;
  1066. // } else {
  1067. // console.log('h is nout found', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
  1068. // }
  1069. // }
  1070. // }
  1071. // return true;
  1072. // }
  1073. // };
  1074.  
  1075. const thisConversionFn = (thisArg) => {
  1076. if (!thisArg) return null;
  1077. const kThis = thisArg[vmb];
  1078. if (kThis) {
  1079. const ref = kThis.ref;
  1080. return (ref ? kRef(ref) : null) || null;
  1081. }
  1082. return thisArg;
  1083. }
  1084.  
  1085. const pFnHandler2 = {
  1086. get(target, prop) {
  1087. if (prop === vmc) return target;
  1088. return Reflect.get(target, prop);
  1089. },
  1090. apply(target, thisArg, argumentsList) {
  1091. thisArg = thisConversionFn(thisArg);
  1092. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  1093. }
  1094. }
  1095.  
  1096.  
  1097. const proxySelfHandler = {
  1098. get(target, prop) {
  1099. if(prop === vmb) return target;
  1100. const ref = target.ref;
  1101. const cnt = kRef(ref);
  1102. if (!cnt) return;
  1103. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  1104. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  1105. return cnt[prop][vmd];
  1106. }
  1107. return cnt[prop];
  1108. },
  1109. set(target, prop, value) {
  1110. const cnt = kRef(target.ref);
  1111. if (!cnt) return true;
  1112. if(value && (value[vmc] || value[vmb])){
  1113. cnt[prop] = value[vmc] || thisConversionFn(value);
  1114. return true;
  1115. }
  1116. cnt[prop] = value;
  1117. return true;
  1118. }
  1119. };
  1120.  
  1121. const weakWrap = (thisArg) => {
  1122. thisArg = thisConversionFn(thisArg);
  1123. if (!thisArg) {
  1124. console.error('thisArg is not found');
  1125. return null;
  1126. }
  1127. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  1128. }
  1129.  
  1130. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  1131. window.getComputedStyle533 = window.getComputedStyle;
  1132. window.getComputedStyle = function (a, ...args) {
  1133. a = thisConversionFn(a);
  1134. if (a) {
  1135. return getComputedStyle533(a, ...args);
  1136. }
  1137. return null;
  1138. }
  1139. }
  1140.  
  1141. Function._count_bind_00 = 0;
  1142. // Function._count_bind_01 = 0;
  1143.  
  1144. // let matchNativeCode = (Object+"");
  1145. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1146. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1147.  
  1148. // const matchConstructor = (thisArg) => {
  1149. // const f = `${(thisArg || 0).constructor}`;
  1150. // if (f.length > 45) return true;
  1151. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1152. // if (f.includes('[native code]')){
  1153. // return false;
  1154. // }
  1155. // return true;
  1156. // }
  1157. // return false;
  1158. // }
  1159.  
  1160. // const acceptThis = (thisArg)=>{
  1161. // // if(!thisArg || typeof thisArg !=='object') return false;
  1162. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1163. // // if(typeof thisArg.path === 'string') return true;
  1164. // // if(typeof thisArg.fn === 'function') return true;
  1165. // // if(typeof thisArg.id === 'string') return true;
  1166. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1167. // return false;
  1168. // }
  1169.  
  1170. const patchFn = (fn) => {
  1171.  
  1172. let s = `${fn}`;
  1173. if (s.length < 11 || s.includes('\n')) return false;
  1174. if(s.includes('bind(this')) return true;
  1175. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1176. // var a=this;
  1177. // f.bind(this)
  1178.  
  1179.  
  1180. return false;
  1181. }
  1182.  
  1183. Function.prototype.bind488 = Function.prototype.bind;
  1184. Function.prototype.bind = function(thisArg, ...args){
  1185.  
  1186. if (thisConversionFn(thisArg) !== thisArg) {
  1187. return this.bind488(thisArg, ...args);
  1188. }
  1189. if( thisArg && patchFn(this) ){
  1190.  
  1191. // console.log(599,`${this}`)
  1192.  
  1193. try {
  1194. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1195. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1196. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1197. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1198. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1199. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1200. // // let b4 = false;
  1201. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1202.  
  1203. // // b3 = false;
  1204. // // b4 = false;
  1205. // // b5 = false;
  1206.  
  1207. // if (b1 || b2 || b3 ||b4 ) {
  1208. const f = this;
  1209. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1210. if (ps && ps[vmb]) {
  1211. Function._count_bind_00++;
  1212. return f.bind488(ps, ...args)
  1213. }
  1214. // }
  1215. } catch (e) {
  1216. console.warn(e)
  1217. }
  1218. }
  1219. return this.bind488(thisArg, ...args);
  1220. }
  1221. Function.prototype.bind588 = 1;
  1222. }
  1223.  
  1224.  
  1225. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  1226. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  1227. const wm6 = new WeakMapOriginal();
  1228.  
  1229. const skipW = new WeakSet();
  1230.  
  1231.  
  1232. window.WeakMap = class WeakMap extends WeakMapOriginal {
  1233. constructor(iterable = undefined) {
  1234. super();
  1235. if (iterable && iterable[Symbol.iterator]) {
  1236. for (const entry of iterable) {
  1237. entry && this.set(entry[0], entry[1]);
  1238. }
  1239. }
  1240. }
  1241. delete(a) {
  1242. if (!this.has(a)) return false;
  1243. super.delete(a);
  1244. return true;
  1245. }
  1246. get(a) {
  1247. const p = super.get(a);
  1248. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1249. let v = kRef(p);
  1250. if (!v) {
  1251. super.delete(a);
  1252. }
  1253. return v || undefined;
  1254. }
  1255. return p;
  1256. }
  1257. has(a) {
  1258. if (!super.has(a)) return false;
  1259. const p = super.get(a);
  1260. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1261. if (!kRef(p)) {
  1262. super.delete(a);
  1263. return false;
  1264. }
  1265. }
  1266. return true;
  1267. }
  1268. set(a, b) {
  1269. let wq = b;
  1270. if (b && (typeof b === 'function' || typeof b === 'object')) {
  1271. if (b.deref) {
  1272. skipW.add(b);
  1273. wq = b;
  1274. } else {
  1275. wq = wm6.get(b);
  1276. if (!wq) {
  1277. wq = mWeakRef(b);
  1278. wm6.set(b, wq);
  1279. }
  1280. }
  1281. }
  1282. super.set(a, wq);
  1283. return this;
  1284. }
  1285. }
  1286. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  1287. configurable: true,
  1288. enumerable: false,
  1289. value: "WeakMap",
  1290. writable: false
  1291. });
  1292. }
  1293.  
  1294. const isWatchPageURL = (url) => {
  1295. url = url || location;
  1296. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  1297. };
  1298.  
  1299. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  1300.  
  1301. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  1302. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1303. if (typeof customElements === 'undefined') {
  1304. if (!('__CE_registry' in document)) {
  1305. // https://github.com/webcomponents/polyfills/
  1306. Object.defineProperty(document, '__CE_registry', {
  1307. get() {
  1308. // return undefined
  1309. },
  1310. set(nv) {
  1311. if (typeof nv == 'object') {
  1312. delete this.__CE_registry;
  1313. this.__CE_registry = nv;
  1314. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1315. }
  1316. return true;
  1317. },
  1318. enumerable: false,
  1319. configurable: true
  1320. })
  1321. }
  1322. let eventHandler = (evt) => {
  1323. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1324. const f = callback;
  1325. callback = null;
  1326. eventHandler = null;
  1327. f();
  1328. };
  1329. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1330. } else {
  1331. callback();
  1332. }
  1333. });
  1334.  
  1335. const whenCEDefined = isCustomElementsProvided
  1336. ? (nodeName) => customElements.whenDefined(nodeName)
  1337. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  1338.  
  1339. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  1340. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  1341. const f = performance.now23 = Performance.prototype.now;
  1342.  
  1343. let k = 0; // 0 <= k < 9998m
  1344. let u = 0;
  1345. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  1346.  
  1347. // By definition, performance.now() is mono increasing.
  1348. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  1349. performance.now = performance.now16 = function () {
  1350. /**
  1351. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  1352. *
  1353. * If consecutive session history entries had history.state.entryTime set to same value,
  1354. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  1355. * and modifying its return value slightly to make sure two close consecutive calls don't
  1356. * get the same result helped with resolving the issue.
  1357. */
  1358. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  1359. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  1360.  
  1361. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  1362. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  1363. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  1364. else { // more than 9998 consecutive calls
  1365. /**
  1366. *
  1367. * max no. of consecutive calls
  1368. *
  1369. * Sample Size: 4800
  1370. * Sample Avg = 1565.375
  1371. * Sample Median = 1469.5
  1372. * Sample Max = 5660 << 7500 << 9999
  1373. *
  1374. *
  1375. * */
  1376. k = 0;
  1377. s += 1 / 7;
  1378. }
  1379. return v + k; // 0 < v - M < v - M + k < v
  1380. }
  1381.  
  1382. let loggerMsg = '';
  1383. if (`${performance.now()}` === `${performance.now()}`) {
  1384. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  1385. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  1386. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  1387. }
  1388. loggerMsg && console.warn(loggerMsg);
  1389. })();
  1390.  
  1391. FIX_removeChild && (() => {
  1392. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  1393. Node.prototype.removeChild062 = Node.prototype.removeChild;
  1394. Node.prototype.removeChild = function (child) {
  1395. if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  1396. this.removeChild062(child);
  1397. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  1398. // tooltip bug
  1399. } else {
  1400. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  1401. }
  1402. return child;
  1403. }
  1404. }
  1405. })();
  1406.  
  1407.  
  1408. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  1409.  
  1410. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  1411.  
  1412. // let cid = 0;
  1413.  
  1414. let mousemoveFn = null;
  1415. let mousemoveDT = 0;
  1416. let mousemoveCount = 0;
  1417. // let qv = false;
  1418. const cif = () => {
  1419. if (!mousemoveFn) return;
  1420. const ct = Date.now();
  1421. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  1422. mousemoveFn && mousemoveFn();
  1423. }
  1424. mousemoveFn = null;
  1425. };
  1426. let mousemoveCId = 0;
  1427. let mouseoverFn = null;
  1428. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  1429. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  1430. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  1431. const bt = `${b}`;
  1432. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  1433. b[`__$$${a}$$1926__`] = true;
  1434. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  1435. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  1436. // console.log(3928, a, this[`__$$${a}$$1937__`])
  1437. if (!this[`__$$${a}$$1938__`]) {
  1438. this[`__$$${a}$$1938__`] = b;
  1439. if (a === 'mousemove') {
  1440. this.addEventListener4882('mouseenter', (evt) => {
  1441. if (mousemoveCId) return;
  1442. mousemoveCId = setIntervalX0(cif, 380);
  1443. });
  1444. this.addEventListener4882('mouseleave', (evt) => {
  1445. clearIntervalX0(mousemoveCId);
  1446. mousemoveCId = 0;
  1447. });
  1448. }
  1449. this.addEventListener4882(a, (evt) => {
  1450. const evt_ = evt;
  1451. if (!this[`__$$${a}$$1937__`]) return;
  1452. if (!this[`__$$${a}$$1938__`]) return;
  1453. if (a === 'mousemove') {
  1454. mouseoverFn && mouseoverFn();
  1455. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  1456. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  1457. } else {
  1458. mousemoveCount = 0;
  1459. }
  1460. const f = mousemoveFn = () => {
  1461. if (f !== mousemoveFn) return;
  1462. mousemoveFn = null;
  1463. this[`__$$${a}$$1938__`](evt_);
  1464. };
  1465. if (mousemoveCount <= 1) mousemoveFn();
  1466. } else {
  1467. if (a === 'mouseout' || a === 'mouseleave') {
  1468. mousemoveFn = null;
  1469. mousemoveDT = 0;
  1470. mousemoveCount = 0;
  1471. this[`__$$${a}$$1938__`](evt_);
  1472. mouseoverFn && mouseoverFn();
  1473. } else { // mouseover, mouseenter
  1474. mousemoveFn = null;
  1475. mousemoveDT = 0;
  1476. mousemoveCount = 0;
  1477. mouseoverFn && mouseoverFn(); // just in case
  1478. const f = mouseoverFn = () => {
  1479. if (f !== mouseoverFn) return;
  1480. mouseoverFn = null;
  1481. this[`__$$${a}$$1938__`](evt_);
  1482. }
  1483. nextBrowserTick_(mouseoverFn);
  1484. }
  1485. }
  1486. }, c);
  1487.  
  1488.  
  1489. return;
  1490. } else {
  1491.  
  1492. return;
  1493. }
  1494. }
  1495.  
  1496. }
  1497. return this.addEventListener4882(a, b, c)
  1498. }
  1499.  
  1500.  
  1501.  
  1502.  
  1503. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  1504. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  1505. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  1506.  
  1507. if (b[`__$$${a}$$1926__`]) {
  1508. b[`__$$${a}$$1926__`] = false;
  1509.  
  1510. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  1511.  
  1512. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  1513.  
  1514. return;
  1515.  
  1516. }
  1517.  
  1518. }
  1519. return this.removeEventListener4882(a, b, c)
  1520. }
  1521.  
  1522.  
  1523. })();
  1524.  
  1525.  
  1526. FIX_DOM_IF_REPEAT && (() => {
  1527. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  1528. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  1529. // Be careful of the mixture of polymer functions and native Element functions
  1530. // Be careful of the coding design is different with the modern Yt elements
  1531.  
  1532.  
  1533. /*
  1534.  
  1535.  
  1536. function Ks(a, b, c) {
  1537. if (kj && !BOa(a))
  1538. throw Error("strictTemplatePolicy: template owner not trusted");
  1539. c = c || {};
  1540. if (a.__templatizeOwner)
  1541. throw Error("A <template> can only be templatized once");
  1542. a.__templatizeOwner = b;
  1543. var d = (b ? b.constructor : Js)._parseTemplate(a)
  1544. , e = d.templatizeInstanceClass;
  1545. e || (e = COa(a, d, c),
  1546. d.templatizeInstanceClass = e);
  1547. var g = BOa(a);
  1548. EOa(a, d, c, g);
  1549. c = function() {
  1550. return e.apply(this, arguments) || this
  1551. }
  1552. ;
  1553. h(c, e);
  1554. c.prototype._methodHost = g;
  1555. c.prototype.__dataHost = a;
  1556. c.prototype.__templatizeOwner = b;
  1557. c.prototype.__hostProps = d.hostProps;
  1558. return c
  1559. }
  1560.  
  1561. */
  1562.  
  1563. // Polymer.enqueueDebouncer
  1564.  
  1565. const s81 = Symbol();
  1566. const s83 = Symbol();
  1567. const s84 = Symbol();
  1568. const s85 = Symbol();
  1569. const s85b = Symbol();
  1570. const s85c = Symbol();
  1571.  
  1572. let renderDebounceTs = null;
  1573.  
  1574. let renderDebouncePromise = null;
  1575. let qp;
  1576.  
  1577. let cme = 0;
  1578.  
  1579. const shadyFlushMO = new MutationObserver(() => {
  1580.  
  1581. if (!renderDebounceTs) return;
  1582.  
  1583. if (renderDebounceTs.size > 0) {
  1584. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  1585. try {
  1586. Polymer.flush();
  1587. return;
  1588. } catch (e) { }
  1589. }
  1590.  
  1591. renderDebouncePromise && Promise.resolve().then(() => {
  1592.  
  1593. if (renderDebouncePromise) {
  1594. renderDebouncePromise && renderDebouncePromise.resolve();
  1595. renderDebouncePromise = null;
  1596. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  1597. }
  1598.  
  1599. });
  1600.  
  1601. // Polymer.flush
  1602.  
  1603. window.ShadyDOM && ShadyDOM.flush();
  1604. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  1605.  
  1606.  
  1607. });
  1608.  
  1609. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  1610.  
  1611. const observablePromise = (proc, timeoutPromise) => {
  1612. let promise = null;
  1613. return {
  1614. obtain() {
  1615. if (!promise) {
  1616. promise = new Promise(resolve => {
  1617. let mo = null;
  1618. const f = () => {
  1619. let t = proc();
  1620. if (t) {
  1621. mo.disconnect();
  1622. mo.takeRecords();
  1623. mo = null;
  1624. resolve(t);
  1625. }
  1626. }
  1627. mo = new MutationObserver(f);
  1628. mo.observe(document, { subtree: true, childList: true })
  1629. f();
  1630. timeoutPromise && timeoutPromise.then(() => {
  1631. resolve(null)
  1632. });
  1633. });
  1634. }
  1635. return promise
  1636. }
  1637. }
  1638. }
  1639.  
  1640.  
  1641. let p = 0;
  1642. qp = observablePromise(() => {
  1643. if (!(p & 1)) {
  1644.  
  1645. if (window.ShadyDOM && ShadyDOM.flush) {
  1646. p |= 1;
  1647. if (!ShadyDOM.flush847) {
  1648.  
  1649. ShadyDOM.flush847 = ShadyDOM.flush;
  1650. ShadyDOM.flush = function () {
  1651.  
  1652. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  1653. renderDebouncePromise && Promise.resolve().then(() => {
  1654. if (renderDebouncePromise) {
  1655.  
  1656. renderDebouncePromise && renderDebouncePromise.resolve();
  1657. renderDebouncePromise = null;
  1658.  
  1659. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  1660.  
  1661. }
  1662.  
  1663. });
  1664. let r = this.flush847(...arguments);
  1665. if (r) {
  1666. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1667. }
  1668. return r
  1669. }
  1670.  
  1671. }
  1672. }
  1673. }
  1674.  
  1675. if (!(p & 2)) {
  1676.  
  1677. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  1678. p |= 2;
  1679. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  1680. if (!ScopingShim.flush848) {
  1681.  
  1682. ScopingShim.flush848 = ScopingShim.flush;
  1683. ScopingShim.flush = function () {
  1684.  
  1685. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  1686.  
  1687. renderDebouncePromise && Promise.resolve().then(() => {
  1688.  
  1689. if (renderDebouncePromise) {
  1690.  
  1691. renderDebouncePromise && renderDebouncePromise.resolve();
  1692. renderDebouncePromise = null;
  1693.  
  1694. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  1695.  
  1696.  
  1697.  
  1698. }
  1699.  
  1700. });
  1701. return this.flush848(...arguments);
  1702. }
  1703.  
  1704. }
  1705. }
  1706. }
  1707. if (p === 3) {
  1708. p |= 8;
  1709.  
  1710. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  1711. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  1712. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  1713.  
  1714. if (r) {
  1715. let w = Set.prototype.add;
  1716. let u = null;
  1717. Set.prototype.add = function () {
  1718. u = this;
  1719. throw new Error();
  1720. }
  1721. try {
  1722. Polymer.enqueueDebouncer()
  1723. } catch (e) { }
  1724. Set.prototype.add = w;
  1725. if (u !== null) {
  1726. renderDebounceTs = u;
  1727. if (DEBUG_renderDebounceTs) {
  1728. renderDebounceTs.add58438 = renderDebounceTs.add;
  1729. renderDebounceTs.add = function () {
  1730. console.log('renderDebounceTs.add')
  1731. console.log(traceStack((new Error()).stack))
  1732. // debugger;
  1733. return this.add58438(...arguments)
  1734. }
  1735.  
  1736. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  1737. renderDebounceTs.delete = function () {
  1738. console.log('renderDebounceTs.delete')
  1739. const stack = `${(new Error()).stack}`
  1740. let isCallbackRemoval = false;
  1741. if (stack) {
  1742. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  1743. const s = t.split(':');
  1744. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  1745. isCallbackRemoval = true;
  1746. }
  1747. }
  1748. if (isCallbackRemoval) {
  1749. return this.delete58438(...arguments)
  1750. }
  1751. console.log(traceStack((new Error()).stack))
  1752. // debugger;
  1753. return this.delete58438(...arguments)
  1754. }
  1755. }
  1756. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  1757. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  1758. }
  1759. }
  1760.  
  1761. return true;
  1762. }
  1763. })
  1764.  
  1765. // if(window.ShadyDOM && ShadyDOM.flush){
  1766. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  1767.  
  1768. // }
  1769. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  1770.  
  1771. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  1772. // }
  1773.  
  1774. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  1775.  
  1776. }
  1777.  
  1778. Object.defineProperty(Object.prototype, '_lastIf', {
  1779. get() {
  1780. return this[s81];
  1781. },
  1782. set(nv) {
  1783. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  1784. // DOM-IF initialization
  1785. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  1786.  
  1787. this.__xiWB8__ = 2;
  1788.  
  1789. const cProto = this.__proto__;
  1790. if (cProto && !cProto.__xiWB7__) {
  1791. cProto.__xiWB7__ = 1;
  1792.  
  1793. // dom-if __template
  1794. // dom-repeat template
  1795. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  1796. cProto.__template847 = true;
  1797. try {
  1798. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  1799. Object.defineProperty(cProto, '__template', {
  1800. get() {
  1801. const v = this[s84];
  1802. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  1803. },
  1804. set(nv) {
  1805. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  1806. this[s84] = nv;
  1807. return true;
  1808. }
  1809. });
  1810. } catch (e) {
  1811. console.warn(e);
  1812. }
  1813.  
  1814. console.log('FIX_DOM_IF - __template')
  1815. }
  1816.  
  1817. // dom-if __ensureTemplate
  1818. // dom-repeat __ensureTemplatized
  1819. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  1820. // note that "_templateInfo" diffs the different version of DOM-IF
  1821.  
  1822. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  1823. cProto.__ensureTemplate = function () {
  1824. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  1825. if (!this.__template) {
  1826. let b;
  1827. if (this._templateInfo) {
  1828. b = this;
  1829. } else {
  1830. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  1831. b = this.__templateCollection011__[0];
  1832. if (!b) {
  1833. let a = mWeakRef(this);
  1834. let c = new MutationObserver(function () {
  1835. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  1836. if (c && a) {
  1837. c.disconnect();
  1838. a = kRef(a);
  1839. a && a.__render();
  1840. a && (a.__templateCollection011__ = null);
  1841. }
  1842. c = null;
  1843. a = null;
  1844. });
  1845. c && c.observe(this, {
  1846. childList: !0
  1847. });
  1848. return !1
  1849. } else {
  1850. this.__templateCollection011__ = null;
  1851. }
  1852. }
  1853. this.__template = b
  1854. }
  1855. return !0
  1856. }
  1857.  
  1858. console.log('FIX_DOM_IF - __ensureTemplate')
  1859.  
  1860. }
  1861.  
  1862.  
  1863. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  1864.  
  1865. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  1866.  
  1867. // cProto.__createAndInsertInstance = function (a) {
  1868. // Promise.resolve().then(()=>{
  1869. // console.log('__createAndInsertInstance')
  1870. // window.lm5 = window.lm5 || [];
  1871. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  1872. // });
  1873. // return this.__createAndInsertInstance847(a);
  1874. // }
  1875.  
  1876. // }
  1877.  
  1878.  
  1879. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  1880.  
  1881. // cProto._bindTemplate847 = cProto._bindTemplate;
  1882.  
  1883. // cProto._bindTemplate = function (a, b) {
  1884. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  1885. // }
  1886.  
  1887. // }
  1888. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  1889.  
  1890. // cProto._stampTemplate847 = cProto._stampTemplate;
  1891.  
  1892. // cProto._stampTemplate = function (a, b) {
  1893. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  1894. // }
  1895.  
  1896. // }
  1897. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  1898. }
  1899.  
  1900.  
  1901. // need to fix __observeEffects
  1902. // this.__observeEffects.if[0].info.method === this.__debounceRender
  1903. const f = () => {
  1904.  
  1905. const __observeEffects = this.__observeEffects;
  1906.  
  1907. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  1908. for (const effect of __observeEffects.if) {
  1909. const info = effect.info;
  1910. if (info && typeof info.method === 'function') {
  1911.  
  1912. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  1913. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  1914. }
  1915.  
  1916. }
  1917. }
  1918. }
  1919.  
  1920.  
  1921. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  1922. for (const effect of __observeEffects.restamp) {
  1923. const info = effect.info;
  1924. if (info && typeof info.method === 'function') {
  1925.  
  1926. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  1927. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  1928. }
  1929.  
  1930. }
  1931. }
  1932. }
  1933.  
  1934. // console.log(5881, this.__observeEffects)
  1935. }
  1936. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  1937. f();
  1938. Promise.resolve().then(f);
  1939. // afterward, don't care adding fn directly (the fn is already modified)
  1940. }
  1941.  
  1942. }
  1943. this[s81] = nv;
  1944. return true;
  1945. }
  1946. });
  1947.  
  1948.  
  1949. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  1950. get() {
  1951. return this[s85];
  1952. },
  1953. set(nv) {
  1954. if (nv === null && this[s85] === undefined) {
  1955. // DOM-IF / DOM-REPEAT initialization
  1956.  
  1957.  
  1958. const cProto = this.__proto__;
  1959. if (qp) {
  1960. qp.obtain();
  1961. qp = null;
  1962. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  1963. }
  1964. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  1965.  
  1966. cProto.__debounceRender847 = cProto.__debounceRender;
  1967.  
  1968. if (cProto.__debounceRender.length === 2) {
  1969.  
  1970. cProto.__debounceRender = function (a, b) {
  1971.  
  1972. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  1973.  
  1974. b = b === void 0 ? 0 : b;
  1975.  
  1976. /*
  1977. b = b === void 0 ? 0 : b;
  1978. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  1979. vs(this.__renderDebouncer)
  1980. */
  1981.  
  1982. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1983.  
  1984. if (!renderDebouncePromise) {
  1985. renderDebouncePromise = new PromiseExternal();
  1986. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1987. }
  1988.  
  1989. renderDebouncePromise.then(async () => {
  1990. if (b > 0) await delayPn(b);
  1991.  
  1992. const f = this.__dsIRYqw1__;
  1993. if (f === cme) return;
  1994. this.__dsIRYqw1__ = cme;
  1995. a.call(this);
  1996. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  1997.  
  1998. });
  1999.  
  2000. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  2001. }
  2002.  
  2003. } else if (cProto.__debounceRender.length === 0) {
  2004.  
  2005.  
  2006. cProto.__debounceRender = function () {
  2007.  
  2008. if (!renderDebounceTs) return this.__debounceRender847();
  2009.  
  2010. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2011. /*
  2012. var a = this;
  2013. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  2014. return a.__render()
  2015. });
  2016. vs(this.__renderDebouncer)
  2017. */
  2018.  
  2019. if (!renderDebouncePromise) {
  2020. renderDebouncePromise = new PromiseExternal();
  2021. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2022. }
  2023. renderDebouncePromise.then(() => {
  2024. const f = this.__dsIRYqw1__;
  2025. if (f === cme) return;
  2026. this.__dsIRYqw1__ = cme;
  2027. this.__render()
  2028. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  2029. });
  2030. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  2031.  
  2032.  
  2033. }
  2034. }
  2035. }
  2036.  
  2037.  
  2038.  
  2039. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  2040. // cProto.render847 = cProto.render;
  2041. // cProto.render = function(){
  2042.  
  2043. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2044. // try{
  2045. // this.render847();
  2046. // }catch(e){}
  2047. // // if(this.__DBR847__){
  2048. // // this.__DBR847__.resolve();
  2049. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  2050. // // }
  2051.  
  2052. // // renderDebouncePromise && renderDebouncePromise.resolve()
  2053. // // renderDebouncePromise = null;
  2054. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  2055.  
  2056. // }
  2057. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  2058. // }
  2059.  
  2060. }
  2061. this[s85] = nv;
  2062. return true;
  2063. }
  2064. });
  2065.  
  2066. // PS-DOM-REPEAT
  2067.  
  2068. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  2069. get() {
  2070. return this[s85b];
  2071. },
  2072. set(nv) {
  2073.  
  2074. this[s85b] = nv;
  2075. return true;
  2076. }
  2077. })
  2078.  
  2079. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  2080. get() {
  2081. return this[s85c];
  2082. },
  2083. set(nv) {
  2084.  
  2085. this[s85c] = nv;
  2086. return true;
  2087. }
  2088. })
  2089.  
  2090.  
  2091. })();
  2092.  
  2093. const setupXdeadC = (cnt)=>{
  2094.  
  2095. let xdeadc = xdeadc00;
  2096. if(!xdeadc){
  2097. setupSDomWrapper(); // just in case
  2098. const hostElement = cnt.hostElement;
  2099. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2100. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2101. hostElement.lastChild.replaceWith(el);
  2102. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2103. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2104. el.firstElementChild.id = rid;
  2105. cnt.$[rid] = el.firstElementChild;
  2106. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2107.  
  2108. xdeadc = cnt.getStampContainer_(rid);
  2109. el.remove();
  2110. xdeadc00 = xdeadc;
  2111. // console.log(xdeadc.__domApi)
  2112. // debugger;
  2113. // const xdeadv = xdeadc.__domApi;
  2114. }
  2115.  
  2116. let xlivec = xlivec00;
  2117. if(!xlivec){
  2118. setupSDomWrapper(); // just in case
  2119. const hostElement = cnt.hostElement;
  2120. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2121. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2122. hostElement.lastChild.replaceWith(el);
  2123. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2124. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2125. el.firstElementChild.id = rid;
  2126. cnt.$[rid] = el.firstElementChild;
  2127. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2128.  
  2129. xlivec = cnt.getStampContainer_(rid);
  2130. xlivec00 = xlivec;
  2131. // console.log(xdeadc.__domApi)
  2132. // debugger;
  2133. // const xdeadv = xdeadc.__domApi;
  2134. }
  2135.  
  2136. return xdeadc00;
  2137. }
  2138.  
  2139. let standardWrap_ = null;
  2140.  
  2141. const setupSDomWrapper = () => {
  2142.  
  2143. const sdwProto = ShadyDOM.Wrapper.prototype;
  2144.  
  2145. if (sdwProto.__pseudo__isConnected__ !== null) {
  2146. sdwProto.__pseudo__isConnected__ = null;
  2147. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  2148. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  2149. const get = isConnectedPd.get;
  2150. isConnectedPd.get = function () {
  2151. const pseudoVal = this.__pseudo__isConnected__;
  2152. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  2153. }
  2154. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  2155. }
  2156.  
  2157.  
  2158.  
  2159. // if (!sdwProto.__nodeMove__) {
  2160.  
  2161. // sdwProto.__nodeMove__ = function (dest) {
  2162.  
  2163.  
  2164. // }
  2165.  
  2166.  
  2167. // }
  2168.  
  2169.  
  2170.  
  2171.  
  2172. // debugger;
  2173. // new xdeadc.__domApi.constructor(document.createElement('div'));
  2174. }
  2175.  
  2176. }
  2177. const setupDomApi = (daProto) => {
  2178.  
  2179. daProto.__daHook377__ = true;
  2180.  
  2181.  
  2182.  
  2183. }
  2184.  
  2185.  
  2186. // WEAKREF_ShadyDOM
  2187.  
  2188. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  2189.  
  2190. const setupPlainShadyDOM = (b) => {
  2191. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  2192. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  2193. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  2194. b.patchOnDemand = true;
  2195. b.preferPerformance = true;
  2196. b.noPatch = true;
  2197. }
  2198.  
  2199. const isPlainObject = (b, m) => {
  2200. if (!b || typeof b !== 'object') return false;
  2201. const e = Object.getOwnPropertyDescriptors(b);
  2202. if (e.length <= m) return false;
  2203. let pr = 0;
  2204. for (const k in e) {
  2205. const d = e[k];
  2206. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  2207. if (!('value' in d) || typeof d.value === 'function') return false;
  2208. pr++;
  2209. }
  2210. return pr > m;
  2211. }
  2212.  
  2213. let b;
  2214.  
  2215. let lz = 0;
  2216.  
  2217. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  2218. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  2219.  
  2220. // Brave - ShadyDOM exists before userscripting
  2221. b = sdp.value;
  2222.  
  2223. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  2224. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  2225. lz = 1;
  2226. }
  2227.  
  2228. }
  2229.  
  2230.  
  2231. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  2232. } else if (!sdp) {
  2233. } else {
  2234. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  2235. return;
  2236. }
  2237.  
  2238. const shadyDOMNodeWRM = new WeakMap();
  2239.  
  2240. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  2241.  
  2242. const selfWrKey = Symbol();
  2243.  
  2244. const mak = new Map();
  2245. const emm = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2246.  
  2247. const weakWrapperNodeHandlerFn = () => ({
  2248. get() {
  2249. const wv = this[selfWrKey];
  2250. if (typeof wv === 'undefined') return undefined;
  2251. let node = kRef(wv);
  2252. if (!node) this[selfWrKey] = undefined;
  2253.  
  2254. // if(node && node.__shady_shadowRoot instanceof DocumentFragment_ && !node.__shady_shadowRoot.d32 ){
  2255. // node.__shady_shadowRoot.d32 = 1;
  2256. // const c = node.__shady_shadowRoot;
  2257. // if(mak.has(node.nodeName)){
  2258. // const r = mak.get(node.nodeName);
  2259. // if(r !== c){
  2260. // let t;
  2261. // while(t = c.firstChild) c.removeChild(t);
  2262. // node.__shady_shadowRoot = mak.get(node.nodeName);
  2263. // console.log('123234534')
  2264. // }
  2265. // }else{
  2266. // mak.set(node.nodeName, c);
  2267. // }
  2268.  
  2269. // }
  2270.  
  2271. return node || undefined;
  2272. // let w = shadyDOMNodeWRM.get(this);
  2273. // if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
  2274. // return w;
  2275. },
  2276. set(nv) {
  2277. const wv = (nv[selfWrKey] || (nv[selfWrKey] = mWeakRef(nv)));
  2278. this[selfWrKey] = wv;
  2279. return true;
  2280. },
  2281. enumerable: true,
  2282. configurable: true
  2283. });
  2284.  
  2285. /*
  2286. const weakWrapperNodeHandlerFn = () => ({
  2287. get() {
  2288. let w = shadyDOMNodeWRM.get(this);
  2289. if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
  2290. return w;
  2291. },
  2292. set(nv) {
  2293. const wv = (nv[selfWrKey] || (nv[selfWrKey] = mWeakRef(nv)));
  2294. shadyDOMNodeWRM.set(this, wv);
  2295. return true;
  2296. },
  2297. enumerable: true,
  2298. configurable: true
  2299. });
  2300. */
  2301.  
  2302. function weakWrapper(_ShadyDOM) {
  2303. const ShadyDOM = _ShadyDOM;
  2304. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  2305. let nullElement = { node: null };
  2306. Object.setPrototypeOf(nullElement, Element.prototype);
  2307. let p = new ShadyDOM.Wrapper(nullElement);
  2308. let d = Object.getOwnPropertyDescriptor(p, 'node');
  2309. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  2310. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  2311. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  2312. }
  2313. // Object.defineProperty(ShadyDOM.Wrapper.prototype, '__cleanup__', function(){
  2314. // // to be reviewed
  2315. // debugger;
  2316.  
  2317.  
  2318.  
  2319.  
  2320. // });
  2321.  
  2322.  
  2323. }
  2324. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  2325. try {
  2326. setupSDomWrapper();
  2327. } catch (e) { }
  2328. }
  2329.  
  2330. }
  2331.  
  2332. let previousWrapStore = null;
  2333.  
  2334. const standardWrap = function (a) {
  2335. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  2336. if (previousWrapStore) {
  2337. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  2338. if (s) {
  2339. previousWrapStore.delete(a);
  2340. shadyDOMNodeWRM.set(a, mWeakRef(s));
  2341. }
  2342. }
  2343. let u = kRef(shadyDOMNodeWRM.get(a));
  2344. if (!u) {
  2345. u = new ShadyDOM.Wrapper(a);
  2346. shadyDOMNodeWRM.set(a, mWeakRef(u));
  2347. }
  2348. return u;
  2349. }
  2350.  
  2351. standardWrap_ = standardWrap;
  2352.  
  2353.  
  2354. function setupWrapFunc(_ShadyDOM) {
  2355. const ShadyDOM = _ShadyDOM;
  2356.  
  2357.  
  2358. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  2359. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  2360. return;
  2361. }
  2362. let mm = new Set();
  2363. const pget = wmPD.value;
  2364. WeakMap.prototype.get = function (a) {
  2365. mm.add(this);
  2366. return a;
  2367. }
  2368. try {
  2369. let nullElement = { node: null };
  2370. Object.setPrototypeOf(nullElement, Element.prototype);
  2371. ShadyDOM.wrapIfNeeded(nullElement)
  2372. ShadyDOM.wrap(nullElement)
  2373. } catch (e) { }
  2374. WeakMap.prototype.get = pget;
  2375. if (mm.size !== 1) {
  2376. mm.clear();
  2377. return;
  2378. }
  2379. const p = mm.values().next().value;
  2380. if (!(p instanceof WeakMap)) return;
  2381. // p.clear();
  2382. // p.get = function (a) { return a }
  2383. // p.set = function (a, b) { return this }
  2384. // console.log(188, window.n2n = mm, window.n2p = p)
  2385.  
  2386. // console.log(34929,p.size)
  2387. previousWrapStore = p;
  2388.  
  2389. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  2390. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  2391. }
  2392. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  2393. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  2394. }
  2395.  
  2396. }
  2397.  
  2398. function setupLZ3(nv) {
  2399.  
  2400. const ShadyDOM = nv;
  2401.  
  2402. const ShadyDOMSettings = ShadyDOM.settings;
  2403. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2404. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2405. return false;
  2406. }
  2407.  
  2408. weakWrapper(ShadyDOM);
  2409.  
  2410. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  2411.  
  2412. setupPlainShadyDOM(ShadyDOMSettings);
  2413. setupPlainShadyDOM(ShadyDOM);
  2414.  
  2415. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  2416.  
  2417. setupWrapFunc(ShadyDOM);
  2418. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  2419. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  2420.  
  2421. // To be confirmed
  2422. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  2423. ShadyDOM.composedPath = function (e) {
  2424. const t = (e || 0).target || null;
  2425. if (!(t instanceof HTMLElement_)) {
  2426. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  2427. }
  2428. return t instanceof HTMLElement_ ? [t] : [];
  2429. };
  2430. }
  2431.  
  2432. }
  2433.  
  2434. }
  2435.  
  2436.  
  2437. function setupLZ6(nv) {
  2438.  
  2439. const ShadyDOM = nv;
  2440.  
  2441. const ShadyDOMSettings = ShadyDOM.settings;
  2442.  
  2443. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2444. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2445. return false;
  2446. }
  2447.  
  2448. weakWrapper(ShadyDOM);
  2449.  
  2450. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  2451.  
  2452. setupPlainShadyDOM(ShadyDOMSettings);
  2453. setupPlainShadyDOM(ShadyDOM);
  2454.  
  2455. setupWrapFunc(ShadyDOM);
  2456.  
  2457. }
  2458.  
  2459. }
  2460.  
  2461. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  2462.  
  2463. const nv = b;
  2464.  
  2465. if (setupLZ6(nv) === false) return;
  2466.  
  2467. lz = 6;
  2468.  
  2469. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  2470.  
  2471. return;
  2472. }
  2473.  
  2474. delete window.ShadyDOM;
  2475.  
  2476. Object.defineProperty(window, 'ShadyDOM', {
  2477. get() {
  2478. return b;
  2479. },
  2480. set(nv) {
  2481. let ret = 0;
  2482. try {
  2483. do {
  2484. if (!nv || !nv.settings) {
  2485. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  2486. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  2487. lz = 1;
  2488. break;
  2489. } else {
  2490. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  2491. break;
  2492. }
  2493. }
  2494.  
  2495. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  2496. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  2497. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  2498. break;
  2499. }
  2500.  
  2501. if (setupLZ3(nv) === false) break;
  2502.  
  2503. lz = 3;
  2504.  
  2505. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  2506.  
  2507. ret = 1;
  2508.  
  2509. } while (0);
  2510. } catch (e) {
  2511. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  2512. }
  2513.  
  2514. if (!ret) b = nv;
  2515. else {
  2516. delete this.ShadyDOM;
  2517. this.ShadyDOM = nv;
  2518. }
  2519. return true;
  2520. },
  2521. enumerable: false,
  2522. configurable: true
  2523. });
  2524.  
  2525. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  2526.  
  2527. if (ENABLE_ASYNC_DISPATCHEVENT) {
  2528. const filter = new Set([
  2529. 'yt-action',
  2530. // 'iframe-src-replaced',
  2531. 'shown-items-changed',
  2532. 'can-show-more-changed', 'collapsed-changed',
  2533.  
  2534. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  2535. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  2536. 'yt-navigate-finish',
  2537.  
  2538. // 'data-changed','yt-watch-comments-ready'
  2539. ])
  2540. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  2541. EventTarget.prototype.dispatchEvent = function (event) {
  2542. const type = (event || 0).type;
  2543. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  2544. if (!filter.has(type) && !type.endsWith('-changed')) {
  2545. if (this instanceof Node || this instanceof Window) {
  2546. nextBrowserTick_(() => this.dispatchEvent938(event));
  2547. return true;
  2548. }
  2549. }
  2550. }
  2551. return this.dispatchEvent938(event);
  2552. }
  2553. }
  2554.  
  2555. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  2556. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  2557. // const xhr = new XMLHttpRequest;
  2558. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  2559. if (!pdOri || pdOri.configurable !== true) return;
  2560. let propNeedles = null;
  2561. const pdNew = {
  2562. configurable: true,
  2563. enumerable: true,
  2564. get: function () {
  2565. propNeedles = this;
  2566. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  2567. throw new Error();
  2568. }
  2569. }
  2570. Object.defineProperty(Map.prototype, 'size', pdNew);
  2571. try {
  2572. XMLHttpRequest.prototype.open.call(0);
  2573. // xhr.open.call(null)
  2574. } catch (e) { }
  2575. Object.defineProperty(Map.prototype, 'size', pdOri);
  2576. if (!propNeedles) return;
  2577. const entries = [...propNeedles.entries()];
  2578. propNeedles.clear();
  2579. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  2580. })();
  2581.  
  2582. if (FIX_XHR_REQUESTING) {
  2583.  
  2584. const URL = window.URL || new Function('return URL')();
  2585. const createObjectURL = URL.createObjectURL.bind(URL);
  2586.  
  2587. XMLHttpRequest = (() => {
  2588. const XMLHttpRequest_ = XMLHttpRequest;
  2589. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  2590. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  2591. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  2592. constructor(...args) {
  2593. super(...args);
  2594. }
  2595. open(method, url, ...args) {
  2596. let skip = false;
  2597. if (!url || typeof url !== 'string') skip = true;
  2598. else if (typeof url === 'string') {
  2599. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  2600. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  2601. skip = true;
  2602. } else if (turl.includes('.youtube.com/pagead/')) {
  2603. skip = true;
  2604. } else if (turl.includes('.youtube.com/ptracking')) {
  2605. skip = true;
  2606. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  2607. skip = true;
  2608. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  2609. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  2610. skip = true;
  2611. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  2612. skip = true;
  2613. } else {
  2614. // skip = true; // for user activity logging e.g. watched videos
  2615. }
  2616. } else if (turl.includes('play.google.com/log')) {
  2617. skip = true;
  2618. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  2619. skip = true;
  2620. }
  2621. }
  2622. if (!skip) {
  2623. this.__xmMc8__ = 1;
  2624. return super.open(method, url, ...args);
  2625. } else {
  2626. this.__xmMc8__ = 2;
  2627. return super.open('GET', url0);
  2628. }
  2629. }
  2630. send(...args) {
  2631. if (this.__xmMc8__ === 1) {
  2632. return super.send(...args);
  2633. } else if (this.__xmMc8__ === 2) {
  2634. return super.send();
  2635. } else {
  2636. console.log('[yt-js-engine-tamer]', 'xhr warning');
  2637. return super.send(...args);
  2638. }
  2639. }
  2640. }
  2641. c.prototype.__xmMc8__ = 0;
  2642. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  2643. return c;
  2644. })();
  2645. }
  2646.  
  2647. // Alternative HACK -> Tabview Youtube
  2648. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  2649.  
  2650. // ---- << this.overscrollConfig HACK >> -----
  2651.  
  2652. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  2653.  
  2654. /*
  2655.  
  2656. ;function gZb(a, b) {
  2657. b = void 0 === b ? !0 : b;
  2658. a.addEventListener("wheel", hZb);
  2659. a.overscrollConfig = {
  2660. cooldown: b
  2661. }
  2662. }
  2663. function iZb(a) {
  2664. a.overscrollConfig = void 0;
  2665. a.removeEventListener("wheel", hZb)
  2666. }
  2667. function hZb(a) {
  2668. var b = a.deltaY
  2669. , c = a.target
  2670. , d = null;
  2671. if (window.Polymer && window.Polymer.Element) {
  2672. if (c = a.path || a.composedPath && a.composedPath()) {
  2673. c = g(c);
  2674. for (var e = c.next(); !e.done && (e = e.value,
  2675. !jZb(e, b)); e = c.next())
  2676. if (e.overscrollConfig) {
  2677. d = e;
  2678. break
  2679. }
  2680. }
  2681. } else
  2682. for (; c && !jZb(c, b); ) {
  2683. if (c.overscrollConfig) {
  2684. d = c;
  2685. break
  2686. }
  2687. c = c.parentElement
  2688. }
  2689. d && (b = d.overscrollConfig,
  2690. b.cooldown ? (d = a.deltaY,
  2691. c = b.lastDeltaY || 0,
  2692. b.lastDeltaY = d,
  2693. e = b.lastStopped || 0,
  2694. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  2695. c = !1) : (d = e + 600,
  2696. c = !0) : (d = Date.now() + 600,
  2697. c = !0),
  2698. d > Date.now() && (a.preventDefault(),
  2699. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  2700. }
  2701. */
  2702.  
  2703. let wheelHandler = function (a) {
  2704. if (window.Polymer && window.Polymer.Element) {
  2705. let c;
  2706. if (c = a.path || a.composedPath && a.composedPath()) {
  2707. for (const e of c) {
  2708. const cnt = insp(e);
  2709. if (e.overscrollConfig) e.overscrollConfig = void 0;
  2710. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  2711. }
  2712. }
  2713. } else {
  2714. let e = a.target;
  2715. for (; e instanceof Element; e = e.parentElement) {
  2716. const cnt = insp(e);
  2717. if (e.overscrollConfig) e.overscrollConfig = void 0;
  2718. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  2719. }
  2720. }
  2721. };
  2722.  
  2723. let checkWheelListenerObjs = null;
  2724.  
  2725. let getObjsFn = () => {
  2726. let euyVal = 0;
  2727. const eukElm = {};
  2728. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  2729. const euzObj = new Proxy(eukElm, {
  2730. get(target, prop) {
  2731. throw `ErrorF31.get(${prop})`
  2732. },
  2733. set(target, prop, value) {
  2734. throw `ErrorF33.set(${prop}, ${value})`
  2735. }
  2736. });
  2737. const euxElm = new Proxy(eukElm, {
  2738. get(target, prop) {
  2739. if (prop === 'scrollTop') {
  2740. euyVal = euyVal | 8;
  2741. return 0;
  2742. }
  2743. if (prop === 'overscrollConfig') {
  2744. euyVal = euyVal | 16;
  2745. return void 0;
  2746. }
  2747. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  2748. return 640;
  2749. }
  2750. if (prop === 'scrollLeft') {
  2751. euyVal = euyVal | 8;
  2752. return 0;
  2753. }
  2754. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  2755. return 800;
  2756. }
  2757. throw `ErrorF45.get(${prop})`
  2758. },
  2759. set(target, prop, value) {
  2760. throw `ErrorF47.set(${prop}, ${value})`
  2761. }
  2762. });
  2763. const eukEvt = {};
  2764. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  2765. const euyEvt = new Proxy(eukEvt, {
  2766. get(target, prop) {
  2767. if (prop === 'deltaY' || prop === 'deltaX') {
  2768. euyVal = euyVal | 1;
  2769. return -999;
  2770. }
  2771. if (prop === 'target') {
  2772. euyVal = euyVal | 2;
  2773. return euxElm
  2774. }
  2775. if (prop === 'path' || prop === 'composedPath') {
  2776. euyVal = euyVal | 2;
  2777. return [euxElm]
  2778. }
  2779. throw `ErrorF51.get(${prop})`
  2780. },
  2781. set(target, prop, value) {
  2782. throw `ErrorF53.set(${prop}, ${value})`
  2783. }
  2784. });
  2785. const setVal = (v) => {
  2786. euyVal = v;
  2787. }
  2788. const getVal = () => {
  2789. return euyVal;
  2790. }
  2791. return { euzObj, euyEvt, setVal, getVal };
  2792. }
  2793.  
  2794. let checkWheelListener = (callback) => {
  2795.  
  2796. let callbackIdentifier = '';
  2797.  
  2798. let res = null;
  2799. try {
  2800. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  2801. setVal(0);
  2802. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  2803. throw `RESULT${getVal()}`;
  2804. } catch (e) {
  2805. res = e;
  2806. }
  2807.  
  2808. res = `${res}` || `${null}`;
  2809. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  2810.  
  2811. callbackIdentifier = res;
  2812. if (callbackIdentifier === 'RESULT27') 0;
  2813. else if (callbackIdentifier === 'RESULT0') {
  2814. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  2815. } else if (callbackIdentifier.startsWith('RESULT')) {
  2816. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  2817. }
  2818. return callbackIdentifier;
  2819.  
  2820. };
  2821.  
  2822. let callbackFound = false;
  2823. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  2824. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  2825. // M-youtube-js-engine-tamer.52178
  2826. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  2827. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  2828. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  2829. // RESULTXX / ErrorFXX / Other...
  2830. if (callbackIdentifier === 'RESULT27') {
  2831. this.overscrollConfigDisable = true;
  2832. if (!callbackFound) {
  2833. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  2834. getObjsFn = checkWheelListener = null;
  2835. checkWheelListenerObjs = null;
  2836. wheelHandler = null;
  2837. }
  2838. return void 0;
  2839. } else if (!callbackFound && !this.overscrollConfigDisable) {
  2840. this.overscrollConfigDisable = true;
  2841. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  2842. }
  2843. }
  2844. return this.addEventListener52178(type, callback, option);
  2845. };
  2846.  
  2847. // ---- << this.overscrollConfig HACK >> -----
  2848.  
  2849. }
  2850.  
  2851. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  2852.  
  2853. let p_a_objWR = null;
  2854. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  2855. let ytPageReady = 0;
  2856.  
  2857. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  2858. let isGlobalSpaceControl = true;
  2859. let mediaPlayerElementWR = null;
  2860. let focusedElementAtSelection = null;
  2861.  
  2862. // let want_control_video = false;
  2863.  
  2864. let spaceBarControl_keyG = '';
  2865.  
  2866. let lastUserAction = 0;
  2867.  
  2868. const wmKeyControlPhase = new WeakMap();
  2869.  
  2870. let currentSelectionText = null;
  2871.  
  2872. const getCurrentSelectionText = () => {
  2873. if (currentSelectionText !== null) return currentSelectionText
  2874. return (currentSelectionText = `${getSelection()}`)
  2875. }
  2876.  
  2877. const pageMediaWatcher = () => {
  2878.  
  2879. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  2880. // want_control_video = false;
  2881. // }, { capture: true, passive: true });
  2882.  
  2883. document.addEventListener('yt-navigate', () => {
  2884. ytPageReady = 0;
  2885. });
  2886. document.addEventListener('yt-navigate-start', () => {
  2887. ytPageReady = 0;
  2888. });
  2889. document.addEventListener('yt-navigate-cache', () => {
  2890. ytPageReady = 0;
  2891. });
  2892.  
  2893. document.addEventListener('yt-navigate-finish', () => {
  2894. ytPageReady = 1;
  2895. });
  2896.  
  2897. document.addEventListener('durationchange', () => {
  2898. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  2899. if (elm.duration > 0.01) {
  2900. if (elm.closest('[hidden]')) continue;
  2901. mediaPlayerElementWR = mWeakRef(elm);
  2902. return;
  2903. }
  2904. }
  2905. }, { capture: true, passive: true });
  2906.  
  2907. document.addEventListener('selectionchange', (evt) => {
  2908. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  2909. currentSelectionText = null;
  2910. if (!(evt.target instanceof Node)) return;
  2911. focusedElementAtSelection = evt.target;
  2912. }, { capture: true, passive: true })
  2913.  
  2914. document.addEventListener('pointerdown', (evt) => {
  2915. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2916. }, { capture: true, passive: true });
  2917.  
  2918.  
  2919. document.addEventListener('pointerup', (evt) => {
  2920. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2921. }, { capture: true, passive: true });
  2922.  
  2923.  
  2924. document.addEventListener('keydown', (evt) => {
  2925. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2926. }, { capture: true, passive: true });
  2927.  
  2928. document.addEventListener('keyup', (evt) => {
  2929. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2930. }, { capture: true, passive: true });
  2931.  
  2932. };
  2933.  
  2934.  
  2935. const checkKeyB = (p_a_obj) => {
  2936.  
  2937. const boolList = new Set();
  2938. const p_a_obj_api = p_a_obj.api;
  2939.  
  2940. const nilFunc0 = function () {
  2941. return void 0
  2942. };
  2943. const mt = new Proxy({}, {
  2944. get(target, prop) {
  2945. if (prop === 'get') return nilFunc0;
  2946. return mt;
  2947. }
  2948. });
  2949. const nilFunc = function () {
  2950. return mt
  2951. };
  2952. const mw = new Proxy({}, {
  2953. get(target, prop) {
  2954. if (prop in p_a_obj_api) {
  2955. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  2956. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  2957. if (q && q.value) {
  2958. if (!q.writable) return q.value;
  2959. if (typeof q.value === 'string') return '';
  2960. if (typeof q.value === 'number') return 0;
  2961. if (typeof q.value === 'boolean') return false;
  2962. if (q.value && typeof q.value === 'object') return {};
  2963. }
  2964. }
  2965. return undefined;
  2966. },
  2967. set(target, prop) {
  2968. throw 'mwSet';
  2969. }
  2970. });
  2971.  
  2972. const mq = new Proxy({}, {
  2973. get(target, prop) {
  2974. if (prop === 'api') return mw;
  2975. if (prop in p_a_obj) {
  2976. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  2977. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  2978. if (q && q.value) {
  2979. if (!q.writable) return q.value;
  2980. if (typeof q.value === 'string') return '';
  2981. if (typeof q.value === 'number') return 0;
  2982. if (typeof q.value === 'boolean') return false;
  2983. if (q.value && typeof q.value === 'object') return {};
  2984. }
  2985. }
  2986. return undefined;
  2987. },
  2988. set(target, prop, val) {
  2989. if (typeof val === 'boolean') boolList.add(prop)
  2990. throw `mqSet(${prop},${val})`;
  2991. }
  2992. });
  2993.  
  2994. let res = ''
  2995. try {
  2996. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  2997. } catch (e) {
  2998. res = `ERROR::${e}`;
  2999. }
  3000.  
  3001. if (boolList.size === 1) {
  3002. const value = boolList.values().next().value;
  3003. if (res === `ERROR::mqSet(${value},${true})`) {
  3004. p_a_obj.__uZWaD__ = value;
  3005. }
  3006. }
  3007.  
  3008. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  3009.  
  3010. }
  3011.  
  3012.  
  3013. let pm_p_a = null;
  3014.  
  3015. const p_a_init = function () {
  3016. const r = this.init91();
  3017. const keyBw = this.__cPzfo__ || '__NIL__';
  3018. const p_a_obj = this[keyBw];
  3019. if (!p_a_obj) return;
  3020. try {
  3021. checkKeyB(p_a_obj);
  3022. } catch (e) { }
  3023. p_a_objWR = mWeakRef(p_a_obj);
  3024. if (FIX_SHORTCUTKEYS > 0) {
  3025. if (p_a_obj && !p_a_obj.hVhtg) {
  3026. p_a_obj.hVhtg = 1;
  3027.  
  3028. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  3029. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  3030. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  3031. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  3032. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  3033. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  3034.  
  3035. }
  3036. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  3037. // const api = p_a_obj.api
  3038. // api.hVhtg = 1;
  3039. // api.playVideo91 = api.playVideo;
  3040. // api.playVideo = p_a_jt.playVideo;
  3041. // api.pauseVideo91 = api.pauseVideo;
  3042. // api.pauseVideo = p_a_jt.pauseVideo;
  3043. // }
  3044. }
  3045. if (pm_p_a) {
  3046. pm_p_a.resolve();
  3047. pm_p_a = null;
  3048. }
  3049. return r;
  3050. };
  3051.  
  3052. const p_a_xt = {
  3053.  
  3054. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  3055.  
  3056. if (FIX_SHORTCUTKEYS === 2) {
  3057.  
  3058. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  3059.  
  3060. if (activeElement) {
  3061.  
  3062. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  3063.  
  3064. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  3065. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  3066. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  3067.  
  3068. }
  3069.  
  3070. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  3071. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  3072. // console.log(582, isDelayedSpaceBar)
  3073. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  3074.  
  3075. if (activeElement && (h === 'Space' || h === 'Enter')) {
  3076. const controlPhase = wmKeyControlPhase.get(activeElement);
  3077. if (controlPhase === 4 || controlPhase === 5) return false;
  3078. }
  3079. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  3080. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  3081. // if (!isSpaceKeyImmediate) return false;
  3082. // }
  3083. }
  3084.  
  3085. },
  3086.  
  3087. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  3088.  
  3089. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  3090.  
  3091. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  3092. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  3093. // console.log(583, isDelayedSpaceBar)
  3094. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  3095.  
  3096. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3097.  
  3098. let mediaWorking = false;
  3099. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  3100. mediaWorking = true;
  3101. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3102. mediaWorking = true;
  3103. }
  3104. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  3105. mediaWorking && Promise.resolve().then(() => {
  3106. if (activeElement === document.activeElement) {
  3107. return activeElement.blur()
  3108. } else {
  3109. return false
  3110. }
  3111. }).then((r) => {
  3112. r !== false && mediaPlayerElement.focus();
  3113. });
  3114. }
  3115. },
  3116.  
  3117.  
  3118. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  3119.  
  3120. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3121.  
  3122. const activeElement = document.activeElement;
  3123.  
  3124. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3125. if (allow === false) return false;
  3126.  
  3127. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3128. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  3129.  
  3130. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3131.  
  3132. return ret;
  3133. },
  3134. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  3135.  
  3136.  
  3137. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3138.  
  3139. const activeElement = document.activeElement;
  3140. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3141. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3142. // }
  3143. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3144. if (allow === false) return false;
  3145.  
  3146. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3147. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  3148.  
  3149. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3150.  
  3151. return ret;
  3152. }
  3153.  
  3154. };
  3155.  
  3156. // const p_a_jt = { // API
  3157.  
  3158. // playVideo(a) { // without spinner effect
  3159.  
  3160. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3161.  
  3162. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3163. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3164. // want_control_video = true;
  3165. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3166. // }
  3167.  
  3168. // }
  3169. // return this.playVideo91(a);
  3170.  
  3171. // },
  3172.  
  3173. // pauseVideo(a) { // without spinner effect
  3174.  
  3175. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3176.  
  3177. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3178. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3179. // want_control_video = true;
  3180. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3181. // }
  3182.  
  3183. // }
  3184. // return this.pauseVideo91(a);
  3185.  
  3186. // }
  3187. // };
  3188.  
  3189. let flagSpeedMaster = null;
  3190. const getSpeedMasterControlFlag = () => {
  3191.  
  3192. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3193. isSpeedMastSpacebarControlEnabled = false;
  3194. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  3195. isSpeedMastSpacebarControlEnabled = true;
  3196. }
  3197. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  3198. isSpeedMastSpacebarControlEnabled = true;
  3199. }
  3200.  
  3201. if (flagSpeedMaster === null) {
  3202. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  3203. if (!p) {
  3204. flagSpeedMaster = false;
  3205. } else {
  3206.  
  3207. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  3208.  
  3209. }
  3210.  
  3211. }
  3212. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  3213.  
  3214. return isSpeedMastSpacebarControlEnabled;
  3215. }
  3216.  
  3217.  
  3218. const getGlobalSpacebarControlFlag = () => {
  3219.  
  3220. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3221. isGlobalSpaceControl = false;
  3222. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  3223. isGlobalSpaceControl = true;
  3224. }
  3225. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  3226. isGlobalSpaceControl = true;
  3227. }
  3228.  
  3229. return isGlobalSpaceControl;
  3230. }
  3231.  
  3232. const keyboardController = async (_yt_player) => {
  3233.  
  3234. const keyQT = getQT(_yt_player);
  3235. const keySV = getSV(_yt_player);
  3236. const keyDX = getDX(_yt_player);
  3237. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  3238.  
  3239. if (!keyDX) return;
  3240. if (keyDX === keyQT || keyDX === keySV) return;
  3241.  
  3242. if (typeof keyDX !== 'string') return;
  3243.  
  3244. let lastAccessKey = '';
  3245. let lastAccessKeyConfirmed = '';
  3246. const mb = new Proxy({}, {
  3247. get(target, prop) {
  3248. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  3249. throw 'mbGet'
  3250. },
  3251. set(target, prop, val) {
  3252. throw 'mbSet'
  3253. }
  3254. });
  3255. const ma = new Proxy({}, {
  3256. get(target, prop) {
  3257. lastAccessKey = prop;
  3258. return mb
  3259. },
  3260. set(target, prop, val) {
  3261. throw 'maSet'
  3262. }
  3263. });
  3264.  
  3265. let keyBw = '';
  3266. try {
  3267. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  3268. } catch (e) {
  3269. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  3270. keyBw = lastAccessKeyConfirmed;
  3271. }
  3272. }
  3273.  
  3274. if (!keyBw) return;
  3275.  
  3276. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  3277.  
  3278. pm_p_a = new PromiseExternal();
  3279.  
  3280. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  3281.  
  3282. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  3283.  
  3284. _yt_player[keyDX].prototype.init = p_a_init;
  3285.  
  3286. await pm_p_a.then();
  3287. const p_a_obj = kRef(p_a_objWR);
  3288.  
  3289. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  3290.  
  3291.  
  3292. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  3293.  
  3294. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  3295.  
  3296. if (!isSpeedMastSpacebarControlEnabled) {
  3297.  
  3298. if (config && config.EXPERIMENT_FLAGS) {
  3299. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  3300. }
  3301. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3302. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  3303. }
  3304.  
  3305. } else {
  3306.  
  3307. if (config && config.EXPERIMENT_FLAGS) {
  3308. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  3309. }
  3310. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3311. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  3312. }
  3313.  
  3314. }
  3315.  
  3316. }
  3317.  
  3318. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  3319.  
  3320.  
  3321.  
  3322.  
  3323. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  3324.  
  3325. // console.log(p_a_obj.handleGlobalKeyUp)
  3326. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  3327.  
  3328. // console.log(p_a_obj.api)
  3329.  
  3330.  
  3331. // QT -> DX(SV) -> p_a
  3332.  
  3333.  
  3334. /*
  3335. *
  3336. *
  3337. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3338. b = void 0 === b ? !1 : b;
  3339. c = void 0 === c ? !1 : c;
  3340. d = void 0 === d ? !1 : d;
  3341. e = void 0 === e ? !1 : e;
  3342. var l = g.PT(this);
  3343. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  3344. }
  3345.  
  3346. */
  3347.  
  3348. /*
  3349. *
  3350. *
  3351. *
  3352. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3353. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  3354. }
  3355.  
  3356. */
  3357.  
  3358.  
  3359. // if(!keyDX) return;
  3360.  
  3361. // console.log(4999, keyDX)
  3362.  
  3363. };
  3364.  
  3365.  
  3366. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  3367.  
  3368. const p_a_obj = kRef(p_a_objWR);
  3369. // const api = p_a_obj.api;
  3370.  
  3371.  
  3372. // console.log(540);
  3373.  
  3374. let boolList = null;
  3375. let ret;
  3376. isSpaceKeyImmediate = true;
  3377. try {
  3378.  
  3379. ret = 0;
  3380. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  3381. let p_a_objT;
  3382. if (!spaceBarControl_keyG) { // just in case
  3383. boolList = new Set();
  3384. p_a_objT = new Proxy(p_a_obj, {
  3385. get(target, prop, handler) {
  3386. const val = target[prop];
  3387. if (typeof val !== 'boolean') return val;
  3388. boolList.add(prop);
  3389. // console.log(555, prop, val);
  3390. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  3391. spaceBarControl_keyG = prop;
  3392. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3393. val = false;
  3394. }
  3395. return val;
  3396. }
  3397. });
  3398.  
  3399.  
  3400. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  3401. p_a_obj[spaceBarControl_keyG] = false;
  3402. p_a_objT = p_a_obj;
  3403. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  3404. } else {
  3405.  
  3406. p_a_objT = p_a_obj;
  3407. }
  3408.  
  3409. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  3410.  
  3411.  
  3412. } catch (e) {
  3413. console.log(e)
  3414. }
  3415. isSpaceKeyImmediate = false;
  3416.  
  3417. if (boolList && boolList.size === 1) {
  3418. const value = boolList.values().next().value;
  3419. spaceBarControl_keyG = value;
  3420. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3421.  
  3422. }
  3423.  
  3424. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3425.  
  3426. return ret;
  3427. }
  3428.  
  3429. const shortcutKeysFixer = () => {
  3430.  
  3431. let pausePromiseControlJ = 0;
  3432.  
  3433.  
  3434. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  3435.  
  3436. let controlPhase = 0;
  3437. const aElm = document.activeElement;
  3438.  
  3439. if (aElm) {
  3440.  
  3441. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  3442.  
  3443. if (typeof controlPhaseCache === 'number') {
  3444.  
  3445. controlPhase = controlPhaseCache;
  3446. } else {
  3447.  
  3448. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  3449. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  3450. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  3451. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  3452. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  3453. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  3454. else {
  3455. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  3456. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  3457. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  3458. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  3459. }
  3460.  
  3461. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  3462. controlPhase = 0;
  3463. }
  3464.  
  3465. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  3466. if (aElm.closest('[contenteditable], input, textarea')) {
  3467. controlPhase = 5;
  3468. } else if (aElm.closest('button')) {
  3469. controlPhase = 4;
  3470. }
  3471. }
  3472.  
  3473. if (aElm.closest('#movie_player')) controlPhase = 6;
  3474.  
  3475. wmKeyControlPhase.set(aElm, controlPhase);
  3476.  
  3477. }
  3478. }
  3479.  
  3480. return controlPhase;
  3481.  
  3482. }
  3483.  
  3484. const isStateControllable = (api) => {
  3485. let appState = null;
  3486. let playerState = null;
  3487. let adState = null;
  3488. try {
  3489. appState = api.getAppState();
  3490. playerState = api.getPlayerState();
  3491. adState = api.getAdState();
  3492. } catch (e) { }
  3493. // ignore playerState -1
  3494. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  3495. };
  3496.  
  3497.  
  3498. const keyEventListener = (evt) => {
  3499. if (BY_PASS_KEYBOARD_CONTROL) return;
  3500.  
  3501. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3502. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  3503. if (!ytPageReady) return;
  3504.  
  3505. if (evt.defaultPrevented === true) return;
  3506.  
  3507. const p_a_obj = kRef(p_a_objWR);
  3508.  
  3509. if (!p_a_obj) return;
  3510.  
  3511.  
  3512. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3513. if (!mediaPlayerElement) return;
  3514.  
  3515. // let focusBodyIfSuccess = false;
  3516.  
  3517. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  3518.  
  3519. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  3520. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  3521. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  3522.  
  3523.  
  3524. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  3525.  
  3526. // console.log(`${evt.type}::controlPhase`,controlPhase)
  3527.  
  3528. // if (controlPhase == 4) {
  3529. // focusBodyIfSuccess = true;
  3530. // }
  3531.  
  3532. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  3533. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3534.  
  3535. if (FIX_SHORTCUTKEYS < 2) return;
  3536. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  3537.  
  3538. let rr;
  3539. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  3540.  
  3541.  
  3542.  
  3543. let useImprovedPauseResume = false;
  3544.  
  3545. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3546.  
  3547. const api = p_a_obj.api;
  3548. const stateControllable = isStateControllable(api);
  3549. // console.log(2122, appState, playerState, adState)
  3550.  
  3551. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  3552.  
  3553. useImprovedPauseResume = true;
  3554.  
  3555. }
  3556.  
  3557.  
  3558. }
  3559.  
  3560.  
  3561. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  3562. if (evt.type === 'keydown') {
  3563.  
  3564. if (useImprovedPauseResume) {
  3565.  
  3566. const isPaused = mediaPlayerElement.paused;
  3567.  
  3568. const cj = ++pausePromiseControlJ;
  3569. Promise.resolve().then(() => {
  3570.  
  3571. if (cj !== pausePromiseControlJ) return;
  3572.  
  3573. if (mediaPlayerElement.paused !== isPaused) return;
  3574.  
  3575. const ret = ytResumeFn();
  3576. if (!ret) { // fallback
  3577. isPaused ? api.playVideo() : api.pauseVideo();
  3578. }
  3579.  
  3580. /*
  3581. let a = void 0;
  3582. console.log('Rb', api.Rb())
  3583. a = !window._yt_player.nL(api.Rb());
  3584. p_a_obj.Wd.kG(a)
  3585. a ? api.playVideo() : api.pauseVideo();
  3586.  
  3587. */
  3588.  
  3589.  
  3590. });
  3591. rr = true;
  3592. } else {
  3593.  
  3594. isSpaceKeyImmediate = true;
  3595. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  3596. isSpaceKeyImmediate = false;
  3597. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3598.  
  3599. }
  3600.  
  3601.  
  3602. } else if (evt.type === 'keyup') {
  3603.  
  3604. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3605.  
  3606. rr = true;
  3607. } else {
  3608.  
  3609. isSpaceKeyImmediate = true;
  3610. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  3611. isSpaceKeyImmediate = false;
  3612. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3613.  
  3614. }
  3615.  
  3616.  
  3617. /*
  3618.  
  3619. if (d)
  3620. switch (c) {
  3621. case 32:
  3622. case 13:
  3623. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  3624. b = !0,
  3625. e = !1;
  3626. else if (e) {
  3627. var m = d.getAttribute("role");
  3628. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  3629. d.click(),
  3630. f = !0)
  3631. }
  3632. break;
  3633. case 37:
  3634. case 39:
  3635. case 36:
  3636. case 35:
  3637. b = "slider" === d.getAttribute("role");
  3638. break;
  3639. case 38:
  3640. case 40:
  3641. m = d.getAttribute("role"),
  3642. d = 38 === c ? d.previousSibling : d.nextSibling,
  3643. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  3644. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  3645. f = b = !0))
  3646. }
  3647. if (e && !f)
  3648. switch (c) {
  3649. case 38:
  3650. f = Math.min(this.api.getVolume() + 5, 100);
  3651. XV(this.Wd, f, !1);
  3652. this.api.setVolume(f);
  3653. h = f = !0;
  3654. break;
  3655. case 40:
  3656. f = Math.max(this.api.getVolume() - 5, 0);
  3657. XV(this.Wd, f, !0);
  3658. this.api.setVolume(f);
  3659. h = f = !0;
  3660. break;
  3661. case 36:
  3662. this.api.Yh() && (this.api.startSeekCsiAction(),
  3663. this.api.seekTo(0, void 0, void 0, void 0, 79),
  3664. h = f = !0);
  3665. break;
  3666. case 35:
  3667. this.api.Yh() && (this.api.startSeekCsiAction(),
  3668. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  3669. h = f = !0)
  3670. }
  3671. */
  3672.  
  3673. }
  3674.  
  3675.  
  3676. if (rr) {
  3677.  
  3678. // focusBodyIfSuccess && Promise.resolve().then(() => {
  3679. // activeElement === document.activeElement && activeElement.blur();
  3680. // });
  3681.  
  3682. evt.preventDefault();
  3683. evt.stopImmediatePropagation();
  3684. evt.stopPropagation();
  3685.  
  3686. }
  3687.  
  3688. };
  3689.  
  3690. document.addEventListener('keydown', keyEventListener, { capture: true });
  3691.  
  3692.  
  3693. document.addEventListener('keyup', keyEventListener, { capture: true });
  3694.  
  3695. }
  3696.  
  3697. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  3698.  
  3699. })();
  3700.  
  3701.  
  3702. pageMediaWatcher();
  3703. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  3704.  
  3705.  
  3706. const check_for_set_key_order = (() => {
  3707.  
  3708. let mySet = new Set();
  3709.  
  3710. mySet.add("value1");
  3711. mySet.add("value2");
  3712. mySet.add("value3");
  3713.  
  3714. // Function to convert Set values to an array
  3715. function getSetValues(set) {
  3716. return Array.from(set.values());
  3717. }
  3718.  
  3719. // Function to test if the Set maintains insertion order
  3720. function testSetOrder(set, expectedOrder) {
  3721. let values = getSetValues(set);
  3722. return expectedOrder.join(',') === values.join(',');
  3723. }
  3724.  
  3725. // Test 1: Initial order
  3726. if (mySet.values().next().value !== "value1") return false;
  3727. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  3728.  
  3729. // Test 2: After deleting an element
  3730. mySet.delete("value2");
  3731. if (mySet.values().next().value !== "value1") return false;
  3732. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  3733.  
  3734. // Test 3: After re-adding a deleted element
  3735. mySet.add("value2");
  3736. if (mySet.values().next().value !== "value1") return false;
  3737. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  3738.  
  3739. // Test 4: After adding a new element
  3740. mySet.add("value4");
  3741. if (mySet.values().next().value !== "value1") return false;
  3742. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  3743.  
  3744. // Test 5: Delete+Add
  3745. mySet.delete("value1");
  3746. mySet.delete("value3");
  3747. mySet.add("value3");
  3748. mySet.add("value1");
  3749. if (mySet.values().next().value !== "value2") return false;
  3750. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  3751.  
  3752. return true;
  3753. })();
  3754.  
  3755.  
  3756. // const qm47 = Symbol();
  3757. const qm57 = Symbol();
  3758. const qm53 = Symbol();
  3759. const qn53 = Symbol();
  3760.  
  3761.  
  3762. const ump3 = new WeakMap();
  3763.  
  3764. const stp = document.createElement('noscript');
  3765. stp.id = 'weakref-placeholder';
  3766.  
  3767. PROP_OverReInclusion_AVOID && (() => {
  3768.  
  3769.  
  3770. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  3771. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  3772. let byPassVal = null;
  3773. let byPassCount = 0;
  3774. let mmw = new Set();
  3775. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  3776. if (arguments.length !== 1) return f.apply(this, arguments);
  3777. if (byPassVal !== null && typeof prop === 'string') {
  3778.  
  3779. if (PROP_OverReInclusion_LIST.has(prop)) {
  3780. byPassCount++;
  3781. return byPassVal;
  3782. }
  3783. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  3784.  
  3785. }
  3786. return this.hasOwnProperty72(prop);
  3787. };
  3788.  
  3789.  
  3790. /*
  3791.  
  3792.  
  3793. z.prototype.forwardDynamicProps = function() {
  3794. var B = m(this.inst);
  3795. B = h(B);
  3796. for (var F = B.next(); !F.done; F = B.next()) {
  3797. var H = h(F.value);
  3798. F = H.next().value;
  3799. H = H.next().value;
  3800. my(this, F, H);
  3801. r(b) && !ly(F) && Wua(this.inst, F)
  3802. }
  3803. }
  3804.  
  3805. */
  3806.  
  3807.  
  3808.  
  3809. let byPassZeroShowed = false;
  3810. const forwardDynamicPropsGeneral = function () {
  3811. byPassVal = true;
  3812. byPassCount = 0;
  3813. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  3814. const ret = this.forwardDynamicProps72();
  3815. byPassVal = null;
  3816. if (byPassCount === 0 && !byPassZeroShowed) {
  3817. byPassZeroShowed = true;
  3818. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  3819. }
  3820. byPassCount = 0;
  3821. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  3822. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  3823. mmw.clear();
  3824. }
  3825. return ret;
  3826. };
  3827.  
  3828. const propCheck = (proto) => {
  3829. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  3830. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  3831. if (proto.forwardDynamicProps.length === 0) {
  3832. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  3833. }
  3834. }
  3835. };
  3836.  
  3837. const valMap = new WeakMap();
  3838. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  3839. get() {
  3840. propCheck(this.constructor.prototype);
  3841. return valMap.get(this);
  3842. },
  3843. set(nv) {
  3844. propCheck(this.constructor.prototype);
  3845. valMap.set(this, nv);
  3846. return true;
  3847. },
  3848. enumerable: false,
  3849. configurable: true
  3850.  
  3851. });
  3852.  
  3853. promiseForCustomYtElementsReady.then(() => {
  3854. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  3855. if (customElements.define.length !== 2) return;
  3856. customElements.define72 = customElements.define;
  3857. customElements.define = function (b, w) {
  3858. propCheck(w.prototype);
  3859. const ret = this.define72(b, w);
  3860. return ret;
  3861. }
  3862. });
  3863.  
  3864. })();
  3865.  
  3866.  
  3867. let marcoPr = new PromiseExternal();
  3868. const trackMarcoCm = document.createComment('1');
  3869. const trackMarcoCmObs = new MutationObserver(()=>{
  3870. marcoPr.resolve();
  3871. marcoPr = new PromiseExternal();
  3872. });
  3873. trackMarcoCmObs.observe(trackMarcoCm, {characterData: true});
  3874.  
  3875.  
  3876. // ----------------------------
  3877.  
  3878.  
  3879.  
  3880. // const rendererStamperCreationFactory = (cProto, options) => {
  3881.  
  3882. // const { key, stamperDomClass, preloadFn } = options;
  3883.  
  3884. // // const newDoc = document.implementation.createHTMLDocument("NewDoc");
  3885. // const pSpace = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3886. // document.documentElement.insertAdjacentElement('beforeend', pSpace);
  3887. // const pNode = document.createElement('ns-538');
  3888. // pSpace.insertAdjacentElement('beforeend', pNode);
  3889.  
  3890. // const pDiv = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3891. // if (typeof pNode.attachShadow === 'function') {
  3892. // const pShadow = pNode.attachShadow({ mode: "open" });
  3893. // pShadow.replaceChildren(pDiv);
  3894. // } else {
  3895. // pNode.insertAdjacentElement('beforeend', pDiv);
  3896. // }
  3897.  
  3898. // const pDivNew = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3899. // pDiv.insertAdjacentElement('beforeend', pDivNew);
  3900.  
  3901. // const wmRemoved = new Map();
  3902.  
  3903. // // const wmMapToItem = new WeakMap();
  3904. // // let wmPendingList = null;
  3905.  
  3906. // const nullComponents = new Map();
  3907.  
  3908. // const componentDefaultAttributes = new WeakMap();
  3909.  
  3910. // const fnKeyH = `${key}$$c472`;
  3911.  
  3912. // cProto[fnKeyH] = async function (cTag, cId, pr00) {
  3913. // // await the current executing task (if any)
  3914. // // and avoid stacking in the same marco task
  3915. // await Promise.all([pr00, nextBrowserTick_()]);
  3916. // if (!this.ec389a && !this.ec389r) return;
  3917. // const addedCount0 = this.ec389a;
  3918. // const removedCount0 = this.ec389r;
  3919.  
  3920. // this.ec389 = false;
  3921. // this.ec389a = 0;
  3922. // this.ec389r = 0;
  3923.  
  3924. // const stampDomMap = this.stampDom[cTag].mapping;
  3925. // const isTickerRendering = cTag === 'tickerItems';
  3926. // const isMessageListRendering = cTag === 'visibleItems';
  3927.  
  3928. // // coming process can be stacked as ec389a and ec389r are reset.
  3929.  
  3930. // const deObjectComponent = (itemEntry) => {
  3931. // const I = firstObjectKey(itemEntry);
  3932. // const L = stampDomMap[I];
  3933. // const H = itemEntry[I];
  3934. // return [L, H];
  3935. // }
  3936.  
  3937. // const hostElement = this.hostElement;
  3938.  
  3939. // let renderNodeCount = 0;
  3940. // const renderList = this[cTag].map((item) => {
  3941. // const [L, H] = deObjectComponent(item);
  3942. // const node = kRef(renderMap.get(H));
  3943. // return node && hostElement.contains(node) ? (renderNodeCount++, node) : item;
  3944. // });
  3945.  
  3946. // // this.ec389 = null;
  3947. // // this.ec389a = 0;
  3948. // // this.ec389r = 0;
  3949.  
  3950. // let addedCounter = 0;
  3951. // let removedCounter = 0;
  3952.  
  3953. // const createConnectedComponentElm = (insertionObj, L, H, componentName) => {
  3954. // // const reusable = false;
  3955. // // const componentName = this.getComponentName_(L, H);
  3956. // let component;
  3957. // if (!nullComponents.has(componentName)) {
  3958. // nullComponents.set(componentName, (component = document.createElement(componentName)));
  3959. // component.className = stamperDomClass;
  3960. // // shadowElm.insertAdjacentElement('beforeend', component);
  3961. // } else {
  3962. // component = nullComponents.get(componentName);
  3963. // }
  3964. // component = component.cloneNode(false);
  3965.  
  3966. // // const cnt = insp(component);
  3967.  
  3968. // // cnt.__dataOld = cnt.__dataPending = null;
  3969. // pDivNew.insertAdjacentElement('beforeend', component);
  3970. // // cnt.__dataOld = cnt.__dataPending = null;
  3971.  
  3972. // return component;
  3973. // }
  3974.  
  3975. // const listDom = this.getStampContainer_(cId);
  3976.  
  3977. // const pnForNewItem = (item) => {
  3978.  
  3979. // const [L, H] = deObjectComponent(item);
  3980.  
  3981. // const componentName = this.getComponentName_(L, H);
  3982.  
  3983. // const wmList = wmRemoved.get(componentName.toLowerCase());
  3984.  
  3985. // let connectedComponent = null;
  3986. // if (wmList && (connectedComponent = wmList.firstElementChild)) {
  3987. // if (this.telemetry_) this.telemetry_.reuse++;
  3988. // // if (!wmPendingList) {
  3989. // // wmPendingList = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3990. // // wmPendingList.setAttributeNS('http://www.w3.org/2000/svg', 'wm-pending', 'true');
  3991. // // pDiv.insertAdjacentElement('afterend', wmPendingList);
  3992. // // }
  3993. // // wmPendingList.insertAdjacentElement('beforeend', connectedComponent);
  3994. // pDivNew.insertAdjacentElement('beforeend', connectedComponent);
  3995. // const attrMap = connectedComponent.attributes;
  3996. // const defaultAttrs = componentDefaultAttributes.get(connectedComponent);
  3997. // if (defaultAttrs) {
  3998. // for (const attr of attrMap) {
  3999. // const name = attr.name;
  4000. // if (name in defaultAttrs) attr.value = defaultAttrs[name];
  4001. // else attrMap.removeNamedItem(name);
  4002. // }
  4003. // if (attrMap.length !== defaultAttrs['"']) {
  4004. // for (const name in defaultAttrs) {
  4005. // if (!attrMap[name] && name !== '"') connectedComponent.setAttribute(name, defaultAttrs[name]);
  4006. // }
  4007. // }
  4008. // }
  4009.  
  4010. // } else {
  4011. // connectedComponent = createConnectedComponentElm(item, L, H, componentName);
  4012. // if (this.telemetry_) this.telemetry_.create++;
  4013. // }
  4014. // if (isTickerRendering) {
  4015. // const container = connectedComponent.firstElementChild;
  4016. // if (container) container.classList.add('yt-live-chat-ticker-stampdom-container');
  4017. // }
  4018.  
  4019. // return [item, L, H, connectedComponent];
  4020.  
  4021. // };
  4022.  
  4023. // let imgPreloadPr = null;
  4024. // if (isMessageListRendering) {
  4025. // const addedItems = renderList.filter(item => item === 'object' && (item instanceof Node));
  4026. // imgPreloadPr = preloadFn(addedItems)();
  4027. // }
  4028.  
  4029. // const newComponentsEntries = await executeTaskBatch(renderList.map(item => ({
  4030. // item,
  4031. // fn(task) {
  4032. // const { item } = task;
  4033. // return typeof item === 'object' && !(item instanceof Node) ? pnForNewItem(item) : item;
  4034. // }
  4035. // })));
  4036.  
  4037. // const imgPromises = [];
  4038.  
  4039. // const imgPaths = new Set();
  4040.  
  4041. // const pnForRenderNewItem = (entry) => {
  4042. // const [item, L, H, connectedComponent] = entry;
  4043.  
  4044. // const cnt = insp(connectedComponent);
  4045. // if (!cnt.__refreshData938__) {
  4046. // cnt.constructor.prototype.__refreshData938__ = __refreshData938__;
  4047. // }
  4048. // if (typeof cnt.data === 'object' && cnt.__dataEnabled === true && cnt.__dataReady === true && cnt.__dataInvalid === false) {
  4049. // cnt.data = H;
  4050. // } else {
  4051. // const q = this.deferRenderStamperBinding_
  4052. // let q2;
  4053. // if (typeof q === 'object') q2 = this.deferRenderStamperBinding_ = [];
  4054. // this.deferRenderStamperBinding_(connectedComponent, L, H);
  4055. // this.flushRenderStamperComponentBindings_();
  4056. // if (typeof q === 'object') {
  4057. // this.deferRenderStamperBinding_ = q;
  4058. // q2.length = 0;
  4059. // }
  4060. // }
  4061. // if (cnt.data) cnt.__refreshData938__('data', !0); // ensure data is invalidated
  4062.  
  4063. // // fix yt-icon issue
  4064. // for (const node of connectedComponent.getElementsByTagName('yt-icon')) {
  4065. // try {
  4066. // const cnt = insp(node);
  4067. // if (!cnt.__refreshProps938__) cnt.constructor.prototype.__refreshProps938__ = __refreshProps938__;
  4068. // cnt.__refreshProps938__();
  4069. // } catch (e) { }
  4070. // }
  4071.  
  4072. // componentDefaultAttributes.set(connectedComponent, getAttributes(connectedComponent));
  4073. // return entry;
  4074. // }
  4075.  
  4076. // const newRenderedComponents = await executeTaskBatch(newComponentsEntries.map(entry => ({
  4077. // entry,
  4078. // fn(task) {
  4079. // const { entry } = task;
  4080. // return typeof entry === 'object' && !(entry instanceof Node) ? pnForRenderNewItem(entry) : entry;
  4081. // }
  4082. // })));
  4083.  
  4084.  
  4085. // this.flushRenderStamperComponentBindings_(); // ensure all deferred flush render tasks clear.
  4086.  
  4087. // // imgPromises.push(imageFetch('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'));
  4088. // if (imgPromises.length > 0) {
  4089. // const pr1 = Promise.all(imgPromises).catch(e => { });
  4090. // const pr2 = autoTimerFn();
  4091. // await Promise.race([pr1, pr2]).catch(e => { });
  4092. // imgPaths.clear();
  4093. // imgPromises.length = 0;
  4094. // }
  4095. // if (imgPreloadPr) await imgPreloadPr;
  4096.  
  4097. // // const batching = [];
  4098. // // let j = 0;
  4099. // // let elNode;
  4100.  
  4101. // const sideProcesses = [];
  4102.  
  4103. // const removeStampNode_ = (elNode) => {
  4104. // const elm = elNode;
  4105. // const cnt = insp(elm);
  4106. // const componentName = elm.nodeName.toLowerCase();
  4107. // let wmList = wmRemoved.get(componentName);
  4108. // if (!wmList) {
  4109. // wmList = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4110. // wmList.setAttributeNS('http://www.w3.org/2000/svg', 'wm-component', componentName);
  4111. // pDiv.insertAdjacentElement('afterend', wmList);
  4112. // wmRemoved.set(componentName, wmList);
  4113. // }
  4114. // wmList.insertAdjacentElement('beforeend', elm);
  4115. // const data = cnt.data;
  4116. // if (data) renderMap.delete(cnt.data);
  4117.  
  4118. // sideProcesses.push(reuseFixDataViewModel(elm));
  4119. // sideProcesses.push(reuseFixYtIconRendering(elm));
  4120. // }
  4121.  
  4122. // // const removeStampNode = async () => {
  4123.  
  4124. // // removedCounter++;
  4125.  
  4126. // // const nextElm = nextComponentSiblingFn(elNode);
  4127. // // const elmId = elNode.id;
  4128. // // removeStampNode_(elNode);
  4129. // // // const dzid = this.getAttribute('dz-component-id');
  4130. // // // ---- no-cache ----
  4131. // // // try{
  4132. // // // elm.remove();
  4133. // // // }catch(e){}
  4134. // // // ---- no-cache ----
  4135.  
  4136. // // if (cTag === 'visibleItems') {
  4137. // // sideProcesses.push(onVisibleItemStampNodeRemoval(elmId));
  4138. // // }
  4139.  
  4140. // // j++;
  4141. // // elNode = nextElm;
  4142.  
  4143. // // }
  4144.  
  4145. // // if (typeof Polymer !== "undefined" && typeof Polymer.flush === "function") {
  4146. // // // clear all pending rendering first
  4147. // // await stackMarcoTask(async () => {
  4148. // // Polymer.flush();
  4149. // // });
  4150. // // }
  4151.  
  4152. // // main UI thread - DOM modification
  4153. // await new Promise((resolveDM) => {
  4154. // nextBrowserTick_(() => {
  4155.  
  4156. // const isAtBottom = this.atBottom === true;
  4157. // // if (ENABLE_OVERFLOW_ANCHOR && isAtBottom) {
  4158. // // shouldScrollAfterFlush = true;
  4159. // // }
  4160.  
  4161.  
  4162. // const tasks = [];
  4163.  
  4164. // const taskFn = {
  4165. // remove: (task) => {
  4166.  
  4167. // const { elNode } = task;
  4168.  
  4169. // removedCounter++;
  4170.  
  4171. // const elmId = elNode.id;
  4172. // removeStampNode_(elNode);
  4173. // // const dzid = this.getAttribute('dz-component-id');
  4174. // // ---- no-cache ----
  4175. // // try{
  4176. // // elm.remove();
  4177. // // }catch(e){}
  4178. // // ---- no-cache ----
  4179.  
  4180. // if (isMessageListRendering) {
  4181. // sideProcesses.push(onVisibleItemStampNodeRemoval(elmId));
  4182. // }
  4183.  
  4184. // return 2
  4185.  
  4186. // },
  4187. // append: (task) => {
  4188.  
  4189. // const { newNode, nodeAfter, parentNode } = task;
  4190.  
  4191. // nodeAfter ? nodeAfter.insertAdjacentElement('beforebegin', newNode) : parentNode.insertAdjacentElement('beforeend', newNode);
  4192. // const connectedComponent = newNode;
  4193. // const cnt = insp(connectedComponent);
  4194. // renderMap.set(cnt.data, mWeakRef(connectedComponent));
  4195. // mutationDelayedRefreshData(cnt); // not included to sideProcesses
  4196. // addedCounter++;
  4197.  
  4198. // if (isTickerRendering) {
  4199. // sideProcesses.push(onTickerItemStampNodeAdded());
  4200. // }
  4201.  
  4202. // if (isMessageListRendering && isAtBottom) {
  4203.  
  4204. // const itemScroller = this.itemScroller;
  4205. // if (itemScroller && (!ENABLE_OVERFLOW_ANCHOR || itemScroller.scrollTop === 0)) itemScroller.scrollTop = 16777216;
  4206.  
  4207. // }
  4208.  
  4209. // return 1
  4210. // }
  4211. // }
  4212.  
  4213. // {
  4214. // const indexMap = new WeakMap();
  4215. // let index = 0;
  4216. // for (let elNode_ = firstComponentChildFn(listDom); elNode_ instanceof Node; elNode_ = nextComponentSiblingFn(elNode_)) {
  4217. // indexMap.set(elNode_, index++);
  4218. // }
  4219.  
  4220. // const keepIndices = new Array(renderNodeCount);
  4221. // let keepIndicesLen = 0, lastKeepIndex = -1, requireSort = false;
  4222. // for (let i = 0, l = newRenderedComponents.length; i < l; i++) {
  4223. // const entry = newRenderedComponents[i];
  4224. // if (entry instanceof Node) {
  4225. // const index = indexMap.get(entry);
  4226. // keepIndices[keepIndicesLen++] = [index, entry];
  4227. // if (index > lastKeepIndex) lastKeepIndex = index;
  4228. // else requireSort = true;
  4229. // }
  4230. // }
  4231. // keepIndices.length = keepIndicesLen;
  4232. // if (requireSort) keepIndices.sort((a, b) => a[0] - b[0]);
  4233. // let dk = 0;
  4234.  
  4235. // let j = 0;
  4236. // let elNode;
  4237.  
  4238. // elNode = firstComponentChildFn(listDom);
  4239.  
  4240. // for (const rcEntry of newRenderedComponents) {
  4241. // const index = indexMap.get(rcEntry);
  4242. // if (typeof index === 'number') {
  4243. // const indexEntry = keepIndices[dk++];
  4244. // const [dIdx, dNode] = indexEntry;
  4245. // indexMap.delete(rcEntry);
  4246. // const idx = dIdx;
  4247. // while (j < idx && elNode) {
  4248. // tasks.push({
  4249. // type: 'remove',
  4250. // elNode,
  4251. // fn: taskFn.remove
  4252. // });
  4253. // elNode = nextComponentSiblingFn(elNode);
  4254. // j++;
  4255. // }
  4256. // if (j === idx) {
  4257. // if (elNode) {
  4258. // // if (dNode !== elNode) tasks.push({
  4259. // // type: 'swap',
  4260. // // earlyNode: indexEntry[1],
  4261. // // laterNode: elNode
  4262. // // });
  4263. // elNode = nextComponentSiblingFn(elNode);
  4264. // j++;
  4265. // } else {
  4266. // console.warn('elNode is not available?', renderList, addedCount0, removedCount0, j, idx);
  4267. // }
  4268. // }
  4269. // } else if (rcEntry instanceof Node) {
  4270. // // interruped by the external like clearList
  4271.  
  4272. // tasks.push({
  4273. // type: 'remove',
  4274. // elNode: rcEntry,
  4275. // fn: taskFn.remove
  4276. // });
  4277.  
  4278. // } else {
  4279. // const [item, L, H, connectedComponent] = rcEntry;
  4280.  
  4281. // tasks.push({
  4282. // type: 'append',
  4283. // newNode: connectedComponent,
  4284. // nodeAfter: elNode,
  4285. // parentNode: listDom,
  4286. // fn: taskFn.append
  4287. // });
  4288.  
  4289. // }
  4290.  
  4291. // }
  4292.  
  4293. // while (elNode) {
  4294.  
  4295. // tasks.push({
  4296. // type: 'remove',
  4297. // elNode,
  4298. // fn: taskFn.remove
  4299. // });
  4300. // elNode = nextComponentSiblingFn(elNode);
  4301.  
  4302. // }
  4303.  
  4304. // }
  4305.  
  4306.  
  4307. // executeTaskBatch(tasks).then(resolveDM).catch(console.warn);
  4308.  
  4309. // });
  4310. // }).catch(console.warn);
  4311.  
  4312. // {
  4313. // const arr = this[cTag];
  4314. // let b = 0;
  4315. // b = b | this._setPendingPropertyOrPath(`${cTag}.splices`, {}, true, true);
  4316. // b = b | this._setPendingPropertyOrPath(`${cTag}.length`, arr.length, true, true);
  4317. // b && this._invalidateProperties();
  4318. // }
  4319.  
  4320. // // this.flushRenderStamperComponentBindings_(); // just in case...
  4321.  
  4322. // await Promise.all(sideProcesses);
  4323.  
  4324. // const detail = {
  4325. // container: listDom
  4326. // };
  4327. // this.stampDom[cTag].events && this.hostElement.dispatchEvent(new CustomEvent("yt-rendererstamper-finished", {
  4328. // bubbles: !0,
  4329. // cancelable: !1,
  4330. // composed: !0,
  4331. // detail
  4332. // }));
  4333. // detail.container = null;
  4334.  
  4335. // // if (typeof Polymer !== "undefined" && typeof Polymer.flush === "function") {
  4336. // // // clear all remaining rendering before promise resolve
  4337. // // await stackMarcoTask(async () => {
  4338. // // Polymer.flush();
  4339. // // });
  4340. // // }
  4341.  
  4342. // }
  4343.  
  4344. // cProto[key] = function (cTag, cId, indexSplice) {
  4345. // // console.log('proceedStampDomArraySplices_')
  4346. // // assume no error -> no try catch (performance consideration)
  4347. // const { index, addedCount, removed } = indexSplice;
  4348. // const removedCount = removed ? removed.length : indexSplice.removedCount;
  4349. // indexSplice = null;
  4350. // if (!addedCount && !removedCount) {
  4351. // console.warn('proceedStampDomArraySplices_', 'Error 001');
  4352. // return false;
  4353. // }
  4354. // // const streamArr = this[cTag];
  4355. // if (!this.ec389) {
  4356. // if (this.ec389a || this.ec389r) {
  4357. // console.warn('proceedStampDomArraySplices_', 'Error 002');
  4358. // return false;
  4359. // }
  4360. // this.ec389 = true;
  4361. // this.ec389a = 0;
  4362. // this.ec389r = 0;
  4363. // }
  4364. // const shouldExecute = !this.ec389a && !this.ec389r;
  4365.  
  4366. // this.ec389a += addedCount;
  4367. // this.ec389r += removedCount;
  4368.  
  4369. // if (shouldExecute) {
  4370.  
  4371. // // let shouldScrollAfterFlush = false;
  4372. // const pr00 = this.ec389pr;
  4373. // const ec389pr = this.ec389pr = this[fnKeyH](cTag, cId, pr00).catch(console.warn);
  4374.  
  4375. // if (cTag === 'visibleItems') {
  4376. // this.prDelay288 = ec389pr;
  4377. // // this.hasUserJustInteracted12_ = (this.hasUserJustInteracted11_ || (() => false));
  4378.  
  4379. // // the first microtask after promise resolved
  4380. // // YYYYYYY
  4381. // // ec389pr.then(async () => {
  4382. // // if (shouldScrollAfterFlush) {
  4383. // // if (this.atBottom === false && this.allowScroll === true && !this.hasUserJustInteracted12_()) this.scrollToBottom_();
  4384. // // wme.data = `${(wme.data & 7) + 1}`;
  4385. // // await wmp;
  4386. // // if (this.atBottom === false && this.allowScroll === true && !this.hasUserJustInteracted12_()) this.scrollToBottom_();
  4387. // // }
  4388. // // });
  4389.  
  4390. // }
  4391.  
  4392. // }
  4393.  
  4394. // return true;
  4395. // }
  4396.  
  4397.  
  4398.  
  4399.  
  4400.  
  4401. // }
  4402.  
  4403. // ----------------------------
  4404.  
  4405.  
  4406. // const convertionFuncMap = new WeakMap();
  4407. // let val_kevlar_should_maintain_stable_list = null;
  4408.  
  4409. // const csb = (a, b) => { for (const c in a) if (a.hasOwnProperty(c) && b[c]) return c; return null }
  4410. // const createStampDomArrayFnE1_ = function (items, containerId, componentConfig, rendererConfig, shouldTriggerRendererStamperFinished, isStableList) {
  4411.  
  4412.  
  4413. // // this.__$$fs894$$__ = this.__$$fs894$$__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4414.  
  4415. // // console.log(1880, this.__$$fs894$$__)
  4416. // if(!this[`__0p893::${containerId}__`]) this[`__0p893::${containerId}__`]= [];
  4417.  
  4418. // // const task =
  4419. // queueMicrotask_(()=>{
  4420.  
  4421.  
  4422. // });
  4423. // this[`__0p892::${containerId}__`] = (this[`__0p892::${containerId}__`] || Promise.resolve(0)).then(async () => {
  4424.  
  4425. // try {
  4426.  
  4427. // if ((this.hostElement || 0).isConnected) this[`__0fs892::${containerId}__`] = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4428. // const t892 = this[`__0fs892::${containerId}__`];
  4429. // // a - array
  4430. // // c - mapping
  4431. // // d - reuseComponents
  4432. // // e - events (shouldTriggerRendererStamperFinished)
  4433. // // h - stamperStableList
  4434.  
  4435. // // this is for flushing the new elements to a blank container. (without reusing)
  4436.  
  4437. // const b_ = containerId;
  4438. // const c_ = componentConfig;
  4439. // const items_ = items;
  4440.  
  4441. // const doDeferRenderStamperBinding_ = async (component) => {
  4442. // const i = component[stampIdxSb];
  4443. // const u = items_[i];
  4444. // const c = c_;
  4445. // const x = csb(c, u);
  4446. // this.deferRenderStamperBinding_(component, c[x], u[x]); // necessary?
  4447. // };
  4448.  
  4449. // const container = this.getStampContainer_(b_);
  4450.  
  4451. // const domShell = container.__domApi || container;
  4452. // if (!domShell || !domShell.appendChild || typeof domShell.childElementCount !== 'number') throw new Error();
  4453. // const domShellElementCount = domShell.childElementCount;
  4454. // const noscript = document.createElement('noscript');
  4455. // // document.body.appendChild(noscript);
  4456.  
  4457. // let doc = document;
  4458.  
  4459. // const nofn = () => true;
  4460. // const n = items_.length;
  4461. // const fns = new Array(n);
  4462. // let cxt = 0;
  4463.  
  4464. // let qxd = domShellElementCount > 0 ? new WeakSet() : null;
  4465. // const nextTickFnE1 = () => {
  4466. // items_.some((item, i) => {
  4467.  
  4468. // const componentKey = csb(componentConfig, item);
  4469. // if (!componentKey) {
  4470. // fns[i] = nofn;
  4471. // cxt++;
  4472. // } else {
  4473.  
  4474. // const newComponent = this.createComponent_(componentConfig[componentKey], item[componentKey], rendererConfig);
  4475. // newComponent[stampIdxSb] = i;
  4476. // doDeferRenderStamperBinding_(newComponent);
  4477. // // mutex = mutex.then(() => {
  4478. // noscript.appendChild(newComponent);
  4479. // // });
  4480.  
  4481. // // Promise.resolve(cp).then(doDeferRenderStamperBinding_);
  4482. // let newComponent_ = newComponent;
  4483. // fns[i] = () => {
  4484. // if (!newComponent_) return true;
  4485. // if (newComponent_.parentNode === noscript) {
  4486. // newComponent_ = null;
  4487. // return true;
  4488. // }
  4489. // return false;
  4490. // };
  4491.  
  4492. // }
  4493.  
  4494. // });
  4495. // noscript.setAttribute('ylul8gr', `${Date.now()}`);
  4496. // };
  4497.  
  4498. // const nextTickFnF1 = () => {
  4499. // let startNode = null;
  4500.  
  4501. // const isSet = new Set();
  4502. // items_.some((item, i) => {
  4503.  
  4504. // const componentKey = csb(componentConfig, item);
  4505. // if (!componentKey) {
  4506. // fns[i] = nofn;
  4507. // cxt++;
  4508. // } else {
  4509.  
  4510. // const componentName = this.getComponentName_(componentConfig[componentKey], item[componentKey]);
  4511. // isSet.add(componentName);
  4512. // let np = startNode || domShell.firstElementChild;
  4513. // let chosenNode = null;
  4514. // while (np) {
  4515. // if (np instanceof Node_ && np.is === componentName && !qxd.has(np)) {
  4516. // qxd.add(np);
  4517. // chosenNode = np;
  4518. // break;
  4519. // }
  4520. // np = np.nextElementSibling;
  4521. // }
  4522.  
  4523.  
  4524. // const cp = chosenNode || this.createComponent_(componentConfig[componentKey], item[componentKey], rendererConfig);
  4525. // let oldIdx = cp[stampIdxSb];
  4526.  
  4527. // cp[stampIdxSb] = i;
  4528. // doDeferRenderStamperBinding_(cp);
  4529. // if (chosenNode !== null && cp === chosenNode) {
  4530.  
  4531. // fns[i] = nofn;
  4532. // startNode = chosenNode;
  4533. // } else {
  4534.  
  4535. // // mutex = mutex.then(() => {
  4536. // noscript.appendChild(cp); // ui formation
  4537. // // });
  4538.  
  4539. // // Promise.resolve(cp).then(doDeferRenderStamperBinding_);
  4540. // let q = cp;
  4541. // fns[i] = () => {
  4542. // if (q && q.parentNode === noscript) {
  4543. // const cp = q;
  4544. // q = null;
  4545. // }
  4546. // if (!q) return true;
  4547. // };
  4548.  
  4549. // }
  4550.  
  4551. // }
  4552.  
  4553. // });
  4554.  
  4555. // if (isSet.size === 1 && qxd !== null) {
  4556.  
  4557. // const is = isSet.values().next().value;
  4558.  
  4559. // if (typeof is === 'string' && is.length >= 1) {
  4560.  
  4561. // let np = startNode || domShell.firstElementChild;
  4562. // const removal = [];
  4563. // while (np) {
  4564. // if (np instanceof Node_ && np.is === is && !qxd.has(np)) {
  4565. // removal.push(np);
  4566. // np[stampIdxSb] = -1;
  4567. // }
  4568. // np = np.nextElementSibling;
  4569. // }
  4570. // // by default, removal.length shoule be zero. just play safe.
  4571. // if (removal.length > 0) {
  4572. // const dFrag = doc.createDocumentFragment();
  4573. // dFrag.append(...removal);
  4574. // removal.length = 0;
  4575. // }
  4576.  
  4577. // }
  4578.  
  4579. // }
  4580. // noscript.setAttribute('ylul8gr', `${Date.now()}`);
  4581.  
  4582.  
  4583.  
  4584. // }
  4585.  
  4586. // const pr = new Promise(resolvePR => {
  4587.  
  4588. // let mo = new MutationObserver(() => {
  4589. // if (typeof fns[n - 1] !== 'function') return;
  4590. // if (!noscript.hasAttribute('ylul8gr')) return;
  4591. // const everyTrue = fns.every(fn => fn() === true);
  4592. // if (everyTrue) {
  4593. // if (mo) {
  4594. // mo.disconnect();
  4595. // mo.takeRecords();
  4596. // mo = null;
  4597. // }
  4598. // resolvePR();
  4599. // }
  4600. // });
  4601. // mo.observe(noscript, { subtree: false, childList: true, attributes: ['ylul8gr'] });
  4602.  
  4603. // if (domShellElementCount > 0) {
  4604. // nextBrowserTick_(nextTickFnF1);
  4605. // } else {
  4606. // nextBrowserTick_(nextTickFnE1);
  4607. // }
  4608.  
  4609. // });
  4610. // await pr.then();
  4611. // fns.length = 0;
  4612. // qxd = null;
  4613.  
  4614. // // console.log(3025)
  4615.  
  4616.  
  4617.  
  4618. // // document.documentElement.appendChild.call(doc.documentElement, noscript);
  4619. // // nativeRemoveE.call(noscript);
  4620.  
  4621. // // nativeRemoveE.call(noscript);
  4622. // noscript.remove(); // trigger isAttached change
  4623. // const hostElement = this.hostElement;
  4624.  
  4625.  
  4626. // /** @type {DocumentFragment} */
  4627. // // const gFragment = document.createDocumentFragment();
  4628. // const gFragment = doc.createDocumentFragment();
  4629.  
  4630. // const fnE = () => {
  4631. // const evt = new CustomEvent("yt-rendererstamper-finished", {
  4632. // bubbles: !0,
  4633. // cancelable: !1,
  4634. // composed: !0,
  4635. // detail: {
  4636. // container
  4637. // }
  4638. // });
  4639. // hostElement.dispatchEvent(evt);
  4640. // };
  4641.  
  4642. // let f1, f2;
  4643. // f1 = async () => {
  4644. // await new Promise(r => nextBrowserTick_(r));
  4645. // if (t892 !== this[`__0fs892::${containerId}__`]) return;
  4646. // // await new Promise(r=>setTimeout(r, 1000));
  4647.  
  4648. // // if (this.data !== data || this.__data !== __data) return;
  4649.  
  4650. // const domShellElementCountCurrent = domShell.childElementCount;
  4651. // if (domShellElementCountCurrent !== domShellElementCount) return;
  4652. // if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
  4653. // return;
  4654. // }
  4655. // // const t1 = performance.now();
  4656.  
  4657. // if (DO_createStampDomArrayFnE1_nativeAppendD) {
  4658. // let elm;
  4659. // while (elm = noscript.firstChild) {
  4660. // nativeAppendD.call(gFragment, elm); // no attached / detached
  4661. // }
  4662. // } else {
  4663. // let elm;
  4664. // while (elm = noscript.firstChild) {
  4665. // gFragment.appendChild(elm);
  4666. // }
  4667. // }
  4668. // // const t2 = performance.now();
  4669.  
  4670. // // console.log('createStampDomArrayFn_{T2}', t2-t1);
  4671.  
  4672. // // nextBrowserTick_(f2);
  4673. // return true;
  4674. // };
  4675.  
  4676. // f2 = async () => {
  4677. // await new Promise(r => nextBrowserTick_(r));
  4678. // if (t892 !== this[`__0fs892::${containerId}__`]) return;
  4679. // // if (this.data !== data || this.__data !== __data) return;
  4680.  
  4681. // const domShellElementCountCurrent = domShell.childElementCount;
  4682. // if (domShellElementCountCurrent !== domShellElementCount) return;
  4683. // if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
  4684. // return;
  4685. // }
  4686.  
  4687. // domShell.appendChild(gFragment);
  4688. // this.flushRenderStamperComponentBindings_();
  4689. // this.markDirty && this.markDirty();
  4690.  
  4691. // if (shouldTriggerRendererStamperFinished) {
  4692. // nextBrowserTick_(fnE);
  4693. // }
  4694.  
  4695. // return true;
  4696.  
  4697. // };
  4698.  
  4699. // const r1 = await f1();
  4700. // if (r1 === true) {
  4701. // const r2 = await f2();
  4702. // }
  4703.  
  4704.  
  4705. // } catch (err) {
  4706.  
  4707. // console.warn(err);
  4708.  
  4709. // } finally {
  4710. // //
  4711. // }
  4712.  
  4713. // }).catch(() => 0);
  4714.  
  4715.  
  4716. // };
  4717.  
  4718.  
  4719. // const stampIdxSb = Symbol();
  4720. // const byPassIs55 = new Set(['ytd-rich-grid-renderer', 'ytd-rich-item-renderer', 'ytd-rich-grid-media', 'ytd-rich-section-renderer', 'ytd-rich-shelf-renderer']); // some issues for the view model
  4721. // const byPassIs55 = new Set(['ytd-rich-grid-renderer', 'ytd-rich-shelf-renderer']);
  4722. // const byPassIs55 = new Set([
  4723. // 'ytd-rich-grid-renderer', 'ytd-rich-shelf-renderer', // avoid disappearing of video/short entries
  4724. // 'ytd-unified-share-panel-renderer', 'yt-third-party-share-target-section-renderer', 'ytd-add-to-playlist-renderer', // avoid share-panel being non-central
  4725. // 'ytd-continuation-item-renderer', 'tp-yt-paper-spinner',
  4726. // 'ytd-multi-page-menu-renderer', 'yt-multi-page-menu-section-renderer'
  4727. // ]);
  4728. // const byPassB55 = new Set(['continuations']);
  4729. // const byPassB55 = new Set(['flexible-item-buttons', 'continuations', 'header', 'sections']);
  4730.  
  4731. // let stampContainer = null;
  4732. // const requestDomApiObject = { getStampContainer_: () => stampContainer };
  4733. // const requestDomApiProxy = new Proxy(requestDomApiObject, {
  4734. // get(target, prop, receiver) {
  4735. // if (prop === 'getStampContainer_') return target[prop];
  4736. // throw new Error("requestDomApiProxyGet");
  4737. // },
  4738. // set(target, prop, value, receiver) {
  4739. // throw new Error("requestDomApiProxySet");
  4740. // }
  4741. // });
  4742. // const fulfillment2Set = new Set([
  4743. // 'ytd-watch-next-secondary-results-renderer.items',
  4744. // 'yt-related-chip-cloud-renderer.content',
  4745. // 'yt-chip-cloud-renderer.chips',
  4746. // // 'ytd-section-list-renderer.contents', // affect loading of https://www.youtube.com/feed/history
  4747. // 'ytd-engagement-panel-section-list-renderer.content',
  4748. // 'ytd-engagement-panel-section-list-renderer.header',
  4749. // 'ytd-video-description-infocards-section-renderer.items',
  4750. // 'yt-clip-creation-renderer.title-input',
  4751. // 'yt-clip-creation-renderer.scrubber',
  4752. // 'ytd-watch-flexy.info-contents',
  4753. // 'ytd-video-primary-info-renderer.menu',
  4754. // 'ytd-menu-renderer.flexible-item-buttons',
  4755. // 'ytd-metadata-row-container-renderer.always-shown',
  4756. // 'ytd-subscribe-button-renderer.notification-preference-button',
  4757. // 'ytd-watch-metadata.subscribe-button',
  4758. // 'ytd-watch-metadata.teaser-carousel',
  4759. // 'ytd-structured-description-content-renderer.items',
  4760. // 'ytd-video-description-infocards-section-renderer.infocard-videos-button',
  4761. // 'ytd-video-description-infocards-section-renderer.infocard-channel-button',
  4762. // 'ytd-rich-metadata-row-renderer.contents',
  4763. // 'ytd-subscribe-button-renderer.notification-preference-button',
  4764. // 'ytd-watch-flexy.panels',
  4765. // // yt-live-chat
  4766. // 'yt-live-chat-renderer.input-panel',
  4767. // 'yt-live-chat-app.contents',
  4768. // 'yt-live-chat-message-input-renderer.picker-buttons',
  4769. // 'yt-live-chat-message-input-renderer.pickers',
  4770. // 'yt-live-chat-message-input-renderer.emoji-picker-button',
  4771. // 'yt-live-chat-product-picker-panel-view-model.items',
  4772. // 'yt-live-chat-message-input-renderer.send-button',
  4773. // 'yt-live-chat-renderer.continuations',
  4774. // // 'yt-live-chat-renderer.item-list', // affect yt live chat message init
  4775. // 'yt-live-chat-renderer.ticker'
  4776. // ]);
  4777.  
  4778. const __refreshData938o__ = {};
  4779. const __refreshData938__ = function (prop, opt) {
  4780. const d = this[prop];
  4781. if (d) {
  4782. this._setPendingProperty(prop, __refreshData938o__, opt);
  4783. this._setPendingProperty(prop, d, opt);
  4784. this._invalidateProperties();
  4785. }
  4786. };
  4787.  
  4788. // const pendingStampFlushs = [];
  4789.  
  4790. const nativeNow = performance.constructor.prototype.now.bind(performance);
  4791.  
  4792. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  4793.  
  4794. const executeTaskBatch = function (taskArr, firstMarco = true) {
  4795. if (!(taskArr || 0).length) throw new TypeError(`Illegal invocation`);
  4796. return new Promise(resolveFinal => {
  4797. let resolveFn = null;
  4798. const len = taskArr.length;
  4799. const results = new Array(len);
  4800. const makePromise = () => new Promise(resolve => { resolveFn = resolve });
  4801. let firedCount = 0;
  4802. const executor = () => {
  4803. if (taskArr.length !== len) throw new TypeError(`Illegal invocation`);
  4804. const resolveFn_ = resolveFn;
  4805. let t0 = 0;
  4806. let next = 0;
  4807. taskArr.forEach((task, idx) => {
  4808. if (typeof (task || 0) !== 'object') throw new TypeError(`Illegal invocation`);
  4809. if (!task.fired) {
  4810. queueMicrotask_(() => {
  4811. if (next || task.fired) return;
  4812. task.fired = true;
  4813. const { fn } = task;
  4814. task.fn = null;
  4815. if (++firedCount === len) next |= 2;
  4816. if (!t0) t0 = nativeNow() + 10;
  4817. results[idx] = fn(task); // sync task only
  4818. if (nativeNow() > t0) next |= 1;
  4819. });
  4820. }
  4821. });
  4822. queueMicrotask_(() => resolveFn_(next))
  4823. }
  4824. const looper = (next) => {
  4825. if (!next) throw new TypeError(`Illegal invocation`);
  4826. if (next & 2) {
  4827. taskArr.length = 0;
  4828. if (next & 1) {
  4829. nextBrowserTick_(() => resolveFinal(results))
  4830. } else {
  4831. resolveFinal(results);
  4832. }
  4833. } else {
  4834. const p = makePromise();
  4835. nextBrowserTick_(executor);
  4836. p.then(looper);
  4837. }
  4838. }
  4839. const p = makePromise();
  4840. firstMarco ? nextBrowserTick_(executor) : executor();
  4841. p.then(looper);
  4842.  
  4843. })
  4844.  
  4845. }
  4846.  
  4847.  
  4848. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  4849.  
  4850.  
  4851. // const globalPromiseStack = {};
  4852.  
  4853. // let dummy;
  4854. // while(!dummy){
  4855.  
  4856. // dummy = document.querySelector('yt-icon');
  4857. // await new Promise(r=>setTimeout(r,0));
  4858. // }
  4859.  
  4860. dummy = document.createElement('yt-icon');
  4861.  
  4862. let cProto;
  4863. if (!(dummy instanceof Element)) return;
  4864. cProto = insp(dummy).constructor.prototype;
  4865.  
  4866. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  4867. cProto.determineIconSet671 = cProto.determineIconSet;
  4868. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  4869. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  4870. cProto.getIconManager671 = cProto.getIconManager;
  4871. cProto.getIconShapeData671 = cProto.getIconShapeData;
  4872. cProto.renderIcon671 = cProto.renderIcon;
  4873.  
  4874. // cProto.attached488 = cProto.attached;
  4875. // cProto.attached = function(){
  4876. // console.log('attached')
  4877. // return this.attached488(...arguments);
  4878. // }
  4879. // cProto.detached488 = cProto.detached;
  4880. // cProto.detached = function(){
  4881. // console.log('detached')
  4882. // return this.detached488(...arguments);
  4883. // }
  4884.  
  4885. if(cProto.__renderIconFix__) return;
  4886. cProto.__renderIconFix__ = true;
  4887.  
  4888. let taskStack = [];
  4889. const cmObs = new MutationObserver(()=>{
  4890. const tasks = taskStack.slice();
  4891. taskStack.length = 0;
  4892. for(const task of tasks){
  4893. task();
  4894. }
  4895. })
  4896. const cm = document.createComment('1');
  4897. const stackTask = (f) => {
  4898. taskStack.push(f);
  4899. cm.data = `${(cm.data & 7) + 1}`;
  4900. }
  4901. cmObs.observe(cm, { characterData: true });
  4902.  
  4903. // let iconManagers = {}; // assume shared
  4904.  
  4905. // window.iconManagers = () => iconManagers;
  4906.  
  4907.  
  4908. const setupYtIcon = (inst) => {
  4909.  
  4910. if (inst.__ytIconSetup588__) return;
  4911. const cProto = Reflect.getPrototypeOf(inst);
  4912. cProto.__ytIconSetup588__ = true;
  4913.  
  4914.  
  4915. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4916.  
  4917. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  4918. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  4919. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  4920. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  4921.  
  4922.  
  4923. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  4924. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  4925. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  4926. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  4927.  
  4928.  
  4929.  
  4930. }
  4931.  
  4932. cProto.handlePropertyChange = function (...a) { // 10+
  4933.  
  4934. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4935. // string bool=false bool int=24 (empty string?) bool? bool
  4936. // undefined bool=false bool int bool? true
  4937.  
  4938.  
  4939. // if(typeof a[0]==='string'&& typeof (a[1]||false)==='boolean' && typeof a[2]==='boolean' && typeof a[3] === 'number'){
  4940.  
  4941. // if(a[0].)
  4942. // this.determineIconSet()
  4943.  
  4944. // }
  4945.  
  4946. // const lastData = this.__lastData__;
  4947. // let newData = '';
  4948. this.__resolved__ = {
  4949.  
  4950. };
  4951.  
  4952. // let chAction = null;
  4953.  
  4954. // let returnNone = false;
  4955.  
  4956. // // w.nextAddress ...
  4957. // if(typeof a[0] === 'string' && a[0].length > 9 && a[1]===false && a[2] ===false && a[3]===24 && a[5] === true && a[0].length >= 3){
  4958.  
  4959. // console.log(12398, this.icon, this.iconsetName, this.iconType)
  4960. // if(this.icon === a[0] && this.icon === `${this.iconsetName}:${this.iconType}` && this.iconType && this.iconsetName && typeof this.targetContainer === 'string'){
  4961.  
  4962. // console.log(12399)
  4963. // newData = `renderIcon_${this.targetContainer}_${this.icon}`;
  4964. // chAction = ()=>{
  4965. // this.renderIcon(this.targetContainer, this.icon);
  4966. // console.log('yt-icon.xxs')
  4967. // }
  4968.  
  4969. // returnNone = true;
  4970.  
  4971. // }
  4972. // }
  4973.  
  4974.  
  4975. // if(!newData) newData = `x${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  4976.  
  4977. // if (lastData !== newData) {
  4978. // this.__lastData__ = newData;
  4979.  
  4980. // if (chAction && newData.startsWith('renderIcon_')) {
  4981. // stackTask(chAction);
  4982. // }
  4983.  
  4984. // }
  4985. const a01 = this.isAttached;
  4986. let a02, a03;
  4987.  
  4988.  
  4989. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  4990.  
  4991. const stackFn = () => {
  4992. if (t !== this.__stackedKey3818__) {
  4993. return;
  4994. }
  4995. a03 = this.isAttached;
  4996.  
  4997. // if(!a02 && !a03){
  4998.  
  4999. // }
  5000.  
  5001. if (a01 === false && a02 === false && a03 === false) return;
  5002.  
  5003. if (a01 === true && a02 === true && a03 === true) {
  5004.  
  5005. } else {
  5006. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  5007. // unknown yt-icon#label-icon
  5008. return;
  5009. } else {
  5010. console.log('[yt-icon] debug', a01, a02, a03, this)
  5011. }
  5012. }
  5013.  
  5014. this.handlePropertyChange671(...arguments);
  5015.  
  5016. };
  5017.  
  5018.  
  5019.  
  5020. Promise.resolve().then(() => {
  5021. a02 = this.isAttached;
  5022. stackTask(stackFn);
  5023. });
  5024.  
  5025.  
  5026.  
  5027.  
  5028.  
  5029. // console.log('yt-icon.handlePropertyChange', ...arguments);
  5030.  
  5031. // if(returnNone) return;
  5032. // return this.handlePropertyChange671(...arguments);
  5033. }
  5034.  
  5035. cProto.determineIconSet = function (a, b, c, d) { // 10-
  5036.  
  5037. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5038. // string bool? bool=false int=24
  5039. // NOTIFICATIONS_NONE OR LIKE
  5040. // console.log('yt-icon.determineIconSet', ...arguments);
  5041.  
  5042. const r = this.determineIconSet671(...arguments);
  5043. // if(r.then){
  5044. // r.then((result)=>{
  5045. // console.log('yt-icon.determineIconSet.result = ', result)
  5046. // })
  5047. // }
  5048. return r;
  5049. }
  5050.  
  5051. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  5052.  
  5053. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5054. // same as determineIconSet
  5055. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  5056. return this.switchToYtSysIconset671(...arguments);
  5057. }
  5058.  
  5059. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  5060.  
  5061. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5062. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  5063. return this.useYtSysIconsetForMissingIcons671(...arguments);
  5064. }
  5065.  
  5066. cProto.getIconManager = function () { // 10+
  5067.  
  5068. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5069. // no argument
  5070.  
  5071. // if(this.iconsetName && this.iconType){
  5072. // const p = kRef(iconManagers[this.iconsetName]);
  5073. // if(p) return p;
  5074. // }
  5075. // console.log(2388, this.iconType)
  5076. // console.log('yt-icon.getIconManager', ...arguments);
  5077. if (!this.__resolved__) this.__resolved__ = {};
  5078. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  5079. const r = this.__resolved__.getIconManager;
  5080. // if(r.then){
  5081. // r.then((result)=>{
  5082. // iconManagers[this.iconsetName] = mWeakRef(result);
  5083. // console.log('yt-icon.getIconManager.result = ', result)
  5084. // })
  5085. // }
  5086. return r;
  5087. }
  5088.  
  5089. cProto.getIconShapeData = function () { // 10+
  5090.  
  5091. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5092.  
  5093. // let rr;
  5094. // if (typeof (this.iconType || 0) === 'string' && typeof (this.iconsetName || 0) === 'string' && this.icon === `${this.iconsetName}:${this.iconType}` && (+this.size >= 1)) {
  5095. // const a = this;
  5096. // rr= {
  5097. // iconName: a.iconType.toLowerCase(),
  5098. // iconStyle: (a.active || a.defaultToFilled || c ? "youtube_fill" : "youtube_outline"),
  5099. // iconSize: a.size,
  5100. // iconSetName: a.iconsetName
  5101. // };
  5102.  
  5103. // }
  5104.  
  5105. // no argument
  5106. // console.log('yt-icon.getIconShapeData', ...arguments);
  5107. if (!this.__resolved__) this.__resolved__ = {};
  5108. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  5109. const r = this.__resolved__.getIconShapeData;
  5110. // if (r.then) {
  5111. // r.then((result) =>{
  5112.  
  5113. // console.log('yt-icon.getIconShapeData.result = ', result)
  5114. // console.log('yt-icon.getIconShapeData.resultxx = ', rr)
  5115. // } )
  5116. // }
  5117.  
  5118.  
  5119.  
  5120. /*
  5121.  
  5122. temp1.resolveIcon({
  5123. iconName: a.iconType.toLowerCase(),
  5124. iconStyle: (a.active || a.defaultToFilled || c ? "youtube_fill" : "youtube_outline"),
  5125. iconSize: a.size,
  5126. iconSetName: a.iconsetName
  5127. })
  5128.  
  5129. */
  5130. return r
  5131. }
  5132.  
  5133. cProto.renderIcon = function (a, b) { // X
  5134.  
  5135. if (!this.__ytIconSetup588__) setupYtIcon(this);
  5136. // "" yt-icons:xxx
  5137. // console.log('yt-icon.renderIcon', ...arguments);
  5138. return this.renderIcon671(...arguments);
  5139. }
  5140.  
  5141. });
  5142.  
  5143. // stampDomArray_
  5144. const createStampDomArrayFn_ = () => {
  5145. // if (val_kevlar_should_maintain_stable_list === null) {
  5146. // const config_ = ((window.yt || 0).config_ || 0);
  5147. // val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true;
  5148. // }
  5149.  
  5150. // if(true){
  5151.  
  5152.  
  5153. const pSpace = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5154. document.documentElement.insertAdjacentElement('beforeend', pSpace);
  5155. const pNode = document.createElement('ns-538');
  5156. pSpace.insertAdjacentElement('beforeend', pNode);
  5157.  
  5158. const pDiv = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5159. if (typeof pNode.attachShadow === 'function') {
  5160. const pShadow = pNode.attachShadow({ mode: "open" });
  5161. pShadow.replaceChildren(pDiv);
  5162. } else {
  5163. pNode.insertAdjacentElement('beforeend', pDiv);
  5164. }
  5165.  
  5166. const pDivTempRemoval = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5167. pDiv.insertAdjacentElement('beforeend', pDivTempRemoval);
  5168. pDivTempRemoval.setAttribute('attm', 'pDivTempRemoval');
  5169.  
  5170. const pDivDeletion = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5171. pDiv.insertAdjacentElement('beforeend', pDivDeletion);
  5172. pDivDeletion.setAttribute('attm', 'pDivDeletion');
  5173. const pDivKeep = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5174. pDiv.insertAdjacentElement('beforeend', pDivKeep);
  5175. pDivKeep.setAttribute('attm', 'pDivKeep');
  5176.  
  5177.  
  5178. const pDivDeletionObs = new MutationObserver(() => {
  5179. let node = pDivDeletion.firstElementChild;
  5180. while (node) {
  5181. let nextNode = node.nextElementSibling;
  5182. if (node.__delayRemoved__) {
  5183. removeTNode_(node)
  5184. // } else {
  5185. // node.remove();
  5186. }
  5187. node = nextNode;
  5188. }
  5189. if (pDivDeletion.firstChild) pDivDeletion.textContent = '';
  5190. });
  5191. pDivDeletionObs.observe(pDivDeletion, { childList: true, subtree: false });
  5192.  
  5193. // const URa = function (a, b) {
  5194. // for (var c in a)
  5195. // if (a.hasOwnProperty(c) && b[c])
  5196. // return c;
  5197. // return null
  5198. // }
  5199.  
  5200. const syta = Symbol(); // container uid
  5201. // const sytb = Symbol();
  5202. const sytc = Symbol(); // data & parent relationship
  5203. const sytd = Symbol(); // bind data and component (in case not .data relationship -- to be reviewed)
  5204. const syte = Symbol(); // data uid
  5205.  
  5206. // const tmpElementNode = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5207.  
  5208. let fallbackToDefault00 = false; // full by-pass mode enabled as incorrect calling was found
  5209.  
  5210. const attributeMutationObserver = new MutationObserver((mutations) => {
  5211. const targets = new Set();
  5212. for (const mutation of mutations) {
  5213. targets.add(mutation.target);
  5214. }
  5215. for (const container of targets) {
  5216. const tag = container.__closestYtTag388__;
  5217. if (tag) {
  5218. const hostElement = container.closest(tag);
  5219. if (hostElement && hostElement.is === tag) {
  5220. const detail = {
  5221. container
  5222. };
  5223. hostElement.dispatchEvent(new CustomEvent("yt-rendererstamper-finished", {
  5224. bubbles: !0,
  5225. cancelable: !1,
  5226. composed: !0,
  5227. detail
  5228. }));
  5229. detail.container = null;
  5230. }
  5231. }
  5232. }
  5233. });
  5234.  
  5235. const stamperTasksA = {};
  5236.  
  5237. const YRa = (a, b) => {
  5238. for (const c in a)
  5239. if (a.hasOwnProperty(c) && b[c])
  5240. return c;
  5241. return null
  5242. }
  5243.  
  5244. // let lastClickX33 = 0;
  5245. // let minusX33 = 0;
  5246. // document.addEventListener('pointerdown', ()=>{
  5247. // nextBrowserTick_(()=>{
  5248. // minusX33 = 10000;
  5249. // });
  5250. // minusX33 = 0;
  5251. // lastClickX33 = Date.now();
  5252. // },true);
  5253. // document.addEventListener('keydown', ()=>{
  5254. // nextBrowserTick_(()=>{
  5255. // minusX33 = 10000;
  5256. // });
  5257. // minusX33 = 0;
  5258. // lastClickX33 = Date.now();
  5259. // },true);
  5260. // document.addEventListener('keyup', ()=>{
  5261. // nextBrowserTick_(()=>{
  5262. // minusX33 = 10000;
  5263. // });
  5264. // minusX33 = 0;
  5265. // lastClickX33 = Date.now();
  5266. // },true);
  5267. // document.addEventListener('pointerup', ()=>{
  5268. // nextBrowserTick_(()=>{
  5269. // minusX33 = 10000;
  5270. // });
  5271. // minusX33 = 0;
  5272. // lastClickX33 = Date.now();
  5273. // },true);
  5274.  
  5275. // document.addEventListener('pointercancel', ()=>{
  5276. // nextBrowserTick_(()=>{
  5277. // minusX33 = 10000;
  5278. // });
  5279. // minusX33 = 0;
  5280. // lastClickX33 = Date.now();
  5281. // },true);
  5282.  
  5283. let pageFirstDom = '';
  5284.  
  5285. // let emComponents = new Set();
  5286. let withStampDomExx = false;
  5287.  
  5288. const DEBUG_STAMP_CHANGE = false;
  5289. const DEBUG_FINALIZATION = false;
  5290.  
  5291.  
  5292. const reuseStore = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? new Map() : null;
  5293. const registry = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? new FinalizationRegistry((heldValue) => {
  5294. DEBUG_FINALIZATION && console.log(`Object(${heldValue}) has been released`);
  5295. }) : null;
  5296.  
  5297. const registerFn = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? (node, heldValue) => {
  5298. Promise.resolve(node).then((node) => {
  5299. registry.register(node, heldValue);
  5300. });
  5301. } : () => { }
  5302.  
  5303.  
  5304. const go = function (a, b, c, d) {
  5305. d || (d = {
  5306. bubbles: !0,
  5307. cancelable: !1,
  5308. composed: !0
  5309. });
  5310. c !== null && c !== void 0 && (d.detail = c);
  5311. b = new CustomEvent(b, d);
  5312. a.dispatchEvent(b);
  5313. return b
  5314. };
  5315.  
  5316.  
  5317. const removeTNode__ = (node) => { // need trigger removal of its parent component
  5318. const xlivev = xlivec00.__domApi;
  5319. if (node.isConnected === true) {
  5320. xlivev.appendChild(node); // attached -> detached
  5321. // xlivev.removeChild(node); // detached -> detached
  5322. } else {
  5323. xlivev.appendChild(node); // detached -> detached
  5324. // xlivev.removeChild(node); // detached -> detached
  5325. }
  5326. }
  5327. // window.removeTNode__ = removeTNode__;
  5328.  
  5329. const removeTNode_ = (node) => { // need trigger removal of its parent component
  5330. const xdeadv = xdeadc00.__domApi;
  5331. removeTNodeBP = true;
  5332. // if (node.isConnected === true) {
  5333. xdeadv.appendChild(node); // attached -> detached
  5334. xdeadv.removeChild(node); // detached -> detached
  5335. // } else {
  5336. // xdeadv.appendChild(node); // detached -> detached
  5337. // xdeadv.removeChild(node); // detached -> detached
  5338. // }
  5339. removeTNodeBP = false;
  5340. }
  5341. window.removeTNode_ = removeTNode_;
  5342. removeTNodeRM = removeTNode_;
  5343.  
  5344. const removeTNode = (node) => { // need trigger removal of its parent component
  5345. const xdeadv = xdeadc00.__domApi;
  5346. if (node.isConnected === true) {
  5347. if (node.parentNode !== pDivDeletion) {
  5348. pDivDeletion.insertAdjacentHTML('afterbegin', ttpHTML('<!---->'));
  5349. pDivDeletion.lastChild.replaceWith(node); // attached -> attached
  5350. }
  5351.  
  5352. // xdeadv.appendChild(node); // attached -> detached
  5353. // xdeadv.removeChild(node); // detached -> detached
  5354.  
  5355. node.remove(); // attached -> detached
  5356. xdeadv.appendChild(node); // detached -> detached
  5357. xdeadv.removeChild(node); // detached -> detached
  5358. } else {
  5359.  
  5360. node.remove(); // detached -> detached
  5361. xdeadv.appendChild(node); // detached -> detached
  5362. xdeadv.removeChild(node); // detached -> detached
  5363.  
  5364. // xdeadv.appendChild(node); // detached -> detached
  5365. // xdeadv.removeChild(node); // detached -> detached
  5366. }
  5367. }
  5368. // window.removeTNode = removeTNode;
  5369.  
  5370.  
  5371. const removeTNodeDelayed = (node) => {
  5372. if (node.isConnected === true) {
  5373. node.__delayRemoved__ = true;
  5374. pDivDeletion.insertAdjacentHTML('afterbegin', ttpHTML('<!---->'));
  5375. pDivDeletion.lastChild.replaceWith(node); // attached -> attached
  5376. } else {
  5377. const xdeadv = xdeadc00.__domApi;
  5378. xdeadv.appendChild(node); // detached -> detached
  5379. xdeadv.removeChild(node); // detached -> detached
  5380. }
  5381. }
  5382. // window.removeTNodeDelayed = removeTNodeDelayed;
  5383.  
  5384. let config00 = null;
  5385.  
  5386. let appendFrag00 = null;
  5387.  
  5388. const safeAppend = function (items, containerId, componentConfig, bEventCallback, removeExisting, finishState) {
  5389.  
  5390. const config = config00;
  5391. const appendFrag = appendFrag00;
  5392. let err, result;
  5393.  
  5394.  
  5395. const qv1 = config.DEFERRED_DETACH;
  5396. const qv2 = config.REUSE_COMPONENTS;
  5397. const qv3 = config.STAMPER_STABLE_LIST;
  5398. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5399. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5400. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5401.  
  5402.  
  5403. try {
  5404. if (removeExisting) this.stampDomArray9682_(null, containerId, null, false, null, null);
  5405. const c = componentConfig;
  5406. const k = this.getStampContainer_(containerId);
  5407. const b = k.__domApi || k;
  5408. /*
  5409. const g = document.createDocumentFragment();
  5410. let r;
  5411. for(let i = 0, l =items.length; i<l;i++){
  5412. const u = items[i];
  5413. const w = YRa(c, u);
  5414. if (w) {
  5415. r = this.createComponent_(c[w], u[w], false);
  5416. this.deferRenderStamperBinding_(r, c[w], u[w]);
  5417. g.appendChild(r);
  5418. }
  5419. }
  5420. b.appendChild(g)
  5421. */
  5422.  
  5423. const g = appendFrag00 || (appendFrag00 = document.createDocumentFragment());
  5424. let r;
  5425. for (let i = 0, l = items.length; i < l; i++) {
  5426. const u = items[i];
  5427. const w = YRa(c, u);
  5428. if (w) {
  5429. r = this.createComponent_(c[w], u[w], false);
  5430. this.deferRenderStamperBinding_(r, c[w], u[w]);
  5431. g.appendChild(r);
  5432. }
  5433. }
  5434. b.appendChild(g)
  5435.  
  5436. if (finishState & 1) {
  5437. this.flushRenderStamperComponentBindings_();
  5438. }
  5439. if (finishState & 2) {
  5440. this.markDirty && this.markDirty();
  5441. }
  5442. if (finishState & 4) {
  5443. bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  5444. container: k
  5445. });
  5446. }
  5447. } catch (e) {
  5448. err = e;
  5449. }
  5450.  
  5451. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5452. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5453. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5454.  
  5455. if (err) throw err;
  5456.  
  5457. return result;
  5458.  
  5459.  
  5460. };
  5461.  
  5462.  
  5463. const safeFinish = function (containerId, bEventCallback) {
  5464.  
  5465. const config = config00;
  5466. let err, result;
  5467.  
  5468.  
  5469. const qv1 = config.DEFERRED_DETACH;
  5470. const qv2 = config.REUSE_COMPONENTS;
  5471. const qv3 = config.STAMPER_STABLE_LIST;
  5472. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5473. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5474. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5475.  
  5476.  
  5477. try {
  5478. const k = this.getStampContainer_(containerId);
  5479.  
  5480. this.flushRenderStamperComponentBindings_();
  5481. this.markDirty && this.markDirty();
  5482. bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  5483. container: k
  5484. });
  5485.  
  5486. } catch (e) {
  5487. err = e;
  5488. }
  5489.  
  5490. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5491. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5492. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5493.  
  5494. if (err) throw err;
  5495.  
  5496. return result;
  5497.  
  5498.  
  5499. };
  5500.  
  5501.  
  5502. const reuseRefreshMode = 1;
  5503.  
  5504. const setupComponent = function (data, component, containerElement, refNode, deferredBindingTask, reused = false) {
  5505.  
  5506. let noRenderTaskForResuedComponent = false;
  5507. if (component instanceof Node) {
  5508.  
  5509.  
  5510. if (data && data[syte]) {
  5511. // component[sytb] = data[sytb]
  5512. component[sytc] = data[sytc]
  5513. component[syte] = data[syte];
  5514. // containerElement[sytd].set(data, mWeakRef(component));
  5515. containerElement[sytd].set(component, mWeakRef(data));
  5516. if(reuseStore) reuseStore.set(data[syte], mWeakRef(component));
  5517. }
  5518.  
  5519. const cnt = insp(component);
  5520.  
  5521. if (reused && reuseRefreshMode >= 1 && cnt.data) {
  5522. if (!cnt.__refreshData938__) {
  5523. const cProto = Reflect.getPrototypeOf(cnt);
  5524. cProto.__refreshData938__ = __refreshData938__;
  5525. }
  5526. try {
  5527. cnt.__refreshData938__('data', !0);
  5528. if(reuseRefreshMode >= 2) noRenderTaskForResuedComponent = true;
  5529. } catch (e) {
  5530. }
  5531. }
  5532.  
  5533. if (refNode !== undefined) {
  5534. const componentX = component;
  5535. if (componentX instanceof Node) {
  5536. if (refNode !== componentX) {
  5537. if (!refNode) {
  5538. containerElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  5539. containerElement.lastChild.replaceWith(componentX);
  5540. } else {
  5541. refNode.insertAdjacentHTML('beforebegin', ttpHTML('<!---->'));
  5542. refNode.previousSibling.replaceWith(componentX);
  5543. }
  5544. }
  5545. }
  5546.  
  5547. }
  5548.  
  5549. if (noRenderTaskForResuedComponent) {
  5550.  
  5551. } else if (deferredBindingTask && deferredBindingTask.typeOrConfig) {
  5552. this.deferredBindingTasks_.push(deferredBindingTask);
  5553. this.flushRenderStamperComponentBindings_();
  5554. if (this.deferredBindingTasks_.length >= 1) this.deferredBindingTasks_.length = 0;
  5555. }
  5556.  
  5557. return true;
  5558.  
  5559. }
  5560. return false;
  5561.  
  5562. }
  5563.  
  5564.  
  5565. let triggerCountWithinMicro = 0;
  5566.  
  5567. let firstExecuted = false;
  5568.  
  5569. const gn = function (items__, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList) {
  5570. const config = config00 || (config00 = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0));
  5571. if (!firstExecuted) {
  5572. firstExecuted = true;
  5573. if (!xdeadc00) setupXdeadC(this);
  5574. if (FORCE_NO_REUSEABLE_ELEMENT_POOL && typeof this.createComponent_ === 'function' && this.createComponent_.length === 3) {
  5575. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(this);
  5576. }
  5577. }
  5578.  
  5579.  
  5580. let useSyncE = false; // essential components
  5581. let disableTaskSkip = false;
  5582.  
  5583. triggerCountWithinMicro++;
  5584. const triggerCountWithinMicro_ = triggerCountWithinMicro;
  5585. Promise.resolve().then(() => {
  5586. triggerCountWithinMicro--;
  5587. });
  5588.  
  5589. // const stack = new Error().stack;
  5590.  
  5591.  
  5592. if (!this.__rendererStamperConfig5422__) {
  5593. const cProto = Reflect.getPrototypeOf(this);
  5594. cProto.__rendererStamperConfig5422__ = 1;
  5595. if (!cProto.__safeAppend8382__) cProto.__safeAppend8382__ = safeAppend;
  5596. if (!cProto.__safeFinish8382__) cProto.__safeFinish8382__ = safeFinish;
  5597. if (!cProto.__setupComponent8382__) cProto.__setupComponent8382__ = setupComponent;
  5598. }
  5599.  
  5600. const stamperTasksKey = `${this.is}::${containerId}`;
  5601. const stamperTasks = stamperTasksA[stamperTasksKey] || (stamperTasksA[stamperTasksKey] = []);
  5602.  
  5603. let renderJob = this.renderJobsMap_ && containerId ? this.renderJobsMap_[containerId] : null;
  5604. const items_ = items__;
  5605. const hasRunningTasks = stamperTasks.length >= 1;
  5606. const container = typeof this.getStampContainer_ === 'function' ? this.getStampContainer_(containerId) : (this.$ || 0)[containerId];
  5607.  
  5608. let fallbackToDefault = fallbackToDefault00;
  5609. if (!config) {
  5610. console.warn('stampDomArray_ fallback: no config');
  5611. fallbackToDefault = fallbackToDefault00 = true;
  5612. } else if (!this.deferredBindingTasks_ || this.deferredBindingTasks_.length !== 0) {
  5613. console.warn('stampDomArray_ fallback: no deferredBindingTasks_');
  5614. fallbackToDefault = fallbackToDefault00 = true;
  5615. } else if (!container) {
  5616. console.warn('stampDomArray_ fallback: no container');
  5617. fallbackToDefault = fallbackToDefault00 = true;
  5618. } else {
  5619. if (container.__xnHookE93__ !== null) {
  5620. if (container.firstElementChild !== null) {
  5621. if (!container.__xnHookE93__) container.__xnHookE93__ = new Set();
  5622. container.__xnHookE93__.add(containerId);
  5623. } else if (container.__xnHookE93__) {
  5624. container.__xnHookE93__.delete(containerId);
  5625. if (container.__xnHookE93__.size === 0) {
  5626. container.__xnHookE93__ = null;
  5627. }
  5628. } else {
  5629. container.__xnHookE93__ = null;
  5630. }
  5631. if (container.__xnHookE93__ !== null) {
  5632. fallbackToDefault = true; // skip handling weird element. wait until container become clean
  5633. } else {
  5634. container.__xnHookE93__ = null;
  5635. try {
  5636. this.stampDomArray9682_(null, containerId, null, false, false, false); // bind the yt dom api
  5637. } catch (e) { }
  5638. if (container.__domApi && !container.__domApi.__daHook377__) {
  5639. setupDomApi(Reflect.getPrototypeOf(container.__domApi));
  5640. setupSDomWrapper();
  5641. }
  5642. }
  5643. }
  5644. }
  5645.  
  5646. if (fallbackToDefault) {
  5647. return this.stampDomArray9682_(...arguments);
  5648. }
  5649.  
  5650.  
  5651. const bStableListA = bStableList !== undefined ? Boolean(bStableList) : (typeof config.STAMPER_STABLE_LIST !== "undefined" ? !!config.STAMPER_STABLE_LIST : false);
  5652.  
  5653. const containerDomApi = (container || 0).__domApi || container;
  5654. const containerElement = containerDomApi instanceof Node ? containerDomApi : insp(container).hostElement instanceof Node ? insp(container).hostElement : container;
  5655.  
  5656. const keyRequireAsync = `__stamperRequireAsync#${containerId}__`;
  5657. const key5993 = `__stamperCounter5993#${containerId}__`;
  5658. const key5996 = `__stamperCounter5996#${containerId}__`;
  5659. // const keyOnSync = `__stamperOnSync#${containerId}__`;
  5660.  
  5661.  
  5662.  
  5663. let hasKey = false;
  5664. if (items_ && items_.length >= 1) {
  5665.  
  5666. hasKey = items_.some((v) => (typeof YRa(componentConfig, v) === 'string'));
  5667.  
  5668. }
  5669.  
  5670. if (bEventCallback) {
  5671. if (!container.__rendererStamperEventCallback388__) {
  5672. container.__rendererStamperEventCallback388__ = true;
  5673. container.__closestYtTag388__ = this.is;
  5674. attributeMutationObserver.observe(container, { attributes: ['ytxx-stamper-finished'] });
  5675. }
  5676. }
  5677.  
  5678.  
  5679. if (!this.__rendererStamperFinishFn588__) {
  5680. this.__rendererStamperFinishFn588__ = () => {
  5681. if (this.deferredBindingTasks_ && this.deferredBindingTasks_.length >= 1) {
  5682. this.flushRenderStamperComponentBindings_();
  5683. }
  5684. this.markDirty && this.markDirty();
  5685. };
  5686.  
  5687. }
  5688.  
  5689.  
  5690.  
  5691.  
  5692. const items = hasKey ? items_.slice() : []; // avoid memory leakge
  5693.  
  5694. this[key5993] = (this[key5993] & 1073741823) + 1;
  5695.  
  5696. let leaveWithNoChange = false;
  5697.  
  5698.  
  5699. if (!hasRunningTasks && !this[keyRequireAsync]) {
  5700. if (!pageFirstDom) { // initial stamp action
  5701. pageFirstDom = this.is;
  5702. useSyncE = true;
  5703. this.__stampDomExx__ = true;
  5704. } else if (this.__stampDomExx__) { // essential component
  5705. useSyncE = true;
  5706. } else if (!withStampDomExx) { // not ready
  5707. useSyncE = true;
  5708. } else if (triggerCountWithinMicro_ === 1) { // first stamp action (user action)
  5709. useSyncE = true;
  5710. }
  5711. if (!hasKey) { // noChange
  5712. leaveWithNoChange = true;
  5713. useSyncE = true;
  5714. }
  5715. }
  5716.  
  5717. const useSync_ = useSyncE;
  5718. const tryBatchUpdate_ = !useSync_ && (renderJob || hasRunningTasks || this[keyRequireAsync]);
  5719.  
  5720. const skey = stamperTasks.__skey__ = `${Date.now()}`;
  5721.  
  5722. let taskFinish = false;
  5723.  
  5724. let result;
  5725.  
  5726. let skipToNextTask = false;
  5727.  
  5728. stamperTasks.push(() => {
  5729. if (skey !== stamperTasks.__skey__ && !disableTaskSkip) {
  5730. skipToNextTask = true;
  5731. // taskFinish = true;
  5732. }
  5733. });
  5734.  
  5735. if (leaveWithNoChange) {
  5736. if (container.__rendererStamperEventCallback388__) {
  5737. stamperTasks.push(() => {
  5738. if (taskFinish) return;
  5739. if(skipToNextTask) return;
  5740. if (container.__rendererStamperEventCallback388__) {
  5741. taskFinish = true;
  5742. container.setAttribute('ytxx-stamper-finished', (container.getAttribute('ytxx-stamper-finished') & 7) + 1);
  5743. return;
  5744. }
  5745. });
  5746. }
  5747. } else {
  5748.  
  5749. this[key5996] = (this[key5996] & 1073741823) + 1;
  5750. }
  5751.  
  5752. // this[key5996] = (this[key5996] & 1073741823) + 1;
  5753.  
  5754.  
  5755.  
  5756.  
  5757.  
  5758. containerElement[syta] = containerElement[syta] || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  5759. containerElement[sytd] = containerElement[sytd] || new WeakMap();
  5760.  
  5761. const mkData = new Set();
  5762.  
  5763. const pneItems = items.map(eq => {
  5764. const dataKey = firstObjectKey(eq);
  5765. const dataKey2 = YRa(componentConfig, eq)
  5766. if (dataKey && dataKey2 === dataKey) {
  5767. const targetComponentName = this.getComponentName_(componentConfig[dataKey], eq[dataKey]);
  5768. const data = eq[dataKey];
  5769. // if (data) data[sytb] = (data[sytb] & 1073741823) + 1;
  5770. if (data) {
  5771. data[syte] = data[syte] || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  5772. const arr = new Set((data[sytc] || '').split(','));
  5773. arr.delete('');
  5774. arr.add(containerElement[syta]);
  5775. data[sytc] = [...arr].join(',');
  5776. // addData.add(data);
  5777. mkData.add(data[syte]);
  5778. const dte = data[syte];
  5779. return {
  5780. targetComponentName,
  5781. dataKey,
  5782. data,
  5783. item: eq,
  5784. dte
  5785. }
  5786. }
  5787. }
  5788. return {
  5789. data: void 0,
  5790. item: eq,
  5791. dte: ''
  5792. };
  5793. }).filter(e=>!!e.dte);
  5794.  
  5795.  
  5796. let elementIter = containerElement.firstElementChild;
  5797. const uneElements = !elementIter ? [] : new Array(containerElement.childElementCount);
  5798. for (let i = 0, l = uneElements.length; i < l; i++) {
  5799. const pageElement = elementIter;
  5800. if (!pageElement) {
  5801. uneElements.length = i;
  5802. break;
  5803. }
  5804. const pageElementData = kRef(containerElement[sytd].get(pageElement));
  5805. const dte_ = pageElement[syte];
  5806. const dte = pageElementData && dte_ && pageElementData[syte] === dte_ && (insp(pageElement).data || 0)[syte] === dte_ ? dte_ : '';
  5807.  
  5808. uneElements[i] = {
  5809. pageElement: pageElement,
  5810. pageElementData: pageElementData,
  5811. dte
  5812. }
  5813. elementIter = elementIter.nextElementSibling;
  5814. }
  5815.  
  5816.  
  5817. const reuseKey = `${containerElement[syta]}**${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`
  5818.  
  5819.  
  5820.  
  5821. stamperTasks.push(() => {
  5822.  
  5823. if (taskFinish) return;
  5824. if(skipToNextTask) return;
  5825.  
  5826. // if(skipToNextTask) return;
  5827.  
  5828.  
  5829. let tryStable = null;
  5830. if (bStableListA) {
  5831. tryStable = {};
  5832.  
  5833. pneItems.forEach(pneItem => {
  5834.  
  5835.  
  5836. const { item, dte, data, dataKey, targetComponentName } = pneItem;
  5837.  
  5838.  
  5839. const q_ = reuseStore ? kRef(reuseStore.get(dte)) : null; // no rendered dom for the item
  5840.  
  5841. if (!q_) {
  5842.  
  5843. if(!tryStable[targetComponentName]) tryStable[targetComponentName] = new Set();
  5844.  
  5845. tryStable[targetComponentName].add((node)=>{
  5846.  
  5847. const component = node;
  5848. const oldDte = node[syte];
  5849. // const cnt = insp(node);
  5850. if (oldDte && oldDte !== dte && node.parentNode === containerElement && data && data[syte] && data[syte] === dte ) {
  5851.  
  5852. this.telemetry_.reuse++;
  5853.  
  5854. // console.log(123992, node, componentConfig[dataKey], data, cnt.data, oldDte, dte )
  5855.  
  5856. // play safe
  5857. // component[sytb] = null;
  5858. component[sytc] = null;
  5859. component[syte] = null;
  5860. containerElement[sytd].delete(component);
  5861. // play safe
  5862.  
  5863. if (reuseStore) reuseStore.delete(oldDte);
  5864. node[syte] = dte;
  5865. node.___reuseFor__ = reuseKey; // once only
  5866.  
  5867.  
  5868.  
  5869. // cnt.data = data;
  5870. const deferredBindingTaskX = { component: component, typeOrConfig: componentConfig[dataKey], data: data }
  5871. this.__setupComponent8382__(data, component, containerElement, undefined, deferredBindingTaskX, true);
  5872.  
  5873. // console.log(123993,'true')
  5874.  
  5875. return true;
  5876.  
  5877.  
  5878. }
  5879.  
  5880. return false;
  5881.  
  5882. });
  5883.  
  5884. }
  5885.  
  5886. })
  5887.  
  5888. }
  5889.  
  5890.  
  5891. const removes = [];
  5892.  
  5893.  
  5894. let node = containerElement.firstElementChild;
  5895. while (node !== null) {
  5896.  
  5897. const dte = node[syte];
  5898. const nextNode = node.nextElementSibling;
  5899.  
  5900.  
  5901. const tryStableCur = tryStable ? tryStable[node.is] : null;
  5902.  
  5903. if (tryStableCur && dte && !mkData.has(dte) && tryStableCur.size >= 1) {
  5904. // to be removed as no equal entry, but try to make it for tryStable
  5905.  
  5906. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  5907. const fn = tryStableCur.values().next().value;
  5908. tryStableCur.delete(fn) && fn(node);
  5909. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  5910.  
  5911. }
  5912.  
  5913. if(node.___reuseFor__ === reuseKey){
  5914.  
  5915.  
  5916. } else if (!(typeof (dte || 0) === 'string' && mkData.has(dte))) {
  5917.  
  5918. // console.log(insp(node).data);
  5919. // console.log(items)
  5920. removes.push(node);
  5921. // q30 = true;
  5922. // u.removeChild(node)
  5923. // try{
  5924. // v.removeChild(node); // just to trigger some internal removal
  5925. // }catch(e){
  5926. // }
  5927. }
  5928. node = nextNode;
  5929.  
  5930. }
  5931.  
  5932. tryStable = null;
  5933.  
  5934. if(removes.length === 0) return;
  5935.  
  5936. // let xdeadc = xdeadc00;
  5937. if (!xdeadc00) setupXdeadC(this);
  5938. // const xdeadv = xdeadc.__domApi;
  5939.  
  5940. for (const node of removes) {
  5941. removeTNode_(node);
  5942. registerFn(node, '01');
  5943. }
  5944.  
  5945. // safeClear(containerId, null, 2 | 4)
  5946.  
  5947. });
  5948.  
  5949.  
  5950. let refNode = null;
  5951. let refNodeIdx = -1;
  5952.  
  5953. const taskPerPneItem = (pneItem) => {
  5954.  
  5955.  
  5956. let reused = false;
  5957.  
  5958. const { item, dte, data, dataKey, targetComponentName } = pneItem;
  5959.  
  5960. refNode = ++refNodeIdx === 0 ? containerElement.firstElementChild : refNode && refNode.nextElementSibling;
  5961.  
  5962.  
  5963. const q_ = reuseStore ? kRef(reuseStore.get(dte)) : null;
  5964. const q = (q_ && (q_.___reuseFor__ === reuseKey || q_.closest('defs'))) ? q_ : null;
  5965.  
  5966. let deferredBindingTaskX = null;
  5967. let component = null;
  5968. if (q && q.is === targetComponentName) {
  5969.  
  5970. if (q_.closest('defs')) {
  5971.  
  5972. const node = component = q;
  5973. const cnt = insp(node);
  5974. if ('data' in cnt) cnt.data = data;
  5975. deferredBindingTaskX = { component: q, data: data }
  5976. // listX.push(deferredBindingTaskX);
  5977.  
  5978. DEBUG_STAMP_CHANGE && console.log('reuse X0')
  5979. reused = true;
  5980.  
  5981. } else {
  5982.  
  5983. const node = component = q;
  5984. const cnt = insp(node);
  5985. // cnt.data = data;
  5986. deferredBindingTaskX = { component: q, typeOrConfig: componentConfig[dataKey], data: data }
  5987. // listX.push(deferredBindingTaskX);
  5988.  
  5989. reused = true;
  5990.  
  5991. DEBUG_STAMP_CHANGE && console.log('reuse S0')
  5992.  
  5993. }
  5994.  
  5995.  
  5996.  
  5997. } else {
  5998.  
  5999. // console.log('new')
  6000.  
  6001.  
  6002. // const qf2 = this.deferRenderStamperBinding_;
  6003. // let deferredBindingTaskX = null;
  6004. this.deferRenderStamperBinding_ = function (a, b, c) {
  6005. deferredBindingTaskX = {
  6006. component: a,
  6007. typeOrConfig: b,
  6008. data: c
  6009. };
  6010. }
  6011.  
  6012. // console.log(23400, containerElement.childElementCount)
  6013. this.__safeAppend8382__([item], containerId, componentConfig, bEventCallback, false, 0 | 2 | 4);
  6014.  
  6015. // console.log(23401, containerElement.childElementCount)
  6016.  
  6017. // safeFn([item], containerId, componentConfig, false, bEventCallback, false);
  6018.  
  6019. delete this.deferRenderStamperBinding_;
  6020. // this.deferRenderStamperBinding_ = qf2;
  6021. // console.log(deferredBindingTaskX)
  6022. // listX.push(deferredBindingTaskX);
  6023.  
  6024. component = deferredBindingTaskX.component;
  6025.  
  6026. }
  6027.  
  6028.  
  6029. if (this.__setupComponent8382__(data, component, containerElement, refNode, deferredBindingTaskX, reused)) {
  6030.  
  6031. refNode = component;
  6032. }
  6033.  
  6034.  
  6035.  
  6036.  
  6037. }
  6038.  
  6039. pneItems.forEach((pneItem, idx) => {
  6040.  
  6041. stamperTasks.push(() => {
  6042. if (taskFinish) return;
  6043. if (skipToNextTask) return;
  6044.  
  6045. if (skipToNextTask) {
  6046.  
  6047. if (idx === 0) {
  6048.  
  6049. for (const pneItem of pneItems) {
  6050.  
  6051. taskPerPneItem(pneItem);
  6052. }
  6053. } else {
  6054. // skip
  6055.  
  6056. }
  6057. } else {
  6058.  
  6059.  
  6060. taskPerPneItem(pneItem);
  6061.  
  6062. }
  6063.  
  6064. });
  6065.  
  6066.  
  6067. });
  6068.  
  6069.  
  6070. stamperTasks.push(() => {
  6071. if (taskFinish) return;
  6072. if (skipToNextTask) return;
  6073. let node = refNode;
  6074. if (!node) return;
  6075. node = node.nextElementSibling;
  6076. while (node) {
  6077. let nextNode = node.nextElementSibling;
  6078. removeTNode_(node);
  6079. registerFn(node, '02');
  6080. node = nextNode;
  6081. }
  6082. });
  6083.  
  6084.  
  6085.  
  6086.  
  6087. stamperTasks.push(() => {
  6088.  
  6089.  
  6090. if (!skipToNextTask) {
  6091.  
  6092. this.__safeFinish8382__(containerId, bEventCallback);
  6093. }
  6094.  
  6095. });
  6096.  
  6097.  
  6098. this[keyRequireAsync] = (this[keyRequireAsync] || 0) + 1;
  6099.  
  6100.  
  6101. stamperTasks.push(() => {
  6102.  
  6103. if (!skipToNextTask) {
  6104.  
  6105. this.__rendererStamperFinishFn588__();
  6106. }
  6107.  
  6108. this[keyRequireAsync] = (this[keyRequireAsync] || 0) - 1;
  6109.  
  6110. });
  6111.  
  6112.  
  6113. if(!leaveWithNoChange) {
  6114. disableTaskSkip = true;
  6115.  
  6116. const tasks = stamperTasks.slice();
  6117. stamperTasks.length = 0;
  6118.  
  6119. for (const task of tasks) {
  6120. task();
  6121. }
  6122. return;
  6123. }
  6124.  
  6125. if (useSync_) {
  6126.  
  6127. disableTaskSkip = true;
  6128.  
  6129. // [[ FOR CRITICAL TASK ]]
  6130.  
  6131. // if (!this[keyOnSync]) this[keyOnSync] = 0;
  6132. // this[keyOnSync]++;
  6133.  
  6134. // const pr = marcoPr;
  6135. // console.log(2992, pr, trackMarcoCm.data)
  6136. // trackMarcoCm.data = `${(trackMarcoCm.data & 7) + 1}`;
  6137. // pr.then(() => {
  6138. // this[keyOnSync]--;
  6139. // // console.log(3992, this.is);
  6140. // });
  6141.  
  6142. const tasks = stamperTasks.slice();
  6143. stamperTasks.length = 0;
  6144.  
  6145. for (const task of tasks) {
  6146. task();
  6147. }
  6148.  
  6149. if (!withStampDomExx && useSync_ && this.is === pageFirstDom) {
  6150. // we treat the components generated by initial stampDom as important
  6151.  
  6152. for (const elm of document.getElementsByTagName('*')) {
  6153. if (elm.is) {
  6154. insp(elm).__stampDomExx__ = true;
  6155. // emComponents.add(elm.is);
  6156. }
  6157. }
  6158. withStampDomExx = true;
  6159. }
  6160.  
  6161. } else {
  6162.  
  6163. if (!hasRunningTasks) {
  6164.  
  6165. const f = () => {
  6166. if (!stamperTasks.length) return;
  6167. const tasks = stamperTasks.slice();
  6168. stamperTasks.length = 0;
  6169. executeTaskBatch(tasks.map(fn => ({ fn })), false);
  6170. }
  6171.  
  6172. if (tryBatchUpdate_) {
  6173. nextBrowserTick_(f);// collecting all tasks (after reflow)
  6174. } else {
  6175. queueMicrotask_(f); // collecting some tasks (before reflow)
  6176. }
  6177.  
  6178. }
  6179.  
  6180. }
  6181.  
  6182. return;
  6183.  
  6184.  
  6185.  
  6186.  
  6187.  
  6188. }
  6189.  
  6190. return gn;
  6191.  
  6192. };
  6193.  
  6194.  
  6195. const setupDiscreteTasks = (h, rb) => {
  6196.  
  6197.  
  6198.  
  6199. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  6200. const f = h.onYtRendererstamperFinished;
  6201. const g = ump3.get(f) || function () {
  6202. if (this.updateChildVisibilityProperties && !this.markDirty) {
  6203. return f.apply(this, arguments);
  6204. }
  6205. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6206. }
  6207. ump3.set(f, g);
  6208. g.km34 = 1;
  6209. h.onYtRendererstamperFinished = g;
  6210.  
  6211. }
  6212.  
  6213. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  6214. const f = h.onYtUpdateDescriptionAction;
  6215. const g = ump3.get(f) || function (a) {
  6216. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6217. }
  6218. ump3.set(f, g);
  6219. g.km34 = 1;
  6220. h.onYtUpdateDescriptionAction = g;
  6221.  
  6222. }
  6223.  
  6224. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  6225. const f = h.handleUpdateDescriptionAction;
  6226. const g = ump3.get(f) || function (a) {
  6227. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6228. }
  6229. ump3.set(f, g);
  6230. g.km34 = 1;
  6231. h.handleUpdateDescriptionAction = g;
  6232.  
  6233. }
  6234.  
  6235. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  6236. const f = h.handleUpdateLiveChatPollAction;
  6237. const g = ump3.get(f) || function (a) {
  6238. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6239. }
  6240. ump3.set(f, g);
  6241. g.km34 = 1;
  6242. h.handleUpdateLiveChatPollAction = g;
  6243.  
  6244. }
  6245.  
  6246. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  6247. const f = h.onTextChanged;
  6248. const g = ump3.get(f) || function () {
  6249. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6250. }
  6251. ump3.set(f, g);
  6252. g.km34 = 1;
  6253. h.onTextChanged = g;
  6254.  
  6255. }
  6256.  
  6257. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  6258. const f = h.onVideoDataChange;
  6259. const g = ump3.get(f) || function (a) {
  6260. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6261. }
  6262. ump3.set(f, g);
  6263. g.km34 = 1;
  6264. h.onVideoDataChange = g;
  6265.  
  6266. }
  6267.  
  6268. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  6269. const f = h.onVideoDataChange_;
  6270. const g = ump3.get(f) || function () {
  6271. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6272. }
  6273. ump3.set(f, g);
  6274. g.km34 = 1;
  6275. h.onVideoDataChange_ = g;
  6276.  
  6277. }
  6278.  
  6279. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  6280.  
  6281. const f = h.addTooltips_;
  6282. const g = ump3.get(f) || function () {
  6283. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6284. }
  6285. ump3.set(f, g);
  6286. g.km34 = 1;
  6287. h.addTooltips_ = g;
  6288.  
  6289. }
  6290.  
  6291. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  6292.  
  6293. const f = h.updateRenderedElements;
  6294. const g = ump3.get(f) || function () {
  6295. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6296. }
  6297. ump3.set(f, g);
  6298. g.km34 = 1;
  6299. h.updateRenderedElements = g;
  6300.  
  6301. }
  6302.  
  6303. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  6304. const f = h.loadPage_;
  6305. const g = ump3.get(f) || function (a) {
  6306. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6307. }
  6308. ump3.set(f, g);
  6309. g.km34 = 1;
  6310. h.loadPage_ = g;
  6311.  
  6312. }
  6313. // updatePageData_ : possible conflict with Omit ShadyDOM
  6314. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  6315. const f = h.updatePageData_;
  6316. const g = ump3.get(f) || function (a) {
  6317. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6318. }
  6319. ump3.set(f, g);
  6320. g.km34 = 1;
  6321. h.updatePageData_ = g;
  6322.  
  6323. }
  6324.  
  6325.  
  6326. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  6327.  
  6328. const f = h.onFocus_;
  6329. const g = ump3.get(f) || function () {
  6330. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6331. }
  6332. ump3.set(f, g);
  6333. g.km34 = 1;
  6334. h.onFocus_ = g;
  6335.  
  6336. }
  6337.  
  6338. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  6339.  
  6340. const f = h.onBlur_;
  6341. const g = ump3.get(f) || function () {
  6342. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6343. }
  6344. ump3.set(f, g);
  6345. g.km34 = 1;
  6346. h.onBlur_ = g;
  6347.  
  6348. }
  6349.  
  6350.  
  6351. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  6352.  
  6353. const f = h.buttonClassChanged_;
  6354. const g = ump3.get(f) || function (a, b) {
  6355. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6356. }
  6357. ump3.set(f, g);
  6358. g.km34 = 1;
  6359. h.buttonClassChanged_ = g;
  6360.  
  6361. }
  6362.  
  6363. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  6364.  
  6365. const f = h.buttonIconChanged_;
  6366. const g = ump3.get(f) || function (a) {
  6367. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6368. }
  6369. ump3.set(f, g);
  6370. g.km34 = 1;
  6371. h.buttonIconChanged_ = g;
  6372.  
  6373. }
  6374.  
  6375. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  6376.  
  6377. const f = h.dataChangedInBehavior_;
  6378. const g = ump3.get(f) || function () {
  6379. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6380. }
  6381. ump3.set(f, g);
  6382. g.km34 = 1;
  6383. h.dataChangedInBehavior_ = g;
  6384.  
  6385. }
  6386.  
  6387. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  6388.  
  6389. const f = h.continuationsChanged_;
  6390. const g = ump3.get(f) || function () {
  6391. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6392. }
  6393. ump3.set(f, g);
  6394. g.km34 = 1;
  6395. h.continuationsChanged_ = g;
  6396.  
  6397. }
  6398.  
  6399.  
  6400. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  6401.  
  6402. const f = h.forceChatPoll_;
  6403. const g = ump3.get(f) || function (a) {
  6404. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6405. }
  6406. ump3.set(f, g);
  6407. g.km34 = 1;
  6408. h.forceChatPoll_ = g;
  6409.  
  6410. }
  6411.  
  6412. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  6413.  
  6414. const f = h.onEndpointClick_;
  6415. const g = ump3.get(f) || function (a) {
  6416. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6417. }
  6418. ump3.set(f, g);
  6419. g.km34 = 1;
  6420. h.onEndpointClick_ = g;
  6421.  
  6422. }
  6423.  
  6424. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  6425.  
  6426. const f = h.onEndpointTap_;
  6427. const g = ump3.get(f) || function (a) {
  6428. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6429. }
  6430. ump3.set(f, g);
  6431. g.km34 = 1;
  6432. h.onEndpointTap_ = g;
  6433.  
  6434. }
  6435.  
  6436. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  6437.  
  6438. const f = h.handleClick_;
  6439. const g = ump3.get(f) || function (a, b) {
  6440. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6441. }
  6442. ump3.set(f, g);
  6443. g.km34 = 1;
  6444. h.handleClick_ = g;
  6445.  
  6446. }
  6447.  
  6448. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  6449.  
  6450. const f = h.onReadyStateChange_;
  6451. const g = ump3.get(f) || function () {
  6452. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6453. }
  6454. ump3.set(f, g);
  6455. g.km34 = 1;
  6456. h.onReadyStateChange_ = g;
  6457.  
  6458. }
  6459.  
  6460. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  6461.  
  6462. const f = h.onReadyStateChangeEntryPoint_;
  6463. const g = ump3.get(f) || function () {
  6464. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6465. }
  6466. ump3.set(f, g);
  6467. g.km34 = 1;
  6468. h.onReadyStateChangeEntryPoint_ = g;
  6469.  
  6470. }
  6471.  
  6472. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  6473.  
  6474. const f = h.readyStateChangeHandler_;
  6475. const g = ump3.get(f) || function (a) {
  6476. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6477. }
  6478. ump3.set(f, g);
  6479. g.km34 = 1;
  6480. h.readyStateChangeHandler_ = g;
  6481.  
  6482. }
  6483.  
  6484. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  6485.  
  6486. const f = h.xmlHttpHandler_;
  6487. const g = ump3.get(f) || function (a) {
  6488. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6489. }
  6490. ump3.set(f, g);
  6491. g.km34 = 1;
  6492. h.xmlHttpHandler_ = g;
  6493.  
  6494. }
  6495.  
  6496. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  6497.  
  6498. const f = h.executeCallbacks_; // overloaded
  6499. const g = ump3.get(f) || function (a) {
  6500. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6501. }
  6502. ump3.set(f, g);
  6503. g.km34 = 1;
  6504. h.executeCallbacks_ = g;
  6505.  
  6506. }
  6507.  
  6508. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  6509.  
  6510. const f = h.handleInvalidationData_;
  6511. const g = ump3.get(f) || function (a, b) {
  6512. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6513. }
  6514. ump3.set(f, g);
  6515. g.km34 = 1;
  6516. h.handleInvalidationData_ = g;
  6517.  
  6518. }
  6519.  
  6520. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  6521.  
  6522. const f = h.onInput_;
  6523. const g = ump3.get(f) || function () {
  6524. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6525. }
  6526. ump3.set(f, g);
  6527. g.km34 = 1;
  6528. h.onInput_ = g;
  6529.  
  6530. }
  6531. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  6532.  
  6533. const f = h.trigger_;
  6534. const g = ump3.get(f) || function (a) {
  6535. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6536. }
  6537. ump3.set(f, g);
  6538. g.km34 = 1;
  6539. h.trigger_ = g;
  6540.  
  6541. }
  6542.  
  6543. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  6544.  
  6545. const f = h.requestData_;
  6546. const g = ump3.get(f) || function (a) {
  6547. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6548. }
  6549. ump3.set(f, g);
  6550. g.km34 = 1;
  6551. h.requestData_ = g;
  6552.  
  6553. }
  6554.  
  6555. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  6556.  
  6557. const f = h.onLoadReloadContinuation_;
  6558. const g = ump3.get(f) || function (a, b) {
  6559. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6560. }
  6561. ump3.set(f, g);
  6562. g.km34 = 1;
  6563. h.onLoadReloadContinuation_ = g;
  6564.  
  6565. }
  6566.  
  6567. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  6568.  
  6569. const f = h.onLoadIncrementalContinuation_;
  6570. const g = ump3.get(f) || function (a, b) {
  6571. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6572. }
  6573. ump3.set(f, g);
  6574. g.km34 = 1;
  6575. h.onLoadIncrementalContinuation_ = g;
  6576.  
  6577. }
  6578.  
  6579. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  6580.  
  6581. const f = h.onLoadSeekContinuation_;
  6582. const g = ump3.get(f) || function (a, b) {
  6583. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6584. }
  6585. ump3.set(f, g);
  6586. g.km34 = 1;
  6587. h.onLoadSeekContinuation_ = g;
  6588.  
  6589. }
  6590. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  6591.  
  6592. const f = h.onLoadReplayContinuation_;
  6593. const g = ump3.get(f) || function (a, b) {
  6594. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6595. }
  6596. ump3.set(f, g);
  6597. g.km34 = 1;
  6598. h.onLoadReplayContinuation_ = g;
  6599.  
  6600. }
  6601. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  6602.  
  6603. const f = h.onNavigate_;
  6604. const g = ump3.get(f) || function (a) {
  6605. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6606. }
  6607. ump3.set(f, g);
  6608. g.km34 = 1;
  6609. h.onNavigate_ = g;
  6610.  
  6611. }
  6612.  
  6613. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  6614.  
  6615. const f = h.ytRendererBehaviorDataObserver_;
  6616. const g = ump3.get(f) || function () {
  6617. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6618. }
  6619. ump3.set(f, g);
  6620. g.km34 = 1;
  6621. h.ytRendererBehaviorDataObserver_ = g;
  6622.  
  6623. }
  6624.  
  6625. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  6626.  
  6627. const f = h.ytRendererBehaviorTargetIdObserver_;
  6628. const g = ump3.get(f) || function () {
  6629. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6630. }
  6631. ump3.set(f, g);
  6632. g.km34 = 1;
  6633. h.ytRendererBehaviorTargetIdObserver_ = g;
  6634.  
  6635. }
  6636.  
  6637. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  6638.  
  6639. const f = h.unregisterRenderer_;
  6640. const g = ump3.get(f) || function (a) {
  6641. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6642. }
  6643. ump3.set(f, g);
  6644. g.km34 = 1;
  6645. h.unregisterRenderer_ = g;
  6646.  
  6647. }
  6648.  
  6649. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  6650.  
  6651. const f = h.textChanged_;
  6652. const g = ump3.get(f) || function (a) {
  6653. if (void 0 !== this.isAttached) {
  6654. const hostElement = this.hostElement;
  6655. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  6656. return;
  6657. }
  6658. }
  6659. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6660. }
  6661. ump3.set(f, g);
  6662. g.km34 = 1;
  6663. h.textChanged_ = g;
  6664.  
  6665. }
  6666.  
  6667.  
  6668.  
  6669. /**
  6670. *
  6671. * Neglect following
  6672. *
  6673. * h.onYtAction_
  6674. * h.startLoadingWatch [ buggy for yt-player-updated ]
  6675. * h.deferRenderStamperBinding_
  6676. *
  6677. * h.stampDomArray_
  6678. * h.stampDomArraySplices_
  6679. *
  6680. */
  6681.  
  6682.  
  6683. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  6684. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  6685. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  6686. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  6687. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  6688. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  6689.  
  6690. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  6691.  
  6692. const f = h.searchChanged_;
  6693. const g = ump3.get(f) || function () {
  6694. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6695. }
  6696. ump3.set(f, g);
  6697. g.km34 = 1;
  6698. h.searchChanged_ = g;
  6699.  
  6700. }
  6701.  
  6702. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  6703.  
  6704. const f = h.skinToneChanged_;
  6705. const g = ump3.get(f) || function (a) {
  6706. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6707. }
  6708. ump3.set(f, g);
  6709. g.km34 = 1;
  6710. h.skinToneChanged_ = g;
  6711.  
  6712. }
  6713.  
  6714. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  6715.  
  6716. const f = h.onEmojiHover_;
  6717. const g = ump3.get(f) || function (a) {
  6718. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6719. }
  6720. ump3.set(f, g);
  6721. g.km34 = 1;
  6722. h.onEmojiHover_ = g;
  6723.  
  6724. }
  6725.  
  6726. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  6727.  
  6728. const f = h.onSelectCategory_;
  6729. const g = ump3.get(f) || function (a) {
  6730. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6731. }
  6732. ump3.set(f, g);
  6733. g.km34 = 1;
  6734. h.onSelectCategory_ = g;
  6735.  
  6736. }
  6737.  
  6738. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  6739.  
  6740. const f = h.onShowEmojiVariantSelector;
  6741. const g = ump3.get(f) || function (a) {
  6742. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6743. }
  6744. ump3.set(f, g);
  6745. g.km34 = 1;
  6746. h.onShowEmojiVariantSelector = g;
  6747.  
  6748. }
  6749.  
  6750. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  6751.  
  6752. const f = h.updateCategoriesAndPlaceholder_;
  6753. const g = ump3.get(f) || function () {
  6754. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6755. }
  6756. ump3.set(f, g);
  6757. g.km34 = 1;
  6758. h.updateCategoriesAndPlaceholder_ = g;
  6759.  
  6760. }
  6761.  
  6762. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  6763.  
  6764. const f = h.watchPageActiveChanged_;
  6765. const g = ump3.get(f) || function () {
  6766. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6767. }
  6768. ump3.set(f, g);
  6769. g.km34 = 1;
  6770. h.watchPageActiveChanged_ = g;
  6771.  
  6772. }
  6773.  
  6774. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  6775.  
  6776. const f = h.activate_;
  6777. const g = ump3.get(f) || function () {
  6778. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6779. }
  6780. ump3.set(f, g);
  6781. g.km34 = 1;
  6782. h.activate_ = g;
  6783.  
  6784. }
  6785. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  6786.  
  6787. const f = h.onYtPlaylistDataUpdated_;
  6788. const g = ump3.get(f) || function () {
  6789. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6790. }
  6791. ump3.set(f, g);
  6792. g.km34 = 1;
  6793. h.onYtPlaylistDataUpdated_ = g;
  6794.  
  6795. }
  6796.  
  6797.  
  6798.  
  6799. /**
  6800. *
  6801. * Neglect following
  6802. *
  6803. * h.rendererStamperObserver_
  6804. * h.rendererStamperApplyChangeRecord_
  6805. * h.flushRenderStamperComponentBindings_
  6806. * h.forwardRendererStamperChanges_
  6807. *
  6808. */
  6809.  
  6810. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  6811.  
  6812. const f = h.tryRenderChunk_;
  6813. const g = ump3.get(f) || function () {
  6814. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6815. }
  6816. ump3.set(f, g);
  6817. g.km34 = 1;
  6818. h.tryRenderChunk_ = g;
  6819.  
  6820. }
  6821.  
  6822.  
  6823. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  6824.  
  6825. const f = h.renderChunk_;
  6826. const g = ump3.get(f) || function () {
  6827. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6828. }
  6829. ump3.set(f, g);
  6830. g.km34 = 1;
  6831. h.renderChunk_ = g;
  6832.  
  6833. }
  6834.  
  6835. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  6836.  
  6837. const f = h.deepLazyListObserver_;
  6838. const g = ump3.get(f) || function () {
  6839. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6840. }
  6841. ump3.set(f, g);
  6842. g.km34 = 1;
  6843. h.deepLazyListObserver_ = g;
  6844.  
  6845. }
  6846.  
  6847. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  6848.  
  6849. const f = h.onItemsUpdated_;
  6850. const g = ump3.get(f) || function () {
  6851. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6852. }
  6853. ump3.set(f, g);
  6854. g.km34 = 1;
  6855. h.onItemsUpdated_ = g;
  6856.  
  6857. }
  6858.  
  6859. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  6860.  
  6861. const f = h.requestRenderChunk_;
  6862. const g = ump3.get(f) || function () {
  6863. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6864. }
  6865. ump3.set(f, g);
  6866. g.km34 = 1;
  6867. h.requestRenderChunk_ = g;
  6868.  
  6869. }
  6870.  
  6871. /**
  6872. *
  6873. * Neglect following
  6874. *
  6875. * h.dataChanged_ [ buggy for page swtiching ]
  6876. *
  6877. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  6878. *
  6879. * h.cancelPendingTasks_
  6880. * h.fillRange_
  6881. * h.addTextNodes_
  6882. * h.updateText_
  6883. * h.stampTypeChanged_
  6884. *
  6885. */
  6886.  
  6887.  
  6888. }
  6889.  
  6890. const keyStConnectedCallback = Symbol(); // avoid copying the value
  6891.  
  6892. // const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  6893. const cmf = new WeakMap();
  6894. const dmf = new WeakMap();
  6895.  
  6896. const gvGenerator = (nv) => {
  6897. return function () {
  6898. const cnt = insp(this);
  6899. const hostElement = cnt.hostElement || 0;
  6900. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  6901. let p = (hostElement instanceof HTMLElement_) && (dollar || !this.is);
  6902. if (p && (!dollar && !this.is)) {
  6903. const nodeName = hostElement.nodeName;
  6904. if (typeof nodeName !== 'string') {
  6905. // just in case
  6906. } else if (nodeName.startsWith("DOM-")) {
  6907. // dom-if, dom-repeat, etc
  6908. } else {
  6909. // yt element - new model, yt-xxxx, anixxxxxx
  6910. p = false;
  6911. }
  6912. }
  6913. if (p) {
  6914. if (typeof cnt.markDirty === 'function') {
  6915. // the yt element might call markDirty (occasionally)
  6916. p = false;
  6917. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  6918. // see https://github.com/cyfung1031/userscript-supports/issues/20
  6919. p = false;
  6920. }
  6921. }
  6922. if (p) {
  6923.  
  6924. // << dom-repeat & dom-if >>
  6925.  
  6926. // sequence on the same instance
  6927. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  6928. } else {
  6929. nv.apply(this, arguments);
  6930. }
  6931. };
  6932. }
  6933.  
  6934. // const assignedHolderWS = new WeakSet();
  6935.  
  6936. const setupWeakRef = (h) => {
  6937.  
  6938.  
  6939. }
  6940.  
  6941.  
  6942. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  6943.  
  6944. try {
  6945.  
  6946. const q = document.createElement('template');
  6947. q.innerHTML = '<ytz-null361></ytz-null361>';
  6948. nativeHTMLElement = q.content.firstChild.constructor
  6949.  
  6950. } catch (e) { }
  6951.  
  6952. if (!nativeHTMLElement.prototype.connectedCallback) {
  6953. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  6954. nativeHTMLElement.prototype.connectedCallback = function () {
  6955. let r;
  6956. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  6957. return r;
  6958. }
  6959. }
  6960. const pvr = Symbol()
  6961.  
  6962. let stampDomArrayMethod = null;
  6963. const setupMap = new WeakSet();
  6964.  
  6965. // const ENABLE_weakenStampReferencesQ = ENABLE_weakenStampReferences && typeof DocumentTimeline !== 'undefined' && typeof WeakRef !== 'undefined';
  6966. const setupYtComponent = (cnt) => {
  6967. const cProto = (cnt || 0).__proto__ || 0;
  6968. if (!cProto || setupMap.has(cProto)) return;
  6969. setupMap.add(cProto);
  6970. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  6971. cProto[pvr] |= 1;
  6972. if (FIX_stampDomArray && cProto.stampDomArray_ && !cProto.stampDomArray9682_) {
  6973. if (!stampDomArrayMethod) stampDomArrayMethod = createStampDomArrayFn_();
  6974. cProto.stampDomArray9682_ = cProto.stampDomArray_;
  6975. cProto.stampDomArray_ = stampDomArrayMethod;
  6976. }
  6977. }
  6978. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  6979. cProto[pvr] |= 2;
  6980. setupDiscreteTasks(cProto);
  6981. }
  6982. };
  6983.  
  6984. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  6985. get() {
  6986. const f = this[keyStConnectedCallback];
  6987. if (this.is) {
  6988. setupYtComponent(this);
  6989. }
  6990. /*
  6991. if (this.is) {
  6992. setupDiscreteTasks(this, true);
  6993. if (f) this.ky36 = 1;
  6994. }
  6995. */
  6996. return f;
  6997. },
  6998. set(nv) {
  6999. let gv = nv;
  7000. /*
  7001. if (typeof nv === 'function') {
  7002.  
  7003. gv = cmf.get(nv) || gvGenerator(nv);
  7004. if (gv !== nv) {
  7005. cmf.set(nv, gv);
  7006. cmf.set(gv, gv);
  7007. dmf.set(gv, nv);
  7008. }
  7009.  
  7010. } else {
  7011. gv = nv;
  7012. }
  7013. */
  7014. this[keyStConnectedCallback] = gv; // proto or object
  7015. /*
  7016. if (this.is) {
  7017. setupDiscreteTasks(this);
  7018. }
  7019. */
  7020. return true;
  7021. },
  7022. enumerable: false,
  7023. configurable: true
  7024.  
  7025. });
  7026.  
  7027. const pLoad = new Promise(resolve => {
  7028. if (document.readyState !== 'loading') {
  7029. resolve();
  7030. } else {
  7031. window.addEventListener("DOMContentLoaded", resolve, false);
  7032. }
  7033. });
  7034.  
  7035. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  7036. window.requestIdleCallback471 = window.requestIdleCallback;
  7037. window.requestIdleCallback = function (f, ...args) {
  7038. return (this || window).requestIdleCallback471(async function () {
  7039. await pLoad.then();
  7040. // await new Promise(nextBrowserTick_);
  7041. f.call(this, ...arguments)
  7042. }, ...args);
  7043. }
  7044. }
  7045.  
  7046. pLoad.then(() => {
  7047.  
  7048. let nonce = document.querySelector('style[nonce]');
  7049. nonce = nonce ? nonce.getAttribute('nonce') : null;
  7050. const st = document.createElement('style');
  7051. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  7052. st.textContent = "none-element-k47{order:0}";
  7053. st.addEventListener('load', () => {
  7054. pf31.resolve();
  7055. p59 = 1;
  7056. }, false);
  7057. (document.body || document.head || document.documentElement).appendChild(st);
  7058.  
  7059. });
  7060.  
  7061. const prepareLogs = [];
  7062.  
  7063. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  7064.  
  7065. let winError00 = window.onerror;
  7066.  
  7067. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  7068.  
  7069. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  7070.  
  7071. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  7072.  
  7073. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  7074. const lcOpt = { sensitivity: 'base' };
  7075. document.createElement24 = document.createElement;
  7076. document.createElement = function (t) {
  7077. if (typeof t === 'string' && t.length === 6) {
  7078. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  7079. const p = this.createElement24(t);
  7080. try {
  7081. const stack = new Error().stack;
  7082. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  7083. if (!isSearchbox) {
  7084. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  7085. }
  7086. } catch (e) { }
  7087. return p;
  7088. }
  7089. }
  7090. return this.createElement24.apply(this, arguments);
  7091. };
  7092.  
  7093. })();
  7094.  
  7095. ; fix_error_many_stack_state === 1 && (() => {
  7096.  
  7097.  
  7098. let p1 = winError00;
  7099.  
  7100. let stackNeedleDetails = null;
  7101.  
  7102. Object.defineProperty(Object.prototype, 'matchAll', {
  7103. get() {
  7104. stackNeedleDetails = this;
  7105. return true;
  7106. },
  7107. enumerable: true,
  7108. configurable: true
  7109. });
  7110.  
  7111. try {
  7112. JSON.parse("{}");
  7113. } catch (e) {
  7114. console.warn(e)
  7115. fix_error_many_stack_state = 0;
  7116. }
  7117.  
  7118. delete Object.prototype['matchAll'];
  7119.  
  7120. let p2 = window.onerror;
  7121.  
  7122. window.onerror = p1;
  7123.  
  7124. if (fix_error_many_stack_state === 0) return;
  7125.  
  7126. if (stackNeedleDetails) {
  7127. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7128. stackNeedleDetails.matchAll = true;
  7129. }
  7130.  
  7131. if (p1 === p2) return (fix_error_many_stack_state = 0);
  7132.  
  7133. // p1!==p2
  7134. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  7135.  
  7136. })();
  7137.  
  7138. ; fix_error_many_stack_state === 2 && (() => {
  7139.  
  7140.  
  7141. let p1 = winError00;
  7142.  
  7143. let objectPrune = null;
  7144. let stackNeedleDetails = null;
  7145.  
  7146. Object.defineProperty(Function.prototype, 'findOwner', {
  7147. get() {
  7148. objectPrune = this;
  7149. return this._findOwner;
  7150. },
  7151. set(nv) {
  7152. this._findOwner = nv;
  7153. return true;
  7154. },
  7155. enumerable: true,
  7156. configurable: true
  7157. });
  7158.  
  7159. Object.defineProperty(Object.prototype, 'matchAll', {
  7160. get() {
  7161. stackNeedleDetails = this;
  7162. return true;
  7163. },
  7164. enumerable: true,
  7165. configurable: true
  7166. });
  7167.  
  7168. try {
  7169. JSON.parse("{}");
  7170. } catch (e) {
  7171. console.warn(e)
  7172. fix_error_many_stack_state = 0;
  7173. }
  7174.  
  7175. delete Function.prototype['findOwner'];
  7176. delete Object.prototype['matchAll'];
  7177.  
  7178. let p2 = window.onerror;
  7179.  
  7180. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  7181.  
  7182. if (fix_error_many_stack_state == 0) return;
  7183.  
  7184. // the following will only execute when Brave's scriptlets.js is executed.
  7185.  
  7186. prepareLogs.push("fix_error_many_stack_state NB")
  7187.  
  7188. if (stackNeedleDetails) {
  7189. stackNeedleDetails.pattern = null;
  7190. stackNeedleDetails.re = null;
  7191. stackNeedleDetails.expect = null;
  7192. stackNeedleDetails.matchAll = true;
  7193. }
  7194.  
  7195. if (objectPrune) {
  7196. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  7197. delete objectPrune._findOwner;
  7198. }
  7199.  
  7200. fix_error_many_stack_state = 3;
  7201. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7202. JSON.parse.objectPrune = objectPrune;
  7203.  
  7204. })();
  7205.  
  7206. ; fix_error_many_stack_state === 3 && (() => {
  7207.  
  7208.  
  7209. let p1 = winError00;
  7210.  
  7211. try {
  7212. JSON.parse("{}");
  7213. } catch (e) {
  7214. console.warn(e)
  7215. fix_error_many_stack_state = 0;
  7216. }
  7217.  
  7218. let p2 = window.onerror;
  7219.  
  7220. if (p1 === p2) return;
  7221.  
  7222. window.onerror = p1;
  7223.  
  7224. if (fix_error_many_stack_state === 0) return;
  7225.  
  7226. fix_error_many_stack_state = 4; // p1 != p2
  7227.  
  7228.  
  7229. })();
  7230.  
  7231. fix_error_many_stack_state === 4 && (() => {
  7232.  
  7233. // the following will only execute when Brave's scriptlets.js is executed.
  7234.  
  7235. prepareLogs.push("fix_error_many_stack_state AB")
  7236.  
  7237. JSON.parseProxy = JSON.parse;
  7238.  
  7239. JSON.parse = ((parse) => {
  7240.  
  7241. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  7242. return function (text, reviver) {
  7243. const onerror = window.onerror;
  7244. window.onerror = null;
  7245. let r;
  7246. try {
  7247. r = parse(...arguments);
  7248. } catch (e) {
  7249. r = e;
  7250. }
  7251. window.onerror = onerror;
  7252. if (r instanceof Error) {
  7253. throw r;
  7254. }
  7255. return r;
  7256. }
  7257.  
  7258. })(JSON.parse);
  7259.  
  7260.  
  7261. })();
  7262.  
  7263.  
  7264. // << if FIX_yt_player >>
  7265.  
  7266. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  7267. const PERF_471489_ = true;
  7268. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  7269. // This script uses a much gentle way to tamer the JS engine instead.
  7270.  
  7271. // << end >>
  7272.  
  7273. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  7274.  
  7275.  
  7276.  
  7277. const nilFn = () => { };
  7278.  
  7279. let isMainWindow = false;
  7280. try {
  7281. isMainWindow = window.document === window.top.document
  7282. } catch (e) { }
  7283.  
  7284. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  7285. let headLinkCollection = null;
  7286.  
  7287.  
  7288. // const assertor = (f) => f() || console.assert(false, `${f}`);
  7289.  
  7290. const fnIntegrity = (f, d) => {
  7291. if (!f || typeof f !== 'function') {
  7292. console.warn('f is not a function', f);
  7293. return;
  7294. }
  7295. let p = `${f}`, s = 0, j = -1, w = 0;
  7296. for (let i = 0, l = p.length; i < l; i++) {
  7297. const t = p[i];
  7298. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  7299. if (j < i - 1) w++;
  7300. j = i;
  7301. } else {
  7302. s++;
  7303. }
  7304. }
  7305. let itz = `${f.length}.${s}.${w}`;
  7306. if (!d) {
  7307. return itz;
  7308. } else {
  7309. return itz === d;
  7310. }
  7311. };
  7312.  
  7313. const getZqOu = (_yt_player) => {
  7314.  
  7315. const w = 'ZqOu';
  7316.  
  7317. let arr = [];
  7318.  
  7319. for (const [k, v] of Object.entries(_yt_player)) {
  7320.  
  7321. const p = typeof v === 'function' ? v.prototype : 0;
  7322. if (p
  7323. && typeof p.start === 'function' && p.start.length === 0 // Ou
  7324. && typeof p.isActive === 'function' && p.isActive.length === 0
  7325. && typeof p.stop === 'function' && p.stop.length === 0
  7326. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7327. && !p.send && !p.abort
  7328. && !p.sample && !p.initialize && !p.fail && !p.getName
  7329. // && !p.dispose && !p.isDisposed
  7330.  
  7331. ) {
  7332. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7333.  
  7334.  
  7335. }
  7336.  
  7337. }
  7338.  
  7339. if (arr.length === 0) {
  7340.  
  7341. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7342. } else {
  7343.  
  7344. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7345. return arr[0];
  7346. }
  7347.  
  7348. }
  7349.  
  7350. const getZqQu = (_yt_player) => {
  7351.  
  7352. const w = 'ZqQu';
  7353.  
  7354. let arr = [];
  7355.  
  7356.  
  7357. for (const [k, v] of Object.entries(_yt_player)) {
  7358.  
  7359. const p = typeof v === 'function' ? v.prototype : 0;
  7360. if (p
  7361. && typeof p.start === 'function' && p.start.length === 1 // Qu
  7362. && typeof p.isActive === 'function' && p.isActive.length === 0
  7363. && typeof p.stop === 'function' && p.stop.length === 0
  7364. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7365. && !p.send && !p.abort
  7366. && !p.sample && !p.initialize && !p.fail && !p.getName
  7367. // && !p.dispose && !p.isDisposed
  7368.  
  7369. ) {
  7370. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7371.  
  7372.  
  7373. }
  7374.  
  7375. }
  7376.  
  7377. if (arr.length === 0) {
  7378.  
  7379. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7380. } else {
  7381.  
  7382. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7383. return arr[0];
  7384. }
  7385.  
  7386. }
  7387.  
  7388.  
  7389. const getVG = (_yt_player) => {
  7390. const w = 'VG';
  7391.  
  7392. let arr = [];
  7393.  
  7394. for (const [k, v] of Object.entries(_yt_player)) {
  7395.  
  7396. const p = typeof v === 'function' ? v.prototype : 0;
  7397. if (p
  7398. && typeof p.show === 'function' && p.show.length === 1
  7399. && typeof p.hide === 'function' && p.hide.length === 0
  7400. && typeof p.stop === 'function' && p.stop.length === 0) {
  7401.  
  7402. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7403.  
  7404. }
  7405.  
  7406. }
  7407.  
  7408.  
  7409. if (arr.length === 0) {
  7410.  
  7411. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7412. } else {
  7413.  
  7414. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7415. return arr[0];
  7416. }
  7417.  
  7418.  
  7419.  
  7420. }
  7421.  
  7422.  
  7423. const getzo = (_yt_player) => {
  7424. const w = 'zo';
  7425.  
  7426. let arr = [];
  7427.  
  7428. for (const [k, v] of Object.entries(_yt_player)) {
  7429.  
  7430. if (
  7431. typeof v === 'function' && v.length === 3 && k.length < 3
  7432. ) {
  7433. const vt = `${v}`;
  7434. if (vt.length >= 21 && vt.includes(".style[")) {
  7435. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  7436. arr.push(k);
  7437. } else {
  7438. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  7439. }
  7440. }
  7441. }
  7442.  
  7443. }
  7444.  
  7445. if (arr.length === 0) {
  7446.  
  7447. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7448. } else {
  7449.  
  7450. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7451. return arr[0];
  7452. }
  7453.  
  7454. }
  7455.  
  7456. const addProtoToArr = (parent, key, arr) => {
  7457.  
  7458.  
  7459. let isChildProto = false;
  7460. for (const sr of arr) {
  7461. if (parent[key].prototype instanceof parent[sr]) {
  7462. isChildProto = true;
  7463. break;
  7464. }
  7465. }
  7466.  
  7467. if (isChildProto) return;
  7468.  
  7469. arr = arr.filter(sr => {
  7470. if (parent[sr].prototype instanceof parent[key]) {
  7471. return false;
  7472. }
  7473. return true;
  7474. });
  7475.  
  7476. arr.push(key);
  7477.  
  7478. return arr;
  7479.  
  7480.  
  7481. }
  7482.  
  7483. const getuG = (_yt_player) => {
  7484.  
  7485. const w = 'uG';
  7486.  
  7487. let arr = [];
  7488.  
  7489. for (const [k, v] of Object.entries(_yt_player)) {
  7490.  
  7491.  
  7492. const p = typeof v === 'function' ? v.prototype : 0;
  7493.  
  7494. if (p
  7495. && typeof p.createElement === 'function' && p.createElement.length === 2
  7496. && typeof p.detach === 'function' && p.detach.length === 0
  7497. && typeof p.update === 'function' && p.update.length === 1
  7498. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  7499. ) {
  7500.  
  7501. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7502.  
  7503. }
  7504.  
  7505. }
  7506.  
  7507.  
  7508.  
  7509.  
  7510.  
  7511. if (arr.length === 0) {
  7512.  
  7513. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7514. } else {
  7515.  
  7516. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7517. return arr[0];
  7518. }
  7519.  
  7520. }
  7521.  
  7522.  
  7523. const getQT = (_yt_player) => {
  7524. const w = 'QT';
  7525.  
  7526. let arr = [];
  7527. let brr = new Map();
  7528.  
  7529. for (const [k, v] of Object.entries(_yt_player)) {
  7530.  
  7531. const p = typeof v === 'function' ? v.prototype : 0;
  7532. if (p) {
  7533. let q = 0;
  7534. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7535. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7536. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7537.  
  7538. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7539.  
  7540. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7541.  
  7542. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7543. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7544. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7545. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7546.  
  7547.  
  7548. // differentiate QT and DX
  7549.  
  7550. q += 280;
  7551. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  7552. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  7553. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  7554. if (typeof p.seekBy === 'function') q += 4;
  7555. if (typeof p.seekTo === 'function') q += 4;
  7556. if (typeof p.getStoryboardFormat === 'function') q += 4;
  7557. if (typeof p.getDuration === 'function') q += 4;
  7558. if (typeof p.loadModule === 'function') q += 4;
  7559. if (typeof p.unloadModule === 'function') q += 4;
  7560. if (typeof p.getOption === 'function') q += 4;
  7561. if (typeof p.getOptions === 'function') q += 4;
  7562. if (typeof p.setOption === 'function') q += 4;
  7563. if (typeof p.addCueRange === 'function') q += 4;
  7564. if (typeof p.getDebugText === 'function') q += 4;
  7565. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  7566. if (typeof p.setSizeStyle === 'function') q += 4;
  7567. if (typeof p.showControls === 'function') q += 4;
  7568. if (typeof p.hideControls === 'function') q += 4;
  7569. if (typeof p.getVideoContentRect === 'function') q += 4;
  7570. if (typeof p.toggleFullscreen === 'function') q += 4;
  7571. if (typeof p.isFullscreen === 'function') q += 4;
  7572. if (typeof p.cancelPlayback === 'function') q += 4;
  7573. if (typeof p.getProgressState === 'function') q += 4;
  7574. if (typeof p.isInline === 'function') q += 4;
  7575. if (typeof p.setInline === 'function') q += 4;
  7576. if (typeof p.toggleSubtitles === 'function') q += 4;
  7577. if (typeof p.getPlayerSize === 'function') q += 4;
  7578. if (typeof p.wakeUpControls === 'function') q += 4;
  7579. if (typeof p.setCenterCrop === 'function') q += 4;
  7580. if (typeof p.getLoopVideo === 'function') q += 4;
  7581. if (typeof p.setLoopVideo === 'function') q += 4;
  7582.  
  7583.  
  7584. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7585.  
  7586. if (q > 0) brr.set(k, q);
  7587.  
  7588. }
  7589.  
  7590. }
  7591.  
  7592. if (arr.length === 0) {
  7593.  
  7594. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7595. } else {
  7596.  
  7597. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7598.  
  7599. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7600.  
  7601. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7602. return arr[0][0];
  7603. }
  7604.  
  7605.  
  7606.  
  7607. }
  7608.  
  7609.  
  7610.  
  7611. const getSV = (_yt_player) => {
  7612. const w = 'SV';
  7613.  
  7614. let arr = [];
  7615. let brr = new Map();
  7616.  
  7617. for (const [k, v] of Object.entries(_yt_player)) {
  7618.  
  7619. const p = typeof v === 'function' ? v.prototype : 0;
  7620. if (p) {
  7621. let q = 0;
  7622. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7623. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7624. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7625.  
  7626. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  7627.  
  7628. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7629.  
  7630. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7631. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7632. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7633. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7634.  
  7635.  
  7636. // differentiate QT and DX
  7637.  
  7638.  
  7639. q += 280;
  7640.  
  7641. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7642. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7643. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7644. if (typeof p.seekBy === 'function') q -= 4;
  7645. if (typeof p.seekTo === 'function') q -= 4;
  7646. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7647. if (typeof p.getDuration === 'function') q -= 4;
  7648. if (typeof p.loadModule === 'function') q -= 4;
  7649. if (typeof p.unloadModule === 'function') q -= 4;
  7650. if (typeof p.getOption === 'function') q -= 4;
  7651. if (typeof p.getOptions === 'function') q -= 4;
  7652. if (typeof p.setOption === 'function') q -= 4;
  7653. if (typeof p.addCueRange === 'function') q -= 4;
  7654. if (typeof p.getDebugText === 'function') q -= 4;
  7655. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7656. if (typeof p.setSizeStyle === 'function') q -= 4;
  7657. if (typeof p.showControls === 'function') q -= 4;
  7658. if (typeof p.hideControls === 'function') q -= 4;
  7659. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7660. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7661. if (typeof p.isFullscreen === 'function') q -= 4;
  7662. if (typeof p.cancelPlayback === 'function') q -= 4;
  7663. if (typeof p.getProgressState === 'function') q -= 4;
  7664. if (typeof p.isInline === 'function') q -= 4;
  7665. if (typeof p.setInline === 'function') q -= 4;
  7666. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7667. if (typeof p.getPlayerSize === 'function') q -= 4;
  7668. if (typeof p.wakeUpControls === 'function') q -= 4;
  7669. if (typeof p.setCenterCrop === 'function') q -= 4;
  7670. if (typeof p.getLoopVideo === 'function') q -= 4;
  7671. if (typeof p.setLoopVideo === 'function') q -= 4;
  7672.  
  7673.  
  7674. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7675.  
  7676. if (q > 0) brr.set(k, q);
  7677.  
  7678. }
  7679.  
  7680. }
  7681.  
  7682. if (arr.length === 0) {
  7683.  
  7684. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7685. } else {
  7686.  
  7687. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7688.  
  7689. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7690.  
  7691. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7692. return arr[0][0];
  7693. }
  7694.  
  7695.  
  7696.  
  7697. }
  7698.  
  7699.  
  7700.  
  7701.  
  7702. const getDX = (_yt_player) => {
  7703. const w = 'DX';
  7704.  
  7705. let arr = [];
  7706. let brr = new Map();
  7707.  
  7708. for (const [k, v] of Object.entries(_yt_player)) {
  7709.  
  7710. const p = typeof v === 'function' ? v.prototype : 0;
  7711. if (p) {
  7712. let q = 0;
  7713. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7714. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7715. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7716.  
  7717. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7718.  
  7719.  
  7720. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  7721.  
  7722. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7723.  
  7724. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7725. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7726. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7727. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7728.  
  7729.  
  7730. // differentiate QT and DX
  7731.  
  7732.  
  7733. q += 280;
  7734.  
  7735. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7736. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7737. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7738. if (typeof p.seekBy === 'function') q -= 4;
  7739. if (typeof p.seekTo === 'function') q -= 4;
  7740. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7741. if (typeof p.getDuration === 'function') q -= 4;
  7742. if (typeof p.loadModule === 'function') q -= 4;
  7743. if (typeof p.unloadModule === 'function') q -= 4;
  7744. if (typeof p.getOption === 'function') q -= 4;
  7745. if (typeof p.getOptions === 'function') q -= 4;
  7746. if (typeof p.setOption === 'function') q -= 4;
  7747. if (typeof p.addCueRange === 'function') q -= 4;
  7748. if (typeof p.getDebugText === 'function') q -= 4;
  7749. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7750. if (typeof p.setSizeStyle === 'function') q -= 4;
  7751. if (typeof p.showControls === 'function') q -= 4;
  7752. if (typeof p.hideControls === 'function') q -= 4;
  7753. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7754. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7755. if (typeof p.isFullscreen === 'function') q -= 4;
  7756. if (typeof p.cancelPlayback === 'function') q -= 4;
  7757. if (typeof p.getProgressState === 'function') q -= 4;
  7758. if (typeof p.isInline === 'function') q -= 4;
  7759. if (typeof p.setInline === 'function') q -= 4;
  7760. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7761. if (typeof p.getPlayerSize === 'function') q -= 4;
  7762. if (typeof p.wakeUpControls === 'function') q -= 4;
  7763. if (typeof p.setCenterCrop === 'function') q -= 4;
  7764. if (typeof p.getLoopVideo === 'function') q -= 4;
  7765. if (typeof p.setLoopVideo === 'function') q -= 4;
  7766.  
  7767.  
  7768. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7769.  
  7770. if (q > 0) brr.set(k, q);
  7771.  
  7772. }
  7773.  
  7774. }
  7775.  
  7776. if (arr.length === 0) {
  7777.  
  7778. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7779. } else {
  7780.  
  7781. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7782.  
  7783. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7784.  
  7785. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7786. return arr[0][0];
  7787. }
  7788.  
  7789.  
  7790.  
  7791. }
  7792.  
  7793.  
  7794.  
  7795. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  7796.  
  7797. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  7798. let pageSetupState = 0;
  7799.  
  7800. isPrepareCachedV && (() => {
  7801.  
  7802. pageSetupVideoId = '';
  7803. const clearCachedV = () => {
  7804. pageSetupVideoId = '';
  7805. pageSetupState = 0;
  7806. }
  7807. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  7808. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  7809. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  7810. document.addEventListener('yt-navigate-finish', () => {
  7811. pageSetupState = 1;
  7812. try {
  7813. const url = new URL(location.href);
  7814. if (!url || !isWatchPageURL(url)) {
  7815. pageSetupVideoId = '';
  7816. } else {
  7817. pageSetupVideoId = url.searchParams.get('v') || '';
  7818. }
  7819. } catch (e) {
  7820. pageSetupVideoId = '';
  7821. }
  7822. }, false);
  7823.  
  7824. })();
  7825.  
  7826. let videoPlayingY = null;
  7827.  
  7828. isPrepareCachedV && (() => {
  7829.  
  7830. let getNext = true;
  7831. let videoPlayingX = {
  7832. get videoId() {
  7833. if (getNext) {
  7834. getNext = false;
  7835.  
  7836. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  7837. const arr = [];
  7838. for (const element of elements) {
  7839. if (!element.closest('[hidden]')) arr.push(element);
  7840. }
  7841. if (arr.length !== 1) this.__videoId__ = '';
  7842. else {
  7843. this.__videoId__ = arr[0].getAttribute('video-id');
  7844. }
  7845.  
  7846. }
  7847. return this.__videoId__ || '';
  7848. }
  7849. }
  7850.  
  7851. videoPlayingY = videoPlayingX;
  7852. const handler = (evt) => {
  7853. const target = (evt || 0).target;
  7854. if (target instanceof HTMLVideoElement) {
  7855. getNext = true;
  7856. }
  7857. }
  7858. document.addEventListener('loadedmetadata', handler, true);
  7859. document.addEventListener('durationchange', handler, true);
  7860.  
  7861. })();
  7862.  
  7863.  
  7864.  
  7865. const cleanContext = async (win) => {
  7866. const waitFn = requestAnimationFrame; // shall have been binded to window
  7867. try {
  7868. let mx = 16; // MAX TRIAL
  7869. const frameId = 'vanillajs-iframe-v1';
  7870. /** @type {HTMLIFrameElement | null} */
  7871. let frame = document.getElementById(frameId);
  7872. let removeIframeFn = null;
  7873. if (!frame) {
  7874. frame = document.createElement('iframe');
  7875. frame.id = frameId;
  7876. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  7877. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  7878. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  7879. n.appendChild(frame);
  7880. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  7881. const root = document.documentElement;
  7882. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  7883. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  7884.  
  7885. removeIframeFn = (setTimeout) => {
  7886. const removeIframeOnDocumentReady = (e) => {
  7887. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7888. e = n;
  7889. n = win = removeIframeFn = 0;
  7890. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  7891. }
  7892. if (!setTimeout || document.readyState !== 'loading') {
  7893. removeIframeOnDocumentReady();
  7894. } else {
  7895. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7896. }
  7897. }
  7898. }
  7899. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  7900. const fc = frame.contentWindow;
  7901. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  7902. try {
  7903. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  7904. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  7905. for (let k in res) res[k] = res[k].bind(win); // necessary
  7906. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  7907. res.animate = fc.HTMLElement.prototype.animate;
  7908. res.perfNow = fc.performance.now;
  7909. return res;
  7910. } catch (e) {
  7911. if (removeIframeFn) removeIframeFn();
  7912. return null;
  7913. }
  7914. } catch (e) {
  7915. console.warn(e);
  7916. return null;
  7917. }
  7918. };
  7919.  
  7920. const promiseForYtActionCalled = new Promise(resolve => {
  7921.  
  7922. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  7923. if (typeof AbortSignal !== 'undefined') {
  7924. let hn = () => {
  7925. if (!hn) return;
  7926. hn = null;
  7927. resolve(document.querySelector(appTag));
  7928. };
  7929. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  7930. } else {
  7931. let hn = () => {
  7932. if (!hn) return;
  7933. document.removeEventListener('yt-action', hn, true);
  7934. hn = null;
  7935. resolve(document.querySelector(appTag));
  7936. };
  7937. document.addEventListener('yt-action', hn, true);
  7938. }
  7939. });
  7940.  
  7941. cleanContext(window).then(__CONTEXT__ => {
  7942. if (!__CONTEXT__) return null;
  7943.  
  7944. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  7945.  
  7946.  
  7947. performance.now17 = perfNow.bind(performance);
  7948.  
  7949.  
  7950.  
  7951. __requestAnimationFrame__ = requestAnimationFrame;
  7952.  
  7953.  
  7954. const isGPUAccelerationAvailable = (() => {
  7955. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  7956. try {
  7957. const canvas = document.createElement('canvas');
  7958. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  7959. } catch (e) {
  7960. return false;
  7961. }
  7962. })();
  7963.  
  7964. const foregroundPromiseFn_noGPU = (() => {
  7965.  
  7966. if (isGPUAccelerationAvailable) return null;
  7967.  
  7968. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  7969. if (!pd || typeof pd.get !== 'function') return null;
  7970. const pdGet = pd.get;
  7971.  
  7972. let pr = null;
  7973.  
  7974. let hState = pdGet.call(document) === 'hidden';
  7975. // let cid = 0;
  7976. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  7977. const newHState = pdGet.call(document) === 'hidden';
  7978. if (hState !== newHState) {
  7979. // if (cid > 0) cid = clearInterval(cid);
  7980. hState = newHState;
  7981. if (!hState && pr) pr = pr.resolve();
  7982. }
  7983. });
  7984.  
  7985. // cid = setInterval(() => {
  7986. // const newHState = document.visibilityState === 'hidden';
  7987. // if (hState !== newHState) {
  7988. // hState = newHState;
  7989. // if (!hState && pr) pr = pr.resolve();
  7990. // }
  7991. // }, 100);
  7992.  
  7993.  
  7994. return (() => {
  7995. if (pr) return pr;
  7996. const w = ((!hState && setTimeout(() => {
  7997. if (!hState && pr === w) pr = pr.resolve();
  7998. })), (pr = new PromiseExternal()));
  7999. return w;
  8000. });
  8001.  
  8002. })();
  8003.  
  8004.  
  8005. let rafPromise = null;
  8006. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  8007. requestAnimationFrame(hRes => {
  8008. rafPromise = null;
  8009. resolve(hRes);
  8010. });
  8011. }));
  8012.  
  8013. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  8014.  
  8015.  
  8016. const wmComputedStyle = new WeakMap();
  8017.  
  8018. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  8019. window.__native__getComputedStyle__ = getComputedStyle;
  8020. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  8021. window.__original__getComputedStyle__ = window.getComputedStyle;
  8022. window.getComputedStyle = function (elem) {
  8023. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  8024. return window.__original__getComputedStyle__(...arguments);
  8025. }
  8026. let cs = wmComputedStyle.get(elem);
  8027. if (!cs) {
  8028. cs = window.__native__getComputedStyle__(elem);
  8029. wmComputedStyle.set(elem, cs);
  8030. }
  8031. return cs;
  8032. };
  8033. } else {
  8034. window.__original__getComputedStyle__ = null;
  8035. }
  8036. window.__jst__getComputedStyle__ = window.getComputedStyle;
  8037. }
  8038.  
  8039. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  8040. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  8041. window.getComputedStyle = window.__jst__getComputedStyle__;
  8042. }
  8043. });
  8044.  
  8045. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  8046. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  8047.  
  8048. const promiseForTamerTimeout = new Promise(resolve => {
  8049. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8050. setTimeout(resolve, 480);
  8051. }, { capture: true, passive: true, once: true });
  8052. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8053. setTimeout(resolve, 1200);
  8054. });
  8055. setTimeout(resolve, 3000);
  8056. });
  8057.  
  8058. const promiseForPageInitied = new Promise(resolve => {
  8059. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8060. setTimeout(resolve, 450);
  8061. }, { capture: true, passive: true, once: true });
  8062. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8063. setTimeout(resolve, 900);
  8064. });
  8065. setTimeout(resolve, 1800);
  8066. });
  8067.  
  8068. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  8069. NO_PRELOAD_GENERATE_204_BYPASS = true;
  8070. headLinkCollection = null;
  8071. });
  8072.  
  8073.  
  8074. NATIVE_CANVAS_ANIMATION && (() => {
  8075.  
  8076. observablePromise(() => {
  8077. HTMLCanvasElement.prototype.animate = animate;
  8078. }, promiseForTamerTimeout).obtain();
  8079.  
  8080. })();
  8081.  
  8082.  
  8083.  
  8084.  
  8085. FIX_ytAction_ && (async () => {
  8086.  
  8087. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8088.  
  8089. const ytdApp = await new Promise(resolve => {
  8090.  
  8091. whenCEDefined(appTag).then(() => {
  8092. const ytdApp = document.querySelector(appTag);
  8093. if (ytdApp) {
  8094. resolve(ytdApp);
  8095. return;
  8096. }
  8097. let mo = new MutationObserver(() => {
  8098. const ytdApp = document.querySelector(appTag);
  8099. if (!ytdApp) return;
  8100. if (mo) {
  8101. mo.disconnect();
  8102. mo.takeRecords();
  8103. mo = null;
  8104. }
  8105. resolve(ytdApp);
  8106. });
  8107. mo.observe(document, { subtree: true, childList: true });
  8108. });
  8109.  
  8110. });
  8111.  
  8112. if (!ytdApp) return;
  8113. const cProto = insp(ytdApp).constructor.prototype;
  8114.  
  8115. if (!cProto) return;
  8116. let mbd = 0;
  8117.  
  8118. const fixer = (_ytdApp) => {
  8119. const ytdApp = insp(_ytdApp);
  8120. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  8121. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  8122. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  8123. mbd++;
  8124. }
  8125. }
  8126.  
  8127. observablePromise(() => {
  8128.  
  8129. if (typeof cProto.created === 'function' && !cProto.created56) {
  8130. cProto.created56 = cProto.created;
  8131. cProto.created = function (...args) {
  8132. const r = this.created56(...args);
  8133. fixer(this);
  8134. return r;
  8135. };
  8136. mbd++;
  8137. }
  8138.  
  8139. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  8140. cProto.onYtAction57_ = cProto.onYtAction_;
  8141. cProto.onYtAction_ = function (...args) {
  8142. Promise.resolve().then(() => this.onYtAction57_(...args));
  8143. };
  8144. mbd++;
  8145. }
  8146.  
  8147. if (ytdApp) fixer(ytdApp);
  8148.  
  8149. /*
  8150. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  8151. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  8152. actionRouter_.handleAction57 = actionRouter_.handleAction;
  8153. actionRouter_.handleAction = function (...args) {
  8154. Promise.resolve().then(() => this.handleAction57(...args));
  8155. }
  8156. mbd++;
  8157. }
  8158. */
  8159.  
  8160. // if(mbd === 3) return 1;
  8161. if (mbd >= 3) return 1;
  8162.  
  8163. }, new Promise(r => setTimeout(r, 1000))).obtain();
  8164.  
  8165. })();
  8166.  
  8167.  
  8168.  
  8169. // FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  8170.  
  8171. // const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  8172.  
  8173. // const app = await observablePromise(() => {
  8174.  
  8175. // return document.querySelector(appTag);
  8176.  
  8177. // }).obtain();
  8178.  
  8179. // if (!app) return;
  8180.  
  8181.  
  8182. // const appCnt = insp(app);
  8183.  
  8184. // if (typeof appCnt.createComponent_ !== 'function' || appCnt.createComponent_.length != 3) return;
  8185.  
  8186. // // appCnt.createComponent_('amkamk')
  8187.  
  8188.  
  8189.  
  8190. // // setTimeout(()=>{
  8191.  
  8192. // // console.log('XXX_OBJECT')
  8193.  
  8194.  
  8195.  
  8196.  
  8197. // // let j1 = new FinalizationRegistry((heldValue) => {
  8198. // // console.log(`CLEAR_OBJECT (${heldValue}) has been released`);
  8199. // // });
  8200. // // const setup = (options)=>{
  8201. // // const {key, add, remove, parent}=options;
  8202. // // const elm = add();
  8203. // // if(elm.parentNode !== parent) parent.appendChild(elm);
  8204. // // remove(elm, parent);
  8205. // // console.log('SET_OBJECT '+key, elm.outerHTML)
  8206. // // j1.register(elm, key);
  8207. // // }
  8208. // // setup({
  8209. // // key: 'c1',
  8210. // // parent: document.body,
  8211. // // add() {
  8212. // // return appCnt.createComponent_('yt-icon', {}, {
  8213. // // "size": 16,
  8214. // // "icon": "AUDIO_BADGE",
  8215. // // "active": false,
  8216. // // "defaultToFilled": true,
  8217. // // "targetContainer": "",
  8218. // // "isDarkTheme": true,
  8219. // // "isAttached": true
  8220. // // })
  8221. // // },
  8222. // // remove(elm, parent) {
  8223. // // parent.removeChild(elm);
  8224. // // }
  8225. // // });
  8226.  
  8227.  
  8228.  
  8229. // // setup({
  8230. // // key: 'c1b',
  8231. // // parent: document.body,
  8232. // // add() {
  8233. // // return appCnt.createComponent_('yt-icon', {}, { })
  8234. // // },
  8235. // // remove(elm, parent) {
  8236.  
  8237. // // for(const p of elm.childNodes){
  8238. // // p.remove();
  8239. // // }
  8240. // // parent.removeChild(elm);
  8241.  
  8242. // // const cnt = insp(elm);
  8243.  
  8244. // // cnt.$ = null;
  8245. // // cnt.__dataInvalid = true;
  8246. // // cnt.__dataEnabled = false;
  8247. // // cnt.__dataReady = false;
  8248. // // cnt.data = {}; cnt.__data= {};
  8249. // // }
  8250. // // });
  8251.  
  8252.  
  8253. // // setup({
  8254. // // key: 'c1c',
  8255. // // parent: document.body,
  8256. // // add() {
  8257. // // return document.createElement('yt-icon')
  8258. // // },
  8259. // // remove(elm, parent) {
  8260.  
  8261. // // for(const p of elm.childNodes){
  8262. // // p.remove();
  8263. // // }
  8264. // // parent.removeChild(elm);
  8265.  
  8266. // // const cnt = insp(elm);
  8267.  
  8268. // // cnt.$ = null;
  8269. // // cnt.__dataInvalid = true;
  8270. // // cnt.__dataEnabled = false;
  8271. // // cnt.__dataReady = false;
  8272. // // cnt.data = {}; cnt.__data= {};
  8273. // // }
  8274. // // });
  8275.  
  8276.  
  8277. // // const dummyIcon = document.createElement('yt-icon');
  8278. // // setup({
  8279. // // key: 'c1d',
  8280. // // parent: document.documentElement,
  8281. // // add() {
  8282. // // const pt = Reflect.getPrototypeOf(dummyIcon);
  8283. // // const uu = {}
  8284. // // for(const key of Object.keys(pt)){
  8285. // // try{
  8286. // // if(typeof pt[key]==='function') uu[key] = pt[key];
  8287. // // }catch(e){}
  8288. // // }
  8289.  
  8290. // // const qkey = new Set([
  8291.  
  8292. // // // "_applyListeners",
  8293. // // // "ready",
  8294. // // // "registerActionMap",
  8295. // // // "unregisterActionMap",
  8296.  
  8297.  
  8298. // // // "constructor",
  8299.  
  8300.  
  8301. // // // "created",
  8302. // // // "_registered",
  8303. // // // "_ensureAttributes",
  8304. // // // "attached",
  8305. // // // "detached",
  8306. // // // "attributeChanged",
  8307. // // // "equals",
  8308. // // // "isEmpty",
  8309. // // // "onDarkModeToggledAction",
  8310. // // // "handlePropertyChange",
  8311. // // // "toggleContainerClass",
  8312. // // // "computeIcon",
  8313. // // // "determineIconSet",
  8314. // // // "switchToYtSysIconset",
  8315. // // // "getIconName",
  8316. // // // "useYtSysIconsetForMissingIcons",
  8317. // // // "onIconsetAdded",
  8318. // // // "getIconManager",
  8319. // // // "getIconShapeData",
  8320. // // // "shouldRenderIconShape",
  8321. // // // "renderIcon",
  8322. // // // "getContainer",
  8323. // // // "getTargetContainer",
  8324. // // // "applyStaticIcon",
  8325. // // // "applyIconShape",
  8326. // // // "removeIconShape",
  8327. // // // "removeStaticIcon",
  8328. // // // "applyAnimatedIcon",
  8329. // // // "removeAnimatedIcon",
  8330. // // // "handleError",
  8331. // // // "handlePropertyChange671",
  8332. // // // "determineIconSet671",
  8333. // // // "switchToYtSysIconset671",
  8334. // // // "useYtSysIconsetForMissingIcons671",
  8335. // // // "getIconManager671",
  8336. // // // "getIconShapeData671",
  8337. // // // "renderIcon671",
  8338. // // // "__refreshProps938__"
  8339. // // ]);
  8340.  
  8341.  
  8342. // // Object.keys(uu).forEach(key=>{
  8343. // // try{
  8344. // // if(key ==='ready' && 0){
  8345. // // pt[key]=function(){console.log('_OBJECT hello '+ key); debugger; uu.ready.call(this)}
  8346. // // }
  8347. // // else if(qkey.has(key)) pt[key]=function(){console.log('_OBJECT hello '+ key)}
  8348. // // }catch(E){}
  8349. // // });
  8350.  
  8351. // // EventTarget.prototype.addEventListener99320 = EventTarget.prototype.addEventListener;
  8352. // // EventTarget.prototype.addEventListener = function(){console.log('_OBJECT hello addEventListener!!')}
  8353.  
  8354.  
  8355. // // uu._runEffectsForTemplate = pt._runEffectsForTemplate;
  8356. // // uu._flushClients = pt._flushClients;
  8357. // // uu._readyClients = pt._readyClients;
  8358. // // uu._flushClients = pt._flushClients;
  8359. // // uu._attachDom = pt._attachDom;
  8360. // // const pva = function(a, b) {
  8361. // // return a.indexOf(b + ".") === 0
  8362. // // }
  8363. // // const jm = function(a, b) {
  8364. // // return b.indexOf(a + ".") === 0
  8365. // // }
  8366. // // const uva = function(a, b) {
  8367. // // if (b) {
  8368. // // var c = b.name;
  8369. // // return c == a || !(!b.structured || !pva(c, a)) || !(!b.wildcard || !jm(c, a))
  8370. // // }
  8371. // // return !0
  8372. // // }
  8373. // // const im = function(a) {
  8374. // // var b = a.indexOf(".");
  8375. // // return b === -1 ? a : a.slice(0, b)
  8376. // // }
  8377. // // const om = function(a, b, c, d, e, g) {
  8378. // // if (b) {
  8379. // // var k = !1, m = nm++, n;
  8380. // // for (n in c) {
  8381. // // var r = e ? im(n) : n;
  8382. // // if (r = b[r])
  8383. // // for (var t = 0, u = r.length, w = void 0; t < u && (w = r[t]); t++)
  8384. // // w.info && w.info.lastRun === m || e && !uva(n, w.trigger) || (w.info && (w.info.lastRun = m),
  8385. // // w.fn(a, n, c, d, w.info, e, g),
  8386. // // k = !0)
  8387. // // }
  8388. // // return k
  8389. // // }
  8390. // // return !1
  8391. // // }
  8392.  
  8393. // // pt._runEffectsForTemplate = function(c, d, e, g) {
  8394. // // console.log('_OBJECT hello _runEffectsForTemplate!! X')
  8395. // // let k = this;
  8396. // // let wr = new WeakRef(k);
  8397. // // let m = function (n, r) {
  8398. // // const k = wr.deref();
  8399. // // om(k, c.propertyEffects, n, e, r, c.nodeList);
  8400. // // for (var t = c.firstChild; t; t = t.nextSibling)
  8401. // // k._runEffectsForTemplate(t, n, e, r)
  8402. // // };
  8403. // // c.runEffects ? c.runEffects(m, d, g) : m(d, g)
  8404.  
  8405. // // }
  8406.  
  8407. // // pt._readyClients3828 = pt._readyClients;
  8408. // // pt._readyClients = function(){
  8409.  
  8410. // // console.log('_OBJECT hello _readyClients!! A', ...arguments )
  8411.  
  8412. // // // debugger;
  8413. // // this._attachDom(this.root);
  8414.  
  8415. // // const sr = standardWrap_(this).__shady_shadowRoot;
  8416.  
  8417. // // let t;
  8418. // // // while(t=sr.firstChild) sr.removeChild(t);
  8419. // // // console.log(133 )
  8420. // // // debugger;
  8421.  
  8422. // // this.root = null;
  8423.  
  8424. // // // this._template && (this.root = this._attachDom(this.root));
  8425. // // // this.__enableOrFlushClients()
  8426.  
  8427. // // // debugger;
  8428.  
  8429. // // // return this._readyClients3828(...arguments);
  8430. // // }
  8431. // // pt._flushClients = function(){
  8432. // // console.log('_OBJECT hello _flushClients!! Y', this.__dataClientsReady )
  8433. // // this.__dataClientsReady ? this.__enableOrFlushClients() : (this.__dataClientsReady = !0,
  8434. // // this._readyClients(),
  8435. // // this.__dataReady = !0)
  8436.  
  8437.  
  8438. // // }
  8439.  
  8440. // // pt.__cleanup__ = function(templateC){
  8441. // // const c = templateC
  8442. // // const d= c.templateInfo
  8443. // // const e = d.nodeList;
  8444. // // const g = d.nodeInfoList;
  8445. // // d.nodeList = null;
  8446. // // c.nodeList = null;
  8447. // // d.nodeInfoList= null;
  8448. // // c.templateInfo = null;
  8449.  
  8450. // // for(let k =0; k <g.length;i++ ){
  8451.  
  8452. // // const m = e[k];
  8453. // // const n =g[k].bindings;
  8454. // // e[k]=null;
  8455. // // g[k].bindings = null;
  8456. // // g[k]=null;
  8457. // // m.__dataHost = null;
  8458.  
  8459. // // }
  8460.  
  8461.  
  8462. // // }
  8463.  
  8464. // // uu._stampTemplate = pt._stampTemplate;
  8465. // // pt._stampTemplate359 = pt._stampTemplate;
  8466. // // pt._stampTemplate = function(c, d){
  8467. // // if(c===this._template && d === undefined){
  8468. // // console.log('_OBJECT 3882');
  8469.  
  8470.  
  8471. // // Array.prototype.push4882 = Array.prototype.push;
  8472.  
  8473. // // let eru = 0;
  8474. // // Array.prototype.push = function(){
  8475. // // if(eru >= 1) return;
  8476. // // this.push4882(...arguments);
  8477. // // }
  8478.  
  8479. // // Array.prototype.pop4882 = Array.prototype.pop;
  8480. // // Array.prototype.pop = function(){
  8481. // // eru++;
  8482. // // this.pop4882();
  8483. // // // throw new Error()
  8484. // // };
  8485.  
  8486. // // let templateC = null;
  8487. // // // debugger;
  8488. // // try{
  8489. // // templateC = this._stampTemplate359(...arguments)
  8490. // // }catch(e){
  8491. // // console.warn(e);
  8492. // // }
  8493. // // Array.prototype.pop=Array.prototype.pop4882;
  8494. // // Array.prototype.push=Array.prototype.push4882;
  8495.  
  8496.  
  8497. // // this.__cleanup__(templateC);
  8498.  
  8499. // // // throw new Error();
  8500.  
  8501. // // return templateC;
  8502.  
  8503.  
  8504.  
  8505. // // /*
  8506.  
  8507. // // d = d || this._bindTemplate(c, !0);
  8508. // // dC.push(this);
  8509. // // c = b.prototype._stampTemplate.call(this, c, d);
  8510. // // dC.pop();
  8511. // // d.nodeList = c.nodeList;
  8512. // // if (!d.wasPreBound)
  8513. // // for (var e = d.childNodes = [], g = c.firstChild; g; g = g.nextSibling)
  8514. // // e.push(g);
  8515. // // c.templateInfo = d;
  8516. // // e = d.nodeList;
  8517. // // g = d.nodeInfoList;
  8518. // // if (g.length)
  8519. // // for (var k = 0; k < g.length; k++) {
  8520. // // var m = e[k]
  8521. // // , n = g[k].bindings;
  8522. // // if (n)
  8523. // // for (var r = 0; r < n.length; r++) {
  8524. // // var t = n[r]
  8525. // // , u = m
  8526. // // , w = t;
  8527. // // if (w.isCompound) {
  8528. // // for (var A = u.__dataCompoundStorage || (u.__dataCompoundStorage = {}), C = w.parts, G = Array(C.length), J = 0; J < C.length; J++)
  8529. // // G[J] = C[J].literal;
  8530. // // C = w.target;
  8531. // // A[C] = G;
  8532. // // w.literal && w.kind == "property" && (C === "className" && (u = (0,
  8533. // // _.qm)(u)),
  8534. // // u[C] = w.literal)
  8535. // // }
  8536. // // Gva(m, this, t)
  8537. // // }
  8538. // // m.__dataHost = this
  8539. // // }
  8540. // // this.__dataClientsReady && (this._runEffectsForTemplate(d, this.__data, null, !1),
  8541. // // this._flushClients());
  8542. // // return c
  8543.  
  8544.  
  8545.  
  8546. // // */
  8547.  
  8548.  
  8549. // // }else{
  8550. // // return this._stampTemplate359(...arguments)
  8551. // // }
  8552. // // }
  8553.  
  8554. // // console.log('_OBJECT keys', Object.keys(uu))
  8555.  
  8556. // // try{
  8557. // // document.documentElement.insertAdjacentHTML('beforeend', ttpHTML('<yt-icon></yt-icon>'));
  8558. // // }catch(e){}
  8559. // // const r = document.documentElement.lastChild;
  8560.  
  8561.  
  8562.  
  8563. // // const sw = standardWrap_(r);
  8564. // // // debugger;
  8565. // // sw.node.__shady_shadowRoot = null
  8566.  
  8567. // // EventTarget.prototype.addEventListener = EventTarget.prototype.addEventListener99320;
  8568.  
  8569. // // Object.keys(uu).forEach(key=>{
  8570. // // try{
  8571. // // pt[key]=uu[key]
  8572.  
  8573. // // }catch(e){}
  8574. // // });
  8575. // // return r;
  8576. // // },
  8577. // // remove(elm, parent) {
  8578.  
  8579.  
  8580. // // const cnt = insp(elm);
  8581. // // try{
  8582.  
  8583. // // cnt.unregisterActionMap(cnt.actionMap);
  8584. // // }catch(e){}
  8585. // // try{
  8586.  
  8587. // // elm.unregisterActionMap(elm.actionMap);
  8588. // // }catch(e){}
  8589.  
  8590.  
  8591.  
  8592. // // const sr = elm.__shady_shadowRoot;
  8593.  
  8594. // // let t;
  8595. // // while(t=sr.firstChild) {
  8596. // // try{
  8597.  
  8598. // // sr.removeChild(t);
  8599. // // }catch(e){
  8600. // // console.warn(e)
  8601. // // }
  8602. // // }
  8603.  
  8604. // // for(const p of elm.childNodes){
  8605. // // p.remove();
  8606. // // }
  8607. // // parent.removeChild(elm);
  8608.  
  8609. // // try{
  8610.  
  8611. // // cnt.__cleanup__();
  8612. // // }catch(e){}
  8613. // // try{
  8614.  
  8615. // // elm.__cleanup__();
  8616. // // }catch(e){}
  8617.  
  8618.  
  8619. // // for(let k in sr){
  8620. // // try{
  8621. // // sr[k] = null;
  8622. // // }catch(e){}
  8623. // // }
  8624.  
  8625. // // cnt.$.root = null;
  8626.  
  8627. // // cnt.$ = null;
  8628. // // cnt.__dataInvalid = true;
  8629. // // cnt.__dataEnabled = false;
  8630. // // cnt.__dataReady = false;
  8631. // // cnt.data = {}; cnt.__data= {};
  8632.  
  8633.  
  8634. // // console.log('TRY_OBJECT qq')
  8635. // // }
  8636. // // });
  8637.  
  8638.  
  8639.  
  8640. // // setup({
  8641. // // key: 'c1e',
  8642. // // parent: document.documentElement,
  8643. // // add() {
  8644. // // document.documentElement.insertAdjacentElement('beforeend', document.createElement('yt-icon'));
  8645. // // return document.documentElement.lastChild;
  8646. // // },
  8647. // // remove(elm, parent) {
  8648.  
  8649. // // for(const p of elm.childNodes){
  8650. // // p.remove();
  8651. // // }
  8652. // // parent.removeChild(elm);
  8653.  
  8654. // // const cnt = insp(elm);
  8655.  
  8656. // // cnt.$ = null;
  8657. // // cnt.__dataInvalid = true;
  8658. // // cnt.__dataEnabled = false;
  8659. // // cnt.__dataReady = false;
  8660. // // cnt.data = {}; cnt.__data= {};
  8661. // // }
  8662. // // });
  8663. // // setup({
  8664. // // key: 'c2',
  8665. // // parent: document.body,
  8666. // // add() {
  8667. // // return appCnt.createComponent_('dummy-3mk', {}, false);
  8668. // // },
  8669. // // remove(elm, parent) {
  8670. // // setTimeout(()=>{
  8671. // // removeTNodeRM && removeTNodeRM(elm);
  8672. // // });
  8673. // // }
  8674. // // });
  8675. // // setup({
  8676. // // key: 'c3',
  8677. // // parent: document.body,
  8678. // // add() {
  8679. // // return appCnt.createComponent_('dummy-3mk', {}, false);
  8680. // // },
  8681. // // remove(elm, parent) {
  8682. // // elm.remove();
  8683. // // }
  8684. // // });
  8685.  
  8686.  
  8687. // // // const p = document.querySelector('#upload-info yt-icon[size].style-scope.ytd-badge-supported-renderer');
  8688. // // document.querySelector('#upload-info yt-icon[size].style-scope.ytd-badge-supported-renderer') && setup({
  8689. // // key: 'c4',
  8690. // // parent: document.querySelector('#upload-info yt-icon[size].style-scope.ytd-badge-supported-renderer').parentNode,
  8691. // // add() {
  8692. // // return document.querySelector('#upload-info yt-icon[size].style-scope.ytd-badge-supported-renderer');
  8693. // // },
  8694. // // remove(elm, parent) {
  8695. // // elm.remove();
  8696. // // }
  8697. // // });
  8698.  
  8699. // // window.jmksmks =j1;
  8700.  
  8701.  
  8702. // // console.log('YYY_OBJECT')
  8703.  
  8704. // // }, 5000)
  8705.  
  8706.  
  8707. // qcMaps = null;
  8708.  
  8709. // });
  8710.  
  8711.  
  8712. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  8713.  
  8714. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  8715.  
  8716. const app = await observablePromise(() => {
  8717.  
  8718. return document.querySelector(appTag);
  8719.  
  8720. }).obtain();
  8721.  
  8722. if (!app) return;
  8723.  
  8724. const appCnt = insp(app);
  8725. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  8726.  
  8727.  
  8728.  
  8729.  
  8730. });
  8731.  
  8732. const observablePromise = (proc, timeoutPromise) => {
  8733. let promise = null;
  8734. return {
  8735. obtain() {
  8736. if (!promise) {
  8737. promise = new Promise(resolve => {
  8738. let mo = null;
  8739. const f = () => {
  8740. let t = proc();
  8741. if (t) {
  8742. mo.disconnect();
  8743. mo.takeRecords();
  8744. mo = null;
  8745. resolve(t);
  8746. }
  8747. }
  8748. mo = new MutationObserver(f);
  8749. mo.observe(document, { subtree: true, childList: true })
  8750. f();
  8751. timeoutPromise && timeoutPromise.then(() => {
  8752. resolve(null)
  8753. });
  8754. });
  8755. }
  8756. return promise
  8757. }
  8758. }
  8759. }
  8760.  
  8761. // let _yt_player_promise = null;
  8762. /*
  8763. const getYtPlayerPromise = () => {
  8764. if (!_yt_player_promise) {
  8765. _yt_player_promise = new Promise(resolve => {
  8766. let cid = setInterval(() => {
  8767. let t = (((window || 0)._yt_player || 0) || 0);
  8768. if (t) {
  8769. clearInterval(cid);
  8770. resolve(t);
  8771. }
  8772. }, 1);
  8773. promiseForTamerTimeout.then(() => {
  8774. resolve(null)
  8775. });
  8776. });
  8777. }
  8778. return _yt_player_promise;
  8779. }
  8780. */
  8781. const _yt_player_observable = observablePromise(() => {
  8782. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  8783. if (_yt_player) {
  8784. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  8785. return _yt_player;
  8786. }
  8787. }, promiseForTamerTimeout);
  8788.  
  8789. const polymerObservable = observablePromise(() => {
  8790. const Polymer = window.Polymer;
  8791. if (typeof Polymer !== 'function') return;
  8792. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  8793. return Polymer;
  8794. }, promiseForTamerTimeout);
  8795.  
  8796. const schedulerInstanceObservable = observablePromise(() => {
  8797. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  8798. }, promiseForTamerTimeout);
  8799.  
  8800. const timelineObservable = observablePromise(() => {
  8801. let t = (((document || 0).timeline || 0) || 0);
  8802. if (t && typeof t._play === 'function') {
  8803. return t;
  8804. }
  8805. }, promiseForTamerTimeout);
  8806. const animationObservable = observablePromise(() => {
  8807. let t = (((window || 0).Animation || 0) || 0);
  8808. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  8809. return t;
  8810. }
  8811. }, promiseForTamerTimeout);
  8812.  
  8813.  
  8814. const getScreenInfo = {
  8815. screenWidth: 0,
  8816. screenHeight: 0,
  8817. valueReady: false,
  8818. onResize: () => {
  8819. getScreenInfo.valueReady = false;
  8820. },
  8821. sizeProvided: () => {
  8822. if (getScreenInfo.valueReady) return true;
  8823. getScreenInfo.screenWidth = screen.width;
  8824. getScreenInfo.screenHeight = screen.height;
  8825. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  8826. getScreenInfo.valueReady = true;
  8827. return true;
  8828. }
  8829. return false;
  8830. }
  8831. };
  8832.  
  8833. window.addEventListener('resize', getScreenInfo.onResize, true);
  8834.  
  8835.  
  8836. // const hookLeftPending = new WeakMap();
  8837.  
  8838. const isNaNx = Number.isNaN;
  8839.  
  8840. const hookLeftPD = {
  8841. get() {
  8842. const p = 'left';
  8843. // const o = hookLeftPending.get(this);
  8844. // if (o && o.key) {
  8845. // this.setProperty(p, o.value);
  8846. // o.key = null
  8847. // }
  8848. return this.getPropertyValue(p);
  8849. },
  8850. set(v) {
  8851.  
  8852. const p = 'left';
  8853. const cv = this.getPropertyValue(p);
  8854. const sv = v;
  8855.  
  8856. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  8857.  
  8858. // console.log(8380,did, cv, sv)
  8859. if (!cv && !sv) return true;
  8860. if (cv === sv) return true;
  8861.  
  8862. // skip 0~9px => L>=4
  8863.  
  8864. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  8865.  
  8866. if (!isNaNx(qsv)) {
  8867. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  8868.  
  8869. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  8870. const { screenWidth, screenHeight } = getScreenInfo;
  8871. let pWidth = screenWidth + 1024;
  8872. let pHeight = screenHeight + 768;
  8873. const minRatio = 0.003;
  8874. const dw = pWidth * 0.0003; // min dw = 0.3072
  8875. const dh = pHeight * 0.0003; // min dh = 0.2304
  8876. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  8877. if (Math.abs(qcv - qsv) < dw) return true;
  8878. }
  8879.  
  8880. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  8881. if (`${v}`.length > `${sv}`.length) v = sv;
  8882. // console.log(8382, did, sv, nv, cv, this)
  8883. }
  8884.  
  8885. // Promise.resolve().then(() => {
  8886. // const o = hookLeftPending.get(this);
  8887. // if (o && o.key === did) {
  8888. // this.setProperty(p, o.value);
  8889. // o.key = null;
  8890. // }
  8891. // });
  8892. // hookLeftPending.set(this, {
  8893. // key: did,
  8894. // value: nv
  8895. // });
  8896.  
  8897. // if (nv != v) {
  8898. // console.log(8387, v, nv);
  8899. // }
  8900.  
  8901. this.setProperty(p, v);
  8902. // console.log(8383, did, this.getPropertyValue(p))
  8903. return true;
  8904. },
  8905. enumerable: true,
  8906. configurable: true
  8907. };
  8908.  
  8909.  
  8910. if (HOOK_CSSPD_LEFT) {
  8911.  
  8912.  
  8913. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  8914.  
  8915. }
  8916.  
  8917.  
  8918.  
  8919.  
  8920.  
  8921. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  8922.  
  8923. const evKey = `${_evKey}`;
  8924. const fvKey = `${_fvKey}`;
  8925. const debug = !!_debug;
  8926.  
  8927. const _yt_player = await _yt_player_observable.obtain();
  8928.  
  8929.  
  8930. if (!_yt_player || typeof _yt_player !== 'object') return;
  8931.  
  8932.  
  8933. const getArr = (_yt_player) => {
  8934.  
  8935. let arr = [];
  8936.  
  8937. for (const [k, v] of Object.entries(_yt_player)) {
  8938.  
  8939. const p = typeof v === 'function' ? v.prototype : 0;
  8940. if (p
  8941. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  8942.  
  8943. ) {
  8944. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8945.  
  8946. }
  8947.  
  8948. }
  8949.  
  8950. if (arr.length === 0) {
  8951.  
  8952. console.warn(`Key prop [${evKey}] does not exist.`);
  8953. } else {
  8954.  
  8955. return arr;
  8956. }
  8957.  
  8958. };
  8959.  
  8960. const arr = getArr(_yt_player);
  8961.  
  8962.  
  8963. if (!arr) return;
  8964.  
  8965. debug && console.log(`FIX_${evKey}`, arr);
  8966.  
  8967. const f = function (...args) {
  8968. Promise.resolve().then(() => this[fvKey](...args));
  8969. };
  8970.  
  8971.  
  8972. for (const k of arr) {
  8973.  
  8974. const g = _yt_player;
  8975. const gk = g[k];
  8976. const gkp = gk.prototype;
  8977.  
  8978. debug && console.log(237, k, gkp)
  8979.  
  8980. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  8981. gkp[fvKey] = gkp[evKey];
  8982. gkp[evKey] = f;
  8983. }
  8984. }
  8985.  
  8986.  
  8987.  
  8988.  
  8989. }
  8990.  
  8991. if (!isChatRoomURL) {
  8992.  
  8993. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  8994. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  8995. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  8996. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  8997. if (FIX_VideoEVENTS_v2) {
  8998. const FIX_VideoEVENTS_DEBUG = 0;
  8999. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  9000. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  9001. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  9002. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  9003. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  9004. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  9005. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  9006. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  9007. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  9008.  
  9009. }
  9010. // onMutedAutoplayChange
  9011. // onVolumeChange
  9012. // onPlaybackRateChange
  9013.  
  9014. // onAirPlayActiveChange
  9015. // onAirPlayAvailabilityChange
  9016. // onApiChange
  9017. // onAutoplayBlocked
  9018. // onDrmOutputRestricted
  9019. // onFullscreenChange
  9020. // onLoadProgress
  9021. // onLoadedMetadata
  9022. // onVideoDataChange
  9023. // onVideoProgress
  9024.  
  9025. }
  9026.  
  9027.  
  9028.  
  9029. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_stampDomArray ) && (async () => {
  9030.  
  9031. const Polymer = await polymerObservable.obtain();
  9032. if (!Polymer) return;
  9033.  
  9034. if (FIX_Polymer_dom) {
  9035.  
  9036. const checkPDFuncValue = (pd) => {
  9037. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  9038. }
  9039. const checkPDFuncValue2 = (pd) => {
  9040. return pd && typeof pd.value == 'function'
  9041. }
  9042.  
  9043. const checkPDFuncGet = (pd) => {
  9044. return pd && typeof pd.get == 'function'
  9045. }
  9046.  
  9047. const domX = Polymer.dom(document.createElement('null'));
  9048. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  9049. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  9050. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  9051. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  9052. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  9053. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  9054. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  9055. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  9056. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  9057.  
  9058.  
  9059. // getOwnerRoot - to be reviewed
  9060. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  9061.  
  9062. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  9063. domXP.getOwnerRoot = function () {
  9064. try {
  9065. const p = this.node;
  9066.  
  9067. if (p instanceof HTMLElement_) {
  9068. const pp = pd2.get.call(p);
  9069. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  9070. return pp.getRootNode();
  9071. }
  9072.  
  9073. }
  9074. } catch (e) { }
  9075. return this.getOwnerRoot15();
  9076. }
  9077.  
  9078. Polymer.__fixedGetOwnerRoot__ = 1;
  9079. }
  9080.  
  9081.  
  9082.  
  9083.  
  9084. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  9085.  
  9086. domXP.querySelector15 = domXP.querySelector;
  9087.  
  9088. const querySelectorFn = function (query) {
  9089. try {
  9090. const p = this.node;
  9091.  
  9092. if (p instanceof Document && p.isConnected === true) {
  9093. return pd4b.value.call(p, query);
  9094. }
  9095.  
  9096. } catch (e) { }
  9097. return this.querySelector15(query);
  9098. }
  9099.  
  9100. Object.defineProperty(domXP, 'querySelector', {
  9101. get() {
  9102. return querySelectorFn;
  9103. },
  9104. set(nv) {
  9105. if (nv === querySelectorFn) return true;
  9106. this.querySelector15 = nv;
  9107. return true;
  9108. },
  9109.  
  9110. enumerable: false,
  9111. configurable: true
  9112. });
  9113.  
  9114. Polymer.__fixedQuerySelector__ = 1;
  9115. }
  9116.  
  9117. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  9118.  
  9119. domXP.querySelectorAll15 = domXP.querySelectorAll;
  9120.  
  9121. const querySelectorAllFn = function (query) {
  9122.  
  9123. try {
  9124.  
  9125. const p = this.node;
  9126.  
  9127. if (p instanceof Document && p.isConnected === true) {
  9128. return pd6b.value.call(p, query);
  9129. }
  9130.  
  9131. } catch (e) {
  9132.  
  9133. }
  9134. return this.querySelectorAll15(query);
  9135. }
  9136.  
  9137. Object.defineProperty(domXP, 'querySelectorAll', {
  9138. get() {
  9139. return querySelectorAllFn;
  9140. },
  9141. set(nv) {
  9142. if (nv === querySelectorAllFn) return true;
  9143. this.querySelectorAll15 = nv;
  9144. return true;
  9145. },
  9146.  
  9147. enumerable: false,
  9148. configurable: true
  9149. });
  9150.  
  9151. Polymer.__fixedQuerySelectorAll__ = 1;
  9152. }
  9153. }
  9154.  
  9155.  
  9156. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  9157.  
  9158. Polymer.Base.__connInit__ = function () {
  9159. setupYtComponent(this);
  9160. }
  9161.  
  9162.  
  9163. /** @type {Function} */
  9164. const connectedCallbackK = function (...args) {
  9165. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9166. const r = this[qm53](...args);
  9167. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9168. this.mh35 = 1;
  9169. return r;
  9170. };
  9171.  
  9172. connectedCallbackK.m353 = 1;
  9173.  
  9174.  
  9175. const qt53 = Polymer.Base.connectedCallback;
  9176. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  9177.  
  9178. Polymer.Base.connectedCallback = connectedCallbackK;
  9179.  
  9180.  
  9181. /** @type {Function} */
  9182. const createdK = function (...args) {
  9183. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9184. const r = this[qn53](...args);
  9185. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9186. this.mh36 = 1;
  9187. return r;
  9188. };
  9189.  
  9190.  
  9191. createdK.m353 = 1;
  9192. Polymer.Base[qn53] = Polymer.Base.created;
  9193. Polymer.Base.created = createdK;
  9194.  
  9195. }
  9196.  
  9197. })();
  9198.  
  9199.  
  9200. /*
  9201.  
  9202. e.nativeAppendChild = d.prototype.appendChild,
  9203. d.prototype.appendChild = function(h) {
  9204. return function(l) {
  9205. if (l instanceof DocumentFragment) {
  9206. var m = Array.from(l.children);
  9207. l = h.nativeAppendChild.call(this, l);
  9208. if (this.isConnected) {
  9209. m = g(m);
  9210. for (var p = m.next(); !p.done; p = m.next())
  9211. YD(p.value)
  9212. }
  9213. return l
  9214. }
  9215. m = l instanceof Element && l.isConnected;
  9216. p = h.nativeAppendChild.call(this, l);
  9217. m && ZD(l);
  9218. this.isConnected && YD(l);
  9219. return p
  9220. }
  9221. }(e),
  9222.  
  9223. */
  9224.  
  9225. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  9226.  
  9227. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  9228. if (f) Node.prototype.appendChild = function (a) {
  9229. if (this instanceof Element) { // exclude DocumentFragment
  9230. try {
  9231. let checkFragmentA = (a instanceof DocumentFragment);
  9232. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  9233. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  9234. for (const node of headLinkCollection) {
  9235. if (node.rel === 'preload' && node.as === 'fetch') {
  9236. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  9237. }
  9238. }
  9239. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  9240. checkFragmentA = false;
  9241. }
  9242. if (checkFragmentA && a.firstElementChild === null) {
  9243. // no element in fragmentA
  9244. let doNormal = false;
  9245. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  9246. if (child.nodeType === 3) { doNormal = true; break; }
  9247. }
  9248. if (!doNormal) return a;
  9249. }
  9250. } catch (e) {
  9251. console.log(e);
  9252. }
  9253. }
  9254. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  9255. }
  9256.  
  9257. })();
  9258.  
  9259. if (FIX_Shady) {
  9260.  
  9261. observablePromise(() => {
  9262. const { ShadyDOM, ShadyCSS } = window;
  9263. if (ShadyDOM) {
  9264. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  9265. ShadyDOM.noPatch = true; // 1 of 10
  9266. ShadyDOM.patchOnDemand = false; // 1 of 10
  9267. ShadyDOM.preferPerformance = true; // 1 of 10
  9268. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  9269. }
  9270. if (ShadyCSS) {
  9271. ShadyCSS.nativeCss = true; // 1 of 10
  9272. ShadyCSS.nativeShadow = true; // 6 of 10
  9273. ShadyCSS.cssBuild = undefined; // 1 of 10
  9274. ShadyCSS.disableRuntime = true; // 1 of 10
  9275. }
  9276. if (ShadyDOM && ShadyCSS) return 1;
  9277. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  9278.  
  9279. }
  9280.  
  9281.  
  9282. // let schedulerInstancePropOfTimerType = '';
  9283. // let schedulerInstancePropOfTimerId = '';
  9284. (FIX_schedulerInstanceInstance & 2) && (async () => {
  9285.  
  9286. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  9287.  
  9288. if (!schedulerInstanceInstance_) return;
  9289.  
  9290. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  9291. if (checkOK) {
  9292.  
  9293. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  9294.  
  9295. let requestingFn = null;
  9296. let requestingArgs = null;
  9297.  
  9298. const f = function () {
  9299. requestingFn = this.fn;
  9300. requestingArgs = [...arguments];
  9301. return 12373;
  9302. };
  9303.  
  9304. const fakeFns = [
  9305. f.bind({ fn: requestAnimationFrame }),
  9306. f.bind({ fn: setInterval }),
  9307. f.bind({ fn: setTimeout }),
  9308. f.bind({ fn: requestIdleCallback })
  9309. ];
  9310.  
  9311. let mzt = 0;
  9312.  
  9313. let _fnSelectorProp = null;
  9314. const mkFns = new Array(4);
  9315.  
  9316. /*
  9317. case 1:
  9318. var a = this.K;
  9319. this.g = this.I ? window.requestIdleCallback(a, {
  9320. timeout: 3E3
  9321. }) : window.setTimeout(a, ma);
  9322. break;
  9323. case 2:
  9324. this.g = window.setTimeout(this.M, this.N);
  9325. break;
  9326. case 3:
  9327. this.g = window.requestAnimationFrame(this.L);
  9328. break;
  9329. case 4:
  9330. this.g = window.setTimeout(this.J, 0)
  9331. }
  9332.  
  9333. */
  9334. const startFnHandler = {
  9335. get(target, prop, receiver) {
  9336. if (prop === '$$12377$$') return true;
  9337. if (prop === '$$12378$$') return target;
  9338.  
  9339. // console.log('get',prop)
  9340. return target[prop]
  9341. },
  9342. set(target, prop, value, receiver) {
  9343. // console.log('set', prop, value)
  9344.  
  9345. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  9346. if (value === 12373 && _fnSelectorProp) {
  9347.  
  9348. const schedulerTypeSelection = target[_fnSelectorProp];
  9349. const timerIdProp = prop;
  9350.  
  9351. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  9352. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  9353. // schedulerInstancePropOfTimerId = timerIdProp || '';
  9354. // }
  9355.  
  9356. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  9357. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  9358. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  9359. // rare
  9360. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9361. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  9362. // often
  9363. if ((FIX_schedulerInstanceInstance & 4)) {
  9364. const f = requestingArgs[0];
  9365. const tir = ++mzt;
  9366. nextBrowserTick_(() => {
  9367. if (target[timerIdProp] === -tir) f();
  9368. });
  9369. target[_fnSelectorProp] = 940;
  9370. target[timerIdProp] = -tir;
  9371. } else {
  9372. const f = requestingArgs[0];
  9373. const tir = ++mzt;
  9374. Promise.resolve().then(() => {
  9375. if (target[timerIdProp] === -tir) f();
  9376. });
  9377. target[_fnSelectorProp] = 930;
  9378. target[timerIdProp] = -tir;
  9379. }
  9380. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  9381. // often
  9382. if (requestingFn === requestIdleCallback) {
  9383. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  9384. } else {
  9385. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9386. }
  9387. } else {
  9388. target[_fnSelectorProp] = 0;
  9389. target[timerIdProp] = 0;
  9390. }
  9391. } else {
  9392. target[prop] = value;
  9393. }
  9394. return true;
  9395. }
  9396. };
  9397.  
  9398. let startBusy = false;
  9399. schedulerInstanceInstance_.start = function () {
  9400. if (startBusy) return;
  9401. startBusy = true;
  9402. try {
  9403. mkFns[0] = window.requestAnimationFrame;
  9404. mkFns[1] = window.setInterval;
  9405. mkFns[2] = window.setTimeout;
  9406. mkFns[3] = window.requestIdleCallback;
  9407. const tThis = this['$$12378$$'] || this;
  9408. window.requestAnimationFrame = fakeFns[0]
  9409. window.setInterval = fakeFns[1]
  9410. window.setTimeout = fakeFns[2]
  9411. window.requestIdleCallback = fakeFns[3]
  9412. _fnSelectorProp = null;
  9413. tThis.start993.call(new Proxy(tThis, startFnHandler));
  9414. _fnSelectorProp = null;
  9415. window.requestAnimationFrame = mkFns[0];
  9416. window.setInterval = mkFns[1];
  9417. window.setTimeout = mkFns[2];
  9418. window.requestIdleCallback = mkFns[3];
  9419. } catch (e) {
  9420. console.warn(e);
  9421. }
  9422. startBusy = false;
  9423. }
  9424.  
  9425. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  9426.  
  9427. }
  9428. })();
  9429.  
  9430. FIX_yt_player && !isChatRoomURL && (async () => {
  9431.  
  9432. const fOption = 1 | 2 | 4;
  9433.  
  9434. const _yt_player = await _yt_player_observable.obtain();
  9435.  
  9436. if (!_yt_player || typeof _yt_player !== 'object') return;
  9437.  
  9438. const g = _yt_player;
  9439. let k;
  9440.  
  9441. if (fOption & 1) {
  9442.  
  9443. // rAf scheduling
  9444.  
  9445. const keyZqOu = getZqOu(_yt_player);
  9446. if (!keyZqOu) {
  9447. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  9448. return;
  9449. }
  9450. k = keyZqOu
  9451.  
  9452. const gk = g[k];
  9453. if (typeof gk !== 'function') {
  9454. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  9455. return;
  9456. }
  9457. const gkp = gk.prototype;
  9458.  
  9459. const dummyObject = new gk;
  9460. const nilFunc = () => { };
  9461.  
  9462. const nilObj = {};
  9463.  
  9464. // console.log(1111111111)
  9465.  
  9466. let keyBoolD = '';
  9467. let keyWindow = '';
  9468. let keyFuncC = '';
  9469. let keyCidj = '';
  9470.  
  9471. for (const [t, y] of Object.entries(dummyObject)) {
  9472. if (y instanceof Window) keyWindow = t;
  9473. }
  9474.  
  9475. const dummyObjectProxyHandler = {
  9476. get(target, prop) {
  9477. let v = target[prop]
  9478. if (v instanceof Window && !keyWindow) {
  9479. keyWindow = t;
  9480. }
  9481. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  9482. if (prop === keyWindow) y = {
  9483. requestAnimationFrame(f) {
  9484. return 3;
  9485. },
  9486. cancelAnimationFrame() {
  9487.  
  9488. }
  9489. }
  9490. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  9491. keyFuncC = prop;
  9492. }
  9493. // console.log('[get]', prop, typeof target[prop])
  9494.  
  9495.  
  9496. return y;
  9497. },
  9498. set(target, prop, value) {
  9499.  
  9500. if (typeof value === 'boolean' && !keyBoolD) {
  9501. keyBoolD = prop;
  9502. }
  9503. if (typeof value === 'number' && !keyCidj && value >= 2) {
  9504. keyCidj = prop;
  9505. }
  9506.  
  9507. // console.log('[set]', prop, value)
  9508. target[prop] = value;
  9509.  
  9510. return true;
  9511. }
  9512. };
  9513.  
  9514. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  9515.  
  9516. // console.log('gkp.start',gkp.start);
  9517. // console.log('gkp.stop',gkp.stop);
  9518. gkp._activation = false;
  9519.  
  9520. gkp.start = function () {
  9521. // p59 || console.log(12100)
  9522. if (!this._activation) {
  9523. this._activation = true;
  9524. foregroundPromiseFn().then(() => {
  9525. this._activation = false;
  9526. if (this[keyCidj]) {
  9527. Promise.resolve().then(this[keyFuncC]);
  9528. }
  9529. });
  9530. }
  9531. this[keyCidj] = 1;
  9532. this[keyBoolD] = true;
  9533. };
  9534.  
  9535. gkp.stop = function () {
  9536. this[keyCidj] = null;
  9537. };
  9538.  
  9539.  
  9540. /*
  9541. g[k].start = function() {
  9542. this.stop();
  9543. this.D = true;
  9544. var a = requestAnimationFrame
  9545. , b = cancelAnimationFrame;
  9546. this.j = a.call(this.B, this.C)
  9547. }
  9548. ;
  9549. g[k].stop = function() {
  9550. if (this.isActive()) {
  9551. var a = requestAnimationFrame
  9552. , b = cancelAnimationFrame;
  9553. b.call(this.B, this.j)
  9554. }
  9555. this.j = null
  9556. }
  9557. */
  9558. }
  9559.  
  9560. if (fOption & 2) {
  9561. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  9562.  
  9563. if (keyzo) {
  9564.  
  9565. k = keyzo;
  9566.  
  9567. const attrUpdateFn = g[k];
  9568. // console.log(5992, attrUpdateFn)
  9569. g['$$original$$' + k] = attrUpdateFn;
  9570. const zoTransform = async (a, c) => {
  9571.  
  9572. let transformType = '';
  9573. let transformValue = 0;
  9574. let transformUnit = '';
  9575. let transformTypeI = 0;
  9576.  
  9577. const aStyle = a.style;
  9578.  
  9579. let cType = 0;
  9580.  
  9581. const cl = c.length;
  9582.  
  9583. if (cl >= 8) {
  9584. // scale(1)
  9585. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  9586. cType = 1;
  9587. let t = c.charCodeAt(5);
  9588. if (t === 88 || t === 120) cType = 1 | 4;
  9589. if (t === 89 || t === 121) cType = 1 | 8;
  9590. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  9591. cType = 2;
  9592. let t = c.charCodeAt(9);
  9593. if (t === 88 || t === 120) cType = 2 | 4;
  9594. if (t === 89 || t === 121) cType = 2 | 8;
  9595. }
  9596. let w = 0;
  9597. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  9598. let p = c.substring(7, cl - 1);
  9599. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9600. if (typeof q === 'number' && !isNaNx(q)) {
  9601. transformType = w === 1 ? 'scaleX' : 'scaleY';
  9602. transformValue = q;
  9603. transformUnit = '';
  9604. transformTypeI = 1;
  9605. } else {
  9606. cType = 256;
  9607. }
  9608. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  9609. if (c.endsWith('px)')) {
  9610. let p = c.substring(11, cl - 3);
  9611. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9612. if (typeof q === 'number' && !isNaNx(q)) {
  9613. transformType = w === 1 ? 'translateX' : 'translateY';
  9614. transformValue = q;
  9615. transformUnit = 'px';
  9616. transformTypeI = 2;
  9617. } else if (p === 'NaN') {
  9618. return;
  9619. }
  9620. } else {
  9621. cType = 256;
  9622. }
  9623. } else if (cType > 0) {
  9624. cType = 256;
  9625. }
  9626. }
  9627.  
  9628.  
  9629. if (cType === 256) {
  9630. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  9631. }
  9632.  
  9633. if (transformTypeI === 1) {
  9634. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  9635. const vz = toFixed2(q, 3);
  9636. c = `${transformType}(${vz})`;
  9637. const cv = aStyle.transform;
  9638. if (c === cv) return;
  9639. aStyle.transform = c;
  9640. } else if (transformTypeI === 2) {
  9641. const q = transformValue;
  9642. const vz = toFixed2(q, 1);
  9643. c = `${transformType}(${vz}${transformUnit})`;
  9644. const cv = aStyle.transform;
  9645. if (c === cv) return;
  9646. aStyle.transform = c;
  9647. } else { // eg empty
  9648. const cv = aStyle.transform;
  9649. if (!c && !cv) return;
  9650. else if (c === cv) return;
  9651. aStyle.transform = c;
  9652. }
  9653.  
  9654. };
  9655.  
  9656. const elmTransformTemp = new WeakMap();
  9657. const elmPropTemps = {
  9658. 'display': new WeakMap(),
  9659. 'width': new WeakMap(),
  9660. 'height': new WeakMap(),
  9661. 'outlineWidth': new WeakMap(),
  9662. 'position': new WeakMap(),
  9663. 'padding': new WeakMap(),
  9664. "cssText": new WeakMap(),
  9665. "right": new WeakMap(),
  9666. "left": new WeakMap(),
  9667. "top": new WeakMap(),
  9668. "bottom": new WeakMap(),
  9669. "transitionDelay": new WeakMap(),
  9670. "marginLeft": new WeakMap(),
  9671. "marginTop": new WeakMap(),
  9672. "marginRight": new WeakMap(),
  9673. "marginBottom": new WeakMap(),
  9674. }
  9675.  
  9676. const ns5 = Symbol();
  9677. const nextModify = (a, c, m, f, immediate) => {
  9678. const a_ = a;
  9679. const m_ = m;
  9680. const noKey = !m_.has(a_);
  9681. if (immediate || noKey) {
  9682. m_.set(a_, ns5);
  9683. f(a_, c);
  9684. noKey && nextBrowserTick_(() => {
  9685. const d = m_.get(a_);
  9686. if (d === undefined) return;
  9687. m_.delete(a_);
  9688. if (d !== ns5) f(a_, d);
  9689. });
  9690. } else {
  9691. m_.set(a_, c);
  9692. }
  9693. };
  9694.  
  9695. const set66 = new Set();
  9696. const log77 = new Map();
  9697. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  9698.  
  9699. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  9700.  
  9701. // console.log(140000, a, b, c);
  9702. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  9703. const num = c;
  9704. c = `${num}`;
  9705. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  9706. }
  9707.  
  9708. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  9709.  
  9710. let elmPropTemp = null;
  9711.  
  9712. if (b === "transform") {
  9713. // div.ytp-hover-progress.ytp-hover-progress-light
  9714. // div.ytp-play-progress.ytp-swatch-background-color
  9715.  
  9716. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  9717. return;
  9718.  
  9719. } else if (elmPropTemp = elmPropTemps[b]) {
  9720.  
  9721. // if (c.length > 5 && c.includes('.')) {
  9722. // console.log(123213, c)
  9723. // }
  9724.  
  9725. const b_ = b;
  9726. nextModify(a, c, elmPropTemp, (a, c) => {
  9727. const style = a.style;
  9728. const cv = style[b_];
  9729. if (!cv && !c) return;
  9730. if (cv === c) return;
  9731. style[b_] = c;
  9732. }, immediateChange);
  9733. return;
  9734.  
  9735. } else if (b === "outline-width") {
  9736.  
  9737. const b_ = 'outlineWidth';
  9738. elmPropTemp = elmPropTemps[b_];
  9739. nextModify(a, c, elmPropTemp, (a, c) => {
  9740. const style = a.style;
  9741. const cv = style[b_];
  9742. if (!cv && !c) return;
  9743. if (cv === c) return;
  9744. style[b_] = c;
  9745. }, immediateChange);
  9746. return;
  9747.  
  9748. } else if (b === 'maxWidth' || b === 'maxHeight') {
  9749. // I think these can be directly assigned.
  9750.  
  9751. const b_ = b;
  9752. const style = a.style;
  9753. const cv = style[b_];
  9754. if (!cv && !c) return;
  9755. if (cv === c) return;
  9756. style[b_] = c;
  9757. return;
  9758.  
  9759. } else {
  9760. // if(immediate && elmPropTemps[b]){
  9761. // console.log(5191, b)
  9762. // }
  9763. // caption-window
  9764. // margin-left max-height max-width font-family fill color font-size background white-space margin
  9765. // text-align background-color
  9766. // console.log(27304, a, b, c)
  9767. if (!set66.has(b)) {
  9768. set66.add(b);
  9769. nextBrowserTick_(() => {
  9770. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  9771. console.log(27304, a, b, c)
  9772. }
  9773. })
  9774. }
  9775. }
  9776.  
  9777. attrUpdateFn.call(this, a, b, c);
  9778. return;
  9779. } else if (typeof (b || 0) === 'object') {
  9780.  
  9781. // this is to fix caption positioning
  9782. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  9783. const immediate = (a.id || 0).length > 14;
  9784. for (const [k, v] of Object.entries(b)) {
  9785. modifiedFn.call(this, a, k, v, immediate);
  9786. }
  9787.  
  9788. } else {
  9789.  
  9790. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  9791. // ytp-ad-timed-pie-countdown-inner
  9792.  
  9793. if (typeof b === 'string') {
  9794.  
  9795. let m = log77.get(b);
  9796. if (!m) {
  9797. m = [];
  9798. console.log(27306, m);
  9799. log77.set(b, m);
  9800. }
  9801. m.push([a, b, c]);
  9802.  
  9803. } else {
  9804. console.log(27306, a, b, c);
  9805. }
  9806.  
  9807. attrUpdateFn.call(this, a, b, c);
  9808. return;
  9809. }
  9810.  
  9811. // console.log(130000, a, b, c);
  9812.  
  9813. };
  9814. g[k] = modifiedFn;
  9815.  
  9816.  
  9817. /*
  9818.  
  9819. g.zo = function(a, b, c) {
  9820. if ("string" === typeof b)
  9821. (b = yo(a, b)) && (a.style[b] = c);
  9822. else
  9823. for (var d in b) {
  9824. c = a;
  9825. var e = b[d]
  9826. , f = yo(c, d);
  9827. f && (c.style[f] = e)
  9828. }
  9829. }
  9830.  
  9831.  
  9832. */
  9833.  
  9834.  
  9835. }
  9836. }
  9837.  
  9838. if (fOption & 4) {
  9839. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  9840.  
  9841. if (keyuG) {
  9842.  
  9843. k = keyuG;
  9844.  
  9845. const gk = g[k];
  9846. const gkp = gk.prototype;
  9847.  
  9848.  
  9849. /** @type { Map<string, WeakMap<any, any>> } */
  9850. const ntLogs = new Map();
  9851.  
  9852. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  9853.  
  9854. gkp.updateValue31 = gkp.updateValue;
  9855. gkp.updateValue = function (a, b) {
  9856. if (typeof a !== 'string') return this.updateValue31(a, b);
  9857.  
  9858. const element = this.element;
  9859. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  9860.  
  9861. let ntLog = ntLogs.get(a);
  9862. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  9863.  
  9864. let cache = ntLog.get(element);
  9865. if (cache && cache.value === b) {
  9866. return;
  9867. }
  9868. if (!cache) {
  9869. this.__oldValueByUpdateValue__ = null;
  9870. ntLog.set(element, cache = { value: b });
  9871. } else {
  9872. this.__oldValueByUpdateValue__ = cache.value;
  9873. cache.value = b;
  9874. }
  9875.  
  9876. return this.updateValue31(a, b);
  9877. }
  9878.  
  9879. /*
  9880. g.k.update = function(a) {
  9881. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  9882. c = c.value,
  9883. this.updateValue(c, a[c])
  9884. }
  9885. ;
  9886. g.k.updateValue = function(a, b) {
  9887. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  9888. }
  9889. */
  9890.  
  9891. }
  9892.  
  9893.  
  9894. }
  9895. }
  9896.  
  9897.  
  9898.  
  9899. })();
  9900.  
  9901.  
  9902. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  9903. // keyboard shortcut keys controller
  9904.  
  9905. const _yt_player = await _yt_player_observable.obtain();
  9906.  
  9907. if (!_yt_player || typeof _yt_player !== 'object') return;
  9908.  
  9909. keyboardController(_yt_player);
  9910.  
  9911. })();
  9912.  
  9913. FIX_yt_player && !isChatRoomURL && (async () => {
  9914. // timer scheduling
  9915.  
  9916. const _yt_player = await _yt_player_observable.obtain();
  9917.  
  9918. if (!_yt_player || typeof _yt_player !== 'object') return;
  9919.  
  9920. let keyZqQu = getZqQu(_yt_player);
  9921.  
  9922. if (!keyZqQu) return;
  9923.  
  9924. const g = _yt_player
  9925. let k = keyZqQu
  9926.  
  9927. const gk = g[k];
  9928. if (typeof gk !== 'function') return;
  9929. const gkp = gk.prototype;
  9930.  
  9931. const extractKeysZqQu = () => {
  9932.  
  9933.  
  9934. let _keyeC = '';
  9935. try {
  9936. gkp.stop.call(new Proxy({
  9937. isActive: () => { }
  9938. }, {
  9939. set(target, prop, value) {
  9940. if (value === 0) _keyeC = prop;
  9941. return true;
  9942. }
  9943. }));
  9944. } catch (e) { }
  9945. if (!_keyeC) return;
  9946. const keyeC = _keyeC;
  9947.  
  9948. let keyC = ''; // this.C = this.ST.bind(this)
  9949. let keyhj = ''; // 1000ms
  9950. try {
  9951. gkp.start.call(new Proxy({
  9952. stop: () => { },
  9953. [keyeC]: 0,
  9954. }, {
  9955. get(target, prop) {
  9956. if (prop in target) return target[prop];
  9957. if (!keyC) {
  9958. keyC = prop;
  9959. return null; // throw error
  9960. }
  9961. else if (!keyhj) {
  9962. keyhj = prop;
  9963. }
  9964.  
  9965. }
  9966. }));
  9967. } catch (e) {
  9968. if (!keyC || !keyhj) {
  9969. console.log(e)
  9970. }
  9971. }
  9972.  
  9973. if (!keyC || !keyhj) return;
  9974. let keyST = '';
  9975. let keyj = '';
  9976. let keyB = '';
  9977. let keyxa = '';
  9978.  
  9979. const possibleKs = new Set();
  9980.  
  9981. for (const [k, v] of Object.entries(gkp)) {
  9982. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  9983. continue;
  9984. }
  9985. if (typeof v === 'function') {
  9986. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  9987. if (m) {
  9988. keyST = k;
  9989. keyj = m[1];
  9990. keyB = m[2];
  9991. } else {
  9992. possibleKs.add(k);
  9993. }
  9994. }
  9995. }
  9996.  
  9997. if (!keyST || !keyj || !keyB) return;
  9998.  
  9999. for (const k of possibleKs) {
  10000. if (k === keyST || k === keyj || k === keyB) {
  10001. continue;
  10002. }
  10003. const v = gkp[k];
  10004. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  10005. keyxa = k;
  10006. }
  10007. }
  10008.  
  10009. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  10010.  
  10011. }
  10012.  
  10013. const keys = extractKeysZqQu();
  10014. if (!keys || !keys.length) return;
  10015. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  10016.  
  10017. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  10018.  
  10019. let disposeKeys = null;
  10020.  
  10021. gkp[keyxa] = function () {
  10022. // dispose
  10023. if (!disposeKeys) {
  10024. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  10025. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  10026. const t = typeof this[key];
  10027. return t === 'undefined' || t === 'object'
  10028. }
  10029. return false;
  10030. });
  10031. }
  10032. for (const key of disposeKeys) {
  10033. const v = this[key];
  10034. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  10035. }
  10036. if (this[keyeC] > 0) this.stop();
  10037. this[keyj] = null;
  10038. this[keyB] = null;
  10039. };
  10040.  
  10041. gkp.start = function (a) {
  10042. if (this[keyeC] > 0) this.stop();
  10043. const delay = void 0 !== a ? a : this[keyhj];
  10044. this[keyeC] = window.setTimeout(this[keyC], delay);
  10045. };
  10046. gkp.stop = function () {
  10047. if (this[keyeC] > 0) {
  10048. window.clearTimeout(this[keyeC]);
  10049. this[keyeC] = 0;
  10050. }
  10051. };
  10052.  
  10053. gkp.isActive = function () {
  10054. return this[keyeC] > 0;
  10055. };
  10056.  
  10057. gkp[keyST] = function () {
  10058. this.stop(); // this[keyeC] = 0;
  10059. const fn = this[keyj];
  10060. const obj = this[keyB];
  10061. let skip = false;
  10062. if (!fn) skip = true;
  10063. else if (IGNORE_bufferhealth_CHECK && obj) {
  10064. let m;
  10065. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  10066. if (m.has("bufferhealth")) skip = true;
  10067. }
  10068. }
  10069. if (!skip) {
  10070. fn.call(obj);
  10071. }
  10072. };
  10073.  
  10074.  
  10075.  
  10076.  
  10077. /*
  10078.  
  10079. g.k.eC = 0;
  10080. g.k.xa = function() {
  10081. g.Qu.Vf.xa.call(this);
  10082. this.stop();
  10083. delete this.j;
  10084. delete this.B
  10085. }
  10086. ;
  10087. g.k.start = function(a) {
  10088. this.stop();
  10089. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  10090. }
  10091. ;
  10092. g.k.stop = function() {
  10093. this.isActive() && g.Sa.clearTimeout(this.eC);
  10094. this.eC = 0
  10095. }
  10096. ;
  10097. g.k.isActive = function() {
  10098. return 0 != this.eC
  10099. }
  10100. ;
  10101. g.k.ST = function() {
  10102. this.eC = 0;
  10103. this.j && this.j.call(this.B)
  10104. }
  10105. ;
  10106. */
  10107.  
  10108.  
  10109.  
  10110.  
  10111. })();
  10112.  
  10113. FIX_Animation_n_timeline && (async () => {
  10114.  
  10115. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  10116.  
  10117. if (!timeline || !Animation) return;
  10118.  
  10119. const aniProto = Animation.prototype;
  10120. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  10121.  
  10122. const getXroto = (x) => {
  10123. try {
  10124. return x.__proto__;
  10125. } catch (e) { }
  10126. return null;
  10127. }
  10128. const timProto = getXroto(timeline);
  10129. if (!timProto) return;
  10130. if (
  10131. (
  10132. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  10133. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  10134. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  10135. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  10136. )
  10137.  
  10138. ) {
  10139.  
  10140. timProto.nofCQ = 1;
  10141. aniProto.nofYH = 1;
  10142.  
  10143. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  10144.  
  10145.  
  10146. /*
  10147. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10148. return c._updatePromises();
  10149. });
  10150. */
  10151.  
  10152. const p = Array.prototype.filter;
  10153.  
  10154. let res = null;
  10155. Array.prototype.filter = function () {
  10156.  
  10157. res = this;
  10158. return this;
  10159.  
  10160. };
  10161.  
  10162. _updateAnimationsPromises.call({});
  10163.  
  10164. Array.prototype.filter = p;
  10165.  
  10166. if (res && typeof res.length === 'number') {
  10167. /** @type {any[]} */
  10168. const _res = res;
  10169. return _res;
  10170. }
  10171.  
  10172.  
  10173. return null;
  10174.  
  10175.  
  10176.  
  10177.  
  10178. })(timProto._updateAnimationsPromises);
  10179.  
  10180. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  10181.  
  10182. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  10183.  
  10184. aniProto._updatePromises31 = aniProto._updatePromises;
  10185.  
  10186. /*
  10187. aniProto._updatePromises = function(){
  10188. console.log('eff',this._oldPlayState, this.playState)
  10189. return this._updatePromises31.apply(this, arguments)
  10190. }
  10191. */
  10192.  
  10193. aniProto._updatePromises = function () {
  10194. var oldPlayState = this._oldPlayState;
  10195. var newPlayState = this.playState;
  10196. // console.log('ett', oldPlayState, newPlayState)
  10197. if (newPlayState !== oldPlayState) {
  10198. this._oldPlayState = newPlayState;
  10199. if (this._readyPromise) {
  10200. if ("idle" == newPlayState) {
  10201. this._rejectReadyPromise();
  10202. this._readyPromise = void 0;
  10203. } else if ("pending" == oldPlayState) {
  10204. this._resolveReadyPromise();
  10205. } else if ("pending" == newPlayState) {
  10206. this._readyPromise = void 0;
  10207. }
  10208. }
  10209. if (this._finishedPromise) {
  10210. if ("idle" == newPlayState) {
  10211. this._rejectFinishedPromise();
  10212. this._finishedPromise = void 0;
  10213. } else if ("finished" == newPlayState) {
  10214. this._resolveFinishedPromise();
  10215. } else if ("finished" == oldPlayState) {
  10216. this._finishedPromise = void 0;
  10217. }
  10218. }
  10219. }
  10220. return this._readyPromise || this._finishedPromise;
  10221. };
  10222.  
  10223.  
  10224. let restartWebAnimationsNextTickFlag = false;
  10225.  
  10226. const looperMethodT = () => {
  10227.  
  10228. const runnerFn = (hRes) => {
  10229. var b = timeline;
  10230. b.currentTime = hRes;
  10231. b._discardAnimations();
  10232. if (0 == b._animations.length) {
  10233. restartWebAnimationsNextTickFlag = false;
  10234. } else {
  10235. getRafPromise().then(runnerFn);
  10236. }
  10237. }
  10238.  
  10239. const restartWebAnimationsNextTick = () => {
  10240. if (!restartWebAnimationsNextTickFlag) {
  10241. restartWebAnimationsNextTickFlag = true;
  10242. getRafPromise().then(runnerFn);
  10243. }
  10244. }
  10245.  
  10246. return { restartWebAnimationsNextTick }
  10247. };
  10248.  
  10249.  
  10250. const looperMethodN = () => {
  10251.  
  10252. const acs = document.createElement('a-f');
  10253. acs.id = 'a-f';
  10254.  
  10255. if (!document.getElementById('afscript')) {
  10256. const style = document.createElement('style');
  10257. style.id = 'afscript';
  10258. style.textContent = `
  10259. @keyFrames aF1 {
  10260. 0% {
  10261. order: 0;
  10262. }
  10263. 100% {
  10264. order: 1;
  10265. }
  10266. }
  10267. #a-f[id] {
  10268. visibility: collapse !important;
  10269. position: fixed !important;
  10270. display: block !important;
  10271. top: -100px !important;
  10272. left: -100px !important;
  10273. margin:0 !important;
  10274. padding:0 !important;
  10275. outline:0 !important;
  10276. border:0 !important;
  10277. z-index:-1 !important;
  10278. width: 0px !important;
  10279. height: 0px !important;
  10280. contain: strict !important;
  10281. pointer-events: none !important;
  10282. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  10283. }
  10284. `;
  10285. (document.head || document.documentElement).appendChild(style);
  10286. }
  10287.  
  10288. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  10289.  
  10290. const _onanimationiteration = function (evt) {
  10291. const hRes = evt.timeStamp;
  10292. var b = timeline;
  10293. b.currentTime = hRes;
  10294. b._discardAnimations();
  10295. if (0 == b._animations.length) {
  10296. restartWebAnimationsNextTickFlag = false;
  10297. acs.onanimationiteration = null;
  10298. } else {
  10299. acs.onanimationiteration = _onanimationiteration;
  10300. }
  10301.  
  10302. }
  10303.  
  10304.  
  10305.  
  10306. const restartWebAnimationsNextTick = () => {
  10307. if (!restartWebAnimationsNextTickFlag) {
  10308. restartWebAnimationsNextTickFlag = true;
  10309. acs.onanimationiteration = _onanimationiteration;
  10310.  
  10311. }
  10312. }
  10313.  
  10314. return { restartWebAnimationsNextTick }
  10315. };
  10316.  
  10317.  
  10318.  
  10319. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  10320.  
  10321.  
  10322. // console.log(571, timProto);
  10323. timProto._play = function (c) {
  10324. c = new Animation(c, this);
  10325. this._animations.push(c);
  10326. restartWebAnimationsNextTick();
  10327. c._updatePromises();
  10328. c._animation.play();
  10329. c._updatePromises();
  10330. return c
  10331. }
  10332.  
  10333. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  10334. originalAnimationsWithPromises.length = 0;
  10335. originalAnimationsWithPromises.push = null;
  10336. originalAnimationsWithPromises.splice = null;
  10337. originalAnimationsWithPromises.slice = null;
  10338. originalAnimationsWithPromises.indexOf = null;
  10339. originalAnimationsWithPromises.unshift = null;
  10340. originalAnimationsWithPromises.shift = null;
  10341. originalAnimationsWithPromises.pop = null;
  10342. originalAnimationsWithPromises.filter = null;
  10343. originalAnimationsWithPromises.forEach = null;
  10344. originalAnimationsWithPromises.map = null;
  10345.  
  10346.  
  10347. const _updateAnimationsPromises = () => {
  10348. animationsWithPromisesMap.forEach(c => {
  10349. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  10350. });
  10351. /*
  10352. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10353. return c._updatePromises();
  10354. });
  10355. */
  10356. }
  10357.  
  10358. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  10359.  
  10360. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  10361.  
  10362. delete timProto._updateAnimationsPromises;
  10363. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  10364. get() {
  10365. if (animationsWithPromisesMap.size === 0) return nilFn;
  10366. return _updateAnimationsPromises;
  10367. },
  10368. set(nv) {
  10369. delete this._updateAnimationsPromises;
  10370. this._updateAnimationsPromises = nv;
  10371. },
  10372. enumerable: true,
  10373. configurable: true,
  10374. });
  10375.  
  10376.  
  10377. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  10378. aniProto.__finished_native_get__ = pdFinished.get;
  10379. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  10380.  
  10381.  
  10382. Object.defineProperty(aniProto, 'finished', {
  10383. get() {
  10384. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10385. this._finishedPromise = new Promise((resolve, reject) => {
  10386. this._resolveFinishedPromise = function () {
  10387. resolve(this)
  10388. };
  10389. this._rejectFinishedPromise = function () {
  10390. reject({
  10391. type: DOMException.ABORT_ERR,
  10392. name: "AbortError"
  10393. })
  10394. };
  10395. }),
  10396. "finished" == this.playState && this._resolveFinishedPromise());
  10397. return this._finishedPromise
  10398. },
  10399. set: undefined,
  10400. enumerable: true,
  10401. configurable: true
  10402. });
  10403.  
  10404. }
  10405.  
  10406.  
  10407.  
  10408. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  10409. aniProto.__ready_native_get__ = pdReady.get;
  10410. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  10411.  
  10412. Object.defineProperty(aniProto, 'ready', {
  10413. get() {
  10414. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10415. this._readyPromise = new Promise((resolve, reject) => {
  10416. this._resolveReadyPromise = function () {
  10417. resolve(this)
  10418. };
  10419. this._rejectReadyPromise = function () {
  10420. reject({
  10421. type: DOMException.ABORT_ERR,
  10422. name: "AbortError"
  10423. })
  10424. };
  10425. }),
  10426. "pending" !== this.playState && this._resolveReadyPromise());
  10427. return this._readyPromise
  10428. },
  10429. set: undefined,
  10430. enumerable: true,
  10431. configurable: true
  10432. });
  10433.  
  10434. }
  10435.  
  10436.  
  10437. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  10438.  
  10439. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  10440. const _rebuildUnderlyingAnimation = function () {
  10441. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  10442. this.effect && this.effect._onsample && (this.effect._onsample = null);
  10443. return this._rebuildUnderlyingAnimation21();
  10444. }
  10445. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  10446. // delete aniProto._rebuildUnderlyingAnimation;
  10447. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  10448. // get() {
  10449. // if (isNaN(this._sequenceNumber)) return nilFn;
  10450. // return this._rebuildUnderlyingAnimation21;
  10451. // },
  10452. // set(nv) {
  10453. // delete this._rebuildUnderlyingAnimation;
  10454. // this._rebuildUnderlyingAnimation = nv;
  10455. // },
  10456. // enumerable: true,
  10457. // configurable: true
  10458. // });
  10459. }
  10460.  
  10461.  
  10462. /*
  10463.  
  10464.  
  10465. function f(c) {
  10466. var b = v.timeline;
  10467. b.currentTime = c;
  10468. b._discardAnimations();
  10469. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  10470. }
  10471. var h = window.requestAnimationFrame;
  10472. window.requestAnimationFrame = function(c) {
  10473. return h(function(b) {
  10474. v.timeline._updateAnimationsPromises();
  10475. c(b);
  10476. v.timeline._updateAnimationsPromises()
  10477. })
  10478. }
  10479. ;
  10480. v.AnimationTimeline = function() {
  10481. this._animations = [];
  10482. this.currentTime = void 0
  10483. }
  10484. ;
  10485. v.AnimationTimeline.prototype = {
  10486. getAnimations: function() {
  10487. this._discardAnimations();
  10488. return this._animations.slice()
  10489. },
  10490. _updateAnimationsPromises: function() {
  10491. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  10492. return c._updatePromises()
  10493. })
  10494. },
  10495. _discardAnimations: function() {
  10496. this._updateAnimationsPromises();
  10497. this._animations = this._animations.filter(function(c) {
  10498. return "finished" != c.playState && "idle" != c.playState
  10499. })
  10500. },
  10501. _play: function(c) {
  10502. c = new v.Animation(c,this);
  10503. this._animations.push(c);
  10504. v.restartWebAnimationsNextTick();
  10505. c._updatePromises();
  10506. c._animation.play();
  10507. c._updatePromises();
  10508. return c
  10509. },
  10510. play: function(c) {
  10511. c && c.remove();
  10512. return this._play(c)
  10513. }
  10514. };
  10515. var d = !1;
  10516. v.restartWebAnimationsNextTick = function() {
  10517. d || (d = !0,
  10518. requestAnimationFrame(f))
  10519. }
  10520. ;
  10521. var a = new v.AnimationTimeline;
  10522. v.timeline = a;
  10523. try {
  10524. Object.defineProperty(window.document, "timeline", {
  10525. configurable: !0,
  10526. get: function() {
  10527. return a
  10528. }
  10529. })
  10530. } catch (c) {}
  10531. try {
  10532. window.document.timeline = a
  10533. } catch (c) {}
  10534.  
  10535. */
  10536.  
  10537.  
  10538.  
  10539. /*
  10540.  
  10541. var g = window.getComputedStyle;
  10542. Object.defineProperty(window, "getComputedStyle", {
  10543. configurable: !0,
  10544. enumerable: !0,
  10545. value: function() {
  10546. v.timeline._updateAnimationsPromises();
  10547. var e = g.apply(this, arguments);
  10548. h() && (e = g.apply(this, arguments));
  10549. v.timeline._updateAnimationsPromises();
  10550. return e
  10551. }
  10552. });
  10553.  
  10554. */
  10555.  
  10556.  
  10557.  
  10558.  
  10559. }
  10560.  
  10561.  
  10562.  
  10563.  
  10564. })();
  10565.  
  10566. !isUrlInEmbed && Promise.resolve().then(() => {
  10567.  
  10568. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  10569.  
  10570.  
  10571.  
  10572. class LimitedSizeSet extends Set {
  10573. constructor(n) {
  10574. super();
  10575. this.limit = n;
  10576. }
  10577.  
  10578. add(key) {
  10579. if (!super.has(key)) {
  10580. super.add(key);
  10581. let n = super.size - this.limit;
  10582. if (n > 0) {
  10583. const iterator = super.values();
  10584. do {
  10585. const firstKey = iterator.next().value; // Get the first (oldest) key
  10586. super.delete(firstKey); // Delete the oldest key
  10587. } while (--n > 0)
  10588. }
  10589. }
  10590. }
  10591.  
  10592. removeAdd(key) {
  10593. super.delete(key);
  10594. this.add(key);
  10595. }
  10596.  
  10597. }
  10598.  
  10599. // const wk3 = new WeakMap();
  10600.  
  10601. // let mtxVideoId = '';
  10602. // let aje3 = [];
  10603. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  10604. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  10605. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  10606. let mtzCount = 0; // the key keeps unchanged
  10607. // let mjtNextMainKey = '';
  10608. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  10609. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  10610. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  10611. // let allowNoDelay322=false;
  10612. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  10613.  
  10614. let mpKey22 = ''; // last success continutation key & url pair
  10615. let mpUrl22 = ''; // last success continutation key & url pair
  10616. let mpKey21 = ''; // latest requested continutation key & url pair
  10617. let mpUrl21 = ''; // latest requested continutation key & url pair
  10618.  
  10619.  
  10620. async function sha1Hex(message) {
  10621. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  10622. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  10623. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  10624. const hashHex = hashArray
  10625. .map((b) => b.toString(16).padStart(2, "0"))
  10626. .join(""); // convert bytes to hex string
  10627. return hashHex;
  10628. }
  10629.  
  10630. async function continuationLog(a, ...args) {
  10631. let b = a;
  10632. try {
  10633. if (advanceLogging) b = await sha1Hex(a);
  10634. let c = args.map(e => {
  10635. return e === a ? b : e
  10636. });
  10637. console.log(...c)
  10638. } catch (e) { console.warn(e) }
  10639. }
  10640.  
  10641. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  10642.  
  10643.  
  10644. if (mfvContinuationRecorded.length > 0) {
  10645. for (const [e, d] of mfvContinuationRecorded) {
  10646. mfyContinuationIgnored.removeAdd(e);
  10647. }
  10648. toClearRecorded && mfvContinuationRecorded.clear();
  10649. }
  10650.  
  10651. }
  10652.  
  10653. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  10654.  
  10655. const tmProto = taskMgr.constructor.prototype;
  10656. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  10657.  
  10658. if (!tmProto.addJob714) {
  10659.  
  10660. tmProto.addJob714 = tmProto.addJob;
  10661.  
  10662. tmProto.addJob = function (a, b, c) {
  10663. const jobId = this.addJob714(a, b, c);
  10664. if (jobId > 0) {
  10665. // const ez = wk3.get(this);
  10666. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  10667. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  10668.  
  10669. this.__lastJobId863__ = jobId;
  10670. }
  10671. return jobId;
  10672. }
  10673.  
  10674. }
  10675.  
  10676. if (!tmProto.cancelJob714) {
  10677.  
  10678. tmProto.cancelJob714 = tmProto.cancelJob;
  10679.  
  10680. tmProto.cancelJob = function (a) {
  10681. const res = this.cancelJob714(a);
  10682. // if (a > 0) {
  10683. // for (const e of aje3) {
  10684. // if (e.jobId === a) e.cancelled = true;
  10685. // }
  10686. // }
  10687. return res;
  10688. }
  10689.  
  10690. }
  10691.  
  10692. }
  10693. }
  10694.  
  10695.  
  10696. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  10697.  
  10698.  
  10699. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  10700. let dummy;
  10701. let cProto;
  10702. // let mc = 4;
  10703. // dummy = await observablePromise(() => {
  10704. // const r = document.querySelector('ytd-video-primary-info-renderer');
  10705. // if (!r) return;
  10706. // let cProto = insp(r).constructor.prototype;
  10707. // if (cProto.fetchUpdatedMetadata) return r;
  10708. // if (--mc < 0) return -1;
  10709. // return null;
  10710. // }).obtain();
  10711. dummy = document.createElement('ytd-video-primary-info-renderer');
  10712. if (!(dummy instanceof Element)) return;
  10713. // console.log(5022, dummy)
  10714. cProto = insp(dummy).constructor.prototype;
  10715.  
  10716. cProto.__getEmittorTaskMgr859__ = function () {
  10717. let taskMgr_ = null;
  10718. try {
  10719. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  10720. } catch (e) { }
  10721. return taskMgr_;
  10722. }
  10723. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  10724. // console.log(1234, cProto, cProto.is)
  10725. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  10726.  
  10727. let c_;
  10728. cProto.fetchUpdatedMetadata718 = function (a) {
  10729. // delay or immediate call the actual fetchUpdatedMetadata
  10730.  
  10731. let doImmediately = false;
  10732. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  10733.  
  10734. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  10735.  
  10736. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  10737.  
  10738. doImmediately = true;
  10739.  
  10740. }
  10741.  
  10742. if (mbCId322) {
  10743. clearTimeout(mbCId322);
  10744. mbCId322 = 0;
  10745. }
  10746.  
  10747. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  10748.  
  10749. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  10750.  
  10751. mbCId322 = setTimeout(() => {
  10752. this.fetchUpdatedMetadata717(a);
  10753. }, delay);
  10754.  
  10755. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  10756.  
  10757. }
  10758.  
  10759. cProto.fetchUpdatedMetadata = function (a) {
  10760.  
  10761. if (!pageSetupState) {
  10762. if (c_) clearTimeout(c_);
  10763. c_ = setTimeout(() => {
  10764. this.fetchUpdatedMetadata718(a);
  10765. }, 300);
  10766. return;
  10767. }
  10768.  
  10769. // pageSetupState == 0
  10770.  
  10771. try {
  10772.  
  10773. mbDelayBelowNCalls++;
  10774.  
  10775. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  10776. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  10777. }
  10778.  
  10779. // console.log('fum377', a)
  10780. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  10781. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  10782. return;
  10783. }
  10784.  
  10785. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  10786. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  10787. mjtLockPreviousKey = mjtRecordedPrevKey;
  10788. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  10789. }
  10790. // mjtNextMainKey = true;
  10791. mtzlastAllowedContinuation = '';
  10792. mtzCount = 0;
  10793. // allowNoDelay322 = false;
  10794. // fetch new metadata, cancel all previous continuations
  10795. copyPreviousContiuationToIgnored374(true);
  10796. } else if (typeof a === 'string') {
  10797. const videoPlayingId = videoPlayingY.videoId;
  10798.  
  10799. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  10800.  
  10801. let update21 = !!pageSetupVideoId;
  10802. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  10803. update21 = true;
  10804. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  10805. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  10806. return;
  10807. }
  10808. if (update21) {
  10809. mpKey21 = a;
  10810. mpUrl21 = pageSetupVideoId || videoPlayingId;
  10811. }
  10812.  
  10813. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  10814. }
  10815. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  10816. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  10817. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  10818. return this.fetchUpdatedMetadata718(a);
  10819.  
  10820. } catch (e) {
  10821. console.log('Code Error in fetchUpdatedMetadata', e);
  10822. }
  10823. return this.fetchUpdatedMetadata717(a)
  10824. }
  10825. }
  10826.  
  10827.  
  10828. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  10829. // console.log(1234, cProto, cProto.is)
  10830. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  10831. let mJob = null;
  10832.  
  10833. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  10834.  
  10835. try {
  10836.  
  10837. if (arguments.length > 0) {
  10838. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  10839. }
  10840. // mfy = mfv;
  10841.  
  10842. // mjtNextMainKey = '';
  10843. mtzlastAllowedContinuation = '';
  10844. mtzCount = 0;
  10845. if (mbCId322) {
  10846. clearTimeout(mbCId322);
  10847. mbCId322 = 0;
  10848. }
  10849. mbDelayBelowNCalls = 0;
  10850. // allowNoDelay322 = false;
  10851. copyPreviousContiuationToIgnored374(true);
  10852.  
  10853. const taskMgr = this.__getEmittorTaskMgr859__();
  10854. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  10855. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  10856. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  10857. }
  10858.  
  10859. // prevent depulicated schedule job by clearing previous JobId
  10860. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  10861.  
  10862. let res;
  10863.  
  10864. if (mJob) {
  10865. const job = mJob;
  10866. mJob = null;
  10867. console.log('cancelJob', job)
  10868. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  10869. // p.cancelJob(a,b);
  10870. }
  10871.  
  10872. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  10873.  
  10874. let pza = taskMgr.__lastJobId863__;
  10875. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  10876. let pzb = taskMgr.__lastJobId863__
  10877. if (pza !== pzb) {
  10878. mJob = pzb; // set [Interval Meta Update] jobId
  10879. }
  10880.  
  10881. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  10882. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  10883. // } else {
  10884. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  10885. // }
  10886.  
  10887. return res;
  10888.  
  10889. } else {
  10890. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  10891. }
  10892.  
  10893. } catch (e) {
  10894. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  10895. }
  10896.  
  10897.  
  10898. return this.scheduleInitialUpdatedMetadataRequest717();
  10899. }
  10900. }
  10901.  
  10902.  
  10903. });
  10904.  
  10905. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  10906. let dummy;
  10907. let cProto;
  10908. dummy = ytAppDom;
  10909. if (!(dummy instanceof Element)) return;
  10910. cProto = insp(dummy).constructor.prototype;
  10911. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  10912. // console.log(1234, cProto, cProto.is);
  10913. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10914. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  10915. // console.log(123401, arguments);
  10916. // return this.handleServiceRequest717_(a, b, c, d);
  10917. // }
  10918.  
  10919. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10920.  
  10921. // cProto.handleServiceRequest_ = function(a,b,c,d){
  10922. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10923. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  10924. // console.log('mfv', c.continuation);
  10925. // mfv.add( c.continuation);
  10926. // }
  10927. // return this.handleServiceRequest717_(a,b,c,d);
  10928. // }
  10929.  
  10930. function extraArguments322(a, b, c) {
  10931. let is = (a || 0).is;
  10932. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  10933. let continuation = (c || 0).continuation;
  10934. if (typeof is !== 'string') is = null;
  10935. if (typeof videoId !== 'string') videoId = null;
  10936. if (typeof continuation !== 'string') continuation = null;
  10937. return { is, videoId, continuation };
  10938. }
  10939.  
  10940. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  10941. cProto.sendServiceAjax_ = function (a, b, c, d) {
  10942.  
  10943. // console.log(8001)
  10944. try {
  10945.  
  10946. const { is, videoId, continuation } = extraArguments322(a, b, c);
  10947.  
  10948. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10949. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  10950. }
  10951.  
  10952. if (pageSetupVideoId && videoId && continuation) {
  10953. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10954. mfyContinuationIgnored.removeAdd(continuation);
  10955. mfvContinuationRecorded.delete(continuation);
  10956. return;
  10957. }
  10958. }
  10959.  
  10960. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10961. copyPreviousContiuationToIgnored374(false);
  10962. mfyContinuationIgnored.delete(continuation);
  10963. mfvContinuationRecorded.removeAdd(continuation);
  10964. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10965. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10966. mjtLockPreviousKey = '';
  10967. }
  10968. // if (mjtNextMainKey === continuation) {
  10969. // copyPreviousContiuationToIgnored(false);
  10970. // mfyContinuationIgnored.delete(continuation);
  10971. // mfvContinuationRecorded.add(continuation);
  10972. // }
  10973.  
  10974.  
  10975. if (mfyContinuationIgnored && continuation) {
  10976. if (mfyContinuationIgnored.has(continuation)) {
  10977. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  10978. return;
  10979. }
  10980. }
  10981.  
  10982. // console.log(59902, a?.is, b,c,d)
  10983. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10984. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  10985. // console.log('mfv377', continuation);
  10986. mfvContinuationRecorded.add(continuation);
  10987. }
  10988.  
  10989. // if (videoId) {
  10990. // if (!pageSetupVideoId) return; // ignore page not ready
  10991. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10992. // if (videoId !== pageSetupVideoId) {
  10993. // return;
  10994. // }
  10995. // }
  10996.  
  10997. } catch (e) {
  10998. console.log('Coding Error in sendServiceAjax_', e)
  10999. }
  11000. // console.log(8002)
  11001. // console.log(123402, arguments);
  11002. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  11003.  
  11004. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  11005. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  11006. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  11007. // get(target, prop, receiver){
  11008. // console.log('xxs99', target.videoId, mtx)
  11009. // if(prop ==='kdkw33') return 1;
  11010. // console.log(3322, prop, target)
  11011. // if(prop === 'initialDelayMs') {
  11012. // throw new Error("ABCC");
  11013. // }
  11014. // return target[prop];
  11015. // },
  11016. // set(target, prop, value, receiver){
  11017.  
  11018. // if(prop ==='kdkw33') return true;
  11019. // target[prop]=value;
  11020. // return true;
  11021. // }
  11022. // });
  11023. // }
  11024. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  11025. return this.sendServiceAjax717_(a, b, c, d);
  11026. }
  11027. }
  11028.  
  11029. function delayClearOtherKeys(lztContinuation) {
  11030. // // schedule delayed removal if mfyContinuationIgnored is not empty
  11031. // getRafPromise().then(() => {
  11032. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  11033. // // foreground page only
  11034.  
  11035. // });
  11036.  
  11037.  
  11038. if (lztContinuation !== mtzlastAllowedContinuation) return;
  11039. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  11040. if (!mfyContinuationIgnored.size) return;
  11041. if (mfyContinuationIgnored.size > 1) {
  11042. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  11043. }
  11044. mfyContinuationIgnored.forEach((value, key) => {
  11045. if (key !== lztContinuation) {
  11046. mfyContinuationIgnored.delete(key);
  11047. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  11048. }
  11049. });
  11050.  
  11051. }
  11052. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  11053. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  11054. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  11055.  
  11056. // console.log(8003)
  11057. try {
  11058.  
  11059.  
  11060. const { is, videoId, continuation } = extraArguments322(b, c, d);
  11061.  
  11062. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11063. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  11064. }
  11065.  
  11066. if (pageSetupVideoId && videoId && continuation) {
  11067. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11068. mfyContinuationIgnored.removeAdd(continuation);
  11069. mfvContinuationRecorded.delete(continuation);
  11070. return;
  11071. }
  11072. }
  11073.  
  11074. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11075. copyPreviousContiuationToIgnored374(false);
  11076. mfyContinuationIgnored.delete(continuation);
  11077. mfvContinuationRecorded.removeAdd(continuation);
  11078. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11079. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11080. mjtLockPreviousKey = '';
  11081. }
  11082.  
  11083. // if (mjtNextMainKey === continuation) {
  11084. // copyPreviousContiuationToIgnored(false);
  11085. // mfyContinuationIgnored.delete(continuation);
  11086. // mfvContinuationRecorded.add(continuation);
  11087. // }
  11088.  
  11089. const lztContinuation = continuation;
  11090.  
  11091. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  11092. if (mfyContinuationIgnored.has(lztContinuation)) {
  11093. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  11094. return;
  11095. }
  11096. }
  11097.  
  11098. // if (videoId) {
  11099. // if (!pageSetupVideoId) return; // ignore page not ready
  11100. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  11101. // if (videoId !== pageSetupVideoId) {
  11102. // return;
  11103. // }
  11104. // }
  11105.  
  11106. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  11107. mtzlastAllowedContinuation = lztContinuation;
  11108. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  11109.  
  11110. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  11111. mjtRecordedPrevKey = lztContinuation;
  11112. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  11113. // if (mfyContinuationIgnored.size > 0) {
  11114. // delayClearOtherKeys(lztContinuation);
  11115. // }
  11116. mtzCount = 0;
  11117. // allowNoDelay322 = false;
  11118. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  11119. // repeated
  11120. if (++mtzCount > 1e9) mtzCount = 1e4;
  11121. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  11122.  
  11123. // if (mtzCount >= 3) allowNoDelay322 = true;
  11124. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  11125. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  11126. }
  11127. if (mtzCount === 5) {
  11128. mfvContinuationRecorded.clear();
  11129. mfvContinuationRecorded.add(lztContinuation);
  11130. }
  11131.  
  11132. }
  11133.  
  11134. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  11135. mpKey22 = lztContinuation;
  11136. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  11137. }
  11138.  
  11139. if (mbCId322) {
  11140. clearTimeout(mbCId322);
  11141. mbCId322 = 0;
  11142. }
  11143. } catch (e) {
  11144. console.log('Coding Error in getCancellableNetworkPromise_', e)
  11145. }
  11146.  
  11147. // console.log(8004)
  11148. // console.log(123403, arguments);
  11149. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  11150.  
  11151. // console.log(5163, a?.is,b,c,d,e);
  11152. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  11153. }
  11154. }
  11155. });
  11156.  
  11157. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11158.  
  11159.  
  11160. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  11161.  
  11162. let dummy;
  11163. let cProto;
  11164.  
  11165. dummy = document.createElement('ytd-expander');
  11166. cProto = insp(dummy).constructor.prototype;
  11167.  
  11168. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  11169.  
  11170. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  11171. cProto.childrenChanged14 = cProto.childrenChanged;
  11172.  
  11173. cProto.initChildrenObserver = function () {
  11174. var a = this;
  11175. this.observer = new MutationObserver(function () {
  11176. a.childrenChanged()
  11177. }
  11178. );
  11179. this.observer.observe(this.content, {
  11180. subtree: !0,
  11181. childList: !0,
  11182. attributes: !0,
  11183. characterData: !0
  11184. });
  11185. this.childrenChanged()
  11186. }
  11187. ;
  11188. cProto.childrenChanged = function () {
  11189. if (this.alwaysToggleable) {
  11190. this.canToggle = this.alwaysToggleable;
  11191. } else if (!this.canToggleJobId) {
  11192. this.canToggleJobId = 1;
  11193. foregroundPromiseFn().then(() => {
  11194. this.canToggleJobId = 0;
  11195. this.calculateCanCollapse()
  11196. })
  11197. }
  11198. }
  11199.  
  11200. // console.log(cProto.initChildrenObserver)
  11201. console.debug('ytd-expander-fix-childrenChanged');
  11202.  
  11203. }
  11204.  
  11205. });
  11206.  
  11207.  
  11208. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  11209.  
  11210. let dummy;
  11211. let cProto;
  11212. dummy = document.createElement('paper-ripple');
  11213. cProto = insp(dummy).constructor.prototype;
  11214.  
  11215. if (fnIntegrity(cProto.animate, '0.74.5')) {
  11216.  
  11217.  
  11218. cProto.animate34 = cProto.animate;
  11219. cProto.animate = function () {
  11220. if (this._animating) {
  11221. var a;
  11222. const ripples = this.ripples;
  11223. for (a = 0; a < ripples.length; ++a) {
  11224. var b = ripples[a];
  11225. b.draw();
  11226. this.$.background.style.opacity = b.outerOpacity;
  11227. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  11228. }
  11229. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  11230. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  11231. foregroundPromiseFn().then(this._boundAnimate38);
  11232. } else {
  11233. this.onAnimationComplete();
  11234. }
  11235. }
  11236. }
  11237.  
  11238. console.debug('FIX_paper_ripple_animate')
  11239.  
  11240. // console.log(cProto.animate)
  11241.  
  11242. }
  11243.  
  11244. });
  11245.  
  11246. if (FIX_doIdomRender) {
  11247.  
  11248. const xsetTimeout = function (f, d) {
  11249. if (xsetTimeout.m511 === 1 && !d) {
  11250. xsetTimeout.m511 = 2;
  11251. xsetTimeout.m568 = f;
  11252. } else {
  11253. return setTimeout.apply(window, arguments)
  11254. }
  11255.  
  11256. }
  11257.  
  11258. /**
  11259. *
  11260. IGb = function(a) {
  11261. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  11262. c || (a.requestAninmationFrameResolver = new Vi,
  11263. c = a.requestAninmationFrameResolver.promise,
  11264. Da.requestAnimationFrame(function() {
  11265. var d;
  11266. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  11267. a.requestAninmationFrameResolver = null
  11268. }));
  11269. return c
  11270. }
  11271.  
  11272.  
  11273. */
  11274.  
  11275. const xrequestAnimationFrame = function (f) {
  11276. const h = `${f}`;
  11277. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  11278. let t = null;
  11279. xsetTimeout.m511 = 1;
  11280. f();
  11281. if (xsetTimeout.m511 === 2) {
  11282. t = xsetTimeout.m568;
  11283. xsetTimeout.m568 = null;
  11284. }
  11285. xsetTimeout.m511 = 0;
  11286. if (typeof t === 'function') {
  11287. foregroundPromiseFn().then(t);
  11288. }
  11289. } else if (h.includes("requestAninmationFrameResolver")) {
  11290. foregroundPromiseFn().then(f);
  11291. } else {
  11292. return requestAnimationFrame.apply(window, arguments);
  11293. }
  11294. }
  11295.  
  11296. let busy = false;
  11297. const doIdomRender = function () {
  11298.  
  11299. if (!this) return;
  11300. if (busy) {
  11301. return this.doIdomRender13(...arguments);
  11302. }
  11303. busy = true;
  11304. const { requestAnimationFrame, setTimeout } = window;
  11305. window.requestAnimationFrame = xrequestAnimationFrame;
  11306. window.setTimeout = xsetTimeout;
  11307. let r = this.doIdomRender13(...arguments);
  11308. window.requestAnimationFrame = requestAnimationFrame;
  11309. window.setTimeout = setTimeout;
  11310. busy = false;
  11311. return r;
  11312. };
  11313. 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']) {
  11314.  
  11315.  
  11316. whenCEDefined(ytTag).then(() => {
  11317.  
  11318. let dummy;
  11319. let cProto;
  11320. dummy = document.createElement(ytTag);
  11321. cProto = insp(dummy).constructor.prototype;
  11322.  
  11323. cProto.doIdomRender13 = cProto.doIdomRender;
  11324. cProto.doIdomRender = doIdomRender;
  11325.  
  11326. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  11327.  
  11328. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  11329.  
  11330.  
  11331.  
  11332. });
  11333.  
  11334. }
  11335.  
  11336. }
  11337.  
  11338.  
  11339.  
  11340.  
  11341. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  11342.  
  11343. const sMap = new Map();
  11344.  
  11345. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  11346. const ZT = function () {
  11347. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  11348. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  11349. c = b & 15,
  11350. b >>= 4,
  11351. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  11352. return a.join("")
  11353. };
  11354.  
  11355.  
  11356. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  11357.  
  11358. const popupContainer = await observablePromise(() => {
  11359. return popupContainerCollection[0];
  11360. }).obtain();
  11361.  
  11362.  
  11363. let cProto;
  11364. cProto = insp(popupContainer).constructor.prototype;
  11365.  
  11366.  
  11367. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  11368. console.log('FIX_POPUP_UNIQUE_ID NG')
  11369. return;
  11370. }
  11371. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  11372.  
  11373. cProto.handleOpenPopupAction = function (a, b) {
  11374.  
  11375. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  11376.  
  11377. a.__jOdQA__ = true;
  11378.  
  11379. try {
  11380.  
  11381. const h = this.hostElement;
  11382.  
  11383. if (h instanceof HTMLElement_) {
  11384.  
  11385. const map = h.__skme44__ = h.__skme44__ || new Map();
  11386.  
  11387. let mKey = '';
  11388. const wKey = firstObjectKey(a);
  11389. const wObj = wKey ? a[wKey] : null;
  11390. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  11391. const pKey = firstObjectKey(wObj.popup)
  11392. const pObj = pKey ? wObj.popup[pKey] : null;
  11393. let contentKey = '';
  11394. let headerKey = '';
  11395.  
  11396. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  11397. contentKey = firstObjectKey(pObj.content)
  11398. headerKey = firstObjectKey(pObj.header)
  11399. }
  11400. if (contentKey && headerKey) {
  11401.  
  11402. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  11403.  
  11404. if (mKey) {
  11405.  
  11406. if (!wObj.uniqueId) {
  11407. for (let i = 0; i < 8; i++) {
  11408. wObj.uniqueId = ZT();
  11409. if (!sMap.has(wObj.uniqueId)) break;
  11410. }
  11411. }
  11412. const oId = wObj.uniqueId
  11413.  
  11414. let nId_ = map.get(mKey);
  11415. if (!nId_) {
  11416. map.set(mKey, nId_ = oId);
  11417. }
  11418.  
  11419. wObj.uniqueId = nId_ || wObj.uniqueId;
  11420.  
  11421. const nId = wObj.uniqueId
  11422.  
  11423. sMap.set(oId, nId);
  11424. sMap.set(nId, nId);
  11425.  
  11426. wObj.uniqueId = nId;
  11427. pObj.targetId = nId;
  11428. pObj.identifier.tag = nId;
  11429.  
  11430. if (oId !== nId) {
  11431. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  11432. }
  11433.  
  11434. }
  11435.  
  11436. }
  11437. }
  11438.  
  11439. // console.log(12213, mKey, a, b, h)
  11440.  
  11441. }
  11442.  
  11443. } catch (e) {
  11444. console.warn(e)
  11445. }
  11446.  
  11447. try {
  11448.  
  11449. const results = searchNestedObject(a, (x) => {
  11450. if (typeof x === 'string' && x.length === 36) {
  11451. 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;
  11452. }
  11453. return false;
  11454. });
  11455. for (const [obj, key] of results) {
  11456. const oId = obj[key];
  11457. const nId = sMap.get(oId);
  11458. if (nId) obj[key] = nId;
  11459. }
  11460. } catch (e) {
  11461. console.warn(e)
  11462. }
  11463.  
  11464.  
  11465. }
  11466.  
  11467. return this.handleOpenPopupAction3868(...arguments)
  11468. }
  11469.  
  11470. console.log('FIX_POPUP_UNIQUE_ID OK')
  11471.  
  11472.  
  11473. });
  11474.  
  11475.  
  11476. // FIX_TRANSCRIPT_SEGMENTS && (async ()=>{
  11477.  
  11478.  
  11479. // })();
  11480.  
  11481. // FIX_TRANSCRIPT_SEGMENTS && whenCEDefined('ytd-transcript-search-panel-renderer').then(async () => {
  11482.  
  11483.  
  11484. // let dummy;
  11485. // let cProto;
  11486. // dummy = document.createElement('ytd-transcript-search-panel-renderer');
  11487. // cProto = insp(dummy).constructor.prototype;
  11488.  
  11489.  
  11490. // if (!cProto || typeof cProto.bodyChanged !== 'function' || cProto.bodyChanged1848 || cProto.bodyChanged.length !== 0) {
  11491. // console.log('FIX_TRANSCRIPT_SEGMENTS NG')
  11492. // return;
  11493. // }
  11494. // cProto.bodyChanged1848 = cProto.bodyChanged;
  11495.  
  11496. // const wmx = new WeakMap();
  11497.  
  11498. // const sb35 = Symbol();
  11499. // cProto.bodyChanged = function () {
  11500. // let a = null;
  11501. // try {
  11502. // a = this.getBodyRenderer();
  11503. // } catch (e) { }
  11504. // if (!a || !a.initialSegments) {
  11505. // a = this.data;
  11506. // if (a.body) a = a.body;
  11507. // if (a.transcriptSegmentListRenderer) a = a.transcriptSegmentListRenderer;
  11508. // }
  11509. // const a_ = a;
  11510. // const initialSegments = (a_ || 0).initialSegments;
  11511. // if (typeof (initialSegments || 0) === 'object' && initialSegments.length >= 1){
  11512. // ((async () => { })()).then(() => {
  11513.  
  11514. // const c = wmx.get(initialSegments);
  11515. // if (!c) {
  11516. // const d = translateFn(initialSegments);
  11517. // wmx.set(initialSegments, d);
  11518. // console.log('translated', d);
  11519. // wmx.set(d, d);
  11520. // a_.initialSegments = d;
  11521. // } else {
  11522. // a_.initialSegments = c;
  11523. // }
  11524.  
  11525.  
  11526. // }).then(() => {
  11527. // // this.bodyChanged1848();
  11528. // });
  11529.  
  11530. // }else{
  11531.  
  11532. // // return this.bodyChanged1848();
  11533. // }
  11534. // }
  11535.  
  11536. // console.log('FIX_TRANSCRIPT_SEGMENTS OK')
  11537.  
  11538.  
  11539.  
  11540.  
  11541. // });
  11542.  
  11543.  
  11544. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  11545.  
  11546. let dummy;
  11547. let cProto;
  11548. dummy = document.createElement('yt-formatted-string');
  11549. cProto = insp(dummy).constructor.prototype;
  11550.  
  11551. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  11552. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  11553. return;
  11554. }
  11555.  
  11556. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  11557. cProto.setNodeStyle_ = function (a, b) {
  11558. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  11559. return this.setNodeStyle17_(a, b);
  11560. }
  11561.  
  11562. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  11563. });
  11564.  
  11565. });
  11566.  
  11567. });
  11568.  
  11569.  
  11570.  
  11571.  
  11572. if (isMainWindow) {
  11573.  
  11574. console.groupCollapsed(
  11575. "%cYouTube JS Engine Tamer",
  11576. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  11577. );
  11578.  
  11579.  
  11580.  
  11581. console.log("Script is loaded.");
  11582. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  11583.  
  11584. console.log("This script is experimental and subject to further changes.");
  11585.  
  11586. console.log("This might boost your YouTube performance.");
  11587.  
  11588. console.log("CAUTION: This might break your YouTube.");
  11589.  
  11590.  
  11591. if (prepareLogs.length >= 1) {
  11592. console.log(" =========================================================================== ");
  11593.  
  11594. for (const msg of prepareLogs) {
  11595. console.log(msg)
  11596. }
  11597.  
  11598. console.log(" =========================================================================== ");
  11599. }
  11600.  
  11601. console.groupEnd();
  11602.  
  11603. }
  11604.  
  11605.  
  11606.  
  11607. })();