YouTube JS Engine Tamer

To enhance YouTube performance by modifying YouTube JS Engine

  1. // ==UserScript==
  2. // @name YouTube JS Engine Tamer
  3. // @name:ja YouTube JS Engine Tamer
  4. // @name:zh-TW YouTube JS Engine Tamer
  5. // @name:zh-CN YouTube JS Engine Tamer
  6. // @namespace UserScripts
  7. // @version 0.35.4
  8. // @match https://www.youtube.com/*
  9. // @match https://www.youtube-nocookie.com/embed/*
  10. // @match https://studio.youtube.com/live_chat*
  11. // @license MIT
  12. // @author CY Fung
  13. // @icon https://raw.githubusercontent.com/cyfung1031/userscript-supports/main/icons/yt-engine.png
  14. // @grant none
  15. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@c2b707e4977f77792042d4a5015fb188aae4772e/library/nextBrowserTick.min.js
  16. // @run-at document-start
  17. // @unwrap
  18. // @inject-into page
  19. // @allFrames true
  20. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  21. //
  22. // @description To enhance YouTube performance by modifying YouTube JS Engine
  23. // @description:ja YouTubeのJSエンジンを変更してパフォーマンスを向上させる
  24. // @description:zh-TW 修改 YouTube 的 JS 引擎以提升效能
  25. // @description:zh-CN 修改 YouTube 的 JS 引擎以提升性能
  26. //
  27. // ==/UserScript==
  28.  
  29. (() => {
  30.  
  31. /** @type {WeakMapConstructor} */
  32. const WeakMap = window.WeakMapOriginal || window.WeakMap;
  33.  
  34. const NATIVE_CANVAS_ANIMATION = false; // for #cinematics
  35. const FIX_schedulerInstanceInstance = 2 | 4;
  36. const FIX_yt_player = true; // DONT CHANGE
  37. const FIX_Animation_n_timeline = true;
  38. const FIX_Animation_n_timeline_cinematic = true;
  39. const FIX_ytScheduler = true;
  40. const NO_PRELOAD_GENERATE_204 = false;
  41. const ENABLE_COMPUTEDSTYLE_CACHE = true;
  42. const NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE = true;
  43. const CHANGE_appendChild = true; // discussions#236759
  44. const FIX_bind_self_this = false; // EXPERIMENTAL !!!!! this affect page switch after live ends
  45. const FIX_weakMap_weakRef = false; // EXPERIMENTAL !!!!! Might Incompatible to some userscripts (as the strong relationship is removed)
  46.  
  47. const FIX_error_many_stack = true; // should be a bug caused by uBlock Origin
  48. // const FIX_error_many_stack_keepAliveDuration = 200; // ms
  49. // const FIX_error_many_stack_keepAliveDuration_check_if_n_larger_than = 8;
  50.  
  51. const FIX_Iframe_NULL_SRC = false;
  52.  
  53. const IGNORE_bindAnimationForCustomEffect = true; // prevent `v.bindAnimationForCustomEffect(this);` being executed
  54.  
  55. const FIX_ytdExpander_childrenChanged = true;
  56. const FIX_paper_ripple_animate = true;
  57. const FIX_avoid_incorrect_video_meta = true; // omit the incorrect yt-animated-rolling-number
  58. const FIX_avoid_incorrect_video_meta_emitterBehavior = true;
  59.  
  60. const FIX_doIdomRender = true;
  61.  
  62. const FIX_Shady = true;
  63.  
  64. // [[ 2024.04.24 ]]
  65. const MODIFY_ShadyDOM_OBJ = true;
  66. // << if MODIFY_ShadyDOM_OBJ >>
  67. const WEAKREF_ShadyDOM = true;
  68. const OMIT_ShadyDOM_EXPERIMENTAL = 1 | 0; // 1 => enable; 2 => composedPath
  69. const OMIT_ShadyDOM_settings = 0 | 0 | 0; // 1: inUse; 2: handlesDynamicScoping; 4: force // {{ PRELIM TESTING PURPOSE }}
  70. // << end >>
  71.  
  72. const WEAK_REF_BINDING_CONTROL = 1 | 2; // 2 - conflict control with ShadyDOM weakref
  73.  
  74. const FIX_ytAction_ = true; // ytd-app
  75. const FIX_onVideoDataChange = false;
  76. // const FIX_onClick = true;
  77. const FIX_onStateChange = true;
  78. const FIX_onLoopRangeChange = true;
  79. // const FIX_maybeUpdateFlexibleMenu = true; // ytd-menu-renderer
  80. const FIX_VideoEVENTS_v2 = true; // true might cause bug in switching page
  81.  
  82. const ENABLE_discreteTasking = false; // removed since 0.20.0
  83. const FIX_stampDomArray_ = true; // v0.30.0
  84. const FIX_stampDomArray = FIX_stampDomArray_ && typeof WeakRef === "function" && typeof FinalizationRegistry === "function";
  85. // const stampDomArray_MemoryFix_Flag001 = false;
  86. const XFlag = true; // DON'T CHANGE
  87. const MemoryFix_Flag002 = 1 | 2 | 4 | 8 | 0 | 32 | 64 | 0 | 256;
  88. // 32 required for new stampDomArray
  89. // 128 to be tested
  90.  
  91. const FIX_perfNow = true; // history state issue; see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  92. const ENABLE_ASYNC_DISPATCHEVENT = false; // problematic
  93.  
  94. const FIX_Polymer_dom = true;
  95. const FIX_Polymer_AF = true;
  96.  
  97. const SCRIPTLET_REMOVE_PRUNE_propNeedles = true; // brave scriptlet related
  98. const DEBUG_removePrune = false; // true for DEBUG
  99.  
  100. const FIX_XHR_REQUESTING = true;
  101.  
  102. const LOG_FETCHMETA_UPDATE = false; // for DEBUG
  103.  
  104. const IGNORE_bufferhealth_CHECK = false; // experimental; true will make "Stats for nerds" no info.
  105.  
  106. const DENY_requestStorageAccess = true; // remove document.requestStorageAccess
  107. const DISABLE_IFRAME_requestStorageAccess = true; // no effect if DENY_requestStorageAccess is true
  108.  
  109. const DISABLE_COOLDOWN_SCROLLING = true; // YT cause scroll hang in MacOS
  110.  
  111. const FIX_removeChild = true;
  112. const FIX_fix_requestIdleCallback_timing = true;
  113.  
  114. const HOOK_CSSPD_LEFT = true; // global css hack for style.left
  115. const FORCE_NO_REUSEABLE_ELEMENT_POOL = true;
  116.  
  117. const FIX_TRANSCRIPT_SEGMENTS = true; // Based on Tabview Youtube's implementation
  118.  
  119. const FIX_POPUP_UNIQUE_ID = true; // currently only for channel about popup;
  120.  
  121. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  122. // example. https://www.youtube.com/channel/UCgPev1KKSCMbnNRsvN83Hag/about
  123. // first tp-yt-paper-dialog: show once the page is loaded.
  124. // second tp-yt-paper-dialog: click "...more"
  125. // third tp-yt-paper-dialog: click "... and 3 more links"
  126. // check with document.querySelectorAll('ytd-popup-container tp-yt-paper-dialog').length
  127. // currently, uniqueId is preassigned by the network resolveCommand.
  128. // so don't modify the source side, just modify the display side (popup display) via handleOpenPopupAction
  129. // other related functions e.g. handleClosePopupCommand_, getAndMaybeCreatePopup_, handleClosePopupAction_, getAndMaybeCreatePopup_
  130.  
  131. // handleOpenPopupAction -> createCacheKey
  132. // handleClosePopupAction_ -> createCacheKey
  133. // handleGetPopupOpenedAction_ -> createCacheKey
  134. // getAndMaybeCreatePopup_ -> createCacheKey
  135. // closePopup -> createCacheKey
  136.  
  137. // yt-close-popup-command -> handleClosePopupCommand_
  138.  
  139. // ensurePopup_ -> getAndMaybeCreatePopup_
  140.  
  141. // yt-close-popup-action -> handleClosePopupAction_
  142. // closePopup -> handleClosePopupAction_
  143. // handleOpenPopupAction -> handleClosePopupAction_
  144. // handleClosePopupCommand_ -> handleClosePopupAction_
  145. // closeSheet -> handleClosePopupAction_("yt-sheet-view-model")
  146.  
  147. // yt-open-popup-action -> handleOpenPopupAction
  148.  
  149.  
  150. // yt-close-popup-action -> handleClosePopupAction_ -> createCacheKey
  151. // yt-close-popup-command -> handleClosePopupCommand_ -> handleClosePopupAction_ -> createCacheKey
  152.  
  153. // Experimental flag "ytpopup_disable_default_html_caching" is disabled by default.
  154. // Not sure enabling it can make GC or not (Yt Components are usually not GC-able)
  155. // ----------------------------- POPUP UNIQUE ID ISSUE -----------------------------
  156.  
  157.  
  158. const FIX_DOM_IF_REPEAT = true; // semi-experimental (added in 0.17.0)
  159. const FIX_DOM_IF_TEMPLATE = true;
  160. // const FIX_DOM_REPEAT_TEMPLATE = true; // to be implemented
  161. const FIX_DOM_IFREPEAT_RenderDebouncerChange = false; // semi-experimental (added in 0.17.0) // found buggy for chat ticker sizing
  162. const DEBUG_DBR847 = false;
  163. const DEBUG_xx847 = false;
  164. const FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME = true; // default true. false might be required for future change
  165. const DEBUG_renderDebounceTs = false;
  166.  
  167. const FIX_ICON_RENDER = true;
  168.  
  169. const FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS = true; // avoid unnecessary reflows due to cursor moves on the web player.
  170.  
  171. /*
  172.  
  173. FIX_DOM_IFREPEAT_RenderDebouncerChange
  174.  
  175. avoid Polymer.flush
  176. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  177.  
  178. var Is = function() {
  179. do {
  180. var a = window.ShadyDOM && ShadyDOM.flush();
  181. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  182. var b = NNa()
  183. } while (a || b)
  184. };
  185.  
  186. , NNa = function() {
  187. var a = !!ts.size;
  188. ts.forEach(function(b) {
  189. try {
  190. b.flush()
  191. } catch (c) {
  192. setTimeout(function() {
  193. throw c
  194. })
  195. }
  196. });
  197. return a
  198. };
  199.  
  200. // why flush twice after all ts are completed? (!!ts.size => true => loop again)
  201. // this coding logic should be incorrect (mistake).
  202.  
  203. */
  204.  
  205.  
  206.  
  207. // ----------------------------- Shortkey Keyboard Control -----------------------------
  208. // dependency: FIX_yt_player
  209.  
  210. const FIX_SHORTCUTKEYS = 2; // 0 - no fix; 1 - basic fix; 2 - advanced fix
  211. // [0] no fix - not recommended
  212. // [1] basic fix - just fix the global focus detection variable
  213. // [2] advanced fix - call the shortcut actions directly, auto foucs change, direct control of spacebar behavior, etc
  214. // (note) 0 or 1 if you find conflict with other userscripts/plugin
  215.  
  216. const CHANGE_SPEEDMASTER_SPACEBAR_CONTROL = 0; // 0 - disable; 1 - force true; 2 - force false
  217. const USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER = true; // only for SPEEDMASTER = false & FIX_SHORTCUTKEYS = 2
  218.  
  219. const PROP_OverReInclusion_AVOID = true;
  220. const PROP_OverReInclusion_DEBUGLOG = false;
  221. const PROP_OverReInclusion_LIST = new Set([
  222. 'hostElement72',
  223. 'parentComponent72',
  224. 'localVisibilityObserver_72',
  225. 'cachedProviderNode_72',
  226. '__template72',
  227. '__templatizeOwner72',
  228. '__templateInfo72',
  229. '__dataHost72',
  230. '__CE_shadowRoot72',
  231. 'elements_72',
  232.  
  233. 'ky36',
  234. 'kz62',
  235. 'm822',
  236.  
  237.  
  238.  
  239. // To be reviewed.
  240.  
  241. // chat messages
  242. 'disabled', 'allowedProps',
  243. 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons', 'allowedProps',
  244.  
  245. 'dimension', 'loadTime', 'pendingPaint',
  246.  
  247. 'countdownDurationMs', 'countdownMs', 'lastCountdownTimeMs', 'rafId', 'playerProgressSec', 'detlaSincePausedSecs', 'behaviorActionMap', 'selected', 'maxLikeCount', 'maxReplyCount', 'isMouseOver',
  248.  
  249. 'respectLangDir', 'noEndpoints',
  250.  
  251.  
  252. 'objectURL',
  253. 'buttonOverrides', 'queuedMessages',
  254. 'STEP', 'BLOCK_ON', 'MIN_PROGESS', 'MAX_PROGESS',
  255. 'DISMISSED_CONTENT_KEYSPACE', 'followUpDialogPromise', 'followUpDialogPromiseResolve', 'followUpDialogPromiseReject',
  256. 'hoverJobId', 'JSC$14573_touched',
  257.  
  258.  
  259. // tbc
  260. 'toggleable', 'isConnected',
  261. 'scrollDistance', 'dragging', 'dragMouseStart', 'dragOffsetStart', 'containerWidthDiff',
  262. 'disableDeselectEvent',
  263. 'emojiSize',
  264.  
  265. 'buttonOverride',
  266. 'shouldUseStickyPreferences', 'longPressTimeoutId',
  267.  
  268. // others
  269. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  270. // 'filledButtonOverrides', 'openPopupConfig', 'supportsInlineActionButtons',
  271. 'observeVisibleOption', 'observeHiddenOption', 'observePrescanOption', 'visibilityMonitorKeys',
  272. // 'dimension', 'loadTime', 'pendingPaint',
  273. // 'disabled', 'allowedProps',
  274.  
  275.  
  276. // 'enableMssLazyLoad', 'popupContainerConfig', 'actionRouterNode', 'actionRouterIsRoot', 'actionMap', 'dynamicActionMap',
  277. // 'actionMap',
  278.  
  279. // 'sharedTooltipPosition', 'sharedTooltipAnimationDelay', 'disableEmojiPickerIncrementalLoading', 'useResolveCommand', 'activeRequest', 'popoutWindowCheckIntervalId', 'supportedTooltipTargets', 'closeActionPanelTimerId', 'delayCloseActionPanelTimerId', 'tooltipTimerIds', 'queuedTooltips', 'isPopupConfigReady', 'popoutWindow', 'actionMap',
  280.  
  281. 'clearTimeout',
  282. 'switchTemplateAtRegistration', 'hasUnmounted',
  283. 'switchTemplateAtRegistration', 'stopKeyboardEventPropagation',
  284. 'tangoConfiguration',
  285. 'itemIdToDockDurationMap',
  286. 'actionMap',
  287.  
  288. 'emojiManager', 'inputMethodEditorActive', 'suggestionIndex', 'JSC$10745_lastSuggestionRange',
  289. 'actionMap', 'asyncHandle', 'shouldAnimateIn', 'lastFrameTimestamp', 'scrollClampRaf',
  290. 'scrollRatePixelsPerSecond', 'scrollStartTime', 'scrollStopHandle'
  291.  
  292. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  293. // 'stopKeyboardEventPropagation', 'emojiSize',
  294. // 'switchTemplateAtRegistration', 'hasUnmounted',
  295. // 'buttonOverrides', 'queuedMessages', 'clearTimeout', 'actionMap',
  296. // 'isReusable', 'tangoConfiguration',
  297. // 'itemIdToDockDurationMap', 'bottomAlignMessages', 'actionMap',
  298. // */
  299.  
  300. ]);
  301.  
  302.  
  303. // const CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE = false; // NO USE; TO BE REVIEWED
  304.  
  305. // ----------------------------- Shortkey Keyboard Control -----------------------------
  306.  
  307. /*
  308. window.addEventListener('edm',()=>{
  309. let p = [...this.onerror.errorTokens][0].token; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  310. });
  311.  
  312. window.addEventListener('edn',()=>{
  313. let p = [...this.onerror.errorTokens][0].token+"X"; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  314. });
  315. window.addEventListener('edr',()=>{
  316. let p = '123'; (()=>{ console.log(p); throw new Error(p);console.log(334,p) })()
  317. });
  318. */
  319.  
  320. // only for macOS with Chrome/Firefox 100+
  321. const advanceLogging = typeof AbortSignal !== 'undefined' && typeof (AbortSignal || 0).timeout === 'function' && typeof navigator !== 'undefined' && /\b(Macintosh|Mac\s*OS)\b/i.test((navigator || 0).userAgent || '');
  322.  
  323. const win = this instanceof Window ? this : window;
  324.  
  325. // Create a unique key for the script and check if it is already running
  326. const hkey_script = 'jswylcojvzts';
  327. if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting
  328. win[hkey_script] = true;
  329.  
  330.  
  331.  
  332. const wk = Symbol();
  333.  
  334. // const [setTimeoutX0, clearTimeoutX0] = [setTimeout, clearTimeout];
  335.  
  336. let BY_PASS_KEYBOARD_CONTROL = false;
  337.  
  338.  
  339. // const setImmediate = ((self || 0).jmt || 0).setImmediate;
  340. /** @type {(f: ()=>{})=>{}} */
  341. const nextBrowserTick_ = nextBrowserTick;
  342. if (typeof nextBrowserTick_ !== "function" || (nextBrowserTick_.version || 0) < 2) {
  343. console.log('nextBrowserTick is not found.');
  344. return;
  345. }
  346.  
  347. let p59 = 0;
  348.  
  349. const Promise = (async () => { })().constructor;
  350.  
  351. const PromiseExternal = ((resolve_, reject_) => {
  352. const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };
  353. return class PromiseExternal extends Promise {
  354. constructor(cb = h) {
  355. super(cb);
  356. if (cb === h) {
  357. /** @type {(value: any) => void} */
  358. this.resolve = resolve_;
  359. /** @type {(reason?: any) => void} */
  360. this.reject = reject_;
  361. }
  362. }
  363. };
  364. })();
  365.  
  366. const FinalizationRegistry_ = typeof FinalizationRegistry !== "undefined" ? FinalizationRegistry : class FinalizationRegistry__ {
  367. constructor(callback = undefined) {
  368.  
  369. }
  370. register(target, heldValue, unregisterToken = undefined) {
  371.  
  372. }
  373. unregister(unregisterToken) {
  374.  
  375. }
  376. }
  377.  
  378. let ttpHTML = (s) => {
  379. ttpHTML = s => s;
  380. if (typeof trustedTypes !== 'undefined' && trustedTypes.defaultPolicy === null) {
  381. let s = s => s;
  382. trustedTypes.createPolicy('default', { createHTML: s, createScriptURL: s, createScript: s });
  383. }
  384. return s;
  385. }
  386.  
  387.  
  388. /** @type { typeof HTMLElement } */
  389. const HTMLElement_ = Reflect.getPrototypeOf(HTMLTitleElement);
  390. const nativeAppendE = HTMLElement_.prototype.append;
  391. const nativeRemoveE = HTMLElement_.prototype.remove;
  392. const DocumentFragment_ = DocumentFragment;
  393. const nativeAppendD = DocumentFragment_.prototype.append;
  394. const Node_ = Node;
  395.  
  396. /**
  397. @param {number} x
  398. @param {number} d */
  399. const toFixed2 = (x, d) => {
  400. let t = x.toFixed(d);
  401. let y = `${+t}`;
  402. return y.length > t.length ? t : y;
  403. }
  404.  
  405.  
  406. const isChatRoomURL = location.pathname.startsWith('/live_chat');
  407.  
  408.  
  409. const TRANSLATE_DEBUG = false;
  410.  
  411.  
  412. let xdeadc00 = null; // a deteched node with __domApi
  413. let xlivec00 = null; // a deteched node with __domApi
  414.  
  415. let removeTNodeRM = null;
  416. let removeTNodeBP = false;
  417.  
  418.  
  419.  
  420.  
  421. let FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = false;
  422.  
  423. const FORCE_NO_REUSEABLE_ELEMENT_POOL_fn = (mainCnt) => {
  424.  
  425. if (FORCE_NO_REUSEABLE_ELEMENT_POOL_fired) return;
  426.  
  427. FORCE_NO_REUSEABLE_ELEMENT_POOL_fired = true;
  428.  
  429.  
  430. if (typeof mainCnt.createComponent_ !== 'function' || mainCnt.createComponent_.length != 3) {
  431. console.warn('FORCE_NO_REUSEABLE_ELEMENT_POOL_fn failed.')
  432. return;
  433. }
  434.  
  435.  
  436. const mapGet = Map.prototype.get;
  437. const setHas = Set.prototype.has;
  438.  
  439.  
  440. /** @type {Map | null} */
  441. let qcMap = null;
  442.  
  443. Set.prototype.has = function (a) {
  444. if (a === 'dummy-4718') return false; // false to allow re-use?
  445. return setHas.call(this, a);
  446. }
  447.  
  448. Map.prototype.get = function (a) {
  449. if (a === 'dummy-4718') qcMap = this;
  450. return mapGet.call(this, a);
  451. };
  452. let r;
  453. try {
  454. r = mainCnt.createComponent_('dummy-4718', {}, true);
  455. } catch (e) {
  456.  
  457. }
  458.  
  459. Map.prototype.get = mapGet;
  460. Set.prototype.has = setHas;
  461.  
  462. if (r && (r.nodeName || '').toLowerCase() === 'dummy-4718') {
  463.  
  464.  
  465. // clearInterval(ckId);
  466. // ckId = 0;
  467.  
  468. if (qcMap !== null && qcMap instanceof Map) {
  469.  
  470. console.log('[yt-js-engine-tamer] qcMap', qcMap);
  471. qcMap.__qcMap8781__ = true;
  472.  
  473. const setArrayC = (c) => {
  474. if (c instanceof Array) {
  475. c.length = 0;
  476. c.push = function () { };
  477. c.pop = function () { };
  478. c.shift = function () { };
  479. c.unshift = function () { };
  480. c.splice = function () { };
  481. c.sort = function () { };
  482. c.reverse = function () { };
  483. }
  484. }
  485.  
  486. const cleaning = function (m) {
  487. m.forEach(setArrayC);
  488. m.clear();
  489. }
  490.  
  491. qcMap.set = function (b, c) {
  492. if (!this.__qcMap8781__) return Map.prototype.set.call(this, b, c);
  493.  
  494. setArrayC(c);
  495.  
  496. // console.log('qcMap.set', b, c);
  497.  
  498. if (this.size > 0) {
  499. // play safe
  500.  
  501. console.log('[yt-js-engine-tamer] qcMap', 'clear 01')
  502. cleaning(this);
  503. }
  504.  
  505. }
  506. qcMap.get = function (b) {
  507. if (!this.__qcMap8781__) return Map.prototype.get.call(this, b);
  508.  
  509. // console.log('qcMap.get', b);
  510.  
  511. if (this.size > 0) {
  512. // play safe
  513.  
  514. console.log('[yt-js-engine-tamer] qcMap', 'clear 02')
  515. cleaning(this);
  516. }
  517.  
  518. }
  519.  
  520.  
  521. if (qcMap.size > 0) {
  522.  
  523. console.log('[yt-js-engine-tamer] qcMap', 'clear 03')
  524. cleaning(qcMap);
  525. }
  526.  
  527. }
  528.  
  529. }
  530.  
  531. r = null;
  532. qcMap = null;
  533.  
  534. }
  535.  
  536.  
  537. const dispatchYtEvent = function (a, b, c, d) {
  538. d || (d = {
  539. bubbles: !0,
  540. cancelable: !1,
  541. composed: !0
  542. });
  543. c !== null && c !== void 0 && (d.detail = c);
  544. b = new CustomEvent(b, d);
  545. a.dispatchEvent(b);
  546. return b
  547. };
  548.  
  549.  
  550. if (XFlag) {
  551.  
  552. const cMap = new Set();
  553. cMap.add = cMap.addOriginal || cMap.add;
  554. const yMap = new Set();
  555. yMap.add = yMap.addOriginal || yMap.add;
  556.  
  557.  
  558. const ydMap = new Set();
  559. ydMap.add = ydMap.addOriginal || ydMap.add;
  560.  
  561. window.yMap = yMap;
  562. window.cMap = cMap;
  563. window.ydMap = ydMap;
  564.  
  565. const constructAts = new Set();
  566. constructAts.add = constructAts.addOriginal || constructAts.add;
  567. window.constructAts = constructAts;
  568.  
  569. const kMap = new WeakMap();
  570.  
  571. const kRefProp = (wr, prop)=>{
  572. let o = kRef(wr);
  573. return o ? o[prop] : null;
  574. }
  575.  
  576. const wrObj = (objRef, props) => {
  577. let wr = mWeakRef(objRef);
  578. if (wr === objRef || !props || !props.length) return wr;
  579. let properties = {};
  580. props.forEach(k => {
  581. properties[k] = {
  582. get() {
  583. return kRefProp(this, k)
  584. },
  585. enumerable: false,
  586. configurable: true
  587. };
  588. });
  589. Object.defineProperties(wr, properties);
  590. return wr;
  591. }
  592.  
  593. const sProtos = {};
  594.  
  595. const setupCProto = function (cProto) {
  596.  
  597. if(cProto === Object.prototype) return;
  598.  
  599. if (!kMap.get(cProto)) kMap.set(cProto, `protoKey0_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  600. cProto[kMap.get(cProto)] = true;
  601. // debugger;
  602.  
  603. 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];
  604. constructAts.add(constructAt)
  605.  
  606. if (MemoryFix_Flag002 & 32) {
  607. if (!cProto.dk322 && (cProto.__attachInstance || cProto.__detachInstance)) {
  608. fixDetachFn(cProto);
  609. }
  610. }
  611.  
  612. if (MemoryFix_Flag002 & 2) {
  613. if (cProto._setPendingProperty && !cProto.__setPropDX38__) {
  614. cProto.__setPropDX38__ = true;
  615.  
  616. if (cProto._setPendingProperty.length === 3) {
  617. cProto._setPendingProperty.bind = sProtos._setPendingProperty$bind || (sProtos._setPendingProperty$bind = function (obj, ...args) {
  618. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  619. return () => {
  620. const obj = kRef(wobj);
  621. let u = Reflect.apply(this, obj, args);
  622. args.length = 0;
  623. wobj = null;
  624. return u;
  625. };
  626. });
  627. }
  628.  
  629. }
  630. }
  631.  
  632. if (MemoryFix_Flag002 & 4) {
  633. if (cProto._runEffectsForTemplate && !cProto.__runEffectDX38__) {
  634. cProto.__runEffectDX38__ = true;
  635.  
  636. if (cProto._runEffectsForTemplate.length === 4) {
  637. cProto._runEffectsForTemplate3858 = cProto._runEffectsForTemplate;
  638. cProto._runEffectsForTemplate = sProtos._runEffectsForTemplate || (sProtos._runEffectsForTemplate = function (c, d, e, g) {
  639. if (c && c.runEffects) {
  640. let wr = wrObj(c, ['propertyEffects', 'nodeList', 'firstChild']);
  641. // console.log(12837)
  642. if (!this[wk]) this[wk] = mWeakRef(this);
  643. if ((typeof (e || 0) === "object") && !e[wk]) e[wk] = mWeakRef(e);
  644. let cntWr = this[wk];
  645. let eWr = (typeof (e || 0) === "object") ? e[wk] : e;
  646. c.runEffects((n, r) => {
  647. // console.log(12838)
  648. const cnt = kRef(cntWr);
  649. const e = kRef(eWr);
  650. if (cnt) {
  651. cnt._runEffectsForTemplate3858(wr, n, e, r);
  652. }
  653. wr = cntWr = d = e = g = null;
  654. }, d, g);
  655. } else {
  656. let { propertyEffects, nodeList, firstChild } = c;
  657. let o = { propertyEffects, nodeList, firstChild }
  658. this._runEffectsForTemplate3858(o, d, e, g);
  659. o.propertyEffects = o.nodeList = o.firstChild = null;
  660. propertyEffects = nodeList = firstChild = null;
  661. o = null;
  662. }
  663.  
  664. });
  665.  
  666. cProto._runEffectsForTemplate.bind = sProtos._runEffectsForTemplate$bind || (sProtos._runEffectsForTemplate$bind = function (obj, ...args) {
  667. // console.log(12993, args)
  668. let wobj = obj[wk] || (obj[wk] = mWeakRef(obj));
  669. return () => {
  670. const obj = kRef(wobj);
  671. let u = Reflect.apply(this, obj, args);
  672. args.length = 0;
  673. wobj = null;
  674. return u;
  675. };
  676. });
  677. }
  678.  
  679. }
  680. }
  681.  
  682.  
  683.  
  684.  
  685.  
  686. const cProtoConstructor = cProto.constructor;
  687.  
  688. if (MemoryFix_Flag002 & 8) {
  689. if (cProtoConstructor._parseBindings && !cProtoConstructor.__parseBindingsDX38__) {
  690. cProtoConstructor.__parseBindingsDX38__ = true;
  691.  
  692. ydMap.add(cProtoConstructor);
  693.  
  694. if (cProtoConstructor._parseBindings.length === 2) {
  695.  
  696. cProtoConstructor._parseBindings3858 = cProtoConstructor._parseBindings;
  697.  
  698. cProtoConstructor._parseBindings = sProtos._parseBindings || (sProtos._parseBindings = function (c, d) {
  699. let p = this._parseBindings3858(c, d);
  700. this.__bindingsArrs__ = this.__bindingsArrs__ || [];
  701. if (p) this.__bindingsArrs__.push(p);
  702. return p;
  703. });
  704.  
  705. }
  706. }
  707. }
  708.  
  709. /*
  710. a.prototype._initializeProperties = function() {
  711. if (Em && this.hasAttribute("disable-upgrade"))
  712. this.__isUpgradeDisabled = !0;
  713. else {
  714. var e = Object.getPrototypeOf(this);
  715. e.hasOwnProperty("__hasRegisterFinished") || (this._registered(),
  716. e.__hasRegisterFinished = !0);
  717. b.prototype._initializeProperties.call(this);
  718. this.root = this;
  719. this.created();
  720. fpb && !this._legacyForceObservedAttributes && (this.hasAttributes() ? this._takeAttributes() : this.parentNode || (this.__needsAttributesAtConnected = !0));
  721. this._applyListeners()
  722. }
  723. }
  724. */
  725. /*
  726. bOa = function(a, b, c) {
  727. var d = bya(a.prototype, $Na, a.prototype.behaviors);
  728. d.prototype.is = b;
  729. d.prototype.localName = b;
  730. c && aOa(d, c);
  731. return function(e) {
  732. e && (d.prototype.hostElement = e);
  733. var g = new d;
  734. g.root = g;
  735. g.hostElement = e;
  736. return g
  737. }
  738. }
  739. */
  740.  
  741.  
  742. }
  743. const symDH = Symbol();
  744.  
  745. const wfStore = new WeakMap();
  746.  
  747. const wrapF = function (f, key) {
  748. if (wfStore.get(f)) return wfStore.get(f);
  749.  
  750. let g = function () {
  751. const o = kRef(this);
  752. if (!o) return;
  753. const cnt = insp(o);
  754. // if (cnt === o) return;
  755. // if (!('ready' in cnt)) return;
  756. return f.apply(o, arguments);
  757. };
  758. g.key38 = key;
  759. g.originalFunc38 = f;
  760. g.__wrapF84__ = true;
  761. wfStore.set(f, g);
  762. wfStore.set(g, g);
  763. return g;
  764. };
  765.  
  766. if (MemoryFix_Flag002 & 16) {
  767. ['_createPropertyAccessor', '_addPropertyToAttributeMap', '_definePropertyAccessor', 'ready', '_initializeProperties', '_initializeInstanceProperties', '_setProperty', '_getProperty', '_setPendingProperty', '_isPropertyPending', '_invalidateProperties', '_enableProperties', '_flushProperties', '_shouldPropertiesChange', '_propertiesChanged', '_shouldPropertyChange', 'attributeChangedCallback', '_attributeToProperty', '_propertyToAttribute', '_valueToNodeAttribute', '_serializeValue', '_deserializeValue'].forEach(key => {
  768.  
  769. Object.defineProperty(Node.prototype, key, {
  770. get() {
  771. return this[`__a0939${key}__`];
  772. },
  773. set(nv) {
  774. if (typeof nv !== 'function') return;
  775. const g = (nv.__wrapF84__) ? nv : wrapF(nv, key);
  776. this[`__a0939${key}__`] = g;
  777. return true;
  778. }
  779. });
  780.  
  781.  
  782. });
  783. }
  784.  
  785.  
  786. const fragQ = document.createDocumentFragment(); // for cleaup removal
  787. const fixDetachFn = (tpProto) => {
  788.  
  789. if (tpProto.dk322) return;
  790. tpProto.dk322 = true;
  791.  
  792. tpProto.__detachInstance994 = tpProto.__detachInstance;
  793. if (typeof tpProto.__detachInstance994 === 'function' && tpProto.__detachInstance994.length === 1) {
  794. tpProto.__detachInstance = function (a) {
  795. const u = this.__instances[a];
  796. if (u && u.root) {
  797. const children = u ? u.children : null;
  798. if (children && children.length >= 1) {
  799. this.__detachInstance994(a);
  800. }
  801. } else if (u && !u.root) {
  802. const children = u ? u.children : null;
  803. if (children && children.length >= 1) {
  804. for (let i = 0, l = children.length; i < l; i++) {
  805. const node = children[i];
  806. fragQ.appendChild(node); // for cleanup
  807. Promise.resolve(node).then(node => (node.parentNode === fragQ) && !!node.remove());
  808. }
  809. }
  810. }
  811. return u;
  812. }
  813. }
  814.  
  815.  
  816.  
  817. tpProto.__attachInstance994 = tpProto.__attachInstance;
  818. if (typeof tpProto.__attachInstance994 === 'function' && tpProto.__attachInstance994.length === 2) {
  819. tpProto.__attachInstance = function (a, b) {
  820. const u = this.__instances[a];
  821. if (u && u.root && b) {
  822. fragQ.appendChild(u.root); // for cleanup
  823. return this.__attachInstance994(a, b);
  824. }
  825. }
  826. }
  827.  
  828. }
  829. const ytTemplateDomEntry = (tpProto) => {
  830.  
  831. console.log('ytTemplateDomEntry triggered')
  832.  
  833.  
  834. const convertToWeakArr = (arr) => {
  835.  
  836.  
  837. if (arr.isWeak) return;
  838.  
  839. for (let i = 0, l = arr.length; i < l; i++) {
  840. const o = arr[i]
  841. if (o) {
  842. let p = kRef(o)
  843. if (!p) arr[i] = null;
  844. else {
  845. if (!o[wk]) o[wk] = mWeakRef(o);
  846. arr[i] = o[wk];
  847. }
  848. }
  849. }
  850. arr.isWeak = true;
  851.  
  852. }
  853.  
  854. const convertToNormalArr = (arr) => {
  855.  
  856. if (!arr.isWeak) return;
  857.  
  858. for (let i = 0, l = arr.length; i < l; i++) {
  859. const o = arr[i]
  860. if (o) {
  861. let p = kRef(o)
  862. arr[i] = p;
  863. }
  864. }
  865. arr.isWeak = false;
  866.  
  867. }
  868.  
  869. if (MemoryFix_Flag002 & 256) {
  870. Object.defineProperty(tpProto, '__instances', {
  871. get() {
  872. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  873. let arr = this.__instances_actual471__;
  874. convertToNormalArr(arr);
  875. Promise.resolve(arr).then(convertToWeakArr);
  876. return arr;
  877. },
  878. set(nv) {
  879. this.dk322 || fixDetachFn(Reflect.getPrototypeOf(this));
  880. this.__instances_actual471__ = nv;
  881. Promise.resolve(nv).then(convertToWeakArr);
  882. return true;
  883. },
  884. enumerable: false,
  885. configurable: true
  886. });
  887. }
  888.  
  889. // console.log(91901, tpProto.__detachInstance)
  890. if (MemoryFix_Flag002 & 32) {
  891. if (tpProto.__detachInstance) {
  892. fixDetachFn(tpProto);
  893. } else {
  894. Promise.resolve(tpProto).then((tpProto) => {
  895. // console.log(91902, tpProto.__detachInstance)
  896. fixDetachFn(tpProto);
  897. })
  898. }
  899. }
  900.  
  901. }
  902.  
  903. if (MemoryFix_Flag002 & 32) {
  904. Object.defineProperty(Object.prototype, '__ensureTemplatized', {
  905. set(nv) {
  906. if (nv === true) return false;
  907. tpProto = this;
  908. if ('connectedCallback' in tpProto && tpProto !== Node.prototype && !tpProto.__domDX37__) {
  909. tpProto.__domDX37__ = true;
  910. ytTemplateDomEntry(tpProto);
  911. }
  912. this.__ensureTemplatized949__ = nv;
  913. return true;
  914. },
  915. get() {
  916. return this.__ensureTemplatized949__;
  917. }
  918. });
  919. }
  920.  
  921.  
  922. if (MemoryFix_Flag002 & 64) {
  923. HTMLElement_.prototype.__dataHostBinding374 = true;
  924. Object.defineProperty(HTMLElement_.prototype, '__dataHost', {
  925. get() {
  926. return kRef(this.__dataHostWr413__);
  927. },
  928. set(nv) {
  929. if (nv && typeof nv === 'object' && !nv.deref) {
  930. if (!nv[wk]) nv[wk] = mWeakRef(nv);
  931. nv = nv[wk];
  932. }
  933. this.__dataHostWr413__ = nv;
  934. return true;
  935. }
  936. });
  937. }
  938.  
  939.  
  940. const setupYProto = function (yProto) {
  941.  
  942. if(yProto === Object.prototype) return;
  943.  
  944. if (!kMap.get(yProto)) kMap.set(yProto, `protoKey1_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${Date.now()}`);
  945. yProto[kMap.get(yProto)] = true;
  946.  
  947. if (MemoryFix_Flag002 & 32) {
  948. if (!yProto.dk322 && (yProto.__attachInstance || yProto.__detachInstance)) {
  949. fixDetachFn(yProto);
  950. }
  951. }
  952.  
  953. if (MemoryFix_Flag002 & 128) {
  954. if (!yProto.__dataHostBinding374) {
  955. yProto.__dataHostBinding374 = true;
  956. Object.defineProperty(yProto, '__dataHost', {
  957. set(nv) {
  958. let dh = nv;
  959. if (dh && typeof dh === 'object' && !dh.deref) {
  960. const wr = dh[wk] || (dh[wk] = mWeakRef(dh));
  961. dh = wr;
  962. }
  963. this[symDH] = dh;
  964. return true;
  965. },
  966. get() {
  967. let wr = this[symDH];
  968. let obj = typeof wr === 'object' ? kRef(wr) : wr;
  969. return obj;
  970. },
  971. enumerable: false,
  972. configurable: true
  973. });
  974. }
  975.  
  976.  
  977.  
  978. if (yProto._registerHost && yProto._enqueueClient && yProto.__enableOrFlushClients && !yProto._registerHostDX38__) {
  979. yProto._registerHostDX38__ = true;
  980.  
  981. // yProto._registerHost7133 = yProto._registerHost;
  982.  
  983. yProto.__enableOrFlushClients = function () {
  984. const c_ = this.__dataPendingClients;
  985. if (c_) {
  986. const c = c_.slice();
  987. c_.length = 0;
  988. for (let d = 0, l = c.length; d < l; d++) {
  989. let e = kRef(c[d]);
  990. if (e) {
  991. e.__dataEnabled ? e.__dataPending && e._flushProperties() : e._enableProperties()
  992. }
  993. }
  994. }
  995. }
  996.  
  997. yProto._enqueueClient = function (c) {
  998. if (c === this || !c || typeof c !== 'object') return;
  999. if (c.deref) c = kRef(c);
  1000. const m = this.__dataPendingClients || (this.__dataPendingClients = []);
  1001. if (!c[wk]) c[wk] = mWeakRef(c);
  1002. m.push(c[wk]);
  1003. }
  1004.  
  1005. }
  1006. }
  1007.  
  1008.  
  1009.  
  1010. }
  1011. const setupRendering = function () {
  1012.  
  1013. const cnt = this;
  1014. const cProto = Reflect.getPrototypeOf(cnt);
  1015. let yProto = Reflect.getPrototypeOf(cProto);
  1016.  
  1017. const yProtos = new Set();
  1018.  
  1019. if (!yMap.has(yProto)) {
  1020. // capture all ancenstor constructors of a and b (non-specific component type)
  1021.  
  1022. do {
  1023. if (yProto === Object.prototype || yProto === null) break;
  1024. if (yProto === Element.prototype || yProto === Node.prototype || yProto === EventTarget.prototype || yProto === HTMLElement_.prototype) break;
  1025. yProtos.add(yProto);
  1026. yProto = Reflect.getPrototypeOf(yProto);
  1027. } while (!yProtos.has(yProto));
  1028.  
  1029. for (const yProto of yProtos) {
  1030. yMap.add(yProto);
  1031. setupYProto(yProto)
  1032. }
  1033.  
  1034. }
  1035.  
  1036.  
  1037. if (!cMap.has(cProto)) {
  1038. cMap.add(cProto); // cProto constrcutor is either a or b? (specific component type)
  1039. setupCProto(cProto);
  1040. }
  1041.  
  1042. }
  1043.  
  1044. const selfRef = {}; // no change. just key
  1045.  
  1046.  
  1047. let wm3 = new WeakMap();
  1048.  
  1049. Object.defineProperty(Object.prototype, 'root', {
  1050. get() {
  1051. const p = this ? kRef(this) : null;
  1052. const r = p ? wm3.get(p) : null;
  1053. const r2 = r ? kRef(r) : null;
  1054. if (r === selfRef) return p;
  1055. return r2;
  1056. },
  1057. set(nv) {
  1058. const p = this ? kRef(this) : null;
  1059. const mv = nv ? kRef(nv) : null;
  1060. if (typeof mv !== 'object') return;
  1061. if (mv && (mv instanceof Node) && !p.__setupRendered399__) {
  1062. p.__setupRendered399__ = true;
  1063. setupRendering.call(p);
  1064. }
  1065. if (mv && mv.is && !mv.__setupRendered399__) {
  1066. mv.__setupRendered399__ = true;
  1067. setupRendering.call(mv);
  1068. }
  1069. if (mv === p) {
  1070. wm3.set(p, selfRef)
  1071. return true;
  1072. }
  1073. let gv = nv;
  1074. if (nv && !nv[wk]) {
  1075. gv = nv[wk] = mWeakRef(nv);
  1076. }
  1077. if (p) {
  1078. wm3.set(p, gv);
  1079. }
  1080. return true;
  1081. },
  1082. enumerable: false,
  1083. configurable: true
  1084. });
  1085.  
  1086.  
  1087.  
  1088. }
  1089.  
  1090. function getTranslate() {
  1091.  
  1092. pLoad.then(() => {
  1093.  
  1094. let nonce = document.querySelector('style[nonce]');
  1095. nonce = nonce ? nonce.getAttribute('nonce') : null;
  1096. const st = document.createElement('style');
  1097. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  1098. st.textContent = ".yt-formatted-string-block-line{display:block;}";
  1099. let parent;
  1100. if (parent = document.head) parent.appendChild(st);
  1101. else if (parent = (document.body || document.documentElement)) parent.insertBefore(st, parent.firstChild);
  1102.  
  1103. });
  1104.  
  1105. const snCache = new Map();
  1106.  
  1107. if (TRANSLATE_DEBUG) {
  1108. console.log(11)
  1109. }
  1110.  
  1111. /** @type {(str: string?) => string} */
  1112. function _snippetText(str) {
  1113. // str can be underfinded
  1114. if (!str || typeof str !== 'string') return '';
  1115. let res = snCache.get(str);
  1116. if (res === undefined) {
  1117. let b = false;
  1118. res = str.replace(/[\s\u3000\u200b]*[\u200b\xA0\x20\n]+[\s\u3000\u200b]*/g, (m) => {
  1119. b = true;
  1120. return m.includes('\n') ? '\n' : m.replace(/\u200b/g, '').replace(/[\xA0\x20]+/g, ' ');
  1121. });
  1122. res = res.replace(/^[\s\u3000]+|[\u3000\s]+$/g, () => {
  1123. b = true;
  1124. return '';
  1125. });
  1126. if (b) {
  1127. snCache.set(str, res);
  1128. snCache.set(res, null);
  1129. } else {
  1130. res = null;
  1131. snCache.set(str, null);
  1132. }
  1133. }
  1134. return res === null ? str : res;
  1135. }
  1136.  
  1137. /** @type {(snippet: Object) => string} */
  1138. function snippetText(snippet) {
  1139. let runs = snippet.runs;
  1140. const n = runs.length;
  1141. if (n === 1) return _snippetText(runs[0].text);
  1142. let res = new Array(n);
  1143. let ci = 0;
  1144. for (const s of runs) {
  1145. res[ci++] = _snippetText(s.text);
  1146. }
  1147. return res.join('\n');
  1148. }
  1149.  
  1150. const _DEBUG_szz = (t) => t.map(x => {
  1151. const tsr = x.transcriptSegmentRenderer;
  1152. return ({
  1153. t: tsr.snippet.runs.map(x => x.text).join('//'),
  1154. a: tsr.startMs,
  1155. b: tsr.endMs
  1156. });
  1157. });
  1158.  
  1159. const fixRuns = (runs) => {
  1160. if (runs.length === 1 && runs[0]?.text?.includes('\n')) {
  1161. // https://www.youtube.com/watch?v=dmHJJ5k_G-A
  1162. const text = runs[0].text;
  1163. const nlc = text.includes('\r\n') ? '\r\n' : text.includes('\n\r') ? '\n\r' : text.includes('\r') ? '\r' : '\n';
  1164. const s = text.split(nlc);
  1165. let bi = 0;
  1166. runs.length = s.length;
  1167. for (const text of s) {
  1168. runs[bi++] = { ...runs[0], text, ...{blockLine: true} };
  1169. }
  1170. }
  1171. for (const s of runs) {
  1172. s.text = _snippetText(s.text);
  1173. }
  1174. }
  1175.  
  1176. function translate(initialSegments) {
  1177. // 2023.07.13 - fix initialSegments with transcriptSectionHeaderRenderer
  1178.  
  1179. if (!initialSegments) return initialSegments;
  1180.  
  1181. if (TRANSLATE_DEBUG) {
  1182. console.log(12);
  1183. Promise.resolve(JSON.stringify(initialSegments)).then((r) => {
  1184. let obj = JSON.parse(r);
  1185. console.log(7558, 1, obj)
  1186. return obj;
  1187. }).then(p => {
  1188. let obj = _DEBUG_szz(p)
  1189. console.log(7558, 2, obj)
  1190. })
  1191. }
  1192.  
  1193.  
  1194. //let mapRej = new WeakSet();
  1195.  
  1196. const n1 = initialSegments.length;
  1197. if (!n1) return fRes;
  1198. let n2 = 0;
  1199.  
  1200.  
  1201. const fRes = new Array(n1);
  1202. // -----------------------------------------------------------------------------------------
  1203.  
  1204. const s8 = Symbol();
  1205.  
  1206. {
  1207.  
  1208. /** @type {Map<String, Object>} */
  1209. let cacheTexts = new Map(); // avoid duplicate with javascript object properties
  1210.  
  1211. // /-* * @type {Map<String, number>} *-/
  1212. // let mh1 = new Map(); // avoid duplicate with javascript object properties
  1213. // 1: ok
  1214. // 2: abandoned effect text
  1215.  
  1216. for (const initialSegment of initialSegments) {
  1217. const transcript = (initialSegment || 0).transcriptSegmentRenderer;
  1218. if (!transcript) {
  1219. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1220. fRes[n2++] = initialSegment;
  1221. continue;
  1222. }
  1223. const runs = transcript.snippet.runs
  1224. if (!runs || runs.length === 0) {
  1225. initialSegment[s8] = true;
  1226. continue;
  1227. }
  1228. let startMs = (+transcript.startMs || 0); //integer
  1229. let endMs = (+transcript.endMs || 0); //integer
  1230. if (startMs === endMs) {
  1231. // effect text
  1232. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1233. //mapRej.add(initialSegment)
  1234. continue;
  1235. }
  1236. if (endMs - startMs < 30) {
  1237. continue;
  1238. }
  1239. const text = snippetText(transcript.snippet);
  1240. const hEntry = cacheTexts.get(text);
  1241. const mh1e = hEntry === undefined ? 0 : hEntry === null ? 2 : 1;
  1242. if (mh1e === 2) continue;
  1243. const entry = {
  1244. startMs,
  1245. endMs,
  1246. initialSegment,
  1247. text
  1248. };
  1249. if (mh1e === 0) {
  1250. if (/^[,.\x60\x27\x22\u200b\xA0\x20;-]*$/.test(text)) {
  1251. initialSegment[s8] = true;
  1252. cacheTexts.set(text, null);
  1253. //effect only
  1254. // https://www.youtube.com/watch?v=zLak0dxBKpM
  1255. //mapRej.add(initialSegment)
  1256. continue;
  1257. }
  1258. } else if (hEntry) {
  1259.  
  1260. const timeDiff = entry.startMs - hEntry.endMs;
  1261. let shouldMerge = false;
  1262.  
  1263. if (timeDiff >= 0) {
  1264.  
  1265. if (timeDiff < 25) {
  1266. shouldMerge = true;
  1267. } else if (timeDiff < 450 && entry.endMs - entry.startMs < 900) {
  1268. shouldMerge = true;
  1269. } else if (timeDiff < 150 && entry.endMs - entry.startMs > 800) {
  1270. shouldMerge = true;
  1271. }
  1272.  
  1273. if (shouldMerge && hEntry.endMs <= endMs && startMs <= endMs) {
  1274. // abandon the current entry.
  1275. // absorbed by previous entry
  1276. hEntry.endMs = entry.endMs;
  1277. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1278. //mapRej.add(entry.initialSegment);
  1279. continue;
  1280. }
  1281.  
  1282. } else if (entry.startMs < hEntry.startMs && hEntry.startMs < entry.endMs) {
  1283.  
  1284. // abandon the current entry.
  1285. // absorbed by previous entry
  1286. if (entry.endMs > hEntry.endMs) {
  1287. hEntry.endMs = entry.endMs;
  1288. hEntry.initialSegment.transcriptSegmentRenderer.endMs = entry.initialSegment.transcriptSegmentRenderer.endMs; // update fRes & initialSegments as well using object reference
  1289. }
  1290. //mapRej.add(entry.initialSegment);
  1291. continue;
  1292.  
  1293. }
  1294.  
  1295. }
  1296. //if not abandoned
  1297. cacheTexts.set(text, entry); //replace the previous valid entry object if any
  1298. // for (const s of runs) {
  1299. // s.text = _snippetText(s.text);
  1300. // }
  1301. fixRuns(runs);
  1302. fRes[n2++] = initialSegment;
  1303. }
  1304.  
  1305. // cacheTexts.clear(); // let GC do it.
  1306. cacheTexts = null;
  1307. // mh1.clear(); // let GC do it.
  1308. // mh1 = null;
  1309.  
  1310. }
  1311.  
  1312. const si_length = fRes.length = n2;
  1313. const sj_length = n1;
  1314.  
  1315. if (si_length !== sj_length) { // for equal length, no fix is required & ignore spacing fix
  1316. // collect the abandon text to become second subtitle
  1317.  
  1318. let sj_start = 0;
  1319. let invalid_sj = -1;
  1320. for (let si = 0; si < si_length; si++) {
  1321. const segment = fRes[si];
  1322. let transcript = segment.transcriptSegmentRenderer;
  1323. if (!transcript) continue; // e.g. transcriptSectionHeaderRenderer
  1324. const runs = transcript.snippet.runs;
  1325. // fixRuns(runs);
  1326. if (runs.length > 1 || runs[0].text.includes('\n')) continue; // skip multi lines
  1327. const main_startMs = (+transcript.startMs || 0);
  1328. const main_endMs = (+transcript.endMs || 0);
  1329. transcript = null;
  1330.  
  1331. /** @type {Map<string, number>} */
  1332. let tMap = new Map(); // avoid duplicate with javascript object properties
  1333.  
  1334. // assume that it is asc-ordered array of key startMs;
  1335. for (let sj = sj_start; sj < sj_length; sj++) {
  1336. const initialSegment = initialSegments[sj];
  1337.  
  1338. if (!initialSegment || initialSegment[s8]) continue; // should invalid_sj be set ?
  1339.  
  1340. const tSegment = initialSegment.transcriptSegmentRenderer;
  1341.  
  1342. if (!tSegment) {
  1343. // https://www.youtube.com/watch?v=dmHJJ5k_G-A - transcriptSectionHeaderRenderer
  1344. invalid_sj = sj; // should invalid_sj be set ?
  1345. continue;
  1346. }
  1347.  
  1348. const startMs = (+tSegment.startMs || 0)
  1349. const isStartValid = startMs >= main_startMs;
  1350. if (!isStartValid) {
  1351. invalid_sj = sj;
  1352. continue;
  1353. }
  1354. // isStartValid must be true
  1355. if (startMs > main_endMs) {
  1356. sj_start = invalid_sj + 1;
  1357. break;
  1358. }
  1359.  
  1360. const endMs = (+tSegment.endMs || 0)
  1361. if (endMs <= main_endMs) {
  1362. const mt = snippetText(tSegment.snippet);
  1363. const prev = tMap.get(mt);
  1364. if (endMs >= startMs) {
  1365. tMap.set(mt, (prev || 0) + 1 + (endMs - startMs));
  1366. }
  1367. }
  1368.  
  1369. }
  1370.  
  1371. if (tMap.size <= 1) continue; // no second line
  1372. let rg = [...tMap.entries()]; // N x 2 2D-array [string,number][]
  1373. tMap = null;
  1374.  
  1375. // https://www.youtube.com/watch?v=Ud73fm4Uoq0
  1376.  
  1377. rg.sort((a, b) => b[1] - a[1]); //descending order of number
  1378.  
  1379. let targetZ = rg[1][1];
  1380. if (targetZ > 4) {
  1381. let az = 0;
  1382. let fail = false;
  1383. for (let idx = 2, rgl = rg.length; idx < rgl; idx++) {
  1384. az += rg[idx][1];
  1385. if (az >= targetZ) {
  1386. fail = true;
  1387. break;
  1388. }
  1389. }
  1390. if (!fail) {
  1391. const rgA = rg[0][0];
  1392. const rgB = rg[1][0];
  1393. const isDiff = rgB.replace(/\s/g, '') !== rgA.replace(/\s/g, '');
  1394. if (isDiff && rgA === _snippetText(runs[0].text)) {
  1395. if (runs[0] && runs[0].text) runs[0].blockLine = true;
  1396. runs.push({ text: rgB, blockLine: true });
  1397. }
  1398. }
  1399. }
  1400. rg = null;
  1401. }
  1402.  
  1403. TRANSLATE_DEBUG && Promise.resolve(fRes).then((r) => {
  1404.  
  1405. let obj = r;
  1406. console.log(7559, 1, obj)
  1407. return obj;
  1408. }).then(p => {
  1409. let obj = _DEBUG_szz(p)
  1410. console.log(7559, 2, obj)
  1411.  
  1412. });
  1413. }
  1414.  
  1415. // -----------------------------------------------------------------------------------------
  1416. snCache.clear();
  1417. return fRes;
  1418.  
  1419. }
  1420.  
  1421.  
  1422. return translate
  1423.  
  1424. }
  1425.  
  1426.  
  1427. let translateFn = null;
  1428.  
  1429. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && (() => {
  1430.  
  1431. const wmx = new WeakMap();
  1432.  
  1433. function fixSegments(ytObj) {
  1434. let a, b;
  1435. let seg = ((a = ytObj.data) == null ? void 0 : a[b = 'searchResultSegments']) || ((a = ytObj.data) == null ? void 0 : a[b = 'initialSegments']) || [];
  1436. if (!seg || !a || !b || typeof (seg || 0) !== 'object' || !Number.isFinite(seg.length * 1)) return;
  1437. translateFn = translateFn || getTranslate();
  1438. let cSeg;
  1439. cSeg = wmx.get(seg);
  1440. if (!cSeg) {
  1441. let vSeg = null;
  1442. try {
  1443. vSeg = translateFn(seg);
  1444. } catch (e) {
  1445. }
  1446. if (seg && typeof seg === 'object' && seg.length >= 1 && vSeg && typeof vSeg === 'object' && vSeg.length >= 1) {
  1447. // console.log('translated', vSeg);
  1448. cSeg = vSeg;
  1449. wmx.set(seg, cSeg);
  1450. wmx.set(cSeg, cSeg);
  1451. }
  1452. }
  1453. if (cSeg && cSeg !== seg) {
  1454. a[b] = cSeg;
  1455. }
  1456. }
  1457.  
  1458. const dfn = Symbol();
  1459. const Object_ = Object;
  1460. Object_[dfn] = Object_.defineProperties;
  1461. let activation = true;
  1462. Object_.defineProperties = function (obj, pds) {
  1463. let segments, get_;
  1464. if (activation && pds && (segments = pds.segments) && (get_ = segments.get)) {
  1465. activation = false;
  1466. segments.get = function () {
  1467. fixSegments(this);
  1468. return get_.call(this);
  1469. };
  1470. }
  1471. return Object_[dfn](obj, pds);
  1472. };
  1473.  
  1474. })();
  1475.  
  1476.  
  1477. let pf31 = new PromiseExternal();
  1478.  
  1479. // native RAF
  1480. let __requestAnimationFrame__ = typeof webkitRequestAnimationFrame === 'function' ? window.webkitRequestAnimationFrame.bind(window) : window.requestAnimationFrame.bind(window);
  1481.  
  1482. // 1st wrapped RAF
  1483. const baseRAF = (callback) => {
  1484. return p59 ? __requestAnimationFrame__(callback) : __requestAnimationFrame__((hRes) => {
  1485. pf31.then(() => {
  1486. callback(hRes);
  1487. });
  1488. });
  1489. };
  1490.  
  1491. // 2nd wrapped RAF
  1492. window.requestAnimationFrame = baseRAF;
  1493.  
  1494. const insp = o => o ? (o.polymerController || o.inst || o || 0) : (o || 0);
  1495. const indr = o => insp(o).$ || o.$ || 0;
  1496.  
  1497. const prototypeInherit = (d, b) => {
  1498. const m = Object.getOwnPropertyDescriptors(b);
  1499. for (const p in m) {
  1500. if (!Object.getOwnPropertyDescriptor(d, p)) {
  1501. Object.defineProperty(d, p, m[p]);
  1502. }
  1503. }
  1504. };
  1505.  
  1506.  
  1507. const firstObjectKey = (obj) => {
  1508. for (const key in obj) {
  1509. if (obj.hasOwnProperty(key) && typeof obj[key] === 'object') return key;
  1510. }
  1511. return null;
  1512. };
  1513.  
  1514. function searchNestedObject(obj, predicate, maxDepth = 64) {
  1515. // normal case: depth until 36
  1516. const result = [];
  1517. const visited = new WeakSet();
  1518.  
  1519. function search(obj, depth) {
  1520. visited.add(obj);
  1521. for (const [key, value] of Object.entries(obj)) {
  1522. // Recursively search nested objects and arrays
  1523. if (value !== null && typeof value === 'object') {
  1524. // Prevent infinite loops by checking if the object is already visited or depth exceeded
  1525. if (depth + 1 <= maxDepth && !visited.has(value)) {
  1526. search(value, depth + 1);
  1527. }
  1528. } else if (predicate(value)) {
  1529. result.push([obj, key]);
  1530. }
  1531. }
  1532. }
  1533.  
  1534. typeof (obj || 0) === 'object' && search(obj, 0);
  1535. return result;
  1536. }
  1537.  
  1538. /** @type {(o: Object | null) => WeakRef | null} */
  1539. const mWeakRef = typeof WeakRef === 'function' ? (o => o ? new WeakRef(o) : null) : (o => o || null);
  1540.  
  1541. /** @type {(wr: Object | null) => Object | null} */
  1542. const kRef = (wr => (wr && wr.deref) ? wr.deref() : wr);
  1543.  
  1544. const isIterable = (obj) => (Symbol.iterator in Object_(obj));
  1545.  
  1546. if (typeof Document.prototype.requestStorageAccessFor === 'function') {
  1547. if (DENY_requestStorageAccess) {
  1548. // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccessFor
  1549. Document.prototype.requestStorageAccessFor = undefined;
  1550. console.log('[yt-js-engine-tamer]', 'requestStorageAccessFor is removed.');
  1551. } else if (DISABLE_IFRAME_requestStorageAccess && window !== top) {
  1552. Document.prototype.requestStorageAccessFor = function () {
  1553. return new Promise((resolve, reject) => {
  1554. reject();
  1555. });
  1556. };
  1557. }
  1558. }
  1559.  
  1560. const traceStack = (stack) => {
  1561. let result = new Set();
  1562. let p = new Set();
  1563. let u = ''
  1564. for (const s of stack.split('\n')) {
  1565. if (s.split(':').length < 3) continue;
  1566. let m = /(([\w-_\.]+):\d+:\d+)[^:\r\n]*/.exec(s);
  1567. if (!m) continue;
  1568. p.add(m[2]);
  1569. if (p.size >= 3) break;
  1570. if(!u) u = m[2];
  1571. else if(p.size === 2 && u && u=== m[2]) break;
  1572. result.add(s);
  1573. }
  1574. return [...result].join('\n');
  1575. }
  1576.  
  1577. if (FIX_bind_self_this && !Function.prototype.bind488 && !Function.prototype.bind588) {
  1578. // window.m3bb = new Set();
  1579.  
  1580. // const smb = Symbol();
  1581. const vmb = 'dtz02' // Symbol(); // return kThis for thisArg
  1582. const vmc = 'dtz04' // Symbol(); // whether it is proxied fn
  1583. const vmd = 'dtz08' // Symbol(); // self fn proxy (fn--fn)
  1584.  
  1585. const thisConversionFn = (thisArg) => {
  1586. if (!thisArg) return null;
  1587. const kThis = thisArg[vmb];
  1588. if (kThis) {
  1589. const ref = kThis.ref;
  1590. return (ref ? kRef(ref) : null) || null;
  1591. }
  1592. return thisArg;
  1593. }
  1594.  
  1595. const pFnHandler2 = {
  1596. get(target, prop) {
  1597. if (prop === vmc) return target;
  1598. return Reflect.get(target, prop);
  1599. },
  1600. apply(target, thisArg, argumentsList) {
  1601. thisArg = thisConversionFn(thisArg);
  1602. if (thisArg) return Reflect.apply(target, thisArg, argumentsList);
  1603. }
  1604. }
  1605.  
  1606.  
  1607. const proxySelfHandler = {
  1608. get(target, prop) {
  1609. if(prop === vmb) return target;
  1610. const ref = target.ref;
  1611. const cnt = kRef(ref);
  1612. if (!cnt) return;
  1613. if (typeof cnt[prop] === 'function' && !cnt[prop][vmc] && !cnt[prop][vmb]) {
  1614. if (!cnt[prop][vmd]) cnt[prop][vmd] = new Proxy(cnt[prop], pFnHandler2);
  1615. return cnt[prop][vmd];
  1616. }
  1617. return cnt[prop];
  1618. },
  1619. set(target, prop, value) {
  1620. const cnt = kRef(target.ref);
  1621. if (!cnt) return true;
  1622. if(value && (value[vmc] || value[vmb])){
  1623. cnt[prop] = value[vmc] || thisConversionFn(value);
  1624. return true;
  1625. }
  1626. cnt[prop] = value;
  1627. return true;
  1628. }
  1629. };
  1630.  
  1631. const weakWrap = (thisArg) => {
  1632. thisArg = thisConversionFn(thisArg);
  1633. if (!thisArg) {
  1634. console.error('thisArg is not found');
  1635. return null;
  1636. }
  1637. return new Proxy({ ref: mWeakRef(thisArg) }, proxySelfHandler);
  1638. }
  1639.  
  1640. if (!window.getComputedStyle533 && typeof window.getComputedStyle === 'function') {
  1641. window.getComputedStyle533 = window.getComputedStyle;
  1642. window.getComputedStyle = function (a, ...args) {
  1643. a = thisConversionFn(a);
  1644. if (a) {
  1645. return getComputedStyle533(a, ...args);
  1646. }
  1647. return null;
  1648. }
  1649. }
  1650.  
  1651. Function._count_bind_00 = 0;
  1652. // Function._count_bind_01 = 0;
  1653.  
  1654. // let matchNativeCode = (Object+"");
  1655. // let matchNativeCode1 = matchNativeCode.includes("[native code]");
  1656. // let matchNativeLen = matchNativeCode.length - Object.name.length;
  1657.  
  1658. // const matchConstructor = (thisArg) => {
  1659. // const f = `${(thisArg || 0).constructor}`;
  1660. // if (f.length > 45) return true;
  1661. // if (matchNativeCode1 && f.length - thisArg.constructor.name.length === matchNativeLen) {
  1662. // if (f.includes('[native code]')){
  1663. // return false;
  1664. // }
  1665. // return true;
  1666. // }
  1667. // return false;
  1668. // }
  1669.  
  1670. // const acceptThis = (thisArg)=>{
  1671. // // if(!thisArg || typeof thisArg !=='object') return false;
  1672. // // // if((((thisArg||0).constructor||0).name || 'XXXXXXXX').length < 3) return true;
  1673. // // if(typeof thisArg.path === 'string') return true;
  1674. // // if(typeof thisArg.fn === 'function') return true;
  1675. // // if(typeof thisArg.id === 'string') return true;
  1676. // // if(typeof thisArg.isLoaded === 'boolean') return true;
  1677. // return false;
  1678. // }
  1679.  
  1680. const patchFn = (fn) => {
  1681.  
  1682. let s = `${fn}`;
  1683. if (s.length < 11 || s.includes('\n')) return false;
  1684. if(s.includes('bind(this')) return true;
  1685. if(s.includes('=this') && /[,\s][a-zA-Z_][a-zA-Z0-9_]*=this[;,]/.test(s) ) return true;
  1686. // var a=this;
  1687. // f.bind(this)
  1688.  
  1689.  
  1690. return false;
  1691. }
  1692.  
  1693. Function.prototype.bind488 = Function.prototype.bind;
  1694. Function.prototype.bind = function(thisArg, ...args){
  1695.  
  1696. if (thisConversionFn(thisArg) !== thisArg) {
  1697. return this.bind488(thisArg, ...args);
  1698. }
  1699. if( thisArg && patchFn(this) ){
  1700.  
  1701. // console.log(599,`${this}`)
  1702.  
  1703. try {
  1704. // let b1 = thisArg && typeof thisArg === 'object' && typeof thisArg.isAttached === 'boolean' && !thisArg.dtz06; // ready cnt
  1705. // let b2 = !b1 && thisArg && (thisArg instanceof Node) && typeof thisArg.nodeName === 'string' && !thisArg.dtz06; // dom
  1706. // let b3 = !b1 && !b2 && thisArg && typeof thisArg === 'object' && typeof thisArg.is === 'string' && !thisArg.dtz06; // init stage ?
  1707. // // let b4 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && matchConstructor(thisArg);
  1708. // // let b5 = !b1 && !b2 && !b3 && !b4 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && acceptThis(thisArg);
  1709. // // let b5 = !b1 && !b2 && !b3 && thisArg && typeof thisArg === 'object' && !thisArg.dtz06 && !(thisArg instanceof Window);
  1710. // // let b4 = false;
  1711. // let b4 = !b1 && !b2 && !b3 && thisArg && !thisArg.dtz06;
  1712.  
  1713. // // b3 = false;
  1714. // // b4 = false;
  1715. // // b5 = false;
  1716.  
  1717. // if (b1 || b2 || b3 ||b4 ) {
  1718. const f = this;
  1719. const ps = thisArg.__proxySelf0__ || (thisArg.__proxySelf0__ = weakWrap(thisArg));
  1720. if (ps && ps[vmb]) {
  1721. Function._count_bind_00++;
  1722. return f.bind488(ps, ...args)
  1723. }
  1724. // }
  1725. } catch (e) {
  1726. console.warn(e)
  1727. }
  1728. }
  1729. return this.bind488(thisArg, ...args);
  1730. }
  1731. Function.prototype.bind588 = 1;
  1732. }
  1733.  
  1734. const ytSchedulerMethods = {
  1735. addJob(a, b, c) {
  1736. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1737. if (instance) {
  1738. return instance.addJob(a, b, c);
  1739. } else {
  1740. return setTimeout(a, c);
  1741. }
  1742. },
  1743. addImmediateJob(a) {
  1744. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1745. if (instance) {
  1746. return instance.addImmediateJob(a);
  1747. } else {
  1748. a();
  1749. }
  1750. },
  1751. cancelJob(id) {
  1752. const instance = typeof yt !== 'undefined' ? ((yt || 0).scheduler || 0).instance : null;
  1753. if (instance) {
  1754. return instance.cancelJob(id);
  1755. } else {
  1756. return clearTimeout(id);
  1757. }
  1758. }
  1759. };
  1760.  
  1761. if (FIX_ytScheduler) {
  1762.  
  1763. let ytSchedulerFixed = 0;
  1764. // let ytActioned = false;
  1765. // let pr = new PromiseExternal();
  1766.  
  1767. // const hn = function () {
  1768.  
  1769. // document.removeEventListener('yt-action', hn, true);
  1770. // nextBrowserTick_(() => {
  1771. // ytActioned = true;
  1772. // pr.resolve();
  1773. // });
  1774.  
  1775. // }
  1776. // document.addEventListener('yt-action', hn, true);
  1777.  
  1778. // let cancelStore = {}; // tbc
  1779.  
  1780. // yt.scheduler.instance.addJob
  1781. const fixAddJob = (nv) => {
  1782.  
  1783. /*
  1784. function Z() {
  1785. var a = w("ytglobal.schedulerInstanceInstance_");
  1786. if (!a || a.s)
  1787. a = new M(I("scheduler") || {}),
  1788. x("ytglobal.schedulerInstanceInstance_", a);
  1789. return a
  1790. }
  1791. */
  1792.  
  1793. /*
  1794. function R(a, b, c, d) {
  1795. ++a.D;
  1796. if (c === 10)
  1797. return P(a, b),
  1798. a.D;
  1799. var e = a.D;
  1800. a.h[e] = b;
  1801. a.l && !d ? a.u.push({
  1802. id: e,
  1803. priority: c
  1804. }) : (a.i[c].push(e),
  1805. a.C || a.l || (a.g !== 0 && S(a) !== a.m && T(a),
  1806. a.start()));
  1807. return e
  1808. }
  1809. */
  1810.  
  1811. /*
  1812. function sa(a, b, c) {
  1813. if (!c)
  1814. return c = c === void 0,
  1815. -R(Z(), a, b, c);
  1816. var d = window.setTimeout(function() {
  1817. var e = R(Z(), a, b);
  1818. W[d] = e
  1819. }, c);
  1820. return d
  1821. }
  1822. */
  1823. window.originalAddJob = nv;
  1824. // const q1 = new PromiseExternal();
  1825. // const q2 = new PromiseExternal();
  1826. // let uu = 0;
  1827. // let q3 = 0;
  1828. // let mof = null;
  1829. // const mo = new MutationObserver((mutation, observer) => {
  1830. // if (mof) {
  1831. // if (mof() === true) {
  1832. // observer.disconnect();
  1833. // mof = null;
  1834. // }
  1835. // }
  1836. // });
  1837.  
  1838. let lenSkip = -1;
  1839. let lastLen = null;
  1840. let fetchCommentJobTimerId = 0;
  1841.  
  1842. const fetchCommentJobDone = ()=>{
  1843. clearInterval(fetchCommentJobTimerId);
  1844. fetchCommentJobTimerId = 0;
  1845. console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1846. }
  1847.  
  1848. const fetchCommentJob = (a, cid) => {
  1849.  
  1850. // if (cid && cancelStore[cid]) return; // tbc
  1851.  
  1852. if (fetchCommentJobTimerId > 0) {
  1853. fetchCommentJobDone();
  1854. // mof = null;
  1855. }
  1856.  
  1857. // if (mof) {
  1858. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1859. // mof = null;
  1860. // }
  1861.  
  1862. let f = a;
  1863.  
  1864. const selector = 'ytd-comments, ytd-comments > *, ytd-comments [id] > *, ytd-comments ytd-continuation-item-renderer';
  1865.  
  1866. console.log('[yt-js-engine-tamer] fetchCommentJob start');
  1867.  
  1868. lastLen = -1;
  1869. let u = 0;
  1870. let g = () => {
  1871. const lastLen_ = lastLen;
  1872. const len1 = lastLen = document.querySelectorAll(selector).length;
  1873. let mm = true;
  1874. let ff = false;
  1875. if (len1 !== lastLen_) {
  1876. u = 0;
  1877. f();
  1878. const len2 = lastLen = document.querySelectorAll(selector).length;
  1879. if (len2 !== len1) {
  1880. ff = true;
  1881. mm = false;
  1882. }
  1883. }
  1884. if (mm) {
  1885. ++u;
  1886. if (u > 10 || document.querySelector('ytd-comments:not([hidden]) [id]')) {
  1887. ff = true;
  1888. }
  1889. }
  1890. if (ff) {
  1891. fetchCommentJobDone();
  1892. }
  1893. }
  1894.  
  1895.  
  1896. fetchCommentJobTimerId = setInterval(g, 80);
  1897. // g(9);
  1898. // if (lastLen === lenSkip) {
  1899. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1900. // g = f = null;
  1901. // return;
  1902. // }
  1903. // console.log('[yt-js-engine-tamer] fetchCommentJob done');
  1904. // const q1 = lastLen;
  1905. // mof = () => {
  1906. // const q2 = document.querySelectorAll(selector).length;
  1907. // if (q1 === q2) return;
  1908. // fetchCommentJobTimerId = setTimeout(g, 80);
  1909. // g = null;
  1910. // return true;
  1911. // }
  1912. // mo.observe(document, { childList: true, subtree: true });
  1913.  
  1914. }
  1915.  
  1916.  
  1917.  
  1918. return function (a, b, c) {
  1919.  
  1920. if (!c) return nv(a, b, c);
  1921.  
  1922. const c_ = c;
  1923.  
  1924. if (c > 0.2 && (c % 1) === c) c -= 0.125;
  1925.  
  1926. if (!b && c_ === 5000 && `${a}`.includes('.cleanupJob=0')) {
  1927. try {
  1928. yt.scheduler.instance.cancelAllJobs();
  1929. yt.scheduler.instance.dispose();
  1930. ytglobal.schedulerInstanceInstance_.dispose();
  1931. console.log('[yt-js-engine-tamer] cleanupJob');
  1932. } catch (e) { }
  1933. return nv(a, b, c);
  1934. }
  1935.  
  1936. // if(!b && c > 50) c = 50;
  1937. // console.log(58372,a,b,c)
  1938. // function(){xxx(xxx)}
  1939. if (`${a}`.length <= 20 && !b && c_ === 1000 && a.name === '' && /function\(\)\{\w{1,3}\(\w{1,3}\)\}/.test(`${a}`)) {
  1940.  
  1941. /*
  1942.  
  1943. V.setCommentsJobId = _.et(_.r0, function() {
  1944. F5V(V)
  1945. }, 1E3)
  1946.  
  1947. */
  1948.  
  1949. const cid = nv(() => { }, b, 1.125);
  1950.  
  1951. // lastLen = null;
  1952. fetchCommentJob(a, cid);
  1953.  
  1954. // queueMicrotask_(a);
  1955. // nextBrowserTick_(a);
  1956. // a(); // no need to delay
  1957. return cid
  1958.  
  1959. // return nv(a, b, 1.125);
  1960. // const cid = window.setTimeout(() => {
  1961. // nextBrowserTick_(() => {
  1962. // if (cancelStore[cid]) {
  1963. // console.log('task cancelled');
  1964. // return;
  1965. // }
  1966. // a();
  1967.  
  1968. // });
  1969. // }, 0.125);
  1970. // return cid;
  1971. } else {
  1972.  
  1973.  
  1974.  
  1975. return nv(a,b,c);
  1976.  
  1977.  
  1978. // if (c > 2400) c = 2400;
  1979. // else if (c > 800) c = 800;
  1980. // if (c > 0.2 && (c % 1) === c) c -= 0.125;
  1981. // if (0 && ytActioned && !b) {
  1982. // const cid = window.setTimeout(() => {
  1983. // nextBrowserTick_(() => {
  1984. // if (cancelStore[cid]) {
  1985. // console.log('task cancelled');
  1986. // return;
  1987. // }
  1988. // a();
  1989. // });
  1990. // }, c);
  1991. // return cid;
  1992. // } else {
  1993. // return nv(a, b, c);
  1994. // }
  1995.  
  1996. }
  1997. }
  1998. }
  1999.  
  2000. const fixCancelJob = (nv) => {
  2001.  
  2002.  
  2003. window.originalCancelJob = nv;
  2004. return function (a) {
  2005. if (a < 0) return nv(a);
  2006. // cancelStore[a] = true; // tbc
  2007. nv(a);
  2008. }
  2009. }
  2010.  
  2011. const sk44 = Symbol();
  2012. Object.defineProperty(Object.prototype, 'addJob', {
  2013. get() {
  2014. return this[sk44];
  2015. },
  2016. set(nv) {
  2017. if (typeof nv === 'function' && !(ytSchedulerFixed & 1) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2018. ytSchedulerFixed |= 1;
  2019. nv = fixAddJob(nv);
  2020. }
  2021. this[sk44] = nv;
  2022. return true;
  2023. },
  2024. enumerable: false,
  2025. configurable: true
  2026. });
  2027.  
  2028.  
  2029.  
  2030. const sk45 = Symbol();
  2031. Object.defineProperty(Object.prototype, 'cancelJob', {
  2032. get() {
  2033. return this[sk45];
  2034. },
  2035. set(nv) {
  2036. if (typeof nv === 'function' && !(ytSchedulerFixed & 2) && typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2037. ytSchedulerFixed |= 2;
  2038. nv = fixCancelJob(nv);
  2039. }
  2040. this[sk45] = nv;
  2041. return true;
  2042. },
  2043. enumerable: false,
  2044. configurable: true
  2045. });
  2046.  
  2047.  
  2048.  
  2049. if (typeof yt !== 'undefined' && this === ((yt || 0).scheduler || 0).instance) {
  2050. const { addJob, cancelJob } = yt.scheduler.instance;
  2051. if (addJob) {
  2052. yt.scheduler.instance.addJob = null;
  2053. yt.scheduler.instance.addJob = addJob;
  2054. }
  2055. if (cancelJob) {
  2056. yt.scheduler.instance.cancelJob = null;
  2057. yt.scheduler.instance.cancelJob = cancelJob;
  2058. }
  2059. }
  2060.  
  2061.  
  2062. }
  2063.  
  2064.  
  2065. if (FIX_weakMap_weakRef && !window.WeakMapOriginal && typeof window.WeakMap === 'function' && typeof WeakRef === 'function') {
  2066. const WeakMapOriginal = window.WeakMapOriginal = window.WeakMap;
  2067. const wm6 = new WeakMapOriginal();
  2068.  
  2069. const skipW = new WeakSet();
  2070.  
  2071.  
  2072. window.WeakMap = class WeakMap extends WeakMapOriginal {
  2073. constructor(iterable = undefined) {
  2074. super();
  2075. if (iterable && iterable[Symbol.iterator]) {
  2076. for (const entry of iterable) {
  2077. entry && this.set(entry[0], entry[1]);
  2078. }
  2079. }
  2080. }
  2081. delete(a) {
  2082. if (!this.has(a)) return false;
  2083. super.delete(a);
  2084. return true;
  2085. }
  2086. get(a) {
  2087. const p = super.get(a);
  2088. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  2089. let v = kRef(p);
  2090. if (!v) {
  2091. super.delete(a);
  2092. }
  2093. return v || undefined;
  2094. }
  2095. return p;
  2096. }
  2097. has(a) {
  2098. if (!super.has(a)) return false;
  2099. const p = super.get(a);
  2100. if (p && typeof p === 'object' && p.deref && !skipW.has(p)) {
  2101. if (!kRef(p)) {
  2102. super.delete(a);
  2103. return false;
  2104. }
  2105. }
  2106. return true;
  2107. }
  2108. set(a, b) {
  2109. let wq = b;
  2110. if (b && (typeof b === 'function' || typeof b === 'object')) {
  2111. if (b.deref) {
  2112. skipW.add(b);
  2113. wq = b;
  2114. } else {
  2115. wq = wm6.get(b);
  2116. if (!wq) {
  2117. wq = mWeakRef(b);
  2118. wm6.set(b, wq);
  2119. }
  2120. }
  2121. }
  2122. super.set(a, wq);
  2123. return this;
  2124. }
  2125. }
  2126. Object.defineProperty(window.WeakMap, Symbol.toStringTag, {
  2127. configurable: true,
  2128. enumerable: false,
  2129. value: "WeakMap",
  2130. writable: false
  2131. });
  2132. }
  2133.  
  2134. const isWatchPageURL = (url) => {
  2135. url = url || location;
  2136. return location.pathname === '/watch' || location.pathname.startsWith('/live/')
  2137. };
  2138.  
  2139. const isCustomElementsProvided = typeof customElements !== "undefined" && typeof (customElements || 0).whenDefined === "function";
  2140.  
  2141. const promiseForCustomYtElementsReady = isCustomElementsProvided ? Promise.resolve(0) : new Promise((callback) => {
  2142. const EVENT_KEY_ON_REGISTRY_READY = "ytI-ce-registry-created";
  2143. if (typeof customElements === 'undefined') {
  2144. if (!('__CE_registry' in document)) {
  2145. // https://github.com/webcomponents/polyfills/
  2146. Object.defineProperty(document, '__CE_registry', {
  2147. get() {
  2148. // return undefined
  2149. },
  2150. set(nv) {
  2151. if (typeof nv == 'object') {
  2152. delete this.__CE_registry;
  2153. this.__CE_registry = nv;
  2154. this.dispatchEvent(new CustomEvent(EVENT_KEY_ON_REGISTRY_READY));
  2155. }
  2156. return true;
  2157. },
  2158. enumerable: false,
  2159. configurable: true
  2160. })
  2161. }
  2162. let eventHandler = (evt) => {
  2163. document.removeEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2164. const f = callback;
  2165. callback = null;
  2166. eventHandler = null;
  2167. f();
  2168. };
  2169. document.addEventListener(EVENT_KEY_ON_REGISTRY_READY, eventHandler, false);
  2170. } else {
  2171. callback();
  2172. }
  2173. });
  2174.  
  2175. const whenCEDefined = isCustomElementsProvided
  2176. ? (nodeName) => customElements.whenDefined(nodeName)
  2177. : (nodeName) => promiseForCustomYtElementsReady.then(() => customElements.whenDefined(nodeName));
  2178.  
  2179. FIX_perfNow && performance.timeOrigin > 9 && (() => {
  2180. if (performance.now23 || performance.now16 || typeof Performance.prototype.now !== 'function') return;
  2181. const f = performance.now23 = Performance.prototype.now;
  2182.  
  2183. let k = 0; // 0 <= k < 9998m
  2184. let u = 0;
  2185. let s = ((performance.timeOrigin % 7) + 1) / 7 - 1e-2 / 7; // s > 0.14
  2186.  
  2187. // By definition, performance.now() is mono increasing.
  2188. // Fixing in YouTube.com is required to ensure performance.now() is strictly increasing.
  2189. performance.now = performance.now16 = function () {
  2190. /**
  2191. * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same
  2192. *
  2193. * If consecutive session history entries had history.state.entryTime set to same value,
  2194. * back button doesn't work as expected. The entryTime value is coming from performance.now()
  2195. * and modifying its return value slightly to make sure two close consecutive calls don't
  2196. * get the same result helped with resolving the issue.
  2197. */
  2198. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1756970
  2199. // see https://bugzilla.mozilla.org/show_bug.cgi?id=1842437
  2200.  
  2201. const v = typeof (this || 0).now23 === 'function' ? this.now23() + s : f.call(performance) + s; // v > 0.14
  2202. if (u + 0.0015 < (u = v)) k = 0; // note: hRes should be accurate to 5 µs in isolated contexts
  2203. else if (k < 0.001428) k += 1e-6 / 7; // M = 10000 * m; m * 9996 = 0.001428
  2204. else { // more than 9998 consecutive calls
  2205. /**
  2206. *
  2207. * max no. of consecutive calls
  2208. *
  2209. * Sample Size: 4800
  2210. * Sample Avg = 1565.375
  2211. * Sample Median = 1469.5
  2212. * Sample Max = 5660 << 7500 << 9999
  2213. *
  2214. *
  2215. * */
  2216. k = 0;
  2217. s += 1 / 7;
  2218. }
  2219. return v + k; // 0 < v - M < v - M + k < v
  2220. }
  2221.  
  2222. let loggerMsg = '';
  2223. if (`${performance.now()}` === `${performance.now()}`) {
  2224. const msg1 = 'performance.now is modified but performance.now() is not strictly increasing.';
  2225. const msg2 = 'performance.now cannot be modified and performance.now() is not strictly increasing.';
  2226. loggerMsg = performance.now !== performance.now16 ? msg1 : msg2; // might not able to set in Firefox
  2227. }
  2228. loggerMsg && console.warn(loggerMsg);
  2229. })();
  2230.  
  2231. FIX_removeChild && (() => {
  2232. if (typeof Node.prototype.removeChild === 'function' && typeof Node.prototype.removeChild062 !== 'function') {
  2233. const fragD = document.createDocumentFragment();
  2234. Node.prototype.removeChild062 = Node.prototype.removeChild;
  2235. Node.prototype.removeChild = function (child) {
  2236. if (typeof this.__shady_native_removeChild !== 'function' || ((child instanceof Node) && child.parentNode === this)) {
  2237. let ok = false;
  2238. try {
  2239. this.removeChild062(child);
  2240. ok = true;
  2241. } catch (e) {
  2242.  
  2243. }
  2244. if (!ok) {
  2245. try {
  2246. fragD.appendChild(child)
  2247. } catch (e) {
  2248. console.warn(e);
  2249. }
  2250. try {
  2251. child.remove();
  2252. } catch (e) {
  2253. console.warn(e);
  2254. }
  2255. }
  2256. } else if ((child instanceof Element) && child.is === 'tp-yt-paper-tooltip') {
  2257. // tooltip bug
  2258. } else {
  2259. console.warn('[yt-js-engine-tamer] Node is not removed from parent', { parent: this, child: child })
  2260. }
  2261. return child;
  2262. }
  2263. }
  2264. })();
  2265.  
  2266.  
  2267. FIX_VIDEO_PLAYER_MOUSEHOVER_EVENTS && !isChatRoomURL && (() => {
  2268.  
  2269. const [setIntervalX0, clearIntervalX0] = [setInterval, clearInterval];
  2270.  
  2271. // let cid = 0;
  2272.  
  2273. let mousemoveFn = null;
  2274. let mousemoveDT = 0;
  2275. let mousemoveCount = 0;
  2276. // let qv = false;
  2277. const cif = () => {
  2278. if (!mousemoveFn) return;
  2279. const ct = Date.now();
  2280. if (mousemoveDT + 1200 > ct) { // avoid setTimeout delay too long without execution
  2281. mousemoveFn && mousemoveFn();
  2282. }
  2283. mousemoveFn = null;
  2284. };
  2285. let mousemoveCId = 0;
  2286. let mouseoverFn = null;
  2287. HTMLElement_.prototype.addEventListener4882 = HTMLElement_.prototype.addEventListener;
  2288. HTMLElement_.prototype.addEventListener = function (a, b, c) {
  2289. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2290. const bt = `${b}`;
  2291. if (bt.length >= 61 && bt.length <= 71 && bt.startsWith('function(){try{return ') && bt.includes('.apply(this,arguments)}catch(')) {
  2292. b[`__$$${a}$$1926__`] = true;
  2293. this[`__$$${a}$$1937__`] = (this[`__$$${a}$$1937__`] || 0) + 1;
  2294. if (this[`__$$${a}$$1937__`] > 1073741823) this[`__$$${a}$$1937__`] -= 536870911;
  2295. // console.log(3928, a, this[`__$$${a}$$1937__`])
  2296. if (!this[`__$$${a}$$1938__`]) {
  2297. this[`__$$${a}$$1938__`] = b;
  2298. if (a === 'mousemove') {
  2299. this.addEventListener4882('mouseenter', (evt) => {
  2300. if (mousemoveCId) return;
  2301. mousemoveCId = setIntervalX0(cif, 380);
  2302. });
  2303. this.addEventListener4882('mouseleave', (evt) => {
  2304. clearIntervalX0(mousemoveCId);
  2305. mousemoveCId = 0;
  2306. });
  2307. }
  2308. this.addEventListener4882(a, (evt) => {
  2309. const evt_ = evt;
  2310. if (!this[`__$$${a}$$1937__`]) return;
  2311. if (!this[`__$$${a}$$1938__`]) return;
  2312. if (a === 'mousemove') {
  2313. mouseoverFn && mouseoverFn();
  2314. if (mousemoveDT + 350 > (mousemoveDT = Date.now())) {
  2315. (++mousemoveCount > 1e9) && (mousemoveCount = 9);
  2316. } else {
  2317. mousemoveCount = 0;
  2318. }
  2319. const f = mousemoveFn = () => {
  2320. if (f !== mousemoveFn) return;
  2321. mousemoveFn = null;
  2322. this[`__$$${a}$$1938__`](evt_);
  2323. };
  2324. if (mousemoveCount <= 1) mousemoveFn();
  2325. } else {
  2326. if (a === 'mouseout' || a === 'mouseleave') {
  2327. mousemoveFn = null;
  2328. mousemoveDT = 0;
  2329. mousemoveCount = 0;
  2330. this[`__$$${a}$$1938__`](evt_);
  2331. mouseoverFn && mouseoverFn();
  2332. } else { // mouseover, mouseenter
  2333. mousemoveFn = null;
  2334. mousemoveDT = 0;
  2335. mousemoveCount = 0;
  2336. mouseoverFn && mouseoverFn(); // just in case
  2337. const f = mouseoverFn = () => {
  2338. if (f !== mouseoverFn) return;
  2339. mouseoverFn = null;
  2340. this[`__$$${a}$$1938__`](evt_);
  2341. }
  2342. nextBrowserTick_(mouseoverFn);
  2343. }
  2344. }
  2345. }, c);
  2346.  
  2347.  
  2348. return;
  2349. } else {
  2350.  
  2351. return;
  2352. }
  2353. }
  2354.  
  2355. }
  2356. return this.addEventListener4882(a, b, c)
  2357. }
  2358.  
  2359.  
  2360.  
  2361.  
  2362. HTMLElement_.prototype.removeEventListener4882 = HTMLElement_.prototype.removeEventListener;
  2363. HTMLElement_.prototype.removeEventListener = function (a, b, c) {
  2364. if (this.id == 'movie_player' && `${a}`.startsWith('mouse') && c === undefined) {
  2365.  
  2366. if (b[`__$$${a}$$1926__`]) {
  2367. b[`__$$${a}$$1926__`] = false;
  2368.  
  2369. if (this[`__$$${a}$$1937__`]) this[`__$$${a}$$1937__`] -= 1;
  2370.  
  2371. // console.log(3929, a, this[`__$$${a}$$1937__`], b[`__$$${a}$$1926__`])
  2372.  
  2373. return;
  2374.  
  2375. }
  2376.  
  2377. }
  2378. return this.removeEventListener4882(a, b, c)
  2379. }
  2380.  
  2381.  
  2382. })();
  2383.  
  2384.  
  2385. FIX_DOM_IF_REPEAT && (() => {
  2386. // https://www.youtube.com/s/desktop/26a583e4/jsbin/live_chat_polymer.vflset/live_chat_polymer.js
  2387. // DOM-IF is still a core class of Polymer, so no polymerController is available.
  2388. // Be careful of the mixture of polymer functions and native Element functions
  2389. // Be careful of the coding design is different with the modern Yt elements
  2390.  
  2391.  
  2392. /*
  2393.  
  2394.  
  2395. function Ks(a, b, c) {
  2396. if (kj && !BOa(a))
  2397. throw Error("strictTemplatePolicy: template owner not trusted");
  2398. c = c || {};
  2399. if (a.__templatizeOwner)
  2400. throw Error("A <template> can only be templatized once");
  2401. a.__templatizeOwner = b;
  2402. var d = (b ? b.constructor : Js)._parseTemplate(a)
  2403. , e = d.templatizeInstanceClass;
  2404. e || (e = COa(a, d, c),
  2405. d.templatizeInstanceClass = e);
  2406. var g = BOa(a);
  2407. EOa(a, d, c, g);
  2408. c = function() {
  2409. return e.apply(this, arguments) || this
  2410. }
  2411. ;
  2412. h(c, e);
  2413. c.prototype._methodHost = g;
  2414. c.prototype.__dataHost = a;
  2415. c.prototype.__templatizeOwner = b;
  2416. c.prototype.__hostProps = d.hostProps;
  2417. return c
  2418. }
  2419.  
  2420. */
  2421.  
  2422. // Polymer.enqueueDebouncer
  2423.  
  2424. const s81 = Symbol();
  2425. const s83 = Symbol();
  2426. const s84 = Symbol();
  2427. const s85 = Symbol();
  2428. const s85b = Symbol();
  2429. const s85c = Symbol();
  2430.  
  2431. let renderDebounceTs = null;
  2432.  
  2433. let renderDebouncePromise = null;
  2434. let qp;
  2435.  
  2436. let cme = 0;
  2437.  
  2438. const shadyFlushMO = new MutationObserver(() => {
  2439.  
  2440. if (!renderDebounceTs) return;
  2441.  
  2442. if (renderDebounceTs.size > 0) {
  2443. console.warn('renderDebounceTs.size is incorect', renderDebounceTs.size);
  2444. try {
  2445. Polymer.flush();
  2446. return;
  2447. } catch (e) { }
  2448. }
  2449.  
  2450. renderDebouncePromise && Promise.resolve().then(() => {
  2451.  
  2452. if (renderDebouncePromise) {
  2453. renderDebouncePromise && renderDebouncePromise.resolve();
  2454. renderDebouncePromise = null;
  2455. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by MutationObserver')
  2456. }
  2457.  
  2458. });
  2459.  
  2460. // Polymer.flush
  2461.  
  2462. window.ShadyDOM && ShadyDOM.flush();
  2463. window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush();
  2464.  
  2465.  
  2466. });
  2467.  
  2468. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2469.  
  2470. const observablePromise = (proc, timeoutPromise) => {
  2471. let promise = null;
  2472. return {
  2473. obtain() {
  2474. if (!promise) {
  2475. promise = new Promise(resolve => {
  2476. let mo = null;
  2477. const f = () => {
  2478. let t = proc();
  2479. if (t) {
  2480. mo.disconnect();
  2481. mo.takeRecords();
  2482. mo = null;
  2483. resolve(t);
  2484. }
  2485. }
  2486. mo = new MutationObserver(f);
  2487. mo.observe(document, { subtree: true, childList: true })
  2488. f();
  2489. timeoutPromise && timeoutPromise.then(() => {
  2490. resolve(null)
  2491. });
  2492. });
  2493. }
  2494. return promise
  2495. }
  2496. }
  2497. }
  2498.  
  2499.  
  2500. let p = 0;
  2501. qp = observablePromise(() => {
  2502. if (!(p & 1)) {
  2503.  
  2504. if (window.ShadyDOM && ShadyDOM.flush) {
  2505. p |= 1;
  2506. if (!ShadyDOM.flush847) {
  2507.  
  2508. ShadyDOM.flush847 = ShadyDOM.flush;
  2509. ShadyDOM.flush = function () {
  2510.  
  2511. DEBUG_xx847 && console.log('xx847 ShadyDOM.flush')
  2512. renderDebouncePromise && Promise.resolve().then(() => {
  2513. if (renderDebouncePromise) {
  2514.  
  2515. renderDebouncePromise && renderDebouncePromise.resolve();
  2516. renderDebouncePromise = null;
  2517.  
  2518. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ShadyDOM.flush')
  2519.  
  2520. }
  2521.  
  2522. });
  2523. let r = this.flush847(...arguments);
  2524. if (r) {
  2525. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2526. }
  2527. return r
  2528. }
  2529.  
  2530. }
  2531. }
  2532. }
  2533.  
  2534. if (!(p & 2)) {
  2535.  
  2536. if (window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush) {
  2537. p |= 2;
  2538. const ScopingShim = window.ShadyCSS && window.ShadyCSS.ScopingShim;
  2539. if (!ScopingShim.flush848) {
  2540.  
  2541. ScopingShim.flush848 = ScopingShim.flush;
  2542. ScopingShim.flush = function () {
  2543.  
  2544. DEBUG_xx847 && console.log('xx847 ScopingShim.flush')
  2545.  
  2546. renderDebouncePromise && Promise.resolve().then(() => {
  2547.  
  2548. if (renderDebouncePromise) {
  2549.  
  2550. renderDebouncePromise && renderDebouncePromise.resolve();
  2551. renderDebouncePromise = null;
  2552.  
  2553. DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by ScopingShim.flush')
  2554.  
  2555.  
  2556.  
  2557. }
  2558.  
  2559. });
  2560. return this.flush848(...arguments);
  2561. }
  2562.  
  2563. }
  2564. }
  2565. }
  2566. if (p === 3) {
  2567. p |= 8;
  2568.  
  2569. let r = (window.ShadyDOM && ShadyDOM.flush && ShadyDOM.flush847
  2570. && window.ShadyCSS && window.ShadyCSS.ScopingShim &&
  2571. window.ShadyCSS.ScopingShim.flush && window.ShadyCSS.ScopingShim.flush848);
  2572.  
  2573. if (r) {
  2574. let w = Set.prototype.add;
  2575. let u = null;
  2576. Set.prototype.add = function () {
  2577. u = this;
  2578. throw new Error();
  2579. }
  2580. try {
  2581. Polymer.enqueueDebouncer()
  2582. } catch (e) { }
  2583. Set.prototype.add = w;
  2584. if (u !== null) {
  2585. renderDebounceTs = u;
  2586. if (DEBUG_renderDebounceTs) {
  2587. renderDebounceTs.add58438 = renderDebounceTs.add;
  2588. renderDebounceTs.add = function () {
  2589. console.log('renderDebounceTs.add')
  2590. console.log(traceStack((new Error()).stack))
  2591. // debugger;
  2592. return this.add58438(...arguments)
  2593. }
  2594.  
  2595. renderDebounceTs.delete58438 = renderDebounceTs.delete;
  2596. renderDebounceTs.delete = function () {
  2597. console.log('renderDebounceTs.delete')
  2598. const stack = `${(new Error()).stack}`
  2599. let isCallbackRemoval = false;
  2600. if (stack) {
  2601. let t = stack.replace(/[^\r\n]+renderDebounceTs\.delete[^\r\n]+/, '').replace('://','');
  2602. const s = t.split(':');
  2603. if (s.length === 3 && +s[1] > 0 && +s[2] > 0) {
  2604. isCallbackRemoval = true;
  2605. }
  2606. }
  2607. if (isCallbackRemoval) {
  2608. return this.delete58438(...arguments)
  2609. }
  2610. console.log(traceStack((new Error()).stack))
  2611. // debugger;
  2612. return this.delete58438(...arguments)
  2613. }
  2614. }
  2615. DEBUG_renderDebounceTs && (window.renderDebounceTs = renderDebounceTs);
  2616. console.log('renderDebounceTs', renderDebounceTs, `debug=${DEBUG_renderDebounceTs}`);
  2617. }
  2618. }
  2619.  
  2620. return true;
  2621. }
  2622. })
  2623.  
  2624. // if(window.ShadyDOM && ShadyDOM.flush){
  2625. // console.log('FIX_DOM_IF_RenderDebouncerChange X1')
  2626.  
  2627. // }
  2628. // if(window.ShadyCSS && window.ShadyCSS.ScopingShim && window.ShadyCSS.ScopingShim.flush){
  2629.  
  2630. // console.log('FIX_DOM_IF_RenderDebouncerChange X2')
  2631. // }
  2632.  
  2633. // console.log('FIX_DOM_IF_RenderDebouncerChange X3')
  2634.  
  2635. }
  2636.  
  2637. Object.defineProperty(Object.prototype, '_lastIf', {
  2638. get() {
  2639. return this[s81];
  2640. },
  2641. set(nv) {
  2642. if (nv === false && this.nodeName === "DOM-IF" && this.__renderDebouncer === null && this[s81] === undefined) {
  2643. // DOM-IF initialization
  2644. nv = null; // avoid (this.if == this._lastIf) primitive type conversion (object vs false)
  2645.  
  2646. this.__xiWB8__ = 2;
  2647.  
  2648. const cProto = this.__proto__;
  2649. if (cProto && !cProto.__xiWB7__) {
  2650. cProto.__xiWB7__ = 1;
  2651.  
  2652. // dom-if __template
  2653. // dom-repeat template
  2654. if (FIX_DOM_IF_TEMPLATE && !cProto.__template && !cProto.__template847) {
  2655. cProto.__template847 = true;
  2656. try {
  2657. // note: this is not "_template" in Polymer ( see POLYMER_COMPONENT_DEFINITION )
  2658. Object.defineProperty(cProto, '__template', {
  2659. get() {
  2660. const v = this[s84];
  2661. return (typeof (v || 0) === 'object' && v.deref) ? kRef(v) : v;
  2662. },
  2663. set(nv) {
  2664. if (typeof (nv || 0) === 'object' && !nv.deref) nv = mWeakRef(nv);
  2665. this[s84] = nv;
  2666. return true;
  2667. }
  2668. });
  2669. } catch (e) {
  2670. console.warn(e);
  2671. }
  2672.  
  2673. console.log('FIX_DOM_IF - __template')
  2674. }
  2675.  
  2676. // dom-if __ensureTemplate
  2677. // dom-repeat __ensureTemplatized
  2678. if (FIX_DOM_IF_TEMPLATE && !cProto.__ensureTemplate847 && typeof cProto.__ensureTemplate === 'function' && cProto.__ensureTemplate.length === 0 && this instanceof HTMLElement_ && `${cProto.__ensureTemplate}`.length > 20) {
  2679. // note that "_templateInfo" diffs the different version of DOM-IF
  2680.  
  2681. cProto.__ensureTemplate847 = cProto.__ensureTemplate;
  2682. cProto.__ensureTemplate = function () {
  2683. if (!(this instanceof HTMLElement_) || arguments.length > 0) return this.__ensureTemplate847(...arguments);
  2684. if (!this.__template) {
  2685. let b;
  2686. if (this._templateInfo) {
  2687. b = this;
  2688. } else {
  2689. if (!this.__templateCollection011__) this.__templateCollection011__ = this.getElementsByTagName('template');
  2690. b = this.__templateCollection011__[0];
  2691. if (!b) {
  2692. if (!this[wk]) this[wk] = mWeakRef(this);
  2693. let a = this[wk];
  2694. let c = new MutationObserver(function () {
  2695. if (!this.__templateCollection011__[0]) throw Error("dom-if requires a <template> child"); // to be reviewed
  2696. if (c && a) {
  2697. c.disconnect();
  2698. a = kRef(a);
  2699. a && a.__render();
  2700. a && (a.__templateCollection011__ = null);
  2701. }
  2702. c = null;
  2703. a = null;
  2704. });
  2705. c && c.observe(this, {
  2706. childList: !0
  2707. });
  2708. return !1
  2709. } else {
  2710. this.__templateCollection011__ = null;
  2711. }
  2712. }
  2713. this.__template = b
  2714. }
  2715. return !0
  2716. }
  2717.  
  2718. console.log('FIX_DOM_IF - __ensureTemplate')
  2719.  
  2720. }
  2721.  
  2722.  
  2723. // if(!cProto.__createAndInsertInstance847 && typeof cProto.__createAndInsertInstance === 'function' && cProto.__createAndInsertInstance.length === 1 && `${cProto.__createAndInsertInstance}`.length >20){
  2724.  
  2725. // cProto.__createAndInsertInstance847 = cProto.__createAndInsertInstance;
  2726.  
  2727. // cProto.__createAndInsertInstance = function (a) {
  2728. // Promise.resolve().then(()=>{
  2729. // console.log('__createAndInsertInstance')
  2730. // window.lm5 = window.lm5 || [];
  2731. // window.lm5.push([mWeakRef(this), mWeakRef(this.__instance)])
  2732. // });
  2733. // return this.__createAndInsertInstance847(a);
  2734. // }
  2735.  
  2736. // }
  2737.  
  2738.  
  2739. // if(!cProto._bindTemplate847 && typeof cProto._bindTemplate === 'function' && cProto._bindTemplate.length === 2){
  2740.  
  2741. // cProto._bindTemplate847 = cProto._bindTemplate;
  2742.  
  2743. // cProto._bindTemplate = function (a, b) {
  2744. // return this._bindTemplate847(kRef(a), b); // might throw Error as a -> null inside _bindTemplate847
  2745. // }
  2746.  
  2747. // }
  2748. // if(!cProto._stampTemplate847 && typeof cProto._stampTemplate === 'function' && cProto._stampTemplate.length === 2){
  2749.  
  2750. // cProto._stampTemplate847 = cProto._stampTemplate;
  2751.  
  2752. // cProto._stampTemplate = function (a, b) {
  2753. // return this._stampTemplate847(kRef(a), b); // might throw Error as a -> null inside _stampTemplate847
  2754. // }
  2755.  
  2756. // }
  2757. console.log('FIX_DOM_IF OK', Object.keys(cProto))
  2758. }
  2759.  
  2760.  
  2761. // need to fix __observeEffects
  2762. // this.__observeEffects.if[0].info.method === this.__debounceRender
  2763. const f = () => {
  2764.  
  2765. const __observeEffects = this.__observeEffects;
  2766.  
  2767. if (__observeEffects && __observeEffects.if && isIterable(__observeEffects.if)) {
  2768. for (const effect of __observeEffects.if) {
  2769. const info = effect.info;
  2770. if (info && typeof info.method === 'function') {
  2771.  
  2772. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  2773. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  2774. }
  2775.  
  2776. }
  2777. }
  2778. }
  2779.  
  2780.  
  2781. if (__observeEffects && __observeEffects.restamp && isIterable(__observeEffects.restamp)) {
  2782. for (const effect of __observeEffects.restamp) {
  2783. const info = effect.info;
  2784. if (info && typeof info.method === 'function') {
  2785.  
  2786. if (info.method === this.__debounceRender847 || info.method === this.__debounceRender) {
  2787. info.method = FIX_DOM_IFREPEAT_RenderDebouncerChange_SET_TO_PROPNAME ? '__debounceRender' : this.__debounceRender;
  2788. }
  2789.  
  2790. }
  2791. }
  2792. }
  2793.  
  2794. // console.log(5881, this.__observeEffects)
  2795. }
  2796. if (FIX_DOM_IFREPEAT_RenderDebouncerChange) {
  2797. f();
  2798. Promise.resolve().then(f);
  2799. // afterward, don't care adding fn directly (the fn is already modified)
  2800. }
  2801.  
  2802. }
  2803. this[s81] = nv;
  2804. return true;
  2805. }
  2806. });
  2807.  
  2808.  
  2809. Object.defineProperty(Object.prototype, '__renderDebouncer', {
  2810. get() {
  2811. return this[s85];
  2812. },
  2813. set(nv) {
  2814. if (nv === null && this[s85] === undefined) {
  2815. // DOM-IF / DOM-REPEAT initialization
  2816.  
  2817.  
  2818. const cProto = this.__proto__;
  2819. if (qp) {
  2820. qp.obtain();
  2821. qp = null;
  2822. shadyFlushMO.observe(document.documentElement, { attributes: ['nw3a24np'] });
  2823. }
  2824. if (FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.__debounceRender847 && typeof cProto.__debounceRender === 'function' && !(`${cProto.__debounceRender}`.includes("{}"))) {
  2825.  
  2826. cProto.__debounceRender847 = cProto.__debounceRender;
  2827.  
  2828. if (cProto.__debounceRender.length === 2) {
  2829.  
  2830. cProto.__debounceRender = function (a, b) {
  2831.  
  2832. if (!renderDebounceTs) return this.__debounceRender847(a, b);
  2833.  
  2834. b = b === void 0 ? 0 : b;
  2835.  
  2836. /*
  2837. b = b === void 0 ? 0 : b;
  2838. this.__renderDebouncer = us(this.__renderDebouncer, b > 0 ? Rr.after(b) : Tr, a.bind(this));
  2839. vs(this.__renderDebouncer)
  2840. */
  2841.  
  2842. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2843.  
  2844. if (!renderDebouncePromise) {
  2845. renderDebouncePromise = new PromiseExternal();
  2846. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2847. }
  2848.  
  2849. renderDebouncePromise.then(async () => {
  2850. if (b > 0) await delayPn(b);
  2851.  
  2852. const f = this.__dsIRYqw1__;
  2853. if (f === cme) return;
  2854. this.__dsIRYqw1__ = cme;
  2855. a.call(this);
  2856. DEBUG_DBR847 && console.log(`__DBR847__ done 01 (delay=${b})`, this.__DBR848__)
  2857.  
  2858. });
  2859.  
  2860. DEBUG_DBR847 && console.log(`__DBR847__ add 01 (delay=${b})`, this.__DBR848__)
  2861. }
  2862.  
  2863. } else if (cProto.__debounceRender.length === 0) {
  2864.  
  2865.  
  2866. cProto.__debounceRender = function () {
  2867.  
  2868. if (!renderDebounceTs) return this.__debounceRender847();
  2869.  
  2870. this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2871. /*
  2872. var a = this;
  2873. this.__renderDebouncer = us(this.__renderDebouncer, Tr, function() {
  2874. return a.__render()
  2875. });
  2876. vs(this.__renderDebouncer)
  2877. */
  2878.  
  2879. if (!renderDebouncePromise) {
  2880. renderDebouncePromise = new PromiseExternal();
  2881. document.documentElement.setAttribute('nw3a24np', (cme = (cme % 511 + 1)));
  2882. }
  2883. renderDebouncePromise.then(() => {
  2884. const f = this.__dsIRYqw1__;
  2885. if (f === cme) return;
  2886. this.__dsIRYqw1__ = cme;
  2887. this.__render()
  2888. DEBUG_DBR847 && console.log('__DBR847__ done 02', this.__DBR848__)
  2889. });
  2890. DEBUG_DBR847 && console.log('__DBR847__ add 02', this.__DBR848__)
  2891.  
  2892.  
  2893. }
  2894. }
  2895. }
  2896.  
  2897.  
  2898.  
  2899. // if(FIX_DOM_IFREPEAT_RenderDebouncerChange && !cProto.render847 && typeof cProto.render === 'function' && cProto.render.length === 0 && !(`${cProto.render}`.includes("{}"))){
  2900. // cProto.render847 = cProto.render;
  2901. // cProto.render = function(){
  2902.  
  2903. // this.__DBR848__ = this.__DBR848__ || `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2904. // try{
  2905. // this.render847();
  2906. // }catch(e){}
  2907. // // if(this.__DBR847__){
  2908. // // this.__DBR847__.resolve();
  2909. // // DEBUG_DBR847 && console.log('__DBR847__ resolve', this.__DBR848__)
  2910. // // }
  2911.  
  2912. // // renderDebouncePromise && renderDebouncePromise.resolve()
  2913. // // renderDebouncePromise = null;
  2914. // // DEBUG_DBR847 && console.log('__DBR847__ renderDebouncePromise.resolve by render', this.__DBR848__)
  2915.  
  2916. // }
  2917. // console.log('FIX_DOM_IF - render', `${cProto.render847}`, cProto.render847)
  2918. // }
  2919.  
  2920. }
  2921. this[s85] = nv;
  2922. return true;
  2923. }
  2924. });
  2925.  
  2926. // PS-DOM-REPEAT
  2927.  
  2928. Object.defineProperty(Object.prototype, 'JSC$10034_renderDebouncer', {
  2929. get() {
  2930. return this[s85b];
  2931. },
  2932. set(nv) {
  2933.  
  2934. this[s85b] = nv;
  2935. return true;
  2936. }
  2937. })
  2938.  
  2939. Object.defineProperty(Object.prototype, 'JSC$10027_renderDebouncer', {
  2940. get() {
  2941. return this[s85c];
  2942. },
  2943. set(nv) {
  2944.  
  2945. this[s85c] = nv;
  2946. return true;
  2947. }
  2948. })
  2949.  
  2950.  
  2951. })();
  2952.  
  2953. const setupXdeadC = (cnt)=>{
  2954.  
  2955. let xdeadc = xdeadc00;
  2956. if(!xdeadc){
  2957. setupSDomWrapper(); // just in case
  2958. const hostElement = cnt.hostElement;
  2959. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2960. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2961. hostElement.lastChild.replaceWith(el);
  2962. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2963. const rid = `xdead_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2964. el.firstElementChild.id = rid;
  2965. cnt.$[rid] = el.firstElementChild;
  2966. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2967.  
  2968. xdeadc = cnt.getStampContainer_(rid);
  2969. el.remove();
  2970. xdeadc00 = xdeadc;
  2971. // console.log(xdeadc.__domApi)
  2972. // debugger;
  2973. // const xdeadv = xdeadc.__domApi;
  2974. }
  2975.  
  2976. let xlivec = xlivec00;
  2977. if(!xlivec){
  2978. setupSDomWrapper(); // just in case
  2979. const hostElement = cnt.hostElement;
  2980. const el = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
  2981. hostElement.insertAdjacentHTML('beforeend', ttpHTML('<!---->'));
  2982. hostElement.lastChild.replaceWith(el);
  2983. el.insertAdjacentHTML('afterbegin', ttpHTML(`<div></div>`));
  2984. const rid = `xlive_${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
  2985. el.firstElementChild.id = rid;
  2986. cnt.$[rid] = el.firstElementChild;
  2987. cnt.stampDomArray9682_(null, rid, null, false, false, false);
  2988.  
  2989. xlivec = cnt.getStampContainer_(rid);
  2990. xlivec00 = xlivec;
  2991. // console.log(xdeadc.__domApi)
  2992. // debugger;
  2993. // const xdeadv = xdeadc.__domApi;
  2994. }
  2995.  
  2996. return xdeadc00;
  2997. }
  2998.  
  2999. let standardWrap_ = null;
  3000.  
  3001. const setupSDomWrapper = () => {
  3002.  
  3003. const sdwProto = ShadyDOM.Wrapper.prototype;
  3004.  
  3005. if (sdwProto.__pseudo__isConnected__ !== null) {
  3006. sdwProto.__pseudo__isConnected__ = null;
  3007. const isConnectedPd = Object.getOwnPropertyDescriptor(sdwProto, 'isConnected');
  3008. if (isConnectedPd && isConnectedPd.get && isConnectedPd.configurable === true) {
  3009. const get = isConnectedPd.get;
  3010. isConnectedPd.get = function () {
  3011. const pseudoVal = this.__pseudo__isConnected__;
  3012. return typeof pseudoVal === 'boolean' ? pseudoVal : get.call(this);
  3013. }
  3014. Object.defineProperty(sdwProto, 'isConnected', { ...isConnectedPd });
  3015. }
  3016.  
  3017. // debugger;
  3018. // new xdeadc.__domApi.constructor(document.createElement('div'));
  3019. }
  3020.  
  3021. }
  3022.  
  3023. let domApiConstructor = null;
  3024. const setupDomApi = (daProto) => {
  3025.  
  3026. daProto.__daHook377__ = true;
  3027.  
  3028. domApiConstructor = daProto.constructor; // TBC
  3029.  
  3030. // TBC
  3031.  
  3032. }
  3033.  
  3034.  
  3035. // WEAKREF_ShadyDOM
  3036.  
  3037. MODIFY_ShadyDOM_OBJ && ((WeakRef) => {
  3038.  
  3039. const setupPlainShadyDOM = (b) => {
  3040. (OMIT_ShadyDOM_settings & 1) && (b.inUse === true) && (b.inUse = false);
  3041. (OMIT_ShadyDOM_settings & 2) && (b.handlesDynamicScoping === true) && (b.handlesDynamicScoping = false);
  3042. (OMIT_ShadyDOM_settings & 4) && (b.force === true) && (b.force = false);
  3043. b.patchOnDemand = true;
  3044. b.preferPerformance = true;
  3045. b.noPatch = true;
  3046. }
  3047.  
  3048. const isPlainObject = (b, m) => {
  3049. if (!b || typeof b !== 'object') return false;
  3050. const e = Object.getOwnPropertyDescriptors(b);
  3051. if (e.length <= m) return false;
  3052. let pr = 0;
  3053. for (const k in e) {
  3054. const d = e[k];
  3055. if (!d || d.get || d.set || !d.enumerable || !d.configurable) return false;
  3056. if (!('value' in d) || typeof d.value === 'function') return false;
  3057. pr++;
  3058. }
  3059. return pr > m;
  3060. }
  3061.  
  3062. let b;
  3063.  
  3064. let lz = 0;
  3065.  
  3066. const sdp = Object.getOwnPropertyDescriptor(window, 'ShadyDOM');
  3067. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable) {
  3068.  
  3069. // Brave - ShadyDOM exists before userscripting
  3070. b = sdp.value;
  3071.  
  3072. if (b && typeof b === 'object' && isPlainObject(b, 0)) {
  3073. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(b);
  3074. lz = 1;
  3075. }
  3076.  
  3077. }
  3078.  
  3079.  
  3080. if (sdp && sdp.configurable && sdp.value && sdp.enumerable && sdp.writable && !sdp.get && !sdp.set) {
  3081. } else if (!sdp) {
  3082. } else {
  3083. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [ PropertyDescriptor issue ]', sdp);
  3084. return;
  3085. }
  3086.  
  3087. const shadyDOMNodeWRM = new WeakMap();
  3088.  
  3089. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 01 >>', b);
  3090.  
  3091. const weakWrapperNodeHandlerFn = () => ({
  3092. get() {
  3093. const wv = this[wk];
  3094. if (typeof wv === 'undefined') return undefined;
  3095. let node = kRef(wv);
  3096. if (!node) this[wk] = undefined;
  3097. return node || undefined;
  3098. },
  3099. set(nv) {
  3100. const wv = nv ? (nv[wk] || (nv[wk] = mWeakRef(nv))) : nv;
  3101. this[wk] = wv;
  3102. return true;
  3103. },
  3104. enumerable: true,
  3105. configurable: true
  3106. });
  3107.  
  3108.  
  3109. function weakWrapper(_ShadyDOM) {
  3110. const ShadyDOM = _ShadyDOM;
  3111. if (WEAKREF_ShadyDOM && lz < 3 && typeof WeakRef === 'function' && typeof ShadyDOM.Wrapper === 'function' && ShadyDOM.Wrapper.length === 1 && typeof (ShadyDOM.Wrapper.prototype || 0) === 'object') {
  3112. let nullElement = { node: null };
  3113. Object.setPrototypeOf(nullElement, Element.prototype);
  3114. let p = new ShadyDOM.Wrapper(nullElement);
  3115. let d = Object.getOwnPropertyDescriptor(p, 'node');
  3116. if (d.configurable && d.enumerable && !d.get && !d.set && d.writable && d.value === nullElement && !Object.getOwnPropertyDescriptor(ShadyDOM.Wrapper.prototype, 'node')) {
  3117. Object.defineProperty(ShadyDOM.Wrapper.prototype, 'node', weakWrapperNodeHandlerFn());
  3118. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << WEAKREF_ShadyDOM >>')
  3119. }
  3120.  
  3121. }
  3122. if (typeof (((ShadyDOM || 0).Wrapper || 0).prototype || 0) === 'object') {
  3123. try {
  3124. setupSDomWrapper();
  3125. } catch (e) { }
  3126. }
  3127.  
  3128. }
  3129.  
  3130. let previousWrapStore = null;
  3131.  
  3132. const standardWrap = function (a) {
  3133. // if(a && a.deref) a= a.deref();
  3134. if(!a) return a;
  3135. if (a instanceof ShadowRoot || a instanceof ShadyDOM.Wrapper) return a;
  3136. if (previousWrapStore) {
  3137. const s = kRef(previousWrapStore.get(a)); // kRef for play safe only
  3138. if (s) {
  3139. previousWrapStore.delete(a);
  3140. shadyDOMNodeWRM.set(a, mWeakRef(s));
  3141. }
  3142. }
  3143. let u = kRef(shadyDOMNodeWRM.get(a));
  3144. if (!u) {
  3145. u = new ShadyDOM.Wrapper(a);
  3146. shadyDOMNodeWRM.set(a, mWeakRef(u));
  3147. }
  3148. return u;
  3149. }
  3150.  
  3151. standardWrap_ = standardWrap;
  3152.  
  3153.  
  3154. function setupWrapFunc(_ShadyDOM) {
  3155. const ShadyDOM = _ShadyDOM;
  3156.  
  3157.  
  3158. const wmPD = Object.getOwnPropertyDescriptor(WeakMap.prototype, 'get');
  3159. if (!(wmPD && wmPD.writable && !wmPD.enumerable && wmPD.configurable && wmPD.value && !wmPD.get && !wmPD.set)) {
  3160. return;
  3161. }
  3162. let mm = new Set();
  3163. const pget = wmPD.value;
  3164. WeakMap.prototype.get = function (a) {
  3165. mm.add(this);
  3166. return a;
  3167. }
  3168. try {
  3169. let nullElement = { node: null };
  3170. Object.setPrototypeOf(nullElement, Element.prototype);
  3171. ShadyDOM.wrapIfNeeded(nullElement)
  3172. ShadyDOM.wrap(nullElement)
  3173. } catch (e) { }
  3174. WeakMap.prototype.get = pget;
  3175. if (mm.size !== 1) {
  3176. mm.clear();
  3177. return;
  3178. }
  3179. const p = mm.values().next().value;
  3180. if (!(p instanceof WeakMap)) return;
  3181. // p.clear();
  3182. // p.get = function (a) { return a }
  3183. // p.set = function (a, b) { return this }
  3184. // console.log(188, window.n2n = mm, window.n2p = p)
  3185.  
  3186. // console.log(34929,p.size)
  3187. previousWrapStore = p;
  3188.  
  3189. if (typeof ShadyDOM.wrap === 'function' && ShadyDOM.wrap.length === 1) {
  3190. ShadyDOM.wrap = function (a) { 0 && console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrap'); return standardWrap(a) }
  3191. }
  3192. if (typeof ShadyDOM.wrapIfNeeded === 'function' && ShadyDOM.wrapIfNeeded.length === 1) {
  3193. ShadyDOM.wrapIfNeeded = function (a) { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - wrapIfNeeded'); return standardWrap(a) }
  3194. }
  3195.  
  3196. }
  3197.  
  3198. function setupLZ3(nv) {
  3199.  
  3200. const ShadyDOM = nv;
  3201.  
  3202. const ShadyDOMSettings = ShadyDOM.settings;
  3203. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3204. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3205. return false;
  3206. }
  3207.  
  3208. weakWrapper(ShadyDOM);
  3209.  
  3210. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3211.  
  3212. setupPlainShadyDOM(ShadyDOMSettings);
  3213. setupPlainShadyDOM(ShadyDOM);
  3214.  
  3215. ShadyDOM.isShadyRoot = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - isShadyRoot'); return false; }
  3216.  
  3217. setupWrapFunc(ShadyDOM);
  3218. ShadyDOM.patchElementProto = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patchElementProto') }
  3219. ShadyDOM.patch = function () { console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM) function call - patch') }
  3220.  
  3221. // To be confirmed
  3222. if (OMIT_ShadyDOM_EXPERIMENTAL & 2) {
  3223. ShadyDOM.composedPath = function (e) {
  3224. const t = (e || 0).target || null;
  3225. if (!(t instanceof HTMLElement_)) {
  3226. console.log(3719, '[yt-js-engine-tamer] (OMIT_ShadyDOM&2) composedPath', t)
  3227. }
  3228. return t instanceof HTMLElement_ ? [t] : [];
  3229. };
  3230. }
  3231.  
  3232. }
  3233.  
  3234. }
  3235.  
  3236.  
  3237. function setupLZ6(nv) {
  3238.  
  3239. const ShadyDOM = nv;
  3240.  
  3241. const ShadyDOMSettings = ShadyDOM.settings;
  3242.  
  3243. if (!(ShadyDOMSettings.inUse === true && ShadyDOM.inUse === true && (ShadyDOMSettings.handlesDynamicScoping || ShadyDOM.handlesDynamicScoping) === true)) {
  3244. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [02]', window.ShadyDOM);
  3245. return false;
  3246. }
  3247.  
  3248. weakWrapper(ShadyDOM);
  3249.  
  3250. if (OMIT_ShadyDOM_EXPERIMENTAL && lz < 3) {
  3251.  
  3252. setupPlainShadyDOM(ShadyDOMSettings);
  3253. setupPlainShadyDOM(ShadyDOM);
  3254.  
  3255. setupWrapFunc(ShadyDOM);
  3256.  
  3257. }
  3258.  
  3259. }
  3260.  
  3261. if (b && typeof b.Wrapper === 'function' && typeof b.settings === 'object' && typeof b.wrap === 'function') {
  3262.  
  3263. const nv = b;
  3264.  
  3265. if (setupLZ6(nv) === false) return;
  3266.  
  3267. lz = 6;
  3268.  
  3269. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02b >>', nv)
  3270.  
  3271. return;
  3272. }
  3273.  
  3274. delete window.ShadyDOM;
  3275.  
  3276. Object.defineProperty(window, 'ShadyDOM', {
  3277. get() {
  3278. return b;
  3279. },
  3280. set(nv) {
  3281. let ret = 0;
  3282. try {
  3283. do {
  3284. if (!nv || !nv.settings) {
  3285. if (lz < 1 && nv && typeof nv === 'object' && isPlainObject(nv, 0)) {
  3286. OMIT_ShadyDOM_EXPERIMENTAL && setupPlainShadyDOM(nv);
  3287. lz = 1;
  3288. break;
  3289. } else {
  3290. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM is not applied [nv:null]', nv);
  3291. break;
  3292. }
  3293. }
  3294.  
  3295. const sdp = Object.getOwnPropertyDescriptor(this || {}, 'ShadyDOM');
  3296. if (!(sdp && sdp.configurable && sdp.get && sdp.set)) {
  3297. console.log(3719, '[yt-js-engine-tamer] OMIT_ShadyDOM is not applied [ incorrect PropertyDescriptor ]', nv);
  3298. break;
  3299. }
  3300.  
  3301. if (setupLZ3(nv) === false) break;
  3302.  
  3303. lz = 3;
  3304.  
  3305. console.log(3719, '[yt-js-engine-tamer] FIX::ShadyDOM << 02a >>', nv)
  3306.  
  3307. ret = 1;
  3308.  
  3309. } while (0);
  3310. } catch (e) {
  3311. console.log('[yt-js-engine-tamer] FIX::ShadyDOM << ERROR >>', e)
  3312. }
  3313.  
  3314. if (!ret) b = nv;
  3315. else {
  3316. delete this.ShadyDOM;
  3317. this.ShadyDOM = nv;
  3318. }
  3319. return true;
  3320. },
  3321. enumerable: false,
  3322. configurable: true
  3323. });
  3324.  
  3325. })(typeof WeakRef !== 'undefined' ? WeakRef : function () { });
  3326.  
  3327. if (ENABLE_ASYNC_DISPATCHEVENT) {
  3328. const filter = new Set([
  3329. 'yt-action',
  3330. // 'iframe-src-replaced',
  3331. 'shown-items-changed',
  3332. 'can-show-more-changed', 'collapsed-changed',
  3333.  
  3334. 'yt-navigate', 'yt-navigate-start', 'yt-navigate-cache',
  3335. 'yt-player-updated', 'yt-page-data-fetched', 'yt-page-type-changed', 'yt-page-data-updated',
  3336. 'yt-navigate-finish',
  3337.  
  3338. // 'data-changed','yt-watch-comments-ready'
  3339. ])
  3340. EventTarget.prototype.dispatchEvent938 = EventTarget.prototype.dispatchEvent;
  3341. EventTarget.prototype.dispatchEvent = function (event) {
  3342. const type = (event || 0).type;
  3343. if (typeof type === 'string' && event.isTrusted === false && (event instanceof CustomEvent) && event.cancelable === false) {
  3344. if (!filter.has(type) && !type.endsWith('-changed')) {
  3345. if (this instanceof Node || this instanceof Window) {
  3346. nextBrowserTick_(() => this.dispatchEvent938(event));
  3347. return true;
  3348. }
  3349. }
  3350. }
  3351. return this.dispatchEvent938(event);
  3352. }
  3353. }
  3354.  
  3355. // avoid REGEXP testPattern execution in Brave's scriptlet for performance boost
  3356. SCRIPTLET_REMOVE_PRUNE_propNeedles && (() => {
  3357. // const xhr = new XMLHttpRequest;
  3358. const pdOri = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
  3359. if (!pdOri || pdOri.configurable !== true) return;
  3360. let propNeedles = null;
  3361. const pdNew = {
  3362. configurable: true,
  3363. enumerable: true,
  3364. get: function () {
  3365. propNeedles = this;
  3366. if (DEBUG_removePrune) debugger; // to locate Brave scriptlets
  3367. throw new Error();
  3368. }
  3369. }
  3370. Object.defineProperty(Map.prototype, 'size', pdNew);
  3371. try {
  3372. XMLHttpRequest.prototype.open.call(0);
  3373. // xhr.open.call(null)
  3374. } catch (e) { }
  3375. Object.defineProperty(Map.prototype, 'size', pdOri);
  3376. if (!propNeedles) return;
  3377. const entries = [...propNeedles.entries()];
  3378. propNeedles.clear();
  3379. console.log('[yt-js-engine-tamer] propNeedles is cleared from scriptlet', entries, propNeedles);
  3380. })();
  3381.  
  3382. if (FIX_XHR_REQUESTING) {
  3383.  
  3384. const URL = window.URL || new Function('return URL')();
  3385. const createObjectURL = URL.createObjectURL.bind(URL);
  3386.  
  3387. XMLHttpRequest = (() => {
  3388. const XMLHttpRequest_ = XMLHttpRequest;
  3389. if ('__xmMc8__' in XMLHttpRequest_.prototype) return XMLHttpRequest_;
  3390. const url0 = createObjectURL(new Blob([], { type: 'text/plain' }));
  3391. const c = class XMLHttpRequest extends XMLHttpRequest_ {
  3392. constructor(...args) {
  3393. super(...args);
  3394. }
  3395. open(method, url, ...args) {
  3396. let skip = false;
  3397. if (!url || typeof url !== 'string') skip = true;
  3398. else if (typeof url === 'string') {
  3399. let turl = url[0] === '/' ? `.youtube.com${url}` : `${url}`;
  3400. if (turl.includes('googleads') || turl.includes('doubleclick.net')) {
  3401. skip = true;
  3402. } else if (turl.includes('.youtube.com/pagead/')) {
  3403. skip = true;
  3404. } else if (turl.includes('.youtube.com/ptracking')) {
  3405. skip = true;
  3406. } else if (turl.includes('.youtube.com/youtubei/v1/log_event?')) {
  3407. skip = true;
  3408. } else if (turl.includes('.youtube.com/api/stats/')) { // /api/stats/
  3409. if (turl.includes('.youtube.com/api/stats/qoe?')) {
  3410. skip = true;
  3411. } else if (turl.includes('.youtube.com/api/stats/ads?')) {
  3412. skip = true;
  3413. } else {
  3414. // skip = true; // for user activity logging e.g. watched videos
  3415. }
  3416. } else if (turl.includes('play.google.com/log')) {
  3417. skip = true;
  3418. } else if (turl.includes('.youtube.com//?')) { // //?cpn=
  3419. skip = true;
  3420. }
  3421. }
  3422. if (!skip) {
  3423. this.__xmMc8__ = 1;
  3424. return super.open(method, url, ...args);
  3425. } else {
  3426. this.__xmMc8__ = 2;
  3427. return super.open('GET', url0);
  3428. }
  3429. }
  3430. send(...args) {
  3431. if (this.__xmMc8__ === 1) {
  3432. return super.send(...args);
  3433. } else if (this.__xmMc8__ === 2) {
  3434. return super.send();
  3435. } else {
  3436. console.log('[yt-js-engine-tamer]', 'xhr warning');
  3437. return super.send(...args);
  3438. }
  3439. }
  3440. }
  3441. c.prototype.__xmMc8__ = 0;
  3442. prototypeInherit(c.prototype, XMLHttpRequest_.prototype);
  3443. return c;
  3444. })();
  3445. }
  3446.  
  3447. // Alternative HACK -> Tabview Youtube
  3448. if (DISABLE_COOLDOWN_SCROLLING && typeof EventTarget.prototype.addEventListener52178 !== 'function' && typeof EventTarget.prototype.addEventListener === 'function') {
  3449.  
  3450. // ---- << this.overscrollConfig HACK >> -----
  3451.  
  3452. // 2024.04.19 - Playlist in Single Column Mode cannot be scrolled correctly.
  3453.  
  3454. /*
  3455.  
  3456. ;function gZb(a, b) {
  3457. b = void 0 === b ? !0 : b;
  3458. a.addEventListener("wheel", hZb);
  3459. a.overscrollConfig = {
  3460. cooldown: b
  3461. }
  3462. }
  3463. function iZb(a) {
  3464. a.overscrollConfig = void 0;
  3465. a.removeEventListener("wheel", hZb)
  3466. }
  3467. function hZb(a) {
  3468. var b = a.deltaY
  3469. , c = a.target
  3470. , d = null;
  3471. if (window.Polymer && window.Polymer.Element) {
  3472. if (c = a.path || a.composedPath && a.composedPath()) {
  3473. c = g(c);
  3474. for (var e = c.next(); !e.done && (e = e.value,
  3475. !jZb(e, b)); e = c.next())
  3476. if (e.overscrollConfig) {
  3477. d = e;
  3478. break
  3479. }
  3480. }
  3481. } else
  3482. for (; c && !jZb(c, b); ) {
  3483. if (c.overscrollConfig) {
  3484. d = c;
  3485. break
  3486. }
  3487. c = c.parentElement
  3488. }
  3489. d && (b = d.overscrollConfig,
  3490. b.cooldown ? (d = a.deltaY,
  3491. c = b.lastDeltaY || 0,
  3492. b.lastDeltaY = d,
  3493. e = b.lastStopped || 0,
  3494. c && e && 0 < c == 0 < d ? Math.abs(c) >= Math.abs(d) ? (d = e + 1200,
  3495. c = !1) : (d = e + 600,
  3496. c = !0) : (d = Date.now() + 600,
  3497. c = !0),
  3498. d > Date.now() && (a.preventDefault(),
  3499. c && (b.lastStopped = Date.now()))) : a.preventDefault())
  3500. }
  3501. */
  3502.  
  3503. let wheelHandler = function (a) {
  3504. if (window.Polymer && window.Polymer.Element) {
  3505. let c;
  3506. if (c = a.path || a.composedPath && a.composedPath()) {
  3507. for (const e of c) {
  3508. const cnt = insp(e);
  3509. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3510. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3511. }
  3512. }
  3513. } else {
  3514. let e = a.target;
  3515. for (; e instanceof Element; e = e.parentElement) {
  3516. const cnt = insp(e);
  3517. if (e.overscrollConfig) e.overscrollConfig = void 0;
  3518. if (cnt.overscrollConfig) cnt.overscrollConfig = void 0;
  3519. }
  3520. }
  3521. };
  3522.  
  3523. let checkWheelListenerObjs = null;
  3524.  
  3525. let getObjsFn = () => {
  3526. let euyVal = 0;
  3527. const eukElm = {};
  3528. Object.setPrototypeOf(eukElm, HTMLElement_.prototype);
  3529. const euzObj = new Proxy(eukElm, {
  3530. get(target, prop) {
  3531. throw `ErrorF31.get(${prop})`
  3532. },
  3533. set(target, prop, value) {
  3534. throw `ErrorF33.set(${prop}, ${value})`
  3535. }
  3536. });
  3537. const euxElm = new Proxy(eukElm, {
  3538. get(target, prop) {
  3539. if (prop === 'scrollTop') {
  3540. euyVal = euyVal | 8;
  3541. return 0;
  3542. }
  3543. if (prop === 'overscrollConfig') {
  3544. euyVal = euyVal | 16;
  3545. return void 0;
  3546. }
  3547. if (prop === 'scrollHeight' || prop === 'clientHeight' || prop === 'offsetHeight') {
  3548. return 640;
  3549. }
  3550. if (prop === 'scrollLeft') {
  3551. euyVal = euyVal | 8;
  3552. return 0;
  3553. }
  3554. if (prop === 'scrollWidth' || prop === 'clientWidth' || prop === 'offsetWidth') {
  3555. return 800;
  3556. }
  3557. throw `ErrorF45.get(${prop})`
  3558. },
  3559. set(target, prop, value) {
  3560. throw `ErrorF47.set(${prop}, ${value})`
  3561. }
  3562. });
  3563. const eukEvt = {};
  3564. Object.setPrototypeOf(eukEvt, WheelEvent.prototype);
  3565. const euyEvt = new Proxy(eukEvt, {
  3566. get(target, prop) {
  3567. if (prop === 'deltaY' || prop === 'deltaX') {
  3568. euyVal = euyVal | 1;
  3569. return -999;
  3570. }
  3571. if (prop === 'target') {
  3572. euyVal = euyVal | 2;
  3573. return euxElm
  3574. }
  3575. if (prop === 'path' || prop === 'composedPath') {
  3576. euyVal = euyVal | 2;
  3577. return [euxElm]
  3578. }
  3579. throw `ErrorF51.get(${prop})`
  3580. },
  3581. set(target, prop, value) {
  3582. throw `ErrorF53.set(${prop}, ${value})`
  3583. }
  3584. });
  3585. const setVal = (v) => {
  3586. euyVal = v;
  3587. }
  3588. const getVal = () => {
  3589. return euyVal;
  3590. }
  3591. return { euzObj, euyEvt, setVal, getVal };
  3592. }
  3593.  
  3594. let checkWheelListener = (callback) => {
  3595.  
  3596. let callbackIdentifier = '';
  3597.  
  3598. let res = null;
  3599. try {
  3600. const { euzObj, euyEvt, getVal, setVal } = checkWheelListenerObjs || (checkWheelListenerObjs = getObjsFn());
  3601. setVal(0);
  3602. if (callback.call(euzObj, euyEvt) !== void 0) throw 'ErrorF99';
  3603. throw `RESULT${getVal()}`;
  3604. } catch (e) {
  3605. res = e;
  3606. }
  3607.  
  3608. res = `${res}` || `${null}`;
  3609. if (res.length > 20) res = `${res.substring(0, 20)}...`;
  3610.  
  3611. callbackIdentifier = res;
  3612. if (callbackIdentifier === 'RESULT27') 0;
  3613. else if (callbackIdentifier === 'RESULT0') {
  3614. // a.isSearch && !a.disableWheelScroll && B("desktop_enable_dmpanel_wheel_scroll")
  3615. } else if (callbackIdentifier.startsWith('RESULT')) {
  3616. console.log('wheel eventListener - RESULT', callbackIdentifier, callback)
  3617. }
  3618. return callbackIdentifier;
  3619.  
  3620. };
  3621.  
  3622. let callbackFound = false;
  3623. EventTarget.prototype.addEventListener52178 = EventTarget.prototype.addEventListener;
  3624. EventTarget.prototype.addEventListener = function (type, callback, option = void 0) {
  3625. // M-youtube-js-engine-tamer.52178
  3626. if (type === 'wheel' && !option && typeof callback === 'function' && callback.length === 1) {
  3627. // (( match with signature `a.addEventListener("wheel", hZb);` )) [subject to further review]
  3628. const callbackIdentifier = callback.yaujmoms || (callbackFound ? 'IGNORE' : (callback.yaujmoms = checkWheelListener(callback)));
  3629. // RESULTXX / ErrorFXX / Other...
  3630. if (callbackIdentifier === 'RESULT27') {
  3631. this.overscrollConfigDisable = true;
  3632. if (!callbackFound) {
  3633. callbackFound = true; // suppose only one function is assigned to overscrollConfig cooldown [no function binding]
  3634. getObjsFn = checkWheelListener = null;
  3635. checkWheelListenerObjs = null;
  3636. wheelHandler = null;
  3637. }
  3638. return void 0;
  3639. } else if (!callbackFound && !this.overscrollConfigDisable) {
  3640. this.overscrollConfigDisable = true;
  3641. this.addEventListener52178('wheel', wheelHandler, { passive: false });
  3642. }
  3643. }
  3644. return this.addEventListener52178(type, callback, option);
  3645. };
  3646.  
  3647. // ---- << this.overscrollConfig HACK >> -----
  3648.  
  3649. }
  3650.  
  3651. const { pageMediaWatcher, shortcutKeysFixer, keyboardController } = (() => {
  3652.  
  3653. let p_a_objWR = null;
  3654. let isSpaceKeyImmediate = false; // for ADVANCED_FIX_SHORTCUTKEYS
  3655. let ytPageReady = 0;
  3656.  
  3657. let isSpeedMastSpacebarControlEnabled = false; // youtube experimental feature // can be forced by CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  3658. let isGlobalSpaceControl = true;
  3659. let mediaPlayerElementWR = null;
  3660. let focusedElementAtSelection = null;
  3661.  
  3662. // let want_control_video = false;
  3663.  
  3664. let spaceBarControl_keyG = '';
  3665.  
  3666. let lastUserAction = 0;
  3667.  
  3668. const wmKeyControlPhase = new WeakMap();
  3669.  
  3670. let currentSelectionText = null;
  3671.  
  3672. const getCurrentSelectionText = () => {
  3673. if (currentSelectionText !== null) return currentSelectionText
  3674. return (currentSelectionText = `${getSelection()}`)
  3675. }
  3676.  
  3677. const pageMediaWatcher = () => {
  3678.  
  3679. // CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && document.addEventListener('wheel', () => {
  3680. // want_control_video = false;
  3681. // }, { capture: true, passive: true });
  3682.  
  3683. document.addEventListener('yt-navigate', () => {
  3684. ytPageReady = 0;
  3685. });
  3686. document.addEventListener('yt-navigate-start', () => {
  3687. ytPageReady = 0;
  3688. });
  3689. document.addEventListener('yt-navigate-cache', () => {
  3690. ytPageReady = 0;
  3691. });
  3692.  
  3693. document.addEventListener('yt-navigate-finish', () => {
  3694. ytPageReady = 1;
  3695. });
  3696.  
  3697. document.addEventListener('durationchange', () => {
  3698. for (const elm of document.querySelectorAll('#movie_player video[src], #movie_player audio[src]')) {
  3699. if (elm.duration > 0.01) {
  3700. if (elm.closest('[hidden]')) continue;
  3701. mediaPlayerElementWR = mWeakRef(elm);
  3702. return;
  3703. }
  3704. }
  3705. }, { capture: true, passive: true });
  3706.  
  3707. document.addEventListener('selectionchange', (evt) => {
  3708. if (!evt || !evt.isTrusted || !(evt instanceof Event)) return;
  3709. currentSelectionText = null;
  3710. if (!(evt.target instanceof Node)) return;
  3711. focusedElementAtSelection = evt.target;
  3712. }, { capture: true, passive: true })
  3713.  
  3714. document.addEventListener('pointerdown', (evt) => {
  3715. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3716. }, { capture: true, passive: true });
  3717.  
  3718.  
  3719. document.addEventListener('pointerup', (evt) => {
  3720. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3721. }, { capture: true, passive: true });
  3722.  
  3723.  
  3724. document.addEventListener('keydown', (evt) => {
  3725. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3726. }, { capture: true, passive: true });
  3727.  
  3728. document.addEventListener('keyup', (evt) => {
  3729. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  3730. }, { capture: true, passive: true });
  3731.  
  3732. };
  3733.  
  3734.  
  3735. const checkKeyB = (p_a_obj) => {
  3736.  
  3737. const boolList = new Set();
  3738. const p_a_obj_api = p_a_obj.api;
  3739.  
  3740. const nilFunc0 = function () {
  3741. return void 0
  3742. };
  3743. const mt = new Proxy({}, {
  3744. get(target, prop) {
  3745. if (prop === 'get') return nilFunc0;
  3746. return mt;
  3747. }
  3748. });
  3749. const nilFunc = function () {
  3750. return mt
  3751. };
  3752. const mw = new Proxy({}, {
  3753. get(target, prop) {
  3754. if (prop in p_a_obj_api) {
  3755. if (typeof p_a_obj_api.constructor.prototype[prop] === 'function') return nilFunc;
  3756. let q = Object.getOwnPropertyDescriptor(p_a_obj_api, prop);
  3757. if (q && q.value) {
  3758. if (!q.writable) return q.value;
  3759. if (typeof q.value === 'string') return '';
  3760. if (typeof q.value === 'number') return 0;
  3761. if (typeof q.value === 'boolean') return false;
  3762. if (q.value && typeof q.value === 'object') return {};
  3763. }
  3764. }
  3765. return undefined;
  3766. },
  3767. set(target, prop) {
  3768. throw 'mwSet';
  3769. }
  3770. });
  3771.  
  3772. const mq = new Proxy({}, {
  3773. get(target, prop) {
  3774. if (prop === 'api') return mw;
  3775. if (prop in p_a_obj) {
  3776. if (typeof p_a_obj.constructor.prototype[prop] === 'function') return nilFunc;
  3777. let q = Object.getOwnPropertyDescriptor(p_a_obj, prop);
  3778. if (q && q.value) {
  3779. if (!q.writable) return q.value;
  3780. if (typeof q.value === 'string') return '';
  3781. if (typeof q.value === 'number') return 0;
  3782. if (typeof q.value === 'boolean') return false;
  3783. if (q.value && typeof q.value === 'object') return {};
  3784. }
  3785. }
  3786. return undefined;
  3787. },
  3788. set(target, prop, val) {
  3789. if (typeof val === 'boolean') boolList.add(prop)
  3790. throw `mqSet(${prop},${val})`;
  3791. }
  3792. });
  3793.  
  3794. let res = ''
  3795. try {
  3796. res = `RESULT::${p_a_obj.handleGlobalKeyUp.call(mq, 9, false, false, false, false, "Tab", "Tab")}`;
  3797. } catch (e) {
  3798. res = `ERROR::${e}`;
  3799. }
  3800.  
  3801. if (boolList.size === 1) {
  3802. const value = boolList.values().next().value;
  3803. if (res === `ERROR::mqSet(${value},${true})`) {
  3804. p_a_obj.__uZWaD__ = value;
  3805. }
  3806. }
  3807.  
  3808. console.log('[yt-js-engine-tamer] global shortcut control', { '__uZWaD__': p_a_obj.__uZWaD__ });
  3809.  
  3810. }
  3811.  
  3812.  
  3813. let pm_p_a = null;
  3814.  
  3815. const p_a_init = function () {
  3816. const r = this.init91();
  3817. const keyBw = this.__cPzfo__ || '__NIL__';
  3818. const p_a_obj = this[keyBw];
  3819. if (!p_a_obj) return;
  3820. try {
  3821. checkKeyB(p_a_obj);
  3822. } catch (e) { }
  3823. p_a_objWR = mWeakRef(p_a_obj);
  3824. if (FIX_SHORTCUTKEYS > 0) {
  3825. if (p_a_obj && !p_a_obj.hVhtg) {
  3826. p_a_obj.hVhtg = 1;
  3827.  
  3828. p_a_obj.handleGlobalKeyUp91 = p_a_obj.handleGlobalKeyUp;
  3829. p_a_obj.handleGlobalKeyUp = p_a_xt.handleGlobalKeyUp;
  3830. p_a_obj.handleGlobalKeyDown91 = p_a_obj.handleGlobalKeyDown;
  3831. p_a_obj.handleGlobalKeyDown = p_a_xt.handleGlobalKeyDown;
  3832. p_a_obj.__handleGlobalKeyBefore__ = p_a_xt.__handleGlobalKeyBefore__;
  3833. p_a_obj.__handleGlobalKeyAfter__ = p_a_xt.__handleGlobalKeyAfter__;
  3834.  
  3835. }
  3836. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE && p_a_obj && p_a_obj.api && !p_a_obj.api.hVhtg) {
  3837. // const api = p_a_obj.api
  3838. // api.hVhtg = 1;
  3839. // api.playVideo91 = api.playVideo;
  3840. // api.playVideo = p_a_jt.playVideo;
  3841. // api.pauseVideo91 = api.pauseVideo;
  3842. // api.pauseVideo = p_a_jt.pauseVideo;
  3843. // }
  3844. }
  3845. if (pm_p_a) {
  3846. pm_p_a.resolve();
  3847. pm_p_a = null;
  3848. }
  3849. return r;
  3850. };
  3851.  
  3852. const p_a_xt = {
  3853.  
  3854. __handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) {
  3855.  
  3856. if (FIX_SHORTCUTKEYS === 2) {
  3857.  
  3858. // if (flagSpeedMaster !== false && !getGlobalSpacebarControlFlag()) return false;
  3859.  
  3860. if (activeElement) {
  3861.  
  3862. const controlPhaseCache = wmKeyControlPhase.get(activeElement);
  3863.  
  3864. if (controlPhaseCache === 6 && getCurrentSelectionText() !== "") void 0;
  3865. else if (controlPhaseCache === 1 || controlPhaseCache === 2 || controlPhaseCache === 5) return false;
  3866. else if ((controlPhaseCache !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return false;
  3867.  
  3868. }
  3869.  
  3870. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  3871. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  3872. // console.log(582, isDelayedSpaceBar)
  3873. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  3874.  
  3875. if (activeElement && (h === 'Space' || h === 'Enter')) {
  3876. const controlPhase = wmKeyControlPhase.get(activeElement);
  3877. if (controlPhase === 4 || controlPhase === 5) return false;
  3878. }
  3879. if (focusedElementAtSelection === activeElement && getCurrentSelectionText() !== "") return false;
  3880. // if (!isSpeedMastSpacebarControlEnabled && a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space') {
  3881. // if (!isSpaceKeyImmediate) return false;
  3882. // }
  3883. }
  3884.  
  3885. },
  3886.  
  3887. __handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret) {
  3888.  
  3889. if (FIX_SHORTCUTKEYS === 2 && ret && a >= 32 && ytPageReady === 1 && Date.now() - lastUserAction < 40 && activeElement === document.activeElement) {
  3890.  
  3891. const isSpaceBar = a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space';
  3892. const isDelayedSpaceBar = FIX_SHORTCUTKEYS === 2 && isSpaceBar && !isSpaceKeyImmediate && (isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag());
  3893. // console.log(583, isDelayedSpaceBar)
  3894. if (isDelayedSpaceBar) return void 0; // accept delay spacebar under isSpeedMastSpacebarControlEnabled (no rejection)
  3895.  
  3896. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3897.  
  3898. let mediaWorking = false;
  3899. if (mediaPlayerElement && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2 && mediaPlayerElement.duration > 0.01) {
  3900. mediaWorking = true;
  3901. } else if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3902. mediaWorking = true;
  3903. }
  3904. // console.log(182, mediaWorking, mediaPlayerElement.readyState , mediaPlayerElement.networkState)
  3905. mediaWorking && Promise.resolve().then(() => {
  3906. if (activeElement === document.activeElement) {
  3907. return activeElement.blur()
  3908. } else {
  3909. return false
  3910. }
  3911. }).then((r) => {
  3912. r !== false && mediaPlayerElement.focus();
  3913. });
  3914. }
  3915. },
  3916.  
  3917.  
  3918. handleGlobalKeyUp(a, b, c, d, e, f, h) {
  3919.  
  3920. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3921.  
  3922. const activeElement = document.activeElement;
  3923.  
  3924. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3925. if (allow === false) return false;
  3926.  
  3927. const ret = this.handleGlobalKeyUp91(a, b, c, d, e, f, h);
  3928. // console.log('handleGlobalKeyUp',ret, a, b, c, d, e, f, h);
  3929.  
  3930. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3931.  
  3932. return ret;
  3933. },
  3934. handleGlobalKeyDown(a, b, c, d, e, f, h, l) {
  3935.  
  3936.  
  3937. if (BY_PASS_KEYBOARD_CONTROL) return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3938.  
  3939. const activeElement = document.activeElement;
  3940. // if (a === 32 && b === false && c === false && d === false && e === false && f === ' ' && h === 'Space' && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  3941. // return this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3942. // }
  3943. const allow = typeof this.__handleGlobalKeyBefore__ === 'function' ? this.__handleGlobalKeyBefore__(a, b, c, d, e, f, h, activeElement) : void 0;
  3944. if (allow === false) return false;
  3945.  
  3946. const ret = this.handleGlobalKeyDown91(a, b, c, d, e, f, h, l);
  3947. // console.log('handleGlobalKeyDown',ret, a, b, c, d, e, f, h,l)
  3948.  
  3949. typeof this.__handleGlobalKeyAfter__ === 'function' && this.__handleGlobalKeyAfter__(a, b, c, d, e, f, h, activeElement, ret);
  3950.  
  3951. return ret;
  3952. }
  3953.  
  3954. };
  3955.  
  3956. // const p_a_jt = { // API
  3957.  
  3958. // playVideo(a) { // without spinner effect
  3959.  
  3960. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3961.  
  3962. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3963. // if (mediaPlayerElement && !mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3964. // want_control_video = true;
  3965. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3966. // }
  3967.  
  3968. // }
  3969. // return this.playVideo91(a);
  3970.  
  3971. // },
  3972.  
  3973. // pauseVideo(a) { // without spinner effect
  3974.  
  3975. // if (CAN_TUNE_VOLUMN_AFTER_RESUME_OR_PAUSE) {
  3976.  
  3977. // const mediaPlayerElement = kRef(mediaPlayerElementWR);
  3978. // if (mediaPlayerElement && mediaPlayerElement.paused && !mediaPlayerElement.muted && mediaPlayerElement.duration > 0.01) {
  3979. // want_control_video = true;
  3980. // // Promise.resolve().then(()=> mediaPlayerElement.focus() );
  3981. // }
  3982.  
  3983. // }
  3984. // return this.pauseVideo91(a);
  3985.  
  3986. // }
  3987. // };
  3988.  
  3989. let flagSpeedMaster = null;
  3990. const getSpeedMasterControlFlag = () => {
  3991.  
  3992. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  3993. isSpeedMastSpacebarControlEnabled = false;
  3994. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control) {
  3995. isSpeedMastSpacebarControlEnabled = true;
  3996. }
  3997. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control) {
  3998. isSpeedMastSpacebarControlEnabled = true;
  3999. }
  4000.  
  4001. if (flagSpeedMaster === null) {
  4002. const p = (((config || 0).WEB_PLAYER_CONTEXT_CONFIGS || 0).WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH || 0).serializedExperimentFlags;
  4003. if (!p) {
  4004. flagSpeedMaster = false;
  4005. } else {
  4006.  
  4007. flagSpeedMaster = (p.includes('web_enable_speedmaster=true') && p.includes('web_speedmaster_spacebar_control=true') && p.includes('web_speedmaster_updated_edu=true'));
  4008.  
  4009. }
  4010.  
  4011. }
  4012. if (!flagSpeedMaster) isSpeedMastSpacebarControlEnabled = false;
  4013.  
  4014. return isSpeedMastSpacebarControlEnabled;
  4015. }
  4016.  
  4017.  
  4018. const getGlobalSpacebarControlFlag = () => {
  4019.  
  4020. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4021. isGlobalSpaceControl = false;
  4022. if (config && config.EXPERIMENT_FLAGS && config.EXPERIMENT_FLAGS.global_spacebar_pause) {
  4023. isGlobalSpaceControl = true;
  4024. }
  4025. if (config && config.EXPERIMENTS_FORCED_FLAGS && config.EXPERIMENTS_FORCED_FLAGS.global_spacebar_pause) {
  4026. isGlobalSpaceControl = true;
  4027. }
  4028.  
  4029. return isGlobalSpaceControl;
  4030. }
  4031.  
  4032. const keyboardController = async (_yt_player) => {
  4033.  
  4034. const keyQT = getQT(_yt_player);
  4035. const keySV = getSV(_yt_player);
  4036. const keyDX = getDX(_yt_player);
  4037. console.log(`[QT,SV,DX]`, [keyQT, keySV, keyDX]);
  4038.  
  4039. if (!keyDX) return;
  4040. if (keyDX === keyQT || keyDX === keySV) return;
  4041.  
  4042. if (typeof keyDX !== 'string') return;
  4043.  
  4044. let lastAccessKey = '';
  4045. let lastAccessKeyConfirmed = '';
  4046. const mb = new Proxy({}, {
  4047. get(target, prop) {
  4048. if (prop === 'handleGlobalKeyUp') lastAccessKeyConfirmed = lastAccessKey;
  4049. throw 'mbGet'
  4050. },
  4051. set(target, prop, val) {
  4052. throw 'mbSet'
  4053. }
  4054. });
  4055. const ma = new Proxy({}, {
  4056. get(target, prop) {
  4057. lastAccessKey = prop;
  4058. return mb
  4059. },
  4060. set(target, prop, val) {
  4061. throw 'maSet'
  4062. }
  4063. });
  4064.  
  4065. let keyBw = '';
  4066. try {
  4067. _yt_player[keyDX].prototype.handleGlobalKeyUp.call(ma);
  4068. } catch (e) {
  4069. if (e === 'mbGet' && typeof lastAccessKeyConfirmed === 'string' && lastAccessKeyConfirmed.length > 0) {
  4070. keyBw = lastAccessKeyConfirmed;
  4071. }
  4072. }
  4073.  
  4074. if (!keyBw) return;
  4075.  
  4076. if (typeof _yt_player[keyDX].prototype.init !== 'function' || _yt_player[keyDX].prototype.init.length !== 0) return;
  4077.  
  4078. pm_p_a = new PromiseExternal();
  4079.  
  4080. _yt_player[keyDX].prototype.__cPzfo__ = keyBw;
  4081.  
  4082. _yt_player[keyDX].prototype.init91 = _yt_player[keyDX].prototype.init;
  4083.  
  4084. _yt_player[keyDX].prototype.init = p_a_init;
  4085.  
  4086. await pm_p_a.then();
  4087. const p_a_obj = kRef(p_a_objWR);
  4088.  
  4089. const isSpeedMastSpacebarControlEnabledA = getSpeedMasterControlFlag();
  4090.  
  4091.  
  4092. if (CHANGE_SPEEDMASTER_SPACEBAR_CONTROL > 0) {
  4093.  
  4094. isSpeedMastSpacebarControlEnabled = CHANGE_SPEEDMASTER_SPACEBAR_CONTROL == 1;
  4095.  
  4096. if (!isSpeedMastSpacebarControlEnabled) {
  4097.  
  4098. if (config && config.EXPERIMENT_FLAGS) {
  4099. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = false;
  4100. }
  4101. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  4102. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = false;
  4103. }
  4104.  
  4105. } else {
  4106.  
  4107. if (config && config.EXPERIMENT_FLAGS) {
  4108. config.EXPERIMENT_FLAGS.web_speedmaster_spacebar_control = true;
  4109. }
  4110. if (config && config.EXPERIMENTS_FORCED_FLAGS) {
  4111. config.EXPERIMENTS_FORCED_FLAGS.web_speedmaster_spacebar_control = true;
  4112. }
  4113.  
  4114. }
  4115.  
  4116. }
  4117.  
  4118. const isSpeedMastSpacebarControlEnabledB = getSpeedMasterControlFlag();
  4119.  
  4120.  
  4121.  
  4122.  
  4123. console.log('[yt-js-engine-tamer] speedmaster by space (yt setting)', isSpeedMastSpacebarControlEnabledA, isSpeedMastSpacebarControlEnabledB);
  4124.  
  4125. // console.log(p_a_obj.handleGlobalKeyUp)
  4126. console.log('[yt-js-engine-tamer] p_a', p_a_obj);
  4127.  
  4128. // console.log(p_a_obj.api)
  4129.  
  4130.  
  4131. // QT -> DX(SV) -> p_a
  4132.  
  4133.  
  4134. /*
  4135. *
  4136. *
  4137. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  4138. b = void 0 === b ? !1 : b;
  4139. c = void 0 === c ? !1 : c;
  4140. d = void 0 === d ? !1 : d;
  4141. e = void 0 === e ? !1 : e;
  4142. var l = g.PT(this);
  4143. l && l.handleGlobalKeyUp(a, b, c, d, e, f, h)
  4144. }
  4145.  
  4146. */
  4147.  
  4148. /*
  4149. *
  4150. *
  4151. *
  4152. g.k.handleGlobalKeyUp = function(a, b, c, d, e, f, h) {
  4153. return this.Bw ? this.Bw.handleGlobalKeyUp(a, b, c, d, e, f, h) : !1
  4154. }
  4155.  
  4156. */
  4157.  
  4158.  
  4159. // if(!keyDX) return;
  4160.  
  4161. // console.log(4999, keyDX)
  4162.  
  4163. };
  4164.  
  4165.  
  4166. const ytResumeFn = function () { // ADVANCED_FIX_SHORTCUTKEYS
  4167.  
  4168. const p_a_obj = kRef(p_a_objWR);
  4169. // const api = p_a_obj.api;
  4170.  
  4171.  
  4172. // console.log(540);
  4173.  
  4174. let boolList = null;
  4175. let ret;
  4176. isSpaceKeyImmediate = true;
  4177. try {
  4178.  
  4179. ret = 0;
  4180. ret = ret | (p_a_obj.handleGlobalKeyDown(32, false, false, false, false, ' ', 'Space', false) ? 1 : 0);
  4181. let p_a_objT;
  4182. if (!spaceBarControl_keyG) { // just in case
  4183. boolList = new Set();
  4184. p_a_objT = new Proxy(p_a_obj, {
  4185. get(target, prop, handler) {
  4186. const val = target[prop];
  4187. if (typeof val !== 'boolean') return val;
  4188. boolList.add(prop);
  4189. // console.log(555, prop, val);
  4190. if (typeof prop === 'string' && prop.length <= 3 && val === true && boolList.length === 1) {
  4191. spaceBarControl_keyG = prop;
  4192. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4193. val = false;
  4194. }
  4195. return val;
  4196. }
  4197. });
  4198.  
  4199.  
  4200. } else if (p_a_obj[spaceBarControl_keyG] === true) {
  4201. p_a_obj[spaceBarControl_keyG] = false;
  4202. p_a_objT = p_a_obj;
  4203. // console.log(p_a_obj, spaceBarControl_keyG, p_a_obj[spaceBarControl_keyG] )
  4204. } else {
  4205.  
  4206. p_a_objT = p_a_obj;
  4207. }
  4208.  
  4209. ret = ret | (p_a_objT.handleGlobalKeyUp(32, false, false, false, false, ' ', 'Space') ? 2 : 0);
  4210.  
  4211.  
  4212. } catch (e) {
  4213. console.log(e)
  4214. }
  4215. isSpaceKeyImmediate = false;
  4216.  
  4217. if (boolList && boolList.size === 1) {
  4218. const value = boolList.values().next().value;
  4219. spaceBarControl_keyG = value;
  4220. p_a_obj.__uZWaD__ = spaceBarControl_keyG;
  4221.  
  4222. }
  4223.  
  4224. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4225.  
  4226. return ret;
  4227. }
  4228.  
  4229. const shortcutKeysFixer = () => {
  4230.  
  4231. let pausePromiseControlJ = 0;
  4232.  
  4233.  
  4234. const obtainCurrentControlPhase = (evt, mediaPlayerElement) => {
  4235.  
  4236. let controlPhase = 0;
  4237. const aElm = document.activeElement;
  4238.  
  4239. if (aElm) {
  4240.  
  4241. const controlPhaseCache = wmKeyControlPhase.get(aElm);
  4242.  
  4243. if (typeof controlPhaseCache === 'number') {
  4244.  
  4245. controlPhase = controlPhaseCache;
  4246. } else {
  4247.  
  4248. if (aElm instanceof HTMLInputElement) controlPhase = 1;
  4249. else if (aElm instanceof HTMLTextAreaElement) controlPhase = 1;
  4250. else if (aElm instanceof HTMLButtonElement) controlPhase = 2;
  4251. else if (aElm instanceof HTMLIFrameElement) controlPhase = 2;
  4252. else if (aElm instanceof HTMLImageElement) controlPhase = 2;
  4253. else if (aElm instanceof HTMLEmbedElement) controlPhase = 2;
  4254. else {
  4255. if (aElm instanceof HTMLElement_ && aElm.closest('[role]')) controlPhase = 5;
  4256. if (aElm instanceof HTMLDivElement) controlPhase = 2;
  4257. else if (aElm instanceof HTMLAnchorElement) controlPhase = 2;
  4258. else if (!(aElm instanceof HTMLElement_) && (aElm instanceof Element)) controlPhase = 2; // svg
  4259. }
  4260.  
  4261. if ((controlPhase === 2 || controlPhase === 5) && (aElm instanceof HTMLElement_) && aElm.contains(mediaPlayerElement)) {
  4262. controlPhase = 0;
  4263. }
  4264.  
  4265. if ((controlPhase === 2 || controlPhase === 5) && evt && evt.target && evt.target === aElm) {
  4266. if (aElm.closest('[contenteditable], input, textarea')) {
  4267. controlPhase = 5;
  4268. } else if (aElm.closest('button')) {
  4269. controlPhase = 4;
  4270. }
  4271. }
  4272.  
  4273. if (aElm.closest('#movie_player')) controlPhase = 6;
  4274.  
  4275. wmKeyControlPhase.set(aElm, controlPhase);
  4276.  
  4277. }
  4278. }
  4279.  
  4280. return controlPhase;
  4281.  
  4282. }
  4283.  
  4284. const isStateControllable = (api) => {
  4285. let appState = null;
  4286. let playerState = null;
  4287. let adState = null;
  4288. try {
  4289. appState = api.getAppState();
  4290. playerState = api.getPlayerState();
  4291. adState = api.getAdState();
  4292. } catch (e) { }
  4293. // ignore playerState -1
  4294. return appState === 5 && adState === -1 && (playerState === 1 || playerState === 2 || playerState === 3);
  4295. };
  4296.  
  4297.  
  4298. const keyEventListener = (evt) => {
  4299. if (BY_PASS_KEYBOARD_CONTROL) return;
  4300.  
  4301. if (evt.isTrusted && evt instanceof Event) lastUserAction = Date.now();
  4302. if (isSpaceKeyImmediate || !evt.isTrusted || !(evt instanceof KeyboardEvent)) return;
  4303. if (!ytPageReady) return;
  4304.  
  4305. if (evt.defaultPrevented === true) return;
  4306.  
  4307. const p_a_obj = kRef(p_a_objWR);
  4308.  
  4309. if (!p_a_obj) return;
  4310.  
  4311.  
  4312. const mediaPlayerElement = kRef(mediaPlayerElementWR);
  4313. if (!mediaPlayerElement) return;
  4314.  
  4315. // let focusBodyIfSuccess = false;
  4316.  
  4317. const controlPhase = obtainCurrentControlPhase(evt, mediaPlayerElement);
  4318.  
  4319. if (controlPhase === 6 && getCurrentSelectionText() !== "") void 0;
  4320. else if (controlPhase === 1 || controlPhase === 2 || controlPhase === 5) return;
  4321. else if ((controlPhase !== 6 || focusedElementAtSelection === document.activeElement) && getCurrentSelectionText() !== "") return;
  4322.  
  4323.  
  4324. if (evt.code === 'Space' && !getGlobalSpacebarControlFlag()) return;
  4325.  
  4326. // console.log(`${evt.type}::controlPhase`,controlPhase)
  4327.  
  4328. // if (controlPhase == 4) {
  4329. // focusBodyIfSuccess = true;
  4330. // }
  4331.  
  4332. spaceBarControl_keyG = spaceBarControl_keyG || p_a_obj.__uZWaD__ || ''
  4333. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4334.  
  4335. if (FIX_SHORTCUTKEYS < 2) return;
  4336. if (!(!evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey)) return; // ignore if modifier key is pressed -> let other event listener to handle first
  4337.  
  4338. let rr;
  4339. const isSpaceBar = evt.code === 'Space' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey && !evt.metaKey;
  4340.  
  4341.  
  4342.  
  4343. let useImprovedPauseResume = false;
  4344.  
  4345. if (USE_IMPROVED_PAUSERESUME_UNDER_NO_SPEEDMASTER && isSpaceBar && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4346.  
  4347. const api = p_a_obj.api;
  4348. const stateControllable = isStateControllable(api);
  4349. // console.log(2122, appState, playerState, adState)
  4350.  
  4351. if (stateControllable && isWatchPageURL() && mediaPlayerElement.duration > 0.01 && (mediaPlayerElement.readyState === 4 || mediaPlayerElement.readyState === 1) && mediaPlayerElement.networkState === 2) {
  4352.  
  4353. useImprovedPauseResume = true;
  4354.  
  4355. }
  4356.  
  4357.  
  4358. }
  4359.  
  4360.  
  4361. // force flag: CHANGE_SPEEDMASTER_SPACEBAR_CONTROL
  4362. if (evt.type === 'keydown') {
  4363.  
  4364. if (useImprovedPauseResume) {
  4365.  
  4366. const isPaused = mediaPlayerElement.paused;
  4367.  
  4368. const cj = ++pausePromiseControlJ;
  4369. Promise.resolve().then(() => {
  4370.  
  4371. if (cj !== pausePromiseControlJ) return;
  4372.  
  4373. if (mediaPlayerElement.paused !== isPaused) return;
  4374.  
  4375. const ret = ytResumeFn();
  4376. if (!ret) { // fallback
  4377. isPaused ? api.playVideo() : api.pauseVideo();
  4378. }
  4379.  
  4380. /*
  4381. let a = void 0;
  4382. console.log('Rb', api.Rb())
  4383. a = !window._yt_player.nL(api.Rb());
  4384. p_a_obj.Wd.kG(a)
  4385. a ? api.playVideo() : api.pauseVideo();
  4386.  
  4387. */
  4388.  
  4389.  
  4390. });
  4391. rr = true;
  4392. } else {
  4393.  
  4394. isSpaceKeyImmediate = true;
  4395. rr = p_a_obj.handleGlobalKeyDown(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code, evt.repeat);
  4396. isSpaceKeyImmediate = false;
  4397. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4398.  
  4399. }
  4400.  
  4401.  
  4402. } else if (evt.type === 'keyup') {
  4403.  
  4404. if (isSpaceBar && useImprovedPauseResume && !(isSpeedMastSpacebarControlEnabled = getSpeedMasterControlFlag())) {
  4405.  
  4406. rr = true;
  4407. } else {
  4408.  
  4409. isSpaceKeyImmediate = true;
  4410. rr = p_a_obj.handleGlobalKeyUp(evt.keyCode, evt.shiftKey, evt.ctrlKey, evt.altKey, evt.metaKey, evt.key, evt.code);
  4411. isSpaceKeyImmediate = false;
  4412. if (spaceBarControl_keyG && p_a_obj[spaceBarControl_keyG] === true) p_a_obj[spaceBarControl_keyG] = false;
  4413.  
  4414. }
  4415.  
  4416.  
  4417. /*
  4418.  
  4419. if (d)
  4420. switch (c) {
  4421. case 32:
  4422. case 13:
  4423. if ("BUTTON" === d.tagName || "A" === d.tagName || "INPUT" === d.tagName)
  4424. b = !0,
  4425. e = !1;
  4426. else if (e) {
  4427. var m = d.getAttribute("role");
  4428. !m || "option" !== m && "button" !== m && 0 !== m.indexOf("menuitem") || (b = !0,
  4429. d.click(),
  4430. f = !0)
  4431. }
  4432. break;
  4433. case 37:
  4434. case 39:
  4435. case 36:
  4436. case 35:
  4437. b = "slider" === d.getAttribute("role");
  4438. break;
  4439. case 38:
  4440. case 40:
  4441. m = d.getAttribute("role"),
  4442. d = 38 === c ? d.previousSibling : d.nextSibling,
  4443. "slider" === m ? b = !0 : e && ("option" === m ? (d && "option" === d.getAttribute("role") && d.focus(),
  4444. f = b = !0) : m && 0 === m.indexOf("menuitem") && (d && d.hasAttribute("role") && 0 === d.getAttribute("role").indexOf("menuitem") && d.focus(),
  4445. f = b = !0))
  4446. }
  4447. if (e && !f)
  4448. switch (c) {
  4449. case 38:
  4450. f = Math.min(this.api.getVolume() + 5, 100);
  4451. XV(this.Wd, f, !1);
  4452. this.api.setVolume(f);
  4453. h = f = !0;
  4454. break;
  4455. case 40:
  4456. f = Math.max(this.api.getVolume() - 5, 0);
  4457. XV(this.Wd, f, !0);
  4458. this.api.setVolume(f);
  4459. h = f = !0;
  4460. break;
  4461. case 36:
  4462. this.api.Yh() && (this.api.startSeekCsiAction(),
  4463. this.api.seekTo(0, void 0, void 0, void 0, 79),
  4464. h = f = !0);
  4465. break;
  4466. case 35:
  4467. this.api.Yh() && (this.api.startSeekCsiAction(),
  4468. this.api.seekTo(Infinity, void 0, void 0, void 0, 80),
  4469. h = f = !0)
  4470. }
  4471. */
  4472.  
  4473. }
  4474.  
  4475.  
  4476. if (rr) {
  4477.  
  4478. // focusBodyIfSuccess && Promise.resolve().then(() => {
  4479. // activeElement === document.activeElement && activeElement.blur();
  4480. // });
  4481.  
  4482. evt.preventDefault();
  4483. evt.stopImmediatePropagation();
  4484. evt.stopPropagation();
  4485.  
  4486. }
  4487.  
  4488. };
  4489.  
  4490. document.addEventListener('keydown', keyEventListener, { capture: true });
  4491.  
  4492.  
  4493. document.addEventListener('keyup', keyEventListener, { capture: true });
  4494.  
  4495. }
  4496.  
  4497. return { pageMediaWatcher, shortcutKeysFixer, keyboardController };
  4498.  
  4499. })();
  4500.  
  4501.  
  4502. pageMediaWatcher();
  4503. FIX_SHORTCUTKEYS > 0 && shortcutKeysFixer();
  4504.  
  4505.  
  4506. const check_for_set_key_order = (() => {
  4507.  
  4508. let mySet = new Set();
  4509.  
  4510. mySet.add("value1");
  4511. mySet.add("value2");
  4512. mySet.add("value3");
  4513.  
  4514. // Function to convert Set values to an array
  4515. function getSetValues(set) {
  4516. return Array.from(set.values());
  4517. }
  4518.  
  4519. // Function to test if the Set maintains insertion order
  4520. function testSetOrder(set, expectedOrder) {
  4521. let values = getSetValues(set);
  4522. return expectedOrder.join(',') === values.join(',');
  4523. }
  4524.  
  4525. // Test 1: Initial order
  4526. if (mySet.values().next().value !== "value1") return false;
  4527. if (!testSetOrder(mySet, ["value1", "value2", "value3"])) return false;
  4528.  
  4529. // Test 2: After deleting an element
  4530. mySet.delete("value2");
  4531. if (mySet.values().next().value !== "value1") return false;
  4532. if (!testSetOrder(mySet, ["value1", "value3"])) return false;
  4533.  
  4534. // Test 3: After re-adding a deleted element
  4535. mySet.add("value2");
  4536. if (mySet.values().next().value !== "value1") return false;
  4537. if (!testSetOrder(mySet, ["value1", "value3", "value2"])) return false;
  4538.  
  4539. // Test 4: After adding a new element
  4540. mySet.add("value4");
  4541. if (mySet.values().next().value !== "value1") return false;
  4542. if (!testSetOrder(mySet, ["value1", "value3", "value2", "value4"])) return false;
  4543.  
  4544. // Test 5: Delete+Add
  4545. mySet.delete("value1");
  4546. mySet.delete("value3");
  4547. mySet.add("value3");
  4548. mySet.add("value1");
  4549. if (mySet.values().next().value !== "value2") return false;
  4550. if (!testSetOrder(mySet, ["value2", "value4", "value3", "value1"])) return false;
  4551.  
  4552. return true;
  4553. })();
  4554.  
  4555.  
  4556. // const qm47 = Symbol();
  4557. const qm57 = Symbol();
  4558. const qm53 = Symbol();
  4559. const qn53 = Symbol();
  4560.  
  4561.  
  4562. const ump3 = new WeakMap();
  4563.  
  4564. const stp = document.createElement('noscript');
  4565. stp.id = 'weakref-placeholder';
  4566.  
  4567. PROP_OverReInclusion_AVOID && (() => {
  4568.  
  4569.  
  4570. if (typeof HTMLElement_.prototype.hasOwnProperty72 === 'function' || typeof HTMLElement_.prototype.hasOwnProperty !== 'function') return;
  4571. const f = HTMLElement_.prototype.hasOwnProperty72 = HTMLElement_.prototype.hasOwnProperty;
  4572. let byPassVal = null;
  4573. let byPassCount = 0;
  4574. let mmw = new Set();
  4575. HTMLElement_.prototype.hasOwnProperty = function (prop) {
  4576. if (arguments.length !== 1) return f.apply(this, arguments);
  4577. if (byPassVal !== null && typeof prop === 'string') {
  4578.  
  4579. if (PROP_OverReInclusion_LIST.has(prop)) {
  4580. byPassCount++;
  4581. return byPassVal;
  4582. }
  4583. PROP_OverReInclusion_DEBUGLOG && mmw.add(prop);
  4584.  
  4585. }
  4586. return this.hasOwnProperty72(prop);
  4587. };
  4588.  
  4589.  
  4590. /*
  4591.  
  4592.  
  4593. z.prototype.forwardDynamicProps = function() {
  4594. var B = m(this.inst);
  4595. B = h(B);
  4596. for (var F = B.next(); !F.done; F = B.next()) {
  4597. var H = h(F.value);
  4598. F = H.next().value;
  4599. H = H.next().value;
  4600. my(this, F, H);
  4601. r(b) && !ly(F) && Wua(this.inst, F)
  4602. }
  4603. }
  4604.  
  4605. */
  4606.  
  4607.  
  4608.  
  4609. let byPassZeroShowed = false;
  4610. const forwardDynamicPropsGeneral = function () {
  4611. byPassVal = true;
  4612. byPassCount = 0;
  4613. PROP_OverReInclusion_DEBUGLOG && mmw.clear();
  4614. const ret = this.forwardDynamicProps72();
  4615. byPassVal = null;
  4616. if (byPassCount === 0 && !byPassZeroShowed) {
  4617. byPassZeroShowed = true;
  4618. console.log('[yt-js-engine-tamer] byPassCount = 0 in forwardDynamicProps')
  4619. }
  4620. byPassCount = 0;
  4621. if (PROP_OverReInclusion_DEBUGLOG && mmw.size > 0) {
  4622. console.log(399, '[yt-js-engine-tamer]', [...mmw]);
  4623. mmw.clear();
  4624. }
  4625. return ret;
  4626. };
  4627.  
  4628. const propCheck = (proto) => {
  4629. if (typeof (proto || 0) == 'object' && typeof proto.forwardDynamicProps === 'function' && typeof proto.forwardDynamicProps72 !== 'function') {
  4630. proto.forwardDynamicProps72 = proto.forwardDynamicProps;
  4631. if (proto.forwardDynamicProps.length === 0) {
  4632. proto.forwardDynamicProps = forwardDynamicPropsGeneral;
  4633. }
  4634. }
  4635. };
  4636.  
  4637. const valMap = new WeakMap();
  4638. Object.defineProperty(HTMLElement_.prototype, 'didForwardDynamicProps', {
  4639. get() {
  4640. propCheck(this.constructor.prototype);
  4641. return valMap.get(this);
  4642. },
  4643. set(nv) {
  4644. propCheck(this.constructor.prototype);
  4645. valMap.set(this, nv);
  4646. return true;
  4647. },
  4648. enumerable: false,
  4649. configurable: true
  4650.  
  4651. });
  4652.  
  4653. promiseForCustomYtElementsReady.then(() => {
  4654. if (typeof customElements !== 'object' || typeof customElements.define72 === 'function' || typeof customElements.define !== 'function') return;
  4655. if (customElements.define.length !== 2) return;
  4656. customElements.define72 = customElements.define;
  4657. customElements.define = function (b, w) {
  4658. propCheck(w.prototype);
  4659. const ret = this.define72(b, w);
  4660. return ret;
  4661. }
  4662. });
  4663.  
  4664. })();
  4665.  
  4666.  
  4667. let marcoPr = new PromiseExternal();
  4668. const trackMarcoCm = document.createComment('1');
  4669. const trackMarcoCmObs = new MutationObserver(() => {
  4670. marcoPr.resolve();
  4671. marcoPr = new PromiseExternal();
  4672. });
  4673. trackMarcoCmObs.observe(trackMarcoCm, { characterData: true });
  4674.  
  4675.  
  4676. // ----------------------------
  4677.  
  4678.  
  4679. // const pendingStampFlushs = [];
  4680.  
  4681. const nativeNow = performance.constructor.prototype.now.bind(performance);
  4682.  
  4683. const queueMicrotask_ = typeof queueMicrotask === 'function' ? queueMicrotask : (f) => (Promise.resolve().then(f), void 0);
  4684.  
  4685. FIX_ICON_RENDER && whenCEDefined('yt-icon').then(async () => {
  4686.  
  4687.  
  4688. // const globalPromiseStack = {};
  4689.  
  4690. // let dummy;
  4691. // while(!dummy){
  4692.  
  4693. // dummy = document.querySelector('yt-icon');
  4694. // await new Promise(r=>setTimeout(r,0));
  4695. // }
  4696.  
  4697. dummy = document.createElement('yt-icon');
  4698.  
  4699. let cProto;
  4700. if (!(dummy instanceof Element)) return;
  4701. cProto = insp(dummy).constructor.prototype;
  4702.  
  4703. cProto.handlePropertyChange671 = cProto.handlePropertyChange;
  4704. cProto.determineIconSet671 = cProto.determineIconSet;
  4705. cProto.switchToYtSysIconset671 = cProto.switchToYtSysIconset;
  4706. cProto.useYtSysIconsetForMissingIcons671 = cProto.useYtSysIconsetForMissingIcons;
  4707. cProto.getIconManager671 = cProto.getIconManager;
  4708. cProto.getIconShapeData671 = cProto.getIconShapeData;
  4709. cProto.renderIcon671 = cProto.renderIcon;
  4710.  
  4711. // cProto.attached488 = cProto.attached;
  4712. // cProto.attached = function(){
  4713. // console.log('attached')
  4714. // return this.attached488(...arguments);
  4715. // }
  4716. // cProto.detached488 = cProto.detached;
  4717. // cProto.detached = function(){
  4718. // console.log('detached')
  4719. // return this.detached488(...arguments);
  4720. // }
  4721.  
  4722. if (cProto.__renderIconFix__) return;
  4723. cProto.__renderIconFix__ = true;
  4724.  
  4725. let taskStack = [];
  4726. const cmObs = new MutationObserver(() => {
  4727. const tasks = taskStack.slice();
  4728. taskStack.length = 0;
  4729. for (const task of tasks) {
  4730. task();
  4731. }
  4732. })
  4733. const cm = document.createComment('1');
  4734. const stackTask = (f) => {
  4735. taskStack.push(f);
  4736. cm.data = `${(cm.data & 7) + 1}`;
  4737. }
  4738. cmObs.observe(cm, { characterData: true });
  4739.  
  4740. // let iconManagers = {}; // assume shared
  4741.  
  4742. // window.iconManagers = () => iconManagers;
  4743.  
  4744.  
  4745. const setupYtIcon = (inst) => {
  4746.  
  4747. if (inst.__ytIconSetup588__) return;
  4748. const cProto = Reflect.getPrototypeOf(inst);
  4749. cProto.__ytIconSetup588__ = true;
  4750.  
  4751.  
  4752. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  4753.  
  4754. config.EXPERIMENT_FLAGS.wil_icon_render_when_idle = false; // single rendering
  4755. config.EXPERIMENT_FLAGS.wil_icon_load_immediately = true; // single rendering
  4756. // config.EXPERIMENT_FLAGS.wil_icon_use_mask_rendering = false; // DON'T!
  4757. config.EXPERIMENT_FLAGS.wil_icon_network_first = true; // single rendering
  4758.  
  4759.  
  4760. // this.renderingMode = _.x("wil_icon_use_mask_rendering") ? 1 : 0;
  4761. // this.isNetworkFirstStrategy = _.x("wil_icon_network_first");
  4762. // this.renderWhenIdle = _.x("wil_icon_render_when_idle");
  4763. // this.waitForAnimationFrame = !_.x("wil_icon_load_immediately");
  4764.  
  4765.  
  4766.  
  4767. }
  4768.  
  4769. cProto.handlePropertyChange = function (...a) { // 10+
  4770.  
  4771. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4772. this.__resolved__ = {
  4773.  
  4774. };
  4775. const a01 = this.isAttached;
  4776. let a02, a03;
  4777.  
  4778.  
  4779. const t = this.__stackedKey3818__ = (this.__stackedKey3818__ & 1073741823) + 1;
  4780.  
  4781. const stackFn = () => {
  4782. if (t !== this.__stackedKey3818__) {
  4783. return;
  4784. }
  4785. a03 = this.isAttached;
  4786.  
  4787. if (a01 === false && a02 === false && a03 === false) return;
  4788.  
  4789. if (a01 === true && a02 === true && a03 === true) {
  4790.  
  4791. } else {
  4792. if (a01 === undefined && a02 === undefined && a03 === undefined && (this.hostElement || this).isConnected === false) {
  4793. // unknown yt-icon#label-icon
  4794. return;
  4795. } else {
  4796. console.log('[yt-icon] debug', a01, a02, a03, this)
  4797. }
  4798. }
  4799.  
  4800. this.handlePropertyChange671(...arguments);
  4801.  
  4802. };
  4803.  
  4804.  
  4805.  
  4806. Promise.resolve().then(() => {
  4807. a02 = this.isAttached;
  4808. stackTask(stackFn);
  4809. });
  4810.  
  4811.  
  4812. }
  4813.  
  4814. cProto.determineIconSet = function (a, b, c, d) { // 10-
  4815.  
  4816. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4817. // string bool? bool=false int=24
  4818. // NOTIFICATIONS_NONE OR LIKE
  4819. // console.log('yt-icon.determineIconSet', ...arguments);
  4820.  
  4821. const r = this.determineIconSet671(...arguments);
  4822. return r;
  4823. }
  4824.  
  4825. cProto.switchToYtSysIconset = function (a, b, c, d) { // 10-
  4826.  
  4827. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4828. // same as determineIconSet
  4829. // console.log('yt-icon.switchToYtSysIconset', ...arguments);
  4830. return this.switchToYtSysIconset671(...arguments);
  4831. }
  4832.  
  4833. cProto.useYtSysIconsetForMissingIcons = function (a, b, c, d) { // X
  4834.  
  4835. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4836. // console.log('yt-icon.useYtSysIconsetForMissingIcons', ...arguments);
  4837. return this.useYtSysIconsetForMissingIcons671(...arguments);
  4838. }
  4839.  
  4840. cProto.getIconManager = function () { // 10+
  4841.  
  4842. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4843. if (!this.__resolved__) this.__resolved__ = {};
  4844. if (!this.__resolved__.getIconManager) this.__resolved__.getIconManager = this.getIconManager671(...arguments);
  4845. const r = this.__resolved__.getIconManager;
  4846. return r;
  4847. }
  4848.  
  4849. cProto.getIconShapeData = function () { // 10+
  4850.  
  4851. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4852.  
  4853. // no argument
  4854. // console.log('yt-icon.getIconShapeData', ...arguments);
  4855. if (!this.__resolved__) this.__resolved__ = {};
  4856. if (!this.__resolved__.getIconShapeData) this.__resolved__.getIconShapeData = this.getIconShapeData671(...arguments);
  4857. const r = this.__resolved__.getIconShapeData;
  4858. return r
  4859. }
  4860.  
  4861. cProto.renderIcon = function (a, b) { // X
  4862.  
  4863. if (!this.__ytIconSetup588__) setupYtIcon(this);
  4864. // "" yt-icons:xxx
  4865. // console.log('yt-icon.renderIcon', ...arguments);
  4866. return this.renderIcon671(...arguments);
  4867. }
  4868.  
  4869. });
  4870.  
  4871. const createStampDomFnsB_ = () => {
  4872.  
  4873. const config = ((win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0);
  4874.  
  4875. if (config.DEFERRED_DETACH === true) config.DEFERRED_DETACH = false;
  4876. if (config.REUSE_COMPONENTS === true) config.REUSE_COMPONENTS = false;
  4877.  
  4878.  
  4879. const rq0 = document.createElement('rp');
  4880. rq0.setAttribute('yt-element-placholder', '');
  4881.  
  4882. let activeStampContainerId = '';
  4883.  
  4884. const componentBasedTaskPool = new WeakMap();
  4885.  
  4886.  
  4887. Node.prototype.checkFF = function () {
  4888. const pTask = componentBasedTaskPool.get(this);
  4889. if (!pTask) return null;
  4890. return [pTask, taskList.filter(e => e.taskId === pTask.taskId), taskList.filter(e => e.componentWr === this[wk])];
  4891. }
  4892.  
  4893. Node.prototype.checkGG = function () {
  4894. window.me849 = this;
  4895. const pTask = componentBasedTaskPool.get(this);
  4896. if (!pTask) return null;
  4897. window.me848 = pTask.taskId;
  4898. debugger;
  4899. loopTask();
  4900. }
  4901.  
  4902. NodeList.prototype.last = function () {
  4903. return this[this.length - 1];
  4904. }
  4905.  
  4906. const getStampContainer_ = function (containerId) {
  4907.  
  4908. // if(this.__byPass828__) return this.getStampContainer7409_(containerId);
  4909.  
  4910. this.__activeContainerId929__ = containerId;
  4911.  
  4912. return this.getStampContainer7409_(containerId);
  4913.  
  4914. }
  4915.  
  4916.  
  4917.  
  4918. const it0 = Date.now() - 80000000000;
  4919. const genId = () => `${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}_${(Date.now() - it0).toString(36)}`;
  4920.  
  4921.  
  4922. const createComponent_ = function (componentConfig, data, canReuse) {
  4923.  
  4924. this.___lastCreate3311__ = data;
  4925.  
  4926.  
  4927.  
  4928. if (this.__directProduction533__) {
  4929. const cName = this.getComponentName_(componentConfig, data);
  4930.  
  4931. return document.createElement(cName);
  4932. }
  4933.  
  4934. if (this.__byPass828__ || !this.__byPass348__) {
  4935.  
  4936. // console.log(39829004)
  4937. // console.log(new Error().stack)
  4938. return this.createComponent7409_(componentConfig, data, false);
  4939. }
  4940.  
  4941.  
  4942. const containerId = this.__activeContainerId929__;
  4943.  
  4944. // console.log(2883007, componentConfig, data, canReuse)
  4945.  
  4946. const r = rq0.cloneNode(false);
  4947.  
  4948. r.is = 'aa-bb-cc-dd';
  4949.  
  4950. return r;
  4951.  
  4952.  
  4953. }
  4954.  
  4955.  
  4956. const childrenObs = new MutationObserver((mutations) => {
  4957. loopTask();
  4958. });
  4959.  
  4960.  
  4961. class CTaskList {
  4962. constructor() {
  4963. this.head = this.tail = null;
  4964.  
  4965. // ref → {prev, next, level}
  4966. this.nodes = new Map();
  4967.  
  4968. // Per‑level sentinels
  4969. this.levelHead = [];
  4970. this.levelTail = [];
  4971.  
  4972. // Sorted list of non‑empty levels for O(log L) neighbour lookup
  4973. this.nonEmptyLevels = [];
  4974. this.counter = 0;
  4975. }
  4976.  
  4977. _ensure(level) {
  4978. while (this.levelTail.length <= level) {
  4979. this.levelTail.push(null);
  4980. this.levelHead.push(null);
  4981. }
  4982. }
  4983.  
  4984. // Binary‑search index inside nonEmptyLevels
  4985. _indexOfLevel(level) {
  4986. let lo = 0, hi = this.nonEmptyLevels.length;
  4987. while (lo < hi) {
  4988. const mid = (lo + hi) >> 1;
  4989. if (this.nonEmptyLevels[mid] < level) lo = mid + 1;
  4990. else hi = mid;
  4991. }
  4992. return lo;
  4993. }
  4994.  
  4995. _link(ref, prev, next, level) {
  4996.  
  4997.  
  4998. this.nodes.set(ref, { prev, next, level });
  4999.  
  5000. if (prev) this.nodes.get(prev).next = ref;
  5001. else this.head = ref;
  5002.  
  5003. if (next) this.nodes.get(next).prev = ref;
  5004. else this.tail = ref;
  5005.  
  5006. this.levelTail[level] = ref;
  5007. if (!this.levelHead[level]) this.levelHead[level] = ref;
  5008. }
  5009.  
  5010. _detach(ref) {
  5011. if (!ref || !this.nodes.has(ref)) return;
  5012.  
  5013.  
  5014. const { prev, next, level } = this.nodes.get(ref);
  5015.  
  5016. if (prev) this.nodes.get(prev).next = next;
  5017. else this.head = next;
  5018.  
  5019. if (next) this.nodes.get(next).prev = prev;
  5020. else this.tail = prev;
  5021.  
  5022. if (this.levelTail[level] === ref) {
  5023. this.levelTail[level] = prev && this.nodes.get(prev)?.level === level ? prev : null;
  5024. }
  5025. if (this.levelHead[level] === ref) {
  5026. this.levelHead[level] = next && this.nodes.get(next)?.level === level ? next : null;
  5027. }
  5028.  
  5029. if (this.levelTail[level] === null) {
  5030. const idx = this.nonEmptyLevels.indexOf(level);
  5031. if (idx !== -1) this.nonEmptyLevels.splice(idx, 1);
  5032. }
  5033.  
  5034. this.nodes.delete(ref);
  5035.  
  5036. }
  5037.  
  5038. push(component, level) {
  5039. if (!component) return;
  5040.  
  5041. // this.checkIntegrity();
  5042.  
  5043. const ref = component[wk] || (component[wk] = new WeakRef(component));
  5044.  
  5045. if (this.nodes.has(ref)) this._detach(ref);
  5046.  
  5047. this._ensure(level);
  5048.  
  5049. if (!this.levelTail[level]) {
  5050. // First node on this level
  5051. const idx = this._indexOfLevel(level);
  5052. const prevLvl = idx ? this.nonEmptyLevels[idx - 1] : null;
  5053. const nextLvl = idx < this.nonEmptyLevels.length ? this.nonEmptyLevels[idx] : null;
  5054.  
  5055. const prevRef = prevLvl !== null ? this.levelTail[prevLvl] : null;
  5056. const nextRef = nextLvl !== null ? this.levelHead[nextLvl] : null;
  5057.  
  5058. this._link(ref, prevRef, nextRef, level);
  5059. this.nonEmptyLevels.splice(idx, 0, level);
  5060. } else {
  5061. // Append to existing level
  5062. const prevRef = this.levelTail[level];
  5063. const nextRef = this.nodes.get(prevRef).next;
  5064. this._link(ref, prevRef, nextRef, level);
  5065. }
  5066.  
  5067. this.counter++;
  5068. // this.checkIntegrity();
  5069. }
  5070.  
  5071. remove(component) {
  5072. const ref = component && component.deref ? component : (component || 0)[wk];
  5073.  
  5074. // this.checkIntegrity();
  5075. this._detach(ref);
  5076.  
  5077. // this.checkIntegrity();
  5078. }
  5079.  
  5080. replace(componentOld, componentNew) {
  5081. if (!componentOld || !componentNew) {
  5082. throw new Error('replace failed: missing component');
  5083. }
  5084.  
  5085. if (componentOld === componentNew) {
  5086. return;
  5087. }
  5088.  
  5089. const refOld = componentOld[wk];
  5090. // ensure New has a weak‐ref
  5091. const refNew = componentNew[wk] || (componentNew[wk] = mWeakRef(componentNew));
  5092.  
  5093.  
  5094. if (refOld === refNew) {
  5095. return;
  5096. }
  5097.  
  5098. if (!refOld || !this.nodes.has(refOld)) {
  5099. throw new Error('replace failed: old component not found');
  5100. }
  5101.  
  5102. // this.checkIntegrity();
  5103.  
  5104. // If new is already in the list somewhere, detach it first
  5105. if (this.nodes.has(refNew)) {
  5106. this._detach(refNew);
  5107. }
  5108.  
  5109. // Pull out old pointers
  5110. const { prev, next, level } = this.nodes.get(refOld);
  5111.  
  5112. // Link into the main list
  5113. if (prev) {
  5114. this.nodes.get(prev).next = refNew;
  5115. } else {
  5116. this.head = refNew;
  5117. }
  5118.  
  5119. if (next) {
  5120. this.nodes.get(next).prev = refNew;
  5121. } else {
  5122. this.tail = refNew;
  5123. }
  5124.  
  5125. // Link into the per‐level sentinels
  5126. if (this.levelHead[level] === refOld) {
  5127. this.levelHead[level] = refNew;
  5128. }
  5129. if (this.levelTail[level] === refOld) {
  5130. this.levelTail[level] = refNew;
  5131. }
  5132.  
  5133. // Finally re‐key the Map entry
  5134. this.nodes.set(refNew, { prev, next, level });
  5135. this.nodes.delete(refOld);
  5136.  
  5137. // this.checkIntegrity();
  5138. }
  5139.  
  5140. _walk(ref, dir) {
  5141. if (!ref || !this.nodes.has(ref)) return null;
  5142.  
  5143. let cur = this.nodes.get(ref)[dir];
  5144. while (cur) {
  5145. if (cur.deref()) return cur;
  5146.  
  5147. // Clean up collected node
  5148. const nxt = this.nodes.get(cur)[dir];
  5149. this._detach(cur);
  5150. cur = nxt;
  5151. }
  5152. return null;
  5153. }
  5154.  
  5155. nextComp(component) {
  5156. const ref = component && component.deref ? component : (component || 0)[wk];
  5157. return this._walk(ref, 'next');
  5158. }
  5159.  
  5160. prevComp(component) {
  5161. const ref = component && component.deref ? component : (component || 0)[wk];
  5162. return this._walk(ref, 'prev');
  5163. }
  5164.  
  5165. hasComp(component) {
  5166. const ref = component && component.deref ? component : (component || 0)[wk];
  5167. return !!(ref && this.nodes.has(ref))
  5168. }
  5169.  
  5170. count() {
  5171. return this.counter;
  5172. }
  5173.  
  5174. countLevels() {
  5175. const r = [];
  5176. for (let i = 0; ; i++) {
  5177. if (!this.levelHead[i] || !this.levelTail[i]) break;
  5178. let cur = this.levelHead[i];
  5179. let curs = [];
  5180. while (cur && this.nodes.get(cur).level === i) {
  5181. curs.push((cur));
  5182. cur = taskListP.nextComp(cur);
  5183. }
  5184.  
  5185. if (curs[0] !== this.levelHead[i]) debugger;
  5186. if (curs[curs.length - 1] !== this.levelTail[i]) debugger;
  5187. r.push({
  5188. head: this.levelHead[i],
  5189. tail: this.levelTail[i],
  5190. curs: curs,
  5191. set: new Set(curs),
  5192. arrSize: curs.length,
  5193. setSize: (new Set(curs)).size
  5194.  
  5195. });
  5196. }
  5197. return r;
  5198. }
  5199.  
  5200.  
  5201. // // Integrity checker helper
  5202. // checkIntegrity() {
  5203. // const list = this;
  5204. // // Global head/tail pointers
  5205. // if (list.head !== null) {
  5206. // const headNode = list.nodes.get(list.head);
  5207. // assert(headNode.prev === null, "Integrity: head.prev must be null");
  5208. // }
  5209. // if (list.tail !== null) {
  5210. // const tailNode = list.nodes.get(list.tail);
  5211. // assert(tailNode.next === null, "Integrity: tail.next must be null");
  5212. // }
  5213.  
  5214. // // Per-level head/tail and level consistency
  5215. // list.nonEmptyLevels.forEach(level => {
  5216. // assert(list.levelHead[level] != null, `Integrity: levelHead[${level}] should not be null`);
  5217. // assert(list.levelTail[level] != null, `Integrity: levelTail[${level}] should not be null`);
  5218. // const headRef = list.levelHead[level];
  5219. // const tailRef = list.levelTail[level];
  5220. // const headNode = list.nodes.get(headRef);
  5221. // const tailNode = list.nodes.get(tailRef);
  5222. // assert(headNode.level === level, `Integrity: levelHead[${level}].level mismatch`);
  5223. // assert(tailNode.level === level, `Integrity: levelTail[${level}].level mismatch`);
  5224. // });
  5225.  
  5226. // // nonEmptyLevels sorted ascending
  5227. // for (let i = 1; i < list.nonEmptyLevels.length; i++) {
  5228. // assert(
  5229. // list.nonEmptyLevels[i] > list.nonEmptyLevels[i - 1],
  5230. // "Integrity: nonEmptyLevels must be sorted ascending"
  5231. // );
  5232. // }
  5233.  
  5234. // this.countLevels();
  5235. // }
  5236.  
  5237. }
  5238.  
  5239.  
  5240. const taskListP = new CTaskList();
  5241. const taskList = [];
  5242. let taskCounter = 0;
  5243. window.me55 = ()=>taskListP;
  5244.  
  5245. const taskPush = (component, pTask0, pTask1, deferred = false) => {
  5246. component = kRef(component);
  5247. if (!component) return;
  5248. if (!pTask0) pTask0 = pTask1; else Object.assign(pTask0, pTask1);
  5249. componentBasedTaskPool.set(component, pTask0);
  5250. const id = taskCounter = (taskCounter & 1073741823) + 1;
  5251. pTask0.taskId = id;
  5252. if (!pTask1.byPass) pTask0.byPass = false;
  5253. taskListP.push(component, 0);
  5254. if (!deferred) nonDeferredTask = component[wk];
  5255. // taskList.push({
  5256. // taskId: id,
  5257. // componentWr: component[wk]
  5258. // })
  5259. return pTask0;
  5260. }
  5261.  
  5262. const domComment_ = document.createComment('y');
  5263. const triggerDomChange = (node) => {
  5264. node.appendChild(domComment_).remove();
  5265. }
  5266.  
  5267.  
  5268. const performTask = (component, pTask = undefined) => {
  5269.  
  5270. if (pTask === undefined) pTask = componentBasedTaskPool.get(component);
  5271. if (!pTask || !component) return;
  5272. let { step, producer, containerId, typeOrConfig, data, flushing, selfProducer } = pTask;
  5273. producer = kRef(producer);
  5274. selfProducer = kRef(selfProducer);
  5275.  
  5276. const resolveSelf = () => {
  5277.  
  5278. const node = component;
  5279.  
  5280. const prevCur = taskListP.prevComp(node);
  5281.  
  5282. node.removeAttribute('ytx-flushing');
  5283.  
  5284. // if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement && selfProducer.hostElement.isConnected) {
  5285.  
  5286. if (selfProducer && flushing && flushing.length > 0 && selfProducer.hostElement) {
  5287. const node = component;
  5288.  
  5289. let shouldMarkDirty = false;
  5290.  
  5291. const m = new Set();
  5292.  
  5293. const producer = selfProducer;
  5294.  
  5295. for (const [containerId, bEvent, hasData] of flushing) {
  5296. if (hasData || hasData === null) {
  5297. shouldMarkDirty = true;
  5298. if (bEvent) {
  5299. const container = producer.getStampContainer7409_(containerId);
  5300. // console.log(644221499, container)
  5301. m.add(container);
  5302. }
  5303. }
  5304. }
  5305. flushing.length = 0;
  5306.  
  5307. if (shouldMarkDirty) {
  5308. producer.markDirty && producer.markDirty();
  5309. let q = true;
  5310. for (const container of m) {
  5311. if (!q) producer.markDirty && producer.markDirty();
  5312. q = false;
  5313. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  5314. container
  5315. });
  5316. }
  5317. }
  5318.  
  5319. }
  5320.  
  5321.  
  5322.  
  5323. const s = new Set();
  5324.  
  5325. const parentComponent = node.closest('[ytx-flushing]');
  5326. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  5327. if (!s.has(parentComponent[wk])) {
  5328. s.add(parentComponent[wk]);
  5329. }
  5330. }
  5331.  
  5332. const producerElement = producer ? producer.hostElement : null;
  5333.  
  5334. if (parentComponent && parentComponent !== producerElement) {
  5335.  
  5336. const parentComponent = producerElement;
  5337. if (parentComponent && componentBasedTaskPool.has(parentComponent) && parentComponent[wk] && !parentComponent.querySelector('[ytx-flushing]')) {
  5338. if (!s.has(parentComponent[wk])) {
  5339. s.add(parentComponent[wk])
  5340. }
  5341. }
  5342.  
  5343. }
  5344.  
  5345. for (const p of s) {
  5346. const node = kRef(p);
  5347. triggerDomChange(node);
  5348. }
  5349.  
  5350. if (!node.hasAttribute('ytx-flushing') && (!pTask.flushing || !pTask.flushing.length) && !pTask.typeOrConfig && !pTask.data) {
  5351. componentBasedTaskPool.delete(node);
  5352. taskListP.remove(node);
  5353. }
  5354.  
  5355.  
  5356. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head), parents: [...s]};
  5357.  
  5358. }
  5359.  
  5360. if (pTask.step === 'creation') {
  5361.  
  5362. if (flushing) debugger;
  5363. if (!producer || !typeOrConfig) return;
  5364. if (component.parentNode && component.parentNode.id === containerId && component.parentNode === producer.getStampContainer7409_(containerId)) {
  5365. pTask.step = 'flushStamper'; pTask.pq33 = 3;
  5366.  
  5367. // const aNode = producer.createComponent7409_(typeOrConfig, data, false);
  5368.  
  5369. const prevCur = taskListP.prevComp(component);
  5370.  
  5371. const pTaskId = pTask.taskId;
  5372. const cName = producer.getComponentName_(typeOrConfig, data);
  5373. const aNode = document.createElement(cName);
  5374. const qNode = component;
  5375.  
  5376. aNode.setAttribute('ytx-stamp', 'flusher');
  5377. aNode.setAttribute('ytx-flushing', '2');
  5378. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  5379.  
  5380. taskListP.replace(qNode, aNode);
  5381.  
  5382. componentBasedTaskPool.delete(qNode);
  5383. componentBasedTaskPool.set(aNode, pTask); // pTask will be obtained and proceeded during "dom change" in the same micro task
  5384.  
  5385.  
  5386. const container = component.parentNode;
  5387. const containerApi = container.__domApi || container;
  5388.  
  5389. const frag = document.createDocumentFragment();
  5390. frag.appendChild(aNode);
  5391. containerApi.insertBefore(frag, qNode);
  5392. containerApi.removeChild(qNode);
  5393. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  5394.  
  5395. }
  5396. } else if (pTask.step === 'flushStamper') {
  5397.  
  5398. if (flushing) debugger;
  5399.  
  5400. if (!producer || !typeOrConfig) return;
  5401. pTask.step = 'flushStamperWait';
  5402. pTask.typeOrConfig = null;
  5403. pTask.data = null;
  5404.  
  5405. const prevCur = taskListP.prevComp(component);
  5406.  
  5407. const node = component;
  5408. node.setAttribute('ytx-flushing', '3');
  5409.  
  5410. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  5411. // flushedObserver.observe(node, { subtree: true, childList: true });
  5412. producer.deferredBindingTasks_.push(taskB);
  5413. producer.flushRenderStamperComponentBindings7409_();
  5414. // try{Polymer.flush()}catch(e){}
  5415. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  5416.  
  5417. } else if (pTask.step === 'flushStamperWait') {
  5418.  
  5419. if (flushing) debugger;
  5420. if (!producer) return;
  5421.  
  5422. // producer undetermined
  5423.  
  5424. const node = component;
  5425.  
  5426. if (!node.querySelector('[ytx-flushing]')) {
  5427.  
  5428. pTask.step = 'idleContainer';
  5429.  
  5430. return resolveSelf();
  5431.  
  5432.  
  5433. }
  5434.  
  5435. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish') {
  5436.  
  5437. if (producer && typeOrConfig) {
  5438.  
  5439. pTask.typeOrConfig = null;
  5440. pTask.data = null;
  5441.  
  5442. const prevCur = taskListP.prevComp(component);
  5443.  
  5444. const node = component;
  5445. node.setAttribute('ytx-flushing', '3');
  5446.  
  5447. let taskB = { component: component, typeOrConfig: typeOrConfig, data: data };
  5448. // flushedObserver.observe(node, { subtree: true, childList: true });
  5449. producer.deferredBindingTasks_.push(taskB);
  5450. producer.flushRenderStamperComponentBindings7409_();
  5451. // try{Polymer.flush()}catch(e){}
  5452. return {nextCur: (prevCur ? taskListP.nextComp(prevCur) || taskListP.head: taskListP.head)};
  5453. }
  5454.  
  5455. const node = component;
  5456.  
  5457. if (!node.querySelector('[ytx-flushing]')) {
  5458. pTask.step = 'idleProducer';
  5459. return resolveSelf();
  5460. }
  5461. // const selfProducer = kRef(pTask.selfProducer);
  5462.  
  5463. }
  5464.  
  5465. };
  5466.  
  5467. const performTaskQueued = (component)=>{
  5468. queueMicrotask_(()=>{
  5469. performTask(component);
  5470. });
  5471. };
  5472.  
  5473. let isLooping = false;
  5474. let nonDeferredTask = null;
  5475. let loopTaskQ = 0;
  5476. const loopTask = () => {
  5477. if (isLooping) return ++loopTaskQ;
  5478. isLooping = true;
  5479. loopTaskQ = 0;
  5480. let t0 = 0;
  5481. let cur = taskListP.head;
  5482. let nextCur = cur;
  5483. const taskExec = () => {
  5484.  
  5485. if (!t0) {
  5486. t0 = nativeNow();
  5487. }
  5488.  
  5489. if (nonDeferredTask && nextCur && taskListP.nodes.has(nextCur) && taskListP.nodes.get(nextCur).level === 1) {
  5490. nextCur = nonDeferredTask
  5491. }
  5492.  
  5493. nonDeferredTask = null;
  5494.  
  5495. for (;cur = nextCur; ) {
  5496.  
  5497. nextCur = taskListP.nextComp(cur);
  5498. const nextCur0 = nextCur;
  5499.  
  5500. const taskComponent = kRef(cur);
  5501. if (taskComponent) {
  5502. if(taskComponent === window.me849) debugger;
  5503. const pTask = componentBasedTaskPool.get(taskComponent);
  5504. if (pTask) {
  5505. if (pTask.taskId > 0 && !pTask.byPass) {
  5506. if (pTask.taskId === window.me848) debugger;
  5507.  
  5508. let shouldPerformTask = false;
  5509. if (pTask.step === 'creation' && pTask.typeOrConfig) {
  5510. shouldPerformTask = true;
  5511. } else if (pTask.step === 'flushStamper' && pTask.typeOrConfig) {
  5512. shouldPerformTask = true;
  5513. } else if (pTask.step === 'flushStamperWait' && !taskComponent.querySelector('[ytx-flushing]')) {
  5514. shouldPerformTask = true;
  5515. } else if (pTask.step === 'mightFlushAndWaitContainersRenderFinish' && (pTask.typeOrConfig || !taskComponent.querySelector('[ytx-flushing]'))) {
  5516. shouldPerformTask = true;
  5517. }
  5518.  
  5519. let b = shouldPerformTask && taskComponent.parentNode;
  5520. if (b) {
  5521.  
  5522. const result = performTask(taskComponent, pTask);
  5523. let kbb = false;
  5524. if(typeof result ==='object' && result.nextCur === nextCur0){
  5525.  
  5526. } else if(taskListP.nextComp(cur) === null && taskListP.nextComp(cur) !== nextCur0) {
  5527. kbb = true;
  5528. }
  5529. if (typeof result === 'object' && result.parents instanceof Array) {
  5530.  
  5531. const nextCur_ = result.nextCur;
  5532. nextCur = nextCur_;
  5533. const parents = result.parents;
  5534. if (parents.length >= 1) {
  5535. const eSet = new Set(parents); // weak refs
  5536. eSet.add(nextCur_)
  5537. for (let cur_ = taskListP.head; cur_; cur_ = taskListP.nextComp(cur_)) {
  5538. if (eSet.has(cur_)) {
  5539. nextCur = cur_;
  5540. break;
  5541. }
  5542. }
  5543. }
  5544.  
  5545.  
  5546. } else if(typeof result === 'object' && result.nextCur){
  5547. nextCur = result.nextCur;
  5548. }
  5549.  
  5550.  
  5551. if (nativeNow() - t0 > 10) {
  5552. t0 = 0;
  5553. nextBrowserTick_(taskExec);
  5554. } else {
  5555. queueMicrotask_(taskExec);
  5556. }
  5557.  
  5558. return;
  5559.  
  5560. }
  5561.  
  5562. }
  5563.  
  5564. }
  5565.  
  5566. }
  5567.  
  5568. }
  5569.  
  5570. isLooping = false;
  5571.  
  5572. if(loopTaskQ > 0) nextBrowserTick_(loopTask);
  5573.  
  5574. };
  5575.  
  5576. queueMicrotask_(taskExec);
  5577.  
  5578. };
  5579.  
  5580.  
  5581. let q244 = new PromiseExternal();
  5582. let q248a = [];
  5583. let q248b = [];
  5584. let q248c = [];
  5585. const deferRenderStamperBinding_ = function (component, typeOrConfig, data) {
  5586.  
  5587. if(this.__byPass828__) {
  5588.  
  5589. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  5590. }
  5591.  
  5592. const isLastCreate = this.___lastCreate3311__ === data; // false for native element. true for RP or native element
  5593.  
  5594. this.___lastCreate3311__ = -0.125;
  5595.  
  5596.  
  5597. const containerId = this.__activeContainerId929__;
  5598. if (!component[wk]) component[wk] = mWeakRef(component);
  5599. if (!this[wk]) this[wk] = mWeakRef(this);
  5600.  
  5601. const pTask = componentBasedTaskPool.get(component);
  5602.  
  5603. const isSelfProducer = (pTask && pTask.selfProducer && pTask.flushing);
  5604.  
  5605.  
  5606. const abandonUnreadySubtree = () => {
  5607. for (const e of component.querySelectorAll('[ytx-flushing]')) {
  5608. const pTask = componentBasedTaskPool.get(e);
  5609. if (pTask) {
  5610. pTask.step = 'abandon';
  5611. pTask.taskId = 0;
  5612. if (pTask.flushing) pTask.flushing.length = 0;
  5613. pTask.flushing = null;
  5614.  
  5615. pTask.typeOrConfig = null
  5616. pTask.data = null
  5617.  
  5618. componentBasedTaskPool.delete(e);
  5619. taskListP.remove(e);
  5620. }
  5621. e.removeAttribute('ytx-flushing');
  5622. if (e.nodeName === 'RP') e.remove();
  5623. }
  5624. }
  5625.  
  5626. const flushNowTask = (componentWr, pTaskId, flag) => {
  5627. const component = kRef(componentWr);
  5628. if (!component) return;
  5629. const pTaskNew = componentBasedTaskPool.get(component);
  5630. if (!pTaskNew) return;
  5631. if (pTaskId !== pTaskNew.taskId) return;
  5632. pTaskNew.byPass = false;
  5633. if (flag & 1) {
  5634. performTaskQueued(component);
  5635. performTaskQueued(component);
  5636. performTaskQueued(component);
  5637. } else {
  5638. performTask(component);
  5639. performTask(component);
  5640. performTask(component);
  5641. }
  5642. return true;
  5643. }
  5644.  
  5645. const flushNow = (component) => {
  5646.  
  5647.  
  5648.  
  5649. const cName = this.getComponentName_(typeOrConfig, data);
  5650. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  5651. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  5652.  
  5653. if(mDeferred) {
  5654. component.setAttribute('ytx-defer-stamp','');
  5655. this.hostElement.setAttribute('ytx-defer-stamp','');
  5656. }
  5657.  
  5658. const pTaskNew = taskPush(component, pTask, {
  5659. step: isSelfProducer ? 'mightFlushAndWaitContainersRenderFinish' : 'flushStamper',
  5660. producer: this[wk],
  5661. containerId: containerId,
  5662. typeOrConfig: typeOrConfig,
  5663. data: data,
  5664. byPass: true,
  5665. pq33: 7
  5666. }, mDeferred ? 1 : 0);
  5667.  
  5668. const pTaskId = pTaskNew.taskId;
  5669.  
  5670. const componentWr = component[wk];
  5671.  
  5672.  
  5673. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2w');
  5674.  
  5675. if (mDeferred ) {
  5676.  
  5677. q248a.push([componentWr, pTaskId]);
  5678.  
  5679. setTimeout(() => {
  5680. const q248 = q248a;
  5681.  
  5682. if (!q248.length) return;
  5683. let q246 = q248.slice();
  5684. q248.length = 0;
  5685.  
  5686. let doLoop = false;
  5687. for (const [componentWr, pTaskId] of q246) {
  5688. // if(!)
  5689. // console.log(2188, kRef(componentWr).parentNode)
  5690. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  5691. }
  5692. q246.length = 0;
  5693. q246 = null;
  5694. if (doLoop) loopTask();
  5695.  
  5696. }, 0);
  5697.  
  5698.  
  5699. } else {
  5700.  
  5701. if(!component.parentNode){
  5702.  
  5703. q248b.push([componentWr, pTaskId]);
  5704.  
  5705. (() => {
  5706.  
  5707. const q248 = q248b;
  5708.  
  5709. if (!q248.length) return;
  5710. let q246 = q248.slice();
  5711. q248.length = 0;
  5712. let doLoop = false;
  5713. for (const [componentWr, pTaskId] of q246) {
  5714. if (flushNowTask(componentWr, pTaskId, 0) === true) doLoop = true;
  5715. }
  5716. q246.length = 0;
  5717. q246 = null;
  5718. if (doLoop) loopTask();
  5719. })();
  5720.  
  5721. } else {
  5722.  
  5723.  
  5724. q248c.push([componentWr, pTaskId]);
  5725.  
  5726. nextBrowserTick_(() => {
  5727. const q248 = q248c;
  5728.  
  5729. if (!q248.length) return;
  5730. let q246 = q248.slice();
  5731. q248.length = 0;
  5732.  
  5733. let doLoop = false;
  5734. for (const [componentWr, pTaskId] of q246) {
  5735. if (flushNowTask(componentWr, pTaskId, 1) === true) doLoop = true;
  5736. }
  5737. q246.length = 0;
  5738. q246 = null;
  5739. if (doLoop) loopTask();
  5740.  
  5741. });
  5742.  
  5743. }
  5744.  
  5745. }
  5746.  
  5747.  
  5748.  
  5749. loopTask();
  5750.  
  5751. };
  5752.  
  5753. if (!isLastCreate) {
  5754.  
  5755. abandonUnreadySubtree();
  5756.  
  5757. flushNow(component);
  5758. return;
  5759.  
  5760. } else {
  5761. if (pTask) pTask.taskId = 0;
  5762. }
  5763.  
  5764. if (this.__byPass828__ || !this.__byPass348__) {
  5765. return this.deferRenderStamperBinding7409_(component, typeOrConfig, data);
  5766. }
  5767.  
  5768. if (pTask && pTask.step !== 'creation') {
  5769.  
  5770. if(!component.hasAttribute('ytx-flushing')) component.setAttribute('ytx-flushing', '2c');
  5771.  
  5772. abandonUnreadySubtree();
  5773.  
  5774. flushNow(component);
  5775.  
  5776. return;
  5777.  
  5778. } else {
  5779.  
  5780. if (component.nodeName === "RP") {
  5781.  
  5782. component.setAttribute('ytx-stamp', 'flusher');
  5783.  
  5784. component.setAttribute('ytx-flushing', '1');
  5785.  
  5786. const cName = this.getComponentName_(typeOrConfig, data);
  5787. const mDeferred = cName === 'ytd-playlist-panel-video-renderer' || this.is === 'ytd-playlist-panel-video-renderer';
  5788. // const mDeferred = typeof cName === 'string' && cName.length >= 17 && (cName === 'ytd-playlist-panel-video-renderer' || cName === 'ytd-menu-renderer' || cName.startsWith('ytd-thumbnail-overlay-'));
  5789.  
  5790. if(mDeferred) {
  5791. component.setAttribute('ytx-defer-stamp','');
  5792. this.hostElement.setAttribute('ytx-defer-stamp','');
  5793. }
  5794.  
  5795. taskPush(component, pTask, {
  5796. step: 'creation',
  5797. producer: this[wk],
  5798. containerId: containerId,
  5799. typeOrConfig: typeOrConfig,
  5800. data: data
  5801. }, mDeferred ? 1 : 0);
  5802. loopTask();
  5803.  
  5804. } else {
  5805.  
  5806.  
  5807. const aNode = component;
  5808. if (!aNode[wk]) aNode[wk] = mWeakRef(aNode);
  5809.  
  5810. aNode.setAttribute('ytx-stamp', 'flusher');
  5811. aNode.setAttribute('ytx-flushing', '2');
  5812.  
  5813. flushNow(component);
  5814.  
  5815. }
  5816.  
  5817. }
  5818.  
  5819.  
  5820. }
  5821. flushRenderStamperComponentBindings_ = function () {
  5822.  
  5823. if (!this.__byPass348__) {
  5824. return this.flushRenderStamperComponentBindings7409_();
  5825. }
  5826. if (this.__byPass828__) {
  5827. const wr = this[wk] || (this[wk] = mWeakRef(this));
  5828. queueMicrotask_(() => {
  5829. const producer = kRef(wr);
  5830. if (!producer) return;
  5831. producer.flushRenderStamperComponentBindings7409_();
  5832. });
  5833. throw new Error('5ii48');
  5834. }
  5835. throw new Error('5ii48')
  5836. }
  5837.  
  5838.  
  5839. const directComponentList = new Set([
  5840. // for YouTube Tabview Totara
  5841. "YTD-STRUCTURED-DESCRIPTION-CONTENT-RENDERER",
  5842. "YTD-VIDEO-DESCRIPTION-HEADER-RENDERER",
  5843. "YTD-ENGAGEMENT-PANEL-SECTION-LIST-RENDERER",
  5844. ]);
  5845.  
  5846.  
  5847. let kf33;
  5848. let kf3b = 0;
  5849.  
  5850. const sb88 = Symbol();
  5851.  
  5852. const onStampDone = (producer) =>{
  5853.  
  5854.  
  5855. const flushing_ = producer[sb88];
  5856.  
  5857. const flushing = flushing_.slice();
  5858. flushing_.length = 0;
  5859.  
  5860. if (flushing && flushing.length > 0) {
  5861.  
  5862. let shouldMarkDirty = false;
  5863.  
  5864. const m = new Set();
  5865.  
  5866. for (const [containerId, bEvent, hasData] of flushing) {
  5867. if (hasData || hasData === null) {
  5868. shouldMarkDirty = true;
  5869. if (bEvent) {
  5870. const container = producer.getStampContainer7409_(containerId);
  5871. // console.log(644221499, container)
  5872. m.add(container);
  5873. }
  5874. }
  5875. }
  5876. flushing.length = 0;
  5877.  
  5878. if (shouldMarkDirty) {
  5879. producer.markDirty && producer.markDirty();
  5880. let q = true;
  5881. for (const container of m) {
  5882. if (!q) producer.markDirty && producer.markDirty();
  5883. q = false;
  5884. dispatchYtEvent(producer.hostElement, "yt-rendererstamper-finished", {
  5885. container
  5886. });
  5887. }
  5888. }
  5889.  
  5890. }
  5891.  
  5892.  
  5893. }
  5894.  
  5895. stampDomArraySplices_ = function (stampKey, containerId, indexSplicesObj) {
  5896. // this.__byPass828__ = true;
  5897.  
  5898. // return this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  5899.  
  5900. const producer = this;
  5901. const hostElement = producer.hostElement;
  5902.  
  5903. let kf = false;
  5904. const kf3t = nativeNow();
  5905. const kf34 = Math.floor((kf3t - kf3b) / 8);
  5906.  
  5907. if (!kf33 || kf34 !== kf33) {
  5908. kf33 = kf34;
  5909. kf3b = kf3t - kf34 * 8;
  5910. kf = true;
  5911. }
  5912.  
  5913. const container = this.getStampContainer7409_(containerId);
  5914. if (container && !container.__rk75401__) {
  5915. container.__rk75401__ = true;
  5916. childrenObs.observe(container, { subtree: false, childList: true });
  5917. }
  5918.  
  5919. if (kf) this.__directProduction533__ = true;
  5920. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  5921. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  5922. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  5923. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  5924. else this.__directProduction533__ = false;
  5925.  
  5926. this.__directProduction533__ = true;
  5927.  
  5928. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  5929.  
  5930. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  5931.  
  5932. const bEventCb = this.stampDom[stampKey].events;
  5933.  
  5934. this.__activeContainerId929__ = containerId;
  5935.  
  5936. if (!this[wk]) this[wk] = mWeakRef(this);
  5937. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  5938. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  5939. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  5940. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  5941. hostElement.setAttribute('ytx-stamp', 'producer');
  5942. }
  5943.  
  5944.  
  5945. if (this.__byPass828__) {
  5946.  
  5947. const flushing = this[sb88] || (this[sb88] = []);
  5948. flushing.push([containerId, bEventCb, null]);
  5949. let r, e_
  5950. try {
  5951. this.__byPass348__ = true;
  5952. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  5953. } catch (e) {
  5954. e_ = e;
  5955. }
  5956. this.__byPass348__ = false;
  5957.  
  5958. nextBrowserTick_(() => {
  5959. onStampDone(this);
  5960. });
  5961.  
  5962. if (e_ && e_.message !== '5ii48') throw e_;
  5963. return;
  5964.  
  5965. }
  5966.  
  5967.  
  5968. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  5969.  
  5970. const flushing = pTask ? (pTask.flushing || []) : [];
  5971. flushing.push([containerId, bEventCb, null]);
  5972. hostElement.setAttribute('ytx-flushing', 's-1');
  5973.  
  5974. if (pTask) {
  5975. // pTask.taskId = -1;
  5976. pTask.byPass = true;
  5977. }
  5978. if (hostElement && !hostElement.__rk75401__) {
  5979. hostElement.__rk75401__ = true;
  5980. childrenObs.observe(hostElement, { subtree: false, childList: true });
  5981. }
  5982.  
  5983. let r, e_
  5984. try {
  5985. this.__byPass348__ = true;
  5986. this.stampDomArraySplices7409_(stampKey, containerId, indexSplicesObj);
  5987. } catch (e) {
  5988. e_ = e;
  5989. }
  5990. this.__byPass348__ = false;
  5991.  
  5992. taskPush(hostElement, pTask, {
  5993. step: 'mightFlushAndWaitContainersRenderFinish',
  5994. selfProducer: this[wk],
  5995. flushing
  5996. });
  5997. loopTask();
  5998.  
  5999. triggerDomChange(container);
  6000. triggerDomChange(hostElement);
  6001.  
  6002. if (e_ && e_.message !== '5ii48') throw e_;
  6003.  
  6004. };
  6005.  
  6006. stampDomArray_ = function (dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList) {
  6007. // this.__byPass828__ = true;
  6008.  
  6009.  
  6010.  
  6011. // return this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  6012.  
  6013. const producer = this;
  6014. const hostElement = producer.hostElement;
  6015.  
  6016. let kf = false;
  6017. const kf3t = nativeNow();
  6018. const kf34 = Math.floor((kf3t - kf3b) / 8);
  6019.  
  6020. if (!kf33 || kf34 !== kf33) {
  6021. kf33 = kf34;
  6022. kf3b = kf3t - kf34 * 8;
  6023. kf = true;
  6024. }
  6025.  
  6026. const container = this.getStampContainer7409_(containerId);
  6027. if (container && !container.__rk75401__) {
  6028. container.__rk75401__ = true;
  6029. childrenObs.observe(container, { subtree: false, childList: true });
  6030. }
  6031.  
  6032. if (kf) this.__directProduction533__ = true;
  6033. else if (!this.isAttached) this.__directProduction533__ = true; // tbc
  6034. else if (this.onYtRendererstamperFinished && this.updateChildVisibilityProperties) this.__directProduction533__ = true;
  6035. else if (hostElement && directComponentList.has(hostElement.nodeName)) this.__directProduction533__ = true;
  6036. else if (hostElement && hostElement.closest('ytd-engagement-panel-section-list-renderer, [hidden], defs, noscript')) this.__directProduction533__ = true;
  6037. else this.__directProduction533__ = false;
  6038.  
  6039. bReuse = false;
  6040.  
  6041. this.__directProduction533__ = true;
  6042.  
  6043. // if (container.is === 'yt-img-shadow') this.__byPass828__ = true;
  6044. // if(this.hostElement.closest('ytd-comments')) this.__byPass828__ = true;
  6045.  
  6046. this.__activeContainerId929__ = containerId;
  6047.  
  6048. if (!this[wk]) this[wk] = mWeakRef(this);
  6049. if (!hostElement[wk]) hostElement[wk] = mWeakRef(hostElement);
  6050. if (hostElement.getAttribute('ytx-stamp') === 'flusher') {
  6051. hostElement.setAttribute('ytx-stamp', 'flusher|producer');
  6052. } else if (!hostElement.hasAttribute('ytx-stamp')) {
  6053. hostElement.setAttribute('ytx-stamp', 'producer');
  6054. }
  6055.  
  6056.  
  6057. if (this.__byPass828__) {
  6058.  
  6059. const flushing = this[sb88] || (this[sb88] = []);
  6060. flushing.push([containerId, bEventCb, !!dataList]);
  6061. let r, e_
  6062. try {
  6063. this.__byPass348__ = true;
  6064. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  6065. } catch (e) {
  6066. e_ = e;
  6067. }
  6068. this.__byPass348__ = false;
  6069.  
  6070. nextBrowserTick_(() => {
  6071. onStampDone(this);
  6072. });
  6073.  
  6074. if (e_ && e_.message !== '5ii48') throw e_;
  6075. return;
  6076.  
  6077. }
  6078.  
  6079.  
  6080. const pTask = componentBasedTaskPool.get(hostElement); // can be flushStamperWait -> mightFlushAndWaitContainersRenderFinish
  6081.  
  6082. const flushing = pTask ? (pTask.flushing || []) : [];
  6083. flushing.push([containerId, bEventCb, !!dataList]);
  6084. hostElement.setAttribute('ytx-flushing', 's-1');
  6085.  
  6086. if (pTask) {
  6087. pTask.byPass = true;
  6088. // pTask.taskId = -1;
  6089. }
  6090.  
  6091. if (hostElement && !hostElement.__rk75401__) {
  6092. hostElement.__rk75401__ = true;
  6093. childrenObs.observe(hostElement, { subtree: false, childList: true });
  6094. }
  6095.  
  6096. let r, e_
  6097. try {
  6098. this.__byPass348__ = true;
  6099. this.stampDomArray7409_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  6100. } catch (e) {
  6101. e_ = e;
  6102. }
  6103. this.__byPass348__ = false;
  6104.  
  6105. taskPush(hostElement, pTask, {
  6106. step: 'mightFlushAndWaitContainersRenderFinish',
  6107. selfProducer: this[wk],
  6108. flushing
  6109. });
  6110. loopTask();
  6111.  
  6112. triggerDomChange(container);
  6113. triggerDomChange(hostElement);
  6114.  
  6115. if (e_ && e_.message !== '5ii48') throw e_;
  6116.  
  6117. };
  6118.  
  6119. const stampDomArrayWB_ = function (objWr, containerId, xxx_) {
  6120.  
  6121. const obj = kRef(objWr);
  6122. if (!obj) return;
  6123. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`];
  6124. if (xxx !== xxx_) return;
  6125. const dataList = obj[`__stampDomArrayArgs_dataList__#${containerId}__`];
  6126. const typeOrConfig = kRef(obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`]);
  6127. const bReuse = obj[`__stampDomArrayArgs_bReuse__#${containerId}__`];
  6128. const bEventCb = obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`];
  6129. const bStableList = obj[`__stampDomArrayArgs_bStableList__#${containerId}__`];
  6130. // console.log(12388002, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  6131. return obj.stampDomArray_(dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList);
  6132. };
  6133.  
  6134.  
  6135. stampDomArray_.bind = function (obj, ...args) {
  6136. let [dataList, containerId, typeOrConfig, bReuse, bEventCb, bStableList] = args;
  6137. // console.log(12388001, containerId, dataList, typeOrConfig, bReuse, bEventCb, bStableList)
  6138. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  6139. obj[`__stampDomArrayArgs_dataList__#${containerId}__`] = dataList;
  6140. if (!typeOrConfig[wk]) typeOrConfig[wk] = mWeakRef(typeOrConfig);
  6141. obj[`__stampDomArrayArgs_typeOrConfig__#${containerId}__`] = typeOrConfig[wk];
  6142. obj[`__stampDomArrayArgs_bReuse__#${containerId}__`] = bReuse;
  6143. obj[`__stampDomArrayArgs_bEventCb__#${containerId}__`] = bEventCb;
  6144. obj[`__stampDomArrayArgs_bStableList__#${containerId}__`] = bStableList;
  6145.  
  6146. // if (!obj[`__stampDomArrayBoundFn__#${containerId}__`]) obj[`__stampDomArrayBoundFn__#${containerId}__`] = stampDomArrayWB_.bind(null, obj[wk], containerId);
  6147. const xxx = obj[`__stampDomArrayArgs_xxx__#${containerId}__`] = `${Math.random()}_${Date.now()}`;
  6148. // const p = obj[wk];
  6149. // queueMicrotask_(()=>{
  6150. // const obj = kRef(p);
  6151. // if(!obj) return;
  6152. // if(!obj.hostElement) return;
  6153. // triggerDomChange(obj.hostElement);
  6154. // const container = obj.getStampContainer7409_(containerId);
  6155. // if(container instanceof Node) triggerDomChange(container);
  6156. // });
  6157. // return obj[`__stampDomArrayBoundFn__#${containerId}__`];
  6158.  
  6159. return stampDomArrayWB_.bind(null, obj[wk], containerId, xxx);
  6160. };
  6161.  
  6162. return { getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_ };
  6163.  
  6164. }
  6165.  
  6166. const setupDiscreteTasks = (h, rb) => {
  6167.  
  6168. if (typeof h.onYtRendererstamperFinished === 'function' && !(h.onYtRendererstamperFinished.km34)) {
  6169. const f = h.onYtRendererstamperFinished;
  6170. const g = ump3.get(f) || function () {
  6171. if (this.updateChildVisibilityProperties && !this.markDirty) {
  6172. return f.apply(this, arguments);
  6173. }
  6174. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6175. }
  6176. ump3.set(f, g);
  6177. g.km34 = 1;
  6178. h.onYtRendererstamperFinished = g;
  6179.  
  6180. }
  6181.  
  6182. if (typeof h.onYtUpdateDescriptionAction === 'function' && !(h.onYtUpdateDescriptionAction.km34)) {
  6183. const f = h.onYtUpdateDescriptionAction;
  6184. const g = ump3.get(f) || function (a) {
  6185. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6186. }
  6187. ump3.set(f, g);
  6188. g.km34 = 1;
  6189. h.onYtUpdateDescriptionAction = g;
  6190.  
  6191. }
  6192.  
  6193. if (typeof h.handleUpdateDescriptionAction === 'function' && !(h.handleUpdateDescriptionAction.km34)) {
  6194. const f = h.handleUpdateDescriptionAction;
  6195. const g = ump3.get(f) || function (a) {
  6196. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6197. }
  6198. ump3.set(f, g);
  6199. g.km34 = 1;
  6200. h.handleUpdateDescriptionAction = g;
  6201.  
  6202. }
  6203.  
  6204. if (typeof h.handleUpdateLiveChatPollAction === 'function' && !(h.handleUpdateLiveChatPollAction.km34)) {
  6205. const f = h.handleUpdateLiveChatPollAction;
  6206. const g = ump3.get(f) || function (a) {
  6207. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6208. }
  6209. ump3.set(f, g);
  6210. g.km34 = 1;
  6211. h.handleUpdateLiveChatPollAction = g;
  6212.  
  6213. }
  6214.  
  6215. if (typeof h.onTextChanged === 'function' && !(h.onTextChanged.km34)) {
  6216. const f = h.onTextChanged;
  6217. const g = ump3.get(f) || function () {
  6218. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6219. }
  6220. ump3.set(f, g);
  6221. g.km34 = 1;
  6222. h.onTextChanged = g;
  6223.  
  6224. }
  6225.  
  6226. if (typeof h.onVideoDataChange === 'function' && !(h.onVideoDataChange.km34)) {
  6227. const f = h.onVideoDataChange;
  6228. const g = ump3.get(f) || function (a) {
  6229. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6230. }
  6231. ump3.set(f, g);
  6232. g.km34 = 1;
  6233. h.onVideoDataChange = g;
  6234.  
  6235. }
  6236.  
  6237. if (typeof h.onVideoDataChange_ === 'function' && !(h.onVideoDataChange_.km34)) {
  6238. const f = h.onVideoDataChange_;
  6239. const g = ump3.get(f) || function () {
  6240. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6241. }
  6242. ump3.set(f, g);
  6243. g.km34 = 1;
  6244. h.onVideoDataChange_ = g;
  6245.  
  6246. }
  6247.  
  6248. if (typeof h.addTooltips_ === 'function' && !(h.addTooltips_.km34)) {
  6249.  
  6250. const f = h.addTooltips_;
  6251. const g = ump3.get(f) || function () {
  6252. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6253. }
  6254. ump3.set(f, g);
  6255. g.km34 = 1;
  6256. h.addTooltips_ = g;
  6257.  
  6258. }
  6259.  
  6260. if (typeof h.updateRenderedElements === 'function' && !(h.updateRenderedElements.km34)) {
  6261.  
  6262. const f = h.updateRenderedElements;
  6263. const g = ump3.get(f) || function () {
  6264. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6265. }
  6266. ump3.set(f, g);
  6267. g.km34 = 1;
  6268. h.updateRenderedElements = g;
  6269.  
  6270. }
  6271.  
  6272. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.loadPage_ === 'function' && !(h.loadPage_.km34)) {
  6273. const f = h.loadPage_;
  6274. const g = ump3.get(f) || function (a) {
  6275. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6276. }
  6277. ump3.set(f, g);
  6278. g.km34 = 1;
  6279. h.loadPage_ = g;
  6280.  
  6281. }
  6282. // updatePageData_ : possible conflict with Omit ShadyDOM
  6283. if ((WEAK_REF_BINDING_CONTROL & 2) && typeof h.updatePageData_ === 'function' && !(h.updatePageData_.km34)) {
  6284. const f = h.updatePageData_;
  6285. const g = ump3.get(f) || function (a) {
  6286. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6287. }
  6288. ump3.set(f, g);
  6289. g.km34 = 1;
  6290. h.updatePageData_ = g;
  6291.  
  6292. }
  6293.  
  6294.  
  6295. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onFocus_ === 'function' && !(h.onFocus_.km34)) {
  6296.  
  6297. const f = h.onFocus_;
  6298. const g = ump3.get(f) || function () {
  6299. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6300. }
  6301. ump3.set(f, g);
  6302. g.km34 = 1;
  6303. h.onFocus_ = g;
  6304.  
  6305. }
  6306.  
  6307. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onBlur_ === 'function' && !(h.onBlur_.km34)) {
  6308.  
  6309. const f = h.onBlur_;
  6310. const g = ump3.get(f) || function () {
  6311. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6312. }
  6313. ump3.set(f, g);
  6314. g.km34 = 1;
  6315. h.onBlur_ = g;
  6316.  
  6317. }
  6318.  
  6319.  
  6320. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonClassChanged_ === 'function' && !(h.buttonClassChanged_.km34)) {
  6321.  
  6322. const f = h.buttonClassChanged_;
  6323. const g = ump3.get(f) || function (a, b) {
  6324. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6325. }
  6326. ump3.set(f, g);
  6327. g.km34 = 1;
  6328. h.buttonClassChanged_ = g;
  6329.  
  6330. }
  6331.  
  6332. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.buttonIconChanged_ === 'function' && !(h.buttonIconChanged_.km34)) {
  6333.  
  6334. const f = h.buttonIconChanged_;
  6335. const g = ump3.get(f) || function (a) {
  6336. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6337. }
  6338. ump3.set(f, g);
  6339. g.km34 = 1;
  6340. h.buttonIconChanged_ = g;
  6341.  
  6342. }
  6343.  
  6344. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.dataChangedInBehavior_ === 'function' && !(h.dataChangedInBehavior_.km34)) {
  6345.  
  6346. const f = h.dataChangedInBehavior_;
  6347. const g = ump3.get(f) || function () {
  6348. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6349. }
  6350. ump3.set(f, g);
  6351. g.km34 = 1;
  6352. h.dataChangedInBehavior_ = g;
  6353.  
  6354. }
  6355.  
  6356. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.continuationsChanged_ === 'function' && !(h.continuationsChanged_.km34)) {
  6357.  
  6358. const f = h.continuationsChanged_;
  6359. const g = ump3.get(f) || function () {
  6360. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6361. }
  6362. ump3.set(f, g);
  6363. g.km34 = 1;
  6364. h.continuationsChanged_ = g;
  6365.  
  6366. }
  6367.  
  6368.  
  6369. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.forceChatPoll_ === 'function' && !(h.forceChatPoll_.km34)) {
  6370.  
  6371. const f = h.forceChatPoll_;
  6372. const g = ump3.get(f) || function (a) {
  6373. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6374. }
  6375. ump3.set(f, g);
  6376. g.km34 = 1;
  6377. h.forceChatPoll_ = g;
  6378.  
  6379. }
  6380.  
  6381. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointClick_ === 'function' && !(h.onEndpointClick_.km34)) {
  6382.  
  6383. const f = h.onEndpointClick_;
  6384. const g = ump3.get(f) || function (a) {
  6385. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6386. }
  6387. ump3.set(f, g);
  6388. g.km34 = 1;
  6389. h.onEndpointClick_ = g;
  6390.  
  6391. }
  6392.  
  6393. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onEndpointTap_ === 'function' && !(h.onEndpointTap_.km34)) {
  6394.  
  6395. const f = h.onEndpointTap_;
  6396. const g = ump3.get(f) || function (a) {
  6397. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6398. }
  6399. ump3.set(f, g);
  6400. g.km34 = 1;
  6401. h.onEndpointTap_ = g;
  6402.  
  6403. }
  6404.  
  6405. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleClick_ === 'function' && !(h.handleClick_.km34)) {
  6406.  
  6407. const f = h.handleClick_;
  6408. const g = ump3.get(f) || function (a, b) {
  6409. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6410. }
  6411. ump3.set(f, g);
  6412. g.km34 = 1;
  6413. h.handleClick_ = g;
  6414.  
  6415. }
  6416.  
  6417. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChange_ === 'function' && !(h.onReadyStateChange_.km34)) {
  6418.  
  6419. const f = h.onReadyStateChange_;
  6420. const g = ump3.get(f) || function () {
  6421. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6422. }
  6423. ump3.set(f, g);
  6424. g.km34 = 1;
  6425. h.onReadyStateChange_ = g;
  6426.  
  6427. }
  6428.  
  6429. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onReadyStateChangeEntryPoint_ === 'function' && !(h.onReadyStateChangeEntryPoint_.km34)) {
  6430.  
  6431. const f = h.onReadyStateChangeEntryPoint_;
  6432. const g = ump3.get(f) || function () {
  6433. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6434. }
  6435. ump3.set(f, g);
  6436. g.km34 = 1;
  6437. h.onReadyStateChangeEntryPoint_ = g;
  6438.  
  6439. }
  6440.  
  6441. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.readyStateChangeHandler_ === 'function' && !(h.readyStateChangeHandler_.km34)) {
  6442.  
  6443. const f = h.readyStateChangeHandler_;
  6444. const g = ump3.get(f) || function (a) {
  6445. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6446. }
  6447. ump3.set(f, g);
  6448. g.km34 = 1;
  6449. h.readyStateChangeHandler_ = g;
  6450.  
  6451. }
  6452.  
  6453. if (typeof h.xmlHttpHandler_ === 'function' && !(h.xmlHttpHandler_.km34)) {
  6454.  
  6455. const f = h.xmlHttpHandler_;
  6456. const g = ump3.get(f) || function (a) {
  6457. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6458. }
  6459. ump3.set(f, g);
  6460. g.km34 = 1;
  6461. h.xmlHttpHandler_ = g;
  6462.  
  6463. }
  6464.  
  6465. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.executeCallbacks_ === 'function' && !(h.executeCallbacks_.km34)) {
  6466.  
  6467. const f = h.executeCallbacks_; // overloaded
  6468. const g = ump3.get(f) || function (a) {
  6469. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6470. }
  6471. ump3.set(f, g);
  6472. g.km34 = 1;
  6473. h.executeCallbacks_ = g;
  6474.  
  6475. }
  6476.  
  6477. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.handleInvalidationData_ === 'function' && !(h.handleInvalidationData_.km34)) {
  6478.  
  6479. const f = h.handleInvalidationData_;
  6480. const g = ump3.get(f) || function (a, b) {
  6481. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6482. }
  6483. ump3.set(f, g);
  6484. g.km34 = 1;
  6485. h.handleInvalidationData_ = g;
  6486.  
  6487. }
  6488.  
  6489. if (typeof h.onInput_ === 'function' && !(h.onInput_.km34)) {
  6490.  
  6491. const f = h.onInput_;
  6492. const g = ump3.get(f) || function () {
  6493. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6494. }
  6495. ump3.set(f, g);
  6496. g.km34 = 1;
  6497. h.onInput_ = g;
  6498.  
  6499. }
  6500. if (typeof h.trigger_ === 'function' && !(h.trigger_.km34)) {
  6501.  
  6502. const f = h.trigger_;
  6503. const g = ump3.get(f) || function (a) {
  6504. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6505. }
  6506. ump3.set(f, g);
  6507. g.km34 = 1;
  6508. h.trigger_ = g;
  6509.  
  6510. }
  6511.  
  6512. if (typeof h.requestData_ === 'function' && !(h.requestData_.km34)) {
  6513.  
  6514. const f = h.requestData_;
  6515. const g = ump3.get(f) || function (a) {
  6516. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6517. }
  6518. ump3.set(f, g);
  6519. g.km34 = 1;
  6520. h.requestData_ = g;
  6521.  
  6522. }
  6523.  
  6524. if (typeof h.onLoadReloadContinuation_ === 'function' && !(h.onLoadReloadContinuation_.km34)) {
  6525.  
  6526. const f = h.onLoadReloadContinuation_;
  6527. const g = ump3.get(f) || function (a, b) {
  6528. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6529. }
  6530. ump3.set(f, g);
  6531. g.km34 = 1;
  6532. h.onLoadReloadContinuation_ = g;
  6533.  
  6534. }
  6535.  
  6536. if (typeof h.onLoadIncrementalContinuation_ === 'function' && !(h.onLoadIncrementalContinuation_.km34)) {
  6537.  
  6538. const f = h.onLoadIncrementalContinuation_;
  6539. const g = ump3.get(f) || function (a, b) {
  6540. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6541. }
  6542. ump3.set(f, g);
  6543. g.km34 = 1;
  6544. h.onLoadIncrementalContinuation_ = g;
  6545.  
  6546. }
  6547.  
  6548. if (typeof h.onLoadSeekContinuation_ === 'function' && !(h.onLoadSeekContinuation_.km34)) {
  6549.  
  6550. const f = h.onLoadSeekContinuation_;
  6551. const g = ump3.get(f) || function (a, b) {
  6552. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6553. }
  6554. ump3.set(f, g);
  6555. g.km34 = 1;
  6556. h.onLoadSeekContinuation_ = g;
  6557.  
  6558. }
  6559. if (typeof h.onLoadReplayContinuation_ === 'function' && !(h.onLoadReplayContinuation_.km34)) {
  6560.  
  6561. const f = h.onLoadReplayContinuation_;
  6562. const g = ump3.get(f) || function (a, b) {
  6563. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6564. }
  6565. ump3.set(f, g);
  6566. g.km34 = 1;
  6567. h.onLoadReplayContinuation_ = g;
  6568.  
  6569. }
  6570. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.onNavigate_ === 'function' && !(h.onNavigate_.km34)) {
  6571.  
  6572. const f = h.onNavigate_;
  6573. const g = ump3.get(f) || function (a) {
  6574. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6575. }
  6576. ump3.set(f, g);
  6577. g.km34 = 1;
  6578. h.onNavigate_ = g;
  6579.  
  6580. }
  6581.  
  6582. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorDataObserver_ === 'function' && !(h.ytRendererBehaviorDataObserver_.km34)) {
  6583.  
  6584. const f = h.ytRendererBehaviorDataObserver_;
  6585. const g = ump3.get(f) || function () {
  6586. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6587. }
  6588. ump3.set(f, g);
  6589. g.km34 = 1;
  6590. h.ytRendererBehaviorDataObserver_ = g;
  6591.  
  6592. }
  6593.  
  6594. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.ytRendererBehaviorTargetIdObserver_ === 'function' && !(h.ytRendererBehaviorTargetIdObserver_.km34)) {
  6595.  
  6596. const f = h.ytRendererBehaviorTargetIdObserver_;
  6597. const g = ump3.get(f) || function () {
  6598. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6599. }
  6600. ump3.set(f, g);
  6601. g.km34 = 1;
  6602. h.ytRendererBehaviorTargetIdObserver_ = g;
  6603.  
  6604. }
  6605.  
  6606. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.unregisterRenderer_ === 'function' && !(h.unregisterRenderer_.km34)) {
  6607.  
  6608. const f = h.unregisterRenderer_;
  6609. const g = ump3.get(f) || function (a) {
  6610. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6611. }
  6612. ump3.set(f, g);
  6613. g.km34 = 1;
  6614. h.unregisterRenderer_ = g;
  6615.  
  6616. }
  6617.  
  6618. if ((WEAK_REF_BINDING_CONTROL & 1) && typeof h.textChanged_ === 'function' && !(h.textChanged_.km34)) {
  6619.  
  6620. const f = h.textChanged_;
  6621. const g = ump3.get(f) || function (a) {
  6622. if (void 0 !== this.isAttached) {
  6623. const hostElement = this.hostElement;
  6624. if (!(hostElement instanceof Node) || hostElement.nodeName === 'NOSCRIPT') {
  6625. return;
  6626. }
  6627. }
  6628. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6629. }
  6630. ump3.set(f, g);
  6631. g.km34 = 1;
  6632. h.textChanged_ = g;
  6633.  
  6634. }
  6635.  
  6636.  
  6637.  
  6638. /**
  6639. *
  6640. * Neglect following
  6641. *
  6642. * h.onYtAction_
  6643. * h.startLoadingWatch [ buggy for yt-player-updated ]
  6644. * h.deferRenderStamperBinding_
  6645. *
  6646. * h.stampDomArray_
  6647. * h.stampDomArraySplices_
  6648. *
  6649. */
  6650.  
  6651.  
  6652. // RP.prototype.searchChanged_ = RP.prototype.searchChanged_;
  6653. // RP.prototype.skinToneChanged_ = RP.prototype.skinToneChanged_;
  6654. // RP.prototype.onEmojiHover_ = RP.prototype.onEmojiHover_;
  6655. // RP.prototype.onSelectCategory_ = RP.prototype.onSelectCategory_;
  6656. // RP.prototype.onShowEmojiVariantSelector = RP.prototype.onShowEmojiVariantSelector;
  6657. // RP.prototype.updateCategoriesAndPlaceholder_ = RP.prototype.updateCategoriesAndPlaceholder_;
  6658.  
  6659. if (typeof h.searchChanged_ === 'function' && !(h.searchChanged_.km34)) {
  6660.  
  6661. const f = h.searchChanged_;
  6662. const g = ump3.get(f) || function () {
  6663. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6664. }
  6665. ump3.set(f, g);
  6666. g.km34 = 1;
  6667. h.searchChanged_ = g;
  6668.  
  6669. }
  6670.  
  6671. if (typeof h.skinToneChanged_ === 'function' && !(h.skinToneChanged_.km34)) {
  6672.  
  6673. const f = h.skinToneChanged_;
  6674. const g = ump3.get(f) || function (a) {
  6675. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6676. }
  6677. ump3.set(f, g);
  6678. g.km34 = 1;
  6679. h.skinToneChanged_ = g;
  6680.  
  6681. }
  6682.  
  6683. if (typeof h.onEmojiHover_ === 'function' && !(h.onEmojiHover_.km34)) {
  6684.  
  6685. const f = h.onEmojiHover_;
  6686. const g = ump3.get(f) || function (a) {
  6687. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6688. }
  6689. ump3.set(f, g);
  6690. g.km34 = 1;
  6691. h.onEmojiHover_ = g;
  6692.  
  6693. }
  6694.  
  6695. if (typeof h.onSelectCategory_ === 'function' && !(h.onSelectCategory_.km34)) {
  6696.  
  6697. const f = h.onSelectCategory_;
  6698. const g = ump3.get(f) || function (a) {
  6699. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6700. }
  6701. ump3.set(f, g);
  6702. g.km34 = 1;
  6703. h.onSelectCategory_ = g;
  6704.  
  6705. }
  6706.  
  6707. if (typeof h.onShowEmojiVariantSelector === 'function' && !(h.onShowEmojiVariantSelector.km34)) {
  6708.  
  6709. const f = h.onShowEmojiVariantSelector;
  6710. const g = ump3.get(f) || function (a) {
  6711. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6712. }
  6713. ump3.set(f, g);
  6714. g.km34 = 1;
  6715. h.onShowEmojiVariantSelector = g;
  6716.  
  6717. }
  6718.  
  6719. if (typeof h.updateCategoriesAndPlaceholder_ === 'function' && !(h.updateCategoriesAndPlaceholder_.km34)) {
  6720.  
  6721. const f = h.updateCategoriesAndPlaceholder_;
  6722. const g = ump3.get(f) || function () {
  6723. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6724. }
  6725. ump3.set(f, g);
  6726. g.km34 = 1;
  6727. h.updateCategoriesAndPlaceholder_ = g;
  6728.  
  6729. }
  6730.  
  6731. if (typeof h.watchPageActiveChanged_ === 'function' && !(h.watchPageActiveChanged_.km34)) {
  6732.  
  6733. const f = h.watchPageActiveChanged_;
  6734. const g = ump3.get(f) || function () {
  6735. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6736. }
  6737. ump3.set(f, g);
  6738. g.km34 = 1;
  6739. h.watchPageActiveChanged_ = g;
  6740.  
  6741. }
  6742.  
  6743. if (typeof h.activate_ === 'function' && !(h.activate_.km34)) {
  6744.  
  6745. const f = h.activate_;
  6746. const g = ump3.get(f) || function () {
  6747. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6748. }
  6749. ump3.set(f, g);
  6750. g.km34 = 1;
  6751. h.activate_ = g;
  6752.  
  6753. }
  6754. if (typeof h.onYtPlaylistDataUpdated_ === 'function' && !(h.onYtPlaylistDataUpdated_.km34)) {
  6755.  
  6756. const f = h.onYtPlaylistDataUpdated_;
  6757. const g = ump3.get(f) || function () {
  6758. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6759. }
  6760. ump3.set(f, g);
  6761. g.km34 = 1;
  6762. h.onYtPlaylistDataUpdated_ = g;
  6763.  
  6764. }
  6765.  
  6766.  
  6767.  
  6768. /**
  6769. *
  6770. * Neglect following
  6771. *
  6772. * h.rendererStamperObserver_
  6773. * h.rendererStamperApplyChangeRecord_
  6774. * h.flushRenderStamperComponentBindings_
  6775. * h.forwardRendererStamperChanges_
  6776. *
  6777. */
  6778.  
  6779. if (typeof h.tryRenderChunk_ === 'function' && !(h.tryRenderChunk_.km34)) {
  6780.  
  6781. const f = h.tryRenderChunk_;
  6782. const g = ump3.get(f) || function () {
  6783. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6784. }
  6785. ump3.set(f, g);
  6786. g.km34 = 1;
  6787. h.tryRenderChunk_ = g;
  6788.  
  6789. }
  6790.  
  6791.  
  6792. if (typeof h.renderChunk_ === 'function' && !(h.renderChunk_.km34)) {
  6793.  
  6794. const f = h.renderChunk_;
  6795. const g = ump3.get(f) || function () {
  6796. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6797. }
  6798. ump3.set(f, g);
  6799. g.km34 = 1;
  6800. h.renderChunk_ = g;
  6801.  
  6802. }
  6803.  
  6804. if (typeof h.deepLazyListObserver_ === 'function' && !(h.deepLazyListObserver_.km34)) {
  6805.  
  6806. const f = h.deepLazyListObserver_;
  6807. const g = ump3.get(f) || function () {
  6808. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6809. }
  6810. ump3.set(f, g);
  6811. g.km34 = 1;
  6812. h.deepLazyListObserver_ = g;
  6813.  
  6814. }
  6815.  
  6816. if (typeof h.onItemsUpdated_ === 'function' && !(h.onItemsUpdated_.km34)) {
  6817.  
  6818. const f = h.onItemsUpdated_;
  6819. const g = ump3.get(f) || function () {
  6820. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6821. }
  6822. ump3.set(f, g);
  6823. g.km34 = 1;
  6824. h.onItemsUpdated_ = g;
  6825.  
  6826. }
  6827.  
  6828. if (typeof h.requestRenderChunk_ === 'function' && !(h.requestRenderChunk_.km34)) {
  6829.  
  6830. const f = h.requestRenderChunk_;
  6831. const g = ump3.get(f) || function () {
  6832. Promise.resolve().then(() => f.apply(this, arguments)).catch(console.log);
  6833. }
  6834. ump3.set(f, g);
  6835. g.km34 = 1;
  6836. h.requestRenderChunk_ = g;
  6837.  
  6838. }
  6839.  
  6840. /**
  6841. *
  6842. * Neglect following
  6843. *
  6844. * h.dataChanged_ [ buggy for page swtiching ]
  6845. *
  6846. * h.updateChangeRecord_ [ see https://github.com/cyfung1031/userscript-supports/issues/20 ]
  6847. *
  6848. * h.cancelPendingTasks_
  6849. * h.fillRange_
  6850. * h.addTextNodes_
  6851. * h.updateText_
  6852. * h.stampTypeChanged_
  6853. *
  6854. */
  6855.  
  6856.  
  6857. }
  6858.  
  6859. const keyStConnectedCallback = Symbol(); // avoid copying the value
  6860.  
  6861. const dmf = new WeakMap();
  6862.  
  6863.  
  6864. let nativeHTMLElement = Reflect.getPrototypeOf(HTMLFontElement);
  6865.  
  6866. try {
  6867.  
  6868. const q = document.createElement('template');
  6869. q.innerHTML = '<ytz-null361></ytz-null361>';
  6870. nativeHTMLElement = q.content.firstChild.constructor
  6871.  
  6872. } catch (e) { }
  6873.  
  6874. if (!nativeHTMLElement.prototype.connectedCallback) {
  6875. nativeHTMLElement.prototype.connectedCallback79 = nativeHTMLElement.prototype.connectedCallback;
  6876. nativeHTMLElement.prototype.connectedCallback = function () {
  6877. let r;
  6878. if (this.connectedCallback79) r = this.connectedCallback79.apply(this, arguments);
  6879. return r;
  6880. }
  6881. }
  6882. const pvr = Symbol()
  6883.  
  6884. let stampDomArrayFnStore = null;
  6885. const setupMap = new WeakSet();
  6886. const setupYtComponent = (cnt) => {
  6887. const cProto = Reflect.getPrototypeOf(cnt || 0) || 0;
  6888. if (!cProto || setupMap.has(cProto)) return;
  6889. setupMap.add(cProto);
  6890. if (FIX_stampDomArray && !(cProto[pvr] & 1) && 'stampDomArray_' in cProto) {
  6891. cProto[pvr] |= 1;
  6892.  
  6893.  
  6894.  
  6895. if (FIX_stampDomArray && !location.pathname.startsWith('/live_chat') && cProto.stampDomArray_) {
  6896. const b = cProto.stampDomArray_.length === 6
  6897. && cProto.getStampContainer_ && cProto.getStampContainer_.length === 1
  6898. && cProto.createComponent_ && cProto.createComponent_.length === 3
  6899. && cProto.deferRenderStamperBinding_ && cProto.deferRenderStamperBinding_.length === 3
  6900. && cProto.flushRenderStamperComponentBindings_ && cProto.flushRenderStamperComponentBindings_.length === 0
  6901. && cProto.deferRenderStamperBinding_ === cnt.deferRenderStamperBinding_
  6902. if (!b) {
  6903. console.warn("YouTube Coding Changed. createStampDomFns_() is not applied")
  6904. } else if(!cProto.createComponent7409_ && !cProto.deferRenderStamperBinding7409_ && !cProto.flushRenderStamperComponentBindings7409_) {
  6905. if(!stampDomArrayFnStore) stampDomArrayFnStore = createStampDomFnsB_();
  6906. const {getStampContainer_, createComponent_, deferRenderStamperBinding_, flushRenderStamperComponentBindings_, stampDomArray_, stampDomArraySplices_} = stampDomArrayFnStore;
  6907.  
  6908. cProto.getStampContainer7409_ = cProto.getStampContainer_;
  6909. cProto.createComponent7409_ = cProto.createComponent_;
  6910. cProto.deferRenderStamperBinding7409_ = cProto.deferRenderStamperBinding_;
  6911. cProto.flushRenderStamperComponentBindings7409_ = cProto.flushRenderStamperComponentBindings_;
  6912. cProto.stampDomArray7409_ = cProto.stampDomArray_;
  6913. cProto.stampDomArraySplices7409_ = cProto.stampDomArraySplices_;
  6914.  
  6915. cProto.getStampContainer_ = getStampContainer_;
  6916. cProto.createComponent_ = createComponent_;
  6917. cProto.deferRenderStamperBinding_ = deferRenderStamperBinding_;
  6918. cProto.flushRenderStamperComponentBindings_ = flushRenderStamperComponentBindings_;
  6919. cProto.stampDomArray_ = stampDomArray_;
  6920. cProto.stampDomArraySplices_ = stampDomArraySplices_;
  6921.  
  6922. }
  6923. }
  6924.  
  6925.  
  6926.  
  6927.  
  6928. if(cProto._runEffectsForTemplate && !cProto._runEffectsForTemplate6344) {
  6929. cProto._runEffectsForTemplate6344 = cProto._runEffectsForTemplate;
  6930.  
  6931. if(cProto._runEffectsForTemplate6344.length === 4){
  6932.  
  6933. cProto._runEffectsForTemplate = function (c, d, e, g) {
  6934. const cnt = this;
  6935. const { propertyEffects, nodeList, firstChild } = c;
  6936. cnt._runEffectsForTemplate6344({ propertyEffects, nodeList, firstChild }, d, e, g);
  6937.  
  6938. }
  6939.  
  6940. }
  6941.  
  6942. }
  6943.  
  6944. }
  6945. if (ENABLE_discreteTasking && !(cProto[pvr] & 2) && (typeof (cProto.is || 0) === 'string' || ('attached' in cProto) || ('isAttached' in cProto))) {
  6946. cProto[pvr] |= 2;
  6947. setupDiscreteTasks(cProto);
  6948. }
  6949. };
  6950.  
  6951. (ENABLE_discreteTasking || FIX_stampDomArray) && Object.defineProperty(Object.prototype, 'connectedCallback', {
  6952. get() {
  6953. const f = this[keyStConnectedCallback];
  6954. if (this.is) {
  6955. setupYtComponent(this);
  6956. }
  6957. return f;
  6958. },
  6959. set(nv) {
  6960. let gv = nv;
  6961. this[keyStConnectedCallback] = gv; // proto or object
  6962. return true;
  6963. },
  6964. enumerable: false,
  6965. configurable: true
  6966.  
  6967. });
  6968.  
  6969. const pLoad = new Promise(resolve => {
  6970. if (document.readyState !== 'loading') {
  6971. resolve();
  6972. } else {
  6973. window.addEventListener("DOMContentLoaded", resolve, false);
  6974. }
  6975. });
  6976.  
  6977. if (FIX_fix_requestIdleCallback_timing && !window.requestIdleCallback471 && typeof window.requestIdleCallback === 'function') {
  6978. window.requestIdleCallback471 = window.requestIdleCallback;
  6979. window.requestIdleCallback = function (f, ...args) {
  6980. return (this || window).requestIdleCallback471(async function () {
  6981. await pLoad.then();
  6982. // await new Promise(nextBrowserTick_);
  6983. f.call(this, ...arguments)
  6984. }, ...args);
  6985. }
  6986. }
  6987.  
  6988. pLoad.then(() => {
  6989.  
  6990. let nonce = document.querySelector('style[nonce]');
  6991. nonce = nonce ? nonce.getAttribute('nonce') : null;
  6992. const st = document.createElement('style');
  6993. if (typeof nonce === 'string') st.setAttribute('nonce', nonce);
  6994. st.textContent = "none-element-k47{order:0}";
  6995. st.addEventListener('load', () => {
  6996. pf31.resolve();
  6997. p59 = 1;
  6998. }, false);
  6999. (document.body || document.head || document.documentElement).appendChild(st);
  7000.  
  7001. });
  7002.  
  7003. const prepareLogs = [];
  7004.  
  7005. const skipAdsDetection = new Set(['/robots.txt', '/live_chat', '/live_chat_replay']);
  7006.  
  7007. let winError00 = window.onerror;
  7008.  
  7009. let fix_error_many_stack_state = !FIX_error_many_stack ? 0 : skipAdsDetection.has(location.pathname) ? 2 : 1;
  7010.  
  7011. if (!JSON || !('parse' in JSON)) fix_error_many_stack_state = 0;
  7012.  
  7013. ; FIX_Iframe_NULL_SRC && !isChatRoomURL && typeof kagi === 'undefined' && (() => {
  7014.  
  7015. const emptyBlobUrl = URL.createObjectURL(new Blob([], { type: 'text/html' }));
  7016. const lcOpt = { sensitivity: 'base' };
  7017. document.createElement24 = document.createElement;
  7018. document.createElement = function (t) {
  7019. if (typeof t === 'string' && t.length === 6) {
  7020. if (t.localeCompare('iframe', undefined, lcOpt) === 0) {
  7021. const p = this.createElement24(t);
  7022. try {
  7023. const stack = new Error().stack;
  7024. const isSearchbox = stack.includes('initializeSearchbox'); // see https://greatest.deepsurf.us/scripts/473972-youtube-js-engine-tamer/discussions/217084
  7025. if (!isSearchbox) {
  7026. p.src = emptyBlobUrl; // avoid iframe is appended to DOM without any url
  7027. }
  7028. } catch (e) { }
  7029. return p;
  7030. }
  7031. }
  7032. return this.createElement24.apply(this, arguments);
  7033. };
  7034.  
  7035. })();
  7036.  
  7037. ; fix_error_many_stack_state === 1 && (() => {
  7038.  
  7039.  
  7040. let p1 = winError00;
  7041.  
  7042. let stackNeedleDetails = null;
  7043.  
  7044. Object.defineProperty(Object.prototype, 'matchAll', {
  7045. get() {
  7046. stackNeedleDetails = this;
  7047. return true;
  7048. },
  7049. enumerable: true,
  7050. configurable: true
  7051. });
  7052.  
  7053. try {
  7054. JSON.parse("{}");
  7055. } catch (e) {
  7056. console.warn(e)
  7057. fix_error_many_stack_state = 0;
  7058. }
  7059.  
  7060. delete Object.prototype['matchAll'];
  7061.  
  7062. let p2 = window.onerror;
  7063.  
  7064. window.onerror = p1;
  7065.  
  7066. if (fix_error_many_stack_state === 0) return;
  7067.  
  7068. if (stackNeedleDetails) {
  7069. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7070. stackNeedleDetails.matchAll = true;
  7071. }
  7072.  
  7073. if (p1 === p2) return (fix_error_many_stack_state = 0);
  7074.  
  7075. // p1!==p2
  7076. fix_error_many_stack_state = !stackNeedleDetails ? 4 : 3;
  7077.  
  7078. })();
  7079.  
  7080. ; fix_error_many_stack_state === 2 && (() => {
  7081.  
  7082.  
  7083. let p1 = winError00;
  7084.  
  7085. let objectPrune = null;
  7086. let stackNeedleDetails = null;
  7087.  
  7088. Object.defineProperty(Function.prototype, 'findOwner', {
  7089. get() {
  7090. objectPrune = this;
  7091. return this._findOwner;
  7092. },
  7093. set(nv) {
  7094. this._findOwner = nv;
  7095. return true;
  7096. },
  7097. enumerable: true,
  7098. configurable: true
  7099. });
  7100.  
  7101. Object.defineProperty(Object.prototype, 'matchAll', {
  7102. get() {
  7103. stackNeedleDetails = this;
  7104. return true;
  7105. },
  7106. enumerable: true,
  7107. configurable: true
  7108. });
  7109.  
  7110. try {
  7111. JSON.parse("{}");
  7112. } catch (e) {
  7113. console.warn(e)
  7114. fix_error_many_stack_state = 0;
  7115. }
  7116.  
  7117. delete Function.prototype['findOwner'];
  7118. delete Object.prototype['matchAll'];
  7119.  
  7120. let p2 = window.onerror;
  7121.  
  7122. if (p1 !== p2) return (fix_error_many_stack_state = 4); // p1 != p2
  7123.  
  7124. if (fix_error_many_stack_state == 0) return;
  7125.  
  7126. // the following will only execute when Brave's scriptlets.js is executed.
  7127.  
  7128. prepareLogs.push("fix_error_many_stack_state NB")
  7129.  
  7130. if (stackNeedleDetails) {
  7131. stackNeedleDetails.pattern = null;
  7132. stackNeedleDetails.re = null;
  7133. stackNeedleDetails.expect = null;
  7134. stackNeedleDetails.matchAll = true;
  7135. }
  7136.  
  7137. if (objectPrune) {
  7138. objectPrune.findOwner = objectPrune.mustProcess = objectPrune.logJson = () => { }
  7139. delete objectPrune._findOwner;
  7140. }
  7141.  
  7142. fix_error_many_stack_state = 3;
  7143. JSON.parse.stackNeedleDetails = stackNeedleDetails;
  7144. JSON.parse.objectPrune = objectPrune;
  7145.  
  7146. })();
  7147.  
  7148. ; fix_error_many_stack_state === 3 && (() => {
  7149.  
  7150.  
  7151. let p1 = winError00;
  7152.  
  7153. try {
  7154. JSON.parse("{}");
  7155. } catch (e) {
  7156. console.warn(e)
  7157. fix_error_many_stack_state = 0;
  7158. }
  7159.  
  7160. let p2 = window.onerror;
  7161.  
  7162. if (p1 === p2) return;
  7163.  
  7164. window.onerror = p1;
  7165.  
  7166. if (fix_error_many_stack_state === 0) return;
  7167.  
  7168. fix_error_many_stack_state = 4; // p1 != p2
  7169.  
  7170.  
  7171. })();
  7172.  
  7173. fix_error_many_stack_state === 4 && (() => {
  7174.  
  7175. // the following will only execute when Brave's scriptlets.js is executed.
  7176.  
  7177. prepareLogs.push("fix_error_many_stack_state AB")
  7178.  
  7179. JSON.parseProxy = JSON.parse;
  7180.  
  7181. JSON.parse = ((parse) => {
  7182.  
  7183. parse = parse.bind(JSON); // get a new instance of the current JSON.parse
  7184. return function (text, reviver) {
  7185. const onerror = window.onerror;
  7186. window.onerror = null;
  7187. let r;
  7188. try {
  7189. r = parse(...arguments);
  7190. } catch (e) {
  7191. r = e;
  7192. }
  7193. window.onerror = onerror;
  7194. if (r instanceof Error) {
  7195. throw r;
  7196. }
  7197. return r;
  7198. }
  7199.  
  7200. })(JSON.parse);
  7201.  
  7202.  
  7203. })();
  7204.  
  7205.  
  7206. // << if FIX_yt_player >>
  7207.  
  7208. // credit to @nopeless (https://greatest.deepsurf.us/scripts/471489-youtube-player-perf/)
  7209. const PERF_471489_ = true;
  7210. // PERF_471489_ is not exactly the same to Youtube Player perf v0.7
  7211. // This script uses a much gentle way to tamer the JS engine instead.
  7212.  
  7213. // << end >>
  7214.  
  7215. const steppingScaleN = 200; // transform: scaleX(k/N); 0<k<N
  7216.  
  7217.  
  7218.  
  7219. const nilFn = () => { };
  7220.  
  7221. let isMainWindow = false;
  7222. try {
  7223. isMainWindow = window.document === window.top.document
  7224. } catch (e) { }
  7225.  
  7226. let NO_PRELOAD_GENERATE_204_BYPASS = NO_PRELOAD_GENERATE_204 ? false : true;
  7227. let headLinkCollection = null;
  7228.  
  7229.  
  7230. // const assertor = (f) => f() || console.assert(false, `${f}`);
  7231.  
  7232. const fnIntegrity = (f, d) => {
  7233. if (!f || typeof f !== 'function') {
  7234. console.warn('f is not a function', f);
  7235. return;
  7236. }
  7237. let p = `${f}`, s = 0, j = -1, w = 0;
  7238. for (let i = 0, l = p.length; i < l; i++) {
  7239. const t = p[i];
  7240. if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
  7241. if (j < i - 1) w++;
  7242. j = i;
  7243. } else {
  7244. s++;
  7245. }
  7246. }
  7247. let itz = `${f.length}.${s}.${w}`;
  7248. if (!d) {
  7249. return itz;
  7250. } else {
  7251. return itz === d;
  7252. }
  7253. };
  7254.  
  7255. const getZqOu = (_yt_player) => {
  7256.  
  7257. const w = 'ZqOu';
  7258.  
  7259. let arr = [];
  7260.  
  7261. for (const [k, v] of Object.entries(_yt_player)) {
  7262.  
  7263. const p = typeof v === 'function' ? v.prototype : 0;
  7264. if (p
  7265. && typeof p.start === 'function' && p.start.length === 0 // Ou
  7266. && typeof p.isActive === 'function' && p.isActive.length === 0
  7267. && typeof p.stop === 'function' && p.stop.length === 0
  7268. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7269. && !p.send && !p.abort
  7270. && !p.sample && !p.initialize && !p.fail && !p.getName
  7271. // && !p.dispose && !p.isDisposed
  7272.  
  7273. ) {
  7274. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7275.  
  7276.  
  7277. }
  7278.  
  7279. }
  7280.  
  7281. if (arr.length === 0) {
  7282.  
  7283. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7284. } else {
  7285.  
  7286. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7287. return arr[0];
  7288. }
  7289.  
  7290. }
  7291.  
  7292. const getZqQu = (_yt_player) => {
  7293.  
  7294. const w = 'ZqQu';
  7295.  
  7296. let arr = [];
  7297.  
  7298.  
  7299. for (const [k, v] of Object.entries(_yt_player)) {
  7300.  
  7301. const p = typeof v === 'function' ? v.prototype : 0;
  7302. if (p
  7303. && typeof p.start === 'function' && p.start.length === 1 // Qu
  7304. && typeof p.isActive === 'function' && p.isActive.length === 0
  7305. && typeof p.stop === 'function' && p.stop.length === 0
  7306. && !p.isComplete && !p.getStatus && !p.getResponseHeader && !p.getLastError
  7307. && !p.send && !p.abort
  7308. && !p.sample && !p.initialize && !p.fail && !p.getName
  7309. // && !p.dispose && !p.isDisposed
  7310.  
  7311. ) {
  7312. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7313.  
  7314.  
  7315. }
  7316.  
  7317. }
  7318.  
  7319. if (arr.length === 0) {
  7320.  
  7321. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7322. } else {
  7323.  
  7324. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7325. return arr[0];
  7326. }
  7327.  
  7328. }
  7329.  
  7330.  
  7331. const getVG = (_yt_player) => {
  7332. const w = 'VG';
  7333.  
  7334. let arr = [];
  7335.  
  7336. for (const [k, v] of Object.entries(_yt_player)) {
  7337.  
  7338. const p = typeof v === 'function' ? v.prototype : 0;
  7339. if (p
  7340. && typeof p.show === 'function' && p.show.length === 1
  7341. && typeof p.hide === 'function' && p.hide.length === 0
  7342. && typeof p.stop === 'function' && p.stop.length === 0) {
  7343.  
  7344. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7345.  
  7346. }
  7347.  
  7348. }
  7349.  
  7350.  
  7351. if (arr.length === 0) {
  7352.  
  7353. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7354. } else {
  7355.  
  7356. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7357. return arr[0];
  7358. }
  7359.  
  7360.  
  7361.  
  7362. }
  7363.  
  7364.  
  7365. const getzo = (_yt_player) => {
  7366. const w = 'zo';
  7367.  
  7368. let arr = [];
  7369.  
  7370. for (const [k, v] of Object.entries(_yt_player)) {
  7371.  
  7372. if (
  7373. typeof v === 'function' && v.length === 3 && k.length < 3
  7374. ) {
  7375. const vt = `${v}`;
  7376. if (vt.length >= 21 && vt.includes(".style[")) {
  7377. if (/\((\w{1,3}),(\w{1,3}),(\w{1,3})\)\{[\s\S]*\1\.style\[\2\]=\3\W/.test(vt)) {
  7378. arr.push(k);
  7379. } else {
  7380. console.warn('[yt-js-engine-tamer] unexpected zo::vt', vt);
  7381. }
  7382. }
  7383. }
  7384.  
  7385. }
  7386.  
  7387. if (arr.length === 0) {
  7388.  
  7389. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7390. } else {
  7391.  
  7392. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7393. return arr[0];
  7394. }
  7395.  
  7396. }
  7397.  
  7398. const addProtoToArr = (parent, key, arr) => {
  7399.  
  7400.  
  7401. let isChildProto = false;
  7402. for (const sr of arr) {
  7403. if (parent[key].prototype instanceof parent[sr]) {
  7404. isChildProto = true;
  7405. break;
  7406. }
  7407. }
  7408.  
  7409. if (isChildProto) return;
  7410.  
  7411. arr = arr.filter(sr => {
  7412. if (parent[sr].prototype instanceof parent[key]) {
  7413. return false;
  7414. }
  7415. return true;
  7416. });
  7417.  
  7418. arr.push(key);
  7419.  
  7420. return arr;
  7421.  
  7422.  
  7423. }
  7424.  
  7425. const getuG = (_yt_player) => {
  7426.  
  7427. const w = 'uG';
  7428.  
  7429. let arr = [];
  7430.  
  7431. for (const [k, v] of Object.entries(_yt_player)) {
  7432.  
  7433.  
  7434. const p = typeof v === 'function' ? v.prototype : 0;
  7435.  
  7436. if (p
  7437. && typeof p.createElement === 'function' && p.createElement.length === 2
  7438. && typeof p.detach === 'function' && p.detach.length === 0
  7439. && typeof p.update === 'function' && p.update.length === 1
  7440. && typeof p.updateValue === 'function' && p.updateValue.length === 2
  7441. ) {
  7442.  
  7443. arr = addProtoToArr(_yt_player, k, arr) || arr;
  7444.  
  7445. }
  7446.  
  7447. }
  7448.  
  7449.  
  7450.  
  7451.  
  7452.  
  7453. if (arr.length === 0) {
  7454.  
  7455. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7456. } else {
  7457.  
  7458. console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7459. return arr[0];
  7460. }
  7461.  
  7462. }
  7463.  
  7464.  
  7465. const getQT = (_yt_player) => {
  7466. const w = 'QT';
  7467.  
  7468. let arr = [];
  7469. let brr = new Map();
  7470.  
  7471. for (const [k, v] of Object.entries(_yt_player)) {
  7472.  
  7473. const p = typeof v === 'function' ? v.prototype : 0;
  7474. if (p) {
  7475. let q = 0;
  7476. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7477. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7478. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7479.  
  7480. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7481.  
  7482. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7483.  
  7484. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7485. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7486. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7487. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7488.  
  7489.  
  7490. // differentiate QT and DX
  7491.  
  7492. q += 280;
  7493. if (typeof p.cueVideoByPlayerVars === 'function') q += 4;
  7494. if (typeof p.loadVideoByPlayerVars === 'function') q += 4;
  7495. if (typeof p.preloadVideoByPlayerVars === 'function') q += 4;
  7496. if (typeof p.seekBy === 'function') q += 4;
  7497. if (typeof p.seekTo === 'function') q += 4;
  7498. if (typeof p.getStoryboardFormat === 'function') q += 4;
  7499. if (typeof p.getDuration === 'function') q += 4;
  7500. if (typeof p.loadModule === 'function') q += 4;
  7501. if (typeof p.unloadModule === 'function') q += 4;
  7502. if (typeof p.getOption === 'function') q += 4;
  7503. if (typeof p.getOptions === 'function') q += 4;
  7504. if (typeof p.setOption === 'function') q += 4;
  7505. if (typeof p.addCueRange === 'function') q += 4;
  7506. if (typeof p.getDebugText === 'function') q += 4;
  7507. if (typeof p.getCurrentBroadcastId === 'function') q += 4;
  7508. if (typeof p.setSizeStyle === 'function') q += 4;
  7509. if (typeof p.showControls === 'function') q += 4;
  7510. if (typeof p.hideControls === 'function') q += 4;
  7511. if (typeof p.getVideoContentRect === 'function') q += 4;
  7512. if (typeof p.toggleFullscreen === 'function') q += 4;
  7513. if (typeof p.isFullscreen === 'function') q += 4;
  7514. if (typeof p.cancelPlayback === 'function') q += 4;
  7515. if (typeof p.getProgressState === 'function') q += 4;
  7516. if (typeof p.isInline === 'function') q += 4;
  7517. if (typeof p.setInline === 'function') q += 4;
  7518. if (typeof p.toggleSubtitles === 'function') q += 4;
  7519. if (typeof p.getPlayerSize === 'function') q += 4;
  7520. if (typeof p.wakeUpControls === 'function') q += 4;
  7521. if (typeof p.setCenterCrop === 'function') q += 4;
  7522. if (typeof p.getLoopVideo === 'function') q += 4;
  7523. if (typeof p.setLoopVideo === 'function') q += 4;
  7524.  
  7525.  
  7526. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7527.  
  7528. if (q > 0) brr.set(k, q);
  7529.  
  7530. }
  7531.  
  7532. }
  7533.  
  7534. if (arr.length === 0) {
  7535.  
  7536. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7537. } else {
  7538.  
  7539. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7540.  
  7541. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7542.  
  7543. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7544. return arr[0][0];
  7545. }
  7546.  
  7547.  
  7548.  
  7549. }
  7550.  
  7551.  
  7552.  
  7553. const getSV = (_yt_player) => {
  7554. const w = 'SV';
  7555.  
  7556. let arr = [];
  7557. let brr = new Map();
  7558.  
  7559. for (const [k, v] of Object.entries(_yt_player)) {
  7560.  
  7561. const p = typeof v === 'function' ? v.prototype : 0;
  7562. if (p) {
  7563. let q = 0;
  7564. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7565. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7566. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7567.  
  7568. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q += 600; // SV
  7569.  
  7570. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7571.  
  7572. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7573. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7574. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7575. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7576.  
  7577.  
  7578. // differentiate QT and DX
  7579.  
  7580.  
  7581. q += 280;
  7582.  
  7583. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7584. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7585. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7586. if (typeof p.seekBy === 'function') q -= 4;
  7587. if (typeof p.seekTo === 'function') q -= 4;
  7588. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7589. if (typeof p.getDuration === 'function') q -= 4;
  7590. if (typeof p.loadModule === 'function') q -= 4;
  7591. if (typeof p.unloadModule === 'function') q -= 4;
  7592. if (typeof p.getOption === 'function') q -= 4;
  7593. if (typeof p.getOptions === 'function') q -= 4;
  7594. if (typeof p.setOption === 'function') q -= 4;
  7595. if (typeof p.addCueRange === 'function') q -= 4;
  7596. if (typeof p.getDebugText === 'function') q -= 4;
  7597. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7598. if (typeof p.setSizeStyle === 'function') q -= 4;
  7599. if (typeof p.showControls === 'function') q -= 4;
  7600. if (typeof p.hideControls === 'function') q -= 4;
  7601. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7602. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7603. if (typeof p.isFullscreen === 'function') q -= 4;
  7604. if (typeof p.cancelPlayback === 'function') q -= 4;
  7605. if (typeof p.getProgressState === 'function') q -= 4;
  7606. if (typeof p.isInline === 'function') q -= 4;
  7607. if (typeof p.setInline === 'function') q -= 4;
  7608. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7609. if (typeof p.getPlayerSize === 'function') q -= 4;
  7610. if (typeof p.wakeUpControls === 'function') q -= 4;
  7611. if (typeof p.setCenterCrop === 'function') q -= 4;
  7612. if (typeof p.getLoopVideo === 'function') q -= 4;
  7613. if (typeof p.setLoopVideo === 'function') q -= 4;
  7614.  
  7615.  
  7616. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7617.  
  7618. if (q > 0) brr.set(k, q);
  7619.  
  7620. }
  7621.  
  7622. }
  7623.  
  7624. if (arr.length === 0) {
  7625.  
  7626. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7627. } else {
  7628.  
  7629. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7630.  
  7631. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7632.  
  7633. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7634. return arr[0][0];
  7635. }
  7636.  
  7637.  
  7638.  
  7639. }
  7640.  
  7641.  
  7642.  
  7643.  
  7644. const getDX = (_yt_player) => {
  7645. const w = 'DX';
  7646.  
  7647. let arr = [];
  7648. let brr = new Map();
  7649.  
  7650. for (const [k, v] of Object.entries(_yt_player)) {
  7651.  
  7652. const p = typeof v === 'function' ? v.prototype : 0;
  7653. if (p) {
  7654. let q = 0;
  7655. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 7) q += 400;
  7656. else if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 8) q += 300;
  7657. else if (typeof p.handleGlobalKeyUp === 'function') q += 200;
  7658.  
  7659. if (typeof p.handleGlobalKeyUp === 'function' && p.handleGlobalKeyUp.length === 0) q -= 600; // avoid SV
  7660.  
  7661.  
  7662. if (!(typeof p.init === 'function' && p.init.length === 0)) q -= 300; // init is required
  7663.  
  7664. if (q < 200) continue; // p.handleGlobalKeyUp must be available
  7665.  
  7666. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 8) q += 80;
  7667. if (typeof p.handleGlobalKeyDown === 'function' && p.handleGlobalKeyDown.length === 7) q += 30;
  7668. if (typeof p.step === 'function' && p.step.length === 1) q += 10;
  7669. if (typeof p.step === 'function' && p.step.length !== 1) q += 5;
  7670.  
  7671.  
  7672. // differentiate QT and DX
  7673.  
  7674.  
  7675. q += 280;
  7676.  
  7677. if (typeof p.cueVideoByPlayerVars === 'function') q -= 4;
  7678. if (typeof p.loadVideoByPlayerVars === 'function') q -= 4;
  7679. if (typeof p.preloadVideoByPlayerVars === 'function') q -= 4;
  7680. if (typeof p.seekBy === 'function') q -= 4;
  7681. if (typeof p.seekTo === 'function') q -= 4;
  7682. if (typeof p.getStoryboardFormat === 'function') q -= 4;
  7683. if (typeof p.getDuration === 'function') q -= 4;
  7684. if (typeof p.loadModule === 'function') q -= 4;
  7685. if (typeof p.unloadModule === 'function') q -= 4;
  7686. if (typeof p.getOption === 'function') q -= 4;
  7687. if (typeof p.getOptions === 'function') q -= 4;
  7688. if (typeof p.setOption === 'function') q -= 4;
  7689. if (typeof p.addCueRange === 'function') q -= 4;
  7690. if (typeof p.getDebugText === 'function') q -= 4;
  7691. if (typeof p.getCurrentBroadcastId === 'function') q -= 4;
  7692. if (typeof p.setSizeStyle === 'function') q -= 4;
  7693. if (typeof p.showControls === 'function') q -= 4;
  7694. if (typeof p.hideControls === 'function') q -= 4;
  7695. if (typeof p.getVideoContentRect === 'function') q -= 4;
  7696. if (typeof p.toggleFullscreen === 'function') q -= 4;
  7697. if (typeof p.isFullscreen === 'function') q -= 4;
  7698. if (typeof p.cancelPlayback === 'function') q -= 4;
  7699. if (typeof p.getProgressState === 'function') q -= 4;
  7700. if (typeof p.isInline === 'function') q -= 4;
  7701. if (typeof p.setInline === 'function') q -= 4;
  7702. if (typeof p.toggleSubtitles === 'function') q -= 4;
  7703. if (typeof p.getPlayerSize === 'function') q -= 4;
  7704. if (typeof p.wakeUpControls === 'function') q -= 4;
  7705. if (typeof p.setCenterCrop === 'function') q -= 4;
  7706. if (typeof p.getLoopVideo === 'function') q -= 4;
  7707. if (typeof p.setLoopVideo === 'function') q -= 4;
  7708.  
  7709.  
  7710. if (q > 0) arr = addProtoToArr(_yt_player, k, arr) || arr;
  7711.  
  7712. if (q > 0) brr.set(k, q);
  7713.  
  7714. }
  7715.  
  7716. }
  7717.  
  7718. if (arr.length === 0) {
  7719.  
  7720. console.warn(`[yt-js-engine-tamer] (key-extraction) Key does not exist. [${w}]`);
  7721. } else {
  7722.  
  7723. arr = arr.map(key => [key, (brr.get(key) || 0)]);
  7724.  
  7725. if (arr.length > 1) arr.sort((a, b) => b[1] - a[1]);
  7726.  
  7727. if (arr.length > 2) console.log(`[yt-js-engine-tamer] (key-extraction) [${w}]`, arr);
  7728. return arr[0][0];
  7729. }
  7730.  
  7731.  
  7732.  
  7733. }
  7734.  
  7735.  
  7736.  
  7737. const isPrepareCachedV = (FIX_avoid_incorrect_video_meta ? true : false) && (window === top);
  7738.  
  7739. let pageSetupVideoId = null; // set at finish; '' for indeterminate state
  7740. let pageSetupState = 0;
  7741.  
  7742. isPrepareCachedV && (() => {
  7743.  
  7744. pageSetupVideoId = '';
  7745. const clearCachedV = () => {
  7746. pageSetupVideoId = '';
  7747. pageSetupState = 0;
  7748. }
  7749. document.addEventListener('yt-navigate-start', clearCachedV, false); // user action
  7750. document.addEventListener('yt-navigate-cache', clearCachedV, false); // pop state
  7751. document.addEventListener('yt-page-data-fetched', clearCachedV, false); // still consider invalid until url is ready in yt-navigate-finish
  7752. document.addEventListener('yt-navigate-finish', () => {
  7753. pageSetupState = 1;
  7754. try {
  7755. const url = new URL(location.href);
  7756. if (!url || !isWatchPageURL(url)) {
  7757. pageSetupVideoId = '';
  7758. } else {
  7759. pageSetupVideoId = url.searchParams.get('v') || '';
  7760. }
  7761. } catch (e) {
  7762. pageSetupVideoId = '';
  7763. }
  7764. }, false);
  7765.  
  7766. })();
  7767.  
  7768. let videoPlayingY = null;
  7769.  
  7770. isPrepareCachedV && (() => {
  7771.  
  7772. let getNext = true;
  7773. let videoPlayingX = {
  7774. get videoId() {
  7775. if (getNext) {
  7776. getNext = false;
  7777.  
  7778. let elements = document.querySelectorAll('ytd-watch-flexy[video-id]');
  7779. const arr = [];
  7780. for (const element of elements) {
  7781. if (!element.closest('[hidden]')) arr.push(element);
  7782. }
  7783. if (arr.length !== 1) this.__videoId__ = '';
  7784. else {
  7785. this.__videoId__ = arr[0].getAttribute('video-id');
  7786. }
  7787.  
  7788. }
  7789. return this.__videoId__ || '';
  7790. }
  7791. }
  7792.  
  7793. videoPlayingY = videoPlayingX;
  7794. const handler = (evt) => {
  7795. const target = (evt || 0).target;
  7796. if (target instanceof HTMLVideoElement) {
  7797. getNext = true;
  7798. }
  7799. }
  7800. document.addEventListener('loadedmetadata', handler, true);
  7801. document.addEventListener('durationchange', handler, true);
  7802.  
  7803. })();
  7804.  
  7805.  
  7806.  
  7807. const cleanContext = async (win) => {
  7808. const waitFn = requestAnimationFrame; // shall have been binded to window
  7809. try {
  7810. let mx = 16; // MAX TRIAL
  7811. const frameId = 'vanillajs-iframe-v1';
  7812. /** @type {HTMLIFrameElement | null} */
  7813. let frame = document.getElementById(frameId);
  7814. let removeIframeFn = null;
  7815. if (!frame) {
  7816. frame = document.createElement('iframe');
  7817. frame.id = frameId;
  7818. const blobURL = typeof webkitCancelAnimationFrame === 'function' && typeof kagi === 'undefined' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null; // avoid Brave Crash
  7819. frame.sandbox = 'allow-same-origin'; // script cannot be run inside iframe but API can be obtained from iframe
  7820. let n = document.createElement('noscript'); // wrap into NOSCRPIT to avoid reflow (layouting)
  7821. n.appendChild(frame);
  7822. while (!document.documentElement && mx-- > 0) await new Promise(waitFn); // requestAnimationFrame here could get modified by YouTube engine
  7823. const root = document.documentElement;
  7824. root.appendChild(n); // throw error if root is null due to exceeding MAX TRIAL
  7825. if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL));
  7826.  
  7827. removeIframeFn = (setTimeout) => {
  7828. const removeIframeOnDocumentReady = (e) => {
  7829. e && win.removeEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7830. e = n;
  7831. n = win = removeIframeFn = 0;
  7832. setTimeout ? setTimeout(() => e.remove(), 200) : e.remove();
  7833. }
  7834. if (!setTimeout || document.readyState !== 'loading') {
  7835. removeIframeOnDocumentReady();
  7836. } else {
  7837. win.addEventListener("DOMContentLoaded", removeIframeOnDocumentReady, false);
  7838. }
  7839. }
  7840. }
  7841. while (!frame.contentWindow && mx-- > 0) await new Promise(waitFn);
  7842. const fc = frame.contentWindow;
  7843. if (!fc) throw "window is not found."; // throw error if root is null due to exceeding MAX TRIAL
  7844. try {
  7845. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle } = fc;
  7846. const res = { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, requestIdleCallback, getComputedStyle };
  7847. for (let k in res) res[k] = res[k].bind(win); // necessary
  7848. if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn);
  7849. res.animate = fc.HTMLElement.prototype.animate;
  7850. res.perfNow = fc.performance.now;
  7851. return res;
  7852. } catch (e) {
  7853. if (removeIframeFn) removeIframeFn();
  7854. return null;
  7855. }
  7856. } catch (e) {
  7857. console.warn(e);
  7858. return null;
  7859. }
  7860. };
  7861.  
  7862. const promiseForYtActionCalled = new Promise(resolve => {
  7863.  
  7864. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  7865. if (typeof AbortSignal !== 'undefined') {
  7866. let hn = () => {
  7867. if (!hn) return;
  7868. hn = null;
  7869. resolve(document.querySelector(appTag));
  7870. };
  7871. document.addEventListener('yt-action', hn, { capture: true, passive: true, once: true });
  7872. } else {
  7873. let hn = () => {
  7874. if (!hn) return;
  7875. document.removeEventListener('yt-action', hn, true);
  7876. hn = null;
  7877. resolve(document.querySelector(appTag));
  7878. };
  7879. document.addEventListener('yt-action', hn, true);
  7880. }
  7881. });
  7882.  
  7883. cleanContext(window).then(__CONTEXT__ => {
  7884. if (!__CONTEXT__) return null;
  7885.  
  7886. const { requestAnimationFrame, setTimeout, clearTimeout, cancelAnimationFrame, setInterval, clearInterval, animate, requestIdleCallback, getComputedStyle, perfNow } = __CONTEXT__;
  7887.  
  7888.  
  7889. performance.now17 = perfNow.bind(performance);
  7890.  
  7891.  
  7892.  
  7893. __requestAnimationFrame__ = requestAnimationFrame;
  7894.  
  7895.  
  7896. const isGPUAccelerationAvailable = (() => {
  7897. // https://gist.github.com/cvan/042b2448fcecefafbb6a91469484cdf8
  7898. try {
  7899. const canvas = document.createElement('canvas');
  7900. return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
  7901. } catch (e) {
  7902. return false;
  7903. }
  7904. })();
  7905.  
  7906. const foregroundPromiseFn_noGPU = (() => {
  7907.  
  7908. if (isGPUAccelerationAvailable) return null;
  7909.  
  7910. const pd = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState');
  7911. if (!pd || typeof pd.get !== 'function') return null;
  7912. const pdGet = pd.get;
  7913.  
  7914. let pr = null;
  7915.  
  7916. let hState = pdGet.call(document) === 'hidden';
  7917. // let cid = 0;
  7918. pureAddEventListener.call(document, 'visibilitychange', (evt) => {
  7919. const newHState = pdGet.call(document) === 'hidden';
  7920. if (hState !== newHState) {
  7921. // if (cid > 0) cid = clearInterval(cid);
  7922. hState = newHState;
  7923. if (!hState && pr) pr = pr.resolve();
  7924. }
  7925. });
  7926.  
  7927. // cid = setInterval(() => {
  7928. // const newHState = document.visibilityState === 'hidden';
  7929. // if (hState !== newHState) {
  7930. // hState = newHState;
  7931. // if (!hState && pr) pr = pr.resolve();
  7932. // }
  7933. // }, 100);
  7934.  
  7935.  
  7936. return (() => {
  7937. if (pr) return pr;
  7938. const w = ((!hState && setTimeout(() => {
  7939. if (!hState && pr === w) pr = pr.resolve();
  7940. })), (pr = new PromiseExternal()));
  7941. return w;
  7942. });
  7943.  
  7944. })();
  7945.  
  7946.  
  7947. let rafPromise = null;
  7948. const getRafPromise = () => rafPromise || (rafPromise = new Promise(resolve => {
  7949. requestAnimationFrame(hRes => {
  7950. rafPromise = null;
  7951. resolve(hRes);
  7952. });
  7953. }));
  7954.  
  7955. const foregroundPromiseFn = foregroundPromiseFn_noGPU || getRafPromise;
  7956.  
  7957.  
  7958. const wmComputedStyle = new WeakMap();
  7959.  
  7960. if (!window.__native__getComputedStyle__ && !window.__jst__getComputedStyle__ && typeof window.getComputedStyle === 'function' && window.getComputedStyle.length === 1) {
  7961. window.__native__getComputedStyle__ = getComputedStyle;
  7962. if (ENABLE_COMPUTEDSTYLE_CACHE) {
  7963. window.__original__getComputedStyle__ = window.getComputedStyle;
  7964. window.getComputedStyle = function (elem) {
  7965. if (!(elem instanceof Element) || (arguments.length === 2 && arguments[1]) || (arguments.length > 2)) {
  7966. return window.__original__getComputedStyle__(...arguments);
  7967. }
  7968. let cs = wmComputedStyle.get(elem);
  7969. if (!cs) {
  7970. cs = window.__native__getComputedStyle__(elem);
  7971. wmComputedStyle.set(elem, cs);
  7972. }
  7973. return cs;
  7974. };
  7975. } else {
  7976. window.__original__getComputedStyle__ = null;
  7977. }
  7978. window.__jst__getComputedStyle__ = window.getComputedStyle;
  7979. }
  7980.  
  7981. NO_SCHEDULING_DUE_TO_COMPUTEDSTYLE && promiseForYtActionCalled.then(() => {
  7982. if (typeof window.__jst__getComputedStyle__ === 'function' && window.__jst__getComputedStyle__.length === 1 && window.__jst__getComputedStyle__ !== window.getComputedStyle) {
  7983. window.getComputedStyle = window.__jst__getComputedStyle__;
  7984. }
  7985. });
  7986.  
  7987. const isUrlInEmbed = location.href.includes('.youtube.com/embed/');
  7988. const isAbortSignalSupported = typeof AbortSignal !== "undefined";
  7989.  
  7990. const promiseForTamerTimeout = new Promise(resolve => {
  7991. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  7992. setTimeout(resolve, 480);
  7993. }, { capture: true, passive: true, once: true });
  7994. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  7995. setTimeout(resolve, 1200);
  7996. });
  7997. setTimeout(resolve, 3000);
  7998. });
  7999.  
  8000. const promiseForPageInitied = new Promise(resolve => {
  8001. !isUrlInEmbed && isAbortSignalSupported && document.addEventListener('yt-action', function () {
  8002. setTimeout(resolve, 450);
  8003. }, { capture: true, passive: true, once: true });
  8004. !isUrlInEmbed && isAbortSignalSupported && typeof customElements === "object" && whenCEDefined('ytd-app').then(() => {
  8005. setTimeout(resolve, 900);
  8006. });
  8007. setTimeout(resolve, 1800);
  8008. });
  8009.  
  8010. NO_PRELOAD_GENERATE_204_BYPASS || promiseForPageInitied.then(() => {
  8011. NO_PRELOAD_GENERATE_204_BYPASS = true;
  8012. headLinkCollection = null;
  8013. });
  8014.  
  8015.  
  8016. NATIVE_CANVAS_ANIMATION && (() => {
  8017.  
  8018. observablePromise(() => {
  8019. HTMLCanvasElement.prototype.animate = animate;
  8020. }, promiseForTamerTimeout).obtain();
  8021.  
  8022. })();
  8023.  
  8024.  
  8025.  
  8026.  
  8027. FIX_ytAction_ && (async () => {
  8028.  
  8029. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-app';
  8030.  
  8031. const ytdApp = await new Promise(resolve => {
  8032.  
  8033. whenCEDefined(appTag).then(() => {
  8034. const ytdApp = document.querySelector(appTag);
  8035. if (ytdApp) {
  8036. resolve(ytdApp);
  8037. return;
  8038. }
  8039. let mo = new MutationObserver(() => {
  8040. const ytdApp = document.querySelector(appTag);
  8041. if (!ytdApp) return;
  8042. if (mo) {
  8043. mo.disconnect();
  8044. mo.takeRecords();
  8045. mo = null;
  8046. }
  8047. resolve(ytdApp);
  8048. });
  8049. mo.observe(document, { subtree: true, childList: true });
  8050. });
  8051.  
  8052. });
  8053.  
  8054. if (!ytdApp) return;
  8055. const cProto = insp(ytdApp).constructor.prototype;
  8056.  
  8057. if (!cProto) return;
  8058. let mbd = 0;
  8059.  
  8060. const fixer = (_ytdApp) => {
  8061. const ytdApp = insp(_ytdApp);
  8062. if (ytdApp && typeof ytdApp.onYtActionBoundListener_ === 'function' && !ytdApp.onYtActionBoundListener57_) {
  8063. ytdApp.onYtActionBoundListener57_ = ytdApp.onYtActionBoundListener_;
  8064. ytdApp.onYtActionBoundListener_ = ytdApp.onYtAction_.bind(ytdApp);
  8065. mbd++;
  8066. }
  8067. }
  8068.  
  8069. observablePromise(() => {
  8070.  
  8071. if (typeof cProto.created === 'function' && !cProto.created56) {
  8072. cProto.created56 = cProto.created;
  8073. cProto.created = function (...args) {
  8074. const r = this.created56(...args);
  8075. fixer(this);
  8076. return r;
  8077. };
  8078. mbd++;
  8079. }
  8080.  
  8081. if (typeof cProto.onYtAction_ === 'function' && !cProto.onYtAction57_) {
  8082. cProto.onYtAction57_ = cProto.onYtAction_;
  8083. cProto.onYtAction_ = function (...args) {
  8084. Promise.resolve().then(() => this.onYtAction57_(...args));
  8085. };
  8086. mbd++;
  8087. }
  8088.  
  8089. if (ytdApp) fixer(ytdApp);
  8090.  
  8091. /*
  8092. const actionRouter_ = ytdApp ? ytdApp.actionRouter_ : null;
  8093. if (actionRouter_ && typeof actionRouter_.handleAction === 'function' && !actionRouter_.handleAction57) {
  8094. actionRouter_.handleAction57 = actionRouter_.handleAction;
  8095. actionRouter_.handleAction = function (...args) {
  8096. Promise.resolve().then(() => this.handleAction57(...args));
  8097. }
  8098. mbd++;
  8099. }
  8100. */
  8101.  
  8102. // if(mbd === 3) return 1;
  8103. if (mbd >= 3) return 1;
  8104.  
  8105. }, new Promise(r => setTimeout(r, 1000))).obtain();
  8106.  
  8107. })();
  8108.  
  8109.  
  8110. FORCE_NO_REUSEABLE_ELEMENT_POOL && promiseForYtActionCalled.then(async () => {
  8111.  
  8112. const appTag = isChatRoomURL ? 'yt-live-chat-app' : 'ytd-watch-flexy';
  8113.  
  8114. const app = await observablePromise(() => {
  8115.  
  8116. return document.querySelector(appTag);
  8117.  
  8118. }).obtain();
  8119.  
  8120. if (!app) return;
  8121.  
  8122. const appCnt = insp(app);
  8123. FORCE_NO_REUSEABLE_ELEMENT_POOL_fn(appCnt);
  8124.  
  8125.  
  8126.  
  8127.  
  8128. });
  8129.  
  8130. const observablePromise = (proc, timeoutPromise) => {
  8131. let promise = null;
  8132. return {
  8133. obtain() {
  8134. if (!promise) {
  8135. promise = new Promise(resolve => {
  8136. let mo = null;
  8137. const f = () => {
  8138. let t = proc();
  8139. if (t) {
  8140. mo.disconnect();
  8141. mo.takeRecords();
  8142. mo = null;
  8143. resolve(t);
  8144. }
  8145. }
  8146. mo = new MutationObserver(f);
  8147. mo.observe(document, { subtree: true, childList: true })
  8148. f();
  8149. timeoutPromise && timeoutPromise.then(() => {
  8150. resolve(null)
  8151. });
  8152. });
  8153. }
  8154. return promise
  8155. }
  8156. }
  8157. }
  8158.  
  8159. // let _yt_player_promise = null;
  8160. /*
  8161. const getYtPlayerPromise = () => {
  8162. if (!_yt_player_promise) {
  8163. _yt_player_promise = new Promise(resolve => {
  8164. let cid = setInterval(() => {
  8165. let t = (((window || 0)._yt_player || 0) || 0);
  8166. if (t) {
  8167. clearInterval(cid);
  8168. resolve(t);
  8169. }
  8170. }, 1);
  8171. promiseForTamerTimeout.then(() => {
  8172. resolve(null)
  8173. });
  8174. });
  8175. }
  8176. return _yt_player_promise;
  8177. }
  8178. */
  8179. const _yt_player_observable = observablePromise(() => {
  8180. const _yt_player = (((window || 0)._yt_player || 0) || 0);
  8181. if (_yt_player) {
  8182. _yt_player[`__is_yt_player__${Date.now()}`] = 1;
  8183. return _yt_player;
  8184. }
  8185. }, promiseForTamerTimeout);
  8186.  
  8187. const polymerObservable = observablePromise(() => {
  8188. const Polymer = window.Polymer;
  8189. if (typeof Polymer !== 'function') return;
  8190. if (!(Polymer.Base || 0).connectedCallback || !(Polymer.Base || 0).disconnectedCallback) return;
  8191. return Polymer;
  8192. }, promiseForTamerTimeout);
  8193.  
  8194. const schedulerInstanceObservable = observablePromise(() => {
  8195. return (((window || 0).ytglobal || 0).schedulerInstanceInstance_ || 0);
  8196. }, promiseForTamerTimeout);
  8197.  
  8198. const timelineObservable = observablePromise(() => {
  8199. let t = (((document || 0).timeline || 0) || 0);
  8200. if (t && typeof t._play === 'function') {
  8201. return t;
  8202. }
  8203. }, promiseForTamerTimeout);
  8204. const animationObservable = observablePromise(() => {
  8205. let t = (((window || 0).Animation || 0) || 0);
  8206. if (t && typeof t === 'function' && t.length === 2 && typeof t.prototype._updatePromises === 'function') {
  8207. return t;
  8208. }
  8209. }, promiseForTamerTimeout);
  8210.  
  8211.  
  8212. const getScreenInfo = {
  8213. screenWidth: 0,
  8214. screenHeight: 0,
  8215. valueReady: false,
  8216. onResize: () => {
  8217. getScreenInfo.valueReady = false;
  8218. },
  8219. sizeProvided: () => {
  8220. if (getScreenInfo.valueReady) return true;
  8221. getScreenInfo.screenWidth = screen.width;
  8222. getScreenInfo.screenHeight = screen.height;
  8223. if (getScreenInfo.screenWidth * getScreenInfo.screenHeight > 1) {
  8224. getScreenInfo.valueReady = true;
  8225. return true;
  8226. }
  8227. return false;
  8228. }
  8229. };
  8230.  
  8231. window.addEventListener('resize', getScreenInfo.onResize, true);
  8232.  
  8233.  
  8234. // const hookLeftPending = new WeakMap();
  8235.  
  8236. const isNaNx = Number.isNaN;
  8237.  
  8238. const hookLeftPD = {
  8239. get() {
  8240. const p = 'left';
  8241. // const o = hookLeftPending.get(this);
  8242. // if (o && o.key) {
  8243. // this.setProperty(p, o.value);
  8244. // o.key = null
  8245. // }
  8246. return this.getPropertyValue(p);
  8247. },
  8248. set(v) {
  8249.  
  8250. const p = 'left';
  8251. const cv = this.getPropertyValue(p);
  8252. const sv = v;
  8253.  
  8254. // const did = Math.floor(Math.random() * 314159265359 + 314159265359).toString(36);
  8255.  
  8256. // console.log(8380,did, cv, sv)
  8257. if (!cv && !sv) return true;
  8258. if (cv === sv) return true;
  8259.  
  8260. // skip 0~9px => L>=4
  8261.  
  8262. const qsv = `${sv}`.length >= 4 && `${sv}`.endsWith('px') ? +sv.slice(0, -2) : NaN;
  8263.  
  8264. if (!isNaNx(qsv)) {
  8265. const qcv = `${cv}`.length >= 4 && `${cv}`.endsWith('px') ? +cv.slice(0, -2) : NaN;
  8266.  
  8267. if (!isNaNx(qcv) && getScreenInfo.sizeProvided()) {
  8268. const { screenWidth, screenHeight } = getScreenInfo;
  8269. let pWidth = screenWidth + 1024;
  8270. let pHeight = screenHeight + 768;
  8271. const minRatio = 0.003;
  8272. const dw = pWidth * 0.0003; // min dw = 0.3072
  8273. const dh = pHeight * 0.0003; // min dh = 0.2304
  8274. // console.log(8381,did, Math.abs(qcv - qsv) < dw)
  8275. if (Math.abs(qcv - qsv) < dw) return true;
  8276. }
  8277.  
  8278. v = `${qsv > -1e-5 && qsv < 1e-5 ? 0 : qsv.toFixed(4)}px`;
  8279. if (`${v}`.length > `${sv}`.length) v = sv;
  8280. // console.log(8382, did, sv, nv, cv, this)
  8281. }
  8282.  
  8283. // Promise.resolve().then(() => {
  8284. // const o = hookLeftPending.get(this);
  8285. // if (o && o.key === did) {
  8286. // this.setProperty(p, o.value);
  8287. // o.key = null;
  8288. // }
  8289. // });
  8290. // hookLeftPending.set(this, {
  8291. // key: did,
  8292. // value: nv
  8293. // });
  8294.  
  8295. // if (nv != v) {
  8296. // console.log(8387, v, nv);
  8297. // }
  8298.  
  8299. this.setProperty(p, v);
  8300. // console.log(8383, did, this.getPropertyValue(p))
  8301. return true;
  8302. },
  8303. enumerable: true,
  8304. configurable: true
  8305. };
  8306.  
  8307.  
  8308. if (HOOK_CSSPD_LEFT) {
  8309.  
  8310.  
  8311. Object.defineProperty(CSSStyleDeclaration.prototype, 'left', hookLeftPD);
  8312.  
  8313. }
  8314.  
  8315.  
  8316.  
  8317.  
  8318.  
  8319. const generalEvtHandler = async (_evKey, _fvKey, _debug) => {
  8320.  
  8321. const evKey = `${_evKey}`;
  8322. const fvKey = `${_fvKey}`;
  8323. const debug = !!_debug;
  8324.  
  8325. const _yt_player = await _yt_player_observable.obtain();
  8326.  
  8327.  
  8328. if (!_yt_player || typeof _yt_player !== 'object') return;
  8329.  
  8330.  
  8331. const getArr = (_yt_player) => {
  8332.  
  8333. let arr = [];
  8334.  
  8335. for (const [k, v] of Object.entries(_yt_player)) {
  8336.  
  8337. const p = typeof v === 'function' ? v.prototype : 0;
  8338. if (p
  8339. && typeof p[evKey] === 'function' && p[evKey].length >= 0 && !p[fvKey]
  8340.  
  8341. ) {
  8342. arr = addProtoToArr(_yt_player, k, arr) || arr;
  8343.  
  8344. }
  8345.  
  8346. }
  8347.  
  8348. if (arr.length === 0) {
  8349.  
  8350. console.warn(`Key prop [${evKey}] does not exist.`);
  8351. } else {
  8352.  
  8353. return arr;
  8354. }
  8355.  
  8356. };
  8357.  
  8358. const arr = getArr(_yt_player);
  8359.  
  8360.  
  8361. if (!arr) return;
  8362.  
  8363. debug && console.log(`FIX_${evKey}`, arr);
  8364.  
  8365. const f = function (...args) {
  8366. Promise.resolve().then(() => this[fvKey](...args));
  8367. };
  8368.  
  8369.  
  8370. for (const k of arr) {
  8371.  
  8372. const g = _yt_player;
  8373. const gk = g[k];
  8374. const gkp = gk.prototype;
  8375.  
  8376. debug && console.log(237, k, gkp)
  8377.  
  8378. if (typeof gkp[evKey] == 'function' && !gkp[fvKey]) {
  8379. gkp[fvKey] = gkp[evKey];
  8380. gkp[evKey] = f;
  8381. }
  8382. }
  8383.  
  8384.  
  8385.  
  8386.  
  8387. }
  8388.  
  8389. if (!isChatRoomURL) {
  8390.  
  8391. FIX_onVideoDataChange && generalEvtHandler('onVideoDataChange', 'onVideoDataChange57');
  8392. // FIX_onClick && generalEvtHandler('onClick', 'onClick57');
  8393. FIX_onStateChange && generalEvtHandler('onStateChange', 'onStateChange57');
  8394. FIX_onLoopRangeChange && generalEvtHandler('onLoopRangeChange', 'onLoopRangeChange57');
  8395. if (FIX_VideoEVENTS_v2) {
  8396. const FIX_VideoEVENTS_DEBUG = 0;
  8397. generalEvtHandler('onVideoProgress', 'onVideoProgress57', FIX_VideoEVENTS_DEBUG); // --
  8398. // generalEvtHandler('onAutoplayBlocked', 'onAutoplayBlocked57', FIX_VideoEVENTS_DEBUG);
  8399. // generalEvtHandler('onLoadProgress', 'onLoadProgress57', FIX_VideoEVENTS_DEBUG); // << CAUSE ISSUE >>
  8400. generalEvtHandler('onFullscreenChange', 'onFullscreenChange57', FIX_VideoEVENTS_DEBUG); // --
  8401. // generalEvtHandler('onLoadedMetadata', 'onLoadedMetadata57', FIX_VideoEVENTS_DEBUG);
  8402. // generalEvtHandler('onDrmOutputRestricted', 'onDrmOutputRestricted57', FIX_VideoEVENTS_DEBUG);
  8403. // generalEvtHandler('onAirPlayActiveChange', 'onAirPlayActiveChange57', FIX_VideoEVENTS_DEBUG);
  8404. // generalEvtHandler('onAirPlayAvailabilityChange', 'onAirPlayAvailabilityChange57', FIX_VideoEVENTS_DEBUG);
  8405. // generalEvtHandler('onApiChange', 'onApiChange57', FIX_VideoEVENTS_DEBUG);
  8406.  
  8407. }
  8408. // onMutedAutoplayChange
  8409. // onVolumeChange
  8410. // onPlaybackRateChange
  8411.  
  8412. // onAirPlayActiveChange
  8413. // onAirPlayAvailabilityChange
  8414. // onApiChange
  8415. // onAutoplayBlocked
  8416. // onDrmOutputRestricted
  8417. // onFullscreenChange
  8418. // onLoadProgress
  8419. // onLoadedMetadata
  8420. // onVideoDataChange
  8421. // onVideoProgress
  8422.  
  8423. }
  8424.  
  8425.  
  8426. let isAmended_Polymer_RenderStatus = false;
  8427.  
  8428. (ENABLE_discreteTasking || FIX_Polymer_dom || FIX_Polymer_AF || FIX_stampDomArray) && (async () => {
  8429.  
  8430. const Polymer = await polymerObservable.obtain();
  8431. if (!Polymer) return;
  8432.  
  8433. if (FIX_Polymer_AF && Polymer && Polymer.RenderStatus && !isAmended_Polymer_RenderStatus) {
  8434. isAmended_Polymer_RenderStatus = true;
  8435.  
  8436. if (typeof Polymer.RenderStatus.beforeNextRender === 'function' && typeof Polymer.RenderStatus.afterNextRender === 'function' && Polymer.RenderStatus.beforeNextRender.length === 3 && Polymer.RenderStatus.afterNextRender.length === 3) {
  8437. let arrBefore = null, arrAfter = null;
  8438. const push = Array.prototype.push;
  8439. let arr = null;
  8440. Array.prototype.push = function () {
  8441. arr = this;
  8442. }
  8443. Polymer.RenderStatus.beforeNextRender({}, {}, {});
  8444. if (arr) arrBefore = arr;
  8445. arr = null;
  8446. Polymer.RenderStatus.afterNextRender({}, {}, {});
  8447. if (arr) arrAfter = arr;
  8448. arr = null;
  8449. Array.prototype.push = push;
  8450. Polymer.RenderStatus.arrBefore = arrBefore;
  8451. Polymer.RenderStatus.arrAfter = arrAfter;
  8452.  
  8453. if (arrBefore && arrAfter) {
  8454.  
  8455. Function.prototype.call7900 = Function.prototype.call;
  8456. Function.prototype.apply7900 = Function.prototype.apply;
  8457. Function.prototype.apply7948 = function (obj, args) {
  8458. const f = this;
  8459. let m = kRef(obj);
  8460. if (!m) return;
  8461. if (m.is && !m.nodeName) {
  8462. if (!m.isAttached || !m.hostElement) {
  8463. return;
  8464. }
  8465. }
  8466. try {
  8467. return !args ? f.call7900(m) : f.apply7900(m, args);
  8468. } catch (e) {
  8469. console.warn(e);
  8470. }
  8471. return null;
  8472. }
  8473.  
  8474. arrBefore.push = arrAfter.push = function (a) {
  8475. if (arguments.length !== 1 || !a || a.length === 0 || !a[0]) return push.apply(this, arguments);
  8476. if (a[0].deref) a[0] = kRef(a[0]);
  8477. const f = a[1]
  8478. const obj = a[0]
  8479. const args = a[2];
  8480. f.apply = f.apply7948;
  8481. if (!obj[wk]) obj[wk] = mWeakRef(obj);
  8482. a[0] = obj[wk]
  8483. // console.log(4992, a)
  8484. return push.call(this, a);
  8485. }
  8486.  
  8487. }
  8488.  
  8489.  
  8490. }
  8491. // Polymer.RenderStatus.beforeNextRender
  8492. }
  8493.  
  8494. if (FIX_Polymer_dom) {
  8495.  
  8496. const checkPDFuncValue = (pd) => {
  8497. return pd && pd.writable && pd.enumerable && pd.configurable && typeof pd.value == 'function'
  8498. }
  8499. const checkPDFuncValue2 = (pd) => {
  8500. return pd && typeof pd.value == 'function'
  8501. }
  8502.  
  8503. const checkPDFuncGet = (pd) => {
  8504. return pd && typeof pd.get == 'function'
  8505. }
  8506.  
  8507. const domX = Polymer.dom(document.createElement('null'));
  8508. const domXP = (((domX || 0).constructor || 0).prototype || 0);
  8509. const pd1 = Object.getOwnPropertyDescriptor(domXP, 'getOwnerRoot');
  8510. const pd2 = Object.getOwnPropertyDescriptor(Node.prototype, 'parentElement');
  8511. const pd3 = Object.getOwnPropertyDescriptor(domXP, 'querySelector'); // undefined
  8512. const pd4 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelector');
  8513. const pd4b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelector');
  8514. const pd5 = Object.getOwnPropertyDescriptor(domXP, 'querySelectorAll'); // undefined
  8515. const pd6 = Object.getOwnPropertyDescriptor(Element.prototype, 'querySelectorAll');
  8516. const pd6b = Object.getOwnPropertyDescriptor(Document.prototype, 'querySelectorAll');
  8517.  
  8518.  
  8519. // getOwnerRoot - to be reviewed
  8520. if (0 && checkPDFuncValue(pd1) && checkPDFuncGet(pd2) && !domXP.getOwnerRoot15 && typeof domXP.getOwnerRoot === 'function') {
  8521.  
  8522. domXP.getOwnerRoot15 = domXP.getOwnerRoot;
  8523. domXP.getOwnerRoot = function () {
  8524. try {
  8525. const p = this.node;
  8526.  
  8527. if (p instanceof HTMLElement_) {
  8528. const pp = pd2.get.call(p);
  8529. if (pp instanceof HTMLElement_ && pp.isConnected === true) {
  8530. return pp.getRootNode();
  8531. }
  8532.  
  8533. }
  8534. } catch (e) { }
  8535. return this.getOwnerRoot15();
  8536. }
  8537.  
  8538. Polymer.__fixedGetOwnerRoot__ = 1;
  8539. }
  8540.  
  8541.  
  8542.  
  8543.  
  8544. if ((!pd3 || checkPDFuncValue(pd3)) && checkPDFuncValue2(pd4) && checkPDFuncValue2(pd4b) && !('querySelector15' in domXP)) {
  8545.  
  8546. domXP.querySelector15 = domXP.querySelector;
  8547.  
  8548. const querySelectorFn = function (query) {
  8549. try {
  8550. const p = this.node;
  8551.  
  8552. if (p instanceof Document && p.isConnected === true) {
  8553. return pd4b.value.call(p, query);
  8554. }
  8555.  
  8556. } catch (e) { }
  8557. return this.querySelector15(query);
  8558. }
  8559.  
  8560. Object.defineProperty(domXP, 'querySelector', {
  8561. get() {
  8562. return querySelectorFn;
  8563. },
  8564. set(nv) {
  8565. if (nv === querySelectorFn) return true;
  8566. this.querySelector15 = nv;
  8567. return true;
  8568. },
  8569.  
  8570. enumerable: false,
  8571. configurable: true
  8572. });
  8573.  
  8574. Polymer.__fixedQuerySelector__ = 1;
  8575. }
  8576.  
  8577. if ((!pd5 || checkPDFuncValue(pd5)) && checkPDFuncValue2(pd6) && checkPDFuncValue2(pd6b) && !('querySelectorAll15' in domXP)) {
  8578.  
  8579. domXP.querySelectorAll15 = domXP.querySelectorAll;
  8580.  
  8581. const querySelectorAllFn = function (query) {
  8582.  
  8583. try {
  8584.  
  8585. const p = this.node;
  8586.  
  8587. if (p instanceof Document && p.isConnected === true) {
  8588. return pd6b.value.call(p, query);
  8589. }
  8590.  
  8591. } catch (e) {
  8592.  
  8593. }
  8594. return this.querySelectorAll15(query);
  8595. }
  8596.  
  8597. Object.defineProperty(domXP, 'querySelectorAll', {
  8598. get() {
  8599. return querySelectorAllFn;
  8600. },
  8601. set(nv) {
  8602. if (nv === querySelectorAllFn) return true;
  8603. this.querySelectorAll15 = nv;
  8604. return true;
  8605. },
  8606.  
  8607. enumerable: false,
  8608. configurable: true
  8609. });
  8610.  
  8611. Polymer.__fixedQuerySelectorAll__ = 1;
  8612. }
  8613. }
  8614.  
  8615.  
  8616. if (ENABLE_discreteTasking || FIX_stampDomArray) {
  8617.  
  8618. Polymer.Base.__connInit__ = function () {
  8619. setupYtComponent(this);
  8620. }
  8621.  
  8622.  
  8623. /** @type {Function} */
  8624. const connectedCallbackK = function (...args) {
  8625. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8626. const r = this[qm53](...args);
  8627. !this.mh35 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8628. this.mh35 = 1;
  8629. return r;
  8630. };
  8631.  
  8632. connectedCallbackK.m353 = 1;
  8633.  
  8634.  
  8635. const qt53 = Polymer.Base.connectedCallback;
  8636. Polymer.Base[qm53] = dmf.get(qt53) || qt53;
  8637.  
  8638. Polymer.Base.connectedCallback = connectedCallbackK;
  8639.  
  8640.  
  8641. /** @type {Function} */
  8642. const createdK = function (...args) {
  8643. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8644. const r = this[qn53](...args);
  8645. !this.mh36 && typeof this.__connInit__ === 'function' && this.__connInit__();
  8646. this.mh36 = 1;
  8647. return r;
  8648. };
  8649.  
  8650.  
  8651. createdK.m353 = 1;
  8652. Polymer.Base[qn53] = Polymer.Base.created;
  8653. Polymer.Base.created = createdK;
  8654.  
  8655.  
  8656.  
  8657.  
  8658.  
  8659.  
  8660.  
  8661.  
  8662.  
  8663.  
  8664.  
  8665. }
  8666.  
  8667. })();
  8668.  
  8669.  
  8670. /*
  8671.  
  8672. e.nativeAppendChild = d.prototype.appendChild,
  8673. d.prototype.appendChild = function(h) {
  8674. return function(l) {
  8675. if (l instanceof DocumentFragment) {
  8676. var m = Array.from(l.children);
  8677. l = h.nativeAppendChild.call(this, l);
  8678. if (this.isConnected) {
  8679. m = g(m);
  8680. for (var p = m.next(); !p.done; p = m.next())
  8681. YD(p.value)
  8682. }
  8683. return l
  8684. }
  8685. m = l instanceof Element && l.isConnected;
  8686. p = h.nativeAppendChild.call(this, l);
  8687. m && ZD(l);
  8688. this.isConnected && YD(l);
  8689. return p
  8690. }
  8691. }(e),
  8692.  
  8693. */
  8694.  
  8695. CHANGE_appendChild && !Node.prototype.appendChild73 && Node.prototype.appendChild && (() => {
  8696.  
  8697. const f = Node.prototype.appendChild73 = Node.prototype.appendChild;
  8698. if (f) Node.prototype.appendChild = function (a) {
  8699. if (this instanceof Element) { // exclude DocumentFragment
  8700. try {
  8701. let checkFragmentA = (a instanceof DocumentFragment);
  8702. if (!NO_PRELOAD_GENERATE_204_BYPASS && document.head === this) {
  8703. if (headLinkCollection === null) headLinkCollection = document.head.getElementsByTagName('LINK');
  8704. for (const node of headLinkCollection) {
  8705. if (node.rel === 'preload' && node.as === 'fetch') {
  8706. node.rel = 'prefetch'; // see https://github.com/GoogleChromeLabs/quicklink
  8707. }
  8708. }
  8709. } else if (checkFragmentA && this.nodeName.startsWith('YT-')) { // yt-animated-rolling-number, yt-attributed-string
  8710. checkFragmentA = false;
  8711. }
  8712. if (checkFragmentA && a.firstElementChild === null) {
  8713. // no element in fragmentA
  8714. let doNormal = false;
  8715. for (let child = a.firstChild; child instanceof Node; child = child.nextSibling) {
  8716. if (child.nodeType === 3) { doNormal = true; break; }
  8717. }
  8718. if (!doNormal) return a;
  8719. }
  8720. } catch (e) {
  8721. console.log(e);
  8722. }
  8723. }
  8724. return arguments.length === 1 ? f.call(this, a) : f.apply(this, arguments);
  8725. }
  8726.  
  8727. })();
  8728.  
  8729. if (FIX_Shady) {
  8730.  
  8731. observablePromise(() => {
  8732. const { ShadyDOM, ShadyCSS } = window;
  8733. if (ShadyDOM) {
  8734. ShadyDOM.handlesDynamicScoping = false; // 9 of 10
  8735. ShadyDOM.noPatch = true; // 1 of 10
  8736. ShadyDOM.patchOnDemand = false; // 1 of 10
  8737. ShadyDOM.preferPerformance = true; // 1 of 10
  8738. ShadyDOM.querySelectorImplementation = undefined; // 1 of 10
  8739. }
  8740. if (ShadyCSS) {
  8741. ShadyCSS.nativeCss = true; // 1 of 10
  8742. ShadyCSS.nativeShadow = true; // 6 of 10
  8743. ShadyCSS.cssBuild = undefined; // 1 of 10
  8744. ShadyCSS.disableRuntime = true; // 1 of 10
  8745. }
  8746. if (ShadyDOM && ShadyCSS) return 1;
  8747. }, promiseForTamerTimeout).obtain(); // clear until 1 is return
  8748.  
  8749. }
  8750.  
  8751.  
  8752. // let schedulerInstancePropOfTimerType = '';
  8753. // let schedulerInstancePropOfTimerId = '';
  8754. (FIX_schedulerInstanceInstance & 2) && (async () => {
  8755.  
  8756. const schedulerInstanceInstance_ = await schedulerInstanceObservable.obtain();
  8757.  
  8758. if (!schedulerInstanceInstance_) return;
  8759.  
  8760. const checkOK = typeof schedulerInstanceInstance_.start === 'function' && !schedulerInstanceInstance_.start993 && !schedulerInstanceInstance_.stop && !schedulerInstanceInstance_.cancel && !schedulerInstanceInstance_.terminate && !schedulerInstanceInstance_.interupt;
  8761. if (checkOK) {
  8762.  
  8763. let resolveRendering = null;
  8764.  
  8765. let cmPr = new PromiseExternal();
  8766. const cm = document.createComment('0');
  8767. const cmObs = new MutationObserver(() => {
  8768. if (resolveRendering) {
  8769. resolveRendering();
  8770. resolveRendering = null;
  8771. }
  8772. cmPr.resolve();
  8773. cmPr = new PromiseExternal();
  8774. });
  8775. cmObs.observe(cm, {characterData: true})
  8776.  
  8777. let web_emulated_idle_callback_delay_val = null;
  8778.  
  8779. const getRenderIdleCallbackMs = () => {
  8780. if (typeof web_emulated_idle_callback_delay_val === 'number') return web_emulated_idle_callback_delay_val;
  8781. const config = (win.yt || 0).config_ || (win.ytcfg || 0).data_ || 0;
  8782. const delay = (config.EXPERIMENT_FLAGS || 0).web_emulated_idle_callback_delay || (config.EXPERIMENTS_FORCED_FLAGS || 0).web_emulated_idle_callback_delay;
  8783. if (typeof delay === 'number') web_emulated_idle_callback_delay_val = delay;
  8784. return web_emulated_idle_callback_delay_val;
  8785. }
  8786. let isDelayRenderFn_firstCheck = true;
  8787. let isDelayRenderFn_key = null;
  8788. const isDelayRenderFn = (f) => {
  8789. if (!isDelayRenderFn_firstCheck) return (typeof ytglobal === 'undefined' ? false : ((ytglobal || 0).schedulerInstanceInstance_ || 0)[isDelayRenderFn_key] === f);
  8790. isDelayRenderFn_firstCheck = false;
  8791. if (typeof ytglobal === 'undefined') return false;
  8792. const globalInstance = ((ytglobal || 0).schedulerInstanceInstance_ || 0);
  8793. if (!globalInstance) return false;
  8794. for (const entry of Object.entries(Object.getOwnPropertyDescriptors(globalInstance))) {
  8795. if (entry[1].value === f && entry[1].enumerable && entry[1].writable && entry[1].configurable) {
  8796. isDelayRenderFn_key = entry[0]
  8797. console.log('[yt-js-engine-tamer] web_emulated_idle_callback fix applied');
  8798. return true;
  8799. }
  8800. }
  8801. return false;
  8802. }
  8803.  
  8804. schedulerInstanceInstance_.start993 = schedulerInstanceInstance_.start;
  8805.  
  8806. let requestingFn = null;
  8807. let requestingArgs = null;
  8808.  
  8809. const f = function () {
  8810. requestingFn = this.fn;
  8811. requestingArgs = [...arguments];
  8812. return 12373;
  8813. };
  8814.  
  8815. const fakeFns = [
  8816. f.bind({ fn: requestAnimationFrame }),
  8817. f.bind({ fn: setInterval }),
  8818. f.bind({ fn: setTimeout }),
  8819. f.bind({ fn: requestIdleCallback })
  8820. ];
  8821.  
  8822. let mzt = 0;
  8823.  
  8824. let _fnSelectorProp = null;
  8825. const mkFns = new Array(4);
  8826.  
  8827. /*
  8828. case 1:
  8829. var a = this.K;
  8830. this.g = this.I ? window.requestIdleCallback(a, {
  8831. timeout: 3E3
  8832. }) : window.setTimeout(a, ma);
  8833. break;
  8834. case 2:
  8835. this.g = window.setTimeout(this.M, this.N);
  8836. break;
  8837. case 3:
  8838. this.g = window.requestAnimationFrame(this.L);
  8839. break;
  8840. case 4:
  8841. this.g = window.setTimeout(this.J, 0)
  8842. }
  8843.  
  8844. */
  8845. const startFnHandler = {
  8846. get(target, prop, receiver) {
  8847. if (prop === '$$12377$$') return true;
  8848. if (prop === '$$12378$$') return target;
  8849.  
  8850. // console.log('get',prop)
  8851. return target[prop]
  8852. },
  8853. set(target, prop, value, receiver) {
  8854. // console.log('set', prop, value)
  8855.  
  8856.  
  8857. if (value >= 1 && value <= 4) _fnSelectorProp = prop;
  8858. if (value === 12373 && _fnSelectorProp) {
  8859.  
  8860. const schedulerTypeSelection = target[_fnSelectorProp];
  8861. const timerIdProp = prop;
  8862.  
  8863. // console.log(3991, requestingFn, requestingArgs[0], requestingArgs[1])
  8864. // if (schedulerTypeSelection && schedulerTypeSelection >= 1 && schedulerTypeSelection <= 4 && timerIdProp) {
  8865. // schedulerInstancePropOfTimerType = _fnSelectorProp || '';
  8866. // schedulerInstancePropOfTimerId = timerIdProp || '';
  8867. // }
  8868.  
  8869. if (schedulerTypeSelection === 3 && requestingFn === requestAnimationFrame) { // rAF(fn)
  8870. target[timerIdProp] = baseRAF.apply(window, requestingArgs);
  8871. } else if (schedulerTypeSelection === 2 && requestingFn === setTimeout) { // setTimeout(fn, delay)
  8872. // rare
  8873. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  8874. } else if (schedulerTypeSelection === 4 && requestingFn === setTimeout && !requestingArgs[1]) { // setTimeout(fn, 0)
  8875. // often
  8876. if ((FIX_schedulerInstanceInstance & 4)) {
  8877. const f = requestingArgs[0];
  8878. const tir = ++mzt;
  8879. nextBrowserTick_(() => {
  8880. if (target[timerIdProp] === -tir) f();
  8881. });
  8882. target[_fnSelectorProp] = 940;
  8883. target[timerIdProp] = -tir;
  8884. } else {
  8885. const f = requestingArgs[0];
  8886. const tir = ++mzt;
  8887. Promise.resolve().then(() => {
  8888. if (target[timerIdProp] === -tir) f();
  8889. });
  8890. target[_fnSelectorProp] = 930;
  8891. target[timerIdProp] = -tir;
  8892. }
  8893. } else if (schedulerTypeSelection === 1 && (requestingFn === requestIdleCallback || requestingFn === setTimeout)) { // setTimeout(requestIdleCallback)
  8894. // often
  8895. if (requestingFn === requestIdleCallback && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] || 0).timeout === 3000 && isDelayRenderFn(requestingArgs[0])) {
  8896. cm.data = (cm.data & 7) + 1;
  8897. let renderFn = requestingArgs[0];
  8898. const resolveRendering_ = () => {
  8899. const renderFn_ = renderFn;
  8900. if (renderFn_) {
  8901. renderFn = null;
  8902. renderFn_();
  8903. }
  8904. };
  8905. resolveRendering = resolveRendering_;
  8906. // console.log(299,requestingArgs[0], requestingArgs[0].name)
  8907. target[timerIdProp] = requestIdleCallback(resolveRendering_, { timeout: 300 });
  8908.  
  8909. // cm.data = (cm.data & 7) + 1;
  8910. // target[timerIdProp] = Math.random();
  8911.  
  8912. } else if (requestingFn === setTimeout && (requestingArgs[0] || 0).name === "bound " && (requestingArgs[1] === getRenderIdleCallbackMs()) && isDelayRenderFn(requestingArgs[0])) {
  8913.  
  8914. cm.data = (cm.data & 7) + 1;
  8915.  
  8916. let renderFn = requestingArgs[0];
  8917. const resolveRendering_ = () => {
  8918. const renderFn_ = renderFn;
  8919. if (renderFn_) {
  8920. renderFn = null;
  8921. renderFn_();
  8922. }
  8923. };
  8924. resolveRendering = resolveRendering_;
  8925.  
  8926. target[timerIdProp] = mkFns[2].call(window, resolveRendering_, 300);
  8927.  
  8928.  
  8929. } else {
  8930. if (requestingFn === requestIdleCallback) {
  8931. target[timerIdProp] = requestIdleCallback.apply(window, requestingArgs);
  8932. } else {
  8933. target[timerIdProp] = mkFns[2].apply(window, requestingArgs);
  8934. }
  8935. }
  8936. } else {
  8937. target[_fnSelectorProp] = 0;
  8938. target[timerIdProp] = 0;
  8939. }
  8940. } else {
  8941. target[prop] = value;
  8942. }
  8943. return true;
  8944. }
  8945. };
  8946.  
  8947. let startBusy = false;
  8948. schedulerInstanceInstance_.start = function () {
  8949. if (startBusy) return;
  8950. startBusy = true;
  8951. try {
  8952. mkFns[0] = window.requestAnimationFrame;
  8953. mkFns[1] = window.setInterval;
  8954. mkFns[2] = window.setTimeout;
  8955. mkFns[3] = window.requestIdleCallback;
  8956. const tThis = this['$$12378$$'] || this;
  8957. window.requestAnimationFrame = fakeFns[0]
  8958. window.setInterval = fakeFns[1]
  8959. window.setTimeout = fakeFns[2]
  8960. window.requestIdleCallback = fakeFns[3]
  8961. _fnSelectorProp = null;
  8962. tThis.start993.call(new Proxy(tThis, startFnHandler));
  8963. _fnSelectorProp = null;
  8964. window.requestAnimationFrame = mkFns[0];
  8965. window.setInterval = mkFns[1];
  8966. window.setTimeout = mkFns[2];
  8967. window.requestIdleCallback = mkFns[3];
  8968. } catch (e) {
  8969. console.warn(e);
  8970. }
  8971. startBusy = false;
  8972. }
  8973.  
  8974. schedulerInstanceInstance_.start.toString = schedulerInstanceInstance_.start993.toString.bind(schedulerInstanceInstance_.start993);
  8975.  
  8976. }
  8977. })();
  8978.  
  8979. FIX_yt_player && !isChatRoomURL && (async () => {
  8980.  
  8981. const fOption = 1 | 2 | 4;
  8982.  
  8983. const _yt_player = await _yt_player_observable.obtain();
  8984.  
  8985. if (!_yt_player || typeof _yt_player !== 'object') return;
  8986.  
  8987. const g = _yt_player;
  8988. let k;
  8989.  
  8990. if (fOption & 1) {
  8991.  
  8992. // rAf scheduling
  8993.  
  8994. const keyZqOu = getZqOu(_yt_player);
  8995. if (!keyZqOu) {
  8996. console.warn('[yt-js-engine-tamer] FIX_yt_player::keyZqOu error');
  8997. return;
  8998. }
  8999. k = keyZqOu
  9000.  
  9001. const gk = g[k];
  9002. if (typeof gk !== 'function') {
  9003. console.warn('[yt-js-engine-tamer] FIX_yt_player::g[keyZqOu] error');
  9004. return;
  9005. }
  9006. const gkp = gk.prototype;
  9007.  
  9008. const dummyObject = new gk;
  9009. const nilFunc = () => { };
  9010.  
  9011. const nilObj = {};
  9012.  
  9013. // console.log(1111111111)
  9014.  
  9015. let keyBoolD = '';
  9016. let keyWindow = '';
  9017. let keyFuncC = '';
  9018. let keyCidj = '';
  9019.  
  9020. for (const [t, y] of Object.entries(dummyObject)) {
  9021. if (y instanceof Window) keyWindow = t;
  9022. }
  9023.  
  9024. const dummyObjectProxyHandler = {
  9025. get(target, prop) {
  9026. let v = target[prop]
  9027. if (v instanceof Window && !keyWindow) {
  9028. keyWindow = t;
  9029. }
  9030. let y = typeof v === 'function' ? nilFunc : typeof v === 'object' ? nilObj : v;
  9031. if (prop === keyWindow) y = {
  9032. requestAnimationFrame(f) {
  9033. return 3;
  9034. },
  9035. cancelAnimationFrame() {
  9036.  
  9037. }
  9038. }
  9039. if (!keyFuncC && typeof v === 'function' && !(prop in target.constructor.prototype)) {
  9040. keyFuncC = prop;
  9041. }
  9042. // console.log('[get]', prop, typeof target[prop])
  9043.  
  9044.  
  9045. return y;
  9046. },
  9047. set(target, prop, value) {
  9048.  
  9049. if (typeof value === 'boolean' && !keyBoolD) {
  9050. keyBoolD = prop;
  9051. }
  9052. if (typeof value === 'number' && !keyCidj && value >= 2) {
  9053. keyCidj = prop;
  9054. }
  9055.  
  9056. // console.log('[set]', prop, value)
  9057. target[prop] = value;
  9058.  
  9059. return true;
  9060. }
  9061. };
  9062.  
  9063. dummyObject.start.call(new Proxy(dummyObject, dummyObjectProxyHandler));
  9064.  
  9065. // console.log('gkp.start',gkp.start);
  9066. // console.log('gkp.stop',gkp.stop);
  9067. gkp._activation = false;
  9068.  
  9069. gkp.start = function () {
  9070. // p59 || console.log(12100)
  9071. if (!this._activation) {
  9072. this._activation = true;
  9073. foregroundPromiseFn().then(() => {
  9074. this._activation = false;
  9075. if (this[keyCidj]) {
  9076. Promise.resolve().then(this[keyFuncC]);
  9077. }
  9078. });
  9079. }
  9080. this[keyCidj] = 1;
  9081. this[keyBoolD] = true;
  9082. };
  9083.  
  9084. gkp.stop = function () {
  9085. this[keyCidj] = null;
  9086. };
  9087.  
  9088.  
  9089. /*
  9090. g[k].start = function() {
  9091. this.stop();
  9092. this.D = true;
  9093. var a = requestAnimationFrame
  9094. , b = cancelAnimationFrame;
  9095. this.j = a.call(this.B, this.C)
  9096. }
  9097. ;
  9098. g[k].stop = function() {
  9099. if (this.isActive()) {
  9100. var a = requestAnimationFrame
  9101. , b = cancelAnimationFrame;
  9102. b.call(this.B, this.j)
  9103. }
  9104. this.j = null
  9105. }
  9106. */
  9107. }
  9108.  
  9109. if (fOption & 2) {
  9110. const keyzo = PERF_471489_ ? getzo(_yt_player) : null;
  9111.  
  9112. if (keyzo) {
  9113.  
  9114. k = keyzo;
  9115.  
  9116. const attrUpdateFn = g[k];
  9117. // console.log(5992, attrUpdateFn)
  9118. g['$$original$$' + k] = attrUpdateFn;
  9119. const zoTransform = async (a, c) => {
  9120.  
  9121. let transformType = '';
  9122. let transformValue = 0;
  9123. let transformUnit = '';
  9124. let transformTypeI = 0;
  9125.  
  9126. const aStyle = a.style;
  9127.  
  9128. let cType = 0;
  9129.  
  9130. const cl = c.length;
  9131.  
  9132. if (cl >= 8) {
  9133. // scale(1)
  9134. if (c.startsWith('scale') && c.charCodeAt(6) === 40 && c.charCodeAt(cl - 1) === 41) {
  9135. cType = 1;
  9136. let t = c.charCodeAt(5);
  9137. if (t === 88 || t === 120) cType = 1 | 4;
  9138. if (t === 89 || t === 121) cType = 1 | 8;
  9139. } else if (c.startsWith('translate') && c.charCodeAt(10) === 40 && c.charCodeAt(cl - 1) === 41) {
  9140. cType = 2;
  9141. let t = c.charCodeAt(9);
  9142. if (t === 88 || t === 120) cType = 2 | 4;
  9143. if (t === 89 || t === 121) cType = 2 | 8;
  9144. }
  9145. let w = 0;
  9146. if (w = (cType === 5) ? 1 : (cType === 9) ? 2 : 0) {
  9147. let p = c.substring(7, cl - 1);
  9148. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9149. if (typeof q === 'number' && !isNaNx(q)) {
  9150. transformType = w === 1 ? 'scaleX' : 'scaleY';
  9151. transformValue = q;
  9152. transformUnit = '';
  9153. transformTypeI = 1;
  9154. } else {
  9155. cType = 256;
  9156. }
  9157. } else if (w = (cType === 6) ? 1 : (cType === 10) ? 2 : 0) {
  9158. if (c.endsWith('px)')) {
  9159. let p = c.substring(11, cl - 3);
  9160. let q = p.length >= 1 ? parseFloat(p) : NaN;
  9161. if (typeof q === 'number' && !isNaNx(q)) {
  9162. transformType = w === 1 ? 'translateX' : 'translateY';
  9163. transformValue = q;
  9164. transformUnit = 'px';
  9165. transformTypeI = 2;
  9166. } else if (p === 'NaN') {
  9167. return;
  9168. }
  9169. } else {
  9170. cType = 256;
  9171. }
  9172. } else if (cType > 0) {
  9173. cType = 256;
  9174. }
  9175. }
  9176.  
  9177.  
  9178. if (cType === 256) {
  9179. console.log('[yt-js-engine-tamer] zoTransform undefined', c);
  9180. }
  9181.  
  9182. if (transformTypeI === 1) {
  9183. const q = Math.round(transformValue * steppingScaleN) / steppingScaleN;
  9184. const vz = toFixed2(q, 3);
  9185. c = `${transformType}(${vz})`;
  9186. const cv = aStyle.transform;
  9187. if (c === cv) return;
  9188. aStyle.transform = c;
  9189. } else if (transformTypeI === 2) {
  9190. const q = transformValue;
  9191. const vz = toFixed2(q, 1);
  9192. c = `${transformType}(${vz}${transformUnit})`;
  9193. const cv = aStyle.transform;
  9194. if (c === cv) return;
  9195. aStyle.transform = c;
  9196. } else { // eg empty
  9197. const cv = aStyle.transform;
  9198. if (!c && !cv) return;
  9199. else if (c === cv) return;
  9200. aStyle.transform = c;
  9201. }
  9202.  
  9203. };
  9204.  
  9205. const elmTransformTemp = new WeakMap();
  9206. const elmPropTemps = {
  9207. 'display': new WeakMap(),
  9208. 'width': new WeakMap(),
  9209. 'height': new WeakMap(),
  9210. 'outlineWidth': new WeakMap(),
  9211. 'position': new WeakMap(),
  9212. 'padding': new WeakMap(),
  9213. "cssText": new WeakMap(),
  9214. "right": new WeakMap(),
  9215. "left": new WeakMap(),
  9216. "top": new WeakMap(),
  9217. "bottom": new WeakMap(),
  9218. "transitionDelay": new WeakMap(),
  9219. "marginLeft": new WeakMap(),
  9220. "marginTop": new WeakMap(),
  9221. "marginRight": new WeakMap(),
  9222. "marginBottom": new WeakMap(),
  9223. }
  9224.  
  9225. const ns5 = Symbol();
  9226. const nextModify = (a, c, m, f, immediate) => {
  9227. const a_ = a;
  9228. const m_ = m;
  9229. const noKey = !m_.has(a_);
  9230. if (immediate || noKey) {
  9231. m_.set(a_, ns5);
  9232. f(a_, c);
  9233. noKey && nextBrowserTick_(() => {
  9234. const d = m_.get(a_);
  9235. if (d === undefined) return;
  9236. m_.delete(a_);
  9237. if (d !== ns5) f(a_, d);
  9238. });
  9239. } else {
  9240. m_.set(a_, c);
  9241. }
  9242. };
  9243.  
  9244. const set66 = new Set();
  9245. const log77 = new Map();
  9246. // const set77 = new Set(['top', 'left', 'bottom', 'right']); // caption positioning - immediate change
  9247.  
  9248. const modifiedFn = function (a, b, c, immediateChange = false) { // arrow function does not have function.prototype
  9249.  
  9250. // console.log(140000, a, b, c);
  9251. if (typeof c === 'number' && typeof b === 'string' && a instanceof HTMLElement_) {
  9252. const num = c;
  9253. c = `${num}`;
  9254. if (c.length > 5) c = (num < 10 && num > -10) ? toFixed2(num, 3) : toFixed2(num, 1);
  9255. }
  9256.  
  9257. if (typeof b === 'string' && typeof c === 'string' && a instanceof HTMLElement_) {
  9258.  
  9259. let elmPropTemp = null;
  9260.  
  9261. if (b === "transform") {
  9262. // div.ytp-hover-progress.ytp-hover-progress-light
  9263. // div.ytp-play-progress.ytp-swatch-background-color
  9264.  
  9265. nextModify(a, c, elmTransformTemp, zoTransform, immediateChange);
  9266. return;
  9267.  
  9268. } else if (elmPropTemp = elmPropTemps[b]) {
  9269.  
  9270. // if (c.length > 5 && c.includes('.')) {
  9271. // console.log(123213, c)
  9272. // }
  9273.  
  9274. const b_ = b;
  9275. nextModify(a, c, elmPropTemp, (a, c) => {
  9276. const style = a.style;
  9277. const cv = style[b_];
  9278. if (!cv && !c) return;
  9279. if (cv === c) return;
  9280. style[b_] = c;
  9281. }, immediateChange);
  9282. return;
  9283.  
  9284. } else if (b === "outline-width") {
  9285.  
  9286. const b_ = 'outlineWidth';
  9287. elmPropTemp = elmPropTemps[b_];
  9288. nextModify(a, c, elmPropTemp, (a, c) => {
  9289. const style = a.style;
  9290. const cv = style[b_];
  9291. if (!cv && !c) return;
  9292. if (cv === c) return;
  9293. style[b_] = c;
  9294. }, immediateChange);
  9295. return;
  9296.  
  9297. } else if (b === 'maxWidth' || b === 'maxHeight') {
  9298. // I think these can be directly assigned.
  9299.  
  9300. const b_ = b;
  9301. const style = a.style;
  9302. const cv = style[b_];
  9303. if (!cv && !c) return;
  9304. if (cv === c) return;
  9305. style[b_] = c;
  9306. return;
  9307.  
  9308. } else {
  9309. // if(immediate && elmPropTemps[b]){
  9310. // console.log(5191, b)
  9311. // }
  9312. // caption-window
  9313. // margin-left max-height max-width font-family fill color font-size background white-space margin
  9314. // text-align background-color
  9315. // console.log(27304, a, b, c)
  9316. if (!set66.has(b)) {
  9317. set66.add(b);
  9318. nextBrowserTick_(() => {
  9319. if (!a.classList.contains('caption-window') && !a.classList.contains('ytp-caption-segment')) {
  9320. console.log(27304, a, b, c)
  9321. }
  9322. })
  9323. }
  9324. }
  9325.  
  9326. attrUpdateFn.call(this, a, b, c);
  9327. return;
  9328. } else if (typeof (b || 0) === 'object') {
  9329.  
  9330. // this is to fix caption positioning
  9331. // const immediate = (a.id || 0).length > 14 && (('top' in b) || ('left' in b) || ('right' in b) || ('bottom' in b));
  9332. const immediate = (a.id || 0).length > 14;
  9333. for (const [k, v] of Object.entries(b)) {
  9334. modifiedFn.call(this, a, k, v, immediate);
  9335. }
  9336.  
  9337. } else {
  9338.  
  9339. // a = circle, b = stroke-dasharray, c= "1.8422857142857143 32"
  9340. // ytp-ad-timed-pie-countdown-inner
  9341.  
  9342. if (typeof b === 'string') {
  9343.  
  9344. let m = log77.get(b);
  9345. if (!m) {
  9346. m = [];
  9347. console.log('attrUpdateFn.debug.27304', m);
  9348. log77.set(b, m);
  9349. }
  9350. m.push([a, b, c]);
  9351.  
  9352. } else {
  9353. console.log('attrUpdateFn.debug.27306', a, b, c);
  9354. }
  9355.  
  9356. attrUpdateFn.call(this, a, b, c);
  9357. return;
  9358. }
  9359.  
  9360. // console.log(130000, a, b, c);
  9361.  
  9362. };
  9363. g[k] = modifiedFn;
  9364.  
  9365.  
  9366. /*
  9367.  
  9368. g.zo = function(a, b, c) {
  9369. if ("string" === typeof b)
  9370. (b = yo(a, b)) && (a.style[b] = c);
  9371. else
  9372. for (var d in b) {
  9373. c = a;
  9374. var e = b[d]
  9375. , f = yo(c, d);
  9376. f && (c.style[f] = e)
  9377. }
  9378. }
  9379.  
  9380.  
  9381. */
  9382.  
  9383.  
  9384. }
  9385. }
  9386.  
  9387. if (fOption & 4) {
  9388. const keyuG = PERF_471489_ ? getuG(_yt_player) : null;
  9389.  
  9390. if (keyuG) {
  9391.  
  9392. k = keyuG;
  9393.  
  9394. const gk = g[k];
  9395. const gkp = gk.prototype;
  9396.  
  9397.  
  9398. /** @type { Map<string, WeakMap<any, any>> } */
  9399. const ntLogs = new Map();
  9400.  
  9401. if (typeof gkp.updateValue === 'function' && gkp.updateValue.length === 2 && !gkp.updateValue31) {
  9402.  
  9403. gkp.updateValue31 = gkp.updateValue;
  9404. gkp.updateValue = function (a, b) {
  9405. if (typeof a !== 'string') return this.updateValue31(a, b);
  9406.  
  9407. const element = this.element;
  9408. if (!(element instanceof HTMLElement_)) return this.updateValue31(a, b);
  9409.  
  9410. let ntLog = ntLogs.get(a);
  9411. if (!ntLog) ntLogs.set(a, (ntLog = new WeakMap()));
  9412.  
  9413. let cache = ntLog.get(element);
  9414. if (cache && cache.value === b) {
  9415. return;
  9416. }
  9417. if (!cache) {
  9418. this.__oldValueByUpdateValue__ = null;
  9419. ntLog.set(element, cache = { value: b });
  9420. } else {
  9421. this.__oldValueByUpdateValue__ = cache.value;
  9422. cache.value = b;
  9423. }
  9424.  
  9425. return this.updateValue31(a, b);
  9426. }
  9427.  
  9428. /*
  9429. g.k.update = function(a) {
  9430. for (var b = g.u(Object.keys(a)), c = b.next(); !c.done; c = b.next())
  9431. c = c.value,
  9432. this.updateValue(c, a[c])
  9433. }
  9434. ;
  9435. g.k.updateValue = function(a, b) {
  9436. (a = this.Td["{{" + a + "}}"]) && wG(this, a[0], a[1], b)
  9437. }
  9438. */
  9439.  
  9440. }
  9441.  
  9442.  
  9443. }
  9444. }
  9445.  
  9446.  
  9447.  
  9448. })();
  9449.  
  9450.  
  9451. FIX_yt_player && !isChatRoomURL && FIX_SHORTCUTKEYS > 0 && (async () => {
  9452. // keyboard shortcut keys controller
  9453.  
  9454. const _yt_player = await _yt_player_observable.obtain();
  9455.  
  9456. if (!_yt_player || typeof _yt_player !== 'object') return;
  9457.  
  9458. keyboardController(_yt_player);
  9459.  
  9460. })();
  9461.  
  9462. FIX_yt_player && !isChatRoomURL && (async () => {
  9463. // timer scheduling
  9464.  
  9465. const _yt_player = await _yt_player_observable.obtain();
  9466.  
  9467. if (!_yt_player || typeof _yt_player !== 'object') return;
  9468.  
  9469. let keyZqQu = getZqQu(_yt_player);
  9470.  
  9471. if (!keyZqQu) return;
  9472.  
  9473. const g = _yt_player
  9474. let k = keyZqQu
  9475.  
  9476. const gk = g[k];
  9477. if (typeof gk !== 'function') return;
  9478. const gkp = gk.prototype;
  9479.  
  9480. const extractKeysZqQu = () => {
  9481.  
  9482.  
  9483. let _keyeC = '';
  9484. try {
  9485. gkp.stop.call(new Proxy({
  9486. isActive: () => { }
  9487. }, {
  9488. set(target, prop, value) {
  9489. if (value === 0) _keyeC = prop;
  9490. return true;
  9491. }
  9492. }));
  9493. } catch (e) { }
  9494. if (!_keyeC) return;
  9495. const keyeC = _keyeC;
  9496.  
  9497. let keyC = ''; // this.C = this.ST.bind(this)
  9498. let keyhj = ''; // 1000ms
  9499. try {
  9500. gkp.start.call(new Proxy({
  9501. stop: () => { },
  9502. [keyeC]: 0,
  9503. }, {
  9504. get(target, prop) {
  9505. if (prop in target) return target[prop];
  9506. if (!keyC) {
  9507. keyC = prop;
  9508. return null; // throw error
  9509. }
  9510. else if (!keyhj) {
  9511. keyhj = prop;
  9512. }
  9513.  
  9514. }
  9515. }));
  9516. } catch (e) {
  9517. if (!keyC || !keyhj) {
  9518. console.log(e)
  9519. }
  9520. }
  9521.  
  9522. if (!keyC || !keyhj) return;
  9523. let keyST = '';
  9524. let keyj = '';
  9525. let keyB = '';
  9526. let keyxa = '';
  9527.  
  9528. const possibleKs = new Set();
  9529.  
  9530. for (const [k, v] of Object.entries(gkp)) {
  9531. if (k === 'stop' || k === 'start' || k === 'isActive' || k === 'constructor' || k === keyeC || k === keyC || k === keyhj) {
  9532. continue;
  9533. }
  9534. if (typeof v === 'function') {
  9535. const m = /this\.(\w+)\.call\(this\.(\w+)\)/.exec(v + '');
  9536. if (m) {
  9537. keyST = k;
  9538. keyj = m[1];
  9539. keyB = m[2];
  9540. } else {
  9541. possibleKs.add(k);
  9542. }
  9543. }
  9544. }
  9545.  
  9546. if (!keyST || !keyj || !keyB) return;
  9547.  
  9548. for (const k of possibleKs) {
  9549. if (k === keyST || k === keyj || k === keyB) {
  9550. continue;
  9551. }
  9552. const v = gkp[k];
  9553. if (typeof v === 'function' && (v + '').includes(`this.stop();delete this.${keyj};delete this.${keyB}`)) {
  9554. keyxa = k;
  9555. }
  9556. }
  9557.  
  9558. return [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa];
  9559.  
  9560. }
  9561.  
  9562. const keys = extractKeysZqQu();
  9563. if (!keys || !keys.length) return;
  9564. const [keyeC, keyC, keyhj, keyST, keyj, keyB, keyxa] = keys; // [timerId, binded executorFn, 1000ms, executorFn, dataJ, objectB, disposeFn]
  9565.  
  9566. if (!keyeC || !keyC || !keyhj || !keyST || !keyj || !keyB || !keyxa) return;
  9567.  
  9568. let disposeKeys = null;
  9569.  
  9570. gkp[keyxa] = function () {
  9571. // dispose
  9572. if (!disposeKeys) {
  9573. disposeKeys = Object.getOwnPropertyNames(this).filter(key => {
  9574. if (key != keyeC && key != keyC && key != keyhj && key != keyST && key != keyj && key != keyB && key != keyxa) {
  9575. const t = typeof this[key];
  9576. return t === 'undefined' || t === 'object'
  9577. }
  9578. return false;
  9579. });
  9580. }
  9581. for (const key of disposeKeys) {
  9582. const v = this[key];
  9583. if ((v || 0).length >= 1) v.length = 0; // function (){if(this.fn)for(;this.fn.length;)this.fn.shift()()}
  9584. }
  9585. if (this[keyeC] > 0) this.stop();
  9586. this[keyj] = null;
  9587. this[keyB] = null;
  9588. };
  9589.  
  9590. gkp.start = function (a) {
  9591. if (this[keyeC] > 0) this.stop();
  9592. const delay = void 0 !== a ? a : this[keyhj];
  9593. this[keyeC] = window.setTimeout(this[keyC], delay);
  9594. };
  9595. gkp.stop = function () {
  9596. if (this[keyeC] > 0) {
  9597. window.clearTimeout(this[keyeC]);
  9598. this[keyeC] = 0;
  9599. }
  9600. };
  9601.  
  9602. gkp.isActive = function () {
  9603. return this[keyeC] > 0;
  9604. };
  9605.  
  9606. gkp[keyST] = function () {
  9607. this.stop(); // this[keyeC] = 0;
  9608. const fn = this[keyj];
  9609. const obj = this[keyB];
  9610. let skip = false;
  9611. if (!fn) skip = true;
  9612. else if (IGNORE_bufferhealth_CHECK && obj) {
  9613. let m;
  9614. if ((m = obj[keyC]) instanceof Map || (m = obj[keyj]) instanceof Map) {
  9615. if (m.has("bufferhealth")) skip = true;
  9616. }
  9617. }
  9618. if (!skip) {
  9619. fn.call(obj);
  9620. }
  9621. };
  9622.  
  9623.  
  9624.  
  9625.  
  9626. /*
  9627.  
  9628. g.k.eC = 0;
  9629. g.k.xa = function() {
  9630. g.Qu.Vf.xa.call(this);
  9631. this.stop();
  9632. delete this.j;
  9633. delete this.B
  9634. }
  9635. ;
  9636. g.k.start = function(a) {
  9637. this.stop();
  9638. this.eC = g.gg(this.C, void 0 !== a ? a : this.hj)
  9639. }
  9640. ;
  9641. g.k.stop = function() {
  9642. this.isActive() && g.Sa.clearTimeout(this.eC);
  9643. this.eC = 0
  9644. }
  9645. ;
  9646. g.k.isActive = function() {
  9647. return 0 != this.eC
  9648. }
  9649. ;
  9650. g.k.ST = function() {
  9651. this.eC = 0;
  9652. this.j && this.j.call(this.B)
  9653. }
  9654. ;
  9655. */
  9656.  
  9657.  
  9658.  
  9659.  
  9660. })();
  9661.  
  9662. FIX_Animation_n_timeline && (async () => {
  9663.  
  9664. const [timeline, Animation] = await Promise.all([timelineObservable.obtain(), animationObservable.obtain()]);
  9665.  
  9666. if (!timeline || !Animation) return;
  9667.  
  9668. const animationsFix = (timeline) => {
  9669. const animations = (timeline || 0)._animations || 0;
  9670. const c = animations[0];
  9671. if (c) {
  9672. if (c && !c.id && c._isGroup === false && c._holdTime === 0 && c._paused === false && !c._callback && Number.isNaN(c._sequenceNumber) && c.effect.target instanceof HTMLCanvasElement) {
  9673. animations.shift(); // keep animating but no looping
  9674. // c.effect.remove();
  9675. }
  9676. }
  9677. }
  9678.  
  9679. const aniProto = Animation.prototype;
  9680. // aniProto.sequenceNumber = 0; // native YouTube engine bug - sequenceNumber is not set
  9681.  
  9682. const getXroto = (x) => {
  9683. try {
  9684. return x.__proto__;
  9685. } catch (e) { }
  9686. return null;
  9687. }
  9688. const timProto = getXroto(timeline);
  9689. if (!timProto) return;
  9690. if (
  9691. (
  9692. typeof timProto.getAnimations === 'function' && typeof timProto.play === 'function' &&
  9693. typeof timProto._discardAnimations === 'function' && typeof timProto._play === 'function' &&
  9694. typeof timProto._updateAnimationsPromises === 'function' && !timProto.nofCQ &&
  9695. typeof aniProto._updatePromises === 'function' && !aniProto.nofYH
  9696. )
  9697.  
  9698. ) {
  9699.  
  9700. timProto.nofCQ = 1;
  9701. aniProto.nofYH = 1;
  9702.  
  9703. const originalAnimationsWithPromises = ((_updateAnimationsPromises) => {
  9704.  
  9705.  
  9706. /*
  9707. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  9708. return c._updatePromises();
  9709. });
  9710. */
  9711.  
  9712. const p = Array.prototype.filter;
  9713.  
  9714. let res = null;
  9715. Array.prototype.filter = function () {
  9716.  
  9717. res = this;
  9718. return this;
  9719.  
  9720. };
  9721.  
  9722. _updateAnimationsPromises.call({});
  9723.  
  9724. Array.prototype.filter = p;
  9725.  
  9726. if (res && typeof res.length === 'number') {
  9727. /** @type {any[]} */
  9728. const _res = res;
  9729. return _res;
  9730. }
  9731.  
  9732.  
  9733. return null;
  9734.  
  9735.  
  9736.  
  9737.  
  9738. })(timProto._updateAnimationsPromises);
  9739.  
  9740. if (!originalAnimationsWithPromises || typeof originalAnimationsWithPromises.length !== 'number') return;
  9741.  
  9742. // console.log('originalAnimationsWithPromises', originalAnimationsWithPromises)
  9743.  
  9744. aniProto._updatePromises31 = aniProto._updatePromises;
  9745.  
  9746. /*
  9747. aniProto._updatePromises = function(){
  9748. console.log('eff',this._oldPlayState, this.playState)
  9749. return this._updatePromises31.apply(this, arguments)
  9750. }
  9751. */
  9752.  
  9753. aniProto._updatePromises = function () {
  9754. var oldPlayState = this._oldPlayState;
  9755. var newPlayState = this.playState;
  9756. // console.log('ett', oldPlayState, newPlayState)
  9757. if (newPlayState !== oldPlayState) {
  9758. this._oldPlayState = newPlayState;
  9759. if (this._readyPromise) {
  9760. if ("idle" == newPlayState) {
  9761. this._rejectReadyPromise();
  9762. this._readyPromise = void 0;
  9763. } else if ("pending" == oldPlayState) {
  9764. this._resolveReadyPromise();
  9765. } else if ("pending" == newPlayState) {
  9766. this._readyPromise = void 0;
  9767. }
  9768. }
  9769. if (this._finishedPromise) {
  9770. if ("idle" == newPlayState) {
  9771. this._rejectFinishedPromise();
  9772. this._finishedPromise = void 0;
  9773. } else if ("finished" == newPlayState) {
  9774. this._resolveFinishedPromise();
  9775. } else if ("finished" == oldPlayState) {
  9776. this._finishedPromise = void 0;
  9777. }
  9778. }
  9779. }
  9780. return this._readyPromise || this._finishedPromise;
  9781. };
  9782.  
  9783.  
  9784. let restartWebAnimationsNextTickFlag = false;
  9785.  
  9786. const looperMethodT = () => {
  9787.  
  9788. const runnerFn = (hRes) => {
  9789. var b = timeline;
  9790. b.currentTime = hRes;
  9791. b._discardAnimations();
  9792. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  9793. if (0 == b._animations.length) {
  9794. restartWebAnimationsNextTickFlag = false;
  9795. } else {
  9796. getRafPromise().then(runnerFn);
  9797. }
  9798. }
  9799.  
  9800. const restartWebAnimationsNextTick = () => {
  9801. if (!restartWebAnimationsNextTickFlag) {
  9802. restartWebAnimationsNextTickFlag = true;
  9803. getRafPromise().then(runnerFn);
  9804. }
  9805. }
  9806.  
  9807. return { restartWebAnimationsNextTick }
  9808. };
  9809.  
  9810.  
  9811. const looperMethodN = () => {
  9812.  
  9813. const acs = document.createElement('a-f');
  9814. acs.id = 'a-f';
  9815.  
  9816. if (!document.getElementById('afscript')) {
  9817. const style = document.createElement('style');
  9818. style.id = 'afscript';
  9819. style.textContent = `
  9820. @keyFrames aF1 {
  9821. 0% {
  9822. order: 0;
  9823. }
  9824. 100% {
  9825. order: 1;
  9826. }
  9827. }
  9828. #a-f[id] {
  9829. visibility: collapse !important;
  9830. position: fixed !important;
  9831. display: block !important;
  9832. top: -100px !important;
  9833. left: -100px !important;
  9834. margin:0 !important;
  9835. padding:0 !important;
  9836. outline:0 !important;
  9837. border:0 !important;
  9838. z-index:-1 !important;
  9839. width: 0px !important;
  9840. height: 0px !important;
  9841. contain: strict !important;
  9842. pointer-events: none !important;
  9843. animation: 1ms steps(2, jump-none) 0ms infinite alternate forwards running aF1 !important;
  9844. }
  9845. `;
  9846. (document.head || document.documentElement).appendChild(style);
  9847. }
  9848.  
  9849. document.documentElement.insertBefore(acs, document.documentElement.firstChild);
  9850.  
  9851. const _onanimationiteration = function (evt) {
  9852. const hRes = evt.timeStamp;
  9853. var b = timeline;
  9854. b.currentTime = hRes;
  9855. b._discardAnimations();
  9856. FIX_Animation_n_timeline_cinematic && animationsFix(b);
  9857. if (0 == b._animations.length) {
  9858. restartWebAnimationsNextTickFlag = false;
  9859. acs.onanimationiteration = null;
  9860. } else {
  9861. acs.onanimationiteration = _onanimationiteration;
  9862. }
  9863.  
  9864. }
  9865.  
  9866.  
  9867.  
  9868. const restartWebAnimationsNextTick = () => {
  9869. if (!restartWebAnimationsNextTickFlag) {
  9870. restartWebAnimationsNextTickFlag = true;
  9871. acs.onanimationiteration = _onanimationiteration;
  9872.  
  9873. }
  9874. }
  9875.  
  9876. return { restartWebAnimationsNextTick }
  9877. };
  9878.  
  9879.  
  9880.  
  9881. const { restartWebAnimationsNextTick } = ('onanimationiteration' in document.documentElement) ? looperMethodN() : looperMethodT();
  9882.  
  9883.  
  9884. // console.log(571, timProto);
  9885. timProto._play = function (c) {
  9886. c = new Animation(c, this);
  9887. this._animations.push(c);
  9888. restartWebAnimationsNextTick();
  9889. c._updatePromises();
  9890. c._animation.play();
  9891. c._updatePromises();
  9892. return c
  9893. }
  9894.  
  9895. const animationsWithPromisesMap = new Set(originalAnimationsWithPromises);
  9896. originalAnimationsWithPromises.length = 0;
  9897. originalAnimationsWithPromises.push = null;
  9898. originalAnimationsWithPromises.splice = null;
  9899. originalAnimationsWithPromises.slice = null;
  9900. originalAnimationsWithPromises.indexOf = null;
  9901. originalAnimationsWithPromises.unshift = null;
  9902. originalAnimationsWithPromises.shift = null;
  9903. originalAnimationsWithPromises.pop = null;
  9904. originalAnimationsWithPromises.filter = null;
  9905. originalAnimationsWithPromises.forEach = null;
  9906. originalAnimationsWithPromises.map = null;
  9907.  
  9908.  
  9909. const _updateAnimationsPromises = () => {
  9910. animationsWithPromisesMap.forEach(c => {
  9911. if (!c._updatePromises()) animationsWithPromisesMap.delete(c);
  9912. });
  9913. /*
  9914. v.animationsWithPromises = v.animationsWithPromises.filter(function (c) {
  9915. return c._updatePromises();
  9916. });
  9917. */
  9918. }
  9919.  
  9920. timProto._updateAnimationsPromises31 = timProto._updateAnimationsPromises;
  9921.  
  9922. timProto._updateAnimationsPromises = _updateAnimationsPromises;
  9923.  
  9924. delete timProto._updateAnimationsPromises;
  9925. Object.defineProperty(timProto, '_updateAnimationsPromises', {
  9926. get() {
  9927. if (animationsWithPromisesMap.size === 0) return nilFn;
  9928. return _updateAnimationsPromises;
  9929. },
  9930. set(nv) {
  9931. delete this._updateAnimationsPromises;
  9932. this._updateAnimationsPromises = nv;
  9933. },
  9934. enumerable: true,
  9935. configurable: true,
  9936. });
  9937.  
  9938.  
  9939. let pdFinished = Object.getOwnPropertyDescriptor(aniProto, 'finished');
  9940. aniProto.__finished_native_get__ = pdFinished.get;
  9941. if (typeof pdFinished.get === 'function' && !pdFinished.set && pdFinished.configurable === true && pdFinished.enumerable === true) {
  9942.  
  9943.  
  9944. Object.defineProperty(aniProto, 'finished', {
  9945. get() {
  9946. this._finishedPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  9947. this._finishedPromise = new Promise((resolve, reject) => {
  9948. this._resolveFinishedPromise = function () {
  9949. resolve(this)
  9950. };
  9951. this._rejectFinishedPromise = function () {
  9952. reject({
  9953. type: DOMException.ABORT_ERR,
  9954. name: "AbortError"
  9955. })
  9956. };
  9957. }),
  9958. "finished" == this.playState && this._resolveFinishedPromise());
  9959. return this._finishedPromise
  9960. },
  9961. set: undefined,
  9962. enumerable: true,
  9963. configurable: true
  9964. });
  9965.  
  9966. }
  9967.  
  9968.  
  9969.  
  9970. let pdReady = Object.getOwnPropertyDescriptor(aniProto, 'ready');
  9971. aniProto.__ready_native_get__ = pdReady.get;
  9972. if (typeof pdReady.get === 'function' && !pdReady.set && pdReady.configurable === true && pdReady.enumerable === true) {
  9973.  
  9974. Object.defineProperty(aniProto, 'ready', {
  9975. get() {
  9976. this._readyPromise || (!animationsWithPromisesMap.has(this) && animationsWithPromisesMap.add(this),
  9977. this._readyPromise = new Promise((resolve, reject) => {
  9978. this._resolveReadyPromise = function () {
  9979. resolve(this)
  9980. };
  9981. this._rejectReadyPromise = function () {
  9982. reject({
  9983. type: DOMException.ABORT_ERR,
  9984. name: "AbortError"
  9985. })
  9986. };
  9987. }),
  9988. "pending" !== this.playState && this._resolveReadyPromise());
  9989. return this._readyPromise
  9990. },
  9991. set: undefined,
  9992. enumerable: true,
  9993. configurable: true
  9994. });
  9995.  
  9996. }
  9997.  
  9998.  
  9999. if (IGNORE_bindAnimationForCustomEffect && typeof aniProto._rebuildUnderlyingAnimation === 'function' && !aniProto._rebuildUnderlyingAnimation21 && aniProto._rebuildUnderlyingAnimation.length === 0) {
  10000.  
  10001. aniProto._rebuildUnderlyingAnimation21 = aniProto._rebuildUnderlyingAnimation;
  10002. const _rebuildUnderlyingAnimation = function () {
  10003. // if (isNaN(this._sequenceNumber)) return; // do not rebuild underlying animation if native animation is used.
  10004. this.effect && this.effect._onsample && (this.effect._onsample = null);
  10005. return this._rebuildUnderlyingAnimation21();
  10006. }
  10007. aniProto._rebuildUnderlyingAnimation = _rebuildUnderlyingAnimation;
  10008. // delete aniProto._rebuildUnderlyingAnimation;
  10009. // Object.defineProperty(aniProto, '_rebuildUnderlyingAnimation', {
  10010. // get() {
  10011. // if (isNaN(this._sequenceNumber)) return nilFn;
  10012. // return this._rebuildUnderlyingAnimation21;
  10013. // },
  10014. // set(nv) {
  10015. // delete this._rebuildUnderlyingAnimation;
  10016. // this._rebuildUnderlyingAnimation = nv;
  10017. // },
  10018. // enumerable: true,
  10019. // configurable: true
  10020. // });
  10021. }
  10022.  
  10023.  
  10024. /*
  10025.  
  10026.  
  10027. function f(c) {
  10028. var b = v.timeline;
  10029. b.currentTime = c;
  10030. b._discardAnimations();
  10031. 0 == b._animations.length ? d = !1 : requestAnimationFrame(f)
  10032. }
  10033. var h = window.requestAnimationFrame;
  10034. window.requestAnimationFrame = function(c) {
  10035. return h(function(b) {
  10036. v.timeline._updateAnimationsPromises();
  10037. c(b);
  10038. v.timeline._updateAnimationsPromises()
  10039. })
  10040. }
  10041. ;
  10042. v.AnimationTimeline = function() {
  10043. this._animations = [];
  10044. this.currentTime = void 0
  10045. }
  10046. ;
  10047. v.AnimationTimeline.prototype = {
  10048. getAnimations: function() {
  10049. this._discardAnimations();
  10050. return this._animations.slice()
  10051. },
  10052. _updateAnimationsPromises: function() {
  10053. v.animationsWithPromises = v.animationsWithPromises.filter(function(c) {
  10054. return c._updatePromises()
  10055. })
  10056. },
  10057. _discardAnimations: function() {
  10058. this._updateAnimationsPromises();
  10059. this._animations = this._animations.filter(function(c) {
  10060. return "finished" != c.playState && "idle" != c.playState
  10061. })
  10062. },
  10063. _play: function(c) {
  10064. c = new v.Animation(c,this);
  10065. this._animations.push(c);
  10066. v.restartWebAnimationsNextTick();
  10067. c._updatePromises();
  10068. c._animation.play();
  10069. c._updatePromises();
  10070. return c
  10071. },
  10072. play: function(c) {
  10073. c && c.remove();
  10074. return this._play(c)
  10075. }
  10076. };
  10077. var d = !1;
  10078. v.restartWebAnimationsNextTick = function() {
  10079. d || (d = !0,
  10080. requestAnimationFrame(f))
  10081. }
  10082. ;
  10083. var a = new v.AnimationTimeline;
  10084. v.timeline = a;
  10085. try {
  10086. Object.defineProperty(window.document, "timeline", {
  10087. configurable: !0,
  10088. get: function() {
  10089. return a
  10090. }
  10091. })
  10092. } catch (c) {}
  10093. try {
  10094. window.document.timeline = a
  10095. } catch (c) {}
  10096.  
  10097. */
  10098.  
  10099.  
  10100.  
  10101. /*
  10102.  
  10103. var g = window.getComputedStyle;
  10104. Object.defineProperty(window, "getComputedStyle", {
  10105. configurable: !0,
  10106. enumerable: !0,
  10107. value: function() {
  10108. v.timeline._updateAnimationsPromises();
  10109. var e = g.apply(this, arguments);
  10110. h() && (e = g.apply(this, arguments));
  10111. v.timeline._updateAnimationsPromises();
  10112. return e
  10113. }
  10114. });
  10115.  
  10116. */
  10117.  
  10118.  
  10119.  
  10120.  
  10121. }
  10122.  
  10123.  
  10124.  
  10125.  
  10126. })();
  10127.  
  10128. !isUrlInEmbed && Promise.resolve().then(() => {
  10129.  
  10130. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  10131.  
  10132.  
  10133.  
  10134. class LimitedSizeSet extends Set {
  10135. constructor(n) {
  10136. super();
  10137. this.limit = n;
  10138. }
  10139.  
  10140. add(key) {
  10141. if (!super.has(key)) {
  10142. super.add(key);
  10143. let n = super.size - this.limit;
  10144. if (n > 0) {
  10145. const iterator = super.values();
  10146. do {
  10147. const firstKey = iterator.next().value; // Get the first (oldest) key
  10148. super.delete(firstKey); // Delete the oldest key
  10149. } while (--n > 0)
  10150. }
  10151. }
  10152. }
  10153.  
  10154. removeAdd(key) {
  10155. super.delete(key);
  10156. this.add(key);
  10157. }
  10158.  
  10159. }
  10160.  
  10161. // const wk3 = new WeakMap();
  10162.  
  10163. // let mtxVideoId = '';
  10164. // let aje3 = [];
  10165. const mfvContinuationRecorded = new LimitedSizeSet(8); // record all success continuation keys
  10166. const mfyContinuationIgnored = new LimitedSizeSet(8); // ignore continuation keys by copying the keys in the past
  10167. let mtzlastAllowedContinuation = ''; // the key stored at the last success; clear when scheduling changes
  10168. let mtzCount = 0; // the key keeps unchanged
  10169. // let mjtNextMainKey = '';
  10170. let mjtRecordedPrevKey = ''; // the key stored at the last success (no clear)
  10171. let mjtLockPreviousKey = ''; // the key before fetch() should be discarded. (uncertain continuation)
  10172. let mbCId322 = 0; // cid for delay fetchUpdatedMetadata
  10173. // let allowNoDelay322=false;
  10174. let mbDelayBelowNCalls = 0; // after N calls, by pass delay; reset when scheduling changes
  10175.  
  10176. let mpKey22 = ''; // last success continutation key & url pair
  10177. let mpUrl22 = ''; // last success continutation key & url pair
  10178. let mpKey21 = ''; // latest requested continutation key & url pair
  10179. let mpUrl21 = ''; // latest requested continutation key & url pair
  10180.  
  10181.  
  10182. async function sha1Hex(message) {
  10183. const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
  10184. const hashBuffer = await crypto.subtle.digest("SHA-1", msgUint8); // hash the message
  10185. const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
  10186. const hashHex = hashArray
  10187. .map((b) => b.toString(16).padStart(2, "0"))
  10188. .join(""); // convert bytes to hex string
  10189. return hashHex;
  10190. }
  10191.  
  10192. async function continuationLog(a, ...args) {
  10193. let b = a;
  10194. try {
  10195. if (advanceLogging) b = await sha1Hex(a);
  10196. let c = args.map(e => {
  10197. return e === a ? b : e
  10198. });
  10199. console.log(...c)
  10200. } catch (e) { console.warn(e) }
  10201. }
  10202.  
  10203. function copyPreviousContiuationToIgnored374(toClearRecorded) {
  10204.  
  10205.  
  10206. if (mfvContinuationRecorded.length > 0) {
  10207. for (const [e, d] of mfvContinuationRecorded) {
  10208. mfyContinuationIgnored.removeAdd(e);
  10209. }
  10210. toClearRecorded && mfvContinuationRecorded.clear();
  10211. }
  10212.  
  10213. }
  10214.  
  10215. function setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr) {
  10216.  
  10217. const tmProto = taskMgr.constructor.prototype;
  10218. if (tmProto && typeof tmProto.addJob === 'function' && tmProto.addJob.length === 3 && typeof tmProto.cancelJob === 'function' && tmProto.cancelJob.length === 1) {
  10219.  
  10220. if (!tmProto.addJob714) {
  10221.  
  10222. tmProto.addJob714 = tmProto.addJob;
  10223.  
  10224. tmProto.addJob = function (a, b, c) {
  10225. const jobId = this.addJob714(a, b, c);
  10226. if (jobId > 0) {
  10227. // const ez = wk3.get(this);
  10228. // const dz = ez ? ez.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint : null;
  10229. // aje3.push({mtx, jobId, a,b,c, element: this, dz, data: (ez?.data || null) })
  10230.  
  10231. this.__lastJobId863__ = jobId;
  10232. }
  10233. return jobId;
  10234. }
  10235.  
  10236. }
  10237.  
  10238. if (!tmProto.cancelJob714) {
  10239.  
  10240. tmProto.cancelJob714 = tmProto.cancelJob;
  10241.  
  10242. tmProto.cancelJob = function (a) {
  10243. const res = this.cancelJob714(a);
  10244. // if (a > 0) {
  10245. // for (const e of aje3) {
  10246. // if (e.jobId === a) e.cancelled = true;
  10247. // }
  10248. // }
  10249. return res;
  10250. }
  10251.  
  10252. }
  10253.  
  10254. }
  10255. }
  10256.  
  10257.  
  10258. const FIX_avoid_incorrect_video_meta_bool = FIX_avoid_incorrect_video_meta && isPrepareCachedV && check_for_set_key_order && !isChatRoomURL;
  10259.  
  10260.  
  10261. FIX_avoid_incorrect_video_meta_bool && whenCEDefined('ytd-video-primary-info-renderer').then(() => {
  10262. let dummy;
  10263. let cProto;
  10264. // let mc = 4;
  10265. // dummy = await observablePromise(() => {
  10266. // const r = document.querySelector('ytd-video-primary-info-renderer');
  10267. // if (!r) return;
  10268. // let cProto = insp(r).constructor.prototype;
  10269. // if (cProto.fetchUpdatedMetadata) return r;
  10270. // if (--mc < 0) return -1;
  10271. // return null;
  10272. // }).obtain();
  10273. dummy = document.createElement('ytd-video-primary-info-renderer');
  10274. if (!(dummy instanceof Element)) return;
  10275. // console.log(5022, dummy)
  10276. cProto = insp(dummy).constructor.prototype;
  10277.  
  10278. cProto.__getEmittorTaskMgr859__ = function () {
  10279. let taskMgr_ = null;
  10280. try {
  10281. taskMgr_ = (this.ytTaskEmitterBehavior || 0).getTaskManager() || null;
  10282. } catch (e) { }
  10283. return taskMgr_;
  10284. }
  10285. if (typeof cProto.fetchUpdatedMetadata === 'function' && cProto.fetchUpdatedMetadata.length === 1 && !cProto.fetchUpdatedMetadata717) {
  10286. // console.log(1234, cProto, cProto.is)
  10287. cProto.fetchUpdatedMetadata717 = cProto.fetchUpdatedMetadata;
  10288.  
  10289. let c_;
  10290. cProto.fetchUpdatedMetadata718 = function (a) {
  10291. // delay or immediate call the actual fetchUpdatedMetadata
  10292.  
  10293. let doImmediately = false;
  10294. if (a && typeof a === 'string' && mjtRecordedPrevKey && mjtRecordedPrevKey === mpKey22 && a === mpKey22 && (!pageSetupVideoId || pageSetupVideoId !== mpUrl22)) {
  10295.  
  10296. if (!pageSetupVideoId && videoPlayingY.videoId === mpUrl22) doImmediately = true;
  10297.  
  10298. } else if (typeof a !== 'string' || mbDelayBelowNCalls > 3 || !mpKey22 || (mpKey22 === a && mpKey22 !== mjtLockPreviousKey) || (mjtLockPreviousKey && mjtLockPreviousKey !== a)) {
  10299.  
  10300. doImmediately = true;
  10301.  
  10302. }
  10303.  
  10304. if (mbCId322) {
  10305. clearTimeout(mbCId322);
  10306. mbCId322 = 0;
  10307. }
  10308.  
  10309. if (doImmediately) return this.fetchUpdatedMetadata717(a);
  10310.  
  10311. let delay = mjtLockPreviousKey === a ? 8000 : 800;
  10312.  
  10313. mbCId322 = setTimeout(() => {
  10314. this.fetchUpdatedMetadata717(a);
  10315. }, delay);
  10316.  
  10317. console.log('[yt-js-engine-tamer]', '5190 delayed fetchUpdatedMetadata', delay);
  10318.  
  10319. }
  10320.  
  10321. cProto.fetchUpdatedMetadata = function (a) {
  10322.  
  10323. if (!pageSetupState) {
  10324. if (c_) clearTimeout(c_);
  10325. c_ = setTimeout(() => {
  10326. this.fetchUpdatedMetadata718(a);
  10327. }, 300);
  10328. return;
  10329. }
  10330.  
  10331. // pageSetupState == 0
  10332.  
  10333. try {
  10334.  
  10335. mbDelayBelowNCalls++;
  10336.  
  10337. if (arguments.length > 1 || !(a === undefined || (typeof a === 'string' && a))) {
  10338. console.warn("CAUTION: fetchUpdatedMetadata coding might have to be updated.");
  10339. }
  10340.  
  10341. // console.log('fum377', a)
  10342. if (typeof a === 'string' && mfyContinuationIgnored.has(a)) {
  10343. console.log('[yt-js-engine-tamer]', '5040 skip fetchUpdatedMetadata', a);
  10344. return;
  10345. }
  10346.  
  10347. if (!a && (this.data || 0).updatedMetadataEndpoint) {
  10348. if (mjtRecordedPrevKey && mjtLockPreviousKey !== mjtRecordedPrevKey) {
  10349. mjtLockPreviousKey = mjtRecordedPrevKey;
  10350. LOG_FETCHMETA_UPDATE && continuationLog(mjtLockPreviousKey, '5150 Lock Key', mjtLockPreviousKey);
  10351. }
  10352. // mjtNextMainKey = true;
  10353. mtzlastAllowedContinuation = '';
  10354. mtzCount = 0;
  10355. // allowNoDelay322 = false;
  10356. // fetch new metadata, cancel all previous continuations
  10357. copyPreviousContiuationToIgnored374(true);
  10358. } else if (typeof a === 'string') {
  10359. const videoPlayingId = videoPlayingY.videoId;
  10360.  
  10361. // if(mjtNextMainKey === true) mjtNextMainKey = a;
  10362.  
  10363. let update21 = !!pageSetupVideoId;
  10364. if (mpKey22 === a && mpUrl22 === videoPlayingId && mpUrl22 && videoPlayingId && (!pageSetupVideoId || pageSetupVideoId === videoPlayingId)) {
  10365. update21 = true;
  10366. } else if (mpKey22 === a && mpUrl22 !== pageSetupVideoId) {
  10367. LOG_FETCHMETA_UPDATE && continuationLog(mpKey22, '5060 mpUrl22 mismatched', mpKey22, mpUrl22, pageSetupVideoId || '(null)', videoPlayingId || '(null)');
  10368. return;
  10369. }
  10370. if (update21) {
  10371. mpKey21 = a;
  10372. mpUrl21 = pageSetupVideoId || videoPlayingId;
  10373. }
  10374.  
  10375. if (!mfvContinuationRecorded.has(a)) mfvContinuationRecorded.add(a);
  10376. }
  10377. LOG_FETCHMETA_UPDATE && continuationLog(a, '5180 fetchUpdatedMetadata\t', a, pageSetupVideoId || '(null)', videoPlayingY.videoId || '(null)');
  10378. // if (!pageSetupVideoId && typeof a === 'string' && a.length > 40) return; // ignore incorrect continuation
  10379. // if(a === mjtNextMainKey) allowNoDelay322 = false;
  10380. return this.fetchUpdatedMetadata718(a);
  10381.  
  10382. } catch (e) {
  10383. console.log('Code Error in fetchUpdatedMetadata', e);
  10384. }
  10385. return this.fetchUpdatedMetadata717(a)
  10386. }
  10387. }
  10388.  
  10389.  
  10390. if (typeof cProto.scheduleInitialUpdatedMetadataRequest === 'function' && cProto.scheduleInitialUpdatedMetadataRequest.length === 0 && !cProto.scheduleInitialUpdatedMetadataRequest717) {
  10391. // console.log(1234, cProto, cProto.is)
  10392. cProto.scheduleInitialUpdatedMetadataRequest717 = cProto.scheduleInitialUpdatedMetadataRequest;
  10393. let mJob = null;
  10394.  
  10395. cProto.scheduleInitialUpdatedMetadataRequest = function () {
  10396.  
  10397. try {
  10398.  
  10399. if (arguments.length > 0) {
  10400. console.warn("CAUTION: scheduleInitialUpdatedMetadataRequest coding might have to be updated.");
  10401. }
  10402. // mfy = mfv;
  10403.  
  10404. // mjtNextMainKey = '';
  10405. mtzlastAllowedContinuation = '';
  10406. mtzCount = 0;
  10407. if (mbCId322) {
  10408. clearTimeout(mbCId322);
  10409. mbCId322 = 0;
  10410. }
  10411. mbDelayBelowNCalls = 0;
  10412. // allowNoDelay322 = false;
  10413. copyPreviousContiuationToIgnored374(true);
  10414.  
  10415. const taskMgr = this.__getEmittorTaskMgr859__();
  10416. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714 && taskMgr.addJob && taskMgr.cancelJob) setup_ytTaskEmitterBehavior_TaskMgr374(taskMgr);
  10417. if (FIX_avoid_incorrect_video_meta_emitterBehavior && taskMgr && !taskMgr.addJob714) {
  10418. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 507');
  10419. }
  10420.  
  10421. // prevent depulicated schedule job by clearing previous JobId
  10422. if (taskMgr && typeof taskMgr.addLowPriorityJob === 'function' && taskMgr.addLowPriorityJob.length === 2 && typeof taskMgr.cancelJob === 'function' && taskMgr.cancelJob.length === 1) {
  10423.  
  10424. let res;
  10425.  
  10426. if (mJob) {
  10427. const job = mJob;
  10428. mJob = null;
  10429. console.log('cancelJob', job)
  10430. taskMgr.cancelJob(job); // clear previous [Interval Meta Update] job
  10431. // p.cancelJob(a,b);
  10432. }
  10433.  
  10434. // const updatedMetadataEndpoint = this.data?.updatedMetadataEndpoint?.updatedMetadataEndpoint
  10435.  
  10436. let pza = taskMgr.__lastJobId863__;
  10437. try { res = this.scheduleInitialUpdatedMetadataRequest717(); } catch (e) { }
  10438. let pzb = taskMgr.__lastJobId863__
  10439. if (pza !== pzb) {
  10440. mJob = pzb; // set [Interval Meta Update] jobId
  10441. }
  10442.  
  10443. // if (updatedMetadataEndpoint && updatedMetadataEndpoint.videoId) {
  10444. // mtxVideoId = updatedMetadataEndpoint.videoId || ''; // set the current target VideoId
  10445. // } else {
  10446. // mtxVideoId = ''; // sometimes updatedMetadataEndpoint is not ready
  10447. // }
  10448.  
  10449. return res;
  10450.  
  10451. } else {
  10452. console.log('[yt-js-engine-tamer]', 'scheduleInitialUpdatedMetadataRequest error 601');
  10453. }
  10454.  
  10455. } catch (e) {
  10456. console.log('Code Error in scheduleInitialUpdatedMetadataRequest', e);
  10457. }
  10458.  
  10459.  
  10460. return this.scheduleInitialUpdatedMetadataRequest717();
  10461. }
  10462. }
  10463.  
  10464.  
  10465. });
  10466.  
  10467. FIX_avoid_incorrect_video_meta_bool && promiseForYtActionCalled.then((ytAppDom) => {
  10468. let dummy;
  10469. let cProto;
  10470. dummy = ytAppDom;
  10471. if (!(dummy instanceof Element)) return;
  10472. cProto = insp(dummy).constructor.prototype;
  10473. if (typeof cProto.sendServiceAjax_ === 'function' && cProto.sendServiceAjax_.length === 4 && !cProto.sendServiceAjax717_) {
  10474. // console.log(1234, cProto, cProto.is);
  10475. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10476. // cProto.handleServiceRequest_ = function (a, b, c, d) {
  10477. // console.log(123401, arguments);
  10478. // return this.handleServiceRequest717_(a, b, c, d);
  10479. // }
  10480.  
  10481. // cProto.handleServiceRequest717_ = cProto.handleServiceRequest_;
  10482.  
  10483. // cProto.handleServiceRequest_ = function(a,b,c,d){
  10484. // console.log(59901, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10485. // if(a?.is === 'ytd-video-primary-info-renderer' && b?.updatedMetadataEndpoint?.videoId && c?.continuation && typeof c?.continuation ==='string'){
  10486. // console.log('mfv', c.continuation);
  10487. // mfv.add( c.continuation);
  10488. // }
  10489. // return this.handleServiceRequest717_(a,b,c,d);
  10490. // }
  10491.  
  10492. function extraArguments322(a, b, c) {
  10493. let is = (a || 0).is;
  10494. let videoId = ((b || 0).updatedMetadataEndpoint || 0).videoId;
  10495. let continuation = (c || 0).continuation;
  10496. if (typeof is !== 'string') is = null;
  10497. if (typeof videoId !== 'string') videoId = null;
  10498. if (typeof continuation !== 'string') continuation = null;
  10499. return { is, videoId, continuation };
  10500. }
  10501.  
  10502. cProto.sendServiceAjax717_ = cProto.sendServiceAjax_;
  10503. cProto.sendServiceAjax_ = function (a, b, c, d) {
  10504.  
  10505. // console.log(8001)
  10506. try {
  10507.  
  10508. const { is, videoId, continuation } = extraArguments322(a, b, c);
  10509.  
  10510. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10511. console.warn("CAUTION: sendServiceAjax_ coding might have to be updated.");
  10512. }
  10513.  
  10514. if (pageSetupVideoId && videoId && continuation) {
  10515. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10516. mfyContinuationIgnored.removeAdd(continuation);
  10517. mfvContinuationRecorded.delete(continuation);
  10518. return;
  10519. }
  10520. }
  10521.  
  10522. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10523. copyPreviousContiuationToIgnored374(false);
  10524. mfyContinuationIgnored.delete(continuation);
  10525. mfvContinuationRecorded.removeAdd(continuation);
  10526. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10527. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10528. mjtLockPreviousKey = '';
  10529. }
  10530. // if (mjtNextMainKey === continuation) {
  10531. // copyPreviousContiuationToIgnored(false);
  10532. // mfyContinuationIgnored.delete(continuation);
  10533. // mfvContinuationRecorded.add(continuation);
  10534. // }
  10535.  
  10536.  
  10537. if (mfyContinuationIgnored && continuation) {
  10538. if (mfyContinuationIgnored.has(continuation)) {
  10539. LOG_FETCHMETA_UPDATE && continuationLog(continuation, '5260 matched01', continuation)
  10540. return;
  10541. }
  10542. }
  10543.  
  10544. // console.log(59902, a?.is, b,c,d)
  10545. // console.log(59903, a?.is, b?.updatedMetadataEndpoint?.videoId, c?.continuation)
  10546. if (is === 'ytd-video-primary-info-renderer' && videoId && continuation && !mfvContinuationRecorded.has(continuation)) {
  10547. // console.log('mfv377', continuation);
  10548. mfvContinuationRecorded.add(continuation);
  10549. }
  10550.  
  10551. // if (videoId) {
  10552. // if (!pageSetupVideoId) return; // ignore page not ready
  10553. // // if (mtxVideoId && b.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10554. // if (videoId !== pageSetupVideoId) {
  10555. // return;
  10556. // }
  10557. // }
  10558.  
  10559. } catch (e) {
  10560. console.log('Coding Error in sendServiceAjax_', e)
  10561. }
  10562. // console.log(8002)
  10563. // console.log(123402, arguments);
  10564. // console.log(5162, 'a',a?.is,'b',b,'c',c,'d',d);
  10565.  
  10566. // console.log(5211, b?.updatedMetadataEndpoint?.kdkw33);
  10567. // if(b &&b.updatedMetadataEndpoint && !b.updatedMetadataEndpoint.kdkw33){
  10568. // b.updatedMetadataEndpoint = new Proxy(b.updatedMetadataEndpoint, {
  10569. // get(target, prop, receiver){
  10570. // console.log('xxs99', target.videoId, mtx)
  10571. // if(prop ==='kdkw33') return 1;
  10572. // console.log(3322, prop, target)
  10573. // if(prop === 'initialDelayMs') {
  10574. // throw new Error("ABCC");
  10575. // }
  10576. // return target[prop];
  10577. // },
  10578. // set(target, prop, value, receiver){
  10579.  
  10580. // if(prop ==='kdkw33') return true;
  10581. // target[prop]=value;
  10582. // return true;
  10583. // }
  10584. // });
  10585. // }
  10586. // console.log(5533, b?.updatedMetadataEndpoint?.kdkw33)
  10587. return this.sendServiceAjax717_(a, b, c, d);
  10588. }
  10589. }
  10590.  
  10591. function delayClearOtherKeys(lztContinuation) {
  10592. // // schedule delayed removal if mfyContinuationIgnored is not empty
  10593. // getRafPromise().then(() => {
  10594. // // assume the repeat continuation could be only for popstate which is triggered by user interaction
  10595. // // foreground page only
  10596.  
  10597. // });
  10598.  
  10599.  
  10600. if (lztContinuation !== mtzlastAllowedContinuation) return;
  10601. if (lztContinuation !== mpKey21 || lztContinuation !== mpKey22) return;
  10602. if (!mfyContinuationIgnored.size) return;
  10603. if (mfyContinuationIgnored.size > 1) {
  10604. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, 'delayClearOtherKeys, current = ', lztContinuation);
  10605. }
  10606. mfyContinuationIgnored.forEach((value, key) => {
  10607. if (key !== lztContinuation) {
  10608. mfyContinuationIgnored.delete(key);
  10609. LOG_FETCHMETA_UPDATE && continuationLog(key, 'previous continuation removed from ignored store', key);
  10610. }
  10611. });
  10612.  
  10613. }
  10614. if (typeof cProto.getCancellableNetworkPromise_ === 'function' && cProto.getCancellableNetworkPromise_.length === 5 && !cProto.getCancellableNetworkPromise717_) {
  10615. cProto.getCancellableNetworkPromise717_ = cProto.getCancellableNetworkPromise_;
  10616. cProto.getCancellableNetworkPromise_ = function (a, b, c, d, e) {
  10617.  
  10618. // console.log(8003)
  10619. try {
  10620.  
  10621.  
  10622. const { is, videoId, continuation } = extraArguments322(b, c, d);
  10623.  
  10624. if ((videoId || continuation) && (is !== 'ytd-video-primary-info-renderer')) {
  10625. console.warn("CAUTION: getCancellableNetworkPromise_ coding might have to be updated.");
  10626. }
  10627.  
  10628. if (pageSetupVideoId && videoId && continuation) {
  10629. if (mpKey21 && mpUrl21 && mpKey21 === continuation && mpUrl21 !== pageSetupVideoId) {
  10630. mfyContinuationIgnored.removeAdd(continuation);
  10631. mfvContinuationRecorded.delete(continuation);
  10632. return;
  10633. }
  10634. }
  10635.  
  10636. if (mjtLockPreviousKey && mjtLockPreviousKey !== continuation && continuation) {
  10637. copyPreviousContiuationToIgnored374(false);
  10638. mfyContinuationIgnored.delete(continuation);
  10639. mfvContinuationRecorded.removeAdd(continuation);
  10640. mfyContinuationIgnored.removeAdd(mjtLockPreviousKey);
  10641. mfvContinuationRecorded.delete(mjtLockPreviousKey);
  10642. mjtLockPreviousKey = '';
  10643. }
  10644.  
  10645. // if (mjtNextMainKey === continuation) {
  10646. // copyPreviousContiuationToIgnored(false);
  10647. // mfyContinuationIgnored.delete(continuation);
  10648. // mfvContinuationRecorded.add(continuation);
  10649. // }
  10650.  
  10651. const lztContinuation = continuation;
  10652.  
  10653. if (mfyContinuationIgnored && lztContinuation && typeof lztContinuation === 'string') {
  10654. if (mfyContinuationIgnored.has(lztContinuation)) {
  10655. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5360 matched02', lztContinuation)
  10656. return;
  10657. }
  10658. }
  10659.  
  10660. // if (videoId) {
  10661. // if (!pageSetupVideoId) return; // ignore page not ready
  10662. // // if (mtxVideoId && c.updatedMetadataEndpoint.videoId !== mtxVideoId) return; // ignore videoID not matched
  10663. // if (videoId !== pageSetupVideoId) {
  10664. // return;
  10665. // }
  10666. // }
  10667.  
  10668. if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation !== lztContinuation) {
  10669. mtzlastAllowedContinuation = lztContinuation;
  10670. // console.log(70401, lztContinuation, mfyContinuationIgnored.size)
  10671.  
  10672. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5382 Continuation sets to\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  10673. mjtRecordedPrevKey = lztContinuation;
  10674. if (mjtLockPreviousKey === lztContinuation) mjtLockPreviousKey = '';
  10675. // if (mfyContinuationIgnored.size > 0) {
  10676. // delayClearOtherKeys(lztContinuation);
  10677. // }
  10678. mtzCount = 0;
  10679. // allowNoDelay322 = false;
  10680. } else if (typeof lztContinuation === 'string' && mtzlastAllowedContinuation && mtzlastAllowedContinuation === lztContinuation) {
  10681. // repeated
  10682. if (++mtzCount > 1e9) mtzCount = 1e4;
  10683. LOG_FETCHMETA_UPDATE && continuationLog(lztContinuation, '5386 Same Continuation\t\t', lztContinuation, `C${mtzCount}.R${mfvContinuationRecorded.size}.I${mfyContinuationIgnored.size}`);
  10684.  
  10685. // if (mtzCount >= 3) allowNoDelay322 = true;
  10686. if (mtzCount >= 3 && mfyContinuationIgnored.size > 0) {
  10687. Promise.resolve(lztContinuation).then(delayClearOtherKeys).catch(console.warn);
  10688. }
  10689. if (mtzCount === 5) {
  10690. mfvContinuationRecorded.clear();
  10691. mfvContinuationRecorded.add(lztContinuation);
  10692. }
  10693.  
  10694. }
  10695.  
  10696. if (typeof lztContinuation === 'string' && lztContinuation && (pageSetupVideoId || videoPlayingY.videoId)) {
  10697. mpKey22 = lztContinuation;
  10698. mpUrl22 = pageSetupVideoId || videoPlayingY.videoId;
  10699. }
  10700.  
  10701. if (mbCId322) {
  10702. clearTimeout(mbCId322);
  10703. mbCId322 = 0;
  10704. }
  10705. } catch (e) {
  10706. console.log('Coding Error in getCancellableNetworkPromise_', e)
  10707. }
  10708.  
  10709. // console.log(8004)
  10710. // console.log(123403, arguments);
  10711. // if(c.updatedMetadataEndpoint) console.log(123404, pageSetupVideoId, JSON.stringify(c.updatedMetadataEndpoint))
  10712.  
  10713. // console.log(5163, a?.is,b,c,d,e);
  10714. return this.getCancellableNetworkPromise717_(a, b, c, d, e);
  10715. }
  10716. }
  10717. });
  10718.  
  10719. // ==================================== FIX_avoid_incorrect_video_meta ====================================
  10720.  
  10721.  
  10722. FIX_ytdExpander_childrenChanged && !isChatRoomURL && whenCEDefined('ytd-expander').then(() => {
  10723.  
  10724. let dummy;
  10725. let cProto;
  10726.  
  10727. dummy = document.createElement('ytd-expander');
  10728. cProto = insp(dummy).constructor.prototype;
  10729.  
  10730. if (fnIntegrity(cProto.initChildrenObserver, '0.48.21') && fnIntegrity(cProto.childrenChanged, '0.40.22')) {
  10731.  
  10732. cProto.initChildrenObserver14 = cProto.initChildrenObserver;
  10733. cProto.childrenChanged14 = cProto.childrenChanged;
  10734.  
  10735. cProto.initChildrenObserver = function () {
  10736. var a = this;
  10737. this.observer = new MutationObserver(function () {
  10738. a.childrenChanged()
  10739. }
  10740. );
  10741. this.observer.observe(this.content, {
  10742. subtree: !0,
  10743. childList: !0,
  10744. attributes: !0,
  10745. characterData: !0
  10746. });
  10747. this.childrenChanged()
  10748. }
  10749. ;
  10750. cProto.childrenChanged = function () {
  10751. if (this.alwaysToggleable) {
  10752. this.canToggle = this.alwaysToggleable;
  10753. } else if (!this.canToggleJobId) {
  10754. this.canToggleJobId = 1;
  10755. foregroundPromiseFn().then(() => {
  10756. this.canToggleJobId = 0;
  10757. this.calculateCanCollapse()
  10758. })
  10759. }
  10760. }
  10761.  
  10762. // console.log(cProto.initChildrenObserver)
  10763. console.debug('ytd-expander-fix-childrenChanged');
  10764.  
  10765. }
  10766.  
  10767. });
  10768.  
  10769.  
  10770. FIX_paper_ripple_animate && whenCEDefined('paper-ripple').then(() => {
  10771.  
  10772. let dummy;
  10773. let cProto;
  10774. dummy = document.createElement('paper-ripple');
  10775. cProto = insp(dummy).constructor.prototype;
  10776.  
  10777. if (fnIntegrity(cProto.animate, '0.74.5')) {
  10778.  
  10779.  
  10780. cProto.animate34 = cProto.animate;
  10781. cProto.animate = function () {
  10782. if (this._animating) {
  10783. var a;
  10784. const ripples = this.ripples;
  10785. for (a = 0; a < ripples.length; ++a) {
  10786. var b = ripples[a];
  10787. b.draw();
  10788. this.$.background.style.opacity = b.outerOpacity;
  10789. b.isOpacityFullyDecayed && !b.isRestingAtMaxRadius && this.removeRipple(b)
  10790. }
  10791. if ((this.shouldKeepAnimating || 0) !== ripples.length) {
  10792. if (!this._boundAnimate38) this._boundAnimate38 = this.animate.bind(this);
  10793. foregroundPromiseFn().then(this._boundAnimate38);
  10794. } else {
  10795. this.onAnimationComplete();
  10796. }
  10797. }
  10798. }
  10799.  
  10800. console.debug('FIX_paper_ripple_animate')
  10801.  
  10802. // console.log(cProto.animate)
  10803.  
  10804. }
  10805.  
  10806. });
  10807.  
  10808. if (FIX_doIdomRender) {
  10809.  
  10810. const xsetTimeout = function (f, d) {
  10811. if (xsetTimeout.m511 === 1 && !d) {
  10812. xsetTimeout.m511 = 2;
  10813. xsetTimeout.m568 = f;
  10814. } else {
  10815. return setTimeout.apply(window, arguments)
  10816. }
  10817.  
  10818. }
  10819.  
  10820. /**
  10821. *
  10822. IGb = function(a) {
  10823. var b, c = null == (b = a.requestAninmationFrameResolver) ? void 0 : b.promise;
  10824. c || (a.requestAninmationFrameResolver = new Vi,
  10825. c = a.requestAninmationFrameResolver.promise,
  10826. Da.requestAnimationFrame(function() {
  10827. var d;
  10828. null == (d = a.requestAninmationFrameResolver) || d.resolve();
  10829. a.requestAninmationFrameResolver = null
  10830. }));
  10831. return c
  10832. }
  10833.  
  10834.  
  10835. */
  10836.  
  10837. const xrequestAnimationFrame = function (f) {
  10838. const h = `${f}`;
  10839. if (h.startsWith("function(){setTimeout(function(){") && h.endsWith("})}")) {
  10840. let t = null;
  10841. xsetTimeout.m511 = 1;
  10842. f();
  10843. if (xsetTimeout.m511 === 2) {
  10844. t = xsetTimeout.m568;
  10845. xsetTimeout.m568 = null;
  10846. }
  10847. xsetTimeout.m511 = 0;
  10848. if (typeof t === 'function') {
  10849. foregroundPromiseFn().then(t);
  10850. }
  10851. } else if (h.includes("requestAninmationFrameResolver")) {
  10852. foregroundPromiseFn().then(f);
  10853. } else {
  10854. return requestAnimationFrame.apply(window, arguments);
  10855. }
  10856. }
  10857.  
  10858. let busy = false;
  10859. const doIdomRender = function () {
  10860.  
  10861. if (!this) return;
  10862. if (busy) {
  10863. return this.doIdomRender13(...arguments);
  10864. }
  10865. busy = true;
  10866. const { requestAnimationFrame, setTimeout } = window;
  10867. window.requestAnimationFrame = xrequestAnimationFrame;
  10868. window.setTimeout = xsetTimeout;
  10869. let r = this.doIdomRender13(...arguments);
  10870. window.requestAnimationFrame = requestAnimationFrame;
  10871. window.setTimeout = setTimeout;
  10872. busy = false;
  10873. return r;
  10874. };
  10875. 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']) {
  10876.  
  10877.  
  10878. whenCEDefined(ytTag).then(() => {
  10879.  
  10880. let dummy;
  10881. let cProto;
  10882. dummy = document.createElement(ytTag);
  10883. cProto = insp(dummy).constructor.prototype;
  10884.  
  10885. cProto.doIdomRender13 = cProto.doIdomRender;
  10886. cProto.doIdomRender = doIdomRender;
  10887.  
  10888. if (cProto.doIdomRender13 === cProto.templatingFn) cProto.templatingFn = doIdomRender;
  10889.  
  10890. console.debug('[yt-js-engine-tamer] FIX_doIdomRender', ytTag)
  10891.  
  10892.  
  10893.  
  10894. });
  10895.  
  10896. }
  10897.  
  10898. }
  10899.  
  10900.  
  10901.  
  10902.  
  10903. FIX_POPUP_UNIQUE_ID && whenCEDefined('ytd-popup-container').then(async () => {
  10904.  
  10905. const sMap = new Map();
  10906.  
  10907. const ZTa = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  10908. const ZT = function () {
  10909. for (var a = Array(36), b = 0, c, d = 0; d < 36; d++)
  10910. d == 8 || d == 13 || d == 18 || d == 23 ? a[d] = "-" : d == 14 ? a[d] = "4" : (b <= 2 && (b = 33554432 + Math.random() * 16777216 | 0),
  10911. c = b & 15,
  10912. b >>= 4,
  10913. a[d] = ZTa[d == 19 ? c & 3 | 8 : c]);
  10914. return a.join("")
  10915. };
  10916.  
  10917.  
  10918. const popupContainerCollection = document.getElementsByTagName('ytd-popup-container');
  10919.  
  10920. const popupContainer = await observablePromise(() => {
  10921. return popupContainerCollection[0];
  10922. }).obtain();
  10923.  
  10924.  
  10925. let cProto;
  10926. cProto = insp(popupContainer).constructor.prototype;
  10927.  
  10928.  
  10929. if (!cProto || typeof cProto.handleOpenPopupAction !== 'function' || cProto.handleOpenPopupAction3868 || cProto.handleOpenPopupAction.length !== 2) {
  10930. console.log('FIX_POPUP_UNIQUE_ID NG')
  10931. return;
  10932. }
  10933. cProto.handleOpenPopupAction3868 = cProto.handleOpenPopupAction;
  10934.  
  10935. cProto.handleOpenPopupAction = function (a, b) {
  10936.  
  10937. if (typeof (a || 0) === 'object' && !a.__jOdQA__) {
  10938.  
  10939. a.__jOdQA__ = true;
  10940.  
  10941. try {
  10942.  
  10943. const h = this.hostElement;
  10944.  
  10945. if (h instanceof HTMLElement_) {
  10946.  
  10947. const map = h.__skme44__ = h.__skme44__ || new Map();
  10948.  
  10949. let mKey = '';
  10950. const wKey = firstObjectKey(a);
  10951. const wObj = wKey ? a[wKey] : null;
  10952. if (wKey && wObj && typeof (wObj.popup || 0) === 'object') {
  10953. const pKey = firstObjectKey(wObj.popup)
  10954. const pObj = pKey ? wObj.popup[pKey] : null;
  10955. let contentKey = '';
  10956. let headerKey = '';
  10957.  
  10958. if (pObj && pObj.identifier && pObj.content && pObj.header) {
  10959. contentKey = firstObjectKey(pObj.content)
  10960. headerKey = firstObjectKey(pObj.header)
  10961. }
  10962. if (contentKey && headerKey) {
  10963.  
  10964. mKey = `${wKey}(popupType:${wObj.popupType},popup(${pKey}(content(${contentKey}:...),header(${headerKey}:...),identifer(surface:${pObj.identifier.surface}))))`
  10965.  
  10966. if (mKey) {
  10967.  
  10968. if (!wObj.uniqueId) {
  10969. for (let i = 0; i < 8; i++) {
  10970. wObj.uniqueId = ZT();
  10971. if (!sMap.has(wObj.uniqueId)) break;
  10972. }
  10973. }
  10974. const oId = wObj.uniqueId
  10975.  
  10976. let nId_ = map.get(mKey);
  10977. if (!nId_) {
  10978. map.set(mKey, nId_ = oId);
  10979. }
  10980.  
  10981. wObj.uniqueId = nId_ || wObj.uniqueId;
  10982.  
  10983. const nId = wObj.uniqueId
  10984.  
  10985. sMap.set(oId, nId);
  10986. sMap.set(nId, nId);
  10987.  
  10988. wObj.uniqueId = nId;
  10989. pObj.targetId = nId;
  10990. pObj.identifier.tag = nId;
  10991.  
  10992. if (oId !== nId) {
  10993. console.log('FIX_POPUP_UNIQUE_ID', oId, nId);
  10994. }
  10995.  
  10996. }
  10997.  
  10998. }
  10999. }
  11000.  
  11001. // console.log(12213, mKey, a, b, h)
  11002.  
  11003. }
  11004.  
  11005. } catch (e) {
  11006. console.warn(e)
  11007. }
  11008.  
  11009. try {
  11010.  
  11011. const results = searchNestedObject(a, (x) => {
  11012. if (typeof x === 'string' && x.length === 36) {
  11013. 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;
  11014. }
  11015. return false;
  11016. });
  11017. for (const [obj, key] of results) {
  11018. const oId = obj[key];
  11019. const nId = sMap.get(oId);
  11020. if (nId) obj[key] = nId;
  11021. }
  11022. } catch (e) {
  11023. console.warn(e)
  11024. }
  11025.  
  11026.  
  11027. }
  11028.  
  11029. return this.handleOpenPopupAction3868(...arguments)
  11030. }
  11031.  
  11032. console.log('FIX_POPUP_UNIQUE_ID OK')
  11033.  
  11034.  
  11035. });
  11036.  
  11037.  
  11038. FIX_TRANSCRIPT_SEGMENTS && !isChatRoomURL && whenCEDefined('yt-formatted-string').then(async () => {
  11039.  
  11040. let dummy;
  11041. let cProto;
  11042. dummy = document.createElement('yt-formatted-string');
  11043. cProto = insp(dummy).constructor.prototype;
  11044.  
  11045. if (!cProto || typeof cProto.setNodeStyle_ !== 'function' || cProto.setNodeStyle17_ || cProto.setNodeStyle_.length !== 2) {
  11046. console.log('FIX_TRANSCRIPT_SEGMENTS(2) NG');
  11047. return;
  11048. }
  11049.  
  11050. cProto.setNodeStyle17_ = cProto.setNodeStyle_;
  11051. cProto.setNodeStyle_ = function (a, b) {
  11052. if (b instanceof HTMLElement_ && typeof (a || 0) === 'object') b.classList.toggle('yt-formatted-string-block-line', !!a.blockLine);
  11053. return this.setNodeStyle17_(a, b);
  11054. }
  11055.  
  11056. console.log('FIX_TRANSCRIPT_SEGMENTS(2) OK');
  11057. });
  11058.  
  11059. });
  11060.  
  11061. });
  11062.  
  11063.  
  11064.  
  11065.  
  11066. if (isMainWindow) {
  11067.  
  11068. console.groupCollapsed(
  11069. "%cYouTube JS Engine Tamer",
  11070. "background-color: #EDE43B ; color: #000 ; font-weight: bold ; padding: 4px ;"
  11071. );
  11072.  
  11073.  
  11074.  
  11075. console.log("Script is loaded.");
  11076. console.log("This script changes the core mechanisms of the YouTube JS engine.");
  11077.  
  11078. console.log("This script is experimental and subject to further changes.");
  11079.  
  11080. console.log("This might boost your YouTube performance.");
  11081.  
  11082. console.log("CAUTION: This might break your YouTube.");
  11083.  
  11084.  
  11085. if (prepareLogs.length >= 1) {
  11086. console.log(" =========================================================================== ");
  11087.  
  11088. for (const msg of prepareLogs) {
  11089. console.log(msg)
  11090. }
  11091.  
  11092. console.log(" =========================================================================== ");
  11093. }
  11094.  
  11095. console.groupEnd();
  11096.  
  11097. }
  11098.  
  11099.  
  11100.  
  11101. })();