YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @name:ja YouTube JS Engine Tamer
  4. // @name:zh-TW YouTube JS Engine Tamer
  5. // @name:zh-CN YouTube JS Engine Tamer
  6. // @namespace UserScripts
  7. // @version 0.31.1
  8. // @match https://www.youtube.com/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @match https://studio.youtube.com/live_chat*
  11. // @license MIT
  12. // @author CY Fung
  13. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  14. // @grant none
  15. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@c2b707e4977f77792042d4a5015fb188aae4772e/library/nextBrowserTick.min.js
  16. // @run-at document-start
  17. // @unwrap
  18. // @inject-into page
  19. // @allFrames true
  20. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  21. //
  22. // @description To enhance YouTube performance by modifying YouTube JS Engine
  23. // @description:ja YouTubeのJSエンジンを変更してパフォーマンスを向上させる
  24. // @description:zh-TW 修改 YouTube 的 JS 引擎以提升效能
  25. // @description:zh-CN 修改 YouTube 的 JS 引擎以提升性能
  26. //
  27. // ==/UserScript==
  28.  
  29. (() => {
  30.  
  31. /** @type {WeakMapConstructor} */
  32. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  33.  
  34. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  35. const FIX_schedulerInstanceInstance = 2 | 4;
  36. const FIX_yt_player = true; // DONT CHANGE
  37. const FIX_Animation_n_timeline = true;
  38. const NO_PRELOAD_GENERATE_204 = false;
  39. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  40. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  41. const CHANGE_appendChild = true; // discussions#236759
  42. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  43. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  44.  
  45. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  46. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  47. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  48.  
  49. const FIX_Iframe_NULL_SRC = false;
  50.  
  51. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  52.  
  53. const FIX_ytdExpander_childrenChanged = true;
  54. const FIX_paper_ripple_animate = true;
  55. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  56. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  57.  
  58. const FIX_doIdomRender = true;
  59.  
  60. const FIX_Shady = true;
  61.  
  62. // [[ 2024.04.24 ]]
  63. const MODIFY_ShadyDOM_OBJ = true;
  64. // << if MODIFY_ShadyDOM_OBJ >>
  65. const WEAKREF_ShadyDOM = true;
  66. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  67. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  68. // << end >>
  69.  
  70. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  71.  
  72. const FIX_ytAction_ = true; // ytd-app
  73. const FIX_onVideoDataChange = false;
  74. // const FIX_onClick = true;
  75. const FIX_onStateChange = true;
  76. const FIX_onLoopRangeChange = true;
  77. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  78. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  79.  
  80. const ENABLE_discreteTasking = false; // removed since 0.20.0
  81. const FIX_stampDomArray_ = true; // v0.30.0
  82. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  83. const stampDomArray_MemoryFix_Flag001 = false;
  84. const XFlag = true; // DON'T CHANGE
  85. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  86. // 32 required for new stampDomArray
  87. // 128 to be tested
  88.  
  89. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  90. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  91.  
  92. const FIX_Polymer_dom = true;
  93. const FIX_Polymer_AF = true;
  94.  
  95. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  96. const DEBUG_removePrune = false; // true for DEBUG
  97.  
  98. const FIX_XHR_REQUESTING = true;
  99.  
  100. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  101.  
  102. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  103.  
  104. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  105. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  106.  
  107. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  108.  
  109. const FIX_removeChild = true;
  110. const FIX_fix_requestIdleCallback_timing = true;
  111.  
  112. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  113. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  114.  
  115. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  116.  
  117. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  118.  
  119. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  120. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  121. // first tp-yt-paper-dialog: show once the page is loaded.
  122. // second tp-yt-paper-dialog: click "...more"
  123. // third tp-yt-paper-dialog: click "... and 3 more links"
  124. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  125. // currently, uniqueId is preassigned by the network resolveCommand.
  126. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  127. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  128.  
  129. // handleOpenPopupAction -> createCacheKey
  130. // handleClosePopupAction_ -> createCacheKey
  131. // handleGetPopupOpenedAction_ -> createCacheKey
  132. // getAndMaybeCreatePopup_ -> createCacheKey
  133. // closePopup -> createCacheKey
  134.  
  135. // yt-close-popup-command -> handleClosePopupCommand_
  136.  
  137. // ensurePopup_ -> getAndMaybeCreatePopup_
  138.  
  139. // yt-close-popup-action -> handleClosePopupAction_
  140. // closePopup -> handleClosePopupAction_
  141. // handleOpenPopupAction -> handleClosePopupAction_
  142. // handleClosePopupCommand_ -> handleClosePopupAction_
  143. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  144.  
  145. // yt-open-popup-action -> handleOpenPopupAction
  146.  
  147.  
  148. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  149. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  150.  
  151. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  152. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  153. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  154.  
  155.  
  156. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  157. const FIX_DOM_IF_TEMPLATE = true;
  158. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  159. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  160. const DEBUG_DBR847 = false;
  161. const DEBUG_xx847 = false;
  162. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  163. const DEBUG_renderDebounceTs = false;
  164.  
  165. const FIX_ICON_RENDER = true;
  166.  
  167. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  168.  
  169. /*
  170.  
  171. FIX_DOM_IFREPEAT_RenderDebouncerChange
  172.  
  173. avoid Polymer.flush
  174. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  175.  
  176. var Is = function() {
  177. do {
  178. var a = window.ShadyDOM && ShadyDOM.flush();
  179. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  180. var b = NNa()
  181. } while (a || b)
  182. };
  183.  
  184. , NNa = function() {
  185. var a = !!ts.size;
  186. ts.forEach(function(b) {
  187. try {
  188. b.flush()
  189. } catch (c) {
  190. setTimeout(function() {
  191. throw c
  192. })
  193. }
  194. });
  195. return a
  196. };
  197.  
  198. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  199. // this coding logic should be incorrect (mistake).
  200.  
  201. */
  202.  
  203.  
  204.  
  205. // ----------------------------- Shortkey Keyboard Control -----------------------------
  206. // dependency: FIX_yt_player
  207.  
  208. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  209. // [0] no fix - not recommended
  210. // [1] basic fix - just fix the global focus detection variable
  211. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  212. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  213.  
  214. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  215. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  216.  
  217. const PROP_OverReInclusion_AVOID = true;
  218. const PROP_OverReInclusion_DEBUGLOG = false;
  219. const PROP_OverReInclusion_LIST = new Set([
  220. 'hostElement72',
  221. 'parentComponent72',
  222. 'localVisibilityObserver_72',
  223. 'cachedProviderNode_72',
  224. '__template72',
  225. '__templatizeOwner72',
  226. '__templateInfo72',
  227. '__dataHost72',
  228. '__CE_shadowRoot72',
  229. 'elements_72',
  230.  
  231. 'ky36',
  232. 'kz62',
  233. 'm822',
  234.  
  235.  
  236.  
  237. // To be reviewed.
  238.  
  239. // chat messages
  240. 'disabled', 'allowedProps',
  241. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  242.  
  243. 'dimension', 'loadTime', 'pendingPaint',
  244.  
  245. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  246.  
  247. 'respectLangDir', 'noEndpoints',
  248.  
  249.  
  250. 'objectURL',
  251. 'buttonOverrides', 'queuedMessages',
  252. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  253. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  254. 'hoverJobId', 'JSC$14573_touched',
  255.  
  256.  
  257. // tbc
  258. 'toggleable', 'isConnected',
  259. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  260. 'disableDeselectEvent',
  261. 'emojiSize',
  262.  
  263. 'buttonOverride',
  264. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  265.  
  266. // others
  267. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  268. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  269. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  270. // 'dimension', 'loadTime', 'pendingPaint',
  271. // 'disabled', 'allowedProps',
  272.  
  273.  
  274. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  275. // 'actionMap',
  276.  
  277. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  278.  
  279. 'clearTimeout',
  280. 'switchTemplateAtRegistration', 'hasUnmounted',
  281. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  282. 'tangoConfiguration',
  283. 'itemIdToDockDurationMap',
  284. 'actionMap',
  285.  
  286. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  287. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  288. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  289.  
  290. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  291. // 'stopKeyboardEventPropagation', 'emojiSize',
  292. // 'switchTemplateAtRegistration', 'hasUnmounted',
  293. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  294. // 'isReusable', 'tangoConfiguration',
  295. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  296. // */
  297.  
  298. ]);
  299.  
  300.  
  301. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  302.  
  303. // ----------------------------- Shortkey Keyboard Control -----------------------------
  304.  
  305. /*
  306. window.addEventListener('edm',()=>{
  307. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  308. });
  309.  
  310. window.addEventListener('edn',()=>{
  311. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  312. });
  313. window.addEventListener('edr',()=>{
  314. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  315. });
  316. */
  317.  
  318. // only for macOS with Chrome/Firefox 100+
  319. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  320.  
  321. const win = this instanceof Window ? this : window;
  322.  
  323. // Create a unique key for the script and check if it is already running
  324. const hkey_script = 'jswylcojvzts';
  325. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  326. win[hkey_script] = true;
  327.  
  328.  
  329.  
  330. const wk = Symbol();
  331.  
  332. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  333.  
  334. let BY_PASS_KEYBOARD_CONTROL = false;
  335.  
  336.  
  337. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  338. /** @type {(f: ()=>{})=>{}} */
  339. const nextBrowserTick_ = nextBrowserTick;
  340. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  341. console.log('nextBrowserTick is not found.');
  342. return;
  343. }
  344.  
  345. let p59 = 0;
  346.  
  347. const Promise = (async () => { })().constructor;
  348.  
  349. const PromiseExternal = ((resolve_, reject_) => {
  350. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  351. return class PromiseExternal extends Promise {
  352. constructor(cb = h) {
  353. super(cb);
  354. if (cb === h) {
  355. /** @type {(value: any) => void} */
  356. this.resolve = resolve_;
  357. /** @type {(reason?: any) => void} */
  358. this.reject = reject_;
  359. }
  360. }
  361. };
  362. })();
  363.  
  364. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  365. constructor(callback = undefined) {
  366.  
  367. }
  368. register(target, heldValue, unregisterToken = undefined) {
  369.  
  370. }
  371. unregister(unregisterToken) {
  372.  
  373. }
  374. }
  375.  
  376. let ttpHTML = (s) => {
  377. ttpHTML = s => s;
  378. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  379. let s = s => s;
  380. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  381. }
  382. return s;
  383. }
  384.  
  385.  
  386. /** @type { typeof HTMLElement } */
  387. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  388. const nativeAppendE = HTMLElement_.prototype.append;
  389. const nativeRemoveE = HTMLElement_.prototype.remove;
  390. const DocumentFragment_ = DocumentFragment;
  391. const nativeAppendD = DocumentFragment_.prototype.append;
  392. const Node_ = Node;
  393.  
  394. /**
  395. @param {number} x
  396. @param {number} d */
  397. const toFixed2 = (x, d) => {
  398. let t = x.toFixed(d);
  399. let y = `${+t}`;
  400. return y.length > t.length ? t : y;
  401. }
  402.  
  403.  
  404. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  405.  
  406.  
  407. const TRANSLATE_DEBUG = false;
  408.  
  409.  
  410. let xdeadc00 = null; // a deteched node with __domApi
  411. let xlivec00 = null; // a deteched node with __domApi
  412.  
  413. let removeTNodeRM = null;
  414. let removeTNodeBP = false;
  415.  
  416.  
  417.  
  418.  
  419. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  420.  
  421. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  422.  
  423. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  424.  
  425. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  426.  
  427.  
  428. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  429. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  430. return;
  431. }
  432.  
  433.  
  434. const mapGet = Map.prototype.get;
  435. const setHas = Set.prototype.has;
  436.  
  437.  
  438. /** @type {Map | null} */
  439. let qcMap = null;
  440.  
  441. Set.prototype.has = function (a) {
  442. if (a === 'dummy-4718') return false; // false to allow re-use?
  443. return setHas.call(this, a);
  444. }
  445.  
  446. Map.prototype.get = function (a) {
  447. if (a === 'dummy-4718') qcMap = this;
  448. return mapGet.call(this, a);
  449. };
  450. let r;
  451. try {
  452. r = mainCnt.createComponent_('dummy-4718', {}, true);
  453. } catch (e) {
  454.  
  455. }
  456.  
  457. Map.prototype.get = mapGet;
  458. Set.prototype.has = setHas;
  459.  
  460. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  461.  
  462.  
  463. // clearInterval(ckId);
  464. // ckId = 0;
  465.  
  466. if (qcMap !== null && qcMap instanceof Map) {
  467.  
  468. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  469. qcMap.__qcMap8781__ = true;
  470.  
  471. const setArrayC = (c) => {
  472. if (c instanceof Array) {
  473. c.length = 0;
  474. c.push = function () { };
  475. c.pop = function () { };
  476. c.shift = function () { };
  477. c.unshift = function () { };
  478. c.splice = function () { };
  479. c.sort = function () { };
  480. c.reverse = function () { };
  481. }
  482. }
  483.  
  484. const cleaning = function (m) {
  485. m.forEach(setArrayC);
  486. m.clear();
  487. }
  488.  
  489. qcMap.set = function (b, c) {
  490. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  491.  
  492. setArrayC(c);
  493.  
  494. // console.log('qcMap.set', b, c);
  495.  
  496. if (this.size > 0) {
  497. // play safe
  498.  
  499. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  500. cleaning(this);
  501. }
  502.  
  503. }
  504. qcMap.get = function (b) {
  505. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  506.  
  507. // console.log('qcMap.get', b);
  508.  
  509. if (this.size > 0) {
  510. // play safe
  511.  
  512. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  513. cleaning(this);
  514. }
  515.  
  516. }
  517.  
  518.  
  519. if (qcMap.size > 0) {
  520.  
  521. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  522. cleaning(qcMap);
  523. }
  524.  
  525. }
  526.  
  527. }
  528.  
  529. r = null;
  530. qcMap = null;
  531.  
  532. }
  533.  
  534.  
  535. const dispatchYtEvent = function (a, b, c, d) {
  536. d || (d = {
  537. bubbles: !0,
  538. cancelable: !1,
  539. composed: !0
  540. });
  541. c !== null && c !== void 0 && (d.detail = c);
  542. b = new CustomEvent(b, d);
  543. a.dispatchEvent(b);
  544. return b
  545. };
  546.  
  547.  
  548. if (XFlag) {
  549.  
  550. const cMap = new Set();
  551. cMap.add = cMap.addOriginal || cMap.add;
  552. const yMap = new Set();
  553. yMap.add = yMap.addOriginal || yMap.add;
  554.  
  555.  
  556. const ydMap = new Set();
  557. ydMap.add = ydMap.addOriginal || ydMap.add;
  558.  
  559. window.yMap = yMap;
  560. window.cMap = cMap;
  561. window.ydMap = ydMap;
  562.  
  563. const constructAts = new Set();
  564. constructAts.add = constructAts.addOriginal || constructAts.add;
  565. window.constructAts = constructAts;
  566.  
  567. const kMap = new WeakMap();
  568.  
  569. const kRefProp = (wr, prop)=>{
  570. let o = kRef(wr);
  571. return o ? o[prop] : null;
  572. }
  573.  
  574. const wrObj = (objRef, props) => {
  575. let wr = mWeakRef(objRef);
  576. if (wr === objRef || !props || !props.length) return wr;
  577. let properties = {};
  578. props.forEach(k => {
  579. properties[k] = {
  580. get() {
  581. return kRefProp(this, k)
  582. },
  583. enumerable: false,
  584. configurable: true
  585. };
  586. });
  587. Object.defineProperties(wr, properties);
  588. return wr;
  589. }
  590.  
  591. const sProtos = {};
  592.  
  593. const setupCProto = function (cProto) {
  594.  
  595. if(cProto === Object.prototype) return;
  596.  
  597. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  598. cProto[kMap.get(cProto)] = true;
  599. // debugger;
  600.  
  601. const constructAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  602. constructAts.add(constructAt)
  603.  
  604. if (MemoryFix_Flag002 & 32) {
  605. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  606. fixDetachFn(cProto);
  607. }
  608. }
  609.  
  610. if (cProto.stampDomArray_ && !cProto.__stampDX38__) {
  611.  
  612. cProto.__stampDX38__ = true;
  613.  
  614. if (cProto.stampDomArray_.length === 6) {
  615. const pendingFinishContainers = new Map();
  616. const producerMap2 = new WeakMap();
  617. const mutObs = new MutationObserver((mutations) => {
  618. if (pendingFinishContainers.size === 0) return;
  619. let dirtyProducers = new Map();
  620. pendingFinishContainers.forEach((p, containerWr) => {
  621. const container = kRef(containerWr);
  622. if (!container) return pendingFinishContainers.delete(containerWr);
  623. const producerWr = producerMap2.get(container);
  624. if (!producerWr) return pendingFinishContainers.delete(containerWr);
  625. const producer = kRef(producerWr);
  626. if (!producer) return pendingFinishContainers.delete(containerWr);
  627. let dirtyVal = dirtyProducers.get(producer);
  628. if (dirtyVal === false) return;
  629. if (!dirtyVal) {
  630. const hostElement = producer.hostElement;
  631. if (!hostElement) return pendingFinishContainers.delete(containerWr);
  632. if (hostElement.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  633. dirtyProducers.set(producer, false);
  634. return;
  635. }
  636. }
  637. pendingFinishContainers.delete(containerWr);
  638. if (!dirtyVal) dirtyProducers.set(producer, (dirtyVal = new Set()));
  639. let o = dirtyVal;
  640. if (p === 'e') {
  641. o.add(container);
  642. }
  643. });
  644. if (dirtyProducers.size === 0) return;
  645. dirtyProducers.forEach((o, producer) => {
  646. if (o instanceof Set) {
  647. const hostElement = producer.hostElement;
  648. hostElement.removeAttribute('ytx-debug-0173');
  649. producer.markDirty && producer.markDirty();
  650. for (const container of o) {
  651. dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  652. container
  653. });
  654. }
  655. o.clear();
  656. }
  657. });
  658. dirtyProducers.clear();
  659. dirtyProducers = null;
  660. });
  661.  
  662.  
  663. /*
  664. cProto.stampDomArray8581_ = cProto.stampDomArray_;
  665.  
  666. cProto.stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  667.  
  668. const lastByPass01 = this.__lastByPass__
  669. if (this.__stampTaskMap488__ instanceof Map) this.__stampTaskMap488__.delete(containerId);
  670.  
  671. const b = this.flushRenderStamperComponentBindings_;
  672. this.flushRenderStamperComponentBindings_ = function () {
  673. b.call(this);
  674. throw new Error('82919');
  675. }
  676. let r, e_;
  677. try {
  678. r = this.stampDomArray8581_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  679. } catch (e) {
  680. e_ = e;
  681. }
  682. if (Reflect.getPrototypeOf(this).flushRenderStamperComponentBindings_ === b) {
  683. delete this.flushRenderStamperComponentBindings_;
  684. }
  685. if (this.flushRenderStamperComponentBindings_ !== b) {
  686. this.flushRenderStamperComponentBindings_ = b;
  687. }
  688.  
  689. const lastByPass02 = this.__lastByPass__
  690. if (e_ && e_.message !== '82919') throw e_;
  691. if (e_ && e_.message === '82919') {
  692.  
  693. if (lastByPass01 !== lastByPass02 && (lastByPass02 & 1)) {
  694. console.log(123288, this.hostElement.nodeName)
  695. const producer = this;
  696. const container = producer.getStampContainer_(containerId);
  697. const hostElement = producer.hostElement;
  698. hostElement.setAttribute('ytx-debug-0173', '')
  699. if (!producer[wk]) producer[wk] = mWeakRef(producer);
  700. if (!container[wk]) container[wk] = mWeakRef(container);
  701. producerMap2.set(container, producer[wk]);
  702. const currentVal = pendingFinishContainers.get(container[wk]);
  703. const newVal = bEventCb ? 'e' : '1';
  704. if (newVal === 'e' && currentVal !== newVal) {
  705. pendingFinishContainers.set(container[wk], newVal);
  706. } else if (newVal === '1' && !currentVal) {
  707. pendingFinishContainers.set(container[wk], newVal);
  708. }
  709. mutObs.observe(hostElement, { subtree: true, childList: true });
  710. hostElement.appendChild(document.createComment('-')).remove();
  711. }
  712. }
  713. return r;
  714. }
  715. */
  716.  
  717.  
  718. if (MemoryFix_Flag002 & 1) {
  719. cProto.stampDomArray_.bind = sProtos.stampDomArray_$bind || (sProtos.stampDomArray_$bind = function (obj, ...args) {
  720. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  721. return () => {
  722. const obj = kRef(wobj);
  723. let u = Reflect.apply(this, obj, args);
  724. args.length = 0;
  725. wobj = null;
  726. return u;
  727. };
  728. });
  729. }
  730. }
  731.  
  732. }
  733.  
  734. if (MemoryFix_Flag002 & 2) {
  735. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  736. cProto.__setPropDX38__ = true;
  737.  
  738. if (cProto._setPendingProperty.length === 3) {
  739. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  740. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  741. return () => {
  742. const obj = kRef(wobj);
  743. let u = Reflect.apply(this, obj, args);
  744. args.length = 0;
  745. wobj = null;
  746. return u;
  747. };
  748. });
  749. }
  750.  
  751. }
  752. }
  753.  
  754. if (MemoryFix_Flag002 & 4) {
  755. if (cProto._runEffectsForTemplate && !cProto.__runEffectDX38__) {
  756. cProto.__runEffectDX38__ = true;
  757.  
  758. if (cProto._runEffectsForTemplate.length === 4) {
  759. cProto._runEffectsForTemplate3858 = cProto._runEffectsForTemplate;
  760. cProto._runEffectsForTemplate = sProtos._runEffectsForTemplate || (sProtos._runEffectsForTemplate = function (c, d, e, g) {
  761. if (c && c.runEffects) {
  762. let wr = wrObj(c, ['propertyEffects', 'nodeList', 'firstChild']);
  763. // console.log(12837)
  764. if (!this[wk]) this[wk] = mWeakRef(this);
  765. if ((typeof (e || 0) === "object") && !e[wk]) e[wk] = mWeakRef(e);
  766. let cntWr = this[wk];
  767. let eWr = (typeof (e || 0) === "object") ? e[wk] : e;
  768. c.runEffects((n, r) => {
  769. // console.log(12838)
  770. const cnt = kRef(cntWr);
  771. const e = kRef(eWr);
  772. if (cnt) {
  773. cnt._runEffectsForTemplate3858(wr, n, e, r);
  774. }
  775. wr = cntWr = d = e = g = null;
  776. }, d, g);
  777. } else {
  778. let { propertyEffects, nodeList, firstChild } = c;
  779. let o = { propertyEffects, nodeList, firstChild }
  780. this._runEffectsForTemplate3858(o, d, e, g);
  781. o.propertyEffects = o.nodeList = o.firstChild = null;
  782. propertyEffects = nodeList = firstChild = null;
  783. o = null;
  784. }
  785.  
  786. });
  787.  
  788. cProto._runEffectsForTemplate.bind = sProtos._runEffectsForTemplate$bind || (sProtos._runEffectsForTemplate$bind = function (obj, ...args) {
  789. // console.log(12993, args)
  790. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  791. return () => {
  792. const obj = kRef(wobj);
  793. let u = Reflect.apply(this, obj, args);
  794. args.length = 0;
  795. wobj = null;
  796. return u;
  797. };
  798. });
  799. }
  800.  
  801. }
  802. }
  803.  
  804.  
  805.  
  806.  
  807.  
  808. const cProtoConstructor = cProto.constructor;
  809.  
  810. if (MemoryFix_Flag002 & 8) {
  811. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  812. cProtoConstructor.__parseBindingsDX38__ = true;
  813.  
  814. ydMap.add(cProtoConstructor);
  815.  
  816. if (cProtoConstructor._parseBindings.length === 2) {
  817.  
  818. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  819.  
  820. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  821. let p = this._parseBindings3858(c, d);
  822. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  823. if (p) this.__bindingsArrs__.push(p);
  824. return p;
  825. });
  826.  
  827. }
  828. }
  829. }
  830.  
  831. /*
  832. a.prototype._initializeProperties = function() {
  833. if (Em && this.hasAttribute("disable-upgrade"))
  834. this.__isUpgradeDisabled = !0;
  835. else {
  836. var e = Object.getPrototypeOf(this);
  837. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  838. e.__hasRegisterFinished = !0);
  839. b.prototype._initializeProperties.call(this);
  840. this.root = this;
  841. this.created();
  842. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  843. this._applyListeners()
  844. }
  845. }
  846. */
  847. /*
  848. bOa = function(a, b, c) {
  849. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  850. d.prototype.is = b;
  851. d.prototype.localName = b;
  852. c && aOa(d, c);
  853. return function(e) {
  854. e && (d.prototype.hostElement = e);
  855. var g = new d;
  856. g.root = g;
  857. g.hostElement = e;
  858. return g
  859. }
  860. }
  861. */
  862.  
  863.  
  864. }
  865. const symDH = Symbol();
  866.  
  867. const wfStore = new WeakMap();
  868.  
  869. const wrapF = function (f, key) {
  870. if (wfStore.get(f)) return wfStore.get(f);
  871.  
  872. let g = function () {
  873. const o = kRef(this);
  874. if (!o) return;
  875. const cnt = insp(o);
  876. // if (cnt === o) return;
  877. // if (!('ready' in cnt)) return;
  878. return f.apply(o, arguments);
  879. };
  880. g.key38 = key;
  881. g.originalFunc38 = f;
  882. g.__wrapF84__ = true;
  883. wfStore.set(f, g);
  884. wfStore.set(g, g);
  885. return g;
  886. };
  887.  
  888. if (MemoryFix_Flag002 & 16) {
  889. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  890.  
  891. Object.defineProperty(Node.prototype, key, {
  892. get() {
  893. return this[`__a0939${key}__`];
  894. },
  895. set(nv) {
  896. if (typeof nv !== 'function') return;
  897. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  898. this[`__a0939${key}__`] = g;
  899. return true;
  900. }
  901. });
  902.  
  903.  
  904. });
  905. }
  906.  
  907.  
  908. const fragQ = document.createDocumentFragment(); // for cleaup removal
  909. const fixDetachFn = (tpProto) => {
  910.  
  911. if (tpProto.dk322) return;
  912. tpProto.dk322 = true;
  913.  
  914. tpProto.__detachInstance994 = tpProto.__detachInstance;
  915. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  916. tpProto.__detachInstance = function (a) {
  917. const u = this.__instances[a];
  918. if (u && u.root) {
  919. const children = u ? u.children : null;
  920. if (children && children.length >= 1) {
  921. this.__detachInstance994(a);
  922. }
  923. } else if (u && !u.root) {
  924. const children = u ? u.children : null;
  925. if (children && children.length >= 1) {
  926. for (let i = 0, l = children.length; i < l; i++) {
  927. const node = children[i];
  928. fragQ.appendChild(node); // for cleanup
  929. Promise.resolve(node).then(node => (node.parentNode === fragQ) && !!node.remove());
  930. }
  931. }
  932. }
  933. return u;
  934. }
  935. }
  936.  
  937.  
  938.  
  939. tpProto.__attachInstance994 = tpProto.__attachInstance;
  940. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  941. tpProto.__attachInstance = function (a, b) {
  942. const u = this.__instances[a];
  943. if (u && u.root && b) {
  944. fragQ.appendChild(u.root); // for cleanup
  945. return this.__attachInstance994(a, b);
  946. }
  947. }
  948. }
  949.  
  950. }
  951. const ytTemplateDomEntry = (tpProto) => {
  952.  
  953. console.log('ytTemplateDomEntry triggered')
  954.  
  955.  
  956. const convertToWeakArr = (arr) => {
  957.  
  958.  
  959. if (arr.isWeak) return;
  960.  
  961. for (let i = 0, l = arr.length; i < l; i++) {
  962. const o = arr[i]
  963. if (o) {
  964. let p = kRef(o)
  965. if (!p) arr[i] = null;
  966. else {
  967. if (!o[wk]) o[wk] = mWeakRef(o);
  968. arr[i] = o[wk];
  969. }
  970. }
  971. }
  972. arr.isWeak = true;
  973.  
  974. }
  975.  
  976. const convertToNormalArr = (arr) => {
  977.  
  978. if (!arr.isWeak) return;
  979.  
  980. for (let i = 0, l = arr.length; i < l; i++) {
  981. const o = arr[i]
  982. if (o) {
  983. let p = kRef(o)
  984. arr[i] = p;
  985. }
  986. }
  987. arr.isWeak = false;
  988.  
  989. }
  990.  
  991. if (MemoryFix_Flag002 & 256) {
  992. Object.defineProperty(tpProto, '__instances', {
  993. get() {
  994. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  995. let arr = this.__instances_actual471__;
  996. convertToNormalArr(arr);
  997. Promise.resolve(arr).then(convertToWeakArr);
  998. return arr;
  999. },
  1000. set(nv) {
  1001. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  1002. this.__instances_actual471__ = nv;
  1003. Promise.resolve(nv).then(convertToWeakArr);
  1004. return true;
  1005. },
  1006. enumerable: false,
  1007. configurable: true
  1008. });
  1009. }
  1010.  
  1011. // console.log(91901, tpProto.__detachInstance)
  1012. if (MemoryFix_Flag002 & 32) {
  1013. if (tpProto.__detachInstance) {
  1014. fixDetachFn(tpProto);
  1015. } else {
  1016. Promise.resolve(tpProto).then((tpProto) => {
  1017. // console.log(91902, tpProto.__detachInstance)
  1018. fixDetachFn(tpProto);
  1019. })
  1020. }
  1021. }
  1022.  
  1023. }
  1024.  
  1025. if (MemoryFix_Flag002 & 32) {
  1026. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  1027. set(nv) {
  1028. if (nv === true) return false;
  1029. tpProto = this;
  1030. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  1031. tpProto.__domDX37__ = true;
  1032. ytTemplateDomEntry(tpProto);
  1033. }
  1034. this.__ensureTemplatized949__ = nv;
  1035. return true;
  1036. },
  1037. get() {
  1038. return this.__ensureTemplatized949__;
  1039. }
  1040. });
  1041. }
  1042.  
  1043.  
  1044. if (MemoryFix_Flag002 & 64) {
  1045. HTMLElement_.prototype.__dataHostBinding374 = true;
  1046. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  1047. get() {
  1048. return kRef(this.__dataHostWr413__);
  1049. },
  1050. set(nv) {
  1051. if (nv && typeof nv === 'object' && !nv.deref) {
  1052. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1053. nv = nv[wk];
  1054. }
  1055. this.__dataHostWr413__ = nv;
  1056. return true;
  1057. }
  1058. });
  1059. }
  1060.  
  1061.  
  1062. const setupYProto = function (yProto) {
  1063.  
  1064. if(yProto === Object.prototype) return;
  1065.  
  1066. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  1067. yProto[kMap.get(yProto)] = true;
  1068.  
  1069. if (MemoryFix_Flag002 & 32) {
  1070. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  1071. fixDetachFn(yProto);
  1072. }
  1073. }
  1074.  
  1075. if (MemoryFix_Flag002 & 128) {
  1076. if (!yProto.__dataHostBinding374) {
  1077. yProto.__dataHostBinding374 = true;
  1078. Object.defineProperty(yProto, '__dataHost', {
  1079. set(nv) {
  1080. let dh = nv;
  1081. if (dh && typeof dh === 'object' && !dh.deref) {
  1082. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  1083. dh = wr;
  1084. }
  1085. this[symDH] = dh;
  1086. return true;
  1087. },
  1088. get() {
  1089. let wr = this[symDH];
  1090. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  1091. return obj;
  1092. },
  1093. enumerable: false,
  1094. configurable: true
  1095. });
  1096. }
  1097.  
  1098.  
  1099.  
  1100. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  1101. yProto._registerHostDX38__ = true;
  1102.  
  1103. // yProto._registerHost7133 = yProto._registerHost;
  1104.  
  1105. yProto.__enableOrFlushClients = function () {
  1106. const c_ = this.__dataPendingClients;
  1107. if (c_) {
  1108. const c = c_.slice();
  1109. c_.length = 0;
  1110. for (let d = 0, l = c.length; d < l; d++) {
  1111. let e = kRef(c[d]);
  1112. if (e) {
  1113. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  1114. }
  1115. }
  1116. }
  1117. }
  1118.  
  1119. yProto._enqueueClient = function (c) {
  1120. if (c === this || !c || typeof c !== 'object') return;
  1121. if (c.deref) c = kRef(c);
  1122. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  1123. if (!c[wk]) c[wk] = mWeakRef(c);
  1124. m.push(c[wk]);
  1125. }
  1126.  
  1127. }
  1128. }
  1129.  
  1130.  
  1131.  
  1132. }
  1133. const setupRendering = function () {
  1134.  
  1135. const cnt = this;
  1136. const cProto = Reflect.getPrototypeOf(cnt);
  1137. let yProto = Reflect.getPrototypeOf(cProto);
  1138.  
  1139. const yProtos = new Set();
  1140.  
  1141. if (!yMap.has(yProto)) {
  1142. // capture all ancenstor constructors of a and b (non-specific component type)
  1143.  
  1144. do {
  1145. if (yProto === Object.prototype || yProto === null) break;
  1146. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  1147. yProtos.add(yProto);
  1148. yProto = Reflect.getPrototypeOf(yProto);
  1149. } while (!yProtos.has(yProto));
  1150.  
  1151. for (const yProto of yProtos) {
  1152. yMap.add(yProto);
  1153. setupYProto(yProto)
  1154. }
  1155.  
  1156. }
  1157.  
  1158.  
  1159. if (!cMap.has(cProto)) {
  1160. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  1161. setupCProto(cProto);
  1162. }
  1163.  
  1164. }
  1165.  
  1166. const selfRef = {}; // no change. just key
  1167.  
  1168.  
  1169. let wm3 = new WeakMap();
  1170.  
  1171. Object.defineProperty(Object.prototype, 'root', {
  1172. get() {
  1173. const p = this ? kRef(this) : null;
  1174. const r = p ? wm3.get(p) : null;
  1175. const r2 = r ? kRef(r) : null;
  1176. if (r === selfRef) return p;
  1177. return r2;
  1178. },
  1179. set(nv) {
  1180. const p = this ? kRef(this) : null;
  1181. const mv = nv ? kRef(nv) : null;
  1182. if (typeof mv !== 'object') return;
  1183. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  1184. p.__setupRendered399__ = true;
  1185. setupRendering.call(p);
  1186. }
  1187. if (mv && mv.is && !mv.__setupRendered399__) {
  1188. mv.__setupRendered399__ = true;
  1189. setupRendering.call(mv);
  1190. }
  1191. if (mv === p) {
  1192. wm3.set(p, selfRef)
  1193. return true;
  1194. }
  1195. let gv = nv;
  1196. if (nv && !nv[wk]) {
  1197. gv = nv[wk] = mWeakRef(nv);
  1198. }
  1199. if (p) {
  1200. wm3.set(p, gv);
  1201. }
  1202. return true;
  1203. },
  1204. enumerable: false,
  1205. configurable: true
  1206. });
  1207.  
  1208.  
  1209.  
  1210. }
  1211.  
  1212. function getTranslate() {
  1213.  
  1214. pLoad.then(() => {
  1215.  
  1216. let nonce = document.querySelector('style[nonce]');
  1217. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1218. const st = document.createElement('style');
  1219. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1220. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  1221. let parent;
  1222. if (parent = document.head) parent.appendChild(st);
  1223. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  1224.  
  1225. });
  1226.  
  1227. const snCache = new Map();
  1228.  
  1229. if (TRANSLATE_DEBUG) {
  1230. console.log(11)
  1231. }
  1232.  
  1233. /** @type {(str: string?) => string} */
  1234. function _snippetText(str) {
  1235. // str can be underfinded
  1236. if (!str || typeof str !== 'string') return '';
  1237. let res = snCache.get(str);
  1238. if (res === undefined) {
  1239. let b = false;
  1240. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  1241. b = true;
  1242. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  1243. });
  1244. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  1245. b = true;
  1246. return '';
  1247. });
  1248. if (b) {
  1249. snCache.set(str, res);
  1250. snCache.set(res, null);
  1251. } else {
  1252. res = null;
  1253. snCache.set(str, null);
  1254. }
  1255. }
  1256. return res === null ? str : res;
  1257. }
  1258.  
  1259. /** @type {(snippet: Object) => string} */
  1260. function snippetText(snippet) {
  1261. let runs = snippet.runs;
  1262. const n = runs.length;
  1263. if (n === 1) return _snippetText(runs[0].text);
  1264. let res = new Array(n);
  1265. let ci = 0;
  1266. for (const s of runs) {
  1267. res[ci++] = _snippetText(s.text);
  1268. }
  1269. return res.join('\n');
  1270. }
  1271.  
  1272. const _DEBUG_szz = (t) => t.map(x => {
  1273. const tsr = x.transcriptSegmentRenderer;
  1274. return ({
  1275. t: tsr.snippet.runs.map(x => x.text).join('//'),
  1276. a: tsr.startMs,
  1277. b: tsr.endMs
  1278. });
  1279. });
  1280.  
  1281. const fixRuns = (runs) => {
  1282. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  1283. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  1284. const text = runs[0].text;
  1285. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  1286. const s = text.split(nlc);
  1287. let bi = 0;
  1288. runs.length = s.length;
  1289. for (const text of s) {
  1290. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  1291. }
  1292. }
  1293. for (const s of runs) {
  1294. s.text = _snippetText(s.text);
  1295. }
  1296. }
  1297.  
  1298. function translate(initialSegments) {
  1299. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  1300.  
  1301. if (!initialSegments) return initialSegments;
  1302.  
  1303. if (TRANSLATE_DEBUG) {
  1304. console.log(12);
  1305. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  1306. let obj = JSON.parse(r);
  1307. console.log(7558, 1, obj)
  1308. return obj;
  1309. }).then(p => {
  1310. let obj = _DEBUG_szz(p)
  1311. console.log(7558, 2, obj)
  1312. })
  1313. }
  1314.  
  1315.  
  1316. //let mapRej = new WeakSet();
  1317.  
  1318. const n1 = initialSegments.length;
  1319. if (!n1) return fRes;
  1320. let n2 = 0;
  1321.  
  1322.  
  1323. const fRes = new Array(n1);
  1324. // -----------------------------------------------------------------------------------------
  1325.  
  1326. const s8 = Symbol();
  1327.  
  1328. {
  1329.  
  1330. /** @type {Map<String, Object>} */
  1331. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  1332.  
  1333. // /-* * @type {Map<String, number>} *-/
  1334. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  1335. // 1: ok
  1336. // 2: abandoned effect text
  1337.  
  1338. for (const initialSegment of initialSegments) {
  1339. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  1340. if (!transcript) {
  1341. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1342. fRes[n2++] = initialSegment;
  1343. continue;
  1344. }
  1345. const runs = transcript.snippet.runs
  1346. if (!runs || runs.length === 0) {
  1347. initialSegment[s8] = true;
  1348. continue;
  1349. }
  1350. let startMs = (+transcript.startMs || 0); //integer
  1351. let endMs = (+transcript.endMs || 0); //integer
  1352. if (startMs === endMs) {
  1353. // effect text
  1354. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1355. //mapRej.add(initialSegment)
  1356. continue;
  1357. }
  1358. if (endMs - startMs < 30) {
  1359. continue;
  1360. }
  1361. const text = snippetText(transcript.snippet);
  1362. const hEntry = cacheTexts.get(text);
  1363. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  1364. if (mh1e === 2) continue;
  1365. const entry = {
  1366. startMs,
  1367. endMs,
  1368. initialSegment,
  1369. text
  1370. };
  1371. if (mh1e === 0) {
  1372. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  1373. initialSegment[s8] = true;
  1374. cacheTexts.set(text, null);
  1375. //effect only
  1376. // https://www.youtube.com/watch?v=zLak0dxBKpM
  1377. //mapRej.add(initialSegment)
  1378. continue;
  1379. }
  1380. } else if (hEntry) {
  1381.  
  1382. const timeDiff = entry.startMs - hEntry.endMs;
  1383. let shouldMerge = false;
  1384.  
  1385. if (timeDiff >= 0) {
  1386.  
  1387. if (timeDiff < 25) {
  1388. shouldMerge = true;
  1389. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  1390. shouldMerge = true;
  1391. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  1392. shouldMerge = true;
  1393. }
  1394.  
  1395. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  1396. // abandon the current entry.
  1397. // absorbed by previous entry
  1398. hEntry.endMs = entry.endMs;
  1399. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1400. //mapRej.add(entry.initialSegment);
  1401. continue;
  1402. }
  1403.  
  1404. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  1405.  
  1406. // abandon the current entry.
  1407. // absorbed by previous entry
  1408. if (entry.endMs > hEntry.endMs) {
  1409. hEntry.endMs = entry.endMs;
  1410. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1411. }
  1412. //mapRej.add(entry.initialSegment);
  1413. continue;
  1414.  
  1415. }
  1416.  
  1417. }
  1418. //if not abandoned
  1419. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  1420. // for (const s of runs) {
  1421. // s.text = _snippetText(s.text);
  1422. // }
  1423. fixRuns(runs);
  1424. fRes[n2++] = initialSegment;
  1425. }
  1426.  
  1427. // cacheTexts.clear(); // let GC do it.
  1428. cacheTexts = null;
  1429. // mh1.clear(); // let GC do it.
  1430. // mh1 = null;
  1431.  
  1432. }
  1433.  
  1434. const si_length = fRes.length = n2;
  1435. const sj_length = n1;
  1436.  
  1437. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  1438. // collect the abandon text to become second subtitle
  1439.  
  1440. let sj_start = 0;
  1441. let invalid_sj = -1;
  1442. for (let si = 0; si < si_length; si++) {
  1443. const segment = fRes[si];
  1444. let transcript = segment.transcriptSegmentRenderer;
  1445. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  1446. const runs = transcript.snippet.runs;
  1447. // fixRuns(runs);
  1448. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  1449. const main_startMs = (+transcript.startMs || 0);
  1450. const main_endMs = (+transcript.endMs || 0);
  1451. transcript = null;
  1452.  
  1453. /** @type {Map<string, number>} */
  1454. let tMap = new Map(); // avoid duplicate with javascript object properties
  1455.  
  1456. // assume that it is asc-ordered array of key startMs;
  1457. for (let sj = sj_start; sj < sj_length; sj++) {
  1458. const initialSegment = initialSegments[sj];
  1459.  
  1460. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  1461.  
  1462. const tSegment = initialSegment.transcriptSegmentRenderer;
  1463.  
  1464. if (!tSegment) {
  1465. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1466. invalid_sj = sj; // should invalid_sj be set ?
  1467. continue;
  1468. }
  1469.  
  1470. const startMs = (+tSegment.startMs || 0)
  1471. const isStartValid = startMs >= main_startMs;
  1472. if (!isStartValid) {
  1473. invalid_sj = sj;
  1474. continue;
  1475. }
  1476. // isStartValid must be true
  1477. if (startMs > main_endMs) {
  1478. sj_start = invalid_sj + 1;
  1479. break;
  1480. }
  1481.  
  1482. const endMs = (+tSegment.endMs || 0)
  1483. if (endMs <= main_endMs) {
  1484. const mt = snippetText(tSegment.snippet);
  1485. const prev = tMap.get(mt);
  1486. if (endMs >= startMs) {
  1487. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  1488. }
  1489. }
  1490.  
  1491. }
  1492.  
  1493. if (tMap.size <= 1) continue; // no second line
  1494. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  1495. tMap = null;
  1496.  
  1497. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1498.  
  1499. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  1500.  
  1501. let targetZ = rg[1][1];
  1502. if (targetZ > 4) {
  1503. let az = 0;
  1504. let fail = false;
  1505. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  1506. az += rg[idx][1];
  1507. if (az >= targetZ) {
  1508. fail = true;
  1509. break;
  1510. }
  1511. }
  1512. if (!fail) {
  1513. const rgA = rg[0][0];
  1514. const rgB = rg[1][0];
  1515. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  1516. if (isDiff && rgA === _snippetText(runs[0].text)) {
  1517. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  1518. runs.push({ text: rgB, blockLine: true });
  1519. }
  1520. }
  1521. }
  1522. rg = null;
  1523. }
  1524.  
  1525. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  1526.  
  1527. let obj = r;
  1528. console.log(7559, 1, obj)
  1529. return obj;
  1530. }).then(p => {
  1531. let obj = _DEBUG_szz(p)
  1532. console.log(7559, 2, obj)
  1533.  
  1534. });
  1535. }
  1536.  
  1537. // -----------------------------------------------------------------------------------------
  1538. snCache.clear();
  1539. return fRes;
  1540.  
  1541. }
  1542.  
  1543.  
  1544. return translate
  1545.  
  1546. }
  1547.  
  1548.  
  1549. let translateFn = null;
  1550.  
  1551. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  1552.  
  1553. const wmx = new WeakMap();
  1554.  
  1555. function fixSegments(ytObj) {
  1556. let a, b;
  1557. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  1558. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  1559. translateFn = translateFn || getTranslate();
  1560. let cSeg;
  1561. cSeg = wmx.get(seg);
  1562. if (!cSeg) {
  1563. let vSeg = null;
  1564. try {
  1565. vSeg = translateFn(seg);
  1566. } catch (e) {
  1567. }
  1568. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  1569. // console.log('translated', vSeg);
  1570. cSeg = vSeg;
  1571. wmx.set(seg, cSeg);
  1572. wmx.set(cSeg, cSeg);
  1573. }
  1574. }
  1575. if (cSeg && cSeg !== seg) {
  1576. a[b] = cSeg;
  1577. }
  1578. }
  1579.  
  1580. const dfn = Symbol();
  1581. const Object_ = Object;
  1582. Object_[dfn] = Object_.defineProperties;
  1583. let activation = true;
  1584. Object_.defineProperties = function (obj, pds) {
  1585. let segments, get_;
  1586. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  1587. activation = false;
  1588. segments.get = function () {
  1589. fixSegments(this);
  1590. return get_.call(this);
  1591. };
  1592. }
  1593. return Object_[dfn](obj, pds);
  1594. };
  1595.  
  1596. })();
  1597.  
  1598.  
  1599. let pf31 = new PromiseExternal();
  1600.  
  1601. // native RAF
  1602. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  1603.  
  1604. // 1st wrapped RAF
  1605. const baseRAF = (callback) => {
  1606. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  1607. pf31.then(() => {
  1608. callback(hRes);
  1609. });
  1610. });
  1611. };
  1612.  
  1613. // 2nd wrapped RAF
  1614. window.requestAnimationFrame = baseRAF;
  1615.  
  1616. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1617. const indr = o => insp(o).$ || o.$ || 0;
  1618.  
  1619. const prototypeInherit = (d, b) => {
  1620. const m = Object.getOwnPropertyDescriptors(b);
  1621. for (const p in m) {
  1622. if (!Object.getOwnPropertyDescriptor(d, p)) {
  1623. Object.defineProperty(d, p, m[p]);
  1624. }
  1625. }
  1626. };
  1627.  
  1628.  
  1629. const firstObjectKey = (obj) => {
  1630. for (const key in obj) {
  1631. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1632. }
  1633. return null;
  1634. };
  1635.  
  1636. function searchNestedObject(obj, predicate, maxDepth = 64) {
  1637. // normal case: depth until 36
  1638. const result = [];
  1639. const visited = new WeakSet();
  1640.  
  1641. function search(obj, depth) {
  1642. visited.add(obj);
  1643. for (const [key, value] of Object.entries(obj)) {
  1644. // Recursively search nested objects and arrays
  1645. if (value !== null && typeof value === 'object') {
  1646. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  1647. if (depth + 1 <= maxDepth && !visited.has(value)) {
  1648. search(value, depth + 1);
  1649. }
  1650. } else if (predicate(value)) {
  1651. result.push([obj, key]);
  1652. }
  1653. }
  1654. }
  1655.  
  1656. typeof (obj || 0) === 'object' && search(obj, 0);
  1657. return result;
  1658. }
  1659.  
  1660. /** @type {(o: Object | null) => WeakRef | null} */
  1661. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1662.  
  1663. /** @type {(wr: Object | null) => Object | null} */
  1664. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1665.  
  1666. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  1667.  
  1668. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  1669. if (DENY_requestStorageAccess) {
  1670. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  1671. Document.prototype.requestStorageAccessFor = undefined;
  1672. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  1673. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  1674. Document.prototype.requestStorageAccessFor = function () {
  1675. return new Promise((resolve, reject) => {
  1676. reject();
  1677. });
  1678. };
  1679. }
  1680. }
  1681.  
  1682. const traceStack = (stack) => {
  1683. let result = new Set();
  1684. let p = new Set();
  1685. let u = ''
  1686. for (const s of stack.split('\n')) {
  1687. if (s.split(':').length < 3) continue;
  1688. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  1689. if (!m) continue;
  1690. p.add(m[2]);
  1691. if (p.size >= 3) break;
  1692. if(!u) u = m[2];
  1693. else if(p.size === 2 && u && u=== m[2]) break;
  1694. result.add(s);
  1695. }
  1696. return [...result].join('\n');
  1697. }
  1698.  
  1699. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  1700. // window.m3bb = new Set();
  1701.  
  1702. // const smb = Symbol();
  1703. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  1704. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  1705. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  1706.  
  1707. const thisConversionFn = (thisArg) => {
  1708. if (!thisArg) return null;
  1709. const kThis = thisArg[vmb];
  1710. if (kThis) {
  1711. const ref = kThis.ref;
  1712. return (ref ? kRef(ref) : null) || null;
  1713. }
  1714. return thisArg;
  1715. }
  1716.  
  1717. const pFnHandler2 = {
  1718. get(target, prop) {
  1719. if (prop === vmc) return target;
  1720. return Reflect.get(target, prop);
  1721. },
  1722. apply(target, thisArg, argumentsList) {
  1723. thisArg = thisConversionFn(thisArg);
  1724. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  1725. }
  1726. }
  1727.  
  1728.  
  1729. const proxySelfHandler = {
  1730. get(target, prop) {
  1731. if(prop === vmb) return target;
  1732. const ref = target.ref;
  1733. const cnt = kRef(ref);
  1734. if (!cnt) return;
  1735. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  1736. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  1737. return cnt[prop][vmd];
  1738. }
  1739. return cnt[prop];
  1740. },
  1741. set(target, prop, value) {
  1742. const cnt = kRef(target.ref);
  1743. if (!cnt) return true;
  1744. if(value && (value[vmc] || value[vmb])){
  1745. cnt[prop] = value[vmc] || thisConversionFn(value);
  1746. return true;
  1747. }
  1748. cnt[prop] = value;
  1749. return true;
  1750. }
  1751. };
  1752.  
  1753. const weakWrap = (thisArg) => {
  1754. thisArg = thisConversionFn(thisArg);
  1755. if (!thisArg) {
  1756. console.error('thisArg is not found');
  1757. return null;
  1758. }
  1759. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  1760. }
  1761.  
  1762. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  1763. window.getComputedStyle533 = window.getComputedStyle;
  1764. window.getComputedStyle = function (a, ...args) {
  1765. a = thisConversionFn(a);
  1766. if (a) {
  1767. return getComputedStyle533(a, ...args);
  1768. }
  1769. return null;
  1770. }
  1771. }
  1772.  
  1773. Function._count_bind_00 = 0;
  1774. // Function._count_bind_01 = 0;
  1775.  
  1776. // let matchNativeCode = (Object+"");
  1777. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1778. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1779.  
  1780. // const matchConstructor = (thisArg) => {
  1781. // const f = `${(thisArg || 0).constructor}`;
  1782. // if (f.length > 45) return true;
  1783. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1784. // if (f.includes('[native code]')){
  1785. // return false;
  1786. // }
  1787. // return true;
  1788. // }
  1789. // return false;
  1790. // }
  1791.  
  1792. // const acceptThis = (thisArg)=>{
  1793. // // if(!thisArg || typeof thisArg !=='object') return false;
  1794. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1795. // // if(typeof thisArg.path === 'string') return true;
  1796. // // if(typeof thisArg.fn === 'function') return true;
  1797. // // if(typeof thisArg.id === 'string') return true;
  1798. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1799. // return false;
  1800. // }
  1801.  
  1802. const patchFn = (fn) => {
  1803.  
  1804. let s = `${fn}`;
  1805. if (s.length < 11 || s.includes('\n')) return false;
  1806. if(s.includes('bind(this')) return true;
  1807. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1808. // var a=this;
  1809. // f.bind(this)
  1810.  
  1811.  
  1812. return false;
  1813. }
  1814.  
  1815. Function.prototype.bind488 = Function.prototype.bind;
  1816. Function.prototype.bind = function(thisArg, ...args){
  1817.  
  1818. if (thisConversionFn(thisArg) !== thisArg) {
  1819. return this.bind488(thisArg, ...args);
  1820. }
  1821. if( thisArg && patchFn(this) ){
  1822.  
  1823. // console.log(599,`${this}`)
  1824.  
  1825. try {
  1826. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1827. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1828. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1829. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1830. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1831. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1832. // // let b4 = false;
  1833. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1834.  
  1835. // // b3 = false;
  1836. // // b4 = false;
  1837. // // b5 = false;
  1838.  
  1839. // if (b1 || b2 || b3 ||b4 ) {
  1840. const f = this;
  1841. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1842. if (ps && ps[vmb]) {
  1843. Function._count_bind_00++;
  1844. return f.bind488(ps, ...args)
  1845. }
  1846. // }
  1847. } catch (e) {
  1848. console.warn(e)
  1849. }
  1850. }
  1851. return this.bind488(thisArg, ...args);
  1852. }
  1853. Function.prototype.bind588 = 1;
  1854. }
  1855.  
  1856.  
  1857. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  1858. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  1859. const wm6 = new WeakMapOriginal();
  1860.  
  1861. const skipW = new WeakSet();
  1862.  
  1863.  
  1864. window.WeakMap = class WeakMap extends WeakMapOriginal {
  1865. constructor(iterable = undefined) {
  1866. super();
  1867. if (iterable && iterable[Symbol.iterator]) {
  1868. for (const entry of iterable) {
  1869. entry && this.set(entry[0], entry[1]);
  1870. }
  1871. }
  1872. }
  1873. delete(a) {
  1874. if (!this.has(a)) return false;
  1875. super.delete(a);
  1876. return true;
  1877. }
  1878. get(a) {
  1879. const p = super.get(a);
  1880. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1881. let v = kRef(p);
  1882. if (!v) {
  1883. super.delete(a);
  1884. }
  1885. return v || undefined;
  1886. }
  1887. return p;
  1888. }
  1889. has(a) {
  1890. if (!super.has(a)) return false;
  1891. const p = super.get(a);
  1892. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  1893. if (!kRef(p)) {
  1894. super.delete(a);
  1895. return false;
  1896. }
  1897. }
  1898. return true;
  1899. }
  1900. set(a, b) {
  1901. let wq = b;
  1902. if (b && (typeof b === 'function' || typeof b === 'object')) {
  1903. if (b.deref) {
  1904. skipW.add(b);
  1905. wq = b;
  1906. } else {
  1907. wq = wm6.get(b);
  1908. if (!wq) {
  1909. wq = mWeakRef(b);
  1910. wm6.set(b, wq);
  1911. }
  1912. }
  1913. }
  1914. super.set(a, wq);
  1915. return this;
  1916. }
  1917. }
  1918. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  1919. configurable: true,
  1920. enumerable: false,
  1921. value: "WeakMap",
  1922. writable: false
  1923. });
  1924. }
  1925.  
  1926. const isWatchPageURL = (url) => {
  1927. url = url || location;
  1928. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  1929. };
  1930.  
  1931. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  1932.  
  1933. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  1934. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  1935. if (typeof customElements === 'undefined') {
  1936. if (!('__CE_registry' in document)) {
  1937. // https://github.com/webcomponents/polyfills/
  1938. Object.defineProperty(document, '__CE_registry', {
  1939. get() {
  1940. // return undefined
  1941. },
  1942. set(nv) {
  1943. if (typeof nv == 'object') {
  1944. delete this.__CE_registry;
  1945. this.__CE_registry = nv;
  1946. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  1947. }
  1948. return true;
  1949. },
  1950. enumerable: false,
  1951. configurable: true
  1952. })
  1953. }
  1954. let eventHandler = (evt) => {
  1955. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1956. const f = callback;
  1957. callback = null;
  1958. eventHandler = null;
  1959. f();
  1960. };
  1961. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  1962. } else {
  1963. callback();
  1964. }
  1965. });
  1966.  
  1967. const whenCEDefined = isCustomElementsProvided
  1968. ? (nodeName) => customElements.whenDefined(nodeName)
  1969. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  1970.  
  1971. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  1972. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  1973. const f = performance.now23 = Performance.prototype.now;
  1974.  
  1975. let k = 0; // 0 <= k < 9998m
  1976. let u = 0;
  1977. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  1978.  
  1979. // By definition, performance.now() is mono increasing.
  1980. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  1981. performance.now = performance.now16 = function () {
  1982. /**
  1983. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  1984. *
  1985. * If consecutive session history entries had history.state.entryTime set to same value,
  1986. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  1987. * and modifying its return value slightly to make sure two close consecutive calls don't
  1988. * get the same result helped with resolving the issue.
  1989. */
  1990. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  1991. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  1992.  
  1993. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  1994. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  1995. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  1996. else { // more than 9998 consecutive calls
  1997. /**
  1998. *
  1999. * max no. of consecutive calls
  2000. *
  2001. * Sample Size: 4800
  2002. * Sample Avg = 1565.375
  2003. * Sample Median = 1469.5
  2004. * Sample Max = 5660 << 7500 << 9999
  2005. *
  2006. *
  2007. * */
  2008. k = 0;
  2009. s += 1 / 7;
  2010. }
  2011. return v + k; // 0 < v - M < v - M + k < v
  2012. }
  2013.  
  2014. let loggerMsg = '';
  2015. if (`${performance.now()}` === `${performance.now()}`) {
  2016. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  2017. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  2018. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  2019. }
  2020. loggerMsg && console.warn(loggerMsg);
  2021. })();
  2022.  
  2023. FIX_removeChild && (() => {
  2024. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  2025. const fragD = document.createDocumentFragment();
  2026. Node.prototype.removeChild062 = Node.prototype.removeChild;
  2027. Node.prototype.removeChild = function (child) {
  2028. if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  2029. let ok = false;
  2030. try {
  2031. this.removeChild062(child);
  2032. ok = true;
  2033. } catch (e) {
  2034.  
  2035. }
  2036. if (!ok) {
  2037. try {
  2038. fragD.appendChild(child)
  2039. } catch (e) {
  2040. console.warn(e);
  2041. }
  2042. try {
  2043. child.remove();
  2044. } catch (e) {
  2045. console.warn(e);
  2046. }
  2047. }
  2048. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  2049. // tooltip bug
  2050. } else {
  2051. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  2052. }
  2053. return child;
  2054. }
  2055. }
  2056. })();
  2057.  
  2058.  
  2059. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  2060.  
  2061. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  2062.  
  2063. // let cid = 0;
  2064.  
  2065. let mousemoveFn = null;
  2066. let mousemoveDT = 0;
  2067. let mousemoveCount = 0;
  2068. // let qv = false;
  2069. const cif = () => {
  2070. if (!mousemoveFn) return;
  2071. const ct = Date.now();
  2072. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  2073. mousemoveFn && mousemoveFn();
  2074. }
  2075. mousemoveFn = null;
  2076. };
  2077. let mousemoveCId = 0;
  2078. let mouseoverFn = null;
  2079. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  2080. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  2081. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2082. const bt = `${b}`;
  2083. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  2084. b[`__$$${a}$$1926__`] = true;
  2085. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  2086. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  2087. // console.log(3928, a, this[`__$$${a}$$1937__`])
  2088. if (!this[`__$$${a}$$1938__`]) {
  2089. this[`__$$${a}$$1938__`] = b;
  2090. if (a === 'mousemove') {
  2091. this.addEventListener4882('mouseenter', (evt) => {
  2092. if (mousemoveCId) return;
  2093. mousemoveCId = setIntervalX0(cif, 380);
  2094. });
  2095. this.addEventListener4882('mouseleave', (evt) => {
  2096. clearIntervalX0(mousemoveCId);
  2097. mousemoveCId = 0;
  2098. });
  2099. }
  2100. this.addEventListener4882(a, (evt) => {
  2101. const evt_ = evt;
  2102. if (!this[`__$$${a}$$1937__`]) return;
  2103. if (!this[`__$$${a}$$1938__`]) return;
  2104. if (a === 'mousemove') {
  2105. mouseoverFn && mouseoverFn();
  2106. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  2107. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  2108. } else {
  2109. mousemoveCount = 0;
  2110. }
  2111. const f = mousemoveFn = () => {
  2112. if (f !== mousemoveFn) return;
  2113. mousemoveFn = null;
  2114. this[`__$$${a}$$1938__`](evt_);
  2115. };
  2116. if (mousemoveCount <= 1) mousemoveFn();
  2117. } else {
  2118. if (a === 'mouseout' || a === 'mouseleave') {
  2119. mousemoveFn = null;
  2120. mousemoveDT = 0;
  2121. mousemoveCount = 0;
  2122. this[`__$$${a}$$1938__`](evt_);
  2123. mouseoverFn && mouseoverFn();
  2124. } else { // mouseover, mouseenter
  2125. mousemoveFn = null;
  2126. mousemoveDT = 0;
  2127. mousemoveCount = 0;
  2128. mouseoverFn && mouseoverFn(); // just in case
  2129. const f = mouseoverFn = () => {
  2130. if (f !== mouseoverFn) return;
  2131. mouseoverFn = null;
  2132. this[`__$$${a}$$1938__`](evt_);
  2133. }
  2134. nextBrowserTick_(mouseoverFn);
  2135. }
  2136. }
  2137. }, c);
  2138.  
  2139.  
  2140. return;
  2141. } else {
  2142.  
  2143. return;
  2144. }
  2145. }
  2146.  
  2147. }
  2148. return this.addEventListener4882(a, b, c)
  2149. }
  2150.  
  2151.  
  2152.  
  2153.  
  2154. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  2155. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  2156. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2157.  
  2158. if (b[`__$$${a}$$1926__`]) {
  2159. b[`__$$${a}$$1926__`] = false;
  2160.  
  2161. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  2162.  
  2163. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  2164.  
  2165. return;
  2166.  
  2167. }
  2168.  
  2169. }
  2170. return this.removeEventListener4882(a, b, c)
  2171. }
  2172.  
  2173.  
  2174. })();
  2175.  
  2176.  
  2177. FIX_DOM_IF_REPEAT && (() => {
  2178. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  2179. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  2180. // Be careful of the mixture of polymer functions and native Element functions
  2181. // Be careful of the coding design is different with the modern Yt elements
  2182.  
  2183.  
  2184. /*
  2185.  
  2186.  
  2187. function Ks(a, b, c) {
  2188. if (kj && !BOa(a))
  2189. throw Error("strictTemplatePolicy: template owner not trusted");
  2190. c = c || {};
  2191. if (a.__templatizeOwner)
  2192. throw Error("A <template> can only be templatized once");
  2193. a.__templatizeOwner = b;
  2194. var d = (b ? b.constructor : Js)._parseTemplate(a)
  2195. , e = d.templatizeInstanceClass;
  2196. e || (e = COa(a, d, c),
  2197. d.templatizeInstanceClass = e);
  2198. var g = BOa(a);
  2199. EOa(a, d, c, g);
  2200. c = function() {
  2201. return e.apply(this, arguments) || this
  2202. }
  2203. ;
  2204. h(c, e);
  2205. c.prototype._methodHost = g;
  2206. c.prototype.__dataHost = a;
  2207. c.prototype.__templatizeOwner = b;
  2208. c.prototype.__hostProps = d.hostProps;
  2209. return c
  2210. }
  2211.  
  2212. */
  2213.  
  2214. // Polymer.enqueueDebouncer
  2215.  
  2216. const s81 = Symbol();
  2217. const s83 = Symbol();
  2218. const s84 = Symbol();
  2219. const s85 = Symbol();
  2220. const s85b = Symbol();
  2221. const s85c = Symbol();
  2222.  
  2223. let renderDebounceTs = null;
  2224.  
  2225. let renderDebouncePromise = null;
  2226. let qp;
  2227.  
  2228. let cme = 0;
  2229.  
  2230. const shadyFlushMO = new MutationObserver(() => {
  2231.  
  2232. if (!renderDebounceTs) return;
  2233.  
  2234. if (renderDebounceTs.size > 0) {
  2235. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  2236. try {
  2237. Polymer.flush();
  2238. return;
  2239. } catch (e) { }
  2240. }
  2241.  
  2242. renderDebouncePromise && Promise.resolve().then(() => {
  2243.  
  2244. if (renderDebouncePromise) {
  2245. renderDebouncePromise && renderDebouncePromise.resolve();
  2246. renderDebouncePromise = null;
  2247. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  2248. }
  2249.  
  2250. });
  2251.  
  2252. // Polymer.flush
  2253.  
  2254. window.ShadyDOM && ShadyDOM.flush();
  2255. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  2256.  
  2257.  
  2258. });
  2259.  
  2260. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2261.  
  2262. const observablePromise = (proc, timeoutPromise) => {
  2263. let promise = null;
  2264. return {
  2265. obtain() {
  2266. if (!promise) {
  2267. promise = new Promise(resolve => {
  2268. let mo = null;
  2269. const f = () => {
  2270. let t = proc();
  2271. if (t) {
  2272. mo.disconnect();
  2273. mo.takeRecords();
  2274. mo = null;
  2275. resolve(t);
  2276. }
  2277. }
  2278. mo = new MutationObserver(f);
  2279. mo.observe(document, { subtree: true, childList: true })
  2280. f();
  2281. timeoutPromise && timeoutPromise.then(() => {
  2282. resolve(null)
  2283. });
  2284. });
  2285. }
  2286. return promise
  2287. }
  2288. }
  2289. }
  2290.  
  2291.  
  2292. let p = 0;
  2293. qp = observablePromise(() => {
  2294. if (!(p & 1)) {
  2295.  
  2296. if (window.ShadyDOM && ShadyDOM.flush) {
  2297. p |= 1;
  2298. if (!ShadyDOM.flush847) {
  2299.  
  2300. ShadyDOM.flush847 = ShadyDOM.flush;
  2301. ShadyDOM.flush = function () {
  2302.  
  2303. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  2304. renderDebouncePromise && Promise.resolve().then(() => {
  2305. if (renderDebouncePromise) {
  2306.  
  2307. renderDebouncePromise && renderDebouncePromise.resolve();
  2308. renderDebouncePromise = null;
  2309.  
  2310. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  2311.  
  2312. }
  2313.  
  2314. });
  2315. let r = this.flush847(...arguments);
  2316. if (r) {
  2317. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2318. }
  2319. return r
  2320. }
  2321.  
  2322. }
  2323. }
  2324. }
  2325.  
  2326. if (!(p & 2)) {
  2327.  
  2328. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  2329. p |= 2;
  2330. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  2331. if (!ScopingShim.flush848) {
  2332.  
  2333. ScopingShim.flush848 = ScopingShim.flush;
  2334. ScopingShim.flush = function () {
  2335.  
  2336. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  2337.  
  2338. renderDebouncePromise && Promise.resolve().then(() => {
  2339.  
  2340. if (renderDebouncePromise) {
  2341.  
  2342. renderDebouncePromise && renderDebouncePromise.resolve();
  2343. renderDebouncePromise = null;
  2344.  
  2345. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  2346.  
  2347.  
  2348.  
  2349. }
  2350.  
  2351. });
  2352. return this.flush848(...arguments);
  2353. }
  2354.  
  2355. }
  2356. }
  2357. }
  2358. if (p === 3) {
  2359. p |= 8;
  2360.  
  2361. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  2362. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  2363. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  2364.  
  2365. if (r) {
  2366. let w = Set.prototype.add;
  2367. let u = null;
  2368. Set.prototype.add = function () {
  2369. u = this;
  2370. throw new Error();
  2371. }
  2372. try {
  2373. Polymer.enqueueDebouncer()
  2374. } catch (e) { }
  2375. Set.prototype.add = w;
  2376. if (u !== null) {
  2377. renderDebounceTs = u;
  2378. if (DEBUG_renderDebounceTs) {
  2379. renderDebounceTs.add58438 = renderDebounceTs.add;
  2380. renderDebounceTs.add = function () {
  2381. console.log('renderDebounceTs.add')
  2382. console.log(traceStack((new Error()).stack))
  2383. // debugger;
  2384. return this.add58438(...arguments)
  2385. }
  2386.  
  2387. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  2388. renderDebounceTs.delete = function () {
  2389. console.log('renderDebounceTs.delete')
  2390. const stack = `${(new Error()).stack}`
  2391. let isCallbackRemoval = false;
  2392. if (stack) {
  2393. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  2394. const s = t.split(':');
  2395. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  2396. isCallbackRemoval = true;
  2397. }
  2398. }
  2399. if (isCallbackRemoval) {
  2400. return this.delete58438(...arguments)
  2401. }
  2402. console.log(traceStack((new Error()).stack))
  2403. // debugger;
  2404. return this.delete58438(...arguments)
  2405. }
  2406. }
  2407. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  2408. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  2409. }
  2410. }
  2411.  
  2412. return true;
  2413. }
  2414. })
  2415.  
  2416. // if(window.ShadyDOM && ShadyDOM.flush){
  2417. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  2418.  
  2419. // }
  2420. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  2421.  
  2422. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  2423. // }
  2424.  
  2425. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  2426.  
  2427. }
  2428.  
  2429. Object.defineProperty(Object.prototype, '_lastIf', {
  2430. get() {
  2431. return this[s81];
  2432. },
  2433. set(nv) {
  2434. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  2435. // DOM-IF initialization
  2436. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  2437.  
  2438. this.__xiWB8__ = 2;
  2439.  
  2440. const cProto = this.__proto__;
  2441. if (cProto && !cProto.__xiWB7__) {
  2442. cProto.__xiWB7__ = 1;
  2443.  
  2444. // dom-if __template
  2445. // dom-repeat template
  2446. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  2447. cProto.__template847 = true;
  2448. try {
  2449. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  2450. Object.defineProperty(cProto, '__template', {
  2451. get() {
  2452. const v = this[s84];
  2453. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  2454. },
  2455. set(nv) {
  2456. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  2457. this[s84] = nv;
  2458. return true;
  2459. }
  2460. });
  2461. } catch (e) {
  2462. console.warn(e);
  2463. }
  2464.  
  2465. console.log('FIX_DOM_IF - __template')
  2466. }
  2467.  
  2468. // dom-if __ensureTemplate
  2469. // dom-repeat __ensureTemplatized
  2470. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  2471. // note that "_templateInfo" diffs the different version of DOM-IF
  2472.  
  2473. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  2474. cProto.__ensureTemplate = function () {
  2475. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  2476. if (!this.__template) {
  2477. let b;
  2478. if (this._templateInfo) {
  2479. b = this;
  2480. } else {
  2481. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  2482. b = this.__templateCollection011__[0];
  2483. if (!b) {
  2484. if (!this[wk]) this[wk] = mWeakRef(this);
  2485. let a = this[wk];
  2486. let c = new MutationObserver(function () {
  2487. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  2488. if (c && a) {
  2489. c.disconnect();
  2490. a = kRef(a);
  2491. a && a.__render();
  2492. a && (a.__templateCollection011__ = null);
  2493. }
  2494. c = null;
  2495. a = null;
  2496. });
  2497. c && c.observe(this, {
  2498. childList: !0
  2499. });
  2500. return !1
  2501. } else {
  2502. this.__templateCollection011__ = null;
  2503. }
  2504. }
  2505. this.__template = b
  2506. }
  2507. return !0
  2508. }
  2509.  
  2510. console.log('FIX_DOM_IF - __ensureTemplate')
  2511.  
  2512. }
  2513.  
  2514.  
  2515. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  2516.  
  2517. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  2518.  
  2519. // cProto.__createAndInsertInstance = function (a) {
  2520. // Promise.resolve().then(()=>{
  2521. // console.log('__createAndInsertInstance')
  2522. // window.lm5 = window.lm5 || [];
  2523. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  2524. // });
  2525. // return this.__createAndInsertInstance847(a);
  2526. // }
  2527.  
  2528. // }
  2529.  
  2530.  
  2531. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  2532.  
  2533. // cProto._bindTemplate847 = cProto._bindTemplate;
  2534.  
  2535. // cProto._bindTemplate = function (a, b) {
  2536. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  2537. // }
  2538.  
  2539. // }
  2540. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  2541.  
  2542. // cProto._stampTemplate847 = cProto._stampTemplate;
  2543.  
  2544. // cProto._stampTemplate = function (a, b) {
  2545. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  2546. // }
  2547.  
  2548. // }
  2549. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  2550. }
  2551.  
  2552.  
  2553. // need to fix __observeEffects
  2554. // this.__observeEffects.if[0].info.method === this.__debounceRender
  2555. const f = () => {
  2556.  
  2557. const __observeEffects = this.__observeEffects;
  2558.  
  2559. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  2560. for (const effect of __observeEffects.if) {
  2561. const info = effect.info;
  2562. if (info && typeof info.method === 'function') {
  2563.  
  2564. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  2565. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  2566. }
  2567.  
  2568. }
  2569. }
  2570. }
  2571.  
  2572.  
  2573. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  2574. for (const effect of __observeEffects.restamp) {
  2575. const info = effect.info;
  2576. if (info && typeof info.method === 'function') {
  2577.  
  2578. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  2579. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  2580. }
  2581.  
  2582. }
  2583. }
  2584. }
  2585.  
  2586. // console.log(5881, this.__observeEffects)
  2587. }
  2588. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2589. f();
  2590. Promise.resolve().then(f);
  2591. // afterward, don't care adding fn directly (the fn is already modified)
  2592. }
  2593.  
  2594. }
  2595. this[s81] = nv;
  2596. return true;
  2597. }
  2598. });
  2599.  
  2600.  
  2601. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  2602. get() {
  2603. return this[s85];
  2604. },
  2605. set(nv) {
  2606. if (nv === null && this[s85] === undefined) {
  2607. // DOM-IF / DOM-REPEAT initialization
  2608.  
  2609.  
  2610. const cProto = this.__proto__;
  2611. if (qp) {
  2612. qp.obtain();
  2613. qp = null;
  2614. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  2615. }
  2616. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  2617.  
  2618. cProto.__debounceRender847 = cProto.__debounceRender;
  2619.  
  2620. if (cProto.__debounceRender.length === 2) {
  2621.  
  2622. cProto.__debounceRender = function (a, b) {
  2623.  
  2624. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  2625.  
  2626. b = b === void 0 ? 0 : b;
  2627.  
  2628. /*
  2629. b = b === void 0 ? 0 : b;
  2630. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  2631. vs(this.__renderDebouncer)
  2632. */
  2633.  
  2634. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2635.  
  2636. if (!renderDebouncePromise) {
  2637. renderDebouncePromise = new PromiseExternal();
  2638. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2639. }
  2640.  
  2641. renderDebouncePromise.then(async () => {
  2642. if (b > 0) await delayPn(b);
  2643.  
  2644. const f = this.__dsIRYqw1__;
  2645. if (f === cme) return;
  2646. this.__dsIRYqw1__ = cme;
  2647. a.call(this);
  2648. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  2649.  
  2650. });
  2651.  
  2652. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  2653. }
  2654.  
  2655. } else if (cProto.__debounceRender.length === 0) {
  2656.  
  2657.  
  2658. cProto.__debounceRender = function () {
  2659.  
  2660. if (!renderDebounceTs) return this.__debounceRender847();
  2661.  
  2662. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2663. /*
  2664. var a = this;
  2665. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  2666. return a.__render()
  2667. });
  2668. vs(this.__renderDebouncer)
  2669. */
  2670.  
  2671. if (!renderDebouncePromise) {
  2672. renderDebouncePromise = new PromiseExternal();
  2673. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2674. }
  2675. renderDebouncePromise.then(() => {
  2676. const f = this.__dsIRYqw1__;
  2677. if (f === cme) return;
  2678. this.__dsIRYqw1__ = cme;
  2679. this.__render()
  2680. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  2681. });
  2682. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  2683.  
  2684.  
  2685. }
  2686. }
  2687. }
  2688.  
  2689.  
  2690.  
  2691. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  2692. // cProto.render847 = cProto.render;
  2693. // cProto.render = function(){
  2694.  
  2695. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2696. // try{
  2697. // this.render847();
  2698. // }catch(e){}
  2699. // // if(this.__DBR847__){
  2700. // // this.__DBR847__.resolve();
  2701. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  2702. // // }
  2703.  
  2704. // // renderDebouncePromise && renderDebouncePromise.resolve()
  2705. // // renderDebouncePromise = null;
  2706. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  2707.  
  2708. // }
  2709. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  2710. // }
  2711.  
  2712. }
  2713. this[s85] = nv;
  2714. return true;
  2715. }
  2716. });
  2717.  
  2718. // PS-DOM-REPEAT
  2719.  
  2720. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  2721. get() {
  2722. return this[s85b];
  2723. },
  2724. set(nv) {
  2725.  
  2726. this[s85b] = nv;
  2727. return true;
  2728. }
  2729. })
  2730.  
  2731. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  2732. get() {
  2733. return this[s85c];
  2734. },
  2735. set(nv) {
  2736.  
  2737. this[s85c] = nv;
  2738. return true;
  2739. }
  2740. })
  2741.  
  2742.  
  2743. })();
  2744.  
  2745. const setupXdeadC = (cnt)=>{
  2746.  
  2747. let xdeadc = xdeadc00;
  2748. if(!xdeadc){
  2749. setupSDomWrapper(); // just in case
  2750. const hostElement = cnt.hostElement;
  2751. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2752. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2753. hostElement.lastChild.replaceWith(el);
  2754. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2755. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2756. el.firstElementChild.id = rid;
  2757. cnt.$[rid] = el.firstElementChild;
  2758. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2759.  
  2760. xdeadc = cnt.getStampContainer_(rid);
  2761. el.remove();
  2762. xdeadc00 = xdeadc;
  2763. // console.log(xdeadc.__domApi)
  2764. // debugger;
  2765. // const xdeadv = xdeadc.__domApi;
  2766. }
  2767.  
  2768. let xlivec = xlivec00;
  2769. if(!xlivec){
  2770. setupSDomWrapper(); // just in case
  2771. const hostElement = cnt.hostElement;
  2772. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2773. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2774. hostElement.lastChild.replaceWith(el);
  2775. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2776. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2777. el.firstElementChild.id = rid;
  2778. cnt.$[rid] = el.firstElementChild;
  2779. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2780.  
  2781. xlivec = cnt.getStampContainer_(rid);
  2782. xlivec00 = xlivec;
  2783. // console.log(xdeadc.__domApi)
  2784. // debugger;
  2785. // const xdeadv = xdeadc.__domApi;
  2786. }
  2787.  
  2788. return xdeadc00;
  2789. }
  2790.  
  2791. let standardWrap_ = null;
  2792.  
  2793. const setupSDomWrapper = () => {
  2794.  
  2795. const sdwProto = ShadyDOM.Wrapper.prototype;
  2796.  
  2797. if (sdwProto.__pseudo__isConnected__ !== null) {
  2798. sdwProto.__pseudo__isConnected__ = null;
  2799. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  2800. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  2801. const get = isConnectedPd.get;
  2802. isConnectedPd.get = function () {
  2803. const pseudoVal = this.__pseudo__isConnected__;
  2804. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  2805. }
  2806. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  2807. }
  2808.  
  2809. // debugger;
  2810. // new xdeadc.__domApi.constructor(document.createElement('div'));
  2811. }
  2812.  
  2813. }
  2814.  
  2815. let domApiConstructor = null;
  2816. const setupDomApi = (daProto) => {
  2817.  
  2818. daProto.__daHook377__ = true;
  2819.  
  2820. domApiConstructor = daProto.constructor; // TBC
  2821.  
  2822. // TBC
  2823.  
  2824. }
  2825.  
  2826.  
  2827. // WEAKREF_ShadyDOM
  2828.  
  2829. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  2830.  
  2831. const setupPlainShadyDOM = (b) => {
  2832. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  2833. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  2834. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  2835. b.patchOnDemand = true;
  2836. b.preferPerformance = true;
  2837. b.noPatch = true;
  2838. }
  2839.  
  2840. const isPlainObject = (b, m) => {
  2841. if (!b || typeof b !== 'object') return false;
  2842. const e = Object.getOwnPropertyDescriptors(b);
  2843. if (e.length <= m) return false;
  2844. let pr = 0;
  2845. for (const k in e) {
  2846. const d = e[k];
  2847. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  2848. if (!('value' in d) || typeof d.value === 'function') return false;
  2849. pr++;
  2850. }
  2851. return pr > m;
  2852. }
  2853.  
  2854. let b;
  2855.  
  2856. let lz = 0;
  2857.  
  2858. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  2859. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  2860.  
  2861. // Brave - ShadyDOM exists before userscripting
  2862. b = sdp.value;
  2863.  
  2864. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  2865. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  2866. lz = 1;
  2867. }
  2868.  
  2869. }
  2870.  
  2871.  
  2872. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  2873. } else if (!sdp) {
  2874. } else {
  2875. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  2876. return;
  2877. }
  2878.  
  2879. const shadyDOMNodeWRM = new WeakMap();
  2880.  
  2881. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  2882.  
  2883. const weakWrapperNodeHandlerFn = () => ({
  2884. get() {
  2885. const wv = this[wk];
  2886. if (typeof wv === 'undefined') return undefined;
  2887. let node = kRef(wv);
  2888. if (!node) this[wk] = undefined;
  2889. return node || undefined;
  2890. },
  2891. set(nv) {
  2892. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  2893. this[wk] = wv;
  2894. return true;
  2895. },
  2896. enumerable: true,
  2897. configurable: true
  2898. });
  2899.  
  2900.  
  2901. function weakWrapper(_ShadyDOM) {
  2902. const ShadyDOM = _ShadyDOM;
  2903. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  2904. let nullElement = { node: null };
  2905. Object.setPrototypeOf(nullElement, Element.prototype);
  2906. let p = new ShadyDOM.Wrapper(nullElement);
  2907. let d = Object.getOwnPropertyDescriptor(p, 'node');
  2908. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  2909. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  2910. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  2911. }
  2912.  
  2913. }
  2914. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  2915. try {
  2916. setupSDomWrapper();
  2917. } catch (e) { }
  2918. }
  2919.  
  2920. }
  2921.  
  2922. let previousWrapStore = null;
  2923.  
  2924. const standardWrap = function (a) {
  2925. // if(a && a.deref) a= a.deref();
  2926. if(!a) return a;
  2927. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  2928. if (previousWrapStore) {
  2929. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  2930. if (s) {
  2931. previousWrapStore.delete(a);
  2932. shadyDOMNodeWRM.set(a, mWeakRef(s));
  2933. }
  2934. }
  2935. let u = kRef(shadyDOMNodeWRM.get(a));
  2936. if (!u) {
  2937. u = new ShadyDOM.Wrapper(a);
  2938. shadyDOMNodeWRM.set(a, mWeakRef(u));
  2939. }
  2940. return u;
  2941. }
  2942.  
  2943. standardWrap_ = standardWrap;
  2944.  
  2945.  
  2946. function setupWrapFunc(_ShadyDOM) {
  2947. const ShadyDOM = _ShadyDOM;
  2948.  
  2949.  
  2950. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  2951. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  2952. return;
  2953. }
  2954. let mm = new Set();
  2955. const pget = wmPD.value;
  2956. WeakMap.prototype.get = function (a) {
  2957. mm.add(this);
  2958. return a;
  2959. }
  2960. try {
  2961. let nullElement = { node: null };
  2962. Object.setPrototypeOf(nullElement, Element.prototype);
  2963. ShadyDOM.wrapIfNeeded(nullElement)
  2964. ShadyDOM.wrap(nullElement)
  2965. } catch (e) { }
  2966. WeakMap.prototype.get = pget;
  2967. if (mm.size !== 1) {
  2968. mm.clear();
  2969. return;
  2970. }
  2971. const p = mm.values().next().value;
  2972. if (!(p instanceof WeakMap)) return;
  2973. // p.clear();
  2974. // p.get = function (a) { return a }
  2975. // p.set = function (a, b) { return this }
  2976. // console.log(188, window.n2n = mm, window.n2p = p)
  2977.  
  2978. // console.log(34929,p.size)
  2979. previousWrapStore = p;
  2980.  
  2981. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  2982. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  2983. }
  2984. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  2985. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  2986. }
  2987.  
  2988. }
  2989.  
  2990. function setupLZ3(nv) {
  2991.  
  2992. const ShadyDOM = nv;
  2993.  
  2994. const ShadyDOMSettings = ShadyDOM.settings;
  2995. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  2996. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  2997. return false;
  2998. }
  2999.  
  3000. weakWrapper(ShadyDOM);
  3001.  
  3002. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3003.  
  3004. setupPlainShadyDOM(ShadyDOMSettings);
  3005. setupPlainShadyDOM(ShadyDOM);
  3006.  
  3007. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  3008.  
  3009. setupWrapFunc(ShadyDOM);
  3010. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  3011. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  3012.  
  3013. // To be confirmed
  3014. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  3015. ShadyDOM.composedPath = function (e) {
  3016. const t = (e || 0).target || null;
  3017. if (!(t instanceof HTMLElement_)) {
  3018. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  3019. }
  3020. return t instanceof HTMLElement_ ? [t] : [];
  3021. };
  3022. }
  3023.  
  3024. }
  3025.  
  3026. }
  3027.  
  3028.  
  3029. function setupLZ6(nv) {
  3030.  
  3031. const ShadyDOM = nv;
  3032.  
  3033. const ShadyDOMSettings = ShadyDOM.settings;
  3034.  
  3035. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3036. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3037. return false;
  3038. }
  3039.  
  3040. weakWrapper(ShadyDOM);
  3041.  
  3042. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3043.  
  3044. setupPlainShadyDOM(ShadyDOMSettings);
  3045. setupPlainShadyDOM(ShadyDOM);
  3046.  
  3047. setupWrapFunc(ShadyDOM);
  3048.  
  3049. }
  3050.  
  3051. }
  3052.  
  3053. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  3054.  
  3055. const nv = b;
  3056.  
  3057. if (setupLZ6(nv) === false) return;
  3058.  
  3059. lz = 6;
  3060.  
  3061. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  3062.  
  3063. return;
  3064. }
  3065.  
  3066. delete window.ShadyDOM;
  3067.  
  3068. Object.defineProperty(window, 'ShadyDOM', {
  3069. get() {
  3070. return b;
  3071. },
  3072. set(nv) {
  3073. let ret = 0;
  3074. try {
  3075. do {
  3076. if (!nv || !nv.settings) {
  3077. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  3078. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  3079. lz = 1;
  3080. break;
  3081. } else {
  3082. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  3083. break;
  3084. }
  3085. }
  3086.  
  3087. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  3088. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  3089. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  3090. break;
  3091. }
  3092.  
  3093. if (setupLZ3(nv) === false) break;
  3094.  
  3095. lz = 3;
  3096.  
  3097. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  3098.  
  3099. ret = 1;
  3100.  
  3101. } while (0);
  3102. } catch (e) {
  3103. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  3104. }
  3105.  
  3106. if (!ret) b = nv;
  3107. else {
  3108. delete this.ShadyDOM;
  3109. this.ShadyDOM = nv;
  3110. }
  3111. return true;
  3112. },
  3113. enumerable: false,
  3114. configurable: true
  3115. });
  3116.  
  3117. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  3118.  
  3119. if (ENABLE_ASYNC_DISPATCHEVENT) {
  3120. const filter = new Set([
  3121. 'yt-action',
  3122. // 'iframe-src-replaced',
  3123. 'shown-items-changed',
  3124. 'can-show-more-changed', 'collapsed-changed',
  3125.  
  3126. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  3127. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  3128. 'yt-navigate-finish',
  3129.  
  3130. // 'data-changed','yt-watch-comments-ready'
  3131. ])
  3132. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  3133. EventTarget.prototype.dispatchEvent = function (event) {
  3134. const type = (event || 0).type;
  3135. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  3136. if (!filter.has(type) && !type.endsWith('-changed')) {
  3137. if (this instanceof Node || this instanceof Window) {
  3138. nextBrowserTick_(() => this.dispatchEvent938(event));
  3139. return true;
  3140. }
  3141. }
  3142. }
  3143. return this.dispatchEvent938(event);
  3144. }
  3145. }
  3146.  
  3147. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  3148. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  3149. // const xhr = new XMLHttpRequest;
  3150. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  3151. if (!pdOri || pdOri.configurable !== true) return;
  3152. let propNeedles = null;
  3153. const pdNew = {
  3154. configurable: true,
  3155. enumerable: true,
  3156. get: function () {
  3157. propNeedles = this;
  3158. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  3159. throw new Error();
  3160. }
  3161. }
  3162. Object.defineProperty(Map.prototype, 'size', pdNew);
  3163. try {
  3164. XMLHttpRequest.prototype.open.call(0);
  3165. // xhr.open.call(null)
  3166. } catch (e) { }
  3167. Object.defineProperty(Map.prototype, 'size', pdOri);
  3168. if (!propNeedles) return;
  3169. const entries = [...propNeedles.entries()];
  3170. propNeedles.clear();
  3171. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  3172. })();
  3173.  
  3174. if (FIX_XHR_REQUESTING) {
  3175.  
  3176. const URL = window.URL || new Function('return URL')();
  3177. const createObjectURL = URL.createObjectURL.bind(URL);
  3178.  
  3179. XMLHttpRequest = (() => {
  3180. const XMLHttpRequest_ = XMLHttpRequest;
  3181. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  3182. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  3183. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  3184. constructor(...args) {
  3185. super(...args);
  3186. }
  3187. open(method, url, ...args) {
  3188. let skip = false;
  3189. if (!url || typeof url !== 'string') skip = true;
  3190. else if (typeof url === 'string') {
  3191. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  3192. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  3193. skip = true;
  3194. } else if (turl.includes('.youtube.com/pagead/')) {
  3195. skip = true;
  3196. } else if (turl.includes('.youtube.com/ptracking')) {
  3197. skip = true;
  3198. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  3199. skip = true;
  3200. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  3201. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  3202. skip = true;
  3203. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  3204. skip = true;
  3205. } else {
  3206. // skip = true; // for user activity logging e.g. watched videos
  3207. }
  3208. } else if (turl.includes('play.google.com/log')) {
  3209. skip = true;
  3210. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  3211. skip = true;
  3212. }
  3213. }
  3214. if (!skip) {
  3215. this.__xmMc8__ = 1;
  3216. return super.open(method, url, ...args);
  3217. } else {
  3218. this.__xmMc8__ = 2;
  3219. return super.open('GET', url0);
  3220. }
  3221. }
  3222. send(...args) {
  3223. if (this.__xmMc8__ === 1) {
  3224. return super.send(...args);
  3225. } else if (this.__xmMc8__ === 2) {
  3226. return super.send();
  3227. } else {
  3228. console.log('[yt-js-engine-tamer]', 'xhr warning');
  3229. return super.send(...args);
  3230. }
  3231. }
  3232. }
  3233. c.prototype.__xmMc8__ = 0;
  3234. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  3235. return c;
  3236. })();
  3237. }
  3238.  
  3239. // Alternative HACK -> Tabview Youtube
  3240. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  3241.  
  3242. // ---- << this.overscrollConfig HACK >> -----
  3243.  
  3244. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  3245.  
  3246. /*
  3247.  
  3248. ;function gZb(a, b) {
  3249. b = void 0 === b ? !0 : b;
  3250. a.addEventListener("wheel", hZb);
  3251. a.overscrollConfig = {
  3252. cooldown: b
  3253. }
  3254. }
  3255. function iZb(a) {
  3256. a.overscrollConfig = void 0;
  3257. a.removeEventListener("wheel", hZb)
  3258. }
  3259. function hZb(a) {
  3260. var b = a.deltaY
  3261. , c = a.target
  3262. , d = null;
  3263. if (window.Polymer && window.Polymer.Element) {
  3264. if (c = a.path || a.composedPath && a.composedPath()) {
  3265. c = g(c);
  3266. for (var e = c.next(); !e.done && (e = e.value,
  3267. !jZb(e, b)); e = c.next())
  3268. if (e.overscrollConfig) {
  3269. d = e;
  3270. break
  3271. }
  3272. }
  3273. } else
  3274. for (; c && !jZb(c, b); ) {
  3275. if (c.overscrollConfig) {
  3276. d = c;
  3277. break
  3278. }
  3279. c = c.parentElement
  3280. }
  3281. d && (b = d.overscrollConfig,
  3282. b.cooldown ? (d = a.deltaY,
  3283. c = b.lastDeltaY || 0,
  3284. b.lastDeltaY = d,
  3285. e = b.lastStopped || 0,
  3286. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  3287. c = !1) : (d = e + 600,
  3288. c = !0) : (d = Date.now() + 600,
  3289. c = !0),
  3290. d > Date.now() && (a.preventDefault(),
  3291. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  3292. }
  3293. */
  3294.  
  3295. let wheelHandler = function (a) {
  3296. if (window.Polymer && window.Polymer.Element) {
  3297. let c;
  3298. if (c = a.path || a.composedPath && a.composedPath()) {
  3299. for (const e of c) {
  3300. const cnt = insp(e);
  3301. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3302. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3303. }
  3304. }
  3305. } else {
  3306. let e = a.target;
  3307. for (; e instanceof Element; e = e.parentElement) {
  3308. const cnt = insp(e);
  3309. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3310. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3311. }
  3312. }
  3313. };
  3314.  
  3315. let checkWheelListenerObjs = null;
  3316.  
  3317. let getObjsFn = () => {
  3318. let euyVal = 0;
  3319. const eukElm = {};
  3320. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  3321. const euzObj = new Proxy(eukElm, {
  3322. get(target, prop) {
  3323. throw `ErrorF31.get(${prop})`
  3324. },
  3325. set(target, prop, value) {
  3326. throw `ErrorF33.set(${prop}, ${value})`
  3327. }
  3328. });
  3329. const euxElm = new Proxy(eukElm, {
  3330. get(target, prop) {
  3331. if (prop === 'scrollTop') {
  3332. euyVal = euyVal | 8;
  3333. return 0;
  3334. }
  3335. if (prop === 'overscrollConfig') {
  3336. euyVal = euyVal | 16;
  3337. return void 0;
  3338. }
  3339. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  3340. return 640;
  3341. }
  3342. if (prop === 'scrollLeft') {
  3343. euyVal = euyVal | 8;
  3344. return 0;
  3345. }
  3346. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  3347. return 800;
  3348. }
  3349. throw `ErrorF45.get(${prop})`
  3350. },
  3351. set(target, prop, value) {
  3352. throw `ErrorF47.set(${prop}, ${value})`
  3353. }
  3354. });
  3355. const eukEvt = {};
  3356. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  3357. const euyEvt = new Proxy(eukEvt, {
  3358. get(target, prop) {
  3359. if (prop === 'deltaY' || prop === 'deltaX') {
  3360. euyVal = euyVal | 1;
  3361. return -999;
  3362. }
  3363. if (prop === 'target') {
  3364. euyVal = euyVal | 2;
  3365. return euxElm
  3366. }
  3367. if (prop === 'path' || prop === 'composedPath') {
  3368. euyVal = euyVal | 2;
  3369. return [euxElm]
  3370. }
  3371. throw `ErrorF51.get(${prop})`
  3372. },
  3373. set(target, prop, value) {
  3374. throw `ErrorF53.set(${prop}, ${value})`
  3375. }
  3376. });
  3377. const setVal = (v) => {
  3378. euyVal = v;
  3379. }
  3380. const getVal = () => {
  3381. return euyVal;
  3382. }
  3383. return { euzObj, euyEvt, setVal, getVal };
  3384. }
  3385.  
  3386. let checkWheelListener = (callback) => {
  3387.  
  3388. let callbackIdentifier = '';
  3389.  
  3390. let res = null;
  3391. try {
  3392. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  3393. setVal(0);
  3394. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  3395. throw `RESULT${getVal()}`;
  3396. } catch (e) {
  3397. res = e;
  3398. }
  3399.  
  3400. res = `${res}` || `${null}`;
  3401. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  3402.  
  3403. callbackIdentifier = res;
  3404. if (callbackIdentifier === 'RESULT27') 0;
  3405. else if (callbackIdentifier === 'RESULT0') {
  3406. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  3407. } else if (callbackIdentifier.startsWith('RESULT')) {
  3408. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  3409. }
  3410. return callbackIdentifier;
  3411.  
  3412. };
  3413.  
  3414. let callbackFound = false;
  3415. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  3416. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  3417. // M-youtube-js-engine-tamer.52178
  3418. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  3419. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  3420. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  3421. // RESULTXX / ErrorFXX / Other...
  3422. if (callbackIdentifier === 'RESULT27') {
  3423. this.overscrollConfigDisable = true;
  3424. if (!callbackFound) {
  3425. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  3426. getObjsFn = checkWheelListener = null;
  3427. checkWheelListenerObjs = null;
  3428. wheelHandler = null;
  3429. }
  3430. return void 0;
  3431. } else if (!callbackFound && !this.overscrollConfigDisable) {
  3432. this.overscrollConfigDisable = true;
  3433. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  3434. }
  3435. }
  3436. return this.addEventListener52178(type, callback, option);
  3437. };
  3438.  
  3439. // ---- << this.overscrollConfig HACK >> -----
  3440.  
  3441. }
  3442.  
  3443. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  3444.  
  3445. let p_a_objWR = null;
  3446. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  3447. let ytPageReady = 0;
  3448.  
  3449. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  3450. let isGlobalSpaceControl = true;
  3451. let mediaPlayerElementWR = null;
  3452. let focusedElementAtSelection = null;
  3453.  
  3454. // let want_control_video = false;
  3455.  
  3456. let spaceBarControl_keyG = '';
  3457.  
  3458. let lastUserAction = 0;
  3459.  
  3460. const wmKeyControlPhase = new WeakMap();
  3461.  
  3462. let currentSelectionText = null;
  3463.  
  3464. const getCurrentSelectionText = () => {
  3465. if (currentSelectionText !== null) return currentSelectionText
  3466. return (currentSelectionText = `${getSelection()}`)
  3467. }
  3468.  
  3469. const pageMediaWatcher = () => {
  3470.  
  3471. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  3472. // want_control_video = false;
  3473. // }, { capture: true, passive: true });
  3474.  
  3475. document.addEventListener('yt-navigate', () => {
  3476. ytPageReady = 0;
  3477. });
  3478. document.addEventListener('yt-navigate-start', () => {
  3479. ytPageReady = 0;
  3480. });
  3481. document.addEventListener('yt-navigate-cache', () => {
  3482. ytPageReady = 0;
  3483. });
  3484.  
  3485. document.addEventListener('yt-navigate-finish', () => {
  3486. ytPageReady = 1;
  3487. });
  3488.  
  3489. document.addEventListener('durationchange', () => {
  3490. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  3491. if (elm.duration > 0.01) {
  3492. if (elm.closest('[hidden]')) continue;
  3493. mediaPlayerElementWR = mWeakRef(elm);
  3494. return;
  3495. }
  3496. }
  3497. }, { capture: true, passive: true });
  3498.  
  3499. document.addEventListener('selectionchange', (evt) => {
  3500. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  3501. currentSelectionText = null;
  3502. if (!(evt.target instanceof Node)) return;
  3503. focusedElementAtSelection = evt.target;
  3504. }, { capture: true, passive: true })
  3505.  
  3506. document.addEventListener('pointerdown', (evt) => {
  3507. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3508. }, { capture: true, passive: true });
  3509.  
  3510.  
  3511. document.addEventListener('pointerup', (evt) => {
  3512. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3513. }, { capture: true, passive: true });
  3514.  
  3515.  
  3516. document.addEventListener('keydown', (evt) => {
  3517. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3518. }, { capture: true, passive: true });
  3519.  
  3520. document.addEventListener('keyup', (evt) => {
  3521. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3522. }, { capture: true, passive: true });
  3523.  
  3524. };
  3525.  
  3526.  
  3527. const checkKeyB = (p_a_obj) => {
  3528.  
  3529. const boolList = new Set();
  3530. const p_a_obj_api = p_a_obj.api;
  3531.  
  3532. const nilFunc0 = function () {
  3533. return void 0
  3534. };
  3535. const mt = new Proxy({}, {
  3536. get(target, prop) {
  3537. if (prop === 'get') return nilFunc0;
  3538. return mt;
  3539. }
  3540. });
  3541. const nilFunc = function () {
  3542. return mt
  3543. };
  3544. const mw = new Proxy({}, {
  3545. get(target, prop) {
  3546. if (prop in p_a_obj_api) {
  3547. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  3548. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  3549. if (q && q.value) {
  3550. if (!q.writable) return q.value;
  3551. if (typeof q.value === 'string') return '';
  3552. if (typeof q.value === 'number') return 0;
  3553. if (typeof q.value === 'boolean') return false;
  3554. if (q.value && typeof q.value === 'object') return {};
  3555. }
  3556. }
  3557. return undefined;
  3558. },
  3559. set(target, prop) {
  3560. throw 'mwSet';
  3561. }
  3562. });
  3563.  
  3564. const mq = new Proxy({}, {
  3565. get(target, prop) {
  3566. if (prop === 'api') return mw;
  3567. if (prop in p_a_obj) {
  3568. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  3569. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  3570. if (q && q.value) {
  3571. if (!q.writable) return q.value;
  3572. if (typeof q.value === 'string') return '';
  3573. if (typeof q.value === 'number') return 0;
  3574. if (typeof q.value === 'boolean') return false;
  3575. if (q.value && typeof q.value === 'object') return {};
  3576. }
  3577. }
  3578. return undefined;
  3579. },
  3580. set(target, prop, val) {
  3581. if (typeof val === 'boolean') boolList.add(prop)
  3582. throw `mqSet(${prop},${val})`;
  3583. }
  3584. });
  3585.  
  3586. let res = ''
  3587. try {
  3588. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  3589. } catch (e) {
  3590. res = `ERROR::${e}`;
  3591. }
  3592.  
  3593. if (boolList.size === 1) {
  3594. const value = boolList.values().next().value;
  3595. if (res === `ERROR::mqSet(${value},${true})`) {
  3596. p_a_obj.__uZWaD__ = value;
  3597. }
  3598. }
  3599.  
  3600. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  3601.  
  3602. }
  3603.  
  3604.  
  3605. let pm_p_a = null;
  3606.  
  3607. const p_a_init = function () {
  3608. const r = this.init91();
  3609. const keyBw = this.__cPzfo__ || '__NIL__';
  3610. const p_a_obj = this[keyBw];
  3611. if (!p_a_obj) return;
  3612. try {
  3613. checkKeyB(p_a_obj);
  3614. } catch (e) { }
  3615. p_a_objWR = mWeakRef(p_a_obj);
  3616. if (FIX_SHORTCUTKEYS > 0) {
  3617. if (p_a_obj && !p_a_obj.hVhtg) {
  3618. p_a_obj.hVhtg = 1;
  3619.  
  3620. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  3621. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  3622. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  3623. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  3624. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  3625. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  3626.  
  3627. }
  3628. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  3629. // const api = p_a_obj.api
  3630. // api.hVhtg = 1;
  3631. // api.playVideo91 = api.playVideo;
  3632. // api.playVideo = p_a_jt.playVideo;
  3633. // api.pauseVideo91 = api.pauseVideo;
  3634. // api.pauseVideo = p_a_jt.pauseVideo;
  3635. // }
  3636. }
  3637. if (pm_p_a) {
  3638. pm_p_a.resolve();
  3639. pm_p_a = null;
  3640. }
  3641. return r;
  3642. };
  3643.  
  3644. const p_a_xt = {
  3645.  
  3646. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  3647.  
  3648. if (FIX_SHORTCUTKEYS === 2) {
  3649.  
  3650. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  3651.  
  3652. if (activeElement) {
  3653.  
  3654. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  3655.  
  3656. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  3657. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  3658. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  3659.  
  3660. }
  3661.  
  3662. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  3663. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  3664. // console.log(582, isDelayedSpaceBar)
  3665. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  3666.  
  3667. if (activeElement && (h === 'Space' || h === 'Enter')) {
  3668. const controlPhase = wmKeyControlPhase.get(activeElement);
  3669. if (controlPhase === 4 || controlPhase === 5) return false;
  3670. }
  3671. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  3672. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  3673. // if (!isSpaceKeyImmediate) return false;
  3674. // }
  3675. }
  3676.  
  3677. },
  3678.  
  3679. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  3680.  
  3681. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  3682.  
  3683. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  3684. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  3685. // console.log(583, isDelayedSpaceBar)
  3686. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  3687.  
  3688. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3689.  
  3690. let mediaWorking = false;
  3691. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  3692. mediaWorking = true;
  3693. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3694. mediaWorking = true;
  3695. }
  3696. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  3697. mediaWorking && Promise.resolve().then(() => {
  3698. if (activeElement === document.activeElement) {
  3699. return activeElement.blur()
  3700. } else {
  3701. return false
  3702. }
  3703. }).then((r) => {
  3704. r !== false && mediaPlayerElement.focus();
  3705. });
  3706. }
  3707. },
  3708.  
  3709.  
  3710. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  3711.  
  3712. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3713.  
  3714. const activeElement = document.activeElement;
  3715.  
  3716. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3717. if (allow === false) return false;
  3718.  
  3719. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3720. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  3721.  
  3722. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3723.  
  3724. return ret;
  3725. },
  3726. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  3727.  
  3728.  
  3729. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3730.  
  3731. const activeElement = document.activeElement;
  3732. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3733. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3734. // }
  3735. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3736. if (allow === false) return false;
  3737.  
  3738. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3739. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  3740.  
  3741. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3742.  
  3743. return ret;
  3744. }
  3745.  
  3746. };
  3747.  
  3748. // const p_a_jt = { // API
  3749.  
  3750. // playVideo(a) { // without spinner effect
  3751.  
  3752. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3753.  
  3754. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3755. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3756. // want_control_video = true;
  3757. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3758. // }
  3759.  
  3760. // }
  3761. // return this.playVideo91(a);
  3762.  
  3763. // },
  3764.  
  3765. // pauseVideo(a) { // without spinner effect
  3766.  
  3767. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3768.  
  3769. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3770. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3771. // want_control_video = true;
  3772. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3773. // }
  3774.  
  3775. // }
  3776. // return this.pauseVideo91(a);
  3777.  
  3778. // }
  3779. // };
  3780.  
  3781. let flagSpeedMaster = null;
  3782. const getSpeedMasterControlFlag = () => {
  3783.  
  3784. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3785. isSpeedMastSpacebarControlEnabled = false;
  3786. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  3787. isSpeedMastSpacebarControlEnabled = true;
  3788. }
  3789. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  3790. isSpeedMastSpacebarControlEnabled = true;
  3791. }
  3792.  
  3793. if (flagSpeedMaster === null) {
  3794. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  3795. if (!p) {
  3796. flagSpeedMaster = false;
  3797. } else {
  3798.  
  3799. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  3800.  
  3801. }
  3802.  
  3803. }
  3804. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  3805.  
  3806. return isSpeedMastSpacebarControlEnabled;
  3807. }
  3808.  
  3809.  
  3810. const getGlobalSpacebarControlFlag = () => {
  3811.  
  3812. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3813. isGlobalSpaceControl = false;
  3814. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  3815. isGlobalSpaceControl = true;
  3816. }
  3817. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  3818. isGlobalSpaceControl = true;
  3819. }
  3820.  
  3821. return isGlobalSpaceControl;
  3822. }
  3823.  
  3824. const keyboardController = async (_yt_player) => {
  3825.  
  3826. const keyQT = getQT(_yt_player);
  3827. const keySV = getSV(_yt_player);
  3828. const keyDX = getDX(_yt_player);
  3829. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  3830.  
  3831. if (!keyDX) return;
  3832. if (keyDX === keyQT || keyDX === keySV) return;
  3833.  
  3834. if (typeof keyDX !== 'string') return;
  3835.  
  3836. let lastAccessKey = '';
  3837. let lastAccessKeyConfirmed = '';
  3838. const mb = new Proxy({}, {
  3839. get(target, prop) {
  3840. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  3841. throw 'mbGet'
  3842. },
  3843. set(target, prop, val) {
  3844. throw 'mbSet'
  3845. }
  3846. });
  3847. const ma = new Proxy({}, {
  3848. get(target, prop) {
  3849. lastAccessKey = prop;
  3850. return mb
  3851. },
  3852. set(target, prop, val) {
  3853. throw 'maSet'
  3854. }
  3855. });
  3856.  
  3857. let keyBw = '';
  3858. try {
  3859. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  3860. } catch (e) {
  3861. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  3862. keyBw = lastAccessKeyConfirmed;
  3863. }
  3864. }
  3865.  
  3866. if (!keyBw) return;
  3867.  
  3868. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  3869.  
  3870. pm_p_a = new PromiseExternal();
  3871.  
  3872. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  3873.  
  3874. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  3875.  
  3876. _yt_player[keyDX].prototype.init = p_a_init;
  3877.  
  3878. await pm_p_a.then();
  3879. const p_a_obj = kRef(p_a_objWR);
  3880.  
  3881. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  3882.  
  3883.  
  3884. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  3885.  
  3886. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  3887.  
  3888. if (!isSpeedMastSpacebarControlEnabled) {
  3889.  
  3890. if (config && config.EXPERIMENT_FLAGS) {
  3891. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  3892. }
  3893. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3894. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  3895. }
  3896.  
  3897. } else {
  3898.  
  3899. if (config && config.EXPERIMENT_FLAGS) {
  3900. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  3901. }
  3902. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  3903. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  3904. }
  3905.  
  3906. }
  3907.  
  3908. }
  3909.  
  3910. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  3911.  
  3912.  
  3913.  
  3914.  
  3915. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  3916.  
  3917. // console.log(p_a_obj.handleGlobalKeyUp)
  3918. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  3919.  
  3920. // console.log(p_a_obj.api)
  3921.  
  3922.  
  3923. // QT -> DX(SV) -> p_a
  3924.  
  3925.  
  3926. /*
  3927. *
  3928. *
  3929. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3930. b = void 0 === b ? !1 : b;
  3931. c = void 0 === c ? !1 : c;
  3932. d = void 0 === d ? !1 : d;
  3933. e = void 0 === e ? !1 : e;
  3934. var l = g.PT(this);
  3935. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  3936. }
  3937.  
  3938. */
  3939.  
  3940. /*
  3941. *
  3942. *
  3943. *
  3944. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  3945. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  3946. }
  3947.  
  3948. */
  3949.  
  3950.  
  3951. // if(!keyDX) return;
  3952.  
  3953. // console.log(4999, keyDX)
  3954.  
  3955. };
  3956.  
  3957.  
  3958. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  3959.  
  3960. const p_a_obj = kRef(p_a_objWR);
  3961. // const api = p_a_obj.api;
  3962.  
  3963.  
  3964. // console.log(540);
  3965.  
  3966. let boolList = null;
  3967. let ret;
  3968. isSpaceKeyImmediate = true;
  3969. try {
  3970.  
  3971. ret = 0;
  3972. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  3973. let p_a_objT;
  3974. if (!spaceBarControl_keyG) { // just in case
  3975. boolList = new Set();
  3976. p_a_objT = new Proxy(p_a_obj, {
  3977. get(target, prop, handler) {
  3978. const val = target[prop];
  3979. if (typeof val !== 'boolean') return val;
  3980. boolList.add(prop);
  3981. // console.log(555, prop, val);
  3982. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  3983. spaceBarControl_keyG = prop;
  3984. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  3985. val = false;
  3986. }
  3987. return val;
  3988. }
  3989. });
  3990.  
  3991.  
  3992. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  3993. p_a_obj[spaceBarControl_keyG] = false;
  3994. p_a_objT = p_a_obj;
  3995. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  3996. } else {
  3997.  
  3998. p_a_objT = p_a_obj;
  3999. }
  4000.  
  4001. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  4002.  
  4003.  
  4004. } catch (e) {
  4005. console.log(e)
  4006. }
  4007. isSpaceKeyImmediate = false;
  4008.  
  4009. if (boolList && boolList.size === 1) {
  4010. const value = boolList.values().next().value;
  4011. spaceBarControl_keyG = value;
  4012. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4013.  
  4014. }
  4015.  
  4016. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4017.  
  4018. return ret;
  4019. }
  4020.  
  4021. const shortcutKeysFixer = () => {
  4022.  
  4023. let pausePromiseControlJ = 0;
  4024.  
  4025.  
  4026. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  4027.  
  4028. let controlPhase = 0;
  4029. const aElm = document.activeElement;
  4030.  
  4031. if (aElm) {
  4032.  
  4033. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  4034.  
  4035. if (typeof controlPhaseCache === 'number') {
  4036.  
  4037. controlPhase = controlPhaseCache;
  4038. } else {
  4039.  
  4040. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  4041. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  4042. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  4043. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  4044. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  4045. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  4046. else {
  4047. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  4048. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  4049. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  4050. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  4051. }
  4052.  
  4053. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  4054. controlPhase = 0;
  4055. }
  4056.  
  4057. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  4058. if (aElm.closest('[contenteditable], input, textarea')) {
  4059. controlPhase = 5;
  4060. } else if (aElm.closest('button')) {
  4061. controlPhase = 4;
  4062. }
  4063. }
  4064.  
  4065. if (aElm.closest('#movie_player')) controlPhase = 6;
  4066.  
  4067. wmKeyControlPhase.set(aElm, controlPhase);
  4068.  
  4069. }
  4070. }
  4071.  
  4072. return controlPhase;
  4073.  
  4074. }
  4075.  
  4076. const isStateControllable = (api) => {
  4077. let appState = null;
  4078. let playerState = null;
  4079. let adState = null;
  4080. try {
  4081. appState = api.getAppState();
  4082. playerState = api.getPlayerState();
  4083. adState = api.getAdState();
  4084. } catch (e) { }
  4085. // ignore playerState -1
  4086. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  4087. };
  4088.  
  4089.  
  4090. const keyEventListener = (evt) => {
  4091. if (BY_PASS_KEYBOARD_CONTROL) return;
  4092.  
  4093. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4094. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  4095. if (!ytPageReady) return;
  4096.  
  4097. if (evt.defaultPrevented === true) return;
  4098.  
  4099. const p_a_obj = kRef(p_a_objWR);
  4100.  
  4101. if (!p_a_obj) return;
  4102.  
  4103.  
  4104. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4105. if (!mediaPlayerElement) return;
  4106.  
  4107. // let focusBodyIfSuccess = false;
  4108.  
  4109. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  4110.  
  4111. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  4112. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  4113. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  4114.  
  4115.  
  4116. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  4117.  
  4118. // console.log(`${evt.type}::controlPhase`,controlPhase)
  4119.  
  4120. // if (controlPhase == 4) {
  4121. // focusBodyIfSuccess = true;
  4122. // }
  4123.  
  4124. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  4125. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4126.  
  4127. if (FIX_SHORTCUTKEYS < 2) return;
  4128. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  4129.  
  4130. let rr;
  4131. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  4132.  
  4133.  
  4134.  
  4135. let useImprovedPauseResume = false;
  4136.  
  4137. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4138.  
  4139. const api = p_a_obj.api;
  4140. const stateControllable = isStateControllable(api);
  4141. // console.log(2122, appState, playerState, adState)
  4142.  
  4143. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  4144.  
  4145. useImprovedPauseResume = true;
  4146.  
  4147. }
  4148.  
  4149.  
  4150. }
  4151.  
  4152.  
  4153. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  4154. if (evt.type === 'keydown') {
  4155.  
  4156. if (useImprovedPauseResume) {
  4157.  
  4158. const isPaused = mediaPlayerElement.paused;
  4159.  
  4160. const cj = ++pausePromiseControlJ;
  4161. Promise.resolve().then(() => {
  4162.  
  4163. if (cj !== pausePromiseControlJ) return;
  4164.  
  4165. if (mediaPlayerElement.paused !== isPaused) return;
  4166.  
  4167. const ret = ytResumeFn();
  4168. if (!ret) { // fallback
  4169. isPaused ? api.playVideo() : api.pauseVideo();
  4170. }
  4171.  
  4172. /*
  4173. let a = void 0;
  4174. console.log('Rb', api.Rb())
  4175. a = !window._yt_player.nL(api.Rb());
  4176. p_a_obj.Wd.kG(a)
  4177. a ? api.playVideo() : api.pauseVideo();
  4178.  
  4179. */
  4180.  
  4181.  
  4182. });
  4183. rr = true;
  4184. } else {
  4185.  
  4186. isSpaceKeyImmediate = true;
  4187. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  4188. isSpaceKeyImmediate = false;
  4189. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4190.  
  4191. }
  4192.  
  4193.  
  4194. } else if (evt.type === 'keyup') {
  4195.  
  4196. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4197.  
  4198. rr = true;
  4199. } else {
  4200.  
  4201. isSpaceKeyImmediate = true;
  4202. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  4203. isSpaceKeyImmediate = false;
  4204. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4205.  
  4206. }
  4207.  
  4208.  
  4209. /*
  4210.  
  4211. if (d)
  4212. switch (c) {
  4213. case 32:
  4214. case 13:
  4215. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  4216. b = !0,
  4217. e = !1;
  4218. else if (e) {
  4219. var m = d.getAttribute("role");
  4220. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  4221. d.click(),
  4222. f = !0)
  4223. }
  4224. break;
  4225. case 37:
  4226. case 39:
  4227. case 36:
  4228. case 35:
  4229. b = "slider" === d.getAttribute("role");
  4230. break;
  4231. case 38:
  4232. case 40:
  4233. m = d.getAttribute("role"),
  4234. d = 38 === c ? d.previousSibling : d.nextSibling,
  4235. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  4236. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  4237. f = b = !0))
  4238. }
  4239. if (e && !f)
  4240. switch (c) {
  4241. case 38:
  4242. f = Math.min(this.api.getVolume() + 5, 100);
  4243. XV(this.Wd, f, !1);
  4244. this.api.setVolume(f);
  4245. h = f = !0;
  4246. break;
  4247. case 40:
  4248. f = Math.max(this.api.getVolume() - 5, 0);
  4249. XV(this.Wd, f, !0);
  4250. this.api.setVolume(f);
  4251. h = f = !0;
  4252. break;
  4253. case 36:
  4254. this.api.Yh() && (this.api.startSeekCsiAction(),
  4255. this.api.seekTo(0, void 0, void 0, void 0, 79),
  4256. h = f = !0);
  4257. break;
  4258. case 35:
  4259. this.api.Yh() && (this.api.startSeekCsiAction(),
  4260. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  4261. h = f = !0)
  4262. }
  4263. */
  4264.  
  4265. }
  4266.  
  4267.  
  4268. if (rr) {
  4269.  
  4270. // focusBodyIfSuccess && Promise.resolve().then(() => {
  4271. // activeElement === document.activeElement && activeElement.blur();
  4272. // });
  4273.  
  4274. evt.preventDefault();
  4275. evt.stopImmediatePropagation();
  4276. evt.stopPropagation();
  4277.  
  4278. }
  4279.  
  4280. };
  4281.  
  4282. document.addEventListener('keydown', keyEventListener, { capture: true });
  4283.  
  4284.  
  4285. document.addEventListener('keyup', keyEventListener, { capture: true });
  4286.  
  4287. }
  4288.  
  4289. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  4290.  
  4291. })();
  4292.  
  4293.  
  4294. pageMediaWatcher();
  4295. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  4296.  
  4297.  
  4298. const check_for_set_key_order = (() => {
  4299.  
  4300. let mySet = new Set();
  4301.  
  4302. mySet.add("value1");
  4303. mySet.add("value2");
  4304. mySet.add("value3");
  4305.  
  4306. // Function to convert Set values to an array
  4307. function getSetValues(set) {
  4308. return Array.from(set.values());
  4309. }
  4310.  
  4311. // Function to test if the Set maintains insertion order
  4312. function testSetOrder(set, expectedOrder) {
  4313. let values = getSetValues(set);
  4314. return expectedOrder.join(',') === values.join(',');
  4315. }
  4316.  
  4317. // Test 1: Initial order
  4318. if (mySet.values().next().value !== "value1") return false;
  4319. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  4320.  
  4321. // Test 2: After deleting an element
  4322. mySet.delete("value2");
  4323. if (mySet.values().next().value !== "value1") return false;
  4324. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  4325.  
  4326. // Test 3: After re-adding a deleted element
  4327. mySet.add("value2");
  4328. if (mySet.values().next().value !== "value1") return false;
  4329. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  4330.  
  4331. // Test 4: After adding a new element
  4332. mySet.add("value4");
  4333. if (mySet.values().next().value !== "value1") return false;
  4334. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  4335.  
  4336. // Test 5: Delete+Add
  4337. mySet.delete("value1");
  4338. mySet.delete("value3");
  4339. mySet.add("value3");
  4340. mySet.add("value1");
  4341. if (mySet.values().next().value !== "value2") return false;
  4342. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  4343.  
  4344. return true;
  4345. })();
  4346.  
  4347.  
  4348. // const qm47 = Symbol();
  4349. const qm57 = Symbol();
  4350. const qm53 = Symbol();
  4351. const qn53 = Symbol();
  4352.  
  4353.  
  4354. const ump3 = new WeakMap();
  4355.  
  4356. const stp = document.createElement('noscript');
  4357. stp.id = 'weakref-placeholder';
  4358.  
  4359. PROP_OverReInclusion_AVOID && (() => {
  4360.  
  4361.  
  4362. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  4363. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  4364. let byPassVal = null;
  4365. let byPassCount = 0;
  4366. let mmw = new Set();
  4367. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  4368. if (arguments.length !== 1) return f.apply(this, arguments);
  4369. if (byPassVal !== null && typeof prop === 'string') {
  4370.  
  4371. if (PROP_OverReInclusion_LIST.has(prop)) {
  4372. byPassCount++;
  4373. return byPassVal;
  4374. }
  4375. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  4376.  
  4377. }
  4378. return this.hasOwnProperty72(prop);
  4379. };
  4380.  
  4381.  
  4382. /*
  4383.  
  4384.  
  4385. z.prototype.forwardDynamicProps = function() {
  4386. var B = m(this.inst);
  4387. B = h(B);
  4388. for (var F = B.next(); !F.done; F = B.next()) {
  4389. var H = h(F.value);
  4390. F = H.next().value;
  4391. H = H.next().value;
  4392. my(this, F, H);
  4393. r(b) && !ly(F) && Wua(this.inst, F)
  4394. }
  4395. }
  4396.  
  4397. */
  4398.  
  4399.  
  4400.  
  4401. let byPassZeroShowed = false;
  4402. const forwardDynamicPropsGeneral = function () {
  4403. byPassVal = true;
  4404. byPassCount = 0;
  4405. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  4406. const ret = this.forwardDynamicProps72();
  4407. byPassVal = null;
  4408. if (byPassCount === 0 && !byPassZeroShowed) {
  4409. byPassZeroShowed = true;
  4410. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  4411. }
  4412. byPassCount = 0;
  4413. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  4414. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  4415. mmw.clear();
  4416. }
  4417. return ret;
  4418. };
  4419.  
  4420. const propCheck = (proto) => {
  4421. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  4422. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  4423. if (proto.forwardDynamicProps.length === 0) {
  4424. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  4425. }
  4426. }
  4427. };
  4428.  
  4429. const valMap = new WeakMap();
  4430. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  4431. get() {
  4432. propCheck(this.constructor.prototype);
  4433. return valMap.get(this);
  4434. },
  4435. set(nv) {
  4436. propCheck(this.constructor.prototype);
  4437. valMap.set(this, nv);
  4438. return true;
  4439. },
  4440. enumerable: false,
  4441. configurable: true
  4442.  
  4443. });
  4444.  
  4445. promiseForCustomYtElementsReady.then(() => {
  4446. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  4447. if (customElements.define.length !== 2) return;
  4448. customElements.define72 = customElements.define;
  4449. customElements.define = function (b, w) {
  4450. propCheck(w.prototype);
  4451. const ret = this.define72(b, w);
  4452. return ret;
  4453. }
  4454. });
  4455.  
  4456. })();
  4457.  
  4458.  
  4459. let marcoPr = new PromiseExternal();
  4460. const trackMarcoCm = document.createComment('1');
  4461. const trackMarcoCmObs = new MutationObserver(()=>{
  4462. marcoPr.resolve();
  4463. marcoPr = new PromiseExternal();
  4464. });
  4465. trackMarcoCmObs.observe(trackMarcoCm, {characterData: true});
  4466.  
  4467.  
  4468. // ----------------------------
  4469.  
  4470.  
  4471.  
  4472. const __refreshData938o__ = {};
  4473. const __refreshData938__ = function (prop, opt) {
  4474. const d = this[prop];
  4475. if (d) {
  4476. this._setPendingProperty(prop, __refreshData938o__, opt);
  4477. this._setPendingProperty(prop, d, opt);
  4478. this._invalidateProperties();
  4479. }
  4480. };
  4481.  
  4482. const __refreshData933__ = function (prop, opt) {
  4483. const d = this[prop];
  4484. if (d) {
  4485. this.signalProxy.setWithPath([prop], d);
  4486. }
  4487. }
  4488.  
  4489. const setupRefreshData930 = (cnt) => {
  4490. if (cnt.__refreshData930__ !== undefined) return;
  4491. const cProto = Reflect.getPrototypeOf(cnt);
  4492. let r = null;
  4493. let flag = 0;
  4494. if (typeof cnt._setPendingProperty === 'function' && typeof cnt._invalidateProperties === 'function' && cnt._setPendingProperty.length === 3 && cnt._invalidateProperties.length === 0) {
  4495. flag |= 1;
  4496. }
  4497. if (typeof cnt.signalProxy !== "undefined") {
  4498. flag |= 2;
  4499. }
  4500. if (typeof (cnt.signalProxy || 0).setWithPath === 'function' && cnt.signalProxy.setWithPath.length === 2) {
  4501. flag |= 4;
  4502. }
  4503. if (r === 1) r = __refreshData938__;
  4504. // else if (r === 6) r = __refreshData933__;
  4505. cProto.__refreshData930__ = r;
  4506. // ytd-comments-header-renderer : no _invalidateProperties (cnt.signalProxy.setWithPath)
  4507. }
  4508.  
  4509. // const pendingStampFlushs = [];
  4510.  
  4511. const nativeNow = performance.constructor.prototype.now.bind(performance);
  4512.  
  4513. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  4514.  
  4515. const executeTaskBatch = function (taskArr, firstMarco = true) {
  4516. if (!(taskArr || 0).length) throw new TypeError(`Illegal invocation`);
  4517. return new Promise(resolveFinal => {
  4518. let resolveFn = null;
  4519. const len = taskArr.length;
  4520. const results = new Array(len);
  4521. const makePromise = () => new Promise(resolve => { resolveFn = resolve });
  4522. let firedCount = 0;
  4523. const executor = () => {
  4524. if (taskArr.length !== len) throw new TypeError(`Illegal invocation`);
  4525. const resolveFn_ = resolveFn;
  4526. let t0 = 0;
  4527. let next = 0;
  4528. taskArr.forEach((task, idx) => {
  4529. if (typeof (task || 0) !== 'object') throw new TypeError(`Illegal invocation`);
  4530. if (!task.fired) {
  4531. queueMicrotask_(() => {
  4532. if (next || task.fired) return;
  4533. task.fired = true;
  4534. const { fn } = task;
  4535. task.fn = null;
  4536. if (++firedCount === len) next |= 2;
  4537. if (!t0) t0 = nativeNow() + 10;
  4538. results[idx] = fn(task); // sync task only
  4539. if (nativeNow() > t0) next |= 1;
  4540. });
  4541. }
  4542. });
  4543. queueMicrotask_(() => resolveFn_(next))
  4544. }
  4545. const looper = (next) => {
  4546. if (!next) throw new TypeError(`Illegal invocation`);
  4547. if (next & 2) {
  4548. taskArr.length = 0;
  4549. if (next & 1) {
  4550. nextBrowserTick_(() => resolveFinal(results))
  4551. } else {
  4552. resolveFinal(results);
  4553. }
  4554. } else {
  4555. const p = makePromise();
  4556. nextBrowserTick_(executor);
  4557. p.then(looper);
  4558. }
  4559. }
  4560. const p = makePromise();
  4561. firstMarco ? nextBrowserTick_(executor) : executor();
  4562. p.then(looper);
  4563.  
  4564. })
  4565.  
  4566. }
  4567.  
  4568.  
  4569. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  4570.  
  4571.  
  4572. // const globalPromiseStack = {};
  4573.  
  4574. // let dummy;
  4575. // while(!dummy){
  4576.  
  4577. // dummy = document.querySelector('yt-icon');
  4578. // await new Promise(r=>setTimeout(r,0));
  4579. // }
  4580.  
  4581. dummy = document.createElement('yt-icon');
  4582.  
  4583. let cProto;
  4584. if (!(dummy instanceof Element)) return;
  4585. cProto = insp(dummy).constructor.prototype;
  4586.  
  4587. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  4588. cProto.determineIconSet671 = cProto.determineIconSet;
  4589. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  4590. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  4591. cProto.getIconManager671 = cProto.getIconManager;
  4592. cProto.getIconShapeData671 = cProto.getIconShapeData;
  4593. cProto.renderIcon671 = cProto.renderIcon;
  4594.  
  4595. // cProto.attached488 = cProto.attached;
  4596. // cProto.attached = function(){
  4597. // console.log('attached')
  4598. // return this.attached488(...arguments);
  4599. // }
  4600. // cProto.detached488 = cProto.detached;
  4601. // cProto.detached = function(){
  4602. // console.log('detached')
  4603. // return this.detached488(...arguments);
  4604. // }
  4605.  
  4606. if(cProto.__renderIconFix__) return;
  4607. cProto.__renderIconFix__ = true;
  4608.  
  4609. let taskStack = [];
  4610. const cmObs = new MutationObserver(()=>{
  4611. const tasks = taskStack.slice();
  4612. taskStack.length = 0;
  4613. for(const task of tasks){
  4614. task();
  4615. }
  4616. })
  4617. const cm = document.createComment('1');
  4618. const stackTask = (f) => {
  4619. taskStack.push(f);
  4620. cm.data = `${(cm.data & 7) + 1}`;
  4621. }
  4622. cmObs.observe(cm, { characterData: true });
  4623.  
  4624. // let iconManagers = {}; // assume shared
  4625.  
  4626. // window.iconManagers = () => iconManagers;
  4627.  
  4628.  
  4629. const setupYtIcon = (inst) => {
  4630.  
  4631. if (inst.__ytIconSetup588__) return;
  4632. const cProto = Reflect.getPrototypeOf(inst);
  4633. cProto.__ytIconSetup588__ = true;
  4634.  
  4635.  
  4636. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4637.  
  4638. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  4639. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  4640. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  4641. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  4642.  
  4643.  
  4644. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  4645. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  4646. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  4647. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  4648.  
  4649.  
  4650.  
  4651. }
  4652.  
  4653. cProto.handlePropertyChange = function (...a) { // 10+
  4654.  
  4655. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4656. this.__resolved__ = {
  4657.  
  4658. };
  4659. const a01 = this.isAttached;
  4660. let a02, a03;
  4661.  
  4662.  
  4663. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  4664.  
  4665. const stackFn = () => {
  4666. if (t !== this.__stackedKey3818__) {
  4667. return;
  4668. }
  4669. a03 = this.isAttached;
  4670.  
  4671. if (a01 === false && a02 === false && a03 === false) return;
  4672.  
  4673. if (a01 === true && a02 === true && a03 === true) {
  4674.  
  4675. } else {
  4676. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  4677. // unknown yt-icon#label-icon
  4678. return;
  4679. } else {
  4680. console.log('[yt-icon] debug', a01, a02, a03, this)
  4681. }
  4682. }
  4683.  
  4684. this.handlePropertyChange671(...arguments);
  4685.  
  4686. };
  4687.  
  4688.  
  4689.  
  4690. Promise.resolve().then(() => {
  4691. a02 = this.isAttached;
  4692. stackTask(stackFn);
  4693. });
  4694.  
  4695.  
  4696. }
  4697.  
  4698. cProto.determineIconSet = function (a, b, c, d) { // 10-
  4699.  
  4700. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4701. // string bool? bool=false int=24
  4702. // NOTIFICATIONS_NONE OR LIKE
  4703. // console.log('yt-icon.determineIconSet', ...arguments);
  4704.  
  4705. const r = this.determineIconSet671(...arguments);
  4706. return r;
  4707. }
  4708.  
  4709. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  4710.  
  4711. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4712. // same as determineIconSet
  4713. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  4714. return this.switchToYtSysIconset671(...arguments);
  4715. }
  4716.  
  4717. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  4718.  
  4719. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4720. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  4721. return this.useYtSysIconsetForMissingIcons671(...arguments);
  4722. }
  4723.  
  4724. cProto.getIconManager = function () { // 10+
  4725.  
  4726. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4727. if (!this.__resolved__) this.__resolved__ = {};
  4728. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  4729. const r = this.__resolved__.getIconManager;
  4730. return r;
  4731. }
  4732.  
  4733. cProto.getIconShapeData = function () { // 10+
  4734.  
  4735. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4736.  
  4737. // no argument
  4738. // console.log('yt-icon.getIconShapeData', ...arguments);
  4739. if (!this.__resolved__) this.__resolved__ = {};
  4740. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  4741. const r = this.__resolved__.getIconShapeData;
  4742. return r
  4743. }
  4744.  
  4745. cProto.renderIcon = function (a, b) { // X
  4746.  
  4747. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4748. // "" yt-icons:xxx
  4749. // console.log('yt-icon.renderIcon', ...arguments);
  4750. return this.renderIcon671(...arguments);
  4751. }
  4752.  
  4753. });
  4754.  
  4755.  
  4756.  
  4757. const createStampDomFnsB_ = ()=>{
  4758.  
  4759. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  4760.  
  4761. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  4762. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  4763.  
  4764. const rq0 = document.createElement('rp');
  4765. rq0.setAttribute('yt-element-placholder', '');
  4766.  
  4767. let activeStampContainerId = '';
  4768.  
  4769. const componentBasedTaskPool = new WeakMap();
  4770.  
  4771. const getStampContainer_ = function (containerId){
  4772.  
  4773. this.__activeContainerId929__ = containerId;
  4774.  
  4775. return this.getStampContainer7409_(containerId);
  4776.  
  4777. }
  4778.  
  4779.  
  4780. const it0 = Date.now() - 80000000000;
  4781. const genId = ()=>`${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now()-it0).toString(36)}`;
  4782.  
  4783.  
  4784. const createComponent_ = function (componentConfig, data, canReuse) {
  4785.  
  4786. const containerId = this.__activeContainerId929__;
  4787.  
  4788. const r = rq0.cloneNode(false);
  4789.  
  4790. r.is = genId();
  4791.  
  4792. return r;
  4793.  
  4794. }
  4795.  
  4796. /*
  4797. const eTasks = [];
  4798.  
  4799. let executing = false;
  4800. const executeTasks = async () => {
  4801.  
  4802. if(!eTasks.length) return;
  4803. if (executing) return;
  4804. executing = true;
  4805.  
  4806. try {
  4807.  
  4808. let eTask;
  4809. let t0 = performance.now();
  4810. while (eTask = eTasks.shift()) {
  4811. eTask.fn(eTask);
  4812. const t1 = performance.now();
  4813. if (t1 - t0 > 10) {
  4814. await nextBrowserTick_();
  4815. t0 = t1;
  4816. } else {
  4817. await Promise.resolve();
  4818. }
  4819. }
  4820. } catch (e) {
  4821. console.warn(e);
  4822. }
  4823.  
  4824. executing = false;
  4825.  
  4826. }
  4827. */
  4828.  
  4829. let executing = false;
  4830. let eTasks = [];
  4831. let setRkT0;
  4832. let rkT0;
  4833.  
  4834. const rxProcessTask = () => {
  4835. if (setRkT0) {
  4836. rkT0 = performance.now();
  4837. setRkT0 = false;
  4838. }
  4839. const eTask = eTasks.shift();
  4840. if (!eTask) {
  4841. executing = false;
  4842. return;
  4843. }
  4844. try {
  4845. eTask.fn(eTask);
  4846. if (performance.now() - rkT0 > 10) {
  4847. setRkT0 = true;
  4848. nextBrowserTick_(rxProcessTask);
  4849. } else {
  4850. queueMicrotask_(rxProcessTask);
  4851. }
  4852. } catch (e) {
  4853. console.warn(e);
  4854. executing = false;
  4855. }
  4856. };
  4857. const executeTasks = () => {
  4858. if (!eTasks.length) return;
  4859. if (executing) return;
  4860. executing = true;
  4861. setRkT0 = true;
  4862. rxProcessTask();
  4863. };
  4864.  
  4865.  
  4866. const processTask = (mTask)=>{
  4867.  
  4868. let {component} = mTask;
  4869. component = kRef(component);
  4870. const pTask = component ? componentBasedTaskPool.get(component) : null;
  4871. if(!pTask) return;
  4872. let {step, producer, containerId, typeOrConfig, data, flushing, selfProducer} = pTask;
  4873. producer = kRef(producer);
  4874. selfProducer = kRef(selfProducer);
  4875.  
  4876. // console.log(18843992, component, {...pTask})
  4877.  
  4878. const resolveSelfAndCheckParent = ()=>{
  4879. const node = component;
  4880.  
  4881. const s = new Set();
  4882. node.removeAttribute('ytx-flushing');
  4883. const parentComponent = node.closest('[ytx-flushing]');
  4884. if(parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]') ){
  4885. if(!s.has(parentComponent[wk])){
  4886. s.add(parentComponent[wk])
  4887. eTasks.unshift({
  4888. component: parentComponent[wk],
  4889. fn: processTask
  4890. })
  4891. }
  4892. }
  4893.  
  4894. if(producer){
  4895.  
  4896. const parentComponent = producer.hostElement;
  4897. if(parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]') ){
  4898. if(!s.has(parentComponent[wk])){
  4899. s.add(parentComponent[wk])
  4900. eTasks.unshift({
  4901. component: parentComponent[wk],
  4902. fn: processTask
  4903. })
  4904. }
  4905. }
  4906.  
  4907. }
  4908.  
  4909. if(selfProducer){
  4910.  
  4911. const parentComponent = selfProducer.hostElement;
  4912. if(parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]') ){
  4913. if(!s.has(parentComponent[wk])){
  4914. s.add(parentComponent[wk])
  4915. eTasks.unshift({
  4916. component: parentComponent[wk],
  4917. fn: processTask
  4918. })
  4919. }
  4920. }
  4921.  
  4922. }
  4923.  
  4924. s.clear();
  4925.  
  4926.  
  4927. }
  4928. if(pTask.step === 'creation'){
  4929.  
  4930. if (!producer) return;
  4931. if(component.parentNode && component.parentNode.id === containerId && component.parentNode === producer.getStampContainer7409_(containerId) ){
  4932. pTask.step = 'flushStamper';
  4933.  
  4934. const aNode = producer.createComponent7409_(typeOrConfig, data, false);
  4935. const qNode = component;
  4936.  
  4937. aNode.setAttribute('ytx-stamp', 'flusher');
  4938. aNode.setAttribute('ytx-flushing', '2')
  4939. if(!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  4940.  
  4941. const container = producer.getStampContainer7409_(containerId);
  4942. const containerApi = container.__domApi || container;
  4943.  
  4944. const frag = document.createDocumentFragment();
  4945. frag.appendChild(aNode);
  4946. containerApi.insertBefore(frag, qNode);
  4947. containerApi.removeChild(qNode);
  4948.  
  4949. componentBasedTaskPool.delete(qNode)
  4950. componentBasedTaskPool.set(aNode, pTask)
  4951.  
  4952.  
  4953. eTasks.unshift({
  4954. component: aNode[wk],
  4955. fn: processTask
  4956. })
  4957. return;
  4958.  
  4959.  
  4960. }
  4961. } else if(pTask.step === 'flushStamper'){
  4962.  
  4963. if (!producer) return;
  4964. pTask.step = 'flushStamperWait';
  4965. pTask.typeOrConfig = null;
  4966. pTask.data = null;
  4967.  
  4968. const node = component;
  4969. node.setAttribute('ytx-flushing', '3');
  4970. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  4971. // flushedObserver.observe(node, { subtree: true, childList: true });
  4972. producer.deferredBindingTasks_.push(taskB);
  4973. producer.flushRenderStamperComponentBindings7409_();
  4974.  
  4975. node.setAttribute('ytx-flushing', '4');
  4976.  
  4977.  
  4978. if(!node.querySelector('[ytx-flushing]')){
  4979.  
  4980. eTasks.unshift({
  4981. component: component[wk],
  4982. fn: processTask
  4983. })
  4984. return;
  4985. }
  4986.  
  4987.  
  4988.  
  4989. } else if (pTask.step === 'flushStamperWait'){
  4990. if (!producer) return;
  4991.  
  4992. // producer undetermined
  4993.  
  4994. const node = component;
  4995.  
  4996. if(!node.querySelector('[ytx-flushing]')){
  4997.  
  4998. pTask.step = 'idleContainer';
  4999.  
  5000. resolveSelfAndCheckParent();
  5001.  
  5002.  
  5003. }
  5004.  
  5005.  
  5006. } else if (pTask.step === 'waitContainersRenderFinish'){
  5007.  
  5008. const node = component;
  5009.  
  5010. if(!node.querySelector('[ytx-flushing]')){
  5011. pTask.step = 'idleProducer';
  5012. node.setAttribute('ytx-flushing', 's-2')
  5013. }
  5014. // const selfProducer = kRef(pTask.selfProducer);
  5015.  
  5016.  
  5017. }
  5018.  
  5019.  
  5020. if(selfProducer && flushing && flushing.length > 0){
  5021.  
  5022. const node = component;
  5023. if(!node.querySelector('[ytx-flushing]')){
  5024.  
  5025. // pTask.step = 'idleProducer';
  5026.  
  5027. // node.setAttribute('ytx-flushing', 's-2')
  5028.  
  5029. let shouldMarkDirty = false;
  5030.  
  5031. const m = new Set();
  5032.  
  5033.  
  5034. // console.log(644221399, node, [...flushing])
  5035.  
  5036. const producer = selfProducer;
  5037.  
  5038. for(const [containerId, bEvent, hasData] of flushing){
  5039. if(hasData){
  5040. shouldMarkDirty = true;
  5041. if(bEvent){
  5042. const container = producer.getStampContainer7409_(containerId);
  5043. // console.log(644221499, container)
  5044. m.add(container);
  5045. }
  5046. }
  5047. }
  5048. // flushing.clear();
  5049. flushing.length = 0;
  5050.  
  5051. if (shouldMarkDirty) {
  5052. producer.markDirty && producer.markDirty();
  5053. let q = true;
  5054. for (const container of m) {
  5055. if(!q) producer.markDirty && producer.markDirty();
  5056. q = false;
  5057. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  5058. container
  5059. });
  5060. }
  5061. }
  5062.  
  5063. if(node.getAttribute('ytx-flushing') === 's-2') node.setAttribute('ytx-flushing', 's-3');
  5064.  
  5065.  
  5066. resolveSelfAndCheckParent();
  5067.  
  5068. //... event
  5069. }
  5070. }
  5071.  
  5072. // [...document.querySelectorAll('[ytx-flushing]')].filter(e=>!e.querySelector('[ytx-flushing]')).forEach((node)=>{
  5073. // if(node && node[wk] && componentBasedTaskPool.get(node)){
  5074.  
  5075. // eTasks.unshift({
  5076. // component: node[wk],
  5077. // fn: processTask
  5078. // });
  5079. // }
  5080.  
  5081.  
  5082. // })
  5083.  
  5084. }
  5085.  
  5086. const childrenObs = new MutationObserver((mutations) => {
  5087. const nodes = new Set();
  5088. for(const mutation of mutations){
  5089. if(mutation.addedNodes && mutation.addedNodes.length >= 1){
  5090. for(const addedNode of mutation.addedNodes){
  5091. nodes.add(addedNode);
  5092. }
  5093. }
  5094. if(mutation.removedNodes && mutation.removedNodes.length >= 1){
  5095. for(const removedNode of mutation.removedNodes){
  5096. nodes.add(removedNode);
  5097. }
  5098. }
  5099. nodes.add(mutation.target);
  5100. }
  5101. if (!nodes.size) return;
  5102. const flushDom = new Set();
  5103. for (let node of nodes) {
  5104. if (node.nodeType !== 1) {
  5105. node = node.parentNode;
  5106. }
  5107. if (node && node.nodeType === 1) {
  5108. flushDom.add(node.closest('[ytx-flushing]'));
  5109. }
  5110. }
  5111. for (const node of flushDom) {
  5112. if (node && node[wk] && componentBasedTaskPool.get(node)) {
  5113. eTasks.push({
  5114. component: node[wk],
  5115. fn: processTask
  5116. });
  5117. }
  5118. }
  5119. executeTasks();
  5120. });
  5121.  
  5122. // Element.prototype.ssk1 = function(){
  5123. // return componentBasedTaskPool.get(this)
  5124. // }
  5125. // Element.prototype.ssk2= function(){
  5126. // eTasks.push({
  5127. // component: this[wk],
  5128. // fn: processTask
  5129. // });
  5130. // executeTasks();
  5131. // }
  5132.  
  5133. // setInterval(()=>{
  5134.  
  5135. // if(!executing){
  5136.  
  5137. // for(const p of document.querySelectorAll('[ytx-flushing]')){
  5138. // eTasks.push({
  5139. // component: p[wk],
  5140. // fn: processTask
  5141. // });
  5142. // }
  5143.  
  5144. // executeTasks();
  5145. // }
  5146. // }, 500)
  5147.  
  5148. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  5149.  
  5150. const containerId = this.__activeContainerId929__;
  5151. if(!component[wk]) component[wk] = mWeakRef(component);
  5152. if(!this[wk]) this[wk] = mWeakRef(this);
  5153.  
  5154. const pTask = componentBasedTaskPool.get(component);
  5155.  
  5156. if(pTask && component.nodeName !== "RP"){
  5157.  
  5158. component.setAttribute('ytx-flushing', 'c-1');
  5159.  
  5160.  
  5161.  
  5162. for(const e of component.querySelectorAll('[ytx-flushing]')){
  5163. const pTask = componentBasedTaskPool.get(e);
  5164. if(pTask) {
  5165. pTask.step = 'abandon';
  5166. if(pTask.flushing) pTask.flushing.length = 0 ;
  5167. pTask.flushing = null;
  5168.  
  5169. pTask.typeOrConfig = null
  5170. pTask.data = null
  5171. // console.log(2377)
  5172. /*
  5173. pTask.producer = null
  5174. pTask.containerId = null
  5175. pTask.typeOrConfig = null
  5176. pTask.data = null
  5177. pTask.flushing = null;
  5178. */
  5179. componentBasedTaskPool.delete(e);
  5180. }
  5181. // e.removeAttribute('ytx-flushing')
  5182. }
  5183.  
  5184. if(pTask.flushing) pTask.flushing.length = 0;
  5185.  
  5186. // console.log(123, component.querySelectorAll('[ytx-flushing]'))
  5187.  
  5188.  
  5189. Object.assign(pTask, {
  5190. step: 'flushStamper',
  5191. producer: this[wk],
  5192. containerId: containerId,
  5193. typeOrConfig: typeOrConfig,
  5194. data: data
  5195. });
  5196.  
  5197. // let q = false;
  5198.  
  5199. // if(component.isConnected && !component.closest('[hidden]')){
  5200. // // const container = this.getStampContainer7409_(containerId);
  5201. // // if(container && container.isConnected){
  5202. // // // const containerApi = container.__domApi || container;
  5203. // // // let p = document.createElement('rp');
  5204. // // // containerApi.insertBefore(p, component).replaceWith(component);
  5205. // // // p.remove();
  5206. // // // q = true;
  5207. // // }
  5208.  
  5209. // // use direct dom interface.
  5210. // let p = document.createElement('rp');
  5211. // component.parentNode.insertBefore(p, component).replaceWith(component);
  5212. // p.remove();
  5213.  
  5214. // }
  5215.  
  5216. if (component.parentNode) {
  5217. let p = document.createComment('.');
  5218. component.parentNode.insertBefore(p, component).replaceWith(component);
  5219. p.remove();
  5220. }
  5221.  
  5222.  
  5223. // if(!q){
  5224. // processTask({
  5225. // component: component[wk],
  5226. // fn: processTask
  5227. // })
  5228. // }
  5229.  
  5230.  
  5231. // requestAnimationFrame(()=>{
  5232.  
  5233. // executeTasks();
  5234. // })
  5235.  
  5236.  
  5237.  
  5238. eTasks.unshift({
  5239. component: component[wk],
  5240. fn: processTask
  5241. });
  5242.  
  5243. }else{
  5244. component.setAttribute('ytx-flushing', '1');
  5245.  
  5246. component.setAttribute('ytx-stamp', 'flusher')
  5247.  
  5248. if(pTask){
  5249.  
  5250. Object.assign(pTask, {
  5251. step: 'creation',
  5252. producer: this[wk],
  5253. containerId: containerId,
  5254. typeOrConfig: typeOrConfig,
  5255. data: data
  5256. });
  5257. } else {
  5258.  
  5259. componentBasedTaskPool.set(component, {
  5260. step: 'creation',
  5261. producer: this[wk],
  5262. containerId: containerId,
  5263. typeOrConfig: typeOrConfig,
  5264. data: data
  5265. })
  5266. }
  5267.  
  5268. eTasks.push({
  5269. component: component[wk],
  5270. fn: processTask
  5271. });
  5272. }
  5273.  
  5274. const container = this.getStampContainer7409_(containerId);
  5275. if (container && !container.__rk75401__) {
  5276. container.__rk75401__ = true;
  5277. childrenObs.observe(container, { subtree: false, childList: true });
  5278. }
  5279.  
  5280. executeTasks();
  5281.  
  5282.  
  5283. }
  5284. flushRenderStamperComponentBindings_ = function (){
  5285. throw new Error('5ii48')
  5286. }
  5287.  
  5288. stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  5289.  
  5290. // console.log(644221001)
  5291. bReuse = false;
  5292.  
  5293.  
  5294. this.__activeContainerId929__ = containerId;
  5295.  
  5296. const producer = this;
  5297. const hostElement = producer.hostElement;
  5298. if(!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  5299. if(hostElement.getAttribute('ytx-stamp') === 'flusher'){
  5300.  
  5301. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  5302. }else if (!hostElement.hasAttribute('ytx-stamp')){
  5303.  
  5304. hostElement.setAttribute('ytx-stamp', 'producer');
  5305. }
  5306. const pTask = componentBasedTaskPool.get(hostElement) // can be flushStampWait -> waitContainersRenderFinish
  5307.  
  5308. const flushing = pTask? (pTask.flushing || []) : [];
  5309. // if(!flushing) debugger;
  5310. flushing.push([containerId, bEventCb, !!dataList]);
  5311.  
  5312. // console.log(644221299, containerId, bEventCb, !!dataList)
  5313.  
  5314. if(pTask){
  5315.  
  5316. // const pTaskProducer = pTask.producer;
  5317. // const parentProducer = pTaskProducer && pTaskProducer !== this[wk] ? pTaskProducer : null;
  5318. // const parentProducerContainerId = parentProducer ? pTask.containerId : null;
  5319.  
  5320. Object.assign(pTask, {
  5321. step: 'waitContainersRenderFinish',
  5322. selfProducer: this[wk],
  5323. flushing
  5324. });
  5325.  
  5326. // if(parentProducer && parentProducerContainerId){
  5327. // Object.assign(pTask, {
  5328. // parentProducer,
  5329. // parentProducerContainerId
  5330. // });
  5331. // }
  5332.  
  5333. } else {
  5334.  
  5335. componentBasedTaskPool.set(hostElement, {
  5336. step: 'waitContainersRenderFinish',
  5337. selfProducer: this[wk],
  5338. flushing
  5339.  
  5340. });
  5341. }
  5342.  
  5343. hostElement.setAttribute('ytx-flushing', 's-1');
  5344.  
  5345. hostElement.checkEE = ()=>{
  5346. console.log(componentBasedTaskPool.get(hostElement));
  5347. }
  5348.  
  5349. let r, e_
  5350. try{
  5351.  
  5352. this.stampDomArray8581_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  5353. }catch(e){
  5354. e_ = e;
  5355. }
  5356.  
  5357.  
  5358. // console.log()
  5359.  
  5360.  
  5361. eTasks.unshift({
  5362. component: hostElement[wk],
  5363. fn: processTask
  5364. });
  5365.  
  5366.  
  5367.  
  5368. const container = this.getStampContainer7409_(containerId);
  5369. if (container && !container.__rk75401__) {
  5370. container.__rk75401__ = true;
  5371. childrenObs.observe(container, { subtree: false, childList: true });
  5372. }
  5373.  
  5374. // if (hostElement && !hostElement.__rk75401__) {
  5375. // hostElement.__rk75401__ = true;
  5376. // childrenObs.observe(hostElement, { subtree: true, childList: true });
  5377. // }
  5378.  
  5379. // container.appendChild(document.createComment('.')).remove(); // trigger childrenObs for component reuse
  5380. // hostElement.appendChild(document.createComment('.')).remove(); // trigger childrenObs for component reuse
  5381.  
  5382. executeTasks();
  5383.  
  5384.  
  5385. if(e_ && e_.message !== '5ii48') throw e_;
  5386.  
  5387. }
  5388.  
  5389.  
  5390. return {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_};
  5391.  
  5392.  
  5393. }
  5394.  
  5395. const createStampDomFns_ = ()=>{
  5396.  
  5397. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  5398.  
  5399. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  5400. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  5401.  
  5402. // const convMap = new WeakMap();
  5403.  
  5404. const rq0 = document.createElement('rp');
  5405. rq0.setAttribute('yt-element-placholder', '');
  5406.  
  5407. const registry = new FinalizationRegistry_((heldValue)=>{
  5408. // console.log('component clean up', heldValue);
  5409. });
  5410.  
  5411. const syb1 = Symbol(); // data id
  5412. const syb2 = Symbol(); // element id
  5413. const syb3 = Symbol(); // container obs.
  5414. const syb4 = Symbol(); // producer id
  5415. const syb5 = Symbol(); // component belong to
  5416. const syb6 = Symbol(); // bind componentConfig events true
  5417. const syb7 = Symbol(); // containerElement -> container binding
  5418. const syb8 = Symbol(); // flag for container flush event
  5419. const syb9 = Symbol(); // container to producerId
  5420.  
  5421. const producerMap = new Map();
  5422.  
  5423.  
  5424. const it0 = Date.now() - 80000000000;
  5425. const genId = ()=>`${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now()-it0).toString(36)}`;
  5426.  
  5427. const emptyDocument = document.implementation.createHTMLDocument();
  5428. const emptyHTMLRoot = emptyDocument.firstElementChild;
  5429.  
  5430. const syb0 = Symbol();
  5431.  
  5432. const hashs = new Set();
  5433. const hashs2 = new Set();
  5434. hashs.add = Set.prototype.add;
  5435. hashs.has = Set.prototype.has;
  5436. hashs.delete = Set.prototype.delete;
  5437.  
  5438. Node.prototype[syb0] = true;
  5439.  
  5440. if (stampDomArray_MemoryFix_Flag001) {
  5441. {
  5442. const { set, get, has } = Map.prototype;
  5443. Map.prototype.setOriginal = Map.prototype.set;
  5444. Map.prototype.set = function (k, v) {
  5445. if (k && k[syb0]) {
  5446. if (!this[wk]) this[wk] = mWeakRef(this);
  5447. hashs.add(this[wk]);
  5448. }
  5449. if (v && v[syb0]) {
  5450. if (!this[wk]) this[wk] = mWeakRef(this);
  5451. hashs2.add(this[wk]);
  5452. }
  5453. return set.call(this, k, v);
  5454. }
  5455. }
  5456.  
  5457. {
  5458. const { add, has } = Set.prototype;
  5459. Set.prototype.addOriginal = Set.prototype.add;
  5460. Set.prototype.add = function (k) {
  5461. if (k && k[syb0]) {
  5462. if (!this[wk]) this[wk] = mWeakRef(this);
  5463. hashs.add(this[wk]);
  5464. }
  5465. return add.call(this, k);
  5466. }
  5467. };
  5468.  
  5469. }
  5470.  
  5471. const cleanRegister = new FinalizationRegistry_((heldValue) => {
  5472. // console.log(21399)
  5473. heldValue();
  5474. });
  5475.  
  5476. const cleanComponentTasks = [];
  5477.  
  5478. const cleanComponent = stampDomArray_MemoryFix_Flag001 ? (component) => {
  5479. if (!component || typeof component !== 'object') return;
  5480. if (!component[wk]) component[wk] = mWeakRef(component);
  5481. cleanComponentTasks.push(component[wk]);
  5482. } : () => { };
  5483.  
  5484. if (stampDomArray_MemoryFix_Flag001) {
  5485. new MutationObserver(() => {
  5486. if (cleanComponentTasks.length === 0) return;
  5487. if (document.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) return;
  5488. const tasks = cleanComponentTasks.slice();
  5489. cleanComponentTasks.length = 0;
  5490. // console.log('try clean', tasks.length)
  5491. for (const componentWr of tasks) {
  5492. const component = kRef(componentWr);
  5493. if (!component) continue;
  5494. cleanComponent_(component);
  5495. }
  5496. tasks.length = 0;
  5497. }).observe(document, { subtree: true, childList: true });
  5498. }
  5499.  
  5500. const cleanComponent_ = stampDomArray_MemoryFix_Flag001 ? (component) => {
  5501. if (!component) return;
  5502. if (component.parentNode) return;
  5503. if (component.__cleaned9941__) return;
  5504.  
  5505. component.__cleaned9941__ = true;
  5506. const producerId = component[syb5];
  5507. const producerCnt = producerId ? kRef(producerMap.get(producerId)) : null;
  5508. // if(!producerCnt) return;
  5509. const wrapApi = standardWrap_(component);
  5510. delete wrapApi.node;
  5511. const key = wrapApi.__componentIdRemoved__ = component[syb2]
  5512. const cnt = insp(component);
  5513.  
  5514.  
  5515. const componentNodeName = component.nodeName.toLowerCase();
  5516.  
  5517. const cleanMapping = {}
  5518. if (cnt && cnt.is) {
  5519.  
  5520. window.cleanComponents = window.cleanComponents || [];
  5521. window.cleanComponents.push({ type: componentNodeName, keyId: key, state: cleanMapping });
  5522.  
  5523. cnt.__testclean__ = {};
  5524.  
  5525.  
  5526. for (const [k, pd] of Object.entries(Object.getOwnPropertyDescriptors(cnt))) {
  5527. if (pd.get) continue;
  5528. const v = pd.value;
  5529. if (!v) continue;
  5530. if (typeof v === 'boolean' || typeof v === 'number' || typeof v === 'string' || typeof v === 'undefined') continue;
  5531. if (pd.writable === false && pd.configurable === false) continue;
  5532.  
  5533. if (Reflect.getPrototypeOf(cnt)[k] === v) continue;
  5534. cleanMapping[k] = false;
  5535. const f = ((k, v) => {
  5536.  
  5537. return () => {
  5538. cleanMapping[k] = true;
  5539. };
  5540. })(k, v);
  5541. cleanRegister.register(v, f);
  5542.  
  5543. // $
  5544. // hostElement
  5545. // observedAttributes
  5546. // root
  5547. // __templateInfo
  5548.  
  5549. // signalProxy
  5550. // provide
  5551. // polySiParams
  5552. // polySiInfo
  5553.  
  5554. // polySiContext
  5555. // observedAttributes
  5556. // hostElement
  5557.  
  5558.  
  5559.  
  5560.  
  5561.  
  5562.  
  5563. }
  5564.  
  5565. }
  5566.  
  5567.  
  5568. if (typeof cnt.unobserve_ === 'function') {
  5569. cnt.unobserve_();
  5570. cnt.unobserve_ = null;
  5571. }
  5572.  
  5573.  
  5574. if (cnt.disconnectedCallback) {
  5575.  
  5576. try {
  5577. cnt.disconnectedCallback();
  5578. } catch (e) { }
  5579.  
  5580. }
  5581.  
  5582. if (cnt.root && cnt.root !== emptyHTMLRoot) cnt.root = emptyHTMLRoot;
  5583. if (typeof cnt.__removeChildren === 'function') {
  5584. try {
  5585. cnt.__removeChildren();
  5586. } catch (e) { }
  5587. }
  5588. emptyHTMLRoot.textContent = '';
  5589.  
  5590.  
  5591. if (typeof cnt.unregisterRenderer_ === 'function' && typeof (cnt.childCache_ || 0) === 'object') {
  5592. for (let k in cnt.childCache_) {
  5593. cnt.unregisterRenderer_(k);
  5594. }
  5595. cnt.unregisterRenderer_ = null;
  5596. }
  5597.  
  5598. if (producerCnt && (producerCnt.childCache_ instanceof Set || (producerCnt.childCache_ instanceof WeakSet))) {
  5599. producerCnt.childCache_.delete(component);
  5600. }
  5601.  
  5602. cnt.disablePrescanVisibility = true;
  5603. if (cnt.signalProxy) {
  5604. cnt.signalProxy.dispose();
  5605. if (cnt.signalProxy.options) {
  5606. if (cnt.signalProxy.options.reactiveProps) {
  5607. cnt.signalProxy.options.reactiveProps.clear();
  5608. cnt.signalProxy.options.reactiveProps = null;
  5609. }
  5610.  
  5611. if (cnt.signalProxy.owner.disposables) {
  5612. cnt.signalProxy.owner.disposables.length = 0;
  5613. cnt.signalProxy.owner.disposables = null;
  5614. }
  5615. const { model, signalCache } = cnt.signalProxy;
  5616. if (model) {
  5617. for (let k in model) {
  5618. model[k] = null;
  5619. }
  5620. }
  5621.  
  5622. if (signalCache) {
  5623. if (signalCache) {
  5624. for (let k in signalCache) {
  5625. signalCache[k] = null;
  5626. }
  5627. }
  5628. }
  5629.  
  5630. }
  5631.  
  5632. cnt.signalProxy = null;
  5633. }
  5634. if (typeof cnt.dispose === 'function') {
  5635. cnt.dispose();
  5636. cnt.dispose = null;
  5637. }
  5638.  
  5639. cnt.$ = null;
  5640. if (cnt.__children && cnt.__children.length > 0) cnt.__children.length = 0;
  5641. cnt.__children = null;
  5642. cnt.root = null;
  5643. cnt.__isUpgradeDisabled = true;
  5644.  
  5645. const { __data } = cnt;
  5646. if (__data) {
  5647. for (let k in __data) __data[k] = null;
  5648. cnt.__data = null;
  5649. }
  5650.  
  5651. emptyHTMLRoot.textContent = '';
  5652.  
  5653. for (const hash of hashs) {
  5654. const m = kRef(hash);
  5655. if (m) {
  5656. m.delete(cnt);
  5657. m.delete(component);
  5658. m.delete(wrapApi);
  5659. }
  5660. }
  5661.  
  5662. for (const hash of hashs2) {
  5663. const m = kRef(hash);
  5664. if (m) {
  5665. for (const [k, v] of m.entries()) {
  5666. if (v === cnt || v === component || v === wrapApi) {
  5667. m.delete(k);
  5668. }
  5669. }
  5670. }
  5671. }
  5672.  
  5673. /*
  5674. _removeEventListenerFromNode
  5675. _removeBoundDom
  5676. _removePropertyEffect
  5677. __observeEffects
  5678.  
  5679. observedAttributes
  5680.  
  5681. renderJobsMap_
  5682. localVisibilityObserver_
  5683. observeHiddenOption
  5684. observeVisibleOption
  5685.  
  5686. visibilityObserverForChild_
  5687. prescanObservers
  5688.  
  5689. */
  5690.  
  5691.  
  5692.  
  5693.  
  5694. if (cnt && cnt.is) {
  5695.  
  5696.  
  5697.  
  5698.  
  5699. for (const [k, pd] of Object.entries(Object.getOwnPropertyDescriptors(cnt))) {
  5700. if (pd.get) continue;
  5701. const v = pd.value;
  5702. if (!v) continue;
  5703. if (typeof v === 'boolean' || typeof v === 'number' || typeof v === 'string' || typeof v === 'undefined') continue;
  5704. if (pd.writable === false && pd.configurable === false) continue;
  5705. if (pd.writable === false && pd.configurable) delete cnt[k];
  5706.  
  5707. cnt[k] = null;
  5708.  
  5709. }
  5710.  
  5711. }
  5712.  
  5713.  
  5714.  
  5715. // const componentIs = component.is;
  5716. registry.register(wrapApi, `w::${key} [${componentNodeName}]`)
  5717.  
  5718. // if(cnt !== component) Object.setPrototypeOf(cnt, Object.prototype);
  5719. // if(wrapApi !== component) Object.setPrototypeOf(wrapApi, Object.prototype);
  5720. Object.setPrototypeOf(component, Reflect.getPrototypeOf(HTMLTitleElement).prototype);
  5721. // standardWrap_ producerCnt.listner
  5722.  
  5723. // console.log('try clean', `t::${key} [${componentNodeName}]`)
  5724. } : () => { };
  5725.  
  5726.  
  5727. const createFn = (node, binder)=>{
  5728. const q = node;
  5729. let {producer, typeOrConfig, data, canReuse} = binder;
  5730. producer = kRef(producer);
  5731. typeOrConfig = getTypeOfConfig(typeOrConfig);
  5732. data = kRef(data);
  5733.  
  5734.  
  5735. const component = producer.createComponent7409_(typeOrConfig, data, canReuse);
  5736. // if (component[syb5]) cleanComponent(component);
  5737. component[syb5] = producer[syb4];
  5738. component[syb1] = data[syb1];
  5739. component[syb2] = q[syb2] = genId();
  5740. const cnt = insp(component);
  5741. if (cnt && cnt !== component && !cnt[syb0]) {
  5742. Reflect.getPrototypeOf(insp(component))[syb0] = true;
  5743. }
  5744. const componentNodeName = component.nodeName.toLowerCase();
  5745. registry.register(component, `c::${component[syb2]} [${componentNodeName}]`);
  5746. registry.register(q, `q::${q[syb2]} [${componentNodeName}]`);
  5747. return component;
  5748. }
  5749.  
  5750. const setupFlush = (container, p) => {
  5751.  
  5752. const producerId = container[syb9];
  5753. const producer = producerId ? kRef(producerMap.get(producerId)) : null;
  5754. if (!producer) return;
  5755. if (!producer.hostElement) return;
  5756. if (!container || !container.parentNode || !container.nodeName || !container.id) return;
  5757.  
  5758. if (p === 'e' && container.getAttribute('ytx-stamping') !== 'e') {
  5759. container.setAttribute('ytx-stamping', p);
  5760. } else if (p === '1' && !container.hasAttribute('ytx-stamping')) {
  5761. container.setAttribute('ytx-stamping', p);
  5762. }
  5763.  
  5764. if (!producer.__stampTaskMap488__) producer.__stampTaskMap488__ = new Map();
  5765. producer.__stampTaskMap488__.set(container.id, container.getAttribute('ytx-stamping'));
  5766.  
  5767. }
  5768.  
  5769. const removeAttrFn = (mTask) => {
  5770. let { hostElement, producer, containerId } = mTask;
  5771. hostElement = kRef(hostElement);
  5772. producer = kRef(producer);
  5773. if (hostElement.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) return;
  5774. const container = producer.getStampContainer7409_(containerId);
  5775. if (!(container instanceof Node)) return;
  5776. if (!container.isConnected || !hostElement.isConnected) return;
  5777. dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  5778. container
  5779. });
  5780. };
  5781.  
  5782. const flushedFn = () => {
  5783.  
  5784.  
  5785. let eTasks = [];
  5786. let pending = new Set();
  5787.  
  5788. const removeAttr = (producer) => {
  5789.  
  5790. if (pending.has(producer)) return;
  5791.  
  5792. const hostElement = producer.hostElement;
  5793. if (!hostElement) return;
  5794.  
  5795. if (!hostElement.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  5796.  
  5797. const stampingLists = producer.__stampTaskMap488__;
  5798. const stampingListsNew = new Map(stampingLists || undefined);
  5799. if (stampingLists) stampingLists.clear();
  5800.  
  5801. pending.add(producer);
  5802.  
  5803. producer.markDirty && producer.markDirty();
  5804. for (const [containerId, event] of stampingListsNew.entries()) {
  5805. if (event === 'e') {
  5806.  
  5807. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  5808. if (!producer[wk]) producer[wk] = mWeakRef(producer);
  5809. eTasks.push({
  5810. hostElement: hostElement[wk],
  5811. producer: producer[wk],
  5812. containerId,
  5813. fn: removeAttrFn
  5814. });
  5815.  
  5816. }
  5817. }
  5818.  
  5819. }
  5820. }
  5821.  
  5822. let b;
  5823. do {
  5824. b = false;
  5825. for (const node of document.querySelectorAll('[ytx-flushing="3"]')) {
  5826. if (!node.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  5827. node.removeAttribute('ytx-flushing');
  5828. b = true;
  5829. }
  5830. }
  5831. for (const node of document.querySelectorAll('[ytx-stamping]')) {
  5832. if (!node.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  5833. node.removeAttribute('ytx-stamping');
  5834. const producerId = node[syb9];
  5835. const producer = producerId ? kRef(producerMap.get(producerId)) : null;
  5836. if (producer) removeAttr(producer);
  5837. b = true;
  5838. }
  5839. }
  5840. } while (b);
  5841.  
  5842. if (eTasks.length >= 1) {
  5843. Promise.resolve(eTasks).then((eTasks) => executeTaskBatch(eTasks, false));
  5844. }
  5845. pending.clear();
  5846. pending = null;
  5847. eTasks = null;
  5848. };
  5849.  
  5850. const flushedObserver = new MutationObserver((mutations) => {
  5851. flushedFn();
  5852. });
  5853.  
  5854. const containerChildernTaskFn1 = (eTask) => {
  5855. const { nodeWr, targetId, targetWr, bdrFlushId } = eTask;
  5856. const node = kRef(nodeWr);
  5857. if (!node.parentNode || !node.parentNode.id) return;
  5858. const bdr = node ? bindingMap.get(node) : null;
  5859. if (!bdr) return;
  5860. if (bdrFlushId !== bdr.flushId) return;
  5861. const producer = kRef(bdr.producer);
  5862. if (!producer) return;
  5863. const target = kRef(targetWr);
  5864. if (!target || target.id !== targetId || target !== node.parentNode) return;
  5865. if (node.getAttribute('ytx-flushing') === '1') {
  5866. bdr.stampingContainerId = targetId;
  5867. // console.log('set_flushing_2_02', node.nodeName);
  5868. node.setAttribute('ytx-flushing', '2');
  5869. }
  5870. };
  5871.  
  5872. const containerChildernTaskFn2 = (eTask) => {
  5873. const { nodeWr, targetId, targetWr, bdrFlushId } = eTask;
  5874. const node = kRef(nodeWr);
  5875. if (!node || !node.parentNode || !node.parentNode.id) return;
  5876. const bdr = bindingMap.get(node);
  5877. if (!bdr) return;
  5878. if (bdrFlushId !== bdr.flushId) return;
  5879. const producer = kRef(bdr.producer);
  5880. if (!producer) return;
  5881. const target = kRef(targetWr);
  5882. if (!target || target.id !== targetId || target !== node.parentNode) return;
  5883. bindingMap.delete(node);
  5884. bdr.created = true;
  5885. const newNode = createFn(node, bdr);
  5886. if (!newNode[wk]) newNode[wk] = mWeakRef(newNode);
  5887. if (newNode instanceof Node) {
  5888. newNode.setAttribute('ytx-flushing', '0');
  5889. newNode.setAttribute('ytx-flushing', '1');
  5890. }
  5891. bindingMap.set(newNode, bdr);
  5892. const containerId = targetId;
  5893.  
  5894. const container = producer.getStampContainer7409_(containerId);
  5895. const containerApi = container.__domApi || container;
  5896.  
  5897. const frag = document.createDocumentFragment();
  5898. frag.appendChild(newNode);
  5899. containerApi.insertBefore(frag, node);
  5900. containerApi.removeChild(node);
  5901.  
  5902. };
  5903.  
  5904. const containerChildernObs = new MutationObserver((mutations) => {
  5905.  
  5906.  
  5907. let eTasks = [];
  5908. let nodeList = new Set();
  5909.  
  5910. for (const mutation of mutations) {
  5911.  
  5912. // mutation.removedNodes
  5913.  
  5914. // mutation.addedNodes
  5915. const target = mutation.target;
  5916. if (!target.id || !target.parentNode) continue;
  5917. let p;
  5918.  
  5919. for (const node of mutation.addedNodes) {
  5920.  
  5921. if (node.parentNode !== target) continue;
  5922. if (nodeList.has(node)) continue;
  5923. nodeList.add(node);
  5924. if(node.isConnected === false) continue;
  5925.  
  5926. let bdr = bindingMap.get(node);
  5927. if (!bdr) continue;
  5928. let typeOrConfig = bdr ? kRef(bdr.typeOrConfig) : null;
  5929. let data = bdr ? kRef(bdr.data) : null;
  5930. if (typeOrConfig) {
  5931. if (typeof typeOrConfig === 'object' && typeOrConfig[syb6]) p = 'e';
  5932. if (!p) p = '1';
  5933. }
  5934.  
  5935. if (!node[wk]) node[wk] = mWeakRef(node);
  5936. if (!target[wk]) target[wk] = mWeakRef(target);
  5937.  
  5938. const bdrFlushId = bdr.flushId = genId();
  5939. if (bdr.created) {
  5940. eTasks.push({
  5941. nodeWr: node[wk],
  5942. targetId: target.id,
  5943. targetWr: target[wk],
  5944. bdrFlushId,
  5945. fn: containerChildernTaskFn1
  5946. });
  5947. } else if(node.nodeName === 'RP') {
  5948. eTasks.push({
  5949. nodeWr: node[wk],
  5950. targetId: target.id,
  5951. targetWr: target[wk],
  5952. bdrFlushId,
  5953. fn: containerChildernTaskFn2
  5954. });
  5955. }
  5956.  
  5957. }
  5958.  
  5959. for (const node of mutation.removedNodes) {
  5960.  
  5961. if (node.parentNode === target) continue;
  5962. if (nodeList.has(node)) continue;
  5963. nodeList.add(node);
  5964.  
  5965. let bdr = bindingMap.get(node);
  5966. if (!bdr) continue;
  5967. bdr.flushId = genId();
  5968. bindingMap.delete(node);
  5969. let typeOrConfig = bdr ? kRef(bdr.typeOrConfig) : null;
  5970. if (typeOrConfig) {
  5971. if (typeof typeOrConfig === 'object' && typeOrConfig[syb6]) p = 'e';
  5972. if (!p) p = '1';
  5973. }
  5974. // bdr.producer = bdr.typeOrConfig = bdr.data = null;
  5975.  
  5976.  
  5977. forceCancel(node, false);
  5978.  
  5979.  
  5980. node.removeAttribute('ytx-flushing');
  5981. Promise.resolve(node).then(cleanComponent);
  5982.  
  5983. }
  5984.  
  5985. if (p) {
  5986. setupFlush(target, p);
  5987. }
  5988. }
  5989.  
  5990.  
  5991. if (eTasks.length >= 1) {
  5992. Promise.resolve(eTasks).then((eTasks) => executeTaskBatch(eTasks, false));
  5993. }
  5994.  
  5995. nodeList.clear();
  5996. nodeList = null;
  5997. eTasks = null;
  5998.  
  5999.  
  6000. });
  6001.  
  6002. const flushTaskFn = (mTask) => {
  6003.  
  6004. const { containerWr, nodeWr, stampingContainerId, bdrFlushId } = mTask;
  6005. const node = kRef(nodeWr);
  6006. if (!node) return;
  6007. const flushingVal = node.getAttribute('ytx-flushing');
  6008. if (flushingVal !== '2x') return;
  6009.  
  6010. let skip = false;
  6011. const f = () => {
  6012.  
  6013. const bdr = bindingMap.get(node);
  6014. if (!bdr) return;
  6015. if (bdrFlushId !== bdr.flushId) {
  6016. skip = true;
  6017. return;
  6018. }
  6019. const producer = kRef(bdr.producer);
  6020. if (!producer) return;
  6021.  
  6022. if (bdr.stampingContainerId !== stampingContainerId) return;
  6023.  
  6024. const container = kRef(containerWr);
  6025. if (!container) return;
  6026. if (container.id !== stampingContainerId) return;
  6027.  
  6028. const typeOrConfig = getTypeOfConfig(bdr.typeOrConfig);
  6029.  
  6030. let data = kRef(bdr.data);
  6031. bdr.data = null;
  6032. let taskB = { component: node, typeOrConfig: typeOrConfig, data: data };
  6033. flushedObserver.observe(node, { subtree: true, childList: true });
  6034. producer.deferredBindingTasks_.push(taskB);
  6035. producer.flushRenderStamperComponentBindings7409_();
  6036. producer.deferredBindingTasks_.length = 0;
  6037. taskB.component = taskB.typeOrConfig = taskB.data = null;
  6038.  
  6039. }
  6040. let ok = false;
  6041. try {
  6042. f();
  6043. ok = true;
  6044. } catch (e) {
  6045. console.warn(e);
  6046. } finally {
  6047.  
  6048. }
  6049.  
  6050. if (!skip) {
  6051. node.setAttribute('ytx-flushing', '0');
  6052. node.setAttribute('ytx-flushing', '3');
  6053. node.appendChild(document.createComment('-')).remove();
  6054. // if (node.isConnected === true) {
  6055. // node.setAttribute('ytx-flushing', '0');
  6056. // node.setAttribute('ytx-flushing', '3');
  6057. // node.appendChild(document.createComment('-')).remove();
  6058. // } else {
  6059. // node.setAttribute('ytx-flushing', '0');
  6060. // node.setAttribute('ytx-flushing', '3');
  6061. // node.appendChild(document.createComment('-')).remove();
  6062.  
  6063.  
  6064. // let bdr = bindingMap.get(node);
  6065. // if (bdr) bdr.flushId = genId();
  6066.  
  6067. // for (const e of node.querySelectorAll('rp[yt-element-placholder], [ytx-flushing]')) {
  6068. // const bdr = bindingMap.get(e)
  6069. // if (!bdr) continue;
  6070. // bdr.flushId = genId();
  6071. // e.parentNode.appendChild(document.createComment('.')).remove();
  6072. // // e.remove();
  6073. // }
  6074.  
  6075. // for (const e of node.querySelectorAll('rp[yt-element-placholder]')) {
  6076. // e.remove();
  6077. // }
  6078. // for (const e of node.querySelectorAll('[ytx-flushing]')) {
  6079. // e.setAttribute('ytx-flushing', '3');
  6080. // }
  6081.  
  6082. // node.setAttribute('ytx-flushing', '3');
  6083. // flushedFn();
  6084.  
  6085.  
  6086. // for (const e of node.querySelectorAll('rp[yt-element-placholder]')) {
  6087. // e.remove();
  6088. // }
  6089. // for (const e of node.querySelectorAll('[ytx-stamping], [ytx-flushing]')) {
  6090. // e.removeAttribute('ytx-flushing');
  6091. // e.removeAttribute('ytx-stamping');
  6092. // }
  6093.  
  6094. // }
  6095. }
  6096.  
  6097. };
  6098.  
  6099. const flushObserver = new MutationObserver((mutations) => {
  6100.  
  6101. let targets = new Set();
  6102. for (const mutation of mutations) {
  6103. const target = mutation.target;
  6104. targets.add(target);
  6105. }
  6106.  
  6107. let eTasks = [];
  6108.  
  6109. let containerMap = new Map();
  6110. for (const target of targets) {
  6111.  
  6112. if (target.getAttribute('ytx-flushing') === '2') {
  6113.  
  6114. const node = target;
  6115.  
  6116. const container = target.parentNode;
  6117. if (!container || !container.id) continue;
  6118. if (target.isConnected === false) continue;
  6119.  
  6120. const bdr = bindingMap.get(node);
  6121. if (!bdr) continue;
  6122. const producer = kRef(bdr.producer);
  6123. if (!producer) continue;
  6124. const stampingContainerId = bdr.stampingContainerId;
  6125. if (stampingContainerId !== container.id) continue;
  6126.  
  6127. if (target.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  6128. console.log('need forceCancel 003');
  6129. forceCancel(target, false);
  6130. target.setAttribute('ytx-flushing', '0');
  6131. target.setAttribute('ytx-flushing', '2');
  6132. continue;
  6133. }
  6134. const bdrFlushId = bdr.flushId = genId();
  6135.  
  6136. target.setAttribute('ytx-flushing', '2x');
  6137.  
  6138. let p = containerMap.get(container);
  6139. const [typeOrConfig, p_] = getTypeOfConfig(bdr.typeOrConfig, true);
  6140. if (typeOrConfig) {
  6141. if (p_) p = 'e';
  6142. if (!p) p = '1';
  6143. containerMap.set(container, p);
  6144. }
  6145.  
  6146.  
  6147. if (!container[wk]) container[wk] = mWeakRef(container[wk]);
  6148. if (!node[wk]) node[wk] = mWeakRef(node[wk]);
  6149. eTasks.push({
  6150. containerWr: container[wk],
  6151. nodeWr: node[wk],
  6152. stampingContainerId,
  6153. bdrFlushId,
  6154. fn: flushTaskFn
  6155. })
  6156.  
  6157. }
  6158.  
  6159. }
  6160.  
  6161.  
  6162.  
  6163.  
  6164. containerMap.forEach((p, container) => {
  6165.  
  6166. if (container.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  6167.  
  6168. setupFlush(container, p)
  6169. }
  6170.  
  6171.  
  6172. });
  6173.  
  6174.  
  6175.  
  6176. if (eTasks.length >= 1) {
  6177. Promise.resolve(eTasks).then((eTasks) => executeTaskBatch(eTasks, false));
  6178. }
  6179.  
  6180. eTasks = null;
  6181.  
  6182.  
  6183.  
  6184. });
  6185.  
  6186. flushObserver.observe(document, {subtree: true, attributes: true, attributeFilter: ['ytx-flushing']});
  6187.  
  6188.  
  6189. const getTypeOfConfig = (typeOrConfig, b = false) => {
  6190. let p = null;
  6191. if (typeof typeOrConfig === 'object') typeOrConfig = kRef(typeOrConfig);
  6192. if (b && typeof typeOrConfig === 'object' && typeOrConfig[syb6]) p = typeOrConfig[syb6];
  6193. if (typeOrConfig && typeOrConfig.__rawType__) typeOrConfig = typeOrConfig.valueOf();
  6194. return b ? [typeOrConfig, p] : typeOrConfig;
  6195. }
  6196.  
  6197. const setBinding = (component, typeOrConfig, data, producer) => {
  6198.  
  6199. if (typeOrConfig && typeof typeOrConfig === 'object' && !typeOrConfig[wk]) {
  6200. typeOrConfig[wk] = mWeakRef(typeOrConfig);
  6201. typeOrConfig = typeOrConfig[wk]
  6202. }
  6203. if (!data[wk]) data[wk] = mWeakRef(data);
  6204. if (!producer[wk]) producer[wk] = mWeakRef(producer);
  6205. const oldBdr = bindingMap.get(component);
  6206. if (oldBdr) {
  6207. forceCancel(component, true);
  6208. oldBdr.producer = oldBdr.typeOrConfig = oldBdr.data = null;
  6209. oldBdr.flushId = genId();
  6210. }
  6211. const bdr = { typeOrConfig: typeOrConfig, data: data[wk], producer: producer[wk] };
  6212. bdr.flushId = genId();
  6213. bindingMap.set(component, bdr);
  6214.  
  6215. return bdr;
  6216. }
  6217.  
  6218.  
  6219. const byPassList = new Set([
  6220. // for YouTube Tabview Totara (instance data setter)
  6221. "YTD-STRUCTURED-DESCRIPTION-CONTENT-RENDERER",
  6222. "YTD-VIDEO-DESCRIPTION-HEADER-RENDERER",
  6223. "YTD-ENGAGEMENT-PANEL-SECTION-LIST-RENDERER",
  6224. ]);
  6225.  
  6226. const testCntByPass = (cnt) => {
  6227. const hostElement = cnt.hostElement;
  6228. if (hostElement instanceof Node) {
  6229. if (byPassList.has(hostElement.nodeName) || !cnt.stampDomArray_ || cnt.visibleItems || cnt.activeItems_ || cnt.tickerItems || cnt.updatePanel || cnt.updateChildVisibilityProperties || cnt.onYtRendererstamperFinished) {
  6230. const cProto = Reflect.getPrototypeOf(cnt);
  6231. if (cProto.is && cProto.is === cnt.is) {
  6232. cProto.__byPass7409__ = true;
  6233. cProto.createComponent_ = cProto.createComponent7409_;
  6234. cProto.deferRenderStamperBinding_ = cProto.deferRenderStamperBinding7409_;
  6235. cProto.flushRenderStamperComponentBindings_ = cProto.flushRenderStamperComponentBindings7409_;
  6236. cProto.getStampContainer_ = cProto.getStampContainer7409_;
  6237. }
  6238. return true;
  6239. }
  6240. const stampDom = cnt.stampDom;
  6241. if (!stampDom) return true;
  6242. for (const key of Object.getOwnPropertyNames(stampDom)) {
  6243. const stamp = stampDom[key];
  6244. if (typeof (stamp || 0) === 'object' && typeof (stamp.id || 0) === 'string') {
  6245. const e0 = stamp.id.charCodeAt(0);
  6246. if ((e0 >= 97 && e0 <= 122) || (e0 >= 65 && e0 <= 90)) {
  6247. const element = hostElement.querySelector(`#${stamp.id}`);
  6248. if (!element) continue;
  6249. if (element instanceof Node && element.firstElementChild) return true;
  6250. }
  6251. }
  6252. }
  6253. // if(hostElement.closest('[ytx-flushing="2x"], [ytx-flushing="3"]')) return true;
  6254. return testCntInvisible(cnt); // invisible state in the initial flushing
  6255. } else {
  6256. return true;
  6257. }
  6258. }
  6259.  
  6260. const testCntInvisible = (cnt) => {
  6261. const hostElement = cnt.hostElement;
  6262. if (!hostElement) return true;
  6263. // [hidden] test required?
  6264. return !!((hostElement && hostElement.closest('noscript, defs')) || (hostElement && hostElement.isConnected === false))
  6265. }
  6266.  
  6267. const doStampMapFix = function(){
  6268. if (!this.stampDom[syb6]) {
  6269. this.stampDom[syb6] = true;
  6270. for (const stampDetails of Object.values(this.stampDom)) {
  6271. const val = stampDetails.events;
  6272. if (val) {
  6273. const mapping = (stampDetails.mapping || 0);
  6274. if (typeof mapping === 'object') {
  6275. mapping[syb6] = val;
  6276. for (let [mapKey, mapVal] of Object.entries(mapping)) {
  6277. if (typeof mapVal !== 'object') {
  6278. const rawType = typeof mapVal;
  6279. mapVal = mapping[mapKey] = Object(mapVal);
  6280. mapVal.__rawType__ = rawType;
  6281. }
  6282. if (mapVal && typeof mapVal === 'object') mapVal[syb6] = val;
  6283. }
  6284. }
  6285. }
  6286. }
  6287. }
  6288.  
  6289. }
  6290.  
  6291. let firstActionStamper = null;
  6292. const bt0 = Date.now();
  6293.  
  6294. const checkByPass = (cnt) => {
  6295. let byPass = false;
  6296. if (!firstActionStamper) {
  6297. firstActionStamper = true;
  6298. cnt.__firstStamper1299__ = true;
  6299. // Promise.resolve().then(() => { firstActionStamper = null; });
  6300. // const cProto = Reflect.getPrototypeOf(cnt);
  6301. // cProto.__directStampFlush__ = true;
  6302. }
  6303. if (cnt.__firstStamper1299__) byPass = true;
  6304. else {
  6305. if (cnt.__byPass7409__ === undefined) cnt.__byPass7409__ = testCntByPass(cnt);
  6306. if (cnt.__byPass7409__ || testCntInvisible(cnt)) {
  6307. byPass = true;
  6308. }
  6309. }
  6310. cnt.__lastByPass__ = ((Date.now() - bt0) * 100 + Math.floor(Math.random() * 100)) * 2 + (byPass ? 1 : 0);
  6311. return byPass;
  6312. }
  6313.  
  6314. const getStampContainer_ = function(containerId){
  6315.  
  6316. const byPass = checkByPass(this);
  6317. if (byPass) return this.getStampContainer7409_(containerId);
  6318.  
  6319.  
  6320. doStampMapFix.call(this);
  6321. // console.log(1233)
  6322. const containerElement = this.getStampContainer7409_(containerId);
  6323. if (!this[syb4]) {
  6324. this[syb4] = genId();
  6325. if (!this[wk]) this[wk] = mWeakRef(this);
  6326. producerMap.set(this[syb4], this[wk]);
  6327. }
  6328. if (!containerElement[syb9]) containerElement[syb9] = this[syb4];
  6329. if (!containerElement[wk]) containerElement[wk] = mWeakRef(containerElement);
  6330.  
  6331. if (!containerElement[syb3]) {
  6332. containerElement[syb3] = true;
  6333. // stamperFlushedObs.observe(containerElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['ytx-stamping', 'ytx-flushing'] });
  6334.  
  6335. containerChildernObs.observe(containerElement, { subtree: false, childList: true });
  6336. // stamperFinishedObs.observe(containerElement, { attributes: true, attributeFilter: ['yt-stamping']})
  6337. // producerFinishedObs.observe(this.hostElement, { attributes: true, attributeFilter: ['yt-stamping']})
  6338. }
  6339.  
  6340. return containerElement;
  6341. }
  6342.  
  6343. const doNotCacheMe = `${Math.floor(Math.random() * 100) + 100}`;
  6344.  
  6345. const createComponent_ = function (componentConfig, data, canReuse) {
  6346.  
  6347. const byPass = checkByPass(this);
  6348. if (byPass) return this.createComponent7409_(componentConfig, data, canReuse);
  6349.  
  6350. doStampMapFix.call(this);
  6351. canReuse = false;
  6352. if (!data[syb1]) data[syb1] = genId();
  6353. if(!this[syb4]) {
  6354. this[syb4] = genId();
  6355. if (!this[wk]) this[wk] = mWeakRef(this);
  6356. producerMap.set(this[syb4], this[wk]);
  6357. }
  6358.  
  6359. const q = rq0.cloneNode(false);
  6360.  
  6361. q.is = doNotCacheMe;
  6362.  
  6363. return q;
  6364.  
  6365. }
  6366.  
  6367. const bindingMap = new WeakMap();
  6368.  
  6369. const forceCancel = (component, dismissFinish) => {
  6370.  
  6371. const node = component;
  6372. if (node.querySelector('rp[yt-element-placholder], [ytx-stamping], [ytx-flushing]')) {
  6373.  
  6374. for (const e of node.querySelectorAll('rp[yt-element-placholder], [ytx-flushing]')) {
  6375. const bdr = bindingMap.get(e)
  6376. if (bdr) {
  6377. bdr.flushId = genId();
  6378. const producer = kRef(bdr.producer);
  6379. const taskMap = producer ? producer.__stampTaskMap488__ : null;
  6380. if (taskMap instanceof Map) taskMap.clear();
  6381. }
  6382. if (e.hasAttribute('ytx-flushing')) {
  6383. e.removeAttribute('ytx-flushing');
  6384. e.appendChild(document.createComment('.')).remove();
  6385. } else if (e.hasAttribute('yt-element-placholder')) {
  6386. e.remove();
  6387. }
  6388. }
  6389.  
  6390. for (const e of node.querySelectorAll('[ytx-stamping]')) {
  6391. e.removeAttribute('ytx-stamping');
  6392. }
  6393.  
  6394. }
  6395.  
  6396. if (dismissFinish) {
  6397. const bdr = bindingMap.get(node);
  6398. if (bdr) {
  6399. const parentNode = node.parentNode;
  6400. const parentNodeId = parentNode ? parentNode.id : null;
  6401. const stampingContainerId = bdr.stampingContainerId;
  6402. const producer = kRef(bdr.producer);
  6403. const taskMap = producer ? producer.__stampTaskMap488__ : null;
  6404. if (taskMap instanceof Map) {
  6405. parentNodeId && taskMap.delete(parentNodeId);
  6406. stampingContainerId && taskMap.delete(stampingContainerId);
  6407. }
  6408. }
  6409. }
  6410.  
  6411. }
  6412.  
  6413.  
  6414. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  6415.  
  6416. const byPass = checkByPass(this);
  6417. if (byPass) return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  6418.  
  6419. const bdr = setBinding(component, typeOrConfig, data, this);
  6420.  
  6421. if (component && component.parentNode && component.parentNode.id && this.getComponentName_(typeOrConfig, data) === component.is && component.isConnected === true) {
  6422. const containerId = component.parentNode.id;
  6423. try {
  6424.  
  6425. if (component.nodeName === "RP") {
  6426. console.warn('deferRenderStamperBinding_ ERROR 001')
  6427. // debugger;
  6428.  
  6429. }
  6430.  
  6431. const componentFlushing = component.getAttribute('ytx-flushing');
  6432. if (componentFlushing) {
  6433. flushedObserver.observe(component, { subtree: true, childList: true });
  6434. component.appendChild(document.createComment('.')).remove();
  6435. if (componentFlushing === '2' || componentFlushing === '1') {
  6436. // use new data to render the last pending function
  6437.  
  6438. } else if (componentFlushing === '3' || componentFlushing === '2x') {
  6439. // will trigger forceCancel
  6440. } else {
  6441. console.warn('deferRenderStamperBinding_ ERROR 003')
  6442.  
  6443. // debugger;
  6444. }
  6445. }
  6446. } catch (e) {
  6447. console.warn(e);
  6448. }
  6449.  
  6450.  
  6451. const node = component;
  6452. forceCancel(node, true);
  6453.  
  6454. bdr.stampingContainerId = containerId;
  6455. component.setAttribute('ytx-flushing', '0');
  6456. component.setAttribute('ytx-flushing', '2');
  6457.  
  6458.  
  6459.  
  6460. // return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  6461. }
  6462. }
  6463.  
  6464.  
  6465. const flushRenderStamperComponentBindings_ = function() {
  6466.  
  6467. const byPass = checkByPass(this);
  6468. if (byPass) return this.flushRenderStamperComponentBindings7409_();
  6469.  
  6470. // if(!this.deferredBindingTasks7530_) this.deferredBindingTasks7530_ = [];
  6471. // const tasks = this.deferredBindingTasks7530_.slice();
  6472. // this.deferredBindingTasks7530_.length = 0;
  6473.  
  6474. // const producer = this;
  6475.  
  6476. // const stampTasks = this.__stampTasks993__ || (this.__stampTasks993__ = []);
  6477. // for(const task of tasks){
  6478. // if(!task.step){
  6479. // task.step = 1;
  6480. // stampTasks.push(task);
  6481. // }
  6482. // }
  6483.  
  6484. // let toFlush = false;
  6485. // for (const task of tasks) {
  6486. // const { component } = task;
  6487. // if(task.step !== 1) continue;
  6488. // if (component.nodeName === 'RP') continue;
  6489. // const parentNode = component.parentNode;
  6490. // const containerId = parentNode ? parentNode.id : null;
  6491. // if (!containerId) continue;
  6492. // const container = this.getStampContainer7409_(containerId);
  6493. // if (parentNode === container && container.nodeName) {
  6494. // task.stampable = containerId;
  6495. // task.step = 2;
  6496. // incAttr(container);
  6497. // toFlush = true;
  6498. // }
  6499. // }
  6500.  
  6501. }
  6502.  
  6503.  
  6504.  
  6505. return {createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, getStampContainer_}
  6506.  
  6507. }
  6508.  
  6509.  
  6510.  
  6511.  
  6512.  
  6513.  
  6514.  
  6515.  
  6516.  
  6517.  
  6518.  
  6519. const setupDiscreteTasks = (h, rb) => {
  6520.  
  6521.  
  6522.  
  6523. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  6524. const f = h.onYtRendererstamperFinished;
  6525. const g = ump3.get(f) || function () {
  6526. if (this.updateChildVisibilityProperties && !this.markDirty) {
  6527. return f.apply(this, arguments);
  6528. }
  6529. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6530. }
  6531. ump3.set(f, g);
  6532. g.km34 = 1;
  6533. h.onYtRendererstamperFinished = g;
  6534.  
  6535. }
  6536.  
  6537. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  6538. const f = h.onYtUpdateDescriptionAction;
  6539. const g = ump3.get(f) || function (a) {
  6540. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6541. }
  6542. ump3.set(f, g);
  6543. g.km34 = 1;
  6544. h.onYtUpdateDescriptionAction = g;
  6545.  
  6546. }
  6547.  
  6548. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  6549. const f = h.handleUpdateDescriptionAction;
  6550. const g = ump3.get(f) || function (a) {
  6551. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6552. }
  6553. ump3.set(f, g);
  6554. g.km34 = 1;
  6555. h.handleUpdateDescriptionAction = g;
  6556.  
  6557. }
  6558.  
  6559. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  6560. const f = h.handleUpdateLiveChatPollAction;
  6561. const g = ump3.get(f) || function (a) {
  6562. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6563. }
  6564. ump3.set(f, g);
  6565. g.km34 = 1;
  6566. h.handleUpdateLiveChatPollAction = g;
  6567.  
  6568. }
  6569.  
  6570. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  6571. const f = h.onTextChanged;
  6572. const g = ump3.get(f) || function () {
  6573. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6574. }
  6575. ump3.set(f, g);
  6576. g.km34 = 1;
  6577. h.onTextChanged = g;
  6578.  
  6579. }
  6580.  
  6581. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  6582. const f = h.onVideoDataChange;
  6583. const g = ump3.get(f) || function (a) {
  6584. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6585. }
  6586. ump3.set(f, g);
  6587. g.km34 = 1;
  6588. h.onVideoDataChange = g;
  6589.  
  6590. }
  6591.  
  6592. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  6593. const f = h.onVideoDataChange_;
  6594. const g = ump3.get(f) || function () {
  6595. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6596. }
  6597. ump3.set(f, g);
  6598. g.km34 = 1;
  6599. h.onVideoDataChange_ = g;
  6600.  
  6601. }
  6602.  
  6603. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  6604.  
  6605. const f = h.addTooltips_;
  6606. const g = ump3.get(f) || function () {
  6607. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6608. }
  6609. ump3.set(f, g);
  6610. g.km34 = 1;
  6611. h.addTooltips_ = g;
  6612.  
  6613. }
  6614.  
  6615. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  6616.  
  6617. const f = h.updateRenderedElements;
  6618. const g = ump3.get(f) || function () {
  6619. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6620. }
  6621. ump3.set(f, g);
  6622. g.km34 = 1;
  6623. h.updateRenderedElements = g;
  6624.  
  6625. }
  6626.  
  6627. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  6628. const f = h.loadPage_;
  6629. const g = ump3.get(f) || function (a) {
  6630. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6631. }
  6632. ump3.set(f, g);
  6633. g.km34 = 1;
  6634. h.loadPage_ = g;
  6635.  
  6636. }
  6637. // updatePageData_ : possible conflict with Omit ShadyDOM
  6638. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  6639. const f = h.updatePageData_;
  6640. const g = ump3.get(f) || function (a) {
  6641. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6642. }
  6643. ump3.set(f, g);
  6644. g.km34 = 1;
  6645. h.updatePageData_ = g;
  6646.  
  6647. }
  6648.  
  6649.  
  6650. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  6651.  
  6652. const f = h.onFocus_;
  6653. const g = ump3.get(f) || function () {
  6654. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6655. }
  6656. ump3.set(f, g);
  6657. g.km34 = 1;
  6658. h.onFocus_ = g;
  6659.  
  6660. }
  6661.  
  6662. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  6663.  
  6664. const f = h.onBlur_;
  6665. const g = ump3.get(f) || function () {
  6666. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6667. }
  6668. ump3.set(f, g);
  6669. g.km34 = 1;
  6670. h.onBlur_ = g;
  6671.  
  6672. }
  6673.  
  6674.  
  6675. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  6676.  
  6677. const f = h.buttonClassChanged_;
  6678. const g = ump3.get(f) || function (a, b) {
  6679. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6680. }
  6681. ump3.set(f, g);
  6682. g.km34 = 1;
  6683. h.buttonClassChanged_ = g;
  6684.  
  6685. }
  6686.  
  6687. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  6688.  
  6689. const f = h.buttonIconChanged_;
  6690. const g = ump3.get(f) || function (a) {
  6691. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6692. }
  6693. ump3.set(f, g);
  6694. g.km34 = 1;
  6695. h.buttonIconChanged_ = g;
  6696.  
  6697. }
  6698.  
  6699. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  6700.  
  6701. const f = h.dataChangedInBehavior_;
  6702. const g = ump3.get(f) || function () {
  6703. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6704. }
  6705. ump3.set(f, g);
  6706. g.km34 = 1;
  6707. h.dataChangedInBehavior_ = g;
  6708.  
  6709. }
  6710.  
  6711. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  6712.  
  6713. const f = h.continuationsChanged_;
  6714. const g = ump3.get(f) || function () {
  6715. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6716. }
  6717. ump3.set(f, g);
  6718. g.km34 = 1;
  6719. h.continuationsChanged_ = g;
  6720.  
  6721. }
  6722.  
  6723.  
  6724. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  6725.  
  6726. const f = h.forceChatPoll_;
  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.forceChatPoll_ = g;
  6733.  
  6734. }
  6735.  
  6736. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  6737.  
  6738. const f = h.onEndpointClick_;
  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.onEndpointClick_ = g;
  6745.  
  6746. }
  6747.  
  6748. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  6749.  
  6750. const f = h.onEndpointTap_;
  6751. const g = ump3.get(f) || function (a) {
  6752. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6753. }
  6754. ump3.set(f, g);
  6755. g.km34 = 1;
  6756. h.onEndpointTap_ = g;
  6757.  
  6758. }
  6759.  
  6760. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  6761.  
  6762. const f = h.handleClick_;
  6763. const g = ump3.get(f) || function (a, b) {
  6764. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6765. }
  6766. ump3.set(f, g);
  6767. g.km34 = 1;
  6768. h.handleClick_ = g;
  6769.  
  6770. }
  6771.  
  6772. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  6773.  
  6774. const f = h.onReadyStateChange_;
  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.onReadyStateChange_ = g;
  6781.  
  6782. }
  6783.  
  6784. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  6785.  
  6786. const f = h.onReadyStateChangeEntryPoint_;
  6787. const g = ump3.get(f) || function () {
  6788. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6789. }
  6790. ump3.set(f, g);
  6791. g.km34 = 1;
  6792. h.onReadyStateChangeEntryPoint_ = g;
  6793.  
  6794. }
  6795.  
  6796. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  6797.  
  6798. const f = h.readyStateChangeHandler_;
  6799. const g = ump3.get(f) || function (a) {
  6800. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6801. }
  6802. ump3.set(f, g);
  6803. g.km34 = 1;
  6804. h.readyStateChangeHandler_ = g;
  6805.  
  6806. }
  6807.  
  6808. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  6809.  
  6810. const f = h.xmlHttpHandler_;
  6811. const g = ump3.get(f) || function (a) {
  6812. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6813. }
  6814. ump3.set(f, g);
  6815. g.km34 = 1;
  6816. h.xmlHttpHandler_ = g;
  6817.  
  6818. }
  6819.  
  6820. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  6821.  
  6822. const f = h.executeCallbacks_; // overloaded
  6823. const g = ump3.get(f) || function (a) {
  6824. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6825. }
  6826. ump3.set(f, g);
  6827. g.km34 = 1;
  6828. h.executeCallbacks_ = g;
  6829.  
  6830. }
  6831.  
  6832. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  6833.  
  6834. const f = h.handleInvalidationData_;
  6835. const g = ump3.get(f) || function (a, b) {
  6836. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6837. }
  6838. ump3.set(f, g);
  6839. g.km34 = 1;
  6840. h.handleInvalidationData_ = g;
  6841.  
  6842. }
  6843.  
  6844. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  6845.  
  6846. const f = h.onInput_;
  6847. const g = ump3.get(f) || function () {
  6848. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6849. }
  6850. ump3.set(f, g);
  6851. g.km34 = 1;
  6852. h.onInput_ = g;
  6853.  
  6854. }
  6855. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  6856.  
  6857. const f = h.trigger_;
  6858. const g = ump3.get(f) || function (a) {
  6859. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6860. }
  6861. ump3.set(f, g);
  6862. g.km34 = 1;
  6863. h.trigger_ = g;
  6864.  
  6865. }
  6866.  
  6867. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  6868.  
  6869. const f = h.requestData_;
  6870. const g = ump3.get(f) || function (a) {
  6871. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6872. }
  6873. ump3.set(f, g);
  6874. g.km34 = 1;
  6875. h.requestData_ = g;
  6876.  
  6877. }
  6878.  
  6879. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  6880.  
  6881. const f = h.onLoadReloadContinuation_;
  6882. const g = ump3.get(f) || function (a, b) {
  6883. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6884. }
  6885. ump3.set(f, g);
  6886. g.km34 = 1;
  6887. h.onLoadReloadContinuation_ = g;
  6888.  
  6889. }
  6890.  
  6891. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  6892.  
  6893. const f = h.onLoadIncrementalContinuation_;
  6894. const g = ump3.get(f) || function (a, b) {
  6895. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6896. }
  6897. ump3.set(f, g);
  6898. g.km34 = 1;
  6899. h.onLoadIncrementalContinuation_ = g;
  6900.  
  6901. }
  6902.  
  6903. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  6904.  
  6905. const f = h.onLoadSeekContinuation_;
  6906. const g = ump3.get(f) || function (a, b) {
  6907. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6908. }
  6909. ump3.set(f, g);
  6910. g.km34 = 1;
  6911. h.onLoadSeekContinuation_ = g;
  6912.  
  6913. }
  6914. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  6915.  
  6916. const f = h.onLoadReplayContinuation_;
  6917. const g = ump3.get(f) || function (a, b) {
  6918. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6919. }
  6920. ump3.set(f, g);
  6921. g.km34 = 1;
  6922. h.onLoadReplayContinuation_ = g;
  6923.  
  6924. }
  6925. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  6926.  
  6927. const f = h.onNavigate_;
  6928. const g = ump3.get(f) || function (a) {
  6929. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6930. }
  6931. ump3.set(f, g);
  6932. g.km34 = 1;
  6933. h.onNavigate_ = g;
  6934.  
  6935. }
  6936.  
  6937. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  6938.  
  6939. const f = h.ytRendererBehaviorDataObserver_;
  6940. const g = ump3.get(f) || function () {
  6941. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6942. }
  6943. ump3.set(f, g);
  6944. g.km34 = 1;
  6945. h.ytRendererBehaviorDataObserver_ = g;
  6946.  
  6947. }
  6948.  
  6949. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  6950.  
  6951. const f = h.ytRendererBehaviorTargetIdObserver_;
  6952. const g = ump3.get(f) || function () {
  6953. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6954. }
  6955. ump3.set(f, g);
  6956. g.km34 = 1;
  6957. h.ytRendererBehaviorTargetIdObserver_ = g;
  6958.  
  6959. }
  6960.  
  6961. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  6962.  
  6963. const f = h.unregisterRenderer_;
  6964. const g = ump3.get(f) || function (a) {
  6965. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6966. }
  6967. ump3.set(f, g);
  6968. g.km34 = 1;
  6969. h.unregisterRenderer_ = g;
  6970.  
  6971. }
  6972.  
  6973. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  6974.  
  6975. const f = h.textChanged_;
  6976. const g = ump3.get(f) || function (a) {
  6977. if (void 0 !== this.isAttached) {
  6978. const hostElement = this.hostElement;
  6979. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  6980. return;
  6981. }
  6982. }
  6983. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6984. }
  6985. ump3.set(f, g);
  6986. g.km34 = 1;
  6987. h.textChanged_ = g;
  6988.  
  6989. }
  6990.  
  6991.  
  6992.  
  6993. /**
  6994. *
  6995. * Neglect following
  6996. *
  6997. * h.onYtAction_
  6998. * h.startLoadingWatch [ buggy for yt-player-updated ]
  6999. * h.deferRenderStamperBinding_
  7000. *
  7001. * h.stampDomArray_
  7002. * h.stampDomArraySplices_
  7003. *
  7004. */
  7005.  
  7006.  
  7007. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  7008. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  7009. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  7010. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  7011. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  7012. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  7013.  
  7014. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  7015.  
  7016. const f = h.searchChanged_;
  7017. const g = ump3.get(f) || function () {
  7018. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7019. }
  7020. ump3.set(f, g);
  7021. g.km34 = 1;
  7022. h.searchChanged_ = g;
  7023.  
  7024. }
  7025.  
  7026. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  7027.  
  7028. const f = h.skinToneChanged_;
  7029. const g = ump3.get(f) || function (a) {
  7030. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7031. }
  7032. ump3.set(f, g);
  7033. g.km34 = 1;
  7034. h.skinToneChanged_ = g;
  7035.  
  7036. }
  7037.  
  7038. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  7039.  
  7040. const f = h.onEmojiHover_;
  7041. const g = ump3.get(f) || function (a) {
  7042. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7043. }
  7044. ump3.set(f, g);
  7045. g.km34 = 1;
  7046. h.onEmojiHover_ = g;
  7047.  
  7048. }
  7049.  
  7050. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  7051.  
  7052. const f = h.onSelectCategory_;
  7053. const g = ump3.get(f) || function (a) {
  7054. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7055. }
  7056. ump3.set(f, g);
  7057. g.km34 = 1;
  7058. h.onSelectCategory_ = g;
  7059.  
  7060. }
  7061.  
  7062. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  7063.  
  7064. const f = h.onShowEmojiVariantSelector;
  7065. const g = ump3.get(f) || function (a) {
  7066. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7067. }
  7068. ump3.set(f, g);
  7069. g.km34 = 1;
  7070. h.onShowEmojiVariantSelector = g;
  7071.  
  7072. }
  7073.  
  7074. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  7075.  
  7076. const f = h.updateCategoriesAndPlaceholder_;
  7077. const g = ump3.get(f) || function () {
  7078. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7079. }
  7080. ump3.set(f, g);
  7081. g.km34 = 1;
  7082. h.updateCategoriesAndPlaceholder_ = g;
  7083.  
  7084. }
  7085.  
  7086. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  7087.  
  7088. const f = h.watchPageActiveChanged_;
  7089. const g = ump3.get(f) || function () {
  7090. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7091. }
  7092. ump3.set(f, g);
  7093. g.km34 = 1;
  7094. h.watchPageActiveChanged_ = g;
  7095.  
  7096. }
  7097.  
  7098. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  7099.  
  7100. const f = h.activate_;
  7101. const g = ump3.get(f) || function () {
  7102. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7103. }
  7104. ump3.set(f, g);
  7105. g.km34 = 1;
  7106. h.activate_ = g;
  7107.  
  7108. }
  7109. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  7110.  
  7111. const f = h.onYtPlaylistDataUpdated_;
  7112. const g = ump3.get(f) || function () {
  7113. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7114. }
  7115. ump3.set(f, g);
  7116. g.km34 = 1;
  7117. h.onYtPlaylistDataUpdated_ = g;
  7118.  
  7119. }
  7120.  
  7121.  
  7122.  
  7123. /**
  7124. *
  7125. * Neglect following
  7126. *
  7127. * h.rendererStamperObserver_
  7128. * h.rendererStamperApplyChangeRecord_
  7129. * h.flushRenderStamperComponentBindings_
  7130. * h.forwardRendererStamperChanges_
  7131. *
  7132. */
  7133.  
  7134. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  7135.  
  7136. const f = h.tryRenderChunk_;
  7137. const g = ump3.get(f) || function () {
  7138. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7139. }
  7140. ump3.set(f, g);
  7141. g.km34 = 1;
  7142. h.tryRenderChunk_ = g;
  7143.  
  7144. }
  7145.  
  7146.  
  7147. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  7148.  
  7149. const f = h.renderChunk_;
  7150. const g = ump3.get(f) || function () {
  7151. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7152. }
  7153. ump3.set(f, g);
  7154. g.km34 = 1;
  7155. h.renderChunk_ = g;
  7156.  
  7157. }
  7158.  
  7159. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  7160.  
  7161. const f = h.deepLazyListObserver_;
  7162. const g = ump3.get(f) || function () {
  7163. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7164. }
  7165. ump3.set(f, g);
  7166. g.km34 = 1;
  7167. h.deepLazyListObserver_ = g;
  7168.  
  7169. }
  7170.  
  7171. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  7172.  
  7173. const f = h.onItemsUpdated_;
  7174. const g = ump3.get(f) || function () {
  7175. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7176. }
  7177. ump3.set(f, g);
  7178. g.km34 = 1;
  7179. h.onItemsUpdated_ = g;
  7180.  
  7181. }
  7182.  
  7183. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  7184.  
  7185. const f = h.requestRenderChunk_;
  7186. const g = ump3.get(f) || function () {
  7187. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7188. }
  7189. ump3.set(f, g);
  7190. g.km34 = 1;
  7191. h.requestRenderChunk_ = g;
  7192.  
  7193. }
  7194.  
  7195. /**
  7196. *
  7197. * Neglect following
  7198. *
  7199. * h.dataChanged_ [ buggy for page swtiching ]
  7200. *
  7201. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  7202. *
  7203. * h.cancelPendingTasks_
  7204. * h.fillRange_
  7205. * h.addTextNodes_
  7206. * h.updateText_
  7207. * h.stampTypeChanged_
  7208. *
  7209. */
  7210.  
  7211.  
  7212. }
  7213.  
  7214. const keyStConnectedCallback = Symbol(); // avoid copying the value
  7215.  
  7216. const dmf = new WeakMap();
  7217.  
  7218.  
  7219. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  7220.  
  7221. try {
  7222.  
  7223. const q = document.createElement('template');
  7224. q.innerHTML = '<ytz-null361></ytz-null361>';
  7225. nativeHTMLElement = q.content.firstChild.constructor
  7226.  
  7227. } catch (e) { }
  7228.  
  7229. if (!nativeHTMLElement.prototype.connectedCallback) {
  7230. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  7231. nativeHTMLElement.prototype.connectedCallback = function () {
  7232. let r;
  7233. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  7234. return r;
  7235. }
  7236. }
  7237. const pvr = Symbol()
  7238.  
  7239. let stampDomArrayFnStore = null;
  7240. const setupMap = new WeakSet();
  7241. const setupYtComponent = (cnt) => {
  7242. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  7243. if (!cProto || setupMap.has(cProto)) return;
  7244. setupMap.add(cProto);
  7245. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  7246. cProto[pvr] |= 1;
  7247.  
  7248.  
  7249. if (0 && FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  7250. const b = cProto.stampDomArray_.length === 6
  7251. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  7252. && cProto.createComponent_ && cProto.createComponent_.length === 3
  7253. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  7254. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  7255. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  7256. if (!b) {
  7257. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  7258. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  7259. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFns_();
  7260. const {createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, getStampContainer_} = stampDomArrayFnStore;
  7261. cProto.createComponent7409_ = cProto.createComponent_;
  7262. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  7263. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  7264. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  7265.  
  7266. cProto.createComponent_ = createComponent_;
  7267. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  7268. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  7269. cProto.getStampContainer_ = getStampContainer_;
  7270. }
  7271. }
  7272.  
  7273. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  7274. const b = cProto.stampDomArray_.length === 6
  7275. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  7276. && cProto.createComponent_ && cProto.createComponent_.length === 3
  7277. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  7278. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  7279. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  7280. if (!b) {
  7281. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  7282. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  7283. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsB_();
  7284. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_} = stampDomArrayFnStore;
  7285.  
  7286. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  7287. cProto.createComponent7409_ = cProto.createComponent_;
  7288. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  7289. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  7290. cProto.stampDomArray7409_ = cProto.stampDomArray8581_ = cProto.stampDomArray_;
  7291.  
  7292. cProto.getStampContainer_ = getStampContainer_;
  7293. cProto.createComponent_ = createComponent_;
  7294. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  7295. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  7296. cProto.stampDomArray_ = stampDomArray_;
  7297.  
  7298. }
  7299. }
  7300.  
  7301.  
  7302.  
  7303.  
  7304. if(cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  7305. cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  7306.  
  7307. if(cProto._runEffectsForTemplate6344.length === 4){
  7308.  
  7309. cProto._runEffectsForTemplate = function (c, d, e, g) {
  7310. const cnt = this;
  7311. const { propertyEffects, nodeList, firstChild } = c;
  7312. cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  7313.  
  7314. }
  7315.  
  7316. }
  7317.  
  7318. }
  7319.  
  7320. }
  7321. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  7322. cProto[pvr] |= 2;
  7323. setupDiscreteTasks(cProto);
  7324. }
  7325. };
  7326.  
  7327. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  7328. get() {
  7329. const f = this[keyStConnectedCallback];
  7330. if (this.is) {
  7331. setupYtComponent(this);
  7332. }
  7333. return f;
  7334. },
  7335. set(nv) {
  7336. let gv = nv;
  7337. this[keyStConnectedCallback] = gv; // proto or object
  7338. return true;
  7339. },
  7340. enumerable: false,
  7341. configurable: true
  7342.  
  7343. });
  7344.  
  7345. const pLoad = new Promise(resolve => {
  7346. if (document.readyState !== 'loading') {
  7347. resolve();
  7348. } else {
  7349. window.addEventListener("DOMContentLoaded", resolve, false);
  7350. }
  7351. });
  7352.  
  7353. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  7354. window.requestIdleCallback471 = window.requestIdleCallback;
  7355. window.requestIdleCallback = function (f, ...args) {
  7356. return (this || window).requestIdleCallback471(async function () {
  7357. await pLoad.then();
  7358. // await new Promise(nextBrowserTick_);
  7359. f.call(this, ...arguments)
  7360. }, ...args);
  7361. }
  7362. }
  7363.  
  7364. pLoad.then(() => {
  7365.  
  7366. let nonce = document.querySelector('style[nonce]');
  7367. nonce = nonce ? nonce.getAttribute('nonce') : null;
  7368. const st = document.createElement('style');
  7369. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  7370. st.textContent = "none-element-k47{order:0}";
  7371. st.addEventListener('load', () => {
  7372. pf31.resolve();
  7373. p59 = 1;
  7374. }, false);
  7375. (document.body || document.head || document.documentElement).appendChild(st);
  7376.  
  7377. });
  7378.  
  7379. const prepareLogs = [];
  7380.  
  7381. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  7382.  
  7383. let winError00 = window.onerror;
  7384.  
  7385. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  7386.  
  7387. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  7388.  
  7389. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  7390.  
  7391. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  7392. const lcOpt = { sensitivity: 'base' };
  7393. document.createElement24 = document.createElement;
  7394. document.createElement = function (t) {
  7395. if (typeof t === 'string' && t.length === 6) {
  7396. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  7397. const p = this.createElement24(t);
  7398. try {
  7399. const stack = new Error().stack;
  7400. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greatest.deepsurf.us/scripts/473972-youtube-js-engine-tamer/discussions/217084
  7401. if (!isSearchbox) {
  7402. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  7403. }
  7404. } catch (e) { }
  7405. return p;
  7406. }
  7407. }
  7408. return this.createElement24.apply(this, arguments);
  7409. };
  7410.  
  7411. })();
  7412.  
  7413. ; fix_error_many_stack_state === 1 && (() => {
  7414.  
  7415.  
  7416. let p1 = winError00;
  7417.  
  7418. let stackNeedleDetails = null;
  7419.  
  7420. Object.defineProperty(Object.prototype, 'matchAll', {
  7421. get() {
  7422. stackNeedleDetails = this;
  7423. return true;
  7424. },
  7425. enumerable: true,
  7426. configurable: true
  7427. });
  7428.  
  7429. try {
  7430. JSON.parse("{}");
  7431. } catch (e) {
  7432. console.warn(e)
  7433. fix_error_many_stack_state = 0;
  7434. }
  7435.  
  7436. delete Object.prototype['matchAll'];
  7437.  
  7438. let p2 = window.onerror;
  7439.  
  7440. window.onerror = p1;
  7441.  
  7442. if (fix_error_many_stack_state === 0) return;
  7443.  
  7444. if (stackNeedleDetails) {
  7445. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7446. stackNeedleDetails.matchAll = true;
  7447. }
  7448.  
  7449. if (p1 === p2) return (fix_error_many_stack_state = 0);
  7450.  
  7451. // p1!==p2
  7452. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  7453.  
  7454. })();
  7455.  
  7456. ; fix_error_many_stack_state === 2 && (() => {
  7457.  
  7458.  
  7459. let p1 = winError00;
  7460.  
  7461. let objectPrune = null;
  7462. let stackNeedleDetails = null;
  7463.  
  7464. Object.defineProperty(Function.prototype, 'findOwner', {
  7465. get() {
  7466. objectPrune = this;
  7467. return this._findOwner;
  7468. },
  7469. set(nv) {
  7470. this._findOwner = nv;
  7471. return true;
  7472. },
  7473. enumerable: true,
  7474. configurable: true
  7475. });
  7476.  
  7477. Object.defineProperty(Object.prototype, 'matchAll', {
  7478. get() {
  7479. stackNeedleDetails = this;
  7480. return true;
  7481. },
  7482. enumerable: true,
  7483. configurable: true
  7484. });
  7485.  
  7486. try {
  7487. JSON.parse("{}");
  7488. } catch (e) {
  7489. console.warn(e)
  7490. fix_error_many_stack_state = 0;
  7491. }
  7492.  
  7493. delete Function.prototype['findOwner'];
  7494. delete Object.prototype['matchAll'];
  7495.  
  7496. let p2 = window.onerror;
  7497.  
  7498. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  7499.  
  7500. if (fix_error_many_stack_state == 0) return;
  7501.  
  7502. // the following will only execute when Brave's scriptlets.js is executed.
  7503.  
  7504. prepareLogs.push("fix_error_many_stack_state NB")
  7505.  
  7506. if (stackNeedleDetails) {
  7507. stackNeedleDetails.pattern = null;
  7508. stackNeedleDetails.re = null;
  7509. stackNeedleDetails.expect = null;
  7510. stackNeedleDetails.matchAll = true;
  7511. }
  7512.  
  7513. if (objectPrune) {
  7514. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  7515. delete objectPrune._findOwner;
  7516. }
  7517.  
  7518. fix_error_many_stack_state = 3;
  7519. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7520. JSON.parse.objectPrune = objectPrune;
  7521.  
  7522. })();
  7523.  
  7524. ; fix_error_many_stack_state === 3 && (() => {
  7525.  
  7526.  
  7527. let p1 = winError00;
  7528.  
  7529. try {
  7530. JSON.parse("{}");
  7531. } catch (e) {
  7532. console.warn(e)
  7533. fix_error_many_stack_state = 0;
  7534. }
  7535.  
  7536. let p2 = window.onerror;
  7537.  
  7538. if (p1 === p2) return;
  7539.  
  7540. window.onerror = p1;
  7541.  
  7542. if (fix_error_many_stack_state === 0) return;
  7543.  
  7544. fix_error_many_stack_state = 4; // p1 != p2
  7545.  
  7546.  
  7547. })();
  7548.  
  7549. fix_error_many_stack_state === 4 && (() => {
  7550.  
  7551. // the following will only execute when Brave's scriptlets.js is executed.
  7552.  
  7553. prepareLogs.push("fix_error_many_stack_state AB")
  7554.  
  7555. JSON.parseProxy = JSON.parse;
  7556.  
  7557. JSON.parse = ((parse) => {
  7558.  
  7559. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  7560. return function (text, reviver) {
  7561. const onerror = window.onerror;
  7562. window.onerror = null;
  7563. let r;
  7564. try {
  7565. r = parse(...arguments);
  7566. } catch (e) {
  7567. r = e;
  7568. }
  7569. window.onerror = onerror;
  7570. if (r instanceof Error) {
  7571. throw r;
  7572. }
  7573. return r;
  7574. }
  7575.  
  7576. })(JSON.parse);
  7577.  
  7578.  
  7579. })();
  7580.  
  7581.  
  7582. // << if FIX_yt_player >>
  7583.  
  7584. // credit to @nopeless (https://greatest.deepsurf.us/scripts/471489-youtube-player-perf/)
  7585. const PERF_471489_ = true;
  7586. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  7587. // This script uses a much gentle way to tamer the JS engine instead.
  7588.  
  7589. // << end >>
  7590.  
  7591. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  7592.  
  7593.  
  7594.  
  7595. const nilFn = () => { };
  7596.  
  7597. let isMainWindow = false;
  7598. try {
  7599. isMainWindow = window.document === window.top.document
  7600. } catch (e) { }
  7601.  
  7602. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  7603. let headLinkCollection = null;
  7604.  
  7605.  
  7606. // const assertor = (f) => f() || console.assert(false, `${f}`);
  7607.  
  7608. const fnIntegrity = (f, d) => {
  7609. if (!f || typeof f !== 'function') {
  7610. console.warn('f is not a function', f);
  7611. return;
  7612. }
  7613. let p = `${f}`, s = 0, j = -1, w = 0;
  7614. for (let i = 0, l = p.length; i < l; i++) {
  7615. const t = p[i];
  7616. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  7617. if (j < i - 1) w++;
  7618. j = i;
  7619. } else {
  7620. s++;
  7621. }
  7622. }
  7623. let itz = `${f.length}.${s}.${w}`;
  7624. if (!d) {
  7625. return itz;
  7626. } else {
  7627. return itz === d;
  7628. }
  7629. };
  7630.  
  7631. const getZqOu = (_yt_player) => {
  7632.  
  7633. const w = 'ZqOu';
  7634.  
  7635. let arr = [];
  7636.  
  7637. for (const [k, v] of Object.entries(_yt_player)) {
  7638.  
  7639. const p = typeof v === 'function' ? v.prototype : 0;
  7640. if (p
  7641. && typeof p.start === 'function' && p.start.length === 0 // Ou
  7642. && typeof p.isActive === 'function' && p.isActive.length === 0
  7643. && typeof p.stop === 'function' && p.stop.length === 0
  7644. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7645. && !p.send && !p.abort
  7646. && !p.sample && !p.initialize && !p.fail && !p.getName
  7647. // && !p.dispose && !p.isDisposed
  7648.  
  7649. ) {
  7650. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7651.  
  7652.  
  7653. }
  7654.  
  7655. }
  7656.  
  7657. if (arr.length === 0) {
  7658.  
  7659. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7660. } else {
  7661.  
  7662. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7663. return arr[0];
  7664. }
  7665.  
  7666. }
  7667.  
  7668. const getZqQu = (_yt_player) => {
  7669.  
  7670. const w = 'ZqQu';
  7671.  
  7672. let arr = [];
  7673.  
  7674.  
  7675. for (const [k, v] of Object.entries(_yt_player)) {
  7676.  
  7677. const p = typeof v === 'function' ? v.prototype : 0;
  7678. if (p
  7679. && typeof p.start === 'function' && p.start.length === 1 // Qu
  7680. && typeof p.isActive === 'function' && p.isActive.length === 0
  7681. && typeof p.stop === 'function' && p.stop.length === 0
  7682. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7683. && !p.send && !p.abort
  7684. && !p.sample && !p.initialize && !p.fail && !p.getName
  7685. // && !p.dispose && !p.isDisposed
  7686.  
  7687. ) {
  7688. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7689.  
  7690.  
  7691. }
  7692.  
  7693. }
  7694.  
  7695. if (arr.length === 0) {
  7696.  
  7697. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7698. } else {
  7699.  
  7700. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7701. return arr[0];
  7702. }
  7703.  
  7704. }
  7705.  
  7706.  
  7707. const getVG = (_yt_player) => {
  7708. const w = 'VG';
  7709.  
  7710. let arr = [];
  7711.  
  7712. for (const [k, v] of Object.entries(_yt_player)) {
  7713.  
  7714. const p = typeof v === 'function' ? v.prototype : 0;
  7715. if (p
  7716. && typeof p.show === 'function' && p.show.length === 1
  7717. && typeof p.hide === 'function' && p.hide.length === 0
  7718. && typeof p.stop === 'function' && p.stop.length === 0) {
  7719.  
  7720. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7721.  
  7722. }
  7723.  
  7724. }
  7725.  
  7726.  
  7727. if (arr.length === 0) {
  7728.  
  7729. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7730. } else {
  7731.  
  7732. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7733. return arr[0];
  7734. }
  7735.  
  7736.  
  7737.  
  7738. }
  7739.  
  7740.  
  7741. const getzo = (_yt_player) => {
  7742. const w = 'zo';
  7743.  
  7744. let arr = [];
  7745.  
  7746. for (const [k, v] of Object.entries(_yt_player)) {
  7747.  
  7748. if (
  7749. typeof v === 'function' && v.length === 3 && k.length < 3
  7750. ) {
  7751. const vt = `${v}`;
  7752. if (vt.length >= 21 && vt.includes(".style[")) {
  7753. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  7754. arr.push(k);
  7755. } else {
  7756. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  7757. }
  7758. }
  7759. }
  7760.  
  7761. }
  7762.  
  7763. if (arr.length === 0) {
  7764.  
  7765. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7766. } else {
  7767.  
  7768. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7769. return arr[0];
  7770. }
  7771.  
  7772. }
  7773.  
  7774. const addProtoToArr = (parent, key, arr) => {
  7775.  
  7776.  
  7777. let isChildProto = false;
  7778. for (const sr of arr) {
  7779. if (parent[key].prototype instanceof parent[sr]) {
  7780. isChildProto = true;
  7781. break;
  7782. }
  7783. }
  7784.  
  7785. if (isChildProto) return;
  7786.  
  7787. arr = arr.filter(sr => {
  7788. if (parent[sr].prototype instanceof parent[key]) {
  7789. return false;
  7790. }
  7791. return true;
  7792. });
  7793.  
  7794. arr.push(key);
  7795.  
  7796. return arr;
  7797.  
  7798.  
  7799. }
  7800.  
  7801. const getuG = (_yt_player) => {
  7802.  
  7803. const w = 'uG';
  7804.  
  7805. let arr = [];
  7806.  
  7807. for (const [k, v] of Object.entries(_yt_player)) {
  7808.  
  7809.  
  7810. const p = typeof v === 'function' ? v.prototype : 0;
  7811.  
  7812. if (p
  7813. && typeof p.createElement === 'function' && p.createElement.length === 2
  7814. && typeof p.detach === 'function' && p.detach.length === 0
  7815. && typeof p.update === 'function' && p.update.length === 1
  7816. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  7817. ) {
  7818.  
  7819. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7820.  
  7821. }
  7822.  
  7823. }
  7824.  
  7825.  
  7826.  
  7827.  
  7828.  
  7829. if (arr.length === 0) {
  7830.  
  7831. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7832. } else {
  7833.  
  7834. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7835. return arr[0];
  7836. }
  7837.  
  7838. }
  7839.  
  7840.  
  7841. const getQT = (_yt_player) => {
  7842. const w = 'QT';
  7843.  
  7844. let arr = [];
  7845. let brr = new Map();
  7846.  
  7847. for (const [k, v] of Object.entries(_yt_player)) {
  7848.  
  7849. const p = typeof v === 'function' ? v.prototype : 0;
  7850. if (p) {
  7851. let q = 0;
  7852. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7853. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7854. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7855.  
  7856. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7857.  
  7858. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7859.  
  7860. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7861. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7862. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7863. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7864.  
  7865.  
  7866. // differentiate QT and DX
  7867.  
  7868. q += 280;
  7869. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  7870. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  7871. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  7872. if (typeof p.seekBy === 'function') q += 4;
  7873. if (typeof p.seekTo === 'function') q += 4;
  7874. if (typeof p.getStoryboardFormat === 'function') q += 4;
  7875. if (typeof p.getDuration === 'function') q += 4;
  7876. if (typeof p.loadModule === 'function') q += 4;
  7877. if (typeof p.unloadModule === 'function') q += 4;
  7878. if (typeof p.getOption === 'function') q += 4;
  7879. if (typeof p.getOptions === 'function') q += 4;
  7880. if (typeof p.setOption === 'function') q += 4;
  7881. if (typeof p.addCueRange === 'function') q += 4;
  7882. if (typeof p.getDebugText === 'function') q += 4;
  7883. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  7884. if (typeof p.setSizeStyle === 'function') q += 4;
  7885. if (typeof p.showControls === 'function') q += 4;
  7886. if (typeof p.hideControls === 'function') q += 4;
  7887. if (typeof p.getVideoContentRect === 'function') q += 4;
  7888. if (typeof p.toggleFullscreen === 'function') q += 4;
  7889. if (typeof p.isFullscreen === 'function') q += 4;
  7890. if (typeof p.cancelPlayback === 'function') q += 4;
  7891. if (typeof p.getProgressState === 'function') q += 4;
  7892. if (typeof p.isInline === 'function') q += 4;
  7893. if (typeof p.setInline === 'function') q += 4;
  7894. if (typeof p.toggleSubtitles === 'function') q += 4;
  7895. if (typeof p.getPlayerSize === 'function') q += 4;
  7896. if (typeof p.wakeUpControls === 'function') q += 4;
  7897. if (typeof p.setCenterCrop === 'function') q += 4;
  7898. if (typeof p.getLoopVideo === 'function') q += 4;
  7899. if (typeof p.setLoopVideo === 'function') q += 4;
  7900.  
  7901.  
  7902. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7903.  
  7904. if (q > 0) brr.set(k, q);
  7905.  
  7906. }
  7907.  
  7908. }
  7909.  
  7910. if (arr.length === 0) {
  7911.  
  7912. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7913. } else {
  7914.  
  7915. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7916.  
  7917. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7918.  
  7919. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7920. return arr[0][0];
  7921. }
  7922.  
  7923.  
  7924.  
  7925. }
  7926.  
  7927.  
  7928.  
  7929. const getSV = (_yt_player) => {
  7930. const w = 'SV';
  7931.  
  7932. let arr = [];
  7933. let brr = new Map();
  7934.  
  7935. for (const [k, v] of Object.entries(_yt_player)) {
  7936.  
  7937. const p = typeof v === 'function' ? v.prototype : 0;
  7938. if (p) {
  7939. let q = 0;
  7940. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7941. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7942. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7943.  
  7944. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  7945.  
  7946. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7947.  
  7948. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7949. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7950. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7951. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7952.  
  7953.  
  7954. // differentiate QT and DX
  7955.  
  7956.  
  7957. q += 280;
  7958.  
  7959. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7960. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7961. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7962. if (typeof p.seekBy === 'function') q -= 4;
  7963. if (typeof p.seekTo === 'function') q -= 4;
  7964. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7965. if (typeof p.getDuration === 'function') q -= 4;
  7966. if (typeof p.loadModule === 'function') q -= 4;
  7967. if (typeof p.unloadModule === 'function') q -= 4;
  7968. if (typeof p.getOption === 'function') q -= 4;
  7969. if (typeof p.getOptions === 'function') q -= 4;
  7970. if (typeof p.setOption === 'function') q -= 4;
  7971. if (typeof p.addCueRange === 'function') q -= 4;
  7972. if (typeof p.getDebugText === 'function') q -= 4;
  7973. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7974. if (typeof p.setSizeStyle === 'function') q -= 4;
  7975. if (typeof p.showControls === 'function') q -= 4;
  7976. if (typeof p.hideControls === 'function') q -= 4;
  7977. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7978. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7979. if (typeof p.isFullscreen === 'function') q -= 4;
  7980. if (typeof p.cancelPlayback === 'function') q -= 4;
  7981. if (typeof p.getProgressState === 'function') q -= 4;
  7982. if (typeof p.isInline === 'function') q -= 4;
  7983. if (typeof p.setInline === 'function') q -= 4;
  7984. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7985. if (typeof p.getPlayerSize === 'function') q -= 4;
  7986. if (typeof p.wakeUpControls === 'function') q -= 4;
  7987. if (typeof p.setCenterCrop === 'function') q -= 4;
  7988. if (typeof p.getLoopVideo === 'function') q -= 4;
  7989. if (typeof p.setLoopVideo === 'function') q -= 4;
  7990.  
  7991.  
  7992. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7993.  
  7994. if (q > 0) brr.set(k, q);
  7995.  
  7996. }
  7997.  
  7998. }
  7999.  
  8000. if (arr.length === 0) {
  8001.  
  8002. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8003. } else {
  8004.  
  8005. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8006.  
  8007. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8008.  
  8009. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8010. return arr[0][0];
  8011. }
  8012.  
  8013.  
  8014.  
  8015. }
  8016.  
  8017.  
  8018.  
  8019.  
  8020. const getDX = (_yt_player) => {
  8021. const w = 'DX';
  8022.  
  8023. let arr = [];
  8024. let brr = new Map();
  8025.  
  8026. for (const [k, v] of Object.entries(_yt_player)) {
  8027.  
  8028. const p = typeof v === 'function' ? v.prototype : 0;
  8029. if (p) {
  8030. let q = 0;
  8031. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8032. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8033. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8034.  
  8035. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8036.  
  8037.  
  8038. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  8039.  
  8040. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8041.  
  8042. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8043. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8044. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8045. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8046.  
  8047.  
  8048. // differentiate QT and DX
  8049.  
  8050.  
  8051. q += 280;
  8052.  
  8053. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  8054. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  8055. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  8056. if (typeof p.seekBy === 'function') q -= 4;
  8057. if (typeof p.seekTo === 'function') q -= 4;
  8058. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  8059. if (typeof p.getDuration === 'function') q -= 4;
  8060. if (typeof p.loadModule === 'function') q -= 4;
  8061. if (typeof p.unloadModule === 'function') q -= 4;
  8062. if (typeof p.getOption === 'function') q -= 4;
  8063. if (typeof p.getOptions === 'function') q -= 4;
  8064. if (typeof p.setOption === 'function') q -= 4;
  8065. if (typeof p.addCueRange === 'function') q -= 4;
  8066. if (typeof p.getDebugText === 'function') q -= 4;
  8067. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  8068. if (typeof p.setSizeStyle === 'function') q -= 4;
  8069. if (typeof p.showControls === 'function') q -= 4;
  8070. if (typeof p.hideControls === 'function') q -= 4;
  8071. if (typeof p.getVideoContentRect === 'function') q -= 4;
  8072. if (typeof p.toggleFullscreen === 'function') q -= 4;
  8073. if (typeof p.isFullscreen === 'function') q -= 4;
  8074. if (typeof p.cancelPlayback === 'function') q -= 4;
  8075. if (typeof p.getProgressState === 'function') q -= 4;
  8076. if (typeof p.isInline === 'function') q -= 4;
  8077. if (typeof p.setInline === 'function') q -= 4;
  8078. if (typeof p.toggleSubtitles === 'function') q -= 4;
  8079. if (typeof p.getPlayerSize === 'function') q -= 4;
  8080. if (typeof p.wakeUpControls === 'function') q -= 4;
  8081. if (typeof p.setCenterCrop === 'function') q -= 4;
  8082. if (typeof p.getLoopVideo === 'function') q -= 4;
  8083. if (typeof p.setLoopVideo === 'function') q -= 4;
  8084.  
  8085.  
  8086. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8087.  
  8088. if (q > 0) brr.set(k, q);
  8089.  
  8090. }
  8091.  
  8092. }
  8093.  
  8094. if (arr.length === 0) {
  8095.  
  8096. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8097. } else {
  8098.  
  8099. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8100.  
  8101. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8102.  
  8103. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8104. return arr[0][0];
  8105. }
  8106.  
  8107.  
  8108.  
  8109. }
  8110.  
  8111.  
  8112.  
  8113. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  8114.  
  8115. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  8116. let pageSetupState = 0;
  8117.  
  8118. isPrepareCachedV && (() => {
  8119.  
  8120. pageSetupVideoId = '';
  8121. const clearCachedV = () => {
  8122. pageSetupVideoId = '';
  8123. pageSetupState = 0;
  8124. }
  8125. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  8126. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  8127. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  8128. document.addEventListener('yt-navigate-finish', () => {
  8129. pageSetupState = 1;
  8130. try {
  8131. const url = new URL(location.href);
  8132. if (!url || !isWatchPageURL(url)) {
  8133. pageSetupVideoId = '';
  8134. } else {
  8135. pageSetupVideoId = url.searchParams.get('v') || '';
  8136. }
  8137. } catch (e) {
  8138. pageSetupVideoId = '';
  8139. }
  8140. }, false);
  8141.  
  8142. })();
  8143.  
  8144. let videoPlayingY = null;
  8145.  
  8146. isPrepareCachedV && (() => {
  8147.  
  8148. let getNext = true;
  8149. let videoPlayingX = {
  8150. get videoId() {
  8151. if (getNext) {
  8152. getNext = false;
  8153.  
  8154. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  8155. const arr = [];
  8156. for (const element of elements) {
  8157. if (!element.closest('[hidden]')) arr.push(element);
  8158. }
  8159. if (arr.length !== 1) this.__videoId__ = '';
  8160. else {
  8161. this.__videoId__ = arr[0].getAttribute('video-id');
  8162. }
  8163.  
  8164. }
  8165. return this.__videoId__ || '';
  8166. }
  8167. }
  8168.  
  8169. videoPlayingY = videoPlayingX;
  8170. const handler = (evt) => {
  8171. const target = (evt || 0).target;
  8172. if (target instanceof HTMLVideoElement) {
  8173. getNext = true;
  8174. }
  8175. }
  8176. document.addEventListener('loadedmetadata', handler, true);
  8177. document.addEventListener('durationchange', handler, true);
  8178.  
  8179. })();
  8180.  
  8181.  
  8182.  
  8183. const cleanContext = async (win) => {
  8184. const waitFn = requestAnimationFrame; // shall have been binded to window
  8185. try {
  8186. let mx = 16; // MAX TRIAL
  8187. const frameId = 'vanillajs-iframe-v1';
  8188. /** @type {HTMLIFrameElement | null} */
  8189. let frame = document.getElementById(frameId);
  8190. let removeIframeFn = null;
  8191. if (!frame) {
  8192. frame = document.createElement('iframe');
  8193. frame.id = frameId;
  8194. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  8195. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  8196. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  8197. n.appendChild(frame);
  8198. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  8199. const root = document.documentElement;
  8200. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  8201. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  8202.  
  8203. removeIframeFn = (setTimeout) => {
  8204. const removeIframeOnDocumentReady = (e) => {
  8205. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  8206. e = n;
  8207. n = win = removeIframeFn = 0;
  8208. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  8209. }
  8210. if (!setTimeout || document.readyState !== 'loading') {
  8211. removeIframeOnDocumentReady();
  8212. } else {
  8213. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  8214. }
  8215. }
  8216. }
  8217. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  8218. const fc = frame.contentWindow;
  8219. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  8220. try {
  8221. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  8222. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  8223. for (let k in res) res[k] = res[k].bind(win); // necessary
  8224. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  8225. res.animate = fc.HTMLElement.prototype.animate;
  8226. res.perfNow = fc.performance.now;
  8227. return res;
  8228. } catch (e) {
  8229. if (removeIframeFn) removeIframeFn();
  8230. return null;
  8231. }
  8232. } catch (e) {
  8233. console.warn(e);
  8234. return null;
  8235. }
  8236. };
  8237.  
  8238. const promiseForYtActionCalled = new Promise(resolve => {
  8239.  
  8240. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8241. if (typeof AbortSignal !== 'undefined') {
  8242. let hn = () => {
  8243. if (!hn) return;
  8244. hn = null;
  8245. resolve(document.querySelector(appTag));
  8246. };
  8247. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  8248. } else {
  8249. let hn = () => {
  8250. if (!hn) return;
  8251. document.removeEventListener('yt-action', hn, true);
  8252. hn = null;
  8253. resolve(document.querySelector(appTag));
  8254. };
  8255. document.addEventListener('yt-action', hn, true);
  8256. }
  8257. });
  8258.  
  8259. cleanContext(window).then(__CONTEXT__ => {
  8260. if (!__CONTEXT__) return null;
  8261.  
  8262. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  8263.  
  8264.  
  8265. performance.now17 = perfNow.bind(performance);
  8266.  
  8267.  
  8268.  
  8269. __requestAnimationFrame__ = requestAnimationFrame;
  8270.  
  8271.  
  8272. const isGPUAccelerationAvailable = (() => {
  8273. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  8274. try {
  8275. const canvas = document.createElement('canvas');
  8276. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  8277. } catch (e) {
  8278. return false;
  8279. }
  8280. })();
  8281.  
  8282. const foregroundPromiseFn_noGPU = (() => {
  8283.  
  8284. if (isGPUAccelerationAvailable) return null;
  8285.  
  8286. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  8287. if (!pd || typeof pd.get !== 'function') return null;
  8288. const pdGet = pd.get;
  8289.  
  8290. let pr = null;
  8291.  
  8292. let hState = pdGet.call(document) === 'hidden';
  8293. // let cid = 0;
  8294. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  8295. const newHState = pdGet.call(document) === 'hidden';
  8296. if (hState !== newHState) {
  8297. // if (cid > 0) cid = clearInterval(cid);
  8298. hState = newHState;
  8299. if (!hState && pr) pr = pr.resolve();
  8300. }
  8301. });
  8302.  
  8303. // cid = setInterval(() => {
  8304. // const newHState = document.visibilityState === 'hidden';
  8305. // if (hState !== newHState) {
  8306. // hState = newHState;
  8307. // if (!hState && pr) pr = pr.resolve();
  8308. // }
  8309. // }, 100);
  8310.  
  8311.  
  8312. return (() => {
  8313. if (pr) return pr;
  8314. const w = ((!hState && setTimeout(() => {
  8315. if (!hState && pr === w) pr = pr.resolve();
  8316. })), (pr = new PromiseExternal()));
  8317. return w;
  8318. });
  8319.  
  8320. })();
  8321.  
  8322.  
  8323. let rafPromise = null;
  8324. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  8325. requestAnimationFrame(hRes => {
  8326. rafPromise = null;
  8327. resolve(hRes);
  8328. });
  8329. }));
  8330.  
  8331. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  8332.  
  8333.  
  8334. const wmComputedStyle = new WeakMap();
  8335.  
  8336. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  8337. window.__native__getComputedStyle__ = getComputedStyle;
  8338. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  8339. window.__original__getComputedStyle__ = window.getComputedStyle;
  8340. window.getComputedStyle = function (elem) {
  8341. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  8342. return window.__original__getComputedStyle__(...arguments);
  8343. }
  8344. let cs = wmComputedStyle.get(elem);
  8345. if (!cs) {
  8346. cs = window.__native__getComputedStyle__(elem);
  8347. wmComputedStyle.set(elem, cs);
  8348. }
  8349. return cs;
  8350. };
  8351. } else {
  8352. window.__original__getComputedStyle__ = null;
  8353. }
  8354. window.__jst__getComputedStyle__ = window.getComputedStyle;
  8355. }
  8356.  
  8357. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  8358. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  8359. window.getComputedStyle = window.__jst__getComputedStyle__;
  8360. }
  8361. });
  8362.  
  8363. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  8364. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  8365.  
  8366. const promiseForTamerTimeout = new Promise(resolve => {
  8367. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8368. setTimeout(resolve, 480);
  8369. }, { capture: true, passive: true, once: true });
  8370. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8371. setTimeout(resolve, 1200);
  8372. });
  8373. setTimeout(resolve, 3000);
  8374. });
  8375.  
  8376. const promiseForPageInitied = new Promise(resolve => {
  8377. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8378. setTimeout(resolve, 450);
  8379. }, { capture: true, passive: true, once: true });
  8380. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8381. setTimeout(resolve, 900);
  8382. });
  8383. setTimeout(resolve, 1800);
  8384. });
  8385.  
  8386. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  8387. NO_PRELOAD_GENERATE_204_BYPASS = true;
  8388. headLinkCollection = null;
  8389. });
  8390.  
  8391.  
  8392. NATIVE_CANVAS_ANIMATION && (() => {
  8393.  
  8394. observablePromise(() => {
  8395. HTMLCanvasElement.prototype.animate = animate;
  8396. }, promiseForTamerTimeout).obtain();
  8397.  
  8398. })();
  8399.  
  8400.  
  8401.  
  8402.  
  8403. FIX_ytAction_ && (async () => {
  8404.  
  8405. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8406.  
  8407. const ytdApp = await new Promise(resolve => {
  8408.  
  8409. whenCEDefined(appTag).then(() => {
  8410. const ytdApp = document.querySelector(appTag);
  8411. if (ytdApp) {
  8412. resolve(ytdApp);
  8413. return;
  8414. }
  8415. let mo = new MutationObserver(() => {
  8416. const ytdApp = document.querySelector(appTag);
  8417. if (!ytdApp) return;
  8418. if (mo) {
  8419. mo.disconnect();
  8420. mo.takeRecords();
  8421. mo = null;
  8422. }
  8423. resolve(ytdApp);
  8424. });
  8425. mo.observe(document, { subtree: true, childList: true });
  8426. });
  8427.  
  8428. });
  8429.  
  8430. if (!ytdApp) return;
  8431. const cProto = insp(ytdApp).constructor.prototype;
  8432.  
  8433. if (!cProto) return;
  8434. let mbd = 0;
  8435.  
  8436. const fixer = (_ytdApp) => {
  8437. const ytdApp = insp(_ytdApp);
  8438. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  8439. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  8440. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  8441. mbd++;
  8442. }
  8443. }
  8444.  
  8445. observablePromise(() => {
  8446.  
  8447. if (typeof cProto.created === 'function' && !cProto.created56) {
  8448. cProto.created56 = cProto.created;
  8449. cProto.created = function (...args) {
  8450. const r = this.created56(...args);
  8451. fixer(this);
  8452. return r;
  8453. };
  8454. mbd++;
  8455. }
  8456.  
  8457. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  8458. cProto.onYtAction57_ = cProto.onYtAction_;
  8459. cProto.onYtAction_ = function (...args) {
  8460. Promise.resolve().then(() => this.onYtAction57_(...args));
  8461. };
  8462. mbd++;
  8463. }
  8464.  
  8465. if (ytdApp) fixer(ytdApp);
  8466.  
  8467. /*
  8468. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  8469. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  8470. actionRouter_.handleAction57 = actionRouter_.handleAction;
  8471. actionRouter_.handleAction = function (...args) {
  8472. Promise.resolve().then(() => this.handleAction57(...args));
  8473. }
  8474. mbd++;
  8475. }
  8476. */
  8477.  
  8478. // if(mbd === 3) return 1;
  8479. if (mbd >= 3) return 1;
  8480.  
  8481. }, new Promise(r => setTimeout(r, 1000))).obtain();
  8482.  
  8483. })();
  8484.  
  8485.  
  8486. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  8487.  
  8488. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  8489.  
  8490. const app = await observablePromise(() => {
  8491.  
  8492. return document.querySelector(appTag);
  8493.  
  8494. }).obtain();
  8495.  
  8496. if (!app) return;
  8497.  
  8498. const appCnt = insp(app);
  8499. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  8500.  
  8501.  
  8502.  
  8503.  
  8504. });
  8505.  
  8506. const observablePromise = (proc, timeoutPromise) => {
  8507. let promise = null;
  8508. return {
  8509. obtain() {
  8510. if (!promise) {
  8511. promise = new Promise(resolve => {
  8512. let mo = null;
  8513. const f = () => {
  8514. let t = proc();
  8515. if (t) {
  8516. mo.disconnect();
  8517. mo.takeRecords();
  8518. mo = null;
  8519. resolve(t);
  8520. }
  8521. }
  8522. mo = new MutationObserver(f);
  8523. mo.observe(document, { subtree: true, childList: true })
  8524. f();
  8525. timeoutPromise && timeoutPromise.then(() => {
  8526. resolve(null)
  8527. });
  8528. });
  8529. }
  8530. return promise
  8531. }
  8532. }
  8533. }
  8534.  
  8535. // let _yt_player_promise = null;
  8536. /*
  8537. const getYtPlayerPromise = () => {
  8538. if (!_yt_player_promise) {
  8539. _yt_player_promise = new Promise(resolve => {
  8540. let cid = setInterval(() => {
  8541. let t = (((window || 0)._yt_player || 0) || 0);
  8542. if (t) {
  8543. clearInterval(cid);
  8544. resolve(t);
  8545. }
  8546. }, 1);
  8547. promiseForTamerTimeout.then(() => {
  8548. resolve(null)
  8549. });
  8550. });
  8551. }
  8552. return _yt_player_promise;
  8553. }
  8554. */
  8555. const _yt_player_observable = observablePromise(() => {
  8556. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  8557. if (_yt_player) {
  8558. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  8559. return _yt_player;
  8560. }
  8561. }, promiseForTamerTimeout);
  8562.  
  8563. const polymerObservable = observablePromise(() => {
  8564. const Polymer = window.Polymer;
  8565. if (typeof Polymer !== 'function') return;
  8566. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  8567. return Polymer;
  8568. }, promiseForTamerTimeout);
  8569.  
  8570. const schedulerInstanceObservable = observablePromise(() => {
  8571. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  8572. }, promiseForTamerTimeout);
  8573.  
  8574. const timelineObservable = observablePromise(() => {
  8575. let t = (((document || 0).timeline || 0) || 0);
  8576. if (t && typeof t._play === 'function') {
  8577. return t;
  8578. }
  8579. }, promiseForTamerTimeout);
  8580. const animationObservable = observablePromise(() => {
  8581. let t = (((window || 0).Animation || 0) || 0);
  8582. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  8583. return t;
  8584. }
  8585. }, promiseForTamerTimeout);
  8586.  
  8587.  
  8588. const getScreenInfo = {
  8589. screenWidth: 0,
  8590. screenHeight: 0,
  8591. valueReady: false,
  8592. onResize: () => {
  8593. getScreenInfo.valueReady = false;
  8594. },
  8595. sizeProvided: () => {
  8596. if (getScreenInfo.valueReady) return true;
  8597. getScreenInfo.screenWidth = screen.width;
  8598. getScreenInfo.screenHeight = screen.height;
  8599. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  8600. getScreenInfo.valueReady = true;
  8601. return true;
  8602. }
  8603. return false;
  8604. }
  8605. };
  8606.  
  8607. window.addEventListener('resize', getScreenInfo.onResize, true);
  8608.  
  8609.  
  8610. // const hookLeftPending = new WeakMap();
  8611.  
  8612. const isNaNx = Number.isNaN;
  8613.  
  8614. const hookLeftPD = {
  8615. get() {
  8616. const p = 'left';
  8617. // const o = hookLeftPending.get(this);
  8618. // if (o && o.key) {
  8619. // this.setProperty(p, o.value);
  8620. // o.key = null
  8621. // }
  8622. return this.getPropertyValue(p);
  8623. },
  8624. set(v) {
  8625.  
  8626. const p = 'left';
  8627. const cv = this.getPropertyValue(p);
  8628. const sv = v;
  8629.  
  8630. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  8631.  
  8632. // console.log(8380,did, cv, sv)
  8633. if (!cv && !sv) return true;
  8634. if (cv === sv) return true;
  8635.  
  8636. // skip 0~9px => L>=4
  8637.  
  8638. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  8639.  
  8640. if (!isNaNx(qsv)) {
  8641. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  8642.  
  8643. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  8644. const { screenWidth, screenHeight } = getScreenInfo;
  8645. let pWidth = screenWidth + 1024;
  8646. let pHeight = screenHeight + 768;
  8647. const minRatio = 0.003;
  8648. const dw = pWidth * 0.0003; // min dw = 0.3072
  8649. const dh = pHeight * 0.0003; // min dh = 0.2304
  8650. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  8651. if (Math.abs(qcv - qsv) < dw) return true;
  8652. }
  8653.  
  8654. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  8655. if (`${v}`.length > `${sv}`.length) v = sv;
  8656. // console.log(8382, did, sv, nv, cv, this)
  8657. }
  8658.  
  8659. // Promise.resolve().then(() => {
  8660. // const o = hookLeftPending.get(this);
  8661. // if (o && o.key === did) {
  8662. // this.setProperty(p, o.value);
  8663. // o.key = null;
  8664. // }
  8665. // });
  8666. // hookLeftPending.set(this, {
  8667. // key: did,
  8668. // value: nv
  8669. // });
  8670.  
  8671. // if (nv != v) {
  8672. // console.log(8387, v, nv);
  8673. // }
  8674.  
  8675. this.setProperty(p, v);
  8676. // console.log(8383, did, this.getPropertyValue(p))
  8677. return true;
  8678. },
  8679. enumerable: true,
  8680. configurable: true
  8681. };
  8682.  
  8683.  
  8684. if (HOOK_CSSPD_LEFT) {
  8685.  
  8686.  
  8687. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  8688.  
  8689. }
  8690.  
  8691.  
  8692.  
  8693.  
  8694.  
  8695. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  8696.  
  8697. const evKey = `${_evKey}`;
  8698. const fvKey = `${_fvKey}`;
  8699. const debug = !!_debug;
  8700.  
  8701. const _yt_player = await _yt_player_observable.obtain();
  8702.  
  8703.  
  8704. if (!_yt_player || typeof _yt_player !== 'object') return;
  8705.  
  8706.  
  8707. const getArr = (_yt_player) => {
  8708.  
  8709. let arr = [];
  8710.  
  8711. for (const [k, v] of Object.entries(_yt_player)) {
  8712.  
  8713. const p = typeof v === 'function' ? v.prototype : 0;
  8714. if (p
  8715. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  8716.  
  8717. ) {
  8718. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8719.  
  8720. }
  8721.  
  8722. }
  8723.  
  8724. if (arr.length === 0) {
  8725.  
  8726. console.warn(`Key prop [${evKey}] does not exist.`);
  8727. } else {
  8728.  
  8729. return arr;
  8730. }
  8731.  
  8732. };
  8733.  
  8734. const arr = getArr(_yt_player);
  8735.  
  8736.  
  8737. if (!arr) return;
  8738.  
  8739. debug && console.log(`FIX_${evKey}`, arr);
  8740.  
  8741. const f = function (...args) {
  8742. Promise.resolve().then(() => this[fvKey](...args));
  8743. };
  8744.  
  8745.  
  8746. for (const k of arr) {
  8747.  
  8748. const g = _yt_player;
  8749. const gk = g[k];
  8750. const gkp = gk.prototype;
  8751.  
  8752. debug && console.log(237, k, gkp)
  8753.  
  8754. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  8755. gkp[fvKey] = gkp[evKey];
  8756. gkp[evKey] = f;
  8757. }
  8758. }
  8759.  
  8760.  
  8761.  
  8762.  
  8763. }
  8764.  
  8765. if (!isChatRoomURL) {
  8766.  
  8767. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  8768. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  8769. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  8770. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  8771. if (FIX_VideoEVENTS_v2) {
  8772. const FIX_VideoEVENTS_DEBUG = 0;
  8773. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  8774. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  8775. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  8776. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  8777. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  8778. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  8779. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  8780. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  8781. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  8782.  
  8783. }
  8784. // onMutedAutoplayChange
  8785. // onVolumeChange
  8786. // onPlaybackRateChange
  8787.  
  8788. // onAirPlayActiveChange
  8789. // onAirPlayAvailabilityChange
  8790. // onApiChange
  8791. // onAutoplayBlocked
  8792. // onDrmOutputRestricted
  8793. // onFullscreenChange
  8794. // onLoadProgress
  8795. // onLoadedMetadata
  8796. // onVideoDataChange
  8797. // onVideoProgress
  8798.  
  8799. }
  8800.  
  8801.  
  8802. let isAmended_Polymer_RenderStatus = false;
  8803.  
  8804. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  8805.  
  8806. const Polymer = await polymerObservable.obtain();
  8807. if (!Polymer) return;
  8808.  
  8809. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  8810. isAmended_Polymer_RenderStatus = true;
  8811.  
  8812. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  8813. let arrBefore = null, arrAfter = null;
  8814. const push = Array.prototype.push;
  8815. let arr = null;
  8816. Array.prototype.push = function () {
  8817. arr = this;
  8818. }
  8819. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  8820. if (arr) arrBefore = arr;
  8821. arr = null;
  8822. Polymer.RenderStatus.afterNextRender({}, {}, {});
  8823. if (arr) arrAfter = arr;
  8824. arr = null;
  8825. Array.prototype.push = push;
  8826. Polymer.RenderStatus.arrBefore = arrBefore;
  8827. Polymer.RenderStatus.arrAfter = arrAfter;
  8828.  
  8829. if (arrBefore && arrAfter) {
  8830.  
  8831. Function.prototype.call7900 = Function.prototype.call;
  8832. Function.prototype.apply7900 = Function.prototype.apply;
  8833. Function.prototype.apply7948 = function (obj, args) {
  8834. const f = this;
  8835. let m = kRef(obj);
  8836. if (!m) return;
  8837. if (m.is && !m.nodeName) {
  8838. if (!m.isAttached || !m.hostElement) {
  8839. return;
  8840. }
  8841. }
  8842. try {
  8843. return !args ? f.call7900(m) : f.apply7900(m, args);
  8844. } catch (e) {
  8845. console.warn(e);
  8846. }
  8847. return null;
  8848. }
  8849.  
  8850. arrBefore.push = arrAfter.push = function (a) {
  8851. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  8852. if (a[0].deref) a[0] = kRef(a[0]);
  8853. const f = a[1]
  8854. const obj = a[0]
  8855. const args = a[2];
  8856. f.apply = f.apply7948;
  8857. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  8858. a[0] = obj[wk]
  8859. // console.log(4992, a)
  8860. return push.call(this, a);
  8861. }
  8862.  
  8863. }
  8864.  
  8865.  
  8866. }
  8867. // Polymer.RenderStatus.beforeNextRender
  8868. }
  8869.  
  8870. if (FIX_Polymer_dom) {
  8871.  
  8872. const checkPDFuncValue = (pd) => {
  8873. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  8874. }
  8875. const checkPDFuncValue2 = (pd) => {
  8876. return pd && typeof pd.value == 'function'
  8877. }
  8878.  
  8879. const checkPDFuncGet = (pd) => {
  8880. return pd && typeof pd.get == 'function'
  8881. }
  8882.  
  8883. const domX = Polymer.dom(document.createElement('null'));
  8884. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  8885. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  8886. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  8887. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  8888. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  8889. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  8890. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  8891. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  8892. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  8893.  
  8894.  
  8895. // getOwnerRoot - to be reviewed
  8896. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  8897.  
  8898. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  8899. domXP.getOwnerRoot = function () {
  8900. try {
  8901. const p = this.node;
  8902.  
  8903. if (p instanceof HTMLElement_) {
  8904. const pp = pd2.get.call(p);
  8905. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  8906. return pp.getRootNode();
  8907. }
  8908.  
  8909. }
  8910. } catch (e) { }
  8911. return this.getOwnerRoot15();
  8912. }
  8913.  
  8914. Polymer.__fixedGetOwnerRoot__ = 1;
  8915. }
  8916.  
  8917.  
  8918.  
  8919.  
  8920. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  8921.  
  8922. domXP.querySelector15 = domXP.querySelector;
  8923.  
  8924. const querySelectorFn = function (query) {
  8925. try {
  8926. const p = this.node;
  8927.  
  8928. if (p instanceof Document && p.isConnected === true) {
  8929. return pd4b.value.call(p, query);
  8930. }
  8931.  
  8932. } catch (e) { }
  8933. return this.querySelector15(query);
  8934. }
  8935.  
  8936. Object.defineProperty(domXP, 'querySelector', {
  8937. get() {
  8938. return querySelectorFn;
  8939. },
  8940. set(nv) {
  8941. if (nv === querySelectorFn) return true;
  8942. this.querySelector15 = nv;
  8943. return true;
  8944. },
  8945.  
  8946. enumerable: false,
  8947. configurable: true
  8948. });
  8949.  
  8950. Polymer.__fixedQuerySelector__ = 1;
  8951. }
  8952.  
  8953. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  8954.  
  8955. domXP.querySelectorAll15 = domXP.querySelectorAll;
  8956.  
  8957. const querySelectorAllFn = function (query) {
  8958.  
  8959. try {
  8960.  
  8961. const p = this.node;
  8962.  
  8963. if (p instanceof Document && p.isConnected === true) {
  8964. return pd6b.value.call(p, query);
  8965. }
  8966.  
  8967. } catch (e) {
  8968.  
  8969. }
  8970. return this.querySelectorAll15(query);
  8971. }
  8972.  
  8973. Object.defineProperty(domXP, 'querySelectorAll', {
  8974. get() {
  8975. return querySelectorAllFn;
  8976. },
  8977. set(nv) {
  8978. if (nv === querySelectorAllFn) return true;
  8979. this.querySelectorAll15 = nv;
  8980. return true;
  8981. },
  8982.  
  8983. enumerable: false,
  8984. configurable: true
  8985. });
  8986.  
  8987. Polymer.__fixedQuerySelectorAll__ = 1;
  8988. }
  8989. }
  8990.  
  8991.  
  8992. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  8993.  
  8994. Polymer.Base.__connInit__ = function () {
  8995. setupYtComponent(this);
  8996. }
  8997.  
  8998.  
  8999. /** @type {Function} */
  9000. const connectedCallbackK = function (...args) {
  9001. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9002. const r = this[qm53](...args);
  9003. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9004. this.mh35 = 1;
  9005. return r;
  9006. };
  9007.  
  9008. connectedCallbackK.m353 = 1;
  9009.  
  9010.  
  9011. const qt53 = Polymer.Base.connectedCallback;
  9012. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  9013.  
  9014. Polymer.Base.connectedCallback = connectedCallbackK;
  9015.  
  9016.  
  9017. /** @type {Function} */
  9018. const createdK = function (...args) {
  9019. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9020. const r = this[qn53](...args);
  9021. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9022. this.mh36 = 1;
  9023. return r;
  9024. };
  9025.  
  9026.  
  9027. createdK.m353 = 1;
  9028. Polymer.Base[qn53] = Polymer.Base.created;
  9029. Polymer.Base.created = createdK;
  9030.  
  9031.  
  9032.  
  9033.  
  9034.  
  9035.  
  9036.  
  9037.  
  9038.  
  9039.  
  9040.  
  9041. }
  9042.  
  9043. })();
  9044.  
  9045.  
  9046. /*
  9047.  
  9048. e.nativeAppendChild = d.prototype.appendChild,
  9049. d.prototype.appendChild = function(h) {
  9050. return function(l) {
  9051. if (l instanceof DocumentFragment) {
  9052. var m = Array.from(l.children);
  9053. l = h.nativeAppendChild.call(this, l);
  9054. if (this.isConnected) {
  9055. m = g(m);
  9056. for (var p = m.next(); !p.done; p = m.next())
  9057. YD(p.value)
  9058. }
  9059. return l
  9060. }
  9061. m = l instanceof Element && l.isConnected;
  9062. p = h.nativeAppendChild.call(this, l);
  9063. m && ZD(l);
  9064. this.isConnected && YD(l);
  9065. return p
  9066. }
  9067. }(e),
  9068.  
  9069. */
  9070.  
  9071. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  9072.  
  9073. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  9074. if (f) Node.prototype.appendChild = function (a) {
  9075. if (this instanceof Element) { // exclude DocumentFragment
  9076. try {
  9077. let checkFragmentA = (a instanceof DocumentFragment);
  9078. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  9079. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  9080. for (const node of headLinkCollection) {
  9081. if (node.rel === 'preload' && node.as === 'fetch') {
  9082. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  9083. }
  9084. }
  9085. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  9086. checkFragmentA = false;
  9087. }
  9088. if (checkFragmentA && a.firstElementChild === null) {
  9089. // no element in fragmentA
  9090. let doNormal = false;
  9091. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  9092. if (child.nodeType === 3) { doNormal = true; break; }
  9093. }
  9094. if (!doNormal) return a;
  9095. }
  9096. } catch (e) {
  9097. console.log(e);
  9098. }
  9099. }
  9100. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  9101. }
  9102.  
  9103. })();
  9104.  
  9105. if (FIX_Shady) {
  9106.  
  9107. observablePromise(() => {
  9108. const { ShadyDOM, ShadyCSS } = window;
  9109. if (ShadyDOM) {
  9110. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  9111. ShadyDOM.noPatch = true; // 1 of 10
  9112. ShadyDOM.patchOnDemand = false; // 1 of 10
  9113. ShadyDOM.preferPerformance = true; // 1 of 10
  9114. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  9115. }
  9116. if (ShadyCSS) {
  9117. ShadyCSS.nativeCss = true; // 1 of 10
  9118. ShadyCSS.nativeShadow = true; // 6 of 10
  9119. ShadyCSS.cssBuild = undefined; // 1 of 10
  9120. ShadyCSS.disableRuntime = true; // 1 of 10
  9121. }
  9122. if (ShadyDOM && ShadyCSS) return 1;
  9123. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  9124.  
  9125. }
  9126.  
  9127.  
  9128. // let schedulerInstancePropOfTimerType = '';
  9129. // let schedulerInstancePropOfTimerId = '';
  9130. (FIX_schedulerInstanceInstance & 2) && (async () => {
  9131.  
  9132. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  9133.  
  9134. if (!schedulerInstanceInstance_) return;
  9135.  
  9136. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  9137. if (checkOK) {
  9138.  
  9139. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  9140.  
  9141. let requestingFn = null;
  9142. let requestingArgs = null;
  9143.  
  9144. const f = function () {
  9145. requestingFn = this.fn;
  9146. requestingArgs = [...arguments];
  9147. return 12373;
  9148. };
  9149.  
  9150. const fakeFns = [
  9151. f.bind({ fn: requestAnimationFrame }),
  9152. f.bind({ fn: setInterval }),
  9153. f.bind({ fn: setTimeout }),
  9154. f.bind({ fn: requestIdleCallback })
  9155. ];
  9156.  
  9157. let mzt = 0;
  9158.  
  9159. let _fnSelectorProp = null;
  9160. const mkFns = new Array(4);
  9161.  
  9162. /*
  9163. case 1:
  9164. var a = this.K;
  9165. this.g = this.I ? window.requestIdleCallback(a, {
  9166. timeout: 3E3
  9167. }) : window.setTimeout(a, ma);
  9168. break;
  9169. case 2:
  9170. this.g = window.setTimeout(this.M, this.N);
  9171. break;
  9172. case 3:
  9173. this.g = window.requestAnimationFrame(this.L);
  9174. break;
  9175. case 4:
  9176. this.g = window.setTimeout(this.J, 0)
  9177. }
  9178.  
  9179. */
  9180. const startFnHandler = {
  9181. get(target, prop, receiver) {
  9182. if (prop === '$$12377$$') return true;
  9183. if (prop === '$$12378$$') return target;
  9184.  
  9185. // console.log('get',prop)
  9186. return target[prop]
  9187. },
  9188. set(target, prop, value, receiver) {
  9189. // console.log('set', prop, value)
  9190.  
  9191. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  9192. if (value === 12373 && _fnSelectorProp) {
  9193.  
  9194. const schedulerTypeSelection = target[_fnSelectorProp];
  9195. const timerIdProp = prop;
  9196.  
  9197. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  9198. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  9199. // schedulerInstancePropOfTimerId = timerIdProp || '';
  9200. // }
  9201.  
  9202. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  9203. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  9204. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  9205. // rare
  9206. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9207. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  9208. // often
  9209. if ((FIX_schedulerInstanceInstance & 4)) {
  9210. const f = requestingArgs[0];
  9211. const tir = ++mzt;
  9212. nextBrowserTick_(() => {
  9213. if (target[timerIdProp] === -tir) f();
  9214. });
  9215. target[_fnSelectorProp] = 940;
  9216. target[timerIdProp] = -tir;
  9217. } else {
  9218. const f = requestingArgs[0];
  9219. const tir = ++mzt;
  9220. Promise.resolve().then(() => {
  9221. if (target[timerIdProp] === -tir) f();
  9222. });
  9223. target[_fnSelectorProp] = 930;
  9224. target[timerIdProp] = -tir;
  9225. }
  9226. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  9227. // often
  9228. if (requestingFn === requestIdleCallback) {
  9229. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  9230. } else {
  9231. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9232. }
  9233. } else {
  9234. target[_fnSelectorProp] = 0;
  9235. target[timerIdProp] = 0;
  9236. }
  9237. } else {
  9238. target[prop] = value;
  9239. }
  9240. return true;
  9241. }
  9242. };
  9243.  
  9244. let startBusy = false;
  9245. schedulerInstanceInstance_.start = function () {
  9246. if (startBusy) return;
  9247. startBusy = true;
  9248. try {
  9249. mkFns[0] = window.requestAnimationFrame;
  9250. mkFns[1] = window.setInterval;
  9251. mkFns[2] = window.setTimeout;
  9252. mkFns[3] = window.requestIdleCallback;
  9253. const tThis = this['$$12378$$'] || this;
  9254. window.requestAnimationFrame = fakeFns[0]
  9255. window.setInterval = fakeFns[1]
  9256. window.setTimeout = fakeFns[2]
  9257. window.requestIdleCallback = fakeFns[3]
  9258. _fnSelectorProp = null;
  9259. tThis.start993.call(new Proxy(tThis, startFnHandler));
  9260. _fnSelectorProp = null;
  9261. window.requestAnimationFrame = mkFns[0];
  9262. window.setInterval = mkFns[1];
  9263. window.setTimeout = mkFns[2];
  9264. window.requestIdleCallback = mkFns[3];
  9265. } catch (e) {
  9266. console.warn(e);
  9267. }
  9268. startBusy = false;
  9269. }
  9270.  
  9271. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  9272.  
  9273. }
  9274. })();
  9275.  
  9276. FIX_yt_player && !isChatRoomURL && (async () => {
  9277.  
  9278. const fOption = 1 | 2 | 4;
  9279.  
  9280. const _yt_player = await _yt_player_observable.obtain();
  9281.  
  9282. if (!_yt_player || typeof _yt_player !== 'object') return;
  9283.  
  9284. const g = _yt_player;
  9285. let k;
  9286.  
  9287. if (fOption & 1) {
  9288.  
  9289. // rAf scheduling
  9290.  
  9291. const keyZqOu = getZqOu(_yt_player);
  9292. if (!keyZqOu) {
  9293. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  9294. return;
  9295. }
  9296. k = keyZqOu
  9297.  
  9298. const gk = g[k];
  9299. if (typeof gk !== 'function') {
  9300. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  9301. return;
  9302. }
  9303. const gkp = gk.prototype;
  9304.  
  9305. const dummyObject = new gk;
  9306. const nilFunc = () => { };
  9307.  
  9308. const nilObj = {};
  9309.  
  9310. // console.log(1111111111)
  9311.  
  9312. let keyBoolD = '';
  9313. let keyWindow = '';
  9314. let keyFuncC = '';
  9315. let keyCidj = '';
  9316.  
  9317. for (const [t, y] of Object.entries(dummyObject)) {
  9318. if (y instanceof Window) keyWindow = t;
  9319. }
  9320.  
  9321. const dummyObjectProxyHandler = {
  9322. get(target, prop) {
  9323. let v = target[prop]
  9324. if (v instanceof Window && !keyWindow) {
  9325. keyWindow = t;
  9326. }
  9327. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  9328. if (prop === keyWindow) y = {
  9329. requestAnimationFrame(f) {
  9330. return 3;
  9331. },
  9332. cancelAnimationFrame() {
  9333.  
  9334. }
  9335. }
  9336. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  9337. keyFuncC = prop;
  9338. }
  9339. // console.log('[get]', prop, typeof target[prop])
  9340.  
  9341.  
  9342. return y;
  9343. },
  9344. set(target, prop, value) {
  9345.  
  9346. if (typeof value === 'boolean' && !keyBoolD) {
  9347. keyBoolD = prop;
  9348. }
  9349. if (typeof value === 'number' && !keyCidj && value >= 2) {
  9350. keyCidj = prop;
  9351. }
  9352.  
  9353. // console.log('[set]', prop, value)
  9354. target[prop] = value;
  9355.  
  9356. return true;
  9357. }
  9358. };
  9359.  
  9360. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  9361.  
  9362. // console.log('gkp.start',gkp.start);
  9363. // console.log('gkp.stop',gkp.stop);
  9364. gkp._activation = false;
  9365.  
  9366. gkp.start = function () {
  9367. // p59 || console.log(12100)
  9368. if (!this._activation) {
  9369. this._activation = true;
  9370. foregroundPromiseFn().then(() => {
  9371. this._activation = false;
  9372. if (this[keyCidj]) {
  9373. Promise.resolve().then(this[keyFuncC]);
  9374. }
  9375. });
  9376. }
  9377. this[keyCidj] = 1;
  9378. this[keyBoolD] = true;
  9379. };
  9380.  
  9381. gkp.stop = function () {
  9382. this[keyCidj] = null;
  9383. };
  9384.  
  9385.  
  9386. /*
  9387. g[k].start = function() {
  9388. this.stop();
  9389. this.D = true;
  9390. var a = requestAnimationFrame
  9391. , b = cancelAnimationFrame;
  9392. this.j = a.call(this.B, this.C)
  9393. }
  9394. ;
  9395. g[k].stop = function() {
  9396. if (this.isActive()) {
  9397. var a = requestAnimationFrame
  9398. , b = cancelAnimationFrame;
  9399. b.call(this.B, this.j)
  9400. }
  9401. this.j = null
  9402. }
  9403. */
  9404. }
  9405.  
  9406. if (fOption & 2) {
  9407. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  9408.  
  9409. if (keyzo) {
  9410.  
  9411. k = keyzo;
  9412.  
  9413. const attrUpdateFn = g[k];
  9414. // console.log(5992, attrUpdateFn)
  9415. g['$$original$$' + k] = attrUpdateFn;
  9416. const zoTransform = async (a, c) => {
  9417.  
  9418. let transformType = '';
  9419. let transformValue = 0;
  9420. let transformUnit = '';
  9421. let transformTypeI = 0;
  9422.  
  9423. const aStyle = a.style;
  9424.  
  9425. let cType = 0;
  9426.  
  9427. const cl = c.length;
  9428.  
  9429. if (cl >= 8) {
  9430. // scale(1)
  9431. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  9432. cType = 1;
  9433. let t = c.charCodeAt(5);
  9434. if (t === 88 || t === 120) cType = 1 | 4;
  9435. if (t === 89 || t === 121) cType = 1 | 8;
  9436. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  9437. cType = 2;
  9438. let t = c.charCodeAt(9);
  9439. if (t === 88 || t === 120) cType = 2 | 4;
  9440. if (t === 89 || t === 121) cType = 2 | 8;
  9441. }
  9442. let w = 0;
  9443. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  9444. let p = c.substring(7, cl - 1);
  9445. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9446. if (typeof q === 'number' && !isNaNx(q)) {
  9447. transformType = w === 1 ? 'scaleX' : 'scaleY';
  9448. transformValue = q;
  9449. transformUnit = '';
  9450. transformTypeI = 1;
  9451. } else {
  9452. cType = 256;
  9453. }
  9454. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  9455. if (c.endsWith('px)')) {
  9456. let p = c.substring(11, cl - 3);
  9457. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9458. if (typeof q === 'number' && !isNaNx(q)) {
  9459. transformType = w === 1 ? 'translateX' : 'translateY';
  9460. transformValue = q;
  9461. transformUnit = 'px';
  9462. transformTypeI = 2;
  9463. } else if (p === 'NaN') {
  9464. return;
  9465. }
  9466. } else {
  9467. cType = 256;
  9468. }
  9469. } else if (cType > 0) {
  9470. cType = 256;
  9471. }
  9472. }
  9473.  
  9474.  
  9475. if (cType === 256) {
  9476. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  9477. }
  9478.  
  9479. if (transformTypeI === 1) {
  9480. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  9481. const vz = toFixed2(q, 3);
  9482. c = `${transformType}(${vz})`;
  9483. const cv = aStyle.transform;
  9484. if (c === cv) return;
  9485. aStyle.transform = c;
  9486. } else if (transformTypeI === 2) {
  9487. const q = transformValue;
  9488. const vz = toFixed2(q, 1);
  9489. c = `${transformType}(${vz}${transformUnit})`;
  9490. const cv = aStyle.transform;
  9491. if (c === cv) return;
  9492. aStyle.transform = c;
  9493. } else { // eg empty
  9494. const cv = aStyle.transform;
  9495. if (!c && !cv) return;
  9496. else if (c === cv) return;
  9497. aStyle.transform = c;
  9498. }
  9499.  
  9500. };
  9501.  
  9502. const elmTransformTemp = new WeakMap();
  9503. const elmPropTemps = {
  9504. 'display': new WeakMap(),
  9505. 'width': new WeakMap(),
  9506. 'height': new WeakMap(),
  9507. 'outlineWidth': new WeakMap(),
  9508. 'position': new WeakMap(),
  9509. 'padding': new WeakMap(),
  9510. "cssText": new WeakMap(),
  9511. "right": new WeakMap(),
  9512. "left": new WeakMap(),
  9513. "top": new WeakMap(),
  9514. "bottom": new WeakMap(),
  9515. "transitionDelay": new WeakMap(),
  9516. "marginLeft": new WeakMap(),
  9517. "marginTop": new WeakMap(),
  9518. "marginRight": new WeakMap(),
  9519. "marginBottom": new WeakMap(),
  9520. }
  9521.  
  9522. const ns5 = Symbol();
  9523. const nextModify = (a, c, m, f, immediate) => {
  9524. const a_ = a;
  9525. const m_ = m;
  9526. const noKey = !m_.has(a_);
  9527. if (immediate || noKey) {
  9528. m_.set(a_, ns5);
  9529. f(a_, c);
  9530. noKey && nextBrowserTick_(() => {
  9531. const d = m_.get(a_);
  9532. if (d === undefined) return;
  9533. m_.delete(a_);
  9534. if (d !== ns5) f(a_, d);
  9535. });
  9536. } else {
  9537. m_.set(a_, c);
  9538. }
  9539. };
  9540.  
  9541. const set66 = new Set();
  9542. const log77 = new Map();
  9543. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  9544.  
  9545. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  9546.  
  9547. // console.log(140000, a, b, c);
  9548. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  9549. const num = c;
  9550. c = `${num}`;
  9551. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  9552. }
  9553.  
  9554. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  9555.  
  9556. let elmPropTemp = null;
  9557.  
  9558. if (b === "transform") {
  9559. // div.ytp-hover-progress.ytp-hover-progress-light
  9560. // div.ytp-play-progress.ytp-swatch-background-color
  9561.  
  9562. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  9563. return;
  9564.  
  9565. } else if (elmPropTemp = elmPropTemps[b]) {
  9566.  
  9567. // if (c.length > 5 && c.includes('.')) {
  9568. // console.log(123213, c)
  9569. // }
  9570.  
  9571. const b_ = b;
  9572. nextModify(a, c, elmPropTemp, (a, c) => {
  9573. const style = a.style;
  9574. const cv = style[b_];
  9575. if (!cv && !c) return;
  9576. if (cv === c) return;
  9577. style[b_] = c;
  9578. }, immediateChange);
  9579. return;
  9580.  
  9581. } else if (b === "outline-width") {
  9582.  
  9583. const b_ = 'outlineWidth';
  9584. elmPropTemp = elmPropTemps[b_];
  9585. nextModify(a, c, elmPropTemp, (a, c) => {
  9586. const style = a.style;
  9587. const cv = style[b_];
  9588. if (!cv && !c) return;
  9589. if (cv === c) return;
  9590. style[b_] = c;
  9591. }, immediateChange);
  9592. return;
  9593.  
  9594. } else if (b === 'maxWidth' || b === 'maxHeight') {
  9595. // I think these can be directly assigned.
  9596.  
  9597. const b_ = b;
  9598. const style = a.style;
  9599. const cv = style[b_];
  9600. if (!cv && !c) return;
  9601. if (cv === c) return;
  9602. style[b_] = c;
  9603. return;
  9604.  
  9605. } else {
  9606. // if(immediate && elmPropTemps[b]){
  9607. // console.log(5191, b)
  9608. // }
  9609. // caption-window
  9610. // margin-left max-height max-width font-family fill color font-size background white-space margin
  9611. // text-align background-color
  9612. // console.log(27304, a, b, c)
  9613. if (!set66.has(b)) {
  9614. set66.add(b);
  9615. nextBrowserTick_(() => {
  9616. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  9617. console.log(27304, a, b, c)
  9618. }
  9619. })
  9620. }
  9621. }
  9622.  
  9623. attrUpdateFn.call(this, a, b, c);
  9624. return;
  9625. } else if (typeof (b || 0) === 'object') {
  9626.  
  9627. // this is to fix caption positioning
  9628. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  9629. const immediate = (a.id || 0).length > 14;
  9630. for (const [k, v] of Object.entries(b)) {
  9631. modifiedFn.call(this, a, k, v, immediate);
  9632. }
  9633.  
  9634. } else {
  9635.  
  9636. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  9637. // ytp-ad-timed-pie-countdown-inner
  9638.  
  9639. if (typeof b === 'string') {
  9640.  
  9641. let m = log77.get(b);
  9642. if (!m) {
  9643. m = [];
  9644. console.log('attrUpdateFn.debug.27304', m);
  9645. log77.set(b, m);
  9646. }
  9647. m.push([a, b, c]);
  9648.  
  9649. } else {
  9650. console.log('attrUpdateFn.debug.27306', a, b, c);
  9651. }
  9652.  
  9653. attrUpdateFn.call(this, a, b, c);
  9654. return;
  9655. }
  9656.  
  9657. // console.log(130000, a, b, c);
  9658.  
  9659. };
  9660. g[k] = modifiedFn;
  9661.  
  9662.  
  9663. /*
  9664.  
  9665. g.zo = function(a, b, c) {
  9666. if ("string" === typeof b)
  9667. (b = yo(a, b)) && (a.style[b] = c);
  9668. else
  9669. for (var d in b) {
  9670. c = a;
  9671. var e = b[d]
  9672. , f = yo(c, d);
  9673. f && (c.style[f] = e)
  9674. }
  9675. }
  9676.  
  9677.  
  9678. */
  9679.  
  9680.  
  9681. }
  9682. }
  9683.  
  9684. if (fOption & 4) {
  9685. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  9686.  
  9687. if (keyuG) {
  9688.  
  9689. k = keyuG;
  9690.  
  9691. const gk = g[k];
  9692. const gkp = gk.prototype;
  9693.  
  9694.  
  9695. /** @type { Map<string, WeakMap<any, any>> } */
  9696. const ntLogs = new Map();
  9697.  
  9698. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  9699.  
  9700. gkp.updateValue31 = gkp.updateValue;
  9701. gkp.updateValue = function (a, b) {
  9702. if (typeof a !== 'string') return this.updateValue31(a, b);
  9703.  
  9704. const element = this.element;
  9705. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  9706.  
  9707. let ntLog = ntLogs.get(a);
  9708. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  9709.  
  9710. let cache = ntLog.get(element);
  9711. if (cache && cache.value === b) {
  9712. return;
  9713. }
  9714. if (!cache) {
  9715. this.__oldValueByUpdateValue__ = null;
  9716. ntLog.set(element, cache = { value: b });
  9717. } else {
  9718. this.__oldValueByUpdateValue__ = cache.value;
  9719. cache.value = b;
  9720. }
  9721.  
  9722. return this.updateValue31(a, b);
  9723. }
  9724.  
  9725. /*
  9726. g.k.update = function(a) {
  9727. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  9728. c = c.value,
  9729. this.updateValue(c, a[c])
  9730. }
  9731. ;
  9732. g.k.updateValue = function(a, b) {
  9733. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  9734. }
  9735. */
  9736.  
  9737. }
  9738.  
  9739.  
  9740. }
  9741. }
  9742.  
  9743.  
  9744.  
  9745. })();
  9746.  
  9747.  
  9748. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  9749. // keyboard shortcut keys controller
  9750.  
  9751. const _yt_player = await _yt_player_observable.obtain();
  9752.  
  9753. if (!_yt_player || typeof _yt_player !== 'object') return;
  9754.  
  9755. keyboardController(_yt_player);
  9756.  
  9757. })();
  9758.  
  9759. FIX_yt_player && !isChatRoomURL && (async () => {
  9760. // timer scheduling
  9761.  
  9762. const _yt_player = await _yt_player_observable.obtain();
  9763.  
  9764. if (!_yt_player || typeof _yt_player !== 'object') return;
  9765.  
  9766. let keyZqQu = getZqQu(_yt_player);
  9767.  
  9768. if (!keyZqQu) return;
  9769.  
  9770. const g = _yt_player
  9771. let k = keyZqQu
  9772.  
  9773. const gk = g[k];
  9774. if (typeof gk !== 'function') return;
  9775. const gkp = gk.prototype;
  9776.  
  9777. const extractKeysZqQu = () => {
  9778.  
  9779.  
  9780. let _keyeC = '';
  9781. try {
  9782. gkp.stop.call(new Proxy({
  9783. isActive: () => { }
  9784. }, {
  9785. set(target, prop, value) {
  9786. if (value === 0) _keyeC = prop;
  9787. return true;
  9788. }
  9789. }));
  9790. } catch (e) { }
  9791. if (!_keyeC) return;
  9792. const keyeC = _keyeC;
  9793.  
  9794. let keyC = ''; // this.C = this.ST.bind(this)
  9795. let keyhj = ''; // 1000ms
  9796. try {
  9797. gkp.start.call(new Proxy({
  9798. stop: () => { },
  9799. [keyeC]: 0,
  9800. }, {
  9801. get(target, prop) {
  9802. if (prop in target) return target[prop];
  9803. if (!keyC) {
  9804. keyC = prop;
  9805. return null; // throw error
  9806. }
  9807. else if (!keyhj) {
  9808. keyhj = prop;
  9809. }
  9810.  
  9811. }
  9812. }));
  9813. } catch (e) {
  9814. if (!keyC || !keyhj) {
  9815. console.log(e)
  9816. }
  9817. }
  9818.  
  9819. if (!keyC || !keyhj) return;
  9820. let keyST = '';
  9821. let keyj = '';
  9822. let keyB = '';
  9823. let keyxa = '';
  9824.  
  9825. const possibleKs = new Set();
  9826.  
  9827. for (const [k, v] of Object.entries(gkp)) {
  9828. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  9829. continue;
  9830. }
  9831. if (typeof v === 'function') {
  9832. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  9833. if (m) {
  9834. keyST = k;
  9835. keyj = m[1];
  9836. keyB = m[2];
  9837. } else {
  9838. possibleKs.add(k);
  9839. }
  9840. }
  9841. }
  9842.  
  9843. if (!keyST || !keyj || !keyB) return;
  9844.  
  9845. for (const k of possibleKs) {
  9846. if (k === keyST || k === keyj || k === keyB) {
  9847. continue;
  9848. }
  9849. const v = gkp[k];
  9850. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  9851. keyxa = k;
  9852. }
  9853. }
  9854.  
  9855. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  9856.  
  9857. }
  9858.  
  9859. const keys = extractKeysZqQu();
  9860. if (!keys || !keys.length) return;
  9861. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  9862.  
  9863. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  9864.  
  9865. let disposeKeys = null;
  9866.  
  9867. gkp[keyxa] = function () {
  9868. // dispose
  9869. if (!disposeKeys) {
  9870. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  9871. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  9872. const t = typeof this[key];
  9873. return t === 'undefined' || t === 'object'
  9874. }
  9875. return false;
  9876. });
  9877. }
  9878. for (const key of disposeKeys) {
  9879. const v = this[key];
  9880. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  9881. }
  9882. if (this[keyeC] > 0) this.stop();
  9883. this[keyj] = null;
  9884. this[keyB] = null;
  9885. };
  9886.  
  9887. gkp.start = function (a) {
  9888. if (this[keyeC] > 0) this.stop();
  9889. const delay = void 0 !== a ? a : this[keyhj];
  9890. this[keyeC] = window.setTimeout(this[keyC], delay);
  9891. };
  9892. gkp.stop = function () {
  9893. if (this[keyeC] > 0) {
  9894. window.clearTimeout(this[keyeC]);
  9895. this[keyeC] = 0;
  9896. }
  9897. };
  9898.  
  9899. gkp.isActive = function () {
  9900. return this[keyeC] > 0;
  9901. };
  9902.  
  9903. gkp[keyST] = function () {
  9904. this.stop(); // this[keyeC] = 0;
  9905. const fn = this[keyj];
  9906. const obj = this[keyB];
  9907. let skip = false;
  9908. if (!fn) skip = true;
  9909. else if (IGNORE_bufferhealth_CHECK && obj) {
  9910. let m;
  9911. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  9912. if (m.has("bufferhealth")) skip = true;
  9913. }
  9914. }
  9915. if (!skip) {
  9916. fn.call(obj);
  9917. }
  9918. };
  9919.  
  9920.  
  9921.  
  9922.  
  9923. /*
  9924.  
  9925. g.k.eC = 0;
  9926. g.k.xa = function() {
  9927. g.Qu.Vf.xa.call(this);
  9928. this.stop();
  9929. delete this.j;
  9930. delete this.B
  9931. }
  9932. ;
  9933. g.k.start = function(a) {
  9934. this.stop();
  9935. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  9936. }
  9937. ;
  9938. g.k.stop = function() {
  9939. this.isActive() && g.Sa.clearTimeout(this.eC);
  9940. this.eC = 0
  9941. }
  9942. ;
  9943. g.k.isActive = function() {
  9944. return 0 != this.eC
  9945. }
  9946. ;
  9947. g.k.ST = function() {
  9948. this.eC = 0;
  9949. this.j && this.j.call(this.B)
  9950. }
  9951. ;
  9952. */
  9953.  
  9954.  
  9955.  
  9956.  
  9957. })();
  9958.  
  9959. FIX_Animation_n_timeline && (async () => {
  9960.  
  9961. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  9962.  
  9963. if (!timeline || !Animation) return;
  9964.  
  9965. const aniProto = Animation.prototype;
  9966. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  9967.  
  9968. const getXroto = (x) => {
  9969. try {
  9970. return x.__proto__;
  9971. } catch (e) { }
  9972. return null;
  9973. }
  9974. const timProto = getXroto(timeline);
  9975. if (!timProto) return;
  9976. if (
  9977. (
  9978. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  9979. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  9980. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  9981. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  9982. )
  9983.  
  9984. ) {
  9985.  
  9986. timProto.nofCQ = 1;
  9987. aniProto.nofYH = 1;
  9988.  
  9989. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  9990.  
  9991.  
  9992. /*
  9993. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  9994. return c._updatePromises();
  9995. });
  9996. */
  9997.  
  9998. const p = Array.prototype.filter;
  9999.  
  10000. let res = null;
  10001. Array.prototype.filter = function () {
  10002.  
  10003. res = this;
  10004. return this;
  10005.  
  10006. };
  10007.  
  10008. _updateAnimationsPromises.call({});
  10009.  
  10010. Array.prototype.filter = p;
  10011.  
  10012. if (res && typeof res.length === 'number') {
  10013. /** @type {any[]} */
  10014. const _res = res;
  10015. return _res;
  10016. }
  10017.  
  10018.  
  10019. return null;
  10020.  
  10021.  
  10022.  
  10023.  
  10024. })(timProto._updateAnimationsPromises);
  10025.  
  10026. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  10027.  
  10028. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  10029.  
  10030. aniProto._updatePromises31 = aniProto._updatePromises;
  10031.  
  10032. /*
  10033. aniProto._updatePromises = function(){
  10034. console.log('eff',this._oldPlayState, this.playState)
  10035. return this._updatePromises31.apply(this, arguments)
  10036. }
  10037. */
  10038.  
  10039. aniProto._updatePromises = function () {
  10040. var oldPlayState = this._oldPlayState;
  10041. var newPlayState = this.playState;
  10042. // console.log('ett', oldPlayState, newPlayState)
  10043. if (newPlayState !== oldPlayState) {
  10044. this._oldPlayState = newPlayState;
  10045. if (this._readyPromise) {
  10046. if ("idle" == newPlayState) {
  10047. this._rejectReadyPromise();
  10048. this._readyPromise = void 0;
  10049. } else if ("pending" == oldPlayState) {
  10050. this._resolveReadyPromise();
  10051. } else if ("pending" == newPlayState) {
  10052. this._readyPromise = void 0;
  10053. }
  10054. }
  10055. if (this._finishedPromise) {
  10056. if ("idle" == newPlayState) {
  10057. this._rejectFinishedPromise();
  10058. this._finishedPromise = void 0;
  10059. } else if ("finished" == newPlayState) {
  10060. this._resolveFinishedPromise();
  10061. } else if ("finished" == oldPlayState) {
  10062. this._finishedPromise = void 0;
  10063. }
  10064. }
  10065. }
  10066. return this._readyPromise || this._finishedPromise;
  10067. };
  10068.  
  10069.  
  10070. let restartWebAnimationsNextTickFlag = false;
  10071.  
  10072. const looperMethodT = () => {
  10073.  
  10074. const runnerFn = (hRes) => {
  10075. var b = timeline;
  10076. b.currentTime = hRes;
  10077. b._discardAnimations();
  10078. if (0 == b._animations.length) {
  10079. restartWebAnimationsNextTickFlag = false;
  10080. } else {
  10081. getRafPromise().then(runnerFn);
  10082. }
  10083. }
  10084.  
  10085. const restartWebAnimationsNextTick = () => {
  10086. if (!restartWebAnimationsNextTickFlag) {
  10087. restartWebAnimationsNextTickFlag = true;
  10088. getRafPromise().then(runnerFn);
  10089. }
  10090. }
  10091.  
  10092. return { restartWebAnimationsNextTick }
  10093. };
  10094.  
  10095.  
  10096. const looperMethodN = () => {
  10097.  
  10098. const acs = document.createElement('a-f');
  10099. acs.id = 'a-f';
  10100.  
  10101. if (!document.getElementById('afscript')) {
  10102. const style = document.createElement('style');
  10103. style.id = 'afscript';
  10104. style.textContent = `
  10105. @keyFrames aF1 {
  10106. 0% {
  10107. order: 0;
  10108. }
  10109. 100% {
  10110. order: 1;
  10111. }
  10112. }
  10113. #a-f[id] {
  10114. visibility: collapse !important;
  10115. position: fixed !important;
  10116. display: block !important;
  10117. top: -100px !important;
  10118. left: -100px !important;
  10119. margin:0 !important;
  10120. padding:0 !important;
  10121. outline:0 !important;
  10122. border:0 !important;
  10123. z-index:-1 !important;
  10124. width: 0px !important;
  10125. height: 0px !important;
  10126. contain: strict !important;
  10127. pointer-events: none !important;
  10128. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  10129. }
  10130. `;
  10131. (document.head || document.documentElement).appendChild(style);
  10132. }
  10133.  
  10134. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  10135.  
  10136. const _onanimationiteration = function (evt) {
  10137. const hRes = evt.timeStamp;
  10138. var b = timeline;
  10139. b.currentTime = hRes;
  10140. b._discardAnimations();
  10141. if (0 == b._animations.length) {
  10142. restartWebAnimationsNextTickFlag = false;
  10143. acs.onanimationiteration = null;
  10144. } else {
  10145. acs.onanimationiteration = _onanimationiteration;
  10146. }
  10147.  
  10148. }
  10149.  
  10150.  
  10151.  
  10152. const restartWebAnimationsNextTick = () => {
  10153. if (!restartWebAnimationsNextTickFlag) {
  10154. restartWebAnimationsNextTickFlag = true;
  10155. acs.onanimationiteration = _onanimationiteration;
  10156.  
  10157. }
  10158. }
  10159.  
  10160. return { restartWebAnimationsNextTick }
  10161. };
  10162.  
  10163.  
  10164.  
  10165. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  10166.  
  10167.  
  10168. // console.log(571, timProto);
  10169. timProto._play = function (c) {
  10170. c = new Animation(c, this);
  10171. this._animations.push(c);
  10172. restartWebAnimationsNextTick();
  10173. c._updatePromises();
  10174. c._animation.play();
  10175. c._updatePromises();
  10176. return c
  10177. }
  10178.  
  10179. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  10180. originalAnimationsWithPromises.length = 0;
  10181. originalAnimationsWithPromises.push = null;
  10182. originalAnimationsWithPromises.splice = null;
  10183. originalAnimationsWithPromises.slice = null;
  10184. originalAnimationsWithPromises.indexOf = null;
  10185. originalAnimationsWithPromises.unshift = null;
  10186. originalAnimationsWithPromises.shift = null;
  10187. originalAnimationsWithPromises.pop = null;
  10188. originalAnimationsWithPromises.filter = null;
  10189. originalAnimationsWithPromises.forEach = null;
  10190. originalAnimationsWithPromises.map = null;
  10191.  
  10192.  
  10193. const _updateAnimationsPromises = () => {
  10194. animationsWithPromisesMap.forEach(c => {
  10195. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  10196. });
  10197. /*
  10198. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10199. return c._updatePromises();
  10200. });
  10201. */
  10202. }
  10203.  
  10204. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  10205.  
  10206. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  10207.  
  10208. delete timProto._updateAnimationsPromises;
  10209. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  10210. get() {
  10211. if (animationsWithPromisesMap.size === 0) return nilFn;
  10212. return _updateAnimationsPromises;
  10213. },
  10214. set(nv) {
  10215. delete this._updateAnimationsPromises;
  10216. this._updateAnimationsPromises = nv;
  10217. },
  10218. enumerable: true,
  10219. configurable: true,
  10220. });
  10221.  
  10222.  
  10223. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  10224. aniProto.__finished_native_get__ = pdFinished.get;
  10225. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  10226.  
  10227.  
  10228. Object.defineProperty(aniProto, 'finished', {
  10229. get() {
  10230. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10231. this._finishedPromise = new Promise((resolve, reject) => {
  10232. this._resolveFinishedPromise = function () {
  10233. resolve(this)
  10234. };
  10235. this._rejectFinishedPromise = function () {
  10236. reject({
  10237. type: DOMException.ABORT_ERR,
  10238. name: "AbortError"
  10239. })
  10240. };
  10241. }),
  10242. "finished" == this.playState && this._resolveFinishedPromise());
  10243. return this._finishedPromise
  10244. },
  10245. set: undefined,
  10246. enumerable: true,
  10247. configurable: true
  10248. });
  10249.  
  10250. }
  10251.  
  10252.  
  10253.  
  10254. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  10255. aniProto.__ready_native_get__ = pdReady.get;
  10256. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  10257.  
  10258. Object.defineProperty(aniProto, 'ready', {
  10259. get() {
  10260. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10261. this._readyPromise = new Promise((resolve, reject) => {
  10262. this._resolveReadyPromise = function () {
  10263. resolve(this)
  10264. };
  10265. this._rejectReadyPromise = function () {
  10266. reject({
  10267. type: DOMException.ABORT_ERR,
  10268. name: "AbortError"
  10269. })
  10270. };
  10271. }),
  10272. "pending" !== this.playState && this._resolveReadyPromise());
  10273. return this._readyPromise
  10274. },
  10275. set: undefined,
  10276. enumerable: true,
  10277. configurable: true
  10278. });
  10279.  
  10280. }
  10281.  
  10282.  
  10283. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  10284.  
  10285. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  10286. const _rebuildUnderlyingAnimation = function () {
  10287. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  10288. this.effect && this.effect._onsample && (this.effect._onsample = null);
  10289. return this._rebuildUnderlyingAnimation21();
  10290. }
  10291. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  10292. // delete aniProto._rebuildUnderlyingAnimation;
  10293. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  10294. // get() {
  10295. // if (isNaN(this._sequenceNumber)) return nilFn;
  10296. // return this._rebuildUnderlyingAnimation21;
  10297. // },
  10298. // set(nv) {
  10299. // delete this._rebuildUnderlyingAnimation;
  10300. // this._rebuildUnderlyingAnimation = nv;
  10301. // },
  10302. // enumerable: true,
  10303. // configurable: true
  10304. // });
  10305. }
  10306.  
  10307.  
  10308. /*
  10309.  
  10310.  
  10311. function f(c) {
  10312. var b = v.timeline;
  10313. b.currentTime = c;
  10314. b._discardAnimations();
  10315. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  10316. }
  10317. var h = window.requestAnimationFrame;
  10318. window.requestAnimationFrame = function(c) {
  10319. return h(function(b) {
  10320. v.timeline._updateAnimationsPromises();
  10321. c(b);
  10322. v.timeline._updateAnimationsPromises()
  10323. })
  10324. }
  10325. ;
  10326. v.AnimationTimeline = function() {
  10327. this._animations = [];
  10328. this.currentTime = void 0
  10329. }
  10330. ;
  10331. v.AnimationTimeline.prototype = {
  10332. getAnimations: function() {
  10333. this._discardAnimations();
  10334. return this._animations.slice()
  10335. },
  10336. _updateAnimationsPromises: function() {
  10337. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  10338. return c._updatePromises()
  10339. })
  10340. },
  10341. _discardAnimations: function() {
  10342. this._updateAnimationsPromises();
  10343. this._animations = this._animations.filter(function(c) {
  10344. return "finished" != c.playState && "idle" != c.playState
  10345. })
  10346. },
  10347. _play: function(c) {
  10348. c = new v.Animation(c,this);
  10349. this._animations.push(c);
  10350. v.restartWebAnimationsNextTick();
  10351. c._updatePromises();
  10352. c._animation.play();
  10353. c._updatePromises();
  10354. return c
  10355. },
  10356. play: function(c) {
  10357. c && c.remove();
  10358. return this._play(c)
  10359. }
  10360. };
  10361. var d = !1;
  10362. v.restartWebAnimationsNextTick = function() {
  10363. d || (d = !0,
  10364. requestAnimationFrame(f))
  10365. }
  10366. ;
  10367. var a = new v.AnimationTimeline;
  10368. v.timeline = a;
  10369. try {
  10370. Object.defineProperty(window.document, "timeline", {
  10371. configurable: !0,
  10372. get: function() {
  10373. return a
  10374. }
  10375. })
  10376. } catch (c) {}
  10377. try {
  10378. window.document.timeline = a
  10379. } catch (c) {}
  10380.  
  10381. */
  10382.  
  10383.  
  10384.  
  10385. /*
  10386.  
  10387. var g = window.getComputedStyle;
  10388. Object.defineProperty(window, "getComputedStyle", {
  10389. configurable: !0,
  10390. enumerable: !0,
  10391. value: function() {
  10392. v.timeline._updateAnimationsPromises();
  10393. var e = g.apply(this, arguments);
  10394. h() && (e = g.apply(this, arguments));
  10395. v.timeline._updateAnimationsPromises();
  10396. return e
  10397. }
  10398. });
  10399.  
  10400. */
  10401.  
  10402.  
  10403.  
  10404.  
  10405. }
  10406.  
  10407.  
  10408.  
  10409.  
  10410. })();
  10411.  
  10412. !isUrlInEmbed && Promise.resolve().then(() => {
  10413.  
  10414. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  10415.  
  10416.  
  10417.  
  10418. class LimitedSizeSet extends Set {
  10419. constructor(n) {
  10420. super();
  10421. this.limit = n;
  10422. }
  10423.  
  10424. add(key) {
  10425. if (!super.has(key)) {
  10426. super.add(key);
  10427. let n = super.size - this.limit;
  10428. if (n > 0) {
  10429. const iterator = super.values();
  10430. do {
  10431. const firstKey = iterator.next().value; // Get the first (oldest) key
  10432. super.delete(firstKey); // Delete the oldest key
  10433. } while (--n > 0)
  10434. }
  10435. }
  10436. }
  10437.  
  10438. removeAdd(key) {
  10439. super.delete(key);
  10440. this.add(key);
  10441. }
  10442.  
  10443. }
  10444.  
  10445. // const wk3 = new WeakMap();
  10446.  
  10447. // let mtxVideoId = '';
  10448. // let aje3 = [];
  10449. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  10450. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  10451. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  10452. let mtzCount = 0; // the key keeps unchanged
  10453. // let mjtNextMainKey = '';
  10454. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  10455. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  10456. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  10457. // let allowNoDelay322=false;
  10458. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  10459.  
  10460. let mpKey22 = ''; // last success continutation key & url pair
  10461. let mpUrl22 = ''; // last success continutation key & url pair
  10462. let mpKey21 = ''; // latest requested continutation key & url pair
  10463. let mpUrl21 = ''; // latest requested continutation key & url pair
  10464.  
  10465.  
  10466. async function sha1Hex(message) {
  10467. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  10468. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  10469. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  10470. const hashHex = hashArray
  10471. .map((b) => b.toString(16).padStart(2, "0"))
  10472. .join(""); // convert bytes to hex string
  10473. return hashHex;
  10474. }
  10475.  
  10476. async function continuationLog(a, ...args) {
  10477. let b = a;
  10478. try {
  10479. if (advanceLogging) b = await sha1Hex(a);
  10480. let c = args.map(e => {
  10481. return e === a ? b : e
  10482. });
  10483. console.log(...c)
  10484. } catch (e) { console.warn(e) }
  10485. }
  10486.  
  10487. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  10488.  
  10489.  
  10490. if (mfvContinuationRecorded.length > 0) {
  10491. for (const [e, d] of mfvContinuationRecorded) {
  10492. mfyContinuationIgnored.removeAdd(e);
  10493. }
  10494. toClearRecorded && mfvContinuationRecorded.clear();
  10495. }
  10496.  
  10497. }
  10498.  
  10499. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  10500.  
  10501. const tmProto = taskMgr.constructor.prototype;
  10502. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  10503.  
  10504. if (!tmProto.addJob714) {
  10505.  
  10506. tmProto.addJob714 = tmProto.addJob;
  10507.  
  10508. tmProto.addJob = function (a, b, c) {
  10509. const jobId = this.addJob714(a, b, c);
  10510. if (jobId > 0) {
  10511. // const ez = wk3.get(this);
  10512. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  10513. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  10514.  
  10515. this.__lastJobId863__ = jobId;
  10516. }
  10517. return jobId;
  10518. }
  10519.  
  10520. }
  10521.  
  10522. if (!tmProto.cancelJob714) {
  10523.  
  10524. tmProto.cancelJob714 = tmProto.cancelJob;
  10525.  
  10526. tmProto.cancelJob = function (a) {
  10527. const res = this.cancelJob714(a);
  10528. // if (a > 0) {
  10529. // for (const e of aje3) {
  10530. // if (e.jobId === a) e.cancelled = true;
  10531. // }
  10532. // }
  10533. return res;
  10534. }
  10535.  
  10536. }
  10537.  
  10538. }
  10539. }
  10540.  
  10541.  
  10542. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  10543.  
  10544.  
  10545. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  10546. let dummy;
  10547. let cProto;
  10548. // let mc = 4;
  10549. // dummy = await observablePromise(() => {
  10550. // const r = document.querySelector('ytd-video-primary-info-renderer');
  10551. // if (!r) return;
  10552. // let cProto = insp(r).constructor.prototype;
  10553. // if (cProto.fetchUpdatedMetadata) return r;
  10554. // if (--mc < 0) return -1;
  10555. // return null;
  10556. // }).obtain();
  10557. dummy = document.createElement('ytd-video-primary-info-renderer');
  10558. if (!(dummy instanceof Element)) return;
  10559. // console.log(5022, dummy)
  10560. cProto = insp(dummy).constructor.prototype;
  10561.  
  10562. cProto.__getEmittorTaskMgr859__ = function () {
  10563. let taskMgr_ = null;
  10564. try {
  10565. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  10566. } catch (e) { }
  10567. return taskMgr_;
  10568. }
  10569. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  10570. // console.log(1234, cProto, cProto.is)
  10571. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  10572.  
  10573. let c_;
  10574. cProto.fetchUpdatedMetadata718 = function (a) {
  10575. // delay or immediate call the actual fetchUpdatedMetadata
  10576.  
  10577. let doImmediately = false;
  10578. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  10579.  
  10580. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  10581.  
  10582. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  10583.  
  10584. doImmediately = true;
  10585.  
  10586. }
  10587.  
  10588. if (mbCId322) {
  10589. clearTimeout(mbCId322);
  10590. mbCId322 = 0;
  10591. }
  10592.  
  10593. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  10594.  
  10595. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  10596.  
  10597. mbCId322 = setTimeout(() => {
  10598. this.fetchUpdatedMetadata717(a);
  10599. }, delay);
  10600.  
  10601. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  10602.  
  10603. }
  10604.  
  10605. cProto.fetchUpdatedMetadata = function (a) {
  10606.  
  10607. if (!pageSetupState) {
  10608. if (c_) clearTimeout(c_);
  10609. c_ = setTimeout(() => {
  10610. this.fetchUpdatedMetadata718(a);
  10611. }, 300);
  10612. return;
  10613. }
  10614.  
  10615. // pageSetupState == 0
  10616.  
  10617. try {
  10618.  
  10619. mbDelayBelowNCalls++;
  10620.  
  10621. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  10622. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  10623. }
  10624.  
  10625. // console.log('fum377', a)
  10626. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  10627. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  10628. return;
  10629. }
  10630.  
  10631. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  10632. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  10633. mjtLockPreviousKey = mjtRecordedPrevKey;
  10634. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  10635. }
  10636. // mjtNextMainKey = true;
  10637. mtzlastAllowedContinuation = '';
  10638. mtzCount = 0;
  10639. // allowNoDelay322 = false;
  10640. // fetch new metadata, cancel all previous continuations
  10641. copyPreviousContiuationToIgnored374(true);
  10642. } else if (typeof a === 'string') {
  10643. const videoPlayingId = videoPlayingY.videoId;
  10644.  
  10645. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  10646.  
  10647. let update21 = !!pageSetupVideoId;
  10648. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  10649. update21 = true;
  10650. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  10651. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  10652. return;
  10653. }
  10654. if (update21) {
  10655. mpKey21 = a;
  10656. mpUrl21 = pageSetupVideoId || videoPlayingId;
  10657. }
  10658.  
  10659. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  10660. }
  10661. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  10662. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  10663. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  10664. return this.fetchUpdatedMetadata718(a);
  10665.  
  10666. } catch (e) {
  10667. console.log('Code Error in fetchUpdatedMetadata', e);
  10668. }
  10669. return this.fetchUpdatedMetadata717(a)
  10670. }
  10671. }
  10672.  
  10673.  
  10674. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  10675. // console.log(1234, cProto, cProto.is)
  10676. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  10677. let mJob = null;
  10678.  
  10679. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  10680.  
  10681. try {
  10682.  
  10683. if (arguments.length > 0) {
  10684. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  10685. }
  10686. // mfy = mfv;
  10687.  
  10688. // mjtNextMainKey = '';
  10689. mtzlastAllowedContinuation = '';
  10690. mtzCount = 0;
  10691. if (mbCId322) {
  10692. clearTimeout(mbCId322);
  10693. mbCId322 = 0;
  10694. }
  10695. mbDelayBelowNCalls = 0;
  10696. // allowNoDelay322 = false;
  10697. copyPreviousContiuationToIgnored374(true);
  10698.  
  10699. const taskMgr = this.__getEmittorTaskMgr859__();
  10700. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  10701. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  10702. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  10703. }
  10704.  
  10705. // prevent depulicated schedule job by clearing previous JobId
  10706. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  10707.  
  10708. let res;
  10709.  
  10710. if (mJob) {
  10711. const job = mJob;
  10712. mJob = null;
  10713. console.log('cancelJob', job)
  10714. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  10715. // p.cancelJob(a,b);
  10716. }
  10717.  
  10718. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  10719.  
  10720. let pza = taskMgr.__lastJobId863__;
  10721. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  10722. let pzb = taskMgr.__lastJobId863__
  10723. if (pza !== pzb) {
  10724. mJob = pzb; // set [Interval Meta Update] jobId
  10725. }
  10726.  
  10727. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  10728. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  10729. // } else {
  10730. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  10731. // }
  10732.  
  10733. return res;
  10734.  
  10735. } else {
  10736. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  10737. }
  10738.  
  10739. } catch (e) {
  10740. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  10741. }
  10742.  
  10743.  
  10744. return this.scheduleInitialUpdatedMetadataRequest717();
  10745. }
  10746. }
  10747.  
  10748.  
  10749. });
  10750.  
  10751. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  10752. let dummy;
  10753. let cProto;
  10754. dummy = ytAppDom;
  10755. if (!(dummy instanceof Element)) return;
  10756. cProto = insp(dummy).constructor.prototype;
  10757. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  10758. // console.log(1234, cProto, cProto.is);
  10759. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10760. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  10761. // console.log(123401, arguments);
  10762. // return this.handleServiceRequest717_(a, b, c, d);
  10763. // }
  10764.  
  10765. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10766.  
  10767. // cProto.handleServiceRequest_ = function(a,b,c,d){
  10768. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10769. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  10770. // console.log('mfv', c.continuation);
  10771. // mfv.add( c.continuation);
  10772. // }
  10773. // return this.handleServiceRequest717_(a,b,c,d);
  10774. // }
  10775.  
  10776. function extraArguments322(a, b, c) {
  10777. let is = (a || 0).is;
  10778. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  10779. let continuation = (c || 0).continuation;
  10780. if (typeof is !== 'string') is = null;
  10781. if (typeof videoId !== 'string') videoId = null;
  10782. if (typeof continuation !== 'string') continuation = null;
  10783. return { is, videoId, continuation };
  10784. }
  10785.  
  10786. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  10787. cProto.sendServiceAjax_ = function (a, b, c, d) {
  10788.  
  10789. // console.log(8001)
  10790. try {
  10791.  
  10792. const { is, videoId, continuation } = extraArguments322(a, b, c);
  10793.  
  10794. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10795. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  10796. }
  10797.  
  10798. if (pageSetupVideoId && videoId && continuation) {
  10799. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10800. mfyContinuationIgnored.removeAdd(continuation);
  10801. mfvContinuationRecorded.delete(continuation);
  10802. return;
  10803. }
  10804. }
  10805.  
  10806. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10807. copyPreviousContiuationToIgnored374(false);
  10808. mfyContinuationIgnored.delete(continuation);
  10809. mfvContinuationRecorded.removeAdd(continuation);
  10810. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10811. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10812. mjtLockPreviousKey = '';
  10813. }
  10814. // if (mjtNextMainKey === continuation) {
  10815. // copyPreviousContiuationToIgnored(false);
  10816. // mfyContinuationIgnored.delete(continuation);
  10817. // mfvContinuationRecorded.add(continuation);
  10818. // }
  10819.  
  10820.  
  10821. if (mfyContinuationIgnored && continuation) {
  10822. if (mfyContinuationIgnored.has(continuation)) {
  10823. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  10824. return;
  10825. }
  10826. }
  10827.  
  10828. // console.log(59902, a?.is, b,c,d)
  10829. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10830. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  10831. // console.log('mfv377', continuation);
  10832. mfvContinuationRecorded.add(continuation);
  10833. }
  10834.  
  10835. // if (videoId) {
  10836. // if (!pageSetupVideoId) return; // ignore page not ready
  10837. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10838. // if (videoId !== pageSetupVideoId) {
  10839. // return;
  10840. // }
  10841. // }
  10842.  
  10843. } catch (e) {
  10844. console.log('Coding Error in sendServiceAjax_', e)
  10845. }
  10846. // console.log(8002)
  10847. // console.log(123402, arguments);
  10848. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  10849.  
  10850. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  10851. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  10852. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  10853. // get(target, prop, receiver){
  10854. // console.log('xxs99', target.videoId, mtx)
  10855. // if(prop ==='kdkw33') return 1;
  10856. // console.log(3322, prop, target)
  10857. // if(prop === 'initialDelayMs') {
  10858. // throw new Error("ABCC");
  10859. // }
  10860. // return target[prop];
  10861. // },
  10862. // set(target, prop, value, receiver){
  10863.  
  10864. // if(prop ==='kdkw33') return true;
  10865. // target[prop]=value;
  10866. // return true;
  10867. // }
  10868. // });
  10869. // }
  10870. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  10871. return this.sendServiceAjax717_(a, b, c, d);
  10872. }
  10873. }
  10874.  
  10875. function delayClearOtherKeys(lztContinuation) {
  10876. // // schedule delayed removal if mfyContinuationIgnored is not empty
  10877. // getRafPromise().then(() => {
  10878. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  10879. // // foreground page only
  10880.  
  10881. // });
  10882.  
  10883.  
  10884. if (lztContinuation !== mtzlastAllowedContinuation) return;
  10885. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  10886. if (!mfyContinuationIgnored.size) return;
  10887. if (mfyContinuationIgnored.size > 1) {
  10888. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  10889. }
  10890. mfyContinuationIgnored.forEach((value, key) => {
  10891. if (key !== lztContinuation) {
  10892. mfyContinuationIgnored.delete(key);
  10893. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  10894. }
  10895. });
  10896.  
  10897. }
  10898. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  10899. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  10900. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  10901.  
  10902. // console.log(8003)
  10903. try {
  10904.  
  10905.  
  10906. const { is, videoId, continuation } = extraArguments322(b, c, d);
  10907.  
  10908. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10909. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  10910. }
  10911.  
  10912. if (pageSetupVideoId && videoId && continuation) {
  10913. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10914. mfyContinuationIgnored.removeAdd(continuation);
  10915. mfvContinuationRecorded.delete(continuation);
  10916. return;
  10917. }
  10918. }
  10919.  
  10920. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10921. copyPreviousContiuationToIgnored374(false);
  10922. mfyContinuationIgnored.delete(continuation);
  10923. mfvContinuationRecorded.removeAdd(continuation);
  10924. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10925. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10926. mjtLockPreviousKey = '';
  10927. }
  10928.  
  10929. // if (mjtNextMainKey === continuation) {
  10930. // copyPreviousContiuationToIgnored(false);
  10931. // mfyContinuationIgnored.delete(continuation);
  10932. // mfvContinuationRecorded.add(continuation);
  10933. // }
  10934.  
  10935. const lztContinuation = continuation;
  10936.  
  10937. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  10938. if (mfyContinuationIgnored.has(lztContinuation)) {
  10939. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  10940. return;
  10941. }
  10942. }
  10943.  
  10944. // if (videoId) {
  10945. // if (!pageSetupVideoId) return; // ignore page not ready
  10946. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10947. // if (videoId !== pageSetupVideoId) {
  10948. // return;
  10949. // }
  10950. // }
  10951.  
  10952. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  10953. mtzlastAllowedContinuation = lztContinuation;
  10954. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  10955.  
  10956. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  10957. mjtRecordedPrevKey = lztContinuation;
  10958. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  10959. // if (mfyContinuationIgnored.size > 0) {
  10960. // delayClearOtherKeys(lztContinuation);
  10961. // }
  10962. mtzCount = 0;
  10963. // allowNoDelay322 = false;
  10964. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  10965. // repeated
  10966. if (++mtzCount > 1e9) mtzCount = 1e4;
  10967. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  10968.  
  10969. // if (mtzCount >= 3) allowNoDelay322 = true;
  10970. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  10971. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  10972. }
  10973. if (mtzCount === 5) {
  10974. mfvContinuationRecorded.clear();
  10975. mfvContinuationRecorded.add(lztContinuation);
  10976. }
  10977.  
  10978. }
  10979.  
  10980. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  10981. mpKey22 = lztContinuation;
  10982. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  10983. }
  10984.  
  10985. if (mbCId322) {
  10986. clearTimeout(mbCId322);
  10987. mbCId322 = 0;
  10988. }
  10989. } catch (e) {
  10990. console.log('Coding Error in getCancellableNetworkPromise_', e)
  10991. }
  10992.  
  10993. // console.log(8004)
  10994. // console.log(123403, arguments);
  10995. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  10996.  
  10997. // console.log(5163, a?.is,b,c,d,e);
  10998. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  10999. }
  11000. }
  11001. });
  11002.  
  11003. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11004.  
  11005.  
  11006. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  11007.  
  11008. let dummy;
  11009. let cProto;
  11010.  
  11011. dummy = document.createElement('ytd-expander');
  11012. cProto = insp(dummy).constructor.prototype;
  11013.  
  11014. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  11015.  
  11016. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  11017. cProto.childrenChanged14 = cProto.childrenChanged;
  11018.  
  11019. cProto.initChildrenObserver = function () {
  11020. var a = this;
  11021. this.observer = new MutationObserver(function () {
  11022. a.childrenChanged()
  11023. }
  11024. );
  11025. this.observer.observe(this.content, {
  11026. subtree: !0,
  11027. childList: !0,
  11028. attributes: !0,
  11029. characterData: !0
  11030. });
  11031. this.childrenChanged()
  11032. }
  11033. ;
  11034. cProto.childrenChanged = function () {
  11035. if (this.alwaysToggleable) {
  11036. this.canToggle = this.alwaysToggleable;
  11037. } else if (!this.canToggleJobId) {
  11038. this.canToggleJobId = 1;
  11039. foregroundPromiseFn().then(() => {
  11040. this.canToggleJobId = 0;
  11041. this.calculateCanCollapse()
  11042. })
  11043. }
  11044. }
  11045.  
  11046. // console.log(cProto.initChildrenObserver)
  11047. console.debug('ytd-expander-fix-childrenChanged');
  11048.  
  11049. }
  11050.  
  11051. });
  11052.  
  11053.  
  11054. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  11055.  
  11056. let dummy;
  11057. let cProto;
  11058. dummy = document.createElement('paper-ripple');
  11059. cProto = insp(dummy).constructor.prototype;
  11060.  
  11061. if (fnIntegrity(cProto.animate, '0.74.5')) {
  11062.  
  11063.  
  11064. cProto.animate34 = cProto.animate;
  11065. cProto.animate = function () {
  11066. if (this._animating) {
  11067. var a;
  11068. const ripples = this.ripples;
  11069. for (a = 0; a < ripples.length; ++a) {
  11070. var b = ripples[a];
  11071. b.draw();
  11072. this.$.background.style.opacity = b.outerOpacity;
  11073. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  11074. }
  11075. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  11076. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  11077. foregroundPromiseFn().then(this._boundAnimate38);
  11078. } else {
  11079. this.onAnimationComplete();
  11080. }
  11081. }
  11082. }
  11083.  
  11084. console.debug('FIX_paper_ripple_animate')
  11085.  
  11086. // console.log(cProto.animate)
  11087.  
  11088. }
  11089.  
  11090. });
  11091.  
  11092. if (FIX_doIdomRender) {
  11093.  
  11094. const xsetTimeout = function (f, d) {
  11095. if (xsetTimeout.m511 === 1 && !d) {
  11096. xsetTimeout.m511 = 2;
  11097. xsetTimeout.m568 = f;
  11098. } else {
  11099. return setTimeout.apply(window, arguments)
  11100. }
  11101.  
  11102. }
  11103.  
  11104. /**
  11105. *
  11106. IGb = function(a) {
  11107. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  11108. c || (a.requestAninmationFrameResolver = new Vi,
  11109. c = a.requestAninmationFrameResolver.promise,
  11110. Da.requestAnimationFrame(function() {
  11111. var d;
  11112. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  11113. a.requestAninmationFrameResolver = null
  11114. }));
  11115. return c
  11116. }
  11117.  
  11118.  
  11119. */
  11120.  
  11121. const xrequestAnimationFrame = function (f) {
  11122. const h = `${f}`;
  11123. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  11124. let t = null;
  11125. xsetTimeout.m511 = 1;
  11126. f();
  11127. if (xsetTimeout.m511 === 2) {
  11128. t = xsetTimeout.m568;
  11129. xsetTimeout.m568 = null;
  11130. }
  11131. xsetTimeout.m511 = 0;
  11132. if (typeof t === 'function') {
  11133. foregroundPromiseFn().then(t);
  11134. }
  11135. } else if (h.includes("requestAninmationFrameResolver")) {
  11136. foregroundPromiseFn().then(f);
  11137. } else {
  11138. return requestAnimationFrame.apply(window, arguments);
  11139. }
  11140. }
  11141.  
  11142. let busy = false;
  11143. const doIdomRender = function () {
  11144.  
  11145. if (!this) return;
  11146. if (busy) {
  11147. return this.doIdomRender13(...arguments);
  11148. }
  11149. busy = true;
  11150. const { requestAnimationFrame, setTimeout } = window;
  11151. window.requestAnimationFrame = xrequestAnimationFrame;
  11152. window.setTimeout = xsetTimeout;
  11153. let r = this.doIdomRender13(...arguments);
  11154. window.requestAnimationFrame = requestAnimationFrame;
  11155. window.setTimeout = setTimeout;
  11156. busy = false;
  11157. return r;
  11158. };
  11159. 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']) {
  11160.  
  11161.  
  11162. whenCEDefined(ytTag).then(() => {
  11163.  
  11164. let dummy;
  11165. let cProto;
  11166. dummy = document.createElement(ytTag);
  11167. cProto = insp(dummy).constructor.prototype;
  11168.  
  11169. cProto.doIdomRender13 = cProto.doIdomRender;
  11170. cProto.doIdomRender = doIdomRender;
  11171.  
  11172. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  11173.  
  11174. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  11175.  
  11176.  
  11177.  
  11178. });
  11179.  
  11180. }
  11181.  
  11182. }
  11183.  
  11184.  
  11185.  
  11186.  
  11187. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  11188.  
  11189. const sMap = new Map();
  11190.  
  11191. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  11192. const ZT = function () {
  11193. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  11194. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  11195. c = b & 15,
  11196. b >>= 4,
  11197. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  11198. return a.join("")
  11199. };
  11200.  
  11201.  
  11202. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  11203.  
  11204. const popupContainer = await observablePromise(() => {
  11205. return popupContainerCollection[0];
  11206. }).obtain();
  11207.  
  11208.  
  11209. let cProto;
  11210. cProto = insp(popupContainer).constructor.prototype;
  11211.  
  11212.  
  11213. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  11214. console.log('FIX_POPUP_UNIQUE_ID NG')
  11215. return;
  11216. }
  11217. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  11218.  
  11219. cProto.handleOpenPopupAction = function (a, b) {
  11220.  
  11221. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  11222.  
  11223. a.__jOdQA__ = true;
  11224.  
  11225. try {
  11226.  
  11227. const h = this.hostElement;
  11228.  
  11229. if (h instanceof HTMLElement_) {
  11230.  
  11231. const map = h.__skme44__ = h.__skme44__ || new Map();
  11232.  
  11233. let mKey = '';
  11234. const wKey = firstObjectKey(a);
  11235. const wObj = wKey ? a[wKey] : null;
  11236. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  11237. const pKey = firstObjectKey(wObj.popup)
  11238. const pObj = pKey ? wObj.popup[pKey] : null;
  11239. let contentKey = '';
  11240. let headerKey = '';
  11241.  
  11242. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  11243. contentKey = firstObjectKey(pObj.content)
  11244. headerKey = firstObjectKey(pObj.header)
  11245. }
  11246. if (contentKey && headerKey) {
  11247.  
  11248. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  11249.  
  11250. if (mKey) {
  11251.  
  11252. if (!wObj.uniqueId) {
  11253. for (let i = 0; i < 8; i++) {
  11254. wObj.uniqueId = ZT();
  11255. if (!sMap.has(wObj.uniqueId)) break;
  11256. }
  11257. }
  11258. const oId = wObj.uniqueId
  11259.  
  11260. let nId_ = map.get(mKey);
  11261. if (!nId_) {
  11262. map.set(mKey, nId_ = oId);
  11263. }
  11264.  
  11265. wObj.uniqueId = nId_ || wObj.uniqueId;
  11266.  
  11267. const nId = wObj.uniqueId
  11268.  
  11269. sMap.set(oId, nId);
  11270. sMap.set(nId, nId);
  11271.  
  11272. wObj.uniqueId = nId;
  11273. pObj.targetId = nId;
  11274. pObj.identifier.tag = nId;
  11275.  
  11276. if (oId !== nId) {
  11277. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  11278. }
  11279.  
  11280. }
  11281.  
  11282. }
  11283. }
  11284.  
  11285. // console.log(12213, mKey, a, b, h)
  11286.  
  11287. }
  11288.  
  11289. } catch (e) {
  11290. console.warn(e)
  11291. }
  11292.  
  11293. try {
  11294.  
  11295. const results = searchNestedObject(a, (x) => {
  11296. if (typeof x === 'string' && x.length === 36) {
  11297. 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;
  11298. }
  11299. return false;
  11300. });
  11301. for (const [obj, key] of results) {
  11302. const oId = obj[key];
  11303. const nId = sMap.get(oId);
  11304. if (nId) obj[key] = nId;
  11305. }
  11306. } catch (e) {
  11307. console.warn(e)
  11308. }
  11309.  
  11310.  
  11311. }
  11312.  
  11313. return this.handleOpenPopupAction3868(...arguments)
  11314. }
  11315.  
  11316. console.log('FIX_POPUP_UNIQUE_ID OK')
  11317.  
  11318.  
  11319. });
  11320.  
  11321.  
  11322. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  11323.  
  11324. let dummy;
  11325. let cProto;
  11326. dummy = document.createElement('yt-formatted-string');
  11327. cProto = insp(dummy).constructor.prototype;
  11328.  
  11329. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  11330. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  11331. return;
  11332. }
  11333.  
  11334. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  11335. cProto.setNodeStyle_ = function (a, b) {
  11336. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  11337. return this.setNodeStyle17_(a, b);
  11338. }
  11339.  
  11340. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  11341. });
  11342.  
  11343. });
  11344.  
  11345. });
  11346.  
  11347.  
  11348.  
  11349.  
  11350. if (isMainWindow) {
  11351.  
  11352. console.groupCollapsed(
  11353. "%cYouTube JS Engine Tamer",
  11354. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  11355. );
  11356.  
  11357.  
  11358.  
  11359. console.log("Script is loaded.");
  11360. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  11361.  
  11362. console.log("This script is experimental and subject to further changes.");
  11363.  
  11364. console.log("This might boost your YouTube performance.");
  11365.  
  11366. console.log("CAUTION: This might break your YouTube.");
  11367.  
  11368.  
  11369. if (prepareLogs.length >= 1) {
  11370. console.log(" =========================================================================== ");
  11371.  
  11372. for (const msg of prepareLogs) {
  11373. console.log(msg)
  11374. }
  11375.  
  11376. console.log(" =========================================================================== ");
  11377. }
  11378.  
  11379. console.groupEnd();
  11380.  
  11381. }
  11382.  
  11383.  
  11384.  
  11385. })();