YouTube JS Engine Tamer

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

  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.42.0
  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 HOOK_ACTIVE_MODULES = true; // added in 0.37.0
  35. const HOOK_ACTIVE_MODULES_fetchUpdatedMetadata = true; // added in 0.37.0 (make likeCount update)
  36. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  37. const FIX_schedulerInstanceInstance = 2 | 4;
  38. const FIX_yt_player = true; // DONT CHANGE
  39. const FIX_Animation_n_timeline = true;
  40. const FIX_Animation_n_timeline_cinematic = true;
  41. const FIX_ytScheduler = true;
  42. const NO_PRELOAD_GENERATE_204 = false;
  43. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  44. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  45. const CHANGE_appendChild = true; // discussions#236759
  46. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  47.  
  48. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  49.  
  50. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  51.  
  52. const FIX_ytdExpander_childrenChanged = true;
  53. const FIX_paper_ripple_animate = true;
  54. const FIX_avoid_incorrect_video_meta = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  55. const FIX_avoid_incorrect_video_meta_emitterBehavior = true; // [legacy feature for rolling number fixing] 2025.05.10 - obsoleted -> y.fetchUpdatedMetadata(t, e.continuation)
  56.  
  57. const FIX_doIdomRender = true;
  58.  
  59. const FIX_Shady = true;
  60.  
  61. // [[ 2024.04.24 ]]
  62. const MODIFY_ShadyDOM_OBJ = true; // DON'T CHANGE. MUST BE TRUE
  63. // << if MODIFY_ShadyDOM_OBJ >>
  64. const WEAKREF_ShadyDOM = true;
  65. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  66. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  67. // << end >>
  68.  
  69. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  70.  
  71. const FIX_ytAction_ = true; // ytd-app
  72. const FIX_onVideoDataChange = false;
  73. // const FIX_onClick = true;
  74. const FIX_onStateChange = true;
  75. const FIX_onLoopRangeChange = true;
  76. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  77. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  78.  
  79. const FIX_stampDomArray_ = true; // v0.30.0
  80. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  81. // const stampDomArray_MemoryFix_Flag001 = false;
  82. const XFlag = true; // root issue tbc
  83. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  84. // 32 required for new stampDomArray
  85. // 128 to be tested
  86.  
  87. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  88. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  89.  
  90. const FIX_Polymer_dom = true;
  91. const FIX_Polymer_AF = true;
  92.  
  93. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  94. const DEBUG_removePrune = false; // true for DEBUG
  95.  
  96. const FIX_XHR_REQUESTING = true;
  97.  
  98. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  99.  
  100. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  101.  
  102. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  103. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  104.  
  105. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  106.  
  107. const FIX_removeChild = true;
  108. const FIX_fix_requestIdleCallback_timing = true;
  109.  
  110. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  111. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  112.  
  113. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  114.  
  115. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  116.  
  117. // ------------------------------------------------------------------
  118.  
  119. const MEMORY_RELEASE_NF00 = true;
  120. const MEMORY_RELEASE_NF00_SHOW_MESSAGE = false;
  121. const MEMORY_RELEASE_MAP_SET_REMOVE_NODE = true;
  122. const FULLY_REMOVE_ALL_EVENT_LISTENERS = true; // require MEMORY_RELEASE_NF00
  123. const FUZZY_EVENT_LISTENER_REMOVAL = true;
  124. const WEAK_CE_ROOT = true; // shadowRoot of the return value of attachShadow on the node
  125.  
  126. const FIX_TEMPLATE_BINDING = true;
  127. const FIX_TEMPLATE_BINDING_SHOW_MESSAGE = false;
  128.  
  129. const FIX_SHADY_METHODS = true;
  130. const FIX_FRAGEMENT_HOST = true;
  131.  
  132. const USE_fastDomIf = 2; // fastDomIf is seem to be experimental 0 = no change, 1 = enable, 2 = disable
  133. const ENHANCE_DOMIF_createAndInsertInstance = true; // root does not need to store in the instance
  134. const ENHANCE_DOMIF_TEARDOWN = true; // require MEMORY_RELEASE_NF00
  135.  
  136. const FIX_DOM_IF_DETACH = true;
  137. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  138. const FIX_DOM_IF_TEMPLATE = true;
  139. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  140.  
  141. const DEBUG_DBR847 = false;
  142. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  143.  
  144. const FIX_ICON_RENDER = true;
  145. const FIX_GUIDE_ICON = true;
  146. const FIX_ACTIONS_TOOLTIPS = true;
  147.  
  148. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  149.  
  150. const DISABLE_isLowLatencyLiveStream = false; // TBC
  151.  
  152. const FIX_FlexibleItemSizing = true;
  153. const FIX_ROLLING_NUMBER_UPDATE = true;
  154.  
  155.  
  156. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  157. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  158. // first tp-yt-paper-dialog: show once the page is loaded.
  159. // second tp-yt-paper-dialog: click "...more"
  160. // third tp-yt-paper-dialog: click "... and 3 more links"
  161. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  162. // currently, uniqueId is preassigned by the network resolveCommand.
  163. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  164. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  165.  
  166. // handleOpenPopupAction -> createCacheKey
  167. // handleClosePopupAction_ -> createCacheKey
  168. // handleGetPopupOpenedAction_ -> createCacheKey
  169. // getAndMaybeCreatePopup_ -> createCacheKey
  170. // closePopup -> createCacheKey
  171.  
  172. // yt-close-popup-command -> handleClosePopupCommand_
  173.  
  174. // ensurePopup_ -> getAndMaybeCreatePopup_
  175.  
  176. // yt-close-popup-action -> handleClosePopupAction_
  177. // closePopup -> handleClosePopupAction_
  178. // handleOpenPopupAction -> handleClosePopupAction_
  179. // handleClosePopupCommand_ -> handleClosePopupAction_
  180. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  181.  
  182. // yt-open-popup-action -> handleOpenPopupAction
  183.  
  184.  
  185. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  186. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  187.  
  188. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  189. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  190. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  191.  
  192.  
  193. const PROP_OverReInclusion_AVOID = true;
  194. const PROP_OverReInclusion_DEBUGLOG = false;
  195. const PROP_OverReInclusion_LIST = new Set([
  196. 'hostElement72',
  197. 'parentComponent72',
  198. 'localVisibilityObserver_72',
  199. 'cachedProviderNode_72',
  200. '__template72',
  201. '__templatizeOwner72',
  202. '__templateInfo72',
  203. '__dataHost72',
  204. '__CE_shadowRoot72',
  205. 'elements_72',
  206.  
  207. 'ky36',
  208. 'kz62',
  209. 'm822',
  210.  
  211.  
  212.  
  213. // To be reviewed.
  214.  
  215. // chat messages
  216. 'disabled', 'allowedProps',
  217. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  218.  
  219. 'dimension', 'loadTime', 'pendingPaint',
  220.  
  221. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  222.  
  223. 'respectLangDir', 'noEndpoints',
  224.  
  225.  
  226. 'objectURL',
  227. 'buttonOverrides', 'queuedMessages',
  228. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  229. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  230. 'hoverJobId', 'JSC$14573_touched',
  231.  
  232.  
  233. // tbc
  234. 'toggleable', 'isConnected',
  235. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  236. 'disableDeselectEvent',
  237. 'emojiSize',
  238.  
  239. 'buttonOverride',
  240. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  241.  
  242. // others
  243. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  244. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  245. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  246. // 'dimension', 'loadTime', 'pendingPaint',
  247. // 'disabled', 'allowedProps',
  248.  
  249.  
  250. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  251. // 'actionMap',
  252.  
  253. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  254.  
  255. 'clearTimeout',
  256. 'switchTemplateAtRegistration', 'hasUnmounted',
  257. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  258. 'tangoConfiguration',
  259. 'itemIdToDockDurationMap',
  260. 'actionMap',
  261.  
  262. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  263. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  264. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  265.  
  266. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  267. // 'stopKeyboardEventPropagation', 'emojiSize',
  268. // 'switchTemplateAtRegistration', 'hasUnmounted',
  269. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  270. // 'isReusable', 'tangoConfiguration',
  271. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  272. // */
  273.  
  274. ]);
  275.  
  276.  
  277. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  278.  
  279. // ----------------------------- Shortkey Keyboard Control -----------------------------
  280.  
  281. /*
  282. window.addEventListener('edm',()=>{
  283. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  284. });
  285.  
  286. window.addEventListener('edn',()=>{
  287. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  288. });
  289. window.addEventListener('edr',()=>{
  290. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  291. });
  292. */
  293.  
  294. // only for macOS with Chrome/Firefox 100+
  295. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  296.  
  297. const win = this instanceof Window ? this : window;
  298.  
  299. // Create a unique key for the script and check if it is already running
  300. const hkey_script = 'jswylcojvzts';
  301. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  302. win[hkey_script] = true;
  303.  
  304.  
  305.  
  306. const wk = Symbol();
  307.  
  308. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  309.  
  310. let BY_PASS_KEYBOARD_CONTROL = false;
  311.  
  312.  
  313. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  314. /** @type {(f: ()=>{})=>{}} */
  315. const nextBrowserTick_ = nextBrowserTick;
  316. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  317. console.log('nextBrowserTick is not found.');
  318. return;
  319. }
  320.  
  321. let p59 = 0;
  322.  
  323. const Promise = (async () => { })().constructor;
  324.  
  325. const PromiseExternal = ((resolve_, reject_) => {
  326. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  327. return class PromiseExternal extends Promise {
  328. constructor(cb = h) {
  329. super(cb);
  330. if (cb === h) {
  331. /** @type {(value: any) => void} */
  332. this.resolve = resolve_;
  333. /** @type {(reason?: any) => void} */
  334. this.reject = reject_;
  335. }
  336. }
  337. };
  338. })();
  339.  
  340. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  341. constructor(callback = undefined) {
  342.  
  343. }
  344. register(target, heldValue, unregisterToken = undefined) {
  345.  
  346. }
  347. unregister(unregisterToken) {
  348.  
  349. }
  350. }
  351.  
  352. let ttpHTML = (s) => {
  353. ttpHTML = s => s;
  354. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  355. let s = s => s;
  356. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  357. }
  358. return s;
  359. }
  360.  
  361.  
  362. /** @type { typeof HTMLElement } */
  363. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  364. const nativeAppendE = HTMLElement_.prototype.append;
  365. const nativeRemoveE = HTMLElement_.prototype.remove;
  366. const DocumentFragment_ = DocumentFragment;
  367. const nativeAppendD = DocumentFragment_.prototype.append;
  368. const Node_ = Node;
  369.  
  370. /**
  371. @param {number} x
  372. @param {number} d */
  373. const toFixed2 = (x, d) => {
  374. let t = x.toFixed(d);
  375. let y = `${+t}`;
  376. return y.length > t.length ? t : y;
  377. }
  378.  
  379.  
  380. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  381.  
  382.  
  383. const TRANSLATE_DEBUG = false;
  384.  
  385.  
  386. let xdeadc00 = null; // a deteched node with __domApi
  387. let xlivec00 = null; // a deteched node with __domApi
  388.  
  389. let removeTNodeRM = null;
  390. let removeTNodeBP = false;
  391.  
  392.  
  393. if (Node.isConnectedOverrided === undefined) {
  394. const pdConnected = Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected');
  395. if (pdConnected && pdConnected.get && pdConnected.configurable) {
  396. Node.isConnectedOverrided = null;
  397. const get_ = pdConnected.get;
  398. const get = function () {
  399. const overrided = Node.isConnectedOverrided;
  400. if (typeof overrided === 'boolean') return overrided;
  401. return get_.call(this);
  402. }
  403. Object.defineProperty(Node.prototype, 'isConnected', {
  404. ...pdConnected,
  405. get
  406. });
  407. }
  408. }
  409.  
  410. const _nmSet = new Set();
  411. _nmSet.add = _nmSet.addOriginal || _nmSet.add;
  412. const _nmMap = new Set();
  413. _nmMap.add = _nmMap.addOriginal || _nmMap.add;
  414. const _nmMapV = new Set();
  415. _nmMapV.add = _nmMapV.addOriginal || _nmMapV.add;
  416. if (MEMORY_RELEASE_MAP_SET_REMOVE_NODE && !Set.prototype.addOriginal && !Map.prototype.setOriginal) {
  417. const Node_ = Node;
  418. Set.prototype.addOriginal = Set.prototype.add;
  419. Set.prototype.add = function (n) {
  420. if (n instanceof Node_) {
  421. if (!this[wk]) this[wk] = mWeakRef(this);
  422. _nmSet.add(this[wk]);
  423. }
  424. return this.addOriginal(n);
  425. };
  426. Map.prototype.setOriginal = Map.prototype.set;
  427. Map.prototype.set = function (n, v) {
  428. if (n instanceof Node_) {
  429. if (!this[wk]) this[wk] = mWeakRef(this);
  430. _nmMap.add(this[wk]);
  431. }
  432. if (v instanceof Node_) {
  433. if (!this[wk]) this[wk] = mWeakRef(this);
  434. _nmMapV.add(this[wk]);
  435. }
  436. return this.setOriginal(n, v);
  437. };
  438. }
  439.  
  440. window.showNM00 = () => {
  441. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  442. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  443. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  444. return { nmSet, nmMap, nmMapV };
  445. };
  446.  
  447. window.testNM00 = (x) => {
  448. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  449. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  450. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  451. for (const s of nmSet) if (s.has(x)) return 1;
  452. for (const m of nmMap) if (m.has(x)) return 2;
  453. for (const m of nmMapV) {
  454. for (const [u, v] of m.entries()) {
  455. if (v === x) return 4;
  456. }
  457. }
  458. return 0;
  459. };
  460.  
  461. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  462.  
  463. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  464.  
  465. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  466.  
  467. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  468.  
  469. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  470. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  471. return;
  472. }
  473.  
  474. const mapGet = Map.prototype.get;
  475. const setHas = Set.prototype.has;
  476.  
  477. /** @type {Map | null} */
  478. let qcMap = null;
  479.  
  480. Set.prototype.has = function (a) {
  481. if (a === 'dummy-4718') return false; // false to allow re-use?
  482. return setHas.call(this, a);
  483. }
  484.  
  485. Map.prototype.get = function (a) {
  486. if (a === 'dummy-4718') qcMap = this;
  487. return mapGet.call(this, a);
  488. };
  489. let r;
  490. try {
  491. r = mainCnt.createComponent_('dummy-4718', {}, true);
  492. } catch (e) {
  493.  
  494. }
  495.  
  496. Map.prototype.get = mapGet;
  497. Set.prototype.has = setHas;
  498.  
  499. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  500.  
  501.  
  502. // clearInterval(ckId);
  503. // ckId = 0;
  504.  
  505. if (qcMap !== null && qcMap instanceof Map) {
  506.  
  507. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  508. qcMap.__qcMap8781__ = true;
  509.  
  510. const setArrayC = (c) => {
  511. if (c instanceof Array) {
  512. c.length = 0;
  513. c.push = function () { };
  514. c.pop = function () { };
  515. c.shift = function () { };
  516. c.unshift = function () { };
  517. c.splice = function () { };
  518. c.sort = function () { };
  519. c.reverse = function () { };
  520. }
  521. }
  522.  
  523. const cleaning = function (m) {
  524. m.forEach(setArrayC);
  525. m.clear();
  526. }
  527.  
  528. qcMap.set = function (b, c) {
  529. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  530.  
  531. setArrayC(c);
  532.  
  533. // console.log('qcMap.set', b, c);
  534.  
  535. if (this.size > 0) {
  536. // play safe
  537.  
  538. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  539. cleaning(this);
  540. }
  541.  
  542. }
  543. qcMap.get = function (b) {
  544. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  545.  
  546. // console.log('qcMap.get', b);
  547.  
  548. if (this.size > 0) {
  549. // play safe
  550.  
  551. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  552. cleaning(this);
  553. }
  554.  
  555. }
  556.  
  557.  
  558. if (qcMap.size > 0) {
  559.  
  560. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  561. cleaning(qcMap);
  562. }
  563.  
  564. }
  565.  
  566. }
  567.  
  568. r = null;
  569. qcMap = null;
  570.  
  571. }
  572.  
  573. const renderPathMake = (elements) => {
  574. if(!elements) return;
  575. if (!elements.length) elements = [elements];
  576. const s = new Set();
  577. s.add = s.addOriginal || s.add;
  578. for (const element of elements) {
  579. if (element && element.nodeType >= 1) {
  580. s.add(element);
  581. if (element.querySelectorAll) {
  582. for (const e of element.querySelectorAll('*')) {
  583. s.add(e);
  584. }
  585. }
  586. }
  587. }
  588. const y = [...s];
  589. s.clear();
  590.  
  591. const f = (elm) => {
  592. let x = elm.nodeName.toLowerCase();
  593. let y = elm.id;
  594. return y ? `${x}#${y}` : `${x}`;
  595. }
  596. for (const element of y) {
  597. if (element && (element.nodeType >= 1) && !element.__renderPath522__) {
  598. let t = element;
  599. let w = [f(t)];
  600. if (!element.is) {
  601. while (t = t.parentNode) {
  602. w.unshift(f(t))
  603. if (t.is) break;
  604. }
  605. }
  606. element.__renderPath522__ = w.join('/');
  607. }
  608. }
  609. }
  610.  
  611.  
  612. const dispatchYtEvent = function (a, b, c, d) {
  613. d || (d = {
  614. bubbles: !0,
  615. cancelable: !1,
  616. composed: !0
  617. });
  618. c !== null && c !== void 0 && (d.detail = c);
  619. b = new CustomEvent(b, d);
  620. a.dispatchEvent(b);
  621. return b
  622. };
  623.  
  624. if (DISABLE_isLowLatencyLiveStream) {
  625. const sm = Symbol();
  626. const f = () => {
  627. try {
  628. const videoDetails = ytInitialPlayerResponse.videoDetails;
  629. if (videoDetails && videoDetails.isLowLatencyLiveStream) {
  630. videoDetails.isLowLatencyLiveStream = false;
  631. }
  632. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW') {
  633. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  634. }
  635. if (videoDetails && videoDetails.latencyClass === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  636. videoDetails.latencyClass = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  637. }
  638. } catch (e) { }
  639. }
  640. Object.defineProperty(Object.prototype, 'isLowLatencyLiveStream', {
  641. get() {
  642. const v = this[sm];
  643. if (typeof v === 'undefined') return v;
  644. f();
  645. return v;
  646. },
  647. set(nv) {
  648. f();
  649. if (nv === true) nv = false;
  650. this[sm] = nv;
  651. },
  652. enumerable: false,
  653. configurable: true
  654. });
  655.  
  656. const sm3 = Symbol();
  657. Object.defineProperty(Object.prototype, 'latencyClass', {
  658. get() {
  659. const v = this[sm3];
  660. if (typeof v === 'undefined') return v;
  661. f();
  662. return v;
  663. },
  664. set(nv) {
  665. f();
  666. if (nv === 'ULTRALOW' || nv === 'LOW') {
  667. nv = 'NORMAL';
  668. } else if (nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_LOW' || nv === 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_ULTRA_LOW') {
  669. nv = 'MDE_STREAM_OPTIMIZATIONS_RENDERER_LATENCY_NORMAL';
  670. }
  671. this[sm3] = nv;
  672. },
  673. enumerable: false,
  674. configurable: true
  675. });
  676.  
  677. }
  678.  
  679. class PlainHTMLElement extends HTMLTitleElement {
  680.  
  681. }
  682.  
  683. const removeShady = function (shady) {
  684. if (!shady || typeof shady !== 'object') return;
  685. const props = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  686. for (const prop of props) {
  687. const node = shady[prop];
  688. if (typeof (node || 0) !== 'object') continue;
  689. if (node.nodeType >= 1 && node.isConnected === false) _removedElements.addNode(node);
  690. }
  691. }
  692.  
  693. const shadys = new Set();
  694. shadys.add = shadys.addOriginal || shadys.add;
  695.  
  696. window.showShadys00 = ()=>[...shadys].map(e=>kRef(e));
  697.  
  698. const _removedElements = new Set();
  699. _removedElements.add = _removedElements.addOriginal || _removedElements.add;
  700. _removedElements.addNode_ = MEMORY_RELEASE_NF00 ? function (node) {
  701. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  702. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  703. if (!node[wk]) node[wk] = mWeakRef(node);
  704. return this.add(node[wk]);
  705. }
  706. } : () => { };
  707.  
  708. _removedElements.addNode = MEMORY_RELEASE_NF00 ? (node) => {
  709. if (!node || node.__keepInstance038__ || node.t792 || node instanceof HTMLTitleElement || node.nodeName === 'defs' || node.nodeName === 'TITLE') return;
  710. if (node && node.nodeType >= 1 && node.nodeType !== 9) {
  711. try {
  712. const rootNode = node.getRootNode();
  713. if (rootNode && rootNode !== node) {
  714. if (rootNode.nodeType >= 1 && rootNode.nodeType !== 9) _removedElements.addNode_(rootNode);
  715. }
  716. } catch (e) { }
  717. _removedElements.addNode_(node);
  718. }
  719. } : () => { };
  720.  
  721. if (WEAK_CE_ROOT) {
  722. Object.defineProperty(Object.prototype, '__CE_shadowRoot', {
  723. get() {
  724. return kRef(this.__CE_shadowRoot366);
  725. },
  726. set(nv) {
  727. if (typeof nv !== 'object') { // null is okay
  728. if (this.__CE_shadowRoot366) this.__CE_shadowRoot366 = null;
  729. return false;
  730. }
  731. if (!nv || typeof nv !== 'object') {
  732. this.__CE_shadowRoot366 = nv;
  733. } else {
  734. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  735. this.__CE_shadowRoot366 = nv[wk];
  736. }
  737. return true;
  738. }
  739. });
  740. }
  741.  
  742. const _emptyElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  743. const _emptyTipsElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  744. const _emptyVisibilityElement = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  745. // const _emptyShady = new (class EmptyShady { });
  746.  
  747. const nf00 = new FinalizationRegistry_((x) => {
  748. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: node[${x}] fully removed`);
  749. });
  750. let ud00 = 0;
  751. const ng00 = new Set();
  752. nf00.registerNode = function (node) {
  753. if (node && node.nodeType >= 1) {
  754. if (!node.t792) {
  755. node.t792 = (ud00 = (ud00 & 1073741823) + 1);
  756. const x = `${node.nodeName.toLowerCase()}#${node.t792}`;
  757. this.register(node, x);
  758. if (MEMORY_RELEASE_NF00_SHOW_MESSAGE) console.log(`NF00: try remove node[${x}]`);
  759. ng00.add(mWeakRef(node));
  760. }
  761. }
  762. }
  763. window.showNg00 = () => {
  764. const ng01 = new Set();
  765. ng01.add = ng01.addOriginal || ng01.add;
  766. for (const e of ng00) {
  767. const f = kRef(e);
  768. if (!f) continue;
  769. ng01.add(f);
  770. }
  771. const ng02 = [...ng01];
  772. ng01.clear();
  773. window.showNg01 = [...ng02];
  774. return window.showNg01;
  775. }
  776. window.showTemplates00 = () => {
  777. const result = {};
  778. const elements = document.querySelectorAll('*');
  779. for (const element of elements) {
  780. const tag = element.nodeName.toLocaleLowerCase();
  781. const r = result[tag] || [];
  782. const cnt = insp(element);
  783. if (cnt !== element) {
  784. if (cnt.templateInfo) {
  785. r.push(['cnt0', cnt.templateInfo, element]);
  786. }
  787. if (element._templateInfo) {
  788. r.push(['cnt1', cnt._templateInfo, element]);
  789. }
  790. if (element.__templateInfo) {
  791. r.push(['cnt2', cnt.__templateInfo, element]);
  792. }
  793. }
  794. if (element.templateInfo) {
  795. r.push(['elm0', element.templateInfo, element]);
  796. }
  797. if (element._templateInfo) {
  798. r.push(['elm1', element._templateInfo, element]);
  799. }
  800. if (element.__templateInfo) {
  801. r.push(['elm2', element.__templateInfo, element]);
  802. }
  803. if (r.length >= 1) result[tag] = r;
  804. }
  805. const strCmp = (a, b) => {
  806. if (a === b) return 0;
  807. let u = [a, b].sort();
  808. return u[0] === a ? -1 : 1;
  809. }
  810. const counting1 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[0]))].join('|')]).sort((a, b) => {
  811. return strCmp(`${a[1]}.${a[0]}`, `${b[1]}.${b[0]}`);
  812. });
  813.  
  814. const counting2 = Object.entries(result).map(e => [e[0], [...new Set(e[1].map(t => t[1]))]]);
  815.  
  816. const counting3 = Object.entries(result).map(e => {
  817. const a = [...new Set(e[1].map(t => t[1]))];
  818. const b = [...new Set(a.map(e => e.nodeList || e))];
  819.  
  820. const r = [e[0], b];
  821. return r;
  822. });
  823.  
  824. return {result, counting1, counting2, counting3};
  825. };
  826.  
  827. window.showFrag00 = function(){
  828.  
  829. const result = {};
  830. const elements = document.querySelectorAll('*');
  831. for (const element of elements) {
  832. const tag = element.nodeName.toLocaleLowerCase();
  833. const r = result[tag] || [];
  834. const cnt = insp(element);
  835. if (cnt !== element) {
  836. if (cnt.templateInfo) {
  837. r.push(['cnt0', cnt.templateInfo, element]);
  838. }
  839. if (element._templateInfo) {
  840. r.push(['cnt1', cnt._templateInfo, element]);
  841. }
  842. if (element.__templateInfo) {
  843. r.push(['cnt2', cnt.__templateInfo, element]);
  844. }
  845. }
  846. if (element.templateInfo) {
  847. r.push(['elm0', element.templateInfo, element]);
  848. }
  849. if (element._templateInfo) {
  850. r.push(['elm1', element._templateInfo, element]);
  851. }
  852. if (element.__templateInfo) {
  853. r.push(['elm2', element.__templateInfo, element]);
  854. }
  855. if (r.length >= 1) result[tag] = r;
  856. }
  857. return result;
  858.  
  859. }
  860.  
  861. const detachShadyRef = (node) => {
  862.  
  863. const shadyArr = [...shadys];
  864. for (let shady of shadyArr) {
  865. shady = kRef(shady);
  866. if (!shady) continue;
  867. const keys = [...Object.getOwnPropertyNames(shady), ...Object.getOwnPropertySymbols(shady)];
  868. for (const p of keys) {
  869. const v = keys[p];
  870. if (!v) continue;
  871. if (v instanceof Node) {
  872. if (node === v || node.contains(v)) keys[p] = _emptyElement;
  873. } else if (typeof v === 'object' && v.splice && v.length > 0) {
  874. for (let i = v.length - 1; i >= 0; i--) {
  875. const t = v[i];
  876. if (t instanceof Node) {
  877. if (node === t || node.contains(t)) v.splice(i, 1);
  878. }
  879. }
  880. }
  881. }
  882. }
  883. shadyArr.length = 0;
  884.  
  885.  
  886. }
  887.  
  888. if (MEMORY_RELEASE_NF00) {
  889.  
  890. const __removedElements = new Set();
  891. __removedElements.add = __removedElements.addOriginal || __removedElements.add;
  892.  
  893. setInterval(() => {
  894. const nodesSet = new Set();
  895. nodesSet.add = nodesSet.addOriginal || nodesSet.add;
  896.  
  897. for (const nodeWr of __removedElements) {
  898. __removedElements.delete(nodeWr);
  899. const node = kRef(nodeWr);
  900. if (node && node.nodeType >= 1 && node.isConnected === false) {
  901. let rootNode;
  902. try {
  903. rootNode = node.getRootNode();
  904. } catch (e) { }
  905. if (rootNode && rootNode.nodeType >= 1 && rootNode.nodeType !== 9 && rootNode.isConnected === true) {
  906. // do nothing
  907. } else {
  908. nodesSet.add(node);
  909. if (node.querySelectorAll) {
  910. for (const p of node.querySelectorAll('*')) {
  911. nodesSet.add(p);
  912. }
  913. }
  914. }
  915. }
  916. }
  917. for (const nodeWr of _removedElements) {
  918. _removedElements.delete(nodeWr);
  919. const node = kRef(nodeWr);
  920. if (node && node.isConnected === false) {
  921. __removedElements.add(nodeWr);
  922. }
  923. }
  924.  
  925. if(nodesSet.size === 0) return;
  926.  
  927. const nmSet = [..._nmSet].map(e => kRef(e)).filter(e => !!e);
  928. const nmMap = [..._nmMap].map(e => kRef(e)).filter(e => !!e);
  929. const nmMapV = [..._nmMapV].map(e => kRef(e)).filter(e => !!e);
  930.  
  931. for (const node of nodesSet) {
  932. if (node === _emptyElement || node.__keepInstance038__ || node.t792) continue;
  933. const hasToolTips = !!((insp(node).$ || 0).tooltip);
  934.  
  935. if (node && node.__shady_getRootNode) {
  936. let k = null;
  937. try {
  938. k = node.__shady_getRootNode();
  939. } catch { }
  940. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  941. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  942. }
  943. if (node && node.getRootNode) {
  944. const k = node.getRootNode();
  945. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  946. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  947. }
  948.  
  949. if (node.__instances) {
  950. for (const k of node.__instances) {
  951. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  952. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  953. }
  954. // node.__instances.length = 0;
  955. }
  956. if (node && node.nodeType === 1) {
  957. if (typeof insp(node).__teardownInstance === 'function') {
  958. try {
  959. insp(node).__teardownInstance();
  960. } catch (e) { }
  961. } else if (typeof node.__teardownInstance === 'function') {
  962. try {
  963. node.__teardownInstance();
  964. } catch (e) { }
  965. }
  966. }
  967. if (node && node.nodeType === 1 && node.__detachAndRemoveInstance && (node.__instances || 0).length >= 1) {
  968. for (let i = node.__instances.length - 1; i >= 0; i--) {
  969. node.__detachAndRemoveInstance(i)
  970. }
  971. }
  972.  
  973. if (node && node.nodeType === 1 && node.is === void 0) {
  974. if (typeof insp(node).dispose === 'function') {
  975. insp(node).dispose();
  976. } else if (typeof node.dispose === 'function') {
  977. node.dispose();
  978. }
  979. }
  980.  
  981. if (node && node.nodeType === 1) {
  982. if (typeof insp(node).unobserve_ === 'function') {
  983. insp(node).unobserve_();
  984. } else if (typeof node.unobserve_ === 'function') {
  985. node.unobserve_();
  986. }
  987. }
  988.  
  989. if (node) {
  990. if (typeof insp(node).unobserveNodes === 'function') {
  991. insp(node).unobserveNodes();
  992. } else if (typeof node.unobserveNodes === 'function') {
  993. node.unobserveNodes();
  994. }
  995. }
  996.  
  997. // if (node && node.nodeType === 1) {
  998. // const cnt = insp(node);
  999. // const paths = cnt.__dataLinkedPaths;
  1000. // if (paths && paths.length >= 1 && typeof cnt.unlinkPaths === 'function') {
  1001. // for (let k in paths) {
  1002. // cnt.unlinkPaths(k);
  1003. // }
  1004. // }
  1005. // }
  1006.  
  1007. const visibilityMonitorKeys = insp(node).visibilityMonitorKeys || node.visibilityMonitorKeys;
  1008. if (visibilityMonitorKeys) {
  1009. for (const entry of visibilityMonitorKeys) {
  1010. if (entry.element) { entry.element = null }
  1011. }
  1012. visibilityMonitorKeys.length = 0;
  1013. }
  1014. const __instances = node.__instances;
  1015. if (__instances) {
  1016. for (const k of __instances) {
  1017. if (k && k.__keepInstance038__) k.__keepInstance038__ = false;
  1018. if (k && k.nodeType >= 1 && k.isConnected === false) _removedElements.addNode(k);
  1019. }
  1020. __instances.length = 0;
  1021. }
  1022. const sp = node.__shady_parentNode;
  1023. if (sp && sp.nodeType >= 1 && sp.isConnected === false) _removedElements.addNode(sp);
  1024. FULLY_REMOVE_ALL_EVENT_LISTENERS && node.removeAllEventListener001();
  1025. if (node && node.remove) node.remove();
  1026.  
  1027. /*
  1028. if (node._templateInfo && node._templateInfo.content) {
  1029. const templateInfoContent = node._templateInfo.content;
  1030. if (templateInfoContent.nodeType >= 1 && templateInfoContent.isConnected === false) {
  1031. _removedElements.addNode(templateInfoContent);
  1032. }
  1033. try{
  1034. node._templateInfo.content = null;
  1035. }catch(e){}
  1036. }
  1037. */
  1038. if (node.__domApi) {
  1039. node.__domApi = null;
  1040. }
  1041.  
  1042. const __shady = node.__shady;
  1043. if (__shady) {
  1044. delete node.__shady;
  1045. if (shadyKey) {
  1046. const shadyRootNode = __shady[shadyKey];
  1047. if (shadyRootNode) {
  1048. // console.log(shadyRootNode);
  1049. __shady[shadyKey] = null;
  1050. for (const key of [...Object.getOwnPropertyNames(__shady), ...Object.getOwnPropertySymbols(__shady)]) {
  1051. shadyRootNode[key] = null;
  1052. }
  1053. }
  1054. }
  1055. }
  1056.  
  1057.  
  1058. const ceRoot = node.__CE_shadowRoot;
  1059. if (ceRoot) {
  1060. node.__CE_shadowRoot = null;
  1061. if (ceRoot.nodeType >= 1 && ceRoot.isConnected === false) {
  1062. _removedElements.addNode(ceRoot);
  1063. }
  1064.  
  1065. }
  1066.  
  1067. // xTeardownTemplateInfo
  1068. const snChildNodes = node.__shady_native_childNodes;
  1069. if (snChildNodes.length > 0) {
  1070. for (const node of snChildNodes) {
  1071. if (node && node.nodeType >= 1 && node.isConnected === false) {
  1072. _removedElements.addNode(node);
  1073. }
  1074. }
  1075. snChildNodes.length = 0;
  1076. }
  1077. node.__shady_native_childNodes = null;
  1078.  
  1079.  
  1080. const __templateInfo = node.__templateInfo;
  1081. if (__templateInfo) {
  1082. node.__templateInfo = null;
  1083. // xTeardownTemplateInfo(__templateInfo);
  1084. }
  1085.  
  1086. if (hasToolTips && insp(node).$) {
  1087. insp(node).$.tooltip = _emptyTipsElement;
  1088. }
  1089.  
  1090. if (node && node.nodeType >= 1) {
  1091. const pd = Object.getOwnPropertyDescriptor(node, 'visibilityMonitorKeys');
  1092. if (pd && pd.value && pd.value.length >= 1) {
  1093. const arr = pd.value;
  1094. for (let i = 0; i < arr.length; i++) {
  1095. arr[i].element = _emptyVisibilityElement;
  1096. arr[i] = null;
  1097. }
  1098. }
  1099. }
  1100.  
  1101. if (node.__dataHost) {
  1102. try {
  1103. delete node.__dataHost
  1104. } catch (e) { }
  1105. try {
  1106. node.__dataHost = null;
  1107. } catch (e) { }
  1108. }
  1109.  
  1110. if (node.root) {
  1111. try {
  1112. delete node.root
  1113. } catch (e) { }
  1114. try {
  1115. node.root = null;
  1116. } catch (e) { }
  1117. }
  1118.  
  1119. if (node.children && node.children.splice) {
  1120. try {
  1121. delete node.children
  1122. } catch (e) { }
  1123. try {
  1124. node.children = null;
  1125. } catch (e) { }
  1126. }
  1127.  
  1128. if (node.__shady && typeof node.__shady === 'object') {
  1129. try {
  1130. node.__shady = null;
  1131. } catch (e) { }
  1132. }
  1133.  
  1134. if (node.nodeType === 1) Reflect.setPrototypeOf(node, PlainHTMLElement.prototype);
  1135.  
  1136. for (const prop of Object.getOwnPropertyNames(node)) {
  1137. if (prop === 'host' && typeof (node.host || 0) === 'object') {
  1138. if (node.nodeType === 11) {
  1139. const nodeHost = node.host;
  1140. if (nodeHost && nodeHost.nodeType >= 1) {
  1141. node.host = _emptyElement;
  1142. if (nodeHost.isConnected === false && nodeHost !== _emptyElement) {
  1143. _removedElements.addNode(nodeHost);
  1144. }
  1145. } else {
  1146. node.host = null;
  1147. }
  1148. } else {
  1149. node.host = null;
  1150. }
  1151. continue;
  1152. }
  1153. const pd = Object.getOwnPropertyDescriptor(node, prop);
  1154. if (pd.value) {
  1155. const v = pd.value;
  1156. if (typeof (v || 0) === 'object') node[prop] = null;
  1157. else if (typeof (v || 0) === 'function') delete node[prop];
  1158. }
  1159. }
  1160.  
  1161. for (const prop of Object.getOwnPropertySymbols(node)) {
  1162. const v = node[prop];
  1163. if (typeof (v || 0) === 'object' && !v.deref) node[prop] = null;
  1164. }
  1165.  
  1166. if (node.__shady_native_childNodes) {
  1167. node.__shady_native_childNodes = _emptyElement.childNodes;
  1168. }
  1169. if (node.__shady_children) {
  1170. node.__shady_children = _emptyElement.children;
  1171. }
  1172.  
  1173. for (const s of nmSet) s.delete(node);
  1174. for (const m of nmMap) m.delete(node);
  1175.  
  1176. mightTeardownShadyDomWrap(node);
  1177.  
  1178. detachShadyRef(node);
  1179.  
  1180. nf00.registerNode(node);
  1181.  
  1182.  
  1183.  
  1184. // console.log(1883001, node)
  1185. // console.log(3772001, node, node.countEvent767())
  1186. }
  1187.  
  1188. nodesSet.clear();
  1189.  
  1190. }, 400);
  1191.  
  1192. }
  1193.  
  1194.  
  1195. if (FULLY_REMOVE_ALL_EVENT_LISTENERS && !EventTarget.prototype.addEventListener828 && !EventTarget.prototype.removeAllEventListener001) {
  1196. const handlerMap = new WeakMap();
  1197. EventTarget.prototype.addEventListener828 = EventTarget.prototype.addEventListener;
  1198. EventTarget.prototype.addEventListener = function (type, handler, option = void 0) {
  1199. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1200. let hds = handlerMap.get(wr);
  1201. if (!hds) handlerMap.set(wr, (hds = new Set()));
  1202. hds.add([type, handler, option]);
  1203. return this.addEventListener828(type, handler, option);
  1204. }
  1205. EventTarget.prototype.removeEventListener828 = EventTarget.prototype.removeEventListener;
  1206. EventTarget.prototype.removeEventListener = function (type, handler, option = void 0) {
  1207. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1208. let hds = handlerMap.get(wr);
  1209. if (hds) {
  1210. for (const entry of hds) {
  1211. if (entry[0] === type && entry[1] === handler) {
  1212. if (entry[2] === option) {
  1213. hds.delete(entry);
  1214. // break;
  1215. } else if (FUZZY_EVENT_LISTENER_REMOVAL) {
  1216. hds.delete(entry);
  1217. this.removeEventListener828(type, handler, entry[2]);
  1218. }
  1219. }
  1220. }
  1221. }
  1222. return this.removeEventListener828(type, handler, option);
  1223. }
  1224. EventTarget.prototype.countEvent767 = function(){
  1225. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1226. return handlerMap.get(wr);
  1227. }
  1228. EventTarget.prototype.removeAllEventListener001 = function () {
  1229. const wr = this[wk] || (this[wk] = mWeakRef(this));
  1230. let hds = handlerMap.get(wr);
  1231. if (hds) {
  1232. handlerMap.delete(wr);
  1233. for (const entry of hds) {
  1234. const [type, handler, option] = entry;
  1235. entry.length = 0;
  1236. this.removeEventListener828(type, handler, option);
  1237. }
  1238. hds.clear();
  1239. }
  1240. }
  1241. }
  1242.  
  1243. const globalSetup = (key, setup)=>{
  1244. let symb = Symbol();
  1245. Object.defineProperty(Object.prototype, key, {
  1246. get() {
  1247. return this[symb];
  1248. },
  1249. set(nv) {
  1250. if (typeof nv !== 'function') {
  1251. this[symb] = nv;
  1252. return true;
  1253. }
  1254. if (!(symb in this)) {
  1255. setup(this);
  1256. }
  1257. this[symb] = nv;
  1258. return true;
  1259. },
  1260. configurable: true,
  1261. enumerable: false
  1262. });
  1263. }
  1264.  
  1265. const toActualNode = (e) => {
  1266. return e && e.getNode592177 ? e.getNode592177() : e;
  1267. }
  1268.  
  1269. const removeAllChildNodes = (o)=>{
  1270. if ((o instanceof Node) && o.nodeType >= 1) {
  1271. let t, q = null;
  1272. while ((t = o.firstChild) && t !== q) {
  1273. try {
  1274. t.__keepInstance038__ = false;
  1275. t.remove();
  1276. _removedElements.addNode(t);
  1277. q = t;
  1278. } catch (e) { }
  1279. }
  1280. try {
  1281. o.__keepInstance038__ = false;
  1282. o.remove();
  1283. _removedElements.addNode(o);
  1284. } catch (e) { }
  1285. }
  1286. }
  1287.  
  1288. let shadyInited = false;
  1289. let shadyKey = '';
  1290. let shadyKeyX = '';
  1291. const setupShady = () => {
  1292. shadyInited = true;
  1293. let p = document.createComment('1');
  1294. const x = document.implementation.createHTMLDocument();
  1295. const y = x.firstElementChild;
  1296. y.appendChild(p);
  1297. let key = '';
  1298. p.__shady = new Proxy({}, {
  1299. get(target, prop) {
  1300. key = prop;
  1301. throw new Error();
  1302. },
  1303. set(target, prop, val) {
  1304. throw new Error();
  1305. }
  1306. })
  1307. try {
  1308. p.__shady_getRootNode()
  1309. } catch (e) { }
  1310. let __shady = null;
  1311. try {
  1312. p.__shady = null;
  1313. p.__shady_getRootNode()
  1314. __shady = p.__shady;
  1315. } catch (e) {
  1316.  
  1317. }
  1318. y.removeChild(p);
  1319.  
  1320.  
  1321. if (0 && key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1322. const sProto = Reflect.getPrototypeOf(__shady);
  1323. const symb = Symbol('__shady');
  1324. // const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1325. Object.defineProperty(sProto, key, {
  1326. get() {
  1327. if(!this[wk]) this[wk] = mWeakRef(this);
  1328. shadys.add(this[wk]);
  1329. return kRef(this[symb]);
  1330. },
  1331. set(nv) {
  1332. if(!this[wk]) this[wk] = mWeakRef(this);
  1333. shadys.add(this[wk]);
  1334. if (typeof (nv || 0) === 'object') {
  1335. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1336. this[symb] = nv[wk];
  1337. } else {
  1338. this[symb] = nv;
  1339. }
  1340. return true;
  1341. },
  1342. enumerable: false,
  1343. configurable: true
  1344. });
  1345. shadyKey = key;
  1346. console.log('[yt-js-engine-tamer] shadyKey', key);
  1347.  
  1348. }
  1349.  
  1350.  
  1351. if (0 && key && __shady && typeof __shady === 'object' && !('nodeType' in __shady) && !('nodeName' in __shady)) {
  1352. const sProto = Reflect.getPrototypeOf(__shady);
  1353. const symb = Symbol('__shady');
  1354. const symbKeys = ['root', 'firstChild', 'lastChild', 'parentNode', 'nextSibling', 'previousSibling'];
  1355. Object.defineProperty(sProto, key, {
  1356. get() {
  1357. if(!this[wk]) this[wk] = mWeakRef(this);
  1358. shadys.add(this[wk]);
  1359. return kRef(this[symb]);
  1360. },
  1361. set(nv) {
  1362. if(!this[wk]) this[wk] = mWeakRef(this);
  1363. shadys.add(this[wk]);
  1364. if (typeof (nv || 0) === 'object') {
  1365. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1366. this[symb] = nv[wk];
  1367. } else {
  1368. this[symb] = nv;
  1369. }
  1370. return true;
  1371. },
  1372. enumerable: false,
  1373. configurable: true
  1374. });
  1375. shadyKey = key;
  1376. console.log('[yt-js-engine-tamer] shadyKey', key);
  1377.  
  1378. let shadyKeyCached = new Set();
  1379. const fixLastShady = () => {
  1380. const shady = lastShady;
  1381. for (const key of Object.keys(shady)) {
  1382. if (shadyKeyCached.has(key)) continue;
  1383. shadyKeyCached.add(key);
  1384. if ((typeof shady[key] === 'object') && !(shady[key] || 0).deref) {
  1385. if (!shadyKeyX && shady[key] === shady.root) {
  1386. shadyKeyX = key;
  1387. const sProto = Reflect.getPrototypeOf(shady);
  1388. const symb = Symbol();
  1389. Object.defineProperty(sProto, shadyKeyX, {
  1390. get() {
  1391. return kRef(this[symb])
  1392. },
  1393. set(nv) {
  1394. if (typeof (nv || 0) === 'object') {
  1395. nv = kRef(nv);
  1396. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1397. this[symb] = nv[wk];
  1398. } else {
  1399. this[symb] = nv;
  1400. }
  1401. return true;
  1402. },
  1403. enumerable: false,
  1404. configurable: true,
  1405. });
  1406. delete shady[key];
  1407. shady[key] = shady.root;
  1408. };
  1409. // console.log(12883, shady[key], key);
  1410. // assignedNodes, assignedSlot, ja, K, childNodes, ... (keep strong ref)
  1411. }
  1412. }
  1413. }
  1414. let lastShady = null;
  1415.  
  1416. symbKeys.forEach(key => {
  1417. const symb = Symbol(key);
  1418.  
  1419. Object.defineProperty(sProto, key, {
  1420. get() {
  1421. if (this !== lastShady && lastShady) fixLastShady();
  1422. lastShady = this;
  1423. return kRef(this[symb]);
  1424. },
  1425. set(nv) {
  1426. if (this !== lastShady && lastShady) fixLastShady();
  1427. lastShady = this;
  1428. if (typeof (nv || 0) === 'object') {
  1429. nv = kRef(nv);
  1430. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1431. this[symb] = nv[wk];
  1432. } else {
  1433. this[symb] = nv;
  1434. }
  1435. return true;
  1436. },
  1437. enumerable: false,
  1438. configurable: true
  1439. });
  1440.  
  1441. });
  1442.  
  1443. }
  1444.  
  1445.  
  1446.  
  1447. }
  1448.  
  1449. const stampedNodes = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1450. stampedNodes.set = stampedNodes.setOriginal || stampedNodes.set;
  1451. const stampedFragment = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1452. stampedFragment.set = stampedFragment.setOriginal || stampedFragment.set;
  1453.  
  1454.  
  1455. class WeakNodeC extends Node {
  1456. constructor() {
  1457. }
  1458. addEventListener(type, listener, option = void 0) {
  1459. const nodeWr = stampedNodes.get(this.eid);
  1460. const node = kRef(nodeWr);
  1461. if (!node) return;
  1462. return node.addEventListener(type, listener, option);
  1463. }
  1464. removeEventListener(type, listener, option = void 0) {
  1465. const nodeWr = stampedNodes.get(this.eid);
  1466. const node = kRef(nodeWr);
  1467. if (!node) return;
  1468. return node.removeEventListener(type, listener, option);
  1469. }
  1470. getNode592177() {
  1471. const nodeWr = stampedNodes.get(this.eid);
  1472. const node = kRef(nodeWr);
  1473. return node;
  1474. }
  1475.  
  1476. set __dataHost(nv) {
  1477. const nodeWr = stampedNodes.get(this.eid);
  1478. const node = kRef(nodeWr);
  1479. if (!node) return;
  1480. node.__dataHost = nv;
  1481. return true;
  1482. }
  1483. get __dataHost() {
  1484. const nodeWr = stampedNodes.get(this.eid);
  1485. const node = kRef(nodeWr);
  1486. if (!node) return;
  1487. return node.__dataHost;
  1488. }
  1489.  
  1490. set __dataCompoundStorage(nv) {
  1491. const nodeWr = stampedNodes.get(this.eid);
  1492. const node = kRef(nodeWr);
  1493. if (!node) return;
  1494. node.__dataCompoundStorage = nv;
  1495. return true;
  1496. }
  1497. get __dataCompoundStorage() {
  1498. const nodeWr = stampedNodes.get(this.eid);
  1499. const node = kRef(nodeWr);
  1500. if (!node) return;
  1501. return node.__dataCompoundStorage;
  1502. }
  1503.  
  1504. set __shady_className(nv) {
  1505. const nodeWr = stampedNodes.get(this.eid);
  1506. const node = kRef(nodeWr);
  1507. if (!node) return;
  1508. node.__shady_className = nv;
  1509. // debugger;
  1510. return true;
  1511. }
  1512. get __shady_className() {
  1513. const nodeWr = stampedNodes.get(this.eid);
  1514. const node = kRef(nodeWr);
  1515. if (!node) return;
  1516. return node.__shady_className;
  1517. }
  1518. }
  1519.  
  1520. if (FIX_TEMPLATE_BINDING) {
  1521. const templateMap = new Map(); /* !!!!!! CAUTION FOR MEMORY LEAKAGE !!!!!!! */
  1522. templateMap.set = templateMap.setOriginal || templateMap.set;
  1523. // const parsedTemplate = new Map();
  1524.  
  1525.  
  1526. const it0 = Date.now() - 80000000000;
  1527. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  1528.  
  1529.  
  1530. /*
  1531.  
  1532. M.prototype._bindTemplate = function(N, R) {
  1533. var X = this.constructor._parseTemplate(N)
  1534. , A = this.__preBoundTemplateInfo == X;
  1535. if (!A)
  1536. for (var l in X.propertyEffects)
  1537. this._createPropertyAccessor(l);
  1538. R ? (X = Object.create(X),
  1539. X.wasPreBound = A,
  1540. this.__templateInfo ? (N = N._parentTemplateInfo || this.__templateInfo,
  1541. R = N.lastChild,
  1542. X.parent = N,
  1543. N.lastChild = X,
  1544. (X.previousSibling = R) ? R.nextSibling = X : N.firstChild = X) : this.__templateInfo = X) : this.__preBoundTemplateInfo = X;
  1545. return X
  1546. }
  1547. ;
  1548. */
  1549.  
  1550. /*
  1551. ** this.constructor._parseTemplate **
  1552. d._parseTemplate = function(N, R) {
  1553. if (!N._templateInfo) {
  1554. var X = N._templateInfo = {};
  1555. X.nodeInfoList = [];
  1556. X.nestedTemplate = !!R;
  1557. X.stripWhiteSpace = R && R.stripWhiteSpace || N.hasAttribute && N.hasAttribute("strip-whitespace");
  1558. this._parseTemplateContent(N, X, {
  1559. parent: null
  1560. })
  1561. }
  1562. return N._templateInfo
  1563. }
  1564.  
  1565. */
  1566.  
  1567.  
  1568. const exceptionTriggered = new Set();
  1569. const gxx = (window.gxxC572 || (window.gxxC572 = new Set()));
  1570.  
  1571. // let initied1 = false;
  1572. // let _parseTemplateByPass = false;
  1573. const setup1 = (qxx) => {
  1574. // if(initied1) return;
  1575. // initied1 = true;
  1576. const proto = qxx;
  1577. const constructor = proto.constructor;
  1578. const _bindTemplate = proto._bindTemplate;
  1579. // console.log(12883, proto, constructor)
  1580.  
  1581.  
  1582. const _parseTemplate = constructor._parseTemplate;
  1583. if (typeof _parseTemplate === 'function' && _parseTemplate.length === 2 && !constructor._parseTemplate322) {
  1584.  
  1585. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _parseTemplate', _parseTemplate);
  1586. constructor._parseTemplate322 = _parseTemplate;
  1587. const parsedResults = new WeakMap();
  1588.  
  1589. const _templateInfoPd = {
  1590. get() {
  1591. if (!this || !this[wk]) return undefined;
  1592. const r = parsedResults.get(this[wk]);
  1593. return r;
  1594. },
  1595. set(nv) {
  1596. delete this._templateInfo;
  1597. this._templateInfo = nv;
  1598. console.warn('_templateInfoPd set');
  1599. return true;
  1600. },
  1601. enumerable: true,
  1602. configurable: true
  1603. };
  1604. constructor._parseTemplate = function (N, R) {
  1605. if (!N) return _parseTemplate.call(this, N, R);
  1606. if (!N[wk]) N[wk] = mWeakRef(N);
  1607. let r = parsedResults.get(N[wk]);
  1608. if (r) return r;
  1609. r = _parseTemplate.call(this, N, R);
  1610. if (r && !parsedResults.has(N[wk])) {
  1611. parsedResults.set(N[wk], r);
  1612. r.iAm68 = '_templateInfo';
  1613. N.iHave68 = '_templateInfo';
  1614. if (N._templateInfo && N._templateInfo === r) {
  1615. delete N._templateInfo;
  1616. if (!N._templateInfo) {
  1617. Object.defineProperty(N, '_templateInfo', _templateInfoPd);
  1618. }
  1619. }
  1620. }
  1621. return r;
  1622. }
  1623. }
  1624. if (typeof _bindTemplate === 'function' && _bindTemplate.length === 2 && !proto._bindTemplate322) {
  1625.  
  1626. FIX_TEMPLATE_BINDING_SHOW_MESSAGE && console.log('Hack00: _bindTemplate', _bindTemplate);
  1627. proto._bindTemplate322 = _bindTemplate;
  1628. proto._bindTemplate = function (N, R) {
  1629. // R = boolean true or undefined
  1630. // N = template elemenet
  1631. let M = N;
  1632. if (typeof (N || 0) === 'object' && N instanceof HTMLTemplateElement && (N.content || 0).nodeType === 11) {
  1633. let componentIs = '';
  1634. try {
  1635. componentIs = this ? this.is : '';
  1636. } catch (e) { }
  1637. if (typeof (componentIs || 0) === 'string') {
  1638. if (!templateMap.has(componentIs)) {
  1639. templateMap.set(componentIs, N);
  1640. // const parser = this.constructor;
  1641. // console.log(3882, parser._parseTemplate)
  1642. /*
  1643. if (parser._parseTemplate && !parser._parseTemplate477 && parser._parseTemplate.length === 2) {
  1644. parser._parseTemplate477 = parser._parseTemplate;
  1645. const _parseTemplate477 = parser._parseTemplate477;
  1646. parser._parseTemplate = function (N, R) {
  1647. if (!_parseTemplateByPass && N && N[wk]) {
  1648. const u = parsedTemplate.get(N[wk]);
  1649. if (u) {
  1650. console.log(1838, u)
  1651. return u;
  1652. }
  1653. }
  1654. return _parseTemplate477.call(this, N, R);
  1655. };
  1656. }
  1657. if (parser._parseTemplate && parser._parseTemplate477) {
  1658. if (N && !N[wk]) N[wk] = mWeakRef(N);
  1659. if (!parsedTemplate.has(N[wk])) {
  1660. _parseTemplateByPass = true;
  1661. parsedTemplate.set(N[wk], parser._parseTemplate477(N));
  1662. _parseTemplateByPass = false;
  1663. }
  1664. }
  1665. */
  1666. } else {
  1667. M = templateMap.get(componentIs);
  1668. }
  1669. }
  1670. }
  1671. let r_ = null;
  1672. // Promise.resolve(N).then((N) => {
  1673. // console.log(3488,N.templateInfo, N.templateInfo === r_);
  1674. // })
  1675. const r = _bindTemplate.call(this, M, R);
  1676. r_ = r;
  1677. return r;
  1678. }
  1679. }
  1680.  
  1681. const _runEffectsForTemplate = proto._runEffectsForTemplate;
  1682. if (typeof _runEffectsForTemplate === 'function' && _runEffectsForTemplate.length === 4 && !proto._runEffectsForTemplate322) {
  1683. proto._runEffectsForTemplate322 = _runEffectsForTemplate;
  1684.  
  1685. // note: fastDomIf does not work well with runEffects ...
  1686. // so no runEffects actaully?
  1687. const runner = (Tw, Nw, Rw, Xw, Aw) => {
  1688.  
  1689. try {
  1690.  
  1691.  
  1692. // console.log(988003)
  1693. const T = kRef(Tw); // this
  1694. const N = kRef(Nw); // __templateInfo
  1695. if (!T || !N) return;
  1696.  
  1697. // console.log(988004)
  1698. const R = kRef(Rw); // __data
  1699. const X = kRef(Xw); // temp Data ?
  1700. const A = kRef(Aw); // boolean ?
  1701. if (typeof (X || 0) === 'object') gxx.delete(X);
  1702. if (typeof (A || 0) === 'object') gxx.delete(A);
  1703.  
  1704. // console.log(988005)
  1705. const nodeList_ = N.nodeList;
  1706.  
  1707. // console.log(988006, nodeList_)
  1708. const nodeList = nodeList_ ? nodeList_.map(e => toActualNode(e)) : nodeList_;
  1709.  
  1710. // console.log(988007, nodeList)
  1711.  
  1712. const Nx = {
  1713. propertyEffects: N.propertyEffects,
  1714. nodeList: nodeList,
  1715. firstChild: kRef(N.firstChild)
  1716. };
  1717.  
  1718. // if (kRef(N.firstChild)) {
  1719. // console.log(977001, Nx)
  1720. // }
  1721.  
  1722. // console.log(988009, Nx, R, X, A)
  1723.  
  1724.  
  1725. {
  1726.  
  1727.  
  1728. const o = Nx;
  1729. const { propertyEffects, nodeList, firstChild } = o;
  1730. if (propertyEffects && nodeList && nodeList.length >= 0) {
  1731. for (const [effectKey, propertyEffectArr] of Object.entries(propertyEffects)) {
  1732. for (let i = propertyEffectArr.length - 1; i >= 0; i--) {
  1733. const propertyEffect = propertyEffectArr[i];
  1734. const info = (propertyEffect || 0).info;
  1735. if (info && typeof info.index === 'number' && !nodeList[info.index]) {
  1736. propertyEffectArr.splice(i, 1);
  1737. }
  1738. }
  1739. }
  1740. }
  1741.  
  1742. }
  1743.  
  1744.  
  1745. // console.log({T, Nx, R, X , A })
  1746.  
  1747. // console.log(1737001, T)
  1748. // console.log(1737002, Nx)
  1749.  
  1750. // console.log(1737003, R)
  1751. // console.log(1737004, X)
  1752. // console.log(1737005, A)
  1753.  
  1754. const hostElement = T.hostElement;
  1755. const pChildren = (hostElement instanceof Node && hostElement.isConnected === true) ? [...hostElement.childNodes] : null;
  1756. renderPathMake(pChildren);
  1757.  
  1758. try {
  1759. _runEffectsForTemplate.call(T, Nx, R, X, A);
  1760.  
  1761. } catch (err) {
  1762. // debugger;
  1763. const stack = err.stack;
  1764. if (!exceptionTriggered.has(stack)) {
  1765. exceptionTriggered.add(stack);
  1766. console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`+"\n\n", err);
  1767. }
  1768. }
  1769.  
  1770. (pChildren || 0).length >= 1 && Promise.resolve(pChildren).then((pChildren) => {
  1771. for (const node of pChildren) {
  1772. if (node.parentNode !== hostElement && node.__weakNodeCId57__) {
  1773. _removedElements.addNode(node); // rn54001b
  1774. }
  1775. // if (node.isConnected === false) {
  1776. // let tNode = node;
  1777. // let pNode;
  1778. // while ((pNode = tNode.parentNode) && pNode.nodeType >= 1) {
  1779. // tNode = pNode;
  1780. // }
  1781. // // _removedElements.addNode(tNode); // rn54001
  1782. // }
  1783. }
  1784. pChildren.length = 0;
  1785. pChildren = null;
  1786. });
  1787.  
  1788.  
  1789. } catch (err) {
  1790. // debugger;
  1791. // const stack = err.stack;
  1792. // if (!exceptionTriggered.has(stack)) {
  1793. // exceptionTriggered.add(stack);
  1794. // console.warn(`[yt-js-engine-tamer] _runEffectsForTemplate EXCEPTION`, err);
  1795. console.error(err);
  1796. // }
  1797. }
  1798.  
  1799. };
  1800.  
  1801.  
  1802. proto._runEffectsForTemplate = function (N, R, X, A) {
  1803.  
  1804. // console.log(988001)
  1805. /*
  1806. N {wasPreBound: true, nodeList: Array(23)}
  1807.  
  1808. R {showInput: false, narrow: false, menuStrings: {…}, pageDarkTheme: true, theater: false, …}
  1809. X {showInput: undefined, narrow: undefined, menuStrings: undefined, pageDarkTheme: undefined, theater: undefined, …}
  1810. A false
  1811. */
  1812.  
  1813. const Nw = (!N || typeof N !== 'object') ? N : (N[wk] || (N[wk] = mWeakRef(N))); // __templateInfo
  1814. const Xw = (!X || typeof X !== 'object') ? X : (X[wk] || (X[wk] = mWeakRef(X)));
  1815.  
  1816. const Rw = (!R || typeof R !== 'object') ? R : (R[wk] || (R[wk] = mWeakRef(R))); // __data
  1817. const Aw = (!A || typeof A !== 'object') ? A : (A[wk] || (A[wk] = mWeakRef(A)));
  1818.  
  1819. if (typeof (X || 0) === 'object') gxx.add(X);
  1820. if (typeof (A || 0) === 'object') gxx.add(A);
  1821.  
  1822. const Tw = (!this || typeof this !== 'object') ? this : (this[wk] || (this[wk] = mWeakRef(this)));
  1823.  
  1824.  
  1825. if (N.runEffects) {
  1826. N.runEffects(() => {
  1827. runner(Tw, Nw, Rw, Xw, Aw);
  1828. }, R, A);
  1829. } else {
  1830. runner(Tw, Nw, Rw, Xw, Aw);
  1831. }
  1832.  
  1833. // console.log(988002)
  1834.  
  1835. // const N_ =
  1836.  
  1837. // var l = this
  1838. // , k = function (T, W) {
  1839. // XK(l, N.propertyEffects, T, X, W, N.nodeList);
  1840. // for (var w = N.firstChild; w; w = w.nextSibling)
  1841. // l._runEffectsForTemplate(w, T, X, W)
  1842. // };
  1843. // N.runEffects ? N.runEffects(k, R, A) : k(R, A)
  1844. }
  1845.  
  1846. }
  1847.  
  1848.  
  1849. const _registerHost = proto._registerHost;
  1850. if (_registerHost && !proto._registerHost322 && _registerHost.length === 0) {
  1851. proto._registerHost322 = _registerHost;
  1852. const map = new WeakMap();
  1853. map.set = map.setOriginal || map.set;
  1854. proto._registerHost = function () {
  1855. if (!map.has(this)) {
  1856. map.set(this, (this.__dataHost || null));
  1857. Object.defineProperty(this, '__dataHost', {
  1858. get() {
  1859. return kRef(map.get(this)) || null
  1860. },
  1861. set(nv) {
  1862. const w = kRef(nv);
  1863. if (!w) {
  1864. map.set(this, null);
  1865. } else {
  1866. if (!w[wk]) w[wk] = mWeakRef(w);
  1867. let byPass = false;
  1868. if (this.is === 'ytd-masthead') byPass = true;
  1869. if (byPass) {
  1870. map.set(this, w);
  1871. } else {
  1872. map.set(this, w[wk]);
  1873. }
  1874. }
  1875. return true;
  1876. },
  1877. enumerable: true,
  1878. configurable: true
  1879. });
  1880. }
  1881. let previousDataHost = this.__dataHost;
  1882. renderPathMake(previousDataHost)
  1883. let r = _registerHost.call(this);
  1884. let currentDataHost = this.__dataHost;
  1885. if (currentDataHost !== previousDataHost) { // future use only
  1886. if (previousDataHost && previousDataHost.nodeType >= 1 && previousDataHost.isConnected === false) {
  1887. _removedElements.addNode(previousDataHost); // rn54002
  1888. }
  1889. }
  1890. return r;
  1891. }
  1892. }
  1893.  
  1894. }
  1895. globalSetup('_removeBoundDom', setup1);
  1896.  
  1897.  
  1898. /*
  1899.  
  1900. M.prototype._stampTemplate = function(N, R) {
  1901. R = R || this._bindTemplate(N, !0);
  1902. aU.push(this);
  1903. N = d.prototype._stampTemplate.call(this, N, R);
  1904. aU.pop();
  1905. R.nodeList = N.nodeList;
  1906. if (!R.wasPreBound)
  1907. for (var X = R.childNodes = [], A = N.firstChild; A; A = A.nextSibling)
  1908. X.push(A);
  1909. N.templateInfo = R;
  1910. X = R.nodeList;
  1911. A = R.nodeInfoList;
  1912. if (A.length)
  1913. for (var l = 0; l < A.length; l++) {
  1914. var k = X[l]
  1915. , T = A[l].bindings;
  1916. if (T)
  1917. for (var W = 0; W < T.length; W++) {
  1918. var w = T[W]
  1919. , p = k
  1920. , h = w;
  1921. if (h.isCompound) {
  1922. for (var I = p.__dataCompoundStorage || (p.__dataCompoundStorage = {}), O = h.parts, y = Array(O.length), c = 0; c < O.length; c++)
  1923. y[c] = O[c].literal;
  1924. O = h.target;
  1925. I[O] = y;
  1926. h.literal && h.kind == "property" && (O === "className" && (p = (0,
  1927. _.FK)(p)),
  1928. p[O] = h.literal)
  1929. }
  1930. gM2(k, this, w)
  1931. }
  1932. k.__dataHost = this
  1933. }
  1934. this.__dataClientsReady && (this._runEffectsForTemplate(R, this.__data, null, !1),
  1935. this._flushClients());
  1936. return N
  1937. }
  1938. ;
  1939.  
  1940. */
  1941.  
  1942. const wnc = new Set();
  1943.  
  1944. const __listWeakNodeC__ = window.__listWeakNodeC__ = () => {
  1945. const result = __listWeakNodeC0__();
  1946. return [...result].sort();
  1947. }
  1948.  
  1949. const __listWeakNodeC0__ = () => {
  1950. let result = new Set();
  1951. for (const nodeC of wnc) {
  1952. for (const k of Object.getOwnPropertyNames(nodeC)) {
  1953. result.add(k)
  1954. }
  1955. }
  1956. return result;
  1957. }
  1958.  
  1959. setInterval(() => {
  1960. if (wnc.size > 0 && __listWeakNodeC0__().size !== 1) console.warn(`[yt-js-engine-tamer] WARNING 0xF04E: ${__listWeakNodeC__()}`);
  1961. }, 400);
  1962.  
  1963.  
  1964. const dollarStore = new Map();
  1965.  
  1966. const makeDollarClass = (idsJoined, ids) => {
  1967. const $ = class {};
  1968. const a = $.prototype;
  1969. ids.forEach(id => {
  1970. const p = `## ${id}`;
  1971. Object.defineProperty(a, id, {
  1972. get() {
  1973. return kRef(this[p]);
  1974. },
  1975. set(nv) {
  1976. if (nv instanceof Node) {
  1977. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  1978. this[p] = nv[wk];
  1979. } else {
  1980. this[p] = nv;
  1981. }
  1982. return true;
  1983. },
  1984. enumerable: true,
  1985. configurable: true
  1986. });
  1987. });
  1988. a.__w646__ = true;
  1989. dollarStore.set(idsJoined, $);
  1990. return $;
  1991. }
  1992.  
  1993. // let initied2 = false;
  1994. const setup2 = (qxx) => {
  1995. // if(initied2) return;
  1996. // initied2 = true;
  1997. const proto = qxx;
  1998. const constructor = proto.constructor;
  1999. const _stampTemplate = proto._stampTemplate;
  2000. // console.log(12883, proto, constructor)
  2001. if (typeof _stampTemplate === 'function' && _stampTemplate.length === 2 && !proto._stampTemplate374) {
  2002. proto._stampTemplate374 = _stampTemplate;
  2003. proto._stampTemplate = function (N, R) {
  2004.  
  2005. if (!shadyInited) setupShady();
  2006.  
  2007. let e__ = null;
  2008. try {
  2009. // R = boolean true or binded template
  2010. // N = template elemenet
  2011. let M = N;
  2012. let r_ = null;
  2013. const r = _stampTemplate.call(this, M, R); // return the fragment created with nodeList
  2014. r_ = r;
  2015. // if (r && r.host) {
  2016. // console.log(2883, R.host)
  2017. // }
  2018. if (r && r.$ && !r.$.__w646__) {
  2019. const $ = r.$;
  2020. const ids = Object.getOwnPropertyNames($)
  2021. const idsJoined = ids.join(' ');
  2022. const C = dollarStore.get(idsJoined) || makeDollarClass(idsJoined, ids);
  2023. const objVals = { ...$ };
  2024. Reflect.setPrototypeOf($, C.prototype);
  2025. for (const id of ids) {
  2026. delete $[id];
  2027. $[id] = objVals[id];
  2028. }
  2029. }
  2030. if (r && r.nodeType === 11 && !r.__fragId57__) {
  2031.  
  2032. const fid = genId();
  2033.  
  2034. r.__fragId57__ = fid;
  2035. if (!r[wk]) r[wk] = mWeakRef(r);
  2036. stampedFragment.set(fid, r[wk]);
  2037.  
  2038. if (r.nodeList) {
  2039. const nl = r.nodeList;
  2040. nl.__belongFragId57__ = fid;
  2041. for (let i = 0, l = nl.length; i < l; i++) {
  2042. const t = nl[i];
  2043. if (t && t.nodeType >= 1 && !(t instanceof ShadowRoot)) {
  2044. if (!t[wk]) t[wk] = mWeakRef(t);
  2045. const eid = `${fid}::${i}`;
  2046. const wn = Object.create(WeakNodeC.prototype);
  2047. wn.eid = eid;
  2048. wnc.add(wn);
  2049. nl[i] = wn;
  2050. // we believe the stampedNodes shall be attached to the document DomTree
  2051. stampedNodes.set(eid, t[wk]);
  2052. t.__weakNodeCId57__ = eid;
  2053. } else {
  2054. if (t instanceof ShadowRoot) {
  2055. console.warn('[yt-js-engine-tamer]', 'ShadowRoot in _stampTemplate');
  2056. }
  2057. }
  2058. }
  2059. }
  2060.  
  2061. }
  2062.  
  2063. return r;
  2064. } catch (e) { console.error(e); e__ = e; }
  2065. throw e__;
  2066.  
  2067. }
  2068. }
  2069. }
  2070.  
  2071. globalSetup('_addMethodEventListenerToNode', setup2);
  2072.  
  2073. }
  2074.  
  2075.  
  2076. if (FIX_FRAGEMENT_HOST && !DocumentFragment.prototype.host577) {
  2077. DocumentFragment.prototype.host577 = true;
  2078. let propsOK = false;
  2079. const finalizer = new FinalizationRegistry_((frag) => {
  2080.  
  2081. if (!frag.hostCleared55) {
  2082. frag.hostCleared55 = true;
  2083. for (const p of [...Object.getOwnPropertyNames(frag), ...Object.getOwnPropertySymbols(frag)]) {
  2084. const v = frag[p] || 0;
  2085. if (typeof v === 'object') {
  2086. frag[p] = null;
  2087. if (v.length > 0) v.length = 0;
  2088. }
  2089. }
  2090. }
  2091.  
  2092. });
  2093. Object.defineProperty(DocumentFragment.prototype, 'host', {
  2094. get() {
  2095. const r = kRef(this.host677);
  2096. if (!propsOK && this.nodeType === 11 && r) setupProps(Reflect.getPrototypeOf(this));
  2097. return r;
  2098. },
  2099. set(nv) {
  2100. nv = kRef(nv);
  2101. if (typeof (nv || 0) === 'object' && nv.nodeType === 1) {
  2102. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2103. this.host677 = nv[wk];
  2104. finalizer.register(nv, this);
  2105. } else {
  2106. this.host677 = nv;
  2107. }
  2108. return true;
  2109. },
  2110. enumerable: true,
  2111. configurable: true
  2112. });
  2113.  
  2114.  
  2115. const setupProps = (fragProto) => {
  2116.  
  2117. propsOK = true;
  2118.  
  2119. ["ownerDocument", "baseURI", "isConnected"].forEach(function (b) {
  2120.  
  2121. const pd = Object.getOwnPropertyDescriptor(fragProto, b);
  2122. const pdn = Object.getOwnPropertyDescriptor(Node.prototype, b);
  2123. const get1 = pd && pd.get;
  2124. const get2 = pdn && pdn.get;
  2125. if (get1 && get2) {
  2126. delete fragProto[b];
  2127. Object.defineProperty(fragProto, b, {
  2128. get: function () {
  2129. return this.host ? get1.call(this) : get2.call(this);
  2130. },
  2131. configurable: !0
  2132. });
  2133.  
  2134. }
  2135.  
  2136. });
  2137. }
  2138.  
  2139. }
  2140.  
  2141.  
  2142. if (XFlag) {
  2143.  
  2144. const cMap = new Set();
  2145. cMap.add = cMap.addOriginal || cMap.add;
  2146. const yMap = new Set();
  2147. yMap.add = yMap.addOriginal || yMap.add;
  2148.  
  2149.  
  2150. const ydMap = new Set();
  2151. ydMap.add = ydMap.addOriginal || ydMap.add;
  2152.  
  2153. window.yMap = yMap;
  2154. window.cMap = cMap;
  2155. window.ydMap = ydMap;
  2156.  
  2157. const constructAts = new Set();
  2158. constructAts.add = constructAts.addOriginal || constructAts.add;
  2159. window.constructAts = constructAts;
  2160.  
  2161. const kMap = new WeakMap();
  2162.  
  2163. const kRefProp = (wr, prop)=>{
  2164. let o = kRef(wr);
  2165. return o ? o[prop] : null;
  2166. }
  2167.  
  2168. const wrObj = (objRef, props) => {
  2169. let wr = mWeakRef(objRef);
  2170. if (wr === objRef || !props || !props.length) return wr;
  2171. let properties = {};
  2172. props.forEach(k => {
  2173. properties[k] = {
  2174. get() {
  2175. return kRefProp(this, k)
  2176. },
  2177. enumerable: false,
  2178. configurable: true
  2179. };
  2180. });
  2181. Object.defineProperties(wr, properties);
  2182. return wr;
  2183. }
  2184.  
  2185. const sProtos = {};
  2186.  
  2187. const setupCProto = function (cProto) {
  2188.  
  2189. if(cProto === Object.prototype) return;
  2190.  
  2191. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2192. cProto[kMap.get(cProto)] = true;
  2193. // debugger;
  2194.  
  2195. if (FIX_SHADY_METHODS && cProto.appendChild && cProto.cloneNode && cProto.contains && cProto.getRootNode && cProto.insertBefore && cProto.querySelector && cProto.querySelectorAll && cProto.removeAttribute && cProto.removeChild && cProto.replaceChild && cProto.setAttribute && cProto.is === undefined && !(cProto instanceof Node)) {
  2196. if (!cProto.krmv757) {
  2197. cProto.krmv757 = true;
  2198. // const props = Object.entries(Object.getOwnPropertyDescriptors(cProto)).filter(a => {
  2199. // const e = a[1];
  2200. // return typeof e.value === 'function' && e.writable === true && e.enumerable === true && e.configurable === true
  2201. // });
  2202. // const keys = props.map(a => a[0]);
  2203. const keys = ['querySelector', 'querySelectorAll'];
  2204. keys.forEach(key => {
  2205. if (!(key in HTMLTitleElement.prototype)) return;
  2206. const bey = `${key}588`;
  2207. cProto[bey] = cProto[key];
  2208. const isDomChange = key === 'appendChild' || key === 'insertBefore' || key === 'removeChild' || key === 'replaceChild';
  2209. cProto[key] = function () {
  2210. const p = ((this || 0).root || 0).node;
  2211. if (!isDomChange && (p instanceof Element) && p.nodeType === 1) {
  2212. return p[key](...arguments);
  2213. } else {
  2214. return this[bey](...arguments);
  2215. }
  2216. }
  2217. });
  2218. }
  2219. }
  2220.  
  2221. 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];
  2222. constructAts.add(constructAt)
  2223.  
  2224. if (MemoryFix_Flag002 & 32) {
  2225. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  2226. fixDetachFn(cProto);
  2227. }
  2228. }
  2229.  
  2230. if (MemoryFix_Flag002 & 2) {
  2231. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  2232. cProto.__setPropDX38__ = true;
  2233.  
  2234. if (cProto._setPendingProperty.length === 3) {
  2235. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  2236. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  2237. return () => {
  2238. const obj = kRef(wobj);
  2239. let u = Reflect.apply(this, obj, args);
  2240. args.length = 0;
  2241. wobj = null;
  2242. return u;
  2243. };
  2244. });
  2245. }
  2246.  
  2247. }
  2248. }
  2249.  
  2250.  
  2251. const cProtoConstructor = cProto.constructor;
  2252.  
  2253. if (MemoryFix_Flag002 & 8) {
  2254. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  2255. cProtoConstructor.__parseBindingsDX38__ = true;
  2256.  
  2257. ydMap.add(cProtoConstructor);
  2258.  
  2259. if (cProtoConstructor._parseBindings.length === 2) {
  2260.  
  2261. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  2262.  
  2263. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  2264. let p = this._parseBindings3858(c, d);
  2265. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  2266. if (p) this.__bindingsArrs__.push(p);
  2267. return p;
  2268. });
  2269.  
  2270. }
  2271. }
  2272. }
  2273.  
  2274. /*
  2275. a.prototype._initializeProperties = function() {
  2276. if (Em && this.hasAttribute("disable-upgrade"))
  2277. this.__isUpgradeDisabled = !0;
  2278. else {
  2279. var e = Object.getPrototypeOf(this);
  2280. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  2281. e.__hasRegisterFinished = !0);
  2282. b.prototype._initializeProperties.call(this);
  2283. this.root = this;
  2284. this.created();
  2285. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  2286. this._applyListeners()
  2287. }
  2288. }
  2289. */
  2290. /*
  2291. bOa = function(a, b, c) {
  2292. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  2293. d.prototype.is = b;
  2294. d.prototype.localName = b;
  2295. c && aOa(d, c);
  2296. return function(e) {
  2297. e && (d.prototype.hostElement = e);
  2298. var g = new d;
  2299. g.root = g;
  2300. g.hostElement = e;
  2301. return g
  2302. }
  2303. }
  2304. */
  2305.  
  2306.  
  2307. }
  2308. const symDH = Symbol();
  2309.  
  2310. const wfStore = new WeakMap();
  2311.  
  2312. const wrapF = function (f, key) {
  2313. if (wfStore.get(f)) return wfStore.get(f);
  2314.  
  2315. let g = function () {
  2316. const o = kRef(this);
  2317. if (!o) return;
  2318. const cnt = insp(o);
  2319. // if (cnt === o) return;
  2320. // if (!('ready' in cnt)) return;
  2321. return f.apply(o, arguments);
  2322. };
  2323. g.key38 = key;
  2324. g.originalFunc38 = f;
  2325. g.__wrapF84__ = true;
  2326. wfStore.set(f, g);
  2327. wfStore.set(g, g);
  2328. return g;
  2329. };
  2330.  
  2331. if (MemoryFix_Flag002 & 16) {
  2332. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  2333.  
  2334. Object.defineProperty(Node.prototype, key, {
  2335. get() {
  2336. return this[`__a0939${key}__`];
  2337. },
  2338. set(nv) {
  2339. if (typeof nv !== 'function') return;
  2340. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  2341. this[`__a0939${key}__`] = g;
  2342. return true;
  2343. }
  2344. });
  2345.  
  2346.  
  2347. });
  2348. }
  2349.  
  2350.  
  2351.  
  2352. // const wm = new WeakMap();
  2353.  
  2354. const fixDetachFn = (tpProto) => { // & 32
  2355.  
  2356. if (tpProto.dk322) return;
  2357. tpProto.dk322 = true;
  2358.  
  2359. window.__fixTemplateReuse1058__ = true;
  2360.  
  2361.  
  2362. tpProto.__ensureTemplatized994 = tpProto.__ensureTemplatized;
  2363. if (typeof tpProto.__ensureTemplatized994 === 'function' && tpProto.__ensureTemplatized994.length === 0) {
  2364. tpProto.__ensureTemplatized = function () {
  2365. // console.log(18470001)
  2366. return this.__ensureTemplatized994();
  2367. }
  2368. }
  2369.  
  2370.  
  2371. tpProto.__updateInstances994 = tpProto.__updateInstances;
  2372. if (typeof tpProto.__updateInstances994 === 'function' && tpProto.__updateInstances994.length === 3) {
  2373. let bypass= false;
  2374. tpProto.__updateInstances = function (a, b, c) {
  2375.  
  2376. // const a_ = [...a];
  2377. if(!bypass && a === this.items && (a||0).length >=1 ){
  2378.  
  2379. bypass = true;
  2380. // console.log(18470002, a, b,c)
  2381. let e;
  2382. for (e = 0; e < b; e++) {
  2383. let g = this.__instances[e]
  2384. , k = c[e]
  2385. , m = a[k];
  2386. if(g && typeof (m||0) === 'object'){
  2387. // const q = g._shouldPropertyChange;
  2388. // g._shouldPropertyChange = ()=>true;
  2389. // g[this.as] = {};
  2390. // a_[k]=a[k] = m;
  2391. // g[this.as] = m;
  2392.  
  2393. // use public interface notifyPath instead of internal interface _setPendingProperty
  2394. const m_ = a[k] = Object.assign({}, a[k]);
  2395. try {
  2396. g.notifyPath(this.as, {});
  2397. } catch (e) { }
  2398. try {
  2399. g.notifyPath(this.as, m_);
  2400. } catch (e) { }
  2401.  
  2402. // g._setPendingProperty(this.as, {});
  2403. // g._setPendingProperty(this.as, m);
  2404. // g._setPendingProperty(this.indexAs, e);
  2405. // g._setPendingProperty(this.itemsIndexAs, k);
  2406. // delete g._shouldPropertyChange;
  2407. // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2408. }
  2409. }
  2410. bypass = false;
  2411.  
  2412. }
  2413. const r = this.__updateInstances994(a,b,c);
  2414.  
  2415. // for (e = 0; e < b; e++) {
  2416. // let g = this.__instances[e]
  2417. // , k = c[e]
  2418. // , m = a_[k];
  2419. // if(g){
  2420. // // const q = g._shouldPropertyChange;
  2421. // // g._shouldPropertyChange = ()=>true;
  2422. // // g[this.as] = m;
  2423. // // g._setPendingProperty(this.as, {});
  2424. // // g._setPendingProperty(this.as, m);
  2425. // // g._setPendingProperty(this.indexAs, e);
  2426. // // g._setPendingProperty(this.itemsIndexAs, k);
  2427. // // delete g._shouldPropertyChange;
  2428. // // if(g._shouldPropertyChange !== q) g._shouldPropertyChange = q;
  2429. // }
  2430. // }
  2431.  
  2432. return r;
  2433. }
  2434. }
  2435.  
  2436. tpProto.__detachInstance994 = tpProto.__detachInstance;
  2437. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  2438. tpProto.__detachInstance = function (a) {
  2439. const u = this.__instances[a];
  2440. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2441. const children = (u || 0).children;
  2442. if (children && children.length >= 1) {
  2443. const pp = document.createDocumentFragment();
  2444. for (const s of [...children]) {
  2445. pp.appendChild(s);
  2446. }
  2447. }
  2448. try {
  2449. return this.__detachInstance994(a);
  2450. } catch (e) { }
  2451. return u;
  2452. }
  2453. }
  2454.  
  2455. tpProto.__attachInstance994 = tpProto.__attachInstance;
  2456. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  2457. tpProto.__attachInstance = function (a, b) {
  2458. const u = this.__instances[a];
  2459. if (u && !u.__keepInstance038__) u.__keepInstance038__ = true;
  2460. if (u && u.root && b) {
  2461. const root = u.root;
  2462. const pp = document.createDocumentFragment();
  2463. pp.appendChild(root);
  2464. root.appendChild(pp);
  2465. const r = this.__attachInstance994(a, b);
  2466. if (!this.__chunkingId) this.__chunkingId = 0.25;
  2467. return r;
  2468. }
  2469. }
  2470. }
  2471.  
  2472. }
  2473.  
  2474. const ytTemplateDomEntry = (tpProto) => {
  2475.  
  2476. console.log('ytTemplateDomEntry triggered')
  2477.  
  2478.  
  2479. const convertToWeakArr = (arr) => {
  2480.  
  2481. if (arr.isWeak) return;
  2482.  
  2483. for (let i = 0, l = arr.length; i < l; i++) {
  2484. const o = arr[i]
  2485. if (o) {
  2486. let p = kRef(o)
  2487. if (!p) arr[i] = null;
  2488. else {
  2489. if (!o[wk]) o[wk] = mWeakRef(o);
  2490. arr[i] = o[wk];
  2491. }
  2492. }
  2493. }
  2494. arr.isWeak = true;
  2495.  
  2496. }
  2497.  
  2498. const convertToNormalArr = (arr) => {
  2499.  
  2500. if (!arr.isWeak) return;
  2501.  
  2502. for (let i = 0, l = arr.length; i < l; i++) {
  2503. const o = arr[i]
  2504. if (o) {
  2505. let p = kRef(o)
  2506. arr[i] = p;
  2507. }
  2508. }
  2509. arr.isWeak = false;
  2510.  
  2511. }
  2512.  
  2513. if (MemoryFix_Flag002 & 256) {
  2514. Object.defineProperty(tpProto, '__instances', {
  2515. get() {
  2516. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2517. let arr = this.__instances_actual471__;
  2518. if (arr && arr.isWeak) {
  2519. convertToNormalArr(arr);
  2520. for (let i = arr.length - 1; i >= 0; i--) {
  2521. const t = arr[i];
  2522. if (!t) arr.splice(i, 1);
  2523. else if (!t.__keepInstance038__) t.__keepInstance038__ = true;
  2524. }
  2525. Promise.resolve(arr).then(convertToWeakArr);
  2526. }
  2527. return arr;
  2528. },
  2529. set(nv) {
  2530. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  2531. this.__instances_actual471__ = nv;
  2532. if (nv && !nv.isWeak) {
  2533. Promise.resolve(nv).then(convertToWeakArr);
  2534. }
  2535. return true;
  2536. },
  2537. enumerable: false,
  2538. configurable: true
  2539. });
  2540. }
  2541.  
  2542. // console.log(91901, tpProto.__detachInstance)
  2543. if (MemoryFix_Flag002 & 32) {
  2544. if (tpProto.__detachInstance) {
  2545. fixDetachFn(tpProto);
  2546. } else {
  2547. Promise.resolve(tpProto).then((tpProto) => {
  2548. // console.log(91902, tpProto.__detachInstance)
  2549. fixDetachFn(tpProto);
  2550. })
  2551. }
  2552. }
  2553.  
  2554. }
  2555.  
  2556. if (MemoryFix_Flag002 & 32) {
  2557. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  2558. set(nv) {
  2559. if (nv === true) return false;
  2560. tpProto = this;
  2561. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  2562. tpProto.__domDX37__ = true;
  2563. ytTemplateDomEntry(tpProto);
  2564. }
  2565. this.__ensureTemplatized949__ = nv;
  2566. return true;
  2567. },
  2568. get() {
  2569. return this.__ensureTemplatized949__;
  2570. }
  2571. });
  2572. }
  2573.  
  2574.  
  2575. if (MemoryFix_Flag002 & 64) {
  2576. HTMLElement_.prototype.__dataHostBinding374 = true;
  2577. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  2578. get() {
  2579. return kRef(this.__dataHostWr413__);
  2580. },
  2581. set(nv) {
  2582. if (nv && typeof nv === 'object' && !nv.deref) {
  2583. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2584. nv = nv[wk];
  2585. }
  2586. this.__dataHostWr413__ = nv;
  2587. return true;
  2588. }
  2589. });
  2590. }
  2591.  
  2592.  
  2593. const setupYProto = function (yProto) {
  2594.  
  2595. if(yProto === Object.prototype) return;
  2596.  
  2597. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  2598. yProto[kMap.get(yProto)] = true;
  2599.  
  2600. if (FIX_DOM_IF_DETACH && !yProto.disconnectedCallback277 && yProto.disconnectedCallback && typeof yProto._readyClients === 'function' && typeof yProto._canApplyPropertyDefault === 'function' && typeof yProto._attachDom === 'function' && !yProto.is && typeof yProto.constructor._finalizeTemplate === 'function') {
  2601. const disconnectedCallback277 = yProto.disconnectedCallback;
  2602. yProto.disconnectedCallback277 = true;
  2603. yProto.disconnectedCallback = function () {
  2604. disconnectedCallback277.call(this);
  2605. if (this.nodeName === 'DOM-IF' && this.__instance && typeof this.__teardownInstance === 'function') {
  2606. const shadyParent = (this.__shady_parentNode || 0);
  2607. const actualParent = (this.parentNode || 0);
  2608. if (shadyParent !== actualParent && shadyParent.nodeType === 11 && actualParent.nodeType === 11) {
  2609. // && (shadyParent.compareDocumentPosition(actualParent) & (1|8|16) === 1)
  2610. // if (!this.restamp && !this.id && this.__ctor && this.isConnected === false) {
  2611. const children = (this.__instance.children || 0).length;
  2612. if (children >= 1) {
  2613. try {
  2614. this.__teardownInstance();
  2615. } catch (e) { }
  2616. }
  2617. // }
  2618. }
  2619. }
  2620. }
  2621. }
  2622.  
  2623.  
  2624. if (MemoryFix_Flag002 & 32) {
  2625. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  2626. fixDetachFn(yProto);
  2627. }
  2628. }
  2629.  
  2630. if (MemoryFix_Flag002 & 128) {
  2631. if (!yProto.__dataHostBinding374) {
  2632. yProto.__dataHostBinding374 = true;
  2633. Object.defineProperty(yProto, '__dataHost', {
  2634. set(nv) {
  2635. let dh = nv;
  2636. if (dh && typeof dh === 'object' && !dh.deref) {
  2637. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  2638. dh = wr;
  2639. }
  2640. this[symDH] = dh;
  2641. return true;
  2642. },
  2643. get() {
  2644. let wr = this[symDH];
  2645. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  2646. return obj;
  2647. },
  2648. enumerable: false,
  2649. configurable: true
  2650. });
  2651. }
  2652.  
  2653.  
  2654.  
  2655. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  2656. yProto._registerHostDX38__ = true;
  2657.  
  2658. // yProto._registerHost7133 = yProto._registerHost;
  2659.  
  2660. yProto.__enableOrFlushClients = function () {
  2661. const c_ = this.__dataPendingClients;
  2662. if (c_) {
  2663. const c = c_.slice();
  2664. c_.length = 0;
  2665. for (let d = 0, l = c.length; d < l; d++) {
  2666. let e = kRef(c[d]);
  2667. if (e) {
  2668. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  2669. }
  2670. }
  2671. }
  2672. }
  2673.  
  2674. yProto._enqueueClient = function (c) {
  2675. if (c === this || !c || typeof c !== 'object') return;
  2676. if (c.deref) c = kRef(c);
  2677. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  2678. if (!c[wk]) c[wk] = mWeakRef(c);
  2679. m.push(c[wk]);
  2680. }
  2681.  
  2682. }
  2683. }
  2684.  
  2685.  
  2686.  
  2687. }
  2688. const setupRendering = function () {
  2689.  
  2690. const cnt = this;
  2691. const cProto = Reflect.getPrototypeOf(cnt);
  2692. let yProto = Reflect.getPrototypeOf(cProto);
  2693.  
  2694. const yProtos = new Set();
  2695.  
  2696. if (!yMap.has(yProto)) {
  2697. // capture all ancenstor constructors of a and b (non-specific component type)
  2698.  
  2699. do {
  2700. if (yProto === Object.prototype || yProto === null) break;
  2701. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  2702. yProtos.add(yProto);
  2703. yProto = Reflect.getPrototypeOf(yProto);
  2704. } while (!yProtos.has(yProto));
  2705.  
  2706. for (const yProto of yProtos) {
  2707. yMap.add(yProto);
  2708. setupYProto(yProto)
  2709. }
  2710.  
  2711. }
  2712.  
  2713.  
  2714. if (!cMap.has(cProto)) {
  2715. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  2716. setupCProto(cProto);
  2717. }
  2718.  
  2719. }
  2720.  
  2721. /*
  2722.  
  2723. jF = function(M) {
  2724. var d = YNV.call(this) || this;
  2725. d._configureProperties(M);
  2726. d.root = d._stampTemplate(d.__dataHost);
  2727. var N = [];
  2728. d.children = N;
  2729. for (var R = d.root.firstChild; R; R = R.nextSibling)
  2730. N.push(R),
  2731. R.__templatizeInstance = d;
  2732. d.__templatizeOwner && d.__templatizeOwner.__hideTemplateChildren__ && d._showHideChildren(!0);
  2733. N = d.__templatizeOptions;
  2734. (M && N.instanceProps || !N.instanceProps) && d._enableProperties();
  2735. return d
  2736. };
  2737. */
  2738.  
  2739. const sb1 = Symbol();
  2740. Object.defineProperty(Object.prototype, 'root', {
  2741. get() {
  2742. return this[sb1];
  2743. },
  2744. set(nv){
  2745. const p = this ? kRef(this) : null;
  2746. const mv = nv ? kRef(nv) : null;
  2747.  
  2748. // if (typeof (this.host || 0) === 'object' && !this.host6833) {
  2749. // const host = this.host;
  2750. // if (!host[wk]) host[wk] = mWeakRef(host);
  2751. // this.host6833 = host[wk];
  2752. // delete this.host;
  2753. // console.log(21883, host)
  2754. // Object.defineProperty(this, 'host', {
  2755. // get() {
  2756. // return kRef(this.host6833);
  2757. // },
  2758. // set(nv) {
  2759. // if (!nv) {
  2760. // this.host6833 = nv;
  2761. // } else {
  2762. // if (!nv[wk]) nv[wk] = mWeakRef(nv);
  2763. // this.host6833 = nv[wk];
  2764. // }
  2765. // return true;
  2766. // }, enumerable: false, configurable: true
  2767. // });
  2768. // }
  2769.  
  2770. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  2771. p.__setupRendered399__ = true;
  2772. setupRendering.call(p);
  2773. }
  2774. if (mv && mv.is && !mv.__setupRendered399__) {
  2775. mv.__setupRendered399__ = true;
  2776. setupRendering.call(mv);
  2777. }
  2778.  
  2779. this[sb1] = nv;
  2780. return true;
  2781. }
  2782. });
  2783.  
  2784.  
  2785. }
  2786.  
  2787. let _cssSheet = null;
  2788. const addNewCSS = typeof CSSStyleSheet !== 'undefined' && document.adoptedStyleSheets ? (css) => {
  2789. if (!_cssSheet) {
  2790. _cssSheet = new CSSStyleSheet();
  2791. document.adoptedStyleSheets.push(_cssSheet);
  2792. }
  2793. _cssSheet.insertRule(`${css}`);
  2794. } : (css) => {
  2795. let nonce = document.querySelector('style[nonce]');
  2796. nonce = nonce ? nonce.getAttribute('nonce') : null;
  2797. const st = document.createElement('style');
  2798. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  2799. st.textContent = `${css}`;
  2800. let parent;
  2801. if (parent = document.head) parent.appendChild(st);
  2802. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  2803. }
  2804.  
  2805. function getTranslate() {
  2806.  
  2807. pLoad.then(() => {
  2808. addNewCSS(".yt-formatted-string-block-line{display:block;}");
  2809. });
  2810.  
  2811. const snCache = new Map();
  2812.  
  2813. if (TRANSLATE_DEBUG) {
  2814. console.log(11)
  2815. }
  2816.  
  2817. /** @type {(str: string?) => string} */
  2818. function _snippetText(str) {
  2819. // str can be underfinded
  2820. if (!str || typeof str !== 'string') return '';
  2821. let res = snCache.get(str);
  2822. if (res === undefined) {
  2823. let b = false;
  2824. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  2825. b = true;
  2826. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  2827. });
  2828. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  2829. b = true;
  2830. return '';
  2831. });
  2832. if (b) {
  2833. snCache.set(str, res);
  2834. snCache.set(res, null);
  2835. } else {
  2836. res = null;
  2837. snCache.set(str, null);
  2838. }
  2839. }
  2840. return res === null ? str : res;
  2841. }
  2842.  
  2843. /** @type {(snippet: Object) => string} */
  2844. function snippetText(snippet) {
  2845. let runs = snippet.runs;
  2846. const n = runs.length;
  2847. if (n === 1) return _snippetText(runs[0].text);
  2848. let res = new Array(n);
  2849. let ci = 0;
  2850. for (const s of runs) {
  2851. res[ci++] = _snippetText(s.text);
  2852. }
  2853. return res.join('\n');
  2854. }
  2855.  
  2856. const _DEBUG_szz = (t) => t.map(x => {
  2857. const tsr = x.transcriptSegmentRenderer;
  2858. return ({
  2859. t: tsr.snippet.runs.map(x => x.text).join('//'),
  2860. a: tsr.startMs,
  2861. b: tsr.endMs
  2862. });
  2863. });
  2864.  
  2865. const fixRuns = (runs) => {
  2866. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  2867. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  2868. const text = runs[0].text;
  2869. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  2870. const s = text.split(nlc);
  2871. let bi = 0;
  2872. runs.length = s.length;
  2873. for (const text of s) {
  2874. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  2875. }
  2876. }
  2877. for (const s of runs) {
  2878. s.text = _snippetText(s.text);
  2879. }
  2880. }
  2881.  
  2882. function translate(initialSegments) {
  2883. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  2884.  
  2885. if (!initialSegments) return initialSegments;
  2886.  
  2887. if (TRANSLATE_DEBUG) {
  2888. console.log(12);
  2889. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  2890. let obj = JSON.parse(r);
  2891. console.log(7558, 1, obj)
  2892. return obj;
  2893. }).then(p => {
  2894. let obj = _DEBUG_szz(p)
  2895. console.log(7558, 2, obj)
  2896. })
  2897. }
  2898.  
  2899.  
  2900. //let mapRej = new WeakSet();
  2901.  
  2902. const n1 = initialSegments.length;
  2903. if (!n1) return fRes;
  2904. let n2 = 0;
  2905.  
  2906.  
  2907. const fRes = new Array(n1);
  2908. // -----------------------------------------------------------------------------------------
  2909.  
  2910. const s8 = Symbol();
  2911.  
  2912. {
  2913.  
  2914. /** @type {Map<String, Object>} */
  2915. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  2916.  
  2917. // /-* * @type {Map<String, number>} *-/
  2918. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  2919. // 1: ok
  2920. // 2: abandoned effect text
  2921.  
  2922. for (const initialSegment of initialSegments) {
  2923. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  2924. if (!transcript) {
  2925. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  2926. fRes[n2++] = initialSegment;
  2927. continue;
  2928. }
  2929. const runs = transcript.snippet.runs
  2930. if (!runs || runs.length === 0) {
  2931. initialSegment[s8] = true;
  2932. continue;
  2933. }
  2934. let startMs = (+transcript.startMs || 0); //integer
  2935. let endMs = (+transcript.endMs || 0); //integer
  2936. if (startMs === endMs) {
  2937. // effect text
  2938. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  2939. //mapRej.add(initialSegment)
  2940. continue;
  2941. }
  2942. if (endMs - startMs < 30) {
  2943. continue;
  2944. }
  2945. const text = snippetText(transcript.snippet);
  2946. const hEntry = cacheTexts.get(text);
  2947. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  2948. if (mh1e === 2) continue;
  2949. const entry = {
  2950. startMs,
  2951. endMs,
  2952. initialSegment,
  2953. text
  2954. };
  2955. if (mh1e === 0) {
  2956. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  2957. initialSegment[s8] = true;
  2958. cacheTexts.set(text, null);
  2959. //effect only
  2960. // https://www.youtube.com/watch?v=zLak0dxBKpM
  2961. //mapRej.add(initialSegment)
  2962. continue;
  2963. }
  2964. } else if (hEntry) {
  2965.  
  2966. const timeDiff = entry.startMs - hEntry.endMs;
  2967. let shouldMerge = false;
  2968.  
  2969. if (timeDiff >= 0) {
  2970.  
  2971. if (timeDiff < 25) {
  2972. shouldMerge = true;
  2973. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  2974. shouldMerge = true;
  2975. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  2976. shouldMerge = true;
  2977. }
  2978.  
  2979. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  2980. // abandon the current entry.
  2981. // absorbed by previous entry
  2982. hEntry.endMs = entry.endMs;
  2983. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2984. //mapRej.add(entry.initialSegment);
  2985. continue;
  2986. }
  2987.  
  2988. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  2989.  
  2990. // abandon the current entry.
  2991. // absorbed by previous entry
  2992. if (entry.endMs > hEntry.endMs) {
  2993. hEntry.endMs = entry.endMs;
  2994. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  2995. }
  2996. //mapRej.add(entry.initialSegment);
  2997. continue;
  2998.  
  2999. }
  3000.  
  3001. }
  3002. //if not abandoned
  3003. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  3004. // for (const s of runs) {
  3005. // s.text = _snippetText(s.text);
  3006. // }
  3007. fixRuns(runs);
  3008. fRes[n2++] = initialSegment;
  3009. }
  3010.  
  3011. // cacheTexts.clear(); // let GC do it.
  3012. cacheTexts = null;
  3013. // mh1.clear(); // let GC do it.
  3014. // mh1 = null;
  3015.  
  3016. }
  3017.  
  3018. const si_length = fRes.length = n2;
  3019. const sj_length = n1;
  3020.  
  3021. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  3022. // collect the abandon text to become second subtitle
  3023.  
  3024. let sj_start = 0;
  3025. let invalid_sj = -1;
  3026. for (let si = 0; si < si_length; si++) {
  3027. const segment = fRes[si];
  3028. let transcript = segment.transcriptSegmentRenderer;
  3029. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  3030. const runs = transcript.snippet.runs;
  3031. // fixRuns(runs);
  3032. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  3033. const main_startMs = (+transcript.startMs || 0);
  3034. const main_endMs = (+transcript.endMs || 0);
  3035. transcript = null;
  3036.  
  3037. /** @type {Map<string, number>} */
  3038. let tMap = new Map(); // avoid duplicate with javascript object properties
  3039.  
  3040. // assume that it is asc-ordered array of key startMs;
  3041. for (let sj = sj_start; sj < sj_length; sj++) {
  3042. const initialSegment = initialSegments[sj];
  3043.  
  3044. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  3045.  
  3046. const tSegment = initialSegment.transcriptSegmentRenderer;
  3047.  
  3048. if (!tSegment) {
  3049. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  3050. invalid_sj = sj; // should invalid_sj be set ?
  3051. continue;
  3052. }
  3053.  
  3054. const startMs = (+tSegment.startMs || 0)
  3055. const isStartValid = startMs >= main_startMs;
  3056. if (!isStartValid) {
  3057. invalid_sj = sj;
  3058. continue;
  3059. }
  3060. // isStartValid must be true
  3061. if (startMs > main_endMs) {
  3062. sj_start = invalid_sj + 1;
  3063. break;
  3064. }
  3065.  
  3066. const endMs = (+tSegment.endMs || 0)
  3067. if (endMs <= main_endMs) {
  3068. const mt = snippetText(tSegment.snippet);
  3069. const prev = tMap.get(mt);
  3070. if (endMs >= startMs) {
  3071. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  3072. }
  3073. }
  3074.  
  3075. }
  3076.  
  3077. if (tMap.size <= 1) continue; // no second line
  3078. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  3079. tMap = null;
  3080.  
  3081. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  3082.  
  3083. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  3084.  
  3085. let targetZ = rg[1][1];
  3086. if (targetZ > 4) {
  3087. let az = 0;
  3088. let fail = false;
  3089. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  3090. az += rg[idx][1];
  3091. if (az >= targetZ) {
  3092. fail = true;
  3093. break;
  3094. }
  3095. }
  3096. if (!fail) {
  3097. const rgA = rg[0][0];
  3098. const rgB = rg[1][0];
  3099. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  3100. if (isDiff && rgA === _snippetText(runs[0].text)) {
  3101. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  3102. runs.push({ text: rgB, blockLine: true });
  3103. }
  3104. }
  3105. }
  3106. rg = null;
  3107. }
  3108.  
  3109. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  3110.  
  3111. let obj = r;
  3112. console.log(7559, 1, obj)
  3113. return obj;
  3114. }).then(p => {
  3115. let obj = _DEBUG_szz(p)
  3116. console.log(7559, 2, obj)
  3117.  
  3118. });
  3119. }
  3120.  
  3121. // -----------------------------------------------------------------------------------------
  3122. snCache.clear();
  3123. return fRes;
  3124.  
  3125. }
  3126.  
  3127.  
  3128. return translate
  3129.  
  3130. }
  3131.  
  3132.  
  3133. let translateFn = null;
  3134.  
  3135. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  3136.  
  3137. const wmx = new WeakMap();
  3138.  
  3139. function fixSegments(ytObj) {
  3140. let a, b;
  3141. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  3142. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  3143. translateFn = translateFn || getTranslate();
  3144. let cSeg;
  3145. cSeg = wmx.get(seg);
  3146. if (!cSeg) {
  3147. let vSeg = null;
  3148. try {
  3149. vSeg = translateFn(seg);
  3150. } catch (e) {
  3151. }
  3152. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  3153. // console.log('translated', vSeg);
  3154. cSeg = vSeg;
  3155. wmx.set(seg, cSeg);
  3156. wmx.set(cSeg, cSeg);
  3157. }
  3158. }
  3159. if (cSeg && cSeg !== seg) {
  3160. a[b] = cSeg;
  3161. }
  3162. }
  3163.  
  3164. const dfn = Symbol();
  3165. const Object_ = Object;
  3166. Object_[dfn] = Object_.defineProperties;
  3167. let activation = true;
  3168. Object_.defineProperties = function (obj, pds) {
  3169. let segments, get_;
  3170. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  3171. activation = false;
  3172. segments.get = function () {
  3173. fixSegments(this);
  3174. return get_.call(this);
  3175. };
  3176. }
  3177. return Object_[dfn](obj, pds);
  3178. };
  3179.  
  3180. })();
  3181.  
  3182.  
  3183. let pf31 = new PromiseExternal();
  3184.  
  3185. // native RAF
  3186. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  3187.  
  3188. // 1st wrapped RAF
  3189. const baseRAF = (callback) => {
  3190. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  3191. pf31.then(() => {
  3192. callback(hRes);
  3193. });
  3194. });
  3195. };
  3196.  
  3197. // 2nd wrapped RAF
  3198. window.requestAnimationFrame = baseRAF;
  3199.  
  3200. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  3201. const indr = o => insp(o).$ || o.$ || 0;
  3202. const inup = o => {
  3203. if (!o) return null;
  3204. let instance = null, t;
  3205. if ((t = o.__instance) && t.props) instance = t;
  3206. else if ((t = o.instance) && t.props) instance = t;
  3207. else if ((t = insp(o)) && t.props) instance = t;
  3208. else if ((t = (o)) && t.props) instance = t;
  3209. return instance;
  3210. };
  3211.  
  3212. const prototypeInherit = (d, b) => {
  3213. const m = Object.getOwnPropertyDescriptors(b);
  3214. for (const p in m) {
  3215. if (!Object.getOwnPropertyDescriptor(d, p)) {
  3216. Object.defineProperty(d, p, m[p]);
  3217. }
  3218. }
  3219. };
  3220.  
  3221.  
  3222. const firstObjectKey = (obj) => {
  3223. for (const key in obj) {
  3224. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  3225. }
  3226. return null;
  3227. };
  3228.  
  3229. function searchNestedObject(obj, predicate, maxDepth = 64) {
  3230. // normal case: depth until 36
  3231. const result = [];
  3232. const visited = new WeakSet();
  3233.  
  3234. function search(obj, depth) {
  3235. visited.add(obj);
  3236. for (const [key, value] of Object.entries(obj)) {
  3237. // Recursively search nested objects and arrays
  3238. if (value !== null && typeof value === 'object') {
  3239. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  3240. if (depth + 1 <= maxDepth && !visited.has(value)) {
  3241. search(value, depth + 1);
  3242. }
  3243. } else if (predicate(value)) {
  3244. result.push([obj, key]);
  3245. }
  3246. }
  3247. }
  3248.  
  3249. typeof (obj || 0) === 'object' && search(obj, 0);
  3250. return result;
  3251. }
  3252.  
  3253. /** @type {(o: Object | null) => WeakRef | null} */
  3254. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  3255.  
  3256. /** @type {(wr: Object | null) => Object | null} */
  3257. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  3258.  
  3259. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  3260.  
  3261. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  3262. if (DENY_requestStorageAccess) {
  3263. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  3264. Document.prototype.requestStorageAccessFor = undefined;
  3265. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  3266. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  3267. Document.prototype.requestStorageAccessFor = function () {
  3268. return new Promise((resolve, reject) => {
  3269. reject();
  3270. });
  3271. };
  3272. }
  3273. }
  3274.  
  3275. const traceStack = (stack) => {
  3276. let result = new Set();
  3277. let p = new Set();
  3278. let u = ''
  3279. for (const s of stack.split('\n')) {
  3280. if (s.split(':').length < 3) continue;
  3281. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  3282. if (!m) continue;
  3283. p.add(m[2]);
  3284. if (p.size >= 3) break;
  3285. if(!u) u = m[2];
  3286. else if(p.size === 2 && u && u=== m[2]) break;
  3287. result.add(s);
  3288. }
  3289. return [...result].join('\n');
  3290. }
  3291.  
  3292. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  3293. // window.m3bb = new Set();
  3294.  
  3295. // const smb = Symbol();
  3296. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  3297. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  3298. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  3299.  
  3300. const thisConversionFn = (thisArg) => {
  3301. if (!thisArg) return null;
  3302. const kThis = thisArg[vmb];
  3303. if (kThis) {
  3304. const ref = kThis.ref;
  3305. return (ref ? kRef(ref) : null) || null;
  3306. }
  3307. return thisArg;
  3308. }
  3309.  
  3310. const pFnHandler2 = {
  3311. get(target, prop) {
  3312. if (prop === vmc) return target;
  3313. return Reflect.get(target, prop);
  3314. },
  3315. apply(target, thisArg, argumentsList) {
  3316. thisArg = thisConversionFn(thisArg);
  3317. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  3318. }
  3319. }
  3320.  
  3321.  
  3322. const proxySelfHandler = {
  3323. get(target, prop) {
  3324. if(prop === vmb) return target;
  3325. const ref = target.ref;
  3326. const cnt = kRef(ref);
  3327. if (!cnt) return;
  3328. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  3329. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  3330. return cnt[prop][vmd];
  3331. }
  3332. return cnt[prop];
  3333. },
  3334. set(target, prop, value) {
  3335. const cnt = kRef(target.ref);
  3336. if (!cnt) return true;
  3337. if(value && (value[vmc] || value[vmb])){
  3338. cnt[prop] = value[vmc] || thisConversionFn(value);
  3339. return true;
  3340. }
  3341. cnt[prop] = value;
  3342. return true;
  3343. }
  3344. };
  3345.  
  3346. const weakWrap = (thisArg) => {
  3347. thisArg = thisConversionFn(thisArg);
  3348. if (!thisArg) {
  3349. console.error('thisArg is not found');
  3350. return null;
  3351. }
  3352. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  3353. }
  3354.  
  3355. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  3356. window.getComputedStyle533 = window.getComputedStyle;
  3357. window.getComputedStyle = function (a, ...args) {
  3358. a = thisConversionFn(a);
  3359. if (a) {
  3360. return getComputedStyle533(a, ...args);
  3361. }
  3362. return null;
  3363. }
  3364. }
  3365.  
  3366. Function._count_bind_00 = 0;
  3367. // Function._count_bind_01 = 0;
  3368.  
  3369. // let matchNativeCode = (Object+"");
  3370. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  3371. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  3372.  
  3373. // const matchConstructor = (thisArg) => {
  3374. // const f = `${(thisArg || 0).constructor}`;
  3375. // if (f.length > 45) return true;
  3376. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  3377. // if (f.includes('[native code]')){
  3378. // return false;
  3379. // }
  3380. // return true;
  3381. // }
  3382. // return false;
  3383. // }
  3384.  
  3385. // const acceptThis = (thisArg)=>{
  3386. // // if(!thisArg || typeof thisArg !=='object') return false;
  3387. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  3388. // // if(typeof thisArg.path === 'string') return true;
  3389. // // if(typeof thisArg.fn === 'function') return true;
  3390. // // if(typeof thisArg.id === 'string') return true;
  3391. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  3392. // return false;
  3393. // }
  3394.  
  3395. const patchFn = (fn) => {
  3396.  
  3397. let s = `${fn}`;
  3398. if (s.length < 11 || s.includes('\n')) return false;
  3399. if(s.includes('bind(this')) return true;
  3400. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  3401. // var a=this;
  3402. // f.bind(this)
  3403.  
  3404.  
  3405. return false;
  3406. }
  3407.  
  3408. Function.prototype.bind488 = Function.prototype.bind;
  3409. Function.prototype.bind = function(thisArg, ...args){
  3410.  
  3411. if (thisConversionFn(thisArg) !== thisArg) {
  3412. return this.bind488(thisArg, ...args);
  3413. }
  3414. if( thisArg && patchFn(this) ){
  3415.  
  3416. // console.log(599,`${this}`)
  3417.  
  3418. try {
  3419. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  3420. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  3421. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  3422. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  3423. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  3424. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  3425. // // let b4 = false;
  3426. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  3427.  
  3428. // // b3 = false;
  3429. // // b4 = false;
  3430. // // b5 = false;
  3431.  
  3432. // if (b1 || b2 || b3 ||b4 ) {
  3433. const f = this;
  3434. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  3435. if (ps && ps[vmb]) {
  3436. Function._count_bind_00++;
  3437. return f.bind488(ps, ...args)
  3438. }
  3439. // }
  3440. } catch (e) {
  3441. console.warn(e)
  3442. }
  3443. }
  3444. return this.bind488(thisArg, ...args);
  3445. }
  3446. Function.prototype.bind588 = 1;
  3447. }
  3448.  
  3449. const ytSchedulerMethods = {
  3450. addJob(a, b, c) {
  3451. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3452. if (instance) {
  3453. return instance.addJob(a, b, c);
  3454. } else {
  3455. return setTimeout(a, c);
  3456. }
  3457. },
  3458. addImmediateJob(a) {
  3459. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3460. if (instance) {
  3461. return instance.addImmediateJob(a);
  3462. } else {
  3463. a();
  3464. }
  3465. },
  3466. cancelJob(id) {
  3467. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  3468. if (instance) {
  3469. return instance.cancelJob(id);
  3470. } else {
  3471. return clearTimeout(id);
  3472. }
  3473. }
  3474. };
  3475.  
  3476. if (FIX_ytScheduler) {
  3477.  
  3478. let ytSchedulerFixed = 0;
  3479. // let ytActioned = false;
  3480. // let pr = new PromiseExternal();
  3481.  
  3482. // const hn = function () {
  3483.  
  3484. // document.removeEventListener('yt-action', hn, true);
  3485. // nextBrowserTick_(() => {
  3486. // ytActioned = true;
  3487. // pr.resolve();
  3488. // });
  3489.  
  3490. // }
  3491. // document.addEventListener('yt-action', hn, true);
  3492.  
  3493. // let cancelStore = {}; // tbc
  3494.  
  3495. // yt.scheduler.instance.addJob
  3496. const fixAddJob = (nv) => {
  3497.  
  3498. /*
  3499. function Z() {
  3500. var a = w("ytglobal.schedulerInstanceInstance_");
  3501. if (!a || a.s)
  3502. a = new M(I("scheduler") || {}),
  3503. x("ytglobal.schedulerInstanceInstance_", a);
  3504. return a
  3505. }
  3506. */
  3507.  
  3508. /*
  3509. function R(a, b, c, d) {
  3510. ++a.D;
  3511. if (c === 10)
  3512. return P(a, b),
  3513. a.D;
  3514. var e = a.D;
  3515. a.h[e] = b;
  3516. a.l && !d ? a.u.push({
  3517. id: e,
  3518. priority: c
  3519. }) : (a.i[c].push(e),
  3520. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  3521. a.start()));
  3522. return e
  3523. }
  3524. */
  3525.  
  3526. /*
  3527. function sa(a, b, c) {
  3528. if (!c)
  3529. return c = c === void 0,
  3530. -R(Z(), a, b, c);
  3531. var d = window.setTimeout(function() {
  3532. var e = R(Z(), a, b);
  3533. W[d] = e
  3534. }, c);
  3535. return d
  3536. }
  3537. */
  3538. window.originalAddJob = nv;
  3539. // const q1 = new PromiseExternal();
  3540. // const q2 = new PromiseExternal();
  3541. // let uu = 0;
  3542. // let q3 = 0;
  3543. // let mof = null;
  3544. // const mo = new MutationObserver((mutation, observer) => {
  3545. // if (mof) {
  3546. // if (mof() === true) {
  3547. // observer.disconnect();
  3548. // mof = null;
  3549. // }
  3550. // }
  3551. // });
  3552.  
  3553. let lenSkip = -1;
  3554. let lastLen = null;
  3555. let fetchCommentJobTimerId = 0;
  3556. let requestFinish = false;
  3557.  
  3558. const fetchCommentJobDone = ()=>{
  3559. clearInterval(fetchCommentJobTimerId);
  3560. fetchCommentJobTimerId = 0;
  3561. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3562. }
  3563.  
  3564. const fetchCommentJob = (a, cid) => {
  3565.  
  3566. // if (cid && cancelStore[cid]) return; // tbc
  3567.  
  3568. if(fetchCommentJobTimerId > 0){
  3569. fetchCommentJobDone();
  3570. }
  3571.  
  3572. // if (mof) {
  3573. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3574. // mof = null;
  3575. // }
  3576.  
  3577. let f = a;
  3578.  
  3579. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  3580.  
  3581. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  3582.  
  3583. lastLen = -1;
  3584. let u = 0;
  3585. let g = () => {
  3586. if (requestFinish) lastLen = -1;
  3587. const lastLen_ = lastLen;
  3588. const len1 = lastLen = document.querySelectorAll(selector).length;
  3589. let mm = true;
  3590. let ff = false;
  3591. if (len1 !== lastLen_) {
  3592. u = 0;
  3593. f();
  3594. const len2 = lastLen = document.querySelectorAll(selector).length;
  3595. if (len2 !== len1) {
  3596. ff = true;
  3597. mm = false;
  3598. }
  3599. }
  3600. if (mm) {
  3601. ++u;
  3602. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  3603. ff = true;
  3604. }
  3605. }
  3606.  
  3607. if (requestFinish) {
  3608. requestFinish = false;
  3609. fetchCommentJobDone();
  3610. } else if (ff){
  3611. fetchCommentJobDone();
  3612. }
  3613.  
  3614. }
  3615.  
  3616.  
  3617. fetchCommentJobTimerId = setInterval(g, 80);
  3618. // g(9);
  3619. // if (lastLen === lenSkip) {
  3620. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3621. // g = f = null;
  3622. // return;
  3623. // }
  3624. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  3625. // const q1 = lastLen;
  3626. // mof = () => {
  3627. // const q2 = document.querySelectorAll(selector).length;
  3628. // if (q1 === q2) return;
  3629. // fetchCommentJobTimerId = setTimeout(g, 80);
  3630. // g = null;
  3631. // return true;
  3632. // }
  3633. // mo.observe(document, { childList: true, subtree: true });
  3634.  
  3635. }
  3636.  
  3637. // let pr72 = Promise.resolve();
  3638.  
  3639.  
  3640. let qa = null;
  3641. let qasf = '';
  3642.  
  3643.  
  3644. document.addEventListener("fullscreenchange", (evt) => {
  3645. if (evt.isTrusted !== true) return;
  3646. if (qa) {
  3647. // qa();
  3648. nextBrowserTick_(qa);
  3649. }
  3650. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3651. // pr72 = pr72.then(() => {
  3652. // return pr
  3653. // });
  3654. }, true);
  3655.  
  3656. window.addEventListener("resize", (evt) => {
  3657. if (evt.isTrusted !== true) return;
  3658. if (qa) {
  3659. // qa();
  3660. nextBrowserTick_(qa);
  3661. }
  3662. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3663. // pr72 = pr72.then(() => {
  3664. // return pr
  3665. // });
  3666. }, true);
  3667.  
  3668.  
  3669. setInterval(() => {
  3670. const f = qa;
  3671. if (typeof f !== 'function') return;
  3672. qa = null;
  3673. // pr72 = pr72.then(() => {
  3674. // f();
  3675. // });
  3676. // nextBrowserTick_(()=>{
  3677. f();
  3678. // });
  3679. }, 475.25);
  3680.  
  3681.  
  3682.  
  3683. return function (a, b, c) {
  3684.  
  3685.  
  3686. const f = a;
  3687. // const g = ()=>{
  3688. // pr72 = pr72.then(()=>{
  3689. // f();
  3690. // });
  3691. // }
  3692.  
  3693. if (!c) return arguments.length < 3 ? nv(f, b) : nv(f, b, c);
  3694.  
  3695. const c_ = c;
  3696.  
  3697. if (c > 0.25 && (c % 1) === 0) c -= 0.125;
  3698.  
  3699. if (b === 1 && c_ === 500) {
  3700. const sf = `${a}`;
  3701. if (qasf ? (sf === qasf) : (sf.includes('.mediaElement') && sf.includes('.getCurrentTime') && sf.includes('.seekTo'))) {
  3702. qasf = sf;
  3703. qa = a;
  3704. // console.log(12883, a)
  3705. return nv(() => {
  3706. if (qa === a) {
  3707. qa = null;
  3708. a();
  3709. }
  3710. }, b, c);
  3711. }
  3712. }
  3713.  
  3714.  
  3715. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  3716. // console.log('[yt-js-engine-tamer] cleanupJob 01');
  3717. // const pr = new Promise(resolve => { setTimeout(resolve, 94.25) });
  3718. // pr72 = pr72.then(() => {
  3719. // return pr
  3720. // });
  3721. // try {
  3722. // yt.scheduler.instance.cancelAllJobs();
  3723. // yt.scheduler.instance.dispose();
  3724. // if(ytglobal.schedulerInstanceInstance_) ytglobal.schedulerInstanceInstance_.dispose();
  3725. // console.log('[yt-js-engine-tamer] cleanupJob 02');
  3726. // } catch (e) { }
  3727. return nv(f, b, c);
  3728. }
  3729.  
  3730. // if(!b && c > 50) c = 50;
  3731. // console.log(58372,a,b,c)
  3732. // function(){xxx(xxx)}
  3733. if (!b && c_ === 1000 && `${a}`.length <= 20 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  3734.  
  3735. /*
  3736.  
  3737. V.setCommentsJobId = _.et(_.r0, function() {
  3738. F5V(V)
  3739. }, 1E3)
  3740.  
  3741. */
  3742.  
  3743. requestFinish = false;
  3744. const cid = nv(() => { if(fetchCommentJobTimerId > 0) requestFinish = true;}, b, 1000);
  3745.  
  3746. // lastLen = null;
  3747. fetchCommentJob(a, cid);
  3748.  
  3749. // queueMicrotask_(a);
  3750. // nextBrowserTick_(a);
  3751. // a(); // no need to delay
  3752. return cid
  3753.  
  3754. // return nv(a, b, 1.125);
  3755. // const cid = window.setTimeout(() => {
  3756. // nextBrowserTick_(() => {
  3757. // if (cancelStore[cid]) {
  3758. // console.log('task cancelled');
  3759. // return;
  3760. // }
  3761. // a();
  3762.  
  3763. // });
  3764. // }, 0.125);
  3765. // return cid;
  3766. } else {
  3767.  
  3768.  
  3769.  
  3770. return nv(f,b,c);
  3771.  
  3772.  
  3773. // if (c > 2400) c = 2400;
  3774. // else if (c > 800) c = 800;
  3775. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  3776. // if (0 && ytActioned && !b) {
  3777. // const cid = window.setTimeout(() => {
  3778. // nextBrowserTick_(() => {
  3779. // if (cancelStore[cid]) {
  3780. // console.log('task cancelled');
  3781. // return;
  3782. // }
  3783. // a();
  3784. // });
  3785. // }, c);
  3786. // return cid;
  3787. // } else {
  3788. // return nv(a, b, c);
  3789. // }
  3790.  
  3791. }
  3792. }
  3793. }
  3794.  
  3795. const fixCancelJob = (nv) => {
  3796.  
  3797.  
  3798. window.originalCancelJob = nv;
  3799. return function (a) {
  3800. if (a < 0) return nv(a);
  3801. // cancelStore[a] = true; // tbc
  3802. nv(a);
  3803. }
  3804. }
  3805.  
  3806. const sk44 = Symbol();
  3807. Object.defineProperty(Object.prototype, 'addJob', {
  3808. get() {
  3809. return this[sk44];
  3810. },
  3811. set(nv) {
  3812. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3813. ytSchedulerFixed |= 1;
  3814. nv = fixAddJob(nv);
  3815. }
  3816. this[sk44] = nv;
  3817. return true;
  3818. },
  3819. enumerable: false,
  3820. configurable: true
  3821. });
  3822.  
  3823.  
  3824.  
  3825. const sk45 = Symbol();
  3826. Object.defineProperty(Object.prototype, 'cancelJob', {
  3827. get() {
  3828. return this[sk45];
  3829. },
  3830. set(nv) {
  3831. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3832. ytSchedulerFixed |= 2;
  3833. nv = fixCancelJob(nv);
  3834. }
  3835. this[sk45] = nv;
  3836. return true;
  3837. },
  3838. enumerable: false,
  3839. configurable: true
  3840. });
  3841.  
  3842.  
  3843.  
  3844. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  3845. const { addJob, cancelJob } = yt.scheduler.instance;
  3846. if (addJob) {
  3847. yt.scheduler.instance.addJob = null;
  3848. yt.scheduler.instance.addJob = addJob;
  3849. }
  3850. if (cancelJob) {
  3851. yt.scheduler.instance.cancelJob = null;
  3852. yt.scheduler.instance.cancelJob = cancelJob;
  3853. }
  3854. }
  3855.  
  3856.  
  3857. }
  3858.  
  3859. const isWatchPageURL = (url) => {
  3860. url = url || location;
  3861. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  3862. };
  3863.  
  3864. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  3865.  
  3866. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  3867. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  3868. if (typeof customElements === 'undefined') {
  3869. if (!('__CE_registry' in document)) {
  3870. // https://github.com/webcomponents/polyfills/
  3871. Object.defineProperty(document, '__CE_registry', {
  3872. get() {
  3873. // return undefined
  3874. },
  3875. set(nv) {
  3876. if (typeof nv == 'object') {
  3877. delete this.__CE_registry;
  3878. this.__CE_registry = nv;
  3879. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  3880. }
  3881. return true;
  3882. },
  3883. enumerable: false,
  3884. configurable: true
  3885. })
  3886. }
  3887. let eventHandler = (evt) => {
  3888. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3889. const f = callback;
  3890. callback = null;
  3891. eventHandler = null;
  3892. f();
  3893. };
  3894. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  3895. } else {
  3896. callback();
  3897. }
  3898. });
  3899.  
  3900. const whenCEDefined = isCustomElementsProvided
  3901. ? (nodeName) => customElements.whenDefined(nodeName)
  3902. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  3903.  
  3904. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  3905. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  3906. const f = performance.now23 = Performance.prototype.now;
  3907.  
  3908. let k = 0; // 0 <= k < 9998m
  3909. let u = 0;
  3910. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  3911.  
  3912. // By definition, performance.now() is mono increasing.
  3913. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  3914. performance.now = performance.now16 = function () {
  3915. /**
  3916. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  3917. *
  3918. * If consecutive session history entries had history.state.entryTime set to same value,
  3919. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  3920. * and modifying its return value slightly to make sure two close consecutive calls don't
  3921. * get the same result helped with resolving the issue.
  3922. */
  3923. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  3924. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  3925.  
  3926. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  3927. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  3928. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  3929. else { // more than 9998 consecutive calls
  3930. /**
  3931. *
  3932. * max no. of consecutive calls
  3933. *
  3934. * Sample Size: 4800
  3935. * Sample Avg = 1565.375
  3936. * Sample Median = 1469.5
  3937. * Sample Max = 5660 << 7500 << 9999
  3938. *
  3939. *
  3940. * */
  3941. k = 0;
  3942. s += 1 / 7;
  3943. }
  3944. return v + k; // 0 < v - M < v - M + k < v
  3945. }
  3946.  
  3947. let loggerMsg = '';
  3948. if (`${performance.now()}` === `${performance.now()}`) {
  3949. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  3950. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  3951. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  3952. }
  3953. loggerMsg && console.warn(loggerMsg);
  3954. })();
  3955.  
  3956. // let __forceRemoveMode__ = false;
  3957. FIX_removeChild && (() => {
  3958. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  3959. let internalByPass = false;
  3960. const fragD = document.createDocumentFragment();
  3961. fragD.appendChild4201 = fragD.appendChild;
  3962. fragD.removeChild4201 = fragD.removeChild;
  3963. Node.prototype.removeChild062 = Node.prototype.removeChild;
  3964. Node.prototype.removeChild = function (child) {
  3965. try {
  3966. return this.removeChild062(child);
  3967. } catch (e) { }
  3968. if (internalByPass) return child;
  3969. if (this instanceof Node && child instanceof Node && this.nodeType === 11 && child.parentNode !== this && this.contains(child)) { // eg. child = DOM-IF
  3970. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3971. if (idx >= 0) {
  3972. internalByPass = true;
  3973. child.parentNode !== fragD && fragD.appendChild4201(child);
  3974. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3975. fragD.removeChild4201(child);
  3976. internalByPass = false;
  3977. return child;
  3978. }
  3979. }
  3980. // if (this instanceof Node && child instanceof Node && child.parentNode && child.parentNode.nodeType === 11 && child.parentNode !== this && !this.contains(child)) {
  3981. // // force removal
  3982. // internalByPass = true;
  3983. // child.parentNode !== fragD && fragD.appendChild4201(child);
  3984. // fragD.removeChild4201(child);
  3985. // internalByPass = false;
  3986. // return child;
  3987. // }
  3988. if (this && child) {
  3989. if (this.childNodes && this.childNodes.splice) { // tbc
  3990. let idx = (this.childNodes || 0).length >= 1 ? this.childNodes.indexOf(child) : -1;
  3991. if (idx >= 0) {
  3992. internalByPass = true;
  3993. child.parentNode !== fragD && fragD.appendChild4201(child);
  3994. this.childNodes[idx] === child && typeof this.childNodes.splice === 'function' && this.childNodes.splice(idx, 1);
  3995. fragD.removeChild4201(child);
  3996. internalByPass = false;
  3997. return child;
  3998. }
  3999. }
  4000.  
  4001. if (child.parentNode !== this && child.parentNode && child.parentNode === child.__shady_parentNode && child.parentNode.nodeType === 11) {
  4002. if (child.isConnected === false && (this.compareDocumentPosition(child) & (1 | 8 | 16)) === 1) {
  4003. // just ignore (!e.root && a.localName !== "slot" || f === a.__shady_native_parentNode) && f.__shady_native_removeChild(a));
  4004. return child;
  4005. }
  4006. }
  4007.  
  4008. if (child && child.is === 'tp-yt-paper-tooltip' && !child.parentNode && !child.__shady_parentNode) {
  4009. // skip
  4010. return child;
  4011. }
  4012.  
  4013. console.warn('[yt-js-engine-tamer] Node is not removed from parent', {
  4014. parent: this, child: child,
  4015. isParent: child.parentNode === this,
  4016. isParentParent: (child.parentNode || 0).parentNode === this,
  4017. parentNode: child.parentNode,
  4018. shadyParent: child.__shady_parentNode,
  4019. isShadyParent: child.__shady_parentNode === this,
  4020. isAncestor: this instanceof Node && child instanceof Node && this.contains(child)
  4021. });
  4022.  
  4023. }
  4024. return child;
  4025. }
  4026. }
  4027. })();
  4028.  
  4029.  
  4030. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  4031.  
  4032. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  4033.  
  4034. // let cid = 0;
  4035.  
  4036. let mousemoveFn = null;
  4037. let mousemoveDT = 0;
  4038. let mousemoveCount = 0;
  4039. // let qv = false;
  4040. const cif = () => {
  4041. if (!mousemoveFn) return;
  4042. const ct = Date.now();
  4043. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  4044. mousemoveFn && mousemoveFn();
  4045. }
  4046. mousemoveFn = null;
  4047. };
  4048. let mousemoveCId = 0;
  4049. let mouseoverFn = null;
  4050. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  4051. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  4052. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  4053. const bt = `${b}`;
  4054. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  4055. b[`__$$${a}$$1926__`] = true;
  4056. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  4057. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  4058. // console.log(3928, a, this[`__$$${a}$$1937__`])
  4059. if (!this[`__$$${a}$$1938__`]) {
  4060. this[`__$$${a}$$1938__`] = b;
  4061. if (a === 'mousemove') {
  4062. this.addEventListener4882('mouseenter', (evt) => {
  4063. if (mousemoveCId) return;
  4064. mousemoveCId = setIntervalX0(cif, 380);
  4065. });
  4066. this.addEventListener4882('mouseleave', (evt) => {
  4067. clearIntervalX0(mousemoveCId);
  4068. mousemoveCId = 0;
  4069. });
  4070. }
  4071. this.addEventListener4882(a, (evt) => {
  4072. const evt_ = evt;
  4073. if (!this[`__$$${a}$$1937__`]) return;
  4074. if (!this[`__$$${a}$$1938__`]) return;
  4075. if (a === 'mousemove') {
  4076. mouseoverFn && mouseoverFn();
  4077. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  4078. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  4079. } else {
  4080. mousemoveCount = 0;
  4081. }
  4082. const f = mousemoveFn = () => {
  4083. if (f !== mousemoveFn) return;
  4084. mousemoveFn = null;
  4085. this[`__$$${a}$$1938__`](evt_);
  4086. };
  4087. if (mousemoveCount <= 1) mousemoveFn();
  4088. } else {
  4089. if (a === 'mouseout' || a === 'mouseleave') {
  4090. mousemoveFn = null;
  4091. mousemoveDT = 0;
  4092. mousemoveCount = 0;
  4093. this[`__$$${a}$$1938__`](evt_);
  4094. mouseoverFn && mouseoverFn();
  4095. } else { // mouseover, mouseenter
  4096. mousemoveFn = null;
  4097. mousemoveDT = 0;
  4098. mousemoveCount = 0;
  4099. mouseoverFn && mouseoverFn(); // just in case
  4100. const f = mouseoverFn = () => {
  4101. if (f !== mouseoverFn) return;
  4102. mouseoverFn = null;
  4103. this[`__$$${a}$$1938__`](evt_);
  4104. }
  4105. nextBrowserTick_(mouseoverFn);
  4106. }
  4107. }
  4108. }, c);
  4109.  
  4110.  
  4111. return;
  4112. } else {
  4113.  
  4114. return;
  4115. }
  4116. }
  4117.  
  4118. }
  4119. return this.addEventListener4882(a, b, c)
  4120. }
  4121.  
  4122.  
  4123.  
  4124.  
  4125. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  4126. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  4127. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  4128.  
  4129. if (b[`__$$${a}$$1926__`]) {
  4130. b[`__$$${a}$$1926__`] = false;
  4131.  
  4132. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  4133.  
  4134. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  4135.  
  4136. return;
  4137.  
  4138. }
  4139.  
  4140. }
  4141. return this.removeEventListener4882(a, b, c)
  4142. }
  4143.  
  4144.  
  4145. })();
  4146.  
  4147.  
  4148. FIX_DOM_IF_REPEAT && (() => {
  4149. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  4150. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  4151. // Be careful of the mixture of polymer functions and native Element functions
  4152. // Be careful of the coding design is different with the modern Yt elements
  4153.  
  4154.  
  4155. /*
  4156.  
  4157.  
  4158. function Ks(a, b, c) {
  4159. if (kj && !BOa(a))
  4160. throw Error("strictTemplatePolicy: template owner not trusted");
  4161. c = c || {};
  4162. if (a.__templatizeOwner)
  4163. throw Error("A <template> can only be templatized once");
  4164. a.__templatizeOwner = b;
  4165. var d = (b ? b.constructor : Js)._parseTemplate(a)
  4166. , e = d.templatizeInstanceClass;
  4167. e || (e = COa(a, d, c),
  4168. d.templatizeInstanceClass = e);
  4169. var g = BOa(a);
  4170. EOa(a, d, c, g);
  4171. c = function() {
  4172. return e.apply(this, arguments) || this
  4173. }
  4174. ;
  4175. h(c, e);
  4176. c.prototype._methodHost = g;
  4177. c.prototype.__dataHost = a;
  4178. c.prototype.__templatizeOwner = b;
  4179. c.prototype.__hostProps = d.hostProps;
  4180. return c
  4181. }
  4182.  
  4183. */
  4184.  
  4185. // Polymer.enqueueDebouncer
  4186.  
  4187. const s81 = Symbol();
  4188. const s83 = Symbol();
  4189. const s84 = Symbol();
  4190. const s85 = Symbol();
  4191. const s85b = Symbol();
  4192. const s85c = Symbol();
  4193.  
  4194. let renderDebounceTs = null;
  4195.  
  4196. let renderDebouncePromise = null;
  4197. let qp;
  4198.  
  4199. const shadyFlushMO = new MutationObserver(() => {
  4200.  
  4201. if (!renderDebounceTs) return;
  4202.  
  4203. if (renderDebounceTs.size > 0) {
  4204. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  4205. try {
  4206. Polymer.flush();
  4207. return;
  4208. } catch (e) { }
  4209. }
  4210.  
  4211. renderDebouncePromise && Promise.resolve().then(() => {
  4212.  
  4213. if (renderDebouncePromise) {
  4214. renderDebouncePromise && renderDebouncePromise.resolve();
  4215. renderDebouncePromise = null;
  4216. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  4217. }
  4218.  
  4219. });
  4220.  
  4221. // Polymer.flush
  4222.  
  4223. window.ShadyDOM && ShadyDOM.flush();
  4224. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  4225.  
  4226.  
  4227. });
  4228.  
  4229. const setupPolymerAdv = () => {
  4230. // here we can obtain the Polymer faster.
  4231. // reserved for future use.
  4232. }
  4233.  
  4234.  
  4235. if (USE_fastDomIf) {
  4236. // 0 = no effect. 1 = enable. 2 = disable
  4237. // fastDomIf because it delayed the rendering process?
  4238. Object.defineProperty(Object.prototype, 'fastDomIf', {
  4239. get() {
  4240. if (this === window.Polymer) {
  4241. const v = USE_fastDomIf === 1 ? true : false;
  4242. this.fastDomIf = v;
  4243. delete Object.prototype.fastDomIf;
  4244. setupPolymerAdv(this);
  4245. return v;
  4246. }
  4247. },
  4248. set(nv) {
  4249. return false;
  4250. }
  4251. });
  4252. }
  4253.  
  4254. let setupDomIfDone = false;
  4255. const setupDomIf = (DomIf)=>{
  4256. setupDomIfDone = true;
  4257. if(setupDomIfDone) return;
  4258.  
  4259. const fProto = DomIf.prototype;
  4260.  
  4261.  
  4262. // Polymer.DomIf
  4263. // Polymer.DomIf = Polymer.fastDomIf ? ZbL : ESz
  4264. // Assume ESz by default
  4265.  
  4266. // We don't need to store "root" in DOM-IF
  4267. if (ENHANCE_DOMIF_createAndInsertInstance && fProto.__createAndInsertInstance && !fProto.__createAndInsertInstance239 && fProto.__createAndInsertInstance.length === 1) {
  4268. fProto.__createAndInsertInstance239 = fProto.__createAndInsertInstance;
  4269. fProto.__createAndInsertInstance = function (M) {
  4270. const r = this.__createAndInsertInstance239(M);
  4271. const __instance = this.__instance;
  4272. const __ctor = this.__ctor;
  4273. if (__instance && __ctor && __instance instanceof __ctor) {
  4274. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4275. const o = __instance[sym];
  4276. if (o && o.nodeType === 11) {
  4277. __instance[sym] = null;
  4278. }
  4279. }
  4280. }
  4281. return r;
  4282. }
  4283.  
  4284. /*
  4285.  
  4286.  
  4287. sX = function(M, d, N) {
  4288. if (o_ && !vDv(M))
  4289. throw Error("Jd");
  4290. N = N || {};
  4291. if (M.__templatizeOwner)
  4292. throw Error("Kd");
  4293. M.__templatizeOwner = d;
  4294. var R = (d ? d.constructor : jF)._parseTemplate(M)
  4295. , X = R.templatizeInstanceClass;
  4296. X || (X = sfi(M, R, N),
  4297. R.templatizeInstanceClass = X);
  4298. var A = vDv(M);
  4299. y9Z(M, R, N, A);
  4300. N = function() {
  4301. return X.apply(this, arguments) || this
  4302. }
  4303. ;
  4304. _.v(N, X);
  4305. N.prototype._methodHost = A;
  4306. N.prototype.__dataHost = M;
  4307. N.prototype.__templatizeOwner = d;
  4308. N.prototype.__hostProps = R.hostProps;
  4309. return N
  4310. }
  4311.  
  4312. */
  4313. }
  4314.  
  4315. // Polymer.DomIf
  4316. // We can fully teardown the entire instance (including stampFrag and stampNodes), just keep ctor stamper
  4317. if (ENHANCE_DOMIF_TEARDOWN && fProto.__teardownInstance && !fProto.__teardownInstance239 && fProto.__teardownInstance.length === 0) {
  4318. fProto.__teardownInstance239 = fProto.__teardownInstance;
  4319. fProto.__teardownInstance = function () {
  4320. const { __instance, __invalidProps } = this;
  4321. let r, e_;
  4322. try {
  4323. r = this.__teardownInstance239();
  4324. } catch (e) { e_ = e }
  4325. if (!__instance) return r;
  4326.  
  4327. try {
  4328.  
  4329. //console.log(599901,this.countEvent767());
  4330. //console.log('__teardownInstance F', __instance, __invalidProps, this._removeEventListenerFromNode, __instance._removeEventListenerFromNode);
  4331. __instance.__data = null;
  4332. __instance.__dataClientsReady = __instance.__dataEnabled = __instance.__dataReady = false;
  4333. __instance.__dataInvalid = true;
  4334. __instance.__dataHost = __instance.__dataTemp = null;
  4335. __instance.__isPropertyEffectsClient = false;
  4336. __instance.__keepInstance038__ = false;
  4337.  
  4338.  
  4339. const __templateInfo = __instance.__templateInfo;
  4340.  
  4341. let stampFragId = null;
  4342. if (__templateInfo && __templateInfo.nodeList) {
  4343. stampFragId = __templateInfo.nodeList.__belongFragId57__;
  4344. for (const weakNodeC of __templateInfo.nodeList) {
  4345. const node = toActualNode(weakNodeC);
  4346. if (node && node.nodeType >= 1) {
  4347. renderPathMake(node)
  4348. node.__keepInstance038__ = false;
  4349. node.remove();
  4350. _removedElements.addNode(node); // rn54011
  4351. }
  4352. }
  4353. __templateInfo.nodeList.length = 0;
  4354. __templateInfo.nodeList = null;
  4355. }
  4356.  
  4357. const stampFrag = stampFragId ? kRef(stampedFragment.get(stampFragId)) : null;
  4358.  
  4359. if (stampFrag && stampFrag.nodeType === 11) {
  4360. stampFrag.__keepInstance038__ = false;
  4361. _removedElements.addNode(stampFrag); // rn54012
  4362. removeAllChildNodes(stampFrag);
  4363. try {
  4364. stampFrag.remove();
  4365. } catch (e) { }
  4366. stampFrag.__shady = null;
  4367. stampFrag.$ = null;
  4368. stampFrag.__fragTeardowned57__ = true;
  4369. stampFrag.nodeList = null;
  4370. stampFrag.templateInfo = null;
  4371.  
  4372. }
  4373.  
  4374. for (const sym of Object.getOwnPropertySymbols(__instance)) {
  4375. const o = __instance[sym];
  4376. if (o && o.nodeType === 11) {
  4377. __instance[sym] = null;
  4378. }
  4379. }
  4380.  
  4381. const children = (__instance || 0).children;
  4382. if (children && children.splice) {
  4383. __instance.children = null;
  4384. for (const n of children) {
  4385. if (n && n.nodeType >= 1) {
  4386. n.__keepInstance038__ = false;
  4387. _removedElements.addNode(n); // rn54013
  4388. }
  4389. }
  4390. children.length = 0;
  4391. }
  4392.  
  4393. if (__instance.__templateInfo) __instance.__templateInfo = null;
  4394.  
  4395. if (__instance.root) __instance.root = null;
  4396.  
  4397. } catch (e) {
  4398. console.error(e);
  4399. }
  4400.  
  4401. // console.log(3882)
  4402. if (e_) throw e_;
  4403. return r;
  4404. }
  4405. }
  4406.  
  4407. }
  4408.  
  4409. if (ENHANCE_DOMIF_createAndInsertInstance || ENHANCE_DOMIF_TEARDOWN) {
  4410.  
  4411. Object.defineProperty(Object.prototype, 'DomIf', {
  4412. get() {
  4413. return undefined;
  4414. },
  4415. set(nv) {
  4416. if (typeof (nv || 0) !== 'function') return false;
  4417. delete Object.prototype.DomIf;
  4418. this.DomIf = nv;
  4419. setupDomIf(nv);
  4420. return true;
  4421. },
  4422. enumerable: false,
  4423. configurable: true
  4424. });
  4425.  
  4426. }
  4427.  
  4428. Object.defineProperty(Object.prototype, '_lastIf', {
  4429. get() {
  4430. return this[s81];
  4431. },
  4432. set(nv) {
  4433. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  4434. // DOM-IF initialization
  4435. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  4436.  
  4437. this.__xiWB8__ = 2;
  4438. // this.restamp = true;
  4439.  
  4440. const cProto = this.__proto__;
  4441. if (cProto && !cProto.__xiWB7__) {
  4442. cProto.__xiWB7__ = 1;
  4443.  
  4444. // dom-if __template
  4445. // dom-repeat template
  4446. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  4447. cProto.__template847 = true;
  4448. try {
  4449. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  4450. Object.defineProperty(cProto, '__template', {
  4451. get() {
  4452. const v = this[s84];
  4453. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  4454. },
  4455. set(nv) {
  4456. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  4457. this[s84] = nv;
  4458. return true;
  4459. }
  4460. });
  4461. } catch (e) {
  4462. console.warn(e);
  4463. }
  4464.  
  4465. console.log('FIX_DOM_IF - __template')
  4466. }
  4467.  
  4468. // dom-if __ensureTemplate
  4469. // dom-repeat __ensureTemplatized
  4470. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  4471. // note that "_templateInfo" diffs the different version of DOM-IF
  4472.  
  4473. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  4474. cProto.__ensureTemplate = function () {
  4475. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  4476. if (!this.__template) {
  4477. let b;
  4478. if (this._templateInfo) {
  4479. b = this;
  4480. } else {
  4481. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  4482. b = this.__templateCollection011__[0];
  4483. if (!b) {
  4484. if (!this[wk]) this[wk] = mWeakRef(this);
  4485. let a = this[wk];
  4486. let c = new MutationObserver(function () {
  4487. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  4488. if (c && a) {
  4489. c.disconnect();
  4490. a = kRef(a);
  4491. a && a.__render();
  4492. a && (a.__templateCollection011__ = null);
  4493. }
  4494. c = null;
  4495. a = null;
  4496. });
  4497. c && c.observe(this, {
  4498. childList: !0
  4499. });
  4500. return !1
  4501. } else {
  4502. this.__templateCollection011__ = null;
  4503. }
  4504. }
  4505. this.__template = b
  4506. }
  4507. return !0
  4508. }
  4509.  
  4510. console.log('FIX_DOM_IF - __ensureTemplate')
  4511.  
  4512. }
  4513.  
  4514.  
  4515. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  4516. }
  4517.  
  4518.  
  4519. // need to fix __observeEffects
  4520. // this.__observeEffects.if[0].info.method === this.__debounceRender
  4521. const f = () => {
  4522.  
  4523. const __observeEffects = this.__observeEffects;
  4524.  
  4525. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  4526. for (const effect of __observeEffects.if) {
  4527. const info = effect.info;
  4528. if (info && typeof info.method === 'function') {
  4529.  
  4530. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4531. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4532. }
  4533.  
  4534. }
  4535. }
  4536. }
  4537.  
  4538.  
  4539. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  4540. for (const effect of __observeEffects.restamp) {
  4541. const info = effect.info;
  4542. if (info && typeof info.method === 'function') {
  4543.  
  4544. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  4545. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  4546. }
  4547.  
  4548. }
  4549. }
  4550. }
  4551.  
  4552. // console.log(5881, this.__observeEffects)
  4553. }
  4554.  
  4555. }
  4556. this[s81] = nv;
  4557. return true;
  4558. }
  4559. });
  4560.  
  4561.  
  4562. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  4563. get() {
  4564. return this[s85];
  4565. },
  4566. set(nv) {
  4567. if (nv === null && this[s85] === undefined) {
  4568. // DOM-IF / DOM-REPEAT initialization
  4569.  
  4570.  
  4571. const cProto = this.__proto__;
  4572. if (qp) {
  4573. qp.obtain();
  4574. qp = null;
  4575. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  4576. }
  4577.  
  4578. }
  4579. this[s85] = nv;
  4580. return true;
  4581. }
  4582. });
  4583.  
  4584. // PS-DOM-REPEAT
  4585.  
  4586. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  4587. get() {
  4588. return this[s85b];
  4589. },
  4590. set(nv) {
  4591.  
  4592. this[s85b] = nv;
  4593. return true;
  4594. }
  4595. })
  4596.  
  4597. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  4598. get() {
  4599. return this[s85c];
  4600. },
  4601. set(nv) {
  4602.  
  4603. this[s85c] = nv;
  4604. return true;
  4605. }
  4606. })
  4607.  
  4608.  
  4609. })();
  4610.  
  4611. const setupXdeadC = (cnt)=>{
  4612.  
  4613. let xdeadc = xdeadc00;
  4614. if(!xdeadc){
  4615. setupSDomWrapper(); // just in case
  4616. const hostElement = cnt.hostElement;
  4617. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4618. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4619. hostElement.lastChild.replaceWith(el);
  4620. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4621. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4622. el.firstElementChild.id = rid;
  4623. cnt.$[rid] = el.firstElementChild;
  4624. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4625.  
  4626. xdeadc = cnt.getStampContainer_(rid);
  4627. el.remove();
  4628. xdeadc00 = xdeadc;
  4629. // console.log(xdeadc.__domApi)
  4630. // debugger;
  4631. // const xdeadv = xdeadc.__domApi;
  4632. }
  4633.  
  4634. let xlivec = xlivec00;
  4635. if(!xlivec){
  4636. setupSDomWrapper(); // just in case
  4637. const hostElement = cnt.hostElement;
  4638. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  4639. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  4640. hostElement.lastChild.replaceWith(el);
  4641. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  4642. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  4643. el.firstElementChild.id = rid;
  4644. cnt.$[rid] = el.firstElementChild;
  4645. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  4646.  
  4647. xlivec = cnt.getStampContainer_(rid);
  4648. xlivec00 = xlivec;
  4649. // console.log(xdeadc.__domApi)
  4650. // debugger;
  4651. // const xdeadv = xdeadc.__domApi;
  4652. }
  4653.  
  4654. return xdeadc00;
  4655. }
  4656.  
  4657. let standardWrap_ = null;
  4658.  
  4659. const setupSDomWrapper = () => {
  4660.  
  4661. const sdwProto = ShadyDOM.Wrapper.prototype;
  4662.  
  4663. if (sdwProto.__pseudo__isConnected__ !== null) {
  4664. sdwProto.__pseudo__isConnected__ = null;
  4665. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  4666. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  4667. const get = isConnectedPd.get;
  4668. isConnectedPd.get = function () {
  4669. const pseudoVal = this.__pseudo__isConnected__;
  4670. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  4671. }
  4672. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  4673. }
  4674.  
  4675. // debugger;
  4676. // new xdeadc.__domApi.constructor(document.createElement('div'));
  4677. }
  4678.  
  4679. }
  4680.  
  4681. let domApiConstructor = null;
  4682. const setupDomApi = (daProto) => {
  4683.  
  4684. daProto.__daHook377__ = true;
  4685.  
  4686. domApiConstructor = daProto.constructor; // TBC
  4687.  
  4688. // TBC
  4689.  
  4690. }
  4691.  
  4692.  
  4693. // WEAKREF_ShadyDOM
  4694.  
  4695. let mightTeardownShadyDomWrap = () => { };
  4696.  
  4697. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  4698.  
  4699. const setupPlainShadyDOM = (b) => {
  4700. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  4701. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  4702. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  4703. b.patchOnDemand = true;
  4704. b.preferPerformance = true;
  4705. b.noPatch = true;
  4706. }
  4707.  
  4708. const isPlainObject = (b, m) => {
  4709. if (!b || typeof b !== 'object') return false;
  4710. const e = Object.getOwnPropertyDescriptors(b);
  4711. if (e.length <= m) return false;
  4712. let pr = 0;
  4713. for (const k in e) {
  4714. const d = e[k];
  4715. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  4716. if (!('value' in d) || typeof d.value === 'function') return false;
  4717. pr++;
  4718. }
  4719. return pr > m;
  4720. }
  4721.  
  4722. let b;
  4723.  
  4724. let lz = 0;
  4725.  
  4726. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  4727. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  4728.  
  4729. // Brave - ShadyDOM exists before userscripting
  4730. b = sdp.value;
  4731.  
  4732. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  4733. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  4734. lz = 1;
  4735. }
  4736.  
  4737. }
  4738.  
  4739.  
  4740. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  4741. } else if (!sdp) {
  4742. } else {
  4743. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  4744. return;
  4745. }
  4746.  
  4747. const shadyDOMNodeWRM = new WeakMap();
  4748.  
  4749. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  4750.  
  4751. const weakWrapperNodeHandlerFn = () => ({
  4752. get() {
  4753. const wv = this[wk];
  4754. if (typeof wv === 'undefined') return undefined;
  4755. let node = kRef(wv);
  4756. if (!node) this[wk] = undefined;
  4757. return node || undefined;
  4758. },
  4759. set(nv) {
  4760. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  4761. this[wk] = wv;
  4762. return true;
  4763. },
  4764. enumerable: true,
  4765. configurable: true
  4766. });
  4767.  
  4768.  
  4769. function weakWrapper(_ShadyDOM) {
  4770. const ShadyDOM = _ShadyDOM;
  4771. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  4772. let nullElement = { node: null };
  4773. Object.setPrototypeOf(nullElement, Element.prototype);
  4774. let p = new ShadyDOM.Wrapper(nullElement);
  4775. let d = Object.getOwnPropertyDescriptor(p, 'node');
  4776. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  4777. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  4778. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  4779. }
  4780.  
  4781. }
  4782. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  4783. try {
  4784. setupSDomWrapper();
  4785. } catch (e) { }
  4786. }
  4787.  
  4788. }
  4789.  
  4790. let previousWrapStore = null;
  4791.  
  4792. mightTeardownShadyDomWrap = (node) => {
  4793. if (previousWrapStore) previousWrapStore.delete(node);
  4794. if (shadyDOMNodeWRM) shadyDOMNodeWRM.delete(node);
  4795. };
  4796.  
  4797. const standardWrap = function (a) {
  4798. if (a instanceof WeakNodeC) a = a.getNode592177();
  4799. // if(a && a.deref) a= a.deref();
  4800. if(!a) return a;
  4801. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  4802. if (previousWrapStore) {
  4803. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  4804. if (s) {
  4805. previousWrapStore.delete(a);
  4806. shadyDOMNodeWRM.set(a, mWeakRef(s));
  4807. }
  4808. }
  4809. let u = kRef(shadyDOMNodeWRM.get(a));
  4810. if (!u) {
  4811. u = new ShadyDOM.Wrapper(a);
  4812. shadyDOMNodeWRM.set(a, mWeakRef(u));
  4813. }
  4814. return u;
  4815. }
  4816.  
  4817. standardWrap_ = standardWrap;
  4818.  
  4819.  
  4820. function setupWrapFunc(_ShadyDOM) {
  4821. const ShadyDOM = _ShadyDOM;
  4822.  
  4823.  
  4824. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  4825. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  4826. return;
  4827. }
  4828. let mm = new Set();
  4829. const pget = wmPD.value;
  4830. WeakMap.prototype.get = function (a) {
  4831. mm.add(this);
  4832. return a;
  4833. }
  4834. try {
  4835. let nullElement = { node: null };
  4836. Object.setPrototypeOf(nullElement, Element.prototype);
  4837. ShadyDOM.wrapIfNeeded(nullElement)
  4838. ShadyDOM.wrap(nullElement)
  4839. } catch (e) { }
  4840. WeakMap.prototype.get = pget;
  4841. if (mm.size !== 1) {
  4842. mm.clear();
  4843. return;
  4844. }
  4845. const p = mm.values().next().value;
  4846. if (!(p instanceof WeakMap)) return;
  4847. // p.clear();
  4848. // p.get = function (a) { return a }
  4849. // p.set = function (a, b) { return this }
  4850. // console.log(188, window.n2n = mm, window.n2p = p)
  4851.  
  4852. // console.log(34929,p.size)
  4853. previousWrapStore = p;
  4854.  
  4855. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  4856. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  4857. }
  4858. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  4859. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  4860. }
  4861.  
  4862. }
  4863.  
  4864. function setupLZ3(nv) {
  4865.  
  4866. const ShadyDOM = nv;
  4867.  
  4868. const ShadyDOMSettings = ShadyDOM.settings;
  4869. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4870. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4871. return false;
  4872. }
  4873.  
  4874. weakWrapper(ShadyDOM);
  4875.  
  4876. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4877.  
  4878. setupPlainShadyDOM(ShadyDOMSettings);
  4879. setupPlainShadyDOM(ShadyDOM);
  4880.  
  4881. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  4882.  
  4883. setupWrapFunc(ShadyDOM);
  4884. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  4885. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  4886.  
  4887. // To be confirmed
  4888. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  4889. ShadyDOM.composedPath = function (e) {
  4890. const t = (e || 0).target || null;
  4891. if (!(t instanceof HTMLElement_)) {
  4892. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  4893. }
  4894. return t instanceof HTMLElement_ ? [t] : [];
  4895. };
  4896. }
  4897.  
  4898. }
  4899.  
  4900. }
  4901.  
  4902.  
  4903. function setupLZ6(nv) {
  4904.  
  4905. const ShadyDOM = nv;
  4906.  
  4907. const ShadyDOMSettings = ShadyDOM.settings;
  4908.  
  4909. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  4910. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  4911. return false;
  4912. }
  4913.  
  4914. weakWrapper(ShadyDOM);
  4915.  
  4916. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  4917.  
  4918. setupPlainShadyDOM(ShadyDOMSettings);
  4919. setupPlainShadyDOM(ShadyDOM);
  4920.  
  4921. setupWrapFunc(ShadyDOM);
  4922.  
  4923. }
  4924.  
  4925. }
  4926.  
  4927. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  4928.  
  4929. const nv = b;
  4930.  
  4931. if (setupLZ6(nv) === false) return;
  4932.  
  4933. lz = 6;
  4934.  
  4935. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  4936.  
  4937. return;
  4938. }
  4939.  
  4940. delete window.ShadyDOM;
  4941.  
  4942. Object.defineProperty(window, 'ShadyDOM', {
  4943. get() {
  4944. return b;
  4945. },
  4946. set(nv) {
  4947. let ret = 0;
  4948. try {
  4949. do {
  4950. if (!nv || !nv.settings) {
  4951. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  4952. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  4953. lz = 1;
  4954. break;
  4955. } else {
  4956. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  4957. break;
  4958. }
  4959. }
  4960.  
  4961. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  4962. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  4963. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  4964. break;
  4965. }
  4966.  
  4967. if (setupLZ3(nv) === false) break;
  4968.  
  4969. lz = 3;
  4970.  
  4971. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  4972.  
  4973. ret = 1;
  4974.  
  4975. } while (0);
  4976. } catch (e) {
  4977. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  4978. }
  4979.  
  4980. if (!ret) b = nv;
  4981. else {
  4982. delete this.ShadyDOM;
  4983. this.ShadyDOM = nv;
  4984. }
  4985. return true;
  4986. },
  4987. enumerable: false,
  4988. configurable: true
  4989. });
  4990.  
  4991. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  4992.  
  4993. if (ENABLE_ASYNC_DISPATCHEVENT) {
  4994. const filter = new Set([
  4995. 'yt-action',
  4996. // 'iframe-src-replaced',
  4997. 'shown-items-changed',
  4998. 'can-show-more-changed', 'collapsed-changed',
  4999.  
  5000. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  5001. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  5002. 'yt-navigate-finish',
  5003.  
  5004. // 'data-changed','yt-watch-comments-ready'
  5005. ])
  5006. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  5007. EventTarget.prototype.dispatchEvent = function (event) {
  5008. const type = (event || 0).type;
  5009. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  5010. if (!filter.has(type) && !type.endsWith('-changed')) {
  5011. if (this instanceof Node || this instanceof Window) {
  5012. nextBrowserTick_(() => this.dispatchEvent938(event));
  5013. return true;
  5014. }
  5015. }
  5016. }
  5017. return this.dispatchEvent938(event);
  5018. }
  5019. }
  5020.  
  5021. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  5022. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  5023. // const xhr = new XMLHttpRequest;
  5024. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  5025. if (!pdOri || pdOri.configurable !== true) return;
  5026. let propNeedles = null;
  5027. const pdNew = {
  5028. configurable: true,
  5029. enumerable: true,
  5030. get: function () {
  5031. propNeedles = this;
  5032. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  5033. throw new Error();
  5034. }
  5035. }
  5036. Object.defineProperty(Map.prototype, 'size', pdNew);
  5037. try {
  5038. XMLHttpRequest.prototype.open.call(0);
  5039. // xhr.open.call(null)
  5040. } catch (e) { }
  5041. Object.defineProperty(Map.prototype, 'size', pdOri);
  5042. if (!propNeedles) return;
  5043. const entries = [...propNeedles.entries()];
  5044. propNeedles.clear();
  5045. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  5046. })();
  5047.  
  5048. if (FIX_XHR_REQUESTING) {
  5049.  
  5050. const URL = window.URL || new Function('return URL')();
  5051. const createObjectURL = URL.createObjectURL.bind(URL);
  5052.  
  5053. XMLHttpRequest = (() => {
  5054. const XMLHttpRequest_ = XMLHttpRequest;
  5055. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  5056. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  5057. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  5058. constructor(...args) {
  5059. super(...args);
  5060. }
  5061. open(method, url, ...args) {
  5062. let skip = false;
  5063. if (!url || typeof url !== 'string') skip = true;
  5064. else if (typeof url === 'string') {
  5065. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  5066. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  5067. skip = true;
  5068. } else if (turl.includes('.youtube.com/pagead/')) {
  5069. skip = true;
  5070. } else if (turl.includes('.youtube.com/ptracking')) {
  5071. skip = true;
  5072. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  5073. skip = true;
  5074. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  5075. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  5076. skip = true;
  5077. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  5078. skip = true;
  5079. } else {
  5080. // skip = true; // for user activity logging e.g. watched videos
  5081. }
  5082. } else if (turl.includes('play.google.com/log')) {
  5083. skip = true;
  5084. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  5085. skip = true;
  5086. }
  5087. }
  5088. if (!skip) {
  5089. this.__xmMc8__ = 1;
  5090. return super.open(method, url, ...args);
  5091. } else {
  5092. this.__xmMc8__ = 2;
  5093. return super.open('GET', url0);
  5094. }
  5095. }
  5096. send(...args) {
  5097. if (this.__xmMc8__ === 1) {
  5098. return super.send(...args);
  5099. } else if (this.__xmMc8__ === 2) {
  5100. return super.send();
  5101. } else {
  5102. console.log('[yt-js-engine-tamer]', 'xhr warning');
  5103. return super.send(...args);
  5104. }
  5105. }
  5106. }
  5107. c.prototype.__xmMc8__ = 0;
  5108. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  5109. return c;
  5110. })();
  5111. }
  5112.  
  5113. // Alternative HACK -> Tabview Youtube
  5114. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  5115.  
  5116. // ---- << this.overscrollConfig HACK >> -----
  5117.  
  5118. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  5119.  
  5120. /*
  5121.  
  5122. ;function gZb(a, b) {
  5123. b = void 0 === b ? !0 : b;
  5124. a.addEventListener("wheel", hZb);
  5125. a.overscrollConfig = {
  5126. cooldown: b
  5127. }
  5128. }
  5129. function iZb(a) {
  5130. a.overscrollConfig = void 0;
  5131. a.removeEventListener("wheel", hZb)
  5132. }
  5133. function hZb(a) {
  5134. var b = a.deltaY
  5135. , c = a.target
  5136. , d = null;
  5137. if (window.Polymer && window.Polymer.Element) {
  5138. if (c = a.path || a.composedPath && a.composedPath()) {
  5139. c = g(c);
  5140. for (var e = c.next(); !e.done && (e = e.value,
  5141. !jZb(e, b)); e = c.next())
  5142. if (e.overscrollConfig) {
  5143. d = e;
  5144. break
  5145. }
  5146. }
  5147. } else
  5148. for (; c && !jZb(c, b); ) {
  5149. if (c.overscrollConfig) {
  5150. d = c;
  5151. break
  5152. }
  5153. c = c.parentElement
  5154. }
  5155. d && (b = d.overscrollConfig,
  5156. b.cooldown ? (d = a.deltaY,
  5157. c = b.lastDeltaY || 0,
  5158. b.lastDeltaY = d,
  5159. e = b.lastStopped || 0,
  5160. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  5161. c = !1) : (d = e + 600,
  5162. c = !0) : (d = Date.now() + 600,
  5163. c = !0),
  5164. d > Date.now() && (a.preventDefault(),
  5165. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  5166. }
  5167. */
  5168.  
  5169. let wheelHandler = function (a) {
  5170. if (window.Polymer && window.Polymer.Element) {
  5171. let c;
  5172. if (c = a.path || a.composedPath && a.composedPath()) {
  5173. for (const e of c) {
  5174. const cnt = insp(e);
  5175. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5176. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5177. }
  5178. }
  5179. } else {
  5180. let e = a.target;
  5181. for (; e instanceof Element; e = e.parentElement) {
  5182. const cnt = insp(e);
  5183. if (e.overscrollConfig) e.overscrollConfig = void 0;
  5184. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  5185. }
  5186. }
  5187. };
  5188.  
  5189. let checkWheelListenerObjs = null;
  5190.  
  5191. let getObjsFn = () => {
  5192. let euyVal = 0;
  5193. const eukElm = {};
  5194. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  5195. const euzObj = new Proxy(eukElm, {
  5196. get(target, prop) {
  5197. throw `ErrorF31.get(${prop})`
  5198. },
  5199. set(target, prop, value) {
  5200. throw `ErrorF33.set(${prop}, ${value})`
  5201. }
  5202. });
  5203. const euxElm = new Proxy(eukElm, {
  5204. get(target, prop) {
  5205. if (prop === 'scrollTop') {
  5206. euyVal = euyVal | 8;
  5207. return 0;
  5208. }
  5209. if (prop === 'overscrollConfig') {
  5210. euyVal = euyVal | 16;
  5211. return void 0;
  5212. }
  5213. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  5214. return 640;
  5215. }
  5216. if (prop === 'scrollLeft') {
  5217. euyVal = euyVal | 8;
  5218. return 0;
  5219. }
  5220. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  5221. return 800;
  5222. }
  5223. throw `ErrorF45.get(${prop})`
  5224. },
  5225. set(target, prop, value) {
  5226. throw `ErrorF47.set(${prop}, ${value})`
  5227. }
  5228. });
  5229. const eukEvt = {};
  5230. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  5231. const euyEvt = new Proxy(eukEvt, {
  5232. get(target, prop) {
  5233. if (prop === 'deltaY' || prop === 'deltaX') {
  5234. euyVal = euyVal | 1;
  5235. return -999;
  5236. }
  5237. if (prop === 'target') {
  5238. euyVal = euyVal | 2;
  5239. return euxElm
  5240. }
  5241. if (prop === 'path' || prop === 'composedPath') {
  5242. euyVal = euyVal | 2;
  5243. return [euxElm]
  5244. }
  5245. throw `ErrorF51.get(${prop})`
  5246. },
  5247. set(target, prop, value) {
  5248. throw `ErrorF53.set(${prop}, ${value})`
  5249. }
  5250. });
  5251. const setVal = (v) => {
  5252. euyVal = v;
  5253. }
  5254. const getVal = () => {
  5255. return euyVal;
  5256. }
  5257. return { euzObj, euyEvt, setVal, getVal };
  5258. }
  5259.  
  5260. let checkWheelListener = (callback) => {
  5261.  
  5262. let callbackIdentifier = '';
  5263.  
  5264. let res = null;
  5265. try {
  5266. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  5267. setVal(0);
  5268. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  5269. throw `RESULT${getVal()}`;
  5270. } catch (e) {
  5271. res = e;
  5272. }
  5273.  
  5274. res = `${res}` || `${null}`;
  5275. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  5276.  
  5277. callbackIdentifier = res;
  5278. if (callbackIdentifier === 'RESULT27') 0;
  5279. else if (callbackIdentifier === 'RESULT0') {
  5280. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  5281. } else if (callbackIdentifier.startsWith('RESULT')) {
  5282. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  5283. }
  5284. return callbackIdentifier;
  5285.  
  5286. };
  5287.  
  5288. let callbackFound = false;
  5289. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  5290. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  5291. // M-youtube-js-engine-tamer.52178
  5292. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  5293. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  5294. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  5295. // RESULTXX / ErrorFXX / Other...
  5296. if (callbackIdentifier === 'RESULT27') {
  5297. this.overscrollConfigDisable = true;
  5298. if (!callbackFound) {
  5299. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  5300. getObjsFn = checkWheelListener = null;
  5301. checkWheelListenerObjs = null;
  5302. wheelHandler = null;
  5303. }
  5304. return void 0;
  5305. } else if (!callbackFound && !this.overscrollConfigDisable) {
  5306. this.overscrollConfigDisable = true;
  5307. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  5308. }
  5309. }
  5310. return this.addEventListener52178(type, callback, option);
  5311. };
  5312.  
  5313. // ---- << this.overscrollConfig HACK >> -----
  5314.  
  5315. }
  5316.  
  5317. const check_for_set_key_order = (() => {
  5318.  
  5319. let mySet = new Set();
  5320.  
  5321. mySet.add("value1");
  5322. mySet.add("value2");
  5323. mySet.add("value3");
  5324.  
  5325. // Function to convert Set values to an array
  5326. function getSetValues(set) {
  5327. return Array.from(set.values());
  5328. }
  5329.  
  5330. // Function to test if the Set maintains insertion order
  5331. function testSetOrder(set, expectedOrder) {
  5332. let values = getSetValues(set);
  5333. return expectedOrder.join(',') === values.join(',');
  5334. }
  5335.  
  5336. // Test 1: Initial order
  5337. if (mySet.values().next().value !== "value1") return false;
  5338. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  5339.  
  5340. // Test 2: After deleting an element
  5341. mySet.delete("value2");
  5342. if (mySet.values().next().value !== "value1") return false;
  5343. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  5344.  
  5345. // Test 3: After re-adding a deleted element
  5346. mySet.add("value2");
  5347. if (mySet.values().next().value !== "value1") return false;
  5348. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  5349.  
  5350. // Test 4: After adding a new element
  5351. mySet.add("value4");
  5352. if (mySet.values().next().value !== "value1") return false;
  5353. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  5354.  
  5355. // Test 5: Delete+Add
  5356. mySet.delete("value1");
  5357. mySet.delete("value3");
  5358. mySet.add("value3");
  5359. mySet.add("value1");
  5360. if (mySet.values().next().value !== "value2") return false;
  5361. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  5362.  
  5363. return true;
  5364. })();
  5365.  
  5366.  
  5367. // const qm47 = Symbol();
  5368. // const qm57 = Symbol();
  5369. const qm53 = Symbol();
  5370. const qn53 = Symbol();
  5371.  
  5372.  
  5373. const ump3 = new WeakMap();
  5374.  
  5375. const stp = document.createElement('noscript');
  5376. stp.id = 'weakref-placeholder';
  5377.  
  5378. PROP_OverReInclusion_AVOID && (() => {
  5379.  
  5380.  
  5381. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  5382. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  5383. let byPassVal = null;
  5384. let byPassCount = 0;
  5385. let mmw = new Set();
  5386. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  5387. if (arguments.length !== 1) return f.apply(this, arguments);
  5388. if (byPassVal !== null && typeof prop === 'string') {
  5389.  
  5390. if (PROP_OverReInclusion_LIST.has(prop)) {
  5391. byPassCount++;
  5392. return byPassVal;
  5393. }
  5394. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  5395.  
  5396. }
  5397. return this.hasOwnProperty72(prop);
  5398. };
  5399.  
  5400.  
  5401. /*
  5402.  
  5403.  
  5404. z.prototype.forwardDynamicProps = function() {
  5405. var B = m(this.inst);
  5406. B = h(B);
  5407. for (var F = B.next(); !F.done; F = B.next()) {
  5408. var H = h(F.value);
  5409. F = H.next().value;
  5410. H = H.next().value;
  5411. my(this, F, H);
  5412. r(b) && !ly(F) && Wua(this.inst, F)
  5413. }
  5414. }
  5415.  
  5416. */
  5417.  
  5418.  
  5419.  
  5420. let byPassZeroShowed = false;
  5421. const forwardDynamicPropsGeneral = function () {
  5422. byPassVal = true;
  5423. byPassCount = 0;
  5424. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  5425. const ret = this.forwardDynamicProps72();
  5426. byPassVal = null;
  5427. if (byPassCount === 0 && !byPassZeroShowed) {
  5428. byPassZeroShowed = true;
  5429. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  5430. }
  5431. byPassCount = 0;
  5432. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  5433. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  5434. mmw.clear();
  5435. }
  5436. return ret;
  5437. };
  5438.  
  5439. const propCheck = (proto) => {
  5440. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  5441. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  5442. if (proto.forwardDynamicProps.length === 0) {
  5443. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  5444. }
  5445. }
  5446. };
  5447.  
  5448. const valMap = new WeakMap();
  5449. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  5450. get() {
  5451. propCheck(this.constructor.prototype);
  5452. return valMap.get(this);
  5453. },
  5454. set(nv) {
  5455. propCheck(this.constructor.prototype);
  5456. valMap.set(this, nv);
  5457. return true;
  5458. },
  5459. enumerable: false,
  5460. configurable: true
  5461.  
  5462. });
  5463.  
  5464. promiseForCustomYtElementsReady.then(() => {
  5465. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  5466. if (customElements.define.length !== 2) return;
  5467. customElements.define72 = customElements.define;
  5468. customElements.define = function (b, w) {
  5469. propCheck(w.prototype);
  5470. const ret = this.define72(b, w);
  5471. return ret;
  5472. }
  5473. });
  5474.  
  5475. })();
  5476.  
  5477. if (FIX_FlexibleItemSizing) { // for youtube flow chat
  5478.  
  5479. const flexibleItemListMo = new MutationObserver((mutations) => {
  5480. // cnt.onStamperFinished
  5481. // cnt.maybeUpdateFlexibleMenu
  5482. const set = new Set();
  5483. for (const mutation of mutations) {
  5484. if (mutation && ((mutation.addedNodes || 0).length > 0 || (mutation.removedNodes || 0).length > 0)) {
  5485. set.add(mutation.target);
  5486. }
  5487. }
  5488. for (const s of set) {
  5489. const cnt = insp(s);
  5490. if (typeof cnt.maybeUpdateFlexibleMenuImpl === 'function') {
  5491. cnt.maybeUpdateFlexibleMenuImpl();
  5492. } else if (typeof cnt.maybeUpdateFlexibleMenu === 'function') {
  5493. cnt.maybeUpdateFlexibleMenu();
  5494. } else if (typeof cnt.onStamperFinished === 'function') {
  5495. cnt.onStamperFinished();
  5496. }
  5497. }
  5498. set.clear();
  5499. });
  5500.  
  5501. let checkConfig = true;
  5502. const flexibleItemDocMo = new MutationObserver(() => {
  5503. for (const s of document.querySelectorAll('ytd-menu-renderer[has-flexible-items]:not([b289ad])')) {
  5504. s.setAttribute('b289ad', '');
  5505. flexibleItemListMo.observe(s, { subtree: false, childList: true });
  5506. s.appendChild(document.createComment('.')).remove();
  5507. }
  5508. if (checkConfig) {
  5509. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5510. if (config && config.EXPERIMENT_FLAGS) {
  5511. checkConfig = false;
  5512. config.EXPERIMENT_FLAGS.web_fix_missing_action_buttons = true;
  5513. }
  5514. }
  5515. });
  5516. flexibleItemDocMo.observe(document, { subtree: true, childList: true });
  5517.  
  5518. }
  5519.  
  5520.  
  5521.  
  5522.  
  5523. const observablePromise = (proc, timeoutPromise) => {
  5524. let promise = null;
  5525. return {
  5526. obtain() {
  5527. if (!promise) {
  5528. promise = new Promise(resolve => {
  5529. let mo = null;
  5530. const f = () => {
  5531. let t = proc();
  5532. if (t) {
  5533. mo.disconnect();
  5534. mo.takeRecords();
  5535. mo = null;
  5536. resolve(t);
  5537. }
  5538. }
  5539. mo = new MutationObserver(f);
  5540. mo.observe(document, { subtree: true, childList: true })
  5541. f();
  5542. timeoutPromise && timeoutPromise.then(() => {
  5543. resolve(null)
  5544. });
  5545. });
  5546. }
  5547. return promise
  5548. }
  5549. }
  5550. }
  5551.  
  5552.  
  5553. if (HOOK_ACTIVE_MODULES_fetchUpdatedMetadata) {
  5554. observablePromise(() => {
  5555. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  5556. if (config && config.EXPERIMENT_FLAGS) {
  5557. config.EXPERIMENT_FLAGS.web_watch_get_updated_metadata_manager = true;
  5558. return true;
  5559. }
  5560. }).obtain();
  5561. }
  5562.  
  5563. if (FIX_ROLLING_NUMBER_UPDATE) {
  5564.  
  5565.  
  5566. observablePromise(() => {
  5567. if (typeof customElements === 'undefined') return;
  5568. const ce = customElements.get('yt-animated-rolling-number');
  5569. if (!ce) return;
  5570. return ce.prototype;
  5571. }).obtain().then(async (cProto) => {
  5572.  
  5573. const p = document.createElement('yt-animated-rolling-number');
  5574.  
  5575. const frag = document.createDocumentFragment();
  5576. frag.appendChild(p);
  5577. const pDoc = document.implementation.createHTMLDocument();
  5578. pDoc.body.appendChild(frag);
  5579.  
  5580. let p88 = p;
  5581.  
  5582. const __instance = await observablePromise(() => {
  5583. const __instance = (p88 || 0).__instance;
  5584. if (__instance && __instance.render) return __instance;
  5585. }).obtain();
  5586. p88 = null;
  5587.  
  5588. const itProto = Reflect.getPrototypeOf(__instance);
  5589.  
  5590. try {
  5591. p.remove();
  5592. } catch (e) { }
  5593.  
  5594. if (itProto.render && !itProto.render37 && itProto.render.length === 1) {
  5595.  
  5596. itProto.render37 = itProto.render;
  5597. itProto.render = function (t) {
  5598. // (this.xCounter = (this.xCounter & 1073741823)+1)
  5599. let c33 = '';
  5600. let r33 = null;
  5601. let kc = 0;
  5602.  
  5603. let dataType = 0;
  5604.  
  5605. if (t && (('data' in t) || ('buttonShapeOverrideables' in t))) {
  5606. dataType = 1;
  5607. } else if (t && ('heightPx' in t)) {
  5608. dataType = 2;
  5609. } else if (t) {
  5610. dataType = 3;
  5611. }
  5612.  
  5613. if (dataType === 3 && this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  5614. const el = this.el;
  5615. const ct = Date.now();
  5616. const lastFireTime = (el.__lastFireTime491__ || 0);
  5617.  
  5618. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  5619.  
  5620. if (fireTimeDiff < 80 && this.__previousRender61__) {
  5621. return this.__previousRender61__;
  5622. }
  5623.  
  5624. // console.log(3772, t);
  5625.  
  5626. const caseInt =
  5627. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  5628. (t && typeof t.character === 'string') ? (
  5629. (typeof t.previousCharacter === 'string') ? 6 : 2
  5630. ) : 0;
  5631.  
  5632. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender61__ && fireTimeDiff < 9400) {
  5633. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender61__) {
  5634. return this.__previousRender61__;
  5635. }
  5636. }
  5637. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender61__ && fireTimeDiff < 9400) {
  5638. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender61__) {
  5639. return this.__previousRender61__;
  5640. }
  5641. }
  5642.  
  5643. if (caseInt & 2) {
  5644.  
  5645. if (caseInt & 4) {
  5646.  
  5647. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  5648. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  5649. t.previousCharacter = t.character;
  5650. kc = 1;
  5651. }
  5652. }
  5653.  
  5654. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  5655. t.shouldAnimate = false;
  5656. }
  5657. }
  5658.  
  5659.  
  5660. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  5661.  
  5662. el.__lastCharacter353__ = t.character;
  5663.  
  5664. } else if (caseInt === 1) {
  5665.  
  5666. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  5667. t.shouldAnimate = false;
  5668. }
  5669. el.__lastNumberValue353__ = t.numberValue;
  5670.  
  5671. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  5672. t.shouldAnimate = false;
  5673. }
  5674. el.__lastNumberText353__ = t.numberText;
  5675.  
  5676. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  5677.  
  5678. }
  5679.  
  5680. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  5681.  
  5682. el.__lastFireTime491__ = ct;
  5683. } else if (dataType === 2 && this && t && this.hookCounter >= 1 && !this.__unmounted && this.el) {
  5684. const el = this.el;
  5685. const ct = Date.now();
  5686. const lastFireTime = (el.__lastFireTime493__ || 0);
  5687.  
  5688. const fireTimeDiff = lastFireTime > 0 ? ct - lastFireTime : 1e9;
  5689.  
  5690. if (fireTimeDiff < 80 && this.__previousRender63__) {
  5691. return this.__previousRender63__;
  5692. }
  5693.  
  5694. // console.log(3772, t);
  5695.  
  5696. const caseInt =
  5697. (t && typeof t.numberText === 'string' && Number.isFinite(t.numberValue)) ? 1 :
  5698. (t && typeof t.character === 'string') ? (
  5699. (typeof t.previousCharacter === 'string') ? 6 : 2
  5700. ) : 0;
  5701.  
  5702. if (caseInt === 6 && t.previousCharacter && t.character && this.__previousRender63__ && fireTimeDiff < 9400) {
  5703. if (this[`__lastCharRender62__${t.previousCharacter}>${t.character}`] === this.__previousRender63__) {
  5704. return this.__previousRender63__;
  5705. }
  5706. }
  5707. if (caseInt === 1 && t.numberText.length > 0 && this.__previousRender63__ && fireTimeDiff < 9400) {
  5708. if (this[`__lastCharRender65__${t.numberValue}>${t.numberText}`] === this.__previousRender63__) {
  5709. return this.__previousRender63__;
  5710. }
  5711. }
  5712.  
  5713. if (caseInt & 2) {
  5714.  
  5715. if (caseInt & 4) {
  5716.  
  5717. if (el.__lastCharacter353__ && el.__lastCharacter353__.length === 1 && t.character.length === 1 && t.previousCharacter.length === 1) {
  5718. if (t.character !== t.previousCharacter && t.character === el.__lastCharacter353__) {
  5719. t.previousCharacter = t.character;
  5720. kc = 1;
  5721. }
  5722. }
  5723.  
  5724. if (t && t.character && t.previousCharacter && t.shouldAnimate === true && t.character === t.previousCharacter) {
  5725. t.shouldAnimate = false;
  5726. }
  5727. }
  5728.  
  5729.  
  5730. c33 = `__lastCharRender62__${t.previousCharacter}>${t.character}`;
  5731.  
  5732. el.__lastCharacter353__ = t.character;
  5733.  
  5734. } else if (caseInt === 1) {
  5735.  
  5736. if (el.__lastNumberValue353__ === t.numberValue && t.shouldAnimate === true) {
  5737. t.shouldAnimate = false;
  5738. }
  5739. el.__lastNumberValue353__ = t.numberValue;
  5740.  
  5741. if (el.__lastNumberText353__ === t.numberText && t.shouldAnimate === true) {
  5742. t.shouldAnimate = false;
  5743. }
  5744. el.__lastNumberText353__ = t.numberText;
  5745.  
  5746. c33 = `__lastCharRender65__${t.numberValue}>${t.numberText}`;
  5747.  
  5748. }
  5749.  
  5750. // console.log(138002, this, t, caseInt, kc, fireTimeDiff);
  5751.  
  5752. el.__lastFireTime493__ = ct;
  5753. }
  5754.  
  5755. // // console.log(21399, t.character, t.previousCharacter, (t.xCounter = (t.xCounter & 1073741823)+1), t, (this.xCounter = (this.xCounter & 1073741823)+1) )
  5756. // // console.log(12883, this, t);
  5757. const r = r33 || this.render37(t);
  5758. if (dataType === 3) {
  5759. this.__previousRender61__ = r;
  5760. } else if (dataType === 2) {
  5761. this.__previousRender63__ = r;
  5762. }
  5763. if (c33) this[c33] = r;
  5764. return r
  5765. }
  5766.  
  5767. }
  5768.  
  5769. });
  5770.  
  5771. }
  5772.  
  5773. if (HOOK_ACTIVE_MODULES) {
  5774.  
  5775. let watchController;
  5776. const watchControllerObservable = observablePromise(() => {
  5777. const watchFlexy = document.querySelector('ytd-watch-flexy');
  5778. if (!watchFlexy) return;
  5779. return insp(watchFlexy).watchController;
  5780. }).obtain();
  5781. (async () => {
  5782. watchController = await watchControllerObservable;
  5783.  
  5784. const activeModules = watchController.activeModules;
  5785. if (!activeModules) return;
  5786.  
  5787. const checkFn = (activeModule) => {
  5788. if (activeModule && typeof activeModule.fetchUpdatedMetadata === 'function' && activeModule.fetchUpdatedMetadata.length === 2) {
  5789. HOOK_ACTIVE_MODULES_fetchUpdatedMetadata && hookActiveModuleFetchUpdatedMetadata(activeModule);
  5790. }
  5791. }
  5792. if (!activeModules.push8792 && activeModules.push) {
  5793. activeModules.push8792 = activeModules.push;
  5794. activeModules.push = function (a, ...args) {
  5795. checkFn(a);
  5796. let r = args.length >= 1 ? this.push8792(a, ...args) : this.push8792(a);
  5797. return r;
  5798. }
  5799. }
  5800. activeModules.forEach(checkFn);
  5801.  
  5802. })();
  5803.  
  5804. let yieldResultWrappingByPass = false;
  5805. let asyncProto = null;
  5806. const yieldResultWrapping = (f) => {
  5807. if (yieldResultWrappingByPass) return [f(), null];
  5808. yieldResultWrappingByPass = true;
  5809. let D = null;
  5810. let promise, e_;
  5811. if (asyncProto) {
  5812. Object.defineProperty(asyncProto, 'yieldResult', {
  5813. get() {
  5814. return undefined;
  5815. },
  5816. set(nv) {
  5817. delete asyncProto.yieldResult;
  5818. this.yieldResult = nv;
  5819. D = this;
  5820. // console.log(122, this);
  5821. return true;
  5822. },
  5823. enumerable: false,
  5824. configurable: true
  5825. });
  5826. try {
  5827. promise = f();
  5828. } catch (e) { e_ = e }
  5829. delete asyncProto.yieldResult;
  5830. yieldResultWrappingByPass = false;
  5831. } else {
  5832. Object.defineProperty(Object.prototype, 'yieldResult', {
  5833. get() {
  5834. return undefined;
  5835. },
  5836. set(nv) {
  5837. delete Object.prototype.yieldResult;
  5838. this.yieldResult = nv;
  5839. D = this;
  5840. // console.log(122, this);
  5841. return true;
  5842. },
  5843. enumerable: false,
  5844. configurable: true
  5845. });
  5846. try {
  5847. promise = f();
  5848. } catch (e) { e_ = e }
  5849. delete Object.prototype.yieldResult;
  5850. yieldResultWrappingByPass = false;
  5851. if (D) {
  5852. asyncProto = Reflect.getPrototypeOf(D);
  5853. }
  5854. }
  5855. if (e_) throw e_;
  5856. return [promise, D];
  5857. }
  5858.  
  5859. const hookActiveModuleFetchUpdatedMetadata = (activeModule) => {
  5860.  
  5861. const aProto = Reflect.getPrototypeOf(activeModule);
  5862.  
  5863. if (!aProto || !aProto.fetchUpdatedMetadata || aProto.fetchUpdatedMetadata517) return;
  5864.  
  5865. console.log('[yt-js-engine-tamer] hookActiveModuleFetchUpdatedMetadata');
  5866.  
  5867. // console.log(12885)
  5868. aProto.fetchUpdatedMetadata517 = aProto.fetchUpdatedMetadata;
  5869. // let qxt=false;
  5870. const renderLikeButtonViewModel = (likeButtonViewModel) => {
  5871. if (!likeButtonViewModel || likeButtonViewModel.isConnected !== true) return;
  5872. if (likeButtonViewModel.querySelector('yt-animated-rolling-number')) return; // no need to render
  5873. const likeModelInstance = inup(likeButtonViewModel);
  5874. const props = (likeModelInstance || 0).props;
  5875. if (likeModelInstance && likeModelInstance.render && props) {
  5876. const data = (props || 0).data;
  5877. if (data && data.toggleButtonViewModel && props.likeCountEntity) {
  5878. likeModelInstance.render(props)
  5879. // likeModelInstance.functionComponent(props);
  5880. }
  5881. }
  5882. }
  5883. aProto.fetchUpdatedMetadata = function (t, P) {
  5884.  
  5885. // if (!qxt) {
  5886. // qxt = true;
  5887. // var y = watchController.subscribe("WATCH_NEXT_RESPONSE_UPDATED", function (...args) {
  5888. // console.log(199001,...args)
  5889. // });
  5890. // this.addOnDisposeCallback(function (...args) {
  5891.  
  5892. // console.log(199002,...args)
  5893. // watchController.unsubscribeByKey(y)
  5894. // qxt = false;
  5895. // });
  5896. // }
  5897. const [promise, D] = yieldResultWrapping(() => this.fetchUpdatedMetadata517(t, P));
  5898. if (D) promise.then(() => {
  5899. const yieldResult = D.yieldResult;
  5900. if (yieldResult) {
  5901. const mutations = (((yieldResult || 0).frameworkUpdates || 0).entityBatchUpdate || 0).mutations;
  5902. const mutations_ = mutations.slice(); // array clone
  5903. if (mutations_ && mutations_.length >= 1) {
  5904. let likeCountEntity = null;
  5905. for (const mutation of mutations_) {
  5906. if (typeof (mutation.entityKey || 0) === 'string' && (likeCountEntity = (mutation.payload || 0).likeCountEntity)) {
  5907. break;
  5908. }
  5909. }
  5910. if (typeof (likeCountEntity || 0) === 'object') {
  5911. const modelElement = document.querySelector('segmented-like-dislike-button-view-model');
  5912. const model = insp(modelElement);
  5913. const modelInstance = inup(modelElement);
  5914. if (model && modelInstance) {
  5915. const data = ((modelInstance || 0).props || 0).data;
  5916. if (typeof (data || 0) === 'object') {
  5917. if (typeof data.likeCountEntity !== 'object') data.likeCountEntity = {};
  5918. // console.log(12838, {...data.likeCountEntity}, {...likeCountEntity})
  5919. const shouldModelUpdateInit = (data.likeCountEntity.key !== likeCountEntity.key);
  5920. const shouldModelUpdateModel = true;
  5921. Object.assign(data.likeCountEntity, likeCountEntity);
  5922. // data.likeCountEntity = likeCountEntity;
  5923. // if (shouldModelupdate) model.update();
  5924. // else {
  5925. // if (typeof model.notifyPath === 'function' && model.notifyPath.length === 0) model.notifyPath();
  5926. // }
  5927. if (shouldModelUpdateModel) {
  5928. if (typeof model.enqueueUpdate === 'function' && model.enqueueUpdate.length === 0) {
  5929. model.enqueueUpdate();
  5930. } else if (typeof model.update === 'function' && model.update.length === 0) {
  5931. model.update();
  5932. } else {
  5933. console.warn('[yt-js-engine-tamer] cannot do model update.')
  5934. }
  5935. }
  5936. if (shouldModelUpdateInit) {
  5937. const likeButtonViewModel = modelElement.querySelector('like-button-view-model[class]');
  5938. if (likeButtonViewModel) {
  5939. if (!likeButtonViewModel.querySelector('yt-animated-rolling-number')) {
  5940. renderLikeButtonViewModel(likeButtonViewModel);
  5941. }
  5942. }
  5943. }
  5944.  
  5945. }
  5946. }
  5947. }
  5948. }
  5949. }
  5950. }).catch(console.warn);
  5951. return promise;
  5952. };
  5953.  
  5954. }
  5955.  
  5956. }
  5957.  
  5958. // ----------------------------
  5959.  
  5960. const nativeNow = Reflect.getPrototypeOf(performance).now.bind(performance);
  5961.  
  5962. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  5963.  
  5964. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  5965.  
  5966.  
  5967. // const globalPromiseStack = {};
  5968.  
  5969. // let dummy;
  5970. // while(!dummy){
  5971.  
  5972. // dummy = document.querySelector('yt-icon');
  5973. // await new Promise(r=>setTimeout(r,0));
  5974. // }
  5975.  
  5976. dummy = document.createElement('yt-icon');
  5977.  
  5978. let cProto;
  5979. if (!(dummy instanceof Element)) return;
  5980. cProto = insp(dummy).constructor.prototype;
  5981.  
  5982. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  5983. cProto.determineIconSet671 = cProto.determineIconSet;
  5984. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  5985. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  5986. cProto.getIconManager671 = cProto.getIconManager;
  5987. cProto.getIconShapeData671 = cProto.getIconShapeData;
  5988. cProto.renderIcon671 = cProto.renderIcon;
  5989.  
  5990. // cProto.attached488 = cProto.attached;
  5991. // cProto.attached = function(){
  5992. // console.log('attached')
  5993. // return this.attached488(...arguments);
  5994. // }
  5995. // cProto.detached488 = cProto.detached;
  5996. // cProto.detached = function(){
  5997. // console.log('detached')
  5998. // return this.detached488(...arguments);
  5999. // }
  6000.  
  6001. if (cProto.__renderIconFix__) return;
  6002. cProto.__renderIconFix__ = true;
  6003.  
  6004. let taskStack = [];
  6005. const cmObs = new MutationObserver(() => {
  6006. const tasks = taskStack.slice();
  6007. taskStack.length = 0;
  6008. for (const task of tasks) {
  6009. task();
  6010. }
  6011. })
  6012. const cm = document.createComment('1');
  6013. const stackTask = (f) => {
  6014. taskStack.push(f);
  6015. cm.data = `${(cm.data & 7) + 1}`;
  6016. }
  6017. cmObs.observe(cm, { characterData: true });
  6018.  
  6019. // let iconManagers = {}; // assume shared
  6020.  
  6021. // window.iconManagers = () => iconManagers;
  6022.  
  6023.  
  6024. const setupYtIcon = (inst) => {
  6025.  
  6026. if (inst.__ytIconSetup588__) return;
  6027. const cProto = Reflect.getPrototypeOf(inst);
  6028. cProto.__ytIconSetup588__ = true;
  6029.  
  6030.  
  6031. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  6032.  
  6033. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  6034. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  6035. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  6036. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  6037.  
  6038.  
  6039. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  6040. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  6041. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  6042. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  6043.  
  6044.  
  6045.  
  6046. }
  6047.  
  6048. cProto.handlePropertyChange = function (...a) { // 10+
  6049.  
  6050. const __data = this.__data;
  6051. if (FIX_GUIDE_ICON && this.id === 'guide-icon' && __data && !__data.icon && typeof this.set === 'function') {
  6052. this.set('icon', "yt-icons:menu")
  6053. }
  6054.  
  6055. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6056. this.__resolved__ = {
  6057.  
  6058. };
  6059. const a01 = this.isAttached;
  6060. let a02, a03;
  6061.  
  6062.  
  6063. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  6064.  
  6065. const stackFn = () => {
  6066. if (t !== this.__stackedKey3818__) {
  6067. return;
  6068. }
  6069. a03 = this.isAttached;
  6070.  
  6071. if (a01 === false && a02 === false && a03 === false) return;
  6072.  
  6073. if (a01 === true && a02 === true && a03 === true) {
  6074.  
  6075. } else {
  6076. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  6077. // unknown yt-icon#label-icon
  6078. return;
  6079. } else {
  6080. console.log('[yt-icon] debug', a01, a02, a03, this)
  6081. }
  6082. }
  6083.  
  6084. this.handlePropertyChange671(...arguments);
  6085.  
  6086. };
  6087.  
  6088.  
  6089.  
  6090. Promise.resolve().then(() => {
  6091. a02 = this.isAttached;
  6092. stackTask(stackFn);
  6093. });
  6094.  
  6095.  
  6096. }
  6097.  
  6098. cProto.determineIconSet = function (a, b, c, d) { // 10-
  6099.  
  6100. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6101. // string bool? bool=false int=24
  6102. // NOTIFICATIONS_NONE OR LIKE
  6103. // console.log('yt-icon.determineIconSet', ...arguments);
  6104.  
  6105. const r = this.determineIconSet671(...arguments);
  6106. return r;
  6107. }
  6108.  
  6109. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  6110.  
  6111. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6112. // same as determineIconSet
  6113. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  6114. return this.switchToYtSysIconset671(...arguments);
  6115. }
  6116.  
  6117. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  6118.  
  6119. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6120. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  6121. return this.useYtSysIconsetForMissingIcons671(...arguments);
  6122. }
  6123.  
  6124. cProto.getIconManager = function () { // 10+
  6125.  
  6126. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6127. if (!this.__resolved__) this.__resolved__ = {};
  6128. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  6129. const r = this.__resolved__.getIconManager;
  6130. return r;
  6131. }
  6132.  
  6133. cProto.getIconShapeData = function () { // 10+
  6134.  
  6135. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6136.  
  6137. // no argument
  6138. // console.log('yt-icon.getIconShapeData', ...arguments);
  6139. if (!this.__resolved__) this.__resolved__ = {};
  6140. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  6141. const r = this.__resolved__.getIconShapeData;
  6142. return r
  6143. }
  6144.  
  6145. cProto.renderIcon = function (a, b) { // X
  6146.  
  6147. if (!this.__ytIconSetup588__) setupYtIcon(this);
  6148. // "" yt-icons:xxx
  6149. // console.log('yt-icon.renderIcon', ...arguments);
  6150. return this.renderIcon671(...arguments);
  6151. }
  6152.  
  6153. });
  6154.  
  6155.  
  6156. /**
  6157. * Compute the Longest Common Subsequence between two arrays.
  6158. * Returns an array of the LCS elements (in order).
  6159. */
  6160. function computeLCS(a, b) {
  6161. // Input validation
  6162. if (!Array.isArray(a) || !Array.isArray(b)) {
  6163. throw new Error('Inputs must be arrays');
  6164. }
  6165.  
  6166. const n = a.length, m = b.length;
  6167. // Early termination for trivial cases
  6168. if (n === 0 || m === 0) return [];
  6169. // Check for shallow equality
  6170. if (n === m && a.every((x, i) => x === b[i])) return a.slice();
  6171.  
  6172. // Use smaller dimension for space optimization
  6173. if (n > m) return computeLCS(b, a); // Ensure n <= m
  6174.  
  6175. // dp[i%2][j] = length of LCS of a[i..] and b[j..]
  6176. // Use Uint32Array for robustness with long sequences
  6177. const dp = [
  6178. new Uint32Array(m + 1),
  6179. new Uint32Array(m + 1),
  6180. ];
  6181. // Store predecessor for backtracking: 0=diagonal, 1=down, 2=right
  6182. // Optimize space by storing only necessary entries
  6183. const pred = new Uint8Array(n * m); // Single array for moves
  6184.  
  6185. for (let i = n - 1; i >= 0; i--) {
  6186. const curr = i % 2;
  6187. const next = 1 - curr;
  6188. // Clear current row for reuse
  6189. dp[curr].fill(0);
  6190.  
  6191. for (let j = m - 1; j >= 0; j--) {
  6192. const idx = i * m + j;
  6193. if (a[i] === b[j]) {
  6194. dp[curr][j] = dp[next][j + 1] + 1;
  6195. pred[idx] = 0; // Diagonal
  6196. } else if (dp[next][j] >= dp[curr][j + 1]) {
  6197. dp[curr][j] = dp[next][j];
  6198. pred[idx] = 1; // Down
  6199. } else {
  6200. dp[curr][j] = dp[curr][j + 1];
  6201. pred[idx] = 2; // Right
  6202. }
  6203. }
  6204. }
  6205.  
  6206. // Check for potential overflow
  6207. if (dp[0][0] > 0xFFFFFFFF) {
  6208. throw new Error('LCS length exceeds safe integer limit');
  6209. }
  6210.  
  6211. // Backtrack to build the actual LCS
  6212. const lcs = [];
  6213. let i = 0, j = 0;
  6214. while (i < n && j < m) {
  6215. const idx = i * m + j;
  6216. const p = pred[idx];
  6217. if (p === 0) {
  6218. lcs.push(a[i]);
  6219. i++; j++;
  6220. } else if (p === 1) {
  6221. i++;
  6222. } else {
  6223. j++;
  6224. }
  6225. }
  6226. return lcs;
  6227. }
  6228.  
  6229. /**
  6230. * Given original[] and modified[], produce an array of splice-ops:
  6231. * [ [start0, deleteCount0, addedItems0],
  6232. * [start1, deleteCount1, addedItems1],
  6233. * … ]
  6234. * When you do:
  6235. * let arr = original.slice();
  6236. * for (let [s, d, adds] of ops) arr.splice(s, d, ...adds);
  6237. * arr will equal modified.
  6238. */
  6239. function diffSplices(original, modified) {
  6240. // Input validation
  6241. if (!Array.isArray(original) || !Array.isArray(modified)) {
  6242. throw new Error('Inputs must be arrays');
  6243. }
  6244.  
  6245. const origLen = original.length;
  6246. const modLen = modified.length;
  6247. // Early termination for trivial cases
  6248. if (origLen === 0 && modLen === 0) return [];
  6249. if (origLen === 0) return [[0, 0, modified.slice()]];
  6250. if (modLen === 0) return [[0, origLen, []]];
  6251.  
  6252. // Trim common prefix and suffix
  6253. let prefixLen = 0;
  6254. while (prefixLen < origLen && prefixLen < modLen && original[prefixLen] === modified[prefixLen]) {
  6255. prefixLen++;
  6256. }
  6257. let suffixLen = 0;
  6258. while (
  6259. suffixLen < origLen - prefixLen &&
  6260. suffixLen < modLen - prefixLen &&
  6261. original[origLen - 1 - suffixLen] === modified[modLen - 1 - suffixLen]
  6262. ) {
  6263. suffixLen++;
  6264. }
  6265.  
  6266. // Cache references for speed
  6267. const orig = original.slice(prefixLen, origLen - suffixLen);
  6268. const mod = modified.slice(prefixLen, modLen - suffixLen);
  6269. const lcs = computeLCS(orig, mod);
  6270. // Pre-allocate ops array, accounting for potential moves
  6271. const ops = new Array(Math.ceil((orig.length + mod.length) / 1.5));
  6272. let opCount = 0;
  6273.  
  6274. let i = 0, j = 0, k = 0;
  6275. let curIndex = prefixLen;
  6276. const lcsLen = lcs.length;
  6277.  
  6278. while (k < lcsLen) {
  6279. const match = lcs[k];
  6280. let deleteCount = 0;
  6281. const deleted = [];
  6282. const added = [];
  6283.  
  6284. // 1) Collect deletions up to the next common element
  6285. while (i < orig.length && orig[i] !== match) {
  6286. deleted.push(orig[i]);
  6287. deleteCount++;
  6288. i++;
  6289. }
  6290.  
  6291. // 2) Collect insertions up to that same element
  6292. while (j < mod.length && mod[j] !== match) {
  6293. added.push(mod[j]);
  6294. j++;
  6295. }
  6296.  
  6297. // 3) Check for a move (deleted segment matches inserted segment)
  6298. let isMove = false;
  6299. if (deleteCount > 0 && deleteCount === added.length) {
  6300. isMove = deleted.every((x, idx) => x === added[idx]);
  6301. if (isMove) {
  6302. // If a move, split into delete and insert at different indices
  6303. if (deleteCount > 0) {
  6304. ops[opCount++] = [curIndex, deleteCount, []]; // Delete at current index
  6305. ops[opCount++] = [curIndex, 0, added]; // Insert at same index
  6306. curIndex += added.length; // Advance past inserted items
  6307. }
  6308. }
  6309. }
  6310.  
  6311. // 4) Combine delete and insert into a single operation if not a move
  6312. if (!isMove && (deleteCount > 0 || added.length > 0)) {
  6313. ops[opCount++] = [curIndex, deleteCount, added];
  6314. curIndex += added.length; // Advance past inserted items
  6315. }
  6316.  
  6317. // 5) Skip over the matching element itself
  6318. i++;
  6319. j++;
  6320. k++;
  6321. curIndex++;
  6322. }
  6323.  
  6324. // 6) Handle any trailing deletions and insertions as a single operation
  6325. const trailingDelete = orig.length - i;
  6326. const trailingAdd = mod.slice(j);
  6327. if (trailingDelete > 0 || trailingAdd.length > 0) {
  6328. // Check for trailing move
  6329. const trailingDeleted = orig.slice(i);
  6330. let isMove = false;
  6331. if (trailingDelete > 0 && trailingDelete === trailingAdd.length) {
  6332. isMove = trailingDeleted.every((x, idx) => x === trailingAdd[idx]);
  6333. if (isMove) {
  6334. ops[opCount++] = [curIndex, trailingDelete, []];
  6335. ops[opCount++] = [curIndex, 0, trailingAdd];
  6336. }
  6337. }
  6338. if (!isMove) {
  6339. ops[opCount++] = [curIndex, trailingDelete, trailingAdd];
  6340. }
  6341. }
  6342.  
  6343. // 7) Truncate ops array to actual size
  6344. ops.length = opCount;
  6345.  
  6346. return ops;
  6347. }
  6348. // class listPlaceholder {
  6349. // constructor(len){
  6350. // this.length = len;
  6351. // }
  6352. // }
  6353.  
  6354.  
  6355.  
  6356. // rendererStamperApplyChangeRecord_: function(path, key, changeRecord) {
  6357. // var renderJob = this.renderJobsMap_[key],
  6358. // renderCallback = null;
  6359.  
  6360. // if (path === changeRecord.path) {
  6361. // let value = changeRecord.value;
  6362.  
  6363. // if (!_.v_(value)) {
  6364. // value = (value === void 0 || value === null) ? [] : [value];
  6365. // }
  6366.  
  6367. // let stampDomEntry = this.stampDom[path];
  6368.  
  6369. // if (stampDomEntry.mapping) {
  6370. // renderCallback = this.stampDomArray_.bind(
  6371. // this,
  6372. // value,
  6373. // key,
  6374. // stampDomEntry.mapping,
  6375. // stampDomEntry.reuseComponents,
  6376. // stampDomEntry.events,
  6377. // stampDomEntry.stamperStableList
  6378. // );
  6379. // }
  6380.  
  6381. // if (renderJob) renderJob.cancel();
  6382.  
  6383. // let taskManager = stampDomEntry.usePageScheduler ? this.getTaskManager()() : void 0;
  6384.  
  6385. // if (!renderJob && stampDomEntry.initialRenderPriority == void 0) {
  6386. // if (stampDomEntry.renderPriority != void 0 && !renderJob) {
  6387. // renderJob = new _.X6(stampDomEntry.renderPriority, stampDomEntry.waitForSignal, taskManager);
  6388. // this.renderJobsMap_[key] = renderJob;
  6389. // }
  6390. // } else {
  6391. // renderJob = new _.X6(stampDomEntry.initialRenderPriority, stampDomEntry.waitForSignal, taskManager);
  6392. // this.renderJobsMap_[key] = renderJob;
  6393. // renderCallback = function(callback, job) {
  6394. // callback();
  6395. // q4C(job, 10);
  6396. // }.bind(this, renderCallback, renderJob);
  6397. // }
  6398. // } else {
  6399. // renderCallback = (path + ".splices" === changeRecord.path)
  6400. // ? this.stampDomArraySplices_.bind(this, path, key, changeRecord.value)
  6401. // : this.forwardRendererStamperChanges_.bind(this, path, key, changeRecord);
  6402. // }
  6403.  
  6404. // if (renderJob) {
  6405. // _.vY(renderJob, renderCallback);
  6406. // } else {
  6407. // renderCallback();
  6408. // }
  6409. // }
  6410.  
  6411.  
  6412.  
  6413.  
  6414. const createStampDomFnsC_ = () => {
  6415.  
  6416. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  6417.  
  6418. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  6419. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  6420.  
  6421.  
  6422. // const rq0 = document.createElement('rp');
  6423. // rq0.setAttribute('yt-element-placholder', '');
  6424.  
  6425. const it0 = Date.now() - 80000000000;
  6426. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  6427.  
  6428.  
  6429. const getStampContainer_ = function (containerId) {
  6430.  
  6431. return this.getStampContainer7409_(containerId);
  6432.  
  6433. }
  6434.  
  6435.  
  6436.  
  6437.  
  6438. const createComponent_ = function (componentConfig, data, canReuse) {
  6439.  
  6440. return this.createComponent7409_(componentConfig, data, canReuse);
  6441.  
  6442. }
  6443.  
  6444.  
  6445. const s52 = Symbol();
  6446.  
  6447. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  6448.  
  6449. // if(component.querySelectorAll('dom-if').length > 0){
  6450.  
  6451. // // console.log(1233, component.isConnected, component.parentNode, component.querySelectorAll('dom-if'))
  6452. // if (component.isConnected === false) {
  6453. // for (const s of component.querySelectorAll('dom-if')) {
  6454. // try {
  6455. // console.log(1299);
  6456. // insp(s).__teardownInstance();
  6457. // } catch (e) { }
  6458. // }
  6459. // }
  6460.  
  6461. // }
  6462.  
  6463. if (typeof (data || 0) === 'object') {
  6464. if (!data[s52]) data[s52] = genId();
  6465. component[s52] = data[s52];
  6466. // console.log(component[s52], data);
  6467. } else {
  6468. component[s52] = null;
  6469. }
  6470.  
  6471. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  6472.  
  6473. }
  6474.  
  6475. // let pr77 = Promise.resolve();
  6476.  
  6477. const flushRenderStamperComponentBindings_ = function () {
  6478. if (!this.__qsd477__ || !this.deferredBindingTasks_) return this.flushRenderStamperComponentBindings7409_();
  6479.  
  6480. if (this.deferredBindingTasks_.length >= 0) {
  6481.  
  6482. // const deferredBindingTasks_ = this.deferredBindingTasks_;
  6483.  
  6484. const gid = this[`__$$stampFlushKey$$__`] = genId();
  6485. const g = (() => {
  6486. if (gid !== this[`__$$stampFlushKey$$__`]) { return; }
  6487. // if (deferredBindingTasks_.length === 0) return;
  6488. // let q = this.deferredBindingTasks_;
  6489. // this.deferredBindingTasks_ = deferredBindingTasks_;
  6490. this.flushRenderStamperComponentBindings7409_();
  6491. // deferredBindingTasks_.length = 0;
  6492. // this.deferredBindingTasks_ = q;
  6493.  
  6494. const s = [...this.__lat457__];
  6495. this.__lat457__.clear();
  6496.  
  6497. for (const containerWr of s) {
  6498.  
  6499. const container = kRef(containerWr);
  6500. if (!container) continue;
  6501.  
  6502. // const s = new Set();
  6503. if (!container.querySelector('[ytx-flushing]')) {
  6504. if (container.hasAttribute('ytx-flushing')) {
  6505. const attrVal = container.getAttribute('ytx-flushing');
  6506. container.removeAttribute('ytx-flushing');
  6507. // s.add([container, attrVal]);
  6508. addTask(container, attrVal);
  6509. // addTaskIm(container, attrVal);
  6510. let ancestor = container.closest('[ytx-flushing]');
  6511. while (ancestor) {
  6512. if (ancestor.querySelector('[ytx-flushing]')) break;
  6513. const attrVal = ancestor.getAttribute('ytx-flushing');
  6514. ancestor.removeAttribute('ytx-flushing');
  6515. // s.add([ancestor, attrVal]);
  6516. addTask(ancestor, attrVal);
  6517. // addTaskIm(ancestor, attrVal);
  6518. ancestor = ancestor.closest('[ytx-flushing]');
  6519. }
  6520. }
  6521. }
  6522. }
  6523. executeTasks();
  6524.  
  6525.  
  6526. });
  6527. g();
  6528. // const useMicroTaskQueue = this.__qsd477__ === 2;
  6529. // useMicroTaskQueue ? addTask2(g) : g();
  6530. // executeTasks();
  6531.  
  6532. // addTask2(g);
  6533. // executeTasks();
  6534.  
  6535. }
  6536.  
  6537. throw new Error('e5bd8d2f');
  6538.  
  6539. }
  6540.  
  6541. let tasks = [];
  6542. let excuted = false;
  6543. const executeTasks = ()=>{
  6544. if(excuted || tasks.length === 0) return;
  6545. excuted = true;
  6546. let t0 = 0;
  6547. const perform = ()=>{
  6548. if(!t0) t0 = nativeNow();
  6549. const task = tasks.shift();
  6550. if(!task){
  6551. excuted = false;
  6552. return;
  6553. }
  6554. task.fn(task);
  6555. const t1 = nativeNow();
  6556. if(t1 - t0 > 10){
  6557. t0 = 0;
  6558. nextBrowserTick_(perform);
  6559. }else{
  6560. queueMicrotask_(perform);
  6561. }
  6562. }
  6563. queueMicrotask_(perform);
  6564. }
  6565.  
  6566. const taskFn = (task) => {
  6567.  
  6568. if(!task) return;
  6569. const { containerWr, attrVal } = task;
  6570. const container = kRef(containerWr);
  6571. if (!container) return;
  6572. if (attrVal === '0') return;
  6573. const bEventCb = attrVal === '2';
  6574. const producerWr = containerMapping.get(container);
  6575. const producer = kRef(producerWr);
  6576. if (!producer) return;
  6577. const hostElement = producer.hostElement;
  6578. if (!hostElement) return;
  6579. if (hostElement.isConnected !== true) return; // tbc
  6580. producer.markDirty && producer.markDirty();
  6581. bEventCb && dispatchYtEvent(hostElement, "yt-rendererstamper-finished", {
  6582. container
  6583. });
  6584.  
  6585. }
  6586.  
  6587. const addTask = (container, attrVal) => {
  6588. if (!container) return;
  6589. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  6590. tasks.push({
  6591. fn: taskFn,
  6592. containerWr: containerWr,
  6593. attrVal
  6594. });
  6595. // pr77 = pr77.then(()=>{
  6596.  
  6597. // })
  6598. // taskFn({
  6599. // containerWr: containerWr,
  6600. // attrVal
  6601. // })
  6602.  
  6603. }
  6604.  
  6605. const addTaskIm = (container, attrVal) => {
  6606. if (!container) return;
  6607. const containerWr = container[wk] || (container[wk] = mWeakRef(container));
  6608. taskFn({
  6609. fn: taskFn,
  6610. containerWr: containerWr,
  6611. attrVal
  6612. });
  6613.  
  6614. }
  6615.  
  6616.  
  6617. const addTask2 = (f) => {
  6618. // pr77 = pr77.then(f).catch(console.warn);
  6619. tasks.push({
  6620. fn: f
  6621. });
  6622.  
  6623. }
  6624.  
  6625. // const mo = new MutationObserver((mutations)=>{
  6626.  
  6627. // });
  6628. // mo.observe(document, {attributeFilter: ['ytx-flushing'], attributes: true, subtree: true, childList: false});
  6629.  
  6630. const containerMapping = new WeakMap();
  6631.  
  6632. // let pr77 = Promise.resolve();
  6633. // let pr88 = Promise.resolve();
  6634. const uA4 = function (t, P) {
  6635. for (let y in t)
  6636. if (t.hasOwnProperty(y) && P[y])
  6637. return y;
  6638. return null
  6639. }
  6640.  
  6641. const evaluteUseMicroTaskQueue = (ax_, containerId, hostIs_, producer, hostElement)=>{
  6642.  
  6643. const ax = ax_;
  6644. const useMicroTaskQueue = ax ? (ax[2] && ax[2]!==ax[0]) : false;
  6645. let useMicroTaskQueue2 = ax && ax[1] && ax[2];
  6646. // const useMicroTaskQueue = false;
  6647. if (ax && ax[2] && ax[2] === ax[0]) { // short ... execute job
  6648. ax[2].cancel();
  6649. useMicroTaskQueue2 = false;
  6650. }
  6651. // console.log(1992,containerId, this.hostElement.is)
  6652.  
  6653. // if (hostElement.nodeType !== 1 || !hostElement.is || hostElement.isConnected === false || !document.body.contains(hostElement)){
  6654. // console.log(12773, hostElement.nodeType !== 1, !hostElement.is, hostElement.isConnected === false, !document.body.contains(hostElement))
  6655. // return false;
  6656.  
  6657. // }
  6658.  
  6659. if (producer.hasFlexibleItems === true) {
  6660. return false;
  6661. }
  6662.  
  6663. if (hostElement.isConnected === false || hostElement.closest('[hidden]')) {
  6664. return false;
  6665. }
  6666.  
  6667. const hostIs = hostIs_;
  6668.  
  6669. if (hostIs === 'ytd-masthead' || hostIs === 'ytd-button-renderer' || hostIs === 'yt-button-shape' || hostIs === 'yt-icon-button' || hostIs === 'ytd-notification-topbar-button-renderer' || containerId === 'buttons' || containerId === 'button' || containerId === 'icon' || hostIs === 'yt-interaction' || containerId === 'interaction') return false;
  6670.  
  6671. if (containerId === 'overlays') useMicroTaskQueue2 = true;
  6672. else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = true;
  6673. // else if (hostIs === 'ytd-rich-grid-media' || hostIs === 'ytd-rich-grid-renderer') useMicroTaskQueue2 = false;
  6674. // else if (containerId === 'menu') useMicroTaskQueue2 = true;
  6675. else if (containerId === 'replies') useMicroTaskQueue2 = true;
  6676. else if (containerId === 'flexible-item-buttons' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = true;
  6677. else if(hostIs === 'ytd-menu-popup-renderer') useMicroTaskQueue2 = false;
  6678. else if ( containerId === 'ghost-comment-section' && hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = true;
  6679. else if (hostIs === 'ytd-continuation-item-renderer') useMicroTaskQueue2 = false;
  6680. else if (hostIs === 'ytd-feed-filter-chip-bar-renderer' || hostIs === 'yt-chip-cloud-renderer' || containerId==='filter' || containerId ==='chips' || containerId==='left-arrow-button' ||containerId==='right-arrow-button') useMicroTaskQueue2 =false;
  6681. // else if (containerId === 'contents' || containerId === 'content' || containerId === 'header') useMicroTaskQueue2 = true;
  6682. // else if( containerId === 'items') useMicroTaskQueue2 = true;
  6683. else if (containerId === 'menu' && hostIs === 'ytd-playlist-panel-video-renderer') useMicroTaskQueue2 = true;
  6684. else if (containerId === 'top-level-buttons-computed' && hostIs === 'ytd-menu-renderer') useMicroTaskQueue2 = false;
  6685. else if (hostIs === 'ytd-comment-view-model') useMicroTaskQueue2 = true;
  6686. // else if (hostIs === 'ytd-rich-item-renderer') useMicroTaskQueue2 = true;
  6687. // else if (hostIs === 'ytd-rich-grid-media') useMicroTaskQueue2 = true;
  6688. else if (hostIs === 'ytd-video-preview') useMicroTaskQueue2 = true;
  6689. // else if (hostIs === 'ytd-game-card-renderer')useMicroTaskQueue2 = true;
  6690.  
  6691.  
  6692. // console.log(19920030+(useMicroTaskQueue2?1:0), containerId, hostIs)
  6693.  
  6694.  
  6695. // console.log(5992,stackAt)
  6696.  
  6697. // console.log(2883, this[`__quu477#${containerId}__`] )
  6698. // if (useMicroTaskQueue) {
  6699. // console.log(stackAt)
  6700. // }
  6701.  
  6702. // if (useMicroTaskQueue) {
  6703. // console.log(1120301)
  6704. // }
  6705.  
  6706. // if(hostElement.closest('ytd-feed-filter-chip-bar-renderer')) useMicroTaskQueue2 = false;
  6707.  
  6708. return useMicroTaskQueue2;
  6709.  
  6710. }
  6711.  
  6712. const frag385 = document.createDocumentFragment();
  6713. frag385.appendChild4202 = frag385.appendChild;
  6714. frag385.removeChild4202 = frag385.removeChild;
  6715. const cm385 = document.createComment('.');
  6716.  
  6717. const doc385 = document.implementation.createHTMLDocument();
  6718. const html385 = doc385.firstElementChild;
  6719. const node385 = html385.appendChild(document.createElement('div'));
  6720.  
  6721. const fixContainerApi = (container) => {
  6722. if (container instanceof Node) {
  6723. const containerDomApi = container.__domApi;
  6724. if (containerDomApi && !containerDomApi.removeChild588 && containerDomApi.removeChild) {
  6725. // console.log(123882, container)
  6726. containerDomApi.removeChild588 = containerDomApi.removeChild;
  6727. containerDomApi.removeChild = function (elem) {
  6728. let r;
  6729. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  6730. s.setAttribute('ytx-flushing', '0');
  6731. }
  6732. try {
  6733. r = this.removeChild588(elem);
  6734. } catch (e) { }
  6735. if (!r) {
  6736. frag385.appendChild4202(elem);
  6737. frag385.removeChild4202(elem);
  6738. r = elem;
  6739. }
  6740. for (const s of elem.querySelectorAll('[ytx-flushing]')) {
  6741. s.removeAttribute('ytx-flushing');
  6742. }
  6743. return r;
  6744. }
  6745. }
  6746. }
  6747. }
  6748.  
  6749. const stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  6750.  
  6751. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  6752. if (typeof sqq === 'function') sqq();
  6753.  
  6754. // trigger in rendererStamperApplyChangeRecord_
  6755.  
  6756. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  6757. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  6758. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  6759. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  6760.  
  6761. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  6762. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  6763.  
  6764.  
  6765. const ax = this[`__quu477#${containerId}__`];
  6766. const hostIs = (this.hostElement || 0).is;
  6767. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  6768.  
  6769. const container = this.getStampContainer7409_(containerId);
  6770. const pChildren = (container instanceof Node && container.isConnected) ? [...container.children] : [];
  6771. renderPathMake(pChildren)
  6772.  
  6773. containerMapping.set(container,
  6774. (this[wk] || (this[wk] = mWeakRef(this)))
  6775. );
  6776.  
  6777. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  6778. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  6779.  
  6780. // let dataList_ = dataList;
  6781. let dataList_ = typeof (dataList || 0) === 'object' ? (dataList.length >= 1 ? dataList.slice() : []) : dataList;
  6782.  
  6783. dataList = null;
  6784. const gid = this[`__$$stampSID$$#${containerId}__`] = genId();
  6785. let fq = 0;
  6786. const f = (() => {
  6787. if(fq) return;
  6788. fq = 1;
  6789. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  6790. this[`__$$stampSFn$$#${containerId}__`] = null;
  6791. const container = this.getStampContainer7409_(containerId);
  6792.  
  6793. this.__lat457__ = this.__lat457__ || new Set();
  6794. if(!container[wk]) container[wk] = mWeakRef(container);
  6795. this.__lat457__.add(container[wk]);
  6796. fixContainerApi(container);
  6797.  
  6798. // let q = this.deferredBindingTasks_;
  6799. // this.deferredBindingTasks_ = [];
  6800. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  6801. let e_;
  6802. try {
  6803. this.stampDomArray7409_(dataList_, containerId, typeOrConfig, false, bEventCb, bStableList);
  6804. } catch (e) { e_ = e }
  6805. this.__qsd477__ = false;
  6806. dataList_ = typeOrConfig = null;
  6807. fixContainerApi(container);
  6808. // this.deferredBindingTasks_ = q;
  6809. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  6810. if (!e_) {
  6811. // container.setAttribute('ytx-flushing', '0');
  6812. }
  6813. // if( container.childElementCount === 0 ){
  6814. // container.setAttribute('ytx-flushing', '0');
  6815. // this.markDirty && this.markDirty();
  6816. // bEventCb && dispatchYtEvent(this.hostElement, "yt-rendererstamper-finished", {
  6817. // container
  6818. // });
  6819. // }
  6820.  
  6821.  
  6822.  
  6823.  
  6824. });
  6825. this[`__$$stampSFn$$#${containerId}__`] = f;
  6826. this[`__$$stampSqq$$#${containerId}__`] = f;
  6827. useMicroTaskQueue2 ? addTask2(f) : f();
  6828. executeTasks();
  6829.  
  6830. Promise.resolve(pChildren).then(pChildren => {
  6831. for (const node of pChildren) {
  6832. if (node.isConnected === false) {
  6833. _removedElements.addNode(node); // rn54006
  6834. }
  6835. }
  6836. pChildren.length = 0;
  6837. pChildren = null;
  6838. });
  6839.  
  6840. // console.log(58801, this.hostElement.parentNode instanceof HTMLElement_);
  6841.  
  6842. return undefined;
  6843.  
  6844. }
  6845.  
  6846. const stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  6847.  
  6848.  
  6849. const sqq = this[`__$$stampSqq$$#${containerId}__`];
  6850. if (typeof sqq === 'function') sqq();
  6851.  
  6852. // trigger in rendererStamperApplyChangeRecord_
  6853.  
  6854. if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  6855. } else {
  6856. return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  6857. }
  6858.  
  6859.  
  6860. // trigger in rendererStamperApplyChangeRecord_
  6861.  
  6862. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  6863. // const useMicroTaskQueue = (stackAt.includes('.rendererStamperApplyChangeRecord_'));
  6864. // const useMicroTaskQueue = stackAt.includes('.<anonymous>') ? true : false;
  6865.  
  6866. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  6867.  
  6868. // const isRenderJob = this[`__quu477#${containerId}__`] || !!this.renderJobsMap_[containerId];
  6869. // const useMicroTaskQueue = isRenderJob && !stackAt.includes('scheduler.js') && 0 ? true : false; // avoid immediate job
  6870. // const useMicroTaskQueue = this[`__quu477#${containerId}__`] ? true : false;
  6871.  
  6872. const ax = this[`__quu477#${containerId}__`];
  6873. const hostIs = (this.hostElement || 0).is;
  6874. const useMicroTaskQueue2 = evaluteUseMicroTaskQueue(ax, containerId, hostIs, this, this.hostElement);
  6875.  
  6876.  
  6877. // const stackAt = `\n\n${new Error().stack}\n\n`.replace(/[\r\n]([^\r\n]*?\.user\.js[^\r\n]*?[\r\n]+)+/g, '\n').replace(/[\r\n]([^\r\n.]+[\r\n]+)+/g, '\n').trim().split(/[\r\n]+/)[0];
  6878. // const useMicroTaskQueue = true;
  6879. const container = this.getStampContainer7409_(containerId);
  6880.  
  6881. containerMapping.set(container,
  6882. (this[wk] || (this[wk] = mWeakRef(this)))
  6883. );
  6884. const bEventCb = this.stampDom[stampKey].events;
  6885. if (bEventCb) container.setAttribute('ytx-flushing', '2');
  6886. else if (!container.hasAttribute('ytx-flushing')) container.setAttribute('ytx-flushing', '1');
  6887.  
  6888. // let indexSplicesObj_ = indexSplicesObj;
  6889. // if (typeof indexSplicesObj === 'object' && indexSplicesObj.indexSplices instanceof Array) {
  6890. // indexSplicesObj_ = {
  6891. // indexSplices: indexSplicesObj.indexSplices.map(slice => {
  6892. // const { index, addedCount, removed, object, type } = slice;
  6893. // this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  6894. // return { index, addedCount, removed, object, type };
  6895. // })
  6896. // };
  6897. // }
  6898.  
  6899.  
  6900. indexSplicesObj.indexSplices.forEach(slice => {
  6901. const object = slice.object;
  6902. if (!object || typeof object !== 'object') return;
  6903. // const { index, addedCount, removed, object, type } = slice;
  6904. this[`__$$stampSpliceObj$$#${containerId}__`] = (object[wk] || (object[wk] = mWeakRef(object)));
  6905. // return { index, addedCount, removed, object, type };
  6906. });
  6907.  
  6908. // let indexSplicesObj_ = indexSplicesObj;
  6909.  
  6910. // console.log(128783, indexSplicesObj)
  6911.  
  6912. // let indexSplicesObj_ = indexSplicesObj.map(slice => {
  6913. // const { index, addedCount, removed, object, type } = slice;
  6914. // return { index, addedCount, removed, object, type };
  6915. // });
  6916.  
  6917. indexSplicesObj = null;
  6918.  
  6919. if (!this[`__$$stampSID$$#${containerId}__`]) this[`__$$stampSID$$#${containerId}__`] = genId();
  6920. const gid = this[`__$$stampSID$$#${containerId}__`];
  6921. let fq = 0;
  6922. const f = (() => {
  6923. if(fq) return;
  6924. fq = 1;
  6925. if (gid !== this[`__$$stampSID$$#${containerId}__`]) { return; }
  6926. if (this[`__$$stampSFn$$#${containerId}__`]) this[`__$$stampSFn$$#${containerId}__`]();
  6927. const container = this.getStampContainer7409_(containerId);
  6928. if(!container) return;
  6929.  
  6930. // console.log(388 , kRef(this[`__$$stampSpliceObj$$#${containerId}__`]))
  6931.  
  6932. const object = kRef(this[`__$$stampSpliceObj$$#${containerId}__`]);
  6933. // const elementKeys = new Set(Array.prototype.map.call((container.__domApi || container).children, e=>e[s52]));
  6934. const mapping = this.stampDom[stampKey].mapping;
  6935.  
  6936. const map = new Map();
  6937.  
  6938. const currentObjKeys = object.map(objEntry => {
  6939. const mappingKey = uA4(mapping, objEntry);
  6940. if(!mappingKey) return null;
  6941. const data = objEntry[mappingKey];
  6942. if (!data[s52]) data[s52] = genId();
  6943. map.set(data[s52], objEntry);
  6944. // return ({
  6945. // objEntry,
  6946. // data: data,
  6947. // mappingKey: mappingKey,
  6948. // key: data[s52],
  6949. // exist: elementKeys.has(data[s52])
  6950. // });
  6951. return data[s52]
  6952.  
  6953. });
  6954.  
  6955. const oldDomKeys = Array.prototype.map.call((container.__domApi || container).children, node=>node[s52]);
  6956.  
  6957. // console.log(currentObjKeys, oldDomKeys, diffSplices(oldDomKeys, currentObjKeys));
  6958.  
  6959. const splices = diffSplices(oldDomKeys, currentObjKeys);
  6960.  
  6961. // let myObject = object;
  6962. let indexSplicesObj_ = {
  6963. indexSplices: splices.map(splice => {
  6964. const index = splice[0];
  6965. const removedLen = splice[1];
  6966. const added = splice[2];
  6967. const addedCount = added.length;
  6968. const object = {};
  6969. object.length = index + addedCount;
  6970. for (let i = 0; i < addedCount; i++) {
  6971. object[index + i] = map.get(added[i]);
  6972. }
  6973. const removed = {};
  6974. removed.length = removedLen;
  6975.  
  6976. return { index, removed, object, addedCount }
  6977. })
  6978. };
  6979. map.clear();
  6980.  
  6981.  
  6982. this.__lat457__ = this.__lat457__ || new Set();
  6983. if(!container[wk]) container[wk] = mWeakRef(container);
  6984. this.__lat457__.add(container[wk]);
  6985. fixContainerApi(container);
  6986.  
  6987. // console.log(3882, indexSplicesObj_)
  6988. // let q = this.deferredBindingTasks_;
  6989. // this.deferredBindingTasks_ = [];
  6990. this.__qsd477__ = useMicroTaskQueue2 ? 2 : 1;
  6991. let e_;
  6992. try {
  6993. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj_);
  6994. } catch (e) { e_ = e; }
  6995. this.__qsd477__ = false;
  6996. indexSplicesObj_ = null;
  6997. stampKey = indexSplicesObj_ = null;
  6998. fixContainerApi(container);
  6999. // this.deferredBindingTasks_ = q;
  7000. if(e_ && e_.message !== 'e5bd8d2f') throw e_;
  7001. if (!e_) {
  7002. // container.setAttribute('ytx-flushing', '0');
  7003. }
  7004.  
  7005.  
  7006. });
  7007. this[`__$$stampSqq$$#${containerId}__`] = f;
  7008. useMicroTaskQueue2 ? addTask2(f) : f();
  7009. executeTasks();
  7010.  
  7011. // console.log(58802, this.hostElement.parentNode instanceof HTMLElement_);
  7012.  
  7013. return undefined;
  7014.  
  7015. }
  7016.  
  7017.  
  7018. const stampDomArrayWB_ = function (objWr, containerId, xxx_, renderJob0, dt0a) {
  7019. const dt0 = dt0a[0];
  7020. const dt1 = Date.now();
  7021. const obj = kRef(objWr);
  7022. if (!obj) return;
  7023. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  7024. if (xxx !== xxx_) return;
  7025. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  7026. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  7027. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  7028. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  7029. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  7030. const renderJob1 = obj.renderJobsMap_[containerId]
  7031. // console.log(3188, dt0, dt1, renderJob0, renderJob1)
  7032. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7033. let e_, r;
  7034. try {
  7035. r = obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  7036. } catch (e) {
  7037. e_ = e;
  7038. }
  7039. obj[`__quu477#${containerId}__`] = false;
  7040. if (e_) throw e_;
  7041. return r;
  7042. };
  7043.  
  7044.  
  7045. stampDomArray_.bind = function (obj, ...args) {
  7046. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  7047. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7048. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  7049. const typeOrConfig_ = typeof (typeOrConfig || 0) === 'object' ? (typeOrConfig[wk] || (typeOrConfig[wk] = mWeakRef(typeOrConfig))) : typeOrConfig;
  7050. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig_;
  7051. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  7052. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  7053. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  7054. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  7055.  
  7056.  
  7057. const renderJob = obj.renderJobsMap_[containerId];
  7058.  
  7059. const dt0a = [Date.now()];
  7060. queueMicrotask_(() => { dt0a[0] = 0 });
  7061. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx, renderJob, dt0a);
  7062. };
  7063.  
  7064. const stampDomArraySplicesWB_ = function (objWr, stampKey, containerId, indexSplicesObj, renderJob0, dt0a) {
  7065. const dt0 = dt0a[0];
  7066. const dt1 = Date.now();
  7067. const obj = kRef(objWr);
  7068. if (!obj) return;
  7069. const renderJob1 = obj.renderJobsMap_[containerId];
  7070. obj[`__quu477#${containerId}__`] = [renderJob0, (dt1 - dt0 >= 1), renderJob1];
  7071. let e_, r;
  7072. try {
  7073. r = obj.stampDomArraySplices_( stampKey, containerId, indexSplicesObj);
  7074. } catch (e) {
  7075. e_ = e;
  7076. }
  7077. obj[`__quu477#${containerId}__`] = false;
  7078. if (e_) throw e_;
  7079. return r;
  7080. };
  7081.  
  7082.  
  7083. stampDomArraySplices_.bind = function (obj, ...args) {
  7084. let [stampKey, containerId, indexSplicesObj] = args;
  7085. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  7086.  
  7087. const renderJob = obj.renderJobsMap_[containerId];
  7088.  
  7089. const dt0a = [Date.now()];
  7090. queueMicrotask_(() => { dt0a[0] = 0 });
  7091. return stampDomArraySplicesWB_.bind(null, obj[wk], stampKey, containerId, indexSplicesObj, renderJob, dt0a);
  7092. };
  7093.  
  7094. const flushRenderStamperComponentBindings7419_ = function () {
  7095. const tasks = this.deferredBindingTasks_;
  7096. if (!(tasks || 0).length) return;
  7097. const hostElement = this.hostElement;
  7098. if ((hostElement instanceof Node) && hostElement.nodeType === 1) {
  7099. if (hostElement.isConnected === true) {
  7100. this.flushRenderStamperComponentBindings7409_();
  7101. }
  7102. } else if (hostElement) {
  7103. console.log('flushRenderStamperComponentBindings7419_ 002')
  7104. this.flushRenderStamperComponentBindings7409_();
  7105. } else {
  7106. console.log('flushRenderStamperComponentBindings7419_ 003')
  7107. tasks.length = 0;
  7108. }
  7109. }
  7110.  
  7111. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ , flushRenderStamperComponentBindings7419_};
  7112.  
  7113. }
  7114.  
  7115. const setupDiscreteTasks = (h, rb) => {
  7116.  
  7117. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  7118. const f = h.onYtRendererstamperFinished;
  7119. const g = ump3.get(f) || function () {
  7120. if (this.updateChildVisibilityProperties && !this.markDirty) {
  7121. return f.apply(this, arguments);
  7122. }
  7123. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7124. }
  7125. ump3.set(f, g);
  7126. g.km34 = 1;
  7127. h.onYtRendererstamperFinished = g;
  7128.  
  7129. }
  7130.  
  7131. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  7132. const f = h.onYtUpdateDescriptionAction;
  7133. const g = ump3.get(f) || function (a) {
  7134. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7135. }
  7136. ump3.set(f, g);
  7137. g.km34 = 1;
  7138. h.onYtUpdateDescriptionAction = g;
  7139.  
  7140. }
  7141.  
  7142. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  7143. const f = h.handleUpdateDescriptionAction;
  7144. const g = ump3.get(f) || function (a) {
  7145. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7146. }
  7147. ump3.set(f, g);
  7148. g.km34 = 1;
  7149. h.handleUpdateDescriptionAction = g;
  7150.  
  7151. }
  7152.  
  7153. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  7154. const f = h.handleUpdateLiveChatPollAction;
  7155. const g = ump3.get(f) || function (a) {
  7156. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7157. }
  7158. ump3.set(f, g);
  7159. g.km34 = 1;
  7160. h.handleUpdateLiveChatPollAction = g;
  7161.  
  7162. }
  7163.  
  7164. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  7165. const f = h.onTextChanged;
  7166. const g = ump3.get(f) || function () {
  7167. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7168. }
  7169. ump3.set(f, g);
  7170. g.km34 = 1;
  7171. h.onTextChanged = g;
  7172.  
  7173. }
  7174.  
  7175. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  7176. const f = h.onVideoDataChange;
  7177. const g = ump3.get(f) || function (a) {
  7178. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7179. }
  7180. ump3.set(f, g);
  7181. g.km34 = 1;
  7182. h.onVideoDataChange = g;
  7183.  
  7184. }
  7185.  
  7186. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  7187. const f = h.onVideoDataChange_;
  7188. const g = ump3.get(f) || function () {
  7189. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7190. }
  7191. ump3.set(f, g);
  7192. g.km34 = 1;
  7193. h.onVideoDataChange_ = g;
  7194.  
  7195. }
  7196.  
  7197. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  7198.  
  7199. const f = h.addTooltips_;
  7200. const g = ump3.get(f) || function () {
  7201. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7202. }
  7203. ump3.set(f, g);
  7204. g.km34 = 1;
  7205. h.addTooltips_ = g;
  7206.  
  7207. }
  7208.  
  7209. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  7210.  
  7211. const f = h.updateRenderedElements;
  7212. const g = ump3.get(f) || function () {
  7213. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7214. }
  7215. ump3.set(f, g);
  7216. g.km34 = 1;
  7217. h.updateRenderedElements = g;
  7218.  
  7219. }
  7220.  
  7221. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  7222. const f = h.loadPage_;
  7223. const g = ump3.get(f) || function (a) {
  7224. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7225. }
  7226. ump3.set(f, g);
  7227. g.km34 = 1;
  7228. h.loadPage_ = g;
  7229.  
  7230. }
  7231. // updatePageData_ : possible conflict with Omit ShadyDOM
  7232. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  7233. const f = h.updatePageData_;
  7234. const g = ump3.get(f) || function (a) {
  7235. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7236. }
  7237. ump3.set(f, g);
  7238. g.km34 = 1;
  7239. h.updatePageData_ = g;
  7240.  
  7241. }
  7242.  
  7243.  
  7244. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  7245.  
  7246. const f = h.onFocus_;
  7247. const g = ump3.get(f) || function () {
  7248. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7249. }
  7250. ump3.set(f, g);
  7251. g.km34 = 1;
  7252. h.onFocus_ = g;
  7253.  
  7254. }
  7255.  
  7256. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  7257.  
  7258. const f = h.onBlur_;
  7259. const g = ump3.get(f) || function () {
  7260. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7261. }
  7262. ump3.set(f, g);
  7263. g.km34 = 1;
  7264. h.onBlur_ = g;
  7265.  
  7266. }
  7267.  
  7268.  
  7269. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  7270.  
  7271. const f = h.buttonClassChanged_;
  7272. const g = ump3.get(f) || function (a, b) {
  7273. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7274. }
  7275. ump3.set(f, g);
  7276. g.km34 = 1;
  7277. h.buttonClassChanged_ = g;
  7278.  
  7279. }
  7280.  
  7281. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  7282.  
  7283. const f = h.buttonIconChanged_;
  7284. const g = ump3.get(f) || function (a) {
  7285. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7286. }
  7287. ump3.set(f, g);
  7288. g.km34 = 1;
  7289. h.buttonIconChanged_ = g;
  7290.  
  7291. }
  7292.  
  7293. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  7294.  
  7295. const f = h.dataChangedInBehavior_;
  7296. const g = ump3.get(f) || function () {
  7297. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7298. }
  7299. ump3.set(f, g);
  7300. g.km34 = 1;
  7301. h.dataChangedInBehavior_ = g;
  7302.  
  7303. }
  7304.  
  7305. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  7306.  
  7307. const f = h.continuationsChanged_;
  7308. const g = ump3.get(f) || function () {
  7309. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7310. }
  7311. ump3.set(f, g);
  7312. g.km34 = 1;
  7313. h.continuationsChanged_ = g;
  7314.  
  7315. }
  7316.  
  7317.  
  7318. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  7319.  
  7320. const f = h.forceChatPoll_;
  7321. const g = ump3.get(f) || function (a) {
  7322. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7323. }
  7324. ump3.set(f, g);
  7325. g.km34 = 1;
  7326. h.forceChatPoll_ = g;
  7327.  
  7328. }
  7329.  
  7330. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  7331.  
  7332. const f = h.onEndpointClick_;
  7333. const g = ump3.get(f) || function (a) {
  7334. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7335. }
  7336. ump3.set(f, g);
  7337. g.km34 = 1;
  7338. h.onEndpointClick_ = g;
  7339.  
  7340. }
  7341.  
  7342. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  7343.  
  7344. const f = h.onEndpointTap_;
  7345. const g = ump3.get(f) || function (a) {
  7346. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7347. }
  7348. ump3.set(f, g);
  7349. g.km34 = 1;
  7350. h.onEndpointTap_ = g;
  7351.  
  7352. }
  7353.  
  7354. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  7355.  
  7356. const f = h.handleClick_;
  7357. const g = ump3.get(f) || function (a, b) {
  7358. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7359. }
  7360. ump3.set(f, g);
  7361. g.km34 = 1;
  7362. h.handleClick_ = g;
  7363.  
  7364. }
  7365.  
  7366. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  7367.  
  7368. const f = h.onReadyStateChange_;
  7369. const g = ump3.get(f) || function () {
  7370. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7371. }
  7372. ump3.set(f, g);
  7373. g.km34 = 1;
  7374. h.onReadyStateChange_ = g;
  7375.  
  7376. }
  7377.  
  7378. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  7379.  
  7380. const f = h.onReadyStateChangeEntryPoint_;
  7381. const g = ump3.get(f) || function () {
  7382. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7383. }
  7384. ump3.set(f, g);
  7385. g.km34 = 1;
  7386. h.onReadyStateChangeEntryPoint_ = g;
  7387.  
  7388. }
  7389.  
  7390. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  7391.  
  7392. const f = h.readyStateChangeHandler_;
  7393. const g = ump3.get(f) || function (a) {
  7394. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7395. }
  7396. ump3.set(f, g);
  7397. g.km34 = 1;
  7398. h.readyStateChangeHandler_ = g;
  7399.  
  7400. }
  7401.  
  7402. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  7403.  
  7404. const f = h.xmlHttpHandler_;
  7405. const g = ump3.get(f) || function (a) {
  7406. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7407. }
  7408. ump3.set(f, g);
  7409. g.km34 = 1;
  7410. h.xmlHttpHandler_ = g;
  7411.  
  7412. }
  7413.  
  7414. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  7415.  
  7416. const f = h.executeCallbacks_; // overloaded
  7417. const g = ump3.get(f) || function (a) {
  7418. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7419. }
  7420. ump3.set(f, g);
  7421. g.km34 = 1;
  7422. h.executeCallbacks_ = g;
  7423.  
  7424. }
  7425.  
  7426. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  7427.  
  7428. const f = h.handleInvalidationData_;
  7429. const g = ump3.get(f) || function (a, b) {
  7430. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7431. }
  7432. ump3.set(f, g);
  7433. g.km34 = 1;
  7434. h.handleInvalidationData_ = g;
  7435.  
  7436. }
  7437.  
  7438. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  7439.  
  7440. const f = h.onInput_;
  7441. const g = ump3.get(f) || function () {
  7442. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7443. }
  7444. ump3.set(f, g);
  7445. g.km34 = 1;
  7446. h.onInput_ = g;
  7447.  
  7448. }
  7449. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  7450.  
  7451. const f = h.trigger_;
  7452. const g = ump3.get(f) || function (a) {
  7453. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7454. }
  7455. ump3.set(f, g);
  7456. g.km34 = 1;
  7457. h.trigger_ = g;
  7458.  
  7459. }
  7460.  
  7461. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  7462.  
  7463. const f = h.requestData_;
  7464. const g = ump3.get(f) || function (a) {
  7465. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7466. }
  7467. ump3.set(f, g);
  7468. g.km34 = 1;
  7469. h.requestData_ = g;
  7470.  
  7471. }
  7472.  
  7473. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  7474.  
  7475. const f = h.onLoadReloadContinuation_;
  7476. const g = ump3.get(f) || function (a, b) {
  7477. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7478. }
  7479. ump3.set(f, g);
  7480. g.km34 = 1;
  7481. h.onLoadReloadContinuation_ = g;
  7482.  
  7483. }
  7484.  
  7485. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  7486.  
  7487. const f = h.onLoadIncrementalContinuation_;
  7488. const g = ump3.get(f) || function (a, b) {
  7489. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7490. }
  7491. ump3.set(f, g);
  7492. g.km34 = 1;
  7493. h.onLoadIncrementalContinuation_ = g;
  7494.  
  7495. }
  7496.  
  7497. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  7498.  
  7499. const f = h.onLoadSeekContinuation_;
  7500. const g = ump3.get(f) || function (a, b) {
  7501. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7502. }
  7503. ump3.set(f, g);
  7504. g.km34 = 1;
  7505. h.onLoadSeekContinuation_ = g;
  7506.  
  7507. }
  7508. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  7509.  
  7510. const f = h.onLoadReplayContinuation_;
  7511. const g = ump3.get(f) || function (a, b) {
  7512. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7513. }
  7514. ump3.set(f, g);
  7515. g.km34 = 1;
  7516. h.onLoadReplayContinuation_ = g;
  7517.  
  7518. }
  7519. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  7520.  
  7521. const f = h.onNavigate_;
  7522. const g = ump3.get(f) || function (a) {
  7523. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7524. }
  7525. ump3.set(f, g);
  7526. g.km34 = 1;
  7527. h.onNavigate_ = g;
  7528.  
  7529. }
  7530.  
  7531. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  7532.  
  7533. const f = h.ytRendererBehaviorDataObserver_;
  7534. const g = ump3.get(f) || function () {
  7535. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7536. }
  7537. ump3.set(f, g);
  7538. g.km34 = 1;
  7539. h.ytRendererBehaviorDataObserver_ = g;
  7540.  
  7541. }
  7542.  
  7543. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  7544.  
  7545. const f = h.ytRendererBehaviorTargetIdObserver_;
  7546. const g = ump3.get(f) || function () {
  7547. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7548. }
  7549. ump3.set(f, g);
  7550. g.km34 = 1;
  7551. h.ytRendererBehaviorTargetIdObserver_ = g;
  7552.  
  7553. }
  7554.  
  7555. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  7556.  
  7557. const f = h.unregisterRenderer_;
  7558. const g = ump3.get(f) || function (a) {
  7559. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7560. }
  7561. ump3.set(f, g);
  7562. g.km34 = 1;
  7563. h.unregisterRenderer_ = g;
  7564.  
  7565. }
  7566.  
  7567. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  7568.  
  7569. const f = h.textChanged_;
  7570. const g = ump3.get(f) || function (a) {
  7571. if (void 0 !== this.isAttached) {
  7572. const hostElement = this.hostElement;
  7573. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  7574. return;
  7575. }
  7576. }
  7577. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7578. }
  7579. ump3.set(f, g);
  7580. g.km34 = 1;
  7581. h.textChanged_ = g;
  7582.  
  7583. }
  7584.  
  7585.  
  7586.  
  7587. /**
  7588. *
  7589. * Neglect following
  7590. *
  7591. * h.onYtAction_
  7592. * h.startLoadingWatch [ buggy for yt-player-updated ]
  7593. * h.deferRenderStamperBinding_
  7594. *
  7595. * h.stampDomArray_
  7596. * h.stampDomArraySplices_
  7597. *
  7598. */
  7599.  
  7600.  
  7601. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  7602. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  7603. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  7604. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  7605. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  7606. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  7607.  
  7608. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  7609.  
  7610. const f = h.searchChanged_;
  7611. const g = ump3.get(f) || function () {
  7612. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7613. }
  7614. ump3.set(f, g);
  7615. g.km34 = 1;
  7616. h.searchChanged_ = g;
  7617.  
  7618. }
  7619.  
  7620. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  7621.  
  7622. const f = h.skinToneChanged_;
  7623. const g = ump3.get(f) || function (a) {
  7624. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7625. }
  7626. ump3.set(f, g);
  7627. g.km34 = 1;
  7628. h.skinToneChanged_ = g;
  7629.  
  7630. }
  7631.  
  7632. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  7633.  
  7634. const f = h.onEmojiHover_;
  7635. const g = ump3.get(f) || function (a) {
  7636. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7637. }
  7638. ump3.set(f, g);
  7639. g.km34 = 1;
  7640. h.onEmojiHover_ = g;
  7641.  
  7642. }
  7643.  
  7644. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  7645.  
  7646. const f = h.onSelectCategory_;
  7647. const g = ump3.get(f) || function (a) {
  7648. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7649. }
  7650. ump3.set(f, g);
  7651. g.km34 = 1;
  7652. h.onSelectCategory_ = g;
  7653.  
  7654. }
  7655.  
  7656. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  7657.  
  7658. const f = h.onShowEmojiVariantSelector;
  7659. const g = ump3.get(f) || function (a) {
  7660. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7661. }
  7662. ump3.set(f, g);
  7663. g.km34 = 1;
  7664. h.onShowEmojiVariantSelector = g;
  7665.  
  7666. }
  7667.  
  7668. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  7669.  
  7670. const f = h.updateCategoriesAndPlaceholder_;
  7671. const g = ump3.get(f) || function () {
  7672. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7673. }
  7674. ump3.set(f, g);
  7675. g.km34 = 1;
  7676. h.updateCategoriesAndPlaceholder_ = g;
  7677.  
  7678. }
  7679.  
  7680. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  7681.  
  7682. const f = h.watchPageActiveChanged_;
  7683. const g = ump3.get(f) || function () {
  7684. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7685. }
  7686. ump3.set(f, g);
  7687. g.km34 = 1;
  7688. h.watchPageActiveChanged_ = g;
  7689.  
  7690. }
  7691.  
  7692. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  7693.  
  7694. const f = h.activate_;
  7695. const g = ump3.get(f) || function () {
  7696. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7697. }
  7698. ump3.set(f, g);
  7699. g.km34 = 1;
  7700. h.activate_ = g;
  7701.  
  7702. }
  7703. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  7704.  
  7705. const f = h.onYtPlaylistDataUpdated_;
  7706. const g = ump3.get(f) || function () {
  7707. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7708. }
  7709. ump3.set(f, g);
  7710. g.km34 = 1;
  7711. h.onYtPlaylistDataUpdated_ = g;
  7712.  
  7713. }
  7714.  
  7715.  
  7716.  
  7717. /**
  7718. *
  7719. * Neglect following
  7720. *
  7721. * h.rendererStamperObserver_
  7722. * h.rendererStamperApplyChangeRecord_
  7723. * h.flushRenderStamperComponentBindings_
  7724. * h.forwardRendererStamperChanges_
  7725. *
  7726. */
  7727.  
  7728. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  7729.  
  7730. const f = h.tryRenderChunk_;
  7731. const g = ump3.get(f) || function () {
  7732. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7733. }
  7734. ump3.set(f, g);
  7735. g.km34 = 1;
  7736. h.tryRenderChunk_ = g;
  7737.  
  7738. }
  7739.  
  7740.  
  7741. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  7742.  
  7743. const f = h.renderChunk_;
  7744. const g = ump3.get(f) || function () {
  7745. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7746. }
  7747. ump3.set(f, g);
  7748. g.km34 = 1;
  7749. h.renderChunk_ = g;
  7750.  
  7751. }
  7752.  
  7753. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  7754.  
  7755. const f = h.deepLazyListObserver_;
  7756. const g = ump3.get(f) || function () {
  7757. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7758. }
  7759. ump3.set(f, g);
  7760. g.km34 = 1;
  7761. h.deepLazyListObserver_ = g;
  7762.  
  7763. }
  7764.  
  7765. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  7766.  
  7767. const f = h.onItemsUpdated_;
  7768. const g = ump3.get(f) || function () {
  7769. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7770. }
  7771. ump3.set(f, g);
  7772. g.km34 = 1;
  7773. h.onItemsUpdated_ = g;
  7774.  
  7775. }
  7776.  
  7777. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  7778.  
  7779. const f = h.requestRenderChunk_;
  7780. const g = ump3.get(f) || function () {
  7781. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  7782. }
  7783. ump3.set(f, g);
  7784. g.km34 = 1;
  7785. h.requestRenderChunk_ = g;
  7786.  
  7787. }
  7788.  
  7789. /**
  7790. *
  7791. * Neglect following
  7792. *
  7793. * h.dataChanged_ [ buggy for page swtiching ]
  7794. *
  7795. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  7796. *
  7797. * h.cancelPendingTasks_
  7798. * h.fillRange_
  7799. * h.addTextNodes_
  7800. * h.updateText_
  7801. * h.stampTypeChanged_
  7802. *
  7803. */
  7804.  
  7805.  
  7806. }
  7807.  
  7808. const keyStConnectedCallback = Symbol(); // avoid copying the value
  7809.  
  7810. const dmf = new WeakMap();
  7811.  
  7812.  
  7813. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  7814.  
  7815. try {
  7816.  
  7817. const q = document.createElement('template');
  7818. q.innerHTML = '<ytz-null361></ytz-null361>';
  7819. nativeHTMLElement = q.content.firstChild.constructor
  7820.  
  7821. } catch (e) { }
  7822.  
  7823. if (!nativeHTMLElement.prototype.connectedCallback) {
  7824. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  7825. nativeHTMLElement.prototype.connectedCallback = function () {
  7826. let r;
  7827. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  7828. return r;
  7829. }
  7830. }
  7831. const pvr = Symbol()
  7832.  
  7833. let stampDomArrayFnStore = null;
  7834. const setupMap = new WeakSet();
  7835. const setupYtComponent = (cnt) => {
  7836. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  7837. if (!cProto || setupMap.has(cProto)) return;
  7838. setupMap.add(cProto);
  7839. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  7840. cProto[pvr] |= 1;
  7841.  
  7842.  
  7843.  
  7844. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  7845. const b = cProto.stampDomArray_.length === 6
  7846. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  7847. && cProto.createComponent_ && cProto.createComponent_.length === 3
  7848. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  7849. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  7850. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  7851. if (!b) {
  7852. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  7853. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  7854. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsC_();
  7855. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_, flushRenderStamperComponentBindings7419_} = stampDomArrayFnStore;
  7856.  
  7857. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  7858. cProto.createComponent7409_ = cProto.createComponent_;
  7859. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  7860. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  7861. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  7862. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  7863.  
  7864. cProto.getStampContainer_ = getStampContainer_;
  7865. cProto.createComponent_ = createComponent_;
  7866. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  7867. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  7868. cProto.stampDomArray_ = stampDomArray_;
  7869. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  7870. cProto.flushRenderStamperComponentBindings7419_ = flushRenderStamperComponentBindings7419_;
  7871.  
  7872. }
  7873. }
  7874.  
  7875.  
  7876.  
  7877.  
  7878. // if(false && cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  7879. // cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  7880.  
  7881. // if(cProto._runEffectsForTemplate6344.length === 4){
  7882.  
  7883. // cProto._runEffectsForTemplate = function (c, d, e, g) {
  7884. // const cnt = this;
  7885. // const { propertyEffects, nodeList, firstChild } = c;
  7886. // cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  7887.  
  7888. // }
  7889.  
  7890. // }
  7891.  
  7892. // }
  7893.  
  7894. }
  7895. };
  7896.  
  7897. (FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  7898. get() {
  7899. const f = this[keyStConnectedCallback];
  7900. if (this.is) {
  7901. setupYtComponent(this);
  7902. }
  7903. return f;
  7904. },
  7905. set(nv) {
  7906. let gv = nv;
  7907. this[keyStConnectedCallback] = gv; // proto or object
  7908. return true;
  7909. },
  7910. enumerable: false,
  7911. configurable: true
  7912.  
  7913. });
  7914.  
  7915. const pLoad = new Promise(resolve => {
  7916. if (document.readyState !== 'loading') {
  7917. resolve();
  7918. } else {
  7919. window.addEventListener("DOMContentLoaded", resolve, false);
  7920. }
  7921. });
  7922.  
  7923. if (FIX_ACTIONS_TOOLTIPS) {
  7924. pLoad.then(() => {
  7925. addNewCSS("#actions .tp-yt-paper-tooltip{white-space:nowrap}");
  7926. });
  7927. }
  7928.  
  7929. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  7930. window.requestIdleCallback471 = window.requestIdleCallback;
  7931. window.requestIdleCallback = function (f, ...args) {
  7932. return (this || window).requestIdleCallback471(async function () {
  7933. await pLoad.then();
  7934. // await new Promise(nextBrowserTick_);
  7935. f.call(this, ...arguments)
  7936. }, ...args);
  7937. }
  7938. }
  7939.  
  7940. pLoad.then(() => {
  7941.  
  7942. let nonce = document.querySelector('style[nonce]');
  7943. nonce = nonce ? nonce.getAttribute('nonce') : null;
  7944. const st = document.createElement('style');
  7945. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  7946. st.textContent = "none-element-k47{order:0}";
  7947. st.addEventListener('load', () => {
  7948. pf31.resolve();
  7949. p59 = 1;
  7950. }, false);
  7951. (document.body || document.head || document.documentElement).appendChild(st);
  7952.  
  7953. });
  7954.  
  7955. const prepareLogs = [];
  7956.  
  7957. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  7958.  
  7959. let winError00 = window.onerror;
  7960.  
  7961. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  7962.  
  7963. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  7964.  
  7965. ; fix_error_many_stack_state === 1 && (() => {
  7966.  
  7967.  
  7968. let p1 = winError00;
  7969.  
  7970. let stackNeedleDetails = null;
  7971.  
  7972. Object.defineProperty(Object.prototype, 'matchAll', {
  7973. get() {
  7974. stackNeedleDetails = this;
  7975. return true;
  7976. },
  7977. enumerable: true,
  7978. configurable: true
  7979. });
  7980.  
  7981. try {
  7982. JSON.parse("{}");
  7983. } catch (e) {
  7984. console.warn(e)
  7985. fix_error_many_stack_state = 0;
  7986. }
  7987.  
  7988. delete Object.prototype['matchAll'];
  7989.  
  7990. let p2 = window.onerror;
  7991.  
  7992. window.onerror = p1;
  7993.  
  7994. if (fix_error_many_stack_state === 0) return;
  7995.  
  7996. if (stackNeedleDetails) {
  7997. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7998. stackNeedleDetails.matchAll = true;
  7999. }
  8000.  
  8001. if (p1 === p2) return (fix_error_many_stack_state = 0);
  8002.  
  8003. // p1!==p2
  8004. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  8005.  
  8006. })();
  8007.  
  8008. ; fix_error_many_stack_state === 2 && (() => {
  8009.  
  8010.  
  8011. let p1 = winError00;
  8012.  
  8013. let objectPrune = null;
  8014. let stackNeedleDetails = null;
  8015.  
  8016. Object.defineProperty(Function.prototype, 'findOwner', {
  8017. get() {
  8018. objectPrune = this;
  8019. return this._findOwner;
  8020. },
  8021. set(nv) {
  8022. this._findOwner = nv;
  8023. return true;
  8024. },
  8025. enumerable: true,
  8026. configurable: true
  8027. });
  8028.  
  8029. Object.defineProperty(Object.prototype, 'matchAll', {
  8030. get() {
  8031. stackNeedleDetails = this;
  8032. return true;
  8033. },
  8034. enumerable: true,
  8035. configurable: true
  8036. });
  8037.  
  8038. try {
  8039. JSON.parse("{}");
  8040. } catch (e) {
  8041. console.warn(e)
  8042. fix_error_many_stack_state = 0;
  8043. }
  8044.  
  8045. delete Function.prototype['findOwner'];
  8046. delete Object.prototype['matchAll'];
  8047.  
  8048. let p2 = window.onerror;
  8049.  
  8050. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  8051.  
  8052. if (fix_error_many_stack_state == 0) return;
  8053.  
  8054. // the following will only execute when Brave's scriptlets.js is executed.
  8055.  
  8056. prepareLogs.push("fix_error_many_stack_state NB")
  8057.  
  8058. if (stackNeedleDetails) {
  8059. stackNeedleDetails.pattern = null;
  8060. stackNeedleDetails.re = null;
  8061. stackNeedleDetails.expect = null;
  8062. stackNeedleDetails.matchAll = true;
  8063. }
  8064.  
  8065. if (objectPrune) {
  8066. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  8067. delete objectPrune._findOwner;
  8068. }
  8069.  
  8070. fix_error_many_stack_state = 3;
  8071. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  8072. JSON.parse.objectPrune = objectPrune;
  8073.  
  8074. })();
  8075.  
  8076. ; fix_error_many_stack_state === 3 && (() => {
  8077.  
  8078.  
  8079. let p1 = winError00;
  8080.  
  8081. try {
  8082. JSON.parse("{}");
  8083. } catch (e) {
  8084. console.warn(e)
  8085. fix_error_many_stack_state = 0;
  8086. }
  8087.  
  8088. let p2 = window.onerror;
  8089.  
  8090. if (p1 === p2) return;
  8091.  
  8092. window.onerror = p1;
  8093.  
  8094. if (fix_error_many_stack_state === 0) return;
  8095.  
  8096. fix_error_many_stack_state = 4; // p1 != p2
  8097.  
  8098.  
  8099. })();
  8100.  
  8101. fix_error_many_stack_state === 4 && (() => {
  8102.  
  8103. // the following will only execute when Brave's scriptlets.js is executed.
  8104.  
  8105. prepareLogs.push("fix_error_many_stack_state AB")
  8106.  
  8107. JSON.parseProxy = JSON.parse;
  8108.  
  8109. JSON.parse = ((parse) => {
  8110.  
  8111. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  8112. return function (text, reviver) {
  8113. const onerror = window.onerror;
  8114. window.onerror = null;
  8115. let r;
  8116. try {
  8117. r = parse(...arguments);
  8118. } catch (e) {
  8119. r = e;
  8120. }
  8121. window.onerror = onerror;
  8122. if (r instanceof Error) {
  8123. throw r;
  8124. }
  8125. return r;
  8126. }
  8127.  
  8128. })(JSON.parse);
  8129.  
  8130.  
  8131. })();
  8132.  
  8133.  
  8134. // << if FIX_yt_player >>
  8135.  
  8136. // credit to @nopeless (https://greasyfork.org/scripts/471489-youtube-player-perf/)
  8137. const PERF_471489_ = true;
  8138. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  8139. // This script uses a much gentle way to tamer the JS engine instead.
  8140.  
  8141. // << end >>
  8142.  
  8143. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  8144.  
  8145.  
  8146.  
  8147. const nilFn = () => { };
  8148.  
  8149. let isMainWindow = false;
  8150. try {
  8151. isMainWindow = window.document === window.top.document
  8152. } catch (e) { }
  8153.  
  8154. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  8155. let headLinkCollection = null;
  8156.  
  8157.  
  8158. // const assertor = (f) => f() || console.assert(false, `${f}`);
  8159.  
  8160. const fnIntegrity_oldv1 = (f, d) => {
  8161. if (!f || typeof f !== 'function') {
  8162. console.warn('f is not a function', f);
  8163. return;
  8164. }
  8165. let p = `${f}`, s = 0, j = -1, w = 0;
  8166. for (let i = 0, l = p.length; i < l; i++) {
  8167. const t = p[i];
  8168. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8169. if (j < i - 1) w++;
  8170. j = i;
  8171. } else {
  8172. s++;
  8173. }
  8174. }
  8175. let itz = `${f.length}.${s}.${w}`;
  8176. if (!d) {
  8177. return itz;
  8178. } else {
  8179. return itz === d;
  8180. }
  8181. };
  8182.  
  8183. const fnIntegrity = (f, d) => {
  8184. if (!f || typeof f !== 'function') {
  8185. console.warn('f is not a function', f);
  8186. return;
  8187. }
  8188. let p = `${f}`, s = 0, j = -1, w = 0, q = ' ';
  8189. for (let i = 0, l = p.length; i < l; i++) {
  8190. const t = p[i];
  8191. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  8192. if (j < i - 1) {
  8193. w++;
  8194. if (q === '$') s--;
  8195. }
  8196. j = i;
  8197. } else {
  8198. s++;
  8199. }
  8200. q = t;
  8201. }
  8202. let itz = `${f.length}.${s}.${w}`;
  8203. if (!d) {
  8204. return itz;
  8205. } else {
  8206. return itz === d;
  8207. }
  8208. };
  8209.  
  8210. const getZqOu = (_yt_player) => {
  8211.  
  8212. const w = 'ZqOu';
  8213.  
  8214. let arr = [];
  8215.  
  8216. for (const [k, v] of Object.entries(_yt_player)) {
  8217.  
  8218. const p = typeof v === 'function' ? v.prototype : 0;
  8219. if (p
  8220. && typeof p.start === 'function' && p.start.length === 0 // Ou
  8221. && typeof p.isActive === 'function' && p.isActive.length === 0
  8222. && typeof p.stop === 'function' && p.stop.length === 0
  8223. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8224. && !p.send && !p.abort
  8225. && !p.sample && !p.initialize && !p.fail && !p.getName
  8226. // && !p.dispose && !p.isDisposed
  8227.  
  8228. ) {
  8229. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8230.  
  8231.  
  8232. }
  8233.  
  8234. }
  8235.  
  8236. if (arr.length === 0) {
  8237.  
  8238. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8239. } else {
  8240.  
  8241. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8242. return arr[0];
  8243. }
  8244.  
  8245. }
  8246.  
  8247. const getZqQu = (_yt_player) => {
  8248.  
  8249. const w = 'ZqQu';
  8250.  
  8251. let arr = [];
  8252.  
  8253.  
  8254. for (const [k, v] of Object.entries(_yt_player)) {
  8255.  
  8256. const p = typeof v === 'function' ? v.prototype : 0;
  8257. if (p
  8258. && typeof p.start === 'function' && p.start.length === 1 // Qu
  8259. && typeof p.isActive === 'function' && p.isActive.length === 0
  8260. && typeof p.stop === 'function' && p.stop.length === 0
  8261. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  8262. && !p.send && !p.abort
  8263. && !p.sample && !p.initialize && !p.fail && !p.getName
  8264. // && !p.dispose && !p.isDisposed
  8265.  
  8266. ) {
  8267. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8268.  
  8269.  
  8270. }
  8271.  
  8272. }
  8273.  
  8274. if (arr.length === 0) {
  8275.  
  8276. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8277. } else {
  8278.  
  8279. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8280. return arr[0];
  8281. }
  8282.  
  8283. }
  8284.  
  8285.  
  8286. const getVG = (_yt_player) => {
  8287. const w = 'VG';
  8288.  
  8289. let arr = [];
  8290.  
  8291. for (const [k, v] of Object.entries(_yt_player)) {
  8292.  
  8293. const p = typeof v === 'function' ? v.prototype : 0;
  8294. if (p
  8295. && typeof p.show === 'function' && p.show.length === 1
  8296. && typeof p.hide === 'function' && p.hide.length === 0
  8297. && typeof p.stop === 'function' && p.stop.length === 0) {
  8298.  
  8299. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8300.  
  8301. }
  8302.  
  8303. }
  8304.  
  8305.  
  8306. if (arr.length === 0) {
  8307.  
  8308. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8309. } else {
  8310.  
  8311. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8312. return arr[0];
  8313. }
  8314.  
  8315.  
  8316.  
  8317. }
  8318.  
  8319.  
  8320. const getzo = (_yt_player) => {
  8321. const w = 'zo';
  8322.  
  8323. let arr = [];
  8324.  
  8325. for (const [k, v] of Object.entries(_yt_player)) {
  8326.  
  8327. if (
  8328. typeof v === 'function' && v.length === 3 && k.length < 3
  8329. ) {
  8330. const vt = `${v}`;
  8331. if (vt.length >= 21 && vt.includes(".style[")) {
  8332. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  8333. arr.push(k);
  8334. } else {
  8335. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  8336. }
  8337. }
  8338. }
  8339.  
  8340. }
  8341.  
  8342. if (arr.length === 0) {
  8343.  
  8344. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8345. } else {
  8346.  
  8347. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8348. return arr[0];
  8349. }
  8350.  
  8351. }
  8352.  
  8353. const addProtoToArr = (parent, key, arr) => {
  8354.  
  8355.  
  8356. let isChildProto = false;
  8357. for (const sr of arr) {
  8358. if (parent[key].prototype instanceof parent[sr]) {
  8359. isChildProto = true;
  8360. break;
  8361. }
  8362. }
  8363.  
  8364. if (isChildProto) return;
  8365.  
  8366. arr = arr.filter(sr => {
  8367. if (parent[sr].prototype instanceof parent[key]) {
  8368. return false;
  8369. }
  8370. return true;
  8371. });
  8372.  
  8373. arr.push(key);
  8374.  
  8375. return arr;
  8376.  
  8377.  
  8378. }
  8379.  
  8380. const getuG = (_yt_player) => {
  8381.  
  8382. const w = 'uG';
  8383.  
  8384. let arr = [];
  8385.  
  8386. for (const [k, v] of Object.entries(_yt_player)) {
  8387.  
  8388. const p = typeof v === 'function' ? v.prototype : 0;
  8389.  
  8390. if (p
  8391. && typeof p.createElement === 'function' && p.createElement.length === 2
  8392. && typeof p.detach === 'function' && p.detach.length === 0
  8393. && typeof p.update === 'function' && p.update.length === 1
  8394. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  8395. ) {
  8396.  
  8397. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8398.  
  8399. }
  8400.  
  8401. }
  8402.  
  8403. if (arr.length === 0) {
  8404.  
  8405. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8406. } else {
  8407.  
  8408. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8409. return arr[0];
  8410. }
  8411.  
  8412. }
  8413.  
  8414. /*
  8415.  
  8416. // QT might be used in future changes
  8417. const getQT = (_yt_player) => {
  8418. const w = 'QT';
  8419.  
  8420. let arr = [];
  8421. let brr = new Map();
  8422.  
  8423. for (const [k, v] of Object.entries(_yt_player)) {
  8424.  
  8425. const p = typeof v === 'function' ? v.prototype : 0;
  8426. if (p) {
  8427. let q = 0;
  8428. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8429. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8430. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8431.  
  8432. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8433.  
  8434. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8435.  
  8436. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8437. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8438. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8439. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8440.  
  8441.  
  8442. // differentiate QT and DX
  8443.  
  8444. q += 280;
  8445. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  8446. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  8447. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  8448. if (typeof p.seekBy === 'function') q += 4;
  8449. if (typeof p.seekTo === 'function') q += 4;
  8450. if (typeof p.getStoryboardFormat === 'function') q += 4;
  8451. if (typeof p.getDuration === 'function') q += 4;
  8452. if (typeof p.loadModule === 'function') q += 4;
  8453. if (typeof p.unloadModule === 'function') q += 4;
  8454. if (typeof p.getOption === 'function') q += 4;
  8455. if (typeof p.getOptions === 'function') q += 4;
  8456. if (typeof p.setOption === 'function') q += 4;
  8457. if (typeof p.addCueRange === 'function') q += 4;
  8458. if (typeof p.getDebugText === 'function') q += 4;
  8459. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  8460. if (typeof p.setSizeStyle === 'function') q += 4;
  8461. if (typeof p.showControls === 'function') q += 4;
  8462. if (typeof p.hideControls === 'function') q += 4;
  8463. if (typeof p.getVideoContentRect === 'function') q += 4;
  8464. if (typeof p.toggleFullscreen === 'function') q += 4;
  8465. if (typeof p.isFullscreen === 'function') q += 4;
  8466. if (typeof p.cancelPlayback === 'function') q += 4;
  8467. if (typeof p.getProgressState === 'function') q += 4;
  8468. if (typeof p.isInline === 'function') q += 4;
  8469. if (typeof p.setInline === 'function') q += 4;
  8470. if (typeof p.toggleSubtitles === 'function') q += 4;
  8471. if (typeof p.getPlayerSize === 'function') q += 4;
  8472. if (typeof p.wakeUpControls === 'function') q += 4;
  8473. if (typeof p.setCenterCrop === 'function') q += 4;
  8474. if (typeof p.getLoopVideo === 'function') q += 4;
  8475. if (typeof p.setLoopVideo === 'function') q += 4;
  8476.  
  8477.  
  8478. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8479.  
  8480. if (q > 0) brr.set(k, q);
  8481.  
  8482. }
  8483.  
  8484. }
  8485.  
  8486. if (arr.length === 0) {
  8487.  
  8488. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8489. } else {
  8490.  
  8491. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8492.  
  8493. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8494.  
  8495. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8496. return arr[0][0];
  8497. }
  8498.  
  8499. }
  8500.  
  8501. // SV might be used in future changes
  8502. const getSV = (_yt_player) => {
  8503. const w = 'SV';
  8504.  
  8505. let arr = [];
  8506. let brr = new Map();
  8507.  
  8508. for (const [k, v] of Object.entries(_yt_player)) {
  8509.  
  8510. const p = typeof v === 'function' ? v.prototype : 0;
  8511. if (p) {
  8512. let q = 0;
  8513. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8514. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8515. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8516.  
  8517. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  8518.  
  8519. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8520.  
  8521. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8522. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8523. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8524. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8525.  
  8526.  
  8527. // differentiate QT and DX
  8528.  
  8529.  
  8530. q += 280;
  8531.  
  8532. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  8533. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  8534. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  8535. if (typeof p.seekBy === 'function') q -= 4;
  8536. if (typeof p.seekTo === 'function') q -= 4;
  8537. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  8538. if (typeof p.getDuration === 'function') q -= 4;
  8539. if (typeof p.loadModule === 'function') q -= 4;
  8540. if (typeof p.unloadModule === 'function') q -= 4;
  8541. if (typeof p.getOption === 'function') q -= 4;
  8542. if (typeof p.getOptions === 'function') q -= 4;
  8543. if (typeof p.setOption === 'function') q -= 4;
  8544. if (typeof p.addCueRange === 'function') q -= 4;
  8545. if (typeof p.getDebugText === 'function') q -= 4;
  8546. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  8547. if (typeof p.setSizeStyle === 'function') q -= 4;
  8548. if (typeof p.showControls === 'function') q -= 4;
  8549. if (typeof p.hideControls === 'function') q -= 4;
  8550. if (typeof p.getVideoContentRect === 'function') q -= 4;
  8551. if (typeof p.toggleFullscreen === 'function') q -= 4;
  8552. if (typeof p.isFullscreen === 'function') q -= 4;
  8553. if (typeof p.cancelPlayback === 'function') q -= 4;
  8554. if (typeof p.getProgressState === 'function') q -= 4;
  8555. if (typeof p.isInline === 'function') q -= 4;
  8556. if (typeof p.setInline === 'function') q -= 4;
  8557. if (typeof p.toggleSubtitles === 'function') q -= 4;
  8558. if (typeof p.getPlayerSize === 'function') q -= 4;
  8559. if (typeof p.wakeUpControls === 'function') q -= 4;
  8560. if (typeof p.setCenterCrop === 'function') q -= 4;
  8561. if (typeof p.getLoopVideo === 'function') q -= 4;
  8562. if (typeof p.setLoopVideo === 'function') q -= 4;
  8563.  
  8564.  
  8565. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8566.  
  8567. if (q > 0) brr.set(k, q);
  8568.  
  8569. }
  8570.  
  8571. }
  8572.  
  8573. if (arr.length === 0) {
  8574.  
  8575. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8576. } else {
  8577.  
  8578. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8579.  
  8580. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8581.  
  8582. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8583. return arr[0][0];
  8584. }
  8585.  
  8586. }
  8587.  
  8588. // no DX key
  8589. const getDX = (_yt_player) => {
  8590. const w = 'DX';
  8591.  
  8592. let arr = [];
  8593. let brr = new Map();
  8594.  
  8595. for (const [k, v] of Object.entries(_yt_player)) {
  8596.  
  8597. const p = typeof v === 'function' ? v.prototype : 0;
  8598. if (p) {
  8599. let q = 0;
  8600. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  8601. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  8602. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  8603.  
  8604. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  8605.  
  8606.  
  8607. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  8608.  
  8609. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  8610.  
  8611. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  8612. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  8613. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  8614. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  8615.  
  8616.  
  8617. // differentiate QT and DX
  8618.  
  8619.  
  8620. q += 280;
  8621.  
  8622. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  8623. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  8624. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  8625. if (typeof p.seekBy === 'function') q -= 4;
  8626. if (typeof p.seekTo === 'function') q -= 4;
  8627. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  8628. if (typeof p.getDuration === 'function') q -= 4;
  8629. if (typeof p.loadModule === 'function') q -= 4;
  8630. if (typeof p.unloadModule === 'function') q -= 4;
  8631. if (typeof p.getOption === 'function') q -= 4;
  8632. if (typeof p.getOptions === 'function') q -= 4;
  8633. if (typeof p.setOption === 'function') q -= 4;
  8634. if (typeof p.addCueRange === 'function') q -= 4;
  8635. if (typeof p.getDebugText === 'function') q -= 4;
  8636. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  8637. if (typeof p.setSizeStyle === 'function') q -= 4;
  8638. if (typeof p.showControls === 'function') q -= 4;
  8639. if (typeof p.hideControls === 'function') q -= 4;
  8640. if (typeof p.getVideoContentRect === 'function') q -= 4;
  8641. if (typeof p.toggleFullscreen === 'function') q -= 4;
  8642. if (typeof p.isFullscreen === 'function') q -= 4;
  8643. if (typeof p.cancelPlayback === 'function') q -= 4;
  8644. if (typeof p.getProgressState === 'function') q -= 4;
  8645. if (typeof p.isInline === 'function') q -= 4;
  8646. if (typeof p.setInline === 'function') q -= 4;
  8647. if (typeof p.toggleSubtitles === 'function') q -= 4;
  8648. if (typeof p.getPlayerSize === 'function') q -= 4;
  8649. if (typeof p.wakeUpControls === 'function') q -= 4;
  8650. if (typeof p.setCenterCrop === 'function') q -= 4;
  8651. if (typeof p.getLoopVideo === 'function') q -= 4;
  8652. if (typeof p.setLoopVideo === 'function') q -= 4;
  8653.  
  8654.  
  8655. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  8656.  
  8657. if (q > 0) brr.set(k, q);
  8658.  
  8659. }
  8660.  
  8661. }
  8662.  
  8663. if (arr.length === 0) {
  8664.  
  8665. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  8666. } else {
  8667.  
  8668. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  8669.  
  8670. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  8671.  
  8672. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  8673. return arr[0][0];
  8674. }
  8675.  
  8676.  
  8677.  
  8678. }
  8679.  
  8680. */
  8681.  
  8682.  
  8683. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  8684.  
  8685. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  8686. let pageSetupState = 0;
  8687.  
  8688. isPrepareCachedV && (() => {
  8689.  
  8690. pageSetupVideoId = '';
  8691. const clearCachedV = () => {
  8692. pageSetupVideoId = '';
  8693. pageSetupState = 0;
  8694. }
  8695. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  8696. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  8697. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  8698. document.addEventListener('yt-navigate-finish', () => {
  8699. pageSetupState = 1;
  8700. try {
  8701. const url = new URL(location.href);
  8702. if (!url || !isWatchPageURL(url)) {
  8703. pageSetupVideoId = '';
  8704. } else {
  8705. pageSetupVideoId = url.searchParams.get('v') || '';
  8706. }
  8707. } catch (e) {
  8708. pageSetupVideoId = '';
  8709. }
  8710. }, false);
  8711.  
  8712. })();
  8713.  
  8714. let videoPlayingY = null;
  8715.  
  8716. isPrepareCachedV && (() => {
  8717.  
  8718. let getNext = true;
  8719. let videoPlayingX = {
  8720. get videoId() {
  8721. if (getNext) {
  8722. getNext = false;
  8723.  
  8724. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  8725. const arr = [];
  8726. for (const element of elements) {
  8727. if (!element.closest('[hidden]')) arr.push(element);
  8728. }
  8729. if (arr.length !== 1) this.__videoId__ = '';
  8730. else {
  8731. this.__videoId__ = arr[0].getAttribute('video-id');
  8732. }
  8733.  
  8734. }
  8735. return this.__videoId__ || '';
  8736. }
  8737. }
  8738.  
  8739. videoPlayingY = videoPlayingX;
  8740. const handler = (evt) => {
  8741. const target = (evt || 0).target;
  8742. if (target instanceof HTMLVideoElement) {
  8743. getNext = true;
  8744. }
  8745. }
  8746. document.addEventListener('loadedmetadata', handler, true);
  8747. document.addEventListener('durationchange', handler, true);
  8748.  
  8749. })();
  8750.  
  8751.  
  8752.  
  8753. const cleanContext = async (win) => {
  8754. const waitFn = requestAnimationFrame; // shall have been binded to window
  8755. try {
  8756. let mx = 16; // MAX TRIAL
  8757. const frameId = 'vanillajs-iframe-v1';
  8758. /** @type {HTMLIFrameElement | null} */
  8759. let frame = document.getElementById(frameId);
  8760. let removeIframeFn = null;
  8761. if (!frame) {
  8762. frame = document.createElement('iframe');
  8763. frame.id = frameId;
  8764. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  8765. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  8766. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  8767. n.appendChild(frame);
  8768. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  8769. const root = document.documentElement;
  8770. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  8771. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  8772.  
  8773. removeIframeFn = (setTimeout) => {
  8774. const removeIframeOnDocumentReady = (e) => {
  8775. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  8776. e = n;
  8777. n = win = removeIframeFn = 0;
  8778. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  8779. }
  8780. if (!setTimeout || document.readyState !== 'loading') {
  8781. removeIframeOnDocumentReady();
  8782. } else {
  8783. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  8784. }
  8785. }
  8786. }
  8787. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  8788. const fc = frame.contentWindow;
  8789. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  8790. try {
  8791. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  8792. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  8793. for (let k in res) res[k] = res[k].bind(win); // necessary
  8794. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  8795. res.animate = fc.HTMLElement.prototype.animate;
  8796. res.perfNow = fc.performance.now;
  8797. return res;
  8798. } catch (e) {
  8799. if (removeIframeFn) removeIframeFn();
  8800. return null;
  8801. }
  8802. } catch (e) {
  8803. console.warn(e);
  8804. return null;
  8805. }
  8806. };
  8807.  
  8808. const promiseForYtActionCalled = new Promise(resolve => {
  8809.  
  8810. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8811. if (typeof AbortSignal !== 'undefined') {
  8812. let hn = () => {
  8813. if (!hn) return;
  8814. hn = null;
  8815. resolve(document.querySelector(appTag));
  8816. };
  8817. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  8818. } else {
  8819. let hn = () => {
  8820. if (!hn) return;
  8821. document.removeEventListener('yt-action', hn, true);
  8822. hn = null;
  8823. resolve(document.querySelector(appTag));
  8824. };
  8825. document.addEventListener('yt-action', hn, true);
  8826. }
  8827. });
  8828.  
  8829. cleanContext(window).then(__CONTEXT__ => {
  8830. if (!__CONTEXT__) return null;
  8831.  
  8832. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  8833.  
  8834.  
  8835. performance.now17 = perfNow.bind(performance);
  8836.  
  8837.  
  8838.  
  8839. __requestAnimationFrame__ = requestAnimationFrame;
  8840.  
  8841.  
  8842. const isGPUAccelerationAvailable = (() => {
  8843. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  8844. try {
  8845. const canvas = document.createElement('canvas');
  8846. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  8847. } catch (e) {
  8848. return false;
  8849. }
  8850. })();
  8851.  
  8852. const foregroundPromiseFn_noGPU = (() => {
  8853.  
  8854. if (isGPUAccelerationAvailable) return null;
  8855.  
  8856. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  8857. if (!pd || typeof pd.get !== 'function') return null;
  8858. const pdGet = pd.get;
  8859.  
  8860. let pr = null;
  8861.  
  8862. let hState = pdGet.call(document) === 'hidden';
  8863. // let cid = 0;
  8864. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  8865. const newHState = pdGet.call(document) === 'hidden';
  8866. if (hState !== newHState) {
  8867. // if (cid > 0) cid = clearInterval(cid);
  8868. hState = newHState;
  8869. if (!hState && pr) pr = pr.resolve();
  8870. }
  8871. });
  8872.  
  8873. // cid = setInterval(() => {
  8874. // const newHState = document.visibilityState === 'hidden';
  8875. // if (hState !== newHState) {
  8876. // hState = newHState;
  8877. // if (!hState && pr) pr = pr.resolve();
  8878. // }
  8879. // }, 100);
  8880.  
  8881.  
  8882. return (() => {
  8883. if (pr) return pr;
  8884. const w = ((!hState && setTimeout(() => {
  8885. if (!hState && pr === w) pr = pr.resolve();
  8886. })), (pr = new PromiseExternal()));
  8887. return w;
  8888. });
  8889.  
  8890. })();
  8891.  
  8892.  
  8893. let rafPromise = null;
  8894. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  8895. requestAnimationFrame(hRes => {
  8896. rafPromise = null;
  8897. resolve(hRes);
  8898. });
  8899. }));
  8900.  
  8901. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  8902.  
  8903.  
  8904. const wmComputedStyle = new WeakMap();
  8905.  
  8906. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  8907. window.__native__getComputedStyle__ = getComputedStyle;
  8908. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  8909. window.__original__getComputedStyle__ = window.getComputedStyle;
  8910. window.getComputedStyle = function (elem) {
  8911. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  8912. return window.__original__getComputedStyle__(...arguments);
  8913. }
  8914. let cs = wmComputedStyle.get(elem);
  8915. if (!cs) {
  8916. cs = window.__native__getComputedStyle__(elem);
  8917. wmComputedStyle.set(elem, cs);
  8918. }
  8919. return cs;
  8920. };
  8921. } else {
  8922. window.__original__getComputedStyle__ = null;
  8923. }
  8924. window.__jst__getComputedStyle__ = window.getComputedStyle;
  8925. }
  8926.  
  8927. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  8928. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  8929. window.getComputedStyle = window.__jst__getComputedStyle__;
  8930. }
  8931. });
  8932.  
  8933. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  8934. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  8935.  
  8936. const promiseForTamerTimeout = new Promise(resolve => {
  8937. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8938. setTimeout(resolve, 480);
  8939. }, { capture: true, passive: true, once: true });
  8940. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8941. setTimeout(resolve, 1200);
  8942. });
  8943. setTimeout(resolve, 3000);
  8944. });
  8945.  
  8946. const promiseForPageInitied = new Promise(resolve => {
  8947. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8948. setTimeout(resolve, 450);
  8949. }, { capture: true, passive: true, once: true });
  8950. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8951. setTimeout(resolve, 900);
  8952. });
  8953. setTimeout(resolve, 1800);
  8954. });
  8955.  
  8956. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  8957. NO_PRELOAD_GENERATE_204_BYPASS = true;
  8958. headLinkCollection = null;
  8959. });
  8960.  
  8961.  
  8962. NATIVE_CANVAS_ANIMATION && (() => {
  8963.  
  8964. observablePromise(() => {
  8965. HTMLCanvasElement.prototype.animate = animate;
  8966. }, promiseForTamerTimeout).obtain();
  8967.  
  8968. })();
  8969.  
  8970.  
  8971.  
  8972.  
  8973. FIX_ytAction_ && (async () => {
  8974.  
  8975. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8976.  
  8977. const ytdApp = await new Promise(resolve => {
  8978.  
  8979. whenCEDefined(appTag).then(() => {
  8980. const ytdApp = document.querySelector(appTag);
  8981. if (ytdApp) {
  8982. resolve(ytdApp);
  8983. return;
  8984. }
  8985. let mo = new MutationObserver(() => {
  8986. const ytdApp = document.querySelector(appTag);
  8987. if (!ytdApp) return;
  8988. if (mo) {
  8989. mo.disconnect();
  8990. mo.takeRecords();
  8991. mo = null;
  8992. }
  8993. resolve(ytdApp);
  8994. });
  8995. mo.observe(document, { subtree: true, childList: true });
  8996. });
  8997.  
  8998. });
  8999.  
  9000. if (!ytdApp) return;
  9001. const cProto = insp(ytdApp).constructor.prototype;
  9002.  
  9003. if (!cProto) return;
  9004. let mbd = 0;
  9005.  
  9006. const fixer = (_ytdApp) => {
  9007. const ytdApp = insp(_ytdApp);
  9008. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  9009. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  9010. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  9011. mbd++;
  9012. }
  9013. }
  9014.  
  9015. observablePromise(() => {
  9016.  
  9017. if (typeof cProto.created === 'function' && !cProto.created56) {
  9018. cProto.created56 = cProto.created;
  9019. cProto.created = function (...args) {
  9020. const r = this.created56(...args);
  9021. fixer(this);
  9022. return r;
  9023. };
  9024. mbd++;
  9025. }
  9026.  
  9027. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  9028. cProto.onYtAction57_ = cProto.onYtAction_;
  9029. cProto.onYtAction_ = function (...args) {
  9030. Promise.resolve().then(() => this.onYtAction57_(...args));
  9031. };
  9032. mbd++;
  9033. }
  9034.  
  9035. if (ytdApp) fixer(ytdApp);
  9036.  
  9037. /*
  9038. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  9039. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  9040. actionRouter_.handleAction57 = actionRouter_.handleAction;
  9041. actionRouter_.handleAction = function (...args) {
  9042. Promise.resolve().then(() => this.handleAction57(...args));
  9043. }
  9044. mbd++;
  9045. }
  9046. */
  9047.  
  9048. // if(mbd === 3) return 1;
  9049. if (mbd >= 3) return 1;
  9050.  
  9051. }, new Promise(r => setTimeout(r, 1000))).obtain();
  9052.  
  9053. })();
  9054.  
  9055.  
  9056. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  9057.  
  9058. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  9059.  
  9060. const app = await observablePromise(() => {
  9061.  
  9062. return document.querySelector(appTag);
  9063.  
  9064. }).obtain();
  9065.  
  9066. if (!app) return;
  9067.  
  9068. const appCnt = insp(app);
  9069. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  9070.  
  9071.  
  9072.  
  9073.  
  9074. });
  9075.  
  9076.  
  9077. // let _yt_player_promise = null;
  9078. /*
  9079. const getYtPlayerPromise = () => {
  9080. if (!_yt_player_promise) {
  9081. _yt_player_promise = new Promise(resolve => {
  9082. let cid = setInterval(() => {
  9083. let t = (((window || 0)._yt_player || 0) || 0);
  9084. if (t) {
  9085. clearInterval(cid);
  9086. resolve(t);
  9087. }
  9088. }, 1);
  9089. promiseForTamerTimeout.then(() => {
  9090. resolve(null)
  9091. });
  9092. });
  9093. }
  9094. return _yt_player_promise;
  9095. }
  9096. */
  9097. const _yt_player_observable = observablePromise(() => {
  9098. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  9099. if (_yt_player) {
  9100. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  9101. return _yt_player;
  9102. }
  9103. }, promiseForTamerTimeout);
  9104.  
  9105. const polymerObservable = observablePromise(() => {
  9106. const Polymer = window.Polymer;
  9107. if (typeof Polymer !== 'function') return;
  9108. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  9109. return Polymer;
  9110. }, promiseForTamerTimeout);
  9111.  
  9112. const schedulerInstanceObservable = observablePromise(() => {
  9113. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  9114. }, promiseForTamerTimeout);
  9115.  
  9116. const timelineObservable = observablePromise(() => {
  9117. let t = (((document || 0).timeline || 0) || 0);
  9118. if (t && typeof t._play === 'function') {
  9119. return t;
  9120. }
  9121. }, promiseForTamerTimeout);
  9122. const animationObservable = observablePromise(() => {
  9123. let t = (((window || 0).Animation || 0) || 0);
  9124. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  9125. return t;
  9126. }
  9127. }, promiseForTamerTimeout);
  9128.  
  9129.  
  9130. const getScreenInfo = {
  9131. screenWidth: 0,
  9132. screenHeight: 0,
  9133. valueReady: false,
  9134. onResize: () => {
  9135. getScreenInfo.valueReady = false;
  9136. },
  9137. sizeProvided: () => {
  9138. if (getScreenInfo.valueReady) return true;
  9139. getScreenInfo.screenWidth = screen.width;
  9140. getScreenInfo.screenHeight = screen.height;
  9141. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  9142. getScreenInfo.valueReady = true;
  9143. return true;
  9144. }
  9145. return false;
  9146. }
  9147. };
  9148.  
  9149. window.addEventListener('resize', getScreenInfo.onResize, true);
  9150.  
  9151.  
  9152. // const hookLeftPending = new WeakMap();
  9153.  
  9154. const isNaNx = Number.isNaN;
  9155.  
  9156. const hookLeftPD = {
  9157. get() {
  9158. const p = 'left';
  9159. // const o = hookLeftPending.get(this);
  9160. // if (o && o.key) {
  9161. // this.setProperty(p, o.value);
  9162. // o.key = null
  9163. // }
  9164. return this.getPropertyValue(p);
  9165. },
  9166. set(v) {
  9167.  
  9168. const p = 'left';
  9169. const cv = this.getPropertyValue(p);
  9170. const sv = v;
  9171.  
  9172. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  9173.  
  9174. // console.log(8380,did, cv, sv)
  9175. if (!cv && !sv) return true;
  9176. if (cv === sv) return true;
  9177.  
  9178. // skip 0~9px => L>=4
  9179.  
  9180. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  9181.  
  9182. if (!isNaNx(qsv)) {
  9183. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  9184.  
  9185. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  9186. const { screenWidth, screenHeight } = getScreenInfo;
  9187. let pWidth = screenWidth + 1024;
  9188. let pHeight = screenHeight + 768;
  9189. const minRatio = 0.003;
  9190. const dw = pWidth * 0.0003; // min dw = 0.3072
  9191. const dh = pHeight * 0.0003; // min dh = 0.2304
  9192. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  9193. if (Math.abs(qcv - qsv) < dw) return true;
  9194. }
  9195.  
  9196. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  9197. if (`${v}`.length > `${sv}`.length) v = sv;
  9198. // console.log(8382, did, sv, nv, cv, this)
  9199. }
  9200.  
  9201. // Promise.resolve().then(() => {
  9202. // const o = hookLeftPending.get(this);
  9203. // if (o && o.key === did) {
  9204. // this.setProperty(p, o.value);
  9205. // o.key = null;
  9206. // }
  9207. // });
  9208. // hookLeftPending.set(this, {
  9209. // key: did,
  9210. // value: nv
  9211. // });
  9212.  
  9213. // if (nv != v) {
  9214. // console.log(8387, v, nv);
  9215. // }
  9216.  
  9217. this.setProperty(p, v);
  9218. // console.log(8383, did, this.getPropertyValue(p))
  9219. return true;
  9220. },
  9221. enumerable: true,
  9222. configurable: true
  9223. };
  9224.  
  9225.  
  9226. if (HOOK_CSSPD_LEFT) {
  9227.  
  9228.  
  9229. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  9230.  
  9231. }
  9232.  
  9233.  
  9234.  
  9235.  
  9236.  
  9237. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  9238.  
  9239. const evKey = `${_evKey}`;
  9240. const fvKey = `${_fvKey}`;
  9241. const debug = !!_debug;
  9242.  
  9243. const _yt_player = await _yt_player_observable.obtain();
  9244.  
  9245.  
  9246. if (!_yt_player || typeof _yt_player !== 'object') return;
  9247.  
  9248.  
  9249. const getArr = (_yt_player) => {
  9250.  
  9251. let arr = [];
  9252.  
  9253. for (const [k, v] of Object.entries(_yt_player)) {
  9254.  
  9255. const p = typeof v === 'function' ? v.prototype : 0;
  9256. if (p
  9257. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  9258.  
  9259. ) {
  9260. arr = addProtoToArr(_yt_player, k, arr) || arr;
  9261.  
  9262. }
  9263.  
  9264. }
  9265.  
  9266. if (arr.length === 0) {
  9267.  
  9268. console.warn(`Key prop [${evKey}] does not exist.`);
  9269. } else {
  9270.  
  9271. return arr;
  9272. }
  9273.  
  9274. };
  9275.  
  9276. const arr = getArr(_yt_player);
  9277.  
  9278.  
  9279. if (!arr) return;
  9280.  
  9281. debug && console.log(`FIX_${evKey}`, arr);
  9282.  
  9283. const f = function (...args) {
  9284. Promise.resolve().then(() => this[fvKey](...args));
  9285. };
  9286.  
  9287.  
  9288. for (const k of arr) {
  9289.  
  9290. const g = _yt_player;
  9291. const gk = g[k];
  9292. const gkp = gk.prototype;
  9293.  
  9294. debug && console.log(237, k, gkp)
  9295.  
  9296. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  9297. gkp[fvKey] = gkp[evKey];
  9298. gkp[evKey] = f;
  9299. }
  9300. }
  9301.  
  9302.  
  9303.  
  9304.  
  9305. }
  9306.  
  9307. if (!isChatRoomURL) {
  9308.  
  9309. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  9310. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  9311. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  9312. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  9313. if (FIX_VideoEVENTS_v2) {
  9314. const FIX_VideoEVENTS_DEBUG = 0;
  9315. // generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // -- // no onVideoProgress in latest YouTube Coding (2025.06.12)
  9316. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  9317. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  9318. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  9319. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  9320. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  9321. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  9322. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  9323. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  9324.  
  9325. }
  9326. // onMutedAutoplayChange
  9327. // onVolumeChange
  9328. // onPlaybackRateChange
  9329.  
  9330. // onAirPlayActiveChange
  9331. // onAirPlayAvailabilityChange
  9332. // onApiChange
  9333. // onAutoplayBlocked
  9334. // onDrmOutputRestricted
  9335. // onFullscreenChange
  9336. // onLoadProgress
  9337. // onLoadedMetadata
  9338. // onVideoDataChange
  9339. // onVideoProgress
  9340.  
  9341. }
  9342.  
  9343.  
  9344. let isAmended_Polymer_RenderStatus = false;
  9345.  
  9346. (FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  9347.  
  9348. const Polymer = await polymerObservable.obtain();
  9349. if (!Polymer) return;
  9350.  
  9351. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  9352. isAmended_Polymer_RenderStatus = true;
  9353.  
  9354. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  9355. let arrBefore = null, arrAfter = null;
  9356. const push = Array.prototype.push;
  9357. let arr = null;
  9358. Array.prototype.push = function () {
  9359. arr = this;
  9360. }
  9361. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  9362. if (arr) arrBefore = arr;
  9363. arr = null;
  9364. Polymer.RenderStatus.afterNextRender({}, {}, {});
  9365. if (arr) arrAfter = arr;
  9366. arr = null;
  9367. Array.prototype.push = push;
  9368. Polymer.RenderStatus.arrBefore = arrBefore;
  9369. Polymer.RenderStatus.arrAfter = arrAfter;
  9370.  
  9371. if (arrBefore && arrAfter) {
  9372.  
  9373. Function.prototype.call7900 = Function.prototype.call;
  9374. Function.prototype.apply7900 = Function.prototype.apply;
  9375. Function.prototype.apply7948 = function (obj, args) {
  9376. const f = this;
  9377. let m = kRef(obj);
  9378. if (!m) return;
  9379. if (m.is && !m.nodeName) {
  9380. if (!m.isAttached || !m.hostElement) {
  9381. return;
  9382. }
  9383. }
  9384. try {
  9385. return !args ? f.call7900(m) : f.apply7900(m, args);
  9386. } catch (e) {
  9387. console.warn(e);
  9388. }
  9389. return null;
  9390. }
  9391.  
  9392. arrBefore.push = arrAfter.push = function (a) {
  9393. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  9394. if (a[0].deref) a[0] = kRef(a[0]);
  9395. const f = a[1]
  9396. const obj = a[0]
  9397. const args = a[2];
  9398. f.apply = f.apply7948;
  9399. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  9400. a[0] = obj[wk]
  9401. // console.log(4992, a)
  9402. return push.call(this, a);
  9403. }
  9404.  
  9405. }
  9406.  
  9407.  
  9408. }
  9409. // Polymer.RenderStatus.beforeNextRender
  9410. }
  9411.  
  9412. if (FIX_Polymer_dom) {
  9413.  
  9414. const checkPDFuncValue = (pd) => {
  9415. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  9416. }
  9417. const checkPDFuncValue2 = (pd) => {
  9418. return pd && typeof pd.value == 'function'
  9419. }
  9420.  
  9421. const checkPDFuncGet = (pd) => {
  9422. return pd && typeof pd.get == 'function'
  9423. }
  9424.  
  9425. const domX = Polymer.dom(document.createElement('null'));
  9426. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  9427. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  9428. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  9429. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  9430. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  9431. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  9432. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  9433. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  9434. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  9435.  
  9436.  
  9437. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  9438.  
  9439. domXP.querySelector15 = domXP.querySelector;
  9440.  
  9441. const querySelectorFn = function (query) {
  9442. try {
  9443. const p = this.node;
  9444.  
  9445. if (p instanceof Document && p.isConnected === true) {
  9446. return pd4b.value.call(p, query);
  9447. }
  9448.  
  9449. } catch (e) { }
  9450. return this.querySelector15(query);
  9451. }
  9452.  
  9453. Object.defineProperty(domXP, 'querySelector', {
  9454. get() {
  9455. return querySelectorFn;
  9456. },
  9457. set(nv) {
  9458. if (nv === querySelectorFn) return true;
  9459. this.querySelector15 = nv;
  9460. return true;
  9461. },
  9462.  
  9463. enumerable: false,
  9464. configurable: true
  9465. });
  9466.  
  9467. Polymer.__fixedQuerySelector__ = 1;
  9468. }
  9469.  
  9470. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  9471.  
  9472. domXP.querySelectorAll15 = domXP.querySelectorAll;
  9473.  
  9474. const querySelectorAllFn = function (query) {
  9475.  
  9476. try {
  9477.  
  9478. const p = this.node;
  9479.  
  9480. if (p instanceof Document && p.isConnected === true) {
  9481. return pd6b.value.call(p, query);
  9482. }
  9483.  
  9484. } catch (e) {
  9485.  
  9486. }
  9487. return this.querySelectorAll15(query);
  9488. }
  9489.  
  9490. Object.defineProperty(domXP, 'querySelectorAll', {
  9491. get() {
  9492. return querySelectorAllFn;
  9493. },
  9494. set(nv) {
  9495. if (nv === querySelectorAllFn) return true;
  9496. this.querySelectorAll15 = nv;
  9497. return true;
  9498. },
  9499.  
  9500. enumerable: false,
  9501. configurable: true
  9502. });
  9503.  
  9504. Polymer.__fixedQuerySelectorAll__ = 1;
  9505. }
  9506. }
  9507.  
  9508.  
  9509. if (FIX_stampDomArray) {
  9510.  
  9511. Polymer.Base.__connInit__ = function () {
  9512. setupYtComponent(this);
  9513. }
  9514.  
  9515.  
  9516. /** @type {Function} */
  9517. const connectedCallbackK = function (...args) {
  9518. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9519. const r = this[qm53](...args);
  9520. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9521. this.mh35 = 1;
  9522. return r;
  9523. };
  9524.  
  9525. connectedCallbackK.m353 = 1;
  9526.  
  9527.  
  9528. const qt53 = Polymer.Base.connectedCallback;
  9529. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  9530.  
  9531. Polymer.Base.connectedCallback = connectedCallbackK;
  9532.  
  9533.  
  9534. /** @type {Function} */
  9535. const createdK = function (...args) {
  9536. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9537. const r = this[qn53](...args);
  9538. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  9539. this.mh36 = 1;
  9540. return r;
  9541. };
  9542.  
  9543.  
  9544. createdK.m353 = 1;
  9545. Polymer.Base[qn53] = Polymer.Base.created;
  9546. Polymer.Base.created = createdK;
  9547.  
  9548.  
  9549.  
  9550.  
  9551.  
  9552.  
  9553.  
  9554.  
  9555.  
  9556.  
  9557.  
  9558. }
  9559.  
  9560. })();
  9561.  
  9562.  
  9563. /*
  9564.  
  9565. e.nativeAppendChild = d.prototype.appendChild,
  9566. d.prototype.appendChild = function(h) {
  9567. return function(l) {
  9568. if (l instanceof DocumentFragment) {
  9569. var m = Array.from(l.children);
  9570. l = h.nativeAppendChild.call(this, l);
  9571. if (this.isConnected) {
  9572. m = g(m);
  9573. for (var p = m.next(); !p.done; p = m.next())
  9574. YD(p.value)
  9575. }
  9576. return l
  9577. }
  9578. m = l instanceof Element && l.isConnected;
  9579. p = h.nativeAppendChild.call(this, l);
  9580. m && ZD(l);
  9581. this.isConnected && YD(l);
  9582. return p
  9583. }
  9584. }(e),
  9585.  
  9586. */
  9587.  
  9588. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  9589.  
  9590. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  9591. if (f) Node.prototype.appendChild = function (a) {
  9592. if (this instanceof Element) { // exclude DocumentFragment
  9593. try {
  9594. let checkFragmentA = (a instanceof DocumentFragment);
  9595. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  9596. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  9597. for (const node of headLinkCollection) {
  9598. if (node.rel === 'preload' && node.as === 'fetch') {
  9599. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  9600. }
  9601. }
  9602. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  9603. checkFragmentA = false;
  9604. }
  9605. if (checkFragmentA && a.firstElementChild === null) {
  9606. // no element in fragmentA
  9607. let doNormal = false;
  9608. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  9609. if (child.nodeType === 3) { doNormal = true; break; }
  9610. }
  9611. if (!doNormal) return a;
  9612. }
  9613. } catch (e) {
  9614. console.log(e);
  9615. }
  9616. }
  9617. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  9618. }
  9619.  
  9620. })();
  9621.  
  9622. if (FIX_Shady) {
  9623.  
  9624. observablePromise(() => {
  9625. const { ShadyDOM, ShadyCSS } = window;
  9626. if (ShadyDOM) {
  9627. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  9628. ShadyDOM.noPatch = true; // 1 of 10
  9629. ShadyDOM.patchOnDemand = false; // 1 of 10
  9630. ShadyDOM.preferPerformance = true; // 1 of 10
  9631. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  9632. }
  9633. if (ShadyCSS) {
  9634. ShadyCSS.nativeCss = true; // 1 of 10
  9635. ShadyCSS.nativeShadow = true; // 6 of 10
  9636. ShadyCSS.cssBuild = undefined; // 1 of 10
  9637. ShadyCSS.disableRuntime = true; // 1 of 10
  9638. }
  9639. if (ShadyDOM && ShadyCSS) return 1;
  9640. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  9641.  
  9642. }
  9643.  
  9644.  
  9645. // let schedulerInstancePropOfTimerType = '';
  9646. // let schedulerInstancePropOfTimerId = '';
  9647. (FIX_schedulerInstanceInstance & 2) && (async () => {
  9648.  
  9649. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  9650.  
  9651. if (!schedulerInstanceInstance_) return;
  9652.  
  9653. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  9654. if (checkOK) {
  9655.  
  9656. let resolveRendering = null;
  9657.  
  9658. let cmPr = new PromiseExternal();
  9659. const cm = document.createComment('0');
  9660. const cmObs = new MutationObserver(() => {
  9661. if (resolveRendering) {
  9662. resolveRendering();
  9663. resolveRendering = null;
  9664. }
  9665. cmPr.resolve();
  9666. cmPr = new PromiseExternal();
  9667. });
  9668. cmObs.observe(cm, {characterData: true})
  9669.  
  9670. let web_emulated_idle_callback_delay_val = null;
  9671.  
  9672. const getRenderIdleCallbackMs = () => {
  9673. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  9674. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  9675. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  9676. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  9677. return web_emulated_idle_callback_delay_val;
  9678. }
  9679. let isDelayRenderFn_firstCheck = true;
  9680. let isDelayRenderFn_key = null;
  9681. const isDelayRenderFn = (f) => {
  9682. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  9683. isDelayRenderFn_firstCheck = false;
  9684. if (typeof ytglobal === 'undefined') return false;
  9685. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  9686. if (!globalInstance) return false;
  9687. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  9688. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  9689. isDelayRenderFn_key = entry[0]
  9690. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  9691. return true;
  9692. }
  9693. }
  9694. return false;
  9695. }
  9696.  
  9697. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  9698.  
  9699. let requestingFn = null;
  9700. let requestingArgs = null;
  9701.  
  9702. const f = function () {
  9703. requestingFn = this.fn;
  9704. requestingArgs = [...arguments];
  9705. return 12373;
  9706. };
  9707.  
  9708. const fakeFns = [
  9709. f.bind({ fn: requestAnimationFrame }),
  9710. f.bind({ fn: setInterval }),
  9711. f.bind({ fn: setTimeout }),
  9712. f.bind({ fn: requestIdleCallback })
  9713. ];
  9714.  
  9715. let mzt = 0;
  9716.  
  9717. let _fnSelectorProp = null;
  9718. const mkFns = new Array(4);
  9719.  
  9720. /*
  9721. case 1:
  9722. var a = this.K;
  9723. this.g = this.I ? window.requestIdleCallback(a, {
  9724. timeout: 3E3
  9725. }) : window.setTimeout(a, ma);
  9726. break;
  9727. case 2:
  9728. this.g = window.setTimeout(this.M, this.N);
  9729. break;
  9730. case 3:
  9731. this.g = window.requestAnimationFrame(this.L);
  9732. break;
  9733. case 4:
  9734. this.g = window.setTimeout(this.J, 0)
  9735. }
  9736.  
  9737. */
  9738. const startFnHandler = {
  9739. get(target, prop, receiver) {
  9740. if (prop === '$$12377$$') return true;
  9741. if (prop === '$$12378$$') return target;
  9742.  
  9743. // console.log('get',prop)
  9744. return target[prop]
  9745. },
  9746. set(target, prop, value, receiver) {
  9747. // console.log('set', prop, value)
  9748.  
  9749.  
  9750. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  9751. if (value === 12373 && _fnSelectorProp) {
  9752.  
  9753. const schedulerTypeSelection = target[_fnSelectorProp];
  9754. const timerIdProp = prop;
  9755.  
  9756. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  9757. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  9758. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  9759. // schedulerInstancePropOfTimerId = timerIdProp || '';
  9760. // }
  9761.  
  9762. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  9763. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  9764. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  9765. // rare
  9766. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9767. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  9768. // often
  9769. if ((FIX_schedulerInstanceInstance & 4)) {
  9770. const f = requestingArgs[0];
  9771. const tir = ++mzt;
  9772. nextBrowserTick_(() => {
  9773. if (target[timerIdProp] === -tir) f();
  9774. });
  9775. target[_fnSelectorProp] = 940;
  9776. target[timerIdProp] = -tir;
  9777. } else {
  9778. const f = requestingArgs[0];
  9779. const tir = ++mzt;
  9780. Promise.resolve().then(() => {
  9781. if (target[timerIdProp] === -tir) f();
  9782. });
  9783. target[_fnSelectorProp] = 930;
  9784. target[timerIdProp] = -tir;
  9785. }
  9786. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  9787. // often
  9788. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  9789. cm.data = (cm.data & 7) + 1;
  9790. let renderFn = requestingArgs[0];
  9791. const resolveRendering_ = () => {
  9792. const renderFn_ = renderFn;
  9793. if (renderFn_) {
  9794. renderFn = null;
  9795. renderFn_();
  9796. }
  9797. };
  9798. resolveRendering = resolveRendering_;
  9799. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  9800. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  9801.  
  9802. // cm.data = (cm.data & 7) + 1;
  9803. // target[timerIdProp] = Math.random();
  9804.  
  9805. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  9806.  
  9807. cm.data = (cm.data & 7) + 1;
  9808.  
  9809. let renderFn = requestingArgs[0];
  9810. const resolveRendering_ = () => {
  9811. const renderFn_ = renderFn;
  9812. if (renderFn_) {
  9813. renderFn = null;
  9814. renderFn_();
  9815. }
  9816. };
  9817. resolveRendering = resolveRendering_;
  9818.  
  9819. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  9820.  
  9821.  
  9822. } else {
  9823. if (requestingFn === requestIdleCallback) {
  9824. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  9825. } else {
  9826. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  9827. }
  9828. }
  9829. } else {
  9830. target[_fnSelectorProp] = 0;
  9831. target[timerIdProp] = 0;
  9832. }
  9833. } else {
  9834. target[prop] = value;
  9835. }
  9836. return true;
  9837. }
  9838. };
  9839.  
  9840. let startBusy = false;
  9841. schedulerInstanceInstance_.start = function () {
  9842. if (startBusy) return;
  9843. startBusy = true;
  9844. try {
  9845. mkFns[0] = window.requestAnimationFrame;
  9846. mkFns[1] = window.setInterval;
  9847. mkFns[2] = window.setTimeout;
  9848. mkFns[3] = window.requestIdleCallback;
  9849. const tThis = this['$$12378$$'] || this;
  9850. window.requestAnimationFrame = fakeFns[0]
  9851. window.setInterval = fakeFns[1]
  9852. window.setTimeout = fakeFns[2]
  9853. window.requestIdleCallback = fakeFns[3]
  9854. _fnSelectorProp = null;
  9855. tThis.start993.call(new Proxy(tThis, startFnHandler));
  9856. _fnSelectorProp = null;
  9857. window.requestAnimationFrame = mkFns[0];
  9858. window.setInterval = mkFns[1];
  9859. window.setTimeout = mkFns[2];
  9860. window.requestIdleCallback = mkFns[3];
  9861. } catch (e) {
  9862. console.warn(e);
  9863. }
  9864. startBusy = false;
  9865. }
  9866.  
  9867. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  9868.  
  9869. }
  9870. })();
  9871.  
  9872. FIX_yt_player && !isChatRoomURL && (async () => {
  9873.  
  9874. const fOption = 1 | 2 | 4;
  9875.  
  9876. const _yt_player = await _yt_player_observable.obtain();
  9877.  
  9878. if (!_yt_player || typeof _yt_player !== 'object') return;
  9879.  
  9880. const g = _yt_player;
  9881. let k;
  9882.  
  9883. if (fOption & 1) {
  9884.  
  9885. // rAf scheduling
  9886.  
  9887. const keyZqOu = getZqOu(_yt_player);
  9888. if (!keyZqOu) {
  9889. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  9890. return;
  9891. }
  9892. k = keyZqOu
  9893.  
  9894. const gk = g[k];
  9895. if (typeof gk !== 'function') {
  9896. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  9897. return;
  9898. }
  9899. const gkp = gk.prototype;
  9900.  
  9901. const dummyObject = new gk;
  9902. const nilFunc = () => { };
  9903.  
  9904. const nilObj = {};
  9905.  
  9906. // console.log(1111111111)
  9907.  
  9908. let keyBoolD = '';
  9909. let keyWindow = '';
  9910. let keyFuncC = '';
  9911. let keyCidj = '';
  9912.  
  9913. for (const [t, y] of Object.entries(dummyObject)) {
  9914. if (y instanceof Window) keyWindow = t;
  9915. }
  9916.  
  9917. const dummyObjectProxyHandler = {
  9918. get(target, prop) {
  9919. let v = target[prop]
  9920. if (v instanceof Window && !keyWindow) {
  9921. keyWindow = t;
  9922. }
  9923. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  9924. if (prop === keyWindow) y = {
  9925. requestAnimationFrame(f) {
  9926. return 3;
  9927. },
  9928. cancelAnimationFrame() {
  9929.  
  9930. }
  9931. }
  9932. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  9933. keyFuncC = prop;
  9934. }
  9935. // console.log('[get]', prop, typeof target[prop])
  9936.  
  9937.  
  9938. return y;
  9939. },
  9940. set(target, prop, value) {
  9941.  
  9942. if (typeof value === 'boolean' && !keyBoolD) {
  9943. keyBoolD = prop;
  9944. }
  9945. if (typeof value === 'number' && !keyCidj && value >= 2) {
  9946. keyCidj = prop;
  9947. }
  9948.  
  9949. // console.log('[set]', prop, value)
  9950. target[prop] = value;
  9951.  
  9952. return true;
  9953. }
  9954. };
  9955.  
  9956. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  9957.  
  9958. // console.log('gkp.start',gkp.start);
  9959. // console.log('gkp.stop',gkp.stop);
  9960. gkp._activation = false;
  9961.  
  9962. gkp.start = function () {
  9963. // p59 || console.log(12100)
  9964. if (!this._activation) {
  9965. this._activation = true;
  9966. foregroundPromiseFn().then(() => {
  9967. this._activation = false;
  9968. if (this[keyCidj]) {
  9969. Promise.resolve().then(this[keyFuncC]);
  9970. }
  9971. });
  9972. }
  9973. this[keyCidj] = 1;
  9974. this[keyBoolD] = true;
  9975. };
  9976.  
  9977. gkp.stop = function () {
  9978. this[keyCidj] = null;
  9979. };
  9980.  
  9981.  
  9982. /*
  9983. g[k].start = function() {
  9984. this.stop();
  9985. this.D = true;
  9986. var a = requestAnimationFrame
  9987. , b = cancelAnimationFrame;
  9988. this.j = a.call(this.B, this.C)
  9989. }
  9990. ;
  9991. g[k].stop = function() {
  9992. if (this.isActive()) {
  9993. var a = requestAnimationFrame
  9994. , b = cancelAnimationFrame;
  9995. b.call(this.B, this.j)
  9996. }
  9997. this.j = null
  9998. }
  9999. */
  10000. }
  10001.  
  10002. if (fOption & 2) {
  10003. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  10004.  
  10005. if (keyzo) {
  10006.  
  10007. k = keyzo;
  10008.  
  10009. const attrUpdateFn = g[k];
  10010. // console.log(5992, attrUpdateFn)
  10011. g['$$original$$' + k] = attrUpdateFn;
  10012. const zoTransform = async (a, c) => {
  10013.  
  10014. let transformType = '';
  10015. let transformValue = 0;
  10016. let transformUnit = '';
  10017. let transformTypeI = 0;
  10018.  
  10019. const aStyle = a.style;
  10020.  
  10021. let cType = 0;
  10022.  
  10023. const cl = c.length;
  10024.  
  10025. if (cl >= 8) {
  10026. // scale(1)
  10027. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  10028. cType = 1;
  10029. let t = c.charCodeAt(5);
  10030. if (t === 88 || t === 120) cType = 1 | 4;
  10031. if (t === 89 || t === 121) cType = 1 | 8;
  10032. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  10033. cType = 2;
  10034. let t = c.charCodeAt(9);
  10035. if (t === 88 || t === 120) cType = 2 | 4;
  10036. if (t === 89 || t === 121) cType = 2 | 8;
  10037. }
  10038. let w = 0;
  10039. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  10040. let p = c.substring(7, cl - 1);
  10041. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10042. if (typeof q === 'number' && !isNaNx(q)) {
  10043. transformType = w === 1 ? 'scaleX' : 'scaleY';
  10044. transformValue = q;
  10045. transformUnit = '';
  10046. transformTypeI = 1;
  10047. } else {
  10048. cType = 256;
  10049. }
  10050. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  10051. if (c.endsWith('px)')) {
  10052. let p = c.substring(11, cl - 3);
  10053. let q = p.length >= 1 ? parseFloat(p) : NaN;
  10054. if (typeof q === 'number' && !isNaNx(q)) {
  10055. transformType = w === 1 ? 'translateX' : 'translateY';
  10056. transformValue = q;
  10057. transformUnit = 'px';
  10058. transformTypeI = 2;
  10059. } else if (p === 'NaN') {
  10060. return;
  10061. }
  10062. } else {
  10063. cType = 256;
  10064. }
  10065. } else if (cType > 0) {
  10066. cType = 256;
  10067. }
  10068. }
  10069.  
  10070.  
  10071. if (cType === 256) {
  10072. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  10073. }
  10074.  
  10075. if (transformTypeI === 1) {
  10076. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  10077. const vz = toFixed2(q, 3);
  10078. c = `${transformType}(${vz})`;
  10079. const cv = aStyle.transform;
  10080. if (c === cv) return;
  10081. aStyle.transform = c;
  10082. } else if (transformTypeI === 2) {
  10083. const q = transformValue;
  10084. const vz = toFixed2(q, 1);
  10085. c = `${transformType}(${vz}${transformUnit})`;
  10086. const cv = aStyle.transform;
  10087. if (c === cv) return;
  10088. aStyle.transform = c;
  10089. } else { // eg empty
  10090. const cv = aStyle.transform;
  10091. if (!c && !cv) return;
  10092. else if (c === cv) return;
  10093. aStyle.transform = c;
  10094. }
  10095.  
  10096. };
  10097.  
  10098. const elmTransformTemp = new WeakMap();
  10099. const elmPropTemps = {
  10100. 'display': new WeakMap(),
  10101. 'width': new WeakMap(),
  10102. 'height': new WeakMap(),
  10103. 'outlineWidth': new WeakMap(),
  10104. 'position': new WeakMap(),
  10105. 'padding': new WeakMap(),
  10106. "cssText": new WeakMap(),
  10107. "right": new WeakMap(),
  10108. "left": new WeakMap(),
  10109. "top": new WeakMap(),
  10110. "bottom": new WeakMap(),
  10111. "transitionDelay": new WeakMap(),
  10112. "marginLeft": new WeakMap(),
  10113. "marginTop": new WeakMap(),
  10114. "marginRight": new WeakMap(),
  10115. "marginBottom": new WeakMap(),
  10116. }
  10117.  
  10118. const ns5 = Symbol();
  10119. const nextModify = (a, c, m, f, immediate) => {
  10120. const a_ = a;
  10121. const m_ = m;
  10122. const noKey = !m_.has(a_);
  10123. if (immediate || noKey) {
  10124. m_.set(a_, ns5);
  10125. f(a_, c);
  10126. noKey && nextBrowserTick_(() => {
  10127. const d = m_.get(a_);
  10128. if (d === undefined) return;
  10129. m_.delete(a_);
  10130. if (d !== ns5) f(a_, d);
  10131. });
  10132. } else {
  10133. m_.set(a_, c);
  10134. }
  10135. };
  10136.  
  10137. const set66 = new Set();
  10138. const log77 = new Map();
  10139. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  10140.  
  10141. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  10142.  
  10143. // console.log(140000, a, b, c);
  10144. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  10145. const num = c;
  10146. c = `${num}`;
  10147. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  10148. }
  10149.  
  10150. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  10151.  
  10152. let elmPropTemp = null;
  10153.  
  10154. if (b === "transform") {
  10155. // div.ytp-hover-progress.ytp-hover-progress-light
  10156. // div.ytp-play-progress.ytp-swatch-background-color
  10157.  
  10158. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  10159. return;
  10160.  
  10161. } else if (elmPropTemp = elmPropTemps[b]) {
  10162.  
  10163. // if (c.length > 5 && c.includes('.')) {
  10164. // console.log(123213, c)
  10165. // }
  10166.  
  10167. const b_ = b;
  10168. nextModify(a, c, elmPropTemp, (a, c) => {
  10169. const style = a.style;
  10170. const cv = style[b_];
  10171. if (!cv && !c) return;
  10172. if (cv === c) return;
  10173. style[b_] = c;
  10174. }, immediateChange);
  10175. return;
  10176.  
  10177. } else if (b === "outline-width") {
  10178.  
  10179. const b_ = 'outlineWidth';
  10180. elmPropTemp = elmPropTemps[b_];
  10181. nextModify(a, c, elmPropTemp, (a, c) => {
  10182. const style = a.style;
  10183. const cv = style[b_];
  10184. if (!cv && !c) return;
  10185. if (cv === c) return;
  10186. style[b_] = c;
  10187. }, immediateChange);
  10188. return;
  10189.  
  10190. } else if (b === 'maxWidth' || b === 'maxHeight') {
  10191. // I think these can be directly assigned.
  10192.  
  10193. const b_ = b;
  10194. const style = a.style;
  10195. const cv = style[b_];
  10196. if (!cv && !c) return;
  10197. if (cv === c) return;
  10198. style[b_] = c;
  10199. return;
  10200.  
  10201. } else {
  10202. // if(immediate && elmPropTemps[b]){
  10203. // console.log(5191, b)
  10204. // }
  10205. // caption-window
  10206. // margin-left max-height max-width font-family fill color font-size background white-space margin
  10207. // text-align background-color
  10208. // console.log(27304, a, b, c)
  10209. if (!set66.has(b)) {
  10210. set66.add(b);
  10211. nextBrowserTick_(() => {
  10212. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  10213. console.log(27304, a, b, c)
  10214. }
  10215. })
  10216. }
  10217. }
  10218.  
  10219. attrUpdateFn.call(this, a, b, c);
  10220. return;
  10221. } else if (typeof (b || 0) === 'object') {
  10222.  
  10223. // this is to fix caption positioning
  10224. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  10225. const immediate = (a.id || 0).length > 14;
  10226. for (const [k, v] of Object.entries(b)) {
  10227. modifiedFn.call(this, a, k, v, immediate);
  10228. }
  10229.  
  10230. } else {
  10231.  
  10232. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  10233. // ytp-ad-timed-pie-countdown-inner
  10234.  
  10235. if (typeof b === 'string') {
  10236.  
  10237. let m = log77.get(b);
  10238. if (!m) {
  10239. m = [];
  10240. console.log('attrUpdateFn.debug.27304', m);
  10241. log77.set(b, m);
  10242. }
  10243. m.push([a, b, c]);
  10244.  
  10245. } else {
  10246. console.log('attrUpdateFn.debug.27306', a, b, c);
  10247. }
  10248.  
  10249. attrUpdateFn.call(this, a, b, c);
  10250. return;
  10251. }
  10252.  
  10253. // console.log(130000, a, b, c);
  10254.  
  10255. };
  10256. g[k] = modifiedFn;
  10257.  
  10258.  
  10259. /*
  10260.  
  10261. g.zo = function(a, b, c) {
  10262. if ("string" === typeof b)
  10263. (b = yo(a, b)) && (a.style[b] = c);
  10264. else
  10265. for (var d in b) {
  10266. c = a;
  10267. var e = b[d]
  10268. , f = yo(c, d);
  10269. f && (c.style[f] = e)
  10270. }
  10271. }
  10272.  
  10273.  
  10274. */
  10275.  
  10276.  
  10277. }
  10278. }
  10279.  
  10280. if (fOption & 4) {
  10281. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  10282.  
  10283. if (keyuG) {
  10284.  
  10285. k = keyuG;
  10286.  
  10287. const gk = g[k];
  10288. const gkp = gk.prototype;
  10289.  
  10290.  
  10291. /** @type { Map<string, WeakMap<any, any>> } */
  10292. const ntLogs = new Map();
  10293.  
  10294. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  10295.  
  10296. gkp.updateValue31 = gkp.updateValue;
  10297. gkp.updateValue = function (a, b) {
  10298. if (typeof a !== 'string') return this.updateValue31(a, b);
  10299.  
  10300. const element = this.element;
  10301. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  10302.  
  10303. let ntLog = ntLogs.get(a);
  10304. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  10305.  
  10306. let cache = ntLog.get(element);
  10307. if (cache && cache.value === b) {
  10308. return;
  10309. }
  10310. if (!cache) {
  10311. this.__oldValueByUpdateValue__ = null;
  10312. ntLog.set(element, cache = { value: b });
  10313. } else {
  10314. this.__oldValueByUpdateValue__ = cache.value;
  10315. cache.value = b;
  10316. }
  10317.  
  10318. return this.updateValue31(a, b);
  10319. }
  10320.  
  10321. /*
  10322. g.k.update = function(a) {
  10323. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  10324. c = c.value,
  10325. this.updateValue(c, a[c])
  10326. }
  10327. ;
  10328. g.k.updateValue = function(a, b) {
  10329. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  10330. }
  10331. */
  10332.  
  10333. }
  10334.  
  10335.  
  10336. }
  10337. }
  10338.  
  10339.  
  10340.  
  10341. })();
  10342.  
  10343. FIX_yt_player && !isChatRoomURL && (async () => {
  10344. // timer scheduling
  10345.  
  10346. const _yt_player = await _yt_player_observable.obtain();
  10347.  
  10348. if (!_yt_player || typeof _yt_player !== 'object') return;
  10349.  
  10350. let keyZqQu = getZqQu(_yt_player);
  10351.  
  10352. if (!keyZqQu) return;
  10353.  
  10354. const g = _yt_player
  10355. let k = keyZqQu
  10356.  
  10357. const gk = g[k];
  10358. if (typeof gk !== 'function') return;
  10359. const gkp = gk.prototype;
  10360.  
  10361. const extractKeysZqQu = () => {
  10362.  
  10363.  
  10364. let _keyeC = '';
  10365. try {
  10366. gkp.stop.call(new Proxy({
  10367. isActive: () => { }
  10368. }, {
  10369. set(target, prop, value) {
  10370. if (value === 0) _keyeC = prop;
  10371. return true;
  10372. }
  10373. }));
  10374. } catch (e) { }
  10375. if (!_keyeC) return;
  10376. const keyeC = _keyeC;
  10377.  
  10378. let keyC = ''; // this.C = this.ST.bind(this)
  10379. let keyhj = ''; // 1000ms
  10380. try {
  10381. gkp.start.call(new Proxy({
  10382. stop: () => { },
  10383. [keyeC]: 0,
  10384. }, {
  10385. get(target, prop) {
  10386. if (prop in target) return target[prop];
  10387. if (!keyC) {
  10388. keyC = prop;
  10389. return null; // throw error
  10390. }
  10391. else if (!keyhj) {
  10392. keyhj = prop;
  10393. }
  10394.  
  10395. }
  10396. }));
  10397. } catch (e) {
  10398. if (!keyC || !keyhj) {
  10399. console.log(e)
  10400. }
  10401. }
  10402.  
  10403. if (!keyC || !keyhj) return;
  10404. let keyST = '';
  10405. let keyj = '';
  10406. let keyB = '';
  10407. let keyxa = '';
  10408.  
  10409. const possibleKs = new Set();
  10410.  
  10411. for (const [k, v] of Object.entries(gkp)) {
  10412. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  10413. continue;
  10414. }
  10415. if (typeof v === 'function') {
  10416. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  10417. if (m) {
  10418. keyST = k;
  10419. keyj = m[1];
  10420. keyB = m[2];
  10421. } else {
  10422. possibleKs.add(k);
  10423. }
  10424. }
  10425. }
  10426.  
  10427. if (!keyST || !keyj || !keyB) return;
  10428.  
  10429. for (const k of possibleKs) {
  10430. if (k === keyST || k === keyj || k === keyB) {
  10431. continue;
  10432. }
  10433. const v = gkp[k];
  10434. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  10435. keyxa = k;
  10436. }
  10437. }
  10438.  
  10439. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  10440.  
  10441. }
  10442.  
  10443. const keys = extractKeysZqQu();
  10444. if (!keys || !keys.length) return;
  10445. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  10446.  
  10447. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  10448.  
  10449. let disposeKeys = null;
  10450.  
  10451. gkp[keyxa] = function () {
  10452. // dispose
  10453. if (!disposeKeys) {
  10454. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  10455. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  10456. const t = typeof this[key];
  10457. return t === 'undefined' || t === 'object'
  10458. }
  10459. return false;
  10460. });
  10461. }
  10462. for (const key of disposeKeys) {
  10463. const v = this[key];
  10464. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  10465. }
  10466. if (this[keyeC] > 0) this.stop();
  10467. this[keyj] = null;
  10468. this[keyB] = null;
  10469. };
  10470.  
  10471. gkp.start = function (a) {
  10472. if (this[keyeC] > 0) this.stop();
  10473. const delay = void 0 !== a ? a : this[keyhj];
  10474. this[keyeC] = window.setTimeout(this[keyC], delay);
  10475. };
  10476. gkp.stop = function () {
  10477. if (this[keyeC] > 0) {
  10478. window.clearTimeout(this[keyeC]);
  10479. this[keyeC] = 0;
  10480. }
  10481. };
  10482.  
  10483. gkp.isActive = function () {
  10484. return this[keyeC] > 0;
  10485. };
  10486.  
  10487. gkp[keyST] = function () {
  10488. this.stop(); // this[keyeC] = 0;
  10489. const fn = this[keyj];
  10490. const obj = this[keyB];
  10491. let skip = false;
  10492. if (!fn) skip = true;
  10493. else if (IGNORE_bufferhealth_CHECK && obj) {
  10494. let m;
  10495. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  10496. if (m.has("bufferhealth")) skip = true;
  10497. }
  10498. }
  10499. if (!skip) {
  10500. fn.call(obj);
  10501. }
  10502. };
  10503.  
  10504.  
  10505.  
  10506.  
  10507. /*
  10508.  
  10509. g.k.eC = 0;
  10510. g.k.xa = function() {
  10511. g.Qu.Vf.xa.call(this);
  10512. this.stop();
  10513. delete this.j;
  10514. delete this.B
  10515. }
  10516. ;
  10517. g.k.start = function(a) {
  10518. this.stop();
  10519. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  10520. }
  10521. ;
  10522. g.k.stop = function() {
  10523. this.isActive() && g.Sa.clearTimeout(this.eC);
  10524. this.eC = 0
  10525. }
  10526. ;
  10527. g.k.isActive = function() {
  10528. return 0 != this.eC
  10529. }
  10530. ;
  10531. g.k.ST = function() {
  10532. this.eC = 0;
  10533. this.j && this.j.call(this.B)
  10534. }
  10535. ;
  10536. */
  10537.  
  10538.  
  10539.  
  10540.  
  10541. })();
  10542.  
  10543. FIX_Animation_n_timeline && (async () => {
  10544.  
  10545. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  10546.  
  10547. if (!timeline || !Animation) return;
  10548.  
  10549. const animationsFix = (timeline) => {
  10550. const animations = (timeline || 0)._animations || 0;
  10551. const c = animations[0];
  10552. if (c) {
  10553. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  10554. animations.shift(); // keep animating but no looping
  10555. // c.effect.remove();
  10556. }
  10557. }
  10558. }
  10559.  
  10560. const aniProto = Animation.prototype;
  10561. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  10562.  
  10563. const getXroto = (x) => {
  10564. try {
  10565. return x.__proto__;
  10566. } catch (e) { }
  10567. return null;
  10568. }
  10569. const timProto = getXroto(timeline);
  10570. if (!timProto) return;
  10571. if (
  10572. (
  10573. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  10574. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  10575. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  10576. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  10577. )
  10578.  
  10579. ) {
  10580.  
  10581. timProto.nofCQ = 1;
  10582. aniProto.nofYH = 1;
  10583.  
  10584. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  10585.  
  10586.  
  10587. /*
  10588. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10589. return c._updatePromises();
  10590. });
  10591. */
  10592.  
  10593. const p = Array.prototype.filter;
  10594.  
  10595. let res = null;
  10596. Array.prototype.filter = function () {
  10597.  
  10598. res = this;
  10599. return this;
  10600.  
  10601. };
  10602.  
  10603. _updateAnimationsPromises.call({});
  10604.  
  10605. Array.prototype.filter = p;
  10606.  
  10607. if (res && typeof res.length === 'number') {
  10608. /** @type {any[]} */
  10609. const _res = res;
  10610. return _res;
  10611. }
  10612.  
  10613.  
  10614. return null;
  10615.  
  10616.  
  10617.  
  10618.  
  10619. })(timProto._updateAnimationsPromises);
  10620.  
  10621. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  10622.  
  10623. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  10624.  
  10625. aniProto._updatePromises31 = aniProto._updatePromises;
  10626.  
  10627. /*
  10628. aniProto._updatePromises = function(){
  10629. console.log('eff',this._oldPlayState, this.playState)
  10630. return this._updatePromises31.apply(this, arguments)
  10631. }
  10632. */
  10633.  
  10634. aniProto._updatePromises = function () {
  10635. var oldPlayState = this._oldPlayState;
  10636. var newPlayState = this.playState;
  10637. // console.log('ett', oldPlayState, newPlayState)
  10638. if (newPlayState !== oldPlayState) {
  10639. this._oldPlayState = newPlayState;
  10640. if (this._readyPromise) {
  10641. if ("idle" == newPlayState) {
  10642. this._rejectReadyPromise();
  10643. this._readyPromise = void 0;
  10644. } else if ("pending" == oldPlayState) {
  10645. this._resolveReadyPromise();
  10646. } else if ("pending" == newPlayState) {
  10647. this._readyPromise = void 0;
  10648. }
  10649. }
  10650. if (this._finishedPromise) {
  10651. if ("idle" == newPlayState) {
  10652. this._rejectFinishedPromise();
  10653. this._finishedPromise = void 0;
  10654. } else if ("finished" == newPlayState) {
  10655. this._resolveFinishedPromise();
  10656. } else if ("finished" == oldPlayState) {
  10657. this._finishedPromise = void 0;
  10658. }
  10659. }
  10660. }
  10661. return this._readyPromise || this._finishedPromise;
  10662. };
  10663.  
  10664.  
  10665. let restartWebAnimationsNextTickFlag = false;
  10666.  
  10667. const looperMethodT = () => {
  10668.  
  10669. const runnerFn = (hRes) => {
  10670. var b = timeline;
  10671. b.currentTime = hRes;
  10672. b._discardAnimations();
  10673. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  10674. if (0 == b._animations.length) {
  10675. restartWebAnimationsNextTickFlag = false;
  10676. } else {
  10677. getRafPromise().then(runnerFn);
  10678. }
  10679. }
  10680.  
  10681. const restartWebAnimationsNextTick = () => {
  10682. if (!restartWebAnimationsNextTickFlag) {
  10683. restartWebAnimationsNextTickFlag = true;
  10684. getRafPromise().then(runnerFn);
  10685. }
  10686. }
  10687.  
  10688. return { restartWebAnimationsNextTick }
  10689. };
  10690.  
  10691.  
  10692. const looperMethodN = () => {
  10693.  
  10694. const acs = document.createElement('a-f');
  10695. acs.id = 'a-f';
  10696.  
  10697. if (!document.getElementById('afscript')) {
  10698. const style = document.createElement('style');
  10699. style.id = 'afscript';
  10700. style.textContent = `
  10701. @keyFrames aF1 {
  10702. 0% {
  10703. order: 0;
  10704. }
  10705. 100% {
  10706. order: 1;
  10707. }
  10708. }
  10709. #a-f[id] {
  10710. visibility: collapse !important;
  10711. position: fixed !important;
  10712. display: block !important;
  10713. top: -100px !important;
  10714. left: -100px !important;
  10715. margin:0 !important;
  10716. padding:0 !important;
  10717. outline:0 !important;
  10718. border:0 !important;
  10719. z-index:-1 !important;
  10720. width: 0px !important;
  10721. height: 0px !important;
  10722. contain: strict !important;
  10723. pointer-events: none !important;
  10724. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  10725. }
  10726. `;
  10727. (document.head || document.documentElement).appendChild(style);
  10728. }
  10729.  
  10730. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  10731.  
  10732. const _onanimationiteration = function (evt) {
  10733. const hRes = evt.timeStamp;
  10734. var b = timeline;
  10735. b.currentTime = hRes;
  10736. b._discardAnimations();
  10737. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  10738. if (0 == b._animations.length) {
  10739. restartWebAnimationsNextTickFlag = false;
  10740. acs.onanimationiteration = null;
  10741. } else {
  10742. acs.onanimationiteration = _onanimationiteration;
  10743. }
  10744.  
  10745. }
  10746.  
  10747.  
  10748.  
  10749. const restartWebAnimationsNextTick = () => {
  10750. if (!restartWebAnimationsNextTickFlag) {
  10751. restartWebAnimationsNextTickFlag = true;
  10752. acs.onanimationiteration = _onanimationiteration;
  10753.  
  10754. }
  10755. }
  10756.  
  10757. return { restartWebAnimationsNextTick }
  10758. };
  10759.  
  10760.  
  10761.  
  10762. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  10763.  
  10764.  
  10765. // console.log(571, timProto);
  10766. timProto._play = function (c) {
  10767. c = new Animation(c, this);
  10768. this._animations.push(c);
  10769. restartWebAnimationsNextTick();
  10770. c._updatePromises();
  10771. c._animation.play();
  10772. c._updatePromises();
  10773. return c
  10774. }
  10775.  
  10776. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  10777. originalAnimationsWithPromises.length = 0;
  10778. originalAnimationsWithPromises.push = null;
  10779. originalAnimationsWithPromises.splice = null;
  10780. originalAnimationsWithPromises.slice = null;
  10781. originalAnimationsWithPromises.indexOf = null;
  10782. originalAnimationsWithPromises.unshift = null;
  10783. originalAnimationsWithPromises.shift = null;
  10784. originalAnimationsWithPromises.pop = null;
  10785. originalAnimationsWithPromises.filter = null;
  10786. originalAnimationsWithPromises.forEach = null;
  10787. originalAnimationsWithPromises.map = null;
  10788.  
  10789.  
  10790. const _updateAnimationsPromises = () => {
  10791. animationsWithPromisesMap.forEach(c => {
  10792. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  10793. });
  10794. /*
  10795. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  10796. return c._updatePromises();
  10797. });
  10798. */
  10799. }
  10800.  
  10801. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  10802.  
  10803. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  10804.  
  10805. delete timProto._updateAnimationsPromises;
  10806. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  10807. get() {
  10808. if (animationsWithPromisesMap.size === 0) return nilFn;
  10809. return _updateAnimationsPromises;
  10810. },
  10811. set(nv) {
  10812. delete this._updateAnimationsPromises;
  10813. this._updateAnimationsPromises = nv;
  10814. },
  10815. enumerable: true,
  10816. configurable: true,
  10817. });
  10818.  
  10819.  
  10820. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  10821. aniProto.__finished_native_get__ = pdFinished.get;
  10822. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  10823.  
  10824.  
  10825. Object.defineProperty(aniProto, 'finished', {
  10826. get() {
  10827. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10828. this._finishedPromise = new Promise((resolve, reject) => {
  10829. this._resolveFinishedPromise = function () {
  10830. resolve(this)
  10831. };
  10832. this._rejectFinishedPromise = function () {
  10833. reject({
  10834. type: DOMException.ABORT_ERR,
  10835. name: "AbortError"
  10836. })
  10837. };
  10838. }),
  10839. "finished" == this.playState && this._resolveFinishedPromise());
  10840. return this._finishedPromise
  10841. },
  10842. set: undefined,
  10843. enumerable: true,
  10844. configurable: true
  10845. });
  10846.  
  10847. }
  10848.  
  10849.  
  10850.  
  10851. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  10852. aniProto.__ready_native_get__ = pdReady.get;
  10853. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  10854.  
  10855. Object.defineProperty(aniProto, 'ready', {
  10856. get() {
  10857. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  10858. this._readyPromise = new Promise((resolve, reject) => {
  10859. this._resolveReadyPromise = function () {
  10860. resolve(this)
  10861. };
  10862. this._rejectReadyPromise = function () {
  10863. reject({
  10864. type: DOMException.ABORT_ERR,
  10865. name: "AbortError"
  10866. })
  10867. };
  10868. }),
  10869. "pending" !== this.playState && this._resolveReadyPromise());
  10870. return this._readyPromise
  10871. },
  10872. set: undefined,
  10873. enumerable: true,
  10874. configurable: true
  10875. });
  10876.  
  10877. }
  10878.  
  10879.  
  10880. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  10881.  
  10882. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  10883. const _rebuildUnderlyingAnimation = function () {
  10884. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  10885. this.effect && this.effect._onsample && (this.effect._onsample = null);
  10886. return this._rebuildUnderlyingAnimation21();
  10887. }
  10888. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  10889. // delete aniProto._rebuildUnderlyingAnimation;
  10890. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  10891. // get() {
  10892. // if (isNaN(this._sequenceNumber)) return nilFn;
  10893. // return this._rebuildUnderlyingAnimation21;
  10894. // },
  10895. // set(nv) {
  10896. // delete this._rebuildUnderlyingAnimation;
  10897. // this._rebuildUnderlyingAnimation = nv;
  10898. // },
  10899. // enumerable: true,
  10900. // configurable: true
  10901. // });
  10902. }
  10903.  
  10904.  
  10905. /*
  10906.  
  10907.  
  10908. function f(c) {
  10909. var b = v.timeline;
  10910. b.currentTime = c;
  10911. b._discardAnimations();
  10912. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  10913. }
  10914. var h = window.requestAnimationFrame;
  10915. window.requestAnimationFrame = function(c) {
  10916. return h(function(b) {
  10917. v.timeline._updateAnimationsPromises();
  10918. c(b);
  10919. v.timeline._updateAnimationsPromises()
  10920. })
  10921. }
  10922. ;
  10923. v.AnimationTimeline = function() {
  10924. this._animations = [];
  10925. this.currentTime = void 0
  10926. }
  10927. ;
  10928. v.AnimationTimeline.prototype = {
  10929. getAnimations: function() {
  10930. this._discardAnimations();
  10931. return this._animations.slice()
  10932. },
  10933. _updateAnimationsPromises: function() {
  10934. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  10935. return c._updatePromises()
  10936. })
  10937. },
  10938. _discardAnimations: function() {
  10939. this._updateAnimationsPromises();
  10940. this._animations = this._animations.filter(function(c) {
  10941. return "finished" != c.playState && "idle" != c.playState
  10942. })
  10943. },
  10944. _play: function(c) {
  10945. c = new v.Animation(c,this);
  10946. this._animations.push(c);
  10947. v.restartWebAnimationsNextTick();
  10948. c._updatePromises();
  10949. c._animation.play();
  10950. c._updatePromises();
  10951. return c
  10952. },
  10953. play: function(c) {
  10954. c && c.remove();
  10955. return this._play(c)
  10956. }
  10957. };
  10958. var d = !1;
  10959. v.restartWebAnimationsNextTick = function() {
  10960. d || (d = !0,
  10961. requestAnimationFrame(f))
  10962. }
  10963. ;
  10964. var a = new v.AnimationTimeline;
  10965. v.timeline = a;
  10966. try {
  10967. Object.defineProperty(window.document, "timeline", {
  10968. configurable: !0,
  10969. get: function() {
  10970. return a
  10971. }
  10972. })
  10973. } catch (c) {}
  10974. try {
  10975. window.document.timeline = a
  10976. } catch (c) {}
  10977.  
  10978. */
  10979.  
  10980.  
  10981.  
  10982. /*
  10983.  
  10984. var g = window.getComputedStyle;
  10985. Object.defineProperty(window, "getComputedStyle", {
  10986. configurable: !0,
  10987. enumerable: !0,
  10988. value: function() {
  10989. v.timeline._updateAnimationsPromises();
  10990. var e = g.apply(this, arguments);
  10991. h() && (e = g.apply(this, arguments));
  10992. v.timeline._updateAnimationsPromises();
  10993. return e
  10994. }
  10995. });
  10996.  
  10997. */
  10998.  
  10999.  
  11000.  
  11001.  
  11002. }
  11003.  
  11004.  
  11005.  
  11006.  
  11007. })();
  11008.  
  11009. !isUrlInEmbed && Promise.resolve().then(() => {
  11010.  
  11011. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11012.  
  11013.  
  11014.  
  11015. class LimitedSizeSet extends Set {
  11016. constructor(n) {
  11017. super();
  11018. this.limit = n;
  11019. }
  11020.  
  11021. add(key) {
  11022. if (!super.has(key)) {
  11023. super.add(key);
  11024. let n = super.size - this.limit;
  11025. if (n > 0) {
  11026. const iterator = super.values();
  11027. do {
  11028. const firstKey = iterator.next().value; // Get the first (oldest) key
  11029. super.delete(firstKey); // Delete the oldest key
  11030. } while (--n > 0)
  11031. }
  11032. }
  11033. }
  11034.  
  11035. removeAdd(key) {
  11036. super.delete(key);
  11037. this.add(key);
  11038. }
  11039.  
  11040. }
  11041.  
  11042. // const wk3 = new WeakMap();
  11043.  
  11044. // let mtxVideoId = '';
  11045. // let aje3 = [];
  11046. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  11047. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  11048. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  11049. let mtzCount = 0; // the key keeps unchanged
  11050. // let mjtNextMainKey = '';
  11051. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  11052. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  11053. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  11054. // let allowNoDelay322=false;
  11055. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  11056.  
  11057. let mpKey22 = ''; // last success continutation key & url pair
  11058. let mpUrl22 = ''; // last success continutation key & url pair
  11059. let mpKey21 = ''; // latest requested continutation key & url pair
  11060. let mpUrl21 = ''; // latest requested continutation key & url pair
  11061.  
  11062.  
  11063. async function sha1Hex(message) {
  11064. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  11065. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  11066. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  11067. const hashHex = hashArray
  11068. .map((b) => b.toString(16).padStart(2, "0"))
  11069. .join(""); // convert bytes to hex string
  11070. return hashHex;
  11071. }
  11072.  
  11073. async function continuationLog(a, ...args) {
  11074. let b = a;
  11075. try {
  11076. if (advanceLogging) b = await sha1Hex(a);
  11077. let c = args.map(e => {
  11078. return e === a ? b : e
  11079. });
  11080. console.log(...c)
  11081. } catch (e) { console.warn(e) }
  11082. }
  11083.  
  11084. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  11085.  
  11086.  
  11087. if (mfvContinuationRecorded.length > 0) {
  11088. for (const [e, d] of mfvContinuationRecorded) {
  11089. mfyContinuationIgnored.removeAdd(e);
  11090. }
  11091. toClearRecorded && mfvContinuationRecorded.clear();
  11092. }
  11093.  
  11094. }
  11095.  
  11096. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  11097.  
  11098. const tmProto = taskMgr.constructor.prototype;
  11099. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  11100.  
  11101. if (!tmProto.addJob714) {
  11102.  
  11103. tmProto.addJob714 = tmProto.addJob;
  11104.  
  11105. tmProto.addJob = function (a, b, c) {
  11106. const jobId = this.addJob714(a, b, c);
  11107. if (jobId > 0) {
  11108. // const ez = wk3.get(this);
  11109. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  11110. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  11111.  
  11112. this.__lastJobId863__ = jobId;
  11113. }
  11114. return jobId;
  11115. }
  11116.  
  11117. }
  11118.  
  11119. if (!tmProto.cancelJob714) {
  11120.  
  11121. tmProto.cancelJob714 = tmProto.cancelJob;
  11122.  
  11123. tmProto.cancelJob = function (a) {
  11124. const res = this.cancelJob714(a);
  11125. // if (a > 0) {
  11126. // for (const e of aje3) {
  11127. // if (e.jobId === a) e.cancelled = true;
  11128. // }
  11129. // }
  11130. return res;
  11131. }
  11132.  
  11133. }
  11134.  
  11135. }
  11136. }
  11137.  
  11138.  
  11139. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  11140.  
  11141.  
  11142. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  11143. let dummy;
  11144. let cProto;
  11145. // let mc = 4;
  11146. // dummy = await observablePromise(() => {
  11147. // const r = document.querySelector('ytd-video-primary-info-renderer');
  11148. // if (!r) return;
  11149. // let cProto = insp(r).constructor.prototype;
  11150. // if (cProto.fetchUpdatedMetadata) return r;
  11151. // if (--mc < 0) return -1;
  11152. // return null;
  11153. // }).obtain();
  11154. dummy = document.createElement('ytd-video-primary-info-renderer');
  11155. if (!(dummy instanceof Element)) return;
  11156. // console.log(5022, dummy)
  11157. cProto = insp(dummy).constructor.prototype;
  11158.  
  11159. cProto.__getEmittorTaskMgr859__ = function () {
  11160. let taskMgr_ = null;
  11161. try {
  11162. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  11163. } catch (e) { }
  11164. return taskMgr_;
  11165. }
  11166. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  11167. // console.log(1234, cProto, cProto.is)
  11168. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  11169.  
  11170. let c_;
  11171. cProto.fetchUpdatedMetadata718 = function (a) {
  11172. // delay or immediate call the actual fetchUpdatedMetadata
  11173.  
  11174. let doImmediately = false;
  11175. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  11176.  
  11177. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  11178.  
  11179. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  11180.  
  11181. doImmediately = true;
  11182.  
  11183. }
  11184.  
  11185. if (mbCId322) {
  11186. clearTimeout(mbCId322);
  11187. mbCId322 = 0;
  11188. }
  11189.  
  11190. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  11191.  
  11192. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  11193.  
  11194. mbCId322 = setTimeout(() => {
  11195. this.fetchUpdatedMetadata717(a);
  11196. }, delay);
  11197.  
  11198. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  11199.  
  11200. }
  11201.  
  11202. cProto.fetchUpdatedMetadata = function (a) {
  11203.  
  11204. if (!pageSetupState) {
  11205. if (c_) clearTimeout(c_);
  11206. c_ = setTimeout(() => {
  11207. this.fetchUpdatedMetadata718(a);
  11208. }, 300);
  11209. return;
  11210. }
  11211.  
  11212. // pageSetupState == 0
  11213.  
  11214. try {
  11215.  
  11216. mbDelayBelowNCalls++;
  11217.  
  11218. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  11219. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  11220. }
  11221.  
  11222. // console.log('fum377', a)
  11223. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  11224. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  11225. return;
  11226. }
  11227.  
  11228. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  11229. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  11230. mjtLockPreviousKey = mjtRecordedPrevKey;
  11231. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  11232. }
  11233. // mjtNextMainKey = true;
  11234. mtzlastAllowedContinuation = '';
  11235. mtzCount = 0;
  11236. // allowNoDelay322 = false;
  11237. // fetch new metadata, cancel all previous continuations
  11238. copyPreviousContiuationToIgnored374(true);
  11239. } else if (typeof a === 'string') {
  11240. const videoPlayingId = videoPlayingY.videoId;
  11241.  
  11242. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  11243.  
  11244. let update21 = !!pageSetupVideoId;
  11245. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  11246. update21 = true;
  11247. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  11248. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  11249. return;
  11250. }
  11251. if (update21) {
  11252. mpKey21 = a;
  11253. mpUrl21 = pageSetupVideoId || videoPlayingId;
  11254. }
  11255.  
  11256. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  11257. }
  11258. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  11259. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  11260. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  11261. return this.fetchUpdatedMetadata718(a);
  11262.  
  11263. } catch (e) {
  11264. console.log('Code Error in fetchUpdatedMetadata', e);
  11265. }
  11266. return this.fetchUpdatedMetadata717(a)
  11267. }
  11268. }
  11269.  
  11270.  
  11271. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  11272. // console.log(1234, cProto, cProto.is)
  11273. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  11274. let mJob = null;
  11275.  
  11276. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  11277.  
  11278. try {
  11279.  
  11280. if (arguments.length > 0) {
  11281. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  11282. }
  11283. // mfy = mfv;
  11284.  
  11285. // mjtNextMainKey = '';
  11286. mtzlastAllowedContinuation = '';
  11287. mtzCount = 0;
  11288. if (mbCId322) {
  11289. clearTimeout(mbCId322);
  11290. mbCId322 = 0;
  11291. }
  11292. mbDelayBelowNCalls = 0;
  11293. // allowNoDelay322 = false;
  11294. copyPreviousContiuationToIgnored374(true);
  11295.  
  11296. const taskMgr = this.__getEmittorTaskMgr859__();
  11297. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  11298. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  11299. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  11300. }
  11301.  
  11302. // prevent depulicated schedule job by clearing previous JobId
  11303. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  11304.  
  11305. let res;
  11306.  
  11307. if (mJob) {
  11308. const job = mJob;
  11309. mJob = null;
  11310. console.log('cancelJob', job)
  11311. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  11312. // p.cancelJob(a,b);
  11313. }
  11314.  
  11315. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  11316.  
  11317. let pza = taskMgr.__lastJobId863__;
  11318. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  11319. let pzb = taskMgr.__lastJobId863__
  11320. if (pza !== pzb) {
  11321. mJob = pzb; // set [Interval Meta Update] jobId
  11322. }
  11323.  
  11324. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  11325. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  11326. // } else {
  11327. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  11328. // }
  11329.  
  11330. return res;
  11331.  
  11332. } else {
  11333. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  11334. }
  11335.  
  11336. } catch (e) {
  11337. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  11338. }
  11339.  
  11340.  
  11341. return this.scheduleInitialUpdatedMetadataRequest717();
  11342. }
  11343. }
  11344.  
  11345.  
  11346. });
  11347.  
  11348. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  11349. let dummy;
  11350. let cProto;
  11351. dummy = ytAppDom;
  11352. if (!(dummy instanceof Element)) return;
  11353. cProto = insp(dummy).constructor.prototype;
  11354. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  11355. // console.log(1234, cProto, cProto.is);
  11356. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11357. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  11358. // console.log(123401, arguments);
  11359. // return this.handleServiceRequest717_(a, b, c, d);
  11360. // }
  11361.  
  11362. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  11363.  
  11364. // cProto.handleServiceRequest_ = function(a,b,c,d){
  11365. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11366. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  11367. // console.log('mfv', c.continuation);
  11368. // mfv.add( c.continuation);
  11369. // }
  11370. // return this.handleServiceRequest717_(a,b,c,d);
  11371. // }
  11372.  
  11373. function extraArguments322(a, b, c) {
  11374. let is = (a || 0).is;
  11375. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  11376. let continuation = (c || 0).continuation;
  11377. if (typeof is !== 'string') is = null;
  11378. if (typeof videoId !== 'string') videoId = null;
  11379. if (typeof continuation !== 'string') continuation = null;
  11380. return { is, videoId, continuation };
  11381. }
  11382.  
  11383. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  11384. cProto.sendServiceAjax_ = function (a, b, c, d) {
  11385.  
  11386. // console.log(8001)
  11387. try {
  11388.  
  11389. const { is, videoId, continuation } = extraArguments322(a, b, c);
  11390.  
  11391. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11392. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  11393. }
  11394.  
  11395. if (pageSetupVideoId && videoId && continuation) {
  11396. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11397. mfyContinuationIgnored.removeAdd(continuation);
  11398. mfvContinuationRecorded.delete(continuation);
  11399. return;
  11400. }
  11401. }
  11402.  
  11403. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11404. copyPreviousContiuationToIgnored374(false);
  11405. mfyContinuationIgnored.delete(continuation);
  11406. mfvContinuationRecorded.removeAdd(continuation);
  11407. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11408. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11409. mjtLockPreviousKey = '';
  11410. }
  11411. // if (mjtNextMainKey === continuation) {
  11412. // copyPreviousContiuationToIgnored(false);
  11413. // mfyContinuationIgnored.delete(continuation);
  11414. // mfvContinuationRecorded.add(continuation);
  11415. // }
  11416.  
  11417.  
  11418. if (mfyContinuationIgnored && continuation) {
  11419. if (mfyContinuationIgnored.has(continuation)) {
  11420. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  11421. return;
  11422. }
  11423. }
  11424.  
  11425. // console.log(59902, a?.is, b,c,d)
  11426. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  11427. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  11428. // console.log('mfv377', continuation);
  11429. mfvContinuationRecorded.add(continuation);
  11430. }
  11431.  
  11432. // if (videoId) {
  11433. // if (!pageSetupVideoId) return; // ignore page not ready
  11434. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  11435. // if (videoId !== pageSetupVideoId) {
  11436. // return;
  11437. // }
  11438. // }
  11439.  
  11440. } catch (e) {
  11441. console.log('Coding Error in sendServiceAjax_', e)
  11442. }
  11443. // console.log(8002)
  11444. // console.log(123402, arguments);
  11445. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  11446.  
  11447. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  11448. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  11449. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  11450. // get(target, prop, receiver){
  11451. // console.log('xxs99', target.videoId, mtx)
  11452. // if(prop ==='kdkw33') return 1;
  11453. // console.log(3322, prop, target)
  11454. // if(prop === 'initialDelayMs') {
  11455. // throw new Error("ABCC");
  11456. // }
  11457. // return target[prop];
  11458. // },
  11459. // set(target, prop, value, receiver){
  11460.  
  11461. // if(prop ==='kdkw33') return true;
  11462. // target[prop]=value;
  11463. // return true;
  11464. // }
  11465. // });
  11466. // }
  11467. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  11468. return this.sendServiceAjax717_(a, b, c, d);
  11469. }
  11470. }
  11471.  
  11472. function delayClearOtherKeys(lztContinuation) {
  11473. // // schedule delayed removal if mfyContinuationIgnored is not empty
  11474. // getRafPromise().then(() => {
  11475. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  11476. // // foreground page only
  11477.  
  11478. // });
  11479.  
  11480.  
  11481. if (lztContinuation !== mtzlastAllowedContinuation) return;
  11482. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  11483. if (!mfyContinuationIgnored.size) return;
  11484. if (mfyContinuationIgnored.size > 1) {
  11485. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  11486. }
  11487. mfyContinuationIgnored.forEach((value, key) => {
  11488. if (key !== lztContinuation) {
  11489. mfyContinuationIgnored.delete(key);
  11490. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  11491. }
  11492. });
  11493.  
  11494. }
  11495. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  11496. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  11497. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  11498.  
  11499. // console.log(8003)
  11500. try {
  11501.  
  11502.  
  11503. const { is, videoId, continuation } = extraArguments322(b, c, d);
  11504.  
  11505. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  11506. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  11507. }
  11508.  
  11509. if (pageSetupVideoId && videoId && continuation) {
  11510. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  11511. mfyContinuationIgnored.removeAdd(continuation);
  11512. mfvContinuationRecorded.delete(continuation);
  11513. return;
  11514. }
  11515. }
  11516.  
  11517. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  11518. copyPreviousContiuationToIgnored374(false);
  11519. mfyContinuationIgnored.delete(continuation);
  11520. mfvContinuationRecorded.removeAdd(continuation);
  11521. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  11522. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  11523. mjtLockPreviousKey = '';
  11524. }
  11525.  
  11526. // if (mjtNextMainKey === continuation) {
  11527. // copyPreviousContiuationToIgnored(false);
  11528. // mfyContinuationIgnored.delete(continuation);
  11529. // mfvContinuationRecorded.add(continuation);
  11530. // }
  11531.  
  11532. const lztContinuation = continuation;
  11533.  
  11534. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  11535. if (mfyContinuationIgnored.has(lztContinuation)) {
  11536. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  11537. return;
  11538. }
  11539. }
  11540.  
  11541. // if (videoId) {
  11542. // if (!pageSetupVideoId) return; // ignore page not ready
  11543. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  11544. // if (videoId !== pageSetupVideoId) {
  11545. // return;
  11546. // }
  11547. // }
  11548.  
  11549. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  11550. mtzlastAllowedContinuation = lztContinuation;
  11551. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  11552.  
  11553. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  11554. mjtRecordedPrevKey = lztContinuation;
  11555. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  11556. // if (mfyContinuationIgnored.size > 0) {
  11557. // delayClearOtherKeys(lztContinuation);
  11558. // }
  11559. mtzCount = 0;
  11560. // allowNoDelay322 = false;
  11561. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  11562. // repeated
  11563. if (++mtzCount > 1e9) mtzCount = 1e4;
  11564. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  11565.  
  11566. // if (mtzCount >= 3) allowNoDelay322 = true;
  11567. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  11568. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  11569. }
  11570. if (mtzCount === 5) {
  11571. mfvContinuationRecorded.clear();
  11572. mfvContinuationRecorded.add(lztContinuation);
  11573. }
  11574.  
  11575. }
  11576.  
  11577. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  11578. mpKey22 = lztContinuation;
  11579. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  11580. }
  11581.  
  11582. if (mbCId322) {
  11583. clearTimeout(mbCId322);
  11584. mbCId322 = 0;
  11585. }
  11586. } catch (e) {
  11587. console.log('Coding Error in getCancellableNetworkPromise_', e)
  11588. }
  11589.  
  11590. // console.log(8004)
  11591. // console.log(123403, arguments);
  11592. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  11593.  
  11594. // console.log(5163, a?.is,b,c,d,e);
  11595. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  11596. }
  11597. }
  11598. });
  11599.  
  11600. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  11601.  
  11602.  
  11603. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  11604.  
  11605. let dummy;
  11606. let cProto;
  11607.  
  11608. dummy = document.createElement('ytd-expander');
  11609. cProto = insp(dummy).constructor.prototype;
  11610.  
  11611. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  11612.  
  11613. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  11614. cProto.childrenChanged14 = cProto.childrenChanged;
  11615.  
  11616. cProto.initChildrenObserver = function () {
  11617. var a = this;
  11618. this.observer = new MutationObserver(function () {
  11619. a.childrenChanged()
  11620. }
  11621. );
  11622. this.observer.observe(this.content, {
  11623. subtree: !0,
  11624. childList: !0,
  11625. attributes: !0,
  11626. characterData: !0
  11627. });
  11628. this.childrenChanged()
  11629. }
  11630. ;
  11631. cProto.childrenChanged = function () {
  11632. if (this.alwaysToggleable) {
  11633. this.canToggle = this.alwaysToggleable;
  11634. } else if (!this.canToggleJobId) {
  11635. this.canToggleJobId = 1;
  11636. foregroundPromiseFn().then(() => {
  11637. this.canToggleJobId = 0;
  11638. this.calculateCanCollapse()
  11639. })
  11640. }
  11641. }
  11642.  
  11643. // console.log(cProto.initChildrenObserver)
  11644. console.debug('ytd-expander-fix-childrenChanged');
  11645.  
  11646. }
  11647.  
  11648. });
  11649.  
  11650.  
  11651. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  11652.  
  11653. let dummy;
  11654. let cProto;
  11655. dummy = document.createElement('paper-ripple');
  11656. cProto = insp(dummy).constructor.prototype;
  11657.  
  11658. if (fnIntegrity(cProto.animate, '0.74.5')) {
  11659.  
  11660.  
  11661. cProto.animate34 = cProto.animate;
  11662. cProto.animate = function () {
  11663. if (this._animating) {
  11664. var a;
  11665. const ripples = this.ripples;
  11666. for (a = 0; a < ripples.length; ++a) {
  11667. var b = ripples[a];
  11668. b.draw();
  11669. this.$.background.style.opacity = b.outerOpacity;
  11670. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  11671. }
  11672. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  11673. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  11674. foregroundPromiseFn().then(this._boundAnimate38);
  11675. } else {
  11676. this.onAnimationComplete();
  11677. }
  11678. }
  11679. }
  11680.  
  11681. console.debug('FIX_paper_ripple_animate')
  11682.  
  11683. // console.log(cProto.animate)
  11684.  
  11685. }
  11686.  
  11687. });
  11688.  
  11689. if (FIX_doIdomRender) {
  11690.  
  11691. const xsetTimeout = function (f, d) {
  11692. if (xsetTimeout.m511 === 1 && !d) {
  11693. xsetTimeout.m511 = 2;
  11694. xsetTimeout.m568 = f;
  11695. } else {
  11696. return setTimeout.apply(window, arguments)
  11697. }
  11698.  
  11699. }
  11700.  
  11701. /**
  11702. *
  11703. IGb = function(a) {
  11704. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  11705. c || (a.requestAninmationFrameResolver = new Vi,
  11706. c = a.requestAninmationFrameResolver.promise,
  11707. Da.requestAnimationFrame(function() {
  11708. var d;
  11709. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  11710. a.requestAninmationFrameResolver = null
  11711. }));
  11712. return c
  11713. }
  11714.  
  11715.  
  11716. */
  11717.  
  11718. const xrequestAnimationFrame = function (f) {
  11719. const h = `${f}`;
  11720. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  11721. let t = null;
  11722. xsetTimeout.m511 = 1;
  11723. f();
  11724. if (xsetTimeout.m511 === 2) {
  11725. t = xsetTimeout.m568;
  11726. xsetTimeout.m568 = null;
  11727. }
  11728. xsetTimeout.m511 = 0;
  11729. if (typeof t === 'function') {
  11730. foregroundPromiseFn().then(t);
  11731. }
  11732. } else if (h.includes("requestAninmationFrameResolver")) {
  11733. foregroundPromiseFn().then(f);
  11734. } else {
  11735. return requestAnimationFrame.apply(window, arguments);
  11736. }
  11737. }
  11738.  
  11739. let busy = false;
  11740. const doIdomRender = function () {
  11741.  
  11742. if (!this) return;
  11743. if (busy) {
  11744. return this.doIdomRender13(...arguments);
  11745. }
  11746. busy = true;
  11747. const { requestAnimationFrame, setTimeout } = window;
  11748. window.requestAnimationFrame = xrequestAnimationFrame;
  11749. window.setTimeout = xsetTimeout;
  11750. let r = this.doIdomRender13(...arguments);
  11751. window.requestAnimationFrame = requestAnimationFrame;
  11752. window.setTimeout = setTimeout;
  11753. busy = false;
  11754. return r;
  11755. };
  11756. 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']) {
  11757.  
  11758.  
  11759. whenCEDefined(ytTag).then(() => {
  11760.  
  11761. let dummy;
  11762. let cProto;
  11763. dummy = document.createElement(ytTag);
  11764. cProto = insp(dummy).constructor.prototype;
  11765.  
  11766. cProto.doIdomRender13 = cProto.doIdomRender;
  11767. cProto.doIdomRender = doIdomRender;
  11768.  
  11769. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  11770.  
  11771. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  11772.  
  11773.  
  11774.  
  11775. });
  11776.  
  11777. }
  11778.  
  11779. }
  11780.  
  11781.  
  11782.  
  11783.  
  11784. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  11785.  
  11786. const sMap = new Map();
  11787.  
  11788. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  11789. const ZT = function () {
  11790. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  11791. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  11792. c = b & 15,
  11793. b >>= 4,
  11794. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  11795. return a.join("")
  11796. };
  11797.  
  11798.  
  11799. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  11800.  
  11801. const popupContainer = await observablePromise(() => {
  11802. return popupContainerCollection[0];
  11803. }).obtain();
  11804.  
  11805.  
  11806. let cProto;
  11807. cProto = insp(popupContainer).constructor.prototype;
  11808.  
  11809.  
  11810. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  11811. console.log('FIX_POPUP_UNIQUE_ID NG')
  11812. return;
  11813. }
  11814. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  11815.  
  11816. cProto.handleOpenPopupAction = function (a, b) {
  11817.  
  11818. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  11819.  
  11820. a.__jOdQA__ = true;
  11821.  
  11822. try {
  11823.  
  11824. const h = this.hostElement;
  11825.  
  11826. if (h instanceof HTMLElement_) {
  11827.  
  11828. const map = h.__skme44__ = h.__skme44__ || new Map();
  11829.  
  11830. let mKey = '';
  11831. const wKey = firstObjectKey(a);
  11832. const wObj = wKey ? a[wKey] : null;
  11833. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  11834. const pKey = firstObjectKey(wObj.popup)
  11835. const pObj = pKey ? wObj.popup[pKey] : null;
  11836. let contentKey = '';
  11837. let headerKey = '';
  11838.  
  11839. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  11840. contentKey = firstObjectKey(pObj.content)
  11841. headerKey = firstObjectKey(pObj.header)
  11842. }
  11843. if (contentKey && headerKey) {
  11844.  
  11845. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  11846.  
  11847. if (mKey) {
  11848.  
  11849. if (!wObj.uniqueId) {
  11850. for (let i = 0; i < 8; i++) {
  11851. wObj.uniqueId = ZT();
  11852. if (!sMap.has(wObj.uniqueId)) break;
  11853. }
  11854. }
  11855. const oId = wObj.uniqueId
  11856.  
  11857. let nId_ = map.get(mKey);
  11858. if (!nId_) {
  11859. map.set(mKey, nId_ = oId);
  11860. }
  11861.  
  11862. wObj.uniqueId = nId_ || wObj.uniqueId;
  11863.  
  11864. const nId = wObj.uniqueId
  11865.  
  11866. sMap.set(oId, nId);
  11867. sMap.set(nId, nId);
  11868.  
  11869. wObj.uniqueId = nId;
  11870. pObj.targetId = nId;
  11871. pObj.identifier.tag = nId;
  11872.  
  11873. if (oId !== nId) {
  11874. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  11875. }
  11876.  
  11877. }
  11878.  
  11879. }
  11880. }
  11881.  
  11882. // console.log(12213, mKey, a, b, h)
  11883.  
  11884. }
  11885.  
  11886. } catch (e) {
  11887. console.warn(e)
  11888. }
  11889.  
  11890. try {
  11891.  
  11892. const results = searchNestedObject(a, (x) => {
  11893. if (typeof x === 'string' && x.length === 36) {
  11894. 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;
  11895. }
  11896. return false;
  11897. });
  11898. for (const [obj, key] of results) {
  11899. const oId = obj[key];
  11900. const nId = sMap.get(oId);
  11901. if (nId) obj[key] = nId;
  11902. }
  11903. } catch (e) {
  11904. console.warn(e)
  11905. }
  11906.  
  11907.  
  11908. }
  11909.  
  11910. return this.handleOpenPopupAction3868(...arguments)
  11911. }
  11912.  
  11913. console.log('FIX_POPUP_UNIQUE_ID OK')
  11914.  
  11915.  
  11916. });
  11917.  
  11918.  
  11919. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  11920.  
  11921. let dummy;
  11922. let cProto;
  11923. dummy = document.createElement('yt-formatted-string');
  11924. cProto = insp(dummy).constructor.prototype;
  11925.  
  11926. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  11927. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  11928. return;
  11929. }
  11930.  
  11931. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  11932. cProto.setNodeStyle_ = function (a, b) {
  11933. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  11934. return this.setNodeStyle17_(a, b);
  11935. }
  11936.  
  11937. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  11938. });
  11939.  
  11940. });
  11941.  
  11942. });
  11943.  
  11944.  
  11945.  
  11946.  
  11947. if (isMainWindow) {
  11948.  
  11949. console.groupCollapsed(
  11950. "%cYouTube JS Engine Tamer",
  11951. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  11952. );
  11953.  
  11954.  
  11955.  
  11956. console.log("Script is loaded.");
  11957. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  11958.  
  11959. console.log("This script is experimental and subject to further changes.");
  11960.  
  11961. console.log("This might boost your YouTube performance.");
  11962.  
  11963. console.log("CAUTION: This might break your YouTube.");
  11964.  
  11965.  
  11966. if (prepareLogs.length >= 1) {
  11967. console.log(" =========================================================================== ");
  11968.  
  11969. for (const msg of prepareLogs) {
  11970. console.log(msg)
  11971. }
  11972.  
  11973. console.log(" =========================================================================== ");
  11974. }
  11975.  
  11976. console.groupEnd();
  11977.  
  11978. }
  11979.  
  11980.  
  11981.  
  11982. })();