YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

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

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @namespace UserScripts
  4. // @version 0.20.2
  5. // @match https://www.youtube.com/*
  6. // @match https://www.youtube-nocookie.com/embed/*
  7. // @match https://studio.youtube.com/live_chat*
  8. // @license MIT
  9. // @author CY Fung
  10. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  11. // @description To enhance YouTube performance by modifying YouTube JS Engine
  12. // @grant none
  13. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@c2b707e4977f77792042d4a5015fb188aae4772e/library/nextBrowserTick.min.js
  14. // @run-at document-start
  15. // @unwrap
  16. // @inject-into page
  17. // @allFrames true
  18. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  19. // ==/UserScript==
  20.  
  21. (() => {
  22.  
  23. /** @type {WeakMapConstructor} */
  24. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  25.  
  26. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  27. const FIX_schedulerInstanceInstance = 2 | 4;
  28. const FIX_yt_player = true; // DONT CHANGE
  29. const FIX_Animation_n_timeline = true;
  30. const NO_PRELOAD_GENERATE_204 = false;
  31. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  32. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  33. const CHANGE_appendChild = true; // discussions#236759
  34. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  35. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  36.  
  37. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  38. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  39. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  40.  
  41. const FIX_Iframe_NULL_SRC = false;
  42.  
  43. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  44.  
  45. const FIX_ytdExpander_childrenChanged = true;
  46. const FIX_paper_ripple_animate = true;
  47. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  48. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  49.  
  50. const FIX_doIdomRender = true;
  51.  
  52. const FIX_Shady = true;
  53.  
  54. // [[ 2024.04.24 ]]
  55. const MODIFY_ShadyDOM_OBJ = true;
  56. // << if MODIFY_ShadyDOM_OBJ >>
  57. const WEAKREF_ShadyDOM = true;
  58. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  59. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  60. // << end >>
  61.  
  62. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  63.  
  64. const FIX_ytAction_ = true; // ytd-app
  65. const FIX_onVideoDataChange = false;
  66. // const FIX_onClick = true;
  67. const FIX_onStateChange = true;
  68. const FIX_onLoopRangeChange = true;
  69. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  70. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  71.  
  72. const ENABLE_discreteTasking = false; // removed since 0.20.0
  73. const FIX_stampDomArray_ = true; // changed since 0.20.0
  74. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  75.  
  76. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  77. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  78.  
  79. const FIX_Polymer_dom = true;
  80.  
  81. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  82. const DEBUG_removePrune = false; // true for DEBUG
  83.  
  84. const FIX_XHR_REQUESTING = true;
  85.  
  86. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  87.  
  88. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  89.  
  90. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  91. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  92.  
  93. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  94.  
  95. const FIX_removeChild = true;
  96. const FIX_fix_requestIdleCallback_timing = true;
  97.  
  98. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  99. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  100.  
  101. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  102. // const DO_createStampDomArrayFnE1_ = true; // added in 2025.02.11 - to improve stampDom responsiveness
  103. // const DO_createStampDomArrayFnE1_noConstraintE = true;
  104. // const DO_createStampDomArrayFnE1_nativeAppendD = true;
  105. // const DO_createStampDomArrayFnF1_ = true;
  106. // const DO_createStampDomArray_STRICT_FULFILLMENT = true; // avoid issues; can be changed to false
  107. // const DO_createStampDomArray_DEBUG = false;
  108.  
  109. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  110.  
  111. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  112. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  113. // first tp-yt-paper-dialog: show once the page is loaded.
  114. // second tp-yt-paper-dialog: click "...more"
  115. // third tp-yt-paper-dialog: click "... and 3 more links"
  116. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  117. // currently, uniqueId is preassigned by the network resolveCommand.
  118. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  119. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  120.  
  121. // handleOpenPopupAction -> createCacheKey
  122. // handleClosePopupAction_ -> createCacheKey
  123. // handleGetPopupOpenedAction_ -> createCacheKey
  124. // getAndMaybeCreatePopup_ -> createCacheKey
  125. // closePopup -> createCacheKey
  126.  
  127. // yt-close-popup-command -> handleClosePopupCommand_
  128.  
  129. // ensurePopup_ -> getAndMaybeCreatePopup_
  130.  
  131. // yt-close-popup-action -> handleClosePopupAction_
  132. // closePopup -> handleClosePopupAction_
  133. // handleOpenPopupAction -> handleClosePopupAction_
  134. // handleClosePopupCommand_ -> handleClosePopupAction_
  135. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  136.  
  137. // yt-open-popup-action -> handleOpenPopupAction
  138.  
  139.  
  140. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  141. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  142.  
  143. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  144. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  145. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  146.  
  147.  
  148. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  149. const FIX_DOM_IF_TEMPLATE = true;
  150. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  151. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  152. const DEBUG_DBR847 = false;
  153. const DEBUG_xx847 = false;
  154. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  155. const DEBUG_renderDebounceTs = false;
  156.  
  157. const FIX_ICON_RENDER = true;
  158.  
  159. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  160.  
  161. /*
  162.  
  163. FIX_DOM_IFREPEAT_RenderDebouncerChange
  164.  
  165. avoid Polymer.flush
  166. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  167.  
  168. var Is = function() {
  169. do {
  170. var a = window.ShadyDOM && ShadyDOM.flush();
  171. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  172. var b = NNa()
  173. } while (a || b)
  174. };
  175.  
  176. , NNa = function() {
  177. var a = !!ts.size;
  178. ts.forEach(function(b) {
  179. try {
  180. b.flush()
  181. } catch (c) {
  182. setTimeout(function() {
  183. throw c
  184. })
  185. }
  186. });
  187. return a
  188. };
  189.  
  190. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  191. // this coding logic should be incorrect (mistake).
  192.  
  193. */
  194.  
  195.  
  196.  
  197. // ----------------------------- Shortkey Keyboard Control -----------------------------
  198. // dependency: FIX_yt_player
  199.  
  200. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  201. // [0] no fix - not recommended
  202. // [1] basic fix - just fix the global focus detection variable
  203. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  204. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  205.  
  206. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  207. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  208.  
  209. const PROP_OverReInclusion_AVOID = true;
  210. const PROP_OverReInclusion_DEBUGLOG = false;
  211. const PROP_OverReInclusion_LIST = new Set([
  212. 'hostElement72',
  213. 'parentComponent72',
  214. 'localVisibilityObserver_72',
  215. 'cachedProviderNode_72',
  216. '__template72',
  217. '__templatizeOwner72',
  218. '__templateInfo72',
  219. '__dataHost72',
  220. '__CE_shadowRoot72',
  221. 'elements_72',
  222.  
  223. 'ky36',
  224. 'kz62',
  225. 'm822',
  226.  
  227.  
  228.  
  229. // To be reviewed.
  230.  
  231. // chat messages
  232. 'disabled', 'allowedProps',
  233. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  234.  
  235. 'dimension', 'loadTime', 'pendingPaint',
  236.  
  237. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  238.  
  239. 'respectLangDir', 'noEndpoints',
  240.  
  241.  
  242. 'objectURL',
  243. 'buttonOverrides', 'queuedMessages',
  244. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  245. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  246. 'hoverJobId', 'JSC$14573_touched',
  247.  
  248.  
  249. // tbc
  250. 'toggleable', 'isConnected',
  251. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  252. 'disableDeselectEvent',
  253. 'emojiSize',
  254.  
  255. 'buttonOverride',
  256. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  257.  
  258. // others
  259. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  260. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  261. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  262. // 'dimension', 'loadTime', 'pendingPaint',
  263. // 'disabled', 'allowedProps',
  264.  
  265.  
  266. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  267. // 'actionMap',
  268.  
  269. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  270.  
  271. 'clearTimeout',
  272. 'switchTemplateAtRegistration', 'hasUnmounted',
  273. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  274. 'tangoConfiguration',
  275. 'itemIdToDockDurationMap',
  276. 'actionMap',
  277.  
  278. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  279. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  280. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  281.  
  282. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  283. // 'stopKeyboardEventPropagation', 'emojiSize',
  284. // 'switchTemplateAtRegistration', 'hasUnmounted',
  285. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  286. // 'isReusable', 'tangoConfiguration',
  287. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  288. // */
  289.  
  290. ]);
  291.  
  292.  
  293. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  294.  
  295. // ----------------------------- Shortkey Keyboard Control -----------------------------
  296.  
  297. /*
  298. window.addEventListener('edm',()=>{
  299. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  300. });
  301.  
  302. window.addEventListener('edn',()=>{
  303. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  304. });
  305. window.addEventListener('edr',()=>{
  306. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  307. });
  308. */
  309.  
  310. // only for macOS with Chrome/Firefox 100+
  311. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  312.  
  313. const win = this instanceof Window ? this : window;
  314.  
  315. // Create a unique key for the script and check if it is already running
  316. const hkey_script = 'jswylcojvzts';
  317. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  318. win[hkey_script] = true;
  319.  
  320.  
  321. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  322.  
  323. let BY_PASS_KEYBOARD_CONTROL = false;
  324.  
  325.  
  326. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  327. /** @type {(f: ()=>{})=>{}} */
  328. const nextBrowserTick = (self || 0).nextBrowserTick || 0;
  329. const nextBrowserTick_ = nextBrowserTick || (f => f());
  330.  
  331. let p59 = 0;
  332.  
  333. const Promise = (async () => { })().constructor;
  334.  
  335. const PromiseExternal = ((resolve_, reject_) => {
  336. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  337. return class PromiseExternal extends Promise {
  338. constructor(cb = h) {
  339. super(cb);
  340. if (cb === h) {
  341. /** @type {(value: any) => void} */
  342. this.resolve = resolve_;
  343. /** @type {(reason?: any) => void} */
  344. this.reject = reject_;
  345. }
  346. }
  347. };
  348. })();
  349.  
  350. let ttpHTML = (s) => {
  351. ttpHTML = s => s;
  352. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  353. let s = s => s;
  354. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  355. }
  356. return s;
  357. }
  358.  
  359.  
  360. const HTMLElement_ = HTMLElement;
  361. const nativeAppendE = HTMLElement_.prototype.append;
  362. const nativeRemoveE = HTMLElement_.prototype.remove;
  363. const DocumentFragment_ = DocumentFragment;
  364. const nativeAppendD = DocumentFragment_.prototype.append;
  365. const Node_ = Node;
  366.  
  367. /**
  368. @param {number} x
  369. @param {number} d */
  370. const toFixed2 = (x, d) => {
  371. let t = x.toFixed(d);
  372. let y = `${+t}`;
  373. return y.length > t.length ? t : y;
  374. }
  375.  
  376.  
  377. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  378.  
  379.  
  380. const TRANSLATE_DEBUG = false;
  381.  
  382.  
  383. function getTranslate() {
  384.  
  385. pLoad.then(() => {
  386.  
  387. let nonce = document.querySelector('style[nonce]');
  388. nonce = nonce ? nonce.getAttribute('nonce') : null;
  389. const st = document.createElement('style');
  390. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  391. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  392. let parent;
  393. if (parent = document.head) parent.appendChild(st);
  394. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  395.  
  396. });
  397.  
  398. const snCache = new Map();
  399.  
  400. if (TRANSLATE_DEBUG) {
  401. console.log(11)
  402. }
  403.  
  404. /** @type {(str: string?) => string} */
  405. function _snippetText(str) {
  406. // str can be underfinded
  407. if (!str || typeof str !== 'string') return '';
  408. let res = snCache.get(str);
  409. if (res === undefined) {
  410. let b = false;
  411. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  412. b = true;
  413. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  414. });
  415. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  416. b = true;
  417. return '';
  418. });
  419. if (b) {
  420. snCache.set(str, res);
  421. snCache.set(res, null);
  422. } else {
  423. res = null;
  424. snCache.set(str, null);
  425. }
  426. }
  427. return res === null ? str : res;
  428. }
  429.  
  430. /** @type {(snippet: Object) => string} */
  431. function snippetText(snippet) {
  432. let runs = snippet.runs;
  433. const n = runs.length;
  434. if (n === 1) return _snippetText(runs[0].text);
  435. let res = new Array(n);
  436. let ci = 0;
  437. for (const s of runs) {
  438. res[ci++] = _snippetText(s.text);
  439. }
  440. return res.join('\n');
  441. }
  442.  
  443. const _DEBUG_szz = (t) => t.map(x => {
  444. const tsr = x.transcriptSegmentRenderer;
  445. return ({
  446. t: tsr.snippet.runs.map(x => x.text).join('//'),
  447. a: tsr.startMs,
  448. b: tsr.endMs
  449. });
  450. });
  451.  
  452. const fixRuns = (runs) => {
  453. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  454. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  455. const text = runs[0].text;
  456. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  457. const s = text.split(nlc);
  458. let bi = 0;
  459. runs.length = s.length;
  460. for (const text of s) {
  461. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  462. }
  463. }
  464. for (const s of runs) {
  465. s.text = _snippetText(s.text);
  466. }
  467. }
  468.  
  469. function translate(initialSegments) {
  470. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  471.  
  472. if (!initialSegments) return initialSegments;
  473.  
  474. if (TRANSLATE_DEBUG) {
  475. console.log(12);
  476. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  477. let obj = JSON.parse(r);
  478. console.log(7558, 1, obj)
  479. return obj;
  480. }).then(p => {
  481. let obj = _DEBUG_szz(p)
  482. console.log(7558, 2, obj)
  483. })
  484. }
  485.  
  486.  
  487. //let mapRej = new WeakSet();
  488.  
  489. const n1 = initialSegments.length;
  490. if (!n1) return fRes;
  491. let n2 = 0;
  492.  
  493.  
  494. const fRes = new Array(n1);
  495. // -----------------------------------------------------------------------------------------
  496.  
  497. const s8 = Symbol();
  498.  
  499. {
  500.  
  501. /** @type {Map<String, Object>} */
  502. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  503.  
  504. // /-* * @type {Map<String, number>} *-/
  505. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  506. // 1: ok
  507. // 2: abandoned effect text
  508.  
  509. for (const initialSegment of initialSegments) {
  510. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  511. if (!transcript) {
  512. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  513. fRes[n2++] = initialSegment;
  514. continue;
  515. }
  516. const runs = transcript.snippet.runs
  517. if (!runs || runs.length === 0) {
  518. initialSegment[s8] = true;
  519. continue;
  520. }
  521. let startMs = (+transcript.startMs || 0); //integer
  522. let endMs = (+transcript.endMs || 0); //integer
  523. if (startMs === endMs) {
  524. // effect text
  525. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  526. //mapRej.add(initialSegment)
  527. continue;
  528. }
  529. if (endMs - startMs < 30) {
  530. continue;
  531. }
  532. const text = snippetText(transcript.snippet);
  533. const hEntry = cacheTexts.get(text);
  534. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  535. if (mh1e === 2) continue;
  536. const entry = {
  537. startMs,
  538. endMs,
  539. initialSegment,
  540. text
  541. };
  542. if (mh1e === 0) {
  543. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  544. initialSegment[s8] = true;
  545. cacheTexts.set(text, null);
  546. //effect only
  547. // https://www.youtube.com/watch?v=zLak0dxBKpM
  548. //mapRej.add(initialSegment)
  549. continue;
  550. }
  551. } else if (hEntry) {
  552.  
  553. const timeDiff = entry.startMs - hEntry.endMs;
  554. let shouldMerge = false;
  555.  
  556. if (timeDiff >= 0) {
  557.  
  558. if (timeDiff < 25) {
  559. shouldMerge = true;
  560. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  561. shouldMerge = true;
  562. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  563. shouldMerge = true;
  564. }
  565.  
  566. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  567. // abandon the current entry.
  568. // absorbed by previous entry
  569. hEntry.endMs = entry.endMs;
  570. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  571. //mapRej.add(entry.initialSegment);
  572. continue;
  573. }
  574.  
  575. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  576.  
  577. // abandon the current entry.
  578. // absorbed by previous entry
  579. if (entry.endMs > hEntry.endMs) {
  580. hEntry.endMs = entry.endMs;
  581. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  582. }
  583. //mapRej.add(entry.initialSegment);
  584. continue;
  585.  
  586. }
  587.  
  588. }
  589. //if not abandoned
  590. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  591. // for (const s of runs) {
  592. // s.text = _snippetText(s.text);
  593. // }
  594. fixRuns(runs);
  595. fRes[n2++] = initialSegment;
  596. }
  597.  
  598. // cacheTexts.clear(); // let GC do it.
  599. cacheTexts = null;
  600. // mh1.clear(); // let GC do it.
  601. // mh1 = null;
  602.  
  603. }
  604.  
  605. const si_length = fRes.length = n2;
  606. const sj_length = n1;
  607.  
  608. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  609. // collect the abandon text to become second subtitle
  610.  
  611. let sj_start = 0;
  612. let invalid_sj = -1;
  613. for (let si = 0; si < si_length; si++) {
  614. const segment = fRes[si];
  615. let transcript = segment.transcriptSegmentRenderer;
  616. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  617. const runs = transcript.snippet.runs;
  618. // fixRuns(runs);
  619. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  620. const main_startMs = (+transcript.startMs || 0);
  621. const main_endMs = (+transcript.endMs || 0);
  622. transcript = null;
  623.  
  624. /** @type {Map<string, number>} */
  625. let tMap = new Map(); // avoid duplicate with javascript object properties
  626.  
  627. // assume that it is asc-ordered array of key startMs;
  628. for (let sj = sj_start; sj < sj_length; sj++) {
  629. const initialSegment = initialSegments[sj];
  630.  
  631. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  632.  
  633. const tSegment = initialSegment.transcriptSegmentRenderer;
  634.  
  635. if (!tSegment) {
  636. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  637. invalid_sj = sj; // should invalid_sj be set ?
  638. continue;
  639. }
  640.  
  641. const startMs = (+tSegment.startMs || 0)
  642. const isStartValid = startMs >= main_startMs;
  643. if (!isStartValid) {
  644. invalid_sj = sj;
  645. continue;
  646. }
  647. // isStartValid must be true
  648. if (startMs > main_endMs) {
  649. sj_start = invalid_sj + 1;
  650. break;
  651. }
  652.  
  653. const endMs = (+tSegment.endMs || 0)
  654. if (endMs <= main_endMs) {
  655. const mt = snippetText(tSegment.snippet);
  656. const prev = tMap.get(mt);
  657. if (endMs >= startMs) {
  658. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  659. }
  660. }
  661.  
  662. }
  663.  
  664. if (tMap.size <= 1) continue; // no second line
  665. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  666. tMap = null;
  667.  
  668. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  669.  
  670. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  671.  
  672. let targetZ = rg[1][1];
  673. if (targetZ > 4) {
  674. let az = 0;
  675. let fail = false;
  676. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  677. az += rg[idx][1];
  678. if (az >= targetZ) {
  679. fail = true;
  680. break;
  681. }
  682. }
  683. if (!fail) {
  684. const rgA = rg[0][0];
  685. const rgB = rg[1][0];
  686. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  687. if (isDiff && rgA === _snippetText(runs[0].text)) {
  688. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  689. runs.push({ text: rgB, blockLine: true });
  690. }
  691. }
  692. }
  693. rg = null;
  694. }
  695.  
  696. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  697.  
  698. let obj = r;
  699. console.log(7559, 1, obj)
  700. return obj;
  701. }).then(p => {
  702. let obj = _DEBUG_szz(p)
  703. console.log(7559, 2, obj)
  704.  
  705. });
  706. }
  707.  
  708. // -----------------------------------------------------------------------------------------
  709. snCache.clear();
  710. return fRes;
  711.  
  712. }
  713.  
  714.  
  715. return translate
  716.  
  717. }
  718.  
  719.  
  720. let translateFn = null;
  721.  
  722. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  723.  
  724. const wmx = new WeakMap();
  725.  
  726. function fixSegments(ytObj) {
  727. let a, b;
  728. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  729. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  730. translateFn = translateFn || getTranslate();
  731. let cSeg;
  732. cSeg = wmx.get(seg);
  733. if (!cSeg) {
  734. let vSeg = null;
  735. try {
  736. vSeg = translateFn(seg);
  737. } catch (e) {
  738. }
  739. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  740. // console.log('translated', vSeg);
  741. cSeg = vSeg;
  742. wmx.set(seg, cSeg);
  743. wmx.set(cSeg, cSeg);
  744. }
  745. }
  746. if (cSeg && cSeg !== seg) {
  747. a[b] = cSeg;
  748. }
  749. }
  750.  
  751. const dfn = Symbol();
  752. const Object_ = Object;
  753. Object_[dfn] = Object_.defineProperties;
  754. let activation = true;
  755. Object_.defineProperties = function (obj, pds) {
  756. let segments, get_;
  757. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  758. activation = false;
  759. segments.get = function () {
  760. fixSegments(this);
  761. return get_.call(this);
  762. };
  763. }
  764. return Object_[dfn](obj, pds);
  765. };
  766.  
  767. })();
  768.  
  769.  
  770. let pf31 = new PromiseExternal();
  771.  
  772. // native RAF
  773. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  774.  
  775. // 1st wrapped RAF
  776. const baseRAF = (callback) => {
  777. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  778. pf31.then(() => {
  779. callback(hRes);
  780. });
  781. });
  782. };
  783.  
  784. // 2nd wrapped RAF
  785. window.requestAnimationFrame = baseRAF;
  786.  
  787. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  788. const indr = o => insp(o).$ || o.$ || 0;
  789.  
  790. const prototypeInherit = (d, b) => {
  791. const m = Object.getOwnPropertyDescriptors(b);
  792. for (const p in m) {
  793. if (!Object.getOwnPropertyDescriptor(d, p)) {
  794. Object.defineProperty(d, p, m[p]);
  795. }
  796. }
  797. };
  798.  
  799.  
  800. const firstObjectKey = (obj) => {
  801. for (const key in obj) {
  802. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  803. }
  804. return null;
  805. };
  806.  
  807. function searchNestedObject(obj, predicate, maxDepth = 64) {
  808. // normal case: depth until 36
  809. const result = [];
  810. const visited = new WeakSet();
  811.  
  812. function search(obj, depth) {
  813. visited.add(obj);
  814. for (const [key, value] of Object.entries(obj)) {
  815. // Recursively search nested objects and arrays
  816. if (value !== null && typeof value === 'object') {
  817. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  818. if (depth + 1 <= maxDepth && !visited.has(value)) {
  819. search(value, depth + 1);
  820. }
  821. } else if (predicate(value)) {
  822. result.push([obj, key]);
  823. }
  824. }
  825. }
  826.  
  827. typeof (obj || 0) === 'object' && search(obj, 0);
  828. return result;
  829. }
  830.  
  831. /** @type {(o: Object | null) => WeakRef | null} */
  832. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  833.  
  834. /** @type {(wr: Object | null) => Object | null} */
  835. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  836.  
  837. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  838.  
  839. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  840. if (DENY_requestStorageAccess) {
  841. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  842. Document.prototype.requestStorageAccessFor = undefined;
  843. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  844. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  845. Document.prototype.requestStorageAccessFor = function () {
  846. return new Promise((resolve, reject) => {
  847. reject();
  848. });
  849. };
  850. }
  851. }
  852.  
  853. const traceStack = (stack) => {
  854. let result = new Set();
  855. let p = new Set();
  856. let u = ''
  857. for (const s of stack.split('\n')) {
  858. if (s.split(':').length < 3) continue;
  859. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  860. if (!m) continue;
  861. p.add(m[2]);
  862. if (p.size >= 3) break;
  863. if(!u) u = m[2];
  864. else if(p.size === 2 && u && u=== m[2]) break;
  865. result.add(s);
  866. }
  867. return [...result].join('\n');
  868. }
  869.  
  870. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  871. // window.m3bb = new Set();
  872.  
  873. // const smb = Symbol();
  874. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  875. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  876. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  877.  
  878. // const fnProxySelf = function (...args) {
  879. // if (args[0] === smb) return this;
  880. // const cnt = kRef(this.ref);
  881. // if (cnt) {
  882. // if (typeof cnt[this.prop] !== 'function') console.error(`this.${this.prop} is not a function. [${cnt.is || 'nil'}]`)
  883. // return cnt[this.prop](...args); // might throw error
  884. // }
  885. // }
  886. // fnProxySelf.bind588 = fnProxySelf.bind;
  887. // const pFnHandler = {
  888. // get(target, prop){
  889. // if(prop === 'bind588') return 2;
  890. // const fnThis = target(smb);
  891. // if (fnThis && fnThis.prop && fnThis.ref) {
  892. // const cnt = kRef(fnThis.ref || null) || null;
  893. // if (cnt) {
  894. // const h = cnt[fnThis.prop];
  895. // const v = h[prop];
  896. // if (typeof v === 'function'){
  897. // if(typeof h === 'function'){
  898. // if (prop === 'call' || prop === 'bind' || prop === 'bind588' || prop === 'bind488' || prop === 'apply') {
  899. // if(h.bind588 === 1){
  900. // const g = function(...args){
  901. // console.log(1288, this)
  902. // return h.call(this, ...args);
  903. // };
  904. // console.log(399, g)
  905. // return g[prop];
  906. // // console.log(12778)
  907. // // console.log(target, target.call)
  908. // // return target[prop];
  909. // }
  910. // // independent of this
  911. // return v; // function.bind, function.call, function.apply
  912. // }
  913. // }
  914. // console.warn('cnt[fnThis.prop][prop] is function; might rely on this', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
  915.  
  916. // // return new Proxy(fnProxySelf.bind588({ prop: prop, ref: new WeakRef(cnt[fnThis.prop]) }), pFnHandler);
  917. // }
  918. // return v;
  919. // }
  920. // }
  921. // },
  922. // set(target, prop, value) {
  923. // const fnThis = target(smb);
  924. // if (fnThis && fnThis.prop && fnThis.ref) {
  925. // const cnt = kRef(fnThis.ref || null) || null;
  926. // if (cnt) {
  927. // const h = cnt[fnThis.prop];
  928. // if (h) {
  929. // h[prop] = value;
  930. // } else {
  931. // console.log('h is nout found', { prop, fProp: fnThis.prop, is: cnt.is, h: h });
  932. // }
  933. // }
  934. // }
  935. // return true;
  936. // }
  937. // };
  938.  
  939. const thisConversionFn = (thisArg) => {
  940. if (!thisArg) return null;
  941. const kThis = thisArg[vmb];
  942. if (kThis) {
  943. const ref = kThis.ref;
  944. return (ref ? kRef(ref) : null) || null;
  945. }
  946. return thisArg;
  947. }
  948.  
  949. const pFnHandler2 = {
  950. get(target, prop) {
  951. if (prop === vmc) return target;
  952. return Reflect.get(target, prop);
  953. },
  954. apply(target, thisArg, argumentsList) {
  955. thisArg = thisConversionFn(thisArg);
  956. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  957. }
  958. }
  959.  
  960.  
  961. const proxySelfHandler = {
  962. get(target, prop) {
  963. if(prop === vmb) return target;
  964. const ref = target.ref;
  965. const cnt = kRef(ref);
  966. if (!cnt) return;
  967. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  968. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  969. return cnt[prop][vmd];
  970. }
  971. return cnt[prop];
  972. },
  973. set(target, prop, value) {
  974. const cnt = kRef(target.ref);
  975. if (!cnt) return true;
  976. if(value && (value[vmc] || value[vmb])){
  977. cnt[prop] = value[vmc] || thisConversionFn(value);
  978. return true;
  979. }
  980. cnt[prop] = value;
  981. return true;
  982. }
  983. };
  984.  
  985. const weakWrap = (thisArg) => {
  986. thisArg = thisConversionFn(thisArg);
  987. if (!thisArg) {
  988. console.error('thisArg is not found');
  989. return null;
  990. }
  991. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  992. }
  993.  
  994. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  995. window.getComputedStyle533 = window.getComputedStyle;
  996. window.getComputedStyle = function (a, ...args) {
  997. a = thisConversionFn(a);
  998. if (a) {
  999. return getComputedStyle533(a, ...args);
  1000. }
  1001. return null;
  1002. }
  1003. }
  1004.  
  1005. Function._count_bind_00 = 0;
  1006. // Function._count_bind_01 = 0;
  1007.  
  1008. // let matchNativeCode = (Object+"");
  1009. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1010. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1011.  
  1012. // const matchConstructor = (thisArg) => {
  1013. // const f = `${(thisArg || 0).constructor}`;
  1014. // if (f.length > 45) return true;
  1015. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1016. // if (f.includes('[native code]')){
  1017. // return false;
  1018. // }
  1019. // return true;
  1020. // }
  1021. // return false;
  1022. // }
  1023.  
  1024. // const acceptThis = (thisArg)=>{
  1025. // // if(!thisArg || typeof thisArg !=='object') return false;
  1026. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1027. // // if(typeof thisArg.path === 'string') return true;
  1028. // // if(typeof thisArg.fn === 'function') return true;
  1029. // // if(typeof thisArg.id === 'string') return true;
  1030. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1031. // return false;
  1032. // }
  1033.  
  1034. const patchFn = (fn) => {
  1035.  
  1036. let s = `${fn}`;
  1037. if (s.length < 11 || s.includes('\n')) return false;
  1038. if(s.includes('bind(this')) return true;
  1039. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1040. // var a=this;
  1041. // f.bind(this)
  1042.  
  1043.  
  1044. return false;
  1045. }
  1046.  
  1047. Function.prototype.bind488 = Function.prototype.bind;
  1048. Function.prototype.bind = function(thisArg, ...args){
  1049.  
  1050. if (thisConversionFn(thisArg) !== thisArg) {
  1051. return this.bind488(thisArg, ...args);
  1052. }
  1053. if( thisArg && patchFn(this) ){
  1054.  
  1055. // console.log(599,`${this}`)
  1056.  
  1057. try {
  1058. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1059. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1060. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1061. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1062. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1063. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1064. // // let b4 = false;
  1065. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1066.  
  1067. // // b3 = false;
  1068. // // b4 = false;
  1069. // // b5 = false;
  1070.  
  1071. // if (b1 || b2 || b3 ||b4 ) {
  1072. const f = this;
  1073. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1074. if (ps && ps[vmb]) {
  1075. Function._count_bind_00++;
  1076. return f.bind488(ps, ...args)
  1077. }
  1078. // }
  1079. } catch (e) {
  1080. console.warn(e)
  1081. }
  1082. }
  1083. return this.bind488(thisArg, ...args);
  1084. }
  1085. Function.prototype.bind588 = 1;
  1086. }
  1087.  
  1088.  
  1089. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  1090. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  1091. const wm6 = new WeakMapOriginal();
  1092.  
  1093. const skipW = new WeakSet();
  1094.  
  1095.  
  1096. window.WeakMap = class WeakMap extends WeakMapOriginal {
  1097. constructor(iterable = undefined) {
  1098. super();
  1099. if (iterable && iterable[Symbol.iterator]) {
  1100. for (const entry of iterable) {
  1101. entry && this.set(entry[0], entry[1]);
  1102. }
  1103. }
  1104. }
  1105. delete(a) {
  1106. if (!this.has(a)) return false;
  1107. super.delete(a);
  1108. return true;
  1109. }
  1110. get(a) {
  1111. const p = super.get(a);
  1112. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1113. let v = kRef(p);
  1114. if (!v) {
  1115. super.delete(a);
  1116. }
  1117. return v || undefined;
  1118. }
  1119. return p;
  1120. }
  1121. has(a) {
  1122. if (!super.has(a)) return false;
  1123. const p = super.get(a);
  1124. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1125. if (!kRef(p)) {
  1126. super.delete(a);
  1127. return false;
  1128. }
  1129. }
  1130. return true;
  1131. }
  1132. set(a, b) {
  1133. let wq = b;
  1134. if (b && (typeof b === 'function' || typeof b === 'object')) {
  1135. if (b.deref) {
  1136. skipW.add(b);
  1137. wq = b;
  1138. } else {
  1139. wq = wm6.get(b);
  1140. if (!wq) {
  1141. wq = mWeakRef(b);
  1142. wm6.set(b, wq);
  1143. }
  1144. }
  1145. }
  1146. super.set(a, wq);
  1147. return this;
  1148. }
  1149. }
  1150. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  1151. configurable: true,
  1152. enumerable: false,
  1153. value: "WeakMap",
  1154. writable: false
  1155. });
  1156. }
  1157.  
  1158. const isWatchPageURL = (url) => {
  1159. url = url || location;
  1160. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  1161. };
  1162.  
  1163. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  1164.  
  1165. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  1166. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1167. if (typeof customElements === 'undefined') {
  1168. if (!('__CE_registry' in document)) {
  1169. // https://github.com/webcomponents/polyfills/
  1170. Object.defineProperty(document, '__CE_registry', {
  1171. get() {
  1172. // return undefined
  1173. },
  1174. set(nv) {
  1175. if (typeof nv == 'object') {
  1176. delete this.__CE_registry;
  1177. this.__CE_registry = nv;
  1178. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1179. }
  1180. return true;
  1181. },
  1182. enumerable: false,
  1183. configurable: true
  1184. })
  1185. }
  1186. let eventHandler = (evt) => {
  1187. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1188. const f = callback;
  1189. callback = null;
  1190. eventHandler = null;
  1191. f();
  1192. };
  1193. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1194. } else {
  1195. callback();
  1196. }
  1197. });
  1198.  
  1199. const whenCEDefined = isCustomElementsProvided
  1200. ? (nodeName) => customElements.whenDefined(nodeName)
  1201. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  1202.  
  1203. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  1204. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  1205. const f = performance.now23 = Performance.prototype.now;
  1206.  
  1207. let k = 0; // 0 <= k < 9998m
  1208. let u = 0;
  1209. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  1210.  
  1211. // By definition, performance.now() is mono increasing.
  1212. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  1213. performance.now = performance.now16 = function () {
  1214. /**
  1215. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  1216. *
  1217. * If consecutive session history entries had history.state.entryTime set to same value,
  1218. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  1219. * and modifying its return value slightly to make sure two close consecutive calls don't
  1220. * get the same result helped with resolving the issue.
  1221. */
  1222. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  1223. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  1224.  
  1225. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  1226. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  1227. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  1228. else { // more than 9998 consecutive calls
  1229. /**
  1230. *
  1231. * max no. of consecutive calls
  1232. *
  1233. * Sample Size: 4800
  1234. * Sample Avg = 1565.375
  1235. * Sample Median = 1469.5
  1236. * Sample Max = 5660 << 7500 << 9999
  1237. *
  1238. *
  1239. * */
  1240. k = 0;
  1241. s += 1 / 7;
  1242. }
  1243. return v + k; // 0 < v - M < v - M + k < v
  1244. }
  1245.  
  1246. let loggerMsg = '';
  1247. if (`${performance.now()}` === `${performance.now()}`) {
  1248. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  1249. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  1250. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  1251. }
  1252. loggerMsg && console.warn(loggerMsg);
  1253. })();
  1254.  
  1255. FIX_removeChild && (() => {
  1256. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  1257. Node.prototype.removeChild062 = Node.prototype.removeChild;
  1258. Node.prototype.removeChild = function (child) {
  1259. if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  1260. this.removeChild062(child);
  1261. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  1262. // tooltip bug
  1263. } else {
  1264. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  1265. }
  1266. return child;
  1267. }
  1268. }
  1269. })();
  1270.  
  1271.  
  1272. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  1273.  
  1274. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  1275.  
  1276. // let cid = 0;
  1277.  
  1278. let mousemoveFn = null;
  1279. let mousemoveDT = 0;
  1280. let mousemoveCount = 0;
  1281. // let qv = false;
  1282. const cif = () => {
  1283. if (!mousemoveFn) return;
  1284. const ct = Date.now();
  1285. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  1286. mousemoveFn && mousemoveFn();
  1287. }
  1288. mousemoveFn = null;
  1289. };
  1290. let mousemoveCId = 0;
  1291. let mouseoverFn = null;
  1292. HTMLElement.prototype.addEventListener4882 = HTMLElement.prototype.addEventListener;
  1293. HTMLElement.prototype.addEventListener = function (a, b, c) {
  1294. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  1295. const bt = `${b}`;
  1296. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  1297. b[`__$$${a}$$1926__`] = true;
  1298. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  1299. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  1300. // console.log(3928, a, this[`__$$${a}$$1937__`])
  1301. if (!this[`__$$${a}$$1938__`]) {
  1302. this[`__$$${a}$$1938__`] = b;
  1303. if (a === 'mousemove') {
  1304. this.addEventListener4882('mouseenter', (evt) => {
  1305. if (mousemoveCId) return;
  1306. mousemoveCId = setIntervalX0(cif, 380);
  1307. });
  1308. this.addEventListener4882('mouseleave', (evt) => {
  1309. clearIntervalX0(mousemoveCId);
  1310. mousemoveCId = 0;
  1311. });
  1312. }
  1313. this.addEventListener4882(a, (evt) => {
  1314. const evt_ = evt;
  1315. if (!this[`__$$${a}$$1937__`]) return;
  1316. if (!this[`__$$${a}$$1938__`]) return;
  1317. if (a === 'mousemove') {
  1318. mouseoverFn && mouseoverFn();
  1319. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  1320. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  1321. } else {
  1322. mousemoveCount = 0;
  1323. }
  1324. const f = mousemoveFn = () => {
  1325. if (f !== mousemoveFn) return;
  1326. mousemoveFn = null;
  1327. this[`__$$${a}$$1938__`](evt_);
  1328. };
  1329. if (mousemoveCount <= 1) mousemoveFn();
  1330. } else {
  1331. if (a === 'mouseout' || a === 'mouseleave') {
  1332. mousemoveFn = null;
  1333. mousemoveDT = 0;
  1334. mousemoveCount = 0;
  1335. this[`__$$${a}$$1938__`](evt_);
  1336. mouseoverFn && mouseoverFn();
  1337. } else { // mouseover, mouseenter
  1338. mousemoveFn = null;
  1339. mousemoveDT = 0;
  1340. mousemoveCount = 0;
  1341. mouseoverFn && mouseoverFn(); // just in case
  1342. const f = mouseoverFn = () => {
  1343. if (f !== mouseoverFn) return;
  1344. mouseoverFn = null;
  1345. this[`__$$${a}$$1938__`](evt_);
  1346. }
  1347. nextBrowserTick(mouseoverFn);
  1348. }
  1349. }
  1350. }, c);
  1351.  
  1352.  
  1353. return;
  1354. } else {
  1355.  
  1356. return;
  1357. }
  1358. }
  1359.  
  1360. }
  1361. return this.addEventListener4882(a, b, c)
  1362. }
  1363.  
  1364.  
  1365.  
  1366.  
  1367. HTMLElement.prototype.removeEventListener4882 = HTMLElement.prototype.removeEventListener;
  1368. HTMLElement.prototype.removeEventListener = function (a, b, c) {
  1369. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  1370.  
  1371. if (b[`__$$${a}$$1926__`]) {
  1372. b[`__$$${a}$$1926__`] = false;
  1373.  
  1374. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  1375.  
  1376. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  1377.  
  1378. return;
  1379.  
  1380. }
  1381.  
  1382. }
  1383. return this.removeEventListener4882(a, b, c)
  1384. }
  1385.  
  1386.  
  1387. })();
  1388.  
  1389.  
  1390. FIX_DOM_IF_REPEAT && (() => {
  1391. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  1392. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  1393. // Be careful of the mixture of polymer functions and native Element functions
  1394. // Be careful of the coding design is different with the modern Yt elements
  1395.  
  1396.  
  1397. /*
  1398.  
  1399.  
  1400. function Ks(a, b, c) {
  1401. if (kj && !BOa(a))
  1402. throw Error("strictTemplatePolicy: template owner not trusted");
  1403. c = c || {};
  1404. if (a.__templatizeOwner)
  1405. throw Error("A <template> can only be templatized once");
  1406. a.__templatizeOwner = b;
  1407. var d = (b ? b.constructor : Js)._parseTemplate(a)
  1408. , e = d.templatizeInstanceClass;
  1409. e || (e = COa(a, d, c),
  1410. d.templatizeInstanceClass = e);
  1411. var g = BOa(a);
  1412. EOa(a, d, c, g);
  1413. c = function() {
  1414. return e.apply(this, arguments) || this
  1415. }
  1416. ;
  1417. h(c, e);
  1418. c.prototype._methodHost = g;
  1419. c.prototype.__dataHost = a;
  1420. c.prototype.__templatizeOwner = b;
  1421. c.prototype.__hostProps = d.hostProps;
  1422. return c
  1423. }
  1424.  
  1425. */
  1426.  
  1427. // Polymer.enqueueDebouncer
  1428.  
  1429. const s81 = Symbol();
  1430. const s83 = Symbol();
  1431. const s84 = Symbol();
  1432. const s85 = Symbol();
  1433. const s85b = Symbol();
  1434. const s85c = Symbol();
  1435.  
  1436. let renderDebounceTs = null;
  1437.  
  1438. let renderDebouncePromise = null;
  1439. let qp;
  1440.  
  1441. let cme = 0;
  1442.  
  1443. const shadyFlushMO = new MutationObserver(() => {
  1444.  
  1445. if (!renderDebounceTs) return;
  1446.  
  1447. if (renderDebounceTs.size > 0) {
  1448. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  1449. try {
  1450. Polymer.flush();
  1451. return;
  1452. } catch (e) { }
  1453. }
  1454.  
  1455. renderDebouncePromise && Promise.resolve().then(() => {
  1456.  
  1457. if (renderDebouncePromise) {
  1458. renderDebouncePromise && renderDebouncePromise.resolve();
  1459. renderDebouncePromise = null;
  1460. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  1461. }
  1462.  
  1463. });
  1464.  
  1465. // Polymer.flush
  1466.  
  1467. window.ShadyDOM && ShadyDOM.flush();
  1468. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  1469.  
  1470.  
  1471. });
  1472.  
  1473. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  1474.  
  1475. const observablePromise = (proc, timeoutPromise) => {
  1476. let promise = null;
  1477. return {
  1478. obtain() {
  1479. if (!promise) {
  1480. promise = new Promise(resolve => {
  1481. let mo = null;
  1482. const f = () => {
  1483. let t = proc();
  1484. if (t) {
  1485. mo.disconnect();
  1486. mo.takeRecords();
  1487. mo = null;
  1488. resolve(t);
  1489. }
  1490. }
  1491. mo = new MutationObserver(f);
  1492. mo.observe(document, { subtree: true, childList: true })
  1493. f();
  1494. timeoutPromise && timeoutPromise.then(() => {
  1495. resolve(null)
  1496. });
  1497. });
  1498. }
  1499. return promise
  1500. }
  1501. }
  1502. }
  1503.  
  1504.  
  1505. let p = 0;
  1506. qp = observablePromise(() => {
  1507. if (!(p & 1)) {
  1508.  
  1509. if (window.ShadyDOM && ShadyDOM.flush) {
  1510. p |= 1;
  1511. if (!ShadyDOM.flush847) {
  1512.  
  1513. ShadyDOM.flush847 = ShadyDOM.flush;
  1514. ShadyDOM.flush = function () {
  1515.  
  1516. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  1517. renderDebouncePromise && Promise.resolve().then(() => {
  1518. if (renderDebouncePromise) {
  1519.  
  1520. renderDebouncePromise && renderDebouncePromise.resolve();
  1521. renderDebouncePromise = null;
  1522.  
  1523. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  1524.  
  1525. }
  1526.  
  1527. });
  1528. let r = this.flush847(...arguments);
  1529. if (r) {
  1530. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1531. }
  1532. return r
  1533. }
  1534.  
  1535. }
  1536. }
  1537. }
  1538.  
  1539. if (!(p & 2)) {
  1540.  
  1541. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  1542. p |= 2;
  1543. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  1544. if (!ScopingShim.flush848) {
  1545.  
  1546. ScopingShim.flush848 = ScopingShim.flush;
  1547. ScopingShim.flush = function () {
  1548.  
  1549. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  1550.  
  1551. renderDebouncePromise && Promise.resolve().then(() => {
  1552.  
  1553. if (renderDebouncePromise) {
  1554.  
  1555. renderDebouncePromise && renderDebouncePromise.resolve();
  1556. renderDebouncePromise = null;
  1557.  
  1558. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  1559.  
  1560.  
  1561.  
  1562. }
  1563.  
  1564. });
  1565. return this.flush848(...arguments);
  1566. }
  1567.  
  1568. }
  1569. }
  1570. }
  1571. if (p === 3) {
  1572. p |= 8;
  1573.  
  1574. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  1575. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  1576. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  1577.  
  1578. if (r) {
  1579. let w = Set.prototype.add;
  1580. let u = null;
  1581. Set.prototype.add = function () {
  1582. u = this;
  1583. throw new Error();
  1584. }
  1585. try {
  1586. Polymer.enqueueDebouncer()
  1587. } catch (e) { }
  1588. Set.prototype.add = w;
  1589. if (u !== null) {
  1590. renderDebounceTs = u;
  1591. if (DEBUG_renderDebounceTs) {
  1592. renderDebounceTs.add58438 = renderDebounceTs.add;
  1593. renderDebounceTs.add = function () {
  1594. console.log('renderDebounceTs.add')
  1595. console.log(traceStack((new Error()).stack))
  1596. // debugger;
  1597. return this.add58438(...arguments)
  1598. }
  1599.  
  1600. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  1601. renderDebounceTs.delete = function () {
  1602. console.log('renderDebounceTs.delete')
  1603. const stack = `${(new Error()).stack}`
  1604. let isCallbackRemoval = false;
  1605. if (stack) {
  1606. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  1607. const s = t.split(':');
  1608. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  1609. isCallbackRemoval = true;
  1610. }
  1611. }
  1612. if (isCallbackRemoval) {
  1613. return this.delete58438(...arguments)
  1614. }
  1615. console.log(traceStack((new Error()).stack))
  1616. // debugger;
  1617. return this.delete58438(...arguments)
  1618. }
  1619. }
  1620. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  1621. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  1622. }
  1623. }
  1624.  
  1625. return true;
  1626. }
  1627. })
  1628.  
  1629. // if(window.ShadyDOM && ShadyDOM.flush){
  1630. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  1631.  
  1632. // }
  1633. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  1634.  
  1635. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  1636. // }
  1637.  
  1638. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  1639.  
  1640. }
  1641.  
  1642. Object.defineProperty(Object.prototype, '_lastIf', {
  1643. get() {
  1644. return this[s81];
  1645. },
  1646. set(nv) {
  1647. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  1648. // DOM-IF initialization
  1649. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  1650.  
  1651. this.__xiWB8__ = 2;
  1652.  
  1653. const cProto = this.__proto__;
  1654. if (cProto && !cProto.__xiWB7__) {
  1655. cProto.__xiWB7__ = 1;
  1656.  
  1657. // dom-if __template
  1658. // dom-repeat template
  1659. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  1660. cProto.__template847 = true;
  1661. try {
  1662. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  1663. Object.defineProperty(cProto, '__template', {
  1664. get() {
  1665. const v = this[s84];
  1666. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  1667. },
  1668. set(nv) {
  1669. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  1670. this[s84] = nv;
  1671. return true;
  1672. }
  1673. });
  1674. } catch (e) {
  1675. console.warn(e);
  1676. }
  1677.  
  1678. console.log('FIX_DOM_IF - __template')
  1679. }
  1680.  
  1681. // dom-if __ensureTemplate
  1682. // dom-repeat __ensureTemplatized
  1683. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement && `${cProto.__ensureTemplate}`.length > 20) {
  1684. // note that "_templateInfo" diffs the different version of DOM-IF
  1685.  
  1686. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  1687. cProto.__ensureTemplate = function () {
  1688. if (!(this instanceof HTMLElement) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  1689. if (!this.__template) {
  1690. let b;
  1691. if (this._templateInfo) {
  1692. b = this;
  1693. } else {
  1694. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  1695. b = this.__templateCollection011__[0];
  1696. if (!b) {
  1697. let a = mWeakRef(this);
  1698. let c = new MutationObserver(function () {
  1699. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  1700. if (c && a) {
  1701. c.disconnect();
  1702. a = kRef(a);
  1703. a && a.__render();
  1704. a && (a.__templateCollection011__ = null);
  1705. }
  1706. c = null;
  1707. a = null;
  1708. });
  1709. c && c.observe(this, {
  1710. childList: !0
  1711. });
  1712. return !1
  1713. } else {
  1714. this.__templateCollection011__ = null;
  1715. }
  1716. }
  1717. this.__template = b
  1718. }
  1719. return !0
  1720. }
  1721.  
  1722. console.log('FIX_DOM_IF - __ensureTemplate')
  1723.  
  1724. }
  1725.  
  1726.  
  1727. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  1728.  
  1729. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  1730.  
  1731. // cProto.__createAndInsertInstance = function (a) {
  1732. // Promise.resolve().then(()=>{
  1733. // console.log('__createAndInsertInstance')
  1734. // window.lm5 = window.lm5 || [];
  1735. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  1736. // });
  1737. // return this.__createAndInsertInstance847(a);
  1738. // }
  1739.  
  1740. // }
  1741.  
  1742.  
  1743. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  1744.  
  1745. // cProto._bindTemplate847 = cProto._bindTemplate;
  1746.  
  1747. // cProto._bindTemplate = function (a, b) {
  1748. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  1749. // }
  1750.  
  1751. // }
  1752. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  1753.  
  1754. // cProto._stampTemplate847 = cProto._stampTemplate;
  1755.  
  1756. // cProto._stampTemplate = function (a, b) {
  1757. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  1758. // }
  1759.  
  1760. // }
  1761. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  1762. }
  1763.  
  1764.  
  1765. // need to fix __observeEffects
  1766. // this.__observeEffects.if[0].info.method === this.__debounceRender
  1767. const f = () => {
  1768.  
  1769. const __observeEffects = this.__observeEffects;
  1770.  
  1771. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  1772. for (const effect of __observeEffects.if) {
  1773. const info = effect.info;
  1774. if (info && typeof info.method === 'function') {
  1775.  
  1776. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  1777. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  1778. }
  1779.  
  1780. }
  1781. }
  1782. }
  1783.  
  1784.  
  1785. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  1786. for (const effect of __observeEffects.restamp) {
  1787. const info = effect.info;
  1788. if (info && typeof info.method === 'function') {
  1789.  
  1790. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  1791. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  1792. }
  1793.  
  1794. }
  1795. }
  1796. }
  1797.  
  1798. // console.log(5881, this.__observeEffects)
  1799. }
  1800. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  1801. f();
  1802. Promise.resolve().then(f);
  1803. // afterward, don't care adding fn directly (the fn is already modified)
  1804. }
  1805.  
  1806. }
  1807. this[s81] = nv;
  1808. return true;
  1809. }
  1810. });
  1811.  
  1812.  
  1813. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  1814. get() {
  1815. return this[s85];
  1816. },
  1817. set(nv) {
  1818. if (nv === null && this[s85] === undefined) {
  1819. // DOM-IF / DOM-REPEAT initialization
  1820.  
  1821.  
  1822. const cProto = this.__proto__;
  1823. if (qp) {
  1824. qp.obtain();
  1825. qp = null;
  1826. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  1827. }
  1828. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  1829.  
  1830. cProto.__debounceRender847 = cProto.__debounceRender;
  1831.  
  1832. if (cProto.__debounceRender.length === 2) {
  1833.  
  1834. cProto.__debounceRender = function (a, b) {
  1835.  
  1836. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  1837.  
  1838. b = b === void 0 ? 0 : b;
  1839.  
  1840. /*
  1841. b = b === void 0 ? 0 : b;
  1842. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  1843. vs(this.__renderDebouncer)
  1844. */
  1845.  
  1846. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1847.  
  1848. if (!renderDebouncePromise) {
  1849. renderDebouncePromise = new PromiseExternal();
  1850. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1851. }
  1852.  
  1853. renderDebouncePromise.then(async () => {
  1854. if (b > 0) await delayPn(b);
  1855.  
  1856. const f = this.__dsIRYqw1__;
  1857. if (f === cme) return;
  1858. this.__dsIRYqw1__ = cme;
  1859. a.call(this);
  1860. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  1861.  
  1862. });
  1863.  
  1864. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  1865. }
  1866.  
  1867. } else if (cProto.__debounceRender.length === 0) {
  1868.  
  1869.  
  1870. cProto.__debounceRender = function () {
  1871.  
  1872. if (!renderDebounceTs) return this.__debounceRender847();
  1873.  
  1874. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1875. /*
  1876. var a = this;
  1877. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  1878. return a.__render()
  1879. });
  1880. vs(this.__renderDebouncer)
  1881. */
  1882.  
  1883. if (!renderDebouncePromise) {
  1884. renderDebouncePromise = new PromiseExternal();
  1885. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  1886. }
  1887. renderDebouncePromise.then(() => {
  1888. const f = this.__dsIRYqw1__;
  1889. if (f === cme) return;
  1890. this.__dsIRYqw1__ = cme;
  1891. this.__render()
  1892. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  1893. });
  1894. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  1895.  
  1896.  
  1897. }
  1898. }
  1899. }
  1900.  
  1901.  
  1902.  
  1903. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  1904. // cProto.render847 = cProto.render;
  1905. // cProto.render = function(){
  1906.  
  1907. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1908. // try{
  1909. // this.render847();
  1910. // }catch(e){}
  1911. // // if(this.__DBR847__){
  1912. // // this.__DBR847__.resolve();
  1913. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  1914. // // }
  1915.  
  1916. // // renderDebouncePromise && renderDebouncePromise.resolve()
  1917. // // renderDebouncePromise = null;
  1918. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  1919.  
  1920. // }
  1921. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  1922. // }
  1923.  
  1924. }
  1925. this[s85] = nv;
  1926. return true;
  1927. }
  1928. });
  1929.  
  1930. // PS-DOM-REPEAT
  1931.  
  1932. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  1933. get() {
  1934. return this[s85b];
  1935. },
  1936. set(nv) {
  1937.  
  1938. this[s85b] = nv;
  1939. return true;
  1940. }
  1941. })
  1942.  
  1943. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  1944. get() {
  1945. return this[s85c];
  1946. },
  1947. set(nv) {
  1948.  
  1949. this[s85c] = nv;
  1950. return true;
  1951. }
  1952. })
  1953.  
  1954.  
  1955. })();
  1956.  
  1957. let xdeadc00 = null; // a deteched node with __domApi
  1958.  
  1959. const setupXdeadC = (cnt)=>{
  1960.  
  1961. let xdeadc = xdeadc00;
  1962. if(!xdeadc){
  1963. setupSDomWrapper(); // just in case
  1964. const hostElement = cnt.hostElement;
  1965. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  1966. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  1967. hostElement.lastChild.replaceWith(el);
  1968. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  1969. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  1970. el.firstElementChild.id = rid;
  1971. cnt.$[rid] = el.firstElementChild;
  1972. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  1973.  
  1974. xdeadc = cnt.getStampContainer_(rid);
  1975. el.remove();
  1976. xdeadc00 = xdeadc;
  1977. // console.log(xdeadc.__domApi)
  1978. // debugger;
  1979. // const xdeadv = xdeadc.__domApi;
  1980. }
  1981. return xdeadc00;
  1982. }
  1983.  
  1984. const setupSDomWrapper = () => {
  1985.  
  1986. const sdwProto = ShadyDOM.Wrapper.prototype;
  1987.  
  1988. if (sdwProto.__pseudo__isConnected__ !== null) {
  1989. sdwProto.__pseudo__isConnected__ = null;
  1990. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  1991. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  1992. const get = isConnectedPd.get;
  1993. isConnectedPd.get = function () {
  1994. const pseudoVal = this.__pseudo__isConnected__;
  1995. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  1996. }
  1997. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  1998. }
  1999.  
  2000.  
  2001.  
  2002. // if (!sdwProto.__nodeMove__) {
  2003.  
  2004. // sdwProto.__nodeMove__ = function (dest) {
  2005.  
  2006.  
  2007. // }
  2008.  
  2009.  
  2010. // }
  2011.  
  2012.  
  2013.  
  2014.  
  2015. // debugger;
  2016. // new xdeadc.__domApi.constructor(document.createElement('div'));
  2017. }
  2018.  
  2019. }
  2020. const setupDomApi = (daProto) => {
  2021.  
  2022. daProto.__daHook377__ = true;
  2023.  
  2024.  
  2025.  
  2026. }
  2027.  
  2028.  
  2029. // WEAKREF_ShadyDOM
  2030.  
  2031. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  2032.  
  2033. const setupPlainShadyDOM = (b) => {
  2034. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  2035. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  2036. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  2037. b.patchOnDemand = true;
  2038. b.preferPerformance = true;
  2039. b.noPatch = true;
  2040. }
  2041.  
  2042. const isPlainObject = (b, m) => {
  2043. if (!b || typeof b !== 'object') return false;
  2044. const e = Object.getOwnPropertyDescriptors(b);
  2045. if (e.length <= m) return false;
  2046. let pr = 0;
  2047. for (const k in e) {
  2048. const d = e[k];
  2049. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  2050. if (!('value' in d) || typeof d.value === 'function') return false;
  2051. pr++;
  2052. }
  2053. return pr > m;
  2054. }
  2055.  
  2056. let b;
  2057.  
  2058. let lz = 0;
  2059.  
  2060. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  2061. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  2062.  
  2063. // Brave - ShadyDOM exists before userscripting
  2064. b = sdp.value;
  2065.  
  2066. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  2067. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  2068. lz = 1;
  2069. }
  2070.  
  2071. }
  2072.  
  2073.  
  2074. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  2075. } else if (!sdp) {
  2076. } else {
  2077. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  2078. return;
  2079. }
  2080.  
  2081. const shadyDOMNodeWRM = new WeakMap();
  2082.  
  2083. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  2084.  
  2085. const selfWrKey = Symbol();
  2086.  
  2087. const weakWrapperNodeHandlerFn = () => ({
  2088. get() {
  2089. const wv = this[selfWrKey];
  2090. if (typeof wv === 'undefined') return undefined;
  2091. let node = kRef(wv);
  2092. if (!node) this[selfWrKey] = undefined;
  2093. return node || undefined;
  2094. // let w = shadyDOMNodeWRM.get(this);
  2095. // if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
  2096. // return w;
  2097. },
  2098. set(nv) {
  2099. const wv = (nv[selfWrKey] || (nv[selfWrKey] = mWeakRef(nv)));
  2100. this[selfWrKey] = wv;
  2101. return true;
  2102. },
  2103. enumerable: true,
  2104. configurable: true
  2105. });
  2106.  
  2107. /*
  2108. const weakWrapperNodeHandlerFn = () => ({
  2109. get() {
  2110. let w = shadyDOMNodeWRM.get(this);
  2111. if (typeof w === 'object') w = kRef(w) || (shadyDOMNodeWRM.delete(this), undefined);
  2112. return w;
  2113. },
  2114. set(nv) {
  2115. const wv = (nv[selfWrKey] || (nv[selfWrKey] = mWeakRef(nv)));
  2116. shadyDOMNodeWRM.set(this, wv);
  2117. return true;
  2118. },
  2119. enumerable: true,
  2120. configurable: true
  2121. });
  2122. */
  2123.  
  2124. function weakWrapper(_ShadyDOM) {
  2125. const ShadyDOM = _ShadyDOM;
  2126. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  2127. let nullElement = { node: null };
  2128. Object.setPrototypeOf(nullElement, Element.prototype);
  2129. let p = new ShadyDOM.Wrapper(nullElement);
  2130. let d = Object.getOwnPropertyDescriptor(p, 'node');
  2131. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  2132. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  2133. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  2134. }
  2135. // Object.defineProperty(ShadyDOM.Wrapper.prototype, '__cleanup__', function(){
  2136. // // to be reviewed
  2137. // debugger;
  2138.  
  2139.  
  2140.  
  2141.  
  2142. // });
  2143.  
  2144.  
  2145. }
  2146. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  2147. try {
  2148. setupSDomWrapper();
  2149. } catch (e) { }
  2150. }
  2151.  
  2152. }
  2153.  
  2154. let previousWrapStore = null;
  2155.  
  2156. const standardWrap = function (a) {
  2157. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  2158. if (previousWrapStore) {
  2159. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  2160. if (s) {
  2161. previousWrapStore.delete(a);
  2162. shadyDOMNodeWRM.set(a, mWeakRef(s));
  2163. }
  2164. }
  2165. let u = kRef(shadyDOMNodeWRM.get(a));
  2166. if (!u) {
  2167. u = new ShadyDOM.Wrapper(a);
  2168. shadyDOMNodeWRM.set(a, mWeakRef(u));
  2169. }
  2170. return u;
  2171. }
  2172.  
  2173.  
  2174. function setupWrapFunc(_ShadyDOM) {
  2175. const ShadyDOM = _ShadyDOM;
  2176.  
  2177.  
  2178. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  2179. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  2180. return;
  2181. }
  2182. let mm = new Set();
  2183. const pget = wmPD.value;
  2184. WeakMap.prototype.get = function (a) {
  2185. mm.add(this);
  2186. return a;
  2187. }
  2188. try {
  2189. let nullElement = { node: null };
  2190. Object.setPrototypeOf(nullElement, Element.prototype);
  2191. ShadyDOM.wrapIfNeeded(nullElement)
  2192. ShadyDOM.wrap(nullElement)
  2193. } catch (e) { }
  2194. WeakMap.prototype.get = pget;
  2195. if (mm.size !== 1) {
  2196. mm.clear();
  2197. return;
  2198. }
  2199. const p = mm.values().next().value;
  2200. if (!(p instanceof WeakMap)) return;
  2201. // p.clear();
  2202. // p.get = function (a) { return a }
  2203. // p.set = function (a, b) { return this }
  2204. // console.log(188, window.n2n = mm, window.n2p = p)
  2205.  
  2206. // console.log(34929,p.size)
  2207. previousWrapStore = p;
  2208.  
  2209. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  2210. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  2211. }
  2212. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  2213. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  2214. }
  2215.  
  2216. }
  2217.  
  2218. function setupLZ3(nv) {
  2219.  
  2220. const ShadyDOM = nv;
  2221.  
  2222. const ShadyDOMSettings = ShadyDOM.settings;
  2223. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2224. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2225. return false;
  2226. }
  2227.  
  2228. weakWrapper(ShadyDOM);
  2229.  
  2230. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  2231.  
  2232. setupPlainShadyDOM(ShadyDOMSettings);
  2233. setupPlainShadyDOM(ShadyDOM);
  2234.  
  2235. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  2236.  
  2237. setupWrapFunc(ShadyDOM);
  2238. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  2239. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  2240.  
  2241. // To be confirmed
  2242. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  2243. ShadyDOM.composedPath = function (e) {
  2244. const t = (e || 0).target || null;
  2245. if (!(t instanceof HTMLElement)) {
  2246. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  2247. }
  2248. return t instanceof HTMLElement ? [t] : [];
  2249. };
  2250. }
  2251.  
  2252. }
  2253.  
  2254. }
  2255.  
  2256.  
  2257. function setupLZ6(nv) {
  2258.  
  2259. const ShadyDOM = nv;
  2260.  
  2261. const ShadyDOMSettings = ShadyDOM.settings;
  2262.  
  2263. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2264. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2265. return false;
  2266. }
  2267.  
  2268. weakWrapper(ShadyDOM);
  2269.  
  2270. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  2271.  
  2272. setupPlainShadyDOM(ShadyDOMSettings);
  2273. setupPlainShadyDOM(ShadyDOM);
  2274.  
  2275. setupWrapFunc(ShadyDOM);
  2276.  
  2277. }
  2278.  
  2279. }
  2280.  
  2281. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  2282.  
  2283. const nv = b;
  2284.  
  2285. if (setupLZ6(nv) === false) return;
  2286.  
  2287. lz = 6;
  2288.  
  2289. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  2290.  
  2291. return;
  2292. }
  2293.  
  2294. delete window.ShadyDOM;
  2295.  
  2296. Object.defineProperty(window, 'ShadyDOM', {
  2297. get() {
  2298. return b;
  2299. },
  2300. set(nv) {
  2301. let ret = 0;
  2302. try {
  2303. do {
  2304. if (!nv || !nv.settings) {
  2305. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  2306. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  2307. lz = 1;
  2308. break;
  2309. } else {
  2310. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  2311. break;
  2312. }
  2313. }
  2314.  
  2315. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  2316. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  2317. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  2318. break;
  2319. }
  2320.  
  2321. if (setupLZ3(nv) === false) break;
  2322.  
  2323. lz = 3;
  2324.  
  2325. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  2326.  
  2327. ret = 1;
  2328.  
  2329. } while (0);
  2330. } catch (e) {
  2331. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  2332. }
  2333.  
  2334. if (!ret) b = nv;
  2335. else {
  2336. delete this.ShadyDOM;
  2337. this.ShadyDOM = nv;
  2338. }
  2339. return true;
  2340. },
  2341. enumerable: false,
  2342. configurable: true
  2343. });
  2344.  
  2345. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  2346.  
  2347. if (ENABLE_ASYNC_DISPATCHEVENT && nextBrowserTick) {
  2348. const filter = new Set([
  2349. 'yt-action',
  2350. // 'iframe-src-replaced',
  2351. 'shown-items-changed',
  2352. 'can-show-more-changed', 'collapsed-changed',
  2353.  
  2354. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  2355. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  2356. 'yt-navigate-finish',
  2357.  
  2358. // 'data-changed','yt-watch-comments-ready'
  2359. ])
  2360. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  2361. EventTarget.prototype.dispatchEvent = function (event) {
  2362. const type = (event || 0).type;
  2363. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  2364. if (!filter.has(type) && !type.endsWith('-changed')) {
  2365. if (this instanceof Node || this instanceof Window) {
  2366. nextBrowserTick(() => this.dispatchEvent938(event));
  2367. return true;
  2368. }
  2369. }
  2370. }
  2371. return this.dispatchEvent938(event);
  2372. }
  2373. }
  2374.  
  2375. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  2376. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  2377. // const xhr = new XMLHttpRequest;
  2378. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  2379. if (!pdOri || pdOri.configurable !== true) return;
  2380. let propNeedles = null;
  2381. const pdNew = {
  2382. configurable: true,
  2383. enumerable: true,
  2384. get: function () {
  2385. propNeedles = this;
  2386. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  2387. throw new Error();
  2388. }
  2389. }
  2390. Object.defineProperty(Map.prototype, 'size', pdNew);
  2391. try {
  2392. XMLHttpRequest.prototype.open.call(0);
  2393. // xhr.open.call(null)
  2394. } catch (e) { }
  2395. Object.defineProperty(Map.prototype, 'size', pdOri);
  2396. if (!propNeedles) return;
  2397. const entries = [...propNeedles.entries()];
  2398. propNeedles.clear();
  2399. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  2400. })();
  2401.  
  2402. if (FIX_XHR_REQUESTING) {
  2403.  
  2404. const URL = window.URL || new Function('return URL')();
  2405. const createObjectURL = URL.createObjectURL.bind(URL);
  2406.  
  2407. XMLHttpRequest = (() => {
  2408. const XMLHttpRequest_ = XMLHttpRequest;
  2409. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  2410. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  2411. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  2412. constructor(...args) {
  2413. super(...args);
  2414. }
  2415. open(method, url, ...args) {
  2416. let skip = false;
  2417. if (!url || typeof url !== 'string') skip = true;
  2418. else if (typeof url === 'string') {
  2419. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  2420. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  2421. skip = true;
  2422. } else if (turl.includes('.youtube.com/pagead/')) {
  2423. skip = true;
  2424. } else if (turl.includes('.youtube.com/ptracking')) {
  2425. skip = true;
  2426. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  2427. skip = true;
  2428. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  2429. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  2430. skip = true;
  2431. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  2432. skip = true;
  2433. } else {
  2434. // skip = true; // for user activity logging e.g. watched videos
  2435. }
  2436. } else if (turl.includes('play.google.com/log')) {
  2437. skip = true;
  2438. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  2439. skip = true;
  2440. }
  2441. }
  2442. if (!skip) {
  2443. this.__xmMc8__ = 1;
  2444. return super.open(method, url, ...args);
  2445. } else {
  2446. this.__xmMc8__ = 2;
  2447. return super.open('GET', url0);
  2448. }
  2449. }
  2450. send(...args) {
  2451. if (this.__xmMc8__ === 1) {
  2452. return super.send(...args);
  2453. } else if (this.__xmMc8__ === 2) {
  2454. return super.send();
  2455. } else {
  2456. console.log('[yt-js-engine-tamer]', 'xhr warning');
  2457. return super.send(...args);
  2458. }
  2459. }
  2460. }
  2461. c.prototype.__xmMc8__ = 0;
  2462. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  2463. return c;
  2464. })();
  2465. }
  2466.  
  2467. // Alternative HACK -> Tabview Youtube
  2468. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  2469.  
  2470. // ---- << this.overscrollConfig HACK >> -----
  2471.  
  2472. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  2473.  
  2474. /*
  2475.  
  2476. ;function gZb(a, b) {
  2477. b = void 0 === b ? !0 : b;
  2478. a.addEventListener("wheel", hZb);
  2479. a.overscrollConfig = {
  2480. cooldown: b
  2481. }
  2482. }
  2483. function iZb(a) {
  2484. a.overscrollConfig = void 0;
  2485. a.removeEventListener("wheel", hZb)
  2486. }
  2487. function hZb(a) {
  2488. var b = a.deltaY
  2489. , c = a.target
  2490. , d = null;
  2491. if (window.Polymer && window.Polymer.Element) {
  2492. if (c = a.path || a.composedPath && a.composedPath()) {
  2493. c = g(c);
  2494. for (var e = c.next(); !e.done && (e = e.value,
  2495. !jZb(e, b)); e = c.next())
  2496. if (e.overscrollConfig) {
  2497. d = e;
  2498. break
  2499. }
  2500. }
  2501. } else
  2502. for (; c && !jZb(c, b); ) {
  2503. if (c.overscrollConfig) {
  2504. d = c;
  2505. break
  2506. }
  2507. c = c.parentElement
  2508. }
  2509. d && (b = d.overscrollConfig,
  2510. b.cooldown ? (d = a.deltaY,
  2511. c = b.lastDeltaY || 0,
  2512. b.lastDeltaY = d,
  2513. e = b.lastStopped || 0,
  2514. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  2515. c = !1) : (d = e + 600,
  2516. c = !0) : (d = Date.now() + 600,
  2517. c = !0),
  2518. d > Date.now() && (a.preventDefault(),
  2519. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  2520. }
  2521. */
  2522.  
  2523. let wheelHandler = function (a) {
  2524. if (window.Polymer && window.Polymer.Element) {
  2525. let c;
  2526. if (c = a.path || a.composedPath && a.composedPath()) {
  2527. for (const e of c) {
  2528. const cnt = insp(e);
  2529. if (e.overscrollConfig) e.overscrollConfig = void 0;
  2530. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  2531. }
  2532. }
  2533. } else {
  2534. let e = a.target;
  2535. for (; e instanceof Element; e = e.parentElement) {
  2536. const cnt = insp(e);
  2537. if (e.overscrollConfig) e.overscrollConfig = void 0;
  2538. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  2539. }
  2540. }
  2541. };
  2542.  
  2543. let checkWheelListenerObjs = null;
  2544.  
  2545. let getObjsFn = () => {
  2546. let euyVal = 0;
  2547. const eukElm = {};
  2548. Object.setPrototypeOf(eukElm, HTMLElement.prototype);
  2549. const euzObj = new Proxy(eukElm, {
  2550. get(target, prop) {
  2551. throw `ErrorF31.get(${prop})`
  2552. },
  2553. set(target, prop, value) {
  2554. throw `ErrorF33.set(${prop}, ${value})`
  2555. }
  2556. });
  2557. const euxElm = new Proxy(eukElm, {
  2558. get(target, prop) {
  2559. if (prop === 'scrollTop') {
  2560. euyVal = euyVal | 8;
  2561. return 0;
  2562. }
  2563. if (prop === 'overscrollConfig') {
  2564. euyVal = euyVal | 16;
  2565. return void 0;
  2566. }
  2567. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  2568. return 640;
  2569. }
  2570. if (prop === 'scrollLeft') {
  2571. euyVal = euyVal | 8;
  2572. return 0;
  2573. }
  2574. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  2575. return 800;
  2576. }
  2577. throw `ErrorF45.get(${prop})`
  2578. },
  2579. set(target, prop, value) {
  2580. throw `ErrorF47.set(${prop}, ${value})`
  2581. }
  2582. });
  2583. const eukEvt = {};
  2584. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  2585. const euyEvt = new Proxy(eukEvt, {
  2586. get(target, prop) {
  2587. if (prop === 'deltaY' || prop === 'deltaX') {
  2588. euyVal = euyVal | 1;
  2589. return -999;
  2590. }
  2591. if (prop === 'target') {
  2592. euyVal = euyVal | 2;
  2593. return euxElm
  2594. }
  2595. if (prop === 'path' || prop === 'composedPath') {
  2596. euyVal = euyVal | 2;
  2597. return [euxElm]
  2598. }
  2599. throw `ErrorF51.get(${prop})`
  2600. },
  2601. set(target, prop, value) {
  2602. throw `ErrorF53.set(${prop}, ${value})`
  2603. }
  2604. });
  2605. const setVal = (v) => {
  2606. euyVal = v;
  2607. }
  2608. const getVal = () => {
  2609. return euyVal;
  2610. }
  2611. return { euzObj, euyEvt, setVal, getVal };
  2612. }
  2613.  
  2614. let checkWheelListener = (callback) => {
  2615.  
  2616. let callbackIdentifier = '';
  2617.  
  2618. let res = null;
  2619. try {
  2620. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  2621. setVal(0);
  2622. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  2623. throw `RESULT${getVal()}`;
  2624. } catch (e) {
  2625. res = e;
  2626. }
  2627.  
  2628. res = `${res}` || `${null}`;
  2629. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  2630.  
  2631. callbackIdentifier = res;
  2632. if (callbackIdentifier === 'RESULT27') 0;
  2633. else if (callbackIdentifier === 'RESULT0') {
  2634. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  2635. } else if (callbackIdentifier.startsWith('RESULT')) {
  2636. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  2637. }
  2638. return callbackIdentifier;
  2639.  
  2640. };
  2641.  
  2642. let callbackFound = false;
  2643. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  2644. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  2645. // M-youtube-js-engine-tamer.52178
  2646. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  2647. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  2648. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  2649. // RESULTXX / ErrorFXX / Other...
  2650. if (callbackIdentifier === 'RESULT27') {
  2651. this.overscrollConfigDisable = true;
  2652. if (!callbackFound) {
  2653. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  2654. getObjsFn = checkWheelListener = null;
  2655. checkWheelListenerObjs = null;
  2656. wheelHandler = null;
  2657. }
  2658. return void 0;
  2659. } else if (!callbackFound && !this.overscrollConfigDisable) {
  2660. this.overscrollConfigDisable = true;
  2661. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  2662. }
  2663. }
  2664. return this.addEventListener52178(type, callback, option);
  2665. };
  2666.  
  2667. // ---- << this.overscrollConfig HACK >> -----
  2668.  
  2669. }
  2670.  
  2671. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  2672.  
  2673. let p_a_objWR = null;
  2674. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  2675. let ytPageReady = 0;
  2676.  
  2677. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  2678. let isGlobalSpaceControl = true;
  2679. let mediaPlayerElementWR = null;
  2680. let focusedElementAtSelection = null;
  2681.  
  2682. // let want_control_video = false;
  2683.  
  2684. let spaceBarControl_keyG = '';
  2685.  
  2686. let lastUserAction = 0;
  2687.  
  2688. const wmKeyControlPhase = new WeakMap();
  2689.  
  2690. let currentSelectionText = null;
  2691.  
  2692. const getCurrentSelectionText = () => {
  2693. if (currentSelectionText !== null) return currentSelectionText
  2694. return (currentSelectionText = `${getSelection()}`)
  2695. }
  2696.  
  2697. const pageMediaWatcher = () => {
  2698.  
  2699. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  2700. // want_control_video = false;
  2701. // }, { capture: true, passive: true });
  2702.  
  2703. document.addEventListener('yt-navigate', () => {
  2704. ytPageReady = 0;
  2705. });
  2706. document.addEventListener('yt-navigate-start', () => {
  2707. ytPageReady = 0;
  2708. });
  2709. document.addEventListener('yt-navigate-cache', () => {
  2710. ytPageReady = 0;
  2711. });
  2712.  
  2713. document.addEventListener('yt-navigate-finish', () => {
  2714. ytPageReady = 1;
  2715. });
  2716.  
  2717. document.addEventListener('durationchange', () => {
  2718. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  2719. if (elm.duration > 0.01) {
  2720. if (elm.closest('[hidden]')) continue;
  2721. mediaPlayerElementWR = mWeakRef(elm);
  2722. return;
  2723. }
  2724. }
  2725. }, { capture: true, passive: true });
  2726.  
  2727. document.addEventListener('selectionchange', (evt) => {
  2728. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  2729. currentSelectionText = null;
  2730. if (!(evt.target instanceof Node)) return;
  2731. focusedElementAtSelection = evt.target;
  2732. }, { capture: true, passive: true })
  2733.  
  2734. document.addEventListener('pointerdown', (evt) => {
  2735. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2736. }, { capture: true, passive: true });
  2737.  
  2738.  
  2739. document.addEventListener('pointerup', (evt) => {
  2740. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2741. }, { capture: true, passive: true });
  2742.  
  2743.  
  2744. document.addEventListener('keydown', (evt) => {
  2745. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2746. }, { capture: true, passive: true });
  2747.  
  2748. document.addEventListener('keyup', (evt) => {
  2749. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  2750. }, { capture: true, passive: true });
  2751.  
  2752. };
  2753.  
  2754.  
  2755. const checkKeyB = (p_a_obj) => {
  2756.  
  2757. const boolList = new Set();
  2758. const p_a_obj_api = p_a_obj.api;
  2759.  
  2760. const nilFunc0 = function () {
  2761. return void 0
  2762. };
  2763. const mt = new Proxy({}, {
  2764. get(target, prop) {
  2765. if (prop === 'get') return nilFunc0;
  2766. return mt;
  2767. }
  2768. });
  2769. const nilFunc = function () {
  2770. return mt
  2771. };
  2772. const mw = new Proxy({}, {
  2773. get(target, prop) {
  2774. if (prop in p_a_obj_api) {
  2775. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  2776. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  2777. if (q && q.value) {
  2778. if (!q.writable) return q.value;
  2779. if (typeof q.value === 'string') return '';
  2780. if (typeof q.value === 'number') return 0;
  2781. if (typeof q.value === 'boolean') return false;
  2782. if (q.value && typeof q.value === 'object') return {};
  2783. }
  2784. }
  2785. return undefined;
  2786. },
  2787. set(target, prop) {
  2788. throw 'mwSet';
  2789. }
  2790. });
  2791.  
  2792. const mq = new Proxy({}, {
  2793. get(target, prop) {
  2794. if (prop === 'api') return mw;
  2795. if (prop in p_a_obj) {
  2796. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  2797. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  2798. if (q && q.value) {
  2799. if (!q.writable) return q.value;
  2800. if (typeof q.value === 'string') return '';
  2801. if (typeof q.value === 'number') return 0;
  2802. if (typeof q.value === 'boolean') return false;
  2803. if (q.value && typeof q.value === 'object') return {};
  2804. }
  2805. }
  2806. return undefined;
  2807. },
  2808. set(target, prop, val) {
  2809. if (typeof val === 'boolean') boolList.add(prop)
  2810. throw `mqSet(${prop},${val})`;
  2811. }
  2812. });
  2813.  
  2814. let res = ''
  2815. try {
  2816. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  2817. } catch (e) {
  2818. res = `ERROR::${e}`;
  2819. }
  2820.  
  2821. if (boolList.size === 1) {
  2822. const value = boolList.values().next().value;
  2823. if (res === `ERROR::mqSet(${value},${true})`) {
  2824. p_a_obj.__uZWaD__ = value;
  2825. }
  2826. }
  2827.  
  2828. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  2829.  
  2830. }
  2831.  
  2832.  
  2833. let pm_p_a = null;
  2834.  
  2835. const p_a_init = function () {
  2836. const r = this.init91();
  2837. const keyBw = this.__cPzfo__ || '__NIL__';
  2838. const p_a_obj = this[keyBw];
  2839. if (!p_a_obj) return;
  2840. try {
  2841. checkKeyB(p_a_obj);
  2842. } catch (e) { }
  2843. p_a_objWR = mWeakRef(p_a_obj);
  2844. if (FIX_SHORTCUTKEYS > 0) {
  2845. if (p_a_obj && !p_a_obj.hVhtg) {
  2846. p_a_obj.hVhtg = 1;
  2847.  
  2848. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  2849. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  2850. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  2851. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  2852. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  2853. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  2854.  
  2855. }
  2856. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  2857. // const api = p_a_obj.api
  2858. // api.hVhtg = 1;
  2859. // api.playVideo91 = api.playVideo;
  2860. // api.playVideo = p_a_jt.playVideo;
  2861. // api.pauseVideo91 = api.pauseVideo;
  2862. // api.pauseVideo = p_a_jt.pauseVideo;
  2863. // }
  2864. }
  2865. if (pm_p_a) {
  2866. pm_p_a.resolve();
  2867. pm_p_a = null;
  2868. }
  2869. return r;
  2870. };
  2871.  
  2872. const p_a_xt = {
  2873.  
  2874. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  2875.  
  2876. if (FIX_SHORTCUTKEYS === 2) {
  2877.  
  2878. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  2879.  
  2880. if (activeElement) {
  2881.  
  2882. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  2883.  
  2884. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  2885. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  2886. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  2887.  
  2888. }
  2889.  
  2890. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  2891. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  2892. // console.log(582, isDelayedSpaceBar)
  2893. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  2894.  
  2895. if (activeElement && (h === 'Space' || h === 'Enter')) {
  2896. const controlPhase = wmKeyControlPhase.get(activeElement);
  2897. if (controlPhase === 4 || controlPhase === 5) return false;
  2898. }
  2899. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  2900. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  2901. // if (!isSpaceKeyImmediate) return false;
  2902. // }
  2903. }
  2904.  
  2905. },
  2906.  
  2907. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  2908.  
  2909. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  2910.  
  2911. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  2912. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  2913. // console.log(583, isDelayedSpaceBar)
  2914. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  2915.  
  2916. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  2917.  
  2918. let mediaWorking = false;
  2919. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  2920. mediaWorking = true;
  2921. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  2922. mediaWorking = true;
  2923. }
  2924. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  2925. mediaWorking && Promise.resolve().then(() => {
  2926. if (activeElement === document.activeElement) {
  2927. return activeElement.blur()
  2928. } else {
  2929. return false
  2930. }
  2931. }).then((r) => {
  2932. r !== false && mediaPlayerElement.focus();
  2933. });
  2934. }
  2935. },
  2936.  
  2937.  
  2938. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  2939.  
  2940. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  2941.  
  2942. const activeElement = document.activeElement;
  2943.  
  2944. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  2945. if (allow === false) return false;
  2946.  
  2947. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  2948. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  2949.  
  2950. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  2951.  
  2952. return ret;
  2953. },
  2954. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  2955.  
  2956.  
  2957. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  2958.  
  2959. const activeElement = document.activeElement;
  2960. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  2961. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  2962. // }
  2963. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  2964. if (allow === false) return false;
  2965.  
  2966. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  2967. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  2968.  
  2969. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  2970.  
  2971. return ret;
  2972. }
  2973.  
  2974. };
  2975.  
  2976. // const p_a_jt = { // API
  2977.  
  2978. // playVideo(a) { // without spinner effect
  2979.  
  2980. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  2981.  
  2982. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  2983. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  2984. // want_control_video = true;
  2985. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  2986. // }
  2987.  
  2988. // }
  2989. // return this.playVideo91(a);
  2990.  
  2991. // },
  2992.  
  2993. // pauseVideo(a) { // without spinner effect
  2994.  
  2995. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  2996.  
  2997. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  2998. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  2999. // want_control_video = true;
  3000. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3001. // }
  3002.  
  3003. // }
  3004. // return this.pauseVideo91(a);
  3005.  
  3006. // }
  3007. // };
  3008.  
  3009. let flagSpeedMaster = null;
  3010. const getSpeedMasterControlFlag = () => {
  3011.  
  3012. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3013. isSpeedMastSpacebarControlEnabled = false;
  3014. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  3015. isSpeedMastSpacebarControlEnabled = true;
  3016. }
  3017. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  3018. isSpeedMastSpacebarControlEnabled = true;
  3019. }
  3020.  
  3021. if (flagSpeedMaster === null) {
  3022. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  3023. if (!p) {
  3024. flagSpeedMaster = false;
  3025. } else {
  3026.  
  3027. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  3028.  
  3029. }
  3030.  
  3031. }
  3032. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  3033.  
  3034. return isSpeedMastSpacebarControlEnabled;
  3035. }
  3036.  
  3037.  
  3038. const getGlobalSpacebarControlFlag = () => {
  3039.  
  3040. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3041. isGlobalSpaceControl = false;
  3042. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  3043. isGlobalSpaceControl = true;
  3044. }
  3045. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  3046. isGlobalSpaceControl = true;
  3047. }
  3048.  
  3049. return isGlobalSpaceControl;
  3050. }
  3051.  
  3052. const keyboardController = async (_yt_player) => {
  3053.  
  3054. const keyQT = getQT(_yt_player);
  3055. const keySV = getSV(_yt_player);
  3056. const keyDX = getDX(_yt_player);
  3057. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  3058.  
  3059. if (!keyDX) return;
  3060. if (keyDX === keyQT || keyDX === keySV) return;
  3061.  
  3062. if (typeof keyDX !== 'string') return;
  3063.  
  3064. let lastAccessKey = '';
  3065. let lastAccessKeyConfirmed = '';
  3066. const mb = new Proxy({}, {
  3067. get(target, prop) {
  3068. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  3069. throw 'mbGet'
  3070. },
  3071. set(target, prop, val) {
  3072. throw 'mbSet'
  3073. }
  3074. });
  3075. const ma = new Proxy({}, {
  3076. get(target, prop) {
  3077. lastAccessKey = prop;
  3078. return mb
  3079. },
  3080. set(target, prop, val) {
  3081. throw 'maSet'
  3082. }
  3083. });
  3084.  
  3085. let keyBw = '';
  3086. try {
  3087. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  3088. } catch (e) {
  3089. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  3090. keyBw = lastAccessKeyConfirmed;
  3091. }
  3092. }
  3093.  
  3094. if (!keyBw) return;
  3095.  
  3096. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  3097.  
  3098. pm_p_a = new PromiseExternal();
  3099.  
  3100. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  3101.  
  3102. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  3103.  
  3104. _yt_player[keyDX].prototype.init = p_a_init;
  3105.  
  3106. await pm_p_a.then();
  3107. const p_a_obj = kRef(p_a_objWR);
  3108.  
  3109. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  3110.  
  3111.  
  3112. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  3113.  
  3114. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  3115.  
  3116. if (!isSpeedMastSpacebarControlEnabled) {
  3117.  
  3118. if (config && config.EXPERIMENT_FLAGS) {
  3119. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  3120. }
  3121. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3122. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  3123. }
  3124.  
  3125. } else {
  3126.  
  3127. if (config && config.EXPERIMENT_FLAGS) {
  3128. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  3129. }
  3130. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3131. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  3132. }
  3133.  
  3134. }
  3135.  
  3136. }
  3137.  
  3138. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  3139.  
  3140.  
  3141.  
  3142.  
  3143. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  3144.  
  3145. // console.log(p_a_obj.handleGlobalKeyUp)
  3146. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  3147.  
  3148. // console.log(p_a_obj.api)
  3149.  
  3150.  
  3151. // QT -> DX(SV) -> p_a
  3152.  
  3153.  
  3154. /*
  3155. *
  3156. *
  3157. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3158. b = void 0 === b ? !1 : b;
  3159. c = void 0 === c ? !1 : c;
  3160. d = void 0 === d ? !1 : d;
  3161. e = void 0 === e ? !1 : e;
  3162. var l = g.PT(this);
  3163. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  3164. }
  3165.  
  3166. */
  3167.  
  3168. /*
  3169. *
  3170. *
  3171. *
  3172. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3173. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  3174. }
  3175.  
  3176. */
  3177.  
  3178.  
  3179. // if(!keyDX) return;
  3180.  
  3181. // console.log(4999, keyDX)
  3182.  
  3183. };
  3184.  
  3185.  
  3186. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  3187.  
  3188. const p_a_obj = kRef(p_a_objWR);
  3189. // const api = p_a_obj.api;
  3190.  
  3191.  
  3192. // console.log(540);
  3193.  
  3194. let boolList = null;
  3195. let ret;
  3196. isSpaceKeyImmediate = true;
  3197. try {
  3198.  
  3199. ret = 0;
  3200. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  3201. let p_a_objT;
  3202. if (!spaceBarControl_keyG) { // just in case
  3203. boolList = new Set();
  3204. p_a_objT = new Proxy(p_a_obj, {
  3205. get(target, prop, handler) {
  3206. const val = target[prop];
  3207. if (typeof val !== 'boolean') return val;
  3208. boolList.add(prop);
  3209. // console.log(555, prop, val);
  3210. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  3211. spaceBarControl_keyG = prop;
  3212. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3213. val = false;
  3214. }
  3215. return val;
  3216. }
  3217. });
  3218.  
  3219.  
  3220. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  3221. p_a_obj[spaceBarControl_keyG] = false;
  3222. p_a_objT = p_a_obj;
  3223. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  3224. } else {
  3225.  
  3226. p_a_objT = p_a_obj;
  3227. }
  3228.  
  3229. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  3230.  
  3231.  
  3232. } catch (e) {
  3233. console.log(e)
  3234. }
  3235. isSpaceKeyImmediate = false;
  3236.  
  3237. if (boolList && boolList.size === 1) {
  3238. const value = boolList.values().next().value;
  3239. spaceBarControl_keyG = value;
  3240. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3241.  
  3242. }
  3243.  
  3244. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3245.  
  3246. return ret;
  3247. }
  3248.  
  3249. const shortcutKeysFixer = () => {
  3250.  
  3251. let pausePromiseControlJ = 0;
  3252.  
  3253.  
  3254. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  3255.  
  3256. let controlPhase = 0;
  3257. const aElm = document.activeElement;
  3258.  
  3259. if (aElm) {
  3260.  
  3261. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  3262.  
  3263. if (typeof controlPhaseCache === 'number') {
  3264.  
  3265. controlPhase = controlPhaseCache;
  3266. } else {
  3267.  
  3268. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  3269. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  3270. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  3271. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  3272. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  3273. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  3274. else {
  3275. if (aElm instanceof HTMLElement && aElm.closest('[role]')) controlPhase = 5;
  3276. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  3277. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  3278. else if (!(aElm instanceof HTMLElement) && (aElm instanceof Element)) controlPhase = 2; // svg
  3279. }
  3280.  
  3281. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement) && aElm.contains(mediaPlayerElement)) {
  3282. controlPhase = 0;
  3283. }
  3284.  
  3285. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  3286. if (aElm.closest('[contenteditable], input, textarea')) {
  3287. controlPhase = 5;
  3288. } else if (aElm.closest('button')) {
  3289. controlPhase = 4;
  3290. }
  3291. }
  3292.  
  3293. if (aElm.closest('#movie_player')) controlPhase = 6;
  3294.  
  3295. wmKeyControlPhase.set(aElm, controlPhase);
  3296.  
  3297. }
  3298. }
  3299.  
  3300. return controlPhase;
  3301.  
  3302. }
  3303.  
  3304. const isStateControllable = (api) => {
  3305. let appState = null;
  3306. let playerState = null;
  3307. let adState = null;
  3308. try {
  3309. appState = api.getAppState();
  3310. playerState = api.getPlayerState();
  3311. adState = api.getAdState();
  3312. } catch (e) { }
  3313. // ignore playerState -1
  3314. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  3315. };
  3316.  
  3317.  
  3318. const keyEventListener = (evt) => {
  3319. if (BY_PASS_KEYBOARD_CONTROL) return;
  3320.  
  3321. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3322. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  3323. if (!ytPageReady) return;
  3324.  
  3325. if (evt.defaultPrevented === true) return;
  3326.  
  3327. const p_a_obj = kRef(p_a_objWR);
  3328.  
  3329. if (!p_a_obj) return;
  3330.  
  3331.  
  3332. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3333. if (!mediaPlayerElement) return;
  3334.  
  3335. // let focusBodyIfSuccess = false;
  3336.  
  3337. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  3338.  
  3339. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  3340. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  3341. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  3342.  
  3343.  
  3344. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  3345.  
  3346. // console.log(`${evt.type}::controlPhase`,controlPhase)
  3347.  
  3348. // if (controlPhase == 4) {
  3349. // focusBodyIfSuccess = true;
  3350. // }
  3351.  
  3352. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  3353. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3354.  
  3355. if (FIX_SHORTCUTKEYS < 2) return;
  3356. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  3357.  
  3358. let rr;
  3359. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  3360.  
  3361.  
  3362.  
  3363. let useImprovedPauseResume = false;
  3364.  
  3365. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3366.  
  3367. const api = p_a_obj.api;
  3368. const stateControllable = isStateControllable(api);
  3369. // console.log(2122, appState, playerState, adState)
  3370.  
  3371. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  3372.  
  3373. useImprovedPauseResume = true;
  3374.  
  3375. }
  3376.  
  3377.  
  3378. }
  3379.  
  3380.  
  3381. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  3382. if (evt.type === 'keydown') {
  3383.  
  3384. if (useImprovedPauseResume) {
  3385.  
  3386. const isPaused = mediaPlayerElement.paused;
  3387.  
  3388. const cj = ++pausePromiseControlJ;
  3389. Promise.resolve().then(() => {
  3390.  
  3391. if (cj !== pausePromiseControlJ) return;
  3392.  
  3393. if (mediaPlayerElement.paused !== isPaused) return;
  3394.  
  3395. const ret = ytResumeFn();
  3396. if (!ret) { // fallback
  3397. isPaused ? api.playVideo() : api.pauseVideo();
  3398. }
  3399.  
  3400. /*
  3401. let a = void 0;
  3402. console.log('Rb', api.Rb())
  3403. a = !window._yt_player.nL(api.Rb());
  3404. p_a_obj.Wd.kG(a)
  3405. a ? api.playVideo() : api.pauseVideo();
  3406.  
  3407. */
  3408.  
  3409.  
  3410. });
  3411. rr = true;
  3412. } else {
  3413.  
  3414. isSpaceKeyImmediate = true;
  3415. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  3416. isSpaceKeyImmediate = false;
  3417. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3418.  
  3419. }
  3420.  
  3421.  
  3422. } else if (evt.type === 'keyup') {
  3423.  
  3424. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3425.  
  3426. rr = true;
  3427. } else {
  3428.  
  3429. isSpaceKeyImmediate = true;
  3430. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  3431. isSpaceKeyImmediate = false;
  3432. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  3433.  
  3434. }
  3435.  
  3436.  
  3437. /*
  3438.  
  3439. if (d)
  3440. switch (c) {
  3441. case 32:
  3442. case 13:
  3443. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  3444. b = !0,
  3445. e = !1;
  3446. else if (e) {
  3447. var m = d.getAttribute("role");
  3448. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  3449. d.click(),
  3450. f = !0)
  3451. }
  3452. break;
  3453. case 37:
  3454. case 39:
  3455. case 36:
  3456. case 35:
  3457. b = "slider" === d.getAttribute("role");
  3458. break;
  3459. case 38:
  3460. case 40:
  3461. m = d.getAttribute("role"),
  3462. d = 38 === c ? d.previousSibling : d.nextSibling,
  3463. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  3464. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  3465. f = b = !0))
  3466. }
  3467. if (e && !f)
  3468. switch (c) {
  3469. case 38:
  3470. f = Math.min(this.api.getVolume() + 5, 100);
  3471. XV(this.Wd, f, !1);
  3472. this.api.setVolume(f);
  3473. h = f = !0;
  3474. break;
  3475. case 40:
  3476. f = Math.max(this.api.getVolume() - 5, 0);
  3477. XV(this.Wd, f, !0);
  3478. this.api.setVolume(f);
  3479. h = f = !0;
  3480. break;
  3481. case 36:
  3482. this.api.Yh() && (this.api.startSeekCsiAction(),
  3483. this.api.seekTo(0, void 0, void 0, void 0, 79),
  3484. h = f = !0);
  3485. break;
  3486. case 35:
  3487. this.api.Yh() && (this.api.startSeekCsiAction(),
  3488. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  3489. h = f = !0)
  3490. }
  3491. */
  3492.  
  3493. }
  3494.  
  3495.  
  3496. if (rr) {
  3497.  
  3498. // focusBodyIfSuccess && Promise.resolve().then(() => {
  3499. // activeElement === document.activeElement && activeElement.blur();
  3500. // });
  3501.  
  3502. evt.preventDefault();
  3503. evt.stopImmediatePropagation();
  3504. evt.stopPropagation();
  3505.  
  3506. }
  3507.  
  3508. };
  3509.  
  3510. document.addEventListener('keydown', keyEventListener, { capture: true });
  3511.  
  3512.  
  3513. document.addEventListener('keyup', keyEventListener, { capture: true });
  3514.  
  3515. }
  3516.  
  3517. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  3518.  
  3519. })();
  3520.  
  3521.  
  3522. pageMediaWatcher();
  3523. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  3524.  
  3525.  
  3526. const check_for_set_key_order = (() => {
  3527.  
  3528. let mySet = new Set();
  3529.  
  3530. mySet.add("value1");
  3531. mySet.add("value2");
  3532. mySet.add("value3");
  3533.  
  3534. // Function to convert Set values to an array
  3535. function getSetValues(set) {
  3536. return Array.from(set.values());
  3537. }
  3538.  
  3539. // Function to test if the Set maintains insertion order
  3540. function testSetOrder(set, expectedOrder) {
  3541. let values = getSetValues(set);
  3542. return expectedOrder.join(',') === values.join(',');
  3543. }
  3544.  
  3545. // Test 1: Initial order
  3546. if (mySet.values().next().value !== "value1") return false;
  3547. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  3548.  
  3549. // Test 2: After deleting an element
  3550. mySet.delete("value2");
  3551. if (mySet.values().next().value !== "value1") return false;
  3552. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  3553.  
  3554. // Test 3: After re-adding a deleted element
  3555. mySet.add("value2");
  3556. if (mySet.values().next().value !== "value1") return false;
  3557. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  3558.  
  3559. // Test 4: After adding a new element
  3560. mySet.add("value4");
  3561. if (mySet.values().next().value !== "value1") return false;
  3562. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  3563.  
  3564. // Test 5: Delete+Add
  3565. mySet.delete("value1");
  3566. mySet.delete("value3");
  3567. mySet.add("value3");
  3568. mySet.add("value1");
  3569. if (mySet.values().next().value !== "value2") return false;
  3570. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  3571.  
  3572. return true;
  3573. })();
  3574.  
  3575.  
  3576. // const qm47 = Symbol();
  3577. const qm57 = Symbol();
  3578. const qm53 = Symbol();
  3579. const qn53 = Symbol();
  3580.  
  3581.  
  3582. const ump3 = new WeakMap();
  3583.  
  3584. const stp = document.createElement('noscript');
  3585. stp.id = 'weakref-placeholder';
  3586.  
  3587. PROP_OverReInclusion_AVOID && (() => {
  3588.  
  3589.  
  3590. if (typeof HTMLElement.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement.prototype.hasOwnProperty !== 'function') return;
  3591. const f = HTMLElement.prototype.hasOwnProperty72 = HTMLElement.prototype.hasOwnProperty;
  3592. let byPassVal = null;
  3593. let byPassCount = 0;
  3594. let mmw = new Set();
  3595. HTMLElement.prototype.hasOwnProperty = function (prop) {
  3596. if (arguments.length !== 1) return f.apply(this, arguments);
  3597. if (byPassVal !== null && typeof prop === 'string') {
  3598.  
  3599. if (PROP_OverReInclusion_LIST.has(prop)) {
  3600. byPassCount++;
  3601. return byPassVal;
  3602. }
  3603. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  3604.  
  3605. }
  3606. return this.hasOwnProperty72(prop);
  3607. };
  3608.  
  3609.  
  3610. /*
  3611.  
  3612.  
  3613. z.prototype.forwardDynamicProps = function() {
  3614. var B = m(this.inst);
  3615. B = h(B);
  3616. for (var F = B.next(); !F.done; F = B.next()) {
  3617. var H = h(F.value);
  3618. F = H.next().value;
  3619. H = H.next().value;
  3620. my(this, F, H);
  3621. r(b) && !ly(F) && Wua(this.inst, F)
  3622. }
  3623. }
  3624.  
  3625. */
  3626.  
  3627.  
  3628.  
  3629. let byPassZeroShowed = false;
  3630. const forwardDynamicPropsGeneral = function () {
  3631. byPassVal = true;
  3632. byPassCount = 0;
  3633. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  3634. const ret = this.forwardDynamicProps72();
  3635. byPassVal = null;
  3636. if (byPassCount === 0 && !byPassZeroShowed) {
  3637. byPassZeroShowed = true;
  3638. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  3639. }
  3640. byPassCount = 0;
  3641. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  3642. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  3643. mmw.clear();
  3644. }
  3645. return ret;
  3646. };
  3647.  
  3648. const propCheck = (proto) => {
  3649. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  3650. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  3651. if (proto.forwardDynamicProps.length === 0) {
  3652. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  3653. }
  3654. }
  3655. };
  3656.  
  3657. const valMap = new WeakMap();
  3658. Object.defineProperty(HTMLElement.prototype, 'didForwardDynamicProps', {
  3659. get() {
  3660. propCheck(this.constructor.prototype);
  3661. return valMap.get(this);
  3662. },
  3663. set(nv) {
  3664. propCheck(this.constructor.prototype);
  3665. valMap.set(this, nv);
  3666. return true;
  3667. },
  3668. enumerable: false,
  3669. configurable: true
  3670.  
  3671. });
  3672.  
  3673. promiseForCustomYtElementsReady.then(() => {
  3674. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  3675. if (customElements.define.length !== 2) return;
  3676. customElements.define72 = customElements.define;
  3677. customElements.define = function (b, w) {
  3678. propCheck(w.prototype);
  3679. const ret = this.define72(b, w);
  3680. return ret;
  3681. }
  3682. });
  3683.  
  3684. })();
  3685.  
  3686.  
  3687. let marcoPr = new PromiseExternal();
  3688. const trackMarcoCm = document.createComment('1');
  3689. const trackMarcoCmObs = new MutationObserver(()=>{
  3690. marcoPr.resolve();
  3691. marcoPr = new PromiseExternal();
  3692. });
  3693. trackMarcoCmObs.observe(trackMarcoCm, {characterData: true});
  3694.  
  3695.  
  3696. // ----------------------------
  3697.  
  3698.  
  3699.  
  3700. // const rendererStamperCreationFactory = (cProto, options) => {
  3701.  
  3702. // const { key, stamperDomClass, preloadFn } = options;
  3703.  
  3704. // // const newDoc = document.implementation.createHTMLDocument("NewDoc");
  3705. // const pSpace = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3706. // document.documentElement.insertAdjacentElement('beforeend', pSpace);
  3707. // const pNode = document.createElement('ns-538');
  3708. // pSpace.insertAdjacentElement('beforeend', pNode);
  3709.  
  3710. // const pDiv = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3711. // if (typeof pNode.attachShadow === 'function') {
  3712. // const pShadow = pNode.attachShadow({ mode: "open" });
  3713. // pShadow.replaceChildren(pDiv);
  3714. // } else {
  3715. // pNode.insertAdjacentElement('beforeend', pDiv);
  3716. // }
  3717.  
  3718. // const pDivNew = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3719. // pDiv.insertAdjacentElement('beforeend', pDivNew);
  3720.  
  3721. // const wmRemoved = new Map();
  3722.  
  3723. // // const wmMapToItem = new WeakMap();
  3724. // // let wmPendingList = null;
  3725.  
  3726. // const nullComponents = new Map();
  3727.  
  3728. // const componentDefaultAttributes = new WeakMap();
  3729.  
  3730. // const fnKeyH = `${key}$$c472`;
  3731.  
  3732. // cProto[fnKeyH] = async function (cTag, cId, pr00) {
  3733. // // await the current executing task (if any)
  3734. // // and avoid stacking in the same marco task
  3735. // await Promise.all([pr00, nextBrowserTick_()]);
  3736. // if (!this.ec389a && !this.ec389r) return;
  3737. // const addedCount0 = this.ec389a;
  3738. // const removedCount0 = this.ec389r;
  3739.  
  3740. // this.ec389 = false;
  3741. // this.ec389a = 0;
  3742. // this.ec389r = 0;
  3743.  
  3744. // const stampDomMap = this.stampDom[cTag].mapping;
  3745. // const isTickerRendering = cTag === 'tickerItems';
  3746. // const isMessageListRendering = cTag === 'visibleItems';
  3747.  
  3748. // // coming process can be stacked as ec389a and ec389r are reset.
  3749.  
  3750. // const deObjectComponent = (itemEntry) => {
  3751. // const I = firstObjectKey(itemEntry);
  3752. // const L = stampDomMap[I];
  3753. // const H = itemEntry[I];
  3754. // return [L, H];
  3755. // }
  3756.  
  3757. // const hostElement = this.hostElement;
  3758.  
  3759. // let renderNodeCount = 0;
  3760. // const renderList = this[cTag].map((item) => {
  3761. // const [L, H] = deObjectComponent(item);
  3762. // const node = kRef(renderMap.get(H));
  3763. // return node && hostElement.contains(node) ? (renderNodeCount++, node) : item;
  3764. // });
  3765.  
  3766. // // this.ec389 = null;
  3767. // // this.ec389a = 0;
  3768. // // this.ec389r = 0;
  3769.  
  3770. // let addedCounter = 0;
  3771. // let removedCounter = 0;
  3772.  
  3773. // const createConnectedComponentElm = (insertionObj, L, H, componentName) => {
  3774. // // const reusable = false;
  3775. // // const componentName = this.getComponentName_(L, H);
  3776. // let component;
  3777. // if (!nullComponents.has(componentName)) {
  3778. // nullComponents.set(componentName, (component = document.createElement(componentName)));
  3779. // component.className = stamperDomClass;
  3780. // // shadowElm.insertAdjacentElement('beforeend', component);
  3781. // } else {
  3782. // component = nullComponents.get(componentName);
  3783. // }
  3784. // component = component.cloneNode(false);
  3785.  
  3786. // // const cnt = insp(component);
  3787.  
  3788. // // cnt.__dataOld = cnt.__dataPending = null;
  3789. // pDivNew.insertAdjacentElement('beforeend', component);
  3790. // // cnt.__dataOld = cnt.__dataPending = null;
  3791.  
  3792. // return component;
  3793. // }
  3794.  
  3795. // const listDom = this.getStampContainer_(cId);
  3796.  
  3797. // const pnForNewItem = (item) => {
  3798.  
  3799. // const [L, H] = deObjectComponent(item);
  3800.  
  3801. // const componentName = this.getComponentName_(L, H);
  3802.  
  3803. // const wmList = wmRemoved.get(componentName.toLowerCase());
  3804.  
  3805. // let connectedComponent = null;
  3806. // if (wmList && (connectedComponent = wmList.firstElementChild)) {
  3807. // if (this.telemetry_) this.telemetry_.reuse++;
  3808. // // if (!wmPendingList) {
  3809. // // wmPendingList = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3810. // // wmPendingList.setAttributeNS('http://www.w3.org/2000/svg', 'wm-pending', 'true');
  3811. // // pDiv.insertAdjacentElement('afterend', wmPendingList);
  3812. // // }
  3813. // // wmPendingList.insertAdjacentElement('beforeend', connectedComponent);
  3814. // pDivNew.insertAdjacentElement('beforeend', connectedComponent);
  3815. // const attrMap = connectedComponent.attributes;
  3816. // const defaultAttrs = componentDefaultAttributes.get(connectedComponent);
  3817. // if (defaultAttrs) {
  3818. // for (const attr of attrMap) {
  3819. // const name = attr.name;
  3820. // if (name in defaultAttrs) attr.value = defaultAttrs[name];
  3821. // else attrMap.removeNamedItem(name);
  3822. // }
  3823. // if (attrMap.length !== defaultAttrs['"']) {
  3824. // for (const name in defaultAttrs) {
  3825. // if (!attrMap[name] && name !== '"') connectedComponent.setAttribute(name, defaultAttrs[name]);
  3826. // }
  3827. // }
  3828. // }
  3829.  
  3830. // } else {
  3831. // connectedComponent = createConnectedComponentElm(item, L, H, componentName);
  3832. // if (this.telemetry_) this.telemetry_.create++;
  3833. // }
  3834. // if (isTickerRendering) {
  3835. // const container = connectedComponent.firstElementChild;
  3836. // if (container) container.classList.add('yt-live-chat-ticker-stampdom-container');
  3837. // }
  3838.  
  3839. // return [item, L, H, connectedComponent];
  3840.  
  3841. // };
  3842.  
  3843. // let imgPreloadPr = null;
  3844. // if (isMessageListRendering) {
  3845. // const addedItems = renderList.filter(item => item === 'object' && (item instanceof Node));
  3846. // imgPreloadPr = preloadFn(addedItems)();
  3847. // }
  3848.  
  3849. // const newComponentsEntries = await executeTaskBatch(renderList.map(item => ({
  3850. // item,
  3851. // fn(task) {
  3852. // const { item } = task;
  3853. // return typeof item === 'object' && !(item instanceof Node) ? pnForNewItem(item) : item;
  3854. // }
  3855. // })));
  3856.  
  3857. // const imgPromises = [];
  3858.  
  3859. // const imgPaths = new Set();
  3860.  
  3861. // const pnForRenderNewItem = (entry) => {
  3862. // const [item, L, H, connectedComponent] = entry;
  3863.  
  3864. // const cnt = insp(connectedComponent);
  3865. // if (!cnt.__refreshData938__) {
  3866. // cnt.constructor.prototype.__refreshData938__ = __refreshData938__;
  3867. // }
  3868. // if (typeof cnt.data === 'object' && cnt.__dataEnabled === true && cnt.__dataReady === true && cnt.__dataInvalid === false) {
  3869. // cnt.data = H;
  3870. // } else {
  3871. // const q = this.deferRenderStamperBinding_
  3872. // let q2;
  3873. // if (typeof q === 'object') q2 = this.deferRenderStamperBinding_ = [];
  3874. // this.deferRenderStamperBinding_(connectedComponent, L, H);
  3875. // this.flushRenderStamperComponentBindings_();
  3876. // if (typeof q === 'object') {
  3877. // this.deferRenderStamperBinding_ = q;
  3878. // q2.length = 0;
  3879. // }
  3880. // }
  3881. // if (cnt.data) cnt.__refreshData938__('data', !0); // ensure data is invalidated
  3882.  
  3883. // // fix yt-icon issue
  3884. // for (const node of connectedComponent.getElementsByTagName('yt-icon')) {
  3885. // try {
  3886. // const cnt = insp(node);
  3887. // if (!cnt.__refreshProps938__) cnt.constructor.prototype.__refreshProps938__ = __refreshProps938__;
  3888. // cnt.__refreshProps938__();
  3889. // } catch (e) { }
  3890. // }
  3891.  
  3892. // componentDefaultAttributes.set(connectedComponent, getAttributes(connectedComponent));
  3893. // return entry;
  3894. // }
  3895.  
  3896. // const newRenderedComponents = await executeTaskBatch(newComponentsEntries.map(entry => ({
  3897. // entry,
  3898. // fn(task) {
  3899. // const { entry } = task;
  3900. // return typeof entry === 'object' && !(entry instanceof Node) ? pnForRenderNewItem(entry) : entry;
  3901. // }
  3902. // })));
  3903.  
  3904.  
  3905. // this.flushRenderStamperComponentBindings_(); // ensure all deferred flush render tasks clear.
  3906.  
  3907. // // imgPromises.push(imageFetch('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'));
  3908. // if (imgPromises.length > 0) {
  3909. // const pr1 = Promise.all(imgPromises).catch(e => { });
  3910. // const pr2 = autoTimerFn();
  3911. // await Promise.race([pr1, pr2]).catch(e => { });
  3912. // imgPaths.clear();
  3913. // imgPromises.length = 0;
  3914. // }
  3915. // if (imgPreloadPr) await imgPreloadPr;
  3916.  
  3917. // // const batching = [];
  3918. // // let j = 0;
  3919. // // let elNode;
  3920.  
  3921. // const sideProcesses = [];
  3922.  
  3923. // const removeStampNode_ = (elNode) => {
  3924. // const elm = elNode;
  3925. // const cnt = insp(elm);
  3926. // const componentName = elm.nodeName.toLowerCase();
  3927. // let wmList = wmRemoved.get(componentName);
  3928. // if (!wmList) {
  3929. // wmList = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  3930. // wmList.setAttributeNS('http://www.w3.org/2000/svg', 'wm-component', componentName);
  3931. // pDiv.insertAdjacentElement('afterend', wmList);
  3932. // wmRemoved.set(componentName, wmList);
  3933. // }
  3934. // wmList.insertAdjacentElement('beforeend', elm);
  3935. // const data = cnt.data;
  3936. // if (data) renderMap.delete(cnt.data);
  3937.  
  3938. // sideProcesses.push(reuseFixDataViewModel(elm));
  3939. // sideProcesses.push(reuseFixYtIconRendering(elm));
  3940. // }
  3941.  
  3942. // // const removeStampNode = async () => {
  3943.  
  3944. // // removedCounter++;
  3945.  
  3946. // // const nextElm = nextComponentSiblingFn(elNode);
  3947. // // const elmId = elNode.id;
  3948. // // removeStampNode_(elNode);
  3949. // // // const dzid = this.getAttribute('dz-component-id');
  3950. // // // ---- no-cache ----
  3951. // // // try{
  3952. // // // elm.remove();
  3953. // // // }catch(e){}
  3954. // // // ---- no-cache ----
  3955.  
  3956. // // if (cTag === 'visibleItems') {
  3957. // // sideProcesses.push(onVisibleItemStampNodeRemoval(elmId));
  3958. // // }
  3959.  
  3960. // // j++;
  3961. // // elNode = nextElm;
  3962.  
  3963. // // }
  3964.  
  3965. // // if (typeof Polymer !== "undefined" && typeof Polymer.flush === "function") {
  3966. // // // clear all pending rendering first
  3967. // // await stackMarcoTask(async () => {
  3968. // // Polymer.flush();
  3969. // // });
  3970. // // }
  3971.  
  3972. // // main UI thread - DOM modification
  3973. // await new Promise((resolveDM) => {
  3974. // nextBrowserTick_(() => {
  3975.  
  3976. // const isAtBottom = this.atBottom === true;
  3977. // // if (ENABLE_OVERFLOW_ANCHOR && isAtBottom) {
  3978. // // shouldScrollAfterFlush = true;
  3979. // // }
  3980.  
  3981.  
  3982. // const tasks = [];
  3983.  
  3984. // const taskFn = {
  3985. // remove: (task) => {
  3986.  
  3987. // const { elNode } = task;
  3988.  
  3989. // removedCounter++;
  3990.  
  3991. // const elmId = elNode.id;
  3992. // removeStampNode_(elNode);
  3993. // // const dzid = this.getAttribute('dz-component-id');
  3994. // // ---- no-cache ----
  3995. // // try{
  3996. // // elm.remove();
  3997. // // }catch(e){}
  3998. // // ---- no-cache ----
  3999.  
  4000. // if (isMessageListRendering) {
  4001. // sideProcesses.push(onVisibleItemStampNodeRemoval(elmId));
  4002. // }
  4003.  
  4004. // return 2
  4005.  
  4006. // },
  4007. // append: (task) => {
  4008.  
  4009. // const { newNode, nodeAfter, parentNode } = task;
  4010.  
  4011. // nodeAfter ? nodeAfter.insertAdjacentElement('beforebegin', newNode) : parentNode.insertAdjacentElement('beforeend', newNode);
  4012. // const connectedComponent = newNode;
  4013. // const cnt = insp(connectedComponent);
  4014. // renderMap.set(cnt.data, mWeakRef(connectedComponent));
  4015. // mutationDelayedRefreshData(cnt); // not included to sideProcesses
  4016. // addedCounter++;
  4017.  
  4018. // if (isTickerRendering) {
  4019. // sideProcesses.push(onTickerItemStampNodeAdded());
  4020. // }
  4021.  
  4022. // if (isMessageListRendering && isAtBottom) {
  4023.  
  4024. // const itemScroller = this.itemScroller;
  4025. // if (itemScroller && (!ENABLE_OVERFLOW_ANCHOR || itemScroller.scrollTop === 0)) itemScroller.scrollTop = 16777216;
  4026.  
  4027. // }
  4028.  
  4029. // return 1
  4030. // }
  4031. // }
  4032.  
  4033. // {
  4034. // const indexMap = new WeakMap();
  4035. // let index = 0;
  4036. // for (let elNode_ = firstComponentChildFn(listDom); elNode_ instanceof Node; elNode_ = nextComponentSiblingFn(elNode_)) {
  4037. // indexMap.set(elNode_, index++);
  4038. // }
  4039.  
  4040. // const keepIndices = new Array(renderNodeCount);
  4041. // let keepIndicesLen = 0, lastKeepIndex = -1, requireSort = false;
  4042. // for (let i = 0, l = newRenderedComponents.length; i < l; i++) {
  4043. // const entry = newRenderedComponents[i];
  4044. // if (entry instanceof Node) {
  4045. // const index = indexMap.get(entry);
  4046. // keepIndices[keepIndicesLen++] = [index, entry];
  4047. // if (index > lastKeepIndex) lastKeepIndex = index;
  4048. // else requireSort = true;
  4049. // }
  4050. // }
  4051. // keepIndices.length = keepIndicesLen;
  4052. // if (requireSort) keepIndices.sort((a, b) => a[0] - b[0]);
  4053. // let dk = 0;
  4054.  
  4055. // let j = 0;
  4056. // let elNode;
  4057.  
  4058. // elNode = firstComponentChildFn(listDom);
  4059.  
  4060. // for (const rcEntry of newRenderedComponents) {
  4061. // const index = indexMap.get(rcEntry);
  4062. // if (typeof index === 'number') {
  4063. // const indexEntry = keepIndices[dk++];
  4064. // const [dIdx, dNode] = indexEntry;
  4065. // indexMap.delete(rcEntry);
  4066. // const idx = dIdx;
  4067. // while (j < idx && elNode) {
  4068. // tasks.push({
  4069. // type: 'remove',
  4070. // elNode,
  4071. // fn: taskFn.remove
  4072. // });
  4073. // elNode = nextComponentSiblingFn(elNode);
  4074. // j++;
  4075. // }
  4076. // if (j === idx) {
  4077. // if (elNode) {
  4078. // // if (dNode !== elNode) tasks.push({
  4079. // // type: 'swap',
  4080. // // earlyNode: indexEntry[1],
  4081. // // laterNode: elNode
  4082. // // });
  4083. // elNode = nextComponentSiblingFn(elNode);
  4084. // j++;
  4085. // } else {
  4086. // console.warn('elNode is not available?', renderList, addedCount0, removedCount0, j, idx);
  4087. // }
  4088. // }
  4089. // } else if (rcEntry instanceof Node) {
  4090. // // interruped by the external like clearList
  4091.  
  4092. // tasks.push({
  4093. // type: 'remove',
  4094. // elNode: rcEntry,
  4095. // fn: taskFn.remove
  4096. // });
  4097.  
  4098. // } else {
  4099. // const [item, L, H, connectedComponent] = rcEntry;
  4100.  
  4101. // tasks.push({
  4102. // type: 'append',
  4103. // newNode: connectedComponent,
  4104. // nodeAfter: elNode,
  4105. // parentNode: listDom,
  4106. // fn: taskFn.append
  4107. // });
  4108.  
  4109. // }
  4110.  
  4111. // }
  4112.  
  4113. // while (elNode) {
  4114.  
  4115. // tasks.push({
  4116. // type: 'remove',
  4117. // elNode,
  4118. // fn: taskFn.remove
  4119. // });
  4120. // elNode = nextComponentSiblingFn(elNode);
  4121.  
  4122. // }
  4123.  
  4124. // }
  4125.  
  4126.  
  4127. // executeTaskBatch(tasks).then(resolveDM).catch(console.warn);
  4128.  
  4129. // });
  4130. // }).catch(console.warn);
  4131.  
  4132. // {
  4133. // const arr = this[cTag];
  4134. // let b = 0;
  4135. // b = b | this._setPendingPropertyOrPath(`${cTag}.splices`, {}, true, true);
  4136. // b = b | this._setPendingPropertyOrPath(`${cTag}.length`, arr.length, true, true);
  4137. // b && this._invalidateProperties();
  4138. // }
  4139.  
  4140. // // this.flushRenderStamperComponentBindings_(); // just in case...
  4141.  
  4142. // await Promise.all(sideProcesses);
  4143.  
  4144. // const detail = {
  4145. // container: listDom
  4146. // };
  4147. // this.stampDom[cTag].events && this.hostElement.dispatchEvent(new CustomEvent("yt-rendererstamper-finished", {
  4148. // bubbles: !0,
  4149. // cancelable: !1,
  4150. // composed: !0,
  4151. // detail
  4152. // }));
  4153. // detail.container = null;
  4154.  
  4155. // // if (typeof Polymer !== "undefined" && typeof Polymer.flush === "function") {
  4156. // // // clear all remaining rendering before promise resolve
  4157. // // await stackMarcoTask(async () => {
  4158. // // Polymer.flush();
  4159. // // });
  4160. // // }
  4161.  
  4162. // }
  4163.  
  4164. // cProto[key] = function (cTag, cId, indexSplice) {
  4165. // // console.log('proceedStampDomArraySplices_')
  4166. // // assume no error -> no try catch (performance consideration)
  4167. // const { index, addedCount, removed } = indexSplice;
  4168. // const removedCount = removed ? removed.length : indexSplice.removedCount;
  4169. // indexSplice = null;
  4170. // if (!addedCount && !removedCount) {
  4171. // console.warn('proceedStampDomArraySplices_', 'Error 001');
  4172. // return false;
  4173. // }
  4174. // // const streamArr = this[cTag];
  4175. // if (!this.ec389) {
  4176. // if (this.ec389a || this.ec389r) {
  4177. // console.warn('proceedStampDomArraySplices_', 'Error 002');
  4178. // return false;
  4179. // }
  4180. // this.ec389 = true;
  4181. // this.ec389a = 0;
  4182. // this.ec389r = 0;
  4183. // }
  4184. // const shouldExecute = !this.ec389a && !this.ec389r;
  4185.  
  4186. // this.ec389a += addedCount;
  4187. // this.ec389r += removedCount;
  4188.  
  4189. // if (shouldExecute) {
  4190.  
  4191. // // let shouldScrollAfterFlush = false;
  4192. // const pr00 = this.ec389pr;
  4193. // const ec389pr = this.ec389pr = this[fnKeyH](cTag, cId, pr00).catch(console.warn);
  4194.  
  4195. // if (cTag === 'visibleItems') {
  4196. // this.prDelay288 = ec389pr;
  4197. // // this.hasUserJustInteracted12_ = (this.hasUserJustInteracted11_ || (() => false));
  4198.  
  4199. // // the first microtask after promise resolved
  4200. // // YYYYYYY
  4201. // // ec389pr.then(async () => {
  4202. // // if (shouldScrollAfterFlush) {
  4203. // // if (this.atBottom === false && this.allowScroll === true && !this.hasUserJustInteracted12_()) this.scrollToBottom_();
  4204. // // wme.data = `${(wme.data & 7) + 1}`;
  4205. // // await wmp;
  4206. // // if (this.atBottom === false && this.allowScroll === true && !this.hasUserJustInteracted12_()) this.scrollToBottom_();
  4207. // // }
  4208. // // });
  4209.  
  4210. // }
  4211.  
  4212. // }
  4213.  
  4214. // return true;
  4215. // }
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221. // }
  4222.  
  4223. // ----------------------------
  4224.  
  4225.  
  4226. // const convertionFuncMap = new WeakMap();
  4227. // let val_kevlar_should_maintain_stable_list = null;
  4228.  
  4229. // const csb = (a, b) => { for (const c in a) if (a.hasOwnProperty(c) && b[c]) return c; return null }
  4230. // const createStampDomArrayFnE1_ = function (items, containerId, componentConfig, rendererConfig, shouldTriggerRendererStamperFinished, isStableList) {
  4231.  
  4232.  
  4233. // // this.__$$fs894$$__ = this.__$$fs894$$__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4234.  
  4235. // // console.log(1880, this.__$$fs894$$__)
  4236. // if(!this[`__0p893::${containerId}__`]) this[`__0p893::${containerId}__`]= [];
  4237.  
  4238. // // const task =
  4239. // queueMicrotask_(()=>{
  4240.  
  4241.  
  4242. // });
  4243. // this[`__0p892::${containerId}__`] = (this[`__0p892::${containerId}__`] || Promise.resolve(0)).then(async () => {
  4244.  
  4245. // try {
  4246.  
  4247. // if ((this.hostElement || 0).isConnected) this[`__0fs892::${containerId}__`] = `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4248. // const t892 = this[`__0fs892::${containerId}__`];
  4249. // // a - array
  4250. // // c - mapping
  4251. // // d - reuseComponents
  4252. // // e - events (shouldTriggerRendererStamperFinished)
  4253. // // h - stamperStableList
  4254.  
  4255. // // this is for flushing the new elements to a blank container. (without reusing)
  4256.  
  4257. // const b_ = containerId;
  4258. // const c_ = componentConfig;
  4259. // const items_ = items;
  4260.  
  4261. // const doDeferRenderStamperBinding_ = async (component) => {
  4262. // const i = component[stampIdxSb];
  4263. // const u = items_[i];
  4264. // const c = c_;
  4265. // const x = csb(c, u);
  4266. // this.deferRenderStamperBinding_(component, c[x], u[x]); // necessary?
  4267. // };
  4268.  
  4269. // const container = this.getStampContainer_(b_);
  4270.  
  4271. // const domShell = container.__domApi || container;
  4272. // if (!domShell || !domShell.appendChild || typeof domShell.childElementCount !== 'number') throw new Error();
  4273. // const domShellElementCount = domShell.childElementCount;
  4274. // const noscript = document.createElement('noscript');
  4275. // // document.body.appendChild(noscript);
  4276.  
  4277. // let doc = document;
  4278.  
  4279. // const nofn = () => true;
  4280. // const n = items_.length;
  4281. // const fns = new Array(n);
  4282. // let cxt = 0;
  4283.  
  4284. // let qxd = domShellElementCount > 0 ? new WeakSet() : null;
  4285. // const nextTickFnE1 = () => {
  4286. // items_.some((item, i) => {
  4287.  
  4288. // const componentKey = csb(componentConfig, item);
  4289. // if (!componentKey) {
  4290. // fns[i] = nofn;
  4291. // cxt++;
  4292. // } else {
  4293.  
  4294. // const newComponent = this.createComponent_(componentConfig[componentKey], item[componentKey], rendererConfig);
  4295. // newComponent[stampIdxSb] = i;
  4296. // doDeferRenderStamperBinding_(newComponent);
  4297. // // mutex = mutex.then(() => {
  4298. // noscript.appendChild(newComponent);
  4299. // // });
  4300.  
  4301. // // Promise.resolve(cp).then(doDeferRenderStamperBinding_);
  4302. // let newComponent_ = newComponent;
  4303. // fns[i] = () => {
  4304. // if (!newComponent_) return true;
  4305. // if (newComponent_.parentNode === noscript) {
  4306. // newComponent_ = null;
  4307. // return true;
  4308. // }
  4309. // return false;
  4310. // };
  4311.  
  4312. // }
  4313.  
  4314. // });
  4315. // noscript.setAttribute('ylul8gr', `${Date.now()}`);
  4316. // };
  4317.  
  4318. // const nextTickFnF1 = () => {
  4319. // let startNode = null;
  4320.  
  4321. // const isSet = new Set();
  4322. // items_.some((item, i) => {
  4323.  
  4324. // const componentKey = csb(componentConfig, item);
  4325. // if (!componentKey) {
  4326. // fns[i] = nofn;
  4327. // cxt++;
  4328. // } else {
  4329.  
  4330. // const componentName = this.getComponentName_(componentConfig[componentKey], item[componentKey]);
  4331. // isSet.add(componentName);
  4332. // let np = startNode || domShell.firstElementChild;
  4333. // let chosenNode = null;
  4334. // while (np) {
  4335. // if (np instanceof Node_ && np.is === componentName && !qxd.has(np)) {
  4336. // qxd.add(np);
  4337. // chosenNode = np;
  4338. // break;
  4339. // }
  4340. // np = np.nextElementSibling;
  4341. // }
  4342.  
  4343.  
  4344. // const cp = chosenNode || this.createComponent_(componentConfig[componentKey], item[componentKey], rendererConfig);
  4345. // let oldIdx = cp[stampIdxSb];
  4346.  
  4347. // cp[stampIdxSb] = i;
  4348. // doDeferRenderStamperBinding_(cp);
  4349. // if (chosenNode !== null && cp === chosenNode) {
  4350.  
  4351. // fns[i] = nofn;
  4352. // startNode = chosenNode;
  4353. // } else {
  4354.  
  4355. // // mutex = mutex.then(() => {
  4356. // noscript.appendChild(cp); // ui formation
  4357. // // });
  4358.  
  4359. // // Promise.resolve(cp).then(doDeferRenderStamperBinding_);
  4360. // let q = cp;
  4361. // fns[i] = () => {
  4362. // if (q && q.parentNode === noscript) {
  4363. // const cp = q;
  4364. // q = null;
  4365. // }
  4366. // if (!q) return true;
  4367. // };
  4368.  
  4369. // }
  4370.  
  4371. // }
  4372.  
  4373. // });
  4374.  
  4375. // if (isSet.size === 1 && qxd !== null) {
  4376.  
  4377. // const is = isSet.values().next().value;
  4378.  
  4379. // if (typeof is === 'string' && is.length >= 1) {
  4380.  
  4381. // let np = startNode || domShell.firstElementChild;
  4382. // const removal = [];
  4383. // while (np) {
  4384. // if (np instanceof Node_ && np.is === is && !qxd.has(np)) {
  4385. // removal.push(np);
  4386. // np[stampIdxSb] = -1;
  4387. // }
  4388. // np = np.nextElementSibling;
  4389. // }
  4390. // // by default, removal.length shoule be zero. just play safe.
  4391. // if (removal.length > 0) {
  4392. // const dFrag = doc.createDocumentFragment();
  4393. // dFrag.append(...removal);
  4394. // removal.length = 0;
  4395. // }
  4396.  
  4397. // }
  4398.  
  4399. // }
  4400. // noscript.setAttribute('ylul8gr', `${Date.now()}`);
  4401.  
  4402.  
  4403.  
  4404. // }
  4405.  
  4406. // const pr = new Promise(resolvePR => {
  4407.  
  4408. // let mo = new MutationObserver(() => {
  4409. // if (typeof fns[n - 1] !== 'function') return;
  4410. // if (!noscript.hasAttribute('ylul8gr')) return;
  4411. // const everyTrue = fns.every(fn => fn() === true);
  4412. // if (everyTrue) {
  4413. // if (mo) {
  4414. // mo.disconnect();
  4415. // mo.takeRecords();
  4416. // mo = null;
  4417. // }
  4418. // resolvePR();
  4419. // }
  4420. // });
  4421. // mo.observe(noscript, { subtree: false, childList: true, attributes: ['ylul8gr'] });
  4422.  
  4423. // if (domShellElementCount > 0) {
  4424. // nextBrowserTick_(nextTickFnF1);
  4425. // } else {
  4426. // nextBrowserTick_(nextTickFnE1);
  4427. // }
  4428.  
  4429. // });
  4430. // await pr.then();
  4431. // fns.length = 0;
  4432. // qxd = null;
  4433.  
  4434. // // console.log(3025)
  4435.  
  4436.  
  4437.  
  4438. // // document.documentElement.appendChild.call(doc.documentElement, noscript);
  4439. // // nativeRemoveE.call(noscript);
  4440.  
  4441. // // nativeRemoveE.call(noscript);
  4442. // noscript.remove(); // trigger isAttached change
  4443. // const hostElement = this.hostElement;
  4444.  
  4445.  
  4446. // /** @type {DocumentFragment} */
  4447. // // const gFragment = document.createDocumentFragment();
  4448. // const gFragment = doc.createDocumentFragment();
  4449.  
  4450. // const fnE = () => {
  4451. // const evt = new CustomEvent("yt-rendererstamper-finished", {
  4452. // bubbles: !0,
  4453. // cancelable: !1,
  4454. // composed: !0,
  4455. // detail: {
  4456. // container
  4457. // }
  4458. // });
  4459. // hostElement.dispatchEvent(evt);
  4460. // };
  4461.  
  4462. // let f1, f2;
  4463. // f1 = async () => {
  4464. // await new Promise(r => nextBrowserTick_(r));
  4465. // if (t892 !== this[`__0fs892::${containerId}__`]) return;
  4466. // // await new Promise(r=>setTimeout(r, 1000));
  4467.  
  4468. // // if (this.data !== data || this.__data !== __data) return;
  4469.  
  4470. // const domShellElementCountCurrent = domShell.childElementCount;
  4471. // if (domShellElementCountCurrent !== domShellElementCount) return;
  4472. // if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
  4473. // return;
  4474. // }
  4475. // // const t1 = performance.now();
  4476.  
  4477. // if (DO_createStampDomArrayFnE1_nativeAppendD) {
  4478. // let elm;
  4479. // while (elm = noscript.firstChild) {
  4480. // nativeAppendD.call(gFragment, elm); // no attached / detached
  4481. // }
  4482. // } else {
  4483. // let elm;
  4484. // while (elm = noscript.firstChild) {
  4485. // gFragment.appendChild(elm);
  4486. // }
  4487. // }
  4488. // // const t2 = performance.now();
  4489.  
  4490. // // console.log('createStampDomArrayFn_{T2}', t2-t1);
  4491.  
  4492. // // nextBrowserTick_(f2);
  4493. // return true;
  4494. // };
  4495.  
  4496. // f2 = async () => {
  4497. // await new Promise(r => nextBrowserTick_(r));
  4498. // if (t892 !== this[`__0fs892::${containerId}__`]) return;
  4499. // // if (this.data !== data || this.__data !== __data) return;
  4500.  
  4501. // const domShellElementCountCurrent = domShell.childElementCount;
  4502. // if (domShellElementCountCurrent !== domShellElementCount) return;
  4503. // if (hostElement.isConnected === false || this.isAttached === false || !hostElement.contains(container) || container.__domApi !== domShell) {
  4504. // return;
  4505. // }
  4506.  
  4507. // domShell.appendChild(gFragment);
  4508. // this.flushRenderStamperComponentBindings_();
  4509. // this.markDirty && this.markDirty();
  4510.  
  4511. // if (shouldTriggerRendererStamperFinished) {
  4512. // nextBrowserTick_(fnE);
  4513. // }
  4514.  
  4515. // return true;
  4516.  
  4517. // };
  4518.  
  4519. // const r1 = await f1();
  4520. // if (r1 === true) {
  4521. // const r2 = await f2();
  4522. // }
  4523.  
  4524.  
  4525. // } catch (err) {
  4526.  
  4527. // console.warn(err);
  4528.  
  4529. // } finally {
  4530. // //
  4531. // }
  4532.  
  4533. // }).catch(() => 0);
  4534.  
  4535.  
  4536. // };
  4537.  
  4538.  
  4539. // const stampIdxSb = Symbol();
  4540. // 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
  4541. // const byPassIs55 = new Set(['ytd-rich-grid-renderer', 'ytd-rich-shelf-renderer']);
  4542. // const byPassIs55 = new Set([
  4543. // 'ytd-rich-grid-renderer', 'ytd-rich-shelf-renderer', // avoid disappearing of video/short entries
  4544. // 'ytd-unified-share-panel-renderer', 'yt-third-party-share-target-section-renderer', 'ytd-add-to-playlist-renderer', // avoid share-panel being non-central
  4545. // 'ytd-continuation-item-renderer', 'tp-yt-paper-spinner',
  4546. // 'ytd-multi-page-menu-renderer', 'yt-multi-page-menu-section-renderer'
  4547. // ]);
  4548. // const byPassB55 = new Set(['continuations']);
  4549. // const byPassB55 = new Set(['flexible-item-buttons', 'continuations', 'header', 'sections']);
  4550.  
  4551. // let stampContainer = null;
  4552. // const requestDomApiObject = { getStampContainer_: () => stampContainer };
  4553. // const requestDomApiProxy = new Proxy(requestDomApiObject, {
  4554. // get(target, prop, receiver) {
  4555. // if (prop === 'getStampContainer_') return target[prop];
  4556. // throw new Error("requestDomApiProxyGet");
  4557. // },
  4558. // set(target, prop, value, receiver) {
  4559. // throw new Error("requestDomApiProxySet");
  4560. // }
  4561. // });
  4562. // const fulfillment2Set = new Set([
  4563. // 'ytd-watch-next-secondary-results-renderer.items',
  4564. // 'yt-related-chip-cloud-renderer.content',
  4565. // 'yt-chip-cloud-renderer.chips',
  4566. // // 'ytd-section-list-renderer.contents', // affect loading of https://www.youtube.com/feed/history
  4567. // 'ytd-engagement-panel-section-list-renderer.content',
  4568. // 'ytd-engagement-panel-section-list-renderer.header',
  4569. // 'ytd-video-description-infocards-section-renderer.items',
  4570. // 'yt-clip-creation-renderer.title-input',
  4571. // 'yt-clip-creation-renderer.scrubber',
  4572. // 'ytd-watch-flexy.info-contents',
  4573. // 'ytd-video-primary-info-renderer.menu',
  4574. // 'ytd-menu-renderer.flexible-item-buttons',
  4575. // 'ytd-metadata-row-container-renderer.always-shown',
  4576. // 'ytd-subscribe-button-renderer.notification-preference-button',
  4577. // 'ytd-watch-metadata.subscribe-button',
  4578. // 'ytd-watch-metadata.teaser-carousel',
  4579. // 'ytd-structured-description-content-renderer.items',
  4580. // 'ytd-video-description-infocards-section-renderer.infocard-videos-button',
  4581. // 'ytd-video-description-infocards-section-renderer.infocard-channel-button',
  4582. // 'ytd-rich-metadata-row-renderer.contents',
  4583. // 'ytd-subscribe-button-renderer.notification-preference-button',
  4584. // 'ytd-watch-flexy.panels',
  4585. // // yt-live-chat
  4586. // 'yt-live-chat-renderer.input-panel',
  4587. // 'yt-live-chat-app.contents',
  4588. // 'yt-live-chat-message-input-renderer.picker-buttons',
  4589. // 'yt-live-chat-message-input-renderer.pickers',
  4590. // 'yt-live-chat-message-input-renderer.emoji-picker-button',
  4591. // 'yt-live-chat-product-picker-panel-view-model.items',
  4592. // 'yt-live-chat-message-input-renderer.send-button',
  4593. // 'yt-live-chat-renderer.continuations',
  4594. // // 'yt-live-chat-renderer.item-list', // affect yt live chat message init
  4595. // 'yt-live-chat-renderer.ticker'
  4596. // ]);
  4597.  
  4598. const __refreshData938o__ = {};
  4599. const __refreshData938__ = function (prop, opt) {
  4600. const d = this[prop];
  4601. if (d) {
  4602. this._setPendingProperty(prop, __refreshData938o__, opt);
  4603. this._setPendingProperty(prop, d, opt);
  4604. this._invalidateProperties();
  4605. }
  4606. };
  4607.  
  4608. // const pendingStampFlushs = [];
  4609.  
  4610. const nativeNow = performance.constructor.prototype.now.bind(performance);
  4611.  
  4612. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  4613.  
  4614. const executeTaskBatch = function (taskArr, firstMarco = true) {
  4615. if (!(taskArr || 0).length) throw new TypeError(`Illegal invocation`);
  4616. return new Promise(resolveFinal => {
  4617. let resolveFn = null;
  4618. const len = taskArr.length;
  4619. const results = new Array(len);
  4620. const makePromise = () => new Promise(resolve => { resolveFn = resolve });
  4621. let firedCount = 0;
  4622. const executor = () => {
  4623. if (taskArr.length !== len) throw new TypeError(`Illegal invocation`);
  4624. const resolveFn_ = resolveFn;
  4625. let t0 = 0;
  4626. let next = 0;
  4627. taskArr.forEach((task, idx) => {
  4628. if (typeof (task || 0) !== 'object') throw new TypeError(`Illegal invocation`);
  4629. if (!task.fired) {
  4630. queueMicrotask_(() => {
  4631. if (next || task.fired) return;
  4632. task.fired = true;
  4633. if (++firedCount === len) next |= 2;
  4634. if (!t0) t0 = nativeNow() + 10;
  4635. const { fn } = task;
  4636. results[idx] = fn(task); // sync task only
  4637. if (nativeNow() > t0) next |= 1;
  4638. });
  4639. }
  4640. });
  4641. queueMicrotask_(() => resolveFn_(next))
  4642. }
  4643. const looper = (next) => {
  4644. if (!next) throw new TypeError(`Illegal invocation`);
  4645. if (next & 2) {
  4646. if (next & 1) {
  4647. nextBrowserTick_(() => resolveFinal(results))
  4648. } else {
  4649. resolveFinal(results);
  4650. }
  4651. } else {
  4652. const p = makePromise();
  4653. nextBrowserTick_(executor);
  4654. p.then(looper);
  4655. }
  4656. }
  4657. const p = makePromise();
  4658. firstMarco ? nextBrowserTick_(executor) : executor();
  4659. p.then(looper);
  4660.  
  4661. })
  4662.  
  4663. }
  4664.  
  4665.  
  4666. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  4667.  
  4668.  
  4669. const globalPromiseStack = {};
  4670.  
  4671. // let dummy;
  4672. // while(!dummy){
  4673.  
  4674. // dummy = document.querySelector('yt-icon');
  4675. // await new Promise(r=>setTimeout(r,0));
  4676. // }
  4677.  
  4678. dummy = document.createElement('yt-icon');
  4679.  
  4680. let cProto;
  4681. if (!(dummy instanceof Element)) return;
  4682. cProto = insp(dummy).constructor.prototype;
  4683.  
  4684. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  4685. cProto.determineIconSet671 = cProto.determineIconSet;
  4686. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  4687. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  4688. cProto.getIconManager671 = cProto.getIconManager;
  4689. cProto.getIconShapeData671 = cProto.getIconShapeData;
  4690. cProto.renderIcon671 = cProto.renderIcon;
  4691.  
  4692. if(cProto.__renderIconFix__) return;
  4693. cProto.__renderIconFix__ = true;
  4694.  
  4695. let taskStack = [];
  4696. const cmObs = new MutationObserver(()=>{
  4697. const tasks = taskStack.slice();
  4698. taskStack.length = 0;
  4699. for(const task of tasks){
  4700. task();
  4701. }
  4702. })
  4703. const cm = document.createComment('1');
  4704. const stackTask = (f)=>{
  4705. taskStack.push(f);
  4706. cm.data = `${(cm.data & 7) + 1}`;
  4707. }
  4708. cmObs.observe(cm, {characterData: true});
  4709.  
  4710. let iconManagers = {}; // assume shared
  4711.  
  4712. window.iconManagers = ()=>iconManagers;
  4713.  
  4714.  
  4715. const setupYtIcon=(inst)=>{
  4716. if(inst.__ytIconSetup588__) return;
  4717. const cProto = Reflect.getPrototypeOf(inst);
  4718. cProto. __ytIconSetup588__ = true;
  4719.  
  4720. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4721.  
  4722. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false;
  4723. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true;
  4724. config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false;
  4725. config.EXPERIMENT_FLAGS.wil_icon_network_first = true;
  4726.  
  4727. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  4728. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  4729. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  4730. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  4731.  
  4732.  
  4733.  
  4734. }
  4735.  
  4736. cProto.handlePropertyChange = function (...a) { // 10+
  4737.  
  4738. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4739. // string bool=false bool int=24 (empty string?) bool? bool
  4740. // undefined bool=false bool int bool? true
  4741.  
  4742.  
  4743. // if(typeof a[0]==='string'&& typeof (a[1]||false)==='boolean' && typeof a[2]==='boolean' && typeof a[3] === 'number'){
  4744.  
  4745. // if(a[0].)
  4746. // this.determineIconSet()
  4747. // }
  4748.  
  4749. // const lastData = this.__lastData__;
  4750. // let newData = '';
  4751. this.__resolved__ = {
  4752.  
  4753. };
  4754.  
  4755. // let chAction = null;
  4756.  
  4757. // let returnNone = false;
  4758.  
  4759. // // w.nextAddress ...
  4760. // 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){
  4761.  
  4762. // console.log(12398, this.icon, this.iconsetName, this.iconType)
  4763. // if(this.icon === a[0] && this.icon === `${this.iconsetName}:${this.iconType}` && this.iconType && this.iconsetName && typeof this.targetContainer === 'string'){
  4764.  
  4765. // console.log(12399)
  4766. // newData = `renderIcon_${this.targetContainer}_${this.icon}`;
  4767. // chAction = ()=>{
  4768. // this.renderIcon(this.targetContainer, this.icon);
  4769. // console.log('yt-icon.xxs')
  4770. // }
  4771.  
  4772. // returnNone = true;
  4773. // }
  4774. // }
  4775.  
  4776.  
  4777. // if(!newData) newData = `x${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  4778.  
  4779. // if (lastData !== newData) {
  4780. // this.__lastData__ = newData;
  4781.  
  4782. // if (chAction && newData.startsWith('renderIcon_')) {
  4783. // stackTask(chAction);
  4784. // }
  4785.  
  4786. // }
  4787. const a01 = this.isAttached;
  4788. let a02, a03;
  4789.  
  4790.  
  4791. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  4792.  
  4793. const stackFn = ()=>{
  4794. if(t!== this.__stackedKey3818__){
  4795. return;
  4796. }
  4797. a03 = this.isAttached;
  4798.  
  4799. // if(!a02 && !a03){
  4800.  
  4801. // }
  4802.  
  4803. if(a01 === false && a02 === false && a03 === false) return;
  4804.  
  4805. if(a01===true && a02===true && a03===true){
  4806.  
  4807. }else{
  4808. if(a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false ){
  4809. // unknown yt-icon#label-icon
  4810. return;
  4811. }else{
  4812. console.log('[yt-icon] debug', a01, a02, a03, this)
  4813. }
  4814. }
  4815. this.handlePropertyChange671(...arguments);
  4816.  
  4817. };
  4818.  
  4819.  
  4820.  
  4821. Promise.resolve().then(()=>{
  4822. a02= this.isAttached;
  4823. stackTask(stackFn);
  4824. })
  4825.  
  4826.  
  4827.  
  4828.  
  4829. // console.log('yt-icon.handlePropertyChange', ...arguments);
  4830.  
  4831. // if(returnNone) return;
  4832. // return this.handlePropertyChange671(...arguments);
  4833. }
  4834.  
  4835. cProto.determineIconSet = function (a, b, c, d) { // 10-
  4836.  
  4837. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4838. // string bool? bool=false int=24
  4839. // NOTIFICATIONS_NONE OR LIKE
  4840. // console.log('yt-icon.determineIconSet', ...arguments);
  4841.  
  4842. const r = this.determineIconSet671(...arguments);
  4843. // if(r.then){
  4844. // r.then((result)=>{
  4845. // console.log('yt-icon.determineIconSet.result = ', result)
  4846. // })
  4847. // }
  4848. return r;
  4849. }
  4850.  
  4851. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  4852.  
  4853. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4854. // same as determineIconSet
  4855. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  4856. return this.switchToYtSysIconset671(...arguments);
  4857. }
  4858.  
  4859. cProto.useYtSysIconsetForMissingIcons = function(a, b, c, d){ // X
  4860.  
  4861. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4862. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  4863. return this.useYtSysIconsetForMissingIcons671(...arguments);
  4864. }
  4865.  
  4866. cProto.getIconManager = function(){ // 10+
  4867.  
  4868. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4869. // no argument
  4870.  
  4871. // if(this.iconsetName && this.iconType){
  4872. // const p = kRef(iconManagers[this.iconsetName]);
  4873. // if(p) return p;
  4874. // }
  4875. // console.log(2388, this.iconType)
  4876. // console.log('yt-icon.getIconManager', ...arguments);
  4877. if(!this.__resolved__)this.__resolved__ ={};
  4878. if(!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  4879. const r = this.__resolved__.getIconManager;
  4880. // if(r.then){
  4881. // r.then((result)=>{
  4882. // iconManagers[this.iconsetName] = mWeakRef(result);
  4883. // console.log('yt-icon.getIconManager.result = ', result)
  4884. // })
  4885. // }
  4886. return r;
  4887. }
  4888.  
  4889. cProto.getIconShapeData = function(){ // 10+
  4890.  
  4891. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4892.  
  4893. // let rr;
  4894. // if (typeof (this.iconType || 0) === 'string' && typeof (this.iconsetName || 0) === 'string' && this.icon === `${this.iconsetName}:${this.iconType}` && (+this.size >= 1)) {
  4895. // const a = this;
  4896. // rr= {
  4897. // iconName: a.iconType.toLowerCase(),
  4898. // iconStyle: (a.active || a.defaultToFilled || c ? "youtube_fill" : "youtube_outline"),
  4899. // iconSize: a.size,
  4900. // iconSetName: a.iconsetName
  4901. // };
  4902.  
  4903. // }
  4904.  
  4905. // no argument
  4906. // console.log('yt-icon.getIconShapeData', ...arguments);
  4907. if(!this.__resolved__)this.__resolved__ ={};
  4908. if(!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  4909. const r = this.__resolved__.getIconShapeData;
  4910. // if (r.then) {
  4911. // r.then((result) =>{
  4912.  
  4913. // console.log('yt-icon.getIconShapeData.result = ', result)
  4914. // console.log('yt-icon.getIconShapeData.resultxx = ', rr)
  4915. // } )
  4916. // }
  4917.  
  4918.  
  4919. /*
  4920.  
  4921. temp1.resolveIcon({
  4922. iconName: a.iconType.toLowerCase(),
  4923. iconStyle: (a.active || a.defaultToFilled || c ? "youtube_fill" : "youtube_outline"),
  4924. iconSize: a.size,
  4925. iconSetName: a.iconsetName
  4926. })
  4927.  
  4928. */
  4929. return r
  4930. }
  4931.  
  4932. cProto.renderIcon = function(a, b){ // X
  4933.  
  4934. if(!this.__ytIconSetup588__) setupYtIcon(this);
  4935. // "" yt-icons:xxx
  4936. // console.log('yt-icon.renderIcon', ...arguments);
  4937. return this.renderIcon671(...arguments);
  4938. }
  4939.  
  4940. });
  4941.  
  4942. // stampDomArray_
  4943. const createStampDomArrayFn_ = () => {
  4944. // if (val_kevlar_should_maintain_stable_list === null) {
  4945. // const config_ = ((window.yt || 0).config_ || 0);
  4946. // val_kevlar_should_maintain_stable_list = ((config_ || 0).EXPERIMENT_FLAGS || 0).kevlar_should_maintain_stable_list === true;
  4947. // }
  4948.  
  4949. // if(true){
  4950.  
  4951.  
  4952. const pSpace = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4953. document.documentElement.insertAdjacentElement('beforeend', pSpace);
  4954. const pNode = document.createElement('ns-538');
  4955. pSpace.insertAdjacentElement('beforeend', pNode);
  4956.  
  4957. const pDiv = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4958. if (typeof pNode.attachShadow === 'function') {
  4959. const pShadow = pNode.attachShadow({ mode: "open" });
  4960. pShadow.replaceChildren(pDiv);
  4961. } else {
  4962. pNode.insertAdjacentElement('beforeend', pDiv);
  4963. }
  4964.  
  4965. const pDivTempRemoval = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4966. pDiv.insertAdjacentElement('beforeend', pDivTempRemoval);
  4967. pDivTempRemoval.setAttribute('attm', 'pDivTempRemoval');
  4968.  
  4969. const pDivDeletion = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4970. pDiv.insertAdjacentElement('beforeend', pDivDeletion);
  4971. pDivDeletion.setAttribute('attm', 'pDivDeletion');
  4972. const pDivKeep = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4973. pDiv.insertAdjacentElement('beforeend', pDivKeep);
  4974. pDivKeep.setAttribute('attm', 'pDivKeep');
  4975.  
  4976.  
  4977. const pDivDeletionObs = new MutationObserver(() => {
  4978. let node = pDivDeletion.firstElementChild;
  4979. while (node) {
  4980. let nextNode = node.nextElementSibling;
  4981. if (node.__delayRemoved__) {
  4982. removeTNode(node)
  4983. // } else {
  4984. // node.remove();
  4985. }
  4986. node = nextNode;
  4987. }
  4988. if (pDivDeletion.firstChild) pDivDeletion.textContent = '';
  4989. });
  4990. pDivDeletionObs.observe(pDivDeletion, { childList: true, subtree: false });
  4991.  
  4992. // const URa = function (a, b) {
  4993. // for (var c in a)
  4994. // if (a.hasOwnProperty(c) && b[c])
  4995. // return c;
  4996. // return null
  4997. // }
  4998.  
  4999. const syta = Symbol(); // container uid
  5000. // const sytb = Symbol();
  5001. const sytc = Symbol(); // data & parent relationship
  5002. const sytd = Symbol(); // bind data and component (in case not .data relationship -- to be reviewed)
  5003. const syte = Symbol(); // data uid
  5004.  
  5005. // const tmpElementNode = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  5006.  
  5007. let fallbackToDefault = false;
  5008.  
  5009. const attributeMutationObserver = new MutationObserver((mutations) => {
  5010. const targets = new Set();
  5011. for (const mutation of mutations) {
  5012. targets.add(mutation.target);
  5013. }
  5014. for (const container of targets) {
  5015. const tag = container.__closestYtTag388__;
  5016. if (tag) {
  5017. const hostElement = container.closest(tag);
  5018. if (hostElement && hostElement.is === tag) {
  5019. const detail = {
  5020. container
  5021. };
  5022. hostElement.dispatchEvent(new CustomEvent("yt-rendererstamper-finished", {
  5023. bubbles: !0,
  5024. cancelable: !1,
  5025. composed: !0,
  5026. detail
  5027. }));
  5028. detail.container = null;
  5029. }
  5030. }
  5031. }
  5032. });
  5033.  
  5034. const stamperTasksA = {};
  5035.  
  5036. const YRa = (a, b) => {
  5037. for (const c in a)
  5038. if (a.hasOwnProperty(c) && b[c])
  5039. return c;
  5040. return null
  5041. }
  5042.  
  5043. // let lastClickX33 = 0;
  5044. // let minusX33 = 0;
  5045. // document.addEventListener('pointerdown', ()=>{
  5046. // nextBrowserTick_(()=>{
  5047. // minusX33 = 10000;
  5048. // });
  5049. // minusX33 = 0;
  5050. // lastClickX33 = Date.now();
  5051. // },true);
  5052. // document.addEventListener('keydown', ()=>{
  5053. // nextBrowserTick_(()=>{
  5054. // minusX33 = 10000;
  5055. // });
  5056. // minusX33 = 0;
  5057. // lastClickX33 = Date.now();
  5058. // },true);
  5059. // document.addEventListener('keyup', ()=>{
  5060. // nextBrowserTick_(()=>{
  5061. // minusX33 = 10000;
  5062. // });
  5063. // minusX33 = 0;
  5064. // lastClickX33 = Date.now();
  5065. // },true);
  5066. // document.addEventListener('pointerup', ()=>{
  5067. // nextBrowserTick_(()=>{
  5068. // minusX33 = 10000;
  5069. // });
  5070. // minusX33 = 0;
  5071. // lastClickX33 = Date.now();
  5072. // },true);
  5073.  
  5074. // document.addEventListener('pointercancel', ()=>{
  5075. // nextBrowserTick_(()=>{
  5076. // minusX33 = 10000;
  5077. // });
  5078. // minusX33 = 0;
  5079. // lastClickX33 = Date.now();
  5080. // },true);
  5081.  
  5082. let pageFirstDom = '';
  5083.  
  5084. // let emComponents = new Set();
  5085. let withStampDomExx = false;
  5086.  
  5087. const DEBUG_STAMP_CHANGE = false;
  5088.  
  5089.  
  5090. const reuseStore = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? new Map() : null;
  5091. const registry = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? new FinalizationRegistry((heldValue) => {
  5092. DEBUG_STAMP_CHANGE && console.log(`Object(${heldValue}) has been released`);
  5093. }) : null;
  5094.  
  5095. const registerFn = typeof WeakRef === "function" && typeof FinalizationRegistry === "function" ? (node, heldValue) => {
  5096. Promise.resolve(node).then((node) => {
  5097. registry.register(node, heldValue);
  5098. });
  5099. } : () => { }
  5100.  
  5101.  
  5102. const go = function (a, b, c, d) {
  5103. d || (d = {
  5104. bubbles: !0,
  5105. cancelable: !1,
  5106. composed: !0
  5107. });
  5108. c !== null && c !== void 0 && (d.detail = c);
  5109. b = new CustomEvent(b, d);
  5110. a.dispatchEvent(b);
  5111. return b
  5112. };
  5113.  
  5114. const removeTNode = (node) => { // need trigger removal of its parent component
  5115. const xdeadv = xdeadc00.__domApi;
  5116. if (node.isConnected === true) {
  5117. if (node.parentNode !== pDivDeletion) {
  5118. pDivDeletion.insertAdjacentHTML('afterbegin', ttpHTML('<!---->'));
  5119. pDivDeletion.lastChild.replaceWith(node); // attached -> attached
  5120. }
  5121.  
  5122. // xdeadv.appendChild(node); // attached -> detached
  5123. // xdeadv.removeChild(node); // detached -> detached
  5124.  
  5125. node.remove(); // attached -> detached
  5126. xdeadv.appendChild(node); // detached -> detached
  5127. xdeadv.removeChild(node); // detached -> detached
  5128. } else {
  5129.  
  5130. node.remove(); // detached -> detached
  5131. xdeadv.appendChild(node); // detached -> detached
  5132. xdeadv.removeChild(node); // detached -> detached
  5133.  
  5134. // xdeadv.appendChild(node); // detached -> detached
  5135. // xdeadv.removeChild(node); // detached -> detached
  5136. }
  5137. }
  5138.  
  5139.  
  5140. const removeTNodeDelayed = (node) => {
  5141. if (node.isConnected === true) {
  5142. node.__delayRemoved__ = true;
  5143. pDivDeletion.insertAdjacentHTML('afterbegin', ttpHTML('<!---->'));
  5144. pDivDeletion.lastChild.replaceWith(node); // attached -> attached
  5145. } else {
  5146. const xdeadv = xdeadc00.__domApi;
  5147. xdeadv.appendChild(node); // detached -> detached
  5148. xdeadv.removeChild(node); // detached -> detached
  5149. }
  5150. }
  5151.  
  5152. let triggerCountWithinMicro = 0;
  5153.  
  5154.  
  5155. const gn = function (items__, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList) {
  5156. if (!xdeadc00) setupXdeadC(this);
  5157. let useSyncE = false; // essential components
  5158. // let useNative = false; // native
  5159. let disableTaskSkip = false;
  5160.  
  5161. triggerCountWithinMicro++;
  5162. const triggerCountWithinMicro_ = triggerCountWithinMicro;
  5163. Promise.resolve().then(() => {
  5164. triggerCountWithinMicro--;
  5165. });
  5166.  
  5167. const stack = new Error().stack;
  5168.  
  5169. let appendFrag = null;
  5170.  
  5171.  
  5172. // const safeFn0 = (items, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList) => {
  5173.  
  5174. // let err, result;
  5175.  
  5176.  
  5177. // const qv1 = config.DEFERRED_DETACH;
  5178. // const qv2 = config.REUSE_COMPONENTS;
  5179. // const qv3 = config.STAMPER_STABLE_LIST;
  5180. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5181. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5182. // // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5183.  
  5184.  
  5185. // try {
  5186. // result = this.stampDomArray9682_(items, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList);
  5187. // } catch (e) {
  5188. // err = e;
  5189. // }
  5190.  
  5191. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5192. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5193. // // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5194.  
  5195. // if (err) throw err;
  5196.  
  5197. // return result;
  5198.  
  5199.  
  5200. // };
  5201.  
  5202. // const safeFn = (items, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList) => {
  5203.  
  5204. // let err, result;
  5205.  
  5206.  
  5207. // const qv1 = config.DEFERRED_DETACH;
  5208. // const qv2 = config.REUSE_COMPONENTS;
  5209. // const qv3 = config.STAMPER_STABLE_LIST;
  5210. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5211. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5212. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5213.  
  5214.  
  5215. // try {
  5216. // this.stampDomArray9682_(null, containerId, null, bReuseComponent, null, null);
  5217. // result = this.stampDomArray9682_(items, containerId, componentConfig, bReuseComponent, bEventCallback, bStableList);
  5218. // } catch (e) {
  5219. // err = e;
  5220. // }
  5221.  
  5222. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5223. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5224. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5225.  
  5226. // if (err) throw err;
  5227.  
  5228. // return result;
  5229.  
  5230.  
  5231. // };
  5232.  
  5233. // const safeClear = (containerId, bEventCallback, finishState) => {
  5234.  
  5235. // let err, result;
  5236.  
  5237.  
  5238. // const qv1 = config.DEFERRED_DETACH;
  5239. // const qv2 = config.REUSE_COMPONENTS;
  5240. // const qv3 = config.STAMPER_STABLE_LIST;
  5241. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5242. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5243. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5244.  
  5245.  
  5246. // try {
  5247. // this.stampDomArray9682_(null, containerId, null, false, null, null);
  5248. // const k = this.getStampContainer_(containerId);
  5249.  
  5250. // if (finishState & 1) {
  5251. // this.flushRenderStamperComponentBindings_();
  5252. // }
  5253. // if (finishState & 2) {
  5254. // this.markDirty && this.markDirty();
  5255. // }
  5256. // if (finishState & 4) {
  5257. // bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  5258. // container: k
  5259. // });
  5260. // }
  5261. // } catch (e) {
  5262. // err = e;
  5263. // }
  5264.  
  5265. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5266. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5267. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5268.  
  5269. // if (err) throw err;
  5270.  
  5271. // return result;
  5272.  
  5273.  
  5274. // };
  5275.  
  5276.  
  5277.  
  5278. // const safeAppendElm = (elm, items, containerId, componentConfig, bEventCallback, removeExisting, finishState) => {
  5279.  
  5280. // let err, result;
  5281.  
  5282.  
  5283. // const qv1 = config.DEFERRED_DETACH;
  5284. // const qv2 = config.REUSE_COMPONENTS;
  5285. // const qv3 = config.STAMPER_STABLE_LIST;
  5286. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5287. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5288. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5289.  
  5290.  
  5291. // try {
  5292. // if (removeExisting) this.stampDomArray9682_(null, containerId, null, false, null, null);
  5293. // const c = componentConfig;
  5294. // const k = this.getStampContainer_(containerId);
  5295. // const b = k.__domApi || k;
  5296.  
  5297. // const g = appendFrag || (appendFrag = document.createDocumentFragment());
  5298. // let r;
  5299. // for (let i = 0, l = items.length; i < l; i++) {
  5300. // const u = items[i];
  5301. // const w = YRa(c, u);
  5302. // if (w) {
  5303. // r = elm;
  5304. // this.deferRenderStamperBinding_(r, c[w], u[w]);
  5305. // g.appendChild(r);
  5306. // }
  5307. // }
  5308. // b.appendChild(g)
  5309.  
  5310. // if (finishState & 1) {
  5311. // this.flushRenderStamperComponentBindings_();
  5312. // }
  5313. // if (finishState & 2) {
  5314. // this.markDirty && this.markDirty();
  5315. // }
  5316. // if (finishState & 4) {
  5317. // bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  5318. // container: k
  5319. // });
  5320. // }
  5321. // } catch (e) {
  5322. // err = e;
  5323. // }
  5324.  
  5325. // if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5326. // if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5327. // if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5328.  
  5329. // if (err) throw err;
  5330.  
  5331. // return result;
  5332.  
  5333.  
  5334. // };
  5335.  
  5336.  
  5337. const safeAppend = (items, containerId, componentConfig, bEventCallback, removeExisting, finishState) => {
  5338.  
  5339. let err, result;
  5340.  
  5341.  
  5342. const qv1 = config.DEFERRED_DETACH;
  5343. const qv2 = config.REUSE_COMPONENTS;
  5344. const qv3 = config.STAMPER_STABLE_LIST;
  5345. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5346. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5347. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5348.  
  5349.  
  5350. try {
  5351. if (removeExisting) this.stampDomArray9682_(null, containerId, null, false, null, null);
  5352. const c = componentConfig;
  5353. const k = this.getStampContainer_(containerId);
  5354. const b = k.__domApi || k;
  5355. /*
  5356. const g = document.createDocumentFragment();
  5357. let r;
  5358. for(let i = 0, l =items.length; i<l;i++){
  5359. const u = items[i];
  5360. const w = YRa(c, u);
  5361. if (w) {
  5362. r = this.createComponent_(c[w], u[w], false);
  5363. this.deferRenderStamperBinding_(r, c[w], u[w]);
  5364. g.appendChild(r);
  5365. }
  5366. }
  5367. b.appendChild(g)
  5368. */
  5369.  
  5370. const g = appendFrag || (appendFrag = document.createDocumentFragment());
  5371. let r;
  5372. for (let i = 0, l = items.length; i < l; i++) {
  5373. const u = items[i];
  5374. const w = YRa(c, u);
  5375. if (w) {
  5376. r = this.createComponent_(c[w], u[w], false);
  5377. this.deferRenderStamperBinding_(r, c[w], u[w]);
  5378. g.appendChild(r);
  5379. }
  5380. }
  5381. b.appendChild(g)
  5382.  
  5383. if (finishState & 1) {
  5384. this.flushRenderStamperComponentBindings_();
  5385. }
  5386. if (finishState & 2) {
  5387. this.markDirty && this.markDirty();
  5388. }
  5389. if (finishState & 4) {
  5390. bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  5391. container: k
  5392. });
  5393. }
  5394. } catch (e) {
  5395. err = e;
  5396. }
  5397.  
  5398. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5399. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5400. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5401.  
  5402. if (err) throw err;
  5403.  
  5404. return result;
  5405.  
  5406.  
  5407. };
  5408.  
  5409.  
  5410. const safeFinish = (containerId, bEventCallback) => {
  5411.  
  5412. let err, result;
  5413.  
  5414.  
  5415. const qv1 = config.DEFERRED_DETACH;
  5416. const qv2 = config.REUSE_COMPONENTS;
  5417. const qv3 = config.STAMPER_STABLE_LIST;
  5418. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = false;
  5419. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = false;
  5420. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = false;
  5421.  
  5422.  
  5423. try {
  5424. const k = this.getStampContainer_(containerId);
  5425.  
  5426. this.flushRenderStamperComponentBindings_();
  5427. this.markDirty && this.markDirty();
  5428. bEventCallback && go(this.hostElement, "yt-rendererstamper-finished", {
  5429. container: k
  5430. });
  5431.  
  5432. } catch (e) {
  5433. err = e;
  5434. }
  5435.  
  5436. if (typeof qv1 !== 'undefined') config.DEFERRED_DETACH = qv1;
  5437. if (typeof qv2 !== 'undefined') config.REUSE_COMPONENTS = qv2;
  5438. if (typeof qv3 !== 'undefined') config.STAMPER_STABLE_LIST = qv3;
  5439.  
  5440. if (err) throw err;
  5441.  
  5442. return result;
  5443.  
  5444.  
  5445. };
  5446.  
  5447. const stamperTasksKey = `${this.is}::${containerId}`;
  5448. const stamperTasks = stamperTasksA[stamperTasksKey] || (stamperTasksA[stamperTasksKey] = []);
  5449.  
  5450. let renderJob = this.renderJobsMap_ && containerId ? this.renderJobsMap_[containerId] : null;
  5451. const items_ = items__;
  5452.  
  5453. const hasRunningTasks = stamperTasks.length >= 1;
  5454.  
  5455. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5456. if (!config) {
  5457. console.warn('no config');
  5458. fallbackToDefault = true;
  5459. }
  5460.  
  5461. if (!this.deferredBindingTasks_ || this.deferredBindingTasks_.length !== 0) {
  5462. console.warn('no deferredBindingTasks_');
  5463. fallbackToDefault = true;
  5464. }
  5465.  
  5466. const container = typeof this.getStampContainer_ === 'function' ? this.getStampContainer_(containerId) : (this.$ || 0)[containerId];
  5467.  
  5468. if (!container) {
  5469. console.warn('no container');
  5470. fallbackToDefault = true;
  5471. }
  5472. if (!container.__xnHook944__) {
  5473. if (container.__xnHook944__ === 2) {
  5474. console.log('skip handling weird element (2)');
  5475. return this.stampDomArray9682_(...arguments);// skip handling weird element
  5476. }
  5477. if (container.firstElementChild) {
  5478. container.__xnHook944__ = 2;
  5479. console.log('skip handling weird element (1)');
  5480. return this.stampDomArray9682_(...arguments);// skip handling weird element
  5481. }
  5482. container.__xnHook944__ = 1;
  5483. if (container.firstElementChild) {
  5484. debugger;
  5485. console.warn('container element?')
  5486. }
  5487. try {
  5488. this.stampDomArray9682_(null, containerId, null, false, false, false); // bind the yt dom api
  5489. } catch (e) { }
  5490. }
  5491. if (container.__domApi && !container.__domApi.__daHook377__) {
  5492. setupDomApi(Reflect.getPrototypeOf(container.__domApi));
  5493. setupSDomWrapper();
  5494. }
  5495.  
  5496.  
  5497.  
  5498. // if (!hasRunningTasks && !this[keyRequireAsync] && triggerCountWithinMicro_ === 1) {
  5499.  
  5500. // useSyncE = true;
  5501. // // useNative = true;
  5502. // }
  5503. // if(this.is === 'ytd-shorts' || this.hostElement.closest('ytd-shorts')) useNative = true;
  5504.  
  5505. // const isParentFrag = this?.hostElement?.parentNode instanceof DocumentFragment_;
  5506. // const isParentNode = this?.hostElement?.parentNode instanceof Node;
  5507.  
  5508. // if(isParentFrag){
  5509. // // useNative = true;
  5510. // }else if(isParentNode && bStableList !== false){
  5511.  
  5512. // if (bStableList || this.is === 'ytd-shorts' || this?.hostElement?.parentNode?.hasAttribute('__stampWithStableList__')) {
  5513. // if(!this[`__stamperStable#${containerId}__`]){
  5514.  
  5515. // console.log(12883, bStableList)
  5516.  
  5517. // this[`__stamperStable#${containerId}__`] = true;
  5518.  
  5519. // containerElement.setAttribute('__stampWithStableList__', '');
  5520. // this[`__stamperStable__`] = true;
  5521.  
  5522. // }
  5523. // }
  5524.  
  5525. // if(containerElement.closest('[__stampWithStableList__]')) useNative = true;
  5526. // }
  5527.  
  5528. // if(this.parentComponent){
  5529. // if(this.parentComponent.__stamperStable__){
  5530. // this[`__stamperStable__`] = true;
  5531. // useNative = true;
  5532. // }
  5533. // }
  5534.  
  5535. // if(containerElement.hasAttribute('__stampWithStableList__')) useNative = true;
  5536.  
  5537.  
  5538. // if(useNative) fallbackToDefault = true;
  5539.  
  5540.  
  5541.  
  5542.  
  5543. if (fallbackToDefault) {
  5544. // this[keyRequireAsync] = this[key5993] = this[key5996] = null;
  5545. return this.stampDomArray9682_(...arguments);
  5546. }
  5547.  
  5548.  
  5549. const bStableListA = bStableList !== undefined ? Boolean(bStableList) : (typeof config.STAMPER_STABLE_LIST !== "undefined" ? !!config.STAMPER_STABLE_LIST : false);
  5550.  
  5551. const containerDomApi = (container || 0).__domApi || container;
  5552. const containerElement = containerDomApi instanceof Node ? containerDomApi : insp(container).hostElement instanceof Node ? insp(container).hostElement : container;
  5553.  
  5554. const keyRequireAsync = `__stamperRequireAsync#${containerId}__`;
  5555. const key5993 = `__stamperCounter5993#${containerId}__`;
  5556. const key5996 = `__stamperCounter5996#${containerId}__`;
  5557. // const keyOnSync = `__stamperOnSync#${containerId}__`;
  5558.  
  5559.  
  5560.  
  5561. let hasKey = false;
  5562. if (items_ && items_.length >= 1) {
  5563.  
  5564. hasKey = items_.some((v) => (typeof YRa(componentConfig, v) === 'string'));
  5565.  
  5566. }
  5567.  
  5568. if (bEventCallback) {
  5569. if (!container.__rendererStamperEventCallback388__) {
  5570. container.__rendererStamperEventCallback388__ = true;
  5571. container.__closestYtTag388__ = this.is;
  5572. attributeMutationObserver.observe(container, { attributes: ['ytxx-stamper-finished'] });
  5573. }
  5574. }
  5575.  
  5576.  
  5577. if (!this.__rendererStamperFinishFn588__) {
  5578. this.__rendererStamperFinishFn588__ = () => {
  5579. if (this.deferredBindingTasks_ && this.deferredBindingTasks_.length >= 1) {
  5580. this.flushRenderStamperComponentBindings_();
  5581. }
  5582. this.markDirty && this.markDirty();
  5583. };
  5584.  
  5585. }
  5586.  
  5587.  
  5588.  
  5589.  
  5590. const items = hasKey ? items_.slice() : []; // avoid memory leakge
  5591.  
  5592. this[key5993] = (this[key5993] & 1073741823) + 1;
  5593.  
  5594. let leaveWithNoChange = false;
  5595.  
  5596.  
  5597. if (!hasRunningTasks && !this[keyRequireAsync]) {
  5598. if (!pageFirstDom) { // initial stamp action
  5599. pageFirstDom = this.is;
  5600. useSyncE = true;
  5601. this.__stampDomExx__ = true;
  5602. } else if (this.__stampDomExx__) { // essential component
  5603. useSyncE = true;
  5604. } else if (!withStampDomExx) { // not ready
  5605. useSyncE = true;
  5606. } else if (triggerCountWithinMicro_ === 1) { // first stamp action (user action)
  5607. useSyncE = true;
  5608. }
  5609. if (!hasKey) { // noChange
  5610. leaveWithNoChange = true;
  5611. useSyncE = true;
  5612. }
  5613. }
  5614.  
  5615. const useSync_ = useSyncE;
  5616. const tryBatchUpdate_ = !useSync_ && (renderJob || hasRunningTasks || this[keyRequireAsync]);
  5617.  
  5618. const skey = stamperTasks.__skey__ = `${Date.now()}`;
  5619.  
  5620. let taskFinish = false;
  5621.  
  5622. let result;
  5623.  
  5624. let skipToNextTask = false;
  5625.  
  5626. stamperTasks.push(() => {
  5627. if (skey !== stamperTasks.__skey__ && !disableTaskSkip) {
  5628. skipToNextTask = true;
  5629. // taskFinish = true;
  5630. }
  5631. });
  5632.  
  5633. if (leaveWithNoChange) {
  5634. if (container.__rendererStamperEventCallback388__) {
  5635. stamperTasks.push(() => {
  5636. if (taskFinish) return;
  5637. if(skipToNextTask) return;
  5638. if (container.__rendererStamperEventCallback388__) {
  5639. taskFinish = true;
  5640. container.setAttribute('ytxx-stamper-finished', (container.getAttribute('ytxx-stamper-finished') & 7) + 1);
  5641. return;
  5642. }
  5643. });
  5644. }
  5645. } else {
  5646.  
  5647. this[key5996] = (this[key5996] & 1073741823) + 1;
  5648. }
  5649.  
  5650. // this[key5996] = (this[key5996] & 1073741823) + 1;
  5651.  
  5652.  
  5653.  
  5654.  
  5655.  
  5656. containerElement[syta] = containerElement[syta] || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  5657. containerElement[sytd] = containerElement[sytd] || new WeakMap();
  5658.  
  5659. const mkData = new Set();
  5660.  
  5661. const pneItems = items.map(eq => {
  5662. const dataKey = firstObjectKey(eq);
  5663. const dataKey2 = YRa(componentConfig, eq)
  5664. if (dataKey && dataKey2 === dataKey) {
  5665. const targetComponentName = this.getComponentName_(componentConfig[dataKey], eq[dataKey]);
  5666. const data = eq[dataKey];
  5667. // if (data) data[sytb] = (data[sytb] & 1073741823) + 1;
  5668. if (data) {
  5669. data[syte] = data[syte] || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`;
  5670. const arr = new Set((data[sytc] || '').split(','));
  5671. arr.delete('');
  5672. arr.add(containerElement[syta]);
  5673. data[sytc] = [...arr].join(',');
  5674. // addData.add(data);
  5675. mkData.add(data[syte]);
  5676. const dte = data[syte];
  5677. return {
  5678. targetComponentName,
  5679. dataKey,
  5680. data,
  5681. item: eq,
  5682. dte
  5683. }
  5684. }
  5685. }
  5686. return {
  5687. data: void 0,
  5688. item: eq,
  5689. dte: ''
  5690. };
  5691. }).filter(e=>!!e.dte);
  5692.  
  5693.  
  5694. let elementIter = containerElement.firstElementChild;
  5695. const uneElements = !elementIter ? [] : new Array(containerElement.childElementCount);
  5696. for (let i = 0, l = uneElements.length; i < l; i++) {
  5697. const pageElement = elementIter;
  5698. if (!pageElement) {
  5699. uneElements.length = i;
  5700. break;
  5701. }
  5702. const pageElementData = kRef(containerElement[sytd].get(pageElement));
  5703. const dte_ = pageElement[syte];
  5704. const dte = pageElementData && dte_ && pageElementData[syte] === dte_ && (insp(pageElement).data || 0)[syte] === dte_ ? dte_ : '';
  5705.  
  5706. uneElements[i] = {
  5707. pageElement: pageElement,
  5708. pageElementData: pageElementData,
  5709. dte
  5710. }
  5711. elementIter = elementIter.nextElementSibling;
  5712. }
  5713.  
  5714.  
  5715. const reuseKey = `${containerElement[syta]}**${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`
  5716.  
  5717.  
  5718. let reuseRefreshMode = 1;
  5719.  
  5720. const setupComponent = (data, component, refNode, deferredBindingTask, reused = false) => {
  5721.  
  5722. let noRenderTaskForResuedComponent = false;
  5723. if (component instanceof Node) {
  5724.  
  5725.  
  5726. if (data && data[syte]) {
  5727. // component[sytb] = data[sytb]
  5728. component[sytc] = data[sytc]
  5729. component[syte] = data[syte];
  5730. // containerElement[sytd].set(data, mWeakRef(component));
  5731. containerElement[sytd].set(component, mWeakRef(data));
  5732. if(reuseStore) reuseStore.set(data[syte], mWeakRef(component));
  5733. }
  5734.  
  5735. const cnt = insp(component);
  5736.  
  5737. if (reused && reuseRefreshMode >= 1 && cnt.data) {
  5738. if (!cnt.__refreshData938__) {
  5739. cnt.constructor.prototype.__refreshData938__ = __refreshData938__;
  5740. }
  5741. try {
  5742. cnt.__refreshData938__('data', !0);
  5743. if(reuseRefreshMode >= 2) noRenderTaskForResuedComponent = true;
  5744. } catch (e) {
  5745. }
  5746. }
  5747.  
  5748. if (refNode !== undefined) {
  5749. const componentX = component;
  5750. if (componentX instanceof Node) {
  5751. if (refNode !== componentX) {
  5752. if (!refNode) {
  5753. containerElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  5754. containerElement.lastChild.replaceWith(componentX);
  5755. } else {
  5756. refNode.insertAdjacentHTML('beforebegin', ttpHTML('<!---->'));
  5757. refNode.previousSibling.replaceWith(componentX);
  5758. }
  5759. }
  5760. }
  5761.  
  5762. }
  5763.  
  5764. if (noRenderTaskForResuedComponent) {
  5765.  
  5766. } else if (deferredBindingTask && deferredBindingTask.typeOrConfig) {
  5767. this.deferredBindingTasks_.push(deferredBindingTask);
  5768. this.flushRenderStamperComponentBindings_();
  5769. if (this.deferredBindingTasks_.length >= 1) this.deferredBindingTasks_.length = 0;
  5770. }
  5771.  
  5772. return true;
  5773.  
  5774. }
  5775. return false;
  5776.  
  5777. }
  5778.  
  5779. // if(!useNative)
  5780. stamperTasks.push(() => {
  5781.  
  5782. if (taskFinish) return;
  5783. if(skipToNextTask) return;
  5784.  
  5785. // if(skipToNextTask) return;
  5786.  
  5787.  
  5788. let tryStable = null;
  5789. if (bStableListA) {
  5790. tryStable = {};
  5791.  
  5792. pneItems.forEach(pneItem => {
  5793.  
  5794.  
  5795. const { item, dte, data, dataKey, targetComponentName } = pneItem;
  5796.  
  5797.  
  5798. const q_ = reuseStore ? kRef(reuseStore.get(dte)) : null; // no rendered dom for the item
  5799.  
  5800. if (!q_) {
  5801.  
  5802. if(!tryStable[targetComponentName]) tryStable[targetComponentName] = new Set();
  5803.  
  5804. tryStable[targetComponentName].add((node)=>{
  5805.  
  5806. const component = node;
  5807. const oldDte = node[syte];
  5808. const cnt = insp(node);
  5809. if (oldDte && oldDte !== dte && node.parentNode === containerElement && data && data[syte] && cnt.data && cnt.data[syte] ) {
  5810.  
  5811. this.telemetry_.reuse++;
  5812.  
  5813. // console.log(123992, node, componentConfig[dataKey], data, cnt.data, oldDte, dte )
  5814.  
  5815. // play safe
  5816. // component[sytb] = null;
  5817. component[sytc] = null;
  5818. component[syte] = null;
  5819. containerElement[sytd].delete(component);
  5820. // play safe
  5821.  
  5822. if (reuseStore) reuseStore.delete(oldDte);
  5823. node[syte] = dte;
  5824. node.___reuseFor__ = reuseKey; // once only
  5825.  
  5826.  
  5827.  
  5828. // cnt.data = data;
  5829. const deferredBindingTaskX = { component: component, typeOrConfig: componentConfig[dataKey], data: data }
  5830. setupComponent(data, component, undefined, deferredBindingTaskX, true);
  5831.  
  5832. // console.log(123993,'true')
  5833.  
  5834. return true;
  5835.  
  5836.  
  5837. }
  5838.  
  5839. return false;
  5840.  
  5841. });
  5842.  
  5843. }
  5844.  
  5845. })
  5846.  
  5847. }
  5848.  
  5849.  
  5850. const removes = [];
  5851.  
  5852.  
  5853. let node = containerElement.firstElementChild;
  5854. while (node !== null) {
  5855.  
  5856. const dte = node[syte];
  5857. const nextNode = node.nextElementSibling;
  5858.  
  5859.  
  5860. const tryStableCur = tryStable ? tryStable[node.is] : null;
  5861.  
  5862. if (tryStableCur && dte && !mkData.has(dte) && tryStableCur.size >= 1) {
  5863. // to be removed as no equal entry, but try to make it for tryStable
  5864.  
  5865. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  5866. const fn = tryStableCur.values().next().value;
  5867. tryStableCur.delete(fn) && fn(node);
  5868. // this.deferRenderStamperBinding_(r, c[t], g[t]);
  5869.  
  5870. }
  5871.  
  5872. if(node.___reuseFor__ === reuseKey){
  5873.  
  5874.  
  5875. } else if (!(typeof (dte || 0) === 'string' && mkData.has(dte))) {
  5876.  
  5877. // console.log(insp(node).data);
  5878. // console.log(items)
  5879. removes.push(node);
  5880. // q30 = true;
  5881. // u.removeChild(node)
  5882. // try{
  5883. // v.removeChild(node); // just to trigger some internal removal
  5884. // }catch(e){
  5885. // }
  5886. }
  5887. node = nextNode;
  5888.  
  5889. }
  5890.  
  5891. tryStable = null;
  5892.  
  5893. if(removes.length === 0) return;
  5894.  
  5895. // let xdeadc = xdeadc00;
  5896. if (!xdeadc00) setupXdeadC(this);
  5897. // const xdeadv = xdeadc.__domApi;
  5898.  
  5899. for (const node of removes) {
  5900. removeTNode(node);
  5901. registerFn(node, '01');
  5902. }
  5903.  
  5904. // safeClear(containerId, null, 2 | 4)
  5905.  
  5906. });
  5907.  
  5908.  
  5909. let refNode = null;
  5910. let refNodeIdx = -1;
  5911.  
  5912. const taskPerPneItem = (pneItem) => {
  5913.  
  5914.  
  5915. let reused = false;
  5916.  
  5917. const { item, dte, data, dataKey, targetComponentName } = pneItem;
  5918.  
  5919. refNode = ++refNodeIdx === 0 ? containerElement.firstElementChild : refNode && refNode.nextElementSibling;
  5920.  
  5921.  
  5922. const q_ = reuseStore ? kRef(reuseStore.get(dte)) : null;
  5923. const q = (q_ && (q_.___reuseFor__ === reuseKey || q_.closest('defs'))) ? q_ : null;
  5924.  
  5925. let deferredBindingTaskX = null;
  5926. let component = null;
  5927. if (q && q.is === targetComponentName) {
  5928.  
  5929. if (q_.closest('defs')) {
  5930.  
  5931. const node = component = q;
  5932. const cnt = insp(node);
  5933. cnt.data = data;
  5934. deferredBindingTaskX = { component: q, data: data }
  5935. // listX.push(deferredBindingTaskX);
  5936.  
  5937. DEBUG_STAMP_CHANGE && console.log('reuse X0')
  5938. reused = true;
  5939.  
  5940. } else {
  5941.  
  5942. const node = component = q;
  5943. const cnt = insp(node);
  5944. // cnt.data = data;
  5945. deferredBindingTaskX = { component: q, typeOrConfig: componentConfig[dataKey], data: data }
  5946. // listX.push(deferredBindingTaskX);
  5947.  
  5948. reused = true;
  5949.  
  5950. DEBUG_STAMP_CHANGE && console.log('reuse S0')
  5951.  
  5952. }
  5953.  
  5954.  
  5955.  
  5956. } else {
  5957.  
  5958. // console.log('new')
  5959.  
  5960.  
  5961. // const qf2 = this.deferRenderStamperBinding_;
  5962. // let deferredBindingTaskX = null;
  5963. this.deferRenderStamperBinding_ = function (a, b, c) {
  5964. deferredBindingTaskX = {
  5965. component: a,
  5966. typeOrConfig: b,
  5967. data: c
  5968. };
  5969. }
  5970.  
  5971. // console.log(23400, containerElement.childElementCount)
  5972. safeAppend([item], containerId, componentConfig, bEventCallback, false, 0 | 2 | 4);
  5973.  
  5974. // console.log(23401, containerElement.childElementCount)
  5975.  
  5976. // safeFn([item], containerId, componentConfig, false, bEventCallback, false);
  5977.  
  5978. delete this.deferRenderStamperBinding_;
  5979. // this.deferRenderStamperBinding_ = qf2;
  5980. // console.log(deferredBindingTaskX)
  5981. // listX.push(deferredBindingTaskX);
  5982.  
  5983. component = deferredBindingTaskX.component;
  5984.  
  5985. }
  5986.  
  5987.  
  5988. if (setupComponent(data, component, refNode, deferredBindingTaskX, reused)) {
  5989.  
  5990. refNode = component;
  5991. }
  5992.  
  5993.  
  5994.  
  5995.  
  5996. }
  5997.  
  5998. // if (!useNative)
  5999. pneItems.forEach((pneItem, idx) => {
  6000.  
  6001. stamperTasks.push(() => {
  6002. if (taskFinish) return;
  6003. if (skipToNextTask) return;
  6004.  
  6005. if (skipToNextTask) {
  6006.  
  6007. if (idx === 0) {
  6008.  
  6009. for (const pneItem of pneItems) {
  6010.  
  6011. taskPerPneItem(pneItem);
  6012. }
  6013. } else {
  6014. // skip
  6015.  
  6016. }
  6017. } else {
  6018.  
  6019.  
  6020. taskPerPneItem(pneItem);
  6021.  
  6022. }
  6023.  
  6024. });
  6025.  
  6026.  
  6027. });
  6028.  
  6029.  
  6030. // if(!useNative)
  6031. stamperTasks.push(() => {
  6032. if (taskFinish) return;
  6033. if (skipToNextTask) return;
  6034. // if (skipToNextTask) return;
  6035. let node = refNode;
  6036. if (!node) return;
  6037. node = node.nextElementSibling;
  6038. while (node) {
  6039. let nextNode = node.nextElementSibling;
  6040. removeTNode(node);
  6041. registerFn(node, '02');
  6042. node = nextNode;
  6043. }
  6044. });
  6045.  
  6046.  
  6047.  
  6048. // if(useNative && stamperTasks.length === 0){
  6049.  
  6050.  
  6051. // this.stampDomArray9682_(...arguments);
  6052. // return;
  6053.  
  6054. // }
  6055.  
  6056.  
  6057. // if (useNative) {
  6058.  
  6059. // useSyncE = true;
  6060.  
  6061. // stamperTasks.push(() => {
  6062.  
  6063. // if (taskFinish) return;
  6064. // // if (skipToNextTask) return;
  6065.  
  6066. // // safeFn0(items__, containerId, componentConfig, false, bEventCallback, false);
  6067. // // safeFn(pneItems.map(e => e.item), containerId, componentConfig, false, bEventCallback, false)
  6068.  
  6069. // // this.stampDomArray9682_(items_, containerId, componentConfig, false, bEventCallback, false);
  6070. // // this.stampDomArray9682_(pneItems.map(e => e.item), containerId, componentConfig, false, bEventCallback, false);
  6071.  
  6072.  
  6073. // safeFn0(pneItems.map(e => e.item), containerId, componentConfig, bReuseComponent, bEventCallback, bStableList);
  6074. // // this.stampDomArray9682_(pneItems.map(e => e.item), containerId, componentConfig, bReuseComponent, bEventCallback, bStableList);
  6075.  
  6076. // // this.stampDomArray9682_(...arguments);
  6077. // })
  6078.  
  6079. // }
  6080.  
  6081.  
  6082.  
  6083. stamperTasks.push(() => {
  6084.  
  6085.  
  6086. if (!skipToNextTask) {
  6087.  
  6088. safeFinish(containerId, bEventCallback);
  6089. }
  6090.  
  6091. });
  6092.  
  6093.  
  6094. this[keyRequireAsync] = (this[keyRequireAsync] || 0) + 1;
  6095.  
  6096.  
  6097. stamperTasks.push(() => {
  6098.  
  6099. if (!skipToNextTask) {
  6100.  
  6101. this.__rendererStamperFinishFn588__();
  6102. }
  6103.  
  6104. this[keyRequireAsync] = (this[keyRequireAsync] || 0) - 1;
  6105.  
  6106. });
  6107.  
  6108.  
  6109. if(
  6110. // useNative &&
  6111. !leaveWithNoChange) {
  6112. disableTaskSkip = true;
  6113.  
  6114. const tasks = stamperTasks.slice();
  6115. stamperTasks.length = 0;
  6116.  
  6117. for (const task of tasks) {
  6118. task();
  6119. }
  6120. return;
  6121. }
  6122.  
  6123. if (useSync_) {
  6124.  
  6125. disableTaskSkip = true;
  6126.  
  6127. // [[ FOR CRITICAL TASK ]]
  6128.  
  6129. // if (!this[keyOnSync]) this[keyOnSync] = 0;
  6130. // this[keyOnSync]++;
  6131.  
  6132. // const pr = marcoPr;
  6133. // console.log(2992, pr, trackMarcoCm.data)
  6134. // trackMarcoCm.data = `${(trackMarcoCm.data & 7) + 1}`;
  6135. // pr.then(() => {
  6136. // this[keyOnSync]--;
  6137. // // console.log(3992, this.is);
  6138. // });
  6139.  
  6140. const tasks = stamperTasks.slice();
  6141. stamperTasks.length = 0;
  6142.  
  6143. for (const task of tasks) {
  6144. task();
  6145. }
  6146.  
  6147. if (!withStampDomExx && useSyncE && this.is === pageFirstDom) {
  6148. // we treat the components generated by initial stampDom as important
  6149.  
  6150. for (const elm of document.getElementsByTagName('*')) {
  6151. if (elm.is) {
  6152. insp(elm).__stampDomExx__ = true;
  6153. // emComponents.add(elm.is);
  6154. }
  6155. }
  6156. withStampDomExx = true;
  6157. }
  6158.  
  6159. } else {
  6160.  
  6161. if (!hasRunningTasks) {
  6162.  
  6163. const f = () => {
  6164. if (!stamperTasks.length) return;
  6165. const tasks = stamperTasks.slice();
  6166. stamperTasks.length = 0;
  6167. executeTaskBatch(tasks.map(fn => ({ fn })), false);
  6168. }
  6169.  
  6170. if (tryBatchUpdate_) {
  6171. nextBrowserTick_(f);// collecting all tasks (after reflow)
  6172. } else {
  6173. queueMicrotask_(f); // collecting some tasks (before reflow)
  6174. }
  6175.  
  6176. }
  6177.  
  6178. }
  6179.  
  6180. return;
  6181.  
  6182.  
  6183.  
  6184.  
  6185.  
  6186. }
  6187.  
  6188. return gn;
  6189.  
  6190. };
  6191.  
  6192.  
  6193. const setupDiscreteTasks = (h, rb) => {
  6194.  
  6195.  
  6196.  
  6197. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  6198. const f = h.onYtRendererstamperFinished;
  6199. const g = ump3.get(f) || function () {
  6200. if (this.updateChildVisibilityProperties && !this.markDirty) {
  6201. return f.apply(this, arguments);
  6202. }
  6203. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6204. }
  6205. ump3.set(f, g);
  6206. g.km34 = 1;
  6207. h.onYtRendererstamperFinished = g;
  6208.  
  6209. }
  6210.  
  6211. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  6212. const f = h.onYtUpdateDescriptionAction;
  6213. const g = ump3.get(f) || function (a) {
  6214. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6215. }
  6216. ump3.set(f, g);
  6217. g.km34 = 1;
  6218. h.onYtUpdateDescriptionAction = g;
  6219.  
  6220. }
  6221.  
  6222. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  6223. const f = h.handleUpdateDescriptionAction;
  6224. const g = ump3.get(f) || function (a) {
  6225. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6226. }
  6227. ump3.set(f, g);
  6228. g.km34 = 1;
  6229. h.handleUpdateDescriptionAction = g;
  6230.  
  6231. }
  6232.  
  6233. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  6234. const f = h.handleUpdateLiveChatPollAction;
  6235. const g = ump3.get(f) || function (a) {
  6236. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6237. }
  6238. ump3.set(f, g);
  6239. g.km34 = 1;
  6240. h.handleUpdateLiveChatPollAction = g;
  6241.  
  6242. }
  6243.  
  6244. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  6245. const f = h.onTextChanged;
  6246. const g = ump3.get(f) || function () {
  6247. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6248. }
  6249. ump3.set(f, g);
  6250. g.km34 = 1;
  6251. h.onTextChanged = g;
  6252.  
  6253. }
  6254.  
  6255. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  6256. const f = h.onVideoDataChange;
  6257. const g = ump3.get(f) || function (a) {
  6258. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6259. }
  6260. ump3.set(f, g);
  6261. g.km34 = 1;
  6262. h.onVideoDataChange = g;
  6263.  
  6264. }
  6265.  
  6266. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  6267. const f = h.onVideoDataChange_;
  6268. const g = ump3.get(f) || function () {
  6269. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6270. }
  6271. ump3.set(f, g);
  6272. g.km34 = 1;
  6273. h.onVideoDataChange_ = g;
  6274.  
  6275. }
  6276.  
  6277. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  6278.  
  6279. const f = h.addTooltips_;
  6280. const g = ump3.get(f) || function () {
  6281. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6282. }
  6283. ump3.set(f, g);
  6284. g.km34 = 1;
  6285. h.addTooltips_ = g;
  6286.  
  6287. }
  6288.  
  6289. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  6290.  
  6291. const f = h.updateRenderedElements;
  6292. const g = ump3.get(f) || function () {
  6293. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6294. }
  6295. ump3.set(f, g);
  6296. g.km34 = 1;
  6297. h.updateRenderedElements = g;
  6298.  
  6299. }
  6300.  
  6301. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  6302. const f = h.loadPage_;
  6303. const g = ump3.get(f) || function (a) {
  6304. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6305. }
  6306. ump3.set(f, g);
  6307. g.km34 = 1;
  6308. h.loadPage_ = g;
  6309.  
  6310. }
  6311. // updatePageData_ : possible conflict with Omit ShadyDOM
  6312. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  6313. const f = h.updatePageData_;
  6314. const g = ump3.get(f) || function (a) {
  6315. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6316. }
  6317. ump3.set(f, g);
  6318. g.km34 = 1;
  6319. h.updatePageData_ = g;
  6320.  
  6321. }
  6322.  
  6323.  
  6324. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  6325.  
  6326. const f = h.onFocus_;
  6327. const g = ump3.get(f) || function () {
  6328. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6329. }
  6330. ump3.set(f, g);
  6331. g.km34 = 1;
  6332. h.onFocus_ = g;
  6333.  
  6334. }
  6335.  
  6336. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  6337.  
  6338. const f = h.onBlur_;
  6339. const g = ump3.get(f) || function () {
  6340. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6341. }
  6342. ump3.set(f, g);
  6343. g.km34 = 1;
  6344. h.onBlur_ = g;
  6345.  
  6346. }
  6347.  
  6348.  
  6349. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  6350.  
  6351. const f = h.buttonClassChanged_;
  6352. const g = ump3.get(f) || function (a, b) {
  6353. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6354. }
  6355. ump3.set(f, g);
  6356. g.km34 = 1;
  6357. h.buttonClassChanged_ = g;
  6358.  
  6359. }
  6360.  
  6361. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  6362.  
  6363. const f = h.buttonIconChanged_;
  6364. const g = ump3.get(f) || function (a) {
  6365. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6366. }
  6367. ump3.set(f, g);
  6368. g.km34 = 1;
  6369. h.buttonIconChanged_ = g;
  6370.  
  6371. }
  6372.  
  6373. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  6374.  
  6375. const f = h.dataChangedInBehavior_;
  6376. const g = ump3.get(f) || function () {
  6377. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6378. }
  6379. ump3.set(f, g);
  6380. g.km34 = 1;
  6381. h.dataChangedInBehavior_ = g;
  6382.  
  6383. }
  6384.  
  6385. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  6386.  
  6387. const f = h.continuationsChanged_;
  6388. const g = ump3.get(f) || function () {
  6389. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6390. }
  6391. ump3.set(f, g);
  6392. g.km34 = 1;
  6393. h.continuationsChanged_ = g;
  6394.  
  6395. }
  6396.  
  6397.  
  6398. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  6399.  
  6400. const f = h.forceChatPoll_;
  6401. const g = ump3.get(f) || function (a) {
  6402. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6403. }
  6404. ump3.set(f, g);
  6405. g.km34 = 1;
  6406. h.forceChatPoll_ = g;
  6407.  
  6408. }
  6409.  
  6410. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  6411.  
  6412. const f = h.onEndpointClick_;
  6413. const g = ump3.get(f) || function (a) {
  6414. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6415. }
  6416. ump3.set(f, g);
  6417. g.km34 = 1;
  6418. h.onEndpointClick_ = g;
  6419.  
  6420. }
  6421.  
  6422. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  6423.  
  6424. const f = h.onEndpointTap_;
  6425. const g = ump3.get(f) || function (a) {
  6426. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6427. }
  6428. ump3.set(f, g);
  6429. g.km34 = 1;
  6430. h.onEndpointTap_ = g;
  6431.  
  6432. }
  6433.  
  6434. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  6435.  
  6436. const f = h.handleClick_;
  6437. const g = ump3.get(f) || function (a, b) {
  6438. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6439. }
  6440. ump3.set(f, g);
  6441. g.km34 = 1;
  6442. h.handleClick_ = g;
  6443.  
  6444. }
  6445.  
  6446. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  6447.  
  6448. const f = h.onReadyStateChange_;
  6449. const g = ump3.get(f) || function () {
  6450. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6451. }
  6452. ump3.set(f, g);
  6453. g.km34 = 1;
  6454. h.onReadyStateChange_ = g;
  6455.  
  6456. }
  6457.  
  6458. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  6459.  
  6460. const f = h.onReadyStateChangeEntryPoint_;
  6461. const g = ump3.get(f) || function () {
  6462. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6463. }
  6464. ump3.set(f, g);
  6465. g.km34 = 1;
  6466. h.onReadyStateChangeEntryPoint_ = g;
  6467.  
  6468. }
  6469.  
  6470. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  6471.  
  6472. const f = h.readyStateChangeHandler_;
  6473. const g = ump3.get(f) || function (a) {
  6474. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6475. }
  6476. ump3.set(f, g);
  6477. g.km34 = 1;
  6478. h.readyStateChangeHandler_ = g;
  6479.  
  6480. }
  6481.  
  6482. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  6483.  
  6484. const f = h.xmlHttpHandler_;
  6485. const g = ump3.get(f) || function (a) {
  6486. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6487. }
  6488. ump3.set(f, g);
  6489. g.km34 = 1;
  6490. h.xmlHttpHandler_ = g;
  6491.  
  6492. }
  6493.  
  6494. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  6495.  
  6496. const f = h.executeCallbacks_; // overloaded
  6497. const g = ump3.get(f) || function (a) {
  6498. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6499. }
  6500. ump3.set(f, g);
  6501. g.km34 = 1;
  6502. h.executeCallbacks_ = g;
  6503.  
  6504. }
  6505.  
  6506. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  6507.  
  6508. const f = h.handleInvalidationData_;
  6509. const g = ump3.get(f) || function (a, b) {
  6510. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6511. }
  6512. ump3.set(f, g);
  6513. g.km34 = 1;
  6514. h.handleInvalidationData_ = g;
  6515.  
  6516. }
  6517.  
  6518. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  6519.  
  6520. const f = h.onInput_;
  6521. const g = ump3.get(f) || function () {
  6522. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6523. }
  6524. ump3.set(f, g);
  6525. g.km34 = 1;
  6526. h.onInput_ = g;
  6527.  
  6528. }
  6529. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  6530.  
  6531. const f = h.trigger_;
  6532. const g = ump3.get(f) || function (a) {
  6533. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6534. }
  6535. ump3.set(f, g);
  6536. g.km34 = 1;
  6537. h.trigger_ = g;
  6538.  
  6539. }
  6540.  
  6541. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  6542.  
  6543. const f = h.requestData_;
  6544. const g = ump3.get(f) || function (a) {
  6545. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6546. }
  6547. ump3.set(f, g);
  6548. g.km34 = 1;
  6549. h.requestData_ = g;
  6550.  
  6551. }
  6552.  
  6553. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  6554.  
  6555. const f = h.onLoadReloadContinuation_;
  6556. const g = ump3.get(f) || function (a, b) {
  6557. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6558. }
  6559. ump3.set(f, g);
  6560. g.km34 = 1;
  6561. h.onLoadReloadContinuation_ = g;
  6562.  
  6563. }
  6564.  
  6565. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  6566.  
  6567. const f = h.onLoadIncrementalContinuation_;
  6568. const g = ump3.get(f) || function (a, b) {
  6569. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6570. }
  6571. ump3.set(f, g);
  6572. g.km34 = 1;
  6573. h.onLoadIncrementalContinuation_ = g;
  6574.  
  6575. }
  6576.  
  6577. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  6578.  
  6579. const f = h.onLoadSeekContinuation_;
  6580. const g = ump3.get(f) || function (a, b) {
  6581. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6582. }
  6583. ump3.set(f, g);
  6584. g.km34 = 1;
  6585. h.onLoadSeekContinuation_ = g;
  6586.  
  6587. }
  6588. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  6589.  
  6590. const f = h.onLoadReplayContinuation_;
  6591. const g = ump3.get(f) || function (a, b) {
  6592. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6593. }
  6594. ump3.set(f, g);
  6595. g.km34 = 1;
  6596. h.onLoadReplayContinuation_ = g;
  6597.  
  6598. }
  6599. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  6600.  
  6601. const f = h.onNavigate_;
  6602. const g = ump3.get(f) || function (a) {
  6603. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6604. }
  6605. ump3.set(f, g);
  6606. g.km34 = 1;
  6607. h.onNavigate_ = g;
  6608.  
  6609. }
  6610.  
  6611. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  6612.  
  6613. const f = h.ytRendererBehaviorDataObserver_;
  6614. const g = ump3.get(f) || function () {
  6615. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6616. }
  6617. ump3.set(f, g);
  6618. g.km34 = 1;
  6619. h.ytRendererBehaviorDataObserver_ = g;
  6620.  
  6621. }
  6622.  
  6623. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  6624.  
  6625. const f = h.ytRendererBehaviorTargetIdObserver_;
  6626. const g = ump3.get(f) || function () {
  6627. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6628. }
  6629. ump3.set(f, g);
  6630. g.km34 = 1;
  6631. h.ytRendererBehaviorTargetIdObserver_ = g;
  6632.  
  6633. }
  6634.  
  6635. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  6636.  
  6637. const f = h.unregisterRenderer_;
  6638. const g = ump3.get(f) || function (a) {
  6639. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6640. }
  6641. ump3.set(f, g);
  6642. g.km34 = 1;
  6643. h.unregisterRenderer_ = g;
  6644.  
  6645. }
  6646.  
  6647. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  6648.  
  6649. const f = h.textChanged_;
  6650. const g = ump3.get(f) || function (a) {
  6651. if (void 0 !== this.isAttached) {
  6652. const hostElement = this.hostElement;
  6653. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  6654. return;
  6655. }
  6656. }
  6657. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6658. }
  6659. ump3.set(f, g);
  6660. g.km34 = 1;
  6661. h.textChanged_ = g;
  6662.  
  6663. }
  6664.  
  6665.  
  6666.  
  6667. /**
  6668. *
  6669. * Neglect following
  6670. *
  6671. * h.onYtAction_
  6672. * h.startLoadingWatch [ buggy for yt-player-updated ]
  6673. * h.deferRenderStamperBinding_
  6674. *
  6675. * h.stampDomArray_
  6676. * h.stampDomArraySplices_
  6677. *
  6678. */
  6679.  
  6680.  
  6681. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  6682. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  6683. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  6684. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  6685. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  6686. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  6687.  
  6688. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  6689.  
  6690. const f = h.searchChanged_;
  6691. const g = ump3.get(f) || function () {
  6692. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6693. }
  6694. ump3.set(f, g);
  6695. g.km34 = 1;
  6696. h.searchChanged_ = g;
  6697.  
  6698. }
  6699.  
  6700. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  6701.  
  6702. const f = h.skinToneChanged_;
  6703. const g = ump3.get(f) || function (a) {
  6704. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6705. }
  6706. ump3.set(f, g);
  6707. g.km34 = 1;
  6708. h.skinToneChanged_ = g;
  6709.  
  6710. }
  6711.  
  6712. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  6713.  
  6714. const f = h.onEmojiHover_;
  6715. const g = ump3.get(f) || function (a) {
  6716. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6717. }
  6718. ump3.set(f, g);
  6719. g.km34 = 1;
  6720. h.onEmojiHover_ = g;
  6721.  
  6722. }
  6723.  
  6724. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  6725.  
  6726. const f = h.onSelectCategory_;
  6727. const g = ump3.get(f) || function (a) {
  6728. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6729. }
  6730. ump3.set(f, g);
  6731. g.km34 = 1;
  6732. h.onSelectCategory_ = g;
  6733.  
  6734. }
  6735.  
  6736. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  6737.  
  6738. const f = h.onShowEmojiVariantSelector;
  6739. const g = ump3.get(f) || function (a) {
  6740. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6741. }
  6742. ump3.set(f, g);
  6743. g.km34 = 1;
  6744. h.onShowEmojiVariantSelector = g;
  6745.  
  6746. }
  6747.  
  6748. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  6749.  
  6750. const f = h.updateCategoriesAndPlaceholder_;
  6751. const g = ump3.get(f) || function () {
  6752. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6753. }
  6754. ump3.set(f, g);
  6755. g.km34 = 1;
  6756. h.updateCategoriesAndPlaceholder_ = g;
  6757.  
  6758. }
  6759.  
  6760. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  6761.  
  6762. const f = h.watchPageActiveChanged_;
  6763. const g = ump3.get(f) || function () {
  6764. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6765. }
  6766. ump3.set(f, g);
  6767. g.km34 = 1;
  6768. h.watchPageActiveChanged_ = g;
  6769.  
  6770. }
  6771.  
  6772. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  6773.  
  6774. const f = h.activate_;
  6775. const g = ump3.get(f) || function () {
  6776. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6777. }
  6778. ump3.set(f, g);
  6779. g.km34 = 1;
  6780. h.activate_ = g;
  6781.  
  6782. }
  6783. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  6784.  
  6785. const f = h.onYtPlaylistDataUpdated_;
  6786. const g = ump3.get(f) || function () {
  6787. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6788. }
  6789. ump3.set(f, g);
  6790. g.km34 = 1;
  6791. h.onYtPlaylistDataUpdated_ = g;
  6792.  
  6793. }
  6794.  
  6795.  
  6796.  
  6797. /**
  6798. *
  6799. * Neglect following
  6800. *
  6801. * h.rendererStamperObserver_
  6802. * h.rendererStamperApplyChangeRecord_
  6803. * h.flushRenderStamperComponentBindings_
  6804. * h.forwardRendererStamperChanges_
  6805. *
  6806. */
  6807.  
  6808. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  6809.  
  6810. const f = h.tryRenderChunk_;
  6811. const g = ump3.get(f) || function () {
  6812. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6813. }
  6814. ump3.set(f, g);
  6815. g.km34 = 1;
  6816. h.tryRenderChunk_ = g;
  6817.  
  6818. }
  6819.  
  6820.  
  6821. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  6822.  
  6823. const f = h.renderChunk_;
  6824. const g = ump3.get(f) || function () {
  6825. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6826. }
  6827. ump3.set(f, g);
  6828. g.km34 = 1;
  6829. h.renderChunk_ = g;
  6830.  
  6831. }
  6832.  
  6833. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  6834.  
  6835. const f = h.deepLazyListObserver_;
  6836. const g = ump3.get(f) || function () {
  6837. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6838. }
  6839. ump3.set(f, g);
  6840. g.km34 = 1;
  6841. h.deepLazyListObserver_ = g;
  6842.  
  6843. }
  6844.  
  6845. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  6846.  
  6847. const f = h.onItemsUpdated_;
  6848. const g = ump3.get(f) || function () {
  6849. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6850. }
  6851. ump3.set(f, g);
  6852. g.km34 = 1;
  6853. h.onItemsUpdated_ = g;
  6854.  
  6855. }
  6856.  
  6857. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  6858.  
  6859. const f = h.requestRenderChunk_;
  6860. const g = ump3.get(f) || function () {
  6861. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6862. }
  6863. ump3.set(f, g);
  6864. g.km34 = 1;
  6865. h.requestRenderChunk_ = g;
  6866.  
  6867. }
  6868.  
  6869. /**
  6870. *
  6871. * Neglect following
  6872. *
  6873. * h.dataChanged_ [ buggy for page swtiching ]
  6874. *
  6875. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  6876. *
  6877. * h.cancelPendingTasks_
  6878. * h.fillRange_
  6879. * h.addTextNodes_
  6880. * h.updateText_
  6881. * h.stampTypeChanged_
  6882. *
  6883. */
  6884.  
  6885.  
  6886. }
  6887.  
  6888. const keyStConnectedCallback = Symbol(); // avoid copying the value
  6889.  
  6890. // const keyStDisconnectedCallback = Symbol(); // avoid copying the value
  6891. const cmf = new WeakMap();
  6892. const dmf = new WeakMap();
  6893.  
  6894. const gvGenerator = (nv) => {
  6895. return function () {
  6896. const cnt = insp(this);
  6897. const hostElement = cnt.hostElement || 0;
  6898. const dollar = hostElement ? (this.$ || indr(this)) : 0;
  6899. let p = (hostElement instanceof HTMLElement) && (dollar || !this.is);
  6900. if (p && (!dollar && !this.is)) {
  6901. const nodeName = hostElement.nodeName;
  6902. if (typeof nodeName !== 'string') {
  6903. // just in case
  6904. } else if (nodeName.startsWith("DOM-")) {
  6905. // dom-if, dom-repeat, etc
  6906. } else {
  6907. // yt element - new model, yt-xxxx, anixxxxxx
  6908. p = false;
  6909. }
  6910. }
  6911. if (p) {
  6912. if (typeof cnt.markDirty === 'function') {
  6913. // the yt element might call markDirty (occasionally)
  6914. p = false;
  6915. } else if (this.is === 'ytd-engagement-panel-section-list-renderer') {
  6916. // see https://github.com/cyfung1031/userscript-supports/issues/20
  6917. p = false;
  6918. }
  6919. }
  6920. if (p) {
  6921.  
  6922. // << dom-repeat & dom-if >>
  6923.  
  6924. // sequence on the same instance
  6925. this[qm57] = (this[qm57] || Promise.resolve()).then(() => nv.apply(this, arguments)).catch(console.log);
  6926. } else {
  6927. nv.apply(this, arguments);
  6928. }
  6929. };
  6930. }
  6931.  
  6932. // const assignedHolderWS = new WeakSet();
  6933.  
  6934. const setupWeakRef = (h) => {
  6935.  
  6936.  
  6937. }
  6938.  
  6939.  
  6940. let nativeHTMLElement = window.HTMLElement;
  6941.  
  6942. try {
  6943.  
  6944. const q = document.createElement('template');
  6945. q.innerHTML = '<ytz-null361></ytz-null361>';
  6946. nativeHTMLElement = q.content.firstChild.constructor
  6947.  
  6948. } catch (e) { }
  6949.  
  6950. if (!nativeHTMLElement.prototype.connectedCallback) {
  6951. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  6952. nativeHTMLElement.prototype.connectedCallback = function () {
  6953. let r;
  6954. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  6955. return r;
  6956. }
  6957. }
  6958. const pvr = Symbol()
  6959.  
  6960. let stampDomArrayMethod = null;
  6961. const setupMap = new WeakSet();
  6962.  
  6963. // const ENABLE_weakenStampReferencesQ = ENABLE_weakenStampReferences && typeof DocumentTimeline !== 'undefined' && typeof WeakRef !== 'undefined';
  6964. const setupYtComponent = (cnt) => {
  6965. const cProto = (cnt || 0).__proto__ || 0;
  6966. if (!cProto || setupMap.has(cProto)) return;
  6967. setupMap.add(cProto);
  6968. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  6969. cProto[pvr] |= 1;
  6970. if (FIX_stampDomArray && cProto.stampDomArray_ && !cProto.stampDomArray9682_) {
  6971. if (!stampDomArrayMethod) stampDomArrayMethod = createStampDomArrayFn_();
  6972. cProto.stampDomArray9682_ = cProto.stampDomArray_;
  6973. cProto.stampDomArray_ = stampDomArrayMethod;
  6974. }
  6975. }
  6976. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  6977. cProto[pvr] |= 2;
  6978. setupDiscreteTasks(cProto);
  6979. }
  6980. };
  6981.  
  6982. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  6983. get() {
  6984. const f = this[keyStConnectedCallback];
  6985. if (this.is) {
  6986. setupYtComponent(this);
  6987. }
  6988. /*
  6989. if (this.is) {
  6990. setupDiscreteTasks(this, true);
  6991. if (f) this.ky36 = 1;
  6992. }
  6993. */
  6994. return f;
  6995. },
  6996. set(nv) {
  6997. let gv = nv;
  6998. /*
  6999. if (typeof nv === 'function') {
  7000.  
  7001. gv = cmf.get(nv) || gvGenerator(nv);
  7002. if (gv !== nv) {
  7003. cmf.set(nv, gv);
  7004. cmf.set(gv, gv);
  7005. dmf.set(gv, nv);
  7006. }
  7007.  
  7008. } else {
  7009. gv = nv;
  7010. }
  7011. */
  7012. this[keyStConnectedCallback] = gv; // proto or object
  7013. /*
  7014. if (this.is) {
  7015. setupDiscreteTasks(this);
  7016. }
  7017. */
  7018. return true;
  7019. },
  7020. enumerable: false,
  7021. configurable: true
  7022.  
  7023. });
  7024.  
  7025. const pLoad = new Promise(resolve => {
  7026. if (document.readyState !== 'loading') {
  7027. resolve();
  7028. } else {
  7029. window.addEventListener("DOMContentLoaded", resolve, false);
  7030. }
  7031. });
  7032.  
  7033. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  7034. window.requestIdleCallback471 = window.requestIdleCallback;
  7035. window.requestIdleCallback = function (f, ...args) {
  7036. return (this || window).requestIdleCallback471(async function () {
  7037. await pLoad.then();
  7038. // await new Promise(nextBrowserTick_);
  7039. f.call(this, ...arguments)
  7040. }, ...args);
  7041. }
  7042. }
  7043.  
  7044. pLoad.then(() => {
  7045.  
  7046. let nonce = document.querySelector('style[nonce]');
  7047. nonce = nonce ? nonce.getAttribute('nonce') : null;
  7048. const st = document.createElement('style');
  7049. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  7050. st.textContent = "none-element-k47{order:0}";
  7051. st.addEventListener('load', () => {
  7052. pf31.resolve();
  7053. p59 = 1;
  7054. }, false);
  7055. (document.body || document.head || document.documentElement).appendChild(st);
  7056.  
  7057. });
  7058.  
  7059. const prepareLogs = [];
  7060.  
  7061. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  7062.  
  7063. let winError00 = window.onerror;
  7064.  
  7065. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  7066.  
  7067. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  7068.  
  7069. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  7070.  
  7071. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  7072. const lcOpt = { sensitivity: 'base' };
  7073. document.createElement24 = document.createElement;
  7074. document.createElement = function (t) {
  7075. if (typeof t === 'string' && t.length === 6) {
  7076. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  7077. const p = this.createElement24(t);
  7078. try {
  7079. const stack = new Error().stack;
  7080. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greasyfork.org/scripts/473972-youtube-js-engine-tamer/discussions/217084
  7081. if (!isSearchbox) {
  7082. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  7083. }
  7084. } catch (e) { }
  7085. return p;
  7086. }
  7087. }
  7088. return this.createElement24.apply(this, arguments);
  7089. };
  7090.  
  7091. })();
  7092.  
  7093. ; fix_error_many_stack_state === 1 && (() => {
  7094.  
  7095.  
  7096. let p1 = winError00;
  7097.  
  7098. let stackNeedleDetails = null;
  7099.  
  7100. Object.defineProperty(Object.prototype, 'matchAll', {
  7101. get() {
  7102. stackNeedleDetails = this;
  7103. return true;
  7104. },
  7105. enumerable: true,
  7106. configurable: true
  7107. });
  7108.  
  7109. try {
  7110. JSON.parse("{}");
  7111. } catch (e) {
  7112. console.warn(e)
  7113. fix_error_many_stack_state = 0;
  7114. }
  7115.  
  7116. delete Object.prototype['matchAll'];
  7117.  
  7118. let p2 = window.onerror;
  7119.  
  7120. window.onerror = p1;
  7121.  
  7122. if (fix_error_many_stack_state === 0) return;
  7123.  
  7124. if (stackNeedleDetails) {
  7125. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7126. stackNeedleDetails.matchAll = true;
  7127. }
  7128.  
  7129. if (p1 === p2) return (fix_error_many_stack_state = 0);
  7130.  
  7131. // p1!==p2
  7132. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  7133.  
  7134. })();
  7135.  
  7136. ; fix_error_many_stack_state === 2 && (() => {
  7137.  
  7138.  
  7139. let p1 = winError00;
  7140.  
  7141. let objectPrune = null;
  7142. let stackNeedleDetails = null;
  7143.  
  7144. Object.defineProperty(Function.prototype, 'findOwner', {
  7145. get() {
  7146. objectPrune = this;
  7147. return this._findOwner;
  7148. },
  7149. set(nv) {
  7150. this._findOwner = nv;
  7151. return true;
  7152. },
  7153. enumerable: true,
  7154. configurable: true
  7155. });
  7156.  
  7157. Object.defineProperty(Object.prototype, 'matchAll', {
  7158. get() {
  7159. stackNeedleDetails = this;
  7160. return true;
  7161. },
  7162. enumerable: true,
  7163. configurable: true
  7164. });
  7165.  
  7166. try {
  7167. JSON.parse("{}");
  7168. } catch (e) {
  7169. console.warn(e)
  7170. fix_error_many_stack_state = 0;
  7171. }
  7172.  
  7173. delete Function.prototype['findOwner'];
  7174. delete Object.prototype['matchAll'];
  7175.  
  7176. let p2 = window.onerror;
  7177.  
  7178. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  7179.  
  7180. if (fix_error_many_stack_state == 0) return;
  7181.  
  7182. // the following will only execute when Brave's scriptlets.js is executed.
  7183.  
  7184. prepareLogs.push("fix_error_many_stack_state NB")
  7185.  
  7186. if (stackNeedleDetails) {
  7187. stackNeedleDetails.pattern = null;
  7188. stackNeedleDetails.re = null;
  7189. stackNeedleDetails.expect = null;
  7190. stackNeedleDetails.matchAll = true;
  7191. }
  7192.  
  7193. if (objectPrune) {
  7194. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  7195. delete objectPrune._findOwner;
  7196. }
  7197.  
  7198. fix_error_many_stack_state = 3;
  7199. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7200. JSON.parse.objectPrune = objectPrune;
  7201.  
  7202. })();
  7203.  
  7204. ; fix_error_many_stack_state === 3 && (() => {
  7205.  
  7206.  
  7207. let p1 = winError00;
  7208.  
  7209. try {
  7210. JSON.parse("{}");
  7211. } catch (e) {
  7212. console.warn(e)
  7213. fix_error_many_stack_state = 0;
  7214. }
  7215.  
  7216. let p2 = window.onerror;
  7217.  
  7218. if (p1 === p2) return;
  7219.  
  7220. window.onerror = p1;
  7221.  
  7222. if (fix_error_many_stack_state === 0) return;
  7223.  
  7224. fix_error_many_stack_state = 4; // p1 != p2
  7225.  
  7226.  
  7227. })();
  7228.  
  7229. fix_error_many_stack_state === 4 && (() => {
  7230.  
  7231. // the following will only execute when Brave's scriptlets.js is executed.
  7232.  
  7233. prepareLogs.push("fix_error_many_stack_state AB")
  7234.  
  7235. JSON.parseProxy = JSON.parse;
  7236.  
  7237. JSON.parse = ((parse) => {
  7238.  
  7239. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  7240. return function (text, reviver) {
  7241. const onerror = window.onerror;
  7242. window.onerror = null;
  7243. let r;
  7244. try {
  7245. r = parse(...arguments);
  7246. } catch (e) {
  7247. r = e;
  7248. }
  7249. window.onerror = onerror;
  7250. if (r instanceof Error) {
  7251. throw r;
  7252. }
  7253. return r;
  7254. }
  7255.  
  7256. })(JSON.parse);
  7257.  
  7258.  
  7259. })();
  7260.  
  7261.  
  7262. // << if FIX_yt_player >>
  7263.  
  7264. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  7265. const PERF_471489_ = true;
  7266. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  7267. // This script uses a much gentle way to tamer the JS engine instead.
  7268.  
  7269. // << end >>
  7270.  
  7271. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  7272.  
  7273.  
  7274.  
  7275. const nilFn = () => { };
  7276.  
  7277. let isMainWindow = false;
  7278. try {
  7279. isMainWindow = window.document === window.top.document
  7280. } catch (e) { }
  7281.  
  7282. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  7283. let headLinkCollection = null;
  7284.  
  7285.  
  7286. // const assertor = (f) => f() || console.assert(false, `${f}`);
  7287.  
  7288. const fnIntegrity = (f, d) => {
  7289. if (!f || typeof f !== 'function') {
  7290. console.warn('f is not a function', f);
  7291. return;
  7292. }
  7293. let p = `${f}`, s = 0, j = -1, w = 0;
  7294. for (let i = 0, l = p.length; i < l; i++) {
  7295. const t = p[i];
  7296. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  7297. if (j < i - 1) w++;
  7298. j = i;
  7299. } else {
  7300. s++;
  7301. }
  7302. }
  7303. let itz = `${f.length}.${s}.${w}`;
  7304. if (!d) {
  7305. return itz;
  7306. } else {
  7307. return itz === d;
  7308. }
  7309. };
  7310.  
  7311. const getZqOu = (_yt_player) => {
  7312.  
  7313. const w = 'ZqOu';
  7314.  
  7315. let arr = [];
  7316.  
  7317. for (const [k, v] of Object.entries(_yt_player)) {
  7318.  
  7319. const p = typeof v === 'function' ? v.prototype : 0;
  7320. if (p
  7321. && typeof p.start === 'function' && p.start.length === 0 // Ou
  7322. && typeof p.isActive === 'function' && p.isActive.length === 0
  7323. && typeof p.stop === 'function' && p.stop.length === 0
  7324. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7325. && !p.send && !p.abort
  7326. && !p.sample && !p.initialize && !p.fail && !p.getName
  7327. // && !p.dispose && !p.isDisposed
  7328.  
  7329. ) {
  7330. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7331.  
  7332.  
  7333. }
  7334.  
  7335. }
  7336.  
  7337. if (arr.length === 0) {
  7338.  
  7339. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7340. } else {
  7341.  
  7342. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7343. return arr[0];
  7344. }
  7345.  
  7346. }
  7347.  
  7348. const getZqQu = (_yt_player) => {
  7349.  
  7350. const w = 'ZqQu';
  7351.  
  7352. let arr = [];
  7353.  
  7354.  
  7355. for (const [k, v] of Object.entries(_yt_player)) {
  7356.  
  7357. const p = typeof v === 'function' ? v.prototype : 0;
  7358. if (p
  7359. && typeof p.start === 'function' && p.start.length === 1 // Qu
  7360. && typeof p.isActive === 'function' && p.isActive.length === 0
  7361. && typeof p.stop === 'function' && p.stop.length === 0
  7362. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7363. && !p.send && !p.abort
  7364. && !p.sample && !p.initialize && !p.fail && !p.getName
  7365. // && !p.dispose && !p.isDisposed
  7366.  
  7367. ) {
  7368. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7369.  
  7370.  
  7371. }
  7372.  
  7373. }
  7374.  
  7375. if (arr.length === 0) {
  7376.  
  7377. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7378. } else {
  7379.  
  7380. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7381. return arr[0];
  7382. }
  7383.  
  7384. }
  7385.  
  7386.  
  7387. const getVG = (_yt_player) => {
  7388. const w = 'VG';
  7389.  
  7390. let arr = [];
  7391.  
  7392. for (const [k, v] of Object.entries(_yt_player)) {
  7393.  
  7394. const p = typeof v === 'function' ? v.prototype : 0;
  7395. if (p
  7396. && typeof p.show === 'function' && p.show.length === 1
  7397. && typeof p.hide === 'function' && p.hide.length === 0
  7398. && typeof p.stop === 'function' && p.stop.length === 0) {
  7399.  
  7400. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7401.  
  7402. }
  7403.  
  7404. }
  7405.  
  7406.  
  7407. if (arr.length === 0) {
  7408.  
  7409. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7410. } else {
  7411.  
  7412. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7413. return arr[0];
  7414. }
  7415.  
  7416.  
  7417.  
  7418. }
  7419.  
  7420.  
  7421. const getzo = (_yt_player) => {
  7422. const w = 'zo';
  7423.  
  7424. let arr = [];
  7425.  
  7426. for (const [k, v] of Object.entries(_yt_player)) {
  7427.  
  7428. if (
  7429. typeof v === 'function' && v.length === 3 && k.length < 3
  7430. ) {
  7431. const vt = `${v}`;
  7432. if (vt.length >= 21 && vt.includes(".style[")) {
  7433. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  7434. arr.push(k);
  7435. } else {
  7436. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  7437. }
  7438. }
  7439. }
  7440.  
  7441. }
  7442.  
  7443. if (arr.length === 0) {
  7444.  
  7445. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7446. } else {
  7447.  
  7448. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7449. return arr[0];
  7450. }
  7451.  
  7452. }
  7453.  
  7454. const addProtoToArr = (parent, key, arr) => {
  7455.  
  7456.  
  7457. let isChildProto = false;
  7458. for (const sr of arr) {
  7459. if (parent[key].prototype instanceof parent[sr]) {
  7460. isChildProto = true;
  7461. break;
  7462. }
  7463. }
  7464.  
  7465. if (isChildProto) return;
  7466.  
  7467. arr = arr.filter(sr => {
  7468. if (parent[sr].prototype instanceof parent[key]) {
  7469. return false;
  7470. }
  7471. return true;
  7472. });
  7473.  
  7474. arr.push(key);
  7475.  
  7476. return arr;
  7477.  
  7478.  
  7479. }
  7480.  
  7481. const getuG = (_yt_player) => {
  7482.  
  7483. const w = 'uG';
  7484.  
  7485. let arr = [];
  7486.  
  7487. for (const [k, v] of Object.entries(_yt_player)) {
  7488.  
  7489.  
  7490. const p = typeof v === 'function' ? v.prototype : 0;
  7491.  
  7492. if (p
  7493. && typeof p.createElement === 'function' && p.createElement.length === 2
  7494. && typeof p.detach === 'function' && p.detach.length === 0
  7495. && typeof p.update === 'function' && p.update.length === 1
  7496. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  7497. ) {
  7498.  
  7499. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7500.  
  7501. }
  7502.  
  7503. }
  7504.  
  7505.  
  7506.  
  7507.  
  7508.  
  7509. if (arr.length === 0) {
  7510.  
  7511. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7512. } else {
  7513.  
  7514. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7515. return arr[0];
  7516. }
  7517.  
  7518. }
  7519.  
  7520.  
  7521. const getQT = (_yt_player) => {
  7522. const w = 'QT';
  7523.  
  7524. let arr = [];
  7525. let brr = new Map();
  7526.  
  7527. for (const [k, v] of Object.entries(_yt_player)) {
  7528.  
  7529. const p = typeof v === 'function' ? v.prototype : 0;
  7530. if (p) {
  7531. let q = 0;
  7532. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7533. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7534. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7535.  
  7536. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7537.  
  7538. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7539.  
  7540. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7541. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7542. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7543. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7544.  
  7545.  
  7546. // differentiate QT and DX
  7547.  
  7548. q += 280;
  7549. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  7550. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  7551. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  7552. if (typeof p.seekBy === 'function') q += 4;
  7553. if (typeof p.seekTo === 'function') q += 4;
  7554. if (typeof p.getStoryboardFormat === 'function') q += 4;
  7555. if (typeof p.getDuration === 'function') q += 4;
  7556. if (typeof p.loadModule === 'function') q += 4;
  7557. if (typeof p.unloadModule === 'function') q += 4;
  7558. if (typeof p.getOption === 'function') q += 4;
  7559. if (typeof p.getOptions === 'function') q += 4;
  7560. if (typeof p.setOption === 'function') q += 4;
  7561. if (typeof p.addCueRange === 'function') q += 4;
  7562. if (typeof p.getDebugText === 'function') q += 4;
  7563. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  7564. if (typeof p.setSizeStyle === 'function') q += 4;
  7565. if (typeof p.showControls === 'function') q += 4;
  7566. if (typeof p.hideControls === 'function') q += 4;
  7567. if (typeof p.getVideoContentRect === 'function') q += 4;
  7568. if (typeof p.toggleFullscreen === 'function') q += 4;
  7569. if (typeof p.isFullscreen === 'function') q += 4;
  7570. if (typeof p.cancelPlayback === 'function') q += 4;
  7571. if (typeof p.getProgressState === 'function') q += 4;
  7572. if (typeof p.isInline === 'function') q += 4;
  7573. if (typeof p.setInline === 'function') q += 4;
  7574. if (typeof p.toggleSubtitles === 'function') q += 4;
  7575. if (typeof p.getPlayerSize === 'function') q += 4;
  7576. if (typeof p.wakeUpControls === 'function') q += 4;
  7577. if (typeof p.setCenterCrop === 'function') q += 4;
  7578. if (typeof p.getLoopVideo === 'function') q += 4;
  7579. if (typeof p.setLoopVideo === 'function') q += 4;
  7580.  
  7581.  
  7582. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7583.  
  7584. if (q > 0) brr.set(k, q);
  7585.  
  7586. }
  7587.  
  7588. }
  7589.  
  7590. if (arr.length === 0) {
  7591.  
  7592. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7593. } else {
  7594.  
  7595. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7596.  
  7597. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7598.  
  7599. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7600. return arr[0][0];
  7601. }
  7602.  
  7603.  
  7604.  
  7605. }
  7606.  
  7607.  
  7608.  
  7609. const getSV = (_yt_player) => {
  7610. const w = 'SV';
  7611.  
  7612. let arr = [];
  7613. let brr = new Map();
  7614.  
  7615. for (const [k, v] of Object.entries(_yt_player)) {
  7616.  
  7617. const p = typeof v === 'function' ? v.prototype : 0;
  7618. if (p) {
  7619. let q = 0;
  7620. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7621. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7622. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7623.  
  7624. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  7625.  
  7626. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7627.  
  7628. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7629. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7630. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7631. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7632.  
  7633.  
  7634. // differentiate QT and DX
  7635.  
  7636.  
  7637. q += 280;
  7638.  
  7639. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7640. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7641. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7642. if (typeof p.seekBy === 'function') q -= 4;
  7643. if (typeof p.seekTo === 'function') q -= 4;
  7644. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7645. if (typeof p.getDuration === 'function') q -= 4;
  7646. if (typeof p.loadModule === 'function') q -= 4;
  7647. if (typeof p.unloadModule === 'function') q -= 4;
  7648. if (typeof p.getOption === 'function') q -= 4;
  7649. if (typeof p.getOptions === 'function') q -= 4;
  7650. if (typeof p.setOption === 'function') q -= 4;
  7651. if (typeof p.addCueRange === 'function') q -= 4;
  7652. if (typeof p.getDebugText === 'function') q -= 4;
  7653. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7654. if (typeof p.setSizeStyle === 'function') q -= 4;
  7655. if (typeof p.showControls === 'function') q -= 4;
  7656. if (typeof p.hideControls === 'function') q -= 4;
  7657. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7658. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7659. if (typeof p.isFullscreen === 'function') q -= 4;
  7660. if (typeof p.cancelPlayback === 'function') q -= 4;
  7661. if (typeof p.getProgressState === 'function') q -= 4;
  7662. if (typeof p.isInline === 'function') q -= 4;
  7663. if (typeof p.setInline === 'function') q -= 4;
  7664. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7665. if (typeof p.getPlayerSize === 'function') q -= 4;
  7666. if (typeof p.wakeUpControls === 'function') q -= 4;
  7667. if (typeof p.setCenterCrop === 'function') q -= 4;
  7668. if (typeof p.getLoopVideo === 'function') q -= 4;
  7669. if (typeof p.setLoopVideo === 'function') q -= 4;
  7670.  
  7671.  
  7672. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7673.  
  7674. if (q > 0) brr.set(k, q);
  7675.  
  7676. }
  7677.  
  7678. }
  7679.  
  7680. if (arr.length === 0) {
  7681.  
  7682. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7683. } else {
  7684.  
  7685. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7686.  
  7687. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7688.  
  7689. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7690. return arr[0][0];
  7691. }
  7692.  
  7693.  
  7694.  
  7695. }
  7696.  
  7697.  
  7698.  
  7699.  
  7700. const getDX = (_yt_player) => {
  7701. const w = 'DX';
  7702.  
  7703. let arr = [];
  7704. let brr = new Map();
  7705.  
  7706. for (const [k, v] of Object.entries(_yt_player)) {
  7707.  
  7708. const p = typeof v === 'function' ? v.prototype : 0;
  7709. if (p) {
  7710. let q = 0;
  7711. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7712. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7713. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7714.  
  7715. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7716.  
  7717.  
  7718. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  7719.  
  7720. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7721.  
  7722. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7723. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7724. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7725. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7726.  
  7727.  
  7728. // differentiate QT and DX
  7729.  
  7730.  
  7731. q += 280;
  7732.  
  7733. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7734. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7735. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7736. if (typeof p.seekBy === 'function') q -= 4;
  7737. if (typeof p.seekTo === 'function') q -= 4;
  7738. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7739. if (typeof p.getDuration === 'function') q -= 4;
  7740. if (typeof p.loadModule === 'function') q -= 4;
  7741. if (typeof p.unloadModule === 'function') q -= 4;
  7742. if (typeof p.getOption === 'function') q -= 4;
  7743. if (typeof p.getOptions === 'function') q -= 4;
  7744. if (typeof p.setOption === 'function') q -= 4;
  7745. if (typeof p.addCueRange === 'function') q -= 4;
  7746. if (typeof p.getDebugText === 'function') q -= 4;
  7747. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7748. if (typeof p.setSizeStyle === 'function') q -= 4;
  7749. if (typeof p.showControls === 'function') q -= 4;
  7750. if (typeof p.hideControls === 'function') q -= 4;
  7751. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7752. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7753. if (typeof p.isFullscreen === 'function') q -= 4;
  7754. if (typeof p.cancelPlayback === 'function') q -= 4;
  7755. if (typeof p.getProgressState === 'function') q -= 4;
  7756. if (typeof p.isInline === 'function') q -= 4;
  7757. if (typeof p.setInline === 'function') q -= 4;
  7758. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7759. if (typeof p.getPlayerSize === 'function') q -= 4;
  7760. if (typeof p.wakeUpControls === 'function') q -= 4;
  7761. if (typeof p.setCenterCrop === 'function') q -= 4;
  7762. if (typeof p.getLoopVideo === 'function') q -= 4;
  7763. if (typeof p.setLoopVideo === 'function') q -= 4;
  7764.  
  7765.  
  7766. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7767.  
  7768. if (q > 0) brr.set(k, q);
  7769.  
  7770. }
  7771.  
  7772. }
  7773.  
  7774. if (arr.length === 0) {
  7775.  
  7776. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7777. } else {
  7778.  
  7779. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7780.  
  7781. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7782.  
  7783. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7784. return arr[0][0];
  7785. }
  7786.  
  7787.  
  7788.  
  7789. }
  7790.  
  7791.  
  7792.  
  7793. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  7794.  
  7795. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  7796. let pageSetupState = 0;
  7797.  
  7798. isPrepareCachedV && (() => {
  7799.  
  7800. pageSetupVideoId = '';
  7801. const clearCachedV = () => {
  7802. pageSetupVideoId = '';
  7803. pageSetupState = 0;
  7804. }
  7805. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  7806. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  7807. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  7808. document.addEventListener('yt-navigate-finish', () => {
  7809. pageSetupState = 1;
  7810. try {
  7811. const url = new URL(location.href);
  7812. if (!url || !isWatchPageURL(url)) {
  7813. pageSetupVideoId = '';
  7814. } else {
  7815. pageSetupVideoId = url.searchParams.get('v') || '';
  7816. }
  7817. } catch (e) {
  7818. pageSetupVideoId = '';
  7819. }
  7820. }, false);
  7821.  
  7822. })();
  7823.  
  7824. let videoPlayingY = null;
  7825.  
  7826. isPrepareCachedV && (() => {
  7827.  
  7828. let getNext = true;
  7829. let videoPlayingX = {
  7830. get videoId() {
  7831. if (getNext) {
  7832. getNext = false;
  7833.  
  7834. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  7835. const arr = [];
  7836. for (const element of elements) {
  7837. if (!element.closest('[hidden]')) arr.push(element);
  7838. }
  7839. if (arr.length !== 1) this.__videoId__ = '';
  7840. else {
  7841. this.__videoId__ = arr[0].getAttribute('video-id');
  7842. }
  7843.  
  7844. }
  7845. return this.__videoId__ || '';
  7846. }
  7847. }
  7848.  
  7849. videoPlayingY = videoPlayingX;
  7850. const handler = (evt) => {
  7851. const target = (evt || 0).target;
  7852. if (target instanceof HTMLVideoElement) {
  7853. getNext = true;
  7854. }
  7855. }
  7856. document.addEventListener('loadedmetadata', handler, true);
  7857. document.addEventListener('durationchange', handler, true);
  7858.  
  7859. })();
  7860.  
  7861.  
  7862.  
  7863. const cleanContext = async (win) => {
  7864. const waitFn = requestAnimationFrame; // shall have been binded to window
  7865. try {
  7866. let mx = 16; // MAX TRIAL
  7867. const frameId = 'vanillajs-iframe-v1';
  7868. /** @type {HTMLIFrameElement | null} */
  7869. let frame = document.getElementById(frameId);
  7870. let removeIframeFn = null;
  7871. if (!frame) {
  7872. frame = document.createElement('iframe');
  7873. frame.id = frameId;
  7874. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  7875. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  7876. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  7877. n.appendChild(frame);
  7878. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  7879. const root = document.documentElement;
  7880. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  7881. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  7882.  
  7883. removeIframeFn = (setTimeout) => {
  7884. const removeIframeOnDocumentReady = (e) => {
  7885. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7886. e = n;
  7887. n = win = removeIframeFn = 0;
  7888. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  7889. }
  7890. if (!setTimeout || document.readyState !== 'loading') {
  7891. removeIframeOnDocumentReady();
  7892. } else {
  7893. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7894. }
  7895. }
  7896. }
  7897. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  7898. const fc = frame.contentWindow;
  7899. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  7900. try {
  7901. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  7902. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  7903. for (let k in res) res[k] = res[k].bind(win); // necessary
  7904. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  7905. res.animate = fc.HTMLElement.prototype.animate;
  7906. res.perfNow = fc.performance.now;
  7907. return res;
  7908. } catch (e) {
  7909. if (removeIframeFn) removeIframeFn();
  7910. return null;
  7911. }
  7912. } catch (e) {
  7913. console.warn(e);
  7914. return null;
  7915. }
  7916. };
  7917.  
  7918. const promiseForYtActionCalled = new Promise(resolve => {
  7919.  
  7920. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  7921. if (typeof AbortSignal !== 'undefined') {
  7922. let hn = () => {
  7923. if (!hn) return;
  7924. hn = null;
  7925. resolve(document.querySelector(appTag));
  7926. };
  7927. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  7928. } else {
  7929. let hn = () => {
  7930. if (!hn) return;
  7931. document.removeEventListener('yt-action', hn, true);
  7932. hn = null;
  7933. resolve(document.querySelector(appTag));
  7934. };
  7935. document.addEventListener('yt-action', hn, true);
  7936. }
  7937. });
  7938.  
  7939. cleanContext(window).then(__CONTEXT__ => {
  7940. if (!__CONTEXT__) return null;
  7941.  
  7942. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  7943.  
  7944.  
  7945. performance.now17 = perfNow.bind(performance);
  7946.  
  7947.  
  7948.  
  7949. __requestAnimationFrame__ = requestAnimationFrame;
  7950.  
  7951.  
  7952. const isGPUAccelerationAvailable = (() => {
  7953. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  7954. try {
  7955. const canvas = document.createElement('canvas');
  7956. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  7957. } catch (e) {
  7958. return false;
  7959. }
  7960. })();
  7961.  
  7962. const foregroundPromiseFn_noGPU = (() => {
  7963.  
  7964. if (isGPUAccelerationAvailable) return null;
  7965.  
  7966. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  7967. if (!pd || typeof pd.get !== 'function') return null;
  7968. const pdGet = pd.get;
  7969.  
  7970. let pr = null;
  7971.  
  7972. let hState = pdGet.call(document) === 'hidden';
  7973. // let cid = 0;
  7974. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  7975. const newHState = pdGet.call(document) === 'hidden';
  7976. if (hState !== newHState) {
  7977. // if (cid > 0) cid = clearInterval(cid);
  7978. hState = newHState;
  7979. if (!hState && pr) pr = pr.resolve();
  7980. }
  7981. });
  7982.  
  7983. // cid = setInterval(() => {
  7984. // const newHState = document.visibilityState === 'hidden';
  7985. // if (hState !== newHState) {
  7986. // hState = newHState;
  7987. // if (!hState && pr) pr = pr.resolve();
  7988. // }
  7989. // }, 100);
  7990.  
  7991.  
  7992. return (() => {
  7993. if (pr) return pr;
  7994. const w = ((!hState && setTimeout(() => {
  7995. if (!hState && pr === w) pr = pr.resolve();
  7996. })), (pr = new PromiseExternal()));
  7997. return w;
  7998. });
  7999.  
  8000. })();
  8001.  
  8002.  
  8003. let rafPromise = null;
  8004. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  8005. requestAnimationFrame(hRes => {
  8006. rafPromise = null;
  8007. resolve(hRes);
  8008. });
  8009. }));
  8010.  
  8011. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  8012.  
  8013.  
  8014. const wmComputedStyle = new WeakMap();
  8015.  
  8016. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  8017. window.__native__getComputedStyle__ = getComputedStyle;
  8018. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  8019. window.__original__getComputedStyle__ = window.getComputedStyle;
  8020. window.getComputedStyle = function (elem) {
  8021. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  8022. return window.__original__getComputedStyle__(...arguments);
  8023. }
  8024. let cs = wmComputedStyle.get(elem);
  8025. if (!cs) {
  8026. cs = window.__native__getComputedStyle__(elem);
  8027. wmComputedStyle.set(elem, cs);
  8028. }
  8029. return cs;
  8030. };
  8031. } else {
  8032. window.__original__getComputedStyle__ = null;
  8033. }
  8034. window.__jst__getComputedStyle__ = window.getComputedStyle;
  8035. }
  8036.  
  8037. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  8038. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  8039. window.getComputedStyle = window.__jst__getComputedStyle__;
  8040. }
  8041. });
  8042.  
  8043. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  8044. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  8045.  
  8046. const promiseForTamerTimeout = new Promise(resolve => {
  8047. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8048. setTimeout(resolve, 480);
  8049. }, { capture: true, passive: true, once: true });
  8050. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8051. setTimeout(resolve, 1200);
  8052. });
  8053. setTimeout(resolve, 3000);
  8054. });
  8055.  
  8056. const promiseForPageInitied = new Promise(resolve => {
  8057. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8058. setTimeout(resolve, 450);
  8059. }, { capture: true, passive: true, once: true });
  8060. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8061. setTimeout(resolve, 900);
  8062. });
  8063. setTimeout(resolve, 1800);
  8064. });
  8065.  
  8066. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  8067. NO_PRELOAD_GENERATE_204_BYPASS = true;
  8068. headLinkCollection = null;
  8069. });
  8070.  
  8071.  
  8072. NATIVE_CANVAS_ANIMATION && (() => {
  8073.  
  8074. observablePromise(() => {
  8075. HTMLCanvasElement.prototype.animate = animate;
  8076. }, promiseForTamerTimeout).obtain();
  8077.  
  8078. })();
  8079.  
  8080.  
  8081.  
  8082.  
  8083. FIX_ytAction_ && (async () => {
  8084.  
  8085. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8086.  
  8087. const ytdApp = await new Promise(resolve => {
  8088.  
  8089. whenCEDefined(appTag).then(() => {
  8090. const ytdApp = document.querySelector(appTag);
  8091. if (ytdApp) {
  8092. resolve(ytdApp);
  8093. return;
  8094. }
  8095. let mo = new MutationObserver(() => {
  8096. const ytdApp = document.querySelector(appTag);
  8097. if (!ytdApp) return;
  8098. if (mo) {
  8099. mo.disconnect();
  8100. mo.takeRecords();
  8101. mo = null;
  8102. }
  8103. resolve(ytdApp);
  8104. });
  8105. mo.observe(document, { subtree: true, childList: true });
  8106. });
  8107.  
  8108. });
  8109.  
  8110. if (!ytdApp) return;
  8111. const cProto = insp(ytdApp).constructor.prototype;
  8112.  
  8113. if (!cProto) return;
  8114. let mbd = 0;
  8115.  
  8116. const fixer = (_ytdApp) => {
  8117. const ytdApp = insp(_ytdApp);
  8118. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  8119. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  8120. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  8121. mbd++;
  8122. }
  8123. }
  8124.  
  8125. observablePromise(() => {
  8126.  
  8127. if (typeof cProto.created === 'function' && !cProto.created56) {
  8128. cProto.created56 = cProto.created;
  8129. cProto.created = function (...args) {
  8130. const r = this.created56(...args);
  8131. fixer(this);
  8132. return r;
  8133. };
  8134. mbd++;
  8135. }
  8136.  
  8137. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  8138. cProto.onYtAction57_ = cProto.onYtAction_;
  8139. cProto.onYtAction_ = function (...args) {
  8140. Promise.resolve().then(() => this.onYtAction57_(...args));
  8141. };
  8142. mbd++;
  8143. }
  8144.  
  8145. if (ytdApp) fixer(ytdApp);
  8146.  
  8147. /*
  8148. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  8149. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  8150. actionRouter_.handleAction57 = actionRouter_.handleAction;
  8151. actionRouter_.handleAction = function (...args) {
  8152. Promise.resolve().then(() => this.handleAction57(...args));
  8153. }
  8154. mbd++;
  8155. }
  8156. */
  8157.  
  8158. // if(mbd === 3) return 1;
  8159. if (mbd >= 3) return 1;
  8160.  
  8161. }, new Promise(r => setTimeout(r, 1000))).obtain();
  8162.  
  8163. })();
  8164.  
  8165.  
  8166.  
  8167. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  8168.  
  8169. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  8170.  
  8171. const app = await observablePromise(() => {
  8172.  
  8173. return document.querySelector(appTag);
  8174.  
  8175. }).obtain();
  8176.  
  8177. if (!app) return;
  8178.  
  8179.  
  8180. const appCnt = insp(app);
  8181.  
  8182. if (typeof appCnt.createComponent_ !== 'function' || appCnt.createComponent_.length != 3) return;
  8183.  
  8184.  
  8185. const mapGet = Map.prototype.get;
  8186.  
  8187.  
  8188. /** @type {Map | null} */
  8189. let qcMap = null;
  8190.  
  8191. Map.prototype.get = function (a) {
  8192. if (a === 'dummy-4718') qcMap = this;
  8193. return mapGet.call(this, a);
  8194. };
  8195. const r = appCnt.createComponent_('dummy-4718', {}, true);
  8196. Map.prototype.get = mapGet;
  8197.  
  8198. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  8199.  
  8200.  
  8201. // clearInterval(ckId);
  8202. // ckId = 0;
  8203.  
  8204. if (qcMap !== null && qcMap instanceof Map) {
  8205.  
  8206. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  8207.  
  8208. const setArrayC = (c) => {
  8209. if (c instanceof Array) {
  8210. c.length = 0;
  8211. c.push = function () { };
  8212. c.pop = function () { };
  8213. c.shift = function () { };
  8214. c.unshift = function () { };
  8215. c.splice = function () { };
  8216. c.sort = function () { };
  8217. c.reverse = function () { };
  8218. }
  8219. }
  8220.  
  8221. const cleaning = function () {
  8222. qcMap.forEach(setArrayC);
  8223. qcMap.clear();
  8224. }
  8225.  
  8226. qcMap.set = function (b, c) {
  8227.  
  8228. setArrayC(c);
  8229.  
  8230. // console.log('qcMap.set', b, c);
  8231.  
  8232. if (qcMap.size > 0) {
  8233. // play safe
  8234.  
  8235. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  8236. cleaning();
  8237. }
  8238.  
  8239. }
  8240. qcMap.get = function (b) {
  8241.  
  8242. // console.log('qcMap.get', b);
  8243.  
  8244. if (qcMap.size > 0) {
  8245. // play safe
  8246.  
  8247. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  8248. cleaning();
  8249. }
  8250.  
  8251. }
  8252.  
  8253.  
  8254. if (qcMap.size > 0) {
  8255.  
  8256. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  8257. cleaning();
  8258. }
  8259.  
  8260. }
  8261.  
  8262. }
  8263.  
  8264.  
  8265. });
  8266.  
  8267.  
  8268. const observablePromise = (proc, timeoutPromise) => {
  8269. let promise = null;
  8270. return {
  8271. obtain() {
  8272. if (!promise) {
  8273. promise = new Promise(resolve => {
  8274. let mo = null;
  8275. const f = () => {
  8276. let t = proc();
  8277. if (t) {
  8278. mo.disconnect();
  8279. mo.takeRecords();
  8280. mo = null;
  8281. resolve(t);
  8282. }
  8283. }
  8284. mo = new MutationObserver(f);
  8285. mo.observe(document, { subtree: true, childList: true })
  8286. f();
  8287. timeoutPromise && timeoutPromise.then(() => {
  8288. resolve(null)
  8289. });
  8290. });
  8291. }
  8292. return promise
  8293. }
  8294. }
  8295. }
  8296.  
  8297. // let _yt_player_promise = null;
  8298. /*
  8299. const getYtPlayerPromise = () => {
  8300. if (!_yt_player_promise) {
  8301. _yt_player_promise = new Promise(resolve => {
  8302. let cid = setInterval(() => {
  8303. let t = (((window || 0)._yt_player || 0) || 0);
  8304. if (t) {
  8305. clearInterval(cid);
  8306. resolve(t);
  8307. }
  8308. }, 1);
  8309. promiseForTamerTimeout.then(() => {
  8310. resolve(null)
  8311. });
  8312. });
  8313. }
  8314. return _yt_player_promise;
  8315. }
  8316. */
  8317. const _yt_player_observable = observablePromise(() => {
  8318. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  8319. if (_yt_player) {
  8320. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  8321. return _yt_player;
  8322. }
  8323. }, promiseForTamerTimeout);
  8324.  
  8325. const polymerObservable = observablePromise(() => {
  8326. const Polymer = window.Polymer;
  8327. if (typeof Polymer !== 'function') return;
  8328. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  8329. return Polymer;
  8330. }, promiseForTamerTimeout);
  8331.  
  8332. const schedulerInstanceObservable = observablePromise(() => {
  8333. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  8334. }, promiseForTamerTimeout);
  8335.  
  8336. const timelineObservable = observablePromise(() => {
  8337. let t = (((document || 0).timeline || 0) || 0);
  8338. if (t && typeof t._play === 'function') {
  8339. return t;
  8340. }
  8341. }, promiseForTamerTimeout);
  8342. const animationObservable = observablePromise(() => {
  8343. let t = (((window || 0).Animation || 0) || 0);
  8344. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  8345. return t;
  8346. }
  8347. }, promiseForTamerTimeout);
  8348.  
  8349.  
  8350. const getScreenInfo = {
  8351. screenWidth: 0,
  8352. screenHeight: 0,
  8353. valueReady: false,
  8354. onResize: () => {
  8355. getScreenInfo.valueReady = false;
  8356. },
  8357. sizeProvided: () => {
  8358. if (getScreenInfo.valueReady) return true;
  8359. getScreenInfo.screenWidth = screen.width;
  8360. getScreenInfo.screenHeight = screen.height;
  8361. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  8362. getScreenInfo.valueReady = true;
  8363. return true;
  8364. }
  8365. return false;
  8366. }
  8367. };
  8368.  
  8369. window.addEventListener('resize', getScreenInfo.onResize, true);
  8370.  
  8371.  
  8372. // const hookLeftPending = new WeakMap();
  8373.  
  8374. const isNaNx = Number.isNaN;
  8375.  
  8376. const hookLeftPD = {
  8377. get() {
  8378. const p = 'left';
  8379. // const o = hookLeftPending.get(this);
  8380. // if (o && o.key) {
  8381. // this.setProperty(p, o.value);
  8382. // o.key = null
  8383. // }
  8384. return this.getPropertyValue(p);
  8385. },
  8386. set(v) {
  8387.  
  8388. const p = 'left';
  8389. const cv = this.getPropertyValue(p);
  8390. const sv = v;
  8391.  
  8392. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  8393.  
  8394. // console.log(8380,did, cv, sv)
  8395. if (!cv && !sv) return true;
  8396. if (cv === sv) return true;
  8397.  
  8398. // skip 0~9px => L>=4
  8399.  
  8400. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  8401.  
  8402. if (!isNaNx(qsv)) {
  8403. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  8404.  
  8405. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  8406. const { screenWidth, screenHeight } = getScreenInfo;
  8407. let pWidth = screenWidth + 1024;
  8408. let pHeight = screenHeight + 768;
  8409. const minRatio = 0.003;
  8410. const dw = pWidth * 0.0003; // min dw = 0.3072
  8411. const dh = pHeight * 0.0003; // min dh = 0.2304
  8412. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  8413. if (Math.abs(qcv - qsv) < dw) return true;
  8414. }
  8415.  
  8416. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  8417. if (`${v}`.length > `${sv}`.length) v = sv;
  8418. // console.log(8382, did, sv, nv, cv, this)
  8419. }
  8420.  
  8421. // Promise.resolve().then(() => {
  8422. // const o = hookLeftPending.get(this);
  8423. // if (o && o.key === did) {
  8424. // this.setProperty(p, o.value);
  8425. // o.key = null;
  8426. // }
  8427. // });
  8428. // hookLeftPending.set(this, {
  8429. // key: did,
  8430. // value: nv
  8431. // });
  8432.  
  8433. // if (nv != v) {
  8434. // console.log(8387, v, nv);
  8435. // }
  8436.  
  8437. this.setProperty(p, v);
  8438. // console.log(8383, did, this.getPropertyValue(p))
  8439. return true;
  8440. },
  8441. enumerable: true,
  8442. configurable: true
  8443. };
  8444.  
  8445.  
  8446. if (HOOK_CSSPD_LEFT) {
  8447.  
  8448.  
  8449. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  8450.  
  8451. }
  8452.  
  8453.  
  8454.  
  8455.  
  8456.  
  8457. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  8458.  
  8459. const evKey = `${_evKey}`;
  8460. const fvKey = `${_fvKey}`;
  8461. const debug = !!_debug;
  8462.  
  8463. const _yt_player = await _yt_player_observable.obtain();
  8464.  
  8465.  
  8466. if (!_yt_player || typeof _yt_player !== 'object') return;
  8467.  
  8468.  
  8469. const getArr = (_yt_player) => {
  8470.  
  8471. let arr = [];
  8472.  
  8473. for (const [k, v] of Object.entries(_yt_player)) {
  8474.  
  8475. const p = typeof v === 'function' ? v.prototype : 0;
  8476. if (p
  8477. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  8478.  
  8479. ) {
  8480. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8481.  
  8482. }
  8483.  
  8484. }
  8485.  
  8486. if (arr.length === 0) {
  8487.  
  8488. console.warn(`Key prop [${evKey}] does not exist.`);
  8489. } else {
  8490.  
  8491. return arr;
  8492. }
  8493.  
  8494. };
  8495.  
  8496. const arr = getArr(_yt_player);
  8497.  
  8498.  
  8499. if (!arr) return;
  8500.  
  8501. debug && console.log(`FIX_${evKey}`, arr);
  8502.  
  8503. const f = function (...args) {
  8504. Promise.resolve().then(() => this[fvKey](...args));
  8505. };
  8506.  
  8507.  
  8508. for (const k of arr) {
  8509.  
  8510. const g = _yt_player;
  8511. const gk = g[k];
  8512. const gkp = gk.prototype;
  8513.  
  8514. debug && console.log(237, k, gkp)
  8515.  
  8516. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  8517. gkp[fvKey] = gkp[evKey];
  8518. gkp[evKey] = f;
  8519. }
  8520. }
  8521.  
  8522.  
  8523.  
  8524.  
  8525. }
  8526.  
  8527. if (!isChatRoomURL) {
  8528.  
  8529. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  8530. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  8531. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  8532. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  8533. if (FIX_VideoEVENTS_v2) {
  8534. const FIX_VideoEVENTS_DEBUG = 0;
  8535. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  8536. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  8537. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  8538. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  8539. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  8540. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  8541. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  8542. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  8543. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  8544.  
  8545. }
  8546. // onMutedAutoplayChange
  8547. // onVolumeChange
  8548. // onPlaybackRateChange
  8549.  
  8550. // onAirPlayActiveChange
  8551. // onAirPlayAvailabilityChange
  8552. // onApiChange
  8553. // onAutoplayBlocked
  8554. // onDrmOutputRestricted
  8555. // onFullscreenChange
  8556. // onLoadProgress
  8557. // onLoadedMetadata
  8558. // onVideoDataChange
  8559. // onVideoProgress
  8560.  
  8561. }
  8562.  
  8563.  
  8564.  
  8565. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_stampDomArray ) && (async () => {
  8566.  
  8567. const Polymer = await polymerObservable.obtain();
  8568. if (!Polymer) return;
  8569.  
  8570. if (FIX_Polymer_dom) {
  8571.  
  8572. const checkPDFuncValue = (pd) => {
  8573. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  8574. }
  8575. const checkPDFuncValue2 = (pd) => {
  8576. return pd && typeof pd.value == 'function'
  8577. }
  8578.  
  8579. const checkPDFuncGet = (pd) => {
  8580. return pd && typeof pd.get == 'function'
  8581. }
  8582.  
  8583. const domX = Polymer.dom(document.createElement('null'));
  8584. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  8585. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  8586. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  8587. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  8588. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  8589. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  8590. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  8591. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  8592. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  8593.  
  8594.  
  8595. // getOwnerRoot - to be reviewed
  8596. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  8597.  
  8598. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  8599. domXP.getOwnerRoot = function () {
  8600. try {
  8601. const p = this.node;
  8602.  
  8603. if (p instanceof HTMLElement) {
  8604. const pp = pd2.get.call(p);
  8605. if (pp instanceof HTMLElement && pp.isConnected === true) {
  8606. return pp.getRootNode();
  8607. }
  8608.  
  8609. }
  8610. } catch (e) { }
  8611. return this.getOwnerRoot15();
  8612. }
  8613.  
  8614. Polymer.__fixedGetOwnerRoot__ = 1;
  8615. }
  8616.  
  8617.  
  8618.  
  8619.  
  8620. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  8621.  
  8622. domXP.querySelector15 = domXP.querySelector;
  8623.  
  8624. const querySelectorFn = function (query) {
  8625. try {
  8626. const p = this.node;
  8627.  
  8628. // if (p instanceof HTMLElement && p.isConnected === true) {
  8629. // return pd4.value.call(p, query);
  8630. // }
  8631.  
  8632. if (p instanceof Document && p.isConnected === true) {
  8633. return pd4b.value.call(p, query);
  8634. }
  8635.  
  8636. } catch (e) { }
  8637. return this.querySelector15(query);
  8638. }
  8639.  
  8640. Object.defineProperty(domXP, 'querySelector', {
  8641. get() {
  8642. return querySelectorFn;
  8643. },
  8644. set(nv) {
  8645. if (nv === querySelectorFn) return true;
  8646. this.querySelector15 = nv;
  8647. return true;
  8648. },
  8649.  
  8650. enumerable: false,
  8651. configurable: true
  8652. });
  8653.  
  8654. Polymer.__fixedQuerySelector__ = 1;
  8655. }
  8656.  
  8657. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  8658.  
  8659. domXP.querySelectorAll15 = domXP.querySelectorAll;
  8660.  
  8661. const querySelectorAllFn = function (query) {
  8662.  
  8663. try {
  8664.  
  8665. const p = this.node;
  8666.  
  8667. // if (p instanceof HTMLElement && p.isConnected === true) {
  8668. // return pd6.value.call(p, query);
  8669. // }
  8670.  
  8671. if (p instanceof Document && p.isConnected === true) {
  8672. return pd6b.value.call(p, query);
  8673. }
  8674.  
  8675. } catch (e) {
  8676.  
  8677. }
  8678. return this.querySelectorAll15(query);
  8679. }
  8680.  
  8681. Object.defineProperty(domXP, 'querySelectorAll', {
  8682. get() {
  8683. return querySelectorAllFn;
  8684. },
  8685. set(nv) {
  8686. if (nv === querySelectorAllFn) return true;
  8687. this.querySelectorAll15 = nv;
  8688. return true;
  8689. },
  8690.  
  8691. enumerable: false,
  8692. configurable: true
  8693. });
  8694.  
  8695. Polymer.__fixedQuerySelectorAll__ = 1;
  8696. }
  8697. }
  8698.  
  8699.  
  8700. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  8701.  
  8702. Polymer.Base.__connInit__ = function () {
  8703. setupYtComponent(this);
  8704. }
  8705.  
  8706.  
  8707. /** @type {Function} */
  8708. const connectedCallbackK = function (...args) {
  8709. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8710. const r = this[qm53](...args);
  8711. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8712. this.mh35 = 1;
  8713. return r;
  8714. };
  8715.  
  8716. connectedCallbackK.m353 = 1;
  8717.  
  8718.  
  8719. const qt53 = Polymer.Base.connectedCallback;
  8720. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  8721.  
  8722. Polymer.Base.connectedCallback = connectedCallbackK;
  8723.  
  8724.  
  8725. /** @type {Function} */
  8726. const createdK = function (...args) {
  8727. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8728. const r = this[qn53](...args);
  8729. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8730. this.mh36 = 1;
  8731. return r;
  8732. };
  8733.  
  8734.  
  8735. createdK.m353 = 1;
  8736. Polymer.Base[qn53] = Polymer.Base.created;
  8737. Polymer.Base.created = createdK;
  8738.  
  8739. }
  8740.  
  8741. })();
  8742.  
  8743.  
  8744. /*
  8745.  
  8746. e.nativeAppendChild = d.prototype.appendChild,
  8747. d.prototype.appendChild = function(h) {
  8748. return function(l) {
  8749. if (l instanceof DocumentFragment) {
  8750. var m = Array.from(l.children);
  8751. l = h.nativeAppendChild.call(this, l);
  8752. if (this.isConnected) {
  8753. m = g(m);
  8754. for (var p = m.next(); !p.done; p = m.next())
  8755. YD(p.value)
  8756. }
  8757. return l
  8758. }
  8759. m = l instanceof Element && l.isConnected;
  8760. p = h.nativeAppendChild.call(this, l);
  8761. m && ZD(l);
  8762. this.isConnected && YD(l);
  8763. return p
  8764. }
  8765. }(e),
  8766.  
  8767. */
  8768.  
  8769. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  8770.  
  8771. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  8772. if (f) Node.prototype.appendChild = function (a) {
  8773. if (this instanceof Element) { // exclude DocumentFragment
  8774. try {
  8775. let checkFragmentA = (a instanceof DocumentFragment);
  8776. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  8777. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  8778. for (const node of headLinkCollection) {
  8779. if (node.rel === 'preload' && node.as === 'fetch') {
  8780. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  8781. }
  8782. }
  8783. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  8784. checkFragmentA = false;
  8785. }
  8786. if (checkFragmentA && a.firstElementChild === null) {
  8787. // no element in fragmentA
  8788. let doNormal = false;
  8789. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  8790. if (child.nodeType === 3) { doNormal = true; break; }
  8791. }
  8792. if (!doNormal) return a;
  8793. }
  8794. } catch (e) {
  8795. console.log(e);
  8796. }
  8797. }
  8798. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  8799. }
  8800.  
  8801. })();
  8802.  
  8803. if (FIX_Shady) {
  8804.  
  8805. observablePromise(() => {
  8806. const { ShadyDOM, ShadyCSS } = window;
  8807. if (ShadyDOM) {
  8808. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  8809. ShadyDOM.noPatch = true; // 1 of 10
  8810. ShadyDOM.patchOnDemand = false; // 1 of 10
  8811. ShadyDOM.preferPerformance = true; // 1 of 10
  8812. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  8813. }
  8814. if (ShadyCSS) {
  8815. ShadyCSS.nativeCss = true; // 1 of 10
  8816. ShadyCSS.nativeShadow = true; // 6 of 10
  8817. ShadyCSS.cssBuild = undefined; // 1 of 10
  8818. ShadyCSS.disableRuntime = true; // 1 of 10
  8819. }
  8820. if (ShadyDOM && ShadyCSS) return 1;
  8821. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  8822.  
  8823. }
  8824.  
  8825.  
  8826. // let schedulerInstancePropOfTimerType = '';
  8827. // let schedulerInstancePropOfTimerId = '';
  8828. (FIX_schedulerInstanceInstance & 2) && (async () => {
  8829.  
  8830. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  8831.  
  8832. if (!schedulerInstanceInstance_) return;
  8833.  
  8834. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  8835. if (checkOK) {
  8836.  
  8837. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  8838.  
  8839. let requestingFn = null;
  8840. let requestingArgs = null;
  8841.  
  8842. const f = function () {
  8843. requestingFn = this.fn;
  8844. requestingArgs = [...arguments];
  8845. return 12373;
  8846. };
  8847.  
  8848. const fakeFns = [
  8849. f.bind({ fn: requestAnimationFrame }),
  8850. f.bind({ fn: setInterval }),
  8851. f.bind({ fn: setTimeout }),
  8852. f.bind({ fn: requestIdleCallback })
  8853. ];
  8854.  
  8855. let mzt = 0;
  8856.  
  8857. let _fnSelectorProp = null;
  8858. const mkFns = new Array(4);
  8859.  
  8860. /*
  8861. case 1:
  8862. var a = this.K;
  8863. this.g = this.I ? window.requestIdleCallback(a, {
  8864. timeout: 3E3
  8865. }) : window.setTimeout(a, ma);
  8866. break;
  8867. case 2:
  8868. this.g = window.setTimeout(this.M, this.N);
  8869. break;
  8870. case 3:
  8871. this.g = window.requestAnimationFrame(this.L);
  8872. break;
  8873. case 4:
  8874. this.g = window.setTimeout(this.J, 0)
  8875. }
  8876.  
  8877. */
  8878. const startFnHandler = {
  8879. get(target, prop, receiver) {
  8880. if (prop === '$$12377$$') return true;
  8881. if (prop === '$$12378$$') return target;
  8882.  
  8883. // console.log('get',prop)
  8884. return target[prop]
  8885. },
  8886. set(target, prop, value, receiver) {
  8887. // console.log('set', prop, value)
  8888.  
  8889. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  8890. if (value === 12373 && _fnSelectorProp) {
  8891.  
  8892. const schedulerTypeSelection = target[_fnSelectorProp];
  8893. const timerIdProp = prop;
  8894.  
  8895. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  8896. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  8897. // schedulerInstancePropOfTimerId = timerIdProp || '';
  8898. // }
  8899.  
  8900. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  8901. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  8902. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  8903. // rare
  8904. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  8905. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  8906. // often
  8907. if ((FIX_schedulerInstanceInstance & 4) && typeof nextBrowserTick == 'function') {
  8908. const f = requestingArgs[0];
  8909. const tir = ++mzt;
  8910. nextBrowserTick(() => {
  8911. if (target[timerIdProp] === -tir) f();
  8912. });
  8913. target[_fnSelectorProp] = 940;
  8914. target[timerIdProp] = -tir;
  8915. } else {
  8916. const f = requestingArgs[0];
  8917. const tir = ++mzt;
  8918. Promise.resolve().then(() => {
  8919. if (target[timerIdProp] === -tir) f();
  8920. });
  8921. target[_fnSelectorProp] = 930;
  8922. target[timerIdProp] = -tir;
  8923. }
  8924. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  8925. // often
  8926. if (requestingFn === requestIdleCallback) {
  8927. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  8928. } else {
  8929. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  8930. }
  8931. } else {
  8932. target[_fnSelectorProp] = 0;
  8933. target[timerIdProp] = 0;
  8934. }
  8935. } else {
  8936. target[prop] = value;
  8937. }
  8938. return true;
  8939. }
  8940. };
  8941.  
  8942. let startBusy = false;
  8943. schedulerInstanceInstance_.start = function () {
  8944. if (startBusy) return;
  8945. startBusy = true;
  8946. try {
  8947. mkFns[0] = window.requestAnimationFrame;
  8948. mkFns[1] = window.setInterval;
  8949. mkFns[2] = window.setTimeout;
  8950. mkFns[3] = window.requestIdleCallback;
  8951. const tThis = this['$$12378$$'] || this;
  8952. window.requestAnimationFrame = fakeFns[0]
  8953. window.setInterval = fakeFns[1]
  8954. window.setTimeout = fakeFns[2]
  8955. window.requestIdleCallback = fakeFns[3]
  8956. _fnSelectorProp = null;
  8957. tThis.start993.call(new Proxy(tThis, startFnHandler));
  8958. _fnSelectorProp = null;
  8959. window.requestAnimationFrame = mkFns[0];
  8960. window.setInterval = mkFns[1];
  8961. window.setTimeout = mkFns[2];
  8962. window.requestIdleCallback = mkFns[3];
  8963. } catch (e) {
  8964. console.warn(e);
  8965. }
  8966. startBusy = false;
  8967. }
  8968.  
  8969. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  8970.  
  8971. }
  8972. })();
  8973.  
  8974. FIX_yt_player && !isChatRoomURL && (async () => {
  8975.  
  8976. const fOption = 1 | 2 | 4;
  8977.  
  8978. const _yt_player = await _yt_player_observable.obtain();
  8979.  
  8980. if (!_yt_player || typeof _yt_player !== 'object') return;
  8981.  
  8982. const g = _yt_player;
  8983. let k;
  8984.  
  8985. if (fOption & 1) {
  8986.  
  8987. // rAf scheduling
  8988.  
  8989. const keyZqOu = getZqOu(_yt_player);
  8990. if (!keyZqOu) {
  8991. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  8992. return;
  8993. }
  8994. k = keyZqOu
  8995.  
  8996. const gk = g[k];
  8997. if (typeof gk !== 'function') {
  8998. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  8999. return;
  9000. }
  9001. const gkp = gk.prototype;
  9002.  
  9003. const dummyObject = new gk;
  9004. const nilFunc = () => { };
  9005.  
  9006. const nilObj = {};
  9007.  
  9008. // console.log(1111111111)
  9009.  
  9010. let keyBoolD = '';
  9011. let keyWindow = '';
  9012. let keyFuncC = '';
  9013. let keyCidj = '';
  9014.  
  9015. for (const [t, y] of Object.entries(dummyObject)) {
  9016. if (y instanceof Window) keyWindow = t;
  9017. }
  9018.  
  9019. const dummyObjectProxyHandler = {
  9020. get(target, prop) {
  9021. let v = target[prop]
  9022. if (v instanceof Window && !keyWindow) {
  9023. keyWindow = t;
  9024. }
  9025. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  9026. if (prop === keyWindow) y = {
  9027. requestAnimationFrame(f) {
  9028. return 3;
  9029. },
  9030. cancelAnimationFrame() {
  9031.  
  9032. }
  9033. }
  9034. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  9035. keyFuncC = prop;
  9036. }
  9037. // console.log('[get]', prop, typeof target[prop])
  9038.  
  9039.  
  9040. return y;
  9041. },
  9042. set(target, prop, value) {
  9043.  
  9044. if (typeof value === 'boolean' && !keyBoolD) {
  9045. keyBoolD = prop;
  9046. }
  9047. if (typeof value === 'number' && !keyCidj && value >= 2) {
  9048. keyCidj = prop;
  9049. }
  9050.  
  9051. // console.log('[set]', prop, value)
  9052. target[prop] = value;
  9053.  
  9054. return true;
  9055. }
  9056. };
  9057.  
  9058. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  9059.  
  9060. // console.log('gkp.start',gkp.start);
  9061. // console.log('gkp.stop',gkp.stop);
  9062. gkp._activation = false;
  9063.  
  9064. gkp.start = function () {
  9065. // p59 || console.log(12100)
  9066. if (!this._activation) {
  9067. this._activation = true;
  9068. foregroundPromiseFn().then(() => {
  9069. this._activation = false;
  9070. if (this[keyCidj]) {
  9071. Promise.resolve().then(this[keyFuncC]);
  9072. }
  9073. });
  9074. }
  9075. this[keyCidj] = 1;
  9076. this[keyBoolD] = true;
  9077. };
  9078.  
  9079. gkp.stop = function () {
  9080. this[keyCidj] = null;
  9081. };
  9082.  
  9083.  
  9084. /*
  9085. g[k].start = function() {
  9086. this.stop();
  9087. this.D = true;
  9088. var a = requestAnimationFrame
  9089. , b = cancelAnimationFrame;
  9090. this.j = a.call(this.B, this.C)
  9091. }
  9092. ;
  9093. g[k].stop = function() {
  9094. if (this.isActive()) {
  9095. var a = requestAnimationFrame
  9096. , b = cancelAnimationFrame;
  9097. b.call(this.B, this.j)
  9098. }
  9099. this.j = null
  9100. }
  9101. */
  9102. }
  9103.  
  9104. if (fOption & 2) {
  9105. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  9106.  
  9107. if (keyzo) {
  9108.  
  9109. k = keyzo;
  9110.  
  9111. const attrUpdateFn = g[k];
  9112. // console.log(5992, attrUpdateFn)
  9113. g['$$original$$' + k] = attrUpdateFn;
  9114. const zoTransform = async (a, c) => {
  9115.  
  9116. let transformType = '';
  9117. let transformValue = 0;
  9118. let transformUnit = '';
  9119. let transformTypeI = 0;
  9120.  
  9121. const aStyle = a.style;
  9122.  
  9123. let cType = 0;
  9124.  
  9125. const cl = c.length;
  9126.  
  9127. if (cl >= 8) {
  9128. // scale(1)
  9129. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  9130. cType = 1;
  9131. let t = c.charCodeAt(5);
  9132. if (t === 88 || t === 120) cType = 1 | 4;
  9133. if (t === 89 || t === 121) cType = 1 | 8;
  9134. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  9135. cType = 2;
  9136. let t = c.charCodeAt(9);
  9137. if (t === 88 || t === 120) cType = 2 | 4;
  9138. if (t === 89 || t === 121) cType = 2 | 8;
  9139. }
  9140. let w = 0;
  9141. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  9142. let p = c.substring(7, cl - 1);
  9143. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9144. if (typeof q === 'number' && !isNaNx(q)) {
  9145. transformType = w === 1 ? 'scaleX' : 'scaleY';
  9146. transformValue = q;
  9147. transformUnit = '';
  9148. transformTypeI = 1;
  9149. } else {
  9150. cType = 256;
  9151. }
  9152. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  9153. if (c.endsWith('px)')) {
  9154. let p = c.substring(11, cl - 3);
  9155. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9156. if (typeof q === 'number' && !isNaNx(q)) {
  9157. transformType = w === 1 ? 'translateX' : 'translateY';
  9158. transformValue = q;
  9159. transformUnit = 'px';
  9160. transformTypeI = 2;
  9161. } else if (p === 'NaN') {
  9162. return;
  9163. }
  9164. } else {
  9165. cType = 256;
  9166. }
  9167. } else if (cType > 0) {
  9168. cType = 256;
  9169. }
  9170. }
  9171.  
  9172.  
  9173. if (cType === 256) {
  9174. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  9175. }
  9176.  
  9177. if (transformTypeI === 1) {
  9178. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  9179. const vz = toFixed2(q, 3);
  9180. c = `${transformType}(${vz})`;
  9181. const cv = aStyle.transform;
  9182. if (c === cv) return;
  9183. aStyle.transform = c;
  9184. } else if (transformTypeI === 2) {
  9185. const q = transformValue;
  9186. const vz = toFixed2(q, 1);
  9187. c = `${transformType}(${vz}${transformUnit})`;
  9188. const cv = aStyle.transform;
  9189. if (c === cv) return;
  9190. aStyle.transform = c;
  9191. } else { // eg empty
  9192. const cv = aStyle.transform;
  9193. if (!c && !cv) return;
  9194. else if (c === cv) return;
  9195. aStyle.transform = c;
  9196. }
  9197.  
  9198. };
  9199.  
  9200. const elmTransformTemp = new WeakMap();
  9201. const elmPropTemps = {
  9202. 'display': new WeakMap(),
  9203. 'width': new WeakMap(),
  9204. 'height': new WeakMap(),
  9205. 'outlineWidth': new WeakMap(),
  9206. 'position': new WeakMap(),
  9207. 'padding': new WeakMap(),
  9208. "cssText": new WeakMap(),
  9209. "right": new WeakMap(),
  9210. "left": new WeakMap(),
  9211. "top": new WeakMap(),
  9212. "bottom": new WeakMap(),
  9213. "transitionDelay": new WeakMap(),
  9214. "marginLeft": new WeakMap(),
  9215. "marginTop": new WeakMap(),
  9216. "marginRight": new WeakMap(),
  9217. "marginBottom": new WeakMap(),
  9218. }
  9219.  
  9220. const ns5 = Symbol();
  9221. const nextModify = (a, c, m, f, immediate) => {
  9222. const a_ = a;
  9223. const m_ = m;
  9224. const noKey = !m_.has(a_);
  9225. if (immediate || noKey) {
  9226. m_.set(a_, ns5);
  9227. f(a_, c);
  9228. noKey && nextBrowserTick_(() => {
  9229. const d = m_.get(a_);
  9230. if (d === undefined) return;
  9231. m_.delete(a_);
  9232. if (d !== ns5) f(a_, d);
  9233. });
  9234. } else {
  9235. m_.set(a_, c);
  9236. }
  9237. };
  9238.  
  9239. const set66 = new Set();
  9240. const log77 = new Map();
  9241. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  9242.  
  9243. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  9244.  
  9245. // console.log(140000, a, b, c);
  9246. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement) {
  9247. const num = c;
  9248. c = `${num}`;
  9249. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  9250. }
  9251.  
  9252. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement) {
  9253.  
  9254. let elmPropTemp = null;
  9255.  
  9256. if (b === "transform") {
  9257. // div.ytp-hover-progress.ytp-hover-progress-light
  9258. // div.ytp-play-progress.ytp-swatch-background-color
  9259.  
  9260. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  9261. // let ast = null;
  9262. // if (a instanceof HTMLElement && !('__styleH745__' in a) && (ast = a.style)) {
  9263. // a.__styleH745__ = 1;
  9264. // Object.defineProperty(ast, 'left', hookLeftPD);
  9265. // }
  9266. return;
  9267.  
  9268. } else if (elmPropTemp = elmPropTemps[b]) {
  9269.  
  9270. // if (c.length > 5 && c.includes('.')) {
  9271. // console.log(123213, c)
  9272. // }
  9273.  
  9274. const b_ = b;
  9275. nextModify(a, c, elmPropTemp, (a, c) => {
  9276. const style = a.style;
  9277. const cv = style[b_];
  9278. if (!cv && !c) return;
  9279. if (cv === c) return;
  9280. style[b_] = c;
  9281. }, immediateChange);
  9282. return;
  9283.  
  9284. } else if (b === "outline-width") {
  9285.  
  9286. const b_ = 'outlineWidth';
  9287. elmPropTemp = elmPropTemps[b_];
  9288. nextModify(a, c, elmPropTemp, (a, c) => {
  9289. const style = a.style;
  9290. const cv = style[b_];
  9291. if (!cv && !c) return;
  9292. if (cv === c) return;
  9293. style[b_] = c;
  9294. }, immediateChange);
  9295. return;
  9296.  
  9297. } else if (b === 'maxWidth' || b === 'maxHeight') {
  9298. // I think these can be directly assigned.
  9299.  
  9300. const b_ = b;
  9301. const style = a.style;
  9302. const cv = style[b_];
  9303. if (!cv && !c) return;
  9304. if (cv === c) return;
  9305. style[b_] = c;
  9306. return;
  9307.  
  9308. } else {
  9309. // if(immediate && elmPropTemps[b]){
  9310. // console.log(5191, b)
  9311. // }
  9312. // caption-window
  9313. // margin-left max-height max-width font-family fill color font-size background white-space margin
  9314. // text-align background-color
  9315. // console.log(27304, a, b, c)
  9316. if (!set66.has(b)) {
  9317. set66.add(b);
  9318. nextBrowserTick_(() => {
  9319. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  9320. console.log(27304, a, b, c)
  9321. }
  9322. })
  9323. }
  9324. }
  9325.  
  9326. attrUpdateFn.call(this, a, b, c);
  9327. return;
  9328. } else if (typeof (b || 0) === 'object') {
  9329.  
  9330. // this is to fix caption positioning
  9331. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  9332. const immediate = (a.id || 0).length > 14;
  9333. for (const [k, v] of Object.entries(b)) {
  9334. modifiedFn.call(this, a, k, v, immediate);
  9335. }
  9336.  
  9337. } else {
  9338.  
  9339. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  9340. // ytp-ad-timed-pie-countdown-inner
  9341.  
  9342. if (typeof b === 'string') {
  9343.  
  9344. let m = log77.get(b);
  9345. if (!m) {
  9346. m = [];
  9347. console.log(27306, m);
  9348. log77.set(b, m);
  9349. }
  9350. m.push([a, b, c]);
  9351.  
  9352. } else {
  9353. console.log(27306, a, b, c);
  9354. }
  9355.  
  9356. attrUpdateFn.call(this, a, b, c);
  9357. return;
  9358. }
  9359.  
  9360. // console.log(130000, a, b, c);
  9361.  
  9362. };
  9363. g[k] = modifiedFn;
  9364.  
  9365.  
  9366. /*
  9367.  
  9368. g.zo = function(a, b, c) {
  9369. if ("string" === typeof b)
  9370. (b = yo(a, b)) && (a.style[b] = c);
  9371. else
  9372. for (var d in b) {
  9373. c = a;
  9374. var e = b[d]
  9375. , f = yo(c, d);
  9376. f && (c.style[f] = e)
  9377. }
  9378. }
  9379.  
  9380.  
  9381. */
  9382.  
  9383.  
  9384. }
  9385. }
  9386.  
  9387. if (fOption & 4) {
  9388. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  9389.  
  9390. if (keyuG) {
  9391.  
  9392. k = keyuG;
  9393.  
  9394. const gk = g[k];
  9395. const gkp = gk.prototype;
  9396.  
  9397.  
  9398. /** @type { Map<string, WeakMap<any, any>> } */
  9399. const ntLogs = new Map();
  9400.  
  9401. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  9402.  
  9403. gkp.updateValue31 = gkp.updateValue;
  9404. gkp.updateValue = function (a, b) {
  9405. if (typeof a !== 'string') return this.updateValue31(a, b);
  9406.  
  9407. const element = this.element;
  9408. if (!(element instanceof HTMLElement)) return this.updateValue31(a, b);
  9409.  
  9410. let ntLog = ntLogs.get(a);
  9411. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  9412.  
  9413. let cache = ntLog.get(element);
  9414. if (cache && cache.value === b) {
  9415. return;
  9416. }
  9417. if (!cache) {
  9418. this.__oldValueByUpdateValue__ = null;
  9419. ntLog.set(element, cache = { value: b });
  9420. } else {
  9421. this.__oldValueByUpdateValue__ = cache.value;
  9422. cache.value = b;
  9423. }
  9424.  
  9425. return this.updateValue31(a, b);
  9426. }
  9427.  
  9428. /*
  9429. g.k.update = function(a) {
  9430. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  9431. c = c.value,
  9432. this.updateValue(c, a[c])
  9433. }
  9434. ;
  9435. g.k.updateValue = function(a, b) {
  9436. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  9437. }
  9438. */
  9439.  
  9440. }
  9441.  
  9442.  
  9443. }
  9444. }
  9445.  
  9446.  
  9447.  
  9448. })();
  9449.  
  9450.  
  9451. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  9452. // keyboard shortcut keys controller
  9453.  
  9454. const _yt_player = await _yt_player_observable.obtain();
  9455.  
  9456. if (!_yt_player || typeof _yt_player !== 'object') return;
  9457.  
  9458. keyboardController(_yt_player);
  9459.  
  9460. })();
  9461.  
  9462. FIX_yt_player && !isChatRoomURL && (async () => {
  9463. // timer scheduling
  9464.  
  9465. const _yt_player = await _yt_player_observable.obtain();
  9466.  
  9467. if (!_yt_player || typeof _yt_player !== 'object') return;
  9468.  
  9469. let keyZqQu = getZqQu(_yt_player);
  9470.  
  9471. if (!keyZqQu) return;
  9472.  
  9473. const g = _yt_player
  9474. let k = keyZqQu
  9475.  
  9476. const gk = g[k];
  9477. if (typeof gk !== 'function') return;
  9478. const gkp = gk.prototype;
  9479.  
  9480. const extractKeysZqQu = () => {
  9481.  
  9482.  
  9483. let _keyeC = '';
  9484. try {
  9485. gkp.stop.call(new Proxy({
  9486. isActive: () => { }
  9487. }, {
  9488. set(target, prop, value) {
  9489. if (value === 0) _keyeC = prop;
  9490. return true;
  9491. }
  9492. }));
  9493. } catch (e) { }
  9494. if (!_keyeC) return;
  9495. const keyeC = _keyeC;
  9496.  
  9497. let keyC = ''; // this.C = this.ST.bind(this)
  9498. let keyhj = ''; // 1000ms
  9499. try {
  9500. gkp.start.call(new Proxy({
  9501. stop: () => { },
  9502. [keyeC]: 0,
  9503. }, {
  9504. get(target, prop) {
  9505. if (prop in target) return target[prop];
  9506. if (!keyC) {
  9507. keyC = prop;
  9508. return null; // throw error
  9509. }
  9510. else if (!keyhj) {
  9511. keyhj = prop;
  9512. }
  9513.  
  9514. }
  9515. }));
  9516. } catch (e) {
  9517. if (!keyC || !keyhj) {
  9518. console.log(e)
  9519. }
  9520. }
  9521.  
  9522. if (!keyC || !keyhj) return;
  9523. let keyST = '';
  9524. let keyj = '';
  9525. let keyB = '';
  9526. let keyxa = '';
  9527.  
  9528. const possibleKs = new Set();
  9529.  
  9530. for (const [k, v] of Object.entries(gkp)) {
  9531. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  9532. continue;
  9533. }
  9534. if (typeof v === 'function') {
  9535. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  9536. if (m) {
  9537. keyST = k;
  9538. keyj = m[1];
  9539. keyB = m[2];
  9540. } else {
  9541. possibleKs.add(k);
  9542. }
  9543. }
  9544. }
  9545.  
  9546. if (!keyST || !keyj || !keyB) return;
  9547.  
  9548. for (const k of possibleKs) {
  9549. if (k === keyST || k === keyj || k === keyB) {
  9550. continue;
  9551. }
  9552. const v = gkp[k];
  9553. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  9554. keyxa = k;
  9555. }
  9556. }
  9557.  
  9558. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  9559.  
  9560. }
  9561.  
  9562. const keys = extractKeysZqQu();
  9563. if (!keys || !keys.length) return;
  9564. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  9565.  
  9566. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  9567.  
  9568. let disposeKeys = null;
  9569.  
  9570. gkp[keyxa] = function () {
  9571. // dispose
  9572. if (!disposeKeys) {
  9573. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  9574. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  9575. const t = typeof this[key];
  9576. return t === 'undefined' || t === 'object'
  9577. }
  9578. return false;
  9579. });
  9580. }
  9581. for (const key of disposeKeys) {
  9582. const v = this[key];
  9583. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  9584. }
  9585. if (this[keyeC] > 0) this.stop();
  9586. this[keyj] = null;
  9587. this[keyB] = null;
  9588. };
  9589.  
  9590. gkp.start = function (a) {
  9591. if (this[keyeC] > 0) this.stop();
  9592. const delay = void 0 !== a ? a : this[keyhj];
  9593. this[keyeC] = window.setTimeout(this[keyC], delay);
  9594. };
  9595. gkp.stop = function () {
  9596. if (this[keyeC] > 0) {
  9597. window.clearTimeout(this[keyeC]);
  9598. this[keyeC] = 0;
  9599. }
  9600. };
  9601.  
  9602. gkp.isActive = function () {
  9603. return this[keyeC] > 0;
  9604. };
  9605.  
  9606. gkp[keyST] = function () {
  9607. this.stop(); // this[keyeC] = 0;
  9608. const fn = this[keyj];
  9609. const obj = this[keyB];
  9610. let skip = false;
  9611. if (!fn) skip = true;
  9612. else if (IGNORE_bufferhealth_CHECK && obj) {
  9613. let m;
  9614. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  9615. if (m.has("bufferhealth")) skip = true;
  9616. }
  9617. }
  9618. if (!skip) {
  9619. fn.call(obj);
  9620. }
  9621. };
  9622.  
  9623.  
  9624.  
  9625.  
  9626. /*
  9627.  
  9628. g.k.eC = 0;
  9629. g.k.xa = function() {
  9630. g.Qu.Vf.xa.call(this);
  9631. this.stop();
  9632. delete this.j;
  9633. delete this.B
  9634. }
  9635. ;
  9636. g.k.start = function(a) {
  9637. this.stop();
  9638. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  9639. }
  9640. ;
  9641. g.k.stop = function() {
  9642. this.isActive() && g.Sa.clearTimeout(this.eC);
  9643. this.eC = 0
  9644. }
  9645. ;
  9646. g.k.isActive = function() {
  9647. return 0 != this.eC
  9648. }
  9649. ;
  9650. g.k.ST = function() {
  9651. this.eC = 0;
  9652. this.j && this.j.call(this.B)
  9653. }
  9654. ;
  9655. */
  9656.  
  9657.  
  9658.  
  9659.  
  9660. })();
  9661.  
  9662. FIX_Animation_n_timeline && (async () => {
  9663.  
  9664. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  9665.  
  9666. if (!timeline || !Animation) return;
  9667.  
  9668. const aniProto = Animation.prototype;
  9669. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  9670.  
  9671. const getXroto = (x) => {
  9672. try {
  9673. return x.__proto__;
  9674. } catch (e) { }
  9675. return null;
  9676. }
  9677. const timProto = getXroto(timeline);
  9678. if (!timProto) return;
  9679. if (
  9680. (
  9681. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  9682. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  9683. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  9684. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  9685. )
  9686.  
  9687. ) {
  9688.  
  9689. timProto.nofCQ = 1;
  9690. aniProto.nofYH = 1;
  9691.  
  9692. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  9693.  
  9694.  
  9695. /*
  9696. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  9697. return c._updatePromises();
  9698. });
  9699. */
  9700.  
  9701. const p = Array.prototype.filter;
  9702.  
  9703. let res = null;
  9704. Array.prototype.filter = function () {
  9705.  
  9706. res = this;
  9707. return this;
  9708.  
  9709. };
  9710.  
  9711. _updateAnimationsPromises.call({});
  9712.  
  9713. Array.prototype.filter = p;
  9714.  
  9715. if (res && typeof res.length === 'number') {
  9716. /** @type {any[]} */
  9717. const _res = res;
  9718. return _res;
  9719. }
  9720.  
  9721.  
  9722. return null;
  9723.  
  9724.  
  9725.  
  9726.  
  9727. })(timProto._updateAnimationsPromises);
  9728.  
  9729. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  9730.  
  9731. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  9732.  
  9733. aniProto._updatePromises31 = aniProto._updatePromises;
  9734.  
  9735. /*
  9736. aniProto._updatePromises = function(){
  9737. console.log('eff',this._oldPlayState, this.playState)
  9738. return this._updatePromises31.apply(this, arguments)
  9739. }
  9740. */
  9741.  
  9742. aniProto._updatePromises = function () {
  9743. var oldPlayState = this._oldPlayState;
  9744. var newPlayState = this.playState;
  9745. // console.log('ett', oldPlayState, newPlayState)
  9746. if (newPlayState !== oldPlayState) {
  9747. this._oldPlayState = newPlayState;
  9748. if (this._readyPromise) {
  9749. if ("idle" == newPlayState) {
  9750. this._rejectReadyPromise();
  9751. this._readyPromise = void 0;
  9752. } else if ("pending" == oldPlayState) {
  9753. this._resolveReadyPromise();
  9754. } else if ("pending" == newPlayState) {
  9755. this._readyPromise = void 0;
  9756. }
  9757. }
  9758. if (this._finishedPromise) {
  9759. if ("idle" == newPlayState) {
  9760. this._rejectFinishedPromise();
  9761. this._finishedPromise = void 0;
  9762. } else if ("finished" == newPlayState) {
  9763. this._resolveFinishedPromise();
  9764. } else if ("finished" == oldPlayState) {
  9765. this._finishedPromise = void 0;
  9766. }
  9767. }
  9768. }
  9769. return this._readyPromise || this._finishedPromise;
  9770. };
  9771.  
  9772.  
  9773. let restartWebAnimationsNextTickFlag = false;
  9774.  
  9775. const looperMethodT = () => {
  9776.  
  9777. const runnerFn = (hRes) => {
  9778. var b = timeline;
  9779. b.currentTime = hRes;
  9780. b._discardAnimations();
  9781. if (0 == b._animations.length) {
  9782. restartWebAnimationsNextTickFlag = false;
  9783. } else {
  9784. getRafPromise().then(runnerFn);
  9785. }
  9786. }
  9787.  
  9788. const restartWebAnimationsNextTick = () => {
  9789. if (!restartWebAnimationsNextTickFlag) {
  9790. restartWebAnimationsNextTickFlag = true;
  9791. getRafPromise().then(runnerFn);
  9792. }
  9793. }
  9794.  
  9795. return { restartWebAnimationsNextTick }
  9796. };
  9797.  
  9798.  
  9799. const looperMethodN = () => {
  9800.  
  9801. const acs = document.createElement('a-f');
  9802. acs.id = 'a-f';
  9803.  
  9804. if (!document.getElementById('afscript')) {
  9805. const style = document.createElement('style');
  9806. style.id = 'afscript';
  9807. style.textContent = `
  9808. @keyFrames aF1 {
  9809. 0% {
  9810. order: 0;
  9811. }
  9812. 100% {
  9813. order: 1;
  9814. }
  9815. }
  9816. #a-f[id] {
  9817. visibility: collapse !important;
  9818. position: fixed !important;
  9819. display: block !important;
  9820. top: -100px !important;
  9821. left: -100px !important;
  9822. margin:0 !important;
  9823. padding:0 !important;
  9824. outline:0 !important;
  9825. border:0 !important;
  9826. z-index:-1 !important;
  9827. width: 0px !important;
  9828. height: 0px !important;
  9829. contain: strict !important;
  9830. pointer-events: none !important;
  9831. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  9832. }
  9833. `;
  9834. (document.head || document.documentElement).appendChild(style);
  9835. }
  9836.  
  9837. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  9838.  
  9839. const _onanimationiteration = function (evt) {
  9840. const hRes = evt.timeStamp;
  9841. var b = timeline;
  9842. b.currentTime = hRes;
  9843. b._discardAnimations();
  9844. if (0 == b._animations.length) {
  9845. restartWebAnimationsNextTickFlag = false;
  9846. acs.onanimationiteration = null;
  9847. } else {
  9848. acs.onanimationiteration = _onanimationiteration;
  9849. }
  9850.  
  9851. }
  9852.  
  9853.  
  9854.  
  9855. const restartWebAnimationsNextTick = () => {
  9856. if (!restartWebAnimationsNextTickFlag) {
  9857. restartWebAnimationsNextTickFlag = true;
  9858. acs.onanimationiteration = _onanimationiteration;
  9859.  
  9860. }
  9861. }
  9862.  
  9863. return { restartWebAnimationsNextTick }
  9864. };
  9865.  
  9866.  
  9867.  
  9868. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  9869.  
  9870.  
  9871. // console.log(571, timProto);
  9872. timProto._play = function (c) {
  9873. c = new Animation(c, this);
  9874. this._animations.push(c);
  9875. restartWebAnimationsNextTick();
  9876. c._updatePromises();
  9877. c._animation.play();
  9878. c._updatePromises();
  9879. return c
  9880. }
  9881.  
  9882. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  9883. originalAnimationsWithPromises.length = 0;
  9884. originalAnimationsWithPromises.push = null;
  9885. originalAnimationsWithPromises.splice = null;
  9886. originalAnimationsWithPromises.slice = null;
  9887. originalAnimationsWithPromises.indexOf = null;
  9888. originalAnimationsWithPromises.unshift = null;
  9889. originalAnimationsWithPromises.shift = null;
  9890. originalAnimationsWithPromises.pop = null;
  9891. originalAnimationsWithPromises.filter = null;
  9892. originalAnimationsWithPromises.forEach = null;
  9893. originalAnimationsWithPromises.map = null;
  9894.  
  9895.  
  9896. const _updateAnimationsPromises = () => {
  9897. animationsWithPromisesMap.forEach(c => {
  9898. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  9899. });
  9900. /*
  9901. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  9902. return c._updatePromises();
  9903. });
  9904. */
  9905. }
  9906.  
  9907. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  9908.  
  9909. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  9910.  
  9911. delete timProto._updateAnimationsPromises;
  9912. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  9913. get() {
  9914. if (animationsWithPromisesMap.size === 0) return nilFn;
  9915. return _updateAnimationsPromises;
  9916. },
  9917. set(nv) {
  9918. delete this._updateAnimationsPromises;
  9919. this._updateAnimationsPromises = nv;
  9920. },
  9921. enumerable: true,
  9922. configurable: true,
  9923. });
  9924.  
  9925.  
  9926. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  9927. aniProto.__finished_native_get__ = pdFinished.get;
  9928. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  9929.  
  9930.  
  9931. Object.defineProperty(aniProto, 'finished', {
  9932. get() {
  9933. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  9934. this._finishedPromise = new Promise((resolve, reject) => {
  9935. this._resolveFinishedPromise = function () {
  9936. resolve(this)
  9937. };
  9938. this._rejectFinishedPromise = function () {
  9939. reject({
  9940. type: DOMException.ABORT_ERR,
  9941. name: "AbortError"
  9942. })
  9943. };
  9944. }),
  9945. "finished" == this.playState && this._resolveFinishedPromise());
  9946. return this._finishedPromise
  9947. },
  9948. set: undefined,
  9949. enumerable: true,
  9950. configurable: true
  9951. });
  9952.  
  9953. }
  9954.  
  9955.  
  9956.  
  9957. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  9958. aniProto.__ready_native_get__ = pdReady.get;
  9959. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  9960.  
  9961. Object.defineProperty(aniProto, 'ready', {
  9962. get() {
  9963. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  9964. this._readyPromise = new Promise((resolve, reject) => {
  9965. this._resolveReadyPromise = function () {
  9966. resolve(this)
  9967. };
  9968. this._rejectReadyPromise = function () {
  9969. reject({
  9970. type: DOMException.ABORT_ERR,
  9971. name: "AbortError"
  9972. })
  9973. };
  9974. }),
  9975. "pending" !== this.playState && this._resolveReadyPromise());
  9976. return this._readyPromise
  9977. },
  9978. set: undefined,
  9979. enumerable: true,
  9980. configurable: true
  9981. });
  9982.  
  9983. }
  9984.  
  9985.  
  9986. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  9987.  
  9988. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  9989. const _rebuildUnderlyingAnimation = function () {
  9990. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  9991. this.effect && this.effect._onsample && (this.effect._onsample = null);
  9992. return this._rebuildUnderlyingAnimation21();
  9993. }
  9994. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  9995. // delete aniProto._rebuildUnderlyingAnimation;
  9996. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  9997. // get() {
  9998. // if (isNaN(this._sequenceNumber)) return nilFn;
  9999. // return this._rebuildUnderlyingAnimation21;
  10000. // },
  10001. // set(nv) {
  10002. // delete this._rebuildUnderlyingAnimation;
  10003. // this._rebuildUnderlyingAnimation = nv;
  10004. // },
  10005. // enumerable: true,
  10006. // configurable: true
  10007. // });
  10008. }
  10009.  
  10010.  
  10011. /*
  10012.  
  10013.  
  10014. function f(c) {
  10015. var b = v.timeline;
  10016. b.currentTime = c;
  10017. b._discardAnimations();
  10018. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  10019. }
  10020. var h = window.requestAnimationFrame;
  10021. window.requestAnimationFrame = function(c) {
  10022. return h(function(b) {
  10023. v.timeline._updateAnimationsPromises();
  10024. c(b);
  10025. v.timeline._updateAnimationsPromises()
  10026. })
  10027. }
  10028. ;
  10029. v.AnimationTimeline = function() {
  10030. this._animations = [];
  10031. this.currentTime = void 0
  10032. }
  10033. ;
  10034. v.AnimationTimeline.prototype = {
  10035. getAnimations: function() {
  10036. this._discardAnimations();
  10037. return this._animations.slice()
  10038. },
  10039. _updateAnimationsPromises: function() {
  10040. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  10041. return c._updatePromises()
  10042. })
  10043. },
  10044. _discardAnimations: function() {
  10045. this._updateAnimationsPromises();
  10046. this._animations = this._animations.filter(function(c) {
  10047. return "finished" != c.playState && "idle" != c.playState
  10048. })
  10049. },
  10050. _play: function(c) {
  10051. c = new v.Animation(c,this);
  10052. this._animations.push(c);
  10053. v.restartWebAnimationsNextTick();
  10054. c._updatePromises();
  10055. c._animation.play();
  10056. c._updatePromises();
  10057. return c
  10058. },
  10059. play: function(c) {
  10060. c && c.remove();
  10061. return this._play(c)
  10062. }
  10063. };
  10064. var d = !1;
  10065. v.restartWebAnimationsNextTick = function() {
  10066. d || (d = !0,
  10067. requestAnimationFrame(f))
  10068. }
  10069. ;
  10070. var a = new v.AnimationTimeline;
  10071. v.timeline = a;
  10072. try {
  10073. Object.defineProperty(window.document, "timeline", {
  10074. configurable: !0,
  10075. get: function() {
  10076. return a
  10077. }
  10078. })
  10079. } catch (c) {}
  10080. try {
  10081. window.document.timeline = a
  10082. } catch (c) {}
  10083.  
  10084. */
  10085.  
  10086.  
  10087.  
  10088. /*
  10089.  
  10090. var g = window.getComputedStyle;
  10091. Object.defineProperty(window, "getComputedStyle", {
  10092. configurable: !0,
  10093. enumerable: !0,
  10094. value: function() {
  10095. v.timeline._updateAnimationsPromises();
  10096. var e = g.apply(this, arguments);
  10097. h() && (e = g.apply(this, arguments));
  10098. v.timeline._updateAnimationsPromises();
  10099. return e
  10100. }
  10101. });
  10102.  
  10103. */
  10104.  
  10105.  
  10106.  
  10107.  
  10108. }
  10109.  
  10110.  
  10111.  
  10112.  
  10113. })();
  10114.  
  10115. !isUrlInEmbed && Promise.resolve().then(() => {
  10116.  
  10117. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  10118.  
  10119.  
  10120.  
  10121. class LimitedSizeSet extends Set {
  10122. constructor(n) {
  10123. super();
  10124. this.limit = n;
  10125. }
  10126.  
  10127. add(key) {
  10128. if (!super.has(key)) {
  10129. super.add(key);
  10130. let n = super.size - this.limit;
  10131. if (n > 0) {
  10132. const iterator = super.values();
  10133. do {
  10134. const firstKey = iterator.next().value; // Get the first (oldest) key
  10135. super.delete(firstKey); // Delete the oldest key
  10136. } while (--n > 0)
  10137. }
  10138. }
  10139. }
  10140.  
  10141. removeAdd(key) {
  10142. super.delete(key);
  10143. this.add(key);
  10144. }
  10145.  
  10146. }
  10147.  
  10148. // const wk3 = new WeakMap();
  10149.  
  10150. // let mtxVideoId = '';
  10151. // let aje3 = [];
  10152. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  10153. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  10154. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  10155. let mtzCount = 0; // the key keeps unchanged
  10156. // let mjtNextMainKey = '';
  10157. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  10158. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  10159. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  10160. // let allowNoDelay322=false;
  10161. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  10162.  
  10163. let mpKey22 = ''; // last success continutation key & url pair
  10164. let mpUrl22 = ''; // last success continutation key & url pair
  10165. let mpKey21 = ''; // latest requested continutation key & url pair
  10166. let mpUrl21 = ''; // latest requested continutation key & url pair
  10167.  
  10168.  
  10169. async function sha1Hex(message) {
  10170. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  10171. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  10172. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  10173. const hashHex = hashArray
  10174. .map((b) => b.toString(16).padStart(2, "0"))
  10175. .join(""); // convert bytes to hex string
  10176. return hashHex;
  10177. }
  10178.  
  10179. async function continuationLog(a, ...args) {
  10180. let b = a;
  10181. try {
  10182. if (advanceLogging) b = await sha1Hex(a);
  10183. let c = args.map(e => {
  10184. return e === a ? b : e
  10185. });
  10186. console.log(...c)
  10187. } catch (e) { console.warn(e) }
  10188. }
  10189.  
  10190. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  10191.  
  10192.  
  10193. if (mfvContinuationRecorded.length > 0) {
  10194. for (const [e, d] of mfvContinuationRecorded) {
  10195. mfyContinuationIgnored.removeAdd(e);
  10196. }
  10197. toClearRecorded && mfvContinuationRecorded.clear();
  10198. }
  10199.  
  10200. }
  10201.  
  10202. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  10203.  
  10204. const tmProto = taskMgr.constructor.prototype;
  10205. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  10206.  
  10207. if (!tmProto.addJob714) {
  10208.  
  10209. tmProto.addJob714 = tmProto.addJob;
  10210.  
  10211. tmProto.addJob = function (a, b, c) {
  10212. const jobId = this.addJob714(a, b, c);
  10213. if (jobId > 0) {
  10214. // const ez = wk3.get(this);
  10215. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  10216. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  10217.  
  10218. this.__lastJobId863__ = jobId;
  10219. }
  10220. return jobId;
  10221. }
  10222.  
  10223. }
  10224.  
  10225. if (!tmProto.cancelJob714) {
  10226.  
  10227. tmProto.cancelJob714 = tmProto.cancelJob;
  10228.  
  10229. tmProto.cancelJob = function (a) {
  10230. const res = this.cancelJob714(a);
  10231. // if (a > 0) {
  10232. // for (const e of aje3) {
  10233. // if (e.jobId === a) e.cancelled = true;
  10234. // }
  10235. // }
  10236. return res;
  10237. }
  10238.  
  10239. }
  10240.  
  10241. }
  10242. }
  10243.  
  10244.  
  10245. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  10246.  
  10247.  
  10248. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  10249. let dummy;
  10250. let cProto;
  10251. // let mc = 4;
  10252. // dummy = await observablePromise(() => {
  10253. // const r = document.querySelector('ytd-video-primary-info-renderer');
  10254. // if (!r) return;
  10255. // let cProto = insp(r).constructor.prototype;
  10256. // if (cProto.fetchUpdatedMetadata) return r;
  10257. // if (--mc < 0) return -1;
  10258. // return null;
  10259. // }).obtain();
  10260. dummy = document.createElement('ytd-video-primary-info-renderer');
  10261. if (!(dummy instanceof Element)) return;
  10262. // console.log(5022, dummy)
  10263. cProto = insp(dummy).constructor.prototype;
  10264.  
  10265. cProto.__getEmittorTaskMgr859__ = function () {
  10266. let taskMgr_ = null;
  10267. try {
  10268. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  10269. } catch (e) { }
  10270. return taskMgr_;
  10271. }
  10272. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  10273. // console.log(1234, cProto, cProto.is)
  10274. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  10275.  
  10276. let c_;
  10277. cProto.fetchUpdatedMetadata718 = function (a) {
  10278. // delay or immediate call the actual fetchUpdatedMetadata
  10279.  
  10280. let doImmediately = false;
  10281. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  10282.  
  10283. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  10284.  
  10285. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  10286.  
  10287. doImmediately = true;
  10288.  
  10289. }
  10290.  
  10291. if (mbCId322) {
  10292. clearTimeout(mbCId322);
  10293. mbCId322 = 0;
  10294. }
  10295.  
  10296. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  10297.  
  10298. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  10299.  
  10300. mbCId322 = setTimeout(() => {
  10301. this.fetchUpdatedMetadata717(a);
  10302. }, delay);
  10303.  
  10304. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  10305.  
  10306. }
  10307.  
  10308. cProto.fetchUpdatedMetadata = function (a) {
  10309.  
  10310. if (!pageSetupState) {
  10311. if (c_) clearTimeout(c_);
  10312. c_ = setTimeout(() => {
  10313. this.fetchUpdatedMetadata718(a);
  10314. }, 300);
  10315. return;
  10316. }
  10317.  
  10318. // pageSetupState == 0
  10319.  
  10320. try {
  10321.  
  10322. mbDelayBelowNCalls++;
  10323.  
  10324. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  10325. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  10326. }
  10327.  
  10328. // console.log('fum377', a)
  10329. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  10330. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  10331. return;
  10332. }
  10333.  
  10334. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  10335. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  10336. mjtLockPreviousKey = mjtRecordedPrevKey;
  10337. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  10338. }
  10339. // mjtNextMainKey = true;
  10340. mtzlastAllowedContinuation = '';
  10341. mtzCount = 0;
  10342. // allowNoDelay322 = false;
  10343. // fetch new metadata, cancel all previous continuations
  10344. copyPreviousContiuationToIgnored374(true);
  10345. } else if (typeof a === 'string') {
  10346. const videoPlayingId = videoPlayingY.videoId;
  10347.  
  10348. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  10349.  
  10350. let update21 = !!pageSetupVideoId;
  10351. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  10352. update21 = true;
  10353. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  10354. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  10355. return;
  10356. }
  10357. if (update21) {
  10358. mpKey21 = a;
  10359. mpUrl21 = pageSetupVideoId || videoPlayingId;
  10360. }
  10361.  
  10362. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  10363. }
  10364. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  10365. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  10366. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  10367. return this.fetchUpdatedMetadata718(a);
  10368.  
  10369. } catch (e) {
  10370. console.log('Code Error in fetchUpdatedMetadata', e);
  10371. }
  10372. return this.fetchUpdatedMetadata717(a)
  10373. }
  10374. }
  10375.  
  10376.  
  10377. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  10378. // console.log(1234, cProto, cProto.is)
  10379. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  10380. let mJob = null;
  10381.  
  10382. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  10383.  
  10384. try {
  10385.  
  10386. if (arguments.length > 0) {
  10387. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  10388. }
  10389. // mfy = mfv;
  10390.  
  10391. // mjtNextMainKey = '';
  10392. mtzlastAllowedContinuation = '';
  10393. mtzCount = 0;
  10394. if (mbCId322) {
  10395. clearTimeout(mbCId322);
  10396. mbCId322 = 0;
  10397. }
  10398. mbDelayBelowNCalls = 0;
  10399. // allowNoDelay322 = false;
  10400. copyPreviousContiuationToIgnored374(true);
  10401.  
  10402. const taskMgr = this.__getEmittorTaskMgr859__();
  10403. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  10404. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  10405. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  10406. }
  10407.  
  10408. // prevent depulicated schedule job by clearing previous JobId
  10409. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  10410.  
  10411. let res;
  10412.  
  10413. if (mJob) {
  10414. const job = mJob;
  10415. mJob = null;
  10416. console.log('cancelJob', job)
  10417. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  10418. // p.cancelJob(a,b);
  10419. }
  10420.  
  10421. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  10422.  
  10423. let pza = taskMgr.__lastJobId863__;
  10424. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  10425. let pzb = taskMgr.__lastJobId863__
  10426. if (pza !== pzb) {
  10427. mJob = pzb; // set [Interval Meta Update] jobId
  10428. }
  10429.  
  10430. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  10431. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  10432. // } else {
  10433. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  10434. // }
  10435.  
  10436. return res;
  10437.  
  10438. } else {
  10439. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  10440. }
  10441.  
  10442. } catch (e) {
  10443. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  10444. }
  10445.  
  10446.  
  10447. return this.scheduleInitialUpdatedMetadataRequest717();
  10448. }
  10449. }
  10450.  
  10451.  
  10452. });
  10453.  
  10454. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  10455. let dummy;
  10456. let cProto;
  10457. dummy = ytAppDom;
  10458. if (!(dummy instanceof Element)) return;
  10459. cProto = insp(dummy).constructor.prototype;
  10460. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  10461. // console.log(1234, cProto, cProto.is);
  10462. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10463. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  10464. // console.log(123401, arguments);
  10465. // return this.handleServiceRequest717_(a, b, c, d);
  10466. // }
  10467.  
  10468. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10469.  
  10470. // cProto.handleServiceRequest_ = function(a,b,c,d){
  10471. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10472. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  10473. // console.log('mfv', c.continuation);
  10474. // mfv.add( c.continuation);
  10475. // }
  10476. // return this.handleServiceRequest717_(a,b,c,d);
  10477. // }
  10478.  
  10479. function extraArguments322(a, b, c) {
  10480. let is = (a || 0).is;
  10481. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  10482. let continuation = (c || 0).continuation;
  10483. if (typeof is !== 'string') is = null;
  10484. if (typeof videoId !== 'string') videoId = null;
  10485. if (typeof continuation !== 'string') continuation = null;
  10486. return { is, videoId, continuation };
  10487. }
  10488.  
  10489. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  10490. cProto.sendServiceAjax_ = function (a, b, c, d) {
  10491.  
  10492. // console.log(8001)
  10493. try {
  10494.  
  10495. const { is, videoId, continuation } = extraArguments322(a, b, c);
  10496.  
  10497. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10498. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  10499. }
  10500.  
  10501. if (pageSetupVideoId && videoId && continuation) {
  10502. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10503. mfyContinuationIgnored.removeAdd(continuation);
  10504. mfvContinuationRecorded.delete(continuation);
  10505. return;
  10506. }
  10507. }
  10508.  
  10509. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10510. copyPreviousContiuationToIgnored374(false);
  10511. mfyContinuationIgnored.delete(continuation);
  10512. mfvContinuationRecorded.removeAdd(continuation);
  10513. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10514. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10515. mjtLockPreviousKey = '';
  10516. }
  10517. // if (mjtNextMainKey === continuation) {
  10518. // copyPreviousContiuationToIgnored(false);
  10519. // mfyContinuationIgnored.delete(continuation);
  10520. // mfvContinuationRecorded.add(continuation);
  10521. // }
  10522.  
  10523.  
  10524. if (mfyContinuationIgnored && continuation) {
  10525. if (mfyContinuationIgnored.has(continuation)) {
  10526. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  10527. return;
  10528. }
  10529. }
  10530.  
  10531. // console.log(59902, a?.is, b,c,d)
  10532. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10533. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  10534. // console.log('mfv377', continuation);
  10535. mfvContinuationRecorded.add(continuation);
  10536. }
  10537.  
  10538. // if (videoId) {
  10539. // if (!pageSetupVideoId) return; // ignore page not ready
  10540. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10541. // if (videoId !== pageSetupVideoId) {
  10542. // return;
  10543. // }
  10544. // }
  10545.  
  10546. } catch (e) {
  10547. console.log('Coding Error in sendServiceAjax_', e)
  10548. }
  10549. // console.log(8002)
  10550. // console.log(123402, arguments);
  10551. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  10552.  
  10553. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  10554. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  10555. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  10556. // get(target, prop, receiver){
  10557. // console.log('xxs99', target.videoId, mtx)
  10558. // if(prop ==='kdkw33') return 1;
  10559. // console.log(3322, prop, target)
  10560. // if(prop === 'initialDelayMs') {
  10561. // throw new Error("ABCC");
  10562. // }
  10563. // return target[prop];
  10564. // },
  10565. // set(target, prop, value, receiver){
  10566.  
  10567. // if(prop ==='kdkw33') return true;
  10568. // target[prop]=value;
  10569. // return true;
  10570. // }
  10571. // });
  10572. // }
  10573. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  10574. return this.sendServiceAjax717_(a, b, c, d);
  10575. }
  10576. }
  10577.  
  10578. function delayClearOtherKeys(lztContinuation) {
  10579. // // schedule delayed removal if mfyContinuationIgnored is not empty
  10580. // getRafPromise().then(() => {
  10581. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  10582. // // foreground page only
  10583.  
  10584. // });
  10585.  
  10586.  
  10587. if (lztContinuation !== mtzlastAllowedContinuation) return;
  10588. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  10589. if (!mfyContinuationIgnored.size) return;
  10590. if (mfyContinuationIgnored.size > 1) {
  10591. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  10592. }
  10593. mfyContinuationIgnored.forEach((value, key) => {
  10594. if (key !== lztContinuation) {
  10595. mfyContinuationIgnored.delete(key);
  10596. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  10597. }
  10598. });
  10599.  
  10600. }
  10601. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  10602. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  10603. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  10604.  
  10605. // console.log(8003)
  10606. try {
  10607.  
  10608.  
  10609. const { is, videoId, continuation } = extraArguments322(b, c, d);
  10610.  
  10611. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10612. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  10613. }
  10614.  
  10615. if (pageSetupVideoId && videoId && continuation) {
  10616. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10617. mfyContinuationIgnored.removeAdd(continuation);
  10618. mfvContinuationRecorded.delete(continuation);
  10619. return;
  10620. }
  10621. }
  10622.  
  10623. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10624. copyPreviousContiuationToIgnored374(false);
  10625. mfyContinuationIgnored.delete(continuation);
  10626. mfvContinuationRecorded.removeAdd(continuation);
  10627. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10628. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10629. mjtLockPreviousKey = '';
  10630. }
  10631.  
  10632. // if (mjtNextMainKey === continuation) {
  10633. // copyPreviousContiuationToIgnored(false);
  10634. // mfyContinuationIgnored.delete(continuation);
  10635. // mfvContinuationRecorded.add(continuation);
  10636. // }
  10637.  
  10638. const lztContinuation = continuation;
  10639.  
  10640. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  10641. if (mfyContinuationIgnored.has(lztContinuation)) {
  10642. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  10643. return;
  10644. }
  10645. }
  10646.  
  10647. // if (videoId) {
  10648. // if (!pageSetupVideoId) return; // ignore page not ready
  10649. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10650. // if (videoId !== pageSetupVideoId) {
  10651. // return;
  10652. // }
  10653. // }
  10654.  
  10655. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  10656. mtzlastAllowedContinuation = lztContinuation;
  10657. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  10658.  
  10659. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  10660. mjtRecordedPrevKey = lztContinuation;
  10661. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  10662. // if (mfyContinuationIgnored.size > 0) {
  10663. // delayClearOtherKeys(lztContinuation);
  10664. // }
  10665. mtzCount = 0;
  10666. // allowNoDelay322 = false;
  10667. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  10668. // repeated
  10669. if (++mtzCount > 1e9) mtzCount = 1e4;
  10670. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  10671.  
  10672. // if (mtzCount >= 3) allowNoDelay322 = true;
  10673. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  10674. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  10675. }
  10676. if (mtzCount === 5) {
  10677. mfvContinuationRecorded.clear();
  10678. mfvContinuationRecorded.add(lztContinuation);
  10679. }
  10680.  
  10681. }
  10682.  
  10683. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  10684. mpKey22 = lztContinuation;
  10685. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  10686. }
  10687.  
  10688. if (mbCId322) {
  10689. clearTimeout(mbCId322);
  10690. mbCId322 = 0;
  10691. }
  10692. } catch (e) {
  10693. console.log('Coding Error in getCancellableNetworkPromise_', e)
  10694. }
  10695.  
  10696. // console.log(8004)
  10697. // console.log(123403, arguments);
  10698. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  10699.  
  10700. // console.log(5163, a?.is,b,c,d,e);
  10701. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  10702. }
  10703. }
  10704. });
  10705.  
  10706. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  10707.  
  10708.  
  10709. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  10710.  
  10711. let dummy;
  10712. let cProto;
  10713.  
  10714. dummy = document.createElement('ytd-expander');
  10715. cProto = insp(dummy).constructor.prototype;
  10716.  
  10717. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  10718.  
  10719. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  10720. cProto.childrenChanged14 = cProto.childrenChanged;
  10721.  
  10722. cProto.initChildrenObserver = function () {
  10723. var a = this;
  10724. this.observer = new MutationObserver(function () {
  10725. a.childrenChanged()
  10726. }
  10727. );
  10728. this.observer.observe(this.content, {
  10729. subtree: !0,
  10730. childList: !0,
  10731. attributes: !0,
  10732. characterData: !0
  10733. });
  10734. this.childrenChanged()
  10735. }
  10736. ;
  10737. cProto.childrenChanged = function () {
  10738. if (this.alwaysToggleable) {
  10739. this.canToggle = this.alwaysToggleable;
  10740. } else if (!this.canToggleJobId) {
  10741. this.canToggleJobId = 1;
  10742. foregroundPromiseFn().then(() => {
  10743. this.canToggleJobId = 0;
  10744. this.calculateCanCollapse()
  10745. })
  10746. }
  10747. }
  10748.  
  10749. // console.log(cProto.initChildrenObserver)
  10750. console.debug('ytd-expander-fix-childrenChanged');
  10751.  
  10752. }
  10753.  
  10754. });
  10755.  
  10756.  
  10757. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  10758.  
  10759. let dummy;
  10760. let cProto;
  10761. dummy = document.createElement('paper-ripple');
  10762. cProto = insp(dummy).constructor.prototype;
  10763.  
  10764. if (fnIntegrity(cProto.animate, '0.74.5')) {
  10765.  
  10766.  
  10767. cProto.animate34 = cProto.animate;
  10768. cProto.animate = function () {
  10769. if (this._animating) {
  10770. var a;
  10771. const ripples = this.ripples;
  10772. for (a = 0; a < ripples.length; ++a) {
  10773. var b = ripples[a];
  10774. b.draw();
  10775. this.$.background.style.opacity = b.outerOpacity;
  10776. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  10777. }
  10778. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  10779. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  10780. foregroundPromiseFn().then(this._boundAnimate38);
  10781. } else {
  10782. this.onAnimationComplete();
  10783. }
  10784. }
  10785. }
  10786.  
  10787. console.debug('FIX_paper_ripple_animate')
  10788.  
  10789. // console.log(cProto.animate)
  10790.  
  10791. }
  10792.  
  10793. });
  10794.  
  10795. if (FIX_doIdomRender) {
  10796.  
  10797. const xsetTimeout = function (f, d) {
  10798. if (xsetTimeout.m511 === 1 && !d) {
  10799. xsetTimeout.m511 = 2;
  10800. xsetTimeout.m568 = f;
  10801. } else {
  10802. return setTimeout.apply(window, arguments)
  10803. }
  10804.  
  10805. }
  10806.  
  10807. /**
  10808. *
  10809. IGb = function(a) {
  10810. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  10811. c || (a.requestAninmationFrameResolver = new Vi,
  10812. c = a.requestAninmationFrameResolver.promise,
  10813. Da.requestAnimationFrame(function() {
  10814. var d;
  10815. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  10816. a.requestAninmationFrameResolver = null
  10817. }));
  10818. return c
  10819. }
  10820.  
  10821.  
  10822. */
  10823.  
  10824. const xrequestAnimationFrame = function (f) {
  10825. const h = `${f}`;
  10826. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  10827. let t = null;
  10828. xsetTimeout.m511 = 1;
  10829. f();
  10830. if (xsetTimeout.m511 === 2) {
  10831. t = xsetTimeout.m568;
  10832. xsetTimeout.m568 = null;
  10833. }
  10834. xsetTimeout.m511 = 0;
  10835. if (typeof t === 'function') {
  10836. foregroundPromiseFn().then(t);
  10837. }
  10838. } else if (h.includes("requestAninmationFrameResolver")) {
  10839. foregroundPromiseFn().then(f);
  10840. } else {
  10841. return requestAnimationFrame.apply(window, arguments);
  10842. }
  10843. }
  10844.  
  10845. let busy = false;
  10846. const doIdomRender = function () {
  10847.  
  10848. if (!this) return;
  10849. if (busy) {
  10850. return this.doIdomRender13(...arguments);
  10851. }
  10852. busy = true;
  10853. const { requestAnimationFrame, setTimeout } = window;
  10854. window.requestAnimationFrame = xrequestAnimationFrame;
  10855. window.setTimeout = xsetTimeout;
  10856. let r = this.doIdomRender13(...arguments);
  10857. window.requestAnimationFrame = requestAnimationFrame;
  10858. window.setTimeout = setTimeout;
  10859. busy = false;
  10860. return r;
  10861. };
  10862. 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']) {
  10863.  
  10864.  
  10865. whenCEDefined(ytTag).then(() => {
  10866.  
  10867. let dummy;
  10868. let cProto;
  10869. dummy = document.createElement(ytTag);
  10870. cProto = insp(dummy).constructor.prototype;
  10871.  
  10872. cProto.doIdomRender13 = cProto.doIdomRender;
  10873. cProto.doIdomRender = doIdomRender;
  10874.  
  10875. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  10876.  
  10877. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  10878.  
  10879.  
  10880.  
  10881. });
  10882.  
  10883. }
  10884.  
  10885. }
  10886.  
  10887.  
  10888.  
  10889.  
  10890. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  10891.  
  10892. const sMap = new Map();
  10893.  
  10894. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  10895. const ZT = function () {
  10896. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  10897. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  10898. c = b & 15,
  10899. b >>= 4,
  10900. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  10901. return a.join("")
  10902. };
  10903.  
  10904.  
  10905. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  10906.  
  10907. const popupContainer = await observablePromise(() => {
  10908. return popupContainerCollection[0];
  10909. }).obtain();
  10910.  
  10911.  
  10912. let cProto;
  10913. cProto = insp(popupContainer).constructor.prototype;
  10914.  
  10915.  
  10916. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  10917. console.log('FIX_POPUP_UNIQUE_ID NG')
  10918. return;
  10919. }
  10920. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  10921.  
  10922. cProto.handleOpenPopupAction = function (a, b) {
  10923.  
  10924. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  10925.  
  10926. a.__jOdQA__ = true;
  10927.  
  10928. try {
  10929.  
  10930. const h = this.hostElement;
  10931.  
  10932. if (h instanceof HTMLElement) {
  10933.  
  10934. const map = h.__skme44__ = h.__skme44__ || new Map();
  10935.  
  10936. let mKey = '';
  10937. const wKey = firstObjectKey(a);
  10938. const wObj = wKey ? a[wKey] : null;
  10939. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  10940. const pKey = firstObjectKey(wObj.popup)
  10941. const pObj = pKey ? wObj.popup[pKey] : null;
  10942. let contentKey = '';
  10943. let headerKey = '';
  10944.  
  10945. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  10946. contentKey = firstObjectKey(pObj.content)
  10947. headerKey = firstObjectKey(pObj.header)
  10948. }
  10949. if (contentKey && headerKey) {
  10950.  
  10951. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  10952.  
  10953. if (mKey) {
  10954.  
  10955. if (!wObj.uniqueId) {
  10956. for (let i = 0; i < 8; i++) {
  10957. wObj.uniqueId = ZT();
  10958. if (!sMap.has(wObj.uniqueId)) break;
  10959. }
  10960. }
  10961. const oId = wObj.uniqueId
  10962.  
  10963. let nId_ = map.get(mKey);
  10964. if (!nId_) {
  10965. map.set(mKey, nId_ = oId);
  10966. }
  10967.  
  10968. wObj.uniqueId = nId_ || wObj.uniqueId;
  10969.  
  10970. const nId = wObj.uniqueId
  10971.  
  10972. sMap.set(oId, nId);
  10973. sMap.set(nId, nId);
  10974.  
  10975. wObj.uniqueId = nId;
  10976. pObj.targetId = nId;
  10977. pObj.identifier.tag = nId;
  10978.  
  10979. if (oId !== nId) {
  10980. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  10981. }
  10982.  
  10983. }
  10984.  
  10985. }
  10986. }
  10987.  
  10988. // console.log(12213, mKey, a, b, h)
  10989.  
  10990. }
  10991.  
  10992. } catch (e) {
  10993. console.warn(e)
  10994. }
  10995.  
  10996. try {
  10997.  
  10998. const results = searchNestedObject(a, (x) => {
  10999. if (typeof x === 'string' && x.length === 36) {
  11000. 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;
  11001. }
  11002. return false;
  11003. });
  11004. for (const [obj, key] of results) {
  11005. const oId = obj[key];
  11006. const nId = sMap.get(oId);
  11007. if (nId) obj[key] = nId;
  11008. }
  11009. } catch (e) {
  11010. console.warn(e)
  11011. }
  11012.  
  11013.  
  11014. }
  11015.  
  11016. return this.handleOpenPopupAction3868(...arguments)
  11017. }
  11018.  
  11019. console.log('FIX_POPUP_UNIQUE_ID OK')
  11020.  
  11021.  
  11022. });
  11023.  
  11024.  
  11025. // FIX_TRANSCRIPT_SEGMENTS && (async ()=>{
  11026.  
  11027.  
  11028. // })();
  11029.  
  11030. // FIX_TRANSCRIPT_SEGMENTS && whenCEDefined('ytd-transcript-search-panel-renderer').then(async () => {
  11031.  
  11032.  
  11033. // let dummy;
  11034. // let cProto;
  11035. // dummy = document.createElement('ytd-transcript-search-panel-renderer');
  11036. // cProto = insp(dummy).constructor.prototype;
  11037.  
  11038.  
  11039. // if (!cProto || typeof cProto.bodyChanged !== 'function' || cProto.bodyChanged1848 || cProto.bodyChanged.length !== 0) {
  11040. // console.log('FIX_TRANSCRIPT_SEGMENTS NG')
  11041. // return;
  11042. // }
  11043. // cProto.bodyChanged1848 = cProto.bodyChanged;
  11044.  
  11045. // const wmx = new WeakMap();
  11046.  
  11047. // const sb35 = Symbol();
  11048. // cProto.bodyChanged = function () {
  11049. // let a = null;
  11050. // try {
  11051. // a = this.getBodyRenderer();
  11052. // } catch (e) { }
  11053. // if (!a || !a.initialSegments) {
  11054. // a = this.data;
  11055. // if (a.body) a = a.body;
  11056. // if (a.transcriptSegmentListRenderer) a = a.transcriptSegmentListRenderer;
  11057. // }
  11058. // const a_ = a;
  11059. // const initialSegments = (a_ || 0).initialSegments;
  11060. // if (typeof (initialSegments || 0) === 'object' && initialSegments.length >= 1){
  11061. // ((async () => { })()).then(() => {
  11062.  
  11063. // const c = wmx.get(initialSegments);
  11064. // if (!c) {
  11065. // const d = translateFn(initialSegments);
  11066. // wmx.set(initialSegments, d);
  11067. // console.log('translated', d);
  11068. // wmx.set(d, d);
  11069. // a_.initialSegments = d;
  11070. // } else {
  11071. // a_.initialSegments = c;
  11072. // }
  11073.  
  11074.  
  11075. // }).then(() => {
  11076. // // this.bodyChanged1848();
  11077. // });
  11078.  
  11079. // }else{
  11080.  
  11081. // // return this.bodyChanged1848();
  11082. // }
  11083. // }
  11084.  
  11085. // console.log('FIX_TRANSCRIPT_SEGMENTS OK')
  11086.  
  11087.  
  11088.  
  11089.  
  11090. // });
  11091.  
  11092.  
  11093. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  11094.  
  11095. let dummy;
  11096. let cProto;
  11097. dummy = document.createElement('yt-formatted-string');
  11098. cProto = insp(dummy).constructor.prototype;
  11099.  
  11100. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  11101. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  11102. return;
  11103. }
  11104.  
  11105. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  11106. cProto.setNodeStyle_ = function (a, b) {
  11107. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  11108. return this.setNodeStyle17_(a, b);
  11109. }
  11110.  
  11111. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  11112. });
  11113.  
  11114. });
  11115.  
  11116. });
  11117.  
  11118.  
  11119.  
  11120.  
  11121. if (isMainWindow) {
  11122.  
  11123. console.groupCollapsed(
  11124. "%cYouTube JS Engine Tamer",
  11125. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  11126. );
  11127.  
  11128.  
  11129.  
  11130. console.log("Script is loaded.");
  11131. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  11132.  
  11133. console.log("This script is experimental and subject to further changes.");
  11134.  
  11135. console.log("This might boost your YouTube performance.");
  11136.  
  11137. console.log("CAUTION: This might break your YouTube.");
  11138.  
  11139.  
  11140. if (prepareLogs.length >= 1) {
  11141. console.log(" =========================================================================== ");
  11142.  
  11143. for (const msg of prepareLogs) {
  11144. console.log(msg)
  11145. }
  11146.  
  11147. console.log(" =========================================================================== ");
  11148. }
  11149.  
  11150. console.groupEnd();
  11151.  
  11152. }
  11153.  
  11154.  
  11155.  
  11156. })();